123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943 |
- /**
- * Copyright (c) Tiny Technologies, Inc. All rights reserved.
- * Licensed under the LGPL or a commercial license.
- * For LGPL see License.txt in the project root for license information.
- * For commercial licenses see https://www.tiny.cloud/
- *
- * Version: 5.3.0 (2020-05-21)
- */
- (function (domGlobals) {
- 'use strict';
- var Cell = function (initial) {
- var value = initial;
- var get = function () {
- return value;
- };
- var set = function (v) {
- value = v;
- };
- return {
- get: get,
- set: set
- };
- };
- var noop = function () {
- };
- var compose = function (fa, fb) {
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- return fa(fb.apply(null, args));
- };
- };
- var constant = function (value) {
- return function () {
- return value;
- };
- };
- var identity = function (x) {
- return x;
- };
- function curry(fn) {
- var initialArgs = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- initialArgs[_i - 1] = arguments[_i];
- }
- return function () {
- var restArgs = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- restArgs[_i] = arguments[_i];
- }
- var all = initialArgs.concat(restArgs);
- return fn.apply(null, all);
- };
- }
- var not = function (f) {
- return function (t) {
- return !f(t);
- };
- };
- var die = function (msg) {
- return function () {
- throw new Error(msg);
- };
- };
- var never = constant(false);
- var always = constant(true);
- var none = function () {
- return NONE;
- };
- var NONE = function () {
- var eq = function (o) {
- return o.isNone();
- };
- var call = function (thunk) {
- return thunk();
- };
- var id = function (n) {
- return n;
- };
- var me = {
- fold: function (n, _s) {
- return n();
- },
- is: never,
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function (msg) {
- throw new Error(msg || 'error: getOrDie called on none.');
- },
- getOrNull: constant(null),
- getOrUndefined: constant(undefined),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: none,
- equals: eq,
- equals_: eq,
- toArray: function () {
- return [];
- },
- toString: constant('none()')
- };
- return me;
- }();
- var some = function (a) {
- var constant_a = constant(a);
- var self = function () {
- return me;
- };
- var bind = function (f) {
- return f(a);
- };
- var me = {
- fold: function (n, s) {
- return s(a);
- },
- is: function (v) {
- return a === v;
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function (f) {
- return some(f(a));
- },
- each: function (f) {
- f(a);
- },
- bind: bind,
- exists: bind,
- forall: bind,
- filter: function (f) {
- return f(a) ? me : NONE;
- },
- toArray: function () {
- return [a];
- },
- toString: function () {
- return 'some(' + a + ')';
- },
- equals: function (o) {
- return o.is(a);
- },
- equals_: function (o, elementEq) {
- return o.fold(never, function (b) {
- return elementEq(a, b);
- });
- }
- };
- return me;
- };
- var from = function (value) {
- return value === null || value === undefined ? NONE : some(value);
- };
- var Option = {
- some: some,
- none: none,
- from: from
- };
- var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
- var typeOf = function (x) {
- var t = typeof x;
- if (x === null) {
- return 'null';
- } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
- return 'array';
- } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
- return 'string';
- } else {
- return t;
- }
- };
- var isType = function (type) {
- return function (value) {
- return typeOf(value) === type;
- };
- };
- var isSimpleType = function (type) {
- return function (value) {
- return typeof value === type;
- };
- };
- var isString = isType('string');
- var isArray = isType('array');
- var isBoolean = isSimpleType('boolean');
- var isFunction = isSimpleType('function');
- var isNumber = isSimpleType('number');
- var nativeSlice = Array.prototype.slice;
- var nativeIndexOf = Array.prototype.indexOf;
- var nativePush = Array.prototype.push;
- var rawIndexOf = function (ts, t) {
- return nativeIndexOf.call(ts, t);
- };
- var contains = function (xs, x) {
- return rawIndexOf(xs, x) > -1;
- };
- var exists = function (xs, pred) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return true;
- }
- }
- return false;
- };
- var map = function (xs, f) {
- var len = xs.length;
- var r = new Array(len);
- for (var i = 0; i < len; i++) {
- var x = xs[i];
- r[i] = f(x, i);
- }
- return r;
- };
- var each = function (xs, f) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- f(x, i);
- }
- };
- var eachr = function (xs, f) {
- for (var i = xs.length - 1; i >= 0; i--) {
- var x = xs[i];
- f(x, i);
- }
- };
- var filter = function (xs, pred) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- r.push(x);
- }
- }
- return r;
- };
- var foldr = function (xs, f, acc) {
- eachr(xs, function (x) {
- acc = f(acc, x);
- });
- return acc;
- };
- var foldl = function (xs, f, acc) {
- each(xs, function (x) {
- acc = f(acc, x);
- });
- return acc;
- };
- var findUntil = function (xs, pred, until) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return Option.some(x);
- } else if (until(x, i)) {
- break;
- }
- }
- return Option.none();
- };
- var find = function (xs, pred) {
- return findUntil(xs, pred, never);
- };
- var findIndex = function (xs, pred) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return Option.some(i);
- }
- }
- return Option.none();
- };
- var flatten = function (xs) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; ++i) {
- if (!isArray(xs[i])) {
- throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- var bind = function (xs, f) {
- return flatten(map(xs, f));
- };
- var forall = function (xs, pred) {
- for (var i = 0, len = xs.length; i < len; ++i) {
- var x = xs[i];
- if (pred(x, i) !== true) {
- return false;
- }
- }
- return true;
- };
- var reverse = function (xs) {
- var r = nativeSlice.call(xs, 0);
- r.reverse();
- return r;
- };
- var last = function (xs) {
- return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
- };
- var findMap = function (arr, f) {
- for (var i = 0; i < arr.length; i++) {
- var r = f(arr[i], i);
- if (r.isSome()) {
- return r;
- }
- }
- return Option.none();
- };
- var keys = Object.keys;
- var hasOwnProperty = Object.hasOwnProperty;
- var each$1 = function (obj, f) {
- var props = keys(obj);
- for (var k = 0, len = props.length; k < len; k++) {
- var i = props[k];
- var x = obj[i];
- f(x, i);
- }
- };
- var map$1 = function (obj, f) {
- return tupleMap(obj, function (x, i) {
- return {
- k: i,
- v: f(x, i)
- };
- });
- };
- var tupleMap = function (obj, f) {
- var r = {};
- each$1(obj, function (x, i) {
- var tuple = f(x, i);
- r[tuple.k] = tuple.v;
- });
- return r;
- };
- var get = function (obj, key) {
- return has(obj, key) ? Option.from(obj[key]) : Option.none();
- };
- var has = function (obj, key) {
- return hasOwnProperty.call(obj, key);
- };
- var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
- var COMMENT = 8;
- var DOCUMENT = 9;
- var ELEMENT = 1;
- var TEXT = 3;
- var name = function (element) {
- var r = element.dom().nodeName;
- return r.toLowerCase();
- };
- var type = function (element) {
- return element.dom().nodeType;
- };
- var isType$1 = function (t) {
- return function (element) {
- return type(element) === t;
- };
- };
- var isComment = function (element) {
- return type(element) === COMMENT || name(element) === '#comment';
- };
- var isElement = isType$1(ELEMENT);
- var isText = isType$1(TEXT);
- var rawSet = function (dom, key, value) {
- if (isString(value) || isBoolean(value) || isNumber(value)) {
- dom.setAttribute(key, value + '');
- } else {
- domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
- throw new Error('Attribute value was not simple');
- }
- };
- var set = function (element, key, value) {
- rawSet(element.dom(), key, value);
- };
- var setAll = function (element, attrs) {
- var dom = element.dom();
- each$1(attrs, function (v, k) {
- rawSet(dom, k, v);
- });
- };
- var get$1 = function (element, key) {
- var v = element.dom().getAttribute(key);
- return v === null ? undefined : v;
- };
- var getOpt = function (element, key) {
- return Option.from(get$1(element, key));
- };
- var has$1 = function (element, key) {
- var dom = element.dom();
- return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
- };
- var remove = function (element, key) {
- element.dom().removeAttribute(key);
- };
- var clone = function (element) {
- return foldl(element.dom().attributes, function (acc, attr) {
- acc[attr.name] = attr.value;
- return acc;
- }, {});
- };
- var checkRange = function (str, substr, start) {
- return substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
- };
- var contains$1 = function (str, substr) {
- return str.indexOf(substr) !== -1;
- };
- var startsWith = function (str, prefix) {
- return checkRange(str, prefix, 0);
- };
- var endsWith = function (str, suffix) {
- return checkRange(str, suffix, str.length - suffix.length);
- };
- var blank = function (r) {
- return function (s) {
- return s.replace(r, '');
- };
- };
- var trim = blank(/^\s+|\s+$/g);
- var isSupported = function (dom) {
- return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
- };
- var fromHtml = function (html, scope) {
- var doc = scope || domGlobals.document;
- var div = doc.createElement('div');
- div.innerHTML = html;
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
- domGlobals.console.error('HTML does not have a single root node', html);
- throw new Error('HTML must have a single root node');
- }
- return fromDom(div.childNodes[0]);
- };
- var fromTag = function (tag, scope) {
- var doc = scope || domGlobals.document;
- var node = doc.createElement(tag);
- return fromDom(node);
- };
- var fromText = function (text, scope) {
- var doc = scope || domGlobals.document;
- var node = doc.createTextNode(text);
- return fromDom(node);
- };
- var fromDom = function (node) {
- if (node === null || node === undefined) {
- throw new Error('Node cannot be null or undefined');
- }
- return { dom: constant(node) };
- };
- var fromPoint = function (docElm, x, y) {
- var doc = docElm.dom();
- return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
- };
- var Element = {
- fromHtml: fromHtml,
- fromTag: fromTag,
- fromText: fromText,
- fromDom: fromDom,
- fromPoint: fromPoint
- };
- var inBody = function (element) {
- var dom = isText(element) ? element.dom().parentNode : element.dom();
- return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
- };
- var body = function () {
- return getBody(Element.fromDom(domGlobals.document));
- };
- var getBody = function (doc) {
- var b = doc.dom().body;
- if (b === null || b === undefined) {
- throw new Error('Body is not available yet');
- }
- return Element.fromDom(b);
- };
- var internalSet = function (dom, property, value) {
- if (!isString(value)) {
- domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
- throw new Error('CSS value must be a string: ' + value);
- }
- if (isSupported(dom)) {
- dom.style.setProperty(property, value);
- }
- };
- var internalRemove = function (dom, property) {
- if (isSupported(dom)) {
- dom.style.removeProperty(property);
- }
- };
- var set$1 = function (element, property, value) {
- var dom = element.dom();
- internalSet(dom, property, value);
- };
- var setAll$1 = function (element, css) {
- var dom = element.dom();
- each$1(css, function (v, k) {
- internalSet(dom, k, v);
- });
- };
- var get$2 = function (element, property) {
- var dom = element.dom();
- var styles = domGlobals.window.getComputedStyle(dom);
- var r = styles.getPropertyValue(property);
- return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
- };
- var getUnsafeProperty = function (dom, property) {
- return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
- };
- var getRaw = function (element, property) {
- var dom = element.dom();
- var raw = getUnsafeProperty(dom, property);
- return Option.from(raw).filter(function (r) {
- return r.length > 0;
- });
- };
- var remove$1 = function (element, property) {
- var dom = element.dom();
- internalRemove(dom, property);
- if (getOpt(element, 'style').map(trim).is('')) {
- remove(element, 'style');
- }
- };
- var copy = function (source, target) {
- var sourceDom = source.dom();
- var targetDom = target.dom();
- if (isSupported(sourceDom) && isSupported(targetDom)) {
- targetDom.style.cssText = sourceDom.style.cssText;
- }
- };
- var compareDocumentPosition = function (a, b, match) {
- return (a.compareDocumentPosition(b) & match) !== 0;
- };
- var documentPositionContainedBy = function (a, b) {
- return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
- };
- var __assign = function () {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s)
- if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var cached = function (f) {
- var called = false;
- var r;
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (!called) {
- called = true;
- r = f.apply(null, args);
- }
- return r;
- };
- };
- var firstMatch = function (regexes, s) {
- for (var i = 0; i < regexes.length; i++) {
- var x = regexes[i];
- if (x.test(s)) {
- return x;
- }
- }
- return undefined;
- };
- var find$1 = function (regexes, agent) {
- var r = firstMatch(regexes, agent);
- if (!r) {
- return {
- major: 0,
- minor: 0
- };
- }
- var group = function (i) {
- return Number(agent.replace(r, '$' + i));
- };
- return nu(group(1), group(2));
- };
- var detect = function (versionRegexes, agent) {
- var cleanedAgent = String(agent).toLowerCase();
- if (versionRegexes.length === 0) {
- return unknown();
- }
- return find$1(versionRegexes, cleanedAgent);
- };
- var unknown = function () {
- return nu(0, 0);
- };
- var nu = function (major, minor) {
- return {
- major: major,
- minor: minor
- };
- };
- var Version = {
- nu: nu,
- detect: detect,
- unknown: unknown
- };
- var edge = 'Edge';
- var chrome = 'Chrome';
- var ie = 'IE';
- var opera = 'Opera';
- var firefox = 'Firefox';
- var safari = 'Safari';
- var unknown$1 = function () {
- return nu$1({
- current: undefined,
- version: Version.unknown()
- });
- };
- var nu$1 = function (info) {
- var current = info.current;
- var version = info.version;
- var isBrowser = function (name) {
- return function () {
- return current === name;
- };
- };
- return {
- current: current,
- version: version,
- isEdge: isBrowser(edge),
- isChrome: isBrowser(chrome),
- isIE: isBrowser(ie),
- isOpera: isBrowser(opera),
- isFirefox: isBrowser(firefox),
- isSafari: isBrowser(safari)
- };
- };
- var Browser = {
- unknown: unknown$1,
- nu: nu$1,
- edge: constant(edge),
- chrome: constant(chrome),
- ie: constant(ie),
- opera: constant(opera),
- firefox: constant(firefox),
- safari: constant(safari)
- };
- var windows = 'Windows';
- var ios = 'iOS';
- var android = 'Android';
- var linux = 'Linux';
- var osx = 'OSX';
- var solaris = 'Solaris';
- var freebsd = 'FreeBSD';
- var chromeos = 'ChromeOS';
- var unknown$2 = function () {
- return nu$2({
- current: undefined,
- version: Version.unknown()
- });
- };
- var nu$2 = function (info) {
- var current = info.current;
- var version = info.version;
- var isOS = function (name) {
- return function () {
- return current === name;
- };
- };
- return {
- current: current,
- version: version,
- isWindows: isOS(windows),
- isiOS: isOS(ios),
- isAndroid: isOS(android),
- isOSX: isOS(osx),
- isLinux: isOS(linux),
- isSolaris: isOS(solaris),
- isFreeBSD: isOS(freebsd),
- isChromeOS: isOS(chromeos)
- };
- };
- var OperatingSystem = {
- unknown: unknown$2,
- nu: nu$2,
- windows: constant(windows),
- ios: constant(ios),
- android: constant(android),
- linux: constant(linux),
- osx: constant(osx),
- solaris: constant(solaris),
- freebsd: constant(freebsd),
- chromeos: constant(chromeos)
- };
- var DeviceType = function (os, browser, userAgent, mediaMatch) {
- var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
- var isiPhone = os.isiOS() && !isiPad;
- var isMobile = os.isiOS() || os.isAndroid();
- var isTouch = isMobile || mediaMatch('(pointer:coarse)');
- var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
- var isPhone = isiPhone || isMobile && !isTablet;
- var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
- var isDesktop = !isPhone && !isTablet && !iOSwebview;
- return {
- isiPad: constant(isiPad),
- isiPhone: constant(isiPhone),
- isTablet: constant(isTablet),
- isPhone: constant(isPhone),
- isTouch: constant(isTouch),
- isAndroid: os.isAndroid,
- isiOS: os.isiOS,
- isWebView: constant(iOSwebview),
- isDesktop: constant(isDesktop)
- };
- };
- var detect$1 = function (candidates, userAgent) {
- var agent = String(userAgent).toLowerCase();
- return find(candidates, function (candidate) {
- return candidate.search(agent);
- });
- };
- var detectBrowser = function (browsers, userAgent) {
- return detect$1(browsers, userAgent).map(function (browser) {
- var version = Version.detect(browser.versionRegexes, userAgent);
- return {
- current: browser.name,
- version: version
- };
- });
- };
- var detectOs = function (oses, userAgent) {
- return detect$1(oses, userAgent).map(function (os) {
- var version = Version.detect(os.versionRegexes, userAgent);
- return {
- current: os.name,
- version: version
- };
- });
- };
- var UaString = {
- detectBrowser: detectBrowser,
- detectOs: detectOs
- };
- var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
- var checkContains = function (target) {
- return function (uastring) {
- return contains$1(uastring, target);
- };
- };
- var browsers = [
- {
- name: 'Edge',
- versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
- search: function (uastring) {
- return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
- }
- },
- {
- name: 'Chrome',
- versionRegexes: [
- /.*?chrome\/([0-9]+)\.([0-9]+).*/,
- normalVersionRegex
- ],
- search: function (uastring) {
- return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
- }
- },
- {
- name: 'IE',
- versionRegexes: [
- /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
- /.*?rv:([0-9]+)\.([0-9]+).*/
- ],
- search: function (uastring) {
- return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
- }
- },
- {
- name: 'Opera',
- versionRegexes: [
- normalVersionRegex,
- /.*?opera\/([0-9]+)\.([0-9]+).*/
- ],
- search: checkContains('opera')
- },
- {
- name: 'Firefox',
- versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
- search: checkContains('firefox')
- },
- {
- name: 'Safari',
- versionRegexes: [
- normalVersionRegex,
- /.*?cpu os ([0-9]+)_([0-9]+).*/
- ],
- search: function (uastring) {
- return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
- }
- }
- ];
- var oses = [
- {
- name: 'Windows',
- search: checkContains('win'),
- versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'iOS',
- search: function (uastring) {
- return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
- },
- versionRegexes: [
- /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
- /.*cpu os ([0-9]+)_([0-9]+).*/,
- /.*cpu iphone os ([0-9]+)_([0-9]+).*/
- ]
- },
- {
- name: 'Android',
- search: checkContains('android'),
- versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'OSX',
- search: checkContains('mac os x'),
- versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
- },
- {
- name: 'Linux',
- search: checkContains('linux'),
- versionRegexes: []
- },
- {
- name: 'Solaris',
- search: checkContains('sunos'),
- versionRegexes: []
- },
- {
- name: 'FreeBSD',
- search: checkContains('freebsd'),
- versionRegexes: []
- },
- {
- name: 'ChromeOS',
- search: checkContains('cros'),
- versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
- }
- ];
- var PlatformInfo = {
- browsers: constant(browsers),
- oses: constant(oses)
- };
- var detect$2 = function (userAgent, mediaMatch) {
- var browsers = PlatformInfo.browsers();
- var oses = PlatformInfo.oses();
- var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
- var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
- var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
- return {
- browser: browser,
- os: os,
- deviceType: deviceType
- };
- };
- var PlatformDetection = { detect: detect$2 };
- var mediaMatch = function (query) {
- return domGlobals.window.matchMedia(query).matches;
- };
- var platform = cached(function () {
- return PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch);
- });
- var detect$3 = function () {
- return platform();
- };
- var ELEMENT$1 = ELEMENT;
- var DOCUMENT$1 = DOCUMENT;
- var is = function (element, selector) {
- var dom = element.dom();
- if (dom.nodeType !== ELEMENT$1) {
- return false;
- } else {
- var elem = dom;
- if (elem.matches !== undefined) {
- return elem.matches(selector);
- } else if (elem.msMatchesSelector !== undefined) {
- return elem.msMatchesSelector(selector);
- } else if (elem.webkitMatchesSelector !== undefined) {
- return elem.webkitMatchesSelector(selector);
- } else if (elem.mozMatchesSelector !== undefined) {
- return elem.mozMatchesSelector(selector);
- } else {
- throw new Error('Browser lacks native selectors');
- }
- }
- };
- var bypassSelector = function (dom) {
- return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
- };
- var all = function (selector, scope) {
- var base = scope === undefined ? domGlobals.document : scope.dom();
- return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
- };
- var one = function (selector, scope) {
- var base = scope === undefined ? domGlobals.document : scope.dom();
- return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
- };
- var eq = function (e1, e2) {
- return e1.dom() === e2.dom();
- };
- var regularContains = function (e1, e2) {
- var d1 = e1.dom();
- var d2 = e2.dom();
- return d1 === d2 ? false : d1.contains(d2);
- };
- var ieContains = function (e1, e2) {
- return documentPositionContainedBy(e1.dom(), e2.dom());
- };
- var contains$2 = function (e1, e2) {
- return detect$3().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
- };
- var is$1 = is;
- var owner = function (element) {
- return Element.fromDom(element.dom().ownerDocument);
- };
- var defaultView = function (element) {
- return Element.fromDom(element.dom().ownerDocument.defaultView);
- };
- var parent = function (element) {
- return Option.from(element.dom().parentNode).map(Element.fromDom);
- };
- var parents = function (element, isRoot) {
- var stop = isFunction(isRoot) ? isRoot : never;
- var dom = element.dom();
- var ret = [];
- while (dom.parentNode !== null && dom.parentNode !== undefined) {
- var rawParent = dom.parentNode;
- var p = Element.fromDom(rawParent);
- ret.push(p);
- if (stop(p) === true) {
- break;
- } else {
- dom = rawParent;
- }
- }
- return ret;
- };
- var prevSibling = function (element) {
- return Option.from(element.dom().previousSibling).map(Element.fromDom);
- };
- var nextSibling = function (element) {
- return Option.from(element.dom().nextSibling).map(Element.fromDom);
- };
- var children = function (element) {
- return map(element.dom().childNodes, Element.fromDom);
- };
- var child = function (element, index) {
- var cs = element.dom().childNodes;
- return Option.from(cs[index]).map(Element.fromDom);
- };
- var firstChild = function (element) {
- return child(element, 0);
- };
- var before = function (marker, element) {
- var parent$1 = parent(marker);
- parent$1.each(function (v) {
- v.dom().insertBefore(element.dom(), marker.dom());
- });
- };
- var after = function (marker, element) {
- var sibling = nextSibling(marker);
- sibling.fold(function () {
- var parent$1 = parent(marker);
- parent$1.each(function (v) {
- append(v, element);
- });
- }, function (v) {
- before(v, element);
- });
- };
- var prepend = function (parent, element) {
- var firstChild$1 = firstChild(parent);
- firstChild$1.fold(function () {
- append(parent, element);
- }, function (v) {
- parent.dom().insertBefore(element.dom(), v.dom());
- });
- };
- var append = function (parent, element) {
- parent.dom().appendChild(element.dom());
- };
- var wrap = function (element, wrapper) {
- before(element, wrapper);
- append(wrapper, element);
- };
- var before$1 = function (marker, elements) {
- each(elements, function (x) {
- before(marker, x);
- });
- };
- var after$1 = function (marker, elements) {
- each(elements, function (x, i) {
- var e = i === 0 ? marker : elements[i - 1];
- after(e, x);
- });
- };
- var append$1 = function (parent, elements) {
- each(elements, function (x) {
- append(parent, x);
- });
- };
- var empty = function (element) {
- element.dom().textContent = '';
- each(children(element), function (rogue) {
- remove$2(rogue);
- });
- };
- var remove$2 = function (element) {
- var dom = element.dom();
- if (dom.parentNode !== null) {
- dom.parentNode.removeChild(dom);
- }
- };
- var unwrap = function (wrapper) {
- var children$1 = children(wrapper);
- if (children$1.length > 0) {
- before$1(wrapper, children$1);
- }
- remove$2(wrapper);
- };
- var grid = function (rows, columns) {
- return {
- rows: constant(rows),
- columns: constant(columns)
- };
- };
- var address = function (row, column) {
- return {
- row: constant(row),
- column: constant(column)
- };
- };
- var detail = function (element, rowspan, colspan) {
- return {
- element: constant(element),
- rowspan: constant(rowspan),
- colspan: constant(colspan)
- };
- };
- var detailnew = function (element, rowspan, colspan, isNew) {
- return {
- element: constant(element),
- rowspan: constant(rowspan),
- colspan: constant(colspan),
- isNew: constant(isNew)
- };
- };
- var extended = function (element, rowspan, colspan, row, column) {
- return {
- element: constant(element),
- rowspan: constant(rowspan),
- colspan: constant(colspan),
- row: constant(row),
- column: constant(column)
- };
- };
- var rowdata = function (element, cells, section) {
- return {
- element: constant(element),
- cells: constant(cells),
- section: constant(section)
- };
- };
- var elementnew = function (element, isNew) {
- return {
- element: constant(element),
- isNew: constant(isNew)
- };
- };
- var rowdatanew = function (element, cells, section, isNew) {
- return {
- element: constant(element),
- cells: constant(cells),
- section: constant(section),
- isNew: constant(isNew)
- };
- };
- var rowcells = function (cells, section) {
- return {
- cells: constant(cells),
- section: constant(section)
- };
- };
- var rowdetails = function (details, section) {
- return {
- details: constant(details),
- section: constant(section)
- };
- };
- var bounds = function (startRow, startCol, finishRow, finishCol) {
- return {
- startRow: constant(startRow),
- startCol: constant(startCol),
- finishRow: constant(finishRow),
- finishCol: constant(finishCol)
- };
- };
- var ancestors = function (scope, predicate, isRoot) {
- return filter(parents(scope, isRoot), predicate);
- };
- var children$1 = function (scope, predicate) {
- return filter(children(scope), predicate);
- };
- var descendants = function (scope, predicate) {
- var result = [];
- each(children(scope), function (x) {
- if (predicate(x)) {
- result = result.concat([x]);
- }
- result = result.concat(descendants(x, predicate));
- });
- return result;
- };
- var ancestors$1 = function (scope, selector, isRoot) {
- return ancestors(scope, function (e) {
- return is(e, selector);
- }, isRoot);
- };
- var children$2 = function (scope, selector) {
- return children$1(scope, function (e) {
- return is(e, selector);
- });
- };
- var descendants$1 = function (scope, selector) {
- return all(selector, scope);
- };
- function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
- return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
- }
- var ancestor = function (scope, predicate, isRoot) {
- var element = scope.dom();
- var stop = isFunction(isRoot) ? isRoot : constant(false);
- while (element.parentNode) {
- element = element.parentNode;
- var el = Element.fromDom(element);
- if (predicate(el)) {
- return Option.some(el);
- } else if (stop(el)) {
- break;
- }
- }
- return Option.none();
- };
- var closest = function (scope, predicate, isRoot) {
- var is = function (s, test) {
- return test(s);
- };
- return ClosestOrAncestor(is, ancestor, scope, predicate, isRoot);
- };
- var child$1 = function (scope, predicate) {
- var pred = function (node) {
- return predicate(Element.fromDom(node));
- };
- var result = find(scope.dom().childNodes, pred);
- return result.map(Element.fromDom);
- };
- var descendant = function (scope, predicate) {
- var descend = function (node) {
- for (var i = 0; i < node.childNodes.length; i++) {
- var child_1 = Element.fromDom(node.childNodes[i]);
- if (predicate(child_1)) {
- return Option.some(child_1);
- }
- var res = descend(node.childNodes[i]);
- if (res.isSome()) {
- return res;
- }
- }
- return Option.none();
- };
- return descend(scope.dom());
- };
- var ancestor$1 = function (scope, selector, isRoot) {
- return ancestor(scope, function (e) {
- return is(e, selector);
- }, isRoot);
- };
- var child$2 = function (scope, selector) {
- return child$1(scope, function (e) {
- return is(e, selector);
- });
- };
- var descendant$1 = function (scope, selector) {
- return one(selector, scope);
- };
- var closest$1 = function (scope, selector, isRoot) {
- var is$1 = function (element, selector) {
- return is(element, selector);
- };
- return ClosestOrAncestor(is$1, ancestor$1, scope, selector, isRoot);
- };
- var getAttrValue = function (cell, name, fallback) {
- if (fallback === void 0) {
- fallback = 0;
- }
- return getOpt(cell, name).map(function (value) {
- return parseInt(value, 10);
- }).getOr(fallback);
- };
- var getSpan = function (cell, type) {
- return getAttrValue(cell, type, 1);
- };
- var hasColspan = function (cell) {
- return getSpan(cell, 'colspan') > 1;
- };
- var hasRowspan = function (cell) {
- return getSpan(cell, 'rowspan') > 1;
- };
- var getCssValue = function (element, property) {
- return parseInt(get$2(element, property), 10);
- };
- var minWidth = constant(10);
- var minHeight = constant(10);
- var firstLayer = function (scope, selector) {
- return filterFirstLayer(scope, selector, constant(true));
- };
- var filterFirstLayer = function (scope, selector, predicate) {
- return bind(children(scope), function (x) {
- return is(x, selector) ? predicate(x) ? [x] : [] : filterFirstLayer(x, selector, predicate);
- });
- };
- var lookup = function (tags, element, isRoot) {
- if (isRoot === void 0) {
- isRoot = never;
- }
- if (isRoot(element)) {
- return Option.none();
- }
- if (contains(tags, name(element))) {
- return Option.some(element);
- }
- var isRootOrUpperTable = function (elm) {
- return is(elm, 'table') || isRoot(elm);
- };
- return ancestor$1(element, tags.join(','), isRootOrUpperTable);
- };
- var cell = function (element, isRoot) {
- return lookup([
- 'td',
- 'th'
- ], element, isRoot);
- };
- var cells = function (ancestor) {
- return firstLayer(ancestor, 'th,td');
- };
- var neighbours = function (selector, element) {
- return parent(element).map(function (parent) {
- return children$2(parent, selector);
- });
- };
- var neighbourCells = curry(neighbours, 'th,td');
- var neighbourRows = curry(neighbours, 'tr');
- var table = function (element, isRoot) {
- return closest$1(element, 'table', isRoot);
- };
- var rows = function (ancestor) {
- return firstLayer(ancestor, 'tr');
- };
- var fromTable = function (table) {
- var rows$1 = rows(table);
- return map(rows$1, function (row) {
- var element = row;
- var parent$1 = parent(element);
- var parentSection = parent$1.map(function (p) {
- var parentName = name(p);
- return parentName === 'tfoot' || parentName === 'thead' || parentName === 'tbody' ? parentName : 'tbody';
- }).getOr('tbody');
- var cells$1 = map(cells(row), function (cell) {
- var rowspan = getAttrValue(cell, 'rowspan', 1);
- var colspan = getAttrValue(cell, 'colspan', 1);
- return detail(cell, rowspan, colspan);
- });
- return rowdata(element, cells$1, parentSection);
- });
- };
- var fromPastedRows = function (rows, example) {
- return map(rows, function (row) {
- var cells$1 = map(cells(row), function (cell) {
- var rowspan = getAttrValue(cell, 'rowspan', 1);
- var colspan = getAttrValue(cell, 'colspan', 1);
- return detail(cell, rowspan, colspan);
- });
- return rowdata(row, cells$1, example.section());
- });
- };
- var key = function (row, column) {
- return row + ',' + column;
- };
- var getAt = function (warehouse, row, column) {
- var raw = warehouse.access[key(row, column)];
- return raw !== undefined ? Option.some(raw) : Option.none();
- };
- var findItem = function (warehouse, item, comparator) {
- var filtered = filterItems(warehouse, function (detail) {
- return comparator(item, detail.element());
- });
- return filtered.length > 0 ? Option.some(filtered[0]) : Option.none();
- };
- var filterItems = function (warehouse, predicate) {
- var all = bind(warehouse.all, function (r) {
- return r.cells();
- });
- return filter(all, predicate);
- };
- var generate = function (list) {
- var access = {};
- var cells = [];
- var maxRows = list.length;
- var maxColumns = 0;
- each(list, function (details, r) {
- var currentRow = [];
- each(details.cells(), function (detail) {
- var start = 0;
- while (access[key(r, start)] !== undefined) {
- start++;
- }
- var current = extended(detail.element(), detail.rowspan(), detail.colspan(), r, start);
- for (var i = 0; i < detail.colspan(); i++) {
- for (var j = 0; j < detail.rowspan(); j++) {
- var cr = r + j;
- var cc = start + i;
- var newpos = key(cr, cc);
- access[newpos] = current;
- maxColumns = Math.max(maxColumns, cc + 1);
- }
- }
- currentRow.push(current);
- });
- cells.push(rowdata(details.element(), currentRow, details.section()));
- });
- var grid$1 = grid(maxRows, maxColumns);
- return {
- grid: grid$1,
- access: access,
- all: cells
- };
- };
- var justCells = function (warehouse) {
- var rows = map(warehouse.all, function (w) {
- return w.cells();
- });
- return flatten(rows);
- };
- var Warehouse = {
- generate: generate,
- getAt: getAt,
- findItem: findItem,
- filterItems: filterItems,
- justCells: justCells
- };
- var statsStruct = function (minRow, minCol, maxRow, maxCol) {
- return {
- minRow: minRow,
- minCol: minCol,
- maxRow: maxRow,
- maxCol: maxCol
- };
- };
- var findSelectedStats = function (house, isSelected) {
- var totalColumns = house.grid.columns();
- var totalRows = house.grid.rows();
- var minRow = totalRows;
- var minCol = totalColumns;
- var maxRow = 0;
- var maxCol = 0;
- each$1(house.access, function (detail) {
- if (isSelected(detail)) {
- var startRow = detail.row();
- var endRow = startRow + detail.rowspan() - 1;
- var startCol = detail.column();
- var endCol = startCol + detail.colspan() - 1;
- if (startRow < minRow) {
- minRow = startRow;
- } else if (endRow > maxRow) {
- maxRow = endRow;
- }
- if (startCol < minCol) {
- minCol = startCol;
- } else if (endCol > maxCol) {
- maxCol = endCol;
- }
- }
- });
- return statsStruct(minRow, minCol, maxRow, maxCol);
- };
- var makeCell = function (list, seenSelected, rowIndex) {
- var row = list[rowIndex].element();
- var td = Element.fromTag('td');
- append(td, Element.fromTag('br'));
- var f = seenSelected ? append : prepend;
- f(row, td);
- };
- var fillInGaps = function (list, house, stats, isSelected) {
- var totalColumns = house.grid.columns();
- var totalRows = house.grid.rows();
- for (var i = 0; i < totalRows; i++) {
- var seenSelected = false;
- for (var j = 0; j < totalColumns; j++) {
- if (!(i < stats.minRow || i > stats.maxRow || j < stats.minCol || j > stats.maxCol)) {
- var needCell = Warehouse.getAt(house, i, j).filter(isSelected).isNone();
- if (needCell) {
- makeCell(list, seenSelected, i);
- } else {
- seenSelected = true;
- }
- }
- }
- }
- };
- var clean = function (table, stats) {
- var emptyRows = filter(firstLayer(table, 'tr'), function (row) {
- return row.dom().childElementCount === 0;
- });
- each(emptyRows, remove$2);
- if (stats.minCol === stats.maxCol || stats.minRow === stats.maxRow) {
- each(firstLayer(table, 'th,td'), function (cell) {
- remove(cell, 'rowspan');
- remove(cell, 'colspan');
- });
- }
- remove(table, 'width');
- remove(table, 'height');
- remove$1(table, 'width');
- remove$1(table, 'height');
- };
- var extract = function (table, selectedSelector) {
- var isSelected = function (detail) {
- return is(detail.element(), selectedSelector);
- };
- var list = fromTable(table);
- var house = Warehouse.generate(list);
- var stats = findSelectedStats(house, isSelected);
- var selector = 'th:not(' + selectedSelector + ')' + ',td:not(' + selectedSelector + ')';
- var unselectedCells = filterFirstLayer(table, 'th,td', function (cell) {
- return is(cell, selector);
- });
- each(unselectedCells, remove$2);
- fillInGaps(list, house, stats, isSelected);
- clean(table, stats);
- return table;
- };
- var nbsp = '\xA0';
- function NodeValue (is, name) {
- var get = function (element) {
- if (!is(element)) {
- throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
- }
- return getOption(element).getOr('');
- };
- var getOption = function (element) {
- return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
- };
- var set = function (element, value) {
- if (!is(element)) {
- throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
- }
- element.dom().nodeValue = value;
- };
- return {
- get: get,
- getOption: getOption,
- set: set
- };
- }
- var api = NodeValue(isText, 'text');
- var get$3 = function (element) {
- return api.get(element);
- };
- var getOption = function (element) {
- return api.getOption(element);
- };
- var set$2 = function (element, value) {
- return api.set(element, value);
- };
- var getEnd = function (element) {
- return name(element) === 'img' ? 1 : getOption(element).fold(function () {
- return children(element).length;
- }, function (v) {
- return v.length;
- });
- };
- var isTextNodeWithCursorPosition = function (el) {
- return getOption(el).filter(function (text) {
- return text.trim().length !== 0 || text.indexOf(nbsp) > -1;
- }).isSome();
- };
- var elementsWithCursorPosition = [
- 'img',
- 'br'
- ];
- var isCursorPosition = function (elem) {
- var hasCursorPosition = isTextNodeWithCursorPosition(elem);
- return hasCursorPosition || contains(elementsWithCursorPosition, name(elem));
- };
- var first = function (element) {
- return descendant(element, isCursorPosition);
- };
- var last$1 = function (element) {
- return descendantRtl(element, isCursorPosition);
- };
- var descendantRtl = function (scope, predicate) {
- var descend = function (element) {
- var children$1 = children(element);
- for (var i = children$1.length - 1; i >= 0; i--) {
- var child = children$1[i];
- if (predicate(child)) {
- return Option.some(child);
- }
- var res = descend(child);
- if (res.isSome()) {
- return res;
- }
- }
- return Option.none();
- };
- return descend(scope);
- };
- var clone$1 = function (original, isDeep) {
- return Element.fromDom(original.dom().cloneNode(isDeep));
- };
- var shallow = function (original) {
- return clone$1(original, false);
- };
- var deep = function (original) {
- return clone$1(original, true);
- };
- var shallowAs = function (original, tag) {
- var nu = Element.fromTag(tag);
- var attributes = clone(original);
- setAll(nu, attributes);
- return nu;
- };
- var copy$1 = function (original, tag) {
- var nu = shallowAs(original, tag);
- var cloneChildren = children(deep(original));
- append$1(nu, cloneChildren);
- return nu;
- };
- var createCell = function () {
- var td = Element.fromTag('td');
- append(td, Element.fromTag('br'));
- return td;
- };
- var replace = function (cell, tag, attrs) {
- var replica = copy$1(cell, tag);
- each$1(attrs, function (v, k) {
- if (v === null) {
- remove(replica, k);
- } else {
- set(replica, k, v);
- }
- });
- return replica;
- };
- var pasteReplace = function (cell) {
- return cell;
- };
- var newRow = function (doc) {
- return function () {
- return Element.fromTag('tr', doc.dom());
- };
- };
- var cloneFormats = function (oldCell, newCell, formats) {
- var first$1 = first(oldCell);
- return first$1.map(function (firstText) {
- var formatSelector = formats.join(',');
- var parents = ancestors$1(firstText, formatSelector, function (element) {
- return eq(element, oldCell);
- });
- return foldr(parents, function (last, parent) {
- var clonedFormat = shallow(parent);
- remove(clonedFormat, 'contenteditable');
- append(last, clonedFormat);
- return clonedFormat;
- }, newCell);
- }).getOr(newCell);
- };
- var cellOperations = function (mutate, doc, formatsToClone) {
- var newCell = function (prev) {
- var docu = owner(prev.element());
- var td = Element.fromTag(name(prev.element()), docu.dom());
- var formats = formatsToClone.getOr([
- 'strong',
- 'em',
- 'b',
- 'i',
- 'span',
- 'font',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'p',
- 'div'
- ]);
- var lastNode = formats.length > 0 ? cloneFormats(prev.element(), td, formats) : td;
- append(lastNode, Element.fromTag('br'));
- copy(prev.element(), td);
- remove$1(td, 'height');
- if (prev.colspan() !== 1) {
- remove$1(prev.element(), 'width');
- }
- mutate(prev.element(), td);
- return td;
- };
- return {
- row: newRow(doc),
- cell: newCell,
- replace: replace,
- gap: createCell
- };
- };
- var paste = function (doc) {
- return {
- row: newRow(doc),
- cell: createCell,
- replace: pasteReplace,
- gap: createCell
- };
- };
- var fromHtml$1 = function (html, scope) {
- var doc = scope || domGlobals.document;
- var div = doc.createElement('div');
- div.innerHTML = html;
- return children(Element.fromDom(div));
- };
- var inSelection = function (bounds, detail) {
- var leftEdge = detail.column();
- var rightEdge = detail.column() + detail.colspan() - 1;
- var topEdge = detail.row();
- var bottomEdge = detail.row() + detail.rowspan() - 1;
- return leftEdge <= bounds.finishCol() && rightEdge >= bounds.startCol() && (topEdge <= bounds.finishRow() && bottomEdge >= bounds.startRow());
- };
- var isWithin = function (bounds, detail) {
- return detail.column() >= bounds.startCol() && detail.column() + detail.colspan() - 1 <= bounds.finishCol() && detail.row() >= bounds.startRow() && detail.row() + detail.rowspan() - 1 <= bounds.finishRow();
- };
- var isRectangular = function (warehouse, bounds) {
- var isRect = true;
- var detailIsWithin = curry(isWithin, bounds);
- for (var i = bounds.startRow(); i <= bounds.finishRow(); i++) {
- for (var j = bounds.startCol(); j <= bounds.finishCol(); j++) {
- isRect = isRect && Warehouse.getAt(warehouse, i, j).exists(detailIsWithin);
- }
- }
- return isRect ? Option.some(bounds) : Option.none();
- };
- var getBounds = function (detailA, detailB) {
- return bounds(Math.min(detailA.row(), detailB.row()), Math.min(detailA.column(), detailB.column()), Math.max(detailA.row() + detailA.rowspan() - 1, detailB.row() + detailB.rowspan() - 1), Math.max(detailA.column() + detailA.colspan() - 1, detailB.column() + detailB.colspan() - 1));
- };
- var getAnyBox = function (warehouse, startCell, finishCell) {
- var startCoords = Warehouse.findItem(warehouse, startCell, eq);
- var finishCoords = Warehouse.findItem(warehouse, finishCell, eq);
- return startCoords.bind(function (sc) {
- return finishCoords.map(function (fc) {
- return getBounds(sc, fc);
- });
- });
- };
- var getBox = function (warehouse, startCell, finishCell) {
- return getAnyBox(warehouse, startCell, finishCell).bind(function (bounds) {
- return isRectangular(warehouse, bounds);
- });
- };
- var moveBy = function (warehouse, cell, row, column) {
- return Warehouse.findItem(warehouse, cell, eq).bind(function (detail) {
- var startRow = row > 0 ? detail.row() + detail.rowspan() - 1 : detail.row();
- var startCol = column > 0 ? detail.column() + detail.colspan() - 1 : detail.column();
- var dest = Warehouse.getAt(warehouse, startRow + row, startCol + column);
- return dest.map(function (d) {
- return d.element();
- });
- });
- };
- var intercepts = function (warehouse, start, finish) {
- return getAnyBox(warehouse, start, finish).map(function (bounds) {
- var inside = Warehouse.filterItems(warehouse, curry(inSelection, bounds));
- return map(inside, function (detail) {
- return detail.element();
- });
- });
- };
- var parentCell = function (warehouse, innerCell) {
- var isContainedBy = function (c1, c2) {
- return contains$2(c2, c1);
- };
- return Warehouse.findItem(warehouse, innerCell, isContainedBy).map(function (detail) {
- return detail.element();
- });
- };
- var moveBy$1 = function (cell, deltaRow, deltaColumn) {
- return table(cell).bind(function (table) {
- var warehouse = getWarehouse(table);
- return moveBy(warehouse, cell, deltaRow, deltaColumn);
- });
- };
- var intercepts$1 = function (table, first, last) {
- var warehouse = getWarehouse(table);
- return intercepts(warehouse, first, last);
- };
- var nestedIntercepts = function (table, first, firstTable, last, lastTable) {
- var warehouse = getWarehouse(table);
- var optStartCell = eq(table, firstTable) ? Option.some(first) : parentCell(warehouse, first);
- var optLastCell = eq(table, lastTable) ? Option.some(last) : parentCell(warehouse, last);
- return optStartCell.bind(function (startCell) {
- return optLastCell.bind(function (lastCell) {
- return intercepts(warehouse, startCell, lastCell);
- });
- });
- };
- var getBox$1 = function (table, first, last) {
- var warehouse = getWarehouse(table);
- return getBox(warehouse, first, last);
- };
- var getWarehouse = function (table) {
- var list = fromTable(table);
- return Warehouse.generate(list);
- };
- var TagBoundaries = [
- 'body',
- 'p',
- 'div',
- 'article',
- 'aside',
- 'figcaption',
- 'figure',
- 'footer',
- 'header',
- 'nav',
- 'section',
- 'ol',
- 'ul',
- 'li',
- 'table',
- 'thead',
- 'tbody',
- 'tfoot',
- 'caption',
- 'tr',
- 'td',
- 'th',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'blockquote',
- 'pre',
- 'address'
- ];
- function DomUniverse () {
- var clone$1 = function (element) {
- return Element.fromDom(element.dom().cloneNode(false));
- };
- var document = function (element) {
- return element.dom().ownerDocument;
- };
- var isBoundary = function (element) {
- if (!isElement(element)) {
- return false;
- }
- if (name(element) === 'body') {
- return true;
- }
- return contains(TagBoundaries, name(element));
- };
- var isEmptyTag = function (element) {
- if (!isElement(element)) {
- return false;
- }
- return contains([
- 'br',
- 'img',
- 'hr',
- 'input'
- ], name(element));
- };
- var isNonEditable = function (element) {
- return isElement(element) && get$1(element, 'contenteditable') === 'false';
- };
- var comparePosition = function (element, other) {
- return element.dom().compareDocumentPosition(other.dom());
- };
- var copyAttributesTo = function (source, destination) {
- var as = clone(source);
- setAll(destination, as);
- };
- return {
- up: constant({
- selector: ancestor$1,
- closest: closest$1,
- predicate: ancestor,
- all: parents
- }),
- down: constant({
- selector: descendants$1,
- predicate: descendants
- }),
- styles: constant({
- get: get$2,
- getRaw: getRaw,
- set: set$1,
- remove: remove$1
- }),
- attrs: constant({
- get: get$1,
- set: set,
- remove: remove,
- copyTo: copyAttributesTo
- }),
- insert: constant({
- before: before,
- after: after,
- afterAll: after$1,
- append: append,
- appendAll: append$1,
- prepend: prepend,
- wrap: wrap
- }),
- remove: constant({
- unwrap: unwrap,
- remove: remove$2
- }),
- create: constant({
- nu: Element.fromTag,
- clone: clone$1,
- text: Element.fromText
- }),
- query: constant({
- comparePosition: comparePosition,
- prevSibling: prevSibling,
- nextSibling: nextSibling
- }),
- property: constant({
- children: children,
- name: name,
- parent: parent,
- document: document,
- isText: isText,
- isComment: isComment,
- isElement: isElement,
- getText: get$3,
- setText: set$2,
- isBoundary: isBoundary,
- isEmptyTag: isEmptyTag,
- isNonEditable: isNonEditable
- }),
- eq: eq,
- is: is$1
- };
- }
- var all$1 = function (universe, look, elements, f) {
- var head = elements[0];
- var tail = elements.slice(1);
- return f(universe, look, head, tail);
- };
- var oneAll = function (universe, look, elements) {
- return elements.length > 0 ? all$1(universe, look, elements, unsafeOne) : Option.none();
- };
- var unsafeOne = function (universe, look, head, tail) {
- var start = look(universe, head);
- return foldr(tail, function (b, a) {
- var current = look(universe, a);
- return commonElement(universe, b, current);
- }, start);
- };
- var commonElement = function (universe, start, end) {
- return start.bind(function (s) {
- return end.filter(curry(universe.eq, s));
- });
- };
- var eq$1 = function (universe, item) {
- return curry(universe.eq, item);
- };
- var ancestors$2 = function (universe, start, end, isRoot) {
- if (isRoot === void 0) {
- isRoot = never;
- }
- var ps1 = [start].concat(universe.up().all(start));
- var ps2 = [end].concat(universe.up().all(end));
- var prune = function (path) {
- var index = findIndex(path, isRoot);
- return index.fold(function () {
- return path;
- }, function (ind) {
- return path.slice(0, ind + 1);
- });
- };
- var pruned1 = prune(ps1);
- var pruned2 = prune(ps2);
- var shared = find(pruned1, function (x) {
- return exists(pruned2, eq$1(universe, x));
- });
- return {
- firstpath: constant(pruned1),
- secondpath: constant(pruned2),
- shared: constant(shared)
- };
- };
- var sharedOne = oneAll;
- var ancestors$3 = ancestors$2;
- var universe = DomUniverse();
- var sharedOne$1 = function (look, elements) {
- return sharedOne(universe, function (_universe, element) {
- return look(element);
- }, elements);
- };
- var ancestors$4 = function (start, finish, isRoot) {
- return ancestors$3(universe, start, finish, isRoot);
- };
- var lookupTable = function (container) {
- return ancestor$1(container, 'table');
- };
- var identify = function (start, finish, isRoot) {
- var getIsRoot = function (rootTable) {
- return function (element) {
- return isRoot !== undefined && isRoot(element) || eq(element, rootTable);
- };
- };
- if (eq(start, finish)) {
- return Option.some({
- boxes: Option.some([start]),
- start: start,
- finish: finish
- });
- } else {
- return lookupTable(start).bind(function (startTable) {
- return lookupTable(finish).bind(function (finishTable) {
- if (eq(startTable, finishTable)) {
- return Option.some({
- boxes: intercepts$1(startTable, start, finish),
- start: start,
- finish: finish
- });
- } else if (contains$2(startTable, finishTable)) {
- var ancestorCells = ancestors$1(finish, 'td,th', getIsRoot(startTable));
- var finishCell = ancestorCells.length > 0 ? ancestorCells[ancestorCells.length - 1] : finish;
- return Option.some({
- boxes: nestedIntercepts(startTable, start, startTable, finish, finishTable),
- start: start,
- finish: finishCell
- });
- } else if (contains$2(finishTable, startTable)) {
- var ancestorCells = ancestors$1(start, 'td,th', getIsRoot(finishTable));
- var startCell = ancestorCells.length > 0 ? ancestorCells[ancestorCells.length - 1] : start;
- return Option.some({
- boxes: nestedIntercepts(finishTable, start, startTable, finish, finishTable),
- start: start,
- finish: startCell
- });
- } else {
- return ancestors$4(start, finish).shared().bind(function (lca) {
- return closest$1(lca, 'table', isRoot).bind(function (lcaTable) {
- var finishAncestorCells = ancestors$1(finish, 'td,th', getIsRoot(lcaTable));
- var finishCell = finishAncestorCells.length > 0 ? finishAncestorCells[finishAncestorCells.length - 1] : finish;
- var startAncestorCells = ancestors$1(start, 'td,th', getIsRoot(lcaTable));
- var startCell = startAncestorCells.length > 0 ? startAncestorCells[startAncestorCells.length - 1] : start;
- return Option.some({
- boxes: nestedIntercepts(lcaTable, start, startTable, finish, finishTable),
- start: startCell,
- finish: finishCell
- });
- });
- });
- }
- });
- });
- }
- };
- var retrieve = function (container, selector) {
- var sels = descendants$1(container, selector);
- return sels.length > 0 ? Option.some(sels) : Option.none();
- };
- var getLast = function (boxes, lastSelectedSelector) {
- return find(boxes, function (box) {
- return is(box, lastSelectedSelector);
- });
- };
- var getEdges = function (container, firstSelectedSelector, lastSelectedSelector) {
- return descendant$1(container, firstSelectedSelector).bind(function (first) {
- return descendant$1(container, lastSelectedSelector).bind(function (last) {
- return sharedOne$1(lookupTable, [
- first,
- last
- ]).map(function (tbl) {
- return {
- first: constant(first),
- last: constant(last),
- table: constant(tbl)
- };
- });
- });
- });
- };
- var expandTo = function (finish, firstSelectedSelector) {
- return ancestor$1(finish, 'table').bind(function (table) {
- return descendant$1(table, firstSelectedSelector).bind(function (start) {
- return identify(start, finish).bind(function (identified) {
- return identified.boxes.map(function (boxes) {
- return {
- boxes: boxes,
- start: identified.start,
- finish: identified.finish
- };
- });
- });
- });
- });
- };
- var shiftSelection = function (boxes, deltaRow, deltaColumn, firstSelectedSelector, lastSelectedSelector) {
- return getLast(boxes, lastSelectedSelector).bind(function (last) {
- return moveBy$1(last, deltaRow, deltaColumn).bind(function (finish) {
- return expandTo(finish, firstSelectedSelector);
- });
- });
- };
- var retrieve$1 = function (container, selector) {
- return retrieve(container, selector);
- };
- var retrieveBox = function (container, firstSelectedSelector, lastSelectedSelector) {
- return getEdges(container, firstSelectedSelector, lastSelectedSelector).bind(function (edges) {
- var isRoot = function (ancestor) {
- return eq(container, ancestor);
- };
- var firstAncestor = ancestor$1(edges.first(), 'thead,tfoot,tbody,table', isRoot);
- var lastAncestor = ancestor$1(edges.last(), 'thead,tfoot,tbody,table', isRoot);
- return firstAncestor.bind(function (fA) {
- return lastAncestor.bind(function (lA) {
- return eq(fA, lA) ? getBox$1(edges.table(), edges.first(), edges.last()) : Option.none();
- });
- });
- });
- };
- var strSelected = 'data-mce-selected';
- var strSelectedSelector = 'td[' + strSelected + '],th[' + strSelected + ']';
- var strAttributeSelector = '[' + strSelected + ']';
- var strFirstSelected = 'data-mce-first-selected';
- var strFirstSelectedSelector = 'td[' + strFirstSelected + '],th[' + strFirstSelected + ']';
- var strLastSelected = 'data-mce-last-selected';
- var strLastSelectedSelector = 'td[' + strLastSelected + '],th[' + strLastSelected + ']';
- var selected = strSelected;
- var selectedSelector = strSelectedSelector;
- var attributeSelector = strAttributeSelector;
- var firstSelected = strFirstSelected;
- var firstSelectedSelector = strFirstSelectedSelector;
- var lastSelected = strLastSelected;
- var lastSelectedSelector = strLastSelectedSelector;
- var Ephemera = /*#__PURE__*/Object.freeze({
- __proto__: null,
- selected: selected,
- selectedSelector: selectedSelector,
- attributeSelector: attributeSelector,
- firstSelected: firstSelected,
- firstSelectedSelector: firstSelectedSelector,
- lastSelected: lastSelected,
- lastSelectedSelector: lastSelectedSelector
- });
- var generate$1 = function (cases) {
- if (!isArray(cases)) {
- throw new Error('cases must be an array');
- }
- if (cases.length === 0) {
- throw new Error('there must be at least one case');
- }
- var constructors = [];
- var adt = {};
- each(cases, function (acase, count) {
- var keys$1 = keys(acase);
- if (keys$1.length !== 1) {
- throw new Error('one and only one name per case');
- }
- var key = keys$1[0];
- var value = acase[key];
- if (adt[key] !== undefined) {
- throw new Error('duplicate key detected:' + key);
- } else if (key === 'cata') {
- throw new Error('cannot have a case named cata (sorry)');
- } else if (!isArray(value)) {
- throw new Error('case arguments must be an array');
- }
- constructors.push(key);
- adt[key] = function () {
- var argLength = arguments.length;
- if (argLength !== value.length) {
- throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
- }
- var args = new Array(argLength);
- for (var i = 0; i < args.length; i++) {
- args[i] = arguments[i];
- }
- var match = function (branches) {
- var branchKeys = keys(branches);
- if (constructors.length !== branchKeys.length) {
- throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
- }
- var allReqd = forall(constructors, function (reqKey) {
- return contains(branchKeys, reqKey);
- });
- if (!allReqd) {
- throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
- }
- return branches[key].apply(null, args);
- };
- return {
- fold: function () {
- if (arguments.length !== cases.length) {
- throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
- }
- var target = arguments[count];
- return target.apply(null, args);
- },
- match: match,
- log: function (label) {
- domGlobals.console.log(label, {
- constructors: constructors,
- constructor: key,
- params: args
- });
- }
- };
- };
- });
- return adt;
- };
- var Adt = { generate: generate$1 };
- var type$1 = Adt.generate([
- { none: [] },
- { multiple: ['elements'] },
- { single: ['selection'] }
- ]);
- var cata = function (subject, onNone, onMultiple, onSingle) {
- return subject.fold(onNone, onMultiple, onSingle);
- };
- var none$1 = type$1.none;
- var multiple = type$1.multiple;
- var single = type$1.single;
- var selection = function (cell, selections) {
- return cata(selections.get(), constant([]), identity, constant([cell]));
- };
- var unmergable = function (cell, selections) {
- var hasSpan = function (elem) {
- return has$1(elem, 'rowspan') && parseInt(get$1(elem, 'rowspan'), 10) > 1 || has$1(elem, 'colspan') && parseInt(get$1(elem, 'colspan'), 10) > 1;
- };
- var candidates = selection(cell, selections);
- return candidates.length > 0 && forall(candidates, hasSpan) ? Option.some(candidates) : Option.none();
- };
- var mergable = function (table, selections) {
- return cata(selections.get(), Option.none, function (cells, _env) {
- if (cells.length === 0) {
- return Option.none();
- }
- return retrieveBox(table, firstSelectedSelector, lastSelectedSelector).bind(function (bounds) {
- return cells.length > 1 ? Option.some({
- bounds: constant(bounds),
- cells: constant(cells)
- }) : Option.none();
- });
- }, Option.none);
- };
- var noMenu = function (cell) {
- return {
- element: constant(cell),
- mergable: Option.none,
- unmergable: Option.none,
- selection: constant([cell])
- };
- };
- var forMenu = function (selections, table, cell) {
- return {
- element: constant(cell),
- mergable: constant(mergable(table, selections)),
- unmergable: constant(unmergable(cell, selections)),
- selection: constant(selection(cell, selections))
- };
- };
- var notCell = function (element) {
- return noMenu(element);
- };
- var paste$1 = function (element, clipboard, generators) {
- return {
- element: constant(element),
- clipboard: constant(clipboard),
- generators: constant(generators)
- };
- };
- var pasteRows = function (selections, table, cell, clipboard, generators) {
- return {
- element: constant(cell),
- mergable: Option.none,
- unmergable: Option.none,
- selection: constant(selection(cell, selections)),
- clipboard: constant(clipboard),
- generators: constant(generators)
- };
- };
- var extractSelected = function (cells) {
- return table(cells[0]).map(deep).map(function (replica) {
- return [extract(replica, attributeSelector)];
- });
- };
- var serializeElements = function (editor, elements) {
- return map(elements, function (elm) {
- return editor.selection.serializer.serialize(elm.dom(), {});
- }).join('');
- };
- var getTextContent = function (elements) {
- return map(elements, function (element) {
- return element.dom().innerText;
- }).join('');
- };
- var registerEvents = function (editor, selections, actions, cellSelection) {
- editor.on('BeforeGetContent', function (e) {
- var multiCellContext = function (cells) {
- e.preventDefault();
- extractSelected(cells).each(function (elements) {
- e.content = e.format === 'text' ? getTextContent(elements) : serializeElements(editor, elements);
- });
- };
- if (e.selection === true) {
- cata(selections.get(), noop, multiCellContext, noop);
- }
- });
- editor.on('BeforeSetContent', function (e) {
- if (e.selection === true && e.paste === true) {
- var cellOpt = Option.from(editor.dom.getParent(editor.selection.getStart(), 'th,td'));
- cellOpt.each(function (domCell) {
- var cell = Element.fromDom(domCell);
- table(cell).each(function (table) {
- var elements = filter(fromHtml$1(e.content), function (content) {
- return name(content) !== 'meta';
- });
- if (elements.length === 1 && name(elements[0]) === 'table') {
- e.preventDefault();
- var doc = Element.fromDom(editor.getDoc());
- var generators = paste(doc);
- var targets = paste$1(cell, elements[0], generators);
- actions.pasteCells(table, targets).each(function (rng) {
- editor.selection.setRng(rng);
- editor.focus();
- cellSelection.clear(table);
- });
- }
- });
- });
- }
- });
- };
- function Dimension (name, getOffset) {
- var set = function (element, h) {
- if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
- throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
- }
- var dom = element.dom();
- if (isSupported(dom)) {
- dom.style[name] = h + 'px';
- }
- };
- var get = function (element) {
- var r = getOffset(element);
- if (r <= 0 || r === null) {
- var css = get$2(element, name);
- return parseFloat(css) || 0;
- }
- return r;
- };
- var getOuter = get;
- var aggregate = function (element, properties) {
- return foldl(properties, function (acc, property) {
- var val = get$2(element, property);
- var value = val === undefined ? 0 : parseInt(val, 10);
- return isNaN(value) ? acc : acc + value;
- }, 0);
- };
- var max = function (element, value, properties) {
- var cumulativeInclusions = aggregate(element, properties);
- var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
- return absoluteMax;
- };
- return {
- set: set,
- get: get,
- getOuter: getOuter,
- aggregate: aggregate,
- max: max
- };
- }
- var api$1 = Dimension('height', function (element) {
- var dom = element.dom();
- return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
- });
- var get$4 = function (element) {
- return api$1.get(element);
- };
- var getOuter = function (element) {
- return api$1.getOuter(element);
- };
- var api$2 = Dimension('width', function (element) {
- return element.dom().offsetWidth;
- });
- var get$5 = function (element) {
- return api$2.get(element);
- };
- var getOuter$1 = function (element) {
- return api$2.getOuter(element);
- };
- var needManualCalc = function () {
- var platform = detect$3();
- return platform.browser.isIE() || platform.browser.isEdge();
- };
- var toNumber = function (px, fallback) {
- var num = parseFloat(px);
- return isNaN(num) ? fallback : num;
- };
- var getProp = function (elm, name, fallback) {
- return toNumber(get$2(elm, name), fallback);
- };
- var getCalculatedHeight = function (cell) {
- var paddingTop = getProp(cell, 'padding-top', 0);
- var paddingBottom = getProp(cell, 'padding-bottom', 0);
- var borderTop = getProp(cell, 'border-top-width', 0);
- var borderBottom = getProp(cell, 'border-bottom-width', 0);
- var height = cell.dom().getBoundingClientRect().height;
- var boxSizing = get$2(cell, 'box-sizing');
- var borders = borderTop + borderBottom;
- return boxSizing === 'border-box' ? height : height - paddingTop - paddingBottom - borders;
- };
- var getHeight = function (cell) {
- return needManualCalc() ? getCalculatedHeight(cell) : getProp(cell, 'height', get$4(cell));
- };
- var rGenericSizeRegex = /(\d+(\.\d+)?)(\w|%)*/;
- var rPercentageBasedSizeRegex = /(\d+(\.\d+)?)%/;
- var rPixelBasedSizeRegex = /(\d+(\.\d+)?)px|em/;
- var setPixelWidth = function (cell, amount) {
- set$1(cell, 'width', amount + 'px');
- };
- var setPercentageWidth = function (cell, amount) {
- set$1(cell, 'width', amount + '%');
- };
- var setHeight = function (cell, amount) {
- set$1(cell, 'height', amount + 'px');
- };
- var getHeightValue = function (cell) {
- return getRaw(cell, 'height').getOrThunk(function () {
- return getHeight(cell) + 'px';
- });
- };
- var convert = function (cell, number, getter, setter) {
- var newSize = table(cell).map(function (table) {
- var total = getter(table);
- return Math.floor(number / 100 * total);
- }).getOr(number);
- setter(cell, newSize);
- return newSize;
- };
- var normalizePixelSize = function (value, cell, getter, setter) {
- var number = parseInt(value, 10);
- return endsWith(value, '%') && name(cell) !== 'table' ? convert(cell, number, getter, setter) : number;
- };
- var getTotalHeight = function (cell) {
- var value = getHeightValue(cell);
- if (!value) {
- return get$4(cell);
- }
- return normalizePixelSize(value, cell, get$4, setHeight);
- };
- var get$6 = function (cell, type, f) {
- var v = f(cell);
- var span = getSpan(cell, type);
- return v / span;
- };
- var getRawWidth = function (element) {
- var cssWidth = getRaw(element, 'width');
- return cssWidth.fold(function () {
- return Option.from(get$1(element, 'width'));
- }, function (width) {
- return Option.some(width);
- });
- };
- var normalizePercentageWidth = function (cellWidth, tableSize) {
- return cellWidth / tableSize.pixelWidth() * 100;
- };
- var choosePercentageSize = function (element, width, tableSize) {
- var percentMatch = rPercentageBasedSizeRegex.exec(width);
- if (percentMatch !== null) {
- return parseFloat(percentMatch[1]);
- } else {
- var intWidth = get$5(element);
- return normalizePercentageWidth(intWidth, tableSize);
- }
- };
- var getPercentageWidth = function (cell, tableSize) {
- var width = getRawWidth(cell);
- return width.fold(function () {
- var intWidth = get$5(cell);
- return normalizePercentageWidth(intWidth, tableSize);
- }, function (w) {
- return choosePercentageSize(cell, w, tableSize);
- });
- };
- var normalizePixelWidth = function (cellWidth, tableSize) {
- return cellWidth / 100 * tableSize.pixelWidth();
- };
- var choosePixelSize = function (element, width, tableSize) {
- var pixelMatch = rPixelBasedSizeRegex.exec(width);
- if (pixelMatch !== null) {
- return parseInt(pixelMatch[1], 10);
- }
- var percentMatch = rPercentageBasedSizeRegex.exec(width);
- if (percentMatch !== null) {
- var floatWidth = parseFloat(percentMatch[1]);
- return normalizePixelWidth(floatWidth, tableSize);
- }
- return get$5(element);
- };
- var getPixelWidth = function (cell, tableSize) {
- var width = getRawWidth(cell);
- return width.fold(function () {
- return get$5(cell);
- }, function (w) {
- return choosePixelSize(cell, w, tableSize);
- });
- };
- var getHeight$1 = function (cell) {
- return get$6(cell, 'rowspan', getTotalHeight);
- };
- var getGenericWidth = function (cell) {
- var width = getRawWidth(cell);
- return width.bind(function (w) {
- var match = rGenericSizeRegex.exec(w);
- if (match !== null) {
- return Option.some({
- width: constant(parseFloat(match[1])),
- unit: constant(match[3])
- });
- } else {
- return Option.none();
- }
- });
- };
- var setGenericWidth = function (cell, amount, unit) {
- set$1(cell, 'width', amount + unit);
- };
- var percentageBasedSizeRegex = constant(rPercentageBasedSizeRegex);
- var pixelBasedSizeRegex = constant(rPixelBasedSizeRegex);
- var halve = function (main, other) {
- var width = getGenericWidth(main);
- width.each(function (w) {
- var newWidth = w.width() / 2;
- setGenericWidth(main, newWidth, w.unit());
- setGenericWidth(other, newWidth, w.unit());
- });
- };
- var r = function (left, top) {
- var translate = function (x, y) {
- return r(left + x, top + y);
- };
- return {
- left: constant(left),
- top: constant(top),
- translate: translate
- };
- };
- var Position = r;
- var boxPosition = function (dom) {
- var box = dom.getBoundingClientRect();
- return Position(box.left, box.top);
- };
- var firstDefinedOrZero = function (a, b) {
- if (a !== undefined) {
- return a;
- } else {
- return b !== undefined ? b : 0;
- }
- };
- var absolute = function (element) {
- var doc = element.dom().ownerDocument;
- var body = doc.body;
- var win = doc.defaultView;
- var html = doc.documentElement;
- if (body === element.dom()) {
- return Position(body.offsetLeft, body.offsetTop);
- }
- var scrollTop = firstDefinedOrZero(win.pageYOffset, html.scrollTop);
- var scrollLeft = firstDefinedOrZero(win.pageXOffset, html.scrollLeft);
- var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
- var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
- return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
- };
- var viewport = function (element) {
- var dom = element.dom();
- var doc = dom.ownerDocument;
- var body = doc.body;
- if (body === dom) {
- return Position(body.offsetLeft, body.offsetTop);
- }
- if (!inBody(element)) {
- return Position(0, 0);
- }
- return boxPosition(dom);
- };
- var rowInfo = function (row, y) {
- return {
- row: row,
- y: y
- };
- };
- var colInfo = function (col, x) {
- return {
- col: col,
- x: x
- };
- };
- var rtlEdge = function (cell) {
- var pos = absolute(cell);
- return pos.left() + getOuter$1(cell);
- };
- var ltrEdge = function (cell) {
- return absolute(cell).left();
- };
- var getLeftEdge = function (index, cell) {
- return colInfo(index, ltrEdge(cell));
- };
- var getRightEdge = function (index, cell) {
- return colInfo(index, rtlEdge(cell));
- };
- var getTop = function (cell) {
- return absolute(cell).top();
- };
- var getTopEdge = function (index, cell) {
- return rowInfo(index, getTop(cell));
- };
- var getBottomEdge = function (index, cell) {
- return rowInfo(index, getTop(cell) + getOuter(cell));
- };
- var findPositions = function (getInnerEdge, getOuterEdge, array) {
- if (array.length === 0) {
- return [];
- }
- var lines = map(array.slice(1), function (cellOption, index) {
- return cellOption.map(function (cell) {
- return getInnerEdge(index, cell);
- });
- });
- var lastLine = array[array.length - 1].map(function (cell) {
- return getOuterEdge(array.length - 1, cell);
- });
- return lines.concat([lastLine]);
- };
- var negate = function (step) {
- return -step;
- };
- var height = {
- delta: identity,
- positions: function (optElements) {
- return findPositions(getTopEdge, getBottomEdge, optElements);
- },
- edge: getTop
- };
- var ltr = {
- delta: identity,
- edge: ltrEdge,
- positions: function (optElements) {
- return findPositions(getLeftEdge, getRightEdge, optElements);
- }
- };
- var rtl = {
- delta: negate,
- edge: rtlEdge,
- positions: function (optElements) {
- return findPositions(getRightEdge, getLeftEdge, optElements);
- }
- };
- var ResizeDirection = {
- ltr: ltr,
- rtl: rtl
- };
- function TableDirection (directionAt) {
- var auto = function (table) {
- return directionAt(table).isRtl() ? ResizeDirection.rtl : ResizeDirection.ltr;
- };
- var delta = function (amount, table) {
- return auto(table).delta(amount, table);
- };
- var positions = function (cols, table) {
- return auto(table).positions(cols, table);
- };
- var edge = function (cell) {
- return auto(cell).edge(cell);
- };
- return {
- delta: delta,
- edge: edge,
- positions: positions
- };
- }
- var getGridSize = function (table) {
- var input = fromTable(table);
- var warehouse = Warehouse.generate(input);
- return warehouse.grid;
- };
- var cat = function (arr) {
- var r = [];
- var push = function (x) {
- r.push(x);
- };
- for (var i = 0; i < arr.length; i++) {
- arr[i].each(push);
- }
- return r;
- };
- var setIfNot = function (element, property, value, ignore) {
- if (value === ignore) {
- remove(element, property);
- } else {
- set(element, property, value);
- }
- };
- var render = function (table, grid) {
- var newRows = [];
- var newCells = [];
- var renderSection = function (gridSection, sectionName) {
- var section = child$2(table, sectionName).getOrThunk(function () {
- var tb = Element.fromTag(sectionName, owner(table).dom());
- append(table, tb);
- return tb;
- });
- empty(section);
- var rows = map(gridSection, function (row) {
- if (row.isNew()) {
- newRows.push(row.element());
- }
- var tr = row.element();
- empty(tr);
- each(row.cells(), function (cell) {
- if (cell.isNew()) {
- newCells.push(cell.element());
- }
- setIfNot(cell.element(), 'colspan', cell.colspan(), 1);
- setIfNot(cell.element(), 'rowspan', cell.rowspan(), 1);
- append(tr, cell.element());
- });
- return tr;
- });
- append$1(section, rows);
- };
- var removeSection = function (sectionName) {
- child$2(table, sectionName).each(remove$2);
- };
- var renderOrRemoveSection = function (gridSection, sectionName) {
- if (gridSection.length > 0) {
- renderSection(gridSection, sectionName);
- } else {
- removeSection(sectionName);
- }
- };
- var headSection = [];
- var bodySection = [];
- var footSection = [];
- each(grid, function (row) {
- switch (row.section()) {
- case 'thead':
- headSection.push(row);
- break;
- case 'tbody':
- bodySection.push(row);
- break;
- case 'tfoot':
- footSection.push(row);
- break;
- }
- });
- renderOrRemoveSection(headSection, 'thead');
- renderOrRemoveSection(bodySection, 'tbody');
- renderOrRemoveSection(footSection, 'tfoot');
- return {
- newRows: newRows,
- newCells: newCells
- };
- };
- var copy$2 = function (grid) {
- return map(grid, function (row) {
- var tr = shallow(row.element());
- each(row.cells(), function (cell) {
- var clonedCell = deep(cell.element());
- setIfNot(clonedCell, 'colspan', cell.colspan(), 1);
- setIfNot(clonedCell, 'rowspan', cell.rowspan(), 1);
- append(tr, clonedCell);
- });
- return tr;
- });
- };
- var read = function (element, attr) {
- var value = get$1(element, attr);
- return value === undefined || value === '' ? [] : value.split(' ');
- };
- var add = function (element, attr, id) {
- var old = read(element, attr);
- var nu = old.concat([id]);
- set(element, attr, nu.join(' '));
- return true;
- };
- var remove$3 = function (element, attr, id) {
- var nu = filter(read(element, attr), function (v) {
- return v !== id;
- });
- if (nu.length > 0) {
- set(element, attr, nu.join(' '));
- } else {
- remove(element, attr);
- }
- return false;
- };
- var supports = function (element) {
- return element.dom().classList !== undefined;
- };
- var get$7 = function (element) {
- return read(element, 'class');
- };
- var add$1 = function (element, clazz) {
- return add(element, 'class', clazz);
- };
- var remove$4 = function (element, clazz) {
- return remove$3(element, 'class', clazz);
- };
- var add$2 = function (element, clazz) {
- if (supports(element)) {
- element.dom().classList.add(clazz);
- } else {
- add$1(element, clazz);
- }
- };
- var cleanClass = function (element) {
- var classList = supports(element) ? element.dom().classList : get$7(element);
- if (classList.length === 0) {
- remove(element, 'class');
- }
- };
- var remove$5 = function (element, clazz) {
- if (supports(element)) {
- var classList = element.dom().classList;
- classList.remove(clazz);
- } else {
- remove$4(element, clazz);
- }
- cleanClass(element);
- };
- var has$2 = function (element, clazz) {
- return supports(element) && element.dom().classList.contains(clazz);
- };
- var repeat = function (repititions, f) {
- var r = [];
- for (var i = 0; i < repititions; i++) {
- r.push(f(i));
- }
- return r;
- };
- var range = function (start, end) {
- var r = [];
- for (var i = start; i < end; i++) {
- r.push(i);
- }
- return r;
- };
- var deduce = function (xs, index) {
- if (index < 0 || index >= xs.length - 1) {
- return Option.none();
- }
- var current = xs[index].fold(function () {
- var rest = reverse(xs.slice(0, index));
- return findMap(rest, function (a, i) {
- return a.map(function (aa) {
- return {
- value: aa,
- delta: i + 1
- };
- });
- });
- }, function (c) {
- return Option.some({
- value: c,
- delta: 0
- });
- });
- var next = xs[index + 1].fold(function () {
- var rest = xs.slice(index + 1);
- return findMap(rest, function (a, i) {
- return a.map(function (aa) {
- return {
- value: aa,
- delta: i + 1
- };
- });
- });
- }, function (n) {
- return Option.some({
- value: n,
- delta: 1
- });
- });
- return current.bind(function (c) {
- return next.map(function (n) {
- var extras = n.delta + c.delta;
- return Math.abs(n.value - c.value) / extras;
- });
- });
- };
- var columns = function (warehouse) {
- var grid = warehouse.grid;
- var cols = range(0, grid.columns());
- var rowsArr = range(0, grid.rows());
- return map(cols, function (col) {
- var getBlock = function () {
- return bind(rowsArr, function (r) {
- return Warehouse.getAt(warehouse, r, col).filter(function (detail) {
- return detail.column() === col;
- }).fold(constant([]), function (detail) {
- return [detail];
- });
- });
- };
- var isSingle = function (detail) {
- return detail.colspan() === 1;
- };
- var getFallback = function () {
- return Warehouse.getAt(warehouse, 0, col);
- };
- return decide(getBlock, isSingle, getFallback);
- });
- };
- var decide = function (getBlock, isSingle, getFallback) {
- var inBlock = getBlock();
- var singleInBlock = find(inBlock, isSingle);
- var detailOption = singleInBlock.orThunk(function () {
- return Option.from(inBlock[0]).orThunk(getFallback);
- });
- return detailOption.map(function (detail) {
- return detail.element();
- });
- };
- var rows$1 = function (warehouse) {
- var grid = warehouse.grid;
- var rowsArr = range(0, grid.rows());
- var cols = range(0, grid.columns());
- return map(rowsArr, function (row) {
- var getBlock = function () {
- return bind(cols, function (c) {
- return Warehouse.getAt(warehouse, row, c).filter(function (detail) {
- return detail.row() === row;
- }).fold(constant([]), function (detail) {
- return [detail];
- });
- });
- };
- var isSingle = function (detail) {
- return detail.rowspan() === 1;
- };
- var getFallback = function () {
- return Warehouse.getAt(warehouse, row, 0);
- };
- return decide(getBlock, isSingle, getFallback);
- });
- };
- var css = function (namespace) {
- var dashNamespace = namespace.replace(/\./g, '-');
- var resolve = function (str) {
- return dashNamespace + '-' + str;
- };
- return { resolve: resolve };
- };
- var styles = css('ephox-snooker');
- var resolve = styles.resolve;
- var col = function (column, x, y, w, h) {
- var bar = Element.fromTag('div');
- setAll$1(bar, {
- position: 'absolute',
- left: x - w / 2 + 'px',
- top: y + 'px',
- height: h + 'px',
- width: w + 'px'
- });
- setAll(bar, {
- 'data-column': column,
- 'role': 'presentation'
- });
- return bar;
- };
- var row = function (r, x, y, w, h) {
- var bar = Element.fromTag('div');
- setAll$1(bar, {
- position: 'absolute',
- left: x + 'px',
- top: y - h / 2 + 'px',
- height: h + 'px',
- width: w + 'px'
- });
- setAll(bar, {
- 'data-row': r,
- 'role': 'presentation'
- });
- return bar;
- };
- var resizeBar = resolve('resizer-bar');
- var resizeRowBar = resolve('resizer-rows');
- var resizeColBar = resolve('resizer-cols');
- var BAR_THICKNESS = 7;
- var destroy = function (wire) {
- var previous = descendants$1(wire.parent(), '.' + resizeBar);
- each(previous, remove$2);
- };
- var drawBar = function (wire, positions, create) {
- var origin = wire.origin();
- each(positions, function (cpOption) {
- cpOption.each(function (cp) {
- var bar = create(origin, cp);
- add$2(bar, resizeBar);
- append(wire.parent(), bar);
- });
- });
- };
- var refreshCol = function (wire, colPositions, position, tableHeight) {
- drawBar(wire, colPositions, function (origin, cp) {
- var colBar = col(cp.col, cp.x - origin.left(), position.top() - origin.top(), BAR_THICKNESS, tableHeight);
- add$2(colBar, resizeColBar);
- return colBar;
- });
- };
- var refreshRow = function (wire, rowPositions, position, tableWidth) {
- drawBar(wire, rowPositions, function (origin, cp) {
- var rowBar = row(cp.row, position.left() - origin.left(), cp.y - origin.top(), tableWidth, BAR_THICKNESS);
- add$2(rowBar, resizeRowBar);
- return rowBar;
- });
- };
- var refreshGrid = function (wire, table, rows, cols, hdirection, vdirection) {
- var position = absolute(table);
- var rowPositions = rows.length > 0 ? hdirection.positions(rows, table) : [];
- refreshRow(wire, rowPositions, position, getOuter$1(table));
- var colPositions = cols.length > 0 ? vdirection.positions(cols, table) : [];
- refreshCol(wire, colPositions, position, getOuter(table));
- };
- var refresh = function (wire, table, hdirection, vdirection) {
- destroy(wire);
- var list = fromTable(table);
- var warehouse = Warehouse.generate(list);
- var rows = rows$1(warehouse);
- var cols = columns(warehouse);
- refreshGrid(wire, table, rows, cols, hdirection, vdirection);
- };
- var each$2 = function (wire, f) {
- var bars = descendants$1(wire.parent(), '.' + resizeBar);
- each(bars, f);
- };
- var hide = function (wire) {
- each$2(wire, function (bar) {
- set$1(bar, 'display', 'none');
- });
- };
- var show = function (wire) {
- each$2(wire, function (bar) {
- set$1(bar, 'display', 'block');
- });
- };
- var isRowBar = function (element) {
- return has$2(element, resizeRowBar);
- };
- var isColBar = function (element) {
- return has$2(element, resizeColBar);
- };
- var addCell = function (gridRow, index, cell) {
- var cells = gridRow.cells();
- var before = cells.slice(0, index);
- var after = cells.slice(index);
- var newCells = before.concat([cell]).concat(after);
- return setCells(gridRow, newCells);
- };
- var mutateCell = function (gridRow, index, cell) {
- var cells = gridRow.cells();
- cells[index] = cell;
- };
- var setCells = function (gridRow, cells) {
- return rowcells(cells, gridRow.section());
- };
- var mapCells = function (gridRow, f) {
- var cells = gridRow.cells();
- var r = map(cells, f);
- return rowcells(r, gridRow.section());
- };
- var getCell = function (gridRow, index) {
- return gridRow.cells()[index];
- };
- var getCellElement = function (gridRow, index) {
- return getCell(gridRow, index).element();
- };
- var cellLength = function (gridRow) {
- return gridRow.cells().length;
- };
- var getColumn = function (grid, index) {
- return map(grid, function (row) {
- return getCell(row, index);
- });
- };
- var getRow = function (grid, index) {
- return grid[index];
- };
- var findDiff = function (xs, comp) {
- if (xs.length === 0) {
- return 0;
- }
- var first = xs[0];
- var index = findIndex(xs, function (x) {
- return !comp(first.element(), x.element());
- });
- return index.fold(function () {
- return xs.length;
- }, function (ind) {
- return ind;
- });
- };
- var subgrid = function (grid, row, column, comparator) {
- var restOfRow = getRow(grid, row).cells().slice(column);
- var endColIndex = findDiff(restOfRow, comparator);
- var restOfColumn = getColumn(grid, column).slice(row);
- var endRowIndex = findDiff(restOfColumn, comparator);
- return {
- colspan: endColIndex,
- rowspan: endRowIndex
- };
- };
- var toDetails = function (grid, comparator) {
- var seen = map(grid, function (row) {
- return map(row.cells(), function () {
- return false;
- });
- });
- var updateSeen = function (ri, ci, rowspan, colspan) {
- for (var r = ri; r < ri + rowspan; r++) {
- for (var c = ci; c < ci + colspan; c++) {
- seen[r][c] = true;
- }
- }
- };
- return map(grid, function (row, ri) {
- var details = bind(row.cells(), function (cell, ci) {
- if (seen[ri][ci] === false) {
- var result = subgrid(grid, ri, ci, comparator);
- updateSeen(ri, ci, result.rowspan, result.colspan);
- return [detailnew(cell.element(), result.rowspan, result.colspan, cell.isNew())];
- } else {
- return [];
- }
- });
- return rowdetails(details, row.section());
- });
- };
- var toGrid = function (warehouse, generators, isNew) {
- var grid = [];
- for (var i = 0; i < warehouse.grid.rows(); i++) {
- var rowCells = [];
- for (var j = 0; j < warehouse.grid.columns(); j++) {
- var element = Warehouse.getAt(warehouse, i, j).map(function (item) {
- return elementnew(item.element(), isNew);
- }).getOrThunk(function () {
- return elementnew(generators.gap(), true);
- });
- rowCells.push(element);
- }
- var row = rowcells(rowCells, warehouse.all[i].section());
- grid.push(row);
- }
- return grid;
- };
- var fromWarehouse = function (warehouse, generators) {
- return toGrid(warehouse, generators, false);
- };
- var deriveRows = function (rendered, generators) {
- var findRow = function (details) {
- var rowOfCells = findMap(details, function (detail) {
- return parent(detail.element()).map(function (row) {
- var isNew = parent(row).isNone();
- return elementnew(row, isNew);
- });
- });
- return rowOfCells.getOrThunk(function () {
- return elementnew(generators.row(), true);
- });
- };
- return map(rendered, function (details) {
- var row = findRow(details.details());
- return rowdatanew(row.element(), details.details(), details.section(), row.isNew());
- });
- };
- var toDetailList = function (grid, generators) {
- var rendered = toDetails(grid, eq);
- return deriveRows(rendered, generators);
- };
- var findInWarehouse = function (warehouse, element) {
- return findMap(warehouse.all, function (r) {
- return find(r.cells(), function (e) {
- return eq(element, e.element());
- });
- });
- };
- var run = function (operation, extract, adjustment, postAction, genWrappers) {
- return function (wire, table, target, generators, direction) {
- var input = fromTable(table);
- var warehouse = Warehouse.generate(input);
- var output = extract(warehouse, target).map(function (info) {
- var model = fromWarehouse(warehouse, generators);
- var result = operation(model, info, eq, genWrappers(generators));
- var grid = toDetailList(result.grid(), generators);
- return {
- grid: constant(grid),
- cursor: result.cursor
- };
- });
- return output.fold(function () {
- return Option.none();
- }, function (out) {
- var newElements = render(table, out.grid());
- adjustment(table, out.grid(), direction);
- postAction(table);
- refresh(wire, table, height, direction);
- return Option.some({
- cursor: out.cursor,
- newRows: constant(newElements.newRows),
- newCells: constant(newElements.newCells)
- });
- });
- };
- };
- var onCell = function (warehouse, target) {
- return cell(target.element()).bind(function (cell) {
- return findInWarehouse(warehouse, cell);
- });
- };
- var onPaste = function (warehouse, target) {
- return cell(target.element()).bind(function (cell) {
- return findInWarehouse(warehouse, cell).map(function (details) {
- var value = __assign(__assign({}, details), {
- generators: target.generators,
- clipboard: target.clipboard
- });
- return value;
- });
- });
- };
- var onPasteRows = function (warehouse, target) {
- var details = map(target.selection(), function (cell$1) {
- return cell(cell$1).bind(function (lc) {
- return findInWarehouse(warehouse, lc);
- });
- });
- var cells = cat(details);
- return cells.length > 0 ? Option.some({
- cells: cells,
- generators: target.generators,
- clipboard: target.clipboard
- }) : Option.none();
- };
- var onMergable = function (_warehouse, target) {
- return target.mergable();
- };
- var onUnmergable = function (_warehouse, target) {
- return target.unmergable();
- };
- var onCells = function (warehouse, target) {
- var details = map(target.selection(), function (cell$1) {
- return cell(cell$1).bind(function (lc) {
- return findInWarehouse(warehouse, lc);
- });
- });
- var cells = cat(details);
- return cells.length > 0 ? Option.some(cells) : Option.none();
- };
- var value = function (o) {
- var is = function (v) {
- return o === v;
- };
- var or = function (_opt) {
- return value(o);
- };
- var orThunk = function (_f) {
- return value(o);
- };
- var map = function (f) {
- return value(f(o));
- };
- var mapError = function (_f) {
- return value(o);
- };
- var each = function (f) {
- f(o);
- };
- var bind = function (f) {
- return f(o);
- };
- var fold = function (_, onValue) {
- return onValue(o);
- };
- var exists = function (f) {
- return f(o);
- };
- var forall = function (f) {
- return f(o);
- };
- var toOption = function () {
- return Option.some(o);
- };
- return {
- is: is,
- isValue: always,
- isError: never,
- getOr: constant(o),
- getOrThunk: constant(o),
- getOrDie: constant(o),
- or: or,
- orThunk: orThunk,
- fold: fold,
- map: map,
- mapError: mapError,
- each: each,
- bind: bind,
- exists: exists,
- forall: forall,
- toOption: toOption
- };
- };
- var error = function (message) {
- var getOrThunk = function (f) {
- return f();
- };
- var getOrDie = function () {
- return die(String(message))();
- };
- var or = function (opt) {
- return opt;
- };
- var orThunk = function (f) {
- return f();
- };
- var map = function (_f) {
- return error(message);
- };
- var mapError = function (f) {
- return error(f(message));
- };
- var bind = function (_f) {
- return error(message);
- };
- var fold = function (onError, _) {
- return onError(message);
- };
- return {
- is: never,
- isValue: never,
- isError: always,
- getOr: identity,
- getOrThunk: getOrThunk,
- getOrDie: getOrDie,
- or: or,
- orThunk: orThunk,
- fold: fold,
- map: map,
- mapError: mapError,
- each: noop,
- bind: bind,
- exists: never,
- forall: always,
- toOption: Option.none
- };
- };
- var fromOption = function (opt, err) {
- return opt.fold(function () {
- return error(err);
- }, value);
- };
- var Result = {
- value: value,
- error: error,
- fromOption: fromOption
- };
- var measure = function (startAddress, gridA, gridB) {
- if (startAddress.row() >= gridA.length || startAddress.column() > cellLength(gridA[0])) {
- return Result.error('invalid start address out of table bounds, row: ' + startAddress.row() + ', column: ' + startAddress.column());
- }
- var rowRemainder = gridA.slice(startAddress.row());
- var colRemainder = rowRemainder[0].cells().slice(startAddress.column());
- var colRequired = cellLength(gridB[0]);
- var rowRequired = gridB.length;
- return Result.value({
- rowDelta: rowRemainder.length - rowRequired,
- colDelta: colRemainder.length - colRequired
- });
- };
- var measureWidth = function (gridA, gridB) {
- var colLengthA = cellLength(gridA[0]);
- var colLengthB = cellLength(gridB[0]);
- return {
- rowDelta: 0,
- colDelta: colLengthA - colLengthB
- };
- };
- var fill = function (cells, generator) {
- return map(cells, function () {
- return elementnew(generator.cell(), true);
- });
- };
- var rowFill = function (grid, amount, generator) {
- return grid.concat(repeat(amount, function (_row) {
- return setCells(grid[grid.length - 1], fill(grid[grid.length - 1].cells(), generator));
- }));
- };
- var colFill = function (grid, amount, generator) {
- return map(grid, function (row) {
- return setCells(row, row.cells().concat(fill(range(0, amount), generator)));
- });
- };
- var tailor = function (gridA, delta, generator) {
- var fillCols = delta.colDelta < 0 ? colFill : identity;
- var fillRows = delta.rowDelta < 0 ? rowFill : identity;
- var modifiedCols = fillCols(gridA, Math.abs(delta.colDelta), generator);
- return fillRows(modifiedCols, Math.abs(delta.rowDelta), generator);
- };
- var merge = function (grid, bounds, comparator, substitution) {
- if (grid.length === 0) {
- return grid;
- }
- for (var i = bounds.startRow(); i <= bounds.finishRow(); i++) {
- for (var j = bounds.startCol(); j <= bounds.finishCol(); j++) {
- mutateCell(grid[i], j, elementnew(substitution(), false));
- }
- }
- return grid;
- };
- var unmerge = function (grid, target, comparator, substitution) {
- var first = true;
- for (var i = 0; i < grid.length; i++) {
- for (var j = 0; j < cellLength(grid[0]); j++) {
- var current = getCellElement(grid[i], j);
- var isToReplace = comparator(current, target);
- if (isToReplace === true && first === false) {
- mutateCell(grid[i], j, elementnew(substitution(), true));
- } else if (isToReplace === true) {
- first = false;
- }
- }
- }
- return grid;
- };
- var uniqueCells = function (row, comparator) {
- return foldl(row, function (rest, cell) {
- return exists(rest, function (currentCell) {
- return comparator(currentCell.element(), cell.element());
- }) ? rest : rest.concat([cell]);
- }, []);
- };
- var splitRows = function (grid, index, comparator, substitution) {
- if (index > 0 && index < grid.length) {
- var rowPrevCells = grid[index - 1].cells();
- var cells = uniqueCells(rowPrevCells, comparator);
- each(cells, function (cell) {
- var replacement = Option.none();
- var _loop_1 = function (i) {
- var _loop_2 = function (j) {
- var current = grid[i].cells()[j];
- var isToReplace = comparator(current.element(), cell.element());
- if (isToReplace) {
- if (replacement.isNone()) {
- replacement = Option.some(substitution());
- }
- replacement.each(function (sub) {
- mutateCell(grid[i], j, elementnew(sub, true));
- });
- }
- };
- for (var j = 0; j < cellLength(grid[0]); j++) {
- _loop_2(j);
- }
- };
- for (var i = index; i < grid.length; i++) {
- _loop_1(i);
- }
- });
- }
- return grid;
- };
- var isSpanning = function (grid, row, col, comparator) {
- var candidate = getCell(grid[row], col);
- var matching = curry(comparator, candidate.element());
- var currentRow = grid[row];
- return grid.length > 1 && cellLength(currentRow) > 1 && (col > 0 && matching(getCellElement(currentRow, col - 1)) || col < currentRow.cells().length - 1 && matching(getCellElement(currentRow, col + 1)) || row > 0 && matching(getCellElement(grid[row - 1], col)) || row < grid.length - 1 && matching(getCellElement(grid[row + 1], col)));
- };
- var mergeTables = function (startAddress, gridA, gridB, generator, comparator) {
- var startRow = startAddress.row();
- var startCol = startAddress.column();
- var mergeHeight = gridB.length;
- var mergeWidth = cellLength(gridB[0]);
- var endRow = startRow + mergeHeight;
- var endCol = startCol + mergeWidth;
- for (var r = startRow; r < endRow; r++) {
- for (var c = startCol; c < endCol; c++) {
- if (isSpanning(gridA, r, c, comparator)) {
- unmerge(gridA, getCellElement(gridA[r], c), comparator, generator.cell);
- }
- var newCell = getCellElement(gridB[r - startRow], c - startCol);
- var replacement = generator.replace(newCell);
- mutateCell(gridA[r], c, elementnew(replacement, true));
- }
- }
- return gridA;
- };
- var merge$1 = function (startAddress, gridA, gridB, generator, comparator) {
- var result = measure(startAddress, gridA, gridB);
- return result.map(function (delta) {
- var fittedGrid = tailor(gridA, delta, generator);
- return mergeTables(startAddress, fittedGrid, gridB, generator, comparator);
- });
- };
- var insert = function (index, gridA, gridB, generator, comparator) {
- splitRows(gridA, index, comparator, generator.cell);
- var delta = measureWidth(gridB, gridA);
- var fittedNewGrid = tailor(gridB, delta, generator);
- var secondDelta = measureWidth(gridA, fittedNewGrid);
- var fittedOldGrid = tailor(gridA, secondDelta, generator);
- return fittedOldGrid.slice(0, index).concat(fittedNewGrid).concat(fittedOldGrid.slice(index, fittedOldGrid.length));
- };
- var insertRowAt = function (grid, index, example, comparator, substitution) {
- var before = grid.slice(0, index);
- var after = grid.slice(index);
- var between = mapCells(grid[example], function (ex, c) {
- var withinSpan = index > 0 && index < grid.length && comparator(getCellElement(grid[index - 1], c), getCellElement(grid[index], c));
- var ret = withinSpan ? getCell(grid[index], c) : elementnew(substitution(ex.element(), comparator), true);
- return ret;
- });
- return before.concat([between]).concat(after);
- };
- var insertColumnAt = function (grid, index, example, comparator, substitution) {
- return map(grid, function (row) {
- var withinSpan = index > 0 && index < cellLength(row) && comparator(getCellElement(row, index - 1), getCellElement(row, index));
- var sub = withinSpan ? getCell(row, index) : elementnew(substitution(getCellElement(row, example), comparator), true);
- return addCell(row, index, sub);
- });
- };
- var deleteColumnsAt = function (grid, start, finish) {
- var rows = map(grid, function (row) {
- var cells = row.cells().slice(0, start).concat(row.cells().slice(finish + 1));
- return rowcells(cells, row.section());
- });
- return filter(rows, function (row) {
- return row.cells().length > 0;
- });
- };
- var deleteRowsAt = function (grid, start, finish) {
- return grid.slice(0, start).concat(grid.slice(finish + 1));
- };
- var replaceIn = function (grid, targets, comparator, substitution) {
- var isTarget = function (cell) {
- return exists(targets, function (target) {
- return comparator(cell.element(), target.element());
- });
- };
- return map(grid, function (row) {
- return mapCells(row, function (cell) {
- return isTarget(cell) ? elementnew(substitution(cell.element(), comparator), true) : cell;
- });
- });
- };
- var notStartRow = function (grid, rowIndex, colIndex, comparator) {
- return getCellElement(grid[rowIndex], colIndex) !== undefined && (rowIndex > 0 && comparator(getCellElement(grid[rowIndex - 1], colIndex), getCellElement(grid[rowIndex], colIndex)));
- };
- var notStartColumn = function (row, index, comparator) {
- return index > 0 && comparator(getCellElement(row, index - 1), getCellElement(row, index));
- };
- var replaceColumn = function (grid, index, comparator, substitution) {
- var targets = bind(grid, function (row, i) {
- var alreadyAdded = notStartRow(grid, i, index, comparator) || notStartColumn(row, index, comparator);
- return alreadyAdded ? [] : [getCell(row, index)];
- });
- return replaceIn(grid, targets, comparator, substitution);
- };
- var replaceRow = function (grid, index, comparator, substitution) {
- var targetRow = grid[index];
- var targets = bind(targetRow.cells(), function (item, i) {
- var alreadyAdded = notStartRow(grid, index, i, comparator) || notStartColumn(targetRow, i, comparator);
- return alreadyAdded ? [] : [item];
- });
- return replaceIn(grid, targets, comparator, substitution);
- };
- var adt = Adt.generate([
- { none: [] },
- { only: ['index'] },
- {
- left: [
- 'index',
- 'next'
- ]
- },
- {
- middle: [
- 'prev',
- 'index',
- 'next'
- ]
- },
- {
- right: [
- 'prev',
- 'index'
- ]
- }
- ]);
- var ColumnContext = __assign({}, adt);
- var neighbours$1 = function (input, index) {
- if (input.length === 0) {
- return ColumnContext.none();
- }
- if (input.length === 1) {
- return ColumnContext.only(0);
- }
- if (index === 0) {
- return ColumnContext.left(0, 1);
- }
- if (index === input.length - 1) {
- return ColumnContext.right(index - 1, index);
- }
- if (index > 0 && index < input.length - 1) {
- return ColumnContext.middle(index - 1, index, index + 1);
- }
- return ColumnContext.none();
- };
- var determine = function (input, column, step, tableSize) {
- var result = input.slice(0);
- var context = neighbours$1(input, column);
- var zero = function (array) {
- return map(array, constant(0));
- };
- var onNone = constant(zero(result));
- var onOnly = function (index) {
- return tableSize.singleColumnWidth(result[index], step);
- };
- var onChange = function (index, next) {
- if (step >= 0) {
- var newNext = Math.max(tableSize.minCellWidth(), result[next] - step);
- return zero(result.slice(0, index)).concat([
- step,
- newNext - result[next]
- ]).concat(zero(result.slice(next + 1)));
- } else {
- var newThis = Math.max(tableSize.minCellWidth(), result[index] + step);
- var diffx = result[index] - newThis;
- return zero(result.slice(0, index)).concat([
- newThis - result[index],
- diffx
- ]).concat(zero(result.slice(next + 1)));
- }
- };
- var onLeft = onChange;
- var onMiddle = function (_prev, index, next) {
- return onChange(index, next);
- };
- var onRight = function (_prev, index) {
- if (step >= 0) {
- return zero(result.slice(0, index)).concat([step]);
- } else {
- var size = Math.max(tableSize.minCellWidth(), result[index] + step);
- return zero(result.slice(0, index)).concat([size - result[index]]);
- }
- };
- return context.fold(onNone, onOnly, onLeft, onMiddle, onRight);
- };
- var getWidthFrom = function (warehouse, direction, getWidth, fallback, tableSize) {
- var columns$1 = columns(warehouse);
- var backups = map(columns$1, function (cellOption) {
- return cellOption.map(direction.edge);
- });
- return map(columns$1, function (cellOption, c) {
- var columnCell = cellOption.filter(not(hasColspan));
- return columnCell.fold(function () {
- var deduced = deduce(backups, c);
- return fallback(deduced);
- }, function (cell) {
- return getWidth(cell, tableSize);
- });
- });
- };
- var getPercentageWidths = function (warehouse, direction, tableSize) {
- return getWidthFrom(warehouse, direction, getPercentageWidth, function (deduced) {
- return deduced.fold(function () {
- return tableSize.minCellWidth();
- }, function (cellWidth) {
- return cellWidth / tableSize.pixelWidth() * 100;
- });
- }, tableSize);
- };
- var getPixelWidths = function (warehouse, direction, tableSize) {
- return getWidthFrom(warehouse, direction, getPixelWidth, function (deduced) {
- return deduced.getOrThunk(tableSize.minCellWidth);
- }, tableSize);
- };
- var getHeightFrom = function (warehouse, direction, getHeight, fallback) {
- var rows = rows$1(warehouse);
- var backups = map(rows, function (cellOption) {
- return cellOption.map(direction.edge);
- });
- return map(rows, function (cellOption, c) {
- var rowCell = cellOption.filter(not(hasRowspan));
- return rowCell.fold(function () {
- var deduced = deduce(backups, c);
- return fallback(deduced);
- }, function (cell) {
- return getHeight(cell);
- });
- });
- };
- var getPixelHeights = function (warehouse, direction) {
- return getHeightFrom(warehouse, direction, getHeight$1, function (deduced) {
- return deduced.getOrThunk(minHeight);
- });
- };
- var total = function (start, end, measures) {
- var r = 0;
- for (var i = start; i < end; i++) {
- r += measures[i] !== undefined ? measures[i] : 0;
- }
- return r;
- };
- var recalculateWidth = function (warehouse, widths) {
- var all = Warehouse.justCells(warehouse);
- return map(all, function (cell) {
- var width = total(cell.column(), cell.column() + cell.colspan(), widths);
- return {
- element: cell.element(),
- width: width,
- colspan: cell.colspan()
- };
- });
- };
- var recalculateHeight = function (warehouse, heights) {
- var all = Warehouse.justCells(warehouse);
- return map(all, function (cell) {
- var height = total(cell.row(), cell.row() + cell.rowspan(), heights);
- return {
- element: cell.element,
- height: constant(height),
- rowspan: cell.rowspan
- };
- });
- };
- var matchRowHeight = function (warehouse, heights) {
- return map(warehouse.all, function (row, i) {
- return {
- element: row.element,
- height: constant(heights[i])
- };
- });
- };
- var percentageSize = function (width, element) {
- var floatWidth = parseFloat(width);
- var pixelWidth = get$5(element);
- var getCellDelta = function (delta) {
- return delta / pixelWidth * 100;
- };
- var singleColumnWidth = function (w, _delta) {
- return [100 - w];
- };
- var minCellWidth = function () {
- return minWidth() / pixelWidth * 100;
- };
- var setTableWidth = function (table, _newWidths, delta) {
- var ratio = delta / 100;
- var change = ratio * floatWidth;
- setPercentageWidth(table, floatWidth + change);
- };
- return {
- width: constant(floatWidth),
- pixelWidth: constant(pixelWidth),
- getWidths: getPercentageWidths,
- getCellDelta: getCellDelta,
- singleColumnWidth: singleColumnWidth,
- minCellWidth: minCellWidth,
- setElementWidth: setPercentageWidth,
- setTableWidth: setTableWidth
- };
- };
- var pixelSize = function (width) {
- var getCellDelta = identity;
- var singleColumnWidth = function (w, delta) {
- var newNext = Math.max(minWidth(), w + delta);
- return [newNext - w];
- };
- var setTableWidth = function (table, newWidths, _delta) {
- var total = foldr(newWidths, function (b, a) {
- return b + a;
- }, 0);
- setPixelWidth(table, total);
- };
- return {
- width: constant(width),
- pixelWidth: constant(width),
- getWidths: getPixelWidths,
- getCellDelta: getCellDelta,
- singleColumnWidth: singleColumnWidth,
- minCellWidth: minWidth,
- setElementWidth: setPixelWidth,
- setTableWidth: setTableWidth
- };
- };
- var chooseSize = function (element, width) {
- var percentMatch = percentageBasedSizeRegex().exec(width);
- if (percentMatch !== null) {
- return percentageSize(percentMatch[1], element);
- }
- var pixelMatch = pixelBasedSizeRegex().exec(width);
- if (pixelMatch !== null) {
- var intWidth = parseInt(pixelMatch[1], 10);
- return pixelSize(intWidth);
- }
- var fallbackWidth = get$5(element);
- return pixelSize(fallbackWidth);
- };
- var getTableSize = function (element) {
- var width = getRawWidth(element);
- return width.fold(function () {
- var fallbackWidth = get$5(element);
- return pixelSize(fallbackWidth);
- }, function (w) {
- return chooseSize(element, w);
- });
- };
- var getWarehouse$1 = function (list) {
- return Warehouse.generate(list);
- };
- var sumUp = function (newSize) {
- return foldr(newSize, function (b, a) {
- return b + a;
- }, 0);
- };
- var getTableWarehouse = function (table) {
- var list = fromTable(table);
- return getWarehouse$1(list);
- };
- var adjustWidth = function (table, delta, index, direction) {
- var tableSize = getTableSize(table);
- var step = tableSize.getCellDelta(delta);
- var warehouse = getTableWarehouse(table);
- var widths = tableSize.getWidths(warehouse, direction, tableSize);
- var deltas = determine(widths, index, step, tableSize);
- var newWidths = map(deltas, function (dx, i) {
- return dx + widths[i];
- });
- var newSizes = recalculateWidth(warehouse, newWidths);
- each(newSizes, function (cell) {
- tableSize.setElementWidth(cell.element, cell.width);
- });
- if (index === warehouse.grid.columns() - 1) {
- tableSize.setTableWidth(table, newWidths, step);
- }
- };
- var adjustHeight = function (table, delta, index, direction) {
- var warehouse = getTableWarehouse(table);
- var heights = getPixelHeights(warehouse, direction);
- var newHeights = map(heights, function (dy, i) {
- return index === i ? Math.max(delta + dy, minHeight()) : dy;
- });
- var newCellSizes = recalculateHeight(warehouse, newHeights);
- var newRowSizes = matchRowHeight(warehouse, newHeights);
- each(newRowSizes, function (row) {
- setHeight(row.element(), row.height());
- });
- each(newCellSizes, function (cell) {
- setHeight(cell.element(), cell.height());
- });
- var total = sumUp(newHeights);
- setHeight(table, total);
- };
- var adjustWidthTo = function (table, list, direction) {
- var tableSize = getTableSize(table);
- var warehouse = getWarehouse$1(list);
- var widths = tableSize.getWidths(warehouse, direction, tableSize);
- var newSizes = recalculateWidth(warehouse, widths);
- each(newSizes, function (cell) {
- tableSize.setElementWidth(cell.element, cell.width);
- });
- if (newSizes.length > 0) {
- tableSize.setTableWidth(table, widths, tableSize.getCellDelta(0));
- }
- };
- var sort = function (arr) {
- return arr.slice(0).sort();
- };
- var reqMessage = function (required, keys) {
- throw new Error('All required keys (' + sort(required).join(', ') + ') were not specified. Specified keys were: ' + sort(keys).join(', ') + '.');
- };
- var unsuppMessage = function (unsupported) {
- throw new Error('Unsupported keys for object: ' + sort(unsupported).join(', '));
- };
- var validateStrArr = function (label, array) {
- if (!isArray(array)) {
- throw new Error('The ' + label + ' fields must be an array. Was: ' + array + '.');
- }
- each(array, function (a) {
- if (!isString(a)) {
- throw new Error('The value ' + a + ' in the ' + label + ' fields was not a string.');
- }
- });
- };
- var invalidTypeMessage = function (incorrect, type) {
- throw new Error('All values need to be of type: ' + type + '. Keys (' + sort(incorrect).join(', ') + ') were not.');
- };
- var checkDupes = function (everything) {
- var sorted = sort(everything);
- var dupe = find(sorted, function (s, i) {
- return i < sorted.length - 1 && s === sorted[i + 1];
- });
- dupe.each(function (d) {
- throw new Error('The field: ' + d + ' occurs more than once in the combined fields: [' + sorted.join(', ') + '].');
- });
- };
- var base = function (handleUnsupported, required) {
- return baseWith(handleUnsupported, required, {
- validate: isFunction,
- label: 'function'
- });
- };
- var baseWith = function (handleUnsupported, required, pred) {
- if (required.length === 0) {
- throw new Error('You must specify at least one required field.');
- }
- validateStrArr('required', required);
- checkDupes(required);
- return function (obj) {
- var keys$1 = keys(obj);
- var allReqd = forall(required, function (req) {
- return contains(keys$1, req);
- });
- if (!allReqd) {
- reqMessage(required, keys$1);
- }
- handleUnsupported(required, keys$1);
- var invalidKeys = filter(required, function (key) {
- return !pred.validate(obj[key], key);
- });
- if (invalidKeys.length > 0) {
- invalidTypeMessage(invalidKeys, pred.label);
- }
- return obj;
- };
- };
- var handleExact = function (required, keys) {
- var unsupported = filter(keys, function (key) {
- return !contains(required, key);
- });
- if (unsupported.length > 0) {
- unsuppMessage(unsupported);
- }
- };
- var exactly = function (required) {
- return base(handleExact, required);
- };
- var verifyGenerators = exactly([
- 'cell',
- 'row',
- 'replace',
- 'gap'
- ]);
- var elementToData = function (element) {
- var colspan = getAttrValue(element, 'colspan', 1);
- var rowspan = getAttrValue(element, 'rowspan', 1);
- return {
- element: constant(element),
- colspan: constant(colspan),
- rowspan: constant(rowspan)
- };
- };
- var modification = function (generators, toData) {
- if (toData === void 0) {
- toData = elementToData;
- }
- verifyGenerators(generators);
- var position = Cell(Option.none());
- var nu = function (data) {
- return generators.cell(data);
- };
- var nuFrom = function (element) {
- var data = toData(element);
- return nu(data);
- };
- var add = function (element) {
- var replacement = nuFrom(element);
- if (position.get().isNone()) {
- position.set(Option.some(replacement));
- }
- recent = Option.some({
- item: element,
- replacement: replacement
- });
- return replacement;
- };
- var recent = Option.none();
- var getOrInit = function (element, comparator) {
- return recent.fold(function () {
- return add(element);
- }, function (p) {
- return comparator(element, p.item) ? p.replacement : add(element);
- });
- };
- return {
- getOrInit: getOrInit,
- cursor: position.get
- };
- };
- var transform = function (scope, tag) {
- return function (generators) {
- var position = Cell(Option.none());
- verifyGenerators(generators);
- var list = [];
- var find$1 = function (element, comparator) {
- return find(list, function (x) {
- return comparator(x.item, element);
- });
- };
- var makeNew = function (element) {
- var attrs = { scope: scope };
- var cell = generators.replace(element, tag, attrs);
- list.push({
- item: element,
- sub: cell
- });
- if (position.get().isNone()) {
- position.set(Option.some(cell));
- }
- return cell;
- };
- var replaceOrInit = function (element, comparator) {
- return find$1(element, comparator).fold(function () {
- return makeNew(element);
- }, function (p) {
- return comparator(element, p.item) ? p.sub : makeNew(element);
- });
- };
- return {
- replaceOrInit: replaceOrInit,
- cursor: position.get
- };
- };
- };
- var merging = function (generators) {
- verifyGenerators(generators);
- var position = Cell(Option.none());
- var combine = function (cell) {
- if (position.get().isNone()) {
- position.set(Option.some(cell));
- }
- return function () {
- var raw = generators.cell({
- element: constant(cell),
- colspan: constant(1),
- rowspan: constant(1)
- });
- remove$1(raw, 'width');
- remove$1(cell, 'width');
- return raw;
- };
- };
- return {
- combine: combine,
- cursor: position.get
- };
- };
- var Generators = {
- modification: modification,
- transform: transform,
- merging: merging
- };
- var blockList = [
- 'body',
- 'p',
- 'div',
- 'article',
- 'aside',
- 'figcaption',
- 'figure',
- 'footer',
- 'header',
- 'nav',
- 'section',
- 'ol',
- 'ul',
- 'table',
- 'thead',
- 'tfoot',
- 'tbody',
- 'caption',
- 'tr',
- 'td',
- 'th',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'blockquote',
- 'pre',
- 'address'
- ];
- var isList = function (universe, item) {
- var tagName = universe.property().name(item);
- return contains([
- 'ol',
- 'ul'
- ], tagName);
- };
- var isBlock = function (universe, item) {
- var tagName = universe.property().name(item);
- return contains(blockList, tagName);
- };
- var isEmptyTag = function (universe, item) {
- return contains([
- 'br',
- 'img',
- 'hr',
- 'input'
- ], universe.property().name(item));
- };
- var universe$1 = DomUniverse();
- var isBlock$1 = function (element) {
- return isBlock(universe$1, element);
- };
- var isList$1 = function (element) {
- return isList(universe$1, element);
- };
- var isEmptyTag$1 = function (element) {
- return isEmptyTag(universe$1, element);
- };
- var merge$2 = function (cells) {
- var isBr = function (el) {
- return name(el) === 'br';
- };
- var advancedBr = function (children) {
- return forall(children, function (c) {
- return isBr(c) || isText(c) && get$3(c).trim().length === 0;
- });
- };
- var isListItem = function (el) {
- return name(el) === 'li' || ancestor(el, isList$1).isSome();
- };
- var siblingIsBlock = function (el) {
- return nextSibling(el).map(function (rightSibling) {
- if (isBlock$1(rightSibling)) {
- return true;
- }
- if (isEmptyTag$1(rightSibling)) {
- return name(rightSibling) === 'img' ? false : true;
- }
- return false;
- }).getOr(false);
- };
- var markCell = function (cell) {
- return last$1(cell).bind(function (rightEdge) {
- var rightSiblingIsBlock = siblingIsBlock(rightEdge);
- return parent(rightEdge).map(function (parent) {
- return rightSiblingIsBlock === true || isListItem(parent) || isBr(rightEdge) || isBlock$1(parent) && !eq(cell, parent) ? [] : [Element.fromTag('br')];
- });
- }).getOr([]);
- };
- var markContent = function () {
- var content = bind(cells, function (cell) {
- var children$1 = children(cell);
- return advancedBr(children$1) ? [] : children$1.concat(markCell(cell));
- });
- return content.length === 0 ? [Element.fromTag('br')] : content;
- };
- var contents = markContent();
- empty(cells[0]);
- append$1(cells[0], contents);
- };
- var prune = function (table) {
- var cells$1 = cells(table);
- if (cells$1.length === 0) {
- remove$2(table);
- }
- };
- var outcome = function (grid, cursor) {
- return {
- grid: constant(grid),
- cursor: constant(cursor)
- };
- };
- var elementFromGrid = function (grid, row, column) {
- return findIn(grid, row, column).orThunk(function () {
- return findIn(grid, 0, 0);
- });
- };
- var findIn = function (grid, row, column) {
- return Option.from(grid[row]).bind(function (r) {
- return Option.from(r.cells()[column]).bind(function (c) {
- return Option.from(c.element());
- });
- });
- };
- var bundle = function (grid, row, column) {
- return outcome(grid, findIn(grid, row, column));
- };
- var uniqueRows = function (details) {
- return foldl(details, function (rest, detail) {
- return exists(rest, function (currentDetail) {
- return currentDetail.row() === detail.row();
- }) ? rest : rest.concat([detail]);
- }, []).sort(function (detailA, detailB) {
- return detailA.row() - detailB.row();
- });
- };
- var uniqueColumns = function (details) {
- return foldl(details, function (rest, detail) {
- return exists(rest, function (currentDetail) {
- return currentDetail.column() === detail.column();
- }) ? rest : rest.concat([detail]);
- }, []).sort(function (detailA, detailB) {
- return detailA.column() - detailB.column();
- });
- };
- var opInsertRowsBefore = function (grid, details, comparator, genWrappers) {
- var example = details[0].row();
- var targetIndex = details[0].row();
- var rows = uniqueRows(details);
- var newGrid = foldl(rows, function (newG, _row) {
- return insertRowAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
- }, grid);
- return bundle(newGrid, targetIndex, details[0].column());
- };
- var opInsertRowsAfter = function (grid, details, comparator, genWrappers) {
- var rows = uniqueRows(details);
- var example = rows[rows.length - 1].row();
- var targetIndex = rows[rows.length - 1].row() + rows[rows.length - 1].rowspan();
- var newGrid = foldl(rows, function (newG, _row) {
- return insertRowAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
- }, grid);
- return bundle(newGrid, targetIndex, details[0].column());
- };
- var opInsertColumnsBefore = function (grid, details, comparator, genWrappers) {
- var columns = uniqueColumns(details);
- var example = columns[0].column();
- var targetIndex = columns[0].column();
- var newGrid = foldl(columns, function (newG, _row) {
- return insertColumnAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
- }, grid);
- return bundle(newGrid, details[0].row(), targetIndex);
- };
- var opInsertColumnsAfter = function (grid, details, comparator, genWrappers) {
- var example = details[details.length - 1].column();
- var targetIndex = details[details.length - 1].column() + details[details.length - 1].colspan();
- var columns = uniqueColumns(details);
- var newGrid = foldl(columns, function (newG, _row) {
- return insertColumnAt(newG, targetIndex, example, comparator, genWrappers.getOrInit);
- }, grid);
- return bundle(newGrid, details[0].row(), targetIndex);
- };
- var opMakeRowHeader = function (grid, detail, comparator, genWrappers) {
- var newGrid = replaceRow(grid, detail.row(), comparator, genWrappers.replaceOrInit);
- return bundle(newGrid, detail.row(), detail.column());
- };
- var opMakeColumnHeader = function (grid, detail, comparator, genWrappers) {
- var newGrid = replaceColumn(grid, detail.column(), comparator, genWrappers.replaceOrInit);
- return bundle(newGrid, detail.row(), detail.column());
- };
- var opUnmakeRowHeader = function (grid, detail, comparator, genWrappers) {
- var newGrid = replaceRow(grid, detail.row(), comparator, genWrappers.replaceOrInit);
- return bundle(newGrid, detail.row(), detail.column());
- };
- var opUnmakeColumnHeader = function (grid, detail, comparator, genWrappers) {
- var newGrid = replaceColumn(grid, detail.column(), comparator, genWrappers.replaceOrInit);
- return bundle(newGrid, detail.row(), detail.column());
- };
- var opEraseColumns = function (grid, details, _comparator, _genWrappers) {
- var columns = uniqueColumns(details);
- var newGrid = deleteColumnsAt(grid, columns[0].column(), columns[columns.length - 1].column());
- var cursor = elementFromGrid(newGrid, details[0].row(), details[0].column());
- return outcome(newGrid, cursor);
- };
- var opEraseRows = function (grid, details, _comparator, _genWrappers) {
- var rows = uniqueRows(details);
- var newGrid = deleteRowsAt(grid, rows[0].row(), rows[rows.length - 1].row());
- var cursor = elementFromGrid(newGrid, details[0].row(), details[0].column());
- return outcome(newGrid, cursor);
- };
- var opMergeCells = function (grid, mergable, comparator, _genWrappers) {
- var cells = mergable.cells();
- merge$2(cells);
- var newGrid = merge(grid, mergable.bounds(), comparator, constant(cells[0]));
- return outcome(newGrid, Option.from(cells[0]));
- };
- var opUnmergeCells = function (grid, unmergable, comparator, genWrappers) {
- var newGrid = foldr(unmergable, function (b, cell) {
- return unmerge(b, cell, comparator, genWrappers.combine(cell));
- }, grid);
- return outcome(newGrid, Option.from(unmergable[0]));
- };
- var opPasteCells = function (grid, pasteDetails, comparator, _genWrappers) {
- var gridify = function (table, generators) {
- var list = fromTable(table);
- var wh = Warehouse.generate(list);
- return toGrid(wh, generators, true);
- };
- var gridB = gridify(pasteDetails.clipboard(), pasteDetails.generators());
- var startAddress = address(pasteDetails.row(), pasteDetails.column());
- var mergedGrid = merge$1(startAddress, grid, gridB, pasteDetails.generators(), comparator);
- return mergedGrid.fold(function () {
- return outcome(grid, Option.some(pasteDetails.element()));
- }, function (nuGrid) {
- var cursor = elementFromGrid(nuGrid, pasteDetails.row(), pasteDetails.column());
- return outcome(nuGrid, cursor);
- });
- };
- var gridifyRows = function (rows, generators, example) {
- var pasteDetails = fromPastedRows(rows, example);
- var wh = Warehouse.generate(pasteDetails);
- return toGrid(wh, generators, true);
- };
- var opPasteRowsBefore = function (grid, pasteDetails, comparator, _genWrappers) {
- var example = grid[pasteDetails.cells[0].row()];
- var index = pasteDetails.cells[0].row();
- var gridB = gridifyRows(pasteDetails.clipboard(), pasteDetails.generators(), example);
- var mergedGrid = insert(index, grid, gridB, pasteDetails.generators(), comparator);
- var cursor = elementFromGrid(mergedGrid, pasteDetails.cells[0].row(), pasteDetails.cells[0].column());
- return outcome(mergedGrid, cursor);
- };
- var opPasteRowsAfter = function (grid, pasteDetails, comparator, _genWrappers) {
- var example = grid[pasteDetails.cells[0].row()];
- var index = pasteDetails.cells[pasteDetails.cells.length - 1].row() + pasteDetails.cells[pasteDetails.cells.length - 1].rowspan();
- var gridB = gridifyRows(pasteDetails.clipboard(), pasteDetails.generators(), example);
- var mergedGrid = insert(index, grid, gridB, pasteDetails.generators(), comparator);
- var cursor = elementFromGrid(mergedGrid, pasteDetails.cells[0].row(), pasteDetails.cells[0].column());
- return outcome(mergedGrid, cursor);
- };
- var resize = adjustWidthTo;
- var insertRowsBefore = run(opInsertRowsBefore, onCells, noop, noop, Generators.modification);
- var insertRowsAfter = run(opInsertRowsAfter, onCells, noop, noop, Generators.modification);
- var insertColumnsBefore = run(opInsertColumnsBefore, onCells, resize, noop, Generators.modification);
- var insertColumnsAfter = run(opInsertColumnsAfter, onCells, resize, noop, Generators.modification);
- var eraseColumns = run(opEraseColumns, onCells, resize, prune, Generators.modification);
- var eraseRows = run(opEraseRows, onCells, noop, prune, Generators.modification);
- var makeColumnHeader = run(opMakeColumnHeader, onCell, noop, noop, Generators.transform('row', 'th'));
- var unmakeColumnHeader = run(opUnmakeColumnHeader, onCell, noop, noop, Generators.transform(null, 'td'));
- var makeRowHeader = run(opMakeRowHeader, onCell, noop, noop, Generators.transform('col', 'th'));
- var unmakeRowHeader = run(opUnmakeRowHeader, onCell, noop, noop, Generators.transform(null, 'td'));
- var mergeCells = run(opMergeCells, onMergable, noop, noop, Generators.merging);
- var unmergeCells = run(opUnmergeCells, onUnmergable, resize, noop, Generators.merging);
- var pasteCells = run(opPasteCells, onPaste, resize, noop, Generators.modification);
- var pasteRowsBefore = run(opPasteRowsBefore, onPasteRows, noop, noop, Generators.modification);
- var pasteRowsAfter = run(opPasteRowsAfter, onPasteRows, noop, noop, Generators.modification);
- var getBody$1 = function (editor) {
- return Element.fromDom(editor.getBody());
- };
- var getPixelWidth$1 = function (elm) {
- return elm.getBoundingClientRect().width;
- };
- var getPixelHeight = function (elm) {
- return elm.getBoundingClientRect().height;
- };
- var getIsRoot = function (editor) {
- return function (element) {
- return eq(element, getBody$1(editor));
- };
- };
- var removePxSuffix = function (size) {
- return size ? size.replace(/px$/, '') : '';
- };
- var addSizeSuffix = function (size) {
- if (/^[0-9]+$/.test(size)) {
- size += 'px';
- }
- return size;
- };
- var removeDataStyle = function (table) {
- var dataStyleCells = descendants$1(table, 'td[data-mce-style],th[data-mce-style]');
- remove(table, 'data-mce-style');
- each(dataStyleCells, function (cell) {
- remove(cell, 'data-mce-style');
- });
- };
- var getDirection = function (element) {
- return get$2(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
- };
- var ltr$1 = { isRtl: constant(false) };
- var rtl$1 = { isRtl: constant(true) };
- var directionAt = function (element) {
- var dir = getDirection(element);
- return dir === 'rtl' ? rtl$1 : ltr$1;
- };
- var defaultTableToolbar = 'tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol';
- var defaultStyles = {
- 'border-collapse': 'collapse',
- 'width': '100%'
- };
- var defaultAttributes = { border: '1' };
- var getDefaultAttributes = function (editor) {
- return editor.getParam('table_default_attributes', defaultAttributes, 'object');
- };
- var getDefaultStyles = function (editor) {
- return editor.getParam('table_default_styles', defaultStyles, 'object');
- };
- var hasTableResizeBars = function (editor) {
- return editor.getParam('table_resize_bars', true, 'boolean');
- };
- var hasTabNavigation = function (editor) {
- return editor.getParam('table_tab_navigation', true, 'boolean');
- };
- var hasAdvancedCellTab = function (editor) {
- return editor.getParam('table_cell_advtab', true, 'boolean');
- };
- var hasAdvancedRowTab = function (editor) {
- return editor.getParam('table_row_advtab', true, 'boolean');
- };
- var hasAdvancedTableTab = function (editor) {
- return editor.getParam('table_advtab', true, 'boolean');
- };
- var hasAppearanceOptions = function (editor) {
- return editor.getParam('table_appearance_options', true, 'boolean');
- };
- var hasTableGrid = function (editor) {
- return editor.getParam('table_grid', true, 'boolean');
- };
- var shouldStyleWithCss = function (editor) {
- return editor.getParam('table_style_by_css', false, 'boolean');
- };
- var getCellClassList = function (editor) {
- return editor.getParam('table_cell_class_list', [], 'array');
- };
- var getRowClassList = function (editor) {
- return editor.getParam('table_row_class_list', [], 'array');
- };
- var getTableClassList = function (editor) {
- return editor.getParam('table_class_list', [], 'array');
- };
- var isPercentagesForced = function (editor) {
- return editor.getParam('table_responsive_width') === true;
- };
- var isPixelsForced = function (editor) {
- return editor.getParam('table_responsive_width') === false;
- };
- var getToolbar = function (editor) {
- return editor.getParam('table_toolbar', defaultTableToolbar);
- };
- var getCloneElements = function (editor) {
- var cloneElements = editor.getParam('table_clone_elements');
- if (isString(cloneElements)) {
- return Option.some(cloneElements.split(/[ ,]/));
- } else if (Array.isArray(cloneElements)) {
- return Option.some(cloneElements);
- } else {
- return Option.none();
- }
- };
- var hasObjectResizing = function (editor) {
- var objectResizing = editor.getParam('object_resizing', true);
- return isString(objectResizing) ? objectResizing === 'table' : objectResizing;
- };
- var fireNewRow = function (editor, row) {
- return editor.fire('newrow', { node: row });
- };
- var fireNewCell = function (editor, cell) {
- return editor.fire('newcell', { node: cell });
- };
- var fireObjectResizeStart = function (editor, target, width, height) {
- editor.fire('ObjectResizeStart', {
- target: target,
- width: width,
- height: height
- });
- };
- var fireObjectResized = function (editor, target, width, height) {
- editor.fire('ObjectResized', {
- target: target,
- width: width,
- height: height
- });
- };
- var fireTableSelectionChange = function (editor, cells, start, finish, otherCells) {
- editor.fire('TableSelectionChange', {
- cells: cells,
- start: start,
- finish: finish,
- otherCells: otherCells
- });
- };
- var fireTableSelectionClear = function (editor) {
- editor.fire('TableSelectionClear');
- };
- var point = function (element, offset) {
- return {
- element: constant(element),
- offset: constant(offset)
- };
- };
- var scan = function (universe, element, direction) {
- if (universe.property().isText(element) && universe.property().getText(element).trim().length === 0 || universe.property().isComment(element)) {
- return direction(element).bind(function (elem) {
- return scan(universe, elem, direction).orThunk(function () {
- return Option.some(elem);
- });
- });
- } else {
- return Option.none();
- }
- };
- var toEnd = function (universe, element) {
- if (universe.property().isText(element)) {
- return universe.property().getText(element).length;
- }
- var children = universe.property().children(element);
- return children.length;
- };
- var freefallRtl = function (universe, element) {
- var candidate = scan(universe, element, universe.query().prevSibling).getOr(element);
- if (universe.property().isText(candidate)) {
- return point(candidate, toEnd(universe, candidate));
- }
- var children = universe.property().children(candidate);
- return children.length > 0 ? freefallRtl(universe, children[children.length - 1]) : point(candidate, toEnd(universe, candidate));
- };
- var freefallRtl$1 = freefallRtl;
- var universe$2 = DomUniverse();
- var freefallRtl$2 = function (element) {
- return freefallRtl$1(universe$2, element);
- };
- var TableActions = function (editor, lazyWire) {
- var isTableBody = function (editor) {
- return name(getBody$1(editor)) === 'table';
- };
- var lastRowGuard = function (table) {
- var size = getGridSize(table);
- return isTableBody(editor) === false || size.rows() > 1;
- };
- var lastColumnGuard = function (table) {
- var size = getGridSize(table);
- return isTableBody(editor) === false || size.columns() > 1;
- };
- var cloneFormats = getCloneElements(editor);
- var execute = function (operation, guard, mutate, lazyWire) {
- return function (table, target) {
- removeDataStyle(table);
- var wire = lazyWire();
- var doc = Element.fromDom(editor.getDoc());
- var direction = TableDirection(directionAt);
- var generators = cellOperations(mutate, doc, cloneFormats);
- return guard(table) ? operation(wire, table, target, generators, direction).bind(function (result) {
- each(result.newRows(), function (row) {
- fireNewRow(editor, row.dom());
- });
- each(result.newCells(), function (cell) {
- fireNewCell(editor, cell.dom());
- });
- return result.cursor().map(function (cell) {
- var des = freefallRtl$2(cell);
- var rng = editor.dom.createRng();
- rng.setStart(des.element().dom(), des.offset());
- rng.setEnd(des.element().dom(), des.offset());
- return rng;
- });
- }) : Option.none();
- };
- };
- var deleteRow = execute(eraseRows, lastRowGuard, noop, lazyWire);
- var deleteColumn = execute(eraseColumns, lastColumnGuard, noop, lazyWire);
- var insertRowsBefore$1 = execute(insertRowsBefore, always, noop, lazyWire);
- var insertRowsAfter$1 = execute(insertRowsAfter, always, noop, lazyWire);
- var insertColumnsBefore$1 = execute(insertColumnsBefore, always, halve, lazyWire);
- var insertColumnsAfter$1 = execute(insertColumnsAfter, always, halve, lazyWire);
- var mergeCells$1 = execute(mergeCells, always, noop, lazyWire);
- var unmergeCells$1 = execute(unmergeCells, always, noop, lazyWire);
- var pasteRowsBefore$1 = execute(pasteRowsBefore, always, noop, lazyWire);
- var pasteRowsAfter$1 = execute(pasteRowsAfter, always, noop, lazyWire);
- var pasteCells$1 = execute(pasteCells, always, noop, lazyWire);
- return {
- deleteRow: deleteRow,
- deleteColumn: deleteColumn,
- insertRowsBefore: insertRowsBefore$1,
- insertRowsAfter: insertRowsAfter$1,
- insertColumnsBefore: insertColumnsBefore$1,
- insertColumnsAfter: insertColumnsAfter$1,
- mergeCells: mergeCells$1,
- unmergeCells: unmergeCells$1,
- pasteRowsBefore: pasteRowsBefore$1,
- pasteRowsAfter: pasteRowsAfter$1,
- pasteCells: pasteCells$1
- };
- };
- var copyRows = function (table, target, generators) {
- var list = fromTable(table);
- var house = Warehouse.generate(list);
- var details = onCells(house, target);
- return details.map(function (selectedCells) {
- var grid = toGrid(house, generators, false);
- var slicedGrid = grid.slice(selectedCells[0].row(), selectedCells[selectedCells.length - 1].row() + selectedCells[selectedCells.length - 1].rowspan());
- var slicedDetails = toDetailList(slicedGrid, generators);
- return copy$2(slicedDetails);
- });
- };
- var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
- var getSelectionStartFromSelector = function (selector) {
- return function (editor) {
- return Option.from(editor.dom.getParent(editor.selection.getStart(), selector)).map(Element.fromDom);
- };
- };
- var getSelectionStartCell = getSelectionStartFromSelector('th,td');
- var getSelectionStartCellOrCaption = getSelectionStartFromSelector('th,td,caption');
- var getTDTHOverallStyle = function (dom, elm, name) {
- var cells = dom.select('td,th', elm);
- var firstChildStyle;
- var checkChildren = function (firstChildStyle, elms) {
- for (var i = 0; i < elms.length; i++) {
- var currentStyle = dom.getStyle(elms[i], name);
- if (typeof firstChildStyle === 'undefined') {
- firstChildStyle = currentStyle;
- }
- if (firstChildStyle !== currentStyle) {
- return '';
- }
- }
- return firstChildStyle;
- };
- firstChildStyle = checkChildren(firstChildStyle, cells);
- return firstChildStyle;
- };
- var applyAlign = function (editor, elm, name) {
- if (name) {
- editor.formatter.apply('align' + name, {}, elm);
- }
- };
- var applyVAlign = function (editor, elm, name) {
- if (name) {
- editor.formatter.apply('valign' + name, {}, elm);
- }
- };
- var unApplyAlign = function (editor, elm) {
- global$1.each('left center right'.split(' '), function (name) {
- editor.formatter.remove('align' + name, {}, elm);
- });
- };
- var unApplyVAlign = function (editor, elm) {
- global$1.each('top middle bottom'.split(' '), function (name) {
- editor.formatter.remove('valign' + name, {}, elm);
- });
- };
- var buildListItems = function (inputList, itemCallback, startItems) {
- var appendItems = function (values, output) {
- output = output || [];
- global$1.each(values, function (item) {
- var menuItem = { text: item.text || item.title };
- if (item.menu) {
- menuItem.menu = appendItems(item.menu);
- } else {
- menuItem.value = item.value;
- if (itemCallback) {
- itemCallback(menuItem);
- }
- }
- output.push(menuItem);
- });
- return output;
- };
- return appendItems(inputList, startItems || []);
- };
- var extractAdvancedStyles = function (dom, elm) {
- var rgbToHex = function (value) {
- return startsWith(value, 'rgb') ? dom.toHex(value) : value;
- };
- var borderWidth = getRaw(Element.fromDom(elm), 'border-width').getOr('');
- var borderStyle = getRaw(Element.fromDom(elm), 'border-style').getOr('');
- var borderColor = getRaw(Element.fromDom(elm), 'border-color').map(rgbToHex).getOr('');
- var bgColor = getRaw(Element.fromDom(elm), 'background-color').map(rgbToHex).getOr('');
- return {
- borderwidth: borderWidth,
- borderstyle: borderStyle,
- bordercolor: borderColor,
- backgroundcolor: bgColor
- };
- };
- var getSharedValues = function (data) {
- var baseData = data[0];
- var comparisonData = data.slice(1);
- var keys$1 = keys(baseData);
- each(comparisonData, function (items) {
- each(keys$1, function (key) {
- each$1(items, function (itemValue, itemKey) {
- var comparisonValue = baseData[key];
- if (comparisonValue !== '' && key === itemKey) {
- if (comparisonValue !== itemValue) {
- baseData[key] = '';
- }
- }
- });
- });
- });
- return baseData;
- };
- var getAdvancedTab = function (dialogName) {
- var advTabItems = [
- {
- name: 'borderstyle',
- type: 'selectbox',
- label: 'Border style',
- items: [
- {
- text: 'Select...',
- value: ''
- },
- {
- text: 'Solid',
- value: 'solid'
- },
- {
- text: 'Dotted',
- value: 'dotted'
- },
- {
- text: 'Dashed',
- value: 'dashed'
- },
- {
- text: 'Double',
- value: 'double'
- },
- {
- text: 'Groove',
- value: 'groove'
- },
- {
- text: 'Ridge',
- value: 'ridge'
- },
- {
- text: 'Inset',
- value: 'inset'
- },
- {
- text: 'Outset',
- value: 'outset'
- },
- {
- text: 'None',
- value: 'none'
- },
- {
- text: 'Hidden',
- value: 'hidden'
- }
- ]
- },
- {
- name: 'bordercolor',
- type: 'colorinput',
- label: 'Border color'
- },
- {
- name: 'backgroundcolor',
- type: 'colorinput',
- label: 'Background color'
- }
- ];
- var borderWidth = {
- name: 'borderwidth',
- type: 'input',
- label: 'Border width'
- };
- var items = dialogName === 'cell' ? [borderWidth].concat(advTabItems) : advTabItems;
- return {
- title: 'Advanced',
- name: 'advanced',
- items: items
- };
- };
- var getAlignment = function (alignments, formatName, dataName, editor, elm) {
- var alignmentData = {};
- global$1.each(alignments.split(' '), function (name) {
- if (editor.formatter.matchNode(elm, formatName + name)) {
- alignmentData[dataName] = name;
- }
- });
- if (!alignmentData[dataName]) {
- alignmentData[dataName] = '';
- }
- return alignmentData;
- };
- var getHAlignment = curry(getAlignment, 'left center right');
- var getVAlignment = curry(getAlignment, 'top middle bottom');
- var extractDataFromSettings = function (editor, hasAdvTableTab) {
- var style = getDefaultStyles(editor);
- var attrs = getDefaultAttributes(editor);
- var extractAdvancedStyleData = function (dom) {
- var rgbToHex = function (value) {
- return startsWith(value, 'rgb') ? dom.toHex(value) : value;
- };
- var borderStyle = get(style, 'border-style').getOr('');
- var borderColor = get(style, 'border-color').getOr('');
- var bgColor = get(style, 'background-color').getOr('');
- return {
- borderstyle: borderStyle,
- bordercolor: rgbToHex(borderColor),
- backgroundcolor: rgbToHex(bgColor)
- };
- };
- var defaultData = {
- height: '',
- width: '100%',
- cellspacing: '',
- cellpadding: '',
- caption: false,
- class: '',
- align: '',
- border: ''
- };
- var getBorder = function () {
- var borderWidth = style['border-width'];
- if (shouldStyleWithCss(editor) && borderWidth) {
- return { border: borderWidth };
- }
- return get(attrs, 'border').fold(function () {
- return {};
- }, function (border) {
- return { border: border };
- });
- };
- var dom = editor.dom;
- var advStyle = hasAdvTableTab ? extractAdvancedStyleData(dom) : {};
- var getCellPaddingCellSpacing = function () {
- var spacing = get(style, 'border-spacing').or(get(attrs, 'cellspacing')).fold(function () {
- return {};
- }, function (cellspacing) {
- return { cellspacing: cellspacing };
- });
- var padding = get(style, 'border-padding').or(get(attrs, 'cellpadding')).fold(function () {
- return {};
- }, function (cellpadding) {
- return { cellpadding: cellpadding };
- });
- return __assign(__assign({}, spacing), padding);
- };
- var data = __assign(__assign(__assign(__assign(__assign(__assign({}, defaultData), style), attrs), advStyle), getBorder()), getCellPaddingCellSpacing());
- return data;
- };
- var extractDataFromTableElement = function (editor, elm, hasAdvTableTab) {
- var getBorder = function (dom, elm) {
- var optBorderWidth = getRaw(Element.fromDom(elm), 'border-width');
- if (shouldStyleWithCss(editor) && optBorderWidth.isSome()) {
- return optBorderWidth.getOr('');
- }
- return dom.getAttrib(elm, 'border') || getTDTHOverallStyle(editor.dom, elm, 'border-width') || getTDTHOverallStyle(editor.dom, elm, 'border');
- };
- var dom = editor.dom;
- var data = __assign(__assign({
- width: dom.getStyle(elm, 'width') || dom.getAttrib(elm, 'width'),
- height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
- cellspacing: dom.getStyle(elm, 'border-spacing') || dom.getAttrib(elm, 'cellspacing'),
- cellpadding: dom.getAttrib(elm, 'cellpadding') || getTDTHOverallStyle(editor.dom, elm, 'padding'),
- border: getBorder(dom, elm),
- caption: !!dom.select('caption', elm)[0],
- class: dom.getAttrib(elm, 'class', '')
- }, getHAlignment('align', 'align', editor, elm)), hasAdvTableTab ? extractAdvancedStyles(dom, elm) : {});
- return data;
- };
- var extractDataFromRowElement = function (editor, elm, hasAdvancedRowTab) {
- var dom = editor.dom;
- var data = __assign(__assign({
- height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
- scope: dom.getAttrib(elm, 'scope'),
- class: dom.getAttrib(elm, 'class', ''),
- align: '',
- type: elm.parentNode.nodeName.toLowerCase()
- }, getHAlignment('align', 'align', editor, elm)), hasAdvancedRowTab ? extractAdvancedStyles(dom, elm) : {});
- return data;
- };
- var extractDataFromCellElement = function (editor, elm, hasAdvancedCellTab) {
- var dom = editor.dom;
- var data = __assign(__assign(__assign({
- width: dom.getStyle(elm, 'width') || dom.getAttrib(elm, 'width'),
- height: dom.getStyle(elm, 'height') || dom.getAttrib(elm, 'height'),
- scope: dom.getAttrib(elm, 'scope'),
- celltype: elm.nodeName.toLowerCase(),
- class: dom.getAttrib(elm, 'class', '')
- }, getHAlignment('align', 'halign', editor, elm)), getVAlignment('valign', 'valign', editor, elm)), hasAdvancedCellTab ? extractAdvancedStyles(dom, elm) : {});
- return data;
- };
- var getClassList = function (editor) {
- var rowClassList = getCellClassList(editor);
- var classes = buildListItems(rowClassList, function (item) {
- if (item.value) {
- item.textStyle = function () {
- return editor.formatter.getCssText({
- block: 'tr',
- classes: [item.value]
- });
- };
- }
- });
- if (rowClassList.length > 0) {
- return Option.some({
- name: 'class',
- type: 'selectbox',
- label: 'Class',
- items: classes
- });
- }
- return Option.none();
- };
- var children$3 = [
- {
- name: 'width',
- type: 'input',
- label: 'Width'
- },
- {
- name: 'height',
- type: 'input',
- label: 'Height'
- },
- {
- name: 'celltype',
- type: 'selectbox',
- label: 'Cell type',
- items: [
- {
- text: 'Cell',
- value: 'td'
- },
- {
- text: 'Header cell',
- value: 'th'
- }
- ]
- },
- {
- name: 'scope',
- type: 'selectbox',
- label: 'Scope',
- items: [
- {
- text: 'None',
- value: ''
- },
- {
- text: 'Row',
- value: 'row'
- },
- {
- text: 'Column',
- value: 'col'
- },
- {
- text: 'Row group',
- value: 'rowgroup'
- },
- {
- text: 'Column group',
- value: 'colgroup'
- }
- ]
- },
- {
- name: 'halign',
- type: 'selectbox',
- label: 'H Align',
- items: [
- {
- text: 'None',
- value: ''
- },
- {
- text: 'Left',
- value: 'left'
- },
- {
- text: 'Center',
- value: 'center'
- },
- {
- text: 'Right',
- value: 'right'
- }
- ]
- },
- {
- name: 'valign',
- type: 'selectbox',
- label: 'V Align',
- items: [
- {
- text: 'None',
- value: ''
- },
- {
- text: 'Top',
- value: 'top'
- },
- {
- text: 'Middle',
- value: 'middle'
- },
- {
- text: 'Bottom',
- value: 'bottom'
- }
- ]
- }
- ];
- var getItems = function (editor) {
- return getClassList(editor).fold(function () {
- return children$3;
- }, function (classlist) {
- return children$3.concat(classlist);
- });
- };
- var normal = function (dom, node) {
- var setAttrib = function (attr, value) {
- dom.setAttrib(node, attr, value);
- };
- var setStyle = function (prop, value) {
- dom.setStyle(node, prop, value);
- };
- return {
- setAttrib: setAttrib,
- setStyle: setStyle
- };
- };
- var ifTruthy = function (dom, node) {
- var setAttrib = function (attr, value) {
- if (value) {
- dom.setAttrib(node, attr, value);
- }
- };
- var setStyle = function (prop, value) {
- if (value) {
- dom.setStyle(node, prop, value);
- }
- };
- return {
- setAttrib: setAttrib,
- setStyle: setStyle
- };
- };
- var DomModifier = {
- normal: normal,
- ifTruthy: ifTruthy
- };
- var updateSimpleProps = function (modifiers, data) {
- modifiers.setAttrib('scope', data.scope);
- modifiers.setAttrib('class', data.class);
- modifiers.setStyle('width', addSizeSuffix(data.width));
- modifiers.setStyle('height', addSizeSuffix(data.height));
- };
- var updateAdvancedProps = function (modifiers, data) {
- modifiers.setStyle('background-color', data.backgroundcolor);
- modifiers.setStyle('border-color', data.bordercolor);
- modifiers.setStyle('border-style', data.borderstyle);
- modifiers.setStyle('border-width', addSizeSuffix(data.borderwidth));
- };
- var applyToSingle = function (editor, cells, data) {
- var dom = editor.dom;
- var cellElm = data.celltype && cells[0].nodeName.toLowerCase() !== data.celltype ? dom.rename(cells[0], data.celltype) : cells[0];
- var modifiers = DomModifier.normal(dom, cellElm);
- updateSimpleProps(modifiers, data);
- if (hasAdvancedCellTab(editor)) {
- updateAdvancedProps(modifiers, data);
- }
- unApplyAlign(editor, cellElm);
- unApplyVAlign(editor, cellElm);
- if (data.halign) {
- applyAlign(editor, cellElm, data.halign);
- }
- if (data.valign) {
- applyVAlign(editor, cellElm, data.valign);
- }
- };
- var applyToMultiple = function (editor, cells, data) {
- var dom = editor.dom;
- global$1.each(cells, function (cellElm) {
- if (data.celltype && cellElm.nodeName.toLowerCase() !== data.celltype) {
- cellElm = dom.rename(cellElm, data.celltype);
- }
- var modifiers = DomModifier.ifTruthy(dom, cellElm);
- updateSimpleProps(modifiers, data);
- if (hasAdvancedCellTab(editor)) {
- updateAdvancedProps(modifiers, data);
- }
- if (data.halign) {
- applyAlign(editor, cellElm, data.halign);
- }
- if (data.valign) {
- applyVAlign(editor, cellElm, data.valign);
- }
- });
- };
- var onSubmitCellForm = function (editor, cells, api) {
- var data = api.getData();
- api.close();
- editor.undoManager.transact(function () {
- var applicator = cells.length === 1 ? applyToSingle : applyToMultiple;
- applicator(editor, cells, data);
- editor.focus();
- });
- };
- var open = function (editor) {
- var cellElm, cells = [];
- cells = editor.dom.select('td[data-mce-selected],th[data-mce-selected]');
- cellElm = editor.dom.getParent(editor.selection.getStart(), 'td,th');
- if (!cells.length && cellElm) {
- cells.push(cellElm);
- }
- cellElm = cellElm || cells[0];
- if (!cellElm) {
- return;
- }
- var cellsData = global$1.map(cells, function (cellElm) {
- return extractDataFromCellElement(editor, cellElm, hasAdvancedCellTab(editor));
- });
- var data = getSharedValues(cellsData);
- var dialogTabPanel = {
- type: 'tabpanel',
- tabs: [
- {
- title: 'General',
- name: 'general',
- items: getItems(editor)
- },
- getAdvancedTab('cell')
- ]
- };
- var dialogPanel = {
- type: 'panel',
- items: [{
- type: 'grid',
- columns: 2,
- items: getItems(editor)
- }]
- };
- editor.windowManager.open({
- title: 'Cell Properties',
- size: 'normal',
- body: hasAdvancedCellTab(editor) ? dialogTabPanel : dialogPanel,
- buttons: [
- {
- type: 'cancel',
- name: 'cancel',
- text: 'Cancel'
- },
- {
- type: 'submit',
- name: 'save',
- text: 'Save',
- primary: true
- }
- ],
- initialData: data,
- onSubmit: curry(onSubmitCellForm, editor, cells)
- });
- };
- var getClassList$1 = function (editor) {
- var rowClassList = getRowClassList(editor);
- var classes = buildListItems(rowClassList, function (item) {
- if (item.value) {
- item.textStyle = function () {
- return editor.formatter.getCssText({
- block: 'tr',
- classes: [item.value]
- });
- };
- }
- });
- if (rowClassList.length > 0) {
- return Option.some({
- name: 'class',
- type: 'selectbox',
- label: 'Class',
- items: classes
- });
- }
- return Option.none();
- };
- var formChildren = [
- {
- type: 'selectbox',
- name: 'type',
- label: 'Row type',
- items: [
- {
- text: 'Header',
- value: 'thead'
- },
- {
- text: 'Body',
- value: 'tbody'
- },
- {
- text: 'Footer',
- value: 'tfoot'
- }
- ]
- },
- {
- type: 'selectbox',
- name: 'align',
- label: 'Alignment',
- items: [
- {
- text: 'None',
- value: ''
- },
- {
- text: 'Left',
- value: 'left'
- },
- {
- text: 'Center',
- value: 'center'
- },
- {
- text: 'Right',
- value: 'right'
- }
- ]
- },
- {
- label: 'Height',
- name: 'height',
- type: 'input'
- }
- ];
- var getItems$1 = function (editor) {
- return getClassList$1(editor).fold(function () {
- return formChildren;
- }, function (classes) {
- return formChildren.concat(classes);
- });
- };
- var switchRowType = function (dom, rowElm, toType) {
- var tableElm = dom.getParent(rowElm, 'table');
- var oldParentElm = rowElm.parentNode;
- var parentElm = dom.select(toType, tableElm)[0];
- if (!parentElm) {
- parentElm = dom.create(toType);
- if (tableElm.firstChild) {
- if (tableElm.firstChild.nodeName === 'CAPTION') {
- dom.insertAfter(parentElm, tableElm.firstChild);
- } else {
- tableElm.insertBefore(parentElm, tableElm.firstChild);
- }
- } else {
- tableElm.appendChild(parentElm);
- }
- }
- if (toType === 'tbody' && oldParentElm.nodeName === 'THEAD' && parentElm.firstChild) {
- parentElm.insertBefore(rowElm, parentElm.firstChild);
- } else {
- parentElm.appendChild(rowElm);
- }
- if (!oldParentElm.hasChildNodes()) {
- dom.remove(oldParentElm);
- }
- };
- var updateAdvancedProps$1 = function (modifier, data) {
- modifier.setStyle('background-color', data.backgroundcolor);
- modifier.setStyle('border-color', data.bordercolor);
- modifier.setStyle('border-style', data.borderstyle);
- };
- var onSubmitRowForm = function (editor, rows, oldData, api) {
- var dom = editor.dom;
- var data = api.getData();
- api.close();
- var createModifier = rows.length === 1 ? DomModifier.normal : DomModifier.ifTruthy;
- editor.undoManager.transact(function () {
- global$1.each(rows, function (rowElm) {
- if (data.type !== rowElm.parentNode.nodeName.toLowerCase()) {
- switchRowType(editor.dom, rowElm, data.type);
- }
- var modifier = createModifier(dom, rowElm);
- modifier.setAttrib('scope', data.scope);
- modifier.setAttrib('class', data.class);
- modifier.setStyle('height', addSizeSuffix(data.height));
- if (hasAdvancedRowTab(editor)) {
- updateAdvancedProps$1(modifier, data);
- }
- if (data.align !== oldData.align) {
- unApplyAlign(editor, rowElm);
- applyAlign(editor, rowElm, data.align);
- }
- });
- editor.focus();
- });
- };
- var open$1 = function (editor) {
- var dom = editor.dom;
- var tableElm, cellElm, rowElm;
- var rows = [];
- tableElm = dom.getParent(editor.selection.getStart(), 'table');
- if (!tableElm) {
- return;
- }
- cellElm = dom.getParent(editor.selection.getStart(), 'td,th');
- global$1.each(tableElm.rows, function (row) {
- global$1.each(row.cells, function (cell) {
- if ((dom.getAttrib(cell, 'data-mce-selected') || cell === cellElm) && rows.indexOf(row) < 0) {
- rows.push(row);
- return false;
- }
- });
- });
- rowElm = rows[0];
- if (!rowElm) {
- return;
- }
- var rowsData = global$1.map(rows, function (rowElm) {
- return extractDataFromRowElement(editor, rowElm, hasAdvancedRowTab(editor));
- });
- var data = getSharedValues(rowsData);
- var dialogTabPanel = {
- type: 'tabpanel',
- tabs: [
- {
- title: 'General',
- name: 'general',
- items: getItems$1(editor)
- },
- getAdvancedTab('row')
- ]
- };
- var dialogPanel = {
- type: 'panel',
- items: [{
- type: 'grid',
- columns: 2,
- items: getItems$1(editor)
- }]
- };
- editor.windowManager.open({
- title: 'Row Properties',
- size: 'normal',
- body: hasAdvancedRowTab(editor) ? dialogTabPanel : dialogPanel,
- buttons: [
- {
- type: 'cancel',
- name: 'cancel',
- text: 'Cancel'
- },
- {
- type: 'submit',
- name: 'save',
- text: 'Save',
- primary: true
- }
- ],
- initialData: data,
- onSubmit: curry(onSubmitRowForm, editor, rows, data)
- });
- };
- var global$2 = tinymce.util.Tools.resolve('tinymce.Env');
- var DefaultRenderOptions = {
- styles: {
- 'border-collapse': 'collapse',
- 'width': '100%'
- },
- attributes: { border: '1' },
- percentages: true
- };
- var makeTable = function () {
- return Element.fromTag('table');
- };
- var tableBody = function () {
- return Element.fromTag('tbody');
- };
- var tableRow = function () {
- return Element.fromTag('tr');
- };
- var tableHeaderCell = function () {
- return Element.fromTag('th');
- };
- var tableCell = function () {
- return Element.fromTag('td');
- };
- var render$1 = function (rows, columns, rowHeaders, columnHeaders, renderOpts) {
- if (renderOpts === void 0) {
- renderOpts = DefaultRenderOptions;
- }
- var table = makeTable();
- setAll$1(table, renderOpts.styles);
- setAll(table, renderOpts.attributes);
- var tbody = tableBody();
- append(table, tbody);
- var trs = [];
- for (var i = 0; i < rows; i++) {
- var tr = tableRow();
- for (var j = 0; j < columns; j++) {
- var td = i < rowHeaders || j < columnHeaders ? tableHeaderCell() : tableCell();
- if (j < columnHeaders) {
- set(td, 'scope', 'row');
- }
- if (i < rowHeaders) {
- set(td, 'scope', 'col');
- }
- append(td, Element.fromTag('br'));
- if (renderOpts.percentages) {
- set$1(td, 'width', 100 / columns + '%');
- }
- append(tr, td);
- }
- trs.push(tr);
- }
- append$1(tbody, trs);
- return table;
- };
- var get$8 = function (element) {
- return element.dom().innerHTML;
- };
- var getOuter$2 = function (element) {
- var container = Element.fromTag('div');
- var clone = Element.fromDom(element.dom().cloneNode(true));
- append(container, clone);
- return get$8(container);
- };
- var placeCaretInCell = function (editor, cell) {
- editor.selection.select(cell.dom(), true);
- editor.selection.collapse(true);
- };
- var selectFirstCellInTable = function (editor, tableElm) {
- descendant$1(tableElm, 'td,th').each(curry(placeCaretInCell, editor));
- };
- var fireEvents = function (editor, table) {
- each(descendants$1(table, 'tr'), function (row) {
- fireNewRow(editor, row.dom());
- each(descendants$1(row, 'th,td'), function (cell) {
- fireNewCell(editor, cell.dom());
- });
- });
- };
- var isPercentage = function (width) {
- return isString(width) && width.indexOf('%') !== -1;
- };
- var insert$1 = function (editor, columns, rows) {
- var defaultStyles = getDefaultStyles(editor);
- var options = {
- styles: defaultStyles,
- attributes: getDefaultAttributes(editor),
- percentages: isPercentage(defaultStyles.width) && !isPixelsForced(editor)
- };
- var table = render$1(rows, columns, 0, 0, options);
- set(table, 'data-mce-id', '__mce');
- var html = getOuter$2(table);
- editor.insertContent(html);
- return descendant$1(getBody$1(editor), 'table[data-mce-id="__mce"]').map(function (table) {
- if (isPixelsForced(editor)) {
- set$1(table, 'width', get$2(table, 'width'));
- }
- remove(table, 'data-mce-id');
- fireEvents(editor, table);
- selectFirstCellInTable(editor, table);
- return table.dom();
- }).getOr(null);
- };
- var getItems$2 = function (editor, hasClasses, insertNewTable) {
- var rowColCountItems = !insertNewTable ? [] : [
- {
- type: 'input',
- name: 'cols',
- label: 'Cols',
- inputMode: 'numeric'
- },
- {
- type: 'input',
- name: 'rows',
- label: 'Rows',
- inputMode: 'numeric'
- }
- ];
- var alwaysItems = [
- {
- type: 'input',
- name: 'width',
- label: 'Width'
- },
- {
- type: 'input',
- name: 'height',
- label: 'Height'
- }
- ];
- var appearanceItems = hasAppearanceOptions(editor) ? [
- {
- type: 'input',
- name: 'cellspacing',
- label: 'Cell spacing',
- inputMode: 'numeric'
- },
- {
- type: 'input',
- name: 'cellpadding',
- label: 'Cell padding',
- inputMode: 'numeric'
- },
- {
- type: 'input',
- name: 'border',
- label: 'Border width'
- },
- {
- type: 'label',
- label: 'Caption',
- items: [{
- type: 'checkbox',
- name: 'caption',
- label: 'Show caption'
- }]
- }
- ] : [];
- var alignmentItem = [{
- type: 'selectbox',
- name: 'align',
- label: 'Alignment',
- items: [
- {
- text: 'None',
- value: ''
- },
- {
- text: 'Left',
- value: 'left'
- },
- {
- text: 'Center',
- value: 'center'
- },
- {
- text: 'Right',
- value: 'right'
- }
- ]
- }];
- var classListItem = hasClasses ? [{
- type: 'selectbox',
- name: 'class',
- label: 'Class',
- items: buildListItems(getTableClassList(editor), function (item) {
- if (item.value) {
- item.textStyle = function () {
- return editor.formatter.getCssText({
- block: 'table',
- classes: [item.value]
- });
- };
- }
- })
- }] : [];
- return rowColCountItems.concat(alwaysItems).concat(appearanceItems).concat(alignmentItem).concat(classListItem);
- };
- var styleTDTH = function (dom, elm, name, value) {
- if (elm.tagName === 'TD' || elm.tagName === 'TH') {
- if (isString(name)) {
- dom.setStyle(elm, name, value);
- } else {
- dom.setStyle(elm, name);
- }
- } else {
- if (elm.children) {
- for (var i = 0; i < elm.children.length; i++) {
- styleTDTH(dom, elm.children[i], name, value);
- }
- }
- }
- };
- var applyDataToElement = function (editor, tableElm, data) {
- var dom = editor.dom;
- var attrs = {};
- var styles = {};
- attrs.class = data.class;
- styles.height = addSizeSuffix(data.height);
- if (dom.getAttrib(tableElm, 'width') && !shouldStyleWithCss(editor)) {
- attrs.width = removePxSuffix(data.width);
- } else {
- styles.width = addSizeSuffix(data.width);
- }
- if (shouldStyleWithCss(editor)) {
- styles['border-width'] = addSizeSuffix(data.border);
- styles['border-spacing'] = addSizeSuffix(data.cellspacing);
- } else {
- attrs.border = data.border;
- attrs.cellpadding = data.cellpadding;
- attrs.cellspacing = data.cellspacing;
- }
- if (shouldStyleWithCss(editor) && tableElm.children) {
- for (var i = 0; i < tableElm.children.length; i++) {
- styleTDTH(dom, tableElm.children[i], {
- 'border-width': addSizeSuffix(data.border),
- 'padding': addSizeSuffix(data.cellpadding)
- });
- if (hasAdvancedTableTab(editor)) {
- styleTDTH(dom, tableElm.children[i], { 'border-color': data.bordercolor });
- }
- }
- }
- if (hasAdvancedTableTab(editor)) {
- styles['background-color'] = data.backgroundcolor;
- styles['border-color'] = data.bordercolor;
- styles['border-style'] = data.borderstyle;
- }
- attrs.style = dom.serializeStyle(__assign(__assign({}, getDefaultStyles(editor)), styles));
- dom.setAttribs(tableElm, __assign(__assign({}, getDefaultAttributes(editor)), attrs));
- };
- var onSubmitTableForm = function (editor, tableElm, api) {
- var dom = editor.dom;
- var captionElm;
- var data = api.getData();
- api.close();
- if (data.class === '') {
- delete data.class;
- }
- editor.undoManager.transact(function () {
- if (!tableElm) {
- var cols = parseInt(data.cols, 10) || 1;
- var rows = parseInt(data.rows, 10) || 1;
- tableElm = insert$1(editor, cols, rows);
- }
- applyDataToElement(editor, tableElm, data);
- captionElm = dom.select('caption', tableElm)[0];
- if (captionElm && !data.caption) {
- dom.remove(captionElm);
- }
- if (!captionElm && data.caption) {
- captionElm = dom.create('caption');
- captionElm.innerHTML = !global$2.ie ? '<br data-mce-bogus="1"/>' : nbsp;
- tableElm.insertBefore(captionElm, tableElm.firstChild);
- }
- if (data.align === '') {
- unApplyAlign(editor, tableElm);
- } else {
- applyAlign(editor, tableElm, data.align);
- }
- editor.focus();
- editor.addVisual();
- });
- };
- var open$2 = function (editor, insertNewTable) {
- var dom = editor.dom;
- var tableElm;
- var data = extractDataFromSettings(editor, hasAdvancedTableTab(editor));
- if (insertNewTable === false) {
- tableElm = dom.getParent(editor.selection.getStart(), 'table');
- if (tableElm) {
- data = extractDataFromTableElement(editor, tableElm, hasAdvancedTableTab(editor));
- } else {
- if (hasAdvancedTableTab(editor)) {
- data.borderstyle = '';
- data.bordercolor = '';
- data.backgroundcolor = '';
- }
- }
- } else {
- data.cols = '1';
- data.rows = '1';
- if (hasAdvancedTableTab(editor)) {
- data.borderstyle = '';
- data.bordercolor = '';
- data.backgroundcolor = '';
- }
- }
- var hasClasses = getTableClassList(editor).length > 0;
- if (hasClasses) {
- if (data.class) {
- data.class = data.class.replace(/\s*mce\-item\-table\s*/g, '');
- }
- }
- var generalPanel = {
- type: 'grid',
- columns: 2,
- items: getItems$2(editor, hasClasses, insertNewTable)
- };
- var nonAdvancedForm = function () {
- return {
- type: 'panel',
- items: [generalPanel]
- };
- };
- var advancedForm = function () {
- return {
- type: 'tabpanel',
- tabs: [
- {
- title: 'General',
- name: 'general',
- items: [generalPanel]
- },
- getAdvancedTab('table')
- ]
- };
- };
- var dialogBody = hasAdvancedTableTab(editor) ? advancedForm() : nonAdvancedForm();
- editor.windowManager.open({
- title: 'Table Properties',
- size: 'normal',
- body: dialogBody,
- onSubmit: curry(onSubmitTableForm, editor, tableElm),
- buttons: [
- {
- type: 'cancel',
- name: 'cancel',
- text: 'Cancel'
- },
- {
- type: 'submit',
- name: 'save',
- text: 'Save',
- primary: true
- }
- ],
- initialData: data
- });
- };
- var each$3 = global$1.each;
- var registerCommands = function (editor, actions, cellSelection, selections, clipboardRows) {
- var isRoot = getIsRoot(editor);
- var eraseTable = function () {
- getSelectionStartCellOrCaption(editor).each(function (cellOrCaption) {
- var tableOpt = table(cellOrCaption, isRoot);
- tableOpt.filter(not(isRoot)).each(function (table) {
- var cursor = Element.fromText('');
- after(table, cursor);
- remove$2(table);
- if (editor.dom.isEmpty(editor.getBody())) {
- editor.setContent('');
- editor.selection.setCursorLocation();
- } else {
- var rng = editor.dom.createRng();
- rng.setStart(cursor.dom(), 0);
- rng.setEnd(cursor.dom(), 0);
- editor.selection.setRng(rng);
- editor.nodeChanged();
- }
- });
- });
- };
- var getTableFromCell = function (cell) {
- return table(cell, isRoot);
- };
- var actOnSelection = function (execute) {
- getSelectionStartCell(editor).each(function (cell) {
- getTableFromCell(cell).each(function (table) {
- var targets = forMenu(selections, table, cell);
- execute(table, targets).each(function (rng) {
- editor.selection.setRng(rng);
- editor.focus();
- cellSelection.clear(table);
- removeDataStyle(table);
- });
- });
- });
- };
- var copyRowSelection = function (_execute) {
- return getSelectionStartCell(editor).map(function (cell) {
- return getTableFromCell(cell).bind(function (table) {
- var doc = Element.fromDom(editor.getDoc());
- var targets = forMenu(selections, table, cell);
- var generators = cellOperations(noop, doc, Option.none());
- return copyRows(table, targets, generators);
- });
- });
- };
- var pasteOnSelection = function (execute) {
- clipboardRows.get().each(function (rows) {
- var clonedRows = map(rows, function (row) {
- return deep(row);
- });
- getSelectionStartCell(editor).each(function (cell) {
- getTableFromCell(cell).each(function (table) {
- var doc = Element.fromDom(editor.getDoc());
- var generators = paste(doc);
- var targets = pasteRows(selections, table, cell, clonedRows, generators);
- execute(table, targets).each(function (rng) {
- editor.selection.setRng(rng);
- editor.focus();
- cellSelection.clear(table);
- });
- });
- });
- });
- };
- each$3({
- mceTableSplitCells: function () {
- actOnSelection(actions.unmergeCells);
- },
- mceTableMergeCells: function () {
- actOnSelection(actions.mergeCells);
- },
- mceTableInsertRowBefore: function () {
- actOnSelection(actions.insertRowsBefore);
- },
- mceTableInsertRowAfter: function () {
- actOnSelection(actions.insertRowsAfter);
- },
- mceTableInsertColBefore: function () {
- actOnSelection(actions.insertColumnsBefore);
- },
- mceTableInsertColAfter: function () {
- actOnSelection(actions.insertColumnsAfter);
- },
- mceTableDeleteCol: function () {
- actOnSelection(actions.deleteColumn);
- },
- mceTableDeleteRow: function () {
- actOnSelection(actions.deleteRow);
- },
- mceTableCutRow: function (_grid) {
- copyRowSelection().each(function (selection) {
- clipboardRows.set(selection);
- actOnSelection(actions.deleteRow);
- });
- },
- mceTableCopyRow: function (_grid) {
- copyRowSelection().each(function (selection) {
- clipboardRows.set(selection);
- });
- },
- mceTablePasteRowBefore: function (_grid) {
- pasteOnSelection(actions.pasteRowsBefore);
- },
- mceTablePasteRowAfter: function (_grid) {
- pasteOnSelection(actions.pasteRowsAfter);
- },
- mceTableDelete: eraseTable
- }, function (func, name) {
- editor.addCommand(name, func);
- });
- each$3({
- mceInsertTable: curry(open$2, editor, true),
- mceTableProps: curry(open$2, editor, false),
- mceTableRowProps: curry(open$1, editor),
- mceTableCellProps: curry(open, editor)
- }, function (func, name) {
- editor.addCommand(name, function () {
- func();
- });
- });
- };
- var only = function (element) {
- var parent = Option.from(element.dom().documentElement).map(Element.fromDom).getOr(element);
- return {
- parent: constant(parent),
- view: constant(element),
- origin: constant(Position(0, 0))
- };
- };
- var detached = function (editable, chrome) {
- var origin = function () {
- return absolute(chrome);
- };
- return {
- parent: constant(chrome),
- view: constant(editable),
- origin: origin
- };
- };
- var body$1 = function (editable, chrome) {
- return {
- parent: constant(chrome),
- view: constant(editable),
- origin: constant(Position(0, 0))
- };
- };
- var ResizeWire = {
- only: only,
- detached: detached,
- body: body$1
- };
- var Immutable = function () {
- var fields = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- fields[_i] = arguments[_i];
- }
- return function () {
- var values = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- values[_i] = arguments[_i];
- }
- if (fields.length !== values.length) {
- throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
- }
- var struct = {};
- each(fields, function (name, i) {
- struct[name] = constant(values[i]);
- });
- return struct;
- };
- };
- var Event = function (fields) {
- var struct = Immutable.apply(null, fields);
- var handlers = [];
- var bind = function (handler) {
- if (handler === undefined) {
- throw new Error('Event bind error: undefined handler');
- }
- handlers.push(handler);
- };
- var unbind = function (handler) {
- handlers = filter(handlers, function (h) {
- return h !== handler;
- });
- };
- var trigger = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- var event = struct.apply(null, args);
- each(handlers, function (handler) {
- handler(event);
- });
- };
- return {
- bind: bind,
- unbind: unbind,
- trigger: trigger
- };
- };
- var create = function (typeDefs) {
- var registry = map$1(typeDefs, function (event) {
- return {
- bind: event.bind,
- unbind: event.unbind
- };
- });
- var trigger = map$1(typeDefs, function (event) {
- return event.trigger;
- });
- return {
- registry: registry,
- trigger: trigger
- };
- };
- var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
- return {
- target: constant(target),
- x: constant(x),
- y: constant(y),
- stop: stop,
- prevent: prevent,
- kill: kill,
- raw: constant(raw)
- };
- };
- var fromRawEvent = function (rawEvent) {
- var target = Element.fromDom(rawEvent.target);
- var stop = function () {
- return rawEvent.stopPropagation();
- };
- var prevent = function () {
- return rawEvent.preventDefault();
- };
- var kill = compose(prevent, stop);
- return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
- };
- var handle = function (filter, handler) {
- return function (rawEvent) {
- if (filter(rawEvent)) {
- handler(fromRawEvent(rawEvent));
- }
- };
- };
- var binder = function (element, event, filter, handler, useCapture) {
- var wrapped = handle(filter, handler);
- element.dom().addEventListener(event, wrapped, useCapture);
- return { unbind: curry(unbind, element, event, wrapped, useCapture) };
- };
- var bind$1 = function (element, event, filter, handler) {
- return binder(element, event, filter, handler, false);
- };
- var unbind = function (element, event, handler, useCapture) {
- element.dom().removeEventListener(event, handler, useCapture);
- };
- var filter$1 = constant(true);
- var bind$2 = function (element, event, handler) {
- return bind$1(element, event, filter$1, handler);
- };
- var fromRawEvent$1 = fromRawEvent;
- var styles$1 = css('ephox-dragster');
- var resolve$1 = styles$1.resolve;
- var Blocker = function (options) {
- var settings = __assign({ layerClass: resolve$1('blocker') }, options);
- var div = Element.fromTag('div');
- set(div, 'role', 'presentation');
- setAll$1(div, {
- position: 'fixed',
- left: '0px',
- top: '0px',
- width: '100%',
- height: '100%'
- });
- add$2(div, resolve$1('blocker'));
- add$2(div, settings.layerClass);
- var element = function () {
- return div;
- };
- var destroy = function () {
- remove$2(div);
- };
- return {
- element: element,
- destroy: destroy
- };
- };
- var DragMode = exactly([
- 'compare',
- 'extract',
- 'mutate',
- 'sink'
- ]);
- var DragSink = exactly([
- 'element',
- 'start',
- 'stop',
- 'destroy'
- ]);
- var DragApi = exactly([
- 'forceDrop',
- 'drop',
- 'move',
- 'delayDrop'
- ]);
- var compare = function (old, nu) {
- return Position(nu.left() - old.left(), nu.top() - old.top());
- };
- var extract$1 = function (event) {
- return Option.some(Position(event.x(), event.y()));
- };
- var mutate = function (mutation, info) {
- mutation.mutate(info.left(), info.top());
- };
- var sink = function (dragApi, settings) {
- var blocker = Blocker(settings);
- var mdown = bind$2(blocker.element(), 'mousedown', dragApi.forceDrop);
- var mup = bind$2(blocker.element(), 'mouseup', dragApi.drop);
- var mmove = bind$2(blocker.element(), 'mousemove', dragApi.move);
- var mout = bind$2(blocker.element(), 'mouseout', dragApi.delayDrop);
- var destroy = function () {
- blocker.destroy();
- mup.unbind();
- mmove.unbind();
- mout.unbind();
- mdown.unbind();
- };
- var start = function (parent) {
- append(parent, blocker.element());
- };
- var stop = function () {
- remove$2(blocker.element());
- };
- return DragSink({
- element: blocker.element,
- start: start,
- stop: stop,
- destroy: destroy
- });
- };
- var MouseDrag = DragMode({
- compare: compare,
- extract: extract$1,
- sink: sink,
- mutate: mutate
- });
- var last$2 = function (fn, rate) {
- var timer = null;
- var cancel = function () {
- if (timer !== null) {
- domGlobals.clearTimeout(timer);
- timer = null;
- }
- };
- var throttle = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (timer !== null) {
- domGlobals.clearTimeout(timer);
- }
- timer = domGlobals.setTimeout(function () {
- fn.apply(null, args);
- timer = null;
- }, rate);
- };
- return {
- cancel: cancel,
- throttle: throttle
- };
- };
- function InDrag () {
- var previous = Option.none();
- var reset = function () {
- previous = Option.none();
- };
- var update = function (mode, nu) {
- var result = previous.map(function (old) {
- return mode.compare(old, nu);
- });
- previous = Option.some(nu);
- return result;
- };
- var onEvent = function (event, mode) {
- var dataOption = mode.extract(event);
- dataOption.each(function (data) {
- var offset = update(mode, data);
- offset.each(function (d) {
- events.trigger.move(d);
- });
- });
- };
- var events = create({ move: Event(['info']) });
- return {
- onEvent: onEvent,
- reset: reset,
- events: events.registry
- };
- }
- function NoDrag () {
- return {
- onEvent: noop,
- reset: noop
- };
- }
- function Movement () {
- var noDragState = NoDrag();
- var inDragState = InDrag();
- var dragState = noDragState;
- var on = function () {
- dragState.reset();
- dragState = inDragState;
- };
- var off = function () {
- dragState.reset();
- dragState = noDragState;
- };
- var onEvent = function (event, mode) {
- dragState.onEvent(event, mode);
- };
- var isOn = function () {
- return dragState === inDragState;
- };
- return {
- on: on,
- off: off,
- isOn: isOn,
- onEvent: onEvent,
- events: inDragState.events
- };
- }
- var setup = function (mutation, mode, settings) {
- var active = false;
- var events = create({
- start: Event([]),
- stop: Event([])
- });
- var movement = Movement();
- var drop = function () {
- sink.stop();
- if (movement.isOn()) {
- movement.off();
- events.trigger.stop();
- }
- };
- var throttledDrop = last$2(drop, 200);
- var go = function (parent) {
- sink.start(parent);
- movement.on();
- events.trigger.start();
- };
- var mousemove = function (event) {
- throttledDrop.cancel();
- movement.onEvent(event, mode);
- };
- movement.events.move.bind(function (event) {
- mode.mutate(mutation, event.info());
- });
- var on = function () {
- active = true;
- };
- var off = function () {
- active = false;
- };
- var runIfActive = function (f) {
- return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (active) {
- f.apply(null, args);
- }
- };
- };
- var sink = mode.sink(DragApi({
- forceDrop: drop,
- drop: runIfActive(drop),
- move: runIfActive(mousemove),
- delayDrop: runIfActive(throttledDrop.throttle)
- }), settings);
- var destroy = function () {
- sink.destroy();
- };
- return {
- element: sink.element,
- go: go,
- on: on,
- off: off,
- destroy: destroy,
- events: events.registry
- };
- };
- var transform$1 = function (mutation, settings) {
- if (settings === void 0) {
- settings = {};
- }
- var mode = settings.mode !== undefined ? settings.mode : MouseDrag;
- return setup(mutation, mode, settings);
- };
- var isContentEditableTrue = function (elm) {
- return get$1(elm, 'contenteditable') === 'true';
- };
- var findClosestContentEditable = function (target, isRoot) {
- return closest$1(target, '[contenteditable]', isRoot);
- };
- var Mutation = function () {
- var events = create({
- drag: Event([
- 'xDelta',
- 'yDelta'
- ])
- });
- var mutate = function (x, y) {
- events.trigger.drag(x, y);
- };
- return {
- mutate: mutate,
- events: events.registry
- };
- };
- var BarMutation = function () {
- var events = create({
- drag: Event([
- 'xDelta',
- 'yDelta',
- 'target'
- ])
- });
- var target = Option.none();
- var delegate = Mutation();
- delegate.events.drag.bind(function (event) {
- target.each(function (t) {
- events.trigger.drag(event.xDelta(), event.yDelta(), t);
- });
- });
- var assign = function (t) {
- target = Option.some(t);
- };
- var get = function () {
- return target;
- };
- return {
- assign: assign,
- get: get,
- mutate: delegate.mutate,
- events: events.registry
- };
- };
- var resizeBarDragging = resolve('resizer-bar-dragging');
- var BarManager = function (wire, direction, hdirection) {
- var mutation = BarMutation();
- var resizing = transform$1(mutation, {});
- var hoverTable = Option.none();
- var getResizer = function (element, type) {
- return Option.from(get$1(element, type));
- };
- mutation.events.drag.bind(function (event) {
- getResizer(event.target(), 'data-row').each(function (_dataRow) {
- var currentRow = getCssValue(event.target(), 'top');
- set$1(event.target(), 'top', currentRow + event.yDelta() + 'px');
- });
- getResizer(event.target(), 'data-column').each(function (_dataCol) {
- var currentCol = getCssValue(event.target(), 'left');
- set$1(event.target(), 'left', currentCol + event.xDelta() + 'px');
- });
- });
- var getDelta = function (target, dir) {
- var newX = getCssValue(target, dir);
- var oldX = getAttrValue(target, 'data-initial-' + dir, 0);
- return newX - oldX;
- };
- resizing.events.stop.bind(function () {
- mutation.get().each(function (target) {
- hoverTable.each(function (table) {
- getResizer(target, 'data-row').each(function (row) {
- var delta = getDelta(target, 'top');
- remove(target, 'data-initial-top');
- events.trigger.adjustHeight(table, delta, parseInt(row, 10));
- });
- getResizer(target, 'data-column').each(function (column) {
- var delta = getDelta(target, 'left');
- remove(target, 'data-initial-left');
- events.trigger.adjustWidth(table, delta, parseInt(column, 10));
- });
- refresh(wire, table, hdirection, direction);
- });
- });
- });
- var handler = function (target, dir) {
- events.trigger.startAdjust();
- mutation.assign(target);
- set(target, 'data-initial-' + dir, getCssValue(target, dir));
- add$2(target, resizeBarDragging);
- set$1(target, 'opacity', '0.2');
- resizing.go(wire.parent());
- };
- var mousedown = bind$2(wire.parent(), 'mousedown', function (event) {
- if (isRowBar(event.target())) {
- handler(event.target(), 'top');
- }
- if (isColBar(event.target())) {
- handler(event.target(), 'left');
- }
- });
- var isRoot = function (e) {
- return eq(e, wire.view());
- };
- var findClosestEditableTable = function (target) {
- return closest$1(target, 'table', isRoot).filter(function (table) {
- return findClosestContentEditable(table, isRoot).exists(isContentEditableTrue);
- });
- };
- var mouseover = bind$2(wire.view(), 'mouseover', function (event) {
- findClosestEditableTable(event.target()).fold(function () {
- if (inBody(event.target())) {
- destroy(wire);
- }
- }, function (table) {
- hoverTable = Option.some(table);
- refresh(wire, table, hdirection, direction);
- });
- });
- var destroy$1 = function () {
- mousedown.unbind();
- mouseover.unbind();
- resizing.destroy();
- destroy(wire);
- };
- var refresh$1 = function (tbl) {
- refresh(wire, tbl, hdirection, direction);
- };
- var events = create({
- adjustHeight: Event([
- 'table',
- 'delta',
- 'row'
- ]),
- adjustWidth: Event([
- 'table',
- 'delta',
- 'column'
- ]),
- startAdjust: Event([])
- });
- return {
- destroy: destroy$1,
- refresh: refresh$1,
- on: resizing.on,
- off: resizing.off,
- hideBars: curry(hide, wire),
- showBars: curry(show, wire),
- events: events.registry
- };
- };
- var create$1 = function (wire, vdirection) {
- var hdirection = height;
- var manager = BarManager(wire, vdirection, hdirection);
- var events = create({
- beforeResize: Event(['table']),
- afterResize: Event(['table']),
- startDrag: Event([])
- });
- manager.events.adjustHeight.bind(function (event) {
- events.trigger.beforeResize(event.table());
- var delta = hdirection.delta(event.delta(), event.table());
- adjustHeight(event.table(), delta, event.row(), hdirection);
- events.trigger.afterResize(event.table());
- });
- manager.events.startAdjust.bind(function (_event) {
- events.trigger.startDrag();
- });
- manager.events.adjustWidth.bind(function (event) {
- events.trigger.beforeResize(event.table());
- var delta = vdirection.delta(event.delta(), event.table());
- adjustWidth(event.table(), delta, event.column(), vdirection);
- events.trigger.afterResize(event.table());
- });
- return {
- on: manager.on,
- off: manager.off,
- hideBars: manager.hideBars,
- showBars: manager.showBars,
- destroy: manager.destroy,
- events: events.registry
- };
- };
- var TableResize = { create: create$1 };
- var createContainer = function () {
- var container = Element.fromTag('div');
- setAll$1(container, {
- position: 'static',
- height: '0',
- width: '0',
- padding: '0',
- margin: '0',
- border: '0'
- });
- append(body(), container);
- return container;
- };
- var get$9 = function (editor, _container) {
- return editor.inline ? ResizeWire.body(getBody$1(editor), createContainer()) : ResizeWire.only(Element.fromDom(editor.getDoc()));
- };
- var remove$6 = function (editor, wire) {
- if (editor.inline) {
- remove$2(wire.parent());
- }
- };
- var calculatePercentageWidth = function (element, parent) {
- return getPixelWidth$1(element.dom()) / getPixelWidth$1(parent.dom()) * 100 + '%';
- };
- var enforcePercentage = function (rawTable) {
- var table = Element.fromDom(rawTable);
- parent(table).map(function (parent) {
- return calculatePercentageWidth(table, parent);
- }).each(function (tablePercentage) {
- set$1(table, 'width', tablePercentage);
- each(descendants$1(table, 'tr'), function (tr) {
- each(children(tr), function (td) {
- set$1(td, 'width', calculatePercentageWidth(td, tr));
- });
- });
- });
- };
- var enforcePixels = function (table) {
- set$1(Element.fromDom(table), 'width', getPixelWidth$1(table).toString() + 'px');
- };
- var getResizeHandler = function (editor) {
- var selectionRng = Option.none();
- var resize = Option.none();
- var wire = Option.none();
- var percentageBasedSizeRegex = /(\d+(\.\d+)?)%/;
- var startW;
- var startRawW;
- var isTable = function (elm) {
- return elm.nodeName === 'TABLE';
- };
- var getRawWidth = function (elm) {
- var raw = editor.dom.getStyle(elm, 'width') || editor.dom.getAttrib(elm, 'width');
- return Option.from(raw).filter(function (s) {
- return s.length > 0;
- });
- };
- var lazyResize = function () {
- return resize;
- };
- var lazyWire = function () {
- return wire.getOr(ResizeWire.only(Element.fromDom(editor.getBody())));
- };
- var destroy = function () {
- resize.each(function (sz) {
- sz.destroy();
- });
- wire.each(function (w) {
- remove$6(editor, w);
- });
- };
- editor.on('init', function () {
- var direction = TableDirection(directionAt);
- var rawWire = get$9(editor);
- wire = Option.some(rawWire);
- if (hasObjectResizing(editor) && hasTableResizeBars(editor)) {
- var sz = TableResize.create(rawWire, direction);
- sz.on();
- sz.events.startDrag.bind(function (_event) {
- selectionRng = Option.some(editor.selection.getRng());
- });
- sz.events.beforeResize.bind(function (event) {
- var rawTable = event.table().dom();
- fireObjectResizeStart(editor, rawTable, getPixelWidth$1(rawTable), getPixelHeight(rawTable));
- });
- sz.events.afterResize.bind(function (event) {
- var table = event.table();
- var rawTable = table.dom();
- removeDataStyle(table);
- selectionRng.each(function (rng) {
- editor.selection.setRng(rng);
- editor.focus();
- });
- fireObjectResized(editor, rawTable, getPixelWidth$1(rawTable), getPixelHeight(rawTable));
- editor.undoManager.add();
- });
- resize = Option.some(sz);
- }
- });
- editor.on('ObjectResizeStart', function (e) {
- var targetElm = e.target;
- if (isTable(targetElm)) {
- var tableHasPercentage = getRawWidth(targetElm).map(function (w) {
- return percentageBasedSizeRegex.test(w);
- }).getOr(false);
- if (tableHasPercentage && isPixelsForced(editor)) {
- enforcePixels(targetElm);
- } else if (!tableHasPercentage && isPercentagesForced(editor)) {
- enforcePercentage(targetElm);
- }
- startW = e.width;
- startRawW = getRawWidth(targetElm).getOr('');
- }
- });
- editor.on('ObjectResized', function (e) {
- var targetElm = e.target;
- if (isTable(targetElm)) {
- var table = targetElm;
- if (percentageBasedSizeRegex.test(startRawW)) {
- var percentW = parseFloat(percentageBasedSizeRegex.exec(startRawW)[1]);
- var targetPercentW = e.width * percentW / startW;
- editor.dom.setStyle(table, 'width', targetPercentW + '%');
- } else {
- var newCellSizes_1 = [];
- global$1.each(table.rows, function (row) {
- global$1.each(row.cells, function (cell) {
- var width = editor.dom.getStyle(cell, 'width', true);
- newCellSizes_1.push({
- cell: cell,
- width: width
- });
- });
- });
- global$1.each(newCellSizes_1, function (newCellSize) {
- editor.dom.setStyle(newCellSize.cell, 'width', newCellSize.width);
- editor.dom.setAttrib(newCellSize.cell, 'width', null);
- });
- }
- }
- });
- editor.on('SwitchMode', function () {
- lazyResize().each(function (resize) {
- if (editor.mode.isReadOnly()) {
- resize.hideBars();
- } else {
- resize.showBars();
- }
- });
- });
- return {
- lazyResize: lazyResize,
- lazyWire: lazyWire,
- destroy: destroy
- };
- };
- var adt$1 = Adt.generate([
- { none: ['current'] },
- { first: ['current'] },
- {
- middle: [
- 'current',
- 'target'
- ]
- },
- { last: ['current'] }
- ]);
- var none$2 = function (current) {
- if (current === void 0) {
- current = undefined;
- }
- return adt$1.none(current);
- };
- var CellLocation = __assign(__assign({}, adt$1), { none: none$2 });
- var detect$4 = function (current, isRoot) {
- return table(current, isRoot).bind(function (table) {
- var all = cells(table);
- var index = findIndex(all, function (x) {
- return eq(current, x);
- });
- return index.map(function (index) {
- return {
- index: index,
- all: all
- };
- });
- });
- };
- var next = function (current, isRoot) {
- var detection = detect$4(current, isRoot);
- return detection.fold(function () {
- return CellLocation.none(current);
- }, function (info) {
- return info.index + 1 < info.all.length ? CellLocation.middle(current, info.all[info.index + 1]) : CellLocation.last(current);
- });
- };
- var prev = function (current, isRoot) {
- var detection = detect$4(current, isRoot);
- return detection.fold(function () {
- return CellLocation.none();
- }, function (info) {
- return info.index - 1 >= 0 ? CellLocation.middle(current, info.all[info.index - 1]) : CellLocation.first(current);
- });
- };
- var create$2 = function (start, soffset, finish, foffset) {
- return {
- start: constant(start),
- soffset: constant(soffset),
- finish: constant(finish),
- foffset: constant(foffset)
- };
- };
- var SimRange = { create: create$2 };
- var adt$2 = Adt.generate([
- { before: ['element'] },
- {
- on: [
- 'element',
- 'offset'
- ]
- },
- { after: ['element'] }
- ]);
- var cata$1 = function (subject, onBefore, onOn, onAfter) {
- return subject.fold(onBefore, onOn, onAfter);
- };
- var getStart = function (situ) {
- return situ.fold(identity, identity, identity);
- };
- var before$2 = adt$2.before;
- var on = adt$2.on;
- var after$2 = adt$2.after;
- var Situ = {
- before: before$2,
- on: on,
- after: after$2,
- cata: cata$1,
- getStart: getStart
- };
- var adt$3 = Adt.generate([
- { domRange: ['rng'] },
- {
- relative: [
- 'startSitu',
- 'finishSitu'
- ]
- },
- {
- exact: [
- 'start',
- 'soffset',
- 'finish',
- 'foffset'
- ]
- }
- ]);
- var exactFromRange = function (simRange) {
- return adt$3.exact(simRange.start(), simRange.soffset(), simRange.finish(), simRange.foffset());
- };
- var getStart$1 = function (selection) {
- return selection.match({
- domRange: function (rng) {
- return Element.fromDom(rng.startContainer);
- },
- relative: function (startSitu, _finishSitu) {
- return Situ.getStart(startSitu);
- },
- exact: function (start, _soffset, _finish, _foffset) {
- return start;
- }
- });
- };
- var domRange = adt$3.domRange;
- var relative = adt$3.relative;
- var exact = adt$3.exact;
- var getWin = function (selection) {
- var start = getStart$1(selection);
- return defaultView(start);
- };
- var range$1 = SimRange.create;
- var Selection = {
- domRange: domRange,
- relative: relative,
- exact: exact,
- exactFromRange: exactFromRange,
- getWin: getWin,
- range: range$1
- };
- var selectNodeContents = function (win, element) {
- var rng = win.document.createRange();
- selectNodeContentsUsing(rng, element);
- return rng;
- };
- var selectNodeContentsUsing = function (rng, element) {
- return rng.selectNodeContents(element.dom());
- };
- var setStart = function (rng, situ) {
- situ.fold(function (e) {
- rng.setStartBefore(e.dom());
- }, function (e, o) {
- rng.setStart(e.dom(), o);
- }, function (e) {
- rng.setStartAfter(e.dom());
- });
- };
- var setFinish = function (rng, situ) {
- situ.fold(function (e) {
- rng.setEndBefore(e.dom());
- }, function (e, o) {
- rng.setEnd(e.dom(), o);
- }, function (e) {
- rng.setEndAfter(e.dom());
- });
- };
- var relativeToNative = function (win, startSitu, finishSitu) {
- var range = win.document.createRange();
- setStart(range, startSitu);
- setFinish(range, finishSitu);
- return range;
- };
- var exactToNative = function (win, start, soffset, finish, foffset) {
- var rng = win.document.createRange();
- rng.setStart(start.dom(), soffset);
- rng.setEnd(finish.dom(), foffset);
- return rng;
- };
- var toRect = function (rect) {
- return {
- left: constant(rect.left),
- top: constant(rect.top),
- right: constant(rect.right),
- bottom: constant(rect.bottom),
- width: constant(rect.width),
- height: constant(rect.height)
- };
- };
- var getFirstRect = function (rng) {
- var rects = rng.getClientRects();
- var rect = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
- return rect.width > 0 || rect.height > 0 ? Option.some(rect).map(toRect) : Option.none();
- };
- var adt$4 = Adt.generate([
- {
- ltr: [
- 'start',
- 'soffset',
- 'finish',
- 'foffset'
- ]
- },
- {
- rtl: [
- 'start',
- 'soffset',
- 'finish',
- 'foffset'
- ]
- }
- ]);
- var fromRange = function (win, type, range) {
- return type(Element.fromDom(range.startContainer), range.startOffset, Element.fromDom(range.endContainer), range.endOffset);
- };
- var getRanges = function (win, selection) {
- return selection.match({
- domRange: function (rng) {
- return {
- ltr: constant(rng),
- rtl: Option.none
- };
- },
- relative: function (startSitu, finishSitu) {
- return {
- ltr: cached(function () {
- return relativeToNative(win, startSitu, finishSitu);
- }),
- rtl: cached(function () {
- return Option.some(relativeToNative(win, finishSitu, startSitu));
- })
- };
- },
- exact: function (start, soffset, finish, foffset) {
- return {
- ltr: cached(function () {
- return exactToNative(win, start, soffset, finish, foffset);
- }),
- rtl: cached(function () {
- return Option.some(exactToNative(win, finish, foffset, start, soffset));
- })
- };
- }
- });
- };
- var doDiagnose = function (win, ranges) {
- var rng = ranges.ltr();
- if (rng.collapsed) {
- var reversed = ranges.rtl().filter(function (rev) {
- return rev.collapsed === false;
- });
- return reversed.map(function (rev) {
- return adt$4.rtl(Element.fromDom(rev.endContainer), rev.endOffset, Element.fromDom(rev.startContainer), rev.startOffset);
- }).getOrThunk(function () {
- return fromRange(win, adt$4.ltr, rng);
- });
- } else {
- return fromRange(win, adt$4.ltr, rng);
- }
- };
- var diagnose = function (win, selection) {
- var ranges = getRanges(win, selection);
- return doDiagnose(win, ranges);
- };
- var asLtrRange = function (win, selection) {
- var diagnosis = diagnose(win, selection);
- return diagnosis.match({
- ltr: function (start, soffset, finish, foffset) {
- var rng = win.document.createRange();
- rng.setStart(start.dom(), soffset);
- rng.setEnd(finish.dom(), foffset);
- return rng;
- },
- rtl: function (start, soffset, finish, foffset) {
- var rng = win.document.createRange();
- rng.setStart(finish.dom(), foffset);
- rng.setEnd(start.dom(), soffset);
- return rng;
- }
- });
- };
- var ltr$2 = adt$4.ltr;
- var rtl$2 = adt$4.rtl;
- var searchForPoint = function (rectForOffset, x, y, maxX, length) {
- if (length === 0) {
- return 0;
- } else if (x === maxX) {
- return length - 1;
- }
- var xDelta = maxX;
- for (var i = 1; i < length; i++) {
- var rect = rectForOffset(i);
- var curDeltaX = Math.abs(x - rect.left);
- if (y <= rect.bottom) {
- if (y < rect.top || curDeltaX > xDelta) {
- return i - 1;
- } else {
- xDelta = curDeltaX;
- }
- }
- }
- return 0;
- };
- var inRect = function (rect, x, y) {
- return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
- };
- var locateOffset = function (doc, textnode, x, y, rect) {
- var rangeForOffset = function (o) {
- var r = doc.dom().createRange();
- r.setStart(textnode.dom(), o);
- r.collapse(true);
- return r;
- };
- var rectForOffset = function (o) {
- var r = rangeForOffset(o);
- return r.getBoundingClientRect();
- };
- var length = get$3(textnode).length;
- var offset = searchForPoint(rectForOffset, x, y, rect.right, length);
- return rangeForOffset(offset);
- };
- var locate = function (doc, node, x, y) {
- var r = doc.dom().createRange();
- r.selectNode(node.dom());
- var rects = r.getClientRects();
- var foundRect = findMap(rects, function (rect) {
- return inRect(rect, x, y) ? Option.some(rect) : Option.none();
- });
- return foundRect.map(function (rect) {
- return locateOffset(doc, node, x, y, rect);
- });
- };
- var searchInChildren = function (doc, node, x, y) {
- var r = doc.dom().createRange();
- var nodes = children(node);
- return findMap(nodes, function (n) {
- r.selectNode(n.dom());
- return inRect(r.getBoundingClientRect(), x, y) ? locateNode(doc, n, x, y) : Option.none();
- });
- };
- var locateNode = function (doc, node, x, y) {
- return isText(node) ? locate(doc, node, x, y) : searchInChildren(doc, node, x, y);
- };
- var locate$1 = function (doc, node, x, y) {
- var r = doc.dom().createRange();
- r.selectNode(node.dom());
- var rect = r.getBoundingClientRect();
- var boundedX = Math.max(rect.left, Math.min(rect.right, x));
- var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
- return locateNode(doc, node, boundedX, boundedY);
- };
- var COLLAPSE_TO_LEFT = true;
- var COLLAPSE_TO_RIGHT = false;
- var getCollapseDirection = function (rect, x) {
- return x - rect.left < rect.right - x ? COLLAPSE_TO_LEFT : COLLAPSE_TO_RIGHT;
- };
- var createCollapsedNode = function (doc, target, collapseDirection) {
- var r = doc.dom().createRange();
- r.selectNode(target.dom());
- r.collapse(collapseDirection);
- return r;
- };
- var locateInElement = function (doc, node, x) {
- var cursorRange = doc.dom().createRange();
- cursorRange.selectNode(node.dom());
- var rect = cursorRange.getBoundingClientRect();
- var collapseDirection = getCollapseDirection(rect, x);
- var f = collapseDirection === COLLAPSE_TO_LEFT ? first : last$1;
- return f(node).map(function (target) {
- return createCollapsedNode(doc, target, collapseDirection);
- });
- };
- var locateInEmpty = function (doc, node, x) {
- var rect = node.dom().getBoundingClientRect();
- var collapseDirection = getCollapseDirection(rect, x);
- return Option.some(createCollapsedNode(doc, node, collapseDirection));
- };
- var search = function (doc, node, x) {
- var f = children(node).length === 0 ? locateInEmpty : locateInElement;
- return f(doc, node, x);
- };
- var caretPositionFromPoint = function (doc, x, y) {
- return Option.from(doc.dom().caretPositionFromPoint(x, y)).bind(function (pos) {
- if (pos.offsetNode === null) {
- return Option.none();
- }
- var r = doc.dom().createRange();
- r.setStart(pos.offsetNode, pos.offset);
- r.collapse();
- return Option.some(r);
- });
- };
- var caretRangeFromPoint = function (doc, x, y) {
- return Option.from(doc.dom().caretRangeFromPoint(x, y));
- };
- var searchTextNodes = function (doc, node, x, y) {
- var r = doc.dom().createRange();
- r.selectNode(node.dom());
- var rect = r.getBoundingClientRect();
- var boundedX = Math.max(rect.left, Math.min(rect.right, x));
- var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
- return locate$1(doc, node, boundedX, boundedY);
- };
- var searchFromPoint = function (doc, x, y) {
- return Element.fromPoint(doc, x, y).bind(function (elem) {
- var fallback = function () {
- return search(doc, elem, x);
- };
- return children(elem).length === 0 ? fallback() : searchTextNodes(doc, elem, x, y).orThunk(fallback);
- });
- };
- var availableSearch = document.caretPositionFromPoint ? caretPositionFromPoint : document.caretRangeFromPoint ? caretRangeFromPoint : searchFromPoint;
- var fromPoint$1 = function (win, x, y) {
- var doc = Element.fromDom(win.document);
- return availableSearch(doc, x, y).map(function (rng) {
- return SimRange.create(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset);
- });
- };
- var beforeSpecial = function (element, offset) {
- var name$1 = name(element);
- if ('input' === name$1) {
- return Situ.after(element);
- } else if (!contains([
- 'br',
- 'img'
- ], name$1)) {
- return Situ.on(element, offset);
- } else {
- return offset === 0 ? Situ.before(element) : Situ.after(element);
- }
- };
- var preprocessRelative = function (startSitu, finishSitu) {
- var start = startSitu.fold(Situ.before, beforeSpecial, Situ.after);
- var finish = finishSitu.fold(Situ.before, beforeSpecial, Situ.after);
- return Selection.relative(start, finish);
- };
- var preprocessExact = function (start, soffset, finish, foffset) {
- var startSitu = beforeSpecial(start, soffset);
- var finishSitu = beforeSpecial(finish, foffset);
- return Selection.relative(startSitu, finishSitu);
- };
- var preprocess = function (selection) {
- return selection.match({
- domRange: function (rng) {
- var start = Element.fromDom(rng.startContainer);
- var finish = Element.fromDom(rng.endContainer);
- return preprocessExact(start, rng.startOffset, finish, rng.endOffset);
- },
- relative: preprocessRelative,
- exact: preprocessExact
- });
- };
- var makeRange = function (start, soffset, finish, foffset) {
- var doc = owner(start);
- var rng = doc.dom().createRange();
- rng.setStart(start.dom(), soffset);
- rng.setEnd(finish.dom(), foffset);
- return rng;
- };
- var after$3 = function (start, soffset, finish, foffset) {
- var r = makeRange(start, soffset, finish, foffset);
- var same = eq(start, finish) && soffset === foffset;
- return r.collapsed && !same;
- };
- var doSetNativeRange = function (win, rng) {
- Option.from(win.getSelection()).each(function (selection) {
- selection.removeAllRanges();
- selection.addRange(rng);
- });
- };
- var doSetRange = function (win, start, soffset, finish, foffset) {
- var rng = exactToNative(win, start, soffset, finish, foffset);
- doSetNativeRange(win, rng);
- };
- var setLegacyRtlRange = function (win, selection, start, soffset, finish, foffset) {
- selection.collapse(start.dom(), soffset);
- selection.extend(finish.dom(), foffset);
- };
- var setRangeFromRelative = function (win, relative) {
- return diagnose(win, relative).match({
- ltr: function (start, soffset, finish, foffset) {
- doSetRange(win, start, soffset, finish, foffset);
- },
- rtl: function (start, soffset, finish, foffset) {
- var selection = win.getSelection();
- if (selection.setBaseAndExtent) {
- selection.setBaseAndExtent(start.dom(), soffset, finish.dom(), foffset);
- } else if (selection.extend) {
- try {
- setLegacyRtlRange(win, selection, start, soffset, finish, foffset);
- } catch (e) {
- doSetRange(win, finish, foffset, start, soffset);
- }
- } else {
- doSetRange(win, finish, foffset, start, soffset);
- }
- }
- });
- };
- var setExact = function (win, start, soffset, finish, foffset) {
- var relative = preprocessExact(start, soffset, finish, foffset);
- setRangeFromRelative(win, relative);
- };
- var setRelative = function (win, startSitu, finishSitu) {
- var relative = preprocessRelative(startSitu, finishSitu);
- setRangeFromRelative(win, relative);
- };
- var toNative = function (selection) {
- var win = Selection.getWin(selection).dom();
- var getDomRange = function (start, soffset, finish, foffset) {
- return exactToNative(win, start, soffset, finish, foffset);
- };
- var filtered = preprocess(selection);
- return diagnose(win, filtered).match({
- ltr: getDomRange,
- rtl: getDomRange
- });
- };
- var readRange = function (selection) {
- if (selection.rangeCount > 0) {
- var firstRng = selection.getRangeAt(0);
- var lastRng = selection.getRangeAt(selection.rangeCount - 1);
- return Option.some(SimRange.create(Element.fromDom(firstRng.startContainer), firstRng.startOffset, Element.fromDom(lastRng.endContainer), lastRng.endOffset));
- } else {
- return Option.none();
- }
- };
- var doGetExact = function (selection) {
- var anchor = Element.fromDom(selection.anchorNode);
- var focus = Element.fromDom(selection.focusNode);
- return after$3(anchor, selection.anchorOffset, focus, selection.focusOffset) ? Option.some(SimRange.create(anchor, selection.anchorOffset, focus, selection.focusOffset)) : readRange(selection);
- };
- var setToElement = function (win, element) {
- var rng = selectNodeContents(win, element);
- doSetNativeRange(win, rng);
- };
- var getExact = function (win) {
- return Option.from(win.getSelection()).filter(function (sel) {
- return sel.rangeCount > 0;
- }).bind(doGetExact);
- };
- var get$a = function (win) {
- return getExact(win).map(function (range) {
- return Selection.exact(range.start(), range.soffset(), range.finish(), range.foffset());
- });
- };
- var getFirstRect$1 = function (win, selection) {
- var rng = asLtrRange(win, selection);
- return getFirstRect(rng);
- };
- var getAtPoint = function (win, x, y) {
- return fromPoint$1(win, x, y);
- };
- var clear = function (win) {
- var selection = win.getSelection();
- selection.removeAllRanges();
- };
- var global$3 = tinymce.util.Tools.resolve('tinymce.util.VK');
- var forward = function (editor, isRoot, cell, lazyWire) {
- return go(editor, isRoot, next(cell), lazyWire);
- };
- var backward = function (editor, isRoot, cell, lazyWire) {
- return go(editor, isRoot, prev(cell), lazyWire);
- };
- var getCellFirstCursorPosition = function (editor, cell) {
- var selection = Selection.exact(cell, 0, cell, 0);
- return toNative(selection);
- };
- var getNewRowCursorPosition = function (editor, table) {
- var rows = descendants$1(table, 'tr');
- return last(rows).bind(function (last) {
- return descendant$1(last, 'td,th').map(function (first) {
- return getCellFirstCursorPosition(editor, first);
- });
- });
- };
- var go = function (editor, isRoot, cell, actions, _lazyWire) {
- return cell.fold(Option.none, Option.none, function (current, next) {
- return first(next).map(function (cell) {
- return getCellFirstCursorPosition(editor, cell);
- });
- }, function (current) {
- return table(current, isRoot).bind(function (table) {
- var targets = noMenu(current);
- editor.undoManager.transact(function () {
- actions.insertRowsAfter(table, targets);
- });
- return getNewRowCursorPosition(editor, table);
- });
- });
- };
- var rootElements = [
- 'table',
- 'li',
- 'dl'
- ];
- var handle$1 = function (event, editor, actions, lazyWire) {
- if (event.keyCode === global$3.TAB) {
- var body_1 = getBody$1(editor);
- var isRoot_1 = function (element) {
- var name$1 = name(element);
- return eq(element, body_1) || contains(rootElements, name$1);
- };
- var rng = editor.selection.getRng();
- if (rng.collapsed) {
- var start = Element.fromDom(rng.startContainer);
- cell(start, isRoot_1).each(function (cell) {
- event.preventDefault();
- var navigation = event.shiftKey ? backward : forward;
- var rng = navigation(editor, isRoot_1, cell, actions, lazyWire);
- rng.each(function (range) {
- editor.selection.setRng(range);
- });
- });
- }
- }
- };
- var create$3 = function (selection, kill) {
- return {
- selection: constant(selection),
- kill: constant(kill)
- };
- };
- var Response = { create: create$3 };
- var create$4 = function (start, soffset, finish, foffset) {
- return {
- start: constant(Situ.on(start, soffset)),
- finish: constant(Situ.on(finish, foffset))
- };
- };
- var Situs = { create: create$4 };
- var convertToRange = function (win, selection) {
- var rng = asLtrRange(win, selection);
- return SimRange.create(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset);
- };
- var makeSitus = Situs.create;
- var sync = function (container, isRoot, start, soffset, finish, foffset, selectRange) {
- if (!(eq(start, finish) && soffset === foffset)) {
- return closest$1(start, 'td,th', isRoot).bind(function (s) {
- return closest$1(finish, 'td,th', isRoot).bind(function (f) {
- return detect$5(container, isRoot, s, f, selectRange);
- });
- });
- } else {
- return Option.none();
- }
- };
- var detect$5 = function (container, isRoot, start, finish, selectRange) {
- if (!eq(start, finish)) {
- return identify(start, finish, isRoot).bind(function (cellSel) {
- var boxes = cellSel.boxes.getOr([]);
- if (boxes.length > 0) {
- selectRange(container, boxes, cellSel.start, cellSel.finish);
- return Option.some(Response.create(Option.some(makeSitus(start, 0, start, getEnd(start))), true));
- } else {
- return Option.none();
- }
- });
- } else {
- return Option.none();
- }
- };
- var update = function (rows, columns, container, selected, annotations) {
- var updateSelection = function (newSels) {
- annotations.clearBeforeUpdate(container);
- annotations.selectRange(container, newSels.boxes, newSels.start, newSels.finish);
- return newSels.boxes;
- };
- return shiftSelection(selected, rows, columns, annotations.firstSelectedSelector, annotations.lastSelectedSelector).map(updateSelection);
- };
- var traverse = function (item, mode) {
- return {
- item: constant(item),
- mode: constant(mode)
- };
- };
- var backtrack = function (universe, item, _direction, transition) {
- if (transition === void 0) {
- transition = sidestep;
- }
- return universe.property().parent(item).map(function (p) {
- return traverse(p, transition);
- });
- };
- var sidestep = function (universe, item, direction, transition) {
- if (transition === void 0) {
- transition = advance;
- }
- return direction.sibling(universe, item).map(function (p) {
- return traverse(p, transition);
- });
- };
- var advance = function (universe, item, direction, transition) {
- if (transition === void 0) {
- transition = advance;
- }
- var children = universe.property().children(item);
- var result = direction.first(children);
- return result.map(function (r) {
- return traverse(r, transition);
- });
- };
- var successors = [
- {
- current: backtrack,
- next: sidestep,
- fallback: Option.none()
- },
- {
- current: sidestep,
- next: advance,
- fallback: Option.some(backtrack)
- },
- {
- current: advance,
- next: advance,
- fallback: Option.some(sidestep)
- }
- ];
- var go$1 = function (universe, item, mode, direction, rules) {
- if (rules === void 0) {
- rules = successors;
- }
- var ruleOpt = find(rules, function (succ) {
- return succ.current === mode;
- });
- return ruleOpt.bind(function (rule) {
- return rule.current(universe, item, direction, rule.next).orThunk(function () {
- return rule.fallback.bind(function (fb) {
- return go$1(universe, item, fb, direction);
- });
- });
- });
- };
- var left = function () {
- var sibling = function (universe, item) {
- return universe.query().prevSibling(item);
- };
- var first = function (children) {
- return children.length > 0 ? Option.some(children[children.length - 1]) : Option.none();
- };
- return {
- sibling: sibling,
- first: first
- };
- };
- var right = function () {
- var sibling = function (universe, item) {
- return universe.query().nextSibling(item);
- };
- var first = function (children) {
- return children.length > 0 ? Option.some(children[0]) : Option.none();
- };
- return {
- sibling: sibling,
- first: first
- };
- };
- var Walkers = {
- left: left,
- right: right
- };
- var hone = function (universe, item, predicate, mode, direction, isRoot) {
- var next = go$1(universe, item, mode, direction);
- return next.bind(function (n) {
- if (isRoot(n.item())) {
- return Option.none();
- } else {
- return predicate(n.item()) ? Option.some(n.item()) : hone(universe, n.item(), predicate, n.mode(), direction, isRoot);
- }
- });
- };
- var left$1 = function (universe, item, predicate, isRoot) {
- return hone(universe, item, predicate, sidestep, Walkers.left(), isRoot);
- };
- var right$1 = function (universe, item, predicate, isRoot) {
- return hone(universe, item, predicate, sidestep, Walkers.right(), isRoot);
- };
- var isLeaf = function (universe) {
- return function (element) {
- return universe.property().children(element).length === 0;
- };
- };
- var before$3 = function (universe, item, isRoot) {
- return seekLeft(universe, item, isLeaf(universe), isRoot);
- };
- var after$4 = function (universe, item, isRoot) {
- return seekRight(universe, item, isLeaf(universe), isRoot);
- };
- var seekLeft = left$1;
- var seekRight = right$1;
- var universe$3 = DomUniverse();
- var before$4 = function (element, isRoot) {
- return before$3(universe$3, element, isRoot);
- };
- var after$5 = function (element, isRoot) {
- return after$4(universe$3, element, isRoot);
- };
- var seekLeft$1 = function (element, predicate, isRoot) {
- return seekLeft(universe$3, element, predicate, isRoot);
- };
- var seekRight$1 = function (element, predicate, isRoot) {
- return seekRight(universe$3, element, predicate, isRoot);
- };
- var ancestor$2 = function (scope, predicate, isRoot) {
- return ancestor(scope, predicate, isRoot).isSome();
- };
- var adt$5 = Adt.generate([
- { none: ['message'] },
- { success: [] },
- { failedUp: ['cell'] },
- { failedDown: ['cell'] }
- ]);
- var isOverlapping = function (bridge, before, after) {
- var beforeBounds = bridge.getRect(before);
- var afterBounds = bridge.getRect(after);
- return afterBounds.right > beforeBounds.left && afterBounds.left < beforeBounds.right;
- };
- var isRow = function (elem) {
- return closest$1(elem, 'tr');
- };
- var verify = function (bridge, before, beforeOffset, after, afterOffset, failure, isRoot) {
- return closest$1(after, 'td,th', isRoot).bind(function (afterCell) {
- return closest$1(before, 'td,th', isRoot).map(function (beforeCell) {
- if (!eq(afterCell, beforeCell)) {
- return sharedOne$1(isRow, [
- afterCell,
- beforeCell
- ]).fold(function () {
- return isOverlapping(bridge, beforeCell, afterCell) ? adt$5.success() : failure(beforeCell);
- }, function (_sharedRow) {
- return failure(beforeCell);
- });
- } else {
- return eq(after, afterCell) && getEnd(afterCell) === afterOffset ? failure(beforeCell) : adt$5.none('in same cell');
- }
- });
- }).getOr(adt$5.none('default'));
- };
- var cata$2 = function (subject, onNone, onSuccess, onFailedUp, onFailedDown) {
- return subject.fold(onNone, onSuccess, onFailedUp, onFailedDown);
- };
- var BeforeAfter = __assign(__assign({}, adt$5), {
- verify: verify,
- cata: cata$2
- });
- var inParent = function (parent, children, element, index) {
- return {
- parent: constant(parent),
- children: constant(children),
- element: constant(element),
- index: constant(index)
- };
- };
- var indexInParent = function (element) {
- return parent(element).bind(function (parent) {
- var children$1 = children(parent);
- return indexOf(children$1, element).map(function (index) {
- return inParent(parent, children$1, element, index);
- });
- });
- };
- var indexOf = function (elements, element) {
- return findIndex(elements, curry(eq, element));
- };
- var isBr = function (elem) {
- return name(elem) === 'br';
- };
- var gatherer = function (cand, gather, isRoot) {
- return gather(cand, isRoot).bind(function (target) {
- return isText(target) && get$3(target).trim().length === 0 ? gatherer(target, gather, isRoot) : Option.some(target);
- });
- };
- var handleBr = function (isRoot, element, direction) {
- return direction.traverse(element).orThunk(function () {
- return gatherer(element, direction.gather, isRoot);
- }).map(direction.relative);
- };
- var findBr = function (element, offset) {
- return child(element, offset).filter(isBr).orThunk(function () {
- return child(element, offset - 1).filter(isBr);
- });
- };
- var handleParent = function (isRoot, element, offset, direction) {
- return findBr(element, offset).bind(function (br) {
- return direction.traverse(br).fold(function () {
- return gatherer(br, direction.gather, isRoot).map(direction.relative);
- }, function (adjacent) {
- return indexInParent(adjacent).map(function (info) {
- return Situ.on(info.parent(), info.index());
- });
- });
- });
- };
- var tryBr = function (isRoot, element, offset, direction) {
- var target = isBr(element) ? handleBr(isRoot, element, direction) : handleParent(isRoot, element, offset, direction);
- return target.map(function (tgt) {
- return {
- start: constant(tgt),
- finish: constant(tgt)
- };
- });
- };
- var process = function (analysis) {
- return BeforeAfter.cata(analysis, function (_message) {
- return Option.none();
- }, function () {
- return Option.none();
- }, function (cell) {
- return Option.some(point(cell, 0));
- }, function (cell) {
- return Option.some(point(cell, getEnd(cell)));
- });
- };
- var moveDown = function (caret, amount) {
- return {
- left: caret.left,
- top: caret.top + amount,
- right: caret.right,
- bottom: caret.bottom + amount
- };
- };
- var moveUp = function (caret, amount) {
- return {
- left: caret.left,
- top: caret.top - amount,
- right: caret.right,
- bottom: caret.bottom - amount
- };
- };
- var translate = function (caret, xDelta, yDelta) {
- return {
- left: caret.left + xDelta,
- top: caret.top + yDelta,
- right: caret.right + xDelta,
- bottom: caret.bottom + yDelta
- };
- };
- var getTop$1 = function (caret) {
- return caret.top;
- };
- var getBottom = function (caret) {
- return caret.bottom;
- };
- var getPartialBox = function (bridge, element, offset) {
- if (offset >= 0 && offset < getEnd(element)) {
- return bridge.getRangedRect(element, offset, element, offset + 1);
- } else if (offset > 0) {
- return bridge.getRangedRect(element, offset - 1, element, offset);
- }
- return Option.none();
- };
- var toCaret = function (rect) {
- return {
- left: rect.left,
- top: rect.top,
- right: rect.right,
- bottom: rect.bottom
- };
- };
- var getElemBox = function (bridge, element) {
- return Option.some(bridge.getRect(element));
- };
- var getBoxAt = function (bridge, element, offset) {
- if (isElement(element)) {
- return getElemBox(bridge, element).map(toCaret);
- } else if (isText(element)) {
- return getPartialBox(bridge, element, offset).map(toCaret);
- } else {
- return Option.none();
- }
- };
- var getEntireBox = function (bridge, element) {
- if (isElement(element)) {
- return getElemBox(bridge, element).map(toCaret);
- } else if (isText(element)) {
- return bridge.getRangedRect(element, 0, element, getEnd(element)).map(toCaret);
- } else {
- return Option.none();
- }
- };
- var JUMP_SIZE = 5;
- var NUM_RETRIES = 100;
- var adt$6 = Adt.generate([
- { none: [] },
- { retry: ['caret'] }
- ]);
- var isOutside = function (caret, box) {
- return caret.left < box.left || Math.abs(box.right - caret.left) < 1 || caret.left > box.right;
- };
- var inOutsideBlock = function (bridge, element, caret) {
- return closest(element, isBlock$1).fold(constant(false), function (cell) {
- return getEntireBox(bridge, cell).exists(function (box) {
- return isOutside(caret, box);
- });
- });
- };
- var adjustDown = function (bridge, element, guessBox, original, caret) {
- var lowerCaret = moveDown(caret, JUMP_SIZE);
- if (Math.abs(guessBox.bottom - original.bottom) < 1) {
- return adt$6.retry(lowerCaret);
- } else if (guessBox.top > caret.bottom) {
- return adt$6.retry(lowerCaret);
- } else if (guessBox.top === caret.bottom) {
- return adt$6.retry(moveDown(caret, 1));
- } else {
- return inOutsideBlock(bridge, element, caret) ? adt$6.retry(translate(lowerCaret, JUMP_SIZE, 0)) : adt$6.none();
- }
- };
- var adjustUp = function (bridge, element, guessBox, original, caret) {
- var higherCaret = moveUp(caret, JUMP_SIZE);
- if (Math.abs(guessBox.top - original.top) < 1) {
- return adt$6.retry(higherCaret);
- } else if (guessBox.bottom < caret.top) {
- return adt$6.retry(higherCaret);
- } else if (guessBox.bottom === caret.top) {
- return adt$6.retry(moveUp(caret, 1));
- } else {
- return inOutsideBlock(bridge, element, caret) ? adt$6.retry(translate(higherCaret, JUMP_SIZE, 0)) : adt$6.none();
- }
- };
- var upMovement = {
- point: getTop$1,
- adjuster: adjustUp,
- move: moveUp,
- gather: before$4
- };
- var downMovement = {
- point: getBottom,
- adjuster: adjustDown,
- move: moveDown,
- gather: after$5
- };
- var isAtTable = function (bridge, x, y) {
- return bridge.elementFromPoint(x, y).filter(function (elm) {
- return name(elm) === 'table';
- }).isSome();
- };
- var adjustForTable = function (bridge, movement, original, caret, numRetries) {
- return adjustTil(bridge, movement, original, movement.move(caret, JUMP_SIZE), numRetries);
- };
- var adjustTil = function (bridge, movement, original, caret, numRetries) {
- if (numRetries === 0) {
- return Option.some(caret);
- }
- if (isAtTable(bridge, caret.left, movement.point(caret))) {
- return adjustForTable(bridge, movement, original, caret, numRetries - 1);
- }
- return bridge.situsFromPoint(caret.left, movement.point(caret)).bind(function (guess) {
- return guess.start().fold(Option.none, function (element) {
- return getEntireBox(bridge, element).bind(function (guessBox) {
- return movement.adjuster(bridge, element, guessBox, original, caret).fold(Option.none, function (newCaret) {
- return adjustTil(bridge, movement, original, newCaret, numRetries - 1);
- });
- }).orThunk(function () {
- return Option.some(caret);
- });
- }, Option.none);
- });
- };
- var ieTryDown = function (bridge, caret) {
- return bridge.situsFromPoint(caret.left, caret.bottom + JUMP_SIZE);
- };
- var ieTryUp = function (bridge, caret) {
- return bridge.situsFromPoint(caret.left, caret.top - JUMP_SIZE);
- };
- var checkScroll = function (movement, adjusted, bridge) {
- if (movement.point(adjusted) > bridge.getInnerHeight()) {
- return Option.some(movement.point(adjusted) - bridge.getInnerHeight());
- } else if (movement.point(adjusted) < 0) {
- return Option.some(-movement.point(adjusted));
- } else {
- return Option.none();
- }
- };
- var retry = function (movement, bridge, caret) {
- var moved = movement.move(caret, JUMP_SIZE);
- var adjusted = adjustTil(bridge, movement, caret, moved, NUM_RETRIES).getOr(moved);
- return checkScroll(movement, adjusted, bridge).fold(function () {
- return bridge.situsFromPoint(adjusted.left, movement.point(adjusted));
- }, function (delta) {
- bridge.scrollBy(0, delta);
- return bridge.situsFromPoint(adjusted.left, movement.point(adjusted) - delta);
- });
- };
- var Retries = {
- tryUp: curry(retry, upMovement),
- tryDown: curry(retry, downMovement),
- ieTryUp: ieTryUp,
- ieTryDown: ieTryDown,
- getJumpSize: constant(JUMP_SIZE)
- };
- var MAX_RETRIES = 20;
- var findSpot = function (bridge, isRoot, direction) {
- return bridge.getSelection().bind(function (sel) {
- return tryBr(isRoot, sel.finish(), sel.foffset(), direction).fold(function () {
- return Option.some(point(sel.finish(), sel.foffset()));
- }, function (brNeighbour) {
- var range = bridge.fromSitus(brNeighbour);
- var analysis = BeforeAfter.verify(bridge, sel.finish(), sel.foffset(), range.finish(), range.foffset(), direction.failure, isRoot);
- return process(analysis);
- });
- });
- };
- var scan$1 = function (bridge, isRoot, element, offset, direction, numRetries) {
- if (numRetries === 0) {
- return Option.none();
- }
- return tryCursor(bridge, isRoot, element, offset, direction).bind(function (situs) {
- var range = bridge.fromSitus(situs);
- var analysis = BeforeAfter.verify(bridge, element, offset, range.finish(), range.foffset(), direction.failure, isRoot);
- return BeforeAfter.cata(analysis, function () {
- return Option.none();
- }, function () {
- return Option.some(situs);
- }, function (cell) {
- if (eq(element, cell) && offset === 0) {
- return tryAgain(bridge, element, offset, moveUp, direction);
- } else {
- return scan$1(bridge, isRoot, cell, 0, direction, numRetries - 1);
- }
- }, function (cell) {
- if (eq(element, cell) && offset === getEnd(cell)) {
- return tryAgain(bridge, element, offset, moveDown, direction);
- } else {
- return scan$1(bridge, isRoot, cell, getEnd(cell), direction, numRetries - 1);
- }
- });
- });
- };
- var tryAgain = function (bridge, element, offset, move, direction) {
- return getBoxAt(bridge, element, offset).bind(function (box) {
- return tryAt(bridge, direction, move(box, Retries.getJumpSize()));
- });
- };
- var tryAt = function (bridge, direction, box) {
- var browser = detect$3().browser;
- if (browser.isChrome() || browser.isSafari() || browser.isFirefox() || browser.isEdge()) {
- return direction.otherRetry(bridge, box);
- } else if (browser.isIE()) {
- return direction.ieRetry(bridge, box);
- } else {
- return Option.none();
- }
- };
- var tryCursor = function (bridge, isRoot, element, offset, direction) {
- return getBoxAt(bridge, element, offset).bind(function (box) {
- return tryAt(bridge, direction, box);
- });
- };
- var handle$2 = function (bridge, isRoot, direction) {
- return findSpot(bridge, isRoot, direction).bind(function (spot) {
- return scan$1(bridge, isRoot, spot.element(), spot.offset(), direction, MAX_RETRIES).map(bridge.fromSitus);
- });
- };
- var inSameTable = function (elem, table) {
- return ancestor$2(elem, function (e) {
- return parent(e).exists(function (p) {
- return eq(p, table);
- });
- });
- };
- var simulate = function (bridge, isRoot, direction, initial, anchor) {
- return closest$1(initial, 'td,th', isRoot).bind(function (start) {
- return closest$1(start, 'table', isRoot).bind(function (table) {
- if (!inSameTable(anchor, table)) {
- return Option.none();
- }
- return handle$2(bridge, isRoot, direction).bind(function (range) {
- return closest$1(range.finish(), 'td,th', isRoot).map(function (finish) {
- return {
- start: constant(start),
- finish: constant(finish),
- range: constant(range)
- };
- });
- });
- });
- });
- };
- var navigate = function (bridge, isRoot, direction, initial, anchor, precheck) {
- if (detect$3().browser.isIE()) {
- return Option.none();
- } else {
- return precheck(initial, isRoot).orThunk(function () {
- return simulate(bridge, isRoot, direction, initial, anchor).map(function (info) {
- var range = info.range();
- return Response.create(Option.some(makeSitus(range.start(), range.soffset(), range.finish(), range.foffset())), true);
- });
- });
- }
- };
- var firstUpCheck = function (initial, isRoot) {
- return closest$1(initial, 'tr', isRoot).bind(function (startRow) {
- return closest$1(startRow, 'table', isRoot).bind(function (table) {
- var rows = descendants$1(table, 'tr');
- if (eq(startRow, rows[0])) {
- return seekLeft$1(table, function (element) {
- return last$1(element).isSome();
- }, isRoot).map(function (last) {
- var lastOffset = getEnd(last);
- return Response.create(Option.some(makeSitus(last, lastOffset, last, lastOffset)), true);
- });
- } else {
- return Option.none();
- }
- });
- });
- };
- var lastDownCheck = function (initial, isRoot) {
- return closest$1(initial, 'tr', isRoot).bind(function (startRow) {
- return closest$1(startRow, 'table', isRoot).bind(function (table) {
- var rows = descendants$1(table, 'tr');
- if (eq(startRow, rows[rows.length - 1])) {
- return seekRight$1(table, function (element) {
- return first(element).isSome();
- }, isRoot).map(function (first) {
- return Response.create(Option.some(makeSitus(first, 0, first, 0)), true);
- });
- } else {
- return Option.none();
- }
- });
- });
- };
- var select = function (bridge, container, isRoot, direction, initial, anchor, selectRange) {
- return simulate(bridge, isRoot, direction, initial, anchor).bind(function (info) {
- return detect$5(container, isRoot, info.start(), info.finish(), selectRange);
- });
- };
- var findCell = function (target, isRoot) {
- return closest$1(target, 'td,th', isRoot);
- };
- function MouseSelection (bridge, container, isRoot, annotations) {
- var cursor = Option.none();
- var clearState = function () {
- cursor = Option.none();
- };
- var mousedown = function (event) {
- annotations.clear(container);
- cursor = findCell(event.target(), isRoot);
- };
- var mouseover = function (event) {
- cursor.each(function (start) {
- annotations.clearBeforeUpdate(container);
- findCell(event.target(), isRoot).each(function (finish) {
- identify(start, finish, isRoot).each(function (cellSel) {
- var boxes = cellSel.boxes.getOr([]);
- if (boxes.length > 1 || boxes.length === 1 && !eq(start, finish)) {
- annotations.selectRange(container, boxes, cellSel.start, cellSel.finish);
- bridge.selectContents(finish);
- }
- });
- });
- });
- };
- var mouseup = function (_event) {
- cursor.each(clearState);
- };
- return {
- mousedown: mousedown,
- mouseover: mouseover,
- mouseup: mouseup
- };
- }
- var down = {
- traverse: nextSibling,
- gather: after$5,
- relative: Situ.before,
- otherRetry: Retries.tryDown,
- ieRetry: Retries.ieTryDown,
- failure: BeforeAfter.failedDown
- };
- var up = {
- traverse: prevSibling,
- gather: before$4,
- relative: Situ.before,
- otherRetry: Retries.tryUp,
- ieRetry: Retries.ieTryUp,
- failure: BeforeAfter.failedUp
- };
- var isKey = function (key) {
- return function (keycode) {
- return keycode === key;
- };
- };
- var isUp = isKey(38);
- var isDown = isKey(40);
- var isNavigation = function (keycode) {
- return keycode >= 37 && keycode <= 40;
- };
- var ltr$3 = {
- isBackward: isKey(37),
- isForward: isKey(39)
- };
- var rtl$3 = {
- isBackward: isKey(39),
- isForward: isKey(37)
- };
- var toRaw = function (sr) {
- return {
- left: sr.left(),
- top: sr.top(),
- right: sr.right(),
- bottom: sr.bottom(),
- width: sr.width(),
- height: sr.height()
- };
- };
- var Rect = { toRaw: toRaw };
- var get$b = function (_DOC) {
- var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
- var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
- var y = doc.body.scrollTop || doc.documentElement.scrollTop;
- return Position(x, y);
- };
- var by = function (x, y, _DOC) {
- var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
- var win = doc.defaultView;
- win.scrollBy(x, y);
- };
- var WindowBridge = function (win) {
- var elementFromPoint = function (x, y) {
- return Element.fromPoint(Element.fromDom(win.document), x, y);
- };
- var getRect = function (element) {
- return element.dom().getBoundingClientRect();
- };
- var getRangedRect = function (start, soffset, finish, foffset) {
- var sel = Selection.exact(start, soffset, finish, foffset);
- return getFirstRect$1(win, sel).map(Rect.toRaw);
- };
- var getSelection = function () {
- return get$a(win).map(function (exactAdt) {
- return convertToRange(win, exactAdt);
- });
- };
- var fromSitus = function (situs) {
- var relative = Selection.relative(situs.start(), situs.finish());
- return convertToRange(win, relative);
- };
- var situsFromPoint = function (x, y) {
- return getAtPoint(win, x, y).map(function (exact) {
- return Situs.create(exact.start(), exact.soffset(), exact.finish(), exact.foffset());
- });
- };
- var clearSelection = function () {
- clear(win);
- };
- var collapseSelection = function (toStart) {
- if (toStart === void 0) {
- toStart = false;
- }
- get$a(win).each(function (sel) {
- return sel.fold(function (rng) {
- return rng.collapse(toStart);
- }, function (startSitu, finishSitu) {
- var situ = toStart ? startSitu : finishSitu;
- setRelative(win, situ, situ);
- }, function (start, soffset, finish, foffset) {
- var node = toStart ? start : finish;
- var offset = toStart ? soffset : foffset;
- setExact(win, node, offset, node, offset);
- });
- });
- };
- var selectContents = function (element) {
- setToElement(win, element);
- };
- var setSelection = function (sel) {
- setExact(win, sel.start(), sel.soffset(), sel.finish(), sel.foffset());
- };
- var setRelativeSelection = function (start, finish) {
- setRelative(win, start, finish);
- };
- var getInnerHeight = function () {
- return win.innerHeight;
- };
- var getScrollY = function () {
- var pos = get$b(Element.fromDom(win.document));
- return pos.top();
- };
- var scrollBy = function (x, y) {
- by(x, y, Element.fromDom(win.document));
- };
- return {
- elementFromPoint: elementFromPoint,
- getRect: getRect,
- getRangedRect: getRangedRect,
- getSelection: getSelection,
- fromSitus: fromSitus,
- situsFromPoint: situsFromPoint,
- clearSelection: clearSelection,
- collapseSelection: collapseSelection,
- setSelection: setSelection,
- setRelativeSelection: setRelativeSelection,
- selectContents: selectContents,
- getInnerHeight: getInnerHeight,
- getScrollY: getScrollY,
- scrollBy: scrollBy
- };
- };
- var rc = function (rows, cols) {
- return {
- rows: rows,
- cols: cols
- };
- };
- var mouse = function (win, container, isRoot, annotations) {
- var bridge = WindowBridge(win);
- var handlers = MouseSelection(bridge, container, isRoot, annotations);
- return {
- mousedown: handlers.mousedown,
- mouseover: handlers.mouseover,
- mouseup: handlers.mouseup
- };
- };
- var keyboard = function (win, container, isRoot, annotations) {
- var bridge = WindowBridge(win);
- var clearToNavigate = function () {
- annotations.clear(container);
- return Option.none();
- };
- var keydown = function (event, start, soffset, finish, foffset, direction) {
- var realEvent = event.raw();
- var keycode = realEvent.which;
- var shiftKey = realEvent.shiftKey === true;
- var handler = retrieve(container, annotations.selectedSelector).fold(function () {
- if (isDown(keycode) && shiftKey) {
- return curry(select, bridge, container, isRoot, down, finish, start, annotations.selectRange);
- } else if (isUp(keycode) && shiftKey) {
- return curry(select, bridge, container, isRoot, up, finish, start, annotations.selectRange);
- } else if (isDown(keycode)) {
- return curry(navigate, bridge, isRoot, down, finish, start, lastDownCheck);
- } else if (isUp(keycode)) {
- return curry(navigate, bridge, isRoot, up, finish, start, firstUpCheck);
- } else {
- return Option.none;
- }
- }, function (selected) {
- var update$1 = function (attempts) {
- return function () {
- var navigation = findMap(attempts, function (delta) {
- return update(delta.rows, delta.cols, container, selected, annotations);
- });
- return navigation.fold(function () {
- return getEdges(container, annotations.firstSelectedSelector, annotations.lastSelectedSelector).map(function (edges) {
- var relative = isDown(keycode) || direction.isForward(keycode) ? Situ.after : Situ.before;
- bridge.setRelativeSelection(Situ.on(edges.first(), 0), relative(edges.table()));
- annotations.clear(container);
- return Response.create(Option.none(), true);
- });
- }, function (_) {
- return Option.some(Response.create(Option.none(), true));
- });
- };
- };
- if (isDown(keycode) && shiftKey) {
- return update$1([rc(+1, 0)]);
- } else if (isUp(keycode) && shiftKey) {
- return update$1([rc(-1, 0)]);
- } else if (direction.isBackward(keycode) && shiftKey) {
- return update$1([
- rc(0, -1),
- rc(-1, 0)
- ]);
- } else if (direction.isForward(keycode) && shiftKey) {
- return update$1([
- rc(0, +1),
- rc(+1, 0)
- ]);
- } else if (isNavigation(keycode) && shiftKey === false) {
- return clearToNavigate;
- } else {
- return Option.none;
- }
- });
- return handler();
- };
- var keyup = function (event, start, soffset, finish, foffset) {
- return retrieve(container, annotations.selectedSelector).fold(function () {
- var realEvent = event.raw();
- var keycode = realEvent.which;
- var shiftKey = realEvent.shiftKey === true;
- if (shiftKey === false) {
- return Option.none();
- }
- if (isNavigation(keycode)) {
- return sync(container, isRoot, start, soffset, finish, foffset, annotations.selectRange);
- } else {
- return Option.none();
- }
- }, Option.none);
- };
- return {
- keydown: keydown,
- keyup: keyup
- };
- };
- var external = function (win, container, isRoot, annotations) {
- var bridge = WindowBridge(win);
- return function (start, finish) {
- annotations.clearBeforeUpdate(container);
- identify(start, finish, isRoot).each(function (cellSel) {
- var boxes = cellSel.boxes.getOr([]);
- annotations.selectRange(container, boxes, cellSel.start, cellSel.finish);
- bridge.selectContents(finish);
- bridge.collapseSelection();
- });
- };
- };
- var remove$7 = function (element, classes) {
- each(classes, function (x) {
- remove$5(element, x);
- });
- };
- var addClass = function (clazz) {
- return function (element) {
- add$2(element, clazz);
- };
- };
- var removeClasses = function (classes) {
- return function (element) {
- remove$7(element, classes);
- };
- };
- var byClass = function (ephemera) {
- var addSelectionClass = addClass(ephemera.selected);
- var removeSelectionClasses = removeClasses([
- ephemera.selected,
- ephemera.lastSelected,
- ephemera.firstSelected
- ]);
- var clear = function (container) {
- var sels = descendants$1(container, ephemera.selectedSelector);
- each(sels, removeSelectionClasses);
- };
- var selectRange = function (container, cells, start, finish) {
- clear(container);
- each(cells, addSelectionClass);
- add$2(start, ephemera.firstSelected);
- add$2(finish, ephemera.lastSelected);
- };
- return {
- clearBeforeUpdate: clear,
- clear: clear,
- selectRange: selectRange,
- selectedSelector: ephemera.selectedSelector,
- firstSelectedSelector: ephemera.firstSelectedSelector,
- lastSelectedSelector: ephemera.lastSelectedSelector
- };
- };
- var byAttr = function (ephemera, onSelection, onClear) {
- var removeSelectionAttributes = function (element) {
- remove(element, ephemera.selected);
- remove(element, ephemera.firstSelected);
- remove(element, ephemera.lastSelected);
- };
- var addSelectionAttribute = function (element) {
- set(element, ephemera.selected, '1');
- };
- var clear = function (container) {
- clearBeforeUpdate(container);
- onClear();
- };
- var clearBeforeUpdate = function (container) {
- var sels = descendants$1(container, ephemera.selectedSelector);
- each(sels, removeSelectionAttributes);
- };
- var selectRange = function (container, cells, start, finish) {
- clear(container);
- each(cells, addSelectionAttribute);
- set(start, ephemera.firstSelected, '1');
- set(finish, ephemera.lastSelected, '1');
- onSelection(cells, start, finish);
- };
- return {
- clearBeforeUpdate: clearBeforeUpdate,
- clear: clear,
- selectRange: selectRange,
- selectedSelector: ephemera.selectedSelector,
- firstSelectedSelector: ephemera.firstSelectedSelector,
- lastSelectedSelector: ephemera.lastSelectedSelector
- };
- };
- var SelectionAnnotation = {
- byClass: byClass,
- byAttr: byAttr
- };
- var getUpOrLeftCells = function (grid, selectedCells, generators) {
- var upGrid = grid.slice(0, selectedCells[selectedCells.length - 1].row() + 1);
- var upDetails = toDetailList(upGrid, generators);
- return bind(upDetails, function (detail) {
- var slicedCells = detail.cells().slice(0, selectedCells[selectedCells.length - 1].column() + 1);
- return map(slicedCells, function (cell) {
- return cell.element();
- });
- });
- };
- var getDownOrRightCells = function (grid, selectedCells, generators) {
- var downGrid = grid.slice(selectedCells[0].row() + selectedCells[0].rowspan() - 1, grid.length);
- var downDetails = toDetailList(downGrid, generators);
- return bind(downDetails, function (detail) {
- var slicedCells = detail.cells().slice(selectedCells[0].column() + selectedCells[0].colspan() - 1, +detail.cells().length);
- return map(slicedCells, function (cell) {
- return cell.element();
- });
- });
- };
- var getOtherCells = function (table, target, generators) {
- var list = fromTable(table);
- var house = Warehouse.generate(list);
- var details = onCells(house, target);
- return details.map(function (selectedCells) {
- var grid = toGrid(house, generators, false);
- var upOrLeftCells = getUpOrLeftCells(grid, selectedCells, generators);
- var downOrRightCells = getDownOrRightCells(grid, selectedCells, generators);
- return {
- upOrLeftCells: upOrLeftCells,
- downOrRightCells: downOrRightCells
- };
- });
- };
- var hasInternalTarget = function (e) {
- return has$2(Element.fromDom(e.target), 'ephox-snooker-resizer-bar') === false;
- };
- function CellSelection (editor, lazyResize, selectionTargets) {
- var handlers = Option.none();
- var cloneFormats = getCloneElements(editor);
- var onSelection = function (cells, start, finish) {
- selectionTargets.targets().each(function (targets) {
- var tableOpt = table(start);
- tableOpt.each(function (table) {
- var doc = Element.fromDom(editor.getDoc());
- var generators = cellOperations(noop, doc, cloneFormats);
- var otherCells = getOtherCells(table, targets, generators);
- fireTableSelectionChange(editor, cells, start, finish, otherCells);
- });
- });
- };
- var onClear = function () {
- fireTableSelectionClear(editor);
- };
- var annotations = SelectionAnnotation.byAttr(Ephemera, onSelection, onClear);
- editor.on('init', function (_e) {
- var win = editor.getWin();
- var body = getBody$1(editor);
- var isRoot = getIsRoot(editor);
- var syncSelection = function () {
- var sel = editor.selection;
- var start = Element.fromDom(sel.getStart());
- var end = Element.fromDom(sel.getEnd());
- var shared = sharedOne$1(table, [
- start,
- end
- ]);
- shared.fold(function () {
- annotations.clear(body);
- }, noop);
- };
- var mouseHandlers = mouse(win, body, isRoot, annotations);
- var keyHandlers = keyboard(win, body, isRoot, annotations);
- var external$1 = external(win, body, isRoot, annotations);
- var hasShiftKey = function (event) {
- return event.raw().shiftKey === true;
- };
- editor.on('TableSelectorChange', function (e) {
- external$1(e.start, e.finish);
- });
- var handleResponse = function (event, response) {
- if (!hasShiftKey(event)) {
- return;
- }
- if (response.kill()) {
- event.kill();
- }
- response.selection().each(function (ns) {
- var relative = Selection.relative(ns.start(), ns.finish());
- var rng = asLtrRange(win, relative);
- editor.selection.setRng(rng);
- });
- };
- var keyup = function (event) {
- var wrappedEvent = fromRawEvent$1(event);
- if (wrappedEvent.raw().shiftKey && isNavigation(wrappedEvent.raw().which)) {
- var rng = editor.selection.getRng();
- var start = Element.fromDom(rng.startContainer);
- var end = Element.fromDom(rng.endContainer);
- keyHandlers.keyup(wrappedEvent, start, rng.startOffset, end, rng.endOffset).each(function (response) {
- handleResponse(wrappedEvent, response);
- });
- }
- };
- var keydown = function (event) {
- var wrappedEvent = fromRawEvent$1(event);
- lazyResize().each(function (resize) {
- resize.hideBars();
- });
- var rng = editor.selection.getRng();
- var startContainer = Element.fromDom(editor.selection.getStart());
- var start = Element.fromDom(rng.startContainer);
- var end = Element.fromDom(rng.endContainer);
- var direction = directionAt(startContainer).isRtl() ? rtl$3 : ltr$3;
- keyHandlers.keydown(wrappedEvent, start, rng.startOffset, end, rng.endOffset, direction).each(function (response) {
- handleResponse(wrappedEvent, response);
- });
- lazyResize().each(function (resize) {
- resize.showBars();
- });
- };
- var isLeftMouse = function (raw) {
- return raw.button === 0;
- };
- var isLeftButtonPressed = function (raw) {
- if (raw.buttons === undefined) {
- return true;
- }
- if (global$2.browser.isEdge() && raw.buttons === 0) {
- return true;
- }
- return (raw.buttons & 1) !== 0;
- };
- var mouseDown = function (e) {
- if (isLeftMouse(e) && hasInternalTarget(e)) {
- mouseHandlers.mousedown(fromRawEvent$1(e));
- }
- };
- var mouseOver = function (e) {
- if (isLeftButtonPressed(e) && hasInternalTarget(e)) {
- mouseHandlers.mouseover(fromRawEvent$1(e));
- }
- };
- var mouseUp = function (e) {
- if (isLeftMouse(e) && hasInternalTarget(e)) {
- mouseHandlers.mouseup(fromRawEvent$1(e));
- }
- };
- var getDoubleTap = function () {
- var lastTarget = Cell(Element.fromDom(body));
- var lastTimeStamp = Cell(0);
- var touchEnd = function (t) {
- var target = Element.fromDom(t.target);
- if (name(target) === 'td' || name(target) === 'th') {
- var lT = lastTarget.get();
- var lTS = lastTimeStamp.get();
- if (eq(lT, target) && t.timeStamp - lTS < 300) {
- t.preventDefault();
- external$1(target, target);
- }
- }
- lastTarget.set(target);
- lastTimeStamp.set(t.timeStamp);
- };
- return { touchEnd: touchEnd };
- };
- var doubleTap = getDoubleTap();
- editor.on('mousedown', mouseDown);
- editor.on('mouseover', mouseOver);
- editor.on('mouseup', mouseUp);
- editor.on('touchend', doubleTap.touchEnd);
- editor.on('keyup', keyup);
- editor.on('keydown', keydown);
- editor.on('NodeChange', syncSelection);
- handlers = Option.some({
- mousedown: mouseDown,
- mouseover: mouseOver,
- mouseup: mouseUp,
- keyup: keyup,
- keydown: keydown
- });
- });
- var destroy = function () {
- handlers.each(function (_handlers) {
- });
- };
- return {
- clear: annotations.clear,
- destroy: destroy
- };
- }
- var Selections = function (editor) {
- var get = function () {
- var body = getBody$1(editor);
- return retrieve$1(body, selectedSelector).fold(function () {
- if (editor.selection.getStart() === undefined) {
- return none$1();
- } else {
- return single(editor.selection);
- }
- }, function (cells) {
- return multiple(cells);
- });
- };
- return { get: get };
- };
- var getSelectionTargets = function (editor, selections) {
- var targets = Cell(Option.none());
- var changeHandlers = Cell([]);
- var findTargets = function () {
- return getSelectionStartCellOrCaption(editor).bind(function (cellOrCaption) {
- var table$1 = table(cellOrCaption);
- return table$1.map(function (table) {
- if (name(cellOrCaption) === 'caption') {
- return notCell(cellOrCaption);
- } else {
- return forMenu(selections, table, cellOrCaption);
- }
- });
- });
- };
- var resetTargets = function () {
- targets.set(cached(findTargets)());
- each(changeHandlers.get(), function (handler) {
- return handler();
- });
- };
- var onSetup = function (api, isDisabled) {
- var handler = function () {
- return targets.get().fold(function () {
- api.setDisabled(true);
- }, function (targets) {
- api.setDisabled(isDisabled(targets));
- });
- };
- handler();
- changeHandlers.set(changeHandlers.get().concat([handler]));
- return function () {
- changeHandlers.set(filter(changeHandlers.get(), function (h) {
- return h !== handler;
- }));
- };
- };
- var onSetupTable = function (api) {
- return onSetup(api, function (_) {
- return false;
- });
- };
- var onSetupCellOrRow = function (api) {
- return onSetup(api, function (targets) {
- return name(targets.element()) === 'caption';
- });
- };
- var onSetupMergeable = function (api) {
- return onSetup(api, function (targets) {
- return targets.mergable().isNone();
- });
- };
- var onSetupUnmergeable = function (api) {
- return onSetup(api, function (targets) {
- return targets.unmergable().isNone();
- });
- };
- editor.on('NodeChange TableSelectorChange', resetTargets);
- return {
- onSetupTable: onSetupTable,
- onSetupCellOrRow: onSetupCellOrRow,
- onSetupMergeable: onSetupMergeable,
- onSetupUnmergeable: onSetupUnmergeable,
- resetTargets: resetTargets,
- targets: function () {
- return targets.get();
- }
- };
- };
- var addButtons = function (editor, selectionTargets) {
- editor.ui.registry.addMenuButton('table', {
- tooltip: 'Table',
- icon: 'table',
- fetch: function (callback) {
- return callback('inserttable | cell row column | advtablesort | tableprops deletetable');
- }
- });
- var cmd = function (command) {
- return function () {
- return editor.execCommand(command);
- };
- };
- editor.ui.registry.addButton('tableprops', {
- tooltip: 'Table properties',
- onAction: cmd('mceTableProps'),
- icon: 'table',
- onSetup: selectionTargets.onSetupTable
- });
- editor.ui.registry.addButton('tabledelete', {
- tooltip: 'Delete table',
- onAction: cmd('mceTableDelete'),
- icon: 'table-delete-table',
- onSetup: selectionTargets.onSetupTable
- });
- editor.ui.registry.addButton('tablecellprops', {
- tooltip: 'Cell properties',
- onAction: cmd('mceTableCellProps'),
- icon: 'table-cell-properties',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tablemergecells', {
- tooltip: 'Merge cells',
- onAction: cmd('mceTableMergeCells'),
- icon: 'table-merge-cells',
- onSetup: selectionTargets.onSetupMergeable
- });
- editor.ui.registry.addButton('tablesplitcells', {
- tooltip: 'Split cell',
- onAction: cmd('mceTableSplitCells'),
- icon: 'table-split-cells',
- onSetup: selectionTargets.onSetupUnmergeable
- });
- editor.ui.registry.addButton('tableinsertrowbefore', {
- tooltip: 'Insert row before',
- onAction: cmd('mceTableInsertRowBefore'),
- icon: 'table-insert-row-above',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tableinsertrowafter', {
- tooltip: 'Insert row after',
- onAction: cmd('mceTableInsertRowAfter'),
- icon: 'table-insert-row-after',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tabledeleterow', {
- tooltip: 'Delete row',
- onAction: cmd('mceTableDeleteRow'),
- icon: 'table-delete-row',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tablerowprops', {
- tooltip: 'Row properties',
- onAction: cmd('mceTableRowProps'),
- icon: 'table-row-properties',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tableinsertcolbefore', {
- tooltip: 'Insert column before',
- onAction: cmd('mceTableInsertColBefore'),
- icon: 'table-insert-column-before',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tableinsertcolafter', {
- tooltip: 'Insert column after',
- onAction: cmd('mceTableInsertColAfter'),
- icon: 'table-insert-column-after',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tabledeletecol', {
- tooltip: 'Delete column',
- onAction: cmd('mceTableDeleteCol'),
- icon: 'table-delete-column',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tablecutrow', {
- tooltip: 'Cut row',
- onAction: cmd('mceTableCutRow'),
- icon: 'temporary-placeholder',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tablecopyrow', {
- tooltip: 'Copy row',
- onAction: cmd('mceTableCopyRow'),
- icon: 'temporary-placeholder',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tablepasterowbefore', {
- tooltip: 'Paste row before',
- onAction: cmd('mceTablePasteRowBefore'),
- icon: 'temporary-placeholder',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tablepasterowafter', {
- tooltip: 'Paste row after',
- onAction: cmd('mceTablePasteRowAfter'),
- icon: 'temporary-placeholder',
- onSetup: selectionTargets.onSetupCellOrRow
- });
- editor.ui.registry.addButton('tableinsertdialog', {
- tooltip: 'Insert table',
- onAction: cmd('mceInsertTable'),
- icon: 'table'
- });
- };
- var addToolbars = function (editor) {
- var isTable = function (table) {
- return editor.dom.is(table, 'table') && editor.getBody().contains(table);
- };
- var toolbar = getToolbar(editor);
- if (toolbar.length > 0) {
- editor.ui.registry.addContextToolbar('table', {
- predicate: isTable,
- items: toolbar,
- scope: 'node',
- position: 'node'
- });
- }
- };
- var addMenuItems = function (editor, selectionTargets) {
- var cmd = function (command) {
- return function () {
- return editor.execCommand(command);
- };
- };
- var insertTableAction = function (_a) {
- var numRows = _a.numRows, numColumns = _a.numColumns;
- editor.undoManager.transact(function () {
- insert$1(editor, numColumns, numRows);
- });
- editor.addVisual();
- };
- var tableProperties = {
- text: 'Table properties',
- onSetup: selectionTargets.onSetupTable,
- onAction: cmd('mceTableProps')
- };
- var deleteTable = {
- text: 'Delete table',
- icon: 'table-delete-table',
- onSetup: selectionTargets.onSetupTable,
- onAction: cmd('mceTableDelete')
- };
- var rowItems = [
- {
- type: 'menuitem',
- text: 'Insert row before',
- icon: 'table-insert-row-above',
- onAction: cmd('mceTableInsertRowBefore'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Insert row after',
- icon: 'table-insert-row-after',
- onAction: cmd('mceTableInsertRowAfter'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Delete row',
- icon: 'table-delete-row',
- onAction: cmd('mceTableDeleteRow'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Row properties',
- icon: 'table-row-properties',
- onAction: cmd('mceTableRowProps'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- { type: 'separator' },
- {
- type: 'menuitem',
- text: 'Cut row',
- onAction: cmd('mceTableCutRow'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Copy row',
- onAction: cmd('mceTableCopyRow'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Paste row before',
- onAction: cmd('mceTablePasteRowBefore'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Paste row after',
- onAction: cmd('mceTablePasteRowAfter'),
- onSetup: selectionTargets.onSetupCellOrRow
- }
- ];
- var row = {
- type: 'nestedmenuitem',
- text: 'Row',
- getSubmenuItems: function () {
- return rowItems;
- }
- };
- var columnItems = [
- {
- type: 'menuitem',
- text: 'Insert column before',
- icon: 'table-insert-column-before',
- onAction: cmd('mceTableInsertColBefore'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Insert column after',
- icon: 'table-insert-column-after',
- onAction: cmd('mceTableInsertColAfter'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Delete column',
- icon: 'table-delete-column',
- onAction: cmd('mceTableDeleteCol'),
- onSetup: selectionTargets.onSetupCellOrRow
- }
- ];
- var column = {
- type: 'nestedmenuitem',
- text: 'Column',
- getSubmenuItems: function () {
- return columnItems;
- }
- };
- var cellItems = [
- {
- type: 'menuitem',
- text: 'Cell properties',
- icon: 'table-cell-properties',
- onAction: cmd('mceTableCellProps'),
- onSetup: selectionTargets.onSetupCellOrRow
- },
- {
- type: 'menuitem',
- text: 'Merge cells',
- icon: 'table-merge-cells',
- onAction: cmd('mceTableMergeCells'),
- onSetup: selectionTargets.onSetupMergeable
- },
- {
- type: 'menuitem',
- text: 'Split cell',
- icon: 'table-split-cells',
- onAction: cmd('mceTableSplitCells'),
- onSetup: selectionTargets.onSetupUnmergeable
- }
- ];
- var cell = {
- type: 'nestedmenuitem',
- text: 'Cell',
- getSubmenuItems: function () {
- return cellItems;
- }
- };
- if (hasTableGrid(editor) === false) {
- editor.ui.registry.addMenuItem('inserttable', {
- text: 'Table',
- icon: 'table',
- onAction: cmd('mceInsertTable')
- });
- } else {
- editor.ui.registry.addNestedMenuItem('inserttable', {
- text: 'Table',
- icon: 'table',
- getSubmenuItems: function () {
- return [{
- type: 'fancymenuitem',
- fancytype: 'inserttable',
- onAction: insertTableAction
- }];
- }
- });
- }
- editor.ui.registry.addMenuItem('inserttabledialog', {
- text: 'Insert table',
- icon: 'table',
- onAction: cmd('mceInsertTable')
- });
- editor.ui.registry.addMenuItem('tableprops', tableProperties);
- editor.ui.registry.addMenuItem('deletetable', deleteTable);
- editor.ui.registry.addNestedMenuItem('row', row);
- editor.ui.registry.addNestedMenuItem('column', column);
- editor.ui.registry.addNestedMenuItem('cell', cell);
- editor.ui.registry.addContextMenu('table', {
- update: function () {
- selectionTargets.resetTargets();
- return selectionTargets.targets().fold(function () {
- return '';
- }, function (targets) {
- if (name(targets.element()) === 'caption') {
- return 'tableprops deletetable';
- } else {
- return 'cell row column | advtablesort | tableprops deletetable';
- }
- });
- }
- });
- };
- var getClipboardRows = function (clipboardRows) {
- return clipboardRows.get().fold(function () {
- return;
- }, function (rows) {
- return map(rows, function (row) {
- return row.dom();
- });
- });
- };
- var setClipboardRows = function (rows, clipboardRows) {
- var sugarRows = map(rows, Element.fromDom);
- clipboardRows.set(Option.from(sugarRows));
- };
- var getApi = function (editor, clipboardRows, resizeHandler, selectionTargets) {
- return {
- insertTable: function (columns, rows) {
- return insert$1(editor, columns, rows);
- },
- setClipboardRows: function (rows) {
- return setClipboardRows(rows, clipboardRows);
- },
- getClipboardRows: function () {
- return getClipboardRows(clipboardRows);
- },
- resizeHandler: resizeHandler,
- selectionTargets: selectionTargets
- };
- };
- function Plugin(editor) {
- var selections = Selections(editor);
- var selectionTargets = getSelectionTargets(editor, selections);
- var resizeHandler = getResizeHandler(editor);
- var cellSelection = CellSelection(editor, resizeHandler.lazyResize, selectionTargets);
- var actions = TableActions(editor, resizeHandler.lazyWire);
- var clipboardRows = Cell(Option.none());
- registerCommands(editor, actions, cellSelection, selections, clipboardRows);
- registerEvents(editor, selections, actions, cellSelection);
- addMenuItems(editor, selectionTargets);
- addButtons(editor, selectionTargets);
- addToolbars(editor);
- editor.on('PreInit', function () {
- editor.serializer.addTempAttr(firstSelected);
- editor.serializer.addTempAttr(lastSelected);
- });
- if (hasTabNavigation(editor)) {
- editor.on('keydown', function (e) {
- handle$1(e, editor, actions, resizeHandler.lazyWire);
- });
- }
- editor.on('remove', function () {
- resizeHandler.destroy();
- cellSelection.destroy();
- });
- return getApi(editor, clipboardRows, resizeHandler, selectionTargets);
- }
- function Plugin$1 () {
- global.add('table', Plugin);
- }
- Plugin$1();
- }(window));
|