plugin.js 318 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.0.7 (2019-06-05)
  8. */
  9. (function () {
  10. var table = (function (domGlobals) {
  11. 'use strict';
  12. var Cell = function (initial) {
  13. var value = initial;
  14. var get = function () {
  15. return value;
  16. };
  17. var set = function (v) {
  18. value = v;
  19. };
  20. var clone = function () {
  21. return Cell(get());
  22. };
  23. return {
  24. get: get,
  25. set: set,
  26. clone: clone
  27. };
  28. };
  29. var noop = function () {
  30. };
  31. var noarg = function (f) {
  32. return function () {
  33. return f();
  34. };
  35. };
  36. var compose = function (fa, fb) {
  37. return function () {
  38. var args = [];
  39. for (var _i = 0; _i < arguments.length; _i++) {
  40. args[_i] = arguments[_i];
  41. }
  42. return fa(fb.apply(null, args));
  43. };
  44. };
  45. var constant = function (value) {
  46. return function () {
  47. return value;
  48. };
  49. };
  50. var identity = function (x) {
  51. return x;
  52. };
  53. var tripleEquals = function (a, b) {
  54. return a === b;
  55. };
  56. function curry(fn) {
  57. var initialArgs = [];
  58. for (var _i = 1; _i < arguments.length; _i++) {
  59. initialArgs[_i - 1] = arguments[_i];
  60. }
  61. return function () {
  62. var restArgs = [];
  63. for (var _i = 0; _i < arguments.length; _i++) {
  64. restArgs[_i] = arguments[_i];
  65. }
  66. var all = initialArgs.concat(restArgs);
  67. return fn.apply(null, all);
  68. };
  69. }
  70. var not = function (f) {
  71. return function () {
  72. var args = [];
  73. for (var _i = 0; _i < arguments.length; _i++) {
  74. args[_i] = arguments[_i];
  75. }
  76. return !f.apply(null, args);
  77. };
  78. };
  79. var die = function (msg) {
  80. return function () {
  81. throw new Error(msg);
  82. };
  83. };
  84. var apply = function (f) {
  85. return f();
  86. };
  87. var call = function (f) {
  88. f();
  89. };
  90. var never = constant(false);
  91. var always = constant(true);
  92. var Fun = /*#__PURE__*/Object.freeze({
  93. noop: noop,
  94. noarg: noarg,
  95. compose: compose,
  96. constant: constant,
  97. identity: identity,
  98. tripleEquals: tripleEquals,
  99. curry: curry,
  100. not: not,
  101. die: die,
  102. apply: apply,
  103. call: call,
  104. never: never,
  105. always: always
  106. });
  107. var never$1 = never;
  108. var always$1 = always;
  109. var none = function () {
  110. return NONE;
  111. };
  112. var NONE = function () {
  113. var eq = function (o) {
  114. return o.isNone();
  115. };
  116. var call = function (thunk) {
  117. return thunk();
  118. };
  119. var id = function (n) {
  120. return n;
  121. };
  122. var noop = function () {
  123. };
  124. var nul = function () {
  125. return null;
  126. };
  127. var undef = function () {
  128. return undefined;
  129. };
  130. var me = {
  131. fold: function (n, s) {
  132. return n();
  133. },
  134. is: never$1,
  135. isSome: never$1,
  136. isNone: always$1,
  137. getOr: id,
  138. getOrThunk: call,
  139. getOrDie: function (msg) {
  140. throw new Error(msg || 'error: getOrDie called on none.');
  141. },
  142. getOrNull: nul,
  143. getOrUndefined: undef,
  144. or: id,
  145. orThunk: call,
  146. map: none,
  147. ap: none,
  148. each: noop,
  149. bind: none,
  150. flatten: none,
  151. exists: never$1,
  152. forall: always$1,
  153. filter: none,
  154. equals: eq,
  155. equals_: eq,
  156. toArray: function () {
  157. return [];
  158. },
  159. toString: constant('none()')
  160. };
  161. if (Object.freeze)
  162. Object.freeze(me);
  163. return me;
  164. }();
  165. var some = function (a) {
  166. var constant_a = function () {
  167. return a;
  168. };
  169. var self = function () {
  170. return me;
  171. };
  172. var map = function (f) {
  173. return some(f(a));
  174. };
  175. var bind = function (f) {
  176. return f(a);
  177. };
  178. var me = {
  179. fold: function (n, s) {
  180. return s(a);
  181. },
  182. is: function (v) {
  183. return a === v;
  184. },
  185. isSome: always$1,
  186. isNone: never$1,
  187. getOr: constant_a,
  188. getOrThunk: constant_a,
  189. getOrDie: constant_a,
  190. getOrNull: constant_a,
  191. getOrUndefined: constant_a,
  192. or: self,
  193. orThunk: self,
  194. map: map,
  195. ap: function (optfab) {
  196. return optfab.fold(none, function (fab) {
  197. return some(fab(a));
  198. });
  199. },
  200. each: function (f) {
  201. f(a);
  202. },
  203. bind: bind,
  204. flatten: constant_a,
  205. exists: bind,
  206. forall: bind,
  207. filter: function (f) {
  208. return f(a) ? me : NONE;
  209. },
  210. equals: function (o) {
  211. return o.is(a);
  212. },
  213. equals_: function (o, elementEq) {
  214. return o.fold(never$1, function (b) {
  215. return elementEq(a, b);
  216. });
  217. },
  218. toArray: function () {
  219. return [a];
  220. },
  221. toString: function () {
  222. return 'some(' + a + ')';
  223. }
  224. };
  225. return me;
  226. };
  227. var from = function (value) {
  228. return value === null || value === undefined ? NONE : some(value);
  229. };
  230. var Option = {
  231. some: some,
  232. none: none,
  233. from: from
  234. };
  235. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  236. var typeOf = function (x) {
  237. if (x === null)
  238. return 'null';
  239. var t = typeof x;
  240. if (t === 'object' && Array.prototype.isPrototypeOf(x))
  241. return 'array';
  242. if (t === 'object' && String.prototype.isPrototypeOf(x))
  243. return 'string';
  244. return t;
  245. };
  246. var isType = function (type) {
  247. return function (value) {
  248. return typeOf(value) === type;
  249. };
  250. };
  251. var isString = isType('string');
  252. var isArray = isType('array');
  253. var isBoolean = isType('boolean');
  254. var isFunction = isType('function');
  255. var isNumber = isType('number');
  256. var slice = Array.prototype.slice;
  257. var rawIndexOf = function () {
  258. var pIndexOf = Array.prototype.indexOf;
  259. var fastIndex = function (xs, x) {
  260. return pIndexOf.call(xs, x);
  261. };
  262. var slowIndex = function (xs, x) {
  263. return slowIndexOf(xs, x);
  264. };
  265. return pIndexOf === undefined ? slowIndex : fastIndex;
  266. }();
  267. var indexOf = function (xs, x) {
  268. var r = rawIndexOf(xs, x);
  269. return r === -1 ? Option.none() : Option.some(r);
  270. };
  271. var contains = function (xs, x) {
  272. return rawIndexOf(xs, x) > -1;
  273. };
  274. var exists = function (xs, pred) {
  275. return findIndex(xs, pred).isSome();
  276. };
  277. var range = function (num, f) {
  278. var r = [];
  279. for (var i = 0; i < num; i++) {
  280. r.push(f(i));
  281. }
  282. return r;
  283. };
  284. var chunk = function (array, size) {
  285. var r = [];
  286. for (var i = 0; i < array.length; i += size) {
  287. var s = slice.call(array, i, i + size);
  288. r.push(s);
  289. }
  290. return r;
  291. };
  292. var map = function (xs, f) {
  293. var len = xs.length;
  294. var r = new Array(len);
  295. for (var i = 0; i < len; i++) {
  296. var x = xs[i];
  297. r[i] = f(x, i, xs);
  298. }
  299. return r;
  300. };
  301. var each = function (xs, f) {
  302. for (var i = 0, len = xs.length; i < len; i++) {
  303. var x = xs[i];
  304. f(x, i, xs);
  305. }
  306. };
  307. var eachr = function (xs, f) {
  308. for (var i = xs.length - 1; i >= 0; i--) {
  309. var x = xs[i];
  310. f(x, i, xs);
  311. }
  312. };
  313. var partition = function (xs, pred) {
  314. var pass = [];
  315. var fail = [];
  316. for (var i = 0, len = xs.length; i < len; i++) {
  317. var x = xs[i];
  318. var arr = pred(x, i, xs) ? pass : fail;
  319. arr.push(x);
  320. }
  321. return {
  322. pass: pass,
  323. fail: fail
  324. };
  325. };
  326. var filter = function (xs, pred) {
  327. var r = [];
  328. for (var i = 0, len = xs.length; i < len; i++) {
  329. var x = xs[i];
  330. if (pred(x, i, xs)) {
  331. r.push(x);
  332. }
  333. }
  334. return r;
  335. };
  336. var groupBy = function (xs, f) {
  337. if (xs.length === 0) {
  338. return [];
  339. } else {
  340. var wasType = f(xs[0]);
  341. var r = [];
  342. var group = [];
  343. for (var i = 0, len = xs.length; i < len; i++) {
  344. var x = xs[i];
  345. var type = f(x);
  346. if (type !== wasType) {
  347. r.push(group);
  348. group = [];
  349. }
  350. wasType = type;
  351. group.push(x);
  352. }
  353. if (group.length !== 0) {
  354. r.push(group);
  355. }
  356. return r;
  357. }
  358. };
  359. var foldr = function (xs, f, acc) {
  360. eachr(xs, function (x) {
  361. acc = f(acc, x);
  362. });
  363. return acc;
  364. };
  365. var foldl = function (xs, f, acc) {
  366. each(xs, function (x) {
  367. acc = f(acc, x);
  368. });
  369. return acc;
  370. };
  371. var find = function (xs, pred) {
  372. for (var i = 0, len = xs.length; i < len; i++) {
  373. var x = xs[i];
  374. if (pred(x, i, xs)) {
  375. return Option.some(x);
  376. }
  377. }
  378. return Option.none();
  379. };
  380. var findIndex = function (xs, pred) {
  381. for (var i = 0, len = xs.length; i < len; i++) {
  382. var x = xs[i];
  383. if (pred(x, i, xs)) {
  384. return Option.some(i);
  385. }
  386. }
  387. return Option.none();
  388. };
  389. var slowIndexOf = function (xs, x) {
  390. for (var i = 0, len = xs.length; i < len; ++i) {
  391. if (xs[i] === x) {
  392. return i;
  393. }
  394. }
  395. return -1;
  396. };
  397. var push = Array.prototype.push;
  398. var flatten = function (xs) {
  399. var r = [];
  400. for (var i = 0, len = xs.length; i < len; ++i) {
  401. if (!Array.prototype.isPrototypeOf(xs[i]))
  402. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  403. push.apply(r, xs[i]);
  404. }
  405. return r;
  406. };
  407. var bind = function (xs, f) {
  408. var output = map(xs, f);
  409. return flatten(output);
  410. };
  411. var forall = function (xs, pred) {
  412. for (var i = 0, len = xs.length; i < len; ++i) {
  413. var x = xs[i];
  414. if (pred(x, i, xs) !== true) {
  415. return false;
  416. }
  417. }
  418. return true;
  419. };
  420. var equal = function (a1, a2) {
  421. return a1.length === a2.length && forall(a1, function (x, i) {
  422. return x === a2[i];
  423. });
  424. };
  425. var reverse = function (xs) {
  426. var r = slice.call(xs, 0);
  427. r.reverse();
  428. return r;
  429. };
  430. var difference = function (a1, a2) {
  431. return filter(a1, function (x) {
  432. return !contains(a2, x);
  433. });
  434. };
  435. var mapToObject = function (xs, f) {
  436. var r = {};
  437. for (var i = 0, len = xs.length; i < len; i++) {
  438. var x = xs[i];
  439. r[String(x)] = f(x, i);
  440. }
  441. return r;
  442. };
  443. var pure = function (x) {
  444. return [x];
  445. };
  446. var sort = function (xs, comparator) {
  447. var copy = slice.call(xs, 0);
  448. copy.sort(comparator);
  449. return copy;
  450. };
  451. var head = function (xs) {
  452. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  453. };
  454. var last = function (xs) {
  455. return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
  456. };
  457. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  458. return slice.call(x);
  459. };
  460. var Arr = /*#__PURE__*/Object.freeze({
  461. indexOf: indexOf,
  462. contains: contains,
  463. exists: exists,
  464. range: range,
  465. chunk: chunk,
  466. map: map,
  467. each: each,
  468. eachr: eachr,
  469. partition: partition,
  470. filter: filter,
  471. groupBy: groupBy,
  472. foldr: foldr,
  473. foldl: foldl,
  474. find: find,
  475. findIndex: findIndex,
  476. flatten: flatten,
  477. bind: bind,
  478. forall: forall,
  479. equal: equal,
  480. reverse: reverse,
  481. difference: difference,
  482. mapToObject: mapToObject,
  483. pure: pure,
  484. sort: sort,
  485. head: head,
  486. last: last,
  487. from: from$1
  488. });
  489. var keys = Object.keys;
  490. var hasOwnProperty = Object.hasOwnProperty;
  491. var each$1 = function (obj, f) {
  492. var props = keys(obj);
  493. for (var k = 0, len = props.length; k < len; k++) {
  494. var i = props[k];
  495. var x = obj[i];
  496. f(x, i, obj);
  497. }
  498. };
  499. var map$1 = function (obj, f) {
  500. return tupleMap(obj, function (x, i, obj) {
  501. return {
  502. k: i,
  503. v: f(x, i, obj)
  504. };
  505. });
  506. };
  507. var tupleMap = function (obj, f) {
  508. var r = {};
  509. each$1(obj, function (x, i) {
  510. var tuple = f(x, i, obj);
  511. r[tuple.k] = tuple.v;
  512. });
  513. return r;
  514. };
  515. var get = function (obj, key) {
  516. return has(obj, key) ? Option.from(obj[key]) : Option.none();
  517. };
  518. var has = function (obj, key) {
  519. return hasOwnProperty.call(obj, key);
  520. };
  521. var Immutable = function () {
  522. var fields = [];
  523. for (var _i = 0; _i < arguments.length; _i++) {
  524. fields[_i] = arguments[_i];
  525. }
  526. return function () {
  527. var values = [];
  528. for (var _i = 0; _i < arguments.length; _i++) {
  529. values[_i] = arguments[_i];
  530. }
  531. if (fields.length !== values.length) {
  532. throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
  533. }
  534. var struct = {};
  535. each(fields, function (name, i) {
  536. struct[name] = constant(values[i]);
  537. });
  538. return struct;
  539. };
  540. };
  541. var sort$1 = function (arr) {
  542. return arr.slice(0).sort();
  543. };
  544. var reqMessage = function (required, keys) {
  545. throw new Error('All required keys (' + sort$1(required).join(', ') + ') were not specified. Specified keys were: ' + sort$1(keys).join(', ') + '.');
  546. };
  547. var unsuppMessage = function (unsupported) {
  548. throw new Error('Unsupported keys for object: ' + sort$1(unsupported).join(', '));
  549. };
  550. var validateStrArr = function (label, array) {
  551. if (!isArray(array))
  552. throw new Error('The ' + label + ' fields must be an array. Was: ' + array + '.');
  553. each(array, function (a) {
  554. if (!isString(a))
  555. throw new Error('The value ' + a + ' in the ' + label + ' fields was not a string.');
  556. });
  557. };
  558. var invalidTypeMessage = function (incorrect, type) {
  559. throw new Error('All values need to be of type: ' + type + '. Keys (' + sort$1(incorrect).join(', ') + ') were not.');
  560. };
  561. var checkDupes = function (everything) {
  562. var sorted = sort$1(everything);
  563. var dupe = find(sorted, function (s, i) {
  564. return i < sorted.length - 1 && s === sorted[i + 1];
  565. });
  566. dupe.each(function (d) {
  567. throw new Error('The field: ' + d + ' occurs more than once in the combined fields: [' + sorted.join(', ') + '].');
  568. });
  569. };
  570. var MixedBag = function (required, optional) {
  571. var everything = required.concat(optional);
  572. if (everything.length === 0)
  573. throw new Error('You must specify at least one required or optional field.');
  574. validateStrArr('required', required);
  575. validateStrArr('optional', optional);
  576. checkDupes(everything);
  577. return function (obj) {
  578. var keys$1 = keys(obj);
  579. var allReqd = forall(required, function (req) {
  580. return contains(keys$1, req);
  581. });
  582. if (!allReqd)
  583. reqMessage(required, keys$1);
  584. var unsupported = filter(keys$1, function (key) {
  585. return !contains(everything, key);
  586. });
  587. if (unsupported.length > 0)
  588. unsuppMessage(unsupported);
  589. var r = {};
  590. each(required, function (req) {
  591. r[req] = constant(obj[req]);
  592. });
  593. each(optional, function (opt) {
  594. r[opt] = constant(Object.prototype.hasOwnProperty.call(obj, opt) ? Option.some(obj[opt]) : Option.none());
  595. });
  596. return r;
  597. };
  598. };
  599. var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
  600. var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
  601. var COMMENT = domGlobals.Node.COMMENT_NODE;
  602. var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
  603. var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
  604. var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
  605. var ELEMENT = domGlobals.Node.ELEMENT_NODE;
  606. var TEXT = domGlobals.Node.TEXT_NODE;
  607. var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
  608. var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
  609. var ENTITY = domGlobals.Node.ENTITY_NODE;
  610. var NOTATION = domGlobals.Node.NOTATION_NODE;
  611. var name = function (element) {
  612. var r = element.dom().nodeName;
  613. return r.toLowerCase();
  614. };
  615. var type = function (element) {
  616. return element.dom().nodeType;
  617. };
  618. var value = function (element) {
  619. return element.dom().nodeValue;
  620. };
  621. var isType$1 = function (t) {
  622. return function (element) {
  623. return type(element) === t;
  624. };
  625. };
  626. var isComment = function (element) {
  627. return type(element) === COMMENT || name(element) === '#comment';
  628. };
  629. var isElement = isType$1(ELEMENT);
  630. var isText = isType$1(TEXT);
  631. var isDocument = isType$1(DOCUMENT);
  632. var Node = /*#__PURE__*/Object.freeze({
  633. name: name,
  634. type: type,
  635. value: value,
  636. isElement: isElement,
  637. isText: isText,
  638. isDocument: isDocument,
  639. isComment: isComment
  640. });
  641. var rawSet = function (dom, key, value) {
  642. if (isString(value) || isBoolean(value) || isNumber(value)) {
  643. dom.setAttribute(key, value + '');
  644. } else {
  645. domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  646. throw new Error('Attribute value was not simple');
  647. }
  648. };
  649. var set = function (element, key, value) {
  650. rawSet(element.dom(), key, value);
  651. };
  652. var setAll = function (element, attrs) {
  653. var dom = element.dom();
  654. each$1(attrs, function (v, k) {
  655. rawSet(dom, k, v);
  656. });
  657. };
  658. var get$1 = function (element, key) {
  659. var v = element.dom().getAttribute(key);
  660. return v === null ? undefined : v;
  661. };
  662. var has$1 = function (element, key) {
  663. var dom = element.dom();
  664. return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
  665. };
  666. var remove = function (element, key) {
  667. element.dom().removeAttribute(key);
  668. };
  669. var clone = function (element) {
  670. return foldl(element.dom().attributes, function (acc, attr) {
  671. acc[attr.name] = attr.value;
  672. return acc;
  673. }, {});
  674. };
  675. var checkRange = function (str, substr, start) {
  676. if (substr === '')
  677. return true;
  678. if (str.length < substr.length)
  679. return false;
  680. var x = str.substr(start, start + substr.length);
  681. return x === substr;
  682. };
  683. var contains$1 = function (str, substr) {
  684. return str.indexOf(substr) !== -1;
  685. };
  686. var startsWith = function (str, prefix) {
  687. return checkRange(str, prefix, 0);
  688. };
  689. var endsWith = function (str, suffix) {
  690. return checkRange(str, suffix, str.length - suffix.length);
  691. };
  692. var trim = function (str) {
  693. return str.replace(/^\s+|\s+$/g, '');
  694. };
  695. var isSupported = function (dom) {
  696. return dom.style !== undefined;
  697. };
  698. var cached = function (f) {
  699. var called = false;
  700. var r;
  701. return function () {
  702. var args = [];
  703. for (var _i = 0; _i < arguments.length; _i++) {
  704. args[_i] = arguments[_i];
  705. }
  706. if (!called) {
  707. called = true;
  708. r = f.apply(null, args);
  709. }
  710. return r;
  711. };
  712. };
  713. var fromHtml = function (html, scope) {
  714. var doc = scope || domGlobals.document;
  715. var div = doc.createElement('div');
  716. div.innerHTML = html;
  717. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  718. domGlobals.console.error('HTML does not have a single root node', html);
  719. throw new Error('HTML must have a single root node');
  720. }
  721. return fromDom(div.childNodes[0]);
  722. };
  723. var fromTag = function (tag, scope) {
  724. var doc = scope || domGlobals.document;
  725. var node = doc.createElement(tag);
  726. return fromDom(node);
  727. };
  728. var fromText = function (text, scope) {
  729. var doc = scope || domGlobals.document;
  730. var node = doc.createTextNode(text);
  731. return fromDom(node);
  732. };
  733. var fromDom = function (node) {
  734. if (node === null || node === undefined) {
  735. throw new Error('Node cannot be null or undefined');
  736. }
  737. return { dom: constant(node) };
  738. };
  739. var fromPoint = function (docElm, x, y) {
  740. var doc = docElm.dom();
  741. return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
  742. };
  743. var Element = {
  744. fromHtml: fromHtml,
  745. fromTag: fromTag,
  746. fromText: fromText,
  747. fromDom: fromDom,
  748. fromPoint: fromPoint
  749. };
  750. var inBody = function (element) {
  751. var dom = isText(element) ? element.dom().parentNode : element.dom();
  752. return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
  753. };
  754. var body = cached(function () {
  755. return getBody(Element.fromDom(domGlobals.document));
  756. });
  757. var getBody = function (doc) {
  758. var b = doc.dom().body;
  759. if (b === null || b === undefined) {
  760. throw new Error('Body is not available yet');
  761. }
  762. return Element.fromDom(b);
  763. };
  764. var internalSet = function (dom, property, value) {
  765. if (!isString(value)) {
  766. domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
  767. throw new Error('CSS value must be a string: ' + value);
  768. }
  769. if (isSupported(dom)) {
  770. dom.style.setProperty(property, value);
  771. }
  772. };
  773. var internalRemove = function (dom, property) {
  774. if (isSupported(dom)) {
  775. dom.style.removeProperty(property);
  776. }
  777. };
  778. var set$1 = function (element, property, value) {
  779. var dom = element.dom();
  780. internalSet(dom, property, value);
  781. };
  782. var setAll$1 = function (element, css) {
  783. var dom = element.dom();
  784. each$1(css, function (v, k) {
  785. internalSet(dom, k, v);
  786. });
  787. };
  788. var setOptions = function (element, css) {
  789. var dom = element.dom();
  790. each$1(css, function (v, k) {
  791. v.fold(function () {
  792. internalRemove(dom, k);
  793. }, function (value) {
  794. internalSet(dom, k, value);
  795. });
  796. });
  797. };
  798. var get$2 = function (element, property) {
  799. var dom = element.dom();
  800. var styles = domGlobals.window.getComputedStyle(dom);
  801. var r = styles.getPropertyValue(property);
  802. var v = r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
  803. return v === null ? undefined : v;
  804. };
  805. var getUnsafeProperty = function (dom, property) {
  806. return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
  807. };
  808. var getRaw = function (element, property) {
  809. var dom = element.dom();
  810. var raw = getUnsafeProperty(dom, property);
  811. return Option.from(raw).filter(function (r) {
  812. return r.length > 0;
  813. });
  814. };
  815. var getAllRaw = function (element) {
  816. var css = {};
  817. var dom = element.dom();
  818. if (isSupported(dom)) {
  819. for (var i = 0; i < dom.style.length; i++) {
  820. var ruleName = dom.style.item(i);
  821. css[ruleName] = dom.style[ruleName];
  822. }
  823. }
  824. return css;
  825. };
  826. var isValidValue = function (tag, property, value) {
  827. var element = Element.fromTag(tag);
  828. set$1(element, property, value);
  829. var style = getRaw(element, property);
  830. return style.isSome();
  831. };
  832. var remove$1 = function (element, property) {
  833. var dom = element.dom();
  834. internalRemove(dom, property);
  835. if (has$1(element, 'style') && trim(get$1(element, 'style')) === '') {
  836. remove(element, 'style');
  837. }
  838. };
  839. var preserve = function (element, f) {
  840. var oldStyles = get$1(element, 'style');
  841. var result = f(element);
  842. var restore = oldStyles === undefined ? remove : set;
  843. restore(element, 'style', oldStyles);
  844. return result;
  845. };
  846. var copy = function (source, target) {
  847. var sourceDom = source.dom();
  848. var targetDom = target.dom();
  849. if (isSupported(sourceDom) && isSupported(targetDom)) {
  850. targetDom.style.cssText = sourceDom.style.cssText;
  851. }
  852. };
  853. var reflow = function (e) {
  854. return e.dom().offsetWidth;
  855. };
  856. var transferOne = function (source, destination, style) {
  857. getRaw(source, style).each(function (value) {
  858. if (getRaw(destination, style).isNone()) {
  859. set$1(destination, style, value);
  860. }
  861. });
  862. };
  863. var transfer = function (source, destination, styles) {
  864. if (!isElement(source) || !isElement(destination)) {
  865. return;
  866. }
  867. each(styles, function (style) {
  868. transferOne(source, destination, style);
  869. });
  870. };
  871. var Css = /*#__PURE__*/Object.freeze({
  872. copy: copy,
  873. set: set$1,
  874. preserve: preserve,
  875. setAll: setAll$1,
  876. setOptions: setOptions,
  877. remove: remove$1,
  878. get: get$2,
  879. getRaw: getRaw,
  880. getAllRaw: getAllRaw,
  881. isValidValue: isValidValue,
  882. reflow: reflow,
  883. transfer: transfer
  884. });
  885. var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
  886. var path = function (parts, scope) {
  887. var o = scope !== undefined && scope !== null ? scope : Global;
  888. for (var i = 0; i < parts.length && o !== undefined && o !== null; ++i)
  889. o = o[parts[i]];
  890. return o;
  891. };
  892. var resolve = function (p, scope) {
  893. var parts = p.split('.');
  894. return path(parts, scope);
  895. };
  896. var unsafe = function (name, scope) {
  897. return resolve(name, scope);
  898. };
  899. var getOrDie = function (name, scope) {
  900. var actual = unsafe(name, scope);
  901. if (actual === undefined || actual === null)
  902. throw name + ' not available on this browser';
  903. return actual;
  904. };
  905. var Global$1 = { getOrDie: getOrDie };
  906. var node = function () {
  907. var f = Global$1.getOrDie('Node');
  908. return f;
  909. };
  910. var compareDocumentPosition = function (a, b, match) {
  911. return (a.compareDocumentPosition(b) & match) !== 0;
  912. };
  913. var documentPositionPreceding = function (a, b) {
  914. return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_PRECEDING);
  915. };
  916. var documentPositionContainedBy = function (a, b) {
  917. return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_CONTAINED_BY);
  918. };
  919. var Node$1 = {
  920. documentPositionPreceding: documentPositionPreceding,
  921. documentPositionContainedBy: documentPositionContainedBy
  922. };
  923. var firstMatch = function (regexes, s) {
  924. for (var i = 0; i < regexes.length; i++) {
  925. var x = regexes[i];
  926. if (x.test(s))
  927. return x;
  928. }
  929. return undefined;
  930. };
  931. var find$1 = function (regexes, agent) {
  932. var r = firstMatch(regexes, agent);
  933. if (!r)
  934. return {
  935. major: 0,
  936. minor: 0
  937. };
  938. var group = function (i) {
  939. return Number(agent.replace(r, '$' + i));
  940. };
  941. return nu(group(1), group(2));
  942. };
  943. var detect = function (versionRegexes, agent) {
  944. var cleanedAgent = String(agent).toLowerCase();
  945. if (versionRegexes.length === 0)
  946. return unknown();
  947. return find$1(versionRegexes, cleanedAgent);
  948. };
  949. var unknown = function () {
  950. return nu(0, 0);
  951. };
  952. var nu = function (major, minor) {
  953. return {
  954. major: major,
  955. minor: minor
  956. };
  957. };
  958. var Version = {
  959. nu: nu,
  960. detect: detect,
  961. unknown: unknown
  962. };
  963. var edge = 'Edge';
  964. var chrome = 'Chrome';
  965. var ie = 'IE';
  966. var opera = 'Opera';
  967. var firefox = 'Firefox';
  968. var safari = 'Safari';
  969. var isBrowser = function (name, current) {
  970. return function () {
  971. return current === name;
  972. };
  973. };
  974. var unknown$1 = function () {
  975. return nu$1({
  976. current: undefined,
  977. version: Version.unknown()
  978. });
  979. };
  980. var nu$1 = function (info) {
  981. var current = info.current;
  982. var version = info.version;
  983. return {
  984. current: current,
  985. version: version,
  986. isEdge: isBrowser(edge, current),
  987. isChrome: isBrowser(chrome, current),
  988. isIE: isBrowser(ie, current),
  989. isOpera: isBrowser(opera, current),
  990. isFirefox: isBrowser(firefox, current),
  991. isSafari: isBrowser(safari, current)
  992. };
  993. };
  994. var Browser = {
  995. unknown: unknown$1,
  996. nu: nu$1,
  997. edge: constant(edge),
  998. chrome: constant(chrome),
  999. ie: constant(ie),
  1000. opera: constant(opera),
  1001. firefox: constant(firefox),
  1002. safari: constant(safari)
  1003. };
  1004. var windows = 'Windows';
  1005. var ios = 'iOS';
  1006. var android = 'Android';
  1007. var linux = 'Linux';
  1008. var osx = 'OSX';
  1009. var solaris = 'Solaris';
  1010. var freebsd = 'FreeBSD';
  1011. var isOS = function (name, current) {
  1012. return function () {
  1013. return current === name;
  1014. };
  1015. };
  1016. var unknown$2 = function () {
  1017. return nu$2({
  1018. current: undefined,
  1019. version: Version.unknown()
  1020. });
  1021. };
  1022. var nu$2 = function (info) {
  1023. var current = info.current;
  1024. var version = info.version;
  1025. return {
  1026. current: current,
  1027. version: version,
  1028. isWindows: isOS(windows, current),
  1029. isiOS: isOS(ios, current),
  1030. isAndroid: isOS(android, current),
  1031. isOSX: isOS(osx, current),
  1032. isLinux: isOS(linux, current),
  1033. isSolaris: isOS(solaris, current),
  1034. isFreeBSD: isOS(freebsd, current)
  1035. };
  1036. };
  1037. var OperatingSystem = {
  1038. unknown: unknown$2,
  1039. nu: nu$2,
  1040. windows: constant(windows),
  1041. ios: constant(ios),
  1042. android: constant(android),
  1043. linux: constant(linux),
  1044. osx: constant(osx),
  1045. solaris: constant(solaris),
  1046. freebsd: constant(freebsd)
  1047. };
  1048. var DeviceType = function (os, browser, userAgent) {
  1049. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  1050. var isiPhone = os.isiOS() && !isiPad;
  1051. var isAndroid3 = os.isAndroid() && os.version.major === 3;
  1052. var isAndroid4 = os.isAndroid() && os.version.major === 4;
  1053. var isTablet = isiPad || isAndroid3 || isAndroid4 && /mobile/i.test(userAgent) === true;
  1054. var isTouch = os.isiOS() || os.isAndroid();
  1055. var isPhone = isTouch && !isTablet;
  1056. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  1057. return {
  1058. isiPad: constant(isiPad),
  1059. isiPhone: constant(isiPhone),
  1060. isTablet: constant(isTablet),
  1061. isPhone: constant(isPhone),
  1062. isTouch: constant(isTouch),
  1063. isAndroid: os.isAndroid,
  1064. isiOS: os.isiOS,
  1065. isWebView: constant(iOSwebview)
  1066. };
  1067. };
  1068. var detect$1 = function (candidates, userAgent) {
  1069. var agent = String(userAgent).toLowerCase();
  1070. return find(candidates, function (candidate) {
  1071. return candidate.search(agent);
  1072. });
  1073. };
  1074. var detectBrowser = function (browsers, userAgent) {
  1075. return detect$1(browsers, userAgent).map(function (browser) {
  1076. var version = Version.detect(browser.versionRegexes, userAgent);
  1077. return {
  1078. current: browser.name,
  1079. version: version
  1080. };
  1081. });
  1082. };
  1083. var detectOs = function (oses, userAgent) {
  1084. return detect$1(oses, userAgent).map(function (os) {
  1085. var version = Version.detect(os.versionRegexes, userAgent);
  1086. return {
  1087. current: os.name,
  1088. version: version
  1089. };
  1090. });
  1091. };
  1092. var UaString = {
  1093. detectBrowser: detectBrowser,
  1094. detectOs: detectOs
  1095. };
  1096. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  1097. var checkContains = function (target) {
  1098. return function (uastring) {
  1099. return contains$1(uastring, target);
  1100. };
  1101. };
  1102. var browsers = [
  1103. {
  1104. name: 'Edge',
  1105. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  1106. search: function (uastring) {
  1107. var monstrosity = contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
  1108. return monstrosity;
  1109. }
  1110. },
  1111. {
  1112. name: 'Chrome',
  1113. versionRegexes: [
  1114. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  1115. normalVersionRegex
  1116. ],
  1117. search: function (uastring) {
  1118. return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
  1119. }
  1120. },
  1121. {
  1122. name: 'IE',
  1123. versionRegexes: [
  1124. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  1125. /.*?rv:([0-9]+)\.([0-9]+).*/
  1126. ],
  1127. search: function (uastring) {
  1128. return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
  1129. }
  1130. },
  1131. {
  1132. name: 'Opera',
  1133. versionRegexes: [
  1134. normalVersionRegex,
  1135. /.*?opera\/([0-9]+)\.([0-9]+).*/
  1136. ],
  1137. search: checkContains('opera')
  1138. },
  1139. {
  1140. name: 'Firefox',
  1141. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  1142. search: checkContains('firefox')
  1143. },
  1144. {
  1145. name: 'Safari',
  1146. versionRegexes: [
  1147. normalVersionRegex,
  1148. /.*?cpu os ([0-9]+)_([0-9]+).*/
  1149. ],
  1150. search: function (uastring) {
  1151. return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
  1152. }
  1153. }
  1154. ];
  1155. var oses = [
  1156. {
  1157. name: 'Windows',
  1158. search: checkContains('win'),
  1159. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  1160. },
  1161. {
  1162. name: 'iOS',
  1163. search: function (uastring) {
  1164. return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
  1165. },
  1166. versionRegexes: [
  1167. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  1168. /.*cpu os ([0-9]+)_([0-9]+).*/,
  1169. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  1170. ]
  1171. },
  1172. {
  1173. name: 'Android',
  1174. search: checkContains('android'),
  1175. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  1176. },
  1177. {
  1178. name: 'OSX',
  1179. search: checkContains('os x'),
  1180. versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
  1181. },
  1182. {
  1183. name: 'Linux',
  1184. search: checkContains('linux'),
  1185. versionRegexes: []
  1186. },
  1187. {
  1188. name: 'Solaris',
  1189. search: checkContains('sunos'),
  1190. versionRegexes: []
  1191. },
  1192. {
  1193. name: 'FreeBSD',
  1194. search: checkContains('freebsd'),
  1195. versionRegexes: []
  1196. }
  1197. ];
  1198. var PlatformInfo = {
  1199. browsers: constant(browsers),
  1200. oses: constant(oses)
  1201. };
  1202. var detect$2 = function (userAgent) {
  1203. var browsers = PlatformInfo.browsers();
  1204. var oses = PlatformInfo.oses();
  1205. var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
  1206. var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  1207. var deviceType = DeviceType(os, browser, userAgent);
  1208. return {
  1209. browser: browser,
  1210. os: os,
  1211. deviceType: deviceType
  1212. };
  1213. };
  1214. var PlatformDetection = { detect: detect$2 };
  1215. var detect$3 = cached(function () {
  1216. var userAgent = domGlobals.navigator.userAgent;
  1217. return PlatformDetection.detect(userAgent);
  1218. });
  1219. var PlatformDetection$1 = { detect: detect$3 };
  1220. var ELEMENT$1 = ELEMENT;
  1221. var DOCUMENT$1 = DOCUMENT;
  1222. var is = function (element, selector) {
  1223. var elem = element.dom();
  1224. if (elem.nodeType !== ELEMENT$1) {
  1225. return false;
  1226. } else if (elem.matches !== undefined) {
  1227. return elem.matches(selector);
  1228. } else if (elem.msMatchesSelector !== undefined) {
  1229. return elem.msMatchesSelector(selector);
  1230. } else if (elem.webkitMatchesSelector !== undefined) {
  1231. return elem.webkitMatchesSelector(selector);
  1232. } else if (elem.mozMatchesSelector !== undefined) {
  1233. return elem.mozMatchesSelector(selector);
  1234. } else {
  1235. throw new Error('Browser lacks native selectors');
  1236. }
  1237. };
  1238. var bypassSelector = function (dom) {
  1239. return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
  1240. };
  1241. var all = function (selector, scope) {
  1242. var base = scope === undefined ? domGlobals.document : scope.dom();
  1243. return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
  1244. };
  1245. var one = function (selector, scope) {
  1246. var base = scope === undefined ? domGlobals.document : scope.dom();
  1247. return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
  1248. };
  1249. var eq = function (e1, e2) {
  1250. return e1.dom() === e2.dom();
  1251. };
  1252. var regularContains = function (e1, e2) {
  1253. var d1 = e1.dom();
  1254. var d2 = e2.dom();
  1255. return d1 === d2 ? false : d1.contains(d2);
  1256. };
  1257. var ieContains = function (e1, e2) {
  1258. return Node$1.documentPositionContainedBy(e1.dom(), e2.dom());
  1259. };
  1260. var browser = PlatformDetection$1.detect().browser;
  1261. var contains$2 = browser.isIE() ? ieContains : regularContains;
  1262. var is$1 = is;
  1263. var owner = function (element) {
  1264. return Element.fromDom(element.dom().ownerDocument);
  1265. };
  1266. var defaultView = function (element) {
  1267. var el = element.dom();
  1268. var defView = el.ownerDocument.defaultView;
  1269. return Element.fromDom(defView);
  1270. };
  1271. var parent = function (element) {
  1272. var dom = element.dom();
  1273. return Option.from(dom.parentNode).map(Element.fromDom);
  1274. };
  1275. var parents = function (element, isRoot) {
  1276. var stop = isFunction(isRoot) ? isRoot : constant(false);
  1277. var dom = element.dom();
  1278. var ret = [];
  1279. while (dom.parentNode !== null && dom.parentNode !== undefined) {
  1280. var rawParent = dom.parentNode;
  1281. var p = Element.fromDom(rawParent);
  1282. ret.push(p);
  1283. if (stop(p) === true) {
  1284. break;
  1285. } else {
  1286. dom = rawParent;
  1287. }
  1288. }
  1289. return ret;
  1290. };
  1291. var prevSibling = function (element) {
  1292. var dom = element.dom();
  1293. return Option.from(dom.previousSibling).map(Element.fromDom);
  1294. };
  1295. var nextSibling = function (element) {
  1296. var dom = element.dom();
  1297. return Option.from(dom.nextSibling).map(Element.fromDom);
  1298. };
  1299. var children = function (element) {
  1300. var dom = element.dom();
  1301. return map(dom.childNodes, Element.fromDom);
  1302. };
  1303. var child = function (element, index) {
  1304. var cs = element.dom().childNodes;
  1305. return Option.from(cs[index]).map(Element.fromDom);
  1306. };
  1307. var firstChild = function (element) {
  1308. return child(element, 0);
  1309. };
  1310. var spot = Immutable('element', 'offset');
  1311. var before = function (marker, element) {
  1312. var parent$1 = parent(marker);
  1313. parent$1.each(function (v) {
  1314. v.dom().insertBefore(element.dom(), marker.dom());
  1315. });
  1316. };
  1317. var after = function (marker, element) {
  1318. var sibling = nextSibling(marker);
  1319. sibling.fold(function () {
  1320. var parent$1 = parent(marker);
  1321. parent$1.each(function (v) {
  1322. append(v, element);
  1323. });
  1324. }, function (v) {
  1325. before(v, element);
  1326. });
  1327. };
  1328. var prepend = function (parent, element) {
  1329. var firstChild$1 = firstChild(parent);
  1330. firstChild$1.fold(function () {
  1331. append(parent, element);
  1332. }, function (v) {
  1333. parent.dom().insertBefore(element.dom(), v.dom());
  1334. });
  1335. };
  1336. var append = function (parent, element) {
  1337. parent.dom().appendChild(element.dom());
  1338. };
  1339. var wrap = function (element, wrapper) {
  1340. before(element, wrapper);
  1341. append(wrapper, element);
  1342. };
  1343. var before$1 = function (marker, elements) {
  1344. each(elements, function (x) {
  1345. before(marker, x);
  1346. });
  1347. };
  1348. var after$1 = function (marker, elements) {
  1349. each(elements, function (x, i) {
  1350. var e = i === 0 ? marker : elements[i - 1];
  1351. after(e, x);
  1352. });
  1353. };
  1354. var append$1 = function (parent, elements) {
  1355. each(elements, function (x) {
  1356. append(parent, x);
  1357. });
  1358. };
  1359. var empty = function (element) {
  1360. element.dom().textContent = '';
  1361. each(children(element), function (rogue) {
  1362. remove$2(rogue);
  1363. });
  1364. };
  1365. var remove$2 = function (element) {
  1366. var dom = element.dom();
  1367. if (dom.parentNode !== null) {
  1368. dom.parentNode.removeChild(dom);
  1369. }
  1370. };
  1371. var unwrap = function (wrapper) {
  1372. var children$1 = children(wrapper);
  1373. if (children$1.length > 0) {
  1374. before$1(wrapper, children$1);
  1375. }
  1376. remove$2(wrapper);
  1377. };
  1378. var dimensions = Immutable('width', 'height');
  1379. var grid = Immutable('rows', 'columns');
  1380. var address = Immutable('row', 'column');
  1381. var coords = Immutable('x', 'y');
  1382. var detail = Immutable('element', 'rowspan', 'colspan');
  1383. var detailnew = Immutable('element', 'rowspan', 'colspan', 'isNew');
  1384. var extended = Immutable('element', 'rowspan', 'colspan', 'row', 'column');
  1385. var rowdata = Immutable('element', 'cells', 'section');
  1386. var elementnew = Immutable('element', 'isNew');
  1387. var rowdatanew = Immutable('element', 'cells', 'section', 'isNew');
  1388. var rowcells = Immutable('cells', 'section');
  1389. var rowdetails = Immutable('details', 'section');
  1390. var bounds = Immutable('startRow', 'startCol', 'finishRow', 'finishCol');
  1391. var Structs = {
  1392. dimensions: dimensions,
  1393. grid: grid,
  1394. address: address,
  1395. coords: coords,
  1396. extended: extended,
  1397. detail: detail,
  1398. detailnew: detailnew,
  1399. rowdata: rowdata,
  1400. elementnew: elementnew,
  1401. rowdatanew: rowdatanew,
  1402. rowcells: rowcells,
  1403. rowdetails: rowdetails,
  1404. bounds: bounds
  1405. };
  1406. var ancestors = function (scope, predicate, isRoot) {
  1407. return filter(parents(scope, isRoot), predicate);
  1408. };
  1409. var children$1 = function (scope, predicate) {
  1410. return filter(children(scope), predicate);
  1411. };
  1412. var descendants = function (scope, predicate) {
  1413. var result = [];
  1414. each(children(scope), function (x) {
  1415. if (predicate(x)) {
  1416. result = result.concat([x]);
  1417. }
  1418. result = result.concat(descendants(x, predicate));
  1419. });
  1420. return result;
  1421. };
  1422. var ancestors$1 = function (scope, selector, isRoot) {
  1423. return ancestors(scope, function (e) {
  1424. return is(e, selector);
  1425. }, isRoot);
  1426. };
  1427. var children$2 = function (scope, selector) {
  1428. return children$1(scope, function (e) {
  1429. return is(e, selector);
  1430. });
  1431. };
  1432. var descendants$1 = function (scope, selector) {
  1433. return all(selector, scope);
  1434. };
  1435. function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
  1436. return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
  1437. }
  1438. var ancestor = function (scope, predicate, isRoot) {
  1439. var element = scope.dom();
  1440. var stop = isFunction(isRoot) ? isRoot : constant(false);
  1441. while (element.parentNode) {
  1442. element = element.parentNode;
  1443. var el = Element.fromDom(element);
  1444. if (predicate(el)) {
  1445. return Option.some(el);
  1446. } else if (stop(el)) {
  1447. break;
  1448. }
  1449. }
  1450. return Option.none();
  1451. };
  1452. var closest = function (scope, predicate, isRoot) {
  1453. var is = function (s) {
  1454. return predicate(s);
  1455. };
  1456. return ClosestOrAncestor(is, ancestor, scope, predicate, isRoot);
  1457. };
  1458. var sibling = function (scope, predicate) {
  1459. var element = scope.dom();
  1460. if (!element.parentNode) {
  1461. return Option.none();
  1462. }
  1463. return child$1(Element.fromDom(element.parentNode), function (x) {
  1464. return !eq(scope, x) && predicate(x);
  1465. });
  1466. };
  1467. var child$1 = function (scope, predicate) {
  1468. var result = find(scope.dom().childNodes, compose(predicate, Element.fromDom));
  1469. return result.map(Element.fromDom);
  1470. };
  1471. var descendant = function (scope, predicate) {
  1472. var descend = function (node) {
  1473. for (var i = 0; i < node.childNodes.length; i++) {
  1474. if (predicate(Element.fromDom(node.childNodes[i]))) {
  1475. return Option.some(Element.fromDom(node.childNodes[i]));
  1476. }
  1477. var res = descend(node.childNodes[i]);
  1478. if (res.isSome()) {
  1479. return res;
  1480. }
  1481. }
  1482. return Option.none();
  1483. };
  1484. return descend(scope.dom());
  1485. };
  1486. var first = function (selector) {
  1487. return one(selector);
  1488. };
  1489. var ancestor$1 = function (scope, selector, isRoot) {
  1490. return ancestor(scope, function (e) {
  1491. return is(e, selector);
  1492. }, isRoot);
  1493. };
  1494. var sibling$1 = function (scope, selector) {
  1495. return sibling(scope, function (e) {
  1496. return is(e, selector);
  1497. });
  1498. };
  1499. var child$2 = function (scope, selector) {
  1500. return child$1(scope, function (e) {
  1501. return is(e, selector);
  1502. });
  1503. };
  1504. var descendant$1 = function (scope, selector) {
  1505. return one(selector, scope);
  1506. };
  1507. var closest$1 = function (scope, selector, isRoot) {
  1508. return ClosestOrAncestor(is, ancestor$1, scope, selector, isRoot);
  1509. };
  1510. var SelectorFind = /*#__PURE__*/Object.freeze({
  1511. first: first,
  1512. ancestor: ancestor$1,
  1513. sibling: sibling$1,
  1514. child: child$2,
  1515. descendant: descendant$1,
  1516. closest: closest$1
  1517. });
  1518. var firstLayer = function (scope, selector) {
  1519. return filterFirstLayer(scope, selector, constant(true));
  1520. };
  1521. var filterFirstLayer = function (scope, selector, predicate) {
  1522. return bind(children(scope), function (x) {
  1523. return is(x, selector) ? predicate(x) ? [x] : [] : filterFirstLayer(x, selector, predicate);
  1524. });
  1525. };
  1526. var LayerSelector = {
  1527. firstLayer: firstLayer,
  1528. filterFirstLayer: filterFirstLayer
  1529. };
  1530. var lookup = function (tags, element, _isRoot) {
  1531. var isRoot = _isRoot !== undefined ? _isRoot : constant(false);
  1532. if (isRoot(element)) {
  1533. return Option.none();
  1534. }
  1535. if (contains(tags, name(element))) {
  1536. return Option.some(element);
  1537. }
  1538. var isRootOrUpperTable = function (elm) {
  1539. return is(elm, 'table') || isRoot(elm);
  1540. };
  1541. return ancestor$1(element, tags.join(','), isRootOrUpperTable);
  1542. };
  1543. var cell = function (element, isRoot) {
  1544. return lookup([
  1545. 'td',
  1546. 'th'
  1547. ], element, isRoot);
  1548. };
  1549. var cells = function (ancestor) {
  1550. return LayerSelector.firstLayer(ancestor, 'th,td');
  1551. };
  1552. var notCell = function (element, isRoot) {
  1553. return lookup([
  1554. 'caption',
  1555. 'tr',
  1556. 'tbody',
  1557. 'tfoot',
  1558. 'thead'
  1559. ], element, isRoot);
  1560. };
  1561. var neighbours = function (selector, element) {
  1562. return parent(element).map(function (parent) {
  1563. return children$2(parent, selector);
  1564. });
  1565. };
  1566. var neighbourCells = curry(neighbours, 'th,td');
  1567. var neighbourRows = curry(neighbours, 'tr');
  1568. var firstCell = function (ancestor) {
  1569. return descendant$1(ancestor, 'th,td');
  1570. };
  1571. var table = function (element, isRoot) {
  1572. return closest$1(element, 'table', isRoot);
  1573. };
  1574. var row = function (element, isRoot) {
  1575. return lookup(['tr'], element, isRoot);
  1576. };
  1577. var rows = function (ancestor) {
  1578. return LayerSelector.firstLayer(ancestor, 'tr');
  1579. };
  1580. var attr = function (element, property) {
  1581. return parseInt(get$1(element, property), 10);
  1582. };
  1583. var grid$1 = function (element, rowProp, colProp) {
  1584. var rowsCount = attr(element, rowProp);
  1585. var cols = attr(element, colProp);
  1586. return Structs.grid(rowsCount, cols);
  1587. };
  1588. var TableLookup = {
  1589. cell: cell,
  1590. firstCell: firstCell,
  1591. cells: cells,
  1592. neighbourCells: neighbourCells,
  1593. table: table,
  1594. row: row,
  1595. rows: rows,
  1596. notCell: notCell,
  1597. neighbourRows: neighbourRows,
  1598. attr: attr,
  1599. grid: grid$1
  1600. };
  1601. var fromTable = function (table) {
  1602. var rows = TableLookup.rows(table);
  1603. return map(rows, function (row) {
  1604. var element = row;
  1605. var parent$1 = parent(element);
  1606. var parentSection = parent$1.map(function (p) {
  1607. var parentName = name(p);
  1608. return parentName === 'tfoot' || parentName === 'thead' || parentName === 'tbody' ? parentName : 'tbody';
  1609. }).getOr('tbody');
  1610. var cells = map(TableLookup.cells(row), function (cell) {
  1611. var rowspan = has$1(cell, 'rowspan') ? parseInt(get$1(cell, 'rowspan'), 10) : 1;
  1612. var colspan = has$1(cell, 'colspan') ? parseInt(get$1(cell, 'colspan'), 10) : 1;
  1613. return Structs.detail(cell, rowspan, colspan);
  1614. });
  1615. return Structs.rowdata(element, cells, parentSection);
  1616. });
  1617. };
  1618. var fromPastedRows = function (rows, example) {
  1619. return map(rows, function (row) {
  1620. var cells = map(TableLookup.cells(row), function (cell) {
  1621. var rowspan = has$1(cell, 'rowspan') ? parseInt(get$1(cell, 'rowspan'), 10) : 1;
  1622. var colspan = has$1(cell, 'colspan') ? parseInt(get$1(cell, 'colspan'), 10) : 1;
  1623. return Structs.detail(cell, rowspan, colspan);
  1624. });
  1625. return Structs.rowdata(row, cells, example.section());
  1626. });
  1627. };
  1628. var DetailsList = {
  1629. fromTable: fromTable,
  1630. fromPastedRows: fromPastedRows
  1631. };
  1632. var key = function (row, column) {
  1633. return row + ',' + column;
  1634. };
  1635. var getAt = function (warehouse, row, column) {
  1636. var raw = warehouse.access()[key(row, column)];
  1637. return raw !== undefined ? Option.some(raw) : Option.none();
  1638. };
  1639. var findItem = function (warehouse, item, comparator) {
  1640. var filtered = filterItems(warehouse, function (detail) {
  1641. return comparator(item, detail.element());
  1642. });
  1643. return filtered.length > 0 ? Option.some(filtered[0]) : Option.none();
  1644. };
  1645. var filterItems = function (warehouse, predicate) {
  1646. var all = bind(warehouse.all(), function (r) {
  1647. return r.cells();
  1648. });
  1649. return filter(all, predicate);
  1650. };
  1651. var generate = function (list) {
  1652. var access = {};
  1653. var cells = [];
  1654. var maxRows = list.length;
  1655. var maxColumns = 0;
  1656. each(list, function (details, r) {
  1657. var currentRow = [];
  1658. each(details.cells(), function (detail, c) {
  1659. var start = 0;
  1660. while (access[key(r, start)] !== undefined) {
  1661. start++;
  1662. }
  1663. var current = Structs.extended(detail.element(), detail.rowspan(), detail.colspan(), r, start);
  1664. for (var i = 0; i < detail.colspan(); i++) {
  1665. for (var j = 0; j < detail.rowspan(); j++) {
  1666. var cr = r + j;
  1667. var cc = start + i;
  1668. var newpos = key(cr, cc);
  1669. access[newpos] = current;
  1670. maxColumns = Math.max(maxColumns, cc + 1);
  1671. }
  1672. }
  1673. currentRow.push(current);
  1674. });
  1675. cells.push(Structs.rowdata(details.element(), currentRow, details.section()));
  1676. });
  1677. var grid = Structs.grid(maxRows, maxColumns);
  1678. return {
  1679. grid: constant(grid),
  1680. access: constant(access),
  1681. all: constant(cells)
  1682. };
  1683. };
  1684. var justCells = function (warehouse) {
  1685. var rows = map(warehouse.all(), function (w) {
  1686. return w.cells();
  1687. });
  1688. return flatten(rows);
  1689. };
  1690. var Warehouse = {
  1691. generate: generate,
  1692. getAt: getAt,
  1693. findItem: findItem,
  1694. filterItems: filterItems,
  1695. justCells: justCells
  1696. };
  1697. var statsStruct = Immutable('minRow', 'minCol', 'maxRow', 'maxCol');
  1698. var findSelectedStats = function (house, isSelected) {
  1699. var totalColumns = house.grid().columns();
  1700. var totalRows = house.grid().rows();
  1701. var minRow = totalRows;
  1702. var minCol = totalColumns;
  1703. var maxRow = 0;
  1704. var maxCol = 0;
  1705. each$1(house.access(), function (detail) {
  1706. if (isSelected(detail)) {
  1707. var startRow = detail.row();
  1708. var endRow = startRow + detail.rowspan() - 1;
  1709. var startCol = detail.column();
  1710. var endCol = startCol + detail.colspan() - 1;
  1711. if (startRow < minRow) {
  1712. minRow = startRow;
  1713. } else if (endRow > maxRow) {
  1714. maxRow = endRow;
  1715. }
  1716. if (startCol < minCol) {
  1717. minCol = startCol;
  1718. } else if (endCol > maxCol) {
  1719. maxCol = endCol;
  1720. }
  1721. }
  1722. });
  1723. return statsStruct(minRow, minCol, maxRow, maxCol);
  1724. };
  1725. var makeCell = function (list, seenSelected, rowIndex) {
  1726. var row = list[rowIndex].element();
  1727. var td = Element.fromTag('td');
  1728. append(td, Element.fromTag('br'));
  1729. var f = seenSelected ? append : prepend;
  1730. f(row, td);
  1731. };
  1732. var fillInGaps = function (list, house, stats, isSelected) {
  1733. var totalColumns = house.grid().columns();
  1734. var totalRows = house.grid().rows();
  1735. for (var i = 0; i < totalRows; i++) {
  1736. var seenSelected = false;
  1737. for (var j = 0; j < totalColumns; j++) {
  1738. if (!(i < stats.minRow() || i > stats.maxRow() || j < stats.minCol() || j > stats.maxCol())) {
  1739. var needCell = Warehouse.getAt(house, i, j).filter(isSelected).isNone();
  1740. if (needCell) {
  1741. makeCell(list, seenSelected, i);
  1742. } else {
  1743. seenSelected = true;
  1744. }
  1745. }
  1746. }
  1747. }
  1748. };
  1749. var clean = function (table, stats) {
  1750. var emptyRows = filter(LayerSelector.firstLayer(table, 'tr'), function (row) {
  1751. return row.dom().childElementCount === 0;
  1752. });
  1753. each(emptyRows, remove$2);
  1754. if (stats.minCol() === stats.maxCol() || stats.minRow() === stats.maxRow()) {
  1755. each(LayerSelector.firstLayer(table, 'th,td'), function (cell) {
  1756. remove(cell, 'rowspan');
  1757. remove(cell, 'colspan');
  1758. });
  1759. }
  1760. remove(table, 'width');
  1761. remove(table, 'height');
  1762. remove$1(table, 'width');
  1763. remove$1(table, 'height');
  1764. };
  1765. var extract = function (table, selectedSelector) {
  1766. var isSelected = function (detail) {
  1767. return is(detail.element(), selectedSelector);
  1768. };
  1769. var list = DetailsList.fromTable(table);
  1770. var house = Warehouse.generate(list);
  1771. var stats = findSelectedStats(house, isSelected);
  1772. var selector = 'th:not(' + selectedSelector + ')' + ',td:not(' + selectedSelector + ')';
  1773. var unselectedCells = LayerSelector.filterFirstLayer(table, 'th,td', function (cell) {
  1774. return is(cell, selector);
  1775. });
  1776. each(unselectedCells, remove$2);
  1777. fillInGaps(list, house, stats, isSelected);
  1778. clean(table, stats);
  1779. return table;
  1780. };
  1781. var CopySelected = { extract: extract };
  1782. function NodeValue (is, name) {
  1783. var get = function (element) {
  1784. if (!is(element)) {
  1785. throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
  1786. }
  1787. return getOption(element).getOr('');
  1788. };
  1789. var getOptionIE10 = function (element) {
  1790. try {
  1791. return getOptionSafe(element);
  1792. } catch (e) {
  1793. return Option.none();
  1794. }
  1795. };
  1796. var getOptionSafe = function (element) {
  1797. return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
  1798. };
  1799. var browser = PlatformDetection$1.detect().browser;
  1800. var getOption = browser.isIE() && browser.version.major === 10 ? getOptionIE10 : getOptionSafe;
  1801. var set = function (element, value) {
  1802. if (!is(element)) {
  1803. throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
  1804. }
  1805. element.dom().nodeValue = value;
  1806. };
  1807. return {
  1808. get: get,
  1809. getOption: getOption,
  1810. set: set
  1811. };
  1812. }
  1813. var api = NodeValue(isText, 'text');
  1814. var get$3 = function (element) {
  1815. return api.get(element);
  1816. };
  1817. var getOption = function (element) {
  1818. return api.getOption(element);
  1819. };
  1820. var set$2 = function (element, value) {
  1821. api.set(element, value);
  1822. };
  1823. var getEnd = function (element) {
  1824. return name(element) === 'img' ? 1 : getOption(element).fold(function () {
  1825. return children(element).length;
  1826. }, function (v) {
  1827. return v.length;
  1828. });
  1829. };
  1830. var NBSP = '\xA0';
  1831. var isTextNodeWithCursorPosition = function (el) {
  1832. return getOption(el).filter(function (text) {
  1833. return text.trim().length !== 0 || text.indexOf(NBSP) > -1;
  1834. }).isSome();
  1835. };
  1836. var elementsWithCursorPosition = [
  1837. 'img',
  1838. 'br'
  1839. ];
  1840. var isCursorPosition = function (elem) {
  1841. var hasCursorPosition = isTextNodeWithCursorPosition(elem);
  1842. return hasCursorPosition || contains(elementsWithCursorPosition, name(elem));
  1843. };
  1844. var first$1 = function (element) {
  1845. return descendant(element, isCursorPosition);
  1846. };
  1847. var last$1 = function (element) {
  1848. return descendantRtl(element, isCursorPosition);
  1849. };
  1850. var descendantRtl = function (scope, predicate) {
  1851. var descend = function (element) {
  1852. var children$1 = children(element);
  1853. for (var i = children$1.length - 1; i >= 0; i--) {
  1854. var child = children$1[i];
  1855. if (predicate(child)) {
  1856. return Option.some(child);
  1857. }
  1858. var res = descend(child);
  1859. if (res.isSome()) {
  1860. return res;
  1861. }
  1862. }
  1863. return Option.none();
  1864. };
  1865. return descend(scope);
  1866. };
  1867. var clone$1 = function (original, isDeep) {
  1868. return Element.fromDom(original.dom().cloneNode(isDeep));
  1869. };
  1870. var shallow = function (original) {
  1871. return clone$1(original, false);
  1872. };
  1873. var deep = function (original) {
  1874. return clone$1(original, true);
  1875. };
  1876. var shallowAs = function (original, tag) {
  1877. var nu = Element.fromTag(tag);
  1878. var attributes = clone(original);
  1879. setAll(nu, attributes);
  1880. return nu;
  1881. };
  1882. var copy$1 = function (original, tag) {
  1883. var nu = shallowAs(original, tag);
  1884. var cloneChildren = children(deep(original));
  1885. append$1(nu, cloneChildren);
  1886. return nu;
  1887. };
  1888. var createCell = function () {
  1889. var td = Element.fromTag('td');
  1890. append(td, Element.fromTag('br'));
  1891. return td;
  1892. };
  1893. var replace = function (cell, tag, attrs) {
  1894. var replica = copy$1(cell, tag);
  1895. each$1(attrs, function (v, k) {
  1896. if (v === null) {
  1897. remove(replica, k);
  1898. } else {
  1899. set(replica, k, v);
  1900. }
  1901. });
  1902. return replica;
  1903. };
  1904. var pasteReplace = function (cellContent) {
  1905. return cellContent;
  1906. };
  1907. var newRow = function (doc) {
  1908. return function () {
  1909. return Element.fromTag('tr', doc.dom());
  1910. };
  1911. };
  1912. var cloneFormats = function (oldCell, newCell, formats) {
  1913. var first = first$1(oldCell);
  1914. return first.map(function (firstText) {
  1915. var formatSelector = formats.join(',');
  1916. var parents = ancestors$1(firstText, formatSelector, function (element) {
  1917. return eq(element, oldCell);
  1918. });
  1919. return foldr(parents, function (last, parent) {
  1920. var clonedFormat = shallow(parent);
  1921. remove(clonedFormat, 'contenteditable');
  1922. append(last, clonedFormat);
  1923. return clonedFormat;
  1924. }, newCell);
  1925. }).getOr(newCell);
  1926. };
  1927. var cellOperations = function (mutate, doc, formatsToClone) {
  1928. var newCell = function (prev) {
  1929. var docu = owner(prev.element());
  1930. var td = Element.fromTag(name(prev.element()), docu.dom());
  1931. var formats = formatsToClone.getOr([
  1932. 'strong',
  1933. 'em',
  1934. 'b',
  1935. 'i',
  1936. 'span',
  1937. 'font',
  1938. 'h1',
  1939. 'h2',
  1940. 'h3',
  1941. 'h4',
  1942. 'h5',
  1943. 'h6',
  1944. 'p',
  1945. 'div'
  1946. ]);
  1947. var lastNode = formats.length > 0 ? cloneFormats(prev.element(), td, formats) : td;
  1948. append(lastNode, Element.fromTag('br'));
  1949. copy(prev.element(), td);
  1950. remove$1(td, 'height');
  1951. if (prev.colspan() !== 1) {
  1952. remove$1(prev.element(), 'width');
  1953. }
  1954. mutate(prev.element(), td);
  1955. return td;
  1956. };
  1957. return {
  1958. row: newRow(doc),
  1959. cell: newCell,
  1960. replace: replace,
  1961. gap: createCell
  1962. };
  1963. };
  1964. var paste = function (doc) {
  1965. return {
  1966. row: newRow(doc),
  1967. cell: createCell,
  1968. replace: pasteReplace,
  1969. gap: createCell
  1970. };
  1971. };
  1972. var TableFill = {
  1973. cellOperations: cellOperations,
  1974. paste: paste
  1975. };
  1976. var fromHtml$1 = function (html, scope) {
  1977. var doc = scope || domGlobals.document;
  1978. var div = doc.createElement('div');
  1979. div.innerHTML = html;
  1980. return children(Element.fromDom(div));
  1981. };
  1982. var TagBoundaries = [
  1983. 'body',
  1984. 'p',
  1985. 'div',
  1986. 'article',
  1987. 'aside',
  1988. 'figcaption',
  1989. 'figure',
  1990. 'footer',
  1991. 'header',
  1992. 'nav',
  1993. 'section',
  1994. 'ol',
  1995. 'ul',
  1996. 'li',
  1997. 'table',
  1998. 'thead',
  1999. 'tbody',
  2000. 'tfoot',
  2001. 'caption',
  2002. 'tr',
  2003. 'td',
  2004. 'th',
  2005. 'h1',
  2006. 'h2',
  2007. 'h3',
  2008. 'h4',
  2009. 'h5',
  2010. 'h6',
  2011. 'blockquote',
  2012. 'pre',
  2013. 'address'
  2014. ];
  2015. function DomUniverse () {
  2016. var clone$1 = function (element) {
  2017. return Element.fromDom(element.dom().cloneNode(false));
  2018. };
  2019. var document = function (element) {
  2020. return element.dom().ownerDocument;
  2021. };
  2022. var isBoundary = function (element) {
  2023. if (!isElement(element))
  2024. return false;
  2025. if (name(element) === 'body')
  2026. return true;
  2027. return contains(TagBoundaries, name(element));
  2028. };
  2029. var isEmptyTag = function (element) {
  2030. if (!isElement(element))
  2031. return false;
  2032. return contains([
  2033. 'br',
  2034. 'img',
  2035. 'hr',
  2036. 'input'
  2037. ], name(element));
  2038. };
  2039. var comparePosition = function (element, other) {
  2040. return element.dom().compareDocumentPosition(other.dom());
  2041. };
  2042. var copyAttributesTo = function (source, destination) {
  2043. var as = clone(source);
  2044. setAll(destination, as);
  2045. };
  2046. return {
  2047. up: constant({
  2048. selector: ancestor$1,
  2049. closest: closest$1,
  2050. predicate: ancestor,
  2051. all: parents
  2052. }),
  2053. down: constant({
  2054. selector: descendants$1,
  2055. predicate: descendants
  2056. }),
  2057. styles: constant({
  2058. get: get$2,
  2059. getRaw: getRaw,
  2060. set: set$1,
  2061. remove: remove$1
  2062. }),
  2063. attrs: constant({
  2064. get: get$1,
  2065. set: set,
  2066. remove: remove,
  2067. copyTo: copyAttributesTo
  2068. }),
  2069. insert: constant({
  2070. before: before,
  2071. after: after,
  2072. afterAll: after$1,
  2073. append: append,
  2074. appendAll: append$1,
  2075. prepend: prepend,
  2076. wrap: wrap
  2077. }),
  2078. remove: constant({
  2079. unwrap: unwrap,
  2080. remove: remove$2
  2081. }),
  2082. create: constant({
  2083. nu: Element.fromTag,
  2084. clone: clone$1,
  2085. text: Element.fromText
  2086. }),
  2087. query: constant({
  2088. comparePosition: comparePosition,
  2089. prevSibling: prevSibling,
  2090. nextSibling: nextSibling
  2091. }),
  2092. property: constant({
  2093. children: children,
  2094. name: name,
  2095. parent: parent,
  2096. document: document,
  2097. isText: isText,
  2098. isComment: isComment,
  2099. isElement: isElement,
  2100. getText: get$3,
  2101. setText: set$2,
  2102. isBoundary: isBoundary,
  2103. isEmptyTag: isEmptyTag
  2104. }),
  2105. eq: eq,
  2106. is: is$1
  2107. };
  2108. }
  2109. var leftRight = Immutable('left', 'right');
  2110. var bisect = function (universe, parent, child) {
  2111. var children = universe.property().children(parent);
  2112. var index = findIndex(children, curry(universe.eq, child));
  2113. return index.map(function (ind) {
  2114. return {
  2115. before: constant(children.slice(0, ind)),
  2116. after: constant(children.slice(ind + 1))
  2117. };
  2118. });
  2119. };
  2120. var breakToRight = function (universe, parent, child) {
  2121. return bisect(universe, parent, child).map(function (parts) {
  2122. var second = universe.create().clone(parent);
  2123. universe.insert().appendAll(second, parts.after());
  2124. universe.insert().after(parent, second);
  2125. return leftRight(parent, second);
  2126. });
  2127. };
  2128. var breakToLeft = function (universe, parent, child) {
  2129. return bisect(universe, parent, child).map(function (parts) {
  2130. var prior = universe.create().clone(parent);
  2131. universe.insert().appendAll(prior, parts.before().concat([child]));
  2132. universe.insert().appendAll(parent, parts.after());
  2133. universe.insert().before(parent, prior);
  2134. return leftRight(prior, parent);
  2135. });
  2136. };
  2137. var breakPath = function (universe, item, isTop, breaker) {
  2138. var result = Immutable('first', 'second', 'splits');
  2139. var next = function (child, group, splits) {
  2140. var fallback = result(child, Option.none(), splits);
  2141. if (isTop(child))
  2142. return result(child, group, splits);
  2143. else {
  2144. return universe.property().parent(child).bind(function (parent) {
  2145. return breaker(universe, parent, child).map(function (breakage) {
  2146. var extra = [{
  2147. first: breakage.left,
  2148. second: breakage.right
  2149. }];
  2150. var nextChild = isTop(parent) ? parent : breakage.left();
  2151. return next(nextChild, Option.some(breakage.right()), splits.concat(extra));
  2152. }).getOr(fallback);
  2153. });
  2154. }
  2155. };
  2156. return next(item, Option.none(), []);
  2157. };
  2158. var Breaker = {
  2159. breakToLeft: breakToLeft,
  2160. breakToRight: breakToRight,
  2161. breakPath: breakPath
  2162. };
  2163. var all$1 = function (universe, look, elements, f) {
  2164. var head = elements[0];
  2165. var tail = elements.slice(1);
  2166. return f(universe, look, head, tail);
  2167. };
  2168. var oneAll = function (universe, look, elements) {
  2169. return elements.length > 0 ? all$1(universe, look, elements, unsafeOne) : Option.none();
  2170. };
  2171. var unsafeOne = function (universe, look, head, tail) {
  2172. var start = look(universe, head);
  2173. return foldr(tail, function (b, a) {
  2174. var current = look(universe, a);
  2175. return commonElement(universe, b, current);
  2176. }, start);
  2177. };
  2178. var commonElement = function (universe, start, end) {
  2179. return start.bind(function (s) {
  2180. return end.filter(curry(universe.eq, s));
  2181. });
  2182. };
  2183. var Shared = { oneAll: oneAll };
  2184. var eq$1 = function (universe, item) {
  2185. return curry(universe.eq, item);
  2186. };
  2187. var unsafeSubset = function (universe, common, ps1, ps2) {
  2188. var children = universe.property().children(common);
  2189. if (universe.eq(common, ps1[0]))
  2190. return Option.some([ps1[0]]);
  2191. if (universe.eq(common, ps2[0]))
  2192. return Option.some([ps2[0]]);
  2193. var finder = function (ps) {
  2194. var topDown = reverse(ps);
  2195. var index = findIndex(topDown, eq$1(universe, common)).getOr(-1);
  2196. var item = index < topDown.length - 1 ? topDown[index + 1] : topDown[index];
  2197. return findIndex(children, eq$1(universe, item));
  2198. };
  2199. var startIndex = finder(ps1);
  2200. var endIndex = finder(ps2);
  2201. return startIndex.bind(function (sIndex) {
  2202. return endIndex.map(function (eIndex) {
  2203. var first = Math.min(sIndex, eIndex);
  2204. var last = Math.max(sIndex, eIndex);
  2205. return children.slice(first, last + 1);
  2206. });
  2207. });
  2208. };
  2209. var ancestors$2 = function (universe, start, end, _isRoot) {
  2210. var isRoot = _isRoot !== undefined ? _isRoot : constant(false);
  2211. var ps1 = [start].concat(universe.up().all(start));
  2212. var ps2 = [end].concat(universe.up().all(end));
  2213. var prune = function (path) {
  2214. var index = findIndex(path, isRoot);
  2215. return index.fold(function () {
  2216. return path;
  2217. }, function (ind) {
  2218. return path.slice(0, ind + 1);
  2219. });
  2220. };
  2221. var pruned1 = prune(ps1);
  2222. var pruned2 = prune(ps2);
  2223. var shared = find(pruned1, function (x) {
  2224. return exists(pruned2, eq$1(universe, x));
  2225. });
  2226. return {
  2227. firstpath: constant(pruned1),
  2228. secondpath: constant(pruned2),
  2229. shared: constant(shared)
  2230. };
  2231. };
  2232. var subset = function (universe, start, end) {
  2233. var ancs = ancestors$2(universe, start, end);
  2234. return ancs.shared().bind(function (shared) {
  2235. return unsafeSubset(universe, shared, ancs.firstpath(), ancs.secondpath());
  2236. });
  2237. };
  2238. var Subset = {
  2239. subset: subset,
  2240. ancestors: ancestors$2
  2241. };
  2242. var sharedOne = function (universe, look, elements) {
  2243. return Shared.oneAll(universe, look, elements);
  2244. };
  2245. var subset$1 = function (universe, start, finish) {
  2246. return Subset.subset(universe, start, finish);
  2247. };
  2248. var ancestors$3 = function (universe, start, finish, _isRoot) {
  2249. return Subset.ancestors(universe, start, finish, _isRoot);
  2250. };
  2251. var breakToLeft$1 = function (universe, parent, child) {
  2252. return Breaker.breakToLeft(universe, parent, child);
  2253. };
  2254. var breakToRight$1 = function (universe, parent, child) {
  2255. return Breaker.breakToRight(universe, parent, child);
  2256. };
  2257. var breakPath$1 = function (universe, child, isTop, breaker) {
  2258. return Breaker.breakPath(universe, child, isTop, breaker);
  2259. };
  2260. var Parent = {
  2261. sharedOne: sharedOne,
  2262. subset: subset$1,
  2263. ancestors: ancestors$3,
  2264. breakToLeft: breakToLeft$1,
  2265. breakToRight: breakToRight$1,
  2266. breakPath: breakPath$1
  2267. };
  2268. var universe = DomUniverse();
  2269. var sharedOne$1 = function (look, elements) {
  2270. return Parent.sharedOne(universe, function (universe, element) {
  2271. return look(element);
  2272. }, elements);
  2273. };
  2274. var subset$2 = function (start, finish) {
  2275. return Parent.subset(universe, start, finish);
  2276. };
  2277. var ancestors$4 = function (start, finish, _isRoot) {
  2278. return Parent.ancestors(universe, start, finish, _isRoot);
  2279. };
  2280. var breakToLeft$2 = function (parent, child) {
  2281. return Parent.breakToLeft(universe, parent, child);
  2282. };
  2283. var breakToRight$2 = function (parent, child) {
  2284. return Parent.breakToRight(universe, parent, child);
  2285. };
  2286. var breakPath$2 = function (child, isTop, breaker) {
  2287. return Parent.breakPath(universe, child, isTop, function (u, p, c) {
  2288. return breaker(p, c);
  2289. });
  2290. };
  2291. var DomParent = {
  2292. sharedOne: sharedOne$1,
  2293. subset: subset$2,
  2294. ancestors: ancestors$4,
  2295. breakToLeft: breakToLeft$2,
  2296. breakToRight: breakToRight$2,
  2297. breakPath: breakPath$2
  2298. };
  2299. var inSelection = function (bounds, detail) {
  2300. var leftEdge = detail.column();
  2301. var rightEdge = detail.column() + detail.colspan() - 1;
  2302. var topEdge = detail.row();
  2303. var bottomEdge = detail.row() + detail.rowspan() - 1;
  2304. return leftEdge <= bounds.finishCol() && rightEdge >= bounds.startCol() && (topEdge <= bounds.finishRow() && bottomEdge >= bounds.startRow());
  2305. };
  2306. var isWithin = function (bounds, detail) {
  2307. return detail.column() >= bounds.startCol() && detail.column() + detail.colspan() - 1 <= bounds.finishCol() && detail.row() >= bounds.startRow() && detail.row() + detail.rowspan() - 1 <= bounds.finishRow();
  2308. };
  2309. var isRectangular = function (warehouse, bounds) {
  2310. var isRect = true;
  2311. var detailIsWithin = curry(isWithin, bounds);
  2312. for (var i = bounds.startRow(); i <= bounds.finishRow(); i++) {
  2313. for (var j = bounds.startCol(); j <= bounds.finishCol(); j++) {
  2314. isRect = isRect && Warehouse.getAt(warehouse, i, j).exists(detailIsWithin);
  2315. }
  2316. }
  2317. return isRect ? Option.some(bounds) : Option.none();
  2318. };
  2319. var CellBounds = {
  2320. inSelection: inSelection,
  2321. isWithin: isWithin,
  2322. isRectangular: isRectangular
  2323. };
  2324. var getBounds = function (detailA, detailB) {
  2325. return Structs.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));
  2326. };
  2327. var getAnyBox = function (warehouse, startCell, finishCell) {
  2328. var startCoords = Warehouse.findItem(warehouse, startCell, eq);
  2329. var finishCoords = Warehouse.findItem(warehouse, finishCell, eq);
  2330. return startCoords.bind(function (sc) {
  2331. return finishCoords.map(function (fc) {
  2332. return getBounds(sc, fc);
  2333. });
  2334. });
  2335. };
  2336. var getBox = function (warehouse, startCell, finishCell) {
  2337. return getAnyBox(warehouse, startCell, finishCell).bind(function (bounds) {
  2338. return CellBounds.isRectangular(warehouse, bounds);
  2339. });
  2340. };
  2341. var CellGroup = {
  2342. getAnyBox: getAnyBox,
  2343. getBox: getBox
  2344. };
  2345. var moveBy = function (warehouse, cell, row, column) {
  2346. return Warehouse.findItem(warehouse, cell, eq).bind(function (detail) {
  2347. var startRow = row > 0 ? detail.row() + detail.rowspan() - 1 : detail.row();
  2348. var startCol = column > 0 ? detail.column() + detail.colspan() - 1 : detail.column();
  2349. var dest = Warehouse.getAt(warehouse, startRow + row, startCol + column);
  2350. return dest.map(function (d) {
  2351. return d.element();
  2352. });
  2353. });
  2354. };
  2355. var intercepts = function (warehouse, start, finish) {
  2356. return CellGroup.getAnyBox(warehouse, start, finish).map(function (bounds) {
  2357. var inside = Warehouse.filterItems(warehouse, curry(CellBounds.inSelection, bounds));
  2358. return map(inside, function (detail) {
  2359. return detail.element();
  2360. });
  2361. });
  2362. };
  2363. var parentCell = function (warehouse, innerCell) {
  2364. var isContainedBy = function (c1, c2) {
  2365. return contains$2(c2, c1);
  2366. };
  2367. return Warehouse.findItem(warehouse, innerCell, isContainedBy).bind(function (detail) {
  2368. return detail.element();
  2369. });
  2370. };
  2371. var CellFinder = {
  2372. moveBy: moveBy,
  2373. intercepts: intercepts,
  2374. parentCell: parentCell
  2375. };
  2376. var moveBy$1 = function (cell, deltaRow, deltaColumn) {
  2377. return TableLookup.table(cell).bind(function (table) {
  2378. var warehouse = getWarehouse(table);
  2379. return CellFinder.moveBy(warehouse, cell, deltaRow, deltaColumn);
  2380. });
  2381. };
  2382. var intercepts$1 = function (table, first, last) {
  2383. var warehouse = getWarehouse(table);
  2384. return CellFinder.intercepts(warehouse, first, last);
  2385. };
  2386. var nestedIntercepts = function (table, first, firstTable, last, lastTable) {
  2387. var warehouse = getWarehouse(table);
  2388. var startCell = eq(table, firstTable) ? first : CellFinder.parentCell(warehouse, first);
  2389. var lastCell = eq(table, lastTable) ? last : CellFinder.parentCell(warehouse, last);
  2390. return CellFinder.intercepts(warehouse, startCell, lastCell);
  2391. };
  2392. var getBox$1 = function (table, first, last) {
  2393. var warehouse = getWarehouse(table);
  2394. return CellGroup.getBox(warehouse, first, last);
  2395. };
  2396. var getWarehouse = function (table) {
  2397. var list = DetailsList.fromTable(table);
  2398. return Warehouse.generate(list);
  2399. };
  2400. var TablePositions = {
  2401. moveBy: moveBy$1,
  2402. intercepts: intercepts$1,
  2403. nestedIntercepts: nestedIntercepts,
  2404. getBox: getBox$1
  2405. };
  2406. var lookupTable = function (container, isRoot) {
  2407. return ancestor$1(container, 'table');
  2408. };
  2409. var identified = MixedBag([
  2410. 'boxes',
  2411. 'start',
  2412. 'finish'
  2413. ], []);
  2414. var identify = function (start, finish, isRoot) {
  2415. var getIsRoot = function (rootTable) {
  2416. return function (element) {
  2417. return isRoot(element) || eq(element, rootTable);
  2418. };
  2419. };
  2420. if (eq(start, finish)) {
  2421. return Option.some(identified({
  2422. boxes: Option.some([start]),
  2423. start: start,
  2424. finish: finish
  2425. }));
  2426. } else {
  2427. return lookupTable(start, isRoot).bind(function (startTable) {
  2428. return lookupTable(finish, isRoot).bind(function (finishTable) {
  2429. if (eq(startTable, finishTable)) {
  2430. return Option.some(identified({
  2431. boxes: TablePositions.intercepts(startTable, start, finish),
  2432. start: start,
  2433. finish: finish
  2434. }));
  2435. } else if (contains$2(startTable, finishTable)) {
  2436. var ancestorCells = ancestors$1(finish, 'td,th', getIsRoot(startTable));
  2437. var finishCell = ancestorCells.length > 0 ? ancestorCells[ancestorCells.length - 1] : finish;
  2438. return Option.some(identified({
  2439. boxes: TablePositions.nestedIntercepts(startTable, start, startTable, finish, finishTable),
  2440. start: start,
  2441. finish: finishCell
  2442. }));
  2443. } else if (contains$2(finishTable, startTable)) {
  2444. var ancestorCells = ancestors$1(start, 'td,th', getIsRoot(finishTable));
  2445. var startCell = ancestorCells.length > 0 ? ancestorCells[ancestorCells.length - 1] : start;
  2446. return Option.some(identified({
  2447. boxes: TablePositions.nestedIntercepts(finishTable, start, startTable, finish, finishTable),
  2448. start: start,
  2449. finish: startCell
  2450. }));
  2451. } else {
  2452. return DomParent.ancestors(start, finish).shared().bind(function (lca) {
  2453. return closest$1(lca, 'table', isRoot).bind(function (lcaTable) {
  2454. var finishAncestorCells = ancestors$1(finish, 'td,th', getIsRoot(lcaTable));
  2455. var finishCell = finishAncestorCells.length > 0 ? finishAncestorCells[finishAncestorCells.length - 1] : finish;
  2456. var startAncestorCells = ancestors$1(start, 'td,th', getIsRoot(lcaTable));
  2457. var startCell = startAncestorCells.length > 0 ? startAncestorCells[startAncestorCells.length - 1] : start;
  2458. return Option.some(identified({
  2459. boxes: TablePositions.nestedIntercepts(lcaTable, start, startTable, finish, finishTable),
  2460. start: startCell,
  2461. finish: finishCell
  2462. }));
  2463. });
  2464. });
  2465. }
  2466. });
  2467. });
  2468. }
  2469. };
  2470. var retrieve = function (container, selector) {
  2471. var sels = descendants$1(container, selector);
  2472. return sels.length > 0 ? Option.some(sels) : Option.none();
  2473. };
  2474. var getLast = function (boxes, lastSelectedSelector) {
  2475. return find(boxes, function (box) {
  2476. return is(box, lastSelectedSelector);
  2477. });
  2478. };
  2479. var getEdges = function (container, firstSelectedSelector, lastSelectedSelector) {
  2480. return descendant$1(container, firstSelectedSelector).bind(function (first) {
  2481. return descendant$1(container, lastSelectedSelector).bind(function (last) {
  2482. return DomParent.sharedOne(lookupTable, [
  2483. first,
  2484. last
  2485. ]).map(function (tbl) {
  2486. return {
  2487. first: constant(first),
  2488. last: constant(last),
  2489. table: constant(tbl)
  2490. };
  2491. });
  2492. });
  2493. });
  2494. };
  2495. var expandTo = function (finish, firstSelectedSelector) {
  2496. return ancestor$1(finish, 'table').bind(function (table) {
  2497. return descendant$1(table, firstSelectedSelector).bind(function (start) {
  2498. return identify(start, finish).bind(function (identified) {
  2499. return identified.boxes().map(function (boxes) {
  2500. return {
  2501. boxes: constant(boxes),
  2502. start: constant(identified.start()),
  2503. finish: constant(identified.finish())
  2504. };
  2505. });
  2506. });
  2507. });
  2508. });
  2509. };
  2510. var shiftSelection = function (boxes, deltaRow, deltaColumn, firstSelectedSelector, lastSelectedSelector) {
  2511. return getLast(boxes, lastSelectedSelector).bind(function (last) {
  2512. return TablePositions.moveBy(last, deltaRow, deltaColumn).bind(function (finish) {
  2513. return expandTo(finish, firstSelectedSelector);
  2514. });
  2515. });
  2516. };
  2517. var CellSelection = {
  2518. identify: identify,
  2519. retrieve: retrieve,
  2520. shiftSelection: shiftSelection,
  2521. getEdges: getEdges
  2522. };
  2523. var retrieve$1 = function (container, selector) {
  2524. return CellSelection.retrieve(container, selector);
  2525. };
  2526. var retrieveBox = function (container, firstSelectedSelector, lastSelectedSelector) {
  2527. return CellSelection.getEdges(container, firstSelectedSelector, lastSelectedSelector).bind(function (edges) {
  2528. var isRoot = function (ancestor) {
  2529. return eq(container, ancestor);
  2530. };
  2531. var firstAncestor = ancestor$1(edges.first(), 'thead,tfoot,tbody,table', isRoot);
  2532. var lastAncestor = ancestor$1(edges.last(), 'thead,tfoot,tbody,table', isRoot);
  2533. return firstAncestor.bind(function (fA) {
  2534. return lastAncestor.bind(function (lA) {
  2535. return eq(fA, lA) ? TablePositions.getBox(edges.table(), edges.first(), edges.last()) : Option.none();
  2536. });
  2537. });
  2538. });
  2539. };
  2540. var TableSelection = {
  2541. retrieve: retrieve$1,
  2542. retrieveBox: retrieveBox
  2543. };
  2544. var selected = 'data-mce-selected';
  2545. var selectedSelector = 'td[' + selected + '],th[' + selected + ']';
  2546. var attributeSelector = '[' + selected + ']';
  2547. var firstSelected = 'data-mce-first-selected';
  2548. var firstSelectedSelector = 'td[' + firstSelected + '],th[' + firstSelected + ']';
  2549. var lastSelected = 'data-mce-last-selected';
  2550. var lastSelectedSelector = 'td[' + lastSelected + '],th[' + lastSelected + ']';
  2551. var Ephemera = {
  2552. selected: constant(selected),
  2553. selectedSelector: constant(selectedSelector),
  2554. attributeSelector: constant(attributeSelector),
  2555. firstSelected: constant(firstSelected),
  2556. firstSelectedSelector: constant(firstSelectedSelector),
  2557. lastSelected: constant(lastSelected),
  2558. lastSelectedSelector: constant(lastSelectedSelector)
  2559. };
  2560. var generate$1 = function (cases) {
  2561. if (!isArray(cases)) {
  2562. throw new Error('cases must be an array');
  2563. }
  2564. if (cases.length === 0) {
  2565. throw new Error('there must be at least one case');
  2566. }
  2567. var constructors = [];
  2568. var adt = {};
  2569. each(cases, function (acase, count) {
  2570. var keys$1 = keys(acase);
  2571. if (keys$1.length !== 1) {
  2572. throw new Error('one and only one name per case');
  2573. }
  2574. var key = keys$1[0];
  2575. var value = acase[key];
  2576. if (adt[key] !== undefined) {
  2577. throw new Error('duplicate key detected:' + key);
  2578. } else if (key === 'cata') {
  2579. throw new Error('cannot have a case named cata (sorry)');
  2580. } else if (!isArray(value)) {
  2581. throw new Error('case arguments must be an array');
  2582. }
  2583. constructors.push(key);
  2584. adt[key] = function () {
  2585. var argLength = arguments.length;
  2586. if (argLength !== value.length) {
  2587. throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
  2588. }
  2589. var args = new Array(argLength);
  2590. for (var i = 0; i < args.length; i++)
  2591. args[i] = arguments[i];
  2592. var match = function (branches) {
  2593. var branchKeys = keys(branches);
  2594. if (constructors.length !== branchKeys.length) {
  2595. throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
  2596. }
  2597. var allReqd = forall(constructors, function (reqKey) {
  2598. return contains(branchKeys, reqKey);
  2599. });
  2600. if (!allReqd)
  2601. throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
  2602. return branches[key].apply(null, args);
  2603. };
  2604. return {
  2605. fold: function () {
  2606. if (arguments.length !== cases.length) {
  2607. throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
  2608. }
  2609. var target = arguments[count];
  2610. return target.apply(null, args);
  2611. },
  2612. match: match,
  2613. log: function (label) {
  2614. domGlobals.console.log(label, {
  2615. constructors: constructors,
  2616. constructor: key,
  2617. params: args
  2618. });
  2619. }
  2620. };
  2621. };
  2622. });
  2623. return adt;
  2624. };
  2625. var Adt = { generate: generate$1 };
  2626. var type$1 = Adt.generate([
  2627. { none: [] },
  2628. { multiple: ['elements'] },
  2629. { single: ['selection'] }
  2630. ]);
  2631. var cata = function (subject, onNone, onMultiple, onSingle) {
  2632. return subject.fold(onNone, onMultiple, onSingle);
  2633. };
  2634. var SelectionTypes = {
  2635. cata: cata,
  2636. none: type$1.none,
  2637. multiple: type$1.multiple,
  2638. single: type$1.single
  2639. };
  2640. var selection = function (cell, selections) {
  2641. return SelectionTypes.cata(selections.get(), constant([]), identity, constant([cell]));
  2642. };
  2643. var unmergable = function (cell, selections) {
  2644. var hasSpan = function (elem) {
  2645. return has$1(elem, 'rowspan') && parseInt(get$1(elem, 'rowspan'), 10) > 1 || has$1(elem, 'colspan') && parseInt(get$1(elem, 'colspan'), 10) > 1;
  2646. };
  2647. var candidates = selection(cell, selections);
  2648. return candidates.length > 0 && forall(candidates, hasSpan) ? Option.some(candidates) : Option.none();
  2649. };
  2650. var mergable = function (table, selections) {
  2651. return SelectionTypes.cata(selections.get(), Option.none, function (cells, _env) {
  2652. if (cells.length === 0) {
  2653. return Option.none();
  2654. }
  2655. return TableSelection.retrieveBox(table, Ephemera.firstSelectedSelector(), Ephemera.lastSelectedSelector()).bind(function (bounds) {
  2656. return cells.length > 1 ? Option.some({
  2657. bounds: constant(bounds),
  2658. cells: constant(cells)
  2659. }) : Option.none();
  2660. });
  2661. }, Option.none);
  2662. };
  2663. var CellOperations = {
  2664. mergable: mergable,
  2665. unmergable: unmergable,
  2666. selection: selection
  2667. };
  2668. var noMenu = function (cell) {
  2669. return {
  2670. element: constant(cell),
  2671. mergable: Option.none,
  2672. unmergable: Option.none,
  2673. selection: constant([cell])
  2674. };
  2675. };
  2676. var forMenu = function (selections, table, cell) {
  2677. return {
  2678. element: constant(cell),
  2679. mergable: constant(CellOperations.mergable(table, selections)),
  2680. unmergable: constant(CellOperations.unmergable(cell, selections)),
  2681. selection: constant(CellOperations.selection(cell, selections))
  2682. };
  2683. };
  2684. var notCell$1 = function (element) {
  2685. return noMenu(element);
  2686. };
  2687. var paste$1 = Immutable('element', 'clipboard', 'generators');
  2688. var pasteRows = function (selections, table, cell, clipboard, generators) {
  2689. return {
  2690. element: constant(cell),
  2691. mergable: Option.none,
  2692. unmergable: Option.none,
  2693. selection: constant(CellOperations.selection(cell, selections)),
  2694. clipboard: constant(clipboard),
  2695. generators: constant(generators)
  2696. };
  2697. };
  2698. var TableTargets = {
  2699. noMenu: noMenu,
  2700. forMenu: forMenu,
  2701. notCell: notCell$1,
  2702. paste: paste$1,
  2703. pasteRows: pasteRows
  2704. };
  2705. var extractSelected = function (cells) {
  2706. return TableLookup.table(cells[0]).map(deep).map(function (replica) {
  2707. return [CopySelected.extract(replica, Ephemera.attributeSelector())];
  2708. });
  2709. };
  2710. var serializeElements = function (editor, elements) {
  2711. return map(elements, function (elm) {
  2712. return editor.selection.serializer.serialize(elm.dom(), {});
  2713. }).join('');
  2714. };
  2715. var getTextContent = function (elements) {
  2716. return map(elements, function (element) {
  2717. return element.dom().innerText;
  2718. }).join('');
  2719. };
  2720. var registerEvents = function (editor, selections, actions, cellSelection) {
  2721. editor.on('BeforeGetContent', function (e) {
  2722. var multiCellContext = function (cells) {
  2723. e.preventDefault();
  2724. extractSelected(cells).each(function (elements) {
  2725. e.content = e.format === 'text' ? getTextContent(elements) : serializeElements(editor, elements);
  2726. });
  2727. };
  2728. if (e.selection === true) {
  2729. SelectionTypes.cata(selections.get(), noop, multiCellContext, noop);
  2730. }
  2731. });
  2732. editor.on('BeforeSetContent', function (e) {
  2733. if (e.selection === true && e.paste === true) {
  2734. var cellOpt = Option.from(editor.dom.getParent(editor.selection.getStart(), 'th,td'));
  2735. cellOpt.each(function (domCell) {
  2736. var cell = Element.fromDom(domCell);
  2737. TableLookup.table(cell).each(function (table) {
  2738. var elements = filter(fromHtml$1(e.content), function (content) {
  2739. return name(content) !== 'meta';
  2740. });
  2741. if (elements.length === 1 && name(elements[0]) === 'table') {
  2742. e.preventDefault();
  2743. var doc = Element.fromDom(editor.getDoc());
  2744. var generators = TableFill.paste(doc);
  2745. var targets = TableTargets.paste(cell, elements[0], generators);
  2746. actions.pasteCells(table, targets).each(function (rng) {
  2747. editor.selection.setRng(rng);
  2748. editor.focus();
  2749. cellSelection.clear(table);
  2750. });
  2751. }
  2752. });
  2753. });
  2754. }
  2755. });
  2756. };
  2757. var Clipboard = { registerEvents: registerEvents };
  2758. function Dimension (name, getOffset) {
  2759. var set = function (element, h) {
  2760. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  2761. throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
  2762. }
  2763. var dom = element.dom();
  2764. if (isSupported(dom)) {
  2765. dom.style[name] = h + 'px';
  2766. }
  2767. };
  2768. var get = function (element) {
  2769. var r = getOffset(element);
  2770. if (r <= 0 || r === null) {
  2771. var css = get$2(element, name);
  2772. return parseFloat(css) || 0;
  2773. }
  2774. return r;
  2775. };
  2776. var getOuter = get;
  2777. var aggregate = function (element, properties) {
  2778. return foldl(properties, function (acc, property) {
  2779. var val = get$2(element, property);
  2780. var value = val === undefined ? 0 : parseInt(val, 10);
  2781. return isNaN(value) ? acc : acc + value;
  2782. }, 0);
  2783. };
  2784. var max = function (element, value, properties) {
  2785. var cumulativeInclusions = aggregate(element, properties);
  2786. var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
  2787. return absoluteMax;
  2788. };
  2789. return {
  2790. set: set,
  2791. get: get,
  2792. getOuter: getOuter,
  2793. aggregate: aggregate,
  2794. max: max
  2795. };
  2796. }
  2797. var api$1 = Dimension('height', function (element) {
  2798. var dom = element.dom();
  2799. return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
  2800. });
  2801. var get$4 = function (element) {
  2802. return api$1.get(element);
  2803. };
  2804. var getOuter = function (element) {
  2805. return api$1.getOuter(element);
  2806. };
  2807. var api$2 = Dimension('width', function (element) {
  2808. return element.dom().offsetWidth;
  2809. });
  2810. var get$5 = function (element) {
  2811. return api$2.get(element);
  2812. };
  2813. var getOuter$1 = function (element) {
  2814. return api$2.getOuter(element);
  2815. };
  2816. var platform = PlatformDetection$1.detect();
  2817. var needManualCalc = function () {
  2818. return platform.browser.isIE() || platform.browser.isEdge();
  2819. };
  2820. var toNumber = function (px, fallback) {
  2821. var num = parseFloat(px);
  2822. return isNaN(num) ? fallback : num;
  2823. };
  2824. var getProp = function (elm, name, fallback) {
  2825. return toNumber(get$2(elm, name), fallback);
  2826. };
  2827. var getCalculatedHeight = function (cell) {
  2828. var paddingTop = getProp(cell, 'padding-top', 0);
  2829. var paddingBottom = getProp(cell, 'padding-bottom', 0);
  2830. var borderTop = getProp(cell, 'border-top-width', 0);
  2831. var borderBottom = getProp(cell, 'border-bottom-width', 0);
  2832. var height = cell.dom().getBoundingClientRect().height;
  2833. var boxSizing = get$2(cell, 'box-sizing');
  2834. var borders = borderTop + borderBottom;
  2835. return boxSizing === 'border-box' ? height : height - paddingTop - paddingBottom - borders;
  2836. };
  2837. var getWidth = function (cell) {
  2838. return getProp(cell, 'width', get$5(cell));
  2839. };
  2840. var getHeight = function (cell) {
  2841. return needManualCalc() ? getCalculatedHeight(cell) : getProp(cell, 'height', get$4(cell));
  2842. };
  2843. var RuntimeSize = {
  2844. getWidth: getWidth,
  2845. getHeight: getHeight
  2846. };
  2847. var genericSizeRegex = /(\d+(\.\d+)?)(\w|%)*/;
  2848. var percentageBasedSizeRegex = /(\d+(\.\d+)?)%/;
  2849. var pixelBasedSizeRegex = /(\d+(\.\d+)?)px|em/;
  2850. var setPixelWidth = function (cell, amount) {
  2851. set$1(cell, 'width', amount + 'px');
  2852. };
  2853. var setPercentageWidth = function (cell, amount) {
  2854. set$1(cell, 'width', amount + '%');
  2855. };
  2856. var setHeight = function (cell, amount) {
  2857. set$1(cell, 'height', amount + 'px');
  2858. };
  2859. var getHeightValue = function (cell) {
  2860. return getRaw(cell, 'height').getOrThunk(function () {
  2861. return RuntimeSize.getHeight(cell) + 'px';
  2862. });
  2863. };
  2864. var convert = function (cell, number, getter, setter) {
  2865. var newSize = TableLookup.table(cell).map(function (table) {
  2866. var total = getter(table);
  2867. return Math.floor(number / 100 * total);
  2868. }).getOr(number);
  2869. setter(cell, newSize);
  2870. return newSize;
  2871. };
  2872. var normalizePixelSize = function (value, cell, getter, setter) {
  2873. var number = parseInt(value, 10);
  2874. return endsWith(value, '%') && name(cell) !== 'table' ? convert(cell, number, getter, setter) : number;
  2875. };
  2876. var getTotalHeight = function (cell) {
  2877. var value = getHeightValue(cell);
  2878. if (!value) {
  2879. return get$4(cell);
  2880. }
  2881. return normalizePixelSize(value, cell, get$4, setHeight);
  2882. };
  2883. var get$6 = function (cell, type, f) {
  2884. var v = f(cell);
  2885. var span = getSpan(cell, type);
  2886. return v / span;
  2887. };
  2888. var getSpan = function (cell, type) {
  2889. return has$1(cell, type) ? parseInt(get$1(cell, type), 10) : 1;
  2890. };
  2891. var getRawWidth = function (element) {
  2892. var cssWidth = getRaw(element, 'width');
  2893. return cssWidth.fold(function () {
  2894. return Option.from(get$1(element, 'width'));
  2895. }, function (width) {
  2896. return Option.some(width);
  2897. });
  2898. };
  2899. var normalizePercentageWidth = function (cellWidth, tableSize) {
  2900. return cellWidth / tableSize.pixelWidth() * 100;
  2901. };
  2902. var choosePercentageSize = function (element, width, tableSize) {
  2903. if (percentageBasedSizeRegex.test(width)) {
  2904. var percentMatch = percentageBasedSizeRegex.exec(width);
  2905. return parseFloat(percentMatch[1]);
  2906. } else {
  2907. var intWidth = get$5(element);
  2908. return normalizePercentageWidth(intWidth, tableSize);
  2909. }
  2910. };
  2911. var getPercentageWidth = function (cell, tableSize) {
  2912. var width = getRawWidth(cell);
  2913. return width.fold(function () {
  2914. var intWidth = get$5(cell);
  2915. return normalizePercentageWidth(intWidth, tableSize);
  2916. }, function (w) {
  2917. return choosePercentageSize(cell, w, tableSize);
  2918. });
  2919. };
  2920. var normalizePixelWidth = function (cellWidth, tableSize) {
  2921. return cellWidth / 100 * tableSize.pixelWidth();
  2922. };
  2923. var choosePixelSize = function (element, width, tableSize) {
  2924. if (pixelBasedSizeRegex.test(width)) {
  2925. var pixelMatch = pixelBasedSizeRegex.exec(width);
  2926. return parseInt(pixelMatch[1], 10);
  2927. } else if (percentageBasedSizeRegex.test(width)) {
  2928. var percentMatch = percentageBasedSizeRegex.exec(width);
  2929. var floatWidth = parseFloat(percentMatch[1]);
  2930. return normalizePixelWidth(floatWidth, tableSize);
  2931. } else {
  2932. return get$5(element);
  2933. }
  2934. };
  2935. var getPixelWidth = function (cell, tableSize) {
  2936. var width = getRawWidth(cell);
  2937. return width.fold(function () {
  2938. return get$5(cell);
  2939. }, function (w) {
  2940. return choosePixelSize(cell, w, tableSize);
  2941. });
  2942. };
  2943. var getHeight$1 = function (cell) {
  2944. return get$6(cell, 'rowspan', getTotalHeight);
  2945. };
  2946. var getGenericWidth = function (cell) {
  2947. var width = getRawWidth(cell);
  2948. return width.bind(function (w) {
  2949. if (genericSizeRegex.test(w)) {
  2950. var match = genericSizeRegex.exec(w);
  2951. return Option.some({
  2952. width: constant(match[1]),
  2953. unit: constant(match[3])
  2954. });
  2955. } else {
  2956. return Option.none();
  2957. }
  2958. });
  2959. };
  2960. var setGenericWidth = function (cell, amount, unit) {
  2961. set$1(cell, 'width', amount + unit);
  2962. };
  2963. var Sizes = {
  2964. percentageBasedSizeRegex: constant(percentageBasedSizeRegex),
  2965. pixelBasedSizeRegex: constant(pixelBasedSizeRegex),
  2966. setPixelWidth: setPixelWidth,
  2967. setPercentageWidth: setPercentageWidth,
  2968. setHeight: setHeight,
  2969. getPixelWidth: getPixelWidth,
  2970. getPercentageWidth: getPercentageWidth,
  2971. getGenericWidth: getGenericWidth,
  2972. setGenericWidth: setGenericWidth,
  2973. getHeight: getHeight$1,
  2974. getRawWidth: getRawWidth
  2975. };
  2976. var halve = function (main, other) {
  2977. var width = Sizes.getGenericWidth(main);
  2978. width.each(function (w) {
  2979. var newWidth = w.width() / 2;
  2980. Sizes.setGenericWidth(main, newWidth, w.unit());
  2981. Sizes.setGenericWidth(other, newWidth, w.unit());
  2982. });
  2983. };
  2984. var CellMutations = { halve: halve };
  2985. var attached = function (element, scope) {
  2986. var doc = scope || Element.fromDom(domGlobals.document.documentElement);
  2987. return ancestor(element, curry(eq, doc)).isSome();
  2988. };
  2989. var windowOf = function (element) {
  2990. var dom = element.dom();
  2991. if (dom === dom.window && element instanceof domGlobals.Window) {
  2992. return element;
  2993. }
  2994. return isDocument(element) ? dom.defaultView || dom.parentWindow : null;
  2995. };
  2996. var r = function (left, top) {
  2997. var translate = function (x, y) {
  2998. return r(left + x, top + y);
  2999. };
  3000. return {
  3001. left: constant(left),
  3002. top: constant(top),
  3003. translate: translate
  3004. };
  3005. };
  3006. var Position = r;
  3007. var boxPosition = function (dom) {
  3008. var box = dom.getBoundingClientRect();
  3009. return Position(box.left, box.top);
  3010. };
  3011. var firstDefinedOrZero = function (a, b) {
  3012. return a !== undefined ? a : b !== undefined ? b : 0;
  3013. };
  3014. var absolute = function (element) {
  3015. var doc = element.dom().ownerDocument;
  3016. var body = doc.body;
  3017. var win = windowOf(Element.fromDom(doc));
  3018. var html = doc.documentElement;
  3019. var scrollTop = firstDefinedOrZero(win.pageYOffset, html.scrollTop);
  3020. var scrollLeft = firstDefinedOrZero(win.pageXOffset, html.scrollLeft);
  3021. var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
  3022. var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
  3023. return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  3024. };
  3025. var viewport = function (element) {
  3026. var dom = element.dom();
  3027. var doc = dom.ownerDocument;
  3028. var body = doc.body;
  3029. var html = Element.fromDom(doc.documentElement);
  3030. if (body === dom) {
  3031. return Position(body.offsetLeft, body.offsetTop);
  3032. }
  3033. if (!attached(element, html)) {
  3034. return Position(0, 0);
  3035. }
  3036. return boxPosition(dom);
  3037. };
  3038. var rowInfo = Immutable('row', 'y');
  3039. var colInfo = Immutable('col', 'x');
  3040. var rtlEdge = function (cell) {
  3041. var pos = absolute(cell);
  3042. return pos.left() + getOuter$1(cell);
  3043. };
  3044. var ltrEdge = function (cell) {
  3045. return absolute(cell).left();
  3046. };
  3047. var getLeftEdge = function (index, cell) {
  3048. return colInfo(index, ltrEdge(cell));
  3049. };
  3050. var getRightEdge = function (index, cell) {
  3051. return colInfo(index, rtlEdge(cell));
  3052. };
  3053. var getTop = function (cell) {
  3054. return absolute(cell).top();
  3055. };
  3056. var getTopEdge = function (index, cell) {
  3057. return rowInfo(index, getTop(cell));
  3058. };
  3059. var getBottomEdge = function (index, cell) {
  3060. return rowInfo(index, getTop(cell) + getOuter(cell));
  3061. };
  3062. var findPositions = function (getInnerEdge, getOuterEdge, array) {
  3063. if (array.length === 0) {
  3064. return [];
  3065. }
  3066. var lines = map(array.slice(1), function (cellOption, index) {
  3067. return cellOption.map(function (cell) {
  3068. return getInnerEdge(index, cell);
  3069. });
  3070. });
  3071. var lastLine = array[array.length - 1].map(function (cell) {
  3072. return getOuterEdge(array.length - 1, cell);
  3073. });
  3074. return lines.concat([lastLine]);
  3075. };
  3076. var negate = function (step, _table) {
  3077. return -step;
  3078. };
  3079. var height = {
  3080. delta: identity,
  3081. positions: curry(findPositions, getTopEdge, getBottomEdge),
  3082. edge: getTop
  3083. };
  3084. var ltr = {
  3085. delta: identity,
  3086. edge: ltrEdge,
  3087. positions: curry(findPositions, getLeftEdge, getRightEdge)
  3088. };
  3089. var rtl = {
  3090. delta: negate,
  3091. edge: rtlEdge,
  3092. positions: curry(findPositions, getRightEdge, getLeftEdge)
  3093. };
  3094. var BarPositions = {
  3095. height: height,
  3096. rtl: rtl,
  3097. ltr: ltr
  3098. };
  3099. var ResizeDirection = {
  3100. ltr: BarPositions.ltr,
  3101. rtl: BarPositions.rtl
  3102. };
  3103. function TableDirection (directionAt) {
  3104. var auto = function (table) {
  3105. return directionAt(table).isRtl() ? ResizeDirection.rtl : ResizeDirection.ltr;
  3106. };
  3107. var delta = function (amount, table) {
  3108. return auto(table).delta(amount, table);
  3109. };
  3110. var positions = function (cols, table) {
  3111. return auto(table).positions(cols);
  3112. };
  3113. var edge = function (cell) {
  3114. return auto(cell).edge(cell);
  3115. };
  3116. return {
  3117. delta: delta,
  3118. edge: edge,
  3119. positions: positions
  3120. };
  3121. }
  3122. var getGridSize = function (table) {
  3123. var input = DetailsList.fromTable(table);
  3124. var warehouse = Warehouse.generate(input);
  3125. return warehouse.grid();
  3126. };
  3127. var TableGridSize = { getGridSize: getGridSize };
  3128. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  3129. var shallow$1 = function (old, nu) {
  3130. return nu;
  3131. };
  3132. var baseMerge = function (merger) {
  3133. return function () {
  3134. var objects = new Array(arguments.length);
  3135. for (var i = 0; i < objects.length; i++)
  3136. objects[i] = arguments[i];
  3137. if (objects.length === 0)
  3138. throw new Error('Can\'t merge zero objects');
  3139. var ret = {};
  3140. for (var j = 0; j < objects.length; j++) {
  3141. var curObject = objects[j];
  3142. for (var key in curObject)
  3143. if (hasOwnProperty$1.call(curObject, key)) {
  3144. ret[key] = merger(ret[key], curObject[key]);
  3145. }
  3146. }
  3147. return ret;
  3148. };
  3149. };
  3150. var merge = baseMerge(shallow$1);
  3151. var cat = function (arr) {
  3152. var r = [];
  3153. var push = function (x) {
  3154. r.push(x);
  3155. };
  3156. for (var i = 0; i < arr.length; i++) {
  3157. arr[i].each(push);
  3158. }
  3159. return r;
  3160. };
  3161. var findMap = function (arr, f) {
  3162. for (var i = 0; i < arr.length; i++) {
  3163. var r = f(arr[i], i);
  3164. if (r.isSome()) {
  3165. return r;
  3166. }
  3167. }
  3168. return Option.none();
  3169. };
  3170. var setIfNot = function (element, property, value, ignore) {
  3171. if (value === ignore) {
  3172. remove(element, property);
  3173. } else {
  3174. set(element, property, value);
  3175. }
  3176. };
  3177. var render = function (table, grid) {
  3178. var newRows = [];
  3179. var newCells = [];
  3180. var renderSection = function (gridSection, sectionName) {
  3181. var section = child$2(table, sectionName).getOrThunk(function () {
  3182. var tb = Element.fromTag(sectionName, owner(table).dom());
  3183. append(table, tb);
  3184. return tb;
  3185. });
  3186. empty(section);
  3187. var rows = map(gridSection, function (row) {
  3188. if (row.isNew()) {
  3189. newRows.push(row.element());
  3190. }
  3191. var tr = row.element();
  3192. empty(tr);
  3193. each(row.cells(), function (cell) {
  3194. if (cell.isNew()) {
  3195. newCells.push(cell.element());
  3196. }
  3197. setIfNot(cell.element(), 'colspan', cell.colspan(), 1);
  3198. setIfNot(cell.element(), 'rowspan', cell.rowspan(), 1);
  3199. append(tr, cell.element());
  3200. });
  3201. return tr;
  3202. });
  3203. append$1(section, rows);
  3204. };
  3205. var removeSection = function (sectionName) {
  3206. child$2(table, sectionName).each(remove$2);
  3207. };
  3208. var renderOrRemoveSection = function (gridSection, sectionName) {
  3209. if (gridSection.length > 0) {
  3210. renderSection(gridSection, sectionName);
  3211. } else {
  3212. removeSection(sectionName);
  3213. }
  3214. };
  3215. var headSection = [];
  3216. var bodySection = [];
  3217. var footSection = [];
  3218. each(grid, function (row) {
  3219. switch (row.section()) {
  3220. case 'thead':
  3221. headSection.push(row);
  3222. break;
  3223. case 'tbody':
  3224. bodySection.push(row);
  3225. break;
  3226. case 'tfoot':
  3227. footSection.push(row);
  3228. break;
  3229. }
  3230. });
  3231. renderOrRemoveSection(headSection, 'thead');
  3232. renderOrRemoveSection(bodySection, 'tbody');
  3233. renderOrRemoveSection(footSection, 'tfoot');
  3234. return {
  3235. newRows: constant(newRows),
  3236. newCells: constant(newCells)
  3237. };
  3238. };
  3239. var copy$2 = function (grid) {
  3240. var rows = map(grid, function (row) {
  3241. var tr = shallow(row.element());
  3242. each(row.cells(), function (cell) {
  3243. var clonedCell = deep(cell.element());
  3244. setIfNot(clonedCell, 'colspan', cell.colspan(), 1);
  3245. setIfNot(clonedCell, 'rowspan', cell.rowspan(), 1);
  3246. append(tr, clonedCell);
  3247. });
  3248. return tr;
  3249. });
  3250. return rows;
  3251. };
  3252. var Redraw = {
  3253. render: render,
  3254. copy: copy$2
  3255. };
  3256. var read = function (element, attr) {
  3257. var value = get$1(element, attr);
  3258. return value === undefined || value === '' ? [] : value.split(' ');
  3259. };
  3260. var add = function (element, attr, id) {
  3261. var old = read(element, attr);
  3262. var nu = old.concat([id]);
  3263. set(element, attr, nu.join(' '));
  3264. return true;
  3265. };
  3266. var remove$3 = function (element, attr, id) {
  3267. var nu = filter(read(element, attr), function (v) {
  3268. return v !== id;
  3269. });
  3270. if (nu.length > 0) {
  3271. set(element, attr, nu.join(' '));
  3272. } else {
  3273. remove(element, attr);
  3274. }
  3275. return false;
  3276. };
  3277. var supports = function (element) {
  3278. return element.dom().classList !== undefined;
  3279. };
  3280. var get$7 = function (element) {
  3281. return read(element, 'class');
  3282. };
  3283. var add$1 = function (element, clazz) {
  3284. return add(element, 'class', clazz);
  3285. };
  3286. var remove$4 = function (element, clazz) {
  3287. return remove$3(element, 'class', clazz);
  3288. };
  3289. var toggle = function (element, clazz) {
  3290. if (contains(get$7(element), clazz)) {
  3291. return remove$4(element, clazz);
  3292. } else {
  3293. return add$1(element, clazz);
  3294. }
  3295. };
  3296. var ClassList = /*#__PURE__*/Object.freeze({
  3297. get: get$7,
  3298. add: add$1,
  3299. remove: remove$4,
  3300. toggle: toggle,
  3301. supports: supports
  3302. });
  3303. var add$2 = function (element, clazz) {
  3304. if (supports(element)) {
  3305. element.dom().classList.add(clazz);
  3306. } else {
  3307. add$1(element, clazz);
  3308. }
  3309. };
  3310. var cleanClass = function (element) {
  3311. var classList = supports(element) ? element.dom().classList : get$7(element);
  3312. if (classList.length === 0) {
  3313. remove(element, 'class');
  3314. }
  3315. };
  3316. var remove$5 = function (element, clazz) {
  3317. if (supports(element)) {
  3318. var classList = element.dom().classList;
  3319. classList.remove(clazz);
  3320. } else {
  3321. remove$4(element, clazz);
  3322. }
  3323. cleanClass(element);
  3324. };
  3325. var has$2 = function (element, clazz) {
  3326. return supports(element) && element.dom().classList.contains(clazz);
  3327. };
  3328. var repeat = function (repititions, f) {
  3329. var r = [];
  3330. for (var i = 0; i < repititions; i++) {
  3331. r.push(f(i));
  3332. }
  3333. return r;
  3334. };
  3335. var range$1 = function (start, end) {
  3336. var r = [];
  3337. for (var i = start; i < end; i++) {
  3338. r.push(i);
  3339. }
  3340. return r;
  3341. };
  3342. var unique = function (xs, comparator) {
  3343. var result = [];
  3344. each(xs, function (x, i) {
  3345. if (i < xs.length - 1 && !comparator(x, xs[i + 1])) {
  3346. result.push(x);
  3347. } else if (i === xs.length - 1) {
  3348. result.push(x);
  3349. }
  3350. });
  3351. return result;
  3352. };
  3353. var deduce = function (xs, index) {
  3354. if (index < 0 || index >= xs.length - 1) {
  3355. return Option.none();
  3356. }
  3357. var current = xs[index].fold(function () {
  3358. var rest = reverse(xs.slice(0, index));
  3359. return findMap(rest, function (a, i) {
  3360. return a.map(function (aa) {
  3361. return {
  3362. value: aa,
  3363. delta: i + 1
  3364. };
  3365. });
  3366. });
  3367. }, function (c) {
  3368. return Option.some({
  3369. value: c,
  3370. delta: 0
  3371. });
  3372. });
  3373. var next = xs[index + 1].fold(function () {
  3374. var rest = xs.slice(index + 1);
  3375. return findMap(rest, function (a, i) {
  3376. return a.map(function (aa) {
  3377. return {
  3378. value: aa,
  3379. delta: i + 1
  3380. };
  3381. });
  3382. });
  3383. }, function (n) {
  3384. return Option.some({
  3385. value: n,
  3386. delta: 1
  3387. });
  3388. });
  3389. return current.bind(function (c) {
  3390. return next.map(function (n) {
  3391. var extras = n.delta + c.delta;
  3392. return Math.abs(n.value - c.value) / extras;
  3393. });
  3394. });
  3395. };
  3396. var Util = {
  3397. repeat: repeat,
  3398. range: range$1,
  3399. unique: unique,
  3400. deduce: deduce
  3401. };
  3402. var columns = function (warehouse) {
  3403. var grid = warehouse.grid();
  3404. var cols = Util.range(0, grid.columns());
  3405. var rowsArr = Util.range(0, grid.rows());
  3406. return map(cols, function (col) {
  3407. var getBlock = function () {
  3408. return bind(rowsArr, function (r) {
  3409. return Warehouse.getAt(warehouse, r, col).filter(function (detail) {
  3410. return detail.column() === col;
  3411. }).fold(constant([]), function (detail) {
  3412. return [detail];
  3413. });
  3414. });
  3415. };
  3416. var isSingle = function (detail) {
  3417. return detail.colspan() === 1;
  3418. };
  3419. var getFallback = function () {
  3420. return Warehouse.getAt(warehouse, 0, col);
  3421. };
  3422. return decide(getBlock, isSingle, getFallback);
  3423. });
  3424. };
  3425. var decide = function (getBlock, isSingle, getFallback) {
  3426. var inBlock = getBlock();
  3427. var singleInBlock = find(inBlock, isSingle);
  3428. var detailOption = singleInBlock.orThunk(function () {
  3429. return Option.from(inBlock[0]).orThunk(getFallback);
  3430. });
  3431. return detailOption.map(function (detail) {
  3432. return detail.element();
  3433. });
  3434. };
  3435. var rows$1 = function (warehouse) {
  3436. var grid = warehouse.grid();
  3437. var rowsArr = Util.range(0, grid.rows());
  3438. var cols = Util.range(0, grid.columns());
  3439. return map(rowsArr, function (row) {
  3440. var getBlock = function () {
  3441. return bind(cols, function (c) {
  3442. return Warehouse.getAt(warehouse, row, c).filter(function (detail) {
  3443. return detail.row() === row;
  3444. }).fold(constant([]), function (detail) {
  3445. return [detail];
  3446. });
  3447. });
  3448. };
  3449. var isSingle = function (detail) {
  3450. return detail.rowspan() === 1;
  3451. };
  3452. var getFallback = function () {
  3453. return Warehouse.getAt(warehouse, row, 0);
  3454. };
  3455. return decide(getBlock, isSingle, getFallback);
  3456. });
  3457. };
  3458. var Blocks = {
  3459. columns: columns,
  3460. rows: rows$1
  3461. };
  3462. var css = function (namespace) {
  3463. var dashNamespace = namespace.replace(/\./g, '-');
  3464. var resolve = function (str) {
  3465. return dashNamespace + '-' + str;
  3466. };
  3467. return { resolve: resolve };
  3468. };
  3469. var styles = css('ephox-snooker');
  3470. var Styles = { resolve: styles.resolve };
  3471. var col = function (column, x, y, w, h) {
  3472. var blocker = Element.fromTag('div');
  3473. setAll$1(blocker, {
  3474. position: 'absolute',
  3475. left: x - w / 2 + 'px',
  3476. top: y + 'px',
  3477. height: h + 'px',
  3478. width: w + 'px'
  3479. });
  3480. setAll(blocker, {
  3481. 'data-column': column,
  3482. 'role': 'presentation'
  3483. });
  3484. return blocker;
  3485. };
  3486. var row$1 = function (r, x, y, w, h) {
  3487. var blocker = Element.fromTag('div');
  3488. setAll$1(blocker, {
  3489. position: 'absolute',
  3490. left: x + 'px',
  3491. top: y - h / 2 + 'px',
  3492. height: h + 'px',
  3493. width: w + 'px'
  3494. });
  3495. setAll(blocker, {
  3496. 'data-row': r,
  3497. 'role': 'presentation'
  3498. });
  3499. return blocker;
  3500. };
  3501. var Bar = {
  3502. col: col,
  3503. row: row$1
  3504. };
  3505. var resizeBar = Styles.resolve('resizer-bar');
  3506. var resizeRowBar = Styles.resolve('resizer-rows');
  3507. var resizeColBar = Styles.resolve('resizer-cols');
  3508. var BAR_THICKNESS = 7;
  3509. var clear = function (wire) {
  3510. var previous = descendants$1(wire.parent(), '.' + resizeBar);
  3511. each(previous, remove$2);
  3512. };
  3513. var drawBar = function (wire, positions, create) {
  3514. var origin = wire.origin();
  3515. each(positions, function (cpOption, i) {
  3516. cpOption.each(function (cp) {
  3517. var bar = create(origin, cp);
  3518. add$2(bar, resizeBar);
  3519. append(wire.parent(), bar);
  3520. });
  3521. });
  3522. };
  3523. var refreshCol = function (wire, colPositions, position, tableHeight) {
  3524. drawBar(wire, colPositions, function (origin, cp) {
  3525. var colBar = Bar.col(cp.col(), cp.x() - origin.left(), position.top() - origin.top(), BAR_THICKNESS, tableHeight);
  3526. add$2(colBar, resizeColBar);
  3527. return colBar;
  3528. });
  3529. };
  3530. var refreshRow = function (wire, rowPositions, position, tableWidth) {
  3531. drawBar(wire, rowPositions, function (origin, cp) {
  3532. var rowBar = Bar.row(cp.row(), position.left() - origin.left(), cp.y() - origin.top(), tableWidth, BAR_THICKNESS);
  3533. add$2(rowBar, resizeRowBar);
  3534. return rowBar;
  3535. });
  3536. };
  3537. var refreshGrid = function (wire, table, rows, cols, hdirection, vdirection) {
  3538. var position = absolute(table);
  3539. var rowPositions = rows.length > 0 ? hdirection.positions(rows, table) : [];
  3540. refreshRow(wire, rowPositions, position, getOuter$1(table));
  3541. var colPositions = cols.length > 0 ? vdirection.positions(cols, table) : [];
  3542. refreshCol(wire, colPositions, position, getOuter(table));
  3543. };
  3544. var refresh = function (wire, table, hdirection, vdirection) {
  3545. clear(wire);
  3546. var list = DetailsList.fromTable(table);
  3547. var warehouse = Warehouse.generate(list);
  3548. var rows = Blocks.rows(warehouse);
  3549. var cols = Blocks.columns(warehouse);
  3550. refreshGrid(wire, table, rows, cols, hdirection, vdirection);
  3551. };
  3552. var each$2 = function (wire, f) {
  3553. var bars = descendants$1(wire.parent(), '.' + resizeBar);
  3554. each(bars, f);
  3555. };
  3556. var hide = function (wire) {
  3557. each$2(wire, function (bar) {
  3558. set$1(bar, 'display', 'none');
  3559. });
  3560. };
  3561. var show = function (wire) {
  3562. each$2(wire, function (bar) {
  3563. set$1(bar, 'display', 'block');
  3564. });
  3565. };
  3566. var isRowBar = function (element) {
  3567. return has$2(element, resizeRowBar);
  3568. };
  3569. var isColBar = function (element) {
  3570. return has$2(element, resizeColBar);
  3571. };
  3572. var Bars = {
  3573. refresh: refresh,
  3574. hide: hide,
  3575. show: show,
  3576. destroy: clear,
  3577. isRowBar: isRowBar,
  3578. isColBar: isColBar
  3579. };
  3580. var addCell = function (gridRow, index, cell) {
  3581. var cells = gridRow.cells();
  3582. var before = cells.slice(0, index);
  3583. var after = cells.slice(index);
  3584. var newCells = before.concat([cell]).concat(after);
  3585. return setCells(gridRow, newCells);
  3586. };
  3587. var mutateCell = function (gridRow, index, cell) {
  3588. var cells = gridRow.cells();
  3589. cells[index] = cell;
  3590. };
  3591. var setCells = function (gridRow, cells) {
  3592. return Structs.rowcells(cells, gridRow.section());
  3593. };
  3594. var mapCells = function (gridRow, f) {
  3595. var cells = gridRow.cells();
  3596. var r = map(cells, f);
  3597. return Structs.rowcells(r, gridRow.section());
  3598. };
  3599. var getCell = function (gridRow, index) {
  3600. return gridRow.cells()[index];
  3601. };
  3602. var getCellElement = function (gridRow, index) {
  3603. return getCell(gridRow, index).element();
  3604. };
  3605. var cellLength = function (gridRow) {
  3606. return gridRow.cells().length;
  3607. };
  3608. var GridRow = {
  3609. addCell: addCell,
  3610. setCells: setCells,
  3611. mutateCell: mutateCell,
  3612. getCell: getCell,
  3613. getCellElement: getCellElement,
  3614. mapCells: mapCells,
  3615. cellLength: cellLength
  3616. };
  3617. var getColumn = function (grid, index) {
  3618. return map(grid, function (row) {
  3619. return GridRow.getCell(row, index);
  3620. });
  3621. };
  3622. var getRow = function (grid, index) {
  3623. return grid[index];
  3624. };
  3625. var findDiff = function (xs, comp) {
  3626. if (xs.length === 0) {
  3627. return 0;
  3628. }
  3629. var first = xs[0];
  3630. var index = findIndex(xs, function (x) {
  3631. return !comp(first.element(), x.element());
  3632. });
  3633. return index.fold(function () {
  3634. return xs.length;
  3635. }, function (ind) {
  3636. return ind;
  3637. });
  3638. };
  3639. var subgrid = function (grid, row, column, comparator) {
  3640. var restOfRow = getRow(grid, row).cells().slice(column);
  3641. var endColIndex = findDiff(restOfRow, comparator);
  3642. var restOfColumn = getColumn(grid, column).slice(row);
  3643. var endRowIndex = findDiff(restOfColumn, comparator);
  3644. return {
  3645. colspan: constant(endColIndex),
  3646. rowspan: constant(endRowIndex)
  3647. };
  3648. };
  3649. var TableGrid = { subgrid: subgrid };
  3650. var toDetails = function (grid, comparator) {
  3651. var seen = map(grid, function (row, ri) {
  3652. return map(row.cells(), function (col, ci) {
  3653. return false;
  3654. });
  3655. });
  3656. var updateSeen = function (ri, ci, rowspan, colspan) {
  3657. for (var r = ri; r < ri + rowspan; r++) {
  3658. for (var c = ci; c < ci + colspan; c++) {
  3659. seen[r][c] = true;
  3660. }
  3661. }
  3662. };
  3663. return map(grid, function (row, ri) {
  3664. var details = bind(row.cells(), function (cell, ci) {
  3665. if (seen[ri][ci] === false) {
  3666. var result = TableGrid.subgrid(grid, ri, ci, comparator);
  3667. updateSeen(ri, ci, result.rowspan(), result.colspan());
  3668. return [Structs.detailnew(cell.element(), result.rowspan(), result.colspan(), cell.isNew())];
  3669. } else {
  3670. return [];
  3671. }
  3672. });
  3673. return Structs.rowdetails(details, row.section());
  3674. });
  3675. };
  3676. var toGrid = function (warehouse, generators, isNew) {
  3677. var grid = [];
  3678. for (var i = 0; i < warehouse.grid().rows(); i++) {
  3679. var rowCells = [];
  3680. for (var j = 0; j < warehouse.grid().columns(); j++) {
  3681. var element = Warehouse.getAt(warehouse, i, j).map(function (item) {
  3682. return Structs.elementnew(item.element(), isNew);
  3683. }).getOrThunk(function () {
  3684. return Structs.elementnew(generators.gap(), true);
  3685. });
  3686. rowCells.push(element);
  3687. }
  3688. var row = Structs.rowcells(rowCells, warehouse.all()[i].section());
  3689. grid.push(row);
  3690. }
  3691. return grid;
  3692. };
  3693. var Transitions = {
  3694. toDetails: toDetails,
  3695. toGrid: toGrid
  3696. };
  3697. var fromWarehouse = function (warehouse, generators) {
  3698. return Transitions.toGrid(warehouse, generators, false);
  3699. };
  3700. var deriveRows = function (rendered, generators) {
  3701. var findRow = function (details) {
  3702. var rowOfCells = findMap(details, function (detail) {
  3703. return parent(detail.element()).map(function (row) {
  3704. var isNew = parent(row).isNone();
  3705. return Structs.elementnew(row, isNew);
  3706. });
  3707. });
  3708. return rowOfCells.getOrThunk(function () {
  3709. return Structs.elementnew(generators.row(), true);
  3710. });
  3711. };
  3712. return map(rendered, function (details) {
  3713. var row = findRow(details.details());
  3714. return Structs.rowdatanew(row.element(), details.details(), details.section(), row.isNew());
  3715. });
  3716. };
  3717. var toDetailList = function (grid, generators) {
  3718. var rendered = Transitions.toDetails(grid, eq);
  3719. return deriveRows(rendered, generators);
  3720. };
  3721. var findInWarehouse = function (warehouse, element) {
  3722. var all = flatten(map(warehouse.all(), function (r) {
  3723. return r.cells();
  3724. }));
  3725. return find(all, function (e) {
  3726. return eq(element, e.element());
  3727. });
  3728. };
  3729. var run = function (operation, extract, adjustment, postAction, genWrappers) {
  3730. return function (wire, table, target, generators, direction) {
  3731. var input = DetailsList.fromTable(table);
  3732. var warehouse = Warehouse.generate(input);
  3733. var output = extract(warehouse, target).map(function (info) {
  3734. var model = fromWarehouse(warehouse, generators);
  3735. var result = operation(model, info, eq, genWrappers(generators));
  3736. var grid = toDetailList(result.grid(), generators);
  3737. return {
  3738. grid: constant(grid),
  3739. cursor: result.cursor
  3740. };
  3741. });
  3742. return output.fold(function () {
  3743. return Option.none();
  3744. }, function (out) {
  3745. var newElements = Redraw.render(table, out.grid());
  3746. adjustment(table, out.grid(), direction);
  3747. postAction(table);
  3748. Bars.refresh(wire, table, BarPositions.height, direction);
  3749. return Option.some({
  3750. cursor: out.cursor,
  3751. newRows: newElements.newRows,
  3752. newCells: newElements.newCells
  3753. });
  3754. });
  3755. };
  3756. };
  3757. var onCell = function (warehouse, target) {
  3758. return TableLookup.cell(target.element()).bind(function (cell) {
  3759. return findInWarehouse(warehouse, cell);
  3760. });
  3761. };
  3762. var onPaste = function (warehouse, target) {
  3763. return TableLookup.cell(target.element()).bind(function (cell) {
  3764. return findInWarehouse(warehouse, cell).map(function (details) {
  3765. return merge(details, {
  3766. generators: target.generators,
  3767. clipboard: target.clipboard
  3768. });
  3769. });
  3770. });
  3771. };
  3772. var onPasteRows = function (warehouse, target) {
  3773. var details = map(target.selection(), function (cell) {
  3774. return TableLookup.cell(cell).bind(function (lc) {
  3775. return findInWarehouse(warehouse, lc);
  3776. });
  3777. });
  3778. var cells = cat(details);
  3779. return cells.length > 0 ? Option.some(merge({ cells: cells }, {
  3780. generators: target.generators,
  3781. clipboard: target.clipboard
  3782. })) : Option.none();
  3783. };
  3784. var onMergable = function (warehouse, target) {
  3785. return target.mergable();
  3786. };
  3787. var onUnmergable = function (warehouse, target) {
  3788. return target.unmergable();
  3789. };
  3790. var onCells = function (warehouse, target) {
  3791. var details = map(target.selection(), function (cell) {
  3792. return TableLookup.cell(cell).bind(function (lc) {
  3793. return findInWarehouse(warehouse, lc);
  3794. });
  3795. });
  3796. var cells = cat(details);
  3797. return cells.length > 0 ? Option.some(cells) : Option.none();
  3798. };
  3799. var RunOperation = {
  3800. run: run,
  3801. toDetailList: toDetailList,
  3802. onCell: onCell,
  3803. onCells: onCells,
  3804. onPaste: onPaste,
  3805. onPasteRows: onPasteRows,
  3806. onMergable: onMergable,
  3807. onUnmergable: onUnmergable
  3808. };
  3809. var value$1 = function (o) {
  3810. var is = function (v) {
  3811. return o === v;
  3812. };
  3813. var or = function (opt) {
  3814. return value$1(o);
  3815. };
  3816. var orThunk = function (f) {
  3817. return value$1(o);
  3818. };
  3819. var map = function (f) {
  3820. return value$1(f(o));
  3821. };
  3822. var mapError = function (f) {
  3823. return value$1(o);
  3824. };
  3825. var each = function (f) {
  3826. f(o);
  3827. };
  3828. var bind = function (f) {
  3829. return f(o);
  3830. };
  3831. var fold = function (_, onValue) {
  3832. return onValue(o);
  3833. };
  3834. var exists = function (f) {
  3835. return f(o);
  3836. };
  3837. var forall = function (f) {
  3838. return f(o);
  3839. };
  3840. var toOption = function () {
  3841. return Option.some(o);
  3842. };
  3843. return {
  3844. is: is,
  3845. isValue: always,
  3846. isError: never,
  3847. getOr: constant(o),
  3848. getOrThunk: constant(o),
  3849. getOrDie: constant(o),
  3850. or: or,
  3851. orThunk: orThunk,
  3852. fold: fold,
  3853. map: map,
  3854. mapError: mapError,
  3855. each: each,
  3856. bind: bind,
  3857. exists: exists,
  3858. forall: forall,
  3859. toOption: toOption
  3860. };
  3861. };
  3862. var error = function (message) {
  3863. var getOrThunk = function (f) {
  3864. return f();
  3865. };
  3866. var getOrDie = function () {
  3867. return die(String(message))();
  3868. };
  3869. var or = function (opt) {
  3870. return opt;
  3871. };
  3872. var orThunk = function (f) {
  3873. return f();
  3874. };
  3875. var map = function (f) {
  3876. return error(message);
  3877. };
  3878. var mapError = function (f) {
  3879. return error(f(message));
  3880. };
  3881. var bind = function (f) {
  3882. return error(message);
  3883. };
  3884. var fold = function (onError, _) {
  3885. return onError(message);
  3886. };
  3887. return {
  3888. is: never,
  3889. isValue: never,
  3890. isError: always,
  3891. getOr: identity,
  3892. getOrThunk: getOrThunk,
  3893. getOrDie: getOrDie,
  3894. or: or,
  3895. orThunk: orThunk,
  3896. fold: fold,
  3897. map: map,
  3898. mapError: mapError,
  3899. each: noop,
  3900. bind: bind,
  3901. exists: never,
  3902. forall: always,
  3903. toOption: Option.none
  3904. };
  3905. };
  3906. var fromOption = function (opt, err) {
  3907. return opt.fold(function () {
  3908. return error(err);
  3909. }, value$1);
  3910. };
  3911. var Result = {
  3912. value: value$1,
  3913. error: error,
  3914. fromOption: fromOption
  3915. };
  3916. var measure = function (startAddress, gridA, gridB) {
  3917. if (startAddress.row() >= gridA.length || startAddress.column() > GridRow.cellLength(gridA[0])) {
  3918. return Result.error('invalid start address out of table bounds, row: ' + startAddress.row() + ', column: ' + startAddress.column());
  3919. }
  3920. var rowRemainder = gridA.slice(startAddress.row());
  3921. var colRemainder = rowRemainder[0].cells().slice(startAddress.column());
  3922. var colRequired = GridRow.cellLength(gridB[0]);
  3923. var rowRequired = gridB.length;
  3924. return Result.value({
  3925. rowDelta: constant(rowRemainder.length - rowRequired),
  3926. colDelta: constant(colRemainder.length - colRequired)
  3927. });
  3928. };
  3929. var measureWidth = function (gridA, gridB) {
  3930. var colLengthA = GridRow.cellLength(gridA[0]);
  3931. var colLengthB = GridRow.cellLength(gridB[0]);
  3932. return {
  3933. rowDelta: constant(0),
  3934. colDelta: constant(colLengthA - colLengthB)
  3935. };
  3936. };
  3937. var fill = function (cells, generator) {
  3938. return map(cells, function () {
  3939. return Structs.elementnew(generator.cell(), true);
  3940. });
  3941. };
  3942. var rowFill = function (grid, amount, generator) {
  3943. return grid.concat(Util.repeat(amount, function (_row) {
  3944. return GridRow.setCells(grid[grid.length - 1], fill(grid[grid.length - 1].cells(), generator));
  3945. }));
  3946. };
  3947. var colFill = function (grid, amount, generator) {
  3948. return map(grid, function (row) {
  3949. return GridRow.setCells(row, row.cells().concat(fill(Util.range(0, amount), generator)));
  3950. });
  3951. };
  3952. var tailor = function (gridA, delta, generator) {
  3953. var fillCols = delta.colDelta() < 0 ? colFill : identity;
  3954. var fillRows = delta.rowDelta() < 0 ? rowFill : identity;
  3955. var modifiedCols = fillCols(gridA, Math.abs(delta.colDelta()), generator);
  3956. var tailoredGrid = fillRows(modifiedCols, Math.abs(delta.rowDelta()), generator);
  3957. return tailoredGrid;
  3958. };
  3959. var Fitment = {
  3960. measure: measure,
  3961. measureWidth: measureWidth,
  3962. tailor: tailor
  3963. };
  3964. var merge$1 = function (grid, bounds, comparator, substitution) {
  3965. if (grid.length === 0) {
  3966. return grid;
  3967. }
  3968. for (var i = bounds.startRow(); i <= bounds.finishRow(); i++) {
  3969. for (var j = bounds.startCol(); j <= bounds.finishCol(); j++) {
  3970. GridRow.mutateCell(grid[i], j, Structs.elementnew(substitution(), false));
  3971. }
  3972. }
  3973. return grid;
  3974. };
  3975. var unmerge = function (grid, target, comparator, substitution) {
  3976. var first = true;
  3977. for (var i = 0; i < grid.length; i++) {
  3978. for (var j = 0; j < GridRow.cellLength(grid[0]); j++) {
  3979. var current = GridRow.getCellElement(grid[i], j);
  3980. var isToReplace = comparator(current, target);
  3981. if (isToReplace === true && first === false) {
  3982. GridRow.mutateCell(grid[i], j, Structs.elementnew(substitution(), true));
  3983. } else if (isToReplace === true) {
  3984. first = false;
  3985. }
  3986. }
  3987. }
  3988. return grid;
  3989. };
  3990. var uniqueCells = function (row, comparator) {
  3991. return foldl(row, function (rest, cell) {
  3992. return exists(rest, function (currentCell) {
  3993. return comparator(currentCell.element(), cell.element());
  3994. }) ? rest : rest.concat([cell]);
  3995. }, []);
  3996. };
  3997. var splitRows = function (grid, index, comparator, substitution) {
  3998. if (index > 0 && index < grid.length) {
  3999. var rowPrevCells = grid[index - 1].cells();
  4000. var cells = uniqueCells(rowPrevCells, comparator);
  4001. each(cells, function (cell) {
  4002. var replacement = Option.none();
  4003. var _loop_1 = function (i) {
  4004. var _loop_2 = function (j) {
  4005. var current = grid[i].cells()[j];
  4006. var isToReplace = comparator(current.element(), cell.element());
  4007. if (isToReplace) {
  4008. if (replacement.isNone()) {
  4009. replacement = Option.some(substitution());
  4010. }
  4011. replacement.each(function (sub) {
  4012. GridRow.mutateCell(grid[i], j, Structs.elementnew(sub, true));
  4013. });
  4014. }
  4015. };
  4016. for (var j = 0; j < GridRow.cellLength(grid[0]); j++) {
  4017. _loop_2(j);
  4018. }
  4019. };
  4020. for (var i = index; i < grid.length; i++) {
  4021. _loop_1(i);
  4022. }
  4023. });
  4024. }
  4025. return grid;
  4026. };
  4027. var MergingOperations = {
  4028. merge: merge$1,
  4029. unmerge: unmerge,
  4030. splitRows: splitRows
  4031. };
  4032. var isSpanning = function (grid, row, col, comparator) {
  4033. var candidate = GridRow.getCell(grid[row], col);
  4034. var matching = curry(comparator, candidate.element());
  4035. var currentRow = grid[row];
  4036. return grid.length > 1 && GridRow.cellLength(currentRow) > 1 && (col > 0 && matching(GridRow.getCellElement(currentRow, col - 1)) || col < currentRow.length - 1 && matching(GridRow.getCellElement(currentRow, col + 1)) || row > 0 && matching(GridRow.getCellElement(grid[row - 1], col)) || row < grid.length - 1 && matching(GridRow.getCellElement(grid[row + 1], col)));
  4037. };
  4038. var mergeTables = function (startAddress, gridA, gridB, generator, comparator) {
  4039. var startRow = startAddress.row();
  4040. var startCol = startAddress.column();
  4041. var mergeHeight = gridB.length;
  4042. var mergeWidth = GridRow.cellLength(gridB[0]);
  4043. var endRow = startRow + mergeHeight;
  4044. var endCol = startCol + mergeWidth;
  4045. for (var r = startRow; r < endRow; r++) {
  4046. for (var c = startCol; c < endCol; c++) {
  4047. if (isSpanning(gridA, r, c, comparator)) {
  4048. MergingOperations.unmerge(gridA, GridRow.getCellElement(gridA[r], c), comparator, generator.cell);
  4049. }
  4050. var newCell = GridRow.getCellElement(gridB[r - startRow], c - startCol);
  4051. var replacement = generator.replace(newCell);
  4052. GridRow.mutateCell(gridA[r], c, Structs.elementnew(replacement, true));
  4053. }
  4054. }
  4055. return gridA;
  4056. };
  4057. var merge$2 = function (startAddress, gridA, gridB, generator, comparator) {
  4058. var result = Fitment.measure(startAddress, gridA, gridB);
  4059. return result.map(function (delta) {
  4060. var fittedGrid = Fitment.tailor(gridA, delta, generator);
  4061. return mergeTables(startAddress, fittedGrid, gridB, generator, comparator);
  4062. });
  4063. };
  4064. var insert = function (index, gridA, gridB, generator, comparator) {
  4065. MergingOperations.splitRows(gridA, index, comparator, generator.cell);
  4066. var delta = Fitment.measureWidth(gridB, gridA);
  4067. var fittedNewGrid = Fitment.tailor(gridB, delta, generator);
  4068. var secondDelta = Fitment.measureWidth(gridA, fittedNewGrid);
  4069. var fittedOldGrid = Fitment.tailor(gridA, secondDelta, generator);
  4070. return fittedOldGrid.slice(0, index).concat(fittedNewGrid).concat(fittedOldGrid.slice(index, fittedOldGrid.length));
  4071. };
  4072. var TableMerge = {
  4073. merge: merge$2,
  4074. insert: insert
  4075. };
  4076. var insertRowAt = function (grid, index, example, comparator, substitution) {
  4077. var before = grid.slice(0, index);
  4078. var after = grid.slice(index);
  4079. var between = GridRow.mapCells(grid[example], function (ex, c) {
  4080. var withinSpan = index > 0 && index < grid.length && comparator(GridRow.getCellElement(grid[index - 1], c), GridRow.getCellElement(grid[index], c));
  4081. var ret = withinSpan ? GridRow.getCell(grid[index], c) : Structs.elementnew(substitution(ex.element(), comparator), true);
  4082. return ret;
  4083. });
  4084. return before.concat([between]).concat(after);
  4085. };
  4086. var insertColumnAt = function (grid, index, example, comparator, substitution) {
  4087. return map(grid, function (row) {
  4088. var withinSpan = index > 0 && index < GridRow.cellLength(row) && comparator(GridRow.getCellElement(row, index - 1), GridRow.getCellElement(row, index));
  4089. var sub = withinSpan ? GridRow.getCell(row, index) : Structs.elementnew(substitution(GridRow.getCellElement(row, example), comparator), true);
  4090. return GridRow.addCell(row, index, sub);
  4091. });
  4092. };
  4093. var splitCellIntoColumns = function (grid, exampleRow, exampleCol, comparator, substitution) {
  4094. var index = exampleCol + 1;
  4095. return map(grid, function (row, i) {
  4096. var isTargetCell = i === exampleRow;
  4097. var sub = isTargetCell ? Structs.elementnew(substitution(GridRow.getCellElement(row, exampleCol), comparator), true) : GridRow.getCell(row, exampleCol);
  4098. return GridRow.addCell(row, index, sub);
  4099. });
  4100. };
  4101. var splitCellIntoRows = function (grid, exampleRow, exampleCol, comparator, substitution) {
  4102. var index = exampleRow + 1;
  4103. var before = grid.slice(0, index);
  4104. var after = grid.slice(index);
  4105. var between = GridRow.mapCells(grid[exampleRow], function (ex, i) {
  4106. var isTargetCell = i === exampleCol;
  4107. return isTargetCell ? Structs.elementnew(substitution(ex.element(), comparator), true) : ex;
  4108. });
  4109. return before.concat([between]).concat(after);
  4110. };
  4111. var deleteColumnsAt = function (grid, start, finish) {
  4112. var rows = map(grid, function (row) {
  4113. var cells = row.cells().slice(0, start).concat(row.cells().slice(finish + 1));
  4114. return Structs.rowcells(cells, row.section());
  4115. });
  4116. return filter(rows, function (row) {
  4117. return row.cells().length > 0;
  4118. });
  4119. };
  4120. var deleteRowsAt = function (grid, start, finish) {
  4121. return grid.slice(0, start).concat(grid.slice(finish + 1));
  4122. };
  4123. var ModificationOperations = {
  4124. insertRowAt: insertRowAt,
  4125. insertColumnAt: insertColumnAt,
  4126. splitCellIntoColumns: splitCellIntoColumns,
  4127. splitCellIntoRows: splitCellIntoRows,
  4128. deleteRowsAt: deleteRowsAt,
  4129. deleteColumnsAt: deleteColumnsAt
  4130. };
  4131. var replaceIn = function (grid, targets, comparator, substitution) {
  4132. var isTarget = function (cell) {
  4133. return exists(targets, function (target) {
  4134. return comparator(cell.element(), target.element());
  4135. });
  4136. };
  4137. return map(grid, function (row) {
  4138. return GridRow.mapCells(row, function (cell) {
  4139. return isTarget(cell) ? Structs.elementnew(substitution(cell.element(), comparator), true) : cell;
  4140. });
  4141. });
  4142. };
  4143. var notStartRow = function (grid, rowIndex, colIndex, comparator) {
  4144. return GridRow.getCellElement(grid[rowIndex], colIndex) !== undefined && (rowIndex > 0 && comparator(GridRow.getCellElement(grid[rowIndex - 1], colIndex), GridRow.getCellElement(grid[rowIndex], colIndex)));
  4145. };
  4146. var notStartColumn = function (row, index, comparator) {
  4147. return index > 0 && comparator(GridRow.getCellElement(row, index - 1), GridRow.getCellElement(row, index));
  4148. };
  4149. var replaceColumn = function (grid, index, comparator, substitution) {
  4150. var targets = bind(grid, function (row, i) {
  4151. var alreadyAdded = notStartRow(grid, i, index, comparator) || notStartColumn(row, index, comparator);
  4152. return alreadyAdded ? [] : [GridRow.getCell(row, index)];
  4153. });
  4154. return replaceIn(grid, targets, comparator, substitution);
  4155. };
  4156. var replaceRow = function (grid, index, comparator, substitution) {
  4157. var targetRow = grid[index];
  4158. var targets = bind(targetRow.cells(), function (item, i) {
  4159. var alreadyAdded = notStartRow(grid, index, i, comparator) || notStartColumn(targetRow, i, comparator);
  4160. return alreadyAdded ? [] : [item];
  4161. });
  4162. return replaceIn(grid, targets, comparator, substitution);
  4163. };
  4164. var TransformOperations = {
  4165. replaceColumn: replaceColumn,
  4166. replaceRow: replaceRow
  4167. };
  4168. var none$1 = function () {
  4169. return folder(function (n, o, l, m, r) {
  4170. return n();
  4171. });
  4172. };
  4173. var only = function (index) {
  4174. return folder(function (n, o, l, m, r) {
  4175. return o(index);
  4176. });
  4177. };
  4178. var left = function (index, next) {
  4179. return folder(function (n, o, l, m, r) {
  4180. return l(index, next);
  4181. });
  4182. };
  4183. var middle = function (prev, index, next) {
  4184. return folder(function (n, o, l, m, r) {
  4185. return m(prev, index, next);
  4186. });
  4187. };
  4188. var right = function (prev, index) {
  4189. return folder(function (n, o, l, m, r) {
  4190. return r(prev, index);
  4191. });
  4192. };
  4193. var folder = function (fold) {
  4194. return { fold: fold };
  4195. };
  4196. var ColumnContext = {
  4197. none: none$1,
  4198. only: only,
  4199. left: left,
  4200. middle: middle,
  4201. right: right
  4202. };
  4203. var neighbours$1 = function (input, index) {
  4204. if (input.length === 0) {
  4205. return ColumnContext.none();
  4206. }
  4207. if (input.length === 1) {
  4208. return ColumnContext.only(0);
  4209. }
  4210. if (index === 0) {
  4211. return ColumnContext.left(0, 1);
  4212. }
  4213. if (index === input.length - 1) {
  4214. return ColumnContext.right(index - 1, index);
  4215. }
  4216. if (index > 0 && index < input.length - 1) {
  4217. return ColumnContext.middle(index - 1, index, index + 1);
  4218. }
  4219. return ColumnContext.none();
  4220. };
  4221. var determine = function (input, column, step, tableSize) {
  4222. var result = input.slice(0);
  4223. var context = neighbours$1(input, column);
  4224. var zero = function (array) {
  4225. return map(array, constant(0));
  4226. };
  4227. var onNone = constant(zero(result));
  4228. var onOnly = function (index) {
  4229. return tableSize.singleColumnWidth(result[index], step);
  4230. };
  4231. var onChange = function (index, next) {
  4232. if (step >= 0) {
  4233. var newNext = Math.max(tableSize.minCellWidth(), result[next] - step);
  4234. return zero(result.slice(0, index)).concat([
  4235. step,
  4236. newNext - result[next]
  4237. ]).concat(zero(result.slice(next + 1)));
  4238. } else {
  4239. var newThis = Math.max(tableSize.minCellWidth(), result[index] + step);
  4240. var diffx = result[index] - newThis;
  4241. return zero(result.slice(0, index)).concat([
  4242. newThis - result[index],
  4243. diffx
  4244. ]).concat(zero(result.slice(next + 1)));
  4245. }
  4246. };
  4247. var onLeft = onChange;
  4248. var onMiddle = function (prev, index, next) {
  4249. return onChange(index, next);
  4250. };
  4251. var onRight = function (prev, index) {
  4252. if (step >= 0) {
  4253. return zero(result.slice(0, index)).concat([step]);
  4254. } else {
  4255. var size = Math.max(tableSize.minCellWidth(), result[index] + step);
  4256. return zero(result.slice(0, index)).concat([size - result[index]]);
  4257. }
  4258. };
  4259. return context.fold(onNone, onOnly, onLeft, onMiddle, onRight);
  4260. };
  4261. var Deltas = { determine: determine };
  4262. var getSpan$1 = function (cell, type) {
  4263. return has$1(cell, type) && parseInt(get$1(cell, type), 10) > 1;
  4264. };
  4265. var hasColspan = function (cell) {
  4266. return getSpan$1(cell, 'colspan');
  4267. };
  4268. var hasRowspan = function (cell) {
  4269. return getSpan$1(cell, 'rowspan');
  4270. };
  4271. var getInt = function (element, property) {
  4272. return parseInt(get$2(element, property), 10);
  4273. };
  4274. var CellUtils = {
  4275. hasColspan: hasColspan,
  4276. hasRowspan: hasRowspan,
  4277. minWidth: constant(10),
  4278. minHeight: constant(10),
  4279. getInt: getInt
  4280. };
  4281. var getRaw$1 = function (cell, property, getter) {
  4282. return getRaw(cell, property).fold(function () {
  4283. return getter(cell) + 'px';
  4284. }, function (raw) {
  4285. return raw;
  4286. });
  4287. };
  4288. var getRawW = function (cell) {
  4289. return getRaw$1(cell, 'width', Sizes.getPixelWidth);
  4290. };
  4291. var getRawH = function (cell) {
  4292. return getRaw$1(cell, 'height', Sizes.getHeight);
  4293. };
  4294. var getWidthFrom = function (warehouse, direction, getWidth, fallback, tableSize) {
  4295. var columns = Blocks.columns(warehouse);
  4296. var backups = map(columns, function (cellOption) {
  4297. return cellOption.map(direction.edge);
  4298. });
  4299. return map(columns, function (cellOption, c) {
  4300. var columnCell = cellOption.filter(not(CellUtils.hasColspan));
  4301. return columnCell.fold(function () {
  4302. var deduced = Util.deduce(backups, c);
  4303. return fallback(deduced);
  4304. }, function (cell) {
  4305. return getWidth(cell, tableSize);
  4306. });
  4307. });
  4308. };
  4309. var getDeduced = function (deduced) {
  4310. return deduced.map(function (d) {
  4311. return d + 'px';
  4312. }).getOr('');
  4313. };
  4314. var getRawWidths = function (warehouse, direction) {
  4315. return getWidthFrom(warehouse, direction, getRawW, getDeduced);
  4316. };
  4317. var getPercentageWidths = function (warehouse, direction, tableSize) {
  4318. return getWidthFrom(warehouse, direction, Sizes.getPercentageWidth, function (deduced) {
  4319. return deduced.fold(function () {
  4320. return tableSize.minCellWidth();
  4321. }, function (cellWidth) {
  4322. return cellWidth / tableSize.pixelWidth() * 100;
  4323. });
  4324. }, tableSize);
  4325. };
  4326. var getPixelWidths = function (warehouse, direction, tableSize) {
  4327. return getWidthFrom(warehouse, direction, Sizes.getPixelWidth, function (deduced) {
  4328. return deduced.getOrThunk(tableSize.minCellWidth);
  4329. }, tableSize);
  4330. };
  4331. var getHeightFrom = function (warehouse, direction, getHeight, fallback) {
  4332. var rows = Blocks.rows(warehouse);
  4333. var backups = map(rows, function (cellOption) {
  4334. return cellOption.map(direction.edge);
  4335. });
  4336. return map(rows, function (cellOption, c) {
  4337. var rowCell = cellOption.filter(not(CellUtils.hasRowspan));
  4338. return rowCell.fold(function () {
  4339. var deduced = Util.deduce(backups, c);
  4340. return fallback(deduced);
  4341. }, function (cell) {
  4342. return getHeight(cell);
  4343. });
  4344. });
  4345. };
  4346. var getPixelHeights = function (warehouse, direction) {
  4347. return getHeightFrom(warehouse, direction, Sizes.getHeight, function (deduced) {
  4348. return deduced.getOrThunk(CellUtils.minHeight);
  4349. });
  4350. };
  4351. var getRawHeights = function (warehouse, direction) {
  4352. return getHeightFrom(warehouse, direction, getRawH, getDeduced);
  4353. };
  4354. var ColumnSizes = {
  4355. getRawWidths: getRawWidths,
  4356. getPixelWidths: getPixelWidths,
  4357. getPercentageWidths: getPercentageWidths,
  4358. getPixelHeights: getPixelHeights,
  4359. getRawHeights: getRawHeights
  4360. };
  4361. var total = function (start, end, measures) {
  4362. var r = 0;
  4363. for (var i = start; i < end; i++) {
  4364. r += measures[i] !== undefined ? measures[i] : 0;
  4365. }
  4366. return r;
  4367. };
  4368. var recalculateWidth = function (warehouse, widths) {
  4369. var all = Warehouse.justCells(warehouse);
  4370. return map(all, function (cell) {
  4371. var width = total(cell.column(), cell.column() + cell.colspan(), widths);
  4372. return {
  4373. element: cell.element,
  4374. width: constant(width),
  4375. colspan: cell.colspan
  4376. };
  4377. });
  4378. };
  4379. var recalculateHeight = function (warehouse, heights) {
  4380. var all = Warehouse.justCells(warehouse);
  4381. return map(all, function (cell) {
  4382. var height = total(cell.row(), cell.row() + cell.rowspan(), heights);
  4383. return {
  4384. element: cell.element,
  4385. height: constant(height),
  4386. rowspan: cell.rowspan
  4387. };
  4388. });
  4389. };
  4390. var matchRowHeight = function (warehouse, heights) {
  4391. return map(warehouse.all(), function (row, i) {
  4392. return {
  4393. element: row.element,
  4394. height: constant(heights[i])
  4395. };
  4396. });
  4397. };
  4398. var Recalculations = {
  4399. recalculateWidth: recalculateWidth,
  4400. recalculateHeight: recalculateHeight,
  4401. matchRowHeight: matchRowHeight
  4402. };
  4403. var percentageSize = function (width, element) {
  4404. var floatWidth = parseFloat(width);
  4405. var pixelWidth = get$5(element);
  4406. var getCellDelta = function (delta) {
  4407. return delta / pixelWidth * 100;
  4408. };
  4409. var singleColumnWidth = function (w, _delta) {
  4410. return [100 - w];
  4411. };
  4412. var minCellWidth = function () {
  4413. return CellUtils.minWidth() / pixelWidth * 100;
  4414. };
  4415. var setTableWidth = function (table, _newWidths, delta) {
  4416. var total = floatWidth + delta;
  4417. Sizes.setPercentageWidth(table, total);
  4418. };
  4419. return {
  4420. width: constant(floatWidth),
  4421. pixelWidth: constant(pixelWidth),
  4422. getWidths: ColumnSizes.getPercentageWidths,
  4423. getCellDelta: getCellDelta,
  4424. singleColumnWidth: singleColumnWidth,
  4425. minCellWidth: minCellWidth,
  4426. setElementWidth: Sizes.setPercentageWidth,
  4427. setTableWidth: setTableWidth
  4428. };
  4429. };
  4430. var pixelSize = function (width) {
  4431. var intWidth = parseInt(width, 10);
  4432. var getCellDelta = identity;
  4433. var singleColumnWidth = function (w, delta) {
  4434. var newNext = Math.max(CellUtils.minWidth(), w + delta);
  4435. return [newNext - w];
  4436. };
  4437. var setTableWidth = function (table, newWidths, _delta) {
  4438. var total = foldr(newWidths, function (b, a) {
  4439. return b + a;
  4440. }, 0);
  4441. Sizes.setPixelWidth(table, total);
  4442. };
  4443. return {
  4444. width: constant(intWidth),
  4445. pixelWidth: constant(intWidth),
  4446. getWidths: ColumnSizes.getPixelWidths,
  4447. getCellDelta: getCellDelta,
  4448. singleColumnWidth: singleColumnWidth,
  4449. minCellWidth: CellUtils.minWidth,
  4450. setElementWidth: Sizes.setPixelWidth,
  4451. setTableWidth: setTableWidth
  4452. };
  4453. };
  4454. var chooseSize = function (element, width) {
  4455. if (Sizes.percentageBasedSizeRegex().test(width)) {
  4456. var percentMatch = Sizes.percentageBasedSizeRegex().exec(width);
  4457. return percentageSize(percentMatch[1], element);
  4458. } else if (Sizes.pixelBasedSizeRegex().test(width)) {
  4459. var pixelMatch = Sizes.pixelBasedSizeRegex().exec(width);
  4460. return pixelSize(pixelMatch[1]);
  4461. } else {
  4462. var fallbackWidth = get$5(element);
  4463. return pixelSize(fallbackWidth);
  4464. }
  4465. };
  4466. var getTableSize = function (element) {
  4467. var width = Sizes.getRawWidth(element);
  4468. return width.fold(function () {
  4469. var fallbackWidth = get$5(element);
  4470. return pixelSize(fallbackWidth);
  4471. }, function (w) {
  4472. return chooseSize(element, w);
  4473. });
  4474. };
  4475. var TableSize = { getTableSize: getTableSize };
  4476. var getWarehouse$1 = function (list) {
  4477. return Warehouse.generate(list);
  4478. };
  4479. var sumUp = function (newSize) {
  4480. return foldr(newSize, function (b, a) {
  4481. return b + a;
  4482. }, 0);
  4483. };
  4484. var getTableWarehouse = function (table) {
  4485. var list = DetailsList.fromTable(table);
  4486. return getWarehouse$1(list);
  4487. };
  4488. var adjustWidth = function (table, delta, index, direction) {
  4489. var tableSize = TableSize.getTableSize(table);
  4490. var step = tableSize.getCellDelta(delta);
  4491. var warehouse = getTableWarehouse(table);
  4492. var widths = tableSize.getWidths(warehouse, direction, tableSize);
  4493. var deltas = Deltas.determine(widths, index, step, tableSize);
  4494. var newWidths = map(deltas, function (dx, i) {
  4495. return dx + widths[i];
  4496. });
  4497. var newSizes = Recalculations.recalculateWidth(warehouse, newWidths);
  4498. each(newSizes, function (cell) {
  4499. tableSize.setElementWidth(cell.element(), cell.width());
  4500. });
  4501. if (index === warehouse.grid().columns() - 1) {
  4502. tableSize.setTableWidth(table, newWidths, step);
  4503. }
  4504. };
  4505. var adjustHeight = function (table, delta, index, direction) {
  4506. var warehouse = getTableWarehouse(table);
  4507. var heights = ColumnSizes.getPixelHeights(warehouse, direction);
  4508. var newHeights = map(heights, function (dy, i) {
  4509. return index === i ? Math.max(delta + dy, CellUtils.minHeight()) : dy;
  4510. });
  4511. var newCellSizes = Recalculations.recalculateHeight(warehouse, newHeights);
  4512. var newRowSizes = Recalculations.matchRowHeight(warehouse, newHeights);
  4513. each(newRowSizes, function (row) {
  4514. Sizes.setHeight(row.element(), row.height());
  4515. });
  4516. each(newCellSizes, function (cell) {
  4517. Sizes.setHeight(cell.element(), cell.height());
  4518. });
  4519. var total = sumUp(newHeights);
  4520. Sizes.setHeight(table, total);
  4521. };
  4522. var adjustWidthTo = function (table, list, direction) {
  4523. var tableSize = TableSize.getTableSize(table);
  4524. var warehouse = getWarehouse$1(list);
  4525. var widths = tableSize.getWidths(warehouse, direction, tableSize);
  4526. var newSizes = Recalculations.recalculateWidth(warehouse, widths);
  4527. each(newSizes, function (cell) {
  4528. tableSize.setElementWidth(cell.element(), cell.width());
  4529. });
  4530. var total = foldr(widths, function (b, a) {
  4531. return a + b;
  4532. }, 0);
  4533. if (newSizes.length > 0) {
  4534. tableSize.setTableWidth(table, total);
  4535. }
  4536. };
  4537. var Adjustments = {
  4538. adjustWidth: adjustWidth,
  4539. adjustHeight: adjustHeight,
  4540. adjustWidthTo: adjustWidthTo
  4541. };
  4542. var base = function (handleUnsupported, required) {
  4543. return baseWith(handleUnsupported, required, {
  4544. validate: isFunction,
  4545. label: 'function'
  4546. });
  4547. };
  4548. var baseWith = function (handleUnsupported, required, pred) {
  4549. if (required.length === 0)
  4550. throw new Error('You must specify at least one required field.');
  4551. validateStrArr('required', required);
  4552. checkDupes(required);
  4553. return function (obj) {
  4554. var keys$1 = keys(obj);
  4555. var allReqd = forall(required, function (req) {
  4556. return contains(keys$1, req);
  4557. });
  4558. if (!allReqd)
  4559. reqMessage(required, keys$1);
  4560. handleUnsupported(required, keys$1);
  4561. var invalidKeys = filter(required, function (key) {
  4562. return !pred.validate(obj[key], key);
  4563. });
  4564. if (invalidKeys.length > 0)
  4565. invalidTypeMessage(invalidKeys, pred.label);
  4566. return obj;
  4567. };
  4568. };
  4569. var handleExact = function (required, keys) {
  4570. var unsupported = filter(keys, function (key) {
  4571. return !contains(required, key);
  4572. });
  4573. if (unsupported.length > 0)
  4574. unsuppMessage(unsupported);
  4575. };
  4576. var allowExtra = noop;
  4577. var exactly = function (required) {
  4578. return base(handleExact, required);
  4579. };
  4580. var ensure = function (required) {
  4581. return base(allowExtra, required);
  4582. };
  4583. var ensureWith = function (required, condition) {
  4584. return baseWith(allowExtra, required, condition);
  4585. };
  4586. var Contracts = /*#__PURE__*/Object.freeze({
  4587. exactly: exactly,
  4588. ensure: ensure,
  4589. ensureWith: ensureWith
  4590. });
  4591. var elementToData = function (element) {
  4592. var colspan = has$1(element, 'colspan') ? parseInt(get$1(element, 'colspan'), 10) : 1;
  4593. var rowspan = has$1(element, 'rowspan') ? parseInt(get$1(element, 'rowspan'), 10) : 1;
  4594. return {
  4595. element: constant(element),
  4596. colspan: constant(colspan),
  4597. rowspan: constant(rowspan)
  4598. };
  4599. };
  4600. var modification = function (generators, _toData) {
  4601. contract(generators);
  4602. var position = Cell(Option.none());
  4603. var toData = _toData !== undefined ? _toData : elementToData;
  4604. var nu = function (data) {
  4605. return generators.cell(data);
  4606. };
  4607. var nuFrom = function (element) {
  4608. var data = toData(element);
  4609. return nu(data);
  4610. };
  4611. var add = function (element) {
  4612. var replacement = nuFrom(element);
  4613. if (position.get().isNone()) {
  4614. position.set(Option.some(replacement));
  4615. }
  4616. recent = Option.some({
  4617. item: element,
  4618. replacement: replacement
  4619. });
  4620. return replacement;
  4621. };
  4622. var recent = Option.none();
  4623. var getOrInit = function (element, comparator) {
  4624. return recent.fold(function () {
  4625. return add(element);
  4626. }, function (p) {
  4627. return comparator(element, p.item) ? p.replacement : add(element);
  4628. });
  4629. };
  4630. return {
  4631. getOrInit: getOrInit,
  4632. cursor: position.get
  4633. };
  4634. };
  4635. var transform = function (scope, tag) {
  4636. return function (generators) {
  4637. var position = Cell(Option.none());
  4638. contract(generators);
  4639. var list = [];
  4640. var find$1 = function (element, comparator) {
  4641. return find(list, function (x) {
  4642. return comparator(x.item, element);
  4643. });
  4644. };
  4645. var makeNew = function (element) {
  4646. var cell = generators.replace(element, tag, { scope: scope });
  4647. list.push({
  4648. item: element,
  4649. sub: cell
  4650. });
  4651. if (position.get().isNone()) {
  4652. position.set(Option.some(cell));
  4653. }
  4654. return cell;
  4655. };
  4656. var replaceOrInit = function (element, comparator) {
  4657. return find$1(element, comparator).fold(function () {
  4658. return makeNew(element);
  4659. }, function (p) {
  4660. return comparator(element, p.item) ? p.sub : makeNew(element);
  4661. });
  4662. };
  4663. return {
  4664. replaceOrInit: replaceOrInit,
  4665. cursor: position.get
  4666. };
  4667. };
  4668. };
  4669. var merging = function (generators) {
  4670. contract(generators);
  4671. var position = Cell(Option.none());
  4672. var combine = function (cell) {
  4673. if (position.get().isNone()) {
  4674. position.set(Option.some(cell));
  4675. }
  4676. return function () {
  4677. var raw = generators.cell({
  4678. element: constant(cell),
  4679. colspan: constant(1),
  4680. rowspan: constant(1)
  4681. });
  4682. remove$1(raw, 'width');
  4683. remove$1(cell, 'width');
  4684. return raw;
  4685. };
  4686. };
  4687. return {
  4688. combine: combine,
  4689. cursor: position.get
  4690. };
  4691. };
  4692. var contract = exactly([
  4693. 'cell',
  4694. 'row',
  4695. 'replace',
  4696. 'gap'
  4697. ]);
  4698. var Generators = {
  4699. modification: modification,
  4700. transform: transform,
  4701. merging: merging
  4702. };
  4703. var blockList = [
  4704. 'body',
  4705. 'p',
  4706. 'div',
  4707. 'article',
  4708. 'aside',
  4709. 'figcaption',
  4710. 'figure',
  4711. 'footer',
  4712. 'header',
  4713. 'nav',
  4714. 'section',
  4715. 'ol',
  4716. 'ul',
  4717. 'table',
  4718. 'thead',
  4719. 'tfoot',
  4720. 'tbody',
  4721. 'caption',
  4722. 'tr',
  4723. 'td',
  4724. 'th',
  4725. 'h1',
  4726. 'h2',
  4727. 'h3',
  4728. 'h4',
  4729. 'h5',
  4730. 'h6',
  4731. 'blockquote',
  4732. 'pre',
  4733. 'address'
  4734. ];
  4735. var isList = function (universe, item) {
  4736. var tagName = universe.property().name(item);
  4737. return contains([
  4738. 'ol',
  4739. 'ul'
  4740. ], tagName);
  4741. };
  4742. var isBlock = function (universe, item) {
  4743. var tagName = universe.property().name(item);
  4744. return contains(blockList, tagName);
  4745. };
  4746. var isFormatting = function (universe, item) {
  4747. var tagName = universe.property().name(item);
  4748. return contains([
  4749. 'address',
  4750. 'pre',
  4751. 'p',
  4752. 'h1',
  4753. 'h2',
  4754. 'h3',
  4755. 'h4',
  4756. 'h5',
  4757. 'h6'
  4758. ], tagName);
  4759. };
  4760. var isHeading = function (universe, item) {
  4761. var tagName = universe.property().name(item);
  4762. return contains([
  4763. 'h1',
  4764. 'h2',
  4765. 'h3',
  4766. 'h4',
  4767. 'h5',
  4768. 'h6'
  4769. ], tagName);
  4770. };
  4771. var isContainer = function (universe, item) {
  4772. return contains([
  4773. 'div',
  4774. 'li',
  4775. 'td',
  4776. 'th',
  4777. 'blockquote',
  4778. 'body',
  4779. 'caption'
  4780. ], universe.property().name(item));
  4781. };
  4782. var isEmptyTag = function (universe, item) {
  4783. return contains([
  4784. 'br',
  4785. 'img',
  4786. 'hr',
  4787. 'input'
  4788. ], universe.property().name(item));
  4789. };
  4790. var isFrame = function (universe, item) {
  4791. return universe.property().name(item) === 'iframe';
  4792. };
  4793. var isInline = function (universe, item) {
  4794. return !(isBlock(universe, item) || isEmptyTag(universe, item)) && universe.property().name(item) !== 'li';
  4795. };
  4796. var Structure = {
  4797. isBlock: isBlock,
  4798. isList: isList,
  4799. isFormatting: isFormatting,
  4800. isHeading: isHeading,
  4801. isContainer: isContainer,
  4802. isEmptyTag: isEmptyTag,
  4803. isFrame: isFrame,
  4804. isInline: isInline
  4805. };
  4806. var universe$1 = DomUniverse();
  4807. var isBlock$1 = function (element) {
  4808. return Structure.isBlock(universe$1, element);
  4809. };
  4810. var isList$1 = function (element) {
  4811. return Structure.isList(universe$1, element);
  4812. };
  4813. var isFormatting$1 = function (element) {
  4814. return Structure.isFormatting(universe$1, element);
  4815. };
  4816. var isHeading$1 = function (element) {
  4817. return Structure.isHeading(universe$1, element);
  4818. };
  4819. var isContainer$1 = function (element) {
  4820. return Structure.isContainer(universe$1, element);
  4821. };
  4822. var isEmptyTag$1 = function (element) {
  4823. return Structure.isEmptyTag(universe$1, element);
  4824. };
  4825. var isFrame$1 = function (element) {
  4826. return Structure.isFrame(universe$1, element);
  4827. };
  4828. var isInline$1 = function (element) {
  4829. return Structure.isInline(universe$1, element);
  4830. };
  4831. var DomStructure = {
  4832. isBlock: isBlock$1,
  4833. isList: isList$1,
  4834. isFormatting: isFormatting$1,
  4835. isHeading: isHeading$1,
  4836. isContainer: isContainer$1,
  4837. isEmptyTag: isEmptyTag$1,
  4838. isFrame: isFrame$1,
  4839. isInline: isInline$1
  4840. };
  4841. var merge$3 = function (cells) {
  4842. var isBr = function (el) {
  4843. return name(el) === 'br';
  4844. };
  4845. var advancedBr = function (children) {
  4846. return forall(children, function (c) {
  4847. return isBr(c) || isText(c) && get$3(c).trim().length === 0;
  4848. });
  4849. };
  4850. var isListItem = function (el) {
  4851. return name(el) === 'li' || ancestor(el, DomStructure.isList).isSome();
  4852. };
  4853. var siblingIsBlock = function (el) {
  4854. return nextSibling(el).map(function (rightSibling) {
  4855. if (DomStructure.isBlock(rightSibling)) {
  4856. return true;
  4857. }
  4858. if (DomStructure.isEmptyTag(rightSibling)) {
  4859. return name(rightSibling) === 'img' ? false : true;
  4860. }
  4861. }).getOr(false);
  4862. };
  4863. var markCell = function (cell) {
  4864. return last$1(cell).bind(function (rightEdge) {
  4865. var rightSiblingIsBlock = siblingIsBlock(rightEdge);
  4866. return parent(rightEdge).map(function (parent) {
  4867. return rightSiblingIsBlock === true || isListItem(parent) || isBr(rightEdge) || DomStructure.isBlock(parent) && !eq(cell, parent) ? [] : [Element.fromTag('br')];
  4868. });
  4869. }).getOr([]);
  4870. };
  4871. var markContent = function () {
  4872. var content = bind(cells, function (cell) {
  4873. var children$1 = children(cell);
  4874. return advancedBr(children$1) ? [] : children$1.concat(markCell(cell));
  4875. });
  4876. return content.length === 0 ? [Element.fromTag('br')] : content;
  4877. };
  4878. var contents = markContent();
  4879. empty(cells[0]);
  4880. append$1(cells[0], contents);
  4881. };
  4882. var TableContent = { merge: merge$3 };
  4883. var prune = function (table) {
  4884. var cells = TableLookup.cells(table);
  4885. if (cells.length === 0) {
  4886. remove$2(table);
  4887. }
  4888. };
  4889. var outcome = Immutable('grid', 'cursor');
  4890. var elementFromGrid = function (grid, row, column) {
  4891. return findIn(grid, row, column).orThunk(function () {
  4892. return findIn(grid, 0, 0);
  4893. });
  4894. };
  4895. var findIn = function (grid, row, column) {
  4896. return Option.from(grid[row]).bind(function (r) {
  4897. return Option.from(r.cells()[column]).bind(function (c) {
  4898. return Option.from(c.element());
  4899. });
  4900. });
  4901. };
  4902. var bundle = function (grid, row, column) {
  4903. return outcome(grid, findIn(grid, row, column));
  4904. };
  4905. var uniqueRows = function (details) {
  4906. return foldl(details, function (rest, detail) {
  4907. return exists(rest, function (currentDetail) {
  4908. return currentDetail.row() === detail.row();
  4909. }) ? rest : rest.concat([detail]);
  4910. }, []).sort(function (detailA, detailB) {
  4911. return detailA.row() - detailB.row();
  4912. });
  4913. };
  4914. var uniqueColumns = function (details) {
  4915. return foldl(details, function (rest, detail) {
  4916. return exists(rest, function (currentDetail) {
  4917. return currentDetail.column() === detail.column();
  4918. }) ? rest : rest.concat([detail]);
  4919. }, []).sort(function (detailA, detailB) {
  4920. return detailA.column() - detailB.column();
  4921. });
  4922. };
  4923. var insertRowBefore = function (grid, detail, comparator, genWrappers) {
  4924. var example = detail.row();
  4925. var targetIndex = detail.row();
  4926. var newGrid = ModificationOperations.insertRowAt(grid, targetIndex, example, comparator, genWrappers.getOrInit);
  4927. return bundle(newGrid, targetIndex, detail.column());
  4928. };
  4929. var insertRowsBefore = function (grid, details, comparator, genWrappers) {
  4930. var example = details[0].row();
  4931. var targetIndex = details[0].row();
  4932. var rows = uniqueRows(details);
  4933. var newGrid = foldl(rows, function (newG, _row) {
  4934. return ModificationOperations.insertRowAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
  4935. }, grid);
  4936. return bundle(newGrid, targetIndex, details[0].column());
  4937. };
  4938. var insertRowAfter = function (grid, detail, comparator, genWrappers) {
  4939. var example = detail.row();
  4940. var targetIndex = detail.row() + detail.rowspan();
  4941. var newGrid = ModificationOperations.insertRowAt(grid, targetIndex, example, comparator, genWrappers.getOrInit);
  4942. return bundle(newGrid, targetIndex, detail.column());
  4943. };
  4944. var insertRowsAfter = function (grid, details, comparator, genWrappers) {
  4945. var rows = uniqueRows(details);
  4946. var example = rows[rows.length - 1].row();
  4947. var targetIndex = rows[rows.length - 1].row() + rows[rows.length - 1].rowspan();
  4948. var newGrid = foldl(rows, function (newG, _row) {
  4949. return ModificationOperations.insertRowAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
  4950. }, grid);
  4951. return bundle(newGrid, targetIndex, details[0].column());
  4952. };
  4953. var insertColumnBefore = function (grid, detail, comparator, genWrappers) {
  4954. var example = detail.column();
  4955. var targetIndex = detail.column();
  4956. var newGrid = ModificationOperations.insertColumnAt(grid, targetIndex, example, comparator, genWrappers.getOrInit);
  4957. return bundle(newGrid, detail.row(), targetIndex);
  4958. };
  4959. var insertColumnsBefore = function (grid, details, comparator, genWrappers) {
  4960. var columns = uniqueColumns(details);
  4961. var example = columns[0].column();
  4962. var targetIndex = columns[0].column();
  4963. var newGrid = foldl(columns, function (newG, _row) {
  4964. return ModificationOperations.insertColumnAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
  4965. }, grid);
  4966. return bundle(newGrid, details[0].row(), targetIndex);
  4967. };
  4968. var insertColumnAfter = function (grid, detail, comparator, genWrappers) {
  4969. var example = detail.column();
  4970. var targetIndex = detail.column() + detail.colspan();
  4971. var newGrid = ModificationOperations.insertColumnAt(grid, targetIndex, example, comparator, genWrappers.getOrInit);
  4972. return bundle(newGrid, detail.row(), targetIndex);
  4973. };
  4974. var insertColumnsAfter = function (grid, details, comparator, genWrappers) {
  4975. var example = details[details.length - 1].column();
  4976. var targetIndex = details[details.length - 1].column() + details[details.length - 1].colspan();
  4977. var columns = uniqueColumns(details);
  4978. var newGrid = foldl(columns, function (newG, _row) {
  4979. return ModificationOperations.insertColumnAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
  4980. }, grid);
  4981. return bundle(newGrid, details[0].row(), targetIndex);
  4982. };
  4983. var makeRowHeader = function (grid, detail, comparator, genWrappers) {
  4984. var newGrid = TransformOperations.replaceRow(grid, detail.row(), comparator, genWrappers.replaceOrInit);
  4985. return bundle(newGrid, detail.row(), detail.column());
  4986. };
  4987. var makeColumnHeader = function (grid, detail, comparator, genWrappers) {
  4988. var newGrid = TransformOperations.replaceColumn(grid, detail.column(), comparator, genWrappers.replaceOrInit);
  4989. return bundle(newGrid, detail.row(), detail.column());
  4990. };
  4991. var unmakeRowHeader = function (grid, detail, comparator, genWrappers) {
  4992. var newGrid = TransformOperations.replaceRow(grid, detail.row(), comparator, genWrappers.replaceOrInit);
  4993. return bundle(newGrid, detail.row(), detail.column());
  4994. };
  4995. var unmakeColumnHeader = function (grid, detail, comparator, genWrappers) {
  4996. var newGrid = TransformOperations.replaceColumn(grid, detail.column(), comparator, genWrappers.replaceOrInit);
  4997. return bundle(newGrid, detail.row(), detail.column());
  4998. };
  4999. var splitCellIntoColumns$1 = function (grid, detail, comparator, genWrappers) {
  5000. var newGrid = ModificationOperations.splitCellIntoColumns(grid, detail.row(), detail.column(), comparator, genWrappers.getOrInit);
  5001. return bundle(newGrid, detail.row(), detail.column());
  5002. };
  5003. var splitCellIntoRows$1 = function (grid, detail, comparator, genWrappers) {
  5004. var newGrid = ModificationOperations.splitCellIntoRows(grid, detail.row(), detail.column(), comparator, genWrappers.getOrInit);
  5005. return bundle(newGrid, detail.row(), detail.column());
  5006. };
  5007. var eraseColumns = function (grid, details, comparator, _genWrappers) {
  5008. var columns = uniqueColumns(details);
  5009. var newGrid = ModificationOperations.deleteColumnsAt(grid, columns[0].column(), columns[columns.length - 1].column());
  5010. var cursor = elementFromGrid(newGrid, details[0].row(), details[0].column());
  5011. return outcome(newGrid, cursor);
  5012. };
  5013. var eraseRows = function (grid, details, comparator, _genWrappers) {
  5014. var rows = uniqueRows(details);
  5015. var newGrid = ModificationOperations.deleteRowsAt(grid, rows[0].row(), rows[rows.length - 1].row());
  5016. var cursor = elementFromGrid(newGrid, details[0].row(), details[0].column());
  5017. return outcome(newGrid, cursor);
  5018. };
  5019. var mergeCells = function (grid, mergable, comparator, _genWrappers) {
  5020. var cells = mergable.cells();
  5021. TableContent.merge(cells);
  5022. var newGrid = MergingOperations.merge(grid, mergable.bounds(), comparator, constant(cells[0]));
  5023. return outcome(newGrid, Option.from(cells[0]));
  5024. };
  5025. var unmergeCells = function (grid, unmergable, comparator, genWrappers) {
  5026. var newGrid = foldr(unmergable, function (b, cell) {
  5027. return MergingOperations.unmerge(b, cell, comparator, genWrappers.combine(cell));
  5028. }, grid);
  5029. return outcome(newGrid, Option.from(unmergable[0]));
  5030. };
  5031. var pasteCells = function (grid, pasteDetails, comparator, genWrappers) {
  5032. var gridify = function (table, generators) {
  5033. var list = DetailsList.fromTable(table);
  5034. var wh = Warehouse.generate(list);
  5035. return Transitions.toGrid(wh, generators, true);
  5036. };
  5037. var gridB = gridify(pasteDetails.clipboard(), pasteDetails.generators());
  5038. var startAddress = Structs.address(pasteDetails.row(), pasteDetails.column());
  5039. var mergedGrid = TableMerge.merge(startAddress, grid, gridB, pasteDetails.generators(), comparator);
  5040. return mergedGrid.fold(function () {
  5041. return outcome(grid, Option.some(pasteDetails.element()));
  5042. }, function (nuGrid) {
  5043. var cursor = elementFromGrid(nuGrid, pasteDetails.row(), pasteDetails.column());
  5044. return outcome(nuGrid, cursor);
  5045. });
  5046. };
  5047. var gridifyRows = function (rows, generators, example) {
  5048. var pasteDetails = DetailsList.fromPastedRows(rows, example);
  5049. var wh = Warehouse.generate(pasteDetails);
  5050. return Transitions.toGrid(wh, generators, true);
  5051. };
  5052. var pasteRowsBefore = function (grid, pasteDetails, comparator, genWrappers) {
  5053. var example = grid[pasteDetails.cells[0].row()];
  5054. var index = pasteDetails.cells[0].row();
  5055. var gridB = gridifyRows(pasteDetails.clipboard(), pasteDetails.generators(), example);
  5056. var mergedGrid = TableMerge.insert(index, grid, gridB, pasteDetails.generators(), comparator);
  5057. var cursor = elementFromGrid(mergedGrid, pasteDetails.cells[0].row(), pasteDetails.cells[0].column());
  5058. return outcome(mergedGrid, cursor);
  5059. };
  5060. var pasteRowsAfter = function (grid, pasteDetails, comparator, genWrappers) {
  5061. var example = grid[pasteDetails.cells[0].row()];
  5062. var index = pasteDetails.cells[pasteDetails.cells.length - 1].row() + pasteDetails.cells[pasteDetails.cells.length - 1].rowspan();
  5063. var gridB = gridifyRows(pasteDetails.clipboard(), pasteDetails.generators(), example);
  5064. var mergedGrid = TableMerge.insert(index, grid, gridB, pasteDetails.generators(), comparator);
  5065. var cursor = elementFromGrid(mergedGrid, pasteDetails.cells[0].row(), pasteDetails.cells[0].column());
  5066. return outcome(mergedGrid, cursor);
  5067. };
  5068. var resize = Adjustments.adjustWidthTo;
  5069. var TableOperations = {
  5070. insertRowBefore: RunOperation.run(insertRowBefore, RunOperation.onCell, noop, noop, Generators.modification),
  5071. insertRowsBefore: RunOperation.run(insertRowsBefore, RunOperation.onCells, noop, noop, Generators.modification),
  5072. insertRowAfter: RunOperation.run(insertRowAfter, RunOperation.onCell, noop, noop, Generators.modification),
  5073. insertRowsAfter: RunOperation.run(insertRowsAfter, RunOperation.onCells, noop, noop, Generators.modification),
  5074. insertColumnBefore: RunOperation.run(insertColumnBefore, RunOperation.onCell, resize, noop, Generators.modification),
  5075. insertColumnsBefore: RunOperation.run(insertColumnsBefore, RunOperation.onCells, resize, noop, Generators.modification),
  5076. insertColumnAfter: RunOperation.run(insertColumnAfter, RunOperation.onCell, resize, noop, Generators.modification),
  5077. insertColumnsAfter: RunOperation.run(insertColumnsAfter, RunOperation.onCells, resize, noop, Generators.modification),
  5078. splitCellIntoColumns: RunOperation.run(splitCellIntoColumns$1, RunOperation.onCell, resize, noop, Generators.modification),
  5079. splitCellIntoRows: RunOperation.run(splitCellIntoRows$1, RunOperation.onCell, noop, noop, Generators.modification),
  5080. eraseColumns: RunOperation.run(eraseColumns, RunOperation.onCells, resize, prune, Generators.modification),
  5081. eraseRows: RunOperation.run(eraseRows, RunOperation.onCells, noop, prune, Generators.modification),
  5082. makeColumnHeader: RunOperation.run(makeColumnHeader, RunOperation.onCell, noop, noop, Generators.transform('row', 'th')),
  5083. unmakeColumnHeader: RunOperation.run(unmakeColumnHeader, RunOperation.onCell, noop, noop, Generators.transform(null, 'td')),
  5084. makeRowHeader: RunOperation.run(makeRowHeader, RunOperation.onCell, noop, noop, Generators.transform('col', 'th')),
  5085. unmakeRowHeader: RunOperation.run(unmakeRowHeader, RunOperation.onCell, noop, noop, Generators.transform(null, 'td')),
  5086. mergeCells: RunOperation.run(mergeCells, RunOperation.onMergable, noop, noop, Generators.merging),
  5087. unmergeCells: RunOperation.run(unmergeCells, RunOperation.onUnmergable, resize, noop, Generators.merging),
  5088. pasteCells: RunOperation.run(pasteCells, RunOperation.onPaste, resize, noop, Generators.modification),
  5089. pasteRowsBefore: RunOperation.run(pasteRowsBefore, RunOperation.onPasteRows, noop, noop, Generators.modification),
  5090. pasteRowsAfter: RunOperation.run(pasteRowsAfter, RunOperation.onPasteRows, noop, noop, Generators.modification)
  5091. };
  5092. var getBody$1 = function (editor) {
  5093. return Element.fromDom(editor.getBody());
  5094. };
  5095. var getPixelWidth$1 = function (elm) {
  5096. return elm.getBoundingClientRect().width;
  5097. };
  5098. var getPixelHeight = function (elm) {
  5099. return elm.getBoundingClientRect().height;
  5100. };
  5101. var getIsRoot = function (editor) {
  5102. return function (element) {
  5103. return eq(element, getBody$1(editor));
  5104. };
  5105. };
  5106. var removePxSuffix = function (size) {
  5107. return size ? size.replace(/px$/, '') : '';
  5108. };
  5109. var addSizeSuffix = function (size) {
  5110. if (/^[0-9]+$/.test(size)) {
  5111. size += 'px';
  5112. }
  5113. return size;
  5114. };
  5115. var removeDataStyle = function (table) {
  5116. var dataStyleCells = descendants$1(table, 'td[data-mce-style],th[data-mce-style]');
  5117. remove(table, 'data-mce-style');
  5118. each(dataStyleCells, function (cell) {
  5119. remove(cell, 'data-mce-style');
  5120. });
  5121. };
  5122. var getDirection = function (element) {
  5123. return get$2(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
  5124. };
  5125. var ltr$1 = { isRtl: constant(false) };
  5126. var rtl$1 = { isRtl: constant(true) };
  5127. var directionAt = function (element) {
  5128. var dir = getDirection(element);
  5129. return dir === 'rtl' ? rtl$1 : ltr$1;
  5130. };
  5131. var Direction = { directionAt: directionAt };
  5132. var defaultTableToolbar = 'tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol';
  5133. var defaultStyles = {
  5134. 'border-collapse': 'collapse',
  5135. 'width': '100%'
  5136. };
  5137. var defaultAttributes = { border: '1' };
  5138. var getDefaultAttributes = function (editor) {
  5139. return editor.getParam('table_default_attributes', defaultAttributes, 'object');
  5140. };
  5141. var getDefaultStyles = function (editor) {
  5142. return editor.getParam('table_default_styles', defaultStyles, 'object');
  5143. };
  5144. var hasTableResizeBars = function (editor) {
  5145. return editor.getParam('table_resize_bars', true, 'boolean');
  5146. };
  5147. var hasTabNavigation = function (editor) {
  5148. return editor.getParam('table_tab_navigation', true, 'boolean');
  5149. };
  5150. var hasAdvancedCellTab = function (editor) {
  5151. return editor.getParam('table_cell_advtab', true, 'boolean');
  5152. };
  5153. var hasAdvancedRowTab = function (editor) {
  5154. return editor.getParam('table_row_advtab', true, 'boolean');
  5155. };
  5156. var hasAdvancedTableTab = function (editor) {
  5157. return editor.getParam('table_advtab', true, 'boolean');
  5158. };
  5159. var hasAppearanceOptions = function (editor) {
  5160. return editor.getParam('table_appearance_options', true, 'boolean');
  5161. };
  5162. var hasTableGrid = function (editor) {
  5163. return editor.getParam('table_grid', true, 'boolean');
  5164. };
  5165. var shouldStyleWithCss = function (editor) {
  5166. return editor.getParam('table_style_by_css', false, 'boolean');
  5167. };
  5168. var getCellClassList = function (editor) {
  5169. return editor.getParam('table_cell_class_list', [], 'array');
  5170. };
  5171. var getRowClassList = function (editor) {
  5172. return editor.getParam('table_row_class_list', [], 'array');
  5173. };
  5174. var getTableClassList = function (editor) {
  5175. return editor.getParam('table_class_list', [], 'array');
  5176. };
  5177. var isPixelsForced = function (editor) {
  5178. return editor.getParam('table_responsive_width') === false;
  5179. };
  5180. var getToolbar = function (editor) {
  5181. return editor.getParam('table_toolbar', defaultTableToolbar);
  5182. };
  5183. var getCloneElements = function (editor) {
  5184. var cloneElements = editor.getParam('table_clone_elements');
  5185. if (isString(cloneElements)) {
  5186. return Option.some(cloneElements.split(/[ ,]/));
  5187. } else if (Array.isArray(cloneElements)) {
  5188. return Option.some(cloneElements);
  5189. } else {
  5190. return Option.none();
  5191. }
  5192. };
  5193. var hasObjectResizing = function (editor) {
  5194. var objectResizing = editor.getParam('object_resizing', true);
  5195. return isString(objectResizing) ? objectResizing === 'table' : objectResizing;
  5196. };
  5197. var fireNewRow = function (editor, row) {
  5198. return editor.fire('newrow', { node: row });
  5199. };
  5200. var fireNewCell = function (editor, cell) {
  5201. return editor.fire('newcell', { node: cell });
  5202. };
  5203. var fireObjectResizeStart = function (editor, target, width, height) {
  5204. editor.fire('ObjectResizeStart', {
  5205. target: target,
  5206. width: width,
  5207. height: height
  5208. });
  5209. };
  5210. var fireObjectResized = function (editor, target, width, height) {
  5211. editor.fire('ObjectResized', {
  5212. target: target,
  5213. width: width,
  5214. height: height
  5215. });
  5216. };
  5217. var TableActions = function (editor, lazyWire) {
  5218. var isTableBody = function (editor) {
  5219. return name(getBody$1(editor)) === 'table';
  5220. };
  5221. var lastRowGuard = function (table) {
  5222. var size = TableGridSize.getGridSize(table);
  5223. return isTableBody(editor) === false || size.rows() > 1;
  5224. };
  5225. var lastColumnGuard = function (table) {
  5226. var size = TableGridSize.getGridSize(table);
  5227. return isTableBody(editor) === false || size.columns() > 1;
  5228. };
  5229. var cloneFormats = getCloneElements(editor);
  5230. var execute = function (operation, guard, mutate, lazyWire) {
  5231. return function (table, target) {
  5232. removeDataStyle(table);
  5233. var wire = lazyWire();
  5234. var doc = Element.fromDom(editor.getDoc());
  5235. var direction = TableDirection(Direction.directionAt);
  5236. var generators = TableFill.cellOperations(mutate, doc, cloneFormats);
  5237. return guard(table) ? operation(wire, table, target, generators, direction).bind(function (result) {
  5238. each(result.newRows(), function (row) {
  5239. fireNewRow(editor, row.dom());
  5240. });
  5241. each(result.newCells(), function (cell) {
  5242. fireNewCell(editor, cell.dom());
  5243. });
  5244. return result.cursor().map(function (cell) {
  5245. var rng = editor.dom.createRng();
  5246. rng.setStart(cell.dom(), 0);
  5247. rng.setEnd(cell.dom(), 0);
  5248. return rng;
  5249. });
  5250. }) : Option.none();
  5251. };
  5252. };
  5253. var deleteRow = execute(TableOperations.eraseRows, lastRowGuard, noop, lazyWire);
  5254. var deleteColumn = execute(TableOperations.eraseColumns, lastColumnGuard, noop, lazyWire);
  5255. var insertRowsBefore = execute(TableOperations.insertRowsBefore, always, noop, lazyWire);
  5256. var insertRowsAfter = execute(TableOperations.insertRowsAfter, always, noop, lazyWire);
  5257. var insertColumnsBefore = execute(TableOperations.insertColumnsBefore, always, CellMutations.halve, lazyWire);
  5258. var insertColumnsAfter = execute(TableOperations.insertColumnsAfter, always, CellMutations.halve, lazyWire);
  5259. var mergeCells = execute(TableOperations.mergeCells, always, noop, lazyWire);
  5260. var unmergeCells = execute(TableOperations.unmergeCells, always, noop, lazyWire);
  5261. var pasteRowsBefore = execute(TableOperations.pasteRowsBefore, always, noop, lazyWire);
  5262. var pasteRowsAfter = execute(TableOperations.pasteRowsAfter, always, noop, lazyWire);
  5263. var pasteCells = execute(TableOperations.pasteCells, always, noop, lazyWire);
  5264. return {
  5265. deleteRow: deleteRow,
  5266. deleteColumn: deleteColumn,
  5267. insertRowsBefore: insertRowsBefore,
  5268. insertRowsAfter: insertRowsAfter,
  5269. insertColumnsBefore: insertColumnsBefore,
  5270. insertColumnsAfter: insertColumnsAfter,
  5271. mergeCells: mergeCells,
  5272. unmergeCells: unmergeCells,
  5273. pasteRowsBefore: pasteRowsBefore,
  5274. pasteRowsAfter: pasteRowsAfter,
  5275. pasteCells: pasteCells
  5276. };
  5277. };
  5278. var copyRows = function (table, target, generators) {
  5279. var list = DetailsList.fromTable(table);
  5280. var house = Warehouse.generate(list);
  5281. var details = RunOperation.onCells(house, target);
  5282. return details.map(function (selectedCells) {
  5283. var grid = Transitions.toGrid(house, generators, false);
  5284. var slicedGrid = grid.slice(selectedCells[0].row(), selectedCells[selectedCells.length - 1].row() + selectedCells[selectedCells.length - 1].rowspan());
  5285. var slicedDetails = RunOperation.toDetailList(slicedGrid, generators);
  5286. return Redraw.copy(slicedDetails);
  5287. });
  5288. };
  5289. var CopyRows = { copyRows: copyRows };
  5290. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  5291. var getTDTHOverallStyle = function (dom, elm, name) {
  5292. var cells = dom.select('td,th', elm);
  5293. var firstChildStyle;
  5294. var checkChildren = function (firstChildStyle, elms) {
  5295. for (var i = 0; i < elms.length; i++) {
  5296. var currentStyle = dom.getStyle(elms[i], name);
  5297. if (typeof firstChildStyle === 'undefined') {
  5298. firstChildStyle = currentStyle;
  5299. }
  5300. if (firstChildStyle !== currentStyle) {
  5301. return '';
  5302. }
  5303. }
  5304. return firstChildStyle;
  5305. };
  5306. firstChildStyle = checkChildren(firstChildStyle, cells);
  5307. return firstChildStyle;
  5308. };
  5309. var applyAlign = function (editor, elm, name) {
  5310. if (name) {
  5311. editor.formatter.apply('align' + name, {}, elm);
  5312. }
  5313. };
  5314. var applyVAlign = function (editor, elm, name) {
  5315. if (name) {
  5316. editor.formatter.apply('valign' + name, {}, elm);
  5317. }
  5318. };
  5319. var unApplyAlign = function (editor, elm) {
  5320. global$1.each('left center right'.split(' '), function (name) {
  5321. editor.formatter.remove('align' + name, {}, elm);
  5322. });
  5323. };
  5324. var unApplyVAlign = function (editor, elm) {
  5325. global$1.each('top middle bottom'.split(' '), function (name) {
  5326. editor.formatter.remove('valign' + name, {}, elm);
  5327. });
  5328. };
  5329. var Styles$1 = {
  5330. applyAlign: applyAlign,
  5331. applyVAlign: applyVAlign,
  5332. unApplyAlign: unApplyAlign,
  5333. unApplyVAlign: unApplyVAlign,
  5334. getTDTHOverallStyle: getTDTHOverallStyle
  5335. };
  5336. var __assign = function () {
  5337. __assign = Object.assign || function __assign(t) {
  5338. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5339. s = arguments[i];
  5340. for (var p in s)
  5341. if (Object.prototype.hasOwnProperty.call(s, p))
  5342. t[p] = s[p];
  5343. }
  5344. return t;
  5345. };
  5346. return __assign.apply(this, arguments);
  5347. };
  5348. var buildListItems = function (inputList, itemCallback, startItems) {
  5349. var appendItems = function (values, output) {
  5350. output = output || [];
  5351. global$1.each(values, function (item) {
  5352. var menuItem = { text: item.text || item.title };
  5353. if (item.menu) {
  5354. menuItem.menu = appendItems(item.menu);
  5355. } else {
  5356. menuItem.value = item.value;
  5357. if (itemCallback) {
  5358. itemCallback(menuItem);
  5359. }
  5360. }
  5361. output.push(menuItem);
  5362. });
  5363. return output;
  5364. };
  5365. return appendItems(inputList, startItems || []);
  5366. };
  5367. var extractAdvancedStyles = function (dom, elm) {
  5368. var rgbToHex = function (value) {
  5369. return startsWith(value, 'rgb') ? dom.toHex(value) : value;
  5370. };
  5371. var borderStyle = getRaw(Element.fromDom(elm), 'border-style').getOr('');
  5372. var borderColor = getRaw(Element.fromDom(elm), 'border-color').map(rgbToHex).getOr('');
  5373. var bgColor = getRaw(Element.fromDom(elm), 'background-color').map(rgbToHex).getOr('');
  5374. return {
  5375. borderstyle: borderStyle,
  5376. bordercolor: borderColor,
  5377. backgroundcolor: bgColor
  5378. };
  5379. };
  5380. var getSharedValues = function (data) {
  5381. var baseData = data[0];
  5382. var comparisonData = data.slice(1);
  5383. var keys$1 = keys(baseData);
  5384. each(comparisonData, function (items) {
  5385. each(keys$1, function (key) {
  5386. each$1(items, function (itemValue, itemKey, _) {
  5387. var comparisonValue = baseData[key];
  5388. if (comparisonValue !== '' && key === itemKey) {
  5389. if (comparisonValue !== itemValue) {
  5390. baseData[key] = '';
  5391. }
  5392. }
  5393. });
  5394. });
  5395. });
  5396. return baseData;
  5397. };
  5398. var getAdvancedTab = function () {
  5399. var items = [
  5400. {
  5401. name: 'borderstyle',
  5402. type: 'selectbox',
  5403. label: 'Border style',
  5404. items: [
  5405. {
  5406. text: 'Select...',
  5407. value: ''
  5408. },
  5409. {
  5410. text: 'Solid',
  5411. value: 'solid'
  5412. },
  5413. {
  5414. text: 'Dotted',
  5415. value: 'dotted'
  5416. },
  5417. {
  5418. text: 'Dashed',
  5419. value: 'dashed'
  5420. },
  5421. {
  5422. text: 'Double',
  5423. value: 'double'
  5424. },
  5425. {
  5426. text: 'Groove',
  5427. value: 'groove'
  5428. },
  5429. {
  5430. text: 'Ridge',
  5431. value: 'ridge'
  5432. },
  5433. {
  5434. text: 'Inset',
  5435. value: 'inset'
  5436. },
  5437. {
  5438. text: 'Outset',
  5439. value: 'outset'
  5440. },
  5441. {
  5442. text: 'None',
  5443. value: 'none'
  5444. },
  5445. {
  5446. text: 'Hidden',
  5447. value: 'hidden'
  5448. }
  5449. ]
  5450. },
  5451. {
  5452. name: 'bordercolor',
  5453. type: 'colorinput',
  5454. label: 'Border color'
  5455. },
  5456. {
  5457. name: 'backgroundcolor',
  5458. type: 'colorinput',
  5459. label: 'Background color'
  5460. }
  5461. ];
  5462. return {
  5463. title: 'Advanced',
  5464. name: 'advanced',
  5465. items: items
  5466. };
  5467. };
  5468. var getAlignment = function (alignments, formatName, dataName, editor, elm) {
  5469. var alignmentData = {};
  5470. global$1.each(alignments.split(' '), function (name) {
  5471. if (editor.formatter.matchNode(elm, formatName + name)) {
  5472. alignmentData[dataName] = name;
  5473. }
  5474. });
  5475. if (!alignmentData[dataName]) {
  5476. alignmentData[dataName] = '';
  5477. }
  5478. return alignmentData;
  5479. };
  5480. var getHAlignment = curry(getAlignment, 'left center right');
  5481. var getVAlignment = curry(getAlignment, 'top middle bottom');
  5482. var extractDataFromSettings = function (editor, hasAdvTableTab) {
  5483. var style = getDefaultStyles(editor);
  5484. var attrs = getDefaultAttributes(editor);
  5485. var extractAdvancedStyleData = function (dom) {
  5486. var rgbToHex = function (value) {
  5487. return startsWith(value, 'rgb') ? dom.toHex(value) : value;
  5488. };
  5489. var borderStyle = get(style, 'border-style').getOr('');
  5490. var borderColor = get(style, 'border-color').getOr('');
  5491. var bgColor = get(style, 'background-color').getOr('');
  5492. return {
  5493. borderstyle: borderStyle,
  5494. bordercolor: rgbToHex(borderColor),
  5495. backgroundcolor: rgbToHex(bgColor)
  5496. };
  5497. };
  5498. var defaultData = {
  5499. height: '',
  5500. width: '100%',
  5501. cellspacing: '',
  5502. cellpadding: '',
  5503. caption: false,
  5504. class: '',
  5505. align: '',
  5506. border: ''
  5507. };
  5508. var getBorder = function () {
  5509. var borderWidth = style['border-width'];
  5510. if (shouldStyleWithCss(editor) && borderWidth) {
  5511. return { border: borderWidth };
  5512. }
  5513. return get(attrs, 'border').fold(function () {
  5514. return {};
  5515. }, function (border) {
  5516. return { border: border };
  5517. });
  5518. };
  5519. var dom = editor.dom;
  5520. var advStyle = hasAdvTableTab ? extractAdvancedStyleData(dom) : {};
  5521. var getCellPaddingCellSpacing = function () {
  5522. var spacing = get(style, 'border-spacing').or(get(attrs, 'cellspacing')).fold(function () {
  5523. return {};
  5524. }, function (cellspacing) {
  5525. return { cellspacing: cellspacing };
  5526. });
  5527. var padding = get(style, 'border-padding').or(get(attrs, 'cellpadding')).fold(function () {
  5528. return {};
  5529. }, function (cellpadding) {
  5530. return { cellpadding: cellpadding };
  5531. });
  5532. return __assign({}, spacing, padding);
  5533. };
  5534. var data = __assign({}, defaultData, style, attrs, advStyle, getBorder(), getCellPaddingCellSpacing());
  5535. return data;
  5536. };
  5537. var extractDataFromTableElement = function (editor, elm, hasAdvTableTab) {
  5538. var getBorder = function (dom, elm) {
  5539. var optBorderWidth = getRaw(Element.fromDom(elm), 'border-width');
  5540. if (shouldStyleWithCss(editor) && optBorderWidth.isSome()) {
  5541. return optBorderWidth.getOr('');
  5542. }
  5543. return dom.getAttrib(elm, 'border') || Styles$1.getTDTHOverallStyle(editor.dom, elm, 'border-width') || Styles$1.getTDTHOverallStyle(editor.dom, elm, 'border');
  5544. };
  5545. var dom = editor.dom;
  5546. var data = __assign({
  5547. width: dom.getStyle(elm, 'width') || dom.getAttrib(elm, 'width'),
  5548. height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
  5549. cellspacing: dom.getStyle(elm, 'border-spacing') || dom.getAttrib(elm, 'cellspacing'),
  5550. cellpadding: dom.getAttrib(elm, 'cellpadding') || Styles$1.getTDTHOverallStyle(editor.dom, elm, 'padding'),
  5551. border: getBorder(dom, elm),
  5552. caption: !!dom.select('caption', elm)[0],
  5553. class: dom.getAttrib(elm, 'class', '')
  5554. }, getHAlignment('align', 'align', editor, elm), hasAdvTableTab ? extractAdvancedStyles(dom, elm) : {});
  5555. return data;
  5556. };
  5557. var extractDataFromRowElement = function (editor, elm, hasAdvancedRowTab) {
  5558. var dom = editor.dom;
  5559. var data = __assign({
  5560. height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
  5561. scope: dom.getAttrib(elm, 'scope'),
  5562. class: dom.getAttrib(elm, 'class', ''),
  5563. align: '',
  5564. type: elm.parentNode.nodeName.toLowerCase()
  5565. }, getHAlignment('align', 'align', editor, elm), hasAdvancedRowTab ? extractAdvancedStyles(dom, elm) : {});
  5566. return data;
  5567. };
  5568. var extractDataFromCellElement = function (editor, elm, hasAdvancedCellTab) {
  5569. var dom = editor.dom;
  5570. var data = __assign({
  5571. width: dom.getStyle(elm, 'width') || dom.getAttrib(elm, 'width'),
  5572. height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
  5573. scope: dom.getAttrib(elm, 'scope'),
  5574. celltype: elm.nodeName.toLowerCase(),
  5575. class: dom.getAttrib(elm, 'class', '')
  5576. }, getHAlignment('align', 'halign', editor, elm), getVAlignment('valign', 'valign', editor, elm), hasAdvancedCellTab ? extractAdvancedStyles(dom, elm) : {});
  5577. return data;
  5578. };
  5579. var Helpers = {
  5580. buildListItems: buildListItems,
  5581. extractAdvancedStyles: extractAdvancedStyles,
  5582. getSharedValues: getSharedValues,
  5583. getAdvancedTab: getAdvancedTab,
  5584. extractDataFromTableElement: extractDataFromTableElement,
  5585. extractDataFromRowElement: extractDataFromRowElement,
  5586. extractDataFromCellElement: extractDataFromCellElement,
  5587. extractDataFromSettings: extractDataFromSettings
  5588. };
  5589. var getClassList = function (editor) {
  5590. var rowClassList = getCellClassList(editor);
  5591. var classes = Helpers.buildListItems(rowClassList, function (item) {
  5592. if (item.value) {
  5593. item.textStyle = function () {
  5594. return editor.formatter.getCssText({
  5595. block: 'tr',
  5596. classes: [item.value]
  5597. });
  5598. };
  5599. }
  5600. });
  5601. if (rowClassList.length > 0) {
  5602. return Option.some({
  5603. name: 'class',
  5604. type: 'selectbox',
  5605. label: 'Class',
  5606. items: classes
  5607. });
  5608. }
  5609. return Option.none();
  5610. };
  5611. var children$3 = [
  5612. {
  5613. name: 'width',
  5614. type: 'input',
  5615. label: 'Width'
  5616. },
  5617. {
  5618. name: 'height',
  5619. type: 'input',
  5620. label: 'Height'
  5621. },
  5622. {
  5623. name: 'celltype',
  5624. type: 'selectbox',
  5625. label: 'Cell type',
  5626. items: [
  5627. {
  5628. text: 'Cell',
  5629. value: 'td'
  5630. },
  5631. {
  5632. text: 'Header cell',
  5633. value: 'th'
  5634. }
  5635. ]
  5636. },
  5637. {
  5638. name: 'scope',
  5639. type: 'selectbox',
  5640. label: 'Scope',
  5641. items: [
  5642. {
  5643. text: 'None',
  5644. value: ''
  5645. },
  5646. {
  5647. text: 'Row',
  5648. value: 'row'
  5649. },
  5650. {
  5651. text: 'Column',
  5652. value: 'col'
  5653. },
  5654. {
  5655. text: 'Row group',
  5656. value: 'rowgroup'
  5657. },
  5658. {
  5659. text: 'Column group',
  5660. value: 'colgroup'
  5661. }
  5662. ]
  5663. },
  5664. {
  5665. name: 'halign',
  5666. type: 'selectbox',
  5667. label: 'H Align',
  5668. items: [
  5669. {
  5670. text: 'None',
  5671. value: ''
  5672. },
  5673. {
  5674. text: 'Left',
  5675. value: 'left'
  5676. },
  5677. {
  5678. text: 'Center',
  5679. value: 'center'
  5680. },
  5681. {
  5682. text: 'Right',
  5683. value: 'right'
  5684. }
  5685. ]
  5686. },
  5687. {
  5688. name: 'valign',
  5689. type: 'selectbox',
  5690. label: 'V Align',
  5691. items: [
  5692. {
  5693. text: 'None',
  5694. value: ''
  5695. },
  5696. {
  5697. text: 'Top',
  5698. value: 'top'
  5699. },
  5700. {
  5701. text: 'Middle',
  5702. value: 'middle'
  5703. },
  5704. {
  5705. text: 'Bottom',
  5706. value: 'bottom'
  5707. }
  5708. ]
  5709. }
  5710. ];
  5711. var getItems = function (editor) {
  5712. return getClassList(editor).fold(function () {
  5713. return children$3;
  5714. }, function (classlist) {
  5715. return children$3.concat(classlist);
  5716. });
  5717. };
  5718. var CellDialogGeneralTab = { getItems: getItems };
  5719. var normal = function (dom, node) {
  5720. var setAttrib = function (attr, value) {
  5721. dom.setAttrib(node, attr, value);
  5722. };
  5723. var setStyle = function (prop, value) {
  5724. dom.setStyle(node, prop, value);
  5725. };
  5726. return {
  5727. setAttrib: setAttrib,
  5728. setStyle: setStyle
  5729. };
  5730. };
  5731. var ifTruthy = function (dom, node) {
  5732. var setAttrib = function (attr, value) {
  5733. if (value) {
  5734. dom.setAttrib(node, attr, value);
  5735. }
  5736. };
  5737. var setStyle = function (prop, value) {
  5738. if (value) {
  5739. dom.setStyle(node, prop, value);
  5740. }
  5741. };
  5742. return {
  5743. setAttrib: setAttrib,
  5744. setStyle: setStyle
  5745. };
  5746. };
  5747. var DomModifiers = {
  5748. normal: normal,
  5749. ifTruthy: ifTruthy
  5750. };
  5751. var updateSimpleProps = function (modifiers, data) {
  5752. modifiers.setAttrib('scope', data.scope);
  5753. modifiers.setAttrib('class', data.class);
  5754. modifiers.setStyle('width', addSizeSuffix(data.width));
  5755. modifiers.setStyle('height', addSizeSuffix(data.height));
  5756. };
  5757. var updateAdvancedProps = function (modifiers, data) {
  5758. modifiers.setStyle('background-color', data.backgroundcolor);
  5759. modifiers.setStyle('border-color', data.bordercolor);
  5760. modifiers.setStyle('border-style', data.borderstyle);
  5761. };
  5762. var applyToSingle = function (editor, cells, data) {
  5763. var dom = editor.dom;
  5764. var cellElm = data.celltype && cells[0].nodeName.toLowerCase() !== data.celltype ? dom.rename(cells[0], data.celltype) : cells[0];
  5765. var modifiers = DomModifiers.normal(dom, cellElm);
  5766. updateSimpleProps(modifiers, data);
  5767. if (hasAdvancedCellTab(editor)) {
  5768. updateAdvancedProps(modifiers, data);
  5769. }
  5770. Styles$1.unApplyAlign(editor, cellElm);
  5771. Styles$1.unApplyVAlign(editor, cellElm);
  5772. if (data.halign) {
  5773. Styles$1.applyAlign(editor, cellElm, data.halign);
  5774. }
  5775. if (data.valign) {
  5776. Styles$1.applyVAlign(editor, cellElm, data.valign);
  5777. }
  5778. };
  5779. var applyToMultiple = function (editor, cells, data) {
  5780. var dom = editor.dom;
  5781. global$1.each(cells, function (cellElm) {
  5782. if (data.celltype && cellElm.nodeName.toLowerCase() !== data.celltype) {
  5783. cellElm = dom.rename(cellElm, data.celltype);
  5784. }
  5785. var modifiers = DomModifiers.ifTruthy(dom, cellElm);
  5786. updateSimpleProps(modifiers, data);
  5787. if (hasAdvancedCellTab(editor)) {
  5788. updateAdvancedProps(modifiers, data);
  5789. }
  5790. if (data.halign) {
  5791. Styles$1.applyAlign(editor, cellElm, data.halign);
  5792. }
  5793. if (data.valign) {
  5794. Styles$1.applyVAlign(editor, cellElm, data.valign);
  5795. }
  5796. });
  5797. };
  5798. var onSubmitCellForm = function (editor, cells, api) {
  5799. var data = api.getData();
  5800. api.close();
  5801. editor.undoManager.transact(function () {
  5802. var applicator = cells.length === 1 ? applyToSingle : applyToMultiple;
  5803. applicator(editor, cells, data);
  5804. editor.focus();
  5805. });
  5806. };
  5807. var open = function (editor) {
  5808. var cellElm, cells = [];
  5809. cells = editor.dom.select('td[data-mce-selected],th[data-mce-selected]');
  5810. cellElm = editor.dom.getParent(editor.selection.getStart(), 'td,th');
  5811. if (!cells.length && cellElm) {
  5812. cells.push(cellElm);
  5813. }
  5814. cellElm = cellElm || cells[0];
  5815. if (!cellElm) {
  5816. return;
  5817. }
  5818. var cellsData = global$1.map(cells, function (cellElm) {
  5819. return Helpers.extractDataFromCellElement(editor, cellElm, hasAdvancedCellTab(editor));
  5820. });
  5821. var data = Helpers.getSharedValues(cellsData);
  5822. var dialogTabPanel = {
  5823. type: 'tabpanel',
  5824. tabs: [
  5825. {
  5826. title: 'General',
  5827. name: 'general',
  5828. items: CellDialogGeneralTab.getItems(editor)
  5829. },
  5830. Helpers.getAdvancedTab()
  5831. ]
  5832. };
  5833. var dialogPanel = {
  5834. type: 'panel',
  5835. items: [{
  5836. type: 'grid',
  5837. columns: 2,
  5838. items: CellDialogGeneralTab.getItems(editor)
  5839. }]
  5840. };
  5841. editor.windowManager.open({
  5842. title: 'Cell Properties',
  5843. size: 'normal',
  5844. body: hasAdvancedCellTab(editor) ? dialogTabPanel : dialogPanel,
  5845. buttons: [
  5846. {
  5847. type: 'cancel',
  5848. name: 'cancel',
  5849. text: 'Cancel'
  5850. },
  5851. {
  5852. type: 'submit',
  5853. name: 'save',
  5854. text: 'Save',
  5855. primary: true
  5856. }
  5857. ],
  5858. initialData: data,
  5859. onSubmit: curry(onSubmitCellForm, editor, cells)
  5860. });
  5861. };
  5862. var CellDialog = { open: open };
  5863. var getClassList$1 = function (editor) {
  5864. var rowClassList = getRowClassList(editor);
  5865. var classes = Helpers.buildListItems(rowClassList, function (item) {
  5866. if (item.value) {
  5867. item.textStyle = function () {
  5868. return editor.formatter.getCssText({
  5869. block: 'tr',
  5870. classes: [item.value]
  5871. });
  5872. };
  5873. }
  5874. });
  5875. if (rowClassList.length > 0) {
  5876. return Option.some({
  5877. name: 'class',
  5878. type: 'selectbox',
  5879. label: 'Class',
  5880. items: classes
  5881. });
  5882. }
  5883. return Option.none();
  5884. };
  5885. var formChildren = [
  5886. {
  5887. type: 'selectbox',
  5888. name: 'type',
  5889. label: 'Row type',
  5890. items: [
  5891. {
  5892. text: 'Header',
  5893. value: 'thead'
  5894. },
  5895. {
  5896. text: 'Body',
  5897. value: 'tbody'
  5898. },
  5899. {
  5900. text: 'Footer',
  5901. value: 'tfoot'
  5902. }
  5903. ]
  5904. },
  5905. {
  5906. type: 'selectbox',
  5907. name: 'align',
  5908. label: 'Alignment',
  5909. items: [
  5910. {
  5911. text: 'None',
  5912. value: ''
  5913. },
  5914. {
  5915. text: 'Left',
  5916. value: 'left'
  5917. },
  5918. {
  5919. text: 'Center',
  5920. value: 'center'
  5921. },
  5922. {
  5923. text: 'Right',
  5924. value: 'right'
  5925. }
  5926. ]
  5927. },
  5928. {
  5929. label: 'Height',
  5930. name: 'height',
  5931. type: 'input'
  5932. }
  5933. ];
  5934. var getItems$1 = function (editor) {
  5935. return getClassList$1(editor).fold(function () {
  5936. return formChildren;
  5937. }, function (classes) {
  5938. return formChildren.concat(classes);
  5939. });
  5940. };
  5941. var RowDialogGeneralTab = { getItems: getItems$1 };
  5942. var switchRowType = function (dom, rowElm, toType) {
  5943. var tableElm = dom.getParent(rowElm, 'table');
  5944. var oldParentElm = rowElm.parentNode;
  5945. var parentElm = dom.select(toType, tableElm)[0];
  5946. if (!parentElm) {
  5947. parentElm = dom.create(toType);
  5948. if (tableElm.firstChild) {
  5949. if (tableElm.firstChild.nodeName === 'CAPTION') {
  5950. dom.insertAfter(parentElm, tableElm.firstChild);
  5951. } else {
  5952. tableElm.insertBefore(parentElm, tableElm.firstChild);
  5953. }
  5954. } else {
  5955. tableElm.appendChild(parentElm);
  5956. }
  5957. }
  5958. parentElm.appendChild(rowElm);
  5959. if (!oldParentElm.hasChildNodes()) {
  5960. dom.remove(oldParentElm);
  5961. }
  5962. };
  5963. var updateAdvancedProps$1 = function (modifiers, data) {
  5964. modifiers.setStyle('background-color', data.backgroundcolor);
  5965. modifiers.setStyle('border-color', data.bordercolor);
  5966. modifiers.setStyle('border-style', data.borderstyle);
  5967. };
  5968. var onSubmitRowForm = function (editor, rows, oldData, api) {
  5969. var dom = editor.dom;
  5970. var data = api.getData();
  5971. api.close();
  5972. var createModifier = rows.length === 1 ? DomModifiers.normal : DomModifiers.ifTruthy;
  5973. editor.undoManager.transact(function () {
  5974. global$1.each(rows, function (rowElm) {
  5975. if (data.type !== rowElm.parentNode.nodeName.toLowerCase()) {
  5976. switchRowType(editor.dom, rowElm, data.type);
  5977. }
  5978. var modifiers = createModifier(dom, rowElm);
  5979. modifiers.setAttrib('scope', data.scope);
  5980. modifiers.setAttrib('class', data.class);
  5981. modifiers.setStyle('height', addSizeSuffix(data.height));
  5982. if (hasAdvancedRowTab(editor)) {
  5983. updateAdvancedProps$1(modifiers, data);
  5984. }
  5985. if (data.align !== oldData.align) {
  5986. Styles$1.unApplyAlign(editor, rowElm);
  5987. Styles$1.applyAlign(editor, rowElm, data.align);
  5988. }
  5989. });
  5990. editor.focus();
  5991. });
  5992. };
  5993. var open$1 = function (editor) {
  5994. var dom = editor.dom;
  5995. var tableElm, cellElm, rowElm;
  5996. var rows = [];
  5997. tableElm = dom.getParent(editor.selection.getStart(), 'table');
  5998. if (!tableElm) {
  5999. return;
  6000. }
  6001. cellElm = dom.getParent(editor.selection.getStart(), 'td,th');
  6002. global$1.each(tableElm.rows, function (row) {
  6003. global$1.each(row.cells, function (cell) {
  6004. if ((dom.getAttrib(cell, 'data-mce-selected') || cell === cellElm) && rows.indexOf(row) < 0) {
  6005. rows.push(row);
  6006. return false;
  6007. }
  6008. });
  6009. });
  6010. rowElm = rows[0];
  6011. if (!rowElm) {
  6012. return;
  6013. }
  6014. var rowsData = global$1.map(rows, function (rowElm) {
  6015. return Helpers.extractDataFromRowElement(editor, rowElm, hasAdvancedRowTab(editor));
  6016. });
  6017. var data = Helpers.getSharedValues(rowsData);
  6018. var dialogTabPanel = {
  6019. type: 'tabpanel',
  6020. tabs: [
  6021. {
  6022. title: 'General',
  6023. name: 'general',
  6024. items: RowDialogGeneralTab.getItems(editor)
  6025. },
  6026. Helpers.getAdvancedTab()
  6027. ]
  6028. };
  6029. var dialogPanel = {
  6030. type: 'panel',
  6031. items: [{
  6032. type: 'grid',
  6033. columns: 2,
  6034. items: RowDialogGeneralTab.getItems(editor)
  6035. }]
  6036. };
  6037. editor.windowManager.open({
  6038. title: 'Row Properties',
  6039. size: 'normal',
  6040. body: hasAdvancedRowTab(editor) ? dialogTabPanel : dialogPanel,
  6041. buttons: [
  6042. {
  6043. type: 'cancel',
  6044. name: 'cancel',
  6045. text: 'Cancel'
  6046. },
  6047. {
  6048. type: 'submit',
  6049. name: 'save',
  6050. text: 'Save',
  6051. primary: true
  6052. }
  6053. ],
  6054. initialData: data,
  6055. onSubmit: curry(onSubmitRowForm, editor, rows, data)
  6056. });
  6057. };
  6058. var RowDialog = { open: open$1 };
  6059. var global$2 = tinymce.util.Tools.resolve('tinymce.Env');
  6060. var DefaultRenderOptions = {
  6061. styles: {
  6062. 'border-collapse': 'collapse',
  6063. 'width': '100%'
  6064. },
  6065. attributes: { border: '1' },
  6066. percentages: true
  6067. };
  6068. var makeTable = function () {
  6069. return Element.fromTag('table');
  6070. };
  6071. var tableBody = function () {
  6072. return Element.fromTag('tbody');
  6073. };
  6074. var tableRow = function () {
  6075. return Element.fromTag('tr');
  6076. };
  6077. var tableHeaderCell = function () {
  6078. return Element.fromTag('th');
  6079. };
  6080. var tableCell = function () {
  6081. return Element.fromTag('td');
  6082. };
  6083. var render$1 = function (rows, columns, rowHeaders, columnHeaders, renderOpts) {
  6084. if (renderOpts === void 0) {
  6085. renderOpts = DefaultRenderOptions;
  6086. }
  6087. var table = makeTable();
  6088. setAll$1(table, renderOpts.styles);
  6089. setAll(table, renderOpts.attributes);
  6090. var tbody = tableBody();
  6091. append(table, tbody);
  6092. var trs = [];
  6093. for (var i = 0; i < rows; i++) {
  6094. var tr = tableRow();
  6095. for (var j = 0; j < columns; j++) {
  6096. var td = i < rowHeaders || j < columnHeaders ? tableHeaderCell() : tableCell();
  6097. if (j < columnHeaders) {
  6098. set(td, 'scope', 'row');
  6099. }
  6100. if (i < rowHeaders) {
  6101. set(td, 'scope', 'col');
  6102. }
  6103. append(td, Element.fromTag('br'));
  6104. if (renderOpts.percentages) {
  6105. set$1(td, 'width', 100 / columns + '%');
  6106. }
  6107. append(tr, td);
  6108. }
  6109. trs.push(tr);
  6110. }
  6111. append$1(tbody, trs);
  6112. return table;
  6113. };
  6114. var get$8 = function (element) {
  6115. return element.dom().innerHTML;
  6116. };
  6117. var getOuter$2 = function (element) {
  6118. var container = Element.fromTag('div');
  6119. var clone = Element.fromDom(element.dom().cloneNode(true));
  6120. append(container, clone);
  6121. return get$8(container);
  6122. };
  6123. var placeCaretInCell = function (editor, cell) {
  6124. editor.selection.select(cell.dom(), true);
  6125. editor.selection.collapse(true);
  6126. };
  6127. var selectFirstCellInTable = function (editor, tableElm) {
  6128. descendant$1(tableElm, 'td,th').each(curry(placeCaretInCell, editor));
  6129. };
  6130. var fireEvents = function (editor, table) {
  6131. each(descendants$1(table, 'tr'), function (row) {
  6132. fireNewRow(editor, row.dom());
  6133. each(descendants$1(row, 'th,td'), function (cell) {
  6134. fireNewCell(editor, cell.dom());
  6135. });
  6136. });
  6137. };
  6138. var isPercentage = function (width) {
  6139. return isString(width) && width.indexOf('%') !== -1;
  6140. };
  6141. var insert$1 = function (editor, columns, rows) {
  6142. var defaultStyles = getDefaultStyles(editor);
  6143. var options = {
  6144. styles: defaultStyles,
  6145. attributes: getDefaultAttributes(editor),
  6146. percentages: isPercentage(defaultStyles.width) && !isPixelsForced(editor)
  6147. };
  6148. var table = render$1(rows, columns, 0, 0, options);
  6149. set(table, 'data-mce-id', '__mce');
  6150. var html = getOuter$2(table);
  6151. editor.insertContent(html);
  6152. return descendant$1(getBody$1(editor), 'table[data-mce-id="__mce"]').map(function (table) {
  6153. if (isPixelsForced(editor)) {
  6154. set$1(table, 'width', get$2(table, 'width'));
  6155. }
  6156. remove(table, 'data-mce-id');
  6157. fireEvents(editor, table);
  6158. selectFirstCellInTable(editor, table);
  6159. return table.dom();
  6160. }).getOr(null);
  6161. };
  6162. var InsertTable = { insert: insert$1 };
  6163. var getItems$2 = function (editor, hasClasses, insertNewTable) {
  6164. var rowColCountItems = !insertNewTable ? [] : [
  6165. {
  6166. type: 'input',
  6167. name: 'cols',
  6168. label: 'Cols'
  6169. },
  6170. {
  6171. type: 'input',
  6172. name: 'rows',
  6173. label: 'Rows'
  6174. }
  6175. ];
  6176. var alwaysItems = [
  6177. {
  6178. type: 'input',
  6179. name: 'width',
  6180. label: 'Width'
  6181. },
  6182. {
  6183. type: 'input',
  6184. name: 'height',
  6185. label: 'Height'
  6186. }
  6187. ];
  6188. var appearanceItems = hasAppearanceOptions(editor) ? [
  6189. {
  6190. type: 'input',
  6191. name: 'cellspacing',
  6192. label: 'Cell spacing'
  6193. },
  6194. {
  6195. type: 'input',
  6196. name: 'cellpadding',
  6197. label: 'Cell padding'
  6198. },
  6199. {
  6200. type: 'input',
  6201. name: 'border',
  6202. label: 'Border width'
  6203. },
  6204. {
  6205. type: 'label',
  6206. label: 'Caption',
  6207. items: [{
  6208. type: 'checkbox',
  6209. name: 'caption',
  6210. label: 'Show caption'
  6211. }]
  6212. }
  6213. ] : [];
  6214. var alignmentItem = [{
  6215. type: 'selectbox',
  6216. name: 'align',
  6217. label: 'Alignment',
  6218. items: [
  6219. {
  6220. text: 'None',
  6221. value: ''
  6222. },
  6223. {
  6224. text: 'Left',
  6225. value: 'left'
  6226. },
  6227. {
  6228. text: 'Center',
  6229. value: 'center'
  6230. },
  6231. {
  6232. text: 'Right',
  6233. value: 'right'
  6234. }
  6235. ]
  6236. }];
  6237. var classListItem = hasClasses ? [{
  6238. type: 'selectbox',
  6239. name: 'class',
  6240. label: 'Class',
  6241. items: Helpers.buildListItems(getTableClassList(editor), function (item) {
  6242. if (item.value) {
  6243. item.textStyle = function () {
  6244. return editor.formatter.getCssText({
  6245. block: 'table',
  6246. classes: [item.value]
  6247. });
  6248. };
  6249. }
  6250. })
  6251. }] : [];
  6252. return rowColCountItems.concat(alwaysItems).concat(appearanceItems).concat(alignmentItem).concat(classListItem);
  6253. };
  6254. var TableDialogGeneralTab = { getItems: getItems$2 };
  6255. var styleTDTH = function (dom, elm, name, value) {
  6256. if (elm.tagName === 'TD' || elm.tagName === 'TH') {
  6257. if (isString(name)) {
  6258. dom.setStyle(elm, name, value);
  6259. } else {
  6260. dom.setStyle(elm, name);
  6261. }
  6262. } else {
  6263. if (elm.children) {
  6264. for (var i = 0; i < elm.children.length; i++) {
  6265. styleTDTH(dom, elm.children[i], name, value);
  6266. }
  6267. }
  6268. }
  6269. };
  6270. var applyDataToElement = function (editor, tableElm, data) {
  6271. var dom = editor.dom;
  6272. var attrs = {};
  6273. var styles = {};
  6274. attrs.class = data.class;
  6275. styles.height = addSizeSuffix(data.height);
  6276. if (dom.getAttrib(tableElm, 'width') && !shouldStyleWithCss(editor)) {
  6277. attrs.width = removePxSuffix(data.width);
  6278. } else {
  6279. styles.width = addSizeSuffix(data.width);
  6280. }
  6281. if (shouldStyleWithCss(editor)) {
  6282. styles['border-width'] = addSizeSuffix(data.border);
  6283. styles['border-spacing'] = addSizeSuffix(data.cellspacing);
  6284. } else {
  6285. attrs.border = data.border;
  6286. attrs.cellpadding = data.cellpadding;
  6287. attrs.cellspacing = data.cellspacing;
  6288. }
  6289. if (shouldStyleWithCss(editor) && tableElm.children) {
  6290. for (var i = 0; i < tableElm.children.length; i++) {
  6291. styleTDTH(dom, tableElm.children[i], {
  6292. 'border-width': addSizeSuffix(data.border),
  6293. 'padding': addSizeSuffix(data.cellpadding)
  6294. });
  6295. if (hasAdvancedTableTab(editor)) {
  6296. styleTDTH(dom, tableElm.children[i], { 'border-color': data.bordercolor });
  6297. }
  6298. }
  6299. }
  6300. if (hasAdvancedTableTab(editor)) {
  6301. styles['background-color'] = data.backgroundcolor;
  6302. styles['border-color'] = data.bordercolor;
  6303. styles['border-style'] = data.borderstyle;
  6304. }
  6305. attrs.style = dom.serializeStyle(merge(getDefaultStyles(editor), styles));
  6306. dom.setAttribs(tableElm, merge(getDefaultAttributes(editor), attrs));
  6307. };
  6308. var onSubmitTableForm = function (editor, tableElm, api) {
  6309. var dom = editor.dom;
  6310. var captionElm;
  6311. var data = api.getData();
  6312. api.close();
  6313. if (data.class === '') {
  6314. delete data.class;
  6315. }
  6316. editor.undoManager.transact(function () {
  6317. if (!tableElm) {
  6318. var cols = parseInt(data.cols, 10) || 1;
  6319. var rows = parseInt(data.rows, 10) || 1;
  6320. tableElm = InsertTable.insert(editor, cols, rows);
  6321. }
  6322. applyDataToElement(editor, tableElm, data);
  6323. captionElm = dom.select('caption', tableElm)[0];
  6324. if (captionElm && !data.caption) {
  6325. dom.remove(captionElm);
  6326. }
  6327. if (!captionElm && data.caption) {
  6328. captionElm = dom.create('caption');
  6329. captionElm.innerHTML = !global$2.ie ? '<br data-mce-bogus="1"/>' : '\xA0';
  6330. tableElm.insertBefore(captionElm, tableElm.firstChild);
  6331. }
  6332. if (data.align === '') {
  6333. Styles$1.unApplyAlign(editor, tableElm);
  6334. } else {
  6335. Styles$1.applyAlign(editor, tableElm, data.align);
  6336. }
  6337. editor.focus();
  6338. editor.addVisual();
  6339. });
  6340. };
  6341. var open$2 = function (editor, insertNewTable) {
  6342. var dom = editor.dom;
  6343. var tableElm;
  6344. var data = Helpers.extractDataFromSettings(editor, hasAdvancedTableTab(editor));
  6345. if (insertNewTable === false) {
  6346. tableElm = dom.getParent(editor.selection.getStart(), 'table');
  6347. if (tableElm) {
  6348. data = Helpers.extractDataFromTableElement(editor, tableElm, hasAdvancedTableTab(editor));
  6349. } else {
  6350. if (hasAdvancedTableTab(editor)) {
  6351. data.borderstyle = '';
  6352. data.bordercolor = '';
  6353. data.backgroundcolor = '';
  6354. }
  6355. }
  6356. } else {
  6357. data.cols = '1';
  6358. data.rows = '1';
  6359. if (hasAdvancedTableTab(editor)) {
  6360. data.borderstyle = '';
  6361. data.bordercolor = '';
  6362. data.backgroundcolor = '';
  6363. }
  6364. }
  6365. var hasClasses = getTableClassList(editor).length > 0;
  6366. if (hasClasses) {
  6367. if (data.class) {
  6368. data.class = data.class.replace(/\s*mce\-item\-table\s*/g, '');
  6369. }
  6370. }
  6371. var generalPanel = {
  6372. type: 'grid',
  6373. columns: 2,
  6374. items: TableDialogGeneralTab.getItems(editor, hasClasses, insertNewTable)
  6375. };
  6376. var nonAdvancedForm = function () {
  6377. return {
  6378. type: 'panel',
  6379. items: [generalPanel]
  6380. };
  6381. };
  6382. var advancedForm = function () {
  6383. return {
  6384. type: 'tabpanel',
  6385. tabs: [
  6386. {
  6387. title: 'General',
  6388. name: 'general',
  6389. items: [generalPanel]
  6390. },
  6391. Helpers.getAdvancedTab()
  6392. ]
  6393. };
  6394. };
  6395. var dialogBody = hasAdvancedTableTab(editor) ? advancedForm() : nonAdvancedForm();
  6396. editor.windowManager.open({
  6397. title: 'Table Properties',
  6398. size: 'normal',
  6399. body: dialogBody,
  6400. onSubmit: curry(onSubmitTableForm, editor, tableElm),
  6401. buttons: [
  6402. {
  6403. type: 'cancel',
  6404. name: 'cancel',
  6405. text: 'Cancel'
  6406. },
  6407. {
  6408. type: 'submit',
  6409. name: 'save',
  6410. text: 'Save',
  6411. primary: true
  6412. }
  6413. ],
  6414. initialData: data
  6415. });
  6416. };
  6417. var TableDialog = { open: open$2 };
  6418. var getSelectionStartFromSelector = function (selector) {
  6419. return function (editor) {
  6420. return Option.from(editor.dom.getParent(editor.selection.getStart(), selector)).map(Element.fromDom);
  6421. };
  6422. };
  6423. var getSelectionStartCell = getSelectionStartFromSelector('th,td');
  6424. var getSelectionStartCellOrCaption = getSelectionStartFromSelector('th,td,caption');
  6425. var each$3 = global$1.each;
  6426. var registerCommands = function (editor, actions, cellSelection, selections, clipboardRows) {
  6427. var isRoot = getIsRoot(editor);
  6428. var eraseTable = function () {
  6429. getSelectionStartCellOrCaption(editor).each(function (cellOrCaption) {
  6430. var tableOpt = TableLookup.table(cellOrCaption, isRoot);
  6431. tableOpt.filter(not(isRoot)).each(function (table) {
  6432. var cursor = Element.fromText('');
  6433. after(table, cursor);
  6434. remove$2(table);
  6435. if (editor.dom.isEmpty(editor.getBody())) {
  6436. editor.setContent('');
  6437. editor.selection.setCursorLocation();
  6438. } else {
  6439. var rng = editor.dom.createRng();
  6440. rng.setStart(cursor.dom(), 0);
  6441. rng.setEnd(cursor.dom(), 0);
  6442. editor.selection.setRng(rng);
  6443. editor.nodeChanged();
  6444. }
  6445. });
  6446. });
  6447. };
  6448. var getTableFromCell = function (cell) {
  6449. return TableLookup.table(cell, isRoot);
  6450. };
  6451. var getSize = function (table) {
  6452. return {
  6453. width: getPixelWidth$1(table.dom()),
  6454. height: getPixelWidth$1(table.dom())
  6455. };
  6456. };
  6457. var resizeChange = function (editor, oldSize, table) {
  6458. var newSize = getSize(table);
  6459. if (oldSize.width !== newSize.width || oldSize.height !== newSize.height) {
  6460. fireObjectResizeStart(editor, table.dom(), oldSize.width, oldSize.height);
  6461. fireObjectResized(editor, table.dom(), newSize.width, newSize.height);
  6462. }
  6463. };
  6464. var actOnSelection = function (execute) {
  6465. getSelectionStartCell(editor).each(function (cell) {
  6466. getTableFromCell(cell).each(function (table) {
  6467. var targets = TableTargets.forMenu(selections, table, cell);
  6468. var beforeSize = getSize(table);
  6469. execute(table, targets).each(function (rng) {
  6470. resizeChange(editor, beforeSize, table);
  6471. editor.selection.setRng(rng);
  6472. editor.focus();
  6473. cellSelection.clear(table);
  6474. removeDataStyle(table);
  6475. });
  6476. });
  6477. });
  6478. };
  6479. var copyRowSelection = function (execute) {
  6480. return getSelectionStartCell(editor).map(function (cell) {
  6481. return getTableFromCell(cell).bind(function (table) {
  6482. var doc = Element.fromDom(editor.getDoc());
  6483. var targets = TableTargets.forMenu(selections, table, cell);
  6484. var generators = TableFill.cellOperations(noop, doc, Option.none());
  6485. return CopyRows.copyRows(table, targets, generators);
  6486. });
  6487. });
  6488. };
  6489. var pasteOnSelection = function (execute) {
  6490. clipboardRows.get().each(function (rows) {
  6491. var clonedRows = map(rows, function (row) {
  6492. return deep(row);
  6493. });
  6494. getSelectionStartCell(editor).each(function (cell) {
  6495. getTableFromCell(cell).each(function (table) {
  6496. var doc = Element.fromDom(editor.getDoc());
  6497. var generators = TableFill.paste(doc);
  6498. var targets = TableTargets.pasteRows(selections, table, cell, clonedRows, generators);
  6499. execute(table, targets).each(function (rng) {
  6500. editor.selection.setRng(rng);
  6501. editor.focus();
  6502. cellSelection.clear(table);
  6503. });
  6504. });
  6505. });
  6506. });
  6507. };
  6508. each$3({
  6509. mceTableSplitCells: function () {
  6510. actOnSelection(actions.unmergeCells);
  6511. },
  6512. mceTableMergeCells: function () {
  6513. actOnSelection(actions.mergeCells);
  6514. },
  6515. mceTableInsertRowBefore: function () {
  6516. actOnSelection(actions.insertRowsBefore);
  6517. },
  6518. mceTableInsertRowAfter: function () {
  6519. actOnSelection(actions.insertRowsAfter);
  6520. },
  6521. mceTableInsertColBefore: function () {
  6522. actOnSelection(actions.insertColumnsBefore);
  6523. },
  6524. mceTableInsertColAfter: function () {
  6525. actOnSelection(actions.insertColumnsAfter);
  6526. },
  6527. mceTableDeleteCol: function () {
  6528. actOnSelection(actions.deleteColumn);
  6529. },
  6530. mceTableDeleteRow: function () {
  6531. actOnSelection(actions.deleteRow);
  6532. },
  6533. mceTableCutRow: function (grid) {
  6534. copyRowSelection().each(function (selection) {
  6535. clipboardRows.set(selection);
  6536. actOnSelection(actions.deleteRow);
  6537. });
  6538. },
  6539. mceTableCopyRow: function (grid) {
  6540. copyRowSelection().each(function (selection) {
  6541. clipboardRows.set(selection);
  6542. });
  6543. },
  6544. mceTablePasteRowBefore: function (grid) {
  6545. pasteOnSelection(actions.pasteRowsBefore);
  6546. },
  6547. mceTablePasteRowAfter: function (grid) {
  6548. pasteOnSelection(actions.pasteRowsAfter);
  6549. },
  6550. mceTableDelete: eraseTable
  6551. }, function (func, name) {
  6552. editor.addCommand(name, func);
  6553. });
  6554. each$3({
  6555. mceInsertTable: curry(TableDialog.open, editor, true),
  6556. mceTableProps: curry(TableDialog.open, editor, false),
  6557. mceTableRowProps: curry(RowDialog.open, editor),
  6558. mceTableCellProps: curry(CellDialog.open, editor)
  6559. }, function (func, name) {
  6560. editor.addCommand(name, function () {
  6561. func();
  6562. });
  6563. });
  6564. };
  6565. var Commands = { registerCommands: registerCommands };
  6566. var only$1 = function (element) {
  6567. var parent = Option.from(element.dom().documentElement).map(Element.fromDom).getOr(element);
  6568. return {
  6569. parent: constant(parent),
  6570. view: constant(element),
  6571. origin: constant(Position(0, 0))
  6572. };
  6573. };
  6574. var detached = function (editable, chrome) {
  6575. var origin = curry(absolute, chrome);
  6576. return {
  6577. parent: constant(chrome),
  6578. view: constant(editable),
  6579. origin: origin
  6580. };
  6581. };
  6582. var body$1 = function (editable, chrome) {
  6583. return {
  6584. parent: constant(chrome),
  6585. view: constant(editable),
  6586. origin: constant(Position(0, 0))
  6587. };
  6588. };
  6589. var ResizeWire = {
  6590. only: only$1,
  6591. detached: detached,
  6592. body: body$1
  6593. };
  6594. function Event (fields) {
  6595. var struct = Immutable.apply(null, fields);
  6596. var handlers = [];
  6597. var bind = function (handler) {
  6598. if (handler === undefined) {
  6599. throw 'Event bind error: undefined handler';
  6600. }
  6601. handlers.push(handler);
  6602. };
  6603. var unbind = function (handler) {
  6604. handlers = filter(handlers, function (h) {
  6605. return h !== handler;
  6606. });
  6607. };
  6608. var trigger = function () {
  6609. var event = struct.apply(null, arguments);
  6610. each(handlers, function (handler) {
  6611. handler(event);
  6612. });
  6613. };
  6614. return {
  6615. bind: bind,
  6616. unbind: unbind,
  6617. trigger: trigger
  6618. };
  6619. }
  6620. var create = function (typeDefs) {
  6621. var registry = map$1(typeDefs, function (event) {
  6622. return {
  6623. bind: event.bind,
  6624. unbind: event.unbind
  6625. };
  6626. });
  6627. var trigger = map$1(typeDefs, function (event) {
  6628. return event.trigger;
  6629. });
  6630. return {
  6631. registry: registry,
  6632. trigger: trigger
  6633. };
  6634. };
  6635. var Events = { create: create };
  6636. var mode = exactly([
  6637. 'compare',
  6638. 'extract',
  6639. 'mutate',
  6640. 'sink'
  6641. ]);
  6642. var sink = exactly([
  6643. 'element',
  6644. 'start',
  6645. 'stop',
  6646. 'destroy'
  6647. ]);
  6648. var api$3 = exactly([
  6649. 'forceDrop',
  6650. 'drop',
  6651. 'move',
  6652. 'delayDrop'
  6653. ]);
  6654. var DragApis = {
  6655. mode: mode,
  6656. sink: sink,
  6657. api: api$3
  6658. };
  6659. var styles$1 = css('ephox-dragster');
  6660. var Styles$2 = { resolve: styles$1.resolve };
  6661. function Blocker (options) {
  6662. var settings = merge({ 'layerClass': Styles$2.resolve('blocker') }, options);
  6663. var div = Element.fromTag('div');
  6664. set(div, 'role', 'presentation');
  6665. setAll$1(div, {
  6666. position: 'fixed',
  6667. left: '0px',
  6668. top: '0px',
  6669. width: '100%',
  6670. height: '100%'
  6671. });
  6672. add$2(div, Styles$2.resolve('blocker'));
  6673. add$2(div, settings.layerClass);
  6674. var element = function () {
  6675. return div;
  6676. };
  6677. var destroy = function () {
  6678. remove$2(div);
  6679. };
  6680. return {
  6681. element: element,
  6682. destroy: destroy
  6683. };
  6684. }
  6685. var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
  6686. return {
  6687. target: constant(target),
  6688. x: constant(x),
  6689. y: constant(y),
  6690. stop: stop,
  6691. prevent: prevent,
  6692. kill: kill,
  6693. raw: constant(raw)
  6694. };
  6695. };
  6696. var handle = function (filter, handler) {
  6697. return function (rawEvent) {
  6698. if (!filter(rawEvent)) {
  6699. return;
  6700. }
  6701. var target = Element.fromDom(rawEvent.target);
  6702. var stop = function () {
  6703. rawEvent.stopPropagation();
  6704. };
  6705. var prevent = function () {
  6706. rawEvent.preventDefault();
  6707. };
  6708. var kill = compose(prevent, stop);
  6709. var evt = mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
  6710. handler(evt);
  6711. };
  6712. };
  6713. var binder = function (element, event, filter, handler, useCapture) {
  6714. var wrapped = handle(filter, handler);
  6715. element.dom().addEventListener(event, wrapped, useCapture);
  6716. return { unbind: curry(unbind, element, event, wrapped, useCapture) };
  6717. };
  6718. var bind$1 = function (element, event, filter, handler) {
  6719. return binder(element, event, filter, handler, false);
  6720. };
  6721. var unbind = function (element, event, handler, useCapture) {
  6722. element.dom().removeEventListener(event, handler, useCapture);
  6723. };
  6724. var filter$1 = constant(true);
  6725. var bind$2 = function (element, event, handler) {
  6726. return bind$1(element, event, filter$1, handler);
  6727. };
  6728. var compare = function (old, nu) {
  6729. return Position(nu.left() - old.left(), nu.top() - old.top());
  6730. };
  6731. var extract$1 = function (event) {
  6732. return Option.some(Position(event.x(), event.y()));
  6733. };
  6734. var mutate = function (mutation, info) {
  6735. mutation.mutate(info.left(), info.top());
  6736. };
  6737. var sink$1 = function (dragApi, settings) {
  6738. var blocker = Blocker(settings);
  6739. var mdown = bind$2(blocker.element(), 'mousedown', dragApi.forceDrop);
  6740. var mup = bind$2(blocker.element(), 'mouseup', dragApi.drop);
  6741. var mmove = bind$2(blocker.element(), 'mousemove', dragApi.move);
  6742. var mout = bind$2(blocker.element(), 'mouseout', dragApi.delayDrop);
  6743. var destroy = function () {
  6744. blocker.destroy();
  6745. mup.unbind();
  6746. mmove.unbind();
  6747. mout.unbind();
  6748. mdown.unbind();
  6749. };
  6750. var start = function (parent) {
  6751. append(parent, blocker.element());
  6752. };
  6753. var stop = function () {
  6754. remove$2(blocker.element());
  6755. };
  6756. return DragApis.sink({
  6757. element: blocker.element,
  6758. start: start,
  6759. stop: stop,
  6760. destroy: destroy
  6761. });
  6762. };
  6763. var MouseDrag = DragApis.mode({
  6764. compare: compare,
  6765. extract: extract$1,
  6766. sink: sink$1,
  6767. mutate: mutate
  6768. });
  6769. function InDrag () {
  6770. var previous = Option.none();
  6771. var reset = function () {
  6772. previous = Option.none();
  6773. };
  6774. var update = function (mode, nu) {
  6775. var result = previous.map(function (old) {
  6776. return mode.compare(old, nu);
  6777. });
  6778. previous = Option.some(nu);
  6779. return result;
  6780. };
  6781. var onEvent = function (event, mode) {
  6782. var dataOption = mode.extract(event);
  6783. dataOption.each(function (data) {
  6784. var offset = update(mode, data);
  6785. offset.each(function (d) {
  6786. events.trigger.move(d);
  6787. });
  6788. });
  6789. };
  6790. var events = Events.create({ move: Event(['info']) });
  6791. return {
  6792. onEvent: onEvent,
  6793. reset: reset,
  6794. events: events.registry
  6795. };
  6796. }
  6797. function NoDrag (anchor) {
  6798. var onEvent = function (event, mode) {
  6799. };
  6800. return {
  6801. onEvent: onEvent,
  6802. reset: noop
  6803. };
  6804. }
  6805. function Movement () {
  6806. var noDragState = NoDrag();
  6807. var inDragState = InDrag();
  6808. var dragState = noDragState;
  6809. var on = function () {
  6810. dragState.reset();
  6811. dragState = inDragState;
  6812. };
  6813. var off = function () {
  6814. dragState.reset();
  6815. dragState = noDragState;
  6816. };
  6817. var onEvent = function (event, mode) {
  6818. dragState.onEvent(event, mode);
  6819. };
  6820. var isOn = function () {
  6821. return dragState === inDragState;
  6822. };
  6823. return {
  6824. on: on,
  6825. off: off,
  6826. isOn: isOn,
  6827. onEvent: onEvent,
  6828. events: inDragState.events
  6829. };
  6830. }
  6831. var last$2 = function (fn, rate) {
  6832. var timer = null;
  6833. var cancel = function () {
  6834. if (timer !== null) {
  6835. domGlobals.clearTimeout(timer);
  6836. timer = null;
  6837. }
  6838. };
  6839. var throttle = function () {
  6840. var args = [];
  6841. for (var _i = 0; _i < arguments.length; _i++) {
  6842. args[_i] = arguments[_i];
  6843. }
  6844. if (timer !== null)
  6845. domGlobals.clearTimeout(timer);
  6846. timer = domGlobals.setTimeout(function () {
  6847. fn.apply(null, args);
  6848. timer = null;
  6849. }, rate);
  6850. };
  6851. return {
  6852. cancel: cancel,
  6853. throttle: throttle
  6854. };
  6855. };
  6856. var setup = function (mutation, mode, settings) {
  6857. var active = false;
  6858. var events = Events.create({
  6859. start: Event([]),
  6860. stop: Event([])
  6861. });
  6862. var movement = Movement();
  6863. var drop = function () {
  6864. sink.stop();
  6865. if (movement.isOn()) {
  6866. movement.off();
  6867. events.trigger.stop();
  6868. }
  6869. };
  6870. var throttledDrop = last$2(drop, 200);
  6871. var go = function (parent) {
  6872. sink.start(parent);
  6873. movement.on();
  6874. events.trigger.start();
  6875. };
  6876. var mousemove = function (event, ui) {
  6877. throttledDrop.cancel();
  6878. movement.onEvent(event, mode);
  6879. };
  6880. movement.events.move.bind(function (event) {
  6881. mode.mutate(mutation, event.info());
  6882. });
  6883. var on = function () {
  6884. active = true;
  6885. };
  6886. var off = function () {
  6887. active = false;
  6888. };
  6889. var runIfActive = function (f) {
  6890. return function () {
  6891. var args = Array.prototype.slice.call(arguments, 0);
  6892. if (active) {
  6893. return f.apply(null, args);
  6894. }
  6895. };
  6896. };
  6897. var sink = mode.sink(DragApis.api({
  6898. forceDrop: drop,
  6899. drop: runIfActive(drop),
  6900. move: runIfActive(mousemove),
  6901. delayDrop: runIfActive(throttledDrop.throttle)
  6902. }), settings);
  6903. var destroy = function () {
  6904. sink.destroy();
  6905. };
  6906. return {
  6907. element: sink.element,
  6908. go: go,
  6909. on: on,
  6910. off: off,
  6911. destroy: destroy,
  6912. events: events.registry
  6913. };
  6914. };
  6915. var Dragging = { setup: setup };
  6916. var transform$1 = function (mutation, options) {
  6917. var settings = options !== undefined ? options : {};
  6918. var mode = settings.mode !== undefined ? settings.mode : MouseDrag;
  6919. return Dragging.setup(mutation, mode, options);
  6920. };
  6921. var Dragger = { transform: transform$1 };
  6922. function Mutation () {
  6923. var events = Events.create({
  6924. drag: Event([
  6925. 'xDelta',
  6926. 'yDelta'
  6927. ])
  6928. });
  6929. var mutate = function (x, y) {
  6930. events.trigger.drag(x, y);
  6931. };
  6932. return {
  6933. mutate: mutate,
  6934. events: events.registry
  6935. };
  6936. }
  6937. function BarMutation () {
  6938. var events = Events.create({
  6939. drag: Event([
  6940. 'xDelta',
  6941. 'yDelta',
  6942. 'target'
  6943. ])
  6944. });
  6945. var target = Option.none();
  6946. var delegate = Mutation();
  6947. delegate.events.drag.bind(function (event) {
  6948. target.each(function (t) {
  6949. events.trigger.drag(event.xDelta(), event.yDelta(), t);
  6950. });
  6951. });
  6952. var assign = function (t) {
  6953. target = Option.some(t);
  6954. };
  6955. var get = function () {
  6956. return target;
  6957. };
  6958. return {
  6959. assign: assign,
  6960. get: get,
  6961. mutate: delegate.mutate,
  6962. events: events.registry
  6963. };
  6964. }
  6965. var isContentEditableTrue = function (elm) {
  6966. return get$1(elm, 'contenteditable') === 'true';
  6967. };
  6968. var findClosestContentEditable = function (target, isRoot) {
  6969. return closest$1(target, '[contenteditable]', isRoot);
  6970. };
  6971. var resizeBarDragging = Styles.resolve('resizer-bar-dragging');
  6972. function BarManager (wire, direction, hdirection) {
  6973. var mutation = BarMutation();
  6974. var resizing = Dragger.transform(mutation, {});
  6975. var hoverTable = Option.none();
  6976. var getResizer = function (element, type) {
  6977. return Option.from(get$1(element, type));
  6978. };
  6979. mutation.events.drag.bind(function (event) {
  6980. getResizer(event.target(), 'data-row').each(function (_dataRow) {
  6981. var currentRow = CellUtils.getInt(event.target(), 'top');
  6982. set$1(event.target(), 'top', currentRow + event.yDelta() + 'px');
  6983. });
  6984. getResizer(event.target(), 'data-column').each(function (_dataCol) {
  6985. var currentCol = CellUtils.getInt(event.target(), 'left');
  6986. set$1(event.target(), 'left', currentCol + event.xDelta() + 'px');
  6987. });
  6988. });
  6989. var getDelta = function (target, dir) {
  6990. var newX = CellUtils.getInt(target, dir);
  6991. var oldX = parseInt(get$1(target, 'data-initial-' + dir), 10);
  6992. return newX - oldX;
  6993. };
  6994. resizing.events.stop.bind(function () {
  6995. mutation.get().each(function (target) {
  6996. hoverTable.each(function (table) {
  6997. getResizer(target, 'data-row').each(function (row) {
  6998. var delta = getDelta(target, 'top');
  6999. remove(target, 'data-initial-top');
  7000. events.trigger.adjustHeight(table, delta, parseInt(row, 10));
  7001. });
  7002. getResizer(target, 'data-column').each(function (column) {
  7003. var delta = getDelta(target, 'left');
  7004. remove(target, 'data-initial-left');
  7005. events.trigger.adjustWidth(table, delta, parseInt(column, 10));
  7006. });
  7007. Bars.refresh(wire, table, hdirection, direction);
  7008. });
  7009. });
  7010. });
  7011. var handler = function (target, dir) {
  7012. events.trigger.startAdjust();
  7013. mutation.assign(target);
  7014. set(target, 'data-initial-' + dir, parseInt(get$2(target, dir), 10));
  7015. add$2(target, resizeBarDragging);
  7016. set$1(target, 'opacity', '0.2');
  7017. resizing.go(wire.parent());
  7018. };
  7019. var mousedown = bind$2(wire.parent(), 'mousedown', function (event) {
  7020. if (Bars.isRowBar(event.target())) {
  7021. handler(event.target(), 'top');
  7022. }
  7023. if (Bars.isColBar(event.target())) {
  7024. handler(event.target(), 'left');
  7025. }
  7026. });
  7027. var isRoot = function (e) {
  7028. return eq(e, wire.view());
  7029. };
  7030. var findClosestEditableTable = function (target) {
  7031. return closest$1(target, 'table', isRoot).filter(function (table) {
  7032. return findClosestContentEditable(table, isRoot).exists(isContentEditableTrue);
  7033. });
  7034. };
  7035. var mouseover = bind$2(wire.view(), 'mouseover', function (event) {
  7036. findClosestEditableTable(event.target()).fold(function () {
  7037. if (inBody(event.target())) {
  7038. Bars.destroy(wire);
  7039. }
  7040. }, function (table) {
  7041. hoverTable = Option.some(table);
  7042. Bars.refresh(wire, table, hdirection, direction);
  7043. });
  7044. });
  7045. var destroy = function () {
  7046. mousedown.unbind();
  7047. mouseover.unbind();
  7048. resizing.destroy();
  7049. Bars.destroy(wire);
  7050. };
  7051. var refresh = function (tbl) {
  7052. Bars.refresh(wire, tbl, hdirection, direction);
  7053. };
  7054. var events = Events.create({
  7055. adjustHeight: Event([
  7056. 'table',
  7057. 'delta',
  7058. 'row'
  7059. ]),
  7060. adjustWidth: Event([
  7061. 'table',
  7062. 'delta',
  7063. 'column'
  7064. ]),
  7065. startAdjust: Event([])
  7066. });
  7067. return {
  7068. destroy: destroy,
  7069. refresh: refresh,
  7070. on: resizing.on,
  7071. off: resizing.off,
  7072. hideBars: curry(Bars.hide, wire),
  7073. showBars: curry(Bars.show, wire),
  7074. events: events.registry
  7075. };
  7076. }
  7077. function TableResize (wire, vdirection) {
  7078. var hdirection = BarPositions.height;
  7079. var manager = BarManager(wire, vdirection, hdirection);
  7080. var events = Events.create({
  7081. beforeResize: Event(['table']),
  7082. afterResize: Event(['table']),
  7083. startDrag: Event([])
  7084. });
  7085. manager.events.adjustHeight.bind(function (event) {
  7086. events.trigger.beforeResize(event.table());
  7087. var delta = hdirection.delta(event.delta());
  7088. Adjustments.adjustHeight(event.table(), delta, event.row(), hdirection);
  7089. events.trigger.afterResize(event.table());
  7090. });
  7091. manager.events.startAdjust.bind(function (event) {
  7092. events.trigger.startDrag();
  7093. });
  7094. manager.events.adjustWidth.bind(function (event) {
  7095. events.trigger.beforeResize(event.table());
  7096. var delta = vdirection.delta(event.delta(), event.table());
  7097. Adjustments.adjustWidth(event.table(), delta, event.column(), vdirection);
  7098. events.trigger.afterResize(event.table());
  7099. });
  7100. return {
  7101. on: manager.on,
  7102. off: manager.off,
  7103. hideBars: manager.hideBars,
  7104. showBars: manager.showBars,
  7105. destroy: manager.destroy,
  7106. events: events.registry
  7107. };
  7108. }
  7109. var createContainer = function () {
  7110. var container = Element.fromTag('div');
  7111. setAll$1(container, {
  7112. position: 'static',
  7113. height: '0',
  7114. width: '0',
  7115. padding: '0',
  7116. margin: '0',
  7117. border: '0'
  7118. });
  7119. append(body(), container);
  7120. return container;
  7121. };
  7122. var get$9 = function (editor, container) {
  7123. return editor.inline ? ResizeWire.body(getBody$1(editor), createContainer()) : ResizeWire.only(Element.fromDom(editor.getDoc()));
  7124. };
  7125. var remove$6 = function (editor, wire) {
  7126. if (editor.inline) {
  7127. remove$2(wire.parent());
  7128. }
  7129. };
  7130. var TableWire = {
  7131. get: get$9,
  7132. remove: remove$6
  7133. };
  7134. var ResizeHandler = function (editor) {
  7135. var selectionRng = Option.none();
  7136. var resize = Option.none();
  7137. var wire = Option.none();
  7138. var percentageBasedSizeRegex = /(\d+(\.\d+)?)%/;
  7139. var startW, startRawW;
  7140. var isTable = function (elm) {
  7141. return elm.nodeName === 'TABLE';
  7142. };
  7143. var getRawWidth = function (elm) {
  7144. return editor.dom.getStyle(elm, 'width') || editor.dom.getAttrib(elm, 'width');
  7145. };
  7146. var lazyResize = function () {
  7147. return resize;
  7148. };
  7149. var lazyWire = function () {
  7150. return wire.getOr(ResizeWire.only(Element.fromDom(editor.getBody())));
  7151. };
  7152. var destroy = function () {
  7153. resize.each(function (sz) {
  7154. sz.destroy();
  7155. });
  7156. wire.each(function (w) {
  7157. TableWire.remove(editor, w);
  7158. });
  7159. };
  7160. editor.on('init', function () {
  7161. var direction = TableDirection(Direction.directionAt);
  7162. var rawWire = TableWire.get(editor);
  7163. wire = Option.some(rawWire);
  7164. if (hasObjectResizing(editor) && hasTableResizeBars(editor)) {
  7165. var sz = TableResize(rawWire, direction);
  7166. sz.on();
  7167. sz.events.startDrag.bind(function (event) {
  7168. selectionRng = Option.some(editor.selection.getRng());
  7169. });
  7170. sz.events.beforeResize.bind(function (event) {
  7171. var rawTable = event.table().dom();
  7172. fireObjectResizeStart(editor, rawTable, getPixelWidth$1(rawTable), getPixelHeight(rawTable));
  7173. });
  7174. sz.events.afterResize.bind(function (event) {
  7175. var table = event.table();
  7176. var rawTable = table.dom();
  7177. removeDataStyle(table);
  7178. selectionRng.each(function (rng) {
  7179. editor.selection.setRng(rng);
  7180. editor.focus();
  7181. });
  7182. fireObjectResized(editor, rawTable, getPixelWidth$1(rawTable), getPixelHeight(rawTable));
  7183. editor.undoManager.add();
  7184. });
  7185. resize = Option.some(sz);
  7186. }
  7187. });
  7188. editor.on('ObjectResizeStart', function (e) {
  7189. var targetElm = e.target;
  7190. if (isTable(targetElm)) {
  7191. startW = e.width;
  7192. startRawW = getRawWidth(targetElm);
  7193. }
  7194. });
  7195. editor.on('ObjectResized', function (e) {
  7196. var targetElm = e.target;
  7197. if (isTable(targetElm)) {
  7198. var table = targetElm;
  7199. if (percentageBasedSizeRegex.test(startRawW)) {
  7200. var percentW = parseFloat(percentageBasedSizeRegex.exec(startRawW)[1]);
  7201. var targetPercentW = e.width * percentW / startW;
  7202. editor.dom.setStyle(table, 'width', targetPercentW + '%');
  7203. } else {
  7204. var newCellSizes_1 = [];
  7205. global$1.each(table.rows, function (row) {
  7206. global$1.each(row.cells, function (cell) {
  7207. var width = editor.dom.getStyle(cell, 'width', true);
  7208. newCellSizes_1.push({
  7209. cell: cell,
  7210. width: width
  7211. });
  7212. });
  7213. });
  7214. global$1.each(newCellSizes_1, function (newCellSize) {
  7215. editor.dom.setStyle(newCellSize.cell, 'width', newCellSize.width);
  7216. editor.dom.setAttrib(newCellSize.cell, 'width', null);
  7217. });
  7218. }
  7219. }
  7220. });
  7221. editor.on('SwitchMode', function () {
  7222. lazyResize().each(function (resize) {
  7223. if (editor.readonly) {
  7224. resize.hideBars();
  7225. } else {
  7226. resize.showBars();
  7227. }
  7228. });
  7229. });
  7230. return {
  7231. lazyResize: lazyResize,
  7232. lazyWire: lazyWire,
  7233. destroy: destroy
  7234. };
  7235. };
  7236. var folder$1 = function (fold) {
  7237. return { fold: fold };
  7238. };
  7239. var none$2 = function (current) {
  7240. return folder$1(function (n, f, m, l) {
  7241. return n(current);
  7242. });
  7243. };
  7244. var first$2 = function (current) {
  7245. return folder$1(function (n, f, m, l) {
  7246. return f(current);
  7247. });
  7248. };
  7249. var middle$1 = function (current, target) {
  7250. return folder$1(function (n, f, m, l) {
  7251. return m(current, target);
  7252. });
  7253. };
  7254. var last$3 = function (current) {
  7255. return folder$1(function (n, f, m, l) {
  7256. return l(current);
  7257. });
  7258. };
  7259. var CellLocation = {
  7260. none: none$2,
  7261. first: first$2,
  7262. middle: middle$1,
  7263. last: last$3
  7264. };
  7265. var detect$4 = function (current, isRoot) {
  7266. return TableLookup.table(current, isRoot).bind(function (table) {
  7267. var all = TableLookup.cells(table);
  7268. var index = findIndex(all, function (x) {
  7269. return eq(current, x);
  7270. });
  7271. return index.map(function (ind) {
  7272. return {
  7273. index: constant(ind),
  7274. all: constant(all)
  7275. };
  7276. });
  7277. });
  7278. };
  7279. var next = function (current, isRoot) {
  7280. var detection = detect$4(current, isRoot);
  7281. return detection.fold(function () {
  7282. return CellLocation.none(current);
  7283. }, function (info) {
  7284. return info.index() + 1 < info.all().length ? CellLocation.middle(current, info.all()[info.index() + 1]) : CellLocation.last(current);
  7285. });
  7286. };
  7287. var prev = function (current, isRoot) {
  7288. var detection = detect$4(current, isRoot);
  7289. return detection.fold(function () {
  7290. return CellLocation.none();
  7291. }, function (info) {
  7292. return info.index() - 1 >= 0 ? CellLocation.middle(current, info.all()[info.index() - 1]) : CellLocation.first(current);
  7293. });
  7294. };
  7295. var CellNavigation = {
  7296. next: next,
  7297. prev: prev
  7298. };
  7299. var adt = Adt.generate([
  7300. { before: ['element'] },
  7301. {
  7302. on: [
  7303. 'element',
  7304. 'offset'
  7305. ]
  7306. },
  7307. { after: ['element'] }
  7308. ]);
  7309. var cata$1 = function (subject, onBefore, onOn, onAfter) {
  7310. return subject.fold(onBefore, onOn, onAfter);
  7311. };
  7312. var getStart = function (situ) {
  7313. return situ.fold(identity, identity, identity);
  7314. };
  7315. var before$2 = adt.before;
  7316. var on = adt.on;
  7317. var after$2 = adt.after;
  7318. var Situ = {
  7319. before: before$2,
  7320. on: on,
  7321. after: after$2,
  7322. cata: cata$1,
  7323. getStart: getStart
  7324. };
  7325. var type$2 = Adt.generate([
  7326. { domRange: ['rng'] },
  7327. {
  7328. relative: [
  7329. 'startSitu',
  7330. 'finishSitu'
  7331. ]
  7332. },
  7333. {
  7334. exact: [
  7335. 'start',
  7336. 'soffset',
  7337. 'finish',
  7338. 'foffset'
  7339. ]
  7340. }
  7341. ]);
  7342. var range$2 = Immutable('start', 'soffset', 'finish', 'foffset');
  7343. var getStart$1 = function (selection) {
  7344. return selection.match({
  7345. domRange: function (rng) {
  7346. return Element.fromDom(rng.startContainer);
  7347. },
  7348. relative: function (startSitu, finishSitu) {
  7349. return Situ.getStart(startSitu);
  7350. },
  7351. exact: function (start, soffset, finish, foffset) {
  7352. return start;
  7353. }
  7354. });
  7355. };
  7356. var getWin = function (selection) {
  7357. var start = getStart$1(selection);
  7358. return defaultView(start);
  7359. };
  7360. var relative = type$2.relative;
  7361. var exact = type$2.exact;
  7362. var makeRange = function (start, soffset, finish, foffset) {
  7363. var doc = owner(start);
  7364. var rng = doc.dom().createRange();
  7365. rng.setStart(start.dom(), soffset);
  7366. rng.setEnd(finish.dom(), foffset);
  7367. return rng;
  7368. };
  7369. var after$3 = function (start, soffset, finish, foffset) {
  7370. var r = makeRange(start, soffset, finish, foffset);
  7371. var same = eq(start, finish) && soffset === foffset;
  7372. return r.collapsed && !same;
  7373. };
  7374. var selectNodeContents = function (win, element) {
  7375. var rng = win.document.createRange();
  7376. selectNodeContentsUsing(rng, element);
  7377. return rng;
  7378. };
  7379. var selectNodeContentsUsing = function (rng, element) {
  7380. rng.selectNodeContents(element.dom());
  7381. };
  7382. var setStart = function (rng, situ) {
  7383. situ.fold(function (e) {
  7384. rng.setStartBefore(e.dom());
  7385. }, function (e, o) {
  7386. rng.setStart(e.dom(), o);
  7387. }, function (e) {
  7388. rng.setStartAfter(e.dom());
  7389. });
  7390. };
  7391. var setFinish = function (rng, situ) {
  7392. situ.fold(function (e) {
  7393. rng.setEndBefore(e.dom());
  7394. }, function (e, o) {
  7395. rng.setEnd(e.dom(), o);
  7396. }, function (e) {
  7397. rng.setEndAfter(e.dom());
  7398. });
  7399. };
  7400. var relativeToNative = function (win, startSitu, finishSitu) {
  7401. var range = win.document.createRange();
  7402. setStart(range, startSitu);
  7403. setFinish(range, finishSitu);
  7404. return range;
  7405. };
  7406. var exactToNative = function (win, start, soffset, finish, foffset) {
  7407. var rng = win.document.createRange();
  7408. rng.setStart(start.dom(), soffset);
  7409. rng.setEnd(finish.dom(), foffset);
  7410. return rng;
  7411. };
  7412. var toRect = function (rect) {
  7413. return {
  7414. left: constant(rect.left),
  7415. top: constant(rect.top),
  7416. right: constant(rect.right),
  7417. bottom: constant(rect.bottom),
  7418. width: constant(rect.width),
  7419. height: constant(rect.height)
  7420. };
  7421. };
  7422. var getFirstRect = function (rng) {
  7423. var rects = rng.getClientRects();
  7424. var rect = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
  7425. return rect.width > 0 || rect.height > 0 ? Option.some(rect).map(toRect) : Option.none();
  7426. };
  7427. var adt$1 = Adt.generate([
  7428. {
  7429. ltr: [
  7430. 'start',
  7431. 'soffset',
  7432. 'finish',
  7433. 'foffset'
  7434. ]
  7435. },
  7436. {
  7437. rtl: [
  7438. 'start',
  7439. 'soffset',
  7440. 'finish',
  7441. 'foffset'
  7442. ]
  7443. }
  7444. ]);
  7445. var fromRange = function (win, type, range) {
  7446. return type(Element.fromDom(range.startContainer), range.startOffset, Element.fromDom(range.endContainer), range.endOffset);
  7447. };
  7448. var getRanges = function (win, selection) {
  7449. return selection.match({
  7450. domRange: function (rng) {
  7451. return {
  7452. ltr: constant(rng),
  7453. rtl: Option.none
  7454. };
  7455. },
  7456. relative: function (startSitu, finishSitu) {
  7457. return {
  7458. ltr: cached(function () {
  7459. return relativeToNative(win, startSitu, finishSitu);
  7460. }),
  7461. rtl: cached(function () {
  7462. return Option.some(relativeToNative(win, finishSitu, startSitu));
  7463. })
  7464. };
  7465. },
  7466. exact: function (start, soffset, finish, foffset) {
  7467. return {
  7468. ltr: cached(function () {
  7469. return exactToNative(win, start, soffset, finish, foffset);
  7470. }),
  7471. rtl: cached(function () {
  7472. return Option.some(exactToNative(win, finish, foffset, start, soffset));
  7473. })
  7474. };
  7475. }
  7476. });
  7477. };
  7478. var doDiagnose = function (win, ranges) {
  7479. var rng = ranges.ltr();
  7480. if (rng.collapsed) {
  7481. var reversed = ranges.rtl().filter(function (rev) {
  7482. return rev.collapsed === false;
  7483. });
  7484. return reversed.map(function (rev) {
  7485. return adt$1.rtl(Element.fromDom(rev.endContainer), rev.endOffset, Element.fromDom(rev.startContainer), rev.startOffset);
  7486. }).getOrThunk(function () {
  7487. return fromRange(win, adt$1.ltr, rng);
  7488. });
  7489. } else {
  7490. return fromRange(win, adt$1.ltr, rng);
  7491. }
  7492. };
  7493. var diagnose = function (win, selection) {
  7494. var ranges = getRanges(win, selection);
  7495. return doDiagnose(win, ranges);
  7496. };
  7497. var asLtrRange = function (win, selection) {
  7498. var diagnosis = diagnose(win, selection);
  7499. return diagnosis.match({
  7500. ltr: function (start, soffset, finish, foffset) {
  7501. var rng = win.document.createRange();
  7502. rng.setStart(start.dom(), soffset);
  7503. rng.setEnd(finish.dom(), foffset);
  7504. return rng;
  7505. },
  7506. rtl: function (start, soffset, finish, foffset) {
  7507. var rng = win.document.createRange();
  7508. rng.setStart(finish.dom(), foffset);
  7509. rng.setEnd(start.dom(), soffset);
  7510. return rng;
  7511. }
  7512. });
  7513. };
  7514. var searchForPoint = function (rectForOffset, x, y, maxX, length) {
  7515. if (length === 0) {
  7516. return 0;
  7517. } else if (x === maxX) {
  7518. return length - 1;
  7519. }
  7520. var xDelta = maxX;
  7521. for (var i = 1; i < length; i++) {
  7522. var rect = rectForOffset(i);
  7523. var curDeltaX = Math.abs(x - rect.left);
  7524. if (y <= rect.bottom) {
  7525. if (y < rect.top || curDeltaX > xDelta) {
  7526. return i - 1;
  7527. } else {
  7528. xDelta = curDeltaX;
  7529. }
  7530. }
  7531. }
  7532. return 0;
  7533. };
  7534. var inRect = function (rect, x, y) {
  7535. return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
  7536. };
  7537. var locateOffset = function (doc, textnode, x, y, rect) {
  7538. var rangeForOffset = function (o) {
  7539. var r = doc.dom().createRange();
  7540. r.setStart(textnode.dom(), o);
  7541. r.collapse(true);
  7542. return r;
  7543. };
  7544. var rectForOffset = function (o) {
  7545. var r = rangeForOffset(o);
  7546. return r.getBoundingClientRect();
  7547. };
  7548. var length = get$3(textnode).length;
  7549. var offset = searchForPoint(rectForOffset, x, y, rect.right, length);
  7550. return rangeForOffset(offset);
  7551. };
  7552. var locate = function (doc, node, x, y) {
  7553. var r = doc.dom().createRange();
  7554. r.selectNode(node.dom());
  7555. var rects = r.getClientRects();
  7556. var foundRect = findMap(rects, function (rect) {
  7557. return inRect(rect, x, y) ? Option.some(rect) : Option.none();
  7558. });
  7559. return foundRect.map(function (rect) {
  7560. return locateOffset(doc, node, x, y, rect);
  7561. });
  7562. };
  7563. var TextPoint = /*#__PURE__*/Object.freeze({
  7564. locate: locate
  7565. });
  7566. var searchInChildren = function (doc, node, x, y) {
  7567. var r = doc.dom().createRange();
  7568. var nodes = children(node);
  7569. return findMap(nodes, function (n) {
  7570. r.selectNode(n.dom());
  7571. return inRect(r.getBoundingClientRect(), x, y) ? locateNode(doc, n, x, y) : Option.none();
  7572. });
  7573. };
  7574. var locateNode = function (doc, node, x, y) {
  7575. var locator = isText(node) ? locate : searchInChildren;
  7576. return locator(doc, node, x, y);
  7577. };
  7578. var locate$1 = function (doc, node, x, y) {
  7579. var r = doc.dom().createRange();
  7580. r.selectNode(node.dom());
  7581. var rect = r.getBoundingClientRect();
  7582. var boundedX = Math.max(rect.left, Math.min(rect.right, x));
  7583. var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
  7584. return locateNode(doc, node, boundedX, boundedY);
  7585. };
  7586. var COLLAPSE_TO_LEFT = true;
  7587. var COLLAPSE_TO_RIGHT = false;
  7588. var getCollapseDirection = function (rect, x) {
  7589. return x - rect.left < rect.right - x ? COLLAPSE_TO_LEFT : COLLAPSE_TO_RIGHT;
  7590. };
  7591. var createCollapsedNode = function (doc, target, collapseDirection) {
  7592. var r = doc.dom().createRange();
  7593. r.selectNode(target.dom());
  7594. r.collapse(collapseDirection);
  7595. return r;
  7596. };
  7597. var locateInElement = function (doc, node, x) {
  7598. var cursorRange = doc.dom().createRange();
  7599. cursorRange.selectNode(node.dom());
  7600. var rect = cursorRange.getBoundingClientRect();
  7601. var collapseDirection = getCollapseDirection(rect, x);
  7602. var f = collapseDirection === COLLAPSE_TO_LEFT ? first$1 : last$1;
  7603. return f(node).map(function (target) {
  7604. return createCollapsedNode(doc, target, collapseDirection);
  7605. });
  7606. };
  7607. var locateInEmpty = function (doc, node, x) {
  7608. var rect = node.dom().getBoundingClientRect();
  7609. var collapseDirection = getCollapseDirection(rect, x);
  7610. return Option.some(createCollapsedNode(doc, node, collapseDirection));
  7611. };
  7612. var search = function (doc, node, x) {
  7613. var f = children(node).length === 0 ? locateInEmpty : locateInElement;
  7614. return f(doc, node, x);
  7615. };
  7616. var caretPositionFromPoint = function (doc, x, y) {
  7617. return Option.from(doc.dom().caretPositionFromPoint(x, y)).bind(function (pos) {
  7618. if (pos.offsetNode === null) {
  7619. return Option.none();
  7620. }
  7621. var r = doc.dom().createRange();
  7622. r.setStart(pos.offsetNode, pos.offset);
  7623. r.collapse();
  7624. return Option.some(r);
  7625. });
  7626. };
  7627. var caretRangeFromPoint = function (doc, x, y) {
  7628. return Option.from(doc.dom().caretRangeFromPoint(x, y));
  7629. };
  7630. var searchTextNodes = function (doc, node, x, y) {
  7631. var r = doc.dom().createRange();
  7632. r.selectNode(node.dom());
  7633. var rect = r.getBoundingClientRect();
  7634. var boundedX = Math.max(rect.left, Math.min(rect.right, x));
  7635. var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
  7636. return locate$1(doc, node, boundedX, boundedY);
  7637. };
  7638. var searchFromPoint = function (doc, x, y) {
  7639. return Element.fromPoint(doc, x, y).bind(function (elem) {
  7640. var fallback = function () {
  7641. return search(doc, elem, x);
  7642. };
  7643. return children(elem).length === 0 ? fallback() : searchTextNodes(doc, elem, x, y).orThunk(fallback);
  7644. });
  7645. };
  7646. var availableSearch = document.caretPositionFromPoint ? caretPositionFromPoint : document.caretRangeFromPoint ? caretRangeFromPoint : searchFromPoint;
  7647. var fromPoint$1 = function (win, x, y) {
  7648. var doc = Element.fromDom(win.document);
  7649. return availableSearch(doc, x, y).map(function (rng) {
  7650. return range$2(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset);
  7651. });
  7652. };
  7653. var beforeSpecial = function (element, offset) {
  7654. var name$1 = name(element);
  7655. if ('input' === name$1) {
  7656. return Situ.after(element);
  7657. } else if (!contains([
  7658. 'br',
  7659. 'img'
  7660. ], name$1)) {
  7661. return Situ.on(element, offset);
  7662. } else {
  7663. return offset === 0 ? Situ.before(element) : Situ.after(element);
  7664. }
  7665. };
  7666. var preprocessRelative = function (startSitu, finishSitu) {
  7667. var start = startSitu.fold(Situ.before, beforeSpecial, Situ.after);
  7668. var finish = finishSitu.fold(Situ.before, beforeSpecial, Situ.after);
  7669. return relative(start, finish);
  7670. };
  7671. var preprocessExact = function (start, soffset, finish, foffset) {
  7672. var startSitu = beforeSpecial(start, soffset);
  7673. var finishSitu = beforeSpecial(finish, foffset);
  7674. return relative(startSitu, finishSitu);
  7675. };
  7676. var preprocess = function (selection) {
  7677. return selection.match({
  7678. domRange: function (rng) {
  7679. var start = Element.fromDom(rng.startContainer);
  7680. var finish = Element.fromDom(rng.endContainer);
  7681. return preprocessExact(start, rng.startOffset, finish, rng.endOffset);
  7682. },
  7683. relative: preprocessRelative,
  7684. exact: preprocessExact
  7685. });
  7686. };
  7687. var doSetNativeRange = function (win, rng) {
  7688. Option.from(win.getSelection()).each(function (selection) {
  7689. selection.removeAllRanges();
  7690. selection.addRange(rng);
  7691. });
  7692. };
  7693. var doSetRange = function (win, start, soffset, finish, foffset) {
  7694. var rng = exactToNative(win, start, soffset, finish, foffset);
  7695. doSetNativeRange(win, rng);
  7696. };
  7697. var setLegacyRtlRange = function (win, selection, start, soffset, finish, foffset) {
  7698. selection.collapse(start.dom(), soffset);
  7699. selection.extend(finish.dom(), foffset);
  7700. };
  7701. var setRangeFromRelative = function (win, relative) {
  7702. return diagnose(win, relative).match({
  7703. ltr: function (start, soffset, finish, foffset) {
  7704. doSetRange(win, start, soffset, finish, foffset);
  7705. },
  7706. rtl: function (start, soffset, finish, foffset) {
  7707. var selection = win.getSelection();
  7708. if (selection.setBaseAndExtent) {
  7709. selection.setBaseAndExtent(start.dom(), soffset, finish.dom(), foffset);
  7710. } else if (selection.extend) {
  7711. try {
  7712. setLegacyRtlRange(win, selection, start, soffset, finish, foffset);
  7713. } catch (e) {
  7714. doSetRange(win, finish, foffset, start, soffset);
  7715. }
  7716. } else {
  7717. doSetRange(win, finish, foffset, start, soffset);
  7718. }
  7719. }
  7720. });
  7721. };
  7722. var setExact = function (win, start, soffset, finish, foffset) {
  7723. var relative = preprocessExact(start, soffset, finish, foffset);
  7724. setRangeFromRelative(win, relative);
  7725. };
  7726. var setRelative = function (win, startSitu, finishSitu) {
  7727. var relative = preprocessRelative(startSitu, finishSitu);
  7728. setRangeFromRelative(win, relative);
  7729. };
  7730. var toNative = function (selection) {
  7731. var win = getWin(selection).dom();
  7732. var getDomRange = function (start, soffset, finish, foffset) {
  7733. return exactToNative(win, start, soffset, finish, foffset);
  7734. };
  7735. var filtered = preprocess(selection);
  7736. return diagnose(win, filtered).match({
  7737. ltr: getDomRange,
  7738. rtl: getDomRange
  7739. });
  7740. };
  7741. var readRange = function (selection) {
  7742. if (selection.rangeCount > 0) {
  7743. var firstRng = selection.getRangeAt(0);
  7744. var lastRng = selection.getRangeAt(selection.rangeCount - 1);
  7745. return Option.some(range$2(Element.fromDom(firstRng.startContainer), firstRng.startOffset, Element.fromDom(lastRng.endContainer), lastRng.endOffset));
  7746. } else {
  7747. return Option.none();
  7748. }
  7749. };
  7750. var doGetExact = function (selection) {
  7751. var anchor = Element.fromDom(selection.anchorNode);
  7752. var focus = Element.fromDom(selection.focusNode);
  7753. return after$3(anchor, selection.anchorOffset, focus, selection.focusOffset) ? Option.some(range$2(anchor, selection.anchorOffset, focus, selection.focusOffset)) : readRange(selection);
  7754. };
  7755. var setToElement = function (win, element) {
  7756. var rng = selectNodeContents(win, element);
  7757. doSetNativeRange(win, rng);
  7758. };
  7759. var getExact = function (win) {
  7760. return Option.from(win.getSelection()).filter(function (sel) {
  7761. return sel.rangeCount > 0;
  7762. }).bind(doGetExact);
  7763. };
  7764. var get$a = function (win) {
  7765. return getExact(win).map(function (range) {
  7766. return exact(range.start(), range.soffset(), range.finish(), range.foffset());
  7767. });
  7768. };
  7769. var getFirstRect$1 = function (win, selection) {
  7770. var rng = asLtrRange(win, selection);
  7771. return getFirstRect(rng);
  7772. };
  7773. var getAtPoint = function (win, x, y) {
  7774. return fromPoint$1(win, x, y);
  7775. };
  7776. var clear$1 = function (win) {
  7777. var selection = win.getSelection();
  7778. selection.removeAllRanges();
  7779. };
  7780. var global$3 = tinymce.util.Tools.resolve('tinymce.util.VK');
  7781. var forward = function (editor, isRoot, cell, lazyWire) {
  7782. return go(editor, isRoot, CellNavigation.next(cell), lazyWire);
  7783. };
  7784. var backward = function (editor, isRoot, cell, lazyWire) {
  7785. return go(editor, isRoot, CellNavigation.prev(cell), lazyWire);
  7786. };
  7787. var getCellFirstCursorPosition = function (editor, cell) {
  7788. var selection = exact(cell, 0, cell, 0);
  7789. return toNative(selection);
  7790. };
  7791. var getNewRowCursorPosition = function (editor, table) {
  7792. var rows = descendants$1(table, 'tr');
  7793. return last(rows).bind(function (last) {
  7794. return descendant$1(last, 'td,th').map(function (first) {
  7795. return getCellFirstCursorPosition(editor, first);
  7796. });
  7797. });
  7798. };
  7799. var go = function (editor, isRoot, cell, actions, lazyWire) {
  7800. return cell.fold(Option.none, Option.none, function (current, next) {
  7801. return first$1(next).map(function (cell) {
  7802. return getCellFirstCursorPosition(editor, cell);
  7803. });
  7804. }, function (current) {
  7805. return TableLookup.table(current, isRoot).bind(function (table) {
  7806. var targets = TableTargets.noMenu(current);
  7807. editor.undoManager.transact(function () {
  7808. actions.insertRowsAfter(table, targets);
  7809. });
  7810. return getNewRowCursorPosition(editor, table);
  7811. });
  7812. });
  7813. };
  7814. var rootElements = [
  7815. 'table',
  7816. 'li',
  7817. 'dl'
  7818. ];
  7819. var handle$1 = function (event, editor, actions, lazyWire) {
  7820. if (event.keyCode === global$3.TAB) {
  7821. var body_1 = getBody$1(editor);
  7822. var isRoot_1 = function (element) {
  7823. var name$1 = name(element);
  7824. return eq(element, body_1) || contains(rootElements, name$1);
  7825. };
  7826. var rng = editor.selection.getRng();
  7827. if (rng.collapsed) {
  7828. var start = Element.fromDom(rng.startContainer);
  7829. TableLookup.cell(start, isRoot_1).each(function (cell) {
  7830. event.preventDefault();
  7831. var navigation = event.shiftKey ? backward : forward;
  7832. var rng = navigation(editor, isRoot_1, cell, actions, lazyWire);
  7833. rng.each(function (range) {
  7834. editor.selection.setRng(range);
  7835. });
  7836. });
  7837. }
  7838. }
  7839. };
  7840. var TabContext = { handle: handle$1 };
  7841. var response = Immutable('selection', 'kill');
  7842. var Responses = { response: response };
  7843. var isKey = function (key) {
  7844. return function (keycode) {
  7845. return keycode === key;
  7846. };
  7847. };
  7848. var isUp = isKey(38);
  7849. var isDown = isKey(40);
  7850. var isNavigation = function (keycode) {
  7851. return keycode >= 37 && keycode <= 40;
  7852. };
  7853. var SelectionKeys = {
  7854. ltr: {
  7855. isBackward: isKey(37),
  7856. isForward: isKey(39)
  7857. },
  7858. rtl: {
  7859. isBackward: isKey(39),
  7860. isForward: isKey(37)
  7861. },
  7862. isUp: isUp,
  7863. isDown: isDown,
  7864. isNavigation: isNavigation
  7865. };
  7866. var convertToRange = function (win, selection) {
  7867. var rng = asLtrRange(win, selection);
  7868. return {
  7869. start: constant(Element.fromDom(rng.startContainer)),
  7870. soffset: constant(rng.startOffset),
  7871. finish: constant(Element.fromDom(rng.endContainer)),
  7872. foffset: constant(rng.endOffset)
  7873. };
  7874. };
  7875. var makeSitus = function (start, soffset, finish, foffset) {
  7876. return {
  7877. start: constant(Situ.on(start, soffset)),
  7878. finish: constant(Situ.on(finish, foffset))
  7879. };
  7880. };
  7881. var Util$1 = {
  7882. convertToRange: convertToRange,
  7883. makeSitus: makeSitus
  7884. };
  7885. var isSafari = PlatformDetection$1.detect().browser.isSafari();
  7886. var get$b = function (_DOC) {
  7887. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  7888. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  7889. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  7890. return Position(x, y);
  7891. };
  7892. var by = function (x, y, _DOC) {
  7893. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  7894. var win = doc.defaultView;
  7895. win.scrollBy(x, y);
  7896. };
  7897. function WindowBridge (win) {
  7898. var elementFromPoint = function (x, y) {
  7899. return Element.fromPoint(Element.fromDom(win.document), x, y);
  7900. };
  7901. var getRect = function (element) {
  7902. return element.dom().getBoundingClientRect();
  7903. };
  7904. var getRangedRect = function (start, soffset, finish, foffset) {
  7905. var sel = exact(start, soffset, finish, foffset);
  7906. return getFirstRect$1(win, sel).map(function (structRect) {
  7907. return map$1(structRect, apply);
  7908. });
  7909. };
  7910. var getSelection = function () {
  7911. return get$a(win).map(function (exactAdt) {
  7912. return Util$1.convertToRange(win, exactAdt);
  7913. });
  7914. };
  7915. var fromSitus = function (situs) {
  7916. var relative$1 = relative(situs.start(), situs.finish());
  7917. return Util$1.convertToRange(win, relative$1);
  7918. };
  7919. var situsFromPoint = function (x, y) {
  7920. return getAtPoint(win, x, y).map(function (exact) {
  7921. return {
  7922. start: constant(Situ.on(exact.start(), exact.soffset())),
  7923. finish: constant(Situ.on(exact.finish(), exact.foffset()))
  7924. };
  7925. });
  7926. };
  7927. var clearSelection = function () {
  7928. clear$1(win);
  7929. };
  7930. var selectContents = function (element) {
  7931. setToElement(win, element);
  7932. };
  7933. var setSelection = function (sel) {
  7934. setExact(win, sel.start(), sel.soffset(), sel.finish(), sel.foffset());
  7935. };
  7936. var setRelativeSelection = function (start, finish) {
  7937. setRelative(win, start, finish);
  7938. };
  7939. var getInnerHeight = function () {
  7940. return win.innerHeight;
  7941. };
  7942. var getScrollY = function () {
  7943. var pos = get$b(Element.fromDom(win.document));
  7944. return pos.top();
  7945. };
  7946. var scrollBy = function (x, y) {
  7947. by(x, y, Element.fromDom(win.document));
  7948. };
  7949. return {
  7950. elementFromPoint: elementFromPoint,
  7951. getRect: getRect,
  7952. getRangedRect: getRangedRect,
  7953. getSelection: getSelection,
  7954. fromSitus: fromSitus,
  7955. situsFromPoint: situsFromPoint,
  7956. clearSelection: clearSelection,
  7957. setSelection: setSelection,
  7958. setRelativeSelection: setRelativeSelection,
  7959. selectContents: selectContents,
  7960. getInnerHeight: getInnerHeight,
  7961. getScrollY: getScrollY,
  7962. scrollBy: scrollBy
  7963. };
  7964. }
  7965. var sync = function (container, isRoot, start, soffset, finish, foffset, selectRange) {
  7966. if (!(eq(start, finish) && soffset === foffset)) {
  7967. return closest$1(start, 'td,th', isRoot).bind(function (s) {
  7968. return closest$1(finish, 'td,th', isRoot).bind(function (f) {
  7969. return detect$5(container, isRoot, s, f, selectRange);
  7970. });
  7971. });
  7972. } else {
  7973. return Option.none();
  7974. }
  7975. };
  7976. var detect$5 = function (container, isRoot, start, finish, selectRange) {
  7977. if (!eq(start, finish)) {
  7978. return CellSelection.identify(start, finish, isRoot).bind(function (cellSel) {
  7979. var boxes = cellSel.boxes().getOr([]);
  7980. if (boxes.length > 0) {
  7981. selectRange(container, boxes, cellSel.start(), cellSel.finish());
  7982. return Option.some(Responses.response(Option.some(Util$1.makeSitus(start, 0, start, getEnd(start))), true));
  7983. } else {
  7984. return Option.none();
  7985. }
  7986. });
  7987. } else {
  7988. return Option.none();
  7989. }
  7990. };
  7991. var update = function (rows, columns, container, selected, annotations) {
  7992. var updateSelection = function (newSels) {
  7993. annotations.clear(container);
  7994. annotations.selectRange(container, newSels.boxes(), newSels.start(), newSels.finish());
  7995. return newSels.boxes();
  7996. };
  7997. return CellSelection.shiftSelection(selected, rows, columns, annotations.firstSelectedSelector(), annotations.lastSelectedSelector()).map(updateSelection);
  7998. };
  7999. var KeySelection = {
  8000. sync: sync,
  8001. detect: detect$5,
  8002. update: update
  8003. };
  8004. var nu$3 = MixedBag([
  8005. 'left',
  8006. 'top',
  8007. 'right',
  8008. 'bottom'
  8009. ], []);
  8010. var moveDown = function (caret, amount) {
  8011. return nu$3({
  8012. left: caret.left(),
  8013. top: caret.top() + amount,
  8014. right: caret.right(),
  8015. bottom: caret.bottom() + amount
  8016. });
  8017. };
  8018. var moveUp = function (caret, amount) {
  8019. return nu$3({
  8020. left: caret.left(),
  8021. top: caret.top() - amount,
  8022. right: caret.right(),
  8023. bottom: caret.bottom() - amount
  8024. });
  8025. };
  8026. var moveBottomTo = function (caret, bottom) {
  8027. var height = caret.bottom() - caret.top();
  8028. return nu$3({
  8029. left: caret.left(),
  8030. top: bottom - height,
  8031. right: caret.right(),
  8032. bottom: bottom
  8033. });
  8034. };
  8035. var moveTopTo = function (caret, top) {
  8036. var height = caret.bottom() - caret.top();
  8037. return nu$3({
  8038. left: caret.left(),
  8039. top: top,
  8040. right: caret.right(),
  8041. bottom: top + height
  8042. });
  8043. };
  8044. var translate = function (caret, xDelta, yDelta) {
  8045. return nu$3({
  8046. left: caret.left() + xDelta,
  8047. top: caret.top() + yDelta,
  8048. right: caret.right() + xDelta,
  8049. bottom: caret.bottom() + yDelta
  8050. });
  8051. };
  8052. var getTop$1 = function (caret) {
  8053. return caret.top();
  8054. };
  8055. var getBottom = function (caret) {
  8056. return caret.bottom();
  8057. };
  8058. var toString = function (caret) {
  8059. return '(' + caret.left() + ', ' + caret.top() + ') -> (' + caret.right() + ', ' + caret.bottom() + ')';
  8060. };
  8061. var Carets = {
  8062. nu: nu$3,
  8063. moveUp: moveUp,
  8064. moveDown: moveDown,
  8065. moveBottomTo: moveBottomTo,
  8066. moveTopTo: moveTopTo,
  8067. getTop: getTop$1,
  8068. getBottom: getBottom,
  8069. translate: translate,
  8070. toString: toString
  8071. };
  8072. var getPartialBox = function (bridge, element, offset) {
  8073. if (offset >= 0 && offset < getEnd(element))
  8074. return bridge.getRangedRect(element, offset, element, offset + 1);
  8075. else if (offset > 0)
  8076. return bridge.getRangedRect(element, offset - 1, element, offset);
  8077. return Option.none();
  8078. };
  8079. var toCaret = function (rect) {
  8080. return Carets.nu({
  8081. left: rect.left,
  8082. top: rect.top,
  8083. right: rect.right,
  8084. bottom: rect.bottom
  8085. });
  8086. };
  8087. var getElemBox = function (bridge, element) {
  8088. return Option.some(bridge.getRect(element));
  8089. };
  8090. var getBoxAt = function (bridge, element, offset) {
  8091. if (isElement(element))
  8092. return getElemBox(bridge, element).map(toCaret);
  8093. else if (isText(element))
  8094. return getPartialBox(bridge, element, offset).map(toCaret);
  8095. else
  8096. return Option.none();
  8097. };
  8098. var getEntireBox = function (bridge, element) {
  8099. if (isElement(element))
  8100. return getElemBox(bridge, element).map(toCaret);
  8101. else if (isText(element))
  8102. return bridge.getRangedRect(element, 0, element, getEnd(element)).map(toCaret);
  8103. else
  8104. return Option.none();
  8105. };
  8106. var Rectangles = {
  8107. getBoxAt: getBoxAt,
  8108. getEntireBox: getEntireBox
  8109. };
  8110. var traverse = Immutable('item', 'mode');
  8111. var backtrack = function (universe, item, _direction, transition) {
  8112. if (transition === void 0) {
  8113. transition = sidestep;
  8114. }
  8115. return universe.property().parent(item).map(function (p) {
  8116. return traverse(p, transition);
  8117. });
  8118. };
  8119. var sidestep = function (universe, item, direction, transition) {
  8120. if (transition === void 0) {
  8121. transition = advance;
  8122. }
  8123. return direction.sibling(universe, item).map(function (p) {
  8124. return traverse(p, transition);
  8125. });
  8126. };
  8127. var advance = function (universe, item, direction, transition) {
  8128. if (transition === void 0) {
  8129. transition = advance;
  8130. }
  8131. var children = universe.property().children(item);
  8132. var result = direction.first(children);
  8133. return result.map(function (r) {
  8134. return traverse(r, transition);
  8135. });
  8136. };
  8137. var successors = [
  8138. {
  8139. current: backtrack,
  8140. next: sidestep,
  8141. fallback: Option.none()
  8142. },
  8143. {
  8144. current: sidestep,
  8145. next: advance,
  8146. fallback: Option.some(backtrack)
  8147. },
  8148. {
  8149. current: advance,
  8150. next: advance,
  8151. fallback: Option.some(sidestep)
  8152. }
  8153. ];
  8154. var go$1 = function (universe, item, mode, direction, rules) {
  8155. if (rules === void 0) {
  8156. rules = successors;
  8157. }
  8158. var ruleOpt = find(rules, function (succ) {
  8159. return succ.current === mode;
  8160. });
  8161. return ruleOpt.bind(function (rule) {
  8162. return rule.current(universe, item, direction, rule.next).orThunk(function () {
  8163. return rule.fallback.bind(function (fb) {
  8164. return go$1(universe, item, fb, direction);
  8165. });
  8166. });
  8167. });
  8168. };
  8169. var left$1 = function () {
  8170. var sibling = function (universe, item) {
  8171. return universe.query().prevSibling(item);
  8172. };
  8173. var first = function (children) {
  8174. return children.length > 0 ? Option.some(children[children.length - 1]) : Option.none();
  8175. };
  8176. return {
  8177. sibling: sibling,
  8178. first: first
  8179. };
  8180. };
  8181. var right$1 = function () {
  8182. var sibling = function (universe, item) {
  8183. return universe.query().nextSibling(item);
  8184. };
  8185. var first = function (children) {
  8186. return children.length > 0 ? Option.some(children[0]) : Option.none();
  8187. };
  8188. return {
  8189. sibling: sibling,
  8190. first: first
  8191. };
  8192. };
  8193. var Walkers = {
  8194. left: left$1,
  8195. right: right$1
  8196. };
  8197. var hone = function (universe, item, predicate, mode, direction, isRoot) {
  8198. var next = go$1(universe, item, mode, direction);
  8199. return next.bind(function (n) {
  8200. if (isRoot(n.item()))
  8201. return Option.none();
  8202. else
  8203. return predicate(n.item()) ? Option.some(n.item()) : hone(universe, n.item(), predicate, n.mode(), direction, isRoot);
  8204. });
  8205. };
  8206. var left$2 = function (universe, item, predicate, isRoot) {
  8207. return hone(universe, item, predicate, sidestep, Walkers.left(), isRoot);
  8208. };
  8209. var right$2 = function (universe, item, predicate, isRoot) {
  8210. return hone(universe, item, predicate, sidestep, Walkers.right(), isRoot);
  8211. };
  8212. var Seeker = /*#__PURE__*/Object.freeze({
  8213. left: left$2,
  8214. right: right$2
  8215. });
  8216. var isLeaf = function (universe) {
  8217. return function (element) {
  8218. return universe.property().children(element).length === 0;
  8219. };
  8220. };
  8221. var before$3 = function (universe, item, isRoot) {
  8222. return seekLeft(universe, item, isLeaf(universe), isRoot);
  8223. };
  8224. var after$4 = function (universe, item, isRoot) {
  8225. return seekRight(universe, item, isLeaf(universe), isRoot);
  8226. };
  8227. var seekLeft = left$2;
  8228. var seekRight = right$2;
  8229. var universe$2 = DomUniverse();
  8230. var before$4 = function (element, isRoot) {
  8231. return before$3(universe$2, element, isRoot);
  8232. };
  8233. var after$5 = function (element, isRoot) {
  8234. return after$4(universe$2, element, isRoot);
  8235. };
  8236. var seekLeft$1 = function (element, predicate, isRoot) {
  8237. return seekLeft(universe$2, element, predicate, isRoot);
  8238. };
  8239. var seekRight$1 = function (element, predicate, isRoot) {
  8240. return seekRight(universe$2, element, predicate, isRoot);
  8241. };
  8242. var JUMP_SIZE = 5;
  8243. var NUM_RETRIES = 100;
  8244. var adt$2 = Adt.generate([
  8245. { 'none': [] },
  8246. { 'retry': ['caret'] }
  8247. ]);
  8248. var isOutside = function (caret, box) {
  8249. return caret.left() < box.left() || Math.abs(box.right() - caret.left()) < 1 || caret.left() > box.right();
  8250. };
  8251. var inOutsideBlock = function (bridge, element, caret) {
  8252. return closest(element, DomStructure.isBlock).fold(constant(false), function (cell) {
  8253. return Rectangles.getEntireBox(bridge, cell).exists(function (box) {
  8254. return isOutside(caret, box);
  8255. });
  8256. });
  8257. };
  8258. var adjustDown = function (bridge, element, guessBox, original, caret) {
  8259. var lowerCaret = Carets.moveDown(caret, JUMP_SIZE);
  8260. if (Math.abs(guessBox.bottom() - original.bottom()) < 1)
  8261. return adt$2.retry(lowerCaret);
  8262. else if (guessBox.top() > caret.bottom())
  8263. return adt$2.retry(lowerCaret);
  8264. else if (guessBox.top() === caret.bottom())
  8265. return adt$2.retry(Carets.moveDown(caret, 1));
  8266. else
  8267. return inOutsideBlock(bridge, element, caret) ? adt$2.retry(Carets.translate(lowerCaret, JUMP_SIZE, 0)) : adt$2.none();
  8268. };
  8269. var adjustUp = function (bridge, element, guessBox, original, caret) {
  8270. var higherCaret = Carets.moveUp(caret, JUMP_SIZE);
  8271. if (Math.abs(guessBox.top() - original.top()) < 1)
  8272. return adt$2.retry(higherCaret);
  8273. else if (guessBox.bottom() < caret.top())
  8274. return adt$2.retry(higherCaret);
  8275. else if (guessBox.bottom() === caret.top())
  8276. return adt$2.retry(Carets.moveUp(caret, 1));
  8277. else
  8278. return inOutsideBlock(bridge, element, caret) ? adt$2.retry(Carets.translate(higherCaret, JUMP_SIZE, 0)) : adt$2.none();
  8279. };
  8280. var upMovement = {
  8281. point: Carets.getTop,
  8282. adjuster: adjustUp,
  8283. move: Carets.moveUp,
  8284. gather: before$4
  8285. };
  8286. var downMovement = {
  8287. point: Carets.getBottom,
  8288. adjuster: adjustDown,
  8289. move: Carets.moveDown,
  8290. gather: after$5
  8291. };
  8292. var isAtTable = function (bridge, x, y) {
  8293. return bridge.elementFromPoint(x, y).filter(function (elm) {
  8294. return name(elm) === 'table';
  8295. }).isSome();
  8296. };
  8297. var adjustForTable = function (bridge, movement, original, caret, numRetries) {
  8298. return adjustTil(bridge, movement, original, movement.move(caret, JUMP_SIZE), numRetries);
  8299. };
  8300. var adjustTil = function (bridge, movement, original, caret, numRetries) {
  8301. if (numRetries === 0)
  8302. return Option.some(caret);
  8303. if (isAtTable(bridge, caret.left(), movement.point(caret)))
  8304. return adjustForTable(bridge, movement, original, caret, numRetries - 1);
  8305. return bridge.situsFromPoint(caret.left(), movement.point(caret)).bind(function (guess) {
  8306. return guess.start().fold(Option.none, function (element, offset) {
  8307. return Rectangles.getEntireBox(bridge, element, offset).bind(function (guessBox) {
  8308. return movement.adjuster(bridge, element, guessBox, original, caret).fold(Option.none, function (newCaret) {
  8309. return adjustTil(bridge, movement, original, newCaret, numRetries - 1);
  8310. });
  8311. }).orThunk(function () {
  8312. return Option.some(caret);
  8313. });
  8314. }, Option.none);
  8315. });
  8316. };
  8317. var ieTryDown = function (bridge, caret) {
  8318. return bridge.situsFromPoint(caret.left(), caret.bottom() + JUMP_SIZE);
  8319. };
  8320. var ieTryUp = function (bridge, caret) {
  8321. return bridge.situsFromPoint(caret.left(), caret.top() - JUMP_SIZE);
  8322. };
  8323. var checkScroll = function (movement, adjusted, bridge) {
  8324. if (movement.point(adjusted) > bridge.getInnerHeight())
  8325. return Option.some(movement.point(adjusted) - bridge.getInnerHeight());
  8326. else if (movement.point(adjusted) < 0)
  8327. return Option.some(-movement.point(adjusted));
  8328. else
  8329. return Option.none();
  8330. };
  8331. var retry = function (movement, bridge, caret) {
  8332. var moved = movement.move(caret, JUMP_SIZE);
  8333. var adjusted = adjustTil(bridge, movement, caret, moved, NUM_RETRIES).getOr(moved);
  8334. return checkScroll(movement, adjusted, bridge).fold(function () {
  8335. return bridge.situsFromPoint(adjusted.left(), movement.point(adjusted));
  8336. }, function (delta) {
  8337. bridge.scrollBy(0, delta);
  8338. return bridge.situsFromPoint(adjusted.left(), movement.point(adjusted) - delta);
  8339. });
  8340. };
  8341. var Retries = {
  8342. tryUp: curry(retry, upMovement),
  8343. tryDown: curry(retry, downMovement),
  8344. ieTryUp: ieTryUp,
  8345. ieTryDown: ieTryDown,
  8346. getJumpSize: constant(JUMP_SIZE)
  8347. };
  8348. var adt$3 = Adt.generate([
  8349. { 'none': ['message'] },
  8350. { 'success': [] },
  8351. { 'failedUp': ['cell'] },
  8352. { 'failedDown': ['cell'] }
  8353. ]);
  8354. var isOverlapping = function (bridge, before, after) {
  8355. var beforeBounds = bridge.getRect(before);
  8356. var afterBounds = bridge.getRect(after);
  8357. return afterBounds.right > beforeBounds.left && afterBounds.left < beforeBounds.right;
  8358. };
  8359. var verify = function (bridge, before, beforeOffset, after, afterOffset, failure, isRoot) {
  8360. return closest$1(after, 'td,th', isRoot).bind(function (afterCell) {
  8361. return closest$1(before, 'td,th', isRoot).map(function (beforeCell) {
  8362. if (!eq(afterCell, beforeCell)) {
  8363. return DomParent.sharedOne(isRow, [
  8364. afterCell,
  8365. beforeCell
  8366. ]).fold(function () {
  8367. return isOverlapping(bridge, beforeCell, afterCell) ? adt$3.success() : failure(beforeCell);
  8368. }, function (sharedRow) {
  8369. return failure(beforeCell);
  8370. });
  8371. } else {
  8372. return eq(after, afterCell) && getEnd(afterCell) === afterOffset ? failure(beforeCell) : adt$3.none('in same cell');
  8373. }
  8374. });
  8375. }).getOr(adt$3.none('default'));
  8376. };
  8377. var isRow = function (elem) {
  8378. return closest$1(elem, 'tr');
  8379. };
  8380. var cata$2 = function (subject, onNone, onSuccess, onFailedUp, onFailedDown) {
  8381. return subject.fold(onNone, onSuccess, onFailedUp, onFailedDown);
  8382. };
  8383. var BeforeAfter = {
  8384. verify: verify,
  8385. cata: cata$2,
  8386. adt: adt$3
  8387. };
  8388. var point = Immutable('element', 'offset');
  8389. var delta = Immutable('element', 'deltaOffset');
  8390. var range$3 = Immutable('element', 'start', 'finish');
  8391. var points = Immutable('begin', 'end');
  8392. var text = Immutable('element', 'text');
  8393. var inAncestor = Immutable('ancestor', 'descendants', 'element', 'index');
  8394. var inParent = Immutable('parent', 'children', 'element', 'index');
  8395. var indexInParent = function (element) {
  8396. return parent(element).bind(function (parent) {
  8397. var children$1 = children(parent);
  8398. return indexOf$1(children$1, element).map(function (index) {
  8399. return inParent(parent, children$1, element, index);
  8400. });
  8401. });
  8402. };
  8403. var indexOf$1 = function (elements, element) {
  8404. return findIndex(elements, curry(eq, element));
  8405. };
  8406. var isBr = function (elem) {
  8407. return name(elem) === 'br';
  8408. };
  8409. var gatherer = function (cand, gather, isRoot) {
  8410. return gather(cand, isRoot).bind(function (target) {
  8411. return isText(target) && get$3(target).trim().length === 0 ? gatherer(target, gather, isRoot) : Option.some(target);
  8412. });
  8413. };
  8414. var handleBr = function (isRoot, element, direction) {
  8415. return direction.traverse(element).orThunk(function () {
  8416. return gatherer(element, direction.gather, isRoot);
  8417. }).map(direction.relative);
  8418. };
  8419. var findBr = function (element, offset) {
  8420. return child(element, offset).filter(isBr).orThunk(function () {
  8421. return child(element, offset - 1).filter(isBr);
  8422. });
  8423. };
  8424. var handleParent = function (isRoot, element, offset, direction) {
  8425. return findBr(element, offset).bind(function (br) {
  8426. return direction.traverse(br).fold(function () {
  8427. return gatherer(br, direction.gather, isRoot).map(direction.relative);
  8428. }, function (adjacent) {
  8429. return indexInParent(adjacent).map(function (info) {
  8430. return Situ.on(info.parent(), info.index());
  8431. });
  8432. });
  8433. });
  8434. };
  8435. var tryBr = function (isRoot, element, offset, direction) {
  8436. var target = isBr(element) ? handleBr(isRoot, element, direction) : handleParent(isRoot, element, offset, direction);
  8437. return target.map(function (tgt) {
  8438. return {
  8439. start: constant(tgt),
  8440. finish: constant(tgt)
  8441. };
  8442. });
  8443. };
  8444. var process = function (analysis) {
  8445. return BeforeAfter.cata(analysis, function (message) {
  8446. return Option.none();
  8447. }, function () {
  8448. return Option.none();
  8449. }, function (cell) {
  8450. return Option.some(point(cell, 0));
  8451. }, function (cell) {
  8452. return Option.some(point(cell, getEnd(cell)));
  8453. });
  8454. };
  8455. var BrTags = {
  8456. tryBr: tryBr,
  8457. process: process
  8458. };
  8459. var MAX_RETRIES = 20;
  8460. var platform$1 = PlatformDetection$1.detect();
  8461. var findSpot = function (bridge, isRoot, direction) {
  8462. return bridge.getSelection().bind(function (sel) {
  8463. return BrTags.tryBr(isRoot, sel.finish(), sel.foffset(), direction).fold(function () {
  8464. return Option.some(point(sel.finish(), sel.foffset()));
  8465. }, function (brNeighbour) {
  8466. var range = bridge.fromSitus(brNeighbour);
  8467. var analysis = BeforeAfter.verify(bridge, sel.finish(), sel.foffset(), range.finish(), range.foffset(), direction.failure, isRoot);
  8468. return BrTags.process(analysis);
  8469. });
  8470. });
  8471. };
  8472. var scan = function (bridge, isRoot, element, offset, direction, numRetries) {
  8473. if (numRetries === 0)
  8474. return Option.none();
  8475. return tryCursor(bridge, isRoot, element, offset, direction).bind(function (situs) {
  8476. var range = bridge.fromSitus(situs);
  8477. var analysis = BeforeAfter.verify(bridge, element, offset, range.finish(), range.foffset(), direction.failure, isRoot);
  8478. return BeforeAfter.cata(analysis, function () {
  8479. return Option.none();
  8480. }, function () {
  8481. return Option.some(situs);
  8482. }, function (cell) {
  8483. if (eq(element, cell) && offset === 0)
  8484. return tryAgain(bridge, element, offset, Carets.moveUp, direction);
  8485. else
  8486. return scan(bridge, isRoot, cell, 0, direction, numRetries - 1);
  8487. }, function (cell) {
  8488. if (eq(element, cell) && offset === getEnd(cell))
  8489. return tryAgain(bridge, element, offset, Carets.moveDown, direction);
  8490. else
  8491. return scan(bridge, isRoot, cell, getEnd(cell), direction, numRetries - 1);
  8492. });
  8493. });
  8494. };
  8495. var tryAgain = function (bridge, element, offset, move, direction) {
  8496. return Rectangles.getBoxAt(bridge, element, offset).bind(function (box) {
  8497. return tryAt(bridge, direction, move(box, Retries.getJumpSize()));
  8498. });
  8499. };
  8500. var tryAt = function (bridge, direction, box) {
  8501. if (platform$1.browser.isChrome() || platform$1.browser.isSafari() || platform$1.browser.isFirefox() || platform$1.browser.isEdge())
  8502. return direction.otherRetry(bridge, box);
  8503. else if (platform$1.browser.isIE())
  8504. return direction.ieRetry(bridge, box);
  8505. else
  8506. return Option.none();
  8507. };
  8508. var tryCursor = function (bridge, isRoot, element, offset, direction) {
  8509. return Rectangles.getBoxAt(bridge, element, offset).bind(function (box) {
  8510. return tryAt(bridge, direction, box);
  8511. });
  8512. };
  8513. var handle$2 = function (bridge, isRoot, direction) {
  8514. return findSpot(bridge, isRoot, direction).bind(function (spot) {
  8515. return scan(bridge, isRoot, spot.element(), spot.offset(), direction, MAX_RETRIES).map(bridge.fromSitus);
  8516. });
  8517. };
  8518. var TableKeys = { handle: handle$2 };
  8519. var ancestor$2 = function (scope, predicate, isRoot) {
  8520. return ancestor(scope, predicate, isRoot).isSome();
  8521. };
  8522. var detection = PlatformDetection$1.detect();
  8523. var inSameTable = function (elem, table) {
  8524. return ancestor$2(elem, function (e) {
  8525. return parent(e).exists(function (p) {
  8526. return eq(p, table);
  8527. });
  8528. });
  8529. };
  8530. var simulate = function (bridge, isRoot, direction, initial, anchor) {
  8531. return closest$1(initial, 'td,th', isRoot).bind(function (start) {
  8532. return closest$1(start, 'table', isRoot).bind(function (table) {
  8533. if (!inSameTable(anchor, table))
  8534. return Option.none();
  8535. return TableKeys.handle(bridge, isRoot, direction).bind(function (range) {
  8536. return closest$1(range.finish(), 'td,th', isRoot).map(function (finish) {
  8537. return {
  8538. start: constant(start),
  8539. finish: constant(finish),
  8540. range: constant(range)
  8541. };
  8542. });
  8543. });
  8544. });
  8545. });
  8546. };
  8547. var navigate = function (bridge, isRoot, direction, initial, anchor, precheck) {
  8548. if (detection.browser.isIE()) {
  8549. return Option.none();
  8550. } else {
  8551. return precheck(initial, isRoot).orThunk(function () {
  8552. return simulate(bridge, isRoot, direction, initial, anchor).map(function (info) {
  8553. var range = info.range();
  8554. return Responses.response(Option.some(Util$1.makeSitus(range.start(), range.soffset(), range.finish(), range.foffset())), true);
  8555. });
  8556. });
  8557. }
  8558. };
  8559. var firstUpCheck = function (initial, isRoot) {
  8560. return closest$1(initial, 'tr', isRoot).bind(function (startRow) {
  8561. return closest$1(startRow, 'table', isRoot).bind(function (table) {
  8562. var rows = descendants$1(table, 'tr');
  8563. if (eq(startRow, rows[0])) {
  8564. return seekLeft$1(table, function (element) {
  8565. return last$1(element).isSome();
  8566. }, isRoot).map(function (last) {
  8567. var lastOffset = getEnd(last);
  8568. return Responses.response(Option.some(Util$1.makeSitus(last, lastOffset, last, lastOffset)), true);
  8569. });
  8570. } else {
  8571. return Option.none();
  8572. }
  8573. });
  8574. });
  8575. };
  8576. var lastDownCheck = function (initial, isRoot) {
  8577. return closest$1(initial, 'tr', isRoot).bind(function (startRow) {
  8578. return closest$1(startRow, 'table', isRoot).bind(function (table) {
  8579. var rows = descendants$1(table, 'tr');
  8580. if (eq(startRow, rows[rows.length - 1])) {
  8581. return seekRight$1(table, function (element) {
  8582. return first$1(element).isSome();
  8583. }, isRoot).map(function (first) {
  8584. return Responses.response(Option.some(Util$1.makeSitus(first, 0, first, 0)), true);
  8585. });
  8586. } else {
  8587. return Option.none();
  8588. }
  8589. });
  8590. });
  8591. };
  8592. var select = function (bridge, container, isRoot, direction, initial, anchor, selectRange) {
  8593. return simulate(bridge, isRoot, direction, initial, anchor).bind(function (info) {
  8594. return KeySelection.detect(container, isRoot, info.start(), info.finish(), selectRange);
  8595. });
  8596. };
  8597. var VerticalMovement = {
  8598. navigate: navigate,
  8599. select: select,
  8600. firstUpCheck: firstUpCheck,
  8601. lastDownCheck: lastDownCheck
  8602. };
  8603. var findCell = function (target, isRoot) {
  8604. return closest$1(target, 'td,th', isRoot);
  8605. };
  8606. function MouseSelection (bridge, container, isRoot, annotations) {
  8607. var cursor = Option.none();
  8608. var clearState = function () {
  8609. cursor = Option.none();
  8610. };
  8611. var mousedown = function (event) {
  8612. annotations.clear(container);
  8613. cursor = findCell(event.target(), isRoot);
  8614. };
  8615. var mouseover = function (event) {
  8616. cursor.each(function (start) {
  8617. annotations.clear(container);
  8618. findCell(event.target(), isRoot).each(function (finish) {
  8619. CellSelection.identify(start, finish, isRoot).each(function (cellSel) {
  8620. var boxes = cellSel.boxes().getOr([]);
  8621. if (boxes.length > 1 || boxes.length === 1 && !eq(start, finish)) {
  8622. annotations.selectRange(container, boxes, cellSel.start(), cellSel.finish());
  8623. bridge.selectContents(finish);
  8624. }
  8625. });
  8626. });
  8627. });
  8628. };
  8629. var mouseup = function () {
  8630. cursor.each(clearState);
  8631. };
  8632. return {
  8633. mousedown: mousedown,
  8634. mouseover: mouseover,
  8635. mouseup: mouseup
  8636. };
  8637. }
  8638. var KeyDirection = {
  8639. down: {
  8640. traverse: nextSibling,
  8641. gather: after$5,
  8642. relative: Situ.before,
  8643. otherRetry: Retries.tryDown,
  8644. ieRetry: Retries.ieTryDown,
  8645. failure: BeforeAfter.adt.failedDown
  8646. },
  8647. up: {
  8648. traverse: prevSibling,
  8649. gather: before$4,
  8650. relative: Situ.before,
  8651. otherRetry: Retries.tryUp,
  8652. ieRetry: Retries.ieTryUp,
  8653. failure: BeforeAfter.adt.failedUp
  8654. }
  8655. };
  8656. var rc = Immutable('rows', 'cols');
  8657. var mouse = function (win, container, isRoot, annotations) {
  8658. var bridge = WindowBridge(win);
  8659. var handlers = MouseSelection(bridge, container, isRoot, annotations);
  8660. return {
  8661. mousedown: handlers.mousedown,
  8662. mouseover: handlers.mouseover,
  8663. mouseup: handlers.mouseup
  8664. };
  8665. };
  8666. var keyboard = function (win, container, isRoot, annotations) {
  8667. var bridge = WindowBridge(win);
  8668. var clearToNavigate = function () {
  8669. annotations.clear(container);
  8670. return Option.none();
  8671. };
  8672. var keydown = function (event, start, soffset, finish, foffset, direction) {
  8673. var keycode = event.raw().which;
  8674. var shiftKey = event.raw().shiftKey === true;
  8675. var handler = CellSelection.retrieve(container, annotations.selectedSelector()).fold(function () {
  8676. if (SelectionKeys.isDown(keycode) && shiftKey) {
  8677. return curry(VerticalMovement.select, bridge, container, isRoot, KeyDirection.down, finish, start, annotations.selectRange);
  8678. } else if (SelectionKeys.isUp(keycode) && shiftKey) {
  8679. return curry(VerticalMovement.select, bridge, container, isRoot, KeyDirection.up, finish, start, annotations.selectRange);
  8680. } else if (SelectionKeys.isDown(keycode)) {
  8681. return curry(VerticalMovement.navigate, bridge, isRoot, KeyDirection.down, finish, start, VerticalMovement.lastDownCheck);
  8682. } else if (SelectionKeys.isUp(keycode)) {
  8683. return curry(VerticalMovement.navigate, bridge, isRoot, KeyDirection.up, finish, start, VerticalMovement.firstUpCheck);
  8684. } else {
  8685. return Option.none;
  8686. }
  8687. }, function (selected) {
  8688. var update = function (attempts) {
  8689. return function () {
  8690. var navigation = findMap(attempts, function (delta) {
  8691. return KeySelection.update(delta.rows(), delta.cols(), container, selected, annotations);
  8692. });
  8693. return navigation.fold(function () {
  8694. return CellSelection.getEdges(container, annotations.firstSelectedSelector(), annotations.lastSelectedSelector()).map(function (edges) {
  8695. var relative = SelectionKeys.isDown(keycode) || direction.isForward(keycode) ? Situ.after : Situ.before;
  8696. bridge.setRelativeSelection(Situ.on(edges.first(), 0), relative(edges.table()));
  8697. annotations.clear(container);
  8698. return Responses.response(Option.none(), true);
  8699. });
  8700. }, function (_) {
  8701. return Option.some(Responses.response(Option.none(), true));
  8702. });
  8703. };
  8704. };
  8705. if (SelectionKeys.isDown(keycode) && shiftKey)
  8706. return update([rc(+1, 0)]);
  8707. else if (SelectionKeys.isUp(keycode) && shiftKey)
  8708. return update([rc(-1, 0)]);
  8709. else if (direction.isBackward(keycode) && shiftKey)
  8710. return update([
  8711. rc(0, -1),
  8712. rc(-1, 0)
  8713. ]);
  8714. else if (direction.isForward(keycode) && shiftKey)
  8715. return update([
  8716. rc(0, +1),
  8717. rc(+1, 0)
  8718. ]);
  8719. else if (SelectionKeys.isNavigation(keycode) && shiftKey === false)
  8720. return clearToNavigate;
  8721. else
  8722. return Option.none;
  8723. });
  8724. return handler();
  8725. };
  8726. var keyup = function (event, start, soffset, finish, foffset) {
  8727. return CellSelection.retrieve(container, annotations.selectedSelector()).fold(function () {
  8728. var keycode = event.raw().which;
  8729. var shiftKey = event.raw().shiftKey === true;
  8730. if (shiftKey === false)
  8731. return Option.none();
  8732. if (SelectionKeys.isNavigation(keycode))
  8733. return KeySelection.sync(container, isRoot, start, soffset, finish, foffset, annotations.selectRange);
  8734. else
  8735. return Option.none();
  8736. }, Option.none);
  8737. };
  8738. return {
  8739. keydown: keydown,
  8740. keyup: keyup
  8741. };
  8742. };
  8743. var InputHandlers = {
  8744. mouse: mouse,
  8745. keyboard: keyboard
  8746. };
  8747. var remove$7 = function (element, classes) {
  8748. each(classes, function (x) {
  8749. remove$5(element, x);
  8750. });
  8751. };
  8752. var addClass = function (clazz) {
  8753. return function (element) {
  8754. add$2(element, clazz);
  8755. };
  8756. };
  8757. var removeClasses = function (classes) {
  8758. return function (element) {
  8759. remove$7(element, classes);
  8760. };
  8761. };
  8762. var byClass = function (ephemera) {
  8763. var addSelectionClass = addClass(ephemera.selected());
  8764. var removeSelectionClasses = removeClasses([
  8765. ephemera.selected(),
  8766. ephemera.lastSelected(),
  8767. ephemera.firstSelected()
  8768. ]);
  8769. var clear = function (container) {
  8770. var sels = descendants$1(container, ephemera.selectedSelector());
  8771. each(sels, removeSelectionClasses);
  8772. };
  8773. var selectRange = function (container, cells, start, finish) {
  8774. clear(container);
  8775. each(cells, addSelectionClass);
  8776. add$2(start, ephemera.firstSelected());
  8777. add$2(finish, ephemera.lastSelected());
  8778. };
  8779. return {
  8780. clear: clear,
  8781. selectRange: selectRange,
  8782. selectedSelector: ephemera.selectedSelector,
  8783. firstSelectedSelector: ephemera.firstSelectedSelector,
  8784. lastSelectedSelector: ephemera.lastSelectedSelector
  8785. };
  8786. };
  8787. var byAttr = function (ephemera) {
  8788. var removeSelectionAttributes = function (element) {
  8789. remove(element, ephemera.selected());
  8790. remove(element, ephemera.firstSelected());
  8791. remove(element, ephemera.lastSelected());
  8792. };
  8793. var addSelectionAttribute = function (element) {
  8794. set(element, ephemera.selected(), '1');
  8795. };
  8796. var clear = function (container) {
  8797. var sels = descendants$1(container, ephemera.selectedSelector());
  8798. each(sels, removeSelectionAttributes);
  8799. };
  8800. var selectRange = function (container, cells, start, finish) {
  8801. clear(container);
  8802. each(cells, addSelectionAttribute);
  8803. set(start, ephemera.firstSelected(), '1');
  8804. set(finish, ephemera.lastSelected(), '1');
  8805. };
  8806. return {
  8807. clear: clear,
  8808. selectRange: selectRange,
  8809. selectedSelector: ephemera.selectedSelector,
  8810. firstSelectedSelector: ephemera.firstSelectedSelector,
  8811. lastSelectedSelector: ephemera.lastSelectedSelector
  8812. };
  8813. };
  8814. var SelectionAnnotation = {
  8815. byClass: byClass,
  8816. byAttr: byAttr
  8817. };
  8818. var hasInternalTarget = function (e) {
  8819. return has$2(Element.fromDom(e.target), 'ephox-snooker-resizer-bar') === false;
  8820. };
  8821. function CellSelection$1 (editor, lazyResize) {
  8822. var handlerStruct = MixedBag([
  8823. 'mousedown',
  8824. 'mouseover',
  8825. 'mouseup',
  8826. 'keyup',
  8827. 'keydown'
  8828. ], []);
  8829. var handlers = Option.none();
  8830. var annotations = SelectionAnnotation.byAttr(Ephemera);
  8831. editor.on('init', function (e) {
  8832. var win = editor.getWin();
  8833. var body = getBody$1(editor);
  8834. var isRoot = getIsRoot(editor);
  8835. var syncSelection = function () {
  8836. var sel = editor.selection;
  8837. var start = Element.fromDom(sel.getStart());
  8838. var end = Element.fromDom(sel.getEnd());
  8839. var shared = DomParent.sharedOne(TableLookup.table, [
  8840. start,
  8841. end
  8842. ]);
  8843. shared.fold(function () {
  8844. annotations.clear(body);
  8845. }, noop);
  8846. };
  8847. var mouseHandlers = InputHandlers.mouse(win, body, isRoot, annotations);
  8848. var keyHandlers = InputHandlers.keyboard(win, body, isRoot, annotations);
  8849. var hasShiftKey = function (event) {
  8850. return event.raw().shiftKey === true;
  8851. };
  8852. var handleResponse = function (event, response) {
  8853. if (!hasShiftKey(event)) {
  8854. return;
  8855. }
  8856. if (response.kill()) {
  8857. event.kill();
  8858. }
  8859. response.selection().each(function (ns) {
  8860. var relative$1 = relative(ns.start(), ns.finish());
  8861. var rng = asLtrRange(win, relative$1);
  8862. editor.selection.setRng(rng);
  8863. });
  8864. };
  8865. var keyup = function (event) {
  8866. var wrappedEvent = wrapEvent(event);
  8867. if (wrappedEvent.raw().shiftKey && SelectionKeys.isNavigation(wrappedEvent.raw().which)) {
  8868. var rng = editor.selection.getRng();
  8869. var start = Element.fromDom(rng.startContainer);
  8870. var end = Element.fromDom(rng.endContainer);
  8871. keyHandlers.keyup(wrappedEvent, start, rng.startOffset, end, rng.endOffset).each(function (response) {
  8872. handleResponse(wrappedEvent, response);
  8873. });
  8874. }
  8875. };
  8876. var keydown = function (event) {
  8877. var wrappedEvent = wrapEvent(event);
  8878. lazyResize().each(function (resize) {
  8879. resize.hideBars();
  8880. });
  8881. var rng = editor.selection.getRng();
  8882. var startContainer = Element.fromDom(editor.selection.getStart());
  8883. var start = Element.fromDom(rng.startContainer);
  8884. var end = Element.fromDom(rng.endContainer);
  8885. var direction = Direction.directionAt(startContainer).isRtl() ? SelectionKeys.rtl : SelectionKeys.ltr;
  8886. keyHandlers.keydown(wrappedEvent, start, rng.startOffset, end, rng.endOffset, direction).each(function (response) {
  8887. handleResponse(wrappedEvent, response);
  8888. });
  8889. lazyResize().each(function (resize) {
  8890. resize.showBars();
  8891. });
  8892. };
  8893. var isMouseEvent = function (event) {
  8894. return event.hasOwnProperty('x') && event.hasOwnProperty('y');
  8895. };
  8896. var wrapEvent = function (event) {
  8897. var target = Element.fromDom(event.target);
  8898. var stop = function () {
  8899. event.stopPropagation();
  8900. };
  8901. var prevent = function () {
  8902. event.preventDefault();
  8903. };
  8904. var kill = compose(prevent, stop);
  8905. return {
  8906. target: constant(target),
  8907. x: constant(isMouseEvent(event) ? event.x : null),
  8908. y: constant(isMouseEvent(event) ? event.y : null),
  8909. stop: stop,
  8910. prevent: prevent,
  8911. kill: kill,
  8912. raw: constant(event)
  8913. };
  8914. };
  8915. var isLeftMouse = function (raw) {
  8916. return raw.button === 0;
  8917. };
  8918. var isLeftButtonPressed = function (raw) {
  8919. if (raw.buttons === undefined) {
  8920. return true;
  8921. }
  8922. return (raw.buttons & 1) !== 0;
  8923. };
  8924. var mouseDown = function (e) {
  8925. if (isLeftMouse(e) && hasInternalTarget(e)) {
  8926. mouseHandlers.mousedown(wrapEvent(e));
  8927. }
  8928. };
  8929. var mouseOver = function (e) {
  8930. if (isLeftButtonPressed(e) && hasInternalTarget(e)) {
  8931. mouseHandlers.mouseover(wrapEvent(e));
  8932. }
  8933. };
  8934. var mouseUp = function (e) {
  8935. if (isLeftMouse(e) && hasInternalTarget(e)) {
  8936. mouseHandlers.mouseup(wrapEvent(e));
  8937. }
  8938. };
  8939. editor.on('mousedown', mouseDown);
  8940. editor.on('mouseover', mouseOver);
  8941. editor.on('mouseup', mouseUp);
  8942. editor.on('keyup', keyup);
  8943. editor.on('keydown', keydown);
  8944. editor.on('NodeChange', syncSelection);
  8945. handlers = Option.some(handlerStruct({
  8946. mousedown: mouseDown,
  8947. mouseover: mouseOver,
  8948. mouseup: mouseUp,
  8949. keyup: keyup,
  8950. keydown: keydown
  8951. }));
  8952. });
  8953. var destroy = function () {
  8954. handlers.each(function (handlers) {
  8955. });
  8956. };
  8957. return {
  8958. clear: annotations.clear,
  8959. destroy: destroy
  8960. };
  8961. }
  8962. var Selections = function (editor) {
  8963. var get = function () {
  8964. var body = getBody$1(editor);
  8965. return TableSelection.retrieve(body, Ephemera.selectedSelector()).fold(function () {
  8966. if (editor.selection.getStart() === undefined) {
  8967. return SelectionTypes.none();
  8968. } else {
  8969. return SelectionTypes.single(editor.selection);
  8970. }
  8971. }, function (cells) {
  8972. return SelectionTypes.multiple(cells);
  8973. });
  8974. };
  8975. return { get: get };
  8976. };
  8977. var SelectionTargets = function (editor, selections) {
  8978. var targets = Cell(Option.none());
  8979. var changeHandlers = Cell([]);
  8980. var findTargets = function () {
  8981. return getSelectionStartCellOrCaption(editor).bind(function (cellOrCaption) {
  8982. var table = TableLookup.table(cellOrCaption);
  8983. return table.map(function (table) {
  8984. if (name(cellOrCaption) === 'caption') {
  8985. return TableTargets.notCell(cellOrCaption);
  8986. } else {
  8987. return TableTargets.forMenu(selections, table, cellOrCaption);
  8988. }
  8989. });
  8990. });
  8991. };
  8992. var resetTargets = function () {
  8993. targets.set(cached(findTargets)());
  8994. each(changeHandlers.get(), function (handler) {
  8995. return handler();
  8996. });
  8997. };
  8998. var onSetup = function (api, isDisabled) {
  8999. var handler = function () {
  9000. return targets.get().fold(function () {
  9001. api.setDisabled(true);
  9002. }, function (targets) {
  9003. api.setDisabled(isDisabled(targets));
  9004. });
  9005. };
  9006. handler();
  9007. changeHandlers.set(changeHandlers.get().concat([handler]));
  9008. return function () {
  9009. changeHandlers.set(filter(changeHandlers.get(), function (h) {
  9010. return h !== handler;
  9011. }));
  9012. };
  9013. };
  9014. var onSetupTable = function (api) {
  9015. return onSetup(api, function (_) {
  9016. return false;
  9017. });
  9018. };
  9019. var onSetupCellOrRow = function (api) {
  9020. return onSetup(api, function (targets) {
  9021. return name(targets.element()) === 'caption';
  9022. });
  9023. };
  9024. var onSetupMergeable = function (api) {
  9025. return onSetup(api, function (targets) {
  9026. return targets.mergable().isNone();
  9027. });
  9028. };
  9029. var onSetupUnmergeable = function (api) {
  9030. return onSetup(api, function (targets) {
  9031. return targets.unmergable().isNone();
  9032. });
  9033. };
  9034. editor.on('NodeChange', resetTargets);
  9035. return {
  9036. onSetupTable: onSetupTable,
  9037. onSetupCellOrRow: onSetupCellOrRow,
  9038. onSetupMergeable: onSetupMergeable,
  9039. onSetupUnmergeable: onSetupUnmergeable,
  9040. resetTargets: resetTargets,
  9041. targets: function () {
  9042. return targets.get();
  9043. }
  9044. };
  9045. };
  9046. var addButtons = function (editor, selectionTargets) {
  9047. editor.ui.registry.addMenuButton('table', {
  9048. tooltip: 'Table',
  9049. icon: 'table',
  9050. fetch: function (callback) {
  9051. return callback('inserttable tableprops deletetable | cell row column');
  9052. }
  9053. });
  9054. var cmd = function (command) {
  9055. return function () {
  9056. return editor.execCommand(command);
  9057. };
  9058. };
  9059. editor.ui.registry.addButton('tableprops', {
  9060. tooltip: 'Table properties',
  9061. onAction: cmd('mceTableProps'),
  9062. icon: 'table',
  9063. onSetup: selectionTargets.onSetupTable
  9064. });
  9065. editor.ui.registry.addButton('tabledelete', {
  9066. tooltip: 'Delete table',
  9067. onAction: cmd('mceTableDelete'),
  9068. icon: 'table-delete-table',
  9069. onSetup: selectionTargets.onSetupTable
  9070. });
  9071. editor.ui.registry.addButton('tablecellprops', {
  9072. tooltip: 'Cell properties',
  9073. onAction: cmd('mceTableCellProps'),
  9074. icon: 'table-cell-properties',
  9075. onSetup: selectionTargets.onSetupCellOrRow
  9076. });
  9077. editor.ui.registry.addButton('tablemergecells', {
  9078. tooltip: 'Merge cells',
  9079. onAction: cmd('mceTableMergeCells'),
  9080. icon: 'table-merge-cells',
  9081. onSetup: selectionTargets.onSetupMergeable
  9082. });
  9083. editor.ui.registry.addButton('tablesplitcells', {
  9084. tooltip: 'Split cell',
  9085. onAction: cmd('mceTableSplitCells'),
  9086. icon: 'table-split-cells',
  9087. onSetup: selectionTargets.onSetupUnmergeable
  9088. });
  9089. editor.ui.registry.addButton('tableinsertrowbefore', {
  9090. tooltip: 'Insert row before',
  9091. onAction: cmd('mceTableInsertRowBefore'),
  9092. icon: 'table-insert-row-above',
  9093. onSetup: selectionTargets.onSetupCellOrRow
  9094. });
  9095. editor.ui.registry.addButton('tableinsertrowafter', {
  9096. tooltip: 'Insert row after',
  9097. onAction: cmd('mceTableInsertRowAfter'),
  9098. icon: 'table-insert-row-after',
  9099. onSetup: selectionTargets.onSetupCellOrRow
  9100. });
  9101. editor.ui.registry.addButton('tabledeleterow', {
  9102. tooltip: 'Delete row',
  9103. onAction: cmd('mceTableDeleteRow'),
  9104. icon: 'table-delete-row',
  9105. onSetup: selectionTargets.onSetupCellOrRow
  9106. });
  9107. editor.ui.registry.addButton('tablerowprops', {
  9108. tooltip: 'Row properties',
  9109. onAction: cmd('mceTableRowProps'),
  9110. icon: 'table-row-properties',
  9111. onSetup: selectionTargets.onSetupCellOrRow
  9112. });
  9113. editor.ui.registry.addButton('tableinsertcolbefore', {
  9114. tooltip: 'Insert column before',
  9115. onAction: cmd('mceTableInsertColBefore'),
  9116. icon: 'table-insert-column-before',
  9117. onSetup: selectionTargets.onSetupCellOrRow
  9118. });
  9119. editor.ui.registry.addButton('tableinsertcolafter', {
  9120. tooltip: 'Insert column after',
  9121. onAction: cmd('mceTableInsertColAfter'),
  9122. icon: 'table-insert-column-after',
  9123. onSetup: selectionTargets.onSetupCellOrRow
  9124. });
  9125. editor.ui.registry.addButton('tabledeletecol', {
  9126. tooltip: 'Delete column',
  9127. onAction: cmd('mceTableDeleteCol'),
  9128. icon: 'table-delete-column',
  9129. onSetup: selectionTargets.onSetupCellOrRow
  9130. });
  9131. editor.ui.registry.addButton('tablecutrow', {
  9132. tooltip: 'Cut row',
  9133. onAction: cmd('mceTableCutRow'),
  9134. icon: 'temporary-placeholder',
  9135. onSetup: selectionTargets.onSetupCellOrRow
  9136. });
  9137. editor.ui.registry.addButton('tablecopyrow', {
  9138. tooltip: 'Copy row',
  9139. onAction: cmd('mceTableCopyRow'),
  9140. icon: 'temporary-placeholder',
  9141. onSetup: selectionTargets.onSetupCellOrRow
  9142. });
  9143. editor.ui.registry.addButton('tablepasterowbefore', {
  9144. tooltip: 'Paste row before',
  9145. onAction: cmd('mceTablePasteRowBefore'),
  9146. icon: 'temporary-placeholder',
  9147. onSetup: selectionTargets.onSetupCellOrRow
  9148. });
  9149. editor.ui.registry.addButton('tablepasterowafter', {
  9150. tooltip: 'Paste row after',
  9151. onAction: cmd('mceTablePasteRowAfter'),
  9152. icon: 'temporary-placeholder',
  9153. onSetup: selectionTargets.onSetupCellOrRow
  9154. });
  9155. editor.ui.registry.addButton('tableinsertdialog', {
  9156. tooltip: 'Insert table',
  9157. onAction: cmd('mceInsertTable'),
  9158. icon: 'table'
  9159. });
  9160. };
  9161. var addToolbars = function (editor) {
  9162. var isTable = function (table) {
  9163. return editor.dom.is(table, 'table') && editor.getBody().contains(table);
  9164. };
  9165. var toolbar = getToolbar(editor);
  9166. if (toolbar.length > 0) {
  9167. editor.ui.registry.addContextToolbar('table', {
  9168. predicate: isTable,
  9169. items: toolbar,
  9170. scope: 'node',
  9171. position: 'node'
  9172. });
  9173. }
  9174. };
  9175. var Buttons = {
  9176. addButtons: addButtons,
  9177. addToolbars: addToolbars
  9178. };
  9179. var addMenuItems = function (editor, selectionTargets) {
  9180. var cmd = function (command) {
  9181. return function () {
  9182. return editor.execCommand(command);
  9183. };
  9184. };
  9185. var insertTableAction = function (_a) {
  9186. var numRows = _a.numRows, numColumns = _a.numColumns;
  9187. editor.undoManager.transact(function () {
  9188. InsertTable.insert(editor, numColumns, numRows);
  9189. });
  9190. editor.addVisual();
  9191. };
  9192. var tableProperties = {
  9193. text: 'Table properties',
  9194. onSetup: selectionTargets.onSetupTable,
  9195. onAction: cmd('mceTableProps')
  9196. };
  9197. var deleteTable = {
  9198. text: 'Delete table',
  9199. icon: 'table-delete-table',
  9200. onSetup: selectionTargets.onSetupTable,
  9201. onAction: cmd('mceTableDelete')
  9202. };
  9203. var row = {
  9204. type: 'nestedmenuitem',
  9205. text: 'Row',
  9206. getSubmenuItems: function () {
  9207. return [
  9208. {
  9209. type: 'menuitem',
  9210. text: 'Insert row before',
  9211. icon: 'table-insert-row-above',
  9212. onAction: cmd('mceTableInsertRowBefore'),
  9213. onSetup: selectionTargets.onSetupCellOrRow
  9214. },
  9215. {
  9216. type: 'menuitem',
  9217. text: 'Insert row after',
  9218. icon: 'table-insert-row-after',
  9219. onAction: cmd('mceTableInsertRowAfter'),
  9220. onSetup: selectionTargets.onSetupCellOrRow
  9221. },
  9222. {
  9223. type: 'menuitem',
  9224. text: 'Delete row',
  9225. icon: 'table-delete-row',
  9226. onAction: cmd('mceTableDeleteRow'),
  9227. onSetup: selectionTargets.onSetupCellOrRow
  9228. },
  9229. {
  9230. type: 'menuitem',
  9231. text: 'Row properties',
  9232. icon: 'table-row-properties',
  9233. onAction: cmd('mceTableRowProps'),
  9234. onSetup: selectionTargets.onSetupCellOrRow
  9235. },
  9236. { type: 'separator' },
  9237. {
  9238. type: 'menuitem',
  9239. text: 'Cut row',
  9240. onAction: cmd('mceTableCutRow'),
  9241. onSetup: selectionTargets.onSetupCellOrRow
  9242. },
  9243. {
  9244. type: 'menuitem',
  9245. text: 'Copy row',
  9246. onAction: cmd('mceTableCopyRow'),
  9247. onSetup: selectionTargets.onSetupCellOrRow
  9248. },
  9249. {
  9250. type: 'menuitem',
  9251. text: 'Paste row before',
  9252. onAction: cmd('mceTablePasteRowBefore'),
  9253. onSetup: selectionTargets.onSetupCellOrRow
  9254. },
  9255. {
  9256. type: 'menuitem',
  9257. text: 'Paste row after',
  9258. onAction: cmd('mceTablePasteRowAfter'),
  9259. onSetup: selectionTargets.onSetupCellOrRow
  9260. }
  9261. ];
  9262. }
  9263. };
  9264. var column = {
  9265. type: 'nestedmenuitem',
  9266. text: 'Column',
  9267. getSubmenuItems: function () {
  9268. return [
  9269. {
  9270. type: 'menuitem',
  9271. text: 'Insert column before',
  9272. icon: 'table-insert-column-before',
  9273. onAction: cmd('mceTableInsertColBefore'),
  9274. onSetup: selectionTargets.onSetupCellOrRow
  9275. },
  9276. {
  9277. type: 'menuitem',
  9278. text: 'Insert column after',
  9279. icon: 'table-insert-column-after',
  9280. onAction: cmd('mceTableInsertColAfter'),
  9281. onSetup: selectionTargets.onSetupCellOrRow
  9282. },
  9283. {
  9284. type: 'menuitem',
  9285. text: 'Delete column',
  9286. icon: 'table-delete-column',
  9287. onAction: cmd('mceTableDeleteCol'),
  9288. onSetup: selectionTargets.onSetupCellOrRow
  9289. }
  9290. ];
  9291. }
  9292. };
  9293. var cell = {
  9294. type: 'nestedmenuitem',
  9295. text: 'Cell',
  9296. getSubmenuItems: function () {
  9297. return [
  9298. {
  9299. type: 'menuitem',
  9300. text: 'Cell properties',
  9301. icon: 'table-cell-properties',
  9302. onAction: cmd('mceTableCellProps'),
  9303. onSetup: selectionTargets.onSetupCellOrRow
  9304. },
  9305. {
  9306. type: 'menuitem',
  9307. text: 'Merge cells',
  9308. icon: 'table-merge-cells',
  9309. onAction: cmd('mceTableMergeCells'),
  9310. onSetup: selectionTargets.onSetupMergeable
  9311. },
  9312. {
  9313. type: 'menuitem',
  9314. text: 'Split cell',
  9315. icon: 'table-split-cells',
  9316. onAction: cmd('mceTableSplitCells'),
  9317. onSetup: selectionTargets.onSetupUnmergeable
  9318. }
  9319. ];
  9320. }
  9321. };
  9322. if (hasTableGrid(editor) === false) {
  9323. editor.ui.registry.addMenuItem('inserttable', {
  9324. text: 'Table',
  9325. icon: 'table',
  9326. onAction: cmd('mceInsertTable')
  9327. });
  9328. } else {
  9329. editor.ui.registry.addNestedMenuItem('inserttable', {
  9330. text: 'Table',
  9331. icon: 'table',
  9332. getSubmenuItems: function () {
  9333. return [{
  9334. type: 'fancymenuitem',
  9335. fancytype: 'inserttable',
  9336. onAction: insertTableAction
  9337. }];
  9338. }
  9339. });
  9340. }
  9341. editor.ui.registry.addMenuItem('inserttabledialog', {
  9342. text: 'Insert table',
  9343. icon: 'table',
  9344. onAction: cmd('mceInsertTable')
  9345. });
  9346. editor.ui.registry.addMenuItem('tableprops', tableProperties);
  9347. editor.ui.registry.addMenuItem('deletetable', deleteTable);
  9348. editor.ui.registry.addNestedMenuItem('row', row);
  9349. editor.ui.registry.addNestedMenuItem('column', column);
  9350. editor.ui.registry.addNestedMenuItem('cell', cell);
  9351. editor.ui.registry.addContextMenu('table', {
  9352. update: function () {
  9353. selectionTargets.resetTargets();
  9354. return selectionTargets.targets().fold(function () {
  9355. return '';
  9356. }, function (targets) {
  9357. if (name(targets.element()) === 'caption') {
  9358. return 'tableprops deletetable';
  9359. } else {
  9360. return 'cell row column | tableprops deletetable';
  9361. }
  9362. });
  9363. }
  9364. });
  9365. };
  9366. var MenuItems = { addMenuItems: addMenuItems };
  9367. var getClipboardRows = function (clipboardRows) {
  9368. return clipboardRows.get().fold(function () {
  9369. return;
  9370. }, function (rows) {
  9371. return map(rows, function (row) {
  9372. return row.dom();
  9373. });
  9374. });
  9375. };
  9376. var setClipboardRows = function (rows, clipboardRows) {
  9377. var sugarRows = map(rows, Element.fromDom);
  9378. clipboardRows.set(Option.from(sugarRows));
  9379. };
  9380. var getApi = function (editor, clipboardRows) {
  9381. return {
  9382. insertTable: function (columns, rows) {
  9383. return InsertTable.insert(editor, columns, rows);
  9384. },
  9385. setClipboardRows: function (rows) {
  9386. return setClipboardRows(rows, clipboardRows);
  9387. },
  9388. getClipboardRows: function () {
  9389. return getClipboardRows(clipboardRows);
  9390. }
  9391. };
  9392. };
  9393. function Plugin(editor) {
  9394. var resizeHandler = ResizeHandler(editor);
  9395. var cellSelection = CellSelection$1(editor, resizeHandler.lazyResize);
  9396. var actions = TableActions(editor, resizeHandler.lazyWire);
  9397. var selections = Selections(editor);
  9398. var selectionTargets = SelectionTargets(editor, selections);
  9399. var clipboardRows = Cell(Option.none());
  9400. Commands.registerCommands(editor, actions, cellSelection, selections, clipboardRows);
  9401. Clipboard.registerEvents(editor, selections, actions, cellSelection);
  9402. MenuItems.addMenuItems(editor, selectionTargets);
  9403. Buttons.addButtons(editor, selectionTargets);
  9404. Buttons.addToolbars(editor);
  9405. editor.on('PreInit', function () {
  9406. editor.serializer.addTempAttr(Ephemera.firstSelected());
  9407. editor.serializer.addTempAttr(Ephemera.lastSelected());
  9408. });
  9409. if (hasTabNavigation(editor)) {
  9410. editor.on('keydown', function (e) {
  9411. TabContext.handle(e, editor, actions, resizeHandler.lazyWire);
  9412. });
  9413. }
  9414. editor.on('remove', function () {
  9415. resizeHandler.destroy();
  9416. cellSelection.destroy();
  9417. });
  9418. return getApi(editor, clipboardRows);
  9419. }
  9420. global.add('table', Plugin);
  9421. function Plugin$1 () {
  9422. }
  9423. return Plugin$1;
  9424. }(window));
  9425. })();