tinymce_plugins_table.js 411 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/table/plugin.js
  5. var require_plugin = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/table/plugin.js"() {
  7. (function() {
  8. "use strict";
  9. var typeOf = function(x) {
  10. var t = typeof x;
  11. if (x === null) {
  12. return "null";
  13. } else if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  14. return "array";
  15. } else if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  16. return "string";
  17. } else {
  18. return t;
  19. }
  20. };
  21. var isType$1 = function(type2) {
  22. return function(value2) {
  23. return typeOf(value2) === type2;
  24. };
  25. };
  26. var isSimpleType = function(type2) {
  27. return function(value2) {
  28. return typeof value2 === type2;
  29. };
  30. };
  31. var eq$2 = function(t) {
  32. return function(a) {
  33. return t === a;
  34. };
  35. };
  36. var isString = isType$1("string");
  37. var isObject = isType$1("object");
  38. var isArray = isType$1("array");
  39. var isNull = eq$2(null);
  40. var isBoolean = isSimpleType("boolean");
  41. var isUndefined = eq$2(void 0);
  42. var isNullable = function(a) {
  43. return a === null || a === void 0;
  44. };
  45. var isNonNullable = function(a) {
  46. return !isNullable(a);
  47. };
  48. var isFunction = isSimpleType("function");
  49. var isNumber = isSimpleType("number");
  50. var noop = function() {
  51. };
  52. var compose = function(fa, fb) {
  53. return function() {
  54. var args = [];
  55. for (var _i = 0; _i < arguments.length; _i++) {
  56. args[_i] = arguments[_i];
  57. }
  58. return fa(fb.apply(null, args));
  59. };
  60. };
  61. var compose1 = function(fbc, fab) {
  62. return function(a) {
  63. return fbc(fab(a));
  64. };
  65. };
  66. var constant = function(value2) {
  67. return function() {
  68. return value2;
  69. };
  70. };
  71. var identity = function(x) {
  72. return x;
  73. };
  74. var tripleEquals = function(a, b) {
  75. return a === b;
  76. };
  77. function curry(fn) {
  78. var initialArgs = [];
  79. for (var _i = 1; _i < arguments.length; _i++) {
  80. initialArgs[_i - 1] = arguments[_i];
  81. }
  82. return function() {
  83. var restArgs = [];
  84. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  85. restArgs[_i2] = arguments[_i2];
  86. }
  87. var all2 = initialArgs.concat(restArgs);
  88. return fn.apply(null, all2);
  89. };
  90. }
  91. var not = function(f) {
  92. return function(t) {
  93. return !f(t);
  94. };
  95. };
  96. var die = function(msg) {
  97. return function() {
  98. throw new Error(msg);
  99. };
  100. };
  101. var never = constant(false);
  102. var always = constant(true);
  103. var none$2 = function() {
  104. return NONE;
  105. };
  106. var NONE = function() {
  107. var call = function(thunk) {
  108. return thunk();
  109. };
  110. var id = identity;
  111. var me = {
  112. fold: function(n, _s) {
  113. return n();
  114. },
  115. isSome: never,
  116. isNone: always,
  117. getOr: id,
  118. getOrThunk: call,
  119. getOrDie: function(msg) {
  120. throw new Error(msg || "error: getOrDie called on none.");
  121. },
  122. getOrNull: constant(null),
  123. getOrUndefined: constant(void 0),
  124. or: id,
  125. orThunk: call,
  126. map: none$2,
  127. each: noop,
  128. bind: none$2,
  129. exists: never,
  130. forall: always,
  131. filter: function() {
  132. return none$2();
  133. },
  134. toArray: function() {
  135. return [];
  136. },
  137. toString: constant("none()")
  138. };
  139. return me;
  140. }();
  141. var some = function(a) {
  142. var constant_a = constant(a);
  143. var self = function() {
  144. return me;
  145. };
  146. var bind2 = function(f) {
  147. return f(a);
  148. };
  149. var me = {
  150. fold: function(n, s) {
  151. return s(a);
  152. },
  153. isSome: always,
  154. isNone: never,
  155. getOr: constant_a,
  156. getOrThunk: constant_a,
  157. getOrDie: constant_a,
  158. getOrNull: constant_a,
  159. getOrUndefined: constant_a,
  160. or: self,
  161. orThunk: self,
  162. map: function(f) {
  163. return some(f(a));
  164. },
  165. each: function(f) {
  166. f(a);
  167. },
  168. bind: bind2,
  169. exists: bind2,
  170. forall: bind2,
  171. filter: function(f) {
  172. return f(a) ? me : NONE;
  173. },
  174. toArray: function() {
  175. return [a];
  176. },
  177. toString: function() {
  178. return "some(" + a + ")";
  179. }
  180. };
  181. return me;
  182. };
  183. var from$1 = function(value2) {
  184. return value2 === null || value2 === void 0 ? NONE : some(value2);
  185. };
  186. var Optional = {
  187. some,
  188. none: none$2,
  189. from: from$1
  190. };
  191. var nativeSlice = Array.prototype.slice;
  192. var nativeIndexOf = Array.prototype.indexOf;
  193. var nativePush = Array.prototype.push;
  194. var rawIndexOf = function(ts, t) {
  195. return nativeIndexOf.call(ts, t);
  196. };
  197. var contains$2 = function(xs, x) {
  198. return rawIndexOf(xs, x) > -1;
  199. };
  200. var exists = function(xs, pred) {
  201. for (var i = 0, len = xs.length; i < len; i++) {
  202. var x = xs[i];
  203. if (pred(x, i)) {
  204. return true;
  205. }
  206. }
  207. return false;
  208. };
  209. var range$1 = function(num, f) {
  210. var r2 = [];
  211. for (var i = 0; i < num; i++) {
  212. r2.push(f(i));
  213. }
  214. return r2;
  215. };
  216. var map$1 = function(xs, f) {
  217. var len = xs.length;
  218. var r2 = new Array(len);
  219. for (var i = 0; i < len; i++) {
  220. var x = xs[i];
  221. r2[i] = f(x, i);
  222. }
  223. return r2;
  224. };
  225. var each$2 = function(xs, f) {
  226. for (var i = 0, len = xs.length; i < len; i++) {
  227. var x = xs[i];
  228. f(x, i);
  229. }
  230. };
  231. var eachr = function(xs, f) {
  232. for (var i = xs.length - 1; i >= 0; i--) {
  233. var x = xs[i];
  234. f(x, i);
  235. }
  236. };
  237. var partition = function(xs, pred) {
  238. var pass = [];
  239. var fail = [];
  240. for (var i = 0, len = xs.length; i < len; i++) {
  241. var x = xs[i];
  242. var arr = pred(x, i) ? pass : fail;
  243. arr.push(x);
  244. }
  245. return {
  246. pass,
  247. fail
  248. };
  249. };
  250. var filter$2 = function(xs, pred) {
  251. var r2 = [];
  252. for (var i = 0, len = xs.length; i < len; i++) {
  253. var x = xs[i];
  254. if (pred(x, i)) {
  255. r2.push(x);
  256. }
  257. }
  258. return r2;
  259. };
  260. var foldr = function(xs, f, acc) {
  261. eachr(xs, function(x, i) {
  262. acc = f(acc, x, i);
  263. });
  264. return acc;
  265. };
  266. var foldl = function(xs, f, acc) {
  267. each$2(xs, function(x, i) {
  268. acc = f(acc, x, i);
  269. });
  270. return acc;
  271. };
  272. var findUntil = function(xs, pred, until) {
  273. for (var i = 0, len = xs.length; i < len; i++) {
  274. var x = xs[i];
  275. if (pred(x, i)) {
  276. return Optional.some(x);
  277. } else if (until(x, i)) {
  278. break;
  279. }
  280. }
  281. return Optional.none();
  282. };
  283. var find$1 = function(xs, pred) {
  284. return findUntil(xs, pred, never);
  285. };
  286. var findIndex = function(xs, pred) {
  287. for (var i = 0, len = xs.length; i < len; i++) {
  288. var x = xs[i];
  289. if (pred(x, i)) {
  290. return Optional.some(i);
  291. }
  292. }
  293. return Optional.none();
  294. };
  295. var flatten$1 = function(xs) {
  296. var r2 = [];
  297. for (var i = 0, len = xs.length; i < len; ++i) {
  298. if (!isArray(xs[i])) {
  299. throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
  300. }
  301. nativePush.apply(r2, xs[i]);
  302. }
  303. return r2;
  304. };
  305. var bind$2 = function(xs, f) {
  306. return flatten$1(map$1(xs, f));
  307. };
  308. var forall = function(xs, pred) {
  309. for (var i = 0, len = xs.length; i < len; ++i) {
  310. var x = xs[i];
  311. if (pred(x, i) !== true) {
  312. return false;
  313. }
  314. }
  315. return true;
  316. };
  317. var reverse = function(xs) {
  318. var r2 = nativeSlice.call(xs, 0);
  319. r2.reverse();
  320. return r2;
  321. };
  322. var mapToObject = function(xs, f) {
  323. var r2 = {};
  324. for (var i = 0, len = xs.length; i < len; i++) {
  325. var x = xs[i];
  326. r2[String(x)] = f(x, i);
  327. }
  328. return r2;
  329. };
  330. var pure = function(x) {
  331. return [x];
  332. };
  333. var sort$1 = function(xs, comparator) {
  334. var copy2 = nativeSlice.call(xs, 0);
  335. copy2.sort(comparator);
  336. return copy2;
  337. };
  338. var get$d = function(xs, i) {
  339. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  340. };
  341. var head = function(xs) {
  342. return get$d(xs, 0);
  343. };
  344. var last$2 = function(xs) {
  345. return get$d(xs, xs.length - 1);
  346. };
  347. var findMap = function(arr, f) {
  348. for (var i = 0; i < arr.length; i++) {
  349. var r2 = f(arr[i], i);
  350. if (r2.isSome()) {
  351. return r2;
  352. }
  353. }
  354. return Optional.none();
  355. };
  356. var __assign = function() {
  357. __assign = Object.assign || function __assign2(t) {
  358. for (var s, i = 1, n = arguments.length; i < n; i++) {
  359. s = arguments[i];
  360. for (var p in s)
  361. if (Object.prototype.hasOwnProperty.call(s, p))
  362. t[p] = s[p];
  363. }
  364. return t;
  365. };
  366. return __assign.apply(this, arguments);
  367. };
  368. function __spreadArray(to, from2, pack) {
  369. if (pack || arguments.length === 2)
  370. for (var i = 0, l = from2.length, ar; i < l; i++) {
  371. if (ar || !(i in from2)) {
  372. if (!ar)
  373. ar = Array.prototype.slice.call(from2, 0, i);
  374. ar[i] = from2[i];
  375. }
  376. }
  377. return to.concat(ar || Array.prototype.slice.call(from2));
  378. }
  379. var cached = function(f) {
  380. var called = false;
  381. var r2;
  382. return function() {
  383. var args = [];
  384. for (var _i = 0; _i < arguments.length; _i++) {
  385. args[_i] = arguments[_i];
  386. }
  387. if (!called) {
  388. called = true;
  389. r2 = f.apply(null, args);
  390. }
  391. return r2;
  392. };
  393. };
  394. var DeviceType = function(os, browser, userAgent, mediaMatch2) {
  395. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  396. var isiPhone = os.isiOS() && !isiPad;
  397. var isMobile = os.isiOS() || os.isAndroid();
  398. var isTouch = isMobile || mediaMatch2("(pointer:coarse)");
  399. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch2("(min-device-width:768px)");
  400. var isPhone = isiPhone || isMobile && !isTablet;
  401. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  402. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  403. return {
  404. isiPad: constant(isiPad),
  405. isiPhone: constant(isiPhone),
  406. isTablet: constant(isTablet),
  407. isPhone: constant(isPhone),
  408. isTouch: constant(isTouch),
  409. isAndroid: os.isAndroid,
  410. isiOS: os.isiOS,
  411. isWebView: constant(iOSwebview),
  412. isDesktop: constant(isDesktop)
  413. };
  414. };
  415. var firstMatch = function(regexes, s) {
  416. for (var i = 0; i < regexes.length; i++) {
  417. var x = regexes[i];
  418. if (x.test(s)) {
  419. return x;
  420. }
  421. }
  422. return void 0;
  423. };
  424. var find = function(regexes, agent) {
  425. var r2 = firstMatch(regexes, agent);
  426. if (!r2) {
  427. return {
  428. major: 0,
  429. minor: 0
  430. };
  431. }
  432. var group = function(i) {
  433. return Number(agent.replace(r2, "$" + i));
  434. };
  435. return nu$2(group(1), group(2));
  436. };
  437. var detect$6 = function(versionRegexes, agent) {
  438. var cleanedAgent = String(agent).toLowerCase();
  439. if (versionRegexes.length === 0) {
  440. return unknown$2();
  441. }
  442. return find(versionRegexes, cleanedAgent);
  443. };
  444. var unknown$2 = function() {
  445. return nu$2(0, 0);
  446. };
  447. var nu$2 = function(major, minor) {
  448. return {
  449. major,
  450. minor
  451. };
  452. };
  453. var Version = {
  454. nu: nu$2,
  455. detect: detect$6,
  456. unknown: unknown$2
  457. };
  458. var detectBrowser$1 = function(browsers2, userAgentData) {
  459. return findMap(userAgentData.brands, function(uaBrand) {
  460. var lcBrand = uaBrand.brand.toLowerCase();
  461. return find$1(browsers2, function(browser) {
  462. var _a;
  463. return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase());
  464. }).map(function(info) {
  465. return {
  466. current: info.name,
  467. version: Version.nu(parseInt(uaBrand.version, 10), 0)
  468. };
  469. });
  470. });
  471. };
  472. var detect$5 = function(candidates, userAgent) {
  473. var agent = String(userAgent).toLowerCase();
  474. return find$1(candidates, function(candidate) {
  475. return candidate.search(agent);
  476. });
  477. };
  478. var detectBrowser = function(browsers2, userAgent) {
  479. return detect$5(browsers2, userAgent).map(function(browser) {
  480. var version = Version.detect(browser.versionRegexes, userAgent);
  481. return {
  482. current: browser.name,
  483. version
  484. };
  485. });
  486. };
  487. var detectOs = function(oses2, userAgent) {
  488. return detect$5(oses2, userAgent).map(function(os) {
  489. var version = Version.detect(os.versionRegexes, userAgent);
  490. return {
  491. current: os.name,
  492. version
  493. };
  494. });
  495. };
  496. var removeFromStart = function(str, numChars) {
  497. return str.substring(numChars);
  498. };
  499. var checkRange = function(str, substr, start) {
  500. return substr === "" || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
  501. };
  502. var removeLeading = function(str, prefix) {
  503. return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;
  504. };
  505. var contains$1 = function(str, substr) {
  506. return str.indexOf(substr) !== -1;
  507. };
  508. var startsWith = function(str, prefix) {
  509. return checkRange(str, prefix, 0);
  510. };
  511. var endsWith = function(str, suffix) {
  512. return checkRange(str, suffix, str.length - suffix.length);
  513. };
  514. var blank = function(r2) {
  515. return function(s) {
  516. return s.replace(r2, "");
  517. };
  518. };
  519. var trim = blank(/^\s+|\s+$/g);
  520. var isNotEmpty = function(s) {
  521. return s.length > 0;
  522. };
  523. var isEmpty$1 = function(s) {
  524. return !isNotEmpty(s);
  525. };
  526. var toFloat = function(value2) {
  527. var num = parseFloat(value2);
  528. return isNaN(num) ? Optional.none() : Optional.some(num);
  529. };
  530. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  531. var checkContains = function(target) {
  532. return function(uastring) {
  533. return contains$1(uastring, target);
  534. };
  535. };
  536. var browsers = [
  537. {
  538. name: "Edge",
  539. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  540. search: function(uastring) {
  541. return contains$1(uastring, "edge/") && contains$1(uastring, "chrome") && contains$1(uastring, "safari") && contains$1(uastring, "applewebkit");
  542. }
  543. },
  544. {
  545. name: "Chrome",
  546. brand: "Chromium",
  547. versionRegexes: [
  548. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  549. normalVersionRegex
  550. ],
  551. search: function(uastring) {
  552. return contains$1(uastring, "chrome") && !contains$1(uastring, "chromeframe");
  553. }
  554. },
  555. {
  556. name: "IE",
  557. versionRegexes: [
  558. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  559. /.*?rv:([0-9]+)\.([0-9]+).*/
  560. ],
  561. search: function(uastring) {
  562. return contains$1(uastring, "msie") || contains$1(uastring, "trident");
  563. }
  564. },
  565. {
  566. name: "Opera",
  567. versionRegexes: [
  568. normalVersionRegex,
  569. /.*?opera\/([0-9]+)\.([0-9]+).*/
  570. ],
  571. search: checkContains("opera")
  572. },
  573. {
  574. name: "Firefox",
  575. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  576. search: checkContains("firefox")
  577. },
  578. {
  579. name: "Safari",
  580. versionRegexes: [
  581. normalVersionRegex,
  582. /.*?cpu os ([0-9]+)_([0-9]+).*/
  583. ],
  584. search: function(uastring) {
  585. return (contains$1(uastring, "safari") || contains$1(uastring, "mobile/")) && contains$1(uastring, "applewebkit");
  586. }
  587. }
  588. ];
  589. var oses = [
  590. {
  591. name: "Windows",
  592. search: checkContains("win"),
  593. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  594. },
  595. {
  596. name: "iOS",
  597. search: function(uastring) {
  598. return contains$1(uastring, "iphone") || contains$1(uastring, "ipad");
  599. },
  600. versionRegexes: [
  601. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  602. /.*cpu os ([0-9]+)_([0-9]+).*/,
  603. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  604. ]
  605. },
  606. {
  607. name: "Android",
  608. search: checkContains("android"),
  609. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  610. },
  611. {
  612. name: "OSX",
  613. search: checkContains("mac os x"),
  614. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  615. },
  616. {
  617. name: "Linux",
  618. search: checkContains("linux"),
  619. versionRegexes: []
  620. },
  621. {
  622. name: "Solaris",
  623. search: checkContains("sunos"),
  624. versionRegexes: []
  625. },
  626. {
  627. name: "FreeBSD",
  628. search: checkContains("freebsd"),
  629. versionRegexes: []
  630. },
  631. {
  632. name: "ChromeOS",
  633. search: checkContains("cros"),
  634. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  635. }
  636. ];
  637. var PlatformInfo = {
  638. browsers: constant(browsers),
  639. oses: constant(oses)
  640. };
  641. var edge = "Edge";
  642. var chrome = "Chrome";
  643. var ie = "IE";
  644. var opera = "Opera";
  645. var firefox = "Firefox";
  646. var safari = "Safari";
  647. var unknown$1 = function() {
  648. return nu$1({
  649. current: void 0,
  650. version: Version.unknown()
  651. });
  652. };
  653. var nu$1 = function(info) {
  654. var current = info.current;
  655. var version = info.version;
  656. var isBrowser = function(name2) {
  657. return function() {
  658. return current === name2;
  659. };
  660. };
  661. return {
  662. current,
  663. version,
  664. isEdge: isBrowser(edge),
  665. isChrome: isBrowser(chrome),
  666. isIE: isBrowser(ie),
  667. isOpera: isBrowser(opera),
  668. isFirefox: isBrowser(firefox),
  669. isSafari: isBrowser(safari)
  670. };
  671. };
  672. var Browser = {
  673. unknown: unknown$1,
  674. nu: nu$1,
  675. edge: constant(edge),
  676. chrome: constant(chrome),
  677. ie: constant(ie),
  678. opera: constant(opera),
  679. firefox: constant(firefox),
  680. safari: constant(safari)
  681. };
  682. var windows = "Windows";
  683. var ios = "iOS";
  684. var android = "Android";
  685. var linux = "Linux";
  686. var osx = "OSX";
  687. var solaris = "Solaris";
  688. var freebsd = "FreeBSD";
  689. var chromeos = "ChromeOS";
  690. var unknown = function() {
  691. return nu({
  692. current: void 0,
  693. version: Version.unknown()
  694. });
  695. };
  696. var nu = function(info) {
  697. var current = info.current;
  698. var version = info.version;
  699. var isOS = function(name2) {
  700. return function() {
  701. return current === name2;
  702. };
  703. };
  704. return {
  705. current,
  706. version,
  707. isWindows: isOS(windows),
  708. isiOS: isOS(ios),
  709. isAndroid: isOS(android),
  710. isOSX: isOS(osx),
  711. isLinux: isOS(linux),
  712. isSolaris: isOS(solaris),
  713. isFreeBSD: isOS(freebsd),
  714. isChromeOS: isOS(chromeos)
  715. };
  716. };
  717. var OperatingSystem = {
  718. unknown,
  719. nu,
  720. windows: constant(windows),
  721. ios: constant(ios),
  722. android: constant(android),
  723. linux: constant(linux),
  724. osx: constant(osx),
  725. solaris: constant(solaris),
  726. freebsd: constant(freebsd),
  727. chromeos: constant(chromeos)
  728. };
  729. var detect$4 = function(userAgent, userAgentDataOpt, mediaMatch2) {
  730. var browsers2 = PlatformInfo.browsers();
  731. var oses2 = PlatformInfo.oses();
  732. var browser = userAgentDataOpt.bind(function(userAgentData) {
  733. return detectBrowser$1(browsers2, userAgentData);
  734. }).orThunk(function() {
  735. return detectBrowser(browsers2, userAgent);
  736. }).fold(Browser.unknown, Browser.nu);
  737. var os = detectOs(oses2, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  738. var deviceType = DeviceType(os, browser, userAgent, mediaMatch2);
  739. return {
  740. browser,
  741. os,
  742. deviceType
  743. };
  744. };
  745. var PlatformDetection = { detect: detect$4 };
  746. var mediaMatch = function(query) {
  747. return window.matchMedia(query).matches;
  748. };
  749. var platform = cached(function() {
  750. return PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch);
  751. });
  752. var detect$3 = function() {
  753. return platform();
  754. };
  755. var compareDocumentPosition = function(a, b, match) {
  756. return (a.compareDocumentPosition(b) & match) !== 0;
  757. };
  758. var documentPositionContainedBy = function(a, b) {
  759. return compareDocumentPosition(a, b, Node.DOCUMENT_POSITION_CONTAINED_BY);
  760. };
  761. var COMMENT = 8;
  762. var DOCUMENT = 9;
  763. var DOCUMENT_FRAGMENT = 11;
  764. var ELEMENT = 1;
  765. var TEXT = 3;
  766. var fromHtml$1 = function(html, scope) {
  767. var doc = scope || document;
  768. var div = doc.createElement("div");
  769. div.innerHTML = html;
  770. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  771. console.error("HTML does not have a single root node", html);
  772. throw new Error("HTML must have a single root node");
  773. }
  774. return fromDom$1(div.childNodes[0]);
  775. };
  776. var fromTag = function(tag, scope) {
  777. var doc = scope || document;
  778. var node = doc.createElement(tag);
  779. return fromDom$1(node);
  780. };
  781. var fromText = function(text, scope) {
  782. var doc = scope || document;
  783. var node = doc.createTextNode(text);
  784. return fromDom$1(node);
  785. };
  786. var fromDom$1 = function(node) {
  787. if (node === null || node === void 0) {
  788. throw new Error("Node cannot be null or undefined");
  789. }
  790. return { dom: node };
  791. };
  792. var fromPoint$1 = function(docElm, x, y) {
  793. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$1);
  794. };
  795. var SugarElement = {
  796. fromHtml: fromHtml$1,
  797. fromTag,
  798. fromText,
  799. fromDom: fromDom$1,
  800. fromPoint: fromPoint$1
  801. };
  802. var is$2 = function(element, selector) {
  803. var dom = element.dom;
  804. if (dom.nodeType !== ELEMENT) {
  805. return false;
  806. } else {
  807. var elem = dom;
  808. if (elem.matches !== void 0) {
  809. return elem.matches(selector);
  810. } else if (elem.msMatchesSelector !== void 0) {
  811. return elem.msMatchesSelector(selector);
  812. } else if (elem.webkitMatchesSelector !== void 0) {
  813. return elem.webkitMatchesSelector(selector);
  814. } else if (elem.mozMatchesSelector !== void 0) {
  815. return elem.mozMatchesSelector(selector);
  816. } else {
  817. throw new Error("Browser lacks native selectors");
  818. }
  819. }
  820. };
  821. var bypassSelector = function(dom) {
  822. return dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0;
  823. };
  824. var all$1 = function(selector, scope) {
  825. var base2 = scope === void 0 ? document : scope.dom;
  826. return bypassSelector(base2) ? [] : map$1(base2.querySelectorAll(selector), SugarElement.fromDom);
  827. };
  828. var one = function(selector, scope) {
  829. var base2 = scope === void 0 ? document : scope.dom;
  830. return bypassSelector(base2) ? Optional.none() : Optional.from(base2.querySelector(selector)).map(SugarElement.fromDom);
  831. };
  832. var eq$1 = function(e1, e2) {
  833. return e1.dom === e2.dom;
  834. };
  835. var regularContains = function(e1, e2) {
  836. var d1 = e1.dom;
  837. var d2 = e2.dom;
  838. return d1 === d2 ? false : d1.contains(d2);
  839. };
  840. var ieContains = function(e1, e2) {
  841. return documentPositionContainedBy(e1.dom, e2.dom);
  842. };
  843. var contains = function(e1, e2) {
  844. return detect$3().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
  845. };
  846. var is$1 = is$2;
  847. var keys = Object.keys;
  848. var hasOwnProperty = Object.hasOwnProperty;
  849. var each$1 = function(obj, f) {
  850. var props = keys(obj);
  851. for (var k = 0, len = props.length; k < len; k++) {
  852. var i = props[k];
  853. var x = obj[i];
  854. f(x, i);
  855. }
  856. };
  857. var map = function(obj, f) {
  858. return tupleMap(obj, function(x, i) {
  859. return {
  860. k: i,
  861. v: f(x, i)
  862. };
  863. });
  864. };
  865. var tupleMap = function(obj, f) {
  866. var r2 = {};
  867. each$1(obj, function(x, i) {
  868. var tuple = f(x, i);
  869. r2[tuple.k] = tuple.v;
  870. });
  871. return r2;
  872. };
  873. var objAcc = function(r2) {
  874. return function(x, i) {
  875. r2[i] = x;
  876. };
  877. };
  878. var internalFilter = function(obj, pred, onTrue, onFalse) {
  879. var r2 = {};
  880. each$1(obj, function(x, i) {
  881. (pred(x, i) ? onTrue : onFalse)(x, i);
  882. });
  883. return r2;
  884. };
  885. var filter$1 = function(obj, pred) {
  886. var t = {};
  887. internalFilter(obj, pred, objAcc(t), noop);
  888. return t;
  889. };
  890. var mapToArray = function(obj, f) {
  891. var r2 = [];
  892. each$1(obj, function(value2, name2) {
  893. r2.push(f(value2, name2));
  894. });
  895. return r2;
  896. };
  897. var values = function(obj) {
  898. return mapToArray(obj, identity);
  899. };
  900. var size = function(obj) {
  901. return keys(obj).length;
  902. };
  903. var get$c = function(obj, key2) {
  904. return has$1(obj, key2) ? Optional.from(obj[key2]) : Optional.none();
  905. };
  906. var has$1 = function(obj, key2) {
  907. return hasOwnProperty.call(obj, key2);
  908. };
  909. var hasNonNullableKey = function(obj, key2) {
  910. return has$1(obj, key2) && obj[key2] !== void 0 && obj[key2] !== null;
  911. };
  912. var isEmpty = function(r2) {
  913. for (var x in r2) {
  914. if (hasOwnProperty.call(r2, x)) {
  915. return false;
  916. }
  917. }
  918. return true;
  919. };
  920. var validSectionList = [
  921. "tfoot",
  922. "thead",
  923. "tbody",
  924. "colgroup"
  925. ];
  926. var isValidSection = function(parentName) {
  927. return contains$2(validSectionList, parentName);
  928. };
  929. var grid = function(rows2, columns2) {
  930. return {
  931. rows: rows2,
  932. columns: columns2
  933. };
  934. };
  935. var address = function(row2, column) {
  936. return {
  937. row: row2,
  938. column
  939. };
  940. };
  941. var detail = function(element, rowspan, colspan) {
  942. return {
  943. element,
  944. rowspan,
  945. colspan
  946. };
  947. };
  948. var detailnew = function(element, rowspan, colspan, isNew) {
  949. return {
  950. element,
  951. rowspan,
  952. colspan,
  953. isNew
  954. };
  955. };
  956. var extended = function(element, rowspan, colspan, row2, column, isLocked) {
  957. return {
  958. element,
  959. rowspan,
  960. colspan,
  961. row: row2,
  962. column,
  963. isLocked
  964. };
  965. };
  966. var rowdetail = function(element, cells2, section2) {
  967. return {
  968. element,
  969. cells: cells2,
  970. section: section2
  971. };
  972. };
  973. var rowdetailnew = function(element, cells2, section2, isNew) {
  974. return {
  975. element,
  976. cells: cells2,
  977. section: section2,
  978. isNew
  979. };
  980. };
  981. var elementnew = function(element, isNew, isLocked) {
  982. return {
  983. element,
  984. isNew,
  985. isLocked
  986. };
  987. };
  988. var rowcells = function(element, cells2, section2, isNew) {
  989. return {
  990. element,
  991. cells: cells2,
  992. section: section2,
  993. isNew
  994. };
  995. };
  996. var bounds = function(startRow, startCol, finishRow, finishCol) {
  997. return {
  998. startRow,
  999. startCol,
  1000. finishRow,
  1001. finishCol
  1002. };
  1003. };
  1004. var columnext = function(element, colspan, column) {
  1005. return {
  1006. element,
  1007. colspan,
  1008. column
  1009. };
  1010. };
  1011. var colgroup = function(element, columns2) {
  1012. return {
  1013. element,
  1014. columns: columns2
  1015. };
  1016. };
  1017. typeof window !== "undefined" ? window : Function("return this;")();
  1018. var name = function(element) {
  1019. var r2 = element.dom.nodeName;
  1020. return r2.toLowerCase();
  1021. };
  1022. var type$1 = function(element) {
  1023. return element.dom.nodeType;
  1024. };
  1025. var isType = function(t) {
  1026. return function(element) {
  1027. return type$1(element) === t;
  1028. };
  1029. };
  1030. var isComment = function(element) {
  1031. return type$1(element) === COMMENT || name(element) === "#comment";
  1032. };
  1033. var isElement = isType(ELEMENT);
  1034. var isText = isType(TEXT);
  1035. var isDocument = isType(DOCUMENT);
  1036. var isDocumentFragment = isType(DOCUMENT_FRAGMENT);
  1037. var isTag = function(tag) {
  1038. return function(e) {
  1039. return isElement(e) && name(e) === tag;
  1040. };
  1041. };
  1042. var owner = function(element) {
  1043. return SugarElement.fromDom(element.dom.ownerDocument);
  1044. };
  1045. var documentOrOwner = function(dos) {
  1046. return isDocument(dos) ? dos : owner(dos);
  1047. };
  1048. var defaultView = function(element) {
  1049. return SugarElement.fromDom(documentOrOwner(element).dom.defaultView);
  1050. };
  1051. var parent = function(element) {
  1052. return Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
  1053. };
  1054. var parentElement = function(element) {
  1055. return Optional.from(element.dom.parentElement).map(SugarElement.fromDom);
  1056. };
  1057. var parents = function(element, isRoot) {
  1058. var stop = isFunction(isRoot) ? isRoot : never;
  1059. var dom = element.dom;
  1060. var ret = [];
  1061. while (dom.parentNode !== null && dom.parentNode !== void 0) {
  1062. var rawParent = dom.parentNode;
  1063. var p = SugarElement.fromDom(rawParent);
  1064. ret.push(p);
  1065. if (stop(p) === true) {
  1066. break;
  1067. } else {
  1068. dom = rawParent;
  1069. }
  1070. }
  1071. return ret;
  1072. };
  1073. var prevSibling = function(element) {
  1074. return Optional.from(element.dom.previousSibling).map(SugarElement.fromDom);
  1075. };
  1076. var nextSibling = function(element) {
  1077. return Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
  1078. };
  1079. var children$3 = function(element) {
  1080. return map$1(element.dom.childNodes, SugarElement.fromDom);
  1081. };
  1082. var child$3 = function(element, index) {
  1083. var cs = element.dom.childNodes;
  1084. return Optional.from(cs[index]).map(SugarElement.fromDom);
  1085. };
  1086. var firstChild = function(element) {
  1087. return child$3(element, 0);
  1088. };
  1089. var isShadowRoot = function(dos) {
  1090. return isDocumentFragment(dos) && isNonNullable(dos.dom.host);
  1091. };
  1092. var supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
  1093. var isSupported$1 = constant(supported);
  1094. var getRootNode = supported ? function(e) {
  1095. return SugarElement.fromDom(e.dom.getRootNode());
  1096. } : documentOrOwner;
  1097. var getShadowRoot = function(e) {
  1098. var r2 = getRootNode(e);
  1099. return isShadowRoot(r2) ? Optional.some(r2) : Optional.none();
  1100. };
  1101. var getShadowHost = function(e) {
  1102. return SugarElement.fromDom(e.dom.host);
  1103. };
  1104. var getOriginalEventTarget = function(event) {
  1105. if (isSupported$1() && isNonNullable(event.target)) {
  1106. var el = SugarElement.fromDom(event.target);
  1107. if (isElement(el) && isOpenShadowHost(el)) {
  1108. if (event.composed && event.composedPath) {
  1109. var composedPath = event.composedPath();
  1110. if (composedPath) {
  1111. return head(composedPath);
  1112. }
  1113. }
  1114. }
  1115. }
  1116. return Optional.from(event.target);
  1117. };
  1118. var isOpenShadowHost = function(element) {
  1119. return isNonNullable(element.dom.shadowRoot);
  1120. };
  1121. var inBody = function(element) {
  1122. var dom = isText(element) ? element.dom.parentNode : element.dom;
  1123. if (dom === void 0 || dom === null || dom.ownerDocument === null) {
  1124. return false;
  1125. }
  1126. var doc = dom.ownerDocument;
  1127. return getShadowRoot(SugarElement.fromDom(dom)).fold(function() {
  1128. return doc.body.contains(dom);
  1129. }, compose1(inBody, getShadowHost));
  1130. };
  1131. var body$1 = function() {
  1132. return getBody$1(SugarElement.fromDom(document));
  1133. };
  1134. var getBody$1 = function(doc) {
  1135. var b = doc.dom.body;
  1136. if (b === null || b === void 0) {
  1137. throw new Error("Body is not available yet");
  1138. }
  1139. return SugarElement.fromDom(b);
  1140. };
  1141. var ancestors$4 = function(scope, predicate, isRoot) {
  1142. return filter$2(parents(scope, isRoot), predicate);
  1143. };
  1144. var children$2 = function(scope, predicate) {
  1145. return filter$2(children$3(scope), predicate);
  1146. };
  1147. var descendants$1 = function(scope, predicate) {
  1148. var result = [];
  1149. each$2(children$3(scope), function(x) {
  1150. if (predicate(x)) {
  1151. result = result.concat([x]);
  1152. }
  1153. result = result.concat(descendants$1(x, predicate));
  1154. });
  1155. return result;
  1156. };
  1157. var ancestors$3 = function(scope, selector, isRoot) {
  1158. return ancestors$4(scope, function(e) {
  1159. return is$2(e, selector);
  1160. }, isRoot);
  1161. };
  1162. var children$1 = function(scope, selector) {
  1163. return children$2(scope, function(e) {
  1164. return is$2(e, selector);
  1165. });
  1166. };
  1167. var descendants = function(scope, selector) {
  1168. return all$1(selector, scope);
  1169. };
  1170. function ClosestOrAncestor(is2, ancestor2, scope, a, isRoot) {
  1171. if (is2(scope, a)) {
  1172. return Optional.some(scope);
  1173. } else if (isFunction(isRoot) && isRoot(scope)) {
  1174. return Optional.none();
  1175. } else {
  1176. return ancestor2(scope, a, isRoot);
  1177. }
  1178. }
  1179. var ancestor$2 = function(scope, predicate, isRoot) {
  1180. var element = scope.dom;
  1181. var stop = isFunction(isRoot) ? isRoot : never;
  1182. while (element.parentNode) {
  1183. element = element.parentNode;
  1184. var el = SugarElement.fromDom(element);
  1185. if (predicate(el)) {
  1186. return Optional.some(el);
  1187. } else if (stop(el)) {
  1188. break;
  1189. }
  1190. }
  1191. return Optional.none();
  1192. };
  1193. var closest$2 = function(scope, predicate, isRoot) {
  1194. var is2 = function(s, test) {
  1195. return test(s);
  1196. };
  1197. return ClosestOrAncestor(is2, ancestor$2, scope, predicate, isRoot);
  1198. };
  1199. var child$2 = function(scope, predicate) {
  1200. var pred = function(node) {
  1201. return predicate(SugarElement.fromDom(node));
  1202. };
  1203. var result = find$1(scope.dom.childNodes, pred);
  1204. return result.map(SugarElement.fromDom);
  1205. };
  1206. var descendant$1 = function(scope, predicate) {
  1207. var descend = function(node) {
  1208. for (var i = 0; i < node.childNodes.length; i++) {
  1209. var child_1 = SugarElement.fromDom(node.childNodes[i]);
  1210. if (predicate(child_1)) {
  1211. return Optional.some(child_1);
  1212. }
  1213. var res = descend(node.childNodes[i]);
  1214. if (res.isSome()) {
  1215. return res;
  1216. }
  1217. }
  1218. return Optional.none();
  1219. };
  1220. return descend(scope.dom);
  1221. };
  1222. var ancestor$1 = function(scope, selector, isRoot) {
  1223. return ancestor$2(scope, function(e) {
  1224. return is$2(e, selector);
  1225. }, isRoot);
  1226. };
  1227. var child$1 = function(scope, selector) {
  1228. return child$2(scope, function(e) {
  1229. return is$2(e, selector);
  1230. });
  1231. };
  1232. var descendant = function(scope, selector) {
  1233. return one(selector, scope);
  1234. };
  1235. var closest$1 = function(scope, selector, isRoot) {
  1236. var is2 = function(element, selector2) {
  1237. return is$2(element, selector2);
  1238. };
  1239. return ClosestOrAncestor(is2, ancestor$1, scope, selector, isRoot);
  1240. };
  1241. var rawSet = function(dom, key2, value2) {
  1242. if (isString(value2) || isBoolean(value2) || isNumber(value2)) {
  1243. dom.setAttribute(key2, value2 + "");
  1244. } else {
  1245. console.error("Invalid call to Attribute.set. Key ", key2, ":: Value ", value2, ":: Element ", dom);
  1246. throw new Error("Attribute value was not simple");
  1247. }
  1248. };
  1249. var set$2 = function(element, key2, value2) {
  1250. rawSet(element.dom, key2, value2);
  1251. };
  1252. var setAll$1 = function(element, attrs) {
  1253. var dom = element.dom;
  1254. each$1(attrs, function(v, k) {
  1255. rawSet(dom, k, v);
  1256. });
  1257. };
  1258. var setOptions = function(element, attrs) {
  1259. each$1(attrs, function(v, k) {
  1260. v.fold(function() {
  1261. remove$7(element, k);
  1262. }, function(value2) {
  1263. rawSet(element.dom, k, value2);
  1264. });
  1265. });
  1266. };
  1267. var get$b = function(element, key2) {
  1268. var v = element.dom.getAttribute(key2);
  1269. return v === null ? void 0 : v;
  1270. };
  1271. var getOpt = function(element, key2) {
  1272. return Optional.from(get$b(element, key2));
  1273. };
  1274. var remove$7 = function(element, key2) {
  1275. element.dom.removeAttribute(key2);
  1276. };
  1277. var clone$2 = function(element) {
  1278. return foldl(element.dom.attributes, function(acc, attr) {
  1279. acc[attr.name] = attr.value;
  1280. return acc;
  1281. }, {});
  1282. };
  1283. var is = function(lhs, rhs, comparator) {
  1284. if (comparator === void 0) {
  1285. comparator = tripleEquals;
  1286. }
  1287. return lhs.exists(function(left2) {
  1288. return comparator(left2, rhs);
  1289. });
  1290. };
  1291. var cat = function(arr) {
  1292. var r2 = [];
  1293. var push = function(x) {
  1294. r2.push(x);
  1295. };
  1296. for (var i = 0; i < arr.length; i++) {
  1297. arr[i].each(push);
  1298. }
  1299. return r2;
  1300. };
  1301. var lift2 = function(oa, ob, f) {
  1302. return oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
  1303. };
  1304. var bindFrom = function(a, f) {
  1305. return a !== void 0 && a !== null ? f(a) : Optional.none();
  1306. };
  1307. var flatten = function(oot) {
  1308. return oot.bind(identity);
  1309. };
  1310. var someIf = function(b, a) {
  1311. return b ? Optional.some(a) : Optional.none();
  1312. };
  1313. var isSupported = function(dom) {
  1314. return dom.style !== void 0 && isFunction(dom.style.getPropertyValue);
  1315. };
  1316. var internalSet = function(dom, property, value2) {
  1317. if (!isString(value2)) {
  1318. console.error("Invalid call to CSS.set. Property ", property, ":: Value ", value2, ":: Element ", dom);
  1319. throw new Error("CSS value must be a string: " + value2);
  1320. }
  1321. if (isSupported(dom)) {
  1322. dom.style.setProperty(property, value2);
  1323. }
  1324. };
  1325. var internalRemove = function(dom, property) {
  1326. if (isSupported(dom)) {
  1327. dom.style.removeProperty(property);
  1328. }
  1329. };
  1330. var set$1 = function(element, property, value2) {
  1331. var dom = element.dom;
  1332. internalSet(dom, property, value2);
  1333. };
  1334. var setAll = function(element, css2) {
  1335. var dom = element.dom;
  1336. each$1(css2, function(v, k) {
  1337. internalSet(dom, k, v);
  1338. });
  1339. };
  1340. var get$a = function(element, property) {
  1341. var dom = element.dom;
  1342. var styles2 = window.getComputedStyle(dom);
  1343. var r2 = styles2.getPropertyValue(property);
  1344. return r2 === "" && !inBody(element) ? getUnsafeProperty(dom, property) : r2;
  1345. };
  1346. var getUnsafeProperty = function(dom, property) {
  1347. return isSupported(dom) ? dom.style.getPropertyValue(property) : "";
  1348. };
  1349. var getRaw$2 = function(element, property) {
  1350. var dom = element.dom;
  1351. var raw = getUnsafeProperty(dom, property);
  1352. return Optional.from(raw).filter(function(r2) {
  1353. return r2.length > 0;
  1354. });
  1355. };
  1356. var remove$6 = function(element, property) {
  1357. var dom = element.dom;
  1358. internalRemove(dom, property);
  1359. if (is(getOpt(element, "style").map(trim), "")) {
  1360. remove$7(element, "style");
  1361. }
  1362. };
  1363. var copy$2 = function(source, target) {
  1364. var sourceDom = source.dom;
  1365. var targetDom = target.dom;
  1366. if (isSupported(sourceDom) && isSupported(targetDom)) {
  1367. targetDom.style.cssText = sourceDom.style.cssText;
  1368. }
  1369. };
  1370. var getAttrValue = function(cell2, name2, fallback2) {
  1371. if (fallback2 === void 0) {
  1372. fallback2 = 0;
  1373. }
  1374. return getOpt(cell2, name2).map(function(value2) {
  1375. return parseInt(value2, 10);
  1376. }).getOr(fallback2);
  1377. };
  1378. var getSpan = function(cell2, type2) {
  1379. return getAttrValue(cell2, type2, 1);
  1380. };
  1381. var hasColspan = function(cellOrCol) {
  1382. if (isTag("col")(cellOrCol)) {
  1383. return getAttrValue(cellOrCol, "span", 1) > 1;
  1384. } else {
  1385. return getSpan(cellOrCol, "colspan") > 1;
  1386. }
  1387. };
  1388. var hasRowspan = function(cell2) {
  1389. return getSpan(cell2, "rowspan") > 1;
  1390. };
  1391. var getCssValue = function(element, property) {
  1392. return parseInt(get$a(element, property), 10);
  1393. };
  1394. var minWidth = constant(10);
  1395. var minHeight = constant(10);
  1396. var firstLayer = function(scope, selector) {
  1397. return filterFirstLayer(scope, selector, always);
  1398. };
  1399. var filterFirstLayer = function(scope, selector, predicate) {
  1400. return bind$2(children$3(scope), function(x) {
  1401. if (is$2(x, selector)) {
  1402. return predicate(x) ? [x] : [];
  1403. } else {
  1404. return filterFirstLayer(x, selector, predicate);
  1405. }
  1406. });
  1407. };
  1408. var lookup = function(tags, element, isRoot) {
  1409. if (isRoot === void 0) {
  1410. isRoot = never;
  1411. }
  1412. if (isRoot(element)) {
  1413. return Optional.none();
  1414. }
  1415. if (contains$2(tags, name(element))) {
  1416. return Optional.some(element);
  1417. }
  1418. var isRootOrUpperTable = function(elm) {
  1419. return is$2(elm, "table") || isRoot(elm);
  1420. };
  1421. return ancestor$1(element, tags.join(","), isRootOrUpperTable);
  1422. };
  1423. var cell = function(element, isRoot) {
  1424. return lookup([
  1425. "td",
  1426. "th"
  1427. ], element, isRoot);
  1428. };
  1429. var cells$1 = function(ancestor2) {
  1430. return firstLayer(ancestor2, "th,td");
  1431. };
  1432. var columns$1 = function(ancestor2) {
  1433. if (is$2(ancestor2, "colgroup")) {
  1434. return children$1(ancestor2, "col");
  1435. } else {
  1436. return bind$2(columnGroups(ancestor2), function(columnGroup) {
  1437. return children$1(columnGroup, "col");
  1438. });
  1439. }
  1440. };
  1441. var table = function(element, isRoot) {
  1442. return closest$1(element, "table", isRoot);
  1443. };
  1444. var rows$1 = function(ancestor2) {
  1445. return firstLayer(ancestor2, "tr");
  1446. };
  1447. var columnGroups = function(ancestor2) {
  1448. return table(ancestor2).fold(constant([]), function(table2) {
  1449. return children$1(table2, "colgroup");
  1450. });
  1451. };
  1452. var fromRowsOrColGroups = function(elems, getSection) {
  1453. return map$1(elems, function(row2) {
  1454. if (name(row2) === "colgroup") {
  1455. var cells2 = map$1(columns$1(row2), function(column) {
  1456. var colspan = getAttrValue(column, "span", 1);
  1457. return detail(column, 1, colspan);
  1458. });
  1459. return rowdetail(row2, cells2, "colgroup");
  1460. } else {
  1461. var cells2 = map$1(cells$1(row2), function(cell2) {
  1462. var rowspan = getAttrValue(cell2, "rowspan", 1);
  1463. var colspan = getAttrValue(cell2, "colspan", 1);
  1464. return detail(cell2, rowspan, colspan);
  1465. });
  1466. return rowdetail(row2, cells2, getSection(row2));
  1467. }
  1468. });
  1469. };
  1470. var getParentSection = function(group) {
  1471. return parent(group).map(function(parent2) {
  1472. var parentName = name(parent2);
  1473. return isValidSection(parentName) ? parentName : "tbody";
  1474. }).getOr("tbody");
  1475. };
  1476. var fromTable$1 = function(table2) {
  1477. var rows2 = rows$1(table2);
  1478. var columnGroups$1 = columnGroups(table2);
  1479. var elems = __spreadArray(__spreadArray([], columnGroups$1, true), rows2, true);
  1480. return fromRowsOrColGroups(elems, getParentSection);
  1481. };
  1482. var fromPastedRows = function(elems, section2) {
  1483. return fromRowsOrColGroups(elems, function() {
  1484. return section2;
  1485. });
  1486. };
  1487. var addCells = function(gridRow, index, cells2) {
  1488. var existingCells = gridRow.cells;
  1489. var before2 = existingCells.slice(0, index);
  1490. var after2 = existingCells.slice(index);
  1491. var newCells = before2.concat(cells2).concat(after2);
  1492. return setCells(gridRow, newCells);
  1493. };
  1494. var addCell = function(gridRow, index, cell2) {
  1495. return addCells(gridRow, index, [cell2]);
  1496. };
  1497. var mutateCell = function(gridRow, index, cell2) {
  1498. var cells2 = gridRow.cells;
  1499. cells2[index] = cell2;
  1500. };
  1501. var setCells = function(gridRow, cells2) {
  1502. return rowcells(gridRow.element, cells2, gridRow.section, gridRow.isNew);
  1503. };
  1504. var mapCells = function(gridRow, f) {
  1505. var cells2 = gridRow.cells;
  1506. var r2 = map$1(cells2, f);
  1507. return rowcells(gridRow.element, r2, gridRow.section, gridRow.isNew);
  1508. };
  1509. var getCell = function(gridRow, index) {
  1510. return gridRow.cells[index];
  1511. };
  1512. var getCellElement = function(gridRow, index) {
  1513. return getCell(gridRow, index).element;
  1514. };
  1515. var cellLength = function(gridRow) {
  1516. return gridRow.cells.length;
  1517. };
  1518. var extractGridDetails = function(grid2) {
  1519. var result = partition(grid2, function(row2) {
  1520. return row2.section === "colgroup";
  1521. });
  1522. return {
  1523. rows: result.fail,
  1524. cols: result.pass
  1525. };
  1526. };
  1527. var clone$1 = function(gridRow, cloneRow2, cloneCell) {
  1528. var newCells = map$1(gridRow.cells, cloneCell);
  1529. return rowcells(cloneRow2(gridRow.element), newCells, gridRow.section, true);
  1530. };
  1531. var LOCKED_COL_ATTR = "data-snooker-locked-cols";
  1532. var getLockedColumnsFromTable = function(table2) {
  1533. return getOpt(table2, LOCKED_COL_ATTR).bind(function(lockedColStr) {
  1534. return Optional.from(lockedColStr.match(/\d+/g));
  1535. }).map(function(lockedCols) {
  1536. return mapToObject(lockedCols, always);
  1537. });
  1538. };
  1539. var getLockedColumnsFromGrid = function(grid2) {
  1540. var locked = foldl(extractGridDetails(grid2).rows, function(acc, row2) {
  1541. each$2(row2.cells, function(cell2, idx) {
  1542. if (cell2.isLocked) {
  1543. acc[idx] = true;
  1544. }
  1545. });
  1546. return acc;
  1547. }, {});
  1548. var lockedArr = mapToArray(locked, function(_val, key2) {
  1549. return parseInt(key2, 10);
  1550. });
  1551. return sort$1(lockedArr);
  1552. };
  1553. var key = function(row2, column) {
  1554. return row2 + "," + column;
  1555. };
  1556. var getAt = function(warehouse, row2, column) {
  1557. return Optional.from(warehouse.access[key(row2, column)]);
  1558. };
  1559. var findItem = function(warehouse, item, comparator) {
  1560. var filtered = filterItems(warehouse, function(detail2) {
  1561. return comparator(item, detail2.element);
  1562. });
  1563. return filtered.length > 0 ? Optional.some(filtered[0]) : Optional.none();
  1564. };
  1565. var filterItems = function(warehouse, predicate) {
  1566. var all2 = bind$2(warehouse.all, function(r2) {
  1567. return r2.cells;
  1568. });
  1569. return filter$2(all2, predicate);
  1570. };
  1571. var generateColumns = function(rowData) {
  1572. var columnsGroup = {};
  1573. var index = 0;
  1574. each$2(rowData.cells, function(column) {
  1575. var colspan = column.colspan;
  1576. range$1(colspan, function(columnIndex) {
  1577. var colIndex = index + columnIndex;
  1578. columnsGroup[colIndex] = columnext(column.element, colspan, colIndex);
  1579. });
  1580. index += colspan;
  1581. });
  1582. return columnsGroup;
  1583. };
  1584. var generate$1 = function(list) {
  1585. var access = {};
  1586. var cells2 = [];
  1587. var tableOpt = head(list).map(function(rowData) {
  1588. return rowData.element;
  1589. }).bind(table);
  1590. var lockedColumns = tableOpt.bind(getLockedColumnsFromTable).getOr({});
  1591. var maxRows = 0;
  1592. var maxColumns = 0;
  1593. var rowCount = 0;
  1594. var _a = partition(list, function(rowData) {
  1595. return rowData.section === "colgroup";
  1596. }), colgroupRows = _a.pass, rows2 = _a.fail;
  1597. each$2(rows2, function(rowData) {
  1598. var currentRow = [];
  1599. each$2(rowData.cells, function(rowCell) {
  1600. var start = 0;
  1601. while (access[key(rowCount, start)] !== void 0) {
  1602. start++;
  1603. }
  1604. var isLocked = hasNonNullableKey(lockedColumns, start.toString());
  1605. var current = extended(rowCell.element, rowCell.rowspan, rowCell.colspan, rowCount, start, isLocked);
  1606. for (var occupiedColumnPosition = 0; occupiedColumnPosition < rowCell.colspan; occupiedColumnPosition++) {
  1607. for (var occupiedRowPosition = 0; occupiedRowPosition < rowCell.rowspan; occupiedRowPosition++) {
  1608. var rowPosition = rowCount + occupiedRowPosition;
  1609. var columnPosition = start + occupiedColumnPosition;
  1610. var newpos = key(rowPosition, columnPosition);
  1611. access[newpos] = current;
  1612. maxColumns = Math.max(maxColumns, columnPosition + 1);
  1613. }
  1614. }
  1615. currentRow.push(current);
  1616. });
  1617. maxRows++;
  1618. cells2.push(rowdetail(rowData.element, currentRow, rowData.section));
  1619. rowCount++;
  1620. });
  1621. var _b = last$2(colgroupRows).map(function(rowData) {
  1622. var columns3 = generateColumns(rowData);
  1623. var colgroup$1 = colgroup(rowData.element, values(columns3));
  1624. return {
  1625. colgroups: [colgroup$1],
  1626. columns: columns3
  1627. };
  1628. }).getOrThunk(function() {
  1629. return {
  1630. colgroups: [],
  1631. columns: {}
  1632. };
  1633. }), columns2 = _b.columns, colgroups = _b.colgroups;
  1634. var grid$1 = grid(maxRows, maxColumns);
  1635. return {
  1636. grid: grid$1,
  1637. access,
  1638. all: cells2,
  1639. columns: columns2,
  1640. colgroups
  1641. };
  1642. };
  1643. var fromTable = function(table2) {
  1644. var list = fromTable$1(table2);
  1645. return generate$1(list);
  1646. };
  1647. var justCells = function(warehouse) {
  1648. return bind$2(warehouse.all, function(w) {
  1649. return w.cells;
  1650. });
  1651. };
  1652. var justColumns = function(warehouse) {
  1653. return values(warehouse.columns);
  1654. };
  1655. var hasColumns = function(warehouse) {
  1656. return keys(warehouse.columns).length > 0;
  1657. };
  1658. var getColumnAt = function(warehouse, columnIndex) {
  1659. return Optional.from(warehouse.columns[columnIndex]);
  1660. };
  1661. var Warehouse = {
  1662. fromTable,
  1663. generate: generate$1,
  1664. getAt,
  1665. findItem,
  1666. filterItems,
  1667. justCells,
  1668. justColumns,
  1669. hasColumns,
  1670. getColumnAt
  1671. };
  1672. var inSelection = function(bounds2, detail2) {
  1673. var leftEdge = detail2.column;
  1674. var rightEdge = detail2.column + detail2.colspan - 1;
  1675. var topEdge = detail2.row;
  1676. var bottomEdge = detail2.row + detail2.rowspan - 1;
  1677. return leftEdge <= bounds2.finishCol && rightEdge >= bounds2.startCol && (topEdge <= bounds2.finishRow && bottomEdge >= bounds2.startRow);
  1678. };
  1679. var isWithin = function(bounds2, detail2) {
  1680. return detail2.column >= bounds2.startCol && detail2.column + detail2.colspan - 1 <= bounds2.finishCol && detail2.row >= bounds2.startRow && detail2.row + detail2.rowspan - 1 <= bounds2.finishRow;
  1681. };
  1682. var isRectangular = function(warehouse, bounds2) {
  1683. var isRect = true;
  1684. var detailIsWithin = curry(isWithin, bounds2);
  1685. for (var i = bounds2.startRow; i <= bounds2.finishRow; i++) {
  1686. for (var j = bounds2.startCol; j <= bounds2.finishCol; j++) {
  1687. isRect = isRect && Warehouse.getAt(warehouse, i, j).exists(detailIsWithin);
  1688. }
  1689. }
  1690. return isRect ? Optional.some(bounds2) : Optional.none();
  1691. };
  1692. var getBounds = function(detailA, detailB) {
  1693. return bounds(Math.min(detailA.row, detailB.row), Math.min(detailA.column, detailB.column), Math.max(detailA.row + detailA.rowspan - 1, detailB.row + detailB.rowspan - 1), Math.max(detailA.column + detailA.colspan - 1, detailB.column + detailB.colspan - 1));
  1694. };
  1695. var getAnyBox = function(warehouse, startCell, finishCell) {
  1696. var startCoords = Warehouse.findItem(warehouse, startCell, eq$1);
  1697. var finishCoords = Warehouse.findItem(warehouse, finishCell, eq$1);
  1698. return startCoords.bind(function(sc) {
  1699. return finishCoords.map(function(fc) {
  1700. return getBounds(sc, fc);
  1701. });
  1702. });
  1703. };
  1704. var getBox$1 = function(warehouse, startCell, finishCell) {
  1705. return getAnyBox(warehouse, startCell, finishCell).bind(function(bounds2) {
  1706. return isRectangular(warehouse, bounds2);
  1707. });
  1708. };
  1709. var moveBy$1 = function(warehouse, cell2, row2, column) {
  1710. return Warehouse.findItem(warehouse, cell2, eq$1).bind(function(detail2) {
  1711. var startRow = row2 > 0 ? detail2.row + detail2.rowspan - 1 : detail2.row;
  1712. var startCol = column > 0 ? detail2.column + detail2.colspan - 1 : detail2.column;
  1713. var dest = Warehouse.getAt(warehouse, startRow + row2, startCol + column);
  1714. return dest.map(function(d) {
  1715. return d.element;
  1716. });
  1717. });
  1718. };
  1719. var intercepts$1 = function(warehouse, start, finish) {
  1720. return getAnyBox(warehouse, start, finish).map(function(bounds2) {
  1721. var inside = Warehouse.filterItems(warehouse, curry(inSelection, bounds2));
  1722. return map$1(inside, function(detail2) {
  1723. return detail2.element;
  1724. });
  1725. });
  1726. };
  1727. var parentCell = function(warehouse, innerCell) {
  1728. var isContainedBy = function(c1, c2) {
  1729. return contains(c2, c1);
  1730. };
  1731. return Warehouse.findItem(warehouse, innerCell, isContainedBy).map(function(detail2) {
  1732. return detail2.element;
  1733. });
  1734. };
  1735. var moveBy = function(cell2, deltaRow, deltaColumn) {
  1736. return table(cell2).bind(function(table2) {
  1737. var warehouse = getWarehouse(table2);
  1738. return moveBy$1(warehouse, cell2, deltaRow, deltaColumn);
  1739. });
  1740. };
  1741. var intercepts = function(table2, first2, last2) {
  1742. var warehouse = getWarehouse(table2);
  1743. return intercepts$1(warehouse, first2, last2);
  1744. };
  1745. var nestedIntercepts = function(table2, first2, firstTable, last2, lastTable) {
  1746. var warehouse = getWarehouse(table2);
  1747. var optStartCell = eq$1(table2, firstTable) ? Optional.some(first2) : parentCell(warehouse, first2);
  1748. var optLastCell = eq$1(table2, lastTable) ? Optional.some(last2) : parentCell(warehouse, last2);
  1749. return optStartCell.bind(function(startCell) {
  1750. return optLastCell.bind(function(lastCell) {
  1751. return intercepts$1(warehouse, startCell, lastCell);
  1752. });
  1753. });
  1754. };
  1755. var getBox = function(table2, first2, last2) {
  1756. var warehouse = getWarehouse(table2);
  1757. return getBox$1(warehouse, first2, last2);
  1758. };
  1759. var getWarehouse = Warehouse.fromTable;
  1760. var before$4 = function(marker, element) {
  1761. var parent$1 = parent(marker);
  1762. parent$1.each(function(v) {
  1763. v.dom.insertBefore(element.dom, marker.dom);
  1764. });
  1765. };
  1766. var after$5 = function(marker, element) {
  1767. var sibling = nextSibling(marker);
  1768. sibling.fold(function() {
  1769. var parent$1 = parent(marker);
  1770. parent$1.each(function(v) {
  1771. append$1(v, element);
  1772. });
  1773. }, function(v) {
  1774. before$4(v, element);
  1775. });
  1776. };
  1777. var prepend = function(parent2, element) {
  1778. var firstChild$1 = firstChild(parent2);
  1779. firstChild$1.fold(function() {
  1780. append$1(parent2, element);
  1781. }, function(v) {
  1782. parent2.dom.insertBefore(element.dom, v.dom);
  1783. });
  1784. };
  1785. var append$1 = function(parent2, element) {
  1786. parent2.dom.appendChild(element.dom);
  1787. };
  1788. var appendAt = function(parent2, element, index) {
  1789. child$3(parent2, index).fold(function() {
  1790. append$1(parent2, element);
  1791. }, function(v) {
  1792. before$4(v, element);
  1793. });
  1794. };
  1795. var wrap = function(element, wrapper) {
  1796. before$4(element, wrapper);
  1797. append$1(wrapper, element);
  1798. };
  1799. var before$3 = function(marker, elements) {
  1800. each$2(elements, function(x) {
  1801. before$4(marker, x);
  1802. });
  1803. };
  1804. var after$4 = function(marker, elements) {
  1805. each$2(elements, function(x, i) {
  1806. var e = i === 0 ? marker : elements[i - 1];
  1807. after$5(e, x);
  1808. });
  1809. };
  1810. var append = function(parent2, elements) {
  1811. each$2(elements, function(x) {
  1812. append$1(parent2, x);
  1813. });
  1814. };
  1815. var empty = function(element) {
  1816. element.dom.textContent = "";
  1817. each$2(children$3(element), function(rogue) {
  1818. remove$5(rogue);
  1819. });
  1820. };
  1821. var remove$5 = function(element) {
  1822. var dom = element.dom;
  1823. if (dom.parentNode !== null) {
  1824. dom.parentNode.removeChild(dom);
  1825. }
  1826. };
  1827. var unwrap = function(wrapper) {
  1828. var children2 = children$3(wrapper);
  1829. if (children2.length > 0) {
  1830. before$3(wrapper, children2);
  1831. }
  1832. remove$5(wrapper);
  1833. };
  1834. var NodeValue = function(is2, name2) {
  1835. var get2 = function(element) {
  1836. if (!is2(element)) {
  1837. throw new Error("Can only get " + name2 + " value of a " + name2 + " node");
  1838. }
  1839. return getOption2(element).getOr("");
  1840. };
  1841. var getOption2 = function(element) {
  1842. return is2(element) ? Optional.from(element.dom.nodeValue) : Optional.none();
  1843. };
  1844. var set2 = function(element, value2) {
  1845. if (!is2(element)) {
  1846. throw new Error("Can only set raw " + name2 + " value of a " + name2 + " node");
  1847. }
  1848. element.dom.nodeValue = value2;
  1849. };
  1850. return {
  1851. get: get2,
  1852. getOption: getOption2,
  1853. set: set2
  1854. };
  1855. };
  1856. var api$2 = NodeValue(isText, "text");
  1857. var get$9 = function(element) {
  1858. return api$2.get(element);
  1859. };
  1860. var getOption = function(element) {
  1861. return api$2.getOption(element);
  1862. };
  1863. var set = function(element, value2) {
  1864. return api$2.set(element, value2);
  1865. };
  1866. var TagBoundaries = [
  1867. "body",
  1868. "p",
  1869. "div",
  1870. "article",
  1871. "aside",
  1872. "figcaption",
  1873. "figure",
  1874. "footer",
  1875. "header",
  1876. "nav",
  1877. "section",
  1878. "ol",
  1879. "ul",
  1880. "li",
  1881. "table",
  1882. "thead",
  1883. "tbody",
  1884. "tfoot",
  1885. "caption",
  1886. "tr",
  1887. "td",
  1888. "th",
  1889. "h1",
  1890. "h2",
  1891. "h3",
  1892. "h4",
  1893. "h5",
  1894. "h6",
  1895. "blockquote",
  1896. "pre",
  1897. "address"
  1898. ];
  1899. function DomUniverse() {
  1900. var clone2 = function(element) {
  1901. return SugarElement.fromDom(element.dom.cloneNode(false));
  1902. };
  1903. var document2 = function(element) {
  1904. return documentOrOwner(element).dom;
  1905. };
  1906. var isBoundary = function(element) {
  1907. if (!isElement(element)) {
  1908. return false;
  1909. }
  1910. if (name(element) === "body") {
  1911. return true;
  1912. }
  1913. return contains$2(TagBoundaries, name(element));
  1914. };
  1915. var isEmptyTag2 = function(element) {
  1916. if (!isElement(element)) {
  1917. return false;
  1918. }
  1919. return contains$2([
  1920. "br",
  1921. "img",
  1922. "hr",
  1923. "input"
  1924. ], name(element));
  1925. };
  1926. var isNonEditable = function(element) {
  1927. return isElement(element) && get$b(element, "contenteditable") === "false";
  1928. };
  1929. var comparePosition = function(element, other) {
  1930. return element.dom.compareDocumentPosition(other.dom);
  1931. };
  1932. var copyAttributesTo = function(source, destination) {
  1933. var as = clone$2(source);
  1934. setAll$1(destination, as);
  1935. };
  1936. var isSpecial = function(element) {
  1937. var tag = name(element);
  1938. return contains$2([
  1939. "script",
  1940. "noscript",
  1941. "iframe",
  1942. "noframes",
  1943. "noembed",
  1944. "title",
  1945. "style",
  1946. "textarea",
  1947. "xmp"
  1948. ], tag);
  1949. };
  1950. var getLanguage = function(element) {
  1951. return isElement(element) ? getOpt(element, "lang") : Optional.none();
  1952. };
  1953. return {
  1954. up: constant({
  1955. selector: ancestor$1,
  1956. closest: closest$1,
  1957. predicate: ancestor$2,
  1958. all: parents
  1959. }),
  1960. down: constant({
  1961. selector: descendants,
  1962. predicate: descendants$1
  1963. }),
  1964. styles: constant({
  1965. get: get$a,
  1966. getRaw: getRaw$2,
  1967. set: set$1,
  1968. remove: remove$6
  1969. }),
  1970. attrs: constant({
  1971. get: get$b,
  1972. set: set$2,
  1973. remove: remove$7,
  1974. copyTo: copyAttributesTo
  1975. }),
  1976. insert: constant({
  1977. before: before$4,
  1978. after: after$5,
  1979. afterAll: after$4,
  1980. append: append$1,
  1981. appendAll: append,
  1982. prepend,
  1983. wrap
  1984. }),
  1985. remove: constant({
  1986. unwrap,
  1987. remove: remove$5
  1988. }),
  1989. create: constant({
  1990. nu: SugarElement.fromTag,
  1991. clone: clone2,
  1992. text: SugarElement.fromText
  1993. }),
  1994. query: constant({
  1995. comparePosition,
  1996. prevSibling,
  1997. nextSibling
  1998. }),
  1999. property: constant({
  2000. children: children$3,
  2001. name,
  2002. parent,
  2003. document: document2,
  2004. isText,
  2005. isComment,
  2006. isElement,
  2007. isSpecial,
  2008. getLanguage,
  2009. getText: get$9,
  2010. setText: set,
  2011. isBoundary,
  2012. isEmptyTag: isEmptyTag2,
  2013. isNonEditable
  2014. }),
  2015. eq: eq$1,
  2016. is: is$1
  2017. };
  2018. }
  2019. var all = function(universe2, look, elements, f) {
  2020. var head2 = elements[0];
  2021. var tail = elements.slice(1);
  2022. return f(universe2, look, head2, tail);
  2023. };
  2024. var oneAll = function(universe2, look, elements) {
  2025. return elements.length > 0 ? all(universe2, look, elements, unsafeOne) : Optional.none();
  2026. };
  2027. var unsafeOne = function(universe2, look, head2, tail) {
  2028. var start = look(universe2, head2);
  2029. return foldr(tail, function(b, a) {
  2030. var current = look(universe2, a);
  2031. return commonElement(universe2, b, current);
  2032. }, start);
  2033. };
  2034. var commonElement = function(universe2, start, end) {
  2035. return start.bind(function(s) {
  2036. return end.filter(curry(universe2.eq, s));
  2037. });
  2038. };
  2039. var eq = function(universe2, item) {
  2040. return curry(universe2.eq, item);
  2041. };
  2042. var ancestors$2 = function(universe2, start, end, isRoot) {
  2043. if (isRoot === void 0) {
  2044. isRoot = never;
  2045. }
  2046. var ps1 = [start].concat(universe2.up().all(start));
  2047. var ps2 = [end].concat(universe2.up().all(end));
  2048. var prune2 = function(path) {
  2049. var index = findIndex(path, isRoot);
  2050. return index.fold(function() {
  2051. return path;
  2052. }, function(ind) {
  2053. return path.slice(0, ind + 1);
  2054. });
  2055. };
  2056. var pruned1 = prune2(ps1);
  2057. var pruned2 = prune2(ps2);
  2058. var shared = find$1(pruned1, function(x) {
  2059. return exists(pruned2, eq(universe2, x));
  2060. });
  2061. return {
  2062. firstpath: pruned1,
  2063. secondpath: pruned2,
  2064. shared
  2065. };
  2066. };
  2067. var sharedOne$1 = oneAll;
  2068. var ancestors$1 = ancestors$2;
  2069. var universe$3 = DomUniverse();
  2070. var sharedOne = function(look, elements) {
  2071. return sharedOne$1(universe$3, function(_universe, element) {
  2072. return look(element);
  2073. }, elements);
  2074. };
  2075. var ancestors = function(start, finish, isRoot) {
  2076. return ancestors$1(universe$3, start, finish, isRoot);
  2077. };
  2078. var lookupTable = function(container) {
  2079. return ancestor$1(container, "table");
  2080. };
  2081. var identify = function(start, finish, isRoot) {
  2082. var getIsRoot2 = function(rootTable) {
  2083. return function(element) {
  2084. return isRoot !== void 0 && isRoot(element) || eq$1(element, rootTable);
  2085. };
  2086. };
  2087. if (eq$1(start, finish)) {
  2088. return Optional.some({
  2089. boxes: Optional.some([start]),
  2090. start,
  2091. finish
  2092. });
  2093. } else {
  2094. return lookupTable(start).bind(function(startTable) {
  2095. return lookupTable(finish).bind(function(finishTable) {
  2096. if (eq$1(startTable, finishTable)) {
  2097. return Optional.some({
  2098. boxes: intercepts(startTable, start, finish),
  2099. start,
  2100. finish
  2101. });
  2102. } else if (contains(startTable, finishTable)) {
  2103. var ancestorCells = ancestors$3(finish, "td,th", getIsRoot2(startTable));
  2104. var finishCell = ancestorCells.length > 0 ? ancestorCells[ancestorCells.length - 1] : finish;
  2105. return Optional.some({
  2106. boxes: nestedIntercepts(startTable, start, startTable, finish, finishTable),
  2107. start,
  2108. finish: finishCell
  2109. });
  2110. } else if (contains(finishTable, startTable)) {
  2111. var ancestorCells = ancestors$3(start, "td,th", getIsRoot2(finishTable));
  2112. var startCell = ancestorCells.length > 0 ? ancestorCells[ancestorCells.length - 1] : start;
  2113. return Optional.some({
  2114. boxes: nestedIntercepts(finishTable, start, startTable, finish, finishTable),
  2115. start,
  2116. finish: startCell
  2117. });
  2118. } else {
  2119. return ancestors(start, finish).shared.bind(function(lca) {
  2120. return closest$1(lca, "table", isRoot).bind(function(lcaTable) {
  2121. var finishAncestorCells = ancestors$3(finish, "td,th", getIsRoot2(lcaTable));
  2122. var finishCell2 = finishAncestorCells.length > 0 ? finishAncestorCells[finishAncestorCells.length - 1] : finish;
  2123. var startAncestorCells = ancestors$3(start, "td,th", getIsRoot2(lcaTable));
  2124. var startCell2 = startAncestorCells.length > 0 ? startAncestorCells[startAncestorCells.length - 1] : start;
  2125. return Optional.some({
  2126. boxes: nestedIntercepts(lcaTable, start, startTable, finish, finishTable),
  2127. start: startCell2,
  2128. finish: finishCell2
  2129. });
  2130. });
  2131. });
  2132. }
  2133. });
  2134. });
  2135. }
  2136. };
  2137. var retrieve$1 = function(container, selector) {
  2138. var sels = descendants(container, selector);
  2139. return sels.length > 0 ? Optional.some(sels) : Optional.none();
  2140. };
  2141. var getLast = function(boxes, lastSelectedSelector) {
  2142. return find$1(boxes, function(box) {
  2143. return is$2(box, lastSelectedSelector);
  2144. });
  2145. };
  2146. var getEdges = function(container, firstSelectedSelector, lastSelectedSelector) {
  2147. return descendant(container, firstSelectedSelector).bind(function(first2) {
  2148. return descendant(container, lastSelectedSelector).bind(function(last2) {
  2149. return sharedOne(lookupTable, [
  2150. first2,
  2151. last2
  2152. ]).map(function(table2) {
  2153. return {
  2154. first: first2,
  2155. last: last2,
  2156. table: table2
  2157. };
  2158. });
  2159. });
  2160. });
  2161. };
  2162. var expandTo = function(finish, firstSelectedSelector) {
  2163. return ancestor$1(finish, "table").bind(function(table2) {
  2164. return descendant(table2, firstSelectedSelector).bind(function(start) {
  2165. return identify(start, finish).bind(function(identified) {
  2166. return identified.boxes.map(function(boxes) {
  2167. return {
  2168. boxes,
  2169. start: identified.start,
  2170. finish: identified.finish
  2171. };
  2172. });
  2173. });
  2174. });
  2175. });
  2176. };
  2177. var shiftSelection = function(boxes, deltaRow, deltaColumn, firstSelectedSelector, lastSelectedSelector) {
  2178. return getLast(boxes, lastSelectedSelector).bind(function(last2) {
  2179. return moveBy(last2, deltaRow, deltaColumn).bind(function(finish) {
  2180. return expandTo(finish, firstSelectedSelector);
  2181. });
  2182. });
  2183. };
  2184. var retrieve = function(container, selector) {
  2185. return retrieve$1(container, selector);
  2186. };
  2187. var retrieveBox = function(container, firstSelectedSelector, lastSelectedSelector) {
  2188. return getEdges(container, firstSelectedSelector, lastSelectedSelector).bind(function(edges) {
  2189. var isRoot = function(ancestor2) {
  2190. return eq$1(container, ancestor2);
  2191. };
  2192. var sectionSelector = "thead,tfoot,tbody,table";
  2193. var firstAncestor = ancestor$1(edges.first, sectionSelector, isRoot);
  2194. var lastAncestor = ancestor$1(edges.last, sectionSelector, isRoot);
  2195. return firstAncestor.bind(function(fA) {
  2196. return lastAncestor.bind(function(lA) {
  2197. return eq$1(fA, lA) ? getBox(edges.table, edges.first, edges.last) : Optional.none();
  2198. });
  2199. });
  2200. });
  2201. };
  2202. var generate = function(cases) {
  2203. if (!isArray(cases)) {
  2204. throw new Error("cases must be an array");
  2205. }
  2206. if (cases.length === 0) {
  2207. throw new Error("there must be at least one case");
  2208. }
  2209. var constructors = [];
  2210. var adt2 = {};
  2211. each$2(cases, function(acase, count) {
  2212. var keys$1 = keys(acase);
  2213. if (keys$1.length !== 1) {
  2214. throw new Error("one and only one name per case");
  2215. }
  2216. var key2 = keys$1[0];
  2217. var value2 = acase[key2];
  2218. if (adt2[key2] !== void 0) {
  2219. throw new Error("duplicate key detected:" + key2);
  2220. } else if (key2 === "cata") {
  2221. throw new Error("cannot have a case named cata (sorry)");
  2222. } else if (!isArray(value2)) {
  2223. throw new Error("case arguments must be an array");
  2224. }
  2225. constructors.push(key2);
  2226. adt2[key2] = function() {
  2227. var args = [];
  2228. for (var _i = 0; _i < arguments.length; _i++) {
  2229. args[_i] = arguments[_i];
  2230. }
  2231. var argLength = args.length;
  2232. if (argLength !== value2.length) {
  2233. throw new Error("Wrong number of arguments to case " + key2 + ". Expected " + value2.length + " (" + value2 + "), got " + argLength);
  2234. }
  2235. var match = function(branches) {
  2236. var branchKeys = keys(branches);
  2237. if (constructors.length !== branchKeys.length) {
  2238. throw new Error("Wrong number of arguments to match. Expected: " + constructors.join(",") + "\nActual: " + branchKeys.join(","));
  2239. }
  2240. var allReqd = forall(constructors, function(reqKey) {
  2241. return contains$2(branchKeys, reqKey);
  2242. });
  2243. if (!allReqd) {
  2244. throw new Error("Not all branches were specified when using match. Specified: " + branchKeys.join(", ") + "\nRequired: " + constructors.join(", "));
  2245. }
  2246. return branches[key2].apply(null, args);
  2247. };
  2248. return {
  2249. fold: function() {
  2250. var foldArgs = [];
  2251. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  2252. foldArgs[_i2] = arguments[_i2];
  2253. }
  2254. if (foldArgs.length !== cases.length) {
  2255. throw new Error("Wrong number of arguments to fold. Expected " + cases.length + ", got " + foldArgs.length);
  2256. }
  2257. var target = foldArgs[count];
  2258. return target.apply(null, args);
  2259. },
  2260. match,
  2261. log: function(label) {
  2262. console.log(label, {
  2263. constructors,
  2264. constructor: key2,
  2265. params: args
  2266. });
  2267. }
  2268. };
  2269. };
  2270. });
  2271. return adt2;
  2272. };
  2273. var Adt = { generate };
  2274. var type = Adt.generate([
  2275. { none: [] },
  2276. { multiple: ["elements"] },
  2277. { single: ["element"] }
  2278. ]);
  2279. var cata$2 = function(subject, onNone, onMultiple, onSingle) {
  2280. return subject.fold(onNone, onMultiple, onSingle);
  2281. };
  2282. var none$1 = type.none;
  2283. var multiple = type.multiple;
  2284. var single = type.single;
  2285. var Selections = function(lazyRoot, getStart2, selectedSelector) {
  2286. var get2 = function() {
  2287. return retrieve(lazyRoot(), selectedSelector).fold(function() {
  2288. return getStart2().fold(none$1, single);
  2289. }, function(cells2) {
  2290. return multiple(cells2);
  2291. });
  2292. };
  2293. return { get: get2 };
  2294. };
  2295. var global$3 = tinymce.util.Tools.resolve("tinymce.PluginManager");
  2296. var clone = function(original, isDeep) {
  2297. return SugarElement.fromDom(original.dom.cloneNode(isDeep));
  2298. };
  2299. var shallow = function(original) {
  2300. return clone(original, false);
  2301. };
  2302. var deep = function(original) {
  2303. return clone(original, true);
  2304. };
  2305. var shallowAs = function(original, tag) {
  2306. var nu2 = SugarElement.fromTag(tag);
  2307. var attributes = clone$2(original);
  2308. setAll$1(nu2, attributes);
  2309. return nu2;
  2310. };
  2311. var copy$1 = function(original, tag) {
  2312. var nu2 = shallowAs(original, tag);
  2313. var cloneChildren = children$3(deep(original));
  2314. append(nu2, cloneChildren);
  2315. return nu2;
  2316. };
  2317. var mutate$1 = function(original, tag) {
  2318. var nu2 = shallowAs(original, tag);
  2319. before$4(original, nu2);
  2320. var children2 = children$3(original);
  2321. append(nu2, children2);
  2322. remove$5(original);
  2323. return nu2;
  2324. };
  2325. var Dimension = function(name2, getOffset) {
  2326. var set2 = function(element, h) {
  2327. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  2328. throw new Error(name2 + ".set accepts only positive integer values. Value was " + h);
  2329. }
  2330. var dom = element.dom;
  2331. if (isSupported(dom)) {
  2332. dom.style[name2] = h + "px";
  2333. }
  2334. };
  2335. var get2 = function(element) {
  2336. var r2 = getOffset(element);
  2337. if (r2 <= 0 || r2 === null) {
  2338. var css2 = get$a(element, name2);
  2339. return parseFloat(css2) || 0;
  2340. }
  2341. return r2;
  2342. };
  2343. var getOuter2 = get2;
  2344. var aggregate = function(element, properties) {
  2345. return foldl(properties, function(acc, property) {
  2346. var val = get$a(element, property);
  2347. var value2 = val === void 0 ? 0 : parseInt(val, 10);
  2348. return isNaN(value2) ? acc : acc + value2;
  2349. }, 0);
  2350. };
  2351. var max = function(element, value2, properties) {
  2352. var cumulativeInclusions = aggregate(element, properties);
  2353. var absoluteMax = value2 > cumulativeInclusions ? value2 - cumulativeInclusions : 0;
  2354. return absoluteMax;
  2355. };
  2356. return {
  2357. set: set2,
  2358. get: get2,
  2359. getOuter: getOuter2,
  2360. aggregate,
  2361. max
  2362. };
  2363. };
  2364. var needManualCalc = function() {
  2365. var browser = detect$3().browser;
  2366. return browser.isIE() || browser.isEdge();
  2367. };
  2368. var toNumber = function(px, fallback2) {
  2369. return toFloat(px).getOr(fallback2);
  2370. };
  2371. var getProp = function(element, name2, fallback2) {
  2372. return toNumber(get$a(element, name2), fallback2);
  2373. };
  2374. var getBoxSizing = function(element) {
  2375. return get$a(element, "box-sizing");
  2376. };
  2377. var calcContentBoxSize = function(element, size2, upper, lower) {
  2378. var paddingUpper = getProp(element, "padding-" + upper, 0);
  2379. var paddingLower = getProp(element, "padding-" + lower, 0);
  2380. var borderUpper = getProp(element, "border-" + upper + "-width", 0);
  2381. var borderLower = getProp(element, "border-" + lower + "-width", 0);
  2382. return size2 - paddingUpper - paddingLower - borderUpper - borderLower;
  2383. };
  2384. var getCalculatedHeight = function(element, boxSizing) {
  2385. var dom = element.dom;
  2386. var height2 = dom.getBoundingClientRect().height || dom.offsetHeight;
  2387. return boxSizing === "border-box" ? height2 : calcContentBoxSize(element, height2, "top", "bottom");
  2388. };
  2389. var getCalculatedWidth = function(element, boxSizing) {
  2390. var dom = element.dom;
  2391. var width2 = dom.getBoundingClientRect().width || dom.offsetWidth;
  2392. return boxSizing === "border-box" ? width2 : calcContentBoxSize(element, width2, "left", "right");
  2393. };
  2394. var getHeight$1 = function(element) {
  2395. return needManualCalc() ? getCalculatedHeight(element, getBoxSizing(element)) : getProp(element, "height", element.dom.offsetHeight);
  2396. };
  2397. var getWidth = function(element) {
  2398. return needManualCalc() ? getCalculatedWidth(element, getBoxSizing(element)) : getProp(element, "width", element.dom.offsetWidth);
  2399. };
  2400. var getInnerWidth = function(element) {
  2401. return getCalculatedWidth(element, "content-box");
  2402. };
  2403. var api$1 = Dimension("width", function(element) {
  2404. return element.dom.offsetWidth;
  2405. });
  2406. var get$8 = function(element) {
  2407. return api$1.get(element);
  2408. };
  2409. var getOuter$2 = function(element) {
  2410. return api$1.getOuter(element);
  2411. };
  2412. var getInner = getInnerWidth;
  2413. var getRuntime$1 = getWidth;
  2414. var columns = function(warehouse, isValidCell) {
  2415. if (isValidCell === void 0) {
  2416. isValidCell = always;
  2417. }
  2418. var grid2 = warehouse.grid;
  2419. var cols = range$1(grid2.columns, identity);
  2420. var rowsArr = range$1(grid2.rows, identity);
  2421. return map$1(cols, function(col2) {
  2422. var getBlock = function() {
  2423. return bind$2(rowsArr, function(r2) {
  2424. return Warehouse.getAt(warehouse, r2, col2).filter(function(detail2) {
  2425. return detail2.column === col2;
  2426. }).toArray();
  2427. });
  2428. };
  2429. var isValid = function(detail2) {
  2430. return detail2.colspan === 1 && isValidCell(detail2.element);
  2431. };
  2432. var getFallback = function() {
  2433. return Warehouse.getAt(warehouse, 0, col2);
  2434. };
  2435. return decide(getBlock, isValid, getFallback);
  2436. });
  2437. };
  2438. var decide = function(getBlock, isValid, getFallback) {
  2439. var inBlock = getBlock();
  2440. var validInBlock = find$1(inBlock, isValid);
  2441. var detailOption = validInBlock.orThunk(function() {
  2442. return Optional.from(inBlock[0]).orThunk(getFallback);
  2443. });
  2444. return detailOption.map(function(detail2) {
  2445. return detail2.element;
  2446. });
  2447. };
  2448. var rows = function(warehouse) {
  2449. var grid2 = warehouse.grid;
  2450. var rowsArr = range$1(grid2.rows, identity);
  2451. var cols = range$1(grid2.columns, identity);
  2452. return map$1(rowsArr, function(row2) {
  2453. var getBlock = function() {
  2454. return bind$2(cols, function(c) {
  2455. return Warehouse.getAt(warehouse, row2, c).filter(function(detail2) {
  2456. return detail2.row === row2;
  2457. }).fold(constant([]), function(detail2) {
  2458. return [detail2];
  2459. });
  2460. });
  2461. };
  2462. var isSingle = function(detail2) {
  2463. return detail2.rowspan === 1;
  2464. };
  2465. var getFallback = function() {
  2466. return Warehouse.getAt(warehouse, row2, 0);
  2467. };
  2468. return decide(getBlock, isSingle, getFallback);
  2469. });
  2470. };
  2471. var deduce = function(xs, index) {
  2472. if (index < 0 || index >= xs.length - 1) {
  2473. return Optional.none();
  2474. }
  2475. var current = xs[index].fold(function() {
  2476. var rest = reverse(xs.slice(0, index));
  2477. return findMap(rest, function(a, i) {
  2478. return a.map(function(aa) {
  2479. return {
  2480. value: aa,
  2481. delta: i + 1
  2482. };
  2483. });
  2484. });
  2485. }, function(c) {
  2486. return Optional.some({
  2487. value: c,
  2488. delta: 0
  2489. });
  2490. });
  2491. var next2 = xs[index + 1].fold(function() {
  2492. var rest = xs.slice(index + 1);
  2493. return findMap(rest, function(a, i) {
  2494. return a.map(function(aa) {
  2495. return {
  2496. value: aa,
  2497. delta: i + 1
  2498. };
  2499. });
  2500. });
  2501. }, function(n) {
  2502. return Optional.some({
  2503. value: n,
  2504. delta: 1
  2505. });
  2506. });
  2507. return current.bind(function(c) {
  2508. return next2.map(function(n) {
  2509. var extras = n.delta + c.delta;
  2510. return Math.abs(n.value - c.value) / extras;
  2511. });
  2512. });
  2513. };
  2514. var onDirection = function(isLtr, isRtl) {
  2515. return function(element) {
  2516. return getDirection(element) === "rtl" ? isRtl : isLtr;
  2517. };
  2518. };
  2519. var getDirection = function(element) {
  2520. return get$a(element, "direction") === "rtl" ? "rtl" : "ltr";
  2521. };
  2522. var api = Dimension("height", function(element) {
  2523. var dom = element.dom;
  2524. return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
  2525. });
  2526. var get$7 = function(element) {
  2527. return api.get(element);
  2528. };
  2529. var getOuter$1 = function(element) {
  2530. return api.getOuter(element);
  2531. };
  2532. var getRuntime = getHeight$1;
  2533. var r = function(left2, top) {
  2534. var translate2 = function(x, y) {
  2535. return r(left2 + x, top + y);
  2536. };
  2537. return {
  2538. left: left2,
  2539. top,
  2540. translate: translate2
  2541. };
  2542. };
  2543. var SugarPosition = r;
  2544. var boxPosition = function(dom) {
  2545. var box = dom.getBoundingClientRect();
  2546. return SugarPosition(box.left, box.top);
  2547. };
  2548. var firstDefinedOrZero = function(a, b) {
  2549. if (a !== void 0) {
  2550. return a;
  2551. } else {
  2552. return b !== void 0 ? b : 0;
  2553. }
  2554. };
  2555. var absolute = function(element) {
  2556. var doc = element.dom.ownerDocument;
  2557. var body2 = doc.body;
  2558. var win = doc.defaultView;
  2559. var html = doc.documentElement;
  2560. if (body2 === element.dom) {
  2561. return SugarPosition(body2.offsetLeft, body2.offsetTop);
  2562. }
  2563. var scrollTop = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageYOffset, html.scrollTop);
  2564. var scrollLeft = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageXOffset, html.scrollLeft);
  2565. var clientTop = firstDefinedOrZero(html.clientTop, body2.clientTop);
  2566. var clientLeft = firstDefinedOrZero(html.clientLeft, body2.clientLeft);
  2567. return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  2568. };
  2569. var viewport = function(element) {
  2570. var dom = element.dom;
  2571. var doc = dom.ownerDocument;
  2572. var body2 = doc.body;
  2573. if (body2 === dom) {
  2574. return SugarPosition(body2.offsetLeft, body2.offsetTop);
  2575. }
  2576. if (!inBody(element)) {
  2577. return SugarPosition(0, 0);
  2578. }
  2579. return boxPosition(dom);
  2580. };
  2581. var rowInfo = function(row2, y) {
  2582. return {
  2583. row: row2,
  2584. y
  2585. };
  2586. };
  2587. var colInfo = function(col2, x) {
  2588. return {
  2589. col: col2,
  2590. x
  2591. };
  2592. };
  2593. var rtlEdge = function(cell2) {
  2594. var pos = absolute(cell2);
  2595. return pos.left + getOuter$2(cell2);
  2596. };
  2597. var ltrEdge = function(cell2) {
  2598. return absolute(cell2).left;
  2599. };
  2600. var getLeftEdge = function(index, cell2) {
  2601. return colInfo(index, ltrEdge(cell2));
  2602. };
  2603. var getRightEdge = function(index, cell2) {
  2604. return colInfo(index, rtlEdge(cell2));
  2605. };
  2606. var getTop$1 = function(cell2) {
  2607. return absolute(cell2).top;
  2608. };
  2609. var getTopEdge = function(index, cell2) {
  2610. return rowInfo(index, getTop$1(cell2));
  2611. };
  2612. var getBottomEdge = function(index, cell2) {
  2613. return rowInfo(index, getTop$1(cell2) + getOuter$1(cell2));
  2614. };
  2615. var findPositions = function(getInnerEdge, getOuterEdge, array) {
  2616. if (array.length === 0) {
  2617. return [];
  2618. }
  2619. var lines = map$1(array.slice(1), function(cellOption, index) {
  2620. return cellOption.map(function(cell2) {
  2621. return getInnerEdge(index, cell2);
  2622. });
  2623. });
  2624. var lastLine = array[array.length - 1].map(function(cell2) {
  2625. return getOuterEdge(array.length - 1, cell2);
  2626. });
  2627. return lines.concat([lastLine]);
  2628. };
  2629. var negate = function(step) {
  2630. return -step;
  2631. };
  2632. var height = {
  2633. delta: identity,
  2634. positions: function(optElements) {
  2635. return findPositions(getTopEdge, getBottomEdge, optElements);
  2636. },
  2637. edge: getTop$1
  2638. };
  2639. var ltr$1 = {
  2640. delta: identity,
  2641. edge: ltrEdge,
  2642. positions: function(optElements) {
  2643. return findPositions(getLeftEdge, getRightEdge, optElements);
  2644. }
  2645. };
  2646. var rtl$1 = {
  2647. delta: negate,
  2648. edge: rtlEdge,
  2649. positions: function(optElements) {
  2650. return findPositions(getRightEdge, getLeftEdge, optElements);
  2651. }
  2652. };
  2653. var detect$2 = onDirection(ltr$1, rtl$1);
  2654. var width = {
  2655. delta: function(amount, table2) {
  2656. return detect$2(table2).delta(amount, table2);
  2657. },
  2658. positions: function(cols, table2) {
  2659. return detect$2(table2).positions(cols, table2);
  2660. },
  2661. edge: function(cell2) {
  2662. return detect$2(cell2).edge(cell2);
  2663. }
  2664. };
  2665. var units = {
  2666. unsupportedLength: [
  2667. "em",
  2668. "ex",
  2669. "cap",
  2670. "ch",
  2671. "ic",
  2672. "rem",
  2673. "lh",
  2674. "rlh",
  2675. "vw",
  2676. "vh",
  2677. "vi",
  2678. "vb",
  2679. "vmin",
  2680. "vmax",
  2681. "cm",
  2682. "mm",
  2683. "Q",
  2684. "in",
  2685. "pc",
  2686. "pt",
  2687. "px"
  2688. ],
  2689. fixed: [
  2690. "px",
  2691. "pt"
  2692. ],
  2693. relative: ["%"],
  2694. empty: [""]
  2695. };
  2696. var pattern = function() {
  2697. var decimalDigits = "[0-9]+";
  2698. var signedInteger = "[+-]?" + decimalDigits;
  2699. var exponentPart = "[eE]" + signedInteger;
  2700. var dot = "\\.";
  2701. var opt = function(input) {
  2702. return "(?:" + input + ")?";
  2703. };
  2704. var unsignedDecimalLiteral = [
  2705. "Infinity",
  2706. decimalDigits + dot + opt(decimalDigits) + opt(exponentPart),
  2707. dot + decimalDigits + opt(exponentPart),
  2708. decimalDigits + opt(exponentPart)
  2709. ].join("|");
  2710. var float = "[+-]?(?:" + unsignedDecimalLiteral + ")";
  2711. return new RegExp("^(" + float + ")(.*)$");
  2712. }();
  2713. var isUnit = function(unit, accepted) {
  2714. return exists(accepted, function(acc) {
  2715. return exists(units[acc], function(check) {
  2716. return unit === check;
  2717. });
  2718. });
  2719. };
  2720. var parse = function(input, accepted) {
  2721. var match = Optional.from(pattern.exec(input));
  2722. return match.bind(function(array) {
  2723. var value2 = Number(array[1]);
  2724. var unitRaw = array[2];
  2725. if (isUnit(unitRaw, accepted)) {
  2726. return Optional.some({
  2727. value: value2,
  2728. unit: unitRaw
  2729. });
  2730. } else {
  2731. return Optional.none();
  2732. }
  2733. });
  2734. };
  2735. var rPercentageBasedSizeRegex = /(\d+(\.\d+)?)%/;
  2736. var rPixelBasedSizeRegex = /(\d+(\.\d+)?)px|em/;
  2737. var isCol$2 = isTag("col");
  2738. var getPercentSize = function(elm, outerGetter, innerGetter) {
  2739. var relativeParent = parentElement(elm).getOrThunk(function() {
  2740. return getBody$1(owner(elm));
  2741. });
  2742. return outerGetter(elm) / innerGetter(relativeParent) * 100;
  2743. };
  2744. var setPixelWidth = function(cell2, amount) {
  2745. set$1(cell2, "width", amount + "px");
  2746. };
  2747. var setPercentageWidth = function(cell2, amount) {
  2748. set$1(cell2, "width", amount + "%");
  2749. };
  2750. var setHeight = function(cell2, amount) {
  2751. set$1(cell2, "height", amount + "px");
  2752. };
  2753. var getHeightValue = function(cell2) {
  2754. return getRuntime(cell2) + "px";
  2755. };
  2756. var convert = function(cell2, number, getter, setter) {
  2757. var newSize = table(cell2).map(function(table2) {
  2758. var total2 = getter(table2);
  2759. return Math.floor(number / 100 * total2);
  2760. }).getOr(number);
  2761. setter(cell2, newSize);
  2762. return newSize;
  2763. };
  2764. var normalizePixelSize = function(value2, cell2, getter, setter) {
  2765. var number = parseFloat(value2);
  2766. return endsWith(value2, "%") && name(cell2) !== "table" ? convert(cell2, number, getter, setter) : number;
  2767. };
  2768. var getTotalHeight = function(cell2) {
  2769. var value2 = getHeightValue(cell2);
  2770. if (!value2) {
  2771. return get$7(cell2);
  2772. }
  2773. return normalizePixelSize(value2, cell2, get$7, setHeight);
  2774. };
  2775. var get$6 = function(cell2, type2, f) {
  2776. var v = f(cell2);
  2777. var span = getSpan(cell2, type2);
  2778. return v / span;
  2779. };
  2780. var getRaw$1 = function(element, prop) {
  2781. return getRaw$2(element, prop).orThunk(function() {
  2782. return getOpt(element, prop).map(function(val) {
  2783. return val + "px";
  2784. });
  2785. });
  2786. };
  2787. var getRawWidth$1 = function(element) {
  2788. return getRaw$1(element, "width");
  2789. };
  2790. var getRawHeight = function(element) {
  2791. return getRaw$1(element, "height");
  2792. };
  2793. var getPercentageWidth = function(cell2) {
  2794. return getPercentSize(cell2, get$8, getInner);
  2795. };
  2796. var getPixelWidth$1 = function(cell2) {
  2797. return isCol$2(cell2) ? get$8(cell2) : getRuntime$1(cell2);
  2798. };
  2799. var getHeight = function(cell2) {
  2800. return get$6(cell2, "rowspan", getTotalHeight);
  2801. };
  2802. var getGenericWidth = function(cell2) {
  2803. var width2 = getRawWidth$1(cell2);
  2804. return width2.bind(function(w) {
  2805. return parse(w, [
  2806. "fixed",
  2807. "relative",
  2808. "empty"
  2809. ]);
  2810. });
  2811. };
  2812. var setGenericWidth = function(cell2, amount, unit) {
  2813. set$1(cell2, "width", amount + unit);
  2814. };
  2815. var getPixelTableWidth = function(table2) {
  2816. return get$8(table2) + "px";
  2817. };
  2818. var getPercentTableWidth = function(table2) {
  2819. return getPercentSize(table2, get$8, getInner) + "%";
  2820. };
  2821. var isPercentSizing$1 = function(table2) {
  2822. return getRawWidth$1(table2).exists(function(size2) {
  2823. return rPercentageBasedSizeRegex.test(size2);
  2824. });
  2825. };
  2826. var isPixelSizing$1 = function(table2) {
  2827. return getRawWidth$1(table2).exists(function(size2) {
  2828. return rPixelBasedSizeRegex.test(size2);
  2829. });
  2830. };
  2831. var isNoneSizing$1 = function(table2) {
  2832. return getRawWidth$1(table2).isNone();
  2833. };
  2834. var percentageBasedSizeRegex = constant(rPercentageBasedSizeRegex);
  2835. var isCol$1 = isTag("col");
  2836. var getRawW = function(cell2) {
  2837. return getRawWidth$1(cell2).getOrThunk(function() {
  2838. return getPixelWidth$1(cell2) + "px";
  2839. });
  2840. };
  2841. var getRawH = function(cell2) {
  2842. return getRawHeight(cell2).getOrThunk(function() {
  2843. return getHeight(cell2) + "px";
  2844. });
  2845. };
  2846. var justCols = function(warehouse) {
  2847. return map$1(Warehouse.justColumns(warehouse), function(column) {
  2848. return Optional.from(column.element);
  2849. });
  2850. };
  2851. var isValidColumn = function(cell2) {
  2852. var browser = detect$3().browser;
  2853. var supportsColWidths = browser.isChrome() || browser.isFirefox();
  2854. return isCol$1(cell2) ? supportsColWidths : true;
  2855. };
  2856. var getDimension = function(cellOpt, index, backups, filter2, getter, fallback2) {
  2857. return cellOpt.filter(filter2).fold(function() {
  2858. return fallback2(deduce(backups, index));
  2859. }, function(cell2) {
  2860. return getter(cell2);
  2861. });
  2862. };
  2863. var getWidthFrom = function(warehouse, table2, getWidth2, fallback2) {
  2864. var columnCells = columns(warehouse);
  2865. var columns$12 = Warehouse.hasColumns(warehouse) ? justCols(warehouse) : columnCells;
  2866. var backups = [Optional.some(width.edge(table2))].concat(map$1(width.positions(columnCells, table2), function(pos) {
  2867. return pos.map(function(p) {
  2868. return p.x;
  2869. });
  2870. }));
  2871. var colFilter = not(hasColspan);
  2872. return map$1(columns$12, function(cellOption, c) {
  2873. return getDimension(cellOption, c, backups, colFilter, function(column) {
  2874. if (isValidColumn(column)) {
  2875. return getWidth2(column);
  2876. } else {
  2877. var cell2 = bindFrom(columnCells[c], identity);
  2878. return getDimension(cell2, c, backups, colFilter, function(cell3) {
  2879. return fallback2(Optional.some(get$8(cell3)));
  2880. }, fallback2);
  2881. }
  2882. }, fallback2);
  2883. });
  2884. };
  2885. var getDeduced = function(deduced) {
  2886. return deduced.map(function(d) {
  2887. return d + "px";
  2888. }).getOr("");
  2889. };
  2890. var getRawWidths = function(warehouse, table2) {
  2891. return getWidthFrom(warehouse, table2, getRawW, getDeduced);
  2892. };
  2893. var getPercentageWidths = function(warehouse, table2, tableSize) {
  2894. return getWidthFrom(warehouse, table2, getPercentageWidth, function(deduced) {
  2895. return deduced.fold(function() {
  2896. return tableSize.minCellWidth();
  2897. }, function(cellWidth) {
  2898. return cellWidth / tableSize.pixelWidth() * 100;
  2899. });
  2900. });
  2901. };
  2902. var getPixelWidths = function(warehouse, table2, tableSize) {
  2903. return getWidthFrom(warehouse, table2, getPixelWidth$1, function(deduced) {
  2904. return deduced.getOrThunk(tableSize.minCellWidth);
  2905. });
  2906. };
  2907. var getHeightFrom = function(warehouse, table2, direction, getHeight2, fallback2) {
  2908. var rows$12 = rows(warehouse);
  2909. var backups = [Optional.some(direction.edge(table2))].concat(map$1(direction.positions(rows$12, table2), function(pos) {
  2910. return pos.map(function(p) {
  2911. return p.y;
  2912. });
  2913. }));
  2914. return map$1(rows$12, function(cellOption, c) {
  2915. return getDimension(cellOption, c, backups, not(hasRowspan), getHeight2, fallback2);
  2916. });
  2917. };
  2918. var getPixelHeights = function(warehouse, table2, direction) {
  2919. return getHeightFrom(warehouse, table2, direction, getHeight, function(deduced) {
  2920. return deduced.getOrThunk(minHeight);
  2921. });
  2922. };
  2923. var getRawHeights = function(warehouse, table2, direction) {
  2924. return getHeightFrom(warehouse, table2, direction, getRawH, getDeduced);
  2925. };
  2926. var widthLookup = function(table2, getter) {
  2927. return function() {
  2928. if (inBody(table2)) {
  2929. return getter(table2);
  2930. } else {
  2931. return parseFloat(getRaw$2(table2, "width").getOr("0"));
  2932. }
  2933. };
  2934. };
  2935. var noneSize = function(table2) {
  2936. var getWidth2 = widthLookup(table2, get$8);
  2937. var zero2 = constant(0);
  2938. var getWidths = function(warehouse, tableSize) {
  2939. return getPixelWidths(warehouse, table2, tableSize);
  2940. };
  2941. return {
  2942. width: getWidth2,
  2943. pixelWidth: getWidth2,
  2944. getWidths,
  2945. getCellDelta: zero2,
  2946. singleColumnWidth: constant([0]),
  2947. minCellWidth: zero2,
  2948. setElementWidth: noop,
  2949. adjustTableWidth: noop,
  2950. isRelative: true,
  2951. label: "none"
  2952. };
  2953. };
  2954. var percentageSize = function(table2) {
  2955. var getFloatWidth = widthLookup(table2, function(elem) {
  2956. return parseFloat(getPercentTableWidth(elem));
  2957. });
  2958. var getWidth2 = widthLookup(table2, get$8);
  2959. var getCellDelta = function(delta) {
  2960. return delta / getWidth2() * 100;
  2961. };
  2962. var singleColumnWidth = function(w, _delta) {
  2963. return [100 - w];
  2964. };
  2965. var minCellWidth = function() {
  2966. return minWidth() / getWidth2() * 100;
  2967. };
  2968. var adjustTableWidth = function(delta) {
  2969. var currentWidth = getFloatWidth();
  2970. var change = delta / 100 * currentWidth;
  2971. var newWidth = currentWidth + change;
  2972. setPercentageWidth(table2, newWidth);
  2973. };
  2974. var getWidths = function(warehouse, tableSize) {
  2975. return getPercentageWidths(warehouse, table2, tableSize);
  2976. };
  2977. return {
  2978. width: getFloatWidth,
  2979. pixelWidth: getWidth2,
  2980. getWidths,
  2981. getCellDelta,
  2982. singleColumnWidth,
  2983. minCellWidth,
  2984. setElementWidth: setPercentageWidth,
  2985. adjustTableWidth,
  2986. isRelative: true,
  2987. label: "percent"
  2988. };
  2989. };
  2990. var pixelSize = function(table2) {
  2991. var getWidth2 = widthLookup(table2, get$8);
  2992. var getCellDelta = identity;
  2993. var singleColumnWidth = function(w, delta) {
  2994. var newNext = Math.max(minWidth(), w + delta);
  2995. return [newNext - w];
  2996. };
  2997. var adjustTableWidth = function(delta) {
  2998. var newWidth = getWidth2() + delta;
  2999. setPixelWidth(table2, newWidth);
  3000. };
  3001. var getWidths = function(warehouse, tableSize) {
  3002. return getPixelWidths(warehouse, table2, tableSize);
  3003. };
  3004. return {
  3005. width: getWidth2,
  3006. pixelWidth: getWidth2,
  3007. getWidths,
  3008. getCellDelta,
  3009. singleColumnWidth,
  3010. minCellWidth: minWidth,
  3011. setElementWidth: setPixelWidth,
  3012. adjustTableWidth,
  3013. isRelative: false,
  3014. label: "pixel"
  3015. };
  3016. };
  3017. var chooseSize = function(element, width2) {
  3018. var percentMatch = percentageBasedSizeRegex().exec(width2);
  3019. if (percentMatch !== null) {
  3020. return percentageSize(element);
  3021. } else {
  3022. return pixelSize(element);
  3023. }
  3024. };
  3025. var getTableSize = function(table2) {
  3026. var width2 = getRawWidth$1(table2);
  3027. return width2.fold(function() {
  3028. return noneSize(table2);
  3029. }, function(w) {
  3030. return chooseSize(table2, w);
  3031. });
  3032. };
  3033. var TableSize = {
  3034. getTableSize,
  3035. pixelSize,
  3036. percentageSize,
  3037. noneSize
  3038. };
  3039. var statsStruct = function(minRow, minCol, maxRow, maxCol, allCells, selectedCells) {
  3040. return {
  3041. minRow,
  3042. minCol,
  3043. maxRow,
  3044. maxCol,
  3045. allCells,
  3046. selectedCells
  3047. };
  3048. };
  3049. var findSelectedStats = function(house, isSelected) {
  3050. var totalColumns = house.grid.columns;
  3051. var totalRows = house.grid.rows;
  3052. var minRow = totalRows;
  3053. var minCol = totalColumns;
  3054. var maxRow = 0;
  3055. var maxCol = 0;
  3056. var allCells = [];
  3057. var selectedCells = [];
  3058. each$1(house.access, function(detail2) {
  3059. allCells.push(detail2);
  3060. if (isSelected(detail2)) {
  3061. selectedCells.push(detail2);
  3062. var startRow = detail2.row;
  3063. var endRow = startRow + detail2.rowspan - 1;
  3064. var startCol = detail2.column;
  3065. var endCol = startCol + detail2.colspan - 1;
  3066. if (startRow < minRow) {
  3067. minRow = startRow;
  3068. } else if (endRow > maxRow) {
  3069. maxRow = endRow;
  3070. }
  3071. if (startCol < minCol) {
  3072. minCol = startCol;
  3073. } else if (endCol > maxCol) {
  3074. maxCol = endCol;
  3075. }
  3076. }
  3077. });
  3078. return statsStruct(minRow, minCol, maxRow, maxCol, allCells, selectedCells);
  3079. };
  3080. var makeCell = function(list, seenSelected, rowIndex) {
  3081. var row2 = list[rowIndex].element;
  3082. var td = SugarElement.fromTag("td");
  3083. append$1(td, SugarElement.fromTag("br"));
  3084. var f = seenSelected ? append$1 : prepend;
  3085. f(row2, td);
  3086. };
  3087. var fillInGaps = function(list, house, stats, isSelected) {
  3088. var totalColumns = house.grid.columns;
  3089. var totalRows = house.grid.rows;
  3090. for (var i = 0; i < totalRows; i++) {
  3091. var seenSelected = false;
  3092. for (var j = 0; j < totalColumns; j++) {
  3093. if (!(i < stats.minRow || i > stats.maxRow || j < stats.minCol || j > stats.maxCol)) {
  3094. var needCell = Warehouse.getAt(house, i, j).filter(isSelected).isNone();
  3095. if (needCell) {
  3096. makeCell(list, seenSelected, i);
  3097. } else {
  3098. seenSelected = true;
  3099. }
  3100. }
  3101. }
  3102. }
  3103. };
  3104. var clean = function(replica, stats, house, widthDelta) {
  3105. each$1(house.columns, function(col2) {
  3106. if (col2.column < stats.minCol || col2.column > stats.maxCol) {
  3107. remove$5(col2.element);
  3108. }
  3109. });
  3110. var emptyRows = filter$2(firstLayer(replica, "tr"), function(row2) {
  3111. return row2.dom.childElementCount === 0;
  3112. });
  3113. each$2(emptyRows, remove$5);
  3114. if (stats.minCol === stats.maxCol || stats.minRow === stats.maxRow) {
  3115. each$2(firstLayer(replica, "th,td"), function(cell2) {
  3116. remove$7(cell2, "rowspan");
  3117. remove$7(cell2, "colspan");
  3118. });
  3119. }
  3120. remove$7(replica, LOCKED_COL_ATTR);
  3121. remove$7(replica, "data-snooker-col-series");
  3122. var tableSize = TableSize.getTableSize(replica);
  3123. tableSize.adjustTableWidth(widthDelta);
  3124. };
  3125. var getTableWidthDelta = function(table2, warehouse, tableSize, stats) {
  3126. if (stats.minCol === 0 && warehouse.grid.columns === stats.maxCol + 1) {
  3127. return 0;
  3128. }
  3129. var colWidths = getPixelWidths(warehouse, table2, tableSize);
  3130. var allColsWidth = foldl(colWidths, function(acc, width2) {
  3131. return acc + width2;
  3132. }, 0);
  3133. var selectedColsWidth = foldl(colWidths.slice(stats.minCol, stats.maxCol + 1), function(acc, width2) {
  3134. return acc + width2;
  3135. }, 0);
  3136. var newWidth = selectedColsWidth / allColsWidth * tableSize.pixelWidth();
  3137. var delta = newWidth - tableSize.pixelWidth();
  3138. return tableSize.getCellDelta(delta);
  3139. };
  3140. var extract$1 = function(table2, selectedSelector) {
  3141. var isSelected = function(detail2) {
  3142. return is$2(detail2.element, selectedSelector);
  3143. };
  3144. var replica = deep(table2);
  3145. var list = fromTable$1(replica);
  3146. var tableSize = TableSize.getTableSize(table2);
  3147. var replicaHouse = Warehouse.generate(list);
  3148. var replicaStats = findSelectedStats(replicaHouse, isSelected);
  3149. var selector = "th:not(" + selectedSelector + "),td:not(" + selectedSelector + ")";
  3150. var unselectedCells = filterFirstLayer(replica, "th,td", function(cell2) {
  3151. return is$2(cell2, selector);
  3152. });
  3153. each$2(unselectedCells, remove$5);
  3154. fillInGaps(list, replicaHouse, replicaStats, isSelected);
  3155. var house = Warehouse.fromTable(table2);
  3156. var widthDelta = getTableWidthDelta(table2, house, tableSize, replicaStats);
  3157. clean(replica, replicaStats, replicaHouse, widthDelta);
  3158. return replica;
  3159. };
  3160. var nbsp = " ";
  3161. var getEnd = function(element) {
  3162. return name(element) === "img" ? 1 : getOption(element).fold(function() {
  3163. return children$3(element).length;
  3164. }, function(v) {
  3165. return v.length;
  3166. });
  3167. };
  3168. var isTextNodeWithCursorPosition = function(el) {
  3169. return getOption(el).filter(function(text) {
  3170. return text.trim().length !== 0 || text.indexOf(nbsp) > -1;
  3171. }).isSome();
  3172. };
  3173. var elementsWithCursorPosition = [
  3174. "img",
  3175. "br"
  3176. ];
  3177. var isCursorPosition = function(elem) {
  3178. var hasCursorPosition = isTextNodeWithCursorPosition(elem);
  3179. return hasCursorPosition || contains$2(elementsWithCursorPosition, name(elem));
  3180. };
  3181. var first = function(element) {
  3182. return descendant$1(element, isCursorPosition);
  3183. };
  3184. var last$1 = function(element) {
  3185. return descendantRtl(element, isCursorPosition);
  3186. };
  3187. var descendantRtl = function(scope, predicate) {
  3188. var descend = function(element) {
  3189. var children2 = children$3(element);
  3190. for (var i = children2.length - 1; i >= 0; i--) {
  3191. var child2 = children2[i];
  3192. if (predicate(child2)) {
  3193. return Optional.some(child2);
  3194. }
  3195. var res = descend(child2);
  3196. if (res.isSome()) {
  3197. return res;
  3198. }
  3199. }
  3200. return Optional.none();
  3201. };
  3202. return descend(scope);
  3203. };
  3204. var transferableAttributes = {
  3205. scope: [
  3206. "row",
  3207. "col"
  3208. ]
  3209. };
  3210. var createCell = function(doc) {
  3211. return function() {
  3212. var td = SugarElement.fromTag("td", doc.dom);
  3213. append$1(td, SugarElement.fromTag("br", doc.dom));
  3214. return td;
  3215. };
  3216. };
  3217. var createCol = function(doc) {
  3218. return function() {
  3219. return SugarElement.fromTag("col", doc.dom);
  3220. };
  3221. };
  3222. var createColgroup = function(doc) {
  3223. return function() {
  3224. return SugarElement.fromTag("colgroup", doc.dom);
  3225. };
  3226. };
  3227. var createRow$1 = function(doc) {
  3228. return function() {
  3229. return SugarElement.fromTag("tr", doc.dom);
  3230. };
  3231. };
  3232. var replace$1 = function(cell2, tag, attrs) {
  3233. var replica = copy$1(cell2, tag);
  3234. each$1(attrs, function(v, k) {
  3235. if (v === null) {
  3236. remove$7(replica, k);
  3237. } else {
  3238. set$2(replica, k, v);
  3239. }
  3240. });
  3241. return replica;
  3242. };
  3243. var pasteReplace = function(cell2) {
  3244. return cell2;
  3245. };
  3246. var cloneFormats = function(oldCell, newCell, formats) {
  3247. var first$1 = first(oldCell);
  3248. return first$1.map(function(firstText) {
  3249. var formatSelector = formats.join(",");
  3250. var parents2 = ancestors$3(firstText, formatSelector, function(element) {
  3251. return eq$1(element, oldCell);
  3252. });
  3253. return foldr(parents2, function(last2, parent2) {
  3254. var clonedFormat = shallow(parent2);
  3255. remove$7(clonedFormat, "contenteditable");
  3256. append$1(last2, clonedFormat);
  3257. return clonedFormat;
  3258. }, newCell);
  3259. }).getOr(newCell);
  3260. };
  3261. var cloneAppropriateAttributes = function(original, clone2) {
  3262. each$1(transferableAttributes, function(validAttributes, attributeName) {
  3263. return getOpt(original, attributeName).filter(function(attribute) {
  3264. return contains$2(validAttributes, attribute);
  3265. }).each(function(attribute) {
  3266. return set$2(clone2, attributeName, attribute);
  3267. });
  3268. });
  3269. };
  3270. var cellOperations = function(mutate2, doc, formatsToClone) {
  3271. var cloneCss = function(prev2, clone2) {
  3272. copy$2(prev2.element, clone2);
  3273. remove$6(clone2, "height");
  3274. if (prev2.colspan !== 1) {
  3275. remove$6(clone2, "width");
  3276. }
  3277. };
  3278. var newCell = function(prev2) {
  3279. var td = SugarElement.fromTag(name(prev2.element), doc.dom);
  3280. var formats = formatsToClone.getOr([
  3281. "strong",
  3282. "em",
  3283. "b",
  3284. "i",
  3285. "span",
  3286. "font",
  3287. "h1",
  3288. "h2",
  3289. "h3",
  3290. "h4",
  3291. "h5",
  3292. "h6",
  3293. "p",
  3294. "div"
  3295. ]);
  3296. var lastNode = formats.length > 0 ? cloneFormats(prev2.element, td, formats) : td;
  3297. append$1(lastNode, SugarElement.fromTag("br"));
  3298. cloneCss(prev2, td);
  3299. cloneAppropriateAttributes(prev2.element, td);
  3300. mutate2(prev2.element, td);
  3301. return td;
  3302. };
  3303. var newCol = function(prev2) {
  3304. var col2 = SugarElement.fromTag(name(prev2.element), doc.dom);
  3305. cloneCss(prev2, col2);
  3306. mutate2(prev2.element, col2);
  3307. return col2;
  3308. };
  3309. return {
  3310. col: newCol,
  3311. colgroup: createColgroup(doc),
  3312. row: createRow$1(doc),
  3313. cell: newCell,
  3314. replace: replace$1,
  3315. colGap: createCol(doc),
  3316. gap: createCell(doc)
  3317. };
  3318. };
  3319. var paste$1 = function(doc) {
  3320. return {
  3321. col: createCol(doc),
  3322. colgroup: createColgroup(doc),
  3323. row: createRow$1(doc),
  3324. cell: createCell(doc),
  3325. replace: pasteReplace,
  3326. colGap: createCol(doc),
  3327. gap: createCell(doc)
  3328. };
  3329. };
  3330. var fromHtml = function(html, scope) {
  3331. var doc = scope || document;
  3332. var div = doc.createElement("div");
  3333. div.innerHTML = html;
  3334. return children$3(SugarElement.fromDom(div));
  3335. };
  3336. var fromDom = function(nodes) {
  3337. return map$1(nodes, SugarElement.fromDom);
  3338. };
  3339. var getNodeName = function(elm) {
  3340. return elm.nodeName.toLowerCase();
  3341. };
  3342. var getBody = function(editor) {
  3343. return SugarElement.fromDom(editor.getBody());
  3344. };
  3345. var getPixelWidth = function(elm) {
  3346. return elm.getBoundingClientRect().width;
  3347. };
  3348. var getPixelHeight = function(elm) {
  3349. return elm.getBoundingClientRect().height;
  3350. };
  3351. var getIsRoot = function(editor) {
  3352. return function(element) {
  3353. return eq$1(element, getBody(editor));
  3354. };
  3355. };
  3356. var removePxSuffix = function(size2) {
  3357. return size2 ? size2.replace(/px$/, "") : "";
  3358. };
  3359. var addPxSuffix = function(size2) {
  3360. return /^\d+(\.\d+)?$/.test(size2) ? size2 + "px" : size2;
  3361. };
  3362. var removeDataStyle = function(table2) {
  3363. remove$7(table2, "data-mce-style");
  3364. var removeStyleAttribute = function(element) {
  3365. return remove$7(element, "data-mce-style");
  3366. };
  3367. each$2(cells$1(table2), removeStyleAttribute);
  3368. each$2(columns$1(table2), removeStyleAttribute);
  3369. each$2(rows$1(table2), removeStyleAttribute);
  3370. };
  3371. var getRawWidth = function(editor, elm) {
  3372. var raw = editor.dom.getStyle(elm, "width") || editor.dom.getAttrib(elm, "width");
  3373. return Optional.from(raw).filter(isNotEmpty);
  3374. };
  3375. var isPercentage$1 = function(value2) {
  3376. return /^(\d+(\.\d+)?)%$/.test(value2);
  3377. };
  3378. var isPixel = function(value2) {
  3379. return /^(\d+(\.\d+)?)px$/.test(value2);
  3380. };
  3381. var getSelectionStart = function(editor) {
  3382. return SugarElement.fromDom(editor.selection.getStart());
  3383. };
  3384. var getSelectionEnd = function(editor) {
  3385. return SugarElement.fromDom(editor.selection.getEnd());
  3386. };
  3387. var selection = function(selections) {
  3388. return cata$2(selections.get(), constant([]), identity, pure);
  3389. };
  3390. var unmergable = function(selections) {
  3391. var hasSpan = function(elem, type2) {
  3392. return getOpt(elem, type2).exists(function(span) {
  3393. return parseInt(span, 10) > 1;
  3394. });
  3395. };
  3396. var hasRowOrColSpan = function(elem) {
  3397. return hasSpan(elem, "rowspan") || hasSpan(elem, "colspan");
  3398. };
  3399. var candidates = selection(selections);
  3400. return candidates.length > 0 && forall(candidates, hasRowOrColSpan) ? Optional.some(candidates) : Optional.none();
  3401. };
  3402. var mergable = function(table2, selections, ephemera2) {
  3403. return cata$2(selections.get(), Optional.none, function(cells2) {
  3404. if (cells2.length <= 1) {
  3405. return Optional.none();
  3406. } else {
  3407. return retrieveBox(table2, ephemera2.firstSelectedSelector, ephemera2.lastSelectedSelector).map(function(bounds2) {
  3408. return {
  3409. bounds: bounds2,
  3410. cells: cells2
  3411. };
  3412. });
  3413. }
  3414. }, Optional.none);
  3415. };
  3416. var strSelected = "data-mce-selected";
  3417. var strSelectedSelector = "td[" + strSelected + "],th[" + strSelected + "]";
  3418. var strAttributeSelector = "[" + strSelected + "]";
  3419. var strFirstSelected = "data-mce-first-selected";
  3420. var strFirstSelectedSelector = "td[" + strFirstSelected + "],th[" + strFirstSelected + "]";
  3421. var strLastSelected = "data-mce-last-selected";
  3422. var strLastSelectedSelector = "td[" + strLastSelected + "],th[" + strLastSelected + "]";
  3423. var attributeSelector = strAttributeSelector;
  3424. var ephemera = {
  3425. selected: strSelected,
  3426. selectedSelector: strSelectedSelector,
  3427. firstSelected: strFirstSelected,
  3428. firstSelectedSelector: strFirstSelectedSelector,
  3429. lastSelected: strLastSelected,
  3430. lastSelectedSelector: strLastSelectedSelector
  3431. };
  3432. var noMenu = function(cell2) {
  3433. return {
  3434. element: cell2,
  3435. mergable: Optional.none(),
  3436. unmergable: Optional.none(),
  3437. selection: [cell2]
  3438. };
  3439. };
  3440. var forMenu = function(selections, table2, cell2) {
  3441. return {
  3442. element: cell2,
  3443. mergable: mergable(table2, selections, ephemera),
  3444. unmergable: unmergable(selections),
  3445. selection: selection(selections)
  3446. };
  3447. };
  3448. var paste = function(element, clipboard, generators) {
  3449. return {
  3450. element,
  3451. clipboard,
  3452. generators
  3453. };
  3454. };
  3455. var pasteRows = function(selections, cell2, clipboard, generators) {
  3456. return {
  3457. selection: selection(selections),
  3458. clipboard,
  3459. generators
  3460. };
  3461. };
  3462. var getSelectionCellFallback = function(element) {
  3463. return table(element).bind(function(table2) {
  3464. return retrieve(table2, ephemera.firstSelectedSelector);
  3465. }).fold(constant(element), function(cells2) {
  3466. return cells2[0];
  3467. });
  3468. };
  3469. var getSelectionFromSelector = function(selector) {
  3470. return function(initCell, isRoot) {
  3471. var cellName = name(initCell);
  3472. var cell2 = cellName === "col" || cellName === "colgroup" ? getSelectionCellFallback(initCell) : initCell;
  3473. return closest$1(cell2, selector, isRoot);
  3474. };
  3475. };
  3476. var getSelectionCellOrCaption = getSelectionFromSelector("th,td,caption");
  3477. var getSelectionCell = getSelectionFromSelector("th,td");
  3478. var getCellsFromSelection = function(selections) {
  3479. return selection(selections);
  3480. };
  3481. var getRowsFromSelection = function(selected, selector) {
  3482. var cellOpt = getSelectionCell(selected);
  3483. var rowsOpt = cellOpt.bind(function(cell2) {
  3484. return table(cell2);
  3485. }).map(function(table2) {
  3486. return rows$1(table2);
  3487. });
  3488. return lift2(cellOpt, rowsOpt, function(cell2, rows2) {
  3489. return filter$2(rows2, function(row2) {
  3490. return exists(fromDom(row2.dom.cells), function(rowCell) {
  3491. return get$b(rowCell, selector) === "1" || eq$1(rowCell, cell2);
  3492. });
  3493. });
  3494. }).getOr([]);
  3495. };
  3496. var extractSelected = function(cells2) {
  3497. return table(cells2[0]).map(function(table2) {
  3498. var replica = extract$1(table2, attributeSelector);
  3499. removeDataStyle(replica);
  3500. return [replica];
  3501. });
  3502. };
  3503. var serializeElements = function(editor, elements) {
  3504. return map$1(elements, function(elm) {
  3505. return editor.selection.serializer.serialize(elm.dom, {});
  3506. }).join("");
  3507. };
  3508. var getTextContent = function(elements) {
  3509. return map$1(elements, function(element) {
  3510. return element.dom.innerText;
  3511. }).join("");
  3512. };
  3513. var registerEvents = function(editor, selections, actions) {
  3514. editor.on("BeforeGetContent", function(e) {
  3515. var multiCellContext = function(cells2) {
  3516. e.preventDefault();
  3517. extractSelected(cells2).each(function(elements) {
  3518. e.content = e.format === "text" ? getTextContent(elements) : serializeElements(editor, elements);
  3519. });
  3520. };
  3521. if (e.selection === true) {
  3522. cata$2(selections.get(), noop, multiCellContext, noop);
  3523. }
  3524. });
  3525. editor.on("BeforeSetContent", function(e) {
  3526. if (e.selection === true && e.paste === true) {
  3527. var selectedCells = getCellsFromSelection(selections);
  3528. head(selectedCells).each(function(cell2) {
  3529. table(cell2).each(function(table2) {
  3530. var elements = filter$2(fromHtml(e.content), function(content) {
  3531. return name(content) !== "meta";
  3532. });
  3533. var isTable = isTag("table");
  3534. if (elements.length === 1 && isTable(elements[0])) {
  3535. e.preventDefault();
  3536. var doc = SugarElement.fromDom(editor.getDoc());
  3537. var generators = paste$1(doc);
  3538. var targets = paste(cell2, elements[0], generators);
  3539. actions.pasteCells(table2, targets).each(function() {
  3540. editor.focus();
  3541. });
  3542. }
  3543. });
  3544. });
  3545. }
  3546. });
  3547. };
  3548. var adt$7 = Adt.generate([
  3549. { none: [] },
  3550. { only: ["index"] },
  3551. {
  3552. left: [
  3553. "index",
  3554. "next"
  3555. ]
  3556. },
  3557. {
  3558. middle: [
  3559. "prev",
  3560. "index",
  3561. "next"
  3562. ]
  3563. },
  3564. {
  3565. right: [
  3566. "prev",
  3567. "index"
  3568. ]
  3569. }
  3570. ]);
  3571. var ColumnContext = __assign({}, adt$7);
  3572. var neighbours = function(input, index) {
  3573. if (input.length === 0) {
  3574. return ColumnContext.none();
  3575. }
  3576. if (input.length === 1) {
  3577. return ColumnContext.only(0);
  3578. }
  3579. if (index === 0) {
  3580. return ColumnContext.left(0, 1);
  3581. }
  3582. if (index === input.length - 1) {
  3583. return ColumnContext.right(index - 1, index);
  3584. }
  3585. if (index > 0 && index < input.length - 1) {
  3586. return ColumnContext.middle(index - 1, index, index + 1);
  3587. }
  3588. return ColumnContext.none();
  3589. };
  3590. var determine = function(input, column, step, tableSize, resize2) {
  3591. var result = input.slice(0);
  3592. var context = neighbours(input, column);
  3593. var onNone = constant(map$1(result, constant(0)));
  3594. var onOnly = function(index) {
  3595. return tableSize.singleColumnWidth(result[index], step);
  3596. };
  3597. var onLeft = function(index, next2) {
  3598. return resize2.calcLeftEdgeDeltas(result, index, next2, step, tableSize.minCellWidth(), tableSize.isRelative);
  3599. };
  3600. var onMiddle = function(prev2, index, next2) {
  3601. return resize2.calcMiddleDeltas(result, prev2, index, next2, step, tableSize.minCellWidth(), tableSize.isRelative);
  3602. };
  3603. var onRight = function(prev2, index) {
  3604. return resize2.calcRightEdgeDeltas(result, prev2, index, step, tableSize.minCellWidth(), tableSize.isRelative);
  3605. };
  3606. return context.fold(onNone, onOnly, onLeft, onMiddle, onRight);
  3607. };
  3608. var total = function(start, end, measures) {
  3609. var r2 = 0;
  3610. for (var i = start; i < end; i++) {
  3611. r2 += measures[i] !== void 0 ? measures[i] : 0;
  3612. }
  3613. return r2;
  3614. };
  3615. var recalculateWidthForCells = function(warehouse, widths) {
  3616. var all2 = Warehouse.justCells(warehouse);
  3617. return map$1(all2, function(cell2) {
  3618. var width2 = total(cell2.column, cell2.column + cell2.colspan, widths);
  3619. return {
  3620. element: cell2.element,
  3621. width: width2,
  3622. colspan: cell2.colspan
  3623. };
  3624. });
  3625. };
  3626. var recalculateWidthForColumns = function(warehouse, widths) {
  3627. var groups = Warehouse.justColumns(warehouse);
  3628. return map$1(groups, function(column, index) {
  3629. return {
  3630. element: column.element,
  3631. width: widths[index],
  3632. colspan: column.colspan
  3633. };
  3634. });
  3635. };
  3636. var recalculateHeightForCells = function(warehouse, heights) {
  3637. var all2 = Warehouse.justCells(warehouse);
  3638. return map$1(all2, function(cell2) {
  3639. var height2 = total(cell2.row, cell2.row + cell2.rowspan, heights);
  3640. return {
  3641. element: cell2.element,
  3642. height: height2,
  3643. rowspan: cell2.rowspan
  3644. };
  3645. });
  3646. };
  3647. var matchRowHeight = function(warehouse, heights) {
  3648. return map$1(warehouse.all, function(row2, i) {
  3649. return {
  3650. element: row2.element,
  3651. height: heights[i]
  3652. };
  3653. });
  3654. };
  3655. var sumUp = function(newSize) {
  3656. return foldr(newSize, function(b, a) {
  3657. return b + a;
  3658. }, 0);
  3659. };
  3660. var recalculate = function(warehouse, widths) {
  3661. if (Warehouse.hasColumns(warehouse)) {
  3662. return recalculateWidthForColumns(warehouse, widths);
  3663. } else {
  3664. return recalculateWidthForCells(warehouse, widths);
  3665. }
  3666. };
  3667. var recalculateAndApply = function(warehouse, widths, tableSize) {
  3668. var newSizes = recalculate(warehouse, widths);
  3669. each$2(newSizes, function(cell2) {
  3670. tableSize.setElementWidth(cell2.element, cell2.width);
  3671. });
  3672. };
  3673. var adjustWidth = function(table2, delta, index, resizing, tableSize) {
  3674. var warehouse = Warehouse.fromTable(table2);
  3675. var step = tableSize.getCellDelta(delta);
  3676. var widths = tableSize.getWidths(warehouse, tableSize);
  3677. var isLastColumn = index === warehouse.grid.columns - 1;
  3678. var clampedStep = resizing.clampTableDelta(widths, index, step, tableSize.minCellWidth(), isLastColumn);
  3679. var deltas = determine(widths, index, clampedStep, tableSize, resizing);
  3680. var newWidths = map$1(deltas, function(dx, i) {
  3681. return dx + widths[i];
  3682. });
  3683. recalculateAndApply(warehouse, newWidths, tableSize);
  3684. resizing.resizeTable(tableSize.adjustTableWidth, clampedStep, isLastColumn);
  3685. };
  3686. var adjustHeight = function(table2, delta, index, direction) {
  3687. var warehouse = Warehouse.fromTable(table2);
  3688. var heights = getPixelHeights(warehouse, table2, direction);
  3689. var newHeights = map$1(heights, function(dy, i) {
  3690. return index === i ? Math.max(delta + dy, minHeight()) : dy;
  3691. });
  3692. var newCellSizes = recalculateHeightForCells(warehouse, newHeights);
  3693. var newRowSizes = matchRowHeight(warehouse, newHeights);
  3694. each$2(newRowSizes, function(row2) {
  3695. setHeight(row2.element, row2.height);
  3696. });
  3697. each$2(newCellSizes, function(cell2) {
  3698. setHeight(cell2.element, cell2.height);
  3699. });
  3700. var total2 = sumUp(newHeights);
  3701. setHeight(table2, total2);
  3702. };
  3703. var adjustAndRedistributeWidths$1 = function(_table, list, details, tableSize, resizeBehaviour) {
  3704. var warehouse = Warehouse.generate(list);
  3705. var sizes = tableSize.getWidths(warehouse, tableSize);
  3706. var tablePixelWidth = tableSize.pixelWidth();
  3707. var _a = resizeBehaviour.calcRedestributedWidths(sizes, tablePixelWidth, details.pixelDelta, tableSize.isRelative), newSizes = _a.newSizes, delta = _a.delta;
  3708. recalculateAndApply(warehouse, newSizes, tableSize);
  3709. tableSize.adjustTableWidth(delta);
  3710. };
  3711. var adjustWidthTo = function(_table, list, _info, tableSize) {
  3712. var warehouse = Warehouse.generate(list);
  3713. var widths = tableSize.getWidths(warehouse, tableSize);
  3714. recalculateAndApply(warehouse, widths, tableSize);
  3715. };
  3716. var zero = function(array) {
  3717. return map$1(array, constant(0));
  3718. };
  3719. var surround = function(sizes, startIndex, endIndex, results, f) {
  3720. return f(sizes.slice(0, startIndex)).concat(results).concat(f(sizes.slice(endIndex)));
  3721. };
  3722. var clampDeltaHelper = function(predicate) {
  3723. return function(sizes, index, delta, minCellSize) {
  3724. if (!predicate(delta)) {
  3725. return delta;
  3726. } else {
  3727. var newSize = Math.max(minCellSize, sizes[index] - Math.abs(delta));
  3728. var diff = Math.abs(newSize - sizes[index]);
  3729. return delta >= 0 ? diff : -diff;
  3730. }
  3731. };
  3732. };
  3733. var clampNegativeDelta = clampDeltaHelper(function(delta) {
  3734. return delta < 0;
  3735. });
  3736. var clampDelta = clampDeltaHelper(always);
  3737. var resizeTable = function() {
  3738. var calcFixedDeltas = function(sizes, index, next2, delta, minCellSize) {
  3739. var clampedDelta = clampNegativeDelta(sizes, index, delta, minCellSize);
  3740. return surround(sizes, index, next2 + 1, [
  3741. clampedDelta,
  3742. 0
  3743. ], zero);
  3744. };
  3745. var calcRelativeDeltas = function(sizes, index, delta, minCellSize) {
  3746. var ratio = (100 + delta) / 100;
  3747. var newThis = Math.max(minCellSize, (sizes[index] + delta) / ratio);
  3748. return map$1(sizes, function(size2, idx) {
  3749. var newSize = idx === index ? newThis : size2 / ratio;
  3750. return newSize - size2;
  3751. });
  3752. };
  3753. var calcLeftEdgeDeltas = function(sizes, index, next2, delta, minCellSize, isRelative) {
  3754. if (isRelative) {
  3755. return calcRelativeDeltas(sizes, index, delta, minCellSize);
  3756. } else {
  3757. return calcFixedDeltas(sizes, index, next2, delta, minCellSize);
  3758. }
  3759. };
  3760. var calcMiddleDeltas = function(sizes, _prev, index, next2, delta, minCellSize, isRelative) {
  3761. return calcLeftEdgeDeltas(sizes, index, next2, delta, minCellSize, isRelative);
  3762. };
  3763. var resizeTable2 = function(resizer, delta) {
  3764. return resizer(delta);
  3765. };
  3766. var calcRightEdgeDeltas = function(sizes, _prev, index, delta, minCellSize, isRelative) {
  3767. if (isRelative) {
  3768. return calcRelativeDeltas(sizes, index, delta, minCellSize);
  3769. } else {
  3770. var clampedDelta = clampNegativeDelta(sizes, index, delta, minCellSize);
  3771. return zero(sizes.slice(0, index)).concat([clampedDelta]);
  3772. }
  3773. };
  3774. var calcRedestributedWidths = function(sizes, totalWidth, pixelDelta, isRelative) {
  3775. if (isRelative) {
  3776. var tableWidth = totalWidth + pixelDelta;
  3777. var ratio_1 = tableWidth / totalWidth;
  3778. var newSizes = map$1(sizes, function(size2) {
  3779. return size2 / ratio_1;
  3780. });
  3781. return {
  3782. delta: ratio_1 * 100 - 100,
  3783. newSizes
  3784. };
  3785. } else {
  3786. return {
  3787. delta: pixelDelta,
  3788. newSizes: sizes
  3789. };
  3790. }
  3791. };
  3792. return {
  3793. resizeTable: resizeTable2,
  3794. clampTableDelta: clampNegativeDelta,
  3795. calcLeftEdgeDeltas,
  3796. calcMiddleDeltas,
  3797. calcRightEdgeDeltas,
  3798. calcRedestributedWidths
  3799. };
  3800. };
  3801. var preserveTable = function() {
  3802. var calcLeftEdgeDeltas = function(sizes, index, next2, delta, minCellSize) {
  3803. var idx = delta >= 0 ? next2 : index;
  3804. var clampedDelta = clampDelta(sizes, idx, delta, minCellSize);
  3805. return surround(sizes, index, next2 + 1, [
  3806. clampedDelta,
  3807. -clampedDelta
  3808. ], zero);
  3809. };
  3810. var calcMiddleDeltas = function(sizes, _prev, index, next2, delta, minCellSize) {
  3811. return calcLeftEdgeDeltas(sizes, index, next2, delta, minCellSize);
  3812. };
  3813. var resizeTable2 = function(resizer, delta, isLastColumn) {
  3814. if (isLastColumn) {
  3815. resizer(delta);
  3816. }
  3817. };
  3818. var calcRightEdgeDeltas = function(sizes, _prev, _index, delta, _minCellSize, isRelative) {
  3819. if (isRelative) {
  3820. return zero(sizes);
  3821. } else {
  3822. var diff = delta / sizes.length;
  3823. return map$1(sizes, constant(diff));
  3824. }
  3825. };
  3826. var clampTableDelta = function(sizes, index, delta, minCellSize, isLastColumn) {
  3827. if (isLastColumn) {
  3828. if (delta >= 0) {
  3829. return delta;
  3830. } else {
  3831. var maxDelta = foldl(sizes, function(a, b) {
  3832. return a + b - minCellSize;
  3833. }, 0);
  3834. return Math.max(-maxDelta, delta);
  3835. }
  3836. } else {
  3837. return clampNegativeDelta(sizes, index, delta, minCellSize);
  3838. }
  3839. };
  3840. var calcRedestributedWidths = function(sizes, _totalWidth, _pixelDelta, _isRelative) {
  3841. return {
  3842. delta: 0,
  3843. newSizes: sizes
  3844. };
  3845. };
  3846. return {
  3847. resizeTable: resizeTable2,
  3848. clampTableDelta,
  3849. calcLeftEdgeDeltas,
  3850. calcMiddleDeltas,
  3851. calcRightEdgeDeltas,
  3852. calcRedestributedWidths
  3853. };
  3854. };
  3855. var only = function(element, isResizable2) {
  3856. var parent2 = Optional.from(element.dom.documentElement).map(SugarElement.fromDom).getOr(element);
  3857. return {
  3858. parent: constant(parent2),
  3859. view: constant(element),
  3860. origin: constant(SugarPosition(0, 0)),
  3861. isResizable: isResizable2
  3862. };
  3863. };
  3864. var detached = function(editable, chrome2, isResizable2) {
  3865. var origin = function() {
  3866. return absolute(chrome2);
  3867. };
  3868. return {
  3869. parent: constant(chrome2),
  3870. view: constant(editable),
  3871. origin,
  3872. isResizable: isResizable2
  3873. };
  3874. };
  3875. var body = function(editable, chrome2, isResizable2) {
  3876. return {
  3877. parent: constant(chrome2),
  3878. view: constant(editable),
  3879. origin: constant(SugarPosition(0, 0)),
  3880. isResizable: isResizable2
  3881. };
  3882. };
  3883. var ResizeWire = {
  3884. only,
  3885. detached,
  3886. body
  3887. };
  3888. var adt$6 = Adt.generate([
  3889. { invalid: ["raw"] },
  3890. { pixels: ["value"] },
  3891. { percent: ["value"] }
  3892. ]);
  3893. var validateFor = function(suffix, type2, value2) {
  3894. var rawAmount = value2.substring(0, value2.length - suffix.length);
  3895. var amount = parseFloat(rawAmount);
  3896. return rawAmount === amount.toString() ? type2(amount) : adt$6.invalid(value2);
  3897. };
  3898. var from = function(value2) {
  3899. if (endsWith(value2, "%")) {
  3900. return validateFor("%", adt$6.percent, value2);
  3901. }
  3902. if (endsWith(value2, "px")) {
  3903. return validateFor("px", adt$6.pixels, value2);
  3904. }
  3905. return adt$6.invalid(value2);
  3906. };
  3907. var Size = __assign(__assign({}, adt$6), { from });
  3908. var redistributeToPercent = function(widths, totalWidth) {
  3909. return map$1(widths, function(w) {
  3910. var colType = Size.from(w);
  3911. return colType.fold(function() {
  3912. return w;
  3913. }, function(px) {
  3914. var ratio = px / totalWidth * 100;
  3915. return ratio + "%";
  3916. }, function(pc) {
  3917. return pc + "%";
  3918. });
  3919. });
  3920. };
  3921. var redistributeToPx = function(widths, totalWidth, newTotalWidth) {
  3922. var scale = newTotalWidth / totalWidth;
  3923. return map$1(widths, function(w) {
  3924. var colType = Size.from(w);
  3925. return colType.fold(function() {
  3926. return w;
  3927. }, function(px) {
  3928. return px * scale + "px";
  3929. }, function(pc) {
  3930. return pc / 100 * newTotalWidth + "px";
  3931. });
  3932. });
  3933. };
  3934. var redistributeEmpty = function(newWidthType, columns2) {
  3935. var f = newWidthType.fold(function() {
  3936. return constant("");
  3937. }, function(pixels) {
  3938. var num = pixels / columns2;
  3939. return constant(num + "px");
  3940. }, function() {
  3941. var num = 100 / columns2;
  3942. return constant(num + "%");
  3943. });
  3944. return range$1(columns2, f);
  3945. };
  3946. var redistributeValues = function(newWidthType, widths, totalWidth) {
  3947. return newWidthType.fold(function() {
  3948. return widths;
  3949. }, function(px) {
  3950. return redistributeToPx(widths, totalWidth, px);
  3951. }, function(_pc) {
  3952. return redistributeToPercent(widths, totalWidth);
  3953. });
  3954. };
  3955. var redistribute$1 = function(widths, totalWidth, newWidth) {
  3956. var newType = Size.from(newWidth);
  3957. var floats = forall(widths, function(s) {
  3958. return s === "0px";
  3959. }) ? redistributeEmpty(newType, widths.length) : redistributeValues(newType, widths, totalWidth);
  3960. return normalize(floats);
  3961. };
  3962. var sum = function(values2, fallback2) {
  3963. if (values2.length === 0) {
  3964. return fallback2;
  3965. }
  3966. return foldr(values2, function(rest, v) {
  3967. return Size.from(v).fold(constant(0), identity, identity) + rest;
  3968. }, 0);
  3969. };
  3970. var roundDown = function(num, unit) {
  3971. var floored = Math.floor(num);
  3972. return {
  3973. value: floored + unit,
  3974. remainder: num - floored
  3975. };
  3976. };
  3977. var add$3 = function(value2, amount) {
  3978. return Size.from(value2).fold(constant(value2), function(px) {
  3979. return px + amount + "px";
  3980. }, function(pc) {
  3981. return pc + amount + "%";
  3982. });
  3983. };
  3984. var normalize = function(values2) {
  3985. if (values2.length === 0) {
  3986. return values2;
  3987. }
  3988. var scan2 = foldr(values2, function(rest, value2) {
  3989. var info = Size.from(value2).fold(function() {
  3990. return {
  3991. value: value2,
  3992. remainder: 0
  3993. };
  3994. }, function(num) {
  3995. return roundDown(num, "px");
  3996. }, function(num) {
  3997. return {
  3998. value: num + "%",
  3999. remainder: 0
  4000. };
  4001. });
  4002. return {
  4003. output: [info.value].concat(rest.output),
  4004. remainder: rest.remainder + info.remainder
  4005. };
  4006. }, {
  4007. output: [],
  4008. remainder: 0
  4009. });
  4010. var r2 = scan2.output;
  4011. return r2.slice(0, r2.length - 1).concat([add$3(r2[r2.length - 1], Math.round(scan2.remainder))]);
  4012. };
  4013. var validate = Size.from;
  4014. var redistributeToW = function(newWidths, cells2, unit) {
  4015. each$2(cells2, function(cell2) {
  4016. var widths = newWidths.slice(cell2.column, cell2.colspan + cell2.column);
  4017. var w = sum(widths, minWidth());
  4018. set$1(cell2.element, "width", w + unit);
  4019. });
  4020. };
  4021. var redistributeToColumns = function(newWidths, columns2, unit) {
  4022. each$2(columns2, function(column, index) {
  4023. var width2 = sum([newWidths[index]], minWidth());
  4024. set$1(column.element, "width", width2 + unit);
  4025. });
  4026. };
  4027. var redistributeToH = function(newHeights, rows2, cells2, unit) {
  4028. each$2(cells2, function(cell2) {
  4029. var heights = newHeights.slice(cell2.row, cell2.rowspan + cell2.row);
  4030. var h = sum(heights, minHeight());
  4031. set$1(cell2.element, "height", h + unit);
  4032. });
  4033. each$2(rows2, function(row2, i) {
  4034. set$1(row2.element, "height", newHeights[i]);
  4035. });
  4036. };
  4037. var getUnit = function(newSize) {
  4038. return validate(newSize).fold(constant("px"), constant("px"), constant("%"));
  4039. };
  4040. var redistribute = function(table2, optWidth, optHeight) {
  4041. var warehouse = Warehouse.fromTable(table2);
  4042. var rows2 = warehouse.all;
  4043. var cells2 = Warehouse.justCells(warehouse);
  4044. var columns2 = Warehouse.justColumns(warehouse);
  4045. optWidth.each(function(newWidth) {
  4046. var widthUnit = getUnit(newWidth);
  4047. var totalWidth = get$8(table2);
  4048. var oldWidths = getRawWidths(warehouse, table2);
  4049. var nuWidths = redistribute$1(oldWidths, totalWidth, newWidth);
  4050. if (Warehouse.hasColumns(warehouse)) {
  4051. redistributeToColumns(nuWidths, columns2, widthUnit);
  4052. } else {
  4053. redistributeToW(nuWidths, cells2, widthUnit);
  4054. }
  4055. set$1(table2, "width", newWidth);
  4056. });
  4057. optHeight.each(function(newHeight) {
  4058. var hUnit = getUnit(newHeight);
  4059. var totalHeight = get$7(table2);
  4060. var oldHeights = getRawHeights(warehouse, table2, height);
  4061. var nuHeights = redistribute$1(oldHeights, totalHeight, newHeight);
  4062. redistributeToH(nuHeights, rows2, cells2, hUnit);
  4063. set$1(table2, "height", newHeight);
  4064. });
  4065. };
  4066. var isPercentSizing = isPercentSizing$1;
  4067. var isPixelSizing = isPixelSizing$1;
  4068. var isNoneSizing = isNoneSizing$1;
  4069. var getGridSize = function(table2) {
  4070. var warehouse = Warehouse.fromTable(table2);
  4071. return warehouse.grid;
  4072. };
  4073. var Event = function(fields) {
  4074. var handlers = [];
  4075. var bind2 = function(handler) {
  4076. if (handler === void 0) {
  4077. throw new Error("Event bind error: undefined handler");
  4078. }
  4079. handlers.push(handler);
  4080. };
  4081. var unbind2 = function(handler) {
  4082. handlers = filter$2(handlers, function(h) {
  4083. return h !== handler;
  4084. });
  4085. };
  4086. var trigger = function() {
  4087. var args = [];
  4088. for (var _i = 0; _i < arguments.length; _i++) {
  4089. args[_i] = arguments[_i];
  4090. }
  4091. var event = {};
  4092. each$2(fields, function(name2, i) {
  4093. event[name2] = args[i];
  4094. });
  4095. each$2(handlers, function(handler) {
  4096. handler(event);
  4097. });
  4098. };
  4099. return {
  4100. bind: bind2,
  4101. unbind: unbind2,
  4102. trigger
  4103. };
  4104. };
  4105. var create$4 = function(typeDefs) {
  4106. var registry = map(typeDefs, function(event) {
  4107. return {
  4108. bind: event.bind,
  4109. unbind: event.unbind
  4110. };
  4111. });
  4112. var trigger = map(typeDefs, function(event) {
  4113. return event.trigger;
  4114. });
  4115. return {
  4116. registry,
  4117. trigger
  4118. };
  4119. };
  4120. var last = function(fn, rate) {
  4121. var timer = null;
  4122. var cancel = function() {
  4123. if (!isNull(timer)) {
  4124. clearTimeout(timer);
  4125. timer = null;
  4126. }
  4127. };
  4128. var throttle = function() {
  4129. var args = [];
  4130. for (var _i = 0; _i < arguments.length; _i++) {
  4131. args[_i] = arguments[_i];
  4132. }
  4133. cancel();
  4134. timer = setTimeout(function() {
  4135. timer = null;
  4136. fn.apply(null, args);
  4137. }, rate);
  4138. };
  4139. return {
  4140. cancel,
  4141. throttle
  4142. };
  4143. };
  4144. var sort = function(arr) {
  4145. return arr.slice(0).sort();
  4146. };
  4147. var reqMessage = function(required, keys2) {
  4148. throw new Error("All required keys (" + sort(required).join(", ") + ") were not specified. Specified keys were: " + sort(keys2).join(", ") + ".");
  4149. };
  4150. var unsuppMessage = function(unsupported) {
  4151. throw new Error("Unsupported keys for object: " + sort(unsupported).join(", "));
  4152. };
  4153. var validateStrArr = function(label, array) {
  4154. if (!isArray(array)) {
  4155. throw new Error("The " + label + " fields must be an array. Was: " + array + ".");
  4156. }
  4157. each$2(array, function(a) {
  4158. if (!isString(a)) {
  4159. throw new Error("The value " + a + " in the " + label + " fields was not a string.");
  4160. }
  4161. });
  4162. };
  4163. var invalidTypeMessage = function(incorrect, type2) {
  4164. throw new Error("All values need to be of type: " + type2 + ". Keys (" + sort(incorrect).join(", ") + ") were not.");
  4165. };
  4166. var checkDupes = function(everything) {
  4167. var sorted = sort(everything);
  4168. var dupe = find$1(sorted, function(s, i) {
  4169. return i < sorted.length - 1 && s === sorted[i + 1];
  4170. });
  4171. dupe.each(function(d) {
  4172. throw new Error("The field: " + d + " occurs more than once in the combined fields: [" + sorted.join(", ") + "].");
  4173. });
  4174. };
  4175. var base = function(handleUnsupported, required) {
  4176. return baseWith(handleUnsupported, required, {
  4177. validate: isFunction,
  4178. label: "function"
  4179. });
  4180. };
  4181. var baseWith = function(handleUnsupported, required, pred) {
  4182. if (required.length === 0) {
  4183. throw new Error("You must specify at least one required field.");
  4184. }
  4185. validateStrArr("required", required);
  4186. checkDupes(required);
  4187. return function(obj) {
  4188. var keys$1 = keys(obj);
  4189. var allReqd = forall(required, function(req) {
  4190. return contains$2(keys$1, req);
  4191. });
  4192. if (!allReqd) {
  4193. reqMessage(required, keys$1);
  4194. }
  4195. handleUnsupported(required, keys$1);
  4196. var invalidKeys = filter$2(required, function(key2) {
  4197. return !pred.validate(obj[key2], key2);
  4198. });
  4199. if (invalidKeys.length > 0) {
  4200. invalidTypeMessage(invalidKeys, pred.label);
  4201. }
  4202. return obj;
  4203. };
  4204. };
  4205. var handleExact = function(required, keys2) {
  4206. var unsupported = filter$2(keys2, function(key2) {
  4207. return !contains$2(required, key2);
  4208. });
  4209. if (unsupported.length > 0) {
  4210. unsuppMessage(unsupported);
  4211. }
  4212. };
  4213. var exactly = function(required) {
  4214. return base(handleExact, required);
  4215. };
  4216. var DragMode = exactly([
  4217. "compare",
  4218. "extract",
  4219. "mutate",
  4220. "sink"
  4221. ]);
  4222. var DragSink = exactly([
  4223. "element",
  4224. "start",
  4225. "stop",
  4226. "destroy"
  4227. ]);
  4228. var DragApi = exactly([
  4229. "forceDrop",
  4230. "drop",
  4231. "move",
  4232. "delayDrop"
  4233. ]);
  4234. var InDrag = function() {
  4235. var previous = Optional.none();
  4236. var reset = function() {
  4237. previous = Optional.none();
  4238. };
  4239. var update2 = function(mode, nu2) {
  4240. var result = previous.map(function(old) {
  4241. return mode.compare(old, nu2);
  4242. });
  4243. previous = Optional.some(nu2);
  4244. return result;
  4245. };
  4246. var onEvent = function(event, mode) {
  4247. var dataOption = mode.extract(event);
  4248. dataOption.each(function(data) {
  4249. var offset = update2(mode, data);
  4250. offset.each(function(d) {
  4251. events.trigger.move(d);
  4252. });
  4253. });
  4254. };
  4255. var events = create$4({ move: Event(["info"]) });
  4256. return {
  4257. onEvent,
  4258. reset,
  4259. events: events.registry
  4260. };
  4261. };
  4262. var NoDrag = function() {
  4263. var events = create$4({ move: Event(["info"]) });
  4264. return {
  4265. onEvent: noop,
  4266. reset: noop,
  4267. events: events.registry
  4268. };
  4269. };
  4270. var Movement = function() {
  4271. var noDragState = NoDrag();
  4272. var inDragState = InDrag();
  4273. var dragState = noDragState;
  4274. var on2 = function() {
  4275. dragState.reset();
  4276. dragState = inDragState;
  4277. };
  4278. var off = function() {
  4279. dragState.reset();
  4280. dragState = noDragState;
  4281. };
  4282. var onEvent = function(event, mode) {
  4283. dragState.onEvent(event, mode);
  4284. };
  4285. var isOn = function() {
  4286. return dragState === inDragState;
  4287. };
  4288. return {
  4289. on: on2,
  4290. off,
  4291. isOn,
  4292. onEvent,
  4293. events: inDragState.events
  4294. };
  4295. };
  4296. var setup = function(mutation, mode, settings) {
  4297. var active = false;
  4298. var events = create$4({
  4299. start: Event([]),
  4300. stop: Event([])
  4301. });
  4302. var movement = Movement();
  4303. var drop = function() {
  4304. sink2.stop();
  4305. if (movement.isOn()) {
  4306. movement.off();
  4307. events.trigger.stop();
  4308. }
  4309. };
  4310. var throttledDrop = last(drop, 200);
  4311. var go2 = function(parent2) {
  4312. sink2.start(parent2);
  4313. movement.on();
  4314. events.trigger.start();
  4315. };
  4316. var mousemove = function(event) {
  4317. throttledDrop.cancel();
  4318. movement.onEvent(event, mode);
  4319. };
  4320. movement.events.move.bind(function(event) {
  4321. mode.mutate(mutation, event.info);
  4322. });
  4323. var on2 = function() {
  4324. active = true;
  4325. };
  4326. var off = function() {
  4327. active = false;
  4328. };
  4329. var runIfActive = function(f) {
  4330. return function() {
  4331. var args = [];
  4332. for (var _i = 0; _i < arguments.length; _i++) {
  4333. args[_i] = arguments[_i];
  4334. }
  4335. if (active) {
  4336. f.apply(null, args);
  4337. }
  4338. };
  4339. };
  4340. var sink2 = mode.sink(DragApi({
  4341. forceDrop: drop,
  4342. drop: runIfActive(drop),
  4343. move: runIfActive(mousemove),
  4344. delayDrop: runIfActive(throttledDrop.throttle)
  4345. }), settings);
  4346. var destroy2 = function() {
  4347. sink2.destroy();
  4348. };
  4349. return {
  4350. element: sink2.element,
  4351. go: go2,
  4352. on: on2,
  4353. off,
  4354. destroy: destroy2,
  4355. events: events.registry
  4356. };
  4357. };
  4358. var mkEvent = function(target, x, y, stop, prevent, kill, raw) {
  4359. return {
  4360. target,
  4361. x,
  4362. y,
  4363. stop,
  4364. prevent,
  4365. kill,
  4366. raw
  4367. };
  4368. };
  4369. var fromRawEvent$1 = function(rawEvent) {
  4370. var target = SugarElement.fromDom(getOriginalEventTarget(rawEvent).getOr(rawEvent.target));
  4371. var stop = function() {
  4372. return rawEvent.stopPropagation();
  4373. };
  4374. var prevent = function() {
  4375. return rawEvent.preventDefault();
  4376. };
  4377. var kill = compose(prevent, stop);
  4378. return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
  4379. };
  4380. var handle$2 = function(filter2, handler) {
  4381. return function(rawEvent) {
  4382. if (filter2(rawEvent)) {
  4383. handler(fromRawEvent$1(rawEvent));
  4384. }
  4385. };
  4386. };
  4387. var binder = function(element, event, filter2, handler, useCapture) {
  4388. var wrapped = handle$2(filter2, handler);
  4389. element.dom.addEventListener(event, wrapped, useCapture);
  4390. return { unbind: curry(unbind, element, event, wrapped, useCapture) };
  4391. };
  4392. var bind$1 = function(element, event, filter2, handler) {
  4393. return binder(element, event, filter2, handler, false);
  4394. };
  4395. var unbind = function(element, event, handler, useCapture) {
  4396. element.dom.removeEventListener(event, handler, useCapture);
  4397. };
  4398. var filter = always;
  4399. var bind = function(element, event, handler) {
  4400. return bind$1(element, event, filter, handler);
  4401. };
  4402. var fromRawEvent = fromRawEvent$1;
  4403. var read = function(element, attr) {
  4404. var value2 = get$b(element, attr);
  4405. return value2 === void 0 || value2 === "" ? [] : value2.split(" ");
  4406. };
  4407. var add$2 = function(element, attr, id) {
  4408. var old = read(element, attr);
  4409. var nu2 = old.concat([id]);
  4410. set$2(element, attr, nu2.join(" "));
  4411. return true;
  4412. };
  4413. var remove$4 = function(element, attr, id) {
  4414. var nu2 = filter$2(read(element, attr), function(v) {
  4415. return v !== id;
  4416. });
  4417. if (nu2.length > 0) {
  4418. set$2(element, attr, nu2.join(" "));
  4419. } else {
  4420. remove$7(element, attr);
  4421. }
  4422. return false;
  4423. };
  4424. var supports = function(element) {
  4425. return element.dom.classList !== void 0;
  4426. };
  4427. var get$5 = function(element) {
  4428. return read(element, "class");
  4429. };
  4430. var add$1 = function(element, clazz) {
  4431. return add$2(element, "class", clazz);
  4432. };
  4433. var remove$3 = function(element, clazz) {
  4434. return remove$4(element, "class", clazz);
  4435. };
  4436. var add = function(element, clazz) {
  4437. if (supports(element)) {
  4438. element.dom.classList.add(clazz);
  4439. } else {
  4440. add$1(element, clazz);
  4441. }
  4442. };
  4443. var cleanClass = function(element) {
  4444. var classList = supports(element) ? element.dom.classList : get$5(element);
  4445. if (classList.length === 0) {
  4446. remove$7(element, "class");
  4447. }
  4448. };
  4449. var remove$2 = function(element, clazz) {
  4450. if (supports(element)) {
  4451. var classList = element.dom.classList;
  4452. classList.remove(clazz);
  4453. } else {
  4454. remove$3(element, clazz);
  4455. }
  4456. cleanClass(element);
  4457. };
  4458. var has = function(element, clazz) {
  4459. return supports(element) && element.dom.classList.contains(clazz);
  4460. };
  4461. var css = function(namespace) {
  4462. var dashNamespace = namespace.replace(/\./g, "-");
  4463. var resolve2 = function(str) {
  4464. return dashNamespace + "-" + str;
  4465. };
  4466. return { resolve: resolve2 };
  4467. };
  4468. var styles$1 = css("ephox-dragster");
  4469. var resolve$1 = styles$1.resolve;
  4470. var Blocker = function(options) {
  4471. var settings = __assign({ layerClass: resolve$1("blocker") }, options);
  4472. var div = SugarElement.fromTag("div");
  4473. set$2(div, "role", "presentation");
  4474. setAll(div, {
  4475. position: "fixed",
  4476. left: "0px",
  4477. top: "0px",
  4478. width: "100%",
  4479. height: "100%"
  4480. });
  4481. add(div, resolve$1("blocker"));
  4482. add(div, settings.layerClass);
  4483. var element = constant(div);
  4484. var destroy2 = function() {
  4485. remove$5(div);
  4486. };
  4487. return {
  4488. element,
  4489. destroy: destroy2
  4490. };
  4491. };
  4492. var compare = function(old, nu2) {
  4493. return SugarPosition(nu2.left - old.left, nu2.top - old.top);
  4494. };
  4495. var extract = function(event) {
  4496. return Optional.some(SugarPosition(event.x, event.y));
  4497. };
  4498. var mutate = function(mutation, info) {
  4499. mutation.mutate(info.left, info.top);
  4500. };
  4501. var sink = function(dragApi, settings) {
  4502. var blocker = Blocker(settings);
  4503. var mdown = bind(blocker.element(), "mousedown", dragApi.forceDrop);
  4504. var mup = bind(blocker.element(), "mouseup", dragApi.drop);
  4505. var mmove = bind(blocker.element(), "mousemove", dragApi.move);
  4506. var mout = bind(blocker.element(), "mouseout", dragApi.delayDrop);
  4507. var destroy2 = function() {
  4508. blocker.destroy();
  4509. mup.unbind();
  4510. mmove.unbind();
  4511. mout.unbind();
  4512. mdown.unbind();
  4513. };
  4514. var start = function(parent2) {
  4515. append$1(parent2, blocker.element());
  4516. };
  4517. var stop = function() {
  4518. remove$5(blocker.element());
  4519. };
  4520. return DragSink({
  4521. element: blocker.element,
  4522. start,
  4523. stop,
  4524. destroy: destroy2
  4525. });
  4526. };
  4527. var MouseDrag = DragMode({
  4528. compare,
  4529. extract,
  4530. sink,
  4531. mutate
  4532. });
  4533. var transform$1 = function(mutation, settings) {
  4534. if (settings === void 0) {
  4535. settings = {};
  4536. }
  4537. var mode = settings.mode !== void 0 ? settings.mode : MouseDrag;
  4538. return setup(mutation, mode, settings);
  4539. };
  4540. var closest = function(target) {
  4541. return closest$1(target, "[contenteditable]");
  4542. };
  4543. var isEditable$1 = function(element, assumeEditable) {
  4544. if (assumeEditable === void 0) {
  4545. assumeEditable = false;
  4546. }
  4547. if (!detect$3().browser.isIE() && inBody(element)) {
  4548. return element.dom.isContentEditable;
  4549. } else {
  4550. return closest(element).fold(constant(assumeEditable), function(editable) {
  4551. return getRaw(editable) === "true";
  4552. });
  4553. }
  4554. };
  4555. var getRaw = function(element) {
  4556. return element.dom.contentEditable;
  4557. };
  4558. var styles = css("ephox-snooker");
  4559. var resolve = styles.resolve;
  4560. var Mutation = function() {
  4561. var events = create$4({
  4562. drag: Event([
  4563. "xDelta",
  4564. "yDelta"
  4565. ])
  4566. });
  4567. var mutate2 = function(x, y) {
  4568. events.trigger.drag(x, y);
  4569. };
  4570. return {
  4571. mutate: mutate2,
  4572. events: events.registry
  4573. };
  4574. };
  4575. var BarMutation = function() {
  4576. var events = create$4({
  4577. drag: Event([
  4578. "xDelta",
  4579. "yDelta",
  4580. "target"
  4581. ])
  4582. });
  4583. var target = Optional.none();
  4584. var delegate = Mutation();
  4585. delegate.events.drag.bind(function(event) {
  4586. target.each(function(t) {
  4587. events.trigger.drag(event.xDelta, event.yDelta, t);
  4588. });
  4589. });
  4590. var assign = function(t) {
  4591. target = Optional.some(t);
  4592. };
  4593. var get2 = function() {
  4594. return target;
  4595. };
  4596. return {
  4597. assign,
  4598. get: get2,
  4599. mutate: delegate.mutate,
  4600. events: events.registry
  4601. };
  4602. };
  4603. var col = function(column, x, y, w, h) {
  4604. var bar = SugarElement.fromTag("div");
  4605. setAll(bar, {
  4606. position: "absolute",
  4607. left: x - w / 2 + "px",
  4608. top: y + "px",
  4609. height: h + "px",
  4610. width: w + "px"
  4611. });
  4612. setAll$1(bar, {
  4613. "data-column": column,
  4614. "role": "presentation"
  4615. });
  4616. return bar;
  4617. };
  4618. var row = function(r2, x, y, w, h) {
  4619. var bar = SugarElement.fromTag("div");
  4620. setAll(bar, {
  4621. position: "absolute",
  4622. left: x + "px",
  4623. top: y - h / 2 + "px",
  4624. height: h + "px",
  4625. width: w + "px"
  4626. });
  4627. setAll$1(bar, {
  4628. "data-row": r2,
  4629. "role": "presentation"
  4630. });
  4631. return bar;
  4632. };
  4633. var resizeBar = resolve("resizer-bar");
  4634. var resizeRowBar = resolve("resizer-rows");
  4635. var resizeColBar = resolve("resizer-cols");
  4636. var BAR_THICKNESS = 7;
  4637. var resizableRows = function(warehouse, isResizable2) {
  4638. return bind$2(warehouse.all, function(row2, i) {
  4639. return isResizable2(row2.element) ? [i] : [];
  4640. });
  4641. };
  4642. var resizableColumns = function(warehouse, isResizable2) {
  4643. var resizableCols = [];
  4644. range$1(warehouse.grid.columns, function(index) {
  4645. var colElmOpt = Warehouse.getColumnAt(warehouse, index).map(function(col2) {
  4646. return col2.element;
  4647. });
  4648. if (colElmOpt.forall(isResizable2)) {
  4649. resizableCols.push(index);
  4650. }
  4651. });
  4652. return filter$2(resizableCols, function(colIndex) {
  4653. var columnCells = Warehouse.filterItems(warehouse, function(cell2) {
  4654. return cell2.column === colIndex;
  4655. });
  4656. return forall(columnCells, function(cell2) {
  4657. return isResizable2(cell2.element);
  4658. });
  4659. });
  4660. };
  4661. var destroy = function(wire) {
  4662. var previous = descendants(wire.parent(), "." + resizeBar);
  4663. each$2(previous, remove$5);
  4664. };
  4665. var drawBar = function(wire, positions, create2) {
  4666. var origin = wire.origin();
  4667. each$2(positions, function(cpOption) {
  4668. cpOption.each(function(cp) {
  4669. var bar = create2(origin, cp);
  4670. add(bar, resizeBar);
  4671. append$1(wire.parent(), bar);
  4672. });
  4673. });
  4674. };
  4675. var refreshCol = function(wire, colPositions, position, tableHeight) {
  4676. drawBar(wire, colPositions, function(origin, cp) {
  4677. var colBar = col(cp.col, cp.x - origin.left, position.top - origin.top, BAR_THICKNESS, tableHeight);
  4678. add(colBar, resizeColBar);
  4679. return colBar;
  4680. });
  4681. };
  4682. var refreshRow = function(wire, rowPositions, position, tableWidth) {
  4683. drawBar(wire, rowPositions, function(origin, cp) {
  4684. var rowBar = row(cp.row, position.left - origin.left, cp.y - origin.top, tableWidth, BAR_THICKNESS);
  4685. add(rowBar, resizeRowBar);
  4686. return rowBar;
  4687. });
  4688. };
  4689. var refreshGrid = function(warhouse, wire, table2, rows2, cols) {
  4690. var position = absolute(table2);
  4691. var isResizable2 = wire.isResizable;
  4692. var rowPositions = rows2.length > 0 ? height.positions(rows2, table2) : [];
  4693. var resizableRowBars = rowPositions.length > 0 ? resizableRows(warhouse, isResizable2) : [];
  4694. var resizableRowPositions = filter$2(rowPositions, function(_pos, i) {
  4695. return exists(resizableRowBars, function(barIndex) {
  4696. return i === barIndex;
  4697. });
  4698. });
  4699. refreshRow(wire, resizableRowPositions, position, getOuter$2(table2));
  4700. var colPositions = cols.length > 0 ? width.positions(cols, table2) : [];
  4701. var resizableColBars = colPositions.length > 0 ? resizableColumns(warhouse, isResizable2) : [];
  4702. var resizableColPositions = filter$2(colPositions, function(_pos, i) {
  4703. return exists(resizableColBars, function(barIndex) {
  4704. return i === barIndex;
  4705. });
  4706. });
  4707. refreshCol(wire, resizableColPositions, position, getOuter$1(table2));
  4708. };
  4709. var refresh = function(wire, table2) {
  4710. destroy(wire);
  4711. if (wire.isResizable(table2)) {
  4712. var warehouse = Warehouse.fromTable(table2);
  4713. var rows$12 = rows(warehouse);
  4714. var cols = columns(warehouse);
  4715. refreshGrid(warehouse, wire, table2, rows$12, cols);
  4716. }
  4717. };
  4718. var each = function(wire, f) {
  4719. var bars = descendants(wire.parent(), "." + resizeBar);
  4720. each$2(bars, f);
  4721. };
  4722. var hide = function(wire) {
  4723. each(wire, function(bar) {
  4724. set$1(bar, "display", "none");
  4725. });
  4726. };
  4727. var show = function(wire) {
  4728. each(wire, function(bar) {
  4729. set$1(bar, "display", "block");
  4730. });
  4731. };
  4732. var isRowBar = function(element) {
  4733. return has(element, resizeRowBar);
  4734. };
  4735. var isColBar = function(element) {
  4736. return has(element, resizeColBar);
  4737. };
  4738. var resizeBarDragging = resolve("resizer-bar-dragging");
  4739. var BarManager = function(wire) {
  4740. var mutation = BarMutation();
  4741. var resizing = transform$1(mutation, {});
  4742. var hoverTable = Optional.none();
  4743. var getResizer = function(element, type2) {
  4744. return Optional.from(get$b(element, type2));
  4745. };
  4746. mutation.events.drag.bind(function(event) {
  4747. getResizer(event.target, "data-row").each(function(_dataRow) {
  4748. var currentRow = getCssValue(event.target, "top");
  4749. set$1(event.target, "top", currentRow + event.yDelta + "px");
  4750. });
  4751. getResizer(event.target, "data-column").each(function(_dataCol) {
  4752. var currentCol = getCssValue(event.target, "left");
  4753. set$1(event.target, "left", currentCol + event.xDelta + "px");
  4754. });
  4755. });
  4756. var getDelta = function(target, dir) {
  4757. var newX = getCssValue(target, dir);
  4758. var oldX = getAttrValue(target, "data-initial-" + dir, 0);
  4759. return newX - oldX;
  4760. };
  4761. resizing.events.stop.bind(function() {
  4762. mutation.get().each(function(target) {
  4763. hoverTable.each(function(table2) {
  4764. getResizer(target, "data-row").each(function(row2) {
  4765. var delta = getDelta(target, "top");
  4766. remove$7(target, "data-initial-top");
  4767. events.trigger.adjustHeight(table2, delta, parseInt(row2, 10));
  4768. });
  4769. getResizer(target, "data-column").each(function(column) {
  4770. var delta = getDelta(target, "left");
  4771. remove$7(target, "data-initial-left");
  4772. events.trigger.adjustWidth(table2, delta, parseInt(column, 10));
  4773. });
  4774. refresh(wire, table2);
  4775. });
  4776. });
  4777. });
  4778. var handler = function(target, dir) {
  4779. events.trigger.startAdjust();
  4780. mutation.assign(target);
  4781. set$2(target, "data-initial-" + dir, getCssValue(target, dir));
  4782. add(target, resizeBarDragging);
  4783. set$1(target, "opacity", "0.2");
  4784. resizing.go(wire.parent());
  4785. };
  4786. var mousedown = bind(wire.parent(), "mousedown", function(event) {
  4787. if (isRowBar(event.target)) {
  4788. handler(event.target, "top");
  4789. }
  4790. if (isColBar(event.target)) {
  4791. handler(event.target, "left");
  4792. }
  4793. });
  4794. var isRoot = function(e) {
  4795. return eq$1(e, wire.view());
  4796. };
  4797. var findClosestEditableTable = function(target) {
  4798. return closest$1(target, "table", isRoot).filter(isEditable$1);
  4799. };
  4800. var mouseover = bind(wire.view(), "mouseover", function(event) {
  4801. findClosestEditableTable(event.target).fold(function() {
  4802. if (inBody(event.target)) {
  4803. destroy(wire);
  4804. }
  4805. }, function(table2) {
  4806. hoverTable = Optional.some(table2);
  4807. refresh(wire, table2);
  4808. });
  4809. });
  4810. var destroy$1 = function() {
  4811. mousedown.unbind();
  4812. mouseover.unbind();
  4813. resizing.destroy();
  4814. destroy(wire);
  4815. };
  4816. var refresh$1 = function(tbl) {
  4817. refresh(wire, tbl);
  4818. };
  4819. var events = create$4({
  4820. adjustHeight: Event([
  4821. "table",
  4822. "delta",
  4823. "row"
  4824. ]),
  4825. adjustWidth: Event([
  4826. "table",
  4827. "delta",
  4828. "column"
  4829. ]),
  4830. startAdjust: Event([])
  4831. });
  4832. return {
  4833. destroy: destroy$1,
  4834. refresh: refresh$1,
  4835. on: resizing.on,
  4836. off: resizing.off,
  4837. hideBars: curry(hide, wire),
  4838. showBars: curry(show, wire),
  4839. events: events.registry
  4840. };
  4841. };
  4842. var create$3 = function(wire, resizing, lazySizing) {
  4843. var hdirection = height;
  4844. var vdirection = width;
  4845. var manager = BarManager(wire);
  4846. var events = create$4({
  4847. beforeResize: Event([
  4848. "table",
  4849. "type"
  4850. ]),
  4851. afterResize: Event([
  4852. "table",
  4853. "type"
  4854. ]),
  4855. startDrag: Event([])
  4856. });
  4857. manager.events.adjustHeight.bind(function(event) {
  4858. var table2 = event.table;
  4859. events.trigger.beforeResize(table2, "row");
  4860. var delta = hdirection.delta(event.delta, table2);
  4861. adjustHeight(table2, delta, event.row, hdirection);
  4862. events.trigger.afterResize(table2, "row");
  4863. });
  4864. manager.events.startAdjust.bind(function(_event) {
  4865. events.trigger.startDrag();
  4866. });
  4867. manager.events.adjustWidth.bind(function(event) {
  4868. var table2 = event.table;
  4869. events.trigger.beforeResize(table2, "col");
  4870. var delta = vdirection.delta(event.delta, table2);
  4871. var tableSize = lazySizing(table2);
  4872. adjustWidth(table2, delta, event.column, resizing, tableSize);
  4873. events.trigger.afterResize(table2, "col");
  4874. });
  4875. return {
  4876. on: manager.on,
  4877. off: manager.off,
  4878. hideBars: manager.hideBars,
  4879. showBars: manager.showBars,
  4880. destroy: manager.destroy,
  4881. events: events.registry
  4882. };
  4883. };
  4884. var TableResize = { create: create$3 };
  4885. var fireNewRow = function(editor, row2) {
  4886. return editor.fire("newrow", { node: row2 });
  4887. };
  4888. var fireNewCell = function(editor, cell2) {
  4889. return editor.fire("newcell", { node: cell2 });
  4890. };
  4891. var fireObjectResizeStart = function(editor, target, width2, height2, origin) {
  4892. editor.fire("ObjectResizeStart", {
  4893. target,
  4894. width: width2,
  4895. height: height2,
  4896. origin
  4897. });
  4898. };
  4899. var fireObjectResized = function(editor, target, width2, height2, origin) {
  4900. editor.fire("ObjectResized", {
  4901. target,
  4902. width: width2,
  4903. height: height2,
  4904. origin
  4905. });
  4906. };
  4907. var fireTableSelectionChange = function(editor, cells2, start, finish, otherCells) {
  4908. editor.fire("TableSelectionChange", {
  4909. cells: cells2,
  4910. start,
  4911. finish,
  4912. otherCells
  4913. });
  4914. };
  4915. var fireTableSelectionClear = function(editor) {
  4916. editor.fire("TableSelectionClear");
  4917. };
  4918. var fireTableModified = function(editor, table2, data) {
  4919. editor.fire("TableModified", __assign(__assign({}, data), { table: table2 }));
  4920. };
  4921. var styleModified = {
  4922. structure: false,
  4923. style: true
  4924. };
  4925. var structureModified = {
  4926. structure: true,
  4927. style: false
  4928. };
  4929. var styleAndStructureModified = {
  4930. structure: true,
  4931. style: true
  4932. };
  4933. var defaultTableToolbar = "tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol";
  4934. var defaultStyles = {
  4935. "border-collapse": "collapse",
  4936. "width": "100%"
  4937. };
  4938. var defaultCellBorderWidths = range$1(5, function(i) {
  4939. var size2 = i + 1 + "px";
  4940. return {
  4941. title: size2,
  4942. value: size2
  4943. };
  4944. });
  4945. var defaultCellBorderStyles = map$1([
  4946. "Solid",
  4947. "Dotted",
  4948. "Dashed",
  4949. "Double",
  4950. "Groove",
  4951. "Ridge",
  4952. "Inset",
  4953. "Outset",
  4954. "None",
  4955. "Hidden"
  4956. ], function(type2) {
  4957. return {
  4958. title: type2,
  4959. value: type2.toLowerCase()
  4960. };
  4961. });
  4962. var determineDefaultStyles = function(editor) {
  4963. var _a;
  4964. if (isPixelsForced(editor)) {
  4965. var dom = editor.dom;
  4966. var parentBlock = (_a = dom.getParent(editor.selection.getStart(), dom.isBlock)) !== null && _a !== void 0 ? _a : editor.getBody();
  4967. var contentWidth = getInner(SugarElement.fromDom(parentBlock));
  4968. return __assign(__assign({}, defaultStyles), { width: contentWidth + "px" });
  4969. } else if (isResponsiveForced(editor)) {
  4970. return filter$1(defaultStyles, function(_value, key2) {
  4971. return key2 !== "width";
  4972. });
  4973. } else {
  4974. return defaultStyles;
  4975. }
  4976. };
  4977. var defaultAttributes = { border: "1" };
  4978. var defaultColumnResizingBehaviour = "preservetable";
  4979. var getTableSizingMode = function(editor) {
  4980. return editor.getParam("table_sizing_mode", "auto");
  4981. };
  4982. var getTableResponseWidth = function(editor) {
  4983. return editor.getParam("table_responsive_width");
  4984. };
  4985. var getTableBorderWidths = function(editor) {
  4986. return editor.getParam("table_border_widths", defaultCellBorderWidths, "array");
  4987. };
  4988. var getTableBorderStyles = function(editor) {
  4989. return editor.getParam("table_border_styles", defaultCellBorderStyles, "array");
  4990. };
  4991. var getDefaultAttributes = function(editor) {
  4992. return editor.getParam("table_default_attributes", defaultAttributes, "object");
  4993. };
  4994. var getDefaultStyles = function(editor) {
  4995. return editor.getParam("table_default_styles", determineDefaultStyles(editor), "object");
  4996. };
  4997. var hasTableResizeBars = function(editor) {
  4998. return editor.getParam("table_resize_bars", true, "boolean");
  4999. };
  5000. var hasTabNavigation = function(editor) {
  5001. return editor.getParam("table_tab_navigation", true, "boolean");
  5002. };
  5003. var hasAdvancedCellTab = function(editor) {
  5004. return editor.getParam("table_cell_advtab", true, "boolean");
  5005. };
  5006. var hasAdvancedRowTab = function(editor) {
  5007. return editor.getParam("table_row_advtab", true, "boolean");
  5008. };
  5009. var hasAdvancedTableTab = function(editor) {
  5010. return editor.getParam("table_advtab", true, "boolean");
  5011. };
  5012. var hasAppearanceOptions = function(editor) {
  5013. return editor.getParam("table_appearance_options", true, "boolean");
  5014. };
  5015. var hasTableGrid = function(editor) {
  5016. return editor.getParam("table_grid", true, "boolean");
  5017. };
  5018. var shouldStyleWithCss = function(editor) {
  5019. return editor.getParam("table_style_by_css", false, "boolean");
  5020. };
  5021. var getCellClassList = function(editor) {
  5022. return editor.getParam("table_cell_class_list", [], "array");
  5023. };
  5024. var getRowClassList = function(editor) {
  5025. return editor.getParam("table_row_class_list", [], "array");
  5026. };
  5027. var getTableClassList = function(editor) {
  5028. return editor.getParam("table_class_list", [], "array");
  5029. };
  5030. var isPercentagesForced = function(editor) {
  5031. return getTableSizingMode(editor) === "relative" || getTableResponseWidth(editor) === true;
  5032. };
  5033. var isPixelsForced = function(editor) {
  5034. return getTableSizingMode(editor) === "fixed" || getTableResponseWidth(editor) === false;
  5035. };
  5036. var isResponsiveForced = function(editor) {
  5037. return getTableSizingMode(editor) === "responsive";
  5038. };
  5039. var getToolbar = function(editor) {
  5040. return editor.getParam("table_toolbar", defaultTableToolbar);
  5041. };
  5042. var useColumnGroup = function(editor) {
  5043. return editor.getParam("table_use_colgroups", false, "boolean");
  5044. };
  5045. var getTableHeaderType = function(editor) {
  5046. var defaultValue = "section";
  5047. var value2 = editor.getParam("table_header_type", defaultValue, "string");
  5048. var validValues = [
  5049. "section",
  5050. "cells",
  5051. "sectionCells",
  5052. "auto"
  5053. ];
  5054. if (!contains$2(validValues, value2)) {
  5055. return defaultValue;
  5056. } else {
  5057. return value2;
  5058. }
  5059. };
  5060. var getColumnResizingBehaviour = function(editor) {
  5061. var validModes = [
  5062. "preservetable",
  5063. "resizetable"
  5064. ];
  5065. var givenMode = editor.getParam("table_column_resizing", defaultColumnResizingBehaviour, "string");
  5066. return find$1(validModes, function(mode) {
  5067. return mode === givenMode;
  5068. }).getOr(defaultColumnResizingBehaviour);
  5069. };
  5070. var isPreserveTableColumnResizing = function(editor) {
  5071. return getColumnResizingBehaviour(editor) === "preservetable";
  5072. };
  5073. var isResizeTableColumnResizing = function(editor) {
  5074. return getColumnResizingBehaviour(editor) === "resizetable";
  5075. };
  5076. var getCloneElements = function(editor) {
  5077. var cloneElements = editor.getParam("table_clone_elements");
  5078. if (isString(cloneElements)) {
  5079. return Optional.some(cloneElements.split(/[ ,]/));
  5080. } else if (Array.isArray(cloneElements)) {
  5081. return Optional.some(cloneElements);
  5082. } else {
  5083. return Optional.none();
  5084. }
  5085. };
  5086. var hasObjectResizing = function(editor) {
  5087. var objectResizing = editor.getParam("object_resizing", true);
  5088. return isString(objectResizing) ? objectResizing === "table" : objectResizing;
  5089. };
  5090. var getTableBackgroundColorMap = function(editor) {
  5091. return editor.getParam("table_background_color_map", [], "array");
  5092. };
  5093. var getTableBorderColorMap = function(editor) {
  5094. return editor.getParam("table_border_color_map", [], "array");
  5095. };
  5096. var get$4 = function(editor, table2) {
  5097. if (isPercentagesForced(editor)) {
  5098. return TableSize.percentageSize(table2);
  5099. } else if (isPixelsForced(editor)) {
  5100. return TableSize.pixelSize(table2);
  5101. } else {
  5102. return TableSize.getTableSize(table2);
  5103. }
  5104. };
  5105. var cleanupLegacyAttributes = function(element) {
  5106. remove$7(element, "width");
  5107. };
  5108. var convertToPercentSize = function(table2) {
  5109. var newWidth = getPercentTableWidth(table2);
  5110. redistribute(table2, Optional.some(newWidth), Optional.none());
  5111. cleanupLegacyAttributes(table2);
  5112. };
  5113. var convertToPixelSize = function(table2) {
  5114. var newWidth = getPixelTableWidth(table2);
  5115. redistribute(table2, Optional.some(newWidth), Optional.none());
  5116. cleanupLegacyAttributes(table2);
  5117. };
  5118. var convertToNoneSize = function(table2) {
  5119. remove$6(table2, "width");
  5120. var columns2 = columns$1(table2);
  5121. var rowElements = columns2.length > 0 ? columns2 : cells$1(table2);
  5122. each$2(rowElements, function(cell2) {
  5123. remove$6(cell2, "width");
  5124. cleanupLegacyAttributes(cell2);
  5125. });
  5126. cleanupLegacyAttributes(table2);
  5127. };
  5128. var enforcePercentage = convertToPercentSize;
  5129. var enforcePixels = convertToPixelSize;
  5130. var enforceNone = convertToNoneSize;
  5131. var syncPixels = function(table2) {
  5132. var warehouse = Warehouse.fromTable(table2);
  5133. if (!Warehouse.hasColumns(warehouse)) {
  5134. each$2(cells$1(table2), function(cell2) {
  5135. var computedWidth = get$a(cell2, "width");
  5136. set$1(cell2, "width", computedWidth);
  5137. remove$7(cell2, "width");
  5138. });
  5139. }
  5140. };
  5141. var createContainer = function() {
  5142. var container = SugarElement.fromTag("div");
  5143. setAll(container, {
  5144. position: "static",
  5145. height: "0",
  5146. width: "0",
  5147. padding: "0",
  5148. margin: "0",
  5149. border: "0"
  5150. });
  5151. append$1(body$1(), container);
  5152. return container;
  5153. };
  5154. var get$3 = function(editor, isResizable2) {
  5155. return editor.inline ? ResizeWire.body(getBody(editor), createContainer(), isResizable2) : ResizeWire.only(SugarElement.fromDom(editor.getDoc()), isResizable2);
  5156. };
  5157. var remove$1 = function(editor, wire) {
  5158. if (editor.inline) {
  5159. remove$5(wire.parent());
  5160. }
  5161. };
  5162. var barResizerPrefix = "bar-";
  5163. var isResizable = function(elm) {
  5164. return get$b(elm, "data-mce-resize") !== "false";
  5165. };
  5166. var getResizeHandler = function(editor) {
  5167. var selectionRng = Optional.none();
  5168. var resize2 = Optional.none();
  5169. var wire = Optional.none();
  5170. var startW;
  5171. var startRawW;
  5172. var isTable = function(elm) {
  5173. return elm.nodeName === "TABLE";
  5174. };
  5175. var lazyResize = function() {
  5176. return resize2;
  5177. };
  5178. var lazyWire = function() {
  5179. return wire.getOr(ResizeWire.only(SugarElement.fromDom(editor.getBody()), isResizable));
  5180. };
  5181. var lazySizing = function(table2) {
  5182. return get$4(editor, table2);
  5183. };
  5184. var lazyResizingBehaviour = function() {
  5185. return isPreserveTableColumnResizing(editor) ? preserveTable() : resizeTable();
  5186. };
  5187. var getNumColumns = function(table2) {
  5188. return getGridSize(table2).columns;
  5189. };
  5190. var afterCornerResize = function(table2, origin, width2) {
  5191. var isRightEdgeResize = endsWith(origin, "e");
  5192. if (startRawW === "") {
  5193. enforcePercentage(table2);
  5194. }
  5195. if (width2 !== startW && startRawW !== "") {
  5196. set$1(table2, "width", startRawW);
  5197. var resizing = lazyResizingBehaviour();
  5198. var tableSize = lazySizing(table2);
  5199. var col2 = isPreserveTableColumnResizing(editor) || isRightEdgeResize ? getNumColumns(table2) - 1 : 0;
  5200. adjustWidth(table2, width2 - startW, col2, resizing, tableSize);
  5201. } else if (isPercentage$1(startRawW)) {
  5202. var percentW = parseFloat(startRawW.replace("%", ""));
  5203. var targetPercentW = width2 * percentW / startW;
  5204. set$1(table2, "width", targetPercentW + "%");
  5205. }
  5206. if (isPixel(startRawW)) {
  5207. syncPixels(table2);
  5208. }
  5209. };
  5210. var destroy2 = function() {
  5211. resize2.each(function(sz) {
  5212. sz.destroy();
  5213. });
  5214. wire.each(function(w) {
  5215. remove$1(editor, w);
  5216. });
  5217. };
  5218. editor.on("init", function() {
  5219. var rawWire = get$3(editor, isResizable);
  5220. wire = Optional.some(rawWire);
  5221. if (hasObjectResizing(editor) && hasTableResizeBars(editor)) {
  5222. var resizing = lazyResizingBehaviour();
  5223. var sz = TableResize.create(rawWire, resizing, lazySizing);
  5224. sz.on();
  5225. sz.events.startDrag.bind(function(_event) {
  5226. selectionRng = Optional.some(editor.selection.getRng());
  5227. });
  5228. sz.events.beforeResize.bind(function(event) {
  5229. var rawTable = event.table.dom;
  5230. fireObjectResizeStart(editor, rawTable, getPixelWidth(rawTable), getPixelHeight(rawTable), barResizerPrefix + event.type);
  5231. });
  5232. sz.events.afterResize.bind(function(event) {
  5233. var table2 = event.table;
  5234. var rawTable = table2.dom;
  5235. removeDataStyle(table2);
  5236. selectionRng.each(function(rng) {
  5237. editor.selection.setRng(rng);
  5238. editor.focus();
  5239. });
  5240. fireObjectResized(editor, rawTable, getPixelWidth(rawTable), getPixelHeight(rawTable), barResizerPrefix + event.type);
  5241. editor.undoManager.add();
  5242. });
  5243. resize2 = Optional.some(sz);
  5244. }
  5245. });
  5246. editor.on("ObjectResizeStart", function(e) {
  5247. var targetElm = e.target;
  5248. if (isTable(targetElm)) {
  5249. var table2 = SugarElement.fromDom(targetElm);
  5250. each$2(editor.dom.select(".mce-clonedresizable"), function(clone2) {
  5251. editor.dom.addClass(clone2, "mce-" + getColumnResizingBehaviour(editor) + "-columns");
  5252. });
  5253. if (!isPixelSizing(table2) && isPixelsForced(editor)) {
  5254. enforcePixels(table2);
  5255. } else if (!isPercentSizing(table2) && isPercentagesForced(editor)) {
  5256. enforcePercentage(table2);
  5257. }
  5258. if (isNoneSizing(table2) && startsWith(e.origin, barResizerPrefix)) {
  5259. enforcePercentage(table2);
  5260. }
  5261. startW = e.width;
  5262. startRawW = isResponsiveForced(editor) ? "" : getRawWidth(editor, targetElm).getOr("");
  5263. }
  5264. });
  5265. editor.on("ObjectResized", function(e) {
  5266. var targetElm = e.target;
  5267. if (isTable(targetElm)) {
  5268. var table2 = SugarElement.fromDom(targetElm);
  5269. var origin_1 = e.origin;
  5270. if (startsWith(origin_1, "corner-")) {
  5271. afterCornerResize(table2, origin_1, e.width);
  5272. }
  5273. removeDataStyle(table2);
  5274. fireTableModified(editor, table2.dom, styleModified);
  5275. }
  5276. });
  5277. editor.on("SwitchMode", function() {
  5278. lazyResize().each(function(resize3) {
  5279. if (editor.mode.isReadOnly()) {
  5280. resize3.hideBars();
  5281. } else {
  5282. resize3.showBars();
  5283. }
  5284. });
  5285. });
  5286. return {
  5287. lazyResize,
  5288. lazyWire,
  5289. destroy: destroy2
  5290. };
  5291. };
  5292. var point = function(element, offset) {
  5293. return {
  5294. element,
  5295. offset
  5296. };
  5297. };
  5298. var scan$1 = function(universe2, element, direction) {
  5299. if (universe2.property().isText(element) && universe2.property().getText(element).trim().length === 0 || universe2.property().isComment(element)) {
  5300. return direction(element).bind(function(elem) {
  5301. return scan$1(universe2, elem, direction).orThunk(function() {
  5302. return Optional.some(elem);
  5303. });
  5304. });
  5305. } else {
  5306. return Optional.none();
  5307. }
  5308. };
  5309. var toEnd = function(universe2, element) {
  5310. if (universe2.property().isText(element)) {
  5311. return universe2.property().getText(element).length;
  5312. }
  5313. var children2 = universe2.property().children(element);
  5314. return children2.length;
  5315. };
  5316. var freefallRtl$2 = function(universe2, element) {
  5317. var candidate = scan$1(universe2, element, universe2.query().prevSibling).getOr(element);
  5318. if (universe2.property().isText(candidate)) {
  5319. return point(candidate, toEnd(universe2, candidate));
  5320. }
  5321. var children2 = universe2.property().children(candidate);
  5322. return children2.length > 0 ? freefallRtl$2(universe2, children2[children2.length - 1]) : point(candidate, toEnd(universe2, candidate));
  5323. };
  5324. var freefallRtl$1 = freefallRtl$2;
  5325. var universe$2 = DomUniverse();
  5326. var freefallRtl = function(element) {
  5327. return freefallRtl$1(universe$2, element);
  5328. };
  5329. var halve = function(main, other) {
  5330. var colspan = getSpan(main, "colspan");
  5331. if (colspan === 1) {
  5332. var width2 = getGenericWidth(main);
  5333. width2.each(function(w) {
  5334. var newWidth = w.value / 2;
  5335. setGenericWidth(main, newWidth, w.unit);
  5336. setGenericWidth(other, newWidth, w.unit);
  5337. });
  5338. }
  5339. };
  5340. var isHeaderCell = isTag("th");
  5341. var isHeaderCells = function(cells2) {
  5342. return forall(cells2, function(cell2) {
  5343. return isHeaderCell(cell2.element);
  5344. });
  5345. };
  5346. var getRowHeaderType = function(isHeaderRow, isHeaderCells2) {
  5347. if (isHeaderRow && isHeaderCells2) {
  5348. return "sectionCells";
  5349. } else if (isHeaderRow) {
  5350. return "section";
  5351. } else {
  5352. return "cells";
  5353. }
  5354. };
  5355. var getRowType$1 = function(row2) {
  5356. var isHeaderRow = row2.section === "thead";
  5357. var isHeaderCells2 = is(findCommonCellType(row2.cells), "th");
  5358. if (isHeaderRow || isHeaderCells2) {
  5359. return {
  5360. type: "header",
  5361. subType: getRowHeaderType(isHeaderRow, isHeaderCells2)
  5362. };
  5363. } else if (row2.section === "tfoot") {
  5364. return { type: "footer" };
  5365. } else {
  5366. return { type: "body" };
  5367. }
  5368. };
  5369. var findCommonCellType = function(cells2) {
  5370. var headerCells = filter$2(cells2, function(cell2) {
  5371. return isHeaderCell(cell2.element);
  5372. });
  5373. if (headerCells.length === 0) {
  5374. return Optional.some("td");
  5375. } else if (headerCells.length === cells2.length) {
  5376. return Optional.some("th");
  5377. } else {
  5378. return Optional.none();
  5379. }
  5380. };
  5381. var findCommonRowType = function(rows2) {
  5382. var rowTypes = map$1(rows2, function(row2) {
  5383. return getRowType$1(row2).type;
  5384. });
  5385. var hasHeader = contains$2(rowTypes, "header");
  5386. var hasFooter = contains$2(rowTypes, "footer");
  5387. if (!hasHeader && !hasFooter) {
  5388. return Optional.some("body");
  5389. } else {
  5390. var hasBody = contains$2(rowTypes, "body");
  5391. if (hasHeader && !hasBody && !hasFooter) {
  5392. return Optional.some("header");
  5393. } else if (!hasHeader && !hasBody && hasFooter) {
  5394. return Optional.some("footer");
  5395. } else {
  5396. return Optional.none();
  5397. }
  5398. }
  5399. };
  5400. var findTableRowHeaderType = function(warehouse) {
  5401. return findMap(warehouse.all, function(row2) {
  5402. var rowType = getRowType$1(row2);
  5403. return rowType.type === "header" ? Optional.from(rowType.subType) : Optional.none();
  5404. });
  5405. };
  5406. var transformCell = function(cell2, comparator, substitution) {
  5407. return elementnew(substitution(cell2.element, comparator), true, cell2.isLocked);
  5408. };
  5409. var transformRow = function(row2, section2) {
  5410. return row2.section !== section2 ? rowcells(row2.element, row2.cells, section2, row2.isNew) : row2;
  5411. };
  5412. var section = function() {
  5413. return {
  5414. transformRow,
  5415. transformCell: function(cell2, comparator, substitution) {
  5416. var newCell = substitution(cell2.element, comparator);
  5417. var fixedCell = name(newCell) !== "td" ? mutate$1(newCell, "td") : newCell;
  5418. return elementnew(fixedCell, cell2.isNew, cell2.isLocked);
  5419. }
  5420. };
  5421. };
  5422. var sectionCells = function() {
  5423. return {
  5424. transformRow,
  5425. transformCell
  5426. };
  5427. };
  5428. var cells = function() {
  5429. return {
  5430. transformRow: function(row2, section2) {
  5431. var newSection = section2 === "thead" ? "tbody" : section2;
  5432. return transformRow(row2, newSection);
  5433. },
  5434. transformCell
  5435. };
  5436. };
  5437. var fallback = function() {
  5438. return {
  5439. transformRow: identity,
  5440. transformCell
  5441. };
  5442. };
  5443. var getTableSectionType = function(table2, fallback2) {
  5444. var warehouse = Warehouse.fromTable(table2);
  5445. var type2 = findTableRowHeaderType(warehouse).getOr(fallback2);
  5446. switch (type2) {
  5447. case "section":
  5448. return section();
  5449. case "sectionCells":
  5450. return sectionCells();
  5451. case "cells":
  5452. return cells();
  5453. }
  5454. };
  5455. var TableSection = {
  5456. getTableSectionType,
  5457. section,
  5458. sectionCells,
  5459. cells,
  5460. fallback
  5461. };
  5462. var setIfNot = function(element, property, value2, ignore) {
  5463. if (value2 === ignore) {
  5464. remove$7(element, property);
  5465. } else {
  5466. set$2(element, property, value2);
  5467. }
  5468. };
  5469. var insert$1 = function(table2, selector, element) {
  5470. last$2(children$1(table2, selector)).fold(function() {
  5471. return prepend(table2, element);
  5472. }, function(child2) {
  5473. return after$5(child2, element);
  5474. });
  5475. };
  5476. var generateSection = function(table2, sectionName) {
  5477. var section2 = child$1(table2, sectionName).getOrThunk(function() {
  5478. var newSection = SugarElement.fromTag(sectionName, owner(table2).dom);
  5479. if (sectionName === "thead") {
  5480. insert$1(table2, "caption,colgroup", newSection);
  5481. } else if (sectionName === "colgroup") {
  5482. insert$1(table2, "caption", newSection);
  5483. } else {
  5484. append$1(table2, newSection);
  5485. }
  5486. return newSection;
  5487. });
  5488. empty(section2);
  5489. return section2;
  5490. };
  5491. var render$1 = function(table2, grid2) {
  5492. var newRows = [];
  5493. var newCells = [];
  5494. var syncRows = function(gridSection) {
  5495. return map$1(gridSection, function(row2) {
  5496. if (row2.isNew) {
  5497. newRows.push(row2.element);
  5498. }
  5499. var tr = row2.element;
  5500. empty(tr);
  5501. each$2(row2.cells, function(cell2) {
  5502. if (cell2.isNew) {
  5503. newCells.push(cell2.element);
  5504. }
  5505. setIfNot(cell2.element, "colspan", cell2.colspan, 1);
  5506. setIfNot(cell2.element, "rowspan", cell2.rowspan, 1);
  5507. append$1(tr, cell2.element);
  5508. });
  5509. return tr;
  5510. });
  5511. };
  5512. var syncColGroup = function(gridSection) {
  5513. return bind$2(gridSection, function(colGroup) {
  5514. return map$1(colGroup.cells, function(col2) {
  5515. setIfNot(col2.element, "span", col2.colspan, 1);
  5516. return col2.element;
  5517. });
  5518. });
  5519. };
  5520. var renderSection = function(gridSection, sectionName) {
  5521. var section2 = generateSection(table2, sectionName);
  5522. var sync2 = sectionName === "colgroup" ? syncColGroup : syncRows;
  5523. var sectionElems = sync2(gridSection);
  5524. append(section2, sectionElems);
  5525. };
  5526. var removeSection = function(sectionName) {
  5527. child$1(table2, sectionName).each(remove$5);
  5528. };
  5529. var renderOrRemoveSection = function(gridSection, sectionName) {
  5530. if (gridSection.length > 0) {
  5531. renderSection(gridSection, sectionName);
  5532. } else {
  5533. removeSection(sectionName);
  5534. }
  5535. };
  5536. var headSection = [];
  5537. var bodySection = [];
  5538. var footSection = [];
  5539. var columnGroupsSection = [];
  5540. each$2(grid2, function(row2) {
  5541. switch (row2.section) {
  5542. case "thead":
  5543. headSection.push(row2);
  5544. break;
  5545. case "tbody":
  5546. bodySection.push(row2);
  5547. break;
  5548. case "tfoot":
  5549. footSection.push(row2);
  5550. break;
  5551. case "colgroup":
  5552. columnGroupsSection.push(row2);
  5553. break;
  5554. }
  5555. });
  5556. renderOrRemoveSection(columnGroupsSection, "colgroup");
  5557. renderOrRemoveSection(headSection, "thead");
  5558. renderOrRemoveSection(bodySection, "tbody");
  5559. renderOrRemoveSection(footSection, "tfoot");
  5560. return {
  5561. newRows,
  5562. newCells
  5563. };
  5564. };
  5565. var copy = function(grid2) {
  5566. return map$1(grid2, function(row2) {
  5567. var tr = shallow(row2.element);
  5568. each$2(row2.cells, function(cell2) {
  5569. var clonedCell = deep(cell2.element);
  5570. setIfNot(clonedCell, "colspan", cell2.colspan, 1);
  5571. setIfNot(clonedCell, "rowspan", cell2.rowspan, 1);
  5572. append$1(tr, clonedCell);
  5573. });
  5574. return tr;
  5575. });
  5576. };
  5577. var getColumn = function(grid2, index) {
  5578. return map$1(grid2, function(row2) {
  5579. return getCell(row2, index);
  5580. });
  5581. };
  5582. var getRow = function(grid2, index) {
  5583. return grid2[index];
  5584. };
  5585. var findDiff = function(xs, comp) {
  5586. if (xs.length === 0) {
  5587. return 0;
  5588. }
  5589. var first2 = xs[0];
  5590. var index = findIndex(xs, function(x) {
  5591. return !comp(first2.element, x.element);
  5592. });
  5593. return index.getOr(xs.length);
  5594. };
  5595. var subgrid = function(grid2, row2, column, comparator) {
  5596. var gridRow = getRow(grid2, row2);
  5597. var isColRow = gridRow.section === "colgroup";
  5598. var colspan = findDiff(gridRow.cells.slice(column), comparator);
  5599. var rowspan = isColRow ? 1 : findDiff(getColumn(grid2.slice(row2), column), comparator);
  5600. return {
  5601. colspan,
  5602. rowspan
  5603. };
  5604. };
  5605. var toDetails = function(grid2, comparator) {
  5606. var seen = map$1(grid2, function(row2) {
  5607. return map$1(row2.cells, never);
  5608. });
  5609. var updateSeen = function(rowIndex, columnIndex, rowspan, colspan) {
  5610. for (var row2 = rowIndex; row2 < rowIndex + rowspan; row2++) {
  5611. for (var column = columnIndex; column < columnIndex + colspan; column++) {
  5612. seen[row2][column] = true;
  5613. }
  5614. }
  5615. };
  5616. return map$1(grid2, function(row2, rowIndex) {
  5617. var details = bind$2(row2.cells, function(cell2, columnIndex) {
  5618. if (seen[rowIndex][columnIndex] === false) {
  5619. var result = subgrid(grid2, rowIndex, columnIndex, comparator);
  5620. updateSeen(rowIndex, columnIndex, result.rowspan, result.colspan);
  5621. return [detailnew(cell2.element, result.rowspan, result.colspan, cell2.isNew)];
  5622. } else {
  5623. return [];
  5624. }
  5625. });
  5626. return rowdetailnew(row2.element, details, row2.section, row2.isNew);
  5627. });
  5628. };
  5629. var toGrid = function(warehouse, generators, isNew) {
  5630. var grid2 = [];
  5631. each$2(warehouse.colgroups, function(colgroup2) {
  5632. var colgroupCols = [];
  5633. for (var columnIndex2 = 0; columnIndex2 < warehouse.grid.columns; columnIndex2++) {
  5634. var element2 = Warehouse.getColumnAt(warehouse, columnIndex2).map(function(column) {
  5635. return elementnew(column.element, isNew, false);
  5636. }).getOrThunk(function() {
  5637. return elementnew(generators.colGap(), true, false);
  5638. });
  5639. colgroupCols.push(element2);
  5640. }
  5641. grid2.push(rowcells(colgroup2.element, colgroupCols, "colgroup", isNew));
  5642. });
  5643. for (var rowIndex = 0; rowIndex < warehouse.grid.rows; rowIndex++) {
  5644. var rowCells = [];
  5645. for (var columnIndex = 0; columnIndex < warehouse.grid.columns; columnIndex++) {
  5646. var element = Warehouse.getAt(warehouse, rowIndex, columnIndex).map(function(item) {
  5647. return elementnew(item.element, isNew, item.isLocked);
  5648. }).getOrThunk(function() {
  5649. return elementnew(generators.gap(), true, false);
  5650. });
  5651. rowCells.push(element);
  5652. }
  5653. var rowDetail = warehouse.all[rowIndex];
  5654. var row2 = rowcells(rowDetail.element, rowCells, rowDetail.section, isNew);
  5655. grid2.push(row2);
  5656. }
  5657. return grid2;
  5658. };
  5659. var fromWarehouse = function(warehouse, generators) {
  5660. return toGrid(warehouse, generators, false);
  5661. };
  5662. var toDetailList = function(grid2) {
  5663. return toDetails(grid2, eq$1);
  5664. };
  5665. var findInWarehouse = function(warehouse, element) {
  5666. return findMap(warehouse.all, function(r2) {
  5667. return find$1(r2.cells, function(e) {
  5668. return eq$1(element, e.element);
  5669. });
  5670. });
  5671. };
  5672. var extractCells = function(warehouse, target, predicate) {
  5673. var details = map$1(target.selection, function(cell$1) {
  5674. return cell(cell$1).bind(function(lc) {
  5675. return findInWarehouse(warehouse, lc);
  5676. }).filter(predicate);
  5677. });
  5678. var cells2 = cat(details);
  5679. return someIf(cells2.length > 0, cells2);
  5680. };
  5681. var run = function(operation, extract2, adjustment, postAction, genWrappers) {
  5682. return function(wire, table2, target, generators, behaviours) {
  5683. var warehouse = Warehouse.fromTable(table2);
  5684. var tableSection = Optional.from(behaviours === null || behaviours === void 0 ? void 0 : behaviours.section).getOrThunk(TableSection.fallback);
  5685. var output = extract2(warehouse, target).map(function(info) {
  5686. var model = fromWarehouse(warehouse, generators);
  5687. var result = operation(model, info, eq$1, genWrappers(generators), tableSection);
  5688. var lockedColumns = getLockedColumnsFromGrid(result.grid);
  5689. var grid2 = toDetailList(result.grid);
  5690. return {
  5691. info,
  5692. grid: grid2,
  5693. cursor: result.cursor,
  5694. lockedColumns
  5695. };
  5696. });
  5697. return output.bind(function(out) {
  5698. var newElements = render$1(table2, out.grid);
  5699. var tableSizing = Optional.from(behaviours === null || behaviours === void 0 ? void 0 : behaviours.sizing).getOrThunk(function() {
  5700. return TableSize.getTableSize(table2);
  5701. });
  5702. var resizing = Optional.from(behaviours === null || behaviours === void 0 ? void 0 : behaviours.resize).getOrThunk(preserveTable);
  5703. adjustment(table2, out.grid, out.info, {
  5704. sizing: tableSizing,
  5705. resize: resizing,
  5706. section: tableSection
  5707. });
  5708. postAction(table2);
  5709. refresh(wire, table2);
  5710. remove$7(table2, LOCKED_COL_ATTR);
  5711. if (out.lockedColumns.length > 0) {
  5712. set$2(table2, LOCKED_COL_ATTR, out.lockedColumns.join(","));
  5713. }
  5714. return Optional.some({
  5715. cursor: out.cursor,
  5716. newRows: newElements.newRows,
  5717. newCells: newElements.newCells
  5718. });
  5719. });
  5720. };
  5721. };
  5722. var onPaste = function(warehouse, target) {
  5723. return cell(target.element).bind(function(cell2) {
  5724. return findInWarehouse(warehouse, cell2).map(function(details) {
  5725. var value2 = __assign(__assign({}, details), {
  5726. generators: target.generators,
  5727. clipboard: target.clipboard
  5728. });
  5729. return value2;
  5730. });
  5731. });
  5732. };
  5733. var onPasteByEditor = function(warehouse, target) {
  5734. return extractCells(warehouse, target, always).map(function(cells2) {
  5735. return {
  5736. cells: cells2,
  5737. generators: target.generators,
  5738. clipboard: target.clipboard
  5739. };
  5740. });
  5741. };
  5742. var onMergable = function(_warehouse, target) {
  5743. return target.mergable;
  5744. };
  5745. var onUnmergable = function(_warehouse, target) {
  5746. return target.unmergable;
  5747. };
  5748. var onCells = function(warehouse, target) {
  5749. return extractCells(warehouse, target, always);
  5750. };
  5751. var onUnlockedCells = function(warehouse, target) {
  5752. return extractCells(warehouse, target, function(detail2) {
  5753. return !detail2.isLocked;
  5754. });
  5755. };
  5756. var isUnlockedTableCell = function(warehouse, cell2) {
  5757. return findInWarehouse(warehouse, cell2).exists(function(detail2) {
  5758. return !detail2.isLocked;
  5759. });
  5760. };
  5761. var allUnlocked = function(warehouse, cells2) {
  5762. return forall(cells2, function(cell2) {
  5763. return isUnlockedTableCell(warehouse, cell2);
  5764. });
  5765. };
  5766. var onUnlockedMergable = function(warehouse, target) {
  5767. return onMergable(warehouse, target).filter(function(mergeable) {
  5768. return allUnlocked(warehouse, mergeable.cells);
  5769. });
  5770. };
  5771. var onUnlockedUnmergable = function(warehouse, target) {
  5772. return onUnmergable(warehouse, target).filter(function(cells2) {
  5773. return allUnlocked(warehouse, cells2);
  5774. });
  5775. };
  5776. var merge$2 = function(grid2, bounds2, comparator, substitution) {
  5777. var rows2 = extractGridDetails(grid2).rows;
  5778. if (rows2.length === 0) {
  5779. return grid2;
  5780. }
  5781. for (var i = bounds2.startRow; i <= bounds2.finishRow; i++) {
  5782. for (var j = bounds2.startCol; j <= bounds2.finishCol; j++) {
  5783. var row2 = rows2[i];
  5784. var isLocked = getCell(row2, j).isLocked;
  5785. mutateCell(row2, j, elementnew(substitution(), false, isLocked));
  5786. }
  5787. }
  5788. return grid2;
  5789. };
  5790. var unmerge = function(grid2, target, comparator, substitution) {
  5791. var rows2 = extractGridDetails(grid2).rows;
  5792. var first2 = true;
  5793. for (var i = 0; i < rows2.length; i++) {
  5794. for (var j = 0; j < cellLength(rows2[0]); j++) {
  5795. var row2 = rows2[i];
  5796. var currentCell = getCell(row2, j);
  5797. var currentCellElm = currentCell.element;
  5798. var isToReplace = comparator(currentCellElm, target);
  5799. if (isToReplace === true && first2 === false) {
  5800. mutateCell(row2, j, elementnew(substitution(), true, currentCell.isLocked));
  5801. } else if (isToReplace === true) {
  5802. first2 = false;
  5803. }
  5804. }
  5805. }
  5806. return grid2;
  5807. };
  5808. var uniqueCells = function(row2, comparator) {
  5809. return foldl(row2, function(rest, cell2) {
  5810. return exists(rest, function(currentCell) {
  5811. return comparator(currentCell.element, cell2.element);
  5812. }) ? rest : rest.concat([cell2]);
  5813. }, []);
  5814. };
  5815. var splitCols = function(grid2, index, comparator, substitution) {
  5816. if (index > 0 && index < grid2[0].cells.length) {
  5817. each$2(grid2, function(row2) {
  5818. var prevCell = row2.cells[index - 1];
  5819. var current = row2.cells[index];
  5820. var isToReplace = comparator(current.element, prevCell.element);
  5821. if (isToReplace) {
  5822. mutateCell(row2, index, elementnew(substitution(), true, current.isLocked));
  5823. }
  5824. });
  5825. }
  5826. return grid2;
  5827. };
  5828. var splitRows = function(grid2, index, comparator, substitution) {
  5829. var rows2 = extractGridDetails(grid2).rows;
  5830. if (index > 0 && index < rows2.length) {
  5831. var rowPrevCells = rows2[index - 1].cells;
  5832. var cells2 = uniqueCells(rowPrevCells, comparator);
  5833. each$2(cells2, function(cell2) {
  5834. var replacement = Optional.none();
  5835. for (var i = index; i < rows2.length; i++) {
  5836. var _loop_1 = function(j2) {
  5837. var row2 = rows2[i];
  5838. var current = getCell(row2, j2);
  5839. var isToReplace = comparator(current.element, cell2.element);
  5840. if (isToReplace) {
  5841. if (replacement.isNone()) {
  5842. replacement = Optional.some(substitution());
  5843. }
  5844. replacement.each(function(sub) {
  5845. mutateCell(row2, j2, elementnew(sub, true, current.isLocked));
  5846. });
  5847. }
  5848. };
  5849. for (var j = 0; j < cellLength(rows2[0]); j++) {
  5850. _loop_1(j);
  5851. }
  5852. }
  5853. });
  5854. }
  5855. return grid2;
  5856. };
  5857. var value$1 = function(o) {
  5858. var or = function(_opt) {
  5859. return value$1(o);
  5860. };
  5861. var orThunk = function(_f) {
  5862. return value$1(o);
  5863. };
  5864. var map2 = function(f) {
  5865. return value$1(f(o));
  5866. };
  5867. var mapError = function(_f) {
  5868. return value$1(o);
  5869. };
  5870. var each2 = function(f) {
  5871. f(o);
  5872. };
  5873. var bind2 = function(f) {
  5874. return f(o);
  5875. };
  5876. var fold = function(_, onValue) {
  5877. return onValue(o);
  5878. };
  5879. var exists2 = function(f) {
  5880. return f(o);
  5881. };
  5882. var forall2 = function(f) {
  5883. return f(o);
  5884. };
  5885. var toOptional = function() {
  5886. return Optional.some(o);
  5887. };
  5888. return {
  5889. isValue: always,
  5890. isError: never,
  5891. getOr: constant(o),
  5892. getOrThunk: constant(o),
  5893. getOrDie: constant(o),
  5894. or,
  5895. orThunk,
  5896. fold,
  5897. map: map2,
  5898. mapError,
  5899. each: each2,
  5900. bind: bind2,
  5901. exists: exists2,
  5902. forall: forall2,
  5903. toOptional
  5904. };
  5905. };
  5906. var error = function(message) {
  5907. var getOrThunk = function(f) {
  5908. return f();
  5909. };
  5910. var getOrDie = function() {
  5911. return die(String(message))();
  5912. };
  5913. var or = identity;
  5914. var orThunk = function(f) {
  5915. return f();
  5916. };
  5917. var map2 = function(_f) {
  5918. return error(message);
  5919. };
  5920. var mapError = function(f) {
  5921. return error(f(message));
  5922. };
  5923. var bind2 = function(_f) {
  5924. return error(message);
  5925. };
  5926. var fold = function(onError, _) {
  5927. return onError(message);
  5928. };
  5929. return {
  5930. isValue: never,
  5931. isError: always,
  5932. getOr: identity,
  5933. getOrThunk,
  5934. getOrDie,
  5935. or,
  5936. orThunk,
  5937. fold,
  5938. map: map2,
  5939. mapError,
  5940. each: noop,
  5941. bind: bind2,
  5942. exists: never,
  5943. forall: always,
  5944. toOptional: Optional.none
  5945. };
  5946. };
  5947. var fromOption = function(opt, err) {
  5948. return opt.fold(function() {
  5949. return error(err);
  5950. }, value$1);
  5951. };
  5952. var Result = {
  5953. value: value$1,
  5954. error,
  5955. fromOption
  5956. };
  5957. var measure = function(startAddress, gridA, gridB) {
  5958. if (startAddress.row >= gridA.length || startAddress.column > cellLength(gridA[0])) {
  5959. return Result.error("invalid start address out of table bounds, row: " + startAddress.row + ", column: " + startAddress.column);
  5960. }
  5961. var rowRemainder = gridA.slice(startAddress.row);
  5962. var colRemainder = rowRemainder[0].cells.slice(startAddress.column);
  5963. var colRequired = cellLength(gridB[0]);
  5964. var rowRequired = gridB.length;
  5965. return Result.value({
  5966. rowDelta: rowRemainder.length - rowRequired,
  5967. colDelta: colRemainder.length - colRequired
  5968. });
  5969. };
  5970. var measureWidth = function(gridA, gridB) {
  5971. var colLengthA = cellLength(gridA[0]);
  5972. var colLengthB = cellLength(gridB[0]);
  5973. return {
  5974. rowDelta: 0,
  5975. colDelta: colLengthA - colLengthB
  5976. };
  5977. };
  5978. var measureHeight = function(gridA, gridB) {
  5979. var rowLengthA = gridA.length;
  5980. var rowLengthB = gridB.length;
  5981. return {
  5982. rowDelta: rowLengthA - rowLengthB,
  5983. colDelta: 0
  5984. };
  5985. };
  5986. var generateElements = function(amount, row2, generators, isLocked) {
  5987. var generator = row2.section === "colgroup" ? generators.col : generators.cell;
  5988. return range$1(amount, function(idx) {
  5989. return elementnew(generator(), true, isLocked(idx));
  5990. });
  5991. };
  5992. var rowFill = function(grid2, amount, generators, lockedColumns) {
  5993. var exampleRow = grid2[grid2.length - 1];
  5994. return grid2.concat(range$1(amount, function() {
  5995. var generator = exampleRow.section === "colgroup" ? generators.colgroup : generators.row;
  5996. var row2 = clone$1(exampleRow, generator, identity);
  5997. var elements = generateElements(row2.cells.length, row2, generators, function(idx) {
  5998. return has$1(lockedColumns, idx.toString());
  5999. });
  6000. return setCells(row2, elements);
  6001. }));
  6002. };
  6003. var colFill = function(grid2, amount, generators, startIndex) {
  6004. return map$1(grid2, function(row2) {
  6005. var newChildren = generateElements(amount, row2, generators, never);
  6006. return addCells(row2, startIndex, newChildren);
  6007. });
  6008. };
  6009. var lockedColFill = function(grid2, generators, lockedColumns) {
  6010. return map$1(grid2, function(row2) {
  6011. return foldl(lockedColumns, function(acc, colNum) {
  6012. var newChild = generateElements(1, row2, generators, always)[0];
  6013. return addCell(acc, colNum, newChild);
  6014. }, row2);
  6015. });
  6016. };
  6017. var tailor = function(gridA, delta, generators) {
  6018. var fillCols = delta.colDelta < 0 ? colFill : identity;
  6019. var fillRows = delta.rowDelta < 0 ? rowFill : identity;
  6020. var lockedColumns = getLockedColumnsFromGrid(gridA);
  6021. var gridWidth = cellLength(gridA[0]);
  6022. var isLastColLocked = exists(lockedColumns, function(locked) {
  6023. return locked === gridWidth - 1;
  6024. });
  6025. var modifiedCols = fillCols(gridA, Math.abs(delta.colDelta), generators, isLastColLocked ? gridWidth - 1 : gridWidth);
  6026. var newLockedColumns = getLockedColumnsFromGrid(modifiedCols);
  6027. return fillRows(modifiedCols, Math.abs(delta.rowDelta), generators, mapToObject(newLockedColumns, always));
  6028. };
  6029. var isSpanning = function(grid2, row2, col2, comparator) {
  6030. var candidate = getCell(grid2[row2], col2);
  6031. var matching = curry(comparator, candidate.element);
  6032. var currentRow = grid2[row2];
  6033. return grid2.length > 1 && cellLength(currentRow) > 1 && (col2 > 0 && matching(getCellElement(currentRow, col2 - 1)) || col2 < currentRow.cells.length - 1 && matching(getCellElement(currentRow, col2 + 1)) || row2 > 0 && matching(getCellElement(grid2[row2 - 1], col2)) || row2 < grid2.length - 1 && matching(getCellElement(grid2[row2 + 1], col2)));
  6034. };
  6035. var mergeTables = function(startAddress, gridA, gridB, generator, comparator, lockedColumns) {
  6036. var startRow = startAddress.row;
  6037. var startCol = startAddress.column;
  6038. var mergeHeight = gridB.length;
  6039. var mergeWidth = cellLength(gridB[0]);
  6040. var endRow = startRow + mergeHeight;
  6041. var endCol = startCol + mergeWidth + lockedColumns.length;
  6042. var lockedColumnObj = mapToObject(lockedColumns, always);
  6043. for (var r2 = startRow; r2 < endRow; r2++) {
  6044. var skippedCol = 0;
  6045. for (var c = startCol; c < endCol; c++) {
  6046. if (lockedColumnObj[c]) {
  6047. skippedCol++;
  6048. continue;
  6049. }
  6050. if (isSpanning(gridA, r2, c, comparator)) {
  6051. unmerge(gridA, getCellElement(gridA[r2], c), comparator, generator.cell);
  6052. }
  6053. var gridBColIndex = c - startCol - skippedCol;
  6054. var newCell = getCell(gridB[r2 - startRow], gridBColIndex);
  6055. var newCellElm = newCell.element;
  6056. var replacement = generator.replace(newCellElm);
  6057. mutateCell(gridA[r2], c, elementnew(replacement, true, newCell.isLocked));
  6058. }
  6059. }
  6060. return gridA;
  6061. };
  6062. var getValidStartAddress = function(currentStartAddress, grid2, lockedColumns) {
  6063. var gridColLength = cellLength(grid2[0]);
  6064. var adjustedRowAddress = extractGridDetails(grid2).cols.length + currentStartAddress.row;
  6065. var possibleColAddresses = range$1(gridColLength - currentStartAddress.column, function(num) {
  6066. return num + currentStartAddress.column;
  6067. });
  6068. var validColAddress = find$1(possibleColAddresses, function(num) {
  6069. return forall(lockedColumns, function(col2) {
  6070. return col2 !== num;
  6071. });
  6072. }).getOr(gridColLength - 1);
  6073. return {
  6074. row: adjustedRowAddress,
  6075. column: validColAddress
  6076. };
  6077. };
  6078. var getLockedColumnsWithinBounds = function(startAddress, grid2, lockedColumns) {
  6079. return filter$2(lockedColumns, function(colNum) {
  6080. return colNum >= startAddress.column && colNum <= cellLength(grid2[0]) + startAddress.column;
  6081. });
  6082. };
  6083. var merge$1 = function(startAddress, gridA, gridB, generator, comparator) {
  6084. var lockedColumns = getLockedColumnsFromGrid(gridA);
  6085. var validStartAddress = getValidStartAddress(startAddress, gridA, lockedColumns);
  6086. var gridBRows = extractGridDetails(gridB).rows;
  6087. var lockedColumnsWithinBounds = getLockedColumnsWithinBounds(validStartAddress, gridBRows, lockedColumns);
  6088. var result = measure(validStartAddress, gridA, gridBRows);
  6089. return result.map(function(diff) {
  6090. var delta = __assign(__assign({}, diff), { colDelta: diff.colDelta - lockedColumnsWithinBounds.length });
  6091. var fittedGrid = tailor(gridA, delta, generator);
  6092. var newLockedColumns = getLockedColumnsFromGrid(fittedGrid);
  6093. var newLockedColumnsWithinBounds = getLockedColumnsWithinBounds(validStartAddress, gridBRows, newLockedColumns);
  6094. return mergeTables(validStartAddress, fittedGrid, gridBRows, generator, comparator, newLockedColumnsWithinBounds);
  6095. });
  6096. };
  6097. var insertCols = function(index, gridA, gridB, generator, comparator) {
  6098. splitCols(gridA, index, comparator, generator.cell);
  6099. var delta = measureHeight(gridB, gridA);
  6100. var fittedNewGrid = tailor(gridB, delta, generator);
  6101. var secondDelta = measureHeight(gridA, fittedNewGrid);
  6102. var fittedOldGrid = tailor(gridA, secondDelta, generator);
  6103. return map$1(fittedOldGrid, function(gridRow, i) {
  6104. return addCells(gridRow, index, fittedNewGrid[i].cells);
  6105. });
  6106. };
  6107. var insertRows = function(index, gridA, gridB, generator, comparator) {
  6108. splitRows(gridA, index, comparator, generator.cell);
  6109. var locked = getLockedColumnsFromGrid(gridA);
  6110. var diff = measureWidth(gridA, gridB);
  6111. var delta = __assign(__assign({}, diff), { colDelta: diff.colDelta - locked.length });
  6112. var fittedOldGrid = tailor(gridA, delta, generator);
  6113. var _a = extractGridDetails(fittedOldGrid), oldCols = _a.cols, oldRows = _a.rows;
  6114. var newLocked = getLockedColumnsFromGrid(fittedOldGrid);
  6115. var secondDiff = measureWidth(gridB, gridA);
  6116. var secondDelta = __assign(__assign({}, secondDiff), { colDelta: secondDiff.colDelta + newLocked.length });
  6117. var fittedGridB = lockedColFill(gridB, generator, newLocked);
  6118. var fittedNewGrid = tailor(fittedGridB, secondDelta, generator);
  6119. return oldCols.concat(oldRows.slice(0, index)).concat(fittedNewGrid).concat(oldRows.slice(index, oldRows.length));
  6120. };
  6121. var cloneRow = function(row2, cloneCell, comparator, substitution) {
  6122. return clone$1(row2, function(elem) {
  6123. return substitution(elem, comparator);
  6124. }, cloneCell);
  6125. };
  6126. var insertRowAt = function(grid2, index, example, comparator, substitution) {
  6127. var _a = extractGridDetails(grid2), rows2 = _a.rows, cols = _a.cols;
  6128. var before2 = rows2.slice(0, index);
  6129. var after2 = rows2.slice(index);
  6130. var newRow = cloneRow(rows2[example], function(ex, c) {
  6131. var withinSpan = index > 0 && index < rows2.length && comparator(getCellElement(rows2[index - 1], c), getCellElement(rows2[index], c));
  6132. var ret = withinSpan ? getCell(rows2[index], c) : elementnew(substitution(ex.element, comparator), true, ex.isLocked);
  6133. return ret;
  6134. }, comparator, substitution);
  6135. return cols.concat(before2).concat([newRow]).concat(after2);
  6136. };
  6137. var getElementFor = function(row2, column, section2, withinSpan, example, comparator, substitution) {
  6138. if (section2 === "colgroup" || !withinSpan) {
  6139. var cell2 = getCell(row2, example);
  6140. return elementnew(substitution(cell2.element, comparator), true, false);
  6141. } else {
  6142. return getCell(row2, column);
  6143. }
  6144. };
  6145. var insertColumnAt = function(grid2, index, example, comparator, substitution) {
  6146. return map$1(grid2, function(row2) {
  6147. var withinSpan = index > 0 && index < cellLength(row2) && comparator(getCellElement(row2, index - 1), getCellElement(row2, index));
  6148. var sub = getElementFor(row2, index, row2.section, withinSpan, example, comparator, substitution);
  6149. return addCell(row2, index, sub);
  6150. });
  6151. };
  6152. var deleteColumnsAt = function(grid2, columns2) {
  6153. return bind$2(grid2, function(row2) {
  6154. var existingCells = row2.cells;
  6155. var cells2 = foldr(columns2, function(acc, column) {
  6156. return column >= 0 && column < acc.length ? acc.slice(0, column).concat(acc.slice(column + 1)) : acc;
  6157. }, existingCells);
  6158. return cells2.length > 0 ? [rowcells(row2.element, cells2, row2.section, row2.isNew)] : [];
  6159. });
  6160. };
  6161. var deleteRowsAt = function(grid2, start, finish) {
  6162. var _a = extractGridDetails(grid2), rows2 = _a.rows, cols = _a.cols;
  6163. return cols.concat(rows2.slice(0, start)).concat(rows2.slice(finish + 1));
  6164. };
  6165. var notInStartRow = function(grid2, rowIndex, colIndex, comparator) {
  6166. return getCellElement(grid2[rowIndex], colIndex) !== void 0 && (rowIndex > 0 && comparator(getCellElement(grid2[rowIndex - 1], colIndex), getCellElement(grid2[rowIndex], colIndex)));
  6167. };
  6168. var notInStartColumn = function(row2, index, comparator) {
  6169. return index > 0 && comparator(getCellElement(row2, index - 1), getCellElement(row2, index));
  6170. };
  6171. var isDuplicatedCell = function(grid2, rowIndex, colIndex, comparator) {
  6172. return notInStartRow(grid2, rowIndex, colIndex, comparator) || notInStartColumn(grid2[rowIndex], colIndex, comparator);
  6173. };
  6174. var rowReplacerPredicate = function(targetRow, columnHeaders) {
  6175. var entireTableIsHeader = forall(columnHeaders, identity) && isHeaderCells(targetRow.cells);
  6176. return entireTableIsHeader ? always : function(cell2, _rowIndex, colIndex) {
  6177. var type2 = name(cell2.element);
  6178. return !(type2 === "th" && columnHeaders[colIndex]);
  6179. };
  6180. };
  6181. var columnReplacePredicate = function(targetColumn, rowHeaders) {
  6182. var entireTableIsHeader = forall(rowHeaders, identity) && isHeaderCells(targetColumn);
  6183. return entireTableIsHeader ? always : function(cell2, rowIndex, _colIndex) {
  6184. var type2 = name(cell2.element);
  6185. return !(type2 === "th" && rowHeaders[rowIndex]);
  6186. };
  6187. };
  6188. var determineScope = function(applyScope, element, newScope, isInHeader) {
  6189. var hasSpan = function(scope) {
  6190. return scope === "row" ? hasRowspan(element) : hasColspan(element);
  6191. };
  6192. var getScope = function(scope) {
  6193. return hasSpan(scope) ? scope + "group" : scope;
  6194. };
  6195. if (applyScope) {
  6196. return isHeaderCell(element) ? getScope(newScope) : null;
  6197. } else if (isInHeader && isHeaderCell(element)) {
  6198. var oppositeScope = newScope === "row" ? "col" : "row";
  6199. return getScope(oppositeScope);
  6200. } else {
  6201. return null;
  6202. }
  6203. };
  6204. var rowScopeGenerator = function(applyScope, columnHeaders) {
  6205. return function(cell2, rowIndex, columnIndex) {
  6206. return Optional.some(determineScope(applyScope, cell2.element, "col", columnHeaders[columnIndex]));
  6207. };
  6208. };
  6209. var columnScopeGenerator = function(applyScope, rowHeaders) {
  6210. return function(cell2, rowIndex) {
  6211. return Optional.some(determineScope(applyScope, cell2.element, "row", rowHeaders[rowIndex]));
  6212. };
  6213. };
  6214. var replace = function(cell2, comparator, substitute) {
  6215. return elementnew(substitute(cell2.element, comparator), true, cell2.isLocked);
  6216. };
  6217. var replaceIn = function(grid2, targets, comparator, substitute, replacer, genScope, shouldReplace) {
  6218. var isTarget = function(cell2) {
  6219. return exists(targets, function(target) {
  6220. return comparator(cell2.element, target.element);
  6221. });
  6222. };
  6223. return map$1(grid2, function(row2, rowIndex) {
  6224. return mapCells(row2, function(cell2, colIndex) {
  6225. if (isTarget(cell2)) {
  6226. var newCell_1 = shouldReplace(cell2, rowIndex, colIndex) ? replacer(cell2, comparator, substitute) : cell2;
  6227. genScope(newCell_1, rowIndex, colIndex).each(function(scope) {
  6228. setOptions(newCell_1.element, { scope: Optional.from(scope) });
  6229. });
  6230. return newCell_1;
  6231. } else {
  6232. return cell2;
  6233. }
  6234. });
  6235. });
  6236. };
  6237. var getColumnCells = function(rows2, columnIndex, comparator) {
  6238. return bind$2(rows2, function(row2, i) {
  6239. return isDuplicatedCell(rows2, i, columnIndex, comparator) ? [] : [getCell(row2, columnIndex)];
  6240. });
  6241. };
  6242. var getRowCells = function(rows2, rowIndex, comparator) {
  6243. var targetRow = rows2[rowIndex];
  6244. return bind$2(targetRow.cells, function(item, i) {
  6245. return isDuplicatedCell(rows2, rowIndex, i, comparator) ? [] : [item];
  6246. });
  6247. };
  6248. var replaceColumns = function(grid2, indexes, applyScope, comparator, substitution) {
  6249. var rows2 = extractGridDetails(grid2).rows;
  6250. var targets = bind$2(indexes, function(index) {
  6251. return getColumnCells(rows2, index, comparator);
  6252. });
  6253. var rowHeaders = map$1(grid2, function(row2) {
  6254. return isHeaderCells(row2.cells);
  6255. });
  6256. var shouldReplaceCell = columnReplacePredicate(targets, rowHeaders);
  6257. var scopeGenerator = columnScopeGenerator(applyScope, rowHeaders);
  6258. return replaceIn(grid2, targets, comparator, substitution, replace, scopeGenerator, shouldReplaceCell);
  6259. };
  6260. var replaceRows = function(grid2, indexes, section2, applyScope, comparator, substitution, tableSection) {
  6261. var _a = extractGridDetails(grid2), cols = _a.cols, rows2 = _a.rows;
  6262. var targetRow = rows2[indexes[0]];
  6263. var targets = bind$2(indexes, function(index) {
  6264. return getRowCells(rows2, index, comparator);
  6265. });
  6266. var columnHeaders = map$1(targetRow.cells, function(_cell, index) {
  6267. return isHeaderCells(getColumnCells(rows2, index, comparator));
  6268. });
  6269. var newRows = __spreadArray([], rows2, true);
  6270. each$2(indexes, function(index) {
  6271. newRows[index] = tableSection.transformRow(rows2[index], section2);
  6272. });
  6273. var newGrid = cols.concat(newRows);
  6274. var shouldReplaceCell = rowReplacerPredicate(targetRow, columnHeaders);
  6275. var scopeGenerator = rowScopeGenerator(applyScope, columnHeaders);
  6276. return replaceIn(newGrid, targets, comparator, substitution, tableSection.transformCell, scopeGenerator, shouldReplaceCell);
  6277. };
  6278. var replaceCells = function(grid2, details, comparator, substitution) {
  6279. var rows2 = extractGridDetails(grid2).rows;
  6280. var targetCells = map$1(details, function(detail2) {
  6281. return getCell(rows2[detail2.row], detail2.column);
  6282. });
  6283. return replaceIn(grid2, targetCells, comparator, substitution, replace, Optional.none, always);
  6284. };
  6285. var uniqueColumns = function(details) {
  6286. var uniqueCheck = function(rest, detail2) {
  6287. var columnExists = exists(rest, function(currentDetail) {
  6288. return currentDetail.column === detail2.column;
  6289. });
  6290. return columnExists ? rest : rest.concat([detail2]);
  6291. };
  6292. return foldl(details, uniqueCheck, []).sort(function(detailA, detailB) {
  6293. return detailA.column - detailB.column;
  6294. });
  6295. };
  6296. var isCol = isTag("col");
  6297. var isColgroup = isTag("colgroup");
  6298. var isRow$1 = function(element) {
  6299. return name(element) === "tr" || isColgroup(element);
  6300. };
  6301. var elementToData = function(element) {
  6302. var colspan = getAttrValue(element, "colspan", 1);
  6303. var rowspan = getAttrValue(element, "rowspan", 1);
  6304. return {
  6305. element,
  6306. colspan,
  6307. rowspan
  6308. };
  6309. };
  6310. var modification = function(generators, toData) {
  6311. if (toData === void 0) {
  6312. toData = elementToData;
  6313. }
  6314. var nuCell = function(data) {
  6315. return isCol(data.element) ? generators.col(data) : generators.cell(data);
  6316. };
  6317. var nuRow = function(data) {
  6318. return isColgroup(data.element) ? generators.colgroup(data) : generators.row(data);
  6319. };
  6320. var add2 = function(element) {
  6321. if (isRow$1(element)) {
  6322. return nuRow({ element });
  6323. } else {
  6324. var replacement = nuCell(toData(element));
  6325. recent = Optional.some({
  6326. item: element,
  6327. replacement
  6328. });
  6329. return replacement;
  6330. }
  6331. };
  6332. var recent = Optional.none();
  6333. var getOrInit = function(element, comparator) {
  6334. return recent.fold(function() {
  6335. return add2(element);
  6336. }, function(p) {
  6337. return comparator(element, p.item) ? p.replacement : add2(element);
  6338. });
  6339. };
  6340. return { getOrInit };
  6341. };
  6342. var transform = function(tag) {
  6343. return function(generators) {
  6344. var list = [];
  6345. var find2 = function(element, comparator) {
  6346. return find$1(list, function(x) {
  6347. return comparator(x.item, element);
  6348. });
  6349. };
  6350. var makeNew = function(element) {
  6351. var attrs = tag === "td" ? { scope: null } : {};
  6352. var cell2 = generators.replace(element, tag, attrs);
  6353. list.push({
  6354. item: element,
  6355. sub: cell2
  6356. });
  6357. return cell2;
  6358. };
  6359. var replaceOrInit = function(element, comparator) {
  6360. if (isRow$1(element) || isCol(element)) {
  6361. return element;
  6362. } else {
  6363. return find2(element, comparator).fold(function() {
  6364. return makeNew(element);
  6365. }, function(p) {
  6366. return comparator(element, p.item) ? p.sub : makeNew(element);
  6367. });
  6368. }
  6369. };
  6370. return { replaceOrInit };
  6371. };
  6372. };
  6373. var getScopeAttribute = function(cell2) {
  6374. return getOpt(cell2, "scope").map(function(attribute) {
  6375. return attribute.substr(0, 3);
  6376. });
  6377. };
  6378. var merging = function(generators) {
  6379. var unmerge2 = function(cell2) {
  6380. var scope = getScopeAttribute(cell2);
  6381. scope.each(function(attribute) {
  6382. return set$2(cell2, "scope", attribute);
  6383. });
  6384. return function() {
  6385. var raw = generators.cell({
  6386. element: cell2,
  6387. colspan: 1,
  6388. rowspan: 1
  6389. });
  6390. remove$6(raw, "width");
  6391. remove$6(cell2, "width");
  6392. scope.each(function(attribute) {
  6393. return set$2(raw, "scope", attribute);
  6394. });
  6395. return raw;
  6396. };
  6397. };
  6398. var merge2 = function(cells2) {
  6399. var getScopeProperty = function() {
  6400. var stringAttributes = cat(map$1(cells2, getScopeAttribute));
  6401. if (stringAttributes.length === 0) {
  6402. return Optional.none();
  6403. } else {
  6404. var baseScope_1 = stringAttributes[0];
  6405. var scopes_1 = [
  6406. "row",
  6407. "col"
  6408. ];
  6409. var isMixed = exists(stringAttributes, function(attribute) {
  6410. return attribute !== baseScope_1 && contains$2(scopes_1, attribute);
  6411. });
  6412. return isMixed ? Optional.none() : Optional.from(baseScope_1);
  6413. }
  6414. };
  6415. remove$6(cells2[0], "width");
  6416. getScopeProperty().fold(function() {
  6417. return remove$7(cells2[0], "scope");
  6418. }, function(attribute) {
  6419. return set$2(cells2[0], "scope", attribute + "group");
  6420. });
  6421. return constant(cells2[0]);
  6422. };
  6423. return {
  6424. unmerge: unmerge2,
  6425. merge: merge2
  6426. };
  6427. };
  6428. var Generators = {
  6429. modification,
  6430. transform,
  6431. merging
  6432. };
  6433. var blockList = [
  6434. "body",
  6435. "p",
  6436. "div",
  6437. "article",
  6438. "aside",
  6439. "figcaption",
  6440. "figure",
  6441. "footer",
  6442. "header",
  6443. "nav",
  6444. "section",
  6445. "ol",
  6446. "ul",
  6447. "table",
  6448. "thead",
  6449. "tfoot",
  6450. "tbody",
  6451. "caption",
  6452. "tr",
  6453. "td",
  6454. "th",
  6455. "h1",
  6456. "h2",
  6457. "h3",
  6458. "h4",
  6459. "h5",
  6460. "h6",
  6461. "blockquote",
  6462. "pre",
  6463. "address"
  6464. ];
  6465. var isList$1 = function(universe2, item) {
  6466. var tagName = universe2.property().name(item);
  6467. return contains$2([
  6468. "ol",
  6469. "ul"
  6470. ], tagName);
  6471. };
  6472. var isBlock$1 = function(universe2, item) {
  6473. var tagName = universe2.property().name(item);
  6474. return contains$2(blockList, tagName);
  6475. };
  6476. var isEmptyTag$1 = function(universe2, item) {
  6477. return contains$2([
  6478. "br",
  6479. "img",
  6480. "hr",
  6481. "input"
  6482. ], universe2.property().name(item));
  6483. };
  6484. var universe$1 = DomUniverse();
  6485. var isBlock = function(element) {
  6486. return isBlock$1(universe$1, element);
  6487. };
  6488. var isList = function(element) {
  6489. return isList$1(universe$1, element);
  6490. };
  6491. var isEmptyTag = function(element) {
  6492. return isEmptyTag$1(universe$1, element);
  6493. };
  6494. var merge = function(cells2) {
  6495. var isBr2 = function(el) {
  6496. return name(el) === "br";
  6497. };
  6498. var advancedBr = function(children2) {
  6499. return forall(children2, function(c) {
  6500. return isBr2(c) || isText(c) && get$9(c).trim().length === 0;
  6501. });
  6502. };
  6503. var isListItem = function(el) {
  6504. return name(el) === "li" || ancestor$2(el, isList).isSome();
  6505. };
  6506. var siblingIsBlock = function(el) {
  6507. return nextSibling(el).map(function(rightSibling) {
  6508. if (isBlock(rightSibling)) {
  6509. return true;
  6510. }
  6511. if (isEmptyTag(rightSibling)) {
  6512. return name(rightSibling) === "img" ? false : true;
  6513. }
  6514. return false;
  6515. }).getOr(false);
  6516. };
  6517. var markCell = function(cell2) {
  6518. return last$1(cell2).bind(function(rightEdge) {
  6519. var rightSiblingIsBlock = siblingIsBlock(rightEdge);
  6520. return parent(rightEdge).map(function(parent2) {
  6521. return rightSiblingIsBlock === true || isListItem(parent2) || isBr2(rightEdge) || isBlock(parent2) && !eq$1(cell2, parent2) ? [] : [SugarElement.fromTag("br")];
  6522. });
  6523. }).getOr([]);
  6524. };
  6525. var markContent = function() {
  6526. var content = bind$2(cells2, function(cell2) {
  6527. var children2 = children$3(cell2);
  6528. return advancedBr(children2) ? [] : children2.concat(markCell(cell2));
  6529. });
  6530. return content.length === 0 ? [SugarElement.fromTag("br")] : content;
  6531. };
  6532. var contents = markContent();
  6533. empty(cells2[0]);
  6534. append(cells2[0], contents);
  6535. };
  6536. var isEditable = function(elem) {
  6537. return isEditable$1(elem, true);
  6538. };
  6539. var prune = function(table2) {
  6540. var cells2 = cells$1(table2);
  6541. if (cells2.length === 0) {
  6542. remove$5(table2);
  6543. }
  6544. };
  6545. var outcome = function(grid2, cursor) {
  6546. return {
  6547. grid: grid2,
  6548. cursor
  6549. };
  6550. };
  6551. var findEditableCursorPosition = function(rows2) {
  6552. return findMap(rows2, function(row2) {
  6553. return findMap(row2.cells, function(cell2) {
  6554. var elem = cell2.element;
  6555. return someIf(isEditable(elem), elem);
  6556. });
  6557. });
  6558. };
  6559. var elementFromGrid = function(grid2, row2, column) {
  6560. var _a, _b;
  6561. var rows2 = extractGridDetails(grid2).rows;
  6562. return Optional.from((_b = (_a = rows2[row2]) === null || _a === void 0 ? void 0 : _a.cells[column]) === null || _b === void 0 ? void 0 : _b.element).filter(isEditable).orThunk(function() {
  6563. return findEditableCursorPosition(rows2);
  6564. });
  6565. };
  6566. var bundle = function(grid2, row2, column) {
  6567. var cursorElement = elementFromGrid(grid2, row2, column);
  6568. return outcome(grid2, cursorElement);
  6569. };
  6570. var uniqueRows = function(details) {
  6571. var rowCompilation = function(rest, detail2) {
  6572. var rowExists = exists(rest, function(currentDetail) {
  6573. return currentDetail.row === detail2.row;
  6574. });
  6575. return rowExists ? rest : rest.concat([detail2]);
  6576. };
  6577. return foldl(details, rowCompilation, []).sort(function(detailA, detailB) {
  6578. return detailA.row - detailB.row;
  6579. });
  6580. };
  6581. var opInsertRowsBefore = function(grid2, details, comparator, genWrappers) {
  6582. var targetIndex = details[0].row;
  6583. var rows2 = uniqueRows(details);
  6584. var newGrid = foldr(rows2, function(acc, row2) {
  6585. var newG = insertRowAt(acc.grid, targetIndex, row2.row + acc.delta, comparator, genWrappers.getOrInit);
  6586. return {
  6587. grid: newG,
  6588. delta: acc.delta + 1
  6589. };
  6590. }, {
  6591. grid: grid2,
  6592. delta: 0
  6593. }).grid;
  6594. return bundle(newGrid, targetIndex, details[0].column);
  6595. };
  6596. var opInsertRowsAfter = function(grid2, details, comparator, genWrappers) {
  6597. var rows2 = uniqueRows(details);
  6598. var target = rows2[rows2.length - 1];
  6599. var targetIndex = target.row + target.rowspan;
  6600. var newGrid = foldr(rows2, function(newG, row2) {
  6601. return insertRowAt(newG, targetIndex, row2.row, comparator, genWrappers.getOrInit);
  6602. }, grid2);
  6603. return bundle(newGrid, targetIndex, details[0].column);
  6604. };
  6605. var opInsertColumnsBefore = function(grid2, extractDetail, comparator, genWrappers) {
  6606. var details = extractDetail.details;
  6607. var columns2 = uniqueColumns(details);
  6608. var targetIndex = columns2[0].column;
  6609. var newGrid = foldr(columns2, function(acc, col2) {
  6610. var newG = insertColumnAt(acc.grid, targetIndex, col2.column + acc.delta, comparator, genWrappers.getOrInit);
  6611. return {
  6612. grid: newG,
  6613. delta: acc.delta + 1
  6614. };
  6615. }, {
  6616. grid: grid2,
  6617. delta: 0
  6618. }).grid;
  6619. return bundle(newGrid, details[0].row, targetIndex);
  6620. };
  6621. var opInsertColumnsAfter = function(grid2, extractDetail, comparator, genWrappers) {
  6622. var details = extractDetail.details;
  6623. var target = details[details.length - 1];
  6624. var targetIndex = target.column + target.colspan;
  6625. var columns2 = uniqueColumns(details);
  6626. var newGrid = foldr(columns2, function(newG, col2) {
  6627. return insertColumnAt(newG, targetIndex, col2.column, comparator, genWrappers.getOrInit);
  6628. }, grid2);
  6629. return bundle(newGrid, details[0].row, targetIndex);
  6630. };
  6631. var opMakeColumnsHeader = function(initialGrid, details, comparator, genWrappers) {
  6632. var columns2 = uniqueColumns(details);
  6633. var columnIndexes = map$1(columns2, function(detail2) {
  6634. return detail2.column;
  6635. });
  6636. var newGrid = replaceColumns(initialGrid, columnIndexes, true, comparator, genWrappers.replaceOrInit);
  6637. return bundle(newGrid, details[0].row, details[0].column);
  6638. };
  6639. var opMakeCellsHeader = function(initialGrid, details, comparator, genWrappers) {
  6640. var newGrid = replaceCells(initialGrid, details, comparator, genWrappers.replaceOrInit);
  6641. return bundle(newGrid, details[0].row, details[0].column);
  6642. };
  6643. var opUnmakeColumnsHeader = function(initialGrid, details, comparator, genWrappers) {
  6644. var columns2 = uniqueColumns(details);
  6645. var columnIndexes = map$1(columns2, function(detail2) {
  6646. return detail2.column;
  6647. });
  6648. var newGrid = replaceColumns(initialGrid, columnIndexes, false, comparator, genWrappers.replaceOrInit);
  6649. return bundle(newGrid, details[0].row, details[0].column);
  6650. };
  6651. var opUnmakeCellsHeader = function(initialGrid, details, comparator, genWrappers) {
  6652. var newGrid = replaceCells(initialGrid, details, comparator, genWrappers.replaceOrInit);
  6653. return bundle(newGrid, details[0].row, details[0].column);
  6654. };
  6655. var makeRowsSection = function(section2, applyScope) {
  6656. return function(initialGrid, details, comparator, genWrappers, tableSection) {
  6657. var rows2 = uniqueRows(details);
  6658. var rowIndexes = map$1(rows2, function(detail2) {
  6659. return detail2.row;
  6660. });
  6661. var newGrid = replaceRows(initialGrid, rowIndexes, section2, applyScope, comparator, genWrappers.replaceOrInit, tableSection);
  6662. return bundle(newGrid, details[0].row, details[0].column);
  6663. };
  6664. };
  6665. var opMakeRowsHeader = makeRowsSection("thead", true);
  6666. var opMakeRowsBody = makeRowsSection("tbody", false);
  6667. var opMakeRowsFooter = makeRowsSection("tfoot", false);
  6668. var opEraseColumns = function(grid2, extractDetail, _comparator, _genWrappers) {
  6669. var columns2 = uniqueColumns(extractDetail.details);
  6670. var newGrid = deleteColumnsAt(grid2, map$1(columns2, function(column) {
  6671. return column.column;
  6672. }));
  6673. var maxColIndex = newGrid.length > 0 ? newGrid[0].cells.length - 1 : 0;
  6674. return bundle(newGrid, columns2[0].row, Math.min(columns2[0].column, maxColIndex));
  6675. };
  6676. var opEraseRows = function(grid2, details, _comparator, _genWrappers) {
  6677. var rows2 = uniqueRows(details);
  6678. var newGrid = deleteRowsAt(grid2, rows2[0].row, rows2[rows2.length - 1].row);
  6679. var maxRowIndex = newGrid.length > 0 ? newGrid.length - 1 : 0;
  6680. return bundle(newGrid, Math.min(details[0].row, maxRowIndex), details[0].column);
  6681. };
  6682. var opMergeCells = function(grid2, mergable2, comparator, genWrappers) {
  6683. var cells2 = mergable2.cells;
  6684. merge(cells2);
  6685. var newGrid = merge$2(grid2, mergable2.bounds, comparator, genWrappers.merge(cells2));
  6686. return outcome(newGrid, Optional.from(cells2[0]));
  6687. };
  6688. var opUnmergeCells = function(grid2, unmergable2, comparator, genWrappers) {
  6689. var unmerge$1 = function(b, cell2) {
  6690. return unmerge(b, cell2, comparator, genWrappers.unmerge(cell2));
  6691. };
  6692. var newGrid = foldr(unmergable2, unmerge$1, grid2);
  6693. return outcome(newGrid, Optional.from(unmergable2[0]));
  6694. };
  6695. var opPasteCells = function(grid2, pasteDetails, comparator, _genWrappers) {
  6696. var gridify = function(table2, generators) {
  6697. var wh = Warehouse.fromTable(table2);
  6698. return toGrid(wh, generators, true);
  6699. };
  6700. var gridB = gridify(pasteDetails.clipboard, pasteDetails.generators);
  6701. var startAddress = address(pasteDetails.row, pasteDetails.column);
  6702. var mergedGrid = merge$1(startAddress, grid2, gridB, pasteDetails.generators, comparator);
  6703. return mergedGrid.fold(function() {
  6704. return outcome(grid2, Optional.some(pasteDetails.element));
  6705. }, function(newGrid) {
  6706. return bundle(newGrid, pasteDetails.row, pasteDetails.column);
  6707. });
  6708. };
  6709. var gridifyRows = function(rows2, generators, context) {
  6710. var pasteDetails = fromPastedRows(rows2, context.section);
  6711. var wh = Warehouse.generate(pasteDetails);
  6712. return toGrid(wh, generators, true);
  6713. };
  6714. var opPasteColsBefore = function(grid2, pasteDetails, comparator, _genWrappers) {
  6715. var rows2 = extractGridDetails(grid2).rows;
  6716. var index = pasteDetails.cells[0].column;
  6717. var context = rows2[pasteDetails.cells[0].row];
  6718. var gridB = gridifyRows(pasteDetails.clipboard, pasteDetails.generators, context);
  6719. var mergedGrid = insertCols(index, grid2, gridB, pasteDetails.generators, comparator);
  6720. return bundle(mergedGrid, pasteDetails.cells[0].row, pasteDetails.cells[0].column);
  6721. };
  6722. var opPasteColsAfter = function(grid2, pasteDetails, comparator, _genWrappers) {
  6723. var rows2 = extractGridDetails(grid2).rows;
  6724. var index = pasteDetails.cells[pasteDetails.cells.length - 1].column + pasteDetails.cells[pasteDetails.cells.length - 1].colspan;
  6725. var context = rows2[pasteDetails.cells[0].row];
  6726. var gridB = gridifyRows(pasteDetails.clipboard, pasteDetails.generators, context);
  6727. var mergedGrid = insertCols(index, grid2, gridB, pasteDetails.generators, comparator);
  6728. return bundle(mergedGrid, pasteDetails.cells[0].row, pasteDetails.cells[0].column);
  6729. };
  6730. var opPasteRowsBefore = function(grid2, pasteDetails, comparator, _genWrappers) {
  6731. var rows2 = extractGridDetails(grid2).rows;
  6732. var index = pasteDetails.cells[0].row;
  6733. var context = rows2[index];
  6734. var gridB = gridifyRows(pasteDetails.clipboard, pasteDetails.generators, context);
  6735. var mergedGrid = insertRows(index, grid2, gridB, pasteDetails.generators, comparator);
  6736. return bundle(mergedGrid, pasteDetails.cells[0].row, pasteDetails.cells[0].column);
  6737. };
  6738. var opPasteRowsAfter = function(grid2, pasteDetails, comparator, _genWrappers) {
  6739. var rows2 = extractGridDetails(grid2).rows;
  6740. var index = pasteDetails.cells[pasteDetails.cells.length - 1].row + pasteDetails.cells[pasteDetails.cells.length - 1].rowspan;
  6741. var context = rows2[pasteDetails.cells[0].row];
  6742. var gridB = gridifyRows(pasteDetails.clipboard, pasteDetails.generators, context);
  6743. var mergedGrid = insertRows(index, grid2, gridB, pasteDetails.generators, comparator);
  6744. return bundle(mergedGrid, pasteDetails.cells[0].row, pasteDetails.cells[0].column);
  6745. };
  6746. var opGetColumnsType = function(table2, target) {
  6747. var house = Warehouse.fromTable(table2);
  6748. var details = onCells(house, target);
  6749. return details.bind(function(selectedCells) {
  6750. var lastSelectedCell = selectedCells[selectedCells.length - 1];
  6751. var minColRange = selectedCells[0].column;
  6752. var maxColRange = lastSelectedCell.column + lastSelectedCell.colspan;
  6753. var selectedColumnCells = flatten$1(map$1(house.all, function(row2) {
  6754. return filter$2(row2.cells, function(cell2) {
  6755. return cell2.column >= minColRange && cell2.column < maxColRange;
  6756. });
  6757. }));
  6758. return findCommonCellType(selectedColumnCells);
  6759. }).getOr("");
  6760. };
  6761. var opGetCellsType = function(table2, target) {
  6762. var house = Warehouse.fromTable(table2);
  6763. var details = onCells(house, target);
  6764. return details.bind(findCommonCellType).getOr("");
  6765. };
  6766. var opGetRowsType = function(table2, target) {
  6767. var house = Warehouse.fromTable(table2);
  6768. var details = onCells(house, target);
  6769. return details.bind(function(selectedCells) {
  6770. var lastSelectedCell = selectedCells[selectedCells.length - 1];
  6771. var minRowRange = selectedCells[0].row;
  6772. var maxRowRange = lastSelectedCell.row + lastSelectedCell.rowspan;
  6773. var selectedRows = house.all.slice(minRowRange, maxRowRange);
  6774. return findCommonRowType(selectedRows);
  6775. }).getOr("");
  6776. };
  6777. var resize = function(table2, list, details, behaviours) {
  6778. return adjustWidthTo(table2, list, details, behaviours.sizing);
  6779. };
  6780. var adjustAndRedistributeWidths = function(table2, list, details, behaviours) {
  6781. return adjustAndRedistributeWidths$1(table2, list, details, behaviours.sizing, behaviours.resize);
  6782. };
  6783. var firstColumnIsLocked = function(_warehouse, details) {
  6784. return exists(details, function(detail2) {
  6785. return detail2.column === 0 && detail2.isLocked;
  6786. });
  6787. };
  6788. var lastColumnIsLocked = function(warehouse, details) {
  6789. return exists(details, function(detail2) {
  6790. return detail2.column + detail2.colspan >= warehouse.grid.columns && detail2.isLocked;
  6791. });
  6792. };
  6793. var getColumnsWidth = function(warehouse, details) {
  6794. var columns$12 = columns(warehouse);
  6795. var uniqueCols = uniqueColumns(details);
  6796. return foldl(uniqueCols, function(acc, detail2) {
  6797. var column = columns$12[detail2.column];
  6798. var colWidth = column.map(getOuter$2).getOr(0);
  6799. return acc + colWidth;
  6800. }, 0);
  6801. };
  6802. var insertColumnsExtractor = function(before2) {
  6803. return function(warehouse, target) {
  6804. return onCells(warehouse, target).filter(function(details) {
  6805. var checkLocked = before2 ? firstColumnIsLocked : lastColumnIsLocked;
  6806. return !checkLocked(warehouse, details);
  6807. }).map(function(details) {
  6808. return {
  6809. details,
  6810. pixelDelta: getColumnsWidth(warehouse, details)
  6811. };
  6812. });
  6813. };
  6814. };
  6815. var eraseColumnsExtractor = function(warehouse, target) {
  6816. return onUnlockedCells(warehouse, target).map(function(details) {
  6817. return {
  6818. details,
  6819. pixelDelta: -getColumnsWidth(warehouse, details)
  6820. };
  6821. });
  6822. };
  6823. var pasteColumnsExtractor = function(before2) {
  6824. return function(warehouse, target) {
  6825. return onPasteByEditor(warehouse, target).filter(function(details) {
  6826. var checkLocked = before2 ? firstColumnIsLocked : lastColumnIsLocked;
  6827. return !checkLocked(warehouse, details.cells);
  6828. });
  6829. };
  6830. };
  6831. var headerCellGenerator = Generators.transform("th");
  6832. var bodyCellGenerator = Generators.transform("td");
  6833. var insertRowsBefore = run(opInsertRowsBefore, onCells, noop, noop, Generators.modification);
  6834. var insertRowsAfter = run(opInsertRowsAfter, onCells, noop, noop, Generators.modification);
  6835. var insertColumnsBefore = run(opInsertColumnsBefore, insertColumnsExtractor(true), adjustAndRedistributeWidths, noop, Generators.modification);
  6836. var insertColumnsAfter = run(opInsertColumnsAfter, insertColumnsExtractor(false), adjustAndRedistributeWidths, noop, Generators.modification);
  6837. var eraseColumns = run(opEraseColumns, eraseColumnsExtractor, adjustAndRedistributeWidths, prune, Generators.modification);
  6838. var eraseRows = run(opEraseRows, onCells, noop, prune, Generators.modification);
  6839. var makeColumnsHeader = run(opMakeColumnsHeader, onUnlockedCells, noop, noop, headerCellGenerator);
  6840. var unmakeColumnsHeader = run(opUnmakeColumnsHeader, onUnlockedCells, noop, noop, bodyCellGenerator);
  6841. var makeRowsHeader = run(opMakeRowsHeader, onUnlockedCells, noop, noop, headerCellGenerator);
  6842. var makeRowsBody = run(opMakeRowsBody, onUnlockedCells, noop, noop, bodyCellGenerator);
  6843. var makeRowsFooter = run(opMakeRowsFooter, onUnlockedCells, noop, noop, bodyCellGenerator);
  6844. var makeCellsHeader = run(opMakeCellsHeader, onUnlockedCells, noop, noop, headerCellGenerator);
  6845. var unmakeCellsHeader = run(opUnmakeCellsHeader, onUnlockedCells, noop, noop, bodyCellGenerator);
  6846. var mergeCells = run(opMergeCells, onUnlockedMergable, resize, noop, Generators.merging);
  6847. var unmergeCells = run(opUnmergeCells, onUnlockedUnmergable, resize, noop, Generators.merging);
  6848. var pasteCells = run(opPasteCells, onPaste, resize, noop, Generators.modification);
  6849. var pasteColsBefore = run(opPasteColsBefore, pasteColumnsExtractor(true), noop, noop, Generators.modification);
  6850. var pasteColsAfter = run(opPasteColsAfter, pasteColumnsExtractor(false), noop, noop, Generators.modification);
  6851. var pasteRowsBefore = run(opPasteRowsBefore, onPasteByEditor, noop, noop, Generators.modification);
  6852. var pasteRowsAfter = run(opPasteRowsAfter, onPasteByEditor, noop, noop, Generators.modification);
  6853. var getColumnsType = opGetColumnsType;
  6854. var getCellsType = opGetCellsType;
  6855. var getRowsType = opGetRowsType;
  6856. var TableActions = function(editor, cellSelection, lazyWire) {
  6857. var isTableBody = function(editor2) {
  6858. return name(getBody(editor2)) === "table";
  6859. };
  6860. var lastRowGuard = function(table2) {
  6861. return isTableBody(editor) === false || getGridSize(table2).rows > 1;
  6862. };
  6863. var lastColumnGuard = function(table2) {
  6864. return isTableBody(editor) === false || getGridSize(table2).columns > 1;
  6865. };
  6866. var cloneFormats2 = getCloneElements(editor);
  6867. var colMutationOp = isResizeTableColumnResizing(editor) ? noop : halve;
  6868. var getTableSectionType2 = function(table2) {
  6869. switch (getTableHeaderType(editor)) {
  6870. case "section":
  6871. return TableSection.section();
  6872. case "sectionCells":
  6873. return TableSection.sectionCells();
  6874. case "cells":
  6875. return TableSection.cells();
  6876. default:
  6877. return TableSection.getTableSectionType(table2, "section");
  6878. }
  6879. };
  6880. var setSelectionFromAction = function(table2, result) {
  6881. return result.cursor.fold(function() {
  6882. var cells2 = cells$1(table2);
  6883. return head(cells2).filter(inBody).map(function(firstCell) {
  6884. cellSelection.clear(table2);
  6885. var rng = editor.dom.createRng();
  6886. rng.selectNode(firstCell.dom);
  6887. editor.selection.setRng(rng);
  6888. set$2(firstCell, "data-mce-selected", "1");
  6889. return rng;
  6890. });
  6891. }, function(cell2) {
  6892. var des = freefallRtl(cell2);
  6893. var rng = editor.dom.createRng();
  6894. rng.setStart(des.element.dom, des.offset);
  6895. rng.setEnd(des.element.dom, des.offset);
  6896. editor.selection.setRng(rng);
  6897. cellSelection.clear(table2);
  6898. return Optional.some(rng);
  6899. });
  6900. };
  6901. var execute = function(operation, guard, mutate2, lazyWire2, effect) {
  6902. return function(table2, target, noEvents) {
  6903. if (noEvents === void 0) {
  6904. noEvents = false;
  6905. }
  6906. removeDataStyle(table2);
  6907. var wire = lazyWire2();
  6908. var doc = SugarElement.fromDom(editor.getDoc());
  6909. var generators = cellOperations(mutate2, doc, cloneFormats2);
  6910. var behaviours = {
  6911. sizing: get$4(editor, table2),
  6912. resize: isResizeTableColumnResizing(editor) ? resizeTable() : preserveTable(),
  6913. section: getTableSectionType2(table2)
  6914. };
  6915. return guard(table2) ? operation(wire, table2, target, generators, behaviours).bind(function(result) {
  6916. each$2(result.newRows, function(row2) {
  6917. fireNewRow(editor, row2.dom);
  6918. });
  6919. each$2(result.newCells, function(cell2) {
  6920. fireNewCell(editor, cell2.dom);
  6921. });
  6922. var range2 = setSelectionFromAction(table2, result);
  6923. if (inBody(table2)) {
  6924. removeDataStyle(table2);
  6925. if (!noEvents) {
  6926. fireTableModified(editor, table2.dom, effect);
  6927. }
  6928. }
  6929. return range2.map(function(rng) {
  6930. return {
  6931. rng,
  6932. effect
  6933. };
  6934. });
  6935. }) : Optional.none();
  6936. };
  6937. };
  6938. var deleteRow = execute(eraseRows, lastRowGuard, noop, lazyWire, structureModified);
  6939. var deleteColumn = execute(eraseColumns, lastColumnGuard, noop, lazyWire, structureModified);
  6940. var insertRowsBefore$1 = execute(insertRowsBefore, always, noop, lazyWire, structureModified);
  6941. var insertRowsAfter$1 = execute(insertRowsAfter, always, noop, lazyWire, structureModified);
  6942. var insertColumnsBefore$1 = execute(insertColumnsBefore, always, colMutationOp, lazyWire, structureModified);
  6943. var insertColumnsAfter$1 = execute(insertColumnsAfter, always, colMutationOp, lazyWire, structureModified);
  6944. var mergeCells$1 = execute(mergeCells, always, noop, lazyWire, structureModified);
  6945. var unmergeCells$1 = execute(unmergeCells, always, noop, lazyWire, structureModified);
  6946. var pasteColsBefore$1 = execute(pasteColsBefore, always, noop, lazyWire, structureModified);
  6947. var pasteColsAfter$1 = execute(pasteColsAfter, always, noop, lazyWire, structureModified);
  6948. var pasteRowsBefore$1 = execute(pasteRowsBefore, always, noop, lazyWire, structureModified);
  6949. var pasteRowsAfter$1 = execute(pasteRowsAfter, always, noop, lazyWire, structureModified);
  6950. var pasteCells$1 = execute(pasteCells, always, noop, lazyWire, styleAndStructureModified);
  6951. var makeCellsHeader$1 = execute(makeCellsHeader, always, noop, lazyWire, structureModified);
  6952. var unmakeCellsHeader$1 = execute(unmakeCellsHeader, always, noop, lazyWire, structureModified);
  6953. var makeColumnsHeader$1 = execute(makeColumnsHeader, always, noop, lazyWire, structureModified);
  6954. var unmakeColumnsHeader$1 = execute(unmakeColumnsHeader, always, noop, lazyWire, structureModified);
  6955. var makeRowsHeader$1 = execute(makeRowsHeader, always, noop, lazyWire, structureModified);
  6956. var makeRowsBody$1 = execute(makeRowsBody, always, noop, lazyWire, structureModified);
  6957. var makeRowsFooter$1 = execute(makeRowsFooter, always, noop, lazyWire, structureModified);
  6958. var getTableCellType = getCellsType;
  6959. var getTableColType = getColumnsType;
  6960. var getTableRowType = getRowsType;
  6961. return {
  6962. deleteRow,
  6963. deleteColumn,
  6964. insertRowsBefore: insertRowsBefore$1,
  6965. insertRowsAfter: insertRowsAfter$1,
  6966. insertColumnsBefore: insertColumnsBefore$1,
  6967. insertColumnsAfter: insertColumnsAfter$1,
  6968. mergeCells: mergeCells$1,
  6969. unmergeCells: unmergeCells$1,
  6970. pasteColsBefore: pasteColsBefore$1,
  6971. pasteColsAfter: pasteColsAfter$1,
  6972. pasteRowsBefore: pasteRowsBefore$1,
  6973. pasteRowsAfter: pasteRowsAfter$1,
  6974. pasteCells: pasteCells$1,
  6975. makeCellsHeader: makeCellsHeader$1,
  6976. unmakeCellsHeader: unmakeCellsHeader$1,
  6977. makeColumnsHeader: makeColumnsHeader$1,
  6978. unmakeColumnsHeader: unmakeColumnsHeader$1,
  6979. makeRowsHeader: makeRowsHeader$1,
  6980. makeRowsBody: makeRowsBody$1,
  6981. makeRowsFooter: makeRowsFooter$1,
  6982. getTableRowType,
  6983. getTableCellType,
  6984. getTableColType
  6985. };
  6986. };
  6987. var DefaultRenderOptions = {
  6988. styles: {
  6989. "border-collapse": "collapse",
  6990. "width": "100%"
  6991. },
  6992. attributes: { border: "1" },
  6993. colGroups: false
  6994. };
  6995. var tableHeaderCell = function() {
  6996. return SugarElement.fromTag("th");
  6997. };
  6998. var tableCell = function() {
  6999. return SugarElement.fromTag("td");
  7000. };
  7001. var tableColumn = function() {
  7002. return SugarElement.fromTag("col");
  7003. };
  7004. var createRow = function(columns2, rowHeaders, columnHeaders, rowIndex) {
  7005. var tr = SugarElement.fromTag("tr");
  7006. for (var j = 0; j < columns2; j++) {
  7007. var td = rowIndex < rowHeaders || j < columnHeaders ? tableHeaderCell() : tableCell();
  7008. if (j < columnHeaders) {
  7009. set$2(td, "scope", "row");
  7010. }
  7011. if (rowIndex < rowHeaders) {
  7012. set$2(td, "scope", "col");
  7013. }
  7014. append$1(td, SugarElement.fromTag("br"));
  7015. append$1(tr, td);
  7016. }
  7017. return tr;
  7018. };
  7019. var createGroupRow = function(columns2) {
  7020. var columnGroup = SugarElement.fromTag("colgroup");
  7021. range$1(columns2, function() {
  7022. return append$1(columnGroup, tableColumn());
  7023. });
  7024. return columnGroup;
  7025. };
  7026. var createRows = function(rows2, columns2, rowHeaders, columnHeaders) {
  7027. return range$1(rows2, function(r2) {
  7028. return createRow(columns2, rowHeaders, columnHeaders, r2);
  7029. });
  7030. };
  7031. var render = function(rows2, columns2, rowHeaders, columnHeaders, headerType, renderOpts) {
  7032. if (renderOpts === void 0) {
  7033. renderOpts = DefaultRenderOptions;
  7034. }
  7035. var table2 = SugarElement.fromTag("table");
  7036. var rowHeadersGoInThead = headerType !== "cells";
  7037. setAll(table2, renderOpts.styles);
  7038. setAll$1(table2, renderOpts.attributes);
  7039. if (renderOpts.colGroups) {
  7040. append$1(table2, createGroupRow(columns2));
  7041. }
  7042. var actualRowHeaders = Math.min(rows2, rowHeaders);
  7043. if (rowHeadersGoInThead && rowHeaders > 0) {
  7044. var thead = SugarElement.fromTag("thead");
  7045. append$1(table2, thead);
  7046. var theadRowHeaders = headerType === "sectionCells" ? actualRowHeaders : 0;
  7047. var theadRows = createRows(rowHeaders, columns2, theadRowHeaders, columnHeaders);
  7048. append(thead, theadRows);
  7049. }
  7050. var tbody = SugarElement.fromTag("tbody");
  7051. append$1(table2, tbody);
  7052. var numRows = rowHeadersGoInThead ? rows2 - actualRowHeaders : rows2;
  7053. var numRowHeaders = rowHeadersGoInThead ? 0 : rowHeaders;
  7054. var tbodyRows = createRows(numRows, columns2, numRowHeaders, columnHeaders);
  7055. append(tbody, tbodyRows);
  7056. return table2;
  7057. };
  7058. var get$2 = function(element) {
  7059. return element.dom.innerHTML;
  7060. };
  7061. var getOuter = function(element) {
  7062. var container = SugarElement.fromTag("div");
  7063. var clone2 = SugarElement.fromDom(element.dom.cloneNode(true));
  7064. append$1(container, clone2);
  7065. return get$2(container);
  7066. };
  7067. var placeCaretInCell = function(editor, cell2) {
  7068. editor.selection.select(cell2.dom, true);
  7069. editor.selection.collapse(true);
  7070. };
  7071. var selectFirstCellInTable = function(editor, tableElm) {
  7072. descendant(tableElm, "td,th").each(curry(placeCaretInCell, editor));
  7073. };
  7074. var fireEvents = function(editor, table2) {
  7075. each$2(descendants(table2, "tr"), function(row2) {
  7076. fireNewRow(editor, row2.dom);
  7077. each$2(descendants(row2, "th,td"), function(cell2) {
  7078. fireNewCell(editor, cell2.dom);
  7079. });
  7080. });
  7081. };
  7082. var isPercentage = function(width2) {
  7083. return isString(width2) && width2.indexOf("%") !== -1;
  7084. };
  7085. var insert = function(editor, columns2, rows2, colHeaders, rowHeaders) {
  7086. var defaultStyles2 = getDefaultStyles(editor);
  7087. var options = {
  7088. styles: defaultStyles2,
  7089. attributes: getDefaultAttributes(editor),
  7090. colGroups: useColumnGroup(editor)
  7091. };
  7092. editor.undoManager.ignore(function() {
  7093. var table2 = render(rows2, columns2, rowHeaders, colHeaders, getTableHeaderType(editor), options);
  7094. set$2(table2, "data-mce-id", "__mce");
  7095. var html = getOuter(table2);
  7096. editor.insertContent(html);
  7097. editor.addVisual();
  7098. });
  7099. return descendant(getBody(editor), 'table[data-mce-id="__mce"]').map(function(table2) {
  7100. if (isPixelsForced(editor)) {
  7101. enforcePixels(table2);
  7102. } else if (isResponsiveForced(editor)) {
  7103. enforceNone(table2);
  7104. } else if (isPercentagesForced(editor) || isPercentage(defaultStyles2.width)) {
  7105. enforcePercentage(table2);
  7106. }
  7107. removeDataStyle(table2);
  7108. remove$7(table2, "data-mce-id");
  7109. fireEvents(editor, table2);
  7110. selectFirstCellInTable(editor, table2);
  7111. return table2.dom;
  7112. }).getOr(null);
  7113. };
  7114. var insertTableWithDataValidation = function(editor, rows2, columns2, options, errorMsg) {
  7115. if (options === void 0) {
  7116. options = {};
  7117. }
  7118. var checkInput = function(val) {
  7119. return isNumber(val) && val > 0;
  7120. };
  7121. if (checkInput(rows2) && checkInput(columns2)) {
  7122. var headerRows = options.headerRows || 0;
  7123. var headerColumns = options.headerColumns || 0;
  7124. return insert(editor, columns2, rows2, headerColumns, headerRows);
  7125. } else {
  7126. console.error(errorMsg);
  7127. return null;
  7128. }
  7129. };
  7130. var getClipboardElements = function(getClipboard) {
  7131. return function() {
  7132. return getClipboard().fold(function() {
  7133. return [];
  7134. }, function(elems) {
  7135. return map$1(elems, function(e) {
  7136. return e.dom;
  7137. });
  7138. });
  7139. };
  7140. };
  7141. var setClipboardElements = function(setClipboard) {
  7142. return function(elems) {
  7143. var elmsOpt = elems.length > 0 ? Optional.some(fromDom(elems)) : Optional.none();
  7144. setClipboard(elmsOpt);
  7145. };
  7146. };
  7147. var insertTable = function(editor) {
  7148. return function(columns2, rows2, options) {
  7149. if (options === void 0) {
  7150. options = {};
  7151. }
  7152. var table2 = insertTableWithDataValidation(editor, rows2, columns2, options, "Invalid values for insertTable - rows and columns values are required to insert a table.");
  7153. editor.undoManager.add();
  7154. return table2;
  7155. };
  7156. };
  7157. var getApi = function(editor, clipboard, resizeHandler, selectionTargets) {
  7158. return {
  7159. insertTable: insertTable(editor),
  7160. setClipboardRows: setClipboardElements(clipboard.setRows),
  7161. getClipboardRows: getClipboardElements(clipboard.getRows),
  7162. setClipboardCols: setClipboardElements(clipboard.setColumns),
  7163. getClipboardCols: getClipboardElements(clipboard.getColumns),
  7164. resizeHandler,
  7165. selectionTargets
  7166. };
  7167. };
  7168. var constrainSpan = function(element, property, value2) {
  7169. var currentColspan = getAttrValue(element, property, 1);
  7170. if (value2 === 1 || currentColspan <= 1) {
  7171. remove$7(element, property);
  7172. } else {
  7173. set$2(element, property, Math.min(value2, currentColspan));
  7174. }
  7175. };
  7176. var generateColGroup = function(house, minColRange, maxColRange) {
  7177. if (Warehouse.hasColumns(house)) {
  7178. var colsToCopy = filter$2(Warehouse.justColumns(house), function(col2) {
  7179. return col2.column >= minColRange && col2.column < maxColRange;
  7180. });
  7181. var copiedCols = map$1(colsToCopy, function(c) {
  7182. var clonedCol = deep(c.element);
  7183. constrainSpan(clonedCol, "span", maxColRange - minColRange);
  7184. return clonedCol;
  7185. });
  7186. var fakeColgroup = SugarElement.fromTag("colgroup");
  7187. append(fakeColgroup, copiedCols);
  7188. return [fakeColgroup];
  7189. } else {
  7190. return [];
  7191. }
  7192. };
  7193. var generateRows = function(house, minColRange, maxColRange) {
  7194. return map$1(house.all, function(row2) {
  7195. var cellsToCopy = filter$2(row2.cells, function(cell2) {
  7196. return cell2.column >= minColRange && cell2.column < maxColRange;
  7197. });
  7198. var copiedCells = map$1(cellsToCopy, function(cell2) {
  7199. var clonedCell = deep(cell2.element);
  7200. constrainSpan(clonedCell, "colspan", maxColRange - minColRange);
  7201. return clonedCell;
  7202. });
  7203. var fakeTR = SugarElement.fromTag("tr");
  7204. append(fakeTR, copiedCells);
  7205. return fakeTR;
  7206. });
  7207. };
  7208. var copyCols = function(table2, target) {
  7209. var house = Warehouse.fromTable(table2);
  7210. var details = onUnlockedCells(house, target);
  7211. return details.map(function(selectedCells) {
  7212. var lastSelectedCell = selectedCells[selectedCells.length - 1];
  7213. var minColRange = selectedCells[0].column;
  7214. var maxColRange = lastSelectedCell.column + lastSelectedCell.colspan;
  7215. var fakeColGroups = generateColGroup(house, minColRange, maxColRange);
  7216. var fakeRows = generateRows(house, minColRange, maxColRange);
  7217. return __spreadArray(__spreadArray([], fakeColGroups, true), fakeRows, true);
  7218. });
  7219. };
  7220. var copyRows = function(table2, target, generators) {
  7221. var warehouse = Warehouse.fromTable(table2);
  7222. var details = onCells(warehouse, target);
  7223. return details.bind(function(selectedCells) {
  7224. var grid2 = toGrid(warehouse, generators, false);
  7225. var rows2 = extractGridDetails(grid2).rows;
  7226. var slicedGrid = rows2.slice(selectedCells[0].row, selectedCells[selectedCells.length - 1].row + selectedCells[selectedCells.length - 1].rowspan);
  7227. var filteredGrid = bind$2(slicedGrid, function(row2) {
  7228. var newCells = filter$2(row2.cells, function(cell2) {
  7229. return !cell2.isLocked;
  7230. });
  7231. return newCells.length > 0 ? [__assign(__assign({}, row2), { cells: newCells })] : [];
  7232. });
  7233. var slicedDetails = toDetailList(filteredGrid);
  7234. return someIf(slicedDetails.length > 0, slicedDetails);
  7235. }).map(function(slicedDetails) {
  7236. return copy(slicedDetails);
  7237. });
  7238. };
  7239. var global$2 = tinymce.util.Tools.resolve("tinymce.util.Tools");
  7240. var getTDTHOverallStyle = function(dom, elm, name2) {
  7241. var cells2 = dom.select("td,th", elm);
  7242. var firstChildStyle;
  7243. var checkChildren = function(firstChildStyle2, elms) {
  7244. for (var i = 0; i < elms.length; i++) {
  7245. var currentStyle = dom.getStyle(elms[i], name2);
  7246. if (typeof firstChildStyle2 === "undefined") {
  7247. firstChildStyle2 = currentStyle;
  7248. }
  7249. if (firstChildStyle2 !== currentStyle) {
  7250. return "";
  7251. }
  7252. }
  7253. return firstChildStyle2;
  7254. };
  7255. return checkChildren(firstChildStyle, cells2);
  7256. };
  7257. var applyAlign = function(editor, elm, name2) {
  7258. if (name2) {
  7259. editor.formatter.apply("align" + name2, {}, elm);
  7260. }
  7261. };
  7262. var applyVAlign = function(editor, elm, name2) {
  7263. if (name2) {
  7264. editor.formatter.apply("valign" + name2, {}, elm);
  7265. }
  7266. };
  7267. var unApplyAlign = function(editor, elm) {
  7268. global$2.each("left center right".split(" "), function(name2) {
  7269. editor.formatter.remove("align" + name2, {}, elm);
  7270. });
  7271. };
  7272. var unApplyVAlign = function(editor, elm) {
  7273. global$2.each("top middle bottom".split(" "), function(name2) {
  7274. editor.formatter.remove("valign" + name2, {}, elm);
  7275. });
  7276. };
  7277. var verticalAlignValues = [
  7278. {
  7279. text: "None",
  7280. value: ""
  7281. },
  7282. {
  7283. text: "Top",
  7284. value: "top"
  7285. },
  7286. {
  7287. text: "Middle",
  7288. value: "middle"
  7289. },
  7290. {
  7291. text: "Bottom",
  7292. value: "bottom"
  7293. }
  7294. ];
  7295. var hexColour = function(value2) {
  7296. return { value: value2 };
  7297. };
  7298. var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  7299. var longformRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
  7300. var isHexString = function(hex) {
  7301. return shorthandRegex.test(hex) || longformRegex.test(hex);
  7302. };
  7303. var normalizeHex = function(hex) {
  7304. return removeLeading(hex, "#").toUpperCase();
  7305. };
  7306. var fromString$1 = function(hex) {
  7307. return isHexString(hex) ? Optional.some({ value: normalizeHex(hex) }) : Optional.none();
  7308. };
  7309. var toHex = function(component) {
  7310. var hex = component.toString(16);
  7311. return (hex.length === 1 ? "0" + hex : hex).toUpperCase();
  7312. };
  7313. var fromRgba = function(rgbaColour2) {
  7314. var value2 = toHex(rgbaColour2.red) + toHex(rgbaColour2.green) + toHex(rgbaColour2.blue);
  7315. return hexColour(value2);
  7316. };
  7317. var rgbRegex = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)/;
  7318. var rgbaRegex = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d?(?:\.\d+)?)\)/;
  7319. var rgbaColour = function(red, green, blue, alpha) {
  7320. return {
  7321. red,
  7322. green,
  7323. blue,
  7324. alpha
  7325. };
  7326. };
  7327. var fromStringValues = function(red, green, blue, alpha) {
  7328. var r2 = parseInt(red, 10);
  7329. var g = parseInt(green, 10);
  7330. var b = parseInt(blue, 10);
  7331. var a = parseFloat(alpha);
  7332. return rgbaColour(r2, g, b, a);
  7333. };
  7334. var fromString = function(rgbaString) {
  7335. if (rgbaString === "transparent") {
  7336. return Optional.some(rgbaColour(0, 0, 0, 0));
  7337. }
  7338. var rgbMatch = rgbRegex.exec(rgbaString);
  7339. if (rgbMatch !== null) {
  7340. return Optional.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], "1"));
  7341. }
  7342. var rgbaMatch = rgbaRegex.exec(rgbaString);
  7343. if (rgbaMatch !== null) {
  7344. return Optional.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
  7345. }
  7346. return Optional.none();
  7347. };
  7348. var anyToHex = function(color) {
  7349. return fromString$1(color).orThunk(function() {
  7350. return fromString(color).map(fromRgba);
  7351. }).getOrThunk(function() {
  7352. var canvas = document.createElement("canvas");
  7353. canvas.height = 1;
  7354. canvas.width = 1;
  7355. var canvasContext = canvas.getContext("2d");
  7356. canvasContext.clearRect(0, 0, canvas.width, canvas.height);
  7357. canvasContext.fillStyle = "#FFFFFF";
  7358. canvasContext.fillStyle = color;
  7359. canvasContext.fillRect(0, 0, 1, 1);
  7360. var rgba = canvasContext.getImageData(0, 0, 1, 1).data;
  7361. var r2 = rgba[0];
  7362. var g = rgba[1];
  7363. var b = rgba[2];
  7364. var a = rgba[3];
  7365. return fromRgba(rgbaColour(r2, g, b, a));
  7366. });
  7367. };
  7368. var Cell = function(initial) {
  7369. var value2 = initial;
  7370. var get2 = function() {
  7371. return value2;
  7372. };
  7373. var set2 = function(v) {
  7374. value2 = v;
  7375. };
  7376. return {
  7377. get: get2,
  7378. set: set2
  7379. };
  7380. };
  7381. var singleton = function(doRevoke) {
  7382. var subject = Cell(Optional.none());
  7383. var revoke = function() {
  7384. return subject.get().each(doRevoke);
  7385. };
  7386. var clear2 = function() {
  7387. revoke();
  7388. subject.set(Optional.none());
  7389. };
  7390. var isSet = function() {
  7391. return subject.get().isSome();
  7392. };
  7393. var get2 = function() {
  7394. return subject.get();
  7395. };
  7396. var set2 = function(s) {
  7397. revoke();
  7398. subject.set(Optional.some(s));
  7399. };
  7400. return {
  7401. clear: clear2,
  7402. isSet,
  7403. get: get2,
  7404. set: set2
  7405. };
  7406. };
  7407. var unbindable = function() {
  7408. return singleton(function(s) {
  7409. return s.unbind();
  7410. });
  7411. };
  7412. var value = function() {
  7413. var subject = singleton(noop);
  7414. var on2 = function(f) {
  7415. return subject.get().each(f);
  7416. };
  7417. return __assign(__assign({}, subject), { on: on2 });
  7418. };
  7419. var onSetupToggle = function(editor, selections, formatName, formatValue) {
  7420. return function(api2) {
  7421. var boundCallback = unbindable();
  7422. var isNone = isEmpty$1(formatValue);
  7423. var init = function() {
  7424. var selectedCells = getCellsFromSelection(selections);
  7425. var checkNode = function(cell2) {
  7426. return editor.formatter.match(formatName, { value: formatValue }, cell2.dom, isNone);
  7427. };
  7428. if (isNone) {
  7429. api2.setActive(!exists(selectedCells, checkNode));
  7430. boundCallback.set(editor.formatter.formatChanged(formatName, function(match) {
  7431. return api2.setActive(!match);
  7432. }, true));
  7433. } else {
  7434. api2.setActive(forall(selectedCells, checkNode));
  7435. boundCallback.set(editor.formatter.formatChanged(formatName, api2.setActive, false, { value: formatValue }));
  7436. }
  7437. };
  7438. editor.initialized ? init() : editor.on("init", init);
  7439. return boundCallback.clear;
  7440. };
  7441. };
  7442. var isListGroup = function(item) {
  7443. return hasNonNullableKey(item, "menu");
  7444. };
  7445. var buildListItems = function(items) {
  7446. return map$1(items, function(item) {
  7447. var text = item.text || item.title;
  7448. if (isListGroup(item)) {
  7449. return {
  7450. text,
  7451. items: buildListItems(item.menu)
  7452. };
  7453. } else {
  7454. return {
  7455. text,
  7456. value: item.value
  7457. };
  7458. }
  7459. });
  7460. };
  7461. var buildMenuItems = function(editor, selections, items, format, onAction) {
  7462. return map$1(items, function(item) {
  7463. var text = item.text || item.title;
  7464. if (isListGroup(item)) {
  7465. return {
  7466. type: "nestedmenuitem",
  7467. text,
  7468. getSubmenuItems: function() {
  7469. return buildMenuItems(editor, selections, item.menu, format, onAction);
  7470. }
  7471. };
  7472. } else {
  7473. return {
  7474. text,
  7475. type: "togglemenuitem",
  7476. onAction: function() {
  7477. return onAction(item.value);
  7478. },
  7479. onSetup: onSetupToggle(editor, selections, format, item.value)
  7480. };
  7481. }
  7482. });
  7483. };
  7484. var applyTableCellStyle = function(editor, style) {
  7485. return function(value2) {
  7486. var _a;
  7487. editor.execCommand("mceTableApplyCellStyle", false, (_a = {}, _a[style] = value2, _a));
  7488. };
  7489. };
  7490. var filterNoneItem = function(list) {
  7491. return bind$2(list, function(item) {
  7492. if (isListGroup(item)) {
  7493. return [__assign(__assign({}, item), { menu: filterNoneItem(item.menu) })];
  7494. } else {
  7495. return isNotEmpty(item.value) ? [item] : [];
  7496. }
  7497. });
  7498. };
  7499. var generateMenuItemsCallback = function(editor, selections, items, format, onAction) {
  7500. return function(callback) {
  7501. return callback(buildMenuItems(editor, selections, items, format, onAction));
  7502. };
  7503. };
  7504. var buildColorMenu = function(editor, colorList, style) {
  7505. var colorMap = map$1(colorList, function(entry) {
  7506. return {
  7507. text: entry.title,
  7508. value: "#" + anyToHex(entry.value).value,
  7509. type: "choiceitem"
  7510. };
  7511. });
  7512. return [{
  7513. type: "fancymenuitem",
  7514. fancytype: "colorswatch",
  7515. initData: {
  7516. colors: colorMap.length > 0 ? colorMap : void 0,
  7517. allowCustomColors: false
  7518. },
  7519. onAction: function(data) {
  7520. var _a;
  7521. var value2 = data.value === "remove" ? "" : data.value;
  7522. editor.execCommand("mceTableApplyCellStyle", false, (_a = {}, _a[style] = value2, _a));
  7523. }
  7524. }];
  7525. };
  7526. var changeRowHeader = function(editor) {
  7527. return function() {
  7528. var currentType = editor.queryCommandValue("mceTableRowType");
  7529. var newType = currentType === "header" ? "body" : "header";
  7530. editor.execCommand("mceTableRowType", false, { type: newType });
  7531. };
  7532. };
  7533. var changeColumnHeader = function(editor) {
  7534. return function() {
  7535. var currentType = editor.queryCommandValue("mceTableColType");
  7536. var newType = currentType === "th" ? "td" : "th";
  7537. editor.execCommand("mceTableColType", false, { type: newType });
  7538. };
  7539. };
  7540. var getClassList$1 = function(editor) {
  7541. var classes = buildListItems(getCellClassList(editor));
  7542. if (classes.length > 0) {
  7543. return Optional.some({
  7544. name: "class",
  7545. type: "listbox",
  7546. label: "Class",
  7547. items: classes
  7548. });
  7549. }
  7550. return Optional.none();
  7551. };
  7552. var children = [
  7553. {
  7554. name: "width",
  7555. type: "input",
  7556. label: "Width"
  7557. },
  7558. {
  7559. name: "height",
  7560. type: "input",
  7561. label: "Height"
  7562. },
  7563. {
  7564. name: "celltype",
  7565. type: "listbox",
  7566. label: "Cell type",
  7567. items: [
  7568. {
  7569. text: "Cell",
  7570. value: "td"
  7571. },
  7572. {
  7573. text: "Header cell",
  7574. value: "th"
  7575. }
  7576. ]
  7577. },
  7578. {
  7579. name: "scope",
  7580. type: "listbox",
  7581. label: "Scope",
  7582. items: [
  7583. {
  7584. text: "None",
  7585. value: ""
  7586. },
  7587. {
  7588. text: "Row",
  7589. value: "row"
  7590. },
  7591. {
  7592. text: "Column",
  7593. value: "col"
  7594. },
  7595. {
  7596. text: "Row group",
  7597. value: "rowgroup"
  7598. },
  7599. {
  7600. text: "Column group",
  7601. value: "colgroup"
  7602. }
  7603. ]
  7604. },
  7605. {
  7606. name: "halign",
  7607. type: "listbox",
  7608. label: "Horizontal align",
  7609. items: [
  7610. {
  7611. text: "None",
  7612. value: ""
  7613. },
  7614. {
  7615. text: "Left",
  7616. value: "left"
  7617. },
  7618. {
  7619. text: "Center",
  7620. value: "center"
  7621. },
  7622. {
  7623. text: "Right",
  7624. value: "right"
  7625. }
  7626. ]
  7627. },
  7628. {
  7629. name: "valign",
  7630. type: "listbox",
  7631. label: "Vertical align",
  7632. items: verticalAlignValues
  7633. }
  7634. ];
  7635. var getItems$2 = function(editor) {
  7636. return children.concat(getClassList$1(editor).toArray());
  7637. };
  7638. var getAdvancedTab = function(editor, dialogName) {
  7639. var emptyBorderStyle = [{
  7640. text: "Select...",
  7641. value: ""
  7642. }];
  7643. var advTabItems = [
  7644. {
  7645. name: "borderstyle",
  7646. type: "listbox",
  7647. label: "Border style",
  7648. items: emptyBorderStyle.concat(buildListItems(getTableBorderStyles(editor)))
  7649. },
  7650. {
  7651. name: "bordercolor",
  7652. type: "colorinput",
  7653. label: "Border color"
  7654. },
  7655. {
  7656. name: "backgroundcolor",
  7657. type: "colorinput",
  7658. label: "Background color"
  7659. }
  7660. ];
  7661. var borderWidth = {
  7662. name: "borderwidth",
  7663. type: "input",
  7664. label: "Border width"
  7665. };
  7666. var items = dialogName === "cell" ? [borderWidth].concat(advTabItems) : advTabItems;
  7667. return {
  7668. title: "Advanced",
  7669. name: "advanced",
  7670. items
  7671. };
  7672. };
  7673. var modifiers = function(testTruthy) {
  7674. return function(editor, node) {
  7675. var dom = editor.dom;
  7676. var setAttrib = function(attr, value2) {
  7677. if (!testTruthy || value2) {
  7678. dom.setAttrib(node, attr, value2);
  7679. }
  7680. };
  7681. var setStyle = function(prop, value2) {
  7682. if (!testTruthy || value2) {
  7683. dom.setStyle(node, prop, value2);
  7684. }
  7685. };
  7686. var setFormat = function(formatName, value2) {
  7687. if (!testTruthy || value2) {
  7688. if (value2 === "") {
  7689. editor.formatter.remove(formatName, { value: null }, node, true);
  7690. } else {
  7691. editor.formatter.apply(formatName, { value: value2 }, node);
  7692. }
  7693. }
  7694. };
  7695. return {
  7696. setAttrib,
  7697. setStyle,
  7698. setFormat
  7699. };
  7700. };
  7701. };
  7702. var DomModifier = {
  7703. normal: modifiers(false),
  7704. ifTruthy: modifiers(true)
  7705. };
  7706. var rgbToHex = function(dom) {
  7707. return function(value2) {
  7708. return startsWith(value2, "rgb") ? dom.toHex(value2) : value2;
  7709. };
  7710. };
  7711. var extractAdvancedStyles = function(dom, elm) {
  7712. var element = SugarElement.fromDom(elm);
  7713. return {
  7714. borderwidth: getRaw$2(element, "border-width").getOr(""),
  7715. borderstyle: getRaw$2(element, "border-style").getOr(""),
  7716. bordercolor: getRaw$2(element, "border-color").map(rgbToHex(dom)).getOr(""),
  7717. backgroundcolor: getRaw$2(element, "background-color").map(rgbToHex(dom)).getOr("")
  7718. };
  7719. };
  7720. var getSharedValues = function(data) {
  7721. var baseData = data[0];
  7722. var comparisonData = data.slice(1);
  7723. each$2(comparisonData, function(items) {
  7724. each$2(keys(baseData), function(key2) {
  7725. each$1(items, function(itemValue, itemKey) {
  7726. var comparisonValue = baseData[key2];
  7727. if (comparisonValue !== "" && key2 === itemKey) {
  7728. if (comparisonValue !== itemValue) {
  7729. baseData[key2] = "";
  7730. }
  7731. }
  7732. });
  7733. });
  7734. });
  7735. return baseData;
  7736. };
  7737. var getAlignment = function(formats, formatName, editor, elm) {
  7738. return find$1(formats, function(name2) {
  7739. return !isUndefined(editor.formatter.matchNode(elm, formatName + name2));
  7740. }).getOr("");
  7741. };
  7742. var getHAlignment = curry(getAlignment, [
  7743. "left",
  7744. "center",
  7745. "right"
  7746. ], "align");
  7747. var getVAlignment = curry(getAlignment, [
  7748. "top",
  7749. "middle",
  7750. "bottom"
  7751. ], "valign");
  7752. var extractDataFromSettings = function(editor, hasAdvTableTab) {
  7753. var style = getDefaultStyles(editor);
  7754. var attrs = getDefaultAttributes(editor);
  7755. var extractAdvancedStyleData = function(dom) {
  7756. return {
  7757. borderstyle: get$c(style, "border-style").getOr(""),
  7758. bordercolor: rgbToHex(dom)(get$c(style, "border-color").getOr("")),
  7759. backgroundcolor: rgbToHex(dom)(get$c(style, "background-color").getOr(""))
  7760. };
  7761. };
  7762. var defaultData = {
  7763. height: "",
  7764. width: "100%",
  7765. cellspacing: "",
  7766. cellpadding: "",
  7767. caption: false,
  7768. class: "",
  7769. align: "",
  7770. border: ""
  7771. };
  7772. var getBorder = function() {
  7773. var borderWidth = style["border-width"];
  7774. if (shouldStyleWithCss(editor) && borderWidth) {
  7775. return { border: borderWidth };
  7776. }
  7777. return get$c(attrs, "border").fold(function() {
  7778. return {};
  7779. }, function(border) {
  7780. return { border };
  7781. });
  7782. };
  7783. var advStyle = hasAdvTableTab ? extractAdvancedStyleData(editor.dom) : {};
  7784. var getCellPaddingCellSpacing = function() {
  7785. var spacing = get$c(style, "border-spacing").or(get$c(attrs, "cellspacing")).fold(function() {
  7786. return {};
  7787. }, function(cellspacing) {
  7788. return { cellspacing };
  7789. });
  7790. var padding = get$c(style, "border-padding").or(get$c(attrs, "cellpadding")).fold(function() {
  7791. return {};
  7792. }, function(cellpadding) {
  7793. return { cellpadding };
  7794. });
  7795. return __assign(__assign({}, spacing), padding);
  7796. };
  7797. var data = __assign(__assign(__assign(__assign(__assign(__assign({}, defaultData), style), attrs), advStyle), getBorder()), getCellPaddingCellSpacing());
  7798. return data;
  7799. };
  7800. var getRowType = function(elm) {
  7801. return table(SugarElement.fromDom(elm)).map(function(table2) {
  7802. var target = { selection: fromDom(elm.cells) };
  7803. return getRowsType(table2, target);
  7804. }).getOr("");
  7805. };
  7806. var extractDataFromTableElement = function(editor, elm, hasAdvTableTab) {
  7807. var getBorder = function(dom2, elm2) {
  7808. var optBorderWidth = getRaw$2(SugarElement.fromDom(elm2), "border-width");
  7809. if (shouldStyleWithCss(editor) && optBorderWidth.isSome()) {
  7810. return optBorderWidth.getOr("");
  7811. }
  7812. return dom2.getAttrib(elm2, "border") || getTDTHOverallStyle(editor.dom, elm2, "border-width") || getTDTHOverallStyle(editor.dom, elm2, "border");
  7813. };
  7814. var dom = editor.dom;
  7815. var cellspacing = shouldStyleWithCss(editor) ? dom.getStyle(elm, "border-spacing") || dom.getAttrib(elm, "cellspacing") : dom.getAttrib(elm, "cellspacing") || dom.getStyle(elm, "border-spacing");
  7816. var cellpadding = shouldStyleWithCss(editor) ? getTDTHOverallStyle(dom, elm, "padding") || dom.getAttrib(elm, "cellpadding") : dom.getAttrib(elm, "cellpadding") || getTDTHOverallStyle(dom, elm, "padding");
  7817. return __assign({
  7818. width: dom.getStyle(elm, "width") || dom.getAttrib(elm, "width"),
  7819. height: dom.getStyle(elm, "height") || dom.getAttrib(elm, "height"),
  7820. cellspacing,
  7821. cellpadding,
  7822. border: getBorder(dom, elm),
  7823. caption: !!dom.select("caption", elm)[0],
  7824. class: dom.getAttrib(elm, "class", ""),
  7825. align: getHAlignment(editor, elm)
  7826. }, hasAdvTableTab ? extractAdvancedStyles(dom, elm) : {});
  7827. };
  7828. var extractDataFromRowElement = function(editor, elm, hasAdvancedRowTab2) {
  7829. var dom = editor.dom;
  7830. return __assign({
  7831. height: dom.getStyle(elm, "height") || dom.getAttrib(elm, "height"),
  7832. class: dom.getAttrib(elm, "class", ""),
  7833. type: getRowType(elm),
  7834. align: getHAlignment(editor, elm)
  7835. }, hasAdvancedRowTab2 ? extractAdvancedStyles(dom, elm) : {});
  7836. };
  7837. var extractDataFromCellElement = function(editor, cell2, hasAdvancedCellTab2, column) {
  7838. var dom = editor.dom;
  7839. var colElm = column.getOr(cell2);
  7840. var getStyle = function(element, style) {
  7841. return dom.getStyle(element, style) || dom.getAttrib(element, style);
  7842. };
  7843. return __assign({
  7844. width: getStyle(colElm, "width"),
  7845. height: getStyle(cell2, "height"),
  7846. scope: dom.getAttrib(cell2, "scope"),
  7847. celltype: getNodeName(cell2),
  7848. class: dom.getAttrib(cell2, "class", ""),
  7849. halign: getHAlignment(editor, cell2),
  7850. valign: getVAlignment(editor, cell2)
  7851. }, hasAdvancedCellTab2 ? extractAdvancedStyles(dom, cell2) : {});
  7852. };
  7853. var getSelectedCells = function(table2, cells2) {
  7854. var warehouse = Warehouse.fromTable(table2);
  7855. var allCells = Warehouse.justCells(warehouse);
  7856. var filtered = filter$2(allCells, function(cellA) {
  7857. return exists(cells2, function(cellB) {
  7858. return eq$1(cellA.element, cellB);
  7859. });
  7860. });
  7861. return map$1(filtered, function(cell2) {
  7862. return {
  7863. element: cell2.element.dom,
  7864. column: Warehouse.getColumnAt(warehouse, cell2.column).map(function(col2) {
  7865. return col2.element.dom;
  7866. })
  7867. };
  7868. });
  7869. };
  7870. var updateSimpleProps$1 = function(modifier, colModifier, data) {
  7871. modifier.setAttrib("scope", data.scope);
  7872. modifier.setAttrib("class", data.class);
  7873. modifier.setStyle("height", addPxSuffix(data.height));
  7874. colModifier.setStyle("width", addPxSuffix(data.width));
  7875. };
  7876. var updateAdvancedProps$1 = function(modifier, data) {
  7877. modifier.setFormat("tablecellbackgroundcolor", data.backgroundcolor);
  7878. modifier.setFormat("tablecellbordercolor", data.bordercolor);
  7879. modifier.setFormat("tablecellborderstyle", data.borderstyle);
  7880. modifier.setFormat("tablecellborderwidth", addPxSuffix(data.borderwidth));
  7881. };
  7882. var applyStyleData$1 = function(editor, cells2, data) {
  7883. var isSingleCell = cells2.length === 1;
  7884. each$2(cells2, function(item) {
  7885. var cellElm = item.element;
  7886. var modifier = isSingleCell ? DomModifier.normal(editor, cellElm) : DomModifier.ifTruthy(editor, cellElm);
  7887. var colModifier = item.column.map(function(col2) {
  7888. return isSingleCell ? DomModifier.normal(editor, col2) : DomModifier.ifTruthy(editor, col2);
  7889. }).getOr(modifier);
  7890. updateSimpleProps$1(modifier, colModifier, data);
  7891. if (hasAdvancedCellTab(editor)) {
  7892. updateAdvancedProps$1(modifier, data);
  7893. }
  7894. if (isSingleCell) {
  7895. unApplyAlign(editor, cellElm);
  7896. unApplyVAlign(editor, cellElm);
  7897. }
  7898. if (data.halign) {
  7899. applyAlign(editor, cellElm, data.halign);
  7900. }
  7901. if (data.valign) {
  7902. applyVAlign(editor, cellElm, data.valign);
  7903. }
  7904. });
  7905. };
  7906. var applyStructureData$1 = function(editor, data) {
  7907. editor.execCommand("mceTableCellType", false, {
  7908. type: data.celltype,
  7909. no_events: true
  7910. });
  7911. };
  7912. var applyCellData = function(editor, cells2, oldData, data) {
  7913. var modifiedData = filter$1(data, function(value2, key2) {
  7914. return oldData[key2] !== value2;
  7915. });
  7916. if (size(modifiedData) > 0 && cells2.length >= 1) {
  7917. table(cells2[0]).each(function(table2) {
  7918. var selectedCells = getSelectedCells(table2, cells2);
  7919. var styleModified2 = size(filter$1(modifiedData, function(_value, key2) {
  7920. return key2 !== "scope" && key2 !== "celltype";
  7921. })) > 0;
  7922. var structureModified2 = has$1(modifiedData, "celltype");
  7923. if (styleModified2 || has$1(modifiedData, "scope")) {
  7924. applyStyleData$1(editor, selectedCells, data);
  7925. }
  7926. if (structureModified2) {
  7927. applyStructureData$1(editor, data);
  7928. }
  7929. fireTableModified(editor, table2.dom, {
  7930. structure: structureModified2,
  7931. style: styleModified2
  7932. });
  7933. });
  7934. }
  7935. };
  7936. var onSubmitCellForm = function(editor, cells2, oldData, api2) {
  7937. var data = api2.getData();
  7938. api2.close();
  7939. editor.undoManager.transact(function() {
  7940. applyCellData(editor, cells2, oldData, data);
  7941. editor.focus();
  7942. });
  7943. };
  7944. var getData = function(editor, cells2) {
  7945. var cellsData = table(cells2[0]).map(function(table2) {
  7946. return map$1(getSelectedCells(table2, cells2), function(item) {
  7947. return extractDataFromCellElement(editor, item.element, hasAdvancedCellTab(editor), item.column);
  7948. });
  7949. });
  7950. return getSharedValues(cellsData.getOrDie());
  7951. };
  7952. var open$2 = function(editor, selections) {
  7953. var cells2 = getCellsFromSelection(selections);
  7954. if (cells2.length === 0) {
  7955. return;
  7956. }
  7957. var data = getData(editor, cells2);
  7958. var dialogTabPanel = {
  7959. type: "tabpanel",
  7960. tabs: [
  7961. {
  7962. title: "General",
  7963. name: "general",
  7964. items: getItems$2(editor)
  7965. },
  7966. getAdvancedTab(editor, "cell")
  7967. ]
  7968. };
  7969. var dialogPanel = {
  7970. type: "panel",
  7971. items: [{
  7972. type: "grid",
  7973. columns: 2,
  7974. items: getItems$2(editor)
  7975. }]
  7976. };
  7977. editor.windowManager.open({
  7978. title: "Cell Properties",
  7979. size: "normal",
  7980. body: hasAdvancedCellTab(editor) ? dialogTabPanel : dialogPanel,
  7981. buttons: [
  7982. {
  7983. type: "cancel",
  7984. name: "cancel",
  7985. text: "Cancel"
  7986. },
  7987. {
  7988. type: "submit",
  7989. name: "save",
  7990. text: "Save",
  7991. primary: true
  7992. }
  7993. ],
  7994. initialData: data,
  7995. onSubmit: curry(onSubmitCellForm, editor, cells2, data)
  7996. });
  7997. };
  7998. var getClassList = function(editor) {
  7999. var classes = buildListItems(getRowClassList(editor));
  8000. if (classes.length > 0) {
  8001. return Optional.some({
  8002. name: "class",
  8003. type: "listbox",
  8004. label: "Class",
  8005. items: classes
  8006. });
  8007. }
  8008. return Optional.none();
  8009. };
  8010. var formChildren = [
  8011. {
  8012. type: "listbox",
  8013. name: "type",
  8014. label: "Row type",
  8015. items: [
  8016. {
  8017. text: "Header",
  8018. value: "header"
  8019. },
  8020. {
  8021. text: "Body",
  8022. value: "body"
  8023. },
  8024. {
  8025. text: "Footer",
  8026. value: "footer"
  8027. }
  8028. ]
  8029. },
  8030. {
  8031. type: "listbox",
  8032. name: "align",
  8033. label: "Alignment",
  8034. items: [
  8035. {
  8036. text: "None",
  8037. value: ""
  8038. },
  8039. {
  8040. text: "Left",
  8041. value: "left"
  8042. },
  8043. {
  8044. text: "Center",
  8045. value: "center"
  8046. },
  8047. {
  8048. text: "Right",
  8049. value: "right"
  8050. }
  8051. ]
  8052. },
  8053. {
  8054. label: "Height",
  8055. name: "height",
  8056. type: "input"
  8057. }
  8058. ];
  8059. var getItems$1 = function(editor) {
  8060. return formChildren.concat(getClassList(editor).toArray());
  8061. };
  8062. var updateSimpleProps = function(modifier, data) {
  8063. modifier.setAttrib("class", data.class);
  8064. modifier.setStyle("height", addPxSuffix(data.height));
  8065. };
  8066. var updateAdvancedProps = function(modifier, data) {
  8067. modifier.setStyle("background-color", data.backgroundcolor);
  8068. modifier.setStyle("border-color", data.bordercolor);
  8069. modifier.setStyle("border-style", data.borderstyle);
  8070. };
  8071. var applyStyleData = function(editor, rows2, data, oldData) {
  8072. var isSingleRow = rows2.length === 1;
  8073. each$2(rows2, function(rowElm) {
  8074. var modifier = isSingleRow ? DomModifier.normal(editor, rowElm) : DomModifier.ifTruthy(editor, rowElm);
  8075. updateSimpleProps(modifier, data);
  8076. if (hasAdvancedRowTab(editor)) {
  8077. updateAdvancedProps(modifier, data);
  8078. }
  8079. if (data.align !== oldData.align) {
  8080. unApplyAlign(editor, rowElm);
  8081. applyAlign(editor, rowElm, data.align);
  8082. }
  8083. });
  8084. };
  8085. var applyStructureData = function(editor, data) {
  8086. editor.execCommand("mceTableRowType", false, {
  8087. type: data.type,
  8088. no_events: true
  8089. });
  8090. };
  8091. var applyRowData = function(editor, rows2, oldData, data) {
  8092. var modifiedData = filter$1(data, function(value2, key2) {
  8093. return oldData[key2] !== value2;
  8094. });
  8095. if (size(modifiedData) > 0) {
  8096. var typeModified_1 = has$1(modifiedData, "type");
  8097. var styleModified_1 = typeModified_1 ? size(modifiedData) > 1 : true;
  8098. if (styleModified_1) {
  8099. applyStyleData(editor, rows2, data, oldData);
  8100. }
  8101. if (typeModified_1) {
  8102. applyStructureData(editor, data);
  8103. }
  8104. table(SugarElement.fromDom(rows2[0])).each(function(table2) {
  8105. return fireTableModified(editor, table2.dom, {
  8106. structure: typeModified_1,
  8107. style: styleModified_1
  8108. });
  8109. });
  8110. }
  8111. };
  8112. var onSubmitRowForm = function(editor, rows2, oldData, api2) {
  8113. var data = api2.getData();
  8114. api2.close();
  8115. editor.undoManager.transact(function() {
  8116. applyRowData(editor, rows2, oldData, data);
  8117. editor.focus();
  8118. });
  8119. };
  8120. var open$1 = function(editor) {
  8121. var rows2 = getRowsFromSelection(getSelectionStart(editor), ephemera.selected);
  8122. if (rows2.length === 0) {
  8123. return;
  8124. }
  8125. var rowsData = map$1(rows2, function(rowElm) {
  8126. return extractDataFromRowElement(editor, rowElm.dom, hasAdvancedRowTab(editor));
  8127. });
  8128. var data = getSharedValues(rowsData);
  8129. var dialogTabPanel = {
  8130. type: "tabpanel",
  8131. tabs: [
  8132. {
  8133. title: "General",
  8134. name: "general",
  8135. items: getItems$1(editor)
  8136. },
  8137. getAdvancedTab(editor, "row")
  8138. ]
  8139. };
  8140. var dialogPanel = {
  8141. type: "panel",
  8142. items: [{
  8143. type: "grid",
  8144. columns: 2,
  8145. items: getItems$1(editor)
  8146. }]
  8147. };
  8148. editor.windowManager.open({
  8149. title: "Row Properties",
  8150. size: "normal",
  8151. body: hasAdvancedRowTab(editor) ? dialogTabPanel : dialogPanel,
  8152. buttons: [
  8153. {
  8154. type: "cancel",
  8155. name: "cancel",
  8156. text: "Cancel"
  8157. },
  8158. {
  8159. type: "submit",
  8160. name: "save",
  8161. text: "Save",
  8162. primary: true
  8163. }
  8164. ],
  8165. initialData: data,
  8166. onSubmit: curry(onSubmitRowForm, editor, map$1(rows2, function(r2) {
  8167. return r2.dom;
  8168. }), data)
  8169. });
  8170. };
  8171. var getItems = function(editor, classes, insertNewTable) {
  8172. var rowColCountItems = !insertNewTable ? [] : [
  8173. {
  8174. type: "input",
  8175. name: "cols",
  8176. label: "Cols",
  8177. inputMode: "numeric"
  8178. },
  8179. {
  8180. type: "input",
  8181. name: "rows",
  8182. label: "Rows",
  8183. inputMode: "numeric"
  8184. }
  8185. ];
  8186. var alwaysItems = [
  8187. {
  8188. type: "input",
  8189. name: "width",
  8190. label: "Width"
  8191. },
  8192. {
  8193. type: "input",
  8194. name: "height",
  8195. label: "Height"
  8196. }
  8197. ];
  8198. var appearanceItems = hasAppearanceOptions(editor) ? [
  8199. {
  8200. type: "input",
  8201. name: "cellspacing",
  8202. label: "Cell spacing",
  8203. inputMode: "numeric"
  8204. },
  8205. {
  8206. type: "input",
  8207. name: "cellpadding",
  8208. label: "Cell padding",
  8209. inputMode: "numeric"
  8210. },
  8211. {
  8212. type: "input",
  8213. name: "border",
  8214. label: "Border width"
  8215. },
  8216. {
  8217. type: "label",
  8218. label: "Caption",
  8219. items: [{
  8220. type: "checkbox",
  8221. name: "caption",
  8222. label: "Show caption"
  8223. }]
  8224. }
  8225. ] : [];
  8226. var alignmentItem = [{
  8227. type: "listbox",
  8228. name: "align",
  8229. label: "Alignment",
  8230. items: [
  8231. {
  8232. text: "None",
  8233. value: ""
  8234. },
  8235. {
  8236. text: "Left",
  8237. value: "left"
  8238. },
  8239. {
  8240. text: "Center",
  8241. value: "center"
  8242. },
  8243. {
  8244. text: "Right",
  8245. value: "right"
  8246. }
  8247. ]
  8248. }];
  8249. var classListItem = classes.length > 0 ? [{
  8250. type: "listbox",
  8251. name: "class",
  8252. label: "Class",
  8253. items: classes
  8254. }] : [];
  8255. return rowColCountItems.concat(alwaysItems).concat(appearanceItems).concat(alignmentItem).concat(classListItem);
  8256. };
  8257. var styleTDTH = function(dom, elm, name2, value2) {
  8258. if (elm.tagName === "TD" || elm.tagName === "TH") {
  8259. if (isString(name2)) {
  8260. dom.setStyle(elm, name2, value2);
  8261. } else {
  8262. dom.setStyle(elm, name2);
  8263. }
  8264. } else {
  8265. if (elm.children) {
  8266. for (var i = 0; i < elm.children.length; i++) {
  8267. styleTDTH(dom, elm.children[i], name2, value2);
  8268. }
  8269. }
  8270. }
  8271. };
  8272. var applyDataToElement = function(editor, tableElm, data) {
  8273. var dom = editor.dom;
  8274. var attrs = {};
  8275. var styles2 = {};
  8276. attrs.class = data.class;
  8277. styles2.height = addPxSuffix(data.height);
  8278. if (dom.getAttrib(tableElm, "width") && !shouldStyleWithCss(editor)) {
  8279. attrs.width = removePxSuffix(data.width);
  8280. } else {
  8281. styles2.width = addPxSuffix(data.width);
  8282. }
  8283. if (shouldStyleWithCss(editor)) {
  8284. styles2["border-width"] = addPxSuffix(data.border);
  8285. styles2["border-spacing"] = addPxSuffix(data.cellspacing);
  8286. } else {
  8287. attrs.border = data.border;
  8288. attrs.cellpadding = data.cellpadding;
  8289. attrs.cellspacing = data.cellspacing;
  8290. }
  8291. if (shouldStyleWithCss(editor) && tableElm.children) {
  8292. for (var i = 0; i < tableElm.children.length; i++) {
  8293. styleTDTH(dom, tableElm.children[i], {
  8294. "border-width": addPxSuffix(data.border),
  8295. "padding": addPxSuffix(data.cellpadding)
  8296. });
  8297. if (hasAdvancedTableTab(editor)) {
  8298. styleTDTH(dom, tableElm.children[i], { "border-color": data.bordercolor });
  8299. }
  8300. }
  8301. }
  8302. if (hasAdvancedTableTab(editor)) {
  8303. styles2["background-color"] = data.backgroundcolor;
  8304. styles2["border-color"] = data.bordercolor;
  8305. styles2["border-style"] = data.borderstyle;
  8306. }
  8307. attrs.style = dom.serializeStyle(__assign(__assign({}, getDefaultStyles(editor)), styles2));
  8308. dom.setAttribs(tableElm, __assign(__assign({}, getDefaultAttributes(editor)), attrs));
  8309. };
  8310. var onSubmitTableForm = function(editor, tableElm, oldData, api2) {
  8311. var dom = editor.dom;
  8312. var data = api2.getData();
  8313. var modifiedData = filter$1(data, function(value2, key2) {
  8314. return oldData[key2] !== value2;
  8315. });
  8316. api2.close();
  8317. if (data.class === "") {
  8318. delete data.class;
  8319. }
  8320. editor.undoManager.transact(function() {
  8321. if (!tableElm) {
  8322. var cols = parseInt(data.cols, 10) || 1;
  8323. var rows2 = parseInt(data.rows, 10) || 1;
  8324. tableElm = insert(editor, cols, rows2, 0, 0);
  8325. }
  8326. if (size(modifiedData) > 0) {
  8327. applyDataToElement(editor, tableElm, data);
  8328. var captionElm = dom.select("caption", tableElm)[0];
  8329. if (captionElm && !data.caption || !captionElm && data.caption) {
  8330. editor.execCommand("mceTableToggleCaption");
  8331. }
  8332. if (data.align === "") {
  8333. unApplyAlign(editor, tableElm);
  8334. } else {
  8335. applyAlign(editor, tableElm, data.align);
  8336. }
  8337. }
  8338. editor.focus();
  8339. editor.addVisual();
  8340. if (size(modifiedData) > 0) {
  8341. var captionModified = has$1(modifiedData, "caption");
  8342. var styleModified2 = captionModified ? size(modifiedData) > 1 : true;
  8343. fireTableModified(editor, tableElm, {
  8344. structure: captionModified,
  8345. style: styleModified2
  8346. });
  8347. }
  8348. });
  8349. };
  8350. var open = function(editor, insertNewTable) {
  8351. var dom = editor.dom;
  8352. var tableElm;
  8353. var data = extractDataFromSettings(editor, hasAdvancedTableTab(editor));
  8354. if (insertNewTable === false) {
  8355. tableElm = dom.getParent(editor.selection.getStart(), "table", editor.getBody());
  8356. if (tableElm) {
  8357. data = extractDataFromTableElement(editor, tableElm, hasAdvancedTableTab(editor));
  8358. } else {
  8359. if (hasAdvancedTableTab(editor)) {
  8360. data.borderstyle = "";
  8361. data.bordercolor = "";
  8362. data.backgroundcolor = "";
  8363. }
  8364. }
  8365. } else {
  8366. data.cols = "1";
  8367. data.rows = "1";
  8368. if (hasAdvancedTableTab(editor)) {
  8369. data.borderstyle = "";
  8370. data.bordercolor = "";
  8371. data.backgroundcolor = "";
  8372. }
  8373. }
  8374. var classes = buildListItems(getTableClassList(editor));
  8375. if (classes.length > 0) {
  8376. if (data.class) {
  8377. data.class = data.class.replace(/\s*mce\-item\-table\s*/g, "");
  8378. }
  8379. }
  8380. var generalPanel = {
  8381. type: "grid",
  8382. columns: 2,
  8383. items: getItems(editor, classes, insertNewTable)
  8384. };
  8385. var nonAdvancedForm = function() {
  8386. return {
  8387. type: "panel",
  8388. items: [generalPanel]
  8389. };
  8390. };
  8391. var advancedForm = function() {
  8392. return {
  8393. type: "tabpanel",
  8394. tabs: [
  8395. {
  8396. title: "General",
  8397. name: "general",
  8398. items: [generalPanel]
  8399. },
  8400. getAdvancedTab(editor, "table")
  8401. ]
  8402. };
  8403. };
  8404. var dialogBody = hasAdvancedTableTab(editor) ? advancedForm() : nonAdvancedForm();
  8405. editor.windowManager.open({
  8406. title: "Table Properties",
  8407. size: "normal",
  8408. body: dialogBody,
  8409. onSubmit: curry(onSubmitTableForm, editor, tableElm, data),
  8410. buttons: [
  8411. {
  8412. type: "cancel",
  8413. name: "cancel",
  8414. text: "Cancel"
  8415. },
  8416. {
  8417. type: "submit",
  8418. name: "save",
  8419. text: "Save",
  8420. primary: true
  8421. }
  8422. ],
  8423. initialData: data
  8424. });
  8425. };
  8426. var getSelectionStartCellOrCaption = function(editor) {
  8427. return getSelectionCellOrCaption(getSelectionStart(editor), getIsRoot(editor));
  8428. };
  8429. var getSelectionStartCell = function(editor) {
  8430. return getSelectionCell(getSelectionStart(editor), getIsRoot(editor));
  8431. };
  8432. var registerCommands = function(editor, actions, cellSelection, selections, clipboard) {
  8433. var isRoot = getIsRoot(editor);
  8434. var eraseTable = function() {
  8435. return getSelectionStartCellOrCaption(editor).each(function(cellOrCaption) {
  8436. table(cellOrCaption, isRoot).filter(not(isRoot)).each(function(table2) {
  8437. var cursor = SugarElement.fromText("");
  8438. after$5(table2, cursor);
  8439. remove$5(table2);
  8440. if (editor.dom.isEmpty(editor.getBody())) {
  8441. editor.setContent("");
  8442. editor.selection.setCursorLocation();
  8443. } else {
  8444. var rng = editor.dom.createRng();
  8445. rng.setStart(cursor.dom, 0);
  8446. rng.setEnd(cursor.dom, 0);
  8447. editor.selection.setRng(rng);
  8448. editor.nodeChanged();
  8449. }
  8450. });
  8451. });
  8452. };
  8453. var setSizingMode = function(sizing) {
  8454. return getSelectionStartCellOrCaption(editor).each(function(cellOrCaption) {
  8455. var isForcedSizing = isResponsiveForced(editor) || isPixelsForced(editor) || isPercentagesForced(editor);
  8456. if (!isForcedSizing) {
  8457. table(cellOrCaption, isRoot).each(function(table2) {
  8458. if (sizing === "relative" && !isPercentSizing(table2)) {
  8459. enforcePercentage(table2);
  8460. } else if (sizing === "fixed" && !isPixelSizing(table2)) {
  8461. enforcePixels(table2);
  8462. } else if (sizing === "responsive" && !isNoneSizing(table2)) {
  8463. enforceNone(table2);
  8464. }
  8465. removeDataStyle(table2);
  8466. fireTableModified(editor, table2.dom, structureModified);
  8467. });
  8468. }
  8469. });
  8470. };
  8471. var getTableFromCell = function(cell2) {
  8472. return table(cell2, isRoot);
  8473. };
  8474. var performActionOnSelection = function(action) {
  8475. return getSelectionStartCell(editor).bind(function(cell2) {
  8476. return getTableFromCell(cell2).map(function(table2) {
  8477. return action(table2, cell2);
  8478. });
  8479. });
  8480. };
  8481. var toggleTableClass = function(_ui, clazz) {
  8482. performActionOnSelection(function(table2) {
  8483. editor.formatter.toggle("tableclass", { value: clazz }, table2.dom);
  8484. fireTableModified(editor, table2.dom, styleModified);
  8485. });
  8486. };
  8487. var toggleTableCellClass = function(_ui, clazz) {
  8488. performActionOnSelection(function(table2) {
  8489. var selectedCells = getCellsFromSelection(selections);
  8490. var allHaveClass = forall(selectedCells, function(cell2) {
  8491. return editor.formatter.match("tablecellclass", { value: clazz }, cell2.dom);
  8492. });
  8493. var formatterAction = allHaveClass ? editor.formatter.remove : editor.formatter.apply;
  8494. each$2(selectedCells, function(cell2) {
  8495. return formatterAction("tablecellclass", { value: clazz }, cell2.dom);
  8496. });
  8497. fireTableModified(editor, table2.dom, styleModified);
  8498. });
  8499. };
  8500. var toggleCaption = function() {
  8501. getSelectionStartCellOrCaption(editor).each(function(cellOrCaption) {
  8502. table(cellOrCaption, isRoot).each(function(table2) {
  8503. child$1(table2, "caption").fold(function() {
  8504. var caption = SugarElement.fromTag("caption");
  8505. append$1(caption, SugarElement.fromText("Caption"));
  8506. appendAt(table2, caption, 0);
  8507. editor.selection.setCursorLocation(caption.dom, 0);
  8508. }, function(caption) {
  8509. if (isTag("caption")(cellOrCaption)) {
  8510. one("td", table2).each(function(td) {
  8511. return editor.selection.setCursorLocation(td.dom, 0);
  8512. });
  8513. }
  8514. remove$5(caption);
  8515. });
  8516. fireTableModified(editor, table2.dom, structureModified);
  8517. });
  8518. });
  8519. };
  8520. var postExecute = function(_data) {
  8521. editor.focus();
  8522. };
  8523. var actOnSelection = function(execute, noEvents) {
  8524. if (noEvents === void 0) {
  8525. noEvents = false;
  8526. }
  8527. return performActionOnSelection(function(table2, startCell) {
  8528. var targets = forMenu(selections, table2, startCell);
  8529. execute(table2, targets, noEvents).each(postExecute);
  8530. });
  8531. };
  8532. var copyRowSelection = function() {
  8533. return performActionOnSelection(function(table2, startCell) {
  8534. var targets = forMenu(selections, table2, startCell);
  8535. var generators = cellOperations(noop, SugarElement.fromDom(editor.getDoc()), Optional.none());
  8536. return copyRows(table2, targets, generators);
  8537. });
  8538. };
  8539. var copyColSelection = function() {
  8540. return performActionOnSelection(function(table2, startCell) {
  8541. var targets = forMenu(selections, table2, startCell);
  8542. return copyCols(table2, targets);
  8543. });
  8544. };
  8545. var pasteOnSelection = function(execute, getRows) {
  8546. return getRows().each(function(rows2) {
  8547. var clonedRows = map$1(rows2, function(row2) {
  8548. return deep(row2);
  8549. });
  8550. performActionOnSelection(function(table2, startCell) {
  8551. var generators = paste$1(SugarElement.fromDom(editor.getDoc()));
  8552. var targets = pasteRows(selections, startCell, clonedRows, generators);
  8553. execute(table2, targets).each(postExecute);
  8554. });
  8555. });
  8556. };
  8557. var actOnType = function(getAction) {
  8558. return function(_ui, args) {
  8559. return get$c(args, "type").each(function(type2) {
  8560. actOnSelection(getAction(type2), args.no_events);
  8561. });
  8562. };
  8563. };
  8564. each$1({
  8565. mceTableSplitCells: function() {
  8566. return actOnSelection(actions.unmergeCells);
  8567. },
  8568. mceTableMergeCells: function() {
  8569. return actOnSelection(actions.mergeCells);
  8570. },
  8571. mceTableInsertRowBefore: function() {
  8572. return actOnSelection(actions.insertRowsBefore);
  8573. },
  8574. mceTableInsertRowAfter: function() {
  8575. return actOnSelection(actions.insertRowsAfter);
  8576. },
  8577. mceTableInsertColBefore: function() {
  8578. return actOnSelection(actions.insertColumnsBefore);
  8579. },
  8580. mceTableInsertColAfter: function() {
  8581. return actOnSelection(actions.insertColumnsAfter);
  8582. },
  8583. mceTableDeleteCol: function() {
  8584. return actOnSelection(actions.deleteColumn);
  8585. },
  8586. mceTableDeleteRow: function() {
  8587. return actOnSelection(actions.deleteRow);
  8588. },
  8589. mceTableCutCol: function() {
  8590. return copyColSelection().each(function(selection2) {
  8591. clipboard.setColumns(selection2);
  8592. actOnSelection(actions.deleteColumn);
  8593. });
  8594. },
  8595. mceTableCutRow: function() {
  8596. return copyRowSelection().each(function(selection2) {
  8597. clipboard.setRows(selection2);
  8598. actOnSelection(actions.deleteRow);
  8599. });
  8600. },
  8601. mceTableCopyCol: function() {
  8602. return copyColSelection().each(function(selection2) {
  8603. return clipboard.setColumns(selection2);
  8604. });
  8605. },
  8606. mceTableCopyRow: function() {
  8607. return copyRowSelection().each(function(selection2) {
  8608. return clipboard.setRows(selection2);
  8609. });
  8610. },
  8611. mceTablePasteColBefore: function() {
  8612. return pasteOnSelection(actions.pasteColsBefore, clipboard.getColumns);
  8613. },
  8614. mceTablePasteColAfter: function() {
  8615. return pasteOnSelection(actions.pasteColsAfter, clipboard.getColumns);
  8616. },
  8617. mceTablePasteRowBefore: function() {
  8618. return pasteOnSelection(actions.pasteRowsBefore, clipboard.getRows);
  8619. },
  8620. mceTablePasteRowAfter: function() {
  8621. return pasteOnSelection(actions.pasteRowsAfter, clipboard.getRows);
  8622. },
  8623. mceTableDelete: eraseTable,
  8624. mceTableCellToggleClass: toggleTableCellClass,
  8625. mceTableToggleClass: toggleTableClass,
  8626. mceTableToggleCaption: toggleCaption,
  8627. mceTableSizingMode: function(_ui, sizing) {
  8628. return setSizingMode(sizing);
  8629. },
  8630. mceTableCellType: actOnType(function(type2) {
  8631. return type2 === "th" ? actions.makeCellsHeader : actions.unmakeCellsHeader;
  8632. }),
  8633. mceTableColType: actOnType(function(type2) {
  8634. return type2 === "th" ? actions.makeColumnsHeader : actions.unmakeColumnsHeader;
  8635. }),
  8636. mceTableRowType: actOnType(function(type2) {
  8637. switch (type2) {
  8638. case "header":
  8639. return actions.makeRowsHeader;
  8640. case "footer":
  8641. return actions.makeRowsFooter;
  8642. default:
  8643. return actions.makeRowsBody;
  8644. }
  8645. })
  8646. }, function(func, name2) {
  8647. return editor.addCommand(name2, func);
  8648. });
  8649. each$1({
  8650. mceTableProps: curry(open, editor, false),
  8651. mceTableRowProps: curry(open$1, editor),
  8652. mceTableCellProps: curry(open$2, editor, selections)
  8653. }, function(func, name2) {
  8654. return editor.addCommand(name2, function() {
  8655. return func();
  8656. });
  8657. });
  8658. editor.addCommand("mceInsertTable", function(_ui, args) {
  8659. if (isObject(args) && keys(args).length > 0) {
  8660. insertTableWithDataValidation(editor, args.rows, args.columns, args.options, "Invalid values for mceInsertTable - rows and columns values are required to insert a table.");
  8661. } else {
  8662. open(editor, true);
  8663. }
  8664. });
  8665. editor.addCommand("mceTableApplyCellStyle", function(_ui, args) {
  8666. var getFormatName = function(style) {
  8667. return "tablecell" + style.toLowerCase().replace("-", "");
  8668. };
  8669. if (!isObject(args)) {
  8670. return;
  8671. }
  8672. var cells2 = getCellsFromSelection(selections);
  8673. if (cells2.length === 0) {
  8674. return;
  8675. }
  8676. var validArgs = filter$1(args, function(value2, style) {
  8677. return editor.formatter.has(getFormatName(style)) && isString(value2);
  8678. });
  8679. if (isEmpty(validArgs)) {
  8680. return;
  8681. }
  8682. each$1(validArgs, function(value2, style) {
  8683. each$2(cells2, function(cell2) {
  8684. DomModifier.normal(editor, cell2.dom).setFormat(getFormatName(style), value2);
  8685. });
  8686. });
  8687. getTableFromCell(cells2[0]).each(function(table2) {
  8688. return fireTableModified(editor, table2.dom, styleModified);
  8689. });
  8690. });
  8691. };
  8692. var registerQueryCommands = function(editor, actions, selections) {
  8693. var isRoot = getIsRoot(editor);
  8694. var lookupOnSelection = function(action) {
  8695. return getSelectionCell(getSelectionStart(editor)).bind(function(cell2) {
  8696. return table(cell2, isRoot).map(function(table2) {
  8697. var targets = forMenu(selections, table2, cell2);
  8698. return action(table2, targets);
  8699. });
  8700. }).getOr("");
  8701. };
  8702. each$1({
  8703. mceTableRowType: function() {
  8704. return lookupOnSelection(actions.getTableRowType);
  8705. },
  8706. mceTableCellType: function() {
  8707. return lookupOnSelection(actions.getTableCellType);
  8708. },
  8709. mceTableColType: function() {
  8710. return lookupOnSelection(actions.getTableColType);
  8711. }
  8712. }, function(func, name2) {
  8713. return editor.addQueryValueHandler(name2, func);
  8714. });
  8715. };
  8716. var Clipboard = function() {
  8717. var rows2 = value();
  8718. var cols = value();
  8719. return {
  8720. getRows: rows2.get,
  8721. setRows: function(r2) {
  8722. r2.fold(rows2.clear, rows2.set);
  8723. cols.clear();
  8724. },
  8725. clearRows: rows2.clear,
  8726. getColumns: cols.get,
  8727. setColumns: function(c) {
  8728. c.fold(cols.clear, cols.set);
  8729. rows2.clear();
  8730. },
  8731. clearColumns: cols.clear
  8732. };
  8733. };
  8734. var genericBase = {
  8735. remove_similar: true,
  8736. inherit: false
  8737. };
  8738. var cellBase = __assign({ selector: "td,th" }, genericBase);
  8739. var cellFormats = {
  8740. tablecellbackgroundcolor: __assign({ styles: { backgroundColor: "%value" } }, cellBase),
  8741. tablecellverticalalign: __assign({ styles: { "vertical-align": "%value" } }, cellBase),
  8742. tablecellbordercolor: __assign({ styles: { borderColor: "%value" } }, cellBase),
  8743. tablecellclass: __assign({ classes: ["%value"] }, cellBase),
  8744. tableclass: __assign({
  8745. selector: "table",
  8746. classes: ["%value"]
  8747. }, genericBase),
  8748. tablecellborderstyle: __assign({ styles: { borderStyle: "%value" } }, cellBase),
  8749. tablecellborderwidth: __assign({ styles: { borderWidth: "%value" } }, cellBase)
  8750. };
  8751. var registerFormats = function(editor) {
  8752. editor.formatter.register(cellFormats);
  8753. };
  8754. var adt$5 = Adt.generate([
  8755. { none: ["current"] },
  8756. { first: ["current"] },
  8757. {
  8758. middle: [
  8759. "current",
  8760. "target"
  8761. ]
  8762. },
  8763. { last: ["current"] }
  8764. ]);
  8765. var none = function(current) {
  8766. if (current === void 0) {
  8767. current = void 0;
  8768. }
  8769. return adt$5.none(current);
  8770. };
  8771. var CellLocation = __assign(__assign({}, adt$5), { none });
  8772. var walk = function(all2, current, index, direction, isEligible) {
  8773. if (isEligible === void 0) {
  8774. isEligible = always;
  8775. }
  8776. var forwards = direction === 1;
  8777. if (!forwards && index <= 0) {
  8778. return CellLocation.first(all2[0]);
  8779. } else if (forwards && index >= all2.length - 1) {
  8780. return CellLocation.last(all2[all2.length - 1]);
  8781. } else {
  8782. var newIndex = index + direction;
  8783. var elem = all2[newIndex];
  8784. return isEligible(elem) ? CellLocation.middle(current, elem) : walk(all2, current, newIndex, direction, isEligible);
  8785. }
  8786. };
  8787. var detect$1 = function(current, isRoot) {
  8788. return table(current, isRoot).bind(function(table2) {
  8789. var all2 = cells$1(table2);
  8790. var index = findIndex(all2, function(x) {
  8791. return eq$1(current, x);
  8792. });
  8793. return index.map(function(index2) {
  8794. return {
  8795. index: index2,
  8796. all: all2
  8797. };
  8798. });
  8799. });
  8800. };
  8801. var next = function(current, isEligible, isRoot) {
  8802. var detection = detect$1(current, isRoot);
  8803. return detection.fold(function() {
  8804. return CellLocation.none(current);
  8805. }, function(info) {
  8806. return walk(info.all, current, info.index, 1, isEligible);
  8807. });
  8808. };
  8809. var prev = function(current, isEligible, isRoot) {
  8810. var detection = detect$1(current, isRoot);
  8811. return detection.fold(function() {
  8812. return CellLocation.none();
  8813. }, function(info) {
  8814. return walk(info.all, current, info.index, -1, isEligible);
  8815. });
  8816. };
  8817. var create$2 = function(start, soffset, finish, foffset) {
  8818. return {
  8819. start,
  8820. soffset,
  8821. finish,
  8822. foffset
  8823. };
  8824. };
  8825. var SimRange = { create: create$2 };
  8826. var adt$4 = Adt.generate([
  8827. { before: ["element"] },
  8828. {
  8829. on: [
  8830. "element",
  8831. "offset"
  8832. ]
  8833. },
  8834. { after: ["element"] }
  8835. ]);
  8836. var cata$1 = function(subject, onBefore, onOn, onAfter) {
  8837. return subject.fold(onBefore, onOn, onAfter);
  8838. };
  8839. var getStart$1 = function(situ) {
  8840. return situ.fold(identity, identity, identity);
  8841. };
  8842. var before$2 = adt$4.before;
  8843. var on = adt$4.on;
  8844. var after$3 = adt$4.after;
  8845. var Situ = {
  8846. before: before$2,
  8847. on,
  8848. after: after$3,
  8849. cata: cata$1,
  8850. getStart: getStart$1
  8851. };
  8852. var adt$3 = Adt.generate([
  8853. { domRange: ["rng"] },
  8854. {
  8855. relative: [
  8856. "startSitu",
  8857. "finishSitu"
  8858. ]
  8859. },
  8860. {
  8861. exact: [
  8862. "start",
  8863. "soffset",
  8864. "finish",
  8865. "foffset"
  8866. ]
  8867. }
  8868. ]);
  8869. var exactFromRange = function(simRange) {
  8870. return adt$3.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset);
  8871. };
  8872. var getStart = function(selection2) {
  8873. return selection2.match({
  8874. domRange: function(rng) {
  8875. return SugarElement.fromDom(rng.startContainer);
  8876. },
  8877. relative: function(startSitu, _finishSitu) {
  8878. return Situ.getStart(startSitu);
  8879. },
  8880. exact: function(start, _soffset, _finish, _foffset) {
  8881. return start;
  8882. }
  8883. });
  8884. };
  8885. var domRange = adt$3.domRange;
  8886. var relative = adt$3.relative;
  8887. var exact = adt$3.exact;
  8888. var getWin = function(selection2) {
  8889. var start = getStart(selection2);
  8890. return defaultView(start);
  8891. };
  8892. var range = SimRange.create;
  8893. var SimSelection = {
  8894. domRange,
  8895. relative,
  8896. exact,
  8897. exactFromRange,
  8898. getWin,
  8899. range
  8900. };
  8901. var selectNode = function(win, element) {
  8902. var rng = win.document.createRange();
  8903. rng.selectNode(element.dom);
  8904. return rng;
  8905. };
  8906. var selectNodeContents = function(win, element) {
  8907. var rng = win.document.createRange();
  8908. selectNodeContentsUsing(rng, element);
  8909. return rng;
  8910. };
  8911. var selectNodeContentsUsing = function(rng, element) {
  8912. return rng.selectNodeContents(element.dom);
  8913. };
  8914. var setStart = function(rng, situ) {
  8915. situ.fold(function(e) {
  8916. rng.setStartBefore(e.dom);
  8917. }, function(e, o) {
  8918. rng.setStart(e.dom, o);
  8919. }, function(e) {
  8920. rng.setStartAfter(e.dom);
  8921. });
  8922. };
  8923. var setFinish = function(rng, situ) {
  8924. situ.fold(function(e) {
  8925. rng.setEndBefore(e.dom);
  8926. }, function(e, o) {
  8927. rng.setEnd(e.dom, o);
  8928. }, function(e) {
  8929. rng.setEndAfter(e.dom);
  8930. });
  8931. };
  8932. var relativeToNative = function(win, startSitu, finishSitu) {
  8933. var range2 = win.document.createRange();
  8934. setStart(range2, startSitu);
  8935. setFinish(range2, finishSitu);
  8936. return range2;
  8937. };
  8938. var exactToNative = function(win, start, soffset, finish, foffset) {
  8939. var rng = win.document.createRange();
  8940. rng.setStart(start.dom, soffset);
  8941. rng.setEnd(finish.dom, foffset);
  8942. return rng;
  8943. };
  8944. var toRect = function(rect) {
  8945. return {
  8946. left: rect.left,
  8947. top: rect.top,
  8948. right: rect.right,
  8949. bottom: rect.bottom,
  8950. width: rect.width,
  8951. height: rect.height
  8952. };
  8953. };
  8954. var getFirstRect$1 = function(rng) {
  8955. var rects = rng.getClientRects();
  8956. var rect = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
  8957. return rect.width > 0 || rect.height > 0 ? Optional.some(rect).map(toRect) : Optional.none();
  8958. };
  8959. var adt$2 = Adt.generate([
  8960. {
  8961. ltr: [
  8962. "start",
  8963. "soffset",
  8964. "finish",
  8965. "foffset"
  8966. ]
  8967. },
  8968. {
  8969. rtl: [
  8970. "start",
  8971. "soffset",
  8972. "finish",
  8973. "foffset"
  8974. ]
  8975. }
  8976. ]);
  8977. var fromRange = function(win, type2, range2) {
  8978. return type2(SugarElement.fromDom(range2.startContainer), range2.startOffset, SugarElement.fromDom(range2.endContainer), range2.endOffset);
  8979. };
  8980. var getRanges = function(win, selection2) {
  8981. return selection2.match({
  8982. domRange: function(rng) {
  8983. return {
  8984. ltr: constant(rng),
  8985. rtl: Optional.none
  8986. };
  8987. },
  8988. relative: function(startSitu, finishSitu) {
  8989. return {
  8990. ltr: cached(function() {
  8991. return relativeToNative(win, startSitu, finishSitu);
  8992. }),
  8993. rtl: cached(function() {
  8994. return Optional.some(relativeToNative(win, finishSitu, startSitu));
  8995. })
  8996. };
  8997. },
  8998. exact: function(start, soffset, finish, foffset) {
  8999. return {
  9000. ltr: cached(function() {
  9001. return exactToNative(win, start, soffset, finish, foffset);
  9002. }),
  9003. rtl: cached(function() {
  9004. return Optional.some(exactToNative(win, finish, foffset, start, soffset));
  9005. })
  9006. };
  9007. }
  9008. });
  9009. };
  9010. var doDiagnose = function(win, ranges) {
  9011. var rng = ranges.ltr();
  9012. if (rng.collapsed) {
  9013. var reversed = ranges.rtl().filter(function(rev) {
  9014. return rev.collapsed === false;
  9015. });
  9016. return reversed.map(function(rev) {
  9017. return adt$2.rtl(SugarElement.fromDom(rev.endContainer), rev.endOffset, SugarElement.fromDom(rev.startContainer), rev.startOffset);
  9018. }).getOrThunk(function() {
  9019. return fromRange(win, adt$2.ltr, rng);
  9020. });
  9021. } else {
  9022. return fromRange(win, adt$2.ltr, rng);
  9023. }
  9024. };
  9025. var diagnose = function(win, selection2) {
  9026. var ranges = getRanges(win, selection2);
  9027. return doDiagnose(win, ranges);
  9028. };
  9029. var asLtrRange = function(win, selection2) {
  9030. var diagnosis = diagnose(win, selection2);
  9031. return diagnosis.match({
  9032. ltr: function(start, soffset, finish, foffset) {
  9033. var rng = win.document.createRange();
  9034. rng.setStart(start.dom, soffset);
  9035. rng.setEnd(finish.dom, foffset);
  9036. return rng;
  9037. },
  9038. rtl: function(start, soffset, finish, foffset) {
  9039. var rng = win.document.createRange();
  9040. rng.setStart(finish.dom, foffset);
  9041. rng.setEnd(start.dom, soffset);
  9042. return rng;
  9043. }
  9044. });
  9045. };
  9046. adt$2.ltr;
  9047. adt$2.rtl;
  9048. var searchForPoint = function(rectForOffset, x, y, maxX, length) {
  9049. if (length === 0) {
  9050. return 0;
  9051. } else if (x === maxX) {
  9052. return length - 1;
  9053. }
  9054. var xDelta = maxX;
  9055. for (var i = 1; i < length; i++) {
  9056. var rect = rectForOffset(i);
  9057. var curDeltaX = Math.abs(x - rect.left);
  9058. if (y <= rect.bottom) {
  9059. if (y < rect.top || curDeltaX > xDelta) {
  9060. return i - 1;
  9061. } else {
  9062. xDelta = curDeltaX;
  9063. }
  9064. }
  9065. }
  9066. return 0;
  9067. };
  9068. var inRect = function(rect, x, y) {
  9069. return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
  9070. };
  9071. var locateOffset = function(doc, textnode, x, y, rect) {
  9072. var rangeForOffset = function(o) {
  9073. var r2 = doc.dom.createRange();
  9074. r2.setStart(textnode.dom, o);
  9075. r2.collapse(true);
  9076. return r2;
  9077. };
  9078. var rectForOffset = function(o) {
  9079. var r2 = rangeForOffset(o);
  9080. return r2.getBoundingClientRect();
  9081. };
  9082. var length = get$9(textnode).length;
  9083. var offset = searchForPoint(rectForOffset, x, y, rect.right, length);
  9084. return rangeForOffset(offset);
  9085. };
  9086. var locate$1 = function(doc, node, x, y) {
  9087. var r2 = doc.dom.createRange();
  9088. r2.selectNode(node.dom);
  9089. var rects = r2.getClientRects();
  9090. var foundRect = findMap(rects, function(rect) {
  9091. return inRect(rect, x, y) ? Optional.some(rect) : Optional.none();
  9092. });
  9093. return foundRect.map(function(rect) {
  9094. return locateOffset(doc, node, x, y, rect);
  9095. });
  9096. };
  9097. var searchInChildren = function(doc, node, x, y) {
  9098. var r2 = doc.dom.createRange();
  9099. var nodes = children$3(node);
  9100. return findMap(nodes, function(n) {
  9101. r2.selectNode(n.dom);
  9102. return inRect(r2.getBoundingClientRect(), x, y) ? locateNode(doc, n, x, y) : Optional.none();
  9103. });
  9104. };
  9105. var locateNode = function(doc, node, x, y) {
  9106. return isText(node) ? locate$1(doc, node, x, y) : searchInChildren(doc, node, x, y);
  9107. };
  9108. var locate = function(doc, node, x, y) {
  9109. var r2 = doc.dom.createRange();
  9110. r2.selectNode(node.dom);
  9111. var rect = r2.getBoundingClientRect();
  9112. var boundedX = Math.max(rect.left, Math.min(rect.right, x));
  9113. var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
  9114. return locateNode(doc, node, boundedX, boundedY);
  9115. };
  9116. var COLLAPSE_TO_LEFT = true;
  9117. var COLLAPSE_TO_RIGHT = false;
  9118. var getCollapseDirection = function(rect, x) {
  9119. return x - rect.left < rect.right - x ? COLLAPSE_TO_LEFT : COLLAPSE_TO_RIGHT;
  9120. };
  9121. var createCollapsedNode = function(doc, target, collapseDirection) {
  9122. var r2 = doc.dom.createRange();
  9123. r2.selectNode(target.dom);
  9124. r2.collapse(collapseDirection);
  9125. return r2;
  9126. };
  9127. var locateInElement = function(doc, node, x) {
  9128. var cursorRange = doc.dom.createRange();
  9129. cursorRange.selectNode(node.dom);
  9130. var rect = cursorRange.getBoundingClientRect();
  9131. var collapseDirection = getCollapseDirection(rect, x);
  9132. var f = collapseDirection === COLLAPSE_TO_LEFT ? first : last$1;
  9133. return f(node).map(function(target) {
  9134. return createCollapsedNode(doc, target, collapseDirection);
  9135. });
  9136. };
  9137. var locateInEmpty = function(doc, node, x) {
  9138. var rect = node.dom.getBoundingClientRect();
  9139. var collapseDirection = getCollapseDirection(rect, x);
  9140. return Optional.some(createCollapsedNode(doc, node, collapseDirection));
  9141. };
  9142. var search = function(doc, node, x) {
  9143. var f = children$3(node).length === 0 ? locateInEmpty : locateInElement;
  9144. return f(doc, node, x);
  9145. };
  9146. var caretPositionFromPoint = function(doc, x, y) {
  9147. var _a, _b;
  9148. return Optional.from((_b = (_a = doc.dom).caretPositionFromPoint) === null || _b === void 0 ? void 0 : _b.call(_a, x, y)).bind(function(pos) {
  9149. if (pos.offsetNode === null) {
  9150. return Optional.none();
  9151. }
  9152. var r2 = doc.dom.createRange();
  9153. r2.setStart(pos.offsetNode, pos.offset);
  9154. r2.collapse();
  9155. return Optional.some(r2);
  9156. });
  9157. };
  9158. var caretRangeFromPoint = function(doc, x, y) {
  9159. var _a, _b;
  9160. return Optional.from((_b = (_a = doc.dom).caretRangeFromPoint) === null || _b === void 0 ? void 0 : _b.call(_a, x, y));
  9161. };
  9162. var searchTextNodes = function(doc, node, x, y) {
  9163. var r2 = doc.dom.createRange();
  9164. r2.selectNode(node.dom);
  9165. var rect = r2.getBoundingClientRect();
  9166. var boundedX = Math.max(rect.left, Math.min(rect.right, x));
  9167. var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
  9168. return locate(doc, node, boundedX, boundedY);
  9169. };
  9170. var searchFromPoint = function(doc, x, y) {
  9171. return SugarElement.fromPoint(doc, x, y).bind(function(elem) {
  9172. var fallback2 = function() {
  9173. return search(doc, elem, x);
  9174. };
  9175. return children$3(elem).length === 0 ? fallback2() : searchTextNodes(doc, elem, x, y).orThunk(fallback2);
  9176. });
  9177. };
  9178. var availableSearch = function() {
  9179. if (document.caretPositionFromPoint) {
  9180. return caretPositionFromPoint;
  9181. } else if (document.caretRangeFromPoint) {
  9182. return caretRangeFromPoint;
  9183. } else {
  9184. return searchFromPoint;
  9185. }
  9186. }();
  9187. var fromPoint = function(win, x, y) {
  9188. var doc = SugarElement.fromDom(win.document);
  9189. return availableSearch(doc, x, y).map(function(rng) {
  9190. return SimRange.create(SugarElement.fromDom(rng.startContainer), rng.startOffset, SugarElement.fromDom(rng.endContainer), rng.endOffset);
  9191. });
  9192. };
  9193. var beforeSpecial = function(element, offset) {
  9194. var name$1 = name(element);
  9195. if ("input" === name$1) {
  9196. return Situ.after(element);
  9197. } else if (!contains$2([
  9198. "br",
  9199. "img"
  9200. ], name$1)) {
  9201. return Situ.on(element, offset);
  9202. } else {
  9203. return offset === 0 ? Situ.before(element) : Situ.after(element);
  9204. }
  9205. };
  9206. var preprocessRelative = function(startSitu, finishSitu) {
  9207. var start = startSitu.fold(Situ.before, beforeSpecial, Situ.after);
  9208. var finish = finishSitu.fold(Situ.before, beforeSpecial, Situ.after);
  9209. return SimSelection.relative(start, finish);
  9210. };
  9211. var preprocessExact = function(start, soffset, finish, foffset) {
  9212. var startSitu = beforeSpecial(start, soffset);
  9213. var finishSitu = beforeSpecial(finish, foffset);
  9214. return SimSelection.relative(startSitu, finishSitu);
  9215. };
  9216. var preprocess = function(selection2) {
  9217. return selection2.match({
  9218. domRange: function(rng) {
  9219. var start = SugarElement.fromDom(rng.startContainer);
  9220. var finish = SugarElement.fromDom(rng.endContainer);
  9221. return preprocessExact(start, rng.startOffset, finish, rng.endOffset);
  9222. },
  9223. relative: preprocessRelative,
  9224. exact: preprocessExact
  9225. });
  9226. };
  9227. var makeRange = function(start, soffset, finish, foffset) {
  9228. var doc = owner(start);
  9229. var rng = doc.dom.createRange();
  9230. rng.setStart(start.dom, soffset);
  9231. rng.setEnd(finish.dom, foffset);
  9232. return rng;
  9233. };
  9234. var after$2 = function(start, soffset, finish, foffset) {
  9235. var r2 = makeRange(start, soffset, finish, foffset);
  9236. var same = eq$1(start, finish) && soffset === foffset;
  9237. return r2.collapsed && !same;
  9238. };
  9239. var getNativeSelection = function(win) {
  9240. return Optional.from(win.getSelection());
  9241. };
  9242. var doSetNativeRange = function(win, rng) {
  9243. getNativeSelection(win).each(function(selection2) {
  9244. selection2.removeAllRanges();
  9245. selection2.addRange(rng);
  9246. });
  9247. };
  9248. var doSetRange = function(win, start, soffset, finish, foffset) {
  9249. var rng = exactToNative(win, start, soffset, finish, foffset);
  9250. doSetNativeRange(win, rng);
  9251. };
  9252. var setLegacyRtlRange = function(win, selection2, start, soffset, finish, foffset) {
  9253. selection2.collapse(start.dom, soffset);
  9254. selection2.extend(finish.dom, foffset);
  9255. };
  9256. var setRangeFromRelative = function(win, relative2) {
  9257. return diagnose(win, relative2).match({
  9258. ltr: function(start, soffset, finish, foffset) {
  9259. doSetRange(win, start, soffset, finish, foffset);
  9260. },
  9261. rtl: function(start, soffset, finish, foffset) {
  9262. getNativeSelection(win).each(function(selection2) {
  9263. if (selection2.setBaseAndExtent) {
  9264. selection2.setBaseAndExtent(start.dom, soffset, finish.dom, foffset);
  9265. } else if (selection2.extend) {
  9266. try {
  9267. setLegacyRtlRange(win, selection2, start, soffset, finish, foffset);
  9268. } catch (e) {
  9269. doSetRange(win, finish, foffset, start, soffset);
  9270. }
  9271. } else {
  9272. doSetRange(win, finish, foffset, start, soffset);
  9273. }
  9274. });
  9275. }
  9276. });
  9277. };
  9278. var setExact = function(win, start, soffset, finish, foffset) {
  9279. var relative2 = preprocessExact(start, soffset, finish, foffset);
  9280. setRangeFromRelative(win, relative2);
  9281. };
  9282. var setRelative = function(win, startSitu, finishSitu) {
  9283. var relative2 = preprocessRelative(startSitu, finishSitu);
  9284. setRangeFromRelative(win, relative2);
  9285. };
  9286. var toNative = function(selection2) {
  9287. var win = SimSelection.getWin(selection2).dom;
  9288. var getDomRange = function(start, soffset, finish, foffset) {
  9289. return exactToNative(win, start, soffset, finish, foffset);
  9290. };
  9291. var filtered = preprocess(selection2);
  9292. return diagnose(win, filtered).match({
  9293. ltr: getDomRange,
  9294. rtl: getDomRange
  9295. });
  9296. };
  9297. var readRange = function(selection2) {
  9298. if (selection2.rangeCount > 0) {
  9299. var firstRng = selection2.getRangeAt(0);
  9300. var lastRng = selection2.getRangeAt(selection2.rangeCount - 1);
  9301. return Optional.some(SimRange.create(SugarElement.fromDom(firstRng.startContainer), firstRng.startOffset, SugarElement.fromDom(lastRng.endContainer), lastRng.endOffset));
  9302. } else {
  9303. return Optional.none();
  9304. }
  9305. };
  9306. var doGetExact = function(selection2) {
  9307. if (selection2.anchorNode === null || selection2.focusNode === null) {
  9308. return readRange(selection2);
  9309. } else {
  9310. var anchor = SugarElement.fromDom(selection2.anchorNode);
  9311. var focus_1 = SugarElement.fromDom(selection2.focusNode);
  9312. return after$2(anchor, selection2.anchorOffset, focus_1, selection2.focusOffset) ? Optional.some(SimRange.create(anchor, selection2.anchorOffset, focus_1, selection2.focusOffset)) : readRange(selection2);
  9313. }
  9314. };
  9315. var setToElement = function(win, element, selectNodeContents$1) {
  9316. if (selectNodeContents$1 === void 0) {
  9317. selectNodeContents$1 = true;
  9318. }
  9319. var rngGetter = selectNodeContents$1 ? selectNodeContents : selectNode;
  9320. var rng = rngGetter(win, element);
  9321. doSetNativeRange(win, rng);
  9322. };
  9323. var getExact = function(win) {
  9324. return getNativeSelection(win).filter(function(sel) {
  9325. return sel.rangeCount > 0;
  9326. }).bind(doGetExact);
  9327. };
  9328. var get$1 = function(win) {
  9329. return getExact(win).map(function(range2) {
  9330. return SimSelection.exact(range2.start, range2.soffset, range2.finish, range2.foffset);
  9331. });
  9332. };
  9333. var getFirstRect = function(win, selection2) {
  9334. var rng = asLtrRange(win, selection2);
  9335. return getFirstRect$1(rng);
  9336. };
  9337. var getAtPoint = function(win, x, y) {
  9338. return fromPoint(win, x, y);
  9339. };
  9340. var clear = function(win) {
  9341. getNativeSelection(win).each(function(selection2) {
  9342. return selection2.removeAllRanges();
  9343. });
  9344. };
  9345. var global$1 = tinymce.util.Tools.resolve("tinymce.util.VK");
  9346. var forward = function(editor, isRoot, cell2) {
  9347. return go$1(editor, isRoot, next(cell2, isEditable$1));
  9348. };
  9349. var backward = function(editor, isRoot, cell2) {
  9350. return go$1(editor, isRoot, prev(cell2, isEditable$1));
  9351. };
  9352. var getCellFirstCursorPosition = function(editor, cell2) {
  9353. var selection2 = SimSelection.exact(cell2, 0, cell2, 0);
  9354. return toNative(selection2);
  9355. };
  9356. var go$1 = function(editor, isRoot, cell2) {
  9357. return cell2.fold(Optional.none, Optional.none, function(current, next2) {
  9358. return first(next2).map(function(cell3) {
  9359. return getCellFirstCursorPosition(editor, cell3);
  9360. });
  9361. }, function(current) {
  9362. editor.execCommand("mceTableInsertRowAfter");
  9363. return forward(editor, isRoot, current);
  9364. });
  9365. };
  9366. var rootElements = [
  9367. "table",
  9368. "li",
  9369. "dl"
  9370. ];
  9371. var handle$1 = function(event, editor, cellSelection) {
  9372. if (event.keyCode === global$1.TAB) {
  9373. var body_1 = getBody(editor);
  9374. var isRoot_1 = function(element) {
  9375. var name$1 = name(element);
  9376. return eq$1(element, body_1) || contains$2(rootElements, name$1);
  9377. };
  9378. var rng = editor.selection.getRng();
  9379. var container = SugarElement.fromDom(event.shiftKey ? rng.startContainer : rng.endContainer);
  9380. cell(container, isRoot_1).each(function(cell2) {
  9381. event.preventDefault();
  9382. table(cell2, isRoot_1).each(cellSelection.clear);
  9383. editor.selection.collapse(event.shiftKey);
  9384. var navigation = event.shiftKey ? backward : forward;
  9385. var rng2 = navigation(editor, isRoot_1, cell2);
  9386. rng2.each(function(range2) {
  9387. editor.selection.setRng(range2);
  9388. });
  9389. });
  9390. }
  9391. };
  9392. var create$1 = function(selection2, kill) {
  9393. return {
  9394. selection: selection2,
  9395. kill
  9396. };
  9397. };
  9398. var Response = { create: create$1 };
  9399. var create = function(start, soffset, finish, foffset) {
  9400. return {
  9401. start: Situ.on(start, soffset),
  9402. finish: Situ.on(finish, foffset)
  9403. };
  9404. };
  9405. var Situs = { create };
  9406. var convertToRange = function(win, selection2) {
  9407. var rng = asLtrRange(win, selection2);
  9408. return SimRange.create(SugarElement.fromDom(rng.startContainer), rng.startOffset, SugarElement.fromDom(rng.endContainer), rng.endOffset);
  9409. };
  9410. var makeSitus = Situs.create;
  9411. var sync = function(container, isRoot, start, soffset, finish, foffset, selectRange) {
  9412. if (!(eq$1(start, finish) && soffset === foffset)) {
  9413. return closest$1(start, "td,th", isRoot).bind(function(s) {
  9414. return closest$1(finish, "td,th", isRoot).bind(function(f) {
  9415. return detect(container, isRoot, s, f, selectRange);
  9416. });
  9417. });
  9418. } else {
  9419. return Optional.none();
  9420. }
  9421. };
  9422. var detect = function(container, isRoot, start, finish, selectRange) {
  9423. if (!eq$1(start, finish)) {
  9424. return identify(start, finish, isRoot).bind(function(cellSel) {
  9425. var boxes = cellSel.boxes.getOr([]);
  9426. if (boxes.length > 1) {
  9427. selectRange(container, boxes, cellSel.start, cellSel.finish);
  9428. return Optional.some(Response.create(Optional.some(makeSitus(start, 0, start, getEnd(start))), true));
  9429. } else {
  9430. return Optional.none();
  9431. }
  9432. });
  9433. } else {
  9434. return Optional.none();
  9435. }
  9436. };
  9437. var update = function(rows2, columns2, container, selected, annotations) {
  9438. var updateSelection = function(newSels) {
  9439. annotations.clearBeforeUpdate(container);
  9440. annotations.selectRange(container, newSels.boxes, newSels.start, newSels.finish);
  9441. return newSels.boxes;
  9442. };
  9443. return shiftSelection(selected, rows2, columns2, annotations.firstSelectedSelector, annotations.lastSelectedSelector).map(updateSelection);
  9444. };
  9445. var traverse = function(item, mode) {
  9446. return {
  9447. item,
  9448. mode
  9449. };
  9450. };
  9451. var backtrack = function(universe2, item, _direction, transition) {
  9452. if (transition === void 0) {
  9453. transition = sidestep;
  9454. }
  9455. return universe2.property().parent(item).map(function(p) {
  9456. return traverse(p, transition);
  9457. });
  9458. };
  9459. var sidestep = function(universe2, item, direction, transition) {
  9460. if (transition === void 0) {
  9461. transition = advance;
  9462. }
  9463. return direction.sibling(universe2, item).map(function(p) {
  9464. return traverse(p, transition);
  9465. });
  9466. };
  9467. var advance = function(universe2, item, direction, transition) {
  9468. if (transition === void 0) {
  9469. transition = advance;
  9470. }
  9471. var children2 = universe2.property().children(item);
  9472. var result = direction.first(children2);
  9473. return result.map(function(r2) {
  9474. return traverse(r2, transition);
  9475. });
  9476. };
  9477. var successors = [
  9478. {
  9479. current: backtrack,
  9480. next: sidestep,
  9481. fallback: Optional.none()
  9482. },
  9483. {
  9484. current: sidestep,
  9485. next: advance,
  9486. fallback: Optional.some(backtrack)
  9487. },
  9488. {
  9489. current: advance,
  9490. next: advance,
  9491. fallback: Optional.some(sidestep)
  9492. }
  9493. ];
  9494. var go = function(universe2, item, mode, direction, rules) {
  9495. if (rules === void 0) {
  9496. rules = successors;
  9497. }
  9498. var ruleOpt = find$1(rules, function(succ) {
  9499. return succ.current === mode;
  9500. });
  9501. return ruleOpt.bind(function(rule) {
  9502. return rule.current(universe2, item, direction, rule.next).orThunk(function() {
  9503. return rule.fallback.bind(function(fb) {
  9504. return go(universe2, item, fb, direction);
  9505. });
  9506. });
  9507. });
  9508. };
  9509. var left$1 = function() {
  9510. var sibling = function(universe2, item) {
  9511. return universe2.query().prevSibling(item);
  9512. };
  9513. var first2 = function(children2) {
  9514. return children2.length > 0 ? Optional.some(children2[children2.length - 1]) : Optional.none();
  9515. };
  9516. return {
  9517. sibling,
  9518. first: first2
  9519. };
  9520. };
  9521. var right$1 = function() {
  9522. var sibling = function(universe2, item) {
  9523. return universe2.query().nextSibling(item);
  9524. };
  9525. var first2 = function(children2) {
  9526. return children2.length > 0 ? Optional.some(children2[0]) : Optional.none();
  9527. };
  9528. return {
  9529. sibling,
  9530. first: first2
  9531. };
  9532. };
  9533. var Walkers = {
  9534. left: left$1,
  9535. right: right$1
  9536. };
  9537. var hone = function(universe2, item, predicate, mode, direction, isRoot) {
  9538. var next2 = go(universe2, item, mode, direction);
  9539. return next2.bind(function(n) {
  9540. if (isRoot(n.item)) {
  9541. return Optional.none();
  9542. } else {
  9543. return predicate(n.item) ? Optional.some(n.item) : hone(universe2, n.item, predicate, n.mode, direction, isRoot);
  9544. }
  9545. });
  9546. };
  9547. var left = function(universe2, item, predicate, isRoot) {
  9548. return hone(universe2, item, predicate, sidestep, Walkers.left(), isRoot);
  9549. };
  9550. var right = function(universe2, item, predicate, isRoot) {
  9551. return hone(universe2, item, predicate, sidestep, Walkers.right(), isRoot);
  9552. };
  9553. var isLeaf = function(universe2) {
  9554. return function(element) {
  9555. return universe2.property().children(element).length === 0;
  9556. };
  9557. };
  9558. var before$1 = function(universe2, item, isRoot) {
  9559. return seekLeft$1(universe2, item, isLeaf(universe2), isRoot);
  9560. };
  9561. var after$1 = function(universe2, item, isRoot) {
  9562. return seekRight$1(universe2, item, isLeaf(universe2), isRoot);
  9563. };
  9564. var seekLeft$1 = left;
  9565. var seekRight$1 = right;
  9566. var universe = DomUniverse();
  9567. var before = function(element, isRoot) {
  9568. return before$1(universe, element, isRoot);
  9569. };
  9570. var after = function(element, isRoot) {
  9571. return after$1(universe, element, isRoot);
  9572. };
  9573. var seekLeft = function(element, predicate, isRoot) {
  9574. return seekLeft$1(universe, element, predicate, isRoot);
  9575. };
  9576. var seekRight = function(element, predicate, isRoot) {
  9577. return seekRight$1(universe, element, predicate, isRoot);
  9578. };
  9579. var ancestor = function(scope, predicate, isRoot) {
  9580. return ancestor$2(scope, predicate, isRoot).isSome();
  9581. };
  9582. var adt$1 = Adt.generate([
  9583. { none: ["message"] },
  9584. { success: [] },
  9585. { failedUp: ["cell"] },
  9586. { failedDown: ["cell"] }
  9587. ]);
  9588. var isOverlapping = function(bridge, before2, after2) {
  9589. var beforeBounds = bridge.getRect(before2);
  9590. var afterBounds = bridge.getRect(after2);
  9591. return afterBounds.right > beforeBounds.left && afterBounds.left < beforeBounds.right;
  9592. };
  9593. var isRow = function(elem) {
  9594. return closest$1(elem, "tr");
  9595. };
  9596. var verify = function(bridge, before2, beforeOffset, after2, afterOffset, failure, isRoot) {
  9597. return closest$1(after2, "td,th", isRoot).bind(function(afterCell) {
  9598. return closest$1(before2, "td,th", isRoot).map(function(beforeCell) {
  9599. if (!eq$1(afterCell, beforeCell)) {
  9600. return sharedOne(isRow, [
  9601. afterCell,
  9602. beforeCell
  9603. ]).fold(function() {
  9604. return isOverlapping(bridge, beforeCell, afterCell) ? adt$1.success() : failure(beforeCell);
  9605. }, function(_sharedRow) {
  9606. return failure(beforeCell);
  9607. });
  9608. } else {
  9609. return eq$1(after2, afterCell) && getEnd(afterCell) === afterOffset ? failure(beforeCell) : adt$1.none("in same cell");
  9610. }
  9611. });
  9612. }).getOr(adt$1.none("default"));
  9613. };
  9614. var cata = function(subject, onNone, onSuccess, onFailedUp, onFailedDown) {
  9615. return subject.fold(onNone, onSuccess, onFailedUp, onFailedDown);
  9616. };
  9617. var BeforeAfter = __assign(__assign({}, adt$1), {
  9618. verify,
  9619. cata
  9620. });
  9621. var inParent = function(parent2, children2, element, index) {
  9622. return {
  9623. parent: parent2,
  9624. children: children2,
  9625. element,
  9626. index
  9627. };
  9628. };
  9629. var indexInParent = function(element) {
  9630. return parent(element).bind(function(parent2) {
  9631. var children2 = children$3(parent2);
  9632. return indexOf(children2, element).map(function(index) {
  9633. return inParent(parent2, children2, element, index);
  9634. });
  9635. });
  9636. };
  9637. var indexOf = function(elements, element) {
  9638. return findIndex(elements, curry(eq$1, element));
  9639. };
  9640. var isBr = function(elem) {
  9641. return name(elem) === "br";
  9642. };
  9643. var gatherer = function(cand, gather, isRoot) {
  9644. return gather(cand, isRoot).bind(function(target) {
  9645. return isText(target) && get$9(target).trim().length === 0 ? gatherer(target, gather, isRoot) : Optional.some(target);
  9646. });
  9647. };
  9648. var handleBr = function(isRoot, element, direction) {
  9649. return direction.traverse(element).orThunk(function() {
  9650. return gatherer(element, direction.gather, isRoot);
  9651. }).map(direction.relative);
  9652. };
  9653. var findBr = function(element, offset) {
  9654. return child$3(element, offset).filter(isBr).orThunk(function() {
  9655. return child$3(element, offset - 1).filter(isBr);
  9656. });
  9657. };
  9658. var handleParent = function(isRoot, element, offset, direction) {
  9659. return findBr(element, offset).bind(function(br) {
  9660. return direction.traverse(br).fold(function() {
  9661. return gatherer(br, direction.gather, isRoot).map(direction.relative);
  9662. }, function(adjacent) {
  9663. return indexInParent(adjacent).map(function(info) {
  9664. return Situ.on(info.parent, info.index);
  9665. });
  9666. });
  9667. });
  9668. };
  9669. var tryBr = function(isRoot, element, offset, direction) {
  9670. var target = isBr(element) ? handleBr(isRoot, element, direction) : handleParent(isRoot, element, offset, direction);
  9671. return target.map(function(tgt) {
  9672. return {
  9673. start: tgt,
  9674. finish: tgt
  9675. };
  9676. });
  9677. };
  9678. var process = function(analysis) {
  9679. return BeforeAfter.cata(analysis, function(_message) {
  9680. return Optional.none();
  9681. }, function() {
  9682. return Optional.none();
  9683. }, function(cell2) {
  9684. return Optional.some(point(cell2, 0));
  9685. }, function(cell2) {
  9686. return Optional.some(point(cell2, getEnd(cell2)));
  9687. });
  9688. };
  9689. var moveDown = function(caret, amount) {
  9690. return {
  9691. left: caret.left,
  9692. top: caret.top + amount,
  9693. right: caret.right,
  9694. bottom: caret.bottom + amount
  9695. };
  9696. };
  9697. var moveUp = function(caret, amount) {
  9698. return {
  9699. left: caret.left,
  9700. top: caret.top - amount,
  9701. right: caret.right,
  9702. bottom: caret.bottom - amount
  9703. };
  9704. };
  9705. var translate = function(caret, xDelta, yDelta) {
  9706. return {
  9707. left: caret.left + xDelta,
  9708. top: caret.top + yDelta,
  9709. right: caret.right + xDelta,
  9710. bottom: caret.bottom + yDelta
  9711. };
  9712. };
  9713. var getTop = function(caret) {
  9714. return caret.top;
  9715. };
  9716. var getBottom = function(caret) {
  9717. return caret.bottom;
  9718. };
  9719. var getPartialBox = function(bridge, element, offset) {
  9720. if (offset >= 0 && offset < getEnd(element)) {
  9721. return bridge.getRangedRect(element, offset, element, offset + 1);
  9722. } else if (offset > 0) {
  9723. return bridge.getRangedRect(element, offset - 1, element, offset);
  9724. }
  9725. return Optional.none();
  9726. };
  9727. var toCaret = function(rect) {
  9728. return {
  9729. left: rect.left,
  9730. top: rect.top,
  9731. right: rect.right,
  9732. bottom: rect.bottom
  9733. };
  9734. };
  9735. var getElemBox = function(bridge, element) {
  9736. return Optional.some(bridge.getRect(element));
  9737. };
  9738. var getBoxAt = function(bridge, element, offset) {
  9739. if (isElement(element)) {
  9740. return getElemBox(bridge, element).map(toCaret);
  9741. } else if (isText(element)) {
  9742. return getPartialBox(bridge, element, offset).map(toCaret);
  9743. } else {
  9744. return Optional.none();
  9745. }
  9746. };
  9747. var getEntireBox = function(bridge, element) {
  9748. if (isElement(element)) {
  9749. return getElemBox(bridge, element).map(toCaret);
  9750. } else if (isText(element)) {
  9751. return bridge.getRangedRect(element, 0, element, getEnd(element)).map(toCaret);
  9752. } else {
  9753. return Optional.none();
  9754. }
  9755. };
  9756. var JUMP_SIZE = 5;
  9757. var NUM_RETRIES = 100;
  9758. var adt = Adt.generate([
  9759. { none: [] },
  9760. { retry: ["caret"] }
  9761. ]);
  9762. var isOutside = function(caret, box) {
  9763. return caret.left < box.left || Math.abs(box.right - caret.left) < 1 || caret.left > box.right;
  9764. };
  9765. var inOutsideBlock = function(bridge, element, caret) {
  9766. return closest$2(element, isBlock).fold(never, function(cell2) {
  9767. return getEntireBox(bridge, cell2).exists(function(box) {
  9768. return isOutside(caret, box);
  9769. });
  9770. });
  9771. };
  9772. var adjustDown = function(bridge, element, guessBox, original, caret) {
  9773. var lowerCaret = moveDown(caret, JUMP_SIZE);
  9774. if (Math.abs(guessBox.bottom - original.bottom) < 1) {
  9775. return adt.retry(lowerCaret);
  9776. } else if (guessBox.top > caret.bottom) {
  9777. return adt.retry(lowerCaret);
  9778. } else if (guessBox.top === caret.bottom) {
  9779. return adt.retry(moveDown(caret, 1));
  9780. } else {
  9781. return inOutsideBlock(bridge, element, caret) ? adt.retry(translate(lowerCaret, JUMP_SIZE, 0)) : adt.none();
  9782. }
  9783. };
  9784. var adjustUp = function(bridge, element, guessBox, original, caret) {
  9785. var higherCaret = moveUp(caret, JUMP_SIZE);
  9786. if (Math.abs(guessBox.top - original.top) < 1) {
  9787. return adt.retry(higherCaret);
  9788. } else if (guessBox.bottom < caret.top) {
  9789. return adt.retry(higherCaret);
  9790. } else if (guessBox.bottom === caret.top) {
  9791. return adt.retry(moveUp(caret, 1));
  9792. } else {
  9793. return inOutsideBlock(bridge, element, caret) ? adt.retry(translate(higherCaret, JUMP_SIZE, 0)) : adt.none();
  9794. }
  9795. };
  9796. var upMovement = {
  9797. point: getTop,
  9798. adjuster: adjustUp,
  9799. move: moveUp,
  9800. gather: before
  9801. };
  9802. var downMovement = {
  9803. point: getBottom,
  9804. adjuster: adjustDown,
  9805. move: moveDown,
  9806. gather: after
  9807. };
  9808. var isAtTable = function(bridge, x, y) {
  9809. return bridge.elementFromPoint(x, y).filter(function(elm) {
  9810. return name(elm) === "table";
  9811. }).isSome();
  9812. };
  9813. var adjustForTable = function(bridge, movement, original, caret, numRetries) {
  9814. return adjustTil(bridge, movement, original, movement.move(caret, JUMP_SIZE), numRetries);
  9815. };
  9816. var adjustTil = function(bridge, movement, original, caret, numRetries) {
  9817. if (numRetries === 0) {
  9818. return Optional.some(caret);
  9819. }
  9820. if (isAtTable(bridge, caret.left, movement.point(caret))) {
  9821. return adjustForTable(bridge, movement, original, caret, numRetries - 1);
  9822. }
  9823. return bridge.situsFromPoint(caret.left, movement.point(caret)).bind(function(guess) {
  9824. return guess.start.fold(Optional.none, function(element) {
  9825. return getEntireBox(bridge, element).bind(function(guessBox) {
  9826. return movement.adjuster(bridge, element, guessBox, original, caret).fold(Optional.none, function(newCaret) {
  9827. return adjustTil(bridge, movement, original, newCaret, numRetries - 1);
  9828. });
  9829. }).orThunk(function() {
  9830. return Optional.some(caret);
  9831. });
  9832. }, Optional.none);
  9833. });
  9834. };
  9835. var ieTryDown = function(bridge, caret) {
  9836. return bridge.situsFromPoint(caret.left, caret.bottom + JUMP_SIZE);
  9837. };
  9838. var ieTryUp = function(bridge, caret) {
  9839. return bridge.situsFromPoint(caret.left, caret.top - JUMP_SIZE);
  9840. };
  9841. var checkScroll = function(movement, adjusted, bridge) {
  9842. if (movement.point(adjusted) > bridge.getInnerHeight()) {
  9843. return Optional.some(movement.point(adjusted) - bridge.getInnerHeight());
  9844. } else if (movement.point(adjusted) < 0) {
  9845. return Optional.some(-movement.point(adjusted));
  9846. } else {
  9847. return Optional.none();
  9848. }
  9849. };
  9850. var retry = function(movement, bridge, caret) {
  9851. var moved = movement.move(caret, JUMP_SIZE);
  9852. var adjusted = adjustTil(bridge, movement, caret, moved, NUM_RETRIES).getOr(moved);
  9853. return checkScroll(movement, adjusted, bridge).fold(function() {
  9854. return bridge.situsFromPoint(adjusted.left, movement.point(adjusted));
  9855. }, function(delta) {
  9856. bridge.scrollBy(0, delta);
  9857. return bridge.situsFromPoint(adjusted.left, movement.point(adjusted) - delta);
  9858. });
  9859. };
  9860. var Retries = {
  9861. tryUp: curry(retry, upMovement),
  9862. tryDown: curry(retry, downMovement),
  9863. ieTryUp,
  9864. ieTryDown,
  9865. getJumpSize: constant(JUMP_SIZE)
  9866. };
  9867. var MAX_RETRIES = 20;
  9868. var findSpot = function(bridge, isRoot, direction) {
  9869. return bridge.getSelection().bind(function(sel) {
  9870. return tryBr(isRoot, sel.finish, sel.foffset, direction).fold(function() {
  9871. return Optional.some(point(sel.finish, sel.foffset));
  9872. }, function(brNeighbour) {
  9873. var range2 = bridge.fromSitus(brNeighbour);
  9874. var analysis = BeforeAfter.verify(bridge, sel.finish, sel.foffset, range2.finish, range2.foffset, direction.failure, isRoot);
  9875. return process(analysis);
  9876. });
  9877. });
  9878. };
  9879. var scan = function(bridge, isRoot, element, offset, direction, numRetries) {
  9880. if (numRetries === 0) {
  9881. return Optional.none();
  9882. }
  9883. return tryCursor(bridge, isRoot, element, offset, direction).bind(function(situs) {
  9884. var range2 = bridge.fromSitus(situs);
  9885. var analysis = BeforeAfter.verify(bridge, element, offset, range2.finish, range2.foffset, direction.failure, isRoot);
  9886. return BeforeAfter.cata(analysis, function() {
  9887. return Optional.none();
  9888. }, function() {
  9889. return Optional.some(situs);
  9890. }, function(cell2) {
  9891. if (eq$1(element, cell2) && offset === 0) {
  9892. return tryAgain(bridge, element, offset, moveUp, direction);
  9893. } else {
  9894. return scan(bridge, isRoot, cell2, 0, direction, numRetries - 1);
  9895. }
  9896. }, function(cell2) {
  9897. if (eq$1(element, cell2) && offset === getEnd(cell2)) {
  9898. return tryAgain(bridge, element, offset, moveDown, direction);
  9899. } else {
  9900. return scan(bridge, isRoot, cell2, getEnd(cell2), direction, numRetries - 1);
  9901. }
  9902. });
  9903. });
  9904. };
  9905. var tryAgain = function(bridge, element, offset, move, direction) {
  9906. return getBoxAt(bridge, element, offset).bind(function(box) {
  9907. return tryAt(bridge, direction, move(box, Retries.getJumpSize()));
  9908. });
  9909. };
  9910. var tryAt = function(bridge, direction, box) {
  9911. var browser = detect$3().browser;
  9912. if (browser.isChrome() || browser.isSafari() || browser.isFirefox() || browser.isEdge()) {
  9913. return direction.otherRetry(bridge, box);
  9914. } else if (browser.isIE()) {
  9915. return direction.ieRetry(bridge, box);
  9916. } else {
  9917. return Optional.none();
  9918. }
  9919. };
  9920. var tryCursor = function(bridge, isRoot, element, offset, direction) {
  9921. return getBoxAt(bridge, element, offset).bind(function(box) {
  9922. return tryAt(bridge, direction, box);
  9923. });
  9924. };
  9925. var handle = function(bridge, isRoot, direction) {
  9926. return findSpot(bridge, isRoot, direction).bind(function(spot) {
  9927. return scan(bridge, isRoot, spot.element, spot.offset, direction, MAX_RETRIES).map(bridge.fromSitus);
  9928. });
  9929. };
  9930. var inSameTable = function(elem, table2) {
  9931. return ancestor(elem, function(e) {
  9932. return parent(e).exists(function(p) {
  9933. return eq$1(p, table2);
  9934. });
  9935. });
  9936. };
  9937. var simulate = function(bridge, isRoot, direction, initial, anchor) {
  9938. return closest$1(initial, "td,th", isRoot).bind(function(start) {
  9939. return closest$1(start, "table", isRoot).bind(function(table2) {
  9940. if (!inSameTable(anchor, table2)) {
  9941. return Optional.none();
  9942. }
  9943. return handle(bridge, isRoot, direction).bind(function(range2) {
  9944. return closest$1(range2.finish, "td,th", isRoot).map(function(finish) {
  9945. return {
  9946. start,
  9947. finish,
  9948. range: range2
  9949. };
  9950. });
  9951. });
  9952. });
  9953. });
  9954. };
  9955. var navigate = function(bridge, isRoot, direction, initial, anchor, precheck) {
  9956. if (detect$3().browser.isIE()) {
  9957. return Optional.none();
  9958. } else {
  9959. return precheck(initial, isRoot).orThunk(function() {
  9960. return simulate(bridge, isRoot, direction, initial, anchor).map(function(info) {
  9961. var range2 = info.range;
  9962. return Response.create(Optional.some(makeSitus(range2.start, range2.soffset, range2.finish, range2.foffset)), true);
  9963. });
  9964. });
  9965. }
  9966. };
  9967. var firstUpCheck = function(initial, isRoot) {
  9968. return closest$1(initial, "tr", isRoot).bind(function(startRow) {
  9969. return closest$1(startRow, "table", isRoot).bind(function(table2) {
  9970. var rows2 = descendants(table2, "tr");
  9971. if (eq$1(startRow, rows2[0])) {
  9972. return seekLeft(table2, function(element) {
  9973. return last$1(element).isSome();
  9974. }, isRoot).map(function(last2) {
  9975. var lastOffset = getEnd(last2);
  9976. return Response.create(Optional.some(makeSitus(last2, lastOffset, last2, lastOffset)), true);
  9977. });
  9978. } else {
  9979. return Optional.none();
  9980. }
  9981. });
  9982. });
  9983. };
  9984. var lastDownCheck = function(initial, isRoot) {
  9985. return closest$1(initial, "tr", isRoot).bind(function(startRow) {
  9986. return closest$1(startRow, "table", isRoot).bind(function(table2) {
  9987. var rows2 = descendants(table2, "tr");
  9988. if (eq$1(startRow, rows2[rows2.length - 1])) {
  9989. return seekRight(table2, function(element) {
  9990. return first(element).isSome();
  9991. }, isRoot).map(function(first2) {
  9992. return Response.create(Optional.some(makeSitus(first2, 0, first2, 0)), true);
  9993. });
  9994. } else {
  9995. return Optional.none();
  9996. }
  9997. });
  9998. });
  9999. };
  10000. var select = function(bridge, container, isRoot, direction, initial, anchor, selectRange) {
  10001. return simulate(bridge, isRoot, direction, initial, anchor).bind(function(info) {
  10002. return detect(container, isRoot, info.start, info.finish, selectRange);
  10003. });
  10004. };
  10005. var findCell = function(target, isRoot) {
  10006. return closest$1(target, "td,th", isRoot);
  10007. };
  10008. var MouseSelection = function(bridge, container, isRoot, annotations) {
  10009. var cursor = value();
  10010. var clearstate = cursor.clear;
  10011. var applySelection = function(event) {
  10012. cursor.on(function(start) {
  10013. annotations.clearBeforeUpdate(container);
  10014. findCell(event.target, isRoot).each(function(finish) {
  10015. identify(start, finish, isRoot).each(function(cellSel) {
  10016. var boxes = cellSel.boxes.getOr([]);
  10017. if (boxes.length === 1) {
  10018. var singleCell = boxes[0];
  10019. var isNonEditableCell = getRaw(singleCell) === "false";
  10020. var isCellClosestContentEditable = is(closest(event.target), singleCell, eq$1);
  10021. if (isNonEditableCell && isCellClosestContentEditable) {
  10022. annotations.selectRange(container, boxes, singleCell, singleCell);
  10023. bridge.selectContents(singleCell);
  10024. }
  10025. } else if (boxes.length > 1) {
  10026. annotations.selectRange(container, boxes, cellSel.start, cellSel.finish);
  10027. bridge.selectContents(finish);
  10028. }
  10029. });
  10030. });
  10031. });
  10032. };
  10033. var mousedown = function(event) {
  10034. annotations.clear(container);
  10035. findCell(event.target, isRoot).each(cursor.set);
  10036. };
  10037. var mouseover = function(event) {
  10038. applySelection(event);
  10039. };
  10040. var mouseup = function(event) {
  10041. applySelection(event);
  10042. clearstate();
  10043. };
  10044. return {
  10045. clearstate,
  10046. mousedown,
  10047. mouseover,
  10048. mouseup
  10049. };
  10050. };
  10051. var down = {
  10052. traverse: nextSibling,
  10053. gather: after,
  10054. relative: Situ.before,
  10055. otherRetry: Retries.tryDown,
  10056. ieRetry: Retries.ieTryDown,
  10057. failure: BeforeAfter.failedDown
  10058. };
  10059. var up = {
  10060. traverse: prevSibling,
  10061. gather: before,
  10062. relative: Situ.before,
  10063. otherRetry: Retries.tryUp,
  10064. ieRetry: Retries.ieTryUp,
  10065. failure: BeforeAfter.failedUp
  10066. };
  10067. var isKey = function(key2) {
  10068. return function(keycode) {
  10069. return keycode === key2;
  10070. };
  10071. };
  10072. var isUp = isKey(38);
  10073. var isDown = isKey(40);
  10074. var isNavigation = function(keycode) {
  10075. return keycode >= 37 && keycode <= 40;
  10076. };
  10077. var ltr = {
  10078. isBackward: isKey(37),
  10079. isForward: isKey(39)
  10080. };
  10081. var rtl = {
  10082. isBackward: isKey(39),
  10083. isForward: isKey(37)
  10084. };
  10085. var get = function(_DOC) {
  10086. var doc = _DOC !== void 0 ? _DOC.dom : document;
  10087. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  10088. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  10089. return SugarPosition(x, y);
  10090. };
  10091. var by = function(x, y, _DOC) {
  10092. var doc = _DOC !== void 0 ? _DOC.dom : document;
  10093. var win = doc.defaultView;
  10094. if (win) {
  10095. win.scrollBy(x, y);
  10096. }
  10097. };
  10098. var WindowBridge = function(win) {
  10099. var elementFromPoint = function(x, y) {
  10100. return SugarElement.fromPoint(SugarElement.fromDom(win.document), x, y);
  10101. };
  10102. var getRect = function(element) {
  10103. return element.dom.getBoundingClientRect();
  10104. };
  10105. var getRangedRect = function(start, soffset, finish, foffset) {
  10106. var sel = SimSelection.exact(start, soffset, finish, foffset);
  10107. return getFirstRect(win, sel);
  10108. };
  10109. var getSelection = function() {
  10110. return get$1(win).map(function(exactAdt) {
  10111. return convertToRange(win, exactAdt);
  10112. });
  10113. };
  10114. var fromSitus = function(situs) {
  10115. var relative2 = SimSelection.relative(situs.start, situs.finish);
  10116. return convertToRange(win, relative2);
  10117. };
  10118. var situsFromPoint = function(x, y) {
  10119. return getAtPoint(win, x, y).map(function(exact2) {
  10120. return Situs.create(exact2.start, exact2.soffset, exact2.finish, exact2.foffset);
  10121. });
  10122. };
  10123. var clearSelection = function() {
  10124. clear(win);
  10125. };
  10126. var collapseSelection = function(toStart) {
  10127. if (toStart === void 0) {
  10128. toStart = false;
  10129. }
  10130. get$1(win).each(function(sel) {
  10131. return sel.fold(function(rng) {
  10132. return rng.collapse(toStart);
  10133. }, function(startSitu, finishSitu) {
  10134. var situ = toStart ? startSitu : finishSitu;
  10135. setRelative(win, situ, situ);
  10136. }, function(start, soffset, finish, foffset) {
  10137. var node = toStart ? start : finish;
  10138. var offset = toStart ? soffset : foffset;
  10139. setExact(win, node, offset, node, offset);
  10140. });
  10141. });
  10142. };
  10143. var selectNode2 = function(element) {
  10144. setToElement(win, element, false);
  10145. };
  10146. var selectContents = function(element) {
  10147. setToElement(win, element);
  10148. };
  10149. var setSelection = function(sel) {
  10150. setExact(win, sel.start, sel.soffset, sel.finish, sel.foffset);
  10151. };
  10152. var setRelativeSelection = function(start, finish) {
  10153. setRelative(win, start, finish);
  10154. };
  10155. var getInnerHeight = function() {
  10156. return win.innerHeight;
  10157. };
  10158. var getScrollY = function() {
  10159. var pos = get(SugarElement.fromDom(win.document));
  10160. return pos.top;
  10161. };
  10162. var scrollBy = function(x, y) {
  10163. by(x, y, SugarElement.fromDom(win.document));
  10164. };
  10165. return {
  10166. elementFromPoint,
  10167. getRect,
  10168. getRangedRect,
  10169. getSelection,
  10170. fromSitus,
  10171. situsFromPoint,
  10172. clearSelection,
  10173. collapseSelection,
  10174. setSelection,
  10175. setRelativeSelection,
  10176. selectNode: selectNode2,
  10177. selectContents,
  10178. getInnerHeight,
  10179. getScrollY,
  10180. scrollBy
  10181. };
  10182. };
  10183. var rc = function(rows2, cols) {
  10184. return {
  10185. rows: rows2,
  10186. cols
  10187. };
  10188. };
  10189. var mouse = function(win, container, isRoot, annotations) {
  10190. var bridge = WindowBridge(win);
  10191. var handlers = MouseSelection(bridge, container, isRoot, annotations);
  10192. return {
  10193. clearstate: handlers.clearstate,
  10194. mousedown: handlers.mousedown,
  10195. mouseover: handlers.mouseover,
  10196. mouseup: handlers.mouseup
  10197. };
  10198. };
  10199. var keyboard = function(win, container, isRoot, annotations) {
  10200. var bridge = WindowBridge(win);
  10201. var clearToNavigate = function() {
  10202. annotations.clear(container);
  10203. return Optional.none();
  10204. };
  10205. var keydown = function(event, start, soffset, finish, foffset, direction) {
  10206. var realEvent = event.raw;
  10207. var keycode = realEvent.which;
  10208. var shiftKey = realEvent.shiftKey === true;
  10209. var handler = retrieve$1(container, annotations.selectedSelector).fold(function() {
  10210. if (isNavigation(keycode) && !shiftKey) {
  10211. annotations.clearBeforeUpdate(container);
  10212. }
  10213. if (isDown(keycode) && shiftKey) {
  10214. return curry(select, bridge, container, isRoot, down, finish, start, annotations.selectRange);
  10215. } else if (isUp(keycode) && shiftKey) {
  10216. return curry(select, bridge, container, isRoot, up, finish, start, annotations.selectRange);
  10217. } else if (isDown(keycode)) {
  10218. return curry(navigate, bridge, isRoot, down, finish, start, lastDownCheck);
  10219. } else if (isUp(keycode)) {
  10220. return curry(navigate, bridge, isRoot, up, finish, start, firstUpCheck);
  10221. } else {
  10222. return Optional.none;
  10223. }
  10224. }, function(selected) {
  10225. var update$1 = function(attempts) {
  10226. return function() {
  10227. var navigation = findMap(attempts, function(delta) {
  10228. return update(delta.rows, delta.cols, container, selected, annotations);
  10229. });
  10230. return navigation.fold(function() {
  10231. return getEdges(container, annotations.firstSelectedSelector, annotations.lastSelectedSelector).map(function(edges) {
  10232. var relative2 = isDown(keycode) || direction.isForward(keycode) ? Situ.after : Situ.before;
  10233. bridge.setRelativeSelection(Situ.on(edges.first, 0), relative2(edges.table));
  10234. annotations.clear(container);
  10235. return Response.create(Optional.none(), true);
  10236. });
  10237. }, function(_) {
  10238. return Optional.some(Response.create(Optional.none(), true));
  10239. });
  10240. };
  10241. };
  10242. if (isDown(keycode) && shiftKey) {
  10243. return update$1([rc(1, 0)]);
  10244. } else if (isUp(keycode) && shiftKey) {
  10245. return update$1([rc(-1, 0)]);
  10246. } else if (direction.isBackward(keycode) && shiftKey) {
  10247. return update$1([
  10248. rc(0, -1),
  10249. rc(-1, 0)
  10250. ]);
  10251. } else if (direction.isForward(keycode) && shiftKey) {
  10252. return update$1([
  10253. rc(0, 1),
  10254. rc(1, 0)
  10255. ]);
  10256. } else if (isNavigation(keycode) && !shiftKey) {
  10257. return clearToNavigate;
  10258. } else {
  10259. return Optional.none;
  10260. }
  10261. });
  10262. return handler();
  10263. };
  10264. var keyup = function(event, start, soffset, finish, foffset) {
  10265. return retrieve$1(container, annotations.selectedSelector).fold(function() {
  10266. var realEvent = event.raw;
  10267. var keycode = realEvent.which;
  10268. var shiftKey = realEvent.shiftKey === true;
  10269. if (!shiftKey) {
  10270. return Optional.none();
  10271. }
  10272. if (isNavigation(keycode)) {
  10273. return sync(container, isRoot, start, soffset, finish, foffset, annotations.selectRange);
  10274. } else {
  10275. return Optional.none();
  10276. }
  10277. }, Optional.none);
  10278. };
  10279. return {
  10280. keydown,
  10281. keyup
  10282. };
  10283. };
  10284. var external = function(win, container, isRoot, annotations) {
  10285. var bridge = WindowBridge(win);
  10286. return function(start, finish) {
  10287. annotations.clearBeforeUpdate(container);
  10288. identify(start, finish, isRoot).each(function(cellSel) {
  10289. var boxes = cellSel.boxes.getOr([]);
  10290. annotations.selectRange(container, boxes, cellSel.start, cellSel.finish);
  10291. bridge.selectContents(finish);
  10292. bridge.collapseSelection();
  10293. });
  10294. };
  10295. };
  10296. var remove = function(element, classes) {
  10297. each$2(classes, function(x) {
  10298. remove$2(element, x);
  10299. });
  10300. };
  10301. var addClass = function(clazz) {
  10302. return function(element) {
  10303. add(element, clazz);
  10304. };
  10305. };
  10306. var removeClasses = function(classes) {
  10307. return function(element) {
  10308. remove(element, classes);
  10309. };
  10310. };
  10311. var byClass = function(ephemera2) {
  10312. var addSelectionClass = addClass(ephemera2.selected);
  10313. var removeSelectionClasses = removeClasses([
  10314. ephemera2.selected,
  10315. ephemera2.lastSelected,
  10316. ephemera2.firstSelected
  10317. ]);
  10318. var clear2 = function(container) {
  10319. var sels = descendants(container, ephemera2.selectedSelector);
  10320. each$2(sels, removeSelectionClasses);
  10321. };
  10322. var selectRange = function(container, cells2, start, finish) {
  10323. clear2(container);
  10324. each$2(cells2, addSelectionClass);
  10325. add(start, ephemera2.firstSelected);
  10326. add(finish, ephemera2.lastSelected);
  10327. };
  10328. return {
  10329. clearBeforeUpdate: clear2,
  10330. clear: clear2,
  10331. selectRange,
  10332. selectedSelector: ephemera2.selectedSelector,
  10333. firstSelectedSelector: ephemera2.firstSelectedSelector,
  10334. lastSelectedSelector: ephemera2.lastSelectedSelector
  10335. };
  10336. };
  10337. var byAttr = function(ephemera2, onSelection, onClear) {
  10338. var removeSelectionAttributes = function(element) {
  10339. remove$7(element, ephemera2.selected);
  10340. remove$7(element, ephemera2.firstSelected);
  10341. remove$7(element, ephemera2.lastSelected);
  10342. };
  10343. var addSelectionAttribute = function(element) {
  10344. set$2(element, ephemera2.selected, "1");
  10345. };
  10346. var clear2 = function(container) {
  10347. clearBeforeUpdate(container);
  10348. onClear();
  10349. };
  10350. var clearBeforeUpdate = function(container) {
  10351. var sels = descendants(container, ephemera2.selectedSelector + "," + ephemera2.firstSelectedSelector + "," + ephemera2.lastSelectedSelector);
  10352. each$2(sels, removeSelectionAttributes);
  10353. };
  10354. var selectRange = function(container, cells2, start, finish) {
  10355. clear2(container);
  10356. each$2(cells2, addSelectionAttribute);
  10357. set$2(start, ephemera2.firstSelected, "1");
  10358. set$2(finish, ephemera2.lastSelected, "1");
  10359. onSelection(cells2, start, finish);
  10360. };
  10361. return {
  10362. clearBeforeUpdate,
  10363. clear: clear2,
  10364. selectRange,
  10365. selectedSelector: ephemera2.selectedSelector,
  10366. firstSelectedSelector: ephemera2.firstSelectedSelector,
  10367. lastSelectedSelector: ephemera2.lastSelectedSelector
  10368. };
  10369. };
  10370. var SelectionAnnotation = {
  10371. byClass,
  10372. byAttr
  10373. };
  10374. var getUpOrLeftCells = function(grid2, selectedCells) {
  10375. var upGrid = grid2.slice(0, selectedCells[selectedCells.length - 1].row + 1);
  10376. var upDetails = toDetailList(upGrid);
  10377. return bind$2(upDetails, function(detail2) {
  10378. var slicedCells = detail2.cells.slice(0, selectedCells[selectedCells.length - 1].column + 1);
  10379. return map$1(slicedCells, function(cell2) {
  10380. return cell2.element;
  10381. });
  10382. });
  10383. };
  10384. var getDownOrRightCells = function(grid2, selectedCells) {
  10385. var downGrid = grid2.slice(selectedCells[0].row + selectedCells[0].rowspan - 1, grid2.length);
  10386. var downDetails = toDetailList(downGrid);
  10387. return bind$2(downDetails, function(detail2) {
  10388. var slicedCells = detail2.cells.slice(selectedCells[0].column + selectedCells[0].colspan - 1, detail2.cells.length);
  10389. return map$1(slicedCells, function(cell2) {
  10390. return cell2.element;
  10391. });
  10392. });
  10393. };
  10394. var getOtherCells = function(table2, target, generators) {
  10395. var warehouse = Warehouse.fromTable(table2);
  10396. var details = onCells(warehouse, target);
  10397. return details.map(function(selectedCells) {
  10398. var grid2 = toGrid(warehouse, generators, false);
  10399. var upOrLeftCells = getUpOrLeftCells(grid2, selectedCells);
  10400. var downOrRightCells = getDownOrRightCells(grid2, selectedCells);
  10401. return {
  10402. upOrLeftCells,
  10403. downOrRightCells
  10404. };
  10405. });
  10406. };
  10407. var global = tinymce.util.Tools.resolve("tinymce.Env");
  10408. var hasInternalTarget = function(e) {
  10409. return has(SugarElement.fromDom(e.target), "ephox-snooker-resizer-bar") === false;
  10410. };
  10411. function CellSelection(editor, lazyResize, selectionTargets) {
  10412. var onSelection = function(cells2, start, finish) {
  10413. selectionTargets.targets().each(function(targets) {
  10414. var tableOpt = table(start);
  10415. tableOpt.each(function(table2) {
  10416. var cloneFormats2 = getCloneElements(editor);
  10417. var generators = cellOperations(noop, SugarElement.fromDom(editor.getDoc()), cloneFormats2);
  10418. var otherCells = getOtherCells(table2, targets, generators);
  10419. fireTableSelectionChange(editor, cells2, start, finish, otherCells);
  10420. });
  10421. });
  10422. };
  10423. var onClear = function() {
  10424. return fireTableSelectionClear(editor);
  10425. };
  10426. var annotations = SelectionAnnotation.byAttr(ephemera, onSelection, onClear);
  10427. editor.on("init", function(_e) {
  10428. var win = editor.getWin();
  10429. var body2 = getBody(editor);
  10430. var isRoot = getIsRoot(editor);
  10431. var syncSelection = function() {
  10432. var sel = editor.selection;
  10433. var start = SugarElement.fromDom(sel.getStart());
  10434. var end = SugarElement.fromDom(sel.getEnd());
  10435. var shared = sharedOne(table, [
  10436. start,
  10437. end
  10438. ]);
  10439. shared.fold(function() {
  10440. return annotations.clear(body2);
  10441. }, noop);
  10442. };
  10443. var mouseHandlers = mouse(win, body2, isRoot, annotations);
  10444. var keyHandlers = keyboard(win, body2, isRoot, annotations);
  10445. var external$1 = external(win, body2, isRoot, annotations);
  10446. var hasShiftKey = function(event) {
  10447. return event.raw.shiftKey === true;
  10448. };
  10449. editor.on("TableSelectorChange", function(e) {
  10450. return external$1(e.start, e.finish);
  10451. });
  10452. var handleResponse = function(event, response) {
  10453. if (!hasShiftKey(event)) {
  10454. return;
  10455. }
  10456. if (response.kill) {
  10457. event.kill();
  10458. }
  10459. response.selection.each(function(ns) {
  10460. var relative2 = SimSelection.relative(ns.start, ns.finish);
  10461. var rng = asLtrRange(win, relative2);
  10462. editor.selection.setRng(rng);
  10463. });
  10464. };
  10465. var keyup = function(event) {
  10466. var wrappedEvent = fromRawEvent(event);
  10467. if (wrappedEvent.raw.shiftKey && isNavigation(wrappedEvent.raw.which)) {
  10468. var rng = editor.selection.getRng();
  10469. var start = SugarElement.fromDom(rng.startContainer);
  10470. var end = SugarElement.fromDom(rng.endContainer);
  10471. keyHandlers.keyup(wrappedEvent, start, rng.startOffset, end, rng.endOffset).each(function(response) {
  10472. handleResponse(wrappedEvent, response);
  10473. });
  10474. }
  10475. };
  10476. var keydown = function(event) {
  10477. var wrappedEvent = fromRawEvent(event);
  10478. lazyResize().each(function(resize2) {
  10479. return resize2.hideBars();
  10480. });
  10481. var rng = editor.selection.getRng();
  10482. var start = SugarElement.fromDom(rng.startContainer);
  10483. var end = SugarElement.fromDom(rng.endContainer);
  10484. var direction = onDirection(ltr, rtl)(SugarElement.fromDom(editor.selection.getStart()));
  10485. keyHandlers.keydown(wrappedEvent, start, rng.startOffset, end, rng.endOffset, direction).each(function(response) {
  10486. handleResponse(wrappedEvent, response);
  10487. });
  10488. lazyResize().each(function(resize2) {
  10489. return resize2.showBars();
  10490. });
  10491. };
  10492. var isLeftMouse = function(raw) {
  10493. return raw.button === 0;
  10494. };
  10495. var isLeftButtonPressed = function(raw) {
  10496. if (raw.buttons === void 0) {
  10497. return true;
  10498. }
  10499. if (global.browser.isEdge() && raw.buttons === 0) {
  10500. return true;
  10501. }
  10502. return (raw.buttons & 1) !== 0;
  10503. };
  10504. var dragStart = function(_e2) {
  10505. mouseHandlers.clearstate();
  10506. };
  10507. var mouseDown = function(e) {
  10508. if (isLeftMouse(e) && hasInternalTarget(e)) {
  10509. mouseHandlers.mousedown(fromRawEvent(e));
  10510. }
  10511. };
  10512. var mouseOver = function(e) {
  10513. if (isLeftButtonPressed(e) && hasInternalTarget(e)) {
  10514. mouseHandlers.mouseover(fromRawEvent(e));
  10515. }
  10516. };
  10517. var mouseUp = function(e) {
  10518. if (isLeftMouse(e) && hasInternalTarget(e)) {
  10519. mouseHandlers.mouseup(fromRawEvent(e));
  10520. }
  10521. };
  10522. var getDoubleTap = function() {
  10523. var lastTarget = Cell(SugarElement.fromDom(body2));
  10524. var lastTimeStamp = Cell(0);
  10525. var touchEnd = function(t) {
  10526. var target = SugarElement.fromDom(t.target);
  10527. if (name(target) === "td" || name(target) === "th") {
  10528. var lT = lastTarget.get();
  10529. var lTS = lastTimeStamp.get();
  10530. if (eq$1(lT, target) && t.timeStamp - lTS < 300) {
  10531. t.preventDefault();
  10532. external$1(target, target);
  10533. }
  10534. }
  10535. lastTarget.set(target);
  10536. lastTimeStamp.set(t.timeStamp);
  10537. };
  10538. return { touchEnd };
  10539. };
  10540. var doubleTap = getDoubleTap();
  10541. editor.on("dragstart", dragStart);
  10542. editor.on("mousedown", mouseDown);
  10543. editor.on("mouseover", mouseOver);
  10544. editor.on("mouseup", mouseUp);
  10545. editor.on("touchend", doubleTap.touchEnd);
  10546. editor.on("keyup", keyup);
  10547. editor.on("keydown", keydown);
  10548. editor.on("NodeChange", syncSelection);
  10549. });
  10550. return { clear: annotations.clear };
  10551. }
  10552. var child = function(scope, selector) {
  10553. return child$1(scope, selector).isSome();
  10554. };
  10555. var getSelectionTargets = function(editor, selections) {
  10556. var targets = Cell(Optional.none());
  10557. var changeHandlers = Cell([]);
  10558. var selectionDetails = Optional.none();
  10559. var isCaption = isTag("caption");
  10560. var isDisabledForSelection = function(key2) {
  10561. return selectionDetails.forall(function(details) {
  10562. return !details[key2];
  10563. });
  10564. };
  10565. var getStart2 = function() {
  10566. return getSelectionCellOrCaption(getSelectionStart(editor), getIsRoot(editor));
  10567. };
  10568. var getEnd2 = function() {
  10569. return getSelectionCellOrCaption(getSelectionEnd(editor), getIsRoot(editor));
  10570. };
  10571. var findTargets = function() {
  10572. return getStart2().bind(function(startCellOrCaption) {
  10573. return flatten(lift2(table(startCellOrCaption), getEnd2().bind(table), function(startTable, endTable) {
  10574. if (eq$1(startTable, endTable)) {
  10575. if (isCaption(startCellOrCaption)) {
  10576. return Optional.some(noMenu(startCellOrCaption));
  10577. } else {
  10578. return Optional.some(forMenu(selections, startTable, startCellOrCaption));
  10579. }
  10580. }
  10581. return Optional.none();
  10582. }));
  10583. });
  10584. };
  10585. var getExtractedDetails = function(targets2) {
  10586. var tableOpt = table(targets2.element);
  10587. return tableOpt.map(function(table2) {
  10588. var warehouse = Warehouse.fromTable(table2);
  10589. var selectedCells = onCells(warehouse, targets2).getOr([]);
  10590. var locked = foldl(selectedCells, function(acc, cell2) {
  10591. if (cell2.isLocked) {
  10592. acc.onAny = true;
  10593. if (cell2.column === 0) {
  10594. acc.onFirst = true;
  10595. } else if (cell2.column + cell2.colspan >= warehouse.grid.columns) {
  10596. acc.onLast = true;
  10597. }
  10598. }
  10599. return acc;
  10600. }, {
  10601. onAny: false,
  10602. onFirst: false,
  10603. onLast: false
  10604. });
  10605. return {
  10606. mergeable: onUnlockedMergable(warehouse, targets2).isSome(),
  10607. unmergeable: onUnlockedUnmergable(warehouse, targets2).isSome(),
  10608. locked
  10609. };
  10610. });
  10611. };
  10612. var resetTargets = function() {
  10613. targets.set(cached(findTargets)());
  10614. selectionDetails = targets.get().bind(getExtractedDetails);
  10615. each$2(changeHandlers.get(), function(handler) {
  10616. return handler();
  10617. });
  10618. };
  10619. var setupHandler = function(handler) {
  10620. handler();
  10621. changeHandlers.set(changeHandlers.get().concat([handler]));
  10622. return function() {
  10623. changeHandlers.set(filter$2(changeHandlers.get(), function(h) {
  10624. return h !== handler;
  10625. }));
  10626. };
  10627. };
  10628. var onSetup = function(api2, isDisabled) {
  10629. return setupHandler(function() {
  10630. return targets.get().fold(function() {
  10631. api2.setDisabled(true);
  10632. }, function(targets2) {
  10633. api2.setDisabled(isDisabled(targets2));
  10634. });
  10635. });
  10636. };
  10637. var onSetupWithToggle = function(api2, isDisabled, isActive) {
  10638. return setupHandler(function() {
  10639. return targets.get().fold(function() {
  10640. api2.setDisabled(true);
  10641. api2.setActive(false);
  10642. }, function(targets2) {
  10643. api2.setDisabled(isDisabled(targets2));
  10644. api2.setActive(isActive(targets2));
  10645. });
  10646. });
  10647. };
  10648. var isDisabledFromLocked = function(lockedDisable) {
  10649. return selectionDetails.exists(function(details) {
  10650. return details.locked[lockedDisable];
  10651. });
  10652. };
  10653. var onSetupTable = function(api2) {
  10654. return onSetup(api2, function(_) {
  10655. return false;
  10656. });
  10657. };
  10658. var onSetupCellOrRow = function(api2) {
  10659. return onSetup(api2, function(targets2) {
  10660. return isCaption(targets2.element);
  10661. });
  10662. };
  10663. var onSetupColumn = function(lockedDisable) {
  10664. return function(api2) {
  10665. return onSetup(api2, function(targets2) {
  10666. return isCaption(targets2.element) || isDisabledFromLocked(lockedDisable);
  10667. });
  10668. };
  10669. };
  10670. var onSetupPasteable = function(getClipboardData) {
  10671. return function(api2) {
  10672. return onSetup(api2, function(targets2) {
  10673. return isCaption(targets2.element) || getClipboardData().isNone();
  10674. });
  10675. };
  10676. };
  10677. var onSetupPasteableColumn = function(getClipboardData, lockedDisable) {
  10678. return function(api2) {
  10679. return onSetup(api2, function(targets2) {
  10680. return isCaption(targets2.element) || getClipboardData().isNone() || isDisabledFromLocked(lockedDisable);
  10681. });
  10682. };
  10683. };
  10684. var onSetupMergeable = function(api2) {
  10685. return onSetup(api2, function(_targets) {
  10686. return isDisabledForSelection("mergeable");
  10687. });
  10688. };
  10689. var onSetupUnmergeable = function(api2) {
  10690. return onSetup(api2, function(_targets) {
  10691. return isDisabledForSelection("unmergeable");
  10692. });
  10693. };
  10694. var onSetupTableWithCaption = function(api2) {
  10695. return onSetupWithToggle(api2, never, function(targets2) {
  10696. var tableOpt = table(targets2.element, getIsRoot(editor));
  10697. return tableOpt.exists(function(table2) {
  10698. return child(table2, "caption");
  10699. });
  10700. });
  10701. };
  10702. var onSetupTableHeaders = function(command, headerType) {
  10703. return function(api2) {
  10704. return onSetupWithToggle(api2, function(targets2) {
  10705. return isCaption(targets2.element);
  10706. }, function() {
  10707. return editor.queryCommandValue(command) === headerType;
  10708. });
  10709. };
  10710. };
  10711. var onSetupTableRowHeaders = onSetupTableHeaders("mceTableRowType", "header");
  10712. var onSetupTableColumnHeaders = onSetupTableHeaders("mceTableColType", "th");
  10713. editor.on("NodeChange ExecCommand TableSelectorChange", resetTargets);
  10714. return {
  10715. onSetupTable,
  10716. onSetupCellOrRow,
  10717. onSetupColumn,
  10718. onSetupPasteable,
  10719. onSetupPasteableColumn,
  10720. onSetupMergeable,
  10721. onSetupUnmergeable,
  10722. resetTargets,
  10723. onSetupTableWithCaption,
  10724. onSetupTableRowHeaders,
  10725. onSetupTableColumnHeaders,
  10726. targets: targets.get
  10727. };
  10728. };
  10729. var addButtons = function(editor, selections, selectionTargets, clipboard) {
  10730. editor.ui.registry.addMenuButton("table", {
  10731. tooltip: "Table",
  10732. icon: "table",
  10733. fetch: function(callback) {
  10734. return callback("inserttable | cell row column | advtablesort | tableprops deletetable");
  10735. }
  10736. });
  10737. var cmd = function(command) {
  10738. return function() {
  10739. return editor.execCommand(command);
  10740. };
  10741. };
  10742. editor.ui.registry.addButton("tableprops", {
  10743. tooltip: "Table properties",
  10744. onAction: cmd("mceTableProps"),
  10745. icon: "table",
  10746. onSetup: selectionTargets.onSetupTable
  10747. });
  10748. editor.ui.registry.addButton("tabledelete", {
  10749. tooltip: "Delete table",
  10750. onAction: cmd("mceTableDelete"),
  10751. icon: "table-delete-table",
  10752. onSetup: selectionTargets.onSetupTable
  10753. });
  10754. editor.ui.registry.addButton("tablecellprops", {
  10755. tooltip: "Cell properties",
  10756. onAction: cmd("mceTableCellProps"),
  10757. icon: "table-cell-properties",
  10758. onSetup: selectionTargets.onSetupCellOrRow
  10759. });
  10760. editor.ui.registry.addButton("tablemergecells", {
  10761. tooltip: "Merge cells",
  10762. onAction: cmd("mceTableMergeCells"),
  10763. icon: "table-merge-cells",
  10764. onSetup: selectionTargets.onSetupMergeable
  10765. });
  10766. editor.ui.registry.addButton("tablesplitcells", {
  10767. tooltip: "Split cell",
  10768. onAction: cmd("mceTableSplitCells"),
  10769. icon: "table-split-cells",
  10770. onSetup: selectionTargets.onSetupUnmergeable
  10771. });
  10772. editor.ui.registry.addButton("tableinsertrowbefore", {
  10773. tooltip: "Insert row before",
  10774. onAction: cmd("mceTableInsertRowBefore"),
  10775. icon: "table-insert-row-above",
  10776. onSetup: selectionTargets.onSetupCellOrRow
  10777. });
  10778. editor.ui.registry.addButton("tableinsertrowafter", {
  10779. tooltip: "Insert row after",
  10780. onAction: cmd("mceTableInsertRowAfter"),
  10781. icon: "table-insert-row-after",
  10782. onSetup: selectionTargets.onSetupCellOrRow
  10783. });
  10784. editor.ui.registry.addButton("tabledeleterow", {
  10785. tooltip: "Delete row",
  10786. onAction: cmd("mceTableDeleteRow"),
  10787. icon: "table-delete-row",
  10788. onSetup: selectionTargets.onSetupCellOrRow
  10789. });
  10790. editor.ui.registry.addButton("tablerowprops", {
  10791. tooltip: "Row properties",
  10792. onAction: cmd("mceTableRowProps"),
  10793. icon: "table-row-properties",
  10794. onSetup: selectionTargets.onSetupCellOrRow
  10795. });
  10796. editor.ui.registry.addButton("tableinsertcolbefore", {
  10797. tooltip: "Insert column before",
  10798. onAction: cmd("mceTableInsertColBefore"),
  10799. icon: "table-insert-column-before",
  10800. onSetup: selectionTargets.onSetupColumn("onFirst")
  10801. });
  10802. editor.ui.registry.addButton("tableinsertcolafter", {
  10803. tooltip: "Insert column after",
  10804. onAction: cmd("mceTableInsertColAfter"),
  10805. icon: "table-insert-column-after",
  10806. onSetup: selectionTargets.onSetupColumn("onLast")
  10807. });
  10808. editor.ui.registry.addButton("tabledeletecol", {
  10809. tooltip: "Delete column",
  10810. onAction: cmd("mceTableDeleteCol"),
  10811. icon: "table-delete-column",
  10812. onSetup: selectionTargets.onSetupColumn("onAny")
  10813. });
  10814. editor.ui.registry.addButton("tablecutrow", {
  10815. tooltip: "Cut row",
  10816. icon: "cut-row",
  10817. onAction: cmd("mceTableCutRow"),
  10818. onSetup: selectionTargets.onSetupCellOrRow
  10819. });
  10820. editor.ui.registry.addButton("tablecopyrow", {
  10821. tooltip: "Copy row",
  10822. icon: "duplicate-row",
  10823. onAction: cmd("mceTableCopyRow"),
  10824. onSetup: selectionTargets.onSetupCellOrRow
  10825. });
  10826. editor.ui.registry.addButton("tablepasterowbefore", {
  10827. tooltip: "Paste row before",
  10828. icon: "paste-row-before",
  10829. onAction: cmd("mceTablePasteRowBefore"),
  10830. onSetup: selectionTargets.onSetupPasteable(clipboard.getRows)
  10831. });
  10832. editor.ui.registry.addButton("tablepasterowafter", {
  10833. tooltip: "Paste row after",
  10834. icon: "paste-row-after",
  10835. onAction: cmd("mceTablePasteRowAfter"),
  10836. onSetup: selectionTargets.onSetupPasteable(clipboard.getRows)
  10837. });
  10838. editor.ui.registry.addButton("tablecutcol", {
  10839. tooltip: "Cut column",
  10840. icon: "cut-column",
  10841. onAction: cmd("mceTableCutCol"),
  10842. onSetup: selectionTargets.onSetupColumn("onAny")
  10843. });
  10844. editor.ui.registry.addButton("tablecopycol", {
  10845. tooltip: "Copy column",
  10846. icon: "duplicate-column",
  10847. onAction: cmd("mceTableCopyCol"),
  10848. onSetup: selectionTargets.onSetupColumn("onAny")
  10849. });
  10850. editor.ui.registry.addButton("tablepastecolbefore", {
  10851. tooltip: "Paste column before",
  10852. icon: "paste-column-before",
  10853. onAction: cmd("mceTablePasteColBefore"),
  10854. onSetup: selectionTargets.onSetupPasteableColumn(clipboard.getColumns, "onFirst")
  10855. });
  10856. editor.ui.registry.addButton("tablepastecolafter", {
  10857. tooltip: "Paste column after",
  10858. icon: "paste-column-after",
  10859. onAction: cmd("mceTablePasteColAfter"),
  10860. onSetup: selectionTargets.onSetupPasteableColumn(clipboard.getColumns, "onLast")
  10861. });
  10862. editor.ui.registry.addButton("tableinsertdialog", {
  10863. tooltip: "Insert table",
  10864. onAction: cmd("mceInsertTable"),
  10865. icon: "table"
  10866. });
  10867. var tableClassList = filterNoneItem(getTableClassList(editor));
  10868. if (tableClassList.length !== 0) {
  10869. editor.ui.registry.addMenuButton("tableclass", {
  10870. icon: "table-classes",
  10871. tooltip: "Table styles",
  10872. fetch: generateMenuItemsCallback(editor, selections, tableClassList, "tableclass", function(value2) {
  10873. return editor.execCommand("mceTableToggleClass", false, value2);
  10874. }),
  10875. onSetup: selectionTargets.onSetupTable
  10876. });
  10877. }
  10878. var tableCellClassList = filterNoneItem(getCellClassList(editor));
  10879. if (tableCellClassList.length !== 0) {
  10880. editor.ui.registry.addMenuButton("tablecellclass", {
  10881. icon: "table-cell-classes",
  10882. tooltip: "Cell styles",
  10883. fetch: generateMenuItemsCallback(editor, selections, tableCellClassList, "tablecellclass", function(value2) {
  10884. return editor.execCommand("mceTableCellToggleClass", false, value2);
  10885. }),
  10886. onSetup: selectionTargets.onSetupCellOrRow
  10887. });
  10888. }
  10889. editor.ui.registry.addMenuButton("tablecellvalign", {
  10890. icon: "vertical-align",
  10891. tooltip: "Vertical align",
  10892. fetch: generateMenuItemsCallback(editor, selections, verticalAlignValues, "tablecellverticalalign", applyTableCellStyle(editor, "vertical-align")),
  10893. onSetup: selectionTargets.onSetupCellOrRow
  10894. });
  10895. editor.ui.registry.addMenuButton("tablecellborderwidth", {
  10896. icon: "border-width",
  10897. tooltip: "Border width",
  10898. fetch: generateMenuItemsCallback(editor, selections, getTableBorderWidths(editor), "tablecellborderwidth", applyTableCellStyle(editor, "border-width")),
  10899. onSetup: selectionTargets.onSetupCellOrRow
  10900. });
  10901. editor.ui.registry.addMenuButton("tablecellborderstyle", {
  10902. icon: "border-style",
  10903. tooltip: "Border style",
  10904. fetch: generateMenuItemsCallback(editor, selections, getTableBorderStyles(editor), "tablecellborderstyle", applyTableCellStyle(editor, "border-style")),
  10905. onSetup: selectionTargets.onSetupCellOrRow
  10906. });
  10907. editor.ui.registry.addToggleButton("tablecaption", {
  10908. tooltip: "Table caption",
  10909. onAction: cmd("mceTableToggleCaption"),
  10910. icon: "table-caption",
  10911. onSetup: selectionTargets.onSetupTableWithCaption
  10912. });
  10913. editor.ui.registry.addMenuButton("tablecellbackgroundcolor", {
  10914. icon: "cell-background-color",
  10915. tooltip: "Background color",
  10916. fetch: function(callback) {
  10917. return callback(buildColorMenu(editor, getTableBackgroundColorMap(editor), "background-color"));
  10918. },
  10919. onSetup: selectionTargets.onSetupCellOrRow
  10920. });
  10921. editor.ui.registry.addMenuButton("tablecellbordercolor", {
  10922. icon: "cell-border-color",
  10923. tooltip: "Border color",
  10924. fetch: function(callback) {
  10925. return callback(buildColorMenu(editor, getTableBorderColorMap(editor), "border-color"));
  10926. },
  10927. onSetup: selectionTargets.onSetupCellOrRow
  10928. });
  10929. editor.ui.registry.addToggleButton("tablerowheader", {
  10930. tooltip: "Row header",
  10931. icon: "table-top-header",
  10932. onAction: changeRowHeader(editor),
  10933. onSetup: selectionTargets.onSetupTableRowHeaders
  10934. });
  10935. editor.ui.registry.addToggleButton("tablecolheader", {
  10936. tooltip: "Column header",
  10937. icon: "table-left-header",
  10938. onAction: changeColumnHeader(editor),
  10939. onSetup: selectionTargets.onSetupTableColumnHeaders
  10940. });
  10941. };
  10942. var addToolbars = function(editor) {
  10943. var isTable = function(table2) {
  10944. return editor.dom.is(table2, "table") && editor.getBody().contains(table2);
  10945. };
  10946. var toolbar = getToolbar(editor);
  10947. if (toolbar.length > 0) {
  10948. editor.ui.registry.addContextToolbar("table", {
  10949. predicate: isTable,
  10950. items: toolbar,
  10951. scope: "node",
  10952. position: "node"
  10953. });
  10954. }
  10955. };
  10956. var addMenuItems = function(editor, selections, selectionTargets, clipboard) {
  10957. var cmd = function(command) {
  10958. return function() {
  10959. return editor.execCommand(command);
  10960. };
  10961. };
  10962. var insertTableAction = function(data) {
  10963. editor.execCommand("mceInsertTable", false, {
  10964. rows: data.numRows,
  10965. columns: data.numColumns
  10966. });
  10967. };
  10968. var tableProperties = {
  10969. text: "Table properties",
  10970. onSetup: selectionTargets.onSetupTable,
  10971. onAction: cmd("mceTableProps")
  10972. };
  10973. var deleteTable = {
  10974. text: "Delete table",
  10975. icon: "table-delete-table",
  10976. onSetup: selectionTargets.onSetupTable,
  10977. onAction: cmd("mceTableDelete")
  10978. };
  10979. editor.ui.registry.addMenuItem("tableinsertrowbefore", {
  10980. text: "Insert row before",
  10981. icon: "table-insert-row-above",
  10982. onAction: cmd("mceTableInsertRowBefore"),
  10983. onSetup: selectionTargets.onSetupCellOrRow
  10984. });
  10985. editor.ui.registry.addMenuItem("tableinsertrowafter", {
  10986. text: "Insert row after",
  10987. icon: "table-insert-row-after",
  10988. onAction: cmd("mceTableInsertRowAfter"),
  10989. onSetup: selectionTargets.onSetupCellOrRow
  10990. });
  10991. editor.ui.registry.addMenuItem("tabledeleterow", {
  10992. text: "Delete row",
  10993. icon: "table-delete-row",
  10994. onAction: cmd("mceTableDeleteRow"),
  10995. onSetup: selectionTargets.onSetupCellOrRow
  10996. });
  10997. editor.ui.registry.addMenuItem("tablerowprops", {
  10998. text: "Row properties",
  10999. icon: "table-row-properties",
  11000. onAction: cmd("mceTableRowProps"),
  11001. onSetup: selectionTargets.onSetupCellOrRow
  11002. });
  11003. editor.ui.registry.addMenuItem("tablecutrow", {
  11004. text: "Cut row",
  11005. icon: "cut-row",
  11006. onAction: cmd("mceTableCutRow"),
  11007. onSetup: selectionTargets.onSetupCellOrRow
  11008. });
  11009. editor.ui.registry.addMenuItem("tablecopyrow", {
  11010. text: "Copy row",
  11011. icon: "duplicate-row",
  11012. onAction: cmd("mceTableCopyRow"),
  11013. onSetup: selectionTargets.onSetupCellOrRow
  11014. });
  11015. editor.ui.registry.addMenuItem("tablepasterowbefore", {
  11016. text: "Paste row before",
  11017. icon: "paste-row-before",
  11018. onAction: cmd("mceTablePasteRowBefore"),
  11019. onSetup: selectionTargets.onSetupPasteable(clipboard.getRows)
  11020. });
  11021. editor.ui.registry.addMenuItem("tablepasterowafter", {
  11022. text: "Paste row after",
  11023. icon: "paste-row-after",
  11024. onAction: cmd("mceTablePasteRowAfter"),
  11025. onSetup: selectionTargets.onSetupPasteable(clipboard.getRows)
  11026. });
  11027. var row2 = {
  11028. type: "nestedmenuitem",
  11029. text: "Row",
  11030. getSubmenuItems: constant("tableinsertrowbefore tableinsertrowafter tabledeleterow tablerowprops | tablecutrow tablecopyrow tablepasterowbefore tablepasterowafter")
  11031. };
  11032. editor.ui.registry.addMenuItem("tableinsertcolumnbefore", {
  11033. text: "Insert column before",
  11034. icon: "table-insert-column-before",
  11035. onAction: cmd("mceTableInsertColBefore"),
  11036. onSetup: selectionTargets.onSetupColumn("onFirst")
  11037. });
  11038. editor.ui.registry.addMenuItem("tableinsertcolumnafter", {
  11039. text: "Insert column after",
  11040. icon: "table-insert-column-after",
  11041. onAction: cmd("mceTableInsertColAfter"),
  11042. onSetup: selectionTargets.onSetupColumn("onLast")
  11043. });
  11044. editor.ui.registry.addMenuItem("tabledeletecolumn", {
  11045. text: "Delete column",
  11046. icon: "table-delete-column",
  11047. onAction: cmd("mceTableDeleteCol"),
  11048. onSetup: selectionTargets.onSetupColumn("onAny")
  11049. });
  11050. editor.ui.registry.addMenuItem("tablecutcolumn", {
  11051. text: "Cut column",
  11052. icon: "cut-column",
  11053. onAction: cmd("mceTableCutCol"),
  11054. onSetup: selectionTargets.onSetupColumn("onAny")
  11055. });
  11056. editor.ui.registry.addMenuItem("tablecopycolumn", {
  11057. text: "Copy column",
  11058. icon: "duplicate-column",
  11059. onAction: cmd("mceTableCopyCol"),
  11060. onSetup: selectionTargets.onSetupColumn("onAny")
  11061. });
  11062. editor.ui.registry.addMenuItem("tablepastecolumnbefore", {
  11063. text: "Paste column before",
  11064. icon: "paste-column-before",
  11065. onAction: cmd("mceTablePasteColBefore"),
  11066. onSetup: selectionTargets.onSetupPasteableColumn(clipboard.getColumns, "onFirst")
  11067. });
  11068. editor.ui.registry.addMenuItem("tablepastecolumnafter", {
  11069. text: "Paste column after",
  11070. icon: "paste-column-after",
  11071. onAction: cmd("mceTablePasteColAfter"),
  11072. onSetup: selectionTargets.onSetupPasteableColumn(clipboard.getColumns, "onLast")
  11073. });
  11074. var column = {
  11075. type: "nestedmenuitem",
  11076. text: "Column",
  11077. getSubmenuItems: constant("tableinsertcolumnbefore tableinsertcolumnafter tabledeletecolumn | tablecutcolumn tablecopycolumn tablepastecolumnbefore tablepastecolumnafter")
  11078. };
  11079. editor.ui.registry.addMenuItem("tablecellprops", {
  11080. text: "Cell properties",
  11081. icon: "table-cell-properties",
  11082. onAction: cmd("mceTableCellProps"),
  11083. onSetup: selectionTargets.onSetupCellOrRow
  11084. });
  11085. editor.ui.registry.addMenuItem("tablemergecells", {
  11086. text: "Merge cells",
  11087. icon: "table-merge-cells",
  11088. onAction: cmd("mceTableMergeCells"),
  11089. onSetup: selectionTargets.onSetupMergeable
  11090. });
  11091. editor.ui.registry.addMenuItem("tablesplitcells", {
  11092. text: "Split cell",
  11093. icon: "table-split-cells",
  11094. onAction: cmd("mceTableSplitCells"),
  11095. onSetup: selectionTargets.onSetupUnmergeable
  11096. });
  11097. var cell2 = {
  11098. type: "nestedmenuitem",
  11099. text: "Cell",
  11100. getSubmenuItems: constant("tablecellprops tablemergecells tablesplitcells")
  11101. };
  11102. if (hasTableGrid(editor) === false) {
  11103. editor.ui.registry.addMenuItem("inserttable", {
  11104. text: "Table",
  11105. icon: "table",
  11106. onAction: cmd("mceInsertTable")
  11107. });
  11108. } else {
  11109. editor.ui.registry.addNestedMenuItem("inserttable", {
  11110. text: "Table",
  11111. icon: "table",
  11112. getSubmenuItems: function() {
  11113. return [{
  11114. type: "fancymenuitem",
  11115. fancytype: "inserttable",
  11116. onAction: insertTableAction
  11117. }];
  11118. }
  11119. });
  11120. }
  11121. editor.ui.registry.addMenuItem("inserttabledialog", {
  11122. text: "Insert table",
  11123. icon: "table",
  11124. onAction: cmd("mceInsertTable")
  11125. });
  11126. editor.ui.registry.addMenuItem("tableprops", tableProperties);
  11127. editor.ui.registry.addMenuItem("deletetable", deleteTable);
  11128. editor.ui.registry.addNestedMenuItem("row", row2);
  11129. editor.ui.registry.addNestedMenuItem("column", column);
  11130. editor.ui.registry.addNestedMenuItem("cell", cell2);
  11131. editor.ui.registry.addContextMenu("table", {
  11132. update: function() {
  11133. selectionTargets.resetTargets();
  11134. return selectionTargets.targets().fold(constant(""), function(targets) {
  11135. if (name(targets.element) === "caption") {
  11136. return "tableprops deletetable";
  11137. } else {
  11138. return "cell row column | advtablesort | tableprops deletetable";
  11139. }
  11140. });
  11141. }
  11142. });
  11143. var tableClassList = filterNoneItem(getTableClassList(editor));
  11144. if (tableClassList.length !== 0) {
  11145. editor.ui.registry.addNestedMenuItem("tableclass", {
  11146. icon: "table-classes",
  11147. text: "Table styles",
  11148. getSubmenuItems: function() {
  11149. return buildMenuItems(editor, selections, tableClassList, "tableclass", function(value2) {
  11150. return editor.execCommand("mceTableToggleClass", false, value2);
  11151. });
  11152. },
  11153. onSetup: selectionTargets.onSetupTable
  11154. });
  11155. }
  11156. var tableCellClassList = filterNoneItem(getCellClassList(editor));
  11157. if (tableCellClassList.length !== 0) {
  11158. editor.ui.registry.addNestedMenuItem("tablecellclass", {
  11159. icon: "table-cell-classes",
  11160. text: "Cell styles",
  11161. getSubmenuItems: function() {
  11162. return buildMenuItems(editor, selections, tableCellClassList, "tablecellclass", function(value2) {
  11163. return editor.execCommand("mceTableCellToggleClass", false, value2);
  11164. });
  11165. },
  11166. onSetup: selectionTargets.onSetupCellOrRow
  11167. });
  11168. }
  11169. editor.ui.registry.addNestedMenuItem("tablecellvalign", {
  11170. icon: "vertical-align",
  11171. text: "Vertical align",
  11172. getSubmenuItems: function() {
  11173. return buildMenuItems(editor, selections, verticalAlignValues, "tablecellverticalalign", applyTableCellStyle(editor, "vertical-align"));
  11174. },
  11175. onSetup: selectionTargets.onSetupCellOrRow
  11176. });
  11177. editor.ui.registry.addNestedMenuItem("tablecellborderwidth", {
  11178. icon: "border-width",
  11179. text: "Border width",
  11180. getSubmenuItems: function() {
  11181. return buildMenuItems(editor, selections, getTableBorderWidths(editor), "tablecellborderwidth", applyTableCellStyle(editor, "border-width"));
  11182. },
  11183. onSetup: selectionTargets.onSetupCellOrRow
  11184. });
  11185. editor.ui.registry.addNestedMenuItem("tablecellborderstyle", {
  11186. icon: "border-style",
  11187. text: "Border style",
  11188. getSubmenuItems: function() {
  11189. return buildMenuItems(editor, selections, getTableBorderStyles(editor), "tablecellborderstyle", applyTableCellStyle(editor, "border-style"));
  11190. },
  11191. onSetup: selectionTargets.onSetupCellOrRow
  11192. });
  11193. editor.ui.registry.addToggleMenuItem("tablecaption", {
  11194. icon: "table-caption",
  11195. text: "Table caption",
  11196. onAction: cmd("mceTableToggleCaption"),
  11197. onSetup: selectionTargets.onSetupTableWithCaption
  11198. });
  11199. editor.ui.registry.addNestedMenuItem("tablecellbackgroundcolor", {
  11200. icon: "cell-background-color",
  11201. text: "Background color",
  11202. getSubmenuItems: function() {
  11203. return buildColorMenu(editor, getTableBackgroundColorMap(editor), "background-color");
  11204. },
  11205. onSetup: selectionTargets.onSetupCellOrRow
  11206. });
  11207. editor.ui.registry.addNestedMenuItem("tablecellbordercolor", {
  11208. icon: "cell-border-color",
  11209. text: "Border color",
  11210. getSubmenuItems: function() {
  11211. return buildColorMenu(editor, getTableBorderColorMap(editor), "border-color");
  11212. },
  11213. onSetup: selectionTargets.onSetupCellOrRow
  11214. });
  11215. editor.ui.registry.addToggleMenuItem("tablerowheader", {
  11216. text: "Row header",
  11217. icon: "table-top-header",
  11218. onAction: changeRowHeader(editor),
  11219. onSetup: selectionTargets.onSetupTableRowHeaders
  11220. });
  11221. editor.ui.registry.addToggleMenuItem("tablecolheader", {
  11222. text: "Column header",
  11223. icon: "table-left-header",
  11224. onAction: changeColumnHeader(editor),
  11225. onSetup: selectionTargets.onSetupTableColumnHeaders
  11226. });
  11227. };
  11228. var Plugin = function(editor) {
  11229. var selections = Selections(function() {
  11230. return getBody(editor);
  11231. }, function() {
  11232. return getSelectionCell(getSelectionStart(editor), getIsRoot(editor));
  11233. }, ephemera.selectedSelector);
  11234. var selectionTargets = getSelectionTargets(editor, selections);
  11235. var resizeHandler = getResizeHandler(editor);
  11236. var cellSelection = CellSelection(editor, resizeHandler.lazyResize, selectionTargets);
  11237. var actions = TableActions(editor, cellSelection, resizeHandler.lazyWire);
  11238. var clipboard = Clipboard();
  11239. registerCommands(editor, actions, cellSelection, selections, clipboard);
  11240. registerQueryCommands(editor, actions, selections);
  11241. registerEvents(editor, selections, actions);
  11242. addMenuItems(editor, selections, selectionTargets, clipboard);
  11243. addButtons(editor, selections, selectionTargets, clipboard);
  11244. addToolbars(editor);
  11245. editor.on("PreInit", function() {
  11246. editor.serializer.addTempAttr(ephemera.firstSelected);
  11247. editor.serializer.addTempAttr(ephemera.lastSelected);
  11248. registerFormats(editor);
  11249. });
  11250. if (hasTabNavigation(editor)) {
  11251. editor.on("keydown", function(e) {
  11252. handle$1(e, editor, cellSelection);
  11253. });
  11254. }
  11255. editor.on("remove", function() {
  11256. resizeHandler.destroy();
  11257. });
  11258. return getApi(editor, clipboard, resizeHandler, selectionTargets);
  11259. };
  11260. function Plugin$1() {
  11261. global$3.add("table", Plugin);
  11262. }
  11263. Plugin$1();
  11264. })();
  11265. }
  11266. });
  11267. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/table/index.js
  11268. require_plugin();
  11269. //# sourceMappingURL=tinymce_plugins_table.js.map