plugin.js 315 KB

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