plugin.js 306 KB

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