123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414 |
- import {
- $e,
- Fi,
- Gb,
- Ji,
- X,
- Xi,
- Yb,
- _f,
- ca,
- fn as fn2,
- g,
- mr,
- pr,
- sa
- } from "./chunk-QRYBFJ3R.js";
- import {
- $R,
- AC,
- BehaviorSubject,
- Bi,
- Ct,
- DC,
- De,
- Eu,
- Fe,
- Go,
- Gs,
- J0,
- K0,
- Ke,
- Ko,
- L0,
- LC,
- Mf,
- Mi,
- Mt,
- NE,
- OR,
- Ot,
- P0,
- Pt,
- Q_,
- Qo,
- Qr,
- Ra,
- SE,
- Subject,
- U0,
- UC,
- UE,
- Vn,
- Vo,
- Vr,
- Vs,
- WC,
- Xe,
- Xt,
- Ze,
- _C,
- _n,
- _s,
- ar,
- bE,
- bR,
- cn,
- cs,
- distinctUntilChanged,
- dn,
- en,
- fC,
- filter,
- first,
- fl,
- fn,
- fs,
- jt,
- kE,
- kt,
- map,
- merge,
- mu,
- nR,
- nf,
- nt,
- nu,
- of,
- ot,
- qt,
- rR,
- re,
- rr,
- shareReplay,
- skip,
- st,
- switchMap,
- takeUntil,
- tr,
- we,
- wo,
- wu,
- x_,
- yu,
- zn
- } from "./chunk-23V3HWTR.js";
- // node_modules/.pnpm/@univerjs+engine-numfmt@0.5.5/node_modules/@univerjs/engine-numfmt/lib/es/index.js
- var T = "@@@";
- // node_modules/.pnpm/@univerjs+sheets@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets/lib/es/index.js
- var ri = Object.defineProperty;
- var ii = (n, e, t) => e in n ? ri(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
- var R = (n, e, t) => ii(n, typeof e != "symbol" ? e + "" : e, t);
- var Ji2 = ((n) => (n.OthersCanView = "othersCanView", n.NoOneElseCanView = "noOneElseCanView", n))(Ji2 || {});
- var Yi = ((n) => (n.DesignedUserCanEdit = "designedUserCanEdit", n.OnlyMe = "onlyMe", n))(Yi || {});
- var de = class {
- constructor() {
- R(this, "_model", /* @__PURE__ */ new Map());
- R(this, "_ruleChange", new Subject());
- R(this, "ruleChange$", this._ruleChange.asObservable());
- R(this, "_ruleRefresh", new Subject());
- R(this, "ruleRefresh$", this._ruleRefresh.asObservable());
- R(this, "_rangeRuleInitStateChange", new BehaviorSubject(false));
- R(this, "rangeRuleInitStateChange$", this._rangeRuleInitStateChange.asObservable());
- }
- ruleRefresh(e) {
- this._ruleRefresh.next(e);
- }
- getRangeRuleInitState() {
- return this._rangeRuleInitStateChange.value;
- }
- changeRuleInitState(e) {
- this._rangeRuleInitStateChange.next(e);
- }
- addRule(e, t, o) {
- this._ensureRuleMap(e, t).set(o.id, o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: o, type: "add" });
- }
- deleteRule(e, t, o) {
- var r, i, a, u;
- const s = (i = (r = this._model.get(e)) == null ? void 0 : r.get(t)) == null ? void 0 : i.get(o);
- s && ((u = (a = this._model.get(e)) == null ? void 0 : a.get(t)) == null || u.delete(o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: s, type: "delete" }));
- }
- setRule(e, t, o, s) {
- var i, a;
- const r = this.getRule(e, t, o);
- r && ((a = (i = this._model.get(e)) == null ? void 0 : i.get(t)) == null || a.set(o, s), this._ruleChange.next({ unitId: e, subUnitId: t, oldRule: r, rule: s, type: "set" }));
- }
- getRule(e, t, o) {
- var s, r;
- return (r = (s = this._model.get(e)) == null ? void 0 : s.get(t)) == null ? void 0 : r.get(o);
- }
- getSubunitRuleList(e, t) {
- var s;
- return [...(((s = this._model.get(e)) == null ? void 0 : s.get(t)) || /* @__PURE__ */ new Map()).values()];
- }
- getSubunitRuleListLength(e, t) {
- var s;
- const o = (s = this._model.get(e)) == null ? void 0 : s.get(t);
- return o ? o.size : 0;
- }
- _ensureRuleMap(e, t) {
- let o = this._model.get(e);
- o || (o = /* @__PURE__ */ new Map(), this._model.set(e, o));
- let s = o.get(t);
- return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
- }
- toObject() {
- const e = {};
- return [...this._model.keys()].forEach((o) => {
- const s = this._model.get(o), r = [...s.keys()];
- e[o] = {}, r.forEach((i) => {
- const a = s.get(i);
- e[o][i] = [...a.values()];
- });
- }), e;
- }
- fromObject(e) {
- const t = /* @__PURE__ */ new Map();
- Object.keys(e).forEach((o) => {
- const s = e[o], r = /* @__PURE__ */ new Map();
- Object.keys(s).forEach((i) => {
- const a = s[i].reduce((u, l) => (u.set(l.id, l), u), /* @__PURE__ */ new Map());
- r.set(i, a);
- }), t.set(o, r);
- }), this._model = t;
- }
- deleteUnitModel(e) {
- this._model.delete(e);
- }
- createRuleId(e, t) {
- let o = re.generateRandomId(4);
- const s = this._ensureRuleMap(e, t);
- for (; s.has(o); )
- o = re.generateRandomId(4);
- return o;
- }
- getTargetByPermissionId(e, t) {
- const o = this._model.get(e);
- if (!o)
- return null;
- for (const [s, r] of o)
- for (const i of r.values())
- if (i.permissionId === t)
- return [e, s];
- return null;
- }
- };
- var Bd = (n, e) => {
- const t = n.get(de), o = e.ruleIds.map((r) => t.getRule(e.unitId, e.subUnitId, r)).filter((r) => !!r);
- return { id: Ne.id, params: { subUnitId: e.subUnitId, unitId: e.unitId, rules: o } };
- };
- var ze = {
- id: "sheet.mutation.delete-range-protection",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, ruleIds: s } = e, r = n.get(de);
- return s.forEach((i) => {
- r.deleteRule(t, o, i);
- }), true;
- }
- };
- var Fd = (n) => {
- const e = { ...n, ruleIds: n.rules.map((t) => t.id) };
- return { id: ze.id, params: e };
- };
- var Ne = {
- id: "sheet.mutation.add-range-protection",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, rules: s } = e, r = n.get(de);
- return s.forEach((i) => {
- r.addRule(t, o, i);
- }), true;
- }
- };
- var Xi2 = {
- type: ar.COMMAND,
- id: "sheet.command.add-range-protection",
- async handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), o = n.get(cn), s = n.get(de), { rule: r, permissionId: i } = e, { unitId: a, subUnitId: u, ranges: l, description: c, viewState: d, editState: h } = r, m = [{
- ranges: l,
- permissionId: i,
- id: s.createRuleId(a, u),
- description: c,
- unitType: r.unitType,
- unitId: a,
- subUnitId: u,
- viewState: d,
- editState: h
- }];
- if (await t.executeCommand(Ne.id, {
- unitId: a,
- subUnitId: u,
- rules: m
- })) {
- const f = [{ id: Ne.id, params: { unitId: a, subUnitId: u, rules: m } }], p = [{ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: m.map((C) => C.id) } }];
- o.pushUndoRedo({
- unitID: a,
- redoMutations: f,
- undoMutations: p
- });
- }
- return true;
- }
- };
- var Ye = class {
- constructor() {
- R(this, "_model", /* @__PURE__ */ new Map());
- R(this, "_ruleChange", new Subject());
- R(this, "_ruleRefresh", new Subject());
- R(this, "_resetOrder", new Subject());
- R(this, "ruleChange$", this._ruleChange.asObservable());
- R(this, "ruleRefresh$", this._ruleRefresh.asObservable());
- R(this, "resetOrder$", this._resetOrder.asObservable());
- R(this, "_worksheetRuleInitStateChange", new BehaviorSubject(false));
- R(this, "worksheetRuleInitStateChange$", this._worksheetRuleInitStateChange.asObservable());
- }
- changeRuleInitState(e) {
- this._worksheetRuleInitStateChange.next(e);
- }
- getSheetRuleInitState() {
- return this._worksheetRuleInitStateChange.value;
- }
- addRule(e, t) {
- this._ensureSubUnitMap(e).set(t.subUnitId, t), this._ruleChange.next({ unitId: e, rule: t, type: "add", subUnitId: t.subUnitId });
- }
- deleteRule(e, t) {
- var s, r, i;
- const o = (r = (s = this._model) == null ? void 0 : s.get(e)) == null ? void 0 : r.get(t);
- o && ((i = this._model.get(e)) == null || i.delete(t), this._ruleChange.next({ unitId: e, rule: o, type: "delete", subUnitId: t }));
- }
- setRule(e, t, o) {
- var r, i;
- const s = this.getRule(e, t);
- s && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.set(t, o), this._ruleChange.next({ unitId: e, oldRule: s, rule: o, type: "set", subUnitId: t }));
- }
- getRule(e, t) {
- var o, s;
- return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
- }
- toObject() {
- const e = {};
- return [...this._model.keys()].forEach((o) => {
- const s = this._model.get(o);
- s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
- const a = s.get(i);
- a && e[o].push(a);
- }));
- }), e;
- }
- fromObject(e) {
- const t = /* @__PURE__ */ new Map();
- Object.keys(e).forEach((o) => {
- const s = e[o];
- if (s != null && s.length) {
- const r = /* @__PURE__ */ new Map();
- s.forEach((i) => {
- r.set(i.subUnitId, i);
- }), t.set(o, r);
- }
- }), this._model = t;
- }
- deleteUnitModel(e) {
- this._model.delete(e);
- }
- _ensureSubUnitMap(e) {
- let t = this._model.get(e);
- return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
- }
- ruleRefresh(e) {
- this._ruleRefresh.next(e);
- }
- resetOrder() {
- this._resetOrder.next(Math.random());
- }
- getTargetByPermissionId(e, t) {
- const o = this._model.get(e);
- if (!o)
- return null;
- for (const [s, r] of o)
- if (r.permissionId === t)
- return [e, s];
- }
- };
- var ct = {
- id: "sheet.mutation.add-worksheet-protection",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, rule: o } = e;
- return n.get(Ye).addRule(t, o), true;
- }
- };
- var St = {
- id: "sheet.mutation.delete-worksheet-protection",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o } = e;
- return n.get(Ye).deleteRule(t, o), true;
- }
- };
- var qi = {
- type: ar.COMMAND,
- id: "sheet.command.add-worksheet-protection",
- async handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), o = n.get(cn), { rule: s, unitId: r } = e, i = s.subUnitId;
- if (await t.executeCommand(ct.id, {
- unitId: r,
- rule: s,
- subUnitId: s.subUnitId
- })) {
- const u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: s.subUnitId } }], l = [{ id: St.id, params: { unitId: r, subUnitId: i } }];
- o.pushUndoRedo({
- unitID: r,
- redoMutations: u,
- undoMutations: l
- });
- }
- return true;
- }
- };
- var Zi = nR("CELL_CONTENT");
- var Qi = nR("ROW_FILTERED");
- var et = {
- CELL_CONTENT: Zi,
- ROW_FILTERED: Qi
- };
- var ea = ((n) => (n[n.DATA_VALIDATION = 9] = "DATA_VALIDATION", n[n.NUMFMT = 10] = "NUMFMT", n[n.CELL_IMAGE = 11] = "CELL_IMAGE", n))(ea || {});
- var Ns = "sheet.interceptor.range-theme-id";
- var jo = "sheet.interceptor.ignore-range-theme";
- var ta = Object.defineProperty;
- var na = Object.getOwnPropertyDescriptor;
- var oa = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? na(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && ta(e, t, s), s;
- };
- var sa2 = (n, e) => (t, o) => e(t, o, n);
- var Go2 = nR("BEFORE_CELL_EDIT");
- var qn = nR("AFTER_CELL_EDIT");
- var Zn = nR("AFTER_CELL_EDIT_ASYNC");
- var V = class extends nt {
- /** @ignore */
- constructor(e) {
- super();
- R(this, "_interceptorsByName", /* @__PURE__ */ new Map());
- R(this, "_commandInterceptors", []);
- R(this, "_rangeInterceptors", []);
- R(this, "_beforeCommandInterceptor", []);
- R(this, "_afterCommandInterceptors", []);
- R(this, "_workbookDisposables", /* @__PURE__ */ new Map());
- R(this, "_worksheetDisposables", /* @__PURE__ */ new Map());
- R(this, "_interceptorsDirty", false);
- R(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map());
- R(this, "writeCellInterceptor", new rR({
- BEFORE_CELL_EDIT: Go2,
- AFTER_CELL_EDIT: qn,
- AFTER_CELL_EDIT_ASYNC: Zn
- }));
- this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((t) => {
- this._interceptWorkbook(t);
- })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).subscribe(
- (t) => this._disposeWorkbookInterceptor(t)
- )), this.intercept(et.CELL_CONTENT, {
- priority: -1,
- effect: Vn.Style | Vn.Value,
- handler(t, o) {
- const s = o.worksheet.getCellRaw(o.row, o.col);
- return t ? { ...s, ...t } : s;
- }
- }), this.disposeWithMe(this.writeCellInterceptor.intercept(qn, {
- priority: -1,
- handler: (t) => t
- })), this.disposeWithMe(this.writeCellInterceptor.intercept(Go2, {
- priority: -1,
- handler: (t) => t
- })), this.disposeWithMe(this.writeCellInterceptor.intercept(Zn, {
- priority: -1,
- handler: (t) => t
- }));
- }
- dispose() {
- super.dispose(), this._workbookDisposables.forEach((e) => e.dispose()), this._workbookDisposables.clear(), this._worksheetDisposables.clear(), this._interceptorsByName.clear();
- }
- // #region intercept command execution
- /**
- * Add a listener function to a specific command to add affiliated mutations. It should be called in controllers.
- *
- * Pairs with {@link onCommandExecute}.
- *
- * @param interceptor
- * @returns
- */
- interceptCommand(e) {
- if (this._commandInterceptors.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._commandInterceptors.push(e), this._commandInterceptors.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(Ze(() => cs(this._commandInterceptors, e)));
- }
- /**
- * When command is executing, call this method to gether undo redo mutations from upper features.
- * @param command
- * @returns
- */
- onCommandExecute(e) {
- const t = this._commandInterceptors.map((o) => o.getMutations(e));
- return {
- preUndos: t.map((o) => {
- var s;
- return (s = o.preUndos) != null ? s : [];
- }).flat(),
- undos: t.map((o) => o.undos).flat(),
- preRedos: t.map((o) => {
- var s;
- return (s = o.preRedos) != null ? s : [];
- }).flat(),
- redos: t.map((o) => o.redos).flat()
- };
- }
- interceptAfterCommand(e) {
- if (this._afterCommandInterceptors.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._afterCommandInterceptors.push(e), this._afterCommandInterceptors.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(Ze(() => cs(this._afterCommandInterceptors, e)));
- }
- afterCommandExecute(e) {
- const t = this._afterCommandInterceptors.map((o) => o.getMutations(e));
- return {
- undos: t.map((o) => o.undos).flat(),
- redos: t.map((o) => o.redos).flat()
- };
- }
- /**
- * Add a listener function to a specific command to determine if the command can execute mutations. It should be
- * called in controllers.
- *
- * Pairs with {@link beforeCommandExecute}.
- *
- * @param interceptor
- * @returns
- */
- interceptBeforeCommand(e) {
- if (this._beforeCommandInterceptor.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._beforeCommandInterceptor.push(e), this._beforeCommandInterceptor.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(Ze(() => cs(this._beforeCommandInterceptor, e)));
- }
- /**
- * before command execute, call this method to get the flag of whether it can be executed the command,
- * @param info ICommandInfo
- * @returns Promise<boolean>
- */
- async beforeCommandExecute(e) {
- return (await Promise.all(this._beforeCommandInterceptor.map((o) => o.performCheck(e)))).every((o) => o);
- }
- // #endregion
- // #region intercept ranges - mainly for pivot table currently (2024/10/28).
- /**
- * By adding callbacks to some Ranges can get some additional mutations, such as clearing all plugin data in a certain area.
- * @param interceptor IRangeInterceptors
- * @returns IDisposable
- */
- interceptRanges(e) {
- if (this._rangeInterceptors.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._rangeInterceptors.push(e), this._rangeInterceptors.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(Ze(() => cs(this._rangeInterceptors, e)));
- }
- generateMutationsByRanges(e) {
- const t = this._rangeInterceptors.map((o) => o.getMutations(e));
- return {
- preUndos: t.map((o) => {
- var s;
- return (s = o.preUndos) != null ? s : [];
- }).flat(),
- undos: t.map((o) => o.undos).flat(),
- preRedos: t.map((o) => {
- var s;
- return (s = o.preRedos) != null ? s : [];
- }).flat(),
- redos: t.map((o) => o.redos).flat()
- };
- }
- // #endregion
- // #region intercept on writing cell
- async onWriteCell(e, t, o, s, r) {
- const i = {
- subUnitId: t.getSheetId(),
- unitId: e.getUnitId(),
- workbook: e,
- worksheet: t,
- row: o,
- col: s,
- origin: re.deepClone(r)
- }, a = this.writeCellInterceptor.fetchThroughInterceptors(qn)(r, i);
- return await this.writeCellInterceptor.fetchThroughInterceptors(Zn)(Promise.resolve(a), i);
- }
- // #endregion
- intercept(e, t) {
- const o = e;
- this._interceptorsByName.has(o) || this._interceptorsByName.set(o, []);
- const s = this._interceptorsByName.get(o);
- s.push(t);
- const r = s.sort((i, a) => {
- var u, l;
- return ((u = a.priority) != null ? u : 0) - ((l = i.priority) != null ? l : 0);
- });
- if (o === et.CELL_CONTENT) {
- this._interceptorsByName.set(
- `${o}-${Vn.Style | Vn.Value}`,
- r
- );
- const i = Vn.Style | Vn.Value;
- this._interceptorsByName.set(
- `${o}-${Vn.Style}`,
- r.filter((a) => ((a.effect || i) & Vn.Style) > 0)
- ), this._interceptorsByName.set(
- `${o}-${Vn.Value}`,
- r.filter((a) => ((a.effect || i) & Vn.Value) > 0)
- );
- } else
- this._interceptorsByName.set(
- o,
- r
- );
- return this._interceptorsDirty = true, this.disposeWithMe(Ze(() => cs(this._interceptorsByName.get(o), t)));
- }
- fetchThroughInterceptors(e, t, o, s) {
- const r = t === void 0 ? e : `${e}-${t}`, i = o != null ? o : r;
- let a = this._composedInterceptorByKey.get(i);
- if (!a || this._interceptorsDirty) {
- let u = this._interceptorsByName.get(r);
- u && s && (u = u.filter(s)), a = x_(u || []), this._composedInterceptorByKey.set(i, a);
- }
- return a;
- }
- _interceptWorkbook(e) {
- const t = new Mi(), o = e.getUnitId(), s = this, r = (i) => {
- const a = i.getSheetId();
- i.__interceptViewModel((u) => {
- const l = new Mi();
- s._worksheetDisposables.set(zo(o, i), l), l.add(u.registerCellContentInterceptor({
- getCell(c, d, h, m, g2) {
- const f = i.getCellRaw(c, d);
- return s.fetchThroughInterceptors(et.CELL_CONTENT, h, m, g2)(
- f,
- {
- unitId: o,
- subUnitId: a,
- row: c,
- col: d,
- worksheet: i,
- workbook: e,
- rawData: f
- }
- );
- }
- })), l.add(u.registerRowFilteredInterceptor({
- getRowFiltered(c) {
- return !!s.fetchThroughInterceptors(et.ROW_FILTERED)(
- false,
- {
- unitId: o,
- subUnitId: a,
- row: c,
- workbook: e,
- worksheet: i
- }
- );
- }
- }));
- });
- };
- e.getSheets().forEach((i) => r(i)), t.add(e.sheetCreated$.subscribe((i) => r(i))), t.add(Ze(() => e.getSheets().forEach((i) => this._disposeSheetInterceptor(o, i)))), t.add(e.sheetDisposed$.subscribe((i) => this._disposeSheetInterceptor(o, i))), this._workbookDisposables.set(o, t);
- }
- _disposeWorkbookInterceptor(e) {
- const t = e.getUnitId(), o = this._workbookDisposables.get(t);
- o && (o.dispose(), this._workbookDisposables.delete(t));
- }
- _disposeSheetInterceptor(e, t) {
- const o = zo(e, t), s = this._worksheetDisposables.get(o);
- s && (s.dispose(), this._worksheetDisposables.delete(o));
- }
- };
- V = oa([
- sa2(0, _n)
- ], V);
- function zo(n, e) {
- return `${n}|${e.getSheetId()}`;
- }
- var le = (n) => {
- const e = {};
- return n.bg && (e.bg = { ...n.bg }), n.ol && (e.ol = { ...n.ol }), n.bd && (e.bd = { ...n.bd }), n.cl && (e.cl = { ...n.cl }), n.ht && (e.ht = n.ht), n.vt && (e.vt = n.vt), n.bl !== void 0 && (e.bl = n.bl), e;
- };
- function ra(n) {
- const e = {};
- if (n.length === 1)
- return n[0];
- for (const t of n)
- t.bg && (e.bg = t.bg), t.ol && (e.ol = t.ol), t.bd && (e.bd = { ...e.bd, ...t.bd }), t.cl && (e.cl = t.cl), t.ht && (e.ht = t.ht), t.vt && (e.vt = t.vt), t.bl !== void 0 && (e.bl = t.bl);
- return e;
- }
- var ce = {
- wholeStyle: 1,
- headerRowStyle: 2,
- headerColumnStyle: 4,
- firstRowStyle: 8,
- secondRowStyle: 16,
- lastRowStyle: 32,
- firstColumnStyle: 128,
- secondColumnStyle: 256,
- lastColumnStyle: 512
- };
- var yt = class {
- /**
- * @constructor
- * @param {string} name The name of the range theme style, it used to identify the range theme style.
- * @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style.
- */
- constructor(e, t) {
- R(this, "_name");
- R(this, "wholeStyle", null);
- R(this, "headerRowStyle", null);
- R(this, "headerColumnStyle", null);
- R(this, "firstRowStyle", null);
- R(this, "secondRowStyle", null);
- R(this, "lastRowStyle", null);
- R(this, "firstColumnStyle", null);
- R(this, "secondColumnStyle", null);
- R(this, "lastColumnStyle", null);
- R(this, "_mergeCacheMap", /* @__PURE__ */ new Map());
- t && this.fromJson({ ...t, name: e }), this._name = e;
- }
- /**
- * Gets the name of the range theme style.The name is read only, and use to identifier the range theme style.
- * @returns {string} The name of the range theme style.
- */
- getName() {
- return this._name;
- }
- getWholeStyle() {
- return this.wholeStyle;
- }
- setWholeStyle(e) {
- this.wholeStyle = e;
- }
- getFirstRowStyle() {
- return this.firstRowStyle;
- }
- setFirstRowStyle(e) {
- this.firstRowStyle = e;
- }
- getSecondRowStyle() {
- return this.secondRowStyle;
- }
- setSecondRowStyle(e) {
- this.secondRowStyle = e;
- }
- getLastRowStyle() {
- return this.lastRowStyle;
- }
- setLastRowStyle(e) {
- this.lastRowStyle = e;
- }
- getFirstColumnStyle() {
- return this.firstColumnStyle;
- }
- setFirstColumnStyle(e) {
- this.firstColumnStyle = e;
- }
- getSecondColumnStyle() {
- return this.secondColumnStyle;
- }
- setSecondColumnStyle(e) {
- this.secondColumnStyle = e;
- }
- getLastColumnStyle() {
- return this.lastColumnStyle;
- }
- setLastColumnStyle(e) {
- this.lastColumnStyle = e;
- }
- getHeaderRowStyle() {
- return this.headerRowStyle;
- }
- setHeaderRowStyle(e) {
- this.headerRowStyle = e;
- }
- getHeaderColumnStyle() {
- return this.headerColumnStyle;
- }
- setHeaderColumnStyle(e) {
- this.headerColumnStyle = e;
- }
- getStyle(e, t, o, s) {
- let r = 0;
- return o && (r = r | ce.lastRowStyle), s && (r = r | ce.lastColumnStyle), e >= 0 && t >= 0 && (r = r | ce.wholeStyle), e % 2 === 1 && (r = r | ce.firstRowStyle), e % 2 === 0 && (r = r | ce.secondRowStyle), e === 0 && (r = r | ce.headerRowStyle), t === 0 && (r = r | ce.headerColumnStyle), t % 2 === 1 && (r = r | ce.firstColumnStyle), t % 2 === 0 && (r = r | ce.secondColumnStyle), r === 0 ? null : this._getMergeStyle(r);
- }
- _getMergeStyle(e) {
- let t = this._mergeCacheMap.get(e);
- return t || (t = this._mergeStyle(e), this._mergeCacheMap.set(e, t)), t;
- }
- _mergeStyle(e) {
- const t = [];
- return this.wholeStyle && e & ce.wholeStyle && t.push(this.wholeStyle), this.firstColumnStyle && e & ce.firstColumnStyle && t.push(this.firstColumnStyle), this.secondColumnStyle && e & ce.secondColumnStyle && t.push(this.secondColumnStyle), this.firstRowStyle && e & ce.firstRowStyle && t.push(this.firstRowStyle), this.secondRowStyle && e & ce.secondRowStyle && t.push(this.secondRowStyle), this.headerColumnStyle && e & ce.headerColumnStyle && t.push(this.headerColumnStyle), this.lastColumnStyle && e & ce.lastColumnStyle && t.push(this.lastColumnStyle), this.headerRowStyle && e & ce.headerRowStyle && t.push(this.headerRowStyle), this.lastRowStyle && e & ce.lastRowStyle && t.push(this.lastRowStyle), ra(t);
- }
- toJson() {
- const e = {
- name: this._name
- };
- return this.wholeStyle && (e.wholeStyle = le(this.wholeStyle)), this.headerRowStyle && (e.headerRowStyle = le(this.headerRowStyle)), this.headerColumnStyle && (e.headerColumnStyle = le(this.headerColumnStyle)), this.firstRowStyle && (e.firstRowStyle = le(this.firstRowStyle)), this.secondRowStyle && (e.secondRowStyle = le(this.secondRowStyle)), this.lastRowStyle && (e.lastRowStyle = le(this.lastRowStyle)), this.firstColumnStyle && (e.firstColumnStyle = le(this.firstColumnStyle)), this.secondColumnStyle && (e.secondColumnStyle = le(this.secondColumnStyle)), this.lastColumnStyle && (e.lastColumnStyle = le(this.lastColumnStyle)), e;
- }
- fromJson(e) {
- this._name = e.name, e.wholeStyle && (this.wholeStyle = le(e.wholeStyle)), e.headerRowStyle && (this.headerRowStyle = le(e.headerRowStyle)), e.headerColumnStyle && (this.headerColumnStyle = le(e.headerColumnStyle)), e.firstRowStyle && (this.firstRowStyle = le(e.firstRowStyle)), e.secondRowStyle && (this.secondRowStyle = le(e.secondRowStyle)), e.lastRowStyle && (this.lastRowStyle = le(e.lastRowStyle)), e.firstColumnStyle && (this.firstColumnStyle = le(e.firstColumnStyle)), e.secondColumnStyle && (this.secondColumnStyle = le(e.secondColumnStyle)), e.lastColumnStyle && (this.lastColumnStyle = le(e.lastColumnStyle));
- }
- dispose() {
- this._mergeCacheMap.clear();
- }
- };
- var ia = (n, e, t) => new yt(`light-${n}`, {
- headerRowStyle: {
- bg: {
- rgb: e
- }
- },
- firstColumnStyle: {
- bg: {
- rgb: "rgb(255, 255, 255)"
- }
- },
- secondColumnStyle: {
- bg: {
- rgb: t
- }
- },
- lastRowStyle: {
- bg: {
- rgb: e
- }
- }
- });
- var aa = (n, e, t) => new yt(`middle-${n}`, {
- headerRowStyle: {
- bg: {
- rgb: e
- }
- },
- headerColumnStyle: {
- bg: {
- rgb: t
- }
- },
- secondRowStyle: {
- bg: {
- rgb: t
- }
- },
- lastRowStyle: {
- bg: {
- rgb: e
- }
- },
- lastColumnStyle: {
- bg: {
- rgb: t
- }
- }
- });
- var ua = (n, e, t, o) => new yt(`dark-${n}`, {
- headerRowStyle: {
- bg: {
- rgb: e
- },
- cl: {
- rgb: "rgb(255, 255, 255)"
- },
- ht: Xt.CENTER,
- bl: we.TRUE
- },
- firstRowStyle: {
- bg: {
- rgb: t
- }
- },
- secondRowStyle: {
- bg: {
- rgb: o
- }
- },
- lastRowStyle: {
- bg: {
- rgb: e
- }
- }
- });
- var la = [
- {
- baseName: "blue",
- header: "rgb(164, 202, 254)",
- color: "rgb(225, 239, 254)"
- },
- {
- baseName: "grey",
- header: "rgb(205, 208, 216)",
- color: "rgb(238, 239, 241)"
- },
- {
- baseName: "red",
- header: "rgb(248, 180, 180)",
- color: "rgb(253, 232, 232)"
- },
- {
- baseName: "orange",
- header: "rgb(253, 186, 140)",
- color: "rgb(254, 236, 220)"
- },
- {
- baseName: "yellow",
- header: "rgb(250, 200, 21)",
- color: "rgb(255, 244, 185)"
- },
- {
- baseName: "green",
- header: "rgb(132, 225, 188)",
- color: "rgb(222, 247, 236)"
- },
- {
- baseName: "azure",
- header: "rgb(126, 220, 226)",
- color: "rgb(213, 245, 246)"
- },
- {
- baseName: "indigo",
- header: "rgb(186, 198, 248)",
- color: "rgb(233, 237, 255)"
- },
- {
- baseName: "purple",
- header: "rgb(202, 191, 253)",
- color: "rgb(237, 235, 254)"
- },
- {
- baseName: "magenta",
- header: "rgb(248, 180, 217)",
- color: "rgb(252, 232, 243)"
- }
- ];
- var ca2 = [
- {
- baseName: "blue",
- rowHeader: "rgb(63, 131, 248)",
- colHeader: "rgb(195, 221, 253)"
- },
- {
- baseName: "grey",
- rowHeader: "rgb(95, 101, 116)",
- colHeader: "rgb(227, 229, 234)"
- },
- {
- baseName: "red",
- rowHeader: "rgb(240, 82, 82)",
- colHeader: "rgb(251, 213, 213)"
- },
- {
- baseName: "orange",
- rowHeader: "rgb(255, 90, 31)",
- colHeader: "rgb(252, 217, 189)"
- },
- {
- baseName: "yellow",
- rowHeader: "rgb(212, 157, 15)",
- colHeader: "rgb(252, 220, 106)"
- },
- {
- baseName: "green",
- rowHeader: "rgb(13, 164, 113)",
- colHeader: "rgb(188, 240, 218)"
- },
- {
- baseName: "azure",
- rowHeader: "rgb(6, 148, 162)",
- colHeader: "rgb(175, 236, 239)"
- },
- {
- baseName: "indigo",
- rowHeader: "rgb(70, 106, 247)",
- colHeader: "rgb(210, 218, 250)"
- },
- {
- baseName: "purple",
- rowHeader: "rgb(144, 97, 249)",
- colHeader: "rgb(220, 215, 254)"
- },
- {
- baseName: "magenta",
- rowHeader: "rgb(231, 70, 148)",
- colHeader: "rgb(250, 209, 232)"
- }
- ];
- var da = [
- {
- baseName: "blue",
- rowHeader: "rgb(30, 66, 159)",
- firstRow: "rgb(195, 221, 253)",
- secondRow: "rgb(118, 169, 250)"
- },
- {
- baseName: "grey",
- rowHeader: "rgb(44, 48, 64)",
- firstRow: "rgb(227, 229, 234)",
- secondRow: "rgb(151, 157, 172)"
- },
- {
- baseName: "red",
- rowHeader: "rgb(155, 28, 28)",
- firstRow: "rgb(251, 213, 213)",
- secondRow: "rgb(249, 128, 128)"
- },
- {
- baseName: "orange",
- rowHeader: "rgb(180, 52, 3)",
- firstRow: "rgb(252, 217, 189)",
- secondRow: "rgb(255, 138, 76)"
- },
- {
- baseName: "yellow",
- rowHeader: "rgb(154, 109, 21)",
- firstRow: "rgb(252, 220, 106)",
- secondRow: "rgb(212, 157, 15)"
- },
- {
- baseName: "green",
- rowHeader: "rgb(4, 108, 78)",
- firstRow: "rgb(188, 240, 218)",
- secondRow: "rgb(49, 196, 141)"
- },
- {
- baseName: "azure",
- rowHeader: "rgb(3, 102, 114)",
- firstRow: "rgb(175, 236, 239)",
- secondRow: "rgb(22, 189, 202)"
- },
- {
- baseName: "indigo",
- rowHeader: "rgb(16, 51, 191)",
- firstRow: "rgb(210, 218, 250)",
- secondRow: "rgb(98, 128, 249)"
- },
- {
- baseName: "purple",
- rowHeader: "rgb(74, 29, 150)",
- firstRow: "rgb(220, 215, 254)",
- secondRow: "rgb(172, 148, 250)"
- },
- {
- baseName: "magenta",
- rowHeader: "rgb(153, 21, 75)",
- firstRow: "rgb(250, 209, 232)",
- secondRow: "rgb(241, 126, 184)"
- }
- ];
- var ha = la.map(({ baseName: n, header: e, color: t }) => ia(n, e, t));
- var ma = ca2.map(({ baseName: n, rowHeader: e, colHeader: t }) => aa(n, e, t));
- var ga = da.map(({ baseName: n, rowHeader: e, firstRow: t, secondRow: o }) => ua(n, e, t, o));
- var fa = [
- ...ha,
- ...ma,
- ...ga
- ];
- var Ra2 = {
- headerRowStyle: {
- bg: {
- rgb: "rgb(68,114,196)"
- },
- cl: {
- rgb: "rgb(255,255,255)"
- },
- ht: Xt.CENTER,
- bl: we.TRUE
- },
- firstRowStyle: {
- bg: {
- rgb: "rgb(217,225,242)"
- }
- },
- lastRowStyle: {
- bd: {
- t: {
- s: Xe.THIN,
- cl: {
- rgb: "rgb(68,114,196)"
- }
- }
- },
- ht: Xt.CENTER,
- bl: we.TRUE
- }
- };
- var pa = new yt("default", Ra2);
- var Ca = Object.defineProperty;
- var Sa = Object.getOwnPropertyDescriptor;
- var wa = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Sa(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Ca(e, t, s), s;
- };
- var Ko2 = (n, e) => (t, o) => e(t, o, n);
- var Ia = "SHEET_RANGE_THEME_MODEL_PLUGIN";
- var He = class extends nt {
- constructor(e, t) {
- super();
- R(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
- R(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
- R(this, "_rTreeCollection", /* @__PURE__ */ new Map());
- R(this, "_defaultRangeThemeMap", /* @__PURE__ */ new Map());
- this._sheetInterceptorService = e, this._resourceManagerService = t, this._registerIntercept(), this._initSnapshot(), this._initDefaultTheme();
- }
- _initDefaultTheme() {
- this.registerDefaultRangeTheme(pa);
- for (const e of fa)
- this.registerDefaultRangeTheme(e);
- }
- _ensureRangeThemeStyleMap(e) {
- return this._rangeThemeStyleMap.has(e) || this._rangeThemeStyleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleMap.get(e);
- }
- _ensureRangeThemeStyleRuleMap(e) {
- return this._rangeThemeStyleRuleMap.has(e) || this._rangeThemeStyleRuleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleRuleMap.get(e);
- }
- _ensureRTreeCollection(e) {
- return this._rTreeCollection.has(e) || this._rTreeCollection.set(e, new $R()), this._rTreeCollection.get(e);
- }
- getDefaultRangeThemeStyle(e) {
- return this._defaultRangeThemeMap.get(e);
- }
- /**
- * Register range theme styles
- * @param {string} themeName
- * @param {IRangeThemeRangeInfo} rangeInfo
- */
- registerRangeThemeRule(e, t) {
- const { unitId: o, subUnitId: s, range: r } = t, i = qt(), a = this._ensureRangeThemeStyleRuleMap(o), u = this._ensureRTreeCollection(o);
- a.set(i, { rangeInfo: t, themeName: e }), u.insert({ unitId: o, sheetId: s, range: r, id: i });
- }
- getRegisteredRangeThemeStyle(e) {
- const { unitId: t, subUnitId: o, range: s } = e, r = this._ensureRTreeCollection(t), i = Array.from(r.bulkSearch([{ unitId: t, sheetId: o, range: s }]));
- if (i[0]) {
- const u = this._ensureRangeThemeStyleRuleMap(t).get(i[0]);
- if (u)
- return u.themeName;
- }
- }
- removeRangeThemeRule(e, t) {
- const { unitId: o, subUnitId: s, range: r } = t, i = this._ensureRTreeCollection(o), a = Array.from(i.bulkSearch([{ unitId: o, sheetId: s, range: r }]));
- if (a[0]) {
- const u = this._ensureRangeThemeStyleRuleMap(o), l = u.get(a[0]);
- l && l.themeName === e && (u.delete(a[0]), i.remove({ unitId: o, sheetId: s, range: r, id: a[0] }));
- }
- }
- registerDefaultRangeTheme(e) {
- this._defaultRangeThemeMap.set(e.getName(), e);
- }
- getRegisteredRangeThemes() {
- return Array.from(this._defaultRangeThemeMap.keys());
- }
- /**
- * Register custom range theme style.
- * @param {string} unitId The unit id.
- * @param {RangeThemeStyle} rangeThemeStyle The range theme style.
- */
- registerRangeThemeStyle(e, t) {
- this._ensureRangeThemeStyleMap(e).set(t.getName(), t);
- }
- /**
- * Unregister custom range theme style.
- * @param {string} unitId The unit id.
- * @param {string} name The name of the range theme style.
- */
- unregisterRangeThemeStyle(e, t) {
- this._ensureRangeThemeStyleMap(e).delete(t);
- }
- /**
- * Gets all custom register themes
- * @return {string[]} The array of all custom registered themes.
- */
- getALLRegisteredTheme() {
- return Array.from(this._rangeThemeStyleMap.keys());
- }
- getRangeThemeStyle(e, t) {
- return this._defaultRangeThemeMap.has(t) ? this._defaultRangeThemeMap.get(t) : this._ensureRangeThemeStyleMap(e).get(t);
- }
- getCellStyle(e, t, o, s) {
- const r = { startRow: o, startColumn: s, endRow: o, endColumn: s }, i = this._ensureRTreeCollection(e), a = Array.from(i.bulkSearch([{ unitId: e, sheetId: t, range: r }]));
- if (a[0]) {
- const l = this._ensureRangeThemeStyleRuleMap(e).get(a[0]);
- if (l) {
- const { rangeInfo: c, themeName: d } = l, h = o - c.range.startRow, m = s - c.range.startColumn;
- return this.getRangeThemeStyle(e, d).getStyle(h, m, o === c.range.endRow, s === c.range.endColumn);
- }
- }
- }
- _registerIntercept() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(et.CELL_CONTENT, {
- id: Ns,
- effect: Vn.Style,
- handler: (e, t, o) => {
- const { row: s, col: r, unitId: i, subUnitId: a } = t, u = this.getCellStyle(i, a, s, r);
- if (u) {
- const l = { ...e };
- return l.themeStyle = u, o(l);
- }
- return o(e);
- }
- }));
- }
- toJson(e) {
- const t = this._ensureRangeThemeStyleRuleMap(e), o = this._ensureRangeThemeStyleMap(e);
- if (o.size === 0 && t.size === 0)
- return "{}";
- const s = {};
- t.forEach((i, a) => {
- s[a] = i;
- });
- const r = {};
- return o.forEach((i, a) => {
- r[a] = i.toJson();
- }), JSON.stringify({
- rangeThemeStyleRuleMap: s,
- rangeThemeStyleMapJson: r
- });
- }
- fromJSON(e) {
- const { rangeThemeStyleRuleMap: t, rangeThemeStyleMapJson: o } = e;
- this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._rTreeCollection.clear(), !(!t || !o) && (Object.keys(t).forEach((s) => {
- const r = t[s], { themeName: i, rangeInfo: a } = r;
- this.registerRangeThemeRule(i, a), this._ensureRTreeCollection(a.unitId).insert({ unitId: s, sheetId: a.subUnitId, range: a.range, id: s });
- }), Object.keys(o).forEach((s) => {
- const r = o[s], i = new yt(r.name);
- i.fromJson(r), this._ensureRangeThemeStyleMap(s).set(i.getName(), i);
- }));
- }
- deleteUnitId(e) {
- this._rangeThemeStyleMap.delete(e), this._rangeThemeStyleRuleMap.delete(e), this._rTreeCollection.delete(e);
- }
- _initSnapshot() {
- this.disposeWithMe(this._resourceManagerService.registerPluginResource({
- toJson: (e) => this.toJson(e),
- parseJson: (e) => {
- if (!e)
- return {};
- try {
- return JSON.parse(e);
- } catch {
- return {};
- }
- },
- businesses: [Fe.UNIVER_SHEET],
- pluginName: Ia,
- onLoad: (e, t) => {
- this.fromJSON(t);
- },
- onUnLoad: (e) => {
- this.deleteUnitId(e);
- }
- }));
- }
- dispose() {
- super.dispose(), this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._defaultRangeThemeMap.clear(), this._rTreeCollection.clear();
- }
- };
- He = wa([
- Ko2(0, ot(V)),
- Ko2(1, ot(Bi))
- ], He);
- function va(n, e) {
- const { unitId: t } = e, o = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(Fe.UNIVER_SHEET);
- return o ? {
- workbook: o,
- unitId: o.getUnitId()
- } : null;
- }
- function N(n, e = {}) {
- const { unitId: t, subUnitId: o } = e, s = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!s)
- return null;
- const r = o ? s.getSheetBySheetId(o) : s.getActiveSheet(true);
- return r ? {
- worksheet: r,
- workbook: s,
- unitId: s.getUnitId(),
- subUnitId: r.getSheetId()
- } : null;
- }
- function Et(n, e) {
- const { unitId: t, subUnitId: o } = e, s = n.getUniverSheetInstance(t);
- if (!s)
- return null;
- const r = s.getSheetBySheetId(o);
- return r ? {
- worksheet: r,
- workbook: s
- } : null;
- }
- var zt = {
- id: "sheet.mutation.set-worksheet-range-theme-style",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(_n), a = N(i), u = n.get(He);
- return a ? (u.registerRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), true) : false;
- }
- };
- var Ma = (n, e) => {
- const t = Et(n.get(_n), e);
- if (!t)
- throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- subUnitId: o.getSheetId(),
- range: e.range,
- themeName: e.themeName
- };
- };
- var Kt = {
- id: "sheet.mutation.remove-worksheet-range-theme-style",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(_n), a = N(i), u = n.get(He);
- return a ? (u.removeRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), true) : false;
- }
- };
- var _a = (n, e) => {
- const t = Et(n.get(_n), e);
- if (!t)
- throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- subUnitId: o.getSheetId(),
- range: e.range,
- themeName: e.themeName
- };
- };
- var ba = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-range-theme-style",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), { unitId: s } = e, r = Ma(n, e);
- return t.syncExecuteCommand(zt.id, e) ? (o.pushUndoRedo({
- unitID: s,
- undoMutations: [{ id: Kt.id, params: r }],
- redoMutations: [{ id: zt.id, params: e }]
- }), true) : false;
- }
- };
- var ya = (n, e, t = "") => n.reduce(
- (o, s) => {
- const r = s && s[e];
- return typeof r != "string" ? (console.warn(s, `${e} is not string`), o) : (r ? (o[r] || (o[r] = []), o[r].push(s)) : o[t].push(s), o);
- },
- {}
- );
- var Ea = (n = 0) => {
- let e = n;
- return function() {
- return e++;
- };
- };
- function Os(n) {
- const e = new kt();
- return n.forEach((t) => {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
- for (let a = o; a <= r; a++)
- for (let u = s; u <= i; u++)
- e.setValue(a, u, null);
- }), e.clone();
- }
- function Ua(n) {
- const e = new kt();
- return n.forEach((t) => {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
- for (let a = o; a <= r; a++)
- for (let u = s; u <= i; u++)
- e.setValue(a, u, {
- v: null,
- p: null,
- f: null,
- si: null,
- custom: null
- });
- }), e.clone();
- }
- function Pa(n) {
- const e = new kt();
- return n.forEach((t) => {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
- for (let a = o; a <= r; a++)
- for (let u = s; u <= i; u++)
- e.setValue(a, u, {
- s: null
- });
- }), e.clone();
- }
- var Ce = ((n) => (n[n.MOVE_START = 0] = "MOVE_START", n[n.MOVING = 1] = "MOVING", n[n.MOVE_END = 2] = "MOVE_END", n[n.ONLY_SET = 3] = "ONLY_SET", n))(Ce || {});
- var Ta = class extends nt {
- constructor(t) {
- super();
- R(this, "_worksheetSelections", /* @__PURE__ */ new Map());
- R(this, "_selectionMoveStart$", new Subject());
- R(this, "selectionMoveStart$", this._selectionMoveStart$.asObservable());
- R(this, "_selectionMoving$", new Subject());
- R(this, "selectionMoving$", this._selectionMoving$.asObservable());
- R(this, "_selectionMoveEnd$", new BehaviorSubject([]));
- R(this, "selectionMoveEnd$", this._selectionMoveEnd$.asObservable());
- R(this, "_selectionSet$", new BehaviorSubject([]));
- R(this, "selectionSet$", this._selectionSet$.asObservable());
- R(this, "selectionChanged$");
- R(this, "_beforeSelectionMoveEnd$", new BehaviorSubject([]));
- R(this, "beforeSelectionMoveEnd$", this._beforeSelectionMoveEnd$.asObservable());
- this._workbook = t, this.selectionChanged$ = merge(this._selectionMoveEnd$, this._selectionSet$);
- }
- dispose() {
- super.dispose(), this._beforeSelectionMoveEnd$.complete(), this._selectionMoveEnd$.complete(), this._selectionMoving$.complete(), this._selectionMoveStart$.complete(), this._selectionSet$.complete();
- }
- addSelections(t, o) {
- const s = this.getSelectionsOfWorksheet(t);
- s.push(...o), this._selectionSet$.next(s);
- }
- /**
- * Set selectionDatas to _worksheetSelections, and emit selectionDatas by type.
- * @param sheetId
- * @param selectionDatas
- * @param type
- */
- setSelections(t, o = [], s) {
- switch (this.setSelectionsOfWorksheet(t, o), s) {
- case Ce.MOVE_START:
- this._selectionMoveStart$.next(o);
- break;
- case Ce.MOVING:
- this._selectionMoving$.next(o);
- break;
- case Ce.MOVE_END:
- this._beforeSelectionMoveEnd$.next(o), this._selectionMoveEnd$.next(o);
- break;
- case Ce.ONLY_SET: {
- this._selectionSet$.next(o);
- break;
- }
- default:
- this._selectionSet$.next(o);
- break;
- }
- }
- getCurrentSelections() {
- return this._getCurrentSelections();
- }
- /**
- * @deprecated use `getSelectionsOfWorksheet` instead.
- * @param sheetId
- * @returns
- */
- getSelectionOfWorksheet(t) {
- return this.getSelectionsOfWorksheet(t);
- }
- getSelectionsOfWorksheet(t) {
- return this._worksheetSelections.has(t) || this._worksheetSelections.set(t, []), this._worksheetSelections.get(t);
- }
- setSelectionsOfWorksheet(t, o) {
- this._worksheetSelections.set(t, [...o]);
- }
- deleteSheetSelection(t) {
- this._worksheetSelections.set(t, []);
- }
- /** Clear all selections in this workbook. */
- clear() {
- this._worksheetSelections.clear(), this._selectionSet$.next([]);
- }
- _getCurrentSelections() {
- return this.getSelectionsOfWorksheet(this._workbook.getActiveSheet().getSheetId());
- }
- getCurrentLastSelection() {
- const t = this._getCurrentSelections();
- return t[t.length - 1];
- }
- };
- var ka = Object.defineProperty;
- var Na = Object.getOwnPropertyDescriptor;
- var Oa = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Na(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && ka(e, t, s), s;
- };
- var Da = (n, e) => (t, o) => e(t, o, n);
- var F = class extends J0 {
- constructor(e) {
- super();
- R(this, "selectionMoveStart$");
- R(this, "selectionMoving$");
- R(this, "selectionMoveEnd$");
- R(this, "selectionSet$");
- R(this, "selectionChanged$");
- R(this, "_workbookSelections", /* @__PURE__ */ new Map());
- this._instanceSrv = e, this._init();
- }
- get _currentSelectionPos() {
- const e = this._instanceSrv.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!e)
- return null;
- const t = e.getActiveSheet();
- return { unitId: e.getUnitId(), sheetId: t.getSheetId() };
- }
- get currentSelectionParam() {
- return this._currentSelectionPos;
- }
- _init() {
- const e = this._instanceSrv.getCurrentTypeOfUnit$(Fe.UNIVER_SHEET).pipe(shareReplay(1), takeUntil(this.dispose$));
- this.selectionMoveStart$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveStart$ : of())), this.selectionMoving$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoving$ : of())), this.selectionMoveEnd$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveEnd$ : of([]))), this.selectionSet$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionSet$ : of([]))), this.selectionChanged$ = e.pipe(switchMap((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionChanged$ : of([]))).pipe(
- distinctUntilChanged((t, o) => t.length !== o.length ? false : t.length === 0 && o.length === 0 ? true : t.every((s, r) => JSON.stringify(s) === JSON.stringify(o[r]))),
- skip(1)
- ), this._instanceSrv.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((t) => {
- this._removeWorkbookSelection(t.getUnitId());
- });
- }
- /**
- * Clear all selections in all workbooks.
- * invoked by prompt.controller
- */
- clear() {
- this._workbookSelections.forEach((e) => e.clear());
- }
- getCurrentSelections() {
- return this._getCurrentSelections();
- }
- getCurrentLastSelection() {
- const e = this._getCurrentSelections();
- return e == null ? void 0 : e[e.length - 1];
- }
- addSelections(e, t, o) {
- if (typeof e == "string") {
- this._ensureWorkbookSelection(e).addSelections(t, o);
- return;
- }
- const s = this._currentSelectionPos;
- if (!s)
- throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
- const { unitId: r, sheetId: i } = s;
- this._ensureWorkbookSelection(r).addSelections(i, e);
- }
- setSelections(e, t, o, s) {
- if (typeof e == "string" && typeof t == "string") {
- const u = e;
- this._ensureWorkbookSelection(u).setSelections(
- t,
- o || [],
- s != null ? s : Ce.ONLY_SET
- );
- return;
- }
- const r = this._currentSelectionPos;
- if (!r)
- throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
- const { unitId: i, sheetId: a } = r;
- if (typeof e == "object") {
- const u = e != null ? e : o, l = t != null ? t : Ce.ONLY_SET;
- this._ensureWorkbookSelection(i).setSelections(a, u, l);
- }
- }
- clearCurrentSelections() {
- this._getCurrentSelections().splice(0);
- }
- /**
- * Determine whether multiple current selections overlap
- *
- * @deprecated this should be extracted to an pure function
- */
- isOverlapping() {
- const e = this.getCurrentSelections();
- return e == null ? false : e.some(
- ({ range: t }, o) => e.some(({ range: s }, r) => o === r ? false : t.startRow <= s.endRow && t.endRow >= s.startRow && t.startColumn <= s.endColumn && t.endColumn >= s.startColumn)
- );
- }
- _getCurrentSelections() {
- const e = this._currentSelectionPos;
- if (!e)
- return [];
- const { unitId: t, sheetId: o } = e;
- return this._ensureWorkbookSelection(t).getSelectionsOfWorksheet(o);
- }
- getWorkbookSelections(e) {
- return this._ensureWorkbookSelection(e);
- }
- _ensureWorkbookSelection(e) {
- let t = this._workbookSelections.get(e);
- if (!t) {
- const o = this._instanceSrv.getUnit(e);
- if (!o)
- throw new Error(`[SheetsSelectionsService]: cannot resolve unit with id "${e}"!`);
- t = new Ta(o), this._workbookSelections.set(e, t);
- }
- return t;
- }
- _removeWorkbookSelection(e) {
- this._workbookSelections.delete(e);
- }
- };
- F = Oa([
- Da(0, _n)
- ], F);
- var jd = "DISABLE_NORMAL_SELECTIONS";
- var Gd = "SELECTIONS_ENABLED";
- var Aa = "REF_SELECTIONS_ENABLED";
- function xa(n, e, t) {
- var i;
- const o = n.getStyleByCell(e);
- o == null && delete e.s, typeof t.s == "string" && (t.s = n.get(t.s));
- const s = gn(o, t.s ? t.s : null);
- s && (re.removeNull(s), Object.entries(s).forEach(([a, u]) => {
- typeof u == "object" && u !== null && Object.keys(u).length === 0 && delete s[a];
- })), re.isEmptyObject(s) ? delete e.s : e.s = n.setValue(s);
- const r = t.v ? `${t.v}\r
- ` : "";
- !t.p && e.p && (r && r !== ((i = e.p.body) == null ? void 0 : i.dataStream) ? delete e.p : La(e.p, t.s ? t.s : null));
- }
- function $a(n, e) {
- if (!e || !Object.keys(e).length)
- return n;
- const t = n || {};
- for (const o in e)
- o === "bd" ? t[o] = Wa(t[o] || {}, e[o]) : o in t || (t[o] = null);
- return t;
- }
- function Wa(n, e) {
- if (!e || !Object.keys(e).length)
- return n;
- for (const t in e)
- t in n || (n[t] = null);
- return n;
- }
- function gn(n, e, t = false) {
- if (e === null)
- return e;
- if (e === void 0)
- return n;
- const o = re.deepClone(n) || {};
- for (const s in e)
- t && ["bd", "tr", "td", "ht", "vt", "tb", "pd", "bg"].includes(s) || (s in o && s === "bd" ? o[s] = Object.assign(o[s], e[s]) : o[s] = e[s]);
- return "cl" in o && ("ul" in o && o.ul && (o.ul.cl = o.cl), "ol" in o && o.ol && (o.ol.cl = o.cl), "st" in o && o.st && (o.st.cl = o.cl)), o;
- }
- function Ds(n, e) {
- return n.some((t) => t.startIndex === e) ? Ds(n, e + 1) : e;
- }
- function La(n, e) {
- var i;
- if (n.body == null)
- return;
- Array.isArray(n.body.textRuns) || (n.body.textRuns = []);
- let t = 0;
- const o = [], s = ((i = n.body) == null ? void 0 : i.paragraphs) || [];
- for (const a of n.body.textRuns) {
- const { st: u, ed: l, ts: c = {} } = a;
- if (t < u) {
- const h = {
- st: t,
- ed: u
- }, m = gn({}, e, true);
- m && re.removeNull(m), re.isEmptyObject(m) || (h.ts = m), o.push(h);
- }
- const d = gn(c, e, true);
- d && re.removeNull(d), re.isEmptyObject(d) ? delete a.ts : a.ts = d, o.push(a), t = Ds(s, l);
- }
- const r = n.body.dataStream.endsWith(`\r
- `) ? n.body.dataStream.length - 2 : n.body.dataStream.length;
- if (t < r) {
- const a = {
- st: t,
- ed: r
- }, u = gn({}, e, true);
- u && re.removeNull(u), re.isEmptyObject(u) || (a.ts = u), o.push(a);
- }
- n.body.textRuns = _s(o);
- }
- function Va(n, e, t) {
- if (e.t)
- return e.t;
- if (e.v === null)
- return null;
- const o = n.getStyleByCell(e), s = n.getStyleByCell(t);
- if (t.t === dn.FORCE_STRING) {
- if (!Qn(s) && e.v !== void 0) {
- if (DC(e.v))
- return dn.NUMBER;
- if (L0(`${e.v}`))
- return dn.BOOLEAN;
- }
- return dn.FORCE_STRING;
- }
- return Ha(o) ? Qn(o) ? dn.STRING : Jo(e, t) : Qn(s) ? dn.STRING : Jo(e, t);
- }
- function Jo(n, e) {
- return n.v !== void 0 ? Yo(n.v, n.t) : Yo(e.v, e.t);
- }
- function Ha(n) {
- var e;
- return !!((e = n == null ? void 0 : n.n) != null && e.pattern);
- }
- function Qn(n) {
- var e;
- return ((e = n == null ? void 0 : n.n) == null ? void 0 : e.pattern) === T;
- }
- function Yo(n, e) {
- return n === null ? null : typeof n == "string" ? DC(n) ? (+n == 0 || +n == 1) && e === dn.BOOLEAN ? dn.BOOLEAN : dn.NUMBER : L0(n) ? dn.BOOLEAN : dn.STRING : typeof n == "number" ? (n === 0 || n === 1) && e === dn.BOOLEAN ? dn.BOOLEAN : dn.NUMBER : typeof n == "boolean" ? dn.BOOLEAN : dn.FORCE_STRING;
- }
- function Xo(n, e) {
- return n === dn.NUMBER ? Number(e.v) : n === dn.BOOLEAN ? Ba(e.v) ? 1 : 0 : n === dn.STRING || n === dn.FORCE_STRING ? `${e.v}` : e.v;
- }
- function Ba(n) {
- if (typeof n == "string") {
- if (n.toUpperCase() === "TRUE")
- return true;
- if (n.toUpperCase() === "FALSE")
- return false;
- if (bR(n)) {
- if (Number(n) === 0)
- return false;
- if (Number(n) === 1)
- return true;
- }
- }
- if (typeof n == "number") {
- if (n === 0)
- return false;
- if (n === 1)
- return true;
- }
- return typeof n == "boolean" ? n : null;
- }
- function Fa(n) {
- return n == null ? null : (n.f === void 0 && (n.f = null), n.si === void 0 && (n.si = null), n.p === void 0 && (n.p = null), n.v === void 0 && (n.v = null), n.t === void 0 && (n.t = null), n.s === void 0 && (n.s = null), n.custom === void 0 && (n.custom = null), n);
- }
- var Ae = (n, e) => {
- const { unitId: t, subUnitId: o, cellValue: s } = e, i = n.get(_n).getUniverSheetInstance(t);
- if (i == null)
- throw new Error("workbook is null error!");
- const a = i.getSheetBySheetId(o);
- if (a == null)
- throw new Error("worksheet is null error!");
- const u = a.getCellMatrix(), l = i.getStyles(), c = new kt();
- return new kt(s).forValue((h, m, g2) => {
- const f = re.deepClone(u == null ? void 0 : u.getValue(h, m)) || {}, p = l.getStyleByCell(f), C = l.getStyleByCell(g2);
- f.s = $a(p, C), c.setValue(h, m, Fa(f));
- }), {
- ...e,
- options: {},
- cellValue: c.getMatrix()
- };
- };
- var Q = {
- id: "sheet.mutation.set-range-values",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { cellValue: t, subUnitId: o, unitId: s } = e, i = n.get(_n).getUnit(s);
- if (!i)
- return false;
- const a = i.getSheetBySheetId(o);
- if (!a)
- return false;
- const u = a.getCellMatrix(), l = i.getStyles();
- return new kt(t).forValue((d, h, m) => {
- if (!m)
- u == null || u.setValue(d, h, {});
- else {
- const g2 = u.getValue(d, h) || {}, f = Va(l, m, g2);
- m.f !== void 0 && (g2.f = m.f), m.si !== void 0 && (g2.si = m.si), m.p !== void 0 && (g2.p = m.p), m.v !== void 0 && (g2.v = Xo(f, m)), g2.v !== void 0 && (g2.t = f, g2.v = Xo(f, g2)), m.s !== void 0 && xa(l, g2, m), m.custom !== void 0 && (g2.custom = m.custom), u.setValue(d, h, re.removeNull(g2));
- }
- }), true;
- }
- };
- var po = {
- id: "sheet.command.clear-selection-all",
- type: ar.COMMAND,
- handler: (n, e) => {
- var S;
- const t = n.get(_n), o = n.get(Pt), s = n.get(F), r = n.get(cn), i = n.get(V), a = t.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!a)
- return false;
- const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
- if (!l)
- return false;
- const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range));
- if (!(d != null && d.length))
- return false;
- const h = [], m = [], g2 = {
- subUnitId: c,
- unitId: u,
- cellValue: Os(d)
- }, f = Ae(
- n,
- g2
- );
- h.push({
- id: Q.id,
- params: g2
- }), m.push({
- id: Q.id,
- params: f
- });
- const p = i.onCommandExecute({ id: po.id });
- return h.push(...p.redos), m.unshift(...p.undos), mu(h, o) ? (r.pushUndoRedo({
- // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
- // Hooks can be used to hook the code of external controllers to add new actions.
- unitID: u,
- undoMutations: m,
- redoMutations: h
- }), true) : false;
- }
- };
- var Co = {
- id: "sheet.command.clear-selection-content",
- type: ar.COMMAND,
- handler: (n, e) => {
- var S;
- const t = n.get(_n), o = n.get(Pt), s = n.get(F), r = n.get(cn), i = n.get(V), a = t.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!a)
- return false;
- const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
- if (!l)
- return false;
- const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range));
- if (!(d != null && d.length))
- return false;
- const h = {
- subUnitId: c,
- unitId: u,
- cellValue: Ua(d)
- }, m = Ae(
- n,
- h
- ), g2 = i.onCommandExecute({ id: Co.id }), f = [{ id: Q.id, params: h }, ...g2.redos], p = [...g2.undos, { id: Q.id, params: m }];
- return mu(f, o).result ? (r.pushUndoRedo({
- // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
- // Hooks can be used to hook the code of external controllers to add new actions.
- unitID: u,
- undoMutations: p,
- redoMutations: f
- }), true) : false;
- }
- };
- var So = {
- id: "sheet.command.clear-selection-format",
- type: ar.COMMAND,
- handler: (n, e) => {
- var S;
- const t = n.get(_n), o = n.get(Pt), s = n.get(F), r = n.get(cn), i = n.get(V), a = t.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!a)
- return false;
- const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
- if (!l)
- return false;
- const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range));
- if (!(d != null && d.length))
- return false;
- const h = [], m = [], g2 = {
- subUnitId: c,
- unitId: u,
- cellValue: Pa(d)
- }, f = Ae(
- n,
- g2
- );
- h.push({
- id: Q.id,
- params: g2
- }), m.push({
- id: Q.id,
- params: f
- });
- const p = i.onCommandExecute({ id: So.id });
- return h.push(...p.redos), m.unshift(...p.undos), mu(h, o) ? (r.pushUndoRedo({
- // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
- // Hooks can be used to hook the code of external controllers to add new actions.
- unitID: u,
- undoMutations: m,
- redoMutations: h
- }), true) : false;
- }
- };
- var As = (n, e) => ({
- subUnitId: e.sheet.id,
- unitId: e.unitId,
- subUnitName: e.sheet.name
- });
- var Jt = {
- id: "sheet.mutation.insert-sheet",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n), { sheet: o, index: s, unitId: r } = e, i = t.getUniverSheetInstance(r);
- return i ? i.addWorksheet(o.id, s, o) : false;
- }
- };
- var ja = (n, e) => {
- const t = n.get(_n), { subUnitId: o, unitId: s } = e, r = Et(t, e);
- if (!r)
- throw new Error("[RemoveSheetUndoMutationFactory]: Worksheet is null error!");
- const { workbook: i, worksheet: a } = r, u = a.getConfig();
- return {
- index: i.getConfig().sheetOrder.findIndex((d) => d === o),
- sheet: u,
- unitId: s
- };
- };
- var Ut = {
- id: "sheet.mutation.remove-sheet",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n), { subUnitId: o, unitId: s } = e, r = t.getUniverSheetInstance(s);
- return r ? r.removeSheet(o) : false;
- }
- };
- var xs = {
- type: ar.COMMAND,
- id: "sheet.command.copy-sheet",
- handler: (n, e) => {
- var w, b;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), i = n.get(Vr), a = N(s, e);
- if (!a)
- return false;
- const { workbook: u, worksheet: l, unitId: c, subUnitId: d } = a, h = re.deepClone(l.getConfig());
- h.name = Ga(u, i, h.name), h.id = re.generateRandomId();
- const g2 = {
- index: u.getSheetIndex(l) + 1,
- sheet: h,
- unitId: c
- }, f = As(
- n,
- g2
- ), p = r.onCommandExecute({
- id: xs.id,
- params: { unitId: c, subUnitId: d, targetSubUnitId: h.id }
- }), C = [
- ...(w = p.preRedos) != null ? w : [],
- { id: Jt.id, params: g2 },
- ...p.redos
- ], S = [
- ...(b = p.preUndos) != null ? b : [],
- { id: Ut.id, params: f },
- ...p.undos
- ];
- return mu(C, t).result ? (o.pushUndoRedo({
- unitID: c,
- undoMutations: S,
- redoMutations: C
- }), true) : false;
- }
- };
- function Ga(n, e, t) {
- let o = t + e.t("sheets.tabs.sheetCopy", ""), s = 2;
- for (; n.checkSheetName(o); )
- o = t + e.t("sheets.tabs.sheetCopy", `${s}`), s++;
- return o;
- }
- var dt = {
- id: "sheet.mutation.move-range",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { from: t, to: o } = e;
- if (!t || !o)
- return false;
- const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!r)
- return false;
- const i = r.getSheetBySheetId(e.from.subUnitId), a = r.getSheetBySheetId(e.to.subUnitId);
- if (!i || !a)
- return false;
- const u = i.getCellMatrix(), l = a.getCellMatrix();
- return new kt(t.value).forValue((c, d, h) => {
- u.setValue(c, d, h);
- }), new kt(o.value).forValue((c, d, h) => {
- l.setValue(c, d, h);
- }), true;
- }
- };
- var za = Object.defineProperty;
- var Ka = Object.getOwnPropertyDescriptor;
- var Ja = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Ka(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && za(e, t, s), s;
- };
- var Ya = (n, e) => (t, o) => e(t, o, n);
- var Xa = Ct("sheets-formula.ref-selections.service");
- var qo = class extends F {
- constructor(n) {
- super(n);
- }
- _init() {
- const n = this._getAliveWorkbooks$().pipe(takeUntil(this.dispose$));
- this.selectionMoveStart$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionMoveStart$)))), this.selectionMoving$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionMoving$)))), this.selectionMoveEnd$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionMoveEnd$)))), this.selectionSet$ = n.pipe(switchMap((e) => merge(...e.map((t) => t.selectionSet$))));
- }
- _getAliveWorkbooks$() {
- const n = this._instanceSrv.getAllUnitsForType(Fe.UNIVER_SHEET);
- n.forEach((t) => this._ensureWorkbookSelection(t.getUnitId()));
- const e = new BehaviorSubject(n);
- return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((t) => {
- this._ensureWorkbookSelection(t.getUnitId()), e.next([...e.getValue(), t]);
- })), this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).subscribe((t) => {
- this._removeWorkbookSelection(t.getUnitId()), e.next(e.getValue().filter((o) => o !== t));
- })), e.pipe(map((t) => t.map((o) => this._ensureWorkbookSelection(o.getUnitId()))));
- }
- };
- qo = Ja([
- Ya(0, _n)
- ], qo);
- function qa(n, e) {
- const o = n.get(fs).getContextValue(Aa);
- return n.get(o && !e ? Xa : F);
- }
- var re2 = {
- id: "sheet.operation.set-selections",
- type: ar.OPERATION,
- handler: (n, e) => {
- if (!e)
- return false;
- const { selections: t, type: o, unitId: s, subUnitId: r } = e;
- return qa(n).setSelections(s, r, [...t], o), true;
- }
- };
- function Ln(n, e, t = true) {
- const o = e.getMatrixWithMergedCells(..._C(n)), s = [];
- if (o.forValue((i, a, u) => {
- if (u.colSpan !== void 0 && u.rowSpan !== void 0) {
- const l = {
- startRow: i,
- startColumn: a,
- endRow: i + u.rowSpan - 1,
- endColumn: a + u.colSpan - 1
- };
- en.contains(n, l) || s.push(l);
- }
- }), s.length === 0)
- return n;
- const r = en.union(n, ...s);
- return t ? Ln(r, e, t) : r;
- }
- function zd(n, e, t) {
- let o = null;
- return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = {
- actualRow: r,
- actualColumn: i,
- startRow: r,
- startColumn: i,
- isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0,
- isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0,
- endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0),
- endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0),
- rangeType: De.NORMAL
- }, false)), o || {
- actualColumn: e,
- actualRow: n,
- startRow: n,
- startColumn: e,
- endRow: n,
- endColumn: e,
- isMerged: false,
- isMergedMainCell: false,
- rangeType: De.NORMAL
- };
- }
- function Kd(n, e, t) {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = n;
- return Number.isNaN(o) && (n.startRow = 0), Number.isNaN(r) && (n.endRow = e - 1), Number.isNaN(s) && (n.startColumn = 0), Number.isNaN(i) && (n.endColumn = t - 1), n;
- }
- function ve(n, e) {
- const t = Number.isNaN(n.startRow) ? 0 : n.startRow, o = Number.isNaN(n.startColumn) ? 0 : n.startColumn, s = e.getMergedCell(t, o);
- return s ? {
- ...s,
- actualRow: t,
- actualColumn: o,
- rangeType: De.NORMAL,
- isMerged: true,
- isMergedMainCell: true
- } : {
- startRow: t,
- startColumn: o,
- endRow: n.startRow,
- endColumn: n.startColumn,
- actualRow: t,
- actualColumn: o,
- rangeType: De.NORMAL,
- isMerged: false,
- isMergedMainCell: false
- };
- }
- var Xe2 = (n, e, t) => ({
- id: re2.id,
- params: {
- unitId: e.getUnitId(),
- subUnitId: t.getSheetId(),
- reveal: true,
- selections: [{ range: n, primary: ve(n, t) }]
- }
- });
- function Jd(n) {
- if (!n)
- return false;
- const { range: e, primary: t } = n;
- return en.equals(e, t);
- }
- function Za(n) {
- function e(t, o) {
- function s(r) {
- for (let i = r.startRow; i <= r.endRow; i++)
- if (!n.getRowFiltered(i))
- for (let a = r.startColumn; a <= r.endColumn; a++)
- o(i, a, r);
- }
- s(t);
- }
- return {
- forOperableEach: e
- };
- }
- var Zo = (n) => n.id !== Ns;
- function Vn2(n, e, t, o, s, r, i) {
- const a = {};
- for (let u = e; u <= t; u++)
- for (let l = o; l <= s; l++) {
- const c = r ? n.getCellWithFilteredInterceptors(i, l, jo, Zo) : n.getCellWithFilteredInterceptors(u, i, jo, Zo);
- !c || !c.s || (a[u] || (a[u] = {}), a[u][l] = { s: c.s });
- }
- return a;
- }
- var $s = "sheet.command.move-range";
- var pt = {
- type: ar.COMMAND,
- id: $s,
- handler: async (n, e) => {
- var I, w;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(NE), i = n.get(Vr), a = n.get(V), u = N(s);
- if (!u || !await a.beforeCommandExecute({ id: pt.id, params: e }))
- return false;
- const { worksheet: c, subUnitId: d, unitId: h } = u, m = wo2(
- n,
- { unitId: h, subUnitId: d, range: e.fromRange },
- { unitId: h, subUnitId: d, range: e.toRange }
- );
- if (m === null)
- return r.emit(i.t("sheets.info.acrossMergedCell")), false;
- const g2 = a.onCommandExecute({
- id: pt.id,
- params: { ...e }
- }), f = [
- ...(I = g2.preRedos) != null ? I : [],
- ...m.redos,
- ...g2.redos,
- {
- id: re2.id,
- params: {
- unitId: h,
- subUnitId: d,
- selections: [{ range: e.toRange, primary: Qa(e.fromRange, e.toRange, c) }],
- type: Ce.MOVE_END
- }
- }
- ], p = [
- ...(w = g2.preUndos) != null ? w : [],
- ...m.undos,
- ...g2.undos,
- {
- id: re2.id,
- params: {
- unitId: h,
- subUnitId: d,
- selections: [{ range: e.fromRange, primary: ve(e.fromRange, c) }],
- type: Ce.MOVE_END
- }
- }
- ], C = mu(f, t).result, S = a.afterCommandExecute({
- id: pt.id,
- params: { ...e }
- });
- return C ? (mu(S.redos, t), o.pushUndoRedo({
- unitID: h,
- undoMutations: [...p, ...S.undos],
- redoMutations: [...f, ...S.redos]
- }), true) : false;
- }
- };
- function wo2(n, e, t, o = false) {
- const s = [], r = [], { range: i, subUnitId: a, unitId: u } = e, { range: l, subUnitId: c } = t, h = n.get(_n).getUniverSheetInstance(u), m = h == null ? void 0 : h.getSheetBySheetId(c), g2 = h == null ? void 0 : h.getSheetBySheetId(a), f = m == null ? void 0 : m.getCellMatrix(), p = g2 == null ? void 0 : g2.getCellMatrix();
- if (m && g2 && f && p) {
- const C = Ln(l, m, false);
- if (!en.equals(l, C) && !o)
- return null;
- const S = new kt(), I = new kt(), w = new kt();
- tr.foreach(i, (U, P) => {
- const A = p.getValue(U, P);
- if (S.setValue(U, P, re.deepClone(A)), A) {
- const j = h == null ? void 0 : h.getStyles().get(A.s);
- w.setValue(U, P, re.deepClone(j));
- }
- I.setValue(U, P, null);
- });
- const b = new kt(), y = new kt();
- tr.foreach(l, (U, P) => {
- b.setValue(U, P, re.deepClone(f.getValue(U, P)));
- }), tr.foreach(i, (U, P) => {
- const A = AC(U, P), j = en.getRelativeRange(A, i), Z = en.getPositionRange(j, l), Y = re.deepClone(w.getValue(U, P)), ee = re.deepClone(S.getValue(U, P));
- ee && Y && (ee.s = Y), y.setValue(Z.startRow, Z.startColumn, ee);
- });
- const x = {
- fromRange: e.range,
- toRange: t.range,
- from: {
- value: I.getMatrix(),
- subUnitId: a
- },
- to: {
- value: y.getMatrix(),
- subUnitId: c
- },
- unitId: u
- }, T2 = {
- fromRange: t.range,
- toRange: e.range,
- from: {
- value: S.getMatrix(),
- subUnitId: a
- },
- to: {
- value: b.getMatrix(),
- subUnitId: c
- },
- unitId: u
- };
- s.push({ id: dt.id, params: x }), r.push({ id: dt.id, params: T2 });
- }
- return {
- redos: s,
- undos: r
- };
- }
- function Qa(n, e, t) {
- const o = n.startRow, s = n.startColumn, r = t.getMergedCell(o, s), i = ve(e, t);
- if (r) {
- const a = r.endRow - r.startRow + 1, u = r.endColumn - r.startColumn + 1;
- i.endRow = i.startRow + a - 1, i.endColumn = i.startColumn + u - 1, i.actualRow = i.startRow, i.actualColumn = i.startColumn, i.isMerged = false, i.isMergedMainCell = true;
- }
- return i;
- }
- var Sn = ((n) => (n[n.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", n[n.UNIVER_DOC = 1] = "UNIVER_DOC", n[n.UNIVER_SHEET = 2] = "UNIVER_SHEET", n[n.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", n[n.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n))(Sn || {});
- var _ = ((n) => (n[n.View = 0] = "View", n[n.Edit = 1] = "Edit", n[n.ManageCollaborator = 2] = "ManageCollaborator", n[n.Print = 3] = "Print", n[n.Duplicate = 4] = "Duplicate", n[n.Comment = 5] = "Comment", n[n.Copy = 6] = "Copy", n[n.Share = 7] = "Share", n[n.Export = 8] = "Export", n[n.MoveWorksheet = 9] = "MoveWorksheet", n[n.DeleteWorksheet = 10] = "DeleteWorksheet", n[n.HideWorksheet = 11] = "HideWorksheet", n[n.RenameWorksheet = 12] = "RenameWorksheet", n[n.CreateWorksheet = 13] = "CreateWorksheet", n[n.SetWorksheetStyle = 14] = "SetWorksheetStyle", n[n.EditWorksheetCell = 15] = "EditWorksheetCell", n[n.InsertHyperlink = 16] = "InsertHyperlink", n[n.Sort = 17] = "Sort", n[n.Filter = 18] = "Filter", n[n.PivotTable = 19] = "PivotTable", n[n.FloatImg = 20] = "FloatImg", n[n.History = 21] = "History", n[n.RwHgtClWdt = 22] = "RwHgtClWdt", n[n.ViemRwHgtClWdt = 23] = "ViemRwHgtClWdt", n[n.ViewFilter = 24] = "ViewFilter", n[n.MoveSheet = 25] = "MoveSheet", n[n.DeleteSheet = 26] = "DeleteSheet", n[n.HideSheet = 27] = "HideSheet", n[n.CopySheet = 28] = "CopySheet", n[n.RenameSheet = 29] = "RenameSheet", n[n.CreateSheet = 30] = "CreateSheet", n[n.SelectProtectedCells = 31] = "SelectProtectedCells", n[n.SelectUnProtectedCells = 32] = "SelectUnProtectedCells", n[n.SetCellStyle = 33] = "SetCellStyle", n[n.SetCellValue = 34] = "SetCellValue", n[n.SetRowStyle = 35] = "SetRowStyle", n[n.SetColumnStyle = 36] = "SetColumnStyle", n[n.InsertRow = 37] = "InsertRow", n[n.InsertColumn = 38] = "InsertColumn", n[n.DeleteRow = 39] = "DeleteRow", n[n.DeleteColumn = 40] = "DeleteColumn", n[n.EditExtraObject = 41] = "EditExtraObject", n[n.Delete = 42] = "Delete", n[n.RecoverHistory = 43] = "RecoverHistory", n[n.ViewHistory = 44] = "ViewHistory", n[n.CreatePermissionObject = 45] = "CreatePermissionObject", n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n))(_ || {});
- var D = ((n) => (n[n.Unkonwn = 0] = "Unkonwn", n[n.Workbook = 1] = "Workbook", n[n.Worksheet = 2] = "Worksheet", n[n.SelectRange = 3] = "SelectRange", n[n.Document = 4] = "Document", n[n.Slide = 5] = "Slide", n[n.UNRECOGNIZED = -1] = "UNRECOGNIZED", n))(D || {});
- var Pe = class {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.Edit);
- R(this, "status", fl.INIT);
- R(this, "value", true);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Edit}.${o}`;
- }
- };
- var Io = class {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.View);
- R(this, "status", fl.INIT);
- R(this, "value", true);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.View}.${o}`;
- }
- };
- var Ws = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Comment);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Comment}_${e}`;
- }
- };
- var Ls = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Copy);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Copy}_${e}`;
- }
- };
- var eu = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "subType", _.CopySheet);
- R(this, "status", fl.INIT);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CopySheet}_${e}`;
- }
- };
- var Vs2 = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.CreatePermissionObject);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreatePermissionObject}_${e}`;
- }
- };
- var Hs = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.CreateSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreateSheet}_${e}`;
- }
- };
- var Bs = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.DeleteSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.DeleteSheet}_${e}`;
- }
- };
- var Fs = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Duplicate);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Duplicate}_${e}`;
- }
- };
- var Me = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Edit);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Edit}_${e}`;
- }
- };
- var js = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Export);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Export}_${e}`;
- }
- };
- var vo = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.HideSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.HideSheet}_${e}`;
- }
- };
- var tu = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.History);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.History}_${e}`;
- }
- };
- var Mo = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.ManageCollaborator);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ManageCollaborator}_${e}`;
- }
- };
- var _o = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.MoveSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.MoveSheet}_${e}`;
- }
- };
- var Gs2 = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Print);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Print}_${e}`;
- }
- };
- var zs = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.RecoverHistory);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RecoverHistory}_${e}`;
- }
- };
- var bo = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.RenameSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RenameSheet}_${e}`;
- }
- };
- var Ks = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.Share);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Share}_${e}`;
- }
- };
- var Js = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.View);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.View}_${e}`;
- }
- };
- var Ys = class {
- constructor(e) {
- R(this, "id");
- R(this, "value", true);
- R(this, "type", D.Workbook);
- R(this, "status", fl.INIT);
- R(this, "subType", _.ViewHistory);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ViewHistory}_${e}`;
- }
- };
- var Xs = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.Copy);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Copy}_${e}_${t}`;
- }
- };
- var qs = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.DeleteColumn);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteColumn}_${e}_${t}`;
- }
- };
- var Zs = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.Delete);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Delete}_${e}_${t}`;
- }
- };
- var Qs = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.DeleteRow);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteRow}_${e}_${t}`;
- }
- };
- var Te = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.Edit);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Edit}_${e}_${t}`;
- }
- };
- var er = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.EditExtraObject);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.EditExtraObject}_${e}_${t}`;
- }
- };
- var tr2 = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.Filter);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Filter}_${e}_${t}`;
- }
- };
- var nr = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.InsertColumn);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertColumn}_${e}_${t}`;
- }
- };
- var or = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.InsertHyperlink);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertHyperlink}_${e}_${t}`;
- }
- };
- var sr = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.InsertRow);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertRow}_${e}_${t}`;
- }
- };
- var rr2 = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.ManageCollaborator);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.ManageCollaborator}_${e}_${t}`;
- }
- };
- var ir = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.PivotTable);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.PivotTable}_${e}_${t}`;
- }
- };
- var nu2 = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.SelectProtectedCells);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectProtectedCells}_${e}_${t}`;
- }
- };
- var ou = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.SelectUnProtectedCells);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`;
- }
- };
- var ar2 = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.SetCellStyle);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellStyle}_${e}_${t}`;
- }
- };
- var wn = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.SetCellValue);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellValue}_${e}_${t}`;
- }
- };
- var $t = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.SetColumnStyle);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetColumnStyle}_${e}_${t}`;
- }
- };
- var Wt = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.SetRowStyle);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetRowStyle}_${e}_${t}`;
- }
- };
- var ur = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.Sort);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Sort}_${e}_${t}`;
- }
- };
- var Hn = class {
- constructor(e, t) {
- R(this, "value", true);
- R(this, "type", D.Worksheet);
- R(this, "status", fl.INIT);
- R(this, "id");
- R(this, "subType", _.View);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.View}_${e}_${t}`;
- }
- };
- var on = {
- id: "sheet.command.set-range-values",
- type: ar.COMMAND,
- handler: (n, e) => {
- var T2;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = n.get(UE), u = N(s, e);
- if (!u)
- return false;
- const { subUnitId: l, unitId: c, workbook: d, worksheet: h } = u, { value: m, range: g2 } = e, f = g2 ? [g2] : (T2 = r.getCurrentSelections()) == null ? void 0 : T2.map((U) => U.range);
- if (!f || !f.length || !a.getPermissionPoint(new Te(c, l).id))
- return false;
- const p = new kt();
- let C;
- if (re.isArray(m))
- for (let U = 0; U < f.length; U++) {
- const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U];
- for (let Y = 0; Y <= j - P; Y++)
- for (let ee = 0; ee <= Z - A; ee++)
- p.setValue(Y + P, ee + A, m[Y][ee]);
- }
- else if (fC(m))
- for (let U = 0; U < f.length; U++) {
- const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U];
- for (let Y = P; Y <= j; Y++)
- for (let ee = A; ee <= Z; ee++)
- p.setValue(Y, ee, m);
- }
- else
- C = m;
- const S = { subUnitId: l, unitId: c, cellValue: C != null ? C : p.getMatrix() }, I = Ae(n, S);
- if (!t.syncExecuteCommand(Q.id, S))
- return false;
- const { undos: b, redos: y } = i.onCommandExecute({
- id: on.id,
- params: { ...S, range: f }
- });
- if (mu([...y], t).result) {
- const U = Xe2(g2 != null ? g2 : p.getRange(), d, h);
- return o.pushUndoRedo({
- unitID: c,
- undoMutations: [
- { id: Q.id, params: I },
- ...b,
- U
- ],
- redoMutations: [
- { id: Q.id, params: S },
- ...y,
- re.deepClone(U)
- ]
- }), true;
- }
- return false;
- }
- };
- function lr(n, e) {
- const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a, cellValue: u = {} } = e, l = n.get(_n), c = n.get(V), d = l.getUniverSheetInstance(s), h = d == null ? void 0 : d.getSheetBySheetId(r);
- if (h) {
- const m = h.getCellMatrix(), g2 = m.getDataRange();
- if (i.startColumn <= g2.endColumn || i.startRow <= g2.endRow) {
- let I, w;
- if (a === yu.COLUMNS) {
- const y = Math.min(i.endRow, g2.endRow);
- let x = 0;
- for (let U = i.startRow; U <= y; U++) {
- const P = m.getRow(U), A = P ? fn(P) - 1 : 0;
- x = Math.max(x, A);
- }
- I = {
- startRow: i.startRow,
- startColumn: i.startColumn,
- endRow: y,
- endColumn: x
- };
- const T2 = i.endColumn - i.startColumn + 1;
- w = {
- startRow: i.startRow,
- startColumn: I.startColumn + T2,
- endRow: y,
- endColumn: I.endColumn + T2
- };
- } else {
- const y = Math.min(i.endColumn, g2.endColumn), x = g2.endRow;
- I = {
- startRow: i.startRow,
- startColumn: i.startColumn,
- endRow: x,
- endColumn: y
- };
- const T2 = i.endRow - i.startRow + 1;
- w = {
- startRow: I.startRow + T2,
- startColumn: i.startColumn,
- endRow: I.endRow + T2,
- endColumn: y
- };
- }
- const b = wo2(
- n,
- { unitId: s, subUnitId: r, range: I },
- { unitId: s, subUnitId: r, range: w },
- true
- );
- b && (t.push(...b.redos), o.push(...b.undos));
- }
- if (Object.entries(u).length === 0)
- for (let I = i.startRow; I <= i.endRow; I++) {
- u[I] || (u[I] = {});
- for (let w = i.startColumn; w <= i.endColumn; w++)
- u[I][w] = null;
- }
- const f = {
- subUnitId: r,
- unitId: s,
- cellValue: u
- }, p = Ae(
- n,
- f
- ), { undos: C, redos: S } = c.onCommandExecute({
- id: on.id,
- params: { ...f, range: i }
- });
- t.push({ id: Q.id, params: f }, ...S), o.push({ id: Q.id, params: p }, ...C);
- }
- return {
- redo: t,
- undo: o
- };
- }
- function cr(n, e) {
- const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a } = e, u = n.get(_n), l = n.get(V), c = u.getUniverSheetInstance(s), d = c == null ? void 0 : c.getSheetBySheetId(r);
- if (d) {
- const h = d.getCellMatrix(), m = h.getDataRange(), g2 = {
- subUnitId: r,
- unitId: s,
- cellValue: Os([i])
- }, f = Ae(
- n,
- g2
- ), p = l.onCommandExecute({
- id: on.id,
- params: g2
- });
- if (t.push({ id: Q.id, params: g2 }, ...p.redos), o.push(...p.undos, {
- id: Q.id,
- params: f
- }), i.startColumn <= m.endColumn || i.startRow <= m.endRow) {
- let C = null, S = null;
- if (a === yu.COLUMNS && i.endColumn < m.endColumn) {
- const I = Math.min(i.endRow, m.endRow);
- let w = 0;
- for (let y = i.startRow; y <= I; y++) {
- const x = h.getRow(y), T2 = x ? fn(x) - 1 : 0;
- w = Math.max(w, T2);
- }
- C = {
- startRow: i.startRow,
- startColumn: i.endColumn + 1,
- endRow: I,
- endColumn: w
- };
- const b = i.endColumn - i.startColumn + 1;
- S = {
- startRow: i.startRow,
- startColumn: C.startColumn - b,
- endRow: I,
- endColumn: C.endColumn - b
- };
- }
- if (a === yu.ROWS && i.endRow < m.endRow) {
- const I = Math.min(i.endColumn, m.endColumn), w = m.endRow;
- C = {
- startRow: i.endRow + 1,
- startColumn: i.startColumn,
- endRow: w,
- endColumn: I
- };
- const b = i.endRow - i.startRow + 1;
- S = {
- startRow: C.startRow - b,
- startColumn: i.startColumn,
- endRow: C.endRow - b,
- endColumn: I
- };
- }
- if (C && S) {
- const I = wo2(
- n,
- { unitId: s, subUnitId: r, range: C },
- { unitId: s, subUnitId: r, range: S },
- true
- );
- I && (t.push(...I.redos), o.push(...I.undos));
- }
- }
- }
- return {
- redo: t,
- undo: o
- };
- }
- function Yd(n, e, t, o, s, r) {
- const { startRow: i, endRow: a, startColumn: u, endColumn: l } = e;
- if (s === yu.ROWS) {
- const c = a - i + 1;
- for (let d = t; d >= i; d--)
- for (let h = u; h <= l; h++) {
- const m = n.getValue(d, h);
- m == null ? n.realDeleteValue(d + c, h) : n.setValue(d + c, h, m);
- }
- for (let d = a; d >= i; d--)
- for (let h = u; h <= l; h++)
- r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h);
- } else if (s === yu.COLUMNS) {
- const c = l - u + 1;
- for (let d = i; d <= a; d++)
- for (let h = o; h >= u; h--) {
- const m = n.getValue(d, h);
- m == null ? n.realDeleteValue(d, h + c) : n.setValue(d, h + c, m);
- }
- for (let d = i; d <= a; d++)
- for (let h = l; h >= u; h--)
- r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h);
- }
- }
- function Xd(n, e, t, o, s) {
- const { startRow: r, endRow: i, startColumn: a, endColumn: u } = e, l = i - r + 1, c = u - a + 1;
- if (s === yu.ROWS)
- for (let d = r; d <= t; d++)
- for (let h = a; h <= u; h++) {
- const m = n.getValue(d + l, h);
- m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m);
- }
- else if (s === yu.COLUMNS)
- for (let d = r; d <= i; d++)
- for (let h = a; h <= o; h++) {
- const m = n.getValue(d, h + c);
- m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m);
- }
- }
- var dr = "sheet.command.delete-range-move-left";
- var Pt2 = {
- type: ar.COMMAND,
- id: dr,
- handler: async (n, e) => {
- var w, b, y;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = N(s);
- if (!a)
- return false;
- const { worksheet: u, workbook: l, subUnitId: c, unitId: d } = a;
- let h = e == null ? void 0 : e.range;
- if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h)
- return false;
- const m = {
- range: h,
- subUnitId: c,
- unitId: d,
- shiftDimension: yu.COLUMNS
- }, g2 = i.onCommandExecute({
- id: Pt2.id,
- params: { range: h }
- }), { redo: f, undo: p } = cr(
- n,
- m
- ), C = [...(b = g2.preRedos) != null ? b : [], ...f], S = [...g2.undos, ...p];
- return C.push(...g2.redos), C.push(Xe2(h, l, u)), S.push(...(y = g2.preUndos) != null ? y : []), mu(C, t).result ? (o.pushUndoRedo({
- unitID: d,
- undoMutations: S.reverse(),
- redoMutations: C
- }), true) : false;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- };
- var hr = "sheet.command.delete-range-move-up";
- var Tt = {
- type: ar.COMMAND,
- id: hr,
- handler: async (n, e) => {
- var w, b, y;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = N(s);
- if (!a)
- return false;
- const { unitId: u, subUnitId: l, workbook: c, worksheet: d } = a;
- let h = e == null ? void 0 : e.range;
- if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h)
- return false;
- const m = {
- range: h,
- subUnitId: l,
- unitId: u,
- shiftDimension: yu.ROWS
- }, g2 = i.onCommandExecute({
- id: Tt.id,
- params: { range: h }
- }), { redo: f, undo: p } = cr(
- n,
- m
- ), C = [...(b = g2.preRedos) != null ? b : [], ...f], S = [...g2.undos, ...p];
- return C.push(...g2.redos), C.push(Xe2(h, c, d)), S.push(...(y = g2.preUndos) != null ? y : []), mu(C, t).result ? (o.pushUndoRedo({
- unitID: u,
- undoMutations: S.reverse(),
- redoMutations: C
- }), true) : false;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- };
- var su = {
- type: ar.COMMAND,
- id: "sheet.command.delete-range-protection",
- async handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), o = n.get(cn), { unitId: s, subUnitId: r, rule: i } = e, a = {
- unitId: s,
- subUnitId: r,
- ruleIds: [i.id]
- };
- return await t.executeCommand(ze.id, a) && o.pushUndoRedo({
- unitID: s,
- redoMutations: [{ id: ze.id, params: a }],
- undoMutations: [{ id: Ne.id, params: { unitId: s, subUnitId: r, rules: [i] } }]
- }), true;
- }
- };
- var ru = {
- type: ar.COMMAND,
- id: "sheet.command.delete-worksheet-protection",
- handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), o = n.get(cn), { rule: s, unitId: r, subUnitId: i } = e;
- t.executeCommand(St.id, {
- unitId: r,
- subUnitId: i
- });
- const a = [{ id: St.id, params: { unitId: r, subUnitId: i } }], u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: i } }];
- return o.pushUndoRedo({
- unitID: r,
- redoMutations: a,
- undoMutations: u
- }), true;
- }
- };
- var iu = {
- type: ar.COMMAND,
- id: "sheet.command.remove-worksheet-range-theme-style",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), { unitId: s } = e, r = _a(n, e);
- return t.syncExecuteCommand(Kt.id, e) ? (o.pushUndoRedo({
- unitID: s,
- undoMutations: [{ id: zt.id, params: r }],
- redoMutations: [{ id: Kt.id, params: e }]
- }), true) : false;
- }
- };
- var au = {
- id: "sheet.command.insert-defined-name",
- type: ar.COMMAND,
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn);
- if (!e)
- return false;
- const s = {
- ...e
- };
- return t.syncExecuteCommand(sa.id, s) ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: [{ id: Xi.id, params: s }],
- redoMutations: [{ id: sa.id, params: s }]
- }), true) : false;
- }
- };
- var mr2 = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- };
- };
- var qe = {
- id: "sheet.mutation.insert-row",
- type: ar.MUTATION,
- handler: (n, e) => {
- var g2;
- const { unitId: t, subUnitId: o, range: s, rowInfo: r } = e, a = n.get(_n).getUniverSheetInstance(t);
- if (a == null)
- throw new Error("universheet is null error!");
- const u = a.getSheetBySheetId(o);
- if (u == null)
- throw new Error("worksheet is null error!");
- const l = u.getRowManager().getRowData(), c = {
- h: u.getConfig().defaultRowHeight,
- hd: 0
- }, d = s.startRow, h = s.endRow - s.startRow + 1;
- for (let f = d; f < d + h; f++)
- r ? Vo(f, (g2 = r[f - s.startRow]) != null ? g2 : c, l) : Vo(f, c, l);
- return u.setRowCount(u.getRowCount() + s.endRow - s.startRow + 1), u.getCellMatrix().insertRows(s.startRow, h), true;
- }
- };
- var yo = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- };
- };
- var je = {
- id: "sheet.mutation.insert-col",
- type: ar.MUTATION,
- handler: (n, e) => {
- var g2;
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s)
- return false;
- const r = s.getColumnManager(), { range: i, colInfo: a } = e, l = r.getColumnData(), c = i.startColumn, d = i.endColumn - i.startColumn + 1, h = s.getConfig().defaultColumnWidth;
- for (let f = c; f < c + d; f++) {
- const p = {
- w: h,
- hd: 0
- };
- a ? Vo(f, (g2 = a[f - i.startColumn]) != null ? g2 : p, l) : Vo(f, p, l);
- }
- return s.setColumnCount(s.getColumnCount() + i.endColumn - i.startColumn + 1), s.getCellMatrix().insertColumns(i.startColumn, d), true;
- }
- };
- var uu = (n, e) => {
- const s = e.getRowManager().getRowData(), r = {}, i = n.range, a = UC(i.startRow, i.endRow, s), u = LC(r, a);
- return {
- unitId: n.unitId,
- subUnitId: n.subUnitId,
- range: n.range,
- rowInfo: u
- };
- };
- var Be = {
- id: "sheet.mutation.remove-rows",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s)
- return false;
- const r = e.range, a = s.getRowManager().getRowData();
- for (let c = r.startRow; c <= r.endRow; c++)
- s.getRowFiltered(c);
- const u = r.endRow - r.startRow + 1;
- return Go(r.startRow, u, a), s.getCellMatrix().removeRows(r.startRow, u), s.setRowCount(s.getRowCount() - u), true;
- }
- };
- var lu = (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (s == null)
- throw new Error("worksheet is null error!");
- const a = s.getColumnManager().getColumnData(), u = {}, l = e.range, c = UC(l.startColumn, l.endColumn, a), d = LC(u, c);
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- colInfo: d
- };
- };
- var De2 = {
- id: "sheet.mutation.remove-col",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s)
- return false;
- const r = e.range, a = s.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1;
- return Go(r.startColumn, u, a), s.setColumnCount(s.getColumnCount() - u), s.getCellMatrix().removeColumns(r.startColumn, u), true;
- }
- };
- var cu = "sheet.command.insert-range-move-down";
- var sn = {
- type: ar.COMMAND,
- id: "sheet.command.insert-range-move-down",
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- var j, Z, Y;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = n.get(NE), u = n.get(Vr);
- if (r.isOverlapping())
- return a.emit(u.t("sheets.info.overlappingSelections")), false;
- const l = N(s);
- if (!l)
- return false;
- const { unitId: c, subUnitId: d, worksheet: h, workbook: m } = l;
- let g2 = e == null ? void 0 : e.range;
- if (g2 || (g2 = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g2)
- return false;
- const f = [], p = [], C = h.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(S.startRow, S.endRow, g2.startColumn, g2.endColumn).getDataRange().endRow, b = Math.max(w + (g2.endRow - g2.startRow + 1) - S.endRow, 0);
- if (b > 0) {
- const ee = g2.startRow - 1, Re = h.getRowHeight(ee), ie = {
- unitId: c,
- subUnitId: d,
- range: {
- startRow: S.endRow + 1,
- endRow: S.endRow + b,
- startColumn: S.startColumn,
- endColumn: S.endColumn
- },
- rowInfo: new Array(b).fill(void 0).map(() => ({
- h: Re,
- hd: we.FALSE
- }))
- };
- f.push({
- id: qe.id,
- params: ie
- });
- const xe = mr2(
- n,
- ie
- );
- p.push({ id: Be.id, params: xe });
- }
- const y = {};
- tr.foreach(g2, (ee, Re) => {
- const ie = h.getCell(ee, Re);
- ie && (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s });
- });
- const x = {
- range: g2,
- subUnitId: d,
- unitId: c,
- shiftDimension: yu.ROWS,
- cellValue: y
- }, { redo: T2, undo: U } = lr(
- n,
- x
- );
- f.push(...T2), p.push(...U);
- const P = i.onCommandExecute({
- id: sn.id,
- params: { range: g2 }
- });
- return f.push(...P.redos), f.push(Xe2(g2, m, h)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), mu(f, t) ? (o.pushUndoRedo({
- unitID: c,
- undoMutations: p.reverse(),
- redoMutations: f
- }), true) : false;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- };
- var Eo = "sheet.command.insert-range-move-right";
- var Bn = {
- type: ar.COMMAND,
- id: Eo,
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- var j, Z, Y;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(V), a = n.get(NE), u = n.get(Vr);
- if (r.isOverlapping())
- return a.emit(u.t("sheets.info.overlappingSelections")), false;
- const l = N(s);
- if (!l)
- return false;
- const { workbook: c, worksheet: d, unitId: h, subUnitId: m } = l;
- let g2 = e == null ? void 0 : e.range;
- if (g2 || (g2 = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g2)
- return false;
- const f = [], p = [], C = d.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(g2.startRow, g2.endRow, S.startColumn, S.endColumn).getDataRange().endColumn, b = Math.max(
- w + (g2.endColumn - g2.startColumn + 1) - S.endColumn,
- 0
- );
- if (b > 0) {
- const ee = g2.startColumn - 1, Re = d.getColumnWidth(ee), ie = {
- unitId: h,
- subUnitId: m,
- range: {
- startRow: S.startRow + 1,
- endRow: S.endRow,
- startColumn: S.endColumn + 1,
- endColumn: S.endColumn + b
- },
- colInfo: new Array(b).fill(void 0).map(() => ({
- w: Re,
- hd: we.FALSE
- }))
- };
- f.push({
- id: je.id,
- params: ie
- });
- const xe = yo(
- n,
- ie
- );
- p.push({ id: De2.id, params: xe });
- }
- const y = {};
- tr.foreach(g2, (ee, Re) => {
- const ie = d.getCell(ee, Re);
- !ie || !ie.s || (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s });
- });
- const x = {
- range: g2,
- subUnitId: m,
- unitId: h,
- shiftDimension: yu.COLUMNS,
- cellValue: y
- }, { redo: T2, undo: U } = lr(
- n,
- x
- );
- f.push(...T2), p.push(...U);
- const P = i.onCommandExecute({
- id: Bn.id,
- params: { range: g2 }
- });
- return f.push(...P.redos), f.push(Xe2(g2, c, d)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), mu(f, t).result ? (o.pushUndoRedo({
- unitID: h,
- undoMutations: p.reverse(),
- redoMutations: f
- }), true) : false;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- };
- var gr = "sheet.command.insert-row";
- var mt = {
- type: ar.COMMAND,
- id: gr,
- handler: async (n, e) => {
- const t = n.get(Pt), o = n.get(V), { range: s, direction: r, unitId: i, subUnitId: a, cellValue: u } = e;
- return await o.beforeCommandExecute({
- id: mt.id,
- params: e
- }) ? t.syncExecuteCommand(fr.id, {
- range: s,
- direction: r,
- unitId: i,
- subUnitId: a,
- cellValue: u
- }) : false;
- }
- };
- var fr = {
- type: ar.COMMAND,
- id: "sheet.command.insert-row-by-range",
- handler: (n, e) => {
- var T2, U, P, A;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), i = N(s, e);
- if (!i)
- return false;
- const { workbook: a, worksheet: u } = i, { range: l, direction: c, unitId: d, subUnitId: h, cellValue: m } = e, { startRow: g2, endRow: f } = l;
- l.rangeType = De.ROW;
- const p = c === wu.UP ? g2 : g2 - 1, C = u.getRowHeight(p), S = {
- unitId: d,
- subUnitId: h,
- range: l,
- rowInfo: new Array(f - g2 + 1).fill(void 0).map(() => ({
- h: C,
- hd: we.FALSE
- }))
- // row height should inherit from the anchor row
- }, I = mr2(
- n,
- S
- ), w = [{ id: qe.id, params: S }], b = [{ id: Be.id, params: I }];
- m && w.push({
- id: Q.id,
- params: {
- unitId: d,
- subUnitId: h,
- cellValue: m
- }
- });
- const y = r.onCommandExecute({
- id: mt.id,
- params: e
- });
- return w.unshift(...(T2 = y.preRedos) != null ? T2 : []), w.push(...(U = y.redos) != null ? U : []), w.push(Xe2(l, a, u)), b.unshift(...(P = y.preUndos) != null ? P : []), b.push(...(A = y.undos) != null ? A : []), mu(w, t).result ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: b,
- redoMutations: w
- }), true) : false;
- }
- };
- var du = {
- type: ar.COMMAND,
- id: "sheet.command.insert-row-before",
- handler: async (n) => {
- var g2;
- const t = (g2 = n.get(F).getCurrentSelections()) == null ? void 0 : g2.map((f) => f.range);
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0];
- else
- return false;
- const s = n.get(_n), r = N(s);
- if (!r)
- return false;
- const { worksheet: i, subUnitId: a, unitId: u } = r, { startRow: l, endRow: c } = o, d = 0, h = i.getColumnCount() - 1, m = {
- unitId: u,
- subUnitId: a,
- direction: wu.UP,
- range: {
- startRow: l,
- endRow: c,
- startColumn: d,
- endColumn: h
- },
- // copy styles from the row above
- cellValue: Vn2(i, l, c, d, h, true, l - 1)
- };
- return n.get(Pt).executeCommand(mt.id, m);
- }
- };
- var hu = {
- type: ar.COMMAND,
- id: "sheet.command.insert-row-after",
- handler: async (n) => {
- var f;
- const t = (f = n.get(F).getCurrentSelections()) == null ? void 0 : f.map((p) => p.range);
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0];
- else
- return false;
- const s = n.get(_n), r = N(s);
- if (!r)
- return false;
- const { worksheet: i, unitId: a, subUnitId: u } = r, l = o.endRow - o.startRow + 1, c = o.endRow + 1, d = o.endRow + l, h = 0, m = i.getColumnCount() - 1, g2 = {
- unitId: a,
- subUnitId: u,
- direction: wu.DOWN,
- range: {
- startRow: c,
- endRow: d,
- startColumn: h,
- endColumn: m,
- rangeType: De.ROW
- },
- // copy styles from the row below
- cellValue: Vn2(i, c, d, h, m, true, o.endRow)
- };
- return n.get(Pt).executeCommand(mt.id, g2);
- }
- };
- var Rr = "sheet.command.insert-col";
- var gt = {
- type: ar.COMMAND,
- id: Rr,
- handler: async (n, e) => {
- const t = n.get(Pt), o = n.get(V), { range: s, direction: r, subUnitId: i, unitId: a, cellValue: u } = e;
- return await o.beforeCommandExecute({
- id: gt.id,
- params: e
- }) ? t.syncExecuteCommand(pr2.id, {
- range: s,
- direction: r,
- unitId: a,
- subUnitId: i,
- cellValue: u
- }) : false;
- }
- };
- var pr2 = {
- type: ar.COMMAND,
- id: "sheet.command.insert-col-by-range",
- handler: (n, e) => {
- var x, T2, U, P;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), { range: i, direction: a, subUnitId: u, unitId: l, cellValue: c } = e, { startColumn: d, endColumn: h } = e.range;
- i.rangeType = De.COLUMN;
- const m = s.getUniverSheetInstance(e.unitId), g2 = m.getSheetBySheetId(e.subUnitId), f = a === wu.LEFT ? d : d - 1, p = g2.getColumnWidth(f), C = {
- unitId: l,
- subUnitId: u,
- range: i,
- colInfo: new Array(h - d + 1).fill(void 0).map(() => ({
- w: p,
- hd: we.FALSE
- }))
- }, S = yo(
- n,
- C
- ), I = [{ id: je.id, params: C }], w = [{ id: De2.id, params: S }];
- c && I.push({
- id: Q.id,
- params: {
- unitId: l,
- subUnitId: u,
- cellValue: c
- }
- });
- const b = r.onCommandExecute({
- id: gt.id,
- params: e
- });
- return I.unshift(...(x = b.preRedos) != null ? x : []), I.push(...(T2 = b.redos) != null ? T2 : []), I.push(Xe2(i, m, g2)), w.unshift(...(U = b.preUndos) != null ? U : []), w.push(...(P = b.undos) != null ? P : []), mu(I, t).result ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: w.filter(Boolean),
- redoMutations: I.filter(Boolean)
- }), true) : false;
- }
- };
- var mu2 = {
- type: ar.COMMAND,
- id: "sheet.command.insert-col-before",
- handler: async (n) => {
- const t = n.get(F).getCurrentSelections();
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0].range;
- else
- return false;
- const s = n.get(_n), r = N(s);
- if (!r)
- return false;
- const { worksheet: i, unitId: a, subUnitId: u } = r, { startColumn: l, endColumn: c } = o, d = 0, h = i.getRowCount() - 1, m = {
- unitId: a,
- subUnitId: u,
- direction: wu.LEFT,
- range: {
- startColumn: l,
- endColumn: c,
- startRow: d,
- endRow: h,
- rangeType: De.COLUMN
- },
- // copy styles from the column before
- cellValue: Vn2(i, d, h, l, c, false, l - 1)
- };
- return n.get(Pt).executeCommand(gt.id, m);
- }
- };
- var gu = {
- type: ar.COMMAND,
- id: "sheet.command.insert-col-after",
- handler: async (n) => {
- const t = n.get(F).getCurrentSelections();
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0].range;
- else
- return false;
- const s = n.get(_n), r = N(s);
- if (!r)
- return false;
- const { worksheet: i, unitId: a, subUnitId: u } = r, l = o.endColumn - o.startColumn + 1, c = o.endColumn + 1, d = o.endColumn + l, h = 0, m = i.getRowCount() - 1, g2 = {
- unitId: a,
- subUnitId: u,
- direction: wu.RIGHT,
- range: {
- startColumn: c,
- endColumn: d,
- startRow: h,
- endRow: m
- },
- // copy styles from the column after
- cellValue: Vn2(i, h, m, c, d, false, o.endColumn)
- };
- return n.get(Pt).executeCommand(gt.id, g2);
- }
- };
- var fu = {
- id: "sheet.command.insert-sheet",
- type: ar.COMMAND,
- handler: (n, e) => {
- var p;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(Vr), i = va(s, { unitId: e == null ? void 0 : e.unitId });
- if (!i)
- return false;
- const { unitId: a, workbook: u } = i;
- let l = u.getSheets().length;
- const c = e == null ? void 0 : e.sheet, d = c == null ? void 0 : c.id, h = Q_(c || {});
- e ? (l = (p = e.index) != null ? p : l, h.id = d || re.generateRandomId(), h.name = (c == null ? void 0 : c.name) || u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)) : (h.id = re.generateRandomId(), h.name = u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`));
- const m = {
- index: l,
- sheet: h,
- unitId: a
- }, g2 = As(
- n,
- m
- );
- return t.syncExecuteCommand(Jt.id, m) ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Ut.id, params: g2 }],
- redoMutations: [{ id: Jt.id, params: m }]
- }), true) : false;
- }
- };
- function Ru(n, e) {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startRow > r.startRow, a = s.endRow - s.startRow + 1;
- return i ? {
- unitId: t,
- subUnitId: o,
- sourceRange: en.clone(r),
- targetRange: {
- ...s,
- endRow: s.endRow + a,
- startRow: s.startRow + a
- }
- } : {
- unitId: t,
- subUnitId: o,
- targetRange: en.clone(s),
- sourceRange: {
- ...r,
- endRow: r.endRow - a,
- startRow: r.startRow - a
- }
- };
- }
- var ot2 = {
- id: "sheet.mutation.move-rows",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(_n).getUniverSheetInstance(t);
- if (!a)
- throw new Error("[MoveRowMutation] univerSheet is null!");
- const u = a.getSheetBySheetId(o);
- if (!u)
- throw new Error("[MoveRowMutation] worksheet is null!");
- const l = s.startRow, c = s.endRow - s.startRow + 1, d = r.startRow, h = u.getRowManager().getRowData();
- return Ko(l, c, d, h), u.getCellMatrix().moveRows(l, c, d), true;
- }
- };
- function pu(n, e) {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startColumn > r.startColumn, a = s.endColumn - s.startColumn + 1;
- return i ? {
- unitId: t,
- subUnitId: o,
- sourceRange: en.clone(r),
- targetRange: {
- ...s,
- endColumn: s.endColumn + a,
- startColumn: s.startColumn + a
- }
- } : {
- unitId: t,
- subUnitId: o,
- targetRange: en.clone(s),
- sourceRange: {
- ...r,
- startColumn: r.startColumn - a,
- endColumn: r.endColumn - a
- }
- };
- }
- var st2 = {
- id: "sheet.mutation.move-columns",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(_n).getUniverSheetInstance(t);
- if (!a)
- throw new Error("[MoveColumnMutation] univerSheet is null!");
- const u = a.getSheetBySheetId(o);
- if (!u)
- throw new Error("[MoveColumnMutation] worksheet is null!");
- const l = s.startColumn, c = s.endColumn - s.startColumn + 1, d = r.startColumn, h = u.getColumnManager().getColumnData();
- return Ko(l, c, d, h), u.getCellMatrix().moveColumns(l, c, d), true;
- }
- };
- function Cu(n, e) {
- return e.getMergeData().some((t) => t.startRow < n && n <= t.endRow);
- }
- function Su(n, e) {
- return e.getMergeData().some((t) => t.startColumn < n && n <= t.endColumn);
- }
- var Cr = "sheet.command.move-rows";
- var Fn = {
- id: Cr,
- type: ar.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var j, Z;
- const t = n.get(F), {
- fromRange: { startRow: o },
- toRange: { startRow: s },
- range: r
- } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter(
- (Y) => Y.range.rangeType === De.ROW && Y.range.startRow <= o && o <= Y.range.endRow
- );
- if ((a == null ? void 0 : a.length) !== 1)
- return false;
- const u = n.get(V), l = n.get(_n), c = N(l, e);
- if (!c)
- return false;
- const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g2 = h.getSheetId(), f = n.get(NE), p = n.get(Vr), C = a[0].range, S = a[0].primary, I = Ln(C, h, false);
- if (!en.equals(C, I))
- return f.emit(p.t("sheets.info.partOfCell")), false;
- if (Cu(s, h))
- return f.emit(p.t("sheets.info.acrossMergedCell")), false;
- const w = {
- ...C,
- startRow: s,
- endRow: s + C.endRow - C.startRow
- }, b = {
- unitId: m,
- subUnitId: g2,
- sourceRange: C,
- targetRange: w
- }, y = Ru(n, b), x = n.get(Pt), T2 = u.onCommandExecute({ id: Fn.id, params: e }), U = [
- ...(j = T2.preRedos) != null ? j : [],
- { id: ot2.id, params: b }
- ], P = [
- ...(Z = T2.preUndos) != null ? Z : [],
- { id: ot2.id, params: y }
- ];
- if (S) {
- const ee = s - o < 0, Re = C.endRow - C.startRow + 1, ie = ee ? w : {
- ...w,
- startRow: w.startRow - Re,
- endRow: w.endRow - Re
- }, xe = {
- unitId: m,
- subUnitId: g2,
- type: Ce.MOVE_END,
- selections: [{
- range: ie,
- primary: ve(ie, h),
- style: null
- }]
- }, ft = {
- unitId: m,
- subUnitId: g2,
- type: Ce.MOVE_END,
- selections: [{ range: C, primary: S, style: null }]
- };
- U.push({ id: re2.id, params: xe }), P.push({ id: re2.id, params: ft });
- }
- return U.push(...T2.redos), P.push(...T2.undos), mu(U, x).result ? (n.get(cn).pushUndoRedo({
- unitID: m,
- undoMutations: P,
- redoMutations: U
- }), true) : false;
- }
- };
- var Sr = "sheet.command.move-cols";
- var jn = {
- id: Sr,
- type: ar.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var j, Z;
- const t = n.get(F), {
- fromRange: { startColumn: o },
- toRange: { startColumn: s },
- range: r
- } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter(
- (Y) => Y.range.rangeType === De.COLUMN && Y.range.startColumn <= o && o <= Y.range.endColumn
- );
- if ((a == null ? void 0 : a.length) !== 1)
- return false;
- const u = n.get(V), l = n.get(_n), c = N(l, e);
- if (!c)
- return false;
- const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g2 = h.getSheetId(), f = n.get(NE), p = n.get(Vr), C = a[0].range, S = a[0].primary, I = Ln(C, h, false);
- if (!en.equals(C, I))
- return f.emit(p.t("sheets.info.partOfCell")), false;
- if (Su(s, h))
- return f.emit(p.t("sheets.info.acrossMergedCell")), false;
- const w = {
- ...C,
- startColumn: s,
- endColumn: s + C.endColumn - C.startColumn
- }, b = {
- unitId: m,
- subUnitId: g2,
- sourceRange: C,
- targetRange: w
- }, y = pu(n, b), x = n.get(Pt), T2 = u.onCommandExecute({ id: jn.id, params: e }), U = [
- ...(j = T2.preRedos) != null ? j : [],
- { id: st2.id, params: b }
- ], P = [
- ...(Z = T2.preUndos) != null ? Z : [],
- { id: st2.id, params: y }
- ];
- if (S) {
- const Y = C.endColumn - C.startColumn + 1, ie = s - o < 0 ? w : {
- ...w,
- startColumn: w.startColumn - Y,
- endColumn: w.endColumn - Y
- }, xe = {
- unitId: m,
- subUnitId: g2,
- type: Ce.MOVE_END,
- selections: [{ range: ie, primary: ve(ie, h), style: null }]
- }, ft = {
- unitId: m,
- subUnitId: g2,
- type: Ce.MOVE_END,
- selections: [{ range: C, primary: S, style: null }]
- };
- U.push({ id: re2.id, params: xe }), P.push({ id: re2.id, params: ft });
- }
- return U.push(...T2.redos), P.push(...T2.undos), mu(U, x).result && n.get(cn).pushUndoRedo({
- unitID: m,
- undoMutations: P,
- redoMutations: U
- }), true;
- }
- };
- function wr(n) {
- return {
- range: n,
- primary: null,
- style: null
- };
- }
- var Yt = {
- id: "sheet.mutation.register-worksheet-range-theme-style",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, rangeThemeStyleJson: o, themeName: s } = e, r = n.get(_n), i = N(r), a = n.get(He);
- if (!i)
- return false;
- const u = new yt(s, o);
- return a.registerRangeThemeStyle(t, u), true;
- }
- };
- var Uo = {
- id: "sheet.mutation.unregister-worksheet-range-theme-style",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, themeName: o } = e, s = n.get(_n), r = N(s), i = n.get(He);
- return r ? (i.unregisterRangeThemeStyle(t, o), true) : false;
- }
- };
- var wu2 = {
- id: "sheet.command.register-worksheet-range-theme-style",
- type: ar.COMMAND,
- handler: (n, e) => {
- if (!e)
- return false;
- const { unitId: t, rangeThemeStyle: o } = e, s = n.get(_n), r = n.get(Pt), i = n.get(cn);
- if (!N(s))
- return false;
- const u = {
- unitId: t,
- themeName: o.getName(),
- rangeThemeStyleJson: o.toJson()
- }, l = {
- unitId: t,
- themeName: o.getName()
- };
- return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({
- unitID: t,
- undoMutations: [{ id: Uo.id, params: l }],
- redoMutations: [{ id: Yt.id, params: u }]
- }), true;
- }
- };
- var Ir = {
- id: "sheet.command.remove-defined-name",
- type: ar.COMMAND,
- handler: (n, e) => {
- var c, d;
- const t = n.get(Pt), o = n.get(cn), s = n.get(V);
- if (!e)
- return false;
- const r = {
- ...e
- }, i = s.onCommandExecute({ id: Ir.id, params: e }), a = [
- ...(c = i.preRedos) != null ? c : [],
- { id: Xi.id, params: r },
- ...i.redos
- ], u = [
- ...(d = i.preUndos) != null ? d : [],
- { id: sa.id, params: r },
- ...i.undos
- ];
- return mu(a, t) ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: u.filter(Boolean),
- redoMutations: a.filter(Boolean)
- }), true) : false;
- }
- };
- var Po = "sheet.command.remove-row";
- var vr = {
- type: ar.COMMAND,
- id: "sheet.command.remove-row-by-range",
- handler: (n, e) => {
- var C, S, I;
- if (!e)
- return false;
- const t = n.get(_n), o = N(t, e);
- if (!o)
- return false;
- const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = {
- unitId: u,
- subUnitId: l,
- range: a
- }, d = uu(
- c,
- r
- ), h = r.getCellMatrix().getSlice(a.startRow, a.endRow, 0, r.getColumnCount() - 1), m = {
- unitId: u,
- subUnitId: l,
- cellValue: h.getMatrix()
- }, g2 = i.onCommandExecute({
- id: Po,
- params: { range: a }
- }), f = n.get(Pt);
- return mu(
- [
- ...(C = g2.preRedos) != null ? C : [],
- { id: Be.id, params: c },
- ...g2.redos,
- Xe2(a, s, r)
- ],
- f
- ).result ? (n.get(cn).pushUndoRedo({
- unitID: u,
- undoMutations: [
- ...(S = g2.preUndos) != null ? S : [],
- { id: qe.id, params: d },
- { id: Q.id, params: m },
- ...g2.undos
- ],
- redoMutations: [
- ...(I = g2.preRedos) != null ? I : [],
- { id: Be.id, params: c },
- ...g2.redos
- ]
- }), true) : false;
- }
- };
- var Gn = {
- type: ar.COMMAND,
- id: Po,
- handler: async (n, e) => {
- var h;
- const t = n.get(F), o = n.get(V), s = n.get(Pt);
- let r = e == null ? void 0 : e.range;
- if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r)
- return false;
- const i = n.get(_n), a = N(i);
- if (!a)
- return false;
- const { worksheet: u, subUnitId: l, unitId: c } = a;
- return r = {
- ...r,
- startColumn: 0,
- endColumn: Math.max(u.getMaxColumns() - 1, 0)
- }, await o.beforeCommandExecute({
- id: Gn.id,
- params: { range: r }
- }) ? s.syncExecuteCommand(vr.id, {
- range: r,
- unitId: c,
- subUnitId: l
- }) : false;
- }
- };
- var To = "sheet.command.remove-col";
- var Mr = {
- type: ar.COMMAND,
- id: "sheet.command.remove-col-by-range",
- handler: (n, e) => {
- var C, S, I;
- if (!e)
- return false;
- const t = n.get(_n), o = N(t, e);
- if (!o)
- return false;
- const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = {
- unitId: u,
- subUnitId: l,
- range: a
- }, d = lu(n, c), h = r.getCellMatrix().getSlice(0, r.getRowCount() - 1, a.startColumn, a.endColumn), m = {
- unitId: u,
- subUnitId: l,
- cellValue: h.getMatrix()
- }, g2 = i.onCommandExecute({
- id: To,
- params: { range: a }
- }), f = n.get(Pt);
- return mu(
- [
- ...(C = g2.preRedos) != null ? C : [],
- { id: De2.id, params: c },
- ...g2.redos,
- Xe2(a, s, r)
- ],
- f
- ).result ? (n.get(cn).pushUndoRedo({
- unitID: u,
- undoMutations: [
- ...(S = g2.preUndos) != null ? S : [],
- { id: je.id, params: d },
- { id: Q.id, params: m },
- ...g2.undos
- ],
- redoMutations: [
- ...(I = g2.preRedos) != null ? I : [],
- { id: De2.id, params: c },
- ...g2.redos
- ]
- }), true) : false;
- }
- };
- var zn2 = {
- type: ar.COMMAND,
- id: To,
- handler: async (n, e) => {
- var h;
- const t = n.get(F), o = n.get(V), s = n.get(Pt);
- let r = e == null ? void 0 : e.range;
- if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r)
- return false;
- const i = n.get(_n), a = N(i);
- if (!a)
- return false;
- const { worksheet: u, subUnitId: l, unitId: c } = a;
- return r = {
- ...r,
- startRow: 0,
- endRow: Math.max(u.getMaxRows() - 1, 0)
- }, await o.beforeCommandExecute({
- id: zn2.id,
- params: { range: r }
- }) ? s.syncExecuteCommand(Mr.id, {
- range: r,
- unitId: c,
- subUnitId: l
- }) : false;
- }
- };
- var ko = {
- id: "sheet.command.remove-sheet",
- type: ar.COMMAND,
- handler: (n, e) => {
- var C, S;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(V), i = N(s, e);
- if (!i)
- return false;
- const { unitId: a, subUnitId: u, workbook: l, worksheet: c } = i;
- if (l.getSheets().length <= 1)
- return false;
- const d = {
- subUnitId: u,
- unitId: a,
- subUnitName: c.getName()
- }, h = ja(
- n,
- d
- ), m = r.onCommandExecute({
- id: ko.id,
- params: { unitId: a, subUnitId: u }
- }), g2 = [...(C = m.preRedos) != null ? C : [], { id: Ut.id, params: d }, ...m.redos], f = [...(S = m.preUndos) != null ? S : [], { id: Jt.id, params: h }, ...m.undos];
- return mu(g2, t).result ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: f,
- redoMutations: g2
- }), true) : false;
- }
- };
- var Ue = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: re.deepClone(e.ranges)
- };
- };
- var ne = {
- id: "sheet.mutation.add-worksheet-merge",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s)
- return false;
- const i = s.getConfig().mergeData, a = e.ranges;
- for (let u = 0; u < a.length; u++)
- i.push(a[u]);
- return s.getSpanModel().rebuild(i), true;
- }
- };
- var Se = (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (s == null)
- throw new Error("worksheet is null error!");
- const i = s.getConfig().mergeData, a = e.ranges, u = [];
- for (let l = 0; l < a.length; l++)
- for (let c = i.length - 1; c >= 0; c--) {
- const d = i[c], h = a[l];
- en.intersects(d, h) && u.push(i[c]);
- }
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: u
- };
- };
- var oe = {
- id: "sheet.mutation.remove-worksheet-merge",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s)
- return false;
- const i = s.getConfig().mergeData, a = e.ranges;
- for (let u = 0; u < a.length; u++)
- for (let l = i.length - 1; l >= 0; l--) {
- const c = i[l], d = a[u];
- en.intersects(c, d) && i.splice(l, 1);
- }
- return s.getSpanModel().rebuild(i), true;
- }
- };
- var Iu = {
- type: ar.COMMAND,
- id: "sheet.command.remove-worksheet-merge",
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var A;
- const t = n.get(F), o = n.get(Pt), s = n.get(cn), r = n.get(_n), i = (e == null ? void 0 : e.ranges) || ((A = t.getCurrentSelections()) == null ? void 0 : A.map((j) => j.range));
- if (!(i != null && i.length))
- return false;
- const a = N(r);
- if (!a)
- return false;
- const { subUnitId: u, unitId: l, worksheet: c } = a, d = {
- unitId: l,
- subUnitId: u,
- ranges: i
- }, m = c.getConfig().mergeData.filter((j) => i.some((Z) => en.intersects(Z, j)));
- if (!m.length)
- return false;
- const g2 = Se(
- n,
- d
- ), f = t.getCurrentSelections();
- if (!(f != null && f.length))
- return false;
- const p = re.deepClone(f), C = re.deepClone(f), S = C[C.length - 1], { startRow: I, startColumn: w } = S.range;
- S.primary = {
- startRow: I,
- startColumn: w,
- endRow: I,
- endColumn: w,
- actualRow: I,
- actualColumn: w,
- isMerged: false,
- isMergedMainCell: false
- };
- const b = vu(c, m), y = {
- unitId: l,
- subUnitId: u,
- cellValue: b.redoParams.getMatrix()
- }, x = {
- unitId: l,
- subUnitId: u,
- cellValue: b.undoParams.getMatrix()
- }, T2 = [
- { id: oe.id, params: g2 },
- { id: Q.id, params: y },
- { id: re2.id, params: { selections: C } }
- ], U = [
- { id: ne.id, params: g2 },
- { id: Q.id, params: x },
- { id: re2.id, params: { selections: p } }
- ];
- return mu(T2, o) ? (s.pushUndoRedo({
- unitID: l,
- undoMutations: U,
- redoMutations: T2
- }), true) : false;
- }
- };
- function vu(n, e) {
- const t = new kt(), o = new kt();
- return e.forEach((s) => {
- const { startRow: r, startColumn: i, endColumn: a, endRow: u } = s, l = n.getCellMatrix().getValue(r, i);
- if (l != null && l.s)
- for (let c = r; c <= u; c++)
- for (let d = i; d <= a; d++)
- (c !== r || d !== i) && (t.setValue(c, d, { s: l.s }), o.setValue(c, d, null));
- }), {
- redoParams: t,
- undoParams: o
- };
- }
- var Mu = (n) => {
- const { order: e } = n, t = {};
- return Object.keys(e).forEach((o) => {
- t[e[Number(o)]] = Number(o);
- }), {
- ...n,
- order: t
- };
- };
- var In = {
- id: "sheet.mutation.reorder-range",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { subUnitId: t, unitId: o, range: s, order: r } = e, u = n.get(_n).getUnit(o).getSheetBySheetId(t);
- if (!u)
- return false;
- const l = new kt();
- tr.foreach(s, (d, h) => {
- if (r.hasOwnProperty(d)) {
- const m = r[d], g2 = re.deepClone(u.getCellRaw(m, h));
- l.setValue(d, h, g2);
- }
- });
- const c = u.getCellMatrix();
- return l.forValue((d, h, m) => {
- c.setValue(d, h, m);
- }), true;
- }
- };
- var _r = "sheet.command.reorder-range";
- var uo = {
- id: _r,
- type: ar.COMMAND,
- handler: (n, e) => {
- var f, p;
- const { subUnitId: t, unitId: o, range: s, order: r } = e, i = n.get(Pt), a = {
- id: In.id,
- params: {
- unitId: o,
- subUnitId: t,
- order: r,
- range: s
- }
- }, u = {
- id: In.id,
- params: Mu(a.params)
- }, l = n.get(V), c = l.onCommandExecute({ id: uo.id, params: e }), d = [
- ...(f = c.preRedos) != null ? f : [],
- a,
- ...c.redos
- ], h = [
- ...(p = c.preUndos) != null ? p : [],
- u,
- ...c.undos
- ], m = mu(d, i), g2 = l.afterCommandExecute({ id: uo.id, params: e });
- return m.result ? (mu(g2.redos, i), n.get(cn).pushUndoRedo({
- unitID: o,
- undoMutations: [...h, ...g2.undos],
- redoMutations: [...d, ...g2.redos]
- }), true) : false;
- }
- };
- var kt2 = class {
- constructor() {
- R(this, "_borderInfo", {
- type: Eu.ALL,
- color: "#000000",
- style: Xe.THIN,
- activeBorderType: false
- });
- R(this, "_borderInfo$", new BehaviorSubject(this._borderInfo));
- R(this, "borderInfo$", this._borderInfo$.asObservable());
- }
- dispose() {
- this._borderInfo$.complete();
- }
- setType(e) {
- this._borderInfo.type = e, this.setActiveBorderType(true), this._refresh();
- }
- setColor(e) {
- this._borderInfo.color = e, this._refresh();
- }
- setStyle(e) {
- this._borderInfo.style = e, this._refresh();
- }
- setActiveBorderType(e) {
- this._borderInfo.activeBorderType = e;
- }
- getBorderInfo() {
- return this._borderInfo;
- }
- _refresh() {
- this._borderInfo$.next(this._borderInfo);
- }
- };
- function vn(n, e) {
- const { startRow: t, startColumn: o, endRow: s, endColumn: r } = n;
- for (let i = t; i <= s; i++)
- for (let a = o; a <= r; a++)
- e(i, a);
- }
- var No = (n, e, t, o) => {
- const { mr: s, worksheet: r } = n;
- e.startRow < 0 || e.startColumn < 0 || vn(e, (i, a) => {
- var c, d;
- const u = r.getMergedCell(i, a);
- let l = t;
- if (u && (t.bc_tr || t.ml_tr || t.bl_tr || t.tl_mr || t.tl_bc || t.tl_br)) {
- if (o) {
- const h = re.deepClone(
- (c = s.getValue(u.startRow, u.startColumn)) == null ? void 0 : c.s
- );
- l = h != null && h.bd ? Object.assign(h.bd, t) : t;
- }
- s.setValue(u.startRow, u.startColumn, {
- s: {
- bd: l
- }
- });
- } else {
- if (o) {
- const h = re.deepClone((d = s.getValue(i, a)) == null ? void 0 : d.s);
- l = h != null && h.bd ? Object.assign(h.bd, t) : t;
- }
- s.setValue(i, a, { s: { bd: l } });
- }
- });
- };
- var _u = (n) => {
- const e = {
- startRow: n.startRow - 1,
- startColumn: n.startColumn,
- endRow: n.startRow - 1,
- endColumn: n.endColumn
- }, t = {
- startRow: n.startRow,
- startColumn: n.startColumn - 1,
- endRow: n.endRow,
- endColumn: n.startColumn - 1
- }, o = {
- startRow: n.endRow + 1,
- startColumn: n.startColumn,
- endRow: n.endRow + 1,
- endColumn: n.endColumn
- }, s = {
- startRow: n.startRow,
- startColumn: n.endColumn + 1,
- endRow: n.endRow,
- endColumn: n.endColumn + 1
- }, r = {
- startRow: n.startRow,
- startColumn: n.startColumn,
- endRow: n.startRow,
- endColumn: n.endColumn
- }, i = {
- startRow: n.startRow,
- startColumn: n.startColumn,
- endRow: n.endRow,
- endColumn: n.startColumn
- }, a = {
- startRow: n.endRow,
- startColumn: n.startColumn,
- endRow: n.endRow,
- endColumn: n.endColumn
- }, u = {
- startRow: n.startRow,
- startColumn: n.endColumn,
- endRow: n.endRow,
- endColumn: n.endColumn
- };
- return {
- topRangeOut: e,
- leftRangeOut: t,
- bottomRangeOut: o,
- rightRangeOut: s,
- topRange: r,
- leftRange: i,
- bottomRange: a,
- rightRange: u
- };
- };
- function bu(n, e, t) {
- const { style: o, color: s, type: r } = n.getBorderInfo(), i = r === Eu.TOP || r === Eu.ALL || r === Eu.OUTSIDE, a = r === Eu.LEFT || r === Eu.ALL || r === Eu.OUTSIDE, u = r === Eu.BOTTOM || r === Eu.ALL || r === Eu.OUTSIDE, l = r === Eu.RIGHT || r === Eu.ALL || r === Eu.OUTSIDE, c = r === Eu.VERTICAL || r === Eu.ALL || r === Eu.INSIDE, d = r === Eu.HORIZONTAL || r === Eu.ALL || r === Eu.INSIDE, h = r.indexOf("tlbr") > -1, m = r.indexOf("tlbc") > -1, g2 = r.indexOf("tlmr") > -1, f = r.indexOf("bltr") > -1, p = r.indexOf("mltr") > -1, C = r.indexOf("bctr") > -1, S = t[0], {
- topRangeOut: I,
- leftRangeOut: w,
- bottomRangeOut: b,
- rightRangeOut: y,
- topRange: x,
- leftRange: T2,
- bottomRange: U,
- rightRange: P
- } = _u(S), A = new kt(), { worksheet: j, unitId: Z, subUnitId: Y } = e;
- return {
- worksheet: j,
- unitId: Z,
- subUnitId: Y,
- style: o,
- color: s,
- type: r,
- top: i,
- left: a,
- right: l,
- bottom: u,
- vertical: c,
- horizontal: d,
- tl_br: h,
- tl_bc: m,
- tl_mr: g2,
- bl_tr: f,
- ml_tr: p,
- bc_tr: C,
- topRangeOut: I,
- leftRangeOut: w,
- bottomRangeOut: b,
- rightRangeOut: y,
- topRange: x,
- leftRange: T2,
- bottomRange: U,
- rightRange: P,
- range: S,
- mr: A,
- borderStyle: {
- s: o,
- cl: {
- rgb: s
- }
- }
- };
- }
- var yu2 = (n) => {
- const { range: e, mr: t, borderStyle: o, vertical: s, horizontal: r, worksheet: i } = n;
- s && vn(e, (a, u) => {
- var c, d, h;
- const l = i.getMergedCell(a, u);
- if (l) {
- const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s;
- l.startColumn !== e.startColumn && t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { l: re.deepClone(o) }) : { l: re.deepClone(o) }
- }
- });
- } else {
- if (u !== e.endColumn) {
- const m = (d = t.getValue(a, u)) == null ? void 0 : d.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { r: re.deepClone(o) }) : { r: re.deepClone(o) }
- }
- });
- }
- if (u !== e.startColumn) {
- const m = (h = t.getValue(a, u)) == null ? void 0 : h.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { l: re.deepClone(o) }) : { l: re.deepClone(o) }
- }
- });
- }
- }
- }), r && vn(e, (a, u) => {
- var c, d, h;
- const l = i.getMergedCell(a, u);
- if (l) {
- const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s;
- l.startRow !== e.startRow && t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { t: re.deepClone(o) }) : { t: re.deepClone(o) }
- }
- });
- } else {
- if (a !== e.endRow) {
- const m = (d = t.getValue(a, u)) == null ? void 0 : d.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { b: re.deepClone(o) }) : { b: re.deepClone(o) }
- }
- });
- }
- if (a !== e.startRow) {
- const m = (h = t.getValue(a, u)) == null ? void 0 : h.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { t: re.deepClone(o) }) : { t: re.deepClone(o) }
- }
- });
- }
- }
- });
- };
- function Eu2(n) {
- const { borderStyle: e, tl_br: t, tl_bc: o, tl_mr: s, bl_tr: r, ml_tr: i, bc_tr: a } = n, u = (l, c, d) => {
- No(n, l, c, d);
- };
- t && u(n.range, { tl_br: re.deepClone(e) }, true), o && u(n.range, { tl_bc: re.deepClone(e) }, true), s && u(n.range, { tl_mr: re.deepClone(e) }, true), r && u(n.range, { bl_tr: re.deepClone(e) }, true), i && u(n.range, { ml_tr: re.deepClone(e) }, true), a && u(n.range, { bc_tr: re.deepClone(e) }, true);
- }
- var Uu = (n) => {
- const { top: e, left: t, right: o, bottom: s, borderStyle: r, bottomRange: i, topRange: a, leftRange: u, rightRange: l, bottomRangeOut: c, topRangeOut: d, leftRangeOut: h, rightRangeOut: m } = n, g2 = (f, p, C) => {
- No(n, f, p, C);
- };
- e && (g2(d, { b: null }), g2(a, { t: re.deepClone(r) }, true)), s && (g2(c, { t: null }), g2(i, { b: re.deepClone(r) }, true)), t && (g2(h, { r: null }), g2(u, { l: re.deepClone(r) }, true)), o && (g2(m, { l: null }), g2(l, { r: re.deepClone(r) }, true));
- };
- var Pu = (n) => {
- const { range: e, worksheet: t, mr: o, top: s, bottom: r, left: i, right: a, vertical: u, horizontal: l, tl_br: c, tl_bc: d, tl_mr: h, bl_tr: m, ml_tr: g2, bc_tr: f, topRange: p, bottomRange: C, leftRange: S, rightRange: I, topRangeOut: w, bottomRangeOut: b, leftRangeOut: y, rightRangeOut: x } = n, T2 = (U, P, A) => {
- No(n, U, P, A);
- };
- !s && !r && !i && !a && !u && !l && !c && !d && !h && !m && !g2 && !f && (vn(e, (U, P) => {
- var j, Z, Y, ee, Re, ie, xe, ft;
- const A = t.getMergedCell(U, P);
- if (A) {
- if (A.endColumn !== e.endColumn) {
- const X2 = (j = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : j.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { r: null }) : { r: null }
- }
- });
- }
- if (A.startColumn !== e.startColumn) {
- const X2 = (Z = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Z.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { l: null }) : { l: null }
- }
- });
- }
- if (A.endRow !== e.endRow) {
- const X2 = (Y = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Y.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { b: null }) : { b: null }
- }
- });
- }
- if (A.startRow !== e.startRow) {
- const X2 = (ee = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : ee.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { t: null }) : { t: null }
- }
- });
- }
- } else {
- if (P !== e.endColumn) {
- const X2 = (Re = o.getValue(U, P)) == null ? void 0 : Re.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { r: null }) : { r: null }
- }
- });
- }
- if (P !== e.startColumn) {
- const X2 = (ie = o.getValue(U, P)) == null ? void 0 : ie.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { l: null }) : { l: null }
- }
- });
- }
- if (U !== e.endRow) {
- const X2 = (xe = o.getValue(U, P)) == null ? void 0 : xe.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { b: null }) : { b: null }
- }
- });
- }
- if (U !== e.startRow) {
- const X2 = (ft = o.getValue(U, P)) == null ? void 0 : ft.s;
- o.setValue(U, P, {
- s: {
- bd: X2 != null && X2.bd ? Object.assign(X2.bd, { t: null }) : { t: null }
- }
- });
- }
- }
- }), T2(w, { b: null }), T2(p, { t: null }, true), T2(b, { t: null }), T2(C, { b: null }, true), T2(y, { r: null }), T2(S, { l: null }, true), T2(x, { l: null }), T2(I, { r: null }, true), T2(e, { tl_br: null }, true), T2(e, { tl_bc: null }, true), T2(e, { tl_mr: null }, true), T2(e, { bl_tr: null }, true), T2(e, { ml_tr: null }, true), T2(e, { bc_tr: null }, true));
- };
- var rn = {
- id: "sheet.command.set-border",
- type: ar.COMMAND,
- handler: (n, e) => {
- var C;
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = n.get(F), i = n.get(kt2), a = N(s, e);
- if (!a)
- return false;
- const u = (C = r.getCurrentSelections()) == null ? void 0 : C.map((S) => S.range);
- if (!(u != null && u.length))
- return false;
- const { activeBorderType: l } = i.getBorderInfo();
- if (!l)
- return false;
- const c = bu(i, a, u);
- yu2(c), Uu(c), Eu2(c), Pu(c);
- const { unitId: d, subUnitId: h, mr: m } = c, g2 = {
- unitId: d,
- subUnitId: h,
- cellValue: m.getData()
- }, f = Ae(
- n,
- g2
- );
- return t.syncExecuteCommand(Q.id, g2) ? (o.pushUndoRedo({
- unitID: d,
- undoMutations: [{ id: Q.id, params: f }],
- redoMutations: [{ id: Q.id, params: g2 }]
- }), true) : false;
- }
- };
- var Tu = {
- id: "sheet.command.set-border-position",
- type: ar.COMMAND,
- handler: (n, e) => {
- if (!e.value)
- return false;
- const t = n.get(Pt);
- return n.get(kt2).setType(e.value), t.syncExecuteCommand(rn.id);
- }
- };
- var ku = {
- id: "sheet.command.set-border-style",
- type: ar.COMMAND,
- handler: (n, e) => {
- const t = n.get(Pt);
- return n.get(kt2).setStyle(e.value), t.syncExecuteCommand(rn.id);
- }
- };
- var Nu = {
- id: "sheet.command.set-border-color",
- type: ar.COMMAND,
- handler: (n, e) => {
- const t = n.get(Pt);
- return n.get(kt2).setColor(e.value), t.syncExecuteCommand(rn.id);
- }
- };
- var Ou = {
- id: "sheet.command.set-border-basic",
- type: ar.COMMAND,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, value: s } = e, { type: r, color: i, style: a } = s, u = n.get(Pt), l = n.get(kt2);
- return l.setType(r), i && l.setColor(i), l.setStyle(a), u.syncExecuteCommand(rn.id, {
- unitId: t,
- subUnitId: o
- });
- }
- };
- function Du(n, e) {
- if (n == null)
- return n;
- const t = re.deepClone(n);
- if (e == null)
- return t;
- const o = {};
- return "h" in e && (o.h = t.h), "ia" in e && (o.ia = t.ia), "ah" in e && (o.ah = t.ah), "hd" in e && (o.hd = t.hd), "s" in e && (o.s = t.s), "custom" in e && (o.custom = t.custom), o;
- }
- function Au(n, e) {
- if (n == null)
- return n;
- const t = re.deepClone(n);
- if (e == null)
- return t;
- const o = {};
- return "w" in e && (o.w = t.w), "hd" in e && (o.hd = t.hd), "s" in e && (o.s = t.s), "custom" in e && (o.custom = t.custom), o;
- }
- var xu = (n, e) => {
- const { unitId: t, subUnitId: o, columnData: s } = n, r = {}, i = e.getColumnManager();
- for (const a in s) {
- const u = s[a], l = i.getColumn(Number(a));
- r[a] = Au(l, u);
- }
- return {
- unitId: t,
- subUnitId: o,
- columnData: r
- };
- };
- var Lt = {
- id: "sheet.mutation.set-col-data",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { columnData: t } = e, o = n.get(_n), s = N(o, e);
- if (!s)
- return false;
- const { worksheet: r } = s, i = r.getColumnManager();
- for (const a in t) {
- const u = t[a];
- if (u == null) {
- i.removeColumn(Number(a));
- continue;
- }
- const l = i.getColumnOrCreate(Number(a));
- Object.assign(l, u);
- }
- return true;
- }
- };
- var $u = {
- type: ar.COMMAND,
- id: "sheet.command.set-col-data",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s, e);
- if (!r)
- return false;
- const { columnData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = {
- subUnitId: u,
- unitId: a,
- columnData: i
- }, d = xu(c, l);
- return t.syncExecuteCommand(Lt.id, c) ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Lt.id, params: d }],
- redoMutations: [{ id: Lt.id, params: c }]
- }), true) : false;
- }
- };
- var Wu = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- };
- var Xt2 = {
- id: "sheet.mutation.set-col-hidden",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (!o)
- return false;
- const s = o.getSheetBySheetId(e.subUnitId).getColumnManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startColumn; a < i.endColumn + 1; a++) {
- const u = s.getColumnOrCreate(a);
- u != null && (u.hd = we.TRUE);
- }
- }
- return true;
- }
- };
- var Lu = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- };
- var qt2 = {
- id: "sheet.mutation.set-col-visible",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (!o)
- return false;
- const s = o.getSheetBySheetId(e.subUnitId).getColumnManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startColumn; a < i.endColumn + 1; a++) {
- const u = s.getColumnOrCreate(a);
- u != null && (u.hd = we.FALSE);
- }
- }
- return true;
- }
- };
- var Kn = {
- type: ar.COMMAND,
- id: "sheet.command.set-col-visible-on-cols",
- handler: (n, e) => {
- var C, S;
- const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(V), i = n.get(Pt), a = n.get(_n), u = N(a, { unitId: t, subUnitId: o });
- if (!u)
- return false;
- const { worksheet: l } = u, c = {
- unitId: t,
- subUnitId: o,
- ranges: s
- }, d = {
- unitId: t,
- subUnitId: o,
- reveal: true,
- selections: s.map((I) => ({ range: I, primary: ve(I, l), style: null }))
- }, h = Lu(n, c), m = {
- unitId: t,
- subUnitId: o,
- selections: Er(s).map((I) => ({
- range: I,
- primary: ve(I, l),
- style: null
- }))
- }, g2 = mu([
- { id: qt2.id, params: c },
- { id: re2.id, params: d }
- ], i), f = r.onCommandExecute({
- id: Kn.id,
- params: e
- }), p = mu([...f.redos], i);
- return g2.result && p.result && n.get(cn).pushUndoRedo({
- unitID: t,
- undoMutations: [
- { id: Xt2.id, params: h },
- { id: re2.id, params: m },
- ...(C = f.undos) != null ? C : []
- ],
- redoMutations: [
- ...(S = f.preRedos) != null ? S : [],
- { id: qt2.id, params: c },
- { id: re2.id, params: d },
- ...f.redos
- ]
- }), true;
- }
- };
- var br = {
- type: ar.COMMAND,
- id: "sheet.command.set-selected-cols-visible",
- handler: (n) => {
- var l;
- const e = n.get(F), t = n.get(Pt), o = (l = e.getCurrentSelections()) == null ? void 0 : l.map((c) => c.range).filter((c) => c.rangeType === De.COLUMN);
- if (!(o != null && o.length))
- return false;
- const s = N(n.get(_n));
- if (!s)
- return false;
- const { worksheet: r, unitId: i, subUnitId: a } = s, u = o.map((c) => r.getHiddenCols(c.startColumn, c.endColumn)).flat();
- return t.executeCommand(Kn.id, {
- unitId: i,
- subUnitId: a,
- ranges: u
- });
- }
- };
- var yr = {
- type: ar.COMMAND,
- id: "sheet.command.set-col-hidden",
- handler: (n, e) => {
- var S, I, w, b;
- const t = n.get(F), o = n.get(V), s = n.get(_n), r = n.get(Pt);
- let i = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((y) => y.range).filter((y) => y.rangeType === De.COLUMN);
- if (!(i != null && i.length))
- return false;
- const a = N(s, e);
- if (!a)
- return false;
- const { worksheet: u, unitId: l, subUnitId: c } = a;
- i = Vu(a.worksheet, i);
- const d = { unitId: l, subUnitId: c, ranges: i }, h = {
- unitId: l,
- subUnitId: c,
- selections: Er(i).map((y) => ({
- range: y,
- primary: ve(y, u),
- style: null
- }))
- }, m = Wu(n, d), g2 = {
- unitId: l,
- subUnitId: c,
- reveal: true,
- selections: i.map((y) => ({
- range: y,
- primary: ve(y, u),
- style: null
- }))
- }, f = mu([
- { id: Xt2.id, params: d },
- { id: re2.id, params: h }
- ], r), p = o.onCommandExecute({
- id: yr.id,
- params: d
- }), C = mu([...p.redos], r);
- return f.result && C.result ? (n.get(cn).pushUndoRedo({
- unitID: l,
- undoMutations: [
- { id: qt2.id, params: m },
- { id: re2.id, params: g2 },
- ...(w = p.undos) != null ? w : []
- ],
- redoMutations: [
- ...(b = p.preRedos) != null ? b : [],
- { id: Xt2.id, params: d },
- { id: re2.id, params: h },
- ...p.redos
- ]
- }), true) : false;
- }
- };
- function Vu(n, e) {
- const t = n.getRowCount() - 1, o = n.getHiddenCols(), s = [];
- return e.forEach((r) => {
- const i = o.filter((a) => a.startColumn >= r.startColumn && a.endColumn <= r.endColumn);
- if (i.length) {
- let a = r.startColumn;
- i.forEach((u) => {
- u.startColumn > a && (s.push({ startColumn: a, endColumn: u.startColumn - 1, startRow: 0, endRow: t }), a = u.endColumn + 1);
- }), a <= r.endColumn && s.push({ startColumn: a, endColumn: r.endColumn, startRow: 0, endRow: t });
- } else
- s.push(r);
- }), s;
- }
- function Er(n) {
- return Hu(n).map((t) => {
- const o = t.startColumn === 0 ? t.endColumn + 1 : t.startColumn - 1;
- return {
- ...t,
- startColumn: o,
- endColumn: o
- };
- });
- }
- function Hu(n) {
- const e = [];
- let t;
- return n.sort((o, s) => o.startColumn - s.startColumn).forEach((o) => {
- if (!t) {
- t = o;
- return;
- }
- t.endColumn === o.startColumn - 1 ? t.endColumn = o.endColumn : (e.push(t), t = o);
- }), e.push(t), e;
- }
- var Ur = {
- id: "sheet.command.set-defined-name",
- type: ar.COMMAND,
- handler: (n, e) => {
- var d, h;
- const t = n.get(Pt), o = n.get(cn), s = n.get(V);
- if (!e)
- return false;
- const r = {
- ...e
- }, i = Yb(n, e), a = s.onCommandExecute({ id: Ur.id, params: e }), u = [
- ...(d = a.preRedos) != null ? d : [],
- { id: Xi.id, params: i },
- { id: sa.id, params: r },
- ...a.redos
- ], l = [
- ...(h = a.preUndos) != null ? h : [],
- { id: Xi.id, params: r },
- { id: sa.id, params: i },
- ...a.undos
- ];
- return mu(u, t) ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: l.filter(Boolean),
- redoMutations: u.filter(Boolean)
- }), true) : false;
- }
- };
- var Pr = (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (s == null)
- throw new Error("worksheet is null error!");
- const i = s.getConfig().freeze;
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ...i
- };
- };
- var ut = {
- id: "sheet.mutation.set-frozen",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s)
- return false;
- const r = s.getConfig(), { startRow: i, startColumn: a, ySplit: u, xSplit: l } = e;
- return r.freeze = { startRow: i, startColumn: a, ySplit: u, xSplit: l }, true;
- }
- };
- var Bu = {
- type: ar.COMMAND,
- id: "sheet.command.set-frozen",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s, { unitId: e.unitId, subUnitId: e.subUnitId });
- if (!r)
- return false;
- const { unitId: i, subUnitId: a, worksheet: u } = r, { startColumn: l, startRow: c, xSplit: d, ySplit: h } = e;
- if (c >= u.getRowCount() || l >= u.getColumnCount() || d >= u.getColumnCount() || h >= u.getRowCount())
- return false;
- const m = {
- unitId: i,
- subUnitId: a,
- ...e
- }, g2 = Pr(n, m);
- return t.syncExecuteCommand(ut.id, m) ? (o.pushUndoRedo({
- unitID: i,
- undoMutations: [{ id: ut.id, params: g2 }],
- redoMutations: [{ id: ut.id, params: m }]
- }), true) : false;
- }
- };
- var Fu = {
- type: ar.COMMAND,
- id: "sheet.command.cancel-frozen",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(_n), s = n.get(cn), r = N(o, { unitId: e == null ? void 0 : e.unitId, subUnitId: e == null ? void 0 : e.subUnitId });
- if (!r)
- return false;
- const { unitId: i, subUnitId: a } = r, u = {
- unitId: i,
- subUnitId: a,
- startRow: -1,
- startColumn: -1,
- xSplit: 0,
- ySplit: 0
- }, l = Pr(n, u);
- return t.syncExecuteCommand(ut.id, u) && s.pushUndoRedo({
- unitID: i,
- undoMutations: [{ id: ut.id, params: l }],
- redoMutations: [{ id: ut.id, params: u }]
- }), true;
- }
- };
- var Vt = {
- id: "sheet.mutation.set-gridlines-color",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = N(n.get(_n), e);
- if (!t)
- return false;
- const { worksheet: o } = t, s = o.getConfig();
- return s.gridlinesColor = e.color, true;
- }
- };
- var ju = {
- type: ar.COMMAND,
- id: "sheet.command.set-gridlines-color",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s);
- if (!r)
- return false;
- const { worksheet: i } = r, a = i.getConfig().gridlinesColor;
- if (a === (e == null ? void 0 : e.color))
- return false;
- const { unitId: u, subUnitId: l } = r, c = {
- color: e == null ? void 0 : e.color,
- unitId: u,
- subUnitId: l
- }, d = {
- color: a,
- unitId: u,
- subUnitId: l
- };
- return t.syncExecuteCommand(Vt.id, c) ? (o.pushUndoRedo({
- unitID: u,
- undoMutations: [{ id: Vt.id, params: d }],
- redoMutations: [{ id: Vt.id, params: c }]
- }), true) : false;
- }
- };
- var he = {
- id: "sheet.mutation.set-range-protection",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, rule: s, ruleId: r } = e;
- return n.get(de).setRule(t, o, r, s), true;
- }
- };
- var qd = (n, e) => {
- const { unitId: t, subUnitId: o, ruleId: s } = e, i = n.get(de).getRule(t, o, s);
- return i ? {
- id: he.id,
- params: {
- ...e,
- rule: i
- }
- } : null;
- };
- var Ct2 = {
- id: "sheet.mutation.set-worksheet-protection",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, rule: s } = e;
- return n.get(Ye).setRule(t, o, s), true;
- }
- };
- var Gu = {
- type: ar.COMMAND,
- id: "sheet.command.set-protection",
- async handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), o = n.get(cn), s = n.get(de), { rule: r, oldRule: i } = e, { unitId: a, subUnitId: u } = r, l = [], c = [];
- return (i == null ? void 0 : i.unitType) === r.unitType ? r.unitType === D.Worksheet ? (l.push({ id: Ct2.id, params: { unitId: a, subUnitId: u, rule: r } }), c.push({ id: Ct2.id, params: { unitId: a, subUnitId: u, rule: i } })) : (l.push({ id: he.id, params: { unitId: a, subUnitId: u, rule: r, ruleId: r.id } }), c.push({ id: he.id, params: { unitId: a, subUnitId: u, ruleId: i.id, rule: i } })) : (i && (i.unitType === D.Worksheet ? (l.push({ id: St.id, params: { unitId: a, subUnitId: u } }), c.push({ id: ct.id, params: { unitId: a, rule: i, subUnitId: i.subUnitId } })) : i.unitType === D.SelectRange && (l.push({ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: [i.id] } }), c.push({ id: Ne.id, params: { unitId: a, subUnitId: u, rules: [i] } }))), r.unitType === D.Worksheet ? (l.push({ id: ct.id, params: { unitId: a, rule: r, subUnitId: r.subUnitId } }), c.unshift({ id: St.id, params: { unitId: a, subUnitId: u } })) : r.unitType === D.SelectRange && (r.id = s.createRuleId(a, u), l.push({ id: Ne.id, params: { unitId: a, subUnitId: u, rules: [r] } }), c.unshift({ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: [r.id] } }))), mu(l, t) && o.pushUndoRedo({
- unitID: a,
- undoMutations: c,
- redoMutations: l
- }), true;
- }
- };
- var zu = (n, e) => {
- const { unitId: t, subUnitId: o, rowData: s } = n, r = {}, i = e.getRowManager();
- for (const a in s) {
- const u = s[a], l = i.getRow(Number(a));
- r[a] = Du(l, u);
- }
- return {
- unitId: t,
- subUnitId: o,
- rowData: r
- };
- };
- var Ht = {
- id: "sheet.mutation.set-row-data",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { rowData: t } = e, o = n.get(_n), s = N(o, e);
- if (!s)
- return false;
- const { worksheet: r } = s, i = r.getRowManager();
- for (const a in t) {
- const u = t[a];
- if (u == null) {
- i.removeRow(Number(a));
- continue;
- }
- const l = i.getRowOrCreate(Number(a));
- Object.assign(l, u);
- }
- return true;
- }
- };
- var Ku = {
- type: ar.COMMAND,
- id: "sheet.command.set-row-data",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s, e);
- if (!r)
- return false;
- const { rowData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = {
- subUnitId: u,
- unitId: a,
- rowData: i
- }, d = zu(c, l);
- return t.syncExecuteCommand(Ht.id, c) ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Ht.id, params: d }],
- redoMutations: [{ id: Ht.id, params: c }]
- }), true) : false;
- }
- };
- var Ju = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- };
- var Zt = {
- id: "sheet.mutation.set-row-visible",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId).getRowManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startRow; a < i.endRow + 1; a++) {
- const u = s.getRowOrCreate(a);
- u != null && (u.hd = 0);
- }
- }
- return true;
- }
- };
- var Yu = (n, e) => {
- if (n.get(_n).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- };
- var Qt = {
- id: "sheet.mutation.set-row-hidden",
- type: ar.MUTATION,
- handler: (n, e) => {
- const o = n.get(_n).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId).getRowManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startRow; a < i.endRow + 1; a++) {
- const u = s.getRowOrCreate(a);
- u != null && (u.hd = 1);
- }
- }
- return true;
- }
- };
- var Jn = {
- type: ar.COMMAND,
- id: "sheet.command.set-specific-rows-visible",
- handler: (n, e) => {
- var C, S, I;
- const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(Pt), i = n.get(cn), a = n.get(V), u = N(n.get(_n), { unitId: t, subUnitId: o });
- if (!u)
- return false;
- const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = {
- unitId: t,
- subUnitId: o,
- reveal: true,
- selections: s.map((w) => ({
- range: w,
- primary: ve(w, l),
- style: null
- }))
- }, h = Ju(n, c), m = {
- unitId: t,
- subUnitId: o,
- selections: Nr(s).map((w) => ({
- range: w,
- primary: ve(w, l),
- style: null
- }))
- }, g2 = mu(
- [
- { id: Zt.id, params: c },
- { id: re2.id, params: d }
- ],
- r
- ), f = a.onCommandExecute({
- id: Jn.id,
- params: e
- }), p = mu([...f.redos], r);
- return g2.result && p.result && i.pushUndoRedo({
- unitID: t,
- undoMutations: [
- ...(C = f.preUndos) != null ? C : [],
- { id: Qt.id, params: h },
- { id: re2.id, params: m },
- ...(S = f.undos) != null ? S : []
- ],
- redoMutations: [
- ...(I = f.preRedos) != null ? I : [],
- { id: Zt.id, params: c },
- { id: re2.id, params: d },
- ...f.redos
- ]
- }), true;
- }
- };
- var Tr = {
- type: ar.COMMAND,
- id: "sheet.command.set-selected-rows-visible",
- handler: async (n) => {
- var c;
- const e = n.get(F), t = n.get(_n), o = n.get(Pt), s = (c = e.getCurrentSelections()) == null ? void 0 : c.map((d) => d.range).filter((d) => d.rangeType === De.ROW);
- if (!(s != null && s.length))
- return false;
- const r = N(t);
- if (!r)
- return false;
- const { worksheet: i, unitId: a, subUnitId: u } = r, l = s.map((d) => i.getHiddenRows(d.startRow, d.endRow)).flat();
- return o.executeCommand(Jn.id, {
- unitId: a,
- subUnitId: u,
- ranges: l
- });
- }
- };
- var kr = {
- type: ar.COMMAND,
- id: "sheet.command.set-rows-hidden",
- handler: (n, e) => {
- var S, I, w, b, y, x;
- const t = n.get(F), o = n.get(Pt), s = n.get(cn), r = n.get(_n), i = n.get(V);
- let a = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((T2) => T2.range).filter((T2) => T2.rangeType === De.ROW);
- if (!(a != null && a.length))
- return false;
- const u = N(r, e);
- if (!u)
- return false;
- a = Xu(u.worksheet, a);
- const { unitId: l, subUnitId: c, worksheet: d } = u, h = { unitId: l, subUnitId: c, ranges: a }, m = {
- unitId: l,
- subUnitId: c,
- selections: Nr(a).map((T2) => ({
- range: T2,
- primary: ve(T2, d),
- style: null
- }))
- }, g2 = Yu(n, h), f = {
- unitId: l,
- subUnitId: c,
- reveal: true,
- selections: a.map((T2) => ({
- range: T2,
- primary: ve(T2, d),
- style: null
- }))
- }, p = i.onCommandExecute({ id: kr.id, params: h });
- return mu([
- ...(w = p.preRedos) != null ? w : [],
- { id: Qt.id, params: h },
- { id: re2.id, params: m },
- ...p.redos
- ], o).result && s.pushUndoRedo({
- unitID: l,
- undoMutations: [
- ...(b = p.preUndos) != null ? b : [],
- { id: Zt.id, params: g2 },
- { id: re2.id, params: f },
- ...(y = p.undos) != null ? y : []
- ],
- redoMutations: [
- ...(x = p.preRedos) != null ? x : [],
- { id: Qt.id, params: h },
- { id: re2.id, params: m },
- ...p.redos
- ]
- }), true;
- }
- };
- function Xu(n, e) {
- const t = n.getMaxColumns() - 1, o = n.getHiddenRows(), s = [];
- return e.forEach((r) => {
- const i = o.filter((a) => a.startRow >= r.startRow && a.endRow <= r.endRow);
- if (i.length) {
- let a = r.startRow;
- i.forEach((u) => {
- u.startRow > a && (s.push({ startRow: a, endRow: u.startRow - 1, startColumn: 0, endColumn: t }), a = u.endRow + 1);
- }), a <= r.endRow && s.push({ startRow: a, endRow: r.endRow, startColumn: 0, endColumn: t });
- } else
- s.push(r);
- }), s;
- }
- function Nr(n) {
- return qu(n).map((t) => {
- const o = t.startRow === 0 ? t.endRow + 1 : t.startRow - 1;
- return {
- ...t,
- startRow: o,
- endRow: o
- };
- });
- }
- function qu(n) {
- const e = [];
- let t;
- return n.sort((o, s) => o.startRow - s.startRow).forEach((o) => {
- if (!t) {
- t = o;
- return;
- }
- o.startRow === t.endRow + 1 ? t.endRow = o.endRow : (e.push(t), t = o);
- }), e.push(t), e;
- }
- var fe = {
- type: ar.COMMAND,
- id: "sheet.command.set-style",
- handler: (n, e) => {
- var b;
- const t = n.get(_n), o = N(t, e);
- if (!o)
- return false;
- const { unitId: s, subUnitId: r, worksheet: i } = o, { range: a, style: u } = e, l = n.get(Pt), c = n.get(cn), d = n.get(F), h = a ? [a] : (b = d.getCurrentSelections()) == null ? void 0 : b.map((y) => y.range);
- if (!(h != null && h.length))
- return false;
- const m = new kt(), g2 = Za(i);
- if (re.isArray(u.value))
- for (let y = 0; y < h.length; y++)
- g2.forOperableEach(h[y], (x, T2, U) => {
- m.setValue(x, T2, {
- s: {
- [u.type]: u.value[x - U.startRow][T2 - U.startColumn]
- }
- });
- });
- else
- for (let y = 0; y < h.length; y++) {
- const x = {
- s: {
- [u.type]: u.value
- }
- };
- g2.forOperableEach(h[y], (T2, U) => m.setValue(T2, U, x));
- }
- const f = {
- subUnitId: r,
- unitId: s,
- cellValue: m.getMatrix()
- }, p = Ae(
- n,
- f
- ), C = l.syncExecuteCommand(
- Q.id,
- f
- ), { undos: S, redos: I } = n.get(V).onCommandExecute({
- id: fe.id,
- params: e
- }), w = mu([...I], l);
- return C && w.result ? (c.pushUndoRedo({
- unitID: f.unitId,
- undoMutations: [{ id: Q.id, params: p }, ...S],
- redoMutations: [{ id: Q.id, params: f }, ...I]
- }), true) : false;
- }
- };
- var Zd = {
- type: ar.COMMAND,
- id: "sheet.command.set-bold",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e)
- return false;
- const t = N(n.get(_n));
- if (!t)
- return false;
- const { worksheet: o } = t, { actualRow: s, actualColumn: r } = e.primary, a = {
- style: {
- type: "bl",
- value: o.getRange(s, r).getFontWeight() === Gs.BOLD ? we.FALSE : we.TRUE
- }
- };
- return n.get(Pt).syncExecuteCommand(fe.id, a);
- }
- };
- var Qd = {
- type: ar.COMMAND,
- id: "sheet.command.set-italic",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e)
- return false;
- const t = N(n.get(_n));
- if (!t)
- return false;
- const { worksheet: o } = t;
- let s = true;
- if (e.primary) {
- const { startRow: i, startColumn: a } = e.primary;
- s = o.getRange(i, a).getFontStyle() === Vs.ITALIC;
- }
- const r = {
- style: {
- type: "it",
- value: s ? we.FALSE : we.TRUE
- }
- };
- return n.get(Pt).syncExecuteCommand(fe.id, r);
- }
- };
- var eh = {
- type: ar.COMMAND,
- id: "sheet.command.set-underline",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e)
- return false;
- const t = N(n.get(_n));
- if (!t)
- return false;
- const { worksheet: o } = t;
- let s = true;
- e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getUnderline().s);
- const r = {
- style: {
- type: "ul",
- value: {
- s: s ? we.FALSE : we.TRUE
- }
- }
- };
- return n.get(Pt).syncExecuteCommand(fe.id, r);
- }
- };
- var th = {
- type: ar.COMMAND,
- id: "sheet.command.set-stroke",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e)
- return false;
- const t = N(n.get(_n));
- if (!t)
- return false;
- const { worksheet: o } = t;
- let s = true;
- e.primary && (s = !!o.getRange(e.primary.actualRow, e.primary.actualColumn).getStrikeThrough().s);
- const r = {
- style: {
- type: "st",
- value: { s: s ? we.FALSE : we.TRUE }
- }
- };
- return n.get(Pt).syncExecuteCommand(fe.id, r);
- }
- };
- var nh = {
- type: ar.COMMAND,
- id: "sheet.command.set-overline",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e)
- return false;
- const t = N(n.get(_n));
- if (!t)
- return false;
- const { worksheet: o } = t;
- let s = true;
- e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getOverline().s);
- const r = {
- style: {
- type: "ol",
- value: {
- s: s ? we.FALSE : we.TRUE
- }
- }
- };
- return n.get(Pt).syncExecuteCommand(fe.id, r);
- }
- };
- var oh = {
- type: ar.COMMAND,
- id: "sheet.command.set-font-family",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = n.get(Pt), o = {
- style: {
- type: "ff",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var sh = {
- type: ar.COMMAND,
- id: "sheet.command.set-font-size",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = n.get(Pt), o = {
- style: {
- type: "fs",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var Zu = {
- type: ar.COMMAND,
- id: "sheet.command.set-text-color",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = n.get(Pt), o = {
- style: {
- type: "cl",
- value: {
- rgb: e.value
- }
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var Qu = {
- type: ar.COMMAND,
- id: "sheet.command.reset-text-color",
- handler: (n) => {
- const e = n.get(Pt), t = {
- style: {
- type: "cl",
- value: {
- rgb: null
- // use null to reset text color
- }
- }
- };
- return e.syncExecuteCommand(fe.id, t);
- }
- };
- var el = {
- type: ar.COMMAND,
- id: "sheet.command.set-background-color",
- handler: (n, e) => {
- if (!e || !e.value)
- return false;
- const t = n.get(Pt), o = {
- style: {
- type: "bg",
- value: {
- rgb: e.value
- }
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var tl = {
- type: ar.COMMAND,
- id: "sheet.command.reset-background-color",
- handler: (n) => {
- const e = n.get(Pt), t = {
- style: {
- type: "bg",
- value: {
- rgb: null
- // use null to reset background color
- }
- }
- };
- return e.syncExecuteCommand(fe.id, t);
- }
- };
- var nl = {
- type: ar.COMMAND,
- id: "sheet.command.set-vertical-text-align",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = n.get(Pt), o = {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- style: {
- type: "vt",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var ol = {
- type: ar.COMMAND,
- id: "sheet.command.set-horizontal-text-align",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = n.get(Pt), o = {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- style: {
- type: "ht",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var sl = {
- type: ar.COMMAND,
- id: "sheet.command.set-text-wrap",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = n.get(Pt), o = {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- style: {
- type: "tb",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- };
- var rl = {
- type: ar.COMMAND,
- id: "sheet.command.set-text-rotation",
- handler: (n, e) => {
- if (!e)
- return false;
- const t = typeof e.value == "number" ? { a: e.value } : { a: 0, v: we.TRUE }, o = n.get(Pt), s = {
- style: {
- type: "tr",
- value: t
- }
- };
- return o.syncExecuteCommand(fe.id, s);
- }
- };
- var il = (n, e) => {
- const r = n.get(_n).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor;
- return {
- ...re.deepClone(e),
- color: r
- };
- };
- var fn3 = {
- id: "sheet.mutation.set-tab-color",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n).getUniverSheetInstance(e.unitId);
- if (!t)
- return false;
- const o = t.getSheetBySheetId(e.subUnitId);
- return o ? (o.getConfig().tabColor = e.color, true) : false;
- }
- };
- var al = {
- type: ar.COMMAND,
- id: "sheet.command.set-tab-color",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = N(n.get(_n));
- if (!s)
- return false;
- const { unitId: r, subUnitId: i } = s, a = {
- color: e.value,
- unitId: r,
- subUnitId: i
- }, u = il(n, a);
- return t.syncExecuteCommand(fn3.id, a) ? (o.pushUndoRedo({
- unitID: r,
- undoMutations: [{ id: fn3.id, params: u }],
- redoMutations: [{ id: fn3.id, params: a }]
- }), true) : false;
- }
- };
- var Or = {
- id: "sheet.mutation.set-workbook-name",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n).getUnit(e.unitId, Fe.UNIVER_SHEET);
- return t ? (t.setName(e.name), true) : false;
- }
- };
- var Dr = {
- type: ar.COMMAND,
- id: "sheet.command.set-workbook-name",
- handler: async (n, e) => {
- var l;
- if (!n.get(_n).getUnit(e.unitId, Fe.UNIVER_SHEET))
- return false;
- const r = n.get(V).onCommandExecute({
- id: Dr.id,
- params: e
- }), i = {
- name: e.name,
- unitId: e.unitId
- }, a = [
- ...(l = r.preRedos) != null ? l : [],
- { id: Or.id, params: i },
- ...r.redos
- ], u = n.get(Pt);
- return mu(a, u).result;
- }
- };
- var an = {
- id: "sheet.operation.set-worksheet-active",
- type: ar.OPERATION,
- handler: (n, e) => {
- const t = n.get(_n).getUniverSheetInstance(e.unitId);
- if (!t)
- return false;
- const o = t.getWorksheets();
- for (const [, s] of o)
- if (s.getSheetId() === e.subUnitId)
- return t.setActiveSheet(s), true;
- return false;
- }
- };
- var ul = 4;
- var Ar = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-activate",
- handler: (n, e, t) => {
- const o = n.get(Pt), s = N(n.get(_n), e);
- if (!s)
- return false;
- const { unitId: r, subUnitId: i } = s;
- return new Promise((a) => {
- setTimeout(() => {
- const u = o.syncExecuteCommand(an.id, {
- unitId: r,
- subUnitId: i
- }, t);
- a(u);
- }, ul);
- });
- }
- };
- var xr = (n, e) => {
- const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getColumnManager();
- for (let a = 0; a < s.length; a++) {
- const u = s[a];
- for (let l = u.startColumn; l < u.endColumn + 1; l++) {
- const c = i.getColumnOrCreate(l);
- r[l] = c.w;
- }
- }
- return {
- unitId: t,
- subUnitId: o,
- ranges: s,
- colWidth: r
- };
- };
- var tt = {
- id: "sheet.mutation.set-worksheet-col-width",
- type: ar.MUTATION,
- handler: (n, e) => {
- var u;
- const t = n.get(_n), o = N(t, e);
- if (!o)
- return false;
- const { worksheet: s } = o, r = s.getConfig().defaultColumnWidth, i = s.getColumnManager(), a = e.ranges;
- for (let l = 0; l < a.length; l++) {
- const c = a[l];
- for (let d = c.startColumn; d < c.endColumn + 1; d++) {
- if (!s.getColVisible(d))
- continue;
- const m = i.getColumnOrCreate(d);
- typeof e.colWidth == "number" ? m.w = e.colWidth : m.w = (u = e.colWidth[d]) != null ? u : r;
- }
- }
- return true;
- }
- };
- var Oo = {
- type: ar.COMMAND,
- id: "sheet.command.delta-column-width",
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- const o = n.get(F).getCurrentSelections();
- if (!(o != null && o.length))
- return false;
- const s = n.get(Pt), r = n.get(cn), i = N(n.get(_n));
- if (!i)
- return false;
- const { worksheet: a, unitId: u, subUnitId: l } = i, { anchorCol: c, deltaX: d } = e, m = a.getColumnWidth(c) + d, g2 = o.length === 1 && o[0].range.rangeType === De.ALL, f = o.filter((x) => x.range.rangeType === De.COLUMN), p = g2 ? De.ALL : f.some(({ range: x }) => {
- const { startColumn: T2, endColumn: U } = x;
- return T2 <= c && c <= U;
- }) ? De.COLUMN : De.NORMAL;
- let C;
- if (p === De.ALL) {
- const x = a.getRowCount(), T2 = new Array(a.getColumnCount()).fill(void 0).map(
- (U, P) => ({ startRow: 0, endRow: x - 1, startColumn: P, endColumn: P })
- );
- C = {
- subUnitId: l,
- unitId: u,
- colWidth: m,
- ranges: T2
- };
- } else
- p === De.COLUMN ? C = {
- subUnitId: l,
- unitId: u,
- ranges: f.map((x) => en.clone(x.range)),
- colWidth: m
- } : C = {
- subUnitId: l,
- unitId: u,
- colWidth: m,
- ranges: [
- {
- startRow: 0,
- endRow: a.getMaxRows() - 1,
- startColumn: c,
- endColumn: c
- }
- ]
- };
- const { undos: S, redos: I } = n.get(V).onCommandExecute({
- id: Oo.id,
- params: C
- }), w = xr(
- C,
- a
- ), b = s.syncExecuteCommand(
- tt.id,
- C
- ), y = mu([...I], s);
- return b && y.result && r.pushUndoRedo({
- unitID: u,
- undoMutations: [{ id: tt.id, params: w }, ...S],
- redoMutations: [{ id: tt.id, params: C }, ...I]
- }), true;
- }
- };
- var Mn = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-col-width",
- handler: (n, e) => {
- var S, I, w, b;
- const t = n.get(F), o = n.get(Pt), s = n.get(cn), r = n.get(V), i = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((y) => y.range);
- if (!(i != null && i.length))
- return false;
- const a = N(n.get(_n), e);
- if (!a)
- return false;
- const { subUnitId: u, unitId: l, worksheet: c } = a, d = {
- subUnitId: u,
- unitId: l,
- ranges: i,
- colWidth: e.value
- }, h = xr(d, c), m = o.syncExecuteCommand(tt.id, d), { undos: g2, redos: f } = n.get(V).onCommandExecute({
- id: Mn.id,
- params: d
- }), p = r.onCommandExecute({
- id: Mn.id,
- params: d
- }), C = mu([...f, ...p.redos], o);
- return m && C.result ? (s.pushUndoRedo({
- unitID: l,
- undoMutations: [...(w = p.preUndos) != null ? w : [], { id: tt.id, params: h }, ...g2],
- redoMutations: [...(b = p.preRedos) != null ? b : [], { id: tt.id, params: d }, ...f]
- }), true) : false;
- }
- };
- var ll = {
- type: ar.COMMAND,
- id: "sheet.command.set-col-is-auto-width",
- handler: async (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(F), r = n.get(_n), i = N(r, e);
- if (!i)
- return false;
- const { unitId: a, subUnitId: u } = i;
- let l = [];
- if (e != null && e.ranges)
- l = [...e.ranges];
- else {
- const g2 = s.getCurrentSelections();
- for (let f = 0; f < g2.length; f++)
- l.push(g2[f].range);
- }
- if (!(l != null && l.length))
- return false;
- const c = {
- unitId: a,
- subUnitId: u,
- ranges: l
- }, { undos: d, redos: h } = n.get(V).onCommandExecute({
- id: ll.id,
- params: c
- });
- return mu([...h], t).result ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [...d],
- redoMutations: [...h]
- }), true) : false;
- }
- };
- var Bt = {
- id: "sheet.mutation.set-worksheet-default-style",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { defaultStyle: t } = e, o = n.get(_n), s = N(o);
- if (!s)
- return false;
- const { worksheet: r } = s;
- return r ? (r.setDefaultCellStyle(t), true) : false;
- }
- };
- var cl = (n, e) => {
- const t = Et(n.get(_n), e);
- if (!t)
- throw new Error("[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- subUnitId: o.getSheetId(),
- defaultStyle: o.getDefaultCellStyle()
- };
- };
- var dl = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-default-style",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), { unitId: s } = e, r = cl(n, e);
- return t.syncExecuteCommand(Bt.id, e) ? (o.pushUndoRedo({
- unitID: s,
- undoMutations: [{ id: Bt.id, params: r }],
- redoMutations: [{ id: Bt.id, params: e }]
- }), true) : false;
- }
- };
- var $r = (n, e) => {
- const t = Et(n.get(_n), e);
- if (!t)
- throw new Error("[SetWorksheetHideMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- hidden: o.isSheetHidden(),
- unitId: e.unitId,
- subUnitId: o.getSheetId()
- };
- };
- var lt = {
- id: "sheet.mutation.set-worksheet-hidden",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n).getUniverSheetInstance(e.unitId);
- if (t == null)
- return false;
- const o = t.getSheetBySheetId(e.subUnitId);
- return o ? (o.getConfig().hidden = e.hidden, true) : false;
- }
- };
- var hl = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-hidden",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(NE), r = n.get(Vr), i = N(n.get(_n), e);
- if (!i)
- return false;
- const { workbook: a, worksheet: u, unitId: l, subUnitId: c } = i;
- if (u.getConfig().hidden === we.TRUE)
- return false;
- const h = {
- unitId: l,
- subUnitId: c,
- hidden: we.TRUE
- }, m = $r(n, h);
- return a.getSheets().filter((C) => C.getConfig().hidden === we.FALSE).length === 1 ? (s.emit(r.t("sheets.info.hideSheet")), false) : t.syncExecuteCommand(lt.id, h) ? (o.pushUndoRedo({
- unitID: l,
- undoMutations: [{ id: lt.id, params: m }],
- redoMutations: [{ id: lt.id, params: h }]
- }), true) : false;
- }
- };
- var ml = (n, e) => {
- const t = Et(n.get(_n), e);
- if (!t)
- throw new Error("[SetWorksheetNameMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- name: o.getName(),
- subUnitId: o.getSheetId()
- };
- };
- var _n2 = {
- id: "sheet.mutation.set-worksheet-name",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n).getUniverSheetInstance(e.unitId);
- if (t == null)
- return false;
- const o = t.getSheetBySheetId(e.subUnitId);
- return o ? (o.getConfig().name = e.name, true) : false;
- }
- };
- var Do = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-name",
- handler: (n, e) => {
- var g2, f;
- const t = n.get(Pt), o = n.get(cn), s = n.get(V), r = N(n.get(_n), e);
- if (!r)
- return false;
- const { unitId: i, subUnitId: a } = r, u = {
- subUnitId: a,
- name: e.name,
- unitId: i
- }, l = ml(
- n,
- u
- ), c = s.onCommandExecute({
- id: Do.id,
- params: e
- }), d = [
- ...(g2 = c.preRedos) != null ? g2 : [],
- { id: _n2.id, params: u },
- ...c.redos
- ], h = [
- ...(f = c.preUndos) != null ? f : [],
- { id: _n2.id, params: l },
- ...c.undos
- ];
- return mu(d, t).result ? (o.pushUndoRedo({
- unitID: i,
- undoMutations: h,
- redoMutations: d
- }), true) : false;
- }
- };
- var gl = (n, e) => ({
- ...re.deepClone(e),
- toOrder: e.fromOrder,
- fromOrder: e.toOrder
- });
- var Rn = {
- id: "sheet.mutation.set-worksheet-order",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n).getUniverSheetInstance(e.unitId);
- if (!t)
- return false;
- const o = t.getConfig();
- return o.sheetOrder.splice(e.fromOrder, 1), o.sheetOrder.splice(e.toOrder, 0, e.subUnitId), true;
- }
- };
- var Wr = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-order",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = N(n.get(_n), e);
- if (!s)
- return false;
- const { workbook: r, unitId: i, subUnitId: a } = s, l = {
- fromOrder: r.getConfig().sheetOrder.indexOf(a),
- toOrder: e.order,
- unitId: i,
- subUnitId: a
- }, c = gl(n, l);
- return t.syncExecuteCommand(Rn.id, l) ? (o.pushUndoRedo({
- unitID: i,
- undoMutations: [{ id: Rn.id, params: c }],
- redoMutations: [{ id: Rn.id, params: l }]
- }), true) : false;
- }
- };
- var un = class {
- constructor() {
- R(this, "_model", /* @__PURE__ */ new Map());
- R(this, "_pointChange", new Subject());
- R(this, "pointChange$", this._pointChange.asObservable());
- }
- addRule(e) {
- this._ensureSubUnitMap(e.unitId).set(e.subUnitId, e), this._pointChange.next(e);
- }
- deleteRule(e, t) {
- var s, r, i;
- const o = (s = this._model.get(e)) == null ? void 0 : s.get(t);
- o && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.delete(t), this._pointChange.next(o));
- }
- getRule(e, t) {
- var o, s;
- return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
- }
- toObject() {
- const e = {};
- return [...this._model.keys()].forEach((o) => {
- const s = this._model.get(o);
- s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
- const a = s.get(i);
- a && e[o].push(a);
- }));
- }), e;
- }
- fromObject(e) {
- const t = /* @__PURE__ */ new Map();
- Object.keys(e).forEach((o) => {
- const s = e[o];
- if (s != null && s.length) {
- const r = /* @__PURE__ */ new Map();
- s.forEach((i) => {
- r.set(i.subUnitId, i);
- }), t.set(o, r);
- }
- }), this._model = t;
- }
- deleteUnitModel(e) {
- this._model.delete(e);
- }
- _ensureSubUnitMap(e) {
- let t = this._model.get(e);
- return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
- }
- getTargetByPermissionId(e, t) {
- const o = this._model.get(e);
- if (!o)
- return null;
- for (const [s, r] of o)
- if (r.permissionId === t)
- return [e, s];
- }
- };
- var Lr = class {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.Delete);
- R(this, "status", fl.INIT);
- R(this, "value", true);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Delete}.${o}`;
- }
- };
- var Vr2 = class {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.ManageCollaborator);
- R(this, "status", fl.INIT);
- R(this, "value", true);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.ManageCollaborator}.${o}`;
- }
- };
- var Ie = () => [Io, Pe, Vr2, Lr];
- var it = [_.Edit, _.View, _.ManageCollaborator, _.Delete];
- var rh = (n = "unitId", e = "subUnitId", t = "permissionId") => Ie().reduce((o, s) => {
- const r = new s(n, e, t);
- return o[r.subType] = r.value, o;
- }, {});
- var en2 = () => [
- Me,
- Gs2,
- Ws,
- Js,
- Ls,
- js,
- Mo,
- Hs,
- Bs,
- bo,
- vo,
- Fs,
- Ks,
- _o,
- eu,
- Ys,
- zs,
- Vs2
- ];
- var fl2 = [
- _.Edit,
- _.Print,
- _.Comment,
- _.View,
- _.Copy,
- _.Export,
- _.ManageCollaborator,
- _.CreateSheet,
- _.DeleteSheet,
- _.RenameSheet,
- _.HideSheet,
- _.Duplicate,
- _.Share,
- _.MoveSheet,
- _.CopySheet,
- _.RecoverHistory,
- _.ViewHistory,
- _.CreatePermissionObject
- ];
- var we2 = () => [
- Te,
- Hn,
- rr2,
- Zs
- ];
- var ke = () => [
- Xs,
- qs,
- Qs,
- er,
- tr2,
- nr,
- sr,
- or,
- ir,
- ar2,
- wn,
- $t,
- Wt,
- ur
- ];
- var eo = [
- _.Copy,
- _.DeleteColumn,
- _.DeleteRow,
- _.EditExtraObject,
- _.Filter,
- _.InsertColumn,
- _.InsertRow,
- _.InsertHyperlink,
- _.PivotTable,
- _.SetCellStyle,
- _.SetCellValue,
- _.SetColumnStyle,
- _.SetRowStyle,
- _.Sort
- ];
- var Rl = Object.defineProperty;
- var pl = Object.getOwnPropertyDescriptor;
- var Cl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? pl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Rl(e, t, s), s;
- };
- var Ze2 = (n, e) => (t, o) => e(t, o, n);
- var Sl = "SHEET_WORKSHEET_PROTECTION_PLUGIN";
- var wl = "SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN";
- var bn = class extends J0 {
- constructor(n, e, t, o, s, r, i, a) {
- super(), this._permissionService = n, this._univerInstanceService = e, this._injector = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointRuleModel = s, this._resourceManagerService = r, this._rangeProtectionRuleModel = i, this._logService = a, this._init(), this._initRuleChange(), this._initRuleSnapshot(), this._initPointSnapshot();
- }
- _init() {
- const n = (e) => {
- const t = e.getUnitId(), o = (s) => {
- const r = s.getSheetId();
- [...we2(), ...ke()].forEach((i) => {
- const a = new i(t, r);
- this._permissionService.addPermissionPoint(a);
- }), this._logService.debug("[WorksheetPermissionService]", "Initialization completed", t, r);
- };
- e.getSheets().forEach((s) => {
- o(s);
- }), e.sheetCreated$.subscribe((s) => {
- o(s);
- }), e.sheetDisposed$.subscribe((s) => {
- const r = s.getSheetId();
- this._rangeProtectionRuleModel.getSubunitRuleList(t, r).forEach((a) => {
- [...Ie()].forEach((u) => {
- const l = new u(t, r, a.permissionId);
- this._permissionService.deletePermissionPoint(l.id);
- });
- }), [...we2(), ...ke()].forEach((a) => {
- const u = new a(t, r);
- this._permissionService.deletePermissionPoint(u.id);
- });
- });
- };
- this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((e) => {
- n(e);
- }), this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe(n), this._univerInstanceService.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).pipe(takeUntil(this.dispose$)).subscribe((e) => {
- e.getSheets().forEach((t) => {
- const o = e.getUnitId(), s = t.getSheetId();
- we2().forEach((r) => {
- const i = new r(o, s);
- this._permissionService.deletePermissionPoint(i.id);
- });
- });
- });
- }
- _initRuleChange() {
- this.disposeWithMe(
- this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => {
- switch (n.type) {
- case "add":
- break;
- case "delete": {
- we2().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(t.id, true);
- });
- break;
- }
- case "set": {
- we2().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(t.id, n.rule);
- });
- break;
- }
- }
- })
- );
- }
- _initRuleSnapshot() {
- const n = () => {
- const t = this._worksheetProtectionRuleModel.toObject();
- return JSON.stringify(t);
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- toJson: n,
- parseJson: e,
- pluginName: Sl,
- businesses: [Sn.UNIVER_SHEET],
- onLoad: (t, o) => {
- this._worksheetProtectionRuleModel.fromObject(o), Object.keys(o).forEach((s) => {
- we2().forEach((r) => {
- const i = new r(t, s);
- i.value = false, this._permissionService.addPermissionPoint(i);
- });
- }), this._worksheetProtectionRuleModel.changeRuleInitState(true);
- },
- onUnLoad: (t) => {
- const o = this._univerInstanceService.getUnit(t);
- o && (o.getSheets().forEach((s) => {
- const r = s.getSheetId();
- [...we2(), ...ke()].forEach((i) => {
- const a = new i(t, r);
- this._permissionService.deletePermissionPoint(a.id);
- });
- }), en2().forEach((s) => {
- const r = new s(t);
- this._permissionService.deletePermissionPoint(r.id);
- })), this._worksheetProtectionRuleModel.deleteUnitModel(t);
- }
- })
- );
- }
- _initPointSnapshot() {
- const n = () => {
- const t = this._worksheetProtectionPointRuleModel.toObject();
- return JSON.stringify(t);
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- toJson: n,
- parseJson: e,
- pluginName: wl,
- businesses: [Sn.UNIVER_SHEET],
- onLoad: (t, o) => {
- this._worksheetProtectionPointRuleModel.fromObject(o), Object.keys(o).forEach((s) => {
- ke().forEach((r) => {
- const i = new r(t, s);
- this._permissionService.addPermissionPoint(i);
- });
- });
- },
- onUnLoad: (t) => {
- this._worksheetProtectionPointRuleModel.deleteUnitModel(t);
- }
- })
- );
- }
- };
- bn = Cl([
- Ze2(0, ot(UE)),
- Ze2(1, ot(_n)),
- Ze2(2, ot(Ot)),
- Ze2(3, ot(Ye)),
- Ze2(4, ot(un)),
- Ze2(5, ot(Bi)),
- Ze2(6, ot(de)),
- Ze2(7, ot(Mt))
- ], bn);
- var Ao = {
- id: "sheet.mutation.set-worksheet-permission-points",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { rule: t } = e;
- return n.get(un).addRule(t), true;
- }
- };
- var Il = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-permission-points",
- async handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), { rule: o } = e;
- return t.executeCommand(Ao.id, {
- rule: o,
- unitId: o.unitId,
- subUnitId: o.subUnitId
- }), true;
- }
- };
- var vl = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-protection",
- async handler(n, e) {
- if (!e)
- return false;
- const t = n.get(Pt), o = n.get(cn), { rule: s, permissionId: r, oldRule: i } = e, { unitId: a, subUnitId: u } = s, l = { ...s, permissionId: r };
- if (await t.executeCommand(Ct2.id, {
- unitId: a,
- subUnitId: u,
- newRule: l
- })) {
- const d = [{ id: Ct2.id, params: { unitId: a, subUnitId: u, newRule: l } }], h = [{ id: Ct2.id, params: { unitId: a, subUnitId: u, rule: i } }];
- o.pushUndoRedo({
- unitID: a,
- redoMutations: d,
- undoMutations: h
- });
- }
- return true;
- }
- };
- var Ml = 2e3;
- var Hr = (n, e) => {
- const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager();
- for (const { startRow: a, endRow: u } of s)
- for (let l = a; l < u + 1; l++) {
- const c = i.getRowOrCreate(l);
- r[l] = c.h;
- }
- return {
- unitId: t,
- subUnitId: o,
- ranges: s,
- rowHeight: r
- };
- };
- var xo = (n, e) => {
- const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager();
- for (const { startRow: a, endRow: u } of s)
- for (let l = a; l <= u; l++) {
- const c = i.getRowOrCreate(l);
- r[l] = c.ia;
- }
- return {
- unitId: t,
- subUnitId: o,
- ranges: s,
- autoHeightInfo: r
- };
- };
- var ih = (n, e) => {
- const { unitId: t, subUnitId: o, rowsAutoHeightInfo: s } = n, r = [], i = e.getRowManager();
- for (const a of s) {
- const { row: u } = a, { ah: l } = i.getRowOrCreate(u);
- r.push({ row: u, autoHeight: l });
- }
- return {
- unitId: t,
- subUnitId: o,
- rowsAutoHeightInfo: r
- };
- };
- var nt2 = {
- id: "sheet.mutation.set-worksheet-row-height",
- type: ar.MUTATION,
- handler: (n, e) => {
- var l;
- const { ranges: t, rowHeight: o } = e, s = n.get(_n), r = N(s, e);
- if (!r)
- return false;
- const { worksheet: i } = r, a = i.getRowManager(), u = i.getConfig().defaultRowHeight;
- for (const { startRow: c, endRow: d } of t)
- for (let h = c; h <= d; h++) {
- const m = a.getRowOrCreate(h);
- typeof o == "number" ? m.h = o : m.h = (l = o[h]) != null ? l : u, m.h = Math.min(Ml, m.h);
- }
- return true;
- }
- };
- var Oe = {
- id: "sheet.mutation.set-worksheet-row-is-auto-height",
- type: ar.MUTATION,
- handler: (n, e) => {
- var a;
- const { ranges: t, autoHeightInfo: o } = e, s = n.get(_n), r = N(s, e);
- if (!r)
- return false;
- const i = r.worksheet.getRowManager();
- for (const { startRow: u, endRow: l } of t)
- for (let c = u; c <= l; c++) {
- const d = i.getRowOrCreate(c);
- typeof o == "number" ? d.ia = o : d.ia = (a = o[c]) != null ? a : void 0;
- }
- return true;
- }
- };
- var Br = {
- id: "sheet.mutation.set-worksheet-row-auto-height",
- type: ar.MUTATION,
- handler: (n, e) => {
- const { rowsAutoHeightInfo: t } = e, o = n.get(_n), s = N(o, e);
- if (!s)
- return false;
- const r = s.worksheet.getRowManager();
- for (const { row: i, autoHeight: a } of t) {
- const u = r.getRowOrCreate(i);
- u.ah = a;
- }
- return true;
- }
- };
- var $o = {
- type: ar.COMMAND,
- id: "sheet.command.delta-row-height",
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- var U, P;
- const o = n.get(F).getCurrentSelections(), s = n.get(V);
- if (!(o != null && o.length))
- return false;
- const r = N(n.get(_n));
- if (!r)
- return false;
- const { worksheet: i, subUnitId: a, unitId: u } = r, { anchorRow: l, deltaY: c } = e, h = i.getRowHeight(l) + c, m = o.length === 1 && o[0].range.rangeType === De.ALL, g2 = o.filter((A) => A.range.rangeType === De.ROW), f = m ? De.ALL : g2.some(({ range: A }) => {
- const { startRow: j, endRow: Z } = A;
- return j <= l && l <= Z;
- }) ? De.ROW : De.NORMAL;
- let p;
- if (f === De.ALL) {
- const A = i.getRowCount(), j = new Array(i.getColumnCount()).fill(void 0).map(
- (Z, Y) => ({ startRow: Y, endRow: Y, startColumn: 0, endColumn: A - 1 })
- );
- p = {
- subUnitId: a,
- unitId: u,
- rowHeight: h,
- ranges: j
- };
- } else
- f === De.ROW ? p = {
- subUnitId: a,
- unitId: u,
- ranges: g2.map((A) => en.clone(A.range)),
- rowHeight: h
- } : p = {
- subUnitId: a,
- unitId: u,
- rowHeight: h,
- ranges: [
- {
- startRow: l,
- endRow: l,
- startColumn: 0,
- endColumn: i.getMaxColumns() - 1
- }
- ]
- };
- const C = Hr(p, i), S = {
- unitId: u,
- subUnitId: a,
- ranges: p.ranges,
- autoHeightInfo: we.FALSE
- }, I = xo(S, i), w = n.get(Pt), b = n.get(cn), y = s.onCommandExecute({
- id: $o.id,
- params: p
- }), x = mu([
- {
- id: nt2.id,
- params: p
- },
- {
- id: Oe.id,
- params: S
- }
- ], w), T2 = mu([...y.redos], w);
- return x.result && T2.result ? (b.pushUndoRedo({
- unitID: u,
- undoMutations: [
- ...(U = y.preUndos) != null ? U : [],
- {
- id: nt2.id,
- params: C
- },
- {
- id: Oe.id,
- params: I
- },
- ...y.undos
- ],
- redoMutations: [
- ...(P = y.preRedos) != null ? P : [],
- {
- id: nt2.id,
- params: p
- },
- {
- id: Oe.id,
- params: S
- },
- ...y.redos
- ]
- }), true) : false;
- }
- };
- var Wo = {
- type: ar.COMMAND,
- id: "sheet.command.set-row-height",
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var I, w, b, y;
- const t = n.get(F), o = n.get(Pt), s = n.get(cn), r = n.get(_n), i = n.get(V), a = (I = e == null ? void 0 : e.ranges) != null && I.length ? e.ranges : (w = t.getCurrentSelections()) == null ? void 0 : w.map((x) => x.range);
- if (!(a != null && a.length))
- return false;
- const u = N(r, e);
- if (!u)
- return false;
- const { unitId: l, subUnitId: c, worksheet: d } = u, h = {
- subUnitId: c,
- unitId: l,
- ranges: a,
- rowHeight: e.value
- }, m = Hr(h, d), g2 = {
- unitId: l,
- subUnitId: c,
- ranges: h.ranges,
- autoHeightInfo: we.FALSE
- }, f = xo(g2, d), p = mu([
- {
- id: nt2.id,
- params: h
- },
- {
- id: Oe.id,
- params: g2
- }
- ], o), C = i.onCommandExecute({
- id: Wo.id,
- params: h
- }), S = mu([...C.redos], o);
- return p.result && S.result ? (s.pushUndoRedo({
- unitID: l,
- undoMutations: [
- ...(b = C.preRedos) != null ? b : [],
- {
- id: nt2.id,
- params: m
- },
- {
- id: Oe.id,
- params: f
- },
- ...C.undos
- ],
- redoMutations: [
- ...(y = C.preRedos) != null ? y : [],
- {
- id: nt2.id,
- params: h
- },
- {
- id: Oe.id,
- params: g2
- },
- ...C.redos
- ]
- }), true) : false;
- }
- };
- var Lo = {
- type: ar.COMMAND,
- id: "sheet.command.set-row-is-auto-height",
- handler: (n, e) => {
- var C, S;
- const t = n.get(Pt), o = n.get(cn), s = n.get(F), r = n.get(_n), i = N(r, e);
- if (!i)
- return false;
- const { unitId: a, subUnitId: u, worksheet: l } = i, c = (C = e == null ? void 0 : e.ranges) != null && C.length ? e.ranges : (S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range);
- if (!(c != null && c.length))
- return false;
- const d = {
- unitId: a,
- subUnitId: u,
- ranges: c,
- autoHeightInfo: we.TRUE
- // Hard code first, maybe it will change by the menu item in the future.
- }, h = xo(d, l), m = t.syncExecuteCommand(
- Oe.id,
- d
- ), { undos: g2, redos: f } = n.get(V).onCommandExecute({
- id: Lo.id,
- params: d
- }), p = mu([...f], t);
- return m && p.result ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Oe.id, params: h }, ...g2],
- redoMutations: [{ id: Oe.id, params: d }, ...f]
- }), true) : false;
- }
- };
- var Fr = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-show",
- handler: (n, e) => {
- const { unitId: t, subUnitId: o } = e, s = n.get(Pt), r = n.get(cn), i = n.get(_n);
- if (!N(n.get(_n)))
- return false;
- const u = i.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!u)
- return false;
- const l = u.getSheetBySheetId(o);
- if (!l || l.getConfig().hidden === we.FALSE)
- return false;
- const d = {
- unitId: t,
- subUnitId: o,
- hidden: we.FALSE
- }, h = $r(n, d), m = s.syncExecuteCommand(lt.id, d), g2 = {
- unitId: t,
- subUnitId: o
- }, f = s.syncExecuteCommand(
- an.id,
- g2
- );
- return m && f ? (r.pushUndoRedo({
- unitID: t,
- undoMutations: [
- { id: lt.id, params: h }
- // { id: SetWorksheetActiveOperation.id, params: unActiveMutationParams },
- ],
- redoMutations: [
- // { id: SetWorksheetActiveOperation.id, params: activeSheetMutationParams },
- { id: lt.id, params: d }
- ]
- }), true) : false;
- }
- };
- var _l = class {
- constructor() {
- R(this, "_tabCount", 0);
- R(this, "_commaCount", 0);
- R(this, "_semicolonCount", 0);
- R(this, "_spaceCount", 0);
- }
- add(e) {
- switch (e) {
- case " ":
- this._tabCount++;
- break;
- case ",":
- this._commaCount++;
- break;
- case ";":
- this._semicolonCount++;
- break;
- case " ":
- this._spaceCount++;
- break;
- }
- }
- update(e) {
- e && typeof e == "string" && (e.includes(" ") && this._tabCount++, e.includes(",") && this._commaCount++, e.includes(";") && this._semicolonCount++, e.trim().includes(" ") && this._spaceCount++);
- }
- getDelimiter() {
- const e = Math.max(this._tabCount, this._commaCount, this._semicolonCount, this._spaceCount);
- return e === 0 || e === this._tabCount ? 1 : e === this._commaCount ? 2 : e === this._semicolonCount ? 4 : e === this._spaceCount ? 8 : 1;
- }
- };
- function bl(n, e, t) {
- const o = [];
- t !== void 0 && (n & 16) > 0 && o.push(t), (n & 1) > 0 && o.push(" "), (n & 2) > 0 && o.push(","), (n & 4) > 0 && o.push(";"), (n & 8) > 0 && o.push(" ");
- let s = "";
- for (const i of o)
- s += yl(i);
- let r = "[".concat(s, "]");
- return e && (r += "+"), new RegExp(r);
- }
- function yl(n) {
- return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
- }
- var El = (n) => {
- var t;
- return ((t = n.body) == null ? void 0 : t.dataStream.replace(/\r\n$/, "")) || "";
- };
- function Ul(n) {
- if (n != null) {
- if (n.p)
- return El(n.p);
- if (n.v && typeof n.v == "string")
- return n.v;
- if (n.t && (n.t === dn.FORCE_STRING || n.t === dn.STRING))
- return String(n.v);
- }
- }
- function Pl(n, e, t, o, s = false) {
- const r = tr.transformRange(e, n), { startColumn: i, startRow: a, endColumn: u, endRow: l } = r;
- if (i !== u)
- throw new Error("The range must be in the same column.");
- if (t && (t & 16) > 0 && (o === void 0 || o.length !== 1))
- throw new Error("The custom delimiter must a character.");
- const c = t === void 0, d = c ? new _l() : null, h = [];
- for (let I = a; I <= l; I++) {
- const w = n.getCell(I, i), b = Ul(w);
- h.push(b), d && d.update(b);
- }
- const m = c ? d.getDelimiter() : t, g2 = bl(m, s, o);
- let f = -1, p = 0, C = 0;
- const S = [];
- for (const I of h) {
- if (I !== void 0) {
- const w = String(I).split(g2);
- f < 0 ? f = w.length : f = Math.max(f, w.length), S.push(w), p = C;
- } else
- S.push(void 0);
- C++;
- }
- return {
- rs: S,
- maxLength: f === -1 ? 0 : f,
- lastRow: p
- };
- }
- var Tl = {
- type: ar.COMMAND,
- id: "sheet.command.split-text-to-columns",
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, range: s, delimiter: r, customDelimiter: i, treatMultipleDelimitersAsOne: a } = e, u = n.get(Pt), l = n.get(_n), c = n.get(cn);
- if (!N(n.get(_n)))
- return false;
- const h = l.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!h)
- return false;
- const m = h.getSheetBySheetId(o);
- if (!m)
- return false;
- const { lastRow: g2, rs: f, maxLength: p } = Pl(m, s, r, i, a), C = m.getColumnCount(), { startColumn: S } = tr.transformRange(s, m);
- if (s.startColumn !== s.endColumn)
- return false;
- const I = [], w = [], b = S + p + 1 - C;
- if (b > 0) {
- const A = {
- unitId: t,
- subUnitId: o,
- range: {
- startRow: 0,
- endRow: m.getRowCount() - 1,
- startColumn: C - 1,
- endColumn: C - 1 + b
- }
- };
- I.push({
- id: je.id,
- params: A
- });
- const j = yo(
- n,
- A
- );
- w.push({ id: De2.id, params: j });
- }
- const y = {
- startRow: s.startRow,
- endRow: g2,
- startColumn: S,
- endColumn: S + p
- }, x = new kt();
- for (let A = y.startRow; A <= y.endRow; A++)
- for (let j = y.startColumn; j <= y.endColumn; j++) {
- const Z = f[A - y.startRow];
- j === 0 && (Z == null ? void 0 : Z.length) === 1 ? x.setValue(A, j, m.getCell(A, j)) : x.setValue(A, j, {
- v: (Z == null ? void 0 : Z[j - y.startColumn]) || null,
- p: null,
- f: null,
- si: null,
- custom: null
- });
- }
- const T2 = {
- unitId: t,
- subUnitId: o,
- cellValue: x.clone()
- }, U = Ae(n, T2);
- return I.push({
- id: Q.id,
- params: T2
- }), w.unshift({
- id: Q.id,
- params: U
- }), mu(I, u).result ? (c.pushUndoRedo({
- unitID: t,
- undoMutations: w,
- redoMutations: I
- }), true) : false;
- }
- };
- var kl = {
- id: "sheet.command.toggle-cell-checkbox",
- type: ar.COMMAND,
- handler: (n, e) => {
- if (!e)
- return false;
- const { unitId: t, subUnitId: o, row: s, col: r, paragraphIndex: i } = e, u = n.get(_n).getUnit(t, Fe.UNIVER_SHEET), l = u == null ? void 0 : u.getSheetBySheetId(o), c = n.get(cn), d = n.get(Pt);
- if (!l)
- return false;
- const h = l.getCell(s, r);
- if (!(h != null && h.p))
- return false;
- const m = re.deepClone(h.p), g2 = new jt(m), f = st.paragraph.bullet.toggleChecklist({
- document: g2,
- paragraphIndex: i
- });
- if (!f)
- return false;
- Ke.apply(g2.getBody(), f.serialize());
- const p = {
- unitId: t,
- subUnitId: o,
- cellValue: {
- [s]: {
- [r]: {
- p: m,
- t: dn.STRING
- }
- }
- }
- }, C = {
- id: Q.id,
- params: p
- }, S = Ae(n, p), I = {
- id: Q.id,
- params: S
- }, w = [C], b = [I];
- return c.pushUndoRedo({
- redoMutations: w,
- undoMutations: b,
- unitID: t
- }), d.syncExecuteCommand(C.id, C.params);
- }
- };
- var Ft = {
- id: "sheet.mutation.toggle-gridlines",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = N(n.get(_n), e);
- if (!t)
- return false;
- const { worksheet: o } = t, s = o.getConfig();
- return s.showGridlines = e.showGridlines, true;
- }
- };
- var Nl = {
- type: ar.COMMAND,
- id: "sheet.command.toggle-gridlines",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = N(s);
- if (!r)
- return false;
- const { worksheet: i } = r, a = i.getConfig().showGridlines;
- if (a === (e == null ? void 0 : e.showGridlines))
- return false;
- const { unitId: u, subUnitId: l } = r, c = {
- showGridlines: a === we.TRUE ? we.FALSE : we.TRUE,
- unitId: u,
- subUnitId: l
- }, d = {
- showGridlines: a,
- unitId: u,
- subUnitId: l
- };
- return t.syncExecuteCommand(Ft.id, c) ? (o.pushUndoRedo({
- unitID: u,
- undoMutations: [{ id: Ft.id, params: d }],
- redoMutations: [{ id: Ft.id, params: c }]
- }), true) : false;
- }
- };
- var Ol = {
- id: "sheet.command.unregister-worksheet-range-theme-style",
- type: ar.COMMAND,
- handler: (n, e) => {
- var h;
- if (!e)
- return false;
- const { unitId: t, themeName: o } = e, s = n.get(_n), r = n.get(Pt), i = n.get(cn), a = n.get(He);
- if (!N(s))
- return false;
- const l = {
- unitId: t,
- themeName: o
- }, c = {
- unitId: t,
- themeName: o,
- rangeThemeStyleJson: (h = a.getRangeThemeStyle(t, o)) == null ? void 0 : h.toJson()
- };
- return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({
- unitID: t,
- undoMutations: [{ id: Yt.id, params: c }],
- redoMutations: [{ id: Uo.id, params: l }]
- }), true;
- }
- };
- var Dl = {
- id: "sheet.mutation.empty",
- type: ar.MUTATION,
- handler: () => true
- };
- var Al = (n) => {
- const e = new kt();
- return n.forEach((t) => {
- tr.foreach(t, (o, s) => {
- e.setValue(o, s, 1);
- });
- }), e.forValue((t, o) => {
- const s = e.getValue(t - 1, o);
- s && e.setValue(t, o, s + 1);
- }), e;
- };
- var xl = (n) => {
- const e = n;
- return e.forValue((t, o) => {
- const s = n.getValue(t - 1, o);
- s && e.setValue(t, o, s + 1);
- }), e;
- };
- var Qo2 = (n) => {
- const e = {
- area: 0
- }, t = (o, s) => e.area < o ? (e.area = o, e.range = s, true) : false;
- return n.forValue((o, s, r) => {
- let i = 1, a = r;
- t(i * a, {
- startRow: o - a + 1,
- endRow: o,
- startColumn: s,
- endColumn: s
- });
- const u = {
- startRow: o - a + 1,
- endRow: o,
- startColumn: 0,
- endColumn: s
- };
- for (let l = s - 1; l >= 0 && n.getValue(o, l); l--) {
- a = Math.min(n.getValue(o, l) || 0, a), i++;
- const c = a * i;
- u.startColumn = l, u.startRow = o - a + 1, t(c, u);
- }
- }), e;
- };
- var $l = (n, e) => {
- tr.foreach(e, (t, o) => {
- n.realDeleteValue(t, o);
- });
- for (let t = e.startColumn; t <= e.endColumn; t++) {
- const o = e.endRow + 1;
- if (n.getValue(o, t) > 0) {
- n.setValue(o, t, 1);
- let r = o + 1;
- for (; n.getValue(r, t) > 0; )
- n.setValue(r, t, n.getValue(r - 1, t) + 1), r++;
- }
- }
- return n;
- };
- var jr = (n) => {
- const e = [];
- let t = Qo2(n);
- for (; t.area > 0; )
- t.range && (e.push(t.range), $l(n, t.range)), t = Qo2(n);
- return e;
- };
- var Gr = (n) => {
- const e = Al(n);
- return jr(e);
- };
- var ah = class {
- constructor() {
- R(this, "_matrix", new kt());
- }
- add(...e) {
- return e.forEach((t) => {
- tr.foreach(t, (o, s) => {
- this._matrix.setValue(o, s, 1);
- });
- }), this;
- }
- subtract(...e) {
- return e.forEach((t) => {
- tr.foreach(t, (o, s) => {
- this._matrix.realDeleteValue(o, s);
- });
- }), this;
- }
- merge() {
- const e = xl(this._matrix);
- return jr(e);
- }
- };
- var wt = Ct("INumfmtService");
- var uh = (n, e) => {
- const t = n.get(wt), { values: o, unitId: s, subUnitId: r } = e, i = [], a = [];
- Object.keys(o).forEach((l) => {
- o[l].ranges.forEach((d) => {
- tr.foreach(d, (h, m) => {
- const g2 = t.getValue(s, r, h, m);
- g2 ? i.push({
- pattern: g2.pattern,
- row: h,
- col: m
- }) : a.push({ startColumn: m, endColumn: m, startRow: h, endRow: h });
- });
- });
- });
- const u = [];
- if (i.length) {
- const l = lo(s, r, i);
- Object.keys(l.values).forEach((c) => {
- const d = l.values[c];
- d.ranges = Gr(d.ranges);
- }), u.push({
- id: Vo2.id,
- params: lo(s, r, i)
- });
- }
- return a.length && u.push({
- id: zr.id,
- params: {
- unitId: s,
- subUnitId: r,
- ranges: a
- }
- }), u;
- };
- var Vo2 = {
- id: "sheet.mutation.set.numfmt",
- type: ar.MUTATION,
- handler: (n, e) => {
- if (!e)
- return false;
- const { values: t, refMap: o } = e, s = n.get(wt), r = e.unitId, i = e.subUnitId, a = Object.keys(t).reduce(
- (u, l) => {
- const c = o[l], d = t[l].ranges;
- return c && u.push({
- ...c,
- ranges: d
- }), u;
- },
- []
- );
- return s.setValues(r, i, a), true;
- }
- };
- var zr = {
- id: "sheet.mutation.remove.numfmt",
- type: ar.MUTATION,
- handler: (n, e) => {
- if (!e)
- return false;
- const { unitId: t, subUnitId: o, ranges: s } = e;
- return n.get(wt).deleteValues(t, o, s), true;
- }
- };
- var lh = (n, e) => {
- const t = n.get(wt), { ranges: o, unitId: s, subUnitId: r } = e, i = [];
- if (o.forEach((u) => {
- tr.foreach(u, (l, c) => {
- const d = t.getValue(s, r, l, c);
- d && i.push({
- pattern: d.pattern,
- row: l,
- col: c
- });
- });
- }), !i.length)
- return [];
- const a = lo(s, r, i);
- return Object.keys(a.values).forEach((u) => {
- const l = a.values[u];
- l.ranges = Gr(l.ranges);
- }), [{ id: Vo2.id, params: a }];
- };
- var lo = (n, e, t) => {
- const o = ya(t, "pattern"), s = {}, r = {}, i = Ea();
- return Object.keys(o).forEach((a) => {
- const u = o[a], l = i();
- s[l] = {
- pattern: a
- }, u.forEach((c) => {
- r[l] || (r[l] = { ranges: [] }), r[l].ranges.push(AC(c.row, c.col));
- });
- }), { unitId: n, subUnitId: e, refMap: s, values: r };
- };
- var Wl = {
- id: "sheet.operation.scroll-to-cell",
- type: ar.OPERATION,
- handler: () => true
- };
- var Kr = "ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY";
- var Ll = "maxCellsPerSheet";
- var Vl = 3e6;
- var Hl = Object.defineProperty;
- var Bl = Object.getOwnPropertyDescriptor;
- var Fl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Bl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Hl(e, t, s), s;
- };
- var to = (n, e) => (t, o) => e(t, o, n);
- var yn = class extends nt {
- // eslint-disable-next-line max-lines-per-function
- constructor(n, e, t) {
- var s;
- super(), this._commandService = n, this._configService = e, this._dataSyncPrimaryController = t, [
- Q,
- je,
- qe,
- Jt,
- dt,
- ot2,
- st2,
- De2,
- Be,
- Ut,
- oe,
- zr,
- ne,
- Or,
- _n2,
- Vo2,
- In,
- Dl,
- Qt,
- // formula SUBTOTAL
- Zt,
- Xt2,
- qt2
- ].forEach((r) => {
- var i;
- this._commandService.registerCommand(r), (i = this._dataSyncPrimaryController) == null || i.registerSyncingMutations(r);
- }), ((s = this._configService.getConfig(Kr)) != null ? s : false) || [
- po,
- Co,
- So,
- xs,
- Pt2,
- Tt,
- Oo,
- $o,
- gu,
- mu2,
- pr2,
- gt,
- sn,
- Bn,
- hu,
- du,
- fr,
- mt,
- fu,
- jn,
- pt,
- Fn,
- vr,
- zn2,
- Mr,
- Gn,
- ko,
- uo,
- Iu,
- tl,
- Qu,
- el,
- Ou,
- Nu,
- rn,
- Tu,
- ku,
- yr,
- Mn,
- $u,
- Lt,
- Bu,
- ut,
- Fu,
- ol,
- on,
- Wo,
- kr,
- Ku,
- Ht,
- br,
- Tr,
- Kn,
- Jn,
- fe,
- al,
- fn3,
- Zu,
- rl,
- sl,
- nl,
- Dr,
- Ar,
- an,
- hl,
- lt,
- Do,
- Wr,
- Rn,
- Br,
- nt2,
- Lo,
- Oe,
- tt,
- // SetWorksheetColIsAutoWidthCommand,
- re2,
- Wl,
- au,
- Ir,
- Ur,
- Fr,
- Nl,
- Ft,
- ju,
- Vt,
- // permissions range protection
- Il,
- ct,
- Ct2,
- St,
- Ao,
- Xi2,
- Gu,
- su,
- qi,
- ru,
- vl,
- Ne,
- ze,
- he,
- kl,
- Bt,
- dl,
- Tl,
- // range theme
- Kt,
- zt,
- Uo,
- Yt,
- Ol,
- wu2,
- ba,
- iu
- ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r))), this._configService.setConfig(Ll, Vl);
- }
- };
- yn = Fl([
- to(0, Pt),
- to(1, SE),
- to(2, nf(g))
- ], yn);
- var jl = Object.defineProperty;
- var Gl = Object.getOwnPropertyDescriptor;
- var zl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Gl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && jl(e, t, s), s;
- };
- var es = (n, e) => (t, o) => e(t, o, n);
- var En = class extends nt {
- constructor(n, e) {
- super(), this._univerInstanceService = n, this._commandService = e, this._initialize();
- }
- _initialize() {
- this.disposeWithMe(
- this._commandService.onCommandExecuted((n) => {
- if (n.id !== Ji.id)
- return;
- const e = n.params, { unitData: t } = e, o = Object.keys(t), s = [];
- for (let i = 0; i < o.length; i++) {
- const a = o[i], u = t[a];
- if (u == null)
- continue;
- const l = Object.keys(u);
- for (let c = 0; c < l.length; c++) {
- const d = l[c], h = u[d];
- if (h == null)
- continue;
- const m = this._getMergedCellData(a, d, h), g2 = {
- subUnitId: d,
- unitId: a,
- cellValue: m
- };
- s.push({
- id: Q.id,
- params: g2
- });
- }
- }
- return s.every(
- (i) => this._commandService.executeCommand(i.id, i.params, {
- onlyLocal: true
- })
- );
- })
- );
- }
- /**
- * Priority that mainly deals with number format in unitData
- * @param unitId
- * @param sheetId
- * @param cellData
- * @returns
- */
- _getMergedCellData(n, e, t) {
- const o = this._univerInstanceService.getUniverSheetInstance(n), s = o == null ? void 0 : o.getStyles(), r = o == null ? void 0 : o.getSheetBySheetId(e), i = r == null ? void 0 : r.getCellMatrix(), a = new kt(t);
- return a.forValue((u, l, c) => {
- const d = i == null ? void 0 : i.getValue(u, l), h = Gb(d, c, s);
- a.setValue(u, l, h);
- }), a.getMatrix();
- }
- };
- En = zl([
- es(0, ot(_n)),
- es(1, Pt)
- ], En);
- var Kl = "sheets.config";
- var ts = {};
- var Jl = Object.defineProperty;
- var Yl = Object.getOwnPropertyDescriptor;
- var Xl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Yl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Jl(e, t, s), s;
- };
- var ns = (n, e) => (t, o) => e(t, o, n);
- var ql = "SHEET_DEFINED_NAME_PLUGIN";
- var ch = "AllDefaultWorkbook";
- var Un = class extends nt {
- constructor(n, e) {
- super(), this._definedNamesService = n, this._resourceManagerService = e, this._initialize();
- }
- _initialize() {
- this._initSnapshot();
- }
- _initSnapshot() {
- const n = (t) => {
- const o = this._definedNamesService.getDefinedNameMap(t);
- return o ? JSON.stringify(o) : "";
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- pluginName: ql,
- businesses: [Fe.UNIVER_SHEET],
- toJson: (t) => n(t),
- parseJson: (t) => e(t),
- onUnLoad: (t) => {
- this._definedNamesService.removeUnitDefinedName(t);
- },
- onLoad: (t, o) => {
- this._definedNamesService.registerDefinedNames(t, o);
- }
- })
- );
- }
- };
- Un = Xl([
- ns(0, pr),
- ns(1, Bi)
- ], Un);
- var $ = {
- MoveRangeCommandId: $s,
- InsertRowCommandId: gr,
- InsertColCommandId: Rr,
- RemoveColCommandId: To,
- RemoveRowCommandId: Po,
- DeleteRangeMoveLeftCommandId: dr,
- DeleteRangeMoveUpCommandId: hr,
- InsertRangeMoveDownCommandId: cu,
- InsertRangeMoveRightCommandId: Eo,
- MoveColsCommandId: Sr,
- MoveRowsCommandId: Cr,
- ReorderRangeCommandId: _r
- };
- var q = ((n) => (n[n.Set = 0] = "Set", n[n.Delete = 1] = "Delete", n[n.HorizontalMove = 2] = "HorizontalMove", n[n.VerticalMove = 3] = "VerticalMove", n[n.Unknown = 4] = "Unknown", n))(q || {});
- var cn2 = Number.MAX_SAFE_INTEGER;
- var Ve = (n) => {
- const e = { ...n }, t = Number.isNaN(e.startRow) && Number.isNaN(e.endRow) && !Number.isNaN(e.startColumn) && !Number.isNaN(e.endColumn), o = Number.isNaN(e.startColumn) && Number.isNaN(e.endColumn) && !Number.isNaN(e.startRow) && !Number.isNaN(e.endRow);
- return (e.rangeType === De.COLUMN || t) && (e.startRow = 0, e.endRow = cn2), (e.rangeType === De.ROW || o) && (e.startColumn = 0, e.endColumn = cn2), e.rangeType === De.ALL && (e.startColumn = 0, e.endColumn = cn2, e.startRow = 0, e.endRow = cn2), e;
- };
- var _e = (n) => {
- let e = n.rangeType;
- return n.rangeType === De.COLUMN ? e = De.ROW : n.rangeType === De.ROW && (e = De.COLUMN), {
- startRow: n.startColumn,
- endRow: n.endColumn,
- startColumn: n.startRow,
- endColumn: n.endRow,
- rangeType: e
- };
- };
- var Pn = (n, e, t) => {
- const o = { ...t }, s = { ...e }, r = (f, p) => {
- const C = Math.max(f.start, p.start), S = Math.min(f.end, p.end);
- return S < C ? null : { start: C, end: S };
- }, i = (f) => f.end - f.start + 1, a = (f, p) => ({
- start: f.start - p.start,
- end: f.start - p.start + f.end - f.start
- }), u = (f, p) => ({
- start: p.start + f.start,
- end: p.start + f.start + f.end - f.start
- }), l = e.start > n.start;
- if (l) {
- const f = Math.min(n.end, e.start) - n.start + 1;
- s.start -= f, s.end -= f;
- }
- const c = i(n), d = c, h = r(n, o), m = h && i(h) >= i(o);
- if (n.end < o.start)
- o.start -= c, o.end -= c;
- else if (h) {
- const f = i(h);
- if (m) {
- const p = a(o, n), C = u(p, s);
- o.start = C.start, o.end = C.end;
- } else
- h.start > n.start ? l ? (o.end -= f + c, o.start -= c) : o.end -= f : l ? o.end -= f : o.start > n.start && o.end > n.end ? (o.start -= c, o.end -= c + f) : o.end -= f;
- }
- const g2 = r(s, o);
- return m || (s.start <= o.start ? (o.start += d, o.end += d) : g2 && (l ? s.end <= o.start || s.start <= o.start && s.end >= o.start ? (o.start += d, o.end += d) : s.start >= o.start && s.start <= o.end && (o.end += d) : o.start < s.start && o.end > s.start ? o.end += d : (o.start >= s.end || o.start >= s.start && o.start <= s.end) && (o.end += d, o.start += d))), {
- step: o.start - t.start,
- length: i(o) - i(t)
- };
- };
- var Jr = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!o || !t)
- return [];
- const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn(
- { start: s.startRow, end: s.endRow },
- { start: r.startRow, end: r.endRow },
- { start: i.startRow, end: i.endRow }
- );
- return a === null ? [
- {
- type: q.Delete
- }
- ] : [
- {
- type: q.VerticalMove,
- step: a.step || 0,
- length: a.length || 0
- }
- ];
- };
- var Zl = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!t || !o)
- return [e];
- const s = t.startRow, r = t.endRow - t.startRow + 1, i = o.startRow, a = new kt();
- return tr.foreach(e, (l, c) => {
- a.setValue(l, c, 1);
- }), a.moveRows(s, r, i), WC(a, (l) => l === 1);
- };
- var Ql = (n, e) => {
- const { range: t, order: o } = n.params || {};
- if (!t || !o)
- return [e];
- const s = new kt();
- tr.foreach(e, (a, u) => {
- s.setValue(a, u, 1);
- });
- const r = new kt();
- return tr.foreach(t, (a, u) => {
- var l;
- if (o.hasOwnProperty(a)) {
- const c = o[a], d = (l = s.getValue(c, u)) != null ? l : 0;
- r.setValue(a, u, d);
- }
- }), r.forValue((a, u, l) => {
- s.setValue(a, u, l);
- }), WC(s, (a) => a === 1);
- };
- var Yr = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!o || !t)
- return [];
- const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn(
- { start: s.startColumn, end: s.endColumn },
- { start: r.startColumn, end: r.endColumn },
- { start: i.startColumn, end: i.endColumn }
- );
- return a === null ? [
- {
- type: q.Delete
- }
- ] : [
- {
- type: q.HorizontalMove,
- step: a.step || 0,
- length: a.length || 0
- }
- ];
- };
- var ec = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!t || !o)
- return [e];
- const s = t.startColumn, r = t.endColumn - t.startColumn + 1, i = o.startColumn, a = new kt();
- return tr.foreach(e, (u, l) => {
- a.setValue(u, l, 1);
- }), a.moveColumns(s, r, i), WC(a, (u) => u === 1);
- };
- var tc = (n, e) => {
- var r, i;
- const t = (r = n.params) == null ? void 0 : r.toRange, o = (i = n.params) == null ? void 0 : i.fromRange;
- if (!t || !o)
- return [];
- const s = [];
- if (en.contains(t, e) && s.push({
- type: q.Delete
- }), en.contains(o, e)) {
- s.push({
- type: q.Delete
- });
- const a = en.getRelativeRange(e, o), u = en.getPositionRange(a, t);
- return [
- {
- type: q.Set,
- range: u
- }
- ];
- }
- return s;
- };
- var nc = (n, e) => {
- var d, h;
- const t = (d = n.params) == null ? void 0 : d.toRange, o = (h = n.params) == null ? void 0 : h.fromRange;
- if (!t || !o)
- return [e];
- if (!en.intersects(o, e) && !en.intersects(t, e))
- return [e];
- if (en.contains(o, e)) {
- const m = en.getRelativeRange(e, o);
- return [en.getPositionRange(m, t)];
- }
- const s = new kt();
- tr.foreach(e, (m, g2) => {
- s.setValue(m, g2, 1);
- });
- const r = new kt(), i = en.getIntersects(o, e);
- i && tr.foreach(i, (m, g2) => {
- s.getValue(m, g2) && (s.setValue(m, g2, void 0), r.setValue(m, g2, 1));
- });
- const a = t.startColumn - o.startColumn, u = t.startRow - o.startRow, l = {
- startColumn: t.startColumn - a,
- endColumn: t.endColumn - a,
- startRow: t.startRow - u,
- endRow: t.endRow - u
- };
- return tr.foreach(l, (m, g2) => {
- var C;
- const f = m + u, p = g2 + a;
- s.setValue(f, p, (C = r.getValue(m, g2)) != null ? C : 0);
- }), WC(s, (m) => m === 1);
- };
- var It = (n, e) => {
- const t = Ve(n), o = Ve(e), s = (i) => i.endColumn - i.startColumn + 1, r = (i) => i.endRow - i.startRow + 1;
- if (t.startRow <= o.startRow && t.endRow >= o.endRow) {
- if (
- // 2
- o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6
- o.startColumn < t.startColumn && o.endColumn >= t.endColumn
- ) {
- const i = en.getIntersects(o, t);
- if (i)
- return { step: 0, length: -s(i) };
- }
- if (o.startColumn >= t.startColumn && o.endColumn <= t.endColumn && r(t) >= r(o))
- return null;
- if (o.startColumn >= t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn) {
- const i = en.getIntersects(o, t);
- if (i) {
- const a = -s(i);
- return { step: -(s(t) - s(i)), length: a };
- }
- }
- if (o.startColumn > t.endColumn)
- return { step: -s(t), length: 0 };
- }
- return { step: 0, length: 0 };
- };
- var Xr = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(t, e);
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.HorizontalMove,
- step: i,
- length: a
- });
- }
- return o;
- };
- var oc = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(_e(t), _e(e));
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.VerticalMove,
- step: i,
- length: a
- });
- }
- return o;
- };
- var sc = (n, e) => {
- const { range: t, order: o } = n.params || {};
- if (!t || !o)
- return [];
- if (en.contains(t, e) && e.endRow === e.startRow) {
- const s = [], r = e.startRow;
- for (const i in o)
- if (o[i] === r) {
- const a = Number(i);
- return s.push({
- type: q.VerticalMove,
- step: a - r,
- length: 0
- }), s;
- }
- return [];
- }
- return [];
- };
- var vt = (n, e) => {
- const t = Ve(n), o = Ve(e), s = (r) => r.endColumn - r.startColumn + 1;
- if (t.startRow <= o.startRow && t.endRow >= o.endRow) {
- if (
- // 2
- o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6
- o.startColumn < t.startColumn && o.endColumn >= t.endColumn
- )
- return { step: 0, length: s(t) };
- if (
- // 3
- o.startColumn >= t.startColumn && o.endColumn <= t.endColumn || // 4
- o.startColumn > t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn || //5
- o.startColumn >= t.endColumn
- )
- return { step: s(t), length: 0 };
- }
- return { step: 0, length: 0 };
- };
- function rc(n, e, t) {
- const o = [];
- if (en.contains(e, t) && o.push({
- type: q.Delete
- }), en.contains(n, t)) {
- o.push({
- type: q.Delete
- });
- const s = en.getRelativeRange(t, n), r = en.getPositionRange(s, e);
- return [
- {
- type: q.Set,
- range: r
- }
- ];
- }
- return o;
- }
- var ic = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s;
- return o.push({
- type: q.VerticalMove,
- step: r,
- length: i
- }), o;
- };
- var ac = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(t, e), { step: r, length: i } = s;
- return o.push({
- type: q.HorizontalMove,
- step: r,
- length: i
- }), o;
- };
- var uc = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s;
- return o.push({
- type: q.VerticalMove,
- step: r,
- length: i
- }), o;
- };
- var lc = (n, e) => {
- var u;
- const t = (u = n.params) == null ? void 0 : u.range;
- if (!t)
- return [e];
- const o = t.endRow - t.startRow + 1, s = {
- ...t,
- startRow: t.startRow,
- endRow: Number.POSITIVE_INFINITY
- }, r = en.subtract(e, s), i = en.getIntersects(s, e);
- if (!i)
- return [e];
- const a = new kt();
- return r.forEach((l) => {
- tr.foreach(l, (c, d) => {
- a.setValue(c, d, 1);
- });
- }), i && tr.foreach(i, (l, c) => {
- a.setValue(l + o, c, 1);
- }), WC(a, (l) => l === 1);
- };
- var cc = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(t, e), { step: r, length: i } = s;
- return o.push({
- type: q.HorizontalMove,
- step: r,
- length: i
- }), o;
- };
- var dc = (n, e) => {
- var u;
- const t = (u = n.params) == null ? void 0 : u.range;
- if (!t)
- return [e];
- const o = t.endColumn - t.startColumn + 1, s = {
- ...t,
- startColumn: t.startColumn,
- endColumn: Number.POSITIVE_INFINITY
- }, r = en.subtract(e, s), i = en.getIntersects(s, e);
- if (!i)
- return [e];
- const a = new kt();
- return r.forEach((l) => {
- tr.foreach(l, (c, d) => {
- a.setValue(c, d, 1);
- });
- }), i && tr.foreach(i, (l, c) => {
- a.setValue(l, c + o, 1);
- }), WC(a, (l) => l === 1);
- };
- var hc = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(t, e);
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.HorizontalMove,
- step: i,
- length: a
- });
- }
- return o;
- };
- var mc = (n, e) => {
- var l;
- const t = (l = n.params) == null ? void 0 : l.range;
- if (!t)
- return [e];
- const o = {
- startRow: t.startRow,
- endRow: t.endRow,
- startColumn: t.startColumn,
- endColumn: Number.POSITIVE_INFINITY
- }, s = t.endColumn - t.startColumn + 1, r = en.getIntersects(t, e), i = en.subtract(e, o), a = en.getIntersects(o, e);
- if (!r && !a)
- return [e];
- const u = new kt();
- return a && tr.foreach(a, (c, d) => {
- u.setValue(c, d - s, 1);
- }), r && tr.foreach(r, (c, d) => {
- u.setValue(c, d - s, 0);
- }), i.forEach((c) => {
- tr.foreach(c, (d, h) => {
- u.setValue(d, h, 1);
- });
- }), WC(u, (c) => c === 1);
- };
- var gc = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(_e(t), _e(e));
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.VerticalMove,
- step: i,
- length: a
- });
- }
- return o;
- };
- var fc = (n, e) => {
- var l;
- const t = (l = n.params) == null ? void 0 : l.range;
- if (!t)
- return [e];
- const o = {
- ...t,
- startRow: t.startRow,
- endRow: Number.POSITIVE_INFINITY
- }, s = t.endRow - t.startRow + 1, r = en.getIntersects(t, e), i = en.subtract(e, o), a = en.getIntersects(o, e);
- if (!r && !a)
- return [e];
- const u = new kt();
- return a && tr.foreach(a, (c, d) => {
- u.setValue(c - s, d, 1);
- }), r && tr.foreach(r, (c, d) => {
- u.setValue(c - s, d, 0);
- }), i.forEach((c) => {
- tr.foreach(c, (d, h) => {
- u.setValue(d, h, 1);
- });
- }), WC(u, (c) => c === 1);
- };
- var Rc = (n, e) => {
- var s;
- const t = (s = n.ranges) != null ? s : [n.range], o = new kt();
- return tr.foreach(e, (r, i) => {
- o.setValue(r, i, 1);
- }), t.forEach((r) => {
- const i = r.startRow, u = r.endRow - i + 1;
- o.removeRows(i, u);
- }), WC(o, (r) => r === 1);
- };
- var pc = (n, e) => {
- const t = n.params, o = t.range.startRow, s = t.range.endRow - t.range.startRow + 1, r = t.direction;
- return r === wu.UP && o === e.startRow || r === wu.DOWN && o - 1 === e.endRow ? [
- {
- startRow: e.startRow,
- endRow: e.endRow + s,
- startColumn: e.startColumn,
- endColumn: e.endColumn
- }
- ] : e.startRow >= o ? [{
- startRow: e.startRow + s,
- endRow: e.endRow + s,
- startColumn: e.startColumn,
- endColumn: e.endColumn
- }] : e.endRow <= o ? [e] : [{
- startRow: e.startRow,
- endRow: e.endRow + s,
- startColumn: e.startColumn,
- endColumn: e.endColumn
- }];
- };
- var Cc = (n, e) => {
- const t = n.params, o = t.range.startColumn, s = t.range.endColumn - t.range.startColumn + 1, r = t.direction;
- return r === wu.LEFT && o === e.startColumn || r === wu.RIGHT && o - 1 === e.endColumn ? [
- {
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: e.startColumn,
- endColumn: e.endColumn + s
- }
- ] : e.startColumn >= o ? [{
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: e.startColumn + s,
- endColumn: e.endColumn + s
- }] : e.endColumn <= o ? [e] : [{
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: e.startColumn,
- endColumn: e.endColumn + s
- }];
- };
- var Mt2 = (n, e) => {
- let t = { ...e };
- return n.forEach((o) => {
- switch (o.type) {
- case q.Delete: {
- t = null;
- break;
- }
- case q.HorizontalMove: {
- if (!t)
- return;
- t.startColumn += o.step, t.endColumn += o.step + (o.length || 0);
- break;
- }
- case q.VerticalMove: {
- if (!t)
- return;
- t.startRow += o.step, t.endRow += o.step + (o.length || 0);
- break;
- }
- case q.Set: {
- t = o.range;
- break;
- }
- }
- }), t && (t.endColumn < t.startColumn || t.endRow < t.startRow) ? null : t;
- };
- var os = (n, e) => {
- let t = [];
- switch (e.id) {
- case $.DeleteRangeMoveLeftCommandId: {
- t = hc(e, n);
- break;
- }
- case $.DeleteRangeMoveUpCommandId: {
- t = gc(e, n);
- break;
- }
- case $.InsertColCommandId: {
- t = ac(e, n);
- break;
- }
- case $.InsertRangeMoveDownCommandId: {
- t = uc(e, n);
- break;
- }
- case $.InsertRangeMoveRightCommandId: {
- t = cc(e, n);
- break;
- }
- case $.InsertRowCommandId: {
- t = ic(e, n);
- break;
- }
- case $.MoveColsCommandId: {
- t = Yr(e, n);
- break;
- }
- case $.MoveRangeCommandId: {
- t = tc(e, n);
- break;
- }
- case $.MoveRowsCommandId: {
- t = Jr(e, n);
- break;
- }
- case $.RemoveColCommandId: {
- t = Xr(e, n);
- break;
- }
- case $.RemoveRowCommandId: {
- t = oc(e, n);
- break;
- }
- case $.ReorderRangeCommandId: {
- t = sc(e, n);
- break;
- }
- }
- return Mt2(t, n);
- };
- var dh = (n, e, t) => [Pt2.id, Tt.id].includes(e.id) || qr(e, t).some((r) => en.intersects(r, n)) ? os(n, e) : n;
- var ss = (n, e) => {
- let t = [];
- switch (e.id) {
- case $.DeleteRangeMoveLeftCommandId:
- return mc(e, n);
- case $.DeleteRangeMoveUpCommandId:
- return fc(e, n);
- case $.InsertRangeMoveDownCommandId:
- return lc(e, n);
- case $.InsertRangeMoveRightCommandId:
- return dc(e, n);
- case $.InsertColCommandId:
- return Cc(e, n);
- case $.InsertRowCommandId:
- return pc(e, n);
- case $.MoveColsCommandId:
- return ec(e, n);
- case $.MoveRangeCommandId:
- return nc(e, n);
- case $.MoveRowsCommandId:
- return Zl(e, n);
- case $.ReorderRangeCommandId:
- return Ql(e, n);
- case $.RemoveColCommandId: {
- t = Xr(e, n);
- break;
- }
- case $.RemoveRowCommandId:
- return Rc(e.params, n);
- }
- const o = Mt2(t, n);
- return o ? [o] : [];
- };
- var hh = (n, e, t) => [Pt2.id, Tt.id, sn.id, Eo].includes(e.id) || qr(e, t).some((r) => en.intersects(r, n)) ? ss(n, e) : n;
- function Sc(n, e) {
- const { id: t, params: o } = e;
- let s = {
- length: 0,
- step: 0,
- type: q.Unknown
- };
- switch (t) {
- case Ut.id:
- s.type = q.Delete;
- break;
- case ot2.id:
- s = Pn(
- { start: o.sourceRange.startRow, end: o.sourceRange.endRow },
- { start: o.targetRange.startRow, end: o.targetRange.endRow },
- { start: n.startRow, end: n.endRow }
- ), s.type = q.VerticalMove;
- break;
- case st2.id:
- s = Pn(
- { start: o.sourceRange.startColumn, end: o.sourceRange.endColumn },
- { start: o.targetRange.startColumn, end: o.targetRange.endColumn },
- { start: n.startColumn, end: n.endColumn }
- ), s.type = q.HorizontalMove;
- break;
- case De2.id:
- s = It(o.range, n), s ? s.type = q.HorizontalMove : s = { step: 0, length: 0, type: q.Delete };
- break;
- case Be.id:
- s = It(_e(o.range), _e(n)), s ? s.type = q.VerticalMove : s = { step: 0, length: 0, type: q.Delete };
- break;
- case qe.id:
- s = vt(_e(o.range), _e(n)), s.type = q.VerticalMove;
- break;
- case je.id:
- s = vt(o.range, n), s.type = q.HorizontalMove;
- break;
- case dt.id:
- {
- const r = o.fromRange || new kt(o.from).getRange(), i = o.toRange || new kt(o.to).getRange();
- s = rc(
- r,
- i,
- n
- );
- }
- break;
- }
- return s ? Array.isArray(s) ? Mt2(s, n) : Mt2([s], n) : n;
- }
- function qr(n, e) {
- var o, s, r, i, a, u;
- const { selectionManagerService: t } = e;
- switch (n.id) {
- case $.MoveColsCommandId: {
- const l = n.params;
- return [
- l.fromRange,
- {
- ...l.toRange,
- startColumn: l.toRange.startColumn - 0.5,
- endColumn: l.toRange.endColumn - 0.5
- }
- ];
- }
- case $.MoveRowsCommandId: {
- const l = n.params;
- return [
- l.fromRange,
- {
- ...l.toRange,
- startRow: l.toRange.startRow - 0.5,
- endRow: l.toRange.startRow - 0.5
- }
- ];
- }
- case $.MoveRangeCommandId: {
- const l = n;
- return [l.params.fromRange, l.params.toRange];
- }
- case $.InsertRowCommandId: {
- const c = n.params.range;
- return [
- {
- ...c,
- startRow: c.startRow - 0.5,
- endRow: c.endRow - 0.5
- }
- ];
- }
- case $.InsertColCommandId: {
- const c = n.params.range;
- return [
- {
- ...c,
- startColumn: c.startColumn - 0.5,
- endColumn: c.endColumn - 0.5
- }
- ];
- }
- case $.RemoveRowCommandId:
- return [n.params.range];
- case $.RemoveColCommandId:
- return [n.params.range];
- case $.DeleteRangeMoveUpCommandId:
- case $.InsertRangeMoveDownCommandId: {
- const c = ((o = n.params) == null ? void 0 : o.range) || ((r = (s = t.getCurrentSelections()) == null ? void 0 : s.map((d) => d.range)) == null ? void 0 : r[0]);
- return c ? [c] : [];
- }
- case $.DeleteRangeMoveLeftCommandId:
- case $.InsertRangeMoveRightCommandId: {
- const c = ((i = n.params) == null ? void 0 : i.range) || ((u = (a = t.getCurrentSelections()) == null ? void 0 : a.map((d) => d.range)) == null ? void 0 : u[0]);
- return c ? [c] : [];
- }
- case $.ReorderRangeCommandId: {
- const l = n, { range: c, order: d } = l.params, h = [];
- for (let m = c.startRow; m <= c.endRow; m++)
- m in d && h.push({
- startRow: m,
- endRow: m,
- startColumn: c.startColumn,
- endColumn: c.endColumn
- });
- return h;
- }
- }
- }
- function wc(n) {
- switch (n.id) {
- case st2.id: {
- const e = n.params;
- return [
- e.sourceRange,
- {
- ...e.targetRange,
- startColumn: e.targetRange.startColumn - 0.5,
- endColumn: e.targetRange.startColumn - 0.5
- }
- ];
- }
- case ot2.id: {
- const e = n.params;
- return [
- e.sourceRange,
- {
- ...e.targetRange,
- startRow: e.targetRange.startRow - 0.5,
- endRow: e.targetRange.startRow - 0.5
- }
- ];
- }
- case dt.id: {
- const e = n.params;
- return [new kt(e.from.value).getRange(), new kt(e.to.value).getRange()];
- }
- case je.id: {
- const t = n.params.range;
- return [
- {
- ...t,
- startColumn: t.startColumn - 0.5,
- endColumn: t.startColumn - 0.5
- }
- ];
- }
- case qe.id: {
- const t = n.params.range;
- return [
- {
- ...t,
- startRow: t.startRow - 0.5,
- endRow: t.startRow - 0.5
- }
- ];
- }
- case De2.id:
- return [n.params.range];
- case Be.id:
- return [n.params.range];
- }
- }
- function mh(n, e) {
- var s, r, i, a, u, l;
- const t = n.get(_n), o = n.get(F);
- switch (e.id) {
- case $.MoveColsCommandId: {
- const c = e.params, d = N(t, {
- unitId: c.unitId,
- subUnitId: c.subUnitId
- });
- return {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [
- c.fromRange,
- {
- ...c.toRange,
- startColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.fromRange.endColumn + 1 : c.toRange.startColumn,
- endColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.toRange.endColumn - 1 : c.fromRange.startColumn - 1
- }
- ]
- };
- }
- case $.MoveRowsCommandId: {
- const c = e.params, d = N(t, {
- unitId: c.unitId,
- subUnitId: c.subUnitId
- });
- return {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [
- c.fromRange,
- {
- ...c.toRange,
- startRow: c.fromRange.startRow < c.toRange.startRow ? c.fromRange.endRow + 1 : c.toRange.startRow,
- endRow: c.fromRange.startRow < c.toRange.startRow ? c.toRange.endRow - 1 : c.fromRange.startRow - 1
- }
- ]
- };
- }
- case $.MoveRangeCommandId: {
- const c = e.params, d = N(t);
- return {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [c.fromRange, c.toRange]
- };
- }
- case $.InsertRowCommandId: {
- const c = e.params, d = c.range;
- return {
- unitId: c.unitId,
- subUnitId: c.subUnitId,
- ranges: [
- ...d.startRow > 0 ? [{
- ...d,
- startRow: d.startRow - 1,
- endRow: d.endRow - 1
- }] : [],
- {
- ...d,
- startRow: d.startRow,
- endRow: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.InsertColCommandId: {
- const c = e.params, d = c.range;
- return {
- unitId: c.unitId,
- subUnitId: c.subUnitId,
- ranges: [
- ...d.startColumn > 0 ? [{
- ...d,
- startColumn: d.startColumn - 1,
- endColumn: d.endColumn - 1
- }] : [],
- {
- ...d,
- startColumn: d.startColumn,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.RemoveRowCommandId: {
- const d = e.params.range, h = N(t);
- return {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: [
- d,
- {
- ...d,
- startRow: d.endRow + 1,
- endRow: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.RemoveColCommandId: {
- const d = e.params.range, h = N(t);
- return {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: [
- d,
- {
- ...d,
- startColumn: d.endColumn + 1,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.DeleteRangeMoveUpCommandId:
- case $.InsertRangeMoveDownCommandId: {
- const c = e, d = N(t), h = ((s = c.params) == null ? void 0 : s.range) || ((i = (r = o.getCurrentSelections()) == null ? void 0 : r.map((m) => m.range)) == null ? void 0 : i[0]);
- return h ? {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [
- h,
- {
- ...h,
- startRow: h.endRow + 1,
- endRow: Number.MAX_SAFE_INTEGER
- }
- ]
- } : {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: []
- };
- }
- case $.DeleteRangeMoveLeftCommandId:
- case $.InsertRangeMoveRightCommandId: {
- const d = ((a = e.params) == null ? void 0 : a.range) || ((l = (u = o.getCurrentSelections()) == null ? void 0 : u.map((m) => m.range)) == null ? void 0 : l[0]), h = N(t);
- return d ? {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: [
- d,
- {
- ...d,
- startColumn: d.endColumn + 1,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- ]
- } : {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: []
- };
- }
- case $.ReorderRangeCommandId: {
- const c = e, { range: d, order: h } = c.params, m = [];
- for (let f = d.startRow; f <= d.endRow; f++)
- f in h && m.push({
- startRow: f,
- endRow: f,
- startColumn: d.startColumn,
- endColumn: d.endColumn
- });
- const g2 = N(t);
- return {
- unitId: g2.unitId,
- subUnitId: g2.subUnitId,
- ranges: m
- };
- }
- }
- }
- var Ic = Object.defineProperty;
- var vc = Object.getOwnPropertyDescriptor;
- var Mc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? vc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Ic(e, t, s), s;
- };
- var dn2 = (n, e) => (t, o) => e(t, o, n);
- var _c = nR("MERGE_REDO");
- var bc = nR("MERGE_UNDO");
- var rs = Math.floor(Number.MAX_SAFE_INTEGER / 10);
- var yc = class extends nt {
- constructor(e, t, o, s, r = false) {
- super(), this._unitId = e, this._subUnitId = t, this._range = o, this._callback = s, this._skipIntersects = r;
- }
- onMutation(e) {
- var s, r;
- if (((s = e.params) == null ? void 0 : s.unitId) !== this._unitId)
- return;
- if (e.id === dt.id) {
- const i = e.params;
- if (i.from.subUnitId !== this._subUnitId || i.to.subUnitId !== this._subUnitId)
- return;
- } else if (((r = e.params) == null ? void 0 : r.subUnitId) !== this._subUnitId)
- return;
- if (!this._range)
- return;
- if (this._skipIntersects) {
- if (e.id === Ut.id)
- return;
- const i = wc(e);
- if (i != null && i.some((a) => en.intersects(a, this._range)))
- return;
- }
- const t = Sc(this._range, e);
- if (t && en.equals(t, this._range))
- return false;
- const o = this._range;
- this._range = t, this._callback(o, t);
- }
- };
- var _t = class extends nt {
- constructor(e, t, o, s) {
- super();
- R(this, "interceptor", new rR({ MERGE_REDO: _c, MERGE_UNDO: bc }));
- R(this, "_watchRanges", /* @__PURE__ */ new Set());
- R(this, "_refRangeManagerMap", /* @__PURE__ */ new Map());
- R(this, "_serializer", Ec());
- R(this, "_onRefRangeChange", () => {
- this._sheetInterceptorService.interceptCommand({
- // eslint-disable-next-line max-lines-per-function
- getMutations: (e2) => {
- const t2 = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET).getActiveSheet(), o2 = is(this._univerInstanceService), s2 = as(this._univerInstanceService);
- if (!t2 || !o2 || !s2)
- return { redos: [], undos: [], preRedos: [], preUndos: [] };
- const a = ((() => {
- switch (e2.id) {
- case $.MoveColsCommandId: {
- const h = e2.params, m = Math.min(h.fromRange.startColumn, h.toRange.startColumn);
- return this._checkRange(
- [{ ...h.fromRange, startColumn: m, endColumn: t2.getColumnCount() - 1 }],
- o2,
- s2
- );
- }
- case $.MoveRowsCommandId: {
- const h = e2.params, m = Math.min(h.fromRange.startRow, h.toRange.startRow);
- return this._checkRange(
- [{ ...h.fromRange, startRow: m, endRow: t2.getRowCount() - 1 }],
- o2,
- s2
- );
- }
- case $.MoveRangeCommandId: {
- const h = e2;
- return this._checkRange(
- [h.params.fromRange, h.params.toRange],
- o2,
- s2
- );
- }
- case $.InsertRowCommandId: {
- const g2 = {
- startRow: e2.params.range.startRow,
- endRow: t2.getRowCount() - 1,
- startColumn: 0,
- endColumn: t2.getColumnCount() - 1,
- rangeType: De.ROW
- };
- return this._checkRange([g2], o2, s2);
- }
- case $.InsertColCommandId: {
- const m = e2.params.range.startColumn, g2 = {
- startRow: 0,
- endRow: t2.getRowCount() - 1,
- startColumn: m,
- endColumn: t2.getColumnCount() - 1,
- rangeType: De.COLUMN
- };
- return this._checkRange([g2], o2, s2);
- }
- case $.RemoveRowCommandId: {
- const g2 = {
- startRow: e2.params.range.startRow,
- endRow: t2.getRowCount() - 1,
- startColumn: 0,
- endColumn: t2.getColumnCount() - 1,
- rangeType: De.ROW
- };
- return this._checkRange([g2], o2, s2);
- }
- case $.RemoveColCommandId: {
- const m = e2.params.range.startColumn, g2 = {
- startRow: 0,
- endRow: t2.getRowCount() - 1,
- startColumn: m,
- endColumn: t2.getColumnCount() - 1,
- rangeType: De.COLUMN
- };
- return this._checkRange([g2], o2, s2);
- }
- case $.DeleteRangeMoveUpCommandId:
- case $.InsertRangeMoveDownCommandId: {
- const m = e2.params.range || us(this._selectionManagerService)[0], g2 = {
- startRow: m.startRow,
- startColumn: m.startColumn,
- endColumn: m.endColumn,
- endRow: rs
- };
- return this._checkRange([g2], o2, s2);
- }
- case $.DeleteRangeMoveLeftCommandId:
- case $.InsertRangeMoveRightCommandId: {
- const m = e2.params.range || us(this._selectionManagerService)[0], g2 = {
- startRow: m.startRow,
- startColumn: m.startColumn,
- endColumn: rs,
- endRow: m.endRow
- };
- return this._checkRange([g2], o2, s2);
- }
- case $.ReorderRangeCommandId: {
- const h = e2, { range: m, order: g2 } = h.params, f = [];
- for (let p = m.startRow; p <= m.endRow; p++)
- p in g2 && f.push({
- startRow: p,
- endRow: p,
- startColumn: m.startColumn,
- endColumn: m.endColumn
- });
- return this._checkRange(f, o2, s2);
- }
- }
- })() || []).reduce(
- (h, m) => {
- const g2 = m(e2);
- return h.push(g2), h;
- },
- []
- ).reduce(
- (h, m) => {
- var g2, f;
- return h.redos.push(...m.redos), h.undos.push(...m.undos), h.preRedos.push(...(g2 = m.preRedos) != null ? g2 : []), h.preUndos.push(...(f = m.preUndos) != null ? f : []), h;
- },
- { redos: [], undos: [], preUndos: [], preRedos: [] }
- ), u = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
- a.preRedos,
- null
- ) || [], l = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
- a.redos,
- null
- ) || [], c = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(
- a.preUndos,
- null
- ) || [], d = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(
- a.undos,
- null
- ) || [];
- return { redos: l, undos: d, preRedos: u, preUndos: c };
- }
- });
- });
- R(this, "_checkRange", (e2, t2, o2) => {
- const s2 = ls(t2, o2), r = this._refRangeManagerMap.get(s2);
- if (r) {
- const i = /* @__PURE__ */ new Set();
- return [...r.keys()].forEach((u) => {
- const l = r.get(u), c = this._serializer.deserialize(u), d = {
- ...c,
- startRow: +c.startRow,
- endRow: +c.endRow,
- startColumn: +c.startColumn,
- endColumn: +c.endColumn,
- rangeType: c.rangeType && +c.rangeType
- };
- e2.some((h) => en.intersects(h, d)) && l && l.forEach((h) => {
- i.add(h);
- });
- }), [...i];
- }
- return [];
- });
- R(this, "registerRefRange", (e2, t2, o2, s2) => {
- const r = o2 || is(this._univerInstanceService), i = s2 || as(this._univerInstanceService);
- if (!r || !i)
- return Ze(() => {
- });
- const a = ls(r, i), u = this._serializer.serialize(e2);
- let l = this._refRangeManagerMap.get(a);
- l || (l = /* @__PURE__ */ new Map(), this._refRangeManagerMap.set(a, l));
- const c = l.get(u);
- return c ? c.add(t2) : l.set(u, /* @__PURE__ */ new Set([t2])), Ze(() => {
- const d = l.get(u);
- d && (d.delete(t2), d.size || (l.delete(u), l.size || this._refRangeManagerMap.delete(a)));
- });
- });
- this._commandService = e, this._sheetInterceptorService = t, this._univerInstanceService = o, this._selectionManagerService = s, this._onRefRangeChange(), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_REDO, {
- priority: -1,
- handler: (r) => r
- }), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_UNDO, {
- priority: -1,
- handler: (r) => r
- });
- }
- watchRange(e, t, o, s, r) {
- let i;
- this._watchRanges.size === 0 && (i = this._commandService.onCommandExecuted((c) => {
- if (c.type !== ar.MUTATION)
- return false;
- for (const d of this._watchRanges)
- d.onMutation(c);
- }));
- const a = new yc(e, t, o, s, r);
- this._watchRanges.add(a);
- const u = Ze(() => {
- this._watchRanges.delete(a), this._watchRanges.size === 0 && (i == null || i.dispose(), i = null);
- }), l = this.disposeWithMe(u);
- return Ze(() => {
- l.dispose(), u.dispose();
- });
- }
- };
- _t = Mc([
- dn2(0, Pt),
- dn2(1, ot(V)),
- dn2(2, ot(_n)),
- dn2(3, ot(F))
- ], _t);
- function is(n) {
- return n.getCurrentUnitForType(Fe.UNIVER_SHEET).getUnitId();
- }
- function as(n) {
- var e;
- return (e = n.getCurrentUnitForType(Fe.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : e.getSheetId();
- }
- function us(n) {
- var e;
- return ((e = n.getCurrentSelections()) == null ? void 0 : e.map((t) => t.range)) || [];
- }
- function ls(n, e) {
- return `${n}_${e}`;
- }
- function Ec() {
- const n = ["startRow", "startColumn", "endRow", "endColumn", "rangeType"], e = "_";
- return {
- deserialize: (t) => {
- const o = n.reduce(
- (r, i, a) => (r[String(a)] = i, r),
- {}
- );
- return t.split(e).reduce(
- (r, i, a) => {
- const u = String(a);
- return i && o[u] && (r[o[u]] = i), r;
- },
- {}
- );
- },
- serialize: (t) => n.reduce((o, s, r) => {
- const i = t[s];
- return i !== void 0 ? `${o}${r > 0 ? e : ""}${i}` : `${o}`;
- }, "")
- };
- }
- var Uc = Object.defineProperty;
- var Pc = Object.getOwnPropertyDescriptor;
- var Tc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Pc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Uc(e, t, s), s;
- };
- var Rt = (n, e) => (t, o) => e(t, o, n);
- var kc = [je.id, qe.id, De2.id, Be.id];
- var Nc = [ot2.id, st2.id];
- function Zr(n, e) {
- let t = n;
- if (e !== void 0) {
- const o = [];
- for (let s = 0; s < t.length; s++) {
- const { startRow: r, endRow: i, startColumn: a, endColumn: u } = t[s];
- if (e === yu.ROWS)
- for (let l = r; l <= i; l++) {
- const c = {
- startRow: l,
- endRow: l,
- startColumn: a,
- endColumn: u
- };
- o.push(c);
- }
- else if (e === yu.COLUMNS)
- for (let l = a; l <= u; l++) {
- const c = {
- startRow: r,
- endRow: i,
- startColumn: l,
- endColumn: l
- };
- o.push(c);
- }
- }
- t = o;
- }
- return t;
- }
- var Oc = nR("mergeCellPermissionCheck");
- var Tn = class extends nt {
- constructor(e, t, o, s, r, i) {
- super();
- R(this, "disposableCollection", new Mi());
- R(this, "interceptor", new rR({ MERGE_CELL_INTERCEPTOR_CHECK: Oc }));
- this._commandService = e, this._refRangeService = t, this._univerInstanceService = o, this._injector = s, this._sheetInterceptorService = r, this._selectionManagerService = i, this._onRefRangeChange(), this._initCommandInterceptor(), this._commandExecutedListener();
- }
- _initCommandInterceptor() {
- const e = this;
- this._sheetInterceptorService.interceptCommand({
- getMutations(t) {
- var o;
- switch (t.id) {
- case po.id:
- case So.id: {
- const s = e._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET), r = s.getUnitId(), i = s == null ? void 0 : s.getActiveSheet();
- if (!i)
- return { redos: [], undos: [] };
- const a = i.getSheetId(), u = i.getConfig().mergeData, l = (o = e._selectionManagerService.getCurrentSelections()) == null ? void 0 : o.map((c) => c.range);
- if (l && l.length > 0 && l.some(
- (d) => u.some((h) => en.intersects(h, d))
- )) {
- const d = {
- unitId: r,
- subUnitId: a,
- ranges: l
- }, h = Se(e._injector, d), m = [
- { id: oe.id, params: d }
- ], g2 = [
- { id: ne.id, params: h }
- ];
- return { redos: m, undos: g2 };
- }
- }
- }
- return { redos: [], undos: [] };
- }
- }), this._sheetInterceptorService.interceptRanges({
- getMutations: ({ unitId: t, subUnitId: o, ranges: s }) => {
- const r = [], i = [], a = { redos: r, undos: i };
- if (!s || !s.length)
- return a;
- const u = N(this._univerInstanceService, { unitId: t, subUnitId: o });
- if (!u)
- return a;
- const { worksheet: l } = u, d = l.getMergeData().filter((h) => s.some((m) => en.intersects(h, m)));
- return d.length ? (r.push({
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: d
- }
- }), i.push({
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: d
- }
- }), { undos: i, redos: r }) : a;
- }
- });
- }
- refRangeHandle(e, t, o) {
- switch (e.id) {
- case $.MoveColsCommandId: {
- const s = e.params;
- return this._handleMoveColsCommand(s, t, o);
- }
- case $.MoveRowsCommandId: {
- const s = e.params;
- return this._handleMoveRowsCommand(s, t, o);
- }
- case mt.id: {
- const s = e.params, r = s.unitId || t, i = s.subUnitId || o;
- return this._handleInsertRowCommand(s, r, i);
- }
- case gt.id: {
- const s = e.params, r = s.unitId || t, i = s.subUnitId || o;
- return this._handleInsertColCommand(s, r, i);
- }
- case zn2.id: {
- const s = e.params;
- return this._handleRemoveColCommand(s, t, o);
- }
- case Gn.id: {
- const s = e.params;
- return this._handleRemoveRowCommand(s, t, o);
- }
- case pt.id: {
- const s = e.params;
- return this._handleMoveRangeCommand(s, t, o);
- }
- case Bn.id: {
- const s = e.params;
- return this._handleInsertRangeMoveRightCommand(s, t, o);
- }
- case sn.id: {
- const s = e.params;
- return this._handleInsertRangeMoveDownCommand(s, t, o);
- }
- case Tt.id: {
- const s = e.params;
- return this._handleDeleteRangeMoveUpCommand(s, t, o);
- }
- case Pt2.id: {
- const s = e.params;
- return this._handleDeleteRangeMoveLeftCommand(s, t, o);
- }
- }
- return { redos: [], undos: [] };
- }
- _onRefRangeChange() {
- const e = (t, o) => {
- const s = this._univerInstanceService.getUniverSheetInstance(t);
- if (!s)
- return;
- const r = s == null ? void 0 : s.getSheetBySheetId(o);
- if (!r)
- return;
- this.disposableCollection.dispose();
- const i = r.getMergeData(), a = (u) => this.refRangeHandle(u, t, o);
- i.forEach((u) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(u, a, t, o));
- });
- };
- this.disposeWithMe(
- this._commandService.onCommandExecuted((t) => {
- if (t.id === an.id) {
- const o = t.params, s = o.subUnitId, r = o.unitId;
- if (!s || !r)
- return;
- e(r, s);
- }
- if (t.id === ne.id) {
- const o = t.params, s = o.subUnitId, r = o.unitId;
- if (!s || !r)
- return;
- e(o.unitId, o.subUnitId);
- }
- })
- ), this._univerInstanceService.getCurrentTypeOfUnit$(Fe.UNIVER_SHEET).pipe(first((t) => !!t)).subscribe((t) => {
- const o = t.getActiveSheet();
- o && e(t.getUnitId(), o.getSheetId());
- });
- }
- _handleMoveRowsCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startRow: c, endRow: d } = l;
- if (i.forEach((g2) => {
- if (c <= g2.startRow && d >= g2.endRow) {
- a.ranges.push(g2);
- const f = Jr({ id: $.MoveRowsCommandId, params: e }, g2), p = Mt2(f, g2);
- p && u.ranges.push(p);
- }
- }), a.ranges.length === 0)
- return this._handleNull();
- const h = Se(this._injector, a), m = Ue(this._injector, u);
- return {
- preRedos: [{ id: oe.id, params: a }],
- redos: [{ id: ne.id, params: u }],
- preUndos: [{ id: oe.id, params: m }],
- undos: [{ id: ne.id, params: h }]
- };
- }
- _handleMoveColsCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startColumn: c, endColumn: d } = l;
- if (i.forEach((g2) => {
- if (c <= g2.startColumn && d >= g2.endColumn) {
- a.ranges.push(g2);
- const f = Yr({ id: $.MoveColsCommandId, params: e }, g2), p = Mt2(f, g2);
- p && u.ranges.push(p);
- }
- }), a.ranges.length === 0)
- return this._handleNull();
- const h = Se(this._injector, a), m = Ue(this._injector, u);
- return {
- preRedos: [{ id: oe.id, params: a }],
- redos: [{ id: ne.id, params: u }],
- preUndos: [{ id: oe.id, params: m }],
- undos: [{ id: ne.id, params: h }]
- };
- }
- _handleMoveRangeCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = r.getMergeData(), a = i.filter((m) => en.intersects(m, e.fromRange)), u = i.filter((m) => en.intersects(m, e.toRange)), l = a.map((m) => en.getRelativeRange(m, e.fromRange)).map((m) => en.getPositionRange(m, e.toRange)), c = Zr(l).filter(
- (m) => !i.some((g2) => en.equals(m, g2))
- ), d = [
- {
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: a
- }
- },
- {
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: u
- }
- },
- {
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: c
- }
- }
- ], h = [
- {
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: c
- }
- },
- {
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: u
- }
- },
- {
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: a
- }
- }
- ];
- return { redos: d, undos: h };
- }
- _handleInsertRowCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const { range: i } = e, { startRow: a, endRow: u } = i, l = re.deepClone(r.getMergeData()).reduce((C, S) => (a > S.startRow && a <= S.endRow && C.push(S), C), []);
- if (l.length === 0)
- return this._handleNull();
- const c = re.deepClone(r.getMergeData()).reduce((C, S) => {
- if (a > S.startRow && a <= S.endRow) {
- const I = u - a + 1;
- S.endRow += I, this._checkIsMergeCell(S) && C.push(S);
- }
- return C;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- ), f = [
- { id: oe.id, params: d },
- { id: ne.id, params: m }
- ], p = [
- { id: oe.id, params: g2 },
- { id: ne.id, params: h }
- ];
- return { redos: f, undos: p };
- }
- _handleInsertColCommand(e, t, o) {
- const { range: s } = e, r = be(this._univerInstanceService, t);
- if (!r)
- return this._handleNull();
- const i = ye(r, o);
- if (!i)
- return this._handleNull();
- const { startColumn: a, endColumn: u } = s, l = re.deepClone(i.getMergeData()).reduce((C, S) => (a > S.startColumn && a <= S.endColumn && C.push(S), C), []);
- if (l.length === 0)
- return this._handleNull();
- const c = re.deepClone(i.getMergeData()).reduce((C, S) => {
- if (a > S.startColumn && a <= S.endColumn) {
- const I = u - a + 1;
- S.endColumn += I, this._checkIsMergeCell(S) && C.push(S);
- }
- return C;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- ), f = [
- { id: oe.id, params: d },
- { id: ne.id, params: m }
- ], p = [
- { id: oe.id, params: g2 },
- { id: ne.id, params: h }
- ];
- return { redos: f, undos: p };
- }
- _handleRemoveColCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const { range: i } = e, { startColumn: a, endColumn: u } = i, l = re.deepClone(r.getMergeData()).reduce((I, w) => (en.intersects(i, w) && I.push(w), I), []);
- if (l.length === 0)
- return this._handleNull();
- const c = re.deepClone(r.getMergeData()).reduce((I, w) => {
- if (en.intersects(i, w)) {
- if (a <= w.startColumn && u >= w.endColumn)
- return I;
- a >= w.startColumn && u <= w.endColumn ? w.endColumn -= u - a + 1 : a < w.startColumn ? (w.startColumn = a, w.endColumn -= u - a + 1) : u > w.endColumn && (w.endColumn = a - 1), this._checkIsMergeCell(w) && I.push(w);
- }
- return I;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g2 }], S = [{ id: ne.id, params: h }];
- return { preUndos: C, undos: S, preRedos: f, redos: p };
- }
- _handleRemoveRowCommand(e, t, o) {
- const { range: s } = e, r = be(this._univerInstanceService, t);
- if (!r)
- return this._handleNull();
- const i = ye(r, o);
- if (!i)
- return this._handleNull();
- const { startRow: a, endRow: u } = s, l = re.deepClone(i.getMergeData()).reduce((I, w) => (en.intersects(s, w) && I.push(w), I), []);
- if (l.length === 0)
- return this._handleNull();
- const c = re.deepClone(i.getMergeData()).reduce((I, w) => {
- if (en.intersects(s, w)) {
- if (a <= w.startRow && u >= w.endRow)
- return I;
- a >= w.startRow && u <= w.endRow ? w.endRow -= u - a + 1 : a < w.startRow ? (w.startRow = a, w.endRow -= u - a + 1) : u > w.endRow && (w.endRow = a - 1), this._checkIsMergeCell(w) && I.push(w);
- }
- return I;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g2 }], S = [{ id: ne.id, params: h }];
- return { preUndos: C, undos: S, preRedos: f, redos: p };
- }
- _handleInsertRangeMoveRightCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((f) => {
- const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i;
- if (en.intersects(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ) && (l.push(f), en.contains(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ))) {
- const y = I - S + 1;
- c.push({
- startRow: f.startRow,
- startColumn: f.startColumn + y,
- endRow: f.endRow,
- endColumn: f.endColumn + y
- });
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- );
- return {
- preRedos: [
- { id: oe.id, params: d }
- ],
- redos: [
- {
- id: ne.id,
- params: m
- }
- ],
- preUndos: [
- { id: oe.id, params: g2 }
- ],
- undos: [
- {
- id: ne.id,
- params: h
- }
- ]
- };
- }
- _handleInsertRangeMoveDownCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((I) => {
- const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i;
- if (en.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), en.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) {
- const P = x - w + 1;
- c.push({
- startRow: I.startRow + P,
- startColumn: I.startColumn,
- endRow: I.endRow + P,
- endColumn: I.endColumn
- });
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- ), f = [
- {
- id: oe.id,
- params: d
- }
- ], p = [
- {
- id: ne.id,
- params: m
- }
- ], C = [
- {
- id: oe.id,
- params: g2
- }
- ], S = [
- {
- id: ne.id,
- params: h
- }
- ];
- return { redos: p, undos: S, preRedos: f, preUndos: C };
- }
- _handleDeleteRangeMoveUpCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((I) => {
- const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i;
- if (en.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), en.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) {
- const P = x - w + 1, A = en.moveVertical(I, -P);
- c.push(A);
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(
- this._injector,
- m
- ), f = [
- {
- id: oe.id,
- params: d
- }
- ], p = [
- {
- id: ne.id,
- params: m
- }
- ], C = [
- {
- id: oe.id,
- params: g2
- }
- ], S = [
- {
- id: ne.id,
- params: h
- }
- ];
- return { redos: p, undos: S, preRedos: f, preUndos: C };
- }
- _handleDeleteRangeMoveLeftCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((f) => {
- const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i;
- if (en.intersects(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ) && (l.push(f), en.contains(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ))) {
- const y = I - S + 1;
- c.push({
- startRow: f.startRow,
- startColumn: f.startColumn - y,
- endRow: f.endRow,
- endColumn: f.endColumn - y
- });
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(this._injector, d), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g2 = Ue(this._injector, m);
- return {
- preRedos: [
- { id: oe.id, params: d }
- ],
- redos: [
- {
- id: ne.id,
- params: m
- }
- ],
- undos: [
- {
- id: ne.id,
- params: h
- }
- ],
- preUndos: [
- { id: oe.id, params: g2 }
- ]
- };
- }
- _checkIsMergeCell(e) {
- return !(e.startRow === e.endRow && e.startColumn === e.endColumn);
- }
- _handleNull() {
- return { redos: [], undos: [] };
- }
- _commandExecutedListener() {
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
- if (Nc.includes(e.id)) {
- if (!e.params)
- return;
- const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
- if (!t)
- return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o)
- return;
- const { sourceRange: s, targetRange: r } = e.params, i = s.startColumn === r.startColumn && s.endColumn === r.endColumn, a = i ? s.endRow - s.startRow + 1 : s.endColumn - s.startColumn + 1, u = i ? s.startRow : s.startColumn, l = i ? r.startRow : r.startColumn, c = o.getConfig().mergeData, d = [];
- c.forEach((f) => {
- let { startRow: p, endRow: C, startColumn: S, endColumn: I, rangeType: w } = f;
- en.intersects(f, s) || (i ? u < p && l > C ? (p -= a, C -= a) : u > C && l <= p && (p += a, C += a) : u < S && l > I ? (S -= a, I -= a) : u > I && l <= S && (S += a, I += a)), f.startRow === f.endRow && f.startColumn === f.endColumn || d.push({ startRow: p, endRow: C, startColumn: S, endColumn: I, rangeType: w });
- }), o.setMergeData(d), this.disposableCollection.dispose();
- const { unitId: h, subUnitId: m } = e.params, g2 = (f) => this.refRangeHandle(f, h, m);
- d.forEach((f) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(f, g2, h, m));
- });
- }
- if (kc.includes(e.id)) {
- const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
- if (!t)
- return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o)
- return;
- const s = o.getConfig().mergeData, r = e.params;
- if (!r)
- return;
- const { range: i } = r, a = e.id.includes("row"), u = e.id.includes("insert"), l = a ? i.startRow : i.startColumn, c = a ? i.endRow : i.endColumn, d = c - l + 1, h = [];
- s.forEach((p) => {
- let { startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b } = p;
- u ? a ? l <= C && (C += d, S += d) : l <= I && (I += d, w += d) : a ? c < C && (C -= d, S -= d) : c < I && (I -= d, w -= d), p.startRow === p.endRow && p.startColumn === p.endColumn || h.push({ startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b });
- }), o.setMergeData(h), this.disposableCollection.dispose();
- const { unitId: m, subUnitId: g2 } = e.params, f = (p) => this.refRangeHandle(p, m, g2);
- h.forEach((p) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(p, f, m, g2));
- });
- }
- }));
- }
- };
- Tn = Tc([
- Rt(0, ot(Pt)),
- Rt(1, ot(_t)),
- Rt(2, ot(_n)),
- Rt(3, ot(Ot)),
- Rt(4, ot(V)),
- Rt(5, ot(F))
- ], Tn);
- function be(n, e) {
- return e ? n.getUniverSheetInstance(e) : n.getCurrentUnitForType(Fe.UNIVER_SHEET);
- }
- function ye(n, e) {
- return e ? n.getSheetBySheetId(e) : n.getActiveSheet();
- }
- var Dc = Object.defineProperty;
- var Ac = Object.getOwnPropertyDescriptor;
- var xc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Ac(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Dc(e, t, s), s;
- };
- var $c = (n, e) => (t, o) => e(t, o, n);
- var kn = class extends nt {
- constructor(n) {
- super(), this._sheetInterceptorService = n, this._initialize();
- }
- _initialize() {
- this._initInterceptorCellContent();
- }
- _initInterceptorCellContent() {
- this.disposeWithMe(
- this._sheetInterceptorService.intercept(et.CELL_CONTENT, {
- priority: 11,
- effect: Vn.Value | Vn.Style,
- handler: (n, e, t) => {
- var s;
- const o = e.workbook.getStyles().getStyleByCell(n);
- return (s = o == null ? void 0 : o.n) != null && s.pattern ? t({ ...n }) : (n == null ? void 0 : n.t) === dn.NUMBER && n.v !== void 0 && n.v !== null && DC(n.v) ? t({
- ...n,
- v: _f(Number(n.v))
- }) : t({ ...n });
- }
- })
- );
- }
- };
- kn = xc([
- $c(0, ot(V))
- ], kn);
- var Wc = Object.defineProperty;
- var Lc = Object.getOwnPropertyDescriptor;
- var Vc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Lc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Wc(e, t, s), s;
- };
- var $e2 = (n, e) => (t, o) => e(t, o, n);
- var Nn = class extends nt {
- constructor(e, t, o, s, r, i, a, u, l, c) {
- super();
- R(this, "disposableCollection", new Mi());
- R(this, "_triggerPermissionUIEvent$", new Subject());
- R(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable());
- this._commandService = e, this._univerInstanceService = t, this._permissionService = o, this._selectionManagerService = s, this._rangeProtectionRuleModel = r, this._worksheetProtectionRuleModel = i, this._localeService = a, this._lexerTreeBuilder = u, this._contextService = l, this._definedNamesService = c, this._initialize();
- }
- blockExecuteWithoutPermission(e) {
- throw this._triggerPermissionUIEvent$.next(e), new wo("have no permission");
- }
- _getPermissionCheck(e, t) {
- let o = true, s = "";
- switch (e) {
- case on.id:
- fC(t.value) && t.value.f ? (o = this._permissionCheckWithFormula(t), s = this._localeService.t("permission.dialog.formulaErr")) : o = this._permissionCheckBySetRangeValue({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [wn, Te]
- }, t);
- break;
- case Co.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [wn, Te]
- }), s = this._localeService.t("permission.dialog.editErr");
- break;
- case Oo.id:
- case Mn.id:
- o = this.permissionCheckWithoutRange({
- worksheetTypes: [$t]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case $o.id:
- case Wo.id:
- case Lo.id:
- o = this.permissionCheckWithoutRange({
- worksheetTypes: [Wt]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case jn.id:
- case Fn.id:
- o = this._permissionCheckByMoveCommand(t), s = this._localeService.t("permission.dialog.moveRowColErr");
- break;
- case pt.id:
- o = this._permissionCheckByMoveRangeCommand(t), s = this._localeService.t("permission.dialog.moveRangeErr");
- break;
- case Wr.id:
- o = this._permissionCheckByWorksheetCommand([Me, _o]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === false && this._worksheetProtectionRuleModel.resetOrder();
- break;
- case Do.id:
- o = this._permissionCheckByWorksheetCommand([Me, bo]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === false && this._worksheetProtectionRuleModel.resetOrder();
- break;
- case Fr.id:
- {
- const { unitId: r, subUnitId: i } = t;
- o = this._permissionCheckByWorksheetCommand([Me, vo], r, i), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === false && this._worksheetProtectionRuleModel.resetOrder();
- }
- break;
- case Kn.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, $t]
- }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case Jn.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, Wt]
- }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case br.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, $t]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case Tr.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, Wt]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case Bn.id:
- o = this._permissionCheckWithInsertRangeMove("right"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- case sn.id:
- o = this._permissionCheckWithInsertRangeMove("bottom"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- case Pt2.id:
- o = this._permissionCheckWithInsertRangeMove("left"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- case Tt.id:
- o = this._permissionCheckWithInsertRangeMove("top"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- }
- o || this.blockExecuteWithoutPermission(s);
- }
- _initialize() {
- this._commandExecutedListener();
- }
- _commandExecutedListener() {
- this.disposeWithMe(
- this._commandService.beforeCommandExecuted((e) => {
- this._getPermissionCheck(e.id, e == null ? void 0 : e.params);
- })
- ), this.disposeWithMe(
- this._commandService.onCommandExecuted((e) => {
- var t;
- if (e.id === _n2.id) {
- const o = e.params, { unitId: s = (t = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET)) == null ? void 0 : t.getUnitId(), subUnitId: r } = o;
- if (!s || !r)
- return;
- const i = this._worksheetProtectionRuleModel.getRule(s, r), a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r);
- i && this._worksheetProtectionRuleModel.ruleRefresh(i.permissionId), a.length && this._rangeProtectionRuleModel.ruleRefresh(r);
- }
- })
- );
- }
- _permissionCheckWithInsertRangeMove(e) {
- var l;
- const t = N(this._univerInstanceService);
- if (!t)
- return false;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = re.deepClone((l = this._selectionManagerService.getCurrentLastSelection()) == null ? void 0 : l.range);
- return !(!i || (e === "top" || e === "bottom" ? i.endRow = o.getRowCount() - 1 : (e === "left" || e === "right") && (i.endColumn = o.getColumnCount() - 1), this._rangeProtectionRuleModel.getSubunitRuleList(s, r).map((c) => c.ranges).flat().some((c) => en.getIntersects(i, c))));
- }
- _permissionCheckByWorksheetCommand(e, t, o) {
- var l, c;
- const s = N(this._univerInstanceService, { unitId: t, subUnitId: o });
- if (!s)
- return false;
- const { unitId: r, subUnitId: i } = s, a = this._worksheetProtectionRuleModel.getRule(r, i), u = this._rangeProtectionRuleModel.getSubunitRuleList(r, i).length > 0;
- return a || u ? (c = (l = this._permissionService.getPermissionPoint(new Mo(r).id)) == null ? void 0 : l.value) != null ? c : false : this._permissionService.composePermission(e.map((d) => new d(r).id)).every((d) => d.value);
- }
- permissionCheckWithoutRange(e) {
- var h, m, g2, f;
- const t = N(this._univerInstanceService);
- if (!t)
- return false;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = this._selectionManagerService.getCurrentLastSelection();
- if (!i)
- return true;
- const a = (m = (h = i == null ? void 0 : i.primary) == null ? void 0 : h.actualRow) != null ? m : 0, u = (f = (g2 = i == null ? void 0 : i.primary) == null ? void 0 : g2.actualColumn) != null ? f : 0, { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e;
- return !(l && l.some((C) => {
- var w, b;
- const S = new C(s);
- return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : false) === false;
- }) === true || c && c.some((C) => {
- var w, b;
- const S = new C(s, r);
- return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : false) === false;
- }) === true || d && d.some((C) => {
- var y, x, T2, U, P;
- const S = (x = (y = o.getCell(a, u)) == null ? void 0 : y.selectionProtection) == null ? void 0 : x[0];
- if (!(S != null && S.ruleId))
- return false;
- const I = (T2 = this._rangeProtectionRuleModel.getRule(s, r, S.ruleId)) == null ? void 0 : T2.permissionId;
- if (!I)
- return false;
- const w = new C(s, r, I);
- return ((P = (U = this._permissionService.getPermissionPoint(w.id)) == null ? void 0 : U.value) != null ? P : false) === false;
- }) === true);
- }
- permissionCheckWithRanges(e, t, o, s) {
- var m;
- const r = N(this._univerInstanceService);
- if (!r)
- return false;
- const { workbook: i, worksheet: a } = r;
- o || (o = i.getUnitId()), s || (s = a.getSheetId());
- const u = t != null ? t : (m = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : m.map((g2) => g2.range);
- if (!u)
- return false;
- const { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e, h = [];
- return l && h.push(...l.map((g2) => new g2(o).id)), c && h.push(...c.map((g2) => new g2(o, s).id)), d && this._rangeProtectionRuleModel.getSubunitRuleList(o, s).forEach((g2) => {
- u.some((p) => g2.ranges.some((C) => en.intersects(C, p))) && h.push(...d.map((p) => new p(o, s, g2.permissionId).id));
- }), h.length ? this._permissionService.composePermission(h).every((g2) => g2.value) : true;
- }
- _permissionCheckByMoveCommand(e) {
- const t = N(this._univerInstanceService);
- if (!t)
- return false;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = e.toRange;
- i.endRow === o.getRowCount() - 1 ? i.endColumn = i.startColumn : i.endRow = i.startRow;
- const a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r).reduce((u, l) => [...u, ...l.ranges], []).filter((u) => en.intersects(u, i));
- return a.length > 0 ? false : (a.forEach((u) => {
- var l, c;
- for (let d = u.startRow; d <= u.endRow; d++)
- for (let h = u.startColumn; h <= u.endColumn; h++) {
- const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0];
- if ((m == null ? void 0 : m[_.Edit]) === false)
- return false;
- }
- }), true);
- }
- _permissionCheckByMoveRangeCommand(e) {
- const t = N(this._univerInstanceService);
- if (!t)
- return false;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = e.toRange, a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r).reduce((u, l) => [...u, ...l.ranges], []).filter((u) => en.intersects(u, i));
- return a.length > 0 ? false : (a.forEach((u) => {
- var l, c;
- for (let d = u.startRow; d <= u.endRow; d++)
- for (let h = u.startColumn; h <= u.endColumn; h++) {
- const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0];
- if ((m == null ? void 0 : m[_.Edit]) === false)
- return false;
- }
- }), true);
- }
- _permissionCheckBySetRangeValue(e, t) {
- let o = [];
- t.range ? o = [t.range] : o = [new kt(t.value).getDataRange()];
- const { unitId: s, subUnitId: r } = t;
- return this.permissionCheckWithRanges(e, o, s, r);
- }
- _permissionCheckWithFormula(e) {
- var r, i, a, u, l;
- const t = e.value, o = e.range, s = t.f;
- if (s) {
- const c = s.substring(1), d = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET), h = (r = e.unitId) != null ? r : d.getUnitId(), m = this._definedNamesService.getValueByName(h, c);
- if (m) {
- let g2 = m.formulaOrRefString;
- g2.startsWith(X.EQUALS) && (g2 = g2.slice(1));
- const f = g2.split(",");
- for (let p = 0; p < f.length; p++) {
- const C = f[p], S = fn2(C);
- if (S.sheetName) {
- const I = d.getSheetBySheetName(S.sheetName);
- if (!I)
- return true;
- const { startRow: w, endRow: b, startColumn: y, endColumn: x } = S.range;
- for (let T2 = w; T2 <= b; T2++)
- for (let U = y; U <= x; U++) {
- const P = (a = (i = I.getCell(T2, U)) == null ? void 0 : i.selectionProtection) == null ? void 0 : a[0];
- if ((P == null ? void 0 : P[_.View]) === false)
- return false;
- }
- }
- }
- return true;
- } else {
- const g2 = this._lexerTreeBuilder.sequenceNodesBuilder(s);
- if (!g2)
- return true;
- for (let f = 0; f < g2.length; f++) {
- const p = g2[f];
- if (typeof p == "string" || p.nodeType !== $e.REFERENCE)
- continue;
- const { token: C } = p, S = mr(C), I = S.unitId ? this._univerInstanceService.getUnit(S.unitId) : this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!I)
- return true;
- let w = S.sheetName ? I.getSheetBySheetName(S.sheetName) : I.getActiveSheet();
- const b = I.getUnitId();
- if (S.sheetName) {
- if (w = I.getSheetBySheetName(S.sheetName), !w)
- return true;
- const P = w == null ? void 0 : w.getSheetId();
- if (!this._permissionService.getPermissionPoint(new Hn(b, P).id))
- return false;
- }
- if (!w)
- return true;
- const { startRow: y, endRow: x, startColumn: T2, endColumn: U } = S.range;
- for (let P = y; P <= x; P++)
- for (let A = T2; A <= U; A++) {
- const j = (l = (u = w.getCell(P, A)) == null ? void 0 : u.selectionProtection) == null ? void 0 : l[0];
- if ((j == null ? void 0 : j[_.View]) === false)
- return false;
- }
- }
- return true;
- }
- }
- if (o) {
- const c = N(this._univerInstanceService);
- if (!c)
- return false;
- const d = e.unitId || c.unitId, h = e.subUnitId || c.subUnitId, g2 = this._rangeProtectionRuleModel.getSubunitRuleList(d, h).filter((p) => p.ranges.some((C) => en.intersects(C, o))).map((p) => new Pe(d, h, p.permissionId).id);
- if (!this._permissionService.composePermission(g2).every((p) => p.value))
- return false;
- }
- return true;
- }
- };
- Nn = Vc([
- $e2(0, Pt),
- $e2(1, _n),
- $e2(2, UE),
- $e2(3, ot(F)),
- $e2(4, ot(de)),
- $e2(5, ot(Ye)),
- $e2(6, ot(Vr)),
- $e2(7, ot(ca)),
- $e2(8, fs),
- $e2(9, pr)
- ], Nn);
- var Hc = Object.defineProperty;
- var Bc = Object.getOwnPropertyDescriptor;
- var Fc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Bc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Hc(e, t, s), s;
- };
- var no = (n, e) => (t, o) => e(t, o, n);
- var ht = class extends nt {
- constructor(e, t, o) {
- super();
- R(this, "_cellRuleCache", /* @__PURE__ */ new Map());
- R(this, "_permissionIdCache", /* @__PURE__ */ new Map());
- R(this, "_cellInfoCache", /* @__PURE__ */ new Map());
- R(this, "_rowInfoCache", /* @__PURE__ */ new Map());
- R(this, "_colInfoCache", /* @__PURE__ */ new Map());
- this._ruleModel = e, this._permissionService = t, this._univerInstanceService = o, this._initUpdateCellRuleCache(), this._initUpdateCellInfoCache(), this._initUpdateRowColInfoCache(), this._initCache();
- }
- _initCache() {
- this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((e) => {
- e.getSheets().forEach((t) => {
- const o = e.getUnitId(), s = t.getSheetId();
- this.reBuildCache(o, s);
- });
- });
- }
- _initUpdateCellInfoCache() {
- this._permissionService.permissionPointUpdate$.pipe(
- filter((e) => e.type === D.SelectRange),
- map((e) => e)
- ).subscribe((e) => {
- const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s);
- if (!r)
- return;
- const i = this._ruleModel.getRule(o, t, r);
- if (!i)
- return;
- const a = this._ensureCellInfoMap(o, t);
- i.ranges.forEach((u) => {
- const { startRow: l, endRow: c, startColumn: d, endColumn: h } = u;
- for (let m = l; m <= c; m++)
- for (let g2 = d; g2 <= h; g2++)
- a.delete(`${m}-${g2}`);
- });
- }), this._ruleModel.ruleChange$.subscribe((e) => {
- var r;
- const { unitId: t, subUnitId: o } = e, s = this._ensureCellInfoMap(t, o);
- e.rule.ranges.forEach((i) => {
- tr.foreach(i, (a, u) => {
- s.delete(`${a}-${u}`);
- });
- }), e.type === "set" && ((r = e.oldRule) == null || r.ranges.forEach((i) => {
- tr.foreach(i, (a, u) => {
- this._cellInfoCache.delete(`${a}-${u}`);
- });
- }));
- });
- }
- _initUpdateCellRuleCache() {
- this._ruleModel.ruleChange$.subscribe((e) => {
- const { type: t } = e;
- t === "add" ? this._addCellRuleCache(e) : t === "delete" ? this._deleteCellRuleCache(e) : (this._deleteCellRuleCache({ ...e, rule: e.oldRule }), this._addCellRuleCache(e));
- });
- }
- _ensureRuleMap(e, t) {
- let o = this._cellRuleCache.get(e);
- o || (o = /* @__PURE__ */ new Map(), this._cellRuleCache.set(e, o));
- let s = o.get(t);
- return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
- }
- _ensureCellInfoMap(e, t) {
- let o = this._cellInfoCache.get(e);
- o || (o = /* @__PURE__ */ new Map(), this._cellInfoCache.set(e, o));
- let s = o.get(t);
- return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
- }
- _ensureRowColInfoMap(e, t, o) {
- let s = o === "row" ? this._rowInfoCache.get(e) : this._colInfoCache.get(e);
- s || (s = /* @__PURE__ */ new Map(), o === "row" ? this._rowInfoCache.set(e, s) : this._colInfoCache.set(e, s));
- let r = s.get(t);
- return r || (r = /* @__PURE__ */ new Map(), s.set(t, r)), r;
- }
- _addCellRuleCache(e) {
- const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t);
- s.ranges.forEach((i) => {
- const { startRow: a, endRow: u, startColumn: l, endColumn: c } = i;
- for (let d = a; d <= u; d++)
- for (let h = l; h <= c; h++)
- r.set(`${d}-${h}`, s.id);
- }), this._permissionIdCache.set(s.permissionId, s.id);
- }
- _deleteCellRuleCache(e) {
- const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t), i = this._ensureCellInfoMap(o, t);
- s.ranges.forEach((a) => {
- const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a;
- for (let h = u; h <= l; h++)
- for (let m = c; m <= d; m++)
- r.delete(`${h}-${m}`), i.delete(`${h}-${m}`);
- }), this._permissionIdCache.delete(s.permissionId);
- }
- _getSelectionActions(e, t, o) {
- var l, c, d, h, m, g2, f, p, C, S, I, w;
- const s = (d = (c = this._permissionService.getPermissionPoint((l = new Pe(e, t, o.permissionId)) == null ? void 0 : l.id)) == null ? void 0 : c.value) != null ? d : true, r = (g2 = (m = this._permissionService.getPermissionPoint((h = new Io(e, t, o.permissionId)) == null ? void 0 : h.id)) == null ? void 0 : m.value) != null ? g2 : true, i = (C = (p = this._permissionService.getPermissionPoint((f = new Vr2(e, t, o.permissionId)) == null ? void 0 : f.id)) == null ? void 0 : p.value) != null ? C : false, a = (w = (I = this._permissionService.getPermissionPoint((S = new Lr(e, t, o.permissionId)) == null ? void 0 : S.id)) == null ? void 0 : I.value) != null ? w : false;
- return {
- [_.Edit]: s,
- [_.View]: r,
- [_.ManageCollaborator]: i,
- [_.Delete]: a
- };
- }
- reBuildCache(e, t) {
- const o = this._ensureRuleMap(e, t), s = this._ensureCellInfoMap(e, t);
- o.clear(), s.clear();
- const r = this._ensureRowColInfoMap(e, t, "row"), i = this._ensureRowColInfoMap(e, t, "col");
- r.clear(), i.clear(), this._ruleModel.getSubunitRuleList(e, t).forEach((a) => {
- const u = this._getSelectionActions(e, t, a), l = {
- ...u,
- ruleId: a.id,
- ranges: a.ranges
- };
- a.ranges.forEach((c) => {
- const { startRow: d, endRow: h, startColumn: m, endColumn: g2 } = c;
- for (let f = d; f <= h; f++) {
- const p = r.get(`${f}`);
- p ? p.set(a.id, u) : r.set(`${f}`, /* @__PURE__ */ new Map([[a.id, u]]));
- for (let C = m; C <= g2; C++) {
- o.set(`${f}-${C}`, a.id), s.set(`${f}-${C}`, l);
- const S = i.get(`${C}`);
- S ? S.set(a.id, u) : i.set(`${C}`, /* @__PURE__ */ new Map([[a.id, u]]));
- }
- }
- }), this._permissionIdCache.set(a.permissionId, a.id);
- });
- }
- getRowPermissionInfo(e, t, o, s) {
- var a;
- const r = (a = this._rowInfoCache.get(e)) == null ? void 0 : a.get(t);
- if (!r)
- return true;
- const i = r.get(`${o}`);
- return i ? s.every((u) => {
- for (const l of i.values())
- if (l[u] === false)
- return false;
- return true;
- }) : true;
- }
- getColPermissionInfo(e, t, o, s) {
- var a;
- const r = (a = this._colInfoCache.get(e)) == null ? void 0 : a.get(t);
- if (!r)
- return true;
- const i = r.get(`${o}`);
- return i ? s.every((u) => {
- for (const l of i.values())
- if (l[u] === false)
- return false;
- return true;
- }) : true;
- }
- _initUpdateRowColInfoCache() {
- this._permissionService.permissionPointUpdate$.pipe(
- filter((e) => e.type === D.SelectRange),
- map((e) => e)
- ).subscribe({
- next: (e) => {
- const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s);
- if (!r)
- return;
- const i = this._ruleModel.getRule(o, t, r);
- if (!i)
- return;
- const a = this._ensureRowColInfoMap(o, t, "row"), u = this._ensureRowColInfoMap(o, t, "col"), l = this._getSelectionActions(o, t, i);
- i.ranges.forEach((c) => {
- const { startRow: d, endRow: h, startColumn: m, endColumn: g2 } = c;
- for (let f = d; f <= h; f++) {
- const p = a.get(`${f}`);
- p ? p.set(r, l) : a.set(`${f}`, /* @__PURE__ */ new Map([[r, l]]));
- for (let C = m; C <= g2; C++) {
- const S = u.get(`${C}`);
- S ? S.set(r, l) : u.set(`${C}`, /* @__PURE__ */ new Map([[r, l]]));
- }
- }
- });
- }
- }), this._ruleModel.ruleChange$.subscribe((e) => {
- if (e.type === "delete") {
- const { unitId: t, subUnitId: o, rule: s } = e, r = this._ensureRowColInfoMap(t, o, "row"), i = this._ensureRowColInfoMap(t, o, "col");
- s.ranges.forEach((a) => {
- const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a;
- for (let h = u; h <= l; h++) {
- const m = r.get(`${h}`);
- m == null || m.delete(s.id);
- for (let g2 = c; g2 <= d; g2++) {
- const f = i.get(`${g2}`);
- f == null || f.delete(s.id);
- }
- }
- });
- }
- });
- }
- getCellInfo(e, t, o, s) {
- var l, c;
- const r = this._ensureCellInfoMap(e, t), i = r.get(`${o}-${s}`);
- if (i)
- return i;
- const a = (c = (l = this._cellRuleCache.get(e)) == null ? void 0 : l.get(t)) == null ? void 0 : c.get(`${o}-${s}`);
- if (!a)
- return;
- const u = this._ruleModel.getRule(e, t, a);
- if (u) {
- const h = {
- ...this._getSelectionActions(e, t, u),
- ruleId: a,
- ranges: u.ranges
- };
- return r.set(`${o}-${s}`, h), h;
- }
- }
- deleteUnit(e) {
- this._cellRuleCache.delete(e), this._cellInfoCache.delete(e), this._rowInfoCache.delete(e), this._colInfoCache.delete(e);
- const t = this._univerInstanceService.getUnit(e);
- t == null || t.getSheets().forEach((o) => {
- const s = o.getSheetId();
- this._ruleModel.getSubunitRuleList(e, s).forEach((r) => {
- this._permissionIdCache.delete(r.permissionId);
- });
- });
- }
- };
- ht = Fc([
- no(0, ot(de)),
- no(1, ot(UE)),
- no(2, ot(_n))
- ], ht);
- var jc = Object.defineProperty;
- var Gc = Object.getOwnPropertyDescriptor;
- var zc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Gc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && jc(e, t, s), s;
- };
- var Ee = (n, e) => (t, o) => e(t, o, n);
- var On = class extends nt {
- constructor(n, e, t, o, s, r, i, a, u, l, c) {
- super(), this._univerInstanceService = n, this._permissionService = e, this._authzIoService = t, this._rangeProtectionRuleModel = o, this._worksheetProtectionRuleModel = s, this._userManagerService = r, this._worksheetProtectionPointRuleModel = i, this._sheetInterceptorService = a, this._undoRedoService = u, this._commandService = l, this._rangeProtectionCache = c, this._initRangePermissionFromSnapshot(), this._initRangePermissionChange(), this._initWorksheetPermissionFromSnapshot(), this._initWorksheetPermissionChange(), this._initWorksheetPermissionPointsChange(), this._initWorkbookPermissionFromSnapshot(), this._initUserChange(), this._refreshPermissionByCollaCreate();
- }
- async _initRangePermissionFromSnapshot() {
- const n = async (e) => {
- const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map();
- if (s.forEach((i) => {
- const a = i.getSheetId();
- this._rangeProtectionRuleModel.getSubunitRuleList(o, a).forEach((u) => {
- r.set(u.permissionId, u), t.push({
- objectID: u.permissionId,
- unitID: o,
- objectType: D.SelectRange,
- actions: it
- });
- });
- }), !t.length) {
- this._rangeProtectionRuleModel.changeRuleInitState(true);
- return;
- }
- this._authzIoService.batchAllowed(t).then((i) => {
- i.forEach((a) => {
- const u = r.get(a.objectID);
- u && Ie().forEach((l) => {
- const c = new l(o, u.subUnitId, a.objectID), d = c.subType, h = a.actions.find((m) => m.action === d);
- (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed);
- });
- }), this._rangeProtectionRuleModel.changeRuleInitState(true);
- });
- };
- await Promise.all(this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).map((e) => n(e))), this._rangeProtectionRuleModel.changeRuleInitState(true);
- }
- _initRangePermissionChange() {
- this.disposeWithMe(
- this._rangeProtectionRuleModel.ruleChange$.subscribe((n) => {
- n.type !== "delete" ? this._authzIoService.allowed({
- objectID: n.rule.permissionId,
- unitID: n.unitId,
- objectType: D.SelectRange,
- actions: it
- }).then((e) => {
- Ie().forEach((t) => {
- if (n.type === "set") {
- const { rule: a, oldRule: u } = n;
- if (a.permissionId === (u == null ? void 0 : u.permissionId))
- return;
- }
- const o = n.rule, s = new t(o.unitId, o.subUnitId, o.permissionId), r = s.subType, i = e.find((a) => a.action === r);
- i && this._permissionService.updatePermissionPoint(s.id, i.allowed);
- }), this._rangeProtectionRuleModel.ruleRefresh(n.rule.permissionId);
- }) : this._rangeProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId), [...ke()].forEach((t) => {
- const o = new t(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(o.id, o.value);
- }));
- })
- );
- }
- async initWorkbookPermissionChange(n) {
- var t;
- const e = n || ((t = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET)) == null ? void 0 : t.getUnitId());
- e && this._authzIoService.allowed({
- objectID: e,
- objectType: D.Workbook,
- unitID: e,
- actions: fl2
- }).then((o) => {
- en2().forEach((s) => {
- const r = new s(e), i = r.subType, a = o.find((u) => u.action === i);
- a && this._permissionService.updatePermissionPoint(r.id, a.allowed);
- });
- });
- }
- async _initWorkbookPermissionFromSnapshot() {
- await Promise.all(this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).map((n) => this.initWorkbookPermissionChange(n.getUnitId())));
- }
- _initWorksheetPermissionChange() {
- this.disposeWithMe(
- this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => {
- n.type !== "delete" ? this._authzIoService.allowed({
- objectID: n.rule.permissionId,
- unitID: n.unitId,
- objectType: D.Worksheet,
- actions: it
- }).then((e) => {
- we2().forEach((t) => {
- const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s);
- r && this._permissionService.updatePermissionPoint(o.id, r.allowed);
- }), this._worksheetProtectionRuleModel.ruleRefresh(n.rule.permissionId);
- }) : ([...we2(), ...ke()].forEach((e) => {
- const t = new e(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(t.id, true);
- }), this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId));
- })
- );
- }
- _initWorksheetPermissionPointsChange() {
- this.disposeWithMe(
- this._worksheetProtectionPointRuleModel.pointChange$.subscribe((n) => {
- this._authzIoService.allowed({
- objectID: n.permissionId,
- unitID: n.unitId,
- objectType: D.Worksheet,
- actions: eo
- }).then((e) => {
- ke().forEach((t) => {
- const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s);
- r && this._permissionService.updatePermissionPoint(o.id, r.allowed);
- });
- });
- })
- );
- }
- async _initWorksheetPermissionFromSnapshot() {
- const n = async (e) => {
- const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map();
- if (s.forEach((i) => {
- const a = i.getSheetId(), u = this._worksheetProtectionRuleModel.getRule(o, a);
- u && (r.set(u.permissionId, u), t.push({
- objectID: u.permissionId,
- unitID: o,
- objectType: D.Worksheet,
- actions: it
- }));
- const l = this._worksheetProtectionPointRuleModel.getRule(o, a);
- l && (r.set(l.permissionId, l), t.push({
- objectID: l.permissionId,
- unitID: o,
- objectType: D.Worksheet,
- actions: eo
- }));
- }), !t.length) {
- this._worksheetProtectionRuleModel.changeRuleInitState(true);
- return;
- }
- this._authzIoService.batchAllowed(t).then((i) => {
- i.forEach((a) => {
- const u = r.get(a.objectID);
- u && [...we2(), ...ke()].forEach((l) => {
- const c = new l(o, u.subUnitId), d = c.subType, h = a.actions.find((m) => m.action === d);
- (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed);
- });
- }), this._worksheetProtectionRuleModel.changeRuleInitState(true);
- });
- };
- await Promise.all(this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).map((e) => n(e))), this._worksheetProtectionRuleModel.changeRuleInitState(true);
- }
- _initUserChange() {
- this.disposeWithMe(
- // When the user changes, the permission points are updated. The first modification needs to be filtered here because it is a Behavior type, but in fact the user information is ready when this controller is initialized.
- this._userManagerService.currentUser$.pipe(skip(1)).subscribe(() => {
- const n = this._permissionService.getAllPermissionPoint();
- this._permissionService.clearPermissionMap(), this._worksheetProtectionRuleModel.changeRuleInitState(false), this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((t) => {
- const o = t.getUnitId();
- en2().forEach((s) => {
- let r = new s(o);
- n.has(r.id) && (r = n.get(r.id)), this._permissionService.addPermissionPoint(r);
- }), t.getSheets().forEach((s) => {
- const r = s.getSheetId();
- [...we2(), ...ke()].forEach((a) => {
- let u = new a(o, r);
- n.has(u.id) && (u = n.get(u.id)), this._permissionService.addPermissionPoint(u);
- }), this._rangeProtectionRuleModel.getSubunitRuleList(o, r).forEach((a) => {
- Ie().forEach((u) => {
- let l = new u(o, r, a.permissionId);
- n.has(l.id) && (l = n.get(l.id)), this._permissionService.addPermissionPoint(l);
- });
- });
- }), this._initWorkbookPermissionFromSnapshot(), this._initWorksheetPermissionFromSnapshot(), this._initRangePermissionFromSnapshot();
- });
- })
- );
- }
- refreshPermission(n, e) {
- const t = this._worksheetProtectionRuleModel.getTargetByPermissionId(n, e);
- let o = false;
- if (t) {
- const [i, a] = t;
- this._authzIoService.allowed({
- objectID: e,
- unitID: n,
- objectType: D.Worksheet,
- actions: it
- }).then((u) => {
- let l = "";
- we2().forEach((c) => {
- var g2;
- const d = new c(n, a), h = d.subType, m = u.find((f) => f.action === h);
- m && (((g2 = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g2.value) !== m.allowed && (o = true), this._permissionService.updatePermissionPoint(d.id, m.allowed), l += `${m.action}_${m.allowed}`);
- }), this._worksheetProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n);
- });
- }
- const s = this._worksheetProtectionPointRuleModel.getTargetByPermissionId(n, e);
- if (s) {
- const [i, a] = s;
- this._authzIoService.allowed({
- objectID: e,
- unitID: n,
- objectType: D.Worksheet,
- actions: eo
- }).then((u) => {
- ke().forEach((l) => {
- var m;
- const c = new l(n, a), d = c.subType, h = u.find((g2) => g2.action === d);
- h && (((m = this._permissionService.getPermissionPoint(c.id)) == null ? void 0 : m.value) !== h.allowed && (o = true), this._permissionService.updatePermissionPoint(c.id, h.allowed));
- }), o && this._undoRedoService.clearUndoRedo(n);
- });
- }
- const r = this._rangeProtectionRuleModel.getTargetByPermissionId(n, e);
- if (r) {
- const [i, a] = r;
- this._authzIoService.allowed({
- objectID: e,
- unitID: n,
- objectType: D.SelectRange,
- actions: it
- }).then((u) => {
- let l = "";
- Ie().forEach((c) => {
- var g2;
- const d = new c(n, a, e), h = d.subType, m = u.find((f) => f.action === h);
- m && (((g2 = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g2.value) !== m.allowed && (o = true), this._permissionService.updatePermissionPoint(d.id, m.allowed), l += `${m.action}_${m.allowed}`);
- }), this._rangeProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n);
- });
- }
- }
- _refreshPermissionByCollaCreate() {
- this.disposeWithMe(
- this._commandService.onCommandExecuted((n, e) => {
- if (e != null && e.fromCollab && (n.id === Ne.id || n.id === ct.id || n.id === Ao.id)) {
- const t = n.params;
- this._undoRedoService.clearUndoRedo(t.unitId);
- }
- })
- );
- }
- };
- On = zc([
- Ee(0, _n),
- Ee(1, UE),
- Ee(2, bE),
- Ee(3, ot(de)),
- Ee(4, ot(Ye)),
- Ee(5, ot(rr)),
- Ee(6, ot(un)),
- Ee(7, ot(V)),
- Ee(8, ot(cn)),
- Ee(9, ot(Pt)),
- Ee(10, ot(ht))
- ], On);
- var Kc = Object.defineProperty;
- var Jc = Object.getOwnPropertyDescriptor;
- var Yc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Jc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Kc(e, t, s), s;
- };
- var hn = (n, e) => (t, o) => e(t, o, n);
- var Dn = class extends nt {
- constructor(n, e, t, o) {
- super(), this._permissionService = n, this._worksheetProtectionRuleModel = e, this._sheetInterceptorService = t, this._rangeProtectionCache = o, this._initViewModelByRangeInterceptor(), this._initViewModelBySheetInterceptor();
- }
- _initViewModelByRangeInterceptor() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(
- et.CELL_CONTENT,
- {
- // permissions are placed at a high level to prioritize whether to filter subsequent renderings.
- priority: 999,
- effect: Vn.Value | Vn.Style,
- handler: (n = {}, e, t) => {
- const { unitId: o, subUnitId: s, row: r, col: i } = e, a = this._rangeProtectionCache.getCellInfo(o, s, r, i);
- if (a) {
- const u = a[_.View] === false, l = { ...n, selectionProtection: [a] };
- return u ? (delete l.s, delete l.v, delete l.p, l) : t(l);
- }
- return t(n);
- }
- }
- ));
- }
- _initViewModelBySheetInterceptor() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(
- et.CELL_CONTENT,
- {
- // permissions are placed at a high level to prioritize whether to filter subsequent renderings.
- priority: 999,
- effect: Vn.Value | Vn.Style,
- handler: (n = {}, e, t) => {
- var i, a, u, l, c;
- const { unitId: o, subUnitId: s } = e, r = this._worksheetProtectionRuleModel.getRule(o, s);
- if (r != null && r.permissionId) {
- const d = [{
- [_.View]: (a = (i = this._permissionService.getPermissionPoint(new Hn(o, s).id)) == null ? void 0 : i.value) != null ? a : false,
- [_.Edit]: (l = (u = this._permissionService.getPermissionPoint(new Te(o, s).id)) == null ? void 0 : u.value) != null ? l : false
- }], h = !((c = d[0]) != null && c[_.View]), m = { ...n, hasWorksheetRule: true, selectionProtection: d };
- return h ? (delete m.s, delete m.v, delete m.p, m) : t(m);
- }
- return t(n);
- }
- }
- ));
- }
- };
- Dn = Yc([
- hn(0, UE),
- hn(1, ot(Ye)),
- hn(2, ot(V)),
- hn(3, ot(ht))
- ], Dn);
- var Xc = Object.defineProperty;
- var qc = Object.getOwnPropertyDescriptor;
- var Zc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? qc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Xc(e, t, s), s;
- };
- var cs2 = (n, e) => (t, o) => e(t, o, n);
- var tn = class {
- constructor(n, e) {
- R(this, "_cache", new Qr(1e4));
- this._selectionProtectionRuleModel = n, this._permissionService = e, this._init();
- }
- _init() {
- this._permissionService.permissionPointUpdate$.pipe(
- filter((n) => n.type === D.SelectRange),
- filter((n) => Ie().some((e) => n instanceof e)),
- map((n) => n)
- ).subscribe((n) => {
- const e = this._selectionProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId);
- for (const t of e)
- t.permissionId === n.permissionId && t.ranges.forEach((o) => {
- tr.foreach(o, (s, r) => {
- const i = this._createKey(n.unitId, n.subUnitId, s, r);
- this._cache.delete(i);
- });
- });
- }), this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => {
- var e;
- n.rule.ranges.forEach((t) => {
- tr.foreach(t, (o, s) => {
- const r = this._createKey(n.unitId, n.subUnitId, o, s);
- this._cache.delete(r);
- });
- }), n.type === "set" && ((e = n.oldRule) == null || e.ranges.forEach((t) => {
- tr.foreach(t, (o, s) => {
- const r = this._createKey(n.unitId, n.subUnitId, o, s);
- this._cache.delete(r);
- });
- }));
- });
- }
- _createKey(n, e, t, o) {
- return `${n}_${e}_${t}_${o}`;
- }
- getCellInfo(n, e, t, o) {
- const s = this._selectionProtectionRuleModel.getSubunitRuleList(n, e), r = [];
- if (!s || !s.length)
- return r;
- const i = this._createKey(n, e, t, o), a = this._cache.get(i);
- if (a)
- return a;
- const u = [];
- for (const l of s)
- if (l.ranges.some((c) => c.startRow <= t && c.endRow >= t && c.startColumn <= o && c.endColumn >= o)) {
- const c = Ie().reduce((d, h) => {
- var f;
- const m = new h(n, e, l.permissionId), g2 = this._permissionService.getPermissionPoint(m.id);
- return d[m.subType] = (f = g2 == null ? void 0 : g2.value) != null ? f : m.value, d;
- }, {});
- u.push({ ...c, ruleId: l.id, ranges: l.ranges });
- }
- return this._cache.set(i, u), u;
- }
- clear() {
- this._cache.clear();
- }
- };
- tn = Zc([
- cs2(0, ot(de)),
- cs2(1, ot(UE))
- ], tn);
- var ds = Ct("univer.exclusive-range-service");
- var Qc = class extends nt {
- constructor() {
- super(...arguments);
- R(this, "_exclusiveRanges", /* @__PURE__ */ new Map());
- R(this, "_exclusiveRangesChange$", new Subject());
- R(this, "exclusiveRangesChange$", this._exclusiveRangesChange$.asObservable());
- }
- _ensureUnitMap(t) {
- return this._exclusiveRanges.has(t) || this._exclusiveRanges.set(t, /* @__PURE__ */ new Map()), this._exclusiveRanges.get(t);
- }
- _ensureSubunitMap(t, o) {
- const s = this._ensureUnitMap(t);
- return s.has(o) || s.set(o, /* @__PURE__ */ new Map()), s.get(o);
- }
- _ensureFeature(t, o, s) {
- const r = this._ensureSubunitMap(t, o);
- return r.has(s) || r.set(s, []), r.get(s);
- }
- addExclusiveRange(t, o, s, r) {
- const i = this._ensureFeature(t, o, s);
- i.push(...r), this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: i.map((a) => a.range) });
- }
- getExclusiveRanges(t, o, s) {
- var r, i;
- return (i = (r = this._exclusiveRanges.get(t)) == null ? void 0 : r.get(o)) == null ? void 0 : i.get(s);
- }
- clearExclusiveRanges(t, o, s) {
- const r = this.getExclusiveRanges(t, o, s);
- this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (r == null ? void 0 : r.map((i) => i.range)) || [] }), this._ensureFeature(t, o, s), this._exclusiveRanges.get(t).get(o).set(s, []);
- }
- clearExclusiveRangesByGroupId(t, o, s, r) {
- const i = this.getExclusiveRanges(t, o, s);
- this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (i == null ? void 0 : i.map((u) => u.range)) || [] });
- const a = this.getExclusiveRanges(t, o, s);
- if (a) {
- const u = a.filter((l) => l.groupId !== r);
- this._exclusiveRanges.get(t).get(o).set(s, u);
- }
- }
- getInterestGroupId(t) {
- const o = [];
- return t.forEach((s) => {
- var l;
- const r = s.range, { unitId: i, sheetId: a } = r;
- if (!i || !a)
- return;
- const u = (l = this._exclusiveRanges.get(i)) == null ? void 0 : l.get(a);
- if (u)
- for (const c of u.keys()) {
- const d = u.get(c);
- if (d) {
- for (const h of d)
- if (en.intersects(r, h.range)) {
- o.push(c);
- break;
- }
- }
- }
- }), o;
- }
- };
- var ed = Object.defineProperty;
- var td = Object.getOwnPropertyDescriptor;
- var nd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? td(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && ed(e, t, s), s;
- };
- var oo = (n, e) => (t, o) => e(t, o, n);
- var co = class extends nt {
- constructor(n, e, t) {
- super(), this._resourceManagerService = n, this._univerInstanceService = e, this._logService = t;
- }
- getValue(n, e, t, o) {
- const s = this._univerInstanceService.getUniverSheetInstance(n);
- if (!s)
- return;
- const r = s == null ? void 0 : s.getSheetBySheetId(e);
- if (!r)
- return;
- const i = s.getStyles(), a = r.getCellRaw(t, o);
- if (a != null && a.s) {
- const u = i.get(a.s);
- if (u != null && u.n)
- return u.n;
- }
- return null;
- }
- deleteValues(n, e, t) {
- const o = this._univerInstanceService.getUniverSheetInstance(n);
- if (!o)
- return;
- const s = o == null ? void 0 : o.getSheetBySheetId(e);
- if (!s)
- return;
- const r = o.getStyles();
- t.forEach((i) => {
- tr.foreach(i, (a, u) => {
- const l = s.getCellRaw(a, u);
- if (!l)
- return;
- const c = l == null ? void 0 : l.s, h = { ...c && r.get(c) || {} };
- delete h.n;
- const m = r.setValue(h);
- l.s = m;
- });
- });
- }
- setValues(n, e, t) {
- const o = this._univerInstanceService.getUniverSheetInstance(n);
- if (!o)
- return;
- const s = o == null ? void 0 : o.getSheetBySheetId(e);
- if (!s)
- return;
- const r = o.getStyles(), i = s.getCellMatrix();
- t.forEach((a) => {
- a.ranges.forEach((u) => {
- tr.foreach(u, (l, c) => {
- const d = s.getCellRaw(l, c);
- if (d) {
- const m = { ...r.getStyleByCell(d) || {}, n: { pattern: a.pattern } }, g2 = r.setValue(m);
- d.s = g2, a.pattern === T && (d.t = dn.STRING);
- } else {
- const h = { n: { pattern: a.pattern } }, m = r.setValue(h);
- m && i.setValue(l, c, { s: m });
- }
- });
- });
- });
- }
- };
- co = nd([
- oo(0, Bi),
- oo(1, _n),
- oo(2, Mt)
- ], co);
- var od = Object.defineProperty;
- var sd = Object.getOwnPropertyDescriptor;
- var rd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? sd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && od(e, t, s), s;
- };
- var Qe = (n, e) => (t, o) => e(t, o, n);
- var hs = [je.id, qe.id, De2.id, Be.id];
- var ms = [ot2.id, st2.id];
- var An = class extends nt {
- constructor(e, t, o, s, r, i, a, u) {
- super();
- R(this, "disposableCollection", new Mi());
- this._selectionProtectionRuleModel = e, this._univerInstanceService = t, this._commandService = o, this._refRangeService = s, this._selectionProtectionRenderModel = r, this._rangeProtectionCache = i, this._sheetInterceptorService = a, this._rangeProtectionRuleModel = u, this._onRefRangeChange(), this._correctPermissionRange(), this._initReBuildCache(), this._initRemoveSheet();
- }
- _onRefRangeChange() {
- const e = (o, s) => {
- const r = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!r || !(r == null ? void 0 : r.getSheetBySheetId(s)))
- return;
- this.disposableCollection.dispose();
- const a = (l) => this.refRangeHandle(l, o, s);
- this._selectionProtectionRuleModel.getSubunitRuleList(o, s).reduce((l, c) => [...l, ...c.ranges], []).forEach((l) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(l, a, o, s));
- });
- };
- this.disposeWithMe(
- this._commandService.onCommandExecuted((o) => {
- if (o.id === Ar.id) {
- const s = o.params, r = s.subUnitId, i = s.unitId;
- if (!r || !i)
- return;
- e(i, r);
- }
- if (o.id === he.id || o.id === Ne.id) {
- const s = o.params, r = s.subUnitId, i = s.unitId;
- if (!r || !i)
- return;
- e(i, r);
- }
- })
- );
- const t = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (t) {
- const o = t.getActiveSheet();
- if (!o)
- return;
- e(t.getUnitId(), o.getSheetId());
- }
- }
- refRangeHandle(e, t, o) {
- switch (e.id) {
- case Fn.id:
- return this._getRefRangeMutationsByMoveRows(e.params, t, o);
- case jn.id:
- return this._getRefRangeMutationsByMoveCols(e.params, t, o);
- case mt.id:
- return this._getRefRangeMutationsByInsertRows(e.params, t, o);
- case gt.id:
- return this._getRefRangeMutationsByInsertCols(e.params, t, o);
- case zn2.id:
- return this._getRefRangeMutationsByDeleteCols(e.params, t, o);
- case Gn.id:
- return this._getRefRangeMutationsByDeleteRows(e.params, t, o);
- }
- return { redos: [], undos: [] };
- }
- _getRefRangeMutationsByDeleteCols(e, t, o) {
- const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => en.intersects(a, e.range))), r = e.range;
- if (s.length) {
- const i = [], a = [];
- return s.forEach((u) => {
- const l = re.deepClone(u), c = l.ranges.reduce((d, h) => {
- if (en.intersects(h, r)) {
- const m = re.deepClone(h), { startColumn: g2, endColumn: f } = r;
- if (g2 <= m.startColumn && f >= m.endColumn)
- return d;
- g2 >= m.startColumn && f <= m.endColumn ? m.endColumn -= f - g2 + 1 : g2 < m.startColumn ? (m.startColumn = g2, m.endColumn -= f - g2 + 1) : f > m.endColumn && (m.endColumn = g2 - 1), this._checkIsRightRange(m) && d.push(m);
- }
- return d;
- }, []);
- l.ranges = c, l.ranges.length ? (i.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: u.id } }), a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: u, ruleId: u.id } })) : (i.push({ id: ze.id, params: { unitId: t, subUnitId: o, ruleIds: [u.id] } }), a.push({ id: Ne.id, params: { unitId: t, subUnitId: o, name: "", rules: [u] } }));
- }), { redos: i, undos: a };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByDeleteRows(e, t, o) {
- const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => en.intersects(a, e.range))), r = e.range;
- if (s.length) {
- const i = [], a = [];
- return s.forEach((u) => {
- const l = re.deepClone(u), c = l.ranges.reduce((d, h) => {
- if (en.intersects(h, r)) {
- const m = re.deepClone(h), { startRow: g2, endRow: f } = r;
- if (g2 <= m.startRow && f >= m.endRow)
- return d;
- g2 >= m.startRow && f <= m.endRow ? m.endRow -= f - g2 + 1 : g2 < m.startRow ? (m.startRow = g2, m.endRow -= f - g2 + 1) : f > m.endRow && (m.endRow = g2 - 1), this._checkIsRightRange(m) && d.push(m);
- }
- return d;
- }, []);
- l.ranges = c, i.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: u.id } }), a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: u, ruleId: u.id } });
- }), { redos: i, undos: a };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByInsertCols(e, t, o) {
- const s = e.range.startColumn, r = e.range.endColumn - e.range.startColumn + 1, i = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((a) => a.ranges.some((u) => s > u.startColumn && s <= u.endColumn));
- if (i.length) {
- const a = [], u = [];
- return i.forEach((l) => {
- const c = re.deepClone(l);
- let d = false;
- c.ranges.forEach((h) => {
- s > h.startColumn && s <= h.endColumn && (h.endColumn += r, d = true);
- }), d && (a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: l.id } }), u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: l.id } }));
- }), { redos: a, undos: u };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByInsertRows(e, t, o) {
- const s = e.range.startRow, r = e.range.endRow - e.range.startRow + 1, i = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((a) => a.ranges.some((u) => s > u.startRow && s <= u.endRow));
- if (i.length) {
- const a = [], u = [];
- return i.forEach((l) => {
- const c = re.deepClone(l);
- let d = false;
- c.ranges.forEach((h) => {
- s > h.startRow && s <= h.endRow && (h.endRow += r, d = true);
- }), d && (a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: l.id } }), u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: l.id } }));
- }), { redos: a, undos: u };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByMoveRows(e, t, o) {
- const s = e.toRange, r = s.startRow, i = s.endRow - s.startRow + 1, a = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((u) => u.ranges.some((l) => r > l.startRow && r <= l.endRow));
- if (a.length) {
- const u = [], l = [];
- return a.forEach((c) => {
- const d = re.deepClone(c), m = e.fromRange.startRow;
- let g2 = false;
- d.ranges.forEach((f) => {
- r > f.startRow && r <= f.endRow && (m < f.startRow && (f.startRow = f.startRow - i, f.endRow = f.endRow - i), f.endRow += i, g2 = true);
- }), g2 && (u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: d, ruleId: c.id } }), l.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: c.id } }));
- }), { redos: u, undos: l };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByMoveCols(e, t, o) {
- const s = e.toRange, r = s.startColumn, i = s.endColumn - s.startColumn + 1, a = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((u) => u.ranges.some((l) => r > l.startColumn && r <= l.endColumn));
- if (a.length) {
- const u = [], l = [];
- return a.forEach((c) => {
- const d = re.deepClone(c), m = e.fromRange.startColumn;
- let g2 = false;
- d.ranges.forEach((f) => {
- r > f.startColumn && r <= f.endColumn && (m < f.startColumn && (f.startColumn = f.startColumn - i, f.endColumn = f.endColumn - i), f.endColumn += i, g2 = true);
- }), g2 && (u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: d, ruleId: c.id } }), l.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: c.id } }));
- }), { redos: u, undos: l };
- }
- return { undos: [], redos: [] };
- }
- _correctPermissionRange() {
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
- if (ms.includes(e.id)) {
- if (!e.params)
- return;
- const t = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!t)
- return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o)
- return;
- const { sourceRange: s, targetRange: r } = e.params, i = s.startColumn === r.startColumn && s.endColumn === r.endColumn, a = i ? s.endRow - s.startRow + 1 : s.endColumn - s.startColumn + 1, u = i ? s.startRow : s.startColumn, l = i ? r.startRow : r.startColumn;
- this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((f) => {
- f.ranges.forEach((C) => {
- let { startRow: S, endRow: I, startColumn: w, endColumn: b } = C;
- en.intersects(C, s) || (i ? u < S && l > I ? (S -= a, I -= a) : u > I && l <= S && (S += a, I += a) : u < w && l > b ? (w -= a, b -= a) : u > b && l <= w && (w += a, b += a)), this._checkIsRightRange({ startRow: S, endRow: I, startColumn: w, endColumn: b }) && (C.startColumn = w, C.endColumn = b, C.startRow = S, C.endRow = I);
- });
- }), this.disposableCollection.dispose();
- const { unitId: d, subUnitId: h } = e.params, m = (f) => this.refRangeHandle(f, d, h);
- this._selectionProtectionRuleModel.getSubunitRuleList(d, h).reduce((f, p) => [...f, ...p.ranges], []).forEach((f) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(f, m, d, h));
- }), this._selectionProtectionRenderModel.clear();
- }
- if (hs.includes(e.id)) {
- const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
- if (!t)
- return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o)
- return;
- const s = e.params;
- if (!s)
- return;
- const { range: r } = s, i = e.id.includes("row"), a = e.id.includes("insert"), u = i ? r.startRow : r.startColumn, l = i ? r.endRow : r.endColumn, c = l - u + 1;
- this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((p) => {
- p.ranges.forEach((S) => {
- let { startRow: I, endRow: w, startColumn: b, endColumn: y } = S;
- a ? i ? u <= I && (I += c, w += c) : u <= b && (b += c, y += c) : i ? l < I && (I -= c, w -= c) : l < b && (b -= c, y -= c), this._checkIsRightRange({ startRow: I, endRow: w, startColumn: b, endColumn: y }) && (S.startColumn = b, S.endColumn = y, S.startRow = I, S.endRow = w);
- });
- }), this.disposableCollection.dispose();
- const { unitId: h, subUnitId: m } = e.params, g2 = (p) => this.refRangeHandle(p, h, m);
- this._selectionProtectionRuleModel.getSubunitRuleList(h, m).reduce((p, C) => [...p, ...C.ranges], []).forEach((p) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(p, g2, h, m));
- }), this._selectionProtectionRenderModel.clear();
- }
- }));
- }
- _checkIsRightRange(e) {
- return e.startRow <= e.endRow && e.startColumn <= e.endColumn;
- }
- _initReBuildCache() {
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
- if (hs.includes(e.id) || ms.includes(e.id)) {
- const { unitId: t, subUnitId: o } = e.params;
- this._rangeProtectionCache.reBuildCache(t, o);
- }
- }));
- }
- _initRemoveSheet() {
- this._sheetInterceptorService.interceptCommand(
- {
- getMutations: (e) => {
- const t = [], o = [], s = [], r = [];
- if (e.id === ko.id) {
- const i = e.params, a = [], u = [];
- this._rangeProtectionRuleModel.getSubunitRuleList(i.unitId, i.subUnitId).forEach((l) => {
- a.push(l.id), u.push(l);
- }), a.length && u.length && (s.push({ id: ze.id, params: { unitId: i.unitId, subUnitId: i.subUnitId, ruleIds: a } }), t.push({ id: Ne.id, params: { unitId: i.unitId, subUnitId: i.subUnitId, name: "", rules: u } }));
- }
- return {
- redos: o,
- undos: t,
- preRedos: s,
- preUndos: r
- };
- }
- }
- );
- }
- };
- An = rd([
- Qe(0, ot(de)),
- Qe(1, ot(_n)),
- Qe(2, Pt),
- Qe(3, ot(_t)),
- Qe(4, ot(tn)),
- Qe(5, ot(ht)),
- Qe(6, ot(V)),
- Qe(7, ot(de))
- ], An);
- var id = Object.defineProperty;
- var ad = Object.getOwnPropertyDescriptor;
- var ud = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? ad(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && id(e, t, s), s;
- };
- var Dt = (n, e) => (t, o) => e(t, o, n);
- var ld = "SHEET_RANGE_PROTECTION_PLUGIN";
- var xn = class extends nt {
- constructor(n, e, t, o, s) {
- super(), this._selectionProtectionRuleModel = n, this._permissionService = e, this._resourceManagerService = t, this._selectionProtectionCache = o, this._univerInstanceService = s, this._initSnapshot(), this._initRuleChange();
- }
- _initRuleChange() {
- this.disposeWithMe(
- this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => {
- switch (n.type) {
- case "add": {
- Ie().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId, n.rule.permissionId);
- this._permissionService.addPermissionPoint(t);
- });
- break;
- }
- case "delete": {
- Ie().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId, n.rule.permissionId);
- this._permissionService.deletePermissionPoint(t.id);
- });
- break;
- }
- case "set": {
- n.oldRule.permissionId !== n.rule.permissionId && Ie().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId, n.oldRule.permissionId);
- this._permissionService.deletePermissionPoint(t.id);
- const o = new e(n.unitId, n.subUnitId, n.rule.permissionId);
- this._permissionService.addPermissionPoint(o);
- });
- break;
- }
- }
- })
- );
- }
- _initSnapshot() {
- const n = (t) => {
- const s = this._selectionProtectionRuleModel.toObject()[t];
- return s ? JSON.stringify(s) : "";
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- toJson: n,
- parseJson: e,
- pluginName: ld,
- businesses: [Sn.UNIVER_SHEET],
- onLoad: (t, o) => {
- const s = this._selectionProtectionRuleModel.toObject();
- s[t] = o, this._selectionProtectionRuleModel.fromObject(s);
- const r = [];
- Object.keys(o).forEach((i) => {
- const a = o[i];
- this._selectionProtectionRuleModel.getSubunitRuleList(t, i).forEach((u) => {
- r.push({
- objectID: u.permissionId,
- unitID: t,
- objectType: D.SelectRange,
- actions: it
- });
- }), a.forEach((u) => {
- Ie().forEach((l) => {
- const c = new l(t, i, u.permissionId);
- c.value = false, this._permissionService.addPermissionPoint(c);
- });
- }), this._selectionProtectionCache.reBuildCache(t, i);
- });
- },
- onUnLoad: (t) => {
- this._selectionProtectionCache.deleteUnit(t);
- }
- })
- );
- }
- };
- xn = ud([
- Dt(0, ot(de)),
- Dt(1, ot(UE)),
- Dt(2, ot(Bi)),
- Dt(3, ot(ht)),
- Dt(4, ot(_n))
- ], xn);
- var cd = Object.defineProperty;
- var dd = Object.getOwnPropertyDescriptor;
- var hd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? dd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && cd(e, t, s), s;
- };
- var At = (n, e) => (t, o) => e(t, o, n);
- var $n = class extends nt {
- constructor(n, e, t, o, s) {
- super(), this._permissionService = n, this._univerInstanceService = e, this._rangeProtectionRuleModel = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointModel = s, this._init();
- }
- _init() {
- const n = (e) => {
- const t = e.getUnitId();
- en2().forEach((o) => {
- const s = new o(t);
- this._permissionService.addPermissionPoint(s);
- });
- };
- this._univerInstanceService.getAllUnitsForType(Fe.UNIVER_SHEET).forEach((e) => {
- n(e);
- }), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((e) => {
- n(e);
- })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(Fe.UNIVER_SHEET).subscribe((e) => {
- const t = e.getUnitId();
- e.getSheets().forEach((o) => {
- const s = o.getSheetId();
- this._rangeProtectionRuleModel.getSubunitRuleList(t, s).forEach((i) => {
- [...Ie()].forEach((a) => {
- const u = new a(t, s, i.permissionId);
- this._permissionService.deletePermissionPoint(u.id);
- });
- }), [...we2(), ...ke()].forEach((i) => {
- const a = new i(t, s);
- this._permissionService.deletePermissionPoint(a.id);
- });
- }), en2().forEach((o) => {
- const s = new o(t);
- this._permissionService.deletePermissionPoint(s.id);
- }), this._rangeProtectionRuleModel.deleteUnitModel(t), this._worksheetProtectionPointModel.deleteUnitModel(t), this._worksheetProtectionRuleModel.deleteUnitModel(t);
- }));
- }
- };
- $n = hd([
- At(0, ot(UE)),
- At(1, ot(_n)),
- At(2, ot(de)),
- At(3, ot(Ye)),
- At(4, ot(un))
- ], $n);
- var md = Object.defineProperty;
- var gd = Object.getOwnPropertyDescriptor;
- var fd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? gd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && md(e, t, s), s;
- };
- var Rd = (n, e) => (t, o) => e(t, o, n);
- var ho = class extends nt {
- constructor(n) {
- super(), this._sheetRangeThemeModel = n;
- }
- /**
- * Register a custom range theme style.
- * @param {string} unitId Which unit to register the range theme style.
- * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register.
- */
- registerRangeTheme(n, e) {
- this._sheetRangeThemeModel.registerRangeThemeStyle(n, e);
- }
- /**
- * Get custom register themes name list
- * @returns {string[]} The list of custom register themes name.
- */
- getALLRegisterThemes() {
- return this._sheetRangeThemeModel.getALLRegisteredTheme();
- }
- /**
- * Register range theme style to the range.
- * @param {string} themeName The defined theme name.
- * @param {IRangeThemeRangeInfo} rangeInfo The range info to apply the theme style.
- */
- registerRangeThemeStyle(n, e) {
- this._sheetRangeThemeModel.registerRangeThemeRule(n, e);
- }
- /**
- * Get applied range theme style name.
- * @param {IRangeThemeRangeInfo} rangeInfo The range info to get the applied theme style.
- * @returns {string | undefined} The applied theme style name or not exist.
- */
- getAppliedRangeThemeStyle(n) {
- return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(n);
- }
- /**
- * Get registered build-in range theme style
- */
- getRegisteredRangeThemes() {
- return this._sheetRangeThemeModel.getRegisteredRangeThemes();
- }
- };
- ho = fd([
- Rd(0, ot(He))
- ], ho);
- var Qr2 = Object.defineProperty;
- var pd = Object.getOwnPropertyDescriptor;
- var Cd = (n, e, t) => e in n ? Qr2(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
- var Sd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? pd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Qr2(e, t, s), s;
- };
- var gs = (n, e) => (t, o) => e(t, o, n);
- var ei = (n, e, t) => Cd(n, typeof e != "symbol" ? e + "" : e, t);
- var wd = "SHEET_PLUGIN";
- var Wn = class extends Ra {
- constructor(n = ts, e, t) {
- super(), this._config = n, this._injector = e, this._configService = t;
- const { ...o } = nu(
- {},
- ts,
- this._config
- );
- this._configService.setConfig(Kl, o), this._initConfig(), this._initDependencies();
- }
- _initConfig() {
- var n, e, t;
- (n = this._config) != null && n.onlyRegisterFormulaRelatedMutations && this._configService.setConfig(Kr, true), (e = this._config) != null && e.isRowStylePrecedeColumnStyle && this._configService.setConfig(U0, true), (t = this._config) != null && t.autoHeightForMergedCells && this._configService.setConfig(P0, true);
- }
- _initDependencies() {
- var e;
- const n = [
- // services
- [kt2],
- [F],
- [_t],
- [$n],
- [wt, { useClass: co }],
- [V],
- [ho],
- // controllers
- [yn],
- [Tn],
- [kn],
- [Un],
- // permission
- [bn],
- [Ye],
- [un],
- [Dn],
- [On],
- [Nn],
- // range theme
- [He],
- // range protection
- [tn],
- [de],
- [ht],
- [An],
- [xn],
- [ds, {
- useClass: Qc,
- deps: [F]
- }]
- ];
- (e = this._config) != null && e.notExecuteFormula || n.push([En]), K0(this._injector, kE(n, this._config.override)), Mf(this._injector, [
- [V],
- [xn],
- [ds]
- ]);
- }
- onStarting() {
- Mf(this._injector, [
- [yn],
- [Tn],
- [$n],
- [bn],
- [Dn]
- ]);
- }
- onRendered() {
- Mf(this._injector, [
- [wt],
- [On]
- ]);
- }
- onReady() {
- Mf(this._injector, [
- [En],
- [Un],
- [He],
- [kn],
- [tn],
- [An],
- [_t],
- [Nn]
- ]);
- }
- };
- ei(Wn, "pluginName", wd);
- ei(Wn, "type", Fe.UNIVER_SHEET);
- Wn = Sd([
- OR(Fi),
- gs(1, ot(Ot)),
- gs(2, SE)
- ], Wn);
- var Id = ((n) => (n.SET_WORKSHEET_ROW_HEIGHT = "sheet.mutation.set-worksheet-row-height", n.SET_WORKSHEET_ROW_IS_AUTO_HEIGHT = "sheet.mutation.set-worksheet-row-is-auto-height", n.SET_WORKSHEET_ROW_AUTO_HEIGHT = "sheet.mutation.set-worksheet-row-auto-height", n.SET_WORKSHEET_COL_WIDTH = "sheet.mutation.set-worksheet-col-width", n.SET_WORKSHEET_ACTIVE = "sheet.operation.set-worksheet-active", n.MOVE_ROWS = "sheet.mutation.move-rows", n.MOVE_COLUMNS = "sheet.mutation.move-columns", n.SET_COL_HIDDEN = "sheet.mutation.set-col-hidden", n.SET_COL_VISIBLE = "sheet.mutation.set-col-visible", n.SET_ROW_HIDDEN = "sheet.mutation.set-row-hidden", n.SET_ROW_VISIBLE = "sheet.mutation.set-row-visible", n.INSERT_COL = "sheet.mutation.insert-col", n.INSERT_ROW = "sheet.mutation.insert-row", n.REMOVE_COL = "sheet.mutation.remove-col", n.REMOVE_ROW = "sheet.mutation.remove-row", n.TOGGLE_GRIDLINES = "sheet.mutation.toggle-gridlines", n.SET_GRIDLINES_COLOR = "sheet.mutation.set-gridlines-color", n))(Id || {});
- var vd = ((n) => (n.SET_RANGE_VALUES = "sheet.mutation.set-range-values", n.MOVE_RANGE = "sheet.mutation.move-range", n.REMOVE_WORKSHEET_MERGE = "sheet.mutation.remove-worksheet-merge", n.ADD_WORKSHEET_MERGE = "sheet.mutation.add-worksheet-merge", n.REORDER_RANGE = "sheet.mutation.reorder-range", n.SET_WORKSHEET_DEFAULT_STYLE = "sheet.mutation.set-worksheet-default-style", n.SET_ROW_DATA = "sheet.mutation.set-row-data", n.SET_COL_DATA = "sheet.mutation.set-col-data", n.SET_WORKSHEET_RANGE_THEME_STYLE = "sheet.mutation.set-worksheet-range-theme-style", n.DELETE_WORKSHEET_RANGE_THEME_STYLE = "sheet.mutation.delete-worksheet-range-theme-style", n))(vd || {});
- var gh = [
- nt2.id,
- Oe.id,
- Br.id,
- tt.id,
- an.id,
- ot2.id,
- st2.id,
- Xt2.id,
- qt2.id,
- Qt.id,
- Zt.id,
- je.id,
- qe.id,
- De2.id,
- Be.id,
- Ft.id,
- Vt.id
- ];
- var fh = [
- Q.id,
- dt.id,
- oe.id,
- ne.id,
- In.id,
- Bt.id,
- Ht.id,
- Lt.id,
- zt.id,
- Kt.id
- ];
- function Rh(n) {
- switch (n.id) {
- case "sheet.mutation.set-range-values": {
- const e = n.params;
- return e.cellValue ? [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: new kt(e.cellValue).getDataRange()
- }] : [];
- }
- case "sheet.mutation.move-range": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.from.subUnitId,
- range: new kt(e.from.value).getRange()
- }, {
- unitId: e.unitId,
- subUnitId: e.to.subUnitId,
- range: new kt(e.to.value).getRange()
- }];
- }
- case "sheet.mutation.remove-worksheet-merge": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: t
- }));
- }
- case "sheet.mutation.add-worksheet-merge": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: t
- }));
- }
- case "sheet.mutation.reorder-range": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- }];
- }
- case "sheet.mutation.set-worksheet-default-style": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: { startRow: 0, endRow: Number.MAX_SAFE_INTEGER, startColumn: 0, endColumn: Number.MAX_SAFE_INTEGER }
- }];
- }
- case "sheet.mutation.set-row-data": {
- const e = n.params, t = Object.keys(e.rowData).map(Number);
- return t.length === 0 ? [] : [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- startRow: Math.min(...t),
- endRow: Math.max(...t),
- startColumn: 0,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- }];
- }
- case "sheet.mutation.set-col-data": {
- const e = n.params, t = Object.keys(e.columnData).map(Number);
- return t.length === 0 ? [] : [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- startRow: 0,
- endRow: Number.MAX_SAFE_INTEGER,
- startColumn: Math.min(...t),
- endColumn: Math.max(...t)
- }
- }];
- }
- case "sheet.mutation.set-worksheet-range-theme-style":
- case "sheet.mutation.delete-worksheet-range-theme-style": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- }];
- }
- default:
- return [];
- }
- }
- function ph(n) {
- switch (n.id) {
- case "sheet.mutation.set-worksheet-row-height":
- case "sheet.mutation.set-worksheet-row-is-auto-height":
- case "sheet.mutation.set-worksheet-row-auto-height": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: De.ROW
- }
- }));
- }
- case "sheet.mutation.set-worksheet-col-width": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: De.COLUMN
- }
- }));
- }
- case "sheet.mutation.move-rows":
- case "sheet.mutation.move-columns": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.targetRange
- }, {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.sourceRange
- }];
- }
- case "sheet.mutation.set-col-hidden":
- case "sheet.mutation.set-col-visible": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: De.COLUMN
- }
- }));
- }
- case "sheet.mutation.set-row-hidden":
- case "sheet.mutation.set-row-visible": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: De.ROW
- }
- }));
- }
- case "sheet.mutation.insert-col": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: De.COLUMN
- }
- }];
- }
- case "sheet.mutation.insert-row": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: De.ROW
- }
- }];
- }
- case "sheet.mutation.remove-col": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: De.COLUMN
- }
- }];
- }
- case "sheet.mutation.remove-row": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: De.ROW
- }
- }];
- }
- case "sheet.mutation.toggle-gridlines":
- case "sheet.mutation.set-gridlines-color":
- return [];
- default:
- return [];
- }
- }
- var Ch = 1.5;
- var Sh = "rgba(255, 255, 255, 0.01)";
- function wh(n) {
- const { rangeWithCoord: e, primaryWithCoord: t, style: o } = n, s = {
- range: {
- startRow: e.startRow,
- startColumn: e.startColumn,
- endRow: e.endRow,
- endColumn: e.endColumn,
- rangeType: e.rangeType,
- unitId: e.unitId,
- sheetId: e.sheetId
- },
- primary: null,
- style: o
- };
- return t != null && (s.primary = Md(t)), s;
- }
- function Md(n) {
- const { actualRow: e, actualColumn: t, isMerged: o, isMergedMainCell: s } = n, { startRow: r, startColumn: i, endRow: a, endColumn: u } = n.mergeInfo;
- return {
- actualRow: e,
- actualColumn: t,
- isMerged: o,
- isMergedMainCell: s,
- startRow: r,
- startColumn: i,
- endRow: a,
- endColumn: u
- };
- }
- var Ih = (n, e, t) => {
- const s = n.get(F).getCurrentSelections(), { value: r, selections: i, unitId: a, subUnitId: u } = e;
- if (s) {
- const c = s[(s == null ? void 0 : s.length) - 1].primary;
- if (c) {
- const { actualColumn: d, actualRow: h } = c;
- let { startRow: m, startColumn: g2, endRow: f, endColumn: p } = i[i.length - 1];
- if (r === yu.COLUMNS) {
- const w = t.find((b) => b.startColumn === d && b.endColumn === d && h === b.startRow);
- w && (p = w.endColumn, m = w.startRow, f = w.endRow);
- } else if (r === yu.ROWS) {
- const w = t.find((b) => b.startRow === h && b.endRow === h && d === b.startColumn);
- w && (f = w.endRow, g2 = w.startColumn, p = w.endColumn);
- }
- const C = {
- startRow: m,
- startColumn: g2,
- endRow: f,
- endColumn: p,
- actualRow: h,
- actualColumn: d,
- isMerged: true,
- isMergedMainCell: m === h && g2 === d
- }, S = s.map((w, b, y) => ({
- range: w.range,
- style: null,
- primary: b === y.length - 1 ? C : null
- })), I = {
- unitId: a,
- subUnitId: u,
- type: Ce.ONLY_SET,
- selections: S
- };
- return {
- id: re2.id,
- params: I
- };
- }
- return null;
- }
- return null;
- };
- var vh = (n, e) => {
- const o = n.get(F).getCurrentSelections(), { unitId: s, subUnitId: r } = e;
- if (o && o[(o == null ? void 0 : o.length) - 1].primary) {
- const u = {
- unitId: s,
- subUnitId: r,
- type: Ce.ONLY_SET,
- selections: [...o]
- };
- return {
- id: re2.id,
- params: u
- };
- }
- return null;
- };
- function fs2(n) {
- return n == null ? false : n.v !== void 0 && n.v !== null && n.v !== "" || n.p !== void 0;
- }
- function Yn(n, e) {
- return n && n.spanAnchor ? fs2(e.getValue(n.spanAnchor.startRow, n.spanAnchor.startColumn)) : fs2(n);
- }
- function _d(n, e, t, o, s) {
- const r = n.getCellMatrix(), i = n.getSpanModel().getMergedCellRange(e, t, o, s), a = new kt();
- return r.forValue((u, l) => {
- const c = r.getValue(u, l);
- c && a.setValue(u, l, c);
- }), i.forEach((u) => {
- const { startColumn: l, startRow: c, endColumn: d, endRow: h } = u;
- Qo(c, h, l, d).forEach((m, g2) => {
- m === c && g2 === l && a.setValue(m, g2, {
- ...r.getValue(m, g2),
- spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d }
- }), (m !== c || g2 !== l) && (a.realDeleteValue(m, g2), a.setValue(m, g2, {
- spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d }
- }));
- });
- }), a;
- }
- function bd(n, e, t, o) {
- const { startRow: s, startColumn: r, endRow: i } = n;
- let a = null, u = false;
- for (let l = s; l <= i; l++) {
- const c = e.getValue(l, r - t);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.startColumn = n.startColumn - t, {
- spanAnchor: a,
- hasValue: true,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: false,
- range: n
- };
- }
- function yd(n, e, t, o) {
- const { startRow: s, endColumn: r, endRow: i } = n;
- let a = null, u = false;
- for (let l = s; l <= i; l++) {
- const c = e.getValue(l, r + t);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.endColumn = n.endColumn + t, {
- spanAnchor: a,
- hasValue: true,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: false,
- range: n
- };
- }
- function Ed(n, e, t, o) {
- const { startRow: s, startColumn: r, endColumn: i } = n;
- let a = null, u = false;
- for (let l = r; l <= i; l++) {
- const c = e.getValue(s - t, l);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.startRow = n.startRow - t, {
- spanAnchor: a,
- hasValue: true,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: false,
- range: n
- };
- }
- function Ud(n, e, t, o) {
- const { startColumn: s, endColumn: r, endRow: i } = n;
- let a = null, u = false;
- for (let l = s; l <= r; l++) {
- const c = e.getValue(i + t, l);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.endRow = n.endRow + t, {
- spanAnchor: a,
- hasValue: true,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: false,
- range: n
- };
- }
- function Mh(n, e, t) {
- const o = t.getMaxRows(), s = t.getMaxColumns(), r = _d(t, 0, 0, o - 1, s - 1), i = t.getSnapshot().mergeData.length > 0, { left: a, right: u, up: l, down: c } = e;
- let d = true, h = { ...n };
- const m = [];
- for (; d; ) {
- if (d = false, l && h.startRow !== 0) {
- const { hasValue: g2, range: f, spanAnchor: p } = Ed(h, r, 1, i);
- if (p && m.push(p), g2) {
- h = f, d = true;
- continue;
- }
- }
- if (c && h.endRow !== o - 1) {
- const { hasValue: g2, range: f, spanAnchor: p } = Ud(h, r, 1, i);
- if (p && m.push(p), g2) {
- h = f, d = true;
- continue;
- }
- }
- if (a && h.startColumn !== 0) {
- const { hasValue: g2, range: f, spanAnchor: p } = bd(h, r, 1, i);
- if (p && m.push(p), g2) {
- h = f, d = true;
- continue;
- }
- }
- if (u && h.endColumn !== s - 1) {
- const { hasValue: g2, range: f, spanAnchor: p } = yd(h, r, 1, i);
- if (p && m.push(p), g2) {
- h = f, d = true;
- continue;
- }
- }
- }
- return m.length > 0 && (h = en.union(h, ...m)), h;
- }
- var ti = (n, e, t, o = 1, s = true, r = true) => {
- const i = tr.transformRange(n, e), { startRow: a, endRow: u } = i;
- let l = t.startRow - o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- for (; !e.getRowVisible(l) || !d; )
- l--, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- if (l >= a)
- return { ...t, startRow: l, endRow: l };
- if (r) {
- const h = { ...t, startRow: u, endRow: u };
- return oi(n, e, h, o, s, false);
- }
- };
- var ni = (n, e, t, o = 1, s = true, r = true) => {
- const i = tr.transformRange(n, e), { startRow: a, endRow: u } = i;
- let l = t.endRow + o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- for (; !e.getRowVisible(l) || !d; )
- l++, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- if (l <= u)
- return { ...t, startRow: l, endRow: l };
- if (r) {
- const h = { ...t, startRow: a, endRow: a };
- return si(n, e, h, o, s, false);
- }
- };
- var oi = (n, e, t, o = 1, s = true, r = true) => {
- const i = tr.transformRange(n, e), { startColumn: a, endColumn: u } = i;
- let l = t.startColumn - o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- for (; !e.getColVisible(l) || !d; )
- l--, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- if (l >= a)
- return { ...t, startColumn: l, endColumn: l };
- if (r) {
- const h = { ...t, startColumn: u, endColumn: u };
- return ti(n, e, h, o, s, false);
- }
- };
- var si = (n, e, t, o = 1, s = true, r = true) => {
- const i = tr.transformRange(n, e), { startColumn: a, endColumn: u } = i;
- let l = t.endColumn + o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- for (; !e.getColVisible(l) || !d; )
- l++, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- if (l <= u)
- return { ...t, endColumn: l, startColumn: l };
- if (r) {
- const h = { ...t, startColumn: a, endColumn: a };
- return ni(n, e, h, o, s, false);
- }
- };
- function mn(n, e, t) {
- let o = null;
- return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = {
- actualRow: r,
- actualColumn: i,
- startRow: r,
- startColumn: i,
- isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0,
- isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0,
- endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0),
- endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0),
- rangeType: De.NORMAL
- }, false)), o || {
- actualColumn: e,
- actualRow: n,
- startRow: n,
- startColumn: e,
- endRow: n,
- endColumn: e,
- isMerged: false,
- isMergedMainCell: false,
- rangeType: De.NORMAL
- };
- }
- var Pd = (n, e, t, o, s = 1) => {
- switch (o) {
- case wu.UP:
- return ti(n, e, t, s);
- case wu.DOWN:
- return ni(n, e, t, s);
- case wu.LEFT:
- return oi(n, e, t, s);
- case wu.RIGHT:
- return si(n, e, t, s);
- }
- };
- var _h = (n, e, t) => {
- let o, s = -1, r;
- for (let C = 0; C < n.length; C++)
- if (n[C].primary) {
- o = n[C], s = C, r = o.primary;
- break;
- }
- if (s === -1)
- return null;
- const i = e === wu.LEFT || e === wu.UP, a = i ? s - 1 >= 0 ? s - 1 : n.length - 1 : s + 1 < n.length ? s + 1 : 0, u = n[a];
- if (!o || !r)
- return null;
- const l = { ...r }, { startRow: c, startColumn: d, endRow: h, endColumn: m } = o.range, g2 = i ? l.startRow === c && l.startColumn === d : l.endRow === h && l.endColumn === m, f = g2 && i;
- if (!en.equals(o.range, l)) {
- const C = g2 ? u.range : Pd(o.range, t, l, e);
- if (!C)
- return null;
- const S = f ? mn(C.endRow, C.endColumn, t) : mn(C.startRow, C.startColumn, t);
- return {
- startRow: S.startRow,
- startColumn: S.startColumn,
- endRow: S.endRow,
- endColumn: S.endColumn
- };
- }
- const p = f ? mn(u.range.endRow, u.range.endColumn, t) : mn(u.range.startRow, u.range.startColumn, t);
- return {
- startRow: p.startRow,
- startColumn: p.startColumn,
- endRow: p.endRow,
- endColumn: p.endColumn
- };
- };
- var bh = {
- WorkbookCommentPermission: Ws,
- WorkbookCopyPermission: Ls,
- WorkbookCreateProtectPermission: Vs2,
- WorkbookCreateSheetPermission: Hs,
- WorkbookDeleteSheetPermission: Bs,
- WorkbookDuplicatePermission: Fs,
- WorkbookEditablePermission: Me,
- WorkbookExportPermission: js,
- WorkbookHideSheetPermission: vo,
- WorkbookHistoryPermission: tu,
- WorkbookManageCollaboratorPermission: Mo,
- WorkbookMoveSheetPermission: _o,
- WorkbookPrintPermission: Gs2,
- WorkbookRecoverHistoryPermission: zs,
- WorkbookRenameSheetPermission: bo,
- WorkbookSharePermission: Ks,
- WorkbookViewHistoryPermission: Ys,
- WorkbookViewPermission: Js,
- WorksheetCopyPermission: Xs,
- WorksheetDeleteColumnPermission: qs,
- WorksheetDeleteProtectionPermission: Zs,
- WorksheetDeleteRowPermission: Qs,
- WorksheetEditExtraObjectPermission: er,
- WorksheetEditPermission: Te,
- WorksheetFilterPermission: tr2,
- WorksheetInsertColumnPermission: nr,
- WorksheetInsertHyperlinkPermission: or,
- WorksheetInsertRowPermission: sr,
- WorksheetManageCollaboratorPermission: rr2,
- WorksheetPivotTablePermission: ir,
- WorksheetSelectProtectedCellsPermission: nu2,
- WorksheetSelectUnProtectedCellsPermission: ou,
- WorksheetSetCellStylePermission: ar2,
- WorksheetSetCellValuePermission: wn,
- WorksheetSetColumnStylePermission: $t,
- WorksheetSetRowStylePermission: Wt,
- WorksheetSortPermission: ur,
- WorksheetViewPermission: Hn,
- RangeProtectionPermissionEditPoint: Pe,
- RangeProtectionPermissionViewPoint: Io
- };
- var yh = (n, e, t, o) => {
- const s = n.get(UE), r = n.get(de), i = s.getPermissionPoint(new Me(e).id);
- if (!(i != null && i.value))
- return false;
- const a = s.getPermissionPoint(new Te(e, t).id);
- if (!(a != null && a.value))
- return false;
- const l = r.getSubunitRuleList(e, t).filter((c) => c.ranges.some((d) => o.some((h) => en.intersects(d, h))));
- return l.length ? l.every((c) => {
- const d = c.permissionId, h = s.getPermissionPoint(new Pe(e, t, d).id);
- return !!(h != null && h.value);
- }) : true;
- };
- function Td(n, e) {
- return e.some((t) => kd(n, t));
- }
- function kd(n, e) {
- const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s);
- let a = false;
- return i.forValue((u, l, c) => {
- if (c && (u !== t || l !== o) && n.cellHasValue(c))
- return a = true, false;
- }), a;
- }
- function Nd(n, e, t, o) {
- const s = [], r = [], i = t.getSheetId();
- return o.forEach((a) => {
- const u = Od(t, a), l = {
- unitId: e,
- subUnitId: i,
- cellValue: u.getData()
- }, c = Ae(
- n,
- l
- );
- s.push({ id: Q.id, params: c }), r.push({ id: Q.id, params: l });
- }), {
- undos: s,
- redos: r
- };
- }
- function Od(n, e) {
- const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s, zn.Intercepted), a = new kt();
- return i.forValue((u, l, c) => {
- c && (u !== t || l !== o) && a.setValue(u, l, null);
- }), a;
- }
- var Xn = {
- type: ar.COMMAND,
- id: "sheet.command.add-worksheet-merge",
- handler: (n, e) => {
- const t = n.get(Pt), o = n.get(cn), s = n.get(_n), r = e.unitId, i = e.subUnitId, a = e.selections, u = Zr(a, e.value), l = s.getUniverSheetInstance(r).getSheetBySheetId(i), c = [], d = [], h = Td(l, u), m = {
- unitId: r,
- subUnitId: i,
- ranges: u
- }, g2 = {
- unitId: r,
- subUnitId: i,
- ranges: u
- };
- c.push({ id: oe.id, params: m }), c.push({ id: ne.id, params: g2 });
- const f = Se(n, m), p = Ue(n, g2);
- if (d.push({ id: oe.id, params: p }), d.push({ id: ne.id, params: f }), h) {
- const S = Nd(n, r, l, u);
- c.unshift(...S.redos), d.push(...S.undos);
- }
- return mu(c, t).result ? (o.pushUndoRedo({
- unitID: r,
- undoMutations: d,
- redoMutations: c
- }), true) : false;
- }
- };
- var Eh = {
- type: ar.COMMAND,
- id: "sheet.command.add-worksheet-merge-all",
- handler: async (n) => {
- var l;
- const e = n.get(Pt), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
- if (!(o != null && o.length))
- return false;
- const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!r)
- return false;
- const i = r.getActiveSheet();
- if (!i)
- return false;
- const a = r.getUnitId(), u = i.getSheetId();
- return e.executeCommand(Xn.id, {
- selections: o,
- unitId: a,
- subUnitId: u
- });
- }
- };
- var Uh = {
- type: ar.COMMAND,
- id: "sheet.command.add-worksheet-merge-vertical",
- handler: async (n) => {
- var l;
- const e = n.get(Pt), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
- if (!(o != null && o.length))
- return false;
- const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!r)
- return false;
- const i = r.getActiveSheet();
- if (!i)
- return false;
- const a = r.getUnitId(), u = i.getSheetId();
- return e.executeCommand(Xn.id, {
- value: yu.COLUMNS,
- selections: o,
- unitId: a,
- subUnitId: u
- });
- }
- };
- var Ph = {
- type: ar.COMMAND,
- id: "sheet.command.add-worksheet-merge-horizontal",
- handler: async (n) => {
- var l;
- const e = n.get(Pt), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
- if (!(o != null && o.length))
- return false;
- const r = n.get(_n).getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (!r)
- return false;
- const i = r.getActiveSheet();
- if (!i)
- return false;
- const a = r.getUnitId(), u = i.getSheetId();
- return e.executeCommand(Xn.id, {
- value: yu.ROWS,
- selections: o,
- unitId: a,
- subUnitId: u
- });
- }
- };
- function Th(n, e, t, o, s) {
- const r = n.get(_n), i = N(r, { unitId: e, subUnitId: t });
- if (!i)
- return;
- const { worksheet: a } = i;
- if (a.getMergeData().some((d) => o.some((h) => en.intersects(h, d))))
- throw new Error("The ranges to be merged overlap with the existing merged cells");
- n.get(Pt).executeCommand(Xn.id, {
- unitId: e,
- subUnitId: t,
- selections: o,
- defaultMerge: s
- });
- }
- var Dd = (n, e) => {
- const r = n.get(_n).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft;
- return {
- ...re.deepClone(e),
- rightToLeft: r
- };
- };
- var so = {
- id: "sheet.mutation.set-worksheet-right-to-left",
- type: ar.MUTATION,
- handler: (n, e) => {
- const t = n.get(_n).getUniverSheetInstance(e.unitId);
- if (!t)
- return false;
- const o = t.getSheetBySheetId(e.subUnitId);
- if (!o)
- return false;
- const s = o.getConfig();
- return s.rightToLeft = e.rightToLeft, true;
- }
- };
- var kh = {
- type: ar.COMMAND,
- id: "sheet.command.set-worksheet-right-to-left",
- handler: async (n, e) => {
- var d;
- const t = n.get(Pt), o = n.get(cn), s = N(n.get(_n), e);
- if (!s)
- return false;
- const { unitId: r, subUnitId: i } = s;
- let a = we.FALSE;
- e && (a = (d = e.rightToLeft) != null ? d : we.FALSE);
- const u = {
- rightToLeft: a,
- unitId: r,
- subUnitId: i
- }, l = Dd(
- n,
- u
- );
- return t.syncExecuteCommand(
- so.id,
- u
- ) ? (o.pushUndoRedo({
- unitID: r,
- undoMutations: [{ id: so.id, params: l }],
- redoMutations: [
- { id: so.id, params: u }
- ]
- }), true) : false;
- }
- };
- export {
- T,
- Ji2 as Ji,
- Yi,
- de,
- Bd,
- ze,
- Fd,
- Ne,
- Xi2 as Xi,
- Ye,
- ct,
- St,
- qi,
- et,
- ea,
- Go2 as Go,
- qn,
- Zn,
- V,
- yt,
- va,
- N,
- Et,
- zt,
- Ma,
- Kt,
- _a,
- ba,
- Os,
- Ua,
- Ce,
- Ta,
- F,
- jd,
- Gd,
- Aa,
- Ae,
- Q,
- po,
- Co,
- So,
- As,
- Jt,
- ja,
- Ut,
- xs,
- dt,
- Xa,
- qo,
- qa,
- re2 as re,
- Ln,
- zd,
- Kd,
- ve,
- Xe2 as Xe,
- Jd,
- Vn2 as Vn,
- pt,
- wo2 as wo,
- _,
- D,
- Pe,
- Io,
- Ws,
- Ls,
- eu,
- Vs2 as Vs,
- Hs,
- Bs,
- Fs,
- Me,
- js,
- vo,
- tu,
- Mo,
- _o,
- Gs2 as Gs,
- zs,
- bo,
- Ks,
- Js,
- Ys,
- Xs,
- qs,
- Zs,
- Qs,
- Te,
- er,
- tr2 as tr,
- nr,
- or,
- sr,
- rr2 as rr,
- ir,
- nu2 as nu,
- ou,
- ar2 as ar,
- wn,
- $t,
- Wt,
- ur,
- Hn,
- on,
- lr,
- cr,
- Yd,
- Xd,
- Pt2 as Pt,
- Tt,
- su,
- ru,
- iu,
- au,
- mr2 as mr,
- qe,
- yo,
- je,
- Be,
- De2 as De,
- sn,
- Bn,
- mt,
- fr,
- du,
- hu,
- gt,
- pr2 as pr,
- mu2 as mu,
- gu,
- fu,
- Ru,
- ot2 as ot,
- pu,
- st2 as st,
- Fn,
- jn,
- Yt,
- Uo,
- wu2 as wu,
- Ir,
- vr,
- Gn,
- Mr,
- zn2 as zn,
- ko,
- Ue,
- ne,
- Se,
- oe,
- Iu,
- Mu,
- In,
- uo,
- kt2 as kt,
- rn,
- Tu,
- ku,
- Nu,
- Ou,
- xu,
- Lt,
- $u,
- Xt2 as Xt,
- qt2 as qt,
- Kn,
- br,
- yr,
- Ur,
- Pr,
- ut,
- Bu,
- Fu,
- Vt,
- ju,
- he,
- qd,
- Ct2 as Ct,
- Gu,
- zu,
- Ht,
- Ku,
- Zt,
- Qt,
- Jn,
- Tr,
- kr,
- fe,
- Zd,
- Qd,
- eh,
- th,
- nh,
- oh,
- sh,
- Zu,
- Qu,
- el,
- tl,
- nl,
- ol,
- sl,
- rl,
- fn3 as fn,
- al,
- Or,
- Dr,
- an,
- Ar,
- xr,
- tt,
- Oo,
- Mn,
- Bt,
- cl,
- dl,
- lt,
- hl,
- _n2 as _n,
- Do,
- Rn,
- Wr,
- un,
- Lr,
- Vr2 as Vr,
- Ie,
- it,
- rh,
- en2 as en,
- fl2 as fl,
- we2 as we,
- ke,
- eo,
- bn,
- Ao,
- Il,
- vl,
- ih,
- nt2 as nt,
- Oe,
- Br,
- $o,
- Wo,
- Lo,
- Fr,
- Pl,
- Tl,
- kl,
- Ft,
- Nl,
- Ol,
- Dl,
- Al,
- xl,
- jr,
- Gr,
- ah,
- wt,
- uh,
- Vo2 as Vo,
- zr,
- lh,
- lo,
- Wl,
- Ll,
- ch,
- Un,
- $,
- q,
- _e,
- Pn,
- Jr,
- Yr,
- tc,
- It,
- Xr,
- oc,
- vt,
- ic,
- ac,
- uc,
- cc,
- hc,
- gc,
- Mt2 as Mt,
- os,
- dh,
- ss,
- hh,
- Sc,
- mh,
- _t,
- Zr,
- Oc,
- Tn,
- Nn,
- ht,
- On,
- tn,
- ds,
- Qc,
- co,
- An,
- xn,
- $n,
- ho,
- Wn,
- Id,
- vd,
- gh,
- fh,
- Rh,
- ph,
- Ch,
- Sh,
- wh,
- Md,
- Ih,
- vh,
- Mh,
- _h,
- bh,
- yh,
- Xn,
- Eh,
- Uh,
- Ph,
- Th,
- so,
- kh
- };
- //# sourceMappingURL=chunk-BW43Z7N3.js.map
|