| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888 |
- var ri = Object.defineProperty;
- var ii = (n, e, t) => e in n ? ri(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
- var R = (n, e, t) => ii(n, typeof e != "symbol" ? e + "" : e, t);
- 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";
- 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";
- import { DataSyncPrimaryController as Fi } from "@univerjs/rpc";
- 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";
- import { DEFAULT_TEXT_FORMAT as ks } from "@univerjs/engine-numfmt";
- import { takeUntil as Bo, filter as Fo, map as Ki } from "rxjs/operators";
- var Ji = /* @__PURE__ */ ((n) => (n.OthersCanView = "othersCanView", n.NoOneElseCanView = "noOneElseCanView", n))(Ji || {}), Yi = /* @__PURE__ */ ((n) => (n.DesignedUserCanEdit = "designedUserCanEdit", n.OnlyMe = "onlyMe", n))(Yi || {});
- class de {
- constructor() {
- /**
- *
- * Map<unitId, Map<subUnitId, Map<ruleId, IRangeProtectionRule>>>
- */
- R(this, "_model", /* @__PURE__ */ new Map());
- R(this, "_ruleChange", new Le());
- R(this, "ruleChange$", this._ruleChange.asObservable());
- R(this, "_ruleRefresh", new Le());
- R(this, "ruleRefresh$", this._ruleRefresh.asObservable());
- R(this, "_rangeRuleInitStateChange", new at(!1));
- R(this, "rangeRuleInitStateChange$", this._rangeRuleInitStateChange.asObservable());
- }
- ruleRefresh(e) {
- this._ruleRefresh.next(e);
- }
- getRangeRuleInitState() {
- return this._rangeRuleInitStateChange.value;
- }
- changeRuleInitState(e) {
- this._rangeRuleInitStateChange.next(e);
- }
- addRule(e, t, o) {
- this._ensureRuleMap(e, t).set(o.id, o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: o, type: "add" });
- }
- deleteRule(e, t, o) {
- var r, i, a, u;
- const s = (i = (r = this._model.get(e)) == null ? void 0 : r.get(t)) == null ? void 0 : i.get(o);
- s && ((u = (a = this._model.get(e)) == null ? void 0 : a.get(t)) == null || u.delete(o), this._ruleChange.next({ unitId: e, subUnitId: t, rule: s, type: "delete" }));
- }
- setRule(e, t, o, s) {
- var i, a;
- const r = this.getRule(e, t, o);
- r && ((a = (i = this._model.get(e)) == null ? void 0 : i.get(t)) == null || a.set(o, s), this._ruleChange.next({ unitId: e, subUnitId: t, oldRule: r, rule: s, type: "set" }));
- }
- getRule(e, t, o) {
- var s, r;
- return (r = (s = this._model.get(e)) == null ? void 0 : s.get(t)) == null ? void 0 : r.get(o);
- }
- getSubunitRuleList(e, t) {
- var s;
- return [...(((s = this._model.get(e)) == null ? void 0 : s.get(t)) || /* @__PURE__ */ new Map()).values()];
- }
- getSubunitRuleListLength(e, t) {
- var s;
- const o = (s = this._model.get(e)) == null ? void 0 : s.get(t);
- return o ? o.size : 0;
- }
- _ensureRuleMap(e, t) {
- let o = this._model.get(e);
- o || (o = /* @__PURE__ */ new Map(), this._model.set(e, o));
- let s = o.get(t);
- return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
- }
- toObject() {
- const e = {};
- return [...this._model.keys()].forEach((o) => {
- const s = this._model.get(o), r = [...s.keys()];
- e[o] = {}, r.forEach((i) => {
- const a = s.get(i);
- e[o][i] = [...a.values()];
- });
- }), e;
- }
- fromObject(e) {
- const t = /* @__PURE__ */ new Map();
- Object.keys(e).forEach((o) => {
- const s = e[o], r = /* @__PURE__ */ new Map();
- Object.keys(s).forEach((i) => {
- const a = s[i].reduce((u, l) => (u.set(l.id, l), u), /* @__PURE__ */ new Map());
- r.set(i, a);
- }), t.set(o, r);
- }), this._model = t;
- }
- deleteUnitModel(e) {
- this._model.delete(e);
- }
- createRuleId(e, t) {
- let o = O.generateRandomId(4);
- const s = this._ensureRuleMap(e, t);
- for (; s.has(o); )
- o = O.generateRandomId(4);
- return o;
- }
- getTargetByPermissionId(e, t) {
- const o = this._model.get(e);
- if (!o) return null;
- for (const [s, r] of o)
- for (const i of r.values())
- if (i.permissionId === t)
- return [e, s];
- return null;
- }
- }
- const Bd = (n, e) => {
- const t = n.get(de), o = e.ruleIds.map((r) => t.getRule(e.unitId, e.subUnitId, r)).filter((r) => !!r);
- return { id: Ne.id, params: { subUnitId: e.subUnitId, unitId: e.unitId, rules: o } };
- }, ze = {
- id: "sheet.mutation.delete-range-protection",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, ruleIds: s } = e, r = n.get(de);
- return s.forEach((i) => {
- r.deleteRule(t, o, i);
- }), !0;
- }
- }, Fd = (n) => {
- const e = { ...n, ruleIds: n.rules.map((t) => t.id) };
- return { id: ze.id, params: e };
- }, Ne = {
- id: "sheet.mutation.add-range-protection",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, rules: s } = e, r = n.get(de);
- return s.forEach((i) => {
- r.addRule(t, o, i);
- }), !0;
- }
- }, Xi = {
- type: v.COMMAND,
- id: "sheet.command.add-range-protection",
- async handler(n, e) {
- if (!e)
- return !1;
- 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 = [{
- ranges: l,
- permissionId: i,
- id: s.createRuleId(a, u),
- description: c,
- unitType: r.unitType,
- unitId: a,
- subUnitId: u,
- viewState: d,
- editState: h
- }];
- if (await t.executeCommand(Ne.id, {
- unitId: a,
- subUnitId: u,
- rules: m
- })) {
- const f = [{ id: Ne.id, params: { unitId: a, subUnitId: u, rules: m } }], p = [{ id: ze.id, params: { unitId: a, subUnitId: u, ruleIds: m.map((C) => C.id) } }];
- o.pushUndoRedo({
- unitID: a,
- redoMutations: f,
- undoMutations: p
- });
- }
- return !0;
- }
- };
- class Ye {
- constructor() {
- /**
- *
- * Map<unitId, Map<subUnitId, Map<subUnitId, IWorksheetProtectionRule>>>
- */
- R(this, "_model", /* @__PURE__ */ new Map());
- R(this, "_ruleChange", new Le());
- R(this, "_ruleRefresh", new Le());
- R(this, "_resetOrder", new Le());
- R(this, "ruleChange$", this._ruleChange.asObservable());
- R(this, "ruleRefresh$", this._ruleRefresh.asObservable());
- R(this, "resetOrder$", this._resetOrder.asObservable());
- R(this, "_worksheetRuleInitStateChange", new at(!1));
- R(this, "worksheetRuleInitStateChange$", this._worksheetRuleInitStateChange.asObservable());
- }
- changeRuleInitState(e) {
- this._worksheetRuleInitStateChange.next(e);
- }
- getSheetRuleInitState() {
- return this._worksheetRuleInitStateChange.value;
- }
- addRule(e, t) {
- this._ensureSubUnitMap(e).set(t.subUnitId, t), this._ruleChange.next({ unitId: e, rule: t, type: "add", subUnitId: t.subUnitId });
- }
- deleteRule(e, t) {
- var s, r, i;
- const o = (r = (s = this._model) == null ? void 0 : s.get(e)) == null ? void 0 : r.get(t);
- o && ((i = this._model.get(e)) == null || i.delete(t), this._ruleChange.next({ unitId: e, rule: o, type: "delete", subUnitId: t }));
- }
- setRule(e, t, o) {
- var r, i;
- const s = this.getRule(e, t);
- s && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.set(t, o), this._ruleChange.next({ unitId: e, oldRule: s, rule: o, type: "set", subUnitId: t }));
- }
- getRule(e, t) {
- var o, s;
- return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
- }
- toObject() {
- const e = {};
- return [...this._model.keys()].forEach((o) => {
- const s = this._model.get(o);
- s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
- const a = s.get(i);
- a && e[o].push(a);
- }));
- }), e;
- }
- fromObject(e) {
- const t = /* @__PURE__ */ new Map();
- Object.keys(e).forEach((o) => {
- const s = e[o];
- if (s != null && s.length) {
- const r = /* @__PURE__ */ new Map();
- s.forEach((i) => {
- r.set(i.subUnitId, i);
- }), t.set(o, r);
- }
- }), this._model = t;
- }
- deleteUnitModel(e) {
- this._model.delete(e);
- }
- _ensureSubUnitMap(e) {
- let t = this._model.get(e);
- return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
- }
- ruleRefresh(e) {
- this._ruleRefresh.next(e);
- }
- resetOrder() {
- this._resetOrder.next(Math.random());
- }
- getTargetByPermissionId(e, t) {
- const o = this._model.get(e);
- if (!o) return null;
- for (const [s, r] of o)
- if (r.permissionId === t)
- return [e, s];
- }
- }
- const ct = {
- id: "sheet.mutation.add-worksheet-protection",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, rule: o } = e;
- return n.get(Ye).addRule(t, o), !0;
- }
- }, St = {
- id: "sheet.mutation.delete-worksheet-protection",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o } = e;
- return n.get(Ye).deleteRule(t, o), !0;
- }
- }, qi = {
- type: v.COMMAND,
- id: "sheet.command.add-worksheet-protection",
- async handler(n, e) {
- if (!e)
- return !1;
- const t = n.get(E), o = n.get(W), { rule: s, unitId: r } = e, i = s.subUnitId;
- if (await t.executeCommand(ct.id, {
- unitId: r,
- rule: s,
- subUnitId: s.subUnitId
- })) {
- const u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: s.subUnitId } }], l = [{ id: St.id, params: { unitId: r, subUnitId: i } }];
- o.pushUndoRedo({
- unitID: r,
- redoMutations: u,
- undoMutations: l
- });
- }
- return !0;
- }
- }, Zi = rt("CELL_CONTENT"), Qi = rt("ROW_FILTERED"), et = {
- CELL_CONTENT: Zi,
- ROW_FILTERED: Qi
- };
- 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 || {});
- const Ns = "sheet.interceptor.range-theme-id", jo = "sheet.interceptor.ignore-range-theme";
- var ta = Object.defineProperty, na = Object.getOwnPropertyDescriptor, oa = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? na(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && ta(e, t, s), s;
- }, sa = (n, e) => (t, o) => e(t, o, n);
- const Go = rt("BEFORE_CELL_EDIT"), qn = rt("AFTER_CELL_EDIT"), Zn = rt("AFTER_CELL_EDIT_ASYNC");
- let V = class extends ae {
- /** @ignore */
- constructor(e) {
- super();
- R(this, "_interceptorsByName", /* @__PURE__ */ new Map());
- R(this, "_commandInterceptors", []);
- R(this, "_rangeInterceptors", []);
- R(this, "_beforeCommandInterceptor", []);
- R(this, "_afterCommandInterceptors", []);
- R(this, "_workbookDisposables", /* @__PURE__ */ new Map());
- R(this, "_worksheetDisposables", /* @__PURE__ */ new Map());
- R(this, "_interceptorsDirty", !1);
- R(this, "_composedInterceptorByKey", /* @__PURE__ */ new Map());
- R(this, "writeCellInterceptor", new mo({
- BEFORE_CELL_EDIT: Go,
- AFTER_CELL_EDIT: qn,
- AFTER_CELL_EDIT_ASYNC: Zn
- }));
- this._univerInstanceService = e, this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((t) => {
- this._interceptWorkbook(t);
- })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe(
- (t) => this._disposeWorkbookInterceptor(t)
- )), this.intercept(et.CELL_CONTENT, {
- priority: -1,
- effect: me.Style | me.Value,
- handler(t, o) {
- const s = o.worksheet.getCellRaw(o.row, o.col);
- return t ? { ...s, ...t } : s;
- }
- }), this.disposeWithMe(this.writeCellInterceptor.intercept(qn, {
- priority: -1,
- handler: (t) => t
- })), this.disposeWithMe(this.writeCellInterceptor.intercept(Go, {
- priority: -1,
- handler: (t) => t
- })), this.disposeWithMe(this.writeCellInterceptor.intercept(Zn, {
- priority: -1,
- handler: (t) => t
- }));
- }
- dispose() {
- super.dispose(), this._workbookDisposables.forEach((e) => e.dispose()), this._workbookDisposables.clear(), this._worksheetDisposables.clear(), this._interceptorsByName.clear();
- }
- // #region intercept command execution
- /**
- * Add a listener function to a specific command to add affiliated mutations. It should be called in controllers.
- *
- * Pairs with {@link onCommandExecute}.
- *
- * @param interceptor
- * @returns
- */
- interceptCommand(e) {
- if (this._commandInterceptors.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._commandInterceptors.push(e), this._commandInterceptors.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(We(() => Nt(this._commandInterceptors, e)));
- }
- /**
- * When command is executing, call this method to gether undo redo mutations from upper features.
- * @param command
- * @returns
- */
- onCommandExecute(e) {
- const t = this._commandInterceptors.map((o) => o.getMutations(e));
- return {
- preUndos: t.map((o) => {
- var s;
- return (s = o.preUndos) != null ? s : [];
- }).flat(),
- undos: t.map((o) => o.undos).flat(),
- preRedos: t.map((o) => {
- var s;
- return (s = o.preRedos) != null ? s : [];
- }).flat(),
- redos: t.map((o) => o.redos).flat()
- };
- }
- interceptAfterCommand(e) {
- if (this._afterCommandInterceptors.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._afterCommandInterceptors.push(e), this._afterCommandInterceptors.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(We(() => Nt(this._afterCommandInterceptors, e)));
- }
- afterCommandExecute(e) {
- const t = this._afterCommandInterceptors.map((o) => o.getMutations(e));
- return {
- undos: t.map((o) => o.undos).flat(),
- redos: t.map((o) => o.redos).flat()
- };
- }
- /**
- * Add a listener function to a specific command to determine if the command can execute mutations. It should be
- * called in controllers.
- *
- * Pairs with {@link beforeCommandExecute}.
- *
- * @param interceptor
- * @returns
- */
- interceptBeforeCommand(e) {
- if (this._beforeCommandInterceptor.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._beforeCommandInterceptor.push(e), this._beforeCommandInterceptor.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(We(() => Nt(this._beforeCommandInterceptor, e)));
- }
- /**
- * before command execute, call this method to get the flag of whether it can be executed the command,
- * @param info ICommandInfo
- * @returns Promise<boolean>
- */
- async beforeCommandExecute(e) {
- return (await Promise.all(this._beforeCommandInterceptor.map((o) => o.performCheck(e)))).every((o) => o);
- }
- // #endregion
- // #region intercept ranges - mainly for pivot table currently (2024/10/28).
- /**
- * By adding callbacks to some Ranges can get some additional mutations, such as clearing all plugin data in a certain area.
- * @param interceptor IRangeInterceptors
- * @returns IDisposable
- */
- interceptRanges(e) {
- if (this._rangeInterceptors.includes(e))
- throw new Error("[SheetInterceptorService]: Interceptor already exists!");
- return this._rangeInterceptors.push(e), this._rangeInterceptors.sort((t, o) => {
- var s, r;
- return ((s = o.priority) != null ? s : 0) - ((r = t.priority) != null ? r : 0);
- }), this.disposeWithMe(We(() => Nt(this._rangeInterceptors, e)));
- }
- generateMutationsByRanges(e) {
- const t = this._rangeInterceptors.map((o) => o.getMutations(e));
- return {
- preUndos: t.map((o) => {
- var s;
- return (s = o.preUndos) != null ? s : [];
- }).flat(),
- undos: t.map((o) => o.undos).flat(),
- preRedos: t.map((o) => {
- var s;
- return (s = o.preRedos) != null ? s : [];
- }).flat(),
- redos: t.map((o) => o.redos).flat()
- };
- }
- // #endregion
- // #region intercept on writing cell
- async onWriteCell(e, t, o, s, r) {
- const i = {
- subUnitId: t.getSheetId(),
- unitId: e.getUnitId(),
- workbook: e,
- worksheet: t,
- row: o,
- col: s,
- origin: O.deepClone(r)
- }, a = this.writeCellInterceptor.fetchThroughInterceptors(qn)(r, i);
- return await this.writeCellInterceptor.fetchThroughInterceptors(Zn)(Promise.resolve(a), i);
- }
- // #endregion
- intercept(e, t) {
- const o = e;
- this._interceptorsByName.has(o) || this._interceptorsByName.set(o, []);
- const s = this._interceptorsByName.get(o);
- s.push(t);
- const r = s.sort((i, a) => {
- var u, l;
- return ((u = a.priority) != null ? u : 0) - ((l = i.priority) != null ? l : 0);
- });
- if (o === et.CELL_CONTENT) {
- this._interceptorsByName.set(
- `${o}-${me.Style | me.Value}`,
- r
- );
- const i = me.Style | me.Value;
- this._interceptorsByName.set(
- `${o}-${me.Style}`,
- r.filter((a) => ((a.effect || i) & me.Style) > 0)
- ), this._interceptorsByName.set(
- `${o}-${me.Value}`,
- r.filter((a) => ((a.effect || i) & me.Value) > 0)
- );
- } else
- this._interceptorsByName.set(
- o,
- r
- );
- return this._interceptorsDirty = !0, this.disposeWithMe(We(() => Nt(this._interceptorsByName.get(o), t)));
- }
- fetchThroughInterceptors(e, t, o, s) {
- const r = t === void 0 ? e : `${e}-${t}`, i = o != null ? o : r;
- let a = this._composedInterceptorByKey.get(i);
- if (!a || this._interceptorsDirty) {
- let u = this._interceptorsByName.get(r);
- u && s && (u = u.filter(s)), a = ai(u || []), this._composedInterceptorByKey.set(i, a);
- }
- return a;
- }
- _interceptWorkbook(e) {
- const t = new jt(), o = e.getUnitId(), s = this, r = (i) => {
- const a = i.getSheetId();
- i.__interceptViewModel((u) => {
- const l = new jt();
- s._worksheetDisposables.set(zo(o, i), l), l.add(u.registerCellContentInterceptor({
- getCell(c, d, h, m, g) {
- const f = i.getCellRaw(c, d);
- return s.fetchThroughInterceptors(et.CELL_CONTENT, h, m, g)(
- f,
- {
- unitId: o,
- subUnitId: a,
- row: c,
- col: d,
- worksheet: i,
- workbook: e,
- rawData: f
- }
- );
- }
- })), l.add(u.registerRowFilteredInterceptor({
- getRowFiltered(c) {
- return !!s.fetchThroughInterceptors(et.ROW_FILTERED)(
- !1,
- {
- unitId: o,
- subUnitId: a,
- row: c,
- workbook: e,
- worksheet: i
- }
- );
- }
- }));
- });
- };
- e.getSheets().forEach((i) => r(i)), t.add(e.sheetCreated$.subscribe((i) => r(i))), t.add(We(() => e.getSheets().forEach((i) => this._disposeSheetInterceptor(o, i)))), t.add(e.sheetDisposed$.subscribe((i) => this._disposeSheetInterceptor(o, i))), this._workbookDisposables.set(o, t);
- }
- _disposeWorkbookInterceptor(e) {
- const t = e.getUnitId(), o = this._workbookDisposables.get(t);
- o && (o.dispose(), this._workbookDisposables.delete(t));
- }
- _disposeSheetInterceptor(e, t) {
- const o = zo(e, t), s = this._worksheetDisposables.get(o);
- s && (s.dispose(), this._worksheetDisposables.delete(o));
- }
- };
- V = oa([
- sa(0, M)
- ], V);
- function zo(n, e) {
- return `${n}|${e.getSheetId()}`;
- }
- const le = (n) => {
- const e = {};
- return n.bg && (e.bg = { ...n.bg }), n.ol && (e.ol = { ...n.ol }), n.bd && (e.bd = { ...n.bd }), n.cl && (e.cl = { ...n.cl }), n.ht && (e.ht = n.ht), n.vt && (e.vt = n.vt), n.bl !== void 0 && (e.bl = n.bl), e;
- };
- function ra(n) {
- const e = {};
- if (n.length === 1)
- return n[0];
- for (const t of n)
- t.bg && (e.bg = t.bg), t.ol && (e.ol = t.ol), t.bd && (e.bd = { ...e.bd, ...t.bd }), t.cl && (e.cl = t.cl), t.ht && (e.ht = t.ht), t.vt && (e.vt = t.vt), t.bl !== void 0 && (e.bl = t.bl);
- return e;
- }
- const ce = {
- wholeStyle: 1,
- headerRowStyle: 2,
- headerColumnStyle: 4,
- firstRowStyle: 8,
- secondRowStyle: 16,
- lastRowStyle: 32,
- firstColumnStyle: 128,
- secondColumnStyle: 256,
- lastColumnStyle: 512
- };
- class yt {
- /**
- * @constructor
- * @param {string} name The name of the range theme style, it used to identify the range theme style.
- * @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style.
- */
- constructor(e, t) {
- R(this, "_name");
- /**
- * @property {Nullable<IRangeThemeStyleItem>} wholeStyle effect for the whole range.
- */
- R(this, "wholeStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} headerRowStyle effect for the header row.
- */
- R(this, "headerRowStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} headerColumnStyle effect for the header column.
- */
- R(this, "headerColumnStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} firstRowStyle effect for the first row.
- */
- R(this, "firstRowStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} secondRowStyle effect for the second row.
- */
- R(this, "secondRowStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} lastRowStyle effect for the last row.
- */
- R(this, "lastRowStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} firstColumnStyle effect for the first column.
- */
- R(this, "firstColumnStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} secondColumnStyle effect for the second column.
- */
- R(this, "secondColumnStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} lastColumnStyle effect for the last column.
- */
- R(this, "lastColumnStyle", null);
- /**
- * @property {Nullable<IRangeThemeStyleItem>} quickly get merge style
- */
- R(this, "_mergeCacheMap", /* @__PURE__ */ new Map());
- t && this.fromJson({ ...t, name: e }), this._name = e;
- }
- /**
- * Gets the name of the range theme style.The name is read only, and use to identifier the range theme style.
- * @returns {string} The name of the range theme style.
- */
- getName() {
- return this._name;
- }
- getWholeStyle() {
- return this.wholeStyle;
- }
- setWholeStyle(e) {
- this.wholeStyle = e;
- }
- getFirstRowStyle() {
- return this.firstRowStyle;
- }
- setFirstRowStyle(e) {
- this.firstRowStyle = e;
- }
- getSecondRowStyle() {
- return this.secondRowStyle;
- }
- setSecondRowStyle(e) {
- this.secondRowStyle = e;
- }
- getLastRowStyle() {
- return this.lastRowStyle;
- }
- setLastRowStyle(e) {
- this.lastRowStyle = e;
- }
- getFirstColumnStyle() {
- return this.firstColumnStyle;
- }
- setFirstColumnStyle(e) {
- this.firstColumnStyle = e;
- }
- getSecondColumnStyle() {
- return this.secondColumnStyle;
- }
- setSecondColumnStyle(e) {
- this.secondColumnStyle = e;
- }
- getLastColumnStyle() {
- return this.lastColumnStyle;
- }
- setLastColumnStyle(e) {
- this.lastColumnStyle = e;
- }
- getHeaderRowStyle() {
- return this.headerRowStyle;
- }
- setHeaderRowStyle(e) {
- this.headerRowStyle = e;
- }
- getHeaderColumnStyle() {
- return this.headerColumnStyle;
- }
- setHeaderColumnStyle(e) {
- this.headerColumnStyle = e;
- }
- getStyle(e, t, o, s) {
- let r = 0;
- return o && (r = r | ce.lastRowStyle), s && (r = r | ce.lastColumnStyle), e >= 0 && t >= 0 && (r = r | ce.wholeStyle), e % 2 === 1 && (r = r | ce.firstRowStyle), e % 2 === 0 && (r = r | ce.secondRowStyle), e === 0 && (r = r | ce.headerRowStyle), t === 0 && (r = r | ce.headerColumnStyle), t % 2 === 1 && (r = r | ce.firstColumnStyle), t % 2 === 0 && (r = r | ce.secondColumnStyle), r === 0 ? null : this._getMergeStyle(r);
- }
- _getMergeStyle(e) {
- let t = this._mergeCacheMap.get(e);
- return t || (t = this._mergeStyle(e), this._mergeCacheMap.set(e, t)), t;
- }
- _mergeStyle(e) {
- const t = [];
- return this.wholeStyle && e & ce.wholeStyle && t.push(this.wholeStyle), this.firstColumnStyle && e & ce.firstColumnStyle && t.push(this.firstColumnStyle), this.secondColumnStyle && e & ce.secondColumnStyle && t.push(this.secondColumnStyle), this.firstRowStyle && e & ce.firstRowStyle && t.push(this.firstRowStyle), this.secondRowStyle && e & ce.secondRowStyle && t.push(this.secondRowStyle), this.headerColumnStyle && e & ce.headerColumnStyle && t.push(this.headerColumnStyle), this.lastColumnStyle && e & ce.lastColumnStyle && t.push(this.lastColumnStyle), this.headerRowStyle && e & ce.headerRowStyle && t.push(this.headerRowStyle), this.lastRowStyle && e & ce.lastRowStyle && t.push(this.lastRowStyle), ra(t);
- }
- toJson() {
- const e = {
- name: this._name
- };
- return this.wholeStyle && (e.wholeStyle = le(this.wholeStyle)), this.headerRowStyle && (e.headerRowStyle = le(this.headerRowStyle)), this.headerColumnStyle && (e.headerColumnStyle = le(this.headerColumnStyle)), this.firstRowStyle && (e.firstRowStyle = le(this.firstRowStyle)), this.secondRowStyle && (e.secondRowStyle = le(this.secondRowStyle)), this.lastRowStyle && (e.lastRowStyle = le(this.lastRowStyle)), this.firstColumnStyle && (e.firstColumnStyle = le(this.firstColumnStyle)), this.secondColumnStyle && (e.secondColumnStyle = le(this.secondColumnStyle)), this.lastColumnStyle && (e.lastColumnStyle = le(this.lastColumnStyle)), e;
- }
- fromJson(e) {
- this._name = e.name, e.wholeStyle && (this.wholeStyle = le(e.wholeStyle)), e.headerRowStyle && (this.headerRowStyle = le(e.headerRowStyle)), e.headerColumnStyle && (this.headerColumnStyle = le(e.headerColumnStyle)), e.firstRowStyle && (this.firstRowStyle = le(e.firstRowStyle)), e.secondRowStyle && (this.secondRowStyle = le(e.secondRowStyle)), e.lastRowStyle && (this.lastRowStyle = le(e.lastRowStyle)), e.firstColumnStyle && (this.firstColumnStyle = le(e.firstColumnStyle)), e.secondColumnStyle && (this.secondColumnStyle = le(e.secondColumnStyle)), e.lastColumnStyle && (this.lastColumnStyle = le(e.lastColumnStyle));
- }
- dispose() {
- this._mergeCacheMap.clear();
- }
- }
- const ia = (n, e, t) => new yt(`light-${n}`, {
- headerRowStyle: {
- bg: {
- rgb: e
- }
- },
- firstColumnStyle: {
- bg: {
- rgb: "rgb(255, 255, 255)"
- }
- },
- secondColumnStyle: {
- bg: {
- rgb: t
- }
- },
- lastRowStyle: {
- bg: {
- rgb: e
- }
- }
- }), aa = (n, e, t) => new yt(`middle-${n}`, {
- headerRowStyle: {
- bg: {
- rgb: e
- }
- },
- headerColumnStyle: {
- bg: {
- rgb: t
- }
- },
- secondRowStyle: {
- bg: {
- rgb: t
- }
- },
- lastRowStyle: {
- bg: {
- rgb: e
- }
- },
- lastColumnStyle: {
- bg: {
- rgb: t
- }
- }
- }), ua = (n, e, t, o) => new yt(`dark-${n}`, {
- headerRowStyle: {
- bg: {
- rgb: e
- },
- cl: {
- rgb: "rgb(255, 255, 255)"
- },
- ht: ro.CENTER,
- bl: te.TRUE
- },
- firstRowStyle: {
- bg: {
- rgb: t
- }
- },
- secondRowStyle: {
- bg: {
- rgb: o
- }
- },
- lastRowStyle: {
- bg: {
- rgb: e
- }
- }
- }), la = [
- {
- baseName: "blue",
- header: "rgb(164, 202, 254)",
- color: "rgb(225, 239, 254)"
- },
- {
- baseName: "grey",
- header: "rgb(205, 208, 216)",
- color: "rgb(238, 239, 241)"
- },
- {
- baseName: "red",
- header: "rgb(248, 180, 180)",
- color: "rgb(253, 232, 232)"
- },
- {
- baseName: "orange",
- header: "rgb(253, 186, 140)",
- color: "rgb(254, 236, 220)"
- },
- {
- baseName: "yellow",
- header: "rgb(250, 200, 21)",
- color: "rgb(255, 244, 185)"
- },
- {
- baseName: "green",
- header: "rgb(132, 225, 188)",
- color: "rgb(222, 247, 236)"
- },
- {
- baseName: "azure",
- header: "rgb(126, 220, 226)",
- color: "rgb(213, 245, 246)"
- },
- {
- baseName: "indigo",
- header: "rgb(186, 198, 248)",
- color: "rgb(233, 237, 255)"
- },
- {
- baseName: "purple",
- header: "rgb(202, 191, 253)",
- color: "rgb(237, 235, 254)"
- },
- {
- baseName: "magenta",
- header: "rgb(248, 180, 217)",
- color: "rgb(252, 232, 243)"
- }
- ], ca = [
- {
- baseName: "blue",
- rowHeader: "rgb(63, 131, 248)",
- colHeader: "rgb(195, 221, 253)"
- },
- {
- baseName: "grey",
- rowHeader: "rgb(95, 101, 116)",
- colHeader: "rgb(227, 229, 234)"
- },
- {
- baseName: "red",
- rowHeader: "rgb(240, 82, 82)",
- colHeader: "rgb(251, 213, 213)"
- },
- {
- baseName: "orange",
- rowHeader: "rgb(255, 90, 31)",
- colHeader: "rgb(252, 217, 189)"
- },
- {
- baseName: "yellow",
- rowHeader: "rgb(212, 157, 15)",
- colHeader: "rgb(252, 220, 106)"
- },
- {
- baseName: "green",
- rowHeader: "rgb(13, 164, 113)",
- colHeader: "rgb(188, 240, 218)"
- },
- {
- baseName: "azure",
- rowHeader: "rgb(6, 148, 162)",
- colHeader: "rgb(175, 236, 239)"
- },
- {
- baseName: "indigo",
- rowHeader: "rgb(70, 106, 247)",
- colHeader: "rgb(210, 218, 250)"
- },
- {
- baseName: "purple",
- rowHeader: "rgb(144, 97, 249)",
- colHeader: "rgb(220, 215, 254)"
- },
- {
- baseName: "magenta",
- rowHeader: "rgb(231, 70, 148)",
- colHeader: "rgb(250, 209, 232)"
- }
- ], da = [
- {
- baseName: "blue",
- rowHeader: "rgb(30, 66, 159)",
- firstRow: "rgb(195, 221, 253)",
- secondRow: "rgb(118, 169, 250)"
- },
- {
- baseName: "grey",
- rowHeader: "rgb(44, 48, 64)",
- firstRow: "rgb(227, 229, 234)",
- secondRow: "rgb(151, 157, 172)"
- },
- {
- baseName: "red",
- rowHeader: "rgb(155, 28, 28)",
- firstRow: "rgb(251, 213, 213)",
- secondRow: "rgb(249, 128, 128)"
- },
- {
- baseName: "orange",
- rowHeader: "rgb(180, 52, 3)",
- firstRow: "rgb(252, 217, 189)",
- secondRow: "rgb(255, 138, 76)"
- },
- {
- baseName: "yellow",
- rowHeader: "rgb(154, 109, 21)",
- firstRow: "rgb(252, 220, 106)",
- secondRow: "rgb(212, 157, 15)"
- },
- {
- baseName: "green",
- rowHeader: "rgb(4, 108, 78)",
- firstRow: "rgb(188, 240, 218)",
- secondRow: "rgb(49, 196, 141)"
- },
- {
- baseName: "azure",
- rowHeader: "rgb(3, 102, 114)",
- firstRow: "rgb(175, 236, 239)",
- secondRow: "rgb(22, 189, 202)"
- },
- {
- baseName: "indigo",
- rowHeader: "rgb(16, 51, 191)",
- firstRow: "rgb(210, 218, 250)",
- secondRow: "rgb(98, 128, 249)"
- },
- {
- baseName: "purple",
- rowHeader: "rgb(74, 29, 150)",
- firstRow: "rgb(220, 215, 254)",
- secondRow: "rgb(172, 148, 250)"
- },
- {
- baseName: "magenta",
- rowHeader: "rgb(153, 21, 75)",
- firstRow: "rgb(250, 209, 232)",
- secondRow: "rgb(241, 126, 184)"
- }
- ], 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 = [
- ...ha,
- ...ma,
- ...ga
- ], Ra = {
- headerRowStyle: {
- bg: {
- rgb: "rgb(68,114,196)"
- },
- cl: {
- rgb: "rgb(255,255,255)"
- },
- ht: ro.CENTER,
- bl: te.TRUE
- },
- firstRowStyle: {
- bg: {
- rgb: "rgb(217,225,242)"
- }
- },
- lastRowStyle: {
- bd: {
- t: {
- s: Rs.THIN,
- cl: {
- rgb: "rgb(68,114,196)"
- }
- }
- },
- ht: ro.CENTER,
- bl: te.TRUE
- }
- }, pa = new yt("default", Ra);
- var Ca = Object.defineProperty, Sa = Object.getOwnPropertyDescriptor, wa = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Sa(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Ca(e, t, s), s;
- }, Ko = (n, e) => (t, o) => e(t, o, n);
- const Ia = "SHEET_RANGE_THEME_MODEL_PLUGIN";
- let He = class extends ae {
- constructor(e, t) {
- super();
- R(this, "_rangeThemeStyleMap", /* @__PURE__ */ new Map());
- R(this, "_rangeThemeStyleRuleMap", /* @__PURE__ */ new Map());
- R(this, "_rTreeCollection", /* @__PURE__ */ new Map());
- R(this, "_defaultRangeThemeMap", /* @__PURE__ */ new Map());
- this._sheetInterceptorService = e, this._resourceManagerService = t, this._registerIntercept(), this._initSnapshot(), this._initDefaultTheme();
- }
- _initDefaultTheme() {
- this.registerDefaultRangeTheme(pa);
- for (const e of fa)
- this.registerDefaultRangeTheme(e);
- }
- _ensureRangeThemeStyleMap(e) {
- return this._rangeThemeStyleMap.has(e) || this._rangeThemeStyleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleMap.get(e);
- }
- _ensureRangeThemeStyleRuleMap(e) {
- return this._rangeThemeStyleRuleMap.has(e) || this._rangeThemeStyleRuleMap.set(e, /* @__PURE__ */ new Map()), this._rangeThemeStyleRuleMap.get(e);
- }
- _ensureRTreeCollection(e) {
- return this._rTreeCollection.has(e) || this._rTreeCollection.set(e, new ui()), this._rTreeCollection.get(e);
- }
- getDefaultRangeThemeStyle(e) {
- return this._defaultRangeThemeMap.get(e);
- }
- /**
- * Register range theme styles
- * @param {string} themeName
- * @param {IRangeThemeRangeInfo} rangeInfo
- */
- registerRangeThemeRule(e, t) {
- const { unitId: o, subUnitId: s, range: r } = t, i = li(), a = this._ensureRangeThemeStyleRuleMap(o), u = this._ensureRTreeCollection(o);
- a.set(i, { rangeInfo: t, themeName: e }), u.insert({ unitId: o, sheetId: s, range: r, id: i });
- }
- getRegisteredRangeThemeStyle(e) {
- const { unitId: t, subUnitId: o, range: s } = e, r = this._ensureRTreeCollection(t), i = Array.from(r.bulkSearch([{ unitId: t, sheetId: o, range: s }]));
- if (i[0]) {
- const u = this._ensureRangeThemeStyleRuleMap(t).get(i[0]);
- if (u)
- return u.themeName;
- }
- }
- removeRangeThemeRule(e, t) {
- const { unitId: o, subUnitId: s, range: r } = t, i = this._ensureRTreeCollection(o), a = Array.from(i.bulkSearch([{ unitId: o, sheetId: s, range: r }]));
- if (a[0]) {
- const u = this._ensureRangeThemeStyleRuleMap(o), l = u.get(a[0]);
- l && l.themeName === e && (u.delete(a[0]), i.remove({ unitId: o, sheetId: s, range: r, id: a[0] }));
- }
- }
- registerDefaultRangeTheme(e) {
- this._defaultRangeThemeMap.set(e.getName(), e);
- }
- getRegisteredRangeThemes() {
- return Array.from(this._defaultRangeThemeMap.keys());
- }
- /**
- * Register custom range theme style.
- * @param {string} unitId The unit id.
- * @param {RangeThemeStyle} rangeThemeStyle The range theme style.
- */
- registerRangeThemeStyle(e, t) {
- this._ensureRangeThemeStyleMap(e).set(t.getName(), t);
- }
- /**
- * Unregister custom range theme style.
- * @param {string} unitId The unit id.
- * @param {string} name The name of the range theme style.
- */
- unregisterRangeThemeStyle(e, t) {
- this._ensureRangeThemeStyleMap(e).delete(t);
- }
- /**
- * Gets all custom register themes
- * @return {string[]} The array of all custom registered themes.
- */
- getALLRegisteredTheme() {
- return Array.from(this._rangeThemeStyleMap.keys());
- }
- getRangeThemeStyle(e, t) {
- return this._defaultRangeThemeMap.has(t) ? this._defaultRangeThemeMap.get(t) : this._ensureRangeThemeStyleMap(e).get(t);
- }
- getCellStyle(e, t, o, s) {
- const r = { startRow: o, startColumn: s, endRow: o, endColumn: s }, i = this._ensureRTreeCollection(e), a = Array.from(i.bulkSearch([{ unitId: e, sheetId: t, range: r }]));
- if (a[0]) {
- const l = this._ensureRangeThemeStyleRuleMap(e).get(a[0]);
- if (l) {
- const { rangeInfo: c, themeName: d } = l, h = o - c.range.startRow, m = s - c.range.startColumn;
- return this.getRangeThemeStyle(e, d).getStyle(h, m, o === c.range.endRow, s === c.range.endColumn);
- }
- }
- }
- _registerIntercept() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(et.CELL_CONTENT, {
- id: Ns,
- effect: me.Style,
- handler: (e, t, o) => {
- const { row: s, col: r, unitId: i, subUnitId: a } = t, u = this.getCellStyle(i, a, s, r);
- if (u) {
- const l = { ...e };
- return l.themeStyle = u, o(l);
- }
- return o(e);
- }
- }));
- }
- toJson(e) {
- const t = this._ensureRangeThemeStyleRuleMap(e), o = this._ensureRangeThemeStyleMap(e);
- if (o.size === 0 && t.size === 0)
- return "{}";
- const s = {};
- t.forEach((i, a) => {
- s[a] = i;
- });
- const r = {};
- return o.forEach((i, a) => {
- r[a] = i.toJson();
- }), JSON.stringify({
- rangeThemeStyleRuleMap: s,
- rangeThemeStyleMapJson: r
- });
- }
- fromJSON(e) {
- const { rangeThemeStyleRuleMap: t, rangeThemeStyleMapJson: o } = e;
- this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._rTreeCollection.clear(), !(!t || !o) && (Object.keys(t).forEach((s) => {
- const r = t[s], { themeName: i, rangeInfo: a } = r;
- this.registerRangeThemeRule(i, a), this._ensureRTreeCollection(a.unitId).insert({ unitId: s, sheetId: a.subUnitId, range: a.range, id: s });
- }), Object.keys(o).forEach((s) => {
- const r = o[s], i = new yt(r.name);
- i.fromJson(r), this._ensureRangeThemeStyleMap(s).set(i.getName(), i);
- }));
- }
- deleteUnitId(e) {
- this._rangeThemeStyleMap.delete(e), this._rangeThemeStyleRuleMap.delete(e), this._rTreeCollection.delete(e);
- }
- _initSnapshot() {
- this.disposeWithMe(this._resourceManagerService.registerPluginResource({
- toJson: (e) => this.toJson(e),
- parseJson: (e) => {
- if (!e)
- return {};
- try {
- return JSON.parse(e);
- } catch {
- return {};
- }
- },
- businesses: [B.UNIVER_SHEET],
- pluginName: Ia,
- onLoad: (e, t) => {
- this.fromJSON(t);
- },
- onUnLoad: (e) => {
- this.deleteUnitId(e);
- }
- }));
- }
- dispose() {
- super.dispose(), this._rangeThemeStyleMap.clear(), this._rangeThemeStyleRuleMap.clear(), this._defaultRangeThemeMap.clear(), this._rTreeCollection.clear();
- }
- };
- He = wa([
- Ko(0, L(V)),
- Ko(1, L(nn))
- ], He);
- function va(n, e) {
- const { unitId: t } = e, o = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(B.UNIVER_SHEET);
- return o ? {
- workbook: o,
- unitId: o.getUnitId()
- } : null;
- }
- function N(n, e = {}) {
- const { unitId: t, subUnitId: o } = e, s = t ? n.getUniverSheetInstance(t) : n.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!s) return null;
- const r = o ? s.getSheetBySheetId(o) : s.getActiveSheet(!0);
- return r ? {
- worksheet: r,
- workbook: s,
- unitId: s.getUnitId(),
- subUnitId: r.getSheetId()
- } : null;
- }
- function Et(n, e) {
- const { unitId: t, subUnitId: o } = e, s = n.getUniverSheetInstance(t);
- if (!s) return null;
- const r = s.getSheetBySheetId(o);
- return r ? {
- worksheet: r,
- workbook: s
- } : null;
- }
- const zt = {
- id: "sheet.mutation.set-worksheet-range-theme-style",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = N(i), u = n.get(He);
- return a ? (u.registerRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1;
- }
- }, Ma = (n, e) => {
- const t = Et(n.get(M), e);
- if (!t)
- throw new Error("[SetWorksheetRangeThemeStyleMutation]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- subUnitId: o.getSheetId(),
- range: e.range,
- themeName: e.themeName
- };
- }, Kt = {
- id: "sheet.mutation.remove-worksheet-range-theme-style",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, range: s, themeName: r } = e, i = n.get(M), a = N(i), u = n.get(He);
- return a ? (u.removeRangeThemeRule(r, { range: s, unitId: t, subUnitId: o }), !0) : !1;
- }
- }, _a = (n, e) => {
- const t = Et(n.get(M), e);
- if (!t)
- throw new Error("[DeleteWorksheetRangeThemeStyleMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- subUnitId: o.getSheetId(),
- range: e.range,
- themeName: e.themeName
- };
- }, ba = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-range-theme-style",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), { unitId: s } = e, r = Ma(n, e);
- return t.syncExecuteCommand(zt.id, e) ? (o.pushUndoRedo({
- unitID: s,
- undoMutations: [{ id: Kt.id, params: r }],
- redoMutations: [{ id: zt.id, params: e }]
- }), !0) : !1;
- }
- }, ya = (n, e, t = "") => n.reduce(
- (o, s) => {
- const r = s && s[e];
- return typeof r != "string" ? (console.warn(s, `${e} is not string`), o) : (r ? (o[r] || (o[r] = []), o[r].push(s)) : o[t].push(s), o);
- },
- {}
- ), Ea = (n = 0) => {
- let e = n;
- return function() {
- return e++;
- };
- };
- function Os(n) {
- const e = new G();
- return n.forEach((t) => {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
- for (let a = o; a <= r; a++)
- for (let u = s; u <= i; u++)
- e.setValue(a, u, null);
- }), e.clone();
- }
- function Ua(n) {
- const e = new G();
- return n.forEach((t) => {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
- for (let a = o; a <= r; a++)
- for (let u = s; u <= i; u++)
- e.setValue(a, u, {
- v: null,
- p: null,
- f: null,
- si: null,
- custom: null
- });
- }), e.clone();
- }
- function Pa(n) {
- const e = new G();
- return n.forEach((t) => {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = t;
- for (let a = o; a <= r; a++)
- for (let u = s; u <= i; u++)
- e.setValue(a, u, {
- s: null
- });
- }), e.clone();
- }
- var Ce = /* @__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 || {});
- class Ta extends ae {
- constructor(t) {
- super();
- /**
- * Selection data model for each worksheet.
- */
- R(this, "_worksheetSelections", /* @__PURE__ */ new Map());
- R(this, "_selectionMoveStart$", new Le());
- R(this, "selectionMoveStart$", this._selectionMoveStart$.asObservable());
- R(this, "_selectionMoving$", new Le());
- R(this, "selectionMoving$", this._selectionMoving$.asObservable());
- R(this, "_selectionMoveEnd$", new at([]));
- R(this, "selectionMoveEnd$", this._selectionMoveEnd$.asObservable());
- R(this, "_selectionSet$", new at([]));
- R(this, "selectionSet$", this._selectionSet$.asObservable());
- R(this, "selectionChanged$");
- R(this, "_beforeSelectionMoveEnd$", new at([]));
- R(this, "beforeSelectionMoveEnd$", this._beforeSelectionMoveEnd$.asObservable());
- this._workbook = t, this.selectionChanged$ = xt(this._selectionMoveEnd$, this._selectionSet$);
- }
- dispose() {
- super.dispose(), this._beforeSelectionMoveEnd$.complete(), this._selectionMoveEnd$.complete(), this._selectionMoving$.complete(), this._selectionMoveStart$.complete(), this._selectionSet$.complete();
- }
- addSelections(t, o) {
- const s = this.getSelectionsOfWorksheet(t);
- s.push(...o), this._selectionSet$.next(s);
- }
- /**
- * Set selectionDatas to _worksheetSelections, and emit selectionDatas by type.
- * @param sheetId
- * @param selectionDatas
- * @param type
- */
- setSelections(t, o = [], s) {
- switch (this.setSelectionsOfWorksheet(t, o), s) {
- case Ce.MOVE_START:
- this._selectionMoveStart$.next(o);
- break;
- case Ce.MOVING:
- this._selectionMoving$.next(o);
- break;
- case Ce.MOVE_END:
- this._beforeSelectionMoveEnd$.next(o), this._selectionMoveEnd$.next(o);
- break;
- case Ce.ONLY_SET: {
- this._selectionSet$.next(o);
- break;
- }
- default:
- this._selectionSet$.next(o);
- break;
- }
- }
- getCurrentSelections() {
- return this._getCurrentSelections();
- }
- /**
- * @deprecated use `getSelectionsOfWorksheet` instead.
- * @param sheetId
- * @returns
- */
- getSelectionOfWorksheet(t) {
- return this.getSelectionsOfWorksheet(t);
- }
- getSelectionsOfWorksheet(t) {
- return this._worksheetSelections.has(t) || this._worksheetSelections.set(t, []), this._worksheetSelections.get(t);
- }
- setSelectionsOfWorksheet(t, o) {
- this._worksheetSelections.set(t, [...o]);
- }
- deleteSheetSelection(t) {
- this._worksheetSelections.set(t, []);
- }
- /** Clear all selections in this workbook. */
- clear() {
- this._worksheetSelections.clear(), this._selectionSet$.next([]);
- }
- _getCurrentSelections() {
- return this.getSelectionsOfWorksheet(this._workbook.getActiveSheet().getSheetId());
- }
- getCurrentLastSelection() {
- const t = this._getCurrentSelections();
- return t[t.length - 1];
- }
- }
- var ka = Object.defineProperty, Na = Object.getOwnPropertyDescriptor, Oa = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Na(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && ka(e, t, s), s;
- }, Da = (n, e) => (t, o) => e(t, o, n);
- let F = class extends ps {
- constructor(e) {
- super();
- /**
- * Selection Events, usually triggered when pointerdown in spreadsheet by selection render service after selectionModel has updated.
- */
- R(this, "selectionMoveStart$");
- /**
- * Selection Events, usually triggered when pointermove in spreadsheet by selection render service after selectionModel has updated.
- */
- R(this, "selectionMoving$");
- /**
- * Selection Events, usually triggered when pointerup in spreadsheet by selection render service after selectionModel has updated.
- */
- R(this, "selectionMoveEnd$");
- /**
- * Selection Events, usually triggered when changing unit.(focus in formula editor)
- */
- R(this, "selectionSet$");
- /**
- * Selection Events, merge moveEnd$ and selectionSet$
- */
- R(this, "selectionChanged$");
- R(this, "_workbookSelections", /* @__PURE__ */ new Map());
- this._instanceSrv = e, this._init();
- }
- get _currentSelectionPos() {
- const e = this._instanceSrv.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!e) return null;
- const t = e.getActiveSheet();
- return { unitId: e.getUnitId(), sheetId: t.getSheetId() };
- }
- get currentSelectionParam() {
- return this._currentSelectionPos;
- }
- _init() {
- const e = this._instanceSrv.getCurrentTypeOfUnit$(B.UNIVER_SHEET).pipe(ji(1), io(this.dispose$));
- 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(
- 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]))),
- Ts(1)
- ), this._instanceSrv.getTypeOfUnitDisposed$(B.UNIVER_SHEET).pipe(io(this.dispose$)).subscribe((t) => {
- this._removeWorkbookSelection(t.getUnitId());
- });
- }
- /**
- * Clear all selections in all workbooks.
- * invoked by prompt.controller
- */
- clear() {
- this._workbookSelections.forEach((e) => e.clear());
- }
- getCurrentSelections() {
- return this._getCurrentSelections();
- }
- getCurrentLastSelection() {
- const e = this._getCurrentSelections();
- return e == null ? void 0 : e[e.length - 1];
- }
- addSelections(e, t, o) {
- if (typeof e == "string") {
- this._ensureWorkbookSelection(e).addSelections(t, o);
- return;
- }
- const s = this._currentSelectionPos;
- if (!s)
- throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
- const { unitId: r, sheetId: i } = s;
- this._ensureWorkbookSelection(r).addSelections(i, e);
- }
- setSelections(e, t, o, s) {
- if (typeof e == "string" && typeof t == "string") {
- const u = e;
- this._ensureWorkbookSelection(u).setSelections(
- t,
- o || [],
- s != null ? s : Ce.ONLY_SET
- );
- return;
- }
- const r = this._currentSelectionPos;
- if (!r)
- throw new Error("[SheetsSelectionsService]: cannot find current selection position!");
- const { unitId: i, sheetId: a } = r;
- if (typeof e == "object") {
- const u = e != null ? e : o, l = t != null ? t : Ce.ONLY_SET;
- this._ensureWorkbookSelection(i).setSelections(a, u, l);
- }
- }
- clearCurrentSelections() {
- this._getCurrentSelections().splice(0);
- }
- /**
- * Determine whether multiple current selections overlap
- *
- * @deprecated this should be extracted to an pure function
- */
- isOverlapping() {
- const e = this.getCurrentSelections();
- return e == null ? !1 : e.some(
- ({ 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)
- );
- }
- _getCurrentSelections() {
- const e = this._currentSelectionPos;
- if (!e)
- return [];
- const { unitId: t, sheetId: o } = e;
- return this._ensureWorkbookSelection(t).getSelectionsOfWorksheet(o);
- }
- getWorkbookSelections(e) {
- return this._ensureWorkbookSelection(e);
- }
- _ensureWorkbookSelection(e) {
- let t = this._workbookSelections.get(e);
- if (!t) {
- const o = this._instanceSrv.getUnit(e);
- if (!o)
- throw new Error(`[SheetsSelectionsService]: cannot resolve unit with id "${e}"!`);
- t = new Ta(o), this._workbookSelections.set(e, t);
- }
- return t;
- }
- _removeWorkbookSelection(e) {
- this._workbookSelections.delete(e);
- }
- };
- F = Oa([
- Da(0, M)
- ], F);
- const jd = "DISABLE_NORMAL_SELECTIONS", Gd = "SELECTIONS_ENABLED", Aa = "REF_SELECTIONS_ENABLED";
- function xa(n, e, t) {
- var i;
- const o = n.getStyleByCell(e);
- o == null && delete e.s, typeof t.s == "string" && (t.s = n.get(t.s));
- const s = gn(o, t.s ? t.s : null);
- s && (O.removeNull(s), Object.entries(s).forEach(([a, u]) => {
- typeof u == "object" && u !== null && Object.keys(u).length === 0 && delete s[a];
- })), O.isEmptyObject(s) ? delete e.s : e.s = n.setValue(s);
- const r = t.v ? `${t.v}\r
- ` : "";
- !t.p && e.p && (r && r !== ((i = e.p.body) == null ? void 0 : i.dataStream) ? delete e.p : La(e.p, t.s ? t.s : null));
- }
- function $a(n, e) {
- if (!e || !Object.keys(e).length)
- return n;
- const t = n || {};
- for (const o in e)
- o === "bd" ? t[o] = Wa(t[o] || {}, e[o]) : o in t || (t[o] = null);
- return t;
- }
- function Wa(n, e) {
- if (!e || !Object.keys(e).length)
- return n;
- for (const t in e)
- t in n || (n[t] = null);
- return n;
- }
- function gn(n, e, t = !1) {
- if (e === null) return e;
- if (e === void 0) return n;
- const o = O.deepClone(n) || {};
- for (const s in e)
- t && ["bd", "tr", "td", "ht", "vt", "tb", "pd", "bg"].includes(s) || (s in o && s === "bd" ? o[s] = Object.assign(o[s], e[s]) : o[s] = e[s]);
- return "cl" in o && ("ul" in o && o.ul && (o.ul.cl = o.cl), "ol" in o && o.ol && (o.ol.cl = o.cl), "st" in o && o.st && (o.st.cl = o.cl)), o;
- }
- function Ds(n, e) {
- return n.some((t) => t.startIndex === e) ? Ds(n, e + 1) : e;
- }
- function La(n, e) {
- var i;
- if (n.body == null)
- return;
- Array.isArray(n.body.textRuns) || (n.body.textRuns = []);
- let t = 0;
- const o = [], s = ((i = n.body) == null ? void 0 : i.paragraphs) || [];
- for (const a of n.body.textRuns) {
- const { st: u, ed: l, ts: c = {} } = a;
- if (t < u) {
- const h = {
- st: t,
- ed: u
- }, m = gn({}, e, !0);
- m && O.removeNull(m), O.isEmptyObject(m) || (h.ts = m), o.push(h);
- }
- const d = gn(c, e, !0);
- d && O.removeNull(d), O.isEmptyObject(d) ? delete a.ts : a.ts = d, o.push(a), t = Ds(s, l);
- }
- const r = n.body.dataStream.endsWith(`\r
- `) ? n.body.dataStream.length - 2 : n.body.dataStream.length;
- if (t < r) {
- const a = {
- st: t,
- ed: r
- }, u = gn({}, e, !0);
- u && O.removeNull(u), O.isEmptyObject(u) || (a.ts = u), o.push(a);
- }
- n.body.textRuns = ci(o);
- }
- function Va(n, e, t) {
- if (e.t) return e.t;
- if (e.v === null) return null;
- const o = n.getStyleByCell(e), s = n.getStyleByCell(t);
- if (t.t === se.FORCE_STRING) {
- if (!Qn(s) && e.v !== void 0) {
- if (go(e.v))
- return se.NUMBER;
- if (Cs(`${e.v}`))
- return se.BOOLEAN;
- }
- return se.FORCE_STRING;
- }
- return Ha(o) ? Qn(o) ? se.STRING : Jo(e, t) : Qn(s) ? se.STRING : Jo(e, t);
- }
- function Jo(n, e) {
- return n.v !== void 0 ? Yo(n.v, n.t) : Yo(e.v, e.t);
- }
- function Ha(n) {
- var e;
- return !!((e = n == null ? void 0 : n.n) != null && e.pattern);
- }
- function Qn(n) {
- var e;
- return ((e = n == null ? void 0 : n.n) == null ? void 0 : e.pattern) === ks;
- }
- function Yo(n, e) {
- 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;
- }
- function Xo(n, e) {
- 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;
- }
- function Ba(n) {
- if (typeof n == "string") {
- if (n.toUpperCase() === "TRUE")
- return !0;
- if (n.toUpperCase() === "FALSE")
- return !1;
- if (di(n)) {
- if (Number(n) === 0)
- return !1;
- if (Number(n) === 1)
- return !0;
- }
- }
- if (typeof n == "number") {
- if (n === 0)
- return !1;
- if (n === 1)
- return !0;
- }
- return typeof n == "boolean" ? n : null;
- }
- function Fa(n) {
- return n == null ? null : (n.f === void 0 && (n.f = null), n.si === void 0 && (n.si = null), n.p === void 0 && (n.p = null), n.v === void 0 && (n.v = null), n.t === void 0 && (n.t = null), n.s === void 0 && (n.s = null), n.custom === void 0 && (n.custom = null), n);
- }
- const Ae = (n, e) => {
- const { unitId: t, subUnitId: o, cellValue: s } = e, i = n.get(M).getUniverSheetInstance(t);
- if (i == null)
- throw new Error("workbook is null error!");
- const a = i.getSheetBySheetId(o);
- if (a == null)
- throw new Error("worksheet is null error!");
- const u = a.getCellMatrix(), l = i.getStyles(), c = new G();
- return new G(s).forValue((h, m, g) => {
- const f = O.deepClone(u == null ? void 0 : u.getValue(h, m)) || {}, p = l.getStyleByCell(f), C = l.getStyleByCell(g);
- f.s = $a(p, C), c.setValue(h, m, Fa(f));
- }), {
- ...e,
- options: {},
- cellValue: c.getMatrix()
- };
- }, Q = {
- id: "sheet.mutation.set-range-values",
- type: v.MUTATION,
- handler: (n, e) => {
- const { cellValue: t, subUnitId: o, unitId: s } = e, i = n.get(M).getUnit(s);
- if (!i)
- return !1;
- const a = i.getSheetBySheetId(o);
- if (!a)
- return !1;
- const u = a.getCellMatrix(), l = i.getStyles();
- return new G(t).forValue((d, h, m) => {
- if (!m)
- u == null || u.setValue(d, h, {});
- else {
- const g = u.getValue(d, h) || {}, f = Va(l, m, g);
- 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));
- }
- }), !0;
- }
- }, po = {
- id: "sheet.command.clear-selection-all",
- type: v.COMMAND,
- handler: (n, e) => {
- var S;
- 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);
- if (!a) return !1;
- const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
- if (!l) return !1;
- const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range));
- if (!(d != null && d.length))
- return !1;
- const h = [], m = [], g = {
- subUnitId: c,
- unitId: u,
- cellValue: Os(d)
- }, f = Ae(
- n,
- g
- );
- h.push({
- id: Q.id,
- params: g
- }), m.push({
- id: Q.id,
- params: f
- });
- const p = i.onCommandExecute({ id: po.id });
- return h.push(...p.redos), m.unshift(...p.undos), z(h, o) ? (r.pushUndoRedo({
- // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
- // Hooks can be used to hook the code of external controllers to add new actions.
- unitID: u,
- undoMutations: m,
- redoMutations: h
- }), !0) : !1;
- }
- }, Co = {
- id: "sheet.command.clear-selection-content",
- type: v.COMMAND,
- handler: (n, e) => {
- var S;
- 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);
- if (!a) return !1;
- const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
- if (!l) return !1;
- const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range));
- if (!(d != null && d.length))
- return !1;
- const h = {
- subUnitId: c,
- unitId: u,
- cellValue: Ua(d)
- }, m = Ae(
- n,
- h
- ), g = i.onCommandExecute({ id: Co.id }), f = [{ id: Q.id, params: h }, ...g.redos], p = [...g.undos, { id: Q.id, params: m }];
- return z(f, o).result ? (r.pushUndoRedo({
- // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
- // Hooks can be used to hook the code of external controllers to add new actions.
- unitID: u,
- undoMutations: p,
- redoMutations: f
- }), !0) : !1;
- }
- }, So = {
- id: "sheet.command.clear-selection-format",
- type: v.COMMAND,
- handler: (n, e) => {
- var S;
- 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);
- if (!a) return !1;
- const u = (e == null ? void 0 : e.unitId) || a.getUnitId(), l = a.getActiveSheet();
- if (!l) return !1;
- const c = (e == null ? void 0 : e.subUnitId) || l.getSheetId(), d = (e == null ? void 0 : e.ranges) || ((S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range));
- if (!(d != null && d.length))
- return !1;
- const h = [], m = [], g = {
- subUnitId: c,
- unitId: u,
- cellValue: Pa(d)
- }, f = Ae(
- n,
- g
- );
- h.push({
- id: Q.id,
- params: g
- }), m.push({
- id: Q.id,
- params: f
- });
- const p = i.onCommandExecute({ id: So.id });
- return h.push(...p.redos), m.unshift(...p.undos), z(h, o) ? (r.pushUndoRedo({
- // If there are multiple mutations that form an encapsulated project, they must be encapsulated in the same undo redo element.
- // Hooks can be used to hook the code of external controllers to add new actions.
- unitID: u,
- undoMutations: m,
- redoMutations: h
- }), !0) : !1;
- }
- }, As = (n, e) => ({
- subUnitId: e.sheet.id,
- unitId: e.unitId,
- subUnitName: e.sheet.name
- }), Jt = {
- id: "sheet.mutation.insert-sheet",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M), { sheet: o, index: s, unitId: r } = e, i = t.getUniverSheetInstance(r);
- return i ? i.addWorksheet(o.id, s, o) : !1;
- }
- }, ja = (n, e) => {
- const t = n.get(M), { subUnitId: o, unitId: s } = e, r = Et(t, e);
- if (!r)
- throw new Error("[RemoveSheetUndoMutationFactory]: Worksheet is null error!");
- const { workbook: i, worksheet: a } = r, u = a.getConfig();
- return {
- index: i.getConfig().sheetOrder.findIndex((d) => d === o),
- sheet: u,
- unitId: s
- };
- }, Ut = {
- id: "sheet.mutation.remove-sheet",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M), { subUnitId: o, unitId: s } = e, r = t.getUniverSheetInstance(s);
- return r ? r.removeSheet(o) : !1;
- }
- }, xs = {
- type: v.COMMAND,
- id: "sheet.command.copy-sheet",
- handler: (n, e) => {
- var w, b;
- 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);
- if (!a)
- return !1;
- const { workbook: u, worksheet: l, unitId: c, subUnitId: d } = a, h = O.deepClone(l.getConfig());
- h.name = Ga(u, i, h.name), h.id = O.generateRandomId();
- const g = {
- index: u.getSheetIndex(l) + 1,
- sheet: h,
- unitId: c
- }, f = As(
- n,
- g
- ), p = r.onCommandExecute({
- id: xs.id,
- params: { unitId: c, subUnitId: d, targetSubUnitId: h.id }
- }), C = [
- ...(w = p.preRedos) != null ? w : [],
- { id: Jt.id, params: g },
- ...p.redos
- ], S = [
- ...(b = p.preUndos) != null ? b : [],
- { id: Ut.id, params: f },
- ...p.undos
- ];
- return z(C, t).result ? (o.pushUndoRedo({
- unitID: c,
- undoMutations: S,
- redoMutations: C
- }), !0) : !1;
- }
- };
- function Ga(n, e, t) {
- let o = t + e.t("sheets.tabs.sheetCopy", ""), s = 2;
- for (; n.checkSheetName(o); )
- o = t + e.t("sheets.tabs.sheetCopy", `${s}`), s++;
- return o;
- }
- const dt = {
- id: "sheet.mutation.move-range",
- type: v.MUTATION,
- handler: (n, e) => {
- const { from: t, to: o } = e;
- if (!t || !o)
- return !1;
- const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
- if (!r)
- return !1;
- const i = r.getSheetBySheetId(e.from.subUnitId), a = r.getSheetBySheetId(e.to.subUnitId);
- if (!i || !a)
- return !1;
- const u = i.getCellMatrix(), l = a.getCellMatrix();
- return new G(t.value).forValue((c, d, h) => {
- u.setValue(c, d, h);
- }), new G(o.value).forValue((c, d, h) => {
- l.setValue(c, d, h);
- }), !0;
- }
- };
- var za = Object.defineProperty, Ka = Object.getOwnPropertyDescriptor, Ja = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Ka(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && za(e, t, s), s;
- }, Ya = (n, e) => (t, o) => e(t, o, n);
- const Xa = fo("sheets-formula.ref-selections.service");
- let qo = class extends F {
- constructor(n) {
- super(n);
- }
- _init() {
- const n = this._getAliveWorkbooks$().pipe(io(this.dispose$));
- 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$))));
- }
- _getAliveWorkbooks$() {
- const n = this._instanceSrv.getAllUnitsForType(B.UNIVER_SHEET);
- n.forEach((t) => this._ensureWorkbookSelection(t.getUnitId()));
- const e = new at(n);
- return this.disposeWithMe(this._instanceSrv.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((t) => {
- this._ensureWorkbookSelection(t.getUnitId()), e.next([...e.getValue(), t]);
- })), this.disposeWithMe(this._instanceSrv.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe((t) => {
- this._removeWorkbookSelection(t.getUnitId()), e.next(e.getValue().filter((o) => o !== t));
- })), e.pipe(ao((t) => t.map((o) => this._ensureWorkbookSelection(o.getUnitId()))));
- }
- };
- qo = Ja([
- Ya(0, M)
- ], qo);
- function qa(n, e) {
- const o = n.get(Ss).getContextValue(Aa);
- return n.get(o && !e ? Xa : F);
- }
- const re = {
- id: "sheet.operation.set-selections",
- type: v.OPERATION,
- handler: (n, e) => {
- if (!e) return !1;
- const { selections: t, type: o, unitId: s, subUnitId: r } = e;
- return qa(n).setSelections(s, r, [...t], o), !0;
- }
- };
- function Ln(n, e, t = !0) {
- const o = e.getMatrixWithMergedCells(...hi(n)), s = [];
- if (o.forValue((i, a, u) => {
- if (u.colSpan !== void 0 && u.rowSpan !== void 0) {
- const l = {
- startRow: i,
- startColumn: a,
- endRow: i + u.rowSpan - 1,
- endColumn: a + u.colSpan - 1
- };
- k.contains(n, l) || s.push(l);
- }
- }), s.length === 0)
- return n;
- const r = k.union(n, ...s);
- return t ? Ln(r, e, t) : r;
- }
- function zd(n, e, t) {
- let o = null;
- return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = {
- actualRow: r,
- actualColumn: i,
- startRow: r,
- startColumn: i,
- isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0,
- isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0,
- endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0),
- endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0),
- rangeType: H.NORMAL
- }, !1)), o || {
- actualColumn: e,
- actualRow: n,
- startRow: n,
- startColumn: e,
- endRow: n,
- endColumn: e,
- isMerged: !1,
- isMergedMainCell: !1,
- rangeType: H.NORMAL
- };
- }
- function Kd(n, e, t) {
- const { startRow: o, startColumn: s, endRow: r, endColumn: i } = n;
- return Number.isNaN(o) && (n.startRow = 0), Number.isNaN(r) && (n.endRow = e - 1), Number.isNaN(s) && (n.startColumn = 0), Number.isNaN(i) && (n.endColumn = t - 1), n;
- }
- function ve(n, e) {
- const t = Number.isNaN(n.startRow) ? 0 : n.startRow, o = Number.isNaN(n.startColumn) ? 0 : n.startColumn, s = e.getMergedCell(t, o);
- return s ? {
- ...s,
- actualRow: t,
- actualColumn: o,
- rangeType: H.NORMAL,
- isMerged: !0,
- isMergedMainCell: !0
- } : {
- startRow: t,
- startColumn: o,
- endRow: n.startRow,
- endColumn: n.startColumn,
- actualRow: t,
- actualColumn: o,
- rangeType: H.NORMAL,
- isMerged: !1,
- isMergedMainCell: !1
- };
- }
- const Xe = (n, e, t) => ({
- id: re.id,
- params: {
- unitId: e.getUnitId(),
- subUnitId: t.getSheetId(),
- reveal: !0,
- selections: [{ range: n, primary: ve(n, t) }]
- }
- });
- function Jd(n) {
- if (!n)
- return !1;
- const { range: e, primary: t } = n;
- return k.equals(e, t);
- }
- function Za(n) {
- function e(t, o) {
- function s(r) {
- for (let i = r.startRow; i <= r.endRow; i++)
- if (!n.getRowFiltered(i))
- for (let a = r.startColumn; a <= r.endColumn; a++)
- o(i, a, r);
- }
- s(t);
- }
- return {
- forOperableEach: e
- };
- }
- const Zo = (n) => n.id !== Ns;
- function Vn(n, e, t, o, s, r, i) {
- const a = {};
- for (let u = e; u <= t; u++)
- for (let l = o; l <= s; l++) {
- const c = r ? n.getCellWithFilteredInterceptors(i, l, jo, Zo) : n.getCellWithFilteredInterceptors(u, i, jo, Zo);
- !c || !c.s || (a[u] || (a[u] = {}), a[u][l] = { s: c.s });
- }
- return a;
- }
- const $s = "sheet.command.move-range", pt = {
- type: v.COMMAND,
- id: $s,
- handler: async (n, e) => {
- var I, w;
- 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);
- if (!u || !await a.beforeCommandExecute({ id: pt.id, params: e }))
- return !1;
- const { worksheet: c, subUnitId: d, unitId: h } = u, m = wo(
- n,
- { unitId: h, subUnitId: d, range: e.fromRange },
- { unitId: h, subUnitId: d, range: e.toRange }
- );
- if (m === null)
- return r.emit(i.t("sheets.info.acrossMergedCell")), !1;
- const g = a.onCommandExecute({
- id: pt.id,
- params: { ...e }
- }), f = [
- ...(I = g.preRedos) != null ? I : [],
- ...m.redos,
- ...g.redos,
- {
- id: re.id,
- params: {
- unitId: h,
- subUnitId: d,
- selections: [{ range: e.toRange, primary: Qa(e.fromRange, e.toRange, c) }],
- type: Ce.MOVE_END
- }
- }
- ], p = [
- ...(w = g.preUndos) != null ? w : [],
- ...m.undos,
- ...g.undos,
- {
- id: re.id,
- params: {
- unitId: h,
- subUnitId: d,
- selections: [{ range: e.fromRange, primary: ve(e.fromRange, c) }],
- type: Ce.MOVE_END
- }
- }
- ], C = z(f, t).result, S = a.afterCommandExecute({
- id: pt.id,
- params: { ...e }
- });
- return C ? (z(S.redos, t), o.pushUndoRedo({
- unitID: h,
- undoMutations: [...p, ...S.undos],
- redoMutations: [...f, ...S.redos]
- }), !0) : !1;
- }
- };
- function wo(n, e, t, o = !1) {
- 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();
- if (m && g && f && p) {
- const C = Ln(l, m, !1);
- if (!k.equals(l, C) && !o)
- return null;
- const S = new G(), I = new G(), w = new G();
- K.foreach(i, (U, P) => {
- const A = p.getValue(U, P);
- if (S.setValue(U, P, O.deepClone(A)), A) {
- const j = h == null ? void 0 : h.getStyles().get(A.s);
- w.setValue(U, P, O.deepClone(j));
- }
- I.setValue(U, P, null);
- });
- const b = new G(), y = new G();
- K.foreach(l, (U, P) => {
- b.setValue(U, P, O.deepClone(f.getValue(U, P)));
- }), K.foreach(i, (U, P) => {
- 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));
- ee && Y && (ee.s = Y), y.setValue(Z.startRow, Z.startColumn, ee);
- });
- const x = {
- fromRange: e.range,
- toRange: t.range,
- from: {
- value: I.getMatrix(),
- subUnitId: a
- },
- to: {
- value: y.getMatrix(),
- subUnitId: c
- },
- unitId: u
- }, T = {
- fromRange: t.range,
- toRange: e.range,
- from: {
- value: S.getMatrix(),
- subUnitId: a
- },
- to: {
- value: b.getMatrix(),
- subUnitId: c
- },
- unitId: u
- };
- s.push({ id: dt.id, params: x }), r.push({ id: dt.id, params: T });
- }
- return {
- redos: s,
- undos: r
- };
- }
- function Qa(n, e, t) {
- const o = n.startRow, s = n.startColumn, r = t.getMergedCell(o, s), i = ve(e, t);
- if (r) {
- const a = r.endRow - r.startRow + 1, u = r.endColumn - r.startColumn + 1;
- i.endRow = i.startRow + a - 1, i.endColumn = i.startColumn + u - 1, i.actualRow = i.startRow, i.actualColumn = i.startColumn, i.isMerged = !1, i.isMergedMainCell = !0;
- }
- return i;
- }
- 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 || {});
- class Pe {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.Edit);
- R(this, "status", J.INIT);
- R(this, "value", !0);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Edit}.${o}`;
- }
- }
- class Io {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.View);
- R(this, "status", J.INIT);
- R(this, "value", !0);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.View}.${o}`;
- }
- }
- class Ws {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Comment);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Comment}_${e}`;
- }
- }
- class Ls {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Copy);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Copy}_${e}`;
- }
- }
- class eu {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "subType", _.CopySheet);
- R(this, "status", J.INIT);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CopySheet}_${e}`;
- }
- }
- class Vs {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.CreatePermissionObject);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreatePermissionObject}_${e}`;
- }
- }
- class Hs {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.CreateSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.CreateSheet}_${e}`;
- }
- }
- class Bs {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.DeleteSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.DeleteSheet}_${e}`;
- }
- }
- class Fs {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Duplicate);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Duplicate}_${e}`;
- }
- }
- class Me {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Edit);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Edit}_${e}`;
- }
- }
- class js {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Export);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Export}_${e}`;
- }
- }
- class vo {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.HideSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.HideSheet}_${e}`;
- }
- }
- class tu {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.History);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.History}_${e}`;
- }
- }
- class Mo {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.ManageCollaborator);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ManageCollaborator}_${e}`;
- }
- }
- class _o {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.MoveSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.MoveSheet}_${e}`;
- }
- }
- class Gs {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Print);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Print}_${e}`;
- }
- }
- class zs {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.RecoverHistory);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RecoverHistory}_${e}`;
- }
- }
- class bo {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.RenameSheet);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.RenameSheet}_${e}`;
- }
- }
- class Ks {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.Share);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.Share}_${e}`;
- }
- }
- class Js {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.View);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.View}_${e}`;
- }
- }
- class Ys {
- constructor(e) {
- R(this, "id");
- R(this, "value", !0);
- R(this, "type", D.Workbook);
- R(this, "status", J.INIT);
- R(this, "subType", _.ViewHistory);
- this.unitId = e, this.unitId = e, this.id = `${this.type}.${_.ViewHistory}_${e}`;
- }
- }
- class Xs {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.Copy);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Copy}_${e}_${t}`;
- }
- }
- class qs {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.DeleteColumn);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteColumn}_${e}_${t}`;
- }
- }
- class Zs {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.Delete);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Delete}_${e}_${t}`;
- }
- }
- class Qs {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.DeleteRow);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.DeleteRow}_${e}_${t}`;
- }
- }
- class Te {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.Edit);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Edit}_${e}_${t}`;
- }
- }
- class er {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.EditExtraObject);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.EditExtraObject}_${e}_${t}`;
- }
- }
- class tr {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.Filter);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Filter}_${e}_${t}`;
- }
- }
- class nr {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.InsertColumn);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertColumn}_${e}_${t}`;
- }
- }
- class or {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.InsertHyperlink);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertHyperlink}_${e}_${t}`;
- }
- }
- class sr {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.InsertRow);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.InsertRow}_${e}_${t}`;
- }
- }
- class rr {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.ManageCollaborator);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.ManageCollaborator}_${e}_${t}`;
- }
- }
- class ir {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.PivotTable);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.PivotTable}_${e}_${t}`;
- }
- }
- class nu {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.SelectProtectedCells);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectProtectedCells}_${e}_${t}`;
- }
- }
- class ou {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.SelectUnProtectedCells);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SelectUnProtectedCells}_${e}_${t}`;
- }
- }
- class ar {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.SetCellStyle);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellStyle}_${e}_${t}`;
- }
- }
- class wn {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.SetCellValue);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetCellValue}_${e}_${t}`;
- }
- }
- class $t {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.SetColumnStyle);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetColumnStyle}_${e}_${t}`;
- }
- }
- class Wt {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.SetRowStyle);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.SetRowStyle}_${e}_${t}`;
- }
- }
- class ur {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.Sort);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.Sort}_${e}_${t}`;
- }
- }
- class Hn {
- constructor(e, t) {
- R(this, "value", !0);
- R(this, "type", D.Worksheet);
- R(this, "status", J.INIT);
- R(this, "id");
- R(this, "subType", _.View);
- this.unitId = e, this.subUnitId = t, this.id = `${this.type}.${_.View}_${e}_${t}`;
- }
- }
- const on = {
- id: "sheet.command.set-range-values",
- type: v.COMMAND,
- handler: (n, e) => {
- var T;
- 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);
- if (!u) return !1;
- 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);
- if (!f || !f.length || !a.getPermissionPoint(new Te(c, l).id)) return !1;
- const p = new G();
- let C;
- if (O.isArray(m))
- for (let U = 0; U < f.length; U++) {
- const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U];
- for (let Y = 0; Y <= j - P; Y++)
- for (let ee = 0; ee <= Z - A; ee++)
- p.setValue(Y + P, ee + A, m[Y][ee]);
- }
- else if (Is(m))
- for (let U = 0; U < f.length; U++) {
- const { startRow: P, startColumn: A, endRow: j, endColumn: Z } = f[U];
- for (let Y = P; Y <= j; Y++)
- for (let ee = A; ee <= Z; ee++)
- p.setValue(Y, ee, m);
- }
- else
- C = m;
- const S = { subUnitId: l, unitId: c, cellValue: C != null ? C : p.getMatrix() }, I = Ae(n, S);
- if (!t.syncExecuteCommand(Q.id, S)) return !1;
- const { undos: b, redos: y } = i.onCommandExecute({
- id: on.id,
- params: { ...S, range: f }
- });
- if (z([...y], t).result) {
- const U = Xe(g != null ? g : p.getRange(), d, h);
- return o.pushUndoRedo({
- unitID: c,
- undoMutations: [
- { id: Q.id, params: I },
- ...b,
- U
- ],
- redoMutations: [
- { id: Q.id, params: S },
- ...y,
- O.deepClone(U)
- ]
- }), !0;
- }
- return !1;
- }
- };
- function lr(n, e) {
- 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);
- if (h) {
- const m = h.getCellMatrix(), g = m.getDataRange();
- if (i.startColumn <= g.endColumn || i.startRow <= g.endRow) {
- let I, w;
- if (a === ge.COLUMNS) {
- const y = Math.min(i.endRow, g.endRow);
- let x = 0;
- for (let U = i.startRow; U <= y; U++) {
- const P = m.getRow(U), A = P ? vs(P) - 1 : 0;
- x = Math.max(x, A);
- }
- I = {
- startRow: i.startRow,
- startColumn: i.startColumn,
- endRow: y,
- endColumn: x
- };
- const T = i.endColumn - i.startColumn + 1;
- w = {
- startRow: i.startRow,
- startColumn: I.startColumn + T,
- endRow: y,
- endColumn: I.endColumn + T
- };
- } else {
- const y = Math.min(i.endColumn, g.endColumn), x = g.endRow;
- I = {
- startRow: i.startRow,
- startColumn: i.startColumn,
- endRow: x,
- endColumn: y
- };
- const T = i.endRow - i.startRow + 1;
- w = {
- startRow: I.startRow + T,
- startColumn: i.startColumn,
- endRow: I.endRow + T,
- endColumn: y
- };
- }
- const b = wo(
- n,
- { unitId: s, subUnitId: r, range: I },
- { unitId: s, subUnitId: r, range: w },
- !0
- );
- b && (t.push(...b.redos), o.push(...b.undos));
- }
- if (Object.entries(u).length === 0)
- for (let I = i.startRow; I <= i.endRow; I++) {
- u[I] || (u[I] = {});
- for (let w = i.startColumn; w <= i.endColumn; w++)
- u[I][w] = null;
- }
- const f = {
- subUnitId: r,
- unitId: s,
- cellValue: u
- }, p = Ae(
- n,
- f
- ), { undos: C, redos: S } = c.onCommandExecute({
- id: on.id,
- params: { ...f, range: i }
- });
- t.push({ id: Q.id, params: f }, ...S), o.push({ id: Q.id, params: p }, ...C);
- }
- return {
- redo: t,
- undo: o
- };
- }
- function cr(n, e) {
- const t = [], o = [], { unitId: s, subUnitId: r, range: i, shiftDimension: a } = e, u = n.get(M), l = n.get(V), c = u.getUniverSheetInstance(s), d = c == null ? void 0 : c.getSheetBySheetId(r);
- if (d) {
- const h = d.getCellMatrix(), m = h.getDataRange(), g = {
- subUnitId: r,
- unitId: s,
- cellValue: Os([i])
- }, f = Ae(
- n,
- g
- ), p = l.onCommandExecute({
- id: on.id,
- params: g
- });
- if (t.push({ id: Q.id, params: g }, ...p.redos), o.push(...p.undos, {
- id: Q.id,
- params: f
- }), i.startColumn <= m.endColumn || i.startRow <= m.endRow) {
- let C = null, S = null;
- if (a === ge.COLUMNS && i.endColumn < m.endColumn) {
- const I = Math.min(i.endRow, m.endRow);
- let w = 0;
- for (let y = i.startRow; y <= I; y++) {
- const x = h.getRow(y), T = x ? vs(x) - 1 : 0;
- w = Math.max(w, T);
- }
- C = {
- startRow: i.startRow,
- startColumn: i.endColumn + 1,
- endRow: I,
- endColumn: w
- };
- const b = i.endColumn - i.startColumn + 1;
- S = {
- startRow: i.startRow,
- startColumn: C.startColumn - b,
- endRow: I,
- endColumn: C.endColumn - b
- };
- }
- if (a === ge.ROWS && i.endRow < m.endRow) {
- const I = Math.min(i.endColumn, m.endColumn), w = m.endRow;
- C = {
- startRow: i.endRow + 1,
- startColumn: i.startColumn,
- endRow: w,
- endColumn: I
- };
- const b = i.endRow - i.startRow + 1;
- S = {
- startRow: C.startRow - b,
- startColumn: i.startColumn,
- endRow: C.endRow - b,
- endColumn: I
- };
- }
- if (C && S) {
- const I = wo(
- n,
- { unitId: s, subUnitId: r, range: C },
- { unitId: s, subUnitId: r, range: S },
- !0
- );
- I && (t.push(...I.redos), o.push(...I.undos));
- }
- }
- }
- return {
- redo: t,
- undo: o
- };
- }
- function Yd(n, e, t, o, s, r) {
- const { startRow: i, endRow: a, startColumn: u, endColumn: l } = e;
- if (s === ge.ROWS) {
- const c = a - i + 1;
- for (let d = t; d >= i; d--)
- for (let h = u; h <= l; h++) {
- const m = n.getValue(d, h);
- m == null ? n.realDeleteValue(d + c, h) : n.setValue(d + c, h, m);
- }
- for (let d = a; d >= i; d--)
- for (let h = u; h <= l; h++)
- r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h);
- } else if (s === ge.COLUMNS) {
- const c = l - u + 1;
- for (let d = i; d <= a; d++)
- for (let h = o; h >= u; h--) {
- const m = n.getValue(d, h);
- m == null ? n.realDeleteValue(d, h + c) : n.setValue(d, h + c, m);
- }
- for (let d = i; d <= a; d++)
- for (let h = l; h >= u; h--)
- r && r[d] && r[d][h] ? n.setValue(d, h, r[d][h]) : n.realDeleteValue(d, h);
- }
- }
- function Xd(n, e, t, o, s) {
- const { startRow: r, endRow: i, startColumn: a, endColumn: u } = e, l = i - r + 1, c = u - a + 1;
- if (s === ge.ROWS)
- for (let d = r; d <= t; d++)
- for (let h = a; h <= u; h++) {
- const m = n.getValue(d + l, h);
- m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m);
- }
- else if (s === ge.COLUMNS)
- for (let d = r; d <= i; d++)
- for (let h = a; h <= o; h++) {
- const m = n.getValue(d, h + c);
- m == null ? n.realDeleteValue(d, h) : n.setValue(d, h, m);
- }
- }
- const dr = "sheet.command.delete-range-move-left", Pt = {
- type: v.COMMAND,
- id: dr,
- handler: async (n, e) => {
- var w, b, y;
- const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = N(s);
- if (!a) return !1;
- const { worksheet: u, workbook: l, subUnitId: c, unitId: d } = a;
- let h = e == null ? void 0 : e.range;
- if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h) return !1;
- const m = {
- range: h,
- subUnitId: c,
- unitId: d,
- shiftDimension: ge.COLUMNS
- }, g = i.onCommandExecute({
- id: Pt.id,
- params: { range: h }
- }), { redo: f, undo: p } = cr(
- n,
- m
- ), C = [...(b = g.preRedos) != null ? b : [], ...f], S = [...g.undos, ...p];
- return C.push(...g.redos), C.push(Xe(h, l, u)), S.push(...(y = g.preUndos) != null ? y : []), z(C, t).result ? (o.pushUndoRedo({
- unitID: d,
- undoMutations: S.reverse(),
- redoMutations: C
- }), !0) : !1;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- }, hr = "sheet.command.delete-range-move-up", Tt = {
- type: v.COMMAND,
- id: hr,
- handler: async (n, e) => {
- var w, b, y;
- const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(F), i = n.get(V), a = N(s);
- if (!a) return !1;
- const { unitId: u, subUnitId: l, workbook: c, worksheet: d } = a;
- let h = e == null ? void 0 : e.range;
- if (h || (h = (w = r.getCurrentLastSelection()) == null ? void 0 : w.range), !h) return !1;
- const m = {
- range: h,
- subUnitId: l,
- unitId: u,
- shiftDimension: ge.ROWS
- }, g = i.onCommandExecute({
- id: Tt.id,
- params: { range: h }
- }), { redo: f, undo: p } = cr(
- n,
- m
- ), C = [...(b = g.preRedos) != null ? b : [], ...f], S = [...g.undos, ...p];
- return C.push(...g.redos), C.push(Xe(h, c, d)), S.push(...(y = g.preUndos) != null ? y : []), z(C, t).result ? (o.pushUndoRedo({
- unitID: u,
- undoMutations: S.reverse(),
- redoMutations: C
- }), !0) : !1;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- }, su = {
- type: v.COMMAND,
- id: "sheet.command.delete-range-protection",
- async handler(n, e) {
- if (!e)
- return !1;
- const t = n.get(E), o = n.get(W), { unitId: s, subUnitId: r, rule: i } = e, a = {
- unitId: s,
- subUnitId: r,
- ruleIds: [i.id]
- };
- return await t.executeCommand(ze.id, a) && o.pushUndoRedo({
- unitID: s,
- redoMutations: [{ id: ze.id, params: a }],
- undoMutations: [{ id: Ne.id, params: { unitId: s, subUnitId: r, rules: [i] } }]
- }), !0;
- }
- }, ru = {
- type: v.COMMAND,
- id: "sheet.command.delete-worksheet-protection",
- handler(n, e) {
- if (!e)
- return !1;
- const t = n.get(E), o = n.get(W), { rule: s, unitId: r, subUnitId: i } = e;
- t.executeCommand(St.id, {
- unitId: r,
- subUnitId: i
- });
- const a = [{ id: St.id, params: { unitId: r, subUnitId: i } }], u = [{ id: ct.id, params: { unitId: r, rule: s, subUnitId: i } }];
- return o.pushUndoRedo({
- unitID: r,
- redoMutations: a,
- undoMutations: u
- }), !0;
- }
- }, iu = {
- type: v.COMMAND,
- id: "sheet.command.remove-worksheet-range-theme-style",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), { unitId: s } = e, r = _a(n, e);
- return t.syncExecuteCommand(Kt.id, e) ? (o.pushUndoRedo({
- unitID: s,
- undoMutations: [{ id: zt.id, params: r }],
- redoMutations: [{ id: Kt.id, params: e }]
- }), !0) : !1;
- }
- }, au = {
- id: "sheet.command.insert-defined-name",
- type: v.COMMAND,
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W);
- if (!e) return !1;
- const s = {
- ...e
- };
- return t.syncExecuteCommand(Gt.id, s) ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: [{ id: Cn.id, params: s }],
- redoMutations: [{ id: Gt.id, params: s }]
- }), !0) : !1;
- }
- }, mr = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- };
- }, qe = {
- id: "sheet.mutation.insert-row",
- type: v.MUTATION,
- handler: (n, e) => {
- var g;
- const { unitId: t, subUnitId: o, range: s, rowInfo: r } = e, a = n.get(M).getUniverSheetInstance(t);
- if (a == null)
- throw new Error("universheet is null error!");
- const u = a.getSheetBySheetId(o);
- if (u == null)
- throw new Error("worksheet is null error!");
- const l = u.getRowManager().getRowData(), c = {
- h: u.getConfig().defaultRowHeight,
- hd: 0
- }, d = s.startRow, h = s.endRow - s.startRow + 1;
- for (let f = d; f < d + h; f++)
- r ? pn(f, (g = r[f - s.startRow]) != null ? g : c, l) : pn(f, c, l);
- return u.setRowCount(u.getRowCount() + s.endRow - s.startRow + 1), u.getCellMatrix().insertRows(s.startRow, h), !0;
- }
- }, yo = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- };
- }, je = {
- id: "sheet.mutation.insert-col",
- type: v.MUTATION,
- handler: (n, e) => {
- var g;
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s) return !1;
- const r = s.getColumnManager(), { range: i, colInfo: a } = e, l = r.getColumnData(), c = i.startColumn, d = i.endColumn - i.startColumn + 1, h = s.getConfig().defaultColumnWidth;
- for (let f = c; f < c + d; f++) {
- const p = {
- w: h,
- hd: 0
- };
- a ? pn(f, (g = a[f - i.startColumn]) != null ? g : p, l) : pn(f, p, l);
- }
- return s.setColumnCount(s.getColumnCount() + i.endColumn - i.startColumn + 1), s.getCellMatrix().insertColumns(i.startColumn, d), !0;
- }
- }, uu = (n, e) => {
- const s = e.getRowManager().getRowData(), r = {}, i = n.range, a = _s(i.startRow, i.endRow, s), u = bs(r, a);
- return {
- unitId: n.unitId,
- subUnitId: n.subUnitId,
- range: n.range,
- rowInfo: u
- };
- }, Be = {
- id: "sheet.mutation.remove-rows",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s) return !1;
- const r = e.range, a = s.getRowManager().getRowData();
- for (let c = r.startRow; c <= r.endRow; c++)
- s.getRowFiltered(c);
- const u = r.endRow - r.startRow + 1;
- return Ms(r.startRow, u, a), s.getCellMatrix().removeRows(r.startRow, u), s.setRowCount(s.getRowCount() - u), !0;
- }
- }, lu = (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (s == null)
- throw new Error("worksheet is null error!");
- const a = s.getColumnManager().getColumnData(), u = {}, l = e.range, c = _s(l.startColumn, l.endColumn, a), d = bs(u, c);
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- colInfo: d
- };
- }, De = {
- id: "sheet.mutation.remove-col",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s) return !1;
- const r = e.range, a = s.getColumnManager().getColumnData(), u = r.endColumn - r.startColumn + 1;
- return Ms(r.startColumn, u, a), s.setColumnCount(s.getColumnCount() - u), s.getCellMatrix().removeColumns(r.startColumn, u), !0;
- }
- }, cu = "sheet.command.insert-range-move-down", sn = {
- type: v.COMMAND,
- id: "sheet.command.insert-range-move-down",
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- var j, Z, Y;
- const t = n.get(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);
- if (r.isOverlapping())
- return a.emit(u.t("sheets.info.overlappingSelections")), !1;
- const l = N(s);
- if (!l) return !1;
- const { unitId: c, subUnitId: d, worksheet: h, workbook: m } = l;
- let g = e == null ? void 0 : e.range;
- if (g || (g = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g) return !1;
- 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);
- if (b > 0) {
- const ee = g.startRow - 1, Re = h.getRowHeight(ee), ie = {
- unitId: c,
- subUnitId: d,
- range: {
- startRow: S.endRow + 1,
- endRow: S.endRow + b,
- startColumn: S.startColumn,
- endColumn: S.endColumn
- },
- rowInfo: new Array(b).fill(void 0).map(() => ({
- h: Re,
- hd: te.FALSE
- }))
- };
- f.push({
- id: qe.id,
- params: ie
- });
- const xe = mr(
- n,
- ie
- );
- p.push({ id: Be.id, params: xe });
- }
- const y = {};
- K.foreach(g, (ee, Re) => {
- const ie = h.getCell(ee, Re);
- ie && (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s });
- });
- const x = {
- range: g,
- subUnitId: d,
- unitId: c,
- shiftDimension: ge.ROWS,
- cellValue: y
- }, { redo: T, undo: U } = lr(
- n,
- x
- );
- f.push(...T), p.push(...U);
- const P = i.onCommandExecute({
- id: sn.id,
- params: { range: g }
- });
- 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({
- unitID: c,
- undoMutations: p.reverse(),
- redoMutations: f
- }), !0) : !1;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- }, Eo = "sheet.command.insert-range-move-right", Bn = {
- type: v.COMMAND,
- id: Eo,
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- var j, Z, Y;
- 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);
- if (r.isOverlapping())
- return a.emit(u.t("sheets.info.overlappingSelections")), !1;
- const l = N(s);
- if (!l) return !1;
- const { workbook: c, worksheet: d, unitId: h, subUnitId: m } = l;
- let g = e == null ? void 0 : e.range;
- if (g || (g = (j = r.getCurrentLastSelection()) == null ? void 0 : j.range), !g) return !1;
- 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(
- w + (g.endColumn - g.startColumn + 1) - S.endColumn,
- 0
- );
- if (b > 0) {
- const ee = g.startColumn - 1, Re = d.getColumnWidth(ee), ie = {
- unitId: h,
- subUnitId: m,
- range: {
- startRow: S.startRow + 1,
- endRow: S.endRow,
- startColumn: S.endColumn + 1,
- endColumn: S.endColumn + b
- },
- colInfo: new Array(b).fill(void 0).map(() => ({
- w: Re,
- hd: te.FALSE
- }))
- };
- f.push({
- id: je.id,
- params: ie
- });
- const xe = yo(
- n,
- ie
- );
- p.push({ id: De.id, params: xe });
- }
- const y = {};
- K.foreach(g, (ee, Re) => {
- const ie = d.getCell(ee, Re);
- !ie || !ie.s || (y[ee] || (y[ee] = {}), y[ee][Re] = { s: ie.s });
- });
- const x = {
- range: g,
- subUnitId: m,
- unitId: h,
- shiftDimension: ge.COLUMNS,
- cellValue: y
- }, { redo: T, undo: U } = lr(
- n,
- x
- );
- f.push(...T), p.push(...U);
- const P = i.onCommandExecute({
- id: Bn.id,
- params: { range: g }
- });
- 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({
- unitID: h,
- undoMutations: p.reverse(),
- redoMutations: f
- }), !0) : !1;
- }
- // all subsequent mutations should succeed inorder to make the whole process succeed
- // Promise.all([]).then(() => true),
- }, gr = "sheet.command.insert-row", mt = {
- type: v.COMMAND,
- id: gr,
- handler: async (n, e) => {
- const t = n.get(E), o = n.get(V), { range: s, direction: r, unitId: i, subUnitId: a, cellValue: u } = e;
- return await o.beforeCommandExecute({
- id: mt.id,
- params: e
- }) ? t.syncExecuteCommand(fr.id, {
- range: s,
- direction: r,
- unitId: i,
- subUnitId: a,
- cellValue: u
- }) : !1;
- }
- }, fr = {
- type: v.COMMAND,
- id: "sheet.command.insert-row-by-range",
- handler: (n, e) => {
- var T, U, P, A;
- const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = N(s, e);
- if (!i) return !1;
- const { workbook: a, worksheet: u } = i, { range: l, direction: c, unitId: d, subUnitId: h, cellValue: m } = e, { startRow: g, endRow: f } = l;
- l.rangeType = H.ROW;
- const p = c === pe.UP ? g : g - 1, C = u.getRowHeight(p), S = {
- unitId: d,
- subUnitId: h,
- range: l,
- rowInfo: new Array(f - g + 1).fill(void 0).map(() => ({
- h: C,
- hd: te.FALSE
- }))
- // row height should inherit from the anchor row
- }, I = mr(
- n,
- S
- ), w = [{ id: qe.id, params: S }], b = [{ id: Be.id, params: I }];
- m && w.push({
- id: Q.id,
- params: {
- unitId: d,
- subUnitId: h,
- cellValue: m
- }
- });
- const y = r.onCommandExecute({
- id: mt.id,
- params: e
- });
- return w.unshift(...(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({
- unitID: e.unitId,
- undoMutations: b,
- redoMutations: w
- }), !0) : !1;
- }
- }, du = {
- type: v.COMMAND,
- id: "sheet.command.insert-row-before",
- handler: async (n) => {
- var g;
- const t = (g = n.get(F).getCurrentSelections()) == null ? void 0 : g.map((f) => f.range);
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0];
- else
- return !1;
- const s = n.get(M), r = N(s);
- if (!r) return !1;
- const { worksheet: i, subUnitId: a, unitId: u } = r, { startRow: l, endRow: c } = o, d = 0, h = i.getColumnCount() - 1, m = {
- unitId: u,
- subUnitId: a,
- direction: pe.UP,
- range: {
- startRow: l,
- endRow: c,
- startColumn: d,
- endColumn: h
- },
- // copy styles from the row above
- cellValue: Vn(i, l, c, d, h, !0, l - 1)
- };
- return n.get(E).executeCommand(mt.id, m);
- }
- }, hu = {
- type: v.COMMAND,
- id: "sheet.command.insert-row-after",
- handler: async (n) => {
- var f;
- const t = (f = n.get(F).getCurrentSelections()) == null ? void 0 : f.map((p) => p.range);
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0];
- else
- return !1;
- const s = n.get(M), r = N(s);
- if (!r) return !1;
- 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 = {
- unitId: a,
- subUnitId: u,
- direction: pe.DOWN,
- range: {
- startRow: c,
- endRow: d,
- startColumn: h,
- endColumn: m,
- rangeType: H.ROW
- },
- // copy styles from the row below
- cellValue: Vn(i, c, d, h, m, !0, o.endRow)
- };
- return n.get(E).executeCommand(mt.id, g);
- }
- }, Rr = "sheet.command.insert-col", gt = {
- type: v.COMMAND,
- id: Rr,
- handler: async (n, e) => {
- const t = n.get(E), o = n.get(V), { range: s, direction: r, subUnitId: i, unitId: a, cellValue: u } = e;
- return await o.beforeCommandExecute({
- id: gt.id,
- params: e
- }) ? t.syncExecuteCommand(pr.id, {
- range: s,
- direction: r,
- unitId: a,
- subUnitId: i,
- cellValue: u
- }) : !1;
- }
- }, pr = {
- type: v.COMMAND,
- id: "sheet.command.insert-col-by-range",
- handler: (n, e) => {
- var x, T, U, P;
- 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;
- i.rangeType = H.COLUMN;
- const m = s.getUniverSheetInstance(e.unitId), g = m.getSheetBySheetId(e.subUnitId), f = a === pe.LEFT ? d : d - 1, p = g.getColumnWidth(f), C = {
- unitId: l,
- subUnitId: u,
- range: i,
- colInfo: new Array(h - d + 1).fill(void 0).map(() => ({
- w: p,
- hd: te.FALSE
- }))
- }, S = yo(
- n,
- C
- ), I = [{ id: je.id, params: C }], w = [{ id: De.id, params: S }];
- c && I.push({
- id: Q.id,
- params: {
- unitId: l,
- subUnitId: u,
- cellValue: c
- }
- });
- const b = r.onCommandExecute({
- id: gt.id,
- params: e
- });
- return I.unshift(...(x = b.preRedos) != null ? x : []), I.push(...(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({
- unitID: e.unitId,
- undoMutations: w.filter(Boolean),
- redoMutations: I.filter(Boolean)
- }), !0) : !1;
- }
- }, mu = {
- type: v.COMMAND,
- id: "sheet.command.insert-col-before",
- handler: async (n) => {
- const t = n.get(F).getCurrentSelections();
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0].range;
- else
- return !1;
- const s = n.get(M), r = N(s);
- if (!r) return !1;
- const { worksheet: i, unitId: a, subUnitId: u } = r, { startColumn: l, endColumn: c } = o, d = 0, h = i.getRowCount() - 1, m = {
- unitId: a,
- subUnitId: u,
- direction: pe.LEFT,
- range: {
- startColumn: l,
- endColumn: c,
- startRow: d,
- endRow: h,
- rangeType: H.COLUMN
- },
- // copy styles from the column before
- cellValue: Vn(i, d, h, l, c, !1, l - 1)
- };
- return n.get(E).executeCommand(gt.id, m);
- }
- }, gu = {
- type: v.COMMAND,
- id: "sheet.command.insert-col-after",
- handler: async (n) => {
- const t = n.get(F).getCurrentSelections();
- let o;
- if ((t == null ? void 0 : t.length) === 1)
- o = t[0].range;
- else
- return !1;
- const s = n.get(M), r = N(s);
- if (!r) return !1;
- 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 = {
- unitId: a,
- subUnitId: u,
- direction: pe.RIGHT,
- range: {
- startColumn: c,
- endColumn: d,
- startRow: h,
- endRow: m
- },
- // copy styles from the column after
- cellValue: Vn(i, h, m, c, d, !1, o.endColumn)
- };
- return n.get(E).executeCommand(gt.id, g);
- }
- }, fu = {
- id: "sheet.command.insert-sheet",
- type: v.COMMAND,
- handler: (n, e) => {
- var p;
- 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 });
- if (!i) return !1;
- const { unitId: a, workbook: u } = i;
- let l = u.getSheets().length;
- const c = e == null ? void 0 : e.sheet, d = c == null ? void 0 : c.id, h = mi(c || {});
- 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")}`));
- const m = {
- index: l,
- sheet: h,
- unitId: a
- }, g = As(
- n,
- m
- );
- return t.syncExecuteCommand(Jt.id, m) ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Ut.id, params: g }],
- redoMutations: [{ id: Jt.id, params: m }]
- }), !0) : !1;
- }
- };
- function Ru(n, e) {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startRow > r.startRow, a = s.endRow - s.startRow + 1;
- return i ? {
- unitId: t,
- subUnitId: o,
- sourceRange: k.clone(r),
- targetRange: {
- ...s,
- endRow: s.endRow + a,
- startRow: s.startRow + a
- }
- } : {
- unitId: t,
- subUnitId: o,
- targetRange: k.clone(s),
- sourceRange: {
- ...r,
- endRow: r.endRow - a,
- startRow: r.startRow - a
- }
- };
- }
- const ot = {
- id: "sheet.mutation.move-rows",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(M).getUniverSheetInstance(t);
- if (!a)
- throw new Error("[MoveRowMutation] univerSheet is null!");
- const u = a.getSheetBySheetId(o);
- if (!u)
- throw new Error("[MoveRowMutation] worksheet is null!");
- const l = s.startRow, c = s.endRow - s.startRow + 1, d = r.startRow, h = u.getRowManager().getRowData();
- return ys(l, c, d, h), u.getCellMatrix().moveRows(l, c, d), !0;
- }
- };
- function pu(n, e) {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, i = s.startColumn > r.startColumn, a = s.endColumn - s.startColumn + 1;
- return i ? {
- unitId: t,
- subUnitId: o,
- sourceRange: k.clone(r),
- targetRange: {
- ...s,
- endColumn: s.endColumn + a,
- startColumn: s.startColumn + a
- }
- } : {
- unitId: t,
- subUnitId: o,
- targetRange: k.clone(s),
- sourceRange: {
- ...r,
- startColumn: r.startColumn - a,
- endColumn: r.endColumn - a
- }
- };
- }
- const st = {
- id: "sheet.mutation.move-columns",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, sourceRange: s, targetRange: r } = e, a = n.get(M).getUniverSheetInstance(t);
- if (!a)
- throw new Error("[MoveColumnMutation] univerSheet is null!");
- const u = a.getSheetBySheetId(o);
- if (!u)
- throw new Error("[MoveColumnMutation] worksheet is null!");
- const l = s.startColumn, c = s.endColumn - s.startColumn + 1, d = r.startColumn, h = u.getColumnManager().getColumnData();
- return ys(l, c, d, h), u.getCellMatrix().moveColumns(l, c, d), !0;
- }
- };
- function Cu(n, e) {
- return e.getMergeData().some((t) => t.startRow < n && n <= t.endRow);
- }
- function Su(n, e) {
- return e.getMergeData().some((t) => t.startColumn < n && n <= t.endColumn);
- }
- const Cr = "sheet.command.move-rows", Fn = {
- id: Cr,
- type: v.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var j, Z;
- const t = n.get(F), {
- fromRange: { startRow: o },
- toRange: { startRow: s },
- range: r
- } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter(
- (Y) => Y.range.rangeType === H.ROW && Y.range.startRow <= o && o <= Y.range.endRow
- );
- if ((a == null ? void 0 : a.length) !== 1)
- return !1;
- const u = n.get(V), l = n.get(M), c = N(l, e);
- if (!c) return !1;
- 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);
- if (!k.equals(C, I))
- return f.emit(p.t("sheets.info.partOfCell")), !1;
- if (Cu(s, h))
- return f.emit(p.t("sheets.info.acrossMergedCell")), !1;
- const w = {
- ...C,
- startRow: s,
- endRow: s + C.endRow - C.startRow
- }, b = {
- unitId: m,
- subUnitId: g,
- sourceRange: C,
- targetRange: w
- }, y = Ru(n, b), x = n.get(E), T = u.onCommandExecute({ id: Fn.id, params: e }), U = [
- ...(j = T.preRedos) != null ? j : [],
- { id: ot.id, params: b }
- ], P = [
- ...(Z = T.preUndos) != null ? Z : [],
- { id: ot.id, params: y }
- ];
- if (S) {
- const ee = s - o < 0, Re = C.endRow - C.startRow + 1, ie = ee ? w : {
- ...w,
- startRow: w.startRow - Re,
- endRow: w.endRow - Re
- }, xe = {
- unitId: m,
- subUnitId: g,
- type: Ce.MOVE_END,
- selections: [{
- range: ie,
- primary: ve(ie, h),
- style: null
- }]
- }, ft = {
- unitId: m,
- subUnitId: g,
- type: Ce.MOVE_END,
- selections: [{ range: C, primary: S, style: null }]
- };
- U.push({ id: re.id, params: xe }), P.push({ id: re.id, params: ft });
- }
- return U.push(...T.redos), P.push(...T.undos), z(U, x).result ? (n.get(W).pushUndoRedo({
- unitID: m,
- undoMutations: P,
- redoMutations: U
- }), !0) : !1;
- }
- }, Sr = "sheet.command.move-cols", jn = {
- id: Sr,
- type: v.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var j, Z;
- const t = n.get(F), {
- fromRange: { startColumn: o },
- toRange: { startColumn: s },
- range: r
- } = e, i = r ? [wr(r)] : t.getCurrentSelections(), a = i == null ? void 0 : i.filter(
- (Y) => Y.range.rangeType === H.COLUMN && Y.range.startColumn <= o && o <= Y.range.endColumn
- );
- if ((a == null ? void 0 : a.length) !== 1)
- return !1;
- const u = n.get(V), l = n.get(M), c = N(l, e);
- if (!c) return !1;
- 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);
- if (!k.equals(C, I))
- return f.emit(p.t("sheets.info.partOfCell")), !1;
- if (Su(s, h))
- return f.emit(p.t("sheets.info.acrossMergedCell")), !1;
- const w = {
- ...C,
- startColumn: s,
- endColumn: s + C.endColumn - C.startColumn
- }, b = {
- unitId: m,
- subUnitId: g,
- sourceRange: C,
- targetRange: w
- }, y = pu(n, b), x = n.get(E), T = u.onCommandExecute({ id: jn.id, params: e }), U = [
- ...(j = T.preRedos) != null ? j : [],
- { id: st.id, params: b }
- ], P = [
- ...(Z = T.preUndos) != null ? Z : [],
- { id: st.id, params: y }
- ];
- if (S) {
- const Y = C.endColumn - C.startColumn + 1, ie = s - o < 0 ? w : {
- ...w,
- startColumn: w.startColumn - Y,
- endColumn: w.endColumn - Y
- }, xe = {
- unitId: m,
- subUnitId: g,
- type: Ce.MOVE_END,
- selections: [{ range: ie, primary: ve(ie, h), style: null }]
- }, ft = {
- unitId: m,
- subUnitId: g,
- type: Ce.MOVE_END,
- selections: [{ range: C, primary: S, style: null }]
- };
- U.push({ id: re.id, params: xe }), P.push({ id: re.id, params: ft });
- }
- return U.push(...T.redos), P.push(...T.undos), z(U, x).result && n.get(W).pushUndoRedo({
- unitID: m,
- undoMutations: P,
- redoMutations: U
- }), !0;
- }
- };
- function wr(n) {
- return {
- range: n,
- primary: null,
- style: null
- };
- }
- const Yt = {
- id: "sheet.mutation.register-worksheet-range-theme-style",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, rangeThemeStyleJson: o, themeName: s } = e, r = n.get(M), i = N(r), a = n.get(He);
- if (!i) return !1;
- const u = new yt(s, o);
- return a.registerRangeThemeStyle(t, u), !0;
- }
- }, Uo = {
- id: "sheet.mutation.unregister-worksheet-range-theme-style",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, themeName: o } = e, s = n.get(M), r = N(s), i = n.get(He);
- return r ? (i.unregisterRangeThemeStyle(t, o), !0) : !1;
- }
- }, wu = {
- id: "sheet.command.register-worksheet-range-theme-style",
- type: v.COMMAND,
- handler: (n, e) => {
- if (!e)
- return !1;
- const { unitId: t, rangeThemeStyle: o } = e, s = n.get(M), r = n.get(E), i = n.get(W);
- if (!N(s)) return !1;
- const u = {
- unitId: t,
- themeName: o.getName(),
- rangeThemeStyleJson: o.toJson()
- }, l = {
- unitId: t,
- themeName: o.getName()
- };
- return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({
- unitID: t,
- undoMutations: [{ id: Uo.id, params: l }],
- redoMutations: [{ id: Yt.id, params: u }]
- }), !0;
- }
- }, Ir = {
- id: "sheet.command.remove-defined-name",
- type: v.COMMAND,
- handler: (n, e) => {
- var c, d;
- const t = n.get(E), o = n.get(W), s = n.get(V);
- if (!e) return !1;
- const r = {
- ...e
- }, i = s.onCommandExecute({ id: Ir.id, params: e }), a = [
- ...(c = i.preRedos) != null ? c : [],
- { id: Cn.id, params: r },
- ...i.redos
- ], u = [
- ...(d = i.preUndos) != null ? d : [],
- { id: Gt.id, params: r },
- ...i.undos
- ];
- return z(a, t) ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: u.filter(Boolean),
- redoMutations: a.filter(Boolean)
- }), !0) : !1;
- }
- }, Po = "sheet.command.remove-row", vr = {
- type: v.COMMAND,
- id: "sheet.command.remove-row-by-range",
- handler: (n, e) => {
- var C, S, I;
- if (!e)
- return !1;
- const t = n.get(M), o = N(t, e);
- if (!o) return !1;
- const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = {
- unitId: u,
- subUnitId: l,
- range: a
- }, d = uu(
- c,
- r
- ), h = r.getCellMatrix().getSlice(a.startRow, a.endRow, 0, r.getColumnCount() - 1), m = {
- unitId: u,
- subUnitId: l,
- cellValue: h.getMatrix()
- }, g = i.onCommandExecute({
- id: Po,
- params: { range: a }
- }), f = n.get(E);
- return z(
- [
- ...(C = g.preRedos) != null ? C : [],
- { id: Be.id, params: c },
- ...g.redos,
- Xe(a, s, r)
- ],
- f
- ).result ? (n.get(W).pushUndoRedo({
- unitID: u,
- undoMutations: [
- ...(S = g.preUndos) != null ? S : [],
- { id: qe.id, params: d },
- { id: Q.id, params: m },
- ...g.undos
- ],
- redoMutations: [
- ...(I = g.preRedos) != null ? I : [],
- { id: Be.id, params: c },
- ...g.redos
- ]
- }), !0) : !1;
- }
- }, Gn = {
- type: v.COMMAND,
- id: Po,
- handler: async (n, e) => {
- var h;
- const t = n.get(F), o = n.get(V), s = n.get(E);
- let r = e == null ? void 0 : e.range;
- if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return !1;
- const i = n.get(M), a = N(i);
- if (!a) return !1;
- const { worksheet: u, subUnitId: l, unitId: c } = a;
- return r = {
- ...r,
- startColumn: 0,
- endColumn: Math.max(u.getMaxColumns() - 1, 0)
- }, await o.beforeCommandExecute({
- id: Gn.id,
- params: { range: r }
- }) ? s.syncExecuteCommand(vr.id, {
- range: r,
- unitId: c,
- subUnitId: l
- }) : !1;
- }
- }, To = "sheet.command.remove-col", Mr = {
- type: v.COMMAND,
- id: "sheet.command.remove-col-by-range",
- handler: (n, e) => {
- var C, S, I;
- if (!e)
- return !1;
- const t = n.get(M), o = N(t, e);
- if (!o) return !1;
- const { workbook: s, worksheet: r } = o, i = n.get(V), { range: a, unitId: u, subUnitId: l } = e, c = {
- unitId: u,
- subUnitId: l,
- range: a
- }, d = lu(n, c), h = r.getCellMatrix().getSlice(0, r.getRowCount() - 1, a.startColumn, a.endColumn), m = {
- unitId: u,
- subUnitId: l,
- cellValue: h.getMatrix()
- }, g = i.onCommandExecute({
- id: To,
- params: { range: a }
- }), f = n.get(E);
- return z(
- [
- ...(C = g.preRedos) != null ? C : [],
- { id: De.id, params: c },
- ...g.redos,
- Xe(a, s, r)
- ],
- f
- ).result ? (n.get(W).pushUndoRedo({
- unitID: u,
- undoMutations: [
- ...(S = g.preUndos) != null ? S : [],
- { id: je.id, params: d },
- { id: Q.id, params: m },
- ...g.undos
- ],
- redoMutations: [
- ...(I = g.preRedos) != null ? I : [],
- { id: De.id, params: c },
- ...g.redos
- ]
- }), !0) : !1;
- }
- }, zn = {
- type: v.COMMAND,
- id: To,
- handler: async (n, e) => {
- var h;
- const t = n.get(F), o = n.get(V), s = n.get(E);
- let r = e == null ? void 0 : e.range;
- if (r || (r = (h = t.getCurrentLastSelection()) == null ? void 0 : h.range), !r) return !1;
- const i = n.get(M), a = N(i);
- if (!a) return !1;
- const { worksheet: u, subUnitId: l, unitId: c } = a;
- return r = {
- ...r,
- startRow: 0,
- endRow: Math.max(u.getMaxRows() - 1, 0)
- }, await o.beforeCommandExecute({
- id: zn.id,
- params: { range: r }
- }) ? s.syncExecuteCommand(Mr.id, {
- range: r,
- unitId: c,
- subUnitId: l
- }) : !1;
- }
- }, ko = {
- id: "sheet.command.remove-sheet",
- type: v.COMMAND,
- handler: (n, e) => {
- var C, S;
- const t = n.get(E), o = n.get(W), s = n.get(M), r = n.get(V), i = N(s, e);
- if (!i) return !1;
- const { unitId: a, subUnitId: u, workbook: l, worksheet: c } = i;
- if (l.getSheets().length <= 1) return !1;
- const d = {
- subUnitId: u,
- unitId: a,
- subUnitName: c.getName()
- }, h = ja(
- n,
- d
- ), m = r.onCommandExecute({
- id: ko.id,
- params: { unitId: a, subUnitId: u }
- }), 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];
- return z(g, t).result ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: f,
- redoMutations: g
- }), !0) : !1;
- }
- }, Ue = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: O.deepClone(e.ranges)
- };
- }, ne = {
- id: "sheet.mutation.add-worksheet-merge",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s) return !1;
- const i = s.getConfig().mergeData, a = e.ranges;
- for (let u = 0; u < a.length; u++)
- i.push(a[u]);
- return s.getSpanModel().rebuild(i), !0;
- }
- }, Se = (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (s == null)
- throw new Error("worksheet is null error!");
- const i = s.getConfig().mergeData, a = e.ranges, u = [];
- for (let l = 0; l < a.length; l++)
- for (let c = i.length - 1; c >= 0; c--) {
- const d = i[c], h = a[l];
- k.intersects(d, h) && u.push(i[c]);
- }
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: u
- };
- }, oe = {
- id: "sheet.mutation.remove-worksheet-merge",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s) return !1;
- const i = s.getConfig().mergeData, a = e.ranges;
- for (let u = 0; u < a.length; u++)
- for (let l = i.length - 1; l >= 0; l--) {
- const c = i[l], d = a[u];
- k.intersects(c, d) && i.splice(l, 1);
- }
- return s.getSpanModel().rebuild(i), !0;
- }
- }, Iu = {
- type: v.COMMAND,
- id: "sheet.command.remove-worksheet-merge",
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var A;
- const t = n.get(F), o = n.get(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));
- if (!(i != null && i.length)) return !1;
- const a = N(r);
- if (!a) return !1;
- const { subUnitId: u, unitId: l, worksheet: c } = a, d = {
- unitId: l,
- subUnitId: u,
- ranges: i
- }, m = c.getConfig().mergeData.filter((j) => i.some((Z) => k.intersects(Z, j)));
- if (!m.length) return !1;
- const g = Se(
- n,
- d
- ), f = t.getCurrentSelections();
- if (!(f != null && f.length)) return !1;
- const p = O.deepClone(f), C = O.deepClone(f), S = C[C.length - 1], { startRow: I, startColumn: w } = S.range;
- S.primary = {
- startRow: I,
- startColumn: w,
- endRow: I,
- endColumn: w,
- actualRow: I,
- actualColumn: w,
- isMerged: !1,
- isMergedMainCell: !1
- };
- const b = vu(c, m), y = {
- unitId: l,
- subUnitId: u,
- cellValue: b.redoParams.getMatrix()
- }, x = {
- unitId: l,
- subUnitId: u,
- cellValue: b.undoParams.getMatrix()
- }, T = [
- { id: oe.id, params: g },
- { id: Q.id, params: y },
- { id: re.id, params: { selections: C } }
- ], U = [
- { id: ne.id, params: g },
- { id: Q.id, params: x },
- { id: re.id, params: { selections: p } }
- ];
- return z(T, o) ? (s.pushUndoRedo({
- unitID: l,
- undoMutations: U,
- redoMutations: T
- }), !0) : !1;
- }
- };
- function vu(n, e) {
- const t = new G(), o = new G();
- return e.forEach((s) => {
- const { startRow: r, startColumn: i, endColumn: a, endRow: u } = s, l = n.getCellMatrix().getValue(r, i);
- if (l != null && l.s)
- for (let c = r; c <= u; c++)
- for (let d = i; d <= a; d++)
- (c !== r || d !== i) && (t.setValue(c, d, { s: l.s }), o.setValue(c, d, null));
- }), {
- redoParams: t,
- undoParams: o
- };
- }
- const Mu = (n) => {
- const { order: e } = n, t = {};
- return Object.keys(e).forEach((o) => {
- t[e[Number(o)]] = Number(o);
- }), {
- ...n,
- order: t
- };
- }, In = {
- id: "sheet.mutation.reorder-range",
- type: v.MUTATION,
- handler: (n, e) => {
- const { subUnitId: t, unitId: o, range: s, order: r } = e, u = n.get(M).getUnit(o).getSheetBySheetId(t);
- if (!u)
- return !1;
- const l = new G();
- K.foreach(s, (d, h) => {
- if (r.hasOwnProperty(d)) {
- const m = r[d], g = O.deepClone(u.getCellRaw(m, h));
- l.setValue(d, h, g);
- }
- });
- const c = u.getCellMatrix();
- return l.forValue((d, h, m) => {
- c.setValue(d, h, m);
- }), !0;
- }
- }, _r = "sheet.command.reorder-range", uo = {
- id: _r,
- type: v.COMMAND,
- handler: (n, e) => {
- var f, p;
- const { subUnitId: t, unitId: o, range: s, order: r } = e, i = n.get(E), a = {
- id: In.id,
- params: {
- unitId: o,
- subUnitId: t,
- order: r,
- range: s
- }
- }, u = {
- id: In.id,
- params: Mu(a.params)
- }, l = n.get(V), c = l.onCommandExecute({ id: uo.id, params: e }), d = [
- ...(f = c.preRedos) != null ? f : [],
- a,
- ...c.redos
- ], h = [
- ...(p = c.preUndos) != null ? p : [],
- u,
- ...c.undos
- ], m = z(d, i), g = l.afterCommandExecute({ id: uo.id, params: e });
- return m.result ? (z(g.redos, i), n.get(W).pushUndoRedo({
- unitID: o,
- undoMutations: [...h, ...g.undos],
- redoMutations: [...d, ...g.redos]
- }), !0) : !1;
- }
- };
- class kt {
- constructor() {
- R(this, "_borderInfo", {
- type: ue.ALL,
- color: "#000000",
- style: Rs.THIN,
- activeBorderType: !1
- });
- R(this, "_borderInfo$", new at(this._borderInfo));
- R(this, "borderInfo$", this._borderInfo$.asObservable());
- }
- dispose() {
- this._borderInfo$.complete();
- }
- setType(e) {
- this._borderInfo.type = e, this.setActiveBorderType(!0), this._refresh();
- }
- setColor(e) {
- this._borderInfo.color = e, this._refresh();
- }
- setStyle(e) {
- this._borderInfo.style = e, this._refresh();
- }
- setActiveBorderType(e) {
- this._borderInfo.activeBorderType = e;
- }
- getBorderInfo() {
- return this._borderInfo;
- }
- _refresh() {
- this._borderInfo$.next(this._borderInfo);
- }
- }
- function vn(n, e) {
- const { startRow: t, startColumn: o, endRow: s, endColumn: r } = n;
- for (let i = t; i <= s; i++)
- for (let a = o; a <= r; a++)
- e(i, a);
- }
- const No = (n, e, t, o) => {
- const { mr: s, worksheet: r } = n;
- e.startRow < 0 || e.startColumn < 0 || vn(e, (i, a) => {
- var c, d;
- const u = r.getMergedCell(i, a);
- let l = t;
- if (u && (t.bc_tr || t.ml_tr || t.bl_tr || t.tl_mr || t.tl_bc || t.tl_br)) {
- if (o) {
- const h = O.deepClone(
- (c = s.getValue(u.startRow, u.startColumn)) == null ? void 0 : c.s
- );
- l = h != null && h.bd ? Object.assign(h.bd, t) : t;
- }
- s.setValue(u.startRow, u.startColumn, {
- s: {
- bd: l
- }
- });
- } else {
- if (o) {
- const h = O.deepClone((d = s.getValue(i, a)) == null ? void 0 : d.s);
- l = h != null && h.bd ? Object.assign(h.bd, t) : t;
- }
- s.setValue(i, a, { s: { bd: l } });
- }
- });
- }, _u = (n) => {
- const e = {
- startRow: n.startRow - 1,
- startColumn: n.startColumn,
- endRow: n.startRow - 1,
- endColumn: n.endColumn
- }, t = {
- startRow: n.startRow,
- startColumn: n.startColumn - 1,
- endRow: n.endRow,
- endColumn: n.startColumn - 1
- }, o = {
- startRow: n.endRow + 1,
- startColumn: n.startColumn,
- endRow: n.endRow + 1,
- endColumn: n.endColumn
- }, s = {
- startRow: n.startRow,
- startColumn: n.endColumn + 1,
- endRow: n.endRow,
- endColumn: n.endColumn + 1
- }, r = {
- startRow: n.startRow,
- startColumn: n.startColumn,
- endRow: n.startRow,
- endColumn: n.endColumn
- }, i = {
- startRow: n.startRow,
- startColumn: n.startColumn,
- endRow: n.endRow,
- endColumn: n.startColumn
- }, a = {
- startRow: n.endRow,
- startColumn: n.startColumn,
- endRow: n.endRow,
- endColumn: n.endColumn
- }, u = {
- startRow: n.startRow,
- startColumn: n.endColumn,
- endRow: n.endRow,
- endColumn: n.endColumn
- };
- return {
- topRangeOut: e,
- leftRangeOut: t,
- bottomRangeOut: o,
- rightRangeOut: s,
- topRange: r,
- leftRange: i,
- bottomRange: a,
- rightRange: u
- };
- };
- function bu(n, e, t) {
- const { style: o, color: s, type: r } = n.getBorderInfo(), i = r === 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], {
- topRangeOut: I,
- leftRangeOut: w,
- bottomRangeOut: b,
- rightRangeOut: y,
- topRange: x,
- leftRange: T,
- bottomRange: U,
- rightRange: P
- } = _u(S), A = new G(), { worksheet: j, unitId: Z, subUnitId: Y } = e;
- return {
- worksheet: j,
- unitId: Z,
- subUnitId: Y,
- style: o,
- color: s,
- type: r,
- top: i,
- left: a,
- right: l,
- bottom: u,
- vertical: c,
- horizontal: d,
- tl_br: h,
- tl_bc: m,
- tl_mr: g,
- bl_tr: f,
- ml_tr: p,
- bc_tr: C,
- topRangeOut: I,
- leftRangeOut: w,
- bottomRangeOut: b,
- rightRangeOut: y,
- topRange: x,
- leftRange: T,
- bottomRange: U,
- rightRange: P,
- range: S,
- mr: A,
- borderStyle: {
- s: o,
- cl: {
- rgb: s
- }
- }
- };
- }
- const yu = (n) => {
- const { range: e, mr: t, borderStyle: o, vertical: s, horizontal: r, worksheet: i } = n;
- s && vn(e, (a, u) => {
- var c, d, h;
- const l = i.getMergedCell(a, u);
- if (l) {
- const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s;
- l.startColumn !== e.startColumn && t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { l: O.deepClone(o) }) : { l: O.deepClone(o) }
- }
- });
- } else {
- if (u !== e.endColumn) {
- const m = (d = t.getValue(a, u)) == null ? void 0 : d.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { r: O.deepClone(o) }) : { r: O.deepClone(o) }
- }
- });
- }
- if (u !== e.startColumn) {
- const m = (h = t.getValue(a, u)) == null ? void 0 : h.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { l: O.deepClone(o) }) : { l: O.deepClone(o) }
- }
- });
- }
- }
- }), r && vn(e, (a, u) => {
- var c, d, h;
- const l = i.getMergedCell(a, u);
- if (l) {
- const m = (c = t.getValue(l.startRow, l.startColumn)) == null ? void 0 : c.s;
- l.startRow !== e.startRow && t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { t: O.deepClone(o) }) : { t: O.deepClone(o) }
- }
- });
- } else {
- if (a !== e.endRow) {
- const m = (d = t.getValue(a, u)) == null ? void 0 : d.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { b: O.deepClone(o) }) : { b: O.deepClone(o) }
- }
- });
- }
- if (a !== e.startRow) {
- const m = (h = t.getValue(a, u)) == null ? void 0 : h.s;
- t.setValue(a, u, {
- s: {
- bd: m != null && m.bd ? Object.assign(m.bd, { t: O.deepClone(o) }) : { t: O.deepClone(o) }
- }
- });
- }
- }
- });
- };
- function Eu(n) {
- const { borderStyle: e, tl_br: t, tl_bc: o, tl_mr: s, bl_tr: r, ml_tr: i, bc_tr: a } = n, u = (l, c, d) => {
- No(n, l, c, d);
- };
- t && u(n.range, { tl_br: 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);
- }
- const Uu = (n) => {
- const { top: e, left: t, right: o, bottom: s, borderStyle: r, bottomRange: i, topRange: a, leftRange: u, rightRange: l, bottomRangeOut: c, topRangeOut: d, leftRangeOut: h, rightRangeOut: m } = n, g = (f, p, C) => {
- No(n, f, p, C);
- };
- 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));
- }, Pu = (n) => {
- const { range: e, worksheet: t, mr: o, top: s, bottom: r, left: i, right: a, vertical: u, horizontal: l, tl_br: c, tl_bc: d, tl_mr: h, bl_tr: m, ml_tr: 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) => {
- No(n, U, P, A);
- };
- !s && !r && !i && !a && !u && !l && !c && !d && !h && !m && !g && !f && (vn(e, (U, P) => {
- var j, Z, Y, ee, Re, ie, xe, ft;
- const A = t.getMergedCell(U, P);
- if (A) {
- if (A.endColumn !== e.endColumn) {
- const X = (j = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : j.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { r: null }) : { r: null }
- }
- });
- }
- if (A.startColumn !== e.startColumn) {
- const X = (Z = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Z.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { l: null }) : { l: null }
- }
- });
- }
- if (A.endRow !== e.endRow) {
- const X = (Y = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : Y.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { b: null }) : { b: null }
- }
- });
- }
- if (A.startRow !== e.startRow) {
- const X = (ee = o.getValue(A.startRow, A.startColumn)) == null ? void 0 : ee.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { t: null }) : { t: null }
- }
- });
- }
- } else {
- if (P !== e.endColumn) {
- const X = (Re = o.getValue(U, P)) == null ? void 0 : Re.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { r: null }) : { r: null }
- }
- });
- }
- if (P !== e.startColumn) {
- const X = (ie = o.getValue(U, P)) == null ? void 0 : ie.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { l: null }) : { l: null }
- }
- });
- }
- if (U !== e.endRow) {
- const X = (xe = o.getValue(U, P)) == null ? void 0 : xe.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { b: null }) : { b: null }
- }
- });
- }
- if (U !== e.startRow) {
- const X = (ft = o.getValue(U, P)) == null ? void 0 : ft.s;
- o.setValue(U, P, {
- s: {
- bd: X != null && X.bd ? Object.assign(X.bd, { t: null }) : { t: null }
- }
- });
- }
- }
- }), 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));
- }, rn = {
- id: "sheet.command.set-border",
- type: v.COMMAND,
- handler: (n, e) => {
- var C;
- 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);
- if (!a) return !1;
- const u = (C = r.getCurrentSelections()) == null ? void 0 : C.map((S) => S.range);
- if (!(u != null && u.length))
- return !1;
- const { activeBorderType: l } = i.getBorderInfo();
- if (!l) return !1;
- const c = bu(i, a, u);
- yu(c), Uu(c), Eu(c), Pu(c);
- const { unitId: d, subUnitId: h, mr: m } = c, g = {
- unitId: d,
- subUnitId: h,
- cellValue: m.getData()
- }, f = Ae(
- n,
- g
- );
- return t.syncExecuteCommand(Q.id, g) ? (o.pushUndoRedo({
- unitID: d,
- undoMutations: [{ id: Q.id, params: f }],
- redoMutations: [{ id: Q.id, params: g }]
- }), !0) : !1;
- }
- }, Tu = {
- id: "sheet.command.set-border-position",
- type: v.COMMAND,
- handler: (n, e) => {
- if (!e.value) return !1;
- const t = n.get(E);
- return n.get(kt).setType(e.value), t.syncExecuteCommand(rn.id);
- }
- }, ku = {
- id: "sheet.command.set-border-style",
- type: v.COMMAND,
- handler: (n, e) => {
- const t = n.get(E);
- return n.get(kt).setStyle(e.value), t.syncExecuteCommand(rn.id);
- }
- }, Nu = {
- id: "sheet.command.set-border-color",
- type: v.COMMAND,
- handler: (n, e) => {
- const t = n.get(E);
- return n.get(kt).setColor(e.value), t.syncExecuteCommand(rn.id);
- }
- }, Ou = {
- id: "sheet.command.set-border-basic",
- type: v.COMMAND,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, value: s } = e, { type: r, color: i, style: a } = s, u = n.get(E), l = n.get(kt);
- return l.setType(r), i && l.setColor(i), l.setStyle(a), u.syncExecuteCommand(rn.id, {
- unitId: t,
- subUnitId: o
- });
- }
- };
- function Du(n, e) {
- if (n == null)
- return n;
- const t = O.deepClone(n);
- if (e == null)
- return t;
- const o = {};
- return "h" in e && (o.h = t.h), "ia" in e && (o.ia = t.ia), "ah" in e && (o.ah = t.ah), "hd" in e && (o.hd = t.hd), "s" in e && (o.s = t.s), "custom" in e && (o.custom = t.custom), o;
- }
- function Au(n, e) {
- if (n == null)
- return n;
- const t = O.deepClone(n);
- if (e == null)
- return t;
- const o = {};
- return "w" in e && (o.w = t.w), "hd" in e && (o.hd = t.hd), "s" in e && (o.s = t.s), "custom" in e && (o.custom = t.custom), o;
- }
- const xu = (n, e) => {
- const { unitId: t, subUnitId: o, columnData: s } = n, r = {}, i = e.getColumnManager();
- for (const a in s) {
- const u = s[a], l = i.getColumn(Number(a));
- r[a] = Au(l, u);
- }
- return {
- unitId: t,
- subUnitId: o,
- columnData: r
- };
- }, Lt = {
- id: "sheet.mutation.set-col-data",
- type: v.MUTATION,
- handler: (n, e) => {
- const { columnData: t } = e, o = n.get(M), s = N(o, e);
- if (!s) return !1;
- const { worksheet: r } = s, i = r.getColumnManager();
- for (const a in t) {
- const u = t[a];
- if (u == null) {
- i.removeColumn(Number(a));
- continue;
- }
- const l = i.getColumnOrCreate(Number(a));
- Object.assign(l, u);
- }
- return !0;
- }
- }, $u = {
- type: v.COMMAND,
- id: "sheet.command.set-col-data",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, e);
- if (!r) return !1;
- const { columnData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = {
- subUnitId: u,
- unitId: a,
- columnData: i
- }, d = xu(c, l);
- return t.syncExecuteCommand(Lt.id, c) ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Lt.id, params: d }],
- redoMutations: [{ id: Lt.id, params: c }]
- }), !0) : !1;
- }
- }, Wu = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- }, Xt = {
- id: "sheet.mutation.set-col-hidden",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (!o)
- return !1;
- const s = o.getSheetBySheetId(e.subUnitId).getColumnManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startColumn; a < i.endColumn + 1; a++) {
- const u = s.getColumnOrCreate(a);
- u != null && (u.hd = te.TRUE);
- }
- }
- return !0;
- }
- }, Lu = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- }, qt = {
- id: "sheet.mutation.set-col-visible",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (!o)
- return !1;
- const s = o.getSheetBySheetId(e.subUnitId).getColumnManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startColumn; a < i.endColumn + 1; a++) {
- const u = s.getColumnOrCreate(a);
- u != null && (u.hd = te.FALSE);
- }
- }
- return !0;
- }
- }, Kn = {
- type: v.COMMAND,
- id: "sheet.command.set-col-visible-on-cols",
- handler: (n, e) => {
- var C, S;
- const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(V), i = n.get(E), a = n.get(M), u = N(a, { unitId: t, subUnitId: o });
- if (!u) return !1;
- const { worksheet: l } = u, c = {
- unitId: t,
- subUnitId: o,
- ranges: s
- }, d = {
- unitId: t,
- subUnitId: o,
- reveal: !0,
- selections: s.map((I) => ({ range: I, primary: ve(I, l), style: null }))
- }, h = Lu(n, c), m = {
- unitId: t,
- subUnitId: o,
- selections: Er(s).map((I) => ({
- range: I,
- primary: ve(I, l),
- style: null
- }))
- }, g = z([
- { id: qt.id, params: c },
- { id: re.id, params: d }
- ], i), f = r.onCommandExecute({
- id: Kn.id,
- params: e
- }), p = z([...f.redos], i);
- return g.result && p.result && n.get(W).pushUndoRedo({
- unitID: t,
- undoMutations: [
- { id: Xt.id, params: h },
- { id: re.id, params: m },
- ...(C = f.undos) != null ? C : []
- ],
- redoMutations: [
- ...(S = f.preRedos) != null ? S : [],
- { id: qt.id, params: c },
- { id: re.id, params: d },
- ...f.redos
- ]
- }), !0;
- }
- }, br = {
- type: v.COMMAND,
- id: "sheet.command.set-selected-cols-visible",
- handler: (n) => {
- var l;
- 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);
- if (!(o != null && o.length)) return !1;
- const s = N(n.get(M));
- if (!s) return !1;
- const { worksheet: r, unitId: i, subUnitId: a } = s, u = o.map((c) => r.getHiddenCols(c.startColumn, c.endColumn)).flat();
- return t.executeCommand(Kn.id, {
- unitId: i,
- subUnitId: a,
- ranges: u
- });
- }
- }, yr = {
- type: v.COMMAND,
- id: "sheet.command.set-col-hidden",
- handler: (n, e) => {
- var S, I, w, b;
- const t = n.get(F), o = n.get(V), s = n.get(M), r = n.get(E);
- 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);
- if (!(i != null && i.length)) return !1;
- const a = N(s, e);
- if (!a) return !1;
- const { worksheet: u, unitId: l, subUnitId: c } = a;
- i = Vu(a.worksheet, i);
- const d = { unitId: l, subUnitId: c, ranges: i }, h = {
- unitId: l,
- subUnitId: c,
- selections: Er(i).map((y) => ({
- range: y,
- primary: ve(y, u),
- style: null
- }))
- }, m = Wu(n, d), g = {
- unitId: l,
- subUnitId: c,
- reveal: !0,
- selections: i.map((y) => ({
- range: y,
- primary: ve(y, u),
- style: null
- }))
- }, f = z([
- { id: Xt.id, params: d },
- { id: re.id, params: h }
- ], r), p = o.onCommandExecute({
- id: yr.id,
- params: d
- }), C = z([...p.redos], r);
- return f.result && C.result ? (n.get(W).pushUndoRedo({
- unitID: l,
- undoMutations: [
- { id: qt.id, params: m },
- { id: re.id, params: g },
- ...(w = p.undos) != null ? w : []
- ],
- redoMutations: [
- ...(b = p.preRedos) != null ? b : [],
- { id: Xt.id, params: d },
- { id: re.id, params: h },
- ...p.redos
- ]
- }), !0) : !1;
- }
- };
- function Vu(n, e) {
- const t = n.getRowCount() - 1, o = n.getHiddenCols(), s = [];
- return e.forEach((r) => {
- const i = o.filter((a) => a.startColumn >= r.startColumn && a.endColumn <= r.endColumn);
- if (i.length) {
- let a = r.startColumn;
- i.forEach((u) => {
- u.startColumn > a && (s.push({ startColumn: a, endColumn: u.startColumn - 1, startRow: 0, endRow: t }), a = u.endColumn + 1);
- }), a <= r.endColumn && s.push({ startColumn: a, endColumn: r.endColumn, startRow: 0, endRow: t });
- } else
- s.push(r);
- }), s;
- }
- function Er(n) {
- return Hu(n).map((t) => {
- const o = t.startColumn === 0 ? t.endColumn + 1 : t.startColumn - 1;
- return {
- ...t,
- startColumn: o,
- endColumn: o
- };
- });
- }
- function Hu(n) {
- const e = [];
- let t;
- return n.sort((o, s) => o.startColumn - s.startColumn).forEach((o) => {
- if (!t) {
- t = o;
- return;
- }
- t.endColumn === o.startColumn - 1 ? t.endColumn = o.endColumn : (e.push(t), t = o);
- }), e.push(t), e;
- }
- const Ur = {
- id: "sheet.command.set-defined-name",
- type: v.COMMAND,
- handler: (n, e) => {
- var d, h;
- const t = n.get(E), o = n.get(W), s = n.get(V);
- if (!e) return !1;
- const r = {
- ...e
- }, i = Oi(n, e), a = s.onCommandExecute({ id: Ur.id, params: e }), u = [
- ...(d = a.preRedos) != null ? d : [],
- { id: Cn.id, params: i },
- { id: Gt.id, params: r },
- ...a.redos
- ], l = [
- ...(h = a.preUndos) != null ? h : [],
- { id: Cn.id, params: r },
- { id: Gt.id, params: i },
- ...a.undos
- ];
- return z(u, t) ? (o.pushUndoRedo({
- unitID: e.unitId,
- undoMutations: l.filter(Boolean),
- redoMutations: u.filter(Boolean)
- }), !0) : !1;
- }
- }, Pr = (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (s == null)
- throw new Error("worksheet is null error!");
- const i = s.getConfig().freeze;
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ...i
- };
- }, ut = {
- id: "sheet.mutation.set-frozen",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId);
- if (!s) return !1;
- const r = s.getConfig(), { startRow: i, startColumn: a, ySplit: u, xSplit: l } = e;
- return r.freeze = { startRow: i, startColumn: a, ySplit: u, xSplit: l }, !0;
- }
- }, Bu = {
- type: v.COMMAND,
- id: "sheet.command.set-frozen",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, { unitId: e.unitId, subUnitId: e.subUnitId });
- if (!r) return !1;
- const { unitId: i, subUnitId: a, worksheet: u } = r, { startColumn: l, startRow: c, xSplit: d, ySplit: h } = e;
- if (c >= u.getRowCount() || l >= u.getColumnCount() || d >= u.getColumnCount() || h >= u.getRowCount())
- return !1;
- const m = {
- unitId: i,
- subUnitId: a,
- ...e
- }, g = Pr(n, m);
- return t.syncExecuteCommand(ut.id, m) ? (o.pushUndoRedo({
- unitID: i,
- undoMutations: [{ id: ut.id, params: g }],
- redoMutations: [{ id: ut.id, params: m }]
- }), !0) : !1;
- }
- }, Fu = {
- type: v.COMMAND,
- id: "sheet.command.cancel-frozen",
- handler: (n, e) => {
- 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 });
- if (!r) return !1;
- const { unitId: i, subUnitId: a } = r, u = {
- unitId: i,
- subUnitId: a,
- startRow: -1,
- startColumn: -1,
- xSplit: 0,
- ySplit: 0
- }, l = Pr(n, u);
- return t.syncExecuteCommand(ut.id, u) && s.pushUndoRedo({
- unitID: i,
- undoMutations: [{ id: ut.id, params: l }],
- redoMutations: [{ id: ut.id, params: u }]
- }), !0;
- }
- }, Vt = {
- id: "sheet.mutation.set-gridlines-color",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = N(n.get(M), e);
- if (!t) return !1;
- const { worksheet: o } = t, s = o.getConfig();
- return s.gridlinesColor = e.color, !0;
- }
- }, ju = {
- type: v.COMMAND,
- id: "sheet.command.set-gridlines-color",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s);
- if (!r) return !1;
- const { worksheet: i } = r, a = i.getConfig().gridlinesColor;
- if (a === (e == null ? void 0 : e.color)) return !1;
- const { unitId: u, subUnitId: l } = r, c = {
- color: e == null ? void 0 : e.color,
- unitId: u,
- subUnitId: l
- }, d = {
- color: a,
- unitId: u,
- subUnitId: l
- };
- return t.syncExecuteCommand(Vt.id, c) ? (o.pushUndoRedo({
- unitID: u,
- undoMutations: [{ id: Vt.id, params: d }],
- redoMutations: [{ id: Vt.id, params: c }]
- }), !0) : !1;
- }
- }, he = {
- id: "sheet.mutation.set-range-protection",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, rule: s, ruleId: r } = e;
- return n.get(de).setRule(t, o, r, s), !0;
- }
- }, qd = (n, e) => {
- const { unitId: t, subUnitId: o, ruleId: s } = e, i = n.get(de).getRule(t, o, s);
- return i ? {
- id: he.id,
- params: {
- ...e,
- rule: i
- }
- } : null;
- }, Ct = {
- id: "sheet.mutation.set-worksheet-protection",
- type: v.MUTATION,
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, rule: s } = e;
- return n.get(Ye).setRule(t, o, s), !0;
- }
- }, Gu = {
- type: v.COMMAND,
- id: "sheet.command.set-protection",
- async handler(n, e) {
- if (!e)
- return !1;
- 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 = [];
- 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({
- unitID: a,
- undoMutations: c,
- redoMutations: l
- }), !0;
- }
- }, zu = (n, e) => {
- const { unitId: t, subUnitId: o, rowData: s } = n, r = {}, i = e.getRowManager();
- for (const a in s) {
- const u = s[a], l = i.getRow(Number(a));
- r[a] = Du(l, u);
- }
- return {
- unitId: t,
- subUnitId: o,
- rowData: r
- };
- }, Ht = {
- id: "sheet.mutation.set-row-data",
- type: v.MUTATION,
- handler: (n, e) => {
- const { rowData: t } = e, o = n.get(M), s = N(o, e);
- if (!s) return !1;
- const { worksheet: r } = s, i = r.getRowManager();
- for (const a in t) {
- const u = t[a];
- if (u == null) {
- i.removeRow(Number(a));
- continue;
- }
- const l = i.getRowOrCreate(Number(a));
- Object.assign(l, u);
- }
- return !0;
- }
- }, Ku = {
- type: v.COMMAND,
- id: "sheet.command.set-row-data",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s, e);
- if (!r) return !1;
- const { rowData: i } = e, { unitId: a, subUnitId: u, worksheet: l } = r, c = {
- subUnitId: u,
- unitId: a,
- rowData: i
- }, d = zu(c, l);
- return t.syncExecuteCommand(Ht.id, c) ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Ht.id, params: d }],
- redoMutations: [{ id: Ht.id, params: c }]
- }), !0) : !1;
- }
- }, Ju = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- }, Zt = {
- id: "sheet.mutation.set-row-visible",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId).getRowManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startRow; a < i.endRow + 1; a++) {
- const u = s.getRowOrCreate(a);
- u != null && (u.hd = 0);
- }
- }
- return !0;
- }
- }, Yu = (n, e) => {
- if (n.get(M).getUniverSheetInstance(e.unitId) == null)
- throw new Error("universheet is null error!");
- return {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- ranges: e.ranges
- };
- }, Qt = {
- id: "sheet.mutation.set-row-hidden",
- type: v.MUTATION,
- handler: (n, e) => {
- const o = n.get(M).getUniverSheetInstance(e.unitId);
- if (o == null)
- throw new Error("universheet is null error!");
- const s = o.getSheetBySheetId(e.subUnitId).getRowManager();
- for (let r = 0; r < e.ranges.length; r++) {
- const i = e.ranges[r];
- for (let a = i.startRow; a < i.endRow + 1; a++) {
- const u = s.getRowOrCreate(a);
- u != null && (u.hd = 1);
- }
- }
- return !0;
- }
- }, Jn = {
- type: v.COMMAND,
- id: "sheet.command.set-specific-rows-visible",
- handler: (n, e) => {
- var C, S, I;
- const { unitId: t, subUnitId: o, ranges: s } = e, r = n.get(E), i = n.get(W), a = n.get(V), u = N(n.get(M), { unitId: t, subUnitId: o });
- if (!u) return !1;
- const { worksheet: l } = u, c = { unitId: t, subUnitId: o, ranges: s }, d = {
- unitId: t,
- subUnitId: o,
- reveal: !0,
- selections: s.map((w) => ({
- range: w,
- primary: ve(w, l),
- style: null
- }))
- }, h = Ju(n, c), m = {
- unitId: t,
- subUnitId: o,
- selections: Nr(s).map((w) => ({
- range: w,
- primary: ve(w, l),
- style: null
- }))
- }, g = z(
- [
- { id: Zt.id, params: c },
- { id: re.id, params: d }
- ],
- r
- ), f = a.onCommandExecute({
- id: Jn.id,
- params: e
- }), p = z([...f.redos], r);
- return g.result && p.result && i.pushUndoRedo({
- unitID: t,
- undoMutations: [
- ...(C = f.preUndos) != null ? C : [],
- { id: Qt.id, params: h },
- { id: re.id, params: m },
- ...(S = f.undos) != null ? S : []
- ],
- redoMutations: [
- ...(I = f.preRedos) != null ? I : [],
- { id: Zt.id, params: c },
- { id: re.id, params: d },
- ...f.redos
- ]
- }), !0;
- }
- }, Tr = {
- type: v.COMMAND,
- id: "sheet.command.set-selected-rows-visible",
- handler: async (n) => {
- var c;
- 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);
- if (!(s != null && s.length)) return !1;
- const r = N(t);
- if (!r) return !1;
- const { worksheet: i, unitId: a, subUnitId: u } = r, l = s.map((d) => i.getHiddenRows(d.startRow, d.endRow)).flat();
- return o.executeCommand(Jn.id, {
- unitId: a,
- subUnitId: u,
- ranges: l
- });
- }
- }, kr = {
- type: v.COMMAND,
- id: "sheet.command.set-rows-hidden",
- handler: (n, e) => {
- var S, I, w, b, y, x;
- const t = n.get(F), o = n.get(E), s = n.get(W), r = n.get(M), i = n.get(V);
- let a = (S = e == null ? void 0 : e.ranges) != null && S.length ? e.ranges : (I = t.getCurrentSelections()) == null ? void 0 : I.map((T) => T.range).filter((T) => T.rangeType === H.ROW);
- if (!(a != null && a.length)) return !1;
- const u = N(r, e);
- if (!u) return !1;
- a = Xu(u.worksheet, a);
- const { unitId: l, subUnitId: c, worksheet: d } = u, h = { unitId: l, subUnitId: c, ranges: a }, m = {
- unitId: l,
- subUnitId: c,
- selections: Nr(a).map((T) => ({
- range: T,
- primary: ve(T, d),
- style: null
- }))
- }, g = Yu(n, h), f = {
- unitId: l,
- subUnitId: c,
- reveal: !0,
- selections: a.map((T) => ({
- range: T,
- primary: ve(T, d),
- style: null
- }))
- }, p = i.onCommandExecute({ id: kr.id, params: h });
- return z([
- ...(w = p.preRedos) != null ? w : [],
- { id: Qt.id, params: h },
- { id: re.id, params: m },
- ...p.redos
- ], o).result && s.pushUndoRedo({
- unitID: l,
- undoMutations: [
- ...(b = p.preUndos) != null ? b : [],
- { id: Zt.id, params: g },
- { id: re.id, params: f },
- ...(y = p.undos) != null ? y : []
- ],
- redoMutations: [
- ...(x = p.preRedos) != null ? x : [],
- { id: Qt.id, params: h },
- { id: re.id, params: m },
- ...p.redos
- ]
- }), !0;
- }
- };
- function Xu(n, e) {
- const t = n.getMaxColumns() - 1, o = n.getHiddenRows(), s = [];
- return e.forEach((r) => {
- const i = o.filter((a) => a.startRow >= r.startRow && a.endRow <= r.endRow);
- if (i.length) {
- let a = r.startRow;
- i.forEach((u) => {
- u.startRow > a && (s.push({ startRow: a, endRow: u.startRow - 1, startColumn: 0, endColumn: t }), a = u.endRow + 1);
- }), a <= r.endRow && s.push({ startRow: a, endRow: r.endRow, startColumn: 0, endColumn: t });
- } else
- s.push(r);
- }), s;
- }
- function Nr(n) {
- return qu(n).map((t) => {
- const o = t.startRow === 0 ? t.endRow + 1 : t.startRow - 1;
- return {
- ...t,
- startRow: o,
- endRow: o
- };
- });
- }
- function qu(n) {
- const e = [];
- let t;
- return n.sort((o, s) => o.startRow - s.startRow).forEach((o) => {
- if (!t) {
- t = o;
- return;
- }
- o.startRow === t.endRow + 1 ? t.endRow = o.endRow : (e.push(t), t = o);
- }), e.push(t), e;
- }
- const fe = {
- type: v.COMMAND,
- id: "sheet.command.set-style",
- handler: (n, e) => {
- var b;
- const t = n.get(M), o = N(t, e);
- if (!o) return !1;
- 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);
- if (!(h != null && h.length))
- return !1;
- const m = new G(), g = Za(i);
- if (O.isArray(u.value))
- for (let y = 0; y < h.length; y++)
- g.forOperableEach(h[y], (x, T, U) => {
- m.setValue(x, T, {
- s: {
- [u.type]: u.value[x - U.startRow][T - U.startColumn]
- }
- });
- });
- else
- for (let y = 0; y < h.length; y++) {
- const x = {
- s: {
- [u.type]: u.value
- }
- };
- g.forOperableEach(h[y], (T, U) => m.setValue(T, U, x));
- }
- const f = {
- subUnitId: r,
- unitId: s,
- cellValue: m.getMatrix()
- }, p = Ae(
- n,
- f
- ), C = l.syncExecuteCommand(
- Q.id,
- f
- ), { undos: S, redos: I } = n.get(V).onCommandExecute({
- id: fe.id,
- params: e
- }), w = z([...I], l);
- return C && w.result ? (c.pushUndoRedo({
- unitID: f.unitId,
- undoMutations: [{ id: Q.id, params: p }, ...S],
- redoMutations: [{ id: Q.id, params: f }, ...I]
- }), !0) : !1;
- }
- }, Zd = {
- type: v.COMMAND,
- id: "sheet.command.set-bold",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e) return !1;
- const t = N(n.get(M));
- if (!t) return !1;
- const { worksheet: o } = t, { actualRow: s, actualColumn: r } = e.primary, a = {
- style: {
- type: "bl",
- value: o.getRange(s, r).getFontWeight() === gi.BOLD ? te.FALSE : te.TRUE
- }
- };
- return n.get(E).syncExecuteCommand(fe.id, a);
- }
- }, Qd = {
- type: v.COMMAND,
- id: "sheet.command.set-italic",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e) return !1;
- const t = N(n.get(M));
- if (!t) return !1;
- const { worksheet: o } = t;
- let s = !0;
- if (e.primary) {
- const { startRow: i, startColumn: a } = e.primary;
- s = o.getRange(i, a).getFontStyle() === fi.ITALIC;
- }
- const r = {
- style: {
- type: "it",
- value: s ? te.FALSE : te.TRUE
- }
- };
- return n.get(E).syncExecuteCommand(fe.id, r);
- }
- }, eh = {
- type: v.COMMAND,
- id: "sheet.command.set-underline",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e) return !1;
- const t = N(n.get(M));
- if (!t) return !1;
- const { worksheet: o } = t;
- let s = !0;
- e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getUnderline().s);
- const r = {
- style: {
- type: "ul",
- value: {
- s: s ? te.FALSE : te.TRUE
- }
- }
- };
- return n.get(E).syncExecuteCommand(fe.id, r);
- }
- }, th = {
- type: v.COMMAND,
- id: "sheet.command.set-stroke",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e) return !1;
- const t = N(n.get(M));
- if (!t) return !1;
- const { worksheet: o } = t;
- let s = !0;
- e.primary && (s = !!o.getRange(e.primary.actualRow, e.primary.actualColumn).getStrikeThrough().s);
- const r = {
- style: {
- type: "st",
- value: { s: s ? te.FALSE : te.TRUE }
- }
- };
- return n.get(E).syncExecuteCommand(fe.id, r);
- }
- }, nh = {
- type: v.COMMAND,
- id: "sheet.command.set-overline",
- handler: (n) => {
- const e = n.get(F).getCurrentLastSelection();
- if (!e) return !1;
- const t = N(n.get(M));
- if (!t) return !1;
- const { worksheet: o } = t;
- let s = !0;
- e.primary && (s = !!o.getRange(e.primary.startRow, e.primary.startColumn).getOverline().s);
- const r = {
- style: {
- type: "ol",
- value: {
- s: s ? te.FALSE : te.TRUE
- }
- }
- };
- return n.get(E).syncExecuteCommand(fe.id, r);
- }
- }, oh = {
- type: v.COMMAND,
- id: "sheet.command.set-font-family",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = n.get(E), o = {
- style: {
- type: "ff",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, sh = {
- type: v.COMMAND,
- id: "sheet.command.set-font-size",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = n.get(E), o = {
- style: {
- type: "fs",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, Zu = {
- type: v.COMMAND,
- id: "sheet.command.set-text-color",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = n.get(E), o = {
- style: {
- type: "cl",
- value: {
- rgb: e.value
- }
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, Qu = {
- type: v.COMMAND,
- id: "sheet.command.reset-text-color",
- handler: (n) => {
- const e = n.get(E), t = {
- style: {
- type: "cl",
- value: {
- rgb: null
- // use null to reset text color
- }
- }
- };
- return e.syncExecuteCommand(fe.id, t);
- }
- }, el = {
- type: v.COMMAND,
- id: "sheet.command.set-background-color",
- handler: (n, e) => {
- if (!e || !e.value)
- return !1;
- const t = n.get(E), o = {
- style: {
- type: "bg",
- value: {
- rgb: e.value
- }
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, tl = {
- type: v.COMMAND,
- id: "sheet.command.reset-background-color",
- handler: (n) => {
- const e = n.get(E), t = {
- style: {
- type: "bg",
- value: {
- rgb: null
- // use null to reset background color
- }
- }
- };
- return e.syncExecuteCommand(fe.id, t);
- }
- }, nl = {
- type: v.COMMAND,
- id: "sheet.command.set-vertical-text-align",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = n.get(E), o = {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- style: {
- type: "vt",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, ol = {
- type: v.COMMAND,
- id: "sheet.command.set-horizontal-text-align",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = n.get(E), o = {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- style: {
- type: "ht",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, sl = {
- type: v.COMMAND,
- id: "sheet.command.set-text-wrap",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = n.get(E), o = {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range,
- style: {
- type: "tb",
- value: e.value
- }
- };
- return t.syncExecuteCommand(fe.id, o);
- }
- }, rl = {
- type: v.COMMAND,
- id: "sheet.command.set-text-rotation",
- handler: (n, e) => {
- if (!e)
- return !1;
- const t = typeof e.value == "number" ? { a: e.value } : { a: 0, v: te.TRUE }, o = n.get(E), s = {
- style: {
- type: "tr",
- value: t
- }
- };
- return o.syncExecuteCommand(fe.id, s);
- }
- }, il = (n, e) => {
- const r = n.get(M).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().tabColor;
- return {
- ...O.deepClone(e),
- color: r
- };
- }, fn = {
- id: "sheet.mutation.set-tab-color",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M).getUniverSheetInstance(e.unitId);
- if (!t) return !1;
- const o = t.getSheetBySheetId(e.subUnitId);
- return o ? (o.getConfig().tabColor = e.color, !0) : !1;
- }
- }, al = {
- type: v.COMMAND,
- id: "sheet.command.set-tab-color",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = N(n.get(M));
- if (!s) return !1;
- const { unitId: r, subUnitId: i } = s, a = {
- color: e.value,
- unitId: r,
- subUnitId: i
- }, u = il(n, a);
- return t.syncExecuteCommand(fn.id, a) ? (o.pushUndoRedo({
- unitID: r,
- undoMutations: [{ id: fn.id, params: u }],
- redoMutations: [{ id: fn.id, params: a }]
- }), !0) : !1;
- }
- }, Or = {
- id: "sheet.mutation.set-workbook-name",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M).getUnit(e.unitId, B.UNIVER_SHEET);
- return t ? (t.setName(e.name), !0) : !1;
- }
- }, Dr = {
- type: v.COMMAND,
- id: "sheet.command.set-workbook-name",
- handler: async (n, e) => {
- var l;
- if (!n.get(M).getUnit(e.unitId, B.UNIVER_SHEET)) return !1;
- const r = n.get(V).onCommandExecute({
- id: Dr.id,
- params: e
- }), i = {
- name: e.name,
- unitId: e.unitId
- }, a = [
- ...(l = r.preRedos) != null ? l : [],
- { id: Or.id, params: i },
- ...r.redos
- ], u = n.get(E);
- return z(a, u).result;
- }
- }, an = {
- id: "sheet.operation.set-worksheet-active",
- type: v.OPERATION,
- handler: (n, e) => {
- const t = n.get(M).getUniverSheetInstance(e.unitId);
- if (!t) return !1;
- const o = t.getWorksheets();
- for (const [, s] of o)
- if (s.getSheetId() === e.subUnitId)
- return t.setActiveSheet(s), !0;
- return !1;
- }
- }, ul = 4, Ar = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-activate",
- handler: (n, e, t) => {
- const o = n.get(E), s = N(n.get(M), e);
- if (!s) return !1;
- const { unitId: r, subUnitId: i } = s;
- return new Promise((a) => {
- setTimeout(() => {
- const u = o.syncExecuteCommand(an.id, {
- unitId: r,
- subUnitId: i
- }, t);
- a(u);
- }, ul);
- });
- }
- }, xr = (n, e) => {
- const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getColumnManager();
- for (let a = 0; a < s.length; a++) {
- const u = s[a];
- for (let l = u.startColumn; l < u.endColumn + 1; l++) {
- const c = i.getColumnOrCreate(l);
- r[l] = c.w;
- }
- }
- return {
- unitId: t,
- subUnitId: o,
- ranges: s,
- colWidth: r
- };
- }, tt = {
- id: "sheet.mutation.set-worksheet-col-width",
- type: v.MUTATION,
- handler: (n, e) => {
- var u;
- const t = n.get(M), o = N(t, e);
- if (!o) return !1;
- const { worksheet: s } = o, r = s.getConfig().defaultColumnWidth, i = s.getColumnManager(), a = e.ranges;
- for (let l = 0; l < a.length; l++) {
- const c = a[l];
- for (let d = c.startColumn; d < c.endColumn + 1; d++) {
- if (!s.getColVisible(d)) continue;
- const m = i.getColumnOrCreate(d);
- typeof e.colWidth == "number" ? m.w = e.colWidth : m.w = (u = e.colWidth[d]) != null ? u : r;
- }
- }
- return !0;
- }
- }, Oo = {
- type: v.COMMAND,
- id: "sheet.command.delta-column-width",
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- const o = n.get(F).getCurrentSelections();
- if (!(o != null && o.length))
- return !1;
- const s = n.get(E), r = n.get(W), i = N(n.get(M));
- if (!i) return !1;
- 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 }) => {
- const { startColumn: T, endColumn: U } = x;
- return T <= c && c <= U;
- }) ? H.COLUMN : H.NORMAL;
- let C;
- if (p === H.ALL) {
- const x = a.getRowCount(), T = new Array(a.getColumnCount()).fill(void 0).map(
- (U, P) => ({ startRow: 0, endRow: x - 1, startColumn: P, endColumn: P })
- );
- C = {
- subUnitId: l,
- unitId: u,
- colWidth: m,
- ranges: T
- };
- } else p === H.COLUMN ? C = {
- subUnitId: l,
- unitId: u,
- ranges: f.map((x) => k.clone(x.range)),
- colWidth: m
- } : C = {
- subUnitId: l,
- unitId: u,
- colWidth: m,
- ranges: [
- {
- startRow: 0,
- endRow: a.getMaxRows() - 1,
- startColumn: c,
- endColumn: c
- }
- ]
- };
- const { undos: S, redos: I } = n.get(V).onCommandExecute({
- id: Oo.id,
- params: C
- }), w = xr(
- C,
- a
- ), b = s.syncExecuteCommand(
- tt.id,
- C
- ), y = z([...I], s);
- return b && y.result && r.pushUndoRedo({
- unitID: u,
- undoMutations: [{ id: tt.id, params: w }, ...S],
- redoMutations: [{ id: tt.id, params: C }, ...I]
- }), !0;
- }
- }, Mn = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-col-width",
- handler: (n, e) => {
- var S, I, w, b;
- 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);
- if (!(i != null && i.length)) return !1;
- const a = N(n.get(M), e);
- if (!a) return !1;
- const { subUnitId: u, unitId: l, worksheet: c } = a, d = {
- subUnitId: u,
- unitId: l,
- ranges: i,
- colWidth: e.value
- }, h = xr(d, c), m = o.syncExecuteCommand(tt.id, d), { undos: g, redos: f } = n.get(V).onCommandExecute({
- id: Mn.id,
- params: d
- }), p = r.onCommandExecute({
- id: Mn.id,
- params: d
- }), C = z([...f, ...p.redos], o);
- return m && C.result ? (s.pushUndoRedo({
- unitID: l,
- undoMutations: [...(w = p.preUndos) != null ? w : [], { id: tt.id, params: h }, ...g],
- redoMutations: [...(b = p.preRedos) != null ? b : [], { id: tt.id, params: d }, ...f]
- }), !0) : !1;
- }
- }, ll = {
- type: v.COMMAND,
- id: "sheet.command.set-col-is-auto-width",
- handler: async (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(F), r = n.get(M), i = N(r, e);
- if (!i) return !1;
- const { unitId: a, subUnitId: u } = i;
- let l = [];
- if (e != null && e.ranges)
- l = [...e.ranges];
- else {
- const g = s.getCurrentSelections();
- for (let f = 0; f < g.length; f++)
- l.push(g[f].range);
- }
- if (!(l != null && l.length))
- return !1;
- const c = {
- unitId: a,
- subUnitId: u,
- ranges: l
- }, { undos: d, redos: h } = n.get(V).onCommandExecute({
- id: ll.id,
- params: c
- });
- return z([...h], t).result ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [...d],
- redoMutations: [...h]
- }), !0) : !1;
- }
- }, Bt = {
- id: "sheet.mutation.set-worksheet-default-style",
- type: v.MUTATION,
- handler: (n, e) => {
- const { defaultStyle: t } = e, o = n.get(M), s = N(o);
- if (!s) return !1;
- const { worksheet: r } = s;
- return r ? (r.setDefaultCellStyle(t), !0) : !1;
- }
- }, cl = (n, e) => {
- const t = Et(n.get(M), e);
- if (!t)
- throw new Error("[SetWorksheetDefaultStyleMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- subUnitId: o.getSheetId(),
- defaultStyle: o.getDefaultCellStyle()
- };
- }, dl = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-default-style",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), { unitId: s } = e, r = cl(n, e);
- return t.syncExecuteCommand(Bt.id, e) ? (o.pushUndoRedo({
- unitID: s,
- undoMutations: [{ id: Bt.id, params: r }],
- redoMutations: [{ id: Bt.id, params: e }]
- }), !0) : !1;
- }
- }, $r = (n, e) => {
- const t = Et(n.get(M), e);
- if (!t)
- throw new Error("[SetWorksheetHideMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- hidden: o.isSheetHidden(),
- unitId: e.unitId,
- subUnitId: o.getSheetId()
- };
- }, lt = {
- id: "sheet.mutation.set-worksheet-hidden",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M).getUniverSheetInstance(e.unitId);
- if (t == null)
- return !1;
- const o = t.getSheetBySheetId(e.subUnitId);
- return o ? (o.getConfig().hidden = e.hidden, !0) : !1;
- }
- }, hl = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-hidden",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(bt), r = n.get(Ke), i = N(n.get(M), e);
- if (!i) return !1;
- const { workbook: a, worksheet: u, unitId: l, subUnitId: c } = i;
- if (u.getConfig().hidden === te.TRUE) return !1;
- const h = {
- unitId: l,
- subUnitId: c,
- hidden: te.TRUE
- }, m = $r(n, h);
- 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({
- unitID: l,
- undoMutations: [{ id: lt.id, params: m }],
- redoMutations: [{ id: lt.id, params: h }]
- }), !0) : !1;
- }
- }, ml = (n, e) => {
- const t = Et(n.get(M), e);
- if (!t)
- throw new Error("[SetWorksheetNameMutationFactory]: worksheet is null error!");
- const { worksheet: o } = t;
- return {
- unitId: e.unitId,
- name: o.getName(),
- subUnitId: o.getSheetId()
- };
- }, _n = {
- id: "sheet.mutation.set-worksheet-name",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M).getUniverSheetInstance(e.unitId);
- if (t == null)
- return !1;
- const o = t.getSheetBySheetId(e.subUnitId);
- return o ? (o.getConfig().name = e.name, !0) : !1;
- }
- }, Do = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-name",
- handler: (n, e) => {
- var g, f;
- const t = n.get(E), o = n.get(W), s = n.get(V), r = N(n.get(M), e);
- if (!r) return !1;
- const { unitId: i, subUnitId: a } = r, u = {
- subUnitId: a,
- name: e.name,
- unitId: i
- }, l = ml(
- n,
- u
- ), c = s.onCommandExecute({
- id: Do.id,
- params: e
- }), d = [
- ...(g = c.preRedos) != null ? g : [],
- { id: _n.id, params: u },
- ...c.redos
- ], h = [
- ...(f = c.preUndos) != null ? f : [],
- { id: _n.id, params: l },
- ...c.undos
- ];
- return z(d, t).result ? (o.pushUndoRedo({
- unitID: i,
- undoMutations: h,
- redoMutations: d
- }), !0) : !1;
- }
- }, gl = (n, e) => ({
- ...O.deepClone(e),
- toOrder: e.fromOrder,
- fromOrder: e.toOrder
- }), Rn = {
- id: "sheet.mutation.set-worksheet-order",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M).getUniverSheetInstance(e.unitId);
- if (!t) return !1;
- const o = t.getConfig();
- return o.sheetOrder.splice(e.fromOrder, 1), o.sheetOrder.splice(e.toOrder, 0, e.subUnitId), !0;
- }
- }, Wr = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-order",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = N(n.get(M), e);
- if (!s) return !1;
- const { workbook: r, unitId: i, subUnitId: a } = s, l = {
- fromOrder: r.getConfig().sheetOrder.indexOf(a),
- toOrder: e.order,
- unitId: i,
- subUnitId: a
- }, c = gl(n, l);
- return t.syncExecuteCommand(Rn.id, l) ? (o.pushUndoRedo({
- unitID: i,
- undoMutations: [{ id: Rn.id, params: c }],
- redoMutations: [{ id: Rn.id, params: l }]
- }), !0) : !1;
- }
- };
- class un {
- constructor() {
- R(this, "_model", /* @__PURE__ */ new Map());
- R(this, "_pointChange", new Le());
- R(this, "pointChange$", this._pointChange.asObservable());
- }
- addRule(e) {
- this._ensureSubUnitMap(e.unitId).set(e.subUnitId, e), this._pointChange.next(e);
- }
- deleteRule(e, t) {
- var s, r, i;
- const o = (s = this._model.get(e)) == null ? void 0 : s.get(t);
- o && ((i = (r = this._model) == null ? void 0 : r.get(e)) == null || i.delete(t), this._pointChange.next(o));
- }
- getRule(e, t) {
- var o, s;
- return (s = (o = this._model) == null ? void 0 : o.get(e)) == null ? void 0 : s.get(t);
- }
- toObject() {
- const e = {};
- return [...this._model.keys()].forEach((o) => {
- const s = this._model.get(o);
- s != null && s.size && (e[o] = [], [...s.keys()].forEach((i) => {
- const a = s.get(i);
- a && e[o].push(a);
- }));
- }), e;
- }
- fromObject(e) {
- const t = /* @__PURE__ */ new Map();
- Object.keys(e).forEach((o) => {
- const s = e[o];
- if (s != null && s.length) {
- const r = /* @__PURE__ */ new Map();
- s.forEach((i) => {
- r.set(i.subUnitId, i);
- }), t.set(o, r);
- }
- }), this._model = t;
- }
- deleteUnitModel(e) {
- this._model.delete(e);
- }
- _ensureSubUnitMap(e) {
- let t = this._model.get(e);
- return t || (t = /* @__PURE__ */ new Map(), this._model.set(e, t)), t;
- }
- getTargetByPermissionId(e, t) {
- const o = this._model.get(e);
- if (!o) return null;
- for (const [s, r] of o)
- if (r.permissionId === t)
- return [e, s];
- }
- }
- class Lr {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.Delete);
- R(this, "status", J.INIT);
- R(this, "value", !0);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.Delete}.${o}`;
- }
- }
- class Vr {
- constructor(e, t, o) {
- R(this, "type", D.SelectRange);
- R(this, "subType", _.ManageCollaborator);
- R(this, "status", J.INIT);
- R(this, "value", !0);
- R(this, "id");
- R(this, "unitId");
- R(this, "subUnitId");
- R(this, "permissionId");
- this.unitId = e, this.subUnitId = t, this.permissionId = o, this.id = `${D.SelectRange}.${_.ManageCollaborator}.${o}`;
- }
- }
- const Ie = () => [Io, Pe, Vr, Lr], it = [_.Edit, _.View, _.ManageCollaborator, _.Delete], rh = (n = "unitId", e = "subUnitId", t = "permissionId") => Ie().reduce((o, s) => {
- const r = new s(n, e, t);
- return o[r.subType] = r.value, o;
- }, {}), en = () => [
- Me,
- Gs,
- Ws,
- Js,
- Ls,
- js,
- Mo,
- Hs,
- Bs,
- bo,
- vo,
- Fs,
- Ks,
- _o,
- eu,
- Ys,
- zs,
- Vs
- ], fl = [
- _.Edit,
- _.Print,
- _.Comment,
- _.View,
- _.Copy,
- _.Export,
- _.ManageCollaborator,
- _.CreateSheet,
- _.DeleteSheet,
- _.RenameSheet,
- _.HideSheet,
- _.Duplicate,
- _.Share,
- _.MoveSheet,
- _.CopySheet,
- _.RecoverHistory,
- _.ViewHistory,
- _.CreatePermissionObject
- ], we = () => [
- Te,
- Hn,
- rr,
- Zs
- ], ke = () => [
- Xs,
- qs,
- Qs,
- er,
- tr,
- nr,
- sr,
- or,
- ir,
- ar,
- wn,
- $t,
- Wt,
- ur
- ], eo = [
- _.Copy,
- _.DeleteColumn,
- _.DeleteRow,
- _.EditExtraObject,
- _.Filter,
- _.InsertColumn,
- _.InsertRow,
- _.InsertHyperlink,
- _.PivotTable,
- _.SetCellStyle,
- _.SetCellValue,
- _.SetColumnStyle,
- _.SetRowStyle,
- _.Sort
- ];
- var Rl = Object.defineProperty, pl = Object.getOwnPropertyDescriptor, Cl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? pl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Rl(e, t, s), s;
- }, Ze = (n, e) => (t, o) => e(t, o, n);
- const Sl = "SHEET_WORKSHEET_PROTECTION_PLUGIN", wl = "SHEET_WORKSHEET_PROTECTION_POINT_PLUGIN";
- let bn = class extends ps {
- constructor(n, e, t, o, s, r, i, a) {
- super(), this._permissionService = n, this._univerInstanceService = e, this._injector = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointRuleModel = s, this._resourceManagerService = r, this._rangeProtectionRuleModel = i, this._logService = a, this._init(), this._initRuleChange(), this._initRuleSnapshot(), this._initPointSnapshot();
- }
- _init() {
- const n = (e) => {
- const t = e.getUnitId(), o = (s) => {
- const r = s.getSheetId();
- [...we(), ...ke()].forEach((i) => {
- const a = new i(t, r);
- this._permissionService.addPermissionPoint(a);
- }), this._logService.debug("[WorksheetPermissionService]", "Initialization completed", t, r);
- };
- e.getSheets().forEach((s) => {
- o(s);
- }), e.sheetCreated$.subscribe((s) => {
- o(s);
- }), e.sheetDisposed$.subscribe((s) => {
- const r = s.getSheetId();
- this._rangeProtectionRuleModel.getSubunitRuleList(t, r).forEach((a) => {
- [...Ie()].forEach((u) => {
- const l = new u(t, r, a.permissionId);
- this._permissionService.deletePermissionPoint(l.id);
- });
- }), [...we(), ...ke()].forEach((a) => {
- const u = new a(t, r);
- this._permissionService.deletePermissionPoint(u.id);
- });
- });
- };
- this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => {
- n(e);
- }), this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).pipe(Bo(this.dispose$)).subscribe(n), this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).pipe(Bo(this.dispose$)).subscribe((e) => {
- e.getSheets().forEach((t) => {
- const o = e.getUnitId(), s = t.getSheetId();
- we().forEach((r) => {
- const i = new r(o, s);
- this._permissionService.deletePermissionPoint(i.id);
- });
- });
- });
- }
- _initRuleChange() {
- this.disposeWithMe(
- this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => {
- switch (n.type) {
- case "add":
- break;
- case "delete": {
- we().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(t.id, !0);
- });
- break;
- }
- case "set": {
- we().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(t.id, n.rule);
- });
- break;
- }
- }
- })
- );
- }
- _initRuleSnapshot() {
- const n = () => {
- const t = this._worksheetProtectionRuleModel.toObject();
- return JSON.stringify(t);
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- toJson: n,
- parseJson: e,
- pluginName: Sl,
- businesses: [Sn.UNIVER_SHEET],
- onLoad: (t, o) => {
- this._worksheetProtectionRuleModel.fromObject(o), Object.keys(o).forEach((s) => {
- we().forEach((r) => {
- const i = new r(t, s);
- i.value = !1, this._permissionService.addPermissionPoint(i);
- });
- }), this._worksheetProtectionRuleModel.changeRuleInitState(!0);
- },
- onUnLoad: (t) => {
- const o = this._univerInstanceService.getUnit(t);
- o && (o.getSheets().forEach((s) => {
- const r = s.getSheetId();
- [...we(), ...ke()].forEach((i) => {
- const a = new i(t, r);
- this._permissionService.deletePermissionPoint(a.id);
- });
- }), en().forEach((s) => {
- const r = new s(t);
- this._permissionService.deletePermissionPoint(r.id);
- })), this._worksheetProtectionRuleModel.deleteUnitModel(t);
- }
- })
- );
- }
- _initPointSnapshot() {
- const n = () => {
- const t = this._worksheetProtectionPointRuleModel.toObject();
- return JSON.stringify(t);
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- toJson: n,
- parseJson: e,
- pluginName: wl,
- businesses: [Sn.UNIVER_SHEET],
- onLoad: (t, o) => {
- this._worksheetProtectionPointRuleModel.fromObject(o), Object.keys(o).forEach((s) => {
- ke().forEach((r) => {
- const i = new r(t, s);
- this._permissionService.addPermissionPoint(i);
- });
- });
- },
- onUnLoad: (t) => {
- this._worksheetProtectionPointRuleModel.deleteUnitModel(t);
- }
- })
- );
- }
- };
- bn = Cl([
- Ze(0, L(Fe)),
- Ze(1, L(M)),
- Ze(2, L(Ro)),
- Ze(3, L(Ye)),
- Ze(4, L(un)),
- Ze(5, L(nn)),
- Ze(6, L(de)),
- Ze(7, L(Es))
- ], bn);
- const Ao = {
- id: "sheet.mutation.set-worksheet-permission-points",
- type: v.MUTATION,
- handler: (n, e) => {
- const { rule: t } = e;
- return n.get(un).addRule(t), !0;
- }
- }, Il = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-permission-points",
- async handler(n, e) {
- if (!e)
- return !1;
- const t = n.get(E), { rule: o } = e;
- return t.executeCommand(Ao.id, {
- rule: o,
- unitId: o.unitId,
- subUnitId: o.subUnitId
- }), !0;
- }
- }, vl = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-protection",
- async handler(n, e) {
- if (!e)
- return !1;
- 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 };
- if (await t.executeCommand(Ct.id, {
- unitId: a,
- subUnitId: u,
- newRule: l
- })) {
- const d = [{ id: Ct.id, params: { unitId: a, subUnitId: u, newRule: l } }], h = [{ id: Ct.id, params: { unitId: a, subUnitId: u, rule: i } }];
- o.pushUndoRedo({
- unitID: a,
- redoMutations: d,
- undoMutations: h
- });
- }
- return !0;
- }
- }, Ml = 2e3, Hr = (n, e) => {
- const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager();
- for (const { startRow: a, endRow: u } of s)
- for (let l = a; l < u + 1; l++) {
- const c = i.getRowOrCreate(l);
- r[l] = c.h;
- }
- return {
- unitId: t,
- subUnitId: o,
- ranges: s,
- rowHeight: r
- };
- }, xo = (n, e) => {
- const { unitId: t, subUnitId: o, ranges: s } = n, r = {}, i = e.getRowManager();
- for (const { startRow: a, endRow: u } of s)
- for (let l = a; l <= u; l++) {
- const c = i.getRowOrCreate(l);
- r[l] = c.ia;
- }
- return {
- unitId: t,
- subUnitId: o,
- ranges: s,
- autoHeightInfo: r
- };
- }, ih = (n, e) => {
- const { unitId: t, subUnitId: o, rowsAutoHeightInfo: s } = n, r = [], i = e.getRowManager();
- for (const a of s) {
- const { row: u } = a, { ah: l } = i.getRowOrCreate(u);
- r.push({ row: u, autoHeight: l });
- }
- return {
- unitId: t,
- subUnitId: o,
- rowsAutoHeightInfo: r
- };
- }, nt = {
- id: "sheet.mutation.set-worksheet-row-height",
- type: v.MUTATION,
- handler: (n, e) => {
- var l;
- const { ranges: t, rowHeight: o } = e, s = n.get(M), r = N(s, e);
- if (!r) return !1;
- const { worksheet: i } = r, a = i.getRowManager(), u = i.getConfig().defaultRowHeight;
- for (const { startRow: c, endRow: d } of t)
- for (let h = c; h <= d; h++) {
- const m = a.getRowOrCreate(h);
- typeof o == "number" ? m.h = o : m.h = (l = o[h]) != null ? l : u, m.h = Math.min(Ml, m.h);
- }
- return !0;
- }
- }, Oe = {
- id: "sheet.mutation.set-worksheet-row-is-auto-height",
- type: v.MUTATION,
- handler: (n, e) => {
- var a;
- const { ranges: t, autoHeightInfo: o } = e, s = n.get(M), r = N(s, e);
- if (!r) return !1;
- const i = r.worksheet.getRowManager();
- for (const { startRow: u, endRow: l } of t)
- for (let c = u; c <= l; c++) {
- const d = i.getRowOrCreate(c);
- typeof o == "number" ? d.ia = o : d.ia = (a = o[c]) != null ? a : void 0;
- }
- return !0;
- }
- }, Br = {
- id: "sheet.mutation.set-worksheet-row-auto-height",
- type: v.MUTATION,
- handler: (n, e) => {
- const { rowsAutoHeightInfo: t } = e, o = n.get(M), s = N(o, e);
- if (!s) return !1;
- const r = s.worksheet.getRowManager();
- for (const { row: i, autoHeight: a } of t) {
- const u = r.getRowOrCreate(i);
- u.ah = a;
- }
- return !0;
- }
- }, $o = {
- type: v.COMMAND,
- id: "sheet.command.delta-row-height",
- // eslint-disable-next-line max-lines-per-function
- handler: async (n, e) => {
- var U, P;
- const o = n.get(F).getCurrentSelections(), s = n.get(V);
- if (!(o != null && o.length))
- return !1;
- const r = N(n.get(M));
- if (!r) return !1;
- 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 }) => {
- const { startRow: j, endRow: Z } = A;
- return j <= l && l <= Z;
- }) ? H.ROW : H.NORMAL;
- let p;
- if (f === H.ALL) {
- const A = i.getRowCount(), j = new Array(i.getColumnCount()).fill(void 0).map(
- (Z, Y) => ({ startRow: Y, endRow: Y, startColumn: 0, endColumn: A - 1 })
- );
- p = {
- subUnitId: a,
- unitId: u,
- rowHeight: h,
- ranges: j
- };
- } else f === H.ROW ? p = {
- subUnitId: a,
- unitId: u,
- ranges: g.map((A) => k.clone(A.range)),
- rowHeight: h
- } : p = {
- subUnitId: a,
- unitId: u,
- rowHeight: h,
- ranges: [
- {
- startRow: l,
- endRow: l,
- startColumn: 0,
- endColumn: i.getMaxColumns() - 1
- }
- ]
- };
- const C = Hr(p, i), S = {
- unitId: u,
- subUnitId: a,
- ranges: p.ranges,
- autoHeightInfo: te.FALSE
- }, I = xo(S, i), w = n.get(E), b = n.get(W), y = s.onCommandExecute({
- id: $o.id,
- params: p
- }), x = z([
- {
- id: nt.id,
- params: p
- },
- {
- id: Oe.id,
- params: S
- }
- ], w), T = z([...y.redos], w);
- return x.result && T.result ? (b.pushUndoRedo({
- unitID: u,
- undoMutations: [
- ...(U = y.preUndos) != null ? U : [],
- {
- id: nt.id,
- params: C
- },
- {
- id: Oe.id,
- params: I
- },
- ...y.undos
- ],
- redoMutations: [
- ...(P = y.preRedos) != null ? P : [],
- {
- id: nt.id,
- params: p
- },
- {
- id: Oe.id,
- params: S
- },
- ...y.redos
- ]
- }), !0) : !1;
- }
- }, Wo = {
- type: v.COMMAND,
- id: "sheet.command.set-row-height",
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- var I, w, b, y;
- const t = n.get(F), o = n.get(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);
- if (!(a != null && a.length))
- return !1;
- const u = N(r, e);
- if (!u) return !1;
- const { unitId: l, subUnitId: c, worksheet: d } = u, h = {
- subUnitId: c,
- unitId: l,
- ranges: a,
- rowHeight: e.value
- }, m = Hr(h, d), g = {
- unitId: l,
- subUnitId: c,
- ranges: h.ranges,
- autoHeightInfo: te.FALSE
- }, f = xo(g, d), p = z([
- {
- id: nt.id,
- params: h
- },
- {
- id: Oe.id,
- params: g
- }
- ], o), C = i.onCommandExecute({
- id: Wo.id,
- params: h
- }), S = z([...C.redos], o);
- return p.result && S.result ? (s.pushUndoRedo({
- unitID: l,
- undoMutations: [
- ...(b = C.preRedos) != null ? b : [],
- {
- id: nt.id,
- params: m
- },
- {
- id: Oe.id,
- params: f
- },
- ...C.undos
- ],
- redoMutations: [
- ...(y = C.preRedos) != null ? y : [],
- {
- id: nt.id,
- params: h
- },
- {
- id: Oe.id,
- params: g
- },
- ...C.redos
- ]
- }), !0) : !1;
- }
- }, Lo = {
- type: v.COMMAND,
- id: "sheet.command.set-row-is-auto-height",
- handler: (n, e) => {
- var C, S;
- const t = n.get(E), o = n.get(W), s = n.get(F), r = n.get(M), i = N(r, e);
- if (!i) return !1;
- const { unitId: a, subUnitId: u, worksheet: l } = i, c = (C = e == null ? void 0 : e.ranges) != null && C.length ? e.ranges : (S = s.getCurrentSelections()) == null ? void 0 : S.map((I) => I.range);
- if (!(c != null && c.length))
- return !1;
- const d = {
- unitId: a,
- subUnitId: u,
- ranges: c,
- autoHeightInfo: te.TRUE
- // Hard code first, maybe it will change by the menu item in the future.
- }, h = xo(d, l), m = t.syncExecuteCommand(
- Oe.id,
- d
- ), { undos: g, redos: f } = n.get(V).onCommandExecute({
- id: Lo.id,
- params: d
- }), p = z([...f], t);
- return m && p.result ? (o.pushUndoRedo({
- unitID: a,
- undoMutations: [{ id: Oe.id, params: h }, ...g],
- redoMutations: [{ id: Oe.id, params: d }, ...f]
- }), !0) : !1;
- }
- }, Fr = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-show",
- handler: (n, e) => {
- const { unitId: t, subUnitId: o } = e, s = n.get(E), r = n.get(W), i = n.get(M);
- if (!N(n.get(M))) return !1;
- const u = i.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!u) return !1;
- const l = u.getSheetBySheetId(o);
- if (!l || l.getConfig().hidden === te.FALSE) return !1;
- const d = {
- unitId: t,
- subUnitId: o,
- hidden: te.FALSE
- }, h = $r(n, d), m = s.syncExecuteCommand(lt.id, d), g = {
- unitId: t,
- subUnitId: o
- }, f = s.syncExecuteCommand(
- an.id,
- g
- );
- return m && f ? (r.pushUndoRedo({
- unitID: t,
- undoMutations: [
- { id: lt.id, params: h }
- // { id: SetWorksheetActiveOperation.id, params: unActiveMutationParams },
- ],
- redoMutations: [
- // { id: SetWorksheetActiveOperation.id, params: activeSheetMutationParams },
- { id: lt.id, params: d }
- ]
- }), !0) : !1;
- }
- };
- class _l {
- constructor() {
- R(this, "_tabCount", 0);
- R(this, "_commaCount", 0);
- R(this, "_semicolonCount", 0);
- R(this, "_spaceCount", 0);
- }
- add(e) {
- switch (e) {
- case " ":
- this._tabCount++;
- break;
- case ",":
- this._commaCount++;
- break;
- case ";":
- this._semicolonCount++;
- break;
- case " ":
- this._spaceCount++;
- break;
- }
- }
- update(e) {
- e && typeof e == "string" && (e.includes(" ") && this._tabCount++, e.includes(",") && this._commaCount++, e.includes(";") && this._semicolonCount++, e.trim().includes(" ") && this._spaceCount++);
- }
- getDelimiter() {
- const e = Math.max(this._tabCount, this._commaCount, this._semicolonCount, this._spaceCount);
- return e === 0 || e === this._tabCount ? 1 : e === this._commaCount ? 2 : e === this._semicolonCount ? 4 : e === this._spaceCount ? 8 : 1;
- }
- }
- function bl(n, e, t) {
- const o = [];
- t !== void 0 && (n & 16) > 0 && o.push(t), (n & 1) > 0 && o.push(" "), (n & 2) > 0 && o.push(","), (n & 4) > 0 && o.push(";"), (n & 8) > 0 && o.push(" ");
- let s = "";
- for (const i of o)
- s += yl(i);
- let r = "[".concat(s, "]");
- return e && (r += "+"), new RegExp(r);
- }
- function yl(n) {
- return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
- }
- const El = (n) => {
- var t;
- return ((t = n.body) == null ? void 0 : t.dataStream.replace(/\r\n$/, "")) || "";
- };
- function Ul(n) {
- if (n != null) {
- if (n.p)
- return El(n.p);
- if (n.v && typeof n.v == "string")
- return n.v;
- if (n.t && (n.t === se.FORCE_STRING || n.t === se.STRING))
- return String(n.v);
- }
- }
- function Pl(n, e, t, o, s = !1) {
- const r = K.transformRange(e, n), { startColumn: i, startRow: a, endColumn: u, endRow: l } = r;
- if (i !== u)
- throw new Error("The range must be in the same column.");
- if (t && (t & 16) > 0 && (o === void 0 || o.length !== 1))
- throw new Error("The custom delimiter must a character.");
- const c = t === void 0, d = c ? new _l() : null, h = [];
- for (let I = a; I <= l; I++) {
- const w = n.getCell(I, i), b = Ul(w);
- h.push(b), d && d.update(b);
- }
- const m = c ? d.getDelimiter() : t, g = bl(m, s, o);
- let f = -1, p = 0, C = 0;
- const S = [];
- for (const I of h) {
- if (I !== void 0) {
- const w = String(I).split(g);
- f < 0 ? f = w.length : f = Math.max(f, w.length), S.push(w), p = C;
- } else
- S.push(void 0);
- C++;
- }
- return {
- rs: S,
- maxLength: f === -1 ? 0 : f,
- lastRow: p
- };
- }
- const Tl = {
- type: v.COMMAND,
- id: "sheet.command.split-text-to-columns",
- // eslint-disable-next-line max-lines-per-function
- handler: (n, e) => {
- const { unitId: t, subUnitId: o, range: s, delimiter: r, customDelimiter: i, treatMultipleDelimitersAsOne: a } = e, u = n.get(E), l = n.get(M), c = n.get(W);
- if (!N(n.get(M))) return !1;
- const h = l.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!h) return !1;
- const m = h.getSheetBySheetId(o);
- if (!m) return !1;
- const { lastRow: g, rs: f, maxLength: p } = Pl(m, s, r, i, a), C = m.getColumnCount(), { startColumn: S } = K.transformRange(s, m);
- if (s.startColumn !== s.endColumn)
- return !1;
- const I = [], w = [], b = S + p + 1 - C;
- if (b > 0) {
- const A = {
- unitId: t,
- subUnitId: o,
- range: {
- startRow: 0,
- endRow: m.getRowCount() - 1,
- startColumn: C - 1,
- endColumn: C - 1 + b
- }
- };
- I.push({
- id: je.id,
- params: A
- });
- const j = yo(
- n,
- A
- );
- w.push({ id: De.id, params: j });
- }
- const y = {
- startRow: s.startRow,
- endRow: g,
- startColumn: S,
- endColumn: S + p
- }, x = new G();
- for (let A = y.startRow; A <= y.endRow; A++)
- for (let j = y.startColumn; j <= y.endColumn; j++) {
- const Z = f[A - y.startRow];
- j === 0 && (Z == null ? void 0 : Z.length) === 1 ? x.setValue(A, j, m.getCell(A, j)) : x.setValue(A, j, {
- v: (Z == null ? void 0 : Z[j - y.startColumn]) || null,
- p: null,
- f: null,
- si: null,
- custom: null
- });
- }
- const T = {
- unitId: t,
- subUnitId: o,
- cellValue: x.clone()
- }, U = Ae(n, T);
- return I.push({
- id: Q.id,
- params: T
- }), w.unshift({
- id: Q.id,
- params: U
- }), z(I, u).result ? (c.pushUndoRedo({
- unitID: t,
- undoMutations: w,
- redoMutations: I
- }), !0) : !1;
- }
- }, kl = {
- id: "sheet.command.toggle-cell-checkbox",
- type: v.COMMAND,
- handler: (n, e) => {
- if (!e)
- return !1;
- 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);
- if (!l)
- return !1;
- const h = l.getCell(s, r);
- if (!(h != null && h.p))
- return !1;
- const m = O.deepClone(h.p), g = new Ri(m), f = pi.paragraph.bullet.toggleChecklist({
- document: g,
- paragraphIndex: i
- });
- if (!f)
- return !1;
- Ci.apply(g.getBody(), f.serialize());
- const p = {
- unitId: t,
- subUnitId: o,
- cellValue: {
- [s]: {
- [r]: {
- p: m,
- t: se.STRING
- }
- }
- }
- }, C = {
- id: Q.id,
- params: p
- }, S = Ae(n, p), I = {
- id: Q.id,
- params: S
- }, w = [C], b = [I];
- return c.pushUndoRedo({
- redoMutations: w,
- undoMutations: b,
- unitID: t
- }), d.syncExecuteCommand(C.id, C.params);
- }
- }, Ft = {
- id: "sheet.mutation.toggle-gridlines",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = N(n.get(M), e);
- if (!t) return !1;
- const { worksheet: o } = t, s = o.getConfig();
- return s.showGridlines = e.showGridlines, !0;
- }
- }, Nl = {
- type: v.COMMAND,
- id: "sheet.command.toggle-gridlines",
- handler: (n, e) => {
- const t = n.get(E), o = n.get(W), s = n.get(M), r = N(s);
- if (!r) return !1;
- const { worksheet: i } = r, a = i.getConfig().showGridlines;
- if (a === (e == null ? void 0 : e.showGridlines)) return !1;
- const { unitId: u, subUnitId: l } = r, c = {
- showGridlines: a === te.TRUE ? te.FALSE : te.TRUE,
- unitId: u,
- subUnitId: l
- }, d = {
- showGridlines: a,
- unitId: u,
- subUnitId: l
- };
- return t.syncExecuteCommand(Ft.id, c) ? (o.pushUndoRedo({
- unitID: u,
- undoMutations: [{ id: Ft.id, params: d }],
- redoMutations: [{ id: Ft.id, params: c }]
- }), !0) : !1;
- }
- }, Ol = {
- id: "sheet.command.unregister-worksheet-range-theme-style",
- type: v.COMMAND,
- handler: (n, e) => {
- var h;
- if (!e)
- return !1;
- const { unitId: t, themeName: o } = e, s = n.get(M), r = n.get(E), i = n.get(W), a = n.get(He);
- if (!N(s)) return !1;
- const l = {
- unitId: t,
- themeName: o
- }, c = {
- unitId: t,
- themeName: o,
- rangeThemeStyleJson: (h = a.getRangeThemeStyle(t, o)) == null ? void 0 : h.toJson()
- };
- return r.syncExecuteCommand(Yt.id, e) && i.pushUndoRedo({
- unitID: t,
- undoMutations: [{ id: Yt.id, params: c }],
- redoMutations: [{ id: Uo.id, params: l }]
- }), !0;
- }
- }, Dl = {
- id: "sheet.mutation.empty",
- type: v.MUTATION,
- handler: () => !0
- }, Al = (n) => {
- const e = new G();
- return n.forEach((t) => {
- K.foreach(t, (o, s) => {
- e.setValue(o, s, 1);
- });
- }), e.forValue((t, o) => {
- const s = e.getValue(t - 1, o);
- s && e.setValue(t, o, s + 1);
- }), e;
- }, xl = (n) => {
- const e = n;
- return e.forValue((t, o) => {
- const s = n.getValue(t - 1, o);
- s && e.setValue(t, o, s + 1);
- }), e;
- }, Qo = (n) => {
- const e = {
- area: 0
- }, t = (o, s) => e.area < o ? (e.area = o, e.range = s, !0) : !1;
- return n.forValue((o, s, r) => {
- let i = 1, a = r;
- t(i * a, {
- startRow: o - a + 1,
- endRow: o,
- startColumn: s,
- endColumn: s
- });
- const u = {
- startRow: o - a + 1,
- endRow: o,
- startColumn: 0,
- endColumn: s
- };
- for (let l = s - 1; l >= 0 && n.getValue(o, l); l--) {
- a = Math.min(n.getValue(o, l) || 0, a), i++;
- const c = a * i;
- u.startColumn = l, u.startRow = o - a + 1, t(c, u);
- }
- }), e;
- }, $l = (n, e) => {
- K.foreach(e, (t, o) => {
- n.realDeleteValue(t, o);
- });
- for (let t = e.startColumn; t <= e.endColumn; t++) {
- const o = e.endRow + 1;
- if (n.getValue(o, t) > 0) {
- n.setValue(o, t, 1);
- let r = o + 1;
- for (; n.getValue(r, t) > 0; )
- n.setValue(r, t, n.getValue(r - 1, t) + 1), r++;
- }
- }
- return n;
- }, jr = (n) => {
- const e = [];
- let t = Qo(n);
- for (; t.area > 0; )
- t.range && (e.push(t.range), $l(n, t.range)), t = Qo(n);
- return e;
- }, Gr = (n) => {
- const e = Al(n);
- return jr(e);
- };
- class ah {
- constructor() {
- R(this, "_matrix", new G());
- }
- add(...e) {
- return e.forEach((t) => {
- K.foreach(t, (o, s) => {
- this._matrix.setValue(o, s, 1);
- });
- }), this;
- }
- subtract(...e) {
- return e.forEach((t) => {
- K.foreach(t, (o, s) => {
- this._matrix.realDeleteValue(o, s);
- });
- }), this;
- }
- merge() {
- const e = xl(this._matrix);
- return jr(e);
- }
- }
- const wt = fo("INumfmtService"), uh = (n, e) => {
- const t = n.get(wt), { values: o, unitId: s, subUnitId: r } = e, i = [], a = [];
- Object.keys(o).forEach((l) => {
- o[l].ranges.forEach((d) => {
- K.foreach(d, (h, m) => {
- const g = t.getValue(s, r, h, m);
- g ? i.push({
- pattern: g.pattern,
- row: h,
- col: m
- }) : a.push({ startColumn: m, endColumn: m, startRow: h, endRow: h });
- });
- });
- });
- const u = [];
- if (i.length) {
- const l = lo(s, r, i);
- Object.keys(l.values).forEach((c) => {
- const d = l.values[c];
- d.ranges = Gr(d.ranges);
- }), u.push({
- id: Vo.id,
- params: lo(s, r, i)
- });
- }
- return a.length && u.push({
- id: zr.id,
- params: {
- unitId: s,
- subUnitId: r,
- ranges: a
- }
- }), u;
- }, Vo = {
- id: "sheet.mutation.set.numfmt",
- type: v.MUTATION,
- handler: (n, e) => {
- if (!e)
- return !1;
- const { values: t, refMap: o } = e, s = n.get(wt), r = e.unitId, i = e.subUnitId, a = Object.keys(t).reduce(
- (u, l) => {
- const c = o[l], d = t[l].ranges;
- return c && u.push({
- ...c,
- ranges: d
- }), u;
- },
- []
- );
- return s.setValues(r, i, a), !0;
- }
- }, zr = {
- id: "sheet.mutation.remove.numfmt",
- type: v.MUTATION,
- handler: (n, e) => {
- if (!e)
- return !1;
- const { unitId: t, subUnitId: o, ranges: s } = e;
- return n.get(wt).deleteValues(t, o, s), !0;
- }
- }, lh = (n, e) => {
- const t = n.get(wt), { ranges: o, unitId: s, subUnitId: r } = e, i = [];
- if (o.forEach((u) => {
- K.foreach(u, (l, c) => {
- const d = t.getValue(s, r, l, c);
- d && i.push({
- pattern: d.pattern,
- row: l,
- col: c
- });
- });
- }), !i.length)
- return [];
- const a = lo(s, r, i);
- return Object.keys(a.values).forEach((u) => {
- const l = a.values[u];
- l.ranges = Gr(l.ranges);
- }), [{ id: Vo.id, params: a }];
- }, lo = (n, e, t) => {
- const o = ya(t, "pattern"), s = {}, r = {}, i = Ea();
- return Object.keys(o).forEach((a) => {
- const u = o[a], l = i();
- s[l] = {
- pattern: a
- }, u.forEach((c) => {
- r[l] || (r[l] = { ranges: [] }), r[l].ranges.push(ws(c.row, c.col));
- });
- }), { unitId: n, subUnitId: e, refMap: s, values: r };
- }, Wl = {
- id: "sheet.operation.scroll-to-cell",
- type: v.OPERATION,
- handler: () => !0
- }, Kr = "ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY", Ll = "maxCellsPerSheet", Vl = 3e6;
- var Hl = Object.defineProperty, Bl = Object.getOwnPropertyDescriptor, Fl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Bl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Hl(e, t, s), s;
- }, to = (n, e) => (t, o) => e(t, o, n);
- let yn = class extends ae {
- // eslint-disable-next-line max-lines-per-function
- constructor(n, e, t) {
- var s;
- super(), this._commandService = n, this._configService = e, this._dataSyncPrimaryController = t, [
- Q,
- je,
- qe,
- Jt,
- dt,
- ot,
- st,
- De,
- Be,
- Ut,
- oe,
- zr,
- ne,
- Or,
- _n,
- Vo,
- In,
- Dl,
- Qt,
- // formula SUBTOTAL
- Zt,
- Xt,
- qt
- ].forEach((r) => {
- var i;
- this._commandService.registerCommand(r), (i = this._dataSyncPrimaryController) == null || i.registerSyncingMutations(r);
- }), ((s = this._configService.getConfig(Kr)) != null ? s : !1) || [
- po,
- Co,
- So,
- xs,
- Pt,
- Tt,
- Oo,
- $o,
- gu,
- mu,
- pr,
- gt,
- sn,
- Bn,
- hu,
- du,
- fr,
- mt,
- fu,
- jn,
- pt,
- Fn,
- vr,
- zn,
- Mr,
- Gn,
- ko,
- uo,
- Iu,
- tl,
- Qu,
- el,
- Ou,
- Nu,
- rn,
- Tu,
- ku,
- yr,
- Mn,
- $u,
- Lt,
- Bu,
- ut,
- Fu,
- ol,
- on,
- Wo,
- kr,
- Ku,
- Ht,
- br,
- Tr,
- Kn,
- Jn,
- fe,
- al,
- fn,
- Zu,
- rl,
- sl,
- nl,
- Dr,
- Ar,
- an,
- hl,
- lt,
- Do,
- Wr,
- Rn,
- Br,
- nt,
- Lo,
- Oe,
- tt,
- // SetWorksheetColIsAutoWidthCommand,
- re,
- Wl,
- au,
- Ir,
- Ur,
- Fr,
- Nl,
- Ft,
- ju,
- Vt,
- // permissions range protection
- Il,
- ct,
- Ct,
- St,
- Ao,
- Xi,
- Gu,
- su,
- qi,
- ru,
- vl,
- Ne,
- ze,
- he,
- kl,
- Bt,
- dl,
- Tl,
- // range theme
- Kt,
- zt,
- Uo,
- Yt,
- Ol,
- wu,
- ba,
- iu
- ].forEach((r) => this.disposeWithMe(this._commandService.registerCommand(r))), this._configService.setConfig(Ll, Vl);
- }
- };
- yn = Fl([
- to(0, E),
- to(1, Us),
- to(2, Si(Fi))
- ], yn);
- var jl = Object.defineProperty, Gl = Object.getOwnPropertyDescriptor, zl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Gl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && jl(e, t, s), s;
- }, es = (n, e) => (t, o) => e(t, o, n);
- let En = class extends ae {
- constructor(n, e) {
- super(), this._univerInstanceService = n, this._commandService = e, this._initialize();
- }
- _initialize() {
- this.disposeWithMe(
- this._commandService.onCommandExecuted((n) => {
- if (n.id !== Di.id)
- return;
- const e = n.params, { unitData: t } = e, o = Object.keys(t), s = [];
- for (let i = 0; i < o.length; i++) {
- const a = o[i], u = t[a];
- if (u == null)
- continue;
- const l = Object.keys(u);
- for (let c = 0; c < l.length; c++) {
- const d = l[c], h = u[d];
- if (h == null)
- continue;
- const m = this._getMergedCellData(a, d, h), g = {
- subUnitId: d,
- unitId: a,
- cellValue: m
- };
- s.push({
- id: Q.id,
- params: g
- });
- }
- }
- return s.every(
- (i) => this._commandService.executeCommand(i.id, i.params, {
- onlyLocal: !0
- })
- );
- })
- );
- }
- /**
- * Priority that mainly deals with number format in unitData
- * @param unitId
- * @param sheetId
- * @param cellData
- * @returns
- */
- _getMergedCellData(n, e, t) {
- const o = this._univerInstanceService.getUniverSheetInstance(n), s = o == null ? void 0 : o.getStyles(), r = o == null ? void 0 : o.getSheetBySheetId(e), i = r == null ? void 0 : r.getCellMatrix(), a = new G(t);
- return a.forValue((u, l, c) => {
- const d = i == null ? void 0 : i.getValue(u, l), h = Ai(d, c, s);
- a.setValue(u, l, h);
- }), a.getMatrix();
- }
- };
- En = zl([
- es(0, L(M)),
- es(1, E)
- ], En);
- const Kl = "sheets.config", ts = {};
- var Jl = Object.defineProperty, Yl = Object.getOwnPropertyDescriptor, Xl = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Yl(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Jl(e, t, s), s;
- }, ns = (n, e) => (t, o) => e(t, o, n);
- const ql = "SHEET_DEFINED_NAME_PLUGIN", ch = "AllDefaultWorkbook";
- let Un = class extends ae {
- constructor(n, e) {
- super(), this._definedNamesService = n, this._resourceManagerService = e, this._initialize();
- }
- _initialize() {
- this._initSnapshot();
- }
- _initSnapshot() {
- const n = (t) => {
- const o = this._definedNamesService.getDefinedNameMap(t);
- return o ? JSON.stringify(o) : "";
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- pluginName: ql,
- businesses: [B.UNIVER_SHEET],
- toJson: (t) => n(t),
- parseJson: (t) => e(t),
- onUnLoad: (t) => {
- this._definedNamesService.removeUnitDefinedName(t);
- },
- onLoad: (t, o) => {
- this._definedNamesService.registerDefinedNames(t, o);
- }
- })
- );
- }
- };
- Un = Xl([
- ns(0, Ps),
- ns(1, nn)
- ], Un);
- const $ = {
- MoveRangeCommandId: $s,
- InsertRowCommandId: gr,
- InsertColCommandId: Rr,
- RemoveColCommandId: To,
- RemoveRowCommandId: Po,
- DeleteRangeMoveLeftCommandId: dr,
- DeleteRangeMoveUpCommandId: hr,
- InsertRangeMoveDownCommandId: cu,
- InsertRangeMoveRightCommandId: Eo,
- MoveColsCommandId: Sr,
- MoveRowsCommandId: Cr,
- ReorderRangeCommandId: _r
- };
- var q = /* @__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 || {});
- const cn = Number.MAX_SAFE_INTEGER, Ve = (n) => {
- const e = { ...n }, t = Number.isNaN(e.startRow) && Number.isNaN(e.endRow) && !Number.isNaN(e.startColumn) && !Number.isNaN(e.endColumn), o = Number.isNaN(e.startColumn) && Number.isNaN(e.endColumn) && !Number.isNaN(e.startRow) && !Number.isNaN(e.endRow);
- return (e.rangeType === 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;
- }, _e = (n) => {
- let e = n.rangeType;
- return n.rangeType === H.COLUMN ? e = H.ROW : n.rangeType === H.ROW && (e = H.COLUMN), {
- startRow: n.startColumn,
- endRow: n.endColumn,
- startColumn: n.startRow,
- endColumn: n.endRow,
- rangeType: e
- };
- }, Pn = (n, e, t) => {
- const o = { ...t }, s = { ...e }, r = (f, p) => {
- const C = Math.max(f.start, p.start), S = Math.min(f.end, p.end);
- return S < C ? null : { start: C, end: S };
- }, i = (f) => f.end - f.start + 1, a = (f, p) => ({
- start: f.start - p.start,
- end: f.start - p.start + f.end - f.start
- }), u = (f, p) => ({
- start: p.start + f.start,
- end: p.start + f.start + f.end - f.start
- }), l = e.start > n.start;
- if (l) {
- const f = Math.min(n.end, e.start) - n.start + 1;
- s.start -= f, s.end -= f;
- }
- const c = i(n), d = c, h = r(n, o), m = h && i(h) >= i(o);
- if (n.end < o.start)
- o.start -= c, o.end -= c;
- else if (h) {
- const f = i(h);
- if (m) {
- const p = a(o, n), C = u(p, s);
- o.start = C.start, o.end = C.end;
- } else h.start > n.start ? l ? (o.end -= f + c, o.start -= c) : o.end -= f : l ? o.end -= f : o.start > n.start && o.end > n.end ? (o.start -= c, o.end -= c + f) : o.end -= f;
- }
- const g = r(s, o);
- 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))), {
- step: o.start - t.start,
- length: i(o) - i(t)
- };
- }, Jr = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!o || !t)
- return [];
- const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn(
- { start: s.startRow, end: s.endRow },
- { start: r.startRow, end: r.endRow },
- { start: i.startRow, end: i.endRow }
- );
- return a === null ? [
- {
- type: q.Delete
- }
- ] : [
- {
- type: q.VerticalMove,
- step: a.step || 0,
- length: a.length || 0
- }
- ];
- }, Zl = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!t || !o)
- return [e];
- const s = t.startRow, r = t.endRow - t.startRow + 1, i = o.startRow, a = new G();
- return K.foreach(e, (l, c) => {
- a.setValue(l, c, 1);
- }), a.moveRows(s, r, i), Je(a, (l) => l === 1);
- }, Ql = (n, e) => {
- const { range: t, order: o } = n.params || {};
- if (!t || !o)
- return [e];
- const s = new G();
- K.foreach(e, (a, u) => {
- s.setValue(a, u, 1);
- });
- const r = new G();
- return K.foreach(t, (a, u) => {
- var l;
- if (o.hasOwnProperty(a)) {
- const c = o[a], d = (l = s.getValue(c, u)) != null ? l : 0;
- r.setValue(a, u, d);
- }
- }), r.forValue((a, u, l) => {
- s.setValue(a, u, l);
- }), Je(s, (a) => a === 1);
- }, Yr = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!o || !t)
- return [];
- const s = Ve(t), r = Ve(o), i = Ve(e), a = Pn(
- { start: s.startColumn, end: s.endColumn },
- { start: r.startColumn, end: r.endColumn },
- { start: i.startColumn, end: i.endColumn }
- );
- return a === null ? [
- {
- type: q.Delete
- }
- ] : [
- {
- type: q.HorizontalMove,
- step: a.step || 0,
- length: a.length || 0
- }
- ];
- }, ec = (n, e) => {
- const { fromRange: t, toRange: o } = n.params || {};
- if (!t || !o)
- return [e];
- const s = t.startColumn, r = t.endColumn - t.startColumn + 1, i = o.startColumn, a = new G();
- return K.foreach(e, (u, l) => {
- a.setValue(u, l, 1);
- }), a.moveColumns(s, r, i), Je(a, (u) => u === 1);
- }, tc = (n, e) => {
- var r, i;
- const t = (r = n.params) == null ? void 0 : r.toRange, o = (i = n.params) == null ? void 0 : i.fromRange;
- if (!t || !o)
- return [];
- const s = [];
- if (k.contains(t, e) && s.push({
- type: q.Delete
- }), k.contains(o, e)) {
- s.push({
- type: q.Delete
- });
- const a = k.getRelativeRange(e, o), u = k.getPositionRange(a, t);
- return [
- {
- type: q.Set,
- range: u
- }
- ];
- }
- return s;
- }, nc = (n, e) => {
- var d, h;
- const t = (d = n.params) == null ? void 0 : d.toRange, o = (h = n.params) == null ? void 0 : h.fromRange;
- if (!t || !o)
- return [e];
- if (!k.intersects(o, e) && !k.intersects(t, e))
- return [e];
- if (k.contains(o, e)) {
- const m = k.getRelativeRange(e, o);
- return [k.getPositionRange(m, t)];
- }
- const s = new G();
- K.foreach(e, (m, g) => {
- s.setValue(m, g, 1);
- });
- const r = new G(), i = k.getIntersects(o, e);
- i && K.foreach(i, (m, g) => {
- s.getValue(m, g) && (s.setValue(m, g, void 0), r.setValue(m, g, 1));
- });
- const a = t.startColumn - o.startColumn, u = t.startRow - o.startRow, l = {
- startColumn: t.startColumn - a,
- endColumn: t.endColumn - a,
- startRow: t.startRow - u,
- endRow: t.endRow - u
- };
- return K.foreach(l, (m, g) => {
- var C;
- const f = m + u, p = g + a;
- s.setValue(f, p, (C = r.getValue(m, g)) != null ? C : 0);
- }), Je(s, (m) => m === 1);
- }, It = (n, e) => {
- const t = Ve(n), o = Ve(e), s = (i) => i.endColumn - i.startColumn + 1, r = (i) => i.endRow - i.startRow + 1;
- if (t.startRow <= o.startRow && t.endRow >= o.endRow) {
- if (
- // 2
- o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6
- o.startColumn < t.startColumn && o.endColumn >= t.endColumn
- ) {
- const i = k.getIntersects(o, t);
- if (i)
- return { step: 0, length: -s(i) };
- }
- if (o.startColumn >= t.startColumn && o.endColumn <= t.endColumn && r(t) >= r(o))
- return null;
- if (o.startColumn >= t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn) {
- const i = k.getIntersects(o, t);
- if (i) {
- const a = -s(i);
- return { step: -(s(t) - s(i)), length: a };
- }
- }
- if (o.startColumn > t.endColumn)
- return { step: -s(t), length: 0 };
- }
- return { step: 0, length: 0 };
- }, Xr = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(t, e);
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.HorizontalMove,
- step: i,
- length: a
- });
- }
- return o;
- }, oc = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(_e(t), _e(e));
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.VerticalMove,
- step: i,
- length: a
- });
- }
- return o;
- }, sc = (n, e) => {
- const { range: t, order: o } = n.params || {};
- if (!t || !o)
- return [];
- if (k.contains(t, e) && e.endRow === e.startRow) {
- const s = [], r = e.startRow;
- for (const i in o)
- if (o[i] === r) {
- const a = Number(i);
- return s.push({
- type: q.VerticalMove,
- step: a - r,
- length: 0
- }), s;
- }
- return [];
- }
- return [];
- }, vt = (n, e) => {
- const t = Ve(n), o = Ve(e), s = (r) => r.endColumn - r.startColumn + 1;
- if (t.startRow <= o.startRow && t.endRow >= o.endRow) {
- if (
- // 2
- o.startColumn < t.startColumn && o.endColumn >= t.startColumn && o.endColumn <= t.endColumn || // 6
- o.startColumn < t.startColumn && o.endColumn >= t.endColumn
- )
- return { step: 0, length: s(t) };
- if (
- // 3
- o.startColumn >= t.startColumn && o.endColumn <= t.endColumn || // 4
- o.startColumn > t.startColumn && o.startColumn <= t.endColumn && o.endColumn > t.endColumn || //5
- o.startColumn >= t.endColumn
- )
- return { step: s(t), length: 0 };
- }
- return { step: 0, length: 0 };
- };
- function rc(n, e, t) {
- const o = [];
- if (k.contains(e, t) && o.push({
- type: q.Delete
- }), k.contains(n, t)) {
- o.push({
- type: q.Delete
- });
- const s = k.getRelativeRange(t, n), r = k.getPositionRange(s, e);
- return [
- {
- type: q.Set,
- range: r
- }
- ];
- }
- return o;
- }
- const ic = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s;
- return o.push({
- type: q.VerticalMove,
- step: r,
- length: i
- }), o;
- }, ac = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(t, e), { step: r, length: i } = s;
- return o.push({
- type: q.HorizontalMove,
- step: r,
- length: i
- }), o;
- }, uc = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(_e(t), _e(e)), { step: r, length: i } = s;
- return o.push({
- type: q.VerticalMove,
- step: r,
- length: i
- }), o;
- }, lc = (n, e) => {
- var u;
- const t = (u = n.params) == null ? void 0 : u.range;
- if (!t)
- return [e];
- const o = t.endRow - t.startRow + 1, s = {
- ...t,
- startRow: t.startRow,
- endRow: Number.POSITIVE_INFINITY
- }, r = k.subtract(e, s), i = k.getIntersects(s, e);
- if (!i)
- return [e];
- const a = new G();
- return r.forEach((l) => {
- K.foreach(l, (c, d) => {
- a.setValue(c, d, 1);
- });
- }), i && K.foreach(i, (l, c) => {
- a.setValue(l + o, c, 1);
- }), Je(a, (l) => l === 1);
- }, cc = (n, e) => {
- var a;
- const t = (a = n.params) == null ? void 0 : a.range;
- if (!t)
- return [];
- const o = [], s = vt(t, e), { step: r, length: i } = s;
- return o.push({
- type: q.HorizontalMove,
- step: r,
- length: i
- }), o;
- }, dc = (n, e) => {
- var u;
- const t = (u = n.params) == null ? void 0 : u.range;
- if (!t)
- return [e];
- const o = t.endColumn - t.startColumn + 1, s = {
- ...t,
- startColumn: t.startColumn,
- endColumn: Number.POSITIVE_INFINITY
- }, r = k.subtract(e, s), i = k.getIntersects(s, e);
- if (!i)
- return [e];
- const a = new G();
- return r.forEach((l) => {
- K.foreach(l, (c, d) => {
- a.setValue(c, d, 1);
- });
- }), i && K.foreach(i, (l, c) => {
- a.setValue(l, c + o, 1);
- }), Je(a, (l) => l === 1);
- }, hc = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(t, e);
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.HorizontalMove,
- step: i,
- length: a
- });
- }
- return o;
- }, mc = (n, e) => {
- var l;
- const t = (l = n.params) == null ? void 0 : l.range;
- if (!t)
- return [e];
- const o = {
- startRow: t.startRow,
- endRow: t.endRow,
- startColumn: t.startColumn,
- endColumn: Number.POSITIVE_INFINITY
- }, s = t.endColumn - t.startColumn + 1, r = k.getIntersects(t, e), i = k.subtract(e, o), a = k.getIntersects(o, e);
- if (!r && !a)
- return [e];
- const u = new G();
- return a && K.foreach(a, (c, d) => {
- u.setValue(c, d - s, 1);
- }), r && K.foreach(r, (c, d) => {
- u.setValue(c, d - s, 0);
- }), i.forEach((c) => {
- K.foreach(c, (d, h) => {
- u.setValue(d, h, 1);
- });
- }), Je(u, (c) => c === 1);
- }, gc = (n, e) => {
- var r;
- const t = (r = n.params) == null ? void 0 : r.range;
- if (!t)
- return [];
- const o = [], s = It(_e(t), _e(e));
- if (!s)
- o.push({ type: q.Delete });
- else {
- const { step: i, length: a } = s;
- o.push({
- type: q.VerticalMove,
- step: i,
- length: a
- });
- }
- return o;
- }, fc = (n, e) => {
- var l;
- const t = (l = n.params) == null ? void 0 : l.range;
- if (!t)
- return [e];
- const o = {
- ...t,
- startRow: t.startRow,
- endRow: Number.POSITIVE_INFINITY
- }, s = t.endRow - t.startRow + 1, r = k.getIntersects(t, e), i = k.subtract(e, o), a = k.getIntersects(o, e);
- if (!r && !a)
- return [e];
- const u = new G();
- return a && K.foreach(a, (c, d) => {
- u.setValue(c - s, d, 1);
- }), r && K.foreach(r, (c, d) => {
- u.setValue(c - s, d, 0);
- }), i.forEach((c) => {
- K.foreach(c, (d, h) => {
- u.setValue(d, h, 1);
- });
- }), Je(u, (c) => c === 1);
- }, Rc = (n, e) => {
- var s;
- const t = (s = n.ranges) != null ? s : [n.range], o = new G();
- return K.foreach(e, (r, i) => {
- o.setValue(r, i, 1);
- }), t.forEach((r) => {
- const i = r.startRow, u = r.endRow - i + 1;
- o.removeRows(i, u);
- }), Je(o, (r) => r === 1);
- }, pc = (n, e) => {
- const t = n.params, o = t.range.startRow, s = t.range.endRow - t.range.startRow + 1, r = t.direction;
- return r === pe.UP && o === e.startRow || r === pe.DOWN && o - 1 === e.endRow ? [
- {
- startRow: e.startRow,
- endRow: e.endRow + s,
- startColumn: e.startColumn,
- endColumn: e.endColumn
- }
- ] : e.startRow >= o ? [{
- startRow: e.startRow + s,
- endRow: e.endRow + s,
- startColumn: e.startColumn,
- endColumn: e.endColumn
- }] : e.endRow <= o ? [e] : [{
- startRow: e.startRow,
- endRow: e.endRow + s,
- startColumn: e.startColumn,
- endColumn: e.endColumn
- }];
- }, Cc = (n, e) => {
- const t = n.params, o = t.range.startColumn, s = t.range.endColumn - t.range.startColumn + 1, r = t.direction;
- return r === pe.LEFT && o === e.startColumn || r === pe.RIGHT && o - 1 === e.endColumn ? [
- {
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: e.startColumn,
- endColumn: e.endColumn + s
- }
- ] : e.startColumn >= o ? [{
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: e.startColumn + s,
- endColumn: e.endColumn + s
- }] : e.endColumn <= o ? [e] : [{
- startRow: e.startRow,
- endRow: e.endRow,
- startColumn: e.startColumn,
- endColumn: e.endColumn + s
- }];
- }, Mt = (n, e) => {
- let t = { ...e };
- return n.forEach((o) => {
- switch (o.type) {
- case q.Delete: {
- t = null;
- break;
- }
- case q.HorizontalMove: {
- if (!t)
- return;
- t.startColumn += o.step, t.endColumn += o.step + (o.length || 0);
- break;
- }
- case q.VerticalMove: {
- if (!t)
- return;
- t.startRow += o.step, t.endRow += o.step + (o.length || 0);
- break;
- }
- case q.Set: {
- t = o.range;
- break;
- }
- }
- }), t && (t.endColumn < t.startColumn || t.endRow < t.startRow) ? null : t;
- }, os = (n, e) => {
- let t = [];
- switch (e.id) {
- case $.DeleteRangeMoveLeftCommandId: {
- t = hc(e, n);
- break;
- }
- case $.DeleteRangeMoveUpCommandId: {
- t = gc(e, n);
- break;
- }
- case $.InsertColCommandId: {
- t = ac(e, n);
- break;
- }
- case $.InsertRangeMoveDownCommandId: {
- t = uc(e, n);
- break;
- }
- case $.InsertRangeMoveRightCommandId: {
- t = cc(e, n);
- break;
- }
- case $.InsertRowCommandId: {
- t = ic(e, n);
- break;
- }
- case $.MoveColsCommandId: {
- t = Yr(e, n);
- break;
- }
- case $.MoveRangeCommandId: {
- t = tc(e, n);
- break;
- }
- case $.MoveRowsCommandId: {
- t = Jr(e, n);
- break;
- }
- case $.RemoveColCommandId: {
- t = Xr(e, n);
- break;
- }
- case $.RemoveRowCommandId: {
- t = oc(e, n);
- break;
- }
- case $.ReorderRangeCommandId: {
- t = sc(e, n);
- break;
- }
- }
- return Mt(t, n);
- }, 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) => {
- let t = [];
- switch (e.id) {
- case $.DeleteRangeMoveLeftCommandId:
- return mc(e, n);
- case $.DeleteRangeMoveUpCommandId:
- return fc(e, n);
- case $.InsertRangeMoveDownCommandId:
- return lc(e, n);
- case $.InsertRangeMoveRightCommandId:
- return dc(e, n);
- case $.InsertColCommandId:
- return Cc(e, n);
- case $.InsertRowCommandId:
- return pc(e, n);
- case $.MoveColsCommandId:
- return ec(e, n);
- case $.MoveRangeCommandId:
- return nc(e, n);
- case $.MoveRowsCommandId:
- return Zl(e, n);
- case $.ReorderRangeCommandId:
- return Ql(e, n);
- case $.RemoveColCommandId: {
- t = Xr(e, n);
- break;
- }
- case $.RemoveRowCommandId:
- return Rc(e.params, n);
- }
- const o = Mt(t, n);
- return o ? [o] : [];
- }, 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;
- function Sc(n, e) {
- const { id: t, params: o } = e;
- let s = {
- length: 0,
- step: 0,
- type: q.Unknown
- };
- switch (t) {
- case Ut.id:
- s.type = q.Delete;
- break;
- case ot.id:
- s = Pn(
- { start: o.sourceRange.startRow, end: o.sourceRange.endRow },
- { start: o.targetRange.startRow, end: o.targetRange.endRow },
- { start: n.startRow, end: n.endRow }
- ), s.type = q.VerticalMove;
- break;
- case st.id:
- s = Pn(
- { start: o.sourceRange.startColumn, end: o.sourceRange.endColumn },
- { start: o.targetRange.startColumn, end: o.targetRange.endColumn },
- { start: n.startColumn, end: n.endColumn }
- ), s.type = q.HorizontalMove;
- break;
- case De.id:
- s = It(o.range, n), s ? s.type = q.HorizontalMove : s = { step: 0, length: 0, type: q.Delete };
- break;
- case Be.id:
- s = It(_e(o.range), _e(n)), s ? s.type = q.VerticalMove : s = { step: 0, length: 0, type: q.Delete };
- break;
- case qe.id:
- s = vt(_e(o.range), _e(n)), s.type = q.VerticalMove;
- break;
- case je.id:
- s = vt(o.range, n), s.type = q.HorizontalMove;
- break;
- case dt.id:
- {
- const r = o.fromRange || new G(o.from).getRange(), i = o.toRange || new G(o.to).getRange();
- s = rc(
- r,
- i,
- n
- );
- }
- break;
- }
- return s ? Array.isArray(s) ? Mt(s, n) : Mt([s], n) : n;
- }
- function qr(n, e) {
- var o, s, r, i, a, u;
- const { selectionManagerService: t } = e;
- switch (n.id) {
- case $.MoveColsCommandId: {
- const l = n.params;
- return [
- l.fromRange,
- {
- ...l.toRange,
- startColumn: l.toRange.startColumn - 0.5,
- endColumn: l.toRange.endColumn - 0.5
- }
- ];
- }
- case $.MoveRowsCommandId: {
- const l = n.params;
- return [
- l.fromRange,
- {
- ...l.toRange,
- startRow: l.toRange.startRow - 0.5,
- endRow: l.toRange.startRow - 0.5
- }
- ];
- }
- case $.MoveRangeCommandId: {
- const l = n;
- return [l.params.fromRange, l.params.toRange];
- }
- case $.InsertRowCommandId: {
- const c = n.params.range;
- return [
- {
- ...c,
- startRow: c.startRow - 0.5,
- endRow: c.endRow - 0.5
- }
- ];
- }
- case $.InsertColCommandId: {
- const c = n.params.range;
- return [
- {
- ...c,
- startColumn: c.startColumn - 0.5,
- endColumn: c.endColumn - 0.5
- }
- ];
- }
- case $.RemoveRowCommandId:
- return [n.params.range];
- case $.RemoveColCommandId:
- return [n.params.range];
- case $.DeleteRangeMoveUpCommandId:
- case $.InsertRangeMoveDownCommandId: {
- const c = ((o = n.params) == null ? void 0 : o.range) || ((r = (s = t.getCurrentSelections()) == null ? void 0 : s.map((d) => d.range)) == null ? void 0 : r[0]);
- return c ? [c] : [];
- }
- case $.DeleteRangeMoveLeftCommandId:
- case $.InsertRangeMoveRightCommandId: {
- const c = ((i = n.params) == null ? void 0 : i.range) || ((u = (a = t.getCurrentSelections()) == null ? void 0 : a.map((d) => d.range)) == null ? void 0 : u[0]);
- return c ? [c] : [];
- }
- case $.ReorderRangeCommandId: {
- const l = n, { range: c, order: d } = l.params, h = [];
- for (let m = c.startRow; m <= c.endRow; m++)
- m in d && h.push({
- startRow: m,
- endRow: m,
- startColumn: c.startColumn,
- endColumn: c.endColumn
- });
- return h;
- }
- }
- }
- function wc(n) {
- switch (n.id) {
- case st.id: {
- const e = n.params;
- return [
- e.sourceRange,
- {
- ...e.targetRange,
- startColumn: e.targetRange.startColumn - 0.5,
- endColumn: e.targetRange.startColumn - 0.5
- }
- ];
- }
- case ot.id: {
- const e = n.params;
- return [
- e.sourceRange,
- {
- ...e.targetRange,
- startRow: e.targetRange.startRow - 0.5,
- endRow: e.targetRange.startRow - 0.5
- }
- ];
- }
- case dt.id: {
- const e = n.params;
- return [new G(e.from.value).getRange(), new G(e.to.value).getRange()];
- }
- case je.id: {
- const t = n.params.range;
- return [
- {
- ...t,
- startColumn: t.startColumn - 0.5,
- endColumn: t.startColumn - 0.5
- }
- ];
- }
- case qe.id: {
- const t = n.params.range;
- return [
- {
- ...t,
- startRow: t.startRow - 0.5,
- endRow: t.startRow - 0.5
- }
- ];
- }
- case De.id:
- return [n.params.range];
- case Be.id:
- return [n.params.range];
- }
- }
- function mh(n, e) {
- var s, r, i, a, u, l;
- const t = n.get(M), o = n.get(F);
- switch (e.id) {
- case $.MoveColsCommandId: {
- const c = e.params, d = N(t, {
- unitId: c.unitId,
- subUnitId: c.subUnitId
- });
- return {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [
- c.fromRange,
- {
- ...c.toRange,
- startColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.fromRange.endColumn + 1 : c.toRange.startColumn,
- endColumn: c.fromRange.startColumn < c.toRange.startColumn ? c.toRange.endColumn - 1 : c.fromRange.startColumn - 1
- }
- ]
- };
- }
- case $.MoveRowsCommandId: {
- const c = e.params, d = N(t, {
- unitId: c.unitId,
- subUnitId: c.subUnitId
- });
- return {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [
- c.fromRange,
- {
- ...c.toRange,
- startRow: c.fromRange.startRow < c.toRange.startRow ? c.fromRange.endRow + 1 : c.toRange.startRow,
- endRow: c.fromRange.startRow < c.toRange.startRow ? c.toRange.endRow - 1 : c.fromRange.startRow - 1
- }
- ]
- };
- }
- case $.MoveRangeCommandId: {
- const c = e.params, d = N(t);
- return {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [c.fromRange, c.toRange]
- };
- }
- case $.InsertRowCommandId: {
- const c = e.params, d = c.range;
- return {
- unitId: c.unitId,
- subUnitId: c.subUnitId,
- ranges: [
- ...d.startRow > 0 ? [{
- ...d,
- startRow: d.startRow - 1,
- endRow: d.endRow - 1
- }] : [],
- {
- ...d,
- startRow: d.startRow,
- endRow: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.InsertColCommandId: {
- const c = e.params, d = c.range;
- return {
- unitId: c.unitId,
- subUnitId: c.subUnitId,
- ranges: [
- ...d.startColumn > 0 ? [{
- ...d,
- startColumn: d.startColumn - 1,
- endColumn: d.endColumn - 1
- }] : [],
- {
- ...d,
- startColumn: d.startColumn,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.RemoveRowCommandId: {
- const d = e.params.range, h = N(t);
- return {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: [
- d,
- {
- ...d,
- startRow: d.endRow + 1,
- endRow: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.RemoveColCommandId: {
- const d = e.params.range, h = N(t);
- return {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: [
- d,
- {
- ...d,
- startColumn: d.endColumn + 1,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- ]
- };
- }
- case $.DeleteRangeMoveUpCommandId:
- case $.InsertRangeMoveDownCommandId: {
- const c = e, d = N(t), h = ((s = c.params) == null ? void 0 : s.range) || ((i = (r = o.getCurrentSelections()) == null ? void 0 : r.map((m) => m.range)) == null ? void 0 : i[0]);
- return h ? {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: [
- h,
- {
- ...h,
- startRow: h.endRow + 1,
- endRow: Number.MAX_SAFE_INTEGER
- }
- ]
- } : {
- unitId: d.unitId,
- subUnitId: d.subUnitId,
- ranges: []
- };
- }
- case $.DeleteRangeMoveLeftCommandId:
- case $.InsertRangeMoveRightCommandId: {
- const d = ((a = e.params) == null ? void 0 : a.range) || ((l = (u = o.getCurrentSelections()) == null ? void 0 : u.map((m) => m.range)) == null ? void 0 : l[0]), h = N(t);
- return d ? {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: [
- d,
- {
- ...d,
- startColumn: d.endColumn + 1,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- ]
- } : {
- unitId: h.unitId,
- subUnitId: h.subUnitId,
- ranges: []
- };
- }
- case $.ReorderRangeCommandId: {
- const c = e, { range: d, order: h } = c.params, m = [];
- for (let f = d.startRow; f <= d.endRow; f++)
- f in h && m.push({
- startRow: f,
- endRow: f,
- startColumn: d.startColumn,
- endColumn: d.endColumn
- });
- const g = N(t);
- return {
- unitId: g.unitId,
- subUnitId: g.subUnitId,
- ranges: m
- };
- }
- }
- }
- var Ic = Object.defineProperty, vc = Object.getOwnPropertyDescriptor, Mc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? vc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Ic(e, t, s), s;
- }, dn = (n, e) => (t, o) => e(t, o, n);
- const _c = rt("MERGE_REDO"), bc = rt("MERGE_UNDO"), rs = Math.floor(Number.MAX_SAFE_INTEGER / 10);
- class yc extends ae {
- constructor(e, t, o, s, r = !1) {
- super(), this._unitId = e, this._subUnitId = t, this._range = o, this._callback = s, this._skipIntersects = r;
- }
- onMutation(e) {
- var s, r;
- if (((s = e.params) == null ? void 0 : s.unitId) !== this._unitId)
- return;
- if (e.id === dt.id) {
- const i = e.params;
- if (i.from.subUnitId !== this._subUnitId || i.to.subUnitId !== this._subUnitId)
- return;
- } else if (((r = e.params) == null ? void 0 : r.subUnitId) !== this._subUnitId)
- return;
- if (!this._range)
- return;
- if (this._skipIntersects) {
- if (e.id === Ut.id)
- return;
- const i = wc(e);
- if (i != null && i.some((a) => k.intersects(a, this._range)))
- return;
- }
- const t = Sc(this._range, e);
- if (t && k.equals(t, this._range))
- return !1;
- const o = this._range;
- this._range = t, this._callback(o, t);
- }
- }
- let _t = class extends ae {
- constructor(e, t, o, s) {
- super();
- R(this, "interceptor", new mo({ MERGE_REDO: _c, MERGE_UNDO: bc }));
- R(this, "_watchRanges", /* @__PURE__ */ new Set());
- R(this, "_refRangeManagerMap", /* @__PURE__ */ new Map());
- R(this, "_serializer", Ec());
- // eslint-disable-next-line max-lines-per-function
- R(this, "_onRefRangeChange", () => {
- this._sheetInterceptorService.interceptCommand({
- // eslint-disable-next-line max-lines-per-function
- getMutations: (e) => {
- const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET).getActiveSheet(), o = is(this._univerInstanceService), s = as(this._univerInstanceService);
- if (!t || !o || !s)
- return { redos: [], undos: [], preRedos: [], preUndos: [] };
- const a = ((() => {
- switch (e.id) {
- case $.MoveColsCommandId: {
- const h = e.params, m = Math.min(h.fromRange.startColumn, h.toRange.startColumn);
- return this._checkRange(
- [{ ...h.fromRange, startColumn: m, endColumn: t.getColumnCount() - 1 }],
- o,
- s
- );
- }
- case $.MoveRowsCommandId: {
- const h = e.params, m = Math.min(h.fromRange.startRow, h.toRange.startRow);
- return this._checkRange(
- [{ ...h.fromRange, startRow: m, endRow: t.getRowCount() - 1 }],
- o,
- s
- );
- }
- case $.MoveRangeCommandId: {
- const h = e;
- return this._checkRange(
- [h.params.fromRange, h.params.toRange],
- o,
- s
- );
- }
- case $.InsertRowCommandId: {
- const g = {
- startRow: e.params.range.startRow,
- endRow: t.getRowCount() - 1,
- startColumn: 0,
- endColumn: t.getColumnCount() - 1,
- rangeType: H.ROW
- };
- return this._checkRange([g], o, s);
- }
- case $.InsertColCommandId: {
- const m = e.params.range.startColumn, g = {
- startRow: 0,
- endRow: t.getRowCount() - 1,
- startColumn: m,
- endColumn: t.getColumnCount() - 1,
- rangeType: H.COLUMN
- };
- return this._checkRange([g], o, s);
- }
- case $.RemoveRowCommandId: {
- const g = {
- startRow: e.params.range.startRow,
- endRow: t.getRowCount() - 1,
- startColumn: 0,
- endColumn: t.getColumnCount() - 1,
- rangeType: H.ROW
- };
- return this._checkRange([g], o, s);
- }
- case $.RemoveColCommandId: {
- const m = e.params.range.startColumn, g = {
- startRow: 0,
- endRow: t.getRowCount() - 1,
- startColumn: m,
- endColumn: t.getColumnCount() - 1,
- rangeType: H.COLUMN
- };
- return this._checkRange([g], o, s);
- }
- case $.DeleteRangeMoveUpCommandId:
- case $.InsertRangeMoveDownCommandId: {
- const m = e.params.range || us(this._selectionManagerService)[0], g = {
- startRow: m.startRow,
- startColumn: m.startColumn,
- endColumn: m.endColumn,
- endRow: rs
- };
- return this._checkRange([g], o, s);
- }
- case $.DeleteRangeMoveLeftCommandId:
- case $.InsertRangeMoveRightCommandId: {
- const m = e.params.range || us(this._selectionManagerService)[0], g = {
- startRow: m.startRow,
- startColumn: m.startColumn,
- endColumn: rs,
- endRow: m.endRow
- };
- return this._checkRange([g], o, s);
- }
- case $.ReorderRangeCommandId: {
- const h = e, { range: m, order: g } = h.params, f = [];
- for (let p = m.startRow; p <= m.endRow; p++)
- p in g && f.push({
- startRow: p,
- endRow: p,
- startColumn: m.startColumn,
- endColumn: m.endColumn
- });
- return this._checkRange(f, o, s);
- }
- }
- })() || []).reduce(
- (h, m) => {
- const g = m(e);
- return h.push(g), h;
- },
- []
- ).reduce(
- (h, m) => {
- var g, f;
- 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;
- },
- { redos: [], undos: [], preUndos: [], preRedos: [] }
- ), u = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
- a.preRedos,
- null
- ) || [], l = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_REDO)(
- a.redos,
- null
- ) || [], c = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(
- a.preUndos,
- null
- ) || [], d = this.interceptor.fetchThroughInterceptors(this.interceptor.getInterceptPoints().MERGE_UNDO)(
- a.undos,
- null
- ) || [];
- return { redos: l, undos: d, preRedos: u, preUndos: c };
- }
- });
- });
- R(this, "_checkRange", (e, t, o) => {
- const s = ls(t, o), r = this._refRangeManagerMap.get(s);
- if (r) {
- const i = /* @__PURE__ */ new Set();
- return [...r.keys()].forEach((u) => {
- const l = r.get(u), c = this._serializer.deserialize(u), d = {
- ...c,
- startRow: +c.startRow,
- endRow: +c.endRow,
- startColumn: +c.startColumn,
- endColumn: +c.endColumn,
- rangeType: c.rangeType && +c.rangeType
- };
- e.some((h) => k.intersects(h, d)) && l && l.forEach((h) => {
- i.add(h);
- });
- }), [...i];
- }
- return [];
- });
- /**
- * Listens to an area and triggers a fall back when movement occurs
- * @param {IRange} range the area that needs to be monitored
- * @param {RefRangCallback} callback the callback function that is executed when the range changes
- * @param {string} [_unitId]
- * @param {string} [_subUnitId]
- * @memberof RefRangeService
- */
- R(this, "registerRefRange", (e, t, o, s) => {
- const r = o || is(this._univerInstanceService), i = s || as(this._univerInstanceService);
- if (!r || !i)
- return We(() => {
- });
- const a = ls(r, i), u = this._serializer.serialize(e);
- let l = this._refRangeManagerMap.get(a);
- l || (l = /* @__PURE__ */ new Map(), this._refRangeManagerMap.set(a, l));
- const c = l.get(u);
- return c ? c.add(t) : l.set(u, /* @__PURE__ */ new Set([t])), We(() => {
- const d = l.get(u);
- d && (d.delete(t), d.size || (l.delete(u), l.size || this._refRangeManagerMap.delete(a)));
- });
- });
- this._commandService = e, this._sheetInterceptorService = t, this._univerInstanceService = o, this._selectionManagerService = s, this._onRefRangeChange(), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_REDO, {
- priority: -1,
- handler: (r) => r
- }), this.interceptor.intercept(this.interceptor.getInterceptPoints().MERGE_UNDO, {
- priority: -1,
- handler: (r) => r
- });
- }
- watchRange(e, t, o, s, r) {
- let i;
- this._watchRanges.size === 0 && (i = this._commandService.onCommandExecuted((c) => {
- if (c.type !== v.MUTATION) return !1;
- for (const d of this._watchRanges)
- d.onMutation(c);
- }));
- const a = new yc(e, t, o, s, r);
- this._watchRanges.add(a);
- const u = We(() => {
- this._watchRanges.delete(a), this._watchRanges.size === 0 && (i == null || i.dispose(), i = null);
- }), l = this.disposeWithMe(u);
- return We(() => {
- l.dispose(), u.dispose();
- });
- }
- };
- _t = Mc([
- dn(0, E),
- dn(1, L(V)),
- dn(2, L(M)),
- dn(3, L(F))
- ], _t);
- function is(n) {
- return n.getCurrentUnitForType(B.UNIVER_SHEET).getUnitId();
- }
- function as(n) {
- var e;
- return (e = n.getCurrentUnitForType(B.UNIVER_SHEET).getActiveSheet()) == null ? void 0 : e.getSheetId();
- }
- function us(n) {
- var e;
- return ((e = n.getCurrentSelections()) == null ? void 0 : e.map((t) => t.range)) || [];
- }
- function ls(n, e) {
- return `${n}_${e}`;
- }
- function Ec() {
- const n = ["startRow", "startColumn", "endRow", "endColumn", "rangeType"], e = "_";
- return {
- deserialize: (t) => {
- const o = n.reduce(
- (r, i, a) => (r[String(a)] = i, r),
- {}
- );
- return t.split(e).reduce(
- (r, i, a) => {
- const u = String(a);
- return i && o[u] && (r[o[u]] = i), r;
- },
- {}
- );
- },
- serialize: (t) => n.reduce((o, s, r) => {
- const i = t[s];
- return i !== void 0 ? `${o}${r > 0 ? e : ""}${i}` : `${o}`;
- }, "")
- };
- }
- var Uc = Object.defineProperty, Pc = Object.getOwnPropertyDescriptor, Tc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Pc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Uc(e, t, s), s;
- }, Rt = (n, e) => (t, o) => e(t, o, n);
- const kc = [je.id, qe.id, De.id, Be.id], Nc = [ot.id, st.id];
- function Zr(n, e) {
- let t = n;
- if (e !== void 0) {
- const o = [];
- for (let s = 0; s < t.length; s++) {
- const { startRow: r, endRow: i, startColumn: a, endColumn: u } = t[s];
- if (e === ge.ROWS)
- for (let l = r; l <= i; l++) {
- const c = {
- startRow: l,
- endRow: l,
- startColumn: a,
- endColumn: u
- };
- o.push(c);
- }
- else if (e === ge.COLUMNS)
- for (let l = a; l <= u; l++) {
- const c = {
- startRow: r,
- endRow: i,
- startColumn: l,
- endColumn: l
- };
- o.push(c);
- }
- }
- t = o;
- }
- return t;
- }
- const Oc = rt("mergeCellPermissionCheck");
- let Tn = class extends ae {
- constructor(e, t, o, s, r, i) {
- super();
- R(this, "disposableCollection", new jt());
- R(this, "interceptor", new mo({ MERGE_CELL_INTERCEPTOR_CHECK: Oc }));
- this._commandService = e, this._refRangeService = t, this._univerInstanceService = o, this._injector = s, this._sheetInterceptorService = r, this._selectionManagerService = i, this._onRefRangeChange(), this._initCommandInterceptor(), this._commandExecutedListener();
- }
- _initCommandInterceptor() {
- const e = this;
- this._sheetInterceptorService.interceptCommand({
- getMutations(t) {
- var o;
- switch (t.id) {
- case po.id:
- case So.id: {
- const s = e._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET), r = s.getUnitId(), i = s == null ? void 0 : s.getActiveSheet();
- if (!i)
- return { redos: [], undos: [] };
- const a = i.getSheetId(), u = i.getConfig().mergeData, l = (o = e._selectionManagerService.getCurrentSelections()) == null ? void 0 : o.map((c) => c.range);
- if (l && l.length > 0 && l.some(
- (d) => u.some((h) => k.intersects(h, d))
- )) {
- const d = {
- unitId: r,
- subUnitId: a,
- ranges: l
- }, h = Se(e._injector, d), m = [
- { id: oe.id, params: d }
- ], g = [
- { id: ne.id, params: h }
- ];
- return { redos: m, undos: g };
- }
- }
- }
- return { redos: [], undos: [] };
- }
- }), this._sheetInterceptorService.interceptRanges({
- getMutations: ({ unitId: t, subUnitId: o, ranges: s }) => {
- const r = [], i = [], a = { redos: r, undos: i };
- if (!s || !s.length)
- return a;
- const u = N(this._univerInstanceService, { unitId: t, subUnitId: o });
- if (!u)
- return a;
- const { worksheet: l } = u, d = l.getMergeData().filter((h) => s.some((m) => k.intersects(h, m)));
- return d.length ? (r.push({
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: d
- }
- }), i.push({
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: d
- }
- }), { undos: i, redos: r }) : a;
- }
- });
- }
- refRangeHandle(e, t, o) {
- switch (e.id) {
- case $.MoveColsCommandId: {
- const s = e.params;
- return this._handleMoveColsCommand(s, t, o);
- }
- case $.MoveRowsCommandId: {
- const s = e.params;
- return this._handleMoveRowsCommand(s, t, o);
- }
- case mt.id: {
- const s = e.params, r = s.unitId || t, i = s.subUnitId || o;
- return this._handleInsertRowCommand(s, r, i);
- }
- case gt.id: {
- const s = e.params, r = s.unitId || t, i = s.subUnitId || o;
- return this._handleInsertColCommand(s, r, i);
- }
- case zn.id: {
- const s = e.params;
- return this._handleRemoveColCommand(s, t, o);
- }
- case Gn.id: {
- const s = e.params;
- return this._handleRemoveRowCommand(s, t, o);
- }
- case pt.id: {
- const s = e.params;
- return this._handleMoveRangeCommand(s, t, o);
- }
- case Bn.id: {
- const s = e.params;
- return this._handleInsertRangeMoveRightCommand(s, t, o);
- }
- case sn.id: {
- const s = e.params;
- return this._handleInsertRangeMoveDownCommand(s, t, o);
- }
- case Tt.id: {
- const s = e.params;
- return this._handleDeleteRangeMoveUpCommand(s, t, o);
- }
- case Pt.id: {
- const s = e.params;
- return this._handleDeleteRangeMoveLeftCommand(s, t, o);
- }
- }
- return { redos: [], undos: [] };
- }
- _onRefRangeChange() {
- const e = (t, o) => {
- const s = this._univerInstanceService.getUniverSheetInstance(t);
- if (!s)
- return;
- const r = s == null ? void 0 : s.getSheetBySheetId(o);
- if (!r)
- return;
- this.disposableCollection.dispose();
- const i = r.getMergeData(), a = (u) => this.refRangeHandle(u, t, o);
- i.forEach((u) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(u, a, t, o));
- });
- };
- this.disposeWithMe(
- this._commandService.onCommandExecuted((t) => {
- if (t.id === an.id) {
- const o = t.params, s = o.subUnitId, r = o.unitId;
- if (!s || !r)
- return;
- e(r, s);
- }
- if (t.id === ne.id) {
- const o = t.params, s = o.subUnitId, r = o.unitId;
- if (!s || !r)
- return;
- e(o.unitId, o.subUnitId);
- }
- })
- ), this._univerInstanceService.getCurrentTypeOfUnit$(B.UNIVER_SHEET).pipe(zi((t) => !!t)).subscribe((t) => {
- const o = t.getActiveSheet();
- o && e(t.getUnitId(), o.getSheetId());
- });
- }
- _handleMoveRowsCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startRow: c, endRow: d } = l;
- if (i.forEach((g) => {
- if (c <= g.startRow && d >= g.endRow) {
- a.ranges.push(g);
- const f = Jr({ id: $.MoveRowsCommandId, params: e }, g), p = Mt(f, g);
- p && u.ranges.push(p);
- }
- }), a.ranges.length === 0)
- return this._handleNull();
- const h = Se(this._injector, a), m = Ue(this._injector, u);
- return {
- preRedos: [{ id: oe.id, params: a }],
- redos: [{ id: ne.id, params: u }],
- preUndos: [{ id: oe.id, params: m }],
- undos: [{ id: ne.id, params: h }]
- };
- }
- _handleMoveColsCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = [...r.getMergeData()], a = { unitId: t, subUnitId: o, ranges: [] }, u = { unitId: t, subUnitId: o, ranges: [] }, { fromRange: l } = e, { startColumn: c, endColumn: d } = l;
- if (i.forEach((g) => {
- if (c <= g.startColumn && d >= g.endColumn) {
- a.ranges.push(g);
- const f = Yr({ id: $.MoveColsCommandId, params: e }, g), p = Mt(f, g);
- p && u.ranges.push(p);
- }
- }), a.ranges.length === 0)
- return this._handleNull();
- const h = Se(this._injector, a), m = Ue(this._injector, u);
- return {
- preRedos: [{ id: oe.id, params: a }],
- redos: [{ id: ne.id, params: u }],
- preUndos: [{ id: oe.id, params: m }],
- undos: [{ id: ne.id, params: h }]
- };
- }
- _handleMoveRangeCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = r.getMergeData(), a = i.filter((m) => 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(
- (m) => !i.some((g) => k.equals(m, g))
- ), d = [
- {
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: a
- }
- },
- {
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: u
- }
- },
- {
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: c
- }
- }
- ], h = [
- {
- id: oe.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: c
- }
- },
- {
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: u
- }
- },
- {
- id: ne.id,
- params: {
- unitId: t,
- subUnitId: o,
- ranges: a
- }
- }
- ];
- return { redos: d, undos: h };
- }
- _handleInsertRowCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const { range: i } = e, { startRow: a, endRow: u } = i, l = O.deepClone(r.getMergeData()).reduce((C, S) => (a > S.startRow && a <= S.endRow && C.push(S), C), []);
- if (l.length === 0)
- return this._handleNull();
- const c = O.deepClone(r.getMergeData()).reduce((C, S) => {
- if (a > S.startRow && a <= S.endRow) {
- const I = u - a + 1;
- S.endRow += I, this._checkIsMergeCell(S) && C.push(S);
- }
- return C;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- ), f = [
- { id: oe.id, params: d },
- { id: ne.id, params: m }
- ], p = [
- { id: oe.id, params: g },
- { id: ne.id, params: h }
- ];
- return { redos: f, undos: p };
- }
- _handleInsertColCommand(e, t, o) {
- const { range: s } = e, r = be(this._univerInstanceService, t);
- if (!r)
- return this._handleNull();
- const i = ye(r, o);
- if (!i)
- return this._handleNull();
- const { startColumn: a, endColumn: u } = s, l = O.deepClone(i.getMergeData()).reduce((C, S) => (a > S.startColumn && a <= S.endColumn && C.push(S), C), []);
- if (l.length === 0)
- return this._handleNull();
- const c = O.deepClone(i.getMergeData()).reduce((C, S) => {
- if (a > S.startColumn && a <= S.endColumn) {
- const I = u - a + 1;
- S.endColumn += I, this._checkIsMergeCell(S) && C.push(S);
- }
- return C;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- ), f = [
- { id: oe.id, params: d },
- { id: ne.id, params: m }
- ], p = [
- { id: oe.id, params: g },
- { id: ne.id, params: h }
- ];
- return { redos: f, undos: p };
- }
- _handleRemoveColCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const { range: i } = e, { startColumn: a, endColumn: u } = i, l = O.deepClone(r.getMergeData()).reduce((I, w) => (k.intersects(i, w) && I.push(w), I), []);
- if (l.length === 0)
- return this._handleNull();
- const c = O.deepClone(r.getMergeData()).reduce((I, w) => {
- if (k.intersects(i, w)) {
- if (a <= w.startColumn && u >= w.endColumn)
- return I;
- a >= w.startColumn && u <= w.endColumn ? w.endColumn -= u - a + 1 : a < w.startColumn ? (w.startColumn = a, w.endColumn -= u - a + 1) : u > w.endColumn && (w.endColumn = a - 1), this._checkIsMergeCell(w) && I.push(w);
- }
- return I;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g }], S = [{ id: ne.id, params: h }];
- return { preUndos: C, undos: S, preRedos: f, redos: p };
- }
- _handleRemoveRowCommand(e, t, o) {
- const { range: s } = e, r = be(this._univerInstanceService, t);
- if (!r)
- return this._handleNull();
- const i = ye(r, o);
- if (!i)
- return this._handleNull();
- const { startRow: a, endRow: u } = s, l = O.deepClone(i.getMergeData()).reduce((I, w) => (k.intersects(s, w) && I.push(w), I), []);
- if (l.length === 0)
- return this._handleNull();
- const c = O.deepClone(i.getMergeData()).reduce((I, w) => {
- if (k.intersects(s, w)) {
- if (a <= w.startRow && u >= w.endRow)
- return I;
- a >= w.startRow && u <= w.endRow ? w.endRow -= u - a + 1 : a < w.startRow ? (w.startRow = a, w.endRow -= u - a + 1) : u > w.endRow && (w.endRow = a - 1), this._checkIsMergeCell(w) && I.push(w);
- }
- return I;
- }, []), d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- ), f = [{ id: oe.id, params: d }], p = [{ id: ne.id, params: m }], C = [{ id: oe.id, params: g }], S = [{ id: ne.id, params: h }];
- return { preUndos: C, undos: S, preRedos: f, redos: p };
- }
- _handleInsertRangeMoveRightCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((f) => {
- const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i;
- if (k.intersects(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ) && (l.push(f), k.contains(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ))) {
- const y = I - S + 1;
- c.push({
- startRow: f.startRow,
- startColumn: f.startColumn + y,
- endRow: f.endRow,
- endColumn: f.endColumn + y
- });
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- );
- return {
- preRedos: [
- { id: oe.id, params: d }
- ],
- redos: [
- {
- id: ne.id,
- params: m
- }
- ],
- preUndos: [
- { id: oe.id, params: g }
- ],
- undos: [
- {
- id: ne.id,
- params: h
- }
- ]
- };
- }
- _handleInsertRangeMoveDownCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((I) => {
- const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i;
- if (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))) {
- const P = x - w + 1;
- c.push({
- startRow: I.startRow + P,
- startColumn: I.startColumn,
- endRow: I.endRow + P,
- endColumn: I.endColumn
- });
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- ), f = [
- {
- id: oe.id,
- params: d
- }
- ], p = [
- {
- id: ne.id,
- params: m
- }
- ], C = [
- {
- id: oe.id,
- params: g
- }
- ], S = [
- {
- id: ne.id,
- params: h
- }
- ];
- return { redos: p, undos: S, preRedos: f, preUndos: C };
- }
- _handleDeleteRangeMoveUpCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxRows() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((I) => {
- const { startRow: w, startColumn: b, endColumn: y, endRow: x } = i;
- if (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))) {
- const P = x - w + 1, A = k.moveVertical(I, -P);
- c.push(A);
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(
- this._injector,
- d
- ), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(
- this._injector,
- m
- ), f = [
- {
- id: oe.id,
- params: d
- }
- ], p = [
- {
- id: ne.id,
- params: m
- }
- ], C = [
- {
- id: oe.id,
- params: g
- }
- ], S = [
- {
- id: ne.id,
- params: h
- }
- ];
- return { redos: p, undos: S, preRedos: f, preUndos: C };
- }
- _handleDeleteRangeMoveLeftCommand(e, t, o) {
- const s = be(this._univerInstanceService, t);
- if (!s)
- return this._handleNull();
- const r = ye(s, o);
- if (!r)
- return this._handleNull();
- const i = e.range, a = r.getMaxColumns() - 1, u = r.getMergeData(), l = [], c = [];
- u.forEach((f) => {
- const { startRow: p, endRow: C, startColumn: S, endColumn: I } = i;
- if (k.intersects(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ) && (l.push(f), k.contains(
- {
- startRow: p,
- startColumn: S,
- endRow: C,
- endColumn: a
- },
- f
- ))) {
- const y = I - S + 1;
- c.push({
- startRow: f.startRow,
- startColumn: f.startColumn - y,
- endRow: f.endRow,
- endColumn: f.endColumn - y
- });
- }
- });
- const d = {
- unitId: t,
- subUnitId: o,
- ranges: l
- }, h = Se(this._injector, d), m = {
- unitId: t,
- subUnitId: o,
- ranges: c
- }, g = Ue(this._injector, m);
- return {
- preRedos: [
- { id: oe.id, params: d }
- ],
- redos: [
- {
- id: ne.id,
- params: m
- }
- ],
- undos: [
- {
- id: ne.id,
- params: h
- }
- ],
- preUndos: [
- { id: oe.id, params: g }
- ]
- };
- }
- _checkIsMergeCell(e) {
- return !(e.startRow === e.endRow && e.startColumn === e.endColumn);
- }
- _handleNull() {
- return { redos: [], undos: [] };
- }
- _commandExecutedListener() {
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
- if (Nc.includes(e.id)) {
- if (!e.params) return;
- const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
- if (!t) return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o) return;
- const { sourceRange: s, targetRange: r } = e.params, i = s.startColumn === r.startColumn && s.endColumn === r.endColumn, a = i ? s.endRow - s.startRow + 1 : s.endColumn - s.startColumn + 1, u = i ? s.startRow : s.startColumn, l = i ? r.startRow : r.startColumn, c = o.getConfig().mergeData, d = [];
- c.forEach((f) => {
- let { startRow: p, endRow: C, startColumn: S, endColumn: I, rangeType: w } = f;
- 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 });
- }), o.setMergeData(d), this.disposableCollection.dispose();
- const { unitId: h, subUnitId: m } = e.params, g = (f) => this.refRangeHandle(f, h, m);
- d.forEach((f) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(f, g, h, m));
- });
- }
- if (kc.includes(e.id)) {
- const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
- if (!t) return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o) return;
- const s = o.getConfig().mergeData, r = e.params;
- if (!r) return;
- const { range: i } = r, a = e.id.includes("row"), u = e.id.includes("insert"), l = a ? i.startRow : i.startColumn, c = a ? i.endRow : i.endColumn, d = c - l + 1, h = [];
- s.forEach((p) => {
- let { startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b } = p;
- u ? a ? l <= C && (C += d, S += d) : l <= I && (I += d, w += d) : a ? c < C && (C -= d, S -= d) : c < I && (I -= d, w -= d), p.startRow === p.endRow && p.startColumn === p.endColumn || h.push({ startRow: C, endRow: S, startColumn: I, endColumn: w, rangeType: b });
- }), o.setMergeData(h), this.disposableCollection.dispose();
- const { unitId: m, subUnitId: g } = e.params, f = (p) => this.refRangeHandle(p, m, g);
- h.forEach((p) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(p, f, m, g));
- });
- }
- }));
- }
- };
- Tn = Tc([
- Rt(0, L(E)),
- Rt(1, L(_t)),
- Rt(2, L(M)),
- Rt(3, L(Ro)),
- Rt(4, L(V)),
- Rt(5, L(F))
- ], Tn);
- function be(n, e) {
- return e ? n.getUniverSheetInstance(e) : n.getCurrentUnitForType(B.UNIVER_SHEET);
- }
- function ye(n, e) {
- return e ? n.getSheetBySheetId(e) : n.getActiveSheet();
- }
- var Dc = Object.defineProperty, Ac = Object.getOwnPropertyDescriptor, xc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Ac(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Dc(e, t, s), s;
- }, $c = (n, e) => (t, o) => e(t, o, n);
- let kn = class extends ae {
- constructor(n) {
- super(), this._sheetInterceptorService = n, this._initialize();
- }
- _initialize() {
- this._initInterceptorCellContent();
- }
- _initInterceptorCellContent() {
- this.disposeWithMe(
- this._sheetInterceptorService.intercept(et.CELL_CONTENT, {
- priority: 11,
- effect: me.Value | me.Style,
- handler: (n, e, t) => {
- var s;
- const o = e.workbook.getStyles().getStyleByCell(n);
- return (s = o == null ? void 0 : o.n) != null && s.pattern ? t({ ...n }) : (n == null ? void 0 : n.t) === se.NUMBER && n.v !== void 0 && n.v !== null && go(n.v) ? t({
- ...n,
- v: xi(Number(n.v))
- }) : t({ ...n });
- }
- })
- );
- }
- };
- kn = xc([
- $c(0, L(V))
- ], kn);
- var Wc = Object.defineProperty, Lc = Object.getOwnPropertyDescriptor, Vc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Lc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Wc(e, t, s), s;
- }, $e = (n, e) => (t, o) => e(t, o, n);
- let Nn = class extends ae {
- constructor(e, t, o, s, r, i, a, u, l, c) {
- super();
- R(this, "disposableCollection", new jt());
- R(this, "_triggerPermissionUIEvent$", new Le());
- R(this, "triggerPermissionUIEvent$", this._triggerPermissionUIEvent$.asObservable());
- this._commandService = e, this._univerInstanceService = t, this._permissionService = o, this._selectionManagerService = s, this._rangeProtectionRuleModel = r, this._worksheetProtectionRuleModel = i, this._localeService = a, this._lexerTreeBuilder = u, this._contextService = l, this._definedNamesService = c, this._initialize();
- }
- blockExecuteWithoutPermission(e) {
- throw this._triggerPermissionUIEvent$.next(e), new wi("have no permission");
- }
- _getPermissionCheck(e, t) {
- let o = !0, s = "";
- switch (e) {
- case on.id:
- Is(t.value) && t.value.f ? (o = this._permissionCheckWithFormula(t), s = this._localeService.t("permission.dialog.formulaErr")) : o = this._permissionCheckBySetRangeValue({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [wn, Te]
- }, t);
- break;
- case Co.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [wn, Te]
- }), s = this._localeService.t("permission.dialog.editErr");
- break;
- case Oo.id:
- case Mn.id:
- o = this.permissionCheckWithoutRange({
- worksheetTypes: [$t]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case $o.id:
- case Wo.id:
- case Lo.id:
- o = this.permissionCheckWithoutRange({
- worksheetTypes: [Wt]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case jn.id:
- case Fn.id:
- o = this._permissionCheckByMoveCommand(t), s = this._localeService.t("permission.dialog.moveRowColErr");
- break;
- case pt.id:
- o = this._permissionCheckByMoveRangeCommand(t), s = this._localeService.t("permission.dialog.moveRangeErr");
- break;
- case Wr.id:
- o = this._permissionCheckByWorksheetCommand([Me, _o]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder();
- break;
- case Do.id:
- o = this._permissionCheckByWorksheetCommand([Me, bo]), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder();
- break;
- case Fr.id:
- {
- const { unitId: r, subUnitId: i } = t;
- o = this._permissionCheckByWorksheetCommand([Me, vo], r, i), s = this._localeService.t("permission.dialog.operatorSheetErr"), o === !1 && this._worksheetProtectionRuleModel.resetOrder();
- }
- break;
- case Kn.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, $t]
- }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case Jn.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, Wt]
- }, t.ranges), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case br.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, $t]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case Tr.id:
- o = this.permissionCheckWithRanges({
- workbookTypes: [Me],
- rangeTypes: [Pe],
- worksheetTypes: [Te, Wt]
- }), s = this._localeService.t("permission.dialog.setRowColStyleErr");
- break;
- case Bn.id:
- o = this._permissionCheckWithInsertRangeMove("right"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- case sn.id:
- o = this._permissionCheckWithInsertRangeMove("bottom"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- case Pt.id:
- o = this._permissionCheckWithInsertRangeMove("left"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- case Tt.id:
- o = this._permissionCheckWithInsertRangeMove("top"), s = this._localeService.t("permission.dialog.insertOrDeleteMoveRangeErr");
- break;
- }
- o || this.blockExecuteWithoutPermission(s);
- }
- _initialize() {
- this._commandExecutedListener();
- }
- _commandExecutedListener() {
- this.disposeWithMe(
- this._commandService.beforeCommandExecuted((e) => {
- this._getPermissionCheck(e.id, e == null ? void 0 : e.params);
- })
- ), this.disposeWithMe(
- this._commandService.onCommandExecuted((e) => {
- var t;
- if (e.id === _n.id) {
- const o = e.params, { unitId: s = (t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET)) == null ? void 0 : t.getUnitId(), subUnitId: r } = o;
- if (!s || !r)
- return;
- const i = this._worksheetProtectionRuleModel.getRule(s, r), a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r);
- i && this._worksheetProtectionRuleModel.ruleRefresh(i.permissionId), a.length && this._rangeProtectionRuleModel.ruleRefresh(r);
- }
- })
- );
- }
- _permissionCheckWithInsertRangeMove(e) {
- var l;
- const t = N(this._univerInstanceService);
- if (!t)
- return !1;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = O.deepClone((l = this._selectionManagerService.getCurrentLastSelection()) == null ? void 0 : l.range);
- return !(!i || (e === "top" || e === "bottom" ? i.endRow = o.getRowCount() - 1 : (e === "left" || e === "right") && (i.endColumn = o.getColumnCount() - 1), this._rangeProtectionRuleModel.getSubunitRuleList(s, r).map((c) => c.ranges).flat().some((c) => k.getIntersects(i, c))));
- }
- _permissionCheckByWorksheetCommand(e, t, o) {
- var l, c;
- const s = N(this._univerInstanceService, { unitId: t, subUnitId: o });
- if (!s)
- return !1;
- const { unitId: r, subUnitId: i } = s, a = this._worksheetProtectionRuleModel.getRule(r, i), u = this._rangeProtectionRuleModel.getSubunitRuleList(r, i).length > 0;
- return a || u ? (c = (l = this._permissionService.getPermissionPoint(new Mo(r).id)) == null ? void 0 : l.value) != null ? c : !1 : this._permissionService.composePermission(e.map((d) => new d(r).id)).every((d) => d.value);
- }
- permissionCheckWithoutRange(e) {
- var h, m, g, f;
- const t = N(this._univerInstanceService);
- if (!t)
- return !1;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = this._selectionManagerService.getCurrentLastSelection();
- if (!i)
- return !0;
- 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;
- return !(l && l.some((C) => {
- var w, b;
- const S = new C(s);
- return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : !1) === !1;
- }) === !0 || c && c.some((C) => {
- var w, b;
- const S = new C(s, r);
- return ((b = (w = this._permissionService.getPermissionPoint(S.id)) == null ? void 0 : w.value) != null ? b : !1) === !1;
- }) === !0 || d && d.some((C) => {
- var y, x, T, U, P;
- const S = (x = (y = o.getCell(a, u)) == null ? void 0 : y.selectionProtection) == null ? void 0 : x[0];
- if (!(S != null && S.ruleId))
- return !1;
- const I = (T = this._rangeProtectionRuleModel.getRule(s, r, S.ruleId)) == null ? void 0 : T.permissionId;
- if (!I)
- return !1;
- const w = new C(s, r, I);
- return ((P = (U = this._permissionService.getPermissionPoint(w.id)) == null ? void 0 : U.value) != null ? P : !1) === !1;
- }) === !0);
- }
- permissionCheckWithRanges(e, t, o, s) {
- var m;
- const r = N(this._univerInstanceService);
- if (!r)
- return !1;
- const { workbook: i, worksheet: a } = r;
- o || (o = i.getUnitId()), s || (s = a.getSheetId());
- const u = t != null ? t : (m = this._selectionManagerService.getCurrentSelections()) == null ? void 0 : m.map((g) => g.range);
- if (!u)
- return !1;
- const { workbookTypes: l, worksheetTypes: c, rangeTypes: d } = e, h = [];
- 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) => {
- u.some((p) => g.ranges.some((C) => k.intersects(C, p))) && h.push(...d.map((p) => new p(o, s, g.permissionId).id));
- }), h.length ? this._permissionService.composePermission(h).every((g) => g.value) : !0;
- }
- _permissionCheckByMoveCommand(e) {
- const t = N(this._univerInstanceService);
- if (!t)
- return !1;
- const { worksheet: o, unitId: s, subUnitId: r } = t, i = e.toRange;
- i.endRow === o.getRowCount() - 1 ? i.endColumn = i.startColumn : i.endRow = i.startRow;
- const a = this._rangeProtectionRuleModel.getSubunitRuleList(s, r).reduce((u, l) => [...u, ...l.ranges], []).filter((u) => k.intersects(u, i));
- return a.length > 0 ? !1 : (a.forEach((u) => {
- var l, c;
- for (let d = u.startRow; d <= u.endRow; d++)
- for (let h = u.startColumn; h <= u.endColumn; h++) {
- const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0];
- if ((m == null ? void 0 : m[_.Edit]) === !1)
- return !1;
- }
- }), !0);
- }
- _permissionCheckByMoveRangeCommand(e) {
- const t = N(this._univerInstanceService);
- if (!t)
- return !1;
- 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));
- return a.length > 0 ? !1 : (a.forEach((u) => {
- var l, c;
- for (let d = u.startRow; d <= u.endRow; d++)
- for (let h = u.startColumn; h <= u.endColumn; h++) {
- const m = (c = (l = o.getCell(d, h)) == null ? void 0 : l.selectionProtection) == null ? void 0 : c[0];
- if ((m == null ? void 0 : m[_.Edit]) === !1)
- return !1;
- }
- }), !0);
- }
- _permissionCheckBySetRangeValue(e, t) {
- let o = [];
- t.range ? o = [t.range] : o = [new G(t.value).getDataRange()];
- const { unitId: s, subUnitId: r } = t;
- return this.permissionCheckWithRanges(e, o, s, r);
- }
- _permissionCheckWithFormula(e) {
- var r, i, a, u, l;
- const t = e.value, o = e.range, s = t.f;
- if (s) {
- const c = s.substring(1), d = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET), h = (r = e.unitId) != null ? r : d.getUnitId(), m = this._definedNamesService.getValueByName(h, c);
- if (m) {
- let g = m.formulaOrRefString;
- g.startsWith(Wi.EQUALS) && (g = g.slice(1));
- const f = g.split(",");
- for (let p = 0; p < f.length; p++) {
- const C = f[p], S = Li(C);
- if (S.sheetName) {
- const I = d.getSheetBySheetName(S.sheetName);
- if (!I)
- return !0;
- const { startRow: w, endRow: b, startColumn: y, endColumn: x } = S.range;
- for (let T = w; T <= b; T++)
- for (let U = y; U <= x; U++) {
- const P = (a = (i = I.getCell(T, U)) == null ? void 0 : i.selectionProtection) == null ? void 0 : a[0];
- if ((P == null ? void 0 : P[_.View]) === !1)
- return !1;
- }
- }
- }
- return !0;
- } else {
- const g = this._lexerTreeBuilder.sequenceNodesBuilder(s);
- if (!g)
- return !0;
- for (let f = 0; f < g.length; f++) {
- const p = g[f];
- if (typeof p == "string" || p.nodeType !== Vi.REFERENCE)
- continue;
- const { token: C } = p, S = Hi(C), I = S.unitId ? this._univerInstanceService.getUnit(S.unitId) : this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!I) return !0;
- let w = S.sheetName ? I.getSheetBySheetName(S.sheetName) : I.getActiveSheet();
- const b = I.getUnitId();
- if (S.sheetName) {
- if (w = I.getSheetBySheetName(S.sheetName), !w)
- return !0;
- const P = w == null ? void 0 : w.getSheetId();
- if (!this._permissionService.getPermissionPoint(new Hn(b, P).id)) return !1;
- }
- if (!w)
- return !0;
- const { startRow: y, endRow: x, startColumn: T, endColumn: U } = S.range;
- for (let P = y; P <= x; P++)
- for (let A = T; A <= U; A++) {
- const j = (l = (u = w.getCell(P, A)) == null ? void 0 : u.selectionProtection) == null ? void 0 : l[0];
- if ((j == null ? void 0 : j[_.View]) === !1)
- return !1;
- }
- }
- return !0;
- }
- }
- if (o) {
- const c = N(this._univerInstanceService);
- if (!c)
- return !1;
- 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);
- if (!this._permissionService.composePermission(g).every((p) => p.value))
- return !1;
- }
- return !0;
- }
- };
- Nn = Vc([
- $e(0, E),
- $e(1, M),
- $e(2, Fe),
- $e(3, L(F)),
- $e(4, L(de)),
- $e(5, L(Ye)),
- $e(6, L(Ke)),
- $e(7, L($i)),
- $e(8, Ss),
- $e(9, Ps)
- ], Nn);
- var Hc = Object.defineProperty, Bc = Object.getOwnPropertyDescriptor, Fc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Bc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Hc(e, t, s), s;
- }, no = (n, e) => (t, o) => e(t, o, n);
- let ht = class extends ae {
- constructor(e, t, o) {
- super();
- R(this, "_cellRuleCache", /* @__PURE__ */ new Map());
- R(this, "_permissionIdCache", /* @__PURE__ */ new Map());
- R(this, "_cellInfoCache", /* @__PURE__ */ new Map());
- // {unitId:{subUnitId:{[row/col]:{permissionId1:{edit:true},permissionId2:{edit:true},permissionId3:{edit:false}}}}}
- R(this, "_rowInfoCache", /* @__PURE__ */ new Map());
- R(this, "_colInfoCache", /* @__PURE__ */ new Map());
- this._ruleModel = e, this._permissionService = t, this._univerInstanceService = o, this._initUpdateCellRuleCache(), this._initUpdateCellInfoCache(), this._initUpdateRowColInfoCache(), this._initCache();
- }
- _initCache() {
- this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => {
- e.getSheets().forEach((t) => {
- const o = e.getUnitId(), s = t.getSheetId();
- this.reBuildCache(o, s);
- });
- });
- }
- _initUpdateCellInfoCache() {
- this._permissionService.permissionPointUpdate$.pipe(
- Ho((e) => e.type === D.SelectRange),
- ao((e) => e)
- ).subscribe((e) => {
- const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s);
- if (!r)
- return;
- const i = this._ruleModel.getRule(o, t, r);
- if (!i)
- return;
- const a = this._ensureCellInfoMap(o, t);
- i.ranges.forEach((u) => {
- const { startRow: l, endRow: c, startColumn: d, endColumn: h } = u;
- for (let m = l; m <= c; m++)
- for (let g = d; g <= h; g++)
- a.delete(`${m}-${g}`);
- });
- }), this._ruleModel.ruleChange$.subscribe((e) => {
- var r;
- const { unitId: t, subUnitId: o } = e, s = this._ensureCellInfoMap(t, o);
- e.rule.ranges.forEach((i) => {
- K.foreach(i, (a, u) => {
- s.delete(`${a}-${u}`);
- });
- }), e.type === "set" && ((r = e.oldRule) == null || r.ranges.forEach((i) => {
- K.foreach(i, (a, u) => {
- this._cellInfoCache.delete(`${a}-${u}`);
- });
- }));
- });
- }
- _initUpdateCellRuleCache() {
- this._ruleModel.ruleChange$.subscribe((e) => {
- const { type: t } = e;
- t === "add" ? this._addCellRuleCache(e) : t === "delete" ? this._deleteCellRuleCache(e) : (this._deleteCellRuleCache({ ...e, rule: e.oldRule }), this._addCellRuleCache(e));
- });
- }
- _ensureRuleMap(e, t) {
- let o = this._cellRuleCache.get(e);
- o || (o = /* @__PURE__ */ new Map(), this._cellRuleCache.set(e, o));
- let s = o.get(t);
- return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
- }
- _ensureCellInfoMap(e, t) {
- let o = this._cellInfoCache.get(e);
- o || (o = /* @__PURE__ */ new Map(), this._cellInfoCache.set(e, o));
- let s = o.get(t);
- return s || (s = /* @__PURE__ */ new Map(), o.set(t, s)), s;
- }
- _ensureRowColInfoMap(e, t, o) {
- let s = o === "row" ? this._rowInfoCache.get(e) : this._colInfoCache.get(e);
- s || (s = /* @__PURE__ */ new Map(), o === "row" ? this._rowInfoCache.set(e, s) : this._colInfoCache.set(e, s));
- let r = s.get(t);
- return r || (r = /* @__PURE__ */ new Map(), s.set(t, r)), r;
- }
- _addCellRuleCache(e) {
- const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t);
- s.ranges.forEach((i) => {
- const { startRow: a, endRow: u, startColumn: l, endColumn: c } = i;
- for (let d = a; d <= u; d++)
- for (let h = l; h <= c; h++)
- r.set(`${d}-${h}`, s.id);
- }), this._permissionIdCache.set(s.permissionId, s.id);
- }
- _deleteCellRuleCache(e) {
- const { subUnitId: t, unitId: o, rule: s } = e, r = this._ensureRuleMap(o, t), i = this._ensureCellInfoMap(o, t);
- s.ranges.forEach((a) => {
- const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a;
- for (let h = u; h <= l; h++)
- for (let m = c; m <= d; m++)
- r.delete(`${h}-${m}`), i.delete(`${h}-${m}`);
- }), this._permissionIdCache.delete(s.permissionId);
- }
- _getSelectionActions(e, t, o) {
- var l, c, d, h, m, g, f, p, C, S, I, w;
- const s = (d = (c = this._permissionService.getPermissionPoint((l = new Pe(e, t, o.permissionId)) == null ? void 0 : l.id)) == null ? void 0 : c.value) != null ? d : !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;
- return {
- [_.Edit]: s,
- [_.View]: r,
- [_.ManageCollaborator]: i,
- [_.Delete]: a
- };
- }
- reBuildCache(e, t) {
- const o = this._ensureRuleMap(e, t), s = this._ensureCellInfoMap(e, t);
- o.clear(), s.clear();
- const r = this._ensureRowColInfoMap(e, t, "row"), i = this._ensureRowColInfoMap(e, t, "col");
- r.clear(), i.clear(), this._ruleModel.getSubunitRuleList(e, t).forEach((a) => {
- const u = this._getSelectionActions(e, t, a), l = {
- ...u,
- ruleId: a.id,
- ranges: a.ranges
- };
- a.ranges.forEach((c) => {
- const { startRow: d, endRow: h, startColumn: m, endColumn: g } = c;
- for (let f = d; f <= h; f++) {
- const p = r.get(`${f}`);
- p ? p.set(a.id, u) : r.set(`${f}`, /* @__PURE__ */ new Map([[a.id, u]]));
- for (let C = m; C <= g; C++) {
- o.set(`${f}-${C}`, a.id), s.set(`${f}-${C}`, l);
- const S = i.get(`${C}`);
- S ? S.set(a.id, u) : i.set(`${C}`, /* @__PURE__ */ new Map([[a.id, u]]));
- }
- }
- }), this._permissionIdCache.set(a.permissionId, a.id);
- });
- }
- getRowPermissionInfo(e, t, o, s) {
- var a;
- const r = (a = this._rowInfoCache.get(e)) == null ? void 0 : a.get(t);
- if (!r)
- return !0;
- const i = r.get(`${o}`);
- return i ? s.every((u) => {
- for (const l of i.values())
- if (l[u] === !1)
- return !1;
- return !0;
- }) : !0;
- }
- getColPermissionInfo(e, t, o, s) {
- var a;
- const r = (a = this._colInfoCache.get(e)) == null ? void 0 : a.get(t);
- if (!r)
- return !0;
- const i = r.get(`${o}`);
- return i ? s.every((u) => {
- for (const l of i.values())
- if (l[u] === !1)
- return !1;
- return !0;
- }) : !0;
- }
- _initUpdateRowColInfoCache() {
- this._permissionService.permissionPointUpdate$.pipe(
- Ho((e) => e.type === D.SelectRange),
- ao((e) => e)
- ).subscribe({
- next: (e) => {
- const { subUnitId: t, unitId: o, permissionId: s } = e, r = this._permissionIdCache.get(s);
- if (!r)
- return;
- const i = this._ruleModel.getRule(o, t, r);
- if (!i)
- return;
- const a = this._ensureRowColInfoMap(o, t, "row"), u = this._ensureRowColInfoMap(o, t, "col"), l = this._getSelectionActions(o, t, i);
- i.ranges.forEach((c) => {
- const { startRow: d, endRow: h, startColumn: m, endColumn: g } = c;
- for (let f = d; f <= h; f++) {
- const p = a.get(`${f}`);
- p ? p.set(r, l) : a.set(`${f}`, /* @__PURE__ */ new Map([[r, l]]));
- for (let C = m; C <= g; C++) {
- const S = u.get(`${C}`);
- S ? S.set(r, l) : u.set(`${C}`, /* @__PURE__ */ new Map([[r, l]]));
- }
- }
- });
- }
- }), this._ruleModel.ruleChange$.subscribe((e) => {
- if (e.type === "delete") {
- const { unitId: t, subUnitId: o, rule: s } = e, r = this._ensureRowColInfoMap(t, o, "row"), i = this._ensureRowColInfoMap(t, o, "col");
- s.ranges.forEach((a) => {
- const { startRow: u, endRow: l, startColumn: c, endColumn: d } = a;
- for (let h = u; h <= l; h++) {
- const m = r.get(`${h}`);
- m == null || m.delete(s.id);
- for (let g = c; g <= d; g++) {
- const f = i.get(`${g}`);
- f == null || f.delete(s.id);
- }
- }
- });
- }
- });
- }
- getCellInfo(e, t, o, s) {
- var l, c;
- const r = this._ensureCellInfoMap(e, t), i = r.get(`${o}-${s}`);
- if (i)
- return i;
- const a = (c = (l = this._cellRuleCache.get(e)) == null ? void 0 : l.get(t)) == null ? void 0 : c.get(`${o}-${s}`);
- if (!a)
- return;
- const u = this._ruleModel.getRule(e, t, a);
- if (u) {
- const h = {
- ...this._getSelectionActions(e, t, u),
- ruleId: a,
- ranges: u.ranges
- };
- return r.set(`${o}-${s}`, h), h;
- }
- }
- deleteUnit(e) {
- this._cellRuleCache.delete(e), this._cellInfoCache.delete(e), this._rowInfoCache.delete(e), this._colInfoCache.delete(e);
- const t = this._univerInstanceService.getUnit(e);
- t == null || t.getSheets().forEach((o) => {
- const s = o.getSheetId();
- this._ruleModel.getSubunitRuleList(e, s).forEach((r) => {
- this._permissionIdCache.delete(r.permissionId);
- });
- });
- }
- };
- ht = Fc([
- no(0, L(de)),
- no(1, L(Fe)),
- no(2, L(M))
- ], ht);
- var jc = Object.defineProperty, Gc = Object.getOwnPropertyDescriptor, zc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Gc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && jc(e, t, s), s;
- }, Ee = (n, e) => (t, o) => e(t, o, n);
- let On = class extends ae {
- constructor(n, e, t, o, s, r, i, a, u, l, c) {
- super(), this._univerInstanceService = n, this._permissionService = e, this._authzIoService = t, this._rangeProtectionRuleModel = o, this._worksheetProtectionRuleModel = s, this._userManagerService = r, this._worksheetProtectionPointRuleModel = i, this._sheetInterceptorService = a, this._undoRedoService = u, this._commandService = l, this._rangeProtectionCache = c, this._initRangePermissionFromSnapshot(), this._initRangePermissionChange(), this._initWorksheetPermissionFromSnapshot(), this._initWorksheetPermissionChange(), this._initWorksheetPermissionPointsChange(), this._initWorkbookPermissionFromSnapshot(), this._initUserChange(), this._refreshPermissionByCollaCreate();
- }
- async _initRangePermissionFromSnapshot() {
- const n = async (e) => {
- const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map();
- if (s.forEach((i) => {
- const a = i.getSheetId();
- this._rangeProtectionRuleModel.getSubunitRuleList(o, a).forEach((u) => {
- r.set(u.permissionId, u), t.push({
- objectID: u.permissionId,
- unitID: o,
- objectType: D.SelectRange,
- actions: it
- });
- });
- }), !t.length) {
- this._rangeProtectionRuleModel.changeRuleInitState(!0);
- return;
- }
- this._authzIoService.batchAllowed(t).then((i) => {
- i.forEach((a) => {
- const u = r.get(a.objectID);
- u && Ie().forEach((l) => {
- const c = new l(o, u.subUnitId, a.objectID), d = c.subType, h = a.actions.find((m) => m.action === d);
- (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed);
- });
- }), this._rangeProtectionRuleModel.changeRuleInitState(!0);
- });
- };
- await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((e) => n(e))), this._rangeProtectionRuleModel.changeRuleInitState(!0);
- }
- _initRangePermissionChange() {
- this.disposeWithMe(
- this._rangeProtectionRuleModel.ruleChange$.subscribe((n) => {
- n.type !== "delete" ? this._authzIoService.allowed({
- objectID: n.rule.permissionId,
- unitID: n.unitId,
- objectType: D.SelectRange,
- actions: it
- }).then((e) => {
- Ie().forEach((t) => {
- if (n.type === "set") {
- const { rule: a, oldRule: u } = n;
- if (a.permissionId === (u == null ? void 0 : u.permissionId))
- return;
- }
- const o = n.rule, s = new t(o.unitId, o.subUnitId, o.permissionId), r = s.subType, i = e.find((a) => a.action === r);
- i && this._permissionService.updatePermissionPoint(s.id, i.allowed);
- }), this._rangeProtectionRuleModel.ruleRefresh(n.rule.permissionId);
- }) : this._rangeProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId), [...ke()].forEach((t) => {
- const o = new t(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(o.id, o.value);
- }));
- })
- );
- }
- async initWorkbookPermissionChange(n) {
- var t;
- const e = n || ((t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET)) == null ? void 0 : t.getUnitId());
- e && this._authzIoService.allowed({
- objectID: e,
- objectType: D.Workbook,
- unitID: e,
- actions: fl
- }).then((o) => {
- en().forEach((s) => {
- const r = new s(e), i = r.subType, a = o.find((u) => u.action === i);
- a && this._permissionService.updatePermissionPoint(r.id, a.allowed);
- });
- });
- }
- async _initWorkbookPermissionFromSnapshot() {
- await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((n) => this.initWorkbookPermissionChange(n.getUnitId())));
- }
- _initWorksheetPermissionChange() {
- this.disposeWithMe(
- this._worksheetProtectionRuleModel.ruleChange$.subscribe((n) => {
- n.type !== "delete" ? this._authzIoService.allowed({
- objectID: n.rule.permissionId,
- unitID: n.unitId,
- objectType: D.Worksheet,
- actions: it
- }).then((e) => {
- we().forEach((t) => {
- const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s);
- r && this._permissionService.updatePermissionPoint(o.id, r.allowed);
- }), this._worksheetProtectionRuleModel.ruleRefresh(n.rule.permissionId);
- }) : ([...we(), ...ke()].forEach((e) => {
- const t = new e(n.unitId, n.subUnitId);
- this._permissionService.updatePermissionPoint(t.id, !0);
- }), this._worksheetProtectionPointRuleModel.deleteRule(n.unitId, n.subUnitId));
- })
- );
- }
- _initWorksheetPermissionPointsChange() {
- this.disposeWithMe(
- this._worksheetProtectionPointRuleModel.pointChange$.subscribe((n) => {
- this._authzIoService.allowed({
- objectID: n.permissionId,
- unitID: n.unitId,
- objectType: D.Worksheet,
- actions: eo
- }).then((e) => {
- ke().forEach((t) => {
- const o = new t(n.unitId, n.subUnitId), s = o.subType, r = e.find((i) => i.action === s);
- r && this._permissionService.updatePermissionPoint(o.id, r.allowed);
- });
- });
- })
- );
- }
- async _initWorksheetPermissionFromSnapshot() {
- const n = async (e) => {
- const t = [], o = e.getUnitId(), s = e.getSheets(), r = /* @__PURE__ */ new Map();
- if (s.forEach((i) => {
- const a = i.getSheetId(), u = this._worksheetProtectionRuleModel.getRule(o, a);
- u && (r.set(u.permissionId, u), t.push({
- objectID: u.permissionId,
- unitID: o,
- objectType: D.Worksheet,
- actions: it
- }));
- const l = this._worksheetProtectionPointRuleModel.getRule(o, a);
- l && (r.set(l.permissionId, l), t.push({
- objectID: l.permissionId,
- unitID: o,
- objectType: D.Worksheet,
- actions: eo
- }));
- }), !t.length) {
- this._worksheetProtectionRuleModel.changeRuleInitState(!0);
- return;
- }
- this._authzIoService.batchAllowed(t).then((i) => {
- i.forEach((a) => {
- const u = r.get(a.objectID);
- u && [...we(), ...ke()].forEach((l) => {
- const c = new l(o, u.subUnitId), d = c.subType, h = a.actions.find((m) => m.action === d);
- (h == null ? void 0 : h.allowed) !== void 0 && this._permissionService.updatePermissionPoint(c.id, h.allowed);
- });
- }), this._worksheetProtectionRuleModel.changeRuleInitState(!0);
- });
- };
- await Promise.all(this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).map((e) => n(e))), this._worksheetProtectionRuleModel.changeRuleInitState(!0);
- }
- _initUserChange() {
- this.disposeWithMe(
- // When the user changes, the permission points are updated. The first modification needs to be filtered here because it is a Behavior type, but in fact the user information is ready when this controller is initialized.
- this._userManagerService.currentUser$.pipe(Ts(1)).subscribe(() => {
- const n = this._permissionService.getAllPermissionPoint();
- this._permissionService.clearPermissionMap(), this._worksheetProtectionRuleModel.changeRuleInitState(!1), this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((t) => {
- const o = t.getUnitId();
- en().forEach((s) => {
- let r = new s(o);
- n.has(r.id) && (r = n.get(r.id)), this._permissionService.addPermissionPoint(r);
- }), t.getSheets().forEach((s) => {
- const r = s.getSheetId();
- [...we(), ...ke()].forEach((a) => {
- let u = new a(o, r);
- n.has(u.id) && (u = n.get(u.id)), this._permissionService.addPermissionPoint(u);
- }), this._rangeProtectionRuleModel.getSubunitRuleList(o, r).forEach((a) => {
- Ie().forEach((u) => {
- let l = new u(o, r, a.permissionId);
- n.has(l.id) && (l = n.get(l.id)), this._permissionService.addPermissionPoint(l);
- });
- });
- }), this._initWorkbookPermissionFromSnapshot(), this._initWorksheetPermissionFromSnapshot(), this._initRangePermissionFromSnapshot();
- });
- })
- );
- }
- refreshPermission(n, e) {
- const t = this._worksheetProtectionRuleModel.getTargetByPermissionId(n, e);
- let o = !1;
- if (t) {
- const [i, a] = t;
- this._authzIoService.allowed({
- objectID: e,
- unitID: n,
- objectType: D.Worksheet,
- actions: it
- }).then((u) => {
- let l = "";
- we().forEach((c) => {
- var g;
- const d = new c(n, a), h = d.subType, m = u.find((f) => f.action === h);
- 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}`);
- }), this._worksheetProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n);
- });
- }
- const s = this._worksheetProtectionPointRuleModel.getTargetByPermissionId(n, e);
- if (s) {
- const [i, a] = s;
- this._authzIoService.allowed({
- objectID: e,
- unitID: n,
- objectType: D.Worksheet,
- actions: eo
- }).then((u) => {
- ke().forEach((l) => {
- var m;
- const c = new l(n, a), d = c.subType, h = u.find((g) => g.action === d);
- h && (((m = this._permissionService.getPermissionPoint(c.id)) == null ? void 0 : m.value) !== h.allowed && (o = !0), this._permissionService.updatePermissionPoint(c.id, h.allowed));
- }), o && this._undoRedoService.clearUndoRedo(n);
- });
- }
- const r = this._rangeProtectionRuleModel.getTargetByPermissionId(n, e);
- if (r) {
- const [i, a] = r;
- this._authzIoService.allowed({
- objectID: e,
- unitID: n,
- objectType: D.SelectRange,
- actions: it
- }).then((u) => {
- let l = "";
- Ie().forEach((c) => {
- var g;
- const d = new c(n, a, e), h = d.subType, m = u.find((f) => f.action === h);
- 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}`);
- }), this._rangeProtectionRuleModel.ruleRefresh(`${e}_${l}`), o && this._undoRedoService.clearUndoRedo(n);
- });
- }
- }
- _refreshPermissionByCollaCreate() {
- this.disposeWithMe(
- this._commandService.onCommandExecuted((n, e) => {
- if (e != null && e.fromCollab && (n.id === Ne.id || n.id === ct.id || n.id === Ao.id)) {
- const t = n.params;
- this._undoRedoService.clearUndoRedo(t.unitId);
- }
- })
- );
- }
- };
- On = zc([
- Ee(0, M),
- Ee(1, Fe),
- Ee(2, vi),
- Ee(3, L(de)),
- Ee(4, L(Ye)),
- Ee(5, L(Ii)),
- Ee(6, L(un)),
- Ee(7, L(V)),
- Ee(8, L(W)),
- Ee(9, L(E)),
- Ee(10, L(ht))
- ], On);
- var Kc = Object.defineProperty, Jc = Object.getOwnPropertyDescriptor, Yc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? Jc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Kc(e, t, s), s;
- }, hn = (n, e) => (t, o) => e(t, o, n);
- let Dn = class extends ae {
- constructor(n, e, t, o) {
- super(), this._permissionService = n, this._worksheetProtectionRuleModel = e, this._sheetInterceptorService = t, this._rangeProtectionCache = o, this._initViewModelByRangeInterceptor(), this._initViewModelBySheetInterceptor();
- }
- _initViewModelByRangeInterceptor() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(
- et.CELL_CONTENT,
- {
- // permissions are placed at a high level to prioritize whether to filter subsequent renderings.
- priority: 999,
- effect: me.Value | me.Style,
- handler: (n = {}, e, t) => {
- const { unitId: o, subUnitId: s, row: r, col: i } = e, a = this._rangeProtectionCache.getCellInfo(o, s, r, i);
- if (a) {
- const u = a[_.View] === !1, l = { ...n, selectionProtection: [a] };
- return u ? (delete l.s, delete l.v, delete l.p, l) : t(l);
- }
- return t(n);
- }
- }
- ));
- }
- _initViewModelBySheetInterceptor() {
- this.disposeWithMe(this._sheetInterceptorService.intercept(
- et.CELL_CONTENT,
- {
- // permissions are placed at a high level to prioritize whether to filter subsequent renderings.
- priority: 999,
- effect: me.Value | me.Style,
- handler: (n = {}, e, t) => {
- var i, a, u, l, c;
- const { unitId: o, subUnitId: s } = e, r = this._worksheetProtectionRuleModel.getRule(o, s);
- if (r != null && r.permissionId) {
- const d = [{
- [_.View]: (a = (i = this._permissionService.getPermissionPoint(new Hn(o, s).id)) == null ? void 0 : i.value) != null ? a : !1,
- [_.Edit]: (l = (u = this._permissionService.getPermissionPoint(new Te(o, s).id)) == null ? void 0 : u.value) != null ? l : !1
- }], h = !((c = d[0]) != null && c[_.View]), m = { ...n, hasWorksheetRule: !0, selectionProtection: d };
- return h ? (delete m.s, delete m.v, delete m.p, m) : t(m);
- }
- return t(n);
- }
- }
- ));
- }
- };
- Dn = Yc([
- hn(0, Fe),
- hn(1, L(Ye)),
- hn(2, L(V)),
- hn(3, L(ht))
- ], Dn);
- var Xc = Object.defineProperty, qc = Object.getOwnPropertyDescriptor, Zc = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? qc(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Xc(e, t, s), s;
- }, cs = (n, e) => (t, o) => e(t, o, n);
- let tn = class {
- constructor(n, e) {
- R(this, "_cache", new Mi(1e4));
- this._selectionProtectionRuleModel = n, this._permissionService = e, this._init();
- }
- _init() {
- this._permissionService.permissionPointUpdate$.pipe(
- Fo((n) => n.type === D.SelectRange),
- Fo((n) => Ie().some((e) => n instanceof e)),
- Ki((n) => n)
- ).subscribe((n) => {
- const e = this._selectionProtectionRuleModel.getSubunitRuleList(n.unitId, n.subUnitId);
- for (const t of e)
- t.permissionId === n.permissionId && t.ranges.forEach((o) => {
- K.foreach(o, (s, r) => {
- const i = this._createKey(n.unitId, n.subUnitId, s, r);
- this._cache.delete(i);
- });
- });
- }), this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => {
- var e;
- n.rule.ranges.forEach((t) => {
- K.foreach(t, (o, s) => {
- const r = this._createKey(n.unitId, n.subUnitId, o, s);
- this._cache.delete(r);
- });
- }), n.type === "set" && ((e = n.oldRule) == null || e.ranges.forEach((t) => {
- K.foreach(t, (o, s) => {
- const r = this._createKey(n.unitId, n.subUnitId, o, s);
- this._cache.delete(r);
- });
- }));
- });
- }
- _createKey(n, e, t, o) {
- return `${n}_${e}_${t}_${o}`;
- }
- getCellInfo(n, e, t, o) {
- const s = this._selectionProtectionRuleModel.getSubunitRuleList(n, e), r = [];
- if (!s || !s.length)
- return r;
- const i = this._createKey(n, e, t, o), a = this._cache.get(i);
- if (a)
- return a;
- const u = [];
- for (const l of s)
- if (l.ranges.some((c) => c.startRow <= t && c.endRow >= t && c.startColumn <= o && c.endColumn >= o)) {
- const c = Ie().reduce((d, h) => {
- var f;
- const m = new h(n, e, l.permissionId), g = this._permissionService.getPermissionPoint(m.id);
- return d[m.subType] = (f = g == null ? void 0 : g.value) != null ? f : m.value, d;
- }, {});
- u.push({ ...c, ruleId: l.id, ranges: l.ranges });
- }
- return this._cache.set(i, u), u;
- }
- clear() {
- this._cache.clear();
- }
- };
- tn = Zc([
- cs(0, L(de)),
- cs(1, L(Fe))
- ], tn);
- const ds = fo("univer.exclusive-range-service");
- class Qc extends ae {
- constructor() {
- super(...arguments);
- /**
- * Exclusive range data structure is as follows: unitId -> sheetId -> feature -> range
- */
- R(this, "_exclusiveRanges", /* @__PURE__ */ new Map());
- R(this, "_exclusiveRangesChange$", new Le());
- R(this, "exclusiveRangesChange$", this._exclusiveRangesChange$.asObservable());
- }
- _ensureUnitMap(t) {
- return this._exclusiveRanges.has(t) || this._exclusiveRanges.set(t, /* @__PURE__ */ new Map()), this._exclusiveRanges.get(t);
- }
- _ensureSubunitMap(t, o) {
- const s = this._ensureUnitMap(t);
- return s.has(o) || s.set(o, /* @__PURE__ */ new Map()), s.get(o);
- }
- _ensureFeature(t, o, s) {
- const r = this._ensureSubunitMap(t, o);
- return r.has(s) || r.set(s, []), r.get(s);
- }
- addExclusiveRange(t, o, s, r) {
- const i = this._ensureFeature(t, o, s);
- i.push(...r), this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: i.map((a) => a.range) });
- }
- getExclusiveRanges(t, o, s) {
- var r, i;
- return (i = (r = this._exclusiveRanges.get(t)) == null ? void 0 : r.get(o)) == null ? void 0 : i.get(s);
- }
- clearExclusiveRanges(t, o, s) {
- const r = this.getExclusiveRanges(t, o, s);
- this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (r == null ? void 0 : r.map((i) => i.range)) || [] }), this._ensureFeature(t, o, s), this._exclusiveRanges.get(t).get(o).set(s, []);
- }
- clearExclusiveRangesByGroupId(t, o, s, r) {
- const i = this.getExclusiveRanges(t, o, s);
- this._exclusiveRangesChange$.next({ unitId: t, subUnitId: o, ranges: (i == null ? void 0 : i.map((u) => u.range)) || [] });
- const a = this.getExclusiveRanges(t, o, s);
- if (a) {
- const u = a.filter((l) => l.groupId !== r);
- this._exclusiveRanges.get(t).get(o).set(s, u);
- }
- }
- getInterestGroupId(t) {
- const o = [];
- return t.forEach((s) => {
- var l;
- const r = s.range, { unitId: i, sheetId: a } = r;
- if (!i || !a) return;
- const u = (l = this._exclusiveRanges.get(i)) == null ? void 0 : l.get(a);
- if (u)
- for (const c of u.keys()) {
- const d = u.get(c);
- if (d) {
- for (const h of d)
- if (k.intersects(r, h.range)) {
- o.push(c);
- break;
- }
- }
- }
- }), o;
- }
- }
- var ed = Object.defineProperty, td = Object.getOwnPropertyDescriptor, nd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? td(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && ed(e, t, s), s;
- }, oo = (n, e) => (t, o) => e(t, o, n);
- let co = class extends ae {
- constructor(n, e, t) {
- super(), this._resourceManagerService = n, this._univerInstanceService = e, this._logService = t;
- }
- getValue(n, e, t, o) {
- const s = this._univerInstanceService.getUniverSheetInstance(n);
- if (!s)
- return;
- const r = s == null ? void 0 : s.getSheetBySheetId(e);
- if (!r)
- return;
- const i = s.getStyles(), a = r.getCellRaw(t, o);
- if (a != null && a.s) {
- const u = i.get(a.s);
- if (u != null && u.n)
- return u.n;
- }
- return null;
- }
- deleteValues(n, e, t) {
- const o = this._univerInstanceService.getUniverSheetInstance(n);
- if (!o)
- return;
- const s = o == null ? void 0 : o.getSheetBySheetId(e);
- if (!s)
- return;
- const r = o.getStyles();
- t.forEach((i) => {
- K.foreach(i, (a, u) => {
- const l = s.getCellRaw(a, u);
- if (!l)
- return;
- const c = l == null ? void 0 : l.s, h = { ...c && r.get(c) || {} };
- delete h.n;
- const m = r.setValue(h);
- l.s = m;
- });
- });
- }
- setValues(n, e, t) {
- const o = this._univerInstanceService.getUniverSheetInstance(n);
- if (!o)
- return;
- const s = o == null ? void 0 : o.getSheetBySheetId(e);
- if (!s)
- return;
- const r = o.getStyles(), i = s.getCellMatrix();
- t.forEach((a) => {
- a.ranges.forEach((u) => {
- K.foreach(u, (l, c) => {
- const d = s.getCellRaw(l, c);
- if (d) {
- const m = { ...r.getStyleByCell(d) || {}, n: { pattern: a.pattern } }, g = r.setValue(m);
- d.s = g, a.pattern === ks && (d.t = se.STRING);
- } else {
- const h = { n: { pattern: a.pattern } }, m = r.setValue(h);
- m && i.setValue(l, c, { s: m });
- }
- });
- });
- });
- }
- };
- co = nd([
- oo(0, nn),
- oo(1, M),
- oo(2, Es)
- ], co);
- var od = Object.defineProperty, sd = Object.getOwnPropertyDescriptor, rd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? sd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && od(e, t, s), s;
- }, Qe = (n, e) => (t, o) => e(t, o, n);
- const hs = [je.id, qe.id, De.id, Be.id], ms = [ot.id, st.id];
- let An = class extends ae {
- constructor(e, t, o, s, r, i, a, u) {
- super();
- R(this, "disposableCollection", new jt());
- this._selectionProtectionRuleModel = e, this._univerInstanceService = t, this._commandService = o, this._refRangeService = s, this._selectionProtectionRenderModel = r, this._rangeProtectionCache = i, this._sheetInterceptorService = a, this._rangeProtectionRuleModel = u, this._onRefRangeChange(), this._correctPermissionRange(), this._initReBuildCache(), this._initRemoveSheet();
- }
- _onRefRangeChange() {
- const e = (o, s) => {
- const r = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!r || !(r == null ? void 0 : r.getSheetBySheetId(s)))
- return;
- this.disposableCollection.dispose();
- const a = (l) => this.refRangeHandle(l, o, s);
- this._selectionProtectionRuleModel.getSubunitRuleList(o, s).reduce((l, c) => [...l, ...c.ranges], []).forEach((l) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(l, a, o, s));
- });
- };
- this.disposeWithMe(
- this._commandService.onCommandExecuted((o) => {
- if (o.id === Ar.id) {
- const s = o.params, r = s.subUnitId, i = s.unitId;
- if (!r || !i)
- return;
- e(i, r);
- }
- if (o.id === he.id || o.id === Ne.id) {
- const s = o.params, r = s.subUnitId, i = s.unitId;
- if (!r || !i)
- return;
- e(i, r);
- }
- })
- );
- const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
- if (t) {
- const o = t.getActiveSheet();
- if (!o) return;
- e(t.getUnitId(), o.getSheetId());
- }
- }
- refRangeHandle(e, t, o) {
- switch (e.id) {
- case Fn.id:
- return this._getRefRangeMutationsByMoveRows(e.params, t, o);
- case jn.id:
- return this._getRefRangeMutationsByMoveCols(e.params, t, o);
- case mt.id:
- return this._getRefRangeMutationsByInsertRows(e.params, t, o);
- case gt.id:
- return this._getRefRangeMutationsByInsertCols(e.params, t, o);
- case zn.id:
- return this._getRefRangeMutationsByDeleteCols(e.params, t, o);
- case Gn.id:
- return this._getRefRangeMutationsByDeleteRows(e.params, t, o);
- }
- return { redos: [], undos: [] };
- }
- _getRefRangeMutationsByDeleteCols(e, t, o) {
- const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => k.intersects(a, e.range))), r = e.range;
- if (s.length) {
- const i = [], a = [];
- return s.forEach((u) => {
- const l = O.deepClone(u), c = l.ranges.reduce((d, h) => {
- if (k.intersects(h, r)) {
- const m = O.deepClone(h), { startColumn: g, endColumn: f } = r;
- if (g <= m.startColumn && f >= m.endColumn)
- return d;
- 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);
- }
- return d;
- }, []);
- l.ranges = c, l.ranges.length ? (i.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: u.id } }), a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: u, ruleId: u.id } })) : (i.push({ id: ze.id, params: { unitId: t, subUnitId: o, ruleIds: [u.id] } }), a.push({ id: Ne.id, params: { unitId: t, subUnitId: o, name: "", rules: [u] } }));
- }), { redos: i, undos: a };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByDeleteRows(e, t, o) {
- const s = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((i) => i.ranges.some((a) => k.intersects(a, e.range))), r = e.range;
- if (s.length) {
- const i = [], a = [];
- return s.forEach((u) => {
- const l = O.deepClone(u), c = l.ranges.reduce((d, h) => {
- if (k.intersects(h, r)) {
- const m = O.deepClone(h), { startRow: g, endRow: f } = r;
- if (g <= m.startRow && f >= m.endRow)
- return d;
- 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);
- }
- return d;
- }, []);
- l.ranges = c, i.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: u.id } }), a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: u, ruleId: u.id } });
- }), { redos: i, undos: a };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByInsertCols(e, t, o) {
- const s = e.range.startColumn, r = e.range.endColumn - e.range.startColumn + 1, i = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((a) => a.ranges.some((u) => s > u.startColumn && s <= u.endColumn));
- if (i.length) {
- const a = [], u = [];
- return i.forEach((l) => {
- const c = O.deepClone(l);
- let d = !1;
- c.ranges.forEach((h) => {
- s > h.startColumn && s <= h.endColumn && (h.endColumn += r, d = !0);
- }), d && (a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: l.id } }), u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: l.id } }));
- }), { redos: a, undos: u };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByInsertRows(e, t, o) {
- const s = e.range.startRow, r = e.range.endRow - e.range.startRow + 1, i = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((a) => a.ranges.some((u) => s > u.startRow && s <= u.endRow));
- if (i.length) {
- const a = [], u = [];
- return i.forEach((l) => {
- const c = O.deepClone(l);
- let d = !1;
- c.ranges.forEach((h) => {
- s > h.startRow && s <= h.endRow && (h.endRow += r, d = !0);
- }), d && (a.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: c, ruleId: l.id } }), u.push({ id: he.id, params: { unitId: t, subUnitId: o, rule: l, ruleId: l.id } }));
- }), { redos: a, undos: u };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByMoveRows(e, t, o) {
- const s = e.toRange, r = s.startRow, i = s.endRow - s.startRow + 1, a = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((u) => u.ranges.some((l) => r > l.startRow && r <= l.endRow));
- if (a.length) {
- const u = [], l = [];
- return a.forEach((c) => {
- const d = O.deepClone(c), m = e.fromRange.startRow;
- let g = !1;
- d.ranges.forEach((f) => {
- r > f.startRow && r <= f.endRow && (m < f.startRow && (f.startRow = f.startRow - i, f.endRow = f.endRow - i), f.endRow += i, g = !0);
- }), 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 } }));
- }), { redos: u, undos: l };
- }
- return { undos: [], redos: [] };
- }
- _getRefRangeMutationsByMoveCols(e, t, o) {
- const s = e.toRange, r = s.startColumn, i = s.endColumn - s.startColumn + 1, a = this._selectionProtectionRuleModel.getSubunitRuleList(t, o).filter((u) => u.ranges.some((l) => r > l.startColumn && r <= l.endColumn));
- if (a.length) {
- const u = [], l = [];
- return a.forEach((c) => {
- const d = O.deepClone(c), m = e.fromRange.startColumn;
- let g = !1;
- d.ranges.forEach((f) => {
- r > f.startColumn && r <= f.endColumn && (m < f.startColumn && (f.startColumn = f.startColumn - i, f.endColumn = f.endColumn - i), f.endColumn += i, g = !0);
- }), 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 } }));
- }), { redos: u, undos: l };
- }
- return { undos: [], redos: [] };
- }
- _correctPermissionRange() {
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
- if (ms.includes(e.id)) {
- if (!e.params) return;
- const t = this._univerInstanceService.getCurrentUnitForType(B.UNIVER_SHEET);
- if (!t) return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o) return;
- const { sourceRange: s, targetRange: r } = e.params, i = s.startColumn === r.startColumn && s.endColumn === r.endColumn, a = i ? s.endRow - s.startRow + 1 : s.endColumn - s.startColumn + 1, u = i ? s.startRow : s.startColumn, l = i ? r.startRow : r.startColumn;
- this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((f) => {
- f.ranges.forEach((C) => {
- let { startRow: S, endRow: I, startColumn: w, endColumn: b } = C;
- 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);
- });
- }), this.disposableCollection.dispose();
- const { unitId: d, subUnitId: h } = e.params, m = (f) => this.refRangeHandle(f, d, h);
- this._selectionProtectionRuleModel.getSubunitRuleList(d, h).reduce((f, p) => [...f, ...p.ranges], []).forEach((f) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(f, m, d, h));
- }), this._selectionProtectionRenderModel.clear();
- }
- if (hs.includes(e.id)) {
- const t = this._univerInstanceService.getUniverSheetInstance(e.params.unitId);
- if (!t) return;
- const o = t.getSheetBySheetId(e.params.subUnitId);
- if (!o) return;
- const s = e.params;
- if (!s) return;
- const { range: r } = s, i = e.id.includes("row"), a = e.id.includes("insert"), u = i ? r.startRow : r.startColumn, l = i ? r.endRow : r.endColumn, c = l - u + 1;
- this._selectionProtectionRuleModel.getSubunitRuleList(t.getUnitId(), o.getSheetId()).forEach((p) => {
- p.ranges.forEach((S) => {
- let { startRow: I, endRow: w, startColumn: b, endColumn: y } = S;
- a ? i ? u <= I && (I += c, w += c) : u <= b && (b += c, y += c) : i ? l < I && (I -= c, w -= c) : l < b && (b -= c, y -= c), this._checkIsRightRange({ startRow: I, endRow: w, startColumn: b, endColumn: y }) && (S.startColumn = b, S.endColumn = y, S.startRow = I, S.endRow = w);
- });
- }), this.disposableCollection.dispose();
- const { unitId: h, subUnitId: m } = e.params, g = (p) => this.refRangeHandle(p, h, m);
- this._selectionProtectionRuleModel.getSubunitRuleList(h, m).reduce((p, C) => [...p, ...C.ranges], []).forEach((p) => {
- this.disposableCollection.add(this._refRangeService.registerRefRange(p, g, h, m));
- }), this._selectionProtectionRenderModel.clear();
- }
- }));
- }
- _checkIsRightRange(e) {
- return e.startRow <= e.endRow && e.startColumn <= e.endColumn;
- }
- _initReBuildCache() {
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
- if (hs.includes(e.id) || ms.includes(e.id)) {
- const { unitId: t, subUnitId: o } = e.params;
- this._rangeProtectionCache.reBuildCache(t, o);
- }
- }));
- }
- _initRemoveSheet() {
- this._sheetInterceptorService.interceptCommand(
- {
- getMutations: (e) => {
- const t = [], o = [], s = [], r = [];
- if (e.id === ko.id) {
- const i = e.params, a = [], u = [];
- this._rangeProtectionRuleModel.getSubunitRuleList(i.unitId, i.subUnitId).forEach((l) => {
- a.push(l.id), u.push(l);
- }), a.length && u.length && (s.push({ id: ze.id, params: { unitId: i.unitId, subUnitId: i.subUnitId, ruleIds: a } }), t.push({ id: Ne.id, params: { unitId: i.unitId, subUnitId: i.subUnitId, name: "", rules: u } }));
- }
- return {
- redos: o,
- undos: t,
- preRedos: s,
- preUndos: r
- };
- }
- }
- );
- }
- };
- An = rd([
- Qe(0, L(de)),
- Qe(1, L(M)),
- Qe(2, E),
- Qe(3, L(_t)),
- Qe(4, L(tn)),
- Qe(5, L(ht)),
- Qe(6, L(V)),
- Qe(7, L(de))
- ], An);
- var id = Object.defineProperty, ad = Object.getOwnPropertyDescriptor, ud = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? ad(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && id(e, t, s), s;
- }, Dt = (n, e) => (t, o) => e(t, o, n);
- const ld = "SHEET_RANGE_PROTECTION_PLUGIN";
- let xn = class extends ae {
- constructor(n, e, t, o, s) {
- super(), this._selectionProtectionRuleModel = n, this._permissionService = e, this._resourceManagerService = t, this._selectionProtectionCache = o, this._univerInstanceService = s, this._initSnapshot(), this._initRuleChange();
- }
- _initRuleChange() {
- this.disposeWithMe(
- this._selectionProtectionRuleModel.ruleChange$.subscribe((n) => {
- switch (n.type) {
- case "add": {
- Ie().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId, n.rule.permissionId);
- this._permissionService.addPermissionPoint(t);
- });
- break;
- }
- case "delete": {
- Ie().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId, n.rule.permissionId);
- this._permissionService.deletePermissionPoint(t.id);
- });
- break;
- }
- case "set": {
- n.oldRule.permissionId !== n.rule.permissionId && Ie().forEach((e) => {
- const t = new e(n.unitId, n.subUnitId, n.oldRule.permissionId);
- this._permissionService.deletePermissionPoint(t.id);
- const o = new e(n.unitId, n.subUnitId, n.rule.permissionId);
- this._permissionService.addPermissionPoint(o);
- });
- break;
- }
- }
- })
- );
- }
- _initSnapshot() {
- const n = (t) => {
- const s = this._selectionProtectionRuleModel.toObject()[t];
- return s ? JSON.stringify(s) : "";
- }, e = (t) => {
- if (!t)
- return {};
- try {
- return JSON.parse(t);
- } catch {
- return {};
- }
- };
- this.disposeWithMe(
- this._resourceManagerService.registerPluginResource({
- toJson: n,
- parseJson: e,
- pluginName: ld,
- businesses: [Sn.UNIVER_SHEET],
- onLoad: (t, o) => {
- const s = this._selectionProtectionRuleModel.toObject();
- s[t] = o, this._selectionProtectionRuleModel.fromObject(s);
- const r = [];
- Object.keys(o).forEach((i) => {
- const a = o[i];
- this._selectionProtectionRuleModel.getSubunitRuleList(t, i).forEach((u) => {
- r.push({
- objectID: u.permissionId,
- unitID: t,
- objectType: D.SelectRange,
- actions: it
- });
- }), a.forEach((u) => {
- Ie().forEach((l) => {
- const c = new l(t, i, u.permissionId);
- c.value = !1, this._permissionService.addPermissionPoint(c);
- });
- }), this._selectionProtectionCache.reBuildCache(t, i);
- });
- },
- onUnLoad: (t) => {
- this._selectionProtectionCache.deleteUnit(t);
- }
- })
- );
- }
- };
- xn = ud([
- Dt(0, L(de)),
- Dt(1, L(Fe)),
- Dt(2, L(nn)),
- Dt(3, L(ht)),
- Dt(4, L(M))
- ], xn);
- var cd = Object.defineProperty, dd = Object.getOwnPropertyDescriptor, hd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? dd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && cd(e, t, s), s;
- }, At = (n, e) => (t, o) => e(t, o, n);
- let $n = class extends ae {
- constructor(n, e, t, o, s) {
- super(), this._permissionService = n, this._univerInstanceService = e, this._rangeProtectionRuleModel = t, this._worksheetProtectionRuleModel = o, this._worksheetProtectionPointModel = s, this._init();
- }
- _init() {
- const n = (e) => {
- const t = e.getUnitId();
- en().forEach((o) => {
- const s = new o(t);
- this._permissionService.addPermissionPoint(s);
- });
- };
- this._univerInstanceService.getAllUnitsForType(B.UNIVER_SHEET).forEach((e) => {
- n(e);
- }), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(B.UNIVER_SHEET).subscribe((e) => {
- n(e);
- })), this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(B.UNIVER_SHEET).subscribe((e) => {
- const t = e.getUnitId();
- e.getSheets().forEach((o) => {
- const s = o.getSheetId();
- this._rangeProtectionRuleModel.getSubunitRuleList(t, s).forEach((i) => {
- [...Ie()].forEach((a) => {
- const u = new a(t, s, i.permissionId);
- this._permissionService.deletePermissionPoint(u.id);
- });
- }), [...we(), ...ke()].forEach((i) => {
- const a = new i(t, s);
- this._permissionService.deletePermissionPoint(a.id);
- });
- }), en().forEach((o) => {
- const s = new o(t);
- this._permissionService.deletePermissionPoint(s.id);
- }), this._rangeProtectionRuleModel.deleteUnitModel(t), this._worksheetProtectionPointModel.deleteUnitModel(t), this._worksheetProtectionRuleModel.deleteUnitModel(t);
- }));
- }
- };
- $n = hd([
- At(0, L(Fe)),
- At(1, L(M)),
- At(2, L(de)),
- At(3, L(Ye)),
- At(4, L(un))
- ], $n);
- var md = Object.defineProperty, gd = Object.getOwnPropertyDescriptor, fd = (n, e, t, o) => {
- for (var s = o > 1 ? void 0 : o ? gd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && md(e, t, s), s;
- }, Rd = (n, e) => (t, o) => e(t, o, n);
- let ho = class extends ae {
- constructor(n) {
- super(), this._sheetRangeThemeModel = n;
- }
- /**
- * Register a custom range theme style.
- * @param {string} unitId Which unit to register the range theme style.
- * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register.
- */
- registerRangeTheme(n, e) {
- this._sheetRangeThemeModel.registerRangeThemeStyle(n, e);
- }
- /**
- * Get custom register themes name list
- * @returns {string[]} The list of custom register themes name.
- */
- getALLRegisterThemes() {
- return this._sheetRangeThemeModel.getALLRegisteredTheme();
- }
- /**
- * Register range theme style to the range.
- * @param {string} themeName The defined theme name.
- * @param {IRangeThemeRangeInfo} rangeInfo The range info to apply the theme style.
- */
- registerRangeThemeStyle(n, e) {
- this._sheetRangeThemeModel.registerRangeThemeRule(n, e);
- }
- /**
- * Get applied range theme style name.
- * @param {IRangeThemeRangeInfo} rangeInfo The range info to get the applied theme style.
- * @returns {string | undefined} The applied theme style name or not exist.
- */
- getAppliedRangeThemeStyle(n) {
- return this._sheetRangeThemeModel.getRegisteredRangeThemeStyle(n);
- }
- /**
- * Get registered build-in range theme style
- */
- getRegisteredRangeThemes() {
- return this._sheetRangeThemeModel.getRegisteredRangeThemes();
- }
- };
- ho = fd([
- Rd(0, L(He))
- ], ho);
- 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) => {
- for (var s = o > 1 ? void 0 : o ? pd(e, t) : e, r = n.length - 1, i; r >= 0; r--)
- (i = n[r]) && (s = (o ? i(e, t, s) : i(s)) || s);
- return o && s && Qr(e, t, s), s;
- }, gs = (n, e) => (t, o) => e(t, o, n), ei = (n, e, t) => Cd(n, typeof e != "symbol" ? e + "" : e, t);
- const wd = "SHEET_PLUGIN";
- let Wn = class extends bi {
- constructor(n = ts, e, t) {
- super(), this._config = n, this._injector = e, this._configService = t;
- const { ...o } = yi(
- {},
- ts,
- this._config
- );
- this._configService.setConfig(Kl, o), this._initConfig(), this._initDependencies();
- }
- _initConfig() {
- var n, e, t;
- (n = this._config) != null && n.onlyRegisterFormulaRelatedMutations && this._configService.setConfig(Kr, !0), (e = this._config) != null && e.isRowStylePrecedeColumnStyle && this._configService.setConfig(Ei, !0), (t = this._config) != null && t.autoHeightForMergedCells && this._configService.setConfig(Ui, !0);
- }
- _initDependencies() {
- var e;
- const n = [
- // services
- [kt],
- [F],
- [_t],
- [$n],
- [wt, { useClass: co }],
- [V],
- [ho],
- // controllers
- [yn],
- [Tn],
- [kn],
- [Un],
- // permission
- [bn],
- [Ye],
- [un],
- [Dn],
- [On],
- [Nn],
- // range theme
- [He],
- // range protection
- [tn],
- [de],
- [ht],
- [An],
- [xn],
- [ds, {
- useClass: Qc,
- deps: [F]
- }]
- ];
- (e = this._config) != null && e.notExecuteFormula || n.push([En]), Pi(this._injector, Ti(n, this._config.override)), ln(this._injector, [
- [V],
- [xn],
- [ds]
- ]);
- }
- onStarting() {
- ln(this._injector, [
- [yn],
- [Tn],
- [$n],
- [bn],
- [Dn]
- ]);
- }
- onRendered() {
- ln(this._injector, [
- [wt],
- [On]
- ]);
- }
- onReady() {
- ln(this._injector, [
- [En],
- [Un],
- [He],
- [kn],
- [tn],
- [An],
- [_t],
- [Nn]
- ]);
- }
- };
- ei(Wn, "pluginName", wd);
- ei(Wn, "type", B.UNIVER_SHEET);
- Wn = Sd([
- _i(Bi),
- gs(1, L(Ro)),
- gs(2, Us)
- ], Wn);
- 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 || {});
- const gh = [
- nt.id,
- Oe.id,
- Br.id,
- tt.id,
- an.id,
- ot.id,
- st.id,
- Xt.id,
- qt.id,
- Qt.id,
- Zt.id,
- je.id,
- qe.id,
- De.id,
- Be.id,
- Ft.id,
- Vt.id
- ], fh = [
- Q.id,
- dt.id,
- oe.id,
- ne.id,
- In.id,
- Bt.id,
- Ht.id,
- Lt.id,
- zt.id,
- Kt.id
- ];
- function Rh(n) {
- switch (n.id) {
- case "sheet.mutation.set-range-values": {
- const e = n.params;
- return e.cellValue ? [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: new G(e.cellValue).getDataRange()
- }] : [];
- }
- case "sheet.mutation.move-range": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.from.subUnitId,
- range: new G(e.from.value).getRange()
- }, {
- unitId: e.unitId,
- subUnitId: e.to.subUnitId,
- range: new G(e.to.value).getRange()
- }];
- }
- case "sheet.mutation.remove-worksheet-merge": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: t
- }));
- }
- case "sheet.mutation.add-worksheet-merge": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: t
- }));
- }
- case "sheet.mutation.reorder-range": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- }];
- }
- case "sheet.mutation.set-worksheet-default-style": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: { startRow: 0, endRow: Number.MAX_SAFE_INTEGER, startColumn: 0, endColumn: Number.MAX_SAFE_INTEGER }
- }];
- }
- case "sheet.mutation.set-row-data": {
- const e = n.params, t = Object.keys(e.rowData).map(Number);
- return t.length === 0 ? [] : [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- startRow: Math.min(...t),
- endRow: Math.max(...t),
- startColumn: 0,
- endColumn: Number.MAX_SAFE_INTEGER
- }
- }];
- }
- case "sheet.mutation.set-col-data": {
- const e = n.params, t = Object.keys(e.columnData).map(Number);
- return t.length === 0 ? [] : [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- startRow: 0,
- endRow: Number.MAX_SAFE_INTEGER,
- startColumn: Math.min(...t),
- endColumn: Math.max(...t)
- }
- }];
- }
- case "sheet.mutation.set-worksheet-range-theme-style":
- case "sheet.mutation.delete-worksheet-range-theme-style": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.range
- }];
- }
- default:
- return [];
- }
- }
- function ph(n) {
- switch (n.id) {
- case "sheet.mutation.set-worksheet-row-height":
- case "sheet.mutation.set-worksheet-row-is-auto-height":
- case "sheet.mutation.set-worksheet-row-auto-height": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: H.ROW
- }
- }));
- }
- case "sheet.mutation.set-worksheet-col-width": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: H.COLUMN
- }
- }));
- }
- case "sheet.mutation.move-rows":
- case "sheet.mutation.move-columns": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.targetRange
- }, {
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: e.sourceRange
- }];
- }
- case "sheet.mutation.set-col-hidden":
- case "sheet.mutation.set-col-visible": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: H.COLUMN
- }
- }));
- }
- case "sheet.mutation.set-row-hidden":
- case "sheet.mutation.set-row-visible": {
- const e = n.params;
- return e.ranges.map((t) => ({
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...t,
- rangeType: H.ROW
- }
- }));
- }
- case "sheet.mutation.insert-col": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: H.COLUMN
- }
- }];
- }
- case "sheet.mutation.insert-row": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: H.ROW
- }
- }];
- }
- case "sheet.mutation.remove-col": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: H.COLUMN
- }
- }];
- }
- case "sheet.mutation.remove-row": {
- const e = n.params;
- return [{
- unitId: e.unitId,
- subUnitId: e.subUnitId,
- range: {
- ...e.range,
- rangeType: H.ROW
- }
- }];
- }
- case "sheet.mutation.toggle-gridlines":
- case "sheet.mutation.set-gridlines-color":
- return [];
- default:
- return [];
- }
- }
- const Ch = 1.5, Sh = "rgba(255, 255, 255, 0.01)";
- function wh(n) {
- const { rangeWithCoord: e, primaryWithCoord: t, style: o } = n, s = {
- range: {
- startRow: e.startRow,
- startColumn: e.startColumn,
- endRow: e.endRow,
- endColumn: e.endColumn,
- rangeType: e.rangeType,
- unitId: e.unitId,
- sheetId: e.sheetId
- },
- primary: null,
- style: o
- };
- return t != null && (s.primary = Md(t)), s;
- }
- function Md(n) {
- const { actualRow: e, actualColumn: t, isMerged: o, isMergedMainCell: s } = n, { startRow: r, startColumn: i, endRow: a, endColumn: u } = n.mergeInfo;
- return {
- actualRow: e,
- actualColumn: t,
- isMerged: o,
- isMergedMainCell: s,
- startRow: r,
- startColumn: i,
- endRow: a,
- endColumn: u
- };
- }
- const Ih = (n, e, t) => {
- const s = n.get(F).getCurrentSelections(), { value: r, selections: i, unitId: a, subUnitId: u } = e;
- if (s) {
- const c = s[(s == null ? void 0 : s.length) - 1].primary;
- if (c) {
- const { actualColumn: d, actualRow: h } = c;
- let { startRow: m, startColumn: g, endRow: f, endColumn: p } = i[i.length - 1];
- if (r === ge.COLUMNS) {
- const w = t.find((b) => b.startColumn === d && b.endColumn === d && h === b.startRow);
- w && (p = w.endColumn, m = w.startRow, f = w.endRow);
- } else if (r === ge.ROWS) {
- const w = t.find((b) => b.startRow === h && b.endRow === h && d === b.startColumn);
- w && (f = w.endRow, g = w.startColumn, p = w.endColumn);
- }
- const C = {
- startRow: m,
- startColumn: g,
- endRow: f,
- endColumn: p,
- actualRow: h,
- actualColumn: d,
- isMerged: !0,
- isMergedMainCell: m === h && g === d
- }, S = s.map((w, b, y) => ({
- range: w.range,
- style: null,
- primary: b === y.length - 1 ? C : null
- })), I = {
- unitId: a,
- subUnitId: u,
- type: Ce.ONLY_SET,
- selections: S
- };
- return {
- id: re.id,
- params: I
- };
- }
- return null;
- }
- return null;
- }, vh = (n, e) => {
- const o = n.get(F).getCurrentSelections(), { unitId: s, subUnitId: r } = e;
- if (o && o[(o == null ? void 0 : o.length) - 1].primary) {
- const u = {
- unitId: s,
- subUnitId: r,
- type: Ce.ONLY_SET,
- selections: [...o]
- };
- return {
- id: re.id,
- params: u
- };
- }
- return null;
- };
- function fs(n) {
- return n == null ? !1 : n.v !== void 0 && n.v !== null && n.v !== "" || n.p !== void 0;
- }
- function Yn(n, e) {
- return n && n.spanAnchor ? fs(e.getValue(n.spanAnchor.startRow, n.spanAnchor.startColumn)) : fs(n);
- }
- function _d(n, e, t, o, s) {
- const r = n.getCellMatrix(), i = n.getSpanModel().getMergedCellRange(e, t, o, s), a = new G();
- return r.forValue((u, l) => {
- const c = r.getValue(u, l);
- c && a.setValue(u, l, c);
- }), i.forEach((u) => {
- const { startColumn: l, startRow: c, endColumn: d, endRow: h } = u;
- ki(c, h, l, d).forEach((m, g) => {
- m === c && g === l && a.setValue(m, g, {
- ...r.getValue(m, g),
- spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d }
- }), (m !== c || g !== l) && (a.realDeleteValue(m, g), a.setValue(m, g, {
- spanAnchor: { startRow: c, endRow: h, startColumn: l, endColumn: d }
- }));
- });
- }), a;
- }
- function bd(n, e, t, o) {
- const { startRow: s, startColumn: r, endRow: i } = n;
- let a = null, u = !1;
- for (let l = s; l <= i; l++) {
- const c = e.getValue(l, r - t);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.startColumn = n.startColumn - t, {
- spanAnchor: a,
- hasValue: !0,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: !1,
- range: n
- };
- }
- function yd(n, e, t, o) {
- const { startRow: s, endColumn: r, endRow: i } = n;
- let a = null, u = !1;
- for (let l = s; l <= i; l++) {
- const c = e.getValue(l, r + t);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.endColumn = n.endColumn + t, {
- spanAnchor: a,
- hasValue: !0,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: !1,
- range: n
- };
- }
- function Ed(n, e, t, o) {
- const { startRow: s, startColumn: r, endColumn: i } = n;
- let a = null, u = !1;
- for (let l = r; l <= i; l++) {
- const c = e.getValue(s - t, l);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.startRow = n.startRow - t, {
- spanAnchor: a,
- hasValue: !0,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: !1,
- range: n
- };
- }
- function Ud(n, e, t, o) {
- const { startColumn: s, endColumn: r, endRow: i } = n;
- let a = null, u = !1;
- for (let l = s; l <= r; l++) {
- const c = e.getValue(i + t, l);
- if (u = u || Yn(c, e), !o && u)
- break;
- c && c.spanAnchor && (a ? a = {
- startRow: Math.min(c.spanAnchor.startRow, a.startRow),
- startColumn: Math.min(c.spanAnchor.startColumn, a.startColumn),
- endRow: Math.max(c.spanAnchor.endRow, a.endRow),
- endColumn: Math.max(c.spanAnchor.endColumn, a.endColumn)
- } : a = {
- startRow: c.spanAnchor.startRow,
- startColumn: c.spanAnchor.startColumn,
- endRow: c.spanAnchor.endRow,
- endColumn: c.spanAnchor.endColumn
- });
- }
- return u ? (n.endRow = n.endRow + t, {
- spanAnchor: a,
- hasValue: !0,
- range: n
- }) : {
- spanAnchor: null,
- hasValue: !1,
- range: n
- };
- }
- function Mh(n, e, t) {
- const o = t.getMaxRows(), s = t.getMaxColumns(), r = _d(t, 0, 0, o - 1, s - 1), i = t.getSnapshot().mergeData.length > 0, { left: a, right: u, up: l, down: c } = e;
- let d = !0, h = { ...n };
- const m = [];
- for (; d; ) {
- if (d = !1, l && h.startRow !== 0) {
- const { hasValue: g, range: f, spanAnchor: p } = Ed(h, r, 1, i);
- if (p && m.push(p), g) {
- h = f, d = !0;
- continue;
- }
- }
- if (c && h.endRow !== o - 1) {
- const { hasValue: g, range: f, spanAnchor: p } = Ud(h, r, 1, i);
- if (p && m.push(p), g) {
- h = f, d = !0;
- continue;
- }
- }
- if (a && h.startColumn !== 0) {
- const { hasValue: g, range: f, spanAnchor: p } = bd(h, r, 1, i);
- if (p && m.push(p), g) {
- h = f, d = !0;
- continue;
- }
- }
- if (u && h.endColumn !== s - 1) {
- const { hasValue: g, range: f, spanAnchor: p } = yd(h, r, 1, i);
- if (p && m.push(p), g) {
- h = f, d = !0;
- continue;
- }
- }
- }
- return m.length > 0 && (h = k.union(h, ...m)), h;
- }
- const ti = (n, e, t, o = 1, s = !0, r = !0) => {
- const i = K.transformRange(n, e), { startRow: a, endRow: u } = i;
- let l = t.startRow - o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- for (; !e.getRowVisible(l) || !d; )
- l--, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- if (l >= a)
- return { ...t, startRow: l, endRow: l };
- if (r) {
- const h = { ...t, startRow: u, endRow: u };
- return oi(n, e, h, o, s, !1);
- }
- }, ni = (n, e, t, o = 1, s = !0, r = !0) => {
- const i = K.transformRange(n, e), { startRow: a, endRow: u } = i;
- let l = t.endRow + o, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- for (; !e.getRowVisible(l) || !d; )
- l++, c = e.getMergedCell(l, t.startColumn), d = !c || c.startRow === l && c.startColumn === t.startColumn;
- if (l <= u)
- return { ...t, startRow: l, endRow: l };
- if (r) {
- const h = { ...t, startRow: a, endRow: a };
- return si(n, e, h, o, s, !1);
- }
- }, oi = (n, e, t, o = 1, s = !0, r = !0) => {
- const i = K.transformRange(n, e), { startColumn: a, endColumn: u } = i;
- let l = t.startColumn - o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- for (; !e.getColVisible(l) || !d; )
- l--, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- if (l >= a)
- return { ...t, startColumn: l, endColumn: l };
- if (r) {
- const h = { ...t, startColumn: u, endColumn: u };
- return ti(n, e, h, o, s, !1);
- }
- }, si = (n, e, t, o = 1, s = !0, r = !0) => {
- const i = K.transformRange(n, e), { startColumn: a, endColumn: u } = i;
- let l = t.endColumn + o, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- for (; !e.getColVisible(l) || !d; )
- l++, c = e.getMergedCell(t.startRow, l), d = !c || c.startRow === t.startRow && c.startColumn === l;
- if (l <= u)
- return { ...t, endColumn: l, startColumn: l };
- if (r) {
- const h = { ...t, startColumn: a, endColumn: a };
- return ni(n, e, h, o, s, !1);
- }
- };
- function mn(n, e, t) {
- let o = null;
- return t.getMatrixWithMergedCells(n, e, n, e).forValue((r, i, a) => (o = {
- actualRow: r,
- actualColumn: i,
- startRow: r,
- startColumn: i,
- isMerged: a.rowSpan !== void 0 || a.colSpan !== void 0,
- isMergedMainCell: a.rowSpan !== void 0 && a.colSpan !== void 0,
- endRow: r + (a.rowSpan !== void 0 ? a.rowSpan - 1 : 0),
- endColumn: i + (a.colSpan !== void 0 ? a.colSpan - 1 : 0),
- rangeType: H.NORMAL
- }, !1)), o || {
- actualColumn: e,
- actualRow: n,
- startRow: n,
- startColumn: e,
- endRow: n,
- endColumn: e,
- isMerged: !1,
- isMergedMainCell: !1,
- rangeType: H.NORMAL
- };
- }
- const Pd = (n, e, t, o, s = 1) => {
- switch (o) {
- case pe.UP:
- return ti(n, e, t, s);
- case pe.DOWN:
- return ni(n, e, t, s);
- case pe.LEFT:
- return oi(n, e, t, s);
- case pe.RIGHT:
- return si(n, e, t, s);
- }
- }, _h = (n, e, t) => {
- let o, s = -1, r;
- for (let C = 0; C < n.length; C++)
- if (n[C].primary) {
- o = n[C], s = C, r = o.primary;
- break;
- }
- if (s === -1)
- return null;
- const i = e === 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];
- if (!o || !r)
- return null;
- 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;
- if (!k.equals(o.range, l)) {
- const C = g ? u.range : Pd(o.range, t, l, e);
- if (!C)
- return null;
- const S = f ? mn(C.endRow, C.endColumn, t) : mn(C.startRow, C.startColumn, t);
- return {
- startRow: S.startRow,
- startColumn: S.startColumn,
- endRow: S.endRow,
- endColumn: S.endColumn
- };
- }
- const p = f ? mn(u.range.endRow, u.range.endColumn, t) : mn(u.range.startRow, u.range.startColumn, t);
- return {
- startRow: p.startRow,
- startColumn: p.startColumn,
- endRow: p.endRow,
- endColumn: p.endColumn
- };
- }, bh = {
- WorkbookCommentPermission: Ws,
- WorkbookCopyPermission: Ls,
- WorkbookCreateProtectPermission: Vs,
- WorkbookCreateSheetPermission: Hs,
- WorkbookDeleteSheetPermission: Bs,
- WorkbookDuplicatePermission: Fs,
- WorkbookEditablePermission: Me,
- WorkbookExportPermission: js,
- WorkbookHideSheetPermission: vo,
- WorkbookHistoryPermission: tu,
- WorkbookManageCollaboratorPermission: Mo,
- WorkbookMoveSheetPermission: _o,
- WorkbookPrintPermission: Gs,
- WorkbookRecoverHistoryPermission: zs,
- WorkbookRenameSheetPermission: bo,
- WorkbookSharePermission: Ks,
- WorkbookViewHistoryPermission: Ys,
- WorkbookViewPermission: Js,
- WorksheetCopyPermission: Xs,
- WorksheetDeleteColumnPermission: qs,
- WorksheetDeleteProtectionPermission: Zs,
- WorksheetDeleteRowPermission: Qs,
- WorksheetEditExtraObjectPermission: er,
- WorksheetEditPermission: Te,
- WorksheetFilterPermission: tr,
- WorksheetInsertColumnPermission: nr,
- WorksheetInsertHyperlinkPermission: or,
- WorksheetInsertRowPermission: sr,
- WorksheetManageCollaboratorPermission: rr,
- WorksheetPivotTablePermission: ir,
- WorksheetSelectProtectedCellsPermission: nu,
- WorksheetSelectUnProtectedCellsPermission: ou,
- WorksheetSetCellStylePermission: ar,
- WorksheetSetCellValuePermission: wn,
- WorksheetSetColumnStylePermission: $t,
- WorksheetSetRowStylePermission: Wt,
- WorksheetSortPermission: ur,
- WorksheetViewPermission: Hn,
- RangeProtectionPermissionEditPoint: Pe,
- RangeProtectionPermissionViewPoint: Io
- }, yh = (n, e, t, o) => {
- const s = n.get(Fe), r = n.get(de), i = s.getPermissionPoint(new Me(e).id);
- if (!(i != null && i.value))
- return !1;
- const a = s.getPermissionPoint(new Te(e, t).id);
- if (!(a != null && a.value))
- return !1;
- const l = r.getSubunitRuleList(e, t).filter((c) => c.ranges.some((d) => o.some((h) => k.intersects(d, h))));
- return l.length ? l.every((c) => {
- const d = c.permissionId, h = s.getPermissionPoint(new Pe(e, t, d).id);
- return !!(h != null && h.value);
- }) : !0;
- };
- function Td(n, e) {
- return e.some((t) => kd(n, t));
- }
- function kd(n, e) {
- const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s);
- let a = !1;
- return i.forValue((u, l, c) => {
- if (c && (u !== t || l !== o) && n.cellHasValue(c))
- return a = !0, !1;
- }), a;
- }
- function Nd(n, e, t, o) {
- const s = [], r = [], i = t.getSheetId();
- return o.forEach((a) => {
- const u = Od(t, a), l = {
- unitId: e,
- subUnitId: i,
- cellValue: u.getData()
- }, c = Ae(
- n,
- l
- );
- s.push({ id: Q.id, params: c }), r.push({ id: Q.id, params: l });
- }), {
- undos: s,
- redos: r
- };
- }
- function Od(n, e) {
- const { startRow: t, startColumn: o, endColumn: s, endRow: r } = e, i = n.getMatrixWithMergedCells(t, o, r, s, Ni.Intercepted), a = new G();
- return i.forValue((u, l, c) => {
- c && (u !== t || l !== o) && a.setValue(u, l, null);
- }), a;
- }
- const Xn = {
- type: v.COMMAND,
- id: "sheet.command.add-worksheet-merge",
- handler: (n, e) => {
- 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 = {
- unitId: r,
- subUnitId: i,
- ranges: u
- }, g = {
- unitId: r,
- subUnitId: i,
- ranges: u
- };
- c.push({ id: oe.id, params: m }), c.push({ id: ne.id, params: g });
- const f = Se(n, m), p = Ue(n, g);
- if (d.push({ id: oe.id, params: p }), d.push({ id: ne.id, params: f }), h) {
- const S = Nd(n, r, l, u);
- c.unshift(...S.redos), d.push(...S.undos);
- }
- return z(c, t).result ? (o.pushUndoRedo({
- unitID: r,
- undoMutations: d,
- redoMutations: c
- }), !0) : !1;
- }
- }, Eh = {
- type: v.COMMAND,
- id: "sheet.command.add-worksheet-merge-all",
- handler: async (n) => {
- var l;
- const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
- if (!(o != null && o.length))
- return !1;
- const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
- if (!r) return !1;
- const i = r.getActiveSheet();
- if (!i) return !1;
- const a = r.getUnitId(), u = i.getSheetId();
- return e.executeCommand(Xn.id, {
- selections: o,
- unitId: a,
- subUnitId: u
- });
- }
- }, Uh = {
- type: v.COMMAND,
- id: "sheet.command.add-worksheet-merge-vertical",
- handler: async (n) => {
- var l;
- const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
- if (!(o != null && o.length))
- return !1;
- const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
- if (!r) return !1;
- const i = r.getActiveSheet();
- if (!i) return !1;
- const a = r.getUnitId(), u = i.getSheetId();
- return e.executeCommand(Xn.id, {
- value: ge.COLUMNS,
- selections: o,
- unitId: a,
- subUnitId: u
- });
- }
- }, Ph = {
- type: v.COMMAND,
- id: "sheet.command.add-worksheet-merge-horizontal",
- handler: async (n) => {
- var l;
- const e = n.get(E), o = (l = n.get(F).getCurrentSelections()) == null ? void 0 : l.map((c) => c.range);
- if (!(o != null && o.length))
- return !1;
- const r = n.get(M).getCurrentUnitForType(B.UNIVER_SHEET);
- if (!r) return !1;
- const i = r.getActiveSheet();
- if (!i) return !1;
- const a = r.getUnitId(), u = i.getSheetId();
- return e.executeCommand(Xn.id, {
- value: ge.ROWS,
- selections: o,
- unitId: a,
- subUnitId: u
- });
- }
- };
- function Th(n, e, t, o, s) {
- const r = n.get(M), i = N(r, { unitId: e, subUnitId: t });
- if (!i) return;
- const { worksheet: a } = i;
- if (a.getMergeData().some((d) => o.some((h) => k.intersects(h, d))))
- throw new Error("The ranges to be merged overlap with the existing merged cells");
- n.get(E).executeCommand(Xn.id, {
- unitId: e,
- subUnitId: t,
- selections: o,
- defaultMerge: s
- });
- }
- const Dd = (n, e) => {
- const r = n.get(M).getUniverSheetInstance(e.unitId).getSheetBySheetId(e.subUnitId).getConfig().rightToLeft;
- return {
- ...O.deepClone(e),
- rightToLeft: r
- };
- }, so = {
- id: "sheet.mutation.set-worksheet-right-to-left",
- type: v.MUTATION,
- handler: (n, e) => {
- const t = n.get(M).getUniverSheetInstance(e.unitId);
- if (!t) return !1;
- const o = t.getSheetBySheetId(e.subUnitId);
- if (!o) return !1;
- const s = o.getConfig();
- return s.rightToLeft = e.rightToLeft, !0;
- }
- }, kh = {
- type: v.COMMAND,
- id: "sheet.command.set-worksheet-right-to-left",
- handler: async (n, e) => {
- var d;
- const t = n.get(E), o = n.get(W), s = N(n.get(M), e);
- if (!s) return !1;
- const { unitId: r, subUnitId: i } = s;
- let a = te.FALSE;
- e && (a = (d = e.rightToLeft) != null ? d : te.FALSE);
- const u = {
- rightToLeft: a,
- unitId: r,
- subUnitId: i
- }, l = Dd(
- n,
- u
- );
- return t.syncExecuteCommand(
- so.id,
- u
- ) ? (o.pushUndoRedo({
- unitID: r,
- undoMutations: [{ id: so.id, params: l }],
- redoMutations: [
- { id: so.id, params: u }
- ]
- }), !0) : !1;
- }
- };
- export {
- qn as AFTER_CELL_EDIT,
- Zn as AFTER_CELL_EDIT_ASYNC,
- Ih as AddMergeRedoSelectionsOperationFactory,
- Ue as AddMergeUndoMutationFactory,
- vh as AddMergeUndoSelectionsOperationFactory,
- Xi as AddRangeProtectionCommand,
- Ne as AddRangeProtectionMutation,
- Eh as AddWorksheetMergeAllCommand,
- Xn as AddWorksheetMergeCommand,
- Ph as AddWorksheetMergeHorizontalCommand,
- ne as AddWorksheetMergeMutation,
- Uh as AddWorksheetMergeVerticalCommand,
- qi as AddWorksheetProtectionCommand,
- ct as AddWorksheetProtectionMutation,
- Go as BEFORE_CELL_EDIT,
- kt as BorderStyleManagerService,
- gh as COMMAND_LISTENER_SKELETON_CHANGE,
- fh as COMMAND_LISTENER_VALUE_CHANGE,
- Fu as CancelFrozenCommand,
- po as ClearSelectionAllCommand,
- Co as ClearSelectionContentCommand,
- So as ClearSelectionFormatCommand,
- xs as CopySheetCommand,
- jd as DISABLE_NORMAL_SELECTIONS,
- Un as DefinedNameDataController,
- Pt as DeleteRangeMoveLeftCommand,
- Tt as DeleteRangeMoveUpCommand,
- su as DeleteRangeProtectionCommand,
- ze as DeleteRangeProtectionMutation,
- ru as DeleteWorksheetProtectionCommand,
- St as DeleteWorksheetProtectionMutation,
- iu as DeleteWorksheetRangeThemeStyleCommand,
- Kt as DeleteWorksheetRangeThemeStyleMutation,
- _a as DeleteWorksheetRangeThemeStyleMutationFactory,
- Oo as DeltaColumnWidthCommand,
- $o as DeltaRowHeightCommand,
- Yi as EditStateEnum,
- $ as EffectRefRangId,
- Dl as EmptyMutation,
- Qc as ExclusiveRangeService,
- Fd as FactoryAddRangeProtectionMutation,
- Bd as FactoryDeleteRangeProtectionMutation,
- qd as FactorySetRangeProtectionMutation,
- ds as IExclusiveRangeService,
- et as INTERCEPTOR_POINT,
- wt as INumfmtService,
- Xa as IRefSelectionsService,
- gu as InsertColAfterCommand,
- mu as InsertColBeforeCommand,
- pr as InsertColByRangeCommand,
- gt as InsertColCommand,
- je as InsertColMutation,
- yo as InsertColMutationUndoFactory,
- au as InsertDefinedNameCommand,
- sn as InsertRangeMoveDownCommand,
- Bn as InsertRangeMoveRightCommand,
- hu as InsertRowAfterCommand,
- du as InsertRowBeforeCommand,
- fr as InsertRowByRangeCommand,
- mt as InsertRowCommand,
- qe as InsertRowMutation,
- mr as InsertRowMutationUndoFactory,
- fu as InsertSheetCommand,
- Jt as InsertSheetMutation,
- As as InsertSheetUndoMutationFactory,
- ea as InterceptCellContentPriority,
- Ll as MAX_CELL_PER_SHEET_KEY,
- Oc as MERGE_CELL_INTERCEPTOR_CHECK,
- Tn as MergeCellController,
- jn as MoveColsCommand,
- st as MoveColsMutation,
- pu as MoveColsMutationUndoFactory,
- pt as MoveRangeCommand,
- dt as MoveRangeMutation,
- Fn as MoveRowsCommand,
- ot as MoveRowsMutation,
- Ru as MoveRowsMutationUndoFactory,
- co as NumfmtService,
- q as OperatorType,
- bh as PermissionPointsDefinitions,
- Aa as REF_SELECTIONS_ENABLED,
- ah as RangeMergeUtil,
- ht as RangeProtectionCache,
- Lr as RangeProtectionPermissionDeleteProtectionPoint,
- Pe as RangeProtectionPermissionEditPoint,
- Vr as RangeProtectionPermissionManageCollaPoint,
- Io as RangeProtectionPermissionViewPoint,
- An as RangeProtectionRefRangeService,
- tn as RangeProtectionRenderModel,
- de as RangeProtectionRuleModel,
- xn as RangeProtectionService,
- yt as RangeThemeStyle,
- _t as RefRangeService,
- qo as RefSelectionsService,
- wu as RegisterWorksheetRangeThemeStyleCommand,
- Yt as RegisterWorksheetRangeThemeStyleMutation,
- Mr as RemoveColByRangeCommand,
- zn as RemoveColCommand,
- De as RemoveColMutation,
- Ir as RemoveDefinedNameCommand,
- Se as RemoveMergeUndoMutationFactory,
- zr as RemoveNumfmtMutation,
- vr as RemoveRowByRangeCommand,
- Gn as RemoveRowCommand,
- Be as RemoveRowMutation,
- ko as RemoveSheetCommand,
- Ut as RemoveSheetMutation,
- ja as RemoveSheetUndoMutationFactory,
- Iu as RemoveWorksheetMergeCommand,
- oe as RemoveWorksheetMergeMutation,
- uo as ReorderRangeCommand,
- In as ReorderRangeMutation,
- Mu as ReorderRangeUndoMutationFactory,
- tl as ResetBackgroundColorCommand,
- Qu as ResetTextColorCommand,
- ch as SCOPE_WORKBOOK_VALUE_DEFINED_NAME,
- Gd as SELECTIONS_ENABLED,
- Sh as SELECTION_CONTROL_BORDER_BUFFER_COLOR,
- Ch as SELECTION_CONTROL_BORDER_BUFFER_WIDTH,
- Wl as ScrollToCellOperation,
- Ce as SelectionMoveType,
- el as SetBackgroundColorCommand,
- Zd as SetBoldCommand,
- Ou as SetBorderBasicCommand,
- Nu as SetBorderColorCommand,
- rn as SetBorderCommand,
- Tu as SetBorderPositionCommand,
- ku as SetBorderStyleCommand,
- $u as SetColDataCommand,
- Lt as SetColDataMutation,
- xu as SetColDataMutationFactory,
- yr as SetColHiddenCommand,
- Xt as SetColHiddenMutation,
- qt as SetColVisibleMutation,
- Mn as SetColWidthCommand,
- Ur as SetDefinedNameCommand,
- oh as SetFontFamilyCommand,
- sh as SetFontSizeCommand,
- Bu as SetFrozenCommand,
- ut as SetFrozenMutation,
- Pr as SetFrozenMutationFactory,
- ju as SetGridlinesColorCommand,
- Vt as SetGridlinesColorMutation,
- ol as SetHorizontalTextAlignCommand,
- Qd as SetItalicCommand,
- Vo as SetNumfmtMutation,
- nh as SetOverlineCommand,
- Gu as SetProtectionCommand,
- he as SetRangeProtectionMutation,
- on as SetRangeValuesCommand,
- Q as SetRangeValuesMutation,
- Ae as SetRangeValuesUndoMutationFactory,
- Ku as SetRowDataCommand,
- Ht as SetRowDataMutation,
- zu as SetRowDataMutationFactory,
- Wo as SetRowHeightCommand,
- kr as SetRowHiddenCommand,
- Qt as SetRowHiddenMutation,
- Zt as SetRowVisibleMutation,
- br as SetSelectedColsVisibleCommand,
- Tr as SetSelectedRowsVisibleCommand,
- re as SetSelectionsOperation,
- Kn as SetSpecificColsVisibleCommand,
- Jn as SetSpecificRowsVisibleCommand,
- th as SetStrikeThroughCommand,
- fe as SetStyleCommand,
- al as SetTabColorCommand,
- fn as SetTabColorMutation,
- Zu as SetTextColorCommand,
- rl as SetTextRotationCommand,
- sl as SetTextWrapCommand,
- eh as SetUnderlineCommand,
- nl as SetVerticalTextAlignCommand,
- Dr as SetWorkbookNameCommand,
- Or as SetWorkbookNameMutation,
- Ar as SetWorksheetActivateCommand,
- an as SetWorksheetActiveOperation,
- tt as SetWorksheetColWidthMutation,
- xr as SetWorksheetColWidthMutationFactory,
- dl as SetWorksheetDefaultStyleCommand,
- Bt as SetWorksheetDefaultStyleMutation,
- cl as SetWorksheetDefaultStyleMutationFactory,
- hl as SetWorksheetHideCommand,
- lt as SetWorksheetHideMutation,
- Do as SetWorksheetNameCommand,
- _n as SetWorksheetNameMutation,
- Wr as SetWorksheetOrderCommand,
- Rn as SetWorksheetOrderMutation,
- Il as SetWorksheetPermissionPointsCommand,
- Ao as SetWorksheetPermissionPointsMutation,
- vl as SetWorksheetProtectionCommand,
- Ct as SetWorksheetProtectionMutation,
- ba as SetWorksheetRangeThemeStyleCommand,
- zt as SetWorksheetRangeThemeStyleMutation,
- Ma as SetWorksheetRangeThemeStyleMutationFactory,
- kh as SetWorksheetRightToLeftCommand,
- so as SetWorksheetRightToLeftMutation,
- Br as SetWorksheetRowAutoHeightMutation,
- ih as SetWorksheetRowAutoHeightMutationFactory,
- nt as SetWorksheetRowHeightMutation,
- Lo as SetWorksheetRowIsAutoHeightCommand,
- Oe as SetWorksheetRowIsAutoHeightMutation,
- Fr as SetWorksheetShowCommand,
- V as SheetInterceptorService,
- Nn as SheetPermissionCheckController,
- On as SheetPermissionInitController,
- ho as SheetRangeThemeService,
- Id as SheetSkeletonChangeType,
- vd as SheetValueChangeType,
- F as SheetsSelectionsService,
- Tl as SplitTextToColumnsCommand,
- kl as ToggleCellCheckboxCommand,
- Nl as ToggleGridlinesCommand,
- Ft as ToggleGridlinesMutation,
- _ as UnitAction,
- D as UnitObject,
- Wn as UniverSheetsPlugin,
- Ol as UnregisterWorksheetRangeThemeStyleCommand,
- Uo as UnregisterWorksheetRangeThemeStyleMutation,
- Ji as ViewStateEnum,
- Ws as WorkbookCommentPermission,
- Ls as WorkbookCopyPermission,
- eu as WorkbookCopySheetPermission,
- Vs as WorkbookCreateProtectPermission,
- Hs as WorkbookCreateSheetPermission,
- Bs as WorkbookDeleteSheetPermission,
- Fs as WorkbookDuplicatePermission,
- Me as WorkbookEditablePermission,
- js as WorkbookExportPermission,
- vo as WorkbookHideSheetPermission,
- tu as WorkbookHistoryPermission,
- Mo as WorkbookManageCollaboratorPermission,
- _o as WorkbookMoveSheetPermission,
- $n as WorkbookPermissionService,
- Gs as WorkbookPrintPermission,
- zs as WorkbookRecoverHistoryPermission,
- bo as WorkbookRenameSheetPermission,
- Ta as WorkbookSelectionModel,
- Ks as WorkbookSharePermission,
- Ys as WorkbookViewHistoryPermission,
- Js as WorkbookViewPermission,
- Xs as WorksheetCopyPermission,
- qs as WorksheetDeleteColumnPermission,
- Zs as WorksheetDeleteProtectionPermission,
- Qs as WorksheetDeleteRowPermission,
- er as WorksheetEditExtraObjectPermission,
- Te as WorksheetEditPermission,
- tr as WorksheetFilterPermission,
- nr as WorksheetInsertColumnPermission,
- or as WorksheetInsertHyperlinkPermission,
- sr as WorksheetInsertRowPermission,
- rr as WorksheetManageCollaboratorPermission,
- bn as WorksheetPermissionService,
- ir as WorksheetPivotTablePermission,
- un as WorksheetProtectionPointModel,
- Ye as WorksheetProtectionRuleModel,
- nu as WorksheetSelectProtectedCellsPermission,
- ou as WorksheetSelectUnProtectedCellsPermission,
- ar as WorksheetSetCellStylePermission,
- wn as WorksheetSetCellValuePermission,
- $t as WorksheetSetColumnStylePermission,
- Wt as WorksheetSetRowStylePermission,
- ur as WorksheetSortPermission,
- Hn as WorksheetViewPermission,
- Th as addMergeCellsUtil,
- Sc as adjustRangeOnMutation,
- Ln as alignToMergedCellsBorders,
- it as baseProtectionActions,
- yh as checkRangesEditablePermission,
- Md as convertPrimaryWithCoordToPrimary,
- wh as convertSelectionDataToRange,
- Vn as copyRangeStyles,
- xl as createTopMatrixFromMatrix,
- Al as createTopMatrixFromRanges,
- fl as defaultWorkbookPermissionPoints,
- eo as defaultWorksheetPermissionPoint,
- Mh as expandToContinuousRange,
- lh as factoryRemoveNumfmtUndoMutation,
- uh as factorySetNumfmtUndoMutation,
- jr as findAllRectangle,
- Xe as followSelectionOperation,
- Os as generateNullCell,
- Ua as generateNullCellValue,
- Zr as getAddMergeMutationRangeByType,
- Ie as getAllRangePermissionPoint,
- en as getAllWorkbookPermissionPoint,
- we as getAllWorksheetPermissionPoint,
- ke as getAllWorksheetPermissionPointByPointPanel,
- zd as getCellAtRowCol,
- rh as getDefaultRangePermission,
- lr as getInsertRangeMutations,
- wo as getMoveRangeUndoRedoMutations,
- _h as getNextPrimaryCell,
- ve as getPrimaryForRange,
- cr as getRemoveRangeMutations,
- qa as getSelectionsService,
- mh as getSeparateEffectedRangesOnCommand,
- N as getSheetCommandTarget,
- va as getSheetCommandTargetWorkbook,
- Et as getSheetMutationTarget,
- ph as getSkeletonChangedEffectedRange,
- Rh as getValueChangedEffectedRange,
- vt as handleBaseInsertRange,
- Pn as handleBaseMoveRowsCols,
- It as handleBaseRemoveRange,
- ss as handleCommonDefaultRangeChangeWithEffectRefCommands,
- hh as handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests,
- os as handleDefaultRangeChangeWithEffectRefCommands,
- dh as handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests,
- hc as handleDeleteRangeMoveLeft,
- gc as handleDeleteRangeMoveUp,
- Xd as handleDeleteRangeMutation,
- Xr as handleIRemoveCol,
- oc as handleIRemoveRow,
- ac as handleInsertCol,
- uc as handleInsertRangeMoveDown,
- cc as handleInsertRangeMoveRight,
- Yd as handleInsertRangeMutation,
- ic as handleInsertRow,
- Yr as handleMoveCols,
- tc as handleMoveRange,
- Jr as handleMoveRows,
- Jd as isSingleCellSelection,
- Gr as rangeMerge,
- _e as rotateRange,
- Mt as runRefRangeMutations,
- Kd as setEndForRange,
- Pl as splitRangeText,
- lo as transformCellsToRange
- };
|