plugin.js 307 KB

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