index.js 377 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888
  1. var ri = Object.defineProperty;
  2. var ii = (n, e, t) => e in n ? ri(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
  3. var R = (n, e, t) => ii(n, typeof e != "symbol" ? e + "" : e, t);
  4. import { Tools as O, CommandType as v, ICommandService as E, IUndoRedoService as W, createInterceptorKey as rt, Disposable as ae, UniverInstanceType as B, InterceptorEffectEnum as me, InterceptorManager as mo, toDisposable as We, remove as Nt, composeInterceptors as ai, DisposableCollection as jt, IUniverInstanceService as M, HorizontalAlign as ro, BooleanNumber as te, BorderStyleTypes as Rs, Inject as L, IResourceManagerService as nn, RTree as ui, generateRandomId as li, ObjectMatrix as G, RxDisposable as ps, normalizeTextRuns as ci, CellValueType as se, isRealNum as go, isBooleanString as Cs, isSafeNumeric as di, sequenceExecute as z, LocaleService as Ke, createIdentifier as fo, IContextService as Ss, selectionToArray as hi, Rectangle as k, RANGE_TYPE as H, ErrorService as bt, Range as K, cellToRange as ws, PermissionStatus as J, IPermissionService as Fe, isICellData as Is, Dimension as ge, getArrayLength as vs, insertMatrixArray as pn, spliceArray as Ms, sliceMatrixArray as _s, concatMatrixArray as bs, Direction as pe, mergeWorksheetSnapshotWithDefault as mi, moveMatrixArray as ys, BorderType as ue, FontWeight as gi, FontItalic as fi, Injector as Ro, ILogService as Es, DocumentDataModel as Ri, BuildTextUtils as pi, TextX as Ci, Optional as Si, IConfigService as Us, queryObjectMatrix as Je, CustomCommandExecutionError as wi, UserManagerService as Ii, IAuthzIoService as vi, LRUMap as Mi, DependentOn as _i, Plugin as bi, merge as yi, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE as Ei, AUTO_HEIGHT_FOR_MERGED_CELLS as Ui, registerDependencies as Pi, mergeOverrideWithDependencies as Ti, touchDependencies as ln, createRowColIter as ki, CellModeEnum as Ni } from "@univerjs/core";
  5. import { SetDefinedNameMutation as Gt, RemoveDefinedNameMutation as Cn, SetDefinedNameMutationFactory as Oi, SetFormulaCalculationResultMutation as Di, handleNumfmtInCell as Ai, IDefinedNamesService as Ps, stripErrorMargin as xi, LexerTreeBuilder as $i, operatorToken as Wi, deserializeRangeWithSheet as Li, sequenceNodeType as Vi, deserializeRangeWithSheetWithCache as Hi, UniverFormulaEnginePlugin as Bi } from "@univerjs/engine-formula";
  6. import { DataSyncPrimaryController as Fi } from "@univerjs/rpc";
  7. import { Subject as Le, BehaviorSubject as at, merge as xt, shareReplay as ji, takeUntil as io, switchMap as Ge, of as Ot, distinctUntilChanged as Gi, skip as Ts, map as ao, first as zi, filter as Ho } from "rxjs";
  8. import { DEFAULT_TEXT_FORMAT as ks } from "@univerjs/engine-numfmt";
  9. import { takeUntil as Bo, filter as Fo, map as Ki } from "rxjs/operators";
  10. var Ji = /* @__PURE__ */ ((n) => (n.OthersCanView = "othersCanView", n.NoOneElseCanView = "noOneElseCanView", n))(Ji || {}), Yi = /* @__PURE__ */ ((n) => (n.DesignedUserCanEdit = "designedUserCanEdit", n.OnlyMe = "onlyMe", n))(Yi || {});
  11. class de {
  12. constructor() {
  13. /**
  14. *
  15. * Map<unitId, Map<subUnitId, Map<ruleId, IRangeProtectionRule>>>
  16. */
  17. R(this, "_model", /* @__PURE__ */ new Map());
  18. R(this, "_ruleChange", new Le());
  19. R(this, "ruleChange$", this._ruleChange.asObservable());
  20. R(this, "_ruleRefresh", new Le());
  21. R(this, "ruleRefresh$", this._ruleRefresh.asObservable());
  22. R(this, "_rangeRuleInitStateChange", new at(!1));
  23. R(this, "rangeRuleInitStateChange$", this._rangeRuleInitStateChange.asObservable());
  24. }
  25. ruleRefresh(e) {
  26. this._ruleRefresh.next(e);
  27. }
  28. getRangeRuleInitState() {
  29. return this._rangeRuleInitStateChange.value;
  30. }
  31. changeRuleInitState(e) {
  32. this._rangeRuleInitStateChange.next(e);
  33. }
  34. addRule(e, t, o) {
  35. this._ensureRuleMap(e, t).set(o.id, o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: o, type: "add" });
  36. }
  37. deleteRule(e, t, o) {
  38. var r, i, a, u;
  39. const s = (i = (r = this._model.get(e)) == null ? void 0 : r.get(t)) == null ? void 0 : i.get(o);
  40. 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" }));
  41. }
  42. setRule(e, t, o, s) {
  43. var i, a;
  44. const r = this.getRule(e, t, o);
  45. 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" }));
  46. }
  47. getRule(e, t, o) {
  48. var s, r;
  49. return (r = (s = this._model.get(e)) == null ? void 0 : s.get(t)) == null ? void 0 : r.get(o);
  50. }
  51. getSubunitRuleList(e, t) {
  52. var s;
  53. return [...(((s = this._model.get(e)) == null ? void 0 : s.get(t)) || /* @__PURE__ */ new Map()).values()];
  54. }
  55. getSubunitRuleListLength(e, t) {
  56. var s;
  57. const o = (s = this._model.get(e)) == null ? void 0 : s.get(t);
  58. return o ? o.size : 0;
  59. }
  60. _ensureRuleMap(e, t) {
  61. let o = this._model.get(e);
  62. o || (o = /* @__PURE__ */ new Map(), this._model.set(e, o));
  63. let s = o.get(t);
  64. return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
  65. }
  66. toObject() {
  67. const e = {};
  68. return [...this._model.keys()].forEach((o) => {
  69. const s = this._model.get(o), r = [...s.keys()];
  70. e[o] = {}, r.forEach((i) => {
  71. const a = s.get(i);
  72. e[o][i] = [...a.values()];
  73. });
  74. }), e;
  75. }
  76. fromObject(e) {
  77. const t = /* @__PURE__ */ new Map();
  78. Object.keys(e).forEach((o) => {
  79. const s = e[o], r = /* @__PURE__ */ new Map();
  80. Object.keys(s).forEach((i) => {
  81. const a = s[i].reduce((u, l) => (u.set(l.id, l), u), /* @__PURE__ */ new Map());
  82. r.set(i, a);
  83. }), t.set(o, r);
  84. }), this._model = t;
  85. }
  86. deleteUnitModel(e) {
  87. this._model.delete(e);
  88. }
  89. createRuleId(e, t) {
  90. let o = O.generateRandomId(4);
  91. const s = this._ensureRuleMap(e, t);
  92. for (; s.has(o); )
  93. o = O.generateRandomId(4);
  94. return o;
  95. }
  96. getTargetByPermissionId(e, t) {
  97. const o = this._model.get(e);
  98. if (!o) return null;
  99. for (const [s, r] of o)
  100. for (const i of r.values())
  101. if (i.permissionId === t)
  102. return [e, s];
  103. return null;
  104. }
  105. }
  106. const Bd = (n, e) => {
  107. const t = n.get(de), o = e.ruleIds.map((r) => t.getRule(e.unitId, e.subUnitId, r)).filter((r) => !!r);
  108. return { id: Ne.id, params: { subUnitId: e.subUnitId, unitId: e.unitId, rules: o } };
  109. }, ze = {
  110. id: "sheet.mutation.delete-range-protection",
  111. type: v.MUTATION,
  112. handler: (n, e) => {
  113. const { unitId: t, subUnitId: o, ruleIds: s } = e, r = n.get(de);
  114. return s.forEach((i) => {
  115. r.deleteRule(t, o, i);
  116. }), !0;
  117. }
  118. }, Fd = (n) => {
  119. const e = { ...n, ruleIds: n.rules.map((t) => t.id) };
  120. return { id: ze.id, params: e };
  121. }, Ne = {
  122. id: "sheet.mutation.add-range-protection",
  123. type: v.MUTATION,
  124. handler: (n, e) => {
  125. const { unitId: t, subUnitId: o, rules: s } = e, r = n.get(de);
  126. return s.forEach((i) => {
  127. r.addRule(t, o, i);
  128. }), !0;
  129. }
  130. }, Xi = {
  131. type: v.COMMAND,
  132. id: "sheet.command.add-range-protection",
  133. async handler(n, e) {
  134. if (!e)
  135. return !1;
  136. const t = n.get(E), o = n.get(W), s = n.get(de), { rule: r, permissionId: i } = e, { unitId: a, subUnitId: u, ranges: l, description: c, viewState: d, editState: h } = r, m = [{
  137. ranges: l,
  138. permissionId: i,
  139. id: s.createRuleId(a, u),
  140. description: c,
  141. unitType: r.unitType,
  142. unitId: a,
  143. subUnitId: u,
  144. viewState: d,
  145. editState: h
  146. }];
  147. if (await t.executeCommand(Ne.id, {
  148. unitId: a,
  149. subUnitId: u,
  150. rules: m
  151. })) {
  152. 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) } }];
  153. o.pushUndoRedo({
  154. unitID: a,
  155. redoMutations: f,
  156. undoMutations: p
  157. });
  158. }
  159. return !0;
  160. }
  161. };
  162. class Ye {
  163. constructor() {
  164. /**
  165. *
  166. * Map<unitId, Map<subUnitId, Map<subUnitId, IWorksheetProtectionRule>>>
  167. */
  168. R(this, "_model", /* @__PURE__ */ new Map());
  169. R(this, "_ruleChange", new Le());
  170. R(this, "_ruleRefresh", new Le());
  171. R(this, "_resetOrder", new Le());
  172. R(this, "ruleChange$", this._ruleChange.asObservable());
  173. R(this, "ruleRefresh$", this._ruleRefresh.asObservable());
  174. R(this, "resetOrder$", this._resetOrder.asObservable());
  175. R(this, "_worksheetRuleInitStateChange", new at(!1));
  176. R(this, "worksheetRuleInitStateChange$", this._worksheetRuleInitStateChange.asObservable());
  177. }
  178. changeRuleInitState(e) {
  179. this._worksheetRuleInitStateChange.next(e);
  180. }
  181. getSheetRuleInitState() {
  182. return this._worksheetRuleInitStateChange.value;
  183. }
  184. addRule(e, t) {
  185. this._ensureSubUnitMap(e).set(t.subUnitId, t), this._ruleChange.next({ unitId: e, rule: t, type: "add", subUnitId: t.subUnitId });
  186. }
  187. deleteRule(e, t) {
  188. var s, r, i;
  189. const o = (r = (s = this._model) == null ? void 0 : s.get(e)) == null ? void 0 : r.get(t);
  190. o && ((i = this._model.get(e)) == null || i.delete(t), this._ruleChange.next({ unitId: e, rule: o, type: "delete", subUnitId: t }));
  191. }
  192. setRule(e, t, o) {
  193. var r, i;
  194. const s = this.getRule(e, t);
  195. 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 }));
  196. }
  197. getRule(e, t) {
  198. var o, s;
  199. return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
  200. }
  201. toObject() {
  202. const e = {};
  203. return [...this._model.keys()].forEach((o) => {
  204. const s = this._model.get(o);
  205. s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
  206. const a = s.get(i);
  207. a && e[o].push(a);
  208. }));
  209. }), e;
  210. }
  211. fromObject(e) {
  212. const t = /* @__PURE__ */ new Map();
  213. Object.keys(e).forEach((o) => {
  214. const s = e[o];
  215. if (s != null && s.length) {
  216. const r = /* @__PURE__ */ new Map();
  217. s.forEach((i) => {
  218. r.set(i.subUnitId, i);
  219. }), t.set(o, r);
  220. }
  221. }), this._model = t;
  222. }
  223. deleteUnitModel(e) {
  224. this._model.delete(e);
  225. }
  226. _ensureSubUnitMap(e) {
  227. let t = this._model.get(e);
  228. return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
  229. }
  230. ruleRefresh(e) {
  231. this._ruleRefresh.next(e);
  232. }
  233. resetOrder() {
  234. this._resetOrder.next(Math.random());
  235. }
  236. getTargetByPermissionId(e, t) {
  237. const o = this._model.get(e);
  238. if (!o) return null;
  239. for (const [s, r] of o)
  240. if (r.permissionId === t)
  241. return [e, s];
  242. }
  243. }
  244. const ct = {
  245. id: "sheet.mutation.add-worksheet-protection",
  246. type: v.MUTATION,
  247. handler: (n, e) => {
  248. const { unitId: t, rule: o } = e;
  249. return n.get(Ye).addRule(t, o), !0;
  250. }
  251. }, St = {
  252. id: "sheet.mutation.delete-worksheet-protection",
  253. type: v.MUTATION,
  254. handler: (n, e) => {
  255. const { unitId: t, subUnitId: o } = e;
  256. return n.get(Ye).deleteRule(t, o), !0;
  257. }
  258. }, qi = {
  259. type: v.COMMAND,
  260. id: "sheet.command.add-worksheet-protection",
  261. async handler(n, e) {
  262. if (!e)
  263. return !1;
  264. const t = n.get(E), o = n.get(W), { rule: s, unitId: r } = e, i = s.subUnitId;
  265. if (await t.executeCommand(ct.id, {
  266. unitId: r,
  267. rule: s,
  268. subUnitId: s.subUnitId
  269. })) {
  270. const u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: s.subUnitId } }], l = [{ id: St.id, params: { unitId: r, subUnitId: i } }];
  271. o.pushUndoRedo({
  272. unitID: r,
  273. redoMutations: u,
  274. undoMutations: l
  275. });
  276. }
  277. return !0;
  278. }
  279. }, Zi = rt("CELL_CONTENT"), Qi = rt("ROW_FILTERED"), et = {
  280. CELL_CONTENT: Zi,
  281. ROW_FILTERED: Qi
  282. };
  283. var ea = /* @__PURE__ */ ((n) => (n[n.DATA_VALIDATION = 9] = "DATA_VALIDATION", n[n.NUMFMT = 10] = "NUMFMT", n[n.CELL_IMAGE = 11] = "CELL_IMAGE", n))(ea || {});
  284. const Ns = "sheet.interceptor.range-theme-id", jo = "sheet.interceptor.ignore-range-theme";
  285. var ta = Object.defineProperty, na = Object.getOwnPropertyDescriptor, oa = (n, e, t, o) => {
  286. for (var s = o > 1 ? void 0 : o ? na(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  287. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  288. return o && s && ta(e, t, s), s;
  289. }, sa = (n, e) => (t, o) => e(t, o, n);
  290. const Go = rt("BEFORE_CELL_EDIT"), qn = rt("AFTER_CELL_EDIT"), Zn = rt("AFTER_CELL_EDIT_ASYNC");
  291. let V = class extends ae {
  292. /** @ignore */
  293. constructor(e) {
  294. super();
  295. R(this, "_interceptorsByName", /* @__PURE__ */ new Map());
  296. R(this, "_commandInterceptors", []);
  297. R(this, "_rangeInterceptors", []);
  298. R(this, "_beforeCommandInterceptor", []);
  299. R(this, "_afterCommandInterceptors", []);
  300. R(this, "_workbookDisposables", /* @__PURE__ */ new Map());
  301. R(this, "_worksheetDisposables", /* @__PURE__ */ new Map());
  302. R(this, "_interceptorsDirty", !1);
  303. R(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map());
  304. R(this, "writeCellInterceptor", new mo({
  305. BEFORE_CELL_EDIT: Go,
  306. AFTER_CELL_EDIT: qn,
  307. AFTER_CELL_EDIT_ASYNC: Zn
  308. }));
  309. this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((t) => {
  310. this._interceptWorkbook(t);
  311. })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe(
  312. (t) => this._disposeWorkbookInterceptor(t)
  313. )), this.intercept(et.CELL_CONTENT, {
  314. priority: -1,
  315. effect: me.Style | me.Value,
  316. handler(t, o) {
  317. const s = o.worksheet.getCellRaw(o.row, o.col);
  318. return t ? { ...s, ...t } : s;
  319. }
  320. }), this.disposeWithMe(this.writeCellInterceptor.intercept(qn, {
  321. priority: -1,
  322. handler: (t) => t
  323. })), this.disposeWithMe(this.writeCellInterceptor.intercept(Go, {
  324. priority: -1,
  325. handler: (t) => t
  326. })), this.disposeWithMe(this.writeCellInterceptor.intercept(Zn, {
  327. priority: -1,
  328. handler: (t) => t
  329. }));
  330. }
  331. dispose() {
  332. super.dispose(), this._workbookDisposables.forEach((e) => e.dispose()), this._workbookDisposables.clear(), this._worksheetDisposables.clear(), this._interceptorsByName.clear();
  333. }
  334. // #region intercept command execution
  335. /**
  336. * Add a listener function to a specific command to add affiliated mutations. It should be called in controllers.
  337. *
  338. * Pairs with {@link onCommandExecute}.
  339. *
  340. * @param interceptor
  341. * @returns
  342. */
  343. interceptCommand(e) {
  344. if (this._commandInterceptors.includes(e))
  345. throw new Error("[SheetInterceptorService]: Interceptor already exists!");
  346. return this._commandInterceptors.push(e), this._commandInterceptors.sort((t, o) => {
  347. var s, r;
  348. return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
  349. }), this.disposeWithMe(We(() => Nt(this._commandInterceptors, e)));
  350. }
  351. /**
  352. * When command is executing, call this method to gether undo redo mutations from upper features.
  353. * @param command
  354. * @returns
  355. */
  356. onCommandExecute(e) {
  357. const t = this._commandInterceptors.map((o) => o.getMutations(e));
  358. return {
  359. preUndos: t.map((o) => {
  360. var s;
  361. return (s = o.preUndos) != null ? s : [];
  362. }).flat(),
  363. undos: t.map((o) => o.undos).flat(),
  364. preRedos: t.map((o) => {
  365. var s;
  366. return (s = o.preRedos) != null ? s : [];
  367. }).flat(),
  368. redos: t.map((o) => o.redos).flat()
  369. };
  370. }
  371. interceptAfterCommand(e) {
  372. if (this._afterCommandInterceptors.includes(e))
  373. throw new Error("[SheetInterceptorService]: Interceptor already exists!");
  374. return this._afterCommandInterceptors.push(e), this._afterCommandInterceptors.sort((t, o) => {
  375. var s, r;
  376. return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
  377. }), this.disposeWithMe(We(() => Nt(this._afterCommandInterceptors, e)));
  378. }
  379. afterCommandExecute(e) {
  380. const t = this._afterCommandInterceptors.map((o) => o.getMutations(e));
  381. return {
  382. undos: t.map((o) => o.undos).flat(),
  383. redos: t.map((o) => o.redos).flat()
  384. };
  385. }
  386. /**
  387. * Add a listener function to a specific command to determine if the command can execute mutations. It should be
  388. * called in controllers.
  389. *
  390. * Pairs with {@link beforeCommandExecute}.
  391. *
  392. * @param interceptor
  393. * @returns
  394. */
  395. interceptBeforeCommand(e) {
  396. if (this._beforeCommandInterceptor.includes(e))
  397. throw new Error("[SheetInterceptorService]: Interceptor already exists!");
  398. return this._beforeCommandInterceptor.push(e), this._beforeCommandInterceptor.sort((t, o) => {
  399. var s, r;
  400. return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
  401. }), this.disposeWithMe(We(() => Nt(this._beforeCommandInterceptor, e)));
  402. }
  403. /**
  404. * before command execute, call this method to get the flag of whether it can be executed the command,
  405. * @param info ICommandInfo
  406. * @returns Promise<boolean>
  407. */
  408. async beforeCommandExecute(e) {
  409. return (await Promise.all(this._beforeCommandInterceptor.map((o) => o.performCheck(e)))).every((o) => o);
  410. }
  411. // #endregion
  412. // #region intercept ranges - mainly for pivot table currently (2024/10/28).
  413. /**
  414. * By adding callbacks to some Ranges can get some additional mutations, such as clearing all plugin data in a certain area.
  415. * @param interceptor IRangeInterceptors
  416. * @returns IDisposable
  417. */
  418. interceptRanges(e) {
  419. if (this._rangeInterceptors.includes(e))
  420. throw new Error("[SheetInterceptorService]: Interceptor already exists!");
  421. return this._rangeInterceptors.push(e), this._rangeInterceptors.sort((t, o) => {
  422. var s, r;
  423. return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
  424. }), this.disposeWithMe(We(() => Nt(this._rangeInterceptors, e)));
  425. }
  426. generateMutationsByRanges(e) {
  427. const t = this._rangeInterceptors.map((o) => o.getMutations(e));
  428. return {
  429. preUndos: t.map((o) => {
  430. var s;
  431. return (s = o.preUndos) != null ? s : [];
  432. }).flat(),
  433. undos: t.map((o) => o.undos).flat(),
  434. preRedos: t.map((o) => {
  435. var s;
  436. return (s = o.preRedos) != null ? s : [];
  437. }).flat(),
  438. redos: t.map((o) => o.redos).flat()
  439. };
  440. }
  441. // #endregion
  442. // #region intercept on writing cell
  443. async onWriteCell(e, t, o, s, r) {
  444. const i = {
  445. subUnitId: t.getSheetId(),
  446. unitId: e.getUnitId(),
  447. workbook: e,
  448. worksheet: t,
  449. row: o,
  450. col: s,
  451. origin: O.deepClone(r)
  452. }, a = this.writeCellInterceptor.fetchThroughInterceptors(qn)(r, i);
  453. return await this.writeCellInterceptor.fetchThroughInterceptors(Zn)(Promise.resolve(a), i);
  454. }
  455. // #endregion
  456. intercept(e, t) {
  457. const o = e;
  458. this._interceptorsByName.has(o) || this._interceptorsByName.set(o, []);
  459. const s = this._interceptorsByName.get(o);
  460. s.push(t);
  461. const r = s.sort((i, a) => {
  462. var u, l;
  463. return ((u = a.priority) != null ? u : 0) - ((l = i.priority) != null ? l : 0);
  464. });
  465. if (o === et.CELL_CONTENT) {
  466. this._interceptorsByName.set(
  467. `${o}-${me.Style | me.Value}`,
  468. r
  469. );
  470. const i = me.Style | me.Value;
  471. this._interceptorsByName.set(
  472. `${o}-${me.Style}`,
  473. r.filter((a) => ((a.effect || i) & me.Style) > 0)
  474. ), this._interceptorsByName.set(
  475. `${o}-${me.Value}`,
  476. r.filter((a) => ((a.effect || i) & me.Value) > 0)
  477. );
  478. } else
  479. this._interceptorsByName.set(
  480. o,
  481. r
  482. );
  483. return this._interceptorsDirty = !0, this.disposeWithMe(We(() => Nt(this._interceptorsByName.get(o), t)));
  484. }
  485. fetchThroughInterceptors(e, t, o, s) {
  486. const r = t === void 0 ? e : `${e}-${t}`, i = o != null ? o : r;
  487. let a = this._composedInterceptorByKey.get(i);
  488. if (!a || this._interceptorsDirty) {
  489. let u = this._interceptorsByName.get(r);
  490. u && s && (u = u.filter(s)), a = ai(u || []), this._composedInterceptorByKey.set(i, a);
  491. }
  492. return a;
  493. }
  494. _interceptWorkbook(e) {
  495. const t = new jt(), o = e.getUnitId(), s = this, r = (i) => {
  496. const a = i.getSheetId();
  497. i.__interceptViewModel((u) => {
  498. const l = new jt();
  499. s._worksheetDisposables.set(zo(o, i), l), l.add(u.registerCellContentInterceptor({
  500. getCell(c, d, h, m, g) {
  501. const f = i.getCellRaw(c, d);
  502. return s.fetchThroughInterceptors(et.CELL_CONTENT, h, m, g)(
  503. f,
  504. {
  505. unitId: o,
  506. subUnitId: a,
  507. row: c,
  508. col: d,
  509. worksheet: i,
  510. workbook: e,
  511. rawData: f
  512. }
  513. );
  514. }
  515. })), l.add(u.registerRowFilteredInterceptor({
  516. getRowFiltered(c) {
  517. return !!s.fetchThroughInterceptors(et.ROW_FILTERED)(
  518. !1,
  519. {
  520. unitId: o,
  521. subUnitId: a,
  522. row: c,
  523. workbook: e,
  524. worksheet: i
  525. }
  526. );
  527. }
  528. }));
  529. });
  530. };
  531. e.getSheets().forEach((i) => r(i)), t.add(e.sheetCreated$.subscribe((i) => r(i))), t.add(We(() => e.getSheets().forEach((i) => this._disposeSheetInterceptor(o, i)))), t.add(e.sheetDisposed$.subscribe((i) => this._disposeSheetInterceptor(o, i))), this._workbookDisposables.set(o, t);
  532. }
  533. _disposeWorkbookInterceptor(e) {
  534. const t = e.getUnitId(), o = this._workbookDisposables.get(t);
  535. o && (o.dispose(), this._workbookDisposables.delete(t));
  536. }
  537. _disposeSheetInterceptor(e, t) {
  538. const o = zo(e, t), s = this._worksheetDisposables.get(o);
  539. s && (s.dispose(), this._worksheetDisposables.delete(o));
  540. }
  541. };
  542. V = oa([
  543. sa(0, M)
  544. ], V);
  545. function zo(n, e) {
  546. return `${n}|${e.getSheetId()}`;
  547. }
  548. const le = (n) => {
  549. const e = {};
  550. 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;
  551. };
  552. function ra(n) {
  553. const e = {};
  554. if (n.length === 1)
  555. return n[0];
  556. for (const t of n)
  557. 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);
  558. return e;
  559. }
  560. const ce = {
  561. wholeStyle: 1,
  562. headerRowStyle: 2,
  563. headerColumnStyle: 4,
  564. firstRowStyle: 8,
  565. secondRowStyle: 16,
  566. lastRowStyle: 32,
  567. firstColumnStyle: 128,
  568. secondColumnStyle: 256,
  569. lastColumnStyle: 512
  570. };
  571. class yt {
  572. /**
  573. * @constructor
  574. * @param {string} name The name of the range theme style, it used to identify the range theme style.
  575. * @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style.
  576. */
  577. constructor(e, t) {
  578. R(this, "_name");
  579. /**
  580. * @property {Nullable<IRangeThemeStyleItem>} wholeStyle effect for the whole range.
  581. */
  582. R(this, "wholeStyle", null);
  583. /**
  584. * @property {Nullable<IRangeThemeStyleItem>} headerRowStyle effect for the header row.
  585. */
  586. R(this, "headerRowStyle", null);
  587. /**
  588. * @property {Nullable<IRangeThemeStyleItem>} headerColumnStyle effect for the header column.
  589. */
  590. R(this, "headerColumnStyle", null);
  591. /**
  592. * @property {Nullable<IRangeThemeStyleItem>} firstRowStyle effect for the first row.
  593. */
  594. R(this, "firstRowStyle", null);
  595. /**
  596. * @property {Nullable<IRangeThemeStyleItem>} secondRowStyle effect for the second row.
  597. */
  598. R(this, "secondRowStyle", null);
  599. /**
  600. * @property {Nullable<IRangeThemeStyleItem>} lastRowStyle effect for the last row.
  601. */
  602. R(this, "lastRowStyle", null);
  603. /**
  604. * @property {Nullable<IRangeThemeStyleItem>} firstColumnStyle effect for the first column.
  605. */
  606. R(this, "firstColumnStyle", null);
  607. /**
  608. * @property {Nullable<IRangeThemeStyleItem>} secondColumnStyle effect for the second column.
  609. */
  610. R(this, "secondColumnStyle", null);
  611. /**
  612. * @property {Nullable<IRangeThemeStyleItem>} lastColumnStyle effect for the last column.
  613. */
  614. R(this, "lastColumnStyle", null);
  615. /**
  616. * @property {Nullable<IRangeThemeStyleItem>} quickly get merge style
  617. */
  618. R(this, "_mergeCacheMap", /* @__PURE__ */ new Map());
  619. t && this.fromJson({ ...t, name: e }), this._name = e;
  620. }
  621. /**
  622. * Gets the name of the range theme style.The name is read only, and use to identifier the range theme style.
  623. * @returns {string} The name of the range theme style.
  624. */
  625. getName() {
  626. return this._name;
  627. }
  628. getWholeStyle() {
  629. return this.wholeStyle;
  630. }
  631. setWholeStyle(e) {
  632. this.wholeStyle = e;
  633. }
  634. getFirstRowStyle() {
  635. return this.firstRowStyle;
  636. }
  637. setFirstRowStyle(e) {
  638. this.firstRowStyle = e;
  639. }
  640. getSecondRowStyle() {
  641. return this.secondRowStyle;
  642. }
  643. setSecondRowStyle(e) {
  644. this.secondRowStyle = e;
  645. }
  646. getLastRowStyle() {
  647. return this.lastRowStyle;
  648. }
  649. setLastRowStyle(e) {
  650. this.lastRowStyle = e;
  651. }
  652. getFirstColumnStyle() {
  653. return this.firstColumnStyle;
  654. }
  655. setFirstColumnStyle(e) {
  656. this.firstColumnStyle = e;
  657. }
  658. getSecondColumnStyle() {
  659. return this.secondColumnStyle;
  660. }
  661. setSecondColumnStyle(e) {
  662. this.secondColumnStyle = e;
  663. }
  664. getLastColumnStyle() {
  665. return this.lastColumnStyle;
  666. }
  667. setLastColumnStyle(e) {
  668. this.lastColumnStyle = e;
  669. }
  670. getHeaderRowStyle() {
  671. return this.headerRowStyle;
  672. }
  673. setHeaderRowStyle(e) {
  674. this.headerRowStyle = e;
  675. }
  676. getHeaderColumnStyle() {
  677. return this.headerColumnStyle;
  678. }
  679. setHeaderColumnStyle(e) {
  680. this.headerColumnStyle = e;
  681. }
  682. getStyle(e, t, o, s) {
  683. let r = 0;
  684. 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);
  685. }
  686. _getMergeStyle(e) {
  687. let t = this._mergeCacheMap.get(e);
  688. return t || (t = this._mergeStyle(e), this._mergeCacheMap.set(e, t)), t;
  689. }
  690. _mergeStyle(e) {
  691. const t = [];
  692. 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);
  693. }
  694. toJson() {
  695. const e = {
  696. name: this._name
  697. };
  698. 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;
  699. }
  700. fromJson(e) {
  701. 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));
  702. }
  703. dispose() {
  704. this._mergeCacheMap.clear();
  705. }
  706. }
  707. const ia = (n, e, t) => new yt(`light-${n}`, {
  708. headerRowStyle: {
  709. bg: {
  710. rgb: e
  711. }
  712. },
  713. firstColumnStyle: {
  714. bg: {
  715. rgb: "rgb(255, 255, 255)"
  716. }
  717. },
  718. secondColumnStyle: {
  719. bg: {
  720. rgb: t
  721. }
  722. },
  723. lastRowStyle: {
  724. bg: {
  725. rgb: e
  726. }
  727. }
  728. }), aa = (n, e, t) => new yt(`middle-${n}`, {
  729. headerRowStyle: {
  730. bg: {
  731. rgb: e
  732. }
  733. },
  734. headerColumnStyle: {
  735. bg: {
  736. rgb: t
  737. }
  738. },
  739. secondRowStyle: {
  740. bg: {
  741. rgb: t
  742. }
  743. },
  744. lastRowStyle: {
  745. bg: {
  746. rgb: e
  747. }
  748. },
  749. lastColumnStyle: {
  750. bg: {
  751. rgb: t
  752. }
  753. }
  754. }), ua = (n, e, t, o) => new yt(`dark-${n}`, {
  755. headerRowStyle: {
  756. bg: {
  757. rgb: e
  758. },
  759. cl: {
  760. rgb: "rgb(255, 255, 255)"
  761. },
  762. ht: ro.CENTER,
  763. bl: te.TRUE
  764. },
  765. firstRowStyle: {
  766. bg: {
  767. rgb: t
  768. }
  769. },
  770. secondRowStyle: {
  771. bg: {
  772. rgb: o
  773. }
  774. },
  775. lastRowStyle: {
  776. bg: {
  777. rgb: e
  778. }
  779. }
  780. }), la = [
  781. {
  782. baseName: "blue",
  783. header: "rgb(164, 202, 254)",
  784. color: "rgb(225, 239, 254)"
  785. },
  786. {
  787. baseName: "grey",
  788. header: "rgb(205, 208, 216)",
  789. color: "rgb(238, 239, 241)"
  790. },
  791. {
  792. baseName: "red",
  793. header: "rgb(248, 180, 180)",
  794. color: "rgb(253, 232, 232)"
  795. },
  796. {
  797. baseName: "orange",
  798. header: "rgb(253, 186, 140)",
  799. color: "rgb(254, 236, 220)"
  800. },
  801. {
  802. baseName: "yellow",
  803. header: "rgb(250, 200, 21)",
  804. color: "rgb(255, 244, 185)"
  805. },
  806. {
  807. baseName: "green",
  808. header: "rgb(132, 225, 188)",
  809. color: "rgb(222, 247, 236)"
  810. },
  811. {
  812. baseName: "azure",
  813. header: "rgb(126, 220, 226)",
  814. color: "rgb(213, 245, 246)"
  815. },
  816. {
  817. baseName: "indigo",
  818. header: "rgb(186, 198, 248)",
  819. color: "rgb(233, 237, 255)"
  820. },
  821. {
  822. baseName: "purple",
  823. header: "rgb(202, 191, 253)",
  824. color: "rgb(237, 235, 254)"
  825. },
  826. {
  827. baseName: "magenta",
  828. header: "rgb(248, 180, 217)",
  829. color: "rgb(252, 232, 243)"
  830. }
  831. ], ca = [
  832. {
  833. baseName: "blue",
  834. rowHeader: "rgb(63, 131, 248)",
  835. colHeader: "rgb(195, 221, 253)"
  836. },
  837. {
  838. baseName: "grey",
  839. rowHeader: "rgb(95, 101, 116)",
  840. colHeader: "rgb(227, 229, 234)"
  841. },
  842. {
  843. baseName: "red",
  844. rowHeader: "rgb(240, 82, 82)",
  845. colHeader: "rgb(251, 213, 213)"
  846. },
  847. {
  848. baseName: "orange",
  849. rowHeader: "rgb(255, 90, 31)",
  850. colHeader: "rgb(252, 217, 189)"
  851. },
  852. {
  853. baseName: "yellow",
  854. rowHeader: "rgb(212, 157, 15)",
  855. colHeader: "rgb(252, 220, 106)"
  856. },
  857. {
  858. baseName: "green",
  859. rowHeader: "rgb(13, 164, 113)",
  860. colHeader: "rgb(188, 240, 218)"
  861. },
  862. {
  863. baseName: "azure",
  864. rowHeader: "rgb(6, 148, 162)",
  865. colHeader: "rgb(175, 236, 239)"
  866. },
  867. {
  868. baseName: "indigo",
  869. rowHeader: "rgb(70, 106, 247)",
  870. colHeader: "rgb(210, 218, 250)"
  871. },
  872. {
  873. baseName: "purple",
  874. rowHeader: "rgb(144, 97, 249)",
  875. colHeader: "rgb(220, 215, 254)"
  876. },
  877. {
  878. baseName: "magenta",
  879. rowHeader: "rgb(231, 70, 148)",
  880. colHeader: "rgb(250, 209, 232)"
  881. }
  882. ], da = [
  883. {
  884. baseName: "blue",
  885. rowHeader: "rgb(30, 66, 159)",
  886. firstRow: "rgb(195, 221, 253)",
  887. secondRow: "rgb(118, 169, 250)"
  888. },
  889. {
  890. baseName: "grey",
  891. rowHeader: "rgb(44, 48, 64)",
  892. firstRow: "rgb(227, 229, 234)",
  893. secondRow: "rgb(151, 157, 172)"
  894. },
  895. {
  896. baseName: "red",
  897. rowHeader: "rgb(155, 28, 28)",
  898. firstRow: "rgb(251, 213, 213)",
  899. secondRow: "rgb(249, 128, 128)"
  900. },
  901. {
  902. baseName: "orange",
  903. rowHeader: "rgb(180, 52, 3)",
  904. firstRow: "rgb(252, 217, 189)",
  905. secondRow: "rgb(255, 138, 76)"
  906. },
  907. {
  908. baseName: "yellow",
  909. rowHeader: "rgb(154, 109, 21)",
  910. firstRow: "rgb(252, 220, 106)",
  911. secondRow: "rgb(212, 157, 15)"
  912. },
  913. {
  914. baseName: "green",
  915. rowHeader: "rgb(4, 108, 78)",
  916. firstRow: "rgb(188, 240, 218)",
  917. secondRow: "rgb(49, 196, 141)"
  918. },
  919. {
  920. baseName: "azure",
  921. rowHeader: "rgb(3, 102, 114)",
  922. firstRow: "rgb(175, 236, 239)",
  923. secondRow: "rgb(22, 189, 202)"
  924. },
  925. {
  926. baseName: "indigo",
  927. rowHeader: "rgb(16, 51, 191)",
  928. firstRow: "rgb(210, 218, 250)",
  929. secondRow: "rgb(98, 128, 249)"
  930. },
  931. {
  932. baseName: "purple",
  933. rowHeader: "rgb(74, 29, 150)",
  934. firstRow: "rgb(220, 215, 254)",
  935. secondRow: "rgb(172, 148, 250)"
  936. },
  937. {
  938. baseName: "magenta",
  939. rowHeader: "rgb(153, 21, 75)",
  940. firstRow: "rgb(250, 209, 232)",
  941. secondRow: "rgb(241, 126, 184)"
  942. }
  943. ], ha = la.map(({ baseName: n, header: e, color: t }) => ia(n, e, t)), ma = ca.map(({ baseName: n, rowHeader: e, colHeader: t }) => aa(n, e, t)), ga = da.map(({ baseName: n, rowHeader: e, firstRow: t, secondRow: o }) => ua(n, e, t, o)), fa = [
  944. ...ha,
  945. ...ma,
  946. ...ga
  947. ], Ra = {
  948. headerRowStyle: {
  949. bg: {
  950. rgb: "rgb(68,114,196)"
  951. },
  952. cl: {
  953. rgb: "rgb(255,255,255)"
  954. },
  955. ht: ro.CENTER,
  956. bl: te.TRUE
  957. },
  958. firstRowStyle: {
  959. bg: {
  960. rgb: "rgb(217,225,242)"
  961. }
  962. },
  963. lastRowStyle: {
  964. bd: {
  965. t: {
  966. s: Rs.THIN,
  967. cl: {
  968. rgb: "rgb(68,114,196)"
  969. }
  970. }
  971. },
  972. ht: ro.CENTER,
  973. bl: te.TRUE
  974. }
  975. }, pa = new yt("default", Ra);
  976. var Ca = Object.defineProperty, Sa = Object.getOwnPropertyDescriptor, wa = (n, e, t, o) => {
  977. for (var s = o > 1 ? void 0 : o ? Sa(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  978. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  979. return o && s && Ca(e, t, s), s;
  980. }, Ko = (n, e) => (t, o) => e(t, o, n);
  981. const Ia = "SHEET_RANGE_THEME_MODEL_PLUGIN";
  982. let He = class extends ae {
  983. constructor(e, t) {
  984. super();
  985. R(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
  986. R(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
  987. R(this, "_rTreeCollection", /* @__PURE__ */ new Map());
  988. R(this, "_defaultRangeThemeMap", /* @__PURE__ */ new Map());
  989. this._sheetInterceptorService = e, this._resourceManagerService = t, this._registerIntercept(), this._initSnapshot(), this._initDefaultTheme();
  990. }
  991. _initDefaultTheme() {
  992. this.registerDefaultRangeTheme(pa);
  993. for (const e of fa)
  994. this.registerDefaultRangeTheme(e);
  995. }
  996. _ensureRangeThemeStyleMap(e) {
  997. return this._rangeThemeStyleMap.has(e) || this._rangeThemeStyleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleMap.get(e);
  998. }
  999. _ensureRangeThemeStyleRuleMap(e) {
  1000. return this._rangeThemeStyleRuleMap.has(e) || this._rangeThemeStyleRuleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleRuleMap.get(e);
  1001. }
  1002. _ensureRTreeCollection(e) {
  1003. return this._rTreeCollection.has(e) || this._rTreeCollection.set(e, new ui()), this._rTreeCollection.get(e);
  1004. }
  1005. getDefaultRangeThemeStyle(e) {
  1006. return this._defaultRangeThemeMap.get(e);
  1007. }
  1008. /**
  1009. * Register range theme styles
  1010. * @param {string} themeName
  1011. * @param {IRangeThemeRangeInfo} rangeInfo
  1012. */
  1013. registerRangeThemeRule(e, t) {
  1014. const { unitId: o, subUnitId: s, range: r } = t, i = li(), a = this._ensureRangeThemeStyleRuleMap(o), u = this._ensureRTreeCollection(o);
  1015. a.set(i, { rangeInfo: t, themeName: e }), u.insert({ unitId: o, sheetId: s, range: r, id: i });
  1016. }
  1017. getRegisteredRangeThemeStyle(e) {
  1018. const { unitId: t, subUnitId: o, range: s } = e, r = this._ensureRTreeCollection(t), i = Array.from(r.bulkSearch([{ unitId: t, sheetId: o, range: s }]));
  1019. if (i[0]) {
  1020. const u = this._ensureRangeThemeStyleRuleMap(t).get(i[0]);
  1021. if (u)
  1022. return u.themeName;
  1023. }
  1024. }
  1025. removeRangeThemeRule(e, t) {
  1026. const { unitId: o, subUnitId: s, range: r } = t, i = this._ensureRTreeCollection(o), a = Array.from(i.bulkSearch([{ unitId: o, sheetId: s, range: r }]));
  1027. if (a[0]) {
  1028. const u = this._ensureRangeThemeStyleRuleMap(o), l = u.get(a[0]);
  1029. l && l.themeName === e && (u.delete(a[0]), i.remove({ unitId: o, sheetId: s, range: r, id: a[0] }));
  1030. }
  1031. }
  1032. registerDefaultRangeTheme(e) {
  1033. this._defaultRangeThemeMap.set(e.getName(), e);
  1034. }
  1035. getRegisteredRangeThemes() {
  1036. return Array.from(this._defaultRangeThemeMap.keys());
  1037. }
  1038. /**
  1039. * Register custom range theme style.
  1040. * @param {string} unitId The unit id.
  1041. * @param {RangeThemeStyle} rangeThemeStyle The range theme style.
  1042. */
  1043. registerRangeThemeStyle(e, t) {
  1044. this._ensureRangeThemeStyleMap(e).set(t.getName(), t);
  1045. }
  1046. /**
  1047. * Unregister custom range theme style.
  1048. * @param {string} unitId The unit id.
  1049. * @param {string} name The name of the range theme style.
  1050. */
  1051. unregisterRangeThemeStyle(e, t) {
  1052. this._ensureRangeThemeStyleMap(e).delete(t);
  1053. }
  1054. /**
  1055. * Gets all custom register themes
  1056. * @return {string[]} The array of all custom registered themes.
  1057. */
  1058. getALLRegisteredTheme() {
  1059. return Array.from(this._rangeThemeStyleMap.keys());
  1060. }
  1061. getRangeThemeStyle(e, t) {
  1062. return this._defaultRangeThemeMap.has(t) ? this._defaultRangeThemeMap.get(t) : this._ensureRangeThemeStyleMap(e).get(t);
  1063. }
  1064. getCellStyle(e, t, o, s) {
  1065. 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 }]));
  1066. if (a[0]) {
  1067. const l = this._ensureRangeThemeStyleRuleMap(e).get(a[0]);
  1068. if (l) {
  1069. const { rangeInfo: c, themeName: d } = l, h = o - c.range.startRow, m = s - c.range.startColumn;
  1070. return this.getRangeThemeStyle(e, d).getStyle(h, m, o === c.range.endRow, s === c.range.endColumn);
  1071. }
  1072. }
  1073. }
  1074. _registerIntercept() {
  1075. this.disposeWithMe(this._sheetInterceptorService.intercept(et.CELL_CONTENT, {
  1076. id: Ns,
  1077. effect: me.Style,
  1078. handler: (e, t, o) => {
  1079. const { row: s, col: r, unitId: i, subUnitId: a } = t, u = this.getCellStyle(i, a, s, r);
  1080. if (u) {
  1081. const l = { ...e };
  1082. return l.themeStyle = u, o(l);
  1083. }
  1084. return o(e);
  1085. }
  1086. }));
  1087. }
  1088. toJson(e) {
  1089. const t = this._ensureRangeThemeStyleRuleMap(e), o = this._ensureRangeThemeStyleMap(e);
  1090. if (o.size === 0 && t.size === 0)
  1091. return "{}";
  1092. const s = {};
  1093. t.forEach((i, a) => {
  1094. s[a] = i;
  1095. });
  1096. const r = {};
  1097. return o.forEach((i, a) => {
  1098. r[a] = i.toJson();
  1099. }), JSON.stringify({
  1100. rangeThemeStyleRuleMap: s,
  1101. rangeThemeStyleMapJson: r
  1102. });
  1103. }
  1104. fromJSON(e) {
  1105. const { rangeThemeStyleRuleMap: t, rangeThemeStyleMapJson: o } = e;
  1106. this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._rTreeCollection.clear(), !(!t || !o) && (Object.keys(t).forEach((s) => {
  1107. const r = t[s], { themeName: i, rangeInfo: a } = r;
  1108. this.registerRangeThemeRule(i, a), this._ensureRTreeCollection(a.unitId).insert({ unitId: s, sheetId: a.subUnitId, range: a.range, id: s });
  1109. }), Object.keys(o).forEach((s) => {
  1110. const r = o[s], i = new yt(r.name);
  1111. i.fromJson(r), this._ensureRangeThemeStyleMap(s).set(i.getName(), i);
  1112. }));
  1113. }
  1114. deleteUnitId(e) {
  1115. this._rangeThemeStyleMap.delete(e), this._rangeThemeStyleRuleMap.delete(e), this._rTreeCollection.delete(e);
  1116. }
  1117. _initSnapshot() {
  1118. this.disposeWithMe(this._resourceManagerService.registerPluginResource({
  1119. toJson: (e) => this.toJson(e),
  1120. parseJson: (e) => {
  1121. if (!e)
  1122. return {};
  1123. try {
  1124. return JSON.parse(e);
  1125. } catch {
  1126. return {};
  1127. }
  1128. },
  1129. businesses: [B.UNIVER_SHEET],
  1130. pluginName: Ia,
  1131. onLoad: (e, t) => {
  1132. this.fromJSON(t);
  1133. },
  1134. onUnLoad: (e) => {
  1135. this.deleteUnitId(e);
  1136. }
  1137. }));
  1138. }
  1139. dispose() {
  1140. super.dispose(), this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._defaultRangeThemeMap.clear(), this._rTreeCollection.clear();
  1141. }
  1142. };
  1143. He = wa([
  1144. Ko(0, L(V)),
  1145. Ko(1, L(nn))
  1146. ], He);
  1147. function va(n, e) {
  1148. const { unitId: t } = e, o = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(B.UNIVER_SHEET);
  1149. return o ? {
  1150. workbook: o,
  1151. unitId: o.getUnitId()
  1152. } : null;
  1153. }
  1154. function N(n, e = {}) {
  1155. const { unitId: t, subUnitId: o } = e, s = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(B.UNIVER_SHEET);
  1156. if (!s) return null;
  1157. const r = o ? s.getSheetBySheetId(o) : s.getActiveSheet(!0);
  1158. return r ? {
  1159. worksheet: r,
  1160. workbook: s,
  1161. unitId: s.getUnitId(),
  1162. subUnitId: r.getSheetId()
  1163. } : null;
  1164. }
  1165. function Et(n, e) {
  1166. const { unitId: t, subUnitId: o } = e, s = n.getUniverSheetInstance(t);
  1167. if (!s) return null;
  1168. const r = s.getSheetBySheetId(o);
  1169. return r ? {
  1170. worksheet: r,
  1171. workbook: s
  1172. } : null;
  1173. }
  1174. const zt = {
  1175. id: "sheet.mutation.set-worksheet-range-theme-style",
  1176. type: v.MUTATION,
  1177. handler: (n, e) => {
  1178. const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = N(i), u = n.get(He);
  1179. return a ? (u.registerRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1;
  1180. }
  1181. }, Ma = (n, e) => {
  1182. const t = Et(n.get(M), e);
  1183. if (!t)
  1184. throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");
  1185. const { worksheet: o } = t;
  1186. return {
  1187. unitId: e.unitId,
  1188. subUnitId: o.getSheetId(),
  1189. range: e.range,
  1190. themeName: e.themeName
  1191. };
  1192. }, Kt = {
  1193. id: "sheet.mutation.remove-worksheet-range-theme-style",
  1194. type: v.MUTATION,
  1195. handler: (n, e) => {
  1196. const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = N(i), u = n.get(He);
  1197. return a ? (u.removeRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1;
  1198. }
  1199. }, _a = (n, e) => {
  1200. const t = Et(n.get(M), e);
  1201. if (!t)
  1202. throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");
  1203. const { worksheet: o } = t;
  1204. return {
  1205. unitId: e.unitId,
  1206. subUnitId: o.getSheetId(),
  1207. range: e.range,
  1208. themeName: e.themeName
  1209. };
  1210. }, ba = {
  1211. type: v.COMMAND,
  1212. id: "sheet.command.set-worksheet-range-theme-style",
  1213. handler: (n, e) => {
  1214. const t = n.get(E), o = n.get(W), { unitId: s } = e, r = Ma(n, e);
  1215. return t.syncExecuteCommand(zt.id, e) ? (o.pushUndoRedo({
  1216. unitID: s,
  1217. undoMutations: [{ id: Kt.id, params: r }],
  1218. redoMutations: [{ id: zt.id, params: e }]
  1219. }), !0) : !1;
  1220. }
  1221. }, ya = (n, e, t = "") => n.reduce(
  1222. (o, s) => {
  1223. const r = s && s[e];
  1224. 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);
  1225. },
  1226. {}
  1227. ), Ea = (n = 0) => {
  1228. let e = n;
  1229. return function() {
  1230. return e++;
  1231. };
  1232. };
  1233. function Os(n) {
  1234. const e = new G();
  1235. return n.forEach((t) => {
  1236. const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
  1237. for (let a = o; a <= r; a++)
  1238. for (let u = s; u <= i; u++)
  1239. e.setValue(a, u, null);
  1240. }), e.clone();
  1241. }
  1242. function Ua(n) {
  1243. const e = new G();
  1244. return n.forEach((t) => {
  1245. const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
  1246. for (let a = o; a <= r; a++)
  1247. for (let u = s; u <= i; u++)
  1248. e.setValue(a, u, {
  1249. v: null,
  1250. p: null,
  1251. f: null,
  1252. si: null,
  1253. custom: null
  1254. });
  1255. }), e.clone();
  1256. }
  1257. function Pa(n) {
  1258. const e = new G();
  1259. return n.forEach((t) => {
  1260. const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
  1261. for (let a = o; a <= r; a++)
  1262. for (let u = s; u <= i; u++)
  1263. e.setValue(a, u, {
  1264. s: null
  1265. });
  1266. }), e.clone();
  1267. }
  1268. var Ce = /* @__PURE__ */ ((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 || {});
  1269. class Ta extends ae {
  1270. constructor(t) {
  1271. super();
  1272. /**
  1273. * Selection data model for each worksheet.
  1274. */
  1275. R(this, "_worksheetSelections", /* @__PURE__ */ new Map());
  1276. R(this, "_selectionMoveStart$", new Le());
  1277. R(this, "selectionMoveStart$", this._selectionMoveStart$.asObservable());
  1278. R(this, "_selectionMoving$", new Le());
  1279. R(this, "selectionMoving$", this._selectionMoving$.asObservable());
  1280. R(this, "_selectionMoveEnd$", new at([]));
  1281. R(this, "selectionMoveEnd$", this._selectionMoveEnd$.asObservable());
  1282. R(this, "_selectionSet$", new at([]));
  1283. R(this, "selectionSet$", this._selectionSet$.asObservable());
  1284. R(this, "selectionChanged$");
  1285. R(this, "_beforeSelectionMoveEnd$", new at([]));
  1286. R(this, "beforeSelectionMoveEnd$", this._beforeSelectionMoveEnd$.asObservable());
  1287. this._workbook = t, this.selectionChanged$ = xt(this._selectionMoveEnd$, this._selectionSet$);
  1288. }
  1289. dispose() {
  1290. super.dispose(), this._beforeSelectionMoveEnd$.complete(), this._selectionMoveEnd$.complete(), this._selectionMoving$.complete(), this._selectionMoveStart$.complete(), this._selectionSet$.complete();
  1291. }
  1292. addSelections(t, o) {
  1293. const s = this.getSelectionsOfWorksheet(t);
  1294. s.push(...o), this._selectionSet$.next(s);
  1295. }
  1296. /**
  1297. * Set selectionDatas to _worksheetSelections, and emit selectionDatas by type.
  1298. * @param sheetId
  1299. * @param selectionDatas
  1300. * @param type
  1301. */
  1302. setSelections(t, o = [], s) {
  1303. switch (this.setSelectionsOfWorksheet(t, o), s) {
  1304. case Ce.MOVE_START:
  1305. this._selectionMoveStart$.next(o);
  1306. break;
  1307. case Ce.MOVING:
  1308. this._selectionMoving$.next(o);
  1309. break;
  1310. case Ce.MOVE_END:
  1311. this._beforeSelectionMoveEnd$.next(o), this._selectionMoveEnd$.next(o);
  1312. break;
  1313. case Ce.ONLY_SET: {
  1314. this._selectionSet$.next(o);
  1315. break;
  1316. }
  1317. default:
  1318. this._selectionSet$.next(o);
  1319. break;
  1320. }
  1321. }
  1322. getCurrentSelections() {
  1323. return this._getCurrentSelections();
  1324. }
  1325. /**
  1326. * @deprecated use `getSelectionsOfWorksheet` instead.
  1327. * @param sheetId
  1328. * @returns
  1329. */
  1330. getSelectionOfWorksheet(t) {
  1331. return this.getSelectionsOfWorksheet(t);
  1332. }
  1333. getSelectionsOfWorksheet(t) {
  1334. return this._worksheetSelections.has(t) || this._worksheetSelections.set(t, []), this._worksheetSelections.get(t);
  1335. }
  1336. setSelectionsOfWorksheet(t, o) {
  1337. this._worksheetSelections.set(t, [...o]);
  1338. }
  1339. deleteSheetSelection(t) {
  1340. this._worksheetSelections.set(t, []);
  1341. }
  1342. /** Clear all selections in this workbook. */
  1343. clear() {
  1344. this._worksheetSelections.clear(), this._selectionSet$.next([]);
  1345. }
  1346. _getCurrentSelections() {
  1347. return this.getSelectionsOfWorksheet(this._workbook.getActiveSheet().getSheetId());
  1348. }
  1349. getCurrentLastSelection() {
  1350. const t = this._getCurrentSelections();
  1351. return t[t.length - 1];
  1352. }
  1353. }
  1354. var ka = Object.defineProperty, Na = Object.getOwnPropertyDescriptor, Oa = (n, e, t, o) => {
  1355. for (var s = o > 1 ? void 0 : o ? Na(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  1356. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  1357. return o && s && ka(e, t, s), s;
  1358. }, Da = (n, e) => (t, o) => e(t, o, n);
  1359. let F = class extends ps {
  1360. constructor(e) {
  1361. super();
  1362. /**
  1363. * Selection Events, usually triggered when pointerdown in spreadsheet by selection render service after selectionModel has updated.
  1364. */
  1365. R(this, "selectionMoveStart$");
  1366. /**
  1367. * Selection Events, usually triggered when pointermove in spreadsheet by selection render service after selectionModel has updated.
  1368. */
  1369. R(this, "selectionMoving$");
  1370. /**
  1371. * Selection Events, usually triggered when pointerup in spreadsheet by selection render service after selectionModel has updated.
  1372. */
  1373. R(this, "selectionMoveEnd$");
  1374. /**
  1375. * Selection Events, usually triggered when changing unit.(focus in formula editor)
  1376. */
  1377. R(this, "selectionSet$");
  1378. /**
  1379. * Selection Events, merge moveEnd$ and selectionSet$
  1380. */
  1381. R(this, "selectionChanged$");
  1382. R(this, "_workbookSelections", /* @__PURE__ */ new Map());
  1383. this._instanceSrv = e, this._init();
  1384. }
  1385. get _currentSelectionPos() {
  1386. const e = this._instanceSrv.getCurrentUnitForType(B.UNIVER_SHEET);
  1387. if (!e) return null;
  1388. const t = e.getActiveSheet();
  1389. return { unitId: e.getUnitId(), sheetId: t.getSheetId() };
  1390. }
  1391. get currentSelectionParam() {
  1392. return this._currentSelectionPos;
  1393. }
  1394. _init() {
  1395. const e = this._instanceSrv.getCurrentTypeOfUnit$(B.UNIVER_SHEET).pipe(ji(1), io(this.dispose$));
  1396. this.selectionMoveStart$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveStart$ : Ot())), this.selectionMoving$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoving$ : Ot())), this.selectionMoveEnd$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionMoveEnd$ : Ot([]))), this.selectionSet$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionSet$ : Ot([]))), this.selectionChanged$ = e.pipe(Ge((t) => t ? this._ensureWorkbookSelection(t.getUnitId()).selectionChanged$ : Ot([]))).pipe(
  1397. Gi((t, o) => t.length !== o.length ? !1 : t.length === 0 && o.length === 0 ? !0 : t.every((s, r) => JSON.stringify(s) === JSON.stringify(o[r]))),
  1398. Ts(1)
  1399. ), this._instanceSrv.getTypeOfUnitDisposed$(B.UNIVER_SHEET).pipe(io(this.dispose$)).subscribe((t) => {
  1400. this._removeWorkbookSelection(t.getUnitId());
  1401. });
  1402. }
  1403. /**
  1404. * Clear all selections in all workbooks.
  1405. * invoked by prompt.controller
  1406. */
  1407. clear() {
  1408. this._workbookSelections.forEach((e) => e.clear());
  1409. }
  1410. getCurrentSelections() {
  1411. return this._getCurrentSelections();
  1412. }
  1413. getCurrentLastSelection() {
  1414. const e = this._getCurrentSelections();
  1415. return e == null ? void 0 : e[e.length - 1];
  1416. }
  1417. addSelections(e, t, o) {
  1418. if (typeof e == "string") {
  1419. this._ensureWorkbookSelection(e).addSelections(t, o);
  1420. return;
  1421. }
  1422. const s = this._currentSelectionPos;
  1423. if (!s)
  1424. throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
  1425. const { unitId: r, sheetId: i } = s;
  1426. this._ensureWorkbookSelection(r).addSelections(i, e);
  1427. }
  1428. setSelections(e, t, o, s) {
  1429. if (typeof e == "string" && typeof t == "string") {
  1430. const u = e;
  1431. this._ensureWorkbookSelection(u).setSelections(
  1432. t,
  1433. o || [],
  1434. s != null ? s : Ce.ONLY_SET
  1435. );
  1436. return;
  1437. }
  1438. const r = this._currentSelectionPos;
  1439. if (!r)
  1440. throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
  1441. const { unitId: i, sheetId: a } = r;
  1442. if (typeof e == "object") {
  1443. const u = e != null ? e : o, l = t != null ? t : Ce.ONLY_SET;
  1444. this._ensureWorkbookSelection(i).setSelections(a, u, l);
  1445. }
  1446. }
  1447. clearCurrentSelections() {
  1448. this._getCurrentSelections().splice(0);
  1449. }
  1450. /**
  1451. * Determine whether multiple current selections overlap
  1452. *
  1453. * @deprecated this should be extracted to an pure function
  1454. */
  1455. isOverlapping() {
  1456. const e = this.getCurrentSelections();
  1457. return e == null ? !1 : e.some(
  1458. ({ range: t }, o) => e.some(({ range: s }, r) => o === r ? !1 : t.startRow <= s.endRow && t.endRow >= s.startRow && t.startColumn <= s.endColumn && t.endColumn >= s.startColumn)
  1459. );
  1460. }
  1461. _getCurrentSelections() {
  1462. const e = this._currentSelectionPos;
  1463. if (!e)
  1464. return [];
  1465. const { unitId: t, sheetId: o } = e;
  1466. return this._ensureWorkbookSelection(t).getSelectionsOfWorksheet(o);
  1467. }
  1468. getWorkbookSelections(e) {
  1469. return this._ensureWorkbookSelection(e);
  1470. }
  1471. _ensureWorkbookSelection(e) {
  1472. let t = this._workbookSelections.get(e);
  1473. if (!t) {
  1474. const o = this._instanceSrv.getUnit(e);
  1475. if (!o)
  1476. throw new Error(`[SheetsSelectionsService]: cannot resolve unit with id "${e}"!`);
  1477. t = new Ta(o), this._workbookSelections.set(e, t);
  1478. }
  1479. return t;
  1480. }
  1481. _removeWorkbookSelection(e) {
  1482. this._workbookSelections.delete(e);
  1483. }
  1484. };
  1485. F = Oa([
  1486. Da(0, M)
  1487. ], F);
  1488. const jd = "DISABLE_NORMAL_SELECTIONS", Gd = "SELECTIONS_ENABLED", Aa = "REF_SELECTIONS_ENABLED";
  1489. function xa(n, e, t) {
  1490. var i;
  1491. const o = n.getStyleByCell(e);
  1492. o == null && delete e.s, typeof t.s == "string" && (t.s = n.get(t.s));
  1493. const s = gn(o, t.s ? t.s : null);
  1494. s && (O.removeNull(s), Object.entries(s).forEach(([a, u]) => {
  1495. typeof u == "object" && u !== null && Object.keys(u).length === 0 && delete s[a];
  1496. })), O.isEmptyObject(s) ? delete e.s : e.s = n.setValue(s);
  1497. const r = t.v ? `${t.v}\r
  1498. ` : "";
  1499. !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));
  1500. }
  1501. function $a(n, e) {
  1502. if (!e || !Object.keys(e).length)
  1503. return n;
  1504. const t = n || {};
  1505. for (const o in e)
  1506. o === "bd" ? t[o] = Wa(t[o] || {}, e[o]) : o in t || (t[o] = null);
  1507. return t;
  1508. }
  1509. function Wa(n, e) {
  1510. if (!e || !Object.keys(e).length)
  1511. return n;
  1512. for (const t in e)
  1513. t in n || (n[t] = null);
  1514. return n;
  1515. }
  1516. function gn(n, e, t = !1) {
  1517. if (e === null) return e;
  1518. if (e === void 0) return n;
  1519. const o = O.deepClone(n) || {};
  1520. for (const s in e)
  1521. 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]);
  1522. 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;
  1523. }
  1524. function Ds(n, e) {
  1525. return n.some((t) => t.startIndex === e) ? Ds(n, e + 1) : e;
  1526. }
  1527. function La(n, e) {
  1528. var i;
  1529. if (n.body == null)
  1530. return;
  1531. Array.isArray(n.body.textRuns) || (n.body.textRuns = []);
  1532. let t = 0;
  1533. const o = [], s = ((i = n.body) == null ? void 0 : i.paragraphs) || [];
  1534. for (const a of n.body.textRuns) {
  1535. const { st: u, ed: l, ts: c = {} } = a;
  1536. if (t < u) {
  1537. const h = {
  1538. st: t,
  1539. ed: u
  1540. }, m = gn({}, e, !0);
  1541. m && O.removeNull(m), O.isEmptyObject(m) || (h.ts = m), o.push(h);
  1542. }
  1543. const d = gn(c, e, !0);
  1544. d && O.removeNull(d), O.isEmptyObject(d) ? delete a.ts : a.ts = d, o.push(a), t = Ds(s, l);
  1545. }
  1546. const r = n.body.dataStream.endsWith(`\r
  1547. `) ? n.body.dataStream.length - 2 : n.body.dataStream.length;
  1548. if (t < r) {
  1549. const a = {
  1550. st: t,
  1551. ed: r
  1552. }, u = gn({}, e, !0);
  1553. u && O.removeNull(u), O.isEmptyObject(u) || (a.ts = u), o.push(a);
  1554. }
  1555. n.body.textRuns = ci(o);
  1556. }
  1557. function Va(n, e, t) {
  1558. if (e.t) return e.t;
  1559. if (e.v === null) return null;
  1560. const o = n.getStyleByCell(e), s = n.getStyleByCell(t);
  1561. if (t.t === se.FORCE_STRING) {
  1562. if (!Qn(s) && e.v !== void 0) {
  1563. if (go(e.v))
  1564. return se.NUMBER;
  1565. if (Cs(`${e.v}`))
  1566. return se.BOOLEAN;
  1567. }
  1568. return se.FORCE_STRING;
  1569. }
  1570. return Ha(o) ? Qn(o) ? se.STRING : Jo(e, t) : Qn(s) ? se.STRING : Jo(e, t);
  1571. }
  1572. function Jo(n, e) {
  1573. return n.v !== void 0 ? Yo(n.v, n.t) : Yo(e.v, e.t);
  1574. }
  1575. function Ha(n) {
  1576. var e;
  1577. return !!((e = n == null ? void 0 : n.n) != null && e.pattern);
  1578. }
  1579. function Qn(n) {
  1580. var e;
  1581. return ((e = n == null ? void 0 : n.n) == null ? void 0 : e.pattern) === ks;
  1582. }
  1583. function Yo(n, e) {
  1584. return n === null ? null : typeof n == "string" ? go(n) ? (+n == 0 || +n == 1) && e === se.BOOLEAN ? se.BOOLEAN : se.NUMBER : Cs(n) ? se.BOOLEAN : se.STRING : typeof n == "number" ? (n === 0 || n === 1) && e === se.BOOLEAN ? se.BOOLEAN : se.NUMBER : typeof n == "boolean" ? se.BOOLEAN : se.FORCE_STRING;
  1585. }
  1586. function Xo(n, e) {
  1587. return n === se.NUMBER ? Number(e.v) : n === se.BOOLEAN ? Ba(e.v) ? 1 : 0 : n === se.STRING || n === se.FORCE_STRING ? `${e.v}` : e.v;
  1588. }
  1589. function Ba(n) {
  1590. if (typeof n == "string") {
  1591. if (n.toUpperCase() === "TRUE")
  1592. return !0;
  1593. if (n.toUpperCase() === "FALSE")
  1594. return !1;
  1595. if (di(n)) {
  1596. if (Number(n) === 0)
  1597. return !1;
  1598. if (Number(n) === 1)
  1599. return !0;
  1600. }
  1601. }
  1602. if (typeof n == "number") {
  1603. if (n === 0)
  1604. return !1;
  1605. if (n === 1)
  1606. return !0;
  1607. }
  1608. return typeof n == "boolean" ? n : null;
  1609. }
  1610. function Fa(n) {
  1611. 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);
  1612. }
  1613. const Ae = (n, e) => {
  1614. const { unitId: t, subUnitId: o, cellValue: s } = e, i = n.get(M).getUniverSheetInstance(t);
  1615. if (i == null)
  1616. throw new Error("workbook is null error!");
  1617. const a = i.getSheetBySheetId(o);
  1618. if (a == null)
  1619. throw new Error("worksheet is null error!");
  1620. const u = a.getCellMatrix(), l = i.getStyles(), c = new G();
  1621. return new G(s).forValue((h, m, g) => {
  1622. const f = O.deepClone(u == null ? void 0 : u.getValue(h, m)) || {}, p = l.getStyleByCell(f), C = l.getStyleByCell(g);
  1623. f.s = $a(p, C), c.setValue(h, m, Fa(f));
  1624. }), {
  1625. ...e,
  1626. options: {},
  1627. cellValue: c.getMatrix()
  1628. };
  1629. }, Q = {
  1630. id: "sheet.mutation.set-range-values",
  1631. type: v.MUTATION,
  1632. handler: (n, e) => {
  1633. const { cellValue: t, subUnitId: o, unitId: s } = e, i = n.get(M).getUnit(s);
  1634. if (!i)
  1635. return !1;
  1636. const a = i.getSheetBySheetId(o);
  1637. if (!a)
  1638. return !1;
  1639. const u = a.getCellMatrix(), l = i.getStyles();
  1640. return new G(t).forValue((d, h, m) => {
  1641. if (!m)
  1642. u == null || u.setValue(d, h, {});
  1643. else {
  1644. const g = u.getValue(d, h) || {}, f = Va(l, m, g);
  1645. m.f !== void 0 && (g.f = m.f), m.si !== void 0 && (g.si = m.si), m.p !== void 0 && (g.p = m.p), m.v !== void 0 && (g.v = Xo(f, m)), g.v !== void 0 && (g.t = f, g.v = Xo(f, g)), m.s !== void 0 && xa(l, g, m), m.custom !== void 0 && (g.custom = m.custom), u.setValue(d, h, O.removeNull(g));
  1646. }
  1647. }), !0;
  1648. }
  1649. }, po = {
  1650. id: "sheet.command.clear-selection-all",
  1651. type: v.COMMAND,
  1652. handler: (n, e) => {
  1653. var S;
  1654. const t = n.get(M), o = n.get(E), s = n.get(F), r = n.get(W), i = n.get(V), a = t.getCurrentUnitForType(B.UNIVER_SHEET);
  1655. if (!a) return !1;
  1656. const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
  1657. if (!l) return !1;
  1658. 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));
  1659. if (!(d != null && d.length))
  1660. return !1;
  1661. const h = [], m = [], g = {
  1662. subUnitId: c,
  1663. unitId: u,
  1664. cellValue: Os(d)
  1665. }, f = Ae(
  1666. n,
  1667. g
  1668. );
  1669. h.push({
  1670. id: Q.id,
  1671. params: g
  1672. }), m.push({
  1673. id: Q.id,
  1674. params: f
  1675. });
  1676. const p = i.onCommandExecute({ id: po.id });
  1677. return h.push(...p.redos), m.unshift(...p.undos), z(h, o) ? (r.pushUndoRedo({
  1678. // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
  1679. // Hooks can be used to hook the code of external controllers to add new actions.
  1680. unitID: u,
  1681. undoMutations: m,
  1682. redoMutations: h
  1683. }), !0) : !1;
  1684. }
  1685. }, Co = {
  1686. id: "sheet.command.clear-selection-content",
  1687. type: v.COMMAND,
  1688. handler: (n, e) => {
  1689. var S;
  1690. const t = n.get(M), o = n.get(E), s = n.get(F), r = n.get(W), i = n.get(V), a = t.getCurrentUnitForType(B.UNIVER_SHEET);
  1691. if (!a) return !1;
  1692. const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
  1693. if (!l) return !1;
  1694. 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));
  1695. if (!(d != null && d.length))
  1696. return !1;
  1697. const h = {
  1698. subUnitId: c,
  1699. unitId: u,
  1700. cellValue: Ua(d)
  1701. }, m = Ae(
  1702. n,
  1703. h
  1704. ), g = i.onCommandExecute({ id: Co.id }), f = [{ id: Q.id, params: h }, ...g.redos], p = [...g.undos, { id: Q.id, params: m }];
  1705. return z(f, o).result ? (r.pushUndoRedo({
  1706. // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
  1707. // Hooks can be used to hook the code of external controllers to add new actions.
  1708. unitID: u,
  1709. undoMutations: p,
  1710. redoMutations: f
  1711. }), !0) : !1;
  1712. }
  1713. }, So = {
  1714. id: "sheet.command.clear-selection-format",
  1715. type: v.COMMAND,
  1716. handler: (n, e) => {
  1717. var S;
  1718. const t = n.get(M), o = n.get(E), s = n.get(F), r = n.get(W), i = n.get(V), a = t.getCurrentUnitForType(B.UNIVER_SHEET);
  1719. if (!a) return !1;
  1720. const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
  1721. if (!l) return !1;
  1722. 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));
  1723. if (!(d != null && d.length))
  1724. return !1;
  1725. const h = [], m = [], g = {
  1726. subUnitId: c,
  1727. unitId: u,
  1728. cellValue: Pa(d)
  1729. }, f = Ae(
  1730. n,
  1731. g
  1732. );
  1733. h.push({
  1734. id: Q.id,
  1735. params: g
  1736. }), m.push({
  1737. id: Q.id,
  1738. params: f
  1739. });
  1740. const p = i.onCommandExecute({ id: So.id });
  1741. return h.push(...p.redos), m.unshift(...p.undos), z(h, o) ? (r.pushUndoRedo({
  1742. // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
  1743. // Hooks can be used to hook the code of external controllers to add new actions.
  1744. unitID: u,
  1745. undoMutations: m,
  1746. redoMutations: h
  1747. }), !0) : !1;
  1748. }
  1749. }, As = (n, e) => ({
  1750. subUnitId: e.sheet.id,
  1751. unitId: e.unitId,
  1752. subUnitName: e.sheet.name
  1753. }), Jt = {
  1754. id: "sheet.mutation.insert-sheet",
  1755. type: v.MUTATION,
  1756. handler: (n, e) => {
  1757. const t = n.get(M), { sheet: o, index: s, unitId: r } = e, i = t.getUniverSheetInstance(r);
  1758. return i ? i.addWorksheet(o.id, s, o) : !1;
  1759. }
  1760. }, ja = (n, e) => {
  1761. const t = n.get(M), { subUnitId: o, unitId: s } = e, r = Et(t, e);
  1762. if (!r)
  1763. throw new Error("[RemoveSheetUndoMutationFactory]: Worksheet is null error!");
  1764. const { workbook: i, worksheet: a } = r, u = a.getConfig();
  1765. return {
  1766. index: i.getConfig().sheetOrder.findIndex((d) => d === o),
  1767. sheet: u,
  1768. unitId: s
  1769. };
  1770. }, Ut = {
  1771. id: "sheet.mutation.remove-sheet",
  1772. type: v.MUTATION,
  1773. handler: (n, e) => {
  1774. const t = n.get(M), { subUnitId: o, unitId: s } = e, r = t.getUniverSheetInstance(s);
  1775. return r ? r.removeSheet(o) : !1;
  1776. }
  1777. }, xs = {
  1778. type: v.COMMAND,
  1779. id: "sheet.command.copy-sheet",
  1780. handler: (n, e) => {
  1781. var w, b;
  1782. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = n.get(Ke), a = N(s, e);
  1783. if (!a)
  1784. return !1;
  1785. const { workbook: u, worksheet: l, unitId: c, subUnitId: d } = a, h = O.deepClone(l.getConfig());
  1786. h.name = Ga(u, i, h.name), h.id = O.generateRandomId();
  1787. const g = {
  1788. index: u.getSheetIndex(l) + 1,
  1789. sheet: h,
  1790. unitId: c
  1791. }, f = As(
  1792. n,
  1793. g
  1794. ), p = r.onCommandExecute({
  1795. id: xs.id,
  1796. params: { unitId: c, subUnitId: d, targetSubUnitId: h.id }
  1797. }), C = [
  1798. ...(w = p.preRedos) != null ? w : [],
  1799. { id: Jt.id, params: g },
  1800. ...p.redos
  1801. ], S = [
  1802. ...(b = p.preUndos) != null ? b : [],
  1803. { id: Ut.id, params: f },
  1804. ...p.undos
  1805. ];
  1806. return z(C, t).result ? (o.pushUndoRedo({
  1807. unitID: c,
  1808. undoMutations: S,
  1809. redoMutations: C
  1810. }), !0) : !1;
  1811. }
  1812. };
  1813. function Ga(n, e, t) {
  1814. let o = t + e.t("sheets.tabs.sheetCopy", ""), s = 2;
  1815. for (; n.checkSheetName(o); )
  1816. o = t + e.t("sheets.tabs.sheetCopy", `${s}`), s++;
  1817. return o;
  1818. }
  1819. const dt = {
  1820. id: "sheet.mutation.move-range",
  1821. type: v.MUTATION,
  1822. handler: (n, e) => {
  1823. const { from: t, to: o } = e;
  1824. if (!t || !o)
  1825. return !1;
  1826. const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
  1827. if (!r)
  1828. return !1;
  1829. const i = r.getSheetBySheetId(e.from.subUnitId), a = r.getSheetBySheetId(e.to.subUnitId);
  1830. if (!i || !a)
  1831. return !1;
  1832. const u = i.getCellMatrix(), l = a.getCellMatrix();
  1833. return new G(t.value).forValue((c, d, h) => {
  1834. u.setValue(c, d, h);
  1835. }), new G(o.value).forValue((c, d, h) => {
  1836. l.setValue(c, d, h);
  1837. }), !0;
  1838. }
  1839. };
  1840. var za = Object.defineProperty, Ka = Object.getOwnPropertyDescriptor, Ja = (n, e, t, o) => {
  1841. for (var s = o > 1 ? void 0 : o ? Ka(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  1842. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  1843. return o && s && za(e, t, s), s;
  1844. }, Ya = (n, e) => (t, o) => e(t, o, n);
  1845. const Xa = fo("sheets-formula.ref-selections.service");
  1846. let qo = class extends F {
  1847. constructor(n) {
  1848. super(n);
  1849. }
  1850. _init() {
  1851. const n = this._getAliveWorkbooks$().pipe(io(this.dispose$));
  1852. this.selectionMoveStart$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionMoveStart$)))), this.selectionMoving$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionMoving$)))), this.selectionMoveEnd$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionMoveEnd$)))), this.selectionSet$ = n.pipe(Ge((e) => xt(...e.map((t) => t.selectionSet$))));
  1853. }
  1854. _getAliveWorkbooks$() {
  1855. const n = this._instanceSrv.getAllUnitsForType(B.UNIVER_SHEET);
  1856. n.forEach((t) => this._ensureWorkbookSelection(t.getUnitId()));
  1857. const e = new at(n);
  1858. return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((t) => {
  1859. this._ensureWorkbookSelection(t.getUnitId()), e.next([...e.getValue(), t]);
  1860. })), this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe((t) => {
  1861. this._removeWorkbookSelection(t.getUnitId()), e.next(e.getValue().filter((o) => o !== t));
  1862. })), e.pipe(ao((t) => t.map((o) => this._ensureWorkbookSelection(o.getUnitId()))));
  1863. }
  1864. };
  1865. qo = Ja([
  1866. Ya(0, M)
  1867. ], qo);
  1868. function qa(n, e) {
  1869. const o = n.get(Ss).getContextValue(Aa);
  1870. return n.get(o && !e ? Xa : F);
  1871. }
  1872. const re = {
  1873. id: "sheet.operation.set-selections",
  1874. type: v.OPERATION,
  1875. handler: (n, e) => {
  1876. if (!e) return !1;
  1877. const { selections: t, type: o, unitId: s, subUnitId: r } = e;
  1878. return qa(n).setSelections(s, r, [...t], o), !0;
  1879. }
  1880. };
  1881. function Ln(n, e, t = !0) {
  1882. const o = e.getMatrixWithMergedCells(...hi(n)), s = [];
  1883. if (o.forValue((i, a, u) => {
  1884. if (u.colSpan !== void 0 && u.rowSpan !== void 0) {
  1885. const l = {
  1886. startRow: i,
  1887. startColumn: a,
  1888. endRow: i + u.rowSpan - 1,
  1889. endColumn: a + u.colSpan - 1
  1890. };
  1891. k.contains(n, l) || s.push(l);
  1892. }
  1893. }), s.length === 0)
  1894. return n;
  1895. const r = k.union(n, ...s);
  1896. return t ? Ln(r, e, t) : r;
  1897. }
  1898. function zd(n, e, t) {
  1899. let o = null;
  1900. return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = {
  1901. actualRow: r,
  1902. actualColumn: i,
  1903. startRow: r,
  1904. startColumn: i,
  1905. isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0,
  1906. isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0,
  1907. endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0),
  1908. endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0),
  1909. rangeType: H.NORMAL
  1910. }, !1)), o || {
  1911. actualColumn: e,
  1912. actualRow: n,
  1913. startRow: n,
  1914. startColumn: e,
  1915. endRow: n,
  1916. endColumn: e,
  1917. isMerged: !1,
  1918. isMergedMainCell: !1,
  1919. rangeType: H.NORMAL
  1920. };
  1921. }
  1922. function Kd(n, e, t) {
  1923. const { startRow: o, startColumn: s, endRow: r, endColumn: i } = n;
  1924. 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;
  1925. }
  1926. function ve(n, e) {
  1927. const t = Number.isNaN(n.startRow) ? 0 : n.startRow, o = Number.isNaN(n.startColumn) ? 0 : n.startColumn, s = e.getMergedCell(t, o);
  1928. return s ? {
  1929. ...s,
  1930. actualRow: t,
  1931. actualColumn: o,
  1932. rangeType: H.NORMAL,
  1933. isMerged: !0,
  1934. isMergedMainCell: !0
  1935. } : {
  1936. startRow: t,
  1937. startColumn: o,
  1938. endRow: n.startRow,
  1939. endColumn: n.startColumn,
  1940. actualRow: t,
  1941. actualColumn: o,
  1942. rangeType: H.NORMAL,
  1943. isMerged: !1,
  1944. isMergedMainCell: !1
  1945. };
  1946. }
  1947. const Xe = (n, e, t) => ({
  1948. id: re.id,
  1949. params: {
  1950. unitId: e.getUnitId(),
  1951. subUnitId: t.getSheetId(),
  1952. reveal: !0,
  1953. selections: [{ range: n, primary: ve(n, t) }]
  1954. }
  1955. });
  1956. function Jd(n) {
  1957. if (!n)
  1958. return !1;
  1959. const { range: e, primary: t } = n;
  1960. return k.equals(e, t);
  1961. }
  1962. function Za(n) {
  1963. function e(t, o) {
  1964. function s(r) {
  1965. for (let i = r.startRow; i <= r.endRow; i++)
  1966. if (!n.getRowFiltered(i))
  1967. for (let a = r.startColumn; a <= r.endColumn; a++)
  1968. o(i, a, r);
  1969. }
  1970. s(t);
  1971. }
  1972. return {
  1973. forOperableEach: e
  1974. };
  1975. }
  1976. const Zo = (n) => n.id !== Ns;
  1977. function Vn(n, e, t, o, s, r, i) {
  1978. const a = {};
  1979. for (let u = e; u <= t; u++)
  1980. for (let l = o; l <= s; l++) {
  1981. const c = r ? n.getCellWithFilteredInterceptors(i, l, jo, Zo) : n.getCellWithFilteredInterceptors(u, i, jo, Zo);
  1982. !c || !c.s || (a[u] || (a[u] = {}), a[u][l] = { s: c.s });
  1983. }
  1984. return a;
  1985. }
  1986. const $s = "sheet.command.move-range", pt = {
  1987. type: v.COMMAND,
  1988. id: $s,
  1989. handler: async (n, e) => {
  1990. var I, w;
  1991. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(bt), i = n.get(Ke), a = n.get(V), u = N(s);
  1992. if (!u || !await a.beforeCommandExecute({ id: pt.id, params: e }))
  1993. return !1;
  1994. const { worksheet: c, subUnitId: d, unitId: h } = u, m = wo(
  1995. n,
  1996. { unitId: h, subUnitId: d, range: e.fromRange },
  1997. { unitId: h, subUnitId: d, range: e.toRange }
  1998. );
  1999. if (m === null)
  2000. return r.emit(i.t("sheets.info.acrossMergedCell")), !1;
  2001. const g = a.onCommandExecute({
  2002. id: pt.id,
  2003. params: { ...e }
  2004. }), f = [
  2005. ...(I = g.preRedos) != null ? I : [],
  2006. ...m.redos,
  2007. ...g.redos,
  2008. {
  2009. id: re.id,
  2010. params: {
  2011. unitId: h,
  2012. subUnitId: d,
  2013. selections: [{ range: e.toRange, primary: Qa(e.fromRange, e.toRange, c) }],
  2014. type: Ce.MOVE_END
  2015. }
  2016. }
  2017. ], p = [
  2018. ...(w = g.preUndos) != null ? w : [],
  2019. ...m.undos,
  2020. ...g.undos,
  2021. {
  2022. id: re.id,
  2023. params: {
  2024. unitId: h,
  2025. subUnitId: d,
  2026. selections: [{ range: e.fromRange, primary: ve(e.fromRange, c) }],
  2027. type: Ce.MOVE_END
  2028. }
  2029. }
  2030. ], C = z(f, t).result, S = a.afterCommandExecute({
  2031. id: pt.id,
  2032. params: { ...e }
  2033. });
  2034. return C ? (z(S.redos, t), o.pushUndoRedo({
  2035. unitID: h,
  2036. undoMutations: [...p, ...S.undos],
  2037. redoMutations: [...f, ...S.redos]
  2038. }), !0) : !1;
  2039. }
  2040. };
  2041. function wo(n, e, t, o = !1) {
  2042. const s = [], r = [], { range: i, subUnitId: a, unitId: u } = e, { range: l, subUnitId: c } = t, h = n.get(M).getUniverSheetInstance(u), m = h == null ? void 0 : h.getSheetBySheetId(c), g = h == null ? void 0 : h.getSheetBySheetId(a), f = m == null ? void 0 : m.getCellMatrix(), p = g == null ? void 0 : g.getCellMatrix();
  2043. if (m && g && f && p) {
  2044. const C = Ln(l, m, !1);
  2045. if (!k.equals(l, C) && !o)
  2046. return null;
  2047. const S = new G(), I = new G(), w = new G();
  2048. K.foreach(i, (U, P) => {
  2049. const A = p.getValue(U, P);
  2050. if (S.setValue(U, P, O.deepClone(A)), A) {
  2051. const j = h == null ? void 0 : h.getStyles().get(A.s);
  2052. w.setValue(U, P, O.deepClone(j));
  2053. }
  2054. I.setValue(U, P, null);
  2055. });
  2056. const b = new G(), y = new G();
  2057. K.foreach(l, (U, P) => {
  2058. b.setValue(U, P, O.deepClone(f.getValue(U, P)));
  2059. }), K.foreach(i, (U, P) => {
  2060. const A = ws(U, P), j = k.getRelativeRange(A, i), Z = k.getPositionRange(j, l), Y = O.deepClone(w.getValue(U, P)), ee = O.deepClone(S.getValue(U, P));
  2061. ee && Y && (ee.s = Y), y.setValue(Z.startRow, Z.startColumn, ee);
  2062. });
  2063. const x = {
  2064. fromRange: e.range,
  2065. toRange: t.range,
  2066. from: {
  2067. value: I.getMatrix(),
  2068. subUnitId: a
  2069. },
  2070. to: {
  2071. value: y.getMatrix(),
  2072. subUnitId: c
  2073. },
  2074. unitId: u
  2075. }, T = {
  2076. fromRange: t.range,
  2077. toRange: e.range,
  2078. from: {
  2079. value: S.getMatrix(),
  2080. subUnitId: a
  2081. },
  2082. to: {
  2083. value: b.getMatrix(),
  2084. subUnitId: c
  2085. },
  2086. unitId: u
  2087. };
  2088. s.push({ id: dt.id, params: x }), r.push({ id: dt.id, params: T });
  2089. }
  2090. return {
  2091. redos: s,
  2092. undos: r
  2093. };
  2094. }
  2095. function Qa(n, e, t) {
  2096. const o = n.startRow, s = n.startColumn, r = t.getMergedCell(o, s), i = ve(e, t);
  2097. if (r) {
  2098. const a = r.endRow - r.startRow + 1, u = r.endColumn - r.startColumn + 1;
  2099. i.endRow = i.startRow + a - 1, i.endColumn = i.startColumn + u - 1, i.actualRow = i.startRow, i.actualColumn = i.startColumn, i.isMerged = !1, i.isMergedMainCell = !0;
  2100. }
  2101. return i;
  2102. }
  2103. var Sn = /* @__PURE__ */ ((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 || {}), _ = /* @__PURE__ */ ((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))(_ || {}), D = /* @__PURE__ */ ((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 || {});
  2104. class Pe {
  2105. constructor(e, t, o) {
  2106. R(this, "type", D.SelectRange);
  2107. R(this, "subType", _.Edit);
  2108. R(this, "status", J.INIT);
  2109. R(this, "value", !0);
  2110. R(this, "id");
  2111. R(this, "unitId");
  2112. R(this, "subUnitId");
  2113. R(this, "permissionId");
  2114. this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Edit}.${o}`;
  2115. }
  2116. }
  2117. class Io {
  2118. constructor(e, t, o) {
  2119. R(this, "type", D.SelectRange);
  2120. R(this, "subType", _.View);
  2121. R(this, "status", J.INIT);
  2122. R(this, "value", !0);
  2123. R(this, "id");
  2124. R(this, "unitId");
  2125. R(this, "subUnitId");
  2126. R(this, "permissionId");
  2127. this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.View}.${o}`;
  2128. }
  2129. }
  2130. class Ws {
  2131. constructor(e) {
  2132. R(this, "id");
  2133. R(this, "value", !0);
  2134. R(this, "type", D.Workbook);
  2135. R(this, "status", J.INIT);
  2136. R(this, "subType", _.Comment);
  2137. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Comment}_${e}`;
  2138. }
  2139. }
  2140. class Ls {
  2141. constructor(e) {
  2142. R(this, "id");
  2143. R(this, "value", !0);
  2144. R(this, "type", D.Workbook);
  2145. R(this, "status", J.INIT);
  2146. R(this, "subType", _.Copy);
  2147. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Copy}_${e}`;
  2148. }
  2149. }
  2150. class eu {
  2151. constructor(e) {
  2152. R(this, "id");
  2153. R(this, "value", !0);
  2154. R(this, "type", D.Workbook);
  2155. R(this, "subType", _.CopySheet);
  2156. R(this, "status", J.INIT);
  2157. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CopySheet}_${e}`;
  2158. }
  2159. }
  2160. class Vs {
  2161. constructor(e) {
  2162. R(this, "id");
  2163. R(this, "value", !0);
  2164. R(this, "type", D.Workbook);
  2165. R(this, "status", J.INIT);
  2166. R(this, "subType", _.CreatePermissionObject);
  2167. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreatePermissionObject}_${e}`;
  2168. }
  2169. }
  2170. class Hs {
  2171. constructor(e) {
  2172. R(this, "id");
  2173. R(this, "value", !0);
  2174. R(this, "type", D.Workbook);
  2175. R(this, "status", J.INIT);
  2176. R(this, "subType", _.CreateSheet);
  2177. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreateSheet}_${e}`;
  2178. }
  2179. }
  2180. class Bs {
  2181. constructor(e) {
  2182. R(this, "id");
  2183. R(this, "value", !0);
  2184. R(this, "type", D.Workbook);
  2185. R(this, "status", J.INIT);
  2186. R(this, "subType", _.DeleteSheet);
  2187. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.DeleteSheet}_${e}`;
  2188. }
  2189. }
  2190. class Fs {
  2191. constructor(e) {
  2192. R(this, "id");
  2193. R(this, "value", !0);
  2194. R(this, "type", D.Workbook);
  2195. R(this, "status", J.INIT);
  2196. R(this, "subType", _.Duplicate);
  2197. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Duplicate}_${e}`;
  2198. }
  2199. }
  2200. class Me {
  2201. constructor(e) {
  2202. R(this, "id");
  2203. R(this, "value", !0);
  2204. R(this, "type", D.Workbook);
  2205. R(this, "status", J.INIT);
  2206. R(this, "subType", _.Edit);
  2207. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Edit}_${e}`;
  2208. }
  2209. }
  2210. class js {
  2211. constructor(e) {
  2212. R(this, "id");
  2213. R(this, "value", !0);
  2214. R(this, "type", D.Workbook);
  2215. R(this, "status", J.INIT);
  2216. R(this, "subType", _.Export);
  2217. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Export}_${e}`;
  2218. }
  2219. }
  2220. class vo {
  2221. constructor(e) {
  2222. R(this, "id");
  2223. R(this, "value", !0);
  2224. R(this, "type", D.Workbook);
  2225. R(this, "status", J.INIT);
  2226. R(this, "subType", _.HideSheet);
  2227. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.HideSheet}_${e}`;
  2228. }
  2229. }
  2230. class tu {
  2231. constructor(e) {
  2232. R(this, "id");
  2233. R(this, "value", !0);
  2234. R(this, "type", D.Workbook);
  2235. R(this, "status", J.INIT);
  2236. R(this, "subType", _.History);
  2237. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.History}_${e}`;
  2238. }
  2239. }
  2240. class Mo {
  2241. constructor(e) {
  2242. R(this, "id");
  2243. R(this, "value", !0);
  2244. R(this, "type", D.Workbook);
  2245. R(this, "status", J.INIT);
  2246. R(this, "subType", _.ManageCollaborator);
  2247. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ManageCollaborator}_${e}`;
  2248. }
  2249. }
  2250. class _o {
  2251. constructor(e) {
  2252. R(this, "id");
  2253. R(this, "value", !0);
  2254. R(this, "type", D.Workbook);
  2255. R(this, "status", J.INIT);
  2256. R(this, "subType", _.MoveSheet);
  2257. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.MoveSheet}_${e}`;
  2258. }
  2259. }
  2260. class Gs {
  2261. constructor(e) {
  2262. R(this, "id");
  2263. R(this, "value", !0);
  2264. R(this, "type", D.Workbook);
  2265. R(this, "status", J.INIT);
  2266. R(this, "subType", _.Print);
  2267. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Print}_${e}`;
  2268. }
  2269. }
  2270. class zs {
  2271. constructor(e) {
  2272. R(this, "id");
  2273. R(this, "value", !0);
  2274. R(this, "type", D.Workbook);
  2275. R(this, "status", J.INIT);
  2276. R(this, "subType", _.RecoverHistory);
  2277. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RecoverHistory}_${e}`;
  2278. }
  2279. }
  2280. class bo {
  2281. constructor(e) {
  2282. R(this, "id");
  2283. R(this, "value", !0);
  2284. R(this, "type", D.Workbook);
  2285. R(this, "status", J.INIT);
  2286. R(this, "subType", _.RenameSheet);
  2287. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RenameSheet}_${e}`;
  2288. }
  2289. }
  2290. class Ks {
  2291. constructor(e) {
  2292. R(this, "id");
  2293. R(this, "value", !0);
  2294. R(this, "type", D.Workbook);
  2295. R(this, "status", J.INIT);
  2296. R(this, "subType", _.Share);
  2297. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Share}_${e}`;
  2298. }
  2299. }
  2300. class Js {
  2301. constructor(e) {
  2302. R(this, "id");
  2303. R(this, "value", !0);
  2304. R(this, "type", D.Workbook);
  2305. R(this, "status", J.INIT);
  2306. R(this, "subType", _.View);
  2307. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.View}_${e}`;
  2308. }
  2309. }
  2310. class Ys {
  2311. constructor(e) {
  2312. R(this, "id");
  2313. R(this, "value", !0);
  2314. R(this, "type", D.Workbook);
  2315. R(this, "status", J.INIT);
  2316. R(this, "subType", _.ViewHistory);
  2317. this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ViewHistory}_${e}`;
  2318. }
  2319. }
  2320. class Xs {
  2321. constructor(e, t) {
  2322. R(this, "value", !0);
  2323. R(this, "type", D.Worksheet);
  2324. R(this, "status", J.INIT);
  2325. R(this, "id");
  2326. R(this, "subType", _.Copy);
  2327. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Copy}_${e}_${t}`;
  2328. }
  2329. }
  2330. class qs {
  2331. constructor(e, t) {
  2332. R(this, "value", !0);
  2333. R(this, "type", D.Worksheet);
  2334. R(this, "status", J.INIT);
  2335. R(this, "id");
  2336. R(this, "subType", _.DeleteColumn);
  2337. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteColumn}_${e}_${t}`;
  2338. }
  2339. }
  2340. class Zs {
  2341. constructor(e, t) {
  2342. R(this, "value", !0);
  2343. R(this, "type", D.Worksheet);
  2344. R(this, "status", J.INIT);
  2345. R(this, "id");
  2346. R(this, "subType", _.Delete);
  2347. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Delete}_${e}_${t}`;
  2348. }
  2349. }
  2350. class Qs {
  2351. constructor(e, t) {
  2352. R(this, "value", !0);
  2353. R(this, "type", D.Worksheet);
  2354. R(this, "status", J.INIT);
  2355. R(this, "id");
  2356. R(this, "subType", _.DeleteRow);
  2357. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteRow}_${e}_${t}`;
  2358. }
  2359. }
  2360. class Te {
  2361. constructor(e, t) {
  2362. R(this, "value", !0);
  2363. R(this, "type", D.Worksheet);
  2364. R(this, "status", J.INIT);
  2365. R(this, "id");
  2366. R(this, "subType", _.Edit);
  2367. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Edit}_${e}_${t}`;
  2368. }
  2369. }
  2370. class er {
  2371. constructor(e, t) {
  2372. R(this, "value", !0);
  2373. R(this, "type", D.Worksheet);
  2374. R(this, "status", J.INIT);
  2375. R(this, "id");
  2376. R(this, "subType", _.EditExtraObject);
  2377. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.EditExtraObject}_${e}_${t}`;
  2378. }
  2379. }
  2380. class tr {
  2381. constructor(e, t) {
  2382. R(this, "value", !0);
  2383. R(this, "type", D.Worksheet);
  2384. R(this, "status", J.INIT);
  2385. R(this, "id");
  2386. R(this, "subType", _.Filter);
  2387. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Filter}_${e}_${t}`;
  2388. }
  2389. }
  2390. class nr {
  2391. constructor(e, t) {
  2392. R(this, "value", !0);
  2393. R(this, "type", D.Worksheet);
  2394. R(this, "status", J.INIT);
  2395. R(this, "id");
  2396. R(this, "subType", _.InsertColumn);
  2397. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertColumn}_${e}_${t}`;
  2398. }
  2399. }
  2400. class or {
  2401. constructor(e, t) {
  2402. R(this, "value", !0);
  2403. R(this, "type", D.Worksheet);
  2404. R(this, "status", J.INIT);
  2405. R(this, "id");
  2406. R(this, "subType", _.InsertHyperlink);
  2407. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertHyperlink}_${e}_${t}`;
  2408. }
  2409. }
  2410. class sr {
  2411. constructor(e, t) {
  2412. R(this, "value", !0);
  2413. R(this, "type", D.Worksheet);
  2414. R(this, "status", J.INIT);
  2415. R(this, "id");
  2416. R(this, "subType", _.InsertRow);
  2417. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertRow}_${e}_${t}`;
  2418. }
  2419. }
  2420. class rr {
  2421. constructor(e, t) {
  2422. R(this, "value", !0);
  2423. R(this, "type", D.Worksheet);
  2424. R(this, "status", J.INIT);
  2425. R(this, "id");
  2426. R(this, "subType", _.ManageCollaborator);
  2427. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.ManageCollaborator}_${e}_${t}`;
  2428. }
  2429. }
  2430. class ir {
  2431. constructor(e, t) {
  2432. R(this, "value", !0);
  2433. R(this, "type", D.Worksheet);
  2434. R(this, "status", J.INIT);
  2435. R(this, "id");
  2436. R(this, "subType", _.PivotTable);
  2437. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.PivotTable}_${e}_${t}`;
  2438. }
  2439. }
  2440. class nu {
  2441. constructor(e, t) {
  2442. R(this, "value", !0);
  2443. R(this, "type", D.Worksheet);
  2444. R(this, "status", J.INIT);
  2445. R(this, "id");
  2446. R(this, "subType", _.SelectProtectedCells);
  2447. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectProtectedCells}_${e}_${t}`;
  2448. }
  2449. }
  2450. class ou {
  2451. constructor(e, t) {
  2452. R(this, "value", !0);
  2453. R(this, "type", D.Worksheet);
  2454. R(this, "status", J.INIT);
  2455. R(this, "id");
  2456. R(this, "subType", _.SelectUnProtectedCells);
  2457. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`;
  2458. }
  2459. }
  2460. class ar {
  2461. constructor(e, t) {
  2462. R(this, "value", !0);
  2463. R(this, "type", D.Worksheet);
  2464. R(this, "status", J.INIT);
  2465. R(this, "id");
  2466. R(this, "subType", _.SetCellStyle);
  2467. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellStyle}_${e}_${t}`;
  2468. }
  2469. }
  2470. class wn {
  2471. constructor(e, t) {
  2472. R(this, "value", !0);
  2473. R(this, "type", D.Worksheet);
  2474. R(this, "status", J.INIT);
  2475. R(this, "id");
  2476. R(this, "subType", _.SetCellValue);
  2477. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellValue}_${e}_${t}`;
  2478. }
  2479. }
  2480. class $t {
  2481. constructor(e, t) {
  2482. R(this, "value", !0);
  2483. R(this, "type", D.Worksheet);
  2484. R(this, "status", J.INIT);
  2485. R(this, "id");
  2486. R(this, "subType", _.SetColumnStyle);
  2487. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetColumnStyle}_${e}_${t}`;
  2488. }
  2489. }
  2490. class Wt {
  2491. constructor(e, t) {
  2492. R(this, "value", !0);
  2493. R(this, "type", D.Worksheet);
  2494. R(this, "status", J.INIT);
  2495. R(this, "id");
  2496. R(this, "subType", _.SetRowStyle);
  2497. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetRowStyle}_${e}_${t}`;
  2498. }
  2499. }
  2500. class ur {
  2501. constructor(e, t) {
  2502. R(this, "value", !0);
  2503. R(this, "type", D.Worksheet);
  2504. R(this, "status", J.INIT);
  2505. R(this, "id");
  2506. R(this, "subType", _.Sort);
  2507. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Sort}_${e}_${t}`;
  2508. }
  2509. }
  2510. class Hn {
  2511. constructor(e, t) {
  2512. R(this, "value", !0);
  2513. R(this, "type", D.Worksheet);
  2514. R(this, "status", J.INIT);
  2515. R(this, "id");
  2516. R(this, "subType", _.View);
  2517. this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.View}_${e}_${t}`;
  2518. }
  2519. }
  2520. const on = {
  2521. id: "sheet.command.set-range-values",
  2522. type: v.COMMAND,
  2523. handler: (n, e) => {
  2524. var T;
  2525. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = n.get(Fe), u = N(s, e);
  2526. if (!u) return !1;
  2527. const { subUnitId: l, unitId: c, workbook: d, worksheet: h } = u, { value: m, range: g } = e, f = g ? [g] : (T = r.getCurrentSelections()) == null ? void 0 : T.map((U) => U.range);
  2528. if (!f || !f.length || !a.getPermissionPoint(new Te(c, l).id)) return !1;
  2529. const p = new G();
  2530. let C;
  2531. if (O.isArray(m))
  2532. for (let U = 0; U < f.length; U++) {
  2533. const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U];
  2534. for (let Y = 0; Y <= j - P; Y++)
  2535. for (let ee = 0; ee <= Z - A; ee++)
  2536. p.setValue(Y + P, ee + A, m[Y][ee]);
  2537. }
  2538. else if (Is(m))
  2539. for (let U = 0; U < f.length; U++) {
  2540. const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U];
  2541. for (let Y = P; Y <= j; Y++)
  2542. for (let ee = A; ee <= Z; ee++)
  2543. p.setValue(Y, ee, m);
  2544. }
  2545. else
  2546. C = m;
  2547. const S = { subUnitId: l, unitId: c, cellValue: C != null ? C : p.getMatrix() }, I = Ae(n, S);
  2548. if (!t.syncExecuteCommand(Q.id, S)) return !1;
  2549. const { undos: b, redos: y } = i.onCommandExecute({
  2550. id: on.id,
  2551. params: { ...S, range: f }
  2552. });
  2553. if (z([...y], t).result) {
  2554. const U = Xe(g != null ? g : p.getRange(), d, h);
  2555. return o.pushUndoRedo({
  2556. unitID: c,
  2557. undoMutations: [
  2558. { id: Q.id, params: I },
  2559. ...b,
  2560. U
  2561. ],
  2562. redoMutations: [
  2563. { id: Q.id, params: S },
  2564. ...y,
  2565. O.deepClone(U)
  2566. ]
  2567. }), !0;
  2568. }
  2569. return !1;
  2570. }
  2571. };
  2572. function lr(n, e) {
  2573. const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a, cellValue: u = {} } = e, l = n.get(M), c = n.get(V), d = l.getUniverSheetInstance(s), h = d == null ? void 0 : d.getSheetBySheetId(r);
  2574. if (h) {
  2575. const m = h.getCellMatrix(), g = m.getDataRange();
  2576. if (i.startColumn <= g.endColumn || i.startRow <= g.endRow) {
  2577. let I, w;
  2578. if (a === ge.COLUMNS) {
  2579. const y = Math.min(i.endRow, g.endRow);
  2580. let x = 0;
  2581. for (let U = i.startRow; U <= y; U++) {
  2582. const P = m.getRow(U), A = P ? vs(P) - 1 : 0;
  2583. x = Math.max(x, A);
  2584. }
  2585. I = {
  2586. startRow: i.startRow,
  2587. startColumn: i.startColumn,
  2588. endRow: y,
  2589. endColumn: x
  2590. };
  2591. const T = i.endColumn - i.startColumn + 1;
  2592. w = {
  2593. startRow: i.startRow,
  2594. startColumn: I.startColumn + T,
  2595. endRow: y,
  2596. endColumn: I.endColumn + T
  2597. };
  2598. } else {
  2599. const y = Math.min(i.endColumn, g.endColumn), x = g.endRow;
  2600. I = {
  2601. startRow: i.startRow,
  2602. startColumn: i.startColumn,
  2603. endRow: x,
  2604. endColumn: y
  2605. };
  2606. const T = i.endRow - i.startRow + 1;
  2607. w = {
  2608. startRow: I.startRow + T,
  2609. startColumn: i.startColumn,
  2610. endRow: I.endRow + T,
  2611. endColumn: y
  2612. };
  2613. }
  2614. const b = wo(
  2615. n,
  2616. { unitId: s, subUnitId: r, range: I },
  2617. { unitId: s, subUnitId: r, range: w },
  2618. !0
  2619. );
  2620. b && (t.push(...b.redos), o.push(...b.undos));
  2621. }
  2622. if (Object.entries(u).length === 0)
  2623. for (let I = i.startRow; I <= i.endRow; I++) {
  2624. u[I] || (u[I] = {});
  2625. for (let w = i.startColumn; w <= i.endColumn; w++)
  2626. u[I][w] = null;
  2627. }
  2628. const f = {
  2629. subUnitId: r,
  2630. unitId: s,
  2631. cellValue: u
  2632. }, p = Ae(
  2633. n,
  2634. f
  2635. ), { undos: C, redos: S } = c.onCommandExecute({
  2636. id: on.id,
  2637. params: { ...f, range: i }
  2638. });
  2639. t.push({ id: Q.id, params: f }, ...S), o.push({ id: Q.id, params: p }, ...C);
  2640. }
  2641. return {
  2642. redo: t,
  2643. undo: o
  2644. };
  2645. }
  2646. function cr(n, e) {
  2647. const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a } = e, u = n.get(M), l = n.get(V), c = u.getUniverSheetInstance(s), d = c == null ? void 0 : c.getSheetBySheetId(r);
  2648. if (d) {
  2649. const h = d.getCellMatrix(), m = h.getDataRange(), g = {
  2650. subUnitId: r,
  2651. unitId: s,
  2652. cellValue: Os([i])
  2653. }, f = Ae(
  2654. n,
  2655. g
  2656. ), p = l.onCommandExecute({
  2657. id: on.id,
  2658. params: g
  2659. });
  2660. if (t.push({ id: Q.id, params: g }, ...p.redos), o.push(...p.undos, {
  2661. id: Q.id,
  2662. params: f
  2663. }), i.startColumn <= m.endColumn || i.startRow <= m.endRow) {
  2664. let C = null, S = null;
  2665. if (a === ge.COLUMNS && i.endColumn < m.endColumn) {
  2666. const I = Math.min(i.endRow, m.endRow);
  2667. let w = 0;
  2668. for (let y = i.startRow; y <= I; y++) {
  2669. const x = h.getRow(y), T = x ? vs(x) - 1 : 0;
  2670. w = Math.max(w, T);
  2671. }
  2672. C = {
  2673. startRow: i.startRow,
  2674. startColumn: i.endColumn + 1,
  2675. endRow: I,
  2676. endColumn: w
  2677. };
  2678. const b = i.endColumn - i.startColumn + 1;
  2679. S = {
  2680. startRow: i.startRow,
  2681. startColumn: C.startColumn - b,
  2682. endRow: I,
  2683. endColumn: C.endColumn - b
  2684. };
  2685. }
  2686. if (a === ge.ROWS && i.endRow < m.endRow) {
  2687. const I = Math.min(i.endColumn, m.endColumn), w = m.endRow;
  2688. C = {
  2689. startRow: i.endRow + 1,
  2690. startColumn: i.startColumn,
  2691. endRow: w,
  2692. endColumn: I
  2693. };
  2694. const b = i.endRow - i.startRow + 1;
  2695. S = {
  2696. startRow: C.startRow - b,
  2697. startColumn: i.startColumn,
  2698. endRow: C.endRow - b,
  2699. endColumn: I
  2700. };
  2701. }
  2702. if (C && S) {
  2703. const I = wo(
  2704. n,
  2705. { unitId: s, subUnitId: r, range: C },
  2706. { unitId: s, subUnitId: r, range: S },
  2707. !0
  2708. );
  2709. I && (t.push(...I.redos), o.push(...I.undos));
  2710. }
  2711. }
  2712. }
  2713. return {
  2714. redo: t,
  2715. undo: o
  2716. };
  2717. }
  2718. function Yd(n, e, t, o, s, r) {
  2719. const { startRow: i, endRow: a, startColumn: u, endColumn: l } = e;
  2720. if (s === ge.ROWS) {
  2721. const c = a - i + 1;
  2722. for (let d = t; d >= i; d--)
  2723. for (let h = u; h <= l; h++) {
  2724. const m = n.getValue(d, h);
  2725. m == null ? n.realDeleteValue(d + c, h) : n.setValue(d + c, h, m);
  2726. }
  2727. for (let d = a; d >= i; d--)
  2728. for (let h = u; h <= l; h++)
  2729. r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h);
  2730. } else if (s === ge.COLUMNS) {
  2731. const c = l - u + 1;
  2732. for (let d = i; d <= a; d++)
  2733. for (let h = o; h >= u; h--) {
  2734. const m = n.getValue(d, h);
  2735. m == null ? n.realDeleteValue(d, h + c) : n.setValue(d, h + c, m);
  2736. }
  2737. for (let d = i; d <= a; d++)
  2738. for (let h = l; h >= u; h--)
  2739. r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h);
  2740. }
  2741. }
  2742. function Xd(n, e, t, o, s) {
  2743. const { startRow: r, endRow: i, startColumn: a, endColumn: u } = e, l = i - r + 1, c = u - a + 1;
  2744. if (s === ge.ROWS)
  2745. for (let d = r; d <= t; d++)
  2746. for (let h = a; h <= u; h++) {
  2747. const m = n.getValue(d + l, h);
  2748. m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m);
  2749. }
  2750. else if (s === ge.COLUMNS)
  2751. for (let d = r; d <= i; d++)
  2752. for (let h = a; h <= o; h++) {
  2753. const m = n.getValue(d, h + c);
  2754. m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m);
  2755. }
  2756. }
  2757. const dr = "sheet.command.delete-range-move-left", Pt = {
  2758. type: v.COMMAND,
  2759. id: dr,
  2760. handler: async (n, e) => {
  2761. var w, b, y;
  2762. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = N(s);
  2763. if (!a) return !1;
  2764. const { worksheet: u, workbook: l, subUnitId: c, unitId: d } = a;
  2765. let h = e == null ? void 0 : e.range;
  2766. if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h) return !1;
  2767. const m = {
  2768. range: h,
  2769. subUnitId: c,
  2770. unitId: d,
  2771. shiftDimension: ge.COLUMNS
  2772. }, g = i.onCommandExecute({
  2773. id: Pt.id,
  2774. params: { range: h }
  2775. }), { redo: f, undo: p } = cr(
  2776. n,
  2777. m
  2778. ), C = [...(b = g.preRedos) != null ? b : [], ...f], S = [...g.undos, ...p];
  2779. return C.push(...g.redos), C.push(Xe(h, l, u)), S.push(...(y = g.preUndos) != null ? y : []), z(C, t).result ? (o.pushUndoRedo({
  2780. unitID: d,
  2781. undoMutations: S.reverse(),
  2782. redoMutations: C
  2783. }), !0) : !1;
  2784. }
  2785. // all subsequent mutations should succeed inorder to make the whole process succeed
  2786. // Promise.all([]).then(() => true),
  2787. }, hr = "sheet.command.delete-range-move-up", Tt = {
  2788. type: v.COMMAND,
  2789. id: hr,
  2790. handler: async (n, e) => {
  2791. var w, b, y;
  2792. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = N(s);
  2793. if (!a) return !1;
  2794. const { unitId: u, subUnitId: l, workbook: c, worksheet: d } = a;
  2795. let h = e == null ? void 0 : e.range;
  2796. if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h) return !1;
  2797. const m = {
  2798. range: h,
  2799. subUnitId: l,
  2800. unitId: u,
  2801. shiftDimension: ge.ROWS
  2802. }, g = i.onCommandExecute({
  2803. id: Tt.id,
  2804. params: { range: h }
  2805. }), { redo: f, undo: p } = cr(
  2806. n,
  2807. m
  2808. ), C = [...(b = g.preRedos) != null ? b : [], ...f], S = [...g.undos, ...p];
  2809. return C.push(...g.redos), C.push(Xe(h, c, d)), S.push(...(y = g.preUndos) != null ? y : []), z(C, t).result ? (o.pushUndoRedo({
  2810. unitID: u,
  2811. undoMutations: S.reverse(),
  2812. redoMutations: C
  2813. }), !0) : !1;
  2814. }
  2815. // all subsequent mutations should succeed inorder to make the whole process succeed
  2816. // Promise.all([]).then(() => true),
  2817. }, su = {
  2818. type: v.COMMAND,
  2819. id: "sheet.command.delete-range-protection",
  2820. async handler(n, e) {
  2821. if (!e)
  2822. return !1;
  2823. const t = n.get(E), o = n.get(W), { unitId: s, subUnitId: r, rule: i } = e, a = {
  2824. unitId: s,
  2825. subUnitId: r,
  2826. ruleIds: [i.id]
  2827. };
  2828. return await t.executeCommand(ze.id, a) && o.pushUndoRedo({
  2829. unitID: s,
  2830. redoMutations: [{ id: ze.id, params: a }],
  2831. undoMutations: [{ id: Ne.id, params: { unitId: s, subUnitId: r, rules: [i] } }]
  2832. }), !0;
  2833. }
  2834. }, ru = {
  2835. type: v.COMMAND,
  2836. id: "sheet.command.delete-worksheet-protection",
  2837. handler(n, e) {
  2838. if (!e)
  2839. return !1;
  2840. const t = n.get(E), o = n.get(W), { rule: s, unitId: r, subUnitId: i } = e;
  2841. t.executeCommand(St.id, {
  2842. unitId: r,
  2843. subUnitId: i
  2844. });
  2845. const a = [{ id: St.id, params: { unitId: r, subUnitId: i } }], u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: i } }];
  2846. return o.pushUndoRedo({
  2847. unitID: r,
  2848. redoMutations: a,
  2849. undoMutations: u
  2850. }), !0;
  2851. }
  2852. }, iu = {
  2853. type: v.COMMAND,
  2854. id: "sheet.command.remove-worksheet-range-theme-style",
  2855. handler: (n, e) => {
  2856. const t = n.get(E), o = n.get(W), { unitId: s } = e, r = _a(n, e);
  2857. return t.syncExecuteCommand(Kt.id, e) ? (o.pushUndoRedo({
  2858. unitID: s,
  2859. undoMutations: [{ id: zt.id, params: r }],
  2860. redoMutations: [{ id: Kt.id, params: e }]
  2861. }), !0) : !1;
  2862. }
  2863. }, au = {
  2864. id: "sheet.command.insert-defined-name",
  2865. type: v.COMMAND,
  2866. handler: (n, e) => {
  2867. const t = n.get(E), o = n.get(W);
  2868. if (!e) return !1;
  2869. const s = {
  2870. ...e
  2871. };
  2872. return t.syncExecuteCommand(Gt.id, s) ? (o.pushUndoRedo({
  2873. unitID: e.unitId,
  2874. undoMutations: [{ id: Cn.id, params: s }],
  2875. redoMutations: [{ id: Gt.id, params: s }]
  2876. }), !0) : !1;
  2877. }
  2878. }, mr = (n, e) => {
  2879. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  2880. throw new Error("universheet is null error!");
  2881. return {
  2882. unitId: e.unitId,
  2883. subUnitId: e.subUnitId,
  2884. range: e.range
  2885. };
  2886. }, qe = {
  2887. id: "sheet.mutation.insert-row",
  2888. type: v.MUTATION,
  2889. handler: (n, e) => {
  2890. var g;
  2891. const { unitId: t, subUnitId: o, range: s, rowInfo: r } = e, a = n.get(M).getUniverSheetInstance(t);
  2892. if (a == null)
  2893. throw new Error("universheet is null error!");
  2894. const u = a.getSheetBySheetId(o);
  2895. if (u == null)
  2896. throw new Error("worksheet is null error!");
  2897. const l = u.getRowManager().getRowData(), c = {
  2898. h: u.getConfig().defaultRowHeight,
  2899. hd: 0
  2900. }, d = s.startRow, h = s.endRow - s.startRow + 1;
  2901. for (let f = d; f < d + h; f++)
  2902. r ? pn(f, (g = r[f - s.startRow]) != null ? g : c, l) : pn(f, c, l);
  2903. return u.setRowCount(u.getRowCount() + s.endRow - s.startRow + 1), u.getCellMatrix().insertRows(s.startRow, h), !0;
  2904. }
  2905. }, yo = (n, e) => {
  2906. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  2907. throw new Error("universheet is null error!");
  2908. return {
  2909. unitId: e.unitId,
  2910. subUnitId: e.subUnitId,
  2911. range: e.range
  2912. };
  2913. }, je = {
  2914. id: "sheet.mutation.insert-col",
  2915. type: v.MUTATION,
  2916. handler: (n, e) => {
  2917. var g;
  2918. const o = n.get(M).getUniverSheetInstance(e.unitId);
  2919. if (o == null)
  2920. throw new Error("universheet is null error!");
  2921. const s = o.getSheetBySheetId(e.subUnitId);
  2922. if (!s) return !1;
  2923. 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;
  2924. for (let f = c; f < c + d; f++) {
  2925. const p = {
  2926. w: h,
  2927. hd: 0
  2928. };
  2929. a ? pn(f, (g = a[f - i.startColumn]) != null ? g : p, l) : pn(f, p, l);
  2930. }
  2931. return s.setColumnCount(s.getColumnCount() + i.endColumn - i.startColumn + 1), s.getCellMatrix().insertColumns(i.startColumn, d), !0;
  2932. }
  2933. }, uu = (n, e) => {
  2934. const s = e.getRowManager().getRowData(), r = {}, i = n.range, a = _s(i.startRow, i.endRow, s), u = bs(r, a);
  2935. return {
  2936. unitId: n.unitId,
  2937. subUnitId: n.subUnitId,
  2938. range: n.range,
  2939. rowInfo: u
  2940. };
  2941. }, Be = {
  2942. id: "sheet.mutation.remove-rows",
  2943. type: v.MUTATION,
  2944. handler: (n, e) => {
  2945. const o = n.get(M).getUniverSheetInstance(e.unitId);
  2946. if (o == null)
  2947. throw new Error("universheet is null error!");
  2948. const s = o.getSheetBySheetId(e.subUnitId);
  2949. if (!s) return !1;
  2950. const r = e.range, a = s.getRowManager().getRowData();
  2951. for (let c = r.startRow; c <= r.endRow; c++)
  2952. s.getRowFiltered(c);
  2953. const u = r.endRow - r.startRow + 1;
  2954. return Ms(r.startRow, u, a), s.getCellMatrix().removeRows(r.startRow, u), s.setRowCount(s.getRowCount() - u), !0;
  2955. }
  2956. }, lu = (n, e) => {
  2957. const o = n.get(M).getUniverSheetInstance(e.unitId);
  2958. if (o == null)
  2959. throw new Error("universheet is null error!");
  2960. const s = o.getSheetBySheetId(e.subUnitId);
  2961. if (s == null)
  2962. throw new Error("worksheet is null error!");
  2963. const a = s.getColumnManager().getColumnData(), u = {}, l = e.range, c = _s(l.startColumn, l.endColumn, a), d = bs(u, c);
  2964. return {
  2965. unitId: e.unitId,
  2966. subUnitId: e.subUnitId,
  2967. range: e.range,
  2968. colInfo: d
  2969. };
  2970. }, De = {
  2971. id: "sheet.mutation.remove-col",
  2972. type: v.MUTATION,
  2973. handler: (n, e) => {
  2974. const o = n.get(M).getUniverSheetInstance(e.unitId);
  2975. if (o == null)
  2976. throw new Error("universheet is null error!");
  2977. const s = o.getSheetBySheetId(e.subUnitId);
  2978. if (!s) return !1;
  2979. const r = e.range, a = s.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1;
  2980. return Ms(r.startColumn, u, a), s.setColumnCount(s.getColumnCount() - u), s.getCellMatrix().removeColumns(r.startColumn, u), !0;
  2981. }
  2982. }, cu = "sheet.command.insert-range-move-down", sn = {
  2983. type: v.COMMAND,
  2984. id: "sheet.command.insert-range-move-down",
  2985. // eslint-disable-next-line max-lines-per-function
  2986. handler: async (n, e) => {
  2987. var j, Z, Y;
  2988. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = n.get(bt), u = n.get(Ke);
  2989. if (r.isOverlapping())
  2990. return a.emit(u.t("sheets.info.overlappingSelections")), !1;
  2991. const l = N(s);
  2992. if (!l) return !1;
  2993. const { unitId: c, subUnitId: d, worksheet: h, workbook: m } = l;
  2994. let g = e == null ? void 0 : e.range;
  2995. if (g || (g = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g) return !1;
  2996. const f = [], p = [], C = h.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(S.startRow, S.endRow, g.startColumn, g.endColumn).getDataRange().endRow, b = Math.max(w + (g.endRow - g.startRow + 1) - S.endRow, 0);
  2997. if (b > 0) {
  2998. const ee = g.startRow - 1, Re = h.getRowHeight(ee), ie = {
  2999. unitId: c,
  3000. subUnitId: d,
  3001. range: {
  3002. startRow: S.endRow + 1,
  3003. endRow: S.endRow + b,
  3004. startColumn: S.startColumn,
  3005. endColumn: S.endColumn
  3006. },
  3007. rowInfo: new Array(b).fill(void 0).map(() => ({
  3008. h: Re,
  3009. hd: te.FALSE
  3010. }))
  3011. };
  3012. f.push({
  3013. id: qe.id,
  3014. params: ie
  3015. });
  3016. const xe = mr(
  3017. n,
  3018. ie
  3019. );
  3020. p.push({ id: Be.id, params: xe });
  3021. }
  3022. const y = {};
  3023. K.foreach(g, (ee, Re) => {
  3024. const ie = h.getCell(ee, Re);
  3025. ie && (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s });
  3026. });
  3027. const x = {
  3028. range: g,
  3029. subUnitId: d,
  3030. unitId: c,
  3031. shiftDimension: ge.ROWS,
  3032. cellValue: y
  3033. }, { redo: T, undo: U } = lr(
  3034. n,
  3035. x
  3036. );
  3037. f.push(...T), p.push(...U);
  3038. const P = i.onCommandExecute({
  3039. id: sn.id,
  3040. params: { range: g }
  3041. });
  3042. return f.push(...P.redos), f.push(Xe(g, m, h)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), z(f, t) ? (o.pushUndoRedo({
  3043. unitID: c,
  3044. undoMutations: p.reverse(),
  3045. redoMutations: f
  3046. }), !0) : !1;
  3047. }
  3048. // all subsequent mutations should succeed inorder to make the whole process succeed
  3049. // Promise.all([]).then(() => true),
  3050. }, Eo = "sheet.command.insert-range-move-right", Bn = {
  3051. type: v.COMMAND,
  3052. id: Eo,
  3053. // eslint-disable-next-line max-lines-per-function
  3054. handler: async (n, e) => {
  3055. var j, Z, Y;
  3056. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = n.get(bt), u = n.get(Ke);
  3057. if (r.isOverlapping())
  3058. return a.emit(u.t("sheets.info.overlappingSelections")), !1;
  3059. const l = N(s);
  3060. if (!l) return !1;
  3061. const { workbook: c, worksheet: d, unitId: h, subUnitId: m } = l;
  3062. let g = e == null ? void 0 : e.range;
  3063. if (g || (g = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g) return !1;
  3064. const f = [], p = [], C = d.getCellMatrix(), S = C.getDataRange(), w = C.getSlice(g.startRow, g.endRow, S.startColumn, S.endColumn).getDataRange().endColumn, b = Math.max(
  3065. w + (g.endColumn - g.startColumn + 1) - S.endColumn,
  3066. 0
  3067. );
  3068. if (b > 0) {
  3069. const ee = g.startColumn - 1, Re = d.getColumnWidth(ee), ie = {
  3070. unitId: h,
  3071. subUnitId: m,
  3072. range: {
  3073. startRow: S.startRow + 1,
  3074. endRow: S.endRow,
  3075. startColumn: S.endColumn + 1,
  3076. endColumn: S.endColumn + b
  3077. },
  3078. colInfo: new Array(b).fill(void 0).map(() => ({
  3079. w: Re,
  3080. hd: te.FALSE
  3081. }))
  3082. };
  3083. f.push({
  3084. id: je.id,
  3085. params: ie
  3086. });
  3087. const xe = yo(
  3088. n,
  3089. ie
  3090. );
  3091. p.push({ id: De.id, params: xe });
  3092. }
  3093. const y = {};
  3094. K.foreach(g, (ee, Re) => {
  3095. const ie = d.getCell(ee, Re);
  3096. !ie || !ie.s || (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s });
  3097. });
  3098. const x = {
  3099. range: g,
  3100. subUnitId: m,
  3101. unitId: h,
  3102. shiftDimension: ge.COLUMNS,
  3103. cellValue: y
  3104. }, { redo: T, undo: U } = lr(
  3105. n,
  3106. x
  3107. );
  3108. f.push(...T), p.push(...U);
  3109. const P = i.onCommandExecute({
  3110. id: Bn.id,
  3111. params: { range: g }
  3112. });
  3113. return f.push(...P.redos), f.push(Xe(g, c, d)), p.push(...(Z = P.preUndos) != null ? Z : []), f.unshift(...(Y = P.preRedos) != null ? Y : []), p.unshift(...P.undos), z(f, t).result ? (o.pushUndoRedo({
  3114. unitID: h,
  3115. undoMutations: p.reverse(),
  3116. redoMutations: f
  3117. }), !0) : !1;
  3118. }
  3119. // all subsequent mutations should succeed inorder to make the whole process succeed
  3120. // Promise.all([]).then(() => true),
  3121. }, gr = "sheet.command.insert-row", mt = {
  3122. type: v.COMMAND,
  3123. id: gr,
  3124. handler: async (n, e) => {
  3125. const t = n.get(E), o = n.get(V), { range: s, direction: r, unitId: i, subUnitId: a, cellValue: u } = e;
  3126. return await o.beforeCommandExecute({
  3127. id: mt.id,
  3128. params: e
  3129. }) ? t.syncExecuteCommand(fr.id, {
  3130. range: s,
  3131. direction: r,
  3132. unitId: i,
  3133. subUnitId: a,
  3134. cellValue: u
  3135. }) : !1;
  3136. }
  3137. }, fr = {
  3138. type: v.COMMAND,
  3139. id: "sheet.command.insert-row-by-range",
  3140. handler: (n, e) => {
  3141. var T, U, P, A;
  3142. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = N(s, e);
  3143. if (!i) return !1;
  3144. const { workbook: a, worksheet: u } = i, { range: l, direction: c, unitId: d, subUnitId: h, cellValue: m } = e, { startRow: g, endRow: f } = l;
  3145. l.rangeType = H.ROW;
  3146. const p = c === pe.UP ? g : g - 1, C = u.getRowHeight(p), S = {
  3147. unitId: d,
  3148. subUnitId: h,
  3149. range: l,
  3150. rowInfo: new Array(f - g + 1).fill(void 0).map(() => ({
  3151. h: C,
  3152. hd: te.FALSE
  3153. }))
  3154. // row height should inherit from the anchor row
  3155. }, I = mr(
  3156. n,
  3157. S
  3158. ), w = [{ id: qe.id, params: S }], b = [{ id: Be.id, params: I }];
  3159. m && w.push({
  3160. id: Q.id,
  3161. params: {
  3162. unitId: d,
  3163. subUnitId: h,
  3164. cellValue: m
  3165. }
  3166. });
  3167. const y = r.onCommandExecute({
  3168. id: mt.id,
  3169. params: e
  3170. });
  3171. return w.unshift(...(T = y.preRedos) != null ? T : []), w.push(...(U = y.redos) != null ? U : []), w.push(Xe(l, a, u)), b.unshift(...(P = y.preUndos) != null ? P : []), b.push(...(A = y.undos) != null ? A : []), z(w, t).result ? (o.pushUndoRedo({
  3172. unitID: e.unitId,
  3173. undoMutations: b,
  3174. redoMutations: w
  3175. }), !0) : !1;
  3176. }
  3177. }, du = {
  3178. type: v.COMMAND,
  3179. id: "sheet.command.insert-row-before",
  3180. handler: async (n) => {
  3181. var g;
  3182. const t = (g = n.get(F).getCurrentSelections()) == null ? void 0 : g.map((f) => f.range);
  3183. let o;
  3184. if ((t == null ? void 0 : t.length) === 1)
  3185. o = t[0];
  3186. else
  3187. return !1;
  3188. const s = n.get(M), r = N(s);
  3189. if (!r) return !1;
  3190. const { worksheet: i, subUnitId: a, unitId: u } = r, { startRow: l, endRow: c } = o, d = 0, h = i.getColumnCount() - 1, m = {
  3191. unitId: u,
  3192. subUnitId: a,
  3193. direction: pe.UP,
  3194. range: {
  3195. startRow: l,
  3196. endRow: c,
  3197. startColumn: d,
  3198. endColumn: h
  3199. },
  3200. // copy styles from the row above
  3201. cellValue: Vn(i, l, c, d, h, !0, l - 1)
  3202. };
  3203. return n.get(E).executeCommand(mt.id, m);
  3204. }
  3205. }, hu = {
  3206. type: v.COMMAND,
  3207. id: "sheet.command.insert-row-after",
  3208. handler: async (n) => {
  3209. var f;
  3210. const t = (f = n.get(F).getCurrentSelections()) == null ? void 0 : f.map((p) => p.range);
  3211. let o;
  3212. if ((t == null ? void 0 : t.length) === 1)
  3213. o = t[0];
  3214. else
  3215. return !1;
  3216. const s = n.get(M), r = N(s);
  3217. if (!r) return !1;
  3218. 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, g = {
  3219. unitId: a,
  3220. subUnitId: u,
  3221. direction: pe.DOWN,
  3222. range: {
  3223. startRow: c,
  3224. endRow: d,
  3225. startColumn: h,
  3226. endColumn: m,
  3227. rangeType: H.ROW
  3228. },
  3229. // copy styles from the row below
  3230. cellValue: Vn(i, c, d, h, m, !0, o.endRow)
  3231. };
  3232. return n.get(E).executeCommand(mt.id, g);
  3233. }
  3234. }, Rr = "sheet.command.insert-col", gt = {
  3235. type: v.COMMAND,
  3236. id: Rr,
  3237. handler: async (n, e) => {
  3238. const t = n.get(E), o = n.get(V), { range: s, direction: r, subUnitId: i, unitId: a, cellValue: u } = e;
  3239. return await o.beforeCommandExecute({
  3240. id: gt.id,
  3241. params: e
  3242. }) ? t.syncExecuteCommand(pr.id, {
  3243. range: s,
  3244. direction: r,
  3245. unitId: a,
  3246. subUnitId: i,
  3247. cellValue: u
  3248. }) : !1;
  3249. }
  3250. }, pr = {
  3251. type: v.COMMAND,
  3252. id: "sheet.command.insert-col-by-range",
  3253. handler: (n, e) => {
  3254. var x, T, U, P;
  3255. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), { range: i, direction: a, subUnitId: u, unitId: l, cellValue: c } = e, { startColumn: d, endColumn: h } = e.range;
  3256. i.rangeType = H.COLUMN;
  3257. const m = s.getUniverSheetInstance(e.unitId), g = m.getSheetBySheetId(e.subUnitId), f = a === pe.LEFT ? d : d - 1, p = g.getColumnWidth(f), C = {
  3258. unitId: l,
  3259. subUnitId: u,
  3260. range: i,
  3261. colInfo: new Array(h - d + 1).fill(void 0).map(() => ({
  3262. w: p,
  3263. hd: te.FALSE
  3264. }))
  3265. }, S = yo(
  3266. n,
  3267. C
  3268. ), I = [{ id: je.id, params: C }], w = [{ id: De.id, params: S }];
  3269. c && I.push({
  3270. id: Q.id,
  3271. params: {
  3272. unitId: l,
  3273. subUnitId: u,
  3274. cellValue: c
  3275. }
  3276. });
  3277. const b = r.onCommandExecute({
  3278. id: gt.id,
  3279. params: e
  3280. });
  3281. return I.unshift(...(x = b.preRedos) != null ? x : []), I.push(...(T = b.redos) != null ? T : []), I.push(Xe(i, m, g)), w.unshift(...(U = b.preUndos) != null ? U : []), w.push(...(P = b.undos) != null ? P : []), z(I, t).result ? (o.pushUndoRedo({
  3282. unitID: e.unitId,
  3283. undoMutations: w.filter(Boolean),
  3284. redoMutations: I.filter(Boolean)
  3285. }), !0) : !1;
  3286. }
  3287. }, mu = {
  3288. type: v.COMMAND,
  3289. id: "sheet.command.insert-col-before",
  3290. handler: async (n) => {
  3291. const t = n.get(F).getCurrentSelections();
  3292. let o;
  3293. if ((t == null ? void 0 : t.length) === 1)
  3294. o = t[0].range;
  3295. else
  3296. return !1;
  3297. const s = n.get(M), r = N(s);
  3298. if (!r) return !1;
  3299. const { worksheet: i, unitId: a, subUnitId: u } = r, { startColumn: l, endColumn: c } = o, d = 0, h = i.getRowCount() - 1, m = {
  3300. unitId: a,
  3301. subUnitId: u,
  3302. direction: pe.LEFT,
  3303. range: {
  3304. startColumn: l,
  3305. endColumn: c,
  3306. startRow: d,
  3307. endRow: h,
  3308. rangeType: H.COLUMN
  3309. },
  3310. // copy styles from the column before
  3311. cellValue: Vn(i, d, h, l, c, !1, l - 1)
  3312. };
  3313. return n.get(E).executeCommand(gt.id, m);
  3314. }
  3315. }, gu = {
  3316. type: v.COMMAND,
  3317. id: "sheet.command.insert-col-after",
  3318. handler: async (n) => {
  3319. const t = n.get(F).getCurrentSelections();
  3320. let o;
  3321. if ((t == null ? void 0 : t.length) === 1)
  3322. o = t[0].range;
  3323. else
  3324. return !1;
  3325. const s = n.get(M), r = N(s);
  3326. if (!r) return !1;
  3327. 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, g = {
  3328. unitId: a,
  3329. subUnitId: u,
  3330. direction: pe.RIGHT,
  3331. range: {
  3332. startColumn: c,
  3333. endColumn: d,
  3334. startRow: h,
  3335. endRow: m
  3336. },
  3337. // copy styles from the column after
  3338. cellValue: Vn(i, h, m, c, d, !1, o.endColumn)
  3339. };
  3340. return n.get(E).executeCommand(gt.id, g);
  3341. }
  3342. }, fu = {
  3343. id: "sheet.command.insert-sheet",
  3344. type: v.COMMAND,
  3345. handler: (n, e) => {
  3346. var p;
  3347. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(Ke), i = va(s, { unitId: e == null ? void 0 : e.unitId });
  3348. if (!i) return !1;
  3349. const { unitId: a, workbook: u } = i;
  3350. let l = u.getSheets().length;
  3351. const c = e == null ? void 0 : e.sheet, d = c == null ? void 0 : c.id, h = mi(c || {});
  3352. e ? (l = (p = e.index) != null ? p : l, h.id = d || O.generateRandomId(), h.name = (c == null ? void 0 : c.name) || u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`)) : (h.id = O.generateRandomId(), h.name = u.generateNewSheetName(`${r.t("sheets.tabs.sheet")}`));
  3353. const m = {
  3354. index: l,
  3355. sheet: h,
  3356. unitId: a
  3357. }, g = As(
  3358. n,
  3359. m
  3360. );
  3361. return t.syncExecuteCommand(Jt.id, m) ? (o.pushUndoRedo({
  3362. unitID: a,
  3363. undoMutations: [{ id: Ut.id, params: g }],
  3364. redoMutations: [{ id: Jt.id, params: m }]
  3365. }), !0) : !1;
  3366. }
  3367. };
  3368. function Ru(n, e) {
  3369. const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startRow > r.startRow, a = s.endRow - s.startRow + 1;
  3370. return i ? {
  3371. unitId: t,
  3372. subUnitId: o,
  3373. sourceRange: k.clone(r),
  3374. targetRange: {
  3375. ...s,
  3376. endRow: s.endRow + a,
  3377. startRow: s.startRow + a
  3378. }
  3379. } : {
  3380. unitId: t,
  3381. subUnitId: o,
  3382. targetRange: k.clone(s),
  3383. sourceRange: {
  3384. ...r,
  3385. endRow: r.endRow - a,
  3386. startRow: r.startRow - a
  3387. }
  3388. };
  3389. }
  3390. const ot = {
  3391. id: "sheet.mutation.move-rows",
  3392. type: v.MUTATION,
  3393. handler: (n, e) => {
  3394. const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(M).getUniverSheetInstance(t);
  3395. if (!a)
  3396. throw new Error("[MoveRowMutation] univerSheet is null!");
  3397. const u = a.getSheetBySheetId(o);
  3398. if (!u)
  3399. throw new Error("[MoveRowMutation] worksheet is null!");
  3400. const l = s.startRow, c = s.endRow - s.startRow + 1, d = r.startRow, h = u.getRowManager().getRowData();
  3401. return ys(l, c, d, h), u.getCellMatrix().moveRows(l, c, d), !0;
  3402. }
  3403. };
  3404. function pu(n, e) {
  3405. const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startColumn > r.startColumn, a = s.endColumn - s.startColumn + 1;
  3406. return i ? {
  3407. unitId: t,
  3408. subUnitId: o,
  3409. sourceRange: k.clone(r),
  3410. targetRange: {
  3411. ...s,
  3412. endColumn: s.endColumn + a,
  3413. startColumn: s.startColumn + a
  3414. }
  3415. } : {
  3416. unitId: t,
  3417. subUnitId: o,
  3418. targetRange: k.clone(s),
  3419. sourceRange: {
  3420. ...r,
  3421. startColumn: r.startColumn - a,
  3422. endColumn: r.endColumn - a
  3423. }
  3424. };
  3425. }
  3426. const st = {
  3427. id: "sheet.mutation.move-columns",
  3428. type: v.MUTATION,
  3429. handler: (n, e) => {
  3430. const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(M).getUniverSheetInstance(t);
  3431. if (!a)
  3432. throw new Error("[MoveColumnMutation] univerSheet is null!");
  3433. const u = a.getSheetBySheetId(o);
  3434. if (!u)
  3435. throw new Error("[MoveColumnMutation] worksheet is null!");
  3436. const l = s.startColumn, c = s.endColumn - s.startColumn + 1, d = r.startColumn, h = u.getColumnManager().getColumnData();
  3437. return ys(l, c, d, h), u.getCellMatrix().moveColumns(l, c, d), !0;
  3438. }
  3439. };
  3440. function Cu(n, e) {
  3441. return e.getMergeData().some((t) => t.startRow < n && n <= t.endRow);
  3442. }
  3443. function Su(n, e) {
  3444. return e.getMergeData().some((t) => t.startColumn < n && n <= t.endColumn);
  3445. }
  3446. const Cr = "sheet.command.move-rows", Fn = {
  3447. id: Cr,
  3448. type: v.COMMAND,
  3449. // eslint-disable-next-line max-lines-per-function
  3450. handler: (n, e) => {
  3451. var j, Z;
  3452. const t = n.get(F), {
  3453. fromRange: { startRow: o },
  3454. toRange: { startRow: s },
  3455. range: r
  3456. } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter(
  3457. (Y) => Y.range.rangeType === H.ROW && Y.range.startRow <= o && o <= Y.range.endRow
  3458. );
  3459. if ((a == null ? void 0 : a.length) !== 1)
  3460. return !1;
  3461. const u = n.get(V), l = n.get(M), c = N(l, e);
  3462. if (!c) return !1;
  3463. const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g = h.getSheetId(), f = n.get(bt), p = n.get(Ke), C = a[0].range, S = a[0].primary, I = Ln(C, h, !1);
  3464. if (!k.equals(C, I))
  3465. return f.emit(p.t("sheets.info.partOfCell")), !1;
  3466. if (Cu(s, h))
  3467. return f.emit(p.t("sheets.info.acrossMergedCell")), !1;
  3468. const w = {
  3469. ...C,
  3470. startRow: s,
  3471. endRow: s + C.endRow - C.startRow
  3472. }, b = {
  3473. unitId: m,
  3474. subUnitId: g,
  3475. sourceRange: C,
  3476. targetRange: w
  3477. }, y = Ru(n, b), x = n.get(E), T = u.onCommandExecute({ id: Fn.id, params: e }), U = [
  3478. ...(j = T.preRedos) != null ? j : [],
  3479. { id: ot.id, params: b }
  3480. ], P = [
  3481. ...(Z = T.preUndos) != null ? Z : [],
  3482. { id: ot.id, params: y }
  3483. ];
  3484. if (S) {
  3485. const ee = s - o < 0, Re = C.endRow - C.startRow + 1, ie = ee ? w : {
  3486. ...w,
  3487. startRow: w.startRow - Re,
  3488. endRow: w.endRow - Re
  3489. }, xe = {
  3490. unitId: m,
  3491. subUnitId: g,
  3492. type: Ce.MOVE_END,
  3493. selections: [{
  3494. range: ie,
  3495. primary: ve(ie, h),
  3496. style: null
  3497. }]
  3498. }, ft = {
  3499. unitId: m,
  3500. subUnitId: g,
  3501. type: Ce.MOVE_END,
  3502. selections: [{ range: C, primary: S, style: null }]
  3503. };
  3504. U.push({ id: re.id, params: xe }), P.push({ id: re.id, params: ft });
  3505. }
  3506. return U.push(...T.redos), P.push(...T.undos), z(U, x).result ? (n.get(W).pushUndoRedo({
  3507. unitID: m,
  3508. undoMutations: P,
  3509. redoMutations: U
  3510. }), !0) : !1;
  3511. }
  3512. }, Sr = "sheet.command.move-cols", jn = {
  3513. id: Sr,
  3514. type: v.COMMAND,
  3515. // eslint-disable-next-line max-lines-per-function
  3516. handler: (n, e) => {
  3517. var j, Z;
  3518. const t = n.get(F), {
  3519. fromRange: { startColumn: o },
  3520. toRange: { startColumn: s },
  3521. range: r
  3522. } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter(
  3523. (Y) => Y.range.rangeType === H.COLUMN && Y.range.startColumn <= o && o <= Y.range.endColumn
  3524. );
  3525. if ((a == null ? void 0 : a.length) !== 1)
  3526. return !1;
  3527. const u = n.get(V), l = n.get(M), c = N(l, e);
  3528. if (!c) return !1;
  3529. const { workbook: d, worksheet: h } = c, m = d.getUnitId(), g = h.getSheetId(), f = n.get(bt), p = n.get(Ke), C = a[0].range, S = a[0].primary, I = Ln(C, h, !1);
  3530. if (!k.equals(C, I))
  3531. return f.emit(p.t("sheets.info.partOfCell")), !1;
  3532. if (Su(s, h))
  3533. return f.emit(p.t("sheets.info.acrossMergedCell")), !1;
  3534. const w = {
  3535. ...C,
  3536. startColumn: s,
  3537. endColumn: s + C.endColumn - C.startColumn
  3538. }, b = {
  3539. unitId: m,
  3540. subUnitId: g,
  3541. sourceRange: C,
  3542. targetRange: w
  3543. }, y = pu(n, b), x = n.get(E), T = u.onCommandExecute({ id: jn.id, params: e }), U = [
  3544. ...(j = T.preRedos) != null ? j : [],
  3545. { id: st.id, params: b }
  3546. ], P = [
  3547. ...(Z = T.preUndos) != null ? Z : [],
  3548. { id: st.id, params: y }
  3549. ];
  3550. if (S) {
  3551. const Y = C.endColumn - C.startColumn + 1, ie = s - o < 0 ? w : {
  3552. ...w,
  3553. startColumn: w.startColumn - Y,
  3554. endColumn: w.endColumn - Y
  3555. }, xe = {
  3556. unitId: m,
  3557. subUnitId: g,
  3558. type: Ce.MOVE_END,
  3559. selections: [{ range: ie, primary: ve(ie, h), style: null }]
  3560. }, ft = {
  3561. unitId: m,
  3562. subUnitId: g,
  3563. type: Ce.MOVE_END,
  3564. selections: [{ range: C, primary: S, style: null }]
  3565. };
  3566. U.push({ id: re.id, params: xe }), P.push({ id: re.id, params: ft });
  3567. }
  3568. return U.push(...T.redos), P.push(...T.undos), z(U, x).result && n.get(W).pushUndoRedo({
  3569. unitID: m,
  3570. undoMutations: P,
  3571. redoMutations: U
  3572. }), !0;
  3573. }
  3574. };
  3575. function wr(n) {
  3576. return {
  3577. range: n,
  3578. primary: null,
  3579. style: null
  3580. };
  3581. }
  3582. const Yt = {
  3583. id: "sheet.mutation.register-worksheet-range-theme-style",
  3584. type: v.MUTATION,
  3585. handler: (n, e) => {
  3586. const { unitId: t, rangeThemeStyleJson: o, themeName: s } = e, r = n.get(M), i = N(r), a = n.get(He);
  3587. if (!i) return !1;
  3588. const u = new yt(s, o);
  3589. return a.registerRangeThemeStyle(t, u), !0;
  3590. }
  3591. }, Uo = {
  3592. id: "sheet.mutation.unregister-worksheet-range-theme-style",
  3593. type: v.MUTATION,
  3594. handler: (n, e) => {
  3595. const { unitId: t, themeName: o } = e, s = n.get(M), r = N(s), i = n.get(He);
  3596. return r ? (i.unregisterRangeThemeStyle(t, o), !0) : !1;
  3597. }
  3598. }, wu = {
  3599. id: "sheet.command.register-worksheet-range-theme-style",
  3600. type: v.COMMAND,
  3601. handler: (n, e) => {
  3602. if (!e)
  3603. return !1;
  3604. const { unitId: t, rangeThemeStyle: o } = e, s = n.get(M), r = n.get(E), i = n.get(W);
  3605. if (!N(s)) return !1;
  3606. const u = {
  3607. unitId: t,
  3608. themeName: o.getName(),
  3609. rangeThemeStyleJson: o.toJson()
  3610. }, l = {
  3611. unitId: t,
  3612. themeName: o.getName()
  3613. };
  3614. return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({
  3615. unitID: t,
  3616. undoMutations: [{ id: Uo.id, params: l }],
  3617. redoMutations: [{ id: Yt.id, params: u }]
  3618. }), !0;
  3619. }
  3620. }, Ir = {
  3621. id: "sheet.command.remove-defined-name",
  3622. type: v.COMMAND,
  3623. handler: (n, e) => {
  3624. var c, d;
  3625. const t = n.get(E), o = n.get(W), s = n.get(V);
  3626. if (!e) return !1;
  3627. const r = {
  3628. ...e
  3629. }, i = s.onCommandExecute({ id: Ir.id, params: e }), a = [
  3630. ...(c = i.preRedos) != null ? c : [],
  3631. { id: Cn.id, params: r },
  3632. ...i.redos
  3633. ], u = [
  3634. ...(d = i.preUndos) != null ? d : [],
  3635. { id: Gt.id, params: r },
  3636. ...i.undos
  3637. ];
  3638. return z(a, t) ? (o.pushUndoRedo({
  3639. unitID: e.unitId,
  3640. undoMutations: u.filter(Boolean),
  3641. redoMutations: a.filter(Boolean)
  3642. }), !0) : !1;
  3643. }
  3644. }, Po = "sheet.command.remove-row", vr = {
  3645. type: v.COMMAND,
  3646. id: "sheet.command.remove-row-by-range",
  3647. handler: (n, e) => {
  3648. var C, S, I;
  3649. if (!e)
  3650. return !1;
  3651. const t = n.get(M), o = N(t, e);
  3652. if (!o) return !1;
  3653. const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = {
  3654. unitId: u,
  3655. subUnitId: l,
  3656. range: a
  3657. }, d = uu(
  3658. c,
  3659. r
  3660. ), h = r.getCellMatrix().getSlice(a.startRow, a.endRow, 0, r.getColumnCount() - 1), m = {
  3661. unitId: u,
  3662. subUnitId: l,
  3663. cellValue: h.getMatrix()
  3664. }, g = i.onCommandExecute({
  3665. id: Po,
  3666. params: { range: a }
  3667. }), f = n.get(E);
  3668. return z(
  3669. [
  3670. ...(C = g.preRedos) != null ? C : [],
  3671. { id: Be.id, params: c },
  3672. ...g.redos,
  3673. Xe(a, s, r)
  3674. ],
  3675. f
  3676. ).result ? (n.get(W).pushUndoRedo({
  3677. unitID: u,
  3678. undoMutations: [
  3679. ...(S = g.preUndos) != null ? S : [],
  3680. { id: qe.id, params: d },
  3681. { id: Q.id, params: m },
  3682. ...g.undos
  3683. ],
  3684. redoMutations: [
  3685. ...(I = g.preRedos) != null ? I : [],
  3686. { id: Be.id, params: c },
  3687. ...g.redos
  3688. ]
  3689. }), !0) : !1;
  3690. }
  3691. }, Gn = {
  3692. type: v.COMMAND,
  3693. id: Po,
  3694. handler: async (n, e) => {
  3695. var h;
  3696. const t = n.get(F), o = n.get(V), s = n.get(E);
  3697. let r = e == null ? void 0 : e.range;
  3698. if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return !1;
  3699. const i = n.get(M), a = N(i);
  3700. if (!a) return !1;
  3701. const { worksheet: u, subUnitId: l, unitId: c } = a;
  3702. return r = {
  3703. ...r,
  3704. startColumn: 0,
  3705. endColumn: Math.max(u.getMaxColumns() - 1, 0)
  3706. }, await o.beforeCommandExecute({
  3707. id: Gn.id,
  3708. params: { range: r }
  3709. }) ? s.syncExecuteCommand(vr.id, {
  3710. range: r,
  3711. unitId: c,
  3712. subUnitId: l
  3713. }) : !1;
  3714. }
  3715. }, To = "sheet.command.remove-col", Mr = {
  3716. type: v.COMMAND,
  3717. id: "sheet.command.remove-col-by-range",
  3718. handler: (n, e) => {
  3719. var C, S, I;
  3720. if (!e)
  3721. return !1;
  3722. const t = n.get(M), o = N(t, e);
  3723. if (!o) return !1;
  3724. const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = {
  3725. unitId: u,
  3726. subUnitId: l,
  3727. range: a
  3728. }, d = lu(n, c), h = r.getCellMatrix().getSlice(0, r.getRowCount() - 1, a.startColumn, a.endColumn), m = {
  3729. unitId: u,
  3730. subUnitId: l,
  3731. cellValue: h.getMatrix()
  3732. }, g = i.onCommandExecute({
  3733. id: To,
  3734. params: { range: a }
  3735. }), f = n.get(E);
  3736. return z(
  3737. [
  3738. ...(C = g.preRedos) != null ? C : [],
  3739. { id: De.id, params: c },
  3740. ...g.redos,
  3741. Xe(a, s, r)
  3742. ],
  3743. f
  3744. ).result ? (n.get(W).pushUndoRedo({
  3745. unitID: u,
  3746. undoMutations: [
  3747. ...(S = g.preUndos) != null ? S : [],
  3748. { id: je.id, params: d },
  3749. { id: Q.id, params: m },
  3750. ...g.undos
  3751. ],
  3752. redoMutations: [
  3753. ...(I = g.preRedos) != null ? I : [],
  3754. { id: De.id, params: c },
  3755. ...g.redos
  3756. ]
  3757. }), !0) : !1;
  3758. }
  3759. }, zn = {
  3760. type: v.COMMAND,
  3761. id: To,
  3762. handler: async (n, e) => {
  3763. var h;
  3764. const t = n.get(F), o = n.get(V), s = n.get(E);
  3765. let r = e == null ? void 0 : e.range;
  3766. if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return !1;
  3767. const i = n.get(M), a = N(i);
  3768. if (!a) return !1;
  3769. const { worksheet: u, subUnitId: l, unitId: c } = a;
  3770. return r = {
  3771. ...r,
  3772. startRow: 0,
  3773. endRow: Math.max(u.getMaxRows() - 1, 0)
  3774. }, await o.beforeCommandExecute({
  3775. id: zn.id,
  3776. params: { range: r }
  3777. }) ? s.syncExecuteCommand(Mr.id, {
  3778. range: r,
  3779. unitId: c,
  3780. subUnitId: l
  3781. }) : !1;
  3782. }
  3783. }, ko = {
  3784. id: "sheet.command.remove-sheet",
  3785. type: v.COMMAND,
  3786. handler: (n, e) => {
  3787. var C, S;
  3788. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = N(s, e);
  3789. if (!i) return !1;
  3790. const { unitId: a, subUnitId: u, workbook: l, worksheet: c } = i;
  3791. if (l.getSheets().length <= 1) return !1;
  3792. const d = {
  3793. subUnitId: u,
  3794. unitId: a,
  3795. subUnitName: c.getName()
  3796. }, h = ja(
  3797. n,
  3798. d
  3799. ), m = r.onCommandExecute({
  3800. id: ko.id,
  3801. params: { unitId: a, subUnitId: u }
  3802. }), g = [...(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];
  3803. return z(g, t).result ? (o.pushUndoRedo({
  3804. unitID: a,
  3805. undoMutations: f,
  3806. redoMutations: g
  3807. }), !0) : !1;
  3808. }
  3809. }, Ue = (n, e) => {
  3810. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  3811. throw new Error("universheet is null error!");
  3812. return {
  3813. unitId: e.unitId,
  3814. subUnitId: e.subUnitId,
  3815. ranges: O.deepClone(e.ranges)
  3816. };
  3817. }, ne = {
  3818. id: "sheet.mutation.add-worksheet-merge",
  3819. type: v.MUTATION,
  3820. handler: (n, e) => {
  3821. const o = n.get(M).getUniverSheetInstance(e.unitId);
  3822. if (o == null)
  3823. throw new Error("universheet is null error!");
  3824. const s = o.getSheetBySheetId(e.subUnitId);
  3825. if (!s) return !1;
  3826. const i = s.getConfig().mergeData, a = e.ranges;
  3827. for (let u = 0; u < a.length; u++)
  3828. i.push(a[u]);
  3829. return s.getSpanModel().rebuild(i), !0;
  3830. }
  3831. }, Se = (n, e) => {
  3832. const o = n.get(M).getUniverSheetInstance(e.unitId);
  3833. if (o == null)
  3834. throw new Error("universheet is null error!");
  3835. const s = o.getSheetBySheetId(e.subUnitId);
  3836. if (s == null)
  3837. throw new Error("worksheet is null error!");
  3838. const i = s.getConfig().mergeData, a = e.ranges, u = [];
  3839. for (let l = 0; l < a.length; l++)
  3840. for (let c = i.length - 1; c >= 0; c--) {
  3841. const d = i[c], h = a[l];
  3842. k.intersects(d, h) && u.push(i[c]);
  3843. }
  3844. return {
  3845. unitId: e.unitId,
  3846. subUnitId: e.subUnitId,
  3847. ranges: u
  3848. };
  3849. }, oe = {
  3850. id: "sheet.mutation.remove-worksheet-merge",
  3851. type: v.MUTATION,
  3852. handler: (n, e) => {
  3853. const o = n.get(M).getUniverSheetInstance(e.unitId);
  3854. if (o == null)
  3855. throw new Error("universheet is null error!");
  3856. const s = o.getSheetBySheetId(e.subUnitId);
  3857. if (!s) return !1;
  3858. const i = s.getConfig().mergeData, a = e.ranges;
  3859. for (let u = 0; u < a.length; u++)
  3860. for (let l = i.length - 1; l >= 0; l--) {
  3861. const c = i[l], d = a[u];
  3862. k.intersects(c, d) && i.splice(l, 1);
  3863. }
  3864. return s.getSpanModel().rebuild(i), !0;
  3865. }
  3866. }, Iu = {
  3867. type: v.COMMAND,
  3868. id: "sheet.command.remove-worksheet-merge",
  3869. // eslint-disable-next-line max-lines-per-function
  3870. handler: (n, e) => {
  3871. var A;
  3872. const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), i = (e == null ? void 0 : e.ranges) || ((A = t.getCurrentSelections()) == null ? void 0 : A.map((j) => j.range));
  3873. if (!(i != null && i.length)) return !1;
  3874. const a = N(r);
  3875. if (!a) return !1;
  3876. const { subUnitId: u, unitId: l, worksheet: c } = a, d = {
  3877. unitId: l,
  3878. subUnitId: u,
  3879. ranges: i
  3880. }, m = c.getConfig().mergeData.filter((j) => i.some((Z) => k.intersects(Z, j)));
  3881. if (!m.length) return !1;
  3882. const g = Se(
  3883. n,
  3884. d
  3885. ), f = t.getCurrentSelections();
  3886. if (!(f != null && f.length)) return !1;
  3887. const p = O.deepClone(f), C = O.deepClone(f), S = C[C.length - 1], { startRow: I, startColumn: w } = S.range;
  3888. S.primary = {
  3889. startRow: I,
  3890. startColumn: w,
  3891. endRow: I,
  3892. endColumn: w,
  3893. actualRow: I,
  3894. actualColumn: w,
  3895. isMerged: !1,
  3896. isMergedMainCell: !1
  3897. };
  3898. const b = vu(c, m), y = {
  3899. unitId: l,
  3900. subUnitId: u,
  3901. cellValue: b.redoParams.getMatrix()
  3902. }, x = {
  3903. unitId: l,
  3904. subUnitId: u,
  3905. cellValue: b.undoParams.getMatrix()
  3906. }, T = [
  3907. { id: oe.id, params: g },
  3908. { id: Q.id, params: y },
  3909. { id: re.id, params: { selections: C } }
  3910. ], U = [
  3911. { id: ne.id, params: g },
  3912. { id: Q.id, params: x },
  3913. { id: re.id, params: { selections: p } }
  3914. ];
  3915. return z(T, o) ? (s.pushUndoRedo({
  3916. unitID: l,
  3917. undoMutations: U,
  3918. redoMutations: T
  3919. }), !0) : !1;
  3920. }
  3921. };
  3922. function vu(n, e) {
  3923. const t = new G(), o = new G();
  3924. return e.forEach((s) => {
  3925. const { startRow: r, startColumn: i, endColumn: a, endRow: u } = s, l = n.getCellMatrix().getValue(r, i);
  3926. if (l != null && l.s)
  3927. for (let c = r; c <= u; c++)
  3928. for (let d = i; d <= a; d++)
  3929. (c !== r || d !== i) && (t.setValue(c, d, { s: l.s }), o.setValue(c, d, null));
  3930. }), {
  3931. redoParams: t,
  3932. undoParams: o
  3933. };
  3934. }
  3935. const Mu = (n) => {
  3936. const { order: e } = n, t = {};
  3937. return Object.keys(e).forEach((o) => {
  3938. t[e[Number(o)]] = Number(o);
  3939. }), {
  3940. ...n,
  3941. order: t
  3942. };
  3943. }, In = {
  3944. id: "sheet.mutation.reorder-range",
  3945. type: v.MUTATION,
  3946. handler: (n, e) => {
  3947. const { subUnitId: t, unitId: o, range: s, order: r } = e, u = n.get(M).getUnit(o).getSheetBySheetId(t);
  3948. if (!u)
  3949. return !1;
  3950. const l = new G();
  3951. K.foreach(s, (d, h) => {
  3952. if (r.hasOwnProperty(d)) {
  3953. const m = r[d], g = O.deepClone(u.getCellRaw(m, h));
  3954. l.setValue(d, h, g);
  3955. }
  3956. });
  3957. const c = u.getCellMatrix();
  3958. return l.forValue((d, h, m) => {
  3959. c.setValue(d, h, m);
  3960. }), !0;
  3961. }
  3962. }, _r = "sheet.command.reorder-range", uo = {
  3963. id: _r,
  3964. type: v.COMMAND,
  3965. handler: (n, e) => {
  3966. var f, p;
  3967. const { subUnitId: t, unitId: o, range: s, order: r } = e, i = n.get(E), a = {
  3968. id: In.id,
  3969. params: {
  3970. unitId: o,
  3971. subUnitId: t,
  3972. order: r,
  3973. range: s
  3974. }
  3975. }, u = {
  3976. id: In.id,
  3977. params: Mu(a.params)
  3978. }, l = n.get(V), c = l.onCommandExecute({ id: uo.id, params: e }), d = [
  3979. ...(f = c.preRedos) != null ? f : [],
  3980. a,
  3981. ...c.redos
  3982. ], h = [
  3983. ...(p = c.preUndos) != null ? p : [],
  3984. u,
  3985. ...c.undos
  3986. ], m = z(d, i), g = l.afterCommandExecute({ id: uo.id, params: e });
  3987. return m.result ? (z(g.redos, i), n.get(W).pushUndoRedo({
  3988. unitID: o,
  3989. undoMutations: [...h, ...g.undos],
  3990. redoMutations: [...d, ...g.redos]
  3991. }), !0) : !1;
  3992. }
  3993. };
  3994. class kt {
  3995. constructor() {
  3996. R(this, "_borderInfo", {
  3997. type: ue.ALL,
  3998. color: "#000000",
  3999. style: Rs.THIN,
  4000. activeBorderType: !1
  4001. });
  4002. R(this, "_borderInfo$", new at(this._borderInfo));
  4003. R(this, "borderInfo$", this._borderInfo$.asObservable());
  4004. }
  4005. dispose() {
  4006. this._borderInfo$.complete();
  4007. }
  4008. setType(e) {
  4009. this._borderInfo.type = e, this.setActiveBorderType(!0), this._refresh();
  4010. }
  4011. setColor(e) {
  4012. this._borderInfo.color = e, this._refresh();
  4013. }
  4014. setStyle(e) {
  4015. this._borderInfo.style = e, this._refresh();
  4016. }
  4017. setActiveBorderType(e) {
  4018. this._borderInfo.activeBorderType = e;
  4019. }
  4020. getBorderInfo() {
  4021. return this._borderInfo;
  4022. }
  4023. _refresh() {
  4024. this._borderInfo$.next(this._borderInfo);
  4025. }
  4026. }
  4027. function vn(n, e) {
  4028. const { startRow: t, startColumn: o, endRow: s, endColumn: r } = n;
  4029. for (let i = t; i <= s; i++)
  4030. for (let a = o; a <= r; a++)
  4031. e(i, a);
  4032. }
  4033. const No = (n, e, t, o) => {
  4034. const { mr: s, worksheet: r } = n;
  4035. e.startRow < 0 || e.startColumn < 0 || vn(e, (i, a) => {
  4036. var c, d;
  4037. const u = r.getMergedCell(i, a);
  4038. let l = t;
  4039. if (u && (t.bc_tr || t.ml_tr || t.bl_tr || t.tl_mr || t.tl_bc || t.tl_br)) {
  4040. if (o) {
  4041. const h = O.deepClone(
  4042. (c = s.getValue(u.startRow, u.startColumn)) == null ? void 0 : c.s
  4043. );
  4044. l = h != null && h.bd ? Object.assign(h.bd, t) : t;
  4045. }
  4046. s.setValue(u.startRow, u.startColumn, {
  4047. s: {
  4048. bd: l
  4049. }
  4050. });
  4051. } else {
  4052. if (o) {
  4053. const h = O.deepClone((d = s.getValue(i, a)) == null ? void 0 : d.s);
  4054. l = h != null && h.bd ? Object.assign(h.bd, t) : t;
  4055. }
  4056. s.setValue(i, a, { s: { bd: l } });
  4057. }
  4058. });
  4059. }, _u = (n) => {
  4060. const e = {
  4061. startRow: n.startRow - 1,
  4062. startColumn: n.startColumn,
  4063. endRow: n.startRow - 1,
  4064. endColumn: n.endColumn
  4065. }, t = {
  4066. startRow: n.startRow,
  4067. startColumn: n.startColumn - 1,
  4068. endRow: n.endRow,
  4069. endColumn: n.startColumn - 1
  4070. }, o = {
  4071. startRow: n.endRow + 1,
  4072. startColumn: n.startColumn,
  4073. endRow: n.endRow + 1,
  4074. endColumn: n.endColumn
  4075. }, s = {
  4076. startRow: n.startRow,
  4077. startColumn: n.endColumn + 1,
  4078. endRow: n.endRow,
  4079. endColumn: n.endColumn + 1
  4080. }, r = {
  4081. startRow: n.startRow,
  4082. startColumn: n.startColumn,
  4083. endRow: n.startRow,
  4084. endColumn: n.endColumn
  4085. }, i = {
  4086. startRow: n.startRow,
  4087. startColumn: n.startColumn,
  4088. endRow: n.endRow,
  4089. endColumn: n.startColumn
  4090. }, a = {
  4091. startRow: n.endRow,
  4092. startColumn: n.startColumn,
  4093. endRow: n.endRow,
  4094. endColumn: n.endColumn
  4095. }, u = {
  4096. startRow: n.startRow,
  4097. startColumn: n.endColumn,
  4098. endRow: n.endRow,
  4099. endColumn: n.endColumn
  4100. };
  4101. return {
  4102. topRangeOut: e,
  4103. leftRangeOut: t,
  4104. bottomRangeOut: o,
  4105. rightRangeOut: s,
  4106. topRange: r,
  4107. leftRange: i,
  4108. bottomRange: a,
  4109. rightRange: u
  4110. };
  4111. };
  4112. function bu(n, e, t) {
  4113. const { style: o, color: s, type: r } = n.getBorderInfo(), i = r === ue.TOP || r === ue.ALL || r === ue.OUTSIDE, a = r === ue.LEFT || r === ue.ALL || r === ue.OUTSIDE, u = r === ue.BOTTOM || r === ue.ALL || r === ue.OUTSIDE, l = r === ue.RIGHT || r === ue.ALL || r === ue.OUTSIDE, c = r === ue.VERTICAL || r === ue.ALL || r === ue.INSIDE, d = r === ue.HORIZONTAL || r === ue.ALL || r === ue.INSIDE, h = r.indexOf("tlbr") > -1, m = r.indexOf("tlbc") > -1, g = r.indexOf("tlmr") > -1, f = r.indexOf("bltr") > -1, p = r.indexOf("mltr") > -1, C = r.indexOf("bctr") > -1, S = t[0], {
  4114. topRangeOut: I,
  4115. leftRangeOut: w,
  4116. bottomRangeOut: b,
  4117. rightRangeOut: y,
  4118. topRange: x,
  4119. leftRange: T,
  4120. bottomRange: U,
  4121. rightRange: P
  4122. } = _u(S), A = new G(), { worksheet: j, unitId: Z, subUnitId: Y } = e;
  4123. return {
  4124. worksheet: j,
  4125. unitId: Z,
  4126. subUnitId: Y,
  4127. style: o,
  4128. color: s,
  4129. type: r,
  4130. top: i,
  4131. left: a,
  4132. right: l,
  4133. bottom: u,
  4134. vertical: c,
  4135. horizontal: d,
  4136. tl_br: h,
  4137. tl_bc: m,
  4138. tl_mr: g,
  4139. bl_tr: f,
  4140. ml_tr: p,
  4141. bc_tr: C,
  4142. topRangeOut: I,
  4143. leftRangeOut: w,
  4144. bottomRangeOut: b,
  4145. rightRangeOut: y,
  4146. topRange: x,
  4147. leftRange: T,
  4148. bottomRange: U,
  4149. rightRange: P,
  4150. range: S,
  4151. mr: A,
  4152. borderStyle: {
  4153. s: o,
  4154. cl: {
  4155. rgb: s
  4156. }
  4157. }
  4158. };
  4159. }
  4160. const yu = (n) => {
  4161. const { range: e, mr: t, borderStyle: o, vertical: s, horizontal: r, worksheet: i } = n;
  4162. s && vn(e, (a, u) => {
  4163. var c, d, h;
  4164. const l = i.getMergedCell(a, u);
  4165. if (l) {
  4166. const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s;
  4167. l.startColumn !== e.startColumn && t.setValue(a, u, {
  4168. s: {
  4169. bd: m != null && m.bd ? Object.assign(m.bd, { l: O.deepClone(o) }) : { l: O.deepClone(o) }
  4170. }
  4171. });
  4172. } else {
  4173. if (u !== e.endColumn) {
  4174. const m = (d = t.getValue(a, u)) == null ? void 0 : d.s;
  4175. t.setValue(a, u, {
  4176. s: {
  4177. bd: m != null && m.bd ? Object.assign(m.bd, { r: O.deepClone(o) }) : { r: O.deepClone(o) }
  4178. }
  4179. });
  4180. }
  4181. if (u !== e.startColumn) {
  4182. const m = (h = t.getValue(a, u)) == null ? void 0 : h.s;
  4183. t.setValue(a, u, {
  4184. s: {
  4185. bd: m != null && m.bd ? Object.assign(m.bd, { l: O.deepClone(o) }) : { l: O.deepClone(o) }
  4186. }
  4187. });
  4188. }
  4189. }
  4190. }), r && vn(e, (a, u) => {
  4191. var c, d, h;
  4192. const l = i.getMergedCell(a, u);
  4193. if (l) {
  4194. const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s;
  4195. l.startRow !== e.startRow && t.setValue(a, u, {
  4196. s: {
  4197. bd: m != null && m.bd ? Object.assign(m.bd, { t: O.deepClone(o) }) : { t: O.deepClone(o) }
  4198. }
  4199. });
  4200. } else {
  4201. if (a !== e.endRow) {
  4202. const m = (d = t.getValue(a, u)) == null ? void 0 : d.s;
  4203. t.setValue(a, u, {
  4204. s: {
  4205. bd: m != null && m.bd ? Object.assign(m.bd, { b: O.deepClone(o) }) : { b: O.deepClone(o) }
  4206. }
  4207. });
  4208. }
  4209. if (a !== e.startRow) {
  4210. const m = (h = t.getValue(a, u)) == null ? void 0 : h.s;
  4211. t.setValue(a, u, {
  4212. s: {
  4213. bd: m != null && m.bd ? Object.assign(m.bd, { t: O.deepClone(o) }) : { t: O.deepClone(o) }
  4214. }
  4215. });
  4216. }
  4217. }
  4218. });
  4219. };
  4220. function Eu(n) {
  4221. 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) => {
  4222. No(n, l, c, d);
  4223. };
  4224. t && u(n.range, { tl_br: O.deepClone(e) }, !0), o && u(n.range, { tl_bc: O.deepClone(e) }, !0), s && u(n.range, { tl_mr: O.deepClone(e) }, !0), r && u(n.range, { bl_tr: O.deepClone(e) }, !0), i && u(n.range, { ml_tr: O.deepClone(e) }, !0), a && u(n.range, { bc_tr: O.deepClone(e) }, !0);
  4225. }
  4226. const Uu = (n) => {
  4227. 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, g = (f, p, C) => {
  4228. No(n, f, p, C);
  4229. };
  4230. e && (g(d, { b: null }), g(a, { t: O.deepClone(r) }, !0)), s && (g(c, { t: null }), g(i, { b: O.deepClone(r) }, !0)), t && (g(h, { r: null }), g(u, { l: O.deepClone(r) }, !0)), o && (g(m, { l: null }), g(l, { r: O.deepClone(r) }, !0));
  4231. }, Pu = (n) => {
  4232. 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: g, bc_tr: f, topRange: p, bottomRange: C, leftRange: S, rightRange: I, topRangeOut: w, bottomRangeOut: b, leftRangeOut: y, rightRangeOut: x } = n, T = (U, P, A) => {
  4233. No(n, U, P, A);
  4234. };
  4235. !s && !r && !i && !a && !u && !l && !c && !d && !h && !m && !g && !f && (vn(e, (U, P) => {
  4236. var j, Z, Y, ee, Re, ie, xe, ft;
  4237. const A = t.getMergedCell(U, P);
  4238. if (A) {
  4239. if (A.endColumn !== e.endColumn) {
  4240. const X = (j = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : j.s;
  4241. o.setValue(U, P, {
  4242. s: {
  4243. bd: X != null && X.bd ? Object.assign(X.bd, { r: null }) : { r: null }
  4244. }
  4245. });
  4246. }
  4247. if (A.startColumn !== e.startColumn) {
  4248. const X = (Z = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Z.s;
  4249. o.setValue(U, P, {
  4250. s: {
  4251. bd: X != null && X.bd ? Object.assign(X.bd, { l: null }) : { l: null }
  4252. }
  4253. });
  4254. }
  4255. if (A.endRow !== e.endRow) {
  4256. const X = (Y = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Y.s;
  4257. o.setValue(U, P, {
  4258. s: {
  4259. bd: X != null && X.bd ? Object.assign(X.bd, { b: null }) : { b: null }
  4260. }
  4261. });
  4262. }
  4263. if (A.startRow !== e.startRow) {
  4264. const X = (ee = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : ee.s;
  4265. o.setValue(U, P, {
  4266. s: {
  4267. bd: X != null && X.bd ? Object.assign(X.bd, { t: null }) : { t: null }
  4268. }
  4269. });
  4270. }
  4271. } else {
  4272. if (P !== e.endColumn) {
  4273. const X = (Re = o.getValue(U, P)) == null ? void 0 : Re.s;
  4274. o.setValue(U, P, {
  4275. s: {
  4276. bd: X != null && X.bd ? Object.assign(X.bd, { r: null }) : { r: null }
  4277. }
  4278. });
  4279. }
  4280. if (P !== e.startColumn) {
  4281. const X = (ie = o.getValue(U, P)) == null ? void 0 : ie.s;
  4282. o.setValue(U, P, {
  4283. s: {
  4284. bd: X != null && X.bd ? Object.assign(X.bd, { l: null }) : { l: null }
  4285. }
  4286. });
  4287. }
  4288. if (U !== e.endRow) {
  4289. const X = (xe = o.getValue(U, P)) == null ? void 0 : xe.s;
  4290. o.setValue(U, P, {
  4291. s: {
  4292. bd: X != null && X.bd ? Object.assign(X.bd, { b: null }) : { b: null }
  4293. }
  4294. });
  4295. }
  4296. if (U !== e.startRow) {
  4297. const X = (ft = o.getValue(U, P)) == null ? void 0 : ft.s;
  4298. o.setValue(U, P, {
  4299. s: {
  4300. bd: X != null && X.bd ? Object.assign(X.bd, { t: null }) : { t: null }
  4301. }
  4302. });
  4303. }
  4304. }
  4305. }), T(w, { b: null }), T(p, { t: null }, !0), T(b, { t: null }), T(C, { b: null }, !0), T(y, { r: null }), T(S, { l: null }, !0), T(x, { l: null }), T(I, { r: null }, !0), T(e, { tl_br: null }, !0), T(e, { tl_bc: null }, !0), T(e, { tl_mr: null }, !0), T(e, { bl_tr: null }, !0), T(e, { ml_tr: null }, !0), T(e, { bc_tr: null }, !0));
  4306. }, rn = {
  4307. id: "sheet.command.set-border",
  4308. type: v.COMMAND,
  4309. handler: (n, e) => {
  4310. var C;
  4311. const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(kt), a = N(s, e);
  4312. if (!a) return !1;
  4313. const u = (C = r.getCurrentSelections()) == null ? void 0 : C.map((S) => S.range);
  4314. if (!(u != null && u.length))
  4315. return !1;
  4316. const { activeBorderType: l } = i.getBorderInfo();
  4317. if (!l) return !1;
  4318. const c = bu(i, a, u);
  4319. yu(c), Uu(c), Eu(c), Pu(c);
  4320. const { unitId: d, subUnitId: h, mr: m } = c, g = {
  4321. unitId: d,
  4322. subUnitId: h,
  4323. cellValue: m.getData()
  4324. }, f = Ae(
  4325. n,
  4326. g
  4327. );
  4328. return t.syncExecuteCommand(Q.id, g) ? (o.pushUndoRedo({
  4329. unitID: d,
  4330. undoMutations: [{ id: Q.id, params: f }],
  4331. redoMutations: [{ id: Q.id, params: g }]
  4332. }), !0) : !1;
  4333. }
  4334. }, Tu = {
  4335. id: "sheet.command.set-border-position",
  4336. type: v.COMMAND,
  4337. handler: (n, e) => {
  4338. if (!e.value) return !1;
  4339. const t = n.get(E);
  4340. return n.get(kt).setType(e.value), t.syncExecuteCommand(rn.id);
  4341. }
  4342. }, ku = {
  4343. id: "sheet.command.set-border-style",
  4344. type: v.COMMAND,
  4345. handler: (n, e) => {
  4346. const t = n.get(E);
  4347. return n.get(kt).setStyle(e.value), t.syncExecuteCommand(rn.id);
  4348. }
  4349. }, Nu = {
  4350. id: "sheet.command.set-border-color",
  4351. type: v.COMMAND,
  4352. handler: (n, e) => {
  4353. const t = n.get(E);
  4354. return n.get(kt).setColor(e.value), t.syncExecuteCommand(rn.id);
  4355. }
  4356. }, Ou = {
  4357. id: "sheet.command.set-border-basic",
  4358. type: v.COMMAND,
  4359. handler: (n, e) => {
  4360. const { unitId: t, subUnitId: o, value: s } = e, { type: r, color: i, style: a } = s, u = n.get(E), l = n.get(kt);
  4361. return l.setType(r), i && l.setColor(i), l.setStyle(a), u.syncExecuteCommand(rn.id, {
  4362. unitId: t,
  4363. subUnitId: o
  4364. });
  4365. }
  4366. };
  4367. function Du(n, e) {
  4368. if (n == null)
  4369. return n;
  4370. const t = O.deepClone(n);
  4371. if (e == null)
  4372. return t;
  4373. const o = {};
  4374. 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;
  4375. }
  4376. function Au(n, e) {
  4377. if (n == null)
  4378. return n;
  4379. const t = O.deepClone(n);
  4380. if (e == null)
  4381. return t;
  4382. const o = {};
  4383. 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;
  4384. }
  4385. const xu = (n, e) => {
  4386. const { unitId: t, subUnitId: o, columnData: s } = n, r = {}, i = e.getColumnManager();
  4387. for (const a in s) {
  4388. const u = s[a], l = i.getColumn(Number(a));
  4389. r[a] = Au(l, u);
  4390. }
  4391. return {
  4392. unitId: t,
  4393. subUnitId: o,
  4394. columnData: r
  4395. };
  4396. }, Lt = {
  4397. id: "sheet.mutation.set-col-data",
  4398. type: v.MUTATION,
  4399. handler: (n, e) => {
  4400. const { columnData: t } = e, o = n.get(M), s = N(o, e);
  4401. if (!s) return !1;
  4402. const { worksheet: r } = s, i = r.getColumnManager();
  4403. for (const a in t) {
  4404. const u = t[a];
  4405. if (u == null) {
  4406. i.removeColumn(Number(a));
  4407. continue;
  4408. }
  4409. const l = i.getColumnOrCreate(Number(a));
  4410. Object.assign(l, u);
  4411. }
  4412. return !0;
  4413. }
  4414. }, $u = {
  4415. type: v.COMMAND,
  4416. id: "sheet.command.set-col-data",
  4417. handler: (n, e) => {
  4418. const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, e);
  4419. if (!r) return !1;
  4420. const { columnData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = {
  4421. subUnitId: u,
  4422. unitId: a,
  4423. columnData: i
  4424. }, d = xu(c, l);
  4425. return t.syncExecuteCommand(Lt.id, c) ? (o.pushUndoRedo({
  4426. unitID: a,
  4427. undoMutations: [{ id: Lt.id, params: d }],
  4428. redoMutations: [{ id: Lt.id, params: c }]
  4429. }), !0) : !1;
  4430. }
  4431. }, Wu = (n, e) => {
  4432. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  4433. throw new Error("universheet is null error!");
  4434. return {
  4435. unitId: e.unitId,
  4436. subUnitId: e.subUnitId,
  4437. ranges: e.ranges
  4438. };
  4439. }, Xt = {
  4440. id: "sheet.mutation.set-col-hidden",
  4441. type: v.MUTATION,
  4442. handler: (n, e) => {
  4443. const o = n.get(M).getUniverSheetInstance(e.unitId);
  4444. if (!o)
  4445. return !1;
  4446. const s = o.getSheetBySheetId(e.subUnitId).getColumnManager();
  4447. for (let r = 0; r < e.ranges.length; r++) {
  4448. const i = e.ranges[r];
  4449. for (let a = i.startColumn; a < i.endColumn + 1; a++) {
  4450. const u = s.getColumnOrCreate(a);
  4451. u != null && (u.hd = te.TRUE);
  4452. }
  4453. }
  4454. return !0;
  4455. }
  4456. }, Lu = (n, e) => {
  4457. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  4458. throw new Error("universheet is null error!");
  4459. return {
  4460. unitId: e.unitId,
  4461. subUnitId: e.subUnitId,
  4462. ranges: e.ranges
  4463. };
  4464. }, qt = {
  4465. id: "sheet.mutation.set-col-visible",
  4466. type: v.MUTATION,
  4467. handler: (n, e) => {
  4468. const o = n.get(M).getUniverSheetInstance(e.unitId);
  4469. if (!o)
  4470. return !1;
  4471. const s = o.getSheetBySheetId(e.subUnitId).getColumnManager();
  4472. for (let r = 0; r < e.ranges.length; r++) {
  4473. const i = e.ranges[r];
  4474. for (let a = i.startColumn; a < i.endColumn + 1; a++) {
  4475. const u = s.getColumnOrCreate(a);
  4476. u != null && (u.hd = te.FALSE);
  4477. }
  4478. }
  4479. return !0;
  4480. }
  4481. }, Kn = {
  4482. type: v.COMMAND,
  4483. id: "sheet.command.set-col-visible-on-cols",
  4484. handler: (n, e) => {
  4485. var C, S;
  4486. const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(V), i = n.get(E), a = n.get(M), u = N(a, { unitId: t, subUnitId: o });
  4487. if (!u) return !1;
  4488. const { worksheet: l } = u, c = {
  4489. unitId: t,
  4490. subUnitId: o,
  4491. ranges: s
  4492. }, d = {
  4493. unitId: t,
  4494. subUnitId: o,
  4495. reveal: !0,
  4496. selections: s.map((I) => ({ range: I, primary: ve(I, l), style: null }))
  4497. }, h = Lu(n, c), m = {
  4498. unitId: t,
  4499. subUnitId: o,
  4500. selections: Er(s).map((I) => ({
  4501. range: I,
  4502. primary: ve(I, l),
  4503. style: null
  4504. }))
  4505. }, g = z([
  4506. { id: qt.id, params: c },
  4507. { id: re.id, params: d }
  4508. ], i), f = r.onCommandExecute({
  4509. id: Kn.id,
  4510. params: e
  4511. }), p = z([...f.redos], i);
  4512. return g.result && p.result && n.get(W).pushUndoRedo({
  4513. unitID: t,
  4514. undoMutations: [
  4515. { id: Xt.id, params: h },
  4516. { id: re.id, params: m },
  4517. ...(C = f.undos) != null ? C : []
  4518. ],
  4519. redoMutations: [
  4520. ...(S = f.preRedos) != null ? S : [],
  4521. { id: qt.id, params: c },
  4522. { id: re.id, params: d },
  4523. ...f.redos
  4524. ]
  4525. }), !0;
  4526. }
  4527. }, br = {
  4528. type: v.COMMAND,
  4529. id: "sheet.command.set-selected-cols-visible",
  4530. handler: (n) => {
  4531. var l;
  4532. const e = n.get(F), t = n.get(E), o = (l = e.getCurrentSelections()) == null ? void 0 : l.map((c) => c.range).filter((c) => c.rangeType === H.COLUMN);
  4533. if (!(o != null && o.length)) return !1;
  4534. const s = N(n.get(M));
  4535. if (!s) return !1;
  4536. const { worksheet: r, unitId: i, subUnitId: a } = s, u = o.map((c) => r.getHiddenCols(c.startColumn, c.endColumn)).flat();
  4537. return t.executeCommand(Kn.id, {
  4538. unitId: i,
  4539. subUnitId: a,
  4540. ranges: u
  4541. });
  4542. }
  4543. }, yr = {
  4544. type: v.COMMAND,
  4545. id: "sheet.command.set-col-hidden",
  4546. handler: (n, e) => {
  4547. var S, I, w, b;
  4548. const t = n.get(F), o = n.get(V), s = n.get(M), r = n.get(E);
  4549. 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 === H.COLUMN);
  4550. if (!(i != null && i.length)) return !1;
  4551. const a = N(s, e);
  4552. if (!a) return !1;
  4553. const { worksheet: u, unitId: l, subUnitId: c } = a;
  4554. i = Vu(a.worksheet, i);
  4555. const d = { unitId: l, subUnitId: c, ranges: i }, h = {
  4556. unitId: l,
  4557. subUnitId: c,
  4558. selections: Er(i).map((y) => ({
  4559. range: y,
  4560. primary: ve(y, u),
  4561. style: null
  4562. }))
  4563. }, m = Wu(n, d), g = {
  4564. unitId: l,
  4565. subUnitId: c,
  4566. reveal: !0,
  4567. selections: i.map((y) => ({
  4568. range: y,
  4569. primary: ve(y, u),
  4570. style: null
  4571. }))
  4572. }, f = z([
  4573. { id: Xt.id, params: d },
  4574. { id: re.id, params: h }
  4575. ], r), p = o.onCommandExecute({
  4576. id: yr.id,
  4577. params: d
  4578. }), C = z([...p.redos], r);
  4579. return f.result && C.result ? (n.get(W).pushUndoRedo({
  4580. unitID: l,
  4581. undoMutations: [
  4582. { id: qt.id, params: m },
  4583. { id: re.id, params: g },
  4584. ...(w = p.undos) != null ? w : []
  4585. ],
  4586. redoMutations: [
  4587. ...(b = p.preRedos) != null ? b : [],
  4588. { id: Xt.id, params: d },
  4589. { id: re.id, params: h },
  4590. ...p.redos
  4591. ]
  4592. }), !0) : !1;
  4593. }
  4594. };
  4595. function Vu(n, e) {
  4596. const t = n.getRowCount() - 1, o = n.getHiddenCols(), s = [];
  4597. return e.forEach((r) => {
  4598. const i = o.filter((a) => a.startColumn >= r.startColumn && a.endColumn <= r.endColumn);
  4599. if (i.length) {
  4600. let a = r.startColumn;
  4601. i.forEach((u) => {
  4602. u.startColumn > a && (s.push({ startColumn: a, endColumn: u.startColumn - 1, startRow: 0, endRow: t }), a = u.endColumn + 1);
  4603. }), a <= r.endColumn && s.push({ startColumn: a, endColumn: r.endColumn, startRow: 0, endRow: t });
  4604. } else
  4605. s.push(r);
  4606. }), s;
  4607. }
  4608. function Er(n) {
  4609. return Hu(n).map((t) => {
  4610. const o = t.startColumn === 0 ? t.endColumn + 1 : t.startColumn - 1;
  4611. return {
  4612. ...t,
  4613. startColumn: o,
  4614. endColumn: o
  4615. };
  4616. });
  4617. }
  4618. function Hu(n) {
  4619. const e = [];
  4620. let t;
  4621. return n.sort((o, s) => o.startColumn - s.startColumn).forEach((o) => {
  4622. if (!t) {
  4623. t = o;
  4624. return;
  4625. }
  4626. t.endColumn === o.startColumn - 1 ? t.endColumn = o.endColumn : (e.push(t), t = o);
  4627. }), e.push(t), e;
  4628. }
  4629. const Ur = {
  4630. id: "sheet.command.set-defined-name",
  4631. type: v.COMMAND,
  4632. handler: (n, e) => {
  4633. var d, h;
  4634. const t = n.get(E), o = n.get(W), s = n.get(V);
  4635. if (!e) return !1;
  4636. const r = {
  4637. ...e
  4638. }, i = Oi(n, e), a = s.onCommandExecute({ id: Ur.id, params: e }), u = [
  4639. ...(d = a.preRedos) != null ? d : [],
  4640. { id: Cn.id, params: i },
  4641. { id: Gt.id, params: r },
  4642. ...a.redos
  4643. ], l = [
  4644. ...(h = a.preUndos) != null ? h : [],
  4645. { id: Cn.id, params: r },
  4646. { id: Gt.id, params: i },
  4647. ...a.undos
  4648. ];
  4649. return z(u, t) ? (o.pushUndoRedo({
  4650. unitID: e.unitId,
  4651. undoMutations: l.filter(Boolean),
  4652. redoMutations: u.filter(Boolean)
  4653. }), !0) : !1;
  4654. }
  4655. }, Pr = (n, e) => {
  4656. const o = n.get(M).getUniverSheetInstance(e.unitId);
  4657. if (o == null)
  4658. throw new Error("universheet is null error!");
  4659. const s = o.getSheetBySheetId(e.subUnitId);
  4660. if (s == null)
  4661. throw new Error("worksheet is null error!");
  4662. const i = s.getConfig().freeze;
  4663. return {
  4664. unitId: e.unitId,
  4665. subUnitId: e.subUnitId,
  4666. ...i
  4667. };
  4668. }, ut = {
  4669. id: "sheet.mutation.set-frozen",
  4670. type: v.MUTATION,
  4671. handler: (n, e) => {
  4672. const o = n.get(M).getUniverSheetInstance(e.unitId);
  4673. if (o == null)
  4674. throw new Error("universheet is null error!");
  4675. const s = o.getSheetBySheetId(e.subUnitId);
  4676. if (!s) return !1;
  4677. const r = s.getConfig(), { startRow: i, startColumn: a, ySplit: u, xSplit: l } = e;
  4678. return r.freeze = { startRow: i, startColumn: a, ySplit: u, xSplit: l }, !0;
  4679. }
  4680. }, Bu = {
  4681. type: v.COMMAND,
  4682. id: "sheet.command.set-frozen",
  4683. handler: (n, e) => {
  4684. const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, { unitId: e.unitId, subUnitId: e.subUnitId });
  4685. if (!r) return !1;
  4686. const { unitId: i, subUnitId: a, worksheet: u } = r, { startColumn: l, startRow: c, xSplit: d, ySplit: h } = e;
  4687. if (c >= u.getRowCount() || l >= u.getColumnCount() || d >= u.getColumnCount() || h >= u.getRowCount())
  4688. return !1;
  4689. const m = {
  4690. unitId: i,
  4691. subUnitId: a,
  4692. ...e
  4693. }, g = Pr(n, m);
  4694. return t.syncExecuteCommand(ut.id, m) ? (o.pushUndoRedo({
  4695. unitID: i,
  4696. undoMutations: [{ id: ut.id, params: g }],
  4697. redoMutations: [{ id: ut.id, params: m }]
  4698. }), !0) : !1;
  4699. }
  4700. }, Fu = {
  4701. type: v.COMMAND,
  4702. id: "sheet.command.cancel-frozen",
  4703. handler: (n, e) => {
  4704. const t = n.get(E), o = n.get(M), s = n.get(W), r = N(o, { unitId: e == null ? void 0 : e.unitId, subUnitId: e == null ? void 0 : e.subUnitId });
  4705. if (!r) return !1;
  4706. const { unitId: i, subUnitId: a } = r, u = {
  4707. unitId: i,
  4708. subUnitId: a,
  4709. startRow: -1,
  4710. startColumn: -1,
  4711. xSplit: 0,
  4712. ySplit: 0
  4713. }, l = Pr(n, u);
  4714. return t.syncExecuteCommand(ut.id, u) && s.pushUndoRedo({
  4715. unitID: i,
  4716. undoMutations: [{ id: ut.id, params: l }],
  4717. redoMutations: [{ id: ut.id, params: u }]
  4718. }), !0;
  4719. }
  4720. }, Vt = {
  4721. id: "sheet.mutation.set-gridlines-color",
  4722. type: v.MUTATION,
  4723. handler: (n, e) => {
  4724. const t = N(n.get(M), e);
  4725. if (!t) return !1;
  4726. const { worksheet: o } = t, s = o.getConfig();
  4727. return s.gridlinesColor = e.color, !0;
  4728. }
  4729. }, ju = {
  4730. type: v.COMMAND,
  4731. id: "sheet.command.set-gridlines-color",
  4732. handler: (n, e) => {
  4733. const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s);
  4734. if (!r) return !1;
  4735. const { worksheet: i } = r, a = i.getConfig().gridlinesColor;
  4736. if (a === (e == null ? void 0 : e.color)) return !1;
  4737. const { unitId: u, subUnitId: l } = r, c = {
  4738. color: e == null ? void 0 : e.color,
  4739. unitId: u,
  4740. subUnitId: l
  4741. }, d = {
  4742. color: a,
  4743. unitId: u,
  4744. subUnitId: l
  4745. };
  4746. return t.syncExecuteCommand(Vt.id, c) ? (o.pushUndoRedo({
  4747. unitID: u,
  4748. undoMutations: [{ id: Vt.id, params: d }],
  4749. redoMutations: [{ id: Vt.id, params: c }]
  4750. }), !0) : !1;
  4751. }
  4752. }, he = {
  4753. id: "sheet.mutation.set-range-protection",
  4754. type: v.MUTATION,
  4755. handler: (n, e) => {
  4756. const { unitId: t, subUnitId: o, rule: s, ruleId: r } = e;
  4757. return n.get(de).setRule(t, o, r, s), !0;
  4758. }
  4759. }, qd = (n, e) => {
  4760. const { unitId: t, subUnitId: o, ruleId: s } = e, i = n.get(de).getRule(t, o, s);
  4761. return i ? {
  4762. id: he.id,
  4763. params: {
  4764. ...e,
  4765. rule: i
  4766. }
  4767. } : null;
  4768. }, Ct = {
  4769. id: "sheet.mutation.set-worksheet-protection",
  4770. type: v.MUTATION,
  4771. handler: (n, e) => {
  4772. const { unitId: t, subUnitId: o, rule: s } = e;
  4773. return n.get(Ye).setRule(t, o, s), !0;
  4774. }
  4775. }, Gu = {
  4776. type: v.COMMAND,
  4777. id: "sheet.command.set-protection",
  4778. async handler(n, e) {
  4779. if (!e)
  4780. return !1;
  4781. const t = n.get(E), o = n.get(W), s = n.get(de), { rule: r, oldRule: i } = e, { unitId: a, subUnitId: u } = r, l = [], c = [];
  4782. return (i == null ? void 0 : i.unitType) === r.unitType ? r.unitType === D.Worksheet ? (l.push({ id: Ct.id, params: { unitId: a, subUnitId: u, rule: r } }), c.push({ id: Ct.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] } }))), z(l, t) && o.pushUndoRedo({
  4783. unitID: a,
  4784. undoMutations: c,
  4785. redoMutations: l
  4786. }), !0;
  4787. }
  4788. }, zu = (n, e) => {
  4789. const { unitId: t, subUnitId: o, rowData: s } = n, r = {}, i = e.getRowManager();
  4790. for (const a in s) {
  4791. const u = s[a], l = i.getRow(Number(a));
  4792. r[a] = Du(l, u);
  4793. }
  4794. return {
  4795. unitId: t,
  4796. subUnitId: o,
  4797. rowData: r
  4798. };
  4799. }, Ht = {
  4800. id: "sheet.mutation.set-row-data",
  4801. type: v.MUTATION,
  4802. handler: (n, e) => {
  4803. const { rowData: t } = e, o = n.get(M), s = N(o, e);
  4804. if (!s) return !1;
  4805. const { worksheet: r } = s, i = r.getRowManager();
  4806. for (const a in t) {
  4807. const u = t[a];
  4808. if (u == null) {
  4809. i.removeRow(Number(a));
  4810. continue;
  4811. }
  4812. const l = i.getRowOrCreate(Number(a));
  4813. Object.assign(l, u);
  4814. }
  4815. return !0;
  4816. }
  4817. }, Ku = {
  4818. type: v.COMMAND,
  4819. id: "sheet.command.set-row-data",
  4820. handler: (n, e) => {
  4821. const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, e);
  4822. if (!r) return !1;
  4823. const { rowData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = {
  4824. subUnitId: u,
  4825. unitId: a,
  4826. rowData: i
  4827. }, d = zu(c, l);
  4828. return t.syncExecuteCommand(Ht.id, c) ? (o.pushUndoRedo({
  4829. unitID: a,
  4830. undoMutations: [{ id: Ht.id, params: d }],
  4831. redoMutations: [{ id: Ht.id, params: c }]
  4832. }), !0) : !1;
  4833. }
  4834. }, Ju = (n, e) => {
  4835. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  4836. throw new Error("universheet is null error!");
  4837. return {
  4838. unitId: e.unitId,
  4839. subUnitId: e.subUnitId,
  4840. ranges: e.ranges
  4841. };
  4842. }, Zt = {
  4843. id: "sheet.mutation.set-row-visible",
  4844. type: v.MUTATION,
  4845. handler: (n, e) => {
  4846. const o = n.get(M).getUniverSheetInstance(e.unitId);
  4847. if (o == null)
  4848. throw new Error("universheet is null error!");
  4849. const s = o.getSheetBySheetId(e.subUnitId).getRowManager();
  4850. for (let r = 0; r < e.ranges.length; r++) {
  4851. const i = e.ranges[r];
  4852. for (let a = i.startRow; a < i.endRow + 1; a++) {
  4853. const u = s.getRowOrCreate(a);
  4854. u != null && (u.hd = 0);
  4855. }
  4856. }
  4857. return !0;
  4858. }
  4859. }, Yu = (n, e) => {
  4860. if (n.get(M).getUniverSheetInstance(e.unitId) == null)
  4861. throw new Error("universheet is null error!");
  4862. return {
  4863. unitId: e.unitId,
  4864. subUnitId: e.subUnitId,
  4865. ranges: e.ranges
  4866. };
  4867. }, Qt = {
  4868. id: "sheet.mutation.set-row-hidden",
  4869. type: v.MUTATION,
  4870. handler: (n, e) => {
  4871. const o = n.get(M).getUniverSheetInstance(e.unitId);
  4872. if (o == null)
  4873. throw new Error("universheet is null error!");
  4874. const s = o.getSheetBySheetId(e.subUnitId).getRowManager();
  4875. for (let r = 0; r < e.ranges.length; r++) {
  4876. const i = e.ranges[r];
  4877. for (let a = i.startRow; a < i.endRow + 1; a++) {
  4878. const u = s.getRowOrCreate(a);
  4879. u != null && (u.hd = 1);
  4880. }
  4881. }
  4882. return !0;
  4883. }
  4884. }, Jn = {
  4885. type: v.COMMAND,
  4886. id: "sheet.command.set-specific-rows-visible",
  4887. handler: (n, e) => {
  4888. var C, S, I;
  4889. const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(E), i = n.get(W), a = n.get(V), u = N(n.get(M), { unitId: t, subUnitId: o });
  4890. if (!u) return !1;
  4891. const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = {
  4892. unitId: t,
  4893. subUnitId: o,
  4894. reveal: !0,
  4895. selections: s.map((w) => ({
  4896. range: w,
  4897. primary: ve(w, l),
  4898. style: null
  4899. }))
  4900. }, h = Ju(n, c), m = {
  4901. unitId: t,
  4902. subUnitId: o,
  4903. selections: Nr(s).map((w) => ({
  4904. range: w,
  4905. primary: ve(w, l),
  4906. style: null
  4907. }))
  4908. }, g = z(
  4909. [
  4910. { id: Zt.id, params: c },
  4911. { id: re.id, params: d }
  4912. ],
  4913. r
  4914. ), f = a.onCommandExecute({
  4915. id: Jn.id,
  4916. params: e
  4917. }), p = z([...f.redos], r);
  4918. return g.result && p.result && i.pushUndoRedo({
  4919. unitID: t,
  4920. undoMutations: [
  4921. ...(C = f.preUndos) != null ? C : [],
  4922. { id: Qt.id, params: h },
  4923. { id: re.id, params: m },
  4924. ...(S = f.undos) != null ? S : []
  4925. ],
  4926. redoMutations: [
  4927. ...(I = f.preRedos) != null ? I : [],
  4928. { id: Zt.id, params: c },
  4929. { id: re.id, params: d },
  4930. ...f.redos
  4931. ]
  4932. }), !0;
  4933. }
  4934. }, Tr = {
  4935. type: v.COMMAND,
  4936. id: "sheet.command.set-selected-rows-visible",
  4937. handler: async (n) => {
  4938. var c;
  4939. const e = n.get(F), t = n.get(M), o = n.get(E), s = (c = e.getCurrentSelections()) == null ? void 0 : c.map((d) => d.range).filter((d) => d.rangeType === H.ROW);
  4940. if (!(s != null && s.length)) return !1;
  4941. const r = N(t);
  4942. if (!r) return !1;
  4943. const { worksheet: i, unitId: a, subUnitId: u } = r, l = s.map((d) => i.getHiddenRows(d.startRow, d.endRow)).flat();
  4944. return o.executeCommand(Jn.id, {
  4945. unitId: a,
  4946. subUnitId: u,
  4947. ranges: l
  4948. });
  4949. }
  4950. }, kr = {
  4951. type: v.COMMAND,
  4952. id: "sheet.command.set-rows-hidden",
  4953. handler: (n, e) => {
  4954. var S, I, w, b, y, x;
  4955. const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), i = n.get(V);
  4956. let a = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((T) => T.range).filter((T) => T.rangeType === H.ROW);
  4957. if (!(a != null && a.length)) return !1;
  4958. const u = N(r, e);
  4959. if (!u) return !1;
  4960. a = Xu(u.worksheet, a);
  4961. const { unitId: l, subUnitId: c, worksheet: d } = u, h = { unitId: l, subUnitId: c, ranges: a }, m = {
  4962. unitId: l,
  4963. subUnitId: c,
  4964. selections: Nr(a).map((T) => ({
  4965. range: T,
  4966. primary: ve(T, d),
  4967. style: null
  4968. }))
  4969. }, g = Yu(n, h), f = {
  4970. unitId: l,
  4971. subUnitId: c,
  4972. reveal: !0,
  4973. selections: a.map((T) => ({
  4974. range: T,
  4975. primary: ve(T, d),
  4976. style: null
  4977. }))
  4978. }, p = i.onCommandExecute({ id: kr.id, params: h });
  4979. return z([
  4980. ...(w = p.preRedos) != null ? w : [],
  4981. { id: Qt.id, params: h },
  4982. { id: re.id, params: m },
  4983. ...p.redos
  4984. ], o).result && s.pushUndoRedo({
  4985. unitID: l,
  4986. undoMutations: [
  4987. ...(b = p.preUndos) != null ? b : [],
  4988. { id: Zt.id, params: g },
  4989. { id: re.id, params: f },
  4990. ...(y = p.undos) != null ? y : []
  4991. ],
  4992. redoMutations: [
  4993. ...(x = p.preRedos) != null ? x : [],
  4994. { id: Qt.id, params: h },
  4995. { id: re.id, params: m },
  4996. ...p.redos
  4997. ]
  4998. }), !0;
  4999. }
  5000. };
  5001. function Xu(n, e) {
  5002. const t = n.getMaxColumns() - 1, o = n.getHiddenRows(), s = [];
  5003. return e.forEach((r) => {
  5004. const i = o.filter((a) => a.startRow >= r.startRow && a.endRow <= r.endRow);
  5005. if (i.length) {
  5006. let a = r.startRow;
  5007. i.forEach((u) => {
  5008. u.startRow > a && (s.push({ startRow: a, endRow: u.startRow - 1, startColumn: 0, endColumn: t }), a = u.endRow + 1);
  5009. }), a <= r.endRow && s.push({ startRow: a, endRow: r.endRow, startColumn: 0, endColumn: t });
  5010. } else
  5011. s.push(r);
  5012. }), s;
  5013. }
  5014. function Nr(n) {
  5015. return qu(n).map((t) => {
  5016. const o = t.startRow === 0 ? t.endRow + 1 : t.startRow - 1;
  5017. return {
  5018. ...t,
  5019. startRow: o,
  5020. endRow: o
  5021. };
  5022. });
  5023. }
  5024. function qu(n) {
  5025. const e = [];
  5026. let t;
  5027. return n.sort((o, s) => o.startRow - s.startRow).forEach((o) => {
  5028. if (!t) {
  5029. t = o;
  5030. return;
  5031. }
  5032. o.startRow === t.endRow + 1 ? t.endRow = o.endRow : (e.push(t), t = o);
  5033. }), e.push(t), e;
  5034. }
  5035. const fe = {
  5036. type: v.COMMAND,
  5037. id: "sheet.command.set-style",
  5038. handler: (n, e) => {
  5039. var b;
  5040. const t = n.get(M), o = N(t, e);
  5041. if (!o) return !1;
  5042. const { unitId: s, subUnitId: r, worksheet: i } = o, { range: a, style: u } = e, l = n.get(E), c = n.get(W), d = n.get(F), h = a ? [a] : (b = d.getCurrentSelections()) == null ? void 0 : b.map((y) => y.range);
  5043. if (!(h != null && h.length))
  5044. return !1;
  5045. const m = new G(), g = Za(i);
  5046. if (O.isArray(u.value))
  5047. for (let y = 0; y < h.length; y++)
  5048. g.forOperableEach(h[y], (x, T, U) => {
  5049. m.setValue(x, T, {
  5050. s: {
  5051. [u.type]: u.value[x - U.startRow][T - U.startColumn]
  5052. }
  5053. });
  5054. });
  5055. else
  5056. for (let y = 0; y < h.length; y++) {
  5057. const x = {
  5058. s: {
  5059. [u.type]: u.value
  5060. }
  5061. };
  5062. g.forOperableEach(h[y], (T, U) => m.setValue(T, U, x));
  5063. }
  5064. const f = {
  5065. subUnitId: r,
  5066. unitId: s,
  5067. cellValue: m.getMatrix()
  5068. }, p = Ae(
  5069. n,
  5070. f
  5071. ), C = l.syncExecuteCommand(
  5072. Q.id,
  5073. f
  5074. ), { undos: S, redos: I } = n.get(V).onCommandExecute({
  5075. id: fe.id,
  5076. params: e
  5077. }), w = z([...I], l);
  5078. return C && w.result ? (c.pushUndoRedo({
  5079. unitID: f.unitId,
  5080. undoMutations: [{ id: Q.id, params: p }, ...S],
  5081. redoMutations: [{ id: Q.id, params: f }, ...I]
  5082. }), !0) : !1;
  5083. }
  5084. }, Zd = {
  5085. type: v.COMMAND,
  5086. id: "sheet.command.set-bold",
  5087. handler: (n) => {
  5088. const e = n.get(F).getCurrentLastSelection();
  5089. if (!e) return !1;
  5090. const t = N(n.get(M));
  5091. if (!t) return !1;
  5092. const { worksheet: o } = t, { actualRow: s, actualColumn: r } = e.primary, a = {
  5093. style: {
  5094. type: "bl",
  5095. value: o.getRange(s, r).getFontWeight() === gi.BOLD ? te.FALSE : te.TRUE
  5096. }
  5097. };
  5098. return n.get(E).syncExecuteCommand(fe.id, a);
  5099. }
  5100. }, Qd = {
  5101. type: v.COMMAND,
  5102. id: "sheet.command.set-italic",
  5103. handler: (n) => {
  5104. const e = n.get(F).getCurrentLastSelection();
  5105. if (!e) return !1;
  5106. const t = N(n.get(M));
  5107. if (!t) return !1;
  5108. const { worksheet: o } = t;
  5109. let s = !0;
  5110. if (e.primary) {
  5111. const { startRow: i, startColumn: a } = e.primary;
  5112. s = o.getRange(i, a).getFontStyle() === fi.ITALIC;
  5113. }
  5114. const r = {
  5115. style: {
  5116. type: "it",
  5117. value: s ? te.FALSE : te.TRUE
  5118. }
  5119. };
  5120. return n.get(E).syncExecuteCommand(fe.id, r);
  5121. }
  5122. }, eh = {
  5123. type: v.COMMAND,
  5124. id: "sheet.command.set-underline",
  5125. handler: (n) => {
  5126. const e = n.get(F).getCurrentLastSelection();
  5127. if (!e) return !1;
  5128. const t = N(n.get(M));
  5129. if (!t) return !1;
  5130. const { worksheet: o } = t;
  5131. let s = !0;
  5132. e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getUnderline().s);
  5133. const r = {
  5134. style: {
  5135. type: "ul",
  5136. value: {
  5137. s: s ? te.FALSE : te.TRUE
  5138. }
  5139. }
  5140. };
  5141. return n.get(E).syncExecuteCommand(fe.id, r);
  5142. }
  5143. }, th = {
  5144. type: v.COMMAND,
  5145. id: "sheet.command.set-stroke",
  5146. handler: (n) => {
  5147. const e = n.get(F).getCurrentLastSelection();
  5148. if (!e) return !1;
  5149. const t = N(n.get(M));
  5150. if (!t) return !1;
  5151. const { worksheet: o } = t;
  5152. let s = !0;
  5153. e.primary && (s = !!o.getRange(e.primary.actualRow, e.primary.actualColumn).getStrikeThrough().s);
  5154. const r = {
  5155. style: {
  5156. type: "st",
  5157. value: { s: s ? te.FALSE : te.TRUE }
  5158. }
  5159. };
  5160. return n.get(E).syncExecuteCommand(fe.id, r);
  5161. }
  5162. }, nh = {
  5163. type: v.COMMAND,
  5164. id: "sheet.command.set-overline",
  5165. handler: (n) => {
  5166. const e = n.get(F).getCurrentLastSelection();
  5167. if (!e) return !1;
  5168. const t = N(n.get(M));
  5169. if (!t) return !1;
  5170. const { worksheet: o } = t;
  5171. let s = !0;
  5172. e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getOverline().s);
  5173. const r = {
  5174. style: {
  5175. type: "ol",
  5176. value: {
  5177. s: s ? te.FALSE : te.TRUE
  5178. }
  5179. }
  5180. };
  5181. return n.get(E).syncExecuteCommand(fe.id, r);
  5182. }
  5183. }, oh = {
  5184. type: v.COMMAND,
  5185. id: "sheet.command.set-font-family",
  5186. handler: (n, e) => {
  5187. if (!e)
  5188. return !1;
  5189. const t = n.get(E), o = {
  5190. style: {
  5191. type: "ff",
  5192. value: e.value
  5193. }
  5194. };
  5195. return t.syncExecuteCommand(fe.id, o);
  5196. }
  5197. }, sh = {
  5198. type: v.COMMAND,
  5199. id: "sheet.command.set-font-size",
  5200. handler: (n, e) => {
  5201. if (!e)
  5202. return !1;
  5203. const t = n.get(E), o = {
  5204. style: {
  5205. type: "fs",
  5206. value: e.value
  5207. }
  5208. };
  5209. return t.syncExecuteCommand(fe.id, o);
  5210. }
  5211. }, Zu = {
  5212. type: v.COMMAND,
  5213. id: "sheet.command.set-text-color",
  5214. handler: (n, e) => {
  5215. if (!e)
  5216. return !1;
  5217. const t = n.get(E), o = {
  5218. style: {
  5219. type: "cl",
  5220. value: {
  5221. rgb: e.value
  5222. }
  5223. }
  5224. };
  5225. return t.syncExecuteCommand(fe.id, o);
  5226. }
  5227. }, Qu = {
  5228. type: v.COMMAND,
  5229. id: "sheet.command.reset-text-color",
  5230. handler: (n) => {
  5231. const e = n.get(E), t = {
  5232. style: {
  5233. type: "cl",
  5234. value: {
  5235. rgb: null
  5236. // use null to reset text color
  5237. }
  5238. }
  5239. };
  5240. return e.syncExecuteCommand(fe.id, t);
  5241. }
  5242. }, el = {
  5243. type: v.COMMAND,
  5244. id: "sheet.command.set-background-color",
  5245. handler: (n, e) => {
  5246. if (!e || !e.value)
  5247. return !1;
  5248. const t = n.get(E), o = {
  5249. style: {
  5250. type: "bg",
  5251. value: {
  5252. rgb: e.value
  5253. }
  5254. }
  5255. };
  5256. return t.syncExecuteCommand(fe.id, o);
  5257. }
  5258. }, tl = {
  5259. type: v.COMMAND,
  5260. id: "sheet.command.reset-background-color",
  5261. handler: (n) => {
  5262. const e = n.get(E), t = {
  5263. style: {
  5264. type: "bg",
  5265. value: {
  5266. rgb: null
  5267. // use null to reset background color
  5268. }
  5269. }
  5270. };
  5271. return e.syncExecuteCommand(fe.id, t);
  5272. }
  5273. }, nl = {
  5274. type: v.COMMAND,
  5275. id: "sheet.command.set-vertical-text-align",
  5276. handler: (n, e) => {
  5277. if (!e)
  5278. return !1;
  5279. const t = n.get(E), o = {
  5280. unitId: e.unitId,
  5281. subUnitId: e.subUnitId,
  5282. range: e.range,
  5283. style: {
  5284. type: "vt",
  5285. value: e.value
  5286. }
  5287. };
  5288. return t.syncExecuteCommand(fe.id, o);
  5289. }
  5290. }, ol = {
  5291. type: v.COMMAND,
  5292. id: "sheet.command.set-horizontal-text-align",
  5293. handler: (n, e) => {
  5294. if (!e)
  5295. return !1;
  5296. const t = n.get(E), o = {
  5297. unitId: e.unitId,
  5298. subUnitId: e.subUnitId,
  5299. range: e.range,
  5300. style: {
  5301. type: "ht",
  5302. value: e.value
  5303. }
  5304. };
  5305. return t.syncExecuteCommand(fe.id, o);
  5306. }
  5307. }, sl = {
  5308. type: v.COMMAND,
  5309. id: "sheet.command.set-text-wrap",
  5310. handler: (n, e) => {
  5311. if (!e)
  5312. return !1;
  5313. const t = n.get(E), o = {
  5314. unitId: e.unitId,
  5315. subUnitId: e.subUnitId,
  5316. range: e.range,
  5317. style: {
  5318. type: "tb",
  5319. value: e.value
  5320. }
  5321. };
  5322. return t.syncExecuteCommand(fe.id, o);
  5323. }
  5324. }, rl = {
  5325. type: v.COMMAND,
  5326. id: "sheet.command.set-text-rotation",
  5327. handler: (n, e) => {
  5328. if (!e)
  5329. return !1;
  5330. const t = typeof e.value == "number" ? { a: e.value } : { a: 0, v: te.TRUE }, o = n.get(E), s = {
  5331. style: {
  5332. type: "tr",
  5333. value: t
  5334. }
  5335. };
  5336. return o.syncExecuteCommand(fe.id, s);
  5337. }
  5338. }, il = (n, e) => {
  5339. const r = n.get(M).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor;
  5340. return {
  5341. ...O.deepClone(e),
  5342. color: r
  5343. };
  5344. }, fn = {
  5345. id: "sheet.mutation.set-tab-color",
  5346. type: v.MUTATION,
  5347. handler: (n, e) => {
  5348. const t = n.get(M).getUniverSheetInstance(e.unitId);
  5349. if (!t) return !1;
  5350. const o = t.getSheetBySheetId(e.subUnitId);
  5351. return o ? (o.getConfig().tabColor = e.color, !0) : !1;
  5352. }
  5353. }, al = {
  5354. type: v.COMMAND,
  5355. id: "sheet.command.set-tab-color",
  5356. handler: (n, e) => {
  5357. const t = n.get(E), o = n.get(W), s = N(n.get(M));
  5358. if (!s) return !1;
  5359. const { unitId: r, subUnitId: i } = s, a = {
  5360. color: e.value,
  5361. unitId: r,
  5362. subUnitId: i
  5363. }, u = il(n, a);
  5364. return t.syncExecuteCommand(fn.id, a) ? (o.pushUndoRedo({
  5365. unitID: r,
  5366. undoMutations: [{ id: fn.id, params: u }],
  5367. redoMutations: [{ id: fn.id, params: a }]
  5368. }), !0) : !1;
  5369. }
  5370. }, Or = {
  5371. id: "sheet.mutation.set-workbook-name",
  5372. type: v.MUTATION,
  5373. handler: (n, e) => {
  5374. const t = n.get(M).getUnit(e.unitId, B.UNIVER_SHEET);
  5375. return t ? (t.setName(e.name), !0) : !1;
  5376. }
  5377. }, Dr = {
  5378. type: v.COMMAND,
  5379. id: "sheet.command.set-workbook-name",
  5380. handler: async (n, e) => {
  5381. var l;
  5382. if (!n.get(M).getUnit(e.unitId, B.UNIVER_SHEET)) return !1;
  5383. const r = n.get(V).onCommandExecute({
  5384. id: Dr.id,
  5385. params: e
  5386. }), i = {
  5387. name: e.name,
  5388. unitId: e.unitId
  5389. }, a = [
  5390. ...(l = r.preRedos) != null ? l : [],
  5391. { id: Or.id, params: i },
  5392. ...r.redos
  5393. ], u = n.get(E);
  5394. return z(a, u).result;
  5395. }
  5396. }, an = {
  5397. id: "sheet.operation.set-worksheet-active",
  5398. type: v.OPERATION,
  5399. handler: (n, e) => {
  5400. const t = n.get(M).getUniverSheetInstance(e.unitId);
  5401. if (!t) return !1;
  5402. const o = t.getWorksheets();
  5403. for (const [, s] of o)
  5404. if (s.getSheetId() === e.subUnitId)
  5405. return t.setActiveSheet(s), !0;
  5406. return !1;
  5407. }
  5408. }, ul = 4, Ar = {
  5409. type: v.COMMAND,
  5410. id: "sheet.command.set-worksheet-activate",
  5411. handler: (n, e, t) => {
  5412. const o = n.get(E), s = N(n.get(M), e);
  5413. if (!s) return !1;
  5414. const { unitId: r, subUnitId: i } = s;
  5415. return new Promise((a) => {
  5416. setTimeout(() => {
  5417. const u = o.syncExecuteCommand(an.id, {
  5418. unitId: r,
  5419. subUnitId: i
  5420. }, t);
  5421. a(u);
  5422. }, ul);
  5423. });
  5424. }
  5425. }, xr = (n, e) => {
  5426. const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getColumnManager();
  5427. for (let a = 0; a < s.length; a++) {
  5428. const u = s[a];
  5429. for (let l = u.startColumn; l < u.endColumn + 1; l++) {
  5430. const c = i.getColumnOrCreate(l);
  5431. r[l] = c.w;
  5432. }
  5433. }
  5434. return {
  5435. unitId: t,
  5436. subUnitId: o,
  5437. ranges: s,
  5438. colWidth: r
  5439. };
  5440. }, tt = {
  5441. id: "sheet.mutation.set-worksheet-col-width",
  5442. type: v.MUTATION,
  5443. handler: (n, e) => {
  5444. var u;
  5445. const t = n.get(M), o = N(t, e);
  5446. if (!o) return !1;
  5447. const { worksheet: s } = o, r = s.getConfig().defaultColumnWidth, i = s.getColumnManager(), a = e.ranges;
  5448. for (let l = 0; l < a.length; l++) {
  5449. const c = a[l];
  5450. for (let d = c.startColumn; d < c.endColumn + 1; d++) {
  5451. if (!s.getColVisible(d)) continue;
  5452. const m = i.getColumnOrCreate(d);
  5453. typeof e.colWidth == "number" ? m.w = e.colWidth : m.w = (u = e.colWidth[d]) != null ? u : r;
  5454. }
  5455. }
  5456. return !0;
  5457. }
  5458. }, Oo = {
  5459. type: v.COMMAND,
  5460. id: "sheet.command.delta-column-width",
  5461. // eslint-disable-next-line max-lines-per-function
  5462. handler: async (n, e) => {
  5463. const o = n.get(F).getCurrentSelections();
  5464. if (!(o != null && o.length))
  5465. return !1;
  5466. const s = n.get(E), r = n.get(W), i = N(n.get(M));
  5467. if (!i) return !1;
  5468. const { worksheet: a, unitId: u, subUnitId: l } = i, { anchorCol: c, deltaX: d } = e, m = a.getColumnWidth(c) + d, g = o.length === 1 && o[0].range.rangeType === H.ALL, f = o.filter((x) => x.range.rangeType === H.COLUMN), p = g ? H.ALL : f.some(({ range: x }) => {
  5469. const { startColumn: T, endColumn: U } = x;
  5470. return T <= c && c <= U;
  5471. }) ? H.COLUMN : H.NORMAL;
  5472. let C;
  5473. if (p === H.ALL) {
  5474. const x = a.getRowCount(), T = new Array(a.getColumnCount()).fill(void 0).map(
  5475. (U, P) => ({ startRow: 0, endRow: x - 1, startColumn: P, endColumn: P })
  5476. );
  5477. C = {
  5478. subUnitId: l,
  5479. unitId: u,
  5480. colWidth: m,
  5481. ranges: T
  5482. };
  5483. } else p === H.COLUMN ? C = {
  5484. subUnitId: l,
  5485. unitId: u,
  5486. ranges: f.map((x) => k.clone(x.range)),
  5487. colWidth: m
  5488. } : C = {
  5489. subUnitId: l,
  5490. unitId: u,
  5491. colWidth: m,
  5492. ranges: [
  5493. {
  5494. startRow: 0,
  5495. endRow: a.getMaxRows() - 1,
  5496. startColumn: c,
  5497. endColumn: c
  5498. }
  5499. ]
  5500. };
  5501. const { undos: S, redos: I } = n.get(V).onCommandExecute({
  5502. id: Oo.id,
  5503. params: C
  5504. }), w = xr(
  5505. C,
  5506. a
  5507. ), b = s.syncExecuteCommand(
  5508. tt.id,
  5509. C
  5510. ), y = z([...I], s);
  5511. return b && y.result && r.pushUndoRedo({
  5512. unitID: u,
  5513. undoMutations: [{ id: tt.id, params: w }, ...S],
  5514. redoMutations: [{ id: tt.id, params: C }, ...I]
  5515. }), !0;
  5516. }
  5517. }, Mn = {
  5518. type: v.COMMAND,
  5519. id: "sheet.command.set-worksheet-col-width",
  5520. handler: (n, e) => {
  5521. var S, I, w, b;
  5522. const t = n.get(F), o = n.get(E), s = n.get(W), 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);
  5523. if (!(i != null && i.length)) return !1;
  5524. const a = N(n.get(M), e);
  5525. if (!a) return !1;
  5526. const { subUnitId: u, unitId: l, worksheet: c } = a, d = {
  5527. subUnitId: u,
  5528. unitId: l,
  5529. ranges: i,
  5530. colWidth: e.value
  5531. }, h = xr(d, c), m = o.syncExecuteCommand(tt.id, d), { undos: g, redos: f } = n.get(V).onCommandExecute({
  5532. id: Mn.id,
  5533. params: d
  5534. }), p = r.onCommandExecute({
  5535. id: Mn.id,
  5536. params: d
  5537. }), C = z([...f, ...p.redos], o);
  5538. return m && C.result ? (s.pushUndoRedo({
  5539. unitID: l,
  5540. undoMutations: [...(w = p.preUndos) != null ? w : [], { id: tt.id, params: h }, ...g],
  5541. redoMutations: [...(b = p.preRedos) != null ? b : [], { id: tt.id, params: d }, ...f]
  5542. }), !0) : !1;
  5543. }
  5544. }, ll = {
  5545. type: v.COMMAND,
  5546. id: "sheet.command.set-col-is-auto-width",
  5547. handler: async (n, e) => {
  5548. const t = n.get(E), o = n.get(W), s = n.get(F), r = n.get(M), i = N(r, e);
  5549. if (!i) return !1;
  5550. const { unitId: a, subUnitId: u } = i;
  5551. let l = [];
  5552. if (e != null && e.ranges)
  5553. l = [...e.ranges];
  5554. else {
  5555. const g = s.getCurrentSelections();
  5556. for (let f = 0; f < g.length; f++)
  5557. l.push(g[f].range);
  5558. }
  5559. if (!(l != null && l.length))
  5560. return !1;
  5561. const c = {
  5562. unitId: a,
  5563. subUnitId: u,
  5564. ranges: l
  5565. }, { undos: d, redos: h } = n.get(V).onCommandExecute({
  5566. id: ll.id,
  5567. params: c
  5568. });
  5569. return z([...h], t).result ? (o.pushUndoRedo({
  5570. unitID: a,
  5571. undoMutations: [...d],
  5572. redoMutations: [...h]
  5573. }), !0) : !1;
  5574. }
  5575. }, Bt = {
  5576. id: "sheet.mutation.set-worksheet-default-style",
  5577. type: v.MUTATION,
  5578. handler: (n, e) => {
  5579. const { defaultStyle: t } = e, o = n.get(M), s = N(o);
  5580. if (!s) return !1;
  5581. const { worksheet: r } = s;
  5582. return r ? (r.setDefaultCellStyle(t), !0) : !1;
  5583. }
  5584. }, cl = (n, e) => {
  5585. const t = Et(n.get(M), e);
  5586. if (!t)
  5587. throw new Error("[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!");
  5588. const { worksheet: o } = t;
  5589. return {
  5590. unitId: e.unitId,
  5591. subUnitId: o.getSheetId(),
  5592. defaultStyle: o.getDefaultCellStyle()
  5593. };
  5594. }, dl = {
  5595. type: v.COMMAND,
  5596. id: "sheet.command.set-worksheet-default-style",
  5597. handler: (n, e) => {
  5598. const t = n.get(E), o = n.get(W), { unitId: s } = e, r = cl(n, e);
  5599. return t.syncExecuteCommand(Bt.id, e) ? (o.pushUndoRedo({
  5600. unitID: s,
  5601. undoMutations: [{ id: Bt.id, params: r }],
  5602. redoMutations: [{ id: Bt.id, params: e }]
  5603. }), !0) : !1;
  5604. }
  5605. }, $r = (n, e) => {
  5606. const t = Et(n.get(M), e);
  5607. if (!t)
  5608. throw new Error("[SetWorksheetHideMutationFactory]: worksheet is null error!");
  5609. const { worksheet: o } = t;
  5610. return {
  5611. hidden: o.isSheetHidden(),
  5612. unitId: e.unitId,
  5613. subUnitId: o.getSheetId()
  5614. };
  5615. }, lt = {
  5616. id: "sheet.mutation.set-worksheet-hidden",
  5617. type: v.MUTATION,
  5618. handler: (n, e) => {
  5619. const t = n.get(M).getUniverSheetInstance(e.unitId);
  5620. if (t == null)
  5621. return !1;
  5622. const o = t.getSheetBySheetId(e.subUnitId);
  5623. return o ? (o.getConfig().hidden = e.hidden, !0) : !1;
  5624. }
  5625. }, hl = {
  5626. type: v.COMMAND,
  5627. id: "sheet.command.set-worksheet-hidden",
  5628. handler: (n, e) => {
  5629. const t = n.get(E), o = n.get(W), s = n.get(bt), r = n.get(Ke), i = N(n.get(M), e);
  5630. if (!i) return !1;
  5631. const { workbook: a, worksheet: u, unitId: l, subUnitId: c } = i;
  5632. if (u.getConfig().hidden === te.TRUE) return !1;
  5633. const h = {
  5634. unitId: l,
  5635. subUnitId: c,
  5636. hidden: te.TRUE
  5637. }, m = $r(n, h);
  5638. return a.getSheets().filter((C) => C.getConfig().hidden === te.FALSE).length === 1 ? (s.emit(r.t("sheets.info.hideSheet")), !1) : t.syncExecuteCommand(lt.id, h) ? (o.pushUndoRedo({
  5639. unitID: l,
  5640. undoMutations: [{ id: lt.id, params: m }],
  5641. redoMutations: [{ id: lt.id, params: h }]
  5642. }), !0) : !1;
  5643. }
  5644. }, ml = (n, e) => {
  5645. const t = Et(n.get(M), e);
  5646. if (!t)
  5647. throw new Error("[SetWorksheetNameMutationFactory]: worksheet is null error!");
  5648. const { worksheet: o } = t;
  5649. return {
  5650. unitId: e.unitId,
  5651. name: o.getName(),
  5652. subUnitId: o.getSheetId()
  5653. };
  5654. }, _n = {
  5655. id: "sheet.mutation.set-worksheet-name",
  5656. type: v.MUTATION,
  5657. handler: (n, e) => {
  5658. const t = n.get(M).getUniverSheetInstance(e.unitId);
  5659. if (t == null)
  5660. return !1;
  5661. const o = t.getSheetBySheetId(e.subUnitId);
  5662. return o ? (o.getConfig().name = e.name, !0) : !1;
  5663. }
  5664. }, Do = {
  5665. type: v.COMMAND,
  5666. id: "sheet.command.set-worksheet-name",
  5667. handler: (n, e) => {
  5668. var g, f;
  5669. const t = n.get(E), o = n.get(W), s = n.get(V), r = N(n.get(M), e);
  5670. if (!r) return !1;
  5671. const { unitId: i, subUnitId: a } = r, u = {
  5672. subUnitId: a,
  5673. name: e.name,
  5674. unitId: i
  5675. }, l = ml(
  5676. n,
  5677. u
  5678. ), c = s.onCommandExecute({
  5679. id: Do.id,
  5680. params: e
  5681. }), d = [
  5682. ...(g = c.preRedos) != null ? g : [],
  5683. { id: _n.id, params: u },
  5684. ...c.redos
  5685. ], h = [
  5686. ...(f = c.preUndos) != null ? f : [],
  5687. { id: _n.id, params: l },
  5688. ...c.undos
  5689. ];
  5690. return z(d, t).result ? (o.pushUndoRedo({
  5691. unitID: i,
  5692. undoMutations: h,
  5693. redoMutations: d
  5694. }), !0) : !1;
  5695. }
  5696. }, gl = (n, e) => ({
  5697. ...O.deepClone(e),
  5698. toOrder: e.fromOrder,
  5699. fromOrder: e.toOrder
  5700. }), Rn = {
  5701. id: "sheet.mutation.set-worksheet-order",
  5702. type: v.MUTATION,
  5703. handler: (n, e) => {
  5704. const t = n.get(M).getUniverSheetInstance(e.unitId);
  5705. if (!t) return !1;
  5706. const o = t.getConfig();
  5707. return o.sheetOrder.splice(e.fromOrder, 1), o.sheetOrder.splice(e.toOrder, 0, e.subUnitId), !0;
  5708. }
  5709. }, Wr = {
  5710. type: v.COMMAND,
  5711. id: "sheet.command.set-worksheet-order",
  5712. handler: (n, e) => {
  5713. const t = n.get(E), o = n.get(W), s = N(n.get(M), e);
  5714. if (!s) return !1;
  5715. const { workbook: r, unitId: i, subUnitId: a } = s, l = {
  5716. fromOrder: r.getConfig().sheetOrder.indexOf(a),
  5717. toOrder: e.order,
  5718. unitId: i,
  5719. subUnitId: a
  5720. }, c = gl(n, l);
  5721. return t.syncExecuteCommand(Rn.id, l) ? (o.pushUndoRedo({
  5722. unitID: i,
  5723. undoMutations: [{ id: Rn.id, params: c }],
  5724. redoMutations: [{ id: Rn.id, params: l }]
  5725. }), !0) : !1;
  5726. }
  5727. };
  5728. class un {
  5729. constructor() {
  5730. R(this, "_model", /* @__PURE__ */ new Map());
  5731. R(this, "_pointChange", new Le());
  5732. R(this, "pointChange$", this._pointChange.asObservable());
  5733. }
  5734. addRule(e) {
  5735. this._ensureSubUnitMap(e.unitId).set(e.subUnitId, e), this._pointChange.next(e);
  5736. }
  5737. deleteRule(e, t) {
  5738. var s, r, i;
  5739. const o = (s = this._model.get(e)) == null ? void 0 : s.get(t);
  5740. o && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.delete(t), this._pointChange.next(o));
  5741. }
  5742. getRule(e, t) {
  5743. var o, s;
  5744. return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
  5745. }
  5746. toObject() {
  5747. const e = {};
  5748. return [...this._model.keys()].forEach((o) => {
  5749. const s = this._model.get(o);
  5750. s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
  5751. const a = s.get(i);
  5752. a && e[o].push(a);
  5753. }));
  5754. }), e;
  5755. }
  5756. fromObject(e) {
  5757. const t = /* @__PURE__ */ new Map();
  5758. Object.keys(e).forEach((o) => {
  5759. const s = e[o];
  5760. if (s != null && s.length) {
  5761. const r = /* @__PURE__ */ new Map();
  5762. s.forEach((i) => {
  5763. r.set(i.subUnitId, i);
  5764. }), t.set(o, r);
  5765. }
  5766. }), this._model = t;
  5767. }
  5768. deleteUnitModel(e) {
  5769. this._model.delete(e);
  5770. }
  5771. _ensureSubUnitMap(e) {
  5772. let t = this._model.get(e);
  5773. return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
  5774. }
  5775. getTargetByPermissionId(e, t) {
  5776. const o = this._model.get(e);
  5777. if (!o) return null;
  5778. for (const [s, r] of o)
  5779. if (r.permissionId === t)
  5780. return [e, s];
  5781. }
  5782. }
  5783. class Lr {
  5784. constructor(e, t, o) {
  5785. R(this, "type", D.SelectRange);
  5786. R(this, "subType", _.Delete);
  5787. R(this, "status", J.INIT);
  5788. R(this, "value", !0);
  5789. R(this, "id");
  5790. R(this, "unitId");
  5791. R(this, "subUnitId");
  5792. R(this, "permissionId");
  5793. this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Delete}.${o}`;
  5794. }
  5795. }
  5796. class Vr {
  5797. constructor(e, t, o) {
  5798. R(this, "type", D.SelectRange);
  5799. R(this, "subType", _.ManageCollaborator);
  5800. R(this, "status", J.INIT);
  5801. R(this, "value", !0);
  5802. R(this, "id");
  5803. R(this, "unitId");
  5804. R(this, "subUnitId");
  5805. R(this, "permissionId");
  5806. this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.ManageCollaborator}.${o}`;
  5807. }
  5808. }
  5809. const Ie = () => [Io, Pe, Vr, Lr], it = [_.Edit, _.View, _.ManageCollaborator, _.Delete], rh = (n = "unitId", e = "subUnitId", t = "permissionId") => Ie().reduce((o, s) => {
  5810. const r = new s(n, e, t);
  5811. return o[r.subType] = r.value, o;
  5812. }, {}), en = () => [
  5813. Me,
  5814. Gs,
  5815. Ws,
  5816. Js,
  5817. Ls,
  5818. js,
  5819. Mo,
  5820. Hs,
  5821. Bs,
  5822. bo,
  5823. vo,
  5824. Fs,
  5825. Ks,
  5826. _o,
  5827. eu,
  5828. Ys,
  5829. zs,
  5830. Vs
  5831. ], fl = [
  5832. _.Edit,
  5833. _.Print,
  5834. _.Comment,
  5835. _.View,
  5836. _.Copy,
  5837. _.Export,
  5838. _.ManageCollaborator,
  5839. _.CreateSheet,
  5840. _.DeleteSheet,
  5841. _.RenameSheet,
  5842. _.HideSheet,
  5843. _.Duplicate,
  5844. _.Share,
  5845. _.MoveSheet,
  5846. _.CopySheet,
  5847. _.RecoverHistory,
  5848. _.ViewHistory,
  5849. _.CreatePermissionObject
  5850. ], we = () => [
  5851. Te,
  5852. Hn,
  5853. rr,
  5854. Zs
  5855. ], ke = () => [
  5856. Xs,
  5857. qs,
  5858. Qs,
  5859. er,
  5860. tr,
  5861. nr,
  5862. sr,
  5863. or,
  5864. ir,
  5865. ar,
  5866. wn,
  5867. $t,
  5868. Wt,
  5869. ur
  5870. ], eo = [
  5871. _.Copy,
  5872. _.DeleteColumn,
  5873. _.DeleteRow,
  5874. _.EditExtraObject,
  5875. _.Filter,
  5876. _.InsertColumn,
  5877. _.InsertRow,
  5878. _.InsertHyperlink,
  5879. _.PivotTable,
  5880. _.SetCellStyle,
  5881. _.SetCellValue,
  5882. _.SetColumnStyle,
  5883. _.SetRowStyle,
  5884. _.Sort
  5885. ];
  5886. var Rl = Object.defineProperty, pl = Object.getOwnPropertyDescriptor, Cl = (n, e, t, o) => {
  5887. for (var s = o > 1 ? void 0 : o ? pl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  5888. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  5889. return o && s && Rl(e, t, s), s;
  5890. }, Ze = (n, e) => (t, o) => e(t, o, n);
  5891. const Sl = "SHEET_WORKSHEET_PROTECTION_PLUGIN", wl = "SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN";
  5892. let bn = class extends ps {
  5893. constructor(n, e, t, o, s, r, i, a) {
  5894. 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();
  5895. }
  5896. _init() {
  5897. const n = (e) => {
  5898. const t = e.getUnitId(), o = (s) => {
  5899. const r = s.getSheetId();
  5900. [...we(), ...ke()].forEach((i) => {
  5901. const a = new i(t, r);
  5902. this._permissionService.addPermissionPoint(a);
  5903. }), this._logService.debug("[WorksheetPermissionService]", "Initialization completed", t, r);
  5904. };
  5905. e.getSheets().forEach((s) => {
  5906. o(s);
  5907. }), e.sheetCreated$.subscribe((s) => {
  5908. o(s);
  5909. }), e.sheetDisposed$.subscribe((s) => {
  5910. const r = s.getSheetId();
  5911. this._rangeProtectionRuleModel.getSubunitRuleList(t, r).forEach((a) => {
  5912. [...Ie()].forEach((u) => {
  5913. const l = new u(t, r, a.permissionId);
  5914. this._permissionService.deletePermissionPoint(l.id);
  5915. });
  5916. }), [...we(), ...ke()].forEach((a) => {
  5917. const u = new a(t, r);
  5918. this._permissionService.deletePermissionPoint(u.id);
  5919. });
  5920. });
  5921. };
  5922. this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => {
  5923. n(e);
  5924. }), this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).pipe(Bo(this.dispose$)).subscribe(n), this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).pipe(Bo(this.dispose$)).subscribe((e) => {
  5925. e.getSheets().forEach((t) => {
  5926. const o = e.getUnitId(), s = t.getSheetId();
  5927. we().forEach((r) => {
  5928. const i = new r(o, s);
  5929. this._permissionService.deletePermissionPoint(i.id);
  5930. });
  5931. });
  5932. });
  5933. }
  5934. _initRuleChange() {
  5935. this.disposeWithMe(
  5936. this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => {
  5937. switch (n.type) {
  5938. case "add":
  5939. break;
  5940. case "delete": {
  5941. we().forEach((e) => {
  5942. const t = new e(n.unitId, n.subUnitId);
  5943. this._permissionService.updatePermissionPoint(t.id, !0);
  5944. });
  5945. break;
  5946. }
  5947. case "set": {
  5948. we().forEach((e) => {
  5949. const t = new e(n.unitId, n.subUnitId);
  5950. this._permissionService.updatePermissionPoint(t.id, n.rule);
  5951. });
  5952. break;
  5953. }
  5954. }
  5955. })
  5956. );
  5957. }
  5958. _initRuleSnapshot() {
  5959. const n = () => {
  5960. const t = this._worksheetProtectionRuleModel.toObject();
  5961. return JSON.stringify(t);
  5962. }, e = (t) => {
  5963. if (!t)
  5964. return {};
  5965. try {
  5966. return JSON.parse(t);
  5967. } catch {
  5968. return {};
  5969. }
  5970. };
  5971. this.disposeWithMe(
  5972. this._resourceManagerService.registerPluginResource({
  5973. toJson: n,
  5974. parseJson: e,
  5975. pluginName: Sl,
  5976. businesses: [Sn.UNIVER_SHEET],
  5977. onLoad: (t, o) => {
  5978. this._worksheetProtectionRuleModel.fromObject(o), Object.keys(o).forEach((s) => {
  5979. we().forEach((r) => {
  5980. const i = new r(t, s);
  5981. i.value = !1, this._permissionService.addPermissionPoint(i);
  5982. });
  5983. }), this._worksheetProtectionRuleModel.changeRuleInitState(!0);
  5984. },
  5985. onUnLoad: (t) => {
  5986. const o = this._univerInstanceService.getUnit(t);
  5987. o && (o.getSheets().forEach((s) => {
  5988. const r = s.getSheetId();
  5989. [...we(), ...ke()].forEach((i) => {
  5990. const a = new i(t, r);
  5991. this._permissionService.deletePermissionPoint(a.id);
  5992. });
  5993. }), en().forEach((s) => {
  5994. const r = new s(t);
  5995. this._permissionService.deletePermissionPoint(r.id);
  5996. })), this._worksheetProtectionRuleModel.deleteUnitModel(t);
  5997. }
  5998. })
  5999. );
  6000. }
  6001. _initPointSnapshot() {
  6002. const n = () => {
  6003. const t = this._worksheetProtectionPointRuleModel.toObject();
  6004. return JSON.stringify(t);
  6005. }, e = (t) => {
  6006. if (!t)
  6007. return {};
  6008. try {
  6009. return JSON.parse(t);
  6010. } catch {
  6011. return {};
  6012. }
  6013. };
  6014. this.disposeWithMe(
  6015. this._resourceManagerService.registerPluginResource({
  6016. toJson: n,
  6017. parseJson: e,
  6018. pluginName: wl,
  6019. businesses: [Sn.UNIVER_SHEET],
  6020. onLoad: (t, o) => {
  6021. this._worksheetProtectionPointRuleModel.fromObject(o), Object.keys(o).forEach((s) => {
  6022. ke().forEach((r) => {
  6023. const i = new r(t, s);
  6024. this._permissionService.addPermissionPoint(i);
  6025. });
  6026. });
  6027. },
  6028. onUnLoad: (t) => {
  6029. this._worksheetProtectionPointRuleModel.deleteUnitModel(t);
  6030. }
  6031. })
  6032. );
  6033. }
  6034. };
  6035. bn = Cl([
  6036. Ze(0, L(Fe)),
  6037. Ze(1, L(M)),
  6038. Ze(2, L(Ro)),
  6039. Ze(3, L(Ye)),
  6040. Ze(4, L(un)),
  6041. Ze(5, L(nn)),
  6042. Ze(6, L(de)),
  6043. Ze(7, L(Es))
  6044. ], bn);
  6045. const Ao = {
  6046. id: "sheet.mutation.set-worksheet-permission-points",
  6047. type: v.MUTATION,
  6048. handler: (n, e) => {
  6049. const { rule: t } = e;
  6050. return n.get(un).addRule(t), !0;
  6051. }
  6052. }, Il = {
  6053. type: v.COMMAND,
  6054. id: "sheet.command.set-worksheet-permission-points",
  6055. async handler(n, e) {
  6056. if (!e)
  6057. return !1;
  6058. const t = n.get(E), { rule: o } = e;
  6059. return t.executeCommand(Ao.id, {
  6060. rule: o,
  6061. unitId: o.unitId,
  6062. subUnitId: o.subUnitId
  6063. }), !0;
  6064. }
  6065. }, vl = {
  6066. type: v.COMMAND,
  6067. id: "sheet.command.set-worksheet-protection",
  6068. async handler(n, e) {
  6069. if (!e)
  6070. return !1;
  6071. const t = n.get(E), o = n.get(W), { rule: s, permissionId: r, oldRule: i } = e, { unitId: a, subUnitId: u } = s, l = { ...s, permissionId: r };
  6072. if (await t.executeCommand(Ct.id, {
  6073. unitId: a,
  6074. subUnitId: u,
  6075. newRule: l
  6076. })) {
  6077. const d = [{ id: Ct.id, params: { unitId: a, subUnitId: u, newRule: l } }], h = [{ id: Ct.id, params: { unitId: a, subUnitId: u, rule: i } }];
  6078. o.pushUndoRedo({
  6079. unitID: a,
  6080. redoMutations: d,
  6081. undoMutations: h
  6082. });
  6083. }
  6084. return !0;
  6085. }
  6086. }, Ml = 2e3, Hr = (n, e) => {
  6087. const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager();
  6088. for (const { startRow: a, endRow: u } of s)
  6089. for (let l = a; l < u + 1; l++) {
  6090. const c = i.getRowOrCreate(l);
  6091. r[l] = c.h;
  6092. }
  6093. return {
  6094. unitId: t,
  6095. subUnitId: o,
  6096. ranges: s,
  6097. rowHeight: r
  6098. };
  6099. }, xo = (n, e) => {
  6100. const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager();
  6101. for (const { startRow: a, endRow: u } of s)
  6102. for (let l = a; l <= u; l++) {
  6103. const c = i.getRowOrCreate(l);
  6104. r[l] = c.ia;
  6105. }
  6106. return {
  6107. unitId: t,
  6108. subUnitId: o,
  6109. ranges: s,
  6110. autoHeightInfo: r
  6111. };
  6112. }, ih = (n, e) => {
  6113. const { unitId: t, subUnitId: o, rowsAutoHeightInfo: s } = n, r = [], i = e.getRowManager();
  6114. for (const a of s) {
  6115. const { row: u } = a, { ah: l } = i.getRowOrCreate(u);
  6116. r.push({ row: u, autoHeight: l });
  6117. }
  6118. return {
  6119. unitId: t,
  6120. subUnitId: o,
  6121. rowsAutoHeightInfo: r
  6122. };
  6123. }, nt = {
  6124. id: "sheet.mutation.set-worksheet-row-height",
  6125. type: v.MUTATION,
  6126. handler: (n, e) => {
  6127. var l;
  6128. const { ranges: t, rowHeight: o } = e, s = n.get(M), r = N(s, e);
  6129. if (!r) return !1;
  6130. const { worksheet: i } = r, a = i.getRowManager(), u = i.getConfig().defaultRowHeight;
  6131. for (const { startRow: c, endRow: d } of t)
  6132. for (let h = c; h <= d; h++) {
  6133. const m = a.getRowOrCreate(h);
  6134. typeof o == "number" ? m.h = o : m.h = (l = o[h]) != null ? l : u, m.h = Math.min(Ml, m.h);
  6135. }
  6136. return !0;
  6137. }
  6138. }, Oe = {
  6139. id: "sheet.mutation.set-worksheet-row-is-auto-height",
  6140. type: v.MUTATION,
  6141. handler: (n, e) => {
  6142. var a;
  6143. const { ranges: t, autoHeightInfo: o } = e, s = n.get(M), r = N(s, e);
  6144. if (!r) return !1;
  6145. const i = r.worksheet.getRowManager();
  6146. for (const { startRow: u, endRow: l } of t)
  6147. for (let c = u; c <= l; c++) {
  6148. const d = i.getRowOrCreate(c);
  6149. typeof o == "number" ? d.ia = o : d.ia = (a = o[c]) != null ? a : void 0;
  6150. }
  6151. return !0;
  6152. }
  6153. }, Br = {
  6154. id: "sheet.mutation.set-worksheet-row-auto-height",
  6155. type: v.MUTATION,
  6156. handler: (n, e) => {
  6157. const { rowsAutoHeightInfo: t } = e, o = n.get(M), s = N(o, e);
  6158. if (!s) return !1;
  6159. const r = s.worksheet.getRowManager();
  6160. for (const { row: i, autoHeight: a } of t) {
  6161. const u = r.getRowOrCreate(i);
  6162. u.ah = a;
  6163. }
  6164. return !0;
  6165. }
  6166. }, $o = {
  6167. type: v.COMMAND,
  6168. id: "sheet.command.delta-row-height",
  6169. // eslint-disable-next-line max-lines-per-function
  6170. handler: async (n, e) => {
  6171. var U, P;
  6172. const o = n.get(F).getCurrentSelections(), s = n.get(V);
  6173. if (!(o != null && o.length))
  6174. return !1;
  6175. const r = N(n.get(M));
  6176. if (!r) return !1;
  6177. 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 === H.ALL, g = o.filter((A) => A.range.rangeType === H.ROW), f = m ? H.ALL : g.some(({ range: A }) => {
  6178. const { startRow: j, endRow: Z } = A;
  6179. return j <= l && l <= Z;
  6180. }) ? H.ROW : H.NORMAL;
  6181. let p;
  6182. if (f === H.ALL) {
  6183. const A = i.getRowCount(), j = new Array(i.getColumnCount()).fill(void 0).map(
  6184. (Z, Y) => ({ startRow: Y, endRow: Y, startColumn: 0, endColumn: A - 1 })
  6185. );
  6186. p = {
  6187. subUnitId: a,
  6188. unitId: u,
  6189. rowHeight: h,
  6190. ranges: j
  6191. };
  6192. } else f === H.ROW ? p = {
  6193. subUnitId: a,
  6194. unitId: u,
  6195. ranges: g.map((A) => k.clone(A.range)),
  6196. rowHeight: h
  6197. } : p = {
  6198. subUnitId: a,
  6199. unitId: u,
  6200. rowHeight: h,
  6201. ranges: [
  6202. {
  6203. startRow: l,
  6204. endRow: l,
  6205. startColumn: 0,
  6206. endColumn: i.getMaxColumns() - 1
  6207. }
  6208. ]
  6209. };
  6210. const C = Hr(p, i), S = {
  6211. unitId: u,
  6212. subUnitId: a,
  6213. ranges: p.ranges,
  6214. autoHeightInfo: te.FALSE
  6215. }, I = xo(S, i), w = n.get(E), b = n.get(W), y = s.onCommandExecute({
  6216. id: $o.id,
  6217. params: p
  6218. }), x = z([
  6219. {
  6220. id: nt.id,
  6221. params: p
  6222. },
  6223. {
  6224. id: Oe.id,
  6225. params: S
  6226. }
  6227. ], w), T = z([...y.redos], w);
  6228. return x.result && T.result ? (b.pushUndoRedo({
  6229. unitID: u,
  6230. undoMutations: [
  6231. ...(U = y.preUndos) != null ? U : [],
  6232. {
  6233. id: nt.id,
  6234. params: C
  6235. },
  6236. {
  6237. id: Oe.id,
  6238. params: I
  6239. },
  6240. ...y.undos
  6241. ],
  6242. redoMutations: [
  6243. ...(P = y.preRedos) != null ? P : [],
  6244. {
  6245. id: nt.id,
  6246. params: p
  6247. },
  6248. {
  6249. id: Oe.id,
  6250. params: S
  6251. },
  6252. ...y.redos
  6253. ]
  6254. }), !0) : !1;
  6255. }
  6256. }, Wo = {
  6257. type: v.COMMAND,
  6258. id: "sheet.command.set-row-height",
  6259. // eslint-disable-next-line max-lines-per-function
  6260. handler: (n, e) => {
  6261. var I, w, b, y;
  6262. const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), 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);
  6263. if (!(a != null && a.length))
  6264. return !1;
  6265. const u = N(r, e);
  6266. if (!u) return !1;
  6267. const { unitId: l, subUnitId: c, worksheet: d } = u, h = {
  6268. subUnitId: c,
  6269. unitId: l,
  6270. ranges: a,
  6271. rowHeight: e.value
  6272. }, m = Hr(h, d), g = {
  6273. unitId: l,
  6274. subUnitId: c,
  6275. ranges: h.ranges,
  6276. autoHeightInfo: te.FALSE
  6277. }, f = xo(g, d), p = z([
  6278. {
  6279. id: nt.id,
  6280. params: h
  6281. },
  6282. {
  6283. id: Oe.id,
  6284. params: g
  6285. }
  6286. ], o), C = i.onCommandExecute({
  6287. id: Wo.id,
  6288. params: h
  6289. }), S = z([...C.redos], o);
  6290. return p.result && S.result ? (s.pushUndoRedo({
  6291. unitID: l,
  6292. undoMutations: [
  6293. ...(b = C.preRedos) != null ? b : [],
  6294. {
  6295. id: nt.id,
  6296. params: m
  6297. },
  6298. {
  6299. id: Oe.id,
  6300. params: f
  6301. },
  6302. ...C.undos
  6303. ],
  6304. redoMutations: [
  6305. ...(y = C.preRedos) != null ? y : [],
  6306. {
  6307. id: nt.id,
  6308. params: h
  6309. },
  6310. {
  6311. id: Oe.id,
  6312. params: g
  6313. },
  6314. ...C.redos
  6315. ]
  6316. }), !0) : !1;
  6317. }
  6318. }, Lo = {
  6319. type: v.COMMAND,
  6320. id: "sheet.command.set-row-is-auto-height",
  6321. handler: (n, e) => {
  6322. var C, S;
  6323. const t = n.get(E), o = n.get(W), s = n.get(F), r = n.get(M), i = N(r, e);
  6324. if (!i) return !1;
  6325. 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);
  6326. if (!(c != null && c.length))
  6327. return !1;
  6328. const d = {
  6329. unitId: a,
  6330. subUnitId: u,
  6331. ranges: c,
  6332. autoHeightInfo: te.TRUE
  6333. // Hard code first, maybe it will change by the menu item in the future.
  6334. }, h = xo(d, l), m = t.syncExecuteCommand(
  6335. Oe.id,
  6336. d
  6337. ), { undos: g, redos: f } = n.get(V).onCommandExecute({
  6338. id: Lo.id,
  6339. params: d
  6340. }), p = z([...f], t);
  6341. return m && p.result ? (o.pushUndoRedo({
  6342. unitID: a,
  6343. undoMutations: [{ id: Oe.id, params: h }, ...g],
  6344. redoMutations: [{ id: Oe.id, params: d }, ...f]
  6345. }), !0) : !1;
  6346. }
  6347. }, Fr = {
  6348. type: v.COMMAND,
  6349. id: "sheet.command.set-worksheet-show",
  6350. handler: (n, e) => {
  6351. const { unitId: t, subUnitId: o } = e, s = n.get(E), r = n.get(W), i = n.get(M);
  6352. if (!N(n.get(M))) return !1;
  6353. const u = i.getCurrentUnitForType(B.UNIVER_SHEET);
  6354. if (!u) return !1;
  6355. const l = u.getSheetBySheetId(o);
  6356. if (!l || l.getConfig().hidden === te.FALSE) return !1;
  6357. const d = {
  6358. unitId: t,
  6359. subUnitId: o,
  6360. hidden: te.FALSE
  6361. }, h = $r(n, d), m = s.syncExecuteCommand(lt.id, d), g = {
  6362. unitId: t,
  6363. subUnitId: o
  6364. }, f = s.syncExecuteCommand(
  6365. an.id,
  6366. g
  6367. );
  6368. return m && f ? (r.pushUndoRedo({
  6369. unitID: t,
  6370. undoMutations: [
  6371. { id: lt.id, params: h }
  6372. // { id: SetWorksheetActiveOperation.id, params: unActiveMutationParams },
  6373. ],
  6374. redoMutations: [
  6375. // { id: SetWorksheetActiveOperation.id, params: activeSheetMutationParams },
  6376. { id: lt.id, params: d }
  6377. ]
  6378. }), !0) : !1;
  6379. }
  6380. };
  6381. class _l {
  6382. constructor() {
  6383. R(this, "_tabCount", 0);
  6384. R(this, "_commaCount", 0);
  6385. R(this, "_semicolonCount", 0);
  6386. R(this, "_spaceCount", 0);
  6387. }
  6388. add(e) {
  6389. switch (e) {
  6390. case " ":
  6391. this._tabCount++;
  6392. break;
  6393. case ",":
  6394. this._commaCount++;
  6395. break;
  6396. case ";":
  6397. this._semicolonCount++;
  6398. break;
  6399. case " ":
  6400. this._spaceCount++;
  6401. break;
  6402. }
  6403. }
  6404. update(e) {
  6405. e && typeof e == "string" && (e.includes(" ") && this._tabCount++, e.includes(",") && this._commaCount++, e.includes(";") && this._semicolonCount++, e.trim().includes(" ") && this._spaceCount++);
  6406. }
  6407. getDelimiter() {
  6408. const e = Math.max(this._tabCount, this._commaCount, this._semicolonCount, this._spaceCount);
  6409. return e === 0 || e === this._tabCount ? 1 : e === this._commaCount ? 2 : e === this._semicolonCount ? 4 : e === this._spaceCount ? 8 : 1;
  6410. }
  6411. }
  6412. function bl(n, e, t) {
  6413. const o = [];
  6414. 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(" ");
  6415. let s = "";
  6416. for (const i of o)
  6417. s += yl(i);
  6418. let r = "[".concat(s, "]");
  6419. return e && (r += "+"), new RegExp(r);
  6420. }
  6421. function yl(n) {
  6422. return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  6423. }
  6424. const El = (n) => {
  6425. var t;
  6426. return ((t = n.body) == null ? void 0 : t.dataStream.replace(/\r\n$/, "")) || "";
  6427. };
  6428. function Ul(n) {
  6429. if (n != null) {
  6430. if (n.p)
  6431. return El(n.p);
  6432. if (n.v && typeof n.v == "string")
  6433. return n.v;
  6434. if (n.t && (n.t === se.FORCE_STRING || n.t === se.STRING))
  6435. return String(n.v);
  6436. }
  6437. }
  6438. function Pl(n, e, t, o, s = !1) {
  6439. const r = K.transformRange(e, n), { startColumn: i, startRow: a, endColumn: u, endRow: l } = r;
  6440. if (i !== u)
  6441. throw new Error("The range must be in the same column.");
  6442. if (t && (t & 16) > 0 && (o === void 0 || o.length !== 1))
  6443. throw new Error("The custom delimiter must a character.");
  6444. const c = t === void 0, d = c ? new _l() : null, h = [];
  6445. for (let I = a; I <= l; I++) {
  6446. const w = n.getCell(I, i), b = Ul(w);
  6447. h.push(b), d && d.update(b);
  6448. }
  6449. const m = c ? d.getDelimiter() : t, g = bl(m, s, o);
  6450. let f = -1, p = 0, C = 0;
  6451. const S = [];
  6452. for (const I of h) {
  6453. if (I !== void 0) {
  6454. const w = String(I).split(g);
  6455. f < 0 ? f = w.length : f = Math.max(f, w.length), S.push(w), p = C;
  6456. } else
  6457. S.push(void 0);
  6458. C++;
  6459. }
  6460. return {
  6461. rs: S,
  6462. maxLength: f === -1 ? 0 : f,
  6463. lastRow: p
  6464. };
  6465. }
  6466. const Tl = {
  6467. type: v.COMMAND,
  6468. id: "sheet.command.split-text-to-columns",
  6469. // eslint-disable-next-line max-lines-per-function
  6470. handler: (n, e) => {
  6471. const { unitId: t, subUnitId: o, range: s, delimiter: r, customDelimiter: i, treatMultipleDelimitersAsOne: a } = e, u = n.get(E), l = n.get(M), c = n.get(W);
  6472. if (!N(n.get(M))) return !1;
  6473. const h = l.getCurrentUnitForType(B.UNIVER_SHEET);
  6474. if (!h) return !1;
  6475. const m = h.getSheetBySheetId(o);
  6476. if (!m) return !1;
  6477. const { lastRow: g, rs: f, maxLength: p } = Pl(m, s, r, i, a), C = m.getColumnCount(), { startColumn: S } = K.transformRange(s, m);
  6478. if (s.startColumn !== s.endColumn)
  6479. return !1;
  6480. const I = [], w = [], b = S + p + 1 - C;
  6481. if (b > 0) {
  6482. const A = {
  6483. unitId: t,
  6484. subUnitId: o,
  6485. range: {
  6486. startRow: 0,
  6487. endRow: m.getRowCount() - 1,
  6488. startColumn: C - 1,
  6489. endColumn: C - 1 + b
  6490. }
  6491. };
  6492. I.push({
  6493. id: je.id,
  6494. params: A
  6495. });
  6496. const j = yo(
  6497. n,
  6498. A
  6499. );
  6500. w.push({ id: De.id, params: j });
  6501. }
  6502. const y = {
  6503. startRow: s.startRow,
  6504. endRow: g,
  6505. startColumn: S,
  6506. endColumn: S + p
  6507. }, x = new G();
  6508. for (let A = y.startRow; A <= y.endRow; A++)
  6509. for (let j = y.startColumn; j <= y.endColumn; j++) {
  6510. const Z = f[A - y.startRow];
  6511. j === 0 && (Z == null ? void 0 : Z.length) === 1 ? x.setValue(A, j, m.getCell(A, j)) : x.setValue(A, j, {
  6512. v: (Z == null ? void 0 : Z[j - y.startColumn]) || null,
  6513. p: null,
  6514. f: null,
  6515. si: null,
  6516. custom: null
  6517. });
  6518. }
  6519. const T = {
  6520. unitId: t,
  6521. subUnitId: o,
  6522. cellValue: x.clone()
  6523. }, U = Ae(n, T);
  6524. return I.push({
  6525. id: Q.id,
  6526. params: T
  6527. }), w.unshift({
  6528. id: Q.id,
  6529. params: U
  6530. }), z(I, u).result ? (c.pushUndoRedo({
  6531. unitID: t,
  6532. undoMutations: w,
  6533. redoMutations: I
  6534. }), !0) : !1;
  6535. }
  6536. }, kl = {
  6537. id: "sheet.command.toggle-cell-checkbox",
  6538. type: v.COMMAND,
  6539. handler: (n, e) => {
  6540. if (!e)
  6541. return !1;
  6542. const { unitId: t, subUnitId: o, row: s, col: r, paragraphIndex: i } = e, u = n.get(M).getUnit(t, B.UNIVER_SHEET), l = u == null ? void 0 : u.getSheetBySheetId(o), c = n.get(W), d = n.get(E);
  6543. if (!l)
  6544. return !1;
  6545. const h = l.getCell(s, r);
  6546. if (!(h != null && h.p))
  6547. return !1;
  6548. const m = O.deepClone(h.p), g = new Ri(m), f = pi.paragraph.bullet.toggleChecklist({
  6549. document: g,
  6550. paragraphIndex: i
  6551. });
  6552. if (!f)
  6553. return !1;
  6554. Ci.apply(g.getBody(), f.serialize());
  6555. const p = {
  6556. unitId: t,
  6557. subUnitId: o,
  6558. cellValue: {
  6559. [s]: {
  6560. [r]: {
  6561. p: m,
  6562. t: se.STRING
  6563. }
  6564. }
  6565. }
  6566. }, C = {
  6567. id: Q.id,
  6568. params: p
  6569. }, S = Ae(n, p), I = {
  6570. id: Q.id,
  6571. params: S
  6572. }, w = [C], b = [I];
  6573. return c.pushUndoRedo({
  6574. redoMutations: w,
  6575. undoMutations: b,
  6576. unitID: t
  6577. }), d.syncExecuteCommand(C.id, C.params);
  6578. }
  6579. }, Ft = {
  6580. id: "sheet.mutation.toggle-gridlines",
  6581. type: v.MUTATION,
  6582. handler: (n, e) => {
  6583. const t = N(n.get(M), e);
  6584. if (!t) return !1;
  6585. const { worksheet: o } = t, s = o.getConfig();
  6586. return s.showGridlines = e.showGridlines, !0;
  6587. }
  6588. }, Nl = {
  6589. type: v.COMMAND,
  6590. id: "sheet.command.toggle-gridlines",
  6591. handler: (n, e) => {
  6592. const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s);
  6593. if (!r) return !1;
  6594. const { worksheet: i } = r, a = i.getConfig().showGridlines;
  6595. if (a === (e == null ? void 0 : e.showGridlines)) return !1;
  6596. const { unitId: u, subUnitId: l } = r, c = {
  6597. showGridlines: a === te.TRUE ? te.FALSE : te.TRUE,
  6598. unitId: u,
  6599. subUnitId: l
  6600. }, d = {
  6601. showGridlines: a,
  6602. unitId: u,
  6603. subUnitId: l
  6604. };
  6605. return t.syncExecuteCommand(Ft.id, c) ? (o.pushUndoRedo({
  6606. unitID: u,
  6607. undoMutations: [{ id: Ft.id, params: d }],
  6608. redoMutations: [{ id: Ft.id, params: c }]
  6609. }), !0) : !1;
  6610. }
  6611. }, Ol = {
  6612. id: "sheet.command.unregister-worksheet-range-theme-style",
  6613. type: v.COMMAND,
  6614. handler: (n, e) => {
  6615. var h;
  6616. if (!e)
  6617. return !1;
  6618. const { unitId: t, themeName: o } = e, s = n.get(M), r = n.get(E), i = n.get(W), a = n.get(He);
  6619. if (!N(s)) return !1;
  6620. const l = {
  6621. unitId: t,
  6622. themeName: o
  6623. }, c = {
  6624. unitId: t,
  6625. themeName: o,
  6626. rangeThemeStyleJson: (h = a.getRangeThemeStyle(t, o)) == null ? void 0 : h.toJson()
  6627. };
  6628. return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({
  6629. unitID: t,
  6630. undoMutations: [{ id: Yt.id, params: c }],
  6631. redoMutations: [{ id: Uo.id, params: l }]
  6632. }), !0;
  6633. }
  6634. }, Dl = {
  6635. id: "sheet.mutation.empty",
  6636. type: v.MUTATION,
  6637. handler: () => !0
  6638. }, Al = (n) => {
  6639. const e = new G();
  6640. return n.forEach((t) => {
  6641. K.foreach(t, (o, s) => {
  6642. e.setValue(o, s, 1);
  6643. });
  6644. }), e.forValue((t, o) => {
  6645. const s = e.getValue(t - 1, o);
  6646. s && e.setValue(t, o, s + 1);
  6647. }), e;
  6648. }, xl = (n) => {
  6649. const e = n;
  6650. return e.forValue((t, o) => {
  6651. const s = n.getValue(t - 1, o);
  6652. s && e.setValue(t, o, s + 1);
  6653. }), e;
  6654. }, Qo = (n) => {
  6655. const e = {
  6656. area: 0
  6657. }, t = (o, s) => e.area < o ? (e.area = o, e.range = s, !0) : !1;
  6658. return n.forValue((o, s, r) => {
  6659. let i = 1, a = r;
  6660. t(i * a, {
  6661. startRow: o - a + 1,
  6662. endRow: o,
  6663. startColumn: s,
  6664. endColumn: s
  6665. });
  6666. const u = {
  6667. startRow: o - a + 1,
  6668. endRow: o,
  6669. startColumn: 0,
  6670. endColumn: s
  6671. };
  6672. for (let l = s - 1; l >= 0 && n.getValue(o, l); l--) {
  6673. a = Math.min(n.getValue(o, l) || 0, a), i++;
  6674. const c = a * i;
  6675. u.startColumn = l, u.startRow = o - a + 1, t(c, u);
  6676. }
  6677. }), e;
  6678. }, $l = (n, e) => {
  6679. K.foreach(e, (t, o) => {
  6680. n.realDeleteValue(t, o);
  6681. });
  6682. for (let t = e.startColumn; t <= e.endColumn; t++) {
  6683. const o = e.endRow + 1;
  6684. if (n.getValue(o, t) > 0) {
  6685. n.setValue(o, t, 1);
  6686. let r = o + 1;
  6687. for (; n.getValue(r, t) > 0; )
  6688. n.setValue(r, t, n.getValue(r - 1, t) + 1), r++;
  6689. }
  6690. }
  6691. return n;
  6692. }, jr = (n) => {
  6693. const e = [];
  6694. let t = Qo(n);
  6695. for (; t.area > 0; )
  6696. t.range && (e.push(t.range), $l(n, t.range)), t = Qo(n);
  6697. return e;
  6698. }, Gr = (n) => {
  6699. const e = Al(n);
  6700. return jr(e);
  6701. };
  6702. class ah {
  6703. constructor() {
  6704. R(this, "_matrix", new G());
  6705. }
  6706. add(...e) {
  6707. return e.forEach((t) => {
  6708. K.foreach(t, (o, s) => {
  6709. this._matrix.setValue(o, s, 1);
  6710. });
  6711. }), this;
  6712. }
  6713. subtract(...e) {
  6714. return e.forEach((t) => {
  6715. K.foreach(t, (o, s) => {
  6716. this._matrix.realDeleteValue(o, s);
  6717. });
  6718. }), this;
  6719. }
  6720. merge() {
  6721. const e = xl(this._matrix);
  6722. return jr(e);
  6723. }
  6724. }
  6725. const wt = fo("INumfmtService"), uh = (n, e) => {
  6726. const t = n.get(wt), { values: o, unitId: s, subUnitId: r } = e, i = [], a = [];
  6727. Object.keys(o).forEach((l) => {
  6728. o[l].ranges.forEach((d) => {
  6729. K.foreach(d, (h, m) => {
  6730. const g = t.getValue(s, r, h, m);
  6731. g ? i.push({
  6732. pattern: g.pattern,
  6733. row: h,
  6734. col: m
  6735. }) : a.push({ startColumn: m, endColumn: m, startRow: h, endRow: h });
  6736. });
  6737. });
  6738. });
  6739. const u = [];
  6740. if (i.length) {
  6741. const l = lo(s, r, i);
  6742. Object.keys(l.values).forEach((c) => {
  6743. const d = l.values[c];
  6744. d.ranges = Gr(d.ranges);
  6745. }), u.push({
  6746. id: Vo.id,
  6747. params: lo(s, r, i)
  6748. });
  6749. }
  6750. return a.length && u.push({
  6751. id: zr.id,
  6752. params: {
  6753. unitId: s,
  6754. subUnitId: r,
  6755. ranges: a
  6756. }
  6757. }), u;
  6758. }, Vo = {
  6759. id: "sheet.mutation.set.numfmt",
  6760. type: v.MUTATION,
  6761. handler: (n, e) => {
  6762. if (!e)
  6763. return !1;
  6764. const { values: t, refMap: o } = e, s = n.get(wt), r = e.unitId, i = e.subUnitId, a = Object.keys(t).reduce(
  6765. (u, l) => {
  6766. const c = o[l], d = t[l].ranges;
  6767. return c && u.push({
  6768. ...c,
  6769. ranges: d
  6770. }), u;
  6771. },
  6772. []
  6773. );
  6774. return s.setValues(r, i, a), !0;
  6775. }
  6776. }, zr = {
  6777. id: "sheet.mutation.remove.numfmt",
  6778. type: v.MUTATION,
  6779. handler: (n, e) => {
  6780. if (!e)
  6781. return !1;
  6782. const { unitId: t, subUnitId: o, ranges: s } = e;
  6783. return n.get(wt).deleteValues(t, o, s), !0;
  6784. }
  6785. }, lh = (n, e) => {
  6786. const t = n.get(wt), { ranges: o, unitId: s, subUnitId: r } = e, i = [];
  6787. if (o.forEach((u) => {
  6788. K.foreach(u, (l, c) => {
  6789. const d = t.getValue(s, r, l, c);
  6790. d && i.push({
  6791. pattern: d.pattern,
  6792. row: l,
  6793. col: c
  6794. });
  6795. });
  6796. }), !i.length)
  6797. return [];
  6798. const a = lo(s, r, i);
  6799. return Object.keys(a.values).forEach((u) => {
  6800. const l = a.values[u];
  6801. l.ranges = Gr(l.ranges);
  6802. }), [{ id: Vo.id, params: a }];
  6803. }, lo = (n, e, t) => {
  6804. const o = ya(t, "pattern"), s = {}, r = {}, i = Ea();
  6805. return Object.keys(o).forEach((a) => {
  6806. const u = o[a], l = i();
  6807. s[l] = {
  6808. pattern: a
  6809. }, u.forEach((c) => {
  6810. r[l] || (r[l] = { ranges: [] }), r[l].ranges.push(ws(c.row, c.col));
  6811. });
  6812. }), { unitId: n, subUnitId: e, refMap: s, values: r };
  6813. }, Wl = {
  6814. id: "sheet.operation.scroll-to-cell",
  6815. type: v.OPERATION,
  6816. handler: () => !0
  6817. }, Kr = "ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY", Ll = "maxCellsPerSheet", Vl = 3e6;
  6818. var Hl = Object.defineProperty, Bl = Object.getOwnPropertyDescriptor, Fl = (n, e, t, o) => {
  6819. for (var s = o > 1 ? void 0 : o ? Bl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  6820. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  6821. return o && s && Hl(e, t, s), s;
  6822. }, to = (n, e) => (t, o) => e(t, o, n);
  6823. let yn = class extends ae {
  6824. // eslint-disable-next-line max-lines-per-function
  6825. constructor(n, e, t) {
  6826. var s;
  6827. super(), this._commandService = n, this._configService = e, this._dataSyncPrimaryController = t, [
  6828. Q,
  6829. je,
  6830. qe,
  6831. Jt,
  6832. dt,
  6833. ot,
  6834. st,
  6835. De,
  6836. Be,
  6837. Ut,
  6838. oe,
  6839. zr,
  6840. ne,
  6841. Or,
  6842. _n,
  6843. Vo,
  6844. In,
  6845. Dl,
  6846. Qt,
  6847. // formula SUBTOTAL
  6848. Zt,
  6849. Xt,
  6850. qt
  6851. ].forEach((r) => {
  6852. var i;
  6853. this._commandService.registerCommand(r), (i = this._dataSyncPrimaryController) == null || i.registerSyncingMutations(r);
  6854. }), ((s = this._configService.getConfig(Kr)) != null ? s : !1) || [
  6855. po,
  6856. Co,
  6857. So,
  6858. xs,
  6859. Pt,
  6860. Tt,
  6861. Oo,
  6862. $o,
  6863. gu,
  6864. mu,
  6865. pr,
  6866. gt,
  6867. sn,
  6868. Bn,
  6869. hu,
  6870. du,
  6871. fr,
  6872. mt,
  6873. fu,
  6874. jn,
  6875. pt,
  6876. Fn,
  6877. vr,
  6878. zn,
  6879. Mr,
  6880. Gn,
  6881. ko,
  6882. uo,
  6883. Iu,
  6884. tl,
  6885. Qu,
  6886. el,
  6887. Ou,
  6888. Nu,
  6889. rn,
  6890. Tu,
  6891. ku,
  6892. yr,
  6893. Mn,
  6894. $u,
  6895. Lt,
  6896. Bu,
  6897. ut,
  6898. Fu,
  6899. ol,
  6900. on,
  6901. Wo,
  6902. kr,
  6903. Ku,
  6904. Ht,
  6905. br,
  6906. Tr,
  6907. Kn,
  6908. Jn,
  6909. fe,
  6910. al,
  6911. fn,
  6912. Zu,
  6913. rl,
  6914. sl,
  6915. nl,
  6916. Dr,
  6917. Ar,
  6918. an,
  6919. hl,
  6920. lt,
  6921. Do,
  6922. Wr,
  6923. Rn,
  6924. Br,
  6925. nt,
  6926. Lo,
  6927. Oe,
  6928. tt,
  6929. // SetWorksheetColIsAutoWidthCommand,
  6930. re,
  6931. Wl,
  6932. au,
  6933. Ir,
  6934. Ur,
  6935. Fr,
  6936. Nl,
  6937. Ft,
  6938. ju,
  6939. Vt,
  6940. // permissions range protection
  6941. Il,
  6942. ct,
  6943. Ct,
  6944. St,
  6945. Ao,
  6946. Xi,
  6947. Gu,
  6948. su,
  6949. qi,
  6950. ru,
  6951. vl,
  6952. Ne,
  6953. ze,
  6954. he,
  6955. kl,
  6956. Bt,
  6957. dl,
  6958. Tl,
  6959. // range theme
  6960. Kt,
  6961. zt,
  6962. Uo,
  6963. Yt,
  6964. Ol,
  6965. wu,
  6966. ba,
  6967. iu
  6968. ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r))), this._configService.setConfig(Ll, Vl);
  6969. }
  6970. };
  6971. yn = Fl([
  6972. to(0, E),
  6973. to(1, Us),
  6974. to(2, Si(Fi))
  6975. ], yn);
  6976. var jl = Object.defineProperty, Gl = Object.getOwnPropertyDescriptor, zl = (n, e, t, o) => {
  6977. for (var s = o > 1 ? void 0 : o ? Gl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  6978. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  6979. return o && s && jl(e, t, s), s;
  6980. }, es = (n, e) => (t, o) => e(t, o, n);
  6981. let En = class extends ae {
  6982. constructor(n, e) {
  6983. super(), this._univerInstanceService = n, this._commandService = e, this._initialize();
  6984. }
  6985. _initialize() {
  6986. this.disposeWithMe(
  6987. this._commandService.onCommandExecuted((n) => {
  6988. if (n.id !== Di.id)
  6989. return;
  6990. const e = n.params, { unitData: t } = e, o = Object.keys(t), s = [];
  6991. for (let i = 0; i < o.length; i++) {
  6992. const a = o[i], u = t[a];
  6993. if (u == null)
  6994. continue;
  6995. const l = Object.keys(u);
  6996. for (let c = 0; c < l.length; c++) {
  6997. const d = l[c], h = u[d];
  6998. if (h == null)
  6999. continue;
  7000. const m = this._getMergedCellData(a, d, h), g = {
  7001. subUnitId: d,
  7002. unitId: a,
  7003. cellValue: m
  7004. };
  7005. s.push({
  7006. id: Q.id,
  7007. params: g
  7008. });
  7009. }
  7010. }
  7011. return s.every(
  7012. (i) => this._commandService.executeCommand(i.id, i.params, {
  7013. onlyLocal: !0
  7014. })
  7015. );
  7016. })
  7017. );
  7018. }
  7019. /**
  7020. * Priority that mainly deals with number format in unitData
  7021. * @param unitId
  7022. * @param sheetId
  7023. * @param cellData
  7024. * @returns
  7025. */
  7026. _getMergedCellData(n, e, t) {
  7027. 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 G(t);
  7028. return a.forValue((u, l, c) => {
  7029. const d = i == null ? void 0 : i.getValue(u, l), h = Ai(d, c, s);
  7030. a.setValue(u, l, h);
  7031. }), a.getMatrix();
  7032. }
  7033. };
  7034. En = zl([
  7035. es(0, L(M)),
  7036. es(1, E)
  7037. ], En);
  7038. const Kl = "sheets.config", ts = {};
  7039. var Jl = Object.defineProperty, Yl = Object.getOwnPropertyDescriptor, Xl = (n, e, t, o) => {
  7040. for (var s = o > 1 ? void 0 : o ? Yl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  7041. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  7042. return o && s && Jl(e, t, s), s;
  7043. }, ns = (n, e) => (t, o) => e(t, o, n);
  7044. const ql = "SHEET_DEFINED_NAME_PLUGIN", ch = "AllDefaultWorkbook";
  7045. let Un = class extends ae {
  7046. constructor(n, e) {
  7047. super(), this._definedNamesService = n, this._resourceManagerService = e, this._initialize();
  7048. }
  7049. _initialize() {
  7050. this._initSnapshot();
  7051. }
  7052. _initSnapshot() {
  7053. const n = (t) => {
  7054. const o = this._definedNamesService.getDefinedNameMap(t);
  7055. return o ? JSON.stringify(o) : "";
  7056. }, e = (t) => {
  7057. if (!t)
  7058. return {};
  7059. try {
  7060. return JSON.parse(t);
  7061. } catch {
  7062. return {};
  7063. }
  7064. };
  7065. this.disposeWithMe(
  7066. this._resourceManagerService.registerPluginResource({
  7067. pluginName: ql,
  7068. businesses: [B.UNIVER_SHEET],
  7069. toJson: (t) => n(t),
  7070. parseJson: (t) => e(t),
  7071. onUnLoad: (t) => {
  7072. this._definedNamesService.removeUnitDefinedName(t);
  7073. },
  7074. onLoad: (t, o) => {
  7075. this._definedNamesService.registerDefinedNames(t, o);
  7076. }
  7077. })
  7078. );
  7079. }
  7080. };
  7081. Un = Xl([
  7082. ns(0, Ps),
  7083. ns(1, nn)
  7084. ], Un);
  7085. const $ = {
  7086. MoveRangeCommandId: $s,
  7087. InsertRowCommandId: gr,
  7088. InsertColCommandId: Rr,
  7089. RemoveColCommandId: To,
  7090. RemoveRowCommandId: Po,
  7091. DeleteRangeMoveLeftCommandId: dr,
  7092. DeleteRangeMoveUpCommandId: hr,
  7093. InsertRangeMoveDownCommandId: cu,
  7094. InsertRangeMoveRightCommandId: Eo,
  7095. MoveColsCommandId: Sr,
  7096. MoveRowsCommandId: Cr,
  7097. ReorderRangeCommandId: _r
  7098. };
  7099. var q = /* @__PURE__ */ ((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 || {});
  7100. const cn = Number.MAX_SAFE_INTEGER, Ve = (n) => {
  7101. 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);
  7102. return (e.rangeType === H.COLUMN || t) && (e.startRow = 0, e.endRow = cn), (e.rangeType === H.ROW || o) && (e.startColumn = 0, e.endColumn = cn), e.rangeType === H.ALL && (e.startColumn = 0, e.endColumn = cn, e.startRow = 0, e.endRow = cn), e;
  7103. }, _e = (n) => {
  7104. let e = n.rangeType;
  7105. return n.rangeType === H.COLUMN ? e = H.ROW : n.rangeType === H.ROW && (e = H.COLUMN), {
  7106. startRow: n.startColumn,
  7107. endRow: n.endColumn,
  7108. startColumn: n.startRow,
  7109. endColumn: n.endRow,
  7110. rangeType: e
  7111. };
  7112. }, Pn = (n, e, t) => {
  7113. const o = { ...t }, s = { ...e }, r = (f, p) => {
  7114. const C = Math.max(f.start, p.start), S = Math.min(f.end, p.end);
  7115. return S < C ? null : { start: C, end: S };
  7116. }, i = (f) => f.end - f.start + 1, a = (f, p) => ({
  7117. start: f.start - p.start,
  7118. end: f.start - p.start + f.end - f.start
  7119. }), u = (f, p) => ({
  7120. start: p.start + f.start,
  7121. end: p.start + f.start + f.end - f.start
  7122. }), l = e.start > n.start;
  7123. if (l) {
  7124. const f = Math.min(n.end, e.start) - n.start + 1;
  7125. s.start -= f, s.end -= f;
  7126. }
  7127. const c = i(n), d = c, h = r(n, o), m = h && i(h) >= i(o);
  7128. if (n.end < o.start)
  7129. o.start -= c, o.end -= c;
  7130. else if (h) {
  7131. const f = i(h);
  7132. if (m) {
  7133. const p = a(o, n), C = u(p, s);
  7134. o.start = C.start, o.end = C.end;
  7135. } 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;
  7136. }
  7137. const g = r(s, o);
  7138. return m || (s.start <= o.start ? (o.start += d, o.end += d) : g && (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))), {
  7139. step: o.start - t.start,
  7140. length: i(o) - i(t)
  7141. };
  7142. }, Jr = (n, e) => {
  7143. const { fromRange: t, toRange: o } = n.params || {};
  7144. if (!o || !t)
  7145. return [];
  7146. const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn(
  7147. { start: s.startRow, end: s.endRow },
  7148. { start: r.startRow, end: r.endRow },
  7149. { start: i.startRow, end: i.endRow }
  7150. );
  7151. return a === null ? [
  7152. {
  7153. type: q.Delete
  7154. }
  7155. ] : [
  7156. {
  7157. type: q.VerticalMove,
  7158. step: a.step || 0,
  7159. length: a.length || 0
  7160. }
  7161. ];
  7162. }, Zl = (n, e) => {
  7163. const { fromRange: t, toRange: o } = n.params || {};
  7164. if (!t || !o)
  7165. return [e];
  7166. const s = t.startRow, r = t.endRow - t.startRow + 1, i = o.startRow, a = new G();
  7167. return K.foreach(e, (l, c) => {
  7168. a.setValue(l, c, 1);
  7169. }), a.moveRows(s, r, i), Je(a, (l) => l === 1);
  7170. }, Ql = (n, e) => {
  7171. const { range: t, order: o } = n.params || {};
  7172. if (!t || !o)
  7173. return [e];
  7174. const s = new G();
  7175. K.foreach(e, (a, u) => {
  7176. s.setValue(a, u, 1);
  7177. });
  7178. const r = new G();
  7179. return K.foreach(t, (a, u) => {
  7180. var l;
  7181. if (o.hasOwnProperty(a)) {
  7182. const c = o[a], d = (l = s.getValue(c, u)) != null ? l : 0;
  7183. r.setValue(a, u, d);
  7184. }
  7185. }), r.forValue((a, u, l) => {
  7186. s.setValue(a, u, l);
  7187. }), Je(s, (a) => a === 1);
  7188. }, Yr = (n, e) => {
  7189. const { fromRange: t, toRange: o } = n.params || {};
  7190. if (!o || !t)
  7191. return [];
  7192. const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn(
  7193. { start: s.startColumn, end: s.endColumn },
  7194. { start: r.startColumn, end: r.endColumn },
  7195. { start: i.startColumn, end: i.endColumn }
  7196. );
  7197. return a === null ? [
  7198. {
  7199. type: q.Delete
  7200. }
  7201. ] : [
  7202. {
  7203. type: q.HorizontalMove,
  7204. step: a.step || 0,
  7205. length: a.length || 0
  7206. }
  7207. ];
  7208. }, ec = (n, e) => {
  7209. const { fromRange: t, toRange: o } = n.params || {};
  7210. if (!t || !o)
  7211. return [e];
  7212. const s = t.startColumn, r = t.endColumn - t.startColumn + 1, i = o.startColumn, a = new G();
  7213. return K.foreach(e, (u, l) => {
  7214. a.setValue(u, l, 1);
  7215. }), a.moveColumns(s, r, i), Je(a, (u) => u === 1);
  7216. }, tc = (n, e) => {
  7217. var r, i;
  7218. const t = (r = n.params) == null ? void 0 : r.toRange, o = (i = n.params) == null ? void 0 : i.fromRange;
  7219. if (!t || !o)
  7220. return [];
  7221. const s = [];
  7222. if (k.contains(t, e) && s.push({
  7223. type: q.Delete
  7224. }), k.contains(o, e)) {
  7225. s.push({
  7226. type: q.Delete
  7227. });
  7228. const a = k.getRelativeRange(e, o), u = k.getPositionRange(a, t);
  7229. return [
  7230. {
  7231. type: q.Set,
  7232. range: u
  7233. }
  7234. ];
  7235. }
  7236. return s;
  7237. }, nc = (n, e) => {
  7238. var d, h;
  7239. const t = (d = n.params) == null ? void 0 : d.toRange, o = (h = n.params) == null ? void 0 : h.fromRange;
  7240. if (!t || !o)
  7241. return [e];
  7242. if (!k.intersects(o, e) && !k.intersects(t, e))
  7243. return [e];
  7244. if (k.contains(o, e)) {
  7245. const m = k.getRelativeRange(e, o);
  7246. return [k.getPositionRange(m, t)];
  7247. }
  7248. const s = new G();
  7249. K.foreach(e, (m, g) => {
  7250. s.setValue(m, g, 1);
  7251. });
  7252. const r = new G(), i = k.getIntersects(o, e);
  7253. i && K.foreach(i, (m, g) => {
  7254. s.getValue(m, g) && (s.setValue(m, g, void 0), r.setValue(m, g, 1));
  7255. });
  7256. const a = t.startColumn - o.startColumn, u = t.startRow - o.startRow, l = {
  7257. startColumn: t.startColumn - a,
  7258. endColumn: t.endColumn - a,
  7259. startRow: t.startRow - u,
  7260. endRow: t.endRow - u
  7261. };
  7262. return K.foreach(l, (m, g) => {
  7263. var C;
  7264. const f = m + u, p = g + a;
  7265. s.setValue(f, p, (C = r.getValue(m, g)) != null ? C : 0);
  7266. }), Je(s, (m) => m === 1);
  7267. }, It = (n, e) => {
  7268. const t = Ve(n), o = Ve(e), s = (i) => i.endColumn - i.startColumn + 1, r = (i) => i.endRow - i.startRow + 1;
  7269. if (t.startRow <= o.startRow && t.endRow >= o.endRow) {
  7270. if (
  7271. // 2
  7272. o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6
  7273. o.startColumn < t.startColumn && o.endColumn >= t.endColumn
  7274. ) {
  7275. const i = k.getIntersects(o, t);
  7276. if (i)
  7277. return { step: 0, length: -s(i) };
  7278. }
  7279. if (o.startColumn >= t.startColumn && o.endColumn <= t.endColumn && r(t) >= r(o))
  7280. return null;
  7281. if (o.startColumn >= t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn) {
  7282. const i = k.getIntersects(o, t);
  7283. if (i) {
  7284. const a = -s(i);
  7285. return { step: -(s(t) - s(i)), length: a };
  7286. }
  7287. }
  7288. if (o.startColumn > t.endColumn)
  7289. return { step: -s(t), length: 0 };
  7290. }
  7291. return { step: 0, length: 0 };
  7292. }, Xr = (n, e) => {
  7293. var r;
  7294. const t = (r = n.params) == null ? void 0 : r.range;
  7295. if (!t)
  7296. return [];
  7297. const o = [], s = It(t, e);
  7298. if (!s)
  7299. o.push({ type: q.Delete });
  7300. else {
  7301. const { step: i, length: a } = s;
  7302. o.push({
  7303. type: q.HorizontalMove,
  7304. step: i,
  7305. length: a
  7306. });
  7307. }
  7308. return o;
  7309. }, oc = (n, e) => {
  7310. var r;
  7311. const t = (r = n.params) == null ? void 0 : r.range;
  7312. if (!t)
  7313. return [];
  7314. const o = [], s = It(_e(t), _e(e));
  7315. if (!s)
  7316. o.push({ type: q.Delete });
  7317. else {
  7318. const { step: i, length: a } = s;
  7319. o.push({
  7320. type: q.VerticalMove,
  7321. step: i,
  7322. length: a
  7323. });
  7324. }
  7325. return o;
  7326. }, sc = (n, e) => {
  7327. const { range: t, order: o } = n.params || {};
  7328. if (!t || !o)
  7329. return [];
  7330. if (k.contains(t, e) && e.endRow === e.startRow) {
  7331. const s = [], r = e.startRow;
  7332. for (const i in o)
  7333. if (o[i] === r) {
  7334. const a = Number(i);
  7335. return s.push({
  7336. type: q.VerticalMove,
  7337. step: a - r,
  7338. length: 0
  7339. }), s;
  7340. }
  7341. return [];
  7342. }
  7343. return [];
  7344. }, vt = (n, e) => {
  7345. const t = Ve(n), o = Ve(e), s = (r) => r.endColumn - r.startColumn + 1;
  7346. if (t.startRow <= o.startRow && t.endRow >= o.endRow) {
  7347. if (
  7348. // 2
  7349. o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6
  7350. o.startColumn < t.startColumn && o.endColumn >= t.endColumn
  7351. )
  7352. return { step: 0, length: s(t) };
  7353. if (
  7354. // 3
  7355. o.startColumn >= t.startColumn && o.endColumn <= t.endColumn || // 4
  7356. o.startColumn > t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn || //5
  7357. o.startColumn >= t.endColumn
  7358. )
  7359. return { step: s(t), length: 0 };
  7360. }
  7361. return { step: 0, length: 0 };
  7362. };
  7363. function rc(n, e, t) {
  7364. const o = [];
  7365. if (k.contains(e, t) && o.push({
  7366. type: q.Delete
  7367. }), k.contains(n, t)) {
  7368. o.push({
  7369. type: q.Delete
  7370. });
  7371. const s = k.getRelativeRange(t, n), r = k.getPositionRange(s, e);
  7372. return [
  7373. {
  7374. type: q.Set,
  7375. range: r
  7376. }
  7377. ];
  7378. }
  7379. return o;
  7380. }
  7381. const ic = (n, e) => {
  7382. var a;
  7383. const t = (a = n.params) == null ? void 0 : a.range;
  7384. if (!t)
  7385. return [];
  7386. const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s;
  7387. return o.push({
  7388. type: q.VerticalMove,
  7389. step: r,
  7390. length: i
  7391. }), o;
  7392. }, ac = (n, e) => {
  7393. var a;
  7394. const t = (a = n.params) == null ? void 0 : a.range;
  7395. if (!t)
  7396. return [];
  7397. const o = [], s = vt(t, e), { step: r, length: i } = s;
  7398. return o.push({
  7399. type: q.HorizontalMove,
  7400. step: r,
  7401. length: i
  7402. }), o;
  7403. }, uc = (n, e) => {
  7404. var a;
  7405. const t = (a = n.params) == null ? void 0 : a.range;
  7406. if (!t)
  7407. return [];
  7408. const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s;
  7409. return o.push({
  7410. type: q.VerticalMove,
  7411. step: r,
  7412. length: i
  7413. }), o;
  7414. }, lc = (n, e) => {
  7415. var u;
  7416. const t = (u = n.params) == null ? void 0 : u.range;
  7417. if (!t)
  7418. return [e];
  7419. const o = t.endRow - t.startRow + 1, s = {
  7420. ...t,
  7421. startRow: t.startRow,
  7422. endRow: Number.POSITIVE_INFINITY
  7423. }, r = k.subtract(e, s), i = k.getIntersects(s, e);
  7424. if (!i)
  7425. return [e];
  7426. const a = new G();
  7427. return r.forEach((l) => {
  7428. K.foreach(l, (c, d) => {
  7429. a.setValue(c, d, 1);
  7430. });
  7431. }), i && K.foreach(i, (l, c) => {
  7432. a.setValue(l + o, c, 1);
  7433. }), Je(a, (l) => l === 1);
  7434. }, cc = (n, e) => {
  7435. var a;
  7436. const t = (a = n.params) == null ? void 0 : a.range;
  7437. if (!t)
  7438. return [];
  7439. const o = [], s = vt(t, e), { step: r, length: i } = s;
  7440. return o.push({
  7441. type: q.HorizontalMove,
  7442. step: r,
  7443. length: i
  7444. }), o;
  7445. }, dc = (n, e) => {
  7446. var u;
  7447. const t = (u = n.params) == null ? void 0 : u.range;
  7448. if (!t)
  7449. return [e];
  7450. const o = t.endColumn - t.startColumn + 1, s = {
  7451. ...t,
  7452. startColumn: t.startColumn,
  7453. endColumn: Number.POSITIVE_INFINITY
  7454. }, r = k.subtract(e, s), i = k.getIntersects(s, e);
  7455. if (!i)
  7456. return [e];
  7457. const a = new G();
  7458. return r.forEach((l) => {
  7459. K.foreach(l, (c, d) => {
  7460. a.setValue(c, d, 1);
  7461. });
  7462. }), i && K.foreach(i, (l, c) => {
  7463. a.setValue(l, c + o, 1);
  7464. }), Je(a, (l) => l === 1);
  7465. }, hc = (n, e) => {
  7466. var r;
  7467. const t = (r = n.params) == null ? void 0 : r.range;
  7468. if (!t)
  7469. return [];
  7470. const o = [], s = It(t, e);
  7471. if (!s)
  7472. o.push({ type: q.Delete });
  7473. else {
  7474. const { step: i, length: a } = s;
  7475. o.push({
  7476. type: q.HorizontalMove,
  7477. step: i,
  7478. length: a
  7479. });
  7480. }
  7481. return o;
  7482. }, mc = (n, e) => {
  7483. var l;
  7484. const t = (l = n.params) == null ? void 0 : l.range;
  7485. if (!t)
  7486. return [e];
  7487. const o = {
  7488. startRow: t.startRow,
  7489. endRow: t.endRow,
  7490. startColumn: t.startColumn,
  7491. endColumn: Number.POSITIVE_INFINITY
  7492. }, s = t.endColumn - t.startColumn + 1, r = k.getIntersects(t, e), i = k.subtract(e, o), a = k.getIntersects(o, e);
  7493. if (!r && !a)
  7494. return [e];
  7495. const u = new G();
  7496. return a && K.foreach(a, (c, d) => {
  7497. u.setValue(c, d - s, 1);
  7498. }), r && K.foreach(r, (c, d) => {
  7499. u.setValue(c, d - s, 0);
  7500. }), i.forEach((c) => {
  7501. K.foreach(c, (d, h) => {
  7502. u.setValue(d, h, 1);
  7503. });
  7504. }), Je(u, (c) => c === 1);
  7505. }, gc = (n, e) => {
  7506. var r;
  7507. const t = (r = n.params) == null ? void 0 : r.range;
  7508. if (!t)
  7509. return [];
  7510. const o = [], s = It(_e(t), _e(e));
  7511. if (!s)
  7512. o.push({ type: q.Delete });
  7513. else {
  7514. const { step: i, length: a } = s;
  7515. o.push({
  7516. type: q.VerticalMove,
  7517. step: i,
  7518. length: a
  7519. });
  7520. }
  7521. return o;
  7522. }, fc = (n, e) => {
  7523. var l;
  7524. const t = (l = n.params) == null ? void 0 : l.range;
  7525. if (!t)
  7526. return [e];
  7527. const o = {
  7528. ...t,
  7529. startRow: t.startRow,
  7530. endRow: Number.POSITIVE_INFINITY
  7531. }, s = t.endRow - t.startRow + 1, r = k.getIntersects(t, e), i = k.subtract(e, o), a = k.getIntersects(o, e);
  7532. if (!r && !a)
  7533. return [e];
  7534. const u = new G();
  7535. return a && K.foreach(a, (c, d) => {
  7536. u.setValue(c - s, d, 1);
  7537. }), r && K.foreach(r, (c, d) => {
  7538. u.setValue(c - s, d, 0);
  7539. }), i.forEach((c) => {
  7540. K.foreach(c, (d, h) => {
  7541. u.setValue(d, h, 1);
  7542. });
  7543. }), Je(u, (c) => c === 1);
  7544. }, Rc = (n, e) => {
  7545. var s;
  7546. const t = (s = n.ranges) != null ? s : [n.range], o = new G();
  7547. return K.foreach(e, (r, i) => {
  7548. o.setValue(r, i, 1);
  7549. }), t.forEach((r) => {
  7550. const i = r.startRow, u = r.endRow - i + 1;
  7551. o.removeRows(i, u);
  7552. }), Je(o, (r) => r === 1);
  7553. }, pc = (n, e) => {
  7554. const t = n.params, o = t.range.startRow, s = t.range.endRow - t.range.startRow + 1, r = t.direction;
  7555. return r === pe.UP && o === e.startRow || r === pe.DOWN && o - 1 === e.endRow ? [
  7556. {
  7557. startRow: e.startRow,
  7558. endRow: e.endRow + s,
  7559. startColumn: e.startColumn,
  7560. endColumn: e.endColumn
  7561. }
  7562. ] : e.startRow >= o ? [{
  7563. startRow: e.startRow + s,
  7564. endRow: e.endRow + s,
  7565. startColumn: e.startColumn,
  7566. endColumn: e.endColumn
  7567. }] : e.endRow <= o ? [e] : [{
  7568. startRow: e.startRow,
  7569. endRow: e.endRow + s,
  7570. startColumn: e.startColumn,
  7571. endColumn: e.endColumn
  7572. }];
  7573. }, Cc = (n, e) => {
  7574. const t = n.params, o = t.range.startColumn, s = t.range.endColumn - t.range.startColumn + 1, r = t.direction;
  7575. return r === pe.LEFT && o === e.startColumn || r === pe.RIGHT && o - 1 === e.endColumn ? [
  7576. {
  7577. startRow: e.startRow,
  7578. endRow: e.endRow,
  7579. startColumn: e.startColumn,
  7580. endColumn: e.endColumn + s
  7581. }
  7582. ] : e.startColumn >= o ? [{
  7583. startRow: e.startRow,
  7584. endRow: e.endRow,
  7585. startColumn: e.startColumn + s,
  7586. endColumn: e.endColumn + s
  7587. }] : e.endColumn <= o ? [e] : [{
  7588. startRow: e.startRow,
  7589. endRow: e.endRow,
  7590. startColumn: e.startColumn,
  7591. endColumn: e.endColumn + s
  7592. }];
  7593. }, Mt = (n, e) => {
  7594. let t = { ...e };
  7595. return n.forEach((o) => {
  7596. switch (o.type) {
  7597. case q.Delete: {
  7598. t = null;
  7599. break;
  7600. }
  7601. case q.HorizontalMove: {
  7602. if (!t)
  7603. return;
  7604. t.startColumn += o.step, t.endColumn += o.step + (o.length || 0);
  7605. break;
  7606. }
  7607. case q.VerticalMove: {
  7608. if (!t)
  7609. return;
  7610. t.startRow += o.step, t.endRow += o.step + (o.length || 0);
  7611. break;
  7612. }
  7613. case q.Set: {
  7614. t = o.range;
  7615. break;
  7616. }
  7617. }
  7618. }), t && (t.endColumn < t.startColumn || t.endRow < t.startRow) ? null : t;
  7619. }, os = (n, e) => {
  7620. let t = [];
  7621. switch (e.id) {
  7622. case $.DeleteRangeMoveLeftCommandId: {
  7623. t = hc(e, n);
  7624. break;
  7625. }
  7626. case $.DeleteRangeMoveUpCommandId: {
  7627. t = gc(e, n);
  7628. break;
  7629. }
  7630. case $.InsertColCommandId: {
  7631. t = ac(e, n);
  7632. break;
  7633. }
  7634. case $.InsertRangeMoveDownCommandId: {
  7635. t = uc(e, n);
  7636. break;
  7637. }
  7638. case $.InsertRangeMoveRightCommandId: {
  7639. t = cc(e, n);
  7640. break;
  7641. }
  7642. case $.InsertRowCommandId: {
  7643. t = ic(e, n);
  7644. break;
  7645. }
  7646. case $.MoveColsCommandId: {
  7647. t = Yr(e, n);
  7648. break;
  7649. }
  7650. case $.MoveRangeCommandId: {
  7651. t = tc(e, n);
  7652. break;
  7653. }
  7654. case $.MoveRowsCommandId: {
  7655. t = Jr(e, n);
  7656. break;
  7657. }
  7658. case $.RemoveColCommandId: {
  7659. t = Xr(e, n);
  7660. break;
  7661. }
  7662. case $.RemoveRowCommandId: {
  7663. t = oc(e, n);
  7664. break;
  7665. }
  7666. case $.ReorderRangeCommandId: {
  7667. t = sc(e, n);
  7668. break;
  7669. }
  7670. }
  7671. return Mt(t, n);
  7672. }, dh = (n, e, t) => [Pt.id, Tt.id].includes(e.id) || qr(e, t).some((r) => k.intersects(r, n)) ? os(n, e) : n, ss = (n, e) => {
  7673. let t = [];
  7674. switch (e.id) {
  7675. case $.DeleteRangeMoveLeftCommandId:
  7676. return mc(e, n);
  7677. case $.DeleteRangeMoveUpCommandId:
  7678. return fc(e, n);
  7679. case $.InsertRangeMoveDownCommandId:
  7680. return lc(e, n);
  7681. case $.InsertRangeMoveRightCommandId:
  7682. return dc(e, n);
  7683. case $.InsertColCommandId:
  7684. return Cc(e, n);
  7685. case $.InsertRowCommandId:
  7686. return pc(e, n);
  7687. case $.MoveColsCommandId:
  7688. return ec(e, n);
  7689. case $.MoveRangeCommandId:
  7690. return nc(e, n);
  7691. case $.MoveRowsCommandId:
  7692. return Zl(e, n);
  7693. case $.ReorderRangeCommandId:
  7694. return Ql(e, n);
  7695. case $.RemoveColCommandId: {
  7696. t = Xr(e, n);
  7697. break;
  7698. }
  7699. case $.RemoveRowCommandId:
  7700. return Rc(e.params, n);
  7701. }
  7702. const o = Mt(t, n);
  7703. return o ? [o] : [];
  7704. }, hh = (n, e, t) => [Pt.id, Tt.id, sn.id, Eo].includes(e.id) || qr(e, t).some((r) => k.intersects(r, n)) ? ss(n, e) : n;
  7705. function Sc(n, e) {
  7706. const { id: t, params: o } = e;
  7707. let s = {
  7708. length: 0,
  7709. step: 0,
  7710. type: q.Unknown
  7711. };
  7712. switch (t) {
  7713. case Ut.id:
  7714. s.type = q.Delete;
  7715. break;
  7716. case ot.id:
  7717. s = Pn(
  7718. { start: o.sourceRange.startRow, end: o.sourceRange.endRow },
  7719. { start: o.targetRange.startRow, end: o.targetRange.endRow },
  7720. { start: n.startRow, end: n.endRow }
  7721. ), s.type = q.VerticalMove;
  7722. break;
  7723. case st.id:
  7724. s = Pn(
  7725. { start: o.sourceRange.startColumn, end: o.sourceRange.endColumn },
  7726. { start: o.targetRange.startColumn, end: o.targetRange.endColumn },
  7727. { start: n.startColumn, end: n.endColumn }
  7728. ), s.type = q.HorizontalMove;
  7729. break;
  7730. case De.id:
  7731. s = It(o.range, n), s ? s.type = q.HorizontalMove : s = { step: 0, length: 0, type: q.Delete };
  7732. break;
  7733. case Be.id:
  7734. s = It(_e(o.range), _e(n)), s ? s.type = q.VerticalMove : s = { step: 0, length: 0, type: q.Delete };
  7735. break;
  7736. case qe.id:
  7737. s = vt(_e(o.range), _e(n)), s.type = q.VerticalMove;
  7738. break;
  7739. case je.id:
  7740. s = vt(o.range, n), s.type = q.HorizontalMove;
  7741. break;
  7742. case dt.id:
  7743. {
  7744. const r = o.fromRange || new G(o.from).getRange(), i = o.toRange || new G(o.to).getRange();
  7745. s = rc(
  7746. r,
  7747. i,
  7748. n
  7749. );
  7750. }
  7751. break;
  7752. }
  7753. return s ? Array.isArray(s) ? Mt(s, n) : Mt([s], n) : n;
  7754. }
  7755. function qr(n, e) {
  7756. var o, s, r, i, a, u;
  7757. const { selectionManagerService: t } = e;
  7758. switch (n.id) {
  7759. case $.MoveColsCommandId: {
  7760. const l = n.params;
  7761. return [
  7762. l.fromRange,
  7763. {
  7764. ...l.toRange,
  7765. startColumn: l.toRange.startColumn - 0.5,
  7766. endColumn: l.toRange.endColumn - 0.5
  7767. }
  7768. ];
  7769. }
  7770. case $.MoveRowsCommandId: {
  7771. const l = n.params;
  7772. return [
  7773. l.fromRange,
  7774. {
  7775. ...l.toRange,
  7776. startRow: l.toRange.startRow - 0.5,
  7777. endRow: l.toRange.startRow - 0.5
  7778. }
  7779. ];
  7780. }
  7781. case $.MoveRangeCommandId: {
  7782. const l = n;
  7783. return [l.params.fromRange, l.params.toRange];
  7784. }
  7785. case $.InsertRowCommandId: {
  7786. const c = n.params.range;
  7787. return [
  7788. {
  7789. ...c,
  7790. startRow: c.startRow - 0.5,
  7791. endRow: c.endRow - 0.5
  7792. }
  7793. ];
  7794. }
  7795. case $.InsertColCommandId: {
  7796. const c = n.params.range;
  7797. return [
  7798. {
  7799. ...c,
  7800. startColumn: c.startColumn - 0.5,
  7801. endColumn: c.endColumn - 0.5
  7802. }
  7803. ];
  7804. }
  7805. case $.RemoveRowCommandId:
  7806. return [n.params.range];
  7807. case $.RemoveColCommandId:
  7808. return [n.params.range];
  7809. case $.DeleteRangeMoveUpCommandId:
  7810. case $.InsertRangeMoveDownCommandId: {
  7811. 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]);
  7812. return c ? [c] : [];
  7813. }
  7814. case $.DeleteRangeMoveLeftCommandId:
  7815. case $.InsertRangeMoveRightCommandId: {
  7816. 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]);
  7817. return c ? [c] : [];
  7818. }
  7819. case $.ReorderRangeCommandId: {
  7820. const l = n, { range: c, order: d } = l.params, h = [];
  7821. for (let m = c.startRow; m <= c.endRow; m++)
  7822. m in d && h.push({
  7823. startRow: m,
  7824. endRow: m,
  7825. startColumn: c.startColumn,
  7826. endColumn: c.endColumn
  7827. });
  7828. return h;
  7829. }
  7830. }
  7831. }
  7832. function wc(n) {
  7833. switch (n.id) {
  7834. case st.id: {
  7835. const e = n.params;
  7836. return [
  7837. e.sourceRange,
  7838. {
  7839. ...e.targetRange,
  7840. startColumn: e.targetRange.startColumn - 0.5,
  7841. endColumn: e.targetRange.startColumn - 0.5
  7842. }
  7843. ];
  7844. }
  7845. case ot.id: {
  7846. const e = n.params;
  7847. return [
  7848. e.sourceRange,
  7849. {
  7850. ...e.targetRange,
  7851. startRow: e.targetRange.startRow - 0.5,
  7852. endRow: e.targetRange.startRow - 0.5
  7853. }
  7854. ];
  7855. }
  7856. case dt.id: {
  7857. const e = n.params;
  7858. return [new G(e.from.value).getRange(), new G(e.to.value).getRange()];
  7859. }
  7860. case je.id: {
  7861. const t = n.params.range;
  7862. return [
  7863. {
  7864. ...t,
  7865. startColumn: t.startColumn - 0.5,
  7866. endColumn: t.startColumn - 0.5
  7867. }
  7868. ];
  7869. }
  7870. case qe.id: {
  7871. const t = n.params.range;
  7872. return [
  7873. {
  7874. ...t,
  7875. startRow: t.startRow - 0.5,
  7876. endRow: t.startRow - 0.5
  7877. }
  7878. ];
  7879. }
  7880. case De.id:
  7881. return [n.params.range];
  7882. case Be.id:
  7883. return [n.params.range];
  7884. }
  7885. }
  7886. function mh(n, e) {
  7887. var s, r, i, a, u, l;
  7888. const t = n.get(M), o = n.get(F);
  7889. switch (e.id) {
  7890. case $.MoveColsCommandId: {
  7891. const c = e.params, d = N(t, {
  7892. unitId: c.unitId,
  7893. subUnitId: c.subUnitId
  7894. });
  7895. return {
  7896. unitId: d.unitId,
  7897. subUnitId: d.subUnitId,
  7898. ranges: [
  7899. c.fromRange,
  7900. {
  7901. ...c.toRange,
  7902. startColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.fromRange.endColumn + 1 : c.toRange.startColumn,
  7903. endColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.toRange.endColumn - 1 : c.fromRange.startColumn - 1
  7904. }
  7905. ]
  7906. };
  7907. }
  7908. case $.MoveRowsCommandId: {
  7909. const c = e.params, d = N(t, {
  7910. unitId: c.unitId,
  7911. subUnitId: c.subUnitId
  7912. });
  7913. return {
  7914. unitId: d.unitId,
  7915. subUnitId: d.subUnitId,
  7916. ranges: [
  7917. c.fromRange,
  7918. {
  7919. ...c.toRange,
  7920. startRow: c.fromRange.startRow < c.toRange.startRow ? c.fromRange.endRow + 1 : c.toRange.startRow,
  7921. endRow: c.fromRange.startRow < c.toRange.startRow ? c.toRange.endRow - 1 : c.fromRange.startRow - 1
  7922. }
  7923. ]
  7924. };
  7925. }
  7926. case $.MoveRangeCommandId: {
  7927. const c = e.params, d = N(t);
  7928. return {
  7929. unitId: d.unitId,
  7930. subUnitId: d.subUnitId,
  7931. ranges: [c.fromRange, c.toRange]
  7932. };
  7933. }
  7934. case $.InsertRowCommandId: {
  7935. const c = e.params, d = c.range;
  7936. return {
  7937. unitId: c.unitId,
  7938. subUnitId: c.subUnitId,
  7939. ranges: [
  7940. ...d.startRow > 0 ? [{
  7941. ...d,
  7942. startRow: d.startRow - 1,
  7943. endRow: d.endRow - 1
  7944. }] : [],
  7945. {
  7946. ...d,
  7947. startRow: d.startRow,
  7948. endRow: Number.MAX_SAFE_INTEGER
  7949. }
  7950. ]
  7951. };
  7952. }
  7953. case $.InsertColCommandId: {
  7954. const c = e.params, d = c.range;
  7955. return {
  7956. unitId: c.unitId,
  7957. subUnitId: c.subUnitId,
  7958. ranges: [
  7959. ...d.startColumn > 0 ? [{
  7960. ...d,
  7961. startColumn: d.startColumn - 1,
  7962. endColumn: d.endColumn - 1
  7963. }] : [],
  7964. {
  7965. ...d,
  7966. startColumn: d.startColumn,
  7967. endColumn: Number.MAX_SAFE_INTEGER
  7968. }
  7969. ]
  7970. };
  7971. }
  7972. case $.RemoveRowCommandId: {
  7973. const d = e.params.range, h = N(t);
  7974. return {
  7975. unitId: h.unitId,
  7976. subUnitId: h.subUnitId,
  7977. ranges: [
  7978. d,
  7979. {
  7980. ...d,
  7981. startRow: d.endRow + 1,
  7982. endRow: Number.MAX_SAFE_INTEGER
  7983. }
  7984. ]
  7985. };
  7986. }
  7987. case $.RemoveColCommandId: {
  7988. const d = e.params.range, h = N(t);
  7989. return {
  7990. unitId: h.unitId,
  7991. subUnitId: h.subUnitId,
  7992. ranges: [
  7993. d,
  7994. {
  7995. ...d,
  7996. startColumn: d.endColumn + 1,
  7997. endColumn: Number.MAX_SAFE_INTEGER
  7998. }
  7999. ]
  8000. };
  8001. }
  8002. case $.DeleteRangeMoveUpCommandId:
  8003. case $.InsertRangeMoveDownCommandId: {
  8004. 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]);
  8005. return h ? {
  8006. unitId: d.unitId,
  8007. subUnitId: d.subUnitId,
  8008. ranges: [
  8009. h,
  8010. {
  8011. ...h,
  8012. startRow: h.endRow + 1,
  8013. endRow: Number.MAX_SAFE_INTEGER
  8014. }
  8015. ]
  8016. } : {
  8017. unitId: d.unitId,
  8018. subUnitId: d.subUnitId,
  8019. ranges: []
  8020. };
  8021. }
  8022. case $.DeleteRangeMoveLeftCommandId:
  8023. case $.InsertRangeMoveRightCommandId: {
  8024. 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);
  8025. return d ? {
  8026. unitId: h.unitId,
  8027. subUnitId: h.subUnitId,
  8028. ranges: [
  8029. d,
  8030. {
  8031. ...d,
  8032. startColumn: d.endColumn + 1,
  8033. endColumn: Number.MAX_SAFE_INTEGER
  8034. }
  8035. ]
  8036. } : {
  8037. unitId: h.unitId,
  8038. subUnitId: h.subUnitId,
  8039. ranges: []
  8040. };
  8041. }
  8042. case $.ReorderRangeCommandId: {
  8043. const c = e, { range: d, order: h } = c.params, m = [];
  8044. for (let f = d.startRow; f <= d.endRow; f++)
  8045. f in h && m.push({
  8046. startRow: f,
  8047. endRow: f,
  8048. startColumn: d.startColumn,
  8049. endColumn: d.endColumn
  8050. });
  8051. const g = N(t);
  8052. return {
  8053. unitId: g.unitId,
  8054. subUnitId: g.subUnitId,
  8055. ranges: m
  8056. };
  8057. }
  8058. }
  8059. }
  8060. var Ic = Object.defineProperty, vc = Object.getOwnPropertyDescriptor, Mc = (n, e, t, o) => {
  8061. for (var s = o > 1 ? void 0 : o ? vc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  8062. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  8063. return o && s && Ic(e, t, s), s;
  8064. }, dn = (n, e) => (t, o) => e(t, o, n);
  8065. const _c = rt("MERGE_REDO"), bc = rt("MERGE_UNDO"), rs = Math.floor(Number.MAX_SAFE_INTEGER / 10);
  8066. class yc extends ae {
  8067. constructor(e, t, o, s, r = !1) {
  8068. super(), this._unitId = e, this._subUnitId = t, this._range = o, this._callback = s, this._skipIntersects = r;
  8069. }
  8070. onMutation(e) {
  8071. var s, r;
  8072. if (((s = e.params) == null ? void 0 : s.unitId) !== this._unitId)
  8073. return;
  8074. if (e.id === dt.id) {
  8075. const i = e.params;
  8076. if (i.from.subUnitId !== this._subUnitId || i.to.subUnitId !== this._subUnitId)
  8077. return;
  8078. } else if (((r = e.params) == null ? void 0 : r.subUnitId) !== this._subUnitId)
  8079. return;
  8080. if (!this._range)
  8081. return;
  8082. if (this._skipIntersects) {
  8083. if (e.id === Ut.id)
  8084. return;
  8085. const i = wc(e);
  8086. if (i != null && i.some((a) => k.intersects(a, this._range)))
  8087. return;
  8088. }
  8089. const t = Sc(this._range, e);
  8090. if (t && k.equals(t, this._range))
  8091. return !1;
  8092. const o = this._range;
  8093. this._range = t, this._callback(o, t);
  8094. }
  8095. }
  8096. let _t = class extends ae {
  8097. constructor(e, t, o, s) {
  8098. super();
  8099. R(this, "interceptor", new mo({ MERGE_REDO: _c, MERGE_UNDO: bc }));
  8100. R(this, "_watchRanges", /* @__PURE__ */ new Set());
  8101. R(this, "_refRangeManagerMap", /* @__PURE__ */ new Map());
  8102. R(this, "_serializer", Ec());
  8103. // eslint-disable-next-line max-lines-per-function
  8104. R(this, "_onRefRangeChange", () => {
  8105. this._sheetInterceptorService.interceptCommand({
  8106. // eslint-disable-next-line max-lines-per-function
  8107. getMutations: (e) => {
  8108. const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET).getActiveSheet(), o = is(this._univerInstanceService), s = as(this._univerInstanceService);
  8109. if (!t || !o || !s)
  8110. return { redos: [], undos: [], preRedos: [], preUndos: [] };
  8111. const a = ((() => {
  8112. switch (e.id) {
  8113. case $.MoveColsCommandId: {
  8114. const h = e.params, m = Math.min(h.fromRange.startColumn, h.toRange.startColumn);
  8115. return this._checkRange(
  8116. [{ ...h.fromRange, startColumn: m, endColumn: t.getColumnCount() - 1 }],
  8117. o,
  8118. s
  8119. );
  8120. }
  8121. case $.MoveRowsCommandId: {
  8122. const h = e.params, m = Math.min(h.fromRange.startRow, h.toRange.startRow);
  8123. return this._checkRange(
  8124. [{ ...h.fromRange, startRow: m, endRow: t.getRowCount() - 1 }],
  8125. o,
  8126. s
  8127. );
  8128. }
  8129. case $.MoveRangeCommandId: {
  8130. const h = e;
  8131. return this._checkRange(
  8132. [h.params.fromRange, h.params.toRange],
  8133. o,
  8134. s
  8135. );
  8136. }
  8137. case $.InsertRowCommandId: {
  8138. const g = {
  8139. startRow: e.params.range.startRow,
  8140. endRow: t.getRowCount() - 1,
  8141. startColumn: 0,
  8142. endColumn: t.getColumnCount() - 1,
  8143. rangeType: H.ROW
  8144. };
  8145. return this._checkRange([g], o, s);
  8146. }
  8147. case $.InsertColCommandId: {
  8148. const m = e.params.range.startColumn, g = {
  8149. startRow: 0,
  8150. endRow: t.getRowCount() - 1,
  8151. startColumn: m,
  8152. endColumn: t.getColumnCount() - 1,
  8153. rangeType: H.COLUMN
  8154. };
  8155. return this._checkRange([g], o, s);
  8156. }
  8157. case $.RemoveRowCommandId: {
  8158. const g = {
  8159. startRow: e.params.range.startRow,
  8160. endRow: t.getRowCount() - 1,
  8161. startColumn: 0,
  8162. endColumn: t.getColumnCount() - 1,
  8163. rangeType: H.ROW
  8164. };
  8165. return this._checkRange([g], o, s);
  8166. }
  8167. case $.RemoveColCommandId: {
  8168. const m = e.params.range.startColumn, g = {
  8169. startRow: 0,
  8170. endRow: t.getRowCount() - 1,
  8171. startColumn: m,
  8172. endColumn: t.getColumnCount() - 1,
  8173. rangeType: H.COLUMN
  8174. };
  8175. return this._checkRange([g], o, s);
  8176. }
  8177. case $.DeleteRangeMoveUpCommandId:
  8178. case $.InsertRangeMoveDownCommandId: {
  8179. const m = e.params.range || us(this._selectionManagerService)[0], g = {
  8180. startRow: m.startRow,
  8181. startColumn: m.startColumn,
  8182. endColumn: m.endColumn,
  8183. endRow: rs
  8184. };
  8185. return this._checkRange([g], o, s);
  8186. }
  8187. case $.DeleteRangeMoveLeftCommandId:
  8188. case $.InsertRangeMoveRightCommandId: {
  8189. const m = e.params.range || us(this._selectionManagerService)[0], g = {
  8190. startRow: m.startRow,
  8191. startColumn: m.startColumn,
  8192. endColumn: rs,
  8193. endRow: m.endRow
  8194. };
  8195. return this._checkRange([g], o, s);
  8196. }
  8197. case $.ReorderRangeCommandId: {
  8198. const h = e, { range: m, order: g } = h.params, f = [];
  8199. for (let p = m.startRow; p <= m.endRow; p++)
  8200. p in g && f.push({
  8201. startRow: p,
  8202. endRow: p,
  8203. startColumn: m.startColumn,
  8204. endColumn: m.endColumn
  8205. });
  8206. return this._checkRange(f, o, s);
  8207. }
  8208. }
  8209. })() || []).reduce(
  8210. (h, m) => {
  8211. const g = m(e);
  8212. return h.push(g), h;
  8213. },
  8214. []
  8215. ).reduce(
  8216. (h, m) => {
  8217. var g, f;
  8218. return h.redos.push(...m.redos), h.undos.push(...m.undos), h.preRedos.push(...(g = m.preRedos) != null ? g : []), h.preUndos.push(...(f = m.preUndos) != null ? f : []), h;
  8219. },
  8220. { redos: [], undos: [], preUndos: [], preRedos: [] }
  8221. ), u = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
  8222. a.preRedos,
  8223. null
  8224. ) || [], l = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
  8225. a.redos,
  8226. null
  8227. ) || [], c = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(
  8228. a.preUndos,
  8229. null
  8230. ) || [], d = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(
  8231. a.undos,
  8232. null
  8233. ) || [];
  8234. return { redos: l, undos: d, preRedos: u, preUndos: c };
  8235. }
  8236. });
  8237. });
  8238. R(this, "_checkRange", (e, t, o) => {
  8239. const s = ls(t, o), r = this._refRangeManagerMap.get(s);
  8240. if (r) {
  8241. const i = /* @__PURE__ */ new Set();
  8242. return [...r.keys()].forEach((u) => {
  8243. const l = r.get(u), c = this._serializer.deserialize(u), d = {
  8244. ...c,
  8245. startRow: +c.startRow,
  8246. endRow: +c.endRow,
  8247. startColumn: +c.startColumn,
  8248. endColumn: +c.endColumn,
  8249. rangeType: c.rangeType && +c.rangeType
  8250. };
  8251. e.some((h) => k.intersects(h, d)) && l && l.forEach((h) => {
  8252. i.add(h);
  8253. });
  8254. }), [...i];
  8255. }
  8256. return [];
  8257. });
  8258. /**
  8259. * Listens to an area and triggers a fall back when movement occurs
  8260. * @param {IRange} range the area that needs to be monitored
  8261. * @param {RefRangCallback} callback the callback function that is executed when the range changes
  8262. * @param {string} [_unitId]
  8263. * @param {string} [_subUnitId]
  8264. * @memberof RefRangeService
  8265. */
  8266. R(this, "registerRefRange", (e, t, o, s) => {
  8267. const r = o || is(this._univerInstanceService), i = s || as(this._univerInstanceService);
  8268. if (!r || !i)
  8269. return We(() => {
  8270. });
  8271. const a = ls(r, i), u = this._serializer.serialize(e);
  8272. let l = this._refRangeManagerMap.get(a);
  8273. l || (l = /* @__PURE__ */ new Map(), this._refRangeManagerMap.set(a, l));
  8274. const c = l.get(u);
  8275. return c ? c.add(t) : l.set(u, /* @__PURE__ */ new Set([t])), We(() => {
  8276. const d = l.get(u);
  8277. d && (d.delete(t), d.size || (l.delete(u), l.size || this._refRangeManagerMap.delete(a)));
  8278. });
  8279. });
  8280. this._commandService = e, this._sheetInterceptorService = t, this._univerInstanceService = o, this._selectionManagerService = s, this._onRefRangeChange(), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_REDO, {
  8281. priority: -1,
  8282. handler: (r) => r
  8283. }), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_UNDO, {
  8284. priority: -1,
  8285. handler: (r) => r
  8286. });
  8287. }
  8288. watchRange(e, t, o, s, r) {
  8289. let i;
  8290. this._watchRanges.size === 0 && (i = this._commandService.onCommandExecuted((c) => {
  8291. if (c.type !== v.MUTATION) return !1;
  8292. for (const d of this._watchRanges)
  8293. d.onMutation(c);
  8294. }));
  8295. const a = new yc(e, t, o, s, r);
  8296. this._watchRanges.add(a);
  8297. const u = We(() => {
  8298. this._watchRanges.delete(a), this._watchRanges.size === 0 && (i == null || i.dispose(), i = null);
  8299. }), l = this.disposeWithMe(u);
  8300. return We(() => {
  8301. l.dispose(), u.dispose();
  8302. });
  8303. }
  8304. };
  8305. _t = Mc([
  8306. dn(0, E),
  8307. dn(1, L(V)),
  8308. dn(2, L(M)),
  8309. dn(3, L(F))
  8310. ], _t);
  8311. function is(n) {
  8312. return n.getCurrentUnitForType(B.UNIVER_SHEET).getUnitId();
  8313. }
  8314. function as(n) {
  8315. var e;
  8316. return (e = n.getCurrentUnitForType(B.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : e.getSheetId();
  8317. }
  8318. function us(n) {
  8319. var e;
  8320. return ((e = n.getCurrentSelections()) == null ? void 0 : e.map((t) => t.range)) || [];
  8321. }
  8322. function ls(n, e) {
  8323. return `${n}_${e}`;
  8324. }
  8325. function Ec() {
  8326. const n = ["startRow", "startColumn", "endRow", "endColumn", "rangeType"], e = "_";
  8327. return {
  8328. deserialize: (t) => {
  8329. const o = n.reduce(
  8330. (r, i, a) => (r[String(a)] = i, r),
  8331. {}
  8332. );
  8333. return t.split(e).reduce(
  8334. (r, i, a) => {
  8335. const u = String(a);
  8336. return i && o[u] && (r[o[u]] = i), r;
  8337. },
  8338. {}
  8339. );
  8340. },
  8341. serialize: (t) => n.reduce((o, s, r) => {
  8342. const i = t[s];
  8343. return i !== void 0 ? `${o}${r > 0 ? e : ""}${i}` : `${o}`;
  8344. }, "")
  8345. };
  8346. }
  8347. var Uc = Object.defineProperty, Pc = Object.getOwnPropertyDescriptor, Tc = (n, e, t, o) => {
  8348. for (var s = o > 1 ? void 0 : o ? Pc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  8349. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  8350. return o && s && Uc(e, t, s), s;
  8351. }, Rt = (n, e) => (t, o) => e(t, o, n);
  8352. const kc = [je.id, qe.id, De.id, Be.id], Nc = [ot.id, st.id];
  8353. function Zr(n, e) {
  8354. let t = n;
  8355. if (e !== void 0) {
  8356. const o = [];
  8357. for (let s = 0; s < t.length; s++) {
  8358. const { startRow: r, endRow: i, startColumn: a, endColumn: u } = t[s];
  8359. if (e === ge.ROWS)
  8360. for (let l = r; l <= i; l++) {
  8361. const c = {
  8362. startRow: l,
  8363. endRow: l,
  8364. startColumn: a,
  8365. endColumn: u
  8366. };
  8367. o.push(c);
  8368. }
  8369. else if (e === ge.COLUMNS)
  8370. for (let l = a; l <= u; l++) {
  8371. const c = {
  8372. startRow: r,
  8373. endRow: i,
  8374. startColumn: l,
  8375. endColumn: l
  8376. };
  8377. o.push(c);
  8378. }
  8379. }
  8380. t = o;
  8381. }
  8382. return t;
  8383. }
  8384. const Oc = rt("mergeCellPermissionCheck");
  8385. let Tn = class extends ae {
  8386. constructor(e, t, o, s, r, i) {
  8387. super();
  8388. R(this, "disposableCollection", new jt());
  8389. R(this, "interceptor", new mo({ MERGE_CELL_INTERCEPTOR_CHECK: Oc }));
  8390. this._commandService = e, this._refRangeService = t, this._univerInstanceService = o, this._injector = s, this._sheetInterceptorService = r, this._selectionManagerService = i, this._onRefRangeChange(), this._initCommandInterceptor(), this._commandExecutedListener();
  8391. }
  8392. _initCommandInterceptor() {
  8393. const e = this;
  8394. this._sheetInterceptorService.interceptCommand({
  8395. getMutations(t) {
  8396. var o;
  8397. switch (t.id) {
  8398. case po.id:
  8399. case So.id: {
  8400. const s = e._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET), r = s.getUnitId(), i = s == null ? void 0 : s.getActiveSheet();
  8401. if (!i)
  8402. return { redos: [], undos: [] };
  8403. const a = i.getSheetId(), u = i.getConfig().mergeData, l = (o = e._selectionManagerService.getCurrentSelections()) == null ? void 0 : o.map((c) => c.range);
  8404. if (l && l.length > 0 && l.some(
  8405. (d) => u.some((h) => k.intersects(h, d))
  8406. )) {
  8407. const d = {
  8408. unitId: r,
  8409. subUnitId: a,
  8410. ranges: l
  8411. }, h = Se(e._injector, d), m = [
  8412. { id: oe.id, params: d }
  8413. ], g = [
  8414. { id: ne.id, params: h }
  8415. ];
  8416. return { redos: m, undos: g };
  8417. }
  8418. }
  8419. }
  8420. return { redos: [], undos: [] };
  8421. }
  8422. }), this._sheetInterceptorService.interceptRanges({
  8423. getMutations: ({ unitId: t, subUnitId: o, ranges: s }) => {
  8424. const r = [], i = [], a = { redos: r, undos: i };
  8425. if (!s || !s.length)
  8426. return a;
  8427. const u = N(this._univerInstanceService, { unitId: t, subUnitId: o });
  8428. if (!u)
  8429. return a;
  8430. const { worksheet: l } = u, d = l.getMergeData().filter((h) => s.some((m) => k.intersects(h, m)));
  8431. return d.length ? (r.push({
  8432. id: oe.id,
  8433. params: {
  8434. unitId: t,
  8435. subUnitId: o,
  8436. ranges: d
  8437. }
  8438. }), i.push({
  8439. id: ne.id,
  8440. params: {
  8441. unitId: t,
  8442. subUnitId: o,
  8443. ranges: d
  8444. }
  8445. }), { undos: i, redos: r }) : a;
  8446. }
  8447. });
  8448. }
  8449. refRangeHandle(e, t, o) {
  8450. switch (e.id) {
  8451. case $.MoveColsCommandId: {
  8452. const s = e.params;
  8453. return this._handleMoveColsCommand(s, t, o);
  8454. }
  8455. case $.MoveRowsCommandId: {
  8456. const s = e.params;
  8457. return this._handleMoveRowsCommand(s, t, o);
  8458. }
  8459. case mt.id: {
  8460. const s = e.params, r = s.unitId || t, i = s.subUnitId || o;
  8461. return this._handleInsertRowCommand(s, r, i);
  8462. }
  8463. case gt.id: {
  8464. const s = e.params, r = s.unitId || t, i = s.subUnitId || o;
  8465. return this._handleInsertColCommand(s, r, i);
  8466. }
  8467. case zn.id: {
  8468. const s = e.params;
  8469. return this._handleRemoveColCommand(s, t, o);
  8470. }
  8471. case Gn.id: {
  8472. const s = e.params;
  8473. return this._handleRemoveRowCommand(s, t, o);
  8474. }
  8475. case pt.id: {
  8476. const s = e.params;
  8477. return this._handleMoveRangeCommand(s, t, o);
  8478. }
  8479. case Bn.id: {
  8480. const s = e.params;
  8481. return this._handleInsertRangeMoveRightCommand(s, t, o);
  8482. }
  8483. case sn.id: {
  8484. const s = e.params;
  8485. return this._handleInsertRangeMoveDownCommand(s, t, o);
  8486. }
  8487. case Tt.id: {
  8488. const s = e.params;
  8489. return this._handleDeleteRangeMoveUpCommand(s, t, o);
  8490. }
  8491. case Pt.id: {
  8492. const s = e.params;
  8493. return this._handleDeleteRangeMoveLeftCommand(s, t, o);
  8494. }
  8495. }
  8496. return { redos: [], undos: [] };
  8497. }
  8498. _onRefRangeChange() {
  8499. const e = (t, o) => {
  8500. const s = this._univerInstanceService.getUniverSheetInstance(t);
  8501. if (!s)
  8502. return;
  8503. const r = s == null ? void 0 : s.getSheetBySheetId(o);
  8504. if (!r)
  8505. return;
  8506. this.disposableCollection.dispose();
  8507. const i = r.getMergeData(), a = (u) => this.refRangeHandle(u, t, o);
  8508. i.forEach((u) => {
  8509. this.disposableCollection.add(this._refRangeService.registerRefRange(u, a, t, o));
  8510. });
  8511. };
  8512. this.disposeWithMe(
  8513. this._commandService.onCommandExecuted((t) => {
  8514. if (t.id === an.id) {
  8515. const o = t.params, s = o.subUnitId, r = o.unitId;
  8516. if (!s || !r)
  8517. return;
  8518. e(r, s);
  8519. }
  8520. if (t.id === ne.id) {
  8521. const o = t.params, s = o.subUnitId, r = o.unitId;
  8522. if (!s || !r)
  8523. return;
  8524. e(o.unitId, o.subUnitId);
  8525. }
  8526. })
  8527. ), this._univerInstanceService.getCurrentTypeOfUnit$(B.UNIVER_SHEET).pipe(zi((t) => !!t)).subscribe((t) => {
  8528. const o = t.getActiveSheet();
  8529. o && e(t.getUnitId(), o.getSheetId());
  8530. });
  8531. }
  8532. _handleMoveRowsCommand(e, t, o) {
  8533. const s = be(this._univerInstanceService, t);
  8534. if (!s)
  8535. return this._handleNull();
  8536. const r = ye(s, o);
  8537. if (!r)
  8538. return this._handleNull();
  8539. const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startRow: c, endRow: d } = l;
  8540. if (i.forEach((g) => {
  8541. if (c <= g.startRow && d >= g.endRow) {
  8542. a.ranges.push(g);
  8543. const f = Jr({ id: $.MoveRowsCommandId, params: e }, g), p = Mt(f, g);
  8544. p && u.ranges.push(p);
  8545. }
  8546. }), a.ranges.length === 0)
  8547. return this._handleNull();
  8548. const h = Se(this._injector, a), m = Ue(this._injector, u);
  8549. return {
  8550. preRedos: [{ id: oe.id, params: a }],
  8551. redos: [{ id: ne.id, params: u }],
  8552. preUndos: [{ id: oe.id, params: m }],
  8553. undos: [{ id: ne.id, params: h }]
  8554. };
  8555. }
  8556. _handleMoveColsCommand(e, t, o) {
  8557. const s = be(this._univerInstanceService, t);
  8558. if (!s)
  8559. return this._handleNull();
  8560. const r = ye(s, o);
  8561. if (!r)
  8562. return this._handleNull();
  8563. const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startColumn: c, endColumn: d } = l;
  8564. if (i.forEach((g) => {
  8565. if (c <= g.startColumn && d >= g.endColumn) {
  8566. a.ranges.push(g);
  8567. const f = Yr({ id: $.MoveColsCommandId, params: e }, g), p = Mt(f, g);
  8568. p && u.ranges.push(p);
  8569. }
  8570. }), a.ranges.length === 0)
  8571. return this._handleNull();
  8572. const h = Se(this._injector, a), m = Ue(this._injector, u);
  8573. return {
  8574. preRedos: [{ id: oe.id, params: a }],
  8575. redos: [{ id: ne.id, params: u }],
  8576. preUndos: [{ id: oe.id, params: m }],
  8577. undos: [{ id: ne.id, params: h }]
  8578. };
  8579. }
  8580. _handleMoveRangeCommand(e, t, o) {
  8581. const s = be(this._univerInstanceService, t);
  8582. if (!s)
  8583. return this._handleNull();
  8584. const r = ye(s, o);
  8585. if (!r)
  8586. return this._handleNull();
  8587. const i = r.getMergeData(), a = i.filter((m) => k.intersects(m, e.fromRange)), u = i.filter((m) => k.intersects(m, e.toRange)), l = a.map((m) => k.getRelativeRange(m, e.fromRange)).map((m) => k.getPositionRange(m, e.toRange)), c = Zr(l).filter(
  8588. (m) => !i.some((g) => k.equals(m, g))
  8589. ), d = [
  8590. {
  8591. id: oe.id,
  8592. params: {
  8593. unitId: t,
  8594. subUnitId: o,
  8595. ranges: a
  8596. }
  8597. },
  8598. {
  8599. id: oe.id,
  8600. params: {
  8601. unitId: t,
  8602. subUnitId: o,
  8603. ranges: u
  8604. }
  8605. },
  8606. {
  8607. id: ne.id,
  8608. params: {
  8609. unitId: t,
  8610. subUnitId: o,
  8611. ranges: c
  8612. }
  8613. }
  8614. ], h = [
  8615. {
  8616. id: oe.id,
  8617. params: {
  8618. unitId: t,
  8619. subUnitId: o,
  8620. ranges: c
  8621. }
  8622. },
  8623. {
  8624. id: ne.id,
  8625. params: {
  8626. unitId: t,
  8627. subUnitId: o,
  8628. ranges: u
  8629. }
  8630. },
  8631. {
  8632. id: ne.id,
  8633. params: {
  8634. unitId: t,
  8635. subUnitId: o,
  8636. ranges: a
  8637. }
  8638. }
  8639. ];
  8640. return { redos: d, undos: h };
  8641. }
  8642. _handleInsertRowCommand(e, t, o) {
  8643. const s = be(this._univerInstanceService, t);
  8644. if (!s)
  8645. return this._handleNull();
  8646. const r = ye(s, o);
  8647. if (!r)
  8648. return this._handleNull();
  8649. const { range: i } = e, { startRow: a, endRow: u } = i, l = O.deepClone(r.getMergeData()).reduce((C, S) => (a > S.startRow && a <= S.endRow && C.push(S), C), []);
  8650. if (l.length === 0)
  8651. return this._handleNull();
  8652. const c = O.deepClone(r.getMergeData()).reduce((C, S) => {
  8653. if (a > S.startRow && a <= S.endRow) {
  8654. const I = u - a + 1;
  8655. S.endRow += I, this._checkIsMergeCell(S) && C.push(S);
  8656. }
  8657. return C;
  8658. }, []), d = {
  8659. unitId: t,
  8660. subUnitId: o,
  8661. ranges: l
  8662. }, h = Se(
  8663. this._injector,
  8664. d
  8665. ), m = {
  8666. unitId: t,
  8667. subUnitId: o,
  8668. ranges: c
  8669. }, g = Ue(
  8670. this._injector,
  8671. m
  8672. ), f = [
  8673. { id: oe.id, params: d },
  8674. { id: ne.id, params: m }
  8675. ], p = [
  8676. { id: oe.id, params: g },
  8677. { id: ne.id, params: h }
  8678. ];
  8679. return { redos: f, undos: p };
  8680. }
  8681. _handleInsertColCommand(e, t, o) {
  8682. const { range: s } = e, r = be(this._univerInstanceService, t);
  8683. if (!r)
  8684. return this._handleNull();
  8685. const i = ye(r, o);
  8686. if (!i)
  8687. return this._handleNull();
  8688. const { startColumn: a, endColumn: u } = s, l = O.deepClone(i.getMergeData()).reduce((C, S) => (a > S.startColumn && a <= S.endColumn && C.push(S), C), []);
  8689. if (l.length === 0)
  8690. return this._handleNull();
  8691. const c = O.deepClone(i.getMergeData()).reduce((C, S) => {
  8692. if (a > S.startColumn && a <= S.endColumn) {
  8693. const I = u - a + 1;
  8694. S.endColumn += I, this._checkIsMergeCell(S) && C.push(S);
  8695. }
  8696. return C;
  8697. }, []), d = {
  8698. unitId: t,
  8699. subUnitId: o,
  8700. ranges: l
  8701. }, h = Se(
  8702. this._injector,
  8703. d
  8704. ), m = {
  8705. unitId: t,
  8706. subUnitId: o,
  8707. ranges: c
  8708. }, g = Ue(
  8709. this._injector,
  8710. m
  8711. ), f = [
  8712. { id: oe.id, params: d },
  8713. { id: ne.id, params: m }
  8714. ], p = [
  8715. { id: oe.id, params: g },
  8716. { id: ne.id, params: h }
  8717. ];
  8718. return { redos: f, undos: p };
  8719. }
  8720. _handleRemoveColCommand(e, t, o) {
  8721. const s = be(this._univerInstanceService, t);
  8722. if (!s)
  8723. return this._handleNull();
  8724. const r = ye(s, o);
  8725. if (!r)
  8726. return this._handleNull();
  8727. const { range: i } = e, { startColumn: a, endColumn: u } = i, l = O.deepClone(r.getMergeData()).reduce((I, w) => (k.intersects(i, w) && I.push(w), I), []);
  8728. if (l.length === 0)
  8729. return this._handleNull();
  8730. const c = O.deepClone(r.getMergeData()).reduce((I, w) => {
  8731. if (k.intersects(i, w)) {
  8732. if (a <= w.startColumn && u >= w.endColumn)
  8733. return I;
  8734. 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);
  8735. }
  8736. return I;
  8737. }, []), d = {
  8738. unitId: t,
  8739. subUnitId: o,
  8740. ranges: l
  8741. }, h = Se(
  8742. this._injector,
  8743. d
  8744. ), m = {
  8745. unitId: t,
  8746. subUnitId: o,
  8747. ranges: c
  8748. }, g = Ue(
  8749. this._injector,
  8750. m
  8751. ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g }], S = [{ id: ne.id, params: h }];
  8752. return { preUndos: C, undos: S, preRedos: f, redos: p };
  8753. }
  8754. _handleRemoveRowCommand(e, t, o) {
  8755. const { range: s } = e, r = be(this._univerInstanceService, t);
  8756. if (!r)
  8757. return this._handleNull();
  8758. const i = ye(r, o);
  8759. if (!i)
  8760. return this._handleNull();
  8761. const { startRow: a, endRow: u } = s, l = O.deepClone(i.getMergeData()).reduce((I, w) => (k.intersects(s, w) && I.push(w), I), []);
  8762. if (l.length === 0)
  8763. return this._handleNull();
  8764. const c = O.deepClone(i.getMergeData()).reduce((I, w) => {
  8765. if (k.intersects(s, w)) {
  8766. if (a <= w.startRow && u >= w.endRow)
  8767. return I;
  8768. 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);
  8769. }
  8770. return I;
  8771. }, []), d = {
  8772. unitId: t,
  8773. subUnitId: o,
  8774. ranges: l
  8775. }, h = Se(
  8776. this._injector,
  8777. d
  8778. ), m = {
  8779. unitId: t,
  8780. subUnitId: o,
  8781. ranges: c
  8782. }, g = Ue(
  8783. this._injector,
  8784. m
  8785. ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g }], S = [{ id: ne.id, params: h }];
  8786. return { preUndos: C, undos: S, preRedos: f, redos: p };
  8787. }
  8788. _handleInsertRangeMoveRightCommand(e, t, o) {
  8789. const s = be(this._univerInstanceService, t);
  8790. if (!s)
  8791. return this._handleNull();
  8792. const r = ye(s, o);
  8793. if (!r)
  8794. return this._handleNull();
  8795. const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = [];
  8796. u.forEach((f) => {
  8797. const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i;
  8798. if (k.intersects(
  8799. {
  8800. startRow: p,
  8801. startColumn: S,
  8802. endRow: C,
  8803. endColumn: a
  8804. },
  8805. f
  8806. ) && (l.push(f), k.contains(
  8807. {
  8808. startRow: p,
  8809. startColumn: S,
  8810. endRow: C,
  8811. endColumn: a
  8812. },
  8813. f
  8814. ))) {
  8815. const y = I - S + 1;
  8816. c.push({
  8817. startRow: f.startRow,
  8818. startColumn: f.startColumn + y,
  8819. endRow: f.endRow,
  8820. endColumn: f.endColumn + y
  8821. });
  8822. }
  8823. });
  8824. const d = {
  8825. unitId: t,
  8826. subUnitId: o,
  8827. ranges: l
  8828. }, h = Se(
  8829. this._injector,
  8830. d
  8831. ), m = {
  8832. unitId: t,
  8833. subUnitId: o,
  8834. ranges: c
  8835. }, g = Ue(
  8836. this._injector,
  8837. m
  8838. );
  8839. return {
  8840. preRedos: [
  8841. { id: oe.id, params: d }
  8842. ],
  8843. redos: [
  8844. {
  8845. id: ne.id,
  8846. params: m
  8847. }
  8848. ],
  8849. preUndos: [
  8850. { id: oe.id, params: g }
  8851. ],
  8852. undos: [
  8853. {
  8854. id: ne.id,
  8855. params: h
  8856. }
  8857. ]
  8858. };
  8859. }
  8860. _handleInsertRangeMoveDownCommand(e, t, o) {
  8861. const s = be(this._univerInstanceService, t);
  8862. if (!s)
  8863. return this._handleNull();
  8864. const r = ye(s, o);
  8865. if (!r)
  8866. return this._handleNull();
  8867. const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = [];
  8868. u.forEach((I) => {
  8869. const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i;
  8870. if (k.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), k.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) {
  8871. const P = x - w + 1;
  8872. c.push({
  8873. startRow: I.startRow + P,
  8874. startColumn: I.startColumn,
  8875. endRow: I.endRow + P,
  8876. endColumn: I.endColumn
  8877. });
  8878. }
  8879. });
  8880. const d = {
  8881. unitId: t,
  8882. subUnitId: o,
  8883. ranges: l
  8884. }, h = Se(
  8885. this._injector,
  8886. d
  8887. ), m = {
  8888. unitId: t,
  8889. subUnitId: o,
  8890. ranges: c
  8891. }, g = Ue(
  8892. this._injector,
  8893. m
  8894. ), f = [
  8895. {
  8896. id: oe.id,
  8897. params: d
  8898. }
  8899. ], p = [
  8900. {
  8901. id: ne.id,
  8902. params: m
  8903. }
  8904. ], C = [
  8905. {
  8906. id: oe.id,
  8907. params: g
  8908. }
  8909. ], S = [
  8910. {
  8911. id: ne.id,
  8912. params: h
  8913. }
  8914. ];
  8915. return { redos: p, undos: S, preRedos: f, preUndos: C };
  8916. }
  8917. _handleDeleteRangeMoveUpCommand(e, t, o) {
  8918. const s = be(this._univerInstanceService, t);
  8919. if (!s)
  8920. return this._handleNull();
  8921. const r = ye(s, o);
  8922. if (!r)
  8923. return this._handleNull();
  8924. const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = [];
  8925. u.forEach((I) => {
  8926. const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i;
  8927. if (k.intersects({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I) && (l.push(I), k.contains({ startRow: w, startColumn: b, endRow: a, endColumn: y }, I))) {
  8928. const P = x - w + 1, A = k.moveVertical(I, -P);
  8929. c.push(A);
  8930. }
  8931. });
  8932. const d = {
  8933. unitId: t,
  8934. subUnitId: o,
  8935. ranges: l
  8936. }, h = Se(
  8937. this._injector,
  8938. d
  8939. ), m = {
  8940. unitId: t,
  8941. subUnitId: o,
  8942. ranges: c
  8943. }, g = Ue(
  8944. this._injector,
  8945. m
  8946. ), f = [
  8947. {
  8948. id: oe.id,
  8949. params: d
  8950. }
  8951. ], p = [
  8952. {
  8953. id: ne.id,
  8954. params: m
  8955. }
  8956. ], C = [
  8957. {
  8958. id: oe.id,
  8959. params: g
  8960. }
  8961. ], S = [
  8962. {
  8963. id: ne.id,
  8964. params: h
  8965. }
  8966. ];
  8967. return { redos: p, undos: S, preRedos: f, preUndos: C };
  8968. }
  8969. _handleDeleteRangeMoveLeftCommand(e, t, o) {
  8970. const s = be(this._univerInstanceService, t);
  8971. if (!s)
  8972. return this._handleNull();
  8973. const r = ye(s, o);
  8974. if (!r)
  8975. return this._handleNull();
  8976. const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = [];
  8977. u.forEach((f) => {
  8978. const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i;
  8979. if (k.intersects(
  8980. {
  8981. startRow: p,
  8982. startColumn: S,
  8983. endRow: C,
  8984. endColumn: a
  8985. },
  8986. f
  8987. ) && (l.push(f), k.contains(
  8988. {
  8989. startRow: p,
  8990. startColumn: S,
  8991. endRow: C,
  8992. endColumn: a
  8993. },
  8994. f
  8995. ))) {
  8996. const y = I - S + 1;
  8997. c.push({
  8998. startRow: f.startRow,
  8999. startColumn: f.startColumn - y,
  9000. endRow: f.endRow,
  9001. endColumn: f.endColumn - y
  9002. });
  9003. }
  9004. });
  9005. const d = {
  9006. unitId: t,
  9007. subUnitId: o,
  9008. ranges: l
  9009. }, h = Se(this._injector, d), m = {
  9010. unitId: t,
  9011. subUnitId: o,
  9012. ranges: c
  9013. }, g = Ue(this._injector, m);
  9014. return {
  9015. preRedos: [
  9016. { id: oe.id, params: d }
  9017. ],
  9018. redos: [
  9019. {
  9020. id: ne.id,
  9021. params: m
  9022. }
  9023. ],
  9024. undos: [
  9025. {
  9026. id: ne.id,
  9027. params: h
  9028. }
  9029. ],
  9030. preUndos: [
  9031. { id: oe.id, params: g }
  9032. ]
  9033. };
  9034. }
  9035. _checkIsMergeCell(e) {
  9036. return !(e.startRow === e.endRow && e.startColumn === e.endColumn);
  9037. }
  9038. _handleNull() {
  9039. return { redos: [], undos: [] };
  9040. }
  9041. _commandExecutedListener() {
  9042. this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
  9043. if (Nc.includes(e.id)) {
  9044. if (!e.params) return;
  9045. const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
  9046. if (!t) return;
  9047. const o = t.getSheetBySheetId(e.params.subUnitId);
  9048. if (!o) return;
  9049. 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 = [];
  9050. c.forEach((f) => {
  9051. let { startRow: p, endRow: C, startColumn: S, endColumn: I, rangeType: w } = f;
  9052. k.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 });
  9053. }), o.setMergeData(d), this.disposableCollection.dispose();
  9054. const { unitId: h, subUnitId: m } = e.params, g = (f) => this.refRangeHandle(f, h, m);
  9055. d.forEach((f) => {
  9056. this.disposableCollection.add(this._refRangeService.registerRefRange(f, g, h, m));
  9057. });
  9058. }
  9059. if (kc.includes(e.id)) {
  9060. const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
  9061. if (!t) return;
  9062. const o = t.getSheetBySheetId(e.params.subUnitId);
  9063. if (!o) return;
  9064. const s = o.getConfig().mergeData, r = e.params;
  9065. if (!r) return;
  9066. 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 = [];
  9067. s.forEach((p) => {
  9068. let { startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b } = p;
  9069. 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 });
  9070. }), o.setMergeData(h), this.disposableCollection.dispose();
  9071. const { unitId: m, subUnitId: g } = e.params, f = (p) => this.refRangeHandle(p, m, g);
  9072. h.forEach((p) => {
  9073. this.disposableCollection.add(this._refRangeService.registerRefRange(p, f, m, g));
  9074. });
  9075. }
  9076. }));
  9077. }
  9078. };
  9079. Tn = Tc([
  9080. Rt(0, L(E)),
  9081. Rt(1, L(_t)),
  9082. Rt(2, L(M)),
  9083. Rt(3, L(Ro)),
  9084. Rt(4, L(V)),
  9085. Rt(5, L(F))
  9086. ], Tn);
  9087. function be(n, e) {
  9088. return e ? n.getUniverSheetInstance(e) : n.getCurrentUnitForType(B.UNIVER_SHEET);
  9089. }
  9090. function ye(n, e) {
  9091. return e ? n.getSheetBySheetId(e) : n.getActiveSheet();
  9092. }
  9093. var Dc = Object.defineProperty, Ac = Object.getOwnPropertyDescriptor, xc = (n, e, t, o) => {
  9094. for (var s = o > 1 ? void 0 : o ? Ac(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  9095. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  9096. return o && s && Dc(e, t, s), s;
  9097. }, $c = (n, e) => (t, o) => e(t, o, n);
  9098. let kn = class extends ae {
  9099. constructor(n) {
  9100. super(), this._sheetInterceptorService = n, this._initialize();
  9101. }
  9102. _initialize() {
  9103. this._initInterceptorCellContent();
  9104. }
  9105. _initInterceptorCellContent() {
  9106. this.disposeWithMe(
  9107. this._sheetInterceptorService.intercept(et.CELL_CONTENT, {
  9108. priority: 11,
  9109. effect: me.Value | me.Style,
  9110. handler: (n, e, t) => {
  9111. var s;
  9112. const o = e.workbook.getStyles().getStyleByCell(n);
  9113. return (s = o == null ? void 0 : o.n) != null && s.pattern ? t({ ...n }) : (n == null ? void 0 : n.t) === se.NUMBER && n.v !== void 0 && n.v !== null && go(n.v) ? t({
  9114. ...n,
  9115. v: xi(Number(n.v))
  9116. }) : t({ ...n });
  9117. }
  9118. })
  9119. );
  9120. }
  9121. };
  9122. kn = xc([
  9123. $c(0, L(V))
  9124. ], kn);
  9125. var Wc = Object.defineProperty, Lc = Object.getOwnPropertyDescriptor, Vc = (n, e, t, o) => {
  9126. for (var s = o > 1 ? void 0 : o ? Lc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  9127. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  9128. return o && s && Wc(e, t, s), s;
  9129. }, $e = (n, e) => (t, o) => e(t, o, n);
  9130. let Nn = class extends ae {
  9131. constructor(e, t, o, s, r, i, a, u, l, c) {
  9132. super();
  9133. R(this, "disposableCollection", new jt());
  9134. R(this, "_triggerPermissionUIEvent$", new Le());
  9135. R(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable());
  9136. 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();
  9137. }
  9138. blockExecuteWithoutPermission(e) {
  9139. throw this._triggerPermissionUIEvent$.next(e), new wi("have no permission");
  9140. }
  9141. _getPermissionCheck(e, t) {
  9142. let o = !0, s = "";
  9143. switch (e) {
  9144. case on.id:
  9145. Is(t.value) && t.value.f ? (o = this._permissionCheckWithFormula(t), s = this._localeService.t("permission.dialog.formulaErr")) : o = this._permissionCheckBySetRangeValue({
  9146. workbookTypes: [Me],
  9147. rangeTypes: [Pe],
  9148. worksheetTypes: [wn, Te]
  9149. }, t);
  9150. break;
  9151. case Co.id:
  9152. o = this.permissionCheckWithRanges({
  9153. workbookTypes: [Me],
  9154. rangeTypes: [Pe],
  9155. worksheetTypes: [wn, Te]
  9156. }), s = this._localeService.t("permission.dialog.editErr");
  9157. break;
  9158. case Oo.id:
  9159. case Mn.id:
  9160. o = this.permissionCheckWithoutRange({
  9161. worksheetTypes: [$t]
  9162. }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
  9163. break;
  9164. case $o.id:
  9165. case Wo.id:
  9166. case Lo.id:
  9167. o = this.permissionCheckWithoutRange({
  9168. worksheetTypes: [Wt]
  9169. }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
  9170. break;
  9171. case jn.id:
  9172. case Fn.id:
  9173. o = this._permissionCheckByMoveCommand(t), s = this._localeService.t("permission.dialog.moveRowColErr");
  9174. break;
  9175. case pt.id:
  9176. o = this._permissionCheckByMoveRangeCommand(t), s = this._localeService.t("permission.dialog.moveRangeErr");
  9177. break;
  9178. case Wr.id:
  9179. o = this._permissionCheckByWorksheetCommand([Me, _o]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder();
  9180. break;
  9181. case Do.id:
  9182. o = this._permissionCheckByWorksheetCommand([Me, bo]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder();
  9183. break;
  9184. case Fr.id:
  9185. {
  9186. const { unitId: r, subUnitId: i } = t;
  9187. o = this._permissionCheckByWorksheetCommand([Me, vo], r, i), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder();
  9188. }
  9189. break;
  9190. case Kn.id:
  9191. o = this.permissionCheckWithRanges({
  9192. workbookTypes: [Me],
  9193. rangeTypes: [Pe],
  9194. worksheetTypes: [Te, $t]
  9195. }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr");
  9196. break;
  9197. case Jn.id:
  9198. o = this.permissionCheckWithRanges({
  9199. workbookTypes: [Me],
  9200. rangeTypes: [Pe],
  9201. worksheetTypes: [Te, Wt]
  9202. }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr");
  9203. break;
  9204. case br.id:
  9205. o = this.permissionCheckWithRanges({
  9206. workbookTypes: [Me],
  9207. rangeTypes: [Pe],
  9208. worksheetTypes: [Te, $t]
  9209. }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
  9210. break;
  9211. case Tr.id:
  9212. o = this.permissionCheckWithRanges({
  9213. workbookTypes: [Me],
  9214. rangeTypes: [Pe],
  9215. worksheetTypes: [Te, Wt]
  9216. }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
  9217. break;
  9218. case Bn.id:
  9219. o = this._permissionCheckWithInsertRangeMove("right"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
  9220. break;
  9221. case sn.id:
  9222. o = this._permissionCheckWithInsertRangeMove("bottom"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
  9223. break;
  9224. case Pt.id:
  9225. o = this._permissionCheckWithInsertRangeMove("left"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
  9226. break;
  9227. case Tt.id:
  9228. o = this._permissionCheckWithInsertRangeMove("top"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
  9229. break;
  9230. }
  9231. o || this.blockExecuteWithoutPermission(s);
  9232. }
  9233. _initialize() {
  9234. this._commandExecutedListener();
  9235. }
  9236. _commandExecutedListener() {
  9237. this.disposeWithMe(
  9238. this._commandService.beforeCommandExecuted((e) => {
  9239. this._getPermissionCheck(e.id, e == null ? void 0 : e.params);
  9240. })
  9241. ), this.disposeWithMe(
  9242. this._commandService.onCommandExecuted((e) => {
  9243. var t;
  9244. if (e.id === _n.id) {
  9245. const o = e.params, { unitId: s = (t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET)) == null ? void 0 : t.getUnitId(), subUnitId: r } = o;
  9246. if (!s || !r)
  9247. return;
  9248. const i = this._worksheetProtectionRuleModel.getRule(s, r), a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r);
  9249. i && this._worksheetProtectionRuleModel.ruleRefresh(i.permissionId), a.length && this._rangeProtectionRuleModel.ruleRefresh(r);
  9250. }
  9251. })
  9252. );
  9253. }
  9254. _permissionCheckWithInsertRangeMove(e) {
  9255. var l;
  9256. const t = N(this._univerInstanceService);
  9257. if (!t)
  9258. return !1;
  9259. const { worksheet: o, unitId: s, subUnitId: r } = t, i = O.deepClone((l = this._selectionManagerService.getCurrentLastSelection()) == null ? void 0 : l.range);
  9260. 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) => k.getIntersects(i, c))));
  9261. }
  9262. _permissionCheckByWorksheetCommand(e, t, o) {
  9263. var l, c;
  9264. const s = N(this._univerInstanceService, { unitId: t, subUnitId: o });
  9265. if (!s)
  9266. return !1;
  9267. const { unitId: r, subUnitId: i } = s, a = this._worksheetProtectionRuleModel.getRule(r, i), u = this._rangeProtectionRuleModel.getSubunitRuleList(r, i).length > 0;
  9268. return a || u ? (c = (l = this._permissionService.getPermissionPoint(new Mo(r).id)) == null ? void 0 : l.value) != null ? c : !1 : this._permissionService.composePermission(e.map((d) => new d(r).id)).every((d) => d.value);
  9269. }
  9270. permissionCheckWithoutRange(e) {
  9271. var h, m, g, f;
  9272. const t = N(this._univerInstanceService);
  9273. if (!t)
  9274. return !1;
  9275. const { worksheet: o, unitId: s, subUnitId: r } = t, i = this._selectionManagerService.getCurrentLastSelection();
  9276. if (!i)
  9277. return !0;
  9278. const a = (m = (h = i == null ? void 0 : i.primary) == null ? void 0 : h.actualRow) != null ? m : 0, u = (f = (g = i == null ? void 0 : i.primary) == null ? void 0 : g.actualColumn) != null ? f : 0, { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e;
  9279. return !(l && l.some((C) => {
  9280. var w, b;
  9281. const S = new C(s);
  9282. return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : !1) === !1;
  9283. }) === !0 || c && c.some((C) => {
  9284. var w, b;
  9285. const S = new C(s, r);
  9286. return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : !1) === !1;
  9287. }) === !0 || d && d.some((C) => {
  9288. var y, x, T, U, P;
  9289. const S = (x = (y = o.getCell(a, u)) == null ? void 0 : y.selectionProtection) == null ? void 0 : x[0];
  9290. if (!(S != null && S.ruleId))
  9291. return !1;
  9292. const I = (T = this._rangeProtectionRuleModel.getRule(s, r, S.ruleId)) == null ? void 0 : T.permissionId;
  9293. if (!I)
  9294. return !1;
  9295. const w = new C(s, r, I);
  9296. return ((P = (U = this._permissionService.getPermissionPoint(w.id)) == null ? void 0 : U.value) != null ? P : !1) === !1;
  9297. }) === !0);
  9298. }
  9299. permissionCheckWithRanges(e, t, o, s) {
  9300. var m;
  9301. const r = N(this._univerInstanceService);
  9302. if (!r)
  9303. return !1;
  9304. const { workbook: i, worksheet: a } = r;
  9305. o || (o = i.getUnitId()), s || (s = a.getSheetId());
  9306. const u = t != null ? t : (m = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : m.map((g) => g.range);
  9307. if (!u)
  9308. return !1;
  9309. const { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e, h = [];
  9310. return l && h.push(...l.map((g) => new g(o).id)), c && h.push(...c.map((g) => new g(o, s).id)), d && this._rangeProtectionRuleModel.getSubunitRuleList(o, s).forEach((g) => {
  9311. u.some((p) => g.ranges.some((C) => k.intersects(C, p))) && h.push(...d.map((p) => new p(o, s, g.permissionId).id));
  9312. }), h.length ? this._permissionService.composePermission(h).every((g) => g.value) : !0;
  9313. }
  9314. _permissionCheckByMoveCommand(e) {
  9315. const t = N(this._univerInstanceService);
  9316. if (!t)
  9317. return !1;
  9318. const { worksheet: o, unitId: s, subUnitId: r } = t, i = e.toRange;
  9319. i.endRow === o.getRowCount() - 1 ? i.endColumn = i.startColumn : i.endRow = i.startRow;
  9320. const a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r).reduce((u, l) => [...u, ...l.ranges], []).filter((u) => k.intersects(u, i));
  9321. return a.length > 0 ? !1 : (a.forEach((u) => {
  9322. var l, c;
  9323. for (let d = u.startRow; d <= u.endRow; d++)
  9324. for (let h = u.startColumn; h <= u.endColumn; h++) {
  9325. const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0];
  9326. if ((m == null ? void 0 : m[_.Edit]) === !1)
  9327. return !1;
  9328. }
  9329. }), !0);
  9330. }
  9331. _permissionCheckByMoveRangeCommand(e) {
  9332. const t = N(this._univerInstanceService);
  9333. if (!t)
  9334. return !1;
  9335. 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) => k.intersects(u, i));
  9336. return a.length > 0 ? !1 : (a.forEach((u) => {
  9337. var l, c;
  9338. for (let d = u.startRow; d <= u.endRow; d++)
  9339. for (let h = u.startColumn; h <= u.endColumn; h++) {
  9340. const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0];
  9341. if ((m == null ? void 0 : m[_.Edit]) === !1)
  9342. return !1;
  9343. }
  9344. }), !0);
  9345. }
  9346. _permissionCheckBySetRangeValue(e, t) {
  9347. let o = [];
  9348. t.range ? o = [t.range] : o = [new G(t.value).getDataRange()];
  9349. const { unitId: s, subUnitId: r } = t;
  9350. return this.permissionCheckWithRanges(e, o, s, r);
  9351. }
  9352. _permissionCheckWithFormula(e) {
  9353. var r, i, a, u, l;
  9354. const t = e.value, o = e.range, s = t.f;
  9355. if (s) {
  9356. const c = s.substring(1), d = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET), h = (r = e.unitId) != null ? r : d.getUnitId(), m = this._definedNamesService.getValueByName(h, c);
  9357. if (m) {
  9358. let g = m.formulaOrRefString;
  9359. g.startsWith(Wi.EQUALS) && (g = g.slice(1));
  9360. const f = g.split(",");
  9361. for (let p = 0; p < f.length; p++) {
  9362. const C = f[p], S = Li(C);
  9363. if (S.sheetName) {
  9364. const I = d.getSheetBySheetName(S.sheetName);
  9365. if (!I)
  9366. return !0;
  9367. const { startRow: w, endRow: b, startColumn: y, endColumn: x } = S.range;
  9368. for (let T = w; T <= b; T++)
  9369. for (let U = y; U <= x; U++) {
  9370. const P = (a = (i = I.getCell(T, U)) == null ? void 0 : i.selectionProtection) == null ? void 0 : a[0];
  9371. if ((P == null ? void 0 : P[_.View]) === !1)
  9372. return !1;
  9373. }
  9374. }
  9375. }
  9376. return !0;
  9377. } else {
  9378. const g = this._lexerTreeBuilder.sequenceNodesBuilder(s);
  9379. if (!g)
  9380. return !0;
  9381. for (let f = 0; f < g.length; f++) {
  9382. const p = g[f];
  9383. if (typeof p == "string" || p.nodeType !== Vi.REFERENCE)
  9384. continue;
  9385. const { token: C } = p, S = Hi(C), I = S.unitId ? this._univerInstanceService.getUnit(S.unitId) : this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
  9386. if (!I) return !0;
  9387. let w = S.sheetName ? I.getSheetBySheetName(S.sheetName) : I.getActiveSheet();
  9388. const b = I.getUnitId();
  9389. if (S.sheetName) {
  9390. if (w = I.getSheetBySheetName(S.sheetName), !w)
  9391. return !0;
  9392. const P = w == null ? void 0 : w.getSheetId();
  9393. if (!this._permissionService.getPermissionPoint(new Hn(b, P).id)) return !1;
  9394. }
  9395. if (!w)
  9396. return !0;
  9397. const { startRow: y, endRow: x, startColumn: T, endColumn: U } = S.range;
  9398. for (let P = y; P <= x; P++)
  9399. for (let A = T; A <= U; A++) {
  9400. const j = (l = (u = w.getCell(P, A)) == null ? void 0 : u.selectionProtection) == null ? void 0 : l[0];
  9401. if ((j == null ? void 0 : j[_.View]) === !1)
  9402. return !1;
  9403. }
  9404. }
  9405. return !0;
  9406. }
  9407. }
  9408. if (o) {
  9409. const c = N(this._univerInstanceService);
  9410. if (!c)
  9411. return !1;
  9412. const d = e.unitId || c.unitId, h = e.subUnitId || c.subUnitId, g = this._rangeProtectionRuleModel.getSubunitRuleList(d, h).filter((p) => p.ranges.some((C) => k.intersects(C, o))).map((p) => new Pe(d, h, p.permissionId).id);
  9413. if (!this._permissionService.composePermission(g).every((p) => p.value))
  9414. return !1;
  9415. }
  9416. return !0;
  9417. }
  9418. };
  9419. Nn = Vc([
  9420. $e(0, E),
  9421. $e(1, M),
  9422. $e(2, Fe),
  9423. $e(3, L(F)),
  9424. $e(4, L(de)),
  9425. $e(5, L(Ye)),
  9426. $e(6, L(Ke)),
  9427. $e(7, L($i)),
  9428. $e(8, Ss),
  9429. $e(9, Ps)
  9430. ], Nn);
  9431. var Hc = Object.defineProperty, Bc = Object.getOwnPropertyDescriptor, Fc = (n, e, t, o) => {
  9432. for (var s = o > 1 ? void 0 : o ? Bc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  9433. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  9434. return o && s && Hc(e, t, s), s;
  9435. }, no = (n, e) => (t, o) => e(t, o, n);
  9436. let ht = class extends ae {
  9437. constructor(e, t, o) {
  9438. super();
  9439. R(this, "_cellRuleCache", /* @__PURE__ */ new Map());
  9440. R(this, "_permissionIdCache", /* @__PURE__ */ new Map());
  9441. R(this, "_cellInfoCache", /* @__PURE__ */ new Map());
  9442. // {unitId:{subUnitId:{[row/col]:{permissionId1:{edit:true},permissionId2:{edit:true},permissionId3:{edit:false}}}}}
  9443. R(this, "_rowInfoCache", /* @__PURE__ */ new Map());
  9444. R(this, "_colInfoCache", /* @__PURE__ */ new Map());
  9445. this._ruleModel = e, this._permissionService = t, this._univerInstanceService = o, this._initUpdateCellRuleCache(), this._initUpdateCellInfoCache(), this._initUpdateRowColInfoCache(), this._initCache();
  9446. }
  9447. _initCache() {
  9448. this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => {
  9449. e.getSheets().forEach((t) => {
  9450. const o = e.getUnitId(), s = t.getSheetId();
  9451. this.reBuildCache(o, s);
  9452. });
  9453. });
  9454. }
  9455. _initUpdateCellInfoCache() {
  9456. this._permissionService.permissionPointUpdate$.pipe(
  9457. Ho((e) => e.type === D.SelectRange),
  9458. ao((e) => e)
  9459. ).subscribe((e) => {
  9460. const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s);
  9461. if (!r)
  9462. return;
  9463. const i = this._ruleModel.getRule(o, t, r);
  9464. if (!i)
  9465. return;
  9466. const a = this._ensureCellInfoMap(o, t);
  9467. i.ranges.forEach((u) => {
  9468. const { startRow: l, endRow: c, startColumn: d, endColumn: h } = u;
  9469. for (let m = l; m <= c; m++)
  9470. for (let g = d; g <= h; g++)
  9471. a.delete(`${m}-${g}`);
  9472. });
  9473. }), this._ruleModel.ruleChange$.subscribe((e) => {
  9474. var r;
  9475. const { unitId: t, subUnitId: o } = e, s = this._ensureCellInfoMap(t, o);
  9476. e.rule.ranges.forEach((i) => {
  9477. K.foreach(i, (a, u) => {
  9478. s.delete(`${a}-${u}`);
  9479. });
  9480. }), e.type === "set" && ((r = e.oldRule) == null || r.ranges.forEach((i) => {
  9481. K.foreach(i, (a, u) => {
  9482. this._cellInfoCache.delete(`${a}-${u}`);
  9483. });
  9484. }));
  9485. });
  9486. }
  9487. _initUpdateCellRuleCache() {
  9488. this._ruleModel.ruleChange$.subscribe((e) => {
  9489. const { type: t } = e;
  9490. t === "add" ? this._addCellRuleCache(e) : t === "delete" ? this._deleteCellRuleCache(e) : (this._deleteCellRuleCache({ ...e, rule: e.oldRule }), this._addCellRuleCache(e));
  9491. });
  9492. }
  9493. _ensureRuleMap(e, t) {
  9494. let o = this._cellRuleCache.get(e);
  9495. o || (o = /* @__PURE__ */ new Map(), this._cellRuleCache.set(e, o));
  9496. let s = o.get(t);
  9497. return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
  9498. }
  9499. _ensureCellInfoMap(e, t) {
  9500. let o = this._cellInfoCache.get(e);
  9501. o || (o = /* @__PURE__ */ new Map(), this._cellInfoCache.set(e, o));
  9502. let s = o.get(t);
  9503. return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
  9504. }
  9505. _ensureRowColInfoMap(e, t, o) {
  9506. let s = o === "row" ? this._rowInfoCache.get(e) : this._colInfoCache.get(e);
  9507. s || (s = /* @__PURE__ */ new Map(), o === "row" ? this._rowInfoCache.set(e, s) : this._colInfoCache.set(e, s));
  9508. let r = s.get(t);
  9509. return r || (r = /* @__PURE__ */ new Map(), s.set(t, r)), r;
  9510. }
  9511. _addCellRuleCache(e) {
  9512. const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t);
  9513. s.ranges.forEach((i) => {
  9514. const { startRow: a, endRow: u, startColumn: l, endColumn: c } = i;
  9515. for (let d = a; d <= u; d++)
  9516. for (let h = l; h <= c; h++)
  9517. r.set(`${d}-${h}`, s.id);
  9518. }), this._permissionIdCache.set(s.permissionId, s.id);
  9519. }
  9520. _deleteCellRuleCache(e) {
  9521. const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t), i = this._ensureCellInfoMap(o, t);
  9522. s.ranges.forEach((a) => {
  9523. const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a;
  9524. for (let h = u; h <= l; h++)
  9525. for (let m = c; m <= d; m++)
  9526. r.delete(`${h}-${m}`), i.delete(`${h}-${m}`);
  9527. }), this._permissionIdCache.delete(s.permissionId);
  9528. }
  9529. _getSelectionActions(e, t, o) {
  9530. var l, c, d, h, m, g, f, p, C, S, I, w;
  9531. 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 : !0, r = (g = (m = this._permissionService.getPermissionPoint((h = new Io(e, t, o.permissionId)) == null ? void 0 : h.id)) == null ? void 0 : m.value) != null ? g : !0, i = (C = (p = this._permissionService.getPermissionPoint((f = new Vr(e, t, o.permissionId)) == null ? void 0 : f.id)) == null ? void 0 : p.value) != null ? C : !1, 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 : !1;
  9532. return {
  9533. [_.Edit]: s,
  9534. [_.View]: r,
  9535. [_.ManageCollaborator]: i,
  9536. [_.Delete]: a
  9537. };
  9538. }
  9539. reBuildCache(e, t) {
  9540. const o = this._ensureRuleMap(e, t), s = this._ensureCellInfoMap(e, t);
  9541. o.clear(), s.clear();
  9542. const r = this._ensureRowColInfoMap(e, t, "row"), i = this._ensureRowColInfoMap(e, t, "col");
  9543. r.clear(), i.clear(), this._ruleModel.getSubunitRuleList(e, t).forEach((a) => {
  9544. const u = this._getSelectionActions(e, t, a), l = {
  9545. ...u,
  9546. ruleId: a.id,
  9547. ranges: a.ranges
  9548. };
  9549. a.ranges.forEach((c) => {
  9550. const { startRow: d, endRow: h, startColumn: m, endColumn: g } = c;
  9551. for (let f = d; f <= h; f++) {
  9552. const p = r.get(`${f}`);
  9553. p ? p.set(a.id, u) : r.set(`${f}`, /* @__PURE__ */ new Map([[a.id, u]]));
  9554. for (let C = m; C <= g; C++) {
  9555. o.set(`${f}-${C}`, a.id), s.set(`${f}-${C}`, l);
  9556. const S = i.get(`${C}`);
  9557. S ? S.set(a.id, u) : i.set(`${C}`, /* @__PURE__ */ new Map([[a.id, u]]));
  9558. }
  9559. }
  9560. }), this._permissionIdCache.set(a.permissionId, a.id);
  9561. });
  9562. }
  9563. getRowPermissionInfo(e, t, o, s) {
  9564. var a;
  9565. const r = (a = this._rowInfoCache.get(e)) == null ? void 0 : a.get(t);
  9566. if (!r)
  9567. return !0;
  9568. const i = r.get(`${o}`);
  9569. return i ? s.every((u) => {
  9570. for (const l of i.values())
  9571. if (l[u] === !1)
  9572. return !1;
  9573. return !0;
  9574. }) : !0;
  9575. }
  9576. getColPermissionInfo(e, t, o, s) {
  9577. var a;
  9578. const r = (a = this._colInfoCache.get(e)) == null ? void 0 : a.get(t);
  9579. if (!r)
  9580. return !0;
  9581. const i = r.get(`${o}`);
  9582. return i ? s.every((u) => {
  9583. for (const l of i.values())
  9584. if (l[u] === !1)
  9585. return !1;
  9586. return !0;
  9587. }) : !0;
  9588. }
  9589. _initUpdateRowColInfoCache() {
  9590. this._permissionService.permissionPointUpdate$.pipe(
  9591. Ho((e) => e.type === D.SelectRange),
  9592. ao((e) => e)
  9593. ).subscribe({
  9594. next: (e) => {
  9595. const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s);
  9596. if (!r)
  9597. return;
  9598. const i = this._ruleModel.getRule(o, t, r);
  9599. if (!i)
  9600. return;
  9601. const a = this._ensureRowColInfoMap(o, t, "row"), u = this._ensureRowColInfoMap(o, t, "col"), l = this._getSelectionActions(o, t, i);
  9602. i.ranges.forEach((c) => {
  9603. const { startRow: d, endRow: h, startColumn: m, endColumn: g } = c;
  9604. for (let f = d; f <= h; f++) {
  9605. const p = a.get(`${f}`);
  9606. p ? p.set(r, l) : a.set(`${f}`, /* @__PURE__ */ new Map([[r, l]]));
  9607. for (let C = m; C <= g; C++) {
  9608. const S = u.get(`${C}`);
  9609. S ? S.set(r, l) : u.set(`${C}`, /* @__PURE__ */ new Map([[r, l]]));
  9610. }
  9611. }
  9612. });
  9613. }
  9614. }), this._ruleModel.ruleChange$.subscribe((e) => {
  9615. if (e.type === "delete") {
  9616. const { unitId: t, subUnitId: o, rule: s } = e, r = this._ensureRowColInfoMap(t, o, "row"), i = this._ensureRowColInfoMap(t, o, "col");
  9617. s.ranges.forEach((a) => {
  9618. const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a;
  9619. for (let h = u; h <= l; h++) {
  9620. const m = r.get(`${h}`);
  9621. m == null || m.delete(s.id);
  9622. for (let g = c; g <= d; g++) {
  9623. const f = i.get(`${g}`);
  9624. f == null || f.delete(s.id);
  9625. }
  9626. }
  9627. });
  9628. }
  9629. });
  9630. }
  9631. getCellInfo(e, t, o, s) {
  9632. var l, c;
  9633. const r = this._ensureCellInfoMap(e, t), i = r.get(`${o}-${s}`);
  9634. if (i)
  9635. return i;
  9636. const a = (c = (l = this._cellRuleCache.get(e)) == null ? void 0 : l.get(t)) == null ? void 0 : c.get(`${o}-${s}`);
  9637. if (!a)
  9638. return;
  9639. const u = this._ruleModel.getRule(e, t, a);
  9640. if (u) {
  9641. const h = {
  9642. ...this._getSelectionActions(e, t, u),
  9643. ruleId: a,
  9644. ranges: u.ranges
  9645. };
  9646. return r.set(`${o}-${s}`, h), h;
  9647. }
  9648. }
  9649. deleteUnit(e) {
  9650. this._cellRuleCache.delete(e), this._cellInfoCache.delete(e), this._rowInfoCache.delete(e), this._colInfoCache.delete(e);
  9651. const t = this._univerInstanceService.getUnit(e);
  9652. t == null || t.getSheets().forEach((o) => {
  9653. const s = o.getSheetId();
  9654. this._ruleModel.getSubunitRuleList(e, s).forEach((r) => {
  9655. this._permissionIdCache.delete(r.permissionId);
  9656. });
  9657. });
  9658. }
  9659. };
  9660. ht = Fc([
  9661. no(0, L(de)),
  9662. no(1, L(Fe)),
  9663. no(2, L(M))
  9664. ], ht);
  9665. var jc = Object.defineProperty, Gc = Object.getOwnPropertyDescriptor, zc = (n, e, t, o) => {
  9666. for (var s = o > 1 ? void 0 : o ? Gc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  9667. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  9668. return o && s && jc(e, t, s), s;
  9669. }, Ee = (n, e) => (t, o) => e(t, o, n);
  9670. let On = class extends ae {
  9671. constructor(n, e, t, o, s, r, i, a, u, l, c) {
  9672. 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();
  9673. }
  9674. async _initRangePermissionFromSnapshot() {
  9675. const n = async (e) => {
  9676. const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map();
  9677. if (s.forEach((i) => {
  9678. const a = i.getSheetId();
  9679. this._rangeProtectionRuleModel.getSubunitRuleList(o, a).forEach((u) => {
  9680. r.set(u.permissionId, u), t.push({
  9681. objectID: u.permissionId,
  9682. unitID: o,
  9683. objectType: D.SelectRange,
  9684. actions: it
  9685. });
  9686. });
  9687. }), !t.length) {
  9688. this._rangeProtectionRuleModel.changeRuleInitState(!0);
  9689. return;
  9690. }
  9691. this._authzIoService.batchAllowed(t).then((i) => {
  9692. i.forEach((a) => {
  9693. const u = r.get(a.objectID);
  9694. u && Ie().forEach((l) => {
  9695. const c = new l(o, u.subUnitId, a.objectID), d = c.subType, h = a.actions.find((m) => m.action === d);
  9696. (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed);
  9697. });
  9698. }), this._rangeProtectionRuleModel.changeRuleInitState(!0);
  9699. });
  9700. };
  9701. await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((e) => n(e))), this._rangeProtectionRuleModel.changeRuleInitState(!0);
  9702. }
  9703. _initRangePermissionChange() {
  9704. this.disposeWithMe(
  9705. this._rangeProtectionRuleModel.ruleChange$.subscribe((n) => {
  9706. n.type !== "delete" ? this._authzIoService.allowed({
  9707. objectID: n.rule.permissionId,
  9708. unitID: n.unitId,
  9709. objectType: D.SelectRange,
  9710. actions: it
  9711. }).then((e) => {
  9712. Ie().forEach((t) => {
  9713. if (n.type === "set") {
  9714. const { rule: a, oldRule: u } = n;
  9715. if (a.permissionId === (u == null ? void 0 : u.permissionId))
  9716. return;
  9717. }
  9718. const o = n.rule, s = new t(o.unitId, o.subUnitId, o.permissionId), r = s.subType, i = e.find((a) => a.action === r);
  9719. i && this._permissionService.updatePermissionPoint(s.id, i.allowed);
  9720. }), this._rangeProtectionRuleModel.ruleRefresh(n.rule.permissionId);
  9721. }) : this._rangeProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId), [...ke()].forEach((t) => {
  9722. const o = new t(n.unitId, n.subUnitId);
  9723. this._permissionService.updatePermissionPoint(o.id, o.value);
  9724. }));
  9725. })
  9726. );
  9727. }
  9728. async initWorkbookPermissionChange(n) {
  9729. var t;
  9730. const e = n || ((t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET)) == null ? void 0 : t.getUnitId());
  9731. e && this._authzIoService.allowed({
  9732. objectID: e,
  9733. objectType: D.Workbook,
  9734. unitID: e,
  9735. actions: fl
  9736. }).then((o) => {
  9737. en().forEach((s) => {
  9738. const r = new s(e), i = r.subType, a = o.find((u) => u.action === i);
  9739. a && this._permissionService.updatePermissionPoint(r.id, a.allowed);
  9740. });
  9741. });
  9742. }
  9743. async _initWorkbookPermissionFromSnapshot() {
  9744. await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((n) => this.initWorkbookPermissionChange(n.getUnitId())));
  9745. }
  9746. _initWorksheetPermissionChange() {
  9747. this.disposeWithMe(
  9748. this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => {
  9749. n.type !== "delete" ? this._authzIoService.allowed({
  9750. objectID: n.rule.permissionId,
  9751. unitID: n.unitId,
  9752. objectType: D.Worksheet,
  9753. actions: it
  9754. }).then((e) => {
  9755. we().forEach((t) => {
  9756. const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s);
  9757. r && this._permissionService.updatePermissionPoint(o.id, r.allowed);
  9758. }), this._worksheetProtectionRuleModel.ruleRefresh(n.rule.permissionId);
  9759. }) : ([...we(), ...ke()].forEach((e) => {
  9760. const t = new e(n.unitId, n.subUnitId);
  9761. this._permissionService.updatePermissionPoint(t.id, !0);
  9762. }), this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId));
  9763. })
  9764. );
  9765. }
  9766. _initWorksheetPermissionPointsChange() {
  9767. this.disposeWithMe(
  9768. this._worksheetProtectionPointRuleModel.pointChange$.subscribe((n) => {
  9769. this._authzIoService.allowed({
  9770. objectID: n.permissionId,
  9771. unitID: n.unitId,
  9772. objectType: D.Worksheet,
  9773. actions: eo
  9774. }).then((e) => {
  9775. ke().forEach((t) => {
  9776. const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s);
  9777. r && this._permissionService.updatePermissionPoint(o.id, r.allowed);
  9778. });
  9779. });
  9780. })
  9781. );
  9782. }
  9783. async _initWorksheetPermissionFromSnapshot() {
  9784. const n = async (e) => {
  9785. const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map();
  9786. if (s.forEach((i) => {
  9787. const a = i.getSheetId(), u = this._worksheetProtectionRuleModel.getRule(o, a);
  9788. u && (r.set(u.permissionId, u), t.push({
  9789. objectID: u.permissionId,
  9790. unitID: o,
  9791. objectType: D.Worksheet,
  9792. actions: it
  9793. }));
  9794. const l = this._worksheetProtectionPointRuleModel.getRule(o, a);
  9795. l && (r.set(l.permissionId, l), t.push({
  9796. objectID: l.permissionId,
  9797. unitID: o,
  9798. objectType: D.Worksheet,
  9799. actions: eo
  9800. }));
  9801. }), !t.length) {
  9802. this._worksheetProtectionRuleModel.changeRuleInitState(!0);
  9803. return;
  9804. }
  9805. this._authzIoService.batchAllowed(t).then((i) => {
  9806. i.forEach((a) => {
  9807. const u = r.get(a.objectID);
  9808. u && [...we(), ...ke()].forEach((l) => {
  9809. const c = new l(o, u.subUnitId), d = c.subType, h = a.actions.find((m) => m.action === d);
  9810. (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed);
  9811. });
  9812. }), this._worksheetProtectionRuleModel.changeRuleInitState(!0);
  9813. });
  9814. };
  9815. await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((e) => n(e))), this._worksheetProtectionRuleModel.changeRuleInitState(!0);
  9816. }
  9817. _initUserChange() {
  9818. this.disposeWithMe(
  9819. // 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.
  9820. this._userManagerService.currentUser$.pipe(Ts(1)).subscribe(() => {
  9821. const n = this._permissionService.getAllPermissionPoint();
  9822. this._permissionService.clearPermissionMap(), this._worksheetProtectionRuleModel.changeRuleInitState(!1), this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((t) => {
  9823. const o = t.getUnitId();
  9824. en().forEach((s) => {
  9825. let r = new s(o);
  9826. n.has(r.id) && (r = n.get(r.id)), this._permissionService.addPermissionPoint(r);
  9827. }), t.getSheets().forEach((s) => {
  9828. const r = s.getSheetId();
  9829. [...we(), ...ke()].forEach((a) => {
  9830. let u = new a(o, r);
  9831. n.has(u.id) && (u = n.get(u.id)), this._permissionService.addPermissionPoint(u);
  9832. }), this._rangeProtectionRuleModel.getSubunitRuleList(o, r).forEach((a) => {
  9833. Ie().forEach((u) => {
  9834. let l = new u(o, r, a.permissionId);
  9835. n.has(l.id) && (l = n.get(l.id)), this._permissionService.addPermissionPoint(l);
  9836. });
  9837. });
  9838. }), this._initWorkbookPermissionFromSnapshot(), this._initWorksheetPermissionFromSnapshot(), this._initRangePermissionFromSnapshot();
  9839. });
  9840. })
  9841. );
  9842. }
  9843. refreshPermission(n, e) {
  9844. const t = this._worksheetProtectionRuleModel.getTargetByPermissionId(n, e);
  9845. let o = !1;
  9846. if (t) {
  9847. const [i, a] = t;
  9848. this._authzIoService.allowed({
  9849. objectID: e,
  9850. unitID: n,
  9851. objectType: D.Worksheet,
  9852. actions: it
  9853. }).then((u) => {
  9854. let l = "";
  9855. we().forEach((c) => {
  9856. var g;
  9857. const d = new c(n, a), h = d.subType, m = u.find((f) => f.action === h);
  9858. m && (((g = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g.value) !== m.allowed && (o = !0), this._permissionService.updatePermissionPoint(d.id, m.allowed), l += `${m.action}_${m.allowed}`);
  9859. }), this._worksheetProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n);
  9860. });
  9861. }
  9862. const s = this._worksheetProtectionPointRuleModel.getTargetByPermissionId(n, e);
  9863. if (s) {
  9864. const [i, a] = s;
  9865. this._authzIoService.allowed({
  9866. objectID: e,
  9867. unitID: n,
  9868. objectType: D.Worksheet,
  9869. actions: eo
  9870. }).then((u) => {
  9871. ke().forEach((l) => {
  9872. var m;
  9873. const c = new l(n, a), d = c.subType, h = u.find((g) => g.action === d);
  9874. h && (((m = this._permissionService.getPermissionPoint(c.id)) == null ? void 0 : m.value) !== h.allowed && (o = !0), this._permissionService.updatePermissionPoint(c.id, h.allowed));
  9875. }), o && this._undoRedoService.clearUndoRedo(n);
  9876. });
  9877. }
  9878. const r = this._rangeProtectionRuleModel.getTargetByPermissionId(n, e);
  9879. if (r) {
  9880. const [i, a] = r;
  9881. this._authzIoService.allowed({
  9882. objectID: e,
  9883. unitID: n,
  9884. objectType: D.SelectRange,
  9885. actions: it
  9886. }).then((u) => {
  9887. let l = "";
  9888. Ie().forEach((c) => {
  9889. var g;
  9890. const d = new c(n, a, e), h = d.subType, m = u.find((f) => f.action === h);
  9891. m && (((g = this._permissionService.getPermissionPoint(d.id)) == null ? void 0 : g.value) !== m.allowed && (o = !0), this._permissionService.updatePermissionPoint(d.id, m.allowed), l += `${m.action}_${m.allowed}`);
  9892. }), this._rangeProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n);
  9893. });
  9894. }
  9895. }
  9896. _refreshPermissionByCollaCreate() {
  9897. this.disposeWithMe(
  9898. this._commandService.onCommandExecuted((n, e) => {
  9899. if (e != null && e.fromCollab && (n.id === Ne.id || n.id === ct.id || n.id === Ao.id)) {
  9900. const t = n.params;
  9901. this._undoRedoService.clearUndoRedo(t.unitId);
  9902. }
  9903. })
  9904. );
  9905. }
  9906. };
  9907. On = zc([
  9908. Ee(0, M),
  9909. Ee(1, Fe),
  9910. Ee(2, vi),
  9911. Ee(3, L(de)),
  9912. Ee(4, L(Ye)),
  9913. Ee(5, L(Ii)),
  9914. Ee(6, L(un)),
  9915. Ee(7, L(V)),
  9916. Ee(8, L(W)),
  9917. Ee(9, L(E)),
  9918. Ee(10, L(ht))
  9919. ], On);
  9920. var Kc = Object.defineProperty, Jc = Object.getOwnPropertyDescriptor, Yc = (n, e, t, o) => {
  9921. for (var s = o > 1 ? void 0 : o ? Jc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  9922. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  9923. return o && s && Kc(e, t, s), s;
  9924. }, hn = (n, e) => (t, o) => e(t, o, n);
  9925. let Dn = class extends ae {
  9926. constructor(n, e, t, o) {
  9927. super(), this._permissionService = n, this._worksheetProtectionRuleModel = e, this._sheetInterceptorService = t, this._rangeProtectionCache = o, this._initViewModelByRangeInterceptor(), this._initViewModelBySheetInterceptor();
  9928. }
  9929. _initViewModelByRangeInterceptor() {
  9930. this.disposeWithMe(this._sheetInterceptorService.intercept(
  9931. et.CELL_CONTENT,
  9932. {
  9933. // permissions are placed at a high level to prioritize whether to filter subsequent renderings.
  9934. priority: 999,
  9935. effect: me.Value | me.Style,
  9936. handler: (n = {}, e, t) => {
  9937. const { unitId: o, subUnitId: s, row: r, col: i } = e, a = this._rangeProtectionCache.getCellInfo(o, s, r, i);
  9938. if (a) {
  9939. const u = a[_.View] === !1, l = { ...n, selectionProtection: [a] };
  9940. return u ? (delete l.s, delete l.v, delete l.p, l) : t(l);
  9941. }
  9942. return t(n);
  9943. }
  9944. }
  9945. ));
  9946. }
  9947. _initViewModelBySheetInterceptor() {
  9948. this.disposeWithMe(this._sheetInterceptorService.intercept(
  9949. et.CELL_CONTENT,
  9950. {
  9951. // permissions are placed at a high level to prioritize whether to filter subsequent renderings.
  9952. priority: 999,
  9953. effect: me.Value | me.Style,
  9954. handler: (n = {}, e, t) => {
  9955. var i, a, u, l, c;
  9956. const { unitId: o, subUnitId: s } = e, r = this._worksheetProtectionRuleModel.getRule(o, s);
  9957. if (r != null && r.permissionId) {
  9958. const d = [{
  9959. [_.View]: (a = (i = this._permissionService.getPermissionPoint(new Hn(o, s).id)) == null ? void 0 : i.value) != null ? a : !1,
  9960. [_.Edit]: (l = (u = this._permissionService.getPermissionPoint(new Te(o, s).id)) == null ? void 0 : u.value) != null ? l : !1
  9961. }], h = !((c = d[0]) != null && c[_.View]), m = { ...n, hasWorksheetRule: !0, selectionProtection: d };
  9962. return h ? (delete m.s, delete m.v, delete m.p, m) : t(m);
  9963. }
  9964. return t(n);
  9965. }
  9966. }
  9967. ));
  9968. }
  9969. };
  9970. Dn = Yc([
  9971. hn(0, Fe),
  9972. hn(1, L(Ye)),
  9973. hn(2, L(V)),
  9974. hn(3, L(ht))
  9975. ], Dn);
  9976. var Xc = Object.defineProperty, qc = Object.getOwnPropertyDescriptor, Zc = (n, e, t, o) => {
  9977. for (var s = o > 1 ? void 0 : o ? qc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  9978. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  9979. return o && s && Xc(e, t, s), s;
  9980. }, cs = (n, e) => (t, o) => e(t, o, n);
  9981. let tn = class {
  9982. constructor(n, e) {
  9983. R(this, "_cache", new Mi(1e4));
  9984. this._selectionProtectionRuleModel = n, this._permissionService = e, this._init();
  9985. }
  9986. _init() {
  9987. this._permissionService.permissionPointUpdate$.pipe(
  9988. Fo((n) => n.type === D.SelectRange),
  9989. Fo((n) => Ie().some((e) => n instanceof e)),
  9990. Ki((n) => n)
  9991. ).subscribe((n) => {
  9992. const e = this._selectionProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId);
  9993. for (const t of e)
  9994. t.permissionId === n.permissionId && t.ranges.forEach((o) => {
  9995. K.foreach(o, (s, r) => {
  9996. const i = this._createKey(n.unitId, n.subUnitId, s, r);
  9997. this._cache.delete(i);
  9998. });
  9999. });
  10000. }), this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => {
  10001. var e;
  10002. n.rule.ranges.forEach((t) => {
  10003. K.foreach(t, (o, s) => {
  10004. const r = this._createKey(n.unitId, n.subUnitId, o, s);
  10005. this._cache.delete(r);
  10006. });
  10007. }), n.type === "set" && ((e = n.oldRule) == null || e.ranges.forEach((t) => {
  10008. K.foreach(t, (o, s) => {
  10009. const r = this._createKey(n.unitId, n.subUnitId, o, s);
  10010. this._cache.delete(r);
  10011. });
  10012. }));
  10013. });
  10014. }
  10015. _createKey(n, e, t, o) {
  10016. return `${n}_${e}_${t}_${o}`;
  10017. }
  10018. getCellInfo(n, e, t, o) {
  10019. const s = this._selectionProtectionRuleModel.getSubunitRuleList(n, e), r = [];
  10020. if (!s || !s.length)
  10021. return r;
  10022. const i = this._createKey(n, e, t, o), a = this._cache.get(i);
  10023. if (a)
  10024. return a;
  10025. const u = [];
  10026. for (const l of s)
  10027. if (l.ranges.some((c) => c.startRow <= t && c.endRow >= t && c.startColumn <= o && c.endColumn >= o)) {
  10028. const c = Ie().reduce((d, h) => {
  10029. var f;
  10030. const m = new h(n, e, l.permissionId), g = this._permissionService.getPermissionPoint(m.id);
  10031. return d[m.subType] = (f = g == null ? void 0 : g.value) != null ? f : m.value, d;
  10032. }, {});
  10033. u.push({ ...c, ruleId: l.id, ranges: l.ranges });
  10034. }
  10035. return this._cache.set(i, u), u;
  10036. }
  10037. clear() {
  10038. this._cache.clear();
  10039. }
  10040. };
  10041. tn = Zc([
  10042. cs(0, L(de)),
  10043. cs(1, L(Fe))
  10044. ], tn);
  10045. const ds = fo("univer.exclusive-range-service");
  10046. class Qc extends ae {
  10047. constructor() {
  10048. super(...arguments);
  10049. /**
  10050. * Exclusive range data structure is as follows: unitId -> sheetId -> feature -> range
  10051. */
  10052. R(this, "_exclusiveRanges", /* @__PURE__ */ new Map());
  10053. R(this, "_exclusiveRangesChange$", new Le());
  10054. R(this, "exclusiveRangesChange$", this._exclusiveRangesChange$.asObservable());
  10055. }
  10056. _ensureUnitMap(t) {
  10057. return this._exclusiveRanges.has(t) || this._exclusiveRanges.set(t, /* @__PURE__ */ new Map()), this._exclusiveRanges.get(t);
  10058. }
  10059. _ensureSubunitMap(t, o) {
  10060. const s = this._ensureUnitMap(t);
  10061. return s.has(o) || s.set(o, /* @__PURE__ */ new Map()), s.get(o);
  10062. }
  10063. _ensureFeature(t, o, s) {
  10064. const r = this._ensureSubunitMap(t, o);
  10065. return r.has(s) || r.set(s, []), r.get(s);
  10066. }
  10067. addExclusiveRange(t, o, s, r) {
  10068. const i = this._ensureFeature(t, o, s);
  10069. i.push(...r), this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: i.map((a) => a.range) });
  10070. }
  10071. getExclusiveRanges(t, o, s) {
  10072. var r, i;
  10073. return (i = (r = this._exclusiveRanges.get(t)) == null ? void 0 : r.get(o)) == null ? void 0 : i.get(s);
  10074. }
  10075. clearExclusiveRanges(t, o, s) {
  10076. const r = this.getExclusiveRanges(t, o, s);
  10077. 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, []);
  10078. }
  10079. clearExclusiveRangesByGroupId(t, o, s, r) {
  10080. const i = this.getExclusiveRanges(t, o, s);
  10081. this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (i == null ? void 0 : i.map((u) => u.range)) || [] });
  10082. const a = this.getExclusiveRanges(t, o, s);
  10083. if (a) {
  10084. const u = a.filter((l) => l.groupId !== r);
  10085. this._exclusiveRanges.get(t).get(o).set(s, u);
  10086. }
  10087. }
  10088. getInterestGroupId(t) {
  10089. const o = [];
  10090. return t.forEach((s) => {
  10091. var l;
  10092. const r = s.range, { unitId: i, sheetId: a } = r;
  10093. if (!i || !a) return;
  10094. const u = (l = this._exclusiveRanges.get(i)) == null ? void 0 : l.get(a);
  10095. if (u)
  10096. for (const c of u.keys()) {
  10097. const d = u.get(c);
  10098. if (d) {
  10099. for (const h of d)
  10100. if (k.intersects(r, h.range)) {
  10101. o.push(c);
  10102. break;
  10103. }
  10104. }
  10105. }
  10106. }), o;
  10107. }
  10108. }
  10109. var ed = Object.defineProperty, td = Object.getOwnPropertyDescriptor, nd = (n, e, t, o) => {
  10110. for (var s = o > 1 ? void 0 : o ? td(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  10111. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  10112. return o && s && ed(e, t, s), s;
  10113. }, oo = (n, e) => (t, o) => e(t, o, n);
  10114. let co = class extends ae {
  10115. constructor(n, e, t) {
  10116. super(), this._resourceManagerService = n, this._univerInstanceService = e, this._logService = t;
  10117. }
  10118. getValue(n, e, t, o) {
  10119. const s = this._univerInstanceService.getUniverSheetInstance(n);
  10120. if (!s)
  10121. return;
  10122. const r = s == null ? void 0 : s.getSheetBySheetId(e);
  10123. if (!r)
  10124. return;
  10125. const i = s.getStyles(), a = r.getCellRaw(t, o);
  10126. if (a != null && a.s) {
  10127. const u = i.get(a.s);
  10128. if (u != null && u.n)
  10129. return u.n;
  10130. }
  10131. return null;
  10132. }
  10133. deleteValues(n, e, t) {
  10134. const o = this._univerInstanceService.getUniverSheetInstance(n);
  10135. if (!o)
  10136. return;
  10137. const s = o == null ? void 0 : o.getSheetBySheetId(e);
  10138. if (!s)
  10139. return;
  10140. const r = o.getStyles();
  10141. t.forEach((i) => {
  10142. K.foreach(i, (a, u) => {
  10143. const l = s.getCellRaw(a, u);
  10144. if (!l)
  10145. return;
  10146. const c = l == null ? void 0 : l.s, h = { ...c && r.get(c) || {} };
  10147. delete h.n;
  10148. const m = r.setValue(h);
  10149. l.s = m;
  10150. });
  10151. });
  10152. }
  10153. setValues(n, e, t) {
  10154. const o = this._univerInstanceService.getUniverSheetInstance(n);
  10155. if (!o)
  10156. return;
  10157. const s = o == null ? void 0 : o.getSheetBySheetId(e);
  10158. if (!s)
  10159. return;
  10160. const r = o.getStyles(), i = s.getCellMatrix();
  10161. t.forEach((a) => {
  10162. a.ranges.forEach((u) => {
  10163. K.foreach(u, (l, c) => {
  10164. const d = s.getCellRaw(l, c);
  10165. if (d) {
  10166. const m = { ...r.getStyleByCell(d) || {}, n: { pattern: a.pattern } }, g = r.setValue(m);
  10167. d.s = g, a.pattern === ks && (d.t = se.STRING);
  10168. } else {
  10169. const h = { n: { pattern: a.pattern } }, m = r.setValue(h);
  10170. m && i.setValue(l, c, { s: m });
  10171. }
  10172. });
  10173. });
  10174. });
  10175. }
  10176. };
  10177. co = nd([
  10178. oo(0, nn),
  10179. oo(1, M),
  10180. oo(2, Es)
  10181. ], co);
  10182. var od = Object.defineProperty, sd = Object.getOwnPropertyDescriptor, rd = (n, e, t, o) => {
  10183. for (var s = o > 1 ? void 0 : o ? sd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  10184. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  10185. return o && s && od(e, t, s), s;
  10186. }, Qe = (n, e) => (t, o) => e(t, o, n);
  10187. const hs = [je.id, qe.id, De.id, Be.id], ms = [ot.id, st.id];
  10188. let An = class extends ae {
  10189. constructor(e, t, o, s, r, i, a, u) {
  10190. super();
  10191. R(this, "disposableCollection", new jt());
  10192. 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();
  10193. }
  10194. _onRefRangeChange() {
  10195. const e = (o, s) => {
  10196. const r = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
  10197. if (!r || !(r == null ? void 0 : r.getSheetBySheetId(s)))
  10198. return;
  10199. this.disposableCollection.dispose();
  10200. const a = (l) => this.refRangeHandle(l, o, s);
  10201. this._selectionProtectionRuleModel.getSubunitRuleList(o, s).reduce((l, c) => [...l, ...c.ranges], []).forEach((l) => {
  10202. this.disposableCollection.add(this._refRangeService.registerRefRange(l, a, o, s));
  10203. });
  10204. };
  10205. this.disposeWithMe(
  10206. this._commandService.onCommandExecuted((o) => {
  10207. if (o.id === Ar.id) {
  10208. const s = o.params, r = s.subUnitId, i = s.unitId;
  10209. if (!r || !i)
  10210. return;
  10211. e(i, r);
  10212. }
  10213. if (o.id === he.id || o.id === Ne.id) {
  10214. const s = o.params, r = s.subUnitId, i = s.unitId;
  10215. if (!r || !i)
  10216. return;
  10217. e(i, r);
  10218. }
  10219. })
  10220. );
  10221. const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
  10222. if (t) {
  10223. const o = t.getActiveSheet();
  10224. if (!o) return;
  10225. e(t.getUnitId(), o.getSheetId());
  10226. }
  10227. }
  10228. refRangeHandle(e, t, o) {
  10229. switch (e.id) {
  10230. case Fn.id:
  10231. return this._getRefRangeMutationsByMoveRows(e.params, t, o);
  10232. case jn.id:
  10233. return this._getRefRangeMutationsByMoveCols(e.params, t, o);
  10234. case mt.id:
  10235. return this._getRefRangeMutationsByInsertRows(e.params, t, o);
  10236. case gt.id:
  10237. return this._getRefRangeMutationsByInsertCols(e.params, t, o);
  10238. case zn.id:
  10239. return this._getRefRangeMutationsByDeleteCols(e.params, t, o);
  10240. case Gn.id:
  10241. return this._getRefRangeMutationsByDeleteRows(e.params, t, o);
  10242. }
  10243. return { redos: [], undos: [] };
  10244. }
  10245. _getRefRangeMutationsByDeleteCols(e, t, o) {
  10246. const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => k.intersects(a, e.range))), r = e.range;
  10247. if (s.length) {
  10248. const i = [], a = [];
  10249. return s.forEach((u) => {
  10250. const l = O.deepClone(u), c = l.ranges.reduce((d, h) => {
  10251. if (k.intersects(h, r)) {
  10252. const m = O.deepClone(h), { startColumn: g, endColumn: f } = r;
  10253. if (g <= m.startColumn && f >= m.endColumn)
  10254. return d;
  10255. g >= m.startColumn && f <= m.endColumn ? m.endColumn -= f - g + 1 : g < m.startColumn ? (m.startColumn = g, m.endColumn -= f - g + 1) : f > m.endColumn && (m.endColumn = g - 1), this._checkIsRightRange(m) && d.push(m);
  10256. }
  10257. return d;
  10258. }, []);
  10259. 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] } }));
  10260. }), { redos: i, undos: a };
  10261. }
  10262. return { undos: [], redos: [] };
  10263. }
  10264. _getRefRangeMutationsByDeleteRows(e, t, o) {
  10265. const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => k.intersects(a, e.range))), r = e.range;
  10266. if (s.length) {
  10267. const i = [], a = [];
  10268. return s.forEach((u) => {
  10269. const l = O.deepClone(u), c = l.ranges.reduce((d, h) => {
  10270. if (k.intersects(h, r)) {
  10271. const m = O.deepClone(h), { startRow: g, endRow: f } = r;
  10272. if (g <= m.startRow && f >= m.endRow)
  10273. return d;
  10274. g >= m.startRow && f <= m.endRow ? m.endRow -= f - g + 1 : g < m.startRow ? (m.startRow = g, m.endRow -= f - g + 1) : f > m.endRow && (m.endRow = g - 1), this._checkIsRightRange(m) && d.push(m);
  10275. }
  10276. return d;
  10277. }, []);
  10278. 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 } });
  10279. }), { redos: i, undos: a };
  10280. }
  10281. return { undos: [], redos: [] };
  10282. }
  10283. _getRefRangeMutationsByInsertCols(e, t, o) {
  10284. 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));
  10285. if (i.length) {
  10286. const a = [], u = [];
  10287. return i.forEach((l) => {
  10288. const c = O.deepClone(l);
  10289. let d = !1;
  10290. c.ranges.forEach((h) => {
  10291. s > h.startColumn && s <= h.endColumn && (h.endColumn += r, d = !0);
  10292. }), 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 } }));
  10293. }), { redos: a, undos: u };
  10294. }
  10295. return { undos: [], redos: [] };
  10296. }
  10297. _getRefRangeMutationsByInsertRows(e, t, o) {
  10298. 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));
  10299. if (i.length) {
  10300. const a = [], u = [];
  10301. return i.forEach((l) => {
  10302. const c = O.deepClone(l);
  10303. let d = !1;
  10304. c.ranges.forEach((h) => {
  10305. s > h.startRow && s <= h.endRow && (h.endRow += r, d = !0);
  10306. }), 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 } }));
  10307. }), { redos: a, undos: u };
  10308. }
  10309. return { undos: [], redos: [] };
  10310. }
  10311. _getRefRangeMutationsByMoveRows(e, t, o) {
  10312. 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));
  10313. if (a.length) {
  10314. const u = [], l = [];
  10315. return a.forEach((c) => {
  10316. const d = O.deepClone(c), m = e.fromRange.startRow;
  10317. let g = !1;
  10318. d.ranges.forEach((f) => {
  10319. r > f.startRow && r <= f.endRow && (m < f.startRow && (f.startRow = f.startRow - i, f.endRow = f.endRow - i), f.endRow += i, g = !0);
  10320. }), g && (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 } }));
  10321. }), { redos: u, undos: l };
  10322. }
  10323. return { undos: [], redos: [] };
  10324. }
  10325. _getRefRangeMutationsByMoveCols(e, t, o) {
  10326. 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));
  10327. if (a.length) {
  10328. const u = [], l = [];
  10329. return a.forEach((c) => {
  10330. const d = O.deepClone(c), m = e.fromRange.startColumn;
  10331. let g = !1;
  10332. d.ranges.forEach((f) => {
  10333. r > f.startColumn && r <= f.endColumn && (m < f.startColumn && (f.startColumn = f.startColumn - i, f.endColumn = f.endColumn - i), f.endColumn += i, g = !0);
  10334. }), g && (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 } }));
  10335. }), { redos: u, undos: l };
  10336. }
  10337. return { undos: [], redos: [] };
  10338. }
  10339. _correctPermissionRange() {
  10340. this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
  10341. if (ms.includes(e.id)) {
  10342. if (!e.params) return;
  10343. const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
  10344. if (!t) return;
  10345. const o = t.getSheetBySheetId(e.params.subUnitId);
  10346. if (!o) return;
  10347. 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;
  10348. this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((f) => {
  10349. f.ranges.forEach((C) => {
  10350. let { startRow: S, endRow: I, startColumn: w, endColumn: b } = C;
  10351. k.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);
  10352. });
  10353. }), this.disposableCollection.dispose();
  10354. const { unitId: d, subUnitId: h } = e.params, m = (f) => this.refRangeHandle(f, d, h);
  10355. this._selectionProtectionRuleModel.getSubunitRuleList(d, h).reduce((f, p) => [...f, ...p.ranges], []).forEach((f) => {
  10356. this.disposableCollection.add(this._refRangeService.registerRefRange(f, m, d, h));
  10357. }), this._selectionProtectionRenderModel.clear();
  10358. }
  10359. if (hs.includes(e.id)) {
  10360. const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
  10361. if (!t) return;
  10362. const o = t.getSheetBySheetId(e.params.subUnitId);
  10363. if (!o) return;
  10364. const s = e.params;
  10365. if (!s) return;
  10366. 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;
  10367. this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((p) => {
  10368. p.ranges.forEach((S) => {
  10369. let { startRow: I, endRow: w, startColumn: b, endColumn: y } = S;
  10370. 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);
  10371. });
  10372. }), this.disposableCollection.dispose();
  10373. const { unitId: h, subUnitId: m } = e.params, g = (p) => this.refRangeHandle(p, h, m);
  10374. this._selectionProtectionRuleModel.getSubunitRuleList(h, m).reduce((p, C) => [...p, ...C.ranges], []).forEach((p) => {
  10375. this.disposableCollection.add(this._refRangeService.registerRefRange(p, g, h, m));
  10376. }), this._selectionProtectionRenderModel.clear();
  10377. }
  10378. }));
  10379. }
  10380. _checkIsRightRange(e) {
  10381. return e.startRow <= e.endRow && e.startColumn <= e.endColumn;
  10382. }
  10383. _initReBuildCache() {
  10384. this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
  10385. if (hs.includes(e.id) || ms.includes(e.id)) {
  10386. const { unitId: t, subUnitId: o } = e.params;
  10387. this._rangeProtectionCache.reBuildCache(t, o);
  10388. }
  10389. }));
  10390. }
  10391. _initRemoveSheet() {
  10392. this._sheetInterceptorService.interceptCommand(
  10393. {
  10394. getMutations: (e) => {
  10395. const t = [], o = [], s = [], r = [];
  10396. if (e.id === ko.id) {
  10397. const i = e.params, a = [], u = [];
  10398. this._rangeProtectionRuleModel.getSubunitRuleList(i.unitId, i.subUnitId).forEach((l) => {
  10399. a.push(l.id), u.push(l);
  10400. }), 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 } }));
  10401. }
  10402. return {
  10403. redos: o,
  10404. undos: t,
  10405. preRedos: s,
  10406. preUndos: r
  10407. };
  10408. }
  10409. }
  10410. );
  10411. }
  10412. };
  10413. An = rd([
  10414. Qe(0, L(de)),
  10415. Qe(1, L(M)),
  10416. Qe(2, E),
  10417. Qe(3, L(_t)),
  10418. Qe(4, L(tn)),
  10419. Qe(5, L(ht)),
  10420. Qe(6, L(V)),
  10421. Qe(7, L(de))
  10422. ], An);
  10423. var id = Object.defineProperty, ad = Object.getOwnPropertyDescriptor, ud = (n, e, t, o) => {
  10424. for (var s = o > 1 ? void 0 : o ? ad(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  10425. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  10426. return o && s && id(e, t, s), s;
  10427. }, Dt = (n, e) => (t, o) => e(t, o, n);
  10428. const ld = "SHEET_RANGE_PROTECTION_PLUGIN";
  10429. let xn = class extends ae {
  10430. constructor(n, e, t, o, s) {
  10431. super(), this._selectionProtectionRuleModel = n, this._permissionService = e, this._resourceManagerService = t, this._selectionProtectionCache = o, this._univerInstanceService = s, this._initSnapshot(), this._initRuleChange();
  10432. }
  10433. _initRuleChange() {
  10434. this.disposeWithMe(
  10435. this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => {
  10436. switch (n.type) {
  10437. case "add": {
  10438. Ie().forEach((e) => {
  10439. const t = new e(n.unitId, n.subUnitId, n.rule.permissionId);
  10440. this._permissionService.addPermissionPoint(t);
  10441. });
  10442. break;
  10443. }
  10444. case "delete": {
  10445. Ie().forEach((e) => {
  10446. const t = new e(n.unitId, n.subUnitId, n.rule.permissionId);
  10447. this._permissionService.deletePermissionPoint(t.id);
  10448. });
  10449. break;
  10450. }
  10451. case "set": {
  10452. n.oldRule.permissionId !== n.rule.permissionId && Ie().forEach((e) => {
  10453. const t = new e(n.unitId, n.subUnitId, n.oldRule.permissionId);
  10454. this._permissionService.deletePermissionPoint(t.id);
  10455. const o = new e(n.unitId, n.subUnitId, n.rule.permissionId);
  10456. this._permissionService.addPermissionPoint(o);
  10457. });
  10458. break;
  10459. }
  10460. }
  10461. })
  10462. );
  10463. }
  10464. _initSnapshot() {
  10465. const n = (t) => {
  10466. const s = this._selectionProtectionRuleModel.toObject()[t];
  10467. return s ? JSON.stringify(s) : "";
  10468. }, e = (t) => {
  10469. if (!t)
  10470. return {};
  10471. try {
  10472. return JSON.parse(t);
  10473. } catch {
  10474. return {};
  10475. }
  10476. };
  10477. this.disposeWithMe(
  10478. this._resourceManagerService.registerPluginResource({
  10479. toJson: n,
  10480. parseJson: e,
  10481. pluginName: ld,
  10482. businesses: [Sn.UNIVER_SHEET],
  10483. onLoad: (t, o) => {
  10484. const s = this._selectionProtectionRuleModel.toObject();
  10485. s[t] = o, this._selectionProtectionRuleModel.fromObject(s);
  10486. const r = [];
  10487. Object.keys(o).forEach((i) => {
  10488. const a = o[i];
  10489. this._selectionProtectionRuleModel.getSubunitRuleList(t, i).forEach((u) => {
  10490. r.push({
  10491. objectID: u.permissionId,
  10492. unitID: t,
  10493. objectType: D.SelectRange,
  10494. actions: it
  10495. });
  10496. }), a.forEach((u) => {
  10497. Ie().forEach((l) => {
  10498. const c = new l(t, i, u.permissionId);
  10499. c.value = !1, this._permissionService.addPermissionPoint(c);
  10500. });
  10501. }), this._selectionProtectionCache.reBuildCache(t, i);
  10502. });
  10503. },
  10504. onUnLoad: (t) => {
  10505. this._selectionProtectionCache.deleteUnit(t);
  10506. }
  10507. })
  10508. );
  10509. }
  10510. };
  10511. xn = ud([
  10512. Dt(0, L(de)),
  10513. Dt(1, L(Fe)),
  10514. Dt(2, L(nn)),
  10515. Dt(3, L(ht)),
  10516. Dt(4, L(M))
  10517. ], xn);
  10518. var cd = Object.defineProperty, dd = Object.getOwnPropertyDescriptor, hd = (n, e, t, o) => {
  10519. for (var s = o > 1 ? void 0 : o ? dd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  10520. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  10521. return o && s && cd(e, t, s), s;
  10522. }, At = (n, e) => (t, o) => e(t, o, n);
  10523. let $n = class extends ae {
  10524. constructor(n, e, t, o, s) {
  10525. super(), this._permissionService = n, this._univerInstanceService = e, this._rangeProtectionRuleModel = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointModel = s, this._init();
  10526. }
  10527. _init() {
  10528. const n = (e) => {
  10529. const t = e.getUnitId();
  10530. en().forEach((o) => {
  10531. const s = new o(t);
  10532. this._permissionService.addPermissionPoint(s);
  10533. });
  10534. };
  10535. this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => {
  10536. n(e);
  10537. }), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((e) => {
  10538. n(e);
  10539. })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe((e) => {
  10540. const t = e.getUnitId();
  10541. e.getSheets().forEach((o) => {
  10542. const s = o.getSheetId();
  10543. this._rangeProtectionRuleModel.getSubunitRuleList(t, s).forEach((i) => {
  10544. [...Ie()].forEach((a) => {
  10545. const u = new a(t, s, i.permissionId);
  10546. this._permissionService.deletePermissionPoint(u.id);
  10547. });
  10548. }), [...we(), ...ke()].forEach((i) => {
  10549. const a = new i(t, s);
  10550. this._permissionService.deletePermissionPoint(a.id);
  10551. });
  10552. }), en().forEach((o) => {
  10553. const s = new o(t);
  10554. this._permissionService.deletePermissionPoint(s.id);
  10555. }), this._rangeProtectionRuleModel.deleteUnitModel(t), this._worksheetProtectionPointModel.deleteUnitModel(t), this._worksheetProtectionRuleModel.deleteUnitModel(t);
  10556. }));
  10557. }
  10558. };
  10559. $n = hd([
  10560. At(0, L(Fe)),
  10561. At(1, L(M)),
  10562. At(2, L(de)),
  10563. At(3, L(Ye)),
  10564. At(4, L(un))
  10565. ], $n);
  10566. var md = Object.defineProperty, gd = Object.getOwnPropertyDescriptor, fd = (n, e, t, o) => {
  10567. for (var s = o > 1 ? void 0 : o ? gd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  10568. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  10569. return o && s && md(e, t, s), s;
  10570. }, Rd = (n, e) => (t, o) => e(t, o, n);
  10571. let ho = class extends ae {
  10572. constructor(n) {
  10573. super(), this._sheetRangeThemeModel = n;
  10574. }
  10575. /**
  10576. * Register a custom range theme style.
  10577. * @param {string} unitId Which unit to register the range theme style.
  10578. * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register.
  10579. */
  10580. registerRangeTheme(n, e) {
  10581. this._sheetRangeThemeModel.registerRangeThemeStyle(n, e);
  10582. }
  10583. /**
  10584. * Get custom register themes name list
  10585. * @returns {string[]} The list of custom register themes name.
  10586. */
  10587. getALLRegisterThemes() {
  10588. return this._sheetRangeThemeModel.getALLRegisteredTheme();
  10589. }
  10590. /**
  10591. * Register range theme style to the range.
  10592. * @param {string} themeName The defined theme name.
  10593. * @param {IRangeThemeRangeInfo} rangeInfo The range info to apply the theme style.
  10594. */
  10595. registerRangeThemeStyle(n, e) {
  10596. this._sheetRangeThemeModel.registerRangeThemeRule(n, e);
  10597. }
  10598. /**
  10599. * Get applied range theme style name.
  10600. * @param {IRangeThemeRangeInfo} rangeInfo The range info to get the applied theme style.
  10601. * @returns {string | undefined} The applied theme style name or not exist.
  10602. */
  10603. getAppliedRangeThemeStyle(n) {
  10604. return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(n);
  10605. }
  10606. /**
  10607. * Get registered build-in range theme style
  10608. */
  10609. getRegisteredRangeThemes() {
  10610. return this._sheetRangeThemeModel.getRegisteredRangeThemes();
  10611. }
  10612. };
  10613. ho = fd([
  10614. Rd(0, L(He))
  10615. ], ho);
  10616. var Qr = Object.defineProperty, pd = Object.getOwnPropertyDescriptor, Cd = (n, e, t) => e in n ? Qr(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Sd = (n, e, t, o) => {
  10617. for (var s = o > 1 ? void 0 : o ? pd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
  10618. (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
  10619. return o && s && Qr(e, t, s), s;
  10620. }, gs = (n, e) => (t, o) => e(t, o, n), ei = (n, e, t) => Cd(n, typeof e != "symbol" ? e + "" : e, t);
  10621. const wd = "SHEET_PLUGIN";
  10622. let Wn = class extends bi {
  10623. constructor(n = ts, e, t) {
  10624. super(), this._config = n, this._injector = e, this._configService = t;
  10625. const { ...o } = yi(
  10626. {},
  10627. ts,
  10628. this._config
  10629. );
  10630. this._configService.setConfig(Kl, o), this._initConfig(), this._initDependencies();
  10631. }
  10632. _initConfig() {
  10633. var n, e, t;
  10634. (n = this._config) != null && n.onlyRegisterFormulaRelatedMutations && this._configService.setConfig(Kr, !0), (e = this._config) != null && e.isRowStylePrecedeColumnStyle && this._configService.setConfig(Ei, !0), (t = this._config) != null && t.autoHeightForMergedCells && this._configService.setConfig(Ui, !0);
  10635. }
  10636. _initDependencies() {
  10637. var e;
  10638. const n = [
  10639. // services
  10640. [kt],
  10641. [F],
  10642. [_t],
  10643. [$n],
  10644. [wt, { useClass: co }],
  10645. [V],
  10646. [ho],
  10647. // controllers
  10648. [yn],
  10649. [Tn],
  10650. [kn],
  10651. [Un],
  10652. // permission
  10653. [bn],
  10654. [Ye],
  10655. [un],
  10656. [Dn],
  10657. [On],
  10658. [Nn],
  10659. // range theme
  10660. [He],
  10661. // range protection
  10662. [tn],
  10663. [de],
  10664. [ht],
  10665. [An],
  10666. [xn],
  10667. [ds, {
  10668. useClass: Qc,
  10669. deps: [F]
  10670. }]
  10671. ];
  10672. (e = this._config) != null && e.notExecuteFormula || n.push([En]), Pi(this._injector, Ti(n, this._config.override)), ln(this._injector, [
  10673. [V],
  10674. [xn],
  10675. [ds]
  10676. ]);
  10677. }
  10678. onStarting() {
  10679. ln(this._injector, [
  10680. [yn],
  10681. [Tn],
  10682. [$n],
  10683. [bn],
  10684. [Dn]
  10685. ]);
  10686. }
  10687. onRendered() {
  10688. ln(this._injector, [
  10689. [wt],
  10690. [On]
  10691. ]);
  10692. }
  10693. onReady() {
  10694. ln(this._injector, [
  10695. [En],
  10696. [Un],
  10697. [He],
  10698. [kn],
  10699. [tn],
  10700. [An],
  10701. [_t],
  10702. [Nn]
  10703. ]);
  10704. }
  10705. };
  10706. ei(Wn, "pluginName", wd);
  10707. ei(Wn, "type", B.UNIVER_SHEET);
  10708. Wn = Sd([
  10709. _i(Bi),
  10710. gs(1, L(Ro)),
  10711. gs(2, Us)
  10712. ], Wn);
  10713. var Id = /* @__PURE__ */ ((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 || {}), vd = /* @__PURE__ */ ((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 || {});
  10714. const gh = [
  10715. nt.id,
  10716. Oe.id,
  10717. Br.id,
  10718. tt.id,
  10719. an.id,
  10720. ot.id,
  10721. st.id,
  10722. Xt.id,
  10723. qt.id,
  10724. Qt.id,
  10725. Zt.id,
  10726. je.id,
  10727. qe.id,
  10728. De.id,
  10729. Be.id,
  10730. Ft.id,
  10731. Vt.id
  10732. ], fh = [
  10733. Q.id,
  10734. dt.id,
  10735. oe.id,
  10736. ne.id,
  10737. In.id,
  10738. Bt.id,
  10739. Ht.id,
  10740. Lt.id,
  10741. zt.id,
  10742. Kt.id
  10743. ];
  10744. function Rh(n) {
  10745. switch (n.id) {
  10746. case "sheet.mutation.set-range-values": {
  10747. const e = n.params;
  10748. return e.cellValue ? [{
  10749. unitId: e.unitId,
  10750. subUnitId: e.subUnitId,
  10751. range: new G(e.cellValue).getDataRange()
  10752. }] : [];
  10753. }
  10754. case "sheet.mutation.move-range": {
  10755. const e = n.params;
  10756. return [{
  10757. unitId: e.unitId,
  10758. subUnitId: e.from.subUnitId,
  10759. range: new G(e.from.value).getRange()
  10760. }, {
  10761. unitId: e.unitId,
  10762. subUnitId: e.to.subUnitId,
  10763. range: new G(e.to.value).getRange()
  10764. }];
  10765. }
  10766. case "sheet.mutation.remove-worksheet-merge": {
  10767. const e = n.params;
  10768. return e.ranges.map((t) => ({
  10769. unitId: e.unitId,
  10770. subUnitId: e.subUnitId,
  10771. range: t
  10772. }));
  10773. }
  10774. case "sheet.mutation.add-worksheet-merge": {
  10775. const e = n.params;
  10776. return e.ranges.map((t) => ({
  10777. unitId: e.unitId,
  10778. subUnitId: e.subUnitId,
  10779. range: t
  10780. }));
  10781. }
  10782. case "sheet.mutation.reorder-range": {
  10783. const e = n.params;
  10784. return [{
  10785. unitId: e.unitId,
  10786. subUnitId: e.subUnitId,
  10787. range: e.range
  10788. }];
  10789. }
  10790. case "sheet.mutation.set-worksheet-default-style": {
  10791. const e = n.params;
  10792. return [{
  10793. unitId: e.unitId,
  10794. subUnitId: e.subUnitId,
  10795. range: { startRow: 0, endRow: Number.MAX_SAFE_INTEGER, startColumn: 0, endColumn: Number.MAX_SAFE_INTEGER }
  10796. }];
  10797. }
  10798. case "sheet.mutation.set-row-data": {
  10799. const e = n.params, t = Object.keys(e.rowData).map(Number);
  10800. return t.length === 0 ? [] : [{
  10801. unitId: e.unitId,
  10802. subUnitId: e.subUnitId,
  10803. range: {
  10804. startRow: Math.min(...t),
  10805. endRow: Math.max(...t),
  10806. startColumn: 0,
  10807. endColumn: Number.MAX_SAFE_INTEGER
  10808. }
  10809. }];
  10810. }
  10811. case "sheet.mutation.set-col-data": {
  10812. const e = n.params, t = Object.keys(e.columnData).map(Number);
  10813. return t.length === 0 ? [] : [{
  10814. unitId: e.unitId,
  10815. subUnitId: e.subUnitId,
  10816. range: {
  10817. startRow: 0,
  10818. endRow: Number.MAX_SAFE_INTEGER,
  10819. startColumn: Math.min(...t),
  10820. endColumn: Math.max(...t)
  10821. }
  10822. }];
  10823. }
  10824. case "sheet.mutation.set-worksheet-range-theme-style":
  10825. case "sheet.mutation.delete-worksheet-range-theme-style": {
  10826. const e = n.params;
  10827. return [{
  10828. unitId: e.unitId,
  10829. subUnitId: e.subUnitId,
  10830. range: e.range
  10831. }];
  10832. }
  10833. default:
  10834. return [];
  10835. }
  10836. }
  10837. function ph(n) {
  10838. switch (n.id) {
  10839. case "sheet.mutation.set-worksheet-row-height":
  10840. case "sheet.mutation.set-worksheet-row-is-auto-height":
  10841. case "sheet.mutation.set-worksheet-row-auto-height": {
  10842. const e = n.params;
  10843. return e.ranges.map((t) => ({
  10844. unitId: e.unitId,
  10845. subUnitId: e.subUnitId,
  10846. range: {
  10847. ...t,
  10848. rangeType: H.ROW
  10849. }
  10850. }));
  10851. }
  10852. case "sheet.mutation.set-worksheet-col-width": {
  10853. const e = n.params;
  10854. return e.ranges.map((t) => ({
  10855. unitId: e.unitId,
  10856. subUnitId: e.subUnitId,
  10857. range: {
  10858. ...t,
  10859. rangeType: H.COLUMN
  10860. }
  10861. }));
  10862. }
  10863. case "sheet.mutation.move-rows":
  10864. case "sheet.mutation.move-columns": {
  10865. const e = n.params;
  10866. return [{
  10867. unitId: e.unitId,
  10868. subUnitId: e.subUnitId,
  10869. range: e.targetRange
  10870. }, {
  10871. unitId: e.unitId,
  10872. subUnitId: e.subUnitId,
  10873. range: e.sourceRange
  10874. }];
  10875. }
  10876. case "sheet.mutation.set-col-hidden":
  10877. case "sheet.mutation.set-col-visible": {
  10878. const e = n.params;
  10879. return e.ranges.map((t) => ({
  10880. unitId: e.unitId,
  10881. subUnitId: e.subUnitId,
  10882. range: {
  10883. ...t,
  10884. rangeType: H.COLUMN
  10885. }
  10886. }));
  10887. }
  10888. case "sheet.mutation.set-row-hidden":
  10889. case "sheet.mutation.set-row-visible": {
  10890. const e = n.params;
  10891. return e.ranges.map((t) => ({
  10892. unitId: e.unitId,
  10893. subUnitId: e.subUnitId,
  10894. range: {
  10895. ...t,
  10896. rangeType: H.ROW
  10897. }
  10898. }));
  10899. }
  10900. case "sheet.mutation.insert-col": {
  10901. const e = n.params;
  10902. return [{
  10903. unitId: e.unitId,
  10904. subUnitId: e.subUnitId,
  10905. range: {
  10906. ...e.range,
  10907. rangeType: H.COLUMN
  10908. }
  10909. }];
  10910. }
  10911. case "sheet.mutation.insert-row": {
  10912. const e = n.params;
  10913. return [{
  10914. unitId: e.unitId,
  10915. subUnitId: e.subUnitId,
  10916. range: {
  10917. ...e.range,
  10918. rangeType: H.ROW
  10919. }
  10920. }];
  10921. }
  10922. case "sheet.mutation.remove-col": {
  10923. const e = n.params;
  10924. return [{
  10925. unitId: e.unitId,
  10926. subUnitId: e.subUnitId,
  10927. range: {
  10928. ...e.range,
  10929. rangeType: H.COLUMN
  10930. }
  10931. }];
  10932. }
  10933. case "sheet.mutation.remove-row": {
  10934. const e = n.params;
  10935. return [{
  10936. unitId: e.unitId,
  10937. subUnitId: e.subUnitId,
  10938. range: {
  10939. ...e.range,
  10940. rangeType: H.ROW
  10941. }
  10942. }];
  10943. }
  10944. case "sheet.mutation.toggle-gridlines":
  10945. case "sheet.mutation.set-gridlines-color":
  10946. return [];
  10947. default:
  10948. return [];
  10949. }
  10950. }
  10951. const Ch = 1.5, Sh = "rgba(255, 255, 255, 0.01)";
  10952. function wh(n) {
  10953. const { rangeWithCoord: e, primaryWithCoord: t, style: o } = n, s = {
  10954. range: {
  10955. startRow: e.startRow,
  10956. startColumn: e.startColumn,
  10957. endRow: e.endRow,
  10958. endColumn: e.endColumn,
  10959. rangeType: e.rangeType,
  10960. unitId: e.unitId,
  10961. sheetId: e.sheetId
  10962. },
  10963. primary: null,
  10964. style: o
  10965. };
  10966. return t != null && (s.primary = Md(t)), s;
  10967. }
  10968. function Md(n) {
  10969. const { actualRow: e, actualColumn: t, isMerged: o, isMergedMainCell: s } = n, { startRow: r, startColumn: i, endRow: a, endColumn: u } = n.mergeInfo;
  10970. return {
  10971. actualRow: e,
  10972. actualColumn: t,
  10973. isMerged: o,
  10974. isMergedMainCell: s,
  10975. startRow: r,
  10976. startColumn: i,
  10977. endRow: a,
  10978. endColumn: u
  10979. };
  10980. }
  10981. const Ih = (n, e, t) => {
  10982. const s = n.get(F).getCurrentSelections(), { value: r, selections: i, unitId: a, subUnitId: u } = e;
  10983. if (s) {
  10984. const c = s[(s == null ? void 0 : s.length) - 1].primary;
  10985. if (c) {
  10986. const { actualColumn: d, actualRow: h } = c;
  10987. let { startRow: m, startColumn: g, endRow: f, endColumn: p } = i[i.length - 1];
  10988. if (r === ge.COLUMNS) {
  10989. const w = t.find((b) => b.startColumn === d && b.endColumn === d && h === b.startRow);
  10990. w && (p = w.endColumn, m = w.startRow, f = w.endRow);
  10991. } else if (r === ge.ROWS) {
  10992. const w = t.find((b) => b.startRow === h && b.endRow === h && d === b.startColumn);
  10993. w && (f = w.endRow, g = w.startColumn, p = w.endColumn);
  10994. }
  10995. const C = {
  10996. startRow: m,
  10997. startColumn: g,
  10998. endRow: f,
  10999. endColumn: p,
  11000. actualRow: h,
  11001. actualColumn: d,
  11002. isMerged: !0,
  11003. isMergedMainCell: m === h && g === d
  11004. }, S = s.map((w, b, y) => ({
  11005. range: w.range,
  11006. style: null,
  11007. primary: b === y.length - 1 ? C : null
  11008. })), I = {
  11009. unitId: a,
  11010. subUnitId: u,
  11011. type: Ce.ONLY_SET,
  11012. selections: S
  11013. };
  11014. return {
  11015. id: re.id,
  11016. params: I
  11017. };
  11018. }
  11019. return null;
  11020. }
  11021. return null;
  11022. }, vh = (n, e) => {
  11023. const o = n.get(F).getCurrentSelections(), { unitId: s, subUnitId: r } = e;
  11024. if (o && o[(o == null ? void 0 : o.length) - 1].primary) {
  11025. const u = {
  11026. unitId: s,
  11027. subUnitId: r,
  11028. type: Ce.ONLY_SET,
  11029. selections: [...o]
  11030. };
  11031. return {
  11032. id: re.id,
  11033. params: u
  11034. };
  11035. }
  11036. return null;
  11037. };
  11038. function fs(n) {
  11039. return n == null ? !1 : n.v !== void 0 && n.v !== null && n.v !== "" || n.p !== void 0;
  11040. }
  11041. function Yn(n, e) {
  11042. return n && n.spanAnchor ? fs(e.getValue(n.spanAnchor.startRow, n.spanAnchor.startColumn)) : fs(n);
  11043. }
  11044. function _d(n, e, t, o, s) {
  11045. const r = n.getCellMatrix(), i = n.getSpanModel().getMergedCellRange(e, t, o, s), a = new G();
  11046. return r.forValue((u, l) => {
  11047. const c = r.getValue(u, l);
  11048. c && a.setValue(u, l, c);
  11049. }), i.forEach((u) => {
  11050. const { startColumn: l, startRow: c, endColumn: d, endRow: h } = u;
  11051. ki(c, h, l, d).forEach((m, g) => {
  11052. m === c && g === l && a.setValue(m, g, {
  11053. ...r.getValue(m, g),
  11054. spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d }
  11055. }), (m !== c || g !== l) && (a.realDeleteValue(m, g), a.setValue(m, g, {
  11056. spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d }
  11057. }));
  11058. });
  11059. }), a;
  11060. }
  11061. function bd(n, e, t, o) {
  11062. const { startRow: s, startColumn: r, endRow: i } = n;
  11063. let a = null, u = !1;
  11064. for (let l = s; l <= i; l++) {
  11065. const c = e.getValue(l, r - t);
  11066. if (u = u || Yn(c, e), !o && u)
  11067. break;
  11068. c && c.spanAnchor && (a ? a = {
  11069. startRow: Math.min(c.spanAnchor.startRow, a.startRow),
  11070. startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
  11071. endRow: Math.max(c.spanAnchor.endRow, a.endRow),
  11072. endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
  11073. } : a = {
  11074. startRow: c.spanAnchor.startRow,
  11075. startColumn: c.spanAnchor.startColumn,
  11076. endRow: c.spanAnchor.endRow,
  11077. endColumn: c.spanAnchor.endColumn
  11078. });
  11079. }
  11080. return u ? (n.startColumn = n.startColumn - t, {
  11081. spanAnchor: a,
  11082. hasValue: !0,
  11083. range: n
  11084. }) : {
  11085. spanAnchor: null,
  11086. hasValue: !1,
  11087. range: n
  11088. };
  11089. }
  11090. function yd(n, e, t, o) {
  11091. const { startRow: s, endColumn: r, endRow: i } = n;
  11092. let a = null, u = !1;
  11093. for (let l = s; l <= i; l++) {
  11094. const c = e.getValue(l, r + t);
  11095. if (u = u || Yn(c, e), !o && u)
  11096. break;
  11097. c && c.spanAnchor && (a ? a = {
  11098. startRow: Math.min(c.spanAnchor.startRow, a.startRow),
  11099. startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
  11100. endRow: Math.max(c.spanAnchor.endRow, a.endRow),
  11101. endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
  11102. } : a = {
  11103. startRow: c.spanAnchor.startRow,
  11104. startColumn: c.spanAnchor.startColumn,
  11105. endRow: c.spanAnchor.endRow,
  11106. endColumn: c.spanAnchor.endColumn
  11107. });
  11108. }
  11109. return u ? (n.endColumn = n.endColumn + t, {
  11110. spanAnchor: a,
  11111. hasValue: !0,
  11112. range: n
  11113. }) : {
  11114. spanAnchor: null,
  11115. hasValue: !1,
  11116. range: n
  11117. };
  11118. }
  11119. function Ed(n, e, t, o) {
  11120. const { startRow: s, startColumn: r, endColumn: i } = n;
  11121. let a = null, u = !1;
  11122. for (let l = r; l <= i; l++) {
  11123. const c = e.getValue(s - t, l);
  11124. if (u = u || Yn(c, e), !o && u)
  11125. break;
  11126. c && c.spanAnchor && (a ? a = {
  11127. startRow: Math.min(c.spanAnchor.startRow, a.startRow),
  11128. startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
  11129. endRow: Math.max(c.spanAnchor.endRow, a.endRow),
  11130. endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
  11131. } : a = {
  11132. startRow: c.spanAnchor.startRow,
  11133. startColumn: c.spanAnchor.startColumn,
  11134. endRow: c.spanAnchor.endRow,
  11135. endColumn: c.spanAnchor.endColumn
  11136. });
  11137. }
  11138. return u ? (n.startRow = n.startRow - t, {
  11139. spanAnchor: a,
  11140. hasValue: !0,
  11141. range: n
  11142. }) : {
  11143. spanAnchor: null,
  11144. hasValue: !1,
  11145. range: n
  11146. };
  11147. }
  11148. function Ud(n, e, t, o) {
  11149. const { startColumn: s, endColumn: r, endRow: i } = n;
  11150. let a = null, u = !1;
  11151. for (let l = s; l <= r; l++) {
  11152. const c = e.getValue(i + t, l);
  11153. if (u = u || Yn(c, e), !o && u)
  11154. break;
  11155. c && c.spanAnchor && (a ? a = {
  11156. startRow: Math.min(c.spanAnchor.startRow, a.startRow),
  11157. startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
  11158. endRow: Math.max(c.spanAnchor.endRow, a.endRow),
  11159. endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
  11160. } : a = {
  11161. startRow: c.spanAnchor.startRow,
  11162. startColumn: c.spanAnchor.startColumn,
  11163. endRow: c.spanAnchor.endRow,
  11164. endColumn: c.spanAnchor.endColumn
  11165. });
  11166. }
  11167. return u ? (n.endRow = n.endRow + t, {
  11168. spanAnchor: a,
  11169. hasValue: !0,
  11170. range: n
  11171. }) : {
  11172. spanAnchor: null,
  11173. hasValue: !1,
  11174. range: n
  11175. };
  11176. }
  11177. function Mh(n, e, t) {
  11178. 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;
  11179. let d = !0, h = { ...n };
  11180. const m = [];
  11181. for (; d; ) {
  11182. if (d = !1, l && h.startRow !== 0) {
  11183. const { hasValue: g, range: f, spanAnchor: p } = Ed(h, r, 1, i);
  11184. if (p && m.push(p), g) {
  11185. h = f, d = !0;
  11186. continue;
  11187. }
  11188. }
  11189. if (c && h.endRow !== o - 1) {
  11190. const { hasValue: g, range: f, spanAnchor: p } = Ud(h, r, 1, i);
  11191. if (p && m.push(p), g) {
  11192. h = f, d = !0;
  11193. continue;
  11194. }
  11195. }
  11196. if (a && h.startColumn !== 0) {
  11197. const { hasValue: g, range: f, spanAnchor: p } = bd(h, r, 1, i);
  11198. if (p && m.push(p), g) {
  11199. h = f, d = !0;
  11200. continue;
  11201. }
  11202. }
  11203. if (u && h.endColumn !== s - 1) {
  11204. const { hasValue: g, range: f, spanAnchor: p } = yd(h, r, 1, i);
  11205. if (p && m.push(p), g) {
  11206. h = f, d = !0;
  11207. continue;
  11208. }
  11209. }
  11210. }
  11211. return m.length > 0 && (h = k.union(h, ...m)), h;
  11212. }
  11213. const ti = (n, e, t, o = 1, s = !0, r = !0) => {
  11214. const i = K.transformRange(n, e), { startRow: a, endRow: u } = i;
  11215. let l = t.startRow - o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
  11216. for (; !e.getRowVisible(l) || !d; )
  11217. l--, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
  11218. if (l >= a)
  11219. return { ...t, startRow: l, endRow: l };
  11220. if (r) {
  11221. const h = { ...t, startRow: u, endRow: u };
  11222. return oi(n, e, h, o, s, !1);
  11223. }
  11224. }, ni = (n, e, t, o = 1, s = !0, r = !0) => {
  11225. const i = K.transformRange(n, e), { startRow: a, endRow: u } = i;
  11226. let l = t.endRow + o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
  11227. for (; !e.getRowVisible(l) || !d; )
  11228. l++, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
  11229. if (l <= u)
  11230. return { ...t, startRow: l, endRow: l };
  11231. if (r) {
  11232. const h = { ...t, startRow: a, endRow: a };
  11233. return si(n, e, h, o, s, !1);
  11234. }
  11235. }, oi = (n, e, t, o = 1, s = !0, r = !0) => {
  11236. const i = K.transformRange(n, e), { startColumn: a, endColumn: u } = i;
  11237. let l = t.startColumn - o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
  11238. for (; !e.getColVisible(l) || !d; )
  11239. l--, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
  11240. if (l >= a)
  11241. return { ...t, startColumn: l, endColumn: l };
  11242. if (r) {
  11243. const h = { ...t, startColumn: u, endColumn: u };
  11244. return ti(n, e, h, o, s, !1);
  11245. }
  11246. }, si = (n, e, t, o = 1, s = !0, r = !0) => {
  11247. const i = K.transformRange(n, e), { startColumn: a, endColumn: u } = i;
  11248. let l = t.endColumn + o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
  11249. for (; !e.getColVisible(l) || !d; )
  11250. l++, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
  11251. if (l <= u)
  11252. return { ...t, endColumn: l, startColumn: l };
  11253. if (r) {
  11254. const h = { ...t, startColumn: a, endColumn: a };
  11255. return ni(n, e, h, o, s, !1);
  11256. }
  11257. };
  11258. function mn(n, e, t) {
  11259. let o = null;
  11260. return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = {
  11261. actualRow: r,
  11262. actualColumn: i,
  11263. startRow: r,
  11264. startColumn: i,
  11265. isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0,
  11266. isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0,
  11267. endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0),
  11268. endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0),
  11269. rangeType: H.NORMAL
  11270. }, !1)), o || {
  11271. actualColumn: e,
  11272. actualRow: n,
  11273. startRow: n,
  11274. startColumn: e,
  11275. endRow: n,
  11276. endColumn: e,
  11277. isMerged: !1,
  11278. isMergedMainCell: !1,
  11279. rangeType: H.NORMAL
  11280. };
  11281. }
  11282. const Pd = (n, e, t, o, s = 1) => {
  11283. switch (o) {
  11284. case pe.UP:
  11285. return ti(n, e, t, s);
  11286. case pe.DOWN:
  11287. return ni(n, e, t, s);
  11288. case pe.LEFT:
  11289. return oi(n, e, t, s);
  11290. case pe.RIGHT:
  11291. return si(n, e, t, s);
  11292. }
  11293. }, _h = (n, e, t) => {
  11294. let o, s = -1, r;
  11295. for (let C = 0; C < n.length; C++)
  11296. if (n[C].primary) {
  11297. o = n[C], s = C, r = o.primary;
  11298. break;
  11299. }
  11300. if (s === -1)
  11301. return null;
  11302. const i = e === pe.LEFT || e === pe.UP, a = i ? s - 1 >= 0 ? s - 1 : n.length - 1 : s + 1 < n.length ? s + 1 : 0, u = n[a];
  11303. if (!o || !r)
  11304. return null;
  11305. const l = { ...r }, { startRow: c, startColumn: d, endRow: h, endColumn: m } = o.range, g = i ? l.startRow === c && l.startColumn === d : l.endRow === h && l.endColumn === m, f = g && i;
  11306. if (!k.equals(o.range, l)) {
  11307. const C = g ? u.range : Pd(o.range, t, l, e);
  11308. if (!C)
  11309. return null;
  11310. const S = f ? mn(C.endRow, C.endColumn, t) : mn(C.startRow, C.startColumn, t);
  11311. return {
  11312. startRow: S.startRow,
  11313. startColumn: S.startColumn,
  11314. endRow: S.endRow,
  11315. endColumn: S.endColumn
  11316. };
  11317. }
  11318. const p = f ? mn(u.range.endRow, u.range.endColumn, t) : mn(u.range.startRow, u.range.startColumn, t);
  11319. return {
  11320. startRow: p.startRow,
  11321. startColumn: p.startColumn,
  11322. endRow: p.endRow,
  11323. endColumn: p.endColumn
  11324. };
  11325. }, bh = {
  11326. WorkbookCommentPermission: Ws,
  11327. WorkbookCopyPermission: Ls,
  11328. WorkbookCreateProtectPermission: Vs,
  11329. WorkbookCreateSheetPermission: Hs,
  11330. WorkbookDeleteSheetPermission: Bs,
  11331. WorkbookDuplicatePermission: Fs,
  11332. WorkbookEditablePermission: Me,
  11333. WorkbookExportPermission: js,
  11334. WorkbookHideSheetPermission: vo,
  11335. WorkbookHistoryPermission: tu,
  11336. WorkbookManageCollaboratorPermission: Mo,
  11337. WorkbookMoveSheetPermission: _o,
  11338. WorkbookPrintPermission: Gs,
  11339. WorkbookRecoverHistoryPermission: zs,
  11340. WorkbookRenameSheetPermission: bo,
  11341. WorkbookSharePermission: Ks,
  11342. WorkbookViewHistoryPermission: Ys,
  11343. WorkbookViewPermission: Js,
  11344. WorksheetCopyPermission: Xs,
  11345. WorksheetDeleteColumnPermission: qs,
  11346. WorksheetDeleteProtectionPermission: Zs,
  11347. WorksheetDeleteRowPermission: Qs,
  11348. WorksheetEditExtraObjectPermission: er,
  11349. WorksheetEditPermission: Te,
  11350. WorksheetFilterPermission: tr,
  11351. WorksheetInsertColumnPermission: nr,
  11352. WorksheetInsertHyperlinkPermission: or,
  11353. WorksheetInsertRowPermission: sr,
  11354. WorksheetManageCollaboratorPermission: rr,
  11355. WorksheetPivotTablePermission: ir,
  11356. WorksheetSelectProtectedCellsPermission: nu,
  11357. WorksheetSelectUnProtectedCellsPermission: ou,
  11358. WorksheetSetCellStylePermission: ar,
  11359. WorksheetSetCellValuePermission: wn,
  11360. WorksheetSetColumnStylePermission: $t,
  11361. WorksheetSetRowStylePermission: Wt,
  11362. WorksheetSortPermission: ur,
  11363. WorksheetViewPermission: Hn,
  11364. RangeProtectionPermissionEditPoint: Pe,
  11365. RangeProtectionPermissionViewPoint: Io
  11366. }, yh = (n, e, t, o) => {
  11367. const s = n.get(Fe), r = n.get(de), i = s.getPermissionPoint(new Me(e).id);
  11368. if (!(i != null && i.value))
  11369. return !1;
  11370. const a = s.getPermissionPoint(new Te(e, t).id);
  11371. if (!(a != null && a.value))
  11372. return !1;
  11373. const l = r.getSubunitRuleList(e, t).filter((c) => c.ranges.some((d) => o.some((h) => k.intersects(d, h))));
  11374. return l.length ? l.every((c) => {
  11375. const d = c.permissionId, h = s.getPermissionPoint(new Pe(e, t, d).id);
  11376. return !!(h != null && h.value);
  11377. }) : !0;
  11378. };
  11379. function Td(n, e) {
  11380. return e.some((t) => kd(n, t));
  11381. }
  11382. function kd(n, e) {
  11383. const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s);
  11384. let a = !1;
  11385. return i.forValue((u, l, c) => {
  11386. if (c && (u !== t || l !== o) && n.cellHasValue(c))
  11387. return a = !0, !1;
  11388. }), a;
  11389. }
  11390. function Nd(n, e, t, o) {
  11391. const s = [], r = [], i = t.getSheetId();
  11392. return o.forEach((a) => {
  11393. const u = Od(t, a), l = {
  11394. unitId: e,
  11395. subUnitId: i,
  11396. cellValue: u.getData()
  11397. }, c = Ae(
  11398. n,
  11399. l
  11400. );
  11401. s.push({ id: Q.id, params: c }), r.push({ id: Q.id, params: l });
  11402. }), {
  11403. undos: s,
  11404. redos: r
  11405. };
  11406. }
  11407. function Od(n, e) {
  11408. const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s, Ni.Intercepted), a = new G();
  11409. return i.forValue((u, l, c) => {
  11410. c && (u !== t || l !== o) && a.setValue(u, l, null);
  11411. }), a;
  11412. }
  11413. const Xn = {
  11414. type: v.COMMAND,
  11415. id: "sheet.command.add-worksheet-merge",
  11416. handler: (n, e) => {
  11417. const t = n.get(E), o = n.get(W), s = n.get(M), 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 = {
  11418. unitId: r,
  11419. subUnitId: i,
  11420. ranges: u
  11421. }, g = {
  11422. unitId: r,
  11423. subUnitId: i,
  11424. ranges: u
  11425. };
  11426. c.push({ id: oe.id, params: m }), c.push({ id: ne.id, params: g });
  11427. const f = Se(n, m), p = Ue(n, g);
  11428. if (d.push({ id: oe.id, params: p }), d.push({ id: ne.id, params: f }), h) {
  11429. const S = Nd(n, r, l, u);
  11430. c.unshift(...S.redos), d.push(...S.undos);
  11431. }
  11432. return z(c, t).result ? (o.pushUndoRedo({
  11433. unitID: r,
  11434. undoMutations: d,
  11435. redoMutations: c
  11436. }), !0) : !1;
  11437. }
  11438. }, Eh = {
  11439. type: v.COMMAND,
  11440. id: "sheet.command.add-worksheet-merge-all",
  11441. handler: async (n) => {
  11442. var l;
  11443. const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
  11444. if (!(o != null && o.length))
  11445. return !1;
  11446. const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
  11447. if (!r) return !1;
  11448. const i = r.getActiveSheet();
  11449. if (!i) return !1;
  11450. const a = r.getUnitId(), u = i.getSheetId();
  11451. return e.executeCommand(Xn.id, {
  11452. selections: o,
  11453. unitId: a,
  11454. subUnitId: u
  11455. });
  11456. }
  11457. }, Uh = {
  11458. type: v.COMMAND,
  11459. id: "sheet.command.add-worksheet-merge-vertical",
  11460. handler: async (n) => {
  11461. var l;
  11462. const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
  11463. if (!(o != null && o.length))
  11464. return !1;
  11465. const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
  11466. if (!r) return !1;
  11467. const i = r.getActiveSheet();
  11468. if (!i) return !1;
  11469. const a = r.getUnitId(), u = i.getSheetId();
  11470. return e.executeCommand(Xn.id, {
  11471. value: ge.COLUMNS,
  11472. selections: o,
  11473. unitId: a,
  11474. subUnitId: u
  11475. });
  11476. }
  11477. }, Ph = {
  11478. type: v.COMMAND,
  11479. id: "sheet.command.add-worksheet-merge-horizontal",
  11480. handler: async (n) => {
  11481. var l;
  11482. const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
  11483. if (!(o != null && o.length))
  11484. return !1;
  11485. const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
  11486. if (!r) return !1;
  11487. const i = r.getActiveSheet();
  11488. if (!i) return !1;
  11489. const a = r.getUnitId(), u = i.getSheetId();
  11490. return e.executeCommand(Xn.id, {
  11491. value: ge.ROWS,
  11492. selections: o,
  11493. unitId: a,
  11494. subUnitId: u
  11495. });
  11496. }
  11497. };
  11498. function Th(n, e, t, o, s) {
  11499. const r = n.get(M), i = N(r, { unitId: e, subUnitId: t });
  11500. if (!i) return;
  11501. const { worksheet: a } = i;
  11502. if (a.getMergeData().some((d) => o.some((h) => k.intersects(h, d))))
  11503. throw new Error("The ranges to be merged overlap with the existing merged cells");
  11504. n.get(E).executeCommand(Xn.id, {
  11505. unitId: e,
  11506. subUnitId: t,
  11507. selections: o,
  11508. defaultMerge: s
  11509. });
  11510. }
  11511. const Dd = (n, e) => {
  11512. const r = n.get(M).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft;
  11513. return {
  11514. ...O.deepClone(e),
  11515. rightToLeft: r
  11516. };
  11517. }, so = {
  11518. id: "sheet.mutation.set-worksheet-right-to-left",
  11519. type: v.MUTATION,
  11520. handler: (n, e) => {
  11521. const t = n.get(M).getUniverSheetInstance(e.unitId);
  11522. if (!t) return !1;
  11523. const o = t.getSheetBySheetId(e.subUnitId);
  11524. if (!o) return !1;
  11525. const s = o.getConfig();
  11526. return s.rightToLeft = e.rightToLeft, !0;
  11527. }
  11528. }, kh = {
  11529. type: v.COMMAND,
  11530. id: "sheet.command.set-worksheet-right-to-left",
  11531. handler: async (n, e) => {
  11532. var d;
  11533. const t = n.get(E), o = n.get(W), s = N(n.get(M), e);
  11534. if (!s) return !1;
  11535. const { unitId: r, subUnitId: i } = s;
  11536. let a = te.FALSE;
  11537. e && (a = (d = e.rightToLeft) != null ? d : te.FALSE);
  11538. const u = {
  11539. rightToLeft: a,
  11540. unitId: r,
  11541. subUnitId: i
  11542. }, l = Dd(
  11543. n,
  11544. u
  11545. );
  11546. return t.syncExecuteCommand(
  11547. so.id,
  11548. u
  11549. ) ? (o.pushUndoRedo({
  11550. unitID: r,
  11551. undoMutations: [{ id: so.id, params: l }],
  11552. redoMutations: [
  11553. { id: so.id, params: u }
  11554. ]
  11555. }), !0) : !1;
  11556. }
  11557. };
  11558. export {
  11559. qn as AFTER_CELL_EDIT,
  11560. Zn as AFTER_CELL_EDIT_ASYNC,
  11561. Ih as AddMergeRedoSelectionsOperationFactory,
  11562. Ue as AddMergeUndoMutationFactory,
  11563. vh as AddMergeUndoSelectionsOperationFactory,
  11564. Xi as AddRangeProtectionCommand,
  11565. Ne as AddRangeProtectionMutation,
  11566. Eh as AddWorksheetMergeAllCommand,
  11567. Xn as AddWorksheetMergeCommand,
  11568. Ph as AddWorksheetMergeHorizontalCommand,
  11569. ne as AddWorksheetMergeMutation,
  11570. Uh as AddWorksheetMergeVerticalCommand,
  11571. qi as AddWorksheetProtectionCommand,
  11572. ct as AddWorksheetProtectionMutation,
  11573. Go as BEFORE_CELL_EDIT,
  11574. kt as BorderStyleManagerService,
  11575. gh as COMMAND_LISTENER_SKELETON_CHANGE,
  11576. fh as COMMAND_LISTENER_VALUE_CHANGE,
  11577. Fu as CancelFrozenCommand,
  11578. po as ClearSelectionAllCommand,
  11579. Co as ClearSelectionContentCommand,
  11580. So as ClearSelectionFormatCommand,
  11581. xs as CopySheetCommand,
  11582. jd as DISABLE_NORMAL_SELECTIONS,
  11583. Un as DefinedNameDataController,
  11584. Pt as DeleteRangeMoveLeftCommand,
  11585. Tt as DeleteRangeMoveUpCommand,
  11586. su as DeleteRangeProtectionCommand,
  11587. ze as DeleteRangeProtectionMutation,
  11588. ru as DeleteWorksheetProtectionCommand,
  11589. St as DeleteWorksheetProtectionMutation,
  11590. iu as DeleteWorksheetRangeThemeStyleCommand,
  11591. Kt as DeleteWorksheetRangeThemeStyleMutation,
  11592. _a as DeleteWorksheetRangeThemeStyleMutationFactory,
  11593. Oo as DeltaColumnWidthCommand,
  11594. $o as DeltaRowHeightCommand,
  11595. Yi as EditStateEnum,
  11596. $ as EffectRefRangId,
  11597. Dl as EmptyMutation,
  11598. Qc as ExclusiveRangeService,
  11599. Fd as FactoryAddRangeProtectionMutation,
  11600. Bd as FactoryDeleteRangeProtectionMutation,
  11601. qd as FactorySetRangeProtectionMutation,
  11602. ds as IExclusiveRangeService,
  11603. et as INTERCEPTOR_POINT,
  11604. wt as INumfmtService,
  11605. Xa as IRefSelectionsService,
  11606. gu as InsertColAfterCommand,
  11607. mu as InsertColBeforeCommand,
  11608. pr as InsertColByRangeCommand,
  11609. gt as InsertColCommand,
  11610. je as InsertColMutation,
  11611. yo as InsertColMutationUndoFactory,
  11612. au as InsertDefinedNameCommand,
  11613. sn as InsertRangeMoveDownCommand,
  11614. Bn as InsertRangeMoveRightCommand,
  11615. hu as InsertRowAfterCommand,
  11616. du as InsertRowBeforeCommand,
  11617. fr as InsertRowByRangeCommand,
  11618. mt as InsertRowCommand,
  11619. qe as InsertRowMutation,
  11620. mr as InsertRowMutationUndoFactory,
  11621. fu as InsertSheetCommand,
  11622. Jt as InsertSheetMutation,
  11623. As as InsertSheetUndoMutationFactory,
  11624. ea as InterceptCellContentPriority,
  11625. Ll as MAX_CELL_PER_SHEET_KEY,
  11626. Oc as MERGE_CELL_INTERCEPTOR_CHECK,
  11627. Tn as MergeCellController,
  11628. jn as MoveColsCommand,
  11629. st as MoveColsMutation,
  11630. pu as MoveColsMutationUndoFactory,
  11631. pt as MoveRangeCommand,
  11632. dt as MoveRangeMutation,
  11633. Fn as MoveRowsCommand,
  11634. ot as MoveRowsMutation,
  11635. Ru as MoveRowsMutationUndoFactory,
  11636. co as NumfmtService,
  11637. q as OperatorType,
  11638. bh as PermissionPointsDefinitions,
  11639. Aa as REF_SELECTIONS_ENABLED,
  11640. ah as RangeMergeUtil,
  11641. ht as RangeProtectionCache,
  11642. Lr as RangeProtectionPermissionDeleteProtectionPoint,
  11643. Pe as RangeProtectionPermissionEditPoint,
  11644. Vr as RangeProtectionPermissionManageCollaPoint,
  11645. Io as RangeProtectionPermissionViewPoint,
  11646. An as RangeProtectionRefRangeService,
  11647. tn as RangeProtectionRenderModel,
  11648. de as RangeProtectionRuleModel,
  11649. xn as RangeProtectionService,
  11650. yt as RangeThemeStyle,
  11651. _t as RefRangeService,
  11652. qo as RefSelectionsService,
  11653. wu as RegisterWorksheetRangeThemeStyleCommand,
  11654. Yt as RegisterWorksheetRangeThemeStyleMutation,
  11655. Mr as RemoveColByRangeCommand,
  11656. zn as RemoveColCommand,
  11657. De as RemoveColMutation,
  11658. Ir as RemoveDefinedNameCommand,
  11659. Se as RemoveMergeUndoMutationFactory,
  11660. zr as RemoveNumfmtMutation,
  11661. vr as RemoveRowByRangeCommand,
  11662. Gn as RemoveRowCommand,
  11663. Be as RemoveRowMutation,
  11664. ko as RemoveSheetCommand,
  11665. Ut as RemoveSheetMutation,
  11666. ja as RemoveSheetUndoMutationFactory,
  11667. Iu as RemoveWorksheetMergeCommand,
  11668. oe as RemoveWorksheetMergeMutation,
  11669. uo as ReorderRangeCommand,
  11670. In as ReorderRangeMutation,
  11671. Mu as ReorderRangeUndoMutationFactory,
  11672. tl as ResetBackgroundColorCommand,
  11673. Qu as ResetTextColorCommand,
  11674. ch as SCOPE_WORKBOOK_VALUE_DEFINED_NAME,
  11675. Gd as SELECTIONS_ENABLED,
  11676. Sh as SELECTION_CONTROL_BORDER_BUFFER_COLOR,
  11677. Ch as SELECTION_CONTROL_BORDER_BUFFER_WIDTH,
  11678. Wl as ScrollToCellOperation,
  11679. Ce as SelectionMoveType,
  11680. el as SetBackgroundColorCommand,
  11681. Zd as SetBoldCommand,
  11682. Ou as SetBorderBasicCommand,
  11683. Nu as SetBorderColorCommand,
  11684. rn as SetBorderCommand,
  11685. Tu as SetBorderPositionCommand,
  11686. ku as SetBorderStyleCommand,
  11687. $u as SetColDataCommand,
  11688. Lt as SetColDataMutation,
  11689. xu as SetColDataMutationFactory,
  11690. yr as SetColHiddenCommand,
  11691. Xt as SetColHiddenMutation,
  11692. qt as SetColVisibleMutation,
  11693. Mn as SetColWidthCommand,
  11694. Ur as SetDefinedNameCommand,
  11695. oh as SetFontFamilyCommand,
  11696. sh as SetFontSizeCommand,
  11697. Bu as SetFrozenCommand,
  11698. ut as SetFrozenMutation,
  11699. Pr as SetFrozenMutationFactory,
  11700. ju as SetGridlinesColorCommand,
  11701. Vt as SetGridlinesColorMutation,
  11702. ol as SetHorizontalTextAlignCommand,
  11703. Qd as SetItalicCommand,
  11704. Vo as SetNumfmtMutation,
  11705. nh as SetOverlineCommand,
  11706. Gu as SetProtectionCommand,
  11707. he as SetRangeProtectionMutation,
  11708. on as SetRangeValuesCommand,
  11709. Q as SetRangeValuesMutation,
  11710. Ae as SetRangeValuesUndoMutationFactory,
  11711. Ku as SetRowDataCommand,
  11712. Ht as SetRowDataMutation,
  11713. zu as SetRowDataMutationFactory,
  11714. Wo as SetRowHeightCommand,
  11715. kr as SetRowHiddenCommand,
  11716. Qt as SetRowHiddenMutation,
  11717. Zt as SetRowVisibleMutation,
  11718. br as SetSelectedColsVisibleCommand,
  11719. Tr as SetSelectedRowsVisibleCommand,
  11720. re as SetSelectionsOperation,
  11721. Kn as SetSpecificColsVisibleCommand,
  11722. Jn as SetSpecificRowsVisibleCommand,
  11723. th as SetStrikeThroughCommand,
  11724. fe as SetStyleCommand,
  11725. al as SetTabColorCommand,
  11726. fn as SetTabColorMutation,
  11727. Zu as SetTextColorCommand,
  11728. rl as SetTextRotationCommand,
  11729. sl as SetTextWrapCommand,
  11730. eh as SetUnderlineCommand,
  11731. nl as SetVerticalTextAlignCommand,
  11732. Dr as SetWorkbookNameCommand,
  11733. Or as SetWorkbookNameMutation,
  11734. Ar as SetWorksheetActivateCommand,
  11735. an as SetWorksheetActiveOperation,
  11736. tt as SetWorksheetColWidthMutation,
  11737. xr as SetWorksheetColWidthMutationFactory,
  11738. dl as SetWorksheetDefaultStyleCommand,
  11739. Bt as SetWorksheetDefaultStyleMutation,
  11740. cl as SetWorksheetDefaultStyleMutationFactory,
  11741. hl as SetWorksheetHideCommand,
  11742. lt as SetWorksheetHideMutation,
  11743. Do as SetWorksheetNameCommand,
  11744. _n as SetWorksheetNameMutation,
  11745. Wr as SetWorksheetOrderCommand,
  11746. Rn as SetWorksheetOrderMutation,
  11747. Il as SetWorksheetPermissionPointsCommand,
  11748. Ao as SetWorksheetPermissionPointsMutation,
  11749. vl as SetWorksheetProtectionCommand,
  11750. Ct as SetWorksheetProtectionMutation,
  11751. ba as SetWorksheetRangeThemeStyleCommand,
  11752. zt as SetWorksheetRangeThemeStyleMutation,
  11753. Ma as SetWorksheetRangeThemeStyleMutationFactory,
  11754. kh as SetWorksheetRightToLeftCommand,
  11755. so as SetWorksheetRightToLeftMutation,
  11756. Br as SetWorksheetRowAutoHeightMutation,
  11757. ih as SetWorksheetRowAutoHeightMutationFactory,
  11758. nt as SetWorksheetRowHeightMutation,
  11759. Lo as SetWorksheetRowIsAutoHeightCommand,
  11760. Oe as SetWorksheetRowIsAutoHeightMutation,
  11761. Fr as SetWorksheetShowCommand,
  11762. V as SheetInterceptorService,
  11763. Nn as SheetPermissionCheckController,
  11764. On as SheetPermissionInitController,
  11765. ho as SheetRangeThemeService,
  11766. Id as SheetSkeletonChangeType,
  11767. vd as SheetValueChangeType,
  11768. F as SheetsSelectionsService,
  11769. Tl as SplitTextToColumnsCommand,
  11770. kl as ToggleCellCheckboxCommand,
  11771. Nl as ToggleGridlinesCommand,
  11772. Ft as ToggleGridlinesMutation,
  11773. _ as UnitAction,
  11774. D as UnitObject,
  11775. Wn as UniverSheetsPlugin,
  11776. Ol as UnregisterWorksheetRangeThemeStyleCommand,
  11777. Uo as UnregisterWorksheetRangeThemeStyleMutation,
  11778. Ji as ViewStateEnum,
  11779. Ws as WorkbookCommentPermission,
  11780. Ls as WorkbookCopyPermission,
  11781. eu as WorkbookCopySheetPermission,
  11782. Vs as WorkbookCreateProtectPermission,
  11783. Hs as WorkbookCreateSheetPermission,
  11784. Bs as WorkbookDeleteSheetPermission,
  11785. Fs as WorkbookDuplicatePermission,
  11786. Me as WorkbookEditablePermission,
  11787. js as WorkbookExportPermission,
  11788. vo as WorkbookHideSheetPermission,
  11789. tu as WorkbookHistoryPermission,
  11790. Mo as WorkbookManageCollaboratorPermission,
  11791. _o as WorkbookMoveSheetPermission,
  11792. $n as WorkbookPermissionService,
  11793. Gs as WorkbookPrintPermission,
  11794. zs as WorkbookRecoverHistoryPermission,
  11795. bo as WorkbookRenameSheetPermission,
  11796. Ta as WorkbookSelectionModel,
  11797. Ks as WorkbookSharePermission,
  11798. Ys as WorkbookViewHistoryPermission,
  11799. Js as WorkbookViewPermission,
  11800. Xs as WorksheetCopyPermission,
  11801. qs as WorksheetDeleteColumnPermission,
  11802. Zs as WorksheetDeleteProtectionPermission,
  11803. Qs as WorksheetDeleteRowPermission,
  11804. er as WorksheetEditExtraObjectPermission,
  11805. Te as WorksheetEditPermission,
  11806. tr as WorksheetFilterPermission,
  11807. nr as WorksheetInsertColumnPermission,
  11808. or as WorksheetInsertHyperlinkPermission,
  11809. sr as WorksheetInsertRowPermission,
  11810. rr as WorksheetManageCollaboratorPermission,
  11811. bn as WorksheetPermissionService,
  11812. ir as WorksheetPivotTablePermission,
  11813. un as WorksheetProtectionPointModel,
  11814. Ye as WorksheetProtectionRuleModel,
  11815. nu as WorksheetSelectProtectedCellsPermission,
  11816. ou as WorksheetSelectUnProtectedCellsPermission,
  11817. ar as WorksheetSetCellStylePermission,
  11818. wn as WorksheetSetCellValuePermission,
  11819. $t as WorksheetSetColumnStylePermission,
  11820. Wt as WorksheetSetRowStylePermission,
  11821. ur as WorksheetSortPermission,
  11822. Hn as WorksheetViewPermission,
  11823. Th as addMergeCellsUtil,
  11824. Sc as adjustRangeOnMutation,
  11825. Ln as alignToMergedCellsBorders,
  11826. it as baseProtectionActions,
  11827. yh as checkRangesEditablePermission,
  11828. Md as convertPrimaryWithCoordToPrimary,
  11829. wh as convertSelectionDataToRange,
  11830. Vn as copyRangeStyles,
  11831. xl as createTopMatrixFromMatrix,
  11832. Al as createTopMatrixFromRanges,
  11833. fl as defaultWorkbookPermissionPoints,
  11834. eo as defaultWorksheetPermissionPoint,
  11835. Mh as expandToContinuousRange,
  11836. lh as factoryRemoveNumfmtUndoMutation,
  11837. uh as factorySetNumfmtUndoMutation,
  11838. jr as findAllRectangle,
  11839. Xe as followSelectionOperation,
  11840. Os as generateNullCell,
  11841. Ua as generateNullCellValue,
  11842. Zr as getAddMergeMutationRangeByType,
  11843. Ie as getAllRangePermissionPoint,
  11844. en as getAllWorkbookPermissionPoint,
  11845. we as getAllWorksheetPermissionPoint,
  11846. ke as getAllWorksheetPermissionPointByPointPanel,
  11847. zd as getCellAtRowCol,
  11848. rh as getDefaultRangePermission,
  11849. lr as getInsertRangeMutations,
  11850. wo as getMoveRangeUndoRedoMutations,
  11851. _h as getNextPrimaryCell,
  11852. ve as getPrimaryForRange,
  11853. cr as getRemoveRangeMutations,
  11854. qa as getSelectionsService,
  11855. mh as getSeparateEffectedRangesOnCommand,
  11856. N as getSheetCommandTarget,
  11857. va as getSheetCommandTargetWorkbook,
  11858. Et as getSheetMutationTarget,
  11859. ph as getSkeletonChangedEffectedRange,
  11860. Rh as getValueChangedEffectedRange,
  11861. vt as handleBaseInsertRange,
  11862. Pn as handleBaseMoveRowsCols,
  11863. It as handleBaseRemoveRange,
  11864. ss as handleCommonDefaultRangeChangeWithEffectRefCommands,
  11865. hh as handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests,
  11866. os as handleDefaultRangeChangeWithEffectRefCommands,
  11867. dh as handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests,
  11868. hc as handleDeleteRangeMoveLeft,
  11869. gc as handleDeleteRangeMoveUp,
  11870. Xd as handleDeleteRangeMutation,
  11871. Xr as handleIRemoveCol,
  11872. oc as handleIRemoveRow,
  11873. ac as handleInsertCol,
  11874. uc as handleInsertRangeMoveDown,
  11875. cc as handleInsertRangeMoveRight,
  11876. Yd as handleInsertRangeMutation,
  11877. ic as handleInsertRow,
  11878. Yr as handleMoveCols,
  11879. tc as handleMoveRange,
  11880. Jr as handleMoveRows,
  11881. Jd as isSingleCellSelection,
  11882. Gr as rangeMerge,
  11883. _e as rotateRange,
  11884. Mt as runRefRangeMutations,
  11885. Kd as setEndForRange,
  11886. Pl as splitRangeText,
  11887. lo as transformCellsToRange
  11888. };