tinymce_themes_silver.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793
  1. import {
  2. __commonJS,
  3. init_define_APP_INFO
  4. } from "./chunk-XY75H3MP.js";
  5. // node_modules/tinymce/themes/silver/theme.js
  6. var require_theme = __commonJS({
  7. "node_modules/tinymce/themes/silver/theme.js"() {
  8. init_define_APP_INFO();
  9. (function() {
  10. "use strict";
  11. var typeOf = function(x) {
  12. var t2 = typeof x;
  13. if (x === null) {
  14. return "null";
  15. } else if (t2 === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  16. return "array";
  17. } else if (t2 === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  18. return "string";
  19. } else {
  20. return t2;
  21. }
  22. };
  23. var isType$1 = function(type2) {
  24. return function(value2) {
  25. return typeOf(value2) === type2;
  26. };
  27. };
  28. var isSimpleType = function(type2) {
  29. return function(value2) {
  30. return typeof value2 === type2;
  31. };
  32. };
  33. var eq$1 = function(t2) {
  34. return function(a) {
  35. return t2 === a;
  36. };
  37. };
  38. var isString = isType$1("string");
  39. var isObject = isType$1("object");
  40. var isArray = isType$1("array");
  41. var isNull = eq$1(null);
  42. var isBoolean = isSimpleType("boolean");
  43. var isUndefined = eq$1(void 0);
  44. var isNullable = function(a) {
  45. return a === null || a === void 0;
  46. };
  47. var isNonNullable = function(a) {
  48. return !isNullable(a);
  49. };
  50. var isFunction = isSimpleType("function");
  51. var isNumber = isSimpleType("number");
  52. var isArrayOf = function(value2, pred) {
  53. if (isArray(value2)) {
  54. for (var i = 0, len = value2.length; i < len; ++i) {
  55. if (!pred(value2[i])) {
  56. return false;
  57. }
  58. }
  59. return true;
  60. }
  61. return false;
  62. };
  63. var noop = function() {
  64. };
  65. var noarg = function(f) {
  66. return function() {
  67. return f();
  68. };
  69. };
  70. var compose = function(fa, fb) {
  71. return function() {
  72. var args = [];
  73. for (var _i = 0; _i < arguments.length; _i++) {
  74. args[_i] = arguments[_i];
  75. }
  76. return fa(fb.apply(null, args));
  77. };
  78. };
  79. var compose1 = function(fbc, fab) {
  80. return function(a) {
  81. return fbc(fab(a));
  82. };
  83. };
  84. var constant$1 = function(value2) {
  85. return function() {
  86. return value2;
  87. };
  88. };
  89. var identity$1 = function(x) {
  90. return x;
  91. };
  92. var tripleEquals = function(a, b2) {
  93. return a === b2;
  94. };
  95. function curry(fn) {
  96. var initialArgs = [];
  97. for (var _i = 1; _i < arguments.length; _i++) {
  98. initialArgs[_i - 1] = arguments[_i];
  99. }
  100. return function() {
  101. var restArgs = [];
  102. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  103. restArgs[_i2] = arguments[_i2];
  104. }
  105. var all2 = initialArgs.concat(restArgs);
  106. return fn.apply(null, all2);
  107. };
  108. }
  109. var not = function(f) {
  110. return function(t2) {
  111. return !f(t2);
  112. };
  113. };
  114. var die = function(msg) {
  115. return function() {
  116. throw new Error(msg);
  117. };
  118. };
  119. var never = constant$1(false);
  120. var always = constant$1(true);
  121. var global$g = tinymce.util.Tools.resolve("tinymce.ThemeManager");
  122. var __assign = function() {
  123. __assign = Object.assign || function __assign2(t2) {
  124. for (var s, i = 1, n = arguments.length; i < n; i++) {
  125. s = arguments[i];
  126. for (var p in s)
  127. if (Object.prototype.hasOwnProperty.call(s, p))
  128. t2[p] = s[p];
  129. }
  130. return t2;
  131. };
  132. return __assign.apply(this, arguments);
  133. };
  134. function __rest(s, e) {
  135. var t2 = {};
  136. for (var p in s)
  137. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  138. t2[p] = s[p];
  139. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  140. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  141. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  142. t2[p[i]] = s[p[i]];
  143. }
  144. return t2;
  145. }
  146. function __spreadArray(to2, from2, pack) {
  147. if (pack || arguments.length === 2)
  148. for (var i = 0, l2 = from2.length, ar; i < l2; i++) {
  149. if (ar || !(i in from2)) {
  150. if (!ar)
  151. ar = Array.prototype.slice.call(from2, 0, i);
  152. ar[i] = from2[i];
  153. }
  154. }
  155. return to2.concat(ar || Array.prototype.slice.call(from2));
  156. }
  157. var none = function() {
  158. return NONE;
  159. };
  160. var NONE = function() {
  161. var call = function(thunk2) {
  162. return thunk2();
  163. };
  164. var id = identity$1;
  165. var me = {
  166. fold: function(n, _s) {
  167. return n();
  168. },
  169. isSome: never,
  170. isNone: always,
  171. getOr: id,
  172. getOrThunk: call,
  173. getOrDie: function(msg) {
  174. throw new Error(msg || "error: getOrDie called on none.");
  175. },
  176. getOrNull: constant$1(null),
  177. getOrUndefined: constant$1(void 0),
  178. or: id,
  179. orThunk: call,
  180. map: none,
  181. each: noop,
  182. bind: none,
  183. exists: never,
  184. forall: always,
  185. filter: function() {
  186. return none();
  187. },
  188. toArray: function() {
  189. return [];
  190. },
  191. toString: constant$1("none()")
  192. };
  193. return me;
  194. }();
  195. var some = function(a) {
  196. var constant_a = constant$1(a);
  197. var self2 = function() {
  198. return me;
  199. };
  200. var bind2 = function(f) {
  201. return f(a);
  202. };
  203. var me = {
  204. fold: function(n, s) {
  205. return s(a);
  206. },
  207. isSome: always,
  208. isNone: never,
  209. getOr: constant_a,
  210. getOrThunk: constant_a,
  211. getOrDie: constant_a,
  212. getOrNull: constant_a,
  213. getOrUndefined: constant_a,
  214. or: self2,
  215. orThunk: self2,
  216. map: function(f) {
  217. return some(f(a));
  218. },
  219. each: function(f) {
  220. f(a);
  221. },
  222. bind: bind2,
  223. exists: bind2,
  224. forall: bind2,
  225. filter: function(f) {
  226. return f(a) ? me : NONE;
  227. },
  228. toArray: function() {
  229. return [a];
  230. },
  231. toString: function() {
  232. return "some(" + a + ")";
  233. }
  234. };
  235. return me;
  236. };
  237. var from$1 = function(value2) {
  238. return value2 === null || value2 === void 0 ? NONE : some(value2);
  239. };
  240. var Optional = {
  241. some,
  242. none,
  243. from: from$1
  244. };
  245. var nativeSlice = Array.prototype.slice;
  246. var nativeIndexOf = Array.prototype.indexOf;
  247. var nativePush = Array.prototype.push;
  248. var rawIndexOf = function(ts, t2) {
  249. return nativeIndexOf.call(ts, t2);
  250. };
  251. var indexOf = function(xs, x) {
  252. var r2 = rawIndexOf(xs, x);
  253. return r2 === -1 ? Optional.none() : Optional.some(r2);
  254. };
  255. var contains$2 = function(xs, x) {
  256. return rawIndexOf(xs, x) > -1;
  257. };
  258. var exists = function(xs, pred) {
  259. for (var i = 0, len = xs.length; i < len; i++) {
  260. var x = xs[i];
  261. if (pred(x, i)) {
  262. return true;
  263. }
  264. }
  265. return false;
  266. };
  267. var range$2 = function(num, f) {
  268. var r2 = [];
  269. for (var i = 0; i < num; i++) {
  270. r2.push(f(i));
  271. }
  272. return r2;
  273. };
  274. var chunk$1 = function(array, size) {
  275. var r2 = [];
  276. for (var i = 0; i < array.length; i += size) {
  277. var s = nativeSlice.call(array, i, i + size);
  278. r2.push(s);
  279. }
  280. return r2;
  281. };
  282. var map$2 = function(xs, f) {
  283. var len = xs.length;
  284. var r2 = new Array(len);
  285. for (var i = 0; i < len; i++) {
  286. var x = xs[i];
  287. r2[i] = f(x, i);
  288. }
  289. return r2;
  290. };
  291. var each$1 = function(xs, f) {
  292. for (var i = 0, len = xs.length; i < len; i++) {
  293. var x = xs[i];
  294. f(x, i);
  295. }
  296. };
  297. var eachr = function(xs, f) {
  298. for (var i = xs.length - 1; i >= 0; i--) {
  299. var x = xs[i];
  300. f(x, i);
  301. }
  302. };
  303. var partition$3 = function(xs, pred) {
  304. var pass = [];
  305. var fail = [];
  306. for (var i = 0, len = xs.length; i < len; i++) {
  307. var x = xs[i];
  308. var arr = pred(x, i) ? pass : fail;
  309. arr.push(x);
  310. }
  311. return {
  312. pass,
  313. fail
  314. };
  315. };
  316. var filter$2 = function(xs, pred) {
  317. var r2 = [];
  318. for (var i = 0, len = xs.length; i < len; i++) {
  319. var x = xs[i];
  320. if (pred(x, i)) {
  321. r2.push(x);
  322. }
  323. }
  324. return r2;
  325. };
  326. var foldr = function(xs, f, acc) {
  327. eachr(xs, function(x, i) {
  328. acc = f(acc, x, i);
  329. });
  330. return acc;
  331. };
  332. var foldl = function(xs, f, acc) {
  333. each$1(xs, function(x, i) {
  334. acc = f(acc, x, i);
  335. });
  336. return acc;
  337. };
  338. var findUntil = function(xs, pred, until) {
  339. for (var i = 0, len = xs.length; i < len; i++) {
  340. var x = xs[i];
  341. if (pred(x, i)) {
  342. return Optional.some(x);
  343. } else if (until(x, i)) {
  344. break;
  345. }
  346. }
  347. return Optional.none();
  348. };
  349. var find$5 = function(xs, pred) {
  350. return findUntil(xs, pred, never);
  351. };
  352. var findIndex$1 = function(xs, pred) {
  353. for (var i = 0, len = xs.length; i < len; i++) {
  354. var x = xs[i];
  355. if (pred(x, i)) {
  356. return Optional.some(i);
  357. }
  358. }
  359. return Optional.none();
  360. };
  361. var flatten = function(xs) {
  362. var r2 = [];
  363. for (var i = 0, len = xs.length; i < len; ++i) {
  364. if (!isArray(xs[i])) {
  365. throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
  366. }
  367. nativePush.apply(r2, xs[i]);
  368. }
  369. return r2;
  370. };
  371. var bind$3 = function(xs, f) {
  372. return flatten(map$2(xs, f));
  373. };
  374. var forall = function(xs, pred) {
  375. for (var i = 0, len = xs.length; i < len; ++i) {
  376. var x = xs[i];
  377. if (pred(x, i) !== true) {
  378. return false;
  379. }
  380. }
  381. return true;
  382. };
  383. var reverse = function(xs) {
  384. var r2 = nativeSlice.call(xs, 0);
  385. r2.reverse();
  386. return r2;
  387. };
  388. var difference = function(a1, a2) {
  389. return filter$2(a1, function(x) {
  390. return !contains$2(a2, x);
  391. });
  392. };
  393. var mapToObject = function(xs, f) {
  394. var r2 = {};
  395. for (var i = 0, len = xs.length; i < len; i++) {
  396. var x = xs[i];
  397. r2[String(x)] = f(x, i);
  398. }
  399. return r2;
  400. };
  401. var pure$2 = function(x) {
  402. return [x];
  403. };
  404. var sort = function(xs, comparator) {
  405. var copy = nativeSlice.call(xs, 0);
  406. copy.sort(comparator);
  407. return copy;
  408. };
  409. var get$f = function(xs, i) {
  410. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  411. };
  412. var head = function(xs) {
  413. return get$f(xs, 0);
  414. };
  415. var last$2 = function(xs) {
  416. return get$f(xs, xs.length - 1);
  417. };
  418. var from = isFunction(Array.from) ? Array.from : function(x) {
  419. return nativeSlice.call(x);
  420. };
  421. var findMap = function(arr, f) {
  422. for (var i = 0; i < arr.length; i++) {
  423. var r2 = f(arr[i], i);
  424. if (r2.isSome()) {
  425. return r2;
  426. }
  427. }
  428. return Optional.none();
  429. };
  430. var keys = Object.keys;
  431. var hasOwnProperty = Object.hasOwnProperty;
  432. var each = function(obj, f) {
  433. var props = keys(obj);
  434. for (var k = 0, len = props.length; k < len; k++) {
  435. var i = props[k];
  436. var x = obj[i];
  437. f(x, i);
  438. }
  439. };
  440. var map$1 = function(obj, f) {
  441. return tupleMap(obj, function(x, i) {
  442. return {
  443. k: i,
  444. v: f(x, i)
  445. };
  446. });
  447. };
  448. var tupleMap = function(obj, f) {
  449. var r2 = {};
  450. each(obj, function(x, i) {
  451. var tuple = f(x, i);
  452. r2[tuple.k] = tuple.v;
  453. });
  454. return r2;
  455. };
  456. var objAcc = function(r2) {
  457. return function(x, i) {
  458. r2[i] = x;
  459. };
  460. };
  461. var internalFilter = function(obj, pred, onTrue, onFalse) {
  462. var r2 = {};
  463. each(obj, function(x, i) {
  464. (pred(x, i) ? onTrue : onFalse)(x, i);
  465. });
  466. return r2;
  467. };
  468. var filter$1 = function(obj, pred) {
  469. var t2 = {};
  470. internalFilter(obj, pred, objAcc(t2), noop);
  471. return t2;
  472. };
  473. var mapToArray = function(obj, f) {
  474. var r2 = [];
  475. each(obj, function(value2, name2) {
  476. r2.push(f(value2, name2));
  477. });
  478. return r2;
  479. };
  480. var find$4 = function(obj, pred) {
  481. var props = keys(obj);
  482. for (var k = 0, len = props.length; k < len; k++) {
  483. var i = props[k];
  484. var x = obj[i];
  485. if (pred(x, i, obj)) {
  486. return Optional.some(x);
  487. }
  488. }
  489. return Optional.none();
  490. };
  491. var values = function(obj) {
  492. return mapToArray(obj, identity$1);
  493. };
  494. var get$e = function(obj, key) {
  495. return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none();
  496. };
  497. var has$2 = function(obj, key) {
  498. return hasOwnProperty.call(obj, key);
  499. };
  500. var hasNonNullableKey = function(obj, key) {
  501. return has$2(obj, key) && obj[key] !== void 0 && obj[key] !== null;
  502. };
  503. var is$1 = function(lhs, rhs, comparator) {
  504. if (comparator === void 0) {
  505. comparator = tripleEquals;
  506. }
  507. return lhs.exists(function(left2) {
  508. return comparator(left2, rhs);
  509. });
  510. };
  511. var equals = function(lhs, rhs, comparator) {
  512. if (comparator === void 0) {
  513. comparator = tripleEquals;
  514. }
  515. return lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone());
  516. };
  517. var cat = function(arr) {
  518. var r2 = [];
  519. var push = function(x) {
  520. r2.push(x);
  521. };
  522. for (var i = 0; i < arr.length; i++) {
  523. arr[i].each(push);
  524. }
  525. return r2;
  526. };
  527. var sequence = function(arr) {
  528. var r2 = [];
  529. for (var i = 0; i < arr.length; i++) {
  530. var x = arr[i];
  531. if (x.isSome()) {
  532. r2.push(x.getOrDie());
  533. } else {
  534. return Optional.none();
  535. }
  536. }
  537. return Optional.some(r2);
  538. };
  539. var lift2 = function(oa, ob, f) {
  540. return oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
  541. };
  542. var lift3 = function(oa, ob, oc, f) {
  543. return oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none();
  544. };
  545. var mapFrom = function(a, f) {
  546. return a !== void 0 && a !== null ? Optional.some(f(a)) : Optional.none();
  547. };
  548. var someIf = function(b2, a) {
  549. return b2 ? Optional.some(a) : Optional.none();
  550. };
  551. var addToEnd = function(str, suffix2) {
  552. return str + suffix2;
  553. };
  554. var removeFromStart = function(str, numChars) {
  555. return str.substring(numChars);
  556. };
  557. var checkRange = function(str, substr, start) {
  558. return substr === "" || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
  559. };
  560. var removeLeading = function(str, prefix2) {
  561. return startsWith(str, prefix2) ? removeFromStart(str, prefix2.length) : str;
  562. };
  563. var ensureTrailing = function(str, suffix2) {
  564. return endsWith(str, suffix2) ? str : addToEnd(str, suffix2);
  565. };
  566. var contains$1 = function(str, substr) {
  567. return str.indexOf(substr) !== -1;
  568. };
  569. var startsWith = function(str, prefix2) {
  570. return checkRange(str, prefix2, 0);
  571. };
  572. var endsWith = function(str, suffix2) {
  573. return checkRange(str, suffix2, str.length - suffix2.length);
  574. };
  575. var blank = function(r2) {
  576. return function(s) {
  577. return s.replace(r2, "");
  578. };
  579. };
  580. var trim$1 = blank(/^\s+|\s+$/g);
  581. var isNotEmpty = function(s) {
  582. return s.length > 0;
  583. };
  584. var isEmpty = function(s) {
  585. return !isNotEmpty(s);
  586. };
  587. var isSupported$1 = function(dom2) {
  588. return dom2.style !== void 0 && isFunction(dom2.style.getPropertyValue);
  589. };
  590. var fromHtml$2 = function(html, scope) {
  591. var doc = scope || document;
  592. var div = doc.createElement("div");
  593. div.innerHTML = html;
  594. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  595. console.error("HTML does not have a single root node", html);
  596. throw new Error("HTML must have a single root node");
  597. }
  598. return fromDom(div.childNodes[0]);
  599. };
  600. var fromTag = function(tag, scope) {
  601. var doc = scope || document;
  602. var node = doc.createElement(tag);
  603. return fromDom(node);
  604. };
  605. var fromText = function(text2, scope) {
  606. var doc = scope || document;
  607. var node = doc.createTextNode(text2);
  608. return fromDom(node);
  609. };
  610. var fromDom = function(node) {
  611. if (node === null || node === void 0) {
  612. throw new Error("Node cannot be null or undefined");
  613. }
  614. return { dom: node };
  615. };
  616. var fromPoint = function(docElm, x, y) {
  617. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
  618. };
  619. var SugarElement = {
  620. fromHtml: fromHtml$2,
  621. fromTag,
  622. fromText,
  623. fromDom,
  624. fromPoint
  625. };
  626. typeof window !== "undefined" ? window : Function("return this;")();
  627. var DOCUMENT = 9;
  628. var DOCUMENT_FRAGMENT = 11;
  629. var ELEMENT = 1;
  630. var TEXT = 3;
  631. var name$2 = function(element2) {
  632. var r2 = element2.dom.nodeName;
  633. return r2.toLowerCase();
  634. };
  635. var type = function(element2) {
  636. return element2.dom.nodeType;
  637. };
  638. var isType = function(t2) {
  639. return function(element2) {
  640. return type(element2) === t2;
  641. };
  642. };
  643. var isElement$2 = isType(ELEMENT);
  644. var isText$1 = isType(TEXT);
  645. var isDocument = isType(DOCUMENT);
  646. var isDocumentFragment = isType(DOCUMENT_FRAGMENT);
  647. var cached = function(f) {
  648. var called = false;
  649. var r2;
  650. return function() {
  651. var args = [];
  652. for (var _i = 0; _i < arguments.length; _i++) {
  653. args[_i] = arguments[_i];
  654. }
  655. if (!called) {
  656. called = true;
  657. r2 = f.apply(null, args);
  658. }
  659. return r2;
  660. };
  661. };
  662. var DeviceType = function(os, browser, userAgent, mediaMatch2) {
  663. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  664. var isiPhone = os.isiOS() && !isiPad;
  665. var isMobile = os.isiOS() || os.isAndroid();
  666. var isTouch2 = isMobile || mediaMatch2("(pointer:coarse)");
  667. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch2("(min-device-width:768px)");
  668. var isPhone = isiPhone || isMobile && !isTablet;
  669. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  670. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  671. return {
  672. isiPad: constant$1(isiPad),
  673. isiPhone: constant$1(isiPhone),
  674. isTablet: constant$1(isTablet),
  675. isPhone: constant$1(isPhone),
  676. isTouch: constant$1(isTouch2),
  677. isAndroid: os.isAndroid,
  678. isiOS: os.isiOS,
  679. isWebView: constant$1(iOSwebview),
  680. isDesktop: constant$1(isDesktop)
  681. };
  682. };
  683. var firstMatch = function(regexes, s) {
  684. for (var i = 0; i < regexes.length; i++) {
  685. var x = regexes[i];
  686. if (x.test(s)) {
  687. return x;
  688. }
  689. }
  690. return void 0;
  691. };
  692. var find$3 = function(regexes, agent) {
  693. var r2 = firstMatch(regexes, agent);
  694. if (!r2) {
  695. return {
  696. major: 0,
  697. minor: 0
  698. };
  699. }
  700. var group2 = function(i) {
  701. return Number(agent.replace(r2, "$" + i));
  702. };
  703. return nu$d(group2(1), group2(2));
  704. };
  705. var detect$4 = function(versionRegexes, agent) {
  706. var cleanedAgent = String(agent).toLowerCase();
  707. if (versionRegexes.length === 0) {
  708. return unknown$3();
  709. }
  710. return find$3(versionRegexes, cleanedAgent);
  711. };
  712. var unknown$3 = function() {
  713. return nu$d(0, 0);
  714. };
  715. var nu$d = function(major, minor) {
  716. return {
  717. major,
  718. minor
  719. };
  720. };
  721. var Version = {
  722. nu: nu$d,
  723. detect: detect$4,
  724. unknown: unknown$3
  725. };
  726. var detectBrowser$1 = function(browsers2, userAgentData) {
  727. return findMap(userAgentData.brands, function(uaBrand) {
  728. var lcBrand = uaBrand.brand.toLowerCase();
  729. return find$5(browsers2, function(browser) {
  730. var _a2;
  731. return lcBrand === ((_a2 = browser.brand) === null || _a2 === void 0 ? void 0 : _a2.toLowerCase());
  732. }).map(function(info) {
  733. return {
  734. current: info.name,
  735. version: Version.nu(parseInt(uaBrand.version, 10), 0)
  736. };
  737. });
  738. });
  739. };
  740. var detect$3 = function(candidates, userAgent) {
  741. var agent = String(userAgent).toLowerCase();
  742. return find$5(candidates, function(candidate) {
  743. return candidate.search(agent);
  744. });
  745. };
  746. var detectBrowser = function(browsers2, userAgent) {
  747. return detect$3(browsers2, userAgent).map(function(browser) {
  748. var version = Version.detect(browser.versionRegexes, userAgent);
  749. return {
  750. current: browser.name,
  751. version
  752. };
  753. });
  754. };
  755. var detectOs = function(oses2, userAgent) {
  756. return detect$3(oses2, userAgent).map(function(os) {
  757. var version = Version.detect(os.versionRegexes, userAgent);
  758. return {
  759. current: os.name,
  760. version
  761. };
  762. });
  763. };
  764. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  765. var checkContains = function(target) {
  766. return function(uastring) {
  767. return contains$1(uastring, target);
  768. };
  769. };
  770. var browsers = [
  771. {
  772. name: "Edge",
  773. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  774. search: function(uastring) {
  775. return contains$1(uastring, "edge/") && contains$1(uastring, "chrome") && contains$1(uastring, "safari") && contains$1(uastring, "applewebkit");
  776. }
  777. },
  778. {
  779. name: "Chrome",
  780. brand: "Chromium",
  781. versionRegexes: [
  782. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  783. normalVersionRegex
  784. ],
  785. search: function(uastring) {
  786. return contains$1(uastring, "chrome") && !contains$1(uastring, "chromeframe");
  787. }
  788. },
  789. {
  790. name: "IE",
  791. versionRegexes: [
  792. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  793. /.*?rv:([0-9]+)\.([0-9]+).*/
  794. ],
  795. search: function(uastring) {
  796. return contains$1(uastring, "msie") || contains$1(uastring, "trident");
  797. }
  798. },
  799. {
  800. name: "Opera",
  801. versionRegexes: [
  802. normalVersionRegex,
  803. /.*?opera\/([0-9]+)\.([0-9]+).*/
  804. ],
  805. search: checkContains("opera")
  806. },
  807. {
  808. name: "Firefox",
  809. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  810. search: checkContains("firefox")
  811. },
  812. {
  813. name: "Safari",
  814. versionRegexes: [
  815. normalVersionRegex,
  816. /.*?cpu os ([0-9]+)_([0-9]+).*/
  817. ],
  818. search: function(uastring) {
  819. return (contains$1(uastring, "safari") || contains$1(uastring, "mobile/")) && contains$1(uastring, "applewebkit");
  820. }
  821. }
  822. ];
  823. var oses = [
  824. {
  825. name: "Windows",
  826. search: checkContains("win"),
  827. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  828. },
  829. {
  830. name: "iOS",
  831. search: function(uastring) {
  832. return contains$1(uastring, "iphone") || contains$1(uastring, "ipad");
  833. },
  834. versionRegexes: [
  835. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  836. /.*cpu os ([0-9]+)_([0-9]+).*/,
  837. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  838. ]
  839. },
  840. {
  841. name: "Android",
  842. search: checkContains("android"),
  843. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  844. },
  845. {
  846. name: "OSX",
  847. search: checkContains("mac os x"),
  848. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  849. },
  850. {
  851. name: "Linux",
  852. search: checkContains("linux"),
  853. versionRegexes: []
  854. },
  855. {
  856. name: "Solaris",
  857. search: checkContains("sunos"),
  858. versionRegexes: []
  859. },
  860. {
  861. name: "FreeBSD",
  862. search: checkContains("freebsd"),
  863. versionRegexes: []
  864. },
  865. {
  866. name: "ChromeOS",
  867. search: checkContains("cros"),
  868. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  869. }
  870. ];
  871. var PlatformInfo = {
  872. browsers: constant$1(browsers),
  873. oses: constant$1(oses)
  874. };
  875. var edge = "Edge";
  876. var chrome = "Chrome";
  877. var ie = "IE";
  878. var opera = "Opera";
  879. var firefox = "Firefox";
  880. var safari = "Safari";
  881. var unknown$2 = function() {
  882. return nu$c({
  883. current: void 0,
  884. version: Version.unknown()
  885. });
  886. };
  887. var nu$c = function(info) {
  888. var current = info.current;
  889. var version = info.version;
  890. var isBrowser = function(name2) {
  891. return function() {
  892. return current === name2;
  893. };
  894. };
  895. return {
  896. current,
  897. version,
  898. isEdge: isBrowser(edge),
  899. isChrome: isBrowser(chrome),
  900. isIE: isBrowser(ie),
  901. isOpera: isBrowser(opera),
  902. isFirefox: isBrowser(firefox),
  903. isSafari: isBrowser(safari)
  904. };
  905. };
  906. var Browser = {
  907. unknown: unknown$2,
  908. nu: nu$c,
  909. edge: constant$1(edge),
  910. chrome: constant$1(chrome),
  911. ie: constant$1(ie),
  912. opera: constant$1(opera),
  913. firefox: constant$1(firefox),
  914. safari: constant$1(safari)
  915. };
  916. var windows = "Windows";
  917. var ios = "iOS";
  918. var android = "Android";
  919. var linux = "Linux";
  920. var osx = "OSX";
  921. var solaris = "Solaris";
  922. var freebsd = "FreeBSD";
  923. var chromeos = "ChromeOS";
  924. var unknown$1 = function() {
  925. return nu$b({
  926. current: void 0,
  927. version: Version.unknown()
  928. });
  929. };
  930. var nu$b = function(info) {
  931. var current = info.current;
  932. var version = info.version;
  933. var isOS = function(name2) {
  934. return function() {
  935. return current === name2;
  936. };
  937. };
  938. return {
  939. current,
  940. version,
  941. isWindows: isOS(windows),
  942. isiOS: isOS(ios),
  943. isAndroid: isOS(android),
  944. isOSX: isOS(osx),
  945. isLinux: isOS(linux),
  946. isSolaris: isOS(solaris),
  947. isFreeBSD: isOS(freebsd),
  948. isChromeOS: isOS(chromeos)
  949. };
  950. };
  951. var OperatingSystem = {
  952. unknown: unknown$1,
  953. nu: nu$b,
  954. windows: constant$1(windows),
  955. ios: constant$1(ios),
  956. android: constant$1(android),
  957. linux: constant$1(linux),
  958. osx: constant$1(osx),
  959. solaris: constant$1(solaris),
  960. freebsd: constant$1(freebsd),
  961. chromeos: constant$1(chromeos)
  962. };
  963. var detect$2 = function(userAgent, userAgentDataOpt, mediaMatch2) {
  964. var browsers2 = PlatformInfo.browsers();
  965. var oses2 = PlatformInfo.oses();
  966. var browser = userAgentDataOpt.bind(function(userAgentData) {
  967. return detectBrowser$1(browsers2, userAgentData);
  968. }).orThunk(function() {
  969. return detectBrowser(browsers2, userAgent);
  970. }).fold(Browser.unknown, Browser.nu);
  971. var os = detectOs(oses2, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  972. var deviceType = DeviceType(os, browser, userAgent, mediaMatch2);
  973. return {
  974. browser,
  975. os,
  976. deviceType
  977. };
  978. };
  979. var PlatformDetection = { detect: detect$2 };
  980. var mediaMatch = function(query2) {
  981. return window.matchMedia(query2).matches;
  982. };
  983. var platform = cached(function() {
  984. return PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch);
  985. });
  986. var detect$1 = function() {
  987. return platform();
  988. };
  989. var compareDocumentPosition = function(a, b2, match) {
  990. return (a.compareDocumentPosition(b2) & match) !== 0;
  991. };
  992. var documentPositionContainedBy = function(a, b2) {
  993. return compareDocumentPosition(a, b2, Node.DOCUMENT_POSITION_CONTAINED_BY);
  994. };
  995. var is = function(element2, selector) {
  996. var dom2 = element2.dom;
  997. if (dom2.nodeType !== ELEMENT) {
  998. return false;
  999. } else {
  1000. var elem = dom2;
  1001. if (elem.matches !== void 0) {
  1002. return elem.matches(selector);
  1003. } else if (elem.msMatchesSelector !== void 0) {
  1004. return elem.msMatchesSelector(selector);
  1005. } else if (elem.webkitMatchesSelector !== void 0) {
  1006. return elem.webkitMatchesSelector(selector);
  1007. } else if (elem.mozMatchesSelector !== void 0) {
  1008. return elem.mozMatchesSelector(selector);
  1009. } else {
  1010. throw new Error("Browser lacks native selectors");
  1011. }
  1012. }
  1013. };
  1014. var bypassSelector = function(dom2) {
  1015. return dom2.nodeType !== ELEMENT && dom2.nodeType !== DOCUMENT && dom2.nodeType !== DOCUMENT_FRAGMENT || dom2.childElementCount === 0;
  1016. };
  1017. var all$3 = function(selector, scope) {
  1018. var base2 = scope === void 0 ? document : scope.dom;
  1019. return bypassSelector(base2) ? [] : map$2(base2.querySelectorAll(selector), SugarElement.fromDom);
  1020. };
  1021. var one = function(selector, scope) {
  1022. var base2 = scope === void 0 ? document : scope.dom;
  1023. return bypassSelector(base2) ? Optional.none() : Optional.from(base2.querySelector(selector)).map(SugarElement.fromDom);
  1024. };
  1025. var eq = function(e1, e2) {
  1026. return e1.dom === e2.dom;
  1027. };
  1028. var regularContains = function(e1, e2) {
  1029. var d1 = e1.dom;
  1030. var d2 = e2.dom;
  1031. return d1 === d2 ? false : d1.contains(d2);
  1032. };
  1033. var ieContains = function(e1, e2) {
  1034. return documentPositionContainedBy(e1.dom, e2.dom);
  1035. };
  1036. var contains = function(e1, e2) {
  1037. return detect$1().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
  1038. };
  1039. var owner$4 = function(element2) {
  1040. return SugarElement.fromDom(element2.dom.ownerDocument);
  1041. };
  1042. var documentOrOwner = function(dos) {
  1043. return isDocument(dos) ? dos : owner$4(dos);
  1044. };
  1045. var documentElement = function(element2) {
  1046. return SugarElement.fromDom(documentOrOwner(element2).dom.documentElement);
  1047. };
  1048. var defaultView = function(element2) {
  1049. return SugarElement.fromDom(documentOrOwner(element2).dom.defaultView);
  1050. };
  1051. var parent = function(element2) {
  1052. return Optional.from(element2.dom.parentNode).map(SugarElement.fromDom);
  1053. };
  1054. var parentNode = function(element2) {
  1055. return parent(element2);
  1056. };
  1057. var offsetParent = function(element2) {
  1058. return Optional.from(element2.dom.offsetParent).map(SugarElement.fromDom);
  1059. };
  1060. var nextSibling = function(element2) {
  1061. return Optional.from(element2.dom.nextSibling).map(SugarElement.fromDom);
  1062. };
  1063. var children = function(element2) {
  1064. return map$2(element2.dom.childNodes, SugarElement.fromDom);
  1065. };
  1066. var child$2 = function(element2, index) {
  1067. var cs = element2.dom.childNodes;
  1068. return Optional.from(cs[index]).map(SugarElement.fromDom);
  1069. };
  1070. var firstChild = function(element2) {
  1071. return child$2(element2, 0);
  1072. };
  1073. var spot = function(element2, offset2) {
  1074. return {
  1075. element: element2,
  1076. offset: offset2
  1077. };
  1078. };
  1079. var leaf = function(element2, offset2) {
  1080. var cs = children(element2);
  1081. return cs.length > 0 && offset2 < cs.length ? spot(cs[offset2], 0) : spot(element2, offset2);
  1082. };
  1083. var isShadowRoot = function(dos) {
  1084. return isDocumentFragment(dos) && isNonNullable(dos.dom.host);
  1085. };
  1086. var supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
  1087. var isSupported = constant$1(supported);
  1088. var getRootNode = supported ? function(e) {
  1089. return SugarElement.fromDom(e.dom.getRootNode());
  1090. } : documentOrOwner;
  1091. var getContentContainer = function(dos) {
  1092. return isShadowRoot(dos) ? dos : SugarElement.fromDom(documentOrOwner(dos).dom.body);
  1093. };
  1094. var isInShadowRoot = function(e) {
  1095. return getShadowRoot(e).isSome();
  1096. };
  1097. var getShadowRoot = function(e) {
  1098. var r2 = getRootNode(e);
  1099. return isShadowRoot(r2) ? Optional.some(r2) : Optional.none();
  1100. };
  1101. var getShadowHost = function(e) {
  1102. return SugarElement.fromDom(e.dom.host);
  1103. };
  1104. var getOriginalEventTarget = function(event) {
  1105. if (isSupported() && isNonNullable(event.target)) {
  1106. var el = SugarElement.fromDom(event.target);
  1107. if (isElement$2(el) && isOpenShadowHost(el)) {
  1108. if (event.composed && event.composedPath) {
  1109. var composedPath = event.composedPath();
  1110. if (composedPath) {
  1111. return head(composedPath);
  1112. }
  1113. }
  1114. }
  1115. }
  1116. return Optional.from(event.target);
  1117. };
  1118. var isOpenShadowHost = function(element2) {
  1119. return isNonNullable(element2.dom.shadowRoot);
  1120. };
  1121. var inBody = function(element2) {
  1122. var dom2 = isText$1(element2) ? element2.dom.parentNode : element2.dom;
  1123. if (dom2 === void 0 || dom2 === null || dom2.ownerDocument === null) {
  1124. return false;
  1125. }
  1126. var doc = dom2.ownerDocument;
  1127. return getShadowRoot(SugarElement.fromDom(dom2)).fold(function() {
  1128. return doc.body.contains(dom2);
  1129. }, compose1(inBody, getShadowHost));
  1130. };
  1131. var body = function() {
  1132. return getBody(SugarElement.fromDom(document));
  1133. };
  1134. var getBody = function(doc) {
  1135. var b2 = doc.dom.body;
  1136. if (b2 === null || b2 === void 0) {
  1137. throw new Error("Body is not available yet");
  1138. }
  1139. return SugarElement.fromDom(b2);
  1140. };
  1141. var rawSet = function(dom2, key, value2) {
  1142. if (isString(value2) || isBoolean(value2) || isNumber(value2)) {
  1143. dom2.setAttribute(key, value2 + "");
  1144. } else {
  1145. console.error("Invalid call to Attribute.set. Key ", key, ":: Value ", value2, ":: Element ", dom2);
  1146. throw new Error("Attribute value was not simple");
  1147. }
  1148. };
  1149. var set$8 = function(element2, key, value2) {
  1150. rawSet(element2.dom, key, value2);
  1151. };
  1152. var setAll$1 = function(element2, attrs) {
  1153. var dom2 = element2.dom;
  1154. each(attrs, function(v, k) {
  1155. rawSet(dom2, k, v);
  1156. });
  1157. };
  1158. var get$d = function(element2, key) {
  1159. var v = element2.dom.getAttribute(key);
  1160. return v === null ? void 0 : v;
  1161. };
  1162. var getOpt = function(element2, key) {
  1163. return Optional.from(get$d(element2, key));
  1164. };
  1165. var has$1 = function(element2, key) {
  1166. var dom2 = element2.dom;
  1167. return dom2 && dom2.hasAttribute ? dom2.hasAttribute(key) : false;
  1168. };
  1169. var remove$7 = function(element2, key) {
  1170. element2.dom.removeAttribute(key);
  1171. };
  1172. var internalSet = function(dom2, property, value2) {
  1173. if (!isString(value2)) {
  1174. console.error("Invalid call to CSS.set. Property ", property, ":: Value ", value2, ":: Element ", dom2);
  1175. throw new Error("CSS value must be a string: " + value2);
  1176. }
  1177. if (isSupported$1(dom2)) {
  1178. dom2.style.setProperty(property, value2);
  1179. }
  1180. };
  1181. var internalRemove = function(dom2, property) {
  1182. if (isSupported$1(dom2)) {
  1183. dom2.style.removeProperty(property);
  1184. }
  1185. };
  1186. var set$7 = function(element2, property, value2) {
  1187. var dom2 = element2.dom;
  1188. internalSet(dom2, property, value2);
  1189. };
  1190. var setAll = function(element2, css) {
  1191. var dom2 = element2.dom;
  1192. each(css, function(v, k) {
  1193. internalSet(dom2, k, v);
  1194. });
  1195. };
  1196. var setOptions = function(element2, css) {
  1197. var dom2 = element2.dom;
  1198. each(css, function(v, k) {
  1199. v.fold(function() {
  1200. internalRemove(dom2, k);
  1201. }, function(value2) {
  1202. internalSet(dom2, k, value2);
  1203. });
  1204. });
  1205. };
  1206. var get$c = function(element2, property) {
  1207. var dom2 = element2.dom;
  1208. var styles = window.getComputedStyle(dom2);
  1209. var r2 = styles.getPropertyValue(property);
  1210. return r2 === "" && !inBody(element2) ? getUnsafeProperty(dom2, property) : r2;
  1211. };
  1212. var getUnsafeProperty = function(dom2, property) {
  1213. return isSupported$1(dom2) ? dom2.style.getPropertyValue(property) : "";
  1214. };
  1215. var getRaw = function(element2, property) {
  1216. var dom2 = element2.dom;
  1217. var raw = getUnsafeProperty(dom2, property);
  1218. return Optional.from(raw).filter(function(r2) {
  1219. return r2.length > 0;
  1220. });
  1221. };
  1222. var getAllRaw = function(element2) {
  1223. var css = {};
  1224. var dom2 = element2.dom;
  1225. if (isSupported$1(dom2)) {
  1226. for (var i = 0; i < dom2.style.length; i++) {
  1227. var ruleName = dom2.style.item(i);
  1228. css[ruleName] = dom2.style[ruleName];
  1229. }
  1230. }
  1231. return css;
  1232. };
  1233. var isValidValue = function(tag, property, value2) {
  1234. var element2 = SugarElement.fromTag(tag);
  1235. set$7(element2, property, value2);
  1236. var style = getRaw(element2, property);
  1237. return style.isSome();
  1238. };
  1239. var remove$6 = function(element2, property) {
  1240. var dom2 = element2.dom;
  1241. internalRemove(dom2, property);
  1242. if (is$1(getOpt(element2, "style").map(trim$1), "")) {
  1243. remove$7(element2, "style");
  1244. }
  1245. };
  1246. var reflow = function(e) {
  1247. return e.dom.offsetWidth;
  1248. };
  1249. var Dimension = function(name2, getOffset2) {
  1250. var set2 = function(element2, h) {
  1251. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  1252. throw new Error(name2 + ".set accepts only positive integer values. Value was " + h);
  1253. }
  1254. var dom2 = element2.dom;
  1255. if (isSupported$1(dom2)) {
  1256. dom2.style[name2] = h + "px";
  1257. }
  1258. };
  1259. var get2 = function(element2) {
  1260. var r2 = getOffset2(element2);
  1261. if (r2 <= 0 || r2 === null) {
  1262. var css = get$c(element2, name2);
  1263. return parseFloat(css) || 0;
  1264. }
  1265. return r2;
  1266. };
  1267. var getOuter2 = get2;
  1268. var aggregate = function(element2, properties2) {
  1269. return foldl(properties2, function(acc, property) {
  1270. var val = get$c(element2, property);
  1271. var value2 = val === void 0 ? 0 : parseInt(val, 10);
  1272. return isNaN(value2) ? acc : acc + value2;
  1273. }, 0);
  1274. };
  1275. var max2 = function(element2, value2, properties2) {
  1276. var cumulativeInclusions = aggregate(element2, properties2);
  1277. var absoluteMax = value2 > cumulativeInclusions ? value2 - cumulativeInclusions : 0;
  1278. return absoluteMax;
  1279. };
  1280. return {
  1281. set: set2,
  1282. get: get2,
  1283. getOuter: getOuter2,
  1284. aggregate,
  1285. max: max2
  1286. };
  1287. };
  1288. var api$3 = Dimension("height", function(element2) {
  1289. var dom2 = element2.dom;
  1290. return inBody(element2) ? dom2.getBoundingClientRect().height : dom2.offsetHeight;
  1291. });
  1292. var get$b = function(element2) {
  1293. return api$3.get(element2);
  1294. };
  1295. var getOuter$2 = function(element2) {
  1296. return api$3.getOuter(element2);
  1297. };
  1298. var setMax$1 = function(element2, value2) {
  1299. var inclusions = [
  1300. "margin-top",
  1301. "border-top-width",
  1302. "padding-top",
  1303. "padding-bottom",
  1304. "border-bottom-width",
  1305. "margin-bottom"
  1306. ];
  1307. var absMax = api$3.max(element2, value2, inclusions);
  1308. set$7(element2, "max-height", absMax + "px");
  1309. };
  1310. var r$1 = function(left2, top2) {
  1311. var translate2 = function(x, y) {
  1312. return r$1(left2 + x, top2 + y);
  1313. };
  1314. return {
  1315. left: left2,
  1316. top: top2,
  1317. translate: translate2
  1318. };
  1319. };
  1320. var SugarPosition = r$1;
  1321. var boxPosition = function(dom2) {
  1322. var box2 = dom2.getBoundingClientRect();
  1323. return SugarPosition(box2.left, box2.top);
  1324. };
  1325. var firstDefinedOrZero = function(a, b2) {
  1326. if (a !== void 0) {
  1327. return a;
  1328. } else {
  1329. return b2 !== void 0 ? b2 : 0;
  1330. }
  1331. };
  1332. var absolute$3 = function(element2) {
  1333. var doc = element2.dom.ownerDocument;
  1334. var body2 = doc.body;
  1335. var win2 = doc.defaultView;
  1336. var html = doc.documentElement;
  1337. if (body2 === element2.dom) {
  1338. return SugarPosition(body2.offsetLeft, body2.offsetTop);
  1339. }
  1340. var scrollTop = firstDefinedOrZero(win2 === null || win2 === void 0 ? void 0 : win2.pageYOffset, html.scrollTop);
  1341. var scrollLeft = firstDefinedOrZero(win2 === null || win2 === void 0 ? void 0 : win2.pageXOffset, html.scrollLeft);
  1342. var clientTop = firstDefinedOrZero(html.clientTop, body2.clientTop);
  1343. var clientLeft = firstDefinedOrZero(html.clientLeft, body2.clientLeft);
  1344. return viewport$1(element2).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  1345. };
  1346. var viewport$1 = function(element2) {
  1347. var dom2 = element2.dom;
  1348. var doc = dom2.ownerDocument;
  1349. var body2 = doc.body;
  1350. if (body2 === dom2) {
  1351. return SugarPosition(body2.offsetLeft, body2.offsetTop);
  1352. }
  1353. if (!inBody(element2)) {
  1354. return SugarPosition(0, 0);
  1355. }
  1356. return boxPosition(dom2);
  1357. };
  1358. var api$2 = Dimension("width", function(element2) {
  1359. return element2.dom.offsetWidth;
  1360. });
  1361. var set$6 = function(element2, h) {
  1362. return api$2.set(element2, h);
  1363. };
  1364. var get$a = function(element2) {
  1365. return api$2.get(element2);
  1366. };
  1367. var getOuter$1 = function(element2) {
  1368. return api$2.getOuter(element2);
  1369. };
  1370. var setMax = function(element2, value2) {
  1371. var inclusions = [
  1372. "margin-left",
  1373. "border-left-width",
  1374. "padding-left",
  1375. "padding-right",
  1376. "border-right-width",
  1377. "margin-right"
  1378. ];
  1379. var absMax = api$2.max(element2, value2, inclusions);
  1380. set$7(element2, "max-width", absMax + "px");
  1381. };
  1382. var mkEvent = function(target, x, y, stop2, prevent, kill, raw) {
  1383. return {
  1384. target,
  1385. x,
  1386. y,
  1387. stop: stop2,
  1388. prevent,
  1389. kill,
  1390. raw
  1391. };
  1392. };
  1393. var fromRawEvent$1 = function(rawEvent) {
  1394. var target = SugarElement.fromDom(getOriginalEventTarget(rawEvent).getOr(rawEvent.target));
  1395. var stop2 = function() {
  1396. return rawEvent.stopPropagation();
  1397. };
  1398. var prevent = function() {
  1399. return rawEvent.preventDefault();
  1400. };
  1401. var kill = compose(prevent, stop2);
  1402. return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop2, prevent, kill, rawEvent);
  1403. };
  1404. var handle = function(filter2, handler) {
  1405. return function(rawEvent) {
  1406. if (filter2(rawEvent)) {
  1407. handler(fromRawEvent$1(rawEvent));
  1408. }
  1409. };
  1410. };
  1411. var binder = function(element2, event, filter2, handler, useCapture) {
  1412. var wrapped = handle(filter2, handler);
  1413. element2.dom.addEventListener(event, wrapped, useCapture);
  1414. return { unbind: curry(unbind, element2, event, wrapped, useCapture) };
  1415. };
  1416. var bind$2 = function(element2, event, filter2, handler) {
  1417. return binder(element2, event, filter2, handler, false);
  1418. };
  1419. var capture$1 = function(element2, event, filter2, handler) {
  1420. return binder(element2, event, filter2, handler, true);
  1421. };
  1422. var unbind = function(element2, event, handler, useCapture) {
  1423. element2.dom.removeEventListener(event, handler, useCapture);
  1424. };
  1425. var before$2 = function(marker, element2) {
  1426. var parent$1 = parent(marker);
  1427. parent$1.each(function(v) {
  1428. v.dom.insertBefore(element2.dom, marker.dom);
  1429. });
  1430. };
  1431. var after$2 = function(marker, element2) {
  1432. var sibling = nextSibling(marker);
  1433. sibling.fold(function() {
  1434. var parent$1 = parent(marker);
  1435. parent$1.each(function(v) {
  1436. append$2(v, element2);
  1437. });
  1438. }, function(v) {
  1439. before$2(v, element2);
  1440. });
  1441. };
  1442. var prepend$1 = function(parent2, element2) {
  1443. var firstChild$1 = firstChild(parent2);
  1444. firstChild$1.fold(function() {
  1445. append$2(parent2, element2);
  1446. }, function(v) {
  1447. parent2.dom.insertBefore(element2.dom, v.dom);
  1448. });
  1449. };
  1450. var append$2 = function(parent2, element2) {
  1451. parent2.dom.appendChild(element2.dom);
  1452. };
  1453. var appendAt = function(parent2, element2, index) {
  1454. child$2(parent2, index).fold(function() {
  1455. append$2(parent2, element2);
  1456. }, function(v) {
  1457. before$2(v, element2);
  1458. });
  1459. };
  1460. var before$1 = function(marker, elements) {
  1461. each$1(elements, function(x) {
  1462. before$2(marker, x);
  1463. });
  1464. };
  1465. var append$1 = function(parent2, elements) {
  1466. each$1(elements, function(x) {
  1467. append$2(parent2, x);
  1468. });
  1469. };
  1470. var empty = function(element2) {
  1471. element2.dom.textContent = "";
  1472. each$1(children(element2), function(rogue) {
  1473. remove$5(rogue);
  1474. });
  1475. };
  1476. var remove$5 = function(element2) {
  1477. var dom2 = element2.dom;
  1478. if (dom2.parentNode !== null) {
  1479. dom2.parentNode.removeChild(dom2);
  1480. }
  1481. };
  1482. var unwrap = function(wrapper) {
  1483. var children$1 = children(wrapper);
  1484. if (children$1.length > 0) {
  1485. before$1(wrapper, children$1);
  1486. }
  1487. remove$5(wrapper);
  1488. };
  1489. var get$9 = function(_DOC) {
  1490. var doc = _DOC !== void 0 ? _DOC.dom : document;
  1491. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  1492. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  1493. return SugarPosition(x, y);
  1494. };
  1495. var to = function(x, y, _DOC) {
  1496. var doc = _DOC !== void 0 ? _DOC.dom : document;
  1497. var win2 = doc.defaultView;
  1498. if (win2) {
  1499. win2.scrollTo(x, y);
  1500. }
  1501. };
  1502. var get$8 = function(_win) {
  1503. var win2 = _win === void 0 ? window : _win;
  1504. if (detect$1().browser.isFirefox()) {
  1505. return Optional.none();
  1506. } else {
  1507. return Optional.from(win2["visualViewport"]);
  1508. }
  1509. };
  1510. var bounds$1 = function(x, y, width2, height2) {
  1511. return {
  1512. x,
  1513. y,
  1514. width: width2,
  1515. height: height2,
  1516. right: x + width2,
  1517. bottom: y + height2
  1518. };
  1519. };
  1520. var getBounds$3 = function(_win) {
  1521. var win2 = _win === void 0 ? window : _win;
  1522. var doc = win2.document;
  1523. var scroll = get$9(SugarElement.fromDom(doc));
  1524. return get$8(win2).fold(function() {
  1525. var html = win2.document.documentElement;
  1526. var width2 = html.clientWidth;
  1527. var height2 = html.clientHeight;
  1528. return bounds$1(scroll.left, scroll.top, width2, height2);
  1529. }, function(visualViewport) {
  1530. return bounds$1(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height);
  1531. });
  1532. };
  1533. var walkUp = function(navigation, doc) {
  1534. var frame = navigation.view(doc);
  1535. return frame.fold(constant$1([]), function(f) {
  1536. var parent2 = navigation.owner(f);
  1537. var rest = walkUp(navigation, parent2);
  1538. return [f].concat(rest);
  1539. });
  1540. };
  1541. var pathTo = function(element2, navigation) {
  1542. var d = navigation.owner(element2);
  1543. var paths = walkUp(navigation, d);
  1544. return Optional.some(paths);
  1545. };
  1546. var view = function(doc) {
  1547. var _a2;
  1548. var element2 = doc.dom === document ? Optional.none() : Optional.from((_a2 = doc.dom.defaultView) === null || _a2 === void 0 ? void 0 : _a2.frameElement);
  1549. return element2.map(SugarElement.fromDom);
  1550. };
  1551. var owner$3 = function(element2) {
  1552. return owner$4(element2);
  1553. };
  1554. var Navigation = Object.freeze({
  1555. __proto__: null,
  1556. view,
  1557. owner: owner$3
  1558. });
  1559. var find$2 = function(element2) {
  1560. var doc = SugarElement.fromDom(document);
  1561. var scroll = get$9(doc);
  1562. var path2 = pathTo(element2, Navigation);
  1563. return path2.fold(curry(absolute$3, element2), function(frames) {
  1564. var offset2 = viewport$1(element2);
  1565. var r2 = foldr(frames, function(b2, a) {
  1566. var loc = viewport$1(a);
  1567. return {
  1568. left: b2.left + loc.left,
  1569. top: b2.top + loc.top
  1570. };
  1571. }, {
  1572. left: 0,
  1573. top: 0
  1574. });
  1575. return SugarPosition(r2.left + offset2.left + scroll.left, r2.top + offset2.top + scroll.top);
  1576. });
  1577. };
  1578. var pointed = function(point2, width2, height2) {
  1579. return {
  1580. point: point2,
  1581. width: width2,
  1582. height: height2
  1583. };
  1584. };
  1585. var rect = function(x, y, width2, height2) {
  1586. return {
  1587. x,
  1588. y,
  1589. width: width2,
  1590. height: height2
  1591. };
  1592. };
  1593. var bounds = function(x, y, width2, height2) {
  1594. return {
  1595. x,
  1596. y,
  1597. width: width2,
  1598. height: height2,
  1599. right: x + width2,
  1600. bottom: y + height2
  1601. };
  1602. };
  1603. var box$1 = function(element2) {
  1604. var xy = absolute$3(element2);
  1605. var w = getOuter$1(element2);
  1606. var h = getOuter$2(element2);
  1607. return bounds(xy.left, xy.top, w, h);
  1608. };
  1609. var absolute$2 = function(element2) {
  1610. var position2 = find$2(element2);
  1611. var width2 = getOuter$1(element2);
  1612. var height2 = getOuter$2(element2);
  1613. return bounds(position2.left, position2.top, width2, height2);
  1614. };
  1615. var win = function() {
  1616. return getBounds$3(window);
  1617. };
  1618. var value$3 = function(o) {
  1619. var or = function(_opt) {
  1620. return value$3(o);
  1621. };
  1622. var orThunk = function(_f) {
  1623. return value$3(o);
  1624. };
  1625. var map2 = function(f) {
  1626. return value$3(f(o));
  1627. };
  1628. var mapError2 = function(_f) {
  1629. return value$3(o);
  1630. };
  1631. var each2 = function(f) {
  1632. f(o);
  1633. };
  1634. var bind2 = function(f) {
  1635. return f(o);
  1636. };
  1637. var fold2 = function(_, onValue) {
  1638. return onValue(o);
  1639. };
  1640. var exists2 = function(f) {
  1641. return f(o);
  1642. };
  1643. var forall2 = function(f) {
  1644. return f(o);
  1645. };
  1646. var toOptional = function() {
  1647. return Optional.some(o);
  1648. };
  1649. return {
  1650. isValue: always,
  1651. isError: never,
  1652. getOr: constant$1(o),
  1653. getOrThunk: constant$1(o),
  1654. getOrDie: constant$1(o),
  1655. or,
  1656. orThunk,
  1657. fold: fold2,
  1658. map: map2,
  1659. mapError: mapError2,
  1660. each: each2,
  1661. bind: bind2,
  1662. exists: exists2,
  1663. forall: forall2,
  1664. toOptional
  1665. };
  1666. };
  1667. var error$1 = function(message) {
  1668. var getOrThunk = function(f) {
  1669. return f();
  1670. };
  1671. var getOrDie2 = function() {
  1672. return die(String(message))();
  1673. };
  1674. var or = identity$1;
  1675. var orThunk = function(f) {
  1676. return f();
  1677. };
  1678. var map2 = function(_f) {
  1679. return error$1(message);
  1680. };
  1681. var mapError2 = function(f) {
  1682. return error$1(f(message));
  1683. };
  1684. var bind2 = function(_f) {
  1685. return error$1(message);
  1686. };
  1687. var fold2 = function(onError, _) {
  1688. return onError(message);
  1689. };
  1690. return {
  1691. isValue: never,
  1692. isError: always,
  1693. getOr: identity$1,
  1694. getOrThunk,
  1695. getOrDie: getOrDie2,
  1696. or,
  1697. orThunk,
  1698. fold: fold2,
  1699. map: map2,
  1700. mapError: mapError2,
  1701. each: noop,
  1702. bind: bind2,
  1703. exists: never,
  1704. forall: always,
  1705. toOptional: Optional.none
  1706. };
  1707. };
  1708. var fromOption = function(opt, err) {
  1709. return opt.fold(function() {
  1710. return error$1(err);
  1711. }, value$3);
  1712. };
  1713. var Result = {
  1714. value: value$3,
  1715. error: error$1,
  1716. fromOption
  1717. };
  1718. var SimpleResultType;
  1719. (function(SimpleResultType2) {
  1720. SimpleResultType2[SimpleResultType2["Error"] = 0] = "Error";
  1721. SimpleResultType2[SimpleResultType2["Value"] = 1] = "Value";
  1722. })(SimpleResultType || (SimpleResultType = {}));
  1723. var fold$1 = function(res, onError, onValue) {
  1724. return res.stype === SimpleResultType.Error ? onError(res.serror) : onValue(res.svalue);
  1725. };
  1726. var partition$2 = function(results) {
  1727. var values2 = [];
  1728. var errors = [];
  1729. each$1(results, function(obj) {
  1730. fold$1(obj, function(err) {
  1731. return errors.push(err);
  1732. }, function(val) {
  1733. return values2.push(val);
  1734. });
  1735. });
  1736. return {
  1737. values: values2,
  1738. errors
  1739. };
  1740. };
  1741. var mapError = function(res, f) {
  1742. if (res.stype === SimpleResultType.Error) {
  1743. return {
  1744. stype: SimpleResultType.Error,
  1745. serror: f(res.serror)
  1746. };
  1747. } else {
  1748. return res;
  1749. }
  1750. };
  1751. var map = function(res, f) {
  1752. if (res.stype === SimpleResultType.Value) {
  1753. return {
  1754. stype: SimpleResultType.Value,
  1755. svalue: f(res.svalue)
  1756. };
  1757. } else {
  1758. return res;
  1759. }
  1760. };
  1761. var bind$1 = function(res, f) {
  1762. if (res.stype === SimpleResultType.Value) {
  1763. return f(res.svalue);
  1764. } else {
  1765. return res;
  1766. }
  1767. };
  1768. var bindError = function(res, f) {
  1769. if (res.stype === SimpleResultType.Error) {
  1770. return f(res.serror);
  1771. } else {
  1772. return res;
  1773. }
  1774. };
  1775. var svalue = function(v) {
  1776. return {
  1777. stype: SimpleResultType.Value,
  1778. svalue: v
  1779. };
  1780. };
  1781. var serror = function(e) {
  1782. return {
  1783. stype: SimpleResultType.Error,
  1784. serror: e
  1785. };
  1786. };
  1787. var toResult$1 = function(res) {
  1788. return fold$1(res, Result.error, Result.value);
  1789. };
  1790. var fromResult$1 = function(res) {
  1791. return res.fold(serror, svalue);
  1792. };
  1793. var SimpleResult = {
  1794. fromResult: fromResult$1,
  1795. toResult: toResult$1,
  1796. svalue,
  1797. partition: partition$2,
  1798. serror,
  1799. bind: bind$1,
  1800. bindError,
  1801. map,
  1802. mapError,
  1803. fold: fold$1
  1804. };
  1805. var field$2 = function(key, newKey, presence, prop) {
  1806. return {
  1807. tag: "field",
  1808. key,
  1809. newKey,
  1810. presence,
  1811. prop
  1812. };
  1813. };
  1814. var customField$1 = function(newKey, instantiator) {
  1815. return {
  1816. tag: "custom",
  1817. newKey,
  1818. instantiator
  1819. };
  1820. };
  1821. var fold = function(value2, ifField, ifCustom) {
  1822. switch (value2.tag) {
  1823. case "field":
  1824. return ifField(value2.key, value2.newKey, value2.presence, value2.prop);
  1825. case "custom":
  1826. return ifCustom(value2.newKey, value2.instantiator);
  1827. }
  1828. };
  1829. var shallow$1 = function(old, nu2) {
  1830. return nu2;
  1831. };
  1832. var deep = function(old, nu2) {
  1833. var bothObjects = isObject(old) && isObject(nu2);
  1834. return bothObjects ? deepMerge(old, nu2) : nu2;
  1835. };
  1836. var baseMerge = function(merger) {
  1837. return function() {
  1838. var objects = [];
  1839. for (var _i = 0; _i < arguments.length; _i++) {
  1840. objects[_i] = arguments[_i];
  1841. }
  1842. if (objects.length === 0) {
  1843. throw new Error("Can't merge zero objects");
  1844. }
  1845. var ret = {};
  1846. for (var j = 0; j < objects.length; j++) {
  1847. var curObject = objects[j];
  1848. for (var key in curObject) {
  1849. if (has$2(curObject, key)) {
  1850. ret[key] = merger(ret[key], curObject[key]);
  1851. }
  1852. }
  1853. }
  1854. return ret;
  1855. };
  1856. };
  1857. var deepMerge = baseMerge(deep);
  1858. var merge$1 = baseMerge(shallow$1);
  1859. var required$2 = function() {
  1860. return {
  1861. tag: "required",
  1862. process: {}
  1863. };
  1864. };
  1865. var defaultedThunk = function(fallbackThunk) {
  1866. return {
  1867. tag: "defaultedThunk",
  1868. process: fallbackThunk
  1869. };
  1870. };
  1871. var defaulted$1 = function(fallback2) {
  1872. return defaultedThunk(constant$1(fallback2));
  1873. };
  1874. var asOption = function() {
  1875. return {
  1876. tag: "option",
  1877. process: {}
  1878. };
  1879. };
  1880. var mergeWithThunk = function(baseThunk) {
  1881. return {
  1882. tag: "mergeWithThunk",
  1883. process: baseThunk
  1884. };
  1885. };
  1886. var mergeWith = function(base2) {
  1887. return mergeWithThunk(constant$1(base2));
  1888. };
  1889. var mergeValues$1 = function(values2, base2) {
  1890. return values2.length > 0 ? SimpleResult.svalue(deepMerge(base2, merge$1.apply(void 0, values2))) : SimpleResult.svalue(base2);
  1891. };
  1892. var mergeErrors$1 = function(errors) {
  1893. return compose(SimpleResult.serror, flatten)(errors);
  1894. };
  1895. var consolidateObj = function(objects, base2) {
  1896. var partition2 = SimpleResult.partition(objects);
  1897. return partition2.errors.length > 0 ? mergeErrors$1(partition2.errors) : mergeValues$1(partition2.values, base2);
  1898. };
  1899. var consolidateArr = function(objects) {
  1900. var partitions = SimpleResult.partition(objects);
  1901. return partitions.errors.length > 0 ? mergeErrors$1(partitions.errors) : SimpleResult.svalue(partitions.values);
  1902. };
  1903. var ResultCombine = {
  1904. consolidateObj,
  1905. consolidateArr
  1906. };
  1907. var formatObj = function(input2) {
  1908. return isObject(input2) && keys(input2).length > 100 ? " removed due to size" : JSON.stringify(input2, null, 2);
  1909. };
  1910. var formatErrors = function(errors) {
  1911. var es = errors.length > 10 ? errors.slice(0, 10).concat([{
  1912. path: [],
  1913. getErrorInfo: constant$1("... (only showing first ten failures)")
  1914. }]) : errors;
  1915. return map$2(es, function(e) {
  1916. return "Failed path: (" + e.path.join(" > ") + ")\n" + e.getErrorInfo();
  1917. });
  1918. };
  1919. var nu$a = function(path2, getErrorInfo) {
  1920. return SimpleResult.serror([{
  1921. path: path2,
  1922. getErrorInfo
  1923. }]);
  1924. };
  1925. var missingRequired = function(path2, key, obj) {
  1926. return nu$a(path2, function() {
  1927. return 'Could not find valid *required* value for "' + key + '" in ' + formatObj(obj);
  1928. });
  1929. };
  1930. var missingKey = function(path2, key) {
  1931. return nu$a(path2, function() {
  1932. return 'Choice schema did not contain choice key: "' + key + '"';
  1933. });
  1934. };
  1935. var missingBranch = function(path2, branches, branch) {
  1936. return nu$a(path2, function() {
  1937. return 'The chosen schema: "' + branch + '" did not exist in branches: ' + formatObj(branches);
  1938. });
  1939. };
  1940. var unsupportedFields = function(path2, unsupported) {
  1941. return nu$a(path2, function() {
  1942. return "There are unsupported fields: [" + unsupported.join(", ") + "] specified";
  1943. });
  1944. };
  1945. var custom = function(path2, err) {
  1946. return nu$a(path2, constant$1(err));
  1947. };
  1948. var value$2 = function(validator) {
  1949. var extract2 = function(path2, val) {
  1950. return SimpleResult.bindError(validator(val), function(err) {
  1951. return custom(path2, err);
  1952. });
  1953. };
  1954. var toString2 = constant$1("val");
  1955. return {
  1956. extract: extract2,
  1957. toString: toString2
  1958. };
  1959. };
  1960. var anyValue$1 = value$2(SimpleResult.svalue);
  1961. var requiredAccess = function(path2, obj, key, bundle) {
  1962. return get$e(obj, key).fold(function() {
  1963. return missingRequired(path2, key, obj);
  1964. }, bundle);
  1965. };
  1966. var fallbackAccess = function(obj, key, fallback2, bundle) {
  1967. var v = get$e(obj, key).getOrThunk(function() {
  1968. return fallback2(obj);
  1969. });
  1970. return bundle(v);
  1971. };
  1972. var optionAccess = function(obj, key, bundle) {
  1973. return bundle(get$e(obj, key));
  1974. };
  1975. var optionDefaultedAccess = function(obj, key, fallback2, bundle) {
  1976. var opt = get$e(obj, key).map(function(val) {
  1977. return val === true ? fallback2(obj) : val;
  1978. });
  1979. return bundle(opt);
  1980. };
  1981. var extractField = function(field2, path2, obj, key, prop) {
  1982. var bundle = function(av) {
  1983. return prop.extract(path2.concat([key]), av);
  1984. };
  1985. var bundleAsOption = function(optValue) {
  1986. return optValue.fold(function() {
  1987. return SimpleResult.svalue(Optional.none());
  1988. }, function(ov) {
  1989. var result = prop.extract(path2.concat([key]), ov);
  1990. return SimpleResult.map(result, Optional.some);
  1991. });
  1992. };
  1993. switch (field2.tag) {
  1994. case "required":
  1995. return requiredAccess(path2, obj, key, bundle);
  1996. case "defaultedThunk":
  1997. return fallbackAccess(obj, key, field2.process, bundle);
  1998. case "option":
  1999. return optionAccess(obj, key, bundleAsOption);
  2000. case "defaultedOptionThunk":
  2001. return optionDefaultedAccess(obj, key, field2.process, bundleAsOption);
  2002. case "mergeWithThunk": {
  2003. return fallbackAccess(obj, key, constant$1({}), function(v) {
  2004. var result = deepMerge(field2.process(obj), v);
  2005. return bundle(result);
  2006. });
  2007. }
  2008. }
  2009. };
  2010. var extractFields = function(path2, obj, fields) {
  2011. var success = {};
  2012. var errors = [];
  2013. for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
  2014. var field2 = fields_1[_i];
  2015. fold(field2, function(key, newKey, presence, prop) {
  2016. var result = extractField(presence, path2, obj, key, prop);
  2017. SimpleResult.fold(result, function(err) {
  2018. errors.push.apply(errors, err);
  2019. }, function(res) {
  2020. success[newKey] = res;
  2021. });
  2022. }, function(newKey, instantiator) {
  2023. success[newKey] = instantiator(obj);
  2024. });
  2025. }
  2026. return errors.length > 0 ? SimpleResult.serror(errors) : SimpleResult.svalue(success);
  2027. };
  2028. var valueThunk = function(getDelegate) {
  2029. var extract2 = function(path2, val) {
  2030. return getDelegate().extract(path2, val);
  2031. };
  2032. var toString2 = function() {
  2033. return getDelegate().toString();
  2034. };
  2035. return {
  2036. extract: extract2,
  2037. toString: toString2
  2038. };
  2039. };
  2040. var getSetKeys = function(obj) {
  2041. return keys(filter$1(obj, isNonNullable));
  2042. };
  2043. var objOfOnly = function(fields) {
  2044. var delegate = objOf(fields);
  2045. var fieldNames = foldr(fields, function(acc, value2) {
  2046. return fold(value2, function(key) {
  2047. var _a2;
  2048. return deepMerge(acc, (_a2 = {}, _a2[key] = true, _a2));
  2049. }, constant$1(acc));
  2050. }, {});
  2051. var extract2 = function(path2, o) {
  2052. var keys2 = isBoolean(o) ? [] : getSetKeys(o);
  2053. var extra = filter$2(keys2, function(k) {
  2054. return !hasNonNullableKey(fieldNames, k);
  2055. });
  2056. return extra.length === 0 ? delegate.extract(path2, o) : unsupportedFields(path2, extra);
  2057. };
  2058. return {
  2059. extract: extract2,
  2060. toString: delegate.toString
  2061. };
  2062. };
  2063. var objOf = function(values2) {
  2064. var extract2 = function(path2, o) {
  2065. return extractFields(path2, o, values2);
  2066. };
  2067. var toString2 = function() {
  2068. var fieldStrings = map$2(values2, function(value2) {
  2069. return fold(value2, function(key, _okey, _presence, prop) {
  2070. return key + " -> " + prop.toString();
  2071. }, function(newKey, _instantiator) {
  2072. return "state(" + newKey + ")";
  2073. });
  2074. });
  2075. return "obj{\n" + fieldStrings.join("\n") + "}";
  2076. };
  2077. return {
  2078. extract: extract2,
  2079. toString: toString2
  2080. };
  2081. };
  2082. var arrOf = function(prop) {
  2083. var extract2 = function(path2, array) {
  2084. var results = map$2(array, function(a, i) {
  2085. return prop.extract(path2.concat(["[" + i + "]"]), a);
  2086. });
  2087. return ResultCombine.consolidateArr(results);
  2088. };
  2089. var toString2 = function() {
  2090. return "array(" + prop.toString() + ")";
  2091. };
  2092. return {
  2093. extract: extract2,
  2094. toString: toString2
  2095. };
  2096. };
  2097. var oneOf = function(props) {
  2098. var extract2 = function(path2, val) {
  2099. var errors = [];
  2100. for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
  2101. var prop = props_1[_i];
  2102. var res = prop.extract(path2, val);
  2103. if (res.stype === SimpleResultType.Value) {
  2104. return res;
  2105. }
  2106. errors.push(res);
  2107. }
  2108. return ResultCombine.consolidateArr(errors);
  2109. };
  2110. var toString2 = function() {
  2111. return "oneOf(" + map$2(props, function(prop) {
  2112. return prop.toString();
  2113. }).join(", ") + ")";
  2114. };
  2115. return {
  2116. extract: extract2,
  2117. toString: toString2
  2118. };
  2119. };
  2120. var setOf$1 = function(validator, prop) {
  2121. var validateKeys = function(path2, keys2) {
  2122. return arrOf(value$2(validator)).extract(path2, keys2);
  2123. };
  2124. var extract2 = function(path2, o) {
  2125. var keys$1 = keys(o);
  2126. var validatedKeys = validateKeys(path2, keys$1);
  2127. return SimpleResult.bind(validatedKeys, function(validKeys) {
  2128. var schema2 = map$2(validKeys, function(vk) {
  2129. return field$2(vk, vk, required$2(), prop);
  2130. });
  2131. return objOf(schema2).extract(path2, o);
  2132. });
  2133. };
  2134. var toString2 = function() {
  2135. return "setOf(" + prop.toString() + ")";
  2136. };
  2137. return {
  2138. extract: extract2,
  2139. toString: toString2
  2140. };
  2141. };
  2142. var thunk = function(_desc, processor) {
  2143. var getP = cached(processor);
  2144. var extract2 = function(path2, val) {
  2145. return getP().extract(path2, val);
  2146. };
  2147. var toString2 = function() {
  2148. return getP().toString();
  2149. };
  2150. return {
  2151. extract: extract2,
  2152. toString: toString2
  2153. };
  2154. };
  2155. var arrOfObj = compose(arrOf, objOf);
  2156. var anyValue = constant$1(anyValue$1);
  2157. var typedValue = function(validator, expectedType) {
  2158. return value$2(function(a) {
  2159. var actualType = typeof a;
  2160. return validator(a) ? SimpleResult.svalue(a) : SimpleResult.serror("Expected type: " + expectedType + " but got: " + actualType);
  2161. });
  2162. };
  2163. var number = typedValue(isNumber, "number");
  2164. var string = typedValue(isString, "string");
  2165. var boolean = typedValue(isBoolean, "boolean");
  2166. var functionProcessor = typedValue(isFunction, "function");
  2167. var isPostMessageable = function(val) {
  2168. if (Object(val) !== val) {
  2169. return true;
  2170. }
  2171. switch ({}.toString.call(val).slice(8, -1)) {
  2172. case "Boolean":
  2173. case "Number":
  2174. case "String":
  2175. case "Date":
  2176. case "RegExp":
  2177. case "Blob":
  2178. case "FileList":
  2179. case "ImageData":
  2180. case "ImageBitmap":
  2181. case "ArrayBuffer":
  2182. return true;
  2183. case "Array":
  2184. case "Object":
  2185. return Object.keys(val).every(function(prop) {
  2186. return isPostMessageable(val[prop]);
  2187. });
  2188. default:
  2189. return false;
  2190. }
  2191. };
  2192. var postMessageable = value$2(function(a) {
  2193. if (isPostMessageable(a)) {
  2194. return SimpleResult.svalue(a);
  2195. } else {
  2196. return SimpleResult.serror("Expected value to be acceptable for sending via postMessage");
  2197. }
  2198. });
  2199. var chooseFrom = function(path2, input2, branches, ch) {
  2200. var fields = get$e(branches, ch);
  2201. return fields.fold(function() {
  2202. return missingBranch(path2, branches, ch);
  2203. }, function(vp) {
  2204. return vp.extract(path2.concat(["branch: " + ch]), input2);
  2205. });
  2206. };
  2207. var choose$2 = function(key, branches) {
  2208. var extract2 = function(path2, input2) {
  2209. var choice = get$e(input2, key);
  2210. return choice.fold(function() {
  2211. return missingKey(path2, key);
  2212. }, function(chosen) {
  2213. return chooseFrom(path2, input2, branches, chosen);
  2214. });
  2215. };
  2216. var toString2 = function() {
  2217. return "chooseOn(" + key + "). Possible values: " + keys(branches);
  2218. };
  2219. return {
  2220. extract: extract2,
  2221. toString: toString2
  2222. };
  2223. };
  2224. var arrOfVal = function() {
  2225. return arrOf(anyValue$1);
  2226. };
  2227. var valueOf = function(validator) {
  2228. return value$2(function(v) {
  2229. return validator(v).fold(SimpleResult.serror, SimpleResult.svalue);
  2230. });
  2231. };
  2232. var setOf = function(validator, prop) {
  2233. return setOf$1(function(v) {
  2234. return SimpleResult.fromResult(validator(v));
  2235. }, prop);
  2236. };
  2237. var extractValue = function(label, prop, obj) {
  2238. var res = prop.extract([label], obj);
  2239. return SimpleResult.mapError(res, function(errs) {
  2240. return {
  2241. input: obj,
  2242. errors: errs
  2243. };
  2244. });
  2245. };
  2246. var asRaw = function(label, prop, obj) {
  2247. return SimpleResult.toResult(extractValue(label, prop, obj));
  2248. };
  2249. var getOrDie = function(extraction) {
  2250. return extraction.fold(function(errInfo) {
  2251. throw new Error(formatError(errInfo));
  2252. }, identity$1);
  2253. };
  2254. var asRawOrDie$1 = function(label, prop, obj) {
  2255. return getOrDie(asRaw(label, prop, obj));
  2256. };
  2257. var formatError = function(errInfo) {
  2258. return "Errors: \n" + formatErrors(errInfo.errors).join("\n") + "\n\nInput object: " + formatObj(errInfo.input);
  2259. };
  2260. var choose$1 = function(key, branches) {
  2261. return choose$2(key, map$1(branches, objOf));
  2262. };
  2263. var thunkOf = function(desc, schema2) {
  2264. return thunk(desc, schema2);
  2265. };
  2266. var field$1 = field$2;
  2267. var customField = customField$1;
  2268. var validateEnum = function(values2) {
  2269. return valueOf(function(value2) {
  2270. return contains$2(values2, value2) ? Result.value(value2) : Result.error('Unsupported value: "' + value2 + '", choose one of "' + values2.join(", ") + '".');
  2271. });
  2272. };
  2273. var required$1 = function(key) {
  2274. return field$1(key, key, required$2(), anyValue());
  2275. };
  2276. var requiredOf = function(key, schema2) {
  2277. return field$1(key, key, required$2(), schema2);
  2278. };
  2279. var requiredNumber = function(key) {
  2280. return requiredOf(key, number);
  2281. };
  2282. var requiredString = function(key) {
  2283. return requiredOf(key, string);
  2284. };
  2285. var requiredStringEnum = function(key, values2) {
  2286. return field$1(key, key, required$2(), validateEnum(values2));
  2287. };
  2288. var requiredBoolean = function(key) {
  2289. return requiredOf(key, boolean);
  2290. };
  2291. var requiredFunction = function(key) {
  2292. return requiredOf(key, functionProcessor);
  2293. };
  2294. var forbid = function(key, message) {
  2295. return field$1(key, key, asOption(), value$2(function(_v) {
  2296. return SimpleResult.serror("The field: " + key + " is forbidden. " + message);
  2297. }));
  2298. };
  2299. var requiredObjOf = function(key, objSchema) {
  2300. return field$1(key, key, required$2(), objOf(objSchema));
  2301. };
  2302. var requiredArrayOfObj = function(key, objFields) {
  2303. return field$1(key, key, required$2(), arrOfObj(objFields));
  2304. };
  2305. var requiredArrayOf = function(key, schema2) {
  2306. return field$1(key, key, required$2(), arrOf(schema2));
  2307. };
  2308. var option = function(key) {
  2309. return field$1(key, key, asOption(), anyValue());
  2310. };
  2311. var optionOf = function(key, schema2) {
  2312. return field$1(key, key, asOption(), schema2);
  2313. };
  2314. var optionNumber = function(key) {
  2315. return optionOf(key, number);
  2316. };
  2317. var optionString = function(key) {
  2318. return optionOf(key, string);
  2319. };
  2320. var optionFunction = function(key) {
  2321. return optionOf(key, functionProcessor);
  2322. };
  2323. var optionArrayOf = function(key, schema2) {
  2324. return optionOf(key, arrOf(schema2));
  2325. };
  2326. var optionObjOf = function(key, objSchema) {
  2327. return optionOf(key, objOf(objSchema));
  2328. };
  2329. var optionObjOfOnly = function(key, objSchema) {
  2330. return optionOf(key, objOfOnly(objSchema));
  2331. };
  2332. var defaulted = function(key, fallback2) {
  2333. return field$1(key, key, defaulted$1(fallback2), anyValue());
  2334. };
  2335. var defaultedOf = function(key, fallback2, schema2) {
  2336. return field$1(key, key, defaulted$1(fallback2), schema2);
  2337. };
  2338. var defaultedNumber = function(key, fallback2) {
  2339. return defaultedOf(key, fallback2, number);
  2340. };
  2341. var defaultedString = function(key, fallback2) {
  2342. return defaultedOf(key, fallback2, string);
  2343. };
  2344. var defaultedStringEnum = function(key, fallback2, values2) {
  2345. return defaultedOf(key, fallback2, validateEnum(values2));
  2346. };
  2347. var defaultedBoolean = function(key, fallback2) {
  2348. return defaultedOf(key, fallback2, boolean);
  2349. };
  2350. var defaultedFunction = function(key, fallback2) {
  2351. return defaultedOf(key, fallback2, functionProcessor);
  2352. };
  2353. var defaultedPostMsg = function(key, fallback2) {
  2354. return defaultedOf(key, fallback2, postMessageable);
  2355. };
  2356. var defaultedArrayOf = function(key, fallback2, schema2) {
  2357. return defaultedOf(key, fallback2, arrOf(schema2));
  2358. };
  2359. var defaultedObjOf = function(key, fallback2, objSchema) {
  2360. return defaultedOf(key, fallback2, objOf(objSchema));
  2361. };
  2362. var Cell = function(initial) {
  2363. var value2 = initial;
  2364. var get2 = function() {
  2365. return value2;
  2366. };
  2367. var set2 = function(v) {
  2368. value2 = v;
  2369. };
  2370. return {
  2371. get: get2,
  2372. set: set2
  2373. };
  2374. };
  2375. var generate$7 = function(cases) {
  2376. if (!isArray(cases)) {
  2377. throw new Error("cases must be an array");
  2378. }
  2379. if (cases.length === 0) {
  2380. throw new Error("there must be at least one case");
  2381. }
  2382. var constructors = [];
  2383. var adt2 = {};
  2384. each$1(cases, function(acase, count2) {
  2385. var keys$1 = keys(acase);
  2386. if (keys$1.length !== 1) {
  2387. throw new Error("one and only one name per case");
  2388. }
  2389. var key = keys$1[0];
  2390. var value2 = acase[key];
  2391. if (adt2[key] !== void 0) {
  2392. throw new Error("duplicate key detected:" + key);
  2393. } else if (key === "cata") {
  2394. throw new Error("cannot have a case named cata (sorry)");
  2395. } else if (!isArray(value2)) {
  2396. throw new Error("case arguments must be an array");
  2397. }
  2398. constructors.push(key);
  2399. adt2[key] = function() {
  2400. var args = [];
  2401. for (var _i = 0; _i < arguments.length; _i++) {
  2402. args[_i] = arguments[_i];
  2403. }
  2404. var argLength = args.length;
  2405. if (argLength !== value2.length) {
  2406. throw new Error("Wrong number of arguments to case " + key + ". Expected " + value2.length + " (" + value2 + "), got " + argLength);
  2407. }
  2408. var match = function(branches) {
  2409. var branchKeys = keys(branches);
  2410. if (constructors.length !== branchKeys.length) {
  2411. throw new Error("Wrong number of arguments to match. Expected: " + constructors.join(",") + "\nActual: " + branchKeys.join(","));
  2412. }
  2413. var allReqd = forall(constructors, function(reqKey) {
  2414. return contains$2(branchKeys, reqKey);
  2415. });
  2416. if (!allReqd) {
  2417. throw new Error("Not all branches were specified when using match. Specified: " + branchKeys.join(", ") + "\nRequired: " + constructors.join(", "));
  2418. }
  2419. return branches[key].apply(null, args);
  2420. };
  2421. return {
  2422. fold: function() {
  2423. var foldArgs = [];
  2424. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  2425. foldArgs[_i2] = arguments[_i2];
  2426. }
  2427. if (foldArgs.length !== cases.length) {
  2428. throw new Error("Wrong number of arguments to fold. Expected " + cases.length + ", got " + foldArgs.length);
  2429. }
  2430. var target = foldArgs[count2];
  2431. return target.apply(null, args);
  2432. },
  2433. match,
  2434. log: function(label) {
  2435. console.log(label, {
  2436. constructors,
  2437. constructor: key,
  2438. params: args
  2439. });
  2440. }
  2441. };
  2442. };
  2443. });
  2444. return adt2;
  2445. };
  2446. var Adt = { generate: generate$7 };
  2447. Adt.generate([
  2448. {
  2449. bothErrors: [
  2450. "error1",
  2451. "error2"
  2452. ]
  2453. },
  2454. {
  2455. firstError: [
  2456. "error1",
  2457. "value2"
  2458. ]
  2459. },
  2460. {
  2461. secondError: [
  2462. "value1",
  2463. "error2"
  2464. ]
  2465. },
  2466. {
  2467. bothValues: [
  2468. "value1",
  2469. "value2"
  2470. ]
  2471. }
  2472. ]);
  2473. var partition$1 = function(results) {
  2474. var errors = [];
  2475. var values2 = [];
  2476. each$1(results, function(result) {
  2477. result.fold(function(err) {
  2478. errors.push(err);
  2479. }, function(value2) {
  2480. values2.push(value2);
  2481. });
  2482. });
  2483. return {
  2484. errors,
  2485. values: values2
  2486. };
  2487. };
  2488. var exclude$1 = function(obj, fields) {
  2489. var r2 = {};
  2490. each(obj, function(v, k) {
  2491. if (!contains$2(fields, k)) {
  2492. r2[k] = v;
  2493. }
  2494. });
  2495. return r2;
  2496. };
  2497. var wrap$2 = function(key, value2) {
  2498. var _a2;
  2499. return _a2 = {}, _a2[key] = value2, _a2;
  2500. };
  2501. var wrapAll$1 = function(keyvalues) {
  2502. var r2 = {};
  2503. each$1(keyvalues, function(kv) {
  2504. r2[kv.key] = kv.value;
  2505. });
  2506. return r2;
  2507. };
  2508. var exclude = function(obj, fields) {
  2509. return exclude$1(obj, fields);
  2510. };
  2511. var wrap$1 = function(key, value2) {
  2512. return wrap$2(key, value2);
  2513. };
  2514. var wrapAll = function(keyvalues) {
  2515. return wrapAll$1(keyvalues);
  2516. };
  2517. var mergeValues = function(values2, base2) {
  2518. return values2.length === 0 ? Result.value(base2) : Result.value(deepMerge(base2, merge$1.apply(void 0, values2)));
  2519. };
  2520. var mergeErrors = function(errors) {
  2521. return Result.error(flatten(errors));
  2522. };
  2523. var consolidate = function(objs, base2) {
  2524. var partitions = partition$1(objs);
  2525. return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : mergeValues(partitions.values, base2);
  2526. };
  2527. var ensureIsRoot = function(isRoot) {
  2528. return isFunction(isRoot) ? isRoot : never;
  2529. };
  2530. var ancestor$2 = function(scope, transform2, isRoot) {
  2531. var element2 = scope.dom;
  2532. var stop2 = ensureIsRoot(isRoot);
  2533. while (element2.parentNode) {
  2534. element2 = element2.parentNode;
  2535. var el = SugarElement.fromDom(element2);
  2536. var transformed = transform2(el);
  2537. if (transformed.isSome()) {
  2538. return transformed;
  2539. } else if (stop2(el)) {
  2540. break;
  2541. }
  2542. }
  2543. return Optional.none();
  2544. };
  2545. var closest$4 = function(scope, transform2, isRoot) {
  2546. var current = transform2(scope);
  2547. var stop2 = ensureIsRoot(isRoot);
  2548. return current.orThunk(function() {
  2549. return stop2(scope) ? Optional.none() : ancestor$2(scope, transform2, stop2);
  2550. });
  2551. };
  2552. var isSource = function(component, simulatedEvent) {
  2553. return eq(component.element, simulatedEvent.event.target);
  2554. };
  2555. var defaultEventHandler = {
  2556. can: always,
  2557. abort: never,
  2558. run: noop
  2559. };
  2560. var nu$9 = function(parts2) {
  2561. if (!hasNonNullableKey(parts2, "can") && !hasNonNullableKey(parts2, "abort") && !hasNonNullableKey(parts2, "run")) {
  2562. throw new Error("EventHandler defined by: " + JSON.stringify(parts2, null, 2) + " does not have can, abort, or run!");
  2563. }
  2564. return __assign(__assign({}, defaultEventHandler), parts2);
  2565. };
  2566. var all$2 = function(handlers2, f) {
  2567. return function() {
  2568. var args = [];
  2569. for (var _i = 0; _i < arguments.length; _i++) {
  2570. args[_i] = arguments[_i];
  2571. }
  2572. return foldl(handlers2, function(acc, handler) {
  2573. return acc && f(handler).apply(void 0, args);
  2574. }, true);
  2575. };
  2576. };
  2577. var any = function(handlers2, f) {
  2578. return function() {
  2579. var args = [];
  2580. for (var _i = 0; _i < arguments.length; _i++) {
  2581. args[_i] = arguments[_i];
  2582. }
  2583. return foldl(handlers2, function(acc, handler) {
  2584. return acc || f(handler).apply(void 0, args);
  2585. }, false);
  2586. };
  2587. };
  2588. var read$2 = function(handler) {
  2589. return isFunction(handler) ? {
  2590. can: always,
  2591. abort: never,
  2592. run: handler
  2593. } : handler;
  2594. };
  2595. var fuse$1 = function(handlers2) {
  2596. var can2 = all$2(handlers2, function(handler) {
  2597. return handler.can;
  2598. });
  2599. var abort2 = any(handlers2, function(handler) {
  2600. return handler.abort;
  2601. });
  2602. var run2 = function() {
  2603. var args = [];
  2604. for (var _i = 0; _i < arguments.length; _i++) {
  2605. args[_i] = arguments[_i];
  2606. }
  2607. each$1(handlers2, function(handler) {
  2608. handler.run.apply(void 0, args);
  2609. });
  2610. };
  2611. return {
  2612. can: can2,
  2613. abort: abort2,
  2614. run: run2
  2615. };
  2616. };
  2617. var constant = constant$1;
  2618. var touchstart = constant("touchstart");
  2619. var touchmove = constant("touchmove");
  2620. var touchend = constant("touchend");
  2621. var touchcancel = constant("touchcancel");
  2622. var mousedown = constant("mousedown");
  2623. var mousemove = constant("mousemove");
  2624. var mouseout = constant("mouseout");
  2625. var mouseup = constant("mouseup");
  2626. var mouseover = constant("mouseover");
  2627. var focusin = constant("focusin");
  2628. var focusout = constant("focusout");
  2629. var keydown = constant("keydown");
  2630. var keyup = constant("keyup");
  2631. var input = constant("input");
  2632. var change = constant("change");
  2633. var click = constant("click");
  2634. var transitioncancel = constant("transitioncancel");
  2635. var transitionend = constant("transitionend");
  2636. var transitionstart = constant("transitionstart");
  2637. var selectstart = constant("selectstart");
  2638. var prefixName = function(name2) {
  2639. return constant$1("alloy." + name2);
  2640. };
  2641. var alloy = { tap: prefixName("tap") };
  2642. var focus$4 = prefixName("focus");
  2643. var postBlur = prefixName("blur.post");
  2644. var postPaste = prefixName("paste.post");
  2645. var receive = prefixName("receive");
  2646. var execute$5 = prefixName("execute");
  2647. var focusItem = prefixName("focus.item");
  2648. var tap = alloy.tap;
  2649. var longpress = prefixName("longpress");
  2650. var sandboxClose = prefixName("sandbox.close");
  2651. var typeaheadCancel = prefixName("typeahead.cancel");
  2652. var systemInit = prefixName("system.init");
  2653. var documentTouchmove = prefixName("system.touchmove");
  2654. var documentTouchend = prefixName("system.touchend");
  2655. var windowScroll = prefixName("system.scroll");
  2656. var windowResize = prefixName("system.resize");
  2657. var attachedToDom = prefixName("system.attached");
  2658. var detachedFromDom = prefixName("system.detached");
  2659. var dismissRequested = prefixName("system.dismissRequested");
  2660. var repositionRequested = prefixName("system.repositionRequested");
  2661. var focusShifted = prefixName("focusmanager.shifted");
  2662. var slotVisibility = prefixName("slotcontainer.visibility");
  2663. var changeTab = prefixName("change.tab");
  2664. var dismissTab = prefixName("dismiss.tab");
  2665. var highlight$1 = prefixName("highlight");
  2666. var dehighlight$1 = prefixName("dehighlight");
  2667. var emit = function(component, event) {
  2668. dispatchWith(component, component.element, event, {});
  2669. };
  2670. var emitWith = function(component, event, properties2) {
  2671. dispatchWith(component, component.element, event, properties2);
  2672. };
  2673. var emitExecute = function(component) {
  2674. emit(component, execute$5());
  2675. };
  2676. var dispatch = function(component, target, event) {
  2677. dispatchWith(component, target, event, {});
  2678. };
  2679. var dispatchWith = function(component, target, event, properties2) {
  2680. var data = __assign({ target }, properties2);
  2681. component.getSystem().triggerEvent(event, target, data);
  2682. };
  2683. var dispatchEvent = function(component, target, event, simulatedEvent) {
  2684. component.getSystem().triggerEvent(event, target, simulatedEvent.event);
  2685. };
  2686. var derive$2 = function(configs) {
  2687. return wrapAll(configs);
  2688. };
  2689. var abort = function(name2, predicate) {
  2690. return {
  2691. key: name2,
  2692. value: nu$9({ abort: predicate })
  2693. };
  2694. };
  2695. var can = function(name2, predicate) {
  2696. return {
  2697. key: name2,
  2698. value: nu$9({ can: predicate })
  2699. };
  2700. };
  2701. var preventDefault = function(name2) {
  2702. return {
  2703. key: name2,
  2704. value: nu$9({
  2705. run: function(component, simulatedEvent) {
  2706. simulatedEvent.event.prevent();
  2707. }
  2708. })
  2709. };
  2710. };
  2711. var run$1 = function(name2, handler) {
  2712. return {
  2713. key: name2,
  2714. value: nu$9({ run: handler })
  2715. };
  2716. };
  2717. var runActionExtra = function(name2, action, extra) {
  2718. return {
  2719. key: name2,
  2720. value: nu$9({
  2721. run: function(component, simulatedEvent) {
  2722. action.apply(void 0, [
  2723. component,
  2724. simulatedEvent
  2725. ].concat(extra));
  2726. }
  2727. })
  2728. };
  2729. };
  2730. var runOnName = function(name2) {
  2731. return function(handler) {
  2732. return run$1(name2, handler);
  2733. };
  2734. };
  2735. var runOnSourceName = function(name2) {
  2736. return function(handler) {
  2737. return {
  2738. key: name2,
  2739. value: nu$9({
  2740. run: function(component, simulatedEvent) {
  2741. if (isSource(component, simulatedEvent)) {
  2742. handler(component, simulatedEvent);
  2743. }
  2744. }
  2745. })
  2746. };
  2747. };
  2748. };
  2749. var redirectToUid = function(name2, uid) {
  2750. return run$1(name2, function(component, simulatedEvent) {
  2751. component.getSystem().getByUid(uid).each(function(redirectee) {
  2752. dispatchEvent(redirectee, redirectee.element, name2, simulatedEvent);
  2753. });
  2754. });
  2755. };
  2756. var redirectToPart = function(name2, detail, partName) {
  2757. var uid = detail.partUids[partName];
  2758. return redirectToUid(name2, uid);
  2759. };
  2760. var runWithTarget = function(name2, f) {
  2761. return run$1(name2, function(component, simulatedEvent) {
  2762. var ev = simulatedEvent.event;
  2763. var target = component.getSystem().getByDom(ev.target).getOrThunk(function() {
  2764. var closest2 = closest$4(ev.target, function(el) {
  2765. return component.getSystem().getByDom(el).toOptional();
  2766. }, never);
  2767. return closest2.getOr(component);
  2768. });
  2769. f(component, target, simulatedEvent);
  2770. });
  2771. };
  2772. var cutter = function(name2) {
  2773. return run$1(name2, function(component, simulatedEvent) {
  2774. simulatedEvent.cut();
  2775. });
  2776. };
  2777. var stopper = function(name2) {
  2778. return run$1(name2, function(component, simulatedEvent) {
  2779. simulatedEvent.stop();
  2780. });
  2781. };
  2782. var runOnSource = function(name2, f) {
  2783. return runOnSourceName(name2)(f);
  2784. };
  2785. var runOnAttached = runOnSourceName(attachedToDom());
  2786. var runOnDetached = runOnSourceName(detachedFromDom());
  2787. var runOnInit = runOnSourceName(systemInit());
  2788. var runOnExecute$1 = runOnName(execute$5());
  2789. var fromHtml$1 = function(html, scope) {
  2790. var doc = scope || document;
  2791. var div = doc.createElement("div");
  2792. div.innerHTML = html;
  2793. return children(SugarElement.fromDom(div));
  2794. };
  2795. var get$7 = function(element2) {
  2796. return element2.dom.innerHTML;
  2797. };
  2798. var set$5 = function(element2, content) {
  2799. var owner2 = owner$4(element2);
  2800. var docDom = owner2.dom;
  2801. var fragment = SugarElement.fromDom(docDom.createDocumentFragment());
  2802. var contentElements = fromHtml$1(content, docDom);
  2803. append$1(fragment, contentElements);
  2804. empty(element2);
  2805. append$2(element2, fragment);
  2806. };
  2807. var getOuter = function(element2) {
  2808. var container = SugarElement.fromTag("div");
  2809. var clone2 = SugarElement.fromDom(element2.dom.cloneNode(true));
  2810. append$2(container, clone2);
  2811. return get$7(container);
  2812. };
  2813. var clone$1 = function(original2, isDeep) {
  2814. return SugarElement.fromDom(original2.dom.cloneNode(isDeep));
  2815. };
  2816. var shallow = function(original2) {
  2817. return clone$1(original2, false);
  2818. };
  2819. var getHtml = function(element2) {
  2820. if (isShadowRoot(element2)) {
  2821. return "#shadow-root";
  2822. } else {
  2823. var clone2 = shallow(element2);
  2824. return getOuter(clone2);
  2825. }
  2826. };
  2827. var element = function(elem) {
  2828. return getHtml(elem);
  2829. };
  2830. var isRecursive = function(component, originator, target) {
  2831. return eq(originator, component.element) && !eq(originator, target);
  2832. };
  2833. var events$i = derive$2([can(focus$4(), function(component, simulatedEvent) {
  2834. var event = simulatedEvent.event;
  2835. var originator = event.originator;
  2836. var target = event.target;
  2837. if (isRecursive(component, originator, target)) {
  2838. console.warn(focus$4() + " did not get interpreted by the desired target. \nOriginator: " + element(originator) + "\nTarget: " + element(target) + "\nCheck the " + focus$4() + " event handlers");
  2839. return false;
  2840. } else {
  2841. return true;
  2842. }
  2843. })]);
  2844. var DefaultEvents = Object.freeze({
  2845. __proto__: null,
  2846. events: events$i
  2847. });
  2848. var unique = 0;
  2849. var generate$6 = function(prefix2) {
  2850. var date = new Date();
  2851. var time = date.getTime();
  2852. var random = Math.floor(Math.random() * 1e9);
  2853. unique++;
  2854. return prefix2 + "_" + random + unique + String(time);
  2855. };
  2856. var prefix$1 = constant$1("alloy-id-");
  2857. var idAttr$1 = constant$1("data-alloy-id");
  2858. var prefix = prefix$1();
  2859. var idAttr = idAttr$1();
  2860. var write = function(label, elem) {
  2861. var id = generate$6(prefix + label);
  2862. writeOnly(elem, id);
  2863. return id;
  2864. };
  2865. var writeOnly = function(elem, uid) {
  2866. Object.defineProperty(elem.dom, idAttr, {
  2867. value: uid,
  2868. writable: true
  2869. });
  2870. };
  2871. var read$1 = function(elem) {
  2872. var id = isElement$2(elem) ? elem.dom[idAttr] : null;
  2873. return Optional.from(id);
  2874. };
  2875. var generate$5 = function(prefix2) {
  2876. return generate$6(prefix2);
  2877. };
  2878. var make$8 = identity$1;
  2879. var NoContextApi = function(getComp) {
  2880. var getMessage = function(event) {
  2881. return "The component must be in a context to execute: " + event + (getComp ? "\n" + element(getComp().element) + " is not in context." : "");
  2882. };
  2883. var fail = function(event) {
  2884. return function() {
  2885. throw new Error(getMessage(event));
  2886. };
  2887. };
  2888. var warn = function(event) {
  2889. return function() {
  2890. console.warn(getMessage(event));
  2891. };
  2892. };
  2893. return {
  2894. debugInfo: constant$1("fake"),
  2895. triggerEvent: warn("triggerEvent"),
  2896. triggerFocus: warn("triggerFocus"),
  2897. triggerEscape: warn("triggerEscape"),
  2898. broadcast: warn("broadcast"),
  2899. broadcastOn: warn("broadcastOn"),
  2900. broadcastEvent: warn("broadcastEvent"),
  2901. build: fail("build"),
  2902. addToWorld: fail("addToWorld"),
  2903. removeFromWorld: fail("removeFromWorld"),
  2904. addToGui: fail("addToGui"),
  2905. removeFromGui: fail("removeFromGui"),
  2906. getByUid: fail("getByUid"),
  2907. getByDom: fail("getByDom"),
  2908. isConnected: never
  2909. };
  2910. };
  2911. var singleton$1 = NoContextApi();
  2912. var markAsBehaviourApi = function(f, apiName, apiFunction) {
  2913. var delegate = apiFunction.toString();
  2914. var endIndex = delegate.indexOf(")") + 1;
  2915. var openBracketIndex = delegate.indexOf("(");
  2916. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2917. f.toFunctionAnnotation = function() {
  2918. return {
  2919. name: apiName,
  2920. parameters: cleanParameters(parameters.slice(0, 1).concat(parameters.slice(3)))
  2921. };
  2922. };
  2923. return f;
  2924. };
  2925. var cleanParameters = function(parameters) {
  2926. return map$2(parameters, function(p) {
  2927. return endsWith(p, "/*") ? p.substring(0, p.length - "/*".length) : p;
  2928. });
  2929. };
  2930. var markAsExtraApi = function(f, extraName) {
  2931. var delegate = f.toString();
  2932. var endIndex = delegate.indexOf(")") + 1;
  2933. var openBracketIndex = delegate.indexOf("(");
  2934. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2935. f.toFunctionAnnotation = function() {
  2936. return {
  2937. name: extraName,
  2938. parameters: cleanParameters(parameters)
  2939. };
  2940. };
  2941. return f;
  2942. };
  2943. var markAsSketchApi = function(f, apiFunction) {
  2944. var delegate = apiFunction.toString();
  2945. var endIndex = delegate.indexOf(")") + 1;
  2946. var openBracketIndex = delegate.indexOf("(");
  2947. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2948. f.toFunctionAnnotation = function() {
  2949. return {
  2950. name: "OVERRIDE",
  2951. parameters: cleanParameters(parameters.slice(1))
  2952. };
  2953. };
  2954. return f;
  2955. };
  2956. var premadeTag = generate$6("alloy-premade");
  2957. var premade$1 = function(comp) {
  2958. return wrap$1(premadeTag, comp);
  2959. };
  2960. var getPremade = function(spec) {
  2961. return get$e(spec, premadeTag);
  2962. };
  2963. var makeApi = function(f) {
  2964. return markAsSketchApi(function(component) {
  2965. var rest = [];
  2966. for (var _i = 1; _i < arguments.length; _i++) {
  2967. rest[_i - 1] = arguments[_i];
  2968. }
  2969. return f.apply(void 0, __spreadArray([
  2970. component.getApis(),
  2971. component
  2972. ], rest, false));
  2973. }, f);
  2974. };
  2975. var NoState = {
  2976. init: function() {
  2977. return nu$8({ readState: constant$1("No State required") });
  2978. }
  2979. };
  2980. var nu$8 = function(spec) {
  2981. return spec;
  2982. };
  2983. var generateFrom$1 = function(spec, all2) {
  2984. var schema2 = map$2(all2, function(a) {
  2985. return optionObjOf(a.name(), [
  2986. required$1("config"),
  2987. defaulted("state", NoState)
  2988. ]);
  2989. });
  2990. var validated = asRaw("component.behaviours", objOf(schema2), spec.behaviours).fold(function(errInfo) {
  2991. throw new Error(formatError(errInfo) + "\nComplete spec:\n" + JSON.stringify(spec, null, 2));
  2992. }, identity$1);
  2993. return {
  2994. list: all2,
  2995. data: map$1(validated, function(optBlobThunk) {
  2996. var output2 = optBlobThunk.map(function(blob) {
  2997. return {
  2998. config: blob.config,
  2999. state: blob.state.init(blob.config)
  3000. };
  3001. });
  3002. return constant$1(output2);
  3003. })
  3004. };
  3005. };
  3006. var getBehaviours$3 = function(bData) {
  3007. return bData.list;
  3008. };
  3009. var getData$2 = function(bData) {
  3010. return bData.data;
  3011. };
  3012. var byInnerKey = function(data, tuple) {
  3013. var r2 = {};
  3014. each(data, function(detail, key) {
  3015. each(detail, function(value2, indexKey) {
  3016. var chain = get$e(r2, indexKey).getOr([]);
  3017. r2[indexKey] = chain.concat([tuple(key, value2)]);
  3018. });
  3019. });
  3020. return r2;
  3021. };
  3022. var nu$7 = function(s) {
  3023. return {
  3024. classes: isUndefined(s.classes) ? [] : s.classes,
  3025. attributes: isUndefined(s.attributes) ? {} : s.attributes,
  3026. styles: isUndefined(s.styles) ? {} : s.styles
  3027. };
  3028. };
  3029. var merge = function(defnA, mod) {
  3030. return __assign(__assign({}, defnA), {
  3031. attributes: __assign(__assign({}, defnA.attributes), mod.attributes),
  3032. styles: __assign(__assign({}, defnA.styles), mod.styles),
  3033. classes: defnA.classes.concat(mod.classes)
  3034. });
  3035. };
  3036. var combine$2 = function(info, baseMod, behaviours2, base2) {
  3037. var modsByBehaviour = __assign({}, baseMod);
  3038. each$1(behaviours2, function(behaviour) {
  3039. modsByBehaviour[behaviour.name()] = behaviour.exhibit(info, base2);
  3040. });
  3041. var byAspect = byInnerKey(modsByBehaviour, function(name2, modification) {
  3042. return {
  3043. name: name2,
  3044. modification
  3045. };
  3046. });
  3047. var combineObjects = function(objects) {
  3048. return foldr(objects, function(b2, a) {
  3049. return __assign(__assign({}, a.modification), b2);
  3050. }, {});
  3051. };
  3052. var combinedClasses = foldr(byAspect.classes, function(b2, a) {
  3053. return a.modification.concat(b2);
  3054. }, []);
  3055. var combinedAttributes = combineObjects(byAspect.attributes);
  3056. var combinedStyles = combineObjects(byAspect.styles);
  3057. return nu$7({
  3058. classes: combinedClasses,
  3059. attributes: combinedAttributes,
  3060. styles: combinedStyles
  3061. });
  3062. };
  3063. var sortKeys = function(label, keyName, array, order) {
  3064. try {
  3065. var sorted = sort(array, function(a, b2) {
  3066. var aKey = a[keyName];
  3067. var bKey = b2[keyName];
  3068. var aIndex = order.indexOf(aKey);
  3069. var bIndex = order.indexOf(bKey);
  3070. if (aIndex === -1) {
  3071. throw new Error("The ordering for " + label + " does not have an entry for " + aKey + ".\nOrder specified: " + JSON.stringify(order, null, 2));
  3072. }
  3073. if (bIndex === -1) {
  3074. throw new Error("The ordering for " + label + " does not have an entry for " + bKey + ".\nOrder specified: " + JSON.stringify(order, null, 2));
  3075. }
  3076. if (aIndex < bIndex) {
  3077. return -1;
  3078. } else if (bIndex < aIndex) {
  3079. return 1;
  3080. } else {
  3081. return 0;
  3082. }
  3083. });
  3084. return Result.value(sorted);
  3085. } catch (err) {
  3086. return Result.error([err]);
  3087. }
  3088. };
  3089. var uncurried = function(handler, purpose) {
  3090. return {
  3091. handler,
  3092. purpose
  3093. };
  3094. };
  3095. var curried = function(handler, purpose) {
  3096. return {
  3097. cHandler: handler,
  3098. purpose
  3099. };
  3100. };
  3101. var curryArgs = function(descHandler, extraArgs) {
  3102. return curried(curry.apply(void 0, [descHandler.handler].concat(extraArgs)), descHandler.purpose);
  3103. };
  3104. var getCurried = function(descHandler) {
  3105. return descHandler.cHandler;
  3106. };
  3107. var behaviourTuple = function(name2, handler) {
  3108. return {
  3109. name: name2,
  3110. handler
  3111. };
  3112. };
  3113. var nameToHandlers = function(behaviours2, info) {
  3114. var r2 = {};
  3115. each$1(behaviours2, function(behaviour) {
  3116. r2[behaviour.name()] = behaviour.handlers(info);
  3117. });
  3118. return r2;
  3119. };
  3120. var groupByEvents = function(info, behaviours2, base2) {
  3121. var behaviourEvents = __assign(__assign({}, base2), nameToHandlers(behaviours2, info));
  3122. return byInnerKey(behaviourEvents, behaviourTuple);
  3123. };
  3124. var combine$1 = function(info, eventOrder, behaviours2, base2) {
  3125. var byEventName = groupByEvents(info, behaviours2, base2);
  3126. return combineGroups(byEventName, eventOrder);
  3127. };
  3128. var assemble = function(rawHandler) {
  3129. var handler = read$2(rawHandler);
  3130. return function(component, simulatedEvent) {
  3131. var rest = [];
  3132. for (var _i = 2; _i < arguments.length; _i++) {
  3133. rest[_i - 2] = arguments[_i];
  3134. }
  3135. var args = [
  3136. component,
  3137. simulatedEvent
  3138. ].concat(rest);
  3139. if (handler.abort.apply(void 0, args)) {
  3140. simulatedEvent.stop();
  3141. } else if (handler.can.apply(void 0, args)) {
  3142. handler.run.apply(void 0, args);
  3143. }
  3144. };
  3145. };
  3146. var missingOrderError = function(eventName, tuples) {
  3147. return Result.error(["The event (" + eventName + ') has more than one behaviour that listens to it.\nWhen this occurs, you must specify an event ordering for the behaviours in your spec (e.g. [ "listing", "toggling" ]).\nThe behaviours that can trigger it are: ' + JSON.stringify(map$2(tuples, function(c) {
  3148. return c.name;
  3149. }), null, 2)]);
  3150. };
  3151. var fuse = function(tuples, eventOrder, eventName) {
  3152. var order = eventOrder[eventName];
  3153. if (!order) {
  3154. return missingOrderError(eventName, tuples);
  3155. } else {
  3156. return sortKeys("Event: " + eventName, "name", tuples, order).map(function(sortedTuples) {
  3157. var handlers2 = map$2(sortedTuples, function(tuple) {
  3158. return tuple.handler;
  3159. });
  3160. return fuse$1(handlers2);
  3161. });
  3162. }
  3163. };
  3164. var combineGroups = function(byEventName, eventOrder) {
  3165. var r2 = mapToArray(byEventName, function(tuples, eventName) {
  3166. var combined = tuples.length === 1 ? Result.value(tuples[0].handler) : fuse(tuples, eventOrder, eventName);
  3167. return combined.map(function(handler) {
  3168. var assembled = assemble(handler);
  3169. var purpose = tuples.length > 1 ? filter$2(eventOrder[eventName], function(o) {
  3170. return exists(tuples, function(t2) {
  3171. return t2.name === o;
  3172. });
  3173. }).join(" > ") : tuples[0].name;
  3174. return wrap$1(eventName, uncurried(assembled, purpose));
  3175. });
  3176. });
  3177. return consolidate(r2, {});
  3178. };
  3179. var _a$2;
  3180. var baseBehaviour = "alloy.base.behaviour";
  3181. var schema$z = objOf([
  3182. field$1("dom", "dom", required$2(), objOf([
  3183. required$1("tag"),
  3184. defaulted("styles", {}),
  3185. defaulted("classes", []),
  3186. defaulted("attributes", {}),
  3187. option("value"),
  3188. option("innerHtml")
  3189. ])),
  3190. required$1("components"),
  3191. required$1("uid"),
  3192. defaulted("events", {}),
  3193. defaulted("apis", {}),
  3194. field$1("eventOrder", "eventOrder", mergeWith((_a$2 = {}, _a$2[execute$5()] = [
  3195. "disabling",
  3196. baseBehaviour,
  3197. "toggling",
  3198. "typeaheadevents"
  3199. ], _a$2[focus$4()] = [
  3200. baseBehaviour,
  3201. "focusing",
  3202. "keying"
  3203. ], _a$2[systemInit()] = [
  3204. baseBehaviour,
  3205. "disabling",
  3206. "toggling",
  3207. "representing"
  3208. ], _a$2[input()] = [
  3209. baseBehaviour,
  3210. "representing",
  3211. "streaming",
  3212. "invalidating"
  3213. ], _a$2[detachedFromDom()] = [
  3214. baseBehaviour,
  3215. "representing",
  3216. "item-events",
  3217. "tooltipping"
  3218. ], _a$2[mousedown()] = [
  3219. "focusing",
  3220. baseBehaviour,
  3221. "item-type-events"
  3222. ], _a$2[touchstart()] = [
  3223. "focusing",
  3224. baseBehaviour,
  3225. "item-type-events"
  3226. ], _a$2[mouseover()] = [
  3227. "item-type-events",
  3228. "tooltipping"
  3229. ], _a$2[receive()] = [
  3230. "receiving",
  3231. "reflecting",
  3232. "tooltipping"
  3233. ], _a$2)), anyValue()),
  3234. option("domModification")
  3235. ]);
  3236. var toInfo = function(spec) {
  3237. return asRaw("custom.definition", schema$z, spec);
  3238. };
  3239. var toDefinition = function(detail) {
  3240. return __assign(__assign({}, detail.dom), {
  3241. uid: detail.uid,
  3242. domChildren: map$2(detail.components, function(comp) {
  3243. return comp.element;
  3244. })
  3245. });
  3246. };
  3247. var toModification = function(detail) {
  3248. return detail.domModification.fold(function() {
  3249. return nu$7({});
  3250. }, nu$7);
  3251. };
  3252. var toEvents = function(info) {
  3253. return info.events;
  3254. };
  3255. var read = function(element2, attr) {
  3256. var value2 = get$d(element2, attr);
  3257. return value2 === void 0 || value2 === "" ? [] : value2.split(" ");
  3258. };
  3259. var add$4 = function(element2, attr, id) {
  3260. var old = read(element2, attr);
  3261. var nu2 = old.concat([id]);
  3262. set$8(element2, attr, nu2.join(" "));
  3263. return true;
  3264. };
  3265. var remove$4 = function(element2, attr, id) {
  3266. var nu2 = filter$2(read(element2, attr), function(v) {
  3267. return v !== id;
  3268. });
  3269. if (nu2.length > 0) {
  3270. set$8(element2, attr, nu2.join(" "));
  3271. } else {
  3272. remove$7(element2, attr);
  3273. }
  3274. return false;
  3275. };
  3276. var supports = function(element2) {
  3277. return element2.dom.classList !== void 0;
  3278. };
  3279. var get$6 = function(element2) {
  3280. return read(element2, "class");
  3281. };
  3282. var add$3 = function(element2, clazz) {
  3283. return add$4(element2, "class", clazz);
  3284. };
  3285. var remove$3 = function(element2, clazz) {
  3286. return remove$4(element2, "class", clazz);
  3287. };
  3288. var add$2 = function(element2, clazz) {
  3289. if (supports(element2)) {
  3290. element2.dom.classList.add(clazz);
  3291. } else {
  3292. add$3(element2, clazz);
  3293. }
  3294. };
  3295. var cleanClass = function(element2) {
  3296. var classList = supports(element2) ? element2.dom.classList : get$6(element2);
  3297. if (classList.length === 0) {
  3298. remove$7(element2, "class");
  3299. }
  3300. };
  3301. var remove$2 = function(element2, clazz) {
  3302. if (supports(element2)) {
  3303. var classList = element2.dom.classList;
  3304. classList.remove(clazz);
  3305. } else {
  3306. remove$3(element2, clazz);
  3307. }
  3308. cleanClass(element2);
  3309. };
  3310. var has = function(element2, clazz) {
  3311. return supports(element2) && element2.dom.classList.contains(clazz);
  3312. };
  3313. var add$1 = function(element2, classes2) {
  3314. each$1(classes2, function(x) {
  3315. add$2(element2, x);
  3316. });
  3317. };
  3318. var remove$1 = function(element2, classes2) {
  3319. each$1(classes2, function(x) {
  3320. remove$2(element2, x);
  3321. });
  3322. };
  3323. var hasAll = function(element2, classes2) {
  3324. return forall(classes2, function(clazz) {
  3325. return has(element2, clazz);
  3326. });
  3327. };
  3328. var get$5 = function(element2) {
  3329. return element2.dom.value;
  3330. };
  3331. var set$4 = function(element2, value2) {
  3332. if (value2 === void 0) {
  3333. throw new Error("Value.set was undefined");
  3334. }
  3335. element2.dom.value = value2;
  3336. };
  3337. var renderToDom = function(definition) {
  3338. var subject = SugarElement.fromTag(definition.tag);
  3339. setAll$1(subject, definition.attributes);
  3340. add$1(subject, definition.classes);
  3341. setAll(subject, definition.styles);
  3342. definition.innerHtml.each(function(html) {
  3343. return set$5(subject, html);
  3344. });
  3345. var children2 = definition.domChildren;
  3346. append$1(subject, children2);
  3347. definition.value.each(function(value2) {
  3348. set$4(subject, value2);
  3349. });
  3350. if (!definition.uid) {
  3351. debugger;
  3352. }
  3353. writeOnly(subject, definition.uid);
  3354. return subject;
  3355. };
  3356. var getBehaviours$2 = function(spec) {
  3357. var behaviours2 = get$e(spec, "behaviours").getOr({});
  3358. return bind$3(keys(behaviours2), function(name2) {
  3359. var behaviour = behaviours2[name2];
  3360. return isNonNullable(behaviour) ? [behaviour.me] : [];
  3361. });
  3362. };
  3363. var generateFrom = function(spec, all2) {
  3364. return generateFrom$1(spec, all2);
  3365. };
  3366. var generate$4 = function(spec) {
  3367. var all2 = getBehaviours$2(spec);
  3368. return generateFrom(spec, all2);
  3369. };
  3370. var getDomDefinition = function(info, bList, bData) {
  3371. var definition = toDefinition(info);
  3372. var infoModification = toModification(info);
  3373. var baseModification = { "alloy.base.modification": infoModification };
  3374. var modification = bList.length > 0 ? combine$2(bData, baseModification, bList, definition) : infoModification;
  3375. return merge(definition, modification);
  3376. };
  3377. var getEvents = function(info, bList, bData) {
  3378. var baseEvents = { "alloy.base.behaviour": toEvents(info) };
  3379. return combine$1(bData, info.eventOrder, bList, baseEvents).getOrDie();
  3380. };
  3381. var build$2 = function(spec) {
  3382. var getMe = function() {
  3383. return me;
  3384. };
  3385. var systemApi = Cell(singleton$1);
  3386. var info = getOrDie(toInfo(spec));
  3387. var bBlob = generate$4(spec);
  3388. var bList = getBehaviours$3(bBlob);
  3389. var bData = getData$2(bBlob);
  3390. var modDefinition = getDomDefinition(info, bList, bData);
  3391. var item2 = renderToDom(modDefinition);
  3392. var events2 = getEvents(info, bList, bData);
  3393. var subcomponents = Cell(info.components);
  3394. var connect = function(newApi) {
  3395. systemApi.set(newApi);
  3396. };
  3397. var disconnect = function() {
  3398. systemApi.set(NoContextApi(getMe));
  3399. };
  3400. var syncComponents = function() {
  3401. var children$1 = children(item2);
  3402. var subs2 = bind$3(children$1, function(child2) {
  3403. return systemApi.get().getByDom(child2).fold(function() {
  3404. return [];
  3405. }, pure$2);
  3406. });
  3407. subcomponents.set(subs2);
  3408. };
  3409. var config2 = function(behaviour) {
  3410. var b2 = bData;
  3411. var f = isFunction(b2[behaviour.name()]) ? b2[behaviour.name()] : function() {
  3412. throw new Error("Could not find " + behaviour.name() + " in " + JSON.stringify(spec, null, 2));
  3413. };
  3414. return f();
  3415. };
  3416. var hasConfigured = function(behaviour) {
  3417. return isFunction(bData[behaviour.name()]);
  3418. };
  3419. var getApis = function() {
  3420. return info.apis;
  3421. };
  3422. var readState = function(behaviourName) {
  3423. return bData[behaviourName]().map(function(b2) {
  3424. return b2.state.readState();
  3425. }).getOr("not enabled");
  3426. };
  3427. var me = {
  3428. uid: spec.uid,
  3429. getSystem: systemApi.get,
  3430. config: config2,
  3431. hasConfigured,
  3432. spec,
  3433. readState,
  3434. getApis,
  3435. connect,
  3436. disconnect,
  3437. element: item2,
  3438. syncComponents,
  3439. components: subcomponents.get,
  3440. events: events2
  3441. };
  3442. return me;
  3443. };
  3444. var buildSubcomponents = function(spec) {
  3445. var components2 = get$e(spec, "components").getOr([]);
  3446. return map$2(components2, build$1);
  3447. };
  3448. var buildFromSpec = function(userSpec) {
  3449. var _a2 = make$8(userSpec), specEvents = _a2.events, spec = __rest(_a2, ["events"]);
  3450. var components2 = buildSubcomponents(spec);
  3451. var completeSpec = __assign(__assign({}, spec), {
  3452. events: __assign(__assign({}, DefaultEvents), specEvents),
  3453. components: components2
  3454. });
  3455. return Result.value(build$2(completeSpec));
  3456. };
  3457. var text = function(textContent) {
  3458. var element2 = SugarElement.fromText(textContent);
  3459. return external$2({ element: element2 });
  3460. };
  3461. var external$2 = function(spec) {
  3462. var extSpec = asRawOrDie$1("external.component", objOfOnly([
  3463. required$1("element"),
  3464. option("uid")
  3465. ]), spec);
  3466. var systemApi = Cell(NoContextApi());
  3467. var connect = function(newApi) {
  3468. systemApi.set(newApi);
  3469. };
  3470. var disconnect = function() {
  3471. systemApi.set(NoContextApi(function() {
  3472. return me;
  3473. }));
  3474. };
  3475. var uid = extSpec.uid.getOrThunk(function() {
  3476. return generate$5("external");
  3477. });
  3478. writeOnly(extSpec.element, uid);
  3479. var me = {
  3480. uid,
  3481. getSystem: systemApi.get,
  3482. config: Optional.none,
  3483. hasConfigured: never,
  3484. connect,
  3485. disconnect,
  3486. getApis: function() {
  3487. return {};
  3488. },
  3489. element: extSpec.element,
  3490. spec,
  3491. readState: constant$1("No state"),
  3492. syncComponents: noop,
  3493. components: constant$1([]),
  3494. events: {}
  3495. };
  3496. return premade$1(me);
  3497. };
  3498. var uids = generate$5;
  3499. var isSketchSpec$1 = function(spec) {
  3500. return has$2(spec, "uid");
  3501. };
  3502. var build$1 = function(spec) {
  3503. return getPremade(spec).getOrThunk(function() {
  3504. var userSpecWithUid = isSketchSpec$1(spec) ? spec : __assign({ uid: uids("") }, spec);
  3505. return buildFromSpec(userSpecWithUid).getOrDie();
  3506. });
  3507. };
  3508. var premade = premade$1;
  3509. function ClosestOrAncestor(is2, ancestor2, scope, a, isRoot) {
  3510. if (is2(scope, a)) {
  3511. return Optional.some(scope);
  3512. } else if (isFunction(isRoot) && isRoot(scope)) {
  3513. return Optional.none();
  3514. } else {
  3515. return ancestor2(scope, a, isRoot);
  3516. }
  3517. }
  3518. var ancestor$1 = function(scope, predicate, isRoot) {
  3519. var element2 = scope.dom;
  3520. var stop2 = isFunction(isRoot) ? isRoot : never;
  3521. while (element2.parentNode) {
  3522. element2 = element2.parentNode;
  3523. var el = SugarElement.fromDom(element2);
  3524. if (predicate(el)) {
  3525. return Optional.some(el);
  3526. } else if (stop2(el)) {
  3527. break;
  3528. }
  3529. }
  3530. return Optional.none();
  3531. };
  3532. var closest$3 = function(scope, predicate, isRoot) {
  3533. var is2 = function(s, test) {
  3534. return test(s);
  3535. };
  3536. return ClosestOrAncestor(is2, ancestor$1, scope, predicate, isRoot);
  3537. };
  3538. var child$1 = function(scope, predicate) {
  3539. var pred = function(node) {
  3540. return predicate(SugarElement.fromDom(node));
  3541. };
  3542. var result = find$5(scope.dom.childNodes, pred);
  3543. return result.map(SugarElement.fromDom);
  3544. };
  3545. var descendant$1 = function(scope, predicate) {
  3546. var descend = function(node) {
  3547. for (var i = 0; i < node.childNodes.length; i++) {
  3548. var child_1 = SugarElement.fromDom(node.childNodes[i]);
  3549. if (predicate(child_1)) {
  3550. return Optional.some(child_1);
  3551. }
  3552. var res = descend(node.childNodes[i]);
  3553. if (res.isSome()) {
  3554. return res;
  3555. }
  3556. }
  3557. return Optional.none();
  3558. };
  3559. return descend(scope.dom);
  3560. };
  3561. var closest$2 = function(scope, predicate, isRoot) {
  3562. return closest$3(scope, predicate, isRoot).isSome();
  3563. };
  3564. var ancestor = function(scope, selector, isRoot) {
  3565. return ancestor$1(scope, function(e) {
  3566. return is(e, selector);
  3567. }, isRoot);
  3568. };
  3569. var child = function(scope, selector) {
  3570. return child$1(scope, function(e) {
  3571. return is(e, selector);
  3572. });
  3573. };
  3574. var descendant = function(scope, selector) {
  3575. return one(selector, scope);
  3576. };
  3577. var closest$1 = function(scope, selector, isRoot) {
  3578. var is$12 = function(element2, selector2) {
  3579. return is(element2, selector2);
  3580. };
  3581. return ClosestOrAncestor(is$12, ancestor, scope, selector, isRoot);
  3582. };
  3583. var find$1 = function(queryElem) {
  3584. var dependent = closest$3(queryElem, function(elem) {
  3585. if (!isElement$2(elem)) {
  3586. return false;
  3587. }
  3588. var id = get$d(elem, "id");
  3589. return id !== void 0 && id.indexOf("aria-owns") > -1;
  3590. });
  3591. return dependent.bind(function(dep) {
  3592. var id = get$d(dep, "id");
  3593. var dos = getRootNode(dep);
  3594. return descendant(dos, '[aria-owns="' + id + '"]');
  3595. });
  3596. };
  3597. var manager = function() {
  3598. var ariaId = generate$6("aria-owns");
  3599. var link = function(elem) {
  3600. set$8(elem, "aria-owns", ariaId);
  3601. };
  3602. var unlink = function(elem) {
  3603. remove$7(elem, "aria-owns");
  3604. };
  3605. return {
  3606. id: ariaId,
  3607. link,
  3608. unlink
  3609. };
  3610. };
  3611. var isAriaPartOf = function(component, queryElem) {
  3612. return find$1(queryElem).exists(function(owner2) {
  3613. return isPartOf$1(component, owner2);
  3614. });
  3615. };
  3616. var isPartOf$1 = function(component, queryElem) {
  3617. return closest$2(queryElem, function(el) {
  3618. return eq(el, component.element);
  3619. }, never) || isAriaPartOf(component, queryElem);
  3620. };
  3621. var unknown = "unknown";
  3622. var EventConfiguration;
  3623. (function(EventConfiguration2) {
  3624. EventConfiguration2[EventConfiguration2["STOP"] = 0] = "STOP";
  3625. EventConfiguration2[EventConfiguration2["NORMAL"] = 1] = "NORMAL";
  3626. EventConfiguration2[EventConfiguration2["LOGGING"] = 2] = "LOGGING";
  3627. })(EventConfiguration || (EventConfiguration = {}));
  3628. var eventConfig = Cell({});
  3629. var makeEventLogger = function(eventName, initialTarget) {
  3630. var sequence2 = [];
  3631. var startTime = new Date().getTime();
  3632. return {
  3633. logEventCut: function(_name, target, purpose) {
  3634. sequence2.push({
  3635. outcome: "cut",
  3636. target,
  3637. purpose
  3638. });
  3639. },
  3640. logEventStopped: function(_name, target, purpose) {
  3641. sequence2.push({
  3642. outcome: "stopped",
  3643. target,
  3644. purpose
  3645. });
  3646. },
  3647. logNoParent: function(_name, target, purpose) {
  3648. sequence2.push({
  3649. outcome: "no-parent",
  3650. target,
  3651. purpose
  3652. });
  3653. },
  3654. logEventNoHandlers: function(_name, target) {
  3655. sequence2.push({
  3656. outcome: "no-handlers-left",
  3657. target
  3658. });
  3659. },
  3660. logEventResponse: function(_name, target, purpose) {
  3661. sequence2.push({
  3662. outcome: "response",
  3663. purpose,
  3664. target
  3665. });
  3666. },
  3667. write: function() {
  3668. var finishTime = new Date().getTime();
  3669. if (contains$2([
  3670. "mousemove",
  3671. "mouseover",
  3672. "mouseout",
  3673. systemInit()
  3674. ], eventName)) {
  3675. return;
  3676. }
  3677. console.log(eventName, {
  3678. event: eventName,
  3679. time: finishTime - startTime,
  3680. target: initialTarget.dom,
  3681. sequence: map$2(sequence2, function(s) {
  3682. if (!contains$2([
  3683. "cut",
  3684. "stopped",
  3685. "response"
  3686. ], s.outcome)) {
  3687. return s.outcome;
  3688. } else {
  3689. return "{" + s.purpose + "} " + s.outcome + " at (" + element(s.target) + ")";
  3690. }
  3691. })
  3692. });
  3693. }
  3694. };
  3695. };
  3696. var processEvent = function(eventName, initialTarget, f) {
  3697. var status = get$e(eventConfig.get(), eventName).orThunk(function() {
  3698. var patterns = keys(eventConfig.get());
  3699. return findMap(patterns, function(p) {
  3700. return eventName.indexOf(p) > -1 ? Optional.some(eventConfig.get()[p]) : Optional.none();
  3701. });
  3702. }).getOr(EventConfiguration.NORMAL);
  3703. switch (status) {
  3704. case EventConfiguration.NORMAL:
  3705. return f(noLogger());
  3706. case EventConfiguration.LOGGING: {
  3707. var logger = makeEventLogger(eventName, initialTarget);
  3708. var output2 = f(logger);
  3709. logger.write();
  3710. return output2;
  3711. }
  3712. case EventConfiguration.STOP:
  3713. return true;
  3714. }
  3715. };
  3716. var path = [
  3717. "alloy/data/Fields",
  3718. "alloy/debugging/Debugging"
  3719. ];
  3720. var getTrace = function() {
  3721. var err = new Error();
  3722. if (err.stack !== void 0) {
  3723. var lines = err.stack.split("\n");
  3724. return find$5(lines, function(line) {
  3725. return line.indexOf("alloy") > 0 && !exists(path, function(p) {
  3726. return line.indexOf(p) > -1;
  3727. });
  3728. }).getOr(unknown);
  3729. } else {
  3730. return unknown;
  3731. }
  3732. };
  3733. var ignoreEvent = {
  3734. logEventCut: noop,
  3735. logEventStopped: noop,
  3736. logNoParent: noop,
  3737. logEventNoHandlers: noop,
  3738. logEventResponse: noop,
  3739. write: noop
  3740. };
  3741. var monitorEvent = function(eventName, initialTarget, f) {
  3742. return processEvent(eventName, initialTarget, f);
  3743. };
  3744. var noLogger = constant$1(ignoreEvent);
  3745. var menuFields = constant$1([
  3746. required$1("menu"),
  3747. required$1("selectedMenu")
  3748. ]);
  3749. var itemFields = constant$1([
  3750. required$1("item"),
  3751. required$1("selectedItem")
  3752. ]);
  3753. constant$1(objOf(itemFields().concat(menuFields())));
  3754. var itemSchema$3 = constant$1(objOf(itemFields()));
  3755. var _initSize = requiredObjOf("initSize", [
  3756. required$1("numColumns"),
  3757. required$1("numRows")
  3758. ]);
  3759. var itemMarkers = function() {
  3760. return requiredOf("markers", itemSchema$3());
  3761. };
  3762. var tieredMenuMarkers = function() {
  3763. return requiredObjOf("markers", [required$1("backgroundMenu")].concat(menuFields()).concat(itemFields()));
  3764. };
  3765. var markers$1 = function(required2) {
  3766. return requiredObjOf("markers", map$2(required2, required$1));
  3767. };
  3768. var onPresenceHandler = function(label, fieldName, presence) {
  3769. getTrace();
  3770. return field$1(fieldName, fieldName, presence, valueOf(function(f) {
  3771. return Result.value(function() {
  3772. var args = [];
  3773. for (var _i = 0; _i < arguments.length; _i++) {
  3774. args[_i] = arguments[_i];
  3775. }
  3776. return f.apply(void 0, args);
  3777. });
  3778. }));
  3779. };
  3780. var onHandler = function(fieldName) {
  3781. return onPresenceHandler("onHandler", fieldName, defaulted$1(noop));
  3782. };
  3783. var onKeyboardHandler = function(fieldName) {
  3784. return onPresenceHandler("onKeyboardHandler", fieldName, defaulted$1(Optional.none));
  3785. };
  3786. var onStrictHandler = function(fieldName) {
  3787. return onPresenceHandler("onHandler", fieldName, required$2());
  3788. };
  3789. var onStrictKeyboardHandler = function(fieldName) {
  3790. return onPresenceHandler("onKeyboardHandler", fieldName, required$2());
  3791. };
  3792. var output$1 = function(name2, value2) {
  3793. return customField(name2, constant$1(value2));
  3794. };
  3795. var snapshot = function(name2) {
  3796. return customField(name2, identity$1);
  3797. };
  3798. var initSize = constant$1(_initSize);
  3799. var nu$6 = function(x, y, bubble, direction, placement2, boundsRestriction2, labelPrefix2, alwaysFit) {
  3800. if (alwaysFit === void 0) {
  3801. alwaysFit = false;
  3802. }
  3803. return {
  3804. x,
  3805. y,
  3806. bubble,
  3807. direction,
  3808. placement: placement2,
  3809. restriction: boundsRestriction2,
  3810. label: labelPrefix2 + "-" + placement2,
  3811. alwaysFit
  3812. };
  3813. };
  3814. var adt$a = Adt.generate([
  3815. { southeast: [] },
  3816. { southwest: [] },
  3817. { northeast: [] },
  3818. { northwest: [] },
  3819. { south: [] },
  3820. { north: [] },
  3821. { east: [] },
  3822. { west: [] }
  3823. ]);
  3824. var cata$2 = function(subject, southeast2, southwest2, northeast2, northwest2, south2, north2, east2, west2) {
  3825. return subject.fold(southeast2, southwest2, northeast2, northwest2, south2, north2, east2, west2);
  3826. };
  3827. var cataVertical = function(subject, south2, middle, north2) {
  3828. return subject.fold(south2, south2, north2, north2, south2, north2, middle, middle);
  3829. };
  3830. var cataHorizontal = function(subject, east2, middle, west2) {
  3831. return subject.fold(east2, west2, east2, west2, middle, middle, east2, west2);
  3832. };
  3833. var southeast$3 = adt$a.southeast;
  3834. var southwest$3 = adt$a.southwest;
  3835. var northeast$3 = adt$a.northeast;
  3836. var northwest$3 = adt$a.northwest;
  3837. var south$3 = adt$a.south;
  3838. var north$3 = adt$a.north;
  3839. var east$3 = adt$a.east;
  3840. var west$3 = adt$a.west;
  3841. var cycleBy = function(value2, delta, min2, max2) {
  3842. var r2 = value2 + delta;
  3843. if (r2 > max2) {
  3844. return min2;
  3845. } else if (r2 < min2) {
  3846. return max2;
  3847. } else {
  3848. return r2;
  3849. }
  3850. };
  3851. var clamp$1 = function(value2, min2, max2) {
  3852. return Math.min(Math.max(value2, min2), max2);
  3853. };
  3854. var getRestriction = function(anchor2, restriction) {
  3855. switch (restriction) {
  3856. case 1:
  3857. return anchor2.x;
  3858. case 0:
  3859. return anchor2.x + anchor2.width;
  3860. case 2:
  3861. return anchor2.y;
  3862. case 3:
  3863. return anchor2.y + anchor2.height;
  3864. }
  3865. };
  3866. var boundsRestriction = function(anchor2, restrictions) {
  3867. return mapToObject([
  3868. "left",
  3869. "right",
  3870. "top",
  3871. "bottom"
  3872. ], function(dir) {
  3873. return get$e(restrictions, dir).map(function(restriction) {
  3874. return getRestriction(anchor2, restriction);
  3875. });
  3876. });
  3877. };
  3878. var adjustBounds = function(bounds$12, restriction, bubbleOffset) {
  3879. var applyRestriction = function(dir, current) {
  3880. return restriction[dir].map(function(pos) {
  3881. var isVerticalAxis = dir === "top" || dir === "bottom";
  3882. var offset2 = isVerticalAxis ? bubbleOffset.top : bubbleOffset.left;
  3883. var comparator = dir === "left" || dir === "top" ? Math.max : Math.min;
  3884. var newPos = comparator(pos, current) + offset2;
  3885. return isVerticalAxis ? clamp$1(newPos, bounds$12.y, bounds$12.bottom) : clamp$1(newPos, bounds$12.x, bounds$12.right);
  3886. }).getOr(current);
  3887. };
  3888. var adjustedLeft = applyRestriction("left", bounds$12.x);
  3889. var adjustedTop = applyRestriction("top", bounds$12.y);
  3890. var adjustedRight = applyRestriction("right", bounds$12.right);
  3891. var adjustedBottom = applyRestriction("bottom", bounds$12.bottom);
  3892. return bounds(adjustedLeft, adjustedTop, adjustedRight - adjustedLeft, adjustedBottom - adjustedTop);
  3893. };
  3894. var labelPrefix$2 = "layout";
  3895. var eastX$1 = function(anchor2) {
  3896. return anchor2.x;
  3897. };
  3898. var middleX$1 = function(anchor2, element2) {
  3899. return anchor2.x + anchor2.width / 2 - element2.width / 2;
  3900. };
  3901. var westX$1 = function(anchor2, element2) {
  3902. return anchor2.x + anchor2.width - element2.width;
  3903. };
  3904. var northY$2 = function(anchor2, element2) {
  3905. return anchor2.y - element2.height;
  3906. };
  3907. var southY$2 = function(anchor2) {
  3908. return anchor2.y + anchor2.height;
  3909. };
  3910. var centreY$1 = function(anchor2, element2) {
  3911. return anchor2.y + anchor2.height / 2 - element2.height / 2;
  3912. };
  3913. var eastEdgeX$1 = function(anchor2) {
  3914. return anchor2.x + anchor2.width;
  3915. };
  3916. var westEdgeX$1 = function(anchor2, element2) {
  3917. return anchor2.x - element2.width;
  3918. };
  3919. var southeast$2 = function(anchor2, element2, bubbles) {
  3920. return nu$6(eastX$1(anchor2), southY$2(anchor2), bubbles.southeast(), southeast$3(), "southeast", boundsRestriction(anchor2, {
  3921. left: 1,
  3922. top: 3
  3923. }), labelPrefix$2);
  3924. };
  3925. var southwest$2 = function(anchor2, element2, bubbles) {
  3926. return nu$6(westX$1(anchor2, element2), southY$2(anchor2), bubbles.southwest(), southwest$3(), "southwest", boundsRestriction(anchor2, {
  3927. right: 0,
  3928. top: 3
  3929. }), labelPrefix$2);
  3930. };
  3931. var northeast$2 = function(anchor2, element2, bubbles) {
  3932. return nu$6(eastX$1(anchor2), northY$2(anchor2, element2), bubbles.northeast(), northeast$3(), "northeast", boundsRestriction(anchor2, {
  3933. left: 1,
  3934. bottom: 2
  3935. }), labelPrefix$2);
  3936. };
  3937. var northwest$2 = function(anchor2, element2, bubbles) {
  3938. return nu$6(westX$1(anchor2, element2), northY$2(anchor2, element2), bubbles.northwest(), northwest$3(), "northwest", boundsRestriction(anchor2, {
  3939. right: 0,
  3940. bottom: 2
  3941. }), labelPrefix$2);
  3942. };
  3943. var north$2 = function(anchor2, element2, bubbles) {
  3944. return nu$6(middleX$1(anchor2, element2), northY$2(anchor2, element2), bubbles.north(), north$3(), "north", boundsRestriction(anchor2, { bottom: 2 }), labelPrefix$2);
  3945. };
  3946. var south$2 = function(anchor2, element2, bubbles) {
  3947. return nu$6(middleX$1(anchor2, element2), southY$2(anchor2), bubbles.south(), south$3(), "south", boundsRestriction(anchor2, { top: 3 }), labelPrefix$2);
  3948. };
  3949. var east$2 = function(anchor2, element2, bubbles) {
  3950. return nu$6(eastEdgeX$1(anchor2), centreY$1(anchor2, element2), bubbles.east(), east$3(), "east", boundsRestriction(anchor2, { left: 0 }), labelPrefix$2);
  3951. };
  3952. var west$2 = function(anchor2, element2, bubbles) {
  3953. return nu$6(westEdgeX$1(anchor2, element2), centreY$1(anchor2, element2), bubbles.west(), west$3(), "west", boundsRestriction(anchor2, { right: 1 }), labelPrefix$2);
  3954. };
  3955. var all$1 = function() {
  3956. return [
  3957. southeast$2,
  3958. southwest$2,
  3959. northeast$2,
  3960. northwest$2,
  3961. south$2,
  3962. north$2,
  3963. east$2,
  3964. west$2
  3965. ];
  3966. };
  3967. var allRtl$1 = function() {
  3968. return [
  3969. southwest$2,
  3970. southeast$2,
  3971. northwest$2,
  3972. northeast$2,
  3973. south$2,
  3974. north$2,
  3975. east$2,
  3976. west$2
  3977. ];
  3978. };
  3979. var aboveOrBelow = function() {
  3980. return [
  3981. northeast$2,
  3982. northwest$2,
  3983. southeast$2,
  3984. southwest$2,
  3985. north$2,
  3986. south$2
  3987. ];
  3988. };
  3989. var aboveOrBelowRtl = function() {
  3990. return [
  3991. northwest$2,
  3992. northeast$2,
  3993. southwest$2,
  3994. southeast$2,
  3995. north$2,
  3996. south$2
  3997. ];
  3998. };
  3999. var belowOrAbove = function() {
  4000. return [
  4001. southeast$2,
  4002. southwest$2,
  4003. northeast$2,
  4004. northwest$2,
  4005. south$2,
  4006. north$2
  4007. ];
  4008. };
  4009. var belowOrAboveRtl = function() {
  4010. return [
  4011. southwest$2,
  4012. southeast$2,
  4013. northwest$2,
  4014. northeast$2,
  4015. south$2,
  4016. north$2
  4017. ];
  4018. };
  4019. var chooseChannels = function(channels, message) {
  4020. return message.universal ? channels : filter$2(channels, function(ch) {
  4021. return contains$2(message.channels, ch);
  4022. });
  4023. };
  4024. var events$h = function(receiveConfig) {
  4025. return derive$2([run$1(receive(), function(component, message) {
  4026. var channelMap = receiveConfig.channels;
  4027. var channels = keys(channelMap);
  4028. var receivingData = message;
  4029. var targetChannels = chooseChannels(channels, receivingData);
  4030. each$1(targetChannels, function(ch) {
  4031. var channelInfo = channelMap[ch];
  4032. var channelSchema = channelInfo.schema;
  4033. var data = asRawOrDie$1("channel[" + ch + "] data\nReceiver: " + element(component.element), channelSchema, receivingData.data);
  4034. channelInfo.onReceive(component, data);
  4035. });
  4036. })]);
  4037. };
  4038. var ActiveReceiving = Object.freeze({
  4039. __proto__: null,
  4040. events: events$h
  4041. });
  4042. var ReceivingSchema = [requiredOf("channels", setOf(Result.value, objOfOnly([
  4043. onStrictHandler("onReceive"),
  4044. defaulted("schema", anyValue())
  4045. ])))];
  4046. var executeEvent = function(bConfig, bState, executor) {
  4047. return runOnExecute$1(function(component) {
  4048. executor(component, bConfig, bState);
  4049. });
  4050. };
  4051. var loadEvent = function(bConfig, bState, f) {
  4052. return runOnInit(function(component, _simulatedEvent) {
  4053. f(component, bConfig, bState);
  4054. });
  4055. };
  4056. var create$8 = function(schema2, name2, active2, apis, extra, state) {
  4057. var configSchema = objOfOnly(schema2);
  4058. var schemaSchema = optionObjOf(name2, [optionObjOfOnly("config", schema2)]);
  4059. return doCreate(configSchema, schemaSchema, name2, active2, apis, extra, state);
  4060. };
  4061. var createModes$1 = function(modes, name2, active2, apis, extra, state) {
  4062. var configSchema = modes;
  4063. var schemaSchema = optionObjOf(name2, [optionOf("config", modes)]);
  4064. return doCreate(configSchema, schemaSchema, name2, active2, apis, extra, state);
  4065. };
  4066. var wrapApi = function(bName, apiFunction, apiName) {
  4067. var f = function(component) {
  4068. var rest = [];
  4069. for (var _i = 1; _i < arguments.length; _i++) {
  4070. rest[_i - 1] = arguments[_i];
  4071. }
  4072. var args = [component].concat(rest);
  4073. return component.config({ name: constant$1(bName) }).fold(function() {
  4074. throw new Error("We could not find any behaviour configuration for: " + bName + ". Using API: " + apiName);
  4075. }, function(info) {
  4076. var rest2 = Array.prototype.slice.call(args, 1);
  4077. return apiFunction.apply(void 0, [
  4078. component,
  4079. info.config,
  4080. info.state
  4081. ].concat(rest2));
  4082. });
  4083. };
  4084. return markAsBehaviourApi(f, apiName, apiFunction);
  4085. };
  4086. var revokeBehaviour = function(name2) {
  4087. return {
  4088. key: name2,
  4089. value: void 0
  4090. };
  4091. };
  4092. var doCreate = function(configSchema, schemaSchema, name2, active2, apis, extra, state) {
  4093. var getConfig = function(info) {
  4094. return hasNonNullableKey(info, name2) ? info[name2]() : Optional.none();
  4095. };
  4096. var wrappedApis = map$1(apis, function(apiF, apiName) {
  4097. return wrapApi(name2, apiF, apiName);
  4098. });
  4099. var wrappedExtra = map$1(extra, function(extraF, extraName) {
  4100. return markAsExtraApi(extraF, extraName);
  4101. });
  4102. var me = __assign(__assign(__assign({}, wrappedExtra), wrappedApis), {
  4103. revoke: curry(revokeBehaviour, name2),
  4104. config: function(spec) {
  4105. var prepared = asRawOrDie$1(name2 + "-config", configSchema, spec);
  4106. return {
  4107. key: name2,
  4108. value: {
  4109. config: prepared,
  4110. me,
  4111. configAsRaw: cached(function() {
  4112. return asRawOrDie$1(name2 + "-config", configSchema, spec);
  4113. }),
  4114. initialConfig: spec,
  4115. state
  4116. }
  4117. };
  4118. },
  4119. schema: constant$1(schemaSchema),
  4120. exhibit: function(info, base2) {
  4121. return lift2(getConfig(info), get$e(active2, "exhibit"), function(behaviourInfo, exhibitor) {
  4122. return exhibitor(base2, behaviourInfo.config, behaviourInfo.state);
  4123. }).getOrThunk(function() {
  4124. return nu$7({});
  4125. });
  4126. },
  4127. name: constant$1(name2),
  4128. handlers: function(info) {
  4129. return getConfig(info).map(function(behaviourInfo) {
  4130. var getEvents2 = get$e(active2, "events").getOr(function() {
  4131. return {};
  4132. });
  4133. return getEvents2(behaviourInfo.config, behaviourInfo.state);
  4134. }).getOr({});
  4135. }
  4136. });
  4137. return me;
  4138. };
  4139. var derive$1 = function(capabilities) {
  4140. return wrapAll(capabilities);
  4141. };
  4142. var simpleSchema = objOfOnly([
  4143. required$1("fields"),
  4144. required$1("name"),
  4145. defaulted("active", {}),
  4146. defaulted("apis", {}),
  4147. defaulted("state", NoState),
  4148. defaulted("extra", {})
  4149. ]);
  4150. var create$7 = function(data) {
  4151. var value2 = asRawOrDie$1("Creating behaviour: " + data.name, simpleSchema, data);
  4152. return create$8(value2.fields, value2.name, value2.active, value2.apis, value2.extra, value2.state);
  4153. };
  4154. var modeSchema = objOfOnly([
  4155. required$1("branchKey"),
  4156. required$1("branches"),
  4157. required$1("name"),
  4158. defaulted("active", {}),
  4159. defaulted("apis", {}),
  4160. defaulted("state", NoState),
  4161. defaulted("extra", {})
  4162. ]);
  4163. var createModes = function(data) {
  4164. var value2 = asRawOrDie$1("Creating behaviour: " + data.name, modeSchema, data);
  4165. return createModes$1(choose$1(value2.branchKey, value2.branches), value2.name, value2.active, value2.apis, value2.extra, value2.state);
  4166. };
  4167. var revoke = constant$1(void 0);
  4168. var Receiving = create$7({
  4169. fields: ReceivingSchema,
  4170. name: "receiving",
  4171. active: ActiveReceiving
  4172. });
  4173. var exhibit$6 = function(base2, posConfig) {
  4174. return nu$7({
  4175. classes: [],
  4176. styles: posConfig.useFixed() ? {} : { position: "relative" }
  4177. });
  4178. };
  4179. var ActivePosition = Object.freeze({
  4180. __proto__: null,
  4181. exhibit: exhibit$6
  4182. });
  4183. var getDocument = function() {
  4184. return SugarElement.fromDom(document);
  4185. };
  4186. var focus$3 = function(element2) {
  4187. return element2.dom.focus();
  4188. };
  4189. var blur$1 = function(element2) {
  4190. return element2.dom.blur();
  4191. };
  4192. var hasFocus = function(element2) {
  4193. var root = getRootNode(element2).dom;
  4194. return element2.dom === root.activeElement;
  4195. };
  4196. var active = function(root) {
  4197. if (root === void 0) {
  4198. root = getDocument();
  4199. }
  4200. return Optional.from(root.dom.activeElement).map(SugarElement.fromDom);
  4201. };
  4202. var search = function(element2) {
  4203. return active(getRootNode(element2)).filter(function(e) {
  4204. return element2.dom.contains(e.dom);
  4205. });
  4206. };
  4207. var preserve$1 = function(f, container) {
  4208. var dos = getRootNode(container);
  4209. var refocus = active(dos).bind(function(focused) {
  4210. var hasFocus2 = function(elem) {
  4211. return eq(focused, elem);
  4212. };
  4213. return hasFocus2(container) ? Optional.some(container) : descendant$1(container, hasFocus2);
  4214. });
  4215. var result = f(container);
  4216. refocus.each(function(oldFocus) {
  4217. active(dos).filter(function(newFocus) {
  4218. return eq(newFocus, oldFocus);
  4219. }).fold(function() {
  4220. focus$3(oldFocus);
  4221. }, noop);
  4222. });
  4223. return result;
  4224. };
  4225. var NuPositionCss = function(position2, left2, top2, right2, bottom2) {
  4226. var toPx = function(num) {
  4227. return num + "px";
  4228. };
  4229. return {
  4230. position: position2,
  4231. left: left2.map(toPx),
  4232. top: top2.map(toPx),
  4233. right: right2.map(toPx),
  4234. bottom: bottom2.map(toPx)
  4235. };
  4236. };
  4237. var toOptions = function(position2) {
  4238. return __assign(__assign({}, position2), { position: Optional.some(position2.position) });
  4239. };
  4240. var applyPositionCss = function(element2, position2) {
  4241. setOptions(element2, toOptions(position2));
  4242. };
  4243. var adt$9 = Adt.generate([
  4244. { none: [] },
  4245. {
  4246. relative: [
  4247. "x",
  4248. "y",
  4249. "width",
  4250. "height"
  4251. ]
  4252. },
  4253. {
  4254. fixed: [
  4255. "x",
  4256. "y",
  4257. "width",
  4258. "height"
  4259. ]
  4260. }
  4261. ]);
  4262. var positionWithDirection = function(posName, decision, x, y, width2, height2) {
  4263. var decisionRect = decision.rect;
  4264. var decisionX = decisionRect.x - x;
  4265. var decisionY = decisionRect.y - y;
  4266. var decisionWidth = decisionRect.width;
  4267. var decisionHeight = decisionRect.height;
  4268. var decisionRight = width2 - (decisionX + decisionWidth);
  4269. var decisionBottom = height2 - (decisionY + decisionHeight);
  4270. var left2 = Optional.some(decisionX);
  4271. var top2 = Optional.some(decisionY);
  4272. var right2 = Optional.some(decisionRight);
  4273. var bottom2 = Optional.some(decisionBottom);
  4274. var none2 = Optional.none();
  4275. return cata$2(decision.direction, function() {
  4276. return NuPositionCss(posName, left2, top2, none2, none2);
  4277. }, function() {
  4278. return NuPositionCss(posName, none2, top2, right2, none2);
  4279. }, function() {
  4280. return NuPositionCss(posName, left2, none2, none2, bottom2);
  4281. }, function() {
  4282. return NuPositionCss(posName, none2, none2, right2, bottom2);
  4283. }, function() {
  4284. return NuPositionCss(posName, left2, top2, none2, none2);
  4285. }, function() {
  4286. return NuPositionCss(posName, left2, none2, none2, bottom2);
  4287. }, function() {
  4288. return NuPositionCss(posName, left2, top2, none2, none2);
  4289. }, function() {
  4290. return NuPositionCss(posName, none2, top2, right2, none2);
  4291. });
  4292. };
  4293. var reposition = function(origin, decision) {
  4294. return origin.fold(function() {
  4295. var decisionRect = decision.rect;
  4296. return NuPositionCss("absolute", Optional.some(decisionRect.x), Optional.some(decisionRect.y), Optional.none(), Optional.none());
  4297. }, function(x, y, width2, height2) {
  4298. return positionWithDirection("absolute", decision, x, y, width2, height2);
  4299. }, function(x, y, width2, height2) {
  4300. return positionWithDirection("fixed", decision, x, y, width2, height2);
  4301. });
  4302. };
  4303. var toBox = function(origin, element2) {
  4304. var rel = curry(find$2, element2);
  4305. var position2 = origin.fold(rel, rel, function() {
  4306. var scroll = get$9();
  4307. return find$2(element2).translate(-scroll.left, -scroll.top);
  4308. });
  4309. var width2 = getOuter$1(element2);
  4310. var height2 = getOuter$2(element2);
  4311. return bounds(position2.left, position2.top, width2, height2);
  4312. };
  4313. var viewport = function(origin, getBounds2) {
  4314. return getBounds2.fold(function() {
  4315. return origin.fold(win, win, bounds);
  4316. }, function(b2) {
  4317. return origin.fold(b2, b2, function() {
  4318. var bounds$12 = b2();
  4319. var pos = translate$2(origin, bounds$12.x, bounds$12.y);
  4320. return bounds(pos.left, pos.top, bounds$12.width, bounds$12.height);
  4321. });
  4322. });
  4323. };
  4324. var translate$2 = function(origin, x, y) {
  4325. var pos = SugarPosition(x, y);
  4326. var removeScroll = function() {
  4327. var outerScroll = get$9();
  4328. return pos.translate(-outerScroll.left, -outerScroll.top);
  4329. };
  4330. return origin.fold(constant$1(pos), constant$1(pos), removeScroll);
  4331. };
  4332. var cata$1 = function(subject, onNone, onRelative, onFixed) {
  4333. return subject.fold(onNone, onRelative, onFixed);
  4334. };
  4335. adt$9.none;
  4336. var relative$1 = adt$9.relative;
  4337. var fixed$1 = adt$9.fixed;
  4338. var anchor = function(anchorBox, origin) {
  4339. return {
  4340. anchorBox,
  4341. origin
  4342. };
  4343. };
  4344. var box = function(anchorBox, origin) {
  4345. return anchor(anchorBox, origin);
  4346. };
  4347. var placementAttribute = "data-alloy-placement";
  4348. var setPlacement$1 = function(element2, placement2) {
  4349. set$8(element2, placementAttribute, placement2);
  4350. };
  4351. var getPlacement = function(element2) {
  4352. return getOpt(element2, placementAttribute);
  4353. };
  4354. var reset$2 = function(element2) {
  4355. return remove$7(element2, placementAttribute);
  4356. };
  4357. var adt$8 = Adt.generate([
  4358. { fit: ["reposition"] },
  4359. {
  4360. nofit: [
  4361. "reposition",
  4362. "visibleW",
  4363. "visibleH",
  4364. "isVisible"
  4365. ]
  4366. }
  4367. ]);
  4368. var determinePosition = function(box2, bounds2) {
  4369. var boundsX = bounds2.x, boundsY = bounds2.y, boundsRight = bounds2.right, boundsBottom = bounds2.bottom;
  4370. var x = box2.x, y = box2.y, right2 = box2.right, bottom2 = box2.bottom, width2 = box2.width, height2 = box2.height;
  4371. var xInBounds = x >= boundsX && x <= boundsRight;
  4372. var yInBounds = y >= boundsY && y <= boundsBottom;
  4373. var originInBounds = xInBounds && yInBounds;
  4374. var rightInBounds = right2 <= boundsRight && right2 >= boundsX;
  4375. var bottomInBounds = bottom2 <= boundsBottom && bottom2 >= boundsY;
  4376. var sizeInBounds = rightInBounds && bottomInBounds;
  4377. var visibleW = Math.min(width2, x >= boundsX ? boundsRight - x : right2 - boundsX);
  4378. var visibleH = Math.min(height2, y >= boundsY ? boundsBottom - y : bottom2 - boundsY);
  4379. return {
  4380. originInBounds,
  4381. sizeInBounds,
  4382. visibleW,
  4383. visibleH
  4384. };
  4385. };
  4386. var calcReposition = function(box2, bounds$12) {
  4387. var boundsX = bounds$12.x, boundsY = bounds$12.y, boundsRight = bounds$12.right, boundsBottom = bounds$12.bottom;
  4388. var x = box2.x, y = box2.y, width2 = box2.width, height2 = box2.height;
  4389. var maxX2 = Math.max(boundsX, boundsRight - width2);
  4390. var maxY2 = Math.max(boundsY, boundsBottom - height2);
  4391. var restrictedX = clamp$1(x, boundsX, maxX2);
  4392. var restrictedY = clamp$1(y, boundsY, maxY2);
  4393. var restrictedWidth = Math.min(restrictedX + width2, boundsRight) - restrictedX;
  4394. var restrictedHeight = Math.min(restrictedY + height2, boundsBottom) - restrictedY;
  4395. return bounds(restrictedX, restrictedY, restrictedWidth, restrictedHeight);
  4396. };
  4397. var calcMaxSizes = function(direction, box2, bounds2) {
  4398. var upAvailable = constant$1(box2.bottom - bounds2.y);
  4399. var downAvailable = constant$1(bounds2.bottom - box2.y);
  4400. var maxHeight = cataVertical(direction, downAvailable, downAvailable, upAvailable);
  4401. var westAvailable = constant$1(box2.right - bounds2.x);
  4402. var eastAvailable = constant$1(bounds2.right - box2.x);
  4403. var maxWidth = cataHorizontal(direction, eastAvailable, eastAvailable, westAvailable);
  4404. return {
  4405. maxWidth,
  4406. maxHeight
  4407. };
  4408. };
  4409. var attempt = function(candidate, width2, height2, bounds$12) {
  4410. var bubble = candidate.bubble;
  4411. var bubbleOffset = bubble.offset;
  4412. var adjustedBounds = adjustBounds(bounds$12, candidate.restriction, bubbleOffset);
  4413. var newX = candidate.x + bubbleOffset.left;
  4414. var newY = candidate.y + bubbleOffset.top;
  4415. var box2 = bounds(newX, newY, width2, height2);
  4416. var _a2 = determinePosition(box2, adjustedBounds), originInBounds = _a2.originInBounds, sizeInBounds = _a2.sizeInBounds, visibleW = _a2.visibleW, visibleH = _a2.visibleH;
  4417. var fits = originInBounds && sizeInBounds;
  4418. var fittedBox = fits ? box2 : calcReposition(box2, adjustedBounds);
  4419. var isPartlyVisible = fittedBox.width > 0 && fittedBox.height > 0;
  4420. var _b = calcMaxSizes(candidate.direction, fittedBox, bounds$12), maxWidth = _b.maxWidth, maxHeight = _b.maxHeight;
  4421. var reposition2 = {
  4422. rect: fittedBox,
  4423. maxHeight,
  4424. maxWidth,
  4425. direction: candidate.direction,
  4426. placement: candidate.placement,
  4427. classes: {
  4428. on: bubble.classesOn,
  4429. off: bubble.classesOff
  4430. },
  4431. layout: candidate.label,
  4432. testY: newY
  4433. };
  4434. return fits || candidate.alwaysFit ? adt$8.fit(reposition2) : adt$8.nofit(reposition2, visibleW, visibleH, isPartlyVisible);
  4435. };
  4436. var attempts = function(element2, candidates, anchorBox, elementBox, bubbles, bounds2) {
  4437. var panelWidth = elementBox.width;
  4438. var panelHeight = elementBox.height;
  4439. var attemptBestFit = function(layout2, reposition2, visibleW, visibleH, isVisible2) {
  4440. var next = layout2(anchorBox, elementBox, bubbles, element2, bounds2);
  4441. var attemptLayout = attempt(next, panelWidth, panelHeight, bounds2);
  4442. return attemptLayout.fold(constant$1(attemptLayout), function(newReposition, newVisibleW, newVisibleH, newIsVisible) {
  4443. var improved = isVisible2 === newIsVisible ? newVisibleH > visibleH || newVisibleW > visibleW : !isVisible2 && newIsVisible;
  4444. return improved ? attemptLayout : adt$8.nofit(reposition2, visibleW, visibleH, isVisible2);
  4445. });
  4446. };
  4447. var abc = foldl(candidates, function(b2, a) {
  4448. var bestNext = curry(attemptBestFit, a);
  4449. return b2.fold(constant$1(b2), bestNext);
  4450. }, adt$8.nofit({
  4451. rect: anchorBox,
  4452. maxHeight: elementBox.height,
  4453. maxWidth: elementBox.width,
  4454. direction: southeast$3(),
  4455. placement: "southeast",
  4456. classes: {
  4457. on: [],
  4458. off: []
  4459. },
  4460. layout: "none",
  4461. testY: anchorBox.y
  4462. }, -1, -1, false));
  4463. return abc.fold(identity$1, identity$1);
  4464. };
  4465. var singleton = function(doRevoke) {
  4466. var subject = Cell(Optional.none());
  4467. var revoke2 = function() {
  4468. return subject.get().each(doRevoke);
  4469. };
  4470. var clear2 = function() {
  4471. revoke2();
  4472. subject.set(Optional.none());
  4473. };
  4474. var isSet = function() {
  4475. return subject.get().isSome();
  4476. };
  4477. var get2 = function() {
  4478. return subject.get();
  4479. };
  4480. var set2 = function(s) {
  4481. revoke2();
  4482. subject.set(Optional.some(s));
  4483. };
  4484. return {
  4485. clear: clear2,
  4486. isSet,
  4487. get: get2,
  4488. set: set2
  4489. };
  4490. };
  4491. var destroyable = function() {
  4492. return singleton(function(s) {
  4493. return s.destroy();
  4494. });
  4495. };
  4496. var unbindable = function() {
  4497. return singleton(function(s) {
  4498. return s.unbind();
  4499. });
  4500. };
  4501. var api$1 = function() {
  4502. var subject = destroyable();
  4503. var run2 = function(f) {
  4504. return subject.get().each(f);
  4505. };
  4506. return __assign(__assign({}, subject), { run: run2 });
  4507. };
  4508. var value$1 = function() {
  4509. var subject = singleton(noop);
  4510. var on2 = function(f) {
  4511. return subject.get().each(f);
  4512. };
  4513. return __assign(__assign({}, subject), { on: on2 });
  4514. };
  4515. var filter = always;
  4516. var bind = function(element2, event, handler) {
  4517. return bind$2(element2, event, filter, handler);
  4518. };
  4519. var capture = function(element2, event, handler) {
  4520. return capture$1(element2, event, filter, handler);
  4521. };
  4522. var fromRawEvent = fromRawEvent$1;
  4523. var properties = [
  4524. "top",
  4525. "bottom",
  4526. "right",
  4527. "left"
  4528. ];
  4529. var timerAttr = "data-alloy-transition-timer";
  4530. var isTransitioning$1 = function(element2, transition) {
  4531. return hasAll(element2, transition.classes);
  4532. };
  4533. var shouldApplyTransitionCss = function(transition, decision, lastPlacement) {
  4534. return lastPlacement.exists(function(placer) {
  4535. var mode = transition.mode;
  4536. return mode === "all" ? true : placer[mode] !== decision[mode];
  4537. });
  4538. };
  4539. var hasChanges = function(position2, intermediate) {
  4540. var round2 = function(value2) {
  4541. return parseFloat(value2).toFixed(3);
  4542. };
  4543. return find$4(intermediate, function(value2, key) {
  4544. var newValue = position2[key].map(round2);
  4545. var val = value2.map(round2);
  4546. return !equals(newValue, val);
  4547. }).isSome();
  4548. };
  4549. var getTransitionDuration = function(element2) {
  4550. var get2 = function(name2) {
  4551. var style = get$c(element2, name2);
  4552. var times = isString(style) ? style.split(/\s*,\s*/) : [];
  4553. return filter$2(times, isNotEmpty);
  4554. };
  4555. var parse2 = function(value2) {
  4556. if (isString(value2) && /^[\d.]+/.test(value2)) {
  4557. var num = parseFloat(value2);
  4558. return endsWith(value2, "ms") ? num : num * 1e3;
  4559. } else {
  4560. return 0;
  4561. }
  4562. };
  4563. var delay = get2("transition-delay");
  4564. var duration = get2("transition-duration");
  4565. return foldl(duration, function(acc, dur, i) {
  4566. var time = parse2(delay[i]) + parse2(dur);
  4567. return Math.max(acc, time);
  4568. }, 0);
  4569. };
  4570. var setupTransitionListeners = function(element2, transition) {
  4571. var transitionEnd = unbindable();
  4572. var transitionCancel = unbindable();
  4573. var timer;
  4574. var isSourceTransition = function(e) {
  4575. var _a2;
  4576. var pseudoElement = (_a2 = e.raw.pseudoElement) !== null && _a2 !== void 0 ? _a2 : "";
  4577. return eq(e.target, element2) && isEmpty(pseudoElement) && contains$2(properties, e.raw.propertyName);
  4578. };
  4579. var transitionDone = function(e) {
  4580. if (isNullable(e) || isSourceTransition(e)) {
  4581. transitionEnd.clear();
  4582. transitionCancel.clear();
  4583. var type2 = e === null || e === void 0 ? void 0 : e.raw.type;
  4584. if (isNullable(type2) || type2 === transitionend()) {
  4585. clearTimeout(timer);
  4586. remove$7(element2, timerAttr);
  4587. remove$1(element2, transition.classes);
  4588. }
  4589. }
  4590. };
  4591. var transitionStarted = function() {
  4592. transitionEnd.set(bind(element2, transitionend(), transitionDone));
  4593. transitionCancel.set(bind(element2, transitioncancel(), transitionDone));
  4594. };
  4595. if ("ontransitionstart" in element2.dom) {
  4596. var transitionStart_1 = bind(element2, transitionstart(), function(e) {
  4597. if (isSourceTransition(e)) {
  4598. transitionStart_1.unbind();
  4599. transitionStarted();
  4600. }
  4601. });
  4602. } else {
  4603. transitionStarted();
  4604. }
  4605. var duration = getTransitionDuration(element2);
  4606. requestAnimationFrame(function() {
  4607. timer = setTimeout(transitionDone, duration + 17);
  4608. set$8(element2, timerAttr, timer);
  4609. });
  4610. };
  4611. var startTransitioning = function(element2, transition) {
  4612. add$1(element2, transition.classes);
  4613. getOpt(element2, timerAttr).each(function(timerId) {
  4614. clearTimeout(parseInt(timerId, 10));
  4615. remove$7(element2, timerAttr);
  4616. });
  4617. setupTransitionListeners(element2, transition);
  4618. };
  4619. var applyTransitionCss = function(element2, origin, position2, transition, decision, lastPlacement) {
  4620. var shouldTransition = shouldApplyTransitionCss(transition, decision, lastPlacement);
  4621. if (shouldTransition || isTransitioning$1(element2, transition)) {
  4622. set$7(element2, "position", position2.position);
  4623. var rect2 = toBox(origin, element2);
  4624. var intermediatePosition_1 = reposition(origin, __assign(__assign({}, decision), { rect: rect2 }));
  4625. var intermediateCssOptions = mapToObject(properties, function(prop) {
  4626. return intermediatePosition_1[prop];
  4627. });
  4628. if (hasChanges(position2, intermediateCssOptions)) {
  4629. setOptions(element2, intermediateCssOptions);
  4630. if (shouldTransition) {
  4631. startTransitioning(element2, transition);
  4632. }
  4633. reflow(element2);
  4634. }
  4635. } else {
  4636. remove$1(element2, transition.classes);
  4637. }
  4638. };
  4639. var elementSize = function(p) {
  4640. return {
  4641. width: getOuter$1(p),
  4642. height: getOuter$2(p)
  4643. };
  4644. };
  4645. var layout = function(anchorBox, element2, bubbles, options) {
  4646. remove$6(element2, "max-height");
  4647. remove$6(element2, "max-width");
  4648. var elementBox = elementSize(element2);
  4649. return attempts(element2, options.preference, anchorBox, elementBox, bubbles, options.bounds);
  4650. };
  4651. var setClasses = function(element2, decision) {
  4652. var classInfo = decision.classes;
  4653. remove$1(element2, classInfo.off);
  4654. add$1(element2, classInfo.on);
  4655. };
  4656. var setHeight = function(element2, decision, options) {
  4657. var maxHeightFunction = options.maxHeightFunction;
  4658. maxHeightFunction(element2, decision.maxHeight);
  4659. };
  4660. var setWidth = function(element2, decision, options) {
  4661. var maxWidthFunction = options.maxWidthFunction;
  4662. maxWidthFunction(element2, decision.maxWidth);
  4663. };
  4664. var position$2 = function(element2, decision, options) {
  4665. var positionCss = reposition(options.origin, decision);
  4666. options.transition.each(function(transition) {
  4667. applyTransitionCss(element2, options.origin, positionCss, transition, decision, options.lastPlacement);
  4668. });
  4669. applyPositionCss(element2, positionCss);
  4670. };
  4671. var setPlacement = function(element2, decision) {
  4672. setPlacement$1(element2, decision.placement);
  4673. };
  4674. var setMaxHeight = function(element2, maxHeight) {
  4675. setMax$1(element2, Math.floor(maxHeight));
  4676. };
  4677. var anchored = constant$1(function(element2, available) {
  4678. setMaxHeight(element2, available);
  4679. setAll(element2, {
  4680. "overflow-x": "hidden",
  4681. "overflow-y": "auto"
  4682. });
  4683. });
  4684. var expandable$1 = constant$1(function(element2, available) {
  4685. setMaxHeight(element2, available);
  4686. });
  4687. var defaultOr = function(options, key, dephault) {
  4688. return options[key] === void 0 ? dephault : options[key];
  4689. };
  4690. var simple = function(anchor2, element2, bubble, layouts2, lastPlacement, getBounds2, overrideOptions, transition) {
  4691. var maxHeightFunction = defaultOr(overrideOptions, "maxHeightFunction", anchored());
  4692. var maxWidthFunction = defaultOr(overrideOptions, "maxWidthFunction", noop);
  4693. var anchorBox = anchor2.anchorBox;
  4694. var origin = anchor2.origin;
  4695. var options = {
  4696. bounds: viewport(origin, getBounds2),
  4697. origin,
  4698. preference: layouts2,
  4699. maxHeightFunction,
  4700. maxWidthFunction,
  4701. lastPlacement,
  4702. transition
  4703. };
  4704. return go(anchorBox, element2, bubble, options);
  4705. };
  4706. var go = function(anchorBox, element2, bubble, options) {
  4707. var decision = layout(anchorBox, element2, bubble, options);
  4708. position$2(element2, decision, options);
  4709. setPlacement(element2, decision);
  4710. setClasses(element2, decision);
  4711. setHeight(element2, decision, options);
  4712. setWidth(element2, decision, options);
  4713. return {
  4714. layout: decision.layout,
  4715. placement: decision.placement
  4716. };
  4717. };
  4718. var allAlignments = [
  4719. "valignCentre",
  4720. "alignLeft",
  4721. "alignRight",
  4722. "alignCentre",
  4723. "top",
  4724. "bottom",
  4725. "left",
  4726. "right",
  4727. "inset"
  4728. ];
  4729. var nu$5 = function(xOffset, yOffset, classes2, insetModifier) {
  4730. if (insetModifier === void 0) {
  4731. insetModifier = 1;
  4732. }
  4733. var insetXOffset = xOffset * insetModifier;
  4734. var insetYOffset = yOffset * insetModifier;
  4735. var getClasses2 = function(prop) {
  4736. return get$e(classes2, prop).getOr([]);
  4737. };
  4738. var make2 = function(xDelta, yDelta, alignmentsOn) {
  4739. var alignmentsOff = difference(allAlignments, alignmentsOn);
  4740. return {
  4741. offset: SugarPosition(xDelta, yDelta),
  4742. classesOn: bind$3(alignmentsOn, getClasses2),
  4743. classesOff: bind$3(alignmentsOff, getClasses2)
  4744. };
  4745. };
  4746. return {
  4747. southeast: function() {
  4748. return make2(-xOffset, yOffset, [
  4749. "top",
  4750. "alignLeft"
  4751. ]);
  4752. },
  4753. southwest: function() {
  4754. return make2(xOffset, yOffset, [
  4755. "top",
  4756. "alignRight"
  4757. ]);
  4758. },
  4759. south: function() {
  4760. return make2(-xOffset / 2, yOffset, [
  4761. "top",
  4762. "alignCentre"
  4763. ]);
  4764. },
  4765. northeast: function() {
  4766. return make2(-xOffset, -yOffset, [
  4767. "bottom",
  4768. "alignLeft"
  4769. ]);
  4770. },
  4771. northwest: function() {
  4772. return make2(xOffset, -yOffset, [
  4773. "bottom",
  4774. "alignRight"
  4775. ]);
  4776. },
  4777. north: function() {
  4778. return make2(-xOffset / 2, -yOffset, [
  4779. "bottom",
  4780. "alignCentre"
  4781. ]);
  4782. },
  4783. east: function() {
  4784. return make2(xOffset, -yOffset / 2, [
  4785. "valignCentre",
  4786. "left"
  4787. ]);
  4788. },
  4789. west: function() {
  4790. return make2(-xOffset, -yOffset / 2, [
  4791. "valignCentre",
  4792. "right"
  4793. ]);
  4794. },
  4795. insetNortheast: function() {
  4796. return make2(insetXOffset, insetYOffset, [
  4797. "top",
  4798. "alignLeft",
  4799. "inset"
  4800. ]);
  4801. },
  4802. insetNorthwest: function() {
  4803. return make2(-insetXOffset, insetYOffset, [
  4804. "top",
  4805. "alignRight",
  4806. "inset"
  4807. ]);
  4808. },
  4809. insetNorth: function() {
  4810. return make2(-insetXOffset / 2, insetYOffset, [
  4811. "top",
  4812. "alignCentre",
  4813. "inset"
  4814. ]);
  4815. },
  4816. insetSoutheast: function() {
  4817. return make2(insetXOffset, -insetYOffset, [
  4818. "bottom",
  4819. "alignLeft",
  4820. "inset"
  4821. ]);
  4822. },
  4823. insetSouthwest: function() {
  4824. return make2(-insetXOffset, -insetYOffset, [
  4825. "bottom",
  4826. "alignRight",
  4827. "inset"
  4828. ]);
  4829. },
  4830. insetSouth: function() {
  4831. return make2(-insetXOffset / 2, -insetYOffset, [
  4832. "bottom",
  4833. "alignCentre",
  4834. "inset"
  4835. ]);
  4836. },
  4837. insetEast: function() {
  4838. return make2(-insetXOffset, -insetYOffset / 2, [
  4839. "valignCentre",
  4840. "right",
  4841. "inset"
  4842. ]);
  4843. },
  4844. insetWest: function() {
  4845. return make2(insetXOffset, -insetYOffset / 2, [
  4846. "valignCentre",
  4847. "left",
  4848. "inset"
  4849. ]);
  4850. }
  4851. };
  4852. };
  4853. var fallback = function() {
  4854. return nu$5(0, 0, {});
  4855. };
  4856. var nu$4 = identity$1;
  4857. var onDirection = function(isLtr, isRtl) {
  4858. return function(element2) {
  4859. return getDirection(element2) === "rtl" ? isRtl : isLtr;
  4860. };
  4861. };
  4862. var getDirection = function(element2) {
  4863. return get$c(element2, "direction") === "rtl" ? "rtl" : "ltr";
  4864. };
  4865. var AttributeValue;
  4866. (function(AttributeValue2) {
  4867. AttributeValue2["TopToBottom"] = "toptobottom";
  4868. AttributeValue2["BottomToTop"] = "bottomtotop";
  4869. })(AttributeValue || (AttributeValue = {}));
  4870. var Attribute = "data-alloy-vertical-dir";
  4871. var isBottomToTopDir = function(el) {
  4872. return closest$2(el, function(current) {
  4873. return isElement$2(current) && get$d(current, "data-alloy-vertical-dir") === AttributeValue.BottomToTop;
  4874. });
  4875. };
  4876. var schema$y = function() {
  4877. return optionObjOf("layouts", [
  4878. required$1("onLtr"),
  4879. required$1("onRtl"),
  4880. option("onBottomLtr"),
  4881. option("onBottomRtl")
  4882. ]);
  4883. };
  4884. var get$4 = function(elem, info, defaultLtr, defaultRtl, defaultBottomLtr, defaultBottomRtl, dirElement) {
  4885. var isBottomToTop = dirElement.map(isBottomToTopDir).getOr(false);
  4886. var customLtr = info.layouts.map(function(ls) {
  4887. return ls.onLtr(elem);
  4888. });
  4889. var customRtl = info.layouts.map(function(ls) {
  4890. return ls.onRtl(elem);
  4891. });
  4892. var ltr = isBottomToTop ? info.layouts.bind(function(ls) {
  4893. return ls.onBottomLtr.map(function(f2) {
  4894. return f2(elem);
  4895. });
  4896. }).or(customLtr).getOr(defaultBottomLtr) : customLtr.getOr(defaultLtr);
  4897. var rtl = isBottomToTop ? info.layouts.bind(function(ls) {
  4898. return ls.onBottomRtl.map(function(f2) {
  4899. return f2(elem);
  4900. });
  4901. }).or(customRtl).getOr(defaultBottomRtl) : customRtl.getOr(defaultRtl);
  4902. var f = onDirection(ltr, rtl);
  4903. return f(elem);
  4904. };
  4905. var placement$4 = function(component, anchorInfo, origin) {
  4906. var hotspot = anchorInfo.hotspot;
  4907. var anchorBox = toBox(origin, hotspot.element);
  4908. var layouts2 = get$4(component.element, anchorInfo, belowOrAbove(), belowOrAboveRtl(), aboveOrBelow(), aboveOrBelowRtl(), Optional.some(anchorInfo.hotspot.element));
  4909. return Optional.some(nu$4({
  4910. anchorBox,
  4911. bubble: anchorInfo.bubble.getOr(fallback()),
  4912. overrides: anchorInfo.overrides,
  4913. layouts: layouts2,
  4914. placer: Optional.none()
  4915. }));
  4916. };
  4917. var HotspotAnchor = [
  4918. required$1("hotspot"),
  4919. option("bubble"),
  4920. defaulted("overrides", {}),
  4921. schema$y(),
  4922. output$1("placement", placement$4)
  4923. ];
  4924. var placement$3 = function(component, anchorInfo, origin) {
  4925. var pos = translate$2(origin, anchorInfo.x, anchorInfo.y);
  4926. var anchorBox = bounds(pos.left, pos.top, anchorInfo.width, anchorInfo.height);
  4927. var layouts2 = get$4(component.element, anchorInfo, all$1(), allRtl$1(), all$1(), allRtl$1(), Optional.none());
  4928. return Optional.some(nu$4({
  4929. anchorBox,
  4930. bubble: anchorInfo.bubble,
  4931. overrides: anchorInfo.overrides,
  4932. layouts: layouts2,
  4933. placer: Optional.none()
  4934. }));
  4935. };
  4936. var MakeshiftAnchor = [
  4937. required$1("x"),
  4938. required$1("y"),
  4939. defaulted("height", 0),
  4940. defaulted("width", 0),
  4941. defaulted("bubble", fallback()),
  4942. defaulted("overrides", {}),
  4943. schema$y(),
  4944. output$1("placement", placement$3)
  4945. ];
  4946. var adt$7 = Adt.generate([
  4947. { screen: ["point"] },
  4948. {
  4949. absolute: [
  4950. "point",
  4951. "scrollLeft",
  4952. "scrollTop"
  4953. ]
  4954. }
  4955. ]);
  4956. var toFixed = function(pos) {
  4957. return pos.fold(identity$1, function(point2, scrollLeft, scrollTop) {
  4958. return point2.translate(-scrollLeft, -scrollTop);
  4959. });
  4960. };
  4961. var toAbsolute = function(pos) {
  4962. return pos.fold(identity$1, identity$1);
  4963. };
  4964. var sum = function(points) {
  4965. return foldl(points, function(b2, a) {
  4966. return b2.translate(a.left, a.top);
  4967. }, SugarPosition(0, 0));
  4968. };
  4969. var sumAsFixed = function(positions) {
  4970. var points = map$2(positions, toFixed);
  4971. return sum(points);
  4972. };
  4973. var sumAsAbsolute = function(positions) {
  4974. var points = map$2(positions, toAbsolute);
  4975. return sum(points);
  4976. };
  4977. var screen = adt$7.screen;
  4978. var absolute$1 = adt$7.absolute;
  4979. var getOffset = function(component, origin, anchorInfo) {
  4980. var win2 = defaultView(anchorInfo.root).dom;
  4981. var hasSameOwner = function(frame) {
  4982. var frameOwner = owner$4(frame);
  4983. var compOwner = owner$4(component.element);
  4984. return eq(frameOwner, compOwner);
  4985. };
  4986. return Optional.from(win2.frameElement).map(SugarElement.fromDom).filter(hasSameOwner).map(absolute$3);
  4987. };
  4988. var getRootPoint = function(component, origin, anchorInfo) {
  4989. var doc = owner$4(component.element);
  4990. var outerScroll = get$9(doc);
  4991. var offset2 = getOffset(component, origin, anchorInfo).getOr(outerScroll);
  4992. return absolute$1(offset2, outerScroll.left, outerScroll.top);
  4993. };
  4994. var getBox = function(left2, top2, width2, height2) {
  4995. var point2 = screen(SugarPosition(left2, top2));
  4996. return Optional.some(pointed(point2, width2, height2));
  4997. };
  4998. var calcNewAnchor = function(optBox, rootPoint, anchorInfo, origin, elem) {
  4999. return optBox.map(function(box2) {
  5000. var points = [
  5001. rootPoint,
  5002. box2.point
  5003. ];
  5004. var topLeft = cata$1(origin, function() {
  5005. return sumAsAbsolute(points);
  5006. }, function() {
  5007. return sumAsAbsolute(points);
  5008. }, function() {
  5009. return sumAsFixed(points);
  5010. });
  5011. var anchorBox = rect(topLeft.left, topLeft.top, box2.width, box2.height);
  5012. var layoutsLtr = anchorInfo.showAbove ? aboveOrBelow() : belowOrAbove();
  5013. var layoutsRtl = anchorInfo.showAbove ? aboveOrBelowRtl() : belowOrAboveRtl();
  5014. var layouts2 = get$4(elem, anchorInfo, layoutsLtr, layoutsRtl, layoutsLtr, layoutsRtl, Optional.none());
  5015. return nu$4({
  5016. anchorBox,
  5017. bubble: anchorInfo.bubble.getOr(fallback()),
  5018. overrides: anchorInfo.overrides,
  5019. layouts: layouts2,
  5020. placer: Optional.none()
  5021. });
  5022. });
  5023. };
  5024. var placement$2 = function(component, anchorInfo, origin) {
  5025. var rootPoint = getRootPoint(component, origin, anchorInfo);
  5026. return anchorInfo.node.filter(inBody).bind(function(target) {
  5027. var rect2 = target.dom.getBoundingClientRect();
  5028. var nodeBox = getBox(rect2.left, rect2.top, rect2.width, rect2.height);
  5029. var elem = anchorInfo.node.getOr(component.element);
  5030. return calcNewAnchor(nodeBox, rootPoint, anchorInfo, origin, elem);
  5031. });
  5032. };
  5033. var NodeAnchor = [
  5034. required$1("node"),
  5035. required$1("root"),
  5036. option("bubble"),
  5037. schema$y(),
  5038. defaulted("overrides", {}),
  5039. defaulted("showAbove", false),
  5040. output$1("placement", placement$2)
  5041. ];
  5042. var zeroWidth = "\uFEFF";
  5043. var nbsp = "\xA0";
  5044. var create$6 = function(start, soffset, finish, foffset) {
  5045. return {
  5046. start,
  5047. soffset,
  5048. finish,
  5049. foffset
  5050. };
  5051. };
  5052. var SimRange = { create: create$6 };
  5053. var adt$6 = Adt.generate([
  5054. { before: ["element"] },
  5055. {
  5056. on: [
  5057. "element",
  5058. "offset"
  5059. ]
  5060. },
  5061. { after: ["element"] }
  5062. ]);
  5063. var cata = function(subject, onBefore, onOn, onAfter) {
  5064. return subject.fold(onBefore, onOn, onAfter);
  5065. };
  5066. var getStart$1 = function(situ) {
  5067. return situ.fold(identity$1, identity$1, identity$1);
  5068. };
  5069. var before = adt$6.before;
  5070. var on$1 = adt$6.on;
  5071. var after$1 = adt$6.after;
  5072. var Situ = {
  5073. before,
  5074. on: on$1,
  5075. after: after$1,
  5076. cata,
  5077. getStart: getStart$1
  5078. };
  5079. var adt$5 = Adt.generate([
  5080. { domRange: ["rng"] },
  5081. {
  5082. relative: [
  5083. "startSitu",
  5084. "finishSitu"
  5085. ]
  5086. },
  5087. {
  5088. exact: [
  5089. "start",
  5090. "soffset",
  5091. "finish",
  5092. "foffset"
  5093. ]
  5094. }
  5095. ]);
  5096. var exactFromRange = function(simRange) {
  5097. return adt$5.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset);
  5098. };
  5099. var getStart = function(selection) {
  5100. return selection.match({
  5101. domRange: function(rng) {
  5102. return SugarElement.fromDom(rng.startContainer);
  5103. },
  5104. relative: function(startSitu, _finishSitu) {
  5105. return Situ.getStart(startSitu);
  5106. },
  5107. exact: function(start, _soffset, _finish, _foffset) {
  5108. return start;
  5109. }
  5110. });
  5111. };
  5112. var domRange = adt$5.domRange;
  5113. var relative = adt$5.relative;
  5114. var exact = adt$5.exact;
  5115. var getWin = function(selection) {
  5116. var start = getStart(selection);
  5117. return defaultView(start);
  5118. };
  5119. var range$1 = SimRange.create;
  5120. var SimSelection = {
  5121. domRange,
  5122. relative,
  5123. exact,
  5124. exactFromRange,
  5125. getWin,
  5126. range: range$1
  5127. };
  5128. var setStart = function(rng, situ) {
  5129. situ.fold(function(e) {
  5130. rng.setStartBefore(e.dom);
  5131. }, function(e, o) {
  5132. rng.setStart(e.dom, o);
  5133. }, function(e) {
  5134. rng.setStartAfter(e.dom);
  5135. });
  5136. };
  5137. var setFinish = function(rng, situ) {
  5138. situ.fold(function(e) {
  5139. rng.setEndBefore(e.dom);
  5140. }, function(e, o) {
  5141. rng.setEnd(e.dom, o);
  5142. }, function(e) {
  5143. rng.setEndAfter(e.dom);
  5144. });
  5145. };
  5146. var relativeToNative = function(win2, startSitu, finishSitu) {
  5147. var range2 = win2.document.createRange();
  5148. setStart(range2, startSitu);
  5149. setFinish(range2, finishSitu);
  5150. return range2;
  5151. };
  5152. var exactToNative = function(win2, start, soffset, finish, foffset) {
  5153. var rng = win2.document.createRange();
  5154. rng.setStart(start.dom, soffset);
  5155. rng.setEnd(finish.dom, foffset);
  5156. return rng;
  5157. };
  5158. var toRect = function(rect2) {
  5159. return {
  5160. left: rect2.left,
  5161. top: rect2.top,
  5162. right: rect2.right,
  5163. bottom: rect2.bottom,
  5164. width: rect2.width,
  5165. height: rect2.height
  5166. };
  5167. };
  5168. var getFirstRect$1 = function(rng) {
  5169. var rects = rng.getClientRects();
  5170. var rect2 = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
  5171. return rect2.width > 0 || rect2.height > 0 ? Optional.some(rect2).map(toRect) : Optional.none();
  5172. };
  5173. var getBounds$2 = function(rng) {
  5174. var rect2 = rng.getBoundingClientRect();
  5175. return rect2.width > 0 || rect2.height > 0 ? Optional.some(rect2).map(toRect) : Optional.none();
  5176. };
  5177. var adt$4 = Adt.generate([
  5178. {
  5179. ltr: [
  5180. "start",
  5181. "soffset",
  5182. "finish",
  5183. "foffset"
  5184. ]
  5185. },
  5186. {
  5187. rtl: [
  5188. "start",
  5189. "soffset",
  5190. "finish",
  5191. "foffset"
  5192. ]
  5193. }
  5194. ]);
  5195. var fromRange = function(win2, type2, range2) {
  5196. return type2(SugarElement.fromDom(range2.startContainer), range2.startOffset, SugarElement.fromDom(range2.endContainer), range2.endOffset);
  5197. };
  5198. var getRanges = function(win2, selection) {
  5199. return selection.match({
  5200. domRange: function(rng) {
  5201. return {
  5202. ltr: constant$1(rng),
  5203. rtl: Optional.none
  5204. };
  5205. },
  5206. relative: function(startSitu, finishSitu) {
  5207. return {
  5208. ltr: cached(function() {
  5209. return relativeToNative(win2, startSitu, finishSitu);
  5210. }),
  5211. rtl: cached(function() {
  5212. return Optional.some(relativeToNative(win2, finishSitu, startSitu));
  5213. })
  5214. };
  5215. },
  5216. exact: function(start, soffset, finish, foffset) {
  5217. return {
  5218. ltr: cached(function() {
  5219. return exactToNative(win2, start, soffset, finish, foffset);
  5220. }),
  5221. rtl: cached(function() {
  5222. return Optional.some(exactToNative(win2, finish, foffset, start, soffset));
  5223. })
  5224. };
  5225. }
  5226. });
  5227. };
  5228. var doDiagnose = function(win2, ranges) {
  5229. var rng = ranges.ltr();
  5230. if (rng.collapsed) {
  5231. var reversed = ranges.rtl().filter(function(rev) {
  5232. return rev.collapsed === false;
  5233. });
  5234. return reversed.map(function(rev) {
  5235. return adt$4.rtl(SugarElement.fromDom(rev.endContainer), rev.endOffset, SugarElement.fromDom(rev.startContainer), rev.startOffset);
  5236. }).getOrThunk(function() {
  5237. return fromRange(win2, adt$4.ltr, rng);
  5238. });
  5239. } else {
  5240. return fromRange(win2, adt$4.ltr, rng);
  5241. }
  5242. };
  5243. var diagnose = function(win2, selection) {
  5244. var ranges = getRanges(win2, selection);
  5245. return doDiagnose(win2, ranges);
  5246. };
  5247. var asLtrRange = function(win2, selection) {
  5248. var diagnosis = diagnose(win2, selection);
  5249. return diagnosis.match({
  5250. ltr: function(start, soffset, finish, foffset) {
  5251. var rng = win2.document.createRange();
  5252. rng.setStart(start.dom, soffset);
  5253. rng.setEnd(finish.dom, foffset);
  5254. return rng;
  5255. },
  5256. rtl: function(start, soffset, finish, foffset) {
  5257. var rng = win2.document.createRange();
  5258. rng.setStart(finish.dom, foffset);
  5259. rng.setEnd(start.dom, soffset);
  5260. return rng;
  5261. }
  5262. });
  5263. };
  5264. adt$4.ltr;
  5265. adt$4.rtl;
  5266. var NodeValue = function(is2, name2) {
  5267. var get2 = function(element2) {
  5268. if (!is2(element2)) {
  5269. throw new Error("Can only get " + name2 + " value of a " + name2 + " node");
  5270. }
  5271. return getOption2(element2).getOr("");
  5272. };
  5273. var getOption2 = function(element2) {
  5274. return is2(element2) ? Optional.from(element2.dom.nodeValue) : Optional.none();
  5275. };
  5276. var set2 = function(element2, value2) {
  5277. if (!is2(element2)) {
  5278. throw new Error("Can only set raw " + name2 + " value of a " + name2 + " node");
  5279. }
  5280. element2.dom.nodeValue = value2;
  5281. };
  5282. return {
  5283. get: get2,
  5284. getOption: getOption2,
  5285. set: set2
  5286. };
  5287. };
  5288. var api = NodeValue(isText$1, "text");
  5289. var get$3 = function(element2) {
  5290. return api.get(element2);
  5291. };
  5292. var getOption = function(element2) {
  5293. return api.getOption(element2);
  5294. };
  5295. var getEnd = function(element2) {
  5296. return name$2(element2) === "img" ? 1 : getOption(element2).fold(function() {
  5297. return children(element2).length;
  5298. }, function(v) {
  5299. return v.length;
  5300. });
  5301. };
  5302. var isTextNodeWithCursorPosition = function(el) {
  5303. return getOption(el).filter(function(text2) {
  5304. return text2.trim().length !== 0 || text2.indexOf(nbsp) > -1;
  5305. }).isSome();
  5306. };
  5307. var elementsWithCursorPosition = [
  5308. "img",
  5309. "br"
  5310. ];
  5311. var isCursorPosition = function(elem) {
  5312. var hasCursorPosition = isTextNodeWithCursorPosition(elem);
  5313. return hasCursorPosition || contains$2(elementsWithCursorPosition, name$2(elem));
  5314. };
  5315. var last$1 = function(element2) {
  5316. return descendantRtl(element2, isCursorPosition);
  5317. };
  5318. var descendantRtl = function(scope, predicate) {
  5319. var descend = function(element2) {
  5320. var children$1 = children(element2);
  5321. for (var i = children$1.length - 1; i >= 0; i--) {
  5322. var child2 = children$1[i];
  5323. if (predicate(child2)) {
  5324. return Optional.some(child2);
  5325. }
  5326. var res = descend(child2);
  5327. if (res.isSome()) {
  5328. return res;
  5329. }
  5330. }
  5331. return Optional.none();
  5332. };
  5333. return descend(scope);
  5334. };
  5335. var descendants = function(scope, selector) {
  5336. return all$3(selector, scope);
  5337. };
  5338. var makeRange = function(start, soffset, finish, foffset) {
  5339. var doc = owner$4(start);
  5340. var rng = doc.dom.createRange();
  5341. rng.setStart(start.dom, soffset);
  5342. rng.setEnd(finish.dom, foffset);
  5343. return rng;
  5344. };
  5345. var after = function(start, soffset, finish, foffset) {
  5346. var r2 = makeRange(start, soffset, finish, foffset);
  5347. var same = eq(start, finish) && soffset === foffset;
  5348. return r2.collapsed && !same;
  5349. };
  5350. var getNativeSelection = function(win2) {
  5351. return Optional.from(win2.getSelection());
  5352. };
  5353. var readRange = function(selection) {
  5354. if (selection.rangeCount > 0) {
  5355. var firstRng = selection.getRangeAt(0);
  5356. var lastRng = selection.getRangeAt(selection.rangeCount - 1);
  5357. return Optional.some(SimRange.create(SugarElement.fromDom(firstRng.startContainer), firstRng.startOffset, SugarElement.fromDom(lastRng.endContainer), lastRng.endOffset));
  5358. } else {
  5359. return Optional.none();
  5360. }
  5361. };
  5362. var doGetExact = function(selection) {
  5363. if (selection.anchorNode === null || selection.focusNode === null) {
  5364. return readRange(selection);
  5365. } else {
  5366. var anchor2 = SugarElement.fromDom(selection.anchorNode);
  5367. var focus_1 = SugarElement.fromDom(selection.focusNode);
  5368. return after(anchor2, selection.anchorOffset, focus_1, selection.focusOffset) ? Optional.some(SimRange.create(anchor2, selection.anchorOffset, focus_1, selection.focusOffset)) : readRange(selection);
  5369. }
  5370. };
  5371. var getExact = function(win2) {
  5372. return getNativeSelection(win2).filter(function(sel) {
  5373. return sel.rangeCount > 0;
  5374. }).bind(doGetExact);
  5375. };
  5376. var getFirstRect = function(win2, selection) {
  5377. var rng = asLtrRange(win2, selection);
  5378. return getFirstRect$1(rng);
  5379. };
  5380. var getBounds$1 = function(win2, selection) {
  5381. var rng = asLtrRange(win2, selection);
  5382. return getBounds$2(rng);
  5383. };
  5384. var point$1 = function(element2, offset2) {
  5385. return {
  5386. element: element2,
  5387. offset: offset2
  5388. };
  5389. };
  5390. var descendOnce$1 = function(element2, offset2) {
  5391. var children$1 = children(element2);
  5392. if (children$1.length === 0) {
  5393. return point$1(element2, offset2);
  5394. } else if (offset2 < children$1.length) {
  5395. return point$1(children$1[offset2], 0);
  5396. } else {
  5397. var last2 = children$1[children$1.length - 1];
  5398. var len = isText$1(last2) ? get$3(last2).length : children(last2).length;
  5399. return point$1(last2, len);
  5400. }
  5401. };
  5402. var descendOnce = function(element2, offset2) {
  5403. return isText$1(element2) ? point$1(element2, offset2) : descendOnce$1(element2, offset2);
  5404. };
  5405. var getAnchorSelection = function(win2, anchorInfo) {
  5406. var getSelection = anchorInfo.getSelection.getOrThunk(function() {
  5407. return function() {
  5408. return getExact(win2);
  5409. };
  5410. });
  5411. return getSelection().map(function(sel) {
  5412. var modStart = descendOnce(sel.start, sel.soffset);
  5413. var modFinish = descendOnce(sel.finish, sel.foffset);
  5414. return SimSelection.range(modStart.element, modStart.offset, modFinish.element, modFinish.offset);
  5415. });
  5416. };
  5417. var placement$1 = function(component, anchorInfo, origin) {
  5418. var win2 = defaultView(anchorInfo.root).dom;
  5419. var rootPoint = getRootPoint(component, origin, anchorInfo);
  5420. var selectionBox = getAnchorSelection(win2, anchorInfo).bind(function(sel) {
  5421. var optRect = getBounds$1(win2, SimSelection.exactFromRange(sel)).orThunk(function() {
  5422. var x = SugarElement.fromText(zeroWidth);
  5423. before$2(sel.start, x);
  5424. var rect2 = getFirstRect(win2, SimSelection.exact(x, 0, x, 1));
  5425. remove$5(x);
  5426. return rect2;
  5427. });
  5428. return optRect.bind(function(rawRect) {
  5429. return getBox(rawRect.left, rawRect.top, rawRect.width, rawRect.height);
  5430. });
  5431. });
  5432. var targetElement = getAnchorSelection(win2, anchorInfo).bind(function(sel) {
  5433. return isElement$2(sel.start) ? Optional.some(sel.start) : parentNode(sel.start);
  5434. });
  5435. var elem = targetElement.getOr(component.element);
  5436. return calcNewAnchor(selectionBox, rootPoint, anchorInfo, origin, elem);
  5437. };
  5438. var SelectionAnchor = [
  5439. option("getSelection"),
  5440. required$1("root"),
  5441. option("bubble"),
  5442. schema$y(),
  5443. defaulted("overrides", {}),
  5444. defaulted("showAbove", false),
  5445. output$1("placement", placement$1)
  5446. ];
  5447. var labelPrefix$1 = "link-layout";
  5448. var eastX = function(anchor2) {
  5449. return anchor2.x + anchor2.width;
  5450. };
  5451. var westX = function(anchor2, element2) {
  5452. return anchor2.x - element2.width;
  5453. };
  5454. var northY$1 = function(anchor2, element2) {
  5455. return anchor2.y - element2.height + anchor2.height;
  5456. };
  5457. var southY$1 = function(anchor2) {
  5458. return anchor2.y;
  5459. };
  5460. var southeast$1 = function(anchor2, element2, bubbles) {
  5461. return nu$6(eastX(anchor2), southY$1(anchor2), bubbles.southeast(), southeast$3(), "southeast", boundsRestriction(anchor2, {
  5462. left: 0,
  5463. top: 2
  5464. }), labelPrefix$1);
  5465. };
  5466. var southwest$1 = function(anchor2, element2, bubbles) {
  5467. return nu$6(westX(anchor2, element2), southY$1(anchor2), bubbles.southwest(), southwest$3(), "southwest", boundsRestriction(anchor2, {
  5468. right: 1,
  5469. top: 2
  5470. }), labelPrefix$1);
  5471. };
  5472. var northeast$1 = function(anchor2, element2, bubbles) {
  5473. return nu$6(eastX(anchor2), northY$1(anchor2, element2), bubbles.northeast(), northeast$3(), "northeast", boundsRestriction(anchor2, {
  5474. left: 0,
  5475. bottom: 3
  5476. }), labelPrefix$1);
  5477. };
  5478. var northwest$1 = function(anchor2, element2, bubbles) {
  5479. return nu$6(westX(anchor2, element2), northY$1(anchor2, element2), bubbles.northwest(), northwest$3(), "northwest", boundsRestriction(anchor2, {
  5480. right: 1,
  5481. bottom: 3
  5482. }), labelPrefix$1);
  5483. };
  5484. var all = function() {
  5485. return [
  5486. southeast$1,
  5487. southwest$1,
  5488. northeast$1,
  5489. northwest$1
  5490. ];
  5491. };
  5492. var allRtl = function() {
  5493. return [
  5494. southwest$1,
  5495. southeast$1,
  5496. northwest$1,
  5497. northeast$1
  5498. ];
  5499. };
  5500. var placement = function(component, submenuInfo, origin) {
  5501. var anchorBox = toBox(origin, submenuInfo.item.element);
  5502. var layouts2 = get$4(component.element, submenuInfo, all(), allRtl(), all(), allRtl(), Optional.none());
  5503. return Optional.some(nu$4({
  5504. anchorBox,
  5505. bubble: fallback(),
  5506. overrides: submenuInfo.overrides,
  5507. layouts: layouts2,
  5508. placer: Optional.none()
  5509. }));
  5510. };
  5511. var SubmenuAnchor = [
  5512. required$1("item"),
  5513. schema$y(),
  5514. defaulted("overrides", {}),
  5515. output$1("placement", placement)
  5516. ];
  5517. var AnchorSchema = choose$1("type", {
  5518. selection: SelectionAnchor,
  5519. node: NodeAnchor,
  5520. hotspot: HotspotAnchor,
  5521. submenu: SubmenuAnchor,
  5522. makeshift: MakeshiftAnchor
  5523. });
  5524. var TransitionSchema = [
  5525. requiredArrayOf("classes", string),
  5526. defaultedStringEnum("mode", "all", [
  5527. "all",
  5528. "layout",
  5529. "placement"
  5530. ])
  5531. ];
  5532. var PositionSchema = [
  5533. defaulted("useFixed", never),
  5534. option("getBounds")
  5535. ];
  5536. var PlacementSchema = [
  5537. requiredOf("anchor", AnchorSchema),
  5538. optionObjOf("transition", TransitionSchema)
  5539. ];
  5540. var getFixedOrigin = function() {
  5541. var html = document.documentElement;
  5542. return fixed$1(0, 0, html.clientWidth, html.clientHeight);
  5543. };
  5544. var getRelativeOrigin = function(component) {
  5545. var position2 = absolute$3(component.element);
  5546. var bounds2 = component.element.dom.getBoundingClientRect();
  5547. return relative$1(position2.left, position2.top, bounds2.width, bounds2.height);
  5548. };
  5549. var place = function(component, origin, anchoring, getBounds2, placee, lastPlace, transition) {
  5550. var anchor2 = box(anchoring.anchorBox, origin);
  5551. return simple(anchor2, placee.element, anchoring.bubble, anchoring.layouts, lastPlace, getBounds2, anchoring.overrides, transition);
  5552. };
  5553. var position$1 = function(component, posConfig, posState, placee, placementSpec) {
  5554. positionWithin(component, posConfig, posState, placee, placementSpec, Optional.none());
  5555. };
  5556. var positionWithin = function(component, posConfig, posState, placee, placementSpec, boxElement) {
  5557. var boundsBox = boxElement.map(box$1);
  5558. return positionWithinBounds(component, posConfig, posState, placee, placementSpec, boundsBox);
  5559. };
  5560. var positionWithinBounds = function(component, posConfig, posState, placee, placementSpec, bounds2) {
  5561. var placeeDetail = asRawOrDie$1("placement.info", objOf(PlacementSchema), placementSpec);
  5562. var anchorage = placeeDetail.anchor;
  5563. var element2 = placee.element;
  5564. var placeeState = posState.get(placee.uid);
  5565. preserve$1(function() {
  5566. set$7(element2, "position", "fixed");
  5567. var oldVisibility = getRaw(element2, "visibility");
  5568. set$7(element2, "visibility", "hidden");
  5569. var origin = posConfig.useFixed() ? getFixedOrigin() : getRelativeOrigin(component);
  5570. var placer = anchorage.placement;
  5571. var getBounds2 = bounds2.map(constant$1).or(posConfig.getBounds);
  5572. placer(component, anchorage, origin).each(function(anchoring) {
  5573. var doPlace = anchoring.placer.getOr(place);
  5574. var newState = doPlace(component, origin, anchoring, getBounds2, placee, placeeState, placeeDetail.transition);
  5575. posState.set(placee.uid, newState);
  5576. });
  5577. oldVisibility.fold(function() {
  5578. remove$6(element2, "visibility");
  5579. }, function(vis) {
  5580. set$7(element2, "visibility", vis);
  5581. });
  5582. if (getRaw(element2, "left").isNone() && getRaw(element2, "top").isNone() && getRaw(element2, "right").isNone() && getRaw(element2, "bottom").isNone() && is$1(getRaw(element2, "position"), "fixed")) {
  5583. remove$6(element2, "position");
  5584. }
  5585. }, element2);
  5586. };
  5587. var getMode = function(component, pConfig, _pState) {
  5588. return pConfig.useFixed() ? "fixed" : "absolute";
  5589. };
  5590. var reset$1 = function(component, pConfig, posState, placee) {
  5591. var element2 = placee.element;
  5592. each$1([
  5593. "position",
  5594. "left",
  5595. "right",
  5596. "top",
  5597. "bottom"
  5598. ], function(prop) {
  5599. return remove$6(element2, prop);
  5600. });
  5601. reset$2(element2);
  5602. posState.clear(placee.uid);
  5603. };
  5604. var PositionApis = Object.freeze({
  5605. __proto__: null,
  5606. position: position$1,
  5607. positionWithin,
  5608. positionWithinBounds,
  5609. getMode,
  5610. reset: reset$1
  5611. });
  5612. var init$g = function() {
  5613. var state = {};
  5614. var set2 = function(id, data) {
  5615. state[id] = data;
  5616. };
  5617. var get2 = function(id) {
  5618. return get$e(state, id);
  5619. };
  5620. var clear2 = function(id) {
  5621. if (isNonNullable(id)) {
  5622. delete state[id];
  5623. } else {
  5624. state = {};
  5625. }
  5626. };
  5627. return nu$8({
  5628. readState: function() {
  5629. return state;
  5630. },
  5631. clear: clear2,
  5632. set: set2,
  5633. get: get2
  5634. });
  5635. };
  5636. var PositioningState = Object.freeze({
  5637. __proto__: null,
  5638. init: init$g
  5639. });
  5640. var Positioning = create$7({
  5641. fields: PositionSchema,
  5642. name: "positioning",
  5643. active: ActivePosition,
  5644. apis: PositionApis,
  5645. state: PositioningState
  5646. });
  5647. var fireDetaching = function(component) {
  5648. emit(component, detachedFromDom());
  5649. var children2 = component.components();
  5650. each$1(children2, fireDetaching);
  5651. };
  5652. var fireAttaching = function(component) {
  5653. var children2 = component.components();
  5654. each$1(children2, fireAttaching);
  5655. emit(component, attachedToDom());
  5656. };
  5657. var attach$1 = function(parent2, child2) {
  5658. append$2(parent2.element, child2.element);
  5659. };
  5660. var detachChildren$1 = function(component) {
  5661. each$1(component.components(), function(childComp) {
  5662. return remove$5(childComp.element);
  5663. });
  5664. empty(component.element);
  5665. component.syncComponents();
  5666. };
  5667. var replaceChildren = function(component, newChildren) {
  5668. var subs2 = component.components();
  5669. detachChildren$1(component);
  5670. var deleted = difference(subs2, newChildren);
  5671. each$1(deleted, function(comp) {
  5672. fireDetaching(comp);
  5673. component.getSystem().removeFromWorld(comp);
  5674. });
  5675. each$1(newChildren, function(childComp) {
  5676. if (!childComp.getSystem().isConnected()) {
  5677. component.getSystem().addToWorld(childComp);
  5678. attach$1(component, childComp);
  5679. if (inBody(component.element)) {
  5680. fireAttaching(childComp);
  5681. }
  5682. } else {
  5683. attach$1(component, childComp);
  5684. }
  5685. component.syncComponents();
  5686. });
  5687. };
  5688. var attach = function(parent2, child2) {
  5689. attachWith(parent2, child2, append$2);
  5690. };
  5691. var attachWith = function(parent2, child2, insertion) {
  5692. parent2.getSystem().addToWorld(child2);
  5693. insertion(parent2.element, child2.element);
  5694. if (inBody(parent2.element)) {
  5695. fireAttaching(child2);
  5696. }
  5697. parent2.syncComponents();
  5698. };
  5699. var doDetach = function(component) {
  5700. fireDetaching(component);
  5701. remove$5(component.element);
  5702. component.getSystem().removeFromWorld(component);
  5703. };
  5704. var detach = function(component) {
  5705. var parent$1 = parent(component.element).bind(function(p) {
  5706. return component.getSystem().getByDom(p).toOptional();
  5707. });
  5708. doDetach(component);
  5709. parent$1.each(function(p) {
  5710. p.syncComponents();
  5711. });
  5712. };
  5713. var detachChildren = function(component) {
  5714. var subs2 = component.components();
  5715. each$1(subs2, doDetach);
  5716. empty(component.element);
  5717. component.syncComponents();
  5718. };
  5719. var attachSystem = function(element2, guiSystem) {
  5720. attachSystemWith(element2, guiSystem, append$2);
  5721. };
  5722. var attachSystemAfter = function(element2, guiSystem) {
  5723. attachSystemWith(element2, guiSystem, after$2);
  5724. };
  5725. var attachSystemWith = function(element2, guiSystem, inserter) {
  5726. inserter(element2, guiSystem.element);
  5727. var children$1 = children(guiSystem.element);
  5728. each$1(children$1, function(child2) {
  5729. guiSystem.getByDom(child2).each(fireAttaching);
  5730. });
  5731. };
  5732. var detachSystem = function(guiSystem) {
  5733. var children$1 = children(guiSystem.element);
  5734. each$1(children$1, function(child2) {
  5735. guiSystem.getByDom(child2).each(fireDetaching);
  5736. });
  5737. remove$5(guiSystem.element);
  5738. };
  5739. var rebuild = function(sandbox, sConfig, sState, data) {
  5740. sState.get().each(function(_data) {
  5741. detachChildren(sandbox);
  5742. });
  5743. var point2 = sConfig.getAttachPoint(sandbox);
  5744. attach(point2, sandbox);
  5745. var built = sandbox.getSystem().build(data);
  5746. attach(sandbox, built);
  5747. sState.set(built);
  5748. return built;
  5749. };
  5750. var open$1 = function(sandbox, sConfig, sState, data) {
  5751. var newState = rebuild(sandbox, sConfig, sState, data);
  5752. sConfig.onOpen(sandbox, newState);
  5753. return newState;
  5754. };
  5755. var setContent = function(sandbox, sConfig, sState, data) {
  5756. return sState.get().map(function() {
  5757. return rebuild(sandbox, sConfig, sState, data);
  5758. });
  5759. };
  5760. var openWhileCloaked = function(sandbox, sConfig, sState, data, transaction) {
  5761. cloak(sandbox, sConfig);
  5762. open$1(sandbox, sConfig, sState, data);
  5763. transaction();
  5764. decloak(sandbox, sConfig);
  5765. };
  5766. var close$1 = function(sandbox, sConfig, sState) {
  5767. sState.get().each(function(data) {
  5768. detachChildren(sandbox);
  5769. detach(sandbox);
  5770. sConfig.onClose(sandbox, data);
  5771. sState.clear();
  5772. });
  5773. };
  5774. var isOpen$1 = function(_sandbox, _sConfig, sState) {
  5775. return sState.isOpen();
  5776. };
  5777. var isPartOf = function(sandbox, sConfig, sState, queryElem) {
  5778. return isOpen$1(sandbox, sConfig, sState) && sState.get().exists(function(data) {
  5779. return sConfig.isPartOf(sandbox, data, queryElem);
  5780. });
  5781. };
  5782. var getState$2 = function(_sandbox, _sConfig, sState) {
  5783. return sState.get();
  5784. };
  5785. var store = function(sandbox, cssKey, attr, newValue) {
  5786. getRaw(sandbox.element, cssKey).fold(function() {
  5787. remove$7(sandbox.element, attr);
  5788. }, function(v) {
  5789. set$8(sandbox.element, attr, v);
  5790. });
  5791. set$7(sandbox.element, cssKey, newValue);
  5792. };
  5793. var restore = function(sandbox, cssKey, attr) {
  5794. getOpt(sandbox.element, attr).fold(function() {
  5795. return remove$6(sandbox.element, cssKey);
  5796. }, function(oldValue) {
  5797. return set$7(sandbox.element, cssKey, oldValue);
  5798. });
  5799. };
  5800. var cloak = function(sandbox, sConfig, _sState) {
  5801. var sink = sConfig.getAttachPoint(sandbox);
  5802. set$7(sandbox.element, "position", Positioning.getMode(sink));
  5803. store(sandbox, "visibility", sConfig.cloakVisibilityAttr, "hidden");
  5804. };
  5805. var hasPosition = function(element2) {
  5806. return exists([
  5807. "top",
  5808. "left",
  5809. "right",
  5810. "bottom"
  5811. ], function(pos) {
  5812. return getRaw(element2, pos).isSome();
  5813. });
  5814. };
  5815. var decloak = function(sandbox, sConfig, _sState) {
  5816. if (!hasPosition(sandbox.element)) {
  5817. remove$6(sandbox.element, "position");
  5818. }
  5819. restore(sandbox, "visibility", sConfig.cloakVisibilityAttr);
  5820. };
  5821. var SandboxApis = Object.freeze({
  5822. __proto__: null,
  5823. cloak,
  5824. decloak,
  5825. open: open$1,
  5826. openWhileCloaked,
  5827. close: close$1,
  5828. isOpen: isOpen$1,
  5829. isPartOf,
  5830. getState: getState$2,
  5831. setContent
  5832. });
  5833. var events$g = function(sandboxConfig, sandboxState) {
  5834. return derive$2([run$1(sandboxClose(), function(sandbox, _simulatedEvent) {
  5835. close$1(sandbox, sandboxConfig, sandboxState);
  5836. })]);
  5837. };
  5838. var ActiveSandbox = Object.freeze({
  5839. __proto__: null,
  5840. events: events$g
  5841. });
  5842. var SandboxSchema = [
  5843. onHandler("onOpen"),
  5844. onHandler("onClose"),
  5845. required$1("isPartOf"),
  5846. required$1("getAttachPoint"),
  5847. defaulted("cloakVisibilityAttr", "data-precloak-visibility")
  5848. ];
  5849. var init$f = function() {
  5850. var contents2 = value$1();
  5851. var readState = constant$1("not-implemented");
  5852. return nu$8({
  5853. readState,
  5854. isOpen: contents2.isSet,
  5855. clear: contents2.clear,
  5856. set: contents2.set,
  5857. get: contents2.get
  5858. });
  5859. };
  5860. var SandboxState = Object.freeze({
  5861. __proto__: null,
  5862. init: init$f
  5863. });
  5864. var Sandboxing = create$7({
  5865. fields: SandboxSchema,
  5866. name: "sandboxing",
  5867. active: ActiveSandbox,
  5868. apis: SandboxApis,
  5869. state: SandboxState
  5870. });
  5871. var dismissPopups = constant$1("dismiss.popups");
  5872. var repositionPopups = constant$1("reposition.popups");
  5873. var mouseReleased = constant$1("mouse.released");
  5874. var schema$x = objOfOnly([
  5875. defaulted("isExtraPart", never),
  5876. optionObjOf("fireEventInstead", [defaulted("event", dismissRequested())])
  5877. ]);
  5878. var receivingChannel$1 = function(rawSpec) {
  5879. var _a2;
  5880. var detail = asRawOrDie$1("Dismissal", schema$x, rawSpec);
  5881. return _a2 = {}, _a2[dismissPopups()] = {
  5882. schema: objOfOnly([required$1("target")]),
  5883. onReceive: function(sandbox, data) {
  5884. if (Sandboxing.isOpen(sandbox)) {
  5885. var isPart = Sandboxing.isPartOf(sandbox, data.target) || detail.isExtraPart(sandbox, data.target);
  5886. if (!isPart) {
  5887. detail.fireEventInstead.fold(function() {
  5888. return Sandboxing.close(sandbox);
  5889. }, function(fe) {
  5890. return emit(sandbox, fe.event);
  5891. });
  5892. }
  5893. }
  5894. }
  5895. }, _a2;
  5896. };
  5897. var schema$w = objOfOnly([
  5898. optionObjOf("fireEventInstead", [defaulted("event", repositionRequested())]),
  5899. requiredFunction("doReposition")
  5900. ]);
  5901. var receivingChannel = function(rawSpec) {
  5902. var _a2;
  5903. var detail = asRawOrDie$1("Reposition", schema$w, rawSpec);
  5904. return _a2 = {}, _a2[repositionPopups()] = {
  5905. onReceive: function(sandbox) {
  5906. if (Sandboxing.isOpen(sandbox)) {
  5907. detail.fireEventInstead.fold(function() {
  5908. return detail.doReposition(sandbox);
  5909. }, function(fe) {
  5910. return emit(sandbox, fe.event);
  5911. });
  5912. }
  5913. }
  5914. }, _a2;
  5915. };
  5916. var onLoad$5 = function(component, repConfig, repState) {
  5917. repConfig.store.manager.onLoad(component, repConfig, repState);
  5918. };
  5919. var onUnload$2 = function(component, repConfig, repState) {
  5920. repConfig.store.manager.onUnload(component, repConfig, repState);
  5921. };
  5922. var setValue$3 = function(component, repConfig, repState, data) {
  5923. repConfig.store.manager.setValue(component, repConfig, repState, data);
  5924. };
  5925. var getValue$3 = function(component, repConfig, repState) {
  5926. return repConfig.store.manager.getValue(component, repConfig, repState);
  5927. };
  5928. var getState$1 = function(component, repConfig, repState) {
  5929. return repState;
  5930. };
  5931. var RepresentApis = Object.freeze({
  5932. __proto__: null,
  5933. onLoad: onLoad$5,
  5934. onUnload: onUnload$2,
  5935. setValue: setValue$3,
  5936. getValue: getValue$3,
  5937. getState: getState$1
  5938. });
  5939. var events$f = function(repConfig, repState) {
  5940. var es = repConfig.resetOnDom ? [
  5941. runOnAttached(function(comp, _se) {
  5942. onLoad$5(comp, repConfig, repState);
  5943. }),
  5944. runOnDetached(function(comp, _se) {
  5945. onUnload$2(comp, repConfig, repState);
  5946. })
  5947. ] : [loadEvent(repConfig, repState, onLoad$5)];
  5948. return derive$2(es);
  5949. };
  5950. var ActiveRepresenting = Object.freeze({
  5951. __proto__: null,
  5952. events: events$f
  5953. });
  5954. var memory$1 = function() {
  5955. var data = Cell(null);
  5956. var readState = function() {
  5957. return {
  5958. mode: "memory",
  5959. value: data.get()
  5960. };
  5961. };
  5962. var isNotSet = function() {
  5963. return data.get() === null;
  5964. };
  5965. var clear2 = function() {
  5966. data.set(null);
  5967. };
  5968. return nu$8({
  5969. set: data.set,
  5970. get: data.get,
  5971. isNotSet,
  5972. clear: clear2,
  5973. readState
  5974. });
  5975. };
  5976. var manual = function() {
  5977. var readState = noop;
  5978. return nu$8({ readState });
  5979. };
  5980. var dataset = function() {
  5981. var dataByValue = Cell({});
  5982. var dataByText = Cell({});
  5983. var readState = function() {
  5984. return {
  5985. mode: "dataset",
  5986. dataByValue: dataByValue.get(),
  5987. dataByText: dataByText.get()
  5988. };
  5989. };
  5990. var clear2 = function() {
  5991. dataByValue.set({});
  5992. dataByText.set({});
  5993. };
  5994. var lookup2 = function(itemString) {
  5995. return get$e(dataByValue.get(), itemString).orThunk(function() {
  5996. return get$e(dataByText.get(), itemString);
  5997. });
  5998. };
  5999. var update = function(items) {
  6000. var currentDataByValue = dataByValue.get();
  6001. var currentDataByText = dataByText.get();
  6002. var newDataByValue = {};
  6003. var newDataByText = {};
  6004. each$1(items, function(item2) {
  6005. newDataByValue[item2.value] = item2;
  6006. get$e(item2, "meta").each(function(meta) {
  6007. get$e(meta, "text").each(function(text2) {
  6008. newDataByText[text2] = item2;
  6009. });
  6010. });
  6011. });
  6012. dataByValue.set(__assign(__assign({}, currentDataByValue), newDataByValue));
  6013. dataByText.set(__assign(__assign({}, currentDataByText), newDataByText));
  6014. };
  6015. return nu$8({
  6016. readState,
  6017. lookup: lookup2,
  6018. update,
  6019. clear: clear2
  6020. });
  6021. };
  6022. var init$e = function(spec) {
  6023. return spec.store.manager.state(spec);
  6024. };
  6025. var RepresentState = Object.freeze({
  6026. __proto__: null,
  6027. memory: memory$1,
  6028. dataset,
  6029. manual,
  6030. init: init$e
  6031. });
  6032. var setValue$2 = function(component, repConfig, repState, data) {
  6033. var store2 = repConfig.store;
  6034. repState.update([data]);
  6035. store2.setValue(component, data);
  6036. repConfig.onSetValue(component, data);
  6037. };
  6038. var getValue$2 = function(component, repConfig, repState) {
  6039. var store2 = repConfig.store;
  6040. var key = store2.getDataKey(component);
  6041. return repState.lookup(key).getOrThunk(function() {
  6042. return store2.getFallbackEntry(key);
  6043. });
  6044. };
  6045. var onLoad$4 = function(component, repConfig, repState) {
  6046. var store2 = repConfig.store;
  6047. store2.initialValue.each(function(data) {
  6048. setValue$2(component, repConfig, repState, data);
  6049. });
  6050. };
  6051. var onUnload$1 = function(component, repConfig, repState) {
  6052. repState.clear();
  6053. };
  6054. var DatasetStore = [
  6055. option("initialValue"),
  6056. required$1("getFallbackEntry"),
  6057. required$1("getDataKey"),
  6058. required$1("setValue"),
  6059. output$1("manager", {
  6060. setValue: setValue$2,
  6061. getValue: getValue$2,
  6062. onLoad: onLoad$4,
  6063. onUnload: onUnload$1,
  6064. state: dataset
  6065. })
  6066. ];
  6067. var getValue$1 = function(component, repConfig, _repState) {
  6068. return repConfig.store.getValue(component);
  6069. };
  6070. var setValue$1 = function(component, repConfig, _repState, data) {
  6071. repConfig.store.setValue(component, data);
  6072. repConfig.onSetValue(component, data);
  6073. };
  6074. var onLoad$3 = function(component, repConfig, _repState) {
  6075. repConfig.store.initialValue.each(function(data) {
  6076. repConfig.store.setValue(component, data);
  6077. });
  6078. };
  6079. var ManualStore = [
  6080. required$1("getValue"),
  6081. defaulted("setValue", noop),
  6082. option("initialValue"),
  6083. output$1("manager", {
  6084. setValue: setValue$1,
  6085. getValue: getValue$1,
  6086. onLoad: onLoad$3,
  6087. onUnload: noop,
  6088. state: NoState.init
  6089. })
  6090. ];
  6091. var setValue = function(component, repConfig, repState, data) {
  6092. repState.set(data);
  6093. repConfig.onSetValue(component, data);
  6094. };
  6095. var getValue = function(component, repConfig, repState) {
  6096. return repState.get();
  6097. };
  6098. var onLoad$2 = function(component, repConfig, repState) {
  6099. repConfig.store.initialValue.each(function(initVal) {
  6100. if (repState.isNotSet()) {
  6101. repState.set(initVal);
  6102. }
  6103. });
  6104. };
  6105. var onUnload = function(component, repConfig, repState) {
  6106. repState.clear();
  6107. };
  6108. var MemoryStore = [
  6109. option("initialValue"),
  6110. output$1("manager", {
  6111. setValue,
  6112. getValue,
  6113. onLoad: onLoad$2,
  6114. onUnload,
  6115. state: memory$1
  6116. })
  6117. ];
  6118. var RepresentSchema = [
  6119. defaultedOf("store", { mode: "memory" }, choose$1("mode", {
  6120. memory: MemoryStore,
  6121. manual: ManualStore,
  6122. dataset: DatasetStore
  6123. })),
  6124. onHandler("onSetValue"),
  6125. defaulted("resetOnDom", false)
  6126. ];
  6127. var Representing = create$7({
  6128. fields: RepresentSchema,
  6129. name: "representing",
  6130. active: ActiveRepresenting,
  6131. apis: RepresentApis,
  6132. extra: {
  6133. setValueFrom: function(component, source) {
  6134. var value2 = Representing.getValue(source);
  6135. Representing.setValue(component, value2);
  6136. }
  6137. },
  6138. state: RepresentState
  6139. });
  6140. var field = function(name2, forbidden) {
  6141. return defaultedObjOf(name2, {}, map$2(forbidden, function(f) {
  6142. return forbid(f.name(), "Cannot configure " + f.name() + " for " + name2);
  6143. }).concat([customField("dump", identity$1)]));
  6144. };
  6145. var get$2 = function(data) {
  6146. return data.dump;
  6147. };
  6148. var augment = function(data, original2) {
  6149. return __assign(__assign({}, derive$1(original2)), data.dump);
  6150. };
  6151. var SketchBehaviours = {
  6152. field,
  6153. augment,
  6154. get: get$2
  6155. };
  6156. var _placeholder = "placeholder";
  6157. var adt$3 = Adt.generate([
  6158. {
  6159. single: [
  6160. "required",
  6161. "valueThunk"
  6162. ]
  6163. },
  6164. {
  6165. multiple: [
  6166. "required",
  6167. "valueThunks"
  6168. ]
  6169. }
  6170. ]);
  6171. var isSubstituted = function(spec) {
  6172. return has$2(spec, "uiType");
  6173. };
  6174. var subPlaceholder = function(owner2, detail, compSpec, placeholders) {
  6175. if (owner2.exists(function(o) {
  6176. return o !== compSpec.owner;
  6177. })) {
  6178. return adt$3.single(true, constant$1(compSpec));
  6179. }
  6180. return get$e(placeholders, compSpec.name).fold(function() {
  6181. throw new Error("Unknown placeholder component: " + compSpec.name + "\nKnown: [" + keys(placeholders) + "]\nNamespace: " + owner2.getOr("none") + "\nSpec: " + JSON.stringify(compSpec, null, 2));
  6182. }, function(newSpec) {
  6183. return newSpec.replace();
  6184. });
  6185. };
  6186. var scan = function(owner2, detail, compSpec, placeholders) {
  6187. if (isSubstituted(compSpec) && compSpec.uiType === _placeholder) {
  6188. return subPlaceholder(owner2, detail, compSpec, placeholders);
  6189. } else {
  6190. return adt$3.single(false, constant$1(compSpec));
  6191. }
  6192. };
  6193. var substitute = function(owner2, detail, compSpec, placeholders) {
  6194. var base2 = scan(owner2, detail, compSpec, placeholders);
  6195. return base2.fold(function(req, valueThunk2) {
  6196. var value2 = isSubstituted(compSpec) ? valueThunk2(detail, compSpec.config, compSpec.validated) : valueThunk2(detail);
  6197. var childSpecs = get$e(value2, "components").getOr([]);
  6198. var substituted = bind$3(childSpecs, function(c) {
  6199. return substitute(owner2, detail, c, placeholders);
  6200. });
  6201. return [__assign(__assign({}, value2), { components: substituted })];
  6202. }, function(req, valuesThunk) {
  6203. if (isSubstituted(compSpec)) {
  6204. var values2 = valuesThunk(detail, compSpec.config, compSpec.validated);
  6205. var preprocessor = compSpec.validated.preprocess.getOr(identity$1);
  6206. return preprocessor(values2);
  6207. } else {
  6208. return valuesThunk(detail);
  6209. }
  6210. });
  6211. };
  6212. var substituteAll = function(owner2, detail, components2, placeholders) {
  6213. return bind$3(components2, function(c) {
  6214. return substitute(owner2, detail, c, placeholders);
  6215. });
  6216. };
  6217. var oneReplace = function(label, replacements) {
  6218. var called = false;
  6219. var used = function() {
  6220. return called;
  6221. };
  6222. var replace = function() {
  6223. if (called) {
  6224. throw new Error("Trying to use the same placeholder more than once: " + label);
  6225. }
  6226. called = true;
  6227. return replacements;
  6228. };
  6229. var required2 = function() {
  6230. return replacements.fold(function(req, _) {
  6231. return req;
  6232. }, function(req, _) {
  6233. return req;
  6234. });
  6235. };
  6236. return {
  6237. name: constant$1(label),
  6238. required: required2,
  6239. used,
  6240. replace
  6241. };
  6242. };
  6243. var substitutePlaces = function(owner2, detail, components2, placeholders) {
  6244. var ps = map$1(placeholders, function(ph, name2) {
  6245. return oneReplace(name2, ph);
  6246. });
  6247. var outcome = substituteAll(owner2, detail, components2, ps);
  6248. each(ps, function(p) {
  6249. if (p.used() === false && p.required()) {
  6250. throw new Error("Placeholder: " + p.name() + " was not found in components list\nNamespace: " + owner2.getOr("none") + "\nComponents: " + JSON.stringify(detail.components, null, 2));
  6251. }
  6252. });
  6253. return outcome;
  6254. };
  6255. var single$2 = adt$3.single;
  6256. var multiple = adt$3.multiple;
  6257. var placeholder = constant$1(_placeholder);
  6258. var adt$2 = Adt.generate([
  6259. { required: ["data"] },
  6260. { external: ["data"] },
  6261. { optional: ["data"] },
  6262. { group: ["data"] }
  6263. ]);
  6264. var fFactory = defaulted("factory", { sketch: identity$1 });
  6265. var fSchema = defaulted("schema", []);
  6266. var fName = required$1("name");
  6267. var fPname = field$1("pname", "pname", defaultedThunk(function(typeSpec) {
  6268. return "<alloy." + generate$6(typeSpec.name) + ">";
  6269. }), anyValue());
  6270. var fGroupSchema = customField("schema", function() {
  6271. return [option("preprocess")];
  6272. });
  6273. var fDefaults = defaulted("defaults", constant$1({}));
  6274. var fOverrides = defaulted("overrides", constant$1({}));
  6275. var requiredSpec = objOf([
  6276. fFactory,
  6277. fSchema,
  6278. fName,
  6279. fPname,
  6280. fDefaults,
  6281. fOverrides
  6282. ]);
  6283. var externalSpec = objOf([
  6284. fFactory,
  6285. fSchema,
  6286. fName,
  6287. fDefaults,
  6288. fOverrides
  6289. ]);
  6290. var optionalSpec = objOf([
  6291. fFactory,
  6292. fSchema,
  6293. fName,
  6294. fPname,
  6295. fDefaults,
  6296. fOverrides
  6297. ]);
  6298. var groupSpec = objOf([
  6299. fFactory,
  6300. fGroupSchema,
  6301. fName,
  6302. required$1("unit"),
  6303. fPname,
  6304. fDefaults,
  6305. fOverrides
  6306. ]);
  6307. var asNamedPart = function(part2) {
  6308. return part2.fold(Optional.some, Optional.none, Optional.some, Optional.some);
  6309. };
  6310. var name$1 = function(part2) {
  6311. var get2 = function(data) {
  6312. return data.name;
  6313. };
  6314. return part2.fold(get2, get2, get2, get2);
  6315. };
  6316. var asCommon = function(part2) {
  6317. return part2.fold(identity$1, identity$1, identity$1, identity$1);
  6318. };
  6319. var convert = function(adtConstructor, partSchema) {
  6320. return function(spec) {
  6321. var data = asRawOrDie$1("Converting part type", partSchema, spec);
  6322. return adtConstructor(data);
  6323. };
  6324. };
  6325. var required = convert(adt$2.required, requiredSpec);
  6326. var external$1 = convert(adt$2.external, externalSpec);
  6327. var optional = convert(adt$2.optional, optionalSpec);
  6328. var group = convert(adt$2.group, groupSpec);
  6329. var original = constant$1("entirety");
  6330. var PartType = Object.freeze({
  6331. __proto__: null,
  6332. required,
  6333. external: external$1,
  6334. optional,
  6335. group,
  6336. asNamedPart,
  6337. name: name$1,
  6338. asCommon,
  6339. original
  6340. });
  6341. var combine = function(detail, data, partSpec, partValidated) {
  6342. return deepMerge(data.defaults(detail, partSpec, partValidated), partSpec, { uid: detail.partUids[data.name] }, data.overrides(detail, partSpec, partValidated));
  6343. };
  6344. var subs = function(owner2, detail, parts2) {
  6345. var internals = {};
  6346. var externals = {};
  6347. each$1(parts2, function(part2) {
  6348. part2.fold(function(data) {
  6349. internals[data.pname] = single$2(true, function(detail2, partSpec, partValidated) {
  6350. return data.factory.sketch(combine(detail2, data, partSpec, partValidated));
  6351. });
  6352. }, function(data) {
  6353. var partSpec = detail.parts[data.name];
  6354. externals[data.name] = constant$1(data.factory.sketch(combine(detail, data, partSpec[original()]), partSpec));
  6355. }, function(data) {
  6356. internals[data.pname] = single$2(false, function(detail2, partSpec, partValidated) {
  6357. return data.factory.sketch(combine(detail2, data, partSpec, partValidated));
  6358. });
  6359. }, function(data) {
  6360. internals[data.pname] = multiple(true, function(detail2, _partSpec, _partValidated) {
  6361. var units2 = detail2[data.name];
  6362. return map$2(units2, function(u) {
  6363. return data.factory.sketch(deepMerge(data.defaults(detail2, u, _partValidated), u, data.overrides(detail2, u)));
  6364. });
  6365. });
  6366. });
  6367. });
  6368. return {
  6369. internals: constant$1(internals),
  6370. externals: constant$1(externals)
  6371. };
  6372. };
  6373. var generate$3 = function(owner2, parts2) {
  6374. var r2 = {};
  6375. each$1(parts2, function(part2) {
  6376. asNamedPart(part2).each(function(np) {
  6377. var g = doGenerateOne(owner2, np.pname);
  6378. r2[np.name] = function(config2) {
  6379. var validated = asRawOrDie$1("Part: " + np.name + " in " + owner2, objOf(np.schema), config2);
  6380. return __assign(__assign({}, g), {
  6381. config: config2,
  6382. validated
  6383. });
  6384. };
  6385. });
  6386. });
  6387. return r2;
  6388. };
  6389. var doGenerateOne = function(owner2, pname) {
  6390. return {
  6391. uiType: placeholder(),
  6392. owner: owner2,
  6393. name: pname
  6394. };
  6395. };
  6396. var generateOne$1 = function(owner2, pname, config2) {
  6397. return {
  6398. uiType: placeholder(),
  6399. owner: owner2,
  6400. name: pname,
  6401. config: config2,
  6402. validated: {}
  6403. };
  6404. };
  6405. var schemas = function(parts2) {
  6406. return bind$3(parts2, function(part2) {
  6407. return part2.fold(Optional.none, Optional.some, Optional.none, Optional.none).map(function(data) {
  6408. return requiredObjOf(data.name, data.schema.concat([snapshot(original())]));
  6409. }).toArray();
  6410. });
  6411. };
  6412. var names = function(parts2) {
  6413. return map$2(parts2, name$1);
  6414. };
  6415. var substitutes = function(owner2, detail, parts2) {
  6416. return subs(owner2, detail, parts2);
  6417. };
  6418. var components$1 = function(owner2, detail, internals) {
  6419. return substitutePlaces(Optional.some(owner2), detail, detail.components, internals);
  6420. };
  6421. var getPart = function(component, detail, partKey) {
  6422. var uid = detail.partUids[partKey];
  6423. return component.getSystem().getByUid(uid).toOptional();
  6424. };
  6425. var getPartOrDie = function(component, detail, partKey) {
  6426. return getPart(component, detail, partKey).getOrDie("Could not find part: " + partKey);
  6427. };
  6428. var getParts = function(component, detail, partKeys) {
  6429. var r2 = {};
  6430. var uids2 = detail.partUids;
  6431. var system = component.getSystem();
  6432. each$1(partKeys, function(pk) {
  6433. r2[pk] = constant$1(system.getByUid(uids2[pk]));
  6434. });
  6435. return r2;
  6436. };
  6437. var getAllParts = function(component, detail) {
  6438. var system = component.getSystem();
  6439. return map$1(detail.partUids, function(pUid, _k) {
  6440. return constant$1(system.getByUid(pUid));
  6441. });
  6442. };
  6443. var getAllPartNames = function(detail) {
  6444. return keys(detail.partUids);
  6445. };
  6446. var getPartsOrDie = function(component, detail, partKeys) {
  6447. var r2 = {};
  6448. var uids2 = detail.partUids;
  6449. var system = component.getSystem();
  6450. each$1(partKeys, function(pk) {
  6451. r2[pk] = constant$1(system.getByUid(uids2[pk]).getOrDie());
  6452. });
  6453. return r2;
  6454. };
  6455. var defaultUids = function(baseUid, partTypes) {
  6456. var partNames = names(partTypes);
  6457. return wrapAll(map$2(partNames, function(pn) {
  6458. return {
  6459. key: pn,
  6460. value: baseUid + "-" + pn
  6461. };
  6462. }));
  6463. };
  6464. var defaultUidsSchema = function(partTypes) {
  6465. return field$1("partUids", "partUids", mergeWithThunk(function(spec) {
  6466. return defaultUids(spec.uid, partTypes);
  6467. }), anyValue());
  6468. };
  6469. var AlloyParts = Object.freeze({
  6470. __proto__: null,
  6471. generate: generate$3,
  6472. generateOne: generateOne$1,
  6473. schemas,
  6474. names,
  6475. substitutes,
  6476. components: components$1,
  6477. defaultUids,
  6478. defaultUidsSchema,
  6479. getAllParts,
  6480. getAllPartNames,
  6481. getPart,
  6482. getPartOrDie,
  6483. getParts,
  6484. getPartsOrDie
  6485. });
  6486. var base = function(partSchemas, partUidsSchemas) {
  6487. var ps = partSchemas.length > 0 ? [requiredObjOf("parts", partSchemas)] : [];
  6488. return ps.concat([
  6489. required$1("uid"),
  6490. defaulted("dom", {}),
  6491. defaulted("components", []),
  6492. snapshot("originalSpec"),
  6493. defaulted("debug.sketcher", {})
  6494. ]).concat(partUidsSchemas);
  6495. };
  6496. var asRawOrDie = function(label, schema2, spec, partSchemas, partUidsSchemas) {
  6497. var baseS = base(partSchemas, partUidsSchemas);
  6498. return asRawOrDie$1(label + " [SpecSchema]", objOfOnly(baseS.concat(schema2)), spec);
  6499. };
  6500. var single$1 = function(owner2, schema2, factory2, spec) {
  6501. var specWithUid = supplyUid(spec);
  6502. var detail = asRawOrDie(owner2, schema2, specWithUid, [], []);
  6503. return factory2(detail, specWithUid);
  6504. };
  6505. var composite$1 = function(owner2, schema2, partTypes, factory2, spec) {
  6506. var specWithUid = supplyUid(spec);
  6507. var partSchemas = schemas(partTypes);
  6508. var partUidsSchema = defaultUidsSchema(partTypes);
  6509. var detail = asRawOrDie(owner2, schema2, specWithUid, partSchemas, [partUidsSchema]);
  6510. var subs2 = substitutes(owner2, detail, partTypes);
  6511. var components2 = components$1(owner2, detail, subs2.internals());
  6512. return factory2(detail, components2, specWithUid, subs2.externals());
  6513. };
  6514. var hasUid = function(spec) {
  6515. return has$2(spec, "uid");
  6516. };
  6517. var supplyUid = function(spec) {
  6518. return hasUid(spec) ? spec : __assign(__assign({}, spec), { uid: generate$5("uid") });
  6519. };
  6520. var isSketchSpec = function(spec) {
  6521. return spec.uid !== void 0;
  6522. };
  6523. var singleSchema = objOfOnly([
  6524. required$1("name"),
  6525. required$1("factory"),
  6526. required$1("configFields"),
  6527. defaulted("apis", {}),
  6528. defaulted("extraApis", {})
  6529. ]);
  6530. var compositeSchema = objOfOnly([
  6531. required$1("name"),
  6532. required$1("factory"),
  6533. required$1("configFields"),
  6534. required$1("partFields"),
  6535. defaulted("apis", {}),
  6536. defaulted("extraApis", {})
  6537. ]);
  6538. var single = function(rawConfig) {
  6539. var config2 = asRawOrDie$1("Sketcher for " + rawConfig.name, singleSchema, rawConfig);
  6540. var sketch2 = function(spec) {
  6541. return single$1(config2.name, config2.configFields, config2.factory, spec);
  6542. };
  6543. var apis = map$1(config2.apis, makeApi);
  6544. var extraApis = map$1(config2.extraApis, function(f, k) {
  6545. return markAsExtraApi(f, k);
  6546. });
  6547. return __assign(__assign({
  6548. name: config2.name,
  6549. configFields: config2.configFields,
  6550. sketch: sketch2
  6551. }, apis), extraApis);
  6552. };
  6553. var composite = function(rawConfig) {
  6554. var config2 = asRawOrDie$1("Sketcher for " + rawConfig.name, compositeSchema, rawConfig);
  6555. var sketch2 = function(spec) {
  6556. return composite$1(config2.name, config2.configFields, config2.partFields, config2.factory, spec);
  6557. };
  6558. var parts2 = generate$3(config2.name, config2.partFields);
  6559. var apis = map$1(config2.apis, makeApi);
  6560. var extraApis = map$1(config2.extraApis, function(f, k) {
  6561. return markAsExtraApi(f, k);
  6562. });
  6563. return __assign(__assign({
  6564. name: config2.name,
  6565. partFields: config2.partFields,
  6566. configFields: config2.configFields,
  6567. sketch: sketch2,
  6568. parts: parts2
  6569. }, apis), extraApis);
  6570. };
  6571. var inside = function(target) {
  6572. return name$2(target) === "input" && get$d(target, "type") !== "radio" || name$2(target) === "textarea";
  6573. };
  6574. var getCurrent = function(component, composeConfig, _composeState) {
  6575. return composeConfig.find(component);
  6576. };
  6577. var ComposeApis = Object.freeze({
  6578. __proto__: null,
  6579. getCurrent
  6580. });
  6581. var ComposeSchema = [required$1("find")];
  6582. var Composing = create$7({
  6583. fields: ComposeSchema,
  6584. name: "composing",
  6585. apis: ComposeApis
  6586. });
  6587. var nativeDisabled = [
  6588. "input",
  6589. "button",
  6590. "textarea",
  6591. "select"
  6592. ];
  6593. var onLoad$1 = function(component, disableConfig, disableState) {
  6594. var f = disableConfig.disabled() ? disable$1 : enable$1;
  6595. f(component, disableConfig);
  6596. };
  6597. var hasNative = function(component, config2) {
  6598. return config2.useNative === true && contains$2(nativeDisabled, name$2(component.element));
  6599. };
  6600. var nativeIsDisabled = function(component) {
  6601. return has$1(component.element, "disabled");
  6602. };
  6603. var nativeDisable = function(component) {
  6604. set$8(component.element, "disabled", "disabled");
  6605. };
  6606. var nativeEnable = function(component) {
  6607. remove$7(component.element, "disabled");
  6608. };
  6609. var ariaIsDisabled = function(component) {
  6610. return get$d(component.element, "aria-disabled") === "true";
  6611. };
  6612. var ariaDisable = function(component) {
  6613. set$8(component.element, "aria-disabled", "true");
  6614. };
  6615. var ariaEnable = function(component) {
  6616. set$8(component.element, "aria-disabled", "false");
  6617. };
  6618. var disable$1 = function(component, disableConfig, _disableState) {
  6619. disableConfig.disableClass.each(function(disableClass) {
  6620. add$2(component.element, disableClass);
  6621. });
  6622. var f = hasNative(component, disableConfig) ? nativeDisable : ariaDisable;
  6623. f(component);
  6624. disableConfig.onDisabled(component);
  6625. };
  6626. var enable$1 = function(component, disableConfig, _disableState) {
  6627. disableConfig.disableClass.each(function(disableClass) {
  6628. remove$2(component.element, disableClass);
  6629. });
  6630. var f = hasNative(component, disableConfig) ? nativeEnable : ariaEnable;
  6631. f(component);
  6632. disableConfig.onEnabled(component);
  6633. };
  6634. var isDisabled = function(component, disableConfig) {
  6635. return hasNative(component, disableConfig) ? nativeIsDisabled(component) : ariaIsDisabled(component);
  6636. };
  6637. var set$3 = function(component, disableConfig, disableState, disabled) {
  6638. var f = disabled ? disable$1 : enable$1;
  6639. f(component, disableConfig);
  6640. };
  6641. var DisableApis = Object.freeze({
  6642. __proto__: null,
  6643. enable: enable$1,
  6644. disable: disable$1,
  6645. isDisabled,
  6646. onLoad: onLoad$1,
  6647. set: set$3
  6648. });
  6649. var exhibit$5 = function(base2, disableConfig) {
  6650. return nu$7({ classes: disableConfig.disabled() ? disableConfig.disableClass.toArray() : [] });
  6651. };
  6652. var events$e = function(disableConfig, disableState) {
  6653. return derive$2([
  6654. abort(execute$5(), function(component, _simulatedEvent) {
  6655. return isDisabled(component, disableConfig);
  6656. }),
  6657. loadEvent(disableConfig, disableState, onLoad$1)
  6658. ]);
  6659. };
  6660. var ActiveDisable = Object.freeze({
  6661. __proto__: null,
  6662. exhibit: exhibit$5,
  6663. events: events$e
  6664. });
  6665. var DisableSchema = [
  6666. defaultedFunction("disabled", never),
  6667. defaulted("useNative", true),
  6668. option("disableClass"),
  6669. onHandler("onDisabled"),
  6670. onHandler("onEnabled")
  6671. ];
  6672. var Disabling = create$7({
  6673. fields: DisableSchema,
  6674. name: "disabling",
  6675. active: ActiveDisable,
  6676. apis: DisableApis
  6677. });
  6678. var dehighlightAllExcept = function(component, hConfig, hState, skip) {
  6679. var highlighted = descendants(component.element, "." + hConfig.highlightClass);
  6680. each$1(highlighted, function(h) {
  6681. if (!exists(skip, function(skipComp) {
  6682. return skipComp.element === h;
  6683. })) {
  6684. remove$2(h, hConfig.highlightClass);
  6685. component.getSystem().getByDom(h).each(function(target) {
  6686. hConfig.onDehighlight(component, target);
  6687. emit(target, dehighlight$1());
  6688. });
  6689. }
  6690. });
  6691. };
  6692. var dehighlightAll = function(component, hConfig, hState) {
  6693. return dehighlightAllExcept(component, hConfig, hState, []);
  6694. };
  6695. var dehighlight = function(component, hConfig, hState, target) {
  6696. if (isHighlighted(component, hConfig, hState, target)) {
  6697. remove$2(target.element, hConfig.highlightClass);
  6698. hConfig.onDehighlight(component, target);
  6699. emit(target, dehighlight$1());
  6700. }
  6701. };
  6702. var highlight = function(component, hConfig, hState, target) {
  6703. dehighlightAllExcept(component, hConfig, hState, [target]);
  6704. if (!isHighlighted(component, hConfig, hState, target)) {
  6705. add$2(target.element, hConfig.highlightClass);
  6706. hConfig.onHighlight(component, target);
  6707. emit(target, highlight$1());
  6708. }
  6709. };
  6710. var highlightFirst = function(component, hConfig, hState) {
  6711. getFirst(component, hConfig).each(function(firstComp) {
  6712. highlight(component, hConfig, hState, firstComp);
  6713. });
  6714. };
  6715. var highlightLast = function(component, hConfig, hState) {
  6716. getLast(component, hConfig).each(function(lastComp) {
  6717. highlight(component, hConfig, hState, lastComp);
  6718. });
  6719. };
  6720. var highlightAt = function(component, hConfig, hState, index) {
  6721. getByIndex(component, hConfig, hState, index).fold(function(err) {
  6722. throw err;
  6723. }, function(firstComp) {
  6724. highlight(component, hConfig, hState, firstComp);
  6725. });
  6726. };
  6727. var highlightBy = function(component, hConfig, hState, predicate) {
  6728. var candidates = getCandidates(component, hConfig);
  6729. var targetComp = find$5(candidates, predicate);
  6730. targetComp.each(function(c) {
  6731. highlight(component, hConfig, hState, c);
  6732. });
  6733. };
  6734. var isHighlighted = function(component, hConfig, hState, queryTarget) {
  6735. return has(queryTarget.element, hConfig.highlightClass);
  6736. };
  6737. var getHighlighted = function(component, hConfig, _hState) {
  6738. return descendant(component.element, "." + hConfig.highlightClass).bind(function(e) {
  6739. return component.getSystem().getByDom(e).toOptional();
  6740. });
  6741. };
  6742. var getByIndex = function(component, hConfig, hState, index) {
  6743. var items = descendants(component.element, "." + hConfig.itemClass);
  6744. return Optional.from(items[index]).fold(function() {
  6745. return Result.error(new Error("No element found with index " + index));
  6746. }, component.getSystem().getByDom);
  6747. };
  6748. var getFirst = function(component, hConfig, _hState) {
  6749. return descendant(component.element, "." + hConfig.itemClass).bind(function(e) {
  6750. return component.getSystem().getByDom(e).toOptional();
  6751. });
  6752. };
  6753. var getLast = function(component, hConfig, _hState) {
  6754. var items = descendants(component.element, "." + hConfig.itemClass);
  6755. var last2 = items.length > 0 ? Optional.some(items[items.length - 1]) : Optional.none();
  6756. return last2.bind(function(c) {
  6757. return component.getSystem().getByDom(c).toOptional();
  6758. });
  6759. };
  6760. var getDelta$2 = function(component, hConfig, hState, delta) {
  6761. var items = descendants(component.element, "." + hConfig.itemClass);
  6762. var current = findIndex$1(items, function(item2) {
  6763. return has(item2, hConfig.highlightClass);
  6764. });
  6765. return current.bind(function(selected) {
  6766. var dest = cycleBy(selected, delta, 0, items.length - 1);
  6767. return component.getSystem().getByDom(items[dest]).toOptional();
  6768. });
  6769. };
  6770. var getPrevious = function(component, hConfig, hState) {
  6771. return getDelta$2(component, hConfig, hState, -1);
  6772. };
  6773. var getNext = function(component, hConfig, hState) {
  6774. return getDelta$2(component, hConfig, hState, 1);
  6775. };
  6776. var getCandidates = function(component, hConfig, _hState) {
  6777. var items = descendants(component.element, "." + hConfig.itemClass);
  6778. return cat(map$2(items, function(i) {
  6779. return component.getSystem().getByDom(i).toOptional();
  6780. }));
  6781. };
  6782. var HighlightApis = Object.freeze({
  6783. __proto__: null,
  6784. dehighlightAll,
  6785. dehighlight,
  6786. highlight,
  6787. highlightFirst,
  6788. highlightLast,
  6789. highlightAt,
  6790. highlightBy,
  6791. isHighlighted,
  6792. getHighlighted,
  6793. getFirst,
  6794. getLast,
  6795. getPrevious,
  6796. getNext,
  6797. getCandidates
  6798. });
  6799. var HighlightSchema = [
  6800. required$1("highlightClass"),
  6801. required$1("itemClass"),
  6802. onHandler("onHighlight"),
  6803. onHandler("onDehighlight")
  6804. ];
  6805. var Highlighting = create$7({
  6806. fields: HighlightSchema,
  6807. name: "highlighting",
  6808. apis: HighlightApis
  6809. });
  6810. var BACKSPACE = [8];
  6811. var TAB = [9];
  6812. var ENTER = [13];
  6813. var ESCAPE = [27];
  6814. var SPACE = [32];
  6815. var LEFT = [37];
  6816. var UP = [38];
  6817. var RIGHT = [39];
  6818. var DOWN = [40];
  6819. var cyclePrev = function(values2, index, predicate) {
  6820. var before2 = reverse(values2.slice(0, index));
  6821. var after2 = reverse(values2.slice(index + 1));
  6822. return find$5(before2.concat(after2), predicate);
  6823. };
  6824. var tryPrev = function(values2, index, predicate) {
  6825. var before2 = reverse(values2.slice(0, index));
  6826. return find$5(before2, predicate);
  6827. };
  6828. var cycleNext = function(values2, index, predicate) {
  6829. var before2 = values2.slice(0, index);
  6830. var after2 = values2.slice(index + 1);
  6831. return find$5(after2.concat(before2), predicate);
  6832. };
  6833. var tryNext = function(values2, index, predicate) {
  6834. var after2 = values2.slice(index + 1);
  6835. return find$5(after2, predicate);
  6836. };
  6837. var inSet = function(keys2) {
  6838. return function(event) {
  6839. var raw = event.raw;
  6840. return contains$2(keys2, raw.which);
  6841. };
  6842. };
  6843. var and = function(preds) {
  6844. return function(event) {
  6845. return forall(preds, function(pred) {
  6846. return pred(event);
  6847. });
  6848. };
  6849. };
  6850. var isShift = function(event) {
  6851. var raw = event.raw;
  6852. return raw.shiftKey === true;
  6853. };
  6854. var isControl = function(event) {
  6855. var raw = event.raw;
  6856. return raw.ctrlKey === true;
  6857. };
  6858. var isNotShift = not(isShift);
  6859. var rule = function(matches, action) {
  6860. return {
  6861. matches,
  6862. classification: action
  6863. };
  6864. };
  6865. var choose = function(transitions, event) {
  6866. var transition = find$5(transitions, function(t2) {
  6867. return t2.matches(event);
  6868. });
  6869. return transition.map(function(t2) {
  6870. return t2.classification;
  6871. });
  6872. };
  6873. var reportFocusShifting = function(component, prevFocus, newFocus) {
  6874. var noChange = prevFocus.exists(function(p) {
  6875. return newFocus.exists(function(n) {
  6876. return eq(n, p);
  6877. });
  6878. });
  6879. if (!noChange) {
  6880. emitWith(component, focusShifted(), {
  6881. prevFocus,
  6882. newFocus
  6883. });
  6884. }
  6885. };
  6886. var dom$2 = function() {
  6887. var get2 = function(component) {
  6888. return search(component.element);
  6889. };
  6890. var set2 = function(component, focusee) {
  6891. var prevFocus = get2(component);
  6892. component.getSystem().triggerFocus(focusee, component.element);
  6893. var newFocus = get2(component);
  6894. reportFocusShifting(component, prevFocus, newFocus);
  6895. };
  6896. return {
  6897. get: get2,
  6898. set: set2
  6899. };
  6900. };
  6901. var highlights = function() {
  6902. var get2 = function(component) {
  6903. return Highlighting.getHighlighted(component).map(function(item2) {
  6904. return item2.element;
  6905. });
  6906. };
  6907. var set2 = function(component, element2) {
  6908. var prevFocus = get2(component);
  6909. component.getSystem().getByDom(element2).fold(noop, function(item2) {
  6910. Highlighting.highlight(component, item2);
  6911. });
  6912. var newFocus = get2(component);
  6913. reportFocusShifting(component, prevFocus, newFocus);
  6914. };
  6915. return {
  6916. get: get2,
  6917. set: set2
  6918. };
  6919. };
  6920. var FocusInsideModes;
  6921. (function(FocusInsideModes2) {
  6922. FocusInsideModes2["OnFocusMode"] = "onFocus";
  6923. FocusInsideModes2["OnEnterOrSpaceMode"] = "onEnterOrSpace";
  6924. FocusInsideModes2["OnApiMode"] = "onApi";
  6925. })(FocusInsideModes || (FocusInsideModes = {}));
  6926. var typical = function(infoSchema, stateInit, getKeydownRules2, getKeyupRules2, optFocusIn) {
  6927. var schema2 = function() {
  6928. return infoSchema.concat([
  6929. defaulted("focusManager", dom$2()),
  6930. defaultedOf("focusInside", "onFocus", valueOf(function(val) {
  6931. return contains$2([
  6932. "onFocus",
  6933. "onEnterOrSpace",
  6934. "onApi"
  6935. ], val) ? Result.value(val) : Result.error("Invalid value for focusInside");
  6936. })),
  6937. output$1("handler", me),
  6938. output$1("state", stateInit),
  6939. output$1("sendFocusIn", optFocusIn)
  6940. ]);
  6941. };
  6942. var processKey = function(component, simulatedEvent, getRules, keyingConfig, keyingState) {
  6943. var rules = getRules(component, simulatedEvent, keyingConfig, keyingState);
  6944. return choose(rules, simulatedEvent.event).bind(function(rule2) {
  6945. return rule2(component, simulatedEvent, keyingConfig, keyingState);
  6946. });
  6947. };
  6948. var toEvents2 = function(keyingConfig, keyingState) {
  6949. var onFocusHandler = keyingConfig.focusInside !== FocusInsideModes.OnFocusMode ? Optional.none() : optFocusIn(keyingConfig).map(function(focusIn2) {
  6950. return run$1(focus$4(), function(component, simulatedEvent) {
  6951. focusIn2(component, keyingConfig, keyingState);
  6952. simulatedEvent.stop();
  6953. });
  6954. });
  6955. var tryGoInsideComponent = function(component, simulatedEvent) {
  6956. var isEnterOrSpace = inSet(SPACE.concat(ENTER))(simulatedEvent.event);
  6957. if (keyingConfig.focusInside === FocusInsideModes.OnEnterOrSpaceMode && isEnterOrSpace && isSource(component, simulatedEvent)) {
  6958. optFocusIn(keyingConfig).each(function(focusIn2) {
  6959. focusIn2(component, keyingConfig, keyingState);
  6960. simulatedEvent.stop();
  6961. });
  6962. }
  6963. };
  6964. var keyboardEvents = [
  6965. run$1(keydown(), function(component, simulatedEvent) {
  6966. processKey(component, simulatedEvent, getKeydownRules2, keyingConfig, keyingState).fold(function() {
  6967. tryGoInsideComponent(component, simulatedEvent);
  6968. }, function(_) {
  6969. simulatedEvent.stop();
  6970. });
  6971. }),
  6972. run$1(keyup(), function(component, simulatedEvent) {
  6973. processKey(component, simulatedEvent, getKeyupRules2, keyingConfig, keyingState).each(function(_) {
  6974. simulatedEvent.stop();
  6975. });
  6976. })
  6977. ];
  6978. return derive$2(onFocusHandler.toArray().concat(keyboardEvents));
  6979. };
  6980. var me = {
  6981. schema: schema2,
  6982. processKey,
  6983. toEvents: toEvents2
  6984. };
  6985. return me;
  6986. };
  6987. var create$5 = function(cyclicField) {
  6988. var schema2 = [
  6989. option("onEscape"),
  6990. option("onEnter"),
  6991. defaulted("selector", '[data-alloy-tabstop="true"]:not(:disabled)'),
  6992. defaulted("firstTabstop", 0),
  6993. defaulted("useTabstopAt", always),
  6994. option("visibilitySelector")
  6995. ].concat([cyclicField]);
  6996. var isVisible2 = function(tabbingConfig, element2) {
  6997. var target = tabbingConfig.visibilitySelector.bind(function(sel) {
  6998. return closest$1(element2, sel);
  6999. }).getOr(element2);
  7000. return get$b(target) > 0;
  7001. };
  7002. var findInitial = function(component, tabbingConfig) {
  7003. var tabstops = descendants(component.element, tabbingConfig.selector);
  7004. var visibles = filter$2(tabstops, function(elem) {
  7005. return isVisible2(tabbingConfig, elem);
  7006. });
  7007. return Optional.from(visibles[tabbingConfig.firstTabstop]);
  7008. };
  7009. var findCurrent2 = function(component, tabbingConfig) {
  7010. return tabbingConfig.focusManager.get(component).bind(function(elem) {
  7011. return closest$1(elem, tabbingConfig.selector);
  7012. });
  7013. };
  7014. var isTabstop = function(tabbingConfig, element2) {
  7015. return isVisible2(tabbingConfig, element2) && tabbingConfig.useTabstopAt(element2);
  7016. };
  7017. var focusIn2 = function(component, tabbingConfig, _tabbingState) {
  7018. findInitial(component, tabbingConfig).each(function(target) {
  7019. tabbingConfig.focusManager.set(component, target);
  7020. });
  7021. };
  7022. var goFromTabstop = function(component, tabstops, stopIndex, tabbingConfig, cycle) {
  7023. return cycle(tabstops, stopIndex, function(elem) {
  7024. return isTabstop(tabbingConfig, elem);
  7025. }).fold(function() {
  7026. return tabbingConfig.cyclic ? Optional.some(true) : Optional.none();
  7027. }, function(target) {
  7028. tabbingConfig.focusManager.set(component, target);
  7029. return Optional.some(true);
  7030. });
  7031. };
  7032. var go2 = function(component, _simulatedEvent, tabbingConfig, cycle) {
  7033. var tabstops = descendants(component.element, tabbingConfig.selector);
  7034. return findCurrent2(component, tabbingConfig).bind(function(tabstop) {
  7035. var optStopIndex = findIndex$1(tabstops, curry(eq, tabstop));
  7036. return optStopIndex.bind(function(stopIndex) {
  7037. return goFromTabstop(component, tabstops, stopIndex, tabbingConfig, cycle);
  7038. });
  7039. });
  7040. };
  7041. var goBackwards = function(component, simulatedEvent, tabbingConfig) {
  7042. var navigate = tabbingConfig.cyclic ? cyclePrev : tryPrev;
  7043. return go2(component, simulatedEvent, tabbingConfig, navigate);
  7044. };
  7045. var goForwards = function(component, simulatedEvent, tabbingConfig) {
  7046. var navigate = tabbingConfig.cyclic ? cycleNext : tryNext;
  7047. return go2(component, simulatedEvent, tabbingConfig, navigate);
  7048. };
  7049. var execute2 = function(component, simulatedEvent, tabbingConfig) {
  7050. return tabbingConfig.onEnter.bind(function(f) {
  7051. return f(component, simulatedEvent);
  7052. });
  7053. };
  7054. var exit = function(component, simulatedEvent, tabbingConfig) {
  7055. return tabbingConfig.onEscape.bind(function(f) {
  7056. return f(component, simulatedEvent);
  7057. });
  7058. };
  7059. var getKeydownRules2 = constant$1([
  7060. rule(and([
  7061. isShift,
  7062. inSet(TAB)
  7063. ]), goBackwards),
  7064. rule(inSet(TAB), goForwards),
  7065. rule(inSet(ESCAPE), exit),
  7066. rule(and([
  7067. isNotShift,
  7068. inSet(ENTER)
  7069. ]), execute2)
  7070. ]);
  7071. var getKeyupRules2 = constant$1([]);
  7072. return typical(schema2, NoState.init, getKeydownRules2, getKeyupRules2, function() {
  7073. return Optional.some(focusIn2);
  7074. });
  7075. };
  7076. var AcyclicType = create$5(customField("cyclic", never));
  7077. var CyclicType = create$5(customField("cyclic", always));
  7078. var doDefaultExecute = function(component, _simulatedEvent, focused) {
  7079. dispatch(component, focused, execute$5());
  7080. return Optional.some(true);
  7081. };
  7082. var defaultExecute = function(component, simulatedEvent, focused) {
  7083. var isComplex = inside(focused) && inSet(SPACE)(simulatedEvent.event);
  7084. return isComplex ? Optional.none() : doDefaultExecute(component, simulatedEvent, focused);
  7085. };
  7086. var stopEventForFirefox = function(_component, _simulatedEvent) {
  7087. return Optional.some(true);
  7088. };
  7089. var schema$v = [
  7090. defaulted("execute", defaultExecute),
  7091. defaulted("useSpace", false),
  7092. defaulted("useEnter", true),
  7093. defaulted("useControlEnter", false),
  7094. defaulted("useDown", false)
  7095. ];
  7096. var execute$4 = function(component, simulatedEvent, executeConfig) {
  7097. return executeConfig.execute(component, simulatedEvent, component.element);
  7098. };
  7099. var getKeydownRules$5 = function(component, _simulatedEvent, executeConfig, _executeState) {
  7100. var spaceExec = executeConfig.useSpace && !inside(component.element) ? SPACE : [];
  7101. var enterExec = executeConfig.useEnter ? ENTER : [];
  7102. var downExec = executeConfig.useDown ? DOWN : [];
  7103. var execKeys = spaceExec.concat(enterExec).concat(downExec);
  7104. return [rule(inSet(execKeys), execute$4)].concat(executeConfig.useControlEnter ? [rule(and([
  7105. isControl,
  7106. inSet(ENTER)
  7107. ]), execute$4)] : []);
  7108. };
  7109. var getKeyupRules$5 = function(component, _simulatedEvent, executeConfig, _executeState) {
  7110. return executeConfig.useSpace && !inside(component.element) ? [rule(inSet(SPACE), stopEventForFirefox)] : [];
  7111. };
  7112. var ExecutionType = typical(schema$v, NoState.init, getKeydownRules$5, getKeyupRules$5, function() {
  7113. return Optional.none();
  7114. });
  7115. var flatgrid$1 = function() {
  7116. var dimensions = value$1();
  7117. var setGridSize = function(numRows, numColumns) {
  7118. dimensions.set({
  7119. numRows,
  7120. numColumns
  7121. });
  7122. };
  7123. var getNumRows = function() {
  7124. return dimensions.get().map(function(d) {
  7125. return d.numRows;
  7126. });
  7127. };
  7128. var getNumColumns = function() {
  7129. return dimensions.get().map(function(d) {
  7130. return d.numColumns;
  7131. });
  7132. };
  7133. return nu$8({
  7134. readState: function() {
  7135. return dimensions.get().map(function(d) {
  7136. return {
  7137. numRows: String(d.numRows),
  7138. numColumns: String(d.numColumns)
  7139. };
  7140. }).getOr({
  7141. numRows: "?",
  7142. numColumns: "?"
  7143. });
  7144. },
  7145. setGridSize,
  7146. getNumRows,
  7147. getNumColumns
  7148. });
  7149. };
  7150. var init$d = function(spec) {
  7151. return spec.state(spec);
  7152. };
  7153. var KeyingState = Object.freeze({
  7154. __proto__: null,
  7155. flatgrid: flatgrid$1,
  7156. init: init$d
  7157. });
  7158. var useH = function(movement) {
  7159. return function(component, simulatedEvent, config2, state) {
  7160. var move2 = movement(component.element);
  7161. return use(move2, component, simulatedEvent, config2, state);
  7162. };
  7163. };
  7164. var west$1 = function(moveLeft2, moveRight2) {
  7165. var movement = onDirection(moveLeft2, moveRight2);
  7166. return useH(movement);
  7167. };
  7168. var east$1 = function(moveLeft2, moveRight2) {
  7169. var movement = onDirection(moveRight2, moveLeft2);
  7170. return useH(movement);
  7171. };
  7172. var useV = function(move2) {
  7173. return function(component, simulatedEvent, config2, state) {
  7174. return use(move2, component, simulatedEvent, config2, state);
  7175. };
  7176. };
  7177. var use = function(move2, component, simulatedEvent, config2, state) {
  7178. var outcome = config2.focusManager.get(component).bind(function(focused) {
  7179. return move2(component.element, focused, config2, state);
  7180. });
  7181. return outcome.map(function(newFocus) {
  7182. config2.focusManager.set(component, newFocus);
  7183. return true;
  7184. });
  7185. };
  7186. var north$1 = useV;
  7187. var south$1 = useV;
  7188. var move$1 = useV;
  7189. var isHidden$1 = function(dom2) {
  7190. return dom2.offsetWidth <= 0 && dom2.offsetHeight <= 0;
  7191. };
  7192. var isVisible = function(element2) {
  7193. return !isHidden$1(element2.dom);
  7194. };
  7195. var locate = function(candidates, predicate) {
  7196. return findIndex$1(candidates, predicate).map(function(index) {
  7197. return {
  7198. index,
  7199. candidates
  7200. };
  7201. });
  7202. };
  7203. var locateVisible = function(container, current, selector) {
  7204. var predicate = function(x) {
  7205. return eq(x, current);
  7206. };
  7207. var candidates = descendants(container, selector);
  7208. var visible = filter$2(candidates, isVisible);
  7209. return locate(visible, predicate);
  7210. };
  7211. var findIndex = function(elements, target) {
  7212. return findIndex$1(elements, function(elem) {
  7213. return eq(target, elem);
  7214. });
  7215. };
  7216. var withGrid = function(values2, index, numCols, f) {
  7217. var oldRow = Math.floor(index / numCols);
  7218. var oldColumn = index % numCols;
  7219. return f(oldRow, oldColumn).bind(function(address) {
  7220. var newIndex = address.row * numCols + address.column;
  7221. return newIndex >= 0 && newIndex < values2.length ? Optional.some(values2[newIndex]) : Optional.none();
  7222. });
  7223. };
  7224. var cycleHorizontal$1 = function(values2, index, numRows, numCols, delta) {
  7225. return withGrid(values2, index, numCols, function(oldRow, oldColumn) {
  7226. var onLastRow = oldRow === numRows - 1;
  7227. var colsInRow = onLastRow ? values2.length - oldRow * numCols : numCols;
  7228. var newColumn = cycleBy(oldColumn, delta, 0, colsInRow - 1);
  7229. return Optional.some({
  7230. row: oldRow,
  7231. column: newColumn
  7232. });
  7233. });
  7234. };
  7235. var cycleVertical$1 = function(values2, index, numRows, numCols, delta) {
  7236. return withGrid(values2, index, numCols, function(oldRow, oldColumn) {
  7237. var newRow = cycleBy(oldRow, delta, 0, numRows - 1);
  7238. var onLastRow = newRow === numRows - 1;
  7239. var colsInRow = onLastRow ? values2.length - newRow * numCols : numCols;
  7240. var newCol = clamp$1(oldColumn, 0, colsInRow - 1);
  7241. return Optional.some({
  7242. row: newRow,
  7243. column: newCol
  7244. });
  7245. });
  7246. };
  7247. var cycleRight$1 = function(values2, index, numRows, numCols) {
  7248. return cycleHorizontal$1(values2, index, numRows, numCols, 1);
  7249. };
  7250. var cycleLeft$1 = function(values2, index, numRows, numCols) {
  7251. return cycleHorizontal$1(values2, index, numRows, numCols, -1);
  7252. };
  7253. var cycleUp$1 = function(values2, index, numRows, numCols) {
  7254. return cycleVertical$1(values2, index, numRows, numCols, -1);
  7255. };
  7256. var cycleDown$1 = function(values2, index, numRows, numCols) {
  7257. return cycleVertical$1(values2, index, numRows, numCols, 1);
  7258. };
  7259. var schema$u = [
  7260. required$1("selector"),
  7261. defaulted("execute", defaultExecute),
  7262. onKeyboardHandler("onEscape"),
  7263. defaulted("captureTab", false),
  7264. initSize()
  7265. ];
  7266. var focusIn$3 = function(component, gridConfig, _gridState) {
  7267. descendant(component.element, gridConfig.selector).each(function(first2) {
  7268. gridConfig.focusManager.set(component, first2);
  7269. });
  7270. };
  7271. var findCurrent$1 = function(component, gridConfig) {
  7272. return gridConfig.focusManager.get(component).bind(function(elem) {
  7273. return closest$1(elem, gridConfig.selector);
  7274. });
  7275. };
  7276. var execute$3 = function(component, simulatedEvent, gridConfig, _gridState) {
  7277. return findCurrent$1(component, gridConfig).bind(function(focused) {
  7278. return gridConfig.execute(component, simulatedEvent, focused);
  7279. });
  7280. };
  7281. var doMove$2 = function(cycle) {
  7282. return function(element2, focused, gridConfig, gridState) {
  7283. return locateVisible(element2, focused, gridConfig.selector).bind(function(identified) {
  7284. return cycle(identified.candidates, identified.index, gridState.getNumRows().getOr(gridConfig.initSize.numRows), gridState.getNumColumns().getOr(gridConfig.initSize.numColumns));
  7285. });
  7286. };
  7287. };
  7288. var handleTab = function(_component, _simulatedEvent, gridConfig) {
  7289. return gridConfig.captureTab ? Optional.some(true) : Optional.none();
  7290. };
  7291. var doEscape$1 = function(component, simulatedEvent, gridConfig) {
  7292. return gridConfig.onEscape(component, simulatedEvent);
  7293. };
  7294. var moveLeft$3 = doMove$2(cycleLeft$1);
  7295. var moveRight$3 = doMove$2(cycleRight$1);
  7296. var moveNorth$1 = doMove$2(cycleUp$1);
  7297. var moveSouth$1 = doMove$2(cycleDown$1);
  7298. var getKeydownRules$4 = constant$1([
  7299. rule(inSet(LEFT), west$1(moveLeft$3, moveRight$3)),
  7300. rule(inSet(RIGHT), east$1(moveLeft$3, moveRight$3)),
  7301. rule(inSet(UP), north$1(moveNorth$1)),
  7302. rule(inSet(DOWN), south$1(moveSouth$1)),
  7303. rule(and([
  7304. isShift,
  7305. inSet(TAB)
  7306. ]), handleTab),
  7307. rule(and([
  7308. isNotShift,
  7309. inSet(TAB)
  7310. ]), handleTab),
  7311. rule(inSet(ESCAPE), doEscape$1),
  7312. rule(inSet(SPACE.concat(ENTER)), execute$3)
  7313. ]);
  7314. var getKeyupRules$4 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7315. var FlatgridType = typical(schema$u, flatgrid$1, getKeydownRules$4, getKeyupRules$4, function() {
  7316. return Optional.some(focusIn$3);
  7317. });
  7318. var horizontal = function(container, selector, current, delta) {
  7319. var isDisabledButton = function(candidate) {
  7320. return name$2(candidate) === "button" && get$d(candidate, "disabled") === "disabled";
  7321. };
  7322. var tryCycle = function(initial, index, candidates) {
  7323. var newIndex = cycleBy(index, delta, 0, candidates.length - 1);
  7324. if (newIndex === initial) {
  7325. return Optional.none();
  7326. } else {
  7327. return isDisabledButton(candidates[newIndex]) ? tryCycle(initial, newIndex, candidates) : Optional.from(candidates[newIndex]);
  7328. }
  7329. };
  7330. return locateVisible(container, current, selector).bind(function(identified) {
  7331. var index = identified.index;
  7332. var candidates = identified.candidates;
  7333. return tryCycle(index, index, candidates);
  7334. });
  7335. };
  7336. var schema$t = [
  7337. required$1("selector"),
  7338. defaulted("getInitial", Optional.none),
  7339. defaulted("execute", defaultExecute),
  7340. onKeyboardHandler("onEscape"),
  7341. defaulted("executeOnMove", false),
  7342. defaulted("allowVertical", true)
  7343. ];
  7344. var findCurrent = function(component, flowConfig) {
  7345. return flowConfig.focusManager.get(component).bind(function(elem) {
  7346. return closest$1(elem, flowConfig.selector);
  7347. });
  7348. };
  7349. var execute$2 = function(component, simulatedEvent, flowConfig) {
  7350. return findCurrent(component, flowConfig).bind(function(focused) {
  7351. return flowConfig.execute(component, simulatedEvent, focused);
  7352. });
  7353. };
  7354. var focusIn$2 = function(component, flowConfig, _state) {
  7355. flowConfig.getInitial(component).orThunk(function() {
  7356. return descendant(component.element, flowConfig.selector);
  7357. }).each(function(first2) {
  7358. flowConfig.focusManager.set(component, first2);
  7359. });
  7360. };
  7361. var moveLeft$2 = function(element2, focused, info) {
  7362. return horizontal(element2, info.selector, focused, -1);
  7363. };
  7364. var moveRight$2 = function(element2, focused, info) {
  7365. return horizontal(element2, info.selector, focused, 1);
  7366. };
  7367. var doMove$1 = function(movement) {
  7368. return function(component, simulatedEvent, flowConfig, flowState) {
  7369. return movement(component, simulatedEvent, flowConfig, flowState).bind(function() {
  7370. return flowConfig.executeOnMove ? execute$2(component, simulatedEvent, flowConfig) : Optional.some(true);
  7371. });
  7372. };
  7373. };
  7374. var doEscape = function(component, simulatedEvent, flowConfig) {
  7375. return flowConfig.onEscape(component, simulatedEvent);
  7376. };
  7377. var getKeydownRules$3 = function(_component, _se, flowConfig, _flowState) {
  7378. var westMovers = LEFT.concat(flowConfig.allowVertical ? UP : []);
  7379. var eastMovers = RIGHT.concat(flowConfig.allowVertical ? DOWN : []);
  7380. return [
  7381. rule(inSet(westMovers), doMove$1(west$1(moveLeft$2, moveRight$2))),
  7382. rule(inSet(eastMovers), doMove$1(east$1(moveLeft$2, moveRight$2))),
  7383. rule(inSet(ENTER), execute$2),
  7384. rule(inSet(SPACE), execute$2),
  7385. rule(inSet(ESCAPE), doEscape)
  7386. ];
  7387. };
  7388. var getKeyupRules$3 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7389. var FlowType = typical(schema$t, NoState.init, getKeydownRules$3, getKeyupRules$3, function() {
  7390. return Optional.some(focusIn$2);
  7391. });
  7392. var toCell = function(matrix2, rowIndex, columnIndex) {
  7393. return Optional.from(matrix2[rowIndex]).bind(function(row) {
  7394. return Optional.from(row[columnIndex]).map(function(cell) {
  7395. return {
  7396. rowIndex,
  7397. columnIndex,
  7398. cell
  7399. };
  7400. });
  7401. });
  7402. };
  7403. var cycleHorizontal = function(matrix2, rowIndex, startCol, deltaCol) {
  7404. var row = matrix2[rowIndex];
  7405. var colsInRow = row.length;
  7406. var newColIndex = cycleBy(startCol, deltaCol, 0, colsInRow - 1);
  7407. return toCell(matrix2, rowIndex, newColIndex);
  7408. };
  7409. var cycleVertical = function(matrix2, colIndex, startRow, deltaRow) {
  7410. var nextRowIndex = cycleBy(startRow, deltaRow, 0, matrix2.length - 1);
  7411. var colsInNextRow = matrix2[nextRowIndex].length;
  7412. var nextColIndex = clamp$1(colIndex, 0, colsInNextRow - 1);
  7413. return toCell(matrix2, nextRowIndex, nextColIndex);
  7414. };
  7415. var moveHorizontal = function(matrix2, rowIndex, startCol, deltaCol) {
  7416. var row = matrix2[rowIndex];
  7417. var colsInRow = row.length;
  7418. var newColIndex = clamp$1(startCol + deltaCol, 0, colsInRow - 1);
  7419. return toCell(matrix2, rowIndex, newColIndex);
  7420. };
  7421. var moveVertical = function(matrix2, colIndex, startRow, deltaRow) {
  7422. var nextRowIndex = clamp$1(startRow + deltaRow, 0, matrix2.length - 1);
  7423. var colsInNextRow = matrix2[nextRowIndex].length;
  7424. var nextColIndex = clamp$1(colIndex, 0, colsInNextRow - 1);
  7425. return toCell(matrix2, nextRowIndex, nextColIndex);
  7426. };
  7427. var cycleRight = function(matrix2, startRow, startCol) {
  7428. return cycleHorizontal(matrix2, startRow, startCol, 1);
  7429. };
  7430. var cycleLeft = function(matrix2, startRow, startCol) {
  7431. return cycleHorizontal(matrix2, startRow, startCol, -1);
  7432. };
  7433. var cycleUp = function(matrix2, startRow, startCol) {
  7434. return cycleVertical(matrix2, startCol, startRow, -1);
  7435. };
  7436. var cycleDown = function(matrix2, startRow, startCol) {
  7437. return cycleVertical(matrix2, startCol, startRow, 1);
  7438. };
  7439. var moveLeft$1 = function(matrix2, startRow, startCol) {
  7440. return moveHorizontal(matrix2, startRow, startCol, -1);
  7441. };
  7442. var moveRight$1 = function(matrix2, startRow, startCol) {
  7443. return moveHorizontal(matrix2, startRow, startCol, 1);
  7444. };
  7445. var moveUp$1 = function(matrix2, startRow, startCol) {
  7446. return moveVertical(matrix2, startCol, startRow, -1);
  7447. };
  7448. var moveDown$1 = function(matrix2, startRow, startCol) {
  7449. return moveVertical(matrix2, startCol, startRow, 1);
  7450. };
  7451. var schema$s = [
  7452. requiredObjOf("selectors", [
  7453. required$1("row"),
  7454. required$1("cell")
  7455. ]),
  7456. defaulted("cycles", true),
  7457. defaulted("previousSelector", Optional.none),
  7458. defaulted("execute", defaultExecute)
  7459. ];
  7460. var focusIn$1 = function(component, matrixConfig, _state) {
  7461. var focused = matrixConfig.previousSelector(component).orThunk(function() {
  7462. var selectors = matrixConfig.selectors;
  7463. return descendant(component.element, selectors.cell);
  7464. });
  7465. focused.each(function(cell) {
  7466. matrixConfig.focusManager.set(component, cell);
  7467. });
  7468. };
  7469. var execute$1 = function(component, simulatedEvent, matrixConfig) {
  7470. return search(component.element).bind(function(focused) {
  7471. return matrixConfig.execute(component, simulatedEvent, focused);
  7472. });
  7473. };
  7474. var toMatrix = function(rows, matrixConfig) {
  7475. return map$2(rows, function(row) {
  7476. return descendants(row, matrixConfig.selectors.cell);
  7477. });
  7478. };
  7479. var doMove = function(ifCycle, ifMove) {
  7480. return function(element2, focused, matrixConfig) {
  7481. var move2 = matrixConfig.cycles ? ifCycle : ifMove;
  7482. return closest$1(focused, matrixConfig.selectors.row).bind(function(inRow) {
  7483. var cellsInRow = descendants(inRow, matrixConfig.selectors.cell);
  7484. return findIndex(cellsInRow, focused).bind(function(colIndex) {
  7485. var allRows = descendants(element2, matrixConfig.selectors.row);
  7486. return findIndex(allRows, inRow).bind(function(rowIndex) {
  7487. var matrix2 = toMatrix(allRows, matrixConfig);
  7488. return move2(matrix2, rowIndex, colIndex).map(function(next) {
  7489. return next.cell;
  7490. });
  7491. });
  7492. });
  7493. });
  7494. };
  7495. };
  7496. var moveLeft = doMove(cycleLeft, moveLeft$1);
  7497. var moveRight = doMove(cycleRight, moveRight$1);
  7498. var moveNorth = doMove(cycleUp, moveUp$1);
  7499. var moveSouth = doMove(cycleDown, moveDown$1);
  7500. var getKeydownRules$2 = constant$1([
  7501. rule(inSet(LEFT), west$1(moveLeft, moveRight)),
  7502. rule(inSet(RIGHT), east$1(moveLeft, moveRight)),
  7503. rule(inSet(UP), north$1(moveNorth)),
  7504. rule(inSet(DOWN), south$1(moveSouth)),
  7505. rule(inSet(SPACE.concat(ENTER)), execute$1)
  7506. ]);
  7507. var getKeyupRules$2 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7508. var MatrixType = typical(schema$s, NoState.init, getKeydownRules$2, getKeyupRules$2, function() {
  7509. return Optional.some(focusIn$1);
  7510. });
  7511. var schema$r = [
  7512. required$1("selector"),
  7513. defaulted("execute", defaultExecute),
  7514. defaulted("moveOnTab", false)
  7515. ];
  7516. var execute = function(component, simulatedEvent, menuConfig) {
  7517. return menuConfig.focusManager.get(component).bind(function(focused) {
  7518. return menuConfig.execute(component, simulatedEvent, focused);
  7519. });
  7520. };
  7521. var focusIn = function(component, menuConfig, _state) {
  7522. descendant(component.element, menuConfig.selector).each(function(first2) {
  7523. menuConfig.focusManager.set(component, first2);
  7524. });
  7525. };
  7526. var moveUp = function(element2, focused, info) {
  7527. return horizontal(element2, info.selector, focused, -1);
  7528. };
  7529. var moveDown = function(element2, focused, info) {
  7530. return horizontal(element2, info.selector, focused, 1);
  7531. };
  7532. var fireShiftTab = function(component, simulatedEvent, menuConfig, menuState) {
  7533. return menuConfig.moveOnTab ? move$1(moveUp)(component, simulatedEvent, menuConfig, menuState) : Optional.none();
  7534. };
  7535. var fireTab = function(component, simulatedEvent, menuConfig, menuState) {
  7536. return menuConfig.moveOnTab ? move$1(moveDown)(component, simulatedEvent, menuConfig, menuState) : Optional.none();
  7537. };
  7538. var getKeydownRules$1 = constant$1([
  7539. rule(inSet(UP), move$1(moveUp)),
  7540. rule(inSet(DOWN), move$1(moveDown)),
  7541. rule(and([
  7542. isShift,
  7543. inSet(TAB)
  7544. ]), fireShiftTab),
  7545. rule(and([
  7546. isNotShift,
  7547. inSet(TAB)
  7548. ]), fireTab),
  7549. rule(inSet(ENTER), execute),
  7550. rule(inSet(SPACE), execute)
  7551. ]);
  7552. var getKeyupRules$1 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7553. var MenuType = typical(schema$r, NoState.init, getKeydownRules$1, getKeyupRules$1, function() {
  7554. return Optional.some(focusIn);
  7555. });
  7556. var schema$q = [
  7557. onKeyboardHandler("onSpace"),
  7558. onKeyboardHandler("onEnter"),
  7559. onKeyboardHandler("onShiftEnter"),
  7560. onKeyboardHandler("onLeft"),
  7561. onKeyboardHandler("onRight"),
  7562. onKeyboardHandler("onTab"),
  7563. onKeyboardHandler("onShiftTab"),
  7564. onKeyboardHandler("onUp"),
  7565. onKeyboardHandler("onDown"),
  7566. onKeyboardHandler("onEscape"),
  7567. defaulted("stopSpaceKeyup", false),
  7568. option("focusIn")
  7569. ];
  7570. var getKeydownRules = function(component, simulatedEvent, specialInfo) {
  7571. return [
  7572. rule(inSet(SPACE), specialInfo.onSpace),
  7573. rule(and([
  7574. isNotShift,
  7575. inSet(ENTER)
  7576. ]), specialInfo.onEnter),
  7577. rule(and([
  7578. isShift,
  7579. inSet(ENTER)
  7580. ]), specialInfo.onShiftEnter),
  7581. rule(and([
  7582. isShift,
  7583. inSet(TAB)
  7584. ]), specialInfo.onShiftTab),
  7585. rule(and([
  7586. isNotShift,
  7587. inSet(TAB)
  7588. ]), specialInfo.onTab),
  7589. rule(inSet(UP), specialInfo.onUp),
  7590. rule(inSet(DOWN), specialInfo.onDown),
  7591. rule(inSet(LEFT), specialInfo.onLeft),
  7592. rule(inSet(RIGHT), specialInfo.onRight),
  7593. rule(inSet(SPACE), specialInfo.onSpace),
  7594. rule(inSet(ESCAPE), specialInfo.onEscape)
  7595. ];
  7596. };
  7597. var getKeyupRules = function(component, simulatedEvent, specialInfo) {
  7598. return specialInfo.stopSpaceKeyup ? [rule(inSet(SPACE), stopEventForFirefox)] : [];
  7599. };
  7600. var SpecialType = typical(schema$q, NoState.init, getKeydownRules, getKeyupRules, function(specialInfo) {
  7601. return specialInfo.focusIn;
  7602. });
  7603. var acyclic = AcyclicType.schema();
  7604. var cyclic = CyclicType.schema();
  7605. var flow = FlowType.schema();
  7606. var flatgrid = FlatgridType.schema();
  7607. var matrix = MatrixType.schema();
  7608. var execution = ExecutionType.schema();
  7609. var menu = MenuType.schema();
  7610. var special = SpecialType.schema();
  7611. var KeyboardBranches = Object.freeze({
  7612. __proto__: null,
  7613. acyclic,
  7614. cyclic,
  7615. flow,
  7616. flatgrid,
  7617. matrix,
  7618. execution,
  7619. menu,
  7620. special
  7621. });
  7622. var isFlatgridState = function(keyState) {
  7623. return hasNonNullableKey(keyState, "setGridSize");
  7624. };
  7625. var Keying = createModes({
  7626. branchKey: "mode",
  7627. branches: KeyboardBranches,
  7628. name: "keying",
  7629. active: {
  7630. events: function(keyingConfig, keyingState) {
  7631. var handler = keyingConfig.handler;
  7632. return handler.toEvents(keyingConfig, keyingState);
  7633. }
  7634. },
  7635. apis: {
  7636. focusIn: function(component, keyConfig, keyState) {
  7637. keyConfig.sendFocusIn(keyConfig).fold(function() {
  7638. component.getSystem().triggerFocus(component.element, component.element);
  7639. }, function(sendFocusIn) {
  7640. sendFocusIn(component, keyConfig, keyState);
  7641. });
  7642. },
  7643. setGridSize: function(component, keyConfig, keyState, numRows, numColumns) {
  7644. if (!isFlatgridState(keyState)) {
  7645. console.error("Layout does not support setGridSize");
  7646. } else {
  7647. keyState.setGridSize(numRows, numColumns);
  7648. }
  7649. }
  7650. },
  7651. state: KeyingState
  7652. });
  7653. var set$2 = function(component, replaceConfig, replaceState, data) {
  7654. preserve$1(function() {
  7655. var newChildren = map$2(data, component.getSystem().build);
  7656. replaceChildren(component, newChildren);
  7657. }, component.element);
  7658. };
  7659. var insert = function(component, replaceConfig, insertion, childSpec) {
  7660. var child2 = component.getSystem().build(childSpec);
  7661. attachWith(component, child2, insertion);
  7662. };
  7663. var append = function(component, replaceConfig, replaceState, appendee) {
  7664. insert(component, replaceConfig, append$2, appendee);
  7665. };
  7666. var prepend = function(component, replaceConfig, replaceState, prependee) {
  7667. insert(component, replaceConfig, prepend$1, prependee);
  7668. };
  7669. var remove = function(component, replaceConfig, replaceState, removee) {
  7670. var children2 = contents(component);
  7671. var foundChild = find$5(children2, function(child2) {
  7672. return eq(removee.element, child2.element);
  7673. });
  7674. foundChild.each(detach);
  7675. };
  7676. var contents = function(component, _replaceConfig) {
  7677. return component.components();
  7678. };
  7679. var replaceAt = function(component, replaceConfig, replaceState, replaceeIndex, replacer) {
  7680. var children2 = contents(component);
  7681. return Optional.from(children2[replaceeIndex]).map(function(replacee) {
  7682. remove(component, replaceConfig, replaceState, replacee);
  7683. replacer.each(function(r2) {
  7684. insert(component, replaceConfig, function(p, c) {
  7685. appendAt(p, c, replaceeIndex);
  7686. }, r2);
  7687. });
  7688. return replacee;
  7689. });
  7690. };
  7691. var replaceBy = function(component, replaceConfig, replaceState, replaceePred, replacer) {
  7692. var children2 = contents(component);
  7693. return findIndex$1(children2, replaceePred).bind(function(replaceeIndex) {
  7694. return replaceAt(component, replaceConfig, replaceState, replaceeIndex, replacer);
  7695. });
  7696. };
  7697. var ReplaceApis = Object.freeze({
  7698. __proto__: null,
  7699. append,
  7700. prepend,
  7701. remove,
  7702. replaceAt,
  7703. replaceBy,
  7704. set: set$2,
  7705. contents
  7706. });
  7707. var Replacing = create$7({
  7708. fields: [],
  7709. name: "replacing",
  7710. apis: ReplaceApis
  7711. });
  7712. var events$d = function(name2, eventHandlers) {
  7713. var events2 = derive$2(eventHandlers);
  7714. return create$7({
  7715. fields: [required$1("enabled")],
  7716. name: name2,
  7717. active: { events: constant$1(events2) }
  7718. });
  7719. };
  7720. var config = function(name2, eventHandlers) {
  7721. var me = events$d(name2, eventHandlers);
  7722. return {
  7723. key: name2,
  7724. value: {
  7725. config: {},
  7726. me,
  7727. configAsRaw: constant$1({}),
  7728. initialConfig: {},
  7729. state: NoState
  7730. }
  7731. };
  7732. };
  7733. var focus$2 = function(component, focusConfig) {
  7734. if (!focusConfig.ignore) {
  7735. focus$3(component.element);
  7736. focusConfig.onFocus(component);
  7737. }
  7738. };
  7739. var blur = function(component, focusConfig) {
  7740. if (!focusConfig.ignore) {
  7741. blur$1(component.element);
  7742. }
  7743. };
  7744. var isFocused = function(component) {
  7745. return hasFocus(component.element);
  7746. };
  7747. var FocusApis = Object.freeze({
  7748. __proto__: null,
  7749. focus: focus$2,
  7750. blur,
  7751. isFocused
  7752. });
  7753. var exhibit$4 = function(base2, focusConfig) {
  7754. var mod = focusConfig.ignore ? {} : { attributes: { tabindex: "-1" } };
  7755. return nu$7(mod);
  7756. };
  7757. var events$c = function(focusConfig) {
  7758. return derive$2([run$1(focus$4(), function(component, simulatedEvent) {
  7759. focus$2(component, focusConfig);
  7760. simulatedEvent.stop();
  7761. })].concat(focusConfig.stopMousedown ? [run$1(mousedown(), function(_, simulatedEvent) {
  7762. simulatedEvent.event.prevent();
  7763. })] : []));
  7764. };
  7765. var ActiveFocus = Object.freeze({
  7766. __proto__: null,
  7767. exhibit: exhibit$4,
  7768. events: events$c
  7769. });
  7770. var FocusSchema = [
  7771. onHandler("onFocus"),
  7772. defaulted("stopMousedown", false),
  7773. defaulted("ignore", false)
  7774. ];
  7775. var Focusing = create$7({
  7776. fields: FocusSchema,
  7777. name: "focusing",
  7778. active: ActiveFocus,
  7779. apis: FocusApis
  7780. });
  7781. var SetupBehaviourCellState = function(initialState) {
  7782. var init2 = function() {
  7783. var cell = Cell(initialState);
  7784. var get2 = function() {
  7785. return cell.get();
  7786. };
  7787. var set2 = function(newState) {
  7788. return cell.set(newState);
  7789. };
  7790. var clear2 = function() {
  7791. return cell.set(initialState);
  7792. };
  7793. var readState = function() {
  7794. return cell.get();
  7795. };
  7796. return {
  7797. get: get2,
  7798. set: set2,
  7799. clear: clear2,
  7800. readState
  7801. };
  7802. };
  7803. return { init: init2 };
  7804. };
  7805. var updateAriaState = function(component, toggleConfig, toggleState) {
  7806. var ariaInfo = toggleConfig.aria;
  7807. ariaInfo.update(component, ariaInfo, toggleState.get());
  7808. };
  7809. var updateClass = function(component, toggleConfig, toggleState) {
  7810. toggleConfig.toggleClass.each(function(toggleClass) {
  7811. if (toggleState.get()) {
  7812. add$2(component.element, toggleClass);
  7813. } else {
  7814. remove$2(component.element, toggleClass);
  7815. }
  7816. });
  7817. };
  7818. var toggle$2 = function(component, toggleConfig, toggleState) {
  7819. set$1(component, toggleConfig, toggleState, !toggleState.get());
  7820. };
  7821. var on = function(component, toggleConfig, toggleState) {
  7822. toggleState.set(true);
  7823. updateClass(component, toggleConfig, toggleState);
  7824. updateAriaState(component, toggleConfig, toggleState);
  7825. };
  7826. var off = function(component, toggleConfig, toggleState) {
  7827. toggleState.set(false);
  7828. updateClass(component, toggleConfig, toggleState);
  7829. updateAriaState(component, toggleConfig, toggleState);
  7830. };
  7831. var set$1 = function(component, toggleConfig, toggleState, state) {
  7832. var action = state ? on : off;
  7833. action(component, toggleConfig, toggleState);
  7834. };
  7835. var isOn = function(component, toggleConfig, toggleState) {
  7836. return toggleState.get();
  7837. };
  7838. var onLoad = function(component, toggleConfig, toggleState) {
  7839. set$1(component, toggleConfig, toggleState, toggleConfig.selected);
  7840. };
  7841. var ToggleApis = Object.freeze({
  7842. __proto__: null,
  7843. onLoad,
  7844. toggle: toggle$2,
  7845. isOn,
  7846. on,
  7847. off,
  7848. set: set$1
  7849. });
  7850. var exhibit$3 = function() {
  7851. return nu$7({});
  7852. };
  7853. var events$b = function(toggleConfig, toggleState) {
  7854. var execute2 = executeEvent(toggleConfig, toggleState, toggle$2);
  7855. var load = loadEvent(toggleConfig, toggleState, onLoad);
  7856. return derive$2(flatten([
  7857. toggleConfig.toggleOnExecute ? [execute2] : [],
  7858. [load]
  7859. ]));
  7860. };
  7861. var ActiveToggle = Object.freeze({
  7862. __proto__: null,
  7863. exhibit: exhibit$3,
  7864. events: events$b
  7865. });
  7866. var updatePressed = function(component, ariaInfo, status) {
  7867. set$8(component.element, "aria-pressed", status);
  7868. if (ariaInfo.syncWithExpanded) {
  7869. updateExpanded(component, ariaInfo, status);
  7870. }
  7871. };
  7872. var updateSelected = function(component, ariaInfo, status) {
  7873. set$8(component.element, "aria-selected", status);
  7874. };
  7875. var updateChecked = function(component, ariaInfo, status) {
  7876. set$8(component.element, "aria-checked", status);
  7877. };
  7878. var updateExpanded = function(component, ariaInfo, status) {
  7879. set$8(component.element, "aria-expanded", status);
  7880. };
  7881. var ToggleSchema = [
  7882. defaulted("selected", false),
  7883. option("toggleClass"),
  7884. defaulted("toggleOnExecute", true),
  7885. defaultedOf("aria", { mode: "none" }, choose$1("mode", {
  7886. pressed: [
  7887. defaulted("syncWithExpanded", false),
  7888. output$1("update", updatePressed)
  7889. ],
  7890. checked: [output$1("update", updateChecked)],
  7891. expanded: [output$1("update", updateExpanded)],
  7892. selected: [output$1("update", updateSelected)],
  7893. none: [output$1("update", noop)]
  7894. }))
  7895. ];
  7896. var Toggling = create$7({
  7897. fields: ToggleSchema,
  7898. name: "toggling",
  7899. active: ActiveToggle,
  7900. apis: ToggleApis,
  7901. state: SetupBehaviourCellState(false)
  7902. });
  7903. var pointerEvents = function() {
  7904. var onClick = function(component, simulatedEvent) {
  7905. simulatedEvent.stop();
  7906. emitExecute(component);
  7907. };
  7908. return [
  7909. run$1(click(), onClick),
  7910. run$1(tap(), onClick),
  7911. cutter(touchstart()),
  7912. cutter(mousedown())
  7913. ];
  7914. };
  7915. var events$a = function(optAction) {
  7916. var executeHandler = function(action) {
  7917. return runOnExecute$1(function(component, simulatedEvent) {
  7918. action(component);
  7919. simulatedEvent.stop();
  7920. });
  7921. };
  7922. return derive$2(flatten([
  7923. optAction.map(executeHandler).toArray(),
  7924. pointerEvents()
  7925. ]));
  7926. };
  7927. var hoverEvent = "alloy.item-hover";
  7928. var focusEvent = "alloy.item-focus";
  7929. var onHover = function(item2) {
  7930. if (search(item2.element).isNone() || Focusing.isFocused(item2)) {
  7931. if (!Focusing.isFocused(item2)) {
  7932. Focusing.focus(item2);
  7933. }
  7934. emitWith(item2, hoverEvent, { item: item2 });
  7935. }
  7936. };
  7937. var onFocus$1 = function(item2) {
  7938. emitWith(item2, focusEvent, { item: item2 });
  7939. };
  7940. var hover = constant$1(hoverEvent);
  7941. var focus$1 = constant$1(focusEvent);
  7942. var builder$2 = function(detail) {
  7943. return {
  7944. dom: detail.dom,
  7945. domModification: __assign(__assign({}, detail.domModification), { attributes: __assign(__assign(__assign({ "role": detail.toggling.isSome() ? "menuitemcheckbox" : "menuitem" }, detail.domModification.attributes), { "aria-haspopup": detail.hasSubmenu }), detail.hasSubmenu ? { "aria-expanded": false } : {}) }),
  7946. behaviours: SketchBehaviours.augment(detail.itemBehaviours, [
  7947. detail.toggling.fold(Toggling.revoke, function(tConfig) {
  7948. return Toggling.config(__assign({ aria: { mode: "checked" } }, tConfig));
  7949. }),
  7950. Focusing.config({
  7951. ignore: detail.ignoreFocus,
  7952. stopMousedown: detail.ignoreFocus,
  7953. onFocus: function(component) {
  7954. onFocus$1(component);
  7955. }
  7956. }),
  7957. Keying.config({ mode: "execution" }),
  7958. Representing.config({
  7959. store: {
  7960. mode: "memory",
  7961. initialValue: detail.data
  7962. }
  7963. }),
  7964. config("item-type-events", __spreadArray(__spreadArray([], pointerEvents(), true), [
  7965. run$1(mouseover(), onHover),
  7966. run$1(focusItem(), Focusing.focus)
  7967. ], false))
  7968. ]),
  7969. components: detail.components,
  7970. eventOrder: detail.eventOrder
  7971. };
  7972. };
  7973. var schema$p = [
  7974. required$1("data"),
  7975. required$1("components"),
  7976. required$1("dom"),
  7977. defaulted("hasSubmenu", false),
  7978. option("toggling"),
  7979. SketchBehaviours.field("itemBehaviours", [
  7980. Toggling,
  7981. Focusing,
  7982. Keying,
  7983. Representing
  7984. ]),
  7985. defaulted("ignoreFocus", false),
  7986. defaulted("domModification", {}),
  7987. output$1("builder", builder$2),
  7988. defaulted("eventOrder", {})
  7989. ];
  7990. var builder$1 = function(detail) {
  7991. return {
  7992. dom: detail.dom,
  7993. components: detail.components,
  7994. events: derive$2([stopper(focusItem())])
  7995. };
  7996. };
  7997. var schema$o = [
  7998. required$1("dom"),
  7999. required$1("components"),
  8000. output$1("builder", builder$1)
  8001. ];
  8002. var owner$2 = constant$1("item-widget");
  8003. var parts$h = constant$1([required({
  8004. name: "widget",
  8005. overrides: function(detail) {
  8006. return {
  8007. behaviours: derive$1([Representing.config({
  8008. store: {
  8009. mode: "manual",
  8010. getValue: function(_component) {
  8011. return detail.data;
  8012. },
  8013. setValue: noop
  8014. }
  8015. })])
  8016. };
  8017. }
  8018. })]);
  8019. var builder = function(detail) {
  8020. var subs2 = substitutes(owner$2(), detail, parts$h());
  8021. var components2 = components$1(owner$2(), detail, subs2.internals());
  8022. var focusWidget = function(component) {
  8023. return getPart(component, detail, "widget").map(function(widget) {
  8024. Keying.focusIn(widget);
  8025. return widget;
  8026. });
  8027. };
  8028. var onHorizontalArrow = function(component, simulatedEvent) {
  8029. return inside(simulatedEvent.event.target) ? Optional.none() : function() {
  8030. if (detail.autofocus) {
  8031. simulatedEvent.setSource(component.element);
  8032. return Optional.none();
  8033. } else {
  8034. return Optional.none();
  8035. }
  8036. }();
  8037. };
  8038. return {
  8039. dom: detail.dom,
  8040. components: components2,
  8041. domModification: detail.domModification,
  8042. events: derive$2([
  8043. runOnExecute$1(function(component, simulatedEvent) {
  8044. focusWidget(component).each(function(_widget) {
  8045. simulatedEvent.stop();
  8046. });
  8047. }),
  8048. run$1(mouseover(), onHover),
  8049. run$1(focusItem(), function(component, _simulatedEvent) {
  8050. if (detail.autofocus) {
  8051. focusWidget(component);
  8052. } else {
  8053. Focusing.focus(component);
  8054. }
  8055. })
  8056. ]),
  8057. behaviours: SketchBehaviours.augment(detail.widgetBehaviours, [
  8058. Representing.config({
  8059. store: {
  8060. mode: "memory",
  8061. initialValue: detail.data
  8062. }
  8063. }),
  8064. Focusing.config({
  8065. ignore: detail.ignoreFocus,
  8066. onFocus: function(component) {
  8067. onFocus$1(component);
  8068. }
  8069. }),
  8070. Keying.config({
  8071. mode: "special",
  8072. focusIn: detail.autofocus ? function(component) {
  8073. focusWidget(component);
  8074. } : revoke(),
  8075. onLeft: onHorizontalArrow,
  8076. onRight: onHorizontalArrow,
  8077. onEscape: function(component, simulatedEvent) {
  8078. if (!Focusing.isFocused(component) && !detail.autofocus) {
  8079. Focusing.focus(component);
  8080. return Optional.some(true);
  8081. } else if (detail.autofocus) {
  8082. simulatedEvent.setSource(component.element);
  8083. return Optional.none();
  8084. } else {
  8085. return Optional.none();
  8086. }
  8087. }
  8088. })
  8089. ])
  8090. };
  8091. };
  8092. var schema$n = [
  8093. required$1("uid"),
  8094. required$1("data"),
  8095. required$1("components"),
  8096. required$1("dom"),
  8097. defaulted("autofocus", false),
  8098. defaulted("ignoreFocus", false),
  8099. SketchBehaviours.field("widgetBehaviours", [
  8100. Representing,
  8101. Focusing,
  8102. Keying
  8103. ]),
  8104. defaulted("domModification", {}),
  8105. defaultUidsSchema(parts$h()),
  8106. output$1("builder", builder)
  8107. ];
  8108. var itemSchema$2 = choose$1("type", {
  8109. widget: schema$n,
  8110. item: schema$p,
  8111. separator: schema$o
  8112. });
  8113. var configureGrid = function(detail, movementInfo) {
  8114. return {
  8115. mode: "flatgrid",
  8116. selector: "." + detail.markers.item,
  8117. initSize: {
  8118. numColumns: movementInfo.initSize.numColumns,
  8119. numRows: movementInfo.initSize.numRows
  8120. },
  8121. focusManager: detail.focusManager
  8122. };
  8123. };
  8124. var configureMatrix = function(detail, movementInfo) {
  8125. return {
  8126. mode: "matrix",
  8127. selectors: {
  8128. row: movementInfo.rowSelector,
  8129. cell: "." + detail.markers.item
  8130. },
  8131. focusManager: detail.focusManager
  8132. };
  8133. };
  8134. var configureMenu = function(detail, movementInfo) {
  8135. return {
  8136. mode: "menu",
  8137. selector: "." + detail.markers.item,
  8138. moveOnTab: movementInfo.moveOnTab,
  8139. focusManager: detail.focusManager
  8140. };
  8141. };
  8142. var parts$g = constant$1([group({
  8143. factory: {
  8144. sketch: function(spec) {
  8145. var itemInfo = asRawOrDie$1("menu.spec item", itemSchema$2, spec);
  8146. return itemInfo.builder(itemInfo);
  8147. }
  8148. },
  8149. name: "items",
  8150. unit: "item",
  8151. defaults: function(detail, u) {
  8152. return has$2(u, "uid") ? u : __assign(__assign({}, u), { uid: generate$5("item") });
  8153. },
  8154. overrides: function(detail, u) {
  8155. return {
  8156. type: u.type,
  8157. ignoreFocus: detail.fakeFocus,
  8158. domModification: { classes: [detail.markers.item] }
  8159. };
  8160. }
  8161. })]);
  8162. var schema$m = constant$1([
  8163. required$1("value"),
  8164. required$1("items"),
  8165. required$1("dom"),
  8166. required$1("components"),
  8167. defaulted("eventOrder", {}),
  8168. field("menuBehaviours", [
  8169. Highlighting,
  8170. Representing,
  8171. Composing,
  8172. Keying
  8173. ]),
  8174. defaultedOf("movement", {
  8175. mode: "menu",
  8176. moveOnTab: true
  8177. }, choose$1("mode", {
  8178. grid: [
  8179. initSize(),
  8180. output$1("config", configureGrid)
  8181. ],
  8182. matrix: [
  8183. output$1("config", configureMatrix),
  8184. required$1("rowSelector")
  8185. ],
  8186. menu: [
  8187. defaulted("moveOnTab", true),
  8188. output$1("config", configureMenu)
  8189. ]
  8190. })),
  8191. itemMarkers(),
  8192. defaulted("fakeFocus", false),
  8193. defaulted("focusManager", dom$2()),
  8194. onHandler("onHighlight")
  8195. ]);
  8196. var focus = constant$1("alloy.menu-focus");
  8197. var make$7 = function(detail, components2, _spec, _externals) {
  8198. return {
  8199. uid: detail.uid,
  8200. dom: detail.dom,
  8201. markers: detail.markers,
  8202. behaviours: augment(detail.menuBehaviours, [
  8203. Highlighting.config({
  8204. highlightClass: detail.markers.selectedItem,
  8205. itemClass: detail.markers.item,
  8206. onHighlight: detail.onHighlight
  8207. }),
  8208. Representing.config({
  8209. store: {
  8210. mode: "memory",
  8211. initialValue: detail.value
  8212. }
  8213. }),
  8214. Composing.config({ find: Optional.some }),
  8215. Keying.config(detail.movement.config(detail, detail.movement))
  8216. ]),
  8217. events: derive$2([
  8218. run$1(focus$1(), function(menu2, simulatedEvent) {
  8219. var event = simulatedEvent.event;
  8220. menu2.getSystem().getByDom(event.target).each(function(item2) {
  8221. Highlighting.highlight(menu2, item2);
  8222. simulatedEvent.stop();
  8223. emitWith(menu2, focus(), {
  8224. menu: menu2,
  8225. item: item2
  8226. });
  8227. });
  8228. }),
  8229. run$1(hover(), function(menu2, simulatedEvent) {
  8230. var item2 = simulatedEvent.event.item;
  8231. Highlighting.highlight(menu2, item2);
  8232. })
  8233. ]),
  8234. components: components2,
  8235. eventOrder: detail.eventOrder,
  8236. domModification: { attributes: { role: "menu" } }
  8237. };
  8238. };
  8239. var Menu = composite({
  8240. name: "Menu",
  8241. configFields: schema$m(),
  8242. partFields: parts$g(),
  8243. factory: make$7
  8244. });
  8245. var transpose$1 = function(obj) {
  8246. return tupleMap(obj, function(v, k) {
  8247. return {
  8248. k: v,
  8249. v: k
  8250. };
  8251. });
  8252. };
  8253. var trace = function(items, byItem, byMenu, finish) {
  8254. return get$e(byMenu, finish).bind(function(triggerItem) {
  8255. return get$e(items, triggerItem).bind(function(triggerMenu) {
  8256. var rest = trace(items, byItem, byMenu, triggerMenu);
  8257. return Optional.some([triggerMenu].concat(rest));
  8258. });
  8259. }).getOr([]);
  8260. };
  8261. var generate$2 = function(menus, expansions) {
  8262. var items = {};
  8263. each(menus, function(menuItems, menu2) {
  8264. each$1(menuItems, function(item2) {
  8265. items[item2] = menu2;
  8266. });
  8267. });
  8268. var byItem = expansions;
  8269. var byMenu = transpose$1(expansions);
  8270. var menuPaths = map$1(byMenu, function(_triggerItem, submenu) {
  8271. return [submenu].concat(trace(items, byItem, byMenu, submenu));
  8272. });
  8273. return map$1(items, function(menu2) {
  8274. return get$e(menuPaths, menu2).getOr([menu2]);
  8275. });
  8276. };
  8277. var init$c = function() {
  8278. var expansions = Cell({});
  8279. var menus = Cell({});
  8280. var paths = Cell({});
  8281. var primary = value$1();
  8282. var directory = Cell({});
  8283. var clear2 = function() {
  8284. expansions.set({});
  8285. menus.set({});
  8286. paths.set({});
  8287. primary.clear();
  8288. };
  8289. var isClear = function() {
  8290. return primary.get().isNone();
  8291. };
  8292. var setMenuBuilt = function(menuName, built) {
  8293. var _a2;
  8294. menus.set(__assign(__assign({}, menus.get()), (_a2 = {}, _a2[menuName] = {
  8295. type: "prepared",
  8296. menu: built
  8297. }, _a2)));
  8298. };
  8299. var setContents = function(sPrimary, sMenus, sExpansions, dir) {
  8300. primary.set(sPrimary);
  8301. expansions.set(sExpansions);
  8302. menus.set(sMenus);
  8303. directory.set(dir);
  8304. var sPaths = generate$2(dir, sExpansions);
  8305. paths.set(sPaths);
  8306. };
  8307. var getTriggeringItem = function(menuValue) {
  8308. return find$4(expansions.get(), function(v, _k) {
  8309. return v === menuValue;
  8310. });
  8311. };
  8312. var getTriggerData = function(menuValue, getItemByValue, path2) {
  8313. return getPreparedMenu(menuValue).bind(function(menu2) {
  8314. return getTriggeringItem(menuValue).bind(function(triggeringItemValue) {
  8315. return getItemByValue(triggeringItemValue).map(function(triggeredItem) {
  8316. return {
  8317. triggeredMenu: menu2,
  8318. triggeringItem: triggeredItem,
  8319. triggeringPath: path2
  8320. };
  8321. });
  8322. });
  8323. });
  8324. };
  8325. var getTriggeringPath = function(itemValue, getItemByValue) {
  8326. var extraPath = filter$2(lookupItem(itemValue).toArray(), function(menuValue) {
  8327. return getPreparedMenu(menuValue).isSome();
  8328. });
  8329. return get$e(paths.get(), itemValue).bind(function(path2) {
  8330. var revPath = reverse(extraPath.concat(path2));
  8331. var triggers = bind$3(revPath, function(menuValue, menuIndex) {
  8332. return getTriggerData(menuValue, getItemByValue, revPath.slice(0, menuIndex + 1)).fold(function() {
  8333. return is$1(primary.get(), menuValue) ? [] : [Optional.none()];
  8334. }, function(data) {
  8335. return [Optional.some(data)];
  8336. });
  8337. });
  8338. return sequence(triggers);
  8339. });
  8340. };
  8341. var expand2 = function(itemValue) {
  8342. return get$e(expansions.get(), itemValue).map(function(menu2) {
  8343. var current = get$e(paths.get(), itemValue).getOr([]);
  8344. return [menu2].concat(current);
  8345. });
  8346. };
  8347. var collapse = function(itemValue) {
  8348. return get$e(paths.get(), itemValue).bind(function(path2) {
  8349. return path2.length > 1 ? Optional.some(path2.slice(1)) : Optional.none();
  8350. });
  8351. };
  8352. var refresh2 = function(itemValue) {
  8353. return get$e(paths.get(), itemValue);
  8354. };
  8355. var getPreparedMenu = function(menuValue) {
  8356. return lookupMenu(menuValue).bind(extractPreparedMenu);
  8357. };
  8358. var lookupMenu = function(menuValue) {
  8359. return get$e(menus.get(), menuValue);
  8360. };
  8361. var lookupItem = function(itemValue) {
  8362. return get$e(expansions.get(), itemValue);
  8363. };
  8364. var otherMenus = function(path2) {
  8365. var menuValues = directory.get();
  8366. return difference(keys(menuValues), path2);
  8367. };
  8368. var getPrimary = function() {
  8369. return primary.get().bind(getPreparedMenu);
  8370. };
  8371. var getMenus2 = function() {
  8372. return menus.get();
  8373. };
  8374. return {
  8375. setMenuBuilt,
  8376. setContents,
  8377. expand: expand2,
  8378. refresh: refresh2,
  8379. collapse,
  8380. lookupMenu,
  8381. lookupItem,
  8382. otherMenus,
  8383. getPrimary,
  8384. getMenus: getMenus2,
  8385. clear: clear2,
  8386. isClear,
  8387. getTriggeringPath
  8388. };
  8389. };
  8390. var extractPreparedMenu = function(prep) {
  8391. return prep.type === "prepared" ? Optional.some(prep.menu) : Optional.none();
  8392. };
  8393. var LayeredState = {
  8394. init: init$c,
  8395. extractPreparedMenu
  8396. };
  8397. var make$6 = function(detail, _rawUiSpec) {
  8398. var submenuParentItems = value$1();
  8399. var buildMenus = function(container, primaryName, menus) {
  8400. return map$1(menus, function(spec, name2) {
  8401. var makeSketch = function() {
  8402. return Menu.sketch(__assign(__assign({}, spec), {
  8403. value: name2,
  8404. markers: detail.markers,
  8405. fakeFocus: detail.fakeFocus,
  8406. onHighlight: detail.onHighlight,
  8407. focusManager: detail.fakeFocus ? highlights() : dom$2()
  8408. }));
  8409. };
  8410. return name2 === primaryName ? {
  8411. type: "prepared",
  8412. menu: container.getSystem().build(makeSketch())
  8413. } : {
  8414. type: "notbuilt",
  8415. nbMenu: makeSketch
  8416. };
  8417. });
  8418. };
  8419. var layeredState = LayeredState.init();
  8420. var setup2 = function(container) {
  8421. var componentMap = buildMenus(container, detail.data.primary, detail.data.menus);
  8422. var directory = toDirectory();
  8423. layeredState.setContents(detail.data.primary, componentMap, detail.data.expansions, directory);
  8424. return layeredState.getPrimary();
  8425. };
  8426. var getItemValue = function(item2) {
  8427. return Representing.getValue(item2).value;
  8428. };
  8429. var getItemByValue = function(_container, menus, itemValue) {
  8430. return findMap(menus, function(menu2) {
  8431. if (!menu2.getSystem().isConnected()) {
  8432. return Optional.none();
  8433. }
  8434. var candidates = Highlighting.getCandidates(menu2);
  8435. return find$5(candidates, function(c) {
  8436. return getItemValue(c) === itemValue;
  8437. });
  8438. });
  8439. };
  8440. var toDirectory = function(_container) {
  8441. return map$1(detail.data.menus, function(data, _menuName) {
  8442. return bind$3(data.items, function(item2) {
  8443. return item2.type === "separator" ? [] : [item2.data.value];
  8444. });
  8445. });
  8446. };
  8447. var setActiveMenu = function(container, menu2) {
  8448. Highlighting.highlight(container, menu2);
  8449. Highlighting.getHighlighted(menu2).orThunk(function() {
  8450. return Highlighting.getFirst(menu2);
  8451. }).each(function(item2) {
  8452. dispatch(container, item2.element, focusItem());
  8453. });
  8454. };
  8455. var getMenus2 = function(state, menuValues) {
  8456. return cat(map$2(menuValues, function(mv) {
  8457. return state.lookupMenu(mv).bind(function(prep) {
  8458. return prep.type === "prepared" ? Optional.some(prep.menu) : Optional.none();
  8459. });
  8460. }));
  8461. };
  8462. var closeOthers = function(container, state, path2) {
  8463. var others = getMenus2(state, state.otherMenus(path2));
  8464. each$1(others, function(o) {
  8465. remove$1(o.element, [detail.markers.backgroundMenu]);
  8466. if (!detail.stayInDom) {
  8467. Replacing.remove(container, o);
  8468. }
  8469. });
  8470. };
  8471. var getSubmenuParents = function(container) {
  8472. return submenuParentItems.get().getOrThunk(function() {
  8473. var r2 = {};
  8474. var items = descendants(container.element, "." + detail.markers.item);
  8475. var parentItems = filter$2(items, function(i) {
  8476. return get$d(i, "aria-haspopup") === "true";
  8477. });
  8478. each$1(parentItems, function(i) {
  8479. container.getSystem().getByDom(i).each(function(itemComp) {
  8480. var key = getItemValue(itemComp);
  8481. r2[key] = itemComp;
  8482. });
  8483. });
  8484. submenuParentItems.set(r2);
  8485. return r2;
  8486. });
  8487. };
  8488. var updateAriaExpansions = function(container, path2) {
  8489. var parentItems = getSubmenuParents(container);
  8490. each(parentItems, function(v, k) {
  8491. var expanded = contains$2(path2, k);
  8492. set$8(v.element, "aria-expanded", expanded);
  8493. });
  8494. };
  8495. var updateMenuPath = function(container, state, path2) {
  8496. return Optional.from(path2[0]).bind(function(latestMenuName) {
  8497. return state.lookupMenu(latestMenuName).bind(function(menuPrep) {
  8498. if (menuPrep.type === "notbuilt") {
  8499. return Optional.none();
  8500. } else {
  8501. var activeMenu = menuPrep.menu;
  8502. var rest = getMenus2(state, path2.slice(1));
  8503. each$1(rest, function(r2) {
  8504. add$2(r2.element, detail.markers.backgroundMenu);
  8505. });
  8506. if (!inBody(activeMenu.element)) {
  8507. Replacing.append(container, premade(activeMenu));
  8508. }
  8509. remove$1(activeMenu.element, [detail.markers.backgroundMenu]);
  8510. setActiveMenu(container, activeMenu);
  8511. closeOthers(container, state, path2);
  8512. return Optional.some(activeMenu);
  8513. }
  8514. });
  8515. });
  8516. };
  8517. var ExpandHighlightDecision;
  8518. (function(ExpandHighlightDecision2) {
  8519. ExpandHighlightDecision2[ExpandHighlightDecision2["HighlightSubmenu"] = 0] = "HighlightSubmenu";
  8520. ExpandHighlightDecision2[ExpandHighlightDecision2["HighlightParent"] = 1] = "HighlightParent";
  8521. })(ExpandHighlightDecision || (ExpandHighlightDecision = {}));
  8522. var buildIfRequired = function(container, menuName, menuPrep) {
  8523. if (menuPrep.type === "notbuilt") {
  8524. var menu2 = container.getSystem().build(menuPrep.nbMenu());
  8525. layeredState.setMenuBuilt(menuName, menu2);
  8526. return menu2;
  8527. } else {
  8528. return menuPrep.menu;
  8529. }
  8530. };
  8531. var expandRight = function(container, item2, decision) {
  8532. if (decision === void 0) {
  8533. decision = ExpandHighlightDecision.HighlightSubmenu;
  8534. }
  8535. if (item2.hasConfigured(Disabling) && Disabling.isDisabled(item2)) {
  8536. return Optional.some(item2);
  8537. } else {
  8538. var value2 = getItemValue(item2);
  8539. return layeredState.expand(value2).bind(function(path2) {
  8540. updateAriaExpansions(container, path2);
  8541. return Optional.from(path2[0]).bind(function(menuName) {
  8542. return layeredState.lookupMenu(menuName).bind(function(activeMenuPrep) {
  8543. var activeMenu = buildIfRequired(container, menuName, activeMenuPrep);
  8544. if (!inBody(activeMenu.element)) {
  8545. Replacing.append(container, premade(activeMenu));
  8546. }
  8547. detail.onOpenSubmenu(container, item2, activeMenu, reverse(path2));
  8548. if (decision === ExpandHighlightDecision.HighlightSubmenu) {
  8549. Highlighting.highlightFirst(activeMenu);
  8550. return updateMenuPath(container, layeredState, path2);
  8551. } else {
  8552. Highlighting.dehighlightAll(activeMenu);
  8553. return Optional.some(item2);
  8554. }
  8555. });
  8556. });
  8557. });
  8558. }
  8559. };
  8560. var collapseLeft = function(container, item2) {
  8561. var value2 = getItemValue(item2);
  8562. return layeredState.collapse(value2).bind(function(path2) {
  8563. updateAriaExpansions(container, path2);
  8564. return updateMenuPath(container, layeredState, path2).map(function(activeMenu) {
  8565. detail.onCollapseMenu(container, item2, activeMenu);
  8566. return activeMenu;
  8567. });
  8568. });
  8569. };
  8570. var updateView = function(container, item2) {
  8571. var value2 = getItemValue(item2);
  8572. return layeredState.refresh(value2).bind(function(path2) {
  8573. updateAriaExpansions(container, path2);
  8574. return updateMenuPath(container, layeredState, path2);
  8575. });
  8576. };
  8577. var onRight2 = function(container, item2) {
  8578. return inside(item2.element) ? Optional.none() : expandRight(container, item2, ExpandHighlightDecision.HighlightSubmenu);
  8579. };
  8580. var onLeft2 = function(container, item2) {
  8581. return inside(item2.element) ? Optional.none() : collapseLeft(container, item2);
  8582. };
  8583. var onEscape = function(container, item2) {
  8584. return collapseLeft(container, item2).orThunk(function() {
  8585. return detail.onEscape(container, item2).map(function() {
  8586. return container;
  8587. });
  8588. });
  8589. };
  8590. var keyOnItem = function(f) {
  8591. return function(container, simulatedEvent) {
  8592. return closest$1(simulatedEvent.getSource(), "." + detail.markers.item).bind(function(target) {
  8593. return container.getSystem().getByDom(target).toOptional().bind(function(item2) {
  8594. return f(container, item2).map(always);
  8595. });
  8596. });
  8597. };
  8598. };
  8599. var events2 = derive$2([
  8600. run$1(focus(), function(sandbox, simulatedEvent) {
  8601. var item2 = simulatedEvent.event.item;
  8602. layeredState.lookupItem(getItemValue(item2)).each(function() {
  8603. var menu2 = simulatedEvent.event.menu;
  8604. Highlighting.highlight(sandbox, menu2);
  8605. var value2 = getItemValue(simulatedEvent.event.item);
  8606. layeredState.refresh(value2).each(function(path2) {
  8607. return closeOthers(sandbox, layeredState, path2);
  8608. });
  8609. });
  8610. }),
  8611. runOnExecute$1(function(component, simulatedEvent) {
  8612. var target = simulatedEvent.event.target;
  8613. component.getSystem().getByDom(target).each(function(item2) {
  8614. var itemValue = getItemValue(item2);
  8615. if (itemValue.indexOf("collapse-item") === 0) {
  8616. collapseLeft(component, item2);
  8617. }
  8618. expandRight(component, item2, ExpandHighlightDecision.HighlightSubmenu).fold(function() {
  8619. detail.onExecute(component, item2);
  8620. }, noop);
  8621. });
  8622. }),
  8623. runOnAttached(function(container, _simulatedEvent) {
  8624. setup2(container).each(function(primary) {
  8625. Replacing.append(container, premade(primary));
  8626. detail.onOpenMenu(container, primary);
  8627. if (detail.highlightImmediately) {
  8628. setActiveMenu(container, primary);
  8629. }
  8630. });
  8631. })
  8632. ].concat(detail.navigateOnHover ? [run$1(hover(), function(sandbox, simulatedEvent) {
  8633. var item2 = simulatedEvent.event.item;
  8634. updateView(sandbox, item2);
  8635. expandRight(sandbox, item2, ExpandHighlightDecision.HighlightParent);
  8636. detail.onHover(sandbox, item2);
  8637. })] : []));
  8638. var getActiveItem = function(container) {
  8639. return Highlighting.getHighlighted(container).bind(Highlighting.getHighlighted);
  8640. };
  8641. var collapseMenuApi = function(container) {
  8642. getActiveItem(container).each(function(currentItem) {
  8643. collapseLeft(container, currentItem);
  8644. });
  8645. };
  8646. var highlightPrimary = function(container) {
  8647. layeredState.getPrimary().each(function(primary) {
  8648. setActiveMenu(container, primary);
  8649. });
  8650. };
  8651. var extractMenuFromContainer = function(container) {
  8652. return Optional.from(container.components()[0]).filter(function(comp) {
  8653. return get$d(comp.element, "role") === "menu";
  8654. });
  8655. };
  8656. var repositionMenus2 = function(container) {
  8657. var maybeActivePrimary = layeredState.getPrimary().bind(function(primary) {
  8658. return getActiveItem(container).bind(function(currentItem) {
  8659. var itemValue = getItemValue(currentItem);
  8660. var allMenus = values(layeredState.getMenus());
  8661. var preparedMenus = cat(map$2(allMenus, LayeredState.extractPreparedMenu));
  8662. return layeredState.getTriggeringPath(itemValue, function(v) {
  8663. return getItemByValue(container, preparedMenus, v);
  8664. });
  8665. }).map(function(triggeringPath) {
  8666. return {
  8667. primary,
  8668. triggeringPath
  8669. };
  8670. });
  8671. });
  8672. maybeActivePrimary.fold(function() {
  8673. extractMenuFromContainer(container).each(function(primaryMenu) {
  8674. detail.onRepositionMenu(container, primaryMenu, []);
  8675. });
  8676. }, function(_a2) {
  8677. var primary = _a2.primary, triggeringPath = _a2.triggeringPath;
  8678. detail.onRepositionMenu(container, primary, triggeringPath);
  8679. });
  8680. };
  8681. var apis = {
  8682. collapseMenu: collapseMenuApi,
  8683. highlightPrimary,
  8684. repositionMenus: repositionMenus2
  8685. };
  8686. return {
  8687. uid: detail.uid,
  8688. dom: detail.dom,
  8689. markers: detail.markers,
  8690. behaviours: augment(detail.tmenuBehaviours, [
  8691. Keying.config({
  8692. mode: "special",
  8693. onRight: keyOnItem(onRight2),
  8694. onLeft: keyOnItem(onLeft2),
  8695. onEscape: keyOnItem(onEscape),
  8696. focusIn: function(container, _keyInfo) {
  8697. layeredState.getPrimary().each(function(primary) {
  8698. dispatch(container, primary.element, focusItem());
  8699. });
  8700. }
  8701. }),
  8702. Highlighting.config({
  8703. highlightClass: detail.markers.selectedMenu,
  8704. itemClass: detail.markers.menu
  8705. }),
  8706. Composing.config({
  8707. find: function(container) {
  8708. return Highlighting.getHighlighted(container);
  8709. }
  8710. }),
  8711. Replacing.config({})
  8712. ]),
  8713. eventOrder: detail.eventOrder,
  8714. apis,
  8715. events: events2
  8716. };
  8717. };
  8718. var collapseItem$1 = constant$1("collapse-item");
  8719. var tieredData = function(primary, menus, expansions) {
  8720. return {
  8721. primary,
  8722. menus,
  8723. expansions
  8724. };
  8725. };
  8726. var singleData = function(name2, menu2) {
  8727. return {
  8728. primary: name2,
  8729. menus: wrap$1(name2, menu2),
  8730. expansions: {}
  8731. };
  8732. };
  8733. var collapseItem = function(text2) {
  8734. return {
  8735. value: generate$6(collapseItem$1()),
  8736. meta: { text: text2 }
  8737. };
  8738. };
  8739. var tieredMenu = single({
  8740. name: "TieredMenu",
  8741. configFields: [
  8742. onStrictKeyboardHandler("onExecute"),
  8743. onStrictKeyboardHandler("onEscape"),
  8744. onStrictHandler("onOpenMenu"),
  8745. onStrictHandler("onOpenSubmenu"),
  8746. onHandler("onRepositionMenu"),
  8747. onHandler("onCollapseMenu"),
  8748. defaulted("highlightImmediately", true),
  8749. requiredObjOf("data", [
  8750. required$1("primary"),
  8751. required$1("menus"),
  8752. required$1("expansions")
  8753. ]),
  8754. defaulted("fakeFocus", false),
  8755. onHandler("onHighlight"),
  8756. onHandler("onHover"),
  8757. tieredMenuMarkers(),
  8758. required$1("dom"),
  8759. defaulted("navigateOnHover", true),
  8760. defaulted("stayInDom", false),
  8761. field("tmenuBehaviours", [
  8762. Keying,
  8763. Highlighting,
  8764. Composing,
  8765. Replacing
  8766. ]),
  8767. defaulted("eventOrder", {})
  8768. ],
  8769. apis: {
  8770. collapseMenu: function(apis, tmenu) {
  8771. apis.collapseMenu(tmenu);
  8772. },
  8773. highlightPrimary: function(apis, tmenu) {
  8774. apis.highlightPrimary(tmenu);
  8775. },
  8776. repositionMenus: function(apis, tmenu) {
  8777. apis.repositionMenus(tmenu);
  8778. }
  8779. },
  8780. factory: make$6,
  8781. extraApis: {
  8782. tieredData,
  8783. singleData,
  8784. collapseItem
  8785. }
  8786. });
  8787. var makeMenu = function(detail, menuSandbox, placementSpec, menuSpec, getBounds2) {
  8788. var lazySink = function() {
  8789. return detail.lazySink(menuSandbox);
  8790. };
  8791. var layouts2 = menuSpec.type === "horizontal" ? {
  8792. layouts: {
  8793. onLtr: function() {
  8794. return belowOrAbove();
  8795. },
  8796. onRtl: function() {
  8797. return belowOrAboveRtl();
  8798. }
  8799. }
  8800. } : {};
  8801. var isFirstTierSubmenu = function(triggeringPaths) {
  8802. return triggeringPaths.length === 2;
  8803. };
  8804. var getSubmenuLayouts = function(triggeringPaths) {
  8805. return isFirstTierSubmenu(triggeringPaths) ? layouts2 : {};
  8806. };
  8807. return tieredMenu.sketch({
  8808. dom: { tag: "div" },
  8809. data: menuSpec.data,
  8810. markers: menuSpec.menu.markers,
  8811. highlightImmediately: menuSpec.menu.highlightImmediately,
  8812. onEscape: function() {
  8813. Sandboxing.close(menuSandbox);
  8814. detail.onEscape.map(function(handler) {
  8815. return handler(menuSandbox);
  8816. });
  8817. return Optional.some(true);
  8818. },
  8819. onExecute: function() {
  8820. return Optional.some(true);
  8821. },
  8822. onOpenMenu: function(tmenu, menu2) {
  8823. Positioning.positionWithinBounds(lazySink().getOrDie(), menu2, placementSpec, getBounds2());
  8824. },
  8825. onOpenSubmenu: function(tmenu, item2, submenu, triggeringPaths) {
  8826. var sink = lazySink().getOrDie();
  8827. Positioning.position(sink, submenu, {
  8828. anchor: __assign({
  8829. type: "submenu",
  8830. item: item2
  8831. }, getSubmenuLayouts(triggeringPaths))
  8832. });
  8833. },
  8834. onRepositionMenu: function(tmenu, primaryMenu, submenuTriggers) {
  8835. var sink = lazySink().getOrDie();
  8836. Positioning.positionWithinBounds(sink, primaryMenu, placementSpec, getBounds2());
  8837. each$1(submenuTriggers, function(st) {
  8838. var submenuLayouts = getSubmenuLayouts(st.triggeringPath);
  8839. Positioning.position(sink, st.triggeredMenu, {
  8840. anchor: __assign({
  8841. type: "submenu",
  8842. item: st.triggeringItem
  8843. }, submenuLayouts)
  8844. });
  8845. });
  8846. }
  8847. });
  8848. };
  8849. var factory$m = function(detail, spec) {
  8850. var isPartOfRelated = function(sandbox, queryElem) {
  8851. var related = detail.getRelated(sandbox);
  8852. return related.exists(function(rel) {
  8853. return isPartOf$1(rel, queryElem);
  8854. });
  8855. };
  8856. var setContent2 = function(sandbox, thing) {
  8857. Sandboxing.setContent(sandbox, thing);
  8858. };
  8859. var showAt = function(sandbox, thing, placementSpec) {
  8860. showWithin(sandbox, thing, placementSpec, Optional.none());
  8861. };
  8862. var showWithin = function(sandbox, thing, placementSpec, boxElement) {
  8863. showWithinBounds(sandbox, thing, placementSpec, function() {
  8864. return boxElement.map(function(elem) {
  8865. return box$1(elem);
  8866. });
  8867. });
  8868. };
  8869. var showWithinBounds = function(sandbox, thing, placementSpec, getBounds2) {
  8870. var sink = detail.lazySink(sandbox).getOrDie();
  8871. Sandboxing.openWhileCloaked(sandbox, thing, function() {
  8872. return Positioning.positionWithinBounds(sink, sandbox, placementSpec, getBounds2());
  8873. });
  8874. Representing.setValue(sandbox, Optional.some({
  8875. mode: "position",
  8876. config: placementSpec,
  8877. getBounds: getBounds2
  8878. }));
  8879. };
  8880. var showMenuAt = function(sandbox, placementSpec, menuSpec) {
  8881. showMenuWithinBounds(sandbox, placementSpec, menuSpec, Optional.none);
  8882. };
  8883. var showMenuWithinBounds = function(sandbox, placementSpec, menuSpec, getBounds2) {
  8884. var menu2 = makeMenu(detail, sandbox, placementSpec, menuSpec, getBounds2);
  8885. Sandboxing.open(sandbox, menu2);
  8886. Representing.setValue(sandbox, Optional.some({
  8887. mode: "menu",
  8888. menu: menu2
  8889. }));
  8890. };
  8891. var hide = function(sandbox) {
  8892. if (Sandboxing.isOpen(sandbox)) {
  8893. Representing.setValue(sandbox, Optional.none());
  8894. Sandboxing.close(sandbox);
  8895. }
  8896. };
  8897. var getContent = function(sandbox) {
  8898. return Sandboxing.getState(sandbox);
  8899. };
  8900. var reposition2 = function(sandbox) {
  8901. if (Sandboxing.isOpen(sandbox)) {
  8902. Representing.getValue(sandbox).each(function(state) {
  8903. switch (state.mode) {
  8904. case "menu":
  8905. Sandboxing.getState(sandbox).each(tieredMenu.repositionMenus);
  8906. break;
  8907. case "position":
  8908. var sink = detail.lazySink(sandbox).getOrDie();
  8909. Positioning.positionWithinBounds(sink, sandbox, state.config, state.getBounds());
  8910. break;
  8911. }
  8912. });
  8913. }
  8914. };
  8915. var apis = {
  8916. setContent: setContent2,
  8917. showAt,
  8918. showWithin,
  8919. showWithinBounds,
  8920. showMenuAt,
  8921. showMenuWithinBounds,
  8922. hide,
  8923. getContent,
  8924. reposition: reposition2,
  8925. isOpen: Sandboxing.isOpen
  8926. };
  8927. return {
  8928. uid: detail.uid,
  8929. dom: detail.dom,
  8930. behaviours: augment(detail.inlineBehaviours, [
  8931. Sandboxing.config({
  8932. isPartOf: function(sandbox, data, queryElem) {
  8933. return isPartOf$1(data, queryElem) || isPartOfRelated(sandbox, queryElem);
  8934. },
  8935. getAttachPoint: function(sandbox) {
  8936. return detail.lazySink(sandbox).getOrDie();
  8937. },
  8938. onOpen: function(sandbox) {
  8939. detail.onShow(sandbox);
  8940. },
  8941. onClose: function(sandbox) {
  8942. detail.onHide(sandbox);
  8943. }
  8944. }),
  8945. Representing.config({
  8946. store: {
  8947. mode: "memory",
  8948. initialValue: Optional.none()
  8949. }
  8950. }),
  8951. Receiving.config({
  8952. channels: __assign(__assign({}, receivingChannel$1(__assign({ isExtraPart: spec.isExtraPart }, detail.fireDismissalEventInstead.map(function(fe) {
  8953. return { fireEventInstead: { event: fe.event } };
  8954. }).getOr({})))), receivingChannel(__assign(__assign({}, detail.fireRepositionEventInstead.map(function(fe) {
  8955. return { fireEventInstead: { event: fe.event } };
  8956. }).getOr({})), { doReposition: reposition2 })))
  8957. })
  8958. ]),
  8959. eventOrder: detail.eventOrder,
  8960. apis
  8961. };
  8962. };
  8963. var InlineView = single({
  8964. name: "InlineView",
  8965. configFields: [
  8966. required$1("lazySink"),
  8967. onHandler("onShow"),
  8968. onHandler("onHide"),
  8969. optionFunction("onEscape"),
  8970. field("inlineBehaviours", [
  8971. Sandboxing,
  8972. Representing,
  8973. Receiving
  8974. ]),
  8975. optionObjOf("fireDismissalEventInstead", [defaulted("event", dismissRequested())]),
  8976. optionObjOf("fireRepositionEventInstead", [defaulted("event", repositionRequested())]),
  8977. defaulted("getRelated", Optional.none),
  8978. defaulted("isExtraPart", never),
  8979. defaulted("eventOrder", Optional.none)
  8980. ],
  8981. factory: factory$m,
  8982. apis: {
  8983. showAt: function(apis, component, anchor2, thing) {
  8984. apis.showAt(component, anchor2, thing);
  8985. },
  8986. showWithin: function(apis, component, anchor2, thing, boxElement) {
  8987. apis.showWithin(component, anchor2, thing, boxElement);
  8988. },
  8989. showWithinBounds: function(apis, component, anchor2, thing, bounds2) {
  8990. apis.showWithinBounds(component, anchor2, thing, bounds2);
  8991. },
  8992. showMenuAt: function(apis, component, anchor2, menuSpec) {
  8993. apis.showMenuAt(component, anchor2, menuSpec);
  8994. },
  8995. showMenuWithinBounds: function(apis, component, anchor2, menuSpec, bounds2) {
  8996. apis.showMenuWithinBounds(component, anchor2, menuSpec, bounds2);
  8997. },
  8998. hide: function(apis, component) {
  8999. apis.hide(component);
  9000. },
  9001. isOpen: function(apis, component) {
  9002. return apis.isOpen(component);
  9003. },
  9004. getContent: function(apis, component) {
  9005. return apis.getContent(component);
  9006. },
  9007. setContent: function(apis, component, thing) {
  9008. apis.setContent(component, thing);
  9009. },
  9010. reposition: function(apis, component) {
  9011. apis.reposition(component);
  9012. }
  9013. }
  9014. });
  9015. var labelPrefix = "layout-inset";
  9016. var westEdgeX = function(anchor2) {
  9017. return anchor2.x;
  9018. };
  9019. var middleX = function(anchor2, element2) {
  9020. return anchor2.x + anchor2.width / 2 - element2.width / 2;
  9021. };
  9022. var eastEdgeX = function(anchor2, element2) {
  9023. return anchor2.x + anchor2.width - element2.width;
  9024. };
  9025. var northY = function(anchor2) {
  9026. return anchor2.y;
  9027. };
  9028. var southY = function(anchor2, element2) {
  9029. return anchor2.y + anchor2.height - element2.height;
  9030. };
  9031. var centreY = function(anchor2, element2) {
  9032. return anchor2.y + anchor2.height / 2 - element2.height / 2;
  9033. };
  9034. var southwest = function(anchor2, element2, bubbles) {
  9035. return nu$6(eastEdgeX(anchor2, element2), southY(anchor2, element2), bubbles.insetSouthwest(), northwest$3(), "southwest", boundsRestriction(anchor2, {
  9036. right: 0,
  9037. bottom: 3
  9038. }), labelPrefix);
  9039. };
  9040. var southeast = function(anchor2, element2, bubbles) {
  9041. return nu$6(westEdgeX(anchor2), southY(anchor2, element2), bubbles.insetSoutheast(), northeast$3(), "southeast", boundsRestriction(anchor2, {
  9042. left: 1,
  9043. bottom: 3
  9044. }), labelPrefix);
  9045. };
  9046. var northwest = function(anchor2, element2, bubbles) {
  9047. return nu$6(eastEdgeX(anchor2, element2), northY(anchor2), bubbles.insetNorthwest(), southwest$3(), "northwest", boundsRestriction(anchor2, {
  9048. right: 0,
  9049. top: 2
  9050. }), labelPrefix);
  9051. };
  9052. var northeast = function(anchor2, element2, bubbles) {
  9053. return nu$6(westEdgeX(anchor2), northY(anchor2), bubbles.insetNortheast(), southeast$3(), "northeast", boundsRestriction(anchor2, {
  9054. left: 1,
  9055. top: 2
  9056. }), labelPrefix);
  9057. };
  9058. var north = function(anchor2, element2, bubbles) {
  9059. return nu$6(middleX(anchor2, element2), northY(anchor2), bubbles.insetNorth(), south$3(), "north", boundsRestriction(anchor2, { top: 2 }), labelPrefix);
  9060. };
  9061. var south = function(anchor2, element2, bubbles) {
  9062. return nu$6(middleX(anchor2, element2), southY(anchor2, element2), bubbles.insetSouth(), north$3(), "south", boundsRestriction(anchor2, { bottom: 3 }), labelPrefix);
  9063. };
  9064. var east = function(anchor2, element2, bubbles) {
  9065. return nu$6(eastEdgeX(anchor2, element2), centreY(anchor2, element2), bubbles.insetEast(), west$3(), "east", boundsRestriction(anchor2, { right: 0 }), labelPrefix);
  9066. };
  9067. var west = function(anchor2, element2, bubbles) {
  9068. return nu$6(westEdgeX(anchor2), centreY(anchor2, element2), bubbles.insetWest(), east$3(), "west", boundsRestriction(anchor2, { left: 1 }), labelPrefix);
  9069. };
  9070. var lookupPreserveLayout = function(lastPlacement) {
  9071. switch (lastPlacement) {
  9072. case "north":
  9073. return north;
  9074. case "northeast":
  9075. return northeast;
  9076. case "northwest":
  9077. return northwest;
  9078. case "south":
  9079. return south;
  9080. case "southeast":
  9081. return southeast;
  9082. case "southwest":
  9083. return southwest;
  9084. case "east":
  9085. return east;
  9086. case "west":
  9087. return west;
  9088. }
  9089. };
  9090. var preserve = function(anchor2, element2, bubbles, placee, bounds2) {
  9091. var layout2 = getPlacement(placee).map(lookupPreserveLayout).getOr(north);
  9092. return layout2(anchor2, element2, bubbles, placee, bounds2);
  9093. };
  9094. var lookupFlippedLayout = function(lastPlacement) {
  9095. switch (lastPlacement) {
  9096. case "north":
  9097. return south;
  9098. case "northeast":
  9099. return southeast;
  9100. case "northwest":
  9101. return southwest;
  9102. case "south":
  9103. return north;
  9104. case "southeast":
  9105. return northeast;
  9106. case "southwest":
  9107. return northwest;
  9108. case "east":
  9109. return west;
  9110. case "west":
  9111. return east;
  9112. }
  9113. };
  9114. var flip$2 = function(anchor2, element2, bubbles, placee, bounds2) {
  9115. var layout2 = getPlacement(placee).map(lookupFlippedLayout).getOr(north);
  9116. return layout2(anchor2, element2, bubbles, placee, bounds2);
  9117. };
  9118. var global$f = tinymce.util.Tools.resolve("tinymce.util.Delay");
  9119. var factory$l = function(detail) {
  9120. var events2 = events$a(detail.action);
  9121. var tag = detail.dom.tag;
  9122. var lookupAttr = function(attr) {
  9123. return get$e(detail.dom, "attributes").bind(function(attrs) {
  9124. return get$e(attrs, attr);
  9125. });
  9126. };
  9127. var getModAttributes = function() {
  9128. if (tag === "button") {
  9129. var type2 = lookupAttr("type").getOr("button");
  9130. var roleAttrs = lookupAttr("role").map(function(role2) {
  9131. return { role: role2 };
  9132. }).getOr({});
  9133. return __assign({ type: type2 }, roleAttrs);
  9134. } else {
  9135. var role = lookupAttr("role").getOr("button");
  9136. return { role };
  9137. }
  9138. };
  9139. return {
  9140. uid: detail.uid,
  9141. dom: detail.dom,
  9142. components: detail.components,
  9143. events: events2,
  9144. behaviours: SketchBehaviours.augment(detail.buttonBehaviours, [
  9145. Focusing.config({}),
  9146. Keying.config({
  9147. mode: "execution",
  9148. useSpace: true,
  9149. useEnter: true
  9150. })
  9151. ]),
  9152. domModification: { attributes: getModAttributes() },
  9153. eventOrder: detail.eventOrder
  9154. };
  9155. };
  9156. var Button = single({
  9157. name: "Button",
  9158. factory: factory$l,
  9159. configFields: [
  9160. defaulted("uid", void 0),
  9161. required$1("dom"),
  9162. defaulted("components", []),
  9163. SketchBehaviours.field("buttonBehaviours", [
  9164. Focusing,
  9165. Keying
  9166. ]),
  9167. option("action"),
  9168. option("role"),
  9169. defaulted("eventOrder", {})
  9170. ]
  9171. });
  9172. var record = function(spec) {
  9173. var uid = isSketchSpec(spec) && hasNonNullableKey(spec, "uid") ? spec.uid : generate$5("memento");
  9174. var get2 = function(anyInSystem) {
  9175. return anyInSystem.getSystem().getByUid(uid).getOrDie();
  9176. };
  9177. var getOpt2 = function(anyInSystem) {
  9178. return anyInSystem.getSystem().getByUid(uid).toOptional();
  9179. };
  9180. var asSpec = function() {
  9181. return __assign(__assign({}, spec), { uid });
  9182. };
  9183. return {
  9184. get: get2,
  9185. getOpt: getOpt2,
  9186. asSpec
  9187. };
  9188. };
  9189. var global$e = tinymce.util.Tools.resolve("tinymce.util.I18n");
  9190. var rtlTransform = {
  9191. "indent": true,
  9192. "outdent": true,
  9193. "table-insert-column-after": true,
  9194. "table-insert-column-before": true,
  9195. "paste-column-after": true,
  9196. "paste-column-before": true,
  9197. "unordered-list": true,
  9198. "list-bull-circle": true,
  9199. "list-bull-default": true,
  9200. "list-bull-square": true
  9201. };
  9202. var defaultIconName = "temporary-placeholder";
  9203. var defaultIcon = function(icons) {
  9204. return function() {
  9205. return get$e(icons, defaultIconName).getOr("!not found!");
  9206. };
  9207. };
  9208. var getIconName = function(name2, icons) {
  9209. var lcName = name2.toLowerCase();
  9210. if (global$e.isRtl()) {
  9211. var rtlName = ensureTrailing(lcName, "-rtl");
  9212. return has$2(icons, rtlName) ? rtlName : lcName;
  9213. } else {
  9214. return lcName;
  9215. }
  9216. };
  9217. var lookupIcon = function(name2, icons) {
  9218. return get$e(icons, getIconName(name2, icons));
  9219. };
  9220. var get$1 = function(name2, iconProvider) {
  9221. var icons = iconProvider();
  9222. return lookupIcon(name2, icons).getOrThunk(defaultIcon(icons));
  9223. };
  9224. var getOr = function(name2, iconProvider, fallbackIcon) {
  9225. var icons = iconProvider();
  9226. return lookupIcon(name2, icons).or(fallbackIcon).getOrThunk(defaultIcon(icons));
  9227. };
  9228. var needsRtlTransform = function(iconName) {
  9229. return global$e.isRtl() ? has$2(rtlTransform, iconName) : false;
  9230. };
  9231. var addFocusableBehaviour = function() {
  9232. return config("add-focusable", [runOnAttached(function(comp) {
  9233. child(comp.element, "svg").each(function(svg) {
  9234. return set$8(svg, "focusable", "false");
  9235. });
  9236. })]);
  9237. };
  9238. var renderIcon$2 = function(spec, iconName, icons, fallbackIcon) {
  9239. var _a2, _b;
  9240. var rtlIconClasses = needsRtlTransform(iconName) ? ["tox-icon--flip"] : [];
  9241. var iconHtml = get$e(icons, getIconName(iconName, icons)).or(fallbackIcon).getOrThunk(defaultIcon(icons));
  9242. return {
  9243. dom: {
  9244. tag: spec.tag,
  9245. attributes: (_a2 = spec.attributes) !== null && _a2 !== void 0 ? _a2 : {},
  9246. classes: spec.classes.concat(rtlIconClasses),
  9247. innerHtml: iconHtml
  9248. },
  9249. behaviours: derive$1(__spreadArray(__spreadArray([], (_b = spec.behaviours) !== null && _b !== void 0 ? _b : [], true), [addFocusableBehaviour()], false))
  9250. };
  9251. };
  9252. var render$3 = function(iconName, spec, iconProvider, fallbackIcon) {
  9253. if (fallbackIcon === void 0) {
  9254. fallbackIcon = Optional.none();
  9255. }
  9256. return renderIcon$2(spec, iconName, iconProvider(), fallbackIcon);
  9257. };
  9258. var renderFirst = function(iconNames, spec, iconProvider) {
  9259. var icons = iconProvider();
  9260. var iconName = find$5(iconNames, function(name2) {
  9261. return has$2(icons, getIconName(name2, icons));
  9262. });
  9263. return renderIcon$2(spec, iconName.getOr(defaultIconName), icons, Optional.none());
  9264. };
  9265. var notificationIconMap = {
  9266. success: "checkmark",
  9267. error: "warning",
  9268. err: "error",
  9269. warning: "warning",
  9270. warn: "warning",
  9271. info: "info"
  9272. };
  9273. var factory$k = function(detail) {
  9274. var memBannerText = record({
  9275. dom: {
  9276. tag: "p",
  9277. innerHtml: detail.translationProvider(detail.text)
  9278. },
  9279. behaviours: derive$1([Replacing.config({})])
  9280. });
  9281. var renderPercentBar = function(percent) {
  9282. return {
  9283. dom: {
  9284. tag: "div",
  9285. classes: ["tox-bar"],
  9286. attributes: { style: "width: " + percent + "%" }
  9287. }
  9288. };
  9289. };
  9290. var renderPercentText = function(percent) {
  9291. return {
  9292. dom: {
  9293. tag: "div",
  9294. classes: ["tox-text"],
  9295. innerHtml: percent + "%"
  9296. }
  9297. };
  9298. };
  9299. var memBannerProgress = record({
  9300. dom: {
  9301. tag: "div",
  9302. classes: detail.progress ? [
  9303. "tox-progress-bar",
  9304. "tox-progress-indicator"
  9305. ] : ["tox-progress-bar"]
  9306. },
  9307. components: [
  9308. {
  9309. dom: {
  9310. tag: "div",
  9311. classes: ["tox-bar-container"]
  9312. },
  9313. components: [renderPercentBar(0)]
  9314. },
  9315. renderPercentText(0)
  9316. ],
  9317. behaviours: derive$1([Replacing.config({})])
  9318. });
  9319. var updateProgress = function(comp, percent) {
  9320. if (comp.getSystem().isConnected()) {
  9321. memBannerProgress.getOpt(comp).each(function(progress) {
  9322. Replacing.set(progress, [
  9323. {
  9324. dom: {
  9325. tag: "div",
  9326. classes: ["tox-bar-container"]
  9327. },
  9328. components: [renderPercentBar(percent)]
  9329. },
  9330. renderPercentText(percent)
  9331. ]);
  9332. });
  9333. }
  9334. };
  9335. var updateText = function(comp, text$1) {
  9336. if (comp.getSystem().isConnected()) {
  9337. var banner = memBannerText.get(comp);
  9338. Replacing.set(banner, [text(text$1)]);
  9339. }
  9340. };
  9341. var apis = {
  9342. updateProgress,
  9343. updateText
  9344. };
  9345. var iconChoices = flatten([
  9346. detail.icon.toArray(),
  9347. detail.level.toArray(),
  9348. detail.level.bind(function(level) {
  9349. return Optional.from(notificationIconMap[level]);
  9350. }).toArray()
  9351. ]);
  9352. var memButton = record(Button.sketch({
  9353. dom: {
  9354. tag: "button",
  9355. classes: [
  9356. "tox-notification__dismiss",
  9357. "tox-button",
  9358. "tox-button--naked",
  9359. "tox-button--icon"
  9360. ]
  9361. },
  9362. components: [render$3("close", {
  9363. tag: "div",
  9364. classes: ["tox-icon"],
  9365. attributes: { "aria-label": detail.translationProvider("Close") }
  9366. }, detail.iconProvider)],
  9367. action: function(comp) {
  9368. detail.onAction(comp);
  9369. }
  9370. }));
  9371. var notificationIconSpec = renderFirst(iconChoices, {
  9372. tag: "div",
  9373. classes: ["tox-notification__icon"]
  9374. }, detail.iconProvider);
  9375. var notificationBodySpec = {
  9376. dom: {
  9377. tag: "div",
  9378. classes: ["tox-notification__body"]
  9379. },
  9380. components: [memBannerText.asSpec()],
  9381. behaviours: derive$1([Replacing.config({})])
  9382. };
  9383. var components2 = [
  9384. notificationIconSpec,
  9385. notificationBodySpec
  9386. ];
  9387. return {
  9388. uid: detail.uid,
  9389. dom: {
  9390. tag: "div",
  9391. attributes: { role: "alert" },
  9392. classes: detail.level.map(function(level) {
  9393. return [
  9394. "tox-notification",
  9395. "tox-notification--in",
  9396. "tox-notification--" + level
  9397. ];
  9398. }).getOr([
  9399. "tox-notification",
  9400. "tox-notification--in"
  9401. ])
  9402. },
  9403. behaviours: derive$1([
  9404. Focusing.config({}),
  9405. config("notification-events", [run$1(focusin(), function(comp) {
  9406. memButton.getOpt(comp).each(Focusing.focus);
  9407. })])
  9408. ]),
  9409. components: components2.concat(detail.progress ? [memBannerProgress.asSpec()] : []).concat(!detail.closeButton ? [] : [memButton.asSpec()]),
  9410. apis
  9411. };
  9412. };
  9413. var Notification = single({
  9414. name: "Notification",
  9415. factory: factory$k,
  9416. configFields: [
  9417. option("level"),
  9418. required$1("progress"),
  9419. required$1("icon"),
  9420. required$1("onAction"),
  9421. required$1("text"),
  9422. required$1("iconProvider"),
  9423. required$1("translationProvider"),
  9424. defaultedBoolean("closeButton", true)
  9425. ],
  9426. apis: {
  9427. updateProgress: function(apis, comp, percent) {
  9428. apis.updateProgress(comp, percent);
  9429. },
  9430. updateText: function(apis, comp, text2) {
  9431. apis.updateText(comp, text2);
  9432. }
  9433. }
  9434. });
  9435. function NotificationManagerImpl(editor, extras, uiMothership) {
  9436. var sharedBackstage = extras.backstage.shared;
  9437. var getLayoutDirection = function(rel) {
  9438. switch (rel) {
  9439. case "bc-bc":
  9440. return south;
  9441. case "tc-tc":
  9442. return north;
  9443. case "tc-bc":
  9444. return north$2;
  9445. case "bc-tc":
  9446. default:
  9447. return south$2;
  9448. }
  9449. };
  9450. var reposition2 = function(notifications) {
  9451. if (notifications.length > 0) {
  9452. each$1(notifications, function(notification, index) {
  9453. if (index === 0) {
  9454. notification.moveRel(null, "banner");
  9455. } else {
  9456. notification.moveRel(notifications[index - 1].getEl(), "bc-tc");
  9457. }
  9458. });
  9459. }
  9460. };
  9461. var open2 = function(settings, closeCallback) {
  9462. var hideCloseButton = !settings.closeButton && settings.timeout && (settings.timeout > 0 || settings.timeout < 0);
  9463. var close3 = function() {
  9464. closeCallback();
  9465. InlineView.hide(notificationWrapper);
  9466. };
  9467. var notification = build$1(Notification.sketch({
  9468. text: settings.text,
  9469. level: contains$2([
  9470. "success",
  9471. "error",
  9472. "warning",
  9473. "warn",
  9474. "info"
  9475. ], settings.type) ? settings.type : void 0,
  9476. progress: settings.progressBar === true,
  9477. icon: Optional.from(settings.icon),
  9478. closeButton: !hideCloseButton,
  9479. onAction: close3,
  9480. iconProvider: sharedBackstage.providers.icons,
  9481. translationProvider: sharedBackstage.providers.translate
  9482. }));
  9483. var notificationWrapper = build$1(InlineView.sketch(__assign({
  9484. dom: {
  9485. tag: "div",
  9486. classes: ["tox-notifications-container"]
  9487. },
  9488. lazySink: sharedBackstage.getSink,
  9489. fireDismissalEventInstead: {}
  9490. }, sharedBackstage.header.isPositionedAtTop() ? {} : { fireRepositionEventInstead: {} })));
  9491. uiMothership.add(notificationWrapper);
  9492. if (settings.timeout > 0) {
  9493. global$f.setTimeout(function() {
  9494. close3();
  9495. }, settings.timeout);
  9496. }
  9497. var getBounds2 = function() {
  9498. var contentArea = box$1(SugarElement.fromDom(editor.getContentAreaContainer()));
  9499. var win$1 = win();
  9500. var x = clamp$1(win$1.x, contentArea.x, contentArea.right);
  9501. var y = clamp$1(win$1.y, contentArea.y, contentArea.bottom);
  9502. var right2 = Math.max(contentArea.right, win$1.right);
  9503. var bottom2 = Math.max(contentArea.bottom, win$1.bottom);
  9504. return Optional.some(bounds(x, y, right2 - x, bottom2 - y));
  9505. };
  9506. return {
  9507. close: close3,
  9508. moveTo: function(x, y) {
  9509. InlineView.showAt(notificationWrapper, premade(notification), {
  9510. anchor: {
  9511. type: "makeshift",
  9512. x,
  9513. y
  9514. }
  9515. });
  9516. },
  9517. moveRel: function(element2, rel) {
  9518. var notificationSpec = premade(notification);
  9519. var anchorOverrides2 = { maxHeightFunction: expandable$1() };
  9520. if (rel !== "banner" && isNonNullable(element2)) {
  9521. var layoutDirection_1 = getLayoutDirection(rel);
  9522. var nodeAnchor = {
  9523. type: "node",
  9524. root: body(),
  9525. node: Optional.some(SugarElement.fromDom(element2)),
  9526. overrides: anchorOverrides2,
  9527. layouts: {
  9528. onRtl: function() {
  9529. return [layoutDirection_1];
  9530. },
  9531. onLtr: function() {
  9532. return [layoutDirection_1];
  9533. }
  9534. }
  9535. };
  9536. InlineView.showWithinBounds(notificationWrapper, notificationSpec, { anchor: nodeAnchor }, getBounds2);
  9537. } else {
  9538. var anchor2 = __assign(__assign({}, sharedBackstage.anchors.banner()), { overrides: anchorOverrides2 });
  9539. InlineView.showWithinBounds(notificationWrapper, notificationSpec, { anchor: anchor2 }, getBounds2);
  9540. }
  9541. },
  9542. text: function(nuText) {
  9543. Notification.updateText(notification, nuText);
  9544. },
  9545. settings,
  9546. getEl: function() {
  9547. return notification.element.dom;
  9548. },
  9549. progressBar: {
  9550. value: function(percent) {
  9551. Notification.updateProgress(notification, percent);
  9552. }
  9553. }
  9554. };
  9555. };
  9556. var close2 = function(notification) {
  9557. notification.close();
  9558. };
  9559. var getArgs = function(notification) {
  9560. return notification.settings;
  9561. };
  9562. return {
  9563. open: open2,
  9564. close: close2,
  9565. reposition: reposition2,
  9566. getArgs
  9567. };
  9568. }
  9569. var first = function(fn, rate) {
  9570. var timer = null;
  9571. var cancel = function() {
  9572. if (!isNull(timer)) {
  9573. clearTimeout(timer);
  9574. timer = null;
  9575. }
  9576. };
  9577. var throttle2 = function() {
  9578. var args = [];
  9579. for (var _i = 0; _i < arguments.length; _i++) {
  9580. args[_i] = arguments[_i];
  9581. }
  9582. if (isNull(timer)) {
  9583. timer = setTimeout(function() {
  9584. timer = null;
  9585. fn.apply(null, args);
  9586. }, rate);
  9587. }
  9588. };
  9589. return {
  9590. cancel,
  9591. throttle: throttle2
  9592. };
  9593. };
  9594. var last = function(fn, rate) {
  9595. var timer = null;
  9596. var cancel = function() {
  9597. if (!isNull(timer)) {
  9598. clearTimeout(timer);
  9599. timer = null;
  9600. }
  9601. };
  9602. var throttle2 = function() {
  9603. var args = [];
  9604. for (var _i = 0; _i < arguments.length; _i++) {
  9605. args[_i] = arguments[_i];
  9606. }
  9607. cancel();
  9608. timer = setTimeout(function() {
  9609. timer = null;
  9610. fn.apply(null, args);
  9611. }, rate);
  9612. };
  9613. return {
  9614. cancel,
  9615. throttle: throttle2
  9616. };
  9617. };
  9618. var global$d = tinymce.util.Tools.resolve("tinymce.dom.TextSeeker");
  9619. var isBoundary = function(dom2, node) {
  9620. return dom2.isBlock(node) || contains$2([
  9621. "BR",
  9622. "IMG",
  9623. "HR",
  9624. "INPUT"
  9625. ], node.nodeName) || dom2.getContentEditable(node) === "false";
  9626. };
  9627. var repeatLeft = function(dom2, node, offset2, process2, rootNode) {
  9628. var search2 = global$d(dom2, function(node2) {
  9629. return isBoundary(dom2, node2);
  9630. });
  9631. return Optional.from(search2.backwards(node, offset2, process2, rootNode));
  9632. };
  9633. var autocompleteSelector = "[data-mce-autocompleter]";
  9634. var create$4 = function(editor, range2) {
  9635. return detect(SugarElement.fromDom(editor.selection.getNode())).getOrThunk(function() {
  9636. var wrapper = SugarElement.fromHtml('<span data-mce-autocompleter="1" data-mce-bogus="1"></span>', editor.getDoc());
  9637. append$2(wrapper, SugarElement.fromDom(range2.extractContents()));
  9638. range2.insertNode(wrapper.dom);
  9639. parent(wrapper).each(function(elm) {
  9640. return elm.dom.normalize();
  9641. });
  9642. last$1(wrapper).map(function(last2) {
  9643. editor.selection.setCursorLocation(last2.dom, getEnd(last2));
  9644. });
  9645. return wrapper;
  9646. });
  9647. };
  9648. var detect = function(elm) {
  9649. return closest$1(elm, autocompleteSelector);
  9650. };
  9651. var isValidTextRange = function(rng) {
  9652. return rng.collapsed && rng.startContainer.nodeType === 3;
  9653. };
  9654. var getText = function(rng) {
  9655. return rng.toString().replace(/\u00A0/g, " ").replace(/\uFEFF/g, "");
  9656. };
  9657. var isWhitespace = function(chr) {
  9658. return chr !== "" && " \xA0\f\n\r \v".indexOf(chr) !== -1;
  9659. };
  9660. var stripTriggerChar = function(text2, triggerCh) {
  9661. return text2.substring(triggerCh.length);
  9662. };
  9663. var findChar = function(text2, index, ch) {
  9664. var i;
  9665. for (i = index - 1; i >= 0; i--) {
  9666. var char = text2.charAt(i);
  9667. if (isWhitespace(char)) {
  9668. return Optional.none();
  9669. }
  9670. if (char === ch) {
  9671. break;
  9672. }
  9673. }
  9674. return Optional.some(i);
  9675. };
  9676. var findStart = function(dom2, initRange, ch, minChars) {
  9677. if (minChars === void 0) {
  9678. minChars = 0;
  9679. }
  9680. if (!isValidTextRange(initRange)) {
  9681. return Optional.none();
  9682. }
  9683. var findTriggerChIndex = function(element2, offset2, text2) {
  9684. return findChar(text2, offset2, ch).getOr(offset2);
  9685. };
  9686. var root = dom2.getParent(initRange.startContainer, dom2.isBlock) || dom2.getRoot();
  9687. return repeatLeft(dom2, initRange.startContainer, initRange.startOffset, findTriggerChIndex, root).bind(function(spot2) {
  9688. var range2 = initRange.cloneRange();
  9689. range2.setStart(spot2.container, spot2.offset);
  9690. range2.setEnd(initRange.endContainer, initRange.endOffset);
  9691. if (range2.collapsed) {
  9692. return Optional.none();
  9693. }
  9694. var text2 = getText(range2);
  9695. var triggerCharIndex = text2.lastIndexOf(ch);
  9696. if (triggerCharIndex !== 0 || stripTriggerChar(text2, ch).length < minChars) {
  9697. return Optional.none();
  9698. } else {
  9699. return Optional.some({
  9700. text: stripTriggerChar(text2, ch),
  9701. range: range2,
  9702. triggerChar: ch
  9703. });
  9704. }
  9705. });
  9706. };
  9707. var getContext = function(dom2, initRange, ch, minChars) {
  9708. if (minChars === void 0) {
  9709. minChars = 0;
  9710. }
  9711. return detect(SugarElement.fromDom(initRange.startContainer)).fold(function() {
  9712. return findStart(dom2, initRange, ch, minChars);
  9713. }, function(elm) {
  9714. var range2 = dom2.createRng();
  9715. range2.selectNode(elm.dom);
  9716. var text2 = getText(range2);
  9717. return Optional.some({
  9718. range: range2,
  9719. text: stripTriggerChar(text2, ch),
  9720. triggerChar: ch
  9721. });
  9722. });
  9723. };
  9724. var setup$e = function(api2, editor) {
  9725. editor.on("keypress compositionend", api2.onKeypress.throttle);
  9726. editor.on("remove", api2.onKeypress.cancel);
  9727. var redirectKeyToItem = function(item2, e) {
  9728. emitWith(item2, keydown(), { raw: e });
  9729. };
  9730. editor.on("keydown", function(e) {
  9731. var getItem = function() {
  9732. return api2.getView().bind(Highlighting.getHighlighted);
  9733. };
  9734. if (e.which === 8) {
  9735. api2.onKeypress.throttle(e);
  9736. }
  9737. if (api2.isActive()) {
  9738. if (e.which === 27) {
  9739. api2.cancelIfNecessary();
  9740. }
  9741. if (api2.isMenuOpen()) {
  9742. if (e.which === 13) {
  9743. getItem().each(emitExecute);
  9744. e.preventDefault();
  9745. } else if (e.which === 40) {
  9746. getItem().fold(function() {
  9747. api2.getView().each(Highlighting.highlightFirst);
  9748. }, function(item2) {
  9749. redirectKeyToItem(item2, e);
  9750. });
  9751. e.preventDefault();
  9752. e.stopImmediatePropagation();
  9753. } else if (e.which === 37 || e.which === 38 || e.which === 39) {
  9754. getItem().each(function(item2) {
  9755. redirectKeyToItem(item2, e);
  9756. e.preventDefault();
  9757. e.stopImmediatePropagation();
  9758. });
  9759. }
  9760. } else {
  9761. if (e.which === 13 || e.which === 38 || e.which === 40) {
  9762. api2.cancelIfNecessary();
  9763. }
  9764. }
  9765. }
  9766. });
  9767. editor.on("NodeChange", function(e) {
  9768. if (api2.isActive() && !api2.isProcessingAction() && detect(SugarElement.fromDom(e.element)).isNone()) {
  9769. api2.cancelIfNecessary();
  9770. }
  9771. });
  9772. };
  9773. var AutocompleterEditorEvents = { setup: setup$e };
  9774. var global$c = tinymce.util.Tools.resolve("tinymce.util.Promise");
  9775. var point = function(container, offset2) {
  9776. return {
  9777. container,
  9778. offset: offset2
  9779. };
  9780. };
  9781. var isText = function(node) {
  9782. return node.nodeType === TEXT;
  9783. };
  9784. var isElement$1 = function(node) {
  9785. return node.nodeType === ELEMENT;
  9786. };
  9787. var toLast = function(node) {
  9788. if (isText(node)) {
  9789. return point(node, node.data.length);
  9790. } else {
  9791. var children2 = node.childNodes;
  9792. return children2.length > 0 ? toLast(children2[children2.length - 1]) : point(node, children2.length);
  9793. }
  9794. };
  9795. var toLeaf = function(node, offset2) {
  9796. var children2 = node.childNodes;
  9797. if (children2.length > 0 && offset2 < children2.length) {
  9798. return toLeaf(children2[offset2], 0);
  9799. } else if (children2.length > 0 && isElement$1(node) && children2.length === offset2) {
  9800. return toLast(children2[children2.length - 1]);
  9801. } else {
  9802. return point(node, offset2);
  9803. }
  9804. };
  9805. var isPreviousCharContent = function(dom2, leaf2) {
  9806. return repeatLeft(dom2, leaf2.container, leaf2.offset, function(element2, offset2) {
  9807. return offset2 === 0 ? -1 : offset2;
  9808. }, dom2.getRoot()).filter(function(spot2) {
  9809. var char = spot2.container.data.charAt(spot2.offset - 1);
  9810. return !isWhitespace(char);
  9811. }).isSome();
  9812. };
  9813. var isStartOfWord = function(dom2) {
  9814. return function(rng) {
  9815. var leaf2 = toLeaf(rng.startContainer, rng.startOffset);
  9816. return !isPreviousCharContent(dom2, leaf2);
  9817. };
  9818. };
  9819. var getTriggerContext = function(dom2, initRange, database) {
  9820. return findMap(database.triggerChars, function(ch) {
  9821. return getContext(dom2, initRange, ch);
  9822. });
  9823. };
  9824. var lookup$2 = function(editor, getDatabase) {
  9825. var database = getDatabase();
  9826. var rng = editor.selection.getRng();
  9827. return getTriggerContext(editor.dom, rng, database).bind(function(context) {
  9828. return lookupWithContext(editor, getDatabase, context);
  9829. });
  9830. };
  9831. var lookupWithContext = function(editor, getDatabase, context, fetchOptions) {
  9832. if (fetchOptions === void 0) {
  9833. fetchOptions = {};
  9834. }
  9835. var database = getDatabase();
  9836. var rng = editor.selection.getRng();
  9837. var startText = rng.startContainer.nodeValue;
  9838. var autocompleters = filter$2(database.lookupByChar(context.triggerChar), function(autocompleter) {
  9839. return context.text.length >= autocompleter.minChars && autocompleter.matches.getOrThunk(function() {
  9840. return isStartOfWord(editor.dom);
  9841. })(context.range, startText, context.text);
  9842. });
  9843. if (autocompleters.length === 0) {
  9844. return Optional.none();
  9845. }
  9846. var lookupData = global$c.all(map$2(autocompleters, function(ac) {
  9847. var fetchResult = ac.fetch(context.text, ac.maxResults, fetchOptions);
  9848. return fetchResult.then(function(results) {
  9849. return {
  9850. matchText: context.text,
  9851. items: results,
  9852. columns: ac.columns,
  9853. onAction: ac.onAction,
  9854. highlightOn: ac.highlightOn
  9855. };
  9856. });
  9857. }));
  9858. return Optional.some({
  9859. lookupData,
  9860. context
  9861. });
  9862. };
  9863. var separatorMenuItemSchema = objOf([
  9864. requiredString("type"),
  9865. optionString("text")
  9866. ]);
  9867. var createSeparatorMenuItem = function(spec) {
  9868. return asRaw("separatormenuitem", separatorMenuItemSchema, spec);
  9869. };
  9870. var autocompleterItemSchema = objOf([
  9871. defaulted("type", "autocompleteitem"),
  9872. defaulted("active", false),
  9873. defaulted("disabled", false),
  9874. defaulted("meta", {}),
  9875. requiredString("value"),
  9876. optionString("text"),
  9877. optionString("icon")
  9878. ]);
  9879. var autocompleterSchema = objOf([
  9880. requiredString("type"),
  9881. requiredString("ch"),
  9882. defaultedNumber("minChars", 1),
  9883. defaulted("columns", 1),
  9884. defaultedNumber("maxResults", 10),
  9885. optionFunction("matches"),
  9886. requiredFunction("fetch"),
  9887. requiredFunction("onAction"),
  9888. defaultedArrayOf("highlightOn", [], string)
  9889. ]);
  9890. var createSeparatorItem = function(spec) {
  9891. return asRaw("Autocompleter.Separator", separatorMenuItemSchema, spec);
  9892. };
  9893. var createAutocompleterItem = function(spec) {
  9894. return asRaw("Autocompleter.Item", autocompleterItemSchema, spec);
  9895. };
  9896. var createAutocompleter = function(spec) {
  9897. return asRaw("Autocompleter", autocompleterSchema, spec);
  9898. };
  9899. var baseToolbarButtonFields = [
  9900. defaultedBoolean("disabled", false),
  9901. optionString("tooltip"),
  9902. optionString("icon"),
  9903. optionString("text"),
  9904. defaultedFunction("onSetup", function() {
  9905. return noop;
  9906. })
  9907. ];
  9908. var toolbarButtonSchema = objOf([
  9909. requiredString("type"),
  9910. requiredFunction("onAction")
  9911. ].concat(baseToolbarButtonFields));
  9912. var createToolbarButton = function(spec) {
  9913. return asRaw("toolbarbutton", toolbarButtonSchema, spec);
  9914. };
  9915. var baseToolbarToggleButtonFields = [defaultedBoolean("active", false)].concat(baseToolbarButtonFields);
  9916. var toggleButtonSchema = objOf(baseToolbarToggleButtonFields.concat([
  9917. requiredString("type"),
  9918. requiredFunction("onAction")
  9919. ]));
  9920. var createToggleButton = function(spec) {
  9921. return asRaw("ToggleButton", toggleButtonSchema, spec);
  9922. };
  9923. var contextBarFields = [
  9924. defaultedFunction("predicate", never),
  9925. defaultedStringEnum("scope", "node", [
  9926. "node",
  9927. "editor"
  9928. ]),
  9929. defaultedStringEnum("position", "selection", [
  9930. "node",
  9931. "selection",
  9932. "line"
  9933. ])
  9934. ];
  9935. var contextButtonFields = baseToolbarButtonFields.concat([
  9936. defaulted("type", "contextformbutton"),
  9937. defaulted("primary", false),
  9938. requiredFunction("onAction"),
  9939. customField("original", identity$1)
  9940. ]);
  9941. var contextToggleButtonFields = baseToolbarToggleButtonFields.concat([
  9942. defaulted("type", "contextformbutton"),
  9943. defaulted("primary", false),
  9944. requiredFunction("onAction"),
  9945. customField("original", identity$1)
  9946. ]);
  9947. var launchButtonFields = baseToolbarButtonFields.concat([defaulted("type", "contextformbutton")]);
  9948. var launchToggleButtonFields = baseToolbarToggleButtonFields.concat([defaulted("type", "contextformtogglebutton")]);
  9949. var toggleOrNormal = choose$1("type", {
  9950. contextformbutton: contextButtonFields,
  9951. contextformtogglebutton: contextToggleButtonFields
  9952. });
  9953. var contextFormSchema = objOf([
  9954. defaulted("type", "contextform"),
  9955. defaultedFunction("initValue", constant$1("")),
  9956. optionString("label"),
  9957. requiredArrayOf("commands", toggleOrNormal),
  9958. optionOf("launch", choose$1("type", {
  9959. contextformbutton: launchButtonFields,
  9960. contextformtogglebutton: launchToggleButtonFields
  9961. }))
  9962. ].concat(contextBarFields));
  9963. var createContextForm = function(spec) {
  9964. return asRaw("ContextForm", contextFormSchema, spec);
  9965. };
  9966. var contextToolbarSchema = objOf([
  9967. defaulted("type", "contexttoolbar"),
  9968. requiredString("items")
  9969. ].concat(contextBarFields));
  9970. var createContextToolbar = function(spec) {
  9971. return asRaw("ContextToolbar", contextToolbarSchema, spec);
  9972. };
  9973. var stringArray = function(a) {
  9974. var all2 = {};
  9975. each$1(a, function(key) {
  9976. all2[key] = {};
  9977. });
  9978. return keys(all2);
  9979. };
  9980. var register$b = function(editor) {
  9981. var popups = editor.ui.registry.getAll().popups;
  9982. var dataset2 = map$1(popups, function(popup) {
  9983. return createAutocompleter(popup).fold(function(err) {
  9984. throw new Error(formatError(err));
  9985. }, identity$1);
  9986. });
  9987. var triggerChars = stringArray(mapToArray(dataset2, function(v) {
  9988. return v.ch;
  9989. }));
  9990. var datasetValues = values(dataset2);
  9991. var lookupByChar = function(ch) {
  9992. return filter$2(datasetValues, function(dv) {
  9993. return dv.ch === ch;
  9994. });
  9995. };
  9996. return {
  9997. dataset: dataset2,
  9998. triggerChars,
  9999. lookupByChar
  10000. };
  10001. };
  10002. var ItemResponse;
  10003. (function(ItemResponse2) {
  10004. ItemResponse2[ItemResponse2["CLOSE_ON_EXECUTE"] = 0] = "CLOSE_ON_EXECUTE";
  10005. ItemResponse2[ItemResponse2["BUBBLE_TO_SANDBOX"] = 1] = "BUBBLE_TO_SANDBOX";
  10006. })(ItemResponse || (ItemResponse = {}));
  10007. var ItemResponse$1 = ItemResponse;
  10008. var navClass = "tox-menu-nav__js";
  10009. var selectableClass = "tox-collection__item";
  10010. var colorClass = "tox-swatch";
  10011. var presetClasses = {
  10012. normal: navClass,
  10013. color: colorClass
  10014. };
  10015. var tickedClass = "tox-collection__item--enabled";
  10016. var groupHeadingClass = "tox-collection__group-heading";
  10017. var iconClass = "tox-collection__item-icon";
  10018. var textClass = "tox-collection__item-label";
  10019. var accessoryClass = "tox-collection__item-accessory";
  10020. var caretClass = "tox-collection__item-caret";
  10021. var checkmarkClass = "tox-collection__item-checkmark";
  10022. var activeClass = "tox-collection__item--active";
  10023. var containerClass = "tox-collection__item-container";
  10024. var containerColumnClass = "tox-collection__item-container--column";
  10025. var containerRowClass = "tox-collection__item-container--row";
  10026. var containerAlignRightClass = "tox-collection__item-container--align-right";
  10027. var containerAlignLeftClass = "tox-collection__item-container--align-left";
  10028. var containerValignTopClass = "tox-collection__item-container--valign-top";
  10029. var containerValignMiddleClass = "tox-collection__item-container--valign-middle";
  10030. var containerValignBottomClass = "tox-collection__item-container--valign-bottom";
  10031. var classForPreset = function(presets) {
  10032. return get$e(presetClasses, presets).getOr(navClass);
  10033. };
  10034. var forMenu = function(presets) {
  10035. if (presets === "color") {
  10036. return "tox-swatches";
  10037. } else {
  10038. return "tox-menu";
  10039. }
  10040. };
  10041. var classes = function(presets) {
  10042. return {
  10043. backgroundMenu: "tox-background-menu",
  10044. selectedMenu: "tox-selected-menu",
  10045. selectedItem: "tox-collection__item--active",
  10046. hasIcons: "tox-menu--has-icons",
  10047. menu: forMenu(presets),
  10048. tieredMenu: "tox-tiered-menu"
  10049. };
  10050. };
  10051. var markers = function(presets) {
  10052. var menuClasses = classes(presets);
  10053. return {
  10054. backgroundMenu: menuClasses.backgroundMenu,
  10055. selectedMenu: menuClasses.selectedMenu,
  10056. menu: menuClasses.menu,
  10057. selectedItem: menuClasses.selectedItem,
  10058. item: classForPreset(presets)
  10059. };
  10060. };
  10061. var dom$1 = function(hasIcons, columns, presets) {
  10062. var menuClasses = classes(presets);
  10063. return {
  10064. tag: "div",
  10065. classes: flatten([
  10066. [
  10067. menuClasses.menu,
  10068. "tox-menu-" + columns + "-column"
  10069. ],
  10070. hasIcons ? [menuClasses.hasIcons] : []
  10071. ])
  10072. };
  10073. };
  10074. var components = [Menu.parts.items({})];
  10075. var part = function(hasIcons, columns, presets) {
  10076. var menuClasses = classes(presets);
  10077. var d = {
  10078. tag: "div",
  10079. classes: flatten([[menuClasses.tieredMenu]])
  10080. };
  10081. return {
  10082. dom: d,
  10083. markers: markers(presets)
  10084. };
  10085. };
  10086. var chunk = function(rowDom, numColumns) {
  10087. return function(items) {
  10088. var chunks = chunk$1(items, numColumns);
  10089. return map$2(chunks, function(c) {
  10090. return {
  10091. dom: rowDom,
  10092. components: c
  10093. };
  10094. });
  10095. };
  10096. };
  10097. var forSwatch = function(columns) {
  10098. return {
  10099. dom: {
  10100. tag: "div",
  10101. classes: [
  10102. "tox-menu",
  10103. "tox-swatches-menu"
  10104. ]
  10105. },
  10106. components: [{
  10107. dom: {
  10108. tag: "div",
  10109. classes: ["tox-swatches"]
  10110. },
  10111. components: [Menu.parts.items({
  10112. preprocess: columns !== "auto" ? chunk({
  10113. tag: "div",
  10114. classes: ["tox-swatches__row"]
  10115. }, columns) : identity$1
  10116. })]
  10117. }]
  10118. };
  10119. };
  10120. var forToolbar = function(columns) {
  10121. return {
  10122. dom: {
  10123. tag: "div",
  10124. classes: [
  10125. "tox-menu",
  10126. "tox-collection",
  10127. "tox-collection--toolbar",
  10128. "tox-collection--toolbar-lg"
  10129. ]
  10130. },
  10131. components: [Menu.parts.items({
  10132. preprocess: chunk({
  10133. tag: "div",
  10134. classes: ["tox-collection__group"]
  10135. }, columns)
  10136. })]
  10137. };
  10138. };
  10139. var preprocessCollection = function(items, isSeparator2) {
  10140. var allSplits = [];
  10141. var currentSplit = [];
  10142. each$1(items, function(item2, i) {
  10143. if (isSeparator2(item2, i)) {
  10144. if (currentSplit.length > 0) {
  10145. allSplits.push(currentSplit);
  10146. }
  10147. currentSplit = [];
  10148. if (has$2(item2.dom, "innerHtml")) {
  10149. currentSplit.push(item2);
  10150. }
  10151. } else {
  10152. currentSplit.push(item2);
  10153. }
  10154. });
  10155. if (currentSplit.length > 0) {
  10156. allSplits.push(currentSplit);
  10157. }
  10158. return map$2(allSplits, function(s) {
  10159. return {
  10160. dom: {
  10161. tag: "div",
  10162. classes: ["tox-collection__group"]
  10163. },
  10164. components: s
  10165. };
  10166. });
  10167. };
  10168. var forCollection = function(columns, initItems, _hasIcons) {
  10169. return {
  10170. dom: {
  10171. tag: "div",
  10172. classes: [
  10173. "tox-menu",
  10174. "tox-collection"
  10175. ].concat(columns === 1 ? ["tox-collection--list"] : ["tox-collection--grid"])
  10176. },
  10177. components: [Menu.parts.items({
  10178. preprocess: function(items) {
  10179. if (columns !== "auto" && columns > 1) {
  10180. return chunk({
  10181. tag: "div",
  10182. classes: ["tox-collection__group"]
  10183. }, columns)(items);
  10184. } else {
  10185. return preprocessCollection(items, function(_item, i) {
  10186. return initItems[i].type === "separator";
  10187. });
  10188. }
  10189. }
  10190. })]
  10191. };
  10192. };
  10193. var forHorizontalCollection = function(initItems, _hasIcons) {
  10194. return {
  10195. dom: {
  10196. tag: "div",
  10197. classes: [
  10198. "tox-collection",
  10199. "tox-collection--horizontal"
  10200. ]
  10201. },
  10202. components: [Menu.parts.items({
  10203. preprocess: function(items) {
  10204. return preprocessCollection(items, function(_item, i) {
  10205. return initItems[i].type === "separator";
  10206. });
  10207. }
  10208. })]
  10209. };
  10210. };
  10211. var menuHasIcons = function(xs) {
  10212. return exists(xs, function(item2) {
  10213. return "icon" in item2 && item2.icon !== void 0;
  10214. });
  10215. };
  10216. var handleError = function(error2) {
  10217. console.error(formatError(error2));
  10218. console.log(error2);
  10219. return Optional.none();
  10220. };
  10221. var createHorizontalPartialMenuWithAlloyItems = function(value2, _hasIcons, items, _columns, _presets) {
  10222. var structure = forHorizontalCollection(items);
  10223. return {
  10224. value: value2,
  10225. dom: structure.dom,
  10226. components: structure.components,
  10227. items
  10228. };
  10229. };
  10230. var createPartialMenuWithAlloyItems = function(value2, hasIcons, items, columns, presets) {
  10231. if (presets === "color") {
  10232. var structure = forSwatch(columns);
  10233. return {
  10234. value: value2,
  10235. dom: structure.dom,
  10236. components: structure.components,
  10237. items
  10238. };
  10239. }
  10240. if (presets === "normal" && columns === "auto") {
  10241. var structure = forCollection(columns, items);
  10242. return {
  10243. value: value2,
  10244. dom: structure.dom,
  10245. components: structure.components,
  10246. items
  10247. };
  10248. }
  10249. if (presets === "normal" && columns === 1) {
  10250. var structure = forCollection(1, items);
  10251. return {
  10252. value: value2,
  10253. dom: structure.dom,
  10254. components: structure.components,
  10255. items
  10256. };
  10257. }
  10258. if (presets === "normal") {
  10259. var structure = forCollection(columns, items);
  10260. return {
  10261. value: value2,
  10262. dom: structure.dom,
  10263. components: structure.components,
  10264. items
  10265. };
  10266. }
  10267. if (presets === "listpreview" && columns !== "auto") {
  10268. var structure = forToolbar(columns);
  10269. return {
  10270. value: value2,
  10271. dom: structure.dom,
  10272. components: structure.components,
  10273. items
  10274. };
  10275. }
  10276. return {
  10277. value: value2,
  10278. dom: dom$1(hasIcons, columns, presets),
  10279. components,
  10280. items
  10281. };
  10282. };
  10283. var cardImageFields = [
  10284. requiredString("type"),
  10285. requiredString("src"),
  10286. optionString("alt"),
  10287. defaultedArrayOf("classes", [], string)
  10288. ];
  10289. var cardImageSchema = objOf(cardImageFields);
  10290. var cardTextFields = [
  10291. requiredString("type"),
  10292. requiredString("text"),
  10293. optionString("name"),
  10294. defaultedArrayOf("classes", ["tox-collection__item-label"], string)
  10295. ];
  10296. var cardTextSchema = objOf(cardTextFields);
  10297. var itemSchema$1 = valueThunk(function() {
  10298. return choose$2("type", {
  10299. cardimage: cardImageSchema,
  10300. cardtext: cardTextSchema,
  10301. cardcontainer: cardContainerSchema
  10302. });
  10303. });
  10304. var cardContainerSchema = objOf([
  10305. requiredString("type"),
  10306. defaultedString("direction", "horizontal"),
  10307. defaultedString("align", "left"),
  10308. defaultedString("valign", "middle"),
  10309. requiredArrayOf("items", itemSchema$1)
  10310. ]);
  10311. var commonMenuItemFields = [
  10312. defaultedBoolean("disabled", false),
  10313. optionString("text"),
  10314. optionString("shortcut"),
  10315. field$1("value", "value", defaultedThunk(function() {
  10316. return generate$6("menuitem-value");
  10317. }), anyValue()),
  10318. defaulted("meta", {})
  10319. ];
  10320. var cardMenuItemSchema = objOf([
  10321. requiredString("type"),
  10322. optionString("label"),
  10323. requiredArrayOf("items", itemSchema$1),
  10324. defaultedFunction("onSetup", function() {
  10325. return noop;
  10326. }),
  10327. defaultedFunction("onAction", noop)
  10328. ].concat(commonMenuItemFields));
  10329. var createCardMenuItem = function(spec) {
  10330. return asRaw("cardmenuitem", cardMenuItemSchema, spec);
  10331. };
  10332. var choiceMenuItemSchema = objOf([
  10333. requiredString("type"),
  10334. defaultedBoolean("active", false),
  10335. optionString("icon")
  10336. ].concat(commonMenuItemFields));
  10337. var createChoiceMenuItem = function(spec) {
  10338. return asRaw("choicemenuitem", choiceMenuItemSchema, spec);
  10339. };
  10340. var baseFields = [
  10341. requiredString("type"),
  10342. requiredString("fancytype"),
  10343. defaultedFunction("onAction", noop)
  10344. ];
  10345. var insertTableFields = [defaulted("initData", {})].concat(baseFields);
  10346. var colorSwatchFields = [defaultedObjOf("initData", {}, [
  10347. defaultedBoolean("allowCustomColors", true),
  10348. optionArrayOf("colors", anyValue())
  10349. ])].concat(baseFields);
  10350. var fancyMenuItemSchema = choose$1("fancytype", {
  10351. inserttable: insertTableFields,
  10352. colorswatch: colorSwatchFields
  10353. });
  10354. var createFancyMenuItem = function(spec) {
  10355. return asRaw("fancymenuitem", fancyMenuItemSchema, spec);
  10356. };
  10357. var menuItemSchema = objOf([
  10358. requiredString("type"),
  10359. defaultedFunction("onSetup", function() {
  10360. return noop;
  10361. }),
  10362. defaultedFunction("onAction", noop),
  10363. optionString("icon")
  10364. ].concat(commonMenuItemFields));
  10365. var createMenuItem = function(spec) {
  10366. return asRaw("menuitem", menuItemSchema, spec);
  10367. };
  10368. var nestedMenuItemSchema = objOf([
  10369. requiredString("type"),
  10370. requiredFunction("getSubmenuItems"),
  10371. defaultedFunction("onSetup", function() {
  10372. return noop;
  10373. }),
  10374. optionString("icon")
  10375. ].concat(commonMenuItemFields));
  10376. var createNestedMenuItem = function(spec) {
  10377. return asRaw("nestedmenuitem", nestedMenuItemSchema, spec);
  10378. };
  10379. var toggleMenuItemSchema = objOf([
  10380. requiredString("type"),
  10381. optionString("icon"),
  10382. defaultedBoolean("active", false),
  10383. defaultedFunction("onSetup", function() {
  10384. return noop;
  10385. }),
  10386. requiredFunction("onAction")
  10387. ].concat(commonMenuItemFields));
  10388. var createToggleMenuItem = function(spec) {
  10389. return asRaw("togglemenuitem", toggleMenuItemSchema, spec);
  10390. };
  10391. var detectSize = function(comp, margin, selectorClass) {
  10392. var descendants$1 = descendants(comp.element, "." + selectorClass);
  10393. if (descendants$1.length > 0) {
  10394. var columnLength = findIndex$1(descendants$1, function(c) {
  10395. var thisTop = c.dom.getBoundingClientRect().top;
  10396. var cTop = descendants$1[0].dom.getBoundingClientRect().top;
  10397. return Math.abs(thisTop - cTop) > margin;
  10398. }).getOr(descendants$1.length);
  10399. return Optional.some({
  10400. numColumns: columnLength,
  10401. numRows: Math.ceil(descendants$1.length / columnLength)
  10402. });
  10403. } else {
  10404. return Optional.none();
  10405. }
  10406. };
  10407. var namedEvents = function(name2, handlers2) {
  10408. return derive$1([config(name2, handlers2)]);
  10409. };
  10410. var unnamedEvents = function(handlers2) {
  10411. return namedEvents(generate$6("unnamed-events"), handlers2);
  10412. };
  10413. var SimpleBehaviours = {
  10414. namedEvents,
  10415. unnamedEvents
  10416. };
  10417. var ExclusivityChannel = generate$6("tooltip.exclusive");
  10418. var ShowTooltipEvent = generate$6("tooltip.show");
  10419. var HideTooltipEvent = generate$6("tooltip.hide");
  10420. var hideAllExclusive = function(component, _tConfig, _tState) {
  10421. component.getSystem().broadcastOn([ExclusivityChannel], {});
  10422. };
  10423. var setComponents = function(component, tConfig, tState, specs) {
  10424. tState.getTooltip().each(function(tooltip) {
  10425. if (tooltip.getSystem().isConnected()) {
  10426. Replacing.set(tooltip, specs);
  10427. }
  10428. });
  10429. };
  10430. var TooltippingApis = Object.freeze({
  10431. __proto__: null,
  10432. hideAllExclusive,
  10433. setComponents
  10434. });
  10435. var events$9 = function(tooltipConfig, state) {
  10436. var hide = function(comp) {
  10437. state.getTooltip().each(function(p) {
  10438. detach(p);
  10439. tooltipConfig.onHide(comp, p);
  10440. state.clearTooltip();
  10441. });
  10442. state.clearTimer();
  10443. };
  10444. var show2 = function(comp) {
  10445. if (!state.isShowing()) {
  10446. hideAllExclusive(comp);
  10447. var sink = tooltipConfig.lazySink(comp).getOrDie();
  10448. var popup = comp.getSystem().build({
  10449. dom: tooltipConfig.tooltipDom,
  10450. components: tooltipConfig.tooltipComponents,
  10451. events: derive$2(tooltipConfig.mode === "normal" ? [
  10452. run$1(mouseover(), function(_) {
  10453. emit(comp, ShowTooltipEvent);
  10454. }),
  10455. run$1(mouseout(), function(_) {
  10456. emit(comp, HideTooltipEvent);
  10457. })
  10458. ] : []),
  10459. behaviours: derive$1([Replacing.config({})])
  10460. });
  10461. state.setTooltip(popup);
  10462. attach(sink, popup);
  10463. tooltipConfig.onShow(comp, popup);
  10464. Positioning.position(sink, popup, { anchor: tooltipConfig.anchor(comp) });
  10465. }
  10466. };
  10467. return derive$2(flatten([
  10468. [
  10469. run$1(ShowTooltipEvent, function(comp) {
  10470. state.resetTimer(function() {
  10471. show2(comp);
  10472. }, tooltipConfig.delay);
  10473. }),
  10474. run$1(HideTooltipEvent, function(comp) {
  10475. state.resetTimer(function() {
  10476. hide(comp);
  10477. }, tooltipConfig.delay);
  10478. }),
  10479. run$1(receive(), function(comp, message) {
  10480. var receivingData = message;
  10481. if (!receivingData.universal) {
  10482. if (contains$2(receivingData.channels, ExclusivityChannel)) {
  10483. hide(comp);
  10484. }
  10485. }
  10486. }),
  10487. runOnDetached(function(comp) {
  10488. hide(comp);
  10489. })
  10490. ],
  10491. tooltipConfig.mode === "normal" ? [
  10492. run$1(focusin(), function(comp) {
  10493. emit(comp, ShowTooltipEvent);
  10494. }),
  10495. run$1(postBlur(), function(comp) {
  10496. emit(comp, HideTooltipEvent);
  10497. }),
  10498. run$1(mouseover(), function(comp) {
  10499. emit(comp, ShowTooltipEvent);
  10500. }),
  10501. run$1(mouseout(), function(comp) {
  10502. emit(comp, HideTooltipEvent);
  10503. })
  10504. ] : [
  10505. run$1(highlight$1(), function(comp, _se) {
  10506. emit(comp, ShowTooltipEvent);
  10507. }),
  10508. run$1(dehighlight$1(), function(comp) {
  10509. emit(comp, HideTooltipEvent);
  10510. })
  10511. ]
  10512. ]));
  10513. };
  10514. var ActiveTooltipping = Object.freeze({
  10515. __proto__: null,
  10516. events: events$9
  10517. });
  10518. var TooltippingSchema = [
  10519. required$1("lazySink"),
  10520. required$1("tooltipDom"),
  10521. defaulted("exclusive", true),
  10522. defaulted("tooltipComponents", []),
  10523. defaulted("delay", 300),
  10524. defaultedStringEnum("mode", "normal", [
  10525. "normal",
  10526. "follow-highlight"
  10527. ]),
  10528. defaulted("anchor", function(comp) {
  10529. return {
  10530. type: "hotspot",
  10531. hotspot: comp,
  10532. layouts: {
  10533. onLtr: constant$1([
  10534. south$2,
  10535. north$2,
  10536. southeast$2,
  10537. northeast$2,
  10538. southwest$2,
  10539. northwest$2
  10540. ]),
  10541. onRtl: constant$1([
  10542. south$2,
  10543. north$2,
  10544. southeast$2,
  10545. northeast$2,
  10546. southwest$2,
  10547. northwest$2
  10548. ])
  10549. }
  10550. };
  10551. }),
  10552. onHandler("onHide"),
  10553. onHandler("onShow")
  10554. ];
  10555. var init$b = function() {
  10556. var timer = value$1();
  10557. var popup = value$1();
  10558. var clearTimer = function() {
  10559. timer.on(clearTimeout);
  10560. };
  10561. var resetTimer = function(f, delay) {
  10562. clearTimer();
  10563. timer.set(setTimeout(f, delay));
  10564. };
  10565. var readState = constant$1("not-implemented");
  10566. return nu$8({
  10567. getTooltip: popup.get,
  10568. isShowing: popup.isSet,
  10569. setTooltip: popup.set,
  10570. clearTooltip: popup.clear,
  10571. clearTimer,
  10572. resetTimer,
  10573. readState
  10574. });
  10575. };
  10576. var TooltippingState = Object.freeze({
  10577. __proto__: null,
  10578. init: init$b
  10579. });
  10580. var Tooltipping = create$7({
  10581. fields: TooltippingSchema,
  10582. name: "tooltipping",
  10583. active: ActiveTooltipping,
  10584. state: TooltippingState,
  10585. apis: TooltippingApis
  10586. });
  10587. var escape = function(text2) {
  10588. return text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  10589. };
  10590. var global$b = tinymce.util.Tools.resolve("tinymce.dom.DOMUtils");
  10591. var global$a = tinymce.util.Tools.resolve("tinymce.EditorManager");
  10592. var getSkinUrl = function(editor) {
  10593. var skin = editor.getParam("skin");
  10594. var skinUrl = editor.getParam("skin_url");
  10595. if (skin !== false) {
  10596. var skinName = skin ? skin : "oxide";
  10597. if (skinUrl) {
  10598. skinUrl = editor.documentBaseURI.toAbsolute(skinUrl);
  10599. } else {
  10600. skinUrl = global$a.baseURL + "/skins/ui/" + skinName;
  10601. }
  10602. }
  10603. return skinUrl;
  10604. };
  10605. var isReadOnly = function(editor) {
  10606. return editor.getParam("readonly", false, "boolean");
  10607. };
  10608. var isSkinDisabled = function(editor) {
  10609. return editor.getParam("skin") === false;
  10610. };
  10611. var getHeightSetting = function(editor) {
  10612. return editor.getParam("height", Math.max(editor.getElement().offsetHeight, 200));
  10613. };
  10614. var getWidthSetting = function(editor) {
  10615. return editor.getParam("width", global$b.DOM.getStyle(editor.getElement(), "width"));
  10616. };
  10617. var getMinWidthSetting = function(editor) {
  10618. return Optional.from(editor.getParam("min_width")).filter(isNumber);
  10619. };
  10620. var getMinHeightSetting = function(editor) {
  10621. return Optional.from(editor.getParam("min_height")).filter(isNumber);
  10622. };
  10623. var getMaxWidthSetting = function(editor) {
  10624. return Optional.from(editor.getParam("max_width")).filter(isNumber);
  10625. };
  10626. var getMaxHeightSetting = function(editor) {
  10627. return Optional.from(editor.getParam("max_height")).filter(isNumber);
  10628. };
  10629. var getUserStyleFormats = function(editor) {
  10630. return Optional.from(editor.getParam("style_formats")).filter(isArray);
  10631. };
  10632. var isMergeStyleFormats = function(editor) {
  10633. return editor.getParam("style_formats_merge", false, "boolean");
  10634. };
  10635. var getLineHeightFormats = function(editor) {
  10636. return editor.getParam("lineheight_formats", "1 1.1 1.2 1.3 1.4 1.5 2", "string").split(" ");
  10637. };
  10638. var getContentLanguages = function(editor) {
  10639. return editor.getParam("content_langs", void 0, "array");
  10640. };
  10641. var getRemovedMenuItems = function(editor) {
  10642. return editor.getParam("removed_menuitems", "");
  10643. };
  10644. var isMenubarEnabled = function(editor) {
  10645. return editor.getParam("menubar", true, "boolean") !== false;
  10646. };
  10647. var isToolbarEnabled = function(editor) {
  10648. var toolbar = editor.getParam("toolbar", true);
  10649. var isToolbarTrue = toolbar === true;
  10650. var isToolbarString = isString(toolbar);
  10651. var isToolbarObjectArray = isArray(toolbar) && toolbar.length > 0;
  10652. return !isMultipleToolbars(editor) && (isToolbarObjectArray || isToolbarString || isToolbarTrue);
  10653. };
  10654. var getMultipleToolbarsSetting = function(editor) {
  10655. var toolbars = range$2(9, function(num) {
  10656. return editor.getParam("toolbar" + (num + 1), false, "string");
  10657. });
  10658. var toolbarArray = filter$2(toolbars, function(toolbar) {
  10659. return typeof toolbar === "string";
  10660. });
  10661. return toolbarArray.length > 0 ? Optional.some(toolbarArray) : Optional.none();
  10662. };
  10663. var isMultipleToolbars = function(editor) {
  10664. return getMultipleToolbarsSetting(editor).fold(function() {
  10665. var toolbar = editor.getParam("toolbar", [], "string[]");
  10666. return toolbar.length > 0;
  10667. }, always);
  10668. };
  10669. var ToolbarMode;
  10670. (function(ToolbarMode2) {
  10671. ToolbarMode2["default"] = "wrap";
  10672. ToolbarMode2["floating"] = "floating";
  10673. ToolbarMode2["sliding"] = "sliding";
  10674. ToolbarMode2["scrolling"] = "scrolling";
  10675. })(ToolbarMode || (ToolbarMode = {}));
  10676. var getToolbarMode = function(editor) {
  10677. return editor.getParam("toolbar_mode", "", "string");
  10678. };
  10679. var ToolbarLocation;
  10680. (function(ToolbarLocation2) {
  10681. ToolbarLocation2["auto"] = "auto";
  10682. ToolbarLocation2["top"] = "top";
  10683. ToolbarLocation2["bottom"] = "bottom";
  10684. })(ToolbarLocation || (ToolbarLocation = {}));
  10685. var getToolbarGroups = function(editor) {
  10686. return editor.getParam("toolbar_groups", {}, "object");
  10687. };
  10688. var getToolbarLocation = function(editor) {
  10689. return editor.getParam("toolbar_location", ToolbarLocation.auto, "string");
  10690. };
  10691. var isToolbarLocationBottom = function(editor) {
  10692. return getToolbarLocation(editor) === ToolbarLocation.bottom;
  10693. };
  10694. var fixedContainerSelector = function(editor) {
  10695. return editor.getParam("fixed_toolbar_container", "", "string");
  10696. };
  10697. var fixedToolbarContainerTarget = function(editor) {
  10698. return editor.getParam("fixed_toolbar_container_target");
  10699. };
  10700. var isToolbarPersist = function(editor) {
  10701. return editor.getParam("toolbar_persist", false, "boolean");
  10702. };
  10703. var fixedContainerTarget = function(editor) {
  10704. if (!editor.inline) {
  10705. return Optional.none();
  10706. }
  10707. var selector = fixedContainerSelector(editor);
  10708. if (selector.length > 0) {
  10709. return descendant(body(), selector);
  10710. }
  10711. var element2 = fixedToolbarContainerTarget(editor);
  10712. if (isNonNullable(element2)) {
  10713. return Optional.some(SugarElement.fromDom(element2));
  10714. }
  10715. return Optional.none();
  10716. };
  10717. var useFixedContainer = function(editor) {
  10718. return editor.inline && fixedContainerTarget(editor).isSome();
  10719. };
  10720. var getUiContainer = function(editor) {
  10721. var fixedContainer = fixedContainerTarget(editor);
  10722. return fixedContainer.getOrThunk(function() {
  10723. return getContentContainer(getRootNode(SugarElement.fromDom(editor.getElement())));
  10724. });
  10725. };
  10726. var isDistractionFree = function(editor) {
  10727. return editor.inline && !isMenubarEnabled(editor) && !isToolbarEnabled(editor) && !isMultipleToolbars(editor);
  10728. };
  10729. var isStickyToolbar = function(editor) {
  10730. var isStickyToolbar2 = editor.getParam("toolbar_sticky", false, "boolean");
  10731. return (isStickyToolbar2 || editor.inline) && !useFixedContainer(editor) && !isDistractionFree(editor);
  10732. };
  10733. var getStickyToolbarOffset = function(editor) {
  10734. return editor.getParam("toolbar_sticky_offset", 0, "number");
  10735. };
  10736. var isDraggableModal$1 = function(editor) {
  10737. return editor.getParam("draggable_modal", false, "boolean");
  10738. };
  10739. var getMenus = function(editor) {
  10740. var menu2 = editor.getParam("menu");
  10741. if (menu2) {
  10742. return map$1(menu2, function(menu3) {
  10743. return __assign(__assign({}, menu3), { items: menu3.items });
  10744. });
  10745. } else {
  10746. return {};
  10747. }
  10748. };
  10749. var getMenubar = function(editor) {
  10750. return editor.getParam("menubar");
  10751. };
  10752. var getToolbar = function(editor) {
  10753. return editor.getParam("toolbar", true);
  10754. };
  10755. var getFilePickerCallback = function(editor) {
  10756. return editor.getParam("file_picker_callback");
  10757. };
  10758. var getFilePickerTypes = function(editor) {
  10759. return editor.getParam("file_picker_types");
  10760. };
  10761. var getFileBrowserCallbackTypes = function(editor) {
  10762. return editor.getParam("file_browser_callback_types");
  10763. };
  10764. var noTypeaheadUrls = function(editor) {
  10765. return editor.getParam("typeahead_urls") === false;
  10766. };
  10767. var getAnchorTop = function(editor) {
  10768. return editor.getParam("anchor_top", "#top");
  10769. };
  10770. var getAnchorBottom = function(editor) {
  10771. return editor.getParam("anchor_bottom", "#bottom");
  10772. };
  10773. var getFilePickerValidatorHandler = function(editor) {
  10774. var handler = editor.getParam("file_picker_validator_handler", void 0, "function");
  10775. if (handler === void 0) {
  10776. return editor.getParam("filepicker_validator_handler", void 0, "function");
  10777. } else {
  10778. return handler;
  10779. }
  10780. };
  10781. var ReadOnlyChannel = "silver.readonly";
  10782. var ReadOnlyDataSchema = objOf([requiredBoolean("readonly")]);
  10783. var broadcastReadonly = function(uiComponents, readonly) {
  10784. var outerContainer = uiComponents.outerContainer;
  10785. var target = outerContainer.element;
  10786. if (readonly) {
  10787. uiComponents.mothership.broadcastOn([dismissPopups()], { target });
  10788. uiComponents.uiMothership.broadcastOn([dismissPopups()], { target });
  10789. }
  10790. uiComponents.mothership.broadcastOn([ReadOnlyChannel], { readonly });
  10791. uiComponents.uiMothership.broadcastOn([ReadOnlyChannel], { readonly });
  10792. };
  10793. var setupReadonlyModeSwitch = function(editor, uiComponents) {
  10794. editor.on("init", function() {
  10795. if (editor.mode.isReadOnly()) {
  10796. broadcastReadonly(uiComponents, true);
  10797. }
  10798. });
  10799. editor.on("SwitchMode", function() {
  10800. return broadcastReadonly(uiComponents, editor.mode.isReadOnly());
  10801. });
  10802. if (isReadOnly(editor)) {
  10803. editor.setMode("readonly");
  10804. }
  10805. };
  10806. var receivingConfig = function() {
  10807. var _a2;
  10808. return Receiving.config({
  10809. channels: (_a2 = {}, _a2[ReadOnlyChannel] = {
  10810. schema: ReadOnlyDataSchema,
  10811. onReceive: function(comp, data) {
  10812. Disabling.set(comp, data.readonly);
  10813. }
  10814. }, _a2)
  10815. });
  10816. };
  10817. var item = function(disabled) {
  10818. return Disabling.config({
  10819. disabled,
  10820. disableClass: "tox-collection__item--state-disabled"
  10821. });
  10822. };
  10823. var button = function(disabled) {
  10824. return Disabling.config({ disabled });
  10825. };
  10826. var splitButton = function(disabled) {
  10827. return Disabling.config({
  10828. disabled,
  10829. disableClass: "tox-tbtn--disabled"
  10830. });
  10831. };
  10832. var toolbarButton = function(disabled) {
  10833. return Disabling.config({
  10834. disabled,
  10835. disableClass: "tox-tbtn--disabled",
  10836. useNative: false
  10837. });
  10838. };
  10839. var DisablingConfigs = {
  10840. item,
  10841. button,
  10842. splitButton,
  10843. toolbarButton
  10844. };
  10845. var runWithApi = function(info, comp) {
  10846. var api2 = info.getApi(comp);
  10847. return function(f) {
  10848. f(api2);
  10849. };
  10850. };
  10851. var onControlAttached = function(info, editorOffCell) {
  10852. return runOnAttached(function(comp) {
  10853. var run2 = runWithApi(info, comp);
  10854. run2(function(api2) {
  10855. var onDestroy = info.onSetup(api2);
  10856. if (isFunction(onDestroy)) {
  10857. editorOffCell.set(onDestroy);
  10858. }
  10859. });
  10860. });
  10861. };
  10862. var onControlDetached = function(getApi2, editorOffCell) {
  10863. return runOnDetached(function(comp) {
  10864. return runWithApi(getApi2, comp)(editorOffCell.get());
  10865. });
  10866. };
  10867. var _a$1;
  10868. var onMenuItemExecute = function(info, itemResponse) {
  10869. return runOnExecute$1(function(comp, simulatedEvent) {
  10870. runWithApi(info, comp)(info.onAction);
  10871. if (!info.triggersSubmenu && itemResponse === ItemResponse$1.CLOSE_ON_EXECUTE) {
  10872. emit(comp, sandboxClose());
  10873. simulatedEvent.stop();
  10874. }
  10875. });
  10876. };
  10877. var menuItemEventOrder = (_a$1 = {}, _a$1[execute$5()] = [
  10878. "disabling",
  10879. "alloy.base.behaviour",
  10880. "toggling",
  10881. "item-events"
  10882. ], _a$1);
  10883. var componentRenderPipeline = cat;
  10884. var renderCommonItem = function(spec, structure, itemResponse, providersbackstage) {
  10885. var editorOffCell = Cell(noop);
  10886. return {
  10887. type: "item",
  10888. dom: structure.dom,
  10889. components: componentRenderPipeline(structure.optComponents),
  10890. data: spec.data,
  10891. eventOrder: menuItemEventOrder,
  10892. hasSubmenu: spec.triggersSubmenu,
  10893. itemBehaviours: derive$1([
  10894. config("item-events", [
  10895. onMenuItemExecute(spec, itemResponse),
  10896. onControlAttached(spec, editorOffCell),
  10897. onControlDetached(spec, editorOffCell)
  10898. ]),
  10899. DisablingConfigs.item(function() {
  10900. return spec.disabled || providersbackstage.isDisabled();
  10901. }),
  10902. receivingConfig(),
  10903. Replacing.config({})
  10904. ].concat(spec.itemBehaviours))
  10905. };
  10906. };
  10907. var buildData = function(source) {
  10908. return {
  10909. value: source.value,
  10910. meta: __assign({ text: source.text.getOr("") }, source.meta)
  10911. };
  10912. };
  10913. var global$9 = tinymce.util.Tools.resolve("tinymce.Env");
  10914. var convertText = function(source) {
  10915. var mac = {
  10916. alt: "&#x2325;",
  10917. ctrl: "&#x2303;",
  10918. shift: "&#x21E7;",
  10919. meta: "&#x2318;",
  10920. access: "&#x2303;&#x2325;"
  10921. };
  10922. var other = {
  10923. meta: "Ctrl",
  10924. access: "Shift+Alt"
  10925. };
  10926. var replace = global$9.mac ? mac : other;
  10927. var shortcut = source.split("+");
  10928. var updated = map$2(shortcut, function(segment) {
  10929. var search2 = segment.toLowerCase().trim();
  10930. return has$2(replace, search2) ? replace[search2] : segment;
  10931. });
  10932. return global$9.mac ? updated.join("") : updated.join("+");
  10933. };
  10934. var renderIcon$1 = function(name2, icons, classes2) {
  10935. if (classes2 === void 0) {
  10936. classes2 = [iconClass];
  10937. }
  10938. return render$3(name2, {
  10939. tag: "div",
  10940. classes: classes2
  10941. }, icons);
  10942. };
  10943. var renderText = function(text$1) {
  10944. return {
  10945. dom: {
  10946. tag: "div",
  10947. classes: [textClass]
  10948. },
  10949. components: [text(global$e.translate(text$1))]
  10950. };
  10951. };
  10952. var renderHtml = function(html, classes2) {
  10953. return {
  10954. dom: {
  10955. tag: "div",
  10956. classes: classes2,
  10957. innerHtml: html
  10958. }
  10959. };
  10960. };
  10961. var renderStyledText = function(style, text$1) {
  10962. return {
  10963. dom: {
  10964. tag: "div",
  10965. classes: [textClass]
  10966. },
  10967. components: [{
  10968. dom: {
  10969. tag: style.tag,
  10970. styles: style.styles
  10971. },
  10972. components: [text(global$e.translate(text$1))]
  10973. }]
  10974. };
  10975. };
  10976. var renderShortcut = function(shortcut) {
  10977. return {
  10978. dom: {
  10979. tag: "div",
  10980. classes: [accessoryClass],
  10981. innerHtml: convertText(shortcut)
  10982. }
  10983. };
  10984. };
  10985. var renderCheckmark = function(icons) {
  10986. return renderIcon$1("checkmark", icons, [checkmarkClass]);
  10987. };
  10988. var renderSubmenuCaret = function(icons) {
  10989. return renderIcon$1("chevron-right", icons, [caretClass]);
  10990. };
  10991. var renderDownwardsCaret = function(icons) {
  10992. return renderIcon$1("chevron-down", icons, [caretClass]);
  10993. };
  10994. var renderContainer = function(container, components2) {
  10995. var directionClass = container.direction === "vertical" ? containerColumnClass : containerRowClass;
  10996. var alignClass = container.align === "left" ? containerAlignLeftClass : containerAlignRightClass;
  10997. var getValignClass = function() {
  10998. switch (container.valign) {
  10999. case "top":
  11000. return containerValignTopClass;
  11001. case "middle":
  11002. return containerValignMiddleClass;
  11003. case "bottom":
  11004. return containerValignBottomClass;
  11005. }
  11006. };
  11007. return {
  11008. dom: {
  11009. tag: "div",
  11010. classes: [
  11011. containerClass,
  11012. directionClass,
  11013. alignClass,
  11014. getValignClass()
  11015. ]
  11016. },
  11017. components: components2
  11018. };
  11019. };
  11020. var renderImage = function(src, classes2, alt) {
  11021. return {
  11022. dom: {
  11023. tag: "img",
  11024. classes: classes2,
  11025. attributes: {
  11026. src,
  11027. alt: alt.getOr("")
  11028. }
  11029. }
  11030. };
  11031. };
  11032. var renderColorStructure = function(item2, providerBackstage, fallbackIcon) {
  11033. var colorPickerCommand = "custom";
  11034. var removeColorCommand = "remove";
  11035. var itemText = item2.ariaLabel;
  11036. var itemValue = item2.value;
  11037. var iconSvg = item2.iconContent.map(function(name2) {
  11038. return getOr(name2, providerBackstage.icons, fallbackIcon);
  11039. });
  11040. var getDom = function() {
  11041. var common = colorClass;
  11042. var icon = iconSvg.getOr("");
  11043. var attributes = itemText.map(function(text2) {
  11044. return { title: providerBackstage.translate(text2) };
  11045. }).getOr({});
  11046. var baseDom = {
  11047. tag: "div",
  11048. attributes,
  11049. classes: [common]
  11050. };
  11051. if (itemValue === colorPickerCommand) {
  11052. return __assign(__assign({}, baseDom), {
  11053. tag: "button",
  11054. classes: __spreadArray(__spreadArray([], baseDom.classes, true), ["tox-swatches__picker-btn"], false),
  11055. innerHtml: icon
  11056. });
  11057. } else if (itemValue === removeColorCommand) {
  11058. return __assign(__assign({}, baseDom), {
  11059. classes: __spreadArray(__spreadArray([], baseDom.classes, true), ["tox-swatch--remove"], false),
  11060. innerHtml: icon
  11061. });
  11062. } else {
  11063. return __assign(__assign({}, baseDom), {
  11064. attributes: __assign(__assign({}, baseDom.attributes), { "data-mce-color": itemValue }),
  11065. styles: { "background-color": itemValue }
  11066. });
  11067. }
  11068. };
  11069. return {
  11070. dom: getDom(),
  11071. optComponents: []
  11072. };
  11073. };
  11074. var renderItemDomStructure = function(ariaLabel) {
  11075. var domTitle = ariaLabel.map(function(label) {
  11076. return { attributes: { title: global$e.translate(label) } };
  11077. }).getOr({});
  11078. return __assign({
  11079. tag: "div",
  11080. classes: [
  11081. navClass,
  11082. selectableClass
  11083. ]
  11084. }, domTitle);
  11085. };
  11086. var renderNormalItemStructure = function(info, providersBackstage, renderIcons, fallbackIcon) {
  11087. var iconSpec = {
  11088. tag: "div",
  11089. classes: [iconClass]
  11090. };
  11091. var renderIcon2 = function(iconName) {
  11092. return render$3(iconName, iconSpec, providersBackstage.icons, fallbackIcon);
  11093. };
  11094. var renderEmptyIcon = function() {
  11095. return Optional.some({ dom: iconSpec });
  11096. };
  11097. var leftIcon = renderIcons ? info.iconContent.map(renderIcon2).orThunk(renderEmptyIcon) : Optional.none();
  11098. var checkmark = info.checkMark;
  11099. var textRender = Optional.from(info.meta).fold(function() {
  11100. return renderText;
  11101. }, function(meta) {
  11102. return has$2(meta, "style") ? curry(renderStyledText, meta.style) : renderText;
  11103. });
  11104. var content = info.htmlContent.fold(function() {
  11105. return info.textContent.map(textRender);
  11106. }, function(html) {
  11107. return Optional.some(renderHtml(html, [textClass]));
  11108. });
  11109. var menuItem = {
  11110. dom: renderItemDomStructure(info.ariaLabel),
  11111. optComponents: [
  11112. leftIcon,
  11113. content,
  11114. info.shortcutContent.map(renderShortcut),
  11115. checkmark,
  11116. info.caret
  11117. ]
  11118. };
  11119. return menuItem;
  11120. };
  11121. var renderItemStructure = function(info, providersBackstage, renderIcons, fallbackIcon) {
  11122. if (fallbackIcon === void 0) {
  11123. fallbackIcon = Optional.none();
  11124. }
  11125. if (info.presets === "color") {
  11126. return renderColorStructure(info, providersBackstage, fallbackIcon);
  11127. } else {
  11128. return renderNormalItemStructure(info, providersBackstage, renderIcons, fallbackIcon);
  11129. }
  11130. };
  11131. var tooltipBehaviour = function(meta, sharedBackstage) {
  11132. return get$e(meta, "tooltipWorker").map(function(tooltipWorker) {
  11133. return [Tooltipping.config({
  11134. lazySink: sharedBackstage.getSink,
  11135. tooltipDom: {
  11136. tag: "div",
  11137. classes: ["tox-tooltip-worker-container"]
  11138. },
  11139. tooltipComponents: [],
  11140. anchor: function(comp) {
  11141. return {
  11142. type: "submenu",
  11143. item: comp,
  11144. overrides: { maxHeightFunction: expandable$1 }
  11145. };
  11146. },
  11147. mode: "follow-highlight",
  11148. onShow: function(component, _tooltip) {
  11149. tooltipWorker(function(elm) {
  11150. Tooltipping.setComponents(component, [external$2({ element: SugarElement.fromDom(elm) })]);
  11151. });
  11152. }
  11153. })];
  11154. }).getOr([]);
  11155. };
  11156. var encodeText = function(text2) {
  11157. return global$b.DOM.encode(text2);
  11158. };
  11159. var replaceText = function(text2, matchText) {
  11160. var translated = global$e.translate(text2);
  11161. var encoded = encodeText(translated);
  11162. if (matchText.length > 0) {
  11163. var escapedMatchRegex = new RegExp(escape(matchText), "gi");
  11164. return encoded.replace(escapedMatchRegex, function(match) {
  11165. return '<span class="tox-autocompleter-highlight">' + match + "</span>";
  11166. });
  11167. } else {
  11168. return encoded;
  11169. }
  11170. };
  11171. var renderAutocompleteItem = function(spec, matchText, useText, presets, onItemValueHandler, itemResponse, sharedBackstage, renderIcons) {
  11172. if (renderIcons === void 0) {
  11173. renderIcons = true;
  11174. }
  11175. var structure = renderItemStructure({
  11176. presets,
  11177. textContent: Optional.none(),
  11178. htmlContent: useText ? spec.text.map(function(text2) {
  11179. return replaceText(text2, matchText);
  11180. }) : Optional.none(),
  11181. ariaLabel: spec.text,
  11182. iconContent: spec.icon,
  11183. shortcutContent: Optional.none(),
  11184. checkMark: Optional.none(),
  11185. caret: Optional.none(),
  11186. value: spec.value
  11187. }, sharedBackstage.providers, renderIcons, spec.icon);
  11188. return renderCommonItem({
  11189. data: buildData(spec),
  11190. disabled: spec.disabled,
  11191. getApi: constant$1({}),
  11192. onAction: function(_api) {
  11193. return onItemValueHandler(spec.value, spec.meta);
  11194. },
  11195. onSetup: constant$1(noop),
  11196. triggersSubmenu: false,
  11197. itemBehaviours: tooltipBehaviour(spec.meta, sharedBackstage)
  11198. }, structure, itemResponse, sharedBackstage.providers);
  11199. };
  11200. var render$2 = function(items, extras) {
  11201. return map$2(items, function(item2) {
  11202. switch (item2.type) {
  11203. case "cardcontainer":
  11204. return renderContainer(item2, render$2(item2.items, extras));
  11205. case "cardimage":
  11206. return renderImage(item2.src, item2.classes, item2.alt);
  11207. case "cardtext":
  11208. var shouldHighlight = item2.name.exists(function(name2) {
  11209. return contains$2(extras.cardText.highlightOn, name2);
  11210. });
  11211. var matchText = shouldHighlight ? Optional.from(extras.cardText.matchText).getOr("") : "";
  11212. return renderHtml(replaceText(item2.text, matchText), item2.classes);
  11213. }
  11214. });
  11215. };
  11216. var renderCardMenuItem = function(spec, itemResponse, sharedBackstage, extras) {
  11217. var getApi2 = function(component) {
  11218. return {
  11219. isDisabled: function() {
  11220. return Disabling.isDisabled(component);
  11221. },
  11222. setDisabled: function(state) {
  11223. Disabling.set(component, state);
  11224. each$1(descendants(component.element, "*"), function(elm) {
  11225. component.getSystem().getByDom(elm).each(function(comp) {
  11226. if (comp.hasConfigured(Disabling)) {
  11227. Disabling.set(comp, state);
  11228. }
  11229. });
  11230. });
  11231. }
  11232. };
  11233. };
  11234. var structure = {
  11235. dom: renderItemDomStructure(spec.label),
  11236. optComponents: [Optional.some({
  11237. dom: {
  11238. tag: "div",
  11239. classes: [
  11240. containerClass,
  11241. containerRowClass
  11242. ]
  11243. },
  11244. components: render$2(spec.items, extras)
  11245. })]
  11246. };
  11247. return renderCommonItem({
  11248. data: buildData(__assign({ text: Optional.none() }, spec)),
  11249. disabled: spec.disabled,
  11250. getApi: getApi2,
  11251. onAction: spec.onAction,
  11252. onSetup: spec.onSetup,
  11253. triggersSubmenu: false,
  11254. itemBehaviours: Optional.from(extras.itemBehaviours).getOr([])
  11255. }, structure, itemResponse, sharedBackstage.providers);
  11256. };
  11257. var renderChoiceItem = function(spec, useText, presets, onItemValueHandler, isSelected, itemResponse, providersBackstage, renderIcons) {
  11258. if (renderIcons === void 0) {
  11259. renderIcons = true;
  11260. }
  11261. var getApi2 = function(component) {
  11262. return {
  11263. setActive: function(state) {
  11264. Toggling.set(component, state);
  11265. },
  11266. isActive: function() {
  11267. return Toggling.isOn(component);
  11268. },
  11269. isDisabled: function() {
  11270. return Disabling.isDisabled(component);
  11271. },
  11272. setDisabled: function(state) {
  11273. return Disabling.set(component, state);
  11274. }
  11275. };
  11276. };
  11277. var structure = renderItemStructure({
  11278. presets,
  11279. textContent: useText ? spec.text : Optional.none(),
  11280. htmlContent: Optional.none(),
  11281. ariaLabel: spec.text,
  11282. iconContent: spec.icon,
  11283. shortcutContent: useText ? spec.shortcut : Optional.none(),
  11284. checkMark: useText ? Optional.some(renderCheckmark(providersBackstage.icons)) : Optional.none(),
  11285. caret: Optional.none(),
  11286. value: spec.value
  11287. }, providersBackstage, renderIcons);
  11288. return deepMerge(renderCommonItem({
  11289. data: buildData(spec),
  11290. disabled: spec.disabled,
  11291. getApi: getApi2,
  11292. onAction: function(_api) {
  11293. return onItemValueHandler(spec.value);
  11294. },
  11295. onSetup: function(api2) {
  11296. api2.setActive(isSelected);
  11297. return noop;
  11298. },
  11299. triggersSubmenu: false,
  11300. itemBehaviours: []
  11301. }, structure, itemResponse, providersBackstage), {
  11302. toggling: {
  11303. toggleClass: tickedClass,
  11304. toggleOnExecute: false,
  11305. selected: spec.active
  11306. }
  11307. });
  11308. };
  11309. var parts$f = generate$3(owner$2(), parts$h());
  11310. var hexColour = function(value2) {
  11311. return { value: value2 };
  11312. };
  11313. var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  11314. var longformRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
  11315. var isHexString = function(hex) {
  11316. return shorthandRegex.test(hex) || longformRegex.test(hex);
  11317. };
  11318. var normalizeHex = function(hex) {
  11319. return removeLeading(hex, "#").toUpperCase();
  11320. };
  11321. var fromString$1 = function(hex) {
  11322. return isHexString(hex) ? Optional.some({ value: normalizeHex(hex) }) : Optional.none();
  11323. };
  11324. var getLongForm = function(hex) {
  11325. var hexString = hex.value.replace(shorthandRegex, function(m, r2, g, b2) {
  11326. return r2 + r2 + g + g + b2 + b2;
  11327. });
  11328. return { value: hexString };
  11329. };
  11330. var extractValues = function(hex) {
  11331. var longForm = getLongForm(hex);
  11332. var splitForm = longformRegex.exec(longForm.value);
  11333. return splitForm === null ? [
  11334. "FFFFFF",
  11335. "FF",
  11336. "FF",
  11337. "FF"
  11338. ] : splitForm;
  11339. };
  11340. var toHex = function(component) {
  11341. var hex = component.toString(16);
  11342. return (hex.length === 1 ? "0" + hex : hex).toUpperCase();
  11343. };
  11344. var fromRgba = function(rgbaColour2) {
  11345. var value2 = toHex(rgbaColour2.red) + toHex(rgbaColour2.green) + toHex(rgbaColour2.blue);
  11346. return hexColour(value2);
  11347. };
  11348. var min = Math.min;
  11349. var max = Math.max;
  11350. var round$1 = Math.round;
  11351. var rgbRegex = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)/;
  11352. var rgbaRegex = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d?(?:\.\d+)?)\)/;
  11353. var rgbaColour = function(red2, green, blue, alpha) {
  11354. return {
  11355. red: red2,
  11356. green,
  11357. blue,
  11358. alpha
  11359. };
  11360. };
  11361. var isRgbaComponent = function(value2) {
  11362. var num = parseInt(value2, 10);
  11363. return num.toString() === value2 && num >= 0 && num <= 255;
  11364. };
  11365. var fromHsv = function(hsv) {
  11366. var r2;
  11367. var g;
  11368. var b2;
  11369. var hue = (hsv.hue || 0) % 360;
  11370. var saturation = hsv.saturation / 100;
  11371. var brightness2 = hsv.value / 100;
  11372. saturation = max(0, min(saturation, 1));
  11373. brightness2 = max(0, min(brightness2, 1));
  11374. if (saturation === 0) {
  11375. r2 = g = b2 = round$1(255 * brightness2);
  11376. return rgbaColour(r2, g, b2, 1);
  11377. }
  11378. var side = hue / 60;
  11379. var chroma = brightness2 * saturation;
  11380. var x = chroma * (1 - Math.abs(side % 2 - 1));
  11381. var match = brightness2 - chroma;
  11382. switch (Math.floor(side)) {
  11383. case 0:
  11384. r2 = chroma;
  11385. g = x;
  11386. b2 = 0;
  11387. break;
  11388. case 1:
  11389. r2 = x;
  11390. g = chroma;
  11391. b2 = 0;
  11392. break;
  11393. case 2:
  11394. r2 = 0;
  11395. g = chroma;
  11396. b2 = x;
  11397. break;
  11398. case 3:
  11399. r2 = 0;
  11400. g = x;
  11401. b2 = chroma;
  11402. break;
  11403. case 4:
  11404. r2 = x;
  11405. g = 0;
  11406. b2 = chroma;
  11407. break;
  11408. case 5:
  11409. r2 = chroma;
  11410. g = 0;
  11411. b2 = x;
  11412. break;
  11413. default:
  11414. r2 = g = b2 = 0;
  11415. }
  11416. r2 = round$1(255 * (r2 + match));
  11417. g = round$1(255 * (g + match));
  11418. b2 = round$1(255 * (b2 + match));
  11419. return rgbaColour(r2, g, b2, 1);
  11420. };
  11421. var fromHex = function(hexColour2) {
  11422. var result = extractValues(hexColour2);
  11423. var red2 = parseInt(result[1], 16);
  11424. var green = parseInt(result[2], 16);
  11425. var blue = parseInt(result[3], 16);
  11426. return rgbaColour(red2, green, blue, 1);
  11427. };
  11428. var fromStringValues = function(red2, green, blue, alpha) {
  11429. var r2 = parseInt(red2, 10);
  11430. var g = parseInt(green, 10);
  11431. var b2 = parseInt(blue, 10);
  11432. var a = parseFloat(alpha);
  11433. return rgbaColour(r2, g, b2, a);
  11434. };
  11435. var fromString = function(rgbaString) {
  11436. if (rgbaString === "transparent") {
  11437. return Optional.some(rgbaColour(0, 0, 0, 0));
  11438. }
  11439. var rgbMatch = rgbRegex.exec(rgbaString);
  11440. if (rgbMatch !== null) {
  11441. return Optional.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], "1"));
  11442. }
  11443. var rgbaMatch = rgbaRegex.exec(rgbaString);
  11444. if (rgbaMatch !== null) {
  11445. return Optional.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
  11446. }
  11447. return Optional.none();
  11448. };
  11449. var toString = function(rgba) {
  11450. return "rgba(" + rgba.red + "," + rgba.green + "," + rgba.blue + "," + rgba.alpha + ")";
  11451. };
  11452. var red = rgbaColour(255, 0, 0, 1);
  11453. var fireSkinLoaded$1 = function(editor) {
  11454. return editor.fire("SkinLoaded");
  11455. };
  11456. var fireSkinLoadError$1 = function(editor, error2) {
  11457. return editor.fire("SkinLoadError", error2);
  11458. };
  11459. var fireResizeEditor = function(editor) {
  11460. return editor.fire("ResizeEditor");
  11461. };
  11462. var fireResizeContent = function(editor, e) {
  11463. return editor.fire("ResizeContent", e);
  11464. };
  11465. var fireScrollContent = function(editor, e) {
  11466. return editor.fire("ScrollContent", e);
  11467. };
  11468. var fireTextColorChange = function(editor, data) {
  11469. return editor.fire("TextColorChange", data);
  11470. };
  11471. var hsvColour = function(hue, saturation, value2) {
  11472. return {
  11473. hue,
  11474. saturation,
  11475. value: value2
  11476. };
  11477. };
  11478. var fromRgb = function(rgbaColour2) {
  11479. var h = 0;
  11480. var s = 0;
  11481. var v = 0;
  11482. var r2 = rgbaColour2.red / 255;
  11483. var g = rgbaColour2.green / 255;
  11484. var b2 = rgbaColour2.blue / 255;
  11485. var minRGB = Math.min(r2, Math.min(g, b2));
  11486. var maxRGB = Math.max(r2, Math.max(g, b2));
  11487. if (minRGB === maxRGB) {
  11488. v = minRGB;
  11489. return hsvColour(0, 0, v * 100);
  11490. }
  11491. var d = r2 === minRGB ? g - b2 : b2 === minRGB ? r2 - g : b2 - r2;
  11492. h = r2 === minRGB ? 3 : b2 === minRGB ? 1 : 5;
  11493. h = 60 * (h - d / (maxRGB - minRGB));
  11494. s = (maxRGB - minRGB) / maxRGB;
  11495. v = maxRGB;
  11496. return hsvColour(Math.round(h), Math.round(s * 100), Math.round(v * 100));
  11497. };
  11498. var hexToHsv = function(hex) {
  11499. return fromRgb(fromHex(hex));
  11500. };
  11501. var hsvToHex = function(hsv) {
  11502. return fromRgba(fromHsv(hsv));
  11503. };
  11504. var anyToHex = function(color) {
  11505. return fromString$1(color).orThunk(function() {
  11506. return fromString(color).map(fromRgba);
  11507. }).getOrThunk(function() {
  11508. var canvas = document.createElement("canvas");
  11509. canvas.height = 1;
  11510. canvas.width = 1;
  11511. var canvasContext = canvas.getContext("2d");
  11512. canvasContext.clearRect(0, 0, canvas.width, canvas.height);
  11513. canvasContext.fillStyle = "#FFFFFF";
  11514. canvasContext.fillStyle = color;
  11515. canvasContext.fillRect(0, 0, 1, 1);
  11516. var rgba = canvasContext.getImageData(0, 0, 1, 1).data;
  11517. var r2 = rgba[0];
  11518. var g = rgba[1];
  11519. var b2 = rgba[2];
  11520. var a = rgba[3];
  11521. return fromRgba(rgbaColour(r2, g, b2, a));
  11522. });
  11523. };
  11524. var global$8 = tinymce.util.Tools.resolve("tinymce.util.LocalStorage");
  11525. var storageName = "tinymce-custom-colors";
  11526. function ColorCache(max2) {
  11527. if (max2 === void 0) {
  11528. max2 = 10;
  11529. }
  11530. var storageString = global$8.getItem(storageName);
  11531. var localstorage = isString(storageString) ? JSON.parse(storageString) : [];
  11532. var prune = function(list) {
  11533. var diff = max2 - list.length;
  11534. return diff < 0 ? list.slice(0, max2) : list;
  11535. };
  11536. var cache = prune(localstorage);
  11537. var add2 = function(key) {
  11538. indexOf(cache, key).each(remove2);
  11539. cache.unshift(key);
  11540. if (cache.length > max2) {
  11541. cache.pop();
  11542. }
  11543. global$8.setItem(storageName, JSON.stringify(cache));
  11544. };
  11545. var remove2 = function(idx) {
  11546. cache.splice(idx, 1);
  11547. };
  11548. var state = function() {
  11549. return cache.slice(0);
  11550. };
  11551. return {
  11552. add: add2,
  11553. state
  11554. };
  11555. }
  11556. var choiceItem = "choiceitem";
  11557. var defaultColors = [
  11558. {
  11559. type: choiceItem,
  11560. text: "Light Green",
  11561. value: "#BFEDD2"
  11562. },
  11563. {
  11564. type: choiceItem,
  11565. text: "Light Yellow",
  11566. value: "#FBEEB8"
  11567. },
  11568. {
  11569. type: choiceItem,
  11570. text: "Light Red",
  11571. value: "#F8CAC6"
  11572. },
  11573. {
  11574. type: choiceItem,
  11575. text: "Light Purple",
  11576. value: "#ECCAFA"
  11577. },
  11578. {
  11579. type: choiceItem,
  11580. text: "Light Blue",
  11581. value: "#C2E0F4"
  11582. },
  11583. {
  11584. type: choiceItem,
  11585. text: "Green",
  11586. value: "#2DC26B"
  11587. },
  11588. {
  11589. type: choiceItem,
  11590. text: "Yellow",
  11591. value: "#F1C40F"
  11592. },
  11593. {
  11594. type: choiceItem,
  11595. text: "Red",
  11596. value: "#E03E2D"
  11597. },
  11598. {
  11599. type: choiceItem,
  11600. text: "Purple",
  11601. value: "#B96AD9"
  11602. },
  11603. {
  11604. type: choiceItem,
  11605. text: "Blue",
  11606. value: "#3598DB"
  11607. },
  11608. {
  11609. type: choiceItem,
  11610. text: "Dark Turquoise",
  11611. value: "#169179"
  11612. },
  11613. {
  11614. type: choiceItem,
  11615. text: "Orange",
  11616. value: "#E67E23"
  11617. },
  11618. {
  11619. type: choiceItem,
  11620. text: "Dark Red",
  11621. value: "#BA372A"
  11622. },
  11623. {
  11624. type: choiceItem,
  11625. text: "Dark Purple",
  11626. value: "#843FA1"
  11627. },
  11628. {
  11629. type: choiceItem,
  11630. text: "Dark Blue",
  11631. value: "#236FA1"
  11632. },
  11633. {
  11634. type: choiceItem,
  11635. text: "Light Gray",
  11636. value: "#ECF0F1"
  11637. },
  11638. {
  11639. type: choiceItem,
  11640. text: "Medium Gray",
  11641. value: "#CED4D9"
  11642. },
  11643. {
  11644. type: choiceItem,
  11645. text: "Gray",
  11646. value: "#95A5A6"
  11647. },
  11648. {
  11649. type: choiceItem,
  11650. text: "Dark Gray",
  11651. value: "#7E8C8D"
  11652. },
  11653. {
  11654. type: choiceItem,
  11655. text: "Navy Blue",
  11656. value: "#34495E"
  11657. },
  11658. {
  11659. type: choiceItem,
  11660. text: "Black",
  11661. value: "#000000"
  11662. },
  11663. {
  11664. type: choiceItem,
  11665. text: "White",
  11666. value: "#ffffff"
  11667. }
  11668. ];
  11669. var colorCache = ColorCache(10);
  11670. var mapColors = function(colorMap) {
  11671. var colors = [];
  11672. for (var i = 0; i < colorMap.length; i += 2) {
  11673. colors.push({
  11674. text: colorMap[i + 1],
  11675. value: "#" + anyToHex(colorMap[i]).value,
  11676. type: "choiceitem"
  11677. });
  11678. }
  11679. return colors;
  11680. };
  11681. var getColorCols$2 = function(editor, defaultCols) {
  11682. return editor.getParam("color_cols", defaultCols, "number");
  11683. };
  11684. var hasCustomColors$1 = function(editor) {
  11685. return editor.getParam("custom_colors") !== false;
  11686. };
  11687. var getColorMap = function(editor) {
  11688. return editor.getParam("color_map");
  11689. };
  11690. var getColors$2 = function(editor) {
  11691. var unmapped = getColorMap(editor);
  11692. return unmapped !== void 0 ? mapColors(unmapped) : defaultColors;
  11693. };
  11694. var getCurrentColors = function() {
  11695. return map$2(colorCache.state(), function(color) {
  11696. return {
  11697. type: choiceItem,
  11698. text: color,
  11699. value: color
  11700. };
  11701. });
  11702. };
  11703. var addColor = function(color) {
  11704. colorCache.add(color);
  11705. };
  11706. var fallbackColor = "#000000";
  11707. var getCurrentColor = function(editor, format) {
  11708. var color;
  11709. editor.dom.getParents(editor.selection.getStart(), function(elm) {
  11710. var value2;
  11711. if (value2 = elm.style[format === "forecolor" ? "color" : "background-color"]) {
  11712. color = color ? color : value2;
  11713. }
  11714. });
  11715. return Optional.from(color);
  11716. };
  11717. var applyFormat = function(editor, format, value2) {
  11718. editor.undoManager.transact(function() {
  11719. editor.focus();
  11720. editor.formatter.apply(format, { value: value2 });
  11721. editor.nodeChanged();
  11722. });
  11723. };
  11724. var removeFormat = function(editor, format) {
  11725. editor.undoManager.transact(function() {
  11726. editor.focus();
  11727. editor.formatter.remove(format, { value: null }, null, true);
  11728. editor.nodeChanged();
  11729. });
  11730. };
  11731. var registerCommands = function(editor) {
  11732. editor.addCommand("mceApplyTextcolor", function(format, value2) {
  11733. applyFormat(editor, format, value2);
  11734. });
  11735. editor.addCommand("mceRemoveTextcolor", function(format) {
  11736. removeFormat(editor, format);
  11737. });
  11738. };
  11739. var calcCols = function(colors) {
  11740. return Math.max(5, Math.ceil(Math.sqrt(colors)));
  11741. };
  11742. var getColorCols$1 = function(editor) {
  11743. var colors = getColors$2(editor);
  11744. var defaultCols = calcCols(colors.length);
  11745. return getColorCols$2(editor, defaultCols);
  11746. };
  11747. var getAdditionalColors = function(hasCustom) {
  11748. var type2 = "choiceitem";
  11749. var remove2 = {
  11750. type: type2,
  11751. text: "Remove color",
  11752. icon: "color-swatch-remove-color",
  11753. value: "remove"
  11754. };
  11755. var custom2 = {
  11756. type: type2,
  11757. text: "Custom color",
  11758. icon: "color-picker",
  11759. value: "custom"
  11760. };
  11761. return hasCustom ? [
  11762. remove2,
  11763. custom2
  11764. ] : [remove2];
  11765. };
  11766. var applyColor = function(editor, format, value2, onChoice) {
  11767. if (value2 === "custom") {
  11768. var dialog = colorPickerDialog(editor);
  11769. dialog(function(colorOpt) {
  11770. colorOpt.each(function(color) {
  11771. addColor(color);
  11772. editor.execCommand("mceApplyTextcolor", format, color);
  11773. onChoice(color);
  11774. });
  11775. }, fallbackColor);
  11776. } else if (value2 === "remove") {
  11777. onChoice("");
  11778. editor.execCommand("mceRemoveTextcolor", format);
  11779. } else {
  11780. onChoice(value2);
  11781. editor.execCommand("mceApplyTextcolor", format, value2);
  11782. }
  11783. };
  11784. var getColors$1 = function(colors, hasCustom) {
  11785. return colors.concat(getCurrentColors().concat(getAdditionalColors(hasCustom)));
  11786. };
  11787. var getFetch$1 = function(colors, hasCustom) {
  11788. return function(callback) {
  11789. callback(getColors$1(colors, hasCustom));
  11790. };
  11791. };
  11792. var setIconColor = function(splitButtonApi, name2, newColor) {
  11793. var id = name2 === "forecolor" ? "tox-icon-text-color__color" : "tox-icon-highlight-bg-color__color";
  11794. splitButtonApi.setIconFill(id, newColor);
  11795. };
  11796. var registerTextColorButton = function(editor, name2, format, tooltip, lastColor) {
  11797. editor.ui.registry.addSplitButton(name2, {
  11798. tooltip,
  11799. presets: "color",
  11800. icon: name2 === "forecolor" ? "text-color" : "highlight-bg-color",
  11801. select: function(value2) {
  11802. var optCurrentRgb = getCurrentColor(editor, format);
  11803. return optCurrentRgb.bind(function(currentRgb) {
  11804. return fromString(currentRgb).map(function(rgba) {
  11805. var currentHex = fromRgba(rgba).value;
  11806. return contains$1(value2.toLowerCase(), currentHex);
  11807. });
  11808. }).getOr(false);
  11809. },
  11810. columns: getColorCols$1(editor),
  11811. fetch: getFetch$1(getColors$2(editor), hasCustomColors$1(editor)),
  11812. onAction: function(_splitButtonApi) {
  11813. applyColor(editor, format, lastColor.get(), noop);
  11814. },
  11815. onItemAction: function(_splitButtonApi, value2) {
  11816. applyColor(editor, format, value2, function(newColor) {
  11817. lastColor.set(newColor);
  11818. fireTextColorChange(editor, {
  11819. name: name2,
  11820. color: newColor
  11821. });
  11822. });
  11823. },
  11824. onSetup: function(splitButtonApi) {
  11825. setIconColor(splitButtonApi, name2, lastColor.get());
  11826. var handler = function(e) {
  11827. if (e.name === name2) {
  11828. setIconColor(splitButtonApi, e.name, e.color);
  11829. }
  11830. };
  11831. editor.on("TextColorChange", handler);
  11832. return function() {
  11833. editor.off("TextColorChange", handler);
  11834. };
  11835. }
  11836. });
  11837. };
  11838. var registerTextColorMenuItem = function(editor, name2, format, text2) {
  11839. editor.ui.registry.addNestedMenuItem(name2, {
  11840. text: text2,
  11841. icon: name2 === "forecolor" ? "text-color" : "highlight-bg-color",
  11842. getSubmenuItems: function() {
  11843. return [{
  11844. type: "fancymenuitem",
  11845. fancytype: "colorswatch",
  11846. onAction: function(data) {
  11847. applyColor(editor, format, data.value, noop);
  11848. }
  11849. }];
  11850. }
  11851. });
  11852. };
  11853. var colorPickerDialog = function(editor) {
  11854. return function(callback, value2) {
  11855. var isValid = false;
  11856. var onSubmit = function(api2) {
  11857. var data = api2.getData();
  11858. var hex = data.colorpicker;
  11859. if (isValid) {
  11860. callback(Optional.from(hex));
  11861. api2.close();
  11862. } else {
  11863. editor.windowManager.alert(editor.translate([
  11864. "Invalid hex color code: {0}",
  11865. hex
  11866. ]));
  11867. }
  11868. };
  11869. var onAction = function(_api, details) {
  11870. if (details.name === "hex-valid") {
  11871. isValid = details.value;
  11872. }
  11873. };
  11874. var initialData = { colorpicker: value2 };
  11875. editor.windowManager.open({
  11876. title: "Color Picker",
  11877. size: "normal",
  11878. body: {
  11879. type: "panel",
  11880. items: [{
  11881. type: "colorpicker",
  11882. name: "colorpicker",
  11883. label: "Color"
  11884. }]
  11885. },
  11886. buttons: [
  11887. {
  11888. type: "cancel",
  11889. name: "cancel",
  11890. text: "Cancel"
  11891. },
  11892. {
  11893. type: "submit",
  11894. name: "save",
  11895. text: "Save",
  11896. primary: true
  11897. }
  11898. ],
  11899. initialData,
  11900. onAction,
  11901. onSubmit,
  11902. onClose: noop,
  11903. onCancel: function() {
  11904. callback(Optional.none());
  11905. }
  11906. });
  11907. };
  11908. };
  11909. var register$a = function(editor) {
  11910. registerCommands(editor);
  11911. var lastForeColor = Cell(fallbackColor);
  11912. var lastBackColor = Cell(fallbackColor);
  11913. registerTextColorButton(editor, "forecolor", "forecolor", "Text color", lastForeColor);
  11914. registerTextColorButton(editor, "backcolor", "hilitecolor", "Background color", lastBackColor);
  11915. registerTextColorMenuItem(editor, "forecolor", "forecolor", "Text color");
  11916. registerTextColorMenuItem(editor, "backcolor", "hilitecolor", "Background color");
  11917. };
  11918. var createPartialChoiceMenu = function(value2, items, onItemValueHandler, columns, presets, itemResponse, select2, providersBackstage) {
  11919. var hasIcons = menuHasIcons(items);
  11920. var presetItemTypes = presets !== "color" ? "normal" : "color";
  11921. var alloyItems = createChoiceItems(items, onItemValueHandler, columns, presetItemTypes, itemResponse, select2, providersBackstage);
  11922. return createPartialMenuWithAlloyItems(value2, hasIcons, alloyItems, columns, presets);
  11923. };
  11924. var createChoiceItems = function(items, onItemValueHandler, columns, itemPresets, itemResponse, select2, providersBackstage) {
  11925. return cat(map$2(items, function(item2) {
  11926. if (item2.type === "choiceitem") {
  11927. return createChoiceMenuItem(item2).fold(handleError, function(d) {
  11928. return Optional.some(renderChoiceItem(d, columns === 1, itemPresets, onItemValueHandler, select2(item2.value), itemResponse, providersBackstage, menuHasIcons(items)));
  11929. });
  11930. } else {
  11931. return Optional.none();
  11932. }
  11933. }));
  11934. };
  11935. var deriveMenuMovement = function(columns, presets) {
  11936. var menuMarkers = markers(presets);
  11937. if (columns === 1) {
  11938. return {
  11939. mode: "menu",
  11940. moveOnTab: true
  11941. };
  11942. } else if (columns === "auto") {
  11943. return {
  11944. mode: "grid",
  11945. selector: "." + menuMarkers.item,
  11946. initSize: {
  11947. numColumns: 1,
  11948. numRows: 1
  11949. }
  11950. };
  11951. } else {
  11952. var rowClass = presets === "color" ? "tox-swatches__row" : "tox-collection__group";
  11953. return {
  11954. mode: "matrix",
  11955. rowSelector: "." + rowClass
  11956. };
  11957. }
  11958. };
  11959. var deriveCollectionMovement = function(columns, presets) {
  11960. if (columns === 1) {
  11961. return {
  11962. mode: "menu",
  11963. moveOnTab: false,
  11964. selector: ".tox-collection__item"
  11965. };
  11966. } else if (columns === "auto") {
  11967. return {
  11968. mode: "flatgrid",
  11969. selector: ".tox-collection__item",
  11970. initSize: {
  11971. numColumns: 1,
  11972. numRows: 1
  11973. }
  11974. };
  11975. } else {
  11976. return {
  11977. mode: "matrix",
  11978. selectors: {
  11979. row: presets === "color" ? ".tox-swatches__row" : ".tox-collection__group",
  11980. cell: presets === "color" ? "." + colorClass : "." + selectableClass
  11981. }
  11982. };
  11983. }
  11984. };
  11985. var renderColorSwatchItem = function(spec, backstage) {
  11986. var items = getColorItems(spec, backstage);
  11987. var columns = backstage.colorinput.getColorCols();
  11988. var presets = "color";
  11989. var menuSpec = createPartialChoiceMenu(generate$6("menu-value"), items, function(value2) {
  11990. spec.onAction({ value: value2 });
  11991. }, columns, presets, ItemResponse$1.CLOSE_ON_EXECUTE, never, backstage.shared.providers);
  11992. var widgetSpec = __assign(__assign({}, menuSpec), {
  11993. markers: markers(presets),
  11994. movement: deriveMenuMovement(columns, presets)
  11995. });
  11996. return {
  11997. type: "widget",
  11998. data: { value: generate$6("widget-id") },
  11999. dom: {
  12000. tag: "div",
  12001. classes: ["tox-fancymenuitem"]
  12002. },
  12003. autofocus: true,
  12004. components: [parts$f.widget(Menu.sketch(widgetSpec))]
  12005. };
  12006. };
  12007. var getColorItems = function(spec, backstage) {
  12008. var useCustomColors = spec.initData.allowCustomColors && backstage.colorinput.hasCustomColors();
  12009. return spec.initData.colors.fold(function() {
  12010. return getColors$1(backstage.colorinput.getColors(), useCustomColors);
  12011. }, function(colors) {
  12012. return colors.concat(getAdditionalColors(useCustomColors));
  12013. });
  12014. };
  12015. var cellOverEvent = generate$6("cell-over");
  12016. var cellExecuteEvent = generate$6("cell-execute");
  12017. var makeCell = function(row, col, labelId) {
  12018. var _a2;
  12019. var emitCellOver = function(c) {
  12020. return emitWith(c, cellOverEvent, {
  12021. row,
  12022. col
  12023. });
  12024. };
  12025. var emitExecute2 = function(c) {
  12026. return emitWith(c, cellExecuteEvent, {
  12027. row,
  12028. col
  12029. });
  12030. };
  12031. var onClick = function(c, se) {
  12032. se.stop();
  12033. emitExecute2(c);
  12034. };
  12035. return build$1({
  12036. dom: {
  12037. tag: "div",
  12038. attributes: (_a2 = { role: "button" }, _a2["aria-labelledby"] = labelId, _a2)
  12039. },
  12040. behaviours: derive$1([
  12041. config("insert-table-picker-cell", [
  12042. run$1(mouseover(), Focusing.focus),
  12043. run$1(execute$5(), emitExecute2),
  12044. run$1(click(), onClick),
  12045. run$1(tap(), onClick)
  12046. ]),
  12047. Toggling.config({
  12048. toggleClass: "tox-insert-table-picker__selected",
  12049. toggleOnExecute: false
  12050. }),
  12051. Focusing.config({ onFocus: emitCellOver })
  12052. ])
  12053. });
  12054. };
  12055. var makeCells = function(labelId, numRows, numCols) {
  12056. var cells = [];
  12057. for (var i = 0; i < numRows; i++) {
  12058. var row = [];
  12059. for (var j = 0; j < numCols; j++) {
  12060. row.push(makeCell(i, j, labelId));
  12061. }
  12062. cells.push(row);
  12063. }
  12064. return cells;
  12065. };
  12066. var selectCells = function(cells, selectedRow, selectedColumn, numRows, numColumns) {
  12067. for (var i = 0; i < numRows; i++) {
  12068. for (var j = 0; j < numColumns; j++) {
  12069. Toggling.set(cells[i][j], i <= selectedRow && j <= selectedColumn);
  12070. }
  12071. }
  12072. };
  12073. var makeComponents = function(cells) {
  12074. return bind$3(cells, function(cellRow) {
  12075. return map$2(cellRow, premade);
  12076. });
  12077. };
  12078. var makeLabelText = function(row, col) {
  12079. return text(col + "x" + row);
  12080. };
  12081. var renderInsertTableMenuItem = function(spec) {
  12082. var numRows = 10;
  12083. var numColumns = 10;
  12084. var sizeLabelId = generate$6("size-label");
  12085. var cells = makeCells(sizeLabelId, numRows, numColumns);
  12086. var emptyLabelText = makeLabelText(0, 0);
  12087. var memLabel = record({
  12088. dom: {
  12089. tag: "span",
  12090. classes: ["tox-insert-table-picker__label"],
  12091. attributes: { id: sizeLabelId }
  12092. },
  12093. components: [emptyLabelText],
  12094. behaviours: derive$1([Replacing.config({})])
  12095. });
  12096. return {
  12097. type: "widget",
  12098. data: { value: generate$6("widget-id") },
  12099. dom: {
  12100. tag: "div",
  12101. classes: ["tox-fancymenuitem"]
  12102. },
  12103. autofocus: true,
  12104. components: [parts$f.widget({
  12105. dom: {
  12106. tag: "div",
  12107. classes: ["tox-insert-table-picker"]
  12108. },
  12109. components: makeComponents(cells).concat(memLabel.asSpec()),
  12110. behaviours: derive$1([
  12111. config("insert-table-picker", [
  12112. runOnAttached(function(c) {
  12113. Replacing.set(memLabel.get(c), [emptyLabelText]);
  12114. }),
  12115. runWithTarget(cellOverEvent, function(c, t2, e) {
  12116. var _a2 = e.event, row = _a2.row, col = _a2.col;
  12117. selectCells(cells, row, col, numRows, numColumns);
  12118. Replacing.set(memLabel.get(c), [makeLabelText(row + 1, col + 1)]);
  12119. }),
  12120. runWithTarget(cellExecuteEvent, function(c, _, e) {
  12121. var _a2 = e.event, row = _a2.row, col = _a2.col;
  12122. spec.onAction({
  12123. numRows: row + 1,
  12124. numColumns: col + 1
  12125. });
  12126. emit(c, sandboxClose());
  12127. })
  12128. ]),
  12129. Keying.config({
  12130. initSize: {
  12131. numRows,
  12132. numColumns
  12133. },
  12134. mode: "flatgrid",
  12135. selector: '[role="button"]'
  12136. })
  12137. ])
  12138. })]
  12139. };
  12140. };
  12141. var fancyMenuItems = {
  12142. inserttable: renderInsertTableMenuItem,
  12143. colorswatch: renderColorSwatchItem
  12144. };
  12145. var renderFancyMenuItem = function(spec, backstage) {
  12146. return get$e(fancyMenuItems, spec.fancytype).map(function(render2) {
  12147. return render2(spec, backstage);
  12148. });
  12149. };
  12150. var renderNestedItem = function(spec, itemResponse, providersBackstage, renderIcons, downwardsCaret) {
  12151. if (renderIcons === void 0) {
  12152. renderIcons = true;
  12153. }
  12154. if (downwardsCaret === void 0) {
  12155. downwardsCaret = false;
  12156. }
  12157. var caret = downwardsCaret ? renderDownwardsCaret(providersBackstage.icons) : renderSubmenuCaret(providersBackstage.icons);
  12158. var getApi2 = function(component) {
  12159. return {
  12160. isDisabled: function() {
  12161. return Disabling.isDisabled(component);
  12162. },
  12163. setDisabled: function(state) {
  12164. return Disabling.set(component, state);
  12165. }
  12166. };
  12167. };
  12168. var structure = renderItemStructure({
  12169. presets: "normal",
  12170. iconContent: spec.icon,
  12171. textContent: spec.text,
  12172. htmlContent: Optional.none(),
  12173. ariaLabel: spec.text,
  12174. caret: Optional.some(caret),
  12175. checkMark: Optional.none(),
  12176. shortcutContent: spec.shortcut
  12177. }, providersBackstage, renderIcons);
  12178. return renderCommonItem({
  12179. data: buildData(spec),
  12180. getApi: getApi2,
  12181. disabled: spec.disabled,
  12182. onAction: noop,
  12183. onSetup: spec.onSetup,
  12184. triggersSubmenu: true,
  12185. itemBehaviours: []
  12186. }, structure, itemResponse, providersBackstage);
  12187. };
  12188. var renderNormalItem = function(spec, itemResponse, providersBackstage, renderIcons) {
  12189. if (renderIcons === void 0) {
  12190. renderIcons = true;
  12191. }
  12192. var getApi2 = function(component) {
  12193. return {
  12194. isDisabled: function() {
  12195. return Disabling.isDisabled(component);
  12196. },
  12197. setDisabled: function(state) {
  12198. return Disabling.set(component, state);
  12199. }
  12200. };
  12201. };
  12202. var structure = renderItemStructure({
  12203. presets: "normal",
  12204. iconContent: spec.icon,
  12205. textContent: spec.text,
  12206. htmlContent: Optional.none(),
  12207. ariaLabel: spec.text,
  12208. caret: Optional.none(),
  12209. checkMark: Optional.none(),
  12210. shortcutContent: spec.shortcut
  12211. }, providersBackstage, renderIcons);
  12212. return renderCommonItem({
  12213. data: buildData(spec),
  12214. getApi: getApi2,
  12215. disabled: spec.disabled,
  12216. onAction: spec.onAction,
  12217. onSetup: spec.onSetup,
  12218. triggersSubmenu: false,
  12219. itemBehaviours: []
  12220. }, structure, itemResponse, providersBackstage);
  12221. };
  12222. var renderSeparatorItem = function(spec) {
  12223. var innerHtml = spec.text.fold(function() {
  12224. return {};
  12225. }, function(text2) {
  12226. return { innerHtml: text2 };
  12227. });
  12228. return {
  12229. type: "separator",
  12230. dom: __assign({
  12231. tag: "div",
  12232. classes: [
  12233. selectableClass,
  12234. groupHeadingClass
  12235. ]
  12236. }, innerHtml),
  12237. components: []
  12238. };
  12239. };
  12240. var renderToggleMenuItem = function(spec, itemResponse, providersBackstage, renderIcons) {
  12241. if (renderIcons === void 0) {
  12242. renderIcons = true;
  12243. }
  12244. var getApi2 = function(component) {
  12245. return {
  12246. setActive: function(state) {
  12247. Toggling.set(component, state);
  12248. },
  12249. isActive: function() {
  12250. return Toggling.isOn(component);
  12251. },
  12252. isDisabled: function() {
  12253. return Disabling.isDisabled(component);
  12254. },
  12255. setDisabled: function(state) {
  12256. return Disabling.set(component, state);
  12257. }
  12258. };
  12259. };
  12260. var structure = renderItemStructure({
  12261. iconContent: spec.icon,
  12262. textContent: spec.text,
  12263. htmlContent: Optional.none(),
  12264. ariaLabel: spec.text,
  12265. checkMark: Optional.some(renderCheckmark(providersBackstage.icons)),
  12266. caret: Optional.none(),
  12267. shortcutContent: spec.shortcut,
  12268. presets: "normal",
  12269. meta: spec.meta
  12270. }, providersBackstage, renderIcons);
  12271. return deepMerge(renderCommonItem({
  12272. data: buildData(spec),
  12273. disabled: spec.disabled,
  12274. getApi: getApi2,
  12275. onAction: spec.onAction,
  12276. onSetup: spec.onSetup,
  12277. triggersSubmenu: false,
  12278. itemBehaviours: []
  12279. }, structure, itemResponse, providersBackstage), {
  12280. toggling: {
  12281. toggleClass: tickedClass,
  12282. toggleOnExecute: false,
  12283. selected: spec.active
  12284. }
  12285. });
  12286. };
  12287. var autocomplete = renderAutocompleteItem;
  12288. var separator$3 = renderSeparatorItem;
  12289. var normal = renderNormalItem;
  12290. var nested = renderNestedItem;
  12291. var toggle$1 = renderToggleMenuItem;
  12292. var fancy = renderFancyMenuItem;
  12293. var card = renderCardMenuItem;
  12294. var FocusMode;
  12295. (function(FocusMode2) {
  12296. FocusMode2[FocusMode2["ContentFocus"] = 0] = "ContentFocus";
  12297. FocusMode2[FocusMode2["UiFocus"] = 1] = "UiFocus";
  12298. })(FocusMode || (FocusMode = {}));
  12299. var createMenuItemFromBridge = function(item2, itemResponse, backstage, menuHasIcons2, isHorizontalMenu) {
  12300. var providersBackstage = backstage.shared.providers;
  12301. var parseForHorizontalMenu = function(menuitem) {
  12302. return !isHorizontalMenu ? menuitem : __assign(__assign({}, menuitem), {
  12303. shortcut: Optional.none(),
  12304. icon: menuitem.text.isSome() ? Optional.none() : menuitem.icon
  12305. });
  12306. };
  12307. switch (item2.type) {
  12308. case "menuitem":
  12309. return createMenuItem(item2).fold(handleError, function(d) {
  12310. return Optional.some(normal(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons2));
  12311. });
  12312. case "nestedmenuitem":
  12313. return createNestedMenuItem(item2).fold(handleError, function(d) {
  12314. return Optional.some(nested(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons2, isHorizontalMenu));
  12315. });
  12316. case "togglemenuitem":
  12317. return createToggleMenuItem(item2).fold(handleError, function(d) {
  12318. return Optional.some(toggle$1(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons2));
  12319. });
  12320. case "separator":
  12321. return createSeparatorMenuItem(item2).fold(handleError, function(d) {
  12322. return Optional.some(separator$3(d));
  12323. });
  12324. case "fancymenuitem":
  12325. return createFancyMenuItem(item2).fold(handleError, function(d) {
  12326. return fancy(parseForHorizontalMenu(d), backstage);
  12327. });
  12328. default: {
  12329. console.error("Unknown item in general menu", item2);
  12330. return Optional.none();
  12331. }
  12332. }
  12333. };
  12334. var createAutocompleteItems = function(items, matchText, onItemValueHandler, columns, itemResponse, sharedBackstage, highlightOn) {
  12335. var renderText2 = columns === 1;
  12336. var renderIcons = !renderText2 || menuHasIcons(items);
  12337. return cat(map$2(items, function(item2) {
  12338. switch (item2.type) {
  12339. case "separator":
  12340. return createSeparatorItem(item2).fold(handleError, function(d) {
  12341. return Optional.some(separator$3(d));
  12342. });
  12343. case "cardmenuitem":
  12344. return createCardMenuItem(item2).fold(handleError, function(d) {
  12345. return Optional.some(card(__assign(__assign({}, d), {
  12346. onAction: function(api2) {
  12347. d.onAction(api2);
  12348. onItemValueHandler(d.value, d.meta);
  12349. }
  12350. }), itemResponse, sharedBackstage, {
  12351. itemBehaviours: tooltipBehaviour(d.meta, sharedBackstage),
  12352. cardText: {
  12353. matchText,
  12354. highlightOn
  12355. }
  12356. }));
  12357. });
  12358. case "autocompleteitem":
  12359. default:
  12360. return createAutocompleterItem(item2).fold(handleError, function(d) {
  12361. return Optional.some(autocomplete(d, matchText, renderText2, "normal", onItemValueHandler, itemResponse, sharedBackstage, renderIcons));
  12362. });
  12363. }
  12364. }));
  12365. };
  12366. var createPartialMenu = function(value2, items, itemResponse, backstage, isHorizontalMenu) {
  12367. var hasIcons = menuHasIcons(items);
  12368. var alloyItems = cat(map$2(items, function(item2) {
  12369. var itemHasIcon = function(i) {
  12370. return isHorizontalMenu ? !has$2(i, "text") : hasIcons;
  12371. };
  12372. var createItem = function(i) {
  12373. return createMenuItemFromBridge(i, itemResponse, backstage, itemHasIcon(i), isHorizontalMenu);
  12374. };
  12375. if (item2.type === "nestedmenuitem" && item2.getSubmenuItems().length <= 0) {
  12376. return createItem(__assign(__assign({}, item2), { disabled: true }));
  12377. } else {
  12378. return createItem(item2);
  12379. }
  12380. }));
  12381. var createPartial = isHorizontalMenu ? createHorizontalPartialMenuWithAlloyItems : createPartialMenuWithAlloyItems;
  12382. return createPartial(value2, hasIcons, alloyItems, 1, "normal");
  12383. };
  12384. var createTieredDataFrom = function(partialMenu) {
  12385. return tieredMenu.singleData(partialMenu.value, partialMenu);
  12386. };
  12387. var createMenuFrom = function(partialMenu, columns, focusMode, presets) {
  12388. var focusManager = focusMode === FocusMode.ContentFocus ? highlights() : dom$2();
  12389. var movement = deriveMenuMovement(columns, presets);
  12390. var menuMarkers = markers(presets);
  12391. return {
  12392. dom: partialMenu.dom,
  12393. components: partialMenu.components,
  12394. items: partialMenu.items,
  12395. value: partialMenu.value,
  12396. markers: {
  12397. selectedItem: menuMarkers.selectedItem,
  12398. item: menuMarkers.item
  12399. },
  12400. movement,
  12401. fakeFocus: focusMode === FocusMode.ContentFocus,
  12402. focusManager,
  12403. menuBehaviours: SimpleBehaviours.unnamedEvents(columns !== "auto" ? [] : [runOnAttached(function(comp, _se) {
  12404. detectSize(comp, 4, menuMarkers.item).each(function(_a2) {
  12405. var numColumns = _a2.numColumns, numRows = _a2.numRows;
  12406. Keying.setGridSize(comp, numRows, numColumns);
  12407. });
  12408. })])
  12409. };
  12410. };
  12411. var register$9 = function(editor, sharedBackstage) {
  12412. var activeAutocompleter = value$1();
  12413. var processingAction = Cell(false);
  12414. var autocompleter = build$1(InlineView.sketch({
  12415. dom: {
  12416. tag: "div",
  12417. classes: ["tox-autocompleter"]
  12418. },
  12419. components: [],
  12420. fireDismissalEventInstead: {},
  12421. inlineBehaviours: derive$1([config("dismissAutocompleter", [run$1(dismissRequested(), function() {
  12422. return cancelIfNecessary();
  12423. })])]),
  12424. lazySink: sharedBackstage.getSink
  12425. }));
  12426. var isMenuOpen = function() {
  12427. return InlineView.isOpen(autocompleter);
  12428. };
  12429. var isActive = function() {
  12430. return activeAutocompleter.get().isSome();
  12431. };
  12432. var hideIfNecessary = function() {
  12433. if (isActive()) {
  12434. InlineView.hide(autocompleter);
  12435. }
  12436. };
  12437. var cancelIfNecessary = function() {
  12438. if (isActive()) {
  12439. var lastElement = activeAutocompleter.get().map(function(ac) {
  12440. return ac.element;
  12441. });
  12442. detect(lastElement.getOr(SugarElement.fromDom(editor.selection.getNode()))).each(unwrap);
  12443. hideIfNecessary();
  12444. activeAutocompleter.clear();
  12445. processingAction.set(false);
  12446. }
  12447. };
  12448. var getAutocompleters = cached(function() {
  12449. return register$b(editor);
  12450. });
  12451. var getCombinedItems = function(triggerChar, matches) {
  12452. var columns = findMap(matches, function(m) {
  12453. return Optional.from(m.columns);
  12454. }).getOr(1);
  12455. return bind$3(matches, function(match) {
  12456. var choices = match.items;
  12457. return createAutocompleteItems(choices, match.matchText, function(itemValue, itemMeta) {
  12458. var nr = editor.selection.getRng();
  12459. getContext(editor.dom, nr, triggerChar).fold(function() {
  12460. return console.error("Lost context. Cursor probably moved");
  12461. }, function(_a2) {
  12462. var range2 = _a2.range;
  12463. var autocompleterApi = {
  12464. hide: function() {
  12465. cancelIfNecessary();
  12466. },
  12467. reload: function(fetchOptions) {
  12468. hideIfNecessary();
  12469. load(fetchOptions);
  12470. }
  12471. };
  12472. processingAction.set(true);
  12473. match.onAction(autocompleterApi, range2, itemValue, itemMeta);
  12474. processingAction.set(false);
  12475. });
  12476. }, columns, ItemResponse$1.BUBBLE_TO_SANDBOX, sharedBackstage, match.highlightOn);
  12477. });
  12478. };
  12479. var commenceIfNecessary = function(context) {
  12480. if (!isActive()) {
  12481. var wrapper = create$4(editor, context.range);
  12482. activeAutocompleter.set({
  12483. triggerChar: context.triggerChar,
  12484. element: wrapper,
  12485. matchLength: context.text.length
  12486. });
  12487. processingAction.set(false);
  12488. }
  12489. };
  12490. var display = function(ac, context, lookupData, items) {
  12491. ac.matchLength = context.text.length;
  12492. var columns = findMap(lookupData, function(ld) {
  12493. return Optional.from(ld.columns);
  12494. }).getOr(1);
  12495. InlineView.showAt(autocompleter, Menu.sketch(createMenuFrom(createPartialMenuWithAlloyItems("autocompleter-value", true, items, columns, "normal"), columns, FocusMode.ContentFocus, "normal")), {
  12496. anchor: {
  12497. type: "node",
  12498. root: SugarElement.fromDom(editor.getBody()),
  12499. node: Optional.from(ac.element)
  12500. }
  12501. });
  12502. InlineView.getContent(autocompleter).each(Highlighting.highlightFirst);
  12503. };
  12504. var doLookup = function(fetchOptions) {
  12505. return activeAutocompleter.get().map(function(ac) {
  12506. return getContext(editor.dom, editor.selection.getRng(), ac.triggerChar).bind(function(newContext) {
  12507. return lookupWithContext(editor, getAutocompleters, newContext, fetchOptions);
  12508. });
  12509. }).getOrThunk(function() {
  12510. return lookup$2(editor, getAutocompleters);
  12511. });
  12512. };
  12513. var load = function(fetchOptions) {
  12514. doLookup(fetchOptions).fold(cancelIfNecessary, function(lookupInfo) {
  12515. commenceIfNecessary(lookupInfo.context);
  12516. lookupInfo.lookupData.then(function(lookupData) {
  12517. activeAutocompleter.get().map(function(ac) {
  12518. var context = lookupInfo.context;
  12519. if (ac.triggerChar === context.triggerChar) {
  12520. var combinedItems = getCombinedItems(context.triggerChar, lookupData);
  12521. if (combinedItems.length > 0) {
  12522. display(ac, context, lookupData, combinedItems);
  12523. } else if (context.text.length - ac.matchLength >= 10) {
  12524. cancelIfNecessary();
  12525. } else {
  12526. hideIfNecessary();
  12527. }
  12528. }
  12529. });
  12530. });
  12531. });
  12532. };
  12533. var onKeypress = last(function(e) {
  12534. if (e.which === 27) {
  12535. return;
  12536. }
  12537. load();
  12538. }, 50);
  12539. var autocompleterUiApi = {
  12540. onKeypress,
  12541. cancelIfNecessary,
  12542. isMenuOpen,
  12543. isActive,
  12544. isProcessingAction: processingAction.get,
  12545. getView: function() {
  12546. return InlineView.getContent(autocompleter);
  12547. }
  12548. };
  12549. if (editor.hasPlugin("rtc") === false) {
  12550. AutocompleterEditorEvents.setup(autocompleterUiApi, editor);
  12551. }
  12552. };
  12553. var Autocompleter = { register: register$9 };
  12554. var closest = function(scope, selector, isRoot) {
  12555. return closest$1(scope, selector, isRoot).isSome();
  12556. };
  12557. var DelayedFunction = function(fun, delay) {
  12558. var ref = null;
  12559. var schedule = function() {
  12560. var args = [];
  12561. for (var _i = 0; _i < arguments.length; _i++) {
  12562. args[_i] = arguments[_i];
  12563. }
  12564. ref = setTimeout(function() {
  12565. fun.apply(null, args);
  12566. ref = null;
  12567. }, delay);
  12568. };
  12569. var cancel = function() {
  12570. if (ref !== null) {
  12571. clearTimeout(ref);
  12572. ref = null;
  12573. }
  12574. };
  12575. return {
  12576. cancel,
  12577. schedule
  12578. };
  12579. };
  12580. var SIGNIFICANT_MOVE = 5;
  12581. var LONGPRESS_DELAY = 400;
  12582. var getTouch = function(event) {
  12583. var raw = event.raw;
  12584. if (raw.touches === void 0 || raw.touches.length !== 1) {
  12585. return Optional.none();
  12586. }
  12587. return Optional.some(raw.touches[0]);
  12588. };
  12589. var isFarEnough = function(touch2, data) {
  12590. var distX = Math.abs(touch2.clientX - data.x);
  12591. var distY = Math.abs(touch2.clientY - data.y);
  12592. return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
  12593. };
  12594. var monitor = function(settings) {
  12595. var startData = value$1();
  12596. var longpressFired = Cell(false);
  12597. var longpress$1 = DelayedFunction(function(event) {
  12598. settings.triggerEvent(longpress(), event);
  12599. longpressFired.set(true);
  12600. }, LONGPRESS_DELAY);
  12601. var handleTouchstart = function(event) {
  12602. getTouch(event).each(function(touch2) {
  12603. longpress$1.cancel();
  12604. var data = {
  12605. x: touch2.clientX,
  12606. y: touch2.clientY,
  12607. target: event.target
  12608. };
  12609. longpress$1.schedule(event);
  12610. longpressFired.set(false);
  12611. startData.set(data);
  12612. });
  12613. return Optional.none();
  12614. };
  12615. var handleTouchmove = function(event) {
  12616. longpress$1.cancel();
  12617. getTouch(event).each(function(touch2) {
  12618. startData.on(function(data) {
  12619. if (isFarEnough(touch2, data)) {
  12620. startData.clear();
  12621. }
  12622. });
  12623. });
  12624. return Optional.none();
  12625. };
  12626. var handleTouchend = function(event) {
  12627. longpress$1.cancel();
  12628. var isSame = function(data) {
  12629. return eq(data.target, event.target);
  12630. };
  12631. return startData.get().filter(isSame).map(function(_data) {
  12632. if (longpressFired.get()) {
  12633. event.prevent();
  12634. return false;
  12635. } else {
  12636. return settings.triggerEvent(tap(), event);
  12637. }
  12638. });
  12639. };
  12640. var handlers2 = wrapAll([
  12641. {
  12642. key: touchstart(),
  12643. value: handleTouchstart
  12644. },
  12645. {
  12646. key: touchmove(),
  12647. value: handleTouchmove
  12648. },
  12649. {
  12650. key: touchend(),
  12651. value: handleTouchend
  12652. }
  12653. ]);
  12654. var fireIfReady = function(event, type2) {
  12655. return get$e(handlers2, type2).bind(function(handler) {
  12656. return handler(event);
  12657. });
  12658. };
  12659. return { fireIfReady };
  12660. };
  12661. var isDangerous = function(event) {
  12662. var keyEv = event.raw;
  12663. return keyEv.which === BACKSPACE[0] && !contains$2([
  12664. "input",
  12665. "textarea"
  12666. ], name$2(event.target)) && !closest(event.target, '[contenteditable="true"]');
  12667. };
  12668. var isFirefox = function() {
  12669. return detect$1().browser.isFirefox();
  12670. };
  12671. var bindFocus = function(container, handler) {
  12672. if (isFirefox()) {
  12673. return capture(container, "focus", handler);
  12674. } else {
  12675. return bind(container, "focusin", handler);
  12676. }
  12677. };
  12678. var bindBlur = function(container, handler) {
  12679. if (isFirefox()) {
  12680. return capture(container, "blur", handler);
  12681. } else {
  12682. return bind(container, "focusout", handler);
  12683. }
  12684. };
  12685. var setup$d = function(container, rawSettings) {
  12686. var settings = __assign({ stopBackspace: true }, rawSettings);
  12687. var pointerEvents2 = [
  12688. "touchstart",
  12689. "touchmove",
  12690. "touchend",
  12691. "touchcancel",
  12692. "gesturestart",
  12693. "mousedown",
  12694. "mouseup",
  12695. "mouseover",
  12696. "mousemove",
  12697. "mouseout",
  12698. "click"
  12699. ];
  12700. var tapEvent = monitor(settings);
  12701. var simpleEvents = map$2(pointerEvents2.concat([
  12702. "selectstart",
  12703. "input",
  12704. "contextmenu",
  12705. "change",
  12706. "transitionend",
  12707. "transitioncancel",
  12708. "drag",
  12709. "dragstart",
  12710. "dragend",
  12711. "dragenter",
  12712. "dragleave",
  12713. "dragover",
  12714. "drop",
  12715. "keyup"
  12716. ]), function(type2) {
  12717. return bind(container, type2, function(event) {
  12718. tapEvent.fireIfReady(event, type2).each(function(tapStopped) {
  12719. if (tapStopped) {
  12720. event.kill();
  12721. }
  12722. });
  12723. var stopped = settings.triggerEvent(type2, event);
  12724. if (stopped) {
  12725. event.kill();
  12726. }
  12727. });
  12728. });
  12729. var pasteTimeout = value$1();
  12730. var onPaste = bind(container, "paste", function(event) {
  12731. tapEvent.fireIfReady(event, "paste").each(function(tapStopped) {
  12732. if (tapStopped) {
  12733. event.kill();
  12734. }
  12735. });
  12736. var stopped = settings.triggerEvent("paste", event);
  12737. if (stopped) {
  12738. event.kill();
  12739. }
  12740. pasteTimeout.set(setTimeout(function() {
  12741. settings.triggerEvent(postPaste(), event);
  12742. }, 0));
  12743. });
  12744. var onKeydown = bind(container, "keydown", function(event) {
  12745. var stopped = settings.triggerEvent("keydown", event);
  12746. if (stopped) {
  12747. event.kill();
  12748. } else if (settings.stopBackspace && isDangerous(event)) {
  12749. event.prevent();
  12750. }
  12751. });
  12752. var onFocusIn = bindFocus(container, function(event) {
  12753. var stopped = settings.triggerEvent("focusin", event);
  12754. if (stopped) {
  12755. event.kill();
  12756. }
  12757. });
  12758. var focusoutTimeout = value$1();
  12759. var onFocusOut = bindBlur(container, function(event) {
  12760. var stopped = settings.triggerEvent("focusout", event);
  12761. if (stopped) {
  12762. event.kill();
  12763. }
  12764. focusoutTimeout.set(setTimeout(function() {
  12765. settings.triggerEvent(postBlur(), event);
  12766. }, 0));
  12767. });
  12768. var unbind2 = function() {
  12769. each$1(simpleEvents, function(e) {
  12770. e.unbind();
  12771. });
  12772. onKeydown.unbind();
  12773. onFocusIn.unbind();
  12774. onFocusOut.unbind();
  12775. onPaste.unbind();
  12776. pasteTimeout.on(clearTimeout);
  12777. focusoutTimeout.on(clearTimeout);
  12778. };
  12779. return { unbind: unbind2 };
  12780. };
  12781. var derive = function(rawEvent, rawTarget) {
  12782. var source = get$e(rawEvent, "target").getOr(rawTarget);
  12783. return Cell(source);
  12784. };
  12785. var fromSource = function(event, source) {
  12786. var stopper2 = Cell(false);
  12787. var cutter2 = Cell(false);
  12788. var stop2 = function() {
  12789. stopper2.set(true);
  12790. };
  12791. var cut = function() {
  12792. cutter2.set(true);
  12793. };
  12794. return {
  12795. stop: stop2,
  12796. cut,
  12797. isStopped: stopper2.get,
  12798. isCut: cutter2.get,
  12799. event,
  12800. setSource: source.set,
  12801. getSource: source.get
  12802. };
  12803. };
  12804. var fromExternal = function(event) {
  12805. var stopper2 = Cell(false);
  12806. var stop2 = function() {
  12807. stopper2.set(true);
  12808. };
  12809. return {
  12810. stop: stop2,
  12811. cut: noop,
  12812. isStopped: stopper2.get,
  12813. isCut: never,
  12814. event,
  12815. setSource: die("Cannot set source of a broadcasted event"),
  12816. getSource: die("Cannot get source of a broadcasted event")
  12817. };
  12818. };
  12819. var adt$1 = Adt.generate([
  12820. { stopped: [] },
  12821. { resume: ["element"] },
  12822. { complete: [] }
  12823. ]);
  12824. var doTriggerHandler = function(lookup2, eventType, rawEvent, target, source, logger) {
  12825. var handler = lookup2(eventType, target);
  12826. var simulatedEvent = fromSource(rawEvent, source);
  12827. return handler.fold(function() {
  12828. logger.logEventNoHandlers(eventType, target);
  12829. return adt$1.complete();
  12830. }, function(handlerInfo) {
  12831. var descHandler = handlerInfo.descHandler;
  12832. var eventHandler2 = getCurried(descHandler);
  12833. eventHandler2(simulatedEvent);
  12834. if (simulatedEvent.isStopped()) {
  12835. logger.logEventStopped(eventType, handlerInfo.element, descHandler.purpose);
  12836. return adt$1.stopped();
  12837. } else if (simulatedEvent.isCut()) {
  12838. logger.logEventCut(eventType, handlerInfo.element, descHandler.purpose);
  12839. return adt$1.complete();
  12840. } else {
  12841. return parent(handlerInfo.element).fold(function() {
  12842. logger.logNoParent(eventType, handlerInfo.element, descHandler.purpose);
  12843. return adt$1.complete();
  12844. }, function(parent2) {
  12845. logger.logEventResponse(eventType, handlerInfo.element, descHandler.purpose);
  12846. return adt$1.resume(parent2);
  12847. });
  12848. }
  12849. });
  12850. };
  12851. var doTriggerOnUntilStopped = function(lookup2, eventType, rawEvent, rawTarget, source, logger) {
  12852. return doTriggerHandler(lookup2, eventType, rawEvent, rawTarget, source, logger).fold(always, function(parent2) {
  12853. return doTriggerOnUntilStopped(lookup2, eventType, rawEvent, parent2, source, logger);
  12854. }, never);
  12855. };
  12856. var triggerHandler = function(lookup2, eventType, rawEvent, target, logger) {
  12857. var source = derive(rawEvent, target);
  12858. return doTriggerHandler(lookup2, eventType, rawEvent, target, source, logger);
  12859. };
  12860. var broadcast = function(listeners, rawEvent, _logger) {
  12861. var simulatedEvent = fromExternal(rawEvent);
  12862. each$1(listeners, function(listener) {
  12863. var descHandler = listener.descHandler;
  12864. var handler = getCurried(descHandler);
  12865. handler(simulatedEvent);
  12866. });
  12867. return simulatedEvent.isStopped();
  12868. };
  12869. var triggerUntilStopped = function(lookup2, eventType, rawEvent, logger) {
  12870. return triggerOnUntilStopped(lookup2, eventType, rawEvent, rawEvent.target, logger);
  12871. };
  12872. var triggerOnUntilStopped = function(lookup2, eventType, rawEvent, rawTarget, logger) {
  12873. var source = derive(rawEvent, rawTarget);
  12874. return doTriggerOnUntilStopped(lookup2, eventType, rawEvent, rawTarget, source, logger);
  12875. };
  12876. var eventHandler = function(element2, descHandler) {
  12877. return {
  12878. element: element2,
  12879. descHandler
  12880. };
  12881. };
  12882. var broadcastHandler = function(id, handler) {
  12883. return {
  12884. id,
  12885. descHandler: handler
  12886. };
  12887. };
  12888. var EventRegistry = function() {
  12889. var registry = {};
  12890. var registerId = function(extraArgs, id, events2) {
  12891. each(events2, function(v, k) {
  12892. var handlers2 = registry[k] !== void 0 ? registry[k] : {};
  12893. handlers2[id] = curryArgs(v, extraArgs);
  12894. registry[k] = handlers2;
  12895. });
  12896. };
  12897. var findHandler = function(handlers2, elem) {
  12898. return read$1(elem).bind(function(id) {
  12899. return get$e(handlers2, id);
  12900. }).map(function(descHandler) {
  12901. return eventHandler(elem, descHandler);
  12902. });
  12903. };
  12904. var filterByType = function(type2) {
  12905. return get$e(registry, type2).map(function(handlers2) {
  12906. return mapToArray(handlers2, function(f, id) {
  12907. return broadcastHandler(id, f);
  12908. });
  12909. }).getOr([]);
  12910. };
  12911. var find2 = function(isAboveRoot, type2, target) {
  12912. return get$e(registry, type2).bind(function(handlers2) {
  12913. return closest$4(target, function(elem) {
  12914. return findHandler(handlers2, elem);
  12915. }, isAboveRoot);
  12916. });
  12917. };
  12918. var unregisterId = function(id) {
  12919. each(registry, function(handlersById, _eventName) {
  12920. if (has$2(handlersById, id)) {
  12921. delete handlersById[id];
  12922. }
  12923. });
  12924. };
  12925. return {
  12926. registerId,
  12927. unregisterId,
  12928. filterByType,
  12929. find: find2
  12930. };
  12931. };
  12932. var Registry = function() {
  12933. var events2 = EventRegistry();
  12934. var components2 = {};
  12935. var readOrTag = function(component) {
  12936. var elem = component.element;
  12937. return read$1(elem).getOrThunk(function() {
  12938. return write("uid-", component.element);
  12939. });
  12940. };
  12941. var failOnDuplicate = function(component, tagId) {
  12942. var conflict = components2[tagId];
  12943. if (conflict === component) {
  12944. unregister(component);
  12945. } else {
  12946. throw new Error('The tagId "' + tagId + '" is already used by: ' + element(conflict.element) + "\nCannot use it for: " + element(component.element) + "\nThe conflicting element is" + (inBody(conflict.element) ? " " : " not ") + "already in the DOM");
  12947. }
  12948. };
  12949. var register2 = function(component) {
  12950. var tagId = readOrTag(component);
  12951. if (hasNonNullableKey(components2, tagId)) {
  12952. failOnDuplicate(component, tagId);
  12953. }
  12954. var extraArgs = [component];
  12955. events2.registerId(extraArgs, tagId, component.events);
  12956. components2[tagId] = component;
  12957. };
  12958. var unregister = function(component) {
  12959. read$1(component.element).each(function(tagId) {
  12960. delete components2[tagId];
  12961. events2.unregisterId(tagId);
  12962. });
  12963. };
  12964. var filter2 = function(type2) {
  12965. return events2.filterByType(type2);
  12966. };
  12967. var find2 = function(isAboveRoot, type2, target) {
  12968. return events2.find(isAboveRoot, type2, target);
  12969. };
  12970. var getById = function(id) {
  12971. return get$e(components2, id);
  12972. };
  12973. return {
  12974. find: find2,
  12975. filter: filter2,
  12976. register: register2,
  12977. unregister,
  12978. getById
  12979. };
  12980. };
  12981. var factory$j = function(detail) {
  12982. var _a2 = detail.dom, attributes = _a2.attributes, domWithoutAttributes = __rest(_a2, ["attributes"]);
  12983. return {
  12984. uid: detail.uid,
  12985. dom: __assign({
  12986. tag: "div",
  12987. attributes: __assign({ role: "presentation" }, attributes)
  12988. }, domWithoutAttributes),
  12989. components: detail.components,
  12990. behaviours: get$2(detail.containerBehaviours),
  12991. events: detail.events,
  12992. domModification: detail.domModification,
  12993. eventOrder: detail.eventOrder
  12994. };
  12995. };
  12996. var Container = single({
  12997. name: "Container",
  12998. factory: factory$j,
  12999. configFields: [
  13000. defaulted("components", []),
  13001. field("containerBehaviours", []),
  13002. defaulted("events", {}),
  13003. defaulted("domModification", {}),
  13004. defaulted("eventOrder", {})
  13005. ]
  13006. });
  13007. var takeover = function(root) {
  13008. var isAboveRoot = function(el) {
  13009. return parent(root.element).fold(always, function(parent2) {
  13010. return eq(el, parent2);
  13011. });
  13012. };
  13013. var registry = Registry();
  13014. var lookup2 = function(eventName, target) {
  13015. return registry.find(isAboveRoot, eventName, target);
  13016. };
  13017. var domEvents = setup$d(root.element, {
  13018. triggerEvent: function(eventName, event) {
  13019. return monitorEvent(eventName, event.target, function(logger) {
  13020. return triggerUntilStopped(lookup2, eventName, event, logger);
  13021. });
  13022. }
  13023. });
  13024. var systemApi = {
  13025. debugInfo: constant$1("real"),
  13026. triggerEvent: function(eventName, target, data) {
  13027. monitorEvent(eventName, target, function(logger) {
  13028. return triggerOnUntilStopped(lookup2, eventName, data, target, logger);
  13029. });
  13030. },
  13031. triggerFocus: function(target, originator) {
  13032. read$1(target).fold(function() {
  13033. focus$3(target);
  13034. }, function(_alloyId) {
  13035. monitorEvent(focus$4(), target, function(logger) {
  13036. triggerHandler(lookup2, focus$4(), {
  13037. originator,
  13038. kill: noop,
  13039. prevent: noop,
  13040. target
  13041. }, target, logger);
  13042. return false;
  13043. });
  13044. });
  13045. },
  13046. triggerEscape: function(comp, simulatedEvent) {
  13047. systemApi.triggerEvent("keydown", comp.element, simulatedEvent.event);
  13048. },
  13049. getByUid: function(uid) {
  13050. return getByUid(uid);
  13051. },
  13052. getByDom: function(elem) {
  13053. return getByDom(elem);
  13054. },
  13055. build: build$1,
  13056. addToGui: function(c) {
  13057. add2(c);
  13058. },
  13059. removeFromGui: function(c) {
  13060. remove2(c);
  13061. },
  13062. addToWorld: function(c) {
  13063. addToWorld(c);
  13064. },
  13065. removeFromWorld: function(c) {
  13066. removeFromWorld(c);
  13067. },
  13068. broadcast: function(message) {
  13069. broadcast$1(message);
  13070. },
  13071. broadcastOn: function(channels, message) {
  13072. broadcastOn(channels, message);
  13073. },
  13074. broadcastEvent: function(eventName, event) {
  13075. broadcastEvent(eventName, event);
  13076. },
  13077. isConnected: always
  13078. };
  13079. var addToWorld = function(component) {
  13080. component.connect(systemApi);
  13081. if (!isText$1(component.element)) {
  13082. registry.register(component);
  13083. each$1(component.components(), addToWorld);
  13084. systemApi.triggerEvent(systemInit(), component.element, { target: component.element });
  13085. }
  13086. };
  13087. var removeFromWorld = function(component) {
  13088. if (!isText$1(component.element)) {
  13089. each$1(component.components(), removeFromWorld);
  13090. registry.unregister(component);
  13091. }
  13092. component.disconnect();
  13093. };
  13094. var add2 = function(component) {
  13095. attach(root, component);
  13096. };
  13097. var remove2 = function(component) {
  13098. detach(component);
  13099. };
  13100. var destroy = function() {
  13101. domEvents.unbind();
  13102. remove$5(root.element);
  13103. };
  13104. var broadcastData = function(data) {
  13105. var receivers = registry.filter(receive());
  13106. each$1(receivers, function(receiver) {
  13107. var descHandler = receiver.descHandler;
  13108. var handler = getCurried(descHandler);
  13109. handler(data);
  13110. });
  13111. };
  13112. var broadcast$1 = function(message) {
  13113. broadcastData({
  13114. universal: true,
  13115. data: message
  13116. });
  13117. };
  13118. var broadcastOn = function(channels, message) {
  13119. broadcastData({
  13120. universal: false,
  13121. channels,
  13122. data: message
  13123. });
  13124. };
  13125. var broadcastEvent = function(eventName, event) {
  13126. var listeners = registry.filter(eventName);
  13127. return broadcast(listeners, event);
  13128. };
  13129. var getByUid = function(uid) {
  13130. return registry.getById(uid).fold(function() {
  13131. return Result.error(new Error('Could not find component with uid: "' + uid + '" in system.'));
  13132. }, Result.value);
  13133. };
  13134. var getByDom = function(elem) {
  13135. var uid = read$1(elem).getOr("not found");
  13136. return getByUid(uid);
  13137. };
  13138. addToWorld(root);
  13139. return {
  13140. root,
  13141. element: root.element,
  13142. destroy,
  13143. add: add2,
  13144. remove: remove2,
  13145. getByUid,
  13146. getByDom,
  13147. addToWorld,
  13148. removeFromWorld,
  13149. broadcast: broadcast$1,
  13150. broadcastOn,
  13151. broadcastEvent
  13152. };
  13153. };
  13154. var renderBar = function(spec, backstage) {
  13155. return {
  13156. dom: {
  13157. tag: "div",
  13158. classes: [
  13159. "tox-bar",
  13160. "tox-form__controls-h-stack"
  13161. ]
  13162. },
  13163. components: map$2(spec.items, backstage.interpreter)
  13164. };
  13165. };
  13166. var schema$l = constant$1([
  13167. defaulted("prefix", "form-field"),
  13168. field("fieldBehaviours", [
  13169. Composing,
  13170. Representing
  13171. ])
  13172. ]);
  13173. var parts$e = constant$1([
  13174. optional({
  13175. schema: [required$1("dom")],
  13176. name: "label"
  13177. }),
  13178. optional({
  13179. factory: {
  13180. sketch: function(spec) {
  13181. return {
  13182. uid: spec.uid,
  13183. dom: {
  13184. tag: "span",
  13185. styles: { display: "none" },
  13186. attributes: { "aria-hidden": "true" },
  13187. innerHtml: spec.text
  13188. }
  13189. };
  13190. }
  13191. },
  13192. schema: [required$1("text")],
  13193. name: "aria-descriptor"
  13194. }),
  13195. required({
  13196. factory: {
  13197. sketch: function(spec) {
  13198. var excludeFactory = exclude(spec, ["factory"]);
  13199. return spec.factory.sketch(excludeFactory);
  13200. }
  13201. },
  13202. schema: [required$1("factory")],
  13203. name: "field"
  13204. })
  13205. ]);
  13206. var factory$i = function(detail, components2, _spec, _externals) {
  13207. var behaviours2 = augment(detail.fieldBehaviours, [
  13208. Composing.config({
  13209. find: function(container) {
  13210. return getPart(container, detail, "field");
  13211. }
  13212. }),
  13213. Representing.config({
  13214. store: {
  13215. mode: "manual",
  13216. getValue: function(field2) {
  13217. return Composing.getCurrent(field2).bind(Representing.getValue);
  13218. },
  13219. setValue: function(field2, value2) {
  13220. Composing.getCurrent(field2).each(function(current) {
  13221. Representing.setValue(current, value2);
  13222. });
  13223. }
  13224. }
  13225. })
  13226. ]);
  13227. var events2 = derive$2([runOnAttached(function(component, _simulatedEvent) {
  13228. var ps = getParts(component, detail, [
  13229. "label",
  13230. "field",
  13231. "aria-descriptor"
  13232. ]);
  13233. ps.field().each(function(field2) {
  13234. var id = generate$6(detail.prefix);
  13235. ps.label().each(function(label) {
  13236. set$8(label.element, "for", id);
  13237. set$8(field2.element, "id", id);
  13238. });
  13239. ps["aria-descriptor"]().each(function(descriptor) {
  13240. var descriptorId = generate$6(detail.prefix);
  13241. set$8(descriptor.element, "id", descriptorId);
  13242. set$8(field2.element, "aria-describedby", descriptorId);
  13243. });
  13244. });
  13245. })]);
  13246. var apis = {
  13247. getField: function(container) {
  13248. return getPart(container, detail, "field");
  13249. },
  13250. getLabel: function(container) {
  13251. return getPart(container, detail, "label");
  13252. }
  13253. };
  13254. return {
  13255. uid: detail.uid,
  13256. dom: detail.dom,
  13257. components: components2,
  13258. behaviours: behaviours2,
  13259. events: events2,
  13260. apis
  13261. };
  13262. };
  13263. var FormField = composite({
  13264. name: "FormField",
  13265. configFields: schema$l(),
  13266. partFields: parts$e(),
  13267. factory: factory$i,
  13268. apis: {
  13269. getField: function(apis, comp) {
  13270. return apis.getField(comp);
  13271. },
  13272. getLabel: function(apis, comp) {
  13273. return apis.getLabel(comp);
  13274. }
  13275. }
  13276. });
  13277. var exhibit$2 = function(base2, tabConfig) {
  13278. return nu$7({
  13279. attributes: wrapAll([{
  13280. key: tabConfig.tabAttr,
  13281. value: "true"
  13282. }])
  13283. });
  13284. };
  13285. var ActiveTabstopping = Object.freeze({
  13286. __proto__: null,
  13287. exhibit: exhibit$2
  13288. });
  13289. var TabstopSchema = [defaulted("tabAttr", "data-alloy-tabstop")];
  13290. var Tabstopping = create$7({
  13291. fields: TabstopSchema,
  13292. name: "tabstopping",
  13293. active: ActiveTabstopping
  13294. });
  13295. var global$7 = tinymce.util.Tools.resolve("tinymce.html.Entities");
  13296. var renderFormFieldWith = function(pLabel, pField, extraClasses, extraBehaviours) {
  13297. var spec = renderFormFieldSpecWith(pLabel, pField, extraClasses, extraBehaviours);
  13298. return FormField.sketch(spec);
  13299. };
  13300. var renderFormField = function(pLabel, pField) {
  13301. return renderFormFieldWith(pLabel, pField, [], []);
  13302. };
  13303. var renderFormFieldSpecWith = function(pLabel, pField, extraClasses, extraBehaviours) {
  13304. return {
  13305. dom: renderFormFieldDomWith(extraClasses),
  13306. components: pLabel.toArray().concat([pField]),
  13307. fieldBehaviours: derive$1(extraBehaviours)
  13308. };
  13309. };
  13310. var renderFormFieldDom = function() {
  13311. return renderFormFieldDomWith([]);
  13312. };
  13313. var renderFormFieldDomWith = function(extraClasses) {
  13314. return {
  13315. tag: "div",
  13316. classes: ["tox-form__group"].concat(extraClasses)
  13317. };
  13318. };
  13319. var renderLabel$2 = function(label, providersBackstage) {
  13320. return FormField.parts.label({
  13321. dom: {
  13322. tag: "label",
  13323. classes: ["tox-label"],
  13324. innerHtml: providersBackstage.translate(label)
  13325. }
  13326. });
  13327. };
  13328. var formChangeEvent = generate$6("form-component-change");
  13329. var formCloseEvent = generate$6("form-close");
  13330. var formCancelEvent = generate$6("form-cancel");
  13331. var formActionEvent = generate$6("form-action");
  13332. var formSubmitEvent = generate$6("form-submit");
  13333. var formBlockEvent = generate$6("form-block");
  13334. var formUnblockEvent = generate$6("form-unblock");
  13335. var formTabChangeEvent = generate$6("form-tabchange");
  13336. var formResizeEvent = generate$6("form-resize");
  13337. var renderCollection = function(spec, providersBackstage) {
  13338. var _a2;
  13339. var pLabel = spec.label.map(function(label) {
  13340. return renderLabel$2(label, providersBackstage);
  13341. });
  13342. var runOnItem = function(f) {
  13343. return function(comp, se) {
  13344. closest$1(se.event.target, "[data-collection-item-value]").each(function(target) {
  13345. f(comp, se, target, get$d(target, "data-collection-item-value"));
  13346. });
  13347. };
  13348. };
  13349. var setContents = function(comp, items) {
  13350. var htmlLines = map$2(items, function(item2) {
  13351. var itemText = global$e.translate(item2.text);
  13352. var textContent = spec.columns === 1 ? '<div class="tox-collection__item-label">' + itemText + "</div>" : "";
  13353. var iconContent = '<div class="tox-collection__item-icon">' + item2.icon + "</div>";
  13354. var mapItemName = {
  13355. "_": " ",
  13356. " - ": " ",
  13357. "-": " "
  13358. };
  13359. var ariaLabel = itemText.replace(/\_| \- |\-/g, function(match) {
  13360. return mapItemName[match];
  13361. });
  13362. var disabledClass = providersBackstage.isDisabled() ? " tox-collection__item--state-disabled" : "";
  13363. return '<div class="tox-collection__item' + disabledClass + '" tabindex="-1" data-collection-item-value="' + global$7.encodeAllRaw(item2.value) + '" title="' + ariaLabel + '" aria-label="' + ariaLabel + '">' + iconContent + textContent + "</div>";
  13364. });
  13365. var chunks = spec.columns !== "auto" && spec.columns > 1 ? chunk$1(htmlLines, spec.columns) : [htmlLines];
  13366. var html = map$2(chunks, function(ch) {
  13367. return '<div class="tox-collection__group">' + ch.join("") + "</div>";
  13368. });
  13369. set$5(comp.element, html.join(""));
  13370. };
  13371. var onClick = runOnItem(function(comp, se, tgt, itemValue) {
  13372. se.stop();
  13373. if (!providersBackstage.isDisabled()) {
  13374. emitWith(comp, formActionEvent, {
  13375. name: spec.name,
  13376. value: itemValue
  13377. });
  13378. }
  13379. });
  13380. var collectionEvents = [
  13381. run$1(mouseover(), runOnItem(function(comp, se, tgt) {
  13382. focus$3(tgt);
  13383. })),
  13384. run$1(click(), onClick),
  13385. run$1(tap(), onClick),
  13386. run$1(focusin(), runOnItem(function(comp, se, tgt) {
  13387. descendant(comp.element, "." + activeClass).each(function(currentActive) {
  13388. remove$2(currentActive, activeClass);
  13389. });
  13390. add$2(tgt, activeClass);
  13391. })),
  13392. run$1(focusout(), runOnItem(function(comp) {
  13393. descendant(comp.element, "." + activeClass).each(function(currentActive) {
  13394. remove$2(currentActive, activeClass);
  13395. });
  13396. })),
  13397. runOnExecute$1(runOnItem(function(comp, se, tgt, itemValue) {
  13398. emitWith(comp, formActionEvent, {
  13399. name: spec.name,
  13400. value: itemValue
  13401. });
  13402. }))
  13403. ];
  13404. var iterCollectionItems = function(comp, applyAttributes) {
  13405. return map$2(descendants(comp.element, ".tox-collection__item"), applyAttributes);
  13406. };
  13407. var pField = FormField.parts.field({
  13408. dom: {
  13409. tag: "div",
  13410. classes: ["tox-collection"].concat(spec.columns !== 1 ? ["tox-collection--grid"] : ["tox-collection--list"])
  13411. },
  13412. components: [],
  13413. factory: { sketch: identity$1 },
  13414. behaviours: derive$1([
  13415. Disabling.config({
  13416. disabled: providersBackstage.isDisabled,
  13417. onDisabled: function(comp) {
  13418. iterCollectionItems(comp, function(childElm) {
  13419. add$2(childElm, "tox-collection__item--state-disabled");
  13420. set$8(childElm, "aria-disabled", true);
  13421. });
  13422. },
  13423. onEnabled: function(comp) {
  13424. iterCollectionItems(comp, function(childElm) {
  13425. remove$2(childElm, "tox-collection__item--state-disabled");
  13426. remove$7(childElm, "aria-disabled");
  13427. });
  13428. }
  13429. }),
  13430. receivingConfig(),
  13431. Replacing.config({}),
  13432. Representing.config({
  13433. store: {
  13434. mode: "memory",
  13435. initialValue: []
  13436. },
  13437. onSetValue: function(comp, items) {
  13438. setContents(comp, items);
  13439. if (spec.columns === "auto") {
  13440. detectSize(comp, 5, "tox-collection__item").each(function(_a3) {
  13441. var numRows = _a3.numRows, numColumns = _a3.numColumns;
  13442. Keying.setGridSize(comp, numRows, numColumns);
  13443. });
  13444. }
  13445. emit(comp, formResizeEvent);
  13446. }
  13447. }),
  13448. Tabstopping.config({}),
  13449. Keying.config(deriveCollectionMovement(spec.columns, "normal")),
  13450. config("collection-events", collectionEvents)
  13451. ]),
  13452. eventOrder: (_a2 = {}, _a2[execute$5()] = [
  13453. "disabling",
  13454. "alloy.base.behaviour",
  13455. "collection-events"
  13456. ], _a2)
  13457. });
  13458. var extraClasses = ["tox-form__group--collection"];
  13459. return renderFormFieldWith(pLabel, pField, extraClasses, []);
  13460. };
  13461. var schema$k = constant$1([
  13462. option("data"),
  13463. defaulted("inputAttributes", {}),
  13464. defaulted("inputStyles", {}),
  13465. defaulted("tag", "input"),
  13466. defaulted("inputClasses", []),
  13467. onHandler("onSetValue"),
  13468. defaulted("styles", {}),
  13469. defaulted("eventOrder", {}),
  13470. field("inputBehaviours", [
  13471. Representing,
  13472. Focusing
  13473. ]),
  13474. defaulted("selectOnFocus", true)
  13475. ]);
  13476. var focusBehaviours = function(detail) {
  13477. return derive$1([Focusing.config({
  13478. onFocus: !detail.selectOnFocus ? noop : function(component) {
  13479. var input2 = component.element;
  13480. var value2 = get$5(input2);
  13481. input2.dom.setSelectionRange(0, value2.length);
  13482. }
  13483. })]);
  13484. };
  13485. var behaviours = function(detail) {
  13486. return __assign(__assign({}, focusBehaviours(detail)), augment(detail.inputBehaviours, [Representing.config({
  13487. store: __assign(__assign({ mode: "manual" }, detail.data.map(function(data) {
  13488. return { initialValue: data };
  13489. }).getOr({})), {
  13490. getValue: function(input2) {
  13491. return get$5(input2.element);
  13492. },
  13493. setValue: function(input2, data) {
  13494. var current = get$5(input2.element);
  13495. if (current !== data) {
  13496. set$4(input2.element, data);
  13497. }
  13498. }
  13499. }),
  13500. onSetValue: detail.onSetValue
  13501. })]));
  13502. };
  13503. var dom = function(detail) {
  13504. return {
  13505. tag: detail.tag,
  13506. attributes: __assign({ type: "text" }, detail.inputAttributes),
  13507. styles: detail.inputStyles,
  13508. classes: detail.inputClasses
  13509. };
  13510. };
  13511. var factory$h = function(detail, _spec) {
  13512. return {
  13513. uid: detail.uid,
  13514. dom: dom(detail),
  13515. components: [],
  13516. behaviours: behaviours(detail),
  13517. eventOrder: detail.eventOrder
  13518. };
  13519. };
  13520. var Input = single({
  13521. name: "Input",
  13522. configFields: schema$k(),
  13523. factory: factory$h
  13524. });
  13525. var exports$1 = {}, module2 = { exports: exports$1 };
  13526. (function(define, exports2, module3, require2) {
  13527. (function(global2, factory2) {
  13528. typeof exports2 === "object" && typeof module3 !== "undefined" ? module3.exports = factory2() : typeof define === "function" && define.amd ? define(factory2) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, global2.EphoxContactWrapper = factory2());
  13529. })(this, function() {
  13530. var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  13531. var promise = { exports: {} };
  13532. (function(module4) {
  13533. (function(root) {
  13534. var setTimeoutFunc = setTimeout;
  13535. function noop2() {
  13536. }
  13537. function bind2(fn, thisArg) {
  13538. return function() {
  13539. fn.apply(thisArg, arguments);
  13540. };
  13541. }
  13542. function Promise2(fn) {
  13543. if (typeof this !== "object")
  13544. throw new TypeError("Promises must be constructed via new");
  13545. if (typeof fn !== "function")
  13546. throw new TypeError("not a function");
  13547. this._state = 0;
  13548. this._handled = false;
  13549. this._value = void 0;
  13550. this._deferreds = [];
  13551. doResolve(fn, this);
  13552. }
  13553. function handle2(self2, deferred) {
  13554. while (self2._state === 3) {
  13555. self2 = self2._value;
  13556. }
  13557. if (self2._state === 0) {
  13558. self2._deferreds.push(deferred);
  13559. return;
  13560. }
  13561. self2._handled = true;
  13562. Promise2._immediateFn(function() {
  13563. var cb = self2._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  13564. if (cb === null) {
  13565. (self2._state === 1 ? resolve : reject)(deferred.promise, self2._value);
  13566. return;
  13567. }
  13568. var ret;
  13569. try {
  13570. ret = cb(self2._value);
  13571. } catch (e) {
  13572. reject(deferred.promise, e);
  13573. return;
  13574. }
  13575. resolve(deferred.promise, ret);
  13576. });
  13577. }
  13578. function resolve(self2, newValue) {
  13579. try {
  13580. if (newValue === self2)
  13581. throw new TypeError("A promise cannot be resolved with itself.");
  13582. if (newValue && (typeof newValue === "object" || typeof newValue === "function")) {
  13583. var then = newValue.then;
  13584. if (newValue instanceof Promise2) {
  13585. self2._state = 3;
  13586. self2._value = newValue;
  13587. finale(self2);
  13588. return;
  13589. } else if (typeof then === "function") {
  13590. doResolve(bind2(then, newValue), self2);
  13591. return;
  13592. }
  13593. }
  13594. self2._state = 1;
  13595. self2._value = newValue;
  13596. finale(self2);
  13597. } catch (e) {
  13598. reject(self2, e);
  13599. }
  13600. }
  13601. function reject(self2, newValue) {
  13602. self2._state = 2;
  13603. self2._value = newValue;
  13604. finale(self2);
  13605. }
  13606. function finale(self2) {
  13607. if (self2._state === 2 && self2._deferreds.length === 0) {
  13608. Promise2._immediateFn(function() {
  13609. if (!self2._handled) {
  13610. Promise2._unhandledRejectionFn(self2._value);
  13611. }
  13612. });
  13613. }
  13614. for (var i = 0, len = self2._deferreds.length; i < len; i++) {
  13615. handle2(self2, self2._deferreds[i]);
  13616. }
  13617. self2._deferreds = null;
  13618. }
  13619. function Handler(onFulfilled, onRejected, promise2) {
  13620. this.onFulfilled = typeof onFulfilled === "function" ? onFulfilled : null;
  13621. this.onRejected = typeof onRejected === "function" ? onRejected : null;
  13622. this.promise = promise2;
  13623. }
  13624. function doResolve(fn, self2) {
  13625. var done = false;
  13626. try {
  13627. fn(function(value2) {
  13628. if (done)
  13629. return;
  13630. done = true;
  13631. resolve(self2, value2);
  13632. }, function(reason) {
  13633. if (done)
  13634. return;
  13635. done = true;
  13636. reject(self2, reason);
  13637. });
  13638. } catch (ex) {
  13639. if (done)
  13640. return;
  13641. done = true;
  13642. reject(self2, ex);
  13643. }
  13644. }
  13645. Promise2.prototype["catch"] = function(onRejected) {
  13646. return this.then(null, onRejected);
  13647. };
  13648. Promise2.prototype.then = function(onFulfilled, onRejected) {
  13649. var prom = new this.constructor(noop2);
  13650. handle2(this, new Handler(onFulfilled, onRejected, prom));
  13651. return prom;
  13652. };
  13653. Promise2.all = function(arr) {
  13654. var args = Array.prototype.slice.call(arr);
  13655. return new Promise2(function(resolve2, reject2) {
  13656. if (args.length === 0)
  13657. return resolve2([]);
  13658. var remaining = args.length;
  13659. function res(i2, val) {
  13660. try {
  13661. if (val && (typeof val === "object" || typeof val === "function")) {
  13662. var then = val.then;
  13663. if (typeof then === "function") {
  13664. then.call(val, function(val2) {
  13665. res(i2, val2);
  13666. }, reject2);
  13667. return;
  13668. }
  13669. }
  13670. args[i2] = val;
  13671. if (--remaining === 0) {
  13672. resolve2(args);
  13673. }
  13674. } catch (ex) {
  13675. reject2(ex);
  13676. }
  13677. }
  13678. for (var i = 0; i < args.length; i++) {
  13679. res(i, args[i]);
  13680. }
  13681. });
  13682. };
  13683. Promise2.resolve = function(value2) {
  13684. if (value2 && typeof value2 === "object" && value2.constructor === Promise2) {
  13685. return value2;
  13686. }
  13687. return new Promise2(function(resolve2) {
  13688. resolve2(value2);
  13689. });
  13690. };
  13691. Promise2.reject = function(value2) {
  13692. return new Promise2(function(resolve2, reject2) {
  13693. reject2(value2);
  13694. });
  13695. };
  13696. Promise2.race = function(values2) {
  13697. return new Promise2(function(resolve2, reject2) {
  13698. for (var i = 0, len = values2.length; i < len; i++) {
  13699. values2[i].then(resolve2, reject2);
  13700. }
  13701. });
  13702. };
  13703. Promise2._immediateFn = typeof setImmediate === "function" ? function(fn) {
  13704. setImmediate(fn);
  13705. } : function(fn) {
  13706. setTimeoutFunc(fn, 0);
  13707. };
  13708. Promise2._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  13709. if (typeof console !== "undefined" && console) {
  13710. console.warn("Possible Unhandled Promise Rejection:", err);
  13711. }
  13712. };
  13713. Promise2._setImmediateFn = function _setImmediateFn(fn) {
  13714. Promise2._immediateFn = fn;
  13715. };
  13716. Promise2._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  13717. Promise2._unhandledRejectionFn = fn;
  13718. };
  13719. if (module4.exports) {
  13720. module4.exports = Promise2;
  13721. } else if (!root.Promise) {
  13722. root.Promise = Promise2;
  13723. }
  13724. })(commonjsGlobal);
  13725. })(promise);
  13726. var promisePolyfill = promise.exports;
  13727. var Global = function() {
  13728. if (typeof window !== "undefined") {
  13729. return window;
  13730. } else {
  13731. return Function("return this;")();
  13732. }
  13733. }();
  13734. var promisePolyfill_1 = { boltExport: Global.Promise || promisePolyfill };
  13735. return promisePolyfill_1;
  13736. });
  13737. })(void 0, exports$1, module2);
  13738. var Promise$1 = module2.exports.boltExport;
  13739. var nu$3 = function(baseFn) {
  13740. var data = Optional.none();
  13741. var callbacks = [];
  13742. var map2 = function(f) {
  13743. return nu$3(function(nCallback) {
  13744. get2(function(data2) {
  13745. nCallback(f(data2));
  13746. });
  13747. });
  13748. };
  13749. var get2 = function(nCallback) {
  13750. if (isReady()) {
  13751. call(nCallback);
  13752. } else {
  13753. callbacks.push(nCallback);
  13754. }
  13755. };
  13756. var set2 = function(x) {
  13757. if (!isReady()) {
  13758. data = Optional.some(x);
  13759. run2(callbacks);
  13760. callbacks = [];
  13761. }
  13762. };
  13763. var isReady = function() {
  13764. return data.isSome();
  13765. };
  13766. var run2 = function(cbs) {
  13767. each$1(cbs, call);
  13768. };
  13769. var call = function(cb) {
  13770. data.each(function(x) {
  13771. setTimeout(function() {
  13772. cb(x);
  13773. }, 0);
  13774. });
  13775. };
  13776. baseFn(set2);
  13777. return {
  13778. get: get2,
  13779. map: map2,
  13780. isReady
  13781. };
  13782. };
  13783. var pure$1 = function(a) {
  13784. return nu$3(function(callback) {
  13785. callback(a);
  13786. });
  13787. };
  13788. var LazyValue = {
  13789. nu: nu$3,
  13790. pure: pure$1
  13791. };
  13792. var errorReporter = function(err) {
  13793. setTimeout(function() {
  13794. throw err;
  13795. }, 0);
  13796. };
  13797. var make$5 = function(run2) {
  13798. var get2 = function(callback) {
  13799. run2().then(callback, errorReporter);
  13800. };
  13801. var map2 = function(fab) {
  13802. return make$5(function() {
  13803. return run2().then(fab);
  13804. });
  13805. };
  13806. var bind2 = function(aFutureB) {
  13807. return make$5(function() {
  13808. return run2().then(function(v) {
  13809. return aFutureB(v).toPromise();
  13810. });
  13811. });
  13812. };
  13813. var anonBind = function(futureB) {
  13814. return make$5(function() {
  13815. return run2().then(function() {
  13816. return futureB.toPromise();
  13817. });
  13818. });
  13819. };
  13820. var toLazy = function() {
  13821. return LazyValue.nu(get2);
  13822. };
  13823. var toCached = function() {
  13824. var cache = null;
  13825. return make$5(function() {
  13826. if (cache === null) {
  13827. cache = run2();
  13828. }
  13829. return cache;
  13830. });
  13831. };
  13832. var toPromise = run2;
  13833. return {
  13834. map: map2,
  13835. bind: bind2,
  13836. anonBind,
  13837. toLazy,
  13838. toCached,
  13839. toPromise,
  13840. get: get2
  13841. };
  13842. };
  13843. var nu$2 = function(baseFn) {
  13844. return make$5(function() {
  13845. return new Promise$1(baseFn);
  13846. });
  13847. };
  13848. var pure = function(a) {
  13849. return make$5(function() {
  13850. return Promise$1.resolve(a);
  13851. });
  13852. };
  13853. var Future = {
  13854. nu: nu$2,
  13855. pure
  13856. };
  13857. var ariaElements = [
  13858. "input",
  13859. "textarea"
  13860. ];
  13861. var isAriaElement = function(elem) {
  13862. var name2 = name$2(elem);
  13863. return contains$2(ariaElements, name2);
  13864. };
  13865. var markValid = function(component, invalidConfig) {
  13866. var elem = invalidConfig.getRoot(component).getOr(component.element);
  13867. remove$2(elem, invalidConfig.invalidClass);
  13868. invalidConfig.notify.each(function(notifyInfo) {
  13869. if (isAriaElement(component.element)) {
  13870. set$8(component.element, "aria-invalid", false);
  13871. }
  13872. notifyInfo.getContainer(component).each(function(container) {
  13873. set$5(container, notifyInfo.validHtml);
  13874. });
  13875. notifyInfo.onValid(component);
  13876. });
  13877. };
  13878. var markInvalid = function(component, invalidConfig, invalidState, text2) {
  13879. var elem = invalidConfig.getRoot(component).getOr(component.element);
  13880. add$2(elem, invalidConfig.invalidClass);
  13881. invalidConfig.notify.each(function(notifyInfo) {
  13882. if (isAriaElement(component.element)) {
  13883. set$8(component.element, "aria-invalid", true);
  13884. }
  13885. notifyInfo.getContainer(component).each(function(container) {
  13886. set$5(container, text2);
  13887. });
  13888. notifyInfo.onInvalid(component, text2);
  13889. });
  13890. };
  13891. var query = function(component, invalidConfig, _invalidState) {
  13892. return invalidConfig.validator.fold(function() {
  13893. return Future.pure(Result.value(true));
  13894. }, function(validatorInfo) {
  13895. return validatorInfo.validate(component);
  13896. });
  13897. };
  13898. var run = function(component, invalidConfig, invalidState) {
  13899. invalidConfig.notify.each(function(notifyInfo) {
  13900. notifyInfo.onValidate(component);
  13901. });
  13902. return query(component, invalidConfig).map(function(valid) {
  13903. if (component.getSystem().isConnected()) {
  13904. return valid.fold(function(err) {
  13905. markInvalid(component, invalidConfig, invalidState, err);
  13906. return Result.error(err);
  13907. }, function(v) {
  13908. markValid(component, invalidConfig);
  13909. return Result.value(v);
  13910. });
  13911. } else {
  13912. return Result.error("No longer in system");
  13913. }
  13914. });
  13915. };
  13916. var isInvalid = function(component, invalidConfig) {
  13917. var elem = invalidConfig.getRoot(component).getOr(component.element);
  13918. return has(elem, invalidConfig.invalidClass);
  13919. };
  13920. var InvalidateApis = Object.freeze({
  13921. __proto__: null,
  13922. markValid,
  13923. markInvalid,
  13924. query,
  13925. run,
  13926. isInvalid
  13927. });
  13928. var events$8 = function(invalidConfig, invalidState) {
  13929. return invalidConfig.validator.map(function(validatorInfo) {
  13930. return derive$2([run$1(validatorInfo.onEvent, function(component) {
  13931. run(component, invalidConfig, invalidState).get(identity$1);
  13932. })].concat(validatorInfo.validateOnLoad ? [runOnAttached(function(component) {
  13933. run(component, invalidConfig, invalidState).get(noop);
  13934. })] : []));
  13935. }).getOr({});
  13936. };
  13937. var ActiveInvalidate = Object.freeze({
  13938. __proto__: null,
  13939. events: events$8
  13940. });
  13941. var InvalidateSchema = [
  13942. required$1("invalidClass"),
  13943. defaulted("getRoot", Optional.none),
  13944. optionObjOf("notify", [
  13945. defaulted("aria", "alert"),
  13946. defaulted("getContainer", Optional.none),
  13947. defaulted("validHtml", ""),
  13948. onHandler("onValid"),
  13949. onHandler("onInvalid"),
  13950. onHandler("onValidate")
  13951. ]),
  13952. optionObjOf("validator", [
  13953. required$1("validate"),
  13954. defaulted("onEvent", "input"),
  13955. defaulted("validateOnLoad", true)
  13956. ])
  13957. ];
  13958. var Invalidating = create$7({
  13959. fields: InvalidateSchema,
  13960. name: "invalidating",
  13961. active: ActiveInvalidate,
  13962. apis: InvalidateApis,
  13963. extra: {
  13964. validation: function(validator) {
  13965. return function(component) {
  13966. var v = Representing.getValue(component);
  13967. return Future.pure(validator(v));
  13968. };
  13969. }
  13970. }
  13971. });
  13972. var getCoupled = function(component, coupleConfig, coupleState, name2) {
  13973. return coupleState.getOrCreate(component, coupleConfig, name2);
  13974. };
  13975. var CouplingApis = Object.freeze({
  13976. __proto__: null,
  13977. getCoupled
  13978. });
  13979. var CouplingSchema = [requiredOf("others", setOf(Result.value, anyValue()))];
  13980. var init$a = function() {
  13981. var coupled = {};
  13982. var getOrCreate = function(component, coupleConfig, name2) {
  13983. var available = keys(coupleConfig.others);
  13984. if (!available) {
  13985. throw new Error("Cannot find coupled component: " + name2 + ". Known coupled components: " + JSON.stringify(available, null, 2));
  13986. } else {
  13987. return get$e(coupled, name2).getOrThunk(function() {
  13988. var builder2 = get$e(coupleConfig.others, name2).getOrDie("No information found for coupled component: " + name2);
  13989. var spec = builder2(component);
  13990. var built = component.getSystem().build(spec);
  13991. coupled[name2] = built;
  13992. return built;
  13993. });
  13994. }
  13995. };
  13996. var readState = constant$1({});
  13997. return nu$8({
  13998. readState,
  13999. getOrCreate
  14000. });
  14001. };
  14002. var CouplingState = Object.freeze({
  14003. __proto__: null,
  14004. init: init$a
  14005. });
  14006. var Coupling = create$7({
  14007. fields: CouplingSchema,
  14008. name: "coupling",
  14009. apis: CouplingApis,
  14010. state: CouplingState
  14011. });
  14012. var suffix = constant$1("sink");
  14013. var partType$1 = constant$1(optional({
  14014. name: suffix(),
  14015. overrides: constant$1({
  14016. dom: { tag: "div" },
  14017. behaviours: derive$1([Positioning.config({ useFixed: always })]),
  14018. events: derive$2([
  14019. cutter(keydown()),
  14020. cutter(mousedown()),
  14021. cutter(click())
  14022. ])
  14023. })
  14024. }));
  14025. var HighlightOnOpen;
  14026. (function(HighlightOnOpen2) {
  14027. HighlightOnOpen2[HighlightOnOpen2["HighlightFirst"] = 0] = "HighlightFirst";
  14028. HighlightOnOpen2[HighlightOnOpen2["HighlightNone"] = 1] = "HighlightNone";
  14029. })(HighlightOnOpen || (HighlightOnOpen = {}));
  14030. var getAnchor = function(detail, component) {
  14031. var hotspot = detail.getHotspot(component).getOr(component);
  14032. var type2 = "hotspot";
  14033. var overrides = detail.getAnchorOverrides();
  14034. return detail.layouts.fold(function() {
  14035. return {
  14036. type: type2,
  14037. hotspot,
  14038. overrides
  14039. };
  14040. }, function(layouts2) {
  14041. return {
  14042. type: type2,
  14043. hotspot,
  14044. overrides,
  14045. layouts: layouts2
  14046. };
  14047. });
  14048. };
  14049. var fetch = function(detail, mapFetch, component) {
  14050. var fetcher = detail.fetch;
  14051. return fetcher(component).map(mapFetch);
  14052. };
  14053. var openF = function(detail, mapFetch, anchor2, component, sandbox, externals, highlightOnOpen) {
  14054. var futureData = fetch(detail, mapFetch, component);
  14055. var getLazySink = getSink(component, detail);
  14056. return futureData.map(function(tdata) {
  14057. return tdata.bind(function(data) {
  14058. return Optional.from(tieredMenu.sketch(__assign(__assign({}, externals.menu()), {
  14059. uid: generate$5(""),
  14060. data,
  14061. highlightImmediately: highlightOnOpen === HighlightOnOpen.HighlightFirst,
  14062. onOpenMenu: function(tmenu, menu2) {
  14063. var sink = getLazySink().getOrDie();
  14064. Positioning.position(sink, menu2, { anchor: anchor2 });
  14065. Sandboxing.decloak(sandbox);
  14066. },
  14067. onOpenSubmenu: function(tmenu, item2, submenu) {
  14068. var sink = getLazySink().getOrDie();
  14069. Positioning.position(sink, submenu, {
  14070. anchor: {
  14071. type: "submenu",
  14072. item: item2
  14073. }
  14074. });
  14075. Sandboxing.decloak(sandbox);
  14076. },
  14077. onRepositionMenu: function(tmenu, primaryMenu, submenuTriggers) {
  14078. var sink = getLazySink().getOrDie();
  14079. Positioning.position(sink, primaryMenu, { anchor: anchor2 });
  14080. each$1(submenuTriggers, function(st) {
  14081. Positioning.position(sink, st.triggeredMenu, {
  14082. anchor: {
  14083. type: "submenu",
  14084. item: st.triggeringItem
  14085. }
  14086. });
  14087. });
  14088. },
  14089. onEscape: function() {
  14090. Focusing.focus(component);
  14091. Sandboxing.close(sandbox);
  14092. return Optional.some(true);
  14093. }
  14094. })));
  14095. });
  14096. });
  14097. };
  14098. var open = function(detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen) {
  14099. var anchor2 = getAnchor(detail, hotspot);
  14100. var processed = openF(detail, mapFetch, anchor2, hotspot, sandbox, externals, highlightOnOpen);
  14101. return processed.map(function(tdata) {
  14102. tdata.fold(function() {
  14103. if (Sandboxing.isOpen(sandbox)) {
  14104. Sandboxing.close(sandbox);
  14105. }
  14106. }, function(data) {
  14107. Sandboxing.cloak(sandbox);
  14108. Sandboxing.open(sandbox, data);
  14109. onOpenSync(sandbox);
  14110. });
  14111. return sandbox;
  14112. });
  14113. };
  14114. var close = function(detail, mapFetch, component, sandbox, _externals, _onOpenSync, _highlightOnOpen) {
  14115. Sandboxing.close(sandbox);
  14116. return Future.pure(sandbox);
  14117. };
  14118. var togglePopup = function(detail, mapFetch, hotspot, externals, onOpenSync, highlightOnOpen) {
  14119. var sandbox = Coupling.getCoupled(hotspot, "sandbox");
  14120. var showing = Sandboxing.isOpen(sandbox);
  14121. var action = showing ? close : open;
  14122. return action(detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen);
  14123. };
  14124. var matchWidth = function(hotspot, container, useMinWidth) {
  14125. var menu2 = Composing.getCurrent(container).getOr(container);
  14126. var buttonWidth = get$a(hotspot.element);
  14127. if (useMinWidth) {
  14128. set$7(menu2.element, "min-width", buttonWidth + "px");
  14129. } else {
  14130. set$6(menu2.element, buttonWidth);
  14131. }
  14132. };
  14133. var getSink = function(anyInSystem, sinkDetail) {
  14134. return anyInSystem.getSystem().getByUid(sinkDetail.uid + "-" + suffix()).map(function(internalSink) {
  14135. return function() {
  14136. return Result.value(internalSink);
  14137. };
  14138. }).getOrThunk(function() {
  14139. return sinkDetail.lazySink.fold(function() {
  14140. return function() {
  14141. return Result.error(new Error("No internal sink is specified, nor could an external sink be found"));
  14142. };
  14143. }, function(lazySinkFn) {
  14144. return function() {
  14145. return lazySinkFn(anyInSystem);
  14146. };
  14147. });
  14148. });
  14149. };
  14150. var doRepositionMenus = function(sandbox) {
  14151. Sandboxing.getState(sandbox).each(function(tmenu) {
  14152. tieredMenu.repositionMenus(tmenu);
  14153. });
  14154. };
  14155. var makeSandbox$1 = function(detail, hotspot, extras) {
  14156. var ariaOwner = manager();
  14157. var onOpen = function(component, menu2) {
  14158. var anchor2 = getAnchor(detail, hotspot);
  14159. ariaOwner.link(hotspot.element);
  14160. if (detail.matchWidth) {
  14161. matchWidth(anchor2.hotspot, menu2, detail.useMinWidth);
  14162. }
  14163. detail.onOpen(anchor2, component, menu2);
  14164. if (extras !== void 0 && extras.onOpen !== void 0) {
  14165. extras.onOpen(component, menu2);
  14166. }
  14167. };
  14168. var onClose = function(component, menu2) {
  14169. ariaOwner.unlink(hotspot.element);
  14170. if (extras !== void 0 && extras.onClose !== void 0) {
  14171. extras.onClose(component, menu2);
  14172. }
  14173. };
  14174. var lazySink = getSink(hotspot, detail);
  14175. return {
  14176. dom: {
  14177. tag: "div",
  14178. classes: detail.sandboxClasses,
  14179. attributes: {
  14180. id: ariaOwner.id,
  14181. role: "listbox"
  14182. }
  14183. },
  14184. behaviours: SketchBehaviours.augment(detail.sandboxBehaviours, [
  14185. Representing.config({
  14186. store: {
  14187. mode: "memory",
  14188. initialValue: hotspot
  14189. }
  14190. }),
  14191. Sandboxing.config({
  14192. onOpen,
  14193. onClose,
  14194. isPartOf: function(container, data, queryElem) {
  14195. return isPartOf$1(data, queryElem) || isPartOf$1(hotspot, queryElem);
  14196. },
  14197. getAttachPoint: function() {
  14198. return lazySink().getOrDie();
  14199. }
  14200. }),
  14201. Composing.config({
  14202. find: function(sandbox) {
  14203. return Sandboxing.getState(sandbox).bind(function(menu2) {
  14204. return Composing.getCurrent(menu2);
  14205. });
  14206. }
  14207. }),
  14208. Receiving.config({ channels: __assign(__assign({}, receivingChannel$1({ isExtraPart: never })), receivingChannel({ doReposition: doRepositionMenus })) })
  14209. ])
  14210. };
  14211. };
  14212. var repositionMenus = function(comp) {
  14213. var sandbox = Coupling.getCoupled(comp, "sandbox");
  14214. doRepositionMenus(sandbox);
  14215. };
  14216. var sandboxFields = function() {
  14217. return [
  14218. defaulted("sandboxClasses", []),
  14219. SketchBehaviours.field("sandboxBehaviours", [
  14220. Composing,
  14221. Receiving,
  14222. Sandboxing,
  14223. Representing
  14224. ])
  14225. ];
  14226. };
  14227. var schema$j = constant$1([
  14228. required$1("dom"),
  14229. required$1("fetch"),
  14230. onHandler("onOpen"),
  14231. onKeyboardHandler("onExecute"),
  14232. defaulted("getHotspot", Optional.some),
  14233. defaulted("getAnchorOverrides", constant$1({})),
  14234. schema$y(),
  14235. field("dropdownBehaviours", [
  14236. Toggling,
  14237. Coupling,
  14238. Keying,
  14239. Focusing
  14240. ]),
  14241. required$1("toggleClass"),
  14242. defaulted("eventOrder", {}),
  14243. option("lazySink"),
  14244. defaulted("matchWidth", false),
  14245. defaulted("useMinWidth", false),
  14246. option("role")
  14247. ].concat(sandboxFields()));
  14248. var parts$d = constant$1([
  14249. external$1({
  14250. schema: [tieredMenuMarkers()],
  14251. name: "menu",
  14252. defaults: function(detail) {
  14253. return { onExecute: detail.onExecute };
  14254. }
  14255. }),
  14256. partType$1()
  14257. ]);
  14258. var factory$g = function(detail, components2, _spec, externals) {
  14259. var _a2;
  14260. var lookupAttr = function(attr) {
  14261. return get$e(detail.dom, "attributes").bind(function(attrs) {
  14262. return get$e(attrs, attr);
  14263. });
  14264. };
  14265. var switchToMenu = function(sandbox) {
  14266. Sandboxing.getState(sandbox).each(function(tmenu) {
  14267. tieredMenu.highlightPrimary(tmenu);
  14268. });
  14269. };
  14270. var action = function(component) {
  14271. var onOpenSync = switchToMenu;
  14272. togglePopup(detail, identity$1, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  14273. };
  14274. var apis = {
  14275. expand: function(comp) {
  14276. if (!Toggling.isOn(comp)) {
  14277. togglePopup(detail, identity$1, comp, externals, noop, HighlightOnOpen.HighlightNone).get(noop);
  14278. }
  14279. },
  14280. open: function(comp) {
  14281. if (!Toggling.isOn(comp)) {
  14282. togglePopup(detail, identity$1, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
  14283. }
  14284. },
  14285. isOpen: Toggling.isOn,
  14286. close: function(comp) {
  14287. if (Toggling.isOn(comp)) {
  14288. togglePopup(detail, identity$1, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
  14289. }
  14290. },
  14291. repositionMenus: function(comp) {
  14292. if (Toggling.isOn(comp)) {
  14293. repositionMenus(comp);
  14294. }
  14295. }
  14296. };
  14297. var triggerExecute = function(comp, _se) {
  14298. emitExecute(comp);
  14299. return Optional.some(true);
  14300. };
  14301. return {
  14302. uid: detail.uid,
  14303. dom: detail.dom,
  14304. components: components2,
  14305. behaviours: augment(detail.dropdownBehaviours, [
  14306. Toggling.config({
  14307. toggleClass: detail.toggleClass,
  14308. aria: { mode: "expanded" }
  14309. }),
  14310. Coupling.config({
  14311. others: {
  14312. sandbox: function(hotspot) {
  14313. return makeSandbox$1(detail, hotspot, {
  14314. onOpen: function() {
  14315. return Toggling.on(hotspot);
  14316. },
  14317. onClose: function() {
  14318. return Toggling.off(hotspot);
  14319. }
  14320. });
  14321. }
  14322. }
  14323. }),
  14324. Keying.config({
  14325. mode: "special",
  14326. onSpace: triggerExecute,
  14327. onEnter: triggerExecute,
  14328. onDown: function(comp, _se) {
  14329. if (Dropdown.isOpen(comp)) {
  14330. var sandbox = Coupling.getCoupled(comp, "sandbox");
  14331. switchToMenu(sandbox);
  14332. } else {
  14333. Dropdown.open(comp);
  14334. }
  14335. return Optional.some(true);
  14336. },
  14337. onEscape: function(comp, _se) {
  14338. if (Dropdown.isOpen(comp)) {
  14339. Dropdown.close(comp);
  14340. return Optional.some(true);
  14341. } else {
  14342. return Optional.none();
  14343. }
  14344. }
  14345. }),
  14346. Focusing.config({})
  14347. ]),
  14348. events: events$a(Optional.some(action)),
  14349. eventOrder: __assign(__assign({}, detail.eventOrder), (_a2 = {}, _a2[execute$5()] = [
  14350. "disabling",
  14351. "toggling",
  14352. "alloy.base.behaviour"
  14353. ], _a2)),
  14354. apis,
  14355. domModification: {
  14356. attributes: __assign(__assign({ "aria-haspopup": "true" }, detail.role.fold(function() {
  14357. return {};
  14358. }, function(role) {
  14359. return { role };
  14360. })), detail.dom.tag === "button" ? { type: lookupAttr("type").getOr("button") } : {})
  14361. }
  14362. };
  14363. };
  14364. var Dropdown = composite({
  14365. name: "Dropdown",
  14366. configFields: schema$j(),
  14367. partFields: parts$d(),
  14368. factory: factory$g,
  14369. apis: {
  14370. open: function(apis, comp) {
  14371. return apis.open(comp);
  14372. },
  14373. expand: function(apis, comp) {
  14374. return apis.expand(comp);
  14375. },
  14376. close: function(apis, comp) {
  14377. return apis.close(comp);
  14378. },
  14379. isOpen: function(apis, comp) {
  14380. return apis.isOpen(comp);
  14381. },
  14382. repositionMenus: function(apis, comp) {
  14383. return apis.repositionMenus(comp);
  14384. }
  14385. }
  14386. });
  14387. var exhibit$1 = function() {
  14388. return nu$7({
  14389. styles: {
  14390. "-webkit-user-select": "none",
  14391. "user-select": "none",
  14392. "-ms-user-select": "none",
  14393. "-moz-user-select": "-moz-none"
  14394. },
  14395. attributes: { unselectable: "on" }
  14396. });
  14397. };
  14398. var events$7 = function() {
  14399. return derive$2([abort(selectstart(), always)]);
  14400. };
  14401. var ActiveUnselecting = Object.freeze({
  14402. __proto__: null,
  14403. events: events$7,
  14404. exhibit: exhibit$1
  14405. });
  14406. var Unselecting = create$7({
  14407. fields: [],
  14408. name: "unselecting",
  14409. active: ActiveUnselecting
  14410. });
  14411. var renderPanelButton = function(spec, sharedBackstage) {
  14412. return Dropdown.sketch({
  14413. dom: spec.dom,
  14414. components: spec.components,
  14415. toggleClass: "mce-active",
  14416. dropdownBehaviours: derive$1([
  14417. DisablingConfigs.button(sharedBackstage.providers.isDisabled),
  14418. receivingConfig(),
  14419. Unselecting.config({}),
  14420. Tabstopping.config({})
  14421. ]),
  14422. layouts: spec.layouts,
  14423. sandboxClasses: ["tox-dialog__popups"],
  14424. lazySink: sharedBackstage.getSink,
  14425. fetch: function(comp) {
  14426. return Future.nu(function(callback) {
  14427. return spec.fetch(callback);
  14428. }).map(function(items) {
  14429. return Optional.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$6("menu-value"), items, function(value2) {
  14430. spec.onItemAction(comp, value2);
  14431. }, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, never, sharedBackstage.providers), { movement: deriveMenuMovement(spec.columns, spec.presets) })));
  14432. });
  14433. },
  14434. parts: { menu: part(false, 1, spec.presets) }
  14435. });
  14436. };
  14437. var colorInputChangeEvent = generate$6("color-input-change");
  14438. var colorSwatchChangeEvent = generate$6("color-swatch-change");
  14439. var colorPickerCancelEvent = generate$6("color-picker-cancel");
  14440. var renderColorInput = function(spec, sharedBackstage, colorInputBackstage) {
  14441. var pField = FormField.parts.field({
  14442. factory: Input,
  14443. inputClasses: ["tox-textfield"],
  14444. onSetValue: function(c) {
  14445. return Invalidating.run(c).get(noop);
  14446. },
  14447. inputBehaviours: derive$1([
  14448. Disabling.config({ disabled: sharedBackstage.providers.isDisabled }),
  14449. receivingConfig(),
  14450. Tabstopping.config({}),
  14451. Invalidating.config({
  14452. invalidClass: "tox-textbox-field-invalid",
  14453. getRoot: function(comp) {
  14454. return parent(comp.element);
  14455. },
  14456. notify: {
  14457. onValid: function(comp) {
  14458. var val = Representing.getValue(comp);
  14459. emitWith(comp, colorInputChangeEvent, { color: val });
  14460. }
  14461. },
  14462. validator: {
  14463. validateOnLoad: false,
  14464. validate: function(input2) {
  14465. var inputValue = Representing.getValue(input2);
  14466. if (inputValue.length === 0) {
  14467. return Future.pure(Result.value(true));
  14468. } else {
  14469. var span = SugarElement.fromTag("span");
  14470. set$7(span, "background-color", inputValue);
  14471. var res = getRaw(span, "background-color").fold(function() {
  14472. return Result.error("blah");
  14473. }, function(_) {
  14474. return Result.value(inputValue);
  14475. });
  14476. return Future.pure(res);
  14477. }
  14478. }
  14479. }
  14480. })
  14481. ]),
  14482. selectOnFocus: false
  14483. });
  14484. var pLabel = spec.label.map(function(label) {
  14485. return renderLabel$2(label, sharedBackstage.providers);
  14486. });
  14487. var emitSwatchChange = function(colorBit, value2) {
  14488. emitWith(colorBit, colorSwatchChangeEvent, { value: value2 });
  14489. };
  14490. var onItemAction = function(comp, value2) {
  14491. memColorButton.getOpt(comp).each(function(colorBit) {
  14492. if (value2 === "custom") {
  14493. colorInputBackstage.colorPicker(function(valueOpt) {
  14494. valueOpt.fold(function() {
  14495. return emit(colorBit, colorPickerCancelEvent);
  14496. }, function(value3) {
  14497. emitSwatchChange(colorBit, value3);
  14498. addColor(value3);
  14499. });
  14500. }, "#ffffff");
  14501. } else if (value2 === "remove") {
  14502. emitSwatchChange(colorBit, "");
  14503. } else {
  14504. emitSwatchChange(colorBit, value2);
  14505. }
  14506. });
  14507. };
  14508. var memColorButton = record(renderPanelButton({
  14509. dom: {
  14510. tag: "span",
  14511. attributes: { "aria-label": sharedBackstage.providers.translate("Color swatch") }
  14512. },
  14513. layouts: {
  14514. onRtl: function() {
  14515. return [
  14516. southwest$2,
  14517. southeast$2,
  14518. south$2
  14519. ];
  14520. },
  14521. onLtr: function() {
  14522. return [
  14523. southeast$2,
  14524. southwest$2,
  14525. south$2
  14526. ];
  14527. }
  14528. },
  14529. components: [],
  14530. fetch: getFetch$1(colorInputBackstage.getColors(), colorInputBackstage.hasCustomColors()),
  14531. columns: colorInputBackstage.getColorCols(),
  14532. presets: "color",
  14533. onItemAction
  14534. }, sharedBackstage));
  14535. return FormField.sketch({
  14536. dom: {
  14537. tag: "div",
  14538. classes: ["tox-form__group"]
  14539. },
  14540. components: pLabel.toArray().concat([{
  14541. dom: {
  14542. tag: "div",
  14543. classes: ["tox-color-input"]
  14544. },
  14545. components: [
  14546. pField,
  14547. memColorButton.asSpec()
  14548. ]
  14549. }]),
  14550. fieldBehaviours: derive$1([config("form-field-events", [
  14551. run$1(colorInputChangeEvent, function(comp, se) {
  14552. memColorButton.getOpt(comp).each(function(colorButton) {
  14553. set$7(colorButton.element, "background-color", se.event.color);
  14554. });
  14555. emitWith(comp, formChangeEvent, { name: spec.name });
  14556. }),
  14557. run$1(colorSwatchChangeEvent, function(comp, se) {
  14558. FormField.getField(comp).each(function(field2) {
  14559. Representing.setValue(field2, se.event.value);
  14560. Composing.getCurrent(comp).each(Focusing.focus);
  14561. });
  14562. }),
  14563. run$1(colorPickerCancelEvent, function(comp, _se) {
  14564. FormField.getField(comp).each(function(_field) {
  14565. Composing.getCurrent(comp).each(Focusing.focus);
  14566. });
  14567. })
  14568. ])])
  14569. });
  14570. };
  14571. var labelPart = optional({
  14572. schema: [required$1("dom")],
  14573. name: "label"
  14574. });
  14575. var edgePart = function(name2) {
  14576. return optional({
  14577. name: "" + name2 + "-edge",
  14578. overrides: function(detail) {
  14579. var action = detail.model.manager.edgeActions[name2];
  14580. return action.fold(function() {
  14581. return {};
  14582. }, function(a) {
  14583. return {
  14584. events: derive$2([
  14585. runActionExtra(touchstart(), function(comp, se, d) {
  14586. return a(comp, d);
  14587. }, [detail]),
  14588. runActionExtra(mousedown(), function(comp, se, d) {
  14589. return a(comp, d);
  14590. }, [detail]),
  14591. runActionExtra(mousemove(), function(comp, se, det) {
  14592. if (det.mouseIsDown.get()) {
  14593. a(comp, det);
  14594. }
  14595. }, [detail])
  14596. ])
  14597. };
  14598. });
  14599. }
  14600. });
  14601. };
  14602. var tlEdgePart = edgePart("top-left");
  14603. var tedgePart = edgePart("top");
  14604. var trEdgePart = edgePart("top-right");
  14605. var redgePart = edgePart("right");
  14606. var brEdgePart = edgePart("bottom-right");
  14607. var bedgePart = edgePart("bottom");
  14608. var blEdgePart = edgePart("bottom-left");
  14609. var ledgePart = edgePart("left");
  14610. var thumbPart = required({
  14611. name: "thumb",
  14612. defaults: constant$1({ dom: { styles: { position: "absolute" } } }),
  14613. overrides: function(detail) {
  14614. return {
  14615. events: derive$2([
  14616. redirectToPart(touchstart(), detail, "spectrum"),
  14617. redirectToPart(touchmove(), detail, "spectrum"),
  14618. redirectToPart(touchend(), detail, "spectrum"),
  14619. redirectToPart(mousedown(), detail, "spectrum"),
  14620. redirectToPart(mousemove(), detail, "spectrum"),
  14621. redirectToPart(mouseup(), detail, "spectrum")
  14622. ])
  14623. };
  14624. }
  14625. });
  14626. var spectrumPart = required({
  14627. schema: [customField("mouseIsDown", function() {
  14628. return Cell(false);
  14629. })],
  14630. name: "spectrum",
  14631. overrides: function(detail) {
  14632. var modelDetail = detail.model;
  14633. var model = modelDetail.manager;
  14634. var setValueFrom2 = function(component, simulatedEvent) {
  14635. return model.getValueFromEvent(simulatedEvent).map(function(value2) {
  14636. return model.setValueFrom(component, detail, value2);
  14637. });
  14638. };
  14639. return {
  14640. behaviours: derive$1([
  14641. Keying.config({
  14642. mode: "special",
  14643. onLeft: function(spectrum) {
  14644. return model.onLeft(spectrum, detail);
  14645. },
  14646. onRight: function(spectrum) {
  14647. return model.onRight(spectrum, detail);
  14648. },
  14649. onUp: function(spectrum) {
  14650. return model.onUp(spectrum, detail);
  14651. },
  14652. onDown: function(spectrum) {
  14653. return model.onDown(spectrum, detail);
  14654. }
  14655. }),
  14656. Focusing.config({})
  14657. ]),
  14658. events: derive$2([
  14659. run$1(touchstart(), setValueFrom2),
  14660. run$1(touchmove(), setValueFrom2),
  14661. run$1(mousedown(), setValueFrom2),
  14662. run$1(mousemove(), function(spectrum, se) {
  14663. if (detail.mouseIsDown.get()) {
  14664. setValueFrom2(spectrum, se);
  14665. }
  14666. })
  14667. ])
  14668. };
  14669. }
  14670. });
  14671. var SliderParts = [
  14672. labelPart,
  14673. ledgePart,
  14674. redgePart,
  14675. tedgePart,
  14676. bedgePart,
  14677. tlEdgePart,
  14678. trEdgePart,
  14679. blEdgePart,
  14680. brEdgePart,
  14681. thumbPart,
  14682. spectrumPart
  14683. ];
  14684. var _sliderChangeEvent = "slider.change.value";
  14685. var sliderChangeEvent = constant$1(_sliderChangeEvent);
  14686. var isTouchEvent$2 = function(evt) {
  14687. return evt.type.indexOf("touch") !== -1;
  14688. };
  14689. var getEventSource = function(simulatedEvent) {
  14690. var evt = simulatedEvent.event.raw;
  14691. if (isTouchEvent$2(evt)) {
  14692. var touchEvent = evt;
  14693. return touchEvent.touches !== void 0 && touchEvent.touches.length === 1 ? Optional.some(touchEvent.touches[0]).map(function(t2) {
  14694. return SugarPosition(t2.clientX, t2.clientY);
  14695. }) : Optional.none();
  14696. } else {
  14697. var mouseEvent = evt;
  14698. return mouseEvent.clientX !== void 0 ? Optional.some(mouseEvent).map(function(me) {
  14699. return SugarPosition(me.clientX, me.clientY);
  14700. }) : Optional.none();
  14701. }
  14702. };
  14703. var t = "top", r = "right", b = "bottom", l = "left";
  14704. var minX = function(detail) {
  14705. return detail.model.minX;
  14706. };
  14707. var minY = function(detail) {
  14708. return detail.model.minY;
  14709. };
  14710. var min1X = function(detail) {
  14711. return detail.model.minX - 1;
  14712. };
  14713. var min1Y = function(detail) {
  14714. return detail.model.minY - 1;
  14715. };
  14716. var maxX = function(detail) {
  14717. return detail.model.maxX;
  14718. };
  14719. var maxY = function(detail) {
  14720. return detail.model.maxY;
  14721. };
  14722. var max1X = function(detail) {
  14723. return detail.model.maxX + 1;
  14724. };
  14725. var max1Y = function(detail) {
  14726. return detail.model.maxY + 1;
  14727. };
  14728. var range = function(detail, max2, min2) {
  14729. return max2(detail) - min2(detail);
  14730. };
  14731. var xRange = function(detail) {
  14732. return range(detail, maxX, minX);
  14733. };
  14734. var yRange = function(detail) {
  14735. return range(detail, maxY, minY);
  14736. };
  14737. var halfX = function(detail) {
  14738. return xRange(detail) / 2;
  14739. };
  14740. var halfY = function(detail) {
  14741. return yRange(detail) / 2;
  14742. };
  14743. var step = function(detail) {
  14744. return detail.stepSize;
  14745. };
  14746. var snap = function(detail) {
  14747. return detail.snapToGrid;
  14748. };
  14749. var snapStart = function(detail) {
  14750. return detail.snapStart;
  14751. };
  14752. var rounded = function(detail) {
  14753. return detail.rounded;
  14754. };
  14755. var hasEdge = function(detail, edgeName) {
  14756. return detail[edgeName + "-edge"] !== void 0;
  14757. };
  14758. var hasLEdge = function(detail) {
  14759. return hasEdge(detail, l);
  14760. };
  14761. var hasREdge = function(detail) {
  14762. return hasEdge(detail, r);
  14763. };
  14764. var hasTEdge = function(detail) {
  14765. return hasEdge(detail, t);
  14766. };
  14767. var hasBEdge = function(detail) {
  14768. return hasEdge(detail, b);
  14769. };
  14770. var currentValue = function(detail) {
  14771. return detail.model.value.get();
  14772. };
  14773. var xValue = function(x) {
  14774. return { x };
  14775. };
  14776. var yValue = function(y) {
  14777. return { y };
  14778. };
  14779. var xyValue = function(x, y) {
  14780. return {
  14781. x,
  14782. y
  14783. };
  14784. };
  14785. var fireSliderChange$3 = function(component, value2) {
  14786. emitWith(component, sliderChangeEvent(), { value: value2 });
  14787. };
  14788. var setToTLEdgeXY = function(edge2, detail) {
  14789. fireSliderChange$3(edge2, xyValue(min1X(detail), min1Y(detail)));
  14790. };
  14791. var setToTEdge = function(edge2, detail) {
  14792. fireSliderChange$3(edge2, yValue(min1Y(detail)));
  14793. };
  14794. var setToTEdgeXY = function(edge2, detail) {
  14795. fireSliderChange$3(edge2, xyValue(halfX(detail), min1Y(detail)));
  14796. };
  14797. var setToTREdgeXY = function(edge2, detail) {
  14798. fireSliderChange$3(edge2, xyValue(max1X(detail), min1Y(detail)));
  14799. };
  14800. var setToREdge = function(edge2, detail) {
  14801. fireSliderChange$3(edge2, xValue(max1X(detail)));
  14802. };
  14803. var setToREdgeXY = function(edge2, detail) {
  14804. fireSliderChange$3(edge2, xyValue(max1X(detail), halfY(detail)));
  14805. };
  14806. var setToBREdgeXY = function(edge2, detail) {
  14807. fireSliderChange$3(edge2, xyValue(max1X(detail), max1Y(detail)));
  14808. };
  14809. var setToBEdge = function(edge2, detail) {
  14810. fireSliderChange$3(edge2, yValue(max1Y(detail)));
  14811. };
  14812. var setToBEdgeXY = function(edge2, detail) {
  14813. fireSliderChange$3(edge2, xyValue(halfX(detail), max1Y(detail)));
  14814. };
  14815. var setToBLEdgeXY = function(edge2, detail) {
  14816. fireSliderChange$3(edge2, xyValue(min1X(detail), max1Y(detail)));
  14817. };
  14818. var setToLEdge = function(edge2, detail) {
  14819. fireSliderChange$3(edge2, xValue(min1X(detail)));
  14820. };
  14821. var setToLEdgeXY = function(edge2, detail) {
  14822. fireSliderChange$3(edge2, xyValue(min1X(detail), halfY(detail)));
  14823. };
  14824. var reduceBy = function(value2, min2, max2, step2) {
  14825. if (value2 < min2) {
  14826. return value2;
  14827. } else if (value2 > max2) {
  14828. return max2;
  14829. } else if (value2 === min2) {
  14830. return min2 - 1;
  14831. } else {
  14832. return Math.max(min2, value2 - step2);
  14833. }
  14834. };
  14835. var increaseBy = function(value2, min2, max2, step2) {
  14836. if (value2 > max2) {
  14837. return value2;
  14838. } else if (value2 < min2) {
  14839. return min2;
  14840. } else if (value2 === max2) {
  14841. return max2 + 1;
  14842. } else {
  14843. return Math.min(max2, value2 + step2);
  14844. }
  14845. };
  14846. var capValue = function(value2, min2, max2) {
  14847. return Math.max(min2, Math.min(max2, value2));
  14848. };
  14849. var snapValueOf = function(value2, min2, max2, step2, snapStart2) {
  14850. return snapStart2.fold(function() {
  14851. var initValue = value2 - min2;
  14852. var extraValue = Math.round(initValue / step2) * step2;
  14853. return capValue(min2 + extraValue, min2 - 1, max2 + 1);
  14854. }, function(start) {
  14855. var remainder = (value2 - start) % step2;
  14856. var adjustment = Math.round(remainder / step2);
  14857. var rawSteps = Math.floor((value2 - start) / step2);
  14858. var maxSteps = Math.floor((max2 - start) / step2);
  14859. var numSteps = Math.min(maxSteps, rawSteps + adjustment);
  14860. var r2 = start + numSteps * step2;
  14861. return Math.max(start, r2);
  14862. });
  14863. };
  14864. var findOffsetOf = function(value2, min2, max2) {
  14865. return Math.min(max2, Math.max(value2, min2)) - min2;
  14866. };
  14867. var findValueOf = function(args) {
  14868. var min2 = args.min, max2 = args.max, range2 = args.range, value2 = args.value, step2 = args.step, snap2 = args.snap, snapStart2 = args.snapStart, rounded2 = args.rounded, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, minBound = args.minBound, maxBound = args.maxBound, screenRange = args.screenRange;
  14869. var capMin = hasMinEdge ? min2 - 1 : min2;
  14870. var capMax = hasMaxEdge ? max2 + 1 : max2;
  14871. if (value2 < minBound) {
  14872. return capMin;
  14873. } else if (value2 > maxBound) {
  14874. return capMax;
  14875. } else {
  14876. var offset2 = findOffsetOf(value2, minBound, maxBound);
  14877. var newValue = capValue(offset2 / screenRange * range2 + min2, capMin, capMax);
  14878. if (snap2 && newValue >= min2 && newValue <= max2) {
  14879. return snapValueOf(newValue, min2, max2, step2, snapStart2);
  14880. } else if (rounded2) {
  14881. return Math.round(newValue);
  14882. } else {
  14883. return newValue;
  14884. }
  14885. }
  14886. };
  14887. var findOffsetOfValue$2 = function(args) {
  14888. var min2 = args.min, max2 = args.max, range2 = args.range, value2 = args.value, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, maxBound = args.maxBound, maxOffset = args.maxOffset, centerMinEdge = args.centerMinEdge, centerMaxEdge = args.centerMaxEdge;
  14889. if (value2 < min2) {
  14890. return hasMinEdge ? 0 : centerMinEdge;
  14891. } else if (value2 > max2) {
  14892. return hasMaxEdge ? maxBound : centerMaxEdge;
  14893. } else {
  14894. return (value2 - min2) / range2 * maxOffset;
  14895. }
  14896. };
  14897. var top = "top", right = "right", bottom = "bottom", left = "left", width = "width", height = "height";
  14898. var getBounds = function(component) {
  14899. return component.element.dom.getBoundingClientRect();
  14900. };
  14901. var getBoundsProperty = function(bounds2, property) {
  14902. return bounds2[property];
  14903. };
  14904. var getMinXBounds = function(component) {
  14905. var bounds2 = getBounds(component);
  14906. return getBoundsProperty(bounds2, left);
  14907. };
  14908. var getMaxXBounds = function(component) {
  14909. var bounds2 = getBounds(component);
  14910. return getBoundsProperty(bounds2, right);
  14911. };
  14912. var getMinYBounds = function(component) {
  14913. var bounds2 = getBounds(component);
  14914. return getBoundsProperty(bounds2, top);
  14915. };
  14916. var getMaxYBounds = function(component) {
  14917. var bounds2 = getBounds(component);
  14918. return getBoundsProperty(bounds2, bottom);
  14919. };
  14920. var getXScreenRange = function(component) {
  14921. var bounds2 = getBounds(component);
  14922. return getBoundsProperty(bounds2, width);
  14923. };
  14924. var getYScreenRange = function(component) {
  14925. var bounds2 = getBounds(component);
  14926. return getBoundsProperty(bounds2, height);
  14927. };
  14928. var getCenterOffsetOf = function(componentMinEdge, componentMaxEdge, spectrumMinEdge) {
  14929. return (componentMinEdge + componentMaxEdge) / 2 - spectrumMinEdge;
  14930. };
  14931. var getXCenterOffSetOf = function(component, spectrum) {
  14932. var componentBounds = getBounds(component);
  14933. var spectrumBounds = getBounds(spectrum);
  14934. var componentMinEdge = getBoundsProperty(componentBounds, left);
  14935. var componentMaxEdge = getBoundsProperty(componentBounds, right);
  14936. var spectrumMinEdge = getBoundsProperty(spectrumBounds, left);
  14937. return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
  14938. };
  14939. var getYCenterOffSetOf = function(component, spectrum) {
  14940. var componentBounds = getBounds(component);
  14941. var spectrumBounds = getBounds(spectrum);
  14942. var componentMinEdge = getBoundsProperty(componentBounds, top);
  14943. var componentMaxEdge = getBoundsProperty(componentBounds, bottom);
  14944. var spectrumMinEdge = getBoundsProperty(spectrumBounds, top);
  14945. return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
  14946. };
  14947. var fireSliderChange$2 = function(spectrum, value2) {
  14948. emitWith(spectrum, sliderChangeEvent(), { value: value2 });
  14949. };
  14950. var sliderValue$2 = function(x) {
  14951. return { x };
  14952. };
  14953. var findValueOfOffset$1 = function(spectrum, detail, left2) {
  14954. var args = {
  14955. min: minX(detail),
  14956. max: maxX(detail),
  14957. range: xRange(detail),
  14958. value: left2,
  14959. step: step(detail),
  14960. snap: snap(detail),
  14961. snapStart: snapStart(detail),
  14962. rounded: rounded(detail),
  14963. hasMinEdge: hasLEdge(detail),
  14964. hasMaxEdge: hasREdge(detail),
  14965. minBound: getMinXBounds(spectrum),
  14966. maxBound: getMaxXBounds(spectrum),
  14967. screenRange: getXScreenRange(spectrum)
  14968. };
  14969. return findValueOf(args);
  14970. };
  14971. var setValueFrom$2 = function(spectrum, detail, value2) {
  14972. var xValue2 = findValueOfOffset$1(spectrum, detail, value2);
  14973. var sliderVal = sliderValue$2(xValue2);
  14974. fireSliderChange$2(spectrum, sliderVal);
  14975. return xValue2;
  14976. };
  14977. var setToMin$2 = function(spectrum, detail) {
  14978. var min2 = minX(detail);
  14979. fireSliderChange$2(spectrum, sliderValue$2(min2));
  14980. };
  14981. var setToMax$2 = function(spectrum, detail) {
  14982. var max2 = maxX(detail);
  14983. fireSliderChange$2(spectrum, sliderValue$2(max2));
  14984. };
  14985. var moveBy$2 = function(direction, spectrum, detail) {
  14986. var f = direction > 0 ? increaseBy : reduceBy;
  14987. var xValue2 = f(currentValue(detail).x, minX(detail), maxX(detail), step(detail));
  14988. fireSliderChange$2(spectrum, sliderValue$2(xValue2));
  14989. return Optional.some(xValue2);
  14990. };
  14991. var handleMovement$2 = function(direction) {
  14992. return function(spectrum, detail) {
  14993. return moveBy$2(direction, spectrum, detail).map(always);
  14994. };
  14995. };
  14996. var getValueFromEvent$2 = function(simulatedEvent) {
  14997. var pos = getEventSource(simulatedEvent);
  14998. return pos.map(function(p) {
  14999. return p.left;
  15000. });
  15001. };
  15002. var findOffsetOfValue$1 = function(spectrum, detail, value2, minEdge, maxEdge) {
  15003. var minOffset = 0;
  15004. var maxOffset = getXScreenRange(spectrum);
  15005. var centerMinEdge = minEdge.bind(function(edge2) {
  15006. return Optional.some(getXCenterOffSetOf(edge2, spectrum));
  15007. }).getOr(minOffset);
  15008. var centerMaxEdge = maxEdge.bind(function(edge2) {
  15009. return Optional.some(getXCenterOffSetOf(edge2, spectrum));
  15010. }).getOr(maxOffset);
  15011. var args = {
  15012. min: minX(detail),
  15013. max: maxX(detail),
  15014. range: xRange(detail),
  15015. value: value2,
  15016. hasMinEdge: hasLEdge(detail),
  15017. hasMaxEdge: hasREdge(detail),
  15018. minBound: getMinXBounds(spectrum),
  15019. minOffset,
  15020. maxBound: getMaxXBounds(spectrum),
  15021. maxOffset,
  15022. centerMinEdge,
  15023. centerMaxEdge
  15024. };
  15025. return findOffsetOfValue$2(args);
  15026. };
  15027. var findPositionOfValue$1 = function(slider, spectrum, value2, minEdge, maxEdge, detail) {
  15028. var offset2 = findOffsetOfValue$1(spectrum, detail, value2, minEdge, maxEdge);
  15029. return getMinXBounds(spectrum) - getMinXBounds(slider) + offset2;
  15030. };
  15031. var setPositionFromValue$2 = function(slider, thumb, detail, edges) {
  15032. var value2 = currentValue(detail);
  15033. var pos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value2.x, edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
  15034. var thumbRadius = get$a(thumb.element) / 2;
  15035. set$7(thumb.element, "left", pos - thumbRadius + "px");
  15036. };
  15037. var onLeft$2 = handleMovement$2(-1);
  15038. var onRight$2 = handleMovement$2(1);
  15039. var onUp$2 = Optional.none;
  15040. var onDown$2 = Optional.none;
  15041. var edgeActions$2 = {
  15042. "top-left": Optional.none(),
  15043. "top": Optional.none(),
  15044. "top-right": Optional.none(),
  15045. "right": Optional.some(setToREdge),
  15046. "bottom-right": Optional.none(),
  15047. "bottom": Optional.none(),
  15048. "bottom-left": Optional.none(),
  15049. "left": Optional.some(setToLEdge)
  15050. };
  15051. var HorizontalModel = Object.freeze({
  15052. __proto__: null,
  15053. setValueFrom: setValueFrom$2,
  15054. setToMin: setToMin$2,
  15055. setToMax: setToMax$2,
  15056. findValueOfOffset: findValueOfOffset$1,
  15057. getValueFromEvent: getValueFromEvent$2,
  15058. findPositionOfValue: findPositionOfValue$1,
  15059. setPositionFromValue: setPositionFromValue$2,
  15060. onLeft: onLeft$2,
  15061. onRight: onRight$2,
  15062. onUp: onUp$2,
  15063. onDown: onDown$2,
  15064. edgeActions: edgeActions$2
  15065. });
  15066. var fireSliderChange$1 = function(spectrum, value2) {
  15067. emitWith(spectrum, sliderChangeEvent(), { value: value2 });
  15068. };
  15069. var sliderValue$1 = function(y) {
  15070. return { y };
  15071. };
  15072. var findValueOfOffset = function(spectrum, detail, top2) {
  15073. var args = {
  15074. min: minY(detail),
  15075. max: maxY(detail),
  15076. range: yRange(detail),
  15077. value: top2,
  15078. step: step(detail),
  15079. snap: snap(detail),
  15080. snapStart: snapStart(detail),
  15081. rounded: rounded(detail),
  15082. hasMinEdge: hasTEdge(detail),
  15083. hasMaxEdge: hasBEdge(detail),
  15084. minBound: getMinYBounds(spectrum),
  15085. maxBound: getMaxYBounds(spectrum),
  15086. screenRange: getYScreenRange(spectrum)
  15087. };
  15088. return findValueOf(args);
  15089. };
  15090. var setValueFrom$1 = function(spectrum, detail, value2) {
  15091. var yValue2 = findValueOfOffset(spectrum, detail, value2);
  15092. var sliderVal = sliderValue$1(yValue2);
  15093. fireSliderChange$1(spectrum, sliderVal);
  15094. return yValue2;
  15095. };
  15096. var setToMin$1 = function(spectrum, detail) {
  15097. var min2 = minY(detail);
  15098. fireSliderChange$1(spectrum, sliderValue$1(min2));
  15099. };
  15100. var setToMax$1 = function(spectrum, detail) {
  15101. var max2 = maxY(detail);
  15102. fireSliderChange$1(spectrum, sliderValue$1(max2));
  15103. };
  15104. var moveBy$1 = function(direction, spectrum, detail) {
  15105. var f = direction > 0 ? increaseBy : reduceBy;
  15106. var yValue2 = f(currentValue(detail).y, minY(detail), maxY(detail), step(detail));
  15107. fireSliderChange$1(spectrum, sliderValue$1(yValue2));
  15108. return Optional.some(yValue2);
  15109. };
  15110. var handleMovement$1 = function(direction) {
  15111. return function(spectrum, detail) {
  15112. return moveBy$1(direction, spectrum, detail).map(always);
  15113. };
  15114. };
  15115. var getValueFromEvent$1 = function(simulatedEvent) {
  15116. var pos = getEventSource(simulatedEvent);
  15117. return pos.map(function(p) {
  15118. return p.top;
  15119. });
  15120. };
  15121. var findOffsetOfValue = function(spectrum, detail, value2, minEdge, maxEdge) {
  15122. var minOffset = 0;
  15123. var maxOffset = getYScreenRange(spectrum);
  15124. var centerMinEdge = minEdge.bind(function(edge2) {
  15125. return Optional.some(getYCenterOffSetOf(edge2, spectrum));
  15126. }).getOr(minOffset);
  15127. var centerMaxEdge = maxEdge.bind(function(edge2) {
  15128. return Optional.some(getYCenterOffSetOf(edge2, spectrum));
  15129. }).getOr(maxOffset);
  15130. var args = {
  15131. min: minY(detail),
  15132. max: maxY(detail),
  15133. range: yRange(detail),
  15134. value: value2,
  15135. hasMinEdge: hasTEdge(detail),
  15136. hasMaxEdge: hasBEdge(detail),
  15137. minBound: getMinYBounds(spectrum),
  15138. minOffset,
  15139. maxBound: getMaxYBounds(spectrum),
  15140. maxOffset,
  15141. centerMinEdge,
  15142. centerMaxEdge
  15143. };
  15144. return findOffsetOfValue$2(args);
  15145. };
  15146. var findPositionOfValue = function(slider, spectrum, value2, minEdge, maxEdge, detail) {
  15147. var offset2 = findOffsetOfValue(spectrum, detail, value2, minEdge, maxEdge);
  15148. return getMinYBounds(spectrum) - getMinYBounds(slider) + offset2;
  15149. };
  15150. var setPositionFromValue$1 = function(slider, thumb, detail, edges) {
  15151. var value2 = currentValue(detail);
  15152. var pos = findPositionOfValue(slider, edges.getSpectrum(slider), value2.y, edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
  15153. var thumbRadius = get$b(thumb.element) / 2;
  15154. set$7(thumb.element, "top", pos - thumbRadius + "px");
  15155. };
  15156. var onLeft$1 = Optional.none;
  15157. var onRight$1 = Optional.none;
  15158. var onUp$1 = handleMovement$1(-1);
  15159. var onDown$1 = handleMovement$1(1);
  15160. var edgeActions$1 = {
  15161. "top-left": Optional.none(),
  15162. "top": Optional.some(setToTEdge),
  15163. "top-right": Optional.none(),
  15164. "right": Optional.none(),
  15165. "bottom-right": Optional.none(),
  15166. "bottom": Optional.some(setToBEdge),
  15167. "bottom-left": Optional.none(),
  15168. "left": Optional.none()
  15169. };
  15170. var VerticalModel = Object.freeze({
  15171. __proto__: null,
  15172. setValueFrom: setValueFrom$1,
  15173. setToMin: setToMin$1,
  15174. setToMax: setToMax$1,
  15175. findValueOfOffset,
  15176. getValueFromEvent: getValueFromEvent$1,
  15177. findPositionOfValue,
  15178. setPositionFromValue: setPositionFromValue$1,
  15179. onLeft: onLeft$1,
  15180. onRight: onRight$1,
  15181. onUp: onUp$1,
  15182. onDown: onDown$1,
  15183. edgeActions: edgeActions$1
  15184. });
  15185. var fireSliderChange = function(spectrum, value2) {
  15186. emitWith(spectrum, sliderChangeEvent(), { value: value2 });
  15187. };
  15188. var sliderValue = function(x, y) {
  15189. return {
  15190. x,
  15191. y
  15192. };
  15193. };
  15194. var setValueFrom = function(spectrum, detail, value2) {
  15195. var xValue2 = findValueOfOffset$1(spectrum, detail, value2.left);
  15196. var yValue2 = findValueOfOffset(spectrum, detail, value2.top);
  15197. var val = sliderValue(xValue2, yValue2);
  15198. fireSliderChange(spectrum, val);
  15199. return val;
  15200. };
  15201. var moveBy = function(direction, isVerticalMovement, spectrum, detail) {
  15202. var f = direction > 0 ? increaseBy : reduceBy;
  15203. var xValue2 = isVerticalMovement ? currentValue(detail).x : f(currentValue(detail).x, minX(detail), maxX(detail), step(detail));
  15204. var yValue2 = !isVerticalMovement ? currentValue(detail).y : f(currentValue(detail).y, minY(detail), maxY(detail), step(detail));
  15205. fireSliderChange(spectrum, sliderValue(xValue2, yValue2));
  15206. return Optional.some(xValue2);
  15207. };
  15208. var handleMovement = function(direction, isVerticalMovement) {
  15209. return function(spectrum, detail) {
  15210. return moveBy(direction, isVerticalMovement, spectrum, detail).map(always);
  15211. };
  15212. };
  15213. var setToMin = function(spectrum, detail) {
  15214. var mX = minX(detail);
  15215. var mY = minY(detail);
  15216. fireSliderChange(spectrum, sliderValue(mX, mY));
  15217. };
  15218. var setToMax = function(spectrum, detail) {
  15219. var mX = maxX(detail);
  15220. var mY = maxY(detail);
  15221. fireSliderChange(spectrum, sliderValue(mX, mY));
  15222. };
  15223. var getValueFromEvent = function(simulatedEvent) {
  15224. return getEventSource(simulatedEvent);
  15225. };
  15226. var setPositionFromValue = function(slider, thumb, detail, edges) {
  15227. var value2 = currentValue(detail);
  15228. var xPos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value2.x, edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
  15229. var yPos = findPositionOfValue(slider, edges.getSpectrum(slider), value2.y, edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
  15230. var thumbXRadius = get$a(thumb.element) / 2;
  15231. var thumbYRadius = get$b(thumb.element) / 2;
  15232. set$7(thumb.element, "left", xPos - thumbXRadius + "px");
  15233. set$7(thumb.element, "top", yPos - thumbYRadius + "px");
  15234. };
  15235. var onLeft = handleMovement(-1, false);
  15236. var onRight = handleMovement(1, false);
  15237. var onUp = handleMovement(-1, true);
  15238. var onDown = handleMovement(1, true);
  15239. var edgeActions = {
  15240. "top-left": Optional.some(setToTLEdgeXY),
  15241. "top": Optional.some(setToTEdgeXY),
  15242. "top-right": Optional.some(setToTREdgeXY),
  15243. "right": Optional.some(setToREdgeXY),
  15244. "bottom-right": Optional.some(setToBREdgeXY),
  15245. "bottom": Optional.some(setToBEdgeXY),
  15246. "bottom-left": Optional.some(setToBLEdgeXY),
  15247. "left": Optional.some(setToLEdgeXY)
  15248. };
  15249. var TwoDModel = Object.freeze({
  15250. __proto__: null,
  15251. setValueFrom,
  15252. setToMin,
  15253. setToMax,
  15254. getValueFromEvent,
  15255. setPositionFromValue,
  15256. onLeft,
  15257. onRight,
  15258. onUp,
  15259. onDown,
  15260. edgeActions
  15261. });
  15262. var SliderSchema = [
  15263. defaulted("stepSize", 1),
  15264. defaulted("onChange", noop),
  15265. defaulted("onChoose", noop),
  15266. defaulted("onInit", noop),
  15267. defaulted("onDragStart", noop),
  15268. defaulted("onDragEnd", noop),
  15269. defaulted("snapToGrid", false),
  15270. defaulted("rounded", true),
  15271. option("snapStart"),
  15272. requiredOf("model", choose$1("mode", {
  15273. x: [
  15274. defaulted("minX", 0),
  15275. defaulted("maxX", 100),
  15276. customField("value", function(spec) {
  15277. return Cell(spec.mode.minX);
  15278. }),
  15279. required$1("getInitialValue"),
  15280. output$1("manager", HorizontalModel)
  15281. ],
  15282. y: [
  15283. defaulted("minY", 0),
  15284. defaulted("maxY", 100),
  15285. customField("value", function(spec) {
  15286. return Cell(spec.mode.minY);
  15287. }),
  15288. required$1("getInitialValue"),
  15289. output$1("manager", VerticalModel)
  15290. ],
  15291. xy: [
  15292. defaulted("minX", 0),
  15293. defaulted("maxX", 100),
  15294. defaulted("minY", 0),
  15295. defaulted("maxY", 100),
  15296. customField("value", function(spec) {
  15297. return Cell({
  15298. x: spec.mode.minX,
  15299. y: spec.mode.minY
  15300. });
  15301. }),
  15302. required$1("getInitialValue"),
  15303. output$1("manager", TwoDModel)
  15304. ]
  15305. })),
  15306. field("sliderBehaviours", [
  15307. Keying,
  15308. Representing
  15309. ]),
  15310. customField("mouseIsDown", function() {
  15311. return Cell(false);
  15312. })
  15313. ];
  15314. var sketch$2 = function(detail, components2, _spec, _externals) {
  15315. var _a2;
  15316. var getThumb = function(component) {
  15317. return getPartOrDie(component, detail, "thumb");
  15318. };
  15319. var getSpectrum = function(component) {
  15320. return getPartOrDie(component, detail, "spectrum");
  15321. };
  15322. var getLeftEdge = function(component) {
  15323. return getPart(component, detail, "left-edge");
  15324. };
  15325. var getRightEdge = function(component) {
  15326. return getPart(component, detail, "right-edge");
  15327. };
  15328. var getTopEdge = function(component) {
  15329. return getPart(component, detail, "top-edge");
  15330. };
  15331. var getBottomEdge = function(component) {
  15332. return getPart(component, detail, "bottom-edge");
  15333. };
  15334. var modelDetail = detail.model;
  15335. var model = modelDetail.manager;
  15336. var refresh2 = function(slider, thumb) {
  15337. model.setPositionFromValue(slider, thumb, detail, {
  15338. getLeftEdge,
  15339. getRightEdge,
  15340. getTopEdge,
  15341. getBottomEdge,
  15342. getSpectrum
  15343. });
  15344. };
  15345. var setValue2 = function(slider, newValue) {
  15346. modelDetail.value.set(newValue);
  15347. var thumb = getThumb(slider);
  15348. refresh2(slider, thumb);
  15349. };
  15350. var changeValue = function(slider, newValue) {
  15351. setValue2(slider, newValue);
  15352. var thumb = getThumb(slider);
  15353. detail.onChange(slider, thumb, newValue);
  15354. return Optional.some(true);
  15355. };
  15356. var resetToMin = function(slider) {
  15357. model.setToMin(slider, detail);
  15358. };
  15359. var resetToMax = function(slider) {
  15360. model.setToMax(slider, detail);
  15361. };
  15362. var choose2 = function(slider) {
  15363. var fireOnChoose = function() {
  15364. getPart(slider, detail, "thumb").each(function(thumb) {
  15365. var value2 = modelDetail.value.get();
  15366. detail.onChoose(slider, thumb, value2);
  15367. });
  15368. };
  15369. var wasDown = detail.mouseIsDown.get();
  15370. detail.mouseIsDown.set(false);
  15371. if (wasDown) {
  15372. fireOnChoose();
  15373. }
  15374. };
  15375. var onDragStart = function(slider, simulatedEvent) {
  15376. simulatedEvent.stop();
  15377. detail.mouseIsDown.set(true);
  15378. detail.onDragStart(slider, getThumb(slider));
  15379. };
  15380. var onDragEnd = function(slider, simulatedEvent) {
  15381. simulatedEvent.stop();
  15382. detail.onDragEnd(slider, getThumb(slider));
  15383. choose2(slider);
  15384. };
  15385. return {
  15386. uid: detail.uid,
  15387. dom: detail.dom,
  15388. components: components2,
  15389. behaviours: augment(detail.sliderBehaviours, [
  15390. Keying.config({
  15391. mode: "special",
  15392. focusIn: function(slider) {
  15393. return getPart(slider, detail, "spectrum").map(Keying.focusIn).map(always);
  15394. }
  15395. }),
  15396. Representing.config({
  15397. store: {
  15398. mode: "manual",
  15399. getValue: function(_) {
  15400. return modelDetail.value.get();
  15401. }
  15402. }
  15403. }),
  15404. Receiving.config({ channels: (_a2 = {}, _a2[mouseReleased()] = { onReceive: choose2 }, _a2) })
  15405. ]),
  15406. events: derive$2([
  15407. run$1(sliderChangeEvent(), function(slider, simulatedEvent) {
  15408. changeValue(slider, simulatedEvent.event.value);
  15409. }),
  15410. runOnAttached(function(slider, _simulatedEvent) {
  15411. var getInitial = modelDetail.getInitialValue();
  15412. modelDetail.value.set(getInitial);
  15413. var thumb = getThumb(slider);
  15414. refresh2(slider, thumb);
  15415. var spectrum = getSpectrum(slider);
  15416. detail.onInit(slider, thumb, spectrum, modelDetail.value.get());
  15417. }),
  15418. run$1(touchstart(), onDragStart),
  15419. run$1(touchend(), onDragEnd),
  15420. run$1(mousedown(), onDragStart),
  15421. run$1(mouseup(), onDragEnd)
  15422. ]),
  15423. apis: {
  15424. resetToMin,
  15425. resetToMax,
  15426. setValue: setValue2,
  15427. refresh: refresh2
  15428. },
  15429. domModification: { styles: { position: "relative" } }
  15430. };
  15431. };
  15432. var Slider = composite({
  15433. name: "Slider",
  15434. configFields: SliderSchema,
  15435. partFields: SliderParts,
  15436. factory: sketch$2,
  15437. apis: {
  15438. setValue: function(apis, slider, value2) {
  15439. apis.setValue(slider, value2);
  15440. },
  15441. resetToMin: function(apis, slider) {
  15442. apis.resetToMin(slider);
  15443. },
  15444. resetToMax: function(apis, slider) {
  15445. apis.resetToMax(slider);
  15446. },
  15447. refresh: function(apis, slider) {
  15448. apis.refresh(slider);
  15449. }
  15450. }
  15451. });
  15452. var fieldsUpdate = generate$6("rgb-hex-update");
  15453. var sliderUpdate = generate$6("slider-update");
  15454. var paletteUpdate = generate$6("palette-update");
  15455. var sliderFactory = function(translate2, getClass) {
  15456. var spectrum = Slider.parts.spectrum({
  15457. dom: {
  15458. tag: "div",
  15459. classes: [getClass("hue-slider-spectrum")],
  15460. attributes: { role: "presentation" }
  15461. }
  15462. });
  15463. var thumb = Slider.parts.thumb({
  15464. dom: {
  15465. tag: "div",
  15466. classes: [getClass("hue-slider-thumb")],
  15467. attributes: { role: "presentation" }
  15468. }
  15469. });
  15470. return Slider.sketch({
  15471. dom: {
  15472. tag: "div",
  15473. classes: [getClass("hue-slider")],
  15474. attributes: { role: "presentation" }
  15475. },
  15476. rounded: false,
  15477. model: {
  15478. mode: "y",
  15479. getInitialValue: constant$1({ y: 0 })
  15480. },
  15481. components: [
  15482. spectrum,
  15483. thumb
  15484. ],
  15485. sliderBehaviours: derive$1([Focusing.config({})]),
  15486. onChange: function(slider, _thumb, value2) {
  15487. emitWith(slider, sliderUpdate, { value: value2 });
  15488. }
  15489. });
  15490. };
  15491. var owner$1 = "form";
  15492. var schema$i = [field("formBehaviours", [Representing])];
  15493. var getPartName$1 = function(name2) {
  15494. return "<alloy.field." + name2 + ">";
  15495. };
  15496. var sketch$1 = function(fSpec) {
  15497. var parts2 = function() {
  15498. var record2 = [];
  15499. var field2 = function(name2, config2) {
  15500. record2.push(name2);
  15501. return generateOne$1(owner$1, getPartName$1(name2), config2);
  15502. };
  15503. return {
  15504. field: field2,
  15505. record: constant$1(record2)
  15506. };
  15507. }();
  15508. var spec = fSpec(parts2);
  15509. var partNames = parts2.record();
  15510. var fieldParts = map$2(partNames, function(n) {
  15511. return required({
  15512. name: n,
  15513. pname: getPartName$1(n)
  15514. });
  15515. });
  15516. return composite$1(owner$1, schema$i, fieldParts, make$4, spec);
  15517. };
  15518. var toResult = function(o, e) {
  15519. return o.fold(function() {
  15520. return Result.error(e);
  15521. }, Result.value);
  15522. };
  15523. var make$4 = function(detail, components2) {
  15524. return {
  15525. uid: detail.uid,
  15526. dom: detail.dom,
  15527. components: components2,
  15528. behaviours: augment(detail.formBehaviours, [Representing.config({
  15529. store: {
  15530. mode: "manual",
  15531. getValue: function(form) {
  15532. var resPs = getAllParts(form, detail);
  15533. return map$1(resPs, function(resPThunk, pName) {
  15534. return resPThunk().bind(function(v) {
  15535. var opt = Composing.getCurrent(v);
  15536. return toResult(opt, new Error("Cannot find a current component to extract the value from for form part '" + pName + "': " + element(v.element)));
  15537. }).map(Representing.getValue);
  15538. });
  15539. },
  15540. setValue: function(form, values2) {
  15541. each(values2, function(newValue, key) {
  15542. getPart(form, detail, key).each(function(wrapper) {
  15543. Composing.getCurrent(wrapper).each(function(field2) {
  15544. Representing.setValue(field2, newValue);
  15545. });
  15546. });
  15547. });
  15548. }
  15549. }
  15550. })]),
  15551. apis: {
  15552. getField: function(form, key) {
  15553. return getPart(form, detail, key).bind(Composing.getCurrent);
  15554. }
  15555. }
  15556. };
  15557. };
  15558. var Form = {
  15559. getField: makeApi(function(apis, component, key) {
  15560. return apis.getField(component, key);
  15561. }),
  15562. sketch: sketch$1
  15563. };
  15564. var validInput = generate$6("valid-input");
  15565. var invalidInput = generate$6("invalid-input");
  15566. var validatingInput = generate$6("validating-input");
  15567. var translatePrefix = "colorcustom.rgb.";
  15568. var rgbFormFactory = function(translate2, getClass, onValidHexx, onInvalidHexx) {
  15569. var invalidation = function(label, isValid) {
  15570. return Invalidating.config({
  15571. invalidClass: getClass("invalid"),
  15572. notify: {
  15573. onValidate: function(comp) {
  15574. emitWith(comp, validatingInput, { type: label });
  15575. },
  15576. onValid: function(comp) {
  15577. emitWith(comp, validInput, {
  15578. type: label,
  15579. value: Representing.getValue(comp)
  15580. });
  15581. },
  15582. onInvalid: function(comp) {
  15583. emitWith(comp, invalidInput, {
  15584. type: label,
  15585. value: Representing.getValue(comp)
  15586. });
  15587. }
  15588. },
  15589. validator: {
  15590. validate: function(comp) {
  15591. var value2 = Representing.getValue(comp);
  15592. var res = isValid(value2) ? Result.value(true) : Result.error(translate2("aria.input.invalid"));
  15593. return Future.pure(res);
  15594. },
  15595. validateOnLoad: false
  15596. }
  15597. });
  15598. };
  15599. var renderTextField2 = function(isValid, name2, label, description, data) {
  15600. var helptext = translate2(translatePrefix + "range");
  15601. var pLabel = FormField.parts.label({
  15602. dom: {
  15603. tag: "label",
  15604. innerHtml: label,
  15605. attributes: { "aria-label": description }
  15606. }
  15607. });
  15608. var pField = FormField.parts.field({
  15609. data,
  15610. factory: Input,
  15611. inputAttributes: __assign({ type: "text" }, name2 === "hex" ? { "aria-live": "polite" } : {}),
  15612. inputClasses: [getClass("textfield")],
  15613. inputBehaviours: derive$1([
  15614. invalidation(name2, isValid),
  15615. Tabstopping.config({})
  15616. ]),
  15617. onSetValue: function(input2) {
  15618. if (Invalidating.isInvalid(input2)) {
  15619. var run2 = Invalidating.run(input2);
  15620. run2.get(noop);
  15621. }
  15622. }
  15623. });
  15624. var comps = [
  15625. pLabel,
  15626. pField
  15627. ];
  15628. var concats = name2 !== "hex" ? [FormField.parts["aria-descriptor"]({ text: helptext })] : [];
  15629. var components2 = comps.concat(concats);
  15630. return {
  15631. dom: {
  15632. tag: "div",
  15633. attributes: { role: "presentation" }
  15634. },
  15635. components: components2
  15636. };
  15637. };
  15638. var copyRgbToHex = function(form, rgba) {
  15639. var hex = fromRgba(rgba);
  15640. Form.getField(form, "hex").each(function(hexField) {
  15641. if (!Focusing.isFocused(hexField)) {
  15642. Representing.setValue(form, { hex: hex.value });
  15643. }
  15644. });
  15645. return hex;
  15646. };
  15647. var copyRgbToForm = function(form, rgb) {
  15648. var red2 = rgb.red;
  15649. var green = rgb.green;
  15650. var blue = rgb.blue;
  15651. Representing.setValue(form, {
  15652. red: red2,
  15653. green,
  15654. blue
  15655. });
  15656. };
  15657. var memPreview = record({
  15658. dom: {
  15659. tag: "div",
  15660. classes: [getClass("rgba-preview")],
  15661. styles: { "background-color": "white" },
  15662. attributes: { role: "presentation" }
  15663. }
  15664. });
  15665. var updatePreview = function(anyInSystem, hex) {
  15666. memPreview.getOpt(anyInSystem).each(function(preview) {
  15667. set$7(preview.element, "background-color", "#" + hex.value);
  15668. });
  15669. };
  15670. var factory2 = function() {
  15671. var state = {
  15672. red: Cell(Optional.some(255)),
  15673. green: Cell(Optional.some(255)),
  15674. blue: Cell(Optional.some(255)),
  15675. hex: Cell(Optional.some("ffffff"))
  15676. };
  15677. var copyHexToRgb = function(form, hex) {
  15678. var rgb = fromHex(hex);
  15679. copyRgbToForm(form, rgb);
  15680. setValueRgb(rgb);
  15681. };
  15682. var get2 = function(prop) {
  15683. return state[prop].get();
  15684. };
  15685. var set2 = function(prop, value2) {
  15686. state[prop].set(value2);
  15687. };
  15688. var getValueRgb = function() {
  15689. return get2("red").bind(function(red2) {
  15690. return get2("green").bind(function(green) {
  15691. return get2("blue").map(function(blue) {
  15692. return rgbaColour(red2, green, blue, 1);
  15693. });
  15694. });
  15695. });
  15696. };
  15697. var setValueRgb = function(rgb) {
  15698. var red2 = rgb.red;
  15699. var green = rgb.green;
  15700. var blue = rgb.blue;
  15701. set2("red", Optional.some(red2));
  15702. set2("green", Optional.some(green));
  15703. set2("blue", Optional.some(blue));
  15704. };
  15705. var onInvalidInput = function(form, simulatedEvent) {
  15706. var data = simulatedEvent.event;
  15707. if (data.type !== "hex") {
  15708. set2(data.type, Optional.none());
  15709. } else {
  15710. onInvalidHexx(form);
  15711. }
  15712. };
  15713. var onValidHex = function(form, value2) {
  15714. onValidHexx(form);
  15715. var hex = hexColour(value2);
  15716. set2("hex", Optional.some(value2));
  15717. var rgb = fromHex(hex);
  15718. copyRgbToForm(form, rgb);
  15719. setValueRgb(rgb);
  15720. emitWith(form, fieldsUpdate, { hex });
  15721. updatePreview(form, hex);
  15722. };
  15723. var onValidRgb = function(form, prop, value2) {
  15724. var val = parseInt(value2, 10);
  15725. set2(prop, Optional.some(val));
  15726. getValueRgb().each(function(rgb) {
  15727. var hex = copyRgbToHex(form, rgb);
  15728. emitWith(form, fieldsUpdate, { hex });
  15729. updatePreview(form, hex);
  15730. });
  15731. };
  15732. var isHexInputEvent = function(data) {
  15733. return data.type === "hex";
  15734. };
  15735. var onValidInput = function(form, simulatedEvent) {
  15736. var data = simulatedEvent.event;
  15737. if (isHexInputEvent(data)) {
  15738. onValidHex(form, data.value);
  15739. } else {
  15740. onValidRgb(form, data.type, data.value);
  15741. }
  15742. };
  15743. var formPartStrings = function(key) {
  15744. return {
  15745. label: translate2(translatePrefix + key + ".label"),
  15746. description: translate2(translatePrefix + key + ".description")
  15747. };
  15748. };
  15749. var redStrings = formPartStrings("red");
  15750. var greenStrings = formPartStrings("green");
  15751. var blueStrings = formPartStrings("blue");
  15752. var hexStrings = formPartStrings("hex");
  15753. return deepMerge(Form.sketch(function(parts2) {
  15754. return {
  15755. dom: {
  15756. tag: "form",
  15757. classes: [getClass("rgb-form")],
  15758. attributes: { "aria-label": translate2("aria.color.picker") }
  15759. },
  15760. components: [
  15761. parts2.field("red", FormField.sketch(renderTextField2(isRgbaComponent, "red", redStrings.label, redStrings.description, 255))),
  15762. parts2.field("green", FormField.sketch(renderTextField2(isRgbaComponent, "green", greenStrings.label, greenStrings.description, 255))),
  15763. parts2.field("blue", FormField.sketch(renderTextField2(isRgbaComponent, "blue", blueStrings.label, blueStrings.description, 255))),
  15764. parts2.field("hex", FormField.sketch(renderTextField2(isHexString, "hex", hexStrings.label, hexStrings.description, "ffffff"))),
  15765. memPreview.asSpec()
  15766. ],
  15767. formBehaviours: derive$1([
  15768. Invalidating.config({ invalidClass: getClass("form-invalid") }),
  15769. config("rgb-form-events", [
  15770. run$1(validInput, onValidInput),
  15771. run$1(invalidInput, onInvalidInput),
  15772. run$1(validatingInput, onInvalidInput)
  15773. ])
  15774. ])
  15775. };
  15776. }), {
  15777. apis: {
  15778. updateHex: function(form, hex) {
  15779. Representing.setValue(form, { hex: hex.value });
  15780. copyHexToRgb(form, hex);
  15781. updatePreview(form, hex);
  15782. }
  15783. }
  15784. });
  15785. };
  15786. var rgbFormSketcher = single({
  15787. factory: factory2,
  15788. name: "RgbForm",
  15789. configFields: [],
  15790. apis: {
  15791. updateHex: function(apis, form, hex) {
  15792. apis.updateHex(form, hex);
  15793. }
  15794. },
  15795. extraApis: {}
  15796. });
  15797. return rgbFormSketcher;
  15798. };
  15799. var paletteFactory = function(_translate, getClass) {
  15800. var spectrumPart2 = Slider.parts.spectrum({
  15801. dom: {
  15802. tag: "canvas",
  15803. attributes: { role: "presentation" },
  15804. classes: [getClass("sv-palette-spectrum")]
  15805. }
  15806. });
  15807. var thumbPart2 = Slider.parts.thumb({
  15808. dom: {
  15809. tag: "div",
  15810. attributes: { role: "presentation" },
  15811. classes: [getClass("sv-palette-thumb")],
  15812. innerHtml: "<div class=" + getClass("sv-palette-inner-thumb") + ' role="presentation"></div>'
  15813. }
  15814. });
  15815. var setColour = function(canvas, rgba) {
  15816. var width2 = canvas.width, height2 = canvas.height;
  15817. var ctx = canvas.getContext("2d");
  15818. if (ctx === null) {
  15819. return;
  15820. }
  15821. ctx.fillStyle = rgba;
  15822. ctx.fillRect(0, 0, width2, height2);
  15823. var grdWhite = ctx.createLinearGradient(0, 0, width2, 0);
  15824. grdWhite.addColorStop(0, "rgba(255,255,255,1)");
  15825. grdWhite.addColorStop(1, "rgba(255,255,255,0)");
  15826. ctx.fillStyle = grdWhite;
  15827. ctx.fillRect(0, 0, width2, height2);
  15828. var grdBlack = ctx.createLinearGradient(0, 0, 0, height2);
  15829. grdBlack.addColorStop(0, "rgba(0,0,0,0)");
  15830. grdBlack.addColorStop(1, "rgba(0,0,0,1)");
  15831. ctx.fillStyle = grdBlack;
  15832. ctx.fillRect(0, 0, width2, height2);
  15833. };
  15834. var setPaletteHue = function(slider, hue) {
  15835. var canvas = slider.components()[0].element.dom;
  15836. var hsv = hsvColour(hue, 100, 100);
  15837. var rgba = fromHsv(hsv);
  15838. setColour(canvas, toString(rgba));
  15839. };
  15840. var setPaletteThumb = function(slider, hex) {
  15841. var hsv = fromRgb(fromHex(hex));
  15842. Slider.setValue(slider, {
  15843. x: hsv.saturation,
  15844. y: 100 - hsv.value
  15845. });
  15846. };
  15847. var factory2 = function(_detail) {
  15848. var getInitialValue = constant$1({
  15849. x: 0,
  15850. y: 0
  15851. });
  15852. var onChange = function(slider, _thumb, value2) {
  15853. emitWith(slider, paletteUpdate, { value: value2 });
  15854. };
  15855. var onInit = function(_slider, _thumb, spectrum, _value) {
  15856. setColour(spectrum.element.dom, toString(red));
  15857. };
  15858. var sliderBehaviours = derive$1([
  15859. Composing.config({ find: Optional.some }),
  15860. Focusing.config({})
  15861. ]);
  15862. return Slider.sketch({
  15863. dom: {
  15864. tag: "div",
  15865. attributes: { role: "presentation" },
  15866. classes: [getClass("sv-palette")]
  15867. },
  15868. model: {
  15869. mode: "xy",
  15870. getInitialValue
  15871. },
  15872. rounded: false,
  15873. components: [
  15874. spectrumPart2,
  15875. thumbPart2
  15876. ],
  15877. onChange,
  15878. onInit,
  15879. sliderBehaviours
  15880. });
  15881. };
  15882. var saturationBrightnessPaletteSketcher = single({
  15883. factory: factory2,
  15884. name: "SaturationBrightnessPalette",
  15885. configFields: [],
  15886. apis: {
  15887. setHue: function(_apis, slider, hue) {
  15888. setPaletteHue(slider, hue);
  15889. },
  15890. setThumb: function(_apis, slider, hex) {
  15891. setPaletteThumb(slider, hex);
  15892. }
  15893. },
  15894. extraApis: {}
  15895. });
  15896. return saturationBrightnessPaletteSketcher;
  15897. };
  15898. var makeFactory = function(translate2, getClass) {
  15899. var factory2 = function(detail) {
  15900. var rgbForm = rgbFormFactory(translate2, getClass, detail.onValidHex, detail.onInvalidHex);
  15901. var sbPalette = paletteFactory(translate2, getClass);
  15902. var hueSliderToDegrees = function(hue) {
  15903. return (100 - hue) / 100 * 360;
  15904. };
  15905. var hueDegreesToSlider = function(hue) {
  15906. return 100 - hue / 360 * 100;
  15907. };
  15908. var state = {
  15909. paletteRgba: Cell(red),
  15910. paletteHue: Cell(0)
  15911. };
  15912. var memSlider = record(sliderFactory(translate2, getClass));
  15913. var memPalette = record(sbPalette.sketch({}));
  15914. var memRgb = record(rgbForm.sketch({}));
  15915. var updatePalette = function(anyInSystem, _hex, hue) {
  15916. memPalette.getOpt(anyInSystem).each(function(palette) {
  15917. sbPalette.setHue(palette, hue);
  15918. });
  15919. };
  15920. var updateFields = function(anyInSystem, hex) {
  15921. memRgb.getOpt(anyInSystem).each(function(form) {
  15922. rgbForm.updateHex(form, hex);
  15923. });
  15924. };
  15925. var updateSlider = function(anyInSystem, _hex, hue) {
  15926. memSlider.getOpt(anyInSystem).each(function(slider) {
  15927. Slider.setValue(slider, { y: hueDegreesToSlider(hue) });
  15928. });
  15929. };
  15930. var updatePaletteThumb = function(anyInSystem, hex) {
  15931. memPalette.getOpt(anyInSystem).each(function(palette) {
  15932. sbPalette.setThumb(palette, hex);
  15933. });
  15934. };
  15935. var updateState = function(hex, hue) {
  15936. var rgba = fromHex(hex);
  15937. state.paletteRgba.set(rgba);
  15938. state.paletteHue.set(hue);
  15939. };
  15940. var runUpdates = function(anyInSystem, hex, hue, updates) {
  15941. updateState(hex, hue);
  15942. each$1(updates, function(update) {
  15943. update(anyInSystem, hex, hue);
  15944. });
  15945. };
  15946. var onPaletteUpdate = function() {
  15947. var updates = [updateFields];
  15948. return function(form, simulatedEvent) {
  15949. var value2 = simulatedEvent.event.value;
  15950. var oldHue = state.paletteHue.get();
  15951. var newHsv = hsvColour(oldHue, value2.x, 100 - value2.y);
  15952. var newHex = hsvToHex(newHsv);
  15953. runUpdates(form, newHex, oldHue, updates);
  15954. };
  15955. };
  15956. var onSliderUpdate = function() {
  15957. var updates = [
  15958. updatePalette,
  15959. updateFields
  15960. ];
  15961. return function(form, simulatedEvent) {
  15962. var hue = hueSliderToDegrees(simulatedEvent.event.value.y);
  15963. var oldRgb = state.paletteRgba.get();
  15964. var oldHsv = fromRgb(oldRgb);
  15965. var newHsv = hsvColour(hue, oldHsv.saturation, oldHsv.value);
  15966. var newHex = hsvToHex(newHsv);
  15967. runUpdates(form, newHex, hue, updates);
  15968. };
  15969. };
  15970. var onFieldsUpdate = function() {
  15971. var updates = [
  15972. updatePalette,
  15973. updateSlider,
  15974. updatePaletteThumb
  15975. ];
  15976. return function(form, simulatedEvent) {
  15977. var hex = simulatedEvent.event.hex;
  15978. var hsv = hexToHsv(hex);
  15979. runUpdates(form, hex, hsv.hue, updates);
  15980. };
  15981. };
  15982. return {
  15983. uid: detail.uid,
  15984. dom: detail.dom,
  15985. components: [
  15986. memPalette.asSpec(),
  15987. memSlider.asSpec(),
  15988. memRgb.asSpec()
  15989. ],
  15990. behaviours: derive$1([
  15991. config("colour-picker-events", [
  15992. run$1(fieldsUpdate, onFieldsUpdate()),
  15993. run$1(paletteUpdate, onPaletteUpdate()),
  15994. run$1(sliderUpdate, onSliderUpdate())
  15995. ]),
  15996. Composing.config({
  15997. find: function(comp) {
  15998. return memRgb.getOpt(comp);
  15999. }
  16000. }),
  16001. Keying.config({ mode: "acyclic" })
  16002. ])
  16003. };
  16004. };
  16005. var colourPickerSketcher = single({
  16006. name: "ColourPicker",
  16007. configFields: [
  16008. required$1("dom"),
  16009. defaulted("onValidHex", noop),
  16010. defaulted("onInvalidHex", noop)
  16011. ],
  16012. factory: factory2
  16013. });
  16014. return colourPickerSketcher;
  16015. };
  16016. var self$1 = function() {
  16017. return Composing.config({ find: Optional.some });
  16018. };
  16019. var memento$1 = function(mem) {
  16020. return Composing.config({ find: mem.getOpt });
  16021. };
  16022. var childAt = function(index) {
  16023. return Composing.config({
  16024. find: function(comp) {
  16025. return child$2(comp.element, index).bind(function(element2) {
  16026. return comp.getSystem().getByDom(element2).toOptional();
  16027. });
  16028. }
  16029. });
  16030. };
  16031. var ComposingConfigs = {
  16032. self: self$1,
  16033. memento: memento$1,
  16034. childAt
  16035. };
  16036. var english = {
  16037. "colorcustom.rgb.red.label": "R",
  16038. "colorcustom.rgb.red.description": "Red component",
  16039. "colorcustom.rgb.green.label": "G",
  16040. "colorcustom.rgb.green.description": "Green component",
  16041. "colorcustom.rgb.blue.label": "B",
  16042. "colorcustom.rgb.blue.description": "Blue component",
  16043. "colorcustom.rgb.hex.label": "#",
  16044. "colorcustom.rgb.hex.description": "Hex color code",
  16045. "colorcustom.rgb.range": "Range 0 to 255",
  16046. "colorcustom.sb.saturation": "Saturation",
  16047. "colorcustom.sb.brightness": "Brightness",
  16048. "colorcustom.sb.picker": "Saturation and Brightness Picker",
  16049. "colorcustom.sb.palette": "Saturation and Brightness Palette",
  16050. "colorcustom.sb.instructions": "Use arrow keys to select saturation and brightness, on x and y axes",
  16051. "colorcustom.hue.hue": "Hue",
  16052. "colorcustom.hue.slider": "Hue Slider",
  16053. "colorcustom.hue.palette": "Hue Palette",
  16054. "colorcustom.hue.instructions": "Use arrow keys to select a hue",
  16055. "aria.color.picker": "Color Picker",
  16056. "aria.input.invalid": "Invalid input"
  16057. };
  16058. var getEnglishText = function(key) {
  16059. return english[key];
  16060. };
  16061. var translate$1 = function(key) {
  16062. return getEnglishText(key);
  16063. };
  16064. var renderColorPicker = function(_spec) {
  16065. var getClass = function(key) {
  16066. return "tox-" + key;
  16067. };
  16068. var colourPickerFactory = makeFactory(translate$1, getClass);
  16069. var onValidHex = function(form) {
  16070. emitWith(form, formActionEvent, {
  16071. name: "hex-valid",
  16072. value: true
  16073. });
  16074. };
  16075. var onInvalidHex = function(form) {
  16076. emitWith(form, formActionEvent, {
  16077. name: "hex-valid",
  16078. value: false
  16079. });
  16080. };
  16081. var memPicker = record(colourPickerFactory.sketch({
  16082. dom: {
  16083. tag: "div",
  16084. classes: [getClass("color-picker-container")],
  16085. attributes: { role: "presentation" }
  16086. },
  16087. onValidHex,
  16088. onInvalidHex
  16089. }));
  16090. return {
  16091. dom: { tag: "div" },
  16092. components: [memPicker.asSpec()],
  16093. behaviours: derive$1([
  16094. Representing.config({
  16095. store: {
  16096. mode: "manual",
  16097. getValue: function(comp) {
  16098. var picker = memPicker.get(comp);
  16099. var optRgbForm = Composing.getCurrent(picker);
  16100. var optHex = optRgbForm.bind(function(rgbForm) {
  16101. var formValues = Representing.getValue(rgbForm);
  16102. return formValues.hex;
  16103. });
  16104. return optHex.map(function(hex) {
  16105. return "#" + hex;
  16106. }).getOr("");
  16107. },
  16108. setValue: function(comp, newValue) {
  16109. var pattern2 = /^#([a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?)/;
  16110. var m = pattern2.exec(newValue);
  16111. var picker = memPicker.get(comp);
  16112. var optRgbForm = Composing.getCurrent(picker);
  16113. optRgbForm.fold(function() {
  16114. console.log("Can not find form");
  16115. }, function(rgbForm) {
  16116. Representing.setValue(rgbForm, { hex: Optional.from(m[1]).getOr("") });
  16117. Form.getField(rgbForm, "hex").each(function(hexField) {
  16118. emit(hexField, input());
  16119. });
  16120. });
  16121. }
  16122. }
  16123. }),
  16124. ComposingConfigs.self()
  16125. ])
  16126. };
  16127. };
  16128. var global$6 = tinymce.util.Tools.resolve("tinymce.Resource");
  16129. var isOldCustomEditor = function(spec) {
  16130. return has$2(spec, "init");
  16131. };
  16132. var renderCustomEditor = function(spec) {
  16133. var editorApi = value$1();
  16134. var memReplaced = record({ dom: { tag: spec.tag } });
  16135. var initialValue = value$1();
  16136. return {
  16137. dom: {
  16138. tag: "div",
  16139. classes: ["tox-custom-editor"]
  16140. },
  16141. behaviours: derive$1([
  16142. config("custom-editor-events", [runOnAttached(function(component) {
  16143. memReplaced.getOpt(component).each(function(ta) {
  16144. (isOldCustomEditor(spec) ? spec.init(ta.element.dom) : global$6.load(spec.scriptId, spec.scriptUrl).then(function(init2) {
  16145. return init2(ta.element.dom, spec.settings);
  16146. })).then(function(ea) {
  16147. initialValue.on(function(cvalue) {
  16148. ea.setValue(cvalue);
  16149. });
  16150. initialValue.clear();
  16151. editorApi.set(ea);
  16152. });
  16153. });
  16154. })]),
  16155. Representing.config({
  16156. store: {
  16157. mode: "manual",
  16158. getValue: function() {
  16159. return editorApi.get().fold(function() {
  16160. return initialValue.get().getOr("");
  16161. }, function(ed) {
  16162. return ed.getValue();
  16163. });
  16164. },
  16165. setValue: function(component, value2) {
  16166. editorApi.get().fold(function() {
  16167. initialValue.set(value2);
  16168. }, function(ed) {
  16169. return ed.setValue(value2);
  16170. });
  16171. }
  16172. }
  16173. }),
  16174. ComposingConfigs.self()
  16175. ]),
  16176. components: [memReplaced.asSpec()]
  16177. };
  16178. };
  16179. var global$5 = tinymce.util.Tools.resolve("tinymce.util.Tools");
  16180. var processors = objOf([
  16181. defaulted("preprocess", identity$1),
  16182. defaulted("postprocess", identity$1)
  16183. ]);
  16184. var memento = function(mem, rawProcessors) {
  16185. var ps = asRawOrDie$1("RepresentingConfigs.memento processors", processors, rawProcessors);
  16186. return Representing.config({
  16187. store: {
  16188. mode: "manual",
  16189. getValue: function(comp) {
  16190. var other = mem.get(comp);
  16191. var rawValue = Representing.getValue(other);
  16192. return ps.postprocess(rawValue);
  16193. },
  16194. setValue: function(comp, rawValue) {
  16195. var newValue = ps.preprocess(rawValue);
  16196. var other = mem.get(comp);
  16197. Representing.setValue(other, newValue);
  16198. }
  16199. }
  16200. });
  16201. };
  16202. var withComp = function(optInitialValue, getter, setter) {
  16203. return Representing.config(deepMerge({
  16204. store: {
  16205. mode: "manual",
  16206. getValue: getter,
  16207. setValue: setter
  16208. }
  16209. }, optInitialValue.map(function(initialValue) {
  16210. return { store: { initialValue } };
  16211. }).getOr({})));
  16212. };
  16213. var withElement = function(initialValue, getter, setter) {
  16214. return withComp(initialValue, function(c) {
  16215. return getter(c.element);
  16216. }, function(c, v) {
  16217. return setter(c.element, v);
  16218. });
  16219. };
  16220. var domValue = function(optInitialValue) {
  16221. return withElement(optInitialValue, get$5, set$4);
  16222. };
  16223. var domHtml = function(optInitialValue) {
  16224. return withElement(optInitialValue, get$7, set$5);
  16225. };
  16226. var memory = function(initialValue) {
  16227. return Representing.config({
  16228. store: {
  16229. mode: "memory",
  16230. initialValue
  16231. }
  16232. });
  16233. };
  16234. var RepresentingConfigs = {
  16235. memento,
  16236. withElement,
  16237. withComp,
  16238. domValue,
  16239. domHtml,
  16240. memory
  16241. };
  16242. var defaultImageFileTypes = "jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp";
  16243. var filterByExtension = function(files, providersBackstage) {
  16244. var allowedImageFileTypes = global$5.explode(providersBackstage.getSetting("images_file_types", defaultImageFileTypes, "string"));
  16245. var isFileInAllowedTypes = function(file) {
  16246. return exists(allowedImageFileTypes, function(type2) {
  16247. return endsWith(file.name.toLowerCase(), "." + type2.toLowerCase());
  16248. });
  16249. };
  16250. return filter$2(from(files), isFileInAllowedTypes);
  16251. };
  16252. var renderDropZone = function(spec, providersBackstage) {
  16253. var stopper2 = function(_, se) {
  16254. se.stop();
  16255. };
  16256. var sequence2 = function(actions) {
  16257. return function(comp, se) {
  16258. each$1(actions, function(a) {
  16259. a(comp, se);
  16260. });
  16261. };
  16262. };
  16263. var onDrop = function(comp, se) {
  16264. if (!Disabling.isDisabled(comp)) {
  16265. var transferEvent = se.event.raw;
  16266. handleFiles(comp, transferEvent.dataTransfer.files);
  16267. }
  16268. };
  16269. var onSelect = function(component, simulatedEvent) {
  16270. var input2 = simulatedEvent.event.raw.target;
  16271. handleFiles(component, input2.files);
  16272. };
  16273. var handleFiles = function(component, files) {
  16274. Representing.setValue(component, filterByExtension(files, providersBackstage));
  16275. emitWith(component, formChangeEvent, { name: spec.name });
  16276. };
  16277. var memInput = record({
  16278. dom: {
  16279. tag: "input",
  16280. attributes: {
  16281. type: "file",
  16282. accept: "image/*"
  16283. },
  16284. styles: { display: "none" }
  16285. },
  16286. behaviours: derive$1([config("input-file-events", [
  16287. cutter(click()),
  16288. cutter(tap())
  16289. ])])
  16290. });
  16291. var renderField = function(s) {
  16292. return {
  16293. uid: s.uid,
  16294. dom: {
  16295. tag: "div",
  16296. classes: ["tox-dropzone-container"]
  16297. },
  16298. behaviours: derive$1([
  16299. RepresentingConfigs.memory([]),
  16300. ComposingConfigs.self(),
  16301. Disabling.config({}),
  16302. Toggling.config({
  16303. toggleClass: "dragenter",
  16304. toggleOnExecute: false
  16305. }),
  16306. config("dropzone-events", [
  16307. run$1("dragenter", sequence2([
  16308. stopper2,
  16309. Toggling.toggle
  16310. ])),
  16311. run$1("dragleave", sequence2([
  16312. stopper2,
  16313. Toggling.toggle
  16314. ])),
  16315. run$1("dragover", stopper2),
  16316. run$1("drop", sequence2([
  16317. stopper2,
  16318. onDrop
  16319. ])),
  16320. run$1(change(), onSelect)
  16321. ])
  16322. ]),
  16323. components: [{
  16324. dom: {
  16325. tag: "div",
  16326. classes: ["tox-dropzone"],
  16327. styles: {}
  16328. },
  16329. components: [
  16330. {
  16331. dom: {
  16332. tag: "p",
  16333. innerHtml: providersBackstage.translate("Drop an image here")
  16334. }
  16335. },
  16336. Button.sketch({
  16337. dom: {
  16338. tag: "button",
  16339. innerHtml: providersBackstage.translate("Browse for an image"),
  16340. styles: { position: "relative" },
  16341. classes: [
  16342. "tox-button",
  16343. "tox-button--secondary"
  16344. ]
  16345. },
  16346. components: [memInput.asSpec()],
  16347. action: function(comp) {
  16348. var inputComp = memInput.get(comp);
  16349. inputComp.element.dom.click();
  16350. },
  16351. buttonBehaviours: derive$1([
  16352. Tabstopping.config({}),
  16353. DisablingConfigs.button(providersBackstage.isDisabled),
  16354. receivingConfig()
  16355. ])
  16356. })
  16357. ]
  16358. }]
  16359. };
  16360. };
  16361. var pLabel = spec.label.map(function(label) {
  16362. return renderLabel$2(label, providersBackstage);
  16363. });
  16364. var pField = FormField.parts.field({ factory: { sketch: renderField } });
  16365. return renderFormFieldWith(pLabel, pField, ["tox-form__group--stretched"], []);
  16366. };
  16367. var renderGrid = function(spec, backstage) {
  16368. return {
  16369. dom: {
  16370. tag: "div",
  16371. classes: [
  16372. "tox-form__grid",
  16373. "tox-form__grid--" + spec.columns + "col"
  16374. ]
  16375. },
  16376. components: map$2(spec.items, backstage.interpreter)
  16377. };
  16378. };
  16379. var beforeObject = generate$6("alloy-fake-before-tabstop");
  16380. var afterObject = generate$6("alloy-fake-after-tabstop");
  16381. var craftWithClasses = function(classes2) {
  16382. return {
  16383. dom: {
  16384. tag: "div",
  16385. styles: {
  16386. width: "1px",
  16387. height: "1px",
  16388. outline: "none"
  16389. },
  16390. attributes: { tabindex: "0" },
  16391. classes: classes2
  16392. },
  16393. behaviours: derive$1([
  16394. Focusing.config({ ignore: true }),
  16395. Tabstopping.config({})
  16396. ])
  16397. };
  16398. };
  16399. var craft = function(spec) {
  16400. return {
  16401. dom: {
  16402. tag: "div",
  16403. classes: ["tox-navobj"]
  16404. },
  16405. components: [
  16406. craftWithClasses([beforeObject]),
  16407. spec,
  16408. craftWithClasses([afterObject])
  16409. ],
  16410. behaviours: derive$1([ComposingConfigs.childAt(1)])
  16411. };
  16412. };
  16413. var triggerTab = function(placeholder2, shiftKey) {
  16414. emitWith(placeholder2, keydown(), {
  16415. raw: {
  16416. which: 9,
  16417. shiftKey
  16418. }
  16419. });
  16420. };
  16421. var onFocus = function(container, targetComp) {
  16422. var target = targetComp.element;
  16423. if (has(target, beforeObject)) {
  16424. triggerTab(container, true);
  16425. } else if (has(target, afterObject)) {
  16426. triggerTab(container, false);
  16427. }
  16428. };
  16429. var isPseudoStop = function(element2) {
  16430. return closest(element2, [
  16431. "." + beforeObject,
  16432. "." + afterObject
  16433. ].join(","), never);
  16434. };
  16435. var platformNeedsSandboxing = !(detect$1().browser.isIE() || detect$1().browser.isEdge());
  16436. var getDynamicSource = function(isSandbox) {
  16437. var cachedValue = Cell("");
  16438. return {
  16439. getValue: function(_frameComponent) {
  16440. return cachedValue.get();
  16441. },
  16442. setValue: function(frameComponent, html) {
  16443. if (!isSandbox) {
  16444. set$8(frameComponent.element, "src", "javascript:''");
  16445. var doc = frameComponent.element.dom.contentWindow.document;
  16446. doc.open();
  16447. doc.write(html);
  16448. doc.close();
  16449. } else {
  16450. set$8(frameComponent.element, "srcdoc", html);
  16451. }
  16452. cachedValue.set(html);
  16453. }
  16454. };
  16455. };
  16456. var renderIFrame = function(spec, providersBackstage) {
  16457. var isSandbox = platformNeedsSandboxing && spec.sandboxed;
  16458. var attributes = __assign(__assign({}, spec.label.map(function(title) {
  16459. return { title };
  16460. }).getOr({})), isSandbox ? { sandbox: "allow-scripts allow-same-origin" } : {});
  16461. var sourcing = getDynamicSource(isSandbox);
  16462. var pLabel = spec.label.map(function(label) {
  16463. return renderLabel$2(label, providersBackstage);
  16464. });
  16465. var factory2 = function(newSpec) {
  16466. return craft({
  16467. uid: newSpec.uid,
  16468. dom: {
  16469. tag: "iframe",
  16470. attributes
  16471. },
  16472. behaviours: derive$1([
  16473. Tabstopping.config({}),
  16474. Focusing.config({}),
  16475. RepresentingConfigs.withComp(Optional.none(), sourcing.getValue, sourcing.setValue)
  16476. ])
  16477. });
  16478. };
  16479. var pField = FormField.parts.field({ factory: { sketch: factory2 } });
  16480. return renderFormFieldWith(pLabel, pField, ["tox-form__group--stretched"], []);
  16481. };
  16482. var create$3 = function(width2, height2) {
  16483. return resize$3(document.createElement("canvas"), width2, height2);
  16484. };
  16485. var clone = function(canvas) {
  16486. var tCanvas = create$3(canvas.width, canvas.height);
  16487. var ctx = get2dContext(tCanvas);
  16488. ctx.drawImage(canvas, 0, 0);
  16489. return tCanvas;
  16490. };
  16491. var get2dContext = function(canvas) {
  16492. return canvas.getContext("2d");
  16493. };
  16494. var resize$3 = function(canvas, width2, height2) {
  16495. canvas.width = width2;
  16496. canvas.height = height2;
  16497. return canvas;
  16498. };
  16499. var getWidth$1 = function(image) {
  16500. return image.naturalWidth || image.width;
  16501. };
  16502. var getHeight$1 = function(image) {
  16503. return image.naturalHeight || image.height;
  16504. };
  16505. var blobToImage = function(blob) {
  16506. return new Promise$1(function(resolve, reject) {
  16507. var blobUrl = URL.createObjectURL(blob);
  16508. var image = new Image();
  16509. var removeListeners = function() {
  16510. image.removeEventListener("load", loaded);
  16511. image.removeEventListener("error", error2);
  16512. };
  16513. var loaded = function() {
  16514. removeListeners();
  16515. resolve(image);
  16516. };
  16517. var error2 = function() {
  16518. removeListeners();
  16519. reject("Unable to load data of type " + blob.type + ": " + blobUrl);
  16520. };
  16521. image.addEventListener("load", loaded);
  16522. image.addEventListener("error", error2);
  16523. image.src = blobUrl;
  16524. if (image.complete) {
  16525. setTimeout(loaded, 0);
  16526. }
  16527. });
  16528. };
  16529. var dataUriToBlobSync = function(uri) {
  16530. var data = uri.split(",");
  16531. var matches = /data:([^;]+)/.exec(data[0]);
  16532. if (!matches) {
  16533. return Optional.none();
  16534. }
  16535. var mimetype = matches[1];
  16536. var base64 = data[1];
  16537. var sliceSize = 1024;
  16538. var byteCharacters = atob(base64);
  16539. var bytesLength = byteCharacters.length;
  16540. var slicesCount = Math.ceil(bytesLength / sliceSize);
  16541. var byteArrays = new Array(slicesCount);
  16542. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
  16543. var begin = sliceIndex * sliceSize;
  16544. var end = Math.min(begin + sliceSize, bytesLength);
  16545. var bytes = new Array(end - begin);
  16546. for (var offset2 = begin, i = 0; offset2 < end; ++i, ++offset2) {
  16547. bytes[i] = byteCharacters[offset2].charCodeAt(0);
  16548. }
  16549. byteArrays[sliceIndex] = new Uint8Array(bytes);
  16550. }
  16551. return Optional.some(new Blob(byteArrays, { type: mimetype }));
  16552. };
  16553. var dataUriToBlob = function(uri) {
  16554. return new Promise$1(function(resolve, reject) {
  16555. dataUriToBlobSync(uri).fold(function() {
  16556. reject("uri is not base64: " + uri);
  16557. }, resolve);
  16558. });
  16559. };
  16560. var canvasToBlob = function(canvas, type2, quality) {
  16561. type2 = type2 || "image/png";
  16562. if (isFunction(HTMLCanvasElement.prototype.toBlob)) {
  16563. return new Promise$1(function(resolve, reject) {
  16564. canvas.toBlob(function(blob) {
  16565. if (blob) {
  16566. resolve(blob);
  16567. } else {
  16568. reject();
  16569. }
  16570. }, type2, quality);
  16571. });
  16572. } else {
  16573. return dataUriToBlob(canvas.toDataURL(type2, quality));
  16574. }
  16575. };
  16576. var canvasToDataURL = function(canvas, type2, quality) {
  16577. type2 = type2 || "image/png";
  16578. return canvas.toDataURL(type2, quality);
  16579. };
  16580. var blobToCanvas = function(blob) {
  16581. return blobToImage(blob).then(function(image) {
  16582. revokeImageUrl(image);
  16583. var canvas = create$3(getWidth$1(image), getHeight$1(image));
  16584. var context = get2dContext(canvas);
  16585. context.drawImage(image, 0, 0);
  16586. return canvas;
  16587. });
  16588. };
  16589. var blobToDataUri = function(blob) {
  16590. return new Promise$1(function(resolve) {
  16591. var reader = new FileReader();
  16592. reader.onloadend = function() {
  16593. resolve(reader.result);
  16594. };
  16595. reader.readAsDataURL(blob);
  16596. });
  16597. };
  16598. var revokeImageUrl = function(image) {
  16599. URL.revokeObjectURL(image.src);
  16600. };
  16601. var create$2 = function(getCanvas, blob, uri) {
  16602. var initialType = blob.type;
  16603. var getType = constant$1(initialType);
  16604. var toBlob = function() {
  16605. return Promise$1.resolve(blob);
  16606. };
  16607. var toDataURL = constant$1(uri);
  16608. var toBase64 = function() {
  16609. return uri.split(",")[1];
  16610. };
  16611. var toAdjustedBlob = function(type2, quality) {
  16612. return getCanvas.then(function(canvas) {
  16613. return canvasToBlob(canvas, type2, quality);
  16614. });
  16615. };
  16616. var toAdjustedDataURL = function(type2, quality) {
  16617. return getCanvas.then(function(canvas) {
  16618. return canvasToDataURL(canvas, type2, quality);
  16619. });
  16620. };
  16621. var toAdjustedBase64 = function(type2, quality) {
  16622. return toAdjustedDataURL(type2, quality).then(function(dataurl) {
  16623. return dataurl.split(",")[1];
  16624. });
  16625. };
  16626. var toCanvas = function() {
  16627. return getCanvas.then(clone);
  16628. };
  16629. return {
  16630. getType,
  16631. toBlob,
  16632. toDataURL,
  16633. toBase64,
  16634. toAdjustedBlob,
  16635. toAdjustedDataURL,
  16636. toAdjustedBase64,
  16637. toCanvas
  16638. };
  16639. };
  16640. var fromBlob = function(blob) {
  16641. return blobToDataUri(blob).then(function(uri) {
  16642. return create$2(blobToCanvas(blob), blob, uri);
  16643. });
  16644. };
  16645. var fromCanvas = function(canvas, type2) {
  16646. return canvasToBlob(canvas, type2).then(function(blob) {
  16647. return create$2(Promise$1.resolve(canvas), blob, canvas.toDataURL());
  16648. });
  16649. };
  16650. var blobToImageResult = function(blob) {
  16651. return fromBlob(blob);
  16652. };
  16653. var clamp = function(value2, min2, max2) {
  16654. var parsedValue = typeof value2 === "string" ? parseFloat(value2) : value2;
  16655. if (parsedValue > max2) {
  16656. parsedValue = max2;
  16657. } else if (parsedValue < min2) {
  16658. parsedValue = min2;
  16659. }
  16660. return parsedValue;
  16661. };
  16662. var identity = function() {
  16663. return [
  16664. 1,
  16665. 0,
  16666. 0,
  16667. 0,
  16668. 0,
  16669. 0,
  16670. 1,
  16671. 0,
  16672. 0,
  16673. 0,
  16674. 0,
  16675. 0,
  16676. 1,
  16677. 0,
  16678. 0,
  16679. 0,
  16680. 0,
  16681. 0,
  16682. 1,
  16683. 0,
  16684. 0,
  16685. 0,
  16686. 0,
  16687. 0,
  16688. 1
  16689. ];
  16690. };
  16691. var DELTA_INDEX = [
  16692. 0,
  16693. 0.01,
  16694. 0.02,
  16695. 0.04,
  16696. 0.05,
  16697. 0.06,
  16698. 0.07,
  16699. 0.08,
  16700. 0.1,
  16701. 0.11,
  16702. 0.12,
  16703. 0.14,
  16704. 0.15,
  16705. 0.16,
  16706. 0.17,
  16707. 0.18,
  16708. 0.2,
  16709. 0.21,
  16710. 0.22,
  16711. 0.24,
  16712. 0.25,
  16713. 0.27,
  16714. 0.28,
  16715. 0.3,
  16716. 0.32,
  16717. 0.34,
  16718. 0.36,
  16719. 0.38,
  16720. 0.4,
  16721. 0.42,
  16722. 0.44,
  16723. 0.46,
  16724. 0.48,
  16725. 0.5,
  16726. 0.53,
  16727. 0.56,
  16728. 0.59,
  16729. 0.62,
  16730. 0.65,
  16731. 0.68,
  16732. 0.71,
  16733. 0.74,
  16734. 0.77,
  16735. 0.8,
  16736. 0.83,
  16737. 0.86,
  16738. 0.89,
  16739. 0.92,
  16740. 0.95,
  16741. 0.98,
  16742. 1,
  16743. 1.06,
  16744. 1.12,
  16745. 1.18,
  16746. 1.24,
  16747. 1.3,
  16748. 1.36,
  16749. 1.42,
  16750. 1.48,
  16751. 1.54,
  16752. 1.6,
  16753. 1.66,
  16754. 1.72,
  16755. 1.78,
  16756. 1.84,
  16757. 1.9,
  16758. 1.96,
  16759. 2,
  16760. 2.12,
  16761. 2.25,
  16762. 2.37,
  16763. 2.5,
  16764. 2.62,
  16765. 2.75,
  16766. 2.87,
  16767. 3,
  16768. 3.2,
  16769. 3.4,
  16770. 3.6,
  16771. 3.8,
  16772. 4,
  16773. 4.3,
  16774. 4.7,
  16775. 4.9,
  16776. 5,
  16777. 5.5,
  16778. 6,
  16779. 6.5,
  16780. 6.8,
  16781. 7,
  16782. 7.3,
  16783. 7.5,
  16784. 7.8,
  16785. 8,
  16786. 8.4,
  16787. 8.7,
  16788. 9,
  16789. 9.4,
  16790. 9.6,
  16791. 9.8,
  16792. 10
  16793. ];
  16794. var multiply = function(matrix1, matrix2) {
  16795. var col = [];
  16796. var out = new Array(25);
  16797. var val;
  16798. for (var i = 0; i < 5; i++) {
  16799. for (var j = 0; j < 5; j++) {
  16800. col[j] = matrix2[j + i * 5];
  16801. }
  16802. for (var j = 0; j < 5; j++) {
  16803. val = 0;
  16804. for (var k = 0; k < 5; k++) {
  16805. val += matrix1[j + k * 5] * col[k];
  16806. }
  16807. out[j + i * 5] = val;
  16808. }
  16809. }
  16810. return out;
  16811. };
  16812. var adjustContrast = function(matrix2, value2) {
  16813. var x;
  16814. value2 = clamp(value2, -1, 1);
  16815. value2 *= 100;
  16816. if (value2 < 0) {
  16817. x = 127 + value2 / 100 * 127;
  16818. } else {
  16819. x = value2 % 1;
  16820. if (x === 0) {
  16821. x = DELTA_INDEX[value2];
  16822. } else {
  16823. x = DELTA_INDEX[Math.floor(value2)] * (1 - x) + DELTA_INDEX[Math.floor(value2) + 1] * x;
  16824. }
  16825. x = x * 127 + 127;
  16826. }
  16827. return multiply(matrix2, [
  16828. x / 127,
  16829. 0,
  16830. 0,
  16831. 0,
  16832. 0.5 * (127 - x),
  16833. 0,
  16834. x / 127,
  16835. 0,
  16836. 0,
  16837. 0.5 * (127 - x),
  16838. 0,
  16839. 0,
  16840. x / 127,
  16841. 0,
  16842. 0.5 * (127 - x),
  16843. 0,
  16844. 0,
  16845. 0,
  16846. 1,
  16847. 0,
  16848. 0,
  16849. 0,
  16850. 0,
  16851. 0,
  16852. 1
  16853. ]);
  16854. };
  16855. var adjustBrightness = function(matrix2, value2) {
  16856. value2 = clamp(255 * value2, -255, 255);
  16857. return multiply(matrix2, [
  16858. 1,
  16859. 0,
  16860. 0,
  16861. 0,
  16862. value2,
  16863. 0,
  16864. 1,
  16865. 0,
  16866. 0,
  16867. value2,
  16868. 0,
  16869. 0,
  16870. 1,
  16871. 0,
  16872. value2,
  16873. 0,
  16874. 0,
  16875. 0,
  16876. 1,
  16877. 0,
  16878. 0,
  16879. 0,
  16880. 0,
  16881. 0,
  16882. 1
  16883. ]);
  16884. };
  16885. var adjustColors = function(matrix2, adjustR, adjustG, adjustB) {
  16886. adjustR = clamp(adjustR, 0, 2);
  16887. adjustG = clamp(adjustG, 0, 2);
  16888. adjustB = clamp(adjustB, 0, 2);
  16889. return multiply(matrix2, [
  16890. adjustR,
  16891. 0,
  16892. 0,
  16893. 0,
  16894. 0,
  16895. 0,
  16896. adjustG,
  16897. 0,
  16898. 0,
  16899. 0,
  16900. 0,
  16901. 0,
  16902. adjustB,
  16903. 0,
  16904. 0,
  16905. 0,
  16906. 0,
  16907. 0,
  16908. 1,
  16909. 0,
  16910. 0,
  16911. 0,
  16912. 0,
  16913. 0,
  16914. 1
  16915. ]);
  16916. };
  16917. var colorFilter = function(ir, matrix2) {
  16918. return ir.toCanvas().then(function(canvas) {
  16919. return applyColorFilter(canvas, ir.getType(), matrix2);
  16920. });
  16921. };
  16922. var applyColorFilter = function(canvas, type2, matrix2) {
  16923. var context = get2dContext(canvas);
  16924. var applyMatrix = function(pixelsData, m) {
  16925. var r2, g, b2, a;
  16926. var data = pixelsData.data, m0 = m[0], m1 = m[1], m2 = m[2], m3 = m[3], m4 = m[4], m5 = m[5], m6 = m[6], m7 = m[7], m8 = m[8], m9 = m[9], m10 = m[10], m11 = m[11], m12 = m[12], m13 = m[13], m14 = m[14], m15 = m[15], m16 = m[16], m17 = m[17], m18 = m[18], m19 = m[19];
  16927. for (var i = 0; i < data.length; i += 4) {
  16928. r2 = data[i];
  16929. g = data[i + 1];
  16930. b2 = data[i + 2];
  16931. a = data[i + 3];
  16932. data[i] = r2 * m0 + g * m1 + b2 * m2 + a * m3 + m4;
  16933. data[i + 1] = r2 * m5 + g * m6 + b2 * m7 + a * m8 + m9;
  16934. data[i + 2] = r2 * m10 + g * m11 + b2 * m12 + a * m13 + m14;
  16935. data[i + 3] = r2 * m15 + g * m16 + b2 * m17 + a * m18 + m19;
  16936. }
  16937. return pixelsData;
  16938. };
  16939. var pixels = applyMatrix(context.getImageData(0, 0, canvas.width, canvas.height), matrix2);
  16940. context.putImageData(pixels, 0, 0);
  16941. return fromCanvas(canvas, type2);
  16942. };
  16943. var convoluteFilter = function(ir, matrix2) {
  16944. return ir.toCanvas().then(function(canvas) {
  16945. return applyConvoluteFilter(canvas, ir.getType(), matrix2);
  16946. });
  16947. };
  16948. var applyConvoluteFilter = function(canvas, type2, matrix2) {
  16949. var context = get2dContext(canvas);
  16950. var applyMatrix = function(pIn, pOut, aMatrix) {
  16951. var clamp2 = function(value2, min2, max2) {
  16952. if (value2 > max2) {
  16953. value2 = max2;
  16954. } else if (value2 < min2) {
  16955. value2 = min2;
  16956. }
  16957. return value2;
  16958. };
  16959. var side = Math.round(Math.sqrt(aMatrix.length));
  16960. var halfSide = Math.floor(side / 2);
  16961. var rgba = pIn.data;
  16962. var drgba = pOut.data;
  16963. var w = pIn.width;
  16964. var h = pIn.height;
  16965. for (var y = 0; y < h; y++) {
  16966. for (var x = 0; x < w; x++) {
  16967. var r2 = 0;
  16968. var g = 0;
  16969. var b2 = 0;
  16970. for (var cy = 0; cy < side; cy++) {
  16971. for (var cx = 0; cx < side; cx++) {
  16972. var scx = clamp2(x + cx - halfSide, 0, w - 1);
  16973. var scy = clamp2(y + cy - halfSide, 0, h - 1);
  16974. var innerOffset = (scy * w + scx) * 4;
  16975. var wt = aMatrix[cy * side + cx];
  16976. r2 += rgba[innerOffset] * wt;
  16977. g += rgba[innerOffset + 1] * wt;
  16978. b2 += rgba[innerOffset + 2] * wt;
  16979. }
  16980. }
  16981. var offset2 = (y * w + x) * 4;
  16982. drgba[offset2] = clamp2(r2, 0, 255);
  16983. drgba[offset2 + 1] = clamp2(g, 0, 255);
  16984. drgba[offset2 + 2] = clamp2(b2, 0, 255);
  16985. }
  16986. }
  16987. return pOut;
  16988. };
  16989. var pixelsIn = context.getImageData(0, 0, canvas.width, canvas.height);
  16990. var pixelsOut = context.getImageData(0, 0, canvas.width, canvas.height);
  16991. pixelsOut = applyMatrix(pixelsIn, pixelsOut, matrix2);
  16992. context.putImageData(pixelsOut, 0, 0);
  16993. return fromCanvas(canvas, type2);
  16994. };
  16995. var functionColorFilter = function(colorFn) {
  16996. var filterImpl = function(canvas, type2, value2) {
  16997. var context = get2dContext(canvas);
  16998. var lookup2 = new Array(256);
  16999. var applyLookup = function(pixelsData, lookupData) {
  17000. var data = pixelsData.data;
  17001. for (var i2 = 0; i2 < data.length; i2 += 4) {
  17002. data[i2] = lookupData[data[i2]];
  17003. data[i2 + 1] = lookupData[data[i2 + 1]];
  17004. data[i2 + 2] = lookupData[data[i2 + 2]];
  17005. }
  17006. return pixelsData;
  17007. };
  17008. for (var i = 0; i < lookup2.length; i++) {
  17009. lookup2[i] = colorFn(i, value2);
  17010. }
  17011. var pixels = applyLookup(context.getImageData(0, 0, canvas.width, canvas.height), lookup2);
  17012. context.putImageData(pixels, 0, 0);
  17013. return fromCanvas(canvas, type2);
  17014. };
  17015. return function(ir, value2) {
  17016. return ir.toCanvas().then(function(canvas) {
  17017. return filterImpl(canvas, ir.getType(), value2);
  17018. });
  17019. };
  17020. };
  17021. var complexAdjustableColorFilter = function(matrixAdjustFn) {
  17022. return function(ir, adjust) {
  17023. return colorFilter(ir, matrixAdjustFn(identity(), adjust));
  17024. };
  17025. };
  17026. var basicColorFilter = function(matrix2) {
  17027. return function(ir) {
  17028. return colorFilter(ir, matrix2);
  17029. };
  17030. };
  17031. var basicConvolutionFilter = function(kernel) {
  17032. return function(ir) {
  17033. return convoluteFilter(ir, kernel);
  17034. };
  17035. };
  17036. var invert$1 = basicColorFilter([
  17037. -1,
  17038. 0,
  17039. 0,
  17040. 0,
  17041. 255,
  17042. 0,
  17043. -1,
  17044. 0,
  17045. 0,
  17046. 255,
  17047. 0,
  17048. 0,
  17049. -1,
  17050. 0,
  17051. 255,
  17052. 0,
  17053. 0,
  17054. 0,
  17055. 1,
  17056. 0,
  17057. 0,
  17058. 0,
  17059. 0,
  17060. 0,
  17061. 1
  17062. ]);
  17063. var brightness$1 = complexAdjustableColorFilter(adjustBrightness);
  17064. var contrast$1 = complexAdjustableColorFilter(adjustContrast);
  17065. var colorize$1 = function(ir, adjustR, adjustG, adjustB) {
  17066. return colorFilter(ir, adjustColors(identity(), adjustR, adjustG, adjustB));
  17067. };
  17068. var sharpen$1 = basicConvolutionFilter([
  17069. 0,
  17070. -1,
  17071. 0,
  17072. -1,
  17073. 5,
  17074. -1,
  17075. 0,
  17076. -1,
  17077. 0
  17078. ]);
  17079. var gamma$1 = functionColorFilter(function(color, value2) {
  17080. return Math.pow(color / 255, 1 - value2) * 255;
  17081. });
  17082. var scale = function(image, dW, dH) {
  17083. var sW = getWidth$1(image);
  17084. var sH = getHeight$1(image);
  17085. var wRatio = dW / sW;
  17086. var hRatio = dH / sH;
  17087. var scaleCapped = false;
  17088. if (wRatio < 0.5 || wRatio > 2) {
  17089. wRatio = wRatio < 0.5 ? 0.5 : 2;
  17090. scaleCapped = true;
  17091. }
  17092. if (hRatio < 0.5 || hRatio > 2) {
  17093. hRatio = hRatio < 0.5 ? 0.5 : 2;
  17094. scaleCapped = true;
  17095. }
  17096. var scaled = _scale(image, wRatio, hRatio);
  17097. return !scaleCapped ? scaled : scaled.then(function(tCanvas) {
  17098. return scale(tCanvas, dW, dH);
  17099. });
  17100. };
  17101. var _scale = function(image, wRatio, hRatio) {
  17102. return new Promise$1(function(resolve) {
  17103. var sW = getWidth$1(image);
  17104. var sH = getHeight$1(image);
  17105. var dW = Math.floor(sW * wRatio);
  17106. var dH = Math.floor(sH * hRatio);
  17107. var canvas = create$3(dW, dH);
  17108. var context = get2dContext(canvas);
  17109. context.drawImage(image, 0, 0, sW, sH, 0, 0, dW, dH);
  17110. resolve(canvas);
  17111. });
  17112. };
  17113. var ceilWithPrecision = function(num, precision) {
  17114. if (precision === void 0) {
  17115. precision = 2;
  17116. }
  17117. var mul = Math.pow(10, precision);
  17118. var upper = Math.round(num * mul);
  17119. return Math.ceil(upper / mul);
  17120. };
  17121. var rotate$1 = function(ir, angle) {
  17122. return ir.toCanvas().then(function(canvas) {
  17123. return applyRotate(canvas, ir.getType(), angle);
  17124. });
  17125. };
  17126. var applyRotate = function(image, type2, angle) {
  17127. var degrees = angle < 0 ? 360 + angle : angle;
  17128. var rad = degrees * Math.PI / 180;
  17129. var width2 = image.width;
  17130. var height2 = image.height;
  17131. var sin = Math.sin(rad);
  17132. var cos = Math.cos(rad);
  17133. var newWidth = ceilWithPrecision(Math.abs(width2 * cos) + Math.abs(height2 * sin));
  17134. var newHeight = ceilWithPrecision(Math.abs(width2 * sin) + Math.abs(height2 * cos));
  17135. var canvas = create$3(newWidth, newHeight);
  17136. var context = get2dContext(canvas);
  17137. context.translate(newWidth / 2, newHeight / 2);
  17138. context.rotate(rad);
  17139. context.drawImage(image, -width2 / 2, -height2 / 2);
  17140. return fromCanvas(canvas, type2);
  17141. };
  17142. var flip$1 = function(ir, axis) {
  17143. return ir.toCanvas().then(function(canvas) {
  17144. return applyFlip(canvas, ir.getType(), axis);
  17145. });
  17146. };
  17147. var applyFlip = function(image, type2, axis) {
  17148. var canvas = create$3(image.width, image.height);
  17149. var context = get2dContext(canvas);
  17150. if (axis === "v") {
  17151. context.scale(1, -1);
  17152. context.drawImage(image, 0, -canvas.height);
  17153. } else {
  17154. context.scale(-1, 1);
  17155. context.drawImage(image, -canvas.width, 0);
  17156. }
  17157. return fromCanvas(canvas, type2);
  17158. };
  17159. var crop$1 = function(ir, x, y, w, h) {
  17160. return ir.toCanvas().then(function(canvas) {
  17161. return applyCrop(canvas, ir.getType(), x, y, w, h);
  17162. });
  17163. };
  17164. var applyCrop = function(image, type2, x, y, w, h) {
  17165. var canvas = create$3(w, h);
  17166. var context = get2dContext(canvas);
  17167. context.drawImage(image, -x, -y);
  17168. return fromCanvas(canvas, type2);
  17169. };
  17170. var resize$2 = function(ir, w, h) {
  17171. return ir.toCanvas().then(function(canvas) {
  17172. return scale(canvas, w, h).then(function(newCanvas) {
  17173. return fromCanvas(newCanvas, ir.getType());
  17174. });
  17175. });
  17176. };
  17177. var invert = function(ir) {
  17178. return invert$1(ir);
  17179. };
  17180. var sharpen = function(ir) {
  17181. return sharpen$1(ir);
  17182. };
  17183. var gamma = function(ir, value2) {
  17184. return gamma$1(ir, value2);
  17185. };
  17186. var colorize = function(ir, adjustR, adjustG, adjustB) {
  17187. return colorize$1(ir, adjustR, adjustG, adjustB);
  17188. };
  17189. var brightness = function(ir, adjust) {
  17190. return brightness$1(ir, adjust);
  17191. };
  17192. var contrast = function(ir, adjust) {
  17193. return contrast$1(ir, adjust);
  17194. };
  17195. var flip = function(ir, axis) {
  17196. return flip$1(ir, axis);
  17197. };
  17198. var crop = function(ir, x, y, w, h) {
  17199. return crop$1(ir, x, y, w, h);
  17200. };
  17201. var resize$1 = function(ir, w, h) {
  17202. return resize$2(ir, w, h);
  17203. };
  17204. var rotate = function(ir, angle) {
  17205. return rotate$1(ir, angle);
  17206. };
  17207. var renderIcon = function(iconName, iconsProvider, behaviours2) {
  17208. return render$3(iconName, {
  17209. tag: "span",
  17210. classes: [
  17211. "tox-icon",
  17212. "tox-tbtn__icon-wrap"
  17213. ],
  17214. behaviours: behaviours2
  17215. }, iconsProvider);
  17216. };
  17217. var renderIconFromPack = function(iconName, iconsProvider) {
  17218. return renderIcon(iconName, iconsProvider, []);
  17219. };
  17220. var renderReplacableIconFromPack = function(iconName, iconsProvider) {
  17221. return renderIcon(iconName, iconsProvider, [Replacing.config({})]);
  17222. };
  17223. var renderLabel$1 = function(text2, prefix2, providersBackstage) {
  17224. return {
  17225. dom: {
  17226. tag: "span",
  17227. innerHtml: providersBackstage.translate(text2),
  17228. classes: [prefix2 + "__select-label"]
  17229. },
  17230. behaviours: derive$1([Replacing.config({})])
  17231. };
  17232. };
  17233. var _a;
  17234. var internalToolbarButtonExecute = generate$6("toolbar.button.execute");
  17235. var onToolbarButtonExecute = function(info) {
  17236. return runOnExecute$1(function(comp, _simulatedEvent) {
  17237. runWithApi(info, comp)(function(itemApi) {
  17238. emitWith(comp, internalToolbarButtonExecute, { buttonApi: itemApi });
  17239. info.onAction(itemApi);
  17240. });
  17241. });
  17242. };
  17243. var toolbarButtonEventOrder = (_a = {}, _a[execute$5()] = [
  17244. "disabling",
  17245. "alloy.base.behaviour",
  17246. "toggling",
  17247. "toolbar-button-events"
  17248. ], _a);
  17249. var updateMenuText = generate$6("update-menu-text");
  17250. var updateMenuIcon = generate$6("update-menu-icon");
  17251. var renderCommonDropdown = function(spec, prefix2, sharedBackstage) {
  17252. var editorOffCell = Cell(noop);
  17253. var optMemDisplayText = spec.text.map(function(text2) {
  17254. return record(renderLabel$1(text2, prefix2, sharedBackstage.providers));
  17255. });
  17256. var optMemDisplayIcon = spec.icon.map(function(iconName) {
  17257. return record(renderReplacableIconFromPack(iconName, sharedBackstage.providers.icons));
  17258. });
  17259. var onLeftOrRightInMenu = function(comp, se) {
  17260. var dropdown = Representing.getValue(comp);
  17261. Focusing.focus(dropdown);
  17262. emitWith(dropdown, "keydown", { raw: se.event.raw });
  17263. Dropdown.close(dropdown);
  17264. return Optional.some(true);
  17265. };
  17266. var role = spec.role.fold(function() {
  17267. return {};
  17268. }, function(role2) {
  17269. return { role: role2 };
  17270. });
  17271. var tooltipAttributes = spec.tooltip.fold(function() {
  17272. return {};
  17273. }, function(tooltip) {
  17274. var translatedTooltip = sharedBackstage.providers.translate(tooltip);
  17275. return {
  17276. "title": translatedTooltip,
  17277. "aria-label": translatedTooltip
  17278. };
  17279. });
  17280. var iconSpec = render$3("chevron-down", {
  17281. tag: "div",
  17282. classes: [prefix2 + "__select-chevron"]
  17283. }, sharedBackstage.providers.icons);
  17284. var memDropdown = record(Dropdown.sketch(__assign(__assign(__assign({}, spec.uid ? { uid: spec.uid } : {}), role), {
  17285. dom: {
  17286. tag: "button",
  17287. classes: [
  17288. prefix2,
  17289. prefix2 + "--select"
  17290. ].concat(map$2(spec.classes, function(c) {
  17291. return prefix2 + "--" + c;
  17292. })),
  17293. attributes: __assign({}, tooltipAttributes)
  17294. },
  17295. components: componentRenderPipeline([
  17296. optMemDisplayIcon.map(function(mem) {
  17297. return mem.asSpec();
  17298. }),
  17299. optMemDisplayText.map(function(mem) {
  17300. return mem.asSpec();
  17301. }),
  17302. Optional.some(iconSpec)
  17303. ]),
  17304. matchWidth: true,
  17305. useMinWidth: true,
  17306. dropdownBehaviours: derive$1(__spreadArray(__spreadArray([], spec.dropdownBehaviours, true), [
  17307. DisablingConfigs.button(function() {
  17308. return spec.disabled || sharedBackstage.providers.isDisabled();
  17309. }),
  17310. receivingConfig(),
  17311. Unselecting.config({}),
  17312. Replacing.config({}),
  17313. config("dropdown-events", [
  17314. onControlAttached(spec, editorOffCell),
  17315. onControlDetached(spec, editorOffCell)
  17316. ]),
  17317. config("menubutton-update-display-text", [
  17318. run$1(updateMenuText, function(comp, se) {
  17319. optMemDisplayText.bind(function(mem) {
  17320. return mem.getOpt(comp);
  17321. }).each(function(displayText) {
  17322. Replacing.set(displayText, [text(sharedBackstage.providers.translate(se.event.text))]);
  17323. });
  17324. }),
  17325. run$1(updateMenuIcon, function(comp, se) {
  17326. optMemDisplayIcon.bind(function(mem) {
  17327. return mem.getOpt(comp);
  17328. }).each(function(displayIcon) {
  17329. Replacing.set(displayIcon, [renderReplacableIconFromPack(se.event.icon, sharedBackstage.providers.icons)]);
  17330. });
  17331. })
  17332. ])
  17333. ], false)),
  17334. eventOrder: deepMerge(toolbarButtonEventOrder, {
  17335. mousedown: [
  17336. "focusing",
  17337. "alloy.base.behaviour",
  17338. "item-type-events",
  17339. "normal-dropdown-events"
  17340. ]
  17341. }),
  17342. sandboxBehaviours: derive$1([Keying.config({
  17343. mode: "special",
  17344. onLeft: onLeftOrRightInMenu,
  17345. onRight: onLeftOrRightInMenu
  17346. })]),
  17347. lazySink: sharedBackstage.getSink,
  17348. toggleClass: prefix2 + "--active",
  17349. parts: { menu: part(false, spec.columns, spec.presets) },
  17350. fetch: function(comp) {
  17351. return Future.nu(curry(spec.fetch, comp));
  17352. }
  17353. })));
  17354. return memDropdown.asSpec();
  17355. };
  17356. var isMenuItemReference = function(item2) {
  17357. return isString(item2);
  17358. };
  17359. var isSeparator$1 = function(item2) {
  17360. return item2.type === "separator";
  17361. };
  17362. var isExpandingMenuItem = function(item2) {
  17363. return has$2(item2, "getSubmenuItems");
  17364. };
  17365. var separator$2 = { type: "separator" };
  17366. var unwrapReferences = function(items, menuItems) {
  17367. var realItems = foldl(items, function(acc, item2) {
  17368. if (isMenuItemReference(item2)) {
  17369. if (item2 === "") {
  17370. return acc;
  17371. } else if (item2 === "|") {
  17372. return acc.length > 0 && !isSeparator$1(acc[acc.length - 1]) ? acc.concat([separator$2]) : acc;
  17373. } else if (has$2(menuItems, item2.toLowerCase())) {
  17374. return acc.concat([menuItems[item2.toLowerCase()]]);
  17375. } else {
  17376. return acc;
  17377. }
  17378. } else {
  17379. return acc.concat([item2]);
  17380. }
  17381. }, []);
  17382. if (realItems.length > 0 && isSeparator$1(realItems[realItems.length - 1])) {
  17383. realItems.pop();
  17384. }
  17385. return realItems;
  17386. };
  17387. var getFromExpandingItem = function(item2, menuItems) {
  17388. var submenuItems = item2.getSubmenuItems();
  17389. var rest = expand(submenuItems, menuItems);
  17390. var newMenus = deepMerge(rest.menus, wrap$1(item2.value, rest.items));
  17391. var newExpansions = deepMerge(rest.expansions, wrap$1(item2.value, item2.value));
  17392. return {
  17393. item: item2,
  17394. menus: newMenus,
  17395. expansions: newExpansions
  17396. };
  17397. };
  17398. var getFromItem = function(item2, menuItems) {
  17399. return isExpandingMenuItem(item2) ? getFromExpandingItem(item2, menuItems) : {
  17400. item: item2,
  17401. menus: {},
  17402. expansions: {}
  17403. };
  17404. };
  17405. var generateValueIfRequired = function(item2) {
  17406. if (isSeparator$1(item2)) {
  17407. return item2;
  17408. } else {
  17409. var itemValue = get$e(item2, "value").getOrThunk(function() {
  17410. return generate$6("generated-menu-item");
  17411. });
  17412. return deepMerge({ value: itemValue }, item2);
  17413. }
  17414. };
  17415. var expand = function(items, menuItems) {
  17416. var realItems = unwrapReferences(isString(items) ? items.split(" ") : items, menuItems);
  17417. return foldr(realItems, function(acc, item2) {
  17418. var itemWithValue = generateValueIfRequired(item2);
  17419. var newData = getFromItem(itemWithValue, menuItems);
  17420. return {
  17421. menus: deepMerge(acc.menus, newData.menus),
  17422. items: [newData.item].concat(acc.items),
  17423. expansions: deepMerge(acc.expansions, newData.expansions)
  17424. };
  17425. }, {
  17426. menus: {},
  17427. expansions: {},
  17428. items: []
  17429. });
  17430. };
  17431. var build = function(items, itemResponse, backstage, isHorizontalMenu) {
  17432. var primary = generate$6("primary-menu");
  17433. var data = expand(items, backstage.shared.providers.menuItems());
  17434. if (data.items.length === 0) {
  17435. return Optional.none();
  17436. }
  17437. var mainMenu = createPartialMenu(primary, data.items, itemResponse, backstage, isHorizontalMenu);
  17438. var submenus = map$1(data.menus, function(menuItems, menuName) {
  17439. return createPartialMenu(menuName, menuItems, itemResponse, backstage, false);
  17440. });
  17441. var menus = deepMerge(submenus, wrap$1(primary, mainMenu));
  17442. return Optional.from(tieredMenu.tieredData(primary, menus, data.expansions));
  17443. };
  17444. var getMenuButtonApi = function(component) {
  17445. return {
  17446. isDisabled: function() {
  17447. return Disabling.isDisabled(component);
  17448. },
  17449. setDisabled: function(state) {
  17450. return Disabling.set(component, state);
  17451. },
  17452. setActive: function(state) {
  17453. var elm = component.element;
  17454. if (state) {
  17455. add$2(elm, "tox-tbtn--enabled");
  17456. set$8(elm, "aria-pressed", true);
  17457. } else {
  17458. remove$2(elm, "tox-tbtn--enabled");
  17459. remove$7(elm, "aria-pressed");
  17460. }
  17461. },
  17462. isActive: function() {
  17463. return has(component.element, "tox-tbtn--enabled");
  17464. }
  17465. };
  17466. };
  17467. var renderMenuButton = function(spec, prefix2, backstage, role) {
  17468. return renderCommonDropdown({
  17469. text: spec.text,
  17470. icon: spec.icon,
  17471. tooltip: spec.tooltip,
  17472. role,
  17473. fetch: function(_comp, callback) {
  17474. spec.fetch(function(items) {
  17475. callback(build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false));
  17476. });
  17477. },
  17478. onSetup: spec.onSetup,
  17479. getApi: getMenuButtonApi,
  17480. columns: 1,
  17481. presets: "normal",
  17482. classes: [],
  17483. dropdownBehaviours: [Tabstopping.config({})]
  17484. }, prefix2, backstage.shared);
  17485. };
  17486. var getFetch = function(items, getButton, backstage) {
  17487. var getMenuItemAction = function(item2) {
  17488. return function(api2) {
  17489. var newValue = !api2.isActive();
  17490. api2.setActive(newValue);
  17491. item2.storage.set(newValue);
  17492. backstage.shared.getSink().each(function(sink) {
  17493. getButton().getOpt(sink).each(function(orig) {
  17494. focus$3(orig.element);
  17495. emitWith(orig, formActionEvent, {
  17496. name: item2.name,
  17497. value: item2.storage.get()
  17498. });
  17499. });
  17500. });
  17501. };
  17502. };
  17503. var getMenuItemSetup = function(item2) {
  17504. return function(api2) {
  17505. api2.setActive(item2.storage.get());
  17506. };
  17507. };
  17508. return function(success) {
  17509. success(map$2(items, function(item2) {
  17510. var text2 = item2.text.fold(function() {
  17511. return {};
  17512. }, function(text3) {
  17513. return { text: text3 };
  17514. });
  17515. return __assign(__assign({
  17516. type: item2.type,
  17517. active: false
  17518. }, text2), {
  17519. onAction: getMenuItemAction(item2),
  17520. onSetup: getMenuItemSetup(item2)
  17521. });
  17522. }));
  17523. };
  17524. };
  17525. var renderCommonSpec = function(spec, actionOpt, extraBehaviours, dom2, components2, providersBackstage) {
  17526. if (extraBehaviours === void 0) {
  17527. extraBehaviours = [];
  17528. }
  17529. var action = actionOpt.fold(function() {
  17530. return {};
  17531. }, function(action2) {
  17532. return { action: action2 };
  17533. });
  17534. var common = __assign({
  17535. buttonBehaviours: derive$1([
  17536. DisablingConfigs.button(function() {
  17537. return spec.disabled || providersBackstage.isDisabled();
  17538. }),
  17539. receivingConfig(),
  17540. Tabstopping.config({}),
  17541. config("button press", [
  17542. preventDefault("click"),
  17543. preventDefault("mousedown")
  17544. ])
  17545. ].concat(extraBehaviours)),
  17546. eventOrder: {
  17547. click: [
  17548. "button press",
  17549. "alloy.base.behaviour"
  17550. ],
  17551. mousedown: [
  17552. "button press",
  17553. "alloy.base.behaviour"
  17554. ]
  17555. }
  17556. }, action);
  17557. var domFinal = deepMerge(common, { dom: dom2 });
  17558. return deepMerge(domFinal, { components: components2 });
  17559. };
  17560. var renderIconButtonSpec = function(spec, action, providersBackstage, extraBehaviours) {
  17561. if (extraBehaviours === void 0) {
  17562. extraBehaviours = [];
  17563. }
  17564. var tooltipAttributes = spec.tooltip.map(function(tooltip) {
  17565. return {
  17566. "aria-label": providersBackstage.translate(tooltip),
  17567. "title": providersBackstage.translate(tooltip)
  17568. };
  17569. }).getOr({});
  17570. var dom2 = {
  17571. tag: "button",
  17572. classes: ["tox-tbtn"],
  17573. attributes: tooltipAttributes
  17574. };
  17575. var icon = spec.icon.map(function(iconName) {
  17576. return renderIconFromPack(iconName, providersBackstage.icons);
  17577. });
  17578. var components2 = componentRenderPipeline([icon]);
  17579. return renderCommonSpec(spec, action, extraBehaviours, dom2, components2, providersBackstage);
  17580. };
  17581. var renderIconButton = function(spec, action, providersBackstage, extraBehaviours) {
  17582. if (extraBehaviours === void 0) {
  17583. extraBehaviours = [];
  17584. }
  17585. var iconButtonSpec = renderIconButtonSpec(spec, Optional.some(action), providersBackstage, extraBehaviours);
  17586. return Button.sketch(iconButtonSpec);
  17587. };
  17588. var renderButtonSpec = function(spec, action, providersBackstage, extraBehaviours, extraClasses) {
  17589. if (extraBehaviours === void 0) {
  17590. extraBehaviours = [];
  17591. }
  17592. if (extraClasses === void 0) {
  17593. extraClasses = [];
  17594. }
  17595. var translatedText = providersBackstage.translate(spec.text);
  17596. var icon = spec.icon ? spec.icon.map(function(iconName) {
  17597. return renderIconFromPack(iconName, providersBackstage.icons);
  17598. }) : Optional.none();
  17599. var components2 = icon.isSome() ? componentRenderPipeline([icon]) : [];
  17600. var innerHtml = icon.isSome() ? {} : { innerHtml: translatedText };
  17601. var classes2 = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], !spec.primary && !spec.borderless ? [
  17602. "tox-button",
  17603. "tox-button--secondary"
  17604. ] : ["tox-button"], true), icon.isSome() ? ["tox-button--icon"] : [], true), spec.borderless ? ["tox-button--naked"] : [], true), extraClasses, true);
  17605. var dom2 = __assign(__assign({
  17606. tag: "button",
  17607. classes: classes2
  17608. }, innerHtml), { attributes: { title: translatedText } });
  17609. return renderCommonSpec(spec, action, extraBehaviours, dom2, components2, providersBackstage);
  17610. };
  17611. var renderButton = function(spec, action, providersBackstage, extraBehaviours, extraClasses) {
  17612. if (extraBehaviours === void 0) {
  17613. extraBehaviours = [];
  17614. }
  17615. if (extraClasses === void 0) {
  17616. extraClasses = [];
  17617. }
  17618. var buttonSpec = renderButtonSpec(spec, Optional.some(action), providersBackstage, extraBehaviours, extraClasses);
  17619. return Button.sketch(buttonSpec);
  17620. };
  17621. var getAction = function(name2, buttonType) {
  17622. return function(comp) {
  17623. if (buttonType === "custom") {
  17624. emitWith(comp, formActionEvent, {
  17625. name: name2,
  17626. value: {}
  17627. });
  17628. } else if (buttonType === "submit") {
  17629. emit(comp, formSubmitEvent);
  17630. } else if (buttonType === "cancel") {
  17631. emit(comp, formCancelEvent);
  17632. } else {
  17633. console.error("Unknown button type: ", buttonType);
  17634. }
  17635. };
  17636. };
  17637. var isMenuFooterButtonSpec = function(spec, buttonType) {
  17638. return buttonType === "menu";
  17639. };
  17640. var isNormalFooterButtonSpec = function(spec, buttonType) {
  17641. return buttonType === "custom" || buttonType === "cancel" || buttonType === "submit";
  17642. };
  17643. var renderFooterButton = function(spec, buttonType, backstage) {
  17644. if (isMenuFooterButtonSpec(spec, buttonType)) {
  17645. var getButton = function() {
  17646. return memButton_1;
  17647. };
  17648. var menuButtonSpec = spec;
  17649. var fixedSpec = __assign(__assign({}, spec), {
  17650. onSetup: function(api2) {
  17651. api2.setDisabled(spec.disabled);
  17652. return noop;
  17653. },
  17654. fetch: getFetch(menuButtonSpec.items, getButton, backstage)
  17655. });
  17656. var memButton_1 = record(renderMenuButton(fixedSpec, "tox-tbtn", backstage, Optional.none()));
  17657. return memButton_1.asSpec();
  17658. } else if (isNormalFooterButtonSpec(spec, buttonType)) {
  17659. var action = getAction(spec.name, buttonType);
  17660. var buttonSpec = __assign(__assign({}, spec), { borderless: false });
  17661. return renderButton(buttonSpec, action, backstage.shared.providers, []);
  17662. } else {
  17663. console.error("Unknown footer button type: ", buttonType);
  17664. }
  17665. };
  17666. var renderDialogButton = function(spec, providersBackstage) {
  17667. var action = getAction(spec.name, "custom");
  17668. return renderFormField(Optional.none(), FormField.parts.field(__assign({ factory: Button }, renderButtonSpec(spec, Optional.some(action), providersBackstage, [
  17669. RepresentingConfigs.memory(""),
  17670. ComposingConfigs.self()
  17671. ]))));
  17672. };
  17673. var schema$h = constant$1([
  17674. defaulted("field1Name", "field1"),
  17675. defaulted("field2Name", "field2"),
  17676. onStrictHandler("onLockedChange"),
  17677. markers$1(["lockClass"]),
  17678. defaulted("locked", false),
  17679. SketchBehaviours.field("coupledFieldBehaviours", [
  17680. Composing,
  17681. Representing
  17682. ])
  17683. ]);
  17684. var getField = function(comp, detail, partName) {
  17685. return getPart(comp, detail, partName).bind(Composing.getCurrent);
  17686. };
  17687. var coupledPart = function(selfName, otherName) {
  17688. return required({
  17689. factory: FormField,
  17690. name: selfName,
  17691. overrides: function(detail) {
  17692. return {
  17693. fieldBehaviours: derive$1([config("coupled-input-behaviour", [run$1(input(), function(me) {
  17694. getField(me, detail, otherName).each(function(other) {
  17695. getPart(me, detail, "lock").each(function(lock) {
  17696. if (Toggling.isOn(lock)) {
  17697. detail.onLockedChange(me, other, lock);
  17698. }
  17699. });
  17700. });
  17701. })])])
  17702. };
  17703. }
  17704. });
  17705. };
  17706. var parts$c = constant$1([
  17707. coupledPart("field1", "field2"),
  17708. coupledPart("field2", "field1"),
  17709. required({
  17710. factory: Button,
  17711. schema: [required$1("dom")],
  17712. name: "lock",
  17713. overrides: function(detail) {
  17714. return {
  17715. buttonBehaviours: derive$1([Toggling.config({
  17716. selected: detail.locked,
  17717. toggleClass: detail.markers.lockClass,
  17718. aria: { mode: "pressed" }
  17719. })])
  17720. };
  17721. }
  17722. })
  17723. ]);
  17724. var factory$f = function(detail, components2, _spec, _externals) {
  17725. return {
  17726. uid: detail.uid,
  17727. dom: detail.dom,
  17728. components: components2,
  17729. behaviours: SketchBehaviours.augment(detail.coupledFieldBehaviours, [
  17730. Composing.config({ find: Optional.some }),
  17731. Representing.config({
  17732. store: {
  17733. mode: "manual",
  17734. getValue: function(comp) {
  17735. var _a2;
  17736. var parts2 = getPartsOrDie(comp, detail, [
  17737. "field1",
  17738. "field2"
  17739. ]);
  17740. return _a2 = {}, _a2[detail.field1Name] = Representing.getValue(parts2.field1()), _a2[detail.field2Name] = Representing.getValue(parts2.field2()), _a2;
  17741. },
  17742. setValue: function(comp, value2) {
  17743. var parts2 = getPartsOrDie(comp, detail, [
  17744. "field1",
  17745. "field2"
  17746. ]);
  17747. if (hasNonNullableKey(value2, detail.field1Name)) {
  17748. Representing.setValue(parts2.field1(), value2[detail.field1Name]);
  17749. }
  17750. if (hasNonNullableKey(value2, detail.field2Name)) {
  17751. Representing.setValue(parts2.field2(), value2[detail.field2Name]);
  17752. }
  17753. }
  17754. }
  17755. })
  17756. ]),
  17757. apis: {
  17758. getField1: function(component) {
  17759. return getPart(component, detail, "field1");
  17760. },
  17761. getField2: function(component) {
  17762. return getPart(component, detail, "field2");
  17763. },
  17764. getLock: function(component) {
  17765. return getPart(component, detail, "lock");
  17766. }
  17767. }
  17768. };
  17769. };
  17770. var FormCoupledInputs = composite({
  17771. name: "FormCoupledInputs",
  17772. configFields: schema$h(),
  17773. partFields: parts$c(),
  17774. factory: factory$f,
  17775. apis: {
  17776. getField1: function(apis, component) {
  17777. return apis.getField1(component);
  17778. },
  17779. getField2: function(apis, component) {
  17780. return apis.getField2(component);
  17781. },
  17782. getLock: function(apis, component) {
  17783. return apis.getLock(component);
  17784. }
  17785. }
  17786. });
  17787. var formatSize = function(size) {
  17788. var unitDec = {
  17789. "": 0,
  17790. "px": 0,
  17791. "pt": 1,
  17792. "mm": 1,
  17793. "pc": 2,
  17794. "ex": 2,
  17795. "em": 2,
  17796. "ch": 2,
  17797. "rem": 2,
  17798. "cm": 3,
  17799. "in": 4,
  17800. "%": 4
  17801. };
  17802. var maxDecimal = function(unit) {
  17803. return unit in unitDec ? unitDec[unit] : 1;
  17804. };
  17805. var numText = size.value.toFixed(maxDecimal(size.unit));
  17806. if (numText.indexOf(".") !== -1) {
  17807. numText = numText.replace(/\.?0*$/, "");
  17808. }
  17809. return numText + size.unit;
  17810. };
  17811. var parseSize = function(sizeText) {
  17812. var numPattern = /^\s*(\d+(?:\.\d+)?)\s*(|cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)\s*$/;
  17813. var match = numPattern.exec(sizeText);
  17814. if (match !== null) {
  17815. var value2 = parseFloat(match[1]);
  17816. var unit = match[2];
  17817. return Result.value({
  17818. value: value2,
  17819. unit
  17820. });
  17821. } else {
  17822. return Result.error(sizeText);
  17823. }
  17824. };
  17825. var convertUnit = function(size, unit) {
  17826. var inInch = {
  17827. "": 96,
  17828. "px": 96,
  17829. "pt": 72,
  17830. "cm": 2.54,
  17831. "pc": 12,
  17832. "mm": 25.4,
  17833. "in": 1
  17834. };
  17835. var supported2 = function(u) {
  17836. return has$2(inInch, u);
  17837. };
  17838. if (size.unit === unit) {
  17839. return Optional.some(size.value);
  17840. } else if (supported2(size.unit) && supported2(unit)) {
  17841. if (inInch[size.unit] === inInch[unit]) {
  17842. return Optional.some(size.value);
  17843. } else {
  17844. return Optional.some(size.value / inInch[size.unit] * inInch[unit]);
  17845. }
  17846. } else {
  17847. return Optional.none();
  17848. }
  17849. };
  17850. var noSizeConversion = function(_input) {
  17851. return Optional.none();
  17852. };
  17853. var ratioSizeConversion = function(scale2, unit) {
  17854. return function(size) {
  17855. return convertUnit(size, unit).map(function(value2) {
  17856. return {
  17857. value: value2 * scale2,
  17858. unit
  17859. };
  17860. });
  17861. };
  17862. };
  17863. var makeRatioConverter = function(currentFieldText, otherFieldText) {
  17864. var cValue = parseSize(currentFieldText).toOptional();
  17865. var oValue = parseSize(otherFieldText).toOptional();
  17866. return lift2(cValue, oValue, function(cSize, oSize) {
  17867. return convertUnit(cSize, oSize.unit).map(function(val) {
  17868. return oSize.value / val;
  17869. }).map(function(r2) {
  17870. return ratioSizeConversion(r2, oSize.unit);
  17871. }).getOr(noSizeConversion);
  17872. }).getOr(noSizeConversion);
  17873. };
  17874. var renderSizeInput = function(spec, providersBackstage) {
  17875. var converter = noSizeConversion;
  17876. var ratioEvent = generate$6("ratio-event");
  17877. var makeIcon = function(iconName) {
  17878. return render$3(iconName, {
  17879. tag: "span",
  17880. classes: [
  17881. "tox-icon",
  17882. "tox-lock-icon__" + iconName
  17883. ]
  17884. }, providersBackstage.icons);
  17885. };
  17886. var pLock = FormCoupledInputs.parts.lock({
  17887. dom: {
  17888. tag: "button",
  17889. classes: [
  17890. "tox-lock",
  17891. "tox-button",
  17892. "tox-button--naked",
  17893. "tox-button--icon"
  17894. ],
  17895. attributes: { title: providersBackstage.translate(spec.label.getOr("Constrain proportions")) }
  17896. },
  17897. components: [
  17898. makeIcon("lock"),
  17899. makeIcon("unlock")
  17900. ],
  17901. buttonBehaviours: derive$1([
  17902. Disabling.config({
  17903. disabled: function() {
  17904. return spec.disabled || providersBackstage.isDisabled();
  17905. }
  17906. }),
  17907. receivingConfig(),
  17908. Tabstopping.config({})
  17909. ])
  17910. });
  17911. var formGroup = function(components2) {
  17912. return {
  17913. dom: {
  17914. tag: "div",
  17915. classes: ["tox-form__group"]
  17916. },
  17917. components: components2
  17918. };
  17919. };
  17920. var getFieldPart = function(isField1) {
  17921. return FormField.parts.field({
  17922. factory: Input,
  17923. inputClasses: ["tox-textfield"],
  17924. inputBehaviours: derive$1([
  17925. Disabling.config({
  17926. disabled: function() {
  17927. return spec.disabled || providersBackstage.isDisabled();
  17928. }
  17929. }),
  17930. receivingConfig(),
  17931. Tabstopping.config({}),
  17932. config("size-input-events", [
  17933. run$1(focusin(), function(component, _simulatedEvent) {
  17934. emitWith(component, ratioEvent, { isField1 });
  17935. }),
  17936. run$1(change(), function(component, _simulatedEvent) {
  17937. emitWith(component, formChangeEvent, { name: spec.name });
  17938. })
  17939. ])
  17940. ]),
  17941. selectOnFocus: false
  17942. });
  17943. };
  17944. var getLabel = function(label) {
  17945. return {
  17946. dom: {
  17947. tag: "label",
  17948. classes: ["tox-label"],
  17949. innerHtml: providersBackstage.translate(label)
  17950. }
  17951. };
  17952. };
  17953. var widthField = FormCoupledInputs.parts.field1(formGroup([
  17954. FormField.parts.label(getLabel("Width")),
  17955. getFieldPart(true)
  17956. ]));
  17957. var heightField = FormCoupledInputs.parts.field2(formGroup([
  17958. FormField.parts.label(getLabel("Height")),
  17959. getFieldPart(false)
  17960. ]));
  17961. return FormCoupledInputs.sketch({
  17962. dom: {
  17963. tag: "div",
  17964. classes: ["tox-form__group"]
  17965. },
  17966. components: [{
  17967. dom: {
  17968. tag: "div",
  17969. classes: ["tox-form__controls-h-stack"]
  17970. },
  17971. components: [
  17972. widthField,
  17973. heightField,
  17974. formGroup([
  17975. getLabel("&nbsp;"),
  17976. pLock
  17977. ])
  17978. ]
  17979. }],
  17980. field1Name: "width",
  17981. field2Name: "height",
  17982. locked: true,
  17983. markers: { lockClass: "tox-locked" },
  17984. onLockedChange: function(current, other, _lock) {
  17985. parseSize(Representing.getValue(current)).each(function(size) {
  17986. converter(size).each(function(newSize) {
  17987. Representing.setValue(other, formatSize(newSize));
  17988. });
  17989. });
  17990. },
  17991. coupledFieldBehaviours: derive$1([
  17992. Disabling.config({
  17993. disabled: function() {
  17994. return spec.disabled || providersBackstage.isDisabled();
  17995. },
  17996. onDisabled: function(comp) {
  17997. FormCoupledInputs.getField1(comp).bind(FormField.getField).each(Disabling.disable);
  17998. FormCoupledInputs.getField2(comp).bind(FormField.getField).each(Disabling.disable);
  17999. FormCoupledInputs.getLock(comp).each(Disabling.disable);
  18000. },
  18001. onEnabled: function(comp) {
  18002. FormCoupledInputs.getField1(comp).bind(FormField.getField).each(Disabling.enable);
  18003. FormCoupledInputs.getField2(comp).bind(FormField.getField).each(Disabling.enable);
  18004. FormCoupledInputs.getLock(comp).each(Disabling.enable);
  18005. }
  18006. }),
  18007. receivingConfig(),
  18008. config("size-input-events2", [run$1(ratioEvent, function(component, simulatedEvent) {
  18009. var isField1 = simulatedEvent.event.isField1;
  18010. var optCurrent = isField1 ? FormCoupledInputs.getField1(component) : FormCoupledInputs.getField2(component);
  18011. var optOther = isField1 ? FormCoupledInputs.getField2(component) : FormCoupledInputs.getField1(component);
  18012. var value1 = optCurrent.map(Representing.getValue).getOr("");
  18013. var value2 = optOther.map(Representing.getValue).getOr("");
  18014. converter = makeRatioConverter(value1, value2);
  18015. })])
  18016. ])
  18017. });
  18018. };
  18019. var undo = constant$1(generate$6("undo"));
  18020. var redo = constant$1(generate$6("redo"));
  18021. var zoom = constant$1(generate$6("zoom"));
  18022. var back = constant$1(generate$6("back"));
  18023. var apply = constant$1(generate$6("apply"));
  18024. var swap = constant$1(generate$6("swap"));
  18025. var transform$1 = constant$1(generate$6("transform"));
  18026. var tempTransform = constant$1(generate$6("temp-transform"));
  18027. var transformApply = constant$1(generate$6("transform-apply"));
  18028. var internal = {
  18029. undo,
  18030. redo,
  18031. zoom,
  18032. back,
  18033. apply,
  18034. swap,
  18035. transform: transform$1,
  18036. tempTransform,
  18037. transformApply
  18038. };
  18039. var saveState = constant$1("save-state");
  18040. var disable = constant$1("disable");
  18041. var enable = constant$1("enable");
  18042. var external = {
  18043. formActionEvent,
  18044. saveState,
  18045. disable,
  18046. enable
  18047. };
  18048. var renderEditPanel = function(imagePanel, providersBackstage) {
  18049. var createButton2 = function(text2, action, disabled, primary) {
  18050. return record(renderButton({
  18051. name: text2,
  18052. text: text2,
  18053. disabled,
  18054. primary,
  18055. icon: Optional.none(),
  18056. borderless: false
  18057. }, action, providersBackstage));
  18058. };
  18059. var createIconButton = function(icon, tooltip, action, disabled) {
  18060. return record(renderIconButton({
  18061. name: icon,
  18062. icon: Optional.some(icon),
  18063. tooltip: Optional.some(tooltip),
  18064. disabled,
  18065. primary: false,
  18066. borderless: false
  18067. }, action, providersBackstage));
  18068. };
  18069. var disableAllComponents = function(comps, eventcomp) {
  18070. comps.map(function(mem) {
  18071. var component = mem.get(eventcomp);
  18072. if (component.hasConfigured(Disabling)) {
  18073. Disabling.disable(component);
  18074. }
  18075. });
  18076. };
  18077. var enableAllComponents = function(comps, eventcomp) {
  18078. comps.map(function(mem) {
  18079. var component = mem.get(eventcomp);
  18080. if (component.hasConfigured(Disabling)) {
  18081. Disabling.enable(component);
  18082. }
  18083. });
  18084. };
  18085. var panelDom = {
  18086. tag: "div",
  18087. classes: [
  18088. "tox-image-tools__toolbar",
  18089. "tox-image-tools-edit-panel"
  18090. ]
  18091. };
  18092. var noop$1 = noop;
  18093. var emit$1 = function(comp, event, data) {
  18094. emitWith(comp, event, data);
  18095. };
  18096. var emitDisable = function(component) {
  18097. return emit(component, external.disable());
  18098. };
  18099. var emitEnable = function(component) {
  18100. return emit(component, external.enable());
  18101. };
  18102. var emitTransform = function(comp, transform2) {
  18103. emitDisable(comp);
  18104. emit$1(comp, internal.transform(), { transform: transform2 });
  18105. emitEnable(comp);
  18106. };
  18107. var emitTempTransform = function(comp, transform2) {
  18108. emitDisable(comp);
  18109. emit$1(comp, internal.tempTransform(), { transform: transform2 });
  18110. emitEnable(comp);
  18111. };
  18112. var getBackSwap = function(anyInSystem) {
  18113. return function() {
  18114. memContainer.getOpt(anyInSystem).each(function(container2) {
  18115. Replacing.set(container2, [ButtonPanel]);
  18116. });
  18117. };
  18118. };
  18119. var emitTransformApply = function(comp, transform2) {
  18120. emitDisable(comp);
  18121. emit$1(comp, internal.transformApply(), {
  18122. transform: transform2,
  18123. swap: getBackSwap(comp)
  18124. });
  18125. emitEnable(comp);
  18126. };
  18127. var createBackButton = function() {
  18128. return createButton2("Back", function(button2) {
  18129. return emit$1(button2, internal.back(), { swap: getBackSwap(button2) });
  18130. }, false, false);
  18131. };
  18132. var createSpacer = function() {
  18133. return record({
  18134. dom: {
  18135. tag: "div",
  18136. classes: ["tox-spacer"]
  18137. },
  18138. behaviours: derive$1([Disabling.config({})])
  18139. });
  18140. };
  18141. var createApplyButton = function() {
  18142. return createButton2("Apply", function(button2) {
  18143. return emit$1(button2, internal.apply(), { swap: getBackSwap(button2) });
  18144. }, true, true);
  18145. };
  18146. var makeCropTransform = function() {
  18147. return function(ir) {
  18148. var rect2 = imagePanel.getRect();
  18149. return crop(ir, rect2.x, rect2.y, rect2.w, rect2.h);
  18150. };
  18151. };
  18152. var cropPanelComponents = [
  18153. createBackButton(),
  18154. createSpacer(),
  18155. createButton2("Apply", function(button2) {
  18156. var transform2 = makeCropTransform();
  18157. emitTransformApply(button2, transform2);
  18158. imagePanel.hideCrop();
  18159. }, false, true)
  18160. ];
  18161. var CropPanel = Container.sketch({
  18162. dom: panelDom,
  18163. components: cropPanelComponents.map(function(mem) {
  18164. return mem.asSpec();
  18165. }),
  18166. containerBehaviours: derive$1([config("image-tools-crop-buttons-events", [
  18167. run$1(external.disable(), function(comp, _se) {
  18168. disableAllComponents(cropPanelComponents, comp);
  18169. }),
  18170. run$1(external.enable(), function(comp, _se) {
  18171. enableAllComponents(cropPanelComponents, comp);
  18172. })
  18173. ])])
  18174. });
  18175. var memSize = record(renderSizeInput({
  18176. name: "size",
  18177. label: Optional.none(),
  18178. constrain: true,
  18179. disabled: false
  18180. }, providersBackstage));
  18181. var makeResizeTransform = function(width2, height2) {
  18182. return function(ir) {
  18183. return resize$1(ir, width2, height2);
  18184. };
  18185. };
  18186. var resizePanelComponents = [
  18187. createBackButton(),
  18188. createSpacer(),
  18189. memSize,
  18190. createSpacer(),
  18191. createButton2("Apply", function(button2) {
  18192. memSize.getOpt(button2).each(function(sizeInput) {
  18193. var value2 = Representing.getValue(sizeInput);
  18194. var width2 = parseInt(value2.width, 10);
  18195. var height2 = parseInt(value2.height, 10);
  18196. var transform2 = makeResizeTransform(width2, height2);
  18197. emitTransformApply(button2, transform2);
  18198. });
  18199. }, false, true)
  18200. ];
  18201. var ResizePanel = Container.sketch({
  18202. dom: panelDom,
  18203. components: resizePanelComponents.map(function(mem) {
  18204. return mem.asSpec();
  18205. }),
  18206. containerBehaviours: derive$1([config("image-tools-resize-buttons-events", [
  18207. run$1(external.disable(), function(comp, _se) {
  18208. disableAllComponents(resizePanelComponents, comp);
  18209. }),
  18210. run$1(external.enable(), function(comp, _se) {
  18211. enableAllComponents(resizePanelComponents, comp);
  18212. })
  18213. ])])
  18214. });
  18215. var makeValueTransform = function(transform2, value2) {
  18216. return function(ir) {
  18217. return transform2(ir, value2);
  18218. };
  18219. };
  18220. var horizontalFlip = makeValueTransform(flip, "h");
  18221. var verticalFlip = makeValueTransform(flip, "v");
  18222. var counterclockwiseRotate = makeValueTransform(rotate, -90);
  18223. var clockwiseRotate = makeValueTransform(rotate, 90);
  18224. var flipRotateOnAction = function(comp, operation) {
  18225. emitTempTransform(comp, operation);
  18226. };
  18227. var flipRotateComponents = [
  18228. createBackButton(),
  18229. createSpacer(),
  18230. createIconButton("flip-horizontally", "Flip horizontally", function(button2) {
  18231. flipRotateOnAction(button2, horizontalFlip);
  18232. }, false),
  18233. createIconButton("flip-vertically", "Flip vertically", function(button2) {
  18234. flipRotateOnAction(button2, verticalFlip);
  18235. }, false),
  18236. createIconButton("rotate-left", "Rotate counterclockwise", function(button2) {
  18237. flipRotateOnAction(button2, counterclockwiseRotate);
  18238. }, false),
  18239. createIconButton("rotate-right", "Rotate clockwise", function(button2) {
  18240. flipRotateOnAction(button2, clockwiseRotate);
  18241. }, false),
  18242. createSpacer(),
  18243. createApplyButton()
  18244. ];
  18245. var FlipRotatePanel = Container.sketch({
  18246. dom: panelDom,
  18247. components: flipRotateComponents.map(function(mem) {
  18248. return mem.asSpec();
  18249. }),
  18250. containerBehaviours: derive$1([config("image-tools-fliprotate-buttons-events", [
  18251. run$1(external.disable(), function(comp, _se) {
  18252. disableAllComponents(flipRotateComponents, comp);
  18253. }),
  18254. run$1(external.enable(), function(comp, _se) {
  18255. enableAllComponents(flipRotateComponents, comp);
  18256. })
  18257. ])])
  18258. });
  18259. var makeSlider = function(label, onChoose, min2, value2, max2) {
  18260. var labelPart2 = Slider.parts.label({
  18261. dom: {
  18262. tag: "label",
  18263. classes: ["tox-label"],
  18264. innerHtml: providersBackstage.translate(label)
  18265. }
  18266. });
  18267. var spectrum = Slider.parts.spectrum({
  18268. dom: {
  18269. tag: "div",
  18270. classes: ["tox-slider__rail"],
  18271. attributes: { role: "presentation" }
  18272. }
  18273. });
  18274. var thumb = Slider.parts.thumb({
  18275. dom: {
  18276. tag: "div",
  18277. classes: ["tox-slider__handle"],
  18278. attributes: { role: "presentation" }
  18279. }
  18280. });
  18281. return record(Slider.sketch({
  18282. dom: {
  18283. tag: "div",
  18284. classes: ["tox-slider"],
  18285. attributes: { role: "presentation" }
  18286. },
  18287. model: {
  18288. mode: "x",
  18289. minX: min2,
  18290. maxX: max2,
  18291. getInitialValue: constant$1({ x: value2 })
  18292. },
  18293. components: [
  18294. labelPart2,
  18295. spectrum,
  18296. thumb
  18297. ],
  18298. sliderBehaviours: derive$1([Focusing.config({})]),
  18299. onChoose
  18300. }));
  18301. };
  18302. var makeVariableSlider = function(label, transform2, min2, value2, max2) {
  18303. var onChoose = function(slider, _thumb, value3) {
  18304. var valTransform = makeValueTransform(transform2, value3.x / 100);
  18305. emitTransform(slider, valTransform);
  18306. };
  18307. return makeSlider(label, onChoose, min2, value2, max2);
  18308. };
  18309. var variableFilterPanelComponents = function(label, transform2, min2, value2, max2) {
  18310. return [
  18311. createBackButton(),
  18312. makeVariableSlider(label, transform2, min2, value2, max2),
  18313. createApplyButton()
  18314. ];
  18315. };
  18316. var createVariableFilterPanel = function(label, transform2, min2, value2, max2) {
  18317. var filterPanelComponents2 = variableFilterPanelComponents(label, transform2, min2, value2, max2);
  18318. return Container.sketch({
  18319. dom: panelDom,
  18320. components: filterPanelComponents2.map(function(mem) {
  18321. return mem.asSpec();
  18322. }),
  18323. containerBehaviours: derive$1([config("image-tools-filter-panel-buttons-events", [
  18324. run$1(external.disable(), function(comp, _se) {
  18325. disableAllComponents(filterPanelComponents2, comp);
  18326. }),
  18327. run$1(external.enable(), function(comp, _se) {
  18328. enableAllComponents(filterPanelComponents2, comp);
  18329. })
  18330. ])])
  18331. });
  18332. };
  18333. var filterPanelComponents = [
  18334. createBackButton(),
  18335. createSpacer(),
  18336. createApplyButton()
  18337. ];
  18338. var FilterPanel = Container.sketch({
  18339. dom: panelDom,
  18340. components: filterPanelComponents.map(function(mem) {
  18341. return mem.asSpec();
  18342. })
  18343. });
  18344. var BrightnessPanel = createVariableFilterPanel("Brightness", brightness, -100, 0, 100);
  18345. var ContrastPanel = createVariableFilterPanel("Contrast", contrast, -100, 0, 100);
  18346. var GammaPanel = createVariableFilterPanel("Gamma", gamma, -100, 0, 100);
  18347. var makeColorTransform = function(red2, green, blue) {
  18348. return function(ir) {
  18349. return colorize(ir, red2, green, blue);
  18350. };
  18351. };
  18352. var makeColorSlider = function(label) {
  18353. var onChoose = function(slider, _thumb, _value) {
  18354. var redOpt = memRed.getOpt(slider);
  18355. var blueOpt = memBlue.getOpt(slider);
  18356. var greenOpt = memGreen.getOpt(slider);
  18357. redOpt.each(function(red2) {
  18358. blueOpt.each(function(blue) {
  18359. greenOpt.each(function(green) {
  18360. var r2 = Representing.getValue(red2).x / 100;
  18361. var g = Representing.getValue(green).x / 100;
  18362. var b2 = Representing.getValue(blue).x / 100;
  18363. var transform2 = makeColorTransform(r2, g, b2);
  18364. emitTransform(slider, transform2);
  18365. });
  18366. });
  18367. });
  18368. };
  18369. return makeSlider(label, onChoose, 0, 100, 200);
  18370. };
  18371. var memRed = makeColorSlider("R");
  18372. var memGreen = makeColorSlider("G");
  18373. var memBlue = makeColorSlider("B");
  18374. var colorizePanelComponents = [
  18375. createBackButton(),
  18376. memRed,
  18377. memGreen,
  18378. memBlue,
  18379. createApplyButton()
  18380. ];
  18381. var ColorizePanel = Container.sketch({
  18382. dom: panelDom,
  18383. components: colorizePanelComponents.map(function(mem) {
  18384. return mem.asSpec();
  18385. })
  18386. });
  18387. var getTransformPanelEvent = function(panel, transform2, update) {
  18388. return function(button2) {
  18389. var swap2 = function() {
  18390. memContainer.getOpt(button2).each(function(container2) {
  18391. Replacing.set(container2, [panel]);
  18392. update(container2);
  18393. });
  18394. };
  18395. emit$1(button2, internal.swap(), {
  18396. transform: transform2,
  18397. swap: swap2
  18398. });
  18399. };
  18400. };
  18401. var cropPanelUpdate = function(_anyInSystem) {
  18402. imagePanel.showCrop();
  18403. };
  18404. var resizePanelUpdate = function(anyInSystem) {
  18405. memSize.getOpt(anyInSystem).each(function(sizeInput) {
  18406. var measurements = imagePanel.getMeasurements();
  18407. var width2 = measurements.width;
  18408. var height2 = measurements.height;
  18409. Representing.setValue(sizeInput, {
  18410. width: width2,
  18411. height: height2
  18412. });
  18413. });
  18414. };
  18415. var sharpenTransform = Optional.some(sharpen);
  18416. var invertTransform = Optional.some(invert);
  18417. var buttonPanelComponents = [
  18418. createIconButton("crop", "Crop", getTransformPanelEvent(CropPanel, Optional.none(), cropPanelUpdate), false),
  18419. createIconButton("resize", "Resize", getTransformPanelEvent(ResizePanel, Optional.none(), resizePanelUpdate), false),
  18420. createIconButton("orientation", "Orientation", getTransformPanelEvent(FlipRotatePanel, Optional.none(), noop$1), false),
  18421. createIconButton("brightness", "Brightness", getTransformPanelEvent(BrightnessPanel, Optional.none(), noop$1), false),
  18422. createIconButton("sharpen", "Sharpen", getTransformPanelEvent(FilterPanel, sharpenTransform, noop$1), false),
  18423. createIconButton("contrast", "Contrast", getTransformPanelEvent(ContrastPanel, Optional.none(), noop$1), false),
  18424. createIconButton("color-levels", "Color levels", getTransformPanelEvent(ColorizePanel, Optional.none(), noop$1), false),
  18425. createIconButton("gamma", "Gamma", getTransformPanelEvent(GammaPanel, Optional.none(), noop$1), false),
  18426. createIconButton("invert", "Invert", getTransformPanelEvent(FilterPanel, invertTransform, noop$1), false)
  18427. ];
  18428. var ButtonPanel = Container.sketch({
  18429. dom: panelDom,
  18430. components: buttonPanelComponents.map(function(mem) {
  18431. return mem.asSpec();
  18432. })
  18433. });
  18434. var container = Container.sketch({
  18435. dom: { tag: "div" },
  18436. components: [ButtonPanel],
  18437. containerBehaviours: derive$1([Replacing.config({})])
  18438. });
  18439. var memContainer = record(container);
  18440. var getApplyButton = function(anyInSystem) {
  18441. return memContainer.getOpt(anyInSystem).map(function(container2) {
  18442. var panel = container2.components()[0];
  18443. return panel.components()[panel.components().length - 1];
  18444. });
  18445. };
  18446. return {
  18447. memContainer,
  18448. getApplyButton
  18449. };
  18450. };
  18451. var global$4 = tinymce.util.Tools.resolve("tinymce.geom.Rect");
  18452. var global$3 = tinymce.util.Tools.resolve("tinymce.util.Observable");
  18453. var global$2 = tinymce.util.Tools.resolve("tinymce.util.VK");
  18454. var getDocumentSize = function(doc) {
  18455. var max2 = Math.max;
  18456. var documentElement2 = doc.documentElement;
  18457. var body2 = doc.body;
  18458. var scrollWidth = max2(documentElement2.scrollWidth, body2.scrollWidth);
  18459. var clientWidth = max2(documentElement2.clientWidth, body2.clientWidth);
  18460. var offsetWidth = max2(documentElement2.offsetWidth, body2.offsetWidth);
  18461. var scrollHeight = max2(documentElement2.scrollHeight, body2.scrollHeight);
  18462. var clientHeight = max2(documentElement2.clientHeight, body2.clientHeight);
  18463. var offsetHeight = max2(documentElement2.offsetHeight, body2.offsetHeight);
  18464. return {
  18465. width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
  18466. height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
  18467. };
  18468. };
  18469. var isTouchEvent$1 = function(e) {
  18470. return isNonNullable(e.changedTouches);
  18471. };
  18472. var updateWithTouchData = function(e) {
  18473. if (isTouchEvent$1(e)) {
  18474. var keys2 = "screenX screenY pageX pageY clientX clientY".split(" ");
  18475. for (var i = 0; i < keys2.length; i++) {
  18476. e[keys2[i]] = e.changedTouches[0][keys2[i]];
  18477. }
  18478. }
  18479. };
  18480. function DragHelper(id, settings) {
  18481. var _a2, _b, _c;
  18482. var eventOverlay;
  18483. var handleEvents = [];
  18484. var overlayEvents = [];
  18485. var doc = (_a2 = settings.document) !== null && _a2 !== void 0 ? _a2 : document;
  18486. var root = (_b = settings.root) !== null && _b !== void 0 ? _b : doc;
  18487. var sugarDoc = SugarElement.fromDom(doc);
  18488. var downButton;
  18489. var startX;
  18490. var startY;
  18491. var handleElement = SugarElement.fromDom(root.getElementById((_c = settings.handle) !== null && _c !== void 0 ? _c : id));
  18492. var start = function(e) {
  18493. var rawEvent = e.raw;
  18494. var docSize = getDocumentSize(doc);
  18495. updateWithTouchData(rawEvent);
  18496. e.prevent();
  18497. downButton = rawEvent.button;
  18498. startX = rawEvent.screenX;
  18499. startY = rawEvent.screenY;
  18500. var cursor = get$c(handleElement, "cursor");
  18501. eventOverlay = SugarElement.fromTag("div", doc);
  18502. setAll(eventOverlay, {
  18503. "position": "absolute",
  18504. "top": "0",
  18505. "left": "0",
  18506. "width": docSize.width + "px",
  18507. "height": docSize.height + "px",
  18508. "z-index": 2147483647 + "",
  18509. "opacity": "0.0001",
  18510. cursor
  18511. });
  18512. append$2(getBody(sugarDoc), eventOverlay);
  18513. overlayEvents.push(bind(sugarDoc, "mousemove", drag), bind(sugarDoc, "touchmove", drag), bind(sugarDoc, "mouseup", stop2), bind(sugarDoc, "touchend", stop2));
  18514. settings.start(rawEvent);
  18515. };
  18516. var drag = function(e) {
  18517. var rawEvent = e.raw;
  18518. updateWithTouchData(rawEvent);
  18519. if (rawEvent.button !== downButton) {
  18520. return stop2(e);
  18521. }
  18522. rawEvent.deltaX = rawEvent.screenX - startX;
  18523. rawEvent.deltaY = rawEvent.screenY - startY;
  18524. e.prevent();
  18525. settings.drag(rawEvent);
  18526. };
  18527. var stop2 = function(e) {
  18528. updateWithTouchData(e.raw);
  18529. each$1(overlayEvents, function(e2) {
  18530. return e2.unbind();
  18531. });
  18532. overlayEvents = [];
  18533. remove$5(eventOverlay);
  18534. if (settings.stop) {
  18535. settings.stop(e.raw);
  18536. }
  18537. };
  18538. var destroy = function() {
  18539. each$1(overlayEvents.concat(handleEvents), function(e) {
  18540. return e.unbind();
  18541. });
  18542. overlayEvents = [];
  18543. handleEvents = [];
  18544. if (isNonNullable(eventOverlay)) {
  18545. remove$5(eventOverlay);
  18546. }
  18547. };
  18548. handleEvents.push(bind(handleElement, "mousedown", start), bind(handleElement, "touchstart", start));
  18549. return { destroy };
  18550. }
  18551. var count = 0;
  18552. var create$1 = function(currentRect, viewPortRect, clampRect, containerElm, action) {
  18553. var dragHelpers;
  18554. var events2 = [];
  18555. var prefix2 = "tox-";
  18556. var id = prefix2 + "crid-" + count++;
  18557. var container = SugarElement.fromDom(containerElm);
  18558. var handles = [
  18559. {
  18560. name: "move",
  18561. xMul: 0,
  18562. yMul: 0,
  18563. deltaX: 1,
  18564. deltaY: 1,
  18565. deltaW: 0,
  18566. deltaH: 0,
  18567. label: "Crop Mask"
  18568. },
  18569. {
  18570. name: "nw",
  18571. xMul: 0,
  18572. yMul: 0,
  18573. deltaX: 1,
  18574. deltaY: 1,
  18575. deltaW: -1,
  18576. deltaH: -1,
  18577. label: "Top Left Crop Handle"
  18578. },
  18579. {
  18580. name: "ne",
  18581. xMul: 1,
  18582. yMul: 0,
  18583. deltaX: 0,
  18584. deltaY: 1,
  18585. deltaW: 1,
  18586. deltaH: -1,
  18587. label: "Top Right Crop Handle"
  18588. },
  18589. {
  18590. name: "sw",
  18591. xMul: 0,
  18592. yMul: 1,
  18593. deltaX: 1,
  18594. deltaY: 0,
  18595. deltaW: -1,
  18596. deltaH: 1,
  18597. label: "Bottom Left Crop Handle"
  18598. },
  18599. {
  18600. name: "se",
  18601. xMul: 1,
  18602. yMul: 1,
  18603. deltaX: 0,
  18604. deltaY: 0,
  18605. deltaW: 1,
  18606. deltaH: 1,
  18607. label: "Bottom Right Crop Handle"
  18608. }
  18609. ];
  18610. var blockers = [
  18611. "top",
  18612. "right",
  18613. "bottom",
  18614. "left"
  18615. ];
  18616. var getAbsoluteRect = function(outerRect, relativeRect) {
  18617. return {
  18618. x: relativeRect.x + outerRect.x,
  18619. y: relativeRect.y + outerRect.y,
  18620. w: relativeRect.w,
  18621. h: relativeRect.h
  18622. };
  18623. };
  18624. var getRelativeRect = function(outerRect, innerRect) {
  18625. return {
  18626. x: innerRect.x - outerRect.x,
  18627. y: innerRect.y - outerRect.y,
  18628. w: innerRect.w,
  18629. h: innerRect.h
  18630. };
  18631. };
  18632. var getInnerRect = function() {
  18633. return getRelativeRect(clampRect, currentRect);
  18634. };
  18635. var moveRect = function(handle2, startRect, deltaX, deltaY) {
  18636. var x = startRect.x + deltaX * handle2.deltaX;
  18637. var y = startRect.y + deltaY * handle2.deltaY;
  18638. var w = Math.max(20, startRect.w + deltaX * handle2.deltaW);
  18639. var h = Math.max(20, startRect.h + deltaY * handle2.deltaH);
  18640. var rect2 = currentRect = global$4.clamp({
  18641. x,
  18642. y,
  18643. w,
  18644. h
  18645. }, clampRect, handle2.name === "move");
  18646. rect2 = getRelativeRect(clampRect, rect2);
  18647. instance.fire("updateRect", { rect: rect2 });
  18648. setInnerRect(rect2);
  18649. };
  18650. var render2 = function() {
  18651. var createDragHelper = function(handle2) {
  18652. var startRect;
  18653. return DragHelper(id, {
  18654. document: containerElm.ownerDocument,
  18655. root: getRootNode(container).dom,
  18656. handle: id + "-" + handle2.name,
  18657. start: function() {
  18658. startRect = currentRect;
  18659. },
  18660. drag: function(e) {
  18661. moveRect(handle2, startRect, e.deltaX, e.deltaY);
  18662. }
  18663. });
  18664. };
  18665. var cropContainer = SugarElement.fromTag("div");
  18666. setAll$1(cropContainer, {
  18667. id,
  18668. "class": prefix2 + "croprect-container",
  18669. "role": "grid",
  18670. "aria-dropeffect": "execute"
  18671. });
  18672. append$2(container, cropContainer);
  18673. each$1(blockers, function(blocker) {
  18674. descendant(container, "#" + id).each(function(blockerElm) {
  18675. var cropBlocker = SugarElement.fromTag("div");
  18676. setAll$1(cropBlocker, {
  18677. "id": id + "-" + blocker,
  18678. "class": prefix2 + "croprect-block",
  18679. "data-mce-bogus": "all"
  18680. });
  18681. set$7(cropBlocker, "display", "none");
  18682. append$2(blockerElm, cropBlocker);
  18683. });
  18684. });
  18685. each$1(handles, function(handle2) {
  18686. descendant(container, "#" + id).each(function(handleElm) {
  18687. var cropHandle = SugarElement.fromTag("div");
  18688. setAll$1(cropHandle, {
  18689. "id": id + "-" + handle2.name,
  18690. "aria-label": handle2.label,
  18691. "aria-grabbed": "false",
  18692. "data-mce-bogus": "all",
  18693. "role": "gridcell",
  18694. "tabindex": "-1",
  18695. "title": handle2.label
  18696. });
  18697. add$1(cropHandle, [
  18698. prefix2 + "croprect-handle",
  18699. prefix2 + "croprect-handle-" + handle2.name
  18700. ]);
  18701. set$7(cropHandle, "display", "none");
  18702. append$2(handleElm, cropHandle);
  18703. });
  18704. });
  18705. dragHelpers = map$2(handles, createDragHelper);
  18706. repaint(currentRect);
  18707. var handleFocus = function(e) {
  18708. set$8(e.target, "aria-grabbed", e.raw.type === "focus" ? "true" : "false");
  18709. };
  18710. var handleKeydown = function(e) {
  18711. var activeHandle;
  18712. each$1(handles, function(handle2) {
  18713. if (get$d(e.target, "id") === id + "-" + handle2.name) {
  18714. activeHandle = handle2;
  18715. return false;
  18716. }
  18717. });
  18718. var moveAndBlock = function(evt, handle2, startRect, deltaX, deltaY) {
  18719. evt.stopPropagation();
  18720. evt.preventDefault();
  18721. moveRect(activeHandle, startRect, deltaX, deltaY);
  18722. };
  18723. switch (e.raw.keyCode) {
  18724. case global$2.LEFT:
  18725. moveAndBlock(e, activeHandle, currentRect, -10, 0);
  18726. break;
  18727. case global$2.RIGHT:
  18728. moveAndBlock(e, activeHandle, currentRect, 10, 0);
  18729. break;
  18730. case global$2.UP:
  18731. moveAndBlock(e, activeHandle, currentRect, 0, -10);
  18732. break;
  18733. case global$2.DOWN:
  18734. moveAndBlock(e, activeHandle, currentRect, 0, 10);
  18735. break;
  18736. case global$2.ENTER:
  18737. case global$2.SPACEBAR:
  18738. e.prevent();
  18739. action();
  18740. break;
  18741. }
  18742. };
  18743. events2.push(bind(container, "focusin", handleFocus), bind(container, "focusout", handleFocus), bind(container, "keydown", handleKeydown));
  18744. };
  18745. var toggleVisibility = function(state) {
  18746. var selectors = __spreadArray(__spreadArray([], map$2(handles, function(handle2) {
  18747. return "#" + id + "-" + handle2.name;
  18748. }), true), map$2(blockers, function(blocker) {
  18749. return "#" + id + "-" + blocker;
  18750. }), true).join(",");
  18751. var elems = descendants(container, selectors);
  18752. if (state) {
  18753. each$1(elems, function(elm) {
  18754. return remove$6(elm, "display");
  18755. });
  18756. } else {
  18757. each$1(elems, function(elm) {
  18758. return set$7(elm, "display", "none");
  18759. });
  18760. }
  18761. };
  18762. var repaint = function(rect2) {
  18763. var updateElementRect = function(name2, newRect) {
  18764. descendant(container, "#" + id + "-" + name2).each(function(elm) {
  18765. setAll(elm, {
  18766. left: newRect.x + "px",
  18767. top: newRect.y + "px",
  18768. width: Math.max(0, newRect.w) + "px",
  18769. height: Math.max(0, newRect.h) + "px"
  18770. });
  18771. });
  18772. };
  18773. each$1(handles, function(handle2) {
  18774. descendant(container, "#" + id + "-" + handle2.name).each(function(elm) {
  18775. setAll(elm, {
  18776. left: rect2.w * handle2.xMul + rect2.x + "px",
  18777. top: rect2.h * handle2.yMul + rect2.y + "px"
  18778. });
  18779. });
  18780. });
  18781. updateElementRect("top", {
  18782. x: viewPortRect.x,
  18783. y: viewPortRect.y,
  18784. w: viewPortRect.w,
  18785. h: rect2.y - viewPortRect.y
  18786. });
  18787. updateElementRect("right", {
  18788. x: rect2.x + rect2.w,
  18789. y: rect2.y,
  18790. w: viewPortRect.w - rect2.x - rect2.w + viewPortRect.x,
  18791. h: rect2.h
  18792. });
  18793. updateElementRect("bottom", {
  18794. x: viewPortRect.x,
  18795. y: rect2.y + rect2.h,
  18796. w: viewPortRect.w,
  18797. h: viewPortRect.h - rect2.y - rect2.h + viewPortRect.y
  18798. });
  18799. updateElementRect("left", {
  18800. x: viewPortRect.x,
  18801. y: rect2.y,
  18802. w: rect2.x - viewPortRect.x,
  18803. h: rect2.h
  18804. });
  18805. updateElementRect("move", rect2);
  18806. };
  18807. var setRect = function(rect2) {
  18808. currentRect = rect2;
  18809. repaint(currentRect);
  18810. };
  18811. var setViewPortRect = function(rect2) {
  18812. viewPortRect = rect2;
  18813. repaint(currentRect);
  18814. };
  18815. var setInnerRect = function(rect2) {
  18816. setRect(getAbsoluteRect(clampRect, rect2));
  18817. };
  18818. var setClampRect = function(rect2) {
  18819. clampRect = rect2;
  18820. repaint(currentRect);
  18821. };
  18822. var destroy = function() {
  18823. each$1(dragHelpers, function(helper) {
  18824. return helper.destroy();
  18825. });
  18826. dragHelpers = [];
  18827. each$1(events2, function(e) {
  18828. return e.unbind();
  18829. });
  18830. events2 = [];
  18831. };
  18832. render2();
  18833. var instance = __assign(__assign({}, global$3), {
  18834. toggleVisibility,
  18835. setClampRect,
  18836. setRect,
  18837. getInnerRect,
  18838. setInnerRect,
  18839. setViewPortRect,
  18840. destroy
  18841. });
  18842. return instance;
  18843. };
  18844. var CropRect = { create: create$1 };
  18845. var loadImage = function(image) {
  18846. return new global$c(function(resolve) {
  18847. var loaded = function() {
  18848. image.removeEventListener("load", loaded);
  18849. resolve(image);
  18850. };
  18851. if (image.complete) {
  18852. resolve(image);
  18853. } else {
  18854. image.addEventListener("load", loaded);
  18855. }
  18856. });
  18857. };
  18858. var renderImagePanel = function(initialUrl) {
  18859. var memBg = record({
  18860. dom: {
  18861. tag: "div",
  18862. classes: ["tox-image-tools__image-bg"],
  18863. attributes: { role: "presentation" }
  18864. }
  18865. });
  18866. var zoomState = Cell(1);
  18867. var cropRect = api$1();
  18868. var rectState = Cell({
  18869. x: 0,
  18870. y: 0,
  18871. w: 1,
  18872. h: 1
  18873. });
  18874. var viewRectState = Cell({
  18875. x: 0,
  18876. y: 0,
  18877. w: 1,
  18878. h: 1
  18879. });
  18880. var repaintImg = function(anyInSystem, img) {
  18881. memContainer.getOpt(anyInSystem).each(function(panel) {
  18882. var zoom3 = zoomState.get();
  18883. var panelW = get$a(panel.element);
  18884. var panelH = get$b(panel.element);
  18885. var width2 = img.dom.naturalWidth * zoom3;
  18886. var height2 = img.dom.naturalHeight * zoom3;
  18887. var left2 = Math.max(0, panelW / 2 - width2 / 2);
  18888. var top2 = Math.max(0, panelH / 2 - height2 / 2);
  18889. var css = {
  18890. left: left2.toString() + "px",
  18891. top: top2.toString() + "px",
  18892. width: width2.toString() + "px",
  18893. height: height2.toString() + "px",
  18894. position: "absolute"
  18895. };
  18896. setAll(img, css);
  18897. memBg.getOpt(panel).each(function(bg) {
  18898. setAll(bg.element, css);
  18899. });
  18900. cropRect.run(function(cRect) {
  18901. var rect2 = rectState.get();
  18902. cRect.setRect({
  18903. x: rect2.x * zoom3 + left2,
  18904. y: rect2.y * zoom3 + top2,
  18905. w: rect2.w * zoom3,
  18906. h: rect2.h * zoom3
  18907. });
  18908. cRect.setClampRect({
  18909. x: left2,
  18910. y: top2,
  18911. w: width2,
  18912. h: height2
  18913. });
  18914. cRect.setViewPortRect({
  18915. x: 0,
  18916. y: 0,
  18917. w: panelW,
  18918. h: panelH
  18919. });
  18920. });
  18921. });
  18922. };
  18923. var zoomFit = function(anyInSystem, img) {
  18924. memContainer.getOpt(anyInSystem).each(function(panel) {
  18925. var panelW = get$a(panel.element);
  18926. var panelH = get$b(panel.element);
  18927. var width2 = img.dom.naturalWidth;
  18928. var height2 = img.dom.naturalHeight;
  18929. var zoom3 = Math.min(panelW / width2, panelH / height2);
  18930. if (zoom3 >= 1) {
  18931. zoomState.set(1);
  18932. } else {
  18933. zoomState.set(zoom3);
  18934. }
  18935. });
  18936. };
  18937. var updateSrc = function(anyInSystem, url) {
  18938. var img = SugarElement.fromTag("img");
  18939. set$8(img, "src", url);
  18940. return loadImage(img.dom).then(function() {
  18941. if (anyInSystem.getSystem().isConnected()) {
  18942. memContainer.getOpt(anyInSystem).map(function(panel) {
  18943. var aImg = external$2({ element: img });
  18944. Replacing.replaceAt(panel, 1, Optional.some(aImg));
  18945. var lastViewRect = viewRectState.get();
  18946. var viewRect = {
  18947. x: 0,
  18948. y: 0,
  18949. w: img.dom.naturalWidth,
  18950. h: img.dom.naturalHeight
  18951. };
  18952. viewRectState.set(viewRect);
  18953. var rect2 = global$4.inflate(viewRect, -20, -20);
  18954. rectState.set(rect2);
  18955. if (lastViewRect.w !== viewRect.w || lastViewRect.h !== viewRect.h) {
  18956. zoomFit(panel, img);
  18957. }
  18958. repaintImg(panel, img);
  18959. });
  18960. }
  18961. });
  18962. };
  18963. var zoom2 = function(anyInSystem, direction) {
  18964. var currentZoom = zoomState.get();
  18965. var newZoom = direction > 0 ? Math.min(2, currentZoom + 0.1) : Math.max(0.1, currentZoom - 0.1);
  18966. zoomState.set(newZoom);
  18967. memContainer.getOpt(anyInSystem).each(function(panel) {
  18968. var img = panel.components()[1].element;
  18969. repaintImg(panel, img);
  18970. });
  18971. };
  18972. var showCrop = function() {
  18973. cropRect.run(function(cRect) {
  18974. cRect.toggleVisibility(true);
  18975. });
  18976. };
  18977. var hideCrop = function() {
  18978. cropRect.run(function(cRect) {
  18979. cRect.toggleVisibility(false);
  18980. });
  18981. };
  18982. var getRect = function() {
  18983. return rectState.get();
  18984. };
  18985. var container = Container.sketch({
  18986. dom: {
  18987. tag: "div",
  18988. classes: ["tox-image-tools__image"]
  18989. },
  18990. components: [
  18991. memBg.asSpec(),
  18992. {
  18993. dom: {
  18994. tag: "img",
  18995. attributes: { src: initialUrl }
  18996. }
  18997. },
  18998. {
  18999. dom: { tag: "div" },
  19000. behaviours: derive$1([config("image-panel-crop-events", [
  19001. runOnAttached(function(comp) {
  19002. memContainer.getOpt(comp).each(function(container2) {
  19003. var el = container2.element.dom;
  19004. var cRect = CropRect.create({
  19005. x: 10,
  19006. y: 10,
  19007. w: 100,
  19008. h: 100
  19009. }, {
  19010. x: 0,
  19011. y: 0,
  19012. w: 200,
  19013. h: 200
  19014. }, {
  19015. x: 0,
  19016. y: 0,
  19017. w: 200,
  19018. h: 200
  19019. }, el, noop);
  19020. cRect.toggleVisibility(false);
  19021. cRect.on("updateRect", function(e) {
  19022. var rect2 = e.rect;
  19023. var zoom3 = zoomState.get();
  19024. var newRect = {
  19025. x: Math.round(rect2.x / zoom3),
  19026. y: Math.round(rect2.y / zoom3),
  19027. w: Math.round(rect2.w / zoom3),
  19028. h: Math.round(rect2.h / zoom3)
  19029. };
  19030. rectState.set(newRect);
  19031. });
  19032. cropRect.set(cRect);
  19033. });
  19034. }),
  19035. runOnDetached(function() {
  19036. cropRect.clear();
  19037. })
  19038. ])])
  19039. }
  19040. ],
  19041. containerBehaviours: derive$1([
  19042. Replacing.config({}),
  19043. config("image-panel-events", [runOnAttached(function(comp) {
  19044. updateSrc(comp, initialUrl);
  19045. })])
  19046. ])
  19047. });
  19048. var memContainer = record(container);
  19049. var getMeasurements = function() {
  19050. var viewRect = viewRectState.get();
  19051. return {
  19052. width: viewRect.w,
  19053. height: viewRect.h
  19054. };
  19055. };
  19056. return {
  19057. memContainer,
  19058. updateSrc,
  19059. zoom: zoom2,
  19060. showCrop,
  19061. hideCrop,
  19062. getRect,
  19063. getMeasurements
  19064. };
  19065. };
  19066. var createButton = function(innerHtml, icon, disabled, action, providersBackstage) {
  19067. return renderIconButton({
  19068. name: innerHtml,
  19069. icon: Optional.some(icon),
  19070. disabled,
  19071. tooltip: Optional.some(innerHtml),
  19072. primary: false,
  19073. borderless: false
  19074. }, action, providersBackstage);
  19075. };
  19076. var setButtonEnabled = function(button2, enabled) {
  19077. if (enabled) {
  19078. Disabling.enable(button2);
  19079. } else {
  19080. Disabling.disable(button2);
  19081. }
  19082. };
  19083. var renderSideBar = function(providersBackstage) {
  19084. var updateButtonUndoStates = function(anyInSystem, undoEnabled, redoEnabled) {
  19085. memUndo.getOpt(anyInSystem).each(function(undo2) {
  19086. setButtonEnabled(undo2, undoEnabled);
  19087. });
  19088. memRedo.getOpt(anyInSystem).each(function(redo2) {
  19089. setButtonEnabled(redo2, redoEnabled);
  19090. });
  19091. };
  19092. var memUndo = record(createButton("Undo", "undo", true, function(button2) {
  19093. emitWith(button2, internal.undo(), { direction: 1 });
  19094. }, providersBackstage));
  19095. var memRedo = record(createButton("Redo", "redo", true, function(button2) {
  19096. emitWith(button2, internal.redo(), { direction: 1 });
  19097. }, providersBackstage));
  19098. var container = Container.sketch({
  19099. dom: {
  19100. tag: "div",
  19101. classes: [
  19102. "tox-image-tools__toolbar",
  19103. "tox-image-tools__sidebar"
  19104. ]
  19105. },
  19106. components: [
  19107. memUndo.asSpec(),
  19108. memRedo.asSpec(),
  19109. createButton("Zoom in", "zoom-in", false, function(button2) {
  19110. emitWith(button2, internal.zoom(), { direction: 1 });
  19111. }, providersBackstage),
  19112. createButton("Zoom out", "zoom-out", false, function(button2) {
  19113. emitWith(button2, internal.zoom(), { direction: -1 });
  19114. }, providersBackstage)
  19115. ]
  19116. });
  19117. return {
  19118. container,
  19119. updateButtonUndoStates
  19120. };
  19121. };
  19122. function UndoStack() {
  19123. var data = [];
  19124. var index = -1;
  19125. var add2 = function(state) {
  19126. var removed = data.splice(++index);
  19127. data.push(state);
  19128. return {
  19129. state,
  19130. removed
  19131. };
  19132. };
  19133. var undo2 = function() {
  19134. if (canUndo()) {
  19135. return data[--index];
  19136. }
  19137. };
  19138. var redo2 = function() {
  19139. if (canRedo()) {
  19140. return data[++index];
  19141. }
  19142. };
  19143. var canUndo = function() {
  19144. return index > 0;
  19145. };
  19146. var canRedo = function() {
  19147. return index !== -1 && index < data.length - 1;
  19148. };
  19149. return {
  19150. data,
  19151. add: add2,
  19152. undo: undo2,
  19153. redo: redo2,
  19154. canUndo,
  19155. canRedo
  19156. };
  19157. }
  19158. var makeState = function(initialState) {
  19159. var blobState = Cell(initialState);
  19160. var tempState = value$1();
  19161. var undoStack = UndoStack();
  19162. undoStack.add(initialState);
  19163. var getBlobState = function() {
  19164. return blobState.get();
  19165. };
  19166. var setBlobState = function(state) {
  19167. blobState.set(state);
  19168. };
  19169. var getTempState = function() {
  19170. return tempState.get().getOrThunk(blobState.get);
  19171. };
  19172. var updateTempState = function(blob) {
  19173. var newTempState = createState(blob);
  19174. destroyTempState();
  19175. tempState.set(newTempState);
  19176. return newTempState.url;
  19177. };
  19178. var createState = function(blob) {
  19179. return {
  19180. blob,
  19181. url: URL.createObjectURL(blob)
  19182. };
  19183. };
  19184. var destroyState = function(state) {
  19185. URL.revokeObjectURL(state.url);
  19186. };
  19187. var destroyStates = function(states) {
  19188. global$5.each(states, destroyState);
  19189. };
  19190. var destroyTempState = function() {
  19191. tempState.on(destroyState);
  19192. tempState.clear();
  19193. };
  19194. var addBlobState = function(blob) {
  19195. var newState = createState(blob);
  19196. setBlobState(newState);
  19197. var removed = undoStack.add(newState).removed;
  19198. destroyStates(removed);
  19199. return newState.url;
  19200. };
  19201. var addTempState = function(blob) {
  19202. var newState = createState(blob);
  19203. tempState.set(newState);
  19204. return newState.url;
  19205. };
  19206. var applyTempState = function(postApply) {
  19207. return tempState.get().fold(noop, function(temp) {
  19208. addBlobState(temp.blob);
  19209. postApply();
  19210. });
  19211. };
  19212. var undo2 = function() {
  19213. var currentState = undoStack.undo();
  19214. setBlobState(currentState);
  19215. return currentState.url;
  19216. };
  19217. var redo2 = function() {
  19218. var currentState = undoStack.redo();
  19219. setBlobState(currentState);
  19220. return currentState.url;
  19221. };
  19222. var getHistoryStates = function() {
  19223. var undoEnabled = undoStack.canUndo();
  19224. var redoEnabled = undoStack.canRedo();
  19225. return {
  19226. undoEnabled,
  19227. redoEnabled
  19228. };
  19229. };
  19230. return {
  19231. getBlobState,
  19232. setBlobState,
  19233. addBlobState,
  19234. getTempState,
  19235. updateTempState,
  19236. addTempState,
  19237. applyTempState,
  19238. destroyTempState,
  19239. undo: undo2,
  19240. redo: redo2,
  19241. getHistoryStates
  19242. };
  19243. };
  19244. var renderImageTools = function(detail, providersBackstage) {
  19245. var state = makeState(detail.currentState);
  19246. var zoom2 = function(anyInSystem, simulatedEvent) {
  19247. var direction = simulatedEvent.event.direction;
  19248. imagePanel.zoom(anyInSystem, direction);
  19249. };
  19250. var updateButtonUndoStates = function(anyInSystem) {
  19251. var historyStates = state.getHistoryStates();
  19252. sideBar.updateButtonUndoStates(anyInSystem, historyStates.undoEnabled, historyStates.redoEnabled);
  19253. emitWith(anyInSystem, external.formActionEvent, {
  19254. name: external.saveState(),
  19255. value: historyStates.undoEnabled
  19256. });
  19257. };
  19258. var disableUndoRedo = function(anyInSystem) {
  19259. sideBar.updateButtonUndoStates(anyInSystem, false, false);
  19260. };
  19261. var undo2 = function(anyInSystem, _simulatedEvent) {
  19262. var url = state.undo();
  19263. updateSrc(anyInSystem, url).then(function(_oImg) {
  19264. unblock2(anyInSystem);
  19265. updateButtonUndoStates(anyInSystem);
  19266. });
  19267. };
  19268. var redo2 = function(anyInSystem, _simulatedEvent) {
  19269. var url = state.redo();
  19270. updateSrc(anyInSystem, url).then(function(_oImg) {
  19271. unblock2(anyInSystem);
  19272. updateButtonUndoStates(anyInSystem);
  19273. });
  19274. };
  19275. var imageResultToBlob = function(ir) {
  19276. return ir.toBlob();
  19277. };
  19278. var block2 = function(anyInSystem) {
  19279. emitWith(anyInSystem, external.formActionEvent, {
  19280. name: external.disable(),
  19281. value: {}
  19282. });
  19283. };
  19284. var unblock2 = function(anyInSystem) {
  19285. editPanel.getApplyButton(anyInSystem).each(function(applyButton) {
  19286. Disabling.enable(applyButton);
  19287. });
  19288. emitWith(anyInSystem, external.formActionEvent, {
  19289. name: external.enable(),
  19290. value: {}
  19291. });
  19292. };
  19293. var updateSrc = function(anyInSystem, src) {
  19294. block2(anyInSystem);
  19295. return imagePanel.updateSrc(anyInSystem, src);
  19296. };
  19297. var blobManipulate = function(anyInSystem, blob, filter2, action, swap3) {
  19298. block2(anyInSystem);
  19299. blobToImageResult(blob).then(filter2).then(imageResultToBlob).then(action).then(function(url) {
  19300. return updateSrc(anyInSystem, url);
  19301. }).then(function() {
  19302. updateButtonUndoStates(anyInSystem);
  19303. swap3();
  19304. unblock2(anyInSystem);
  19305. }).catch(function(err) {
  19306. console.log(err);
  19307. if (anyInSystem.getSystem().isConnected()) {
  19308. unblock2(anyInSystem);
  19309. }
  19310. });
  19311. };
  19312. var manipulate = function(anyInSystem, filter2, swap3) {
  19313. var blob = state.getBlobState().blob;
  19314. var action = function(blob2) {
  19315. return state.updateTempState(blob2);
  19316. };
  19317. blobManipulate(anyInSystem, blob, filter2, action, swap3);
  19318. };
  19319. var tempManipulate = function(anyInSystem, filter2) {
  19320. var blob = state.getTempState().blob;
  19321. var action = function(blob2) {
  19322. return state.addTempState(blob2);
  19323. };
  19324. blobManipulate(anyInSystem, blob, filter2, action, noop);
  19325. };
  19326. var manipulateApply = function(anyInSystem, filter2, swap3) {
  19327. var blob = state.getBlobState().blob;
  19328. var action = function(blob2) {
  19329. var url = state.addBlobState(blob2);
  19330. destroyTempState(anyInSystem);
  19331. return url;
  19332. };
  19333. blobManipulate(anyInSystem, blob, filter2, action, swap3);
  19334. };
  19335. var apply2 = function(anyInSystem, simulatedEvent) {
  19336. var postApply = function() {
  19337. destroyTempState(anyInSystem);
  19338. var swap3 = simulatedEvent.event.swap;
  19339. swap3();
  19340. };
  19341. state.applyTempState(postApply);
  19342. };
  19343. var destroyTempState = function(anyInSystem) {
  19344. var currentUrl = state.getBlobState().url;
  19345. state.destroyTempState();
  19346. updateButtonUndoStates(anyInSystem);
  19347. return currentUrl;
  19348. };
  19349. var cancel = function(anyInSystem) {
  19350. var currentUrl = destroyTempState(anyInSystem);
  19351. updateSrc(anyInSystem, currentUrl).then(function(_oImg) {
  19352. unblock2(anyInSystem);
  19353. });
  19354. };
  19355. var back2 = function(anyInSystem, simulatedEvent) {
  19356. cancel(anyInSystem);
  19357. var swap3 = simulatedEvent.event.swap;
  19358. swap3();
  19359. imagePanel.hideCrop();
  19360. };
  19361. var transform2 = function(anyInSystem, simulatedEvent) {
  19362. return manipulate(anyInSystem, simulatedEvent.event.transform, noop);
  19363. };
  19364. var tempTransform2 = function(anyInSystem, simulatedEvent) {
  19365. return tempManipulate(anyInSystem, simulatedEvent.event.transform);
  19366. };
  19367. var transformApply2 = function(anyInSystem, simulatedEvent) {
  19368. return manipulateApply(anyInSystem, simulatedEvent.event.transform, simulatedEvent.event.swap);
  19369. };
  19370. var imagePanel = renderImagePanel(detail.currentState.url);
  19371. var sideBar = renderSideBar(providersBackstage);
  19372. var editPanel = renderEditPanel(imagePanel, providersBackstage);
  19373. var swap2 = function(anyInSystem, simulatedEvent) {
  19374. disableUndoRedo(anyInSystem);
  19375. var transform3 = simulatedEvent.event.transform;
  19376. var swap3 = simulatedEvent.event.swap;
  19377. transform3.fold(function() {
  19378. swap3();
  19379. }, function(transform4) {
  19380. manipulate(anyInSystem, transform4, swap3);
  19381. });
  19382. };
  19383. return {
  19384. dom: {
  19385. tag: "div",
  19386. attributes: { role: "presentation" }
  19387. },
  19388. components: [
  19389. editPanel.memContainer.asSpec(),
  19390. imagePanel.memContainer.asSpec(),
  19391. sideBar.container
  19392. ],
  19393. behaviours: derive$1([
  19394. Representing.config({
  19395. store: {
  19396. mode: "manual",
  19397. getValue: function() {
  19398. return state.getBlobState();
  19399. }
  19400. }
  19401. }),
  19402. config("image-tools-events", [
  19403. run$1(internal.undo(), undo2),
  19404. run$1(internal.redo(), redo2),
  19405. run$1(internal.zoom(), zoom2),
  19406. run$1(internal.back(), back2),
  19407. run$1(internal.apply(), apply2),
  19408. run$1(internal.transform(), transform2),
  19409. run$1(internal.tempTransform(), tempTransform2),
  19410. run$1(internal.transformApply(), transformApply2),
  19411. run$1(internal.swap(), swap2)
  19412. ]),
  19413. ComposingConfigs.self()
  19414. ])
  19415. };
  19416. };
  19417. var renderLabel = function(spec, backstageShared) {
  19418. var label = {
  19419. dom: {
  19420. tag: "label",
  19421. innerHtml: backstageShared.providers.translate(spec.label),
  19422. classes: ["tox-label"]
  19423. }
  19424. };
  19425. var comps = map$2(spec.items, backstageShared.interpreter);
  19426. return {
  19427. dom: {
  19428. tag: "div",
  19429. classes: ["tox-form__group"]
  19430. },
  19431. components: [label].concat(comps),
  19432. behaviours: derive$1([
  19433. ComposingConfigs.self(),
  19434. Replacing.config({}),
  19435. RepresentingConfigs.domHtml(Optional.none()),
  19436. Keying.config({ mode: "acyclic" })
  19437. ])
  19438. };
  19439. };
  19440. var isSingleListItem = function(item2) {
  19441. return !has$2(item2, "items");
  19442. };
  19443. var dataAttribute = "data-value";
  19444. var fetchItems = function(dropdownComp, name2, items, selectedValue) {
  19445. return map$2(items, function(item2) {
  19446. if (!isSingleListItem(item2)) {
  19447. return {
  19448. type: "nestedmenuitem",
  19449. text: item2.text,
  19450. getSubmenuItems: function() {
  19451. return fetchItems(dropdownComp, name2, item2.items, selectedValue);
  19452. }
  19453. };
  19454. } else {
  19455. return {
  19456. type: "togglemenuitem",
  19457. text: item2.text,
  19458. value: item2.value,
  19459. active: item2.value === selectedValue,
  19460. onAction: function() {
  19461. Representing.setValue(dropdownComp, item2.value);
  19462. emitWith(dropdownComp, formChangeEvent, { name: name2 });
  19463. Focusing.focus(dropdownComp);
  19464. }
  19465. };
  19466. }
  19467. });
  19468. };
  19469. var findItemByValue = function(items, value2) {
  19470. return findMap(items, function(item2) {
  19471. if (!isSingleListItem(item2)) {
  19472. return findItemByValue(item2.items, value2);
  19473. } else {
  19474. return someIf(item2.value === value2, item2);
  19475. }
  19476. });
  19477. };
  19478. var renderListBox = function(spec, backstage) {
  19479. var providersBackstage = backstage.shared.providers;
  19480. var initialItem = head(spec.items).filter(isSingleListItem);
  19481. var pLabel = spec.label.map(function(label) {
  19482. return renderLabel$2(label, providersBackstage);
  19483. });
  19484. var pField = FormField.parts.field({
  19485. dom: {},
  19486. factory: {
  19487. sketch: function(sketchSpec) {
  19488. return renderCommonDropdown({
  19489. uid: sketchSpec.uid,
  19490. text: initialItem.map(function(item2) {
  19491. return item2.text;
  19492. }),
  19493. icon: Optional.none(),
  19494. tooltip: spec.label,
  19495. role: Optional.none(),
  19496. fetch: function(comp, callback) {
  19497. var items = fetchItems(comp, spec.name, spec.items, Representing.getValue(comp));
  19498. callback(build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false));
  19499. },
  19500. onSetup: constant$1(noop),
  19501. getApi: constant$1({}),
  19502. columns: 1,
  19503. presets: "normal",
  19504. classes: [],
  19505. dropdownBehaviours: [
  19506. Tabstopping.config({}),
  19507. Representing.config({
  19508. store: {
  19509. mode: "manual",
  19510. initialValue: initialItem.map(function(item2) {
  19511. return item2.value;
  19512. }).getOr(""),
  19513. getValue: function(comp) {
  19514. return get$d(comp.element, dataAttribute);
  19515. },
  19516. setValue: function(comp, data) {
  19517. findItemByValue(spec.items, data).each(function(item2) {
  19518. set$8(comp.element, dataAttribute, item2.value);
  19519. emitWith(comp, updateMenuText, { text: item2.text });
  19520. });
  19521. }
  19522. }
  19523. })
  19524. ]
  19525. }, "tox-listbox", backstage.shared);
  19526. }
  19527. }
  19528. });
  19529. var listBoxWrap = {
  19530. dom: {
  19531. tag: "div",
  19532. classes: ["tox-listboxfield"]
  19533. },
  19534. components: [pField]
  19535. };
  19536. return FormField.sketch({
  19537. dom: {
  19538. tag: "div",
  19539. classes: ["tox-form__group"]
  19540. },
  19541. components: flatten([
  19542. pLabel.toArray(),
  19543. [listBoxWrap]
  19544. ]),
  19545. fieldBehaviours: derive$1([Disabling.config({
  19546. disabled: constant$1(spec.disabled),
  19547. onDisabled: function(comp) {
  19548. FormField.getField(comp).each(Disabling.disable);
  19549. },
  19550. onEnabled: function(comp) {
  19551. FormField.getField(comp).each(Disabling.enable);
  19552. }
  19553. })])
  19554. });
  19555. };
  19556. var renderPanel = function(spec, backstage) {
  19557. return {
  19558. dom: {
  19559. tag: "div",
  19560. classes: spec.classes
  19561. },
  19562. components: map$2(spec.items, backstage.shared.interpreter)
  19563. };
  19564. };
  19565. var factory$e = function(detail, _spec) {
  19566. var options = map$2(detail.options, function(option2) {
  19567. return {
  19568. dom: {
  19569. tag: "option",
  19570. value: option2.value,
  19571. innerHtml: option2.text
  19572. }
  19573. };
  19574. });
  19575. var initialValues = detail.data.map(function(v) {
  19576. return wrap$1("initialValue", v);
  19577. }).getOr({});
  19578. return {
  19579. uid: detail.uid,
  19580. dom: {
  19581. tag: "select",
  19582. classes: detail.selectClasses,
  19583. attributes: detail.selectAttributes
  19584. },
  19585. components: options,
  19586. behaviours: augment(detail.selectBehaviours, [
  19587. Focusing.config({}),
  19588. Representing.config({
  19589. store: __assign({
  19590. mode: "manual",
  19591. getValue: function(select2) {
  19592. return get$5(select2.element);
  19593. },
  19594. setValue: function(select2, newValue) {
  19595. var found = find$5(detail.options, function(opt) {
  19596. return opt.value === newValue;
  19597. });
  19598. if (found.isSome()) {
  19599. set$4(select2.element, newValue);
  19600. }
  19601. }
  19602. }, initialValues)
  19603. })
  19604. ])
  19605. };
  19606. };
  19607. var HtmlSelect = single({
  19608. name: "HtmlSelect",
  19609. configFields: [
  19610. required$1("options"),
  19611. field("selectBehaviours", [
  19612. Focusing,
  19613. Representing
  19614. ]),
  19615. defaulted("selectClasses", []),
  19616. defaulted("selectAttributes", {}),
  19617. option("data")
  19618. ],
  19619. factory: factory$e
  19620. });
  19621. var renderSelectBox = function(spec, providersBackstage) {
  19622. var translatedOptions = map$2(spec.items, function(item2) {
  19623. return {
  19624. text: providersBackstage.translate(item2.text),
  19625. value: item2.value
  19626. };
  19627. });
  19628. var pLabel = spec.label.map(function(label) {
  19629. return renderLabel$2(label, providersBackstage);
  19630. });
  19631. var pField = FormField.parts.field({
  19632. dom: {},
  19633. selectAttributes: { size: spec.size },
  19634. options: translatedOptions,
  19635. factory: HtmlSelect,
  19636. selectBehaviours: derive$1([
  19637. Disabling.config({
  19638. disabled: function() {
  19639. return spec.disabled || providersBackstage.isDisabled();
  19640. }
  19641. }),
  19642. Tabstopping.config({}),
  19643. config("selectbox-change", [run$1(change(), function(component, _) {
  19644. emitWith(component, formChangeEvent, { name: spec.name });
  19645. })])
  19646. ])
  19647. });
  19648. var chevron = spec.size > 1 ? Optional.none() : Optional.some(render$3("chevron-down", {
  19649. tag: "div",
  19650. classes: ["tox-selectfield__icon-js"]
  19651. }, providersBackstage.icons));
  19652. var selectWrap = {
  19653. dom: {
  19654. tag: "div",
  19655. classes: ["tox-selectfield"]
  19656. },
  19657. components: flatten([
  19658. [pField],
  19659. chevron.toArray()
  19660. ])
  19661. };
  19662. return FormField.sketch({
  19663. dom: {
  19664. tag: "div",
  19665. classes: ["tox-form__group"]
  19666. },
  19667. components: flatten([
  19668. pLabel.toArray(),
  19669. [selectWrap]
  19670. ]),
  19671. fieldBehaviours: derive$1([
  19672. Disabling.config({
  19673. disabled: function() {
  19674. return spec.disabled || providersBackstage.isDisabled();
  19675. },
  19676. onDisabled: function(comp) {
  19677. FormField.getField(comp).each(Disabling.disable);
  19678. },
  19679. onEnabled: function(comp) {
  19680. FormField.getField(comp).each(Disabling.enable);
  19681. }
  19682. }),
  19683. receivingConfig()
  19684. ])
  19685. });
  19686. };
  19687. var renderTable = function(spec, providersBackstage) {
  19688. var renderTh = function(text2) {
  19689. return {
  19690. dom: {
  19691. tag: "th",
  19692. innerHtml: providersBackstage.translate(text2)
  19693. }
  19694. };
  19695. };
  19696. var renderHeader2 = function(header) {
  19697. return {
  19698. dom: { tag: "thead" },
  19699. components: [{
  19700. dom: { tag: "tr" },
  19701. components: map$2(header, renderTh)
  19702. }]
  19703. };
  19704. };
  19705. var renderTd = function(text2) {
  19706. return {
  19707. dom: {
  19708. tag: "td",
  19709. innerHtml: providersBackstage.translate(text2)
  19710. }
  19711. };
  19712. };
  19713. var renderTr = function(row) {
  19714. return {
  19715. dom: { tag: "tr" },
  19716. components: map$2(row, renderTd)
  19717. };
  19718. };
  19719. var renderRows = function(rows) {
  19720. return {
  19721. dom: { tag: "tbody" },
  19722. components: map$2(rows, renderTr)
  19723. };
  19724. };
  19725. return {
  19726. dom: {
  19727. tag: "table",
  19728. classes: ["tox-dialog__table"]
  19729. },
  19730. components: [
  19731. renderHeader2(spec.header),
  19732. renderRows(spec.cells)
  19733. ],
  19734. behaviours: derive$1([
  19735. Tabstopping.config({}),
  19736. Focusing.config({})
  19737. ])
  19738. };
  19739. };
  19740. var renderTextField = function(spec, providersBackstage) {
  19741. var pLabel = spec.label.map(function(label) {
  19742. return renderLabel$2(label, providersBackstage);
  19743. });
  19744. var baseInputBehaviours = [
  19745. Disabling.config({
  19746. disabled: function() {
  19747. return spec.disabled || providersBackstage.isDisabled();
  19748. }
  19749. }),
  19750. receivingConfig(),
  19751. Keying.config({
  19752. mode: "execution",
  19753. useEnter: spec.multiline !== true,
  19754. useControlEnter: spec.multiline === true,
  19755. execute: function(comp) {
  19756. emit(comp, formSubmitEvent);
  19757. return Optional.some(true);
  19758. }
  19759. }),
  19760. config("textfield-change", [
  19761. run$1(input(), function(component, _) {
  19762. emitWith(component, formChangeEvent, { name: spec.name });
  19763. }),
  19764. run$1(postPaste(), function(component, _) {
  19765. emitWith(component, formChangeEvent, { name: spec.name });
  19766. })
  19767. ]),
  19768. Tabstopping.config({})
  19769. ];
  19770. var validatingBehaviours = spec.validation.map(function(vl) {
  19771. return Invalidating.config({
  19772. getRoot: function(input2) {
  19773. return parent(input2.element);
  19774. },
  19775. invalidClass: "tox-invalid",
  19776. validator: {
  19777. validate: function(input2) {
  19778. var v = Representing.getValue(input2);
  19779. var result = vl.validator(v);
  19780. return Future.pure(result === true ? Result.value(v) : Result.error(result));
  19781. },
  19782. validateOnLoad: vl.validateOnLoad
  19783. }
  19784. });
  19785. }).toArray();
  19786. var placeholder2 = spec.placeholder.fold(constant$1({}), function(p) {
  19787. return { placeholder: providersBackstage.translate(p) };
  19788. });
  19789. var inputMode = spec.inputMode.fold(constant$1({}), function(mode) {
  19790. return { inputmode: mode };
  19791. });
  19792. var inputAttributes = __assign(__assign({}, placeholder2), inputMode);
  19793. var pField = FormField.parts.field({
  19794. tag: spec.multiline === true ? "textarea" : "input",
  19795. inputAttributes,
  19796. inputClasses: [spec.classname],
  19797. inputBehaviours: derive$1(flatten([
  19798. baseInputBehaviours,
  19799. validatingBehaviours
  19800. ])),
  19801. selectOnFocus: false,
  19802. factory: Input
  19803. });
  19804. var extraClasses = spec.flex ? ["tox-form__group--stretched"] : [];
  19805. var extraClasses2 = extraClasses.concat(spec.maximized ? ["tox-form-group--maximize"] : []);
  19806. var extraBehaviours = [
  19807. Disabling.config({
  19808. disabled: function() {
  19809. return spec.disabled || providersBackstage.isDisabled();
  19810. },
  19811. onDisabled: function(comp) {
  19812. FormField.getField(comp).each(Disabling.disable);
  19813. },
  19814. onEnabled: function(comp) {
  19815. FormField.getField(comp).each(Disabling.enable);
  19816. }
  19817. }),
  19818. receivingConfig()
  19819. ];
  19820. return renderFormFieldWith(pLabel, pField, extraClasses2, extraBehaviours);
  19821. };
  19822. var renderInput = function(spec, providersBackstage) {
  19823. return renderTextField({
  19824. name: spec.name,
  19825. multiline: false,
  19826. label: spec.label,
  19827. inputMode: spec.inputMode,
  19828. placeholder: spec.placeholder,
  19829. flex: false,
  19830. disabled: spec.disabled,
  19831. classname: "tox-textfield",
  19832. validation: Optional.none(),
  19833. maximized: spec.maximized
  19834. }, providersBackstage);
  19835. };
  19836. var renderTextarea = function(spec, providersBackstage) {
  19837. return renderTextField({
  19838. name: spec.name,
  19839. multiline: true,
  19840. label: spec.label,
  19841. inputMode: Optional.none(),
  19842. placeholder: spec.placeholder,
  19843. flex: true,
  19844. disabled: spec.disabled,
  19845. classname: "tox-textarea",
  19846. validation: Optional.none(),
  19847. maximized: spec.maximized
  19848. }, providersBackstage);
  19849. };
  19850. var events$6 = function(streamConfig, streamState) {
  19851. var streams = streamConfig.stream.streams;
  19852. var processor = streams.setup(streamConfig, streamState);
  19853. return derive$2([
  19854. run$1(streamConfig.event, processor),
  19855. runOnDetached(function() {
  19856. return streamState.cancel();
  19857. })
  19858. ].concat(streamConfig.cancelEvent.map(function(e) {
  19859. return [run$1(e, function() {
  19860. return streamState.cancel();
  19861. })];
  19862. }).getOr([])));
  19863. };
  19864. var ActiveStreaming = Object.freeze({
  19865. __proto__: null,
  19866. events: events$6
  19867. });
  19868. var throttle = function(_config) {
  19869. var state = Cell(null);
  19870. var readState = function() {
  19871. return { timer: state.get() !== null ? "set" : "unset" };
  19872. };
  19873. var setTimer = function(t2) {
  19874. state.set(t2);
  19875. };
  19876. var cancel = function() {
  19877. var t2 = state.get();
  19878. if (t2 !== null) {
  19879. t2.cancel();
  19880. }
  19881. };
  19882. return nu$8({
  19883. readState,
  19884. setTimer,
  19885. cancel
  19886. });
  19887. };
  19888. var init$9 = function(spec) {
  19889. return spec.stream.streams.state(spec);
  19890. };
  19891. var StreamingState = Object.freeze({
  19892. __proto__: null,
  19893. throttle,
  19894. init: init$9
  19895. });
  19896. var setup$c = function(streamInfo, streamState) {
  19897. var sInfo = streamInfo.stream;
  19898. var throttler = last(streamInfo.onStream, sInfo.delay);
  19899. streamState.setTimer(throttler);
  19900. return function(component, simulatedEvent) {
  19901. throttler.throttle(component, simulatedEvent);
  19902. if (sInfo.stopEvent) {
  19903. simulatedEvent.stop();
  19904. }
  19905. };
  19906. };
  19907. var StreamingSchema = [
  19908. requiredOf("stream", choose$1("mode", {
  19909. throttle: [
  19910. required$1("delay"),
  19911. defaulted("stopEvent", true),
  19912. output$1("streams", {
  19913. setup: setup$c,
  19914. state: throttle
  19915. })
  19916. ]
  19917. })),
  19918. defaulted("event", "input"),
  19919. option("cancelEvent"),
  19920. onStrictHandler("onStream")
  19921. ];
  19922. var Streaming = create$7({
  19923. fields: StreamingSchema,
  19924. name: "streaming",
  19925. active: ActiveStreaming,
  19926. state: StreamingState
  19927. });
  19928. var setValueFromItem = function(model, input2, item2) {
  19929. var itemData = Representing.getValue(item2);
  19930. Representing.setValue(input2, itemData);
  19931. setCursorAtEnd(input2);
  19932. };
  19933. var setSelectionOn = function(input2, f) {
  19934. var el = input2.element;
  19935. var value2 = get$5(el);
  19936. var node = el.dom;
  19937. if (get$d(el, "type") !== "number") {
  19938. f(node, value2);
  19939. }
  19940. };
  19941. var setCursorAtEnd = function(input2) {
  19942. setSelectionOn(input2, function(node, value2) {
  19943. return node.setSelectionRange(value2.length, value2.length);
  19944. });
  19945. };
  19946. var setSelectionToEnd = function(input2, startOffset) {
  19947. setSelectionOn(input2, function(node, value2) {
  19948. return node.setSelectionRange(startOffset, value2.length);
  19949. });
  19950. };
  19951. var attemptSelectOver = function(model, input2, item2) {
  19952. if (!model.selectsOver) {
  19953. return Optional.none();
  19954. } else {
  19955. var currentValue2 = Representing.getValue(input2);
  19956. var inputDisplay_1 = model.getDisplayText(currentValue2);
  19957. var itemValue = Representing.getValue(item2);
  19958. var itemDisplay = model.getDisplayText(itemValue);
  19959. return itemDisplay.indexOf(inputDisplay_1) === 0 ? Optional.some(function() {
  19960. setValueFromItem(model, input2, item2);
  19961. setSelectionToEnd(input2, inputDisplay_1.length);
  19962. }) : Optional.none();
  19963. }
  19964. };
  19965. var itemExecute = constant$1("alloy.typeahead.itemexecute");
  19966. var make$3 = function(detail, components2, spec, externals) {
  19967. var navigateList = function(comp, simulatedEvent, highlighter) {
  19968. detail.previewing.set(false);
  19969. var sandbox = Coupling.getCoupled(comp, "sandbox");
  19970. if (Sandboxing.isOpen(sandbox)) {
  19971. Composing.getCurrent(sandbox).each(function(menu2) {
  19972. Highlighting.getHighlighted(menu2).fold(function() {
  19973. highlighter(menu2);
  19974. }, function() {
  19975. dispatchEvent(sandbox, menu2.element, "keydown", simulatedEvent);
  19976. });
  19977. });
  19978. } else {
  19979. var onOpenSync = function(sandbox2) {
  19980. Composing.getCurrent(sandbox2).each(highlighter);
  19981. };
  19982. open(detail, mapFetch(comp), comp, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  19983. }
  19984. };
  19985. var focusBehaviours$1 = focusBehaviours(detail);
  19986. var mapFetch = function(comp) {
  19987. return function(tdata) {
  19988. return tdata.map(function(data) {
  19989. var menus = values(data.menus);
  19990. var items = bind$3(menus, function(menu2) {
  19991. return filter$2(menu2.items, function(item2) {
  19992. return item2.type === "item";
  19993. });
  19994. });
  19995. var repState = Representing.getState(comp);
  19996. repState.update(map$2(items, function(item2) {
  19997. return item2.data;
  19998. }));
  19999. return data;
  20000. });
  20001. };
  20002. };
  20003. var behaviours2 = [
  20004. Focusing.config({}),
  20005. Representing.config({
  20006. onSetValue: detail.onSetValue,
  20007. store: __assign({
  20008. mode: "dataset",
  20009. getDataKey: function(comp) {
  20010. return get$5(comp.element);
  20011. },
  20012. getFallbackEntry: function(itemString) {
  20013. return {
  20014. value: itemString,
  20015. meta: {}
  20016. };
  20017. },
  20018. setValue: function(comp, data) {
  20019. set$4(comp.element, detail.model.getDisplayText(data));
  20020. }
  20021. }, detail.initialData.map(function(d) {
  20022. return wrap$1("initialValue", d);
  20023. }).getOr({}))
  20024. }),
  20025. Streaming.config({
  20026. stream: {
  20027. mode: "throttle",
  20028. delay: detail.responseTime,
  20029. stopEvent: false
  20030. },
  20031. onStream: function(component, _simulatedEvent) {
  20032. var sandbox = Coupling.getCoupled(component, "sandbox");
  20033. var focusInInput = Focusing.isFocused(component);
  20034. if (focusInInput) {
  20035. if (get$5(component.element).length >= detail.minChars) {
  20036. var previousValue_1 = Composing.getCurrent(sandbox).bind(function(menu2) {
  20037. return Highlighting.getHighlighted(menu2).map(Representing.getValue);
  20038. });
  20039. detail.previewing.set(true);
  20040. var onOpenSync = function(_sandbox) {
  20041. Composing.getCurrent(sandbox).each(function(menu2) {
  20042. previousValue_1.fold(function() {
  20043. if (detail.model.selectsOver) {
  20044. Highlighting.highlightFirst(menu2);
  20045. }
  20046. }, function(pv) {
  20047. Highlighting.highlightBy(menu2, function(item2) {
  20048. var itemData = Representing.getValue(item2);
  20049. return itemData.value === pv.value;
  20050. });
  20051. Highlighting.getHighlighted(menu2).orThunk(function() {
  20052. Highlighting.highlightFirst(menu2);
  20053. return Optional.none();
  20054. });
  20055. });
  20056. });
  20057. };
  20058. open(detail, mapFetch(component), component, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  20059. }
  20060. }
  20061. },
  20062. cancelEvent: typeaheadCancel()
  20063. }),
  20064. Keying.config({
  20065. mode: "special",
  20066. onDown: function(comp, simulatedEvent) {
  20067. navigateList(comp, simulatedEvent, Highlighting.highlightFirst);
  20068. return Optional.some(true);
  20069. },
  20070. onEscape: function(comp) {
  20071. var sandbox = Coupling.getCoupled(comp, "sandbox");
  20072. if (Sandboxing.isOpen(sandbox)) {
  20073. Sandboxing.close(sandbox);
  20074. return Optional.some(true);
  20075. }
  20076. return Optional.none();
  20077. },
  20078. onUp: function(comp, simulatedEvent) {
  20079. navigateList(comp, simulatedEvent, Highlighting.highlightLast);
  20080. return Optional.some(true);
  20081. },
  20082. onEnter: function(comp) {
  20083. var sandbox = Coupling.getCoupled(comp, "sandbox");
  20084. var sandboxIsOpen = Sandboxing.isOpen(sandbox);
  20085. if (sandboxIsOpen && !detail.previewing.get()) {
  20086. return Composing.getCurrent(sandbox).bind(function(menu2) {
  20087. return Highlighting.getHighlighted(menu2);
  20088. }).map(function(item2) {
  20089. emitWith(comp, itemExecute(), { item: item2 });
  20090. return true;
  20091. });
  20092. } else {
  20093. var currentValue2 = Representing.getValue(comp);
  20094. emit(comp, typeaheadCancel());
  20095. detail.onExecute(sandbox, comp, currentValue2);
  20096. if (sandboxIsOpen) {
  20097. Sandboxing.close(sandbox);
  20098. }
  20099. return Optional.some(true);
  20100. }
  20101. }
  20102. }),
  20103. Toggling.config({
  20104. toggleClass: detail.markers.openClass,
  20105. aria: { mode: "expanded" }
  20106. }),
  20107. Coupling.config({
  20108. others: {
  20109. sandbox: function(hotspot) {
  20110. return makeSandbox$1(detail, hotspot, {
  20111. onOpen: function() {
  20112. return Toggling.on(hotspot);
  20113. },
  20114. onClose: function() {
  20115. return Toggling.off(hotspot);
  20116. }
  20117. });
  20118. }
  20119. }
  20120. }),
  20121. config("typeaheadevents", [
  20122. runOnExecute$1(function(comp) {
  20123. var onOpenSync = noop;
  20124. togglePopup(detail, mapFetch(comp), comp, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  20125. }),
  20126. run$1(itemExecute(), function(comp, se) {
  20127. var sandbox = Coupling.getCoupled(comp, "sandbox");
  20128. setValueFromItem(detail.model, comp, se.event.item);
  20129. emit(comp, typeaheadCancel());
  20130. detail.onItemExecute(comp, sandbox, se.event.item, Representing.getValue(comp));
  20131. Sandboxing.close(sandbox);
  20132. setCursorAtEnd(comp);
  20133. })
  20134. ].concat(detail.dismissOnBlur ? [run$1(postBlur(), function(typeahead) {
  20135. var sandbox = Coupling.getCoupled(typeahead, "sandbox");
  20136. if (search(sandbox.element).isNone()) {
  20137. Sandboxing.close(sandbox);
  20138. }
  20139. })] : []))
  20140. ];
  20141. return {
  20142. uid: detail.uid,
  20143. dom: dom(deepMerge(detail, {
  20144. inputAttributes: {
  20145. "role": "combobox",
  20146. "aria-autocomplete": "list",
  20147. "aria-haspopup": "true"
  20148. }
  20149. })),
  20150. behaviours: __assign(__assign({}, focusBehaviours$1), augment(detail.typeaheadBehaviours, behaviours2)),
  20151. eventOrder: detail.eventOrder
  20152. };
  20153. };
  20154. var schema$g = constant$1([
  20155. option("lazySink"),
  20156. required$1("fetch"),
  20157. defaulted("minChars", 5),
  20158. defaulted("responseTime", 1e3),
  20159. onHandler("onOpen"),
  20160. defaulted("getHotspot", Optional.some),
  20161. defaulted("getAnchorOverrides", constant$1({})),
  20162. defaulted("layouts", Optional.none()),
  20163. defaulted("eventOrder", {}),
  20164. defaultedObjOf("model", {}, [
  20165. defaulted("getDisplayText", function(itemData) {
  20166. return itemData.meta !== void 0 && itemData.meta.text !== void 0 ? itemData.meta.text : itemData.value;
  20167. }),
  20168. defaulted("selectsOver", true),
  20169. defaulted("populateFromBrowse", true)
  20170. ]),
  20171. onHandler("onSetValue"),
  20172. onKeyboardHandler("onExecute"),
  20173. onHandler("onItemExecute"),
  20174. defaulted("inputClasses", []),
  20175. defaulted("inputAttributes", {}),
  20176. defaulted("inputStyles", {}),
  20177. defaulted("matchWidth", true),
  20178. defaulted("useMinWidth", false),
  20179. defaulted("dismissOnBlur", true),
  20180. markers$1(["openClass"]),
  20181. option("initialData"),
  20182. field("typeaheadBehaviours", [
  20183. Focusing,
  20184. Representing,
  20185. Streaming,
  20186. Keying,
  20187. Toggling,
  20188. Coupling
  20189. ]),
  20190. customField("previewing", function() {
  20191. return Cell(true);
  20192. })
  20193. ].concat(schema$k()).concat(sandboxFields()));
  20194. var parts$b = constant$1([external$1({
  20195. schema: [tieredMenuMarkers()],
  20196. name: "menu",
  20197. overrides: function(detail) {
  20198. return {
  20199. fakeFocus: true,
  20200. onHighlight: function(menu2, item2) {
  20201. if (!detail.previewing.get()) {
  20202. menu2.getSystem().getByUid(detail.uid).each(function(input2) {
  20203. if (detail.model.populateFromBrowse) {
  20204. setValueFromItem(detail.model, input2, item2);
  20205. }
  20206. });
  20207. } else {
  20208. menu2.getSystem().getByUid(detail.uid).each(function(input2) {
  20209. attemptSelectOver(detail.model, input2, item2).fold(function() {
  20210. return Highlighting.dehighlight(menu2, item2);
  20211. }, function(fn) {
  20212. return fn();
  20213. });
  20214. });
  20215. }
  20216. detail.previewing.set(false);
  20217. },
  20218. onExecute: function(menu2, item2) {
  20219. return menu2.getSystem().getByUid(detail.uid).toOptional().map(function(typeahead) {
  20220. emitWith(typeahead, itemExecute(), { item: item2 });
  20221. return true;
  20222. });
  20223. },
  20224. onHover: function(menu2, item2) {
  20225. detail.previewing.set(false);
  20226. menu2.getSystem().getByUid(detail.uid).each(function(input2) {
  20227. if (detail.model.populateFromBrowse) {
  20228. setValueFromItem(detail.model, input2, item2);
  20229. }
  20230. });
  20231. }
  20232. };
  20233. }
  20234. })]);
  20235. var Typeahead = composite({
  20236. name: "Typeahead",
  20237. configFields: schema$g(),
  20238. partFields: parts$b(),
  20239. factory: make$3
  20240. });
  20241. var wrap = function(delegate) {
  20242. var toCached = function() {
  20243. return wrap(delegate.toCached());
  20244. };
  20245. var bindFuture = function(f) {
  20246. return wrap(delegate.bind(function(resA) {
  20247. return resA.fold(function(err) {
  20248. return Future.pure(Result.error(err));
  20249. }, function(a) {
  20250. return f(a);
  20251. });
  20252. }));
  20253. };
  20254. var bindResult = function(f) {
  20255. return wrap(delegate.map(function(resA) {
  20256. return resA.bind(f);
  20257. }));
  20258. };
  20259. var mapResult = function(f) {
  20260. return wrap(delegate.map(function(resA) {
  20261. return resA.map(f);
  20262. }));
  20263. };
  20264. var mapError2 = function(f) {
  20265. return wrap(delegate.map(function(resA) {
  20266. return resA.mapError(f);
  20267. }));
  20268. };
  20269. var foldResult = function(whenError, whenValue) {
  20270. return delegate.map(function(res) {
  20271. return res.fold(whenError, whenValue);
  20272. });
  20273. };
  20274. var withTimeout = function(timeout, errorThunk) {
  20275. return wrap(Future.nu(function(callback) {
  20276. var timedOut = false;
  20277. var timer = setTimeout(function() {
  20278. timedOut = true;
  20279. callback(Result.error(errorThunk()));
  20280. }, timeout);
  20281. delegate.get(function(result) {
  20282. if (!timedOut) {
  20283. clearTimeout(timer);
  20284. callback(result);
  20285. }
  20286. });
  20287. }));
  20288. };
  20289. return __assign(__assign({}, delegate), {
  20290. toCached,
  20291. bindFuture,
  20292. bindResult,
  20293. mapResult,
  20294. mapError: mapError2,
  20295. foldResult,
  20296. withTimeout
  20297. });
  20298. };
  20299. var nu$1 = function(worker) {
  20300. return wrap(Future.nu(worker));
  20301. };
  20302. var value = function(value2) {
  20303. return wrap(Future.pure(Result.value(value2)));
  20304. };
  20305. var error = function(error2) {
  20306. return wrap(Future.pure(Result.error(error2)));
  20307. };
  20308. var fromResult = function(result) {
  20309. return wrap(Future.pure(result));
  20310. };
  20311. var fromFuture = function(future) {
  20312. return wrap(future.map(Result.value));
  20313. };
  20314. var fromPromise = function(promise) {
  20315. return nu$1(function(completer) {
  20316. promise.then(function(value2) {
  20317. completer(Result.value(value2));
  20318. }, function(error2) {
  20319. completer(Result.error(error2));
  20320. });
  20321. });
  20322. };
  20323. var FutureResult = {
  20324. nu: nu$1,
  20325. wrap,
  20326. pure: value,
  20327. value,
  20328. error,
  20329. fromResult,
  20330. fromFuture,
  20331. fromPromise
  20332. };
  20333. var separator$1 = { type: "separator" };
  20334. var toMenuItem = function(target) {
  20335. return {
  20336. type: "menuitem",
  20337. value: target.url,
  20338. text: target.title,
  20339. meta: { attach: target.attach },
  20340. onAction: noop
  20341. };
  20342. };
  20343. var staticMenuItem = function(title, url) {
  20344. return {
  20345. type: "menuitem",
  20346. value: url,
  20347. text: title,
  20348. meta: { attach: void 0 },
  20349. onAction: noop
  20350. };
  20351. };
  20352. var toMenuItems = function(targets) {
  20353. return map$2(targets, toMenuItem);
  20354. };
  20355. var filterLinkTargets = function(type2, targets) {
  20356. return filter$2(targets, function(target) {
  20357. return target.type === type2;
  20358. });
  20359. };
  20360. var filteredTargets = function(type2, targets) {
  20361. return toMenuItems(filterLinkTargets(type2, targets));
  20362. };
  20363. var headerTargets = function(linkInfo) {
  20364. return filteredTargets("header", linkInfo.targets);
  20365. };
  20366. var anchorTargets = function(linkInfo) {
  20367. return filteredTargets("anchor", linkInfo.targets);
  20368. };
  20369. var anchorTargetTop = function(linkInfo) {
  20370. return Optional.from(linkInfo.anchorTop).map(function(url) {
  20371. return staticMenuItem("<top>", url);
  20372. }).toArray();
  20373. };
  20374. var anchorTargetBottom = function(linkInfo) {
  20375. return Optional.from(linkInfo.anchorBottom).map(function(url) {
  20376. return staticMenuItem("<bottom>", url);
  20377. }).toArray();
  20378. };
  20379. var historyTargets = function(history) {
  20380. return map$2(history, function(url) {
  20381. return staticMenuItem(url, url);
  20382. });
  20383. };
  20384. var joinMenuLists = function(items) {
  20385. return foldl(items, function(a, b2) {
  20386. var bothEmpty = a.length === 0 || b2.length === 0;
  20387. return bothEmpty ? a.concat(b2) : a.concat(separator$1, b2);
  20388. }, []);
  20389. };
  20390. var filterByQuery = function(term, menuItems) {
  20391. var lowerCaseTerm = term.toLowerCase();
  20392. return filter$2(menuItems, function(item2) {
  20393. var text2 = item2.meta !== void 0 && item2.meta.text !== void 0 ? item2.meta.text : item2.text;
  20394. return contains$1(text2.toLowerCase(), lowerCaseTerm) || contains$1(item2.value.toLowerCase(), lowerCaseTerm);
  20395. });
  20396. };
  20397. var getItems = function(fileType, input2, urlBackstage) {
  20398. var urlInputValue = Representing.getValue(input2);
  20399. var term = urlInputValue.meta.text !== void 0 ? urlInputValue.meta.text : urlInputValue.value;
  20400. var info = urlBackstage.getLinkInformation();
  20401. return info.fold(function() {
  20402. return [];
  20403. }, function(linkInfo) {
  20404. var history = filterByQuery(term, historyTargets(urlBackstage.getHistory(fileType)));
  20405. return fileType === "file" ? joinMenuLists([
  20406. history,
  20407. filterByQuery(term, headerTargets(linkInfo)),
  20408. filterByQuery(term, flatten([
  20409. anchorTargetTop(linkInfo),
  20410. anchorTargets(linkInfo),
  20411. anchorTargetBottom(linkInfo)
  20412. ]))
  20413. ]) : history;
  20414. });
  20415. };
  20416. var errorId = generate$6("aria-invalid");
  20417. var renderUrlInput = function(spec, backstage, urlBackstage) {
  20418. var _a2;
  20419. var providersBackstage = backstage.shared.providers;
  20420. var updateHistory = function(component) {
  20421. var urlEntry = Representing.getValue(component);
  20422. urlBackstage.addToHistory(urlEntry.value, spec.filetype);
  20423. };
  20424. var pField = FormField.parts.field({
  20425. factory: Typeahead,
  20426. dismissOnBlur: true,
  20427. inputClasses: ["tox-textfield"],
  20428. sandboxClasses: ["tox-dialog__popups"],
  20429. inputAttributes: {
  20430. "aria-errormessage": errorId,
  20431. "type": "url"
  20432. },
  20433. minChars: 0,
  20434. responseTime: 0,
  20435. fetch: function(input2) {
  20436. var items = getItems(spec.filetype, input2, urlBackstage);
  20437. var tdata = build(items, ItemResponse$1.BUBBLE_TO_SANDBOX, backstage, false);
  20438. return Future.pure(tdata);
  20439. },
  20440. getHotspot: function(comp) {
  20441. return memUrlBox.getOpt(comp);
  20442. },
  20443. onSetValue: function(comp, _newValue) {
  20444. if (comp.hasConfigured(Invalidating)) {
  20445. Invalidating.run(comp).get(noop);
  20446. }
  20447. },
  20448. typeaheadBehaviours: derive$1(flatten([
  20449. urlBackstage.getValidationHandler().map(function(handler) {
  20450. return Invalidating.config({
  20451. getRoot: function(comp) {
  20452. return parent(comp.element);
  20453. },
  20454. invalidClass: "tox-control-wrap--status-invalid",
  20455. notify: {
  20456. onInvalid: function(comp, err) {
  20457. memInvalidIcon.getOpt(comp).each(function(invalidComp) {
  20458. set$8(invalidComp.element, "title", providersBackstage.translate(err));
  20459. });
  20460. }
  20461. },
  20462. validator: {
  20463. validate: function(input2) {
  20464. var urlEntry = Representing.getValue(input2);
  20465. return FutureResult.nu(function(completer) {
  20466. handler({
  20467. type: spec.filetype,
  20468. url: urlEntry.value
  20469. }, function(validation) {
  20470. if (validation.status === "invalid") {
  20471. var err = Result.error(validation.message);
  20472. completer(err);
  20473. } else {
  20474. var val = Result.value(validation.message);
  20475. completer(val);
  20476. }
  20477. });
  20478. });
  20479. },
  20480. validateOnLoad: false
  20481. }
  20482. });
  20483. }).toArray(),
  20484. [
  20485. Disabling.config({
  20486. disabled: function() {
  20487. return spec.disabled || providersBackstage.isDisabled();
  20488. }
  20489. }),
  20490. Tabstopping.config({}),
  20491. config("urlinput-events", flatten([
  20492. spec.filetype === "file" ? [run$1(input(), function(comp) {
  20493. emitWith(comp, formChangeEvent, { name: spec.name });
  20494. })] : [],
  20495. [
  20496. run$1(change(), function(comp) {
  20497. emitWith(comp, formChangeEvent, { name: spec.name });
  20498. updateHistory(comp);
  20499. }),
  20500. run$1(postPaste(), function(comp) {
  20501. emitWith(comp, formChangeEvent, { name: spec.name });
  20502. updateHistory(comp);
  20503. })
  20504. ]
  20505. ]))
  20506. ]
  20507. ])),
  20508. eventOrder: (_a2 = {}, _a2[input()] = [
  20509. "streaming",
  20510. "urlinput-events",
  20511. "invalidating"
  20512. ], _a2),
  20513. model: {
  20514. getDisplayText: function(itemData) {
  20515. return itemData.value;
  20516. },
  20517. selectsOver: false,
  20518. populateFromBrowse: false
  20519. },
  20520. markers: { openClass: "tox-textfield--popup-open" },
  20521. lazySink: backstage.shared.getSink,
  20522. parts: { menu: part(false, 1, "normal") },
  20523. onExecute: function(_menu, component, _entry) {
  20524. emitWith(component, formSubmitEvent, {});
  20525. },
  20526. onItemExecute: function(typeahead, _sandbox, _item, _value) {
  20527. updateHistory(typeahead);
  20528. emitWith(typeahead, formChangeEvent, { name: spec.name });
  20529. }
  20530. });
  20531. var pLabel = spec.label.map(function(label) {
  20532. return renderLabel$2(label, providersBackstage);
  20533. });
  20534. var makeIcon = function(name2, errId, icon, label) {
  20535. if (icon === void 0) {
  20536. icon = name2;
  20537. }
  20538. if (label === void 0) {
  20539. label = name2;
  20540. }
  20541. return render$3(icon, {
  20542. tag: "div",
  20543. classes: [
  20544. "tox-icon",
  20545. "tox-control-wrap__status-icon-" + name2
  20546. ],
  20547. attributes: __assign({
  20548. "title": providersBackstage.translate(label),
  20549. "aria-live": "polite"
  20550. }, errId.fold(function() {
  20551. return {};
  20552. }, function(id) {
  20553. return { id };
  20554. }))
  20555. }, providersBackstage.icons);
  20556. };
  20557. var memInvalidIcon = record(makeIcon("invalid", Optional.some(errorId), "warning"));
  20558. var memStatus = record({
  20559. dom: {
  20560. tag: "div",
  20561. classes: ["tox-control-wrap__status-icon-wrap"]
  20562. },
  20563. components: [memInvalidIcon.asSpec()]
  20564. });
  20565. var optUrlPicker = urlBackstage.getUrlPicker(spec.filetype);
  20566. var browseUrlEvent = generate$6("browser.url.event");
  20567. var memUrlBox = record({
  20568. dom: {
  20569. tag: "div",
  20570. classes: ["tox-control-wrap"]
  20571. },
  20572. components: [
  20573. pField,
  20574. memStatus.asSpec()
  20575. ],
  20576. behaviours: derive$1([Disabling.config({
  20577. disabled: function() {
  20578. return spec.disabled || providersBackstage.isDisabled();
  20579. }
  20580. })])
  20581. });
  20582. var memUrlPickerButton = record(renderButton({
  20583. name: spec.name,
  20584. icon: Optional.some("browse"),
  20585. text: spec.label.getOr(""),
  20586. disabled: spec.disabled,
  20587. primary: false,
  20588. borderless: true
  20589. }, function(component) {
  20590. return emit(component, browseUrlEvent);
  20591. }, providersBackstage, [], ["tox-browse-url"]));
  20592. var controlHWrapper = function() {
  20593. return {
  20594. dom: {
  20595. tag: "div",
  20596. classes: ["tox-form__controls-h-stack"]
  20597. },
  20598. components: flatten([
  20599. [memUrlBox.asSpec()],
  20600. optUrlPicker.map(function() {
  20601. return memUrlPickerButton.asSpec();
  20602. }).toArray()
  20603. ])
  20604. };
  20605. };
  20606. var openUrlPicker = function(comp) {
  20607. Composing.getCurrent(comp).each(function(field2) {
  20608. var componentData = Representing.getValue(field2);
  20609. var urlData = __assign({ fieldname: spec.name }, componentData);
  20610. optUrlPicker.each(function(picker) {
  20611. picker(urlData).get(function(chosenData) {
  20612. Representing.setValue(field2, chosenData);
  20613. emitWith(comp, formChangeEvent, { name: spec.name });
  20614. });
  20615. });
  20616. });
  20617. };
  20618. return FormField.sketch({
  20619. dom: renderFormFieldDom(),
  20620. components: pLabel.toArray().concat([controlHWrapper()]),
  20621. fieldBehaviours: derive$1([
  20622. Disabling.config({
  20623. disabled: function() {
  20624. return spec.disabled || providersBackstage.isDisabled();
  20625. },
  20626. onDisabled: function(comp) {
  20627. FormField.getField(comp).each(Disabling.disable);
  20628. memUrlPickerButton.getOpt(comp).each(Disabling.disable);
  20629. },
  20630. onEnabled: function(comp) {
  20631. FormField.getField(comp).each(Disabling.enable);
  20632. memUrlPickerButton.getOpt(comp).each(Disabling.enable);
  20633. }
  20634. }),
  20635. receivingConfig(),
  20636. config("url-input-events", [run$1(browseUrlEvent, openUrlPicker)])
  20637. ])
  20638. });
  20639. };
  20640. var renderAlertBanner = function(spec, providersBackstage) {
  20641. return Container.sketch({
  20642. dom: {
  20643. tag: "div",
  20644. attributes: { role: "alert" },
  20645. classes: [
  20646. "tox-notification",
  20647. "tox-notification--in",
  20648. "tox-notification--" + spec.level
  20649. ]
  20650. },
  20651. components: [
  20652. {
  20653. dom: {
  20654. tag: "div",
  20655. classes: ["tox-notification__icon"]
  20656. },
  20657. components: [Button.sketch({
  20658. dom: {
  20659. tag: "button",
  20660. classes: [
  20661. "tox-button",
  20662. "tox-button--naked",
  20663. "tox-button--icon"
  20664. ],
  20665. innerHtml: get$1(spec.icon, providersBackstage.icons),
  20666. attributes: { title: providersBackstage.translate(spec.iconTooltip) }
  20667. },
  20668. action: function(comp) {
  20669. emitWith(comp, formActionEvent, {
  20670. name: "alert-banner",
  20671. value: spec.url
  20672. });
  20673. },
  20674. buttonBehaviours: derive$1([addFocusableBehaviour()])
  20675. })]
  20676. },
  20677. {
  20678. dom: {
  20679. tag: "div",
  20680. classes: ["tox-notification__body"],
  20681. innerHtml: providersBackstage.translate(spec.text)
  20682. }
  20683. }
  20684. ]
  20685. });
  20686. };
  20687. var renderCheckbox = function(spec, providerBackstage) {
  20688. var repBehaviour = Representing.config({
  20689. store: {
  20690. mode: "manual",
  20691. getValue: function(comp) {
  20692. var el = comp.element.dom;
  20693. return el.checked;
  20694. },
  20695. setValue: function(comp, value2) {
  20696. var el = comp.element.dom;
  20697. el.checked = value2;
  20698. }
  20699. }
  20700. });
  20701. var toggleCheckboxHandler = function(comp) {
  20702. comp.element.dom.click();
  20703. return Optional.some(true);
  20704. };
  20705. var pField = FormField.parts.field({
  20706. factory: { sketch: identity$1 },
  20707. dom: {
  20708. tag: "input",
  20709. classes: ["tox-checkbox__input"],
  20710. attributes: { type: "checkbox" }
  20711. },
  20712. behaviours: derive$1([
  20713. ComposingConfigs.self(),
  20714. Disabling.config({
  20715. disabled: function() {
  20716. return spec.disabled || providerBackstage.isDisabled();
  20717. }
  20718. }),
  20719. Tabstopping.config({}),
  20720. Focusing.config({}),
  20721. repBehaviour,
  20722. Keying.config({
  20723. mode: "special",
  20724. onEnter: toggleCheckboxHandler,
  20725. onSpace: toggleCheckboxHandler,
  20726. stopSpaceKeyup: true
  20727. }),
  20728. config("checkbox-events", [run$1(change(), function(component, _) {
  20729. emitWith(component, formChangeEvent, { name: spec.name });
  20730. })])
  20731. ])
  20732. });
  20733. var pLabel = FormField.parts.label({
  20734. dom: {
  20735. tag: "span",
  20736. classes: ["tox-checkbox__label"],
  20737. innerHtml: providerBackstage.translate(spec.label)
  20738. },
  20739. behaviours: derive$1([Unselecting.config({})])
  20740. });
  20741. var makeIcon = function(className) {
  20742. var iconName = className === "checked" ? "selected" : "unselected";
  20743. return render$3(iconName, {
  20744. tag: "span",
  20745. classes: [
  20746. "tox-icon",
  20747. "tox-checkbox-icon__" + className
  20748. ]
  20749. }, providerBackstage.icons);
  20750. };
  20751. var memIcons = record({
  20752. dom: {
  20753. tag: "div",
  20754. classes: ["tox-checkbox__icons"]
  20755. },
  20756. components: [
  20757. makeIcon("checked"),
  20758. makeIcon("unchecked")
  20759. ]
  20760. });
  20761. return FormField.sketch({
  20762. dom: {
  20763. tag: "label",
  20764. classes: ["tox-checkbox"]
  20765. },
  20766. components: [
  20767. pField,
  20768. memIcons.asSpec(),
  20769. pLabel
  20770. ],
  20771. fieldBehaviours: derive$1([
  20772. Disabling.config({
  20773. disabled: function() {
  20774. return spec.disabled || providerBackstage.isDisabled();
  20775. },
  20776. disableClass: "tox-checkbox--disabled",
  20777. onDisabled: function(comp) {
  20778. FormField.getField(comp).each(Disabling.disable);
  20779. },
  20780. onEnabled: function(comp) {
  20781. FormField.getField(comp).each(Disabling.enable);
  20782. }
  20783. }),
  20784. receivingConfig()
  20785. ])
  20786. });
  20787. };
  20788. var renderHtmlPanel = function(spec) {
  20789. if (spec.presets === "presentation") {
  20790. return Container.sketch({
  20791. dom: {
  20792. tag: "div",
  20793. classes: ["tox-form__group"],
  20794. innerHtml: spec.html
  20795. }
  20796. });
  20797. } else {
  20798. return Container.sketch({
  20799. dom: {
  20800. tag: "div",
  20801. classes: ["tox-form__group"],
  20802. innerHtml: spec.html,
  20803. attributes: { role: "document" }
  20804. },
  20805. containerBehaviours: derive$1([
  20806. Tabstopping.config({}),
  20807. Focusing.config({})
  20808. ])
  20809. });
  20810. }
  20811. };
  20812. var make$2 = function(render2) {
  20813. return function(parts2, spec, backstage) {
  20814. return get$e(spec, "name").fold(function() {
  20815. return render2(spec, backstage);
  20816. }, function(fieldName) {
  20817. return parts2.field(fieldName, render2(spec, backstage));
  20818. });
  20819. };
  20820. };
  20821. var makeIframe = function(render2) {
  20822. return function(parts2, spec, backstage) {
  20823. var iframeSpec = deepMerge(spec, { source: "dynamic" });
  20824. return make$2(render2)(parts2, iframeSpec, backstage);
  20825. };
  20826. };
  20827. var factories = {
  20828. bar: make$2(function(spec, backstage) {
  20829. return renderBar(spec, backstage.shared);
  20830. }),
  20831. collection: make$2(function(spec, backstage) {
  20832. return renderCollection(spec, backstage.shared.providers);
  20833. }),
  20834. alertbanner: make$2(function(spec, backstage) {
  20835. return renderAlertBanner(spec, backstage.shared.providers);
  20836. }),
  20837. input: make$2(function(spec, backstage) {
  20838. return renderInput(spec, backstage.shared.providers);
  20839. }),
  20840. textarea: make$2(function(spec, backstage) {
  20841. return renderTextarea(spec, backstage.shared.providers);
  20842. }),
  20843. label: make$2(function(spec, backstage) {
  20844. return renderLabel(spec, backstage.shared);
  20845. }),
  20846. iframe: makeIframe(function(spec, backstage) {
  20847. return renderIFrame(spec, backstage.shared.providers);
  20848. }),
  20849. button: make$2(function(spec, backstage) {
  20850. return renderDialogButton(spec, backstage.shared.providers);
  20851. }),
  20852. checkbox: make$2(function(spec, backstage) {
  20853. return renderCheckbox(spec, backstage.shared.providers);
  20854. }),
  20855. colorinput: make$2(function(spec, backstage) {
  20856. return renderColorInput(spec, backstage.shared, backstage.colorinput);
  20857. }),
  20858. colorpicker: make$2(renderColorPicker),
  20859. dropzone: make$2(function(spec, backstage) {
  20860. return renderDropZone(spec, backstage.shared.providers);
  20861. }),
  20862. grid: make$2(function(spec, backstage) {
  20863. return renderGrid(spec, backstage.shared);
  20864. }),
  20865. listbox: make$2(function(spec, backstage) {
  20866. return renderListBox(spec, backstage);
  20867. }),
  20868. selectbox: make$2(function(spec, backstage) {
  20869. return renderSelectBox(spec, backstage.shared.providers);
  20870. }),
  20871. sizeinput: make$2(function(spec, backstage) {
  20872. return renderSizeInput(spec, backstage.shared.providers);
  20873. }),
  20874. urlinput: make$2(function(spec, backstage) {
  20875. return renderUrlInput(spec, backstage, backstage.urlinput);
  20876. }),
  20877. customeditor: make$2(renderCustomEditor),
  20878. htmlpanel: make$2(renderHtmlPanel),
  20879. imagetools: make$2(function(spec, backstage) {
  20880. return renderImageTools(spec, backstage.shared.providers);
  20881. }),
  20882. table: make$2(function(spec, backstage) {
  20883. return renderTable(spec, backstage.shared.providers);
  20884. }),
  20885. panel: make$2(function(spec, backstage) {
  20886. return renderPanel(spec, backstage);
  20887. })
  20888. };
  20889. var noFormParts = {
  20890. field: function(_name, spec) {
  20891. return spec;
  20892. }
  20893. };
  20894. var interpretInForm = function(parts2, spec, oldBackstage) {
  20895. var newBackstage = deepMerge(oldBackstage, {
  20896. shared: {
  20897. interpreter: function(childSpec) {
  20898. return interpretParts(parts2, childSpec, newBackstage);
  20899. }
  20900. }
  20901. });
  20902. return interpretParts(parts2, spec, newBackstage);
  20903. };
  20904. var interpretParts = function(parts2, spec, backstage) {
  20905. return get$e(factories, spec.type).fold(function() {
  20906. console.error('Unknown factory type "' + spec.type + '", defaulting to container: ', spec);
  20907. return spec;
  20908. }, function(factory2) {
  20909. return factory2(parts2, spec, backstage);
  20910. });
  20911. };
  20912. var interpretWithoutForm = function(spec, backstage) {
  20913. var parts2 = noFormParts;
  20914. return interpretParts(parts2, spec, backstage);
  20915. };
  20916. var bubbleAlignments$2 = {
  20917. valignCentre: [],
  20918. alignCentre: [],
  20919. alignLeft: [],
  20920. alignRight: [],
  20921. right: [],
  20922. left: [],
  20923. bottom: [],
  20924. top: []
  20925. };
  20926. var getInlineDialogAnchor = function(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor) {
  20927. var bubbleSize2 = 12;
  20928. var overrides = { maxHeightFunction: expandable$1() };
  20929. var editableAreaAnchor = function() {
  20930. return {
  20931. type: "node",
  20932. root: getContentContainer(contentAreaElement()),
  20933. node: Optional.from(contentAreaElement()),
  20934. bubble: nu$5(bubbleSize2, bubbleSize2, bubbleAlignments$2),
  20935. layouts: {
  20936. onRtl: function() {
  20937. return [northeast];
  20938. },
  20939. onLtr: function() {
  20940. return [northwest];
  20941. }
  20942. },
  20943. overrides
  20944. };
  20945. };
  20946. var standardAnchor = function() {
  20947. return {
  20948. type: "hotspot",
  20949. hotspot: lazyAnchorbar(),
  20950. bubble: nu$5(-bubbleSize2, bubbleSize2, bubbleAlignments$2),
  20951. layouts: {
  20952. onRtl: function() {
  20953. return [southeast$2];
  20954. },
  20955. onLtr: function() {
  20956. return [southwest$2];
  20957. }
  20958. },
  20959. overrides
  20960. };
  20961. };
  20962. return function() {
  20963. return lazyUseEditableAreaAnchor() ? editableAreaAnchor() : standardAnchor();
  20964. };
  20965. };
  20966. var getBannerAnchor = function(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor) {
  20967. var editableAreaAnchor = function() {
  20968. return {
  20969. type: "node",
  20970. root: getContentContainer(contentAreaElement()),
  20971. node: Optional.from(contentAreaElement()),
  20972. layouts: {
  20973. onRtl: function() {
  20974. return [north];
  20975. },
  20976. onLtr: function() {
  20977. return [north];
  20978. }
  20979. }
  20980. };
  20981. };
  20982. var standardAnchor = function() {
  20983. return {
  20984. type: "hotspot",
  20985. hotspot: lazyAnchorbar(),
  20986. layouts: {
  20987. onRtl: function() {
  20988. return [south$2];
  20989. },
  20990. onLtr: function() {
  20991. return [south$2];
  20992. }
  20993. }
  20994. };
  20995. };
  20996. return function() {
  20997. return lazyUseEditableAreaAnchor() ? editableAreaAnchor() : standardAnchor();
  20998. };
  20999. };
  21000. var getCursorAnchor = function(editor, bodyElement) {
  21001. return function() {
  21002. return {
  21003. type: "selection",
  21004. root: bodyElement(),
  21005. getSelection: function() {
  21006. var rng = editor.selection.getRng();
  21007. return Optional.some(SimSelection.range(SugarElement.fromDom(rng.startContainer), rng.startOffset, SugarElement.fromDom(rng.endContainer), rng.endOffset));
  21008. }
  21009. };
  21010. };
  21011. };
  21012. var getNodeAnchor$1 = function(bodyElement) {
  21013. return function(element2) {
  21014. return {
  21015. type: "node",
  21016. root: bodyElement(),
  21017. node: element2
  21018. };
  21019. };
  21020. };
  21021. var getAnchors = function(editor, lazyAnchorbar, isToolbarTop) {
  21022. var useFixedToolbarContainer = useFixedContainer(editor);
  21023. var bodyElement = function() {
  21024. return SugarElement.fromDom(editor.getBody());
  21025. };
  21026. var contentAreaElement = function() {
  21027. return SugarElement.fromDom(editor.getContentAreaContainer());
  21028. };
  21029. var lazyUseEditableAreaAnchor = function() {
  21030. return useFixedToolbarContainer || !isToolbarTop();
  21031. };
  21032. return {
  21033. inlineDialog: getInlineDialogAnchor(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor),
  21034. banner: getBannerAnchor(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor),
  21035. cursor: getCursorAnchor(editor, bodyElement),
  21036. node: getNodeAnchor$1(bodyElement)
  21037. };
  21038. };
  21039. var colorPicker = function(editor) {
  21040. return function(callback, value2) {
  21041. var dialog = colorPickerDialog(editor);
  21042. dialog(callback, value2);
  21043. };
  21044. };
  21045. var hasCustomColors = function(editor) {
  21046. return function() {
  21047. return hasCustomColors$1(editor);
  21048. };
  21049. };
  21050. var getColors = function(editor) {
  21051. return function() {
  21052. return getColors$2(editor);
  21053. };
  21054. };
  21055. var getColorCols = function(editor) {
  21056. return function() {
  21057. return getColorCols$1(editor);
  21058. };
  21059. };
  21060. var ColorInputBackstage = function(editor) {
  21061. return {
  21062. colorPicker: colorPicker(editor),
  21063. hasCustomColors: hasCustomColors(editor),
  21064. getColors: getColors(editor),
  21065. getColorCols: getColorCols(editor)
  21066. };
  21067. };
  21068. var isDraggableModal = function(editor) {
  21069. return function() {
  21070. return isDraggableModal$1(editor);
  21071. };
  21072. };
  21073. var DialogBackstage = function(editor) {
  21074. return { isDraggableModal: isDraggableModal(editor) };
  21075. };
  21076. var HeaderBackstage = function(editor) {
  21077. var mode = Cell(isToolbarLocationBottom(editor) ? "bottom" : "top");
  21078. return {
  21079. isPositionedAtTop: function() {
  21080. return mode.get() === "top";
  21081. },
  21082. getDockingMode: mode.get,
  21083. setDockingMode: mode.set
  21084. };
  21085. };
  21086. var defaultStyleFormats = [
  21087. {
  21088. title: "Headings",
  21089. items: [
  21090. {
  21091. title: "Heading 1",
  21092. format: "h1"
  21093. },
  21094. {
  21095. title: "Heading 2",
  21096. format: "h2"
  21097. },
  21098. {
  21099. title: "Heading 3",
  21100. format: "h3"
  21101. },
  21102. {
  21103. title: "Heading 4",
  21104. format: "h4"
  21105. },
  21106. {
  21107. title: "Heading 5",
  21108. format: "h5"
  21109. },
  21110. {
  21111. title: "Heading 6",
  21112. format: "h6"
  21113. }
  21114. ]
  21115. },
  21116. {
  21117. title: "Inline",
  21118. items: [
  21119. {
  21120. title: "Bold",
  21121. format: "bold"
  21122. },
  21123. {
  21124. title: "Italic",
  21125. format: "italic"
  21126. },
  21127. {
  21128. title: "Underline",
  21129. format: "underline"
  21130. },
  21131. {
  21132. title: "Strikethrough",
  21133. format: "strikethrough"
  21134. },
  21135. {
  21136. title: "Superscript",
  21137. format: "superscript"
  21138. },
  21139. {
  21140. title: "Subscript",
  21141. format: "subscript"
  21142. },
  21143. {
  21144. title: "Code",
  21145. format: "code"
  21146. }
  21147. ]
  21148. },
  21149. {
  21150. title: "Blocks",
  21151. items: [
  21152. {
  21153. title: "Paragraph",
  21154. format: "p"
  21155. },
  21156. {
  21157. title: "Blockquote",
  21158. format: "blockquote"
  21159. },
  21160. {
  21161. title: "Div",
  21162. format: "div"
  21163. },
  21164. {
  21165. title: "Pre",
  21166. format: "pre"
  21167. }
  21168. ]
  21169. },
  21170. {
  21171. title: "Align",
  21172. items: [
  21173. {
  21174. title: "Left",
  21175. format: "alignleft"
  21176. },
  21177. {
  21178. title: "Center",
  21179. format: "aligncenter"
  21180. },
  21181. {
  21182. title: "Right",
  21183. format: "alignright"
  21184. },
  21185. {
  21186. title: "Justify",
  21187. format: "alignjustify"
  21188. }
  21189. ]
  21190. }
  21191. ];
  21192. var isNestedFormat = function(format) {
  21193. return has$2(format, "items");
  21194. };
  21195. var isBlockFormat = function(format) {
  21196. return has$2(format, "block");
  21197. };
  21198. var isInlineFormat = function(format) {
  21199. return has$2(format, "inline");
  21200. };
  21201. var isSelectorFormat = function(format) {
  21202. return has$2(format, "selector");
  21203. };
  21204. var mapFormats = function(userFormats) {
  21205. return foldl(userFormats, function(acc, fmt) {
  21206. if (isNestedFormat(fmt)) {
  21207. var result = mapFormats(fmt.items);
  21208. return {
  21209. customFormats: acc.customFormats.concat(result.customFormats),
  21210. formats: acc.formats.concat([{
  21211. title: fmt.title,
  21212. items: result.formats
  21213. }])
  21214. };
  21215. } else if (isInlineFormat(fmt) || isBlockFormat(fmt) || isSelectorFormat(fmt)) {
  21216. var formatName = isString(fmt.name) ? fmt.name : fmt.title.toLowerCase();
  21217. var formatNameWithPrefix = "custom-" + formatName;
  21218. return {
  21219. customFormats: acc.customFormats.concat([{
  21220. name: formatNameWithPrefix,
  21221. format: fmt
  21222. }]),
  21223. formats: acc.formats.concat([{
  21224. title: fmt.title,
  21225. format: formatNameWithPrefix,
  21226. icon: fmt.icon
  21227. }])
  21228. };
  21229. } else {
  21230. return __assign(__assign({}, acc), { formats: acc.formats.concat(fmt) });
  21231. }
  21232. }, {
  21233. customFormats: [],
  21234. formats: []
  21235. });
  21236. };
  21237. var registerCustomFormats = function(editor, userFormats) {
  21238. var result = mapFormats(userFormats);
  21239. var registerFormats = function(customFormats) {
  21240. each$1(customFormats, function(fmt) {
  21241. if (!editor.formatter.has(fmt.name)) {
  21242. editor.formatter.register(fmt.name, fmt.format);
  21243. }
  21244. });
  21245. };
  21246. if (editor.formatter) {
  21247. registerFormats(result.customFormats);
  21248. } else {
  21249. editor.on("init", function() {
  21250. registerFormats(result.customFormats);
  21251. });
  21252. }
  21253. return result.formats;
  21254. };
  21255. var getStyleFormats = function(editor) {
  21256. return getUserStyleFormats(editor).map(function(userFormats) {
  21257. var registeredUserFormats = registerCustomFormats(editor, userFormats);
  21258. return isMergeStyleFormats(editor) ? defaultStyleFormats.concat(registeredUserFormats) : registeredUserFormats;
  21259. }).getOr(defaultStyleFormats);
  21260. };
  21261. var processBasic = function(item2, isSelectedFor, getPreviewFor) {
  21262. var formatterSpec = {
  21263. type: "formatter",
  21264. isSelected: isSelectedFor(item2.format),
  21265. getStylePreview: getPreviewFor(item2.format)
  21266. };
  21267. return deepMerge(item2, formatterSpec);
  21268. };
  21269. var register$8 = function(editor, formats, isSelectedFor, getPreviewFor) {
  21270. var enrichSupported = function(item2) {
  21271. return processBasic(item2, isSelectedFor, getPreviewFor);
  21272. };
  21273. var enrichMenu = function(item2) {
  21274. var submenuSpec = { type: "submenu" };
  21275. return deepMerge(item2, submenuSpec);
  21276. };
  21277. var enrichCustom = function(item2) {
  21278. var formatName = isString(item2.name) ? item2.name : generate$6(item2.title);
  21279. var formatNameWithPrefix = "custom-" + formatName;
  21280. var customSpec = {
  21281. type: "formatter",
  21282. format: formatNameWithPrefix,
  21283. isSelected: isSelectedFor(formatNameWithPrefix),
  21284. getStylePreview: getPreviewFor(formatNameWithPrefix)
  21285. };
  21286. var newItem = deepMerge(item2, customSpec);
  21287. editor.formatter.register(formatName, newItem);
  21288. return newItem;
  21289. };
  21290. var doEnrich = function(items) {
  21291. return map$2(items, function(item2) {
  21292. var keys$1 = keys(item2);
  21293. if (hasNonNullableKey(item2, "items")) {
  21294. var newItems = doEnrich(item2.items);
  21295. return deepMerge(enrichMenu(item2), { getStyleItems: constant$1(newItems) });
  21296. } else if (hasNonNullableKey(item2, "format")) {
  21297. return enrichSupported(item2);
  21298. } else if (keys$1.length === 1 && contains$2(keys$1, "title")) {
  21299. return deepMerge(item2, { type: "separator" });
  21300. } else {
  21301. return enrichCustom(item2);
  21302. }
  21303. });
  21304. };
  21305. return doEnrich(formats);
  21306. };
  21307. var init$8 = function(editor) {
  21308. var isSelectedFor = function(format) {
  21309. return function() {
  21310. return editor.formatter.match(format);
  21311. };
  21312. };
  21313. var getPreviewFor = function(format) {
  21314. return function() {
  21315. var fmt = editor.formatter.get(format);
  21316. return fmt !== void 0 ? Optional.some({
  21317. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || "div" : "div",
  21318. styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
  21319. }) : Optional.none();
  21320. };
  21321. };
  21322. var flatten2 = function(fmt) {
  21323. var subs2 = fmt.items;
  21324. return subs2 !== void 0 && subs2.length > 0 ? bind$3(subs2, flatten2) : [fmt.format];
  21325. };
  21326. var settingsFormats = Cell([]);
  21327. var settingsFlattenedFormats = Cell([]);
  21328. var eventsFormats = Cell([]);
  21329. var eventsFlattenedFormats = Cell([]);
  21330. var replaceSettings = Cell(false);
  21331. editor.on("PreInit", function(_e) {
  21332. var formats = getStyleFormats(editor);
  21333. var enriched = register$8(editor, formats, isSelectedFor, getPreviewFor);
  21334. settingsFormats.set(enriched);
  21335. settingsFlattenedFormats.set(bind$3(enriched, flatten2));
  21336. });
  21337. editor.on("addStyleModifications", function(e) {
  21338. var modifications = register$8(editor, e.items, isSelectedFor, getPreviewFor);
  21339. eventsFormats.set(modifications);
  21340. replaceSettings.set(e.replace);
  21341. eventsFlattenedFormats.set(bind$3(modifications, flatten2));
  21342. });
  21343. var getData2 = function() {
  21344. var fromSettings = replaceSettings.get() ? [] : settingsFormats.get();
  21345. var fromEvents = eventsFormats.get();
  21346. return fromSettings.concat(fromEvents);
  21347. };
  21348. var getFlattenedKeys = function() {
  21349. var fromSettings = replaceSettings.get() ? [] : settingsFlattenedFormats.get();
  21350. var fromEvents = eventsFlattenedFormats.get();
  21351. return fromSettings.concat(fromEvents);
  21352. };
  21353. return {
  21354. getData: getData2,
  21355. getFlattenedKeys
  21356. };
  21357. };
  21358. var isElement = function(node) {
  21359. return isNonNullable(node) && node.nodeType === 1;
  21360. };
  21361. var trim = global$5.trim;
  21362. var hasContentEditableState = function(value2) {
  21363. return function(node) {
  21364. if (isElement(node)) {
  21365. if (node.contentEditable === value2) {
  21366. return true;
  21367. }
  21368. if (node.getAttribute("data-mce-contenteditable") === value2) {
  21369. return true;
  21370. }
  21371. }
  21372. return false;
  21373. };
  21374. };
  21375. var isContentEditableTrue = hasContentEditableState("true");
  21376. var isContentEditableFalse = hasContentEditableState("false");
  21377. var create = function(type2, title, url, level, attach2) {
  21378. return {
  21379. type: type2,
  21380. title,
  21381. url,
  21382. level,
  21383. attach: attach2
  21384. };
  21385. };
  21386. var isChildOfContentEditableTrue = function(node) {
  21387. while (node = node.parentNode) {
  21388. var value2 = node.contentEditable;
  21389. if (value2 && value2 !== "inherit") {
  21390. return isContentEditableTrue(node);
  21391. }
  21392. }
  21393. return false;
  21394. };
  21395. var select = function(selector, root) {
  21396. return map$2(descendants(SugarElement.fromDom(root), selector), function(element2) {
  21397. return element2.dom;
  21398. });
  21399. };
  21400. var getElementText = function(elm) {
  21401. return elm.innerText || elm.textContent;
  21402. };
  21403. var getOrGenerateId = function(elm) {
  21404. return elm.id ? elm.id : generate$6("h");
  21405. };
  21406. var isAnchor = function(elm) {
  21407. return elm && elm.nodeName === "A" && (elm.id || elm.name) !== void 0;
  21408. };
  21409. var isValidAnchor = function(elm) {
  21410. return isAnchor(elm) && isEditable(elm);
  21411. };
  21412. var isHeader = function(elm) {
  21413. return elm && /^(H[1-6])$/.test(elm.nodeName);
  21414. };
  21415. var isEditable = function(elm) {
  21416. return isChildOfContentEditableTrue(elm) && !isContentEditableFalse(elm);
  21417. };
  21418. var isValidHeader = function(elm) {
  21419. return isHeader(elm) && isEditable(elm);
  21420. };
  21421. var getLevel = function(elm) {
  21422. return isHeader(elm) ? parseInt(elm.nodeName.substr(1), 10) : 0;
  21423. };
  21424. var headerTarget = function(elm) {
  21425. var headerId = getOrGenerateId(elm);
  21426. var attach2 = function() {
  21427. elm.id = headerId;
  21428. };
  21429. return create("header", getElementText(elm), "#" + headerId, getLevel(elm), attach2);
  21430. };
  21431. var anchorTarget = function(elm) {
  21432. var anchorId = elm.id || elm.name;
  21433. var anchorText = getElementText(elm);
  21434. return create("anchor", anchorText ? anchorText : "#" + anchorId, "#" + anchorId, 0, noop);
  21435. };
  21436. var getHeaderTargets = function(elms) {
  21437. return map$2(filter$2(elms, isValidHeader), headerTarget);
  21438. };
  21439. var getAnchorTargets = function(elms) {
  21440. return map$2(filter$2(elms, isValidAnchor), anchorTarget);
  21441. };
  21442. var getTargetElements = function(elm) {
  21443. var elms = select("h1,h2,h3,h4,h5,h6,a:not([href])", elm);
  21444. return elms;
  21445. };
  21446. var hasTitle = function(target) {
  21447. return trim(target.title).length > 0;
  21448. };
  21449. var find = function(elm) {
  21450. var elms = getTargetElements(elm);
  21451. return filter$2(getHeaderTargets(elms).concat(getAnchorTargets(elms)), hasTitle);
  21452. };
  21453. var LinkTargets = { find };
  21454. var STORAGE_KEY = "tinymce-url-history";
  21455. var HISTORY_LENGTH = 5;
  21456. var isHttpUrl = function(url) {
  21457. return isString(url) && /^https?/.test(url);
  21458. };
  21459. var isArrayOfUrl = function(a) {
  21460. return isArray(a) && a.length <= HISTORY_LENGTH && forall(a, isHttpUrl);
  21461. };
  21462. var isRecordOfUrlArray = function(r2) {
  21463. return isObject(r2) && find$4(r2, function(value2) {
  21464. return !isArrayOfUrl(value2);
  21465. }).isNone();
  21466. };
  21467. var getAllHistory = function() {
  21468. var unparsedHistory = global$8.getItem(STORAGE_KEY);
  21469. if (unparsedHistory === null) {
  21470. return {};
  21471. }
  21472. var history;
  21473. try {
  21474. history = JSON.parse(unparsedHistory);
  21475. } catch (e) {
  21476. if (e instanceof SyntaxError) {
  21477. console.log("Local storage " + STORAGE_KEY + " was not valid JSON", e);
  21478. return {};
  21479. }
  21480. throw e;
  21481. }
  21482. if (!isRecordOfUrlArray(history)) {
  21483. console.log("Local storage " + STORAGE_KEY + " was not valid format", history);
  21484. return {};
  21485. }
  21486. return history;
  21487. };
  21488. var setAllHistory = function(history) {
  21489. if (!isRecordOfUrlArray(history)) {
  21490. throw new Error("Bad format for history:\n" + JSON.stringify(history));
  21491. }
  21492. global$8.setItem(STORAGE_KEY, JSON.stringify(history));
  21493. };
  21494. var getHistory = function(fileType) {
  21495. var history = getAllHistory();
  21496. return get$e(history, fileType).getOr([]);
  21497. };
  21498. var addToHistory = function(url, fileType) {
  21499. if (!isHttpUrl(url)) {
  21500. return;
  21501. }
  21502. var history = getAllHistory();
  21503. var items = get$e(history, fileType).getOr([]);
  21504. var itemsWithoutUrl = filter$2(items, function(item2) {
  21505. return item2 !== url;
  21506. });
  21507. history[fileType] = [url].concat(itemsWithoutUrl).slice(0, HISTORY_LENGTH);
  21508. setAllHistory(history);
  21509. };
  21510. var isTruthy = function(value2) {
  21511. return !!value2;
  21512. };
  21513. var makeMap = function(value2) {
  21514. return map$1(global$5.makeMap(value2, /[, ]/), isTruthy);
  21515. };
  21516. var getPicker = function(editor) {
  21517. return Optional.from(getFilePickerCallback(editor)).filter(isFunction);
  21518. };
  21519. var getPickerTypes = function(editor) {
  21520. var optFileTypes = Optional.some(getFilePickerTypes(editor)).filter(isTruthy);
  21521. var optLegacyTypes = Optional.some(getFileBrowserCallbackTypes(editor)).filter(isTruthy);
  21522. var optTypes = optFileTypes.or(optLegacyTypes).map(makeMap);
  21523. return getPicker(editor).fold(never, function(_picker) {
  21524. return optTypes.fold(always, function(types2) {
  21525. return keys(types2).length > 0 ? types2 : false;
  21526. });
  21527. });
  21528. };
  21529. var getPickerSetting = function(editor, filetype) {
  21530. var pickerTypes = getPickerTypes(editor);
  21531. if (isBoolean(pickerTypes)) {
  21532. return pickerTypes ? getPicker(editor) : Optional.none();
  21533. } else {
  21534. return pickerTypes[filetype] ? getPicker(editor) : Optional.none();
  21535. }
  21536. };
  21537. var getUrlPicker = function(editor, filetype) {
  21538. return getPickerSetting(editor, filetype).map(function(picker) {
  21539. return function(entry) {
  21540. return Future.nu(function(completer) {
  21541. var handler = function(value2, meta2) {
  21542. if (!isString(value2)) {
  21543. throw new Error("Expected value to be string");
  21544. }
  21545. if (meta2 !== void 0 && !isObject(meta2)) {
  21546. throw new Error("Expected meta to be a object");
  21547. }
  21548. var r2 = {
  21549. value: value2,
  21550. meta: meta2
  21551. };
  21552. completer(r2);
  21553. };
  21554. var meta = __assign({
  21555. filetype,
  21556. fieldname: entry.fieldname
  21557. }, Optional.from(entry.meta).getOr({}));
  21558. picker.call(editor, handler, entry.value, meta);
  21559. });
  21560. };
  21561. });
  21562. };
  21563. var getTextSetting = function(value2) {
  21564. return Optional.from(value2).filter(isString).getOrUndefined();
  21565. };
  21566. var getLinkInformation = function(editor) {
  21567. if (noTypeaheadUrls(editor)) {
  21568. return Optional.none();
  21569. }
  21570. return Optional.some({
  21571. targets: LinkTargets.find(editor.getBody()),
  21572. anchorTop: getTextSetting(getAnchorTop(editor)),
  21573. anchorBottom: getTextSetting(getAnchorBottom(editor))
  21574. });
  21575. };
  21576. var getValidationHandler = function(editor) {
  21577. return Optional.from(getFilePickerValidatorHandler(editor));
  21578. };
  21579. var UrlInputBackstage = function(editor) {
  21580. return {
  21581. getHistory,
  21582. addToHistory,
  21583. getLinkInformation: function() {
  21584. return getLinkInformation(editor);
  21585. },
  21586. getValidationHandler: function() {
  21587. return getValidationHandler(editor);
  21588. },
  21589. getUrlPicker: function(filetype) {
  21590. return getUrlPicker(editor, filetype);
  21591. }
  21592. };
  21593. };
  21594. var init$7 = function(sink, editor, lazyAnchorbar) {
  21595. var contextMenuState = Cell(false);
  21596. var toolbar = HeaderBackstage(editor);
  21597. var backstage = {
  21598. shared: {
  21599. providers: {
  21600. icons: function() {
  21601. return editor.ui.registry.getAll().icons;
  21602. },
  21603. menuItems: function() {
  21604. return editor.ui.registry.getAll().menuItems;
  21605. },
  21606. translate: global$e.translate,
  21607. isDisabled: function() {
  21608. return editor.mode.isReadOnly() || editor.ui.isDisabled();
  21609. },
  21610. getSetting: editor.getParam.bind(editor)
  21611. },
  21612. interpreter: function(s) {
  21613. return interpretWithoutForm(s, backstage);
  21614. },
  21615. anchors: getAnchors(editor, lazyAnchorbar, toolbar.isPositionedAtTop),
  21616. header: toolbar,
  21617. getSink: function() {
  21618. return Result.value(sink);
  21619. }
  21620. },
  21621. urlinput: UrlInputBackstage(editor),
  21622. styleselect: init$8(editor),
  21623. colorinput: ColorInputBackstage(editor),
  21624. dialog: DialogBackstage(editor),
  21625. isContextMenuOpen: function() {
  21626. return contextMenuState.get();
  21627. },
  21628. setContextMenuState: function(state) {
  21629. return contextMenuState.set(state);
  21630. }
  21631. };
  21632. return backstage;
  21633. };
  21634. var setup$b = function(editor, mothership, uiMothership) {
  21635. var broadcastEvent = function(name2, evt) {
  21636. each$1([
  21637. mothership,
  21638. uiMothership
  21639. ], function(ship) {
  21640. ship.broadcastEvent(name2, evt);
  21641. });
  21642. };
  21643. var broadcastOn = function(channel, message) {
  21644. each$1([
  21645. mothership,
  21646. uiMothership
  21647. ], function(ship) {
  21648. ship.broadcastOn([channel], message);
  21649. });
  21650. };
  21651. var fireDismissPopups = function(evt) {
  21652. return broadcastOn(dismissPopups(), { target: evt.target });
  21653. };
  21654. var doc = getDocument();
  21655. var onTouchstart = bind(doc, "touchstart", fireDismissPopups);
  21656. var onTouchmove = bind(doc, "touchmove", function(evt) {
  21657. return broadcastEvent(documentTouchmove(), evt);
  21658. });
  21659. var onTouchend = bind(doc, "touchend", function(evt) {
  21660. return broadcastEvent(documentTouchend(), evt);
  21661. });
  21662. var onMousedown = bind(doc, "mousedown", fireDismissPopups);
  21663. var onMouseup = bind(doc, "mouseup", function(evt) {
  21664. if (evt.raw.button === 0) {
  21665. broadcastOn(mouseReleased(), { target: evt.target });
  21666. }
  21667. });
  21668. var onContentClick = function(raw) {
  21669. return broadcastOn(dismissPopups(), { target: SugarElement.fromDom(raw.target) });
  21670. };
  21671. var onContentMouseup = function(raw) {
  21672. if (raw.button === 0) {
  21673. broadcastOn(mouseReleased(), { target: SugarElement.fromDom(raw.target) });
  21674. }
  21675. };
  21676. var onContentMousedown = function() {
  21677. each$1(editor.editorManager.get(), function(loopEditor) {
  21678. if (editor !== loopEditor) {
  21679. loopEditor.fire("DismissPopups", { relatedTarget: editor });
  21680. }
  21681. });
  21682. };
  21683. var onWindowScroll = function(evt) {
  21684. return broadcastEvent(windowScroll(), fromRawEvent(evt));
  21685. };
  21686. var onWindowResize = function(evt) {
  21687. broadcastOn(repositionPopups(), {});
  21688. broadcastEvent(windowResize(), fromRawEvent(evt));
  21689. };
  21690. var onEditorResize = function() {
  21691. return broadcastOn(repositionPopups(), {});
  21692. };
  21693. var onEditorProgress = function(evt) {
  21694. if (evt.state) {
  21695. broadcastOn(dismissPopups(), { target: SugarElement.fromDom(editor.getContainer()) });
  21696. }
  21697. };
  21698. var onDismissPopups = function(event) {
  21699. broadcastOn(dismissPopups(), { target: SugarElement.fromDom(event.relatedTarget.getContainer()) });
  21700. };
  21701. editor.on("PostRender", function() {
  21702. editor.on("click", onContentClick);
  21703. editor.on("tap", onContentClick);
  21704. editor.on("mouseup", onContentMouseup);
  21705. editor.on("mousedown", onContentMousedown);
  21706. editor.on("ScrollWindow", onWindowScroll);
  21707. editor.on("ResizeWindow", onWindowResize);
  21708. editor.on("ResizeEditor", onEditorResize);
  21709. editor.on("AfterProgressState", onEditorProgress);
  21710. editor.on("DismissPopups", onDismissPopups);
  21711. });
  21712. editor.on("remove", function() {
  21713. editor.off("click", onContentClick);
  21714. editor.off("tap", onContentClick);
  21715. editor.off("mouseup", onContentMouseup);
  21716. editor.off("mousedown", onContentMousedown);
  21717. editor.off("ScrollWindow", onWindowScroll);
  21718. editor.off("ResizeWindow", onWindowResize);
  21719. editor.off("ResizeEditor", onEditorResize);
  21720. editor.off("AfterProgressState", onEditorProgress);
  21721. editor.off("DismissPopups", onDismissPopups);
  21722. onMousedown.unbind();
  21723. onTouchstart.unbind();
  21724. onTouchmove.unbind();
  21725. onTouchend.unbind();
  21726. onMouseup.unbind();
  21727. });
  21728. editor.on("detach", function() {
  21729. detachSystem(mothership);
  21730. detachSystem(uiMothership);
  21731. mothership.destroy();
  21732. uiMothership.destroy();
  21733. });
  21734. };
  21735. var parts$a = AlloyParts;
  21736. var partType = PartType;
  21737. var schema$f = constant$1([
  21738. defaulted("shell", false),
  21739. required$1("makeItem"),
  21740. defaulted("setupItem", noop),
  21741. SketchBehaviours.field("listBehaviours", [Replacing])
  21742. ]);
  21743. var customListDetail = function() {
  21744. return { behaviours: derive$1([Replacing.config({})]) };
  21745. };
  21746. var itemsPart = optional({
  21747. name: "items",
  21748. overrides: customListDetail
  21749. });
  21750. var parts$9 = constant$1([itemsPart]);
  21751. var name = constant$1("CustomList");
  21752. var factory$d = function(detail, components2, _spec, _external) {
  21753. var setItems = function(list, items) {
  21754. getListContainer(list).fold(function() {
  21755. console.error("Custom List was defined to not be a shell, but no item container was specified in components");
  21756. throw new Error("Custom List was defined to not be a shell, but no item container was specified in components");
  21757. }, function(container) {
  21758. var itemComps = Replacing.contents(container);
  21759. var numListsRequired = items.length;
  21760. var numListsToAdd = numListsRequired - itemComps.length;
  21761. var itemsToAdd = numListsToAdd > 0 ? range$2(numListsToAdd, function() {
  21762. return detail.makeItem();
  21763. }) : [];
  21764. var itemsToRemove = itemComps.slice(numListsRequired);
  21765. each$1(itemsToRemove, function(item2) {
  21766. return Replacing.remove(container, item2);
  21767. });
  21768. each$1(itemsToAdd, function(item2) {
  21769. return Replacing.append(container, item2);
  21770. });
  21771. var builtLists = Replacing.contents(container);
  21772. each$1(builtLists, function(item2, i) {
  21773. detail.setupItem(list, item2, items[i], i);
  21774. });
  21775. });
  21776. };
  21777. var extra = detail.shell ? {
  21778. behaviours: [Replacing.config({})],
  21779. components: []
  21780. } : {
  21781. behaviours: [],
  21782. components: components2
  21783. };
  21784. var getListContainer = function(component) {
  21785. return detail.shell ? Optional.some(component) : getPart(component, detail, "items");
  21786. };
  21787. return {
  21788. uid: detail.uid,
  21789. dom: detail.dom,
  21790. components: extra.components,
  21791. behaviours: augment(detail.listBehaviours, extra.behaviours),
  21792. apis: { setItems }
  21793. };
  21794. };
  21795. var CustomList = composite({
  21796. name: name(),
  21797. configFields: schema$f(),
  21798. partFields: parts$9(),
  21799. factory: factory$d,
  21800. apis: {
  21801. setItems: function(apis, list, items) {
  21802. apis.setItems(list, items);
  21803. }
  21804. }
  21805. });
  21806. var schema$e = constant$1([
  21807. required$1("dom"),
  21808. defaulted("shell", true),
  21809. field("toolbarBehaviours", [Replacing])
  21810. ]);
  21811. var enhanceGroups = function() {
  21812. return { behaviours: derive$1([Replacing.config({})]) };
  21813. };
  21814. var parts$8 = constant$1([optional({
  21815. name: "groups",
  21816. overrides: enhanceGroups
  21817. })]);
  21818. var factory$c = function(detail, components2, _spec, _externals) {
  21819. var setGroups2 = function(toolbar, groups) {
  21820. getGroupContainer(toolbar).fold(function() {
  21821. console.error("Toolbar was defined to not be a shell, but no groups container was specified in components");
  21822. throw new Error("Toolbar was defined to not be a shell, but no groups container was specified in components");
  21823. }, function(container) {
  21824. Replacing.set(container, groups);
  21825. });
  21826. };
  21827. var getGroupContainer = function(component) {
  21828. return detail.shell ? Optional.some(component) : getPart(component, detail, "groups");
  21829. };
  21830. var extra = detail.shell ? {
  21831. behaviours: [Replacing.config({})],
  21832. components: []
  21833. } : {
  21834. behaviours: [],
  21835. components: components2
  21836. };
  21837. return {
  21838. uid: detail.uid,
  21839. dom: detail.dom,
  21840. components: extra.components,
  21841. behaviours: augment(detail.toolbarBehaviours, extra.behaviours),
  21842. apis: { setGroups: setGroups2 },
  21843. domModification: { attributes: { role: "group" } }
  21844. };
  21845. };
  21846. var Toolbar = composite({
  21847. name: "Toolbar",
  21848. configFields: schema$e(),
  21849. partFields: parts$8(),
  21850. factory: factory$c,
  21851. apis: {
  21852. setGroups: function(apis, toolbar, groups) {
  21853. apis.setGroups(toolbar, groups);
  21854. }
  21855. }
  21856. });
  21857. var setup$a = noop;
  21858. var isDocked$2 = never;
  21859. var getBehaviours$1 = constant$1([]);
  21860. var StaticHeader = Object.freeze({
  21861. __proto__: null,
  21862. setup: setup$a,
  21863. isDocked: isDocked$2,
  21864. getBehaviours: getBehaviours$1
  21865. });
  21866. var getOffsetParent = function(element2) {
  21867. var isFixed = is$1(getRaw(element2, "position"), "fixed");
  21868. var offsetParent$1 = isFixed ? Optional.none() : offsetParent(element2);
  21869. return offsetParent$1.orThunk(function() {
  21870. var marker = SugarElement.fromTag("span");
  21871. return parent(element2).bind(function(parent2) {
  21872. append$2(parent2, marker);
  21873. var offsetParent$12 = offsetParent(marker);
  21874. remove$5(marker);
  21875. return offsetParent$12;
  21876. });
  21877. });
  21878. };
  21879. var getOrigin = function(element2) {
  21880. return getOffsetParent(element2).map(absolute$3).getOrThunk(function() {
  21881. return SugarPosition(0, 0);
  21882. });
  21883. };
  21884. var morphAdt = Adt.generate([
  21885. { static: [] },
  21886. { absolute: ["positionCss"] },
  21887. { fixed: ["positionCss"] }
  21888. ]);
  21889. var appear = function(component, contextualInfo) {
  21890. var elem = component.element;
  21891. add$2(elem, contextualInfo.transitionClass);
  21892. remove$2(elem, contextualInfo.fadeOutClass);
  21893. add$2(elem, contextualInfo.fadeInClass);
  21894. contextualInfo.onShow(component);
  21895. };
  21896. var disappear = function(component, contextualInfo) {
  21897. var elem = component.element;
  21898. add$2(elem, contextualInfo.transitionClass);
  21899. remove$2(elem, contextualInfo.fadeInClass);
  21900. add$2(elem, contextualInfo.fadeOutClass);
  21901. contextualInfo.onHide(component);
  21902. };
  21903. var isPartiallyVisible = function(box2, viewport2) {
  21904. return box2.y < viewport2.bottom && box2.bottom > viewport2.y;
  21905. };
  21906. var isTopCompletelyVisible = function(box2, viewport2) {
  21907. return box2.y >= viewport2.y;
  21908. };
  21909. var isBottomCompletelyVisible = function(box2, viewport2) {
  21910. return box2.bottom <= viewport2.bottom;
  21911. };
  21912. var isVisibleForModes = function(modes, box2, viewport2) {
  21913. return forall(modes, function(mode) {
  21914. switch (mode) {
  21915. case "bottom":
  21916. return isBottomCompletelyVisible(box2, viewport2);
  21917. case "top":
  21918. return isTopCompletelyVisible(box2, viewport2);
  21919. }
  21920. });
  21921. };
  21922. var getPrior = function(elem, state) {
  21923. return state.getInitialPos().map(function(pos) {
  21924. return bounds(pos.bounds.x, pos.bounds.y, get$a(elem), get$b(elem));
  21925. });
  21926. };
  21927. var storePrior = function(elem, box2, state) {
  21928. state.setInitialPos({
  21929. style: getAllRaw(elem),
  21930. position: get$c(elem, "position") || "static",
  21931. bounds: box2
  21932. });
  21933. };
  21934. var revertToOriginal = function(elem, box2, state) {
  21935. return state.getInitialPos().bind(function(position2) {
  21936. state.clearInitialPos();
  21937. switch (position2.position) {
  21938. case "static":
  21939. return Optional.some(morphAdt.static());
  21940. case "absolute":
  21941. var offsetBox_1 = getOffsetParent(elem).map(box$1).getOrThunk(function() {
  21942. return box$1(body());
  21943. });
  21944. return Optional.some(morphAdt.absolute(NuPositionCss("absolute", get$e(position2.style, "left").map(function(_left) {
  21945. return box2.x - offsetBox_1.x;
  21946. }), get$e(position2.style, "top").map(function(_top) {
  21947. return box2.y - offsetBox_1.y;
  21948. }), get$e(position2.style, "right").map(function(_right) {
  21949. return offsetBox_1.right - box2.right;
  21950. }), get$e(position2.style, "bottom").map(function(_bottom) {
  21951. return offsetBox_1.bottom - box2.bottom;
  21952. }))));
  21953. default:
  21954. return Optional.none();
  21955. }
  21956. });
  21957. };
  21958. var morphToOriginal = function(elem, viewport2, state) {
  21959. return getPrior(elem, state).filter(function(box2) {
  21960. return isVisibleForModes(state.getModes(), box2, viewport2);
  21961. }).bind(function(box2) {
  21962. return revertToOriginal(elem, box2, state);
  21963. });
  21964. };
  21965. var morphToFixed = function(elem, viewport2, state) {
  21966. var box2 = box$1(elem);
  21967. if (!isVisibleForModes(state.getModes(), box2, viewport2)) {
  21968. storePrior(elem, box2, state);
  21969. var winBox = win();
  21970. var left2 = box2.x - winBox.x;
  21971. var top_1 = viewport2.y - winBox.y;
  21972. var bottom2 = winBox.bottom - viewport2.bottom;
  21973. var isTop = box2.y <= viewport2.y;
  21974. return Optional.some(morphAdt.fixed(NuPositionCss("fixed", Optional.some(left2), isTop ? Optional.some(top_1) : Optional.none(), Optional.none(), !isTop ? Optional.some(bottom2) : Optional.none())));
  21975. } else {
  21976. return Optional.none();
  21977. }
  21978. };
  21979. var getMorph = function(component, viewport2, state) {
  21980. var elem = component.element;
  21981. var isDocked2 = is$1(getRaw(elem, "position"), "fixed");
  21982. return isDocked2 ? morphToOriginal(elem, viewport2, state) : morphToFixed(elem, viewport2, state);
  21983. };
  21984. var getMorphToOriginal = function(component, state) {
  21985. var elem = component.element;
  21986. return getPrior(elem, state).bind(function(box2) {
  21987. return revertToOriginal(elem, box2, state);
  21988. });
  21989. };
  21990. var morphToStatic = function(component, config2, state) {
  21991. state.setDocked(false);
  21992. each$1([
  21993. "left",
  21994. "right",
  21995. "top",
  21996. "bottom",
  21997. "position"
  21998. ], function(prop) {
  21999. return remove$6(component.element, prop);
  22000. });
  22001. config2.onUndocked(component);
  22002. };
  22003. var morphToCoord = function(component, config2, state, position2) {
  22004. var isDocked2 = position2.position === "fixed";
  22005. state.setDocked(isDocked2);
  22006. applyPositionCss(component.element, position2);
  22007. var method = isDocked2 ? config2.onDocked : config2.onUndocked;
  22008. method(component);
  22009. };
  22010. var updateVisibility = function(component, config2, state, viewport2, morphToDocked) {
  22011. if (morphToDocked === void 0) {
  22012. morphToDocked = false;
  22013. }
  22014. config2.contextual.each(function(contextInfo) {
  22015. contextInfo.lazyContext(component).each(function(box2) {
  22016. var isVisible2 = isPartiallyVisible(box2, viewport2);
  22017. if (isVisible2 !== state.isVisible()) {
  22018. state.setVisible(isVisible2);
  22019. if (morphToDocked && !isVisible2) {
  22020. add$1(component.element, [contextInfo.fadeOutClass]);
  22021. contextInfo.onHide(component);
  22022. } else {
  22023. var method = isVisible2 ? appear : disappear;
  22024. method(component, contextInfo);
  22025. }
  22026. }
  22027. });
  22028. });
  22029. };
  22030. var refreshInternal = function(component, config2, state) {
  22031. var viewport2 = config2.lazyViewport(component);
  22032. var isDocked2 = state.isDocked();
  22033. if (isDocked2) {
  22034. updateVisibility(component, config2, state, viewport2);
  22035. }
  22036. getMorph(component, viewport2, state).each(function(morph) {
  22037. morph.fold(function() {
  22038. return morphToStatic(component, config2, state);
  22039. }, function(position2) {
  22040. return morphToCoord(component, config2, state, position2);
  22041. }, function(position2) {
  22042. updateVisibility(component, config2, state, viewport2, true);
  22043. morphToCoord(component, config2, state, position2);
  22044. });
  22045. });
  22046. };
  22047. var resetInternal = function(component, config2, state) {
  22048. var elem = component.element;
  22049. state.setDocked(false);
  22050. getMorphToOriginal(component, state).each(function(morph) {
  22051. morph.fold(function() {
  22052. return morphToStatic(component, config2, state);
  22053. }, function(position2) {
  22054. return morphToCoord(component, config2, state, position2);
  22055. }, noop);
  22056. });
  22057. state.setVisible(true);
  22058. config2.contextual.each(function(contextInfo) {
  22059. remove$1(elem, [
  22060. contextInfo.fadeInClass,
  22061. contextInfo.fadeOutClass,
  22062. contextInfo.transitionClass
  22063. ]);
  22064. contextInfo.onShow(component);
  22065. });
  22066. refresh$4(component, config2, state);
  22067. };
  22068. var refresh$4 = function(component, config2, state) {
  22069. if (component.getSystem().isConnected()) {
  22070. refreshInternal(component, config2, state);
  22071. }
  22072. };
  22073. var reset = function(component, config2, state) {
  22074. if (state.isDocked()) {
  22075. resetInternal(component, config2, state);
  22076. }
  22077. };
  22078. var isDocked$1 = function(component, config2, state) {
  22079. return state.isDocked();
  22080. };
  22081. var setModes = function(component, config2, state, modes) {
  22082. return state.setModes(modes);
  22083. };
  22084. var getModes = function(component, config2, state) {
  22085. return state.getModes();
  22086. };
  22087. var DockingApis = Object.freeze({
  22088. __proto__: null,
  22089. refresh: refresh$4,
  22090. reset,
  22091. isDocked: isDocked$1,
  22092. getModes,
  22093. setModes
  22094. });
  22095. var events$5 = function(dockInfo, dockState) {
  22096. return derive$2([
  22097. runOnSource(transitionend(), function(component, simulatedEvent) {
  22098. dockInfo.contextual.each(function(contextInfo) {
  22099. if (has(component.element, contextInfo.transitionClass)) {
  22100. remove$1(component.element, [
  22101. contextInfo.transitionClass,
  22102. contextInfo.fadeInClass
  22103. ]);
  22104. var notify = dockState.isVisible() ? contextInfo.onShown : contextInfo.onHidden;
  22105. notify(component);
  22106. }
  22107. simulatedEvent.stop();
  22108. });
  22109. }),
  22110. run$1(windowScroll(), function(component, _) {
  22111. refresh$4(component, dockInfo, dockState);
  22112. }),
  22113. run$1(windowResize(), function(component, _) {
  22114. reset(component, dockInfo, dockState);
  22115. })
  22116. ]);
  22117. };
  22118. var ActiveDocking = Object.freeze({
  22119. __proto__: null,
  22120. events: events$5
  22121. });
  22122. var DockingSchema = [
  22123. optionObjOf("contextual", [
  22124. requiredString("fadeInClass"),
  22125. requiredString("fadeOutClass"),
  22126. requiredString("transitionClass"),
  22127. requiredFunction("lazyContext"),
  22128. onHandler("onShow"),
  22129. onHandler("onShown"),
  22130. onHandler("onHide"),
  22131. onHandler("onHidden")
  22132. ]),
  22133. defaultedFunction("lazyViewport", win),
  22134. defaultedArrayOf("modes", [
  22135. "top",
  22136. "bottom"
  22137. ], string),
  22138. onHandler("onDocked"),
  22139. onHandler("onUndocked")
  22140. ];
  22141. var init$6 = function(spec) {
  22142. var docked = Cell(false);
  22143. var visible = Cell(true);
  22144. var initialBounds = value$1();
  22145. var modes = Cell(spec.modes);
  22146. var readState = function() {
  22147. return "docked: " + docked.get() + ", visible: " + visible.get() + ", modes: " + modes.get().join(",");
  22148. };
  22149. return nu$8({
  22150. isDocked: docked.get,
  22151. setDocked: docked.set,
  22152. getInitialPos: initialBounds.get,
  22153. setInitialPos: initialBounds.set,
  22154. clearInitialPos: initialBounds.clear,
  22155. isVisible: visible.get,
  22156. setVisible: visible.set,
  22157. getModes: modes.get,
  22158. setModes: modes.set,
  22159. readState
  22160. });
  22161. };
  22162. var DockingState = Object.freeze({
  22163. __proto__: null,
  22164. init: init$6
  22165. });
  22166. var Docking = create$7({
  22167. fields: DockingSchema,
  22168. name: "docking",
  22169. active: ActiveDocking,
  22170. apis: DockingApis,
  22171. state: DockingState
  22172. });
  22173. var toolbarHeightChange = constant$1(generate$6("toolbar-height-change"));
  22174. var visibility = {
  22175. fadeInClass: "tox-editor-dock-fadein",
  22176. fadeOutClass: "tox-editor-dock-fadeout",
  22177. transitionClass: "tox-editor-dock-transition"
  22178. };
  22179. var editorStickyOnClass = "tox-tinymce--toolbar-sticky-on";
  22180. var editorStickyOffClass = "tox-tinymce--toolbar-sticky-off";
  22181. var scrollFromBehindHeader = function(e, containerHeader) {
  22182. var doc = owner$4(containerHeader);
  22183. var viewHeight = doc.dom.defaultView.innerHeight;
  22184. var scrollPos = get$9(doc);
  22185. var markerElement = SugarElement.fromDom(e.elm);
  22186. var markerPos = absolute$2(markerElement);
  22187. var markerHeight = get$b(markerElement);
  22188. var markerTop = markerPos.y;
  22189. var markerBottom = markerTop + markerHeight;
  22190. var editorHeaderPos = absolute$3(containerHeader);
  22191. var editorHeaderHeight = get$b(containerHeader);
  22192. var editorHeaderTop = editorHeaderPos.top;
  22193. var editorHeaderBottom = editorHeaderTop + editorHeaderHeight;
  22194. var editorHeaderDockedAtTop = Math.abs(editorHeaderTop - scrollPos.top) < 2;
  22195. var editorHeaderDockedAtBottom = Math.abs(editorHeaderBottom - (scrollPos.top + viewHeight)) < 2;
  22196. if (editorHeaderDockedAtTop && markerTop < editorHeaderBottom) {
  22197. to(scrollPos.left, markerTop - editorHeaderHeight, doc);
  22198. } else if (editorHeaderDockedAtBottom && markerBottom > editorHeaderTop) {
  22199. var y = markerTop - viewHeight + markerHeight + editorHeaderHeight;
  22200. to(scrollPos.left, y, doc);
  22201. }
  22202. };
  22203. var isDockedMode = function(header, mode) {
  22204. return contains$2(Docking.getModes(header), mode);
  22205. };
  22206. var updateIframeContentFlow = function(header) {
  22207. var getOccupiedHeight = function(elm2) {
  22208. return getOuter$2(elm2) + (parseInt(get$c(elm2, "margin-top"), 10) || 0) + (parseInt(get$c(elm2, "margin-bottom"), 10) || 0);
  22209. };
  22210. var elm = header.element;
  22211. parent(elm).each(function(parentElem) {
  22212. var padding = "padding-" + Docking.getModes(header)[0];
  22213. if (Docking.isDocked(header)) {
  22214. var parentWidth = get$a(parentElem);
  22215. set$7(elm, "width", parentWidth + "px");
  22216. set$7(parentElem, padding, getOccupiedHeight(elm) + "px");
  22217. } else {
  22218. remove$6(elm, "width");
  22219. remove$6(parentElem, padding);
  22220. }
  22221. });
  22222. };
  22223. var updateSinkVisibility = function(sinkElem, visible) {
  22224. if (visible) {
  22225. remove$2(sinkElem, visibility.fadeOutClass);
  22226. add$1(sinkElem, [
  22227. visibility.transitionClass,
  22228. visibility.fadeInClass
  22229. ]);
  22230. } else {
  22231. remove$2(sinkElem, visibility.fadeInClass);
  22232. add$1(sinkElem, [
  22233. visibility.fadeOutClass,
  22234. visibility.transitionClass
  22235. ]);
  22236. }
  22237. };
  22238. var updateEditorClasses = function(editor, docked) {
  22239. var editorContainer = SugarElement.fromDom(editor.getContainer());
  22240. if (docked) {
  22241. add$2(editorContainer, editorStickyOnClass);
  22242. remove$2(editorContainer, editorStickyOffClass);
  22243. } else {
  22244. add$2(editorContainer, editorStickyOffClass);
  22245. remove$2(editorContainer, editorStickyOnClass);
  22246. }
  22247. };
  22248. var restoreFocus = function(headerElem, focusedElem) {
  22249. var ownerDoc = owner$4(focusedElem);
  22250. active(ownerDoc).filter(function(activeElm) {
  22251. return !eq(focusedElem, activeElm);
  22252. }).filter(function(activeElm) {
  22253. return eq(activeElm, SugarElement.fromDom(ownerDoc.dom.body)) || contains(headerElem, activeElm);
  22254. }).each(function() {
  22255. return focus$3(focusedElem);
  22256. });
  22257. };
  22258. var findFocusedElem = function(rootElm, lazySink) {
  22259. return search(rootElm).orThunk(function() {
  22260. return lazySink().toOptional().bind(function(sink) {
  22261. return search(sink.element);
  22262. });
  22263. });
  22264. };
  22265. var setup$9 = function(editor, sharedBackstage, lazyHeader) {
  22266. if (!editor.inline) {
  22267. if (!sharedBackstage.header.isPositionedAtTop()) {
  22268. editor.on("ResizeEditor", function() {
  22269. lazyHeader().each(Docking.reset);
  22270. });
  22271. }
  22272. editor.on("ResizeWindow ResizeEditor", function() {
  22273. lazyHeader().each(updateIframeContentFlow);
  22274. });
  22275. editor.on("SkinLoaded", function() {
  22276. lazyHeader().each(function(comp) {
  22277. Docking.isDocked(comp) ? Docking.reset(comp) : Docking.refresh(comp);
  22278. });
  22279. });
  22280. editor.on("FullscreenStateChanged", function() {
  22281. lazyHeader().each(Docking.reset);
  22282. });
  22283. }
  22284. editor.on("AfterScrollIntoView", function(e) {
  22285. lazyHeader().each(function(header) {
  22286. Docking.refresh(header);
  22287. var headerElem = header.element;
  22288. if (isVisible(headerElem)) {
  22289. scrollFromBehindHeader(e, headerElem);
  22290. }
  22291. });
  22292. });
  22293. editor.on("PostRender", function() {
  22294. updateEditorClasses(editor, false);
  22295. });
  22296. };
  22297. var isDocked = function(lazyHeader) {
  22298. return lazyHeader().map(Docking.isDocked).getOr(false);
  22299. };
  22300. var getIframeBehaviours = function() {
  22301. var _a2;
  22302. return [Receiving.config({ channels: (_a2 = {}, _a2[toolbarHeightChange()] = { onReceive: updateIframeContentFlow }, _a2) })];
  22303. };
  22304. var getBehaviours = function(editor, sharedBackstage) {
  22305. var focusedElm = value$1();
  22306. var lazySink = sharedBackstage.getSink;
  22307. var runOnSinkElement = function(f) {
  22308. lazySink().each(function(sink) {
  22309. return f(sink.element);
  22310. });
  22311. };
  22312. var onDockingSwitch = function(comp) {
  22313. if (!editor.inline) {
  22314. updateIframeContentFlow(comp);
  22315. }
  22316. updateEditorClasses(editor, Docking.isDocked(comp));
  22317. comp.getSystem().broadcastOn([repositionPopups()], {});
  22318. lazySink().each(function(sink) {
  22319. return sink.getSystem().broadcastOn([repositionPopups()], {});
  22320. });
  22321. };
  22322. var additionalBehaviours = editor.inline ? [] : getIframeBehaviours();
  22323. return __spreadArray([
  22324. Focusing.config({}),
  22325. Docking.config({
  22326. contextual: __assign({
  22327. lazyContext: function(comp) {
  22328. var headerHeight = getOuter$2(comp.element);
  22329. var container = editor.inline ? editor.getContentAreaContainer() : editor.getContainer();
  22330. var box2 = box$1(SugarElement.fromDom(container));
  22331. var boxHeight = box2.height - headerHeight;
  22332. var topBound = box2.y + (isDockedMode(comp, "top") ? 0 : headerHeight);
  22333. return Optional.some(bounds(box2.x, topBound, box2.width, boxHeight));
  22334. },
  22335. onShow: function() {
  22336. runOnSinkElement(function(elem) {
  22337. return updateSinkVisibility(elem, true);
  22338. });
  22339. },
  22340. onShown: function(comp) {
  22341. runOnSinkElement(function(elem) {
  22342. return remove$1(elem, [
  22343. visibility.transitionClass,
  22344. visibility.fadeInClass
  22345. ]);
  22346. });
  22347. focusedElm.get().each(function(elem) {
  22348. restoreFocus(comp.element, elem);
  22349. focusedElm.clear();
  22350. });
  22351. },
  22352. onHide: function(comp) {
  22353. findFocusedElem(comp.element, lazySink).fold(focusedElm.clear, focusedElm.set);
  22354. runOnSinkElement(function(elem) {
  22355. return updateSinkVisibility(elem, false);
  22356. });
  22357. },
  22358. onHidden: function() {
  22359. runOnSinkElement(function(elem) {
  22360. return remove$1(elem, [visibility.transitionClass]);
  22361. });
  22362. }
  22363. }, visibility),
  22364. lazyViewport: function(comp) {
  22365. var win$1 = win();
  22366. var offset2 = getStickyToolbarOffset(editor);
  22367. var top2 = win$1.y + (isDockedMode(comp, "top") ? offset2 : 0);
  22368. var height2 = win$1.height - (isDockedMode(comp, "bottom") ? offset2 : 0);
  22369. return bounds(win$1.x, top2, win$1.width, height2);
  22370. },
  22371. modes: [sharedBackstage.header.getDockingMode()],
  22372. onDocked: onDockingSwitch,
  22373. onUndocked: onDockingSwitch
  22374. })
  22375. ], additionalBehaviours, true);
  22376. };
  22377. var StickyHeader = Object.freeze({
  22378. __proto__: null,
  22379. setup: setup$9,
  22380. isDocked,
  22381. getBehaviours
  22382. });
  22383. var renderHeader = function(spec) {
  22384. var editor = spec.editor;
  22385. var getBehaviours$22 = spec.sticky ? getBehaviours : getBehaviours$1;
  22386. return {
  22387. uid: spec.uid,
  22388. dom: spec.dom,
  22389. components: spec.components,
  22390. behaviours: derive$1(getBehaviours$22(editor, spec.sharedBackstage))
  22391. };
  22392. };
  22393. var groupToolbarButtonSchema = objOf([
  22394. requiredString("type"),
  22395. requiredOf("items", oneOf([
  22396. arrOfObj([
  22397. requiredString("name"),
  22398. requiredArrayOf("items", string)
  22399. ]),
  22400. string
  22401. ]))
  22402. ].concat(baseToolbarButtonFields));
  22403. var createGroupToolbarButton = function(spec) {
  22404. return asRaw("GroupToolbarButton", groupToolbarButtonSchema, spec);
  22405. };
  22406. var baseMenuButtonFields = [
  22407. optionString("text"),
  22408. optionString("tooltip"),
  22409. optionString("icon"),
  22410. requiredFunction("fetch"),
  22411. defaultedFunction("onSetup", function() {
  22412. return noop;
  22413. })
  22414. ];
  22415. var MenuButtonSchema = objOf(__spreadArray([requiredString("type")], baseMenuButtonFields, true));
  22416. var createMenuButton = function(spec) {
  22417. return asRaw("menubutton", MenuButtonSchema, spec);
  22418. };
  22419. var splitButtonSchema = objOf([
  22420. requiredString("type"),
  22421. optionString("tooltip"),
  22422. optionString("icon"),
  22423. optionString("text"),
  22424. optionFunction("select"),
  22425. requiredFunction("fetch"),
  22426. defaultedFunction("onSetup", function() {
  22427. return noop;
  22428. }),
  22429. defaultedStringEnum("presets", "normal", [
  22430. "normal",
  22431. "color",
  22432. "listpreview"
  22433. ]),
  22434. defaulted("columns", 1),
  22435. requiredFunction("onAction"),
  22436. requiredFunction("onItemAction")
  22437. ]);
  22438. var createSplitButton = function(spec) {
  22439. return asRaw("SplitButton", splitButtonSchema, spec);
  22440. };
  22441. var factory$b = function(detail, spec) {
  22442. var setMenus = function(comp, menus) {
  22443. var newMenus = map$2(menus, function(m) {
  22444. var buttonSpec = {
  22445. type: "menubutton",
  22446. text: m.text,
  22447. fetch: function(callback) {
  22448. callback(m.getItems());
  22449. }
  22450. };
  22451. var internal2 = createMenuButton(buttonSpec).mapError(function(errInfo) {
  22452. return formatError(errInfo);
  22453. }).getOrDie();
  22454. return renderMenuButton(internal2, "tox-mbtn", spec.backstage, Optional.some("menuitem"));
  22455. });
  22456. Replacing.set(comp, newMenus);
  22457. };
  22458. var apis = {
  22459. focus: Keying.focusIn,
  22460. setMenus
  22461. };
  22462. return {
  22463. uid: detail.uid,
  22464. dom: detail.dom,
  22465. components: [],
  22466. behaviours: derive$1([
  22467. Replacing.config({}),
  22468. config("menubar-events", [
  22469. runOnAttached(function(component) {
  22470. detail.onSetup(component);
  22471. }),
  22472. run$1(mouseover(), function(comp, se) {
  22473. descendant(comp.element, ".tox-mbtn--active").each(function(activeButton) {
  22474. closest$1(se.event.target, ".tox-mbtn").each(function(hoveredButton) {
  22475. if (!eq(activeButton, hoveredButton)) {
  22476. comp.getSystem().getByDom(activeButton).each(function(activeComp) {
  22477. comp.getSystem().getByDom(hoveredButton).each(function(hoveredComp) {
  22478. Dropdown.expand(hoveredComp);
  22479. Dropdown.close(activeComp);
  22480. Focusing.focus(hoveredComp);
  22481. });
  22482. });
  22483. }
  22484. });
  22485. });
  22486. }),
  22487. run$1(focusShifted(), function(comp, se) {
  22488. se.event.prevFocus.bind(function(prev) {
  22489. return comp.getSystem().getByDom(prev).toOptional();
  22490. }).each(function(prev) {
  22491. se.event.newFocus.bind(function(nu2) {
  22492. return comp.getSystem().getByDom(nu2).toOptional();
  22493. }).each(function(nu2) {
  22494. if (Dropdown.isOpen(prev)) {
  22495. Dropdown.expand(nu2);
  22496. Dropdown.close(prev);
  22497. }
  22498. });
  22499. });
  22500. })
  22501. ]),
  22502. Keying.config({
  22503. mode: "flow",
  22504. selector: ".tox-mbtn",
  22505. onEscape: function(comp) {
  22506. detail.onEscape(comp);
  22507. return Optional.some(true);
  22508. }
  22509. }),
  22510. Tabstopping.config({})
  22511. ]),
  22512. apis,
  22513. domModification: { attributes: { role: "menubar" } }
  22514. };
  22515. };
  22516. var SilverMenubar = single({
  22517. factory: factory$b,
  22518. name: "silver.Menubar",
  22519. configFields: [
  22520. required$1("dom"),
  22521. required$1("uid"),
  22522. required$1("onEscape"),
  22523. required$1("backstage"),
  22524. defaulted("onSetup", noop)
  22525. ],
  22526. apis: {
  22527. focus: function(apis, comp) {
  22528. apis.focus(comp);
  22529. },
  22530. setMenus: function(apis, comp, menus) {
  22531. apis.setMenus(comp, menus);
  22532. }
  22533. }
  22534. });
  22535. var getAnimationRoot = function(component, slideConfig) {
  22536. return slideConfig.getAnimationRoot.fold(function() {
  22537. return component.element;
  22538. }, function(get2) {
  22539. return get2(component);
  22540. });
  22541. };
  22542. var getDimensionProperty = function(slideConfig) {
  22543. return slideConfig.dimension.property;
  22544. };
  22545. var getDimension = function(slideConfig, elem) {
  22546. return slideConfig.dimension.getDimension(elem);
  22547. };
  22548. var disableTransitions = function(component, slideConfig) {
  22549. var root = getAnimationRoot(component, slideConfig);
  22550. remove$1(root, [
  22551. slideConfig.shrinkingClass,
  22552. slideConfig.growingClass
  22553. ]);
  22554. };
  22555. var setShrunk = function(component, slideConfig) {
  22556. remove$2(component.element, slideConfig.openClass);
  22557. add$2(component.element, slideConfig.closedClass);
  22558. set$7(component.element, getDimensionProperty(slideConfig), "0px");
  22559. reflow(component.element);
  22560. };
  22561. var setGrown = function(component, slideConfig) {
  22562. remove$2(component.element, slideConfig.closedClass);
  22563. add$2(component.element, slideConfig.openClass);
  22564. remove$6(component.element, getDimensionProperty(slideConfig));
  22565. };
  22566. var doImmediateShrink = function(component, slideConfig, slideState, _calculatedSize) {
  22567. slideState.setCollapsed();
  22568. set$7(component.element, getDimensionProperty(slideConfig), getDimension(slideConfig, component.element));
  22569. reflow(component.element);
  22570. disableTransitions(component, slideConfig);
  22571. setShrunk(component, slideConfig);
  22572. slideConfig.onStartShrink(component);
  22573. slideConfig.onShrunk(component);
  22574. };
  22575. var doStartShrink = function(component, slideConfig, slideState, calculatedSize) {
  22576. var size = calculatedSize.getOrThunk(function() {
  22577. return getDimension(slideConfig, component.element);
  22578. });
  22579. slideState.setCollapsed();
  22580. set$7(component.element, getDimensionProperty(slideConfig), size);
  22581. reflow(component.element);
  22582. var root = getAnimationRoot(component, slideConfig);
  22583. remove$2(root, slideConfig.growingClass);
  22584. add$2(root, slideConfig.shrinkingClass);
  22585. setShrunk(component, slideConfig);
  22586. slideConfig.onStartShrink(component);
  22587. };
  22588. var doStartSmartShrink = function(component, slideConfig, slideState) {
  22589. var size = getDimension(slideConfig, component.element);
  22590. var shrinker = size === "0px" ? doImmediateShrink : doStartShrink;
  22591. shrinker(component, slideConfig, slideState, Optional.some(size));
  22592. };
  22593. var doStartGrow = function(component, slideConfig, slideState) {
  22594. var root = getAnimationRoot(component, slideConfig);
  22595. var wasShrinking = has(root, slideConfig.shrinkingClass);
  22596. var beforeSize = getDimension(slideConfig, component.element);
  22597. setGrown(component, slideConfig);
  22598. var fullSize = getDimension(slideConfig, component.element);
  22599. var startPartialGrow = function() {
  22600. set$7(component.element, getDimensionProperty(slideConfig), beforeSize);
  22601. reflow(component.element);
  22602. };
  22603. var startCompleteGrow = function() {
  22604. setShrunk(component, slideConfig);
  22605. };
  22606. var setStartSize = wasShrinking ? startPartialGrow : startCompleteGrow;
  22607. setStartSize();
  22608. remove$2(root, slideConfig.shrinkingClass);
  22609. add$2(root, slideConfig.growingClass);
  22610. setGrown(component, slideConfig);
  22611. set$7(component.element, getDimensionProperty(slideConfig), fullSize);
  22612. slideState.setExpanded();
  22613. slideConfig.onStartGrow(component);
  22614. };
  22615. var refresh$3 = function(component, slideConfig, slideState) {
  22616. if (slideState.isExpanded()) {
  22617. remove$6(component.element, getDimensionProperty(slideConfig));
  22618. var fullSize = getDimension(slideConfig, component.element);
  22619. set$7(component.element, getDimensionProperty(slideConfig), fullSize);
  22620. }
  22621. };
  22622. var grow = function(component, slideConfig, slideState) {
  22623. if (!slideState.isExpanded()) {
  22624. doStartGrow(component, slideConfig, slideState);
  22625. }
  22626. };
  22627. var shrink = function(component, slideConfig, slideState) {
  22628. if (slideState.isExpanded()) {
  22629. doStartSmartShrink(component, slideConfig, slideState);
  22630. }
  22631. };
  22632. var immediateShrink = function(component, slideConfig, slideState) {
  22633. if (slideState.isExpanded()) {
  22634. doImmediateShrink(component, slideConfig, slideState);
  22635. }
  22636. };
  22637. var hasGrown = function(component, slideConfig, slideState) {
  22638. return slideState.isExpanded();
  22639. };
  22640. var hasShrunk = function(component, slideConfig, slideState) {
  22641. return slideState.isCollapsed();
  22642. };
  22643. var isGrowing = function(component, slideConfig, _slideState) {
  22644. var root = getAnimationRoot(component, slideConfig);
  22645. return has(root, slideConfig.growingClass) === true;
  22646. };
  22647. var isShrinking = function(component, slideConfig, _slideState) {
  22648. var root = getAnimationRoot(component, slideConfig);
  22649. return has(root, slideConfig.shrinkingClass) === true;
  22650. };
  22651. var isTransitioning = function(component, slideConfig, slideState) {
  22652. return isGrowing(component, slideConfig) || isShrinking(component, slideConfig);
  22653. };
  22654. var toggleGrow = function(component, slideConfig, slideState) {
  22655. var f = slideState.isExpanded() ? doStartSmartShrink : doStartGrow;
  22656. f(component, slideConfig, slideState);
  22657. };
  22658. var SlidingApis = Object.freeze({
  22659. __proto__: null,
  22660. refresh: refresh$3,
  22661. grow,
  22662. shrink,
  22663. immediateShrink,
  22664. hasGrown,
  22665. hasShrunk,
  22666. isGrowing,
  22667. isShrinking,
  22668. isTransitioning,
  22669. toggleGrow,
  22670. disableTransitions
  22671. });
  22672. var exhibit = function(base2, slideConfig, _slideState) {
  22673. var expanded = slideConfig.expanded;
  22674. return expanded ? nu$7({
  22675. classes: [slideConfig.openClass],
  22676. styles: {}
  22677. }) : nu$7({
  22678. classes: [slideConfig.closedClass],
  22679. styles: wrap$1(slideConfig.dimension.property, "0px")
  22680. });
  22681. };
  22682. var events$4 = function(slideConfig, slideState) {
  22683. return derive$2([runOnSource(transitionend(), function(component, simulatedEvent) {
  22684. var raw = simulatedEvent.event.raw;
  22685. if (raw.propertyName === slideConfig.dimension.property) {
  22686. disableTransitions(component, slideConfig);
  22687. if (slideState.isExpanded()) {
  22688. remove$6(component.element, slideConfig.dimension.property);
  22689. }
  22690. var notify = slideState.isExpanded() ? slideConfig.onGrown : slideConfig.onShrunk;
  22691. notify(component);
  22692. }
  22693. })]);
  22694. };
  22695. var ActiveSliding = Object.freeze({
  22696. __proto__: null,
  22697. exhibit,
  22698. events: events$4
  22699. });
  22700. var SlidingSchema = [
  22701. required$1("closedClass"),
  22702. required$1("openClass"),
  22703. required$1("shrinkingClass"),
  22704. required$1("growingClass"),
  22705. option("getAnimationRoot"),
  22706. onHandler("onShrunk"),
  22707. onHandler("onStartShrink"),
  22708. onHandler("onGrown"),
  22709. onHandler("onStartGrow"),
  22710. defaulted("expanded", false),
  22711. requiredOf("dimension", choose$1("property", {
  22712. width: [
  22713. output$1("property", "width"),
  22714. output$1("getDimension", function(elem) {
  22715. return get$a(elem) + "px";
  22716. })
  22717. ],
  22718. height: [
  22719. output$1("property", "height"),
  22720. output$1("getDimension", function(elem) {
  22721. return get$b(elem) + "px";
  22722. })
  22723. ]
  22724. }))
  22725. ];
  22726. var init$5 = function(spec) {
  22727. var state = Cell(spec.expanded);
  22728. var readState = function() {
  22729. return "expanded: " + state.get();
  22730. };
  22731. return nu$8({
  22732. isExpanded: function() {
  22733. return state.get() === true;
  22734. },
  22735. isCollapsed: function() {
  22736. return state.get() === false;
  22737. },
  22738. setCollapsed: curry(state.set, false),
  22739. setExpanded: curry(state.set, true),
  22740. readState
  22741. });
  22742. };
  22743. var SlidingState = Object.freeze({
  22744. __proto__: null,
  22745. init: init$5
  22746. });
  22747. var Sliding = create$7({
  22748. fields: SlidingSchema,
  22749. name: "sliding",
  22750. active: ActiveSliding,
  22751. apis: SlidingApis,
  22752. state: SlidingState
  22753. });
  22754. var owner = "container";
  22755. var schema$d = [field("slotBehaviours", [])];
  22756. var getPartName = function(name2) {
  22757. return "<alloy.field." + name2 + ">";
  22758. };
  22759. var sketch = function(sSpec) {
  22760. var parts2 = function() {
  22761. var record2 = [];
  22762. var slot = function(name2, config2) {
  22763. record2.push(name2);
  22764. return generateOne$1(owner, getPartName(name2), config2);
  22765. };
  22766. return {
  22767. slot,
  22768. record: constant$1(record2)
  22769. };
  22770. }();
  22771. var spec = sSpec(parts2);
  22772. var partNames = parts2.record();
  22773. var fieldParts = map$2(partNames, function(n) {
  22774. return required({
  22775. name: n,
  22776. pname: getPartName(n)
  22777. });
  22778. });
  22779. return composite$1(owner, schema$d, fieldParts, make$1, spec);
  22780. };
  22781. var make$1 = function(detail, components2) {
  22782. var getSlotNames = function(_) {
  22783. return getAllPartNames(detail);
  22784. };
  22785. var getSlot = function(container, key) {
  22786. return getPart(container, detail, key);
  22787. };
  22788. var onSlot = function(f, def) {
  22789. return function(container, key) {
  22790. return getPart(container, detail, key).map(function(slot) {
  22791. return f(slot, key);
  22792. }).getOr(def);
  22793. };
  22794. };
  22795. var onSlots = function(f) {
  22796. return function(container, keys2) {
  22797. each$1(keys2, function(key) {
  22798. return f(container, key);
  22799. });
  22800. };
  22801. };
  22802. var doShowing = function(comp, _key) {
  22803. return get$d(comp.element, "aria-hidden") !== "true";
  22804. };
  22805. var doShow = function(comp, key) {
  22806. if (!doShowing(comp)) {
  22807. var element2 = comp.element;
  22808. remove$6(element2, "display");
  22809. remove$7(element2, "aria-hidden");
  22810. emitWith(comp, slotVisibility(), {
  22811. name: key,
  22812. visible: true
  22813. });
  22814. }
  22815. };
  22816. var doHide = function(comp, key) {
  22817. if (doShowing(comp)) {
  22818. var element2 = comp.element;
  22819. set$7(element2, "display", "none");
  22820. set$8(element2, "aria-hidden", "true");
  22821. emitWith(comp, slotVisibility(), {
  22822. name: key,
  22823. visible: false
  22824. });
  22825. }
  22826. };
  22827. var isShowing = onSlot(doShowing, false);
  22828. var hideSlot = onSlot(doHide);
  22829. var hideSlots = onSlots(hideSlot);
  22830. var hideAllSlots = function(container) {
  22831. return hideSlots(container, getSlotNames());
  22832. };
  22833. var showSlot = onSlot(doShow);
  22834. var apis = {
  22835. getSlotNames,
  22836. getSlot,
  22837. isShowing,
  22838. hideSlot,
  22839. hideAllSlots,
  22840. showSlot
  22841. };
  22842. return {
  22843. uid: detail.uid,
  22844. dom: detail.dom,
  22845. components: components2,
  22846. behaviours: get$2(detail.slotBehaviours),
  22847. apis
  22848. };
  22849. };
  22850. var slotApis = map$1({
  22851. getSlotNames: function(apis, c) {
  22852. return apis.getSlotNames(c);
  22853. },
  22854. getSlot: function(apis, c, key) {
  22855. return apis.getSlot(c, key);
  22856. },
  22857. isShowing: function(apis, c, key) {
  22858. return apis.isShowing(c, key);
  22859. },
  22860. hideSlot: function(apis, c, key) {
  22861. return apis.hideSlot(c, key);
  22862. },
  22863. hideAllSlots: function(apis, c) {
  22864. return apis.hideAllSlots(c);
  22865. },
  22866. showSlot: function(apis, c, key) {
  22867. return apis.showSlot(c, key);
  22868. }
  22869. }, function(value2) {
  22870. return makeApi(value2);
  22871. });
  22872. var SlotContainer = __assign(__assign({}, slotApis), { sketch });
  22873. var sidebarSchema = objOf([
  22874. optionString("icon"),
  22875. optionString("tooltip"),
  22876. defaultedFunction("onShow", noop),
  22877. defaultedFunction("onHide", noop),
  22878. defaultedFunction("onSetup", function() {
  22879. return noop;
  22880. })
  22881. ]);
  22882. var createSidebar = function(spec) {
  22883. return asRaw("sidebar", sidebarSchema, spec);
  22884. };
  22885. var setup$8 = function(editor) {
  22886. var sidebars = editor.ui.registry.getAll().sidebars;
  22887. each$1(keys(sidebars), function(name2) {
  22888. var spec = sidebars[name2];
  22889. var isActive = function() {
  22890. return is$1(Optional.from(editor.queryCommandValue("ToggleSidebar")), name2);
  22891. };
  22892. editor.ui.registry.addToggleButton(name2, {
  22893. icon: spec.icon,
  22894. tooltip: spec.tooltip,
  22895. onAction: function(buttonApi) {
  22896. editor.execCommand("ToggleSidebar", false, name2);
  22897. buttonApi.setActive(isActive());
  22898. },
  22899. onSetup: function(buttonApi) {
  22900. var handleToggle = function() {
  22901. return buttonApi.setActive(isActive());
  22902. };
  22903. editor.on("ToggleSidebar", handleToggle);
  22904. return function() {
  22905. editor.off("ToggleSidebar", handleToggle);
  22906. };
  22907. }
  22908. });
  22909. });
  22910. };
  22911. var getApi = function(comp) {
  22912. return {
  22913. element: function() {
  22914. return comp.element.dom;
  22915. }
  22916. };
  22917. };
  22918. var makePanels = function(parts2, panelConfigs) {
  22919. var specs = map$2(keys(panelConfigs), function(name2) {
  22920. var spec = panelConfigs[name2];
  22921. var bridged = getOrDie(createSidebar(spec));
  22922. return {
  22923. name: name2,
  22924. getApi,
  22925. onSetup: bridged.onSetup,
  22926. onShow: bridged.onShow,
  22927. onHide: bridged.onHide
  22928. };
  22929. });
  22930. return map$2(specs, function(spec) {
  22931. var editorOffCell = Cell(noop);
  22932. return parts2.slot(spec.name, {
  22933. dom: {
  22934. tag: "div",
  22935. classes: ["tox-sidebar__pane"]
  22936. },
  22937. behaviours: SimpleBehaviours.unnamedEvents([
  22938. onControlAttached(spec, editorOffCell),
  22939. onControlDetached(spec, editorOffCell),
  22940. run$1(slotVisibility(), function(sidepanel, se) {
  22941. var data = se.event;
  22942. var optSidePanelSpec = find$5(specs, function(config2) {
  22943. return config2.name === data.name;
  22944. });
  22945. optSidePanelSpec.each(function(sidePanelSpec) {
  22946. var handler = data.visible ? sidePanelSpec.onShow : sidePanelSpec.onHide;
  22947. handler(sidePanelSpec.getApi(sidepanel));
  22948. });
  22949. })
  22950. ])
  22951. });
  22952. });
  22953. };
  22954. var makeSidebar = function(panelConfigs) {
  22955. return SlotContainer.sketch(function(parts2) {
  22956. return {
  22957. dom: {
  22958. tag: "div",
  22959. classes: ["tox-sidebar__pane-container"]
  22960. },
  22961. components: makePanels(parts2, panelConfigs),
  22962. slotBehaviours: SimpleBehaviours.unnamedEvents([runOnAttached(function(slotContainer) {
  22963. return SlotContainer.hideAllSlots(slotContainer);
  22964. })])
  22965. };
  22966. });
  22967. };
  22968. var setSidebar = function(sidebar, panelConfigs) {
  22969. var optSlider = Composing.getCurrent(sidebar);
  22970. optSlider.each(function(slider) {
  22971. return Replacing.set(slider, [makeSidebar(panelConfigs)]);
  22972. });
  22973. };
  22974. var toggleSidebar = function(sidebar, name2) {
  22975. var optSlider = Composing.getCurrent(sidebar);
  22976. optSlider.each(function(slider) {
  22977. var optSlotContainer = Composing.getCurrent(slider);
  22978. optSlotContainer.each(function(slotContainer) {
  22979. if (Sliding.hasGrown(slider)) {
  22980. if (SlotContainer.isShowing(slotContainer, name2)) {
  22981. Sliding.shrink(slider);
  22982. } else {
  22983. SlotContainer.hideAllSlots(slotContainer);
  22984. SlotContainer.showSlot(slotContainer, name2);
  22985. }
  22986. } else {
  22987. SlotContainer.hideAllSlots(slotContainer);
  22988. SlotContainer.showSlot(slotContainer, name2);
  22989. Sliding.grow(slider);
  22990. }
  22991. });
  22992. });
  22993. };
  22994. var whichSidebar = function(sidebar) {
  22995. var optSlider = Composing.getCurrent(sidebar);
  22996. return optSlider.bind(function(slider) {
  22997. var sidebarOpen = Sliding.isGrowing(slider) || Sliding.hasGrown(slider);
  22998. if (sidebarOpen) {
  22999. var optSlotContainer = Composing.getCurrent(slider);
  23000. return optSlotContainer.bind(function(slotContainer) {
  23001. return find$5(SlotContainer.getSlotNames(slotContainer), function(name2) {
  23002. return SlotContainer.isShowing(slotContainer, name2);
  23003. });
  23004. });
  23005. } else {
  23006. return Optional.none();
  23007. }
  23008. });
  23009. };
  23010. var fixSize = generate$6("FixSizeEvent");
  23011. var autoSize = generate$6("AutoSizeEvent");
  23012. var renderSidebar = function(spec) {
  23013. return {
  23014. uid: spec.uid,
  23015. dom: {
  23016. tag: "div",
  23017. classes: ["tox-sidebar"],
  23018. attributes: { role: "complementary" }
  23019. },
  23020. components: [{
  23021. dom: {
  23022. tag: "div",
  23023. classes: ["tox-sidebar__slider"]
  23024. },
  23025. components: [],
  23026. behaviours: derive$1([
  23027. Tabstopping.config({}),
  23028. Focusing.config({}),
  23029. Sliding.config({
  23030. dimension: { property: "width" },
  23031. closedClass: "tox-sidebar--sliding-closed",
  23032. openClass: "tox-sidebar--sliding-open",
  23033. shrinkingClass: "tox-sidebar--sliding-shrinking",
  23034. growingClass: "tox-sidebar--sliding-growing",
  23035. onShrunk: function(slider) {
  23036. var optSlotContainer = Composing.getCurrent(slider);
  23037. optSlotContainer.each(SlotContainer.hideAllSlots);
  23038. emit(slider, autoSize);
  23039. },
  23040. onGrown: function(slider) {
  23041. emit(slider, autoSize);
  23042. },
  23043. onStartGrow: function(slider) {
  23044. emitWith(slider, fixSize, { width: getRaw(slider.element, "width").getOr("") });
  23045. },
  23046. onStartShrink: function(slider) {
  23047. emitWith(slider, fixSize, { width: get$a(slider.element) + "px" });
  23048. }
  23049. }),
  23050. Replacing.config({}),
  23051. Composing.config({
  23052. find: function(comp) {
  23053. var children2 = Replacing.contents(comp);
  23054. return head(children2);
  23055. }
  23056. })
  23057. ])
  23058. }],
  23059. behaviours: derive$1([
  23060. ComposingConfigs.childAt(0),
  23061. config("sidebar-sliding-events", [
  23062. run$1(fixSize, function(comp, se) {
  23063. set$7(comp.element, "width", se.event.width);
  23064. }),
  23065. run$1(autoSize, function(comp, _se) {
  23066. remove$6(comp.element, "width");
  23067. })
  23068. ])
  23069. ])
  23070. };
  23071. };
  23072. var block = function(component, config2, state, getBusySpec2) {
  23073. set$8(component.element, "aria-busy", true);
  23074. var root = config2.getRoot(component).getOr(component);
  23075. var blockerBehaviours = derive$1([
  23076. Keying.config({
  23077. mode: "special",
  23078. onTab: function() {
  23079. return Optional.some(true);
  23080. },
  23081. onShiftTab: function() {
  23082. return Optional.some(true);
  23083. }
  23084. }),
  23085. Focusing.config({})
  23086. ]);
  23087. var blockSpec = getBusySpec2(root, blockerBehaviours);
  23088. var blocker = root.getSystem().build(blockSpec);
  23089. Replacing.append(root, premade(blocker));
  23090. if (blocker.hasConfigured(Keying) && config2.focus) {
  23091. Keying.focusIn(blocker);
  23092. }
  23093. if (!state.isBlocked()) {
  23094. config2.onBlock(component);
  23095. }
  23096. state.blockWith(function() {
  23097. return Replacing.remove(root, blocker);
  23098. });
  23099. };
  23100. var unblock = function(component, config2, state) {
  23101. remove$7(component.element, "aria-busy");
  23102. if (state.isBlocked()) {
  23103. config2.onUnblock(component);
  23104. }
  23105. state.clear();
  23106. };
  23107. var BlockingApis = Object.freeze({
  23108. __proto__: null,
  23109. block,
  23110. unblock
  23111. });
  23112. var BlockingSchema = [
  23113. defaultedFunction("getRoot", Optional.none),
  23114. defaultedBoolean("focus", true),
  23115. onHandler("onBlock"),
  23116. onHandler("onUnblock")
  23117. ];
  23118. var init$4 = function() {
  23119. var blocker = destroyable();
  23120. var blockWith = function(destroy) {
  23121. blocker.set({ destroy });
  23122. };
  23123. return nu$8({
  23124. readState: blocker.isSet,
  23125. blockWith,
  23126. clear: blocker.clear,
  23127. isBlocked: blocker.isSet
  23128. });
  23129. };
  23130. var BlockingState = Object.freeze({
  23131. __proto__: null,
  23132. init: init$4
  23133. });
  23134. var Blocking = create$7({
  23135. fields: BlockingSchema,
  23136. name: "blocking",
  23137. apis: BlockingApis,
  23138. state: BlockingState
  23139. });
  23140. var getAttrs = function(elem) {
  23141. var attributes = elem.dom.attributes !== void 0 ? elem.dom.attributes : [];
  23142. return foldl(attributes, function(b2, attr) {
  23143. var _a2;
  23144. if (attr.name === "class") {
  23145. return b2;
  23146. } else {
  23147. return __assign(__assign({}, b2), (_a2 = {}, _a2[attr.name] = attr.value, _a2));
  23148. }
  23149. }, {});
  23150. };
  23151. var getClasses = function(elem) {
  23152. return Array.prototype.slice.call(elem.dom.classList, 0);
  23153. };
  23154. var fromHtml = function(html) {
  23155. var elem = SugarElement.fromHtml(html);
  23156. var children$1 = children(elem);
  23157. var attrs = getAttrs(elem);
  23158. var classes2 = getClasses(elem);
  23159. var contents2 = children$1.length === 0 ? {} : { innerHtml: get$7(elem) };
  23160. return __assign({
  23161. tag: name$2(elem),
  23162. classes: classes2,
  23163. attributes: attrs
  23164. }, contents2);
  23165. };
  23166. var getBusySpec$1 = function(providerBackstage) {
  23167. return function(_root, _behaviours) {
  23168. return {
  23169. dom: {
  23170. tag: "div",
  23171. attributes: {
  23172. "aria-label": providerBackstage.translate("Loading..."),
  23173. "tabindex": "0"
  23174. },
  23175. classes: ["tox-throbber__busy-spinner"]
  23176. },
  23177. components: [{ dom: fromHtml('<div class="tox-spinner"><div></div><div></div><div></div></div>') }]
  23178. };
  23179. };
  23180. };
  23181. var focusBusyComponent = function(throbber) {
  23182. return Composing.getCurrent(throbber).each(function(comp) {
  23183. return focus$3(comp.element);
  23184. });
  23185. };
  23186. var toggleEditorTabIndex = function(editor, state) {
  23187. var tabIndexAttr = "tabindex";
  23188. var dataTabIndexAttr = "data-mce-" + tabIndexAttr;
  23189. Optional.from(editor.iframeElement).map(SugarElement.fromDom).each(function(iframe2) {
  23190. if (state) {
  23191. getOpt(iframe2, tabIndexAttr).each(function(tabIndex) {
  23192. return set$8(iframe2, dataTabIndexAttr, tabIndex);
  23193. });
  23194. set$8(iframe2, tabIndexAttr, -1);
  23195. } else {
  23196. remove$7(iframe2, tabIndexAttr);
  23197. getOpt(iframe2, dataTabIndexAttr).each(function(tabIndex) {
  23198. set$8(iframe2, tabIndexAttr, tabIndex);
  23199. remove$7(iframe2, dataTabIndexAttr);
  23200. });
  23201. }
  23202. });
  23203. };
  23204. var toggleThrobber = function(editor, comp, state, providerBackstage) {
  23205. var element2 = comp.element;
  23206. toggleEditorTabIndex(editor, state);
  23207. if (state) {
  23208. Blocking.block(comp, getBusySpec$1(providerBackstage));
  23209. remove$6(element2, "display");
  23210. remove$7(element2, "aria-hidden");
  23211. if (editor.hasFocus()) {
  23212. focusBusyComponent(comp);
  23213. }
  23214. } else {
  23215. var throbberFocus = Composing.getCurrent(comp).exists(function(busyComp) {
  23216. return hasFocus(busyComp.element);
  23217. });
  23218. Blocking.unblock(comp);
  23219. set$7(element2, "display", "none");
  23220. set$8(element2, "aria-hidden", "true");
  23221. if (throbberFocus) {
  23222. editor.focus();
  23223. }
  23224. }
  23225. };
  23226. var renderThrobber = function(spec) {
  23227. return {
  23228. uid: spec.uid,
  23229. dom: {
  23230. tag: "div",
  23231. attributes: { "aria-hidden": "true" },
  23232. classes: ["tox-throbber"],
  23233. styles: { display: "none" }
  23234. },
  23235. behaviours: derive$1([
  23236. Replacing.config({}),
  23237. Blocking.config({ focus: false }),
  23238. Composing.config({
  23239. find: function(comp) {
  23240. return head(comp.components());
  23241. }
  23242. })
  23243. ]),
  23244. components: []
  23245. };
  23246. };
  23247. var isFocusEvent = function(event) {
  23248. return event.type === "focusin";
  23249. };
  23250. var isPasteBinTarget = function(event) {
  23251. if (isFocusEvent(event)) {
  23252. var node = event.composed ? head(event.composedPath()) : Optional.from(event.target);
  23253. return node.map(SugarElement.fromDom).filter(isElement$2).exists(function(targetElm) {
  23254. return has(targetElm, "mce-pastebin");
  23255. });
  23256. } else {
  23257. return false;
  23258. }
  23259. };
  23260. var setup$7 = function(editor, lazyThrobber, sharedBackstage) {
  23261. var throbberState = Cell(false);
  23262. var timer = value$1();
  23263. var stealFocus = function(e) {
  23264. if (throbberState.get() && !isPasteBinTarget(e)) {
  23265. e.preventDefault();
  23266. focusBusyComponent(lazyThrobber());
  23267. editor.editorManager.setActive(editor);
  23268. }
  23269. };
  23270. if (!editor.inline) {
  23271. editor.on("PreInit", function() {
  23272. editor.dom.bind(editor.getWin(), "focusin", stealFocus);
  23273. editor.on("BeforeExecCommand", function(e) {
  23274. if (e.command.toLowerCase() === "mcefocus" && e.value !== true) {
  23275. stealFocus(e);
  23276. }
  23277. });
  23278. });
  23279. }
  23280. var toggle2 = function(state) {
  23281. if (state !== throbberState.get()) {
  23282. throbberState.set(state);
  23283. toggleThrobber(editor, lazyThrobber(), state, sharedBackstage.providers);
  23284. editor.fire("AfterProgressState", { state });
  23285. }
  23286. };
  23287. editor.on("ProgressState", function(e) {
  23288. timer.on(global$f.clearTimeout);
  23289. if (isNumber(e.time)) {
  23290. var timerId = global$f.setEditorTimeout(editor, function() {
  23291. return toggle2(e.state);
  23292. }, e.time);
  23293. timer.set(timerId);
  23294. } else {
  23295. toggle2(e.state);
  23296. timer.clear();
  23297. }
  23298. });
  23299. };
  23300. var generate$1 = function(xs, f) {
  23301. var init2 = {
  23302. len: 0,
  23303. list: []
  23304. };
  23305. var r2 = foldl(xs, function(b2, a) {
  23306. var value2 = f(a, b2.len);
  23307. return value2.fold(constant$1(b2), function(v) {
  23308. return {
  23309. len: v.finish,
  23310. list: b2.list.concat([v])
  23311. };
  23312. });
  23313. }, init2);
  23314. return r2.list;
  23315. };
  23316. var output = function(within, extra, withinWidth) {
  23317. return {
  23318. within,
  23319. extra,
  23320. withinWidth
  23321. };
  23322. };
  23323. var apportion = function(units2, total, len) {
  23324. var parray = generate$1(units2, function(unit, current) {
  23325. var width2 = len(unit);
  23326. return Optional.some({
  23327. element: unit,
  23328. start: current,
  23329. finish: current + width2,
  23330. width: width2
  23331. });
  23332. });
  23333. var within = filter$2(parray, function(unit) {
  23334. return unit.finish <= total;
  23335. });
  23336. var withinWidth = foldr(within, function(acc, el) {
  23337. return acc + el.width;
  23338. }, 0);
  23339. var extra = parray.slice(within.length);
  23340. return {
  23341. within,
  23342. extra,
  23343. withinWidth
  23344. };
  23345. };
  23346. var toUnit = function(parray) {
  23347. return map$2(parray, function(unit) {
  23348. return unit.element;
  23349. });
  23350. };
  23351. var fitLast = function(within, extra, withinWidth) {
  23352. var fits = toUnit(within.concat(extra));
  23353. return output(fits, [], withinWidth);
  23354. };
  23355. var overflow = function(within, extra, overflower, withinWidth) {
  23356. var fits = toUnit(within).concat([overflower]);
  23357. return output(fits, toUnit(extra), withinWidth);
  23358. };
  23359. var fitAll = function(within, extra, withinWidth) {
  23360. return output(toUnit(within), [], withinWidth);
  23361. };
  23362. var tryFit = function(total, units2, len) {
  23363. var divide = apportion(units2, total, len);
  23364. return divide.extra.length === 0 ? Optional.some(divide) : Optional.none();
  23365. };
  23366. var partition = function(total, units2, len, overflower) {
  23367. var divide = tryFit(total, units2, len).getOrThunk(function() {
  23368. return apportion(units2, total - len(overflower), len);
  23369. });
  23370. var within = divide.within;
  23371. var extra = divide.extra;
  23372. var withinWidth = divide.withinWidth;
  23373. if (extra.length === 1 && extra[0].width <= len(overflower)) {
  23374. return fitLast(within, extra, withinWidth);
  23375. } else if (extra.length >= 1) {
  23376. return overflow(within, extra, overflower, withinWidth);
  23377. } else {
  23378. return fitAll(within, extra, withinWidth);
  23379. }
  23380. };
  23381. var setGroups$1 = function(toolbar, storedGroups) {
  23382. var bGroups = map$2(storedGroups, function(g) {
  23383. return premade(g);
  23384. });
  23385. Toolbar.setGroups(toolbar, bGroups);
  23386. };
  23387. var findFocusedComp = function(comps) {
  23388. return findMap(comps, function(comp) {
  23389. return search(comp.element).bind(function(focusedElm) {
  23390. return comp.getSystem().getByDom(focusedElm).toOptional();
  23391. });
  23392. });
  23393. };
  23394. var refresh$2 = function(toolbar, detail, setOverflow) {
  23395. var builtGroups = detail.builtGroups.get();
  23396. if (builtGroups.length === 0) {
  23397. return;
  23398. }
  23399. var primary = getPartOrDie(toolbar, detail, "primary");
  23400. var overflowGroup = Coupling.getCoupled(toolbar, "overflowGroup");
  23401. set$7(primary.element, "visibility", "hidden");
  23402. var groups = builtGroups.concat([overflowGroup]);
  23403. var focusedComp = findFocusedComp(groups);
  23404. setOverflow([]);
  23405. setGroups$1(primary, groups);
  23406. var availableWidth = get$a(primary.element);
  23407. var overflows = partition(availableWidth, detail.builtGroups.get(), function(comp) {
  23408. return get$a(comp.element);
  23409. }, overflowGroup);
  23410. if (overflows.extra.length === 0) {
  23411. Replacing.remove(primary, overflowGroup);
  23412. setOverflow([]);
  23413. } else {
  23414. setGroups$1(primary, overflows.within);
  23415. setOverflow(overflows.extra);
  23416. }
  23417. remove$6(primary.element, "visibility");
  23418. reflow(primary.element);
  23419. focusedComp.each(Focusing.focus);
  23420. };
  23421. var schema$c = constant$1([
  23422. field("splitToolbarBehaviours", [Coupling]),
  23423. customField("builtGroups", function() {
  23424. return Cell([]);
  23425. })
  23426. ]);
  23427. var schema$b = constant$1([
  23428. markers$1(["overflowToggledClass"]),
  23429. optionFunction("getOverflowBounds"),
  23430. required$1("lazySink"),
  23431. customField("overflowGroups", function() {
  23432. return Cell([]);
  23433. })
  23434. ].concat(schema$c()));
  23435. var parts$7 = constant$1([
  23436. required({
  23437. factory: Toolbar,
  23438. schema: schema$e(),
  23439. name: "primary"
  23440. }),
  23441. external$1({
  23442. schema: schema$e(),
  23443. name: "overflow"
  23444. }),
  23445. external$1({ name: "overflow-button" }),
  23446. external$1({ name: "overflow-group" })
  23447. ]);
  23448. var expandable = constant$1(function(element2, available) {
  23449. setMax(element2, Math.floor(available));
  23450. });
  23451. var schema$a = constant$1([
  23452. markers$1(["toggledClass"]),
  23453. required$1("lazySink"),
  23454. requiredFunction("fetch"),
  23455. optionFunction("getBounds"),
  23456. optionObjOf("fireDismissalEventInstead", [defaulted("event", dismissRequested())]),
  23457. schema$y()
  23458. ]);
  23459. var parts$6 = constant$1([
  23460. external$1({
  23461. name: "button",
  23462. overrides: function(detail) {
  23463. return {
  23464. dom: { attributes: { "aria-haspopup": "true" } },
  23465. buttonBehaviours: derive$1([Toggling.config({
  23466. toggleClass: detail.markers.toggledClass,
  23467. aria: { mode: "expanded" },
  23468. toggleOnExecute: false
  23469. })])
  23470. };
  23471. }
  23472. }),
  23473. external$1({
  23474. factory: Toolbar,
  23475. schema: schema$e(),
  23476. name: "toolbar",
  23477. overrides: function(detail) {
  23478. return {
  23479. toolbarBehaviours: derive$1([Keying.config({
  23480. mode: "cyclic",
  23481. onEscape: function(comp) {
  23482. getPart(comp, detail, "button").each(Focusing.focus);
  23483. return Optional.none();
  23484. }
  23485. })])
  23486. };
  23487. }
  23488. })
  23489. ]);
  23490. var toggle = function(button2, externals) {
  23491. var toolbarSandbox = Coupling.getCoupled(button2, "toolbarSandbox");
  23492. if (Sandboxing.isOpen(toolbarSandbox)) {
  23493. Sandboxing.close(toolbarSandbox);
  23494. } else {
  23495. Sandboxing.open(toolbarSandbox, externals.toolbar());
  23496. }
  23497. };
  23498. var position = function(button2, toolbar, detail, layouts2) {
  23499. var bounds2 = detail.getBounds.map(function(bounder) {
  23500. return bounder();
  23501. });
  23502. var sink = detail.lazySink(button2).getOrDie();
  23503. Positioning.positionWithinBounds(sink, toolbar, {
  23504. anchor: {
  23505. type: "hotspot",
  23506. hotspot: button2,
  23507. layouts: layouts2,
  23508. overrides: { maxWidthFunction: expandable() }
  23509. }
  23510. }, bounds2);
  23511. };
  23512. var setGroups = function(button2, toolbar, detail, layouts2, groups) {
  23513. Toolbar.setGroups(toolbar, groups);
  23514. position(button2, toolbar, detail, layouts2);
  23515. Toggling.on(button2);
  23516. };
  23517. var makeSandbox = function(button2, spec, detail) {
  23518. var ariaOwner = manager();
  23519. var onOpen = function(sandbox, toolbar) {
  23520. detail.fetch().get(function(groups) {
  23521. setGroups(button2, toolbar, detail, spec.layouts, groups);
  23522. ariaOwner.link(button2.element);
  23523. Keying.focusIn(toolbar);
  23524. });
  23525. };
  23526. var onClose = function() {
  23527. Toggling.off(button2);
  23528. Focusing.focus(button2);
  23529. ariaOwner.unlink(button2.element);
  23530. };
  23531. return {
  23532. dom: {
  23533. tag: "div",
  23534. attributes: { id: ariaOwner.id }
  23535. },
  23536. behaviours: derive$1([
  23537. Keying.config({
  23538. mode: "special",
  23539. onEscape: function(comp) {
  23540. Sandboxing.close(comp);
  23541. return Optional.some(true);
  23542. }
  23543. }),
  23544. Sandboxing.config({
  23545. onOpen,
  23546. onClose,
  23547. isPartOf: function(container, data, queryElem) {
  23548. return isPartOf$1(data, queryElem) || isPartOf$1(button2, queryElem);
  23549. },
  23550. getAttachPoint: function() {
  23551. return detail.lazySink(button2).getOrDie();
  23552. }
  23553. }),
  23554. Receiving.config({
  23555. channels: __assign(__assign({}, receivingChannel$1(__assign({ isExtraPart: never }, detail.fireDismissalEventInstead.map(function(fe) {
  23556. return { fireEventInstead: { event: fe.event } };
  23557. }).getOr({})))), receivingChannel({
  23558. doReposition: function() {
  23559. Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox")).each(function(toolbar) {
  23560. position(button2, toolbar, detail, spec.layouts);
  23561. });
  23562. }
  23563. }))
  23564. })
  23565. ])
  23566. };
  23567. };
  23568. var factory$a = function(detail, components2, spec, externals) {
  23569. return __assign(__assign({}, Button.sketch(__assign(__assign({}, externals.button()), {
  23570. action: function(button2) {
  23571. toggle(button2, externals);
  23572. },
  23573. buttonBehaviours: SketchBehaviours.augment({ dump: externals.button().buttonBehaviours }, [Coupling.config({
  23574. others: {
  23575. toolbarSandbox: function(button2) {
  23576. return makeSandbox(button2, spec, detail);
  23577. }
  23578. }
  23579. })])
  23580. }))), {
  23581. apis: {
  23582. setGroups: function(button2, groups) {
  23583. Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox")).each(function(toolbar) {
  23584. setGroups(button2, toolbar, detail, spec.layouts, groups);
  23585. });
  23586. },
  23587. reposition: function(button2) {
  23588. Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox")).each(function(toolbar) {
  23589. position(button2, toolbar, detail, spec.layouts);
  23590. });
  23591. },
  23592. toggle: function(button2) {
  23593. toggle(button2, externals);
  23594. },
  23595. getToolbar: function(button2) {
  23596. return Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox"));
  23597. },
  23598. isOpen: function(button2) {
  23599. return Sandboxing.isOpen(Coupling.getCoupled(button2, "toolbarSandbox"));
  23600. }
  23601. }
  23602. });
  23603. };
  23604. var FloatingToolbarButton = composite({
  23605. name: "FloatingToolbarButton",
  23606. factory: factory$a,
  23607. configFields: schema$a(),
  23608. partFields: parts$6(),
  23609. apis: {
  23610. setGroups: function(apis, button2, groups) {
  23611. apis.setGroups(button2, groups);
  23612. },
  23613. reposition: function(apis, button2) {
  23614. apis.reposition(button2);
  23615. },
  23616. toggle: function(apis, button2) {
  23617. apis.toggle(button2);
  23618. },
  23619. getToolbar: function(apis, button2) {
  23620. return apis.getToolbar(button2);
  23621. },
  23622. isOpen: function(apis, button2) {
  23623. return apis.isOpen(button2);
  23624. }
  23625. }
  23626. });
  23627. var schema$9 = constant$1([
  23628. required$1("items"),
  23629. markers$1(["itemSelector"]),
  23630. field("tgroupBehaviours", [Keying])
  23631. ]);
  23632. var parts$5 = constant$1([group({
  23633. name: "items",
  23634. unit: "item"
  23635. })]);
  23636. var factory$9 = function(detail, components2, _spec, _externals) {
  23637. return {
  23638. uid: detail.uid,
  23639. dom: detail.dom,
  23640. components: components2,
  23641. behaviours: augment(detail.tgroupBehaviours, [Keying.config({
  23642. mode: "flow",
  23643. selector: detail.markers.itemSelector
  23644. })]),
  23645. domModification: { attributes: { role: "toolbar" } }
  23646. };
  23647. };
  23648. var ToolbarGroup = composite({
  23649. name: "ToolbarGroup",
  23650. configFields: schema$9(),
  23651. partFields: parts$5(),
  23652. factory: factory$9
  23653. });
  23654. var buildGroups = function(comps) {
  23655. return map$2(comps, function(g) {
  23656. return premade(g);
  23657. });
  23658. };
  23659. var refresh$1 = function(toolbar, memFloatingToolbarButton, detail) {
  23660. refresh$2(toolbar, detail, function(overflowGroups) {
  23661. detail.overflowGroups.set(overflowGroups);
  23662. memFloatingToolbarButton.getOpt(toolbar).each(function(floatingToolbarButton) {
  23663. FloatingToolbarButton.setGroups(floatingToolbarButton, buildGroups(overflowGroups));
  23664. });
  23665. });
  23666. };
  23667. var factory$8 = function(detail, components2, spec, externals) {
  23668. var memFloatingToolbarButton = record(FloatingToolbarButton.sketch({
  23669. fetch: function() {
  23670. return Future.nu(function(resolve) {
  23671. resolve(buildGroups(detail.overflowGroups.get()));
  23672. });
  23673. },
  23674. layouts: {
  23675. onLtr: function() {
  23676. return [
  23677. southwest$2,
  23678. southeast$2
  23679. ];
  23680. },
  23681. onRtl: function() {
  23682. return [
  23683. southeast$2,
  23684. southwest$2
  23685. ];
  23686. },
  23687. onBottomLtr: function() {
  23688. return [
  23689. northwest$2,
  23690. northeast$2
  23691. ];
  23692. },
  23693. onBottomRtl: function() {
  23694. return [
  23695. northeast$2,
  23696. northwest$2
  23697. ];
  23698. }
  23699. },
  23700. getBounds: spec.getOverflowBounds,
  23701. lazySink: detail.lazySink,
  23702. fireDismissalEventInstead: {},
  23703. markers: { toggledClass: detail.markers.overflowToggledClass },
  23704. parts: {
  23705. button: externals["overflow-button"](),
  23706. toolbar: externals.overflow()
  23707. }
  23708. }));
  23709. return {
  23710. uid: detail.uid,
  23711. dom: detail.dom,
  23712. components: components2,
  23713. behaviours: augment(detail.splitToolbarBehaviours, [Coupling.config({
  23714. others: {
  23715. overflowGroup: function() {
  23716. return ToolbarGroup.sketch(__assign(__assign({}, externals["overflow-group"]()), { items: [memFloatingToolbarButton.asSpec()] }));
  23717. }
  23718. }
  23719. })]),
  23720. apis: {
  23721. setGroups: function(toolbar, groups) {
  23722. detail.builtGroups.set(map$2(groups, toolbar.getSystem().build));
  23723. refresh$1(toolbar, memFloatingToolbarButton, detail);
  23724. },
  23725. refresh: function(toolbar) {
  23726. return refresh$1(toolbar, memFloatingToolbarButton, detail);
  23727. },
  23728. toggle: function(toolbar) {
  23729. memFloatingToolbarButton.getOpt(toolbar).each(function(floatingToolbarButton) {
  23730. FloatingToolbarButton.toggle(floatingToolbarButton);
  23731. });
  23732. },
  23733. isOpen: function(toolbar) {
  23734. return memFloatingToolbarButton.getOpt(toolbar).map(FloatingToolbarButton.isOpen).getOr(false);
  23735. },
  23736. reposition: function(toolbar) {
  23737. memFloatingToolbarButton.getOpt(toolbar).each(function(floatingToolbarButton) {
  23738. FloatingToolbarButton.reposition(floatingToolbarButton);
  23739. });
  23740. },
  23741. getOverflow: function(toolbar) {
  23742. return memFloatingToolbarButton.getOpt(toolbar).bind(FloatingToolbarButton.getToolbar);
  23743. }
  23744. },
  23745. domModification: { attributes: { role: "group" } }
  23746. };
  23747. };
  23748. var SplitFloatingToolbar = composite({
  23749. name: "SplitFloatingToolbar",
  23750. configFields: schema$b(),
  23751. partFields: parts$7(),
  23752. factory: factory$8,
  23753. apis: {
  23754. setGroups: function(apis, toolbar, groups) {
  23755. apis.setGroups(toolbar, groups);
  23756. },
  23757. refresh: function(apis, toolbar) {
  23758. apis.refresh(toolbar);
  23759. },
  23760. reposition: function(apis, toolbar) {
  23761. apis.reposition(toolbar);
  23762. },
  23763. toggle: function(apis, toolbar) {
  23764. apis.toggle(toolbar);
  23765. },
  23766. isOpen: function(apis, toolbar) {
  23767. return apis.isOpen(toolbar);
  23768. },
  23769. getOverflow: function(apis, toolbar) {
  23770. return apis.getOverflow(toolbar);
  23771. }
  23772. }
  23773. });
  23774. var schema$8 = constant$1([
  23775. markers$1([
  23776. "closedClass",
  23777. "openClass",
  23778. "shrinkingClass",
  23779. "growingClass",
  23780. "overflowToggledClass"
  23781. ]),
  23782. onHandler("onOpened"),
  23783. onHandler("onClosed")
  23784. ].concat(schema$c()));
  23785. var parts$4 = constant$1([
  23786. required({
  23787. factory: Toolbar,
  23788. schema: schema$e(),
  23789. name: "primary"
  23790. }),
  23791. required({
  23792. factory: Toolbar,
  23793. schema: schema$e(),
  23794. name: "overflow",
  23795. overrides: function(detail) {
  23796. return {
  23797. toolbarBehaviours: derive$1([
  23798. Sliding.config({
  23799. dimension: { property: "height" },
  23800. closedClass: detail.markers.closedClass,
  23801. openClass: detail.markers.openClass,
  23802. shrinkingClass: detail.markers.shrinkingClass,
  23803. growingClass: detail.markers.growingClass,
  23804. onShrunk: function(comp) {
  23805. getPart(comp, detail, "overflow-button").each(function(button2) {
  23806. Toggling.off(button2);
  23807. Focusing.focus(button2);
  23808. });
  23809. detail.onClosed(comp);
  23810. },
  23811. onGrown: function(comp) {
  23812. Keying.focusIn(comp);
  23813. detail.onOpened(comp);
  23814. },
  23815. onStartGrow: function(comp) {
  23816. getPart(comp, detail, "overflow-button").each(Toggling.on);
  23817. }
  23818. }),
  23819. Keying.config({
  23820. mode: "acyclic",
  23821. onEscape: function(comp) {
  23822. getPart(comp, detail, "overflow-button").each(Focusing.focus);
  23823. return Optional.some(true);
  23824. }
  23825. })
  23826. ])
  23827. };
  23828. }
  23829. }),
  23830. external$1({
  23831. name: "overflow-button",
  23832. overrides: function(detail) {
  23833. return {
  23834. buttonBehaviours: derive$1([Toggling.config({
  23835. toggleClass: detail.markers.overflowToggledClass,
  23836. aria: { mode: "pressed" },
  23837. toggleOnExecute: false
  23838. })])
  23839. };
  23840. }
  23841. }),
  23842. external$1({ name: "overflow-group" })
  23843. ]);
  23844. var isOpen = function(toolbar, detail) {
  23845. return getPart(toolbar, detail, "overflow").map(Sliding.hasGrown).getOr(false);
  23846. };
  23847. var toggleToolbar = function(toolbar, detail) {
  23848. getPart(toolbar, detail, "overflow-button").bind(function() {
  23849. return getPart(toolbar, detail, "overflow");
  23850. }).each(function(overf) {
  23851. refresh(toolbar, detail);
  23852. Sliding.toggleGrow(overf);
  23853. });
  23854. };
  23855. var refresh = function(toolbar, detail) {
  23856. getPart(toolbar, detail, "overflow").each(function(overflow2) {
  23857. refresh$2(toolbar, detail, function(groups) {
  23858. var builtGroups = map$2(groups, function(g) {
  23859. return premade(g);
  23860. });
  23861. Toolbar.setGroups(overflow2, builtGroups);
  23862. });
  23863. getPart(toolbar, detail, "overflow-button").each(function(button2) {
  23864. if (Sliding.hasGrown(overflow2)) {
  23865. Toggling.on(button2);
  23866. }
  23867. });
  23868. Sliding.refresh(overflow2);
  23869. });
  23870. };
  23871. var factory$7 = function(detail, components2, spec, externals) {
  23872. var toolbarToggleEvent = "alloy.toolbar.toggle";
  23873. var doSetGroups = function(toolbar, groups) {
  23874. var built = map$2(groups, toolbar.getSystem().build);
  23875. detail.builtGroups.set(built);
  23876. };
  23877. return {
  23878. uid: detail.uid,
  23879. dom: detail.dom,
  23880. components: components2,
  23881. behaviours: augment(detail.splitToolbarBehaviours, [
  23882. Coupling.config({
  23883. others: {
  23884. overflowGroup: function(toolbar) {
  23885. return ToolbarGroup.sketch(__assign(__assign({}, externals["overflow-group"]()), {
  23886. items: [Button.sketch(__assign(__assign({}, externals["overflow-button"]()), {
  23887. action: function(_button) {
  23888. emit(toolbar, toolbarToggleEvent);
  23889. }
  23890. }))]
  23891. }));
  23892. }
  23893. }
  23894. }),
  23895. config("toolbar-toggle-events", [run$1(toolbarToggleEvent, function(toolbar) {
  23896. toggleToolbar(toolbar, detail);
  23897. })])
  23898. ]),
  23899. apis: {
  23900. setGroups: function(toolbar, groups) {
  23901. doSetGroups(toolbar, groups);
  23902. refresh(toolbar, detail);
  23903. },
  23904. refresh: function(toolbar) {
  23905. return refresh(toolbar, detail);
  23906. },
  23907. toggle: function(toolbar) {
  23908. return toggleToolbar(toolbar, detail);
  23909. },
  23910. isOpen: function(toolbar) {
  23911. return isOpen(toolbar, detail);
  23912. }
  23913. },
  23914. domModification: { attributes: { role: "group" } }
  23915. };
  23916. };
  23917. var SplitSlidingToolbar = composite({
  23918. name: "SplitSlidingToolbar",
  23919. configFields: schema$8(),
  23920. partFields: parts$4(),
  23921. factory: factory$7,
  23922. apis: {
  23923. setGroups: function(apis, toolbar, groups) {
  23924. apis.setGroups(toolbar, groups);
  23925. },
  23926. refresh: function(apis, toolbar) {
  23927. apis.refresh(toolbar);
  23928. },
  23929. toggle: function(apis, toolbar) {
  23930. apis.toggle(toolbar);
  23931. },
  23932. isOpen: function(apis, toolbar) {
  23933. return apis.isOpen(toolbar);
  23934. }
  23935. }
  23936. });
  23937. var renderToolbarGroupCommon = function(toolbarGroup) {
  23938. var attributes = toolbarGroup.title.fold(function() {
  23939. return {};
  23940. }, function(title) {
  23941. return { attributes: { title } };
  23942. });
  23943. return {
  23944. dom: __assign({
  23945. tag: "div",
  23946. classes: ["tox-toolbar__group"]
  23947. }, attributes),
  23948. components: [ToolbarGroup.parts.items({})],
  23949. items: toolbarGroup.items,
  23950. markers: { itemSelector: "*:not(.tox-split-button) > .tox-tbtn:not([disabled]), .tox-split-button:not([disabled]), .tox-toolbar-nav-js:not([disabled])" },
  23951. tgroupBehaviours: derive$1([
  23952. Tabstopping.config({}),
  23953. Focusing.config({})
  23954. ])
  23955. };
  23956. };
  23957. var renderToolbarGroup = function(toolbarGroup) {
  23958. return ToolbarGroup.sketch(renderToolbarGroupCommon(toolbarGroup));
  23959. };
  23960. var getToolbarbehaviours = function(toolbarSpec, modeName) {
  23961. var onAttached = runOnAttached(function(component) {
  23962. var groups = map$2(toolbarSpec.initGroups, renderToolbarGroup);
  23963. Toolbar.setGroups(component, groups);
  23964. });
  23965. return derive$1([
  23966. DisablingConfigs.toolbarButton(toolbarSpec.providers.isDisabled),
  23967. receivingConfig(),
  23968. Keying.config({
  23969. mode: modeName,
  23970. onEscape: toolbarSpec.onEscape,
  23971. selector: ".tox-toolbar__group"
  23972. }),
  23973. config("toolbar-events", [onAttached])
  23974. ]);
  23975. };
  23976. var renderMoreToolbarCommon = function(toolbarSpec) {
  23977. var modeName = toolbarSpec.cyclicKeying ? "cyclic" : "acyclic";
  23978. return {
  23979. uid: toolbarSpec.uid,
  23980. dom: {
  23981. tag: "div",
  23982. classes: ["tox-toolbar-overlord"]
  23983. },
  23984. parts: {
  23985. "overflow-group": renderToolbarGroupCommon({
  23986. title: Optional.none(),
  23987. items: []
  23988. }),
  23989. "overflow-button": renderIconButtonSpec({
  23990. name: "more",
  23991. icon: Optional.some("more-drawer"),
  23992. disabled: false,
  23993. tooltip: Optional.some("More..."),
  23994. primary: false,
  23995. borderless: false
  23996. }, Optional.none(), toolbarSpec.providers)
  23997. },
  23998. splitToolbarBehaviours: getToolbarbehaviours(toolbarSpec, modeName)
  23999. };
  24000. };
  24001. var renderFloatingMoreToolbar = function(toolbarSpec) {
  24002. var baseSpec = renderMoreToolbarCommon(toolbarSpec);
  24003. var overflowXOffset = 4;
  24004. var primary = SplitFloatingToolbar.parts.primary({
  24005. dom: {
  24006. tag: "div",
  24007. classes: ["tox-toolbar__primary"]
  24008. }
  24009. });
  24010. return SplitFloatingToolbar.sketch(__assign(__assign({}, baseSpec), {
  24011. lazySink: toolbarSpec.getSink,
  24012. getOverflowBounds: function() {
  24013. var headerElem = toolbarSpec.moreDrawerData.lazyHeader().element;
  24014. var headerBounds = absolute$2(headerElem);
  24015. var docElem = documentElement(headerElem);
  24016. var docBounds = absolute$2(docElem);
  24017. var height2 = Math.max(docElem.dom.scrollHeight, docBounds.height);
  24018. return bounds(headerBounds.x + overflowXOffset, docBounds.y, headerBounds.width - overflowXOffset * 2, height2);
  24019. },
  24020. parts: __assign(__assign({}, baseSpec.parts), {
  24021. overflow: {
  24022. dom: {
  24023. tag: "div",
  24024. classes: ["tox-toolbar__overflow"],
  24025. attributes: toolbarSpec.attributes
  24026. }
  24027. }
  24028. }),
  24029. components: [primary],
  24030. markers: { overflowToggledClass: "tox-tbtn--enabled" }
  24031. }));
  24032. };
  24033. var renderSlidingMoreToolbar = function(toolbarSpec) {
  24034. var primary = SplitSlidingToolbar.parts.primary({
  24035. dom: {
  24036. tag: "div",
  24037. classes: ["tox-toolbar__primary"]
  24038. }
  24039. });
  24040. var overflow2 = SplitSlidingToolbar.parts.overflow({
  24041. dom: {
  24042. tag: "div",
  24043. classes: ["tox-toolbar__overflow"]
  24044. }
  24045. });
  24046. var baseSpec = renderMoreToolbarCommon(toolbarSpec);
  24047. return SplitSlidingToolbar.sketch(__assign(__assign({}, baseSpec), {
  24048. components: [
  24049. primary,
  24050. overflow2
  24051. ],
  24052. markers: {
  24053. openClass: "tox-toolbar__overflow--open",
  24054. closedClass: "tox-toolbar__overflow--closed",
  24055. growingClass: "tox-toolbar__overflow--growing",
  24056. shrinkingClass: "tox-toolbar__overflow--shrinking",
  24057. overflowToggledClass: "tox-tbtn--enabled"
  24058. },
  24059. onOpened: function(comp) {
  24060. comp.getSystem().broadcastOn([toolbarHeightChange()], { type: "opened" });
  24061. },
  24062. onClosed: function(comp) {
  24063. comp.getSystem().broadcastOn([toolbarHeightChange()], { type: "closed" });
  24064. }
  24065. }));
  24066. };
  24067. var renderToolbar = function(toolbarSpec) {
  24068. var modeName = toolbarSpec.cyclicKeying ? "cyclic" : "acyclic";
  24069. return Toolbar.sketch({
  24070. uid: toolbarSpec.uid,
  24071. dom: {
  24072. tag: "div",
  24073. classes: ["tox-toolbar"].concat(toolbarSpec.type === ToolbarMode.scrolling ? ["tox-toolbar--scrolling"] : [])
  24074. },
  24075. components: [Toolbar.parts.groups({})],
  24076. toolbarBehaviours: getToolbarbehaviours(toolbarSpec, modeName)
  24077. });
  24078. };
  24079. var factory$6 = function(detail, components2, _spec) {
  24080. var apis = {
  24081. getSocket: function(comp) {
  24082. return parts$a.getPart(comp, detail, "socket");
  24083. },
  24084. setSidebar: function(comp, panelConfigs) {
  24085. parts$a.getPart(comp, detail, "sidebar").each(function(sidebar) {
  24086. return setSidebar(sidebar, panelConfigs);
  24087. });
  24088. },
  24089. toggleSidebar: function(comp, name2) {
  24090. parts$a.getPart(comp, detail, "sidebar").each(function(sidebar) {
  24091. return toggleSidebar(sidebar, name2);
  24092. });
  24093. },
  24094. whichSidebar: function(comp) {
  24095. return parts$a.getPart(comp, detail, "sidebar").bind(whichSidebar).getOrNull();
  24096. },
  24097. getHeader: function(comp) {
  24098. return parts$a.getPart(comp, detail, "header");
  24099. },
  24100. getToolbar: function(comp) {
  24101. return parts$a.getPart(comp, detail, "toolbar");
  24102. },
  24103. setToolbar: function(comp, groups) {
  24104. parts$a.getPart(comp, detail, "toolbar").each(function(toolbar) {
  24105. toolbar.getApis().setGroups(toolbar, groups);
  24106. });
  24107. },
  24108. setToolbars: function(comp, toolbars) {
  24109. parts$a.getPart(comp, detail, "multiple-toolbar").each(function(mToolbar) {
  24110. CustomList.setItems(mToolbar, toolbars);
  24111. });
  24112. },
  24113. refreshToolbar: function(comp) {
  24114. var toolbar = parts$a.getPart(comp, detail, "toolbar");
  24115. toolbar.each(function(toolbar2) {
  24116. return toolbar2.getApis().refresh(toolbar2);
  24117. });
  24118. },
  24119. toggleToolbarDrawer: function(comp) {
  24120. parts$a.getPart(comp, detail, "toolbar").each(function(toolbar) {
  24121. mapFrom(toolbar.getApis().toggle, function(toggle2) {
  24122. return toggle2(toolbar);
  24123. });
  24124. });
  24125. },
  24126. isToolbarDrawerToggled: function(comp) {
  24127. return parts$a.getPart(comp, detail, "toolbar").bind(function(toolbar) {
  24128. return Optional.from(toolbar.getApis().isOpen).map(function(isOpen2) {
  24129. return isOpen2(toolbar);
  24130. });
  24131. }).getOr(false);
  24132. },
  24133. getThrobber: function(comp) {
  24134. return parts$a.getPart(comp, detail, "throbber");
  24135. },
  24136. focusToolbar: function(comp) {
  24137. var optToolbar = parts$a.getPart(comp, detail, "toolbar").orThunk(function() {
  24138. return parts$a.getPart(comp, detail, "multiple-toolbar");
  24139. });
  24140. optToolbar.each(function(toolbar) {
  24141. Keying.focusIn(toolbar);
  24142. });
  24143. },
  24144. setMenubar: function(comp, menus) {
  24145. parts$a.getPart(comp, detail, "menubar").each(function(menubar) {
  24146. SilverMenubar.setMenus(menubar, menus);
  24147. });
  24148. },
  24149. focusMenubar: function(comp) {
  24150. parts$a.getPart(comp, detail, "menubar").each(function(menubar) {
  24151. SilverMenubar.focus(menubar);
  24152. });
  24153. }
  24154. };
  24155. return {
  24156. uid: detail.uid,
  24157. dom: detail.dom,
  24158. components: components2,
  24159. apis,
  24160. behaviours: detail.behaviours
  24161. };
  24162. };
  24163. var partMenubar = partType.optional({
  24164. factory: SilverMenubar,
  24165. name: "menubar",
  24166. schema: [required$1("backstage")]
  24167. });
  24168. var toolbarFactory = function(spec) {
  24169. if (spec.type === ToolbarMode.sliding) {
  24170. return renderSlidingMoreToolbar;
  24171. } else if (spec.type === ToolbarMode.floating) {
  24172. return renderFloatingMoreToolbar;
  24173. } else {
  24174. return renderToolbar;
  24175. }
  24176. };
  24177. var partMultipleToolbar = partType.optional({
  24178. factory: {
  24179. sketch: function(spec) {
  24180. return CustomList.sketch({
  24181. uid: spec.uid,
  24182. dom: spec.dom,
  24183. listBehaviours: derive$1([Keying.config({
  24184. mode: "acyclic",
  24185. selector: ".tox-toolbar"
  24186. })]),
  24187. makeItem: function() {
  24188. return renderToolbar({
  24189. type: spec.type,
  24190. uid: generate$6("multiple-toolbar-item"),
  24191. cyclicKeying: false,
  24192. initGroups: [],
  24193. providers: spec.providers,
  24194. onEscape: function() {
  24195. spec.onEscape();
  24196. return Optional.some(true);
  24197. }
  24198. });
  24199. },
  24200. setupItem: function(_mToolbar, tc, data, _index) {
  24201. Toolbar.setGroups(tc, data);
  24202. },
  24203. shell: true
  24204. });
  24205. }
  24206. },
  24207. name: "multiple-toolbar",
  24208. schema: [
  24209. required$1("dom"),
  24210. required$1("onEscape")
  24211. ]
  24212. });
  24213. var partToolbar = partType.optional({
  24214. factory: {
  24215. sketch: function(spec) {
  24216. var renderer = toolbarFactory(spec);
  24217. var toolbarSpec = {
  24218. type: spec.type,
  24219. uid: spec.uid,
  24220. onEscape: function() {
  24221. spec.onEscape();
  24222. return Optional.some(true);
  24223. },
  24224. cyclicKeying: false,
  24225. initGroups: [],
  24226. getSink: spec.getSink,
  24227. providers: spec.providers,
  24228. moreDrawerData: {
  24229. lazyToolbar: spec.lazyToolbar,
  24230. lazyMoreButton: spec.lazyMoreButton,
  24231. lazyHeader: spec.lazyHeader
  24232. },
  24233. attributes: spec.attributes
  24234. };
  24235. return renderer(toolbarSpec);
  24236. }
  24237. },
  24238. name: "toolbar",
  24239. schema: [
  24240. required$1("dom"),
  24241. required$1("onEscape"),
  24242. required$1("getSink")
  24243. ]
  24244. });
  24245. var partHeader = partType.optional({
  24246. factory: { sketch: renderHeader },
  24247. name: "header",
  24248. schema: [required$1("dom")]
  24249. });
  24250. var partSocket = partType.optional({
  24251. name: "socket",
  24252. schema: [required$1("dom")]
  24253. });
  24254. var partSidebar = partType.optional({
  24255. factory: { sketch: renderSidebar },
  24256. name: "sidebar",
  24257. schema: [required$1("dom")]
  24258. });
  24259. var partThrobber = partType.optional({
  24260. factory: { sketch: renderThrobber },
  24261. name: "throbber",
  24262. schema: [required$1("dom")]
  24263. });
  24264. var OuterContainer = composite({
  24265. name: "OuterContainer",
  24266. factory: factory$6,
  24267. configFields: [
  24268. required$1("dom"),
  24269. required$1("behaviours")
  24270. ],
  24271. partFields: [
  24272. partHeader,
  24273. partMenubar,
  24274. partToolbar,
  24275. partMultipleToolbar,
  24276. partSocket,
  24277. partSidebar,
  24278. partThrobber
  24279. ],
  24280. apis: {
  24281. getSocket: function(apis, comp) {
  24282. return apis.getSocket(comp);
  24283. },
  24284. setSidebar: function(apis, comp, panelConfigs) {
  24285. apis.setSidebar(comp, panelConfigs);
  24286. },
  24287. toggleSidebar: function(apis, comp, name2) {
  24288. apis.toggleSidebar(comp, name2);
  24289. },
  24290. whichSidebar: function(apis, comp) {
  24291. return apis.whichSidebar(comp);
  24292. },
  24293. getHeader: function(apis, comp) {
  24294. return apis.getHeader(comp);
  24295. },
  24296. getToolbar: function(apis, comp) {
  24297. return apis.getToolbar(comp);
  24298. },
  24299. setToolbar: function(apis, comp, grps) {
  24300. var groups = map$2(grps, function(grp) {
  24301. return renderToolbarGroup(grp);
  24302. });
  24303. apis.setToolbar(comp, groups);
  24304. },
  24305. setToolbars: function(apis, comp, ts) {
  24306. var renderedToolbars = map$2(ts, function(g) {
  24307. return map$2(g, renderToolbarGroup);
  24308. });
  24309. apis.setToolbars(comp, renderedToolbars);
  24310. },
  24311. refreshToolbar: function(apis, comp) {
  24312. return apis.refreshToolbar(comp);
  24313. },
  24314. toggleToolbarDrawer: function(apis, comp) {
  24315. apis.toggleToolbarDrawer(comp);
  24316. },
  24317. isToolbarDrawerToggled: function(apis, comp) {
  24318. return apis.isToolbarDrawerToggled(comp);
  24319. },
  24320. getThrobber: function(apis, comp) {
  24321. return apis.getThrobber(comp);
  24322. },
  24323. setMenubar: function(apis, comp, menus) {
  24324. apis.setMenubar(comp, menus);
  24325. },
  24326. focusMenubar: function(apis, comp) {
  24327. apis.focusMenubar(comp);
  24328. },
  24329. focusToolbar: function(apis, comp) {
  24330. apis.focusToolbar(comp);
  24331. }
  24332. }
  24333. });
  24334. var defaultMenubar = "file edit view insert format tools table help";
  24335. var defaultMenus = {
  24336. file: {
  24337. title: "File",
  24338. items: "newdocument restoredraft | preview | export print | deleteallconversations"
  24339. },
  24340. edit: {
  24341. title: "Edit",
  24342. items: "undo redo | cut copy paste pastetext | selectall | searchreplace"
  24343. },
  24344. view: {
  24345. title: "View",
  24346. items: "code | visualaid visualchars visualblocks | spellchecker | preview fullscreen | showcomments"
  24347. },
  24348. insert: {
  24349. title: "Insert",
  24350. items: "image link media addcomment pageembed template codesample inserttable | charmap emoticons hr | pagebreak nonbreaking anchor toc | insertdatetime"
  24351. },
  24352. format: {
  24353. title: "Format",
  24354. items: "bold italic underline strikethrough superscript subscript codeformat | formats blockformats fontformats fontsizes align lineheight | forecolor backcolor | language | removeformat"
  24355. },
  24356. tools: {
  24357. title: "Tools",
  24358. items: "spellchecker spellcheckerlanguage | a11ycheck code wordcount"
  24359. },
  24360. table: {
  24361. title: "Table",
  24362. items: "inserttable | cell row column | advtablesort | tableprops deletetable"
  24363. },
  24364. help: {
  24365. title: "Help",
  24366. items: "help"
  24367. }
  24368. };
  24369. var make = function(menu2, registry, editor) {
  24370. var removedMenuItems = getRemovedMenuItems(editor).split(/[ ,]/);
  24371. return {
  24372. text: menu2.title,
  24373. getItems: function() {
  24374. return bind$3(menu2.items, function(i) {
  24375. var itemName = i.toLowerCase();
  24376. if (itemName.trim().length === 0) {
  24377. return [];
  24378. } else if (exists(removedMenuItems, function(removedMenuItem) {
  24379. return removedMenuItem === itemName;
  24380. })) {
  24381. return [];
  24382. } else if (itemName === "separator" || itemName === "|") {
  24383. return [{ type: "separator" }];
  24384. } else if (registry.menuItems[itemName]) {
  24385. return [registry.menuItems[itemName]];
  24386. } else {
  24387. return [];
  24388. }
  24389. });
  24390. }
  24391. };
  24392. };
  24393. var parseItemsString = function(items) {
  24394. if (typeof items === "string") {
  24395. return items.split(" ");
  24396. }
  24397. return items;
  24398. };
  24399. var identifyMenus = function(editor, registry) {
  24400. var rawMenuData = __assign(__assign({}, defaultMenus), registry.menus);
  24401. var userDefinedMenus = keys(registry.menus).length > 0;
  24402. var menubar = registry.menubar === void 0 || registry.menubar === true ? parseItemsString(defaultMenubar) : parseItemsString(registry.menubar === false ? "" : registry.menubar);
  24403. var validMenus = filter$2(menubar, function(menuName) {
  24404. var isDefaultMenu = has$2(defaultMenus, menuName);
  24405. if (userDefinedMenus) {
  24406. return isDefaultMenu || get$e(registry.menus, menuName).exists(function(menu2) {
  24407. return has$2(menu2, "items");
  24408. });
  24409. } else {
  24410. return isDefaultMenu;
  24411. }
  24412. });
  24413. var menus = map$2(validMenus, function(menuName) {
  24414. var menuData = rawMenuData[menuName];
  24415. return make({
  24416. title: menuData.title,
  24417. items: parseItemsString(menuData.items)
  24418. }, registry, editor);
  24419. });
  24420. return filter$2(menus, function(menu2) {
  24421. var isNotSeparator = function(item2) {
  24422. return item2.type !== "separator";
  24423. };
  24424. return menu2.getItems().length > 0 && exists(menu2.getItems(), isNotSeparator);
  24425. });
  24426. };
  24427. var fireSkinLoaded = function(editor) {
  24428. var done = function() {
  24429. editor._skinLoaded = true;
  24430. fireSkinLoaded$1(editor);
  24431. };
  24432. return function() {
  24433. if (editor.initialized) {
  24434. done();
  24435. } else {
  24436. editor.on("init", done);
  24437. }
  24438. };
  24439. };
  24440. var fireSkinLoadError = function(editor, err) {
  24441. return function() {
  24442. return fireSkinLoadError$1(editor, { message: err });
  24443. };
  24444. };
  24445. var loadStylesheet = function(editor, stylesheetUrl, styleSheetLoader) {
  24446. return new global$c(function(resolve, reject) {
  24447. styleSheetLoader.load(stylesheetUrl, resolve, reject);
  24448. editor.on("remove", function() {
  24449. return styleSheetLoader.unload(stylesheetUrl);
  24450. });
  24451. });
  24452. };
  24453. var loadUiSkins = function(editor, skinUrl) {
  24454. var skinUiCss = skinUrl + "/skin.min.css";
  24455. return loadStylesheet(editor, skinUiCss, editor.ui.styleSheetLoader);
  24456. };
  24457. var loadShadowDomUiSkins = function(editor, skinUrl) {
  24458. var isInShadowRoot$1 = isInShadowRoot(SugarElement.fromDom(editor.getElement()));
  24459. if (isInShadowRoot$1) {
  24460. var shadowDomSkinCss = skinUrl + "/skin.shadowdom.min.css";
  24461. return loadStylesheet(editor, shadowDomSkinCss, global$b.DOM.styleSheetLoader);
  24462. } else {
  24463. return global$c.resolve();
  24464. }
  24465. };
  24466. var loadSkin = function(isInline, editor) {
  24467. var skinUrl = getSkinUrl(editor);
  24468. if (skinUrl) {
  24469. editor.contentCSS.push(skinUrl + (isInline ? "/content.inline" : "/content") + ".min.css");
  24470. }
  24471. if (isSkinDisabled(editor) === false && isString(skinUrl)) {
  24472. global$c.all([
  24473. loadUiSkins(editor, skinUrl),
  24474. loadShadowDomUiSkins(editor, skinUrl)
  24475. ]).then(fireSkinLoaded(editor), fireSkinLoadError(editor, "Skin could not be loaded"));
  24476. } else {
  24477. fireSkinLoaded(editor)();
  24478. }
  24479. };
  24480. var iframe = curry(loadSkin, false);
  24481. var inline = curry(loadSkin, true);
  24482. var onSetupFormatToggle = function(editor, name2) {
  24483. return function(api2) {
  24484. var boundCallback = unbindable();
  24485. var init2 = function() {
  24486. api2.setActive(editor.formatter.match(name2));
  24487. var binding = editor.formatter.formatChanged(name2, api2.setActive);
  24488. boundCallback.set(binding);
  24489. };
  24490. editor.initialized ? init2() : editor.once("init", init2);
  24491. return function() {
  24492. editor.off("init", init2);
  24493. boundCallback.clear();
  24494. };
  24495. };
  24496. };
  24497. var onSetupEvent = function(editor, event, f) {
  24498. return function(api2) {
  24499. var handleEvent = function() {
  24500. return f(api2);
  24501. };
  24502. var init2 = function() {
  24503. f(api2);
  24504. editor.on(event, handleEvent);
  24505. };
  24506. editor.initialized ? init2() : editor.once("init", init2);
  24507. return function() {
  24508. editor.off("init", init2);
  24509. editor.off(event, handleEvent);
  24510. };
  24511. };
  24512. };
  24513. var onActionToggleFormat$1 = function(editor) {
  24514. return function(rawItem) {
  24515. return function() {
  24516. editor.undoManager.transact(function() {
  24517. editor.focus();
  24518. editor.execCommand("mceToggleFormat", false, rawItem.format);
  24519. });
  24520. };
  24521. };
  24522. };
  24523. var onActionExecCommand = function(editor, command) {
  24524. return function() {
  24525. return editor.execCommand(command);
  24526. };
  24527. };
  24528. var generateSelectItems = function(_editor, backstage, spec) {
  24529. var generateItem = function(rawItem, response, disabled, value2) {
  24530. var translatedText = backstage.shared.providers.translate(rawItem.title);
  24531. if (rawItem.type === "separator") {
  24532. return Optional.some({
  24533. type: "separator",
  24534. text: translatedText
  24535. });
  24536. } else if (rawItem.type === "submenu") {
  24537. var items = bind$3(rawItem.getStyleItems(), function(si) {
  24538. return validate(si, response, value2);
  24539. });
  24540. if (response === 0 && items.length <= 0) {
  24541. return Optional.none();
  24542. } else {
  24543. return Optional.some({
  24544. type: "nestedmenuitem",
  24545. text: translatedText,
  24546. disabled: items.length <= 0,
  24547. getSubmenuItems: function() {
  24548. return bind$3(rawItem.getStyleItems(), function(si) {
  24549. return validate(si, response, value2);
  24550. });
  24551. }
  24552. });
  24553. }
  24554. } else {
  24555. return Optional.some(__assign({
  24556. type: "togglemenuitem",
  24557. text: translatedText,
  24558. icon: rawItem.icon,
  24559. active: rawItem.isSelected(value2),
  24560. disabled,
  24561. onAction: spec.onAction(rawItem)
  24562. }, rawItem.getStylePreview().fold(function() {
  24563. return {};
  24564. }, function(preview) {
  24565. return { meta: { style: preview } };
  24566. })));
  24567. }
  24568. };
  24569. var validate = function(item2, response, value2) {
  24570. var invalid = item2.type === "formatter" && spec.isInvalid(item2);
  24571. if (response === 0) {
  24572. return invalid ? [] : generateItem(item2, response, false, value2).toArray();
  24573. } else {
  24574. return generateItem(item2, response, invalid, value2).toArray();
  24575. }
  24576. };
  24577. var validateItems = function(preItems) {
  24578. var value2 = spec.getCurrentValue();
  24579. var response = spec.shouldHide ? 0 : 1;
  24580. return bind$3(preItems, function(item2) {
  24581. return validate(item2, response, value2);
  24582. });
  24583. };
  24584. var getFetch2 = function(backstage2, getStyleItems) {
  24585. return function(comp, callback) {
  24586. var preItems = getStyleItems();
  24587. var items = validateItems(preItems);
  24588. var menu2 = build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage2, false);
  24589. callback(menu2);
  24590. };
  24591. };
  24592. return {
  24593. validateItems,
  24594. getFetch: getFetch2
  24595. };
  24596. };
  24597. var createMenuItems = function(editor, backstage, spec) {
  24598. var dataset2 = spec.dataset;
  24599. var getStyleItems = dataset2.type === "basic" ? function() {
  24600. return map$2(dataset2.data, function(d) {
  24601. return processBasic(d, spec.isSelectedFor, spec.getPreviewFor);
  24602. });
  24603. } : dataset2.getData;
  24604. return {
  24605. items: generateSelectItems(editor, backstage, spec),
  24606. getStyleItems
  24607. };
  24608. };
  24609. var createSelectButton = function(editor, backstage, spec) {
  24610. var _a2 = createMenuItems(editor, backstage, spec), items = _a2.items, getStyleItems = _a2.getStyleItems;
  24611. var getApi2 = function(comp) {
  24612. return { getComponent: constant$1(comp) };
  24613. };
  24614. var onSetup = onSetupEvent(editor, "NodeChange", function(api2) {
  24615. var comp = api2.getComponent();
  24616. spec.updateText(comp);
  24617. });
  24618. return renderCommonDropdown({
  24619. text: spec.icon.isSome() ? Optional.none() : spec.text,
  24620. icon: spec.icon,
  24621. tooltip: Optional.from(spec.tooltip),
  24622. role: Optional.none(),
  24623. fetch: items.getFetch(backstage, getStyleItems),
  24624. onSetup,
  24625. getApi: getApi2,
  24626. columns: 1,
  24627. presets: "normal",
  24628. classes: spec.icon.isSome() ? [] : ["bespoke"],
  24629. dropdownBehaviours: []
  24630. }, "tox-tbtn", backstage.shared);
  24631. };
  24632. var process = function(rawFormats) {
  24633. return map$2(rawFormats, function(item2) {
  24634. var title = item2, format = item2;
  24635. var values2 = item2.split("=");
  24636. if (values2.length > 1) {
  24637. title = values2[0];
  24638. format = values2[1];
  24639. }
  24640. return {
  24641. title,
  24642. format
  24643. };
  24644. });
  24645. };
  24646. var buildBasicStaticDataset = function(data) {
  24647. return {
  24648. type: "basic",
  24649. data
  24650. };
  24651. };
  24652. var Delimiter;
  24653. (function(Delimiter2) {
  24654. Delimiter2[Delimiter2["SemiColon"] = 0] = "SemiColon";
  24655. Delimiter2[Delimiter2["Space"] = 1] = "Space";
  24656. })(Delimiter || (Delimiter = {}));
  24657. var split = function(rawFormats, delimiter) {
  24658. if (delimiter === Delimiter.SemiColon) {
  24659. return rawFormats.replace(/;$/, "").split(";");
  24660. } else {
  24661. return rawFormats.split(" ");
  24662. }
  24663. };
  24664. var buildBasicSettingsDataset = function(editor, settingName, defaults, delimiter) {
  24665. var rawFormats = editor.getParam(settingName, defaults, "string");
  24666. var data = process(split(rawFormats, delimiter));
  24667. return {
  24668. type: "basic",
  24669. data
  24670. };
  24671. };
  24672. var alignMenuItems = [
  24673. {
  24674. title: "Left",
  24675. icon: "align-left",
  24676. format: "alignleft",
  24677. command: "JustifyLeft"
  24678. },
  24679. {
  24680. title: "Center",
  24681. icon: "align-center",
  24682. format: "aligncenter",
  24683. command: "JustifyCenter"
  24684. },
  24685. {
  24686. title: "Right",
  24687. icon: "align-right",
  24688. format: "alignright",
  24689. command: "JustifyRight"
  24690. },
  24691. {
  24692. title: "Justify",
  24693. icon: "align-justify",
  24694. format: "alignjustify",
  24695. command: "JustifyFull"
  24696. }
  24697. ];
  24698. var getSpec$4 = function(editor) {
  24699. var getMatchingValue = function() {
  24700. return find$5(alignMenuItems, function(item2) {
  24701. return editor.formatter.match(item2.format);
  24702. });
  24703. };
  24704. var isSelectedFor = function(format) {
  24705. return function() {
  24706. return editor.formatter.match(format);
  24707. };
  24708. };
  24709. var getPreviewFor = function(_format) {
  24710. return Optional.none;
  24711. };
  24712. var updateSelectMenuIcon = function(comp) {
  24713. var match = getMatchingValue();
  24714. var alignment = match.fold(constant$1("left"), function(item2) {
  24715. return item2.title.toLowerCase();
  24716. });
  24717. emitWith(comp, updateMenuIcon, { icon: "align-" + alignment });
  24718. };
  24719. var dataset2 = buildBasicStaticDataset(alignMenuItems);
  24720. var onAction = function(rawItem) {
  24721. return function() {
  24722. return find$5(alignMenuItems, function(item2) {
  24723. return item2.format === rawItem.format;
  24724. }).each(function(item2) {
  24725. return editor.execCommand(item2.command);
  24726. });
  24727. };
  24728. };
  24729. return {
  24730. tooltip: "Align",
  24731. text: Optional.none(),
  24732. icon: Optional.some("align-left"),
  24733. isSelectedFor,
  24734. getCurrentValue: Optional.none,
  24735. getPreviewFor,
  24736. onAction,
  24737. updateText: updateSelectMenuIcon,
  24738. dataset: dataset2,
  24739. shouldHide: false,
  24740. isInvalid: function(item2) {
  24741. return !editor.formatter.canApply(item2.format);
  24742. }
  24743. };
  24744. };
  24745. var createAlignSelect = function(editor, backstage) {
  24746. return createSelectButton(editor, backstage, getSpec$4(editor));
  24747. };
  24748. var alignSelectMenu = function(editor, backstage) {
  24749. var menuItems = createMenuItems(editor, backstage, getSpec$4(editor));
  24750. editor.ui.registry.addNestedMenuItem("align", {
  24751. text: backstage.shared.providers.translate("Align"),
  24752. getSubmenuItems: function() {
  24753. return menuItems.items.validateItems(menuItems.getStyleItems());
  24754. }
  24755. });
  24756. };
  24757. var defaultFontsFormats = "Andale Mono=andale mono,monospace;Arial=arial,helvetica,sans-serif;Arial Black=arial black,sans-serif;Book Antiqua=book antiqua,palatino,serif;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,palatino,serif;Helvetica=helvetica,arial,sans-serif;Impact=impact,sans-serif;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco,monospace;Times New Roman=times new roman,times,serif;Trebuchet MS=trebuchet ms,geneva,sans-serif;Verdana=verdana,geneva,sans-serif;Webdings=webdings;Wingdings=wingdings,zapf dingbats";
  24758. var systemStackFonts = [
  24759. "-apple-system",
  24760. "Segoe UI",
  24761. "Roboto",
  24762. "Helvetica Neue",
  24763. "sans-serif"
  24764. ];
  24765. var splitFonts = function(fontFamily) {
  24766. var fonts = fontFamily.split(/\s*,\s*/);
  24767. return map$2(fonts, function(font) {
  24768. return font.replace(/^['"]+|['"]+$/g, "");
  24769. });
  24770. };
  24771. var isSystemFontStack = function(fontFamily) {
  24772. var matchesSystemStack = function() {
  24773. var fonts = splitFonts(fontFamily.toLowerCase());
  24774. return forall(systemStackFonts, function(font) {
  24775. return fonts.indexOf(font.toLowerCase()) > -1;
  24776. });
  24777. };
  24778. return fontFamily.indexOf("-apple-system") === 0 && matchesSystemStack();
  24779. };
  24780. var getSpec$3 = function(editor) {
  24781. var systemFont = "System Font";
  24782. var getMatchingValue = function() {
  24783. var getFirstFont = function(fontFamily2) {
  24784. return fontFamily2 ? splitFonts(fontFamily2)[0] : "";
  24785. };
  24786. var fontFamily = editor.queryCommandValue("FontName");
  24787. var items = dataset2.data;
  24788. var font = fontFamily ? fontFamily.toLowerCase() : "";
  24789. var matchOpt = find$5(items, function(item2) {
  24790. var format = item2.format;
  24791. return format.toLowerCase() === font || getFirstFont(format).toLowerCase() === getFirstFont(font).toLowerCase();
  24792. }).orThunk(function() {
  24793. return someIf(isSystemFontStack(font), {
  24794. title: systemFont,
  24795. format: font
  24796. });
  24797. });
  24798. return {
  24799. matchOpt,
  24800. font: fontFamily
  24801. };
  24802. };
  24803. var isSelectedFor = function(item2) {
  24804. return function(valueOpt) {
  24805. return valueOpt.exists(function(value2) {
  24806. return value2.format === item2;
  24807. });
  24808. };
  24809. };
  24810. var getCurrentValue = function() {
  24811. var matchOpt = getMatchingValue().matchOpt;
  24812. return matchOpt;
  24813. };
  24814. var getPreviewFor = function(item2) {
  24815. return function() {
  24816. return Optional.some({
  24817. tag: "div",
  24818. styles: item2.indexOf("dings") === -1 ? { "font-family": item2 } : {}
  24819. });
  24820. };
  24821. };
  24822. var onAction = function(rawItem) {
  24823. return function() {
  24824. editor.undoManager.transact(function() {
  24825. editor.focus();
  24826. editor.execCommand("FontName", false, rawItem.format);
  24827. });
  24828. };
  24829. };
  24830. var updateSelectMenuText = function(comp) {
  24831. var _a2 = getMatchingValue(), matchOpt = _a2.matchOpt, font = _a2.font;
  24832. var text2 = matchOpt.fold(constant$1(font), function(item2) {
  24833. return item2.title;
  24834. });
  24835. emitWith(comp, updateMenuText, { text: text2 });
  24836. };
  24837. var dataset2 = buildBasicSettingsDataset(editor, "font_formats", defaultFontsFormats, Delimiter.SemiColon);
  24838. return {
  24839. tooltip: "Fonts",
  24840. text: Optional.some(systemFont),
  24841. icon: Optional.none(),
  24842. isSelectedFor,
  24843. getCurrentValue,
  24844. getPreviewFor,
  24845. onAction,
  24846. updateText: updateSelectMenuText,
  24847. dataset: dataset2,
  24848. shouldHide: false,
  24849. isInvalid: never
  24850. };
  24851. };
  24852. var createFontSelect = function(editor, backstage) {
  24853. return createSelectButton(editor, backstage, getSpec$3(editor));
  24854. };
  24855. var fontSelectMenu = function(editor, backstage) {
  24856. var menuItems = createMenuItems(editor, backstage, getSpec$3(editor));
  24857. editor.ui.registry.addNestedMenuItem("fontformats", {
  24858. text: backstage.shared.providers.translate("Fonts"),
  24859. getSubmenuItems: function() {
  24860. return menuItems.items.validateItems(menuItems.getStyleItems());
  24861. }
  24862. });
  24863. };
  24864. var defaultFontsizeFormats = "8pt 10pt 12pt 14pt 18pt 24pt 36pt";
  24865. var legacyFontSizes = {
  24866. "8pt": "1",
  24867. "10pt": "2",
  24868. "12pt": "3",
  24869. "14pt": "4",
  24870. "18pt": "5",
  24871. "24pt": "6",
  24872. "36pt": "7"
  24873. };
  24874. var keywordFontSizes = {
  24875. "xx-small": "7pt",
  24876. "x-small": "8pt",
  24877. "small": "10pt",
  24878. "medium": "12pt",
  24879. "large": "14pt",
  24880. "x-large": "18pt",
  24881. "xx-large": "24pt"
  24882. };
  24883. var round = function(number2, precision) {
  24884. var factor = Math.pow(10, precision);
  24885. return Math.round(number2 * factor) / factor;
  24886. };
  24887. var toPt = function(fontSize, precision) {
  24888. if (/[0-9.]+px$/.test(fontSize)) {
  24889. return round(parseInt(fontSize, 10) * 72 / 96, precision || 0) + "pt";
  24890. } else {
  24891. return get$e(keywordFontSizes, fontSize).getOr(fontSize);
  24892. }
  24893. };
  24894. var toLegacy = function(fontSize) {
  24895. return get$e(legacyFontSizes, fontSize).getOr("");
  24896. };
  24897. var getSpec$2 = function(editor) {
  24898. var getMatchingValue = function() {
  24899. var matchOpt = Optional.none();
  24900. var items = dataset2.data;
  24901. var fontSize = editor.queryCommandValue("FontSize");
  24902. if (fontSize) {
  24903. var _loop_1 = function(precision2) {
  24904. var pt = toPt(fontSize, precision2);
  24905. var legacy = toLegacy(pt);
  24906. matchOpt = find$5(items, function(item2) {
  24907. return item2.format === fontSize || item2.format === pt || item2.format === legacy;
  24908. });
  24909. };
  24910. for (var precision = 3; matchOpt.isNone() && precision >= 0; precision--) {
  24911. _loop_1(precision);
  24912. }
  24913. }
  24914. return {
  24915. matchOpt,
  24916. size: fontSize
  24917. };
  24918. };
  24919. var isSelectedFor = function(item2) {
  24920. return function(valueOpt) {
  24921. return valueOpt.exists(function(value2) {
  24922. return value2.format === item2;
  24923. });
  24924. };
  24925. };
  24926. var getCurrentValue = function() {
  24927. var matchOpt = getMatchingValue().matchOpt;
  24928. return matchOpt;
  24929. };
  24930. var getPreviewFor = constant$1(Optional.none);
  24931. var onAction = function(rawItem) {
  24932. return function() {
  24933. editor.undoManager.transact(function() {
  24934. editor.focus();
  24935. editor.execCommand("FontSize", false, rawItem.format);
  24936. });
  24937. };
  24938. };
  24939. var updateSelectMenuText = function(comp) {
  24940. var _a2 = getMatchingValue(), matchOpt = _a2.matchOpt, size = _a2.size;
  24941. var text2 = matchOpt.fold(constant$1(size), function(match) {
  24942. return match.title;
  24943. });
  24944. emitWith(comp, updateMenuText, { text: text2 });
  24945. };
  24946. var dataset2 = buildBasicSettingsDataset(editor, "fontsize_formats", defaultFontsizeFormats, Delimiter.Space);
  24947. return {
  24948. tooltip: "Font sizes",
  24949. text: Optional.some("12pt"),
  24950. icon: Optional.none(),
  24951. isSelectedFor,
  24952. getPreviewFor,
  24953. getCurrentValue,
  24954. onAction,
  24955. updateText: updateSelectMenuText,
  24956. dataset: dataset2,
  24957. shouldHide: false,
  24958. isInvalid: never
  24959. };
  24960. };
  24961. var createFontsizeSelect = function(editor, backstage) {
  24962. return createSelectButton(editor, backstage, getSpec$2(editor));
  24963. };
  24964. var fontsizeSelectMenu = function(editor, backstage) {
  24965. var menuItems = createMenuItems(editor, backstage, getSpec$2(editor));
  24966. editor.ui.registry.addNestedMenuItem("fontsizes", {
  24967. text: "Font sizes",
  24968. getSubmenuItems: function() {
  24969. return menuItems.items.validateItems(menuItems.getStyleItems());
  24970. }
  24971. });
  24972. };
  24973. var findNearest = function(editor, getStyles) {
  24974. var styles = getStyles();
  24975. var formats = map$2(styles, function(style) {
  24976. return style.format;
  24977. });
  24978. return Optional.from(editor.formatter.closest(formats)).bind(function(fmt) {
  24979. return find$5(styles, function(data) {
  24980. return data.format === fmt;
  24981. });
  24982. }).orThunk(function() {
  24983. return someIf(editor.formatter.match("p"), {
  24984. title: "Paragraph",
  24985. format: "p"
  24986. });
  24987. });
  24988. };
  24989. var defaultBlocks = "Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Preformatted=pre";
  24990. var getSpec$1 = function(editor) {
  24991. var fallbackFormat = "Paragraph";
  24992. var isSelectedFor = function(format) {
  24993. return function() {
  24994. return editor.formatter.match(format);
  24995. };
  24996. };
  24997. var getPreviewFor = function(format) {
  24998. return function() {
  24999. var fmt = editor.formatter.get(format);
  25000. return Optional.some({
  25001. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || "div" : "div",
  25002. styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
  25003. });
  25004. };
  25005. };
  25006. var updateSelectMenuText = function(comp) {
  25007. var detectedFormat = findNearest(editor, function() {
  25008. return dataset2.data;
  25009. });
  25010. var text2 = detectedFormat.fold(constant$1(fallbackFormat), function(fmt) {
  25011. return fmt.title;
  25012. });
  25013. emitWith(comp, updateMenuText, { text: text2 });
  25014. };
  25015. var dataset2 = buildBasicSettingsDataset(editor, "block_formats", defaultBlocks, Delimiter.SemiColon);
  25016. return {
  25017. tooltip: "Blocks",
  25018. text: Optional.some(fallbackFormat),
  25019. icon: Optional.none(),
  25020. isSelectedFor,
  25021. getCurrentValue: Optional.none,
  25022. getPreviewFor,
  25023. onAction: onActionToggleFormat$1(editor),
  25024. updateText: updateSelectMenuText,
  25025. dataset: dataset2,
  25026. shouldHide: false,
  25027. isInvalid: function(item2) {
  25028. return !editor.formatter.canApply(item2.format);
  25029. }
  25030. };
  25031. };
  25032. var createFormatSelect = function(editor, backstage) {
  25033. return createSelectButton(editor, backstage, getSpec$1(editor));
  25034. };
  25035. var formatSelectMenu = function(editor, backstage) {
  25036. var menuItems = createMenuItems(editor, backstage, getSpec$1(editor));
  25037. editor.ui.registry.addNestedMenuItem("blockformats", {
  25038. text: "Blocks",
  25039. getSubmenuItems: function() {
  25040. return menuItems.items.validateItems(menuItems.getStyleItems());
  25041. }
  25042. });
  25043. };
  25044. var getSpec = function(editor, dataset2) {
  25045. var fallbackFormat = "Paragraph";
  25046. var isSelectedFor = function(format) {
  25047. return function() {
  25048. return editor.formatter.match(format);
  25049. };
  25050. };
  25051. var getPreviewFor = function(format) {
  25052. return function() {
  25053. var fmt = editor.formatter.get(format);
  25054. return fmt !== void 0 ? Optional.some({
  25055. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || "div" : "div",
  25056. styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
  25057. }) : Optional.none();
  25058. };
  25059. };
  25060. var updateSelectMenuText = function(comp) {
  25061. var getFormatItems = function(fmt) {
  25062. var subs2 = fmt.items;
  25063. return subs2 !== void 0 && subs2.length > 0 ? bind$3(subs2, getFormatItems) : [{
  25064. title: fmt.title,
  25065. format: fmt.format
  25066. }];
  25067. };
  25068. var flattenedItems = bind$3(getStyleFormats(editor), getFormatItems);
  25069. var detectedFormat = findNearest(editor, constant$1(flattenedItems));
  25070. var text2 = detectedFormat.fold(constant$1(fallbackFormat), function(fmt) {
  25071. return fmt.title;
  25072. });
  25073. emitWith(comp, updateMenuText, { text: text2 });
  25074. };
  25075. return {
  25076. tooltip: "Formats",
  25077. text: Optional.some(fallbackFormat),
  25078. icon: Optional.none(),
  25079. isSelectedFor,
  25080. getCurrentValue: Optional.none,
  25081. getPreviewFor,
  25082. onAction: onActionToggleFormat$1(editor),
  25083. updateText: updateSelectMenuText,
  25084. shouldHide: editor.getParam("style_formats_autohide", false, "boolean"),
  25085. isInvalid: function(item2) {
  25086. return !editor.formatter.canApply(item2.format);
  25087. },
  25088. dataset: dataset2
  25089. };
  25090. };
  25091. var createStyleSelect = function(editor, backstage) {
  25092. var dataset2 = __assign({ type: "advanced" }, backstage.styleselect);
  25093. return createSelectButton(editor, backstage, getSpec(editor, dataset2));
  25094. };
  25095. var styleSelectMenu = function(editor, backstage) {
  25096. var dataset2 = __assign({ type: "advanced" }, backstage.styleselect);
  25097. var menuItems = createMenuItems(editor, backstage, getSpec(editor, dataset2));
  25098. editor.ui.registry.addNestedMenuItem("formats", {
  25099. text: "Formats",
  25100. getSubmenuItems: function() {
  25101. return menuItems.items.validateItems(menuItems.getStyleItems());
  25102. }
  25103. });
  25104. };
  25105. var events$3 = function(reflectingConfig, reflectingState) {
  25106. var update = function(component, data) {
  25107. reflectingConfig.updateState.each(function(updateState) {
  25108. var newState = updateState(component, data);
  25109. reflectingState.set(newState);
  25110. });
  25111. reflectingConfig.renderComponents.each(function(renderComponents2) {
  25112. var newComponents = renderComponents2(data, reflectingState.get());
  25113. var newChildren = map$2(newComponents, component.getSystem().build);
  25114. replaceChildren(component, newChildren);
  25115. });
  25116. };
  25117. return derive$2([
  25118. run$1(receive(), function(component, message) {
  25119. var receivingData = message;
  25120. if (!receivingData.universal) {
  25121. var channel = reflectingConfig.channel;
  25122. if (contains$2(receivingData.channels, channel)) {
  25123. update(component, receivingData.data);
  25124. }
  25125. }
  25126. }),
  25127. runOnAttached(function(comp, _se) {
  25128. reflectingConfig.initialData.each(function(rawData) {
  25129. update(comp, rawData);
  25130. });
  25131. })
  25132. ]);
  25133. };
  25134. var ActiveReflecting = Object.freeze({
  25135. __proto__: null,
  25136. events: events$3
  25137. });
  25138. var getState = function(component, replaceConfig, reflectState) {
  25139. return reflectState;
  25140. };
  25141. var ReflectingApis = Object.freeze({
  25142. __proto__: null,
  25143. getState
  25144. });
  25145. var ReflectingSchema = [
  25146. required$1("channel"),
  25147. option("renderComponents"),
  25148. option("updateState"),
  25149. option("initialData")
  25150. ];
  25151. var init$3 = function() {
  25152. var cell = Cell(Optional.none());
  25153. var clear2 = function() {
  25154. return cell.set(Optional.none());
  25155. };
  25156. var readState = function() {
  25157. return cell.get().getOr("none");
  25158. };
  25159. return {
  25160. readState,
  25161. get: cell.get,
  25162. set: cell.set,
  25163. clear: clear2
  25164. };
  25165. };
  25166. var ReflectingState = Object.freeze({
  25167. __proto__: null,
  25168. init: init$3
  25169. });
  25170. var Reflecting = create$7({
  25171. fields: ReflectingSchema,
  25172. name: "reflecting",
  25173. active: ActiveReflecting,
  25174. apis: ReflectingApis,
  25175. state: ReflectingState
  25176. });
  25177. var schema$7 = constant$1([
  25178. required$1("toggleClass"),
  25179. required$1("fetch"),
  25180. onStrictHandler("onExecute"),
  25181. defaulted("getHotspot", Optional.some),
  25182. defaulted("getAnchorOverrides", constant$1({})),
  25183. schema$y(),
  25184. onStrictHandler("onItemExecute"),
  25185. option("lazySink"),
  25186. required$1("dom"),
  25187. onHandler("onOpen"),
  25188. field("splitDropdownBehaviours", [
  25189. Coupling,
  25190. Keying,
  25191. Focusing
  25192. ]),
  25193. defaulted("matchWidth", false),
  25194. defaulted("useMinWidth", false),
  25195. defaulted("eventOrder", {}),
  25196. option("role")
  25197. ].concat(sandboxFields()));
  25198. var arrowPart = required({
  25199. factory: Button,
  25200. schema: [required$1("dom")],
  25201. name: "arrow",
  25202. defaults: function() {
  25203. return { buttonBehaviours: derive$1([Focusing.revoke()]) };
  25204. },
  25205. overrides: function(detail) {
  25206. return {
  25207. dom: {
  25208. tag: "span",
  25209. attributes: { role: "presentation" }
  25210. },
  25211. action: function(arrow) {
  25212. arrow.getSystem().getByUid(detail.uid).each(emitExecute);
  25213. },
  25214. buttonBehaviours: derive$1([Toggling.config({
  25215. toggleOnExecute: false,
  25216. toggleClass: detail.toggleClass
  25217. })])
  25218. };
  25219. }
  25220. });
  25221. var buttonPart = required({
  25222. factory: Button,
  25223. schema: [required$1("dom")],
  25224. name: "button",
  25225. defaults: function() {
  25226. return { buttonBehaviours: derive$1([Focusing.revoke()]) };
  25227. },
  25228. overrides: function(detail) {
  25229. return {
  25230. dom: {
  25231. tag: "span",
  25232. attributes: { role: "presentation" }
  25233. },
  25234. action: function(btn) {
  25235. btn.getSystem().getByUid(detail.uid).each(function(splitDropdown) {
  25236. detail.onExecute(splitDropdown, btn);
  25237. });
  25238. }
  25239. };
  25240. }
  25241. });
  25242. var parts$3 = constant$1([
  25243. arrowPart,
  25244. buttonPart,
  25245. optional({
  25246. factory: {
  25247. sketch: function(spec) {
  25248. return {
  25249. uid: spec.uid,
  25250. dom: {
  25251. tag: "span",
  25252. styles: { display: "none" },
  25253. attributes: { "aria-hidden": "true" },
  25254. innerHtml: spec.text
  25255. }
  25256. };
  25257. }
  25258. },
  25259. schema: [required$1("text")],
  25260. name: "aria-descriptor"
  25261. }),
  25262. external$1({
  25263. schema: [tieredMenuMarkers()],
  25264. name: "menu",
  25265. defaults: function(detail) {
  25266. return {
  25267. onExecute: function(tmenu, item2) {
  25268. tmenu.getSystem().getByUid(detail.uid).each(function(splitDropdown) {
  25269. detail.onItemExecute(splitDropdown, tmenu, item2);
  25270. });
  25271. }
  25272. };
  25273. }
  25274. }),
  25275. partType$1()
  25276. ]);
  25277. var factory$5 = function(detail, components2, spec, externals) {
  25278. var _a2;
  25279. var switchToMenu = function(sandbox) {
  25280. Composing.getCurrent(sandbox).each(function(current) {
  25281. Highlighting.highlightFirst(current);
  25282. Keying.focusIn(current);
  25283. });
  25284. };
  25285. var action = function(component) {
  25286. var onOpenSync = switchToMenu;
  25287. togglePopup(detail, identity$1, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  25288. };
  25289. var openMenu = function(comp) {
  25290. action(comp);
  25291. return Optional.some(true);
  25292. };
  25293. var executeOnButton = function(comp) {
  25294. var button2 = getPartOrDie(comp, detail, "button");
  25295. emitExecute(button2);
  25296. return Optional.some(true);
  25297. };
  25298. var buttonEvents = __assign(__assign({}, derive$2([runOnAttached(function(component, _simulatedEvent) {
  25299. var ariaDescriptor = getPart(component, detail, "aria-descriptor");
  25300. ariaDescriptor.each(function(descriptor) {
  25301. var descriptorId = generate$6("aria");
  25302. set$8(descriptor.element, "id", descriptorId);
  25303. set$8(component.element, "aria-describedby", descriptorId);
  25304. });
  25305. })])), events$a(Optional.some(action)));
  25306. var apis = {
  25307. repositionMenus: function(comp) {
  25308. if (Toggling.isOn(comp)) {
  25309. repositionMenus(comp);
  25310. }
  25311. }
  25312. };
  25313. return {
  25314. uid: detail.uid,
  25315. dom: detail.dom,
  25316. components: components2,
  25317. apis,
  25318. eventOrder: __assign(__assign({}, detail.eventOrder), (_a2 = {}, _a2[execute$5()] = [
  25319. "disabling",
  25320. "toggling",
  25321. "alloy.base.behaviour"
  25322. ], _a2)),
  25323. events: buttonEvents,
  25324. behaviours: augment(detail.splitDropdownBehaviours, [
  25325. Coupling.config({
  25326. others: {
  25327. sandbox: function(hotspot) {
  25328. var arrow = getPartOrDie(hotspot, detail, "arrow");
  25329. var extras = {
  25330. onOpen: function() {
  25331. Toggling.on(arrow);
  25332. Toggling.on(hotspot);
  25333. },
  25334. onClose: function() {
  25335. Toggling.off(arrow);
  25336. Toggling.off(hotspot);
  25337. }
  25338. };
  25339. return makeSandbox$1(detail, hotspot, extras);
  25340. }
  25341. }
  25342. }),
  25343. Keying.config({
  25344. mode: "special",
  25345. onSpace: executeOnButton,
  25346. onEnter: executeOnButton,
  25347. onDown: openMenu
  25348. }),
  25349. Focusing.config({}),
  25350. Toggling.config({
  25351. toggleOnExecute: false,
  25352. aria: { mode: "expanded" }
  25353. })
  25354. ]),
  25355. domModification: {
  25356. attributes: {
  25357. "role": detail.role.getOr("button"),
  25358. "aria-haspopup": true
  25359. }
  25360. }
  25361. };
  25362. };
  25363. var SplitDropdown = composite({
  25364. name: "SplitDropdown",
  25365. configFields: schema$7(),
  25366. partFields: parts$3(),
  25367. factory: factory$5,
  25368. apis: {
  25369. repositionMenus: function(apis, comp) {
  25370. return apis.repositionMenus(comp);
  25371. }
  25372. }
  25373. });
  25374. var getButtonApi = function(component) {
  25375. return {
  25376. isDisabled: function() {
  25377. return Disabling.isDisabled(component);
  25378. },
  25379. setDisabled: function(state) {
  25380. return Disabling.set(component, state);
  25381. }
  25382. };
  25383. };
  25384. var getToggleApi = function(component) {
  25385. return {
  25386. setActive: function(state) {
  25387. Toggling.set(component, state);
  25388. },
  25389. isActive: function() {
  25390. return Toggling.isOn(component);
  25391. },
  25392. isDisabled: function() {
  25393. return Disabling.isDisabled(component);
  25394. },
  25395. setDisabled: function(state) {
  25396. return Disabling.set(component, state);
  25397. }
  25398. };
  25399. };
  25400. var getTooltipAttributes = function(tooltip, providersBackstage) {
  25401. return tooltip.map(function(tooltip2) {
  25402. return {
  25403. "aria-label": providersBackstage.translate(tooltip2),
  25404. "title": providersBackstage.translate(tooltip2)
  25405. };
  25406. }).getOr({});
  25407. };
  25408. var focusButtonEvent = generate$6("focus-button");
  25409. var renderCommonStructure = function(icon, text2, tooltip, receiver, behaviours2, providersBackstage) {
  25410. var _d;
  25411. return {
  25412. dom: {
  25413. tag: "button",
  25414. classes: ["tox-tbtn"].concat(text2.isSome() ? ["tox-tbtn--select"] : []),
  25415. attributes: getTooltipAttributes(tooltip, providersBackstage)
  25416. },
  25417. components: componentRenderPipeline([
  25418. icon.map(function(iconName) {
  25419. return renderIconFromPack(iconName, providersBackstage.icons);
  25420. }),
  25421. text2.map(function(text3) {
  25422. return renderLabel$1(text3, "tox-tbtn", providersBackstage);
  25423. })
  25424. ]),
  25425. eventOrder: (_d = {}, _d[mousedown()] = [
  25426. "focusing",
  25427. "alloy.base.behaviour",
  25428. "common-button-display-events"
  25429. ], _d),
  25430. buttonBehaviours: derive$1([
  25431. DisablingConfigs.toolbarButton(providersBackstage.isDisabled),
  25432. receivingConfig(),
  25433. config("common-button-display-events", [run$1(mousedown(), function(button2, se) {
  25434. se.event.prevent();
  25435. emit(button2, focusButtonEvent);
  25436. })])
  25437. ].concat(receiver.map(function(r2) {
  25438. return Reflecting.config({
  25439. channel: r2,
  25440. initialData: {
  25441. icon,
  25442. text: text2
  25443. },
  25444. renderComponents: function(data, _state) {
  25445. return componentRenderPipeline([
  25446. data.icon.map(function(iconName) {
  25447. return renderIconFromPack(iconName, providersBackstage.icons);
  25448. }),
  25449. data.text.map(function(text3) {
  25450. return renderLabel$1(text3, "tox-tbtn", providersBackstage);
  25451. })
  25452. ]);
  25453. }
  25454. });
  25455. }).toArray()).concat(behaviours2.getOr([])))
  25456. };
  25457. };
  25458. var renderFloatingToolbarButton = function(spec, backstage, identifyButtons2, attributes) {
  25459. var sharedBackstage = backstage.shared;
  25460. return FloatingToolbarButton.sketch({
  25461. lazySink: sharedBackstage.getSink,
  25462. fetch: function() {
  25463. return Future.nu(function(resolve) {
  25464. resolve(map$2(identifyButtons2(spec.items), renderToolbarGroup));
  25465. });
  25466. },
  25467. markers: { toggledClass: "tox-tbtn--enabled" },
  25468. parts: {
  25469. button: renderCommonStructure(spec.icon, spec.text, spec.tooltip, Optional.none(), Optional.none(), sharedBackstage.providers),
  25470. toolbar: {
  25471. dom: {
  25472. tag: "div",
  25473. classes: ["tox-toolbar__overflow"],
  25474. attributes
  25475. }
  25476. }
  25477. }
  25478. });
  25479. };
  25480. var renderCommonToolbarButton = function(spec, specialisation, providersBackstage) {
  25481. var editorOffCell = Cell(noop);
  25482. var structure = renderCommonStructure(spec.icon, spec.text, spec.tooltip, Optional.none(), Optional.none(), providersBackstage);
  25483. return Button.sketch({
  25484. dom: structure.dom,
  25485. components: structure.components,
  25486. eventOrder: toolbarButtonEventOrder,
  25487. buttonBehaviours: derive$1([
  25488. config("toolbar-button-events", [
  25489. onToolbarButtonExecute({
  25490. onAction: spec.onAction,
  25491. getApi: specialisation.getApi
  25492. }),
  25493. onControlAttached(specialisation, editorOffCell),
  25494. onControlDetached(specialisation, editorOffCell)
  25495. ]),
  25496. DisablingConfigs.toolbarButton(function() {
  25497. return spec.disabled || providersBackstage.isDisabled();
  25498. }),
  25499. receivingConfig()
  25500. ].concat(specialisation.toolbarButtonBehaviours))
  25501. });
  25502. };
  25503. var renderToolbarButton = function(spec, providersBackstage) {
  25504. return renderToolbarButtonWith(spec, providersBackstage, []);
  25505. };
  25506. var renderToolbarButtonWith = function(spec, providersBackstage, bonusEvents) {
  25507. return renderCommonToolbarButton(spec, {
  25508. toolbarButtonBehaviours: [].concat(bonusEvents.length > 0 ? [config("toolbarButtonWith", bonusEvents)] : []),
  25509. getApi: getButtonApi,
  25510. onSetup: spec.onSetup
  25511. }, providersBackstage);
  25512. };
  25513. var renderToolbarToggleButton = function(spec, providersBackstage) {
  25514. return renderToolbarToggleButtonWith(spec, providersBackstage, []);
  25515. };
  25516. var renderToolbarToggleButtonWith = function(spec, providersBackstage, bonusEvents) {
  25517. return deepMerge(renderCommonToolbarButton(spec, {
  25518. toolbarButtonBehaviours: [
  25519. Replacing.config({}),
  25520. Toggling.config({
  25521. toggleClass: "tox-tbtn--enabled",
  25522. aria: { mode: "pressed" },
  25523. toggleOnExecute: false
  25524. })
  25525. ].concat(bonusEvents.length > 0 ? [config("toolbarToggleButtonWith", bonusEvents)] : []),
  25526. getApi: getToggleApi,
  25527. onSetup: spec.onSetup
  25528. }, providersBackstage));
  25529. };
  25530. var fetchChoices = function(getApi2, spec, providersBackstage) {
  25531. return function(comp) {
  25532. return Future.nu(function(callback) {
  25533. return spec.fetch(callback);
  25534. }).map(function(items) {
  25535. return Optional.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$6("menu-value"), items, function(value2) {
  25536. spec.onItemAction(getApi2(comp), value2);
  25537. }, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, spec.select.getOr(never), providersBackstage), {
  25538. movement: deriveMenuMovement(spec.columns, spec.presets),
  25539. menuBehaviours: SimpleBehaviours.unnamedEvents(spec.columns !== "auto" ? [] : [runOnAttached(function(comp2, _se) {
  25540. detectSize(comp2, 4, classForPreset(spec.presets)).each(function(_d) {
  25541. var numRows = _d.numRows, numColumns = _d.numColumns;
  25542. Keying.setGridSize(comp2, numRows, numColumns);
  25543. });
  25544. })])
  25545. })));
  25546. });
  25547. };
  25548. };
  25549. var renderSplitButton = function(spec, sharedBackstage) {
  25550. var _d;
  25551. var displayChannel = generate$6("channel-update-split-dropdown-display");
  25552. var getApi2 = function(comp) {
  25553. return {
  25554. isDisabled: function() {
  25555. return Disabling.isDisabled(comp);
  25556. },
  25557. setDisabled: function(state) {
  25558. return Disabling.set(comp, state);
  25559. },
  25560. setIconFill: function(id, value2) {
  25561. descendant(comp.element, 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function(underlinePath) {
  25562. set$8(underlinePath, "fill", value2);
  25563. });
  25564. },
  25565. setIconStroke: function(id, value2) {
  25566. descendant(comp.element, 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function(underlinePath) {
  25567. set$8(underlinePath, "stroke", value2);
  25568. });
  25569. },
  25570. setActive: function(state) {
  25571. set$8(comp.element, "aria-pressed", state);
  25572. descendant(comp.element, "span").each(function(button2) {
  25573. comp.getSystem().getByDom(button2).each(function(buttonComp) {
  25574. return Toggling.set(buttonComp, state);
  25575. });
  25576. });
  25577. },
  25578. isActive: function() {
  25579. return descendant(comp.element, "span").exists(function(button2) {
  25580. return comp.getSystem().getByDom(button2).exists(Toggling.isOn);
  25581. });
  25582. }
  25583. };
  25584. };
  25585. var editorOffCell = Cell(noop);
  25586. var specialisation = {
  25587. getApi: getApi2,
  25588. onSetup: spec.onSetup
  25589. };
  25590. return SplitDropdown.sketch({
  25591. dom: {
  25592. tag: "div",
  25593. classes: ["tox-split-button"],
  25594. attributes: __assign({ "aria-pressed": false }, getTooltipAttributes(spec.tooltip, sharedBackstage.providers))
  25595. },
  25596. onExecute: function(button2) {
  25597. spec.onAction(getApi2(button2));
  25598. },
  25599. onItemExecute: function(_a2, _b, _c) {
  25600. },
  25601. splitDropdownBehaviours: derive$1([
  25602. DisablingConfigs.splitButton(sharedBackstage.providers.isDisabled),
  25603. receivingConfig(),
  25604. config("split-dropdown-events", [
  25605. run$1(focusButtonEvent, Focusing.focus),
  25606. onControlAttached(specialisation, editorOffCell),
  25607. onControlDetached(specialisation, editorOffCell)
  25608. ]),
  25609. Unselecting.config({})
  25610. ]),
  25611. eventOrder: (_d = {}, _d[attachedToDom()] = [
  25612. "alloy.base.behaviour",
  25613. "split-dropdown-events"
  25614. ], _d),
  25615. toggleClass: "tox-tbtn--enabled",
  25616. lazySink: sharedBackstage.getSink,
  25617. fetch: fetchChoices(getApi2, spec, sharedBackstage.providers),
  25618. parts: { menu: part(false, spec.columns, spec.presets) },
  25619. components: [
  25620. SplitDropdown.parts.button(renderCommonStructure(spec.icon, spec.text, Optional.none(), Optional.some(displayChannel), Optional.some([Toggling.config({
  25621. toggleClass: "tox-tbtn--enabled",
  25622. toggleOnExecute: false
  25623. })]), sharedBackstage.providers)),
  25624. SplitDropdown.parts.arrow({
  25625. dom: {
  25626. tag: "button",
  25627. classes: [
  25628. "tox-tbtn",
  25629. "tox-split-button__chevron"
  25630. ],
  25631. innerHtml: get$1("chevron-down", sharedBackstage.providers.icons)
  25632. },
  25633. buttonBehaviours: derive$1([
  25634. DisablingConfigs.splitButton(sharedBackstage.providers.isDisabled),
  25635. receivingConfig(),
  25636. addFocusableBehaviour()
  25637. ])
  25638. }),
  25639. SplitDropdown.parts["aria-descriptor"]({ text: sharedBackstage.providers.translate("To open the popup, press Shift+Enter") })
  25640. ]
  25641. });
  25642. };
  25643. var defaultToolbar = [
  25644. {
  25645. name: "history",
  25646. items: [
  25647. "undo",
  25648. "redo"
  25649. ]
  25650. },
  25651. {
  25652. name: "styles",
  25653. items: ["styleselect"]
  25654. },
  25655. {
  25656. name: "formatting",
  25657. items: [
  25658. "bold",
  25659. "italic"
  25660. ]
  25661. },
  25662. {
  25663. name: "alignment",
  25664. items: [
  25665. "alignleft",
  25666. "aligncenter",
  25667. "alignright",
  25668. "alignjustify"
  25669. ]
  25670. },
  25671. {
  25672. name: "indentation",
  25673. items: [
  25674. "outdent",
  25675. "indent"
  25676. ]
  25677. },
  25678. {
  25679. name: "permanent pen",
  25680. items: ["permanentpen"]
  25681. },
  25682. {
  25683. name: "comments",
  25684. items: ["addcomment"]
  25685. }
  25686. ];
  25687. var renderFromBridge = function(bridgeBuilder, render2) {
  25688. return function(spec, extras, editor) {
  25689. var internal2 = bridgeBuilder(spec).mapError(function(errInfo) {
  25690. return formatError(errInfo);
  25691. }).getOrDie();
  25692. return render2(internal2, extras, editor);
  25693. };
  25694. };
  25695. var types = {
  25696. button: renderFromBridge(createToolbarButton, function(s, extras) {
  25697. return renderToolbarButton(s, extras.backstage.shared.providers);
  25698. }),
  25699. togglebutton: renderFromBridge(createToggleButton, function(s, extras) {
  25700. return renderToolbarToggleButton(s, extras.backstage.shared.providers);
  25701. }),
  25702. menubutton: renderFromBridge(createMenuButton, function(s, extras) {
  25703. return renderMenuButton(s, "tox-tbtn", extras.backstage, Optional.none());
  25704. }),
  25705. splitbutton: renderFromBridge(createSplitButton, function(s, extras) {
  25706. return renderSplitButton(s, extras.backstage.shared);
  25707. }),
  25708. grouptoolbarbutton: renderFromBridge(createGroupToolbarButton, function(s, extras, editor) {
  25709. var _a2;
  25710. var buttons = editor.ui.registry.getAll().buttons;
  25711. var identify = function(toolbar) {
  25712. return identifyButtons(editor, {
  25713. buttons,
  25714. toolbar,
  25715. allowToolbarGroups: false
  25716. }, extras, Optional.none());
  25717. };
  25718. var attributes = (_a2 = {}, _a2[Attribute] = extras.backstage.shared.header.isPositionedAtTop() ? AttributeValue.TopToBottom : AttributeValue.BottomToTop, _a2);
  25719. switch (getToolbarMode(editor)) {
  25720. case ToolbarMode.floating:
  25721. return renderFloatingToolbarButton(s, extras.backstage, identify, attributes);
  25722. default:
  25723. throw new Error("Toolbar groups are only supported when using floating toolbar mode");
  25724. }
  25725. }),
  25726. styleSelectButton: function(editor, extras) {
  25727. return createStyleSelect(editor, extras.backstage);
  25728. },
  25729. fontsizeSelectButton: function(editor, extras) {
  25730. return createFontsizeSelect(editor, extras.backstage);
  25731. },
  25732. fontSelectButton: function(editor, extras) {
  25733. return createFontSelect(editor, extras.backstage);
  25734. },
  25735. formatButton: function(editor, extras) {
  25736. return createFormatSelect(editor, extras.backstage);
  25737. },
  25738. alignMenuButton: function(editor, extras) {
  25739. return createAlignSelect(editor, extras.backstage);
  25740. }
  25741. };
  25742. var extractFrom = function(spec, extras, editor) {
  25743. return get$e(types, spec.type).fold(function() {
  25744. console.error("skipping button defined by", spec);
  25745. return Optional.none();
  25746. }, function(render2) {
  25747. return Optional.some(render2(spec, extras, editor));
  25748. });
  25749. };
  25750. var bespokeButtons = {
  25751. styleselect: types.styleSelectButton,
  25752. fontsizeselect: types.fontsizeSelectButton,
  25753. fontselect: types.fontSelectButton,
  25754. formatselect: types.formatButton,
  25755. align: types.alignMenuButton
  25756. };
  25757. var removeUnusedDefaults = function(buttons) {
  25758. var filteredItemGroups = map$2(defaultToolbar, function(group2) {
  25759. var items = filter$2(group2.items, function(subItem) {
  25760. return has$2(buttons, subItem) || has$2(bespokeButtons, subItem);
  25761. });
  25762. return {
  25763. name: group2.name,
  25764. items
  25765. };
  25766. });
  25767. return filter$2(filteredItemGroups, function(group2) {
  25768. return group2.items.length > 0;
  25769. });
  25770. };
  25771. var convertStringToolbar = function(strToolbar) {
  25772. var groupsStrings = strToolbar.split("|");
  25773. return map$2(groupsStrings, function(g) {
  25774. return { items: g.trim().split(" ") };
  25775. });
  25776. };
  25777. var isToolbarGroupSettingArray = function(toolbar) {
  25778. return isArrayOf(toolbar, function(t2) {
  25779. return has$2(t2, "name") && has$2(t2, "items");
  25780. });
  25781. };
  25782. var createToolbar = function(toolbarConfig) {
  25783. var toolbar = toolbarConfig.toolbar;
  25784. var buttons = toolbarConfig.buttons;
  25785. if (toolbar === false) {
  25786. return [];
  25787. } else if (toolbar === void 0 || toolbar === true) {
  25788. return removeUnusedDefaults(buttons);
  25789. } else if (isString(toolbar)) {
  25790. return convertStringToolbar(toolbar);
  25791. } else if (isToolbarGroupSettingArray(toolbar)) {
  25792. return toolbar;
  25793. } else {
  25794. console.error("Toolbar type should be string, string[], boolean or ToolbarGroup[]");
  25795. return [];
  25796. }
  25797. };
  25798. var lookupButton = function(editor, buttons, toolbarItem, allowToolbarGroups, extras, prefixes) {
  25799. return get$e(buttons, toolbarItem.toLowerCase()).orThunk(function() {
  25800. return prefixes.bind(function(ps) {
  25801. return findMap(ps, function(prefix2) {
  25802. return get$e(buttons, prefix2 + toolbarItem.toLowerCase());
  25803. });
  25804. });
  25805. }).fold(function() {
  25806. return get$e(bespokeButtons, toolbarItem.toLowerCase()).map(function(r2) {
  25807. return r2(editor, extras);
  25808. }).orThunk(function() {
  25809. return Optional.none();
  25810. });
  25811. }, function(spec) {
  25812. if (spec.type === "grouptoolbarbutton" && !allowToolbarGroups) {
  25813. console.warn("Ignoring the '" + toolbarItem + "' toolbar button. Group toolbar buttons are only supported when using floating toolbar mode and cannot be nested.");
  25814. return Optional.none();
  25815. } else {
  25816. return extractFrom(spec, extras, editor);
  25817. }
  25818. });
  25819. };
  25820. var identifyButtons = function(editor, toolbarConfig, extras, prefixes) {
  25821. var toolbarGroups = createToolbar(toolbarConfig);
  25822. var groups = map$2(toolbarGroups, function(group2) {
  25823. var items = bind$3(group2.items, function(toolbarItem) {
  25824. return toolbarItem.trim().length === 0 ? [] : lookupButton(editor, toolbarConfig.buttons, toolbarItem, toolbarConfig.allowToolbarGroups, extras, prefixes).toArray();
  25825. });
  25826. return {
  25827. title: Optional.from(editor.translate(group2.name)),
  25828. items
  25829. };
  25830. });
  25831. return filter$2(groups, function(group2) {
  25832. return group2.items.length > 0;
  25833. });
  25834. };
  25835. var setToolbar = function(editor, uiComponents, rawUiConfig, backstage) {
  25836. var comp = uiComponents.outerContainer;
  25837. var toolbarConfig = rawUiConfig.toolbar;
  25838. var toolbarButtonsConfig = rawUiConfig.buttons;
  25839. if (isArrayOf(toolbarConfig, isString)) {
  25840. var toolbars = toolbarConfig.map(function(t2) {
  25841. var config2 = {
  25842. toolbar: t2,
  25843. buttons: toolbarButtonsConfig,
  25844. allowToolbarGroups: rawUiConfig.allowToolbarGroups
  25845. };
  25846. return identifyButtons(editor, config2, { backstage }, Optional.none());
  25847. });
  25848. OuterContainer.setToolbars(comp, toolbars);
  25849. } else {
  25850. OuterContainer.setToolbar(comp, identifyButtons(editor, rawUiConfig, { backstage }, Optional.none()));
  25851. }
  25852. };
  25853. var detection = detect$1();
  25854. var isiOS12 = detection.os.isiOS() && detection.os.version.major <= 12;
  25855. var setupEvents$1 = function(editor, uiComponents) {
  25856. var dom2 = editor.dom;
  25857. var contentWindow = editor.getWin();
  25858. var initialDocEle = editor.getDoc().documentElement;
  25859. var lastWindowDimensions = Cell(SugarPosition(contentWindow.innerWidth, contentWindow.innerHeight));
  25860. var lastDocumentDimensions = Cell(SugarPosition(initialDocEle.offsetWidth, initialDocEle.offsetHeight));
  25861. var resizeWindow = function() {
  25862. var outer = lastWindowDimensions.get();
  25863. if (outer.left !== contentWindow.innerWidth || outer.top !== contentWindow.innerHeight) {
  25864. lastWindowDimensions.set(SugarPosition(contentWindow.innerWidth, contentWindow.innerHeight));
  25865. fireResizeContent(editor);
  25866. }
  25867. };
  25868. var resizeDocument = function() {
  25869. var docEle = editor.getDoc().documentElement;
  25870. var inner = lastDocumentDimensions.get();
  25871. if (inner.left !== docEle.offsetWidth || inner.top !== docEle.offsetHeight) {
  25872. lastDocumentDimensions.set(SugarPosition(docEle.offsetWidth, docEle.offsetHeight));
  25873. fireResizeContent(editor);
  25874. }
  25875. };
  25876. var scroll = function(e) {
  25877. return fireScrollContent(editor, e);
  25878. };
  25879. dom2.bind(contentWindow, "resize", resizeWindow);
  25880. dom2.bind(contentWindow, "scroll", scroll);
  25881. var elementLoad = capture(SugarElement.fromDom(editor.getBody()), "load", resizeDocument);
  25882. var mothership = uiComponents.uiMothership.element;
  25883. editor.on("hide", function() {
  25884. set$7(mothership, "display", "none");
  25885. });
  25886. editor.on("show", function() {
  25887. remove$6(mothership, "display");
  25888. });
  25889. editor.on("NodeChange", resizeDocument);
  25890. editor.on("remove", function() {
  25891. elementLoad.unbind();
  25892. dom2.unbind(contentWindow, "resize", resizeWindow);
  25893. dom2.unbind(contentWindow, "scroll", scroll);
  25894. contentWindow = null;
  25895. });
  25896. };
  25897. var render$1 = function(editor, uiComponents, rawUiConfig, backstage, args) {
  25898. var lastToolbarWidth = Cell(0);
  25899. var outerContainer = uiComponents.outerContainer;
  25900. iframe(editor);
  25901. var eTargetNode = SugarElement.fromDom(args.targetNode);
  25902. var uiRoot = getContentContainer(getRootNode(eTargetNode));
  25903. attachSystemAfter(eTargetNode, uiComponents.mothership);
  25904. attachSystem(uiRoot, uiComponents.uiMothership);
  25905. editor.on("PostRender", function() {
  25906. setToolbar(editor, uiComponents, rawUiConfig, backstage);
  25907. lastToolbarWidth.set(editor.getWin().innerWidth);
  25908. OuterContainer.setMenubar(outerContainer, identifyMenus(editor, rawUiConfig));
  25909. OuterContainer.setSidebar(outerContainer, rawUiConfig.sidebar);
  25910. setupEvents$1(editor, uiComponents);
  25911. });
  25912. var socket = OuterContainer.getSocket(outerContainer).getOrDie("Could not find expected socket element");
  25913. if (isiOS12) {
  25914. setAll(socket.element, {
  25915. "overflow": "scroll",
  25916. "-webkit-overflow-scrolling": "touch"
  25917. });
  25918. var limit = first(function() {
  25919. editor.fire("ScrollContent");
  25920. }, 20);
  25921. var unbinder = bind(socket.element, "scroll", limit.throttle);
  25922. editor.on("remove", unbinder.unbind);
  25923. }
  25924. setupReadonlyModeSwitch(editor, uiComponents);
  25925. editor.addCommand("ToggleSidebar", function(_ui, value2) {
  25926. OuterContainer.toggleSidebar(outerContainer, value2);
  25927. editor.fire("ToggleSidebar");
  25928. });
  25929. editor.addQueryValueHandler("ToggleSidebar", function() {
  25930. return OuterContainer.whichSidebar(outerContainer);
  25931. });
  25932. var toolbarMode = getToolbarMode(editor);
  25933. var refreshDrawer = function() {
  25934. OuterContainer.refreshToolbar(uiComponents.outerContainer);
  25935. };
  25936. if (toolbarMode === ToolbarMode.sliding || toolbarMode === ToolbarMode.floating) {
  25937. editor.on("ResizeWindow ResizeEditor ResizeContent", function() {
  25938. var width2 = editor.getWin().innerWidth;
  25939. if (width2 !== lastToolbarWidth.get()) {
  25940. refreshDrawer();
  25941. lastToolbarWidth.set(width2);
  25942. }
  25943. });
  25944. }
  25945. var api2 = {
  25946. enable: function() {
  25947. broadcastReadonly(uiComponents, false);
  25948. },
  25949. disable: function() {
  25950. broadcastReadonly(uiComponents, true);
  25951. },
  25952. isDisabled: function() {
  25953. return Disabling.isDisabled(outerContainer);
  25954. }
  25955. };
  25956. return {
  25957. iframeContainer: socket.element.dom,
  25958. editorContainer: outerContainer.element.dom,
  25959. api: api2
  25960. };
  25961. };
  25962. var Iframe = Object.freeze({
  25963. __proto__: null,
  25964. render: render$1
  25965. });
  25966. var parseToInt = function(val) {
  25967. var re = /^[0-9\.]+(|px)$/i;
  25968. if (re.test("" + val)) {
  25969. return Optional.some(parseInt("" + val, 10));
  25970. }
  25971. return Optional.none();
  25972. };
  25973. var numToPx = function(val) {
  25974. return isNumber(val) ? val + "px" : val;
  25975. };
  25976. var calcCappedSize = function(size, minSize, maxSize) {
  25977. var minOverride = minSize.filter(function(min2) {
  25978. return size < min2;
  25979. });
  25980. var maxOverride = maxSize.filter(function(max2) {
  25981. return size > max2;
  25982. });
  25983. return minOverride.or(maxOverride).getOr(size);
  25984. };
  25985. var getHeight = function(editor) {
  25986. var baseHeight = getHeightSetting(editor);
  25987. var minHeight = getMinHeightSetting(editor);
  25988. var maxHeight = getMaxHeightSetting(editor);
  25989. return parseToInt(baseHeight).map(function(height2) {
  25990. return calcCappedSize(height2, minHeight, maxHeight);
  25991. });
  25992. };
  25993. var getHeightWithFallback = function(editor) {
  25994. var height2 = getHeight(editor);
  25995. return height2.getOr(getHeightSetting(editor));
  25996. };
  25997. var getWidth = function(editor) {
  25998. var baseWidth = getWidthSetting(editor);
  25999. var minWidth = getMinWidthSetting(editor);
  26000. var maxWidth = getMaxWidthSetting(editor);
  26001. return parseToInt(baseWidth).map(function(width2) {
  26002. return calcCappedSize(width2, minWidth, maxWidth);
  26003. });
  26004. };
  26005. var getWidthWithFallback = function(editor) {
  26006. var width2 = getWidth(editor);
  26007. return width2.getOr(getWidthSetting(editor));
  26008. };
  26009. var InlineHeader = function(editor, targetElm, uiComponents, backstage, floatContainer) {
  26010. var uiMothership = uiComponents.uiMothership, outerContainer = uiComponents.outerContainer;
  26011. var DOM = global$b.DOM;
  26012. var useFixedToolbarContainer = useFixedContainer(editor);
  26013. var isSticky = isStickyToolbar(editor);
  26014. var editorMaxWidthOpt = getMaxWidthSetting(editor).or(getWidth(editor));
  26015. var headerBackstage = backstage.shared.header;
  26016. var isPositionedAtTop = headerBackstage.isPositionedAtTop;
  26017. var toolbarMode = getToolbarMode(editor);
  26018. var isSplitToolbar = toolbarMode === ToolbarMode.sliding || toolbarMode === ToolbarMode.floating;
  26019. var visible = Cell(false);
  26020. var isVisible2 = function() {
  26021. return visible.get() && !editor.removed;
  26022. };
  26023. var calcToolbarOffset = function(toolbar) {
  26024. return isSplitToolbar ? toolbar.fold(constant$1(0), function(tbar) {
  26025. return tbar.components().length > 1 ? get$b(tbar.components()[1].element) : 0;
  26026. }) : 0;
  26027. };
  26028. var calcMode = function(container) {
  26029. switch (getToolbarLocation(editor)) {
  26030. case ToolbarLocation.auto:
  26031. var toolbar_1 = OuterContainer.getToolbar(outerContainer);
  26032. var offset2 = calcToolbarOffset(toolbar_1);
  26033. var toolbarHeight = get$b(container.element) - offset2;
  26034. var targetBounds = box$1(targetElm);
  26035. var roomAtTop = targetBounds.y > toolbarHeight;
  26036. if (roomAtTop) {
  26037. return "top";
  26038. } else {
  26039. var doc = documentElement(targetElm);
  26040. var docHeight = Math.max(doc.dom.scrollHeight, get$b(doc));
  26041. var roomAtBottom = targetBounds.bottom < docHeight - toolbarHeight;
  26042. if (roomAtBottom) {
  26043. return "bottom";
  26044. } else {
  26045. var winBounds = win();
  26046. var isRoomAtBottomViewport = winBounds.bottom < targetBounds.bottom - toolbarHeight;
  26047. return isRoomAtBottomViewport ? "bottom" : "top";
  26048. }
  26049. }
  26050. case ToolbarLocation.bottom:
  26051. return "bottom";
  26052. case ToolbarLocation.top:
  26053. default:
  26054. return "top";
  26055. }
  26056. };
  26057. var setupMode = function(mode) {
  26058. var container = floatContainer.get();
  26059. Docking.setModes(container, [mode]);
  26060. headerBackstage.setDockingMode(mode);
  26061. var verticalDir = isPositionedAtTop() ? AttributeValue.TopToBottom : AttributeValue.BottomToTop;
  26062. set$8(container.element, Attribute, verticalDir);
  26063. };
  26064. var updateChromeWidth = function() {
  26065. var maxWidth = editorMaxWidthOpt.getOrThunk(function() {
  26066. var bodyMargin = parseToInt(get$c(body(), "margin-left")).getOr(0);
  26067. return get$a(body()) - absolute$3(targetElm).left + bodyMargin;
  26068. });
  26069. set$7(floatContainer.get().element, "max-width", maxWidth + "px");
  26070. };
  26071. var updateChromePosition = function() {
  26072. var toolbar = OuterContainer.getToolbar(outerContainer);
  26073. var offset2 = calcToolbarOffset(toolbar);
  26074. var targetBounds = box$1(targetElm);
  26075. var top2 = isPositionedAtTop() ? Math.max(targetBounds.y - get$b(floatContainer.get().element) + offset2, 0) : targetBounds.bottom;
  26076. setAll(outerContainer.element, {
  26077. position: "absolute",
  26078. top: Math.round(top2) + "px",
  26079. left: Math.round(targetBounds.x) + "px"
  26080. });
  26081. };
  26082. var repositionPopups$1 = function() {
  26083. uiMothership.broadcastOn([repositionPopups()], {});
  26084. };
  26085. var updateChromeUi = function(resetDocking) {
  26086. if (resetDocking === void 0) {
  26087. resetDocking = false;
  26088. }
  26089. if (!isVisible2()) {
  26090. return;
  26091. }
  26092. if (!useFixedToolbarContainer) {
  26093. updateChromeWidth();
  26094. }
  26095. if (isSplitToolbar) {
  26096. OuterContainer.refreshToolbar(outerContainer);
  26097. }
  26098. if (!useFixedToolbarContainer) {
  26099. updateChromePosition();
  26100. }
  26101. if (isSticky) {
  26102. var floatContainerComp = floatContainer.get();
  26103. resetDocking ? Docking.reset(floatContainerComp) : Docking.refresh(floatContainerComp);
  26104. }
  26105. repositionPopups$1();
  26106. };
  26107. var updateMode = function(updateUi) {
  26108. if (updateUi === void 0) {
  26109. updateUi = true;
  26110. }
  26111. if (useFixedToolbarContainer || !isSticky || !isVisible2()) {
  26112. return;
  26113. }
  26114. var currentMode = headerBackstage.getDockingMode();
  26115. var newMode = calcMode(floatContainer.get());
  26116. if (newMode !== currentMode) {
  26117. setupMode(newMode);
  26118. if (updateUi) {
  26119. updateChromeUi(true);
  26120. }
  26121. }
  26122. };
  26123. var show2 = function() {
  26124. visible.set(true);
  26125. set$7(outerContainer.element, "display", "flex");
  26126. DOM.addClass(editor.getBody(), "mce-edit-focus");
  26127. remove$6(uiMothership.element, "display");
  26128. updateMode(false);
  26129. updateChromeUi();
  26130. };
  26131. var hide = function() {
  26132. visible.set(false);
  26133. if (uiComponents.outerContainer) {
  26134. set$7(outerContainer.element, "display", "none");
  26135. DOM.removeClass(editor.getBody(), "mce-edit-focus");
  26136. }
  26137. set$7(uiMothership.element, "display", "none");
  26138. };
  26139. return {
  26140. isVisible: isVisible2,
  26141. isPositionedAtTop,
  26142. show: show2,
  26143. hide,
  26144. update: updateChromeUi,
  26145. updateMode,
  26146. repositionPopups: repositionPopups$1
  26147. };
  26148. };
  26149. var getTargetPosAndBounds = function(targetElm, isToolbarTop) {
  26150. var bounds2 = box$1(targetElm);
  26151. return {
  26152. pos: isToolbarTop ? bounds2.y : bounds2.bottom,
  26153. bounds: bounds2
  26154. };
  26155. };
  26156. var setupEvents = function(editor, targetElm, ui, toolbarPersist) {
  26157. var prevPosAndBounds = Cell(getTargetPosAndBounds(targetElm, ui.isPositionedAtTop()));
  26158. var resizeContent = function(e) {
  26159. var _a2 = getTargetPosAndBounds(targetElm, ui.isPositionedAtTop()), pos = _a2.pos, bounds2 = _a2.bounds;
  26160. var _b = prevPosAndBounds.get(), prevPos = _b.pos, prevBounds = _b.bounds;
  26161. var hasResized = bounds2.height !== prevBounds.height || bounds2.width !== prevBounds.width;
  26162. prevPosAndBounds.set({
  26163. pos,
  26164. bounds: bounds2
  26165. });
  26166. if (hasResized) {
  26167. fireResizeContent(editor, e);
  26168. }
  26169. if (ui.isVisible()) {
  26170. if (prevPos !== pos) {
  26171. ui.update(true);
  26172. } else if (hasResized) {
  26173. ui.updateMode();
  26174. ui.repositionPopups();
  26175. }
  26176. }
  26177. };
  26178. if (!toolbarPersist) {
  26179. editor.on("activate", ui.show);
  26180. editor.on("deactivate", ui.hide);
  26181. }
  26182. editor.on("SkinLoaded ResizeWindow", function() {
  26183. return ui.update(true);
  26184. });
  26185. editor.on("NodeChange keydown", function(e) {
  26186. global$f.requestAnimationFrame(function() {
  26187. return resizeContent(e);
  26188. });
  26189. });
  26190. editor.on("ScrollWindow", function() {
  26191. return ui.updateMode();
  26192. });
  26193. var elementLoad = unbindable();
  26194. elementLoad.set(capture(SugarElement.fromDom(editor.getBody()), "load", resizeContent));
  26195. editor.on("remove", function() {
  26196. elementLoad.clear();
  26197. });
  26198. };
  26199. var render = function(editor, uiComponents, rawUiConfig, backstage, args) {
  26200. var mothership = uiComponents.mothership, uiMothership = uiComponents.uiMothership, outerContainer = uiComponents.outerContainer;
  26201. var floatContainer = Cell(null);
  26202. var targetElm = SugarElement.fromDom(args.targetNode);
  26203. var ui = InlineHeader(editor, targetElm, uiComponents, backstage, floatContainer);
  26204. var toolbarPersist = isToolbarPersist(editor);
  26205. inline(editor);
  26206. var render2 = function() {
  26207. if (floatContainer.get()) {
  26208. ui.show();
  26209. return;
  26210. }
  26211. floatContainer.set(OuterContainer.getHeader(outerContainer).getOrDie());
  26212. var uiContainer = getUiContainer(editor);
  26213. attachSystem(uiContainer, mothership);
  26214. attachSystem(uiContainer, uiMothership);
  26215. setToolbar(editor, uiComponents, rawUiConfig, backstage);
  26216. OuterContainer.setMenubar(outerContainer, identifyMenus(editor, rawUiConfig));
  26217. ui.show();
  26218. setupEvents(editor, targetElm, ui, toolbarPersist);
  26219. editor.nodeChanged();
  26220. };
  26221. editor.on("show", render2);
  26222. editor.on("hide", ui.hide);
  26223. if (!toolbarPersist) {
  26224. editor.on("focus", render2);
  26225. editor.on("blur", ui.hide);
  26226. }
  26227. editor.on("init", function() {
  26228. if (editor.hasFocus() || toolbarPersist) {
  26229. render2();
  26230. }
  26231. });
  26232. setupReadonlyModeSwitch(editor, uiComponents);
  26233. var api2 = {
  26234. show: function() {
  26235. ui.show();
  26236. },
  26237. hide: function() {
  26238. ui.hide();
  26239. },
  26240. enable: function() {
  26241. broadcastReadonly(uiComponents, false);
  26242. },
  26243. disable: function() {
  26244. broadcastReadonly(uiComponents, true);
  26245. },
  26246. isDisabled: function() {
  26247. return Disabling.isDisabled(outerContainer);
  26248. }
  26249. };
  26250. return {
  26251. editorContainer: outerContainer.element.dom,
  26252. api: api2
  26253. };
  26254. };
  26255. var Inline = Object.freeze({
  26256. __proto__: null,
  26257. render
  26258. });
  26259. var showContextToolbarEvent = "contexttoolbar-show";
  26260. var hideContextToolbarEvent = "contexttoolbar-hide";
  26261. var getFormApi = function(input2) {
  26262. return {
  26263. hide: function() {
  26264. return emit(input2, sandboxClose());
  26265. },
  26266. getValue: function() {
  26267. return Representing.getValue(input2);
  26268. }
  26269. };
  26270. };
  26271. var runOnExecute = function(memInput, original2) {
  26272. return run$1(internalToolbarButtonExecute, function(comp, se) {
  26273. var input2 = memInput.get(comp);
  26274. var formApi = getFormApi(input2);
  26275. original2.onAction(formApi, se.event.buttonApi);
  26276. });
  26277. };
  26278. var renderContextButton = function(memInput, button2, extras) {
  26279. var _a2 = button2.original;
  26280. _a2.primary;
  26281. var rest = __rest(_a2, ["primary"]);
  26282. var bridged = getOrDie(createToolbarButton(__assign(__assign({}, rest), {
  26283. type: "button",
  26284. onAction: noop
  26285. })));
  26286. return renderToolbarButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute(memInput, button2)]);
  26287. };
  26288. var renderContextToggleButton = function(memInput, button2, extras) {
  26289. var _a2 = button2.original;
  26290. _a2.primary;
  26291. var rest = __rest(_a2, ["primary"]);
  26292. var bridged = getOrDie(createToggleButton(__assign(__assign({}, rest), {
  26293. type: "togglebutton",
  26294. onAction: noop
  26295. })));
  26296. return renderToolbarToggleButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute(memInput, button2)]);
  26297. };
  26298. var generateOne = function(memInput, button2, providersBackstage) {
  26299. var extras = { backstage: { shared: { providers: providersBackstage } } };
  26300. if (button2.type === "contextformtogglebutton") {
  26301. return renderContextToggleButton(memInput, button2, extras);
  26302. } else {
  26303. return renderContextButton(memInput, button2, extras);
  26304. }
  26305. };
  26306. var generate = function(memInput, buttons, providersBackstage) {
  26307. var mementos = map$2(buttons, function(button2) {
  26308. return record(generateOne(memInput, button2, providersBackstage));
  26309. });
  26310. var asSpecs = function() {
  26311. return map$2(mementos, function(mem) {
  26312. return mem.asSpec();
  26313. });
  26314. };
  26315. var findPrimary = function(compInSystem) {
  26316. return findMap(buttons, function(button2, i) {
  26317. if (button2.primary) {
  26318. return Optional.from(mementos[i]).bind(function(mem) {
  26319. return mem.getOpt(compInSystem);
  26320. }).filter(not(Disabling.isDisabled));
  26321. } else {
  26322. return Optional.none();
  26323. }
  26324. });
  26325. };
  26326. return {
  26327. asSpecs,
  26328. findPrimary
  26329. };
  26330. };
  26331. var buildInitGroups = function(ctx, providers) {
  26332. var inputAttributes = ctx.label.fold(function() {
  26333. return {};
  26334. }, function(label) {
  26335. return { "aria-label": label };
  26336. });
  26337. var memInput = record(Input.sketch({
  26338. inputClasses: [
  26339. "tox-toolbar-textfield",
  26340. "tox-toolbar-nav-js"
  26341. ],
  26342. data: ctx.initValue(),
  26343. inputAttributes,
  26344. selectOnFocus: true,
  26345. inputBehaviours: derive$1([Keying.config({
  26346. mode: "special",
  26347. onEnter: function(input2) {
  26348. return commands.findPrimary(input2).map(function(primary) {
  26349. emitExecute(primary);
  26350. return true;
  26351. });
  26352. },
  26353. onLeft: function(comp, se) {
  26354. se.cut();
  26355. return Optional.none();
  26356. },
  26357. onRight: function(comp, se) {
  26358. se.cut();
  26359. return Optional.none();
  26360. }
  26361. })])
  26362. }));
  26363. var commands = generate(memInput, ctx.commands, providers);
  26364. return [
  26365. {
  26366. title: Optional.none(),
  26367. items: [memInput.asSpec()]
  26368. },
  26369. {
  26370. title: Optional.none(),
  26371. items: commands.asSpecs()
  26372. }
  26373. ];
  26374. };
  26375. var renderContextForm = function(toolbarType, ctx, providers) {
  26376. return renderToolbar({
  26377. type: toolbarType,
  26378. uid: generate$6("context-toolbar"),
  26379. initGroups: buildInitGroups(ctx, providers),
  26380. onEscape: Optional.none,
  26381. cyclicKeying: true,
  26382. providers
  26383. });
  26384. };
  26385. var ContextForm = {
  26386. renderContextForm,
  26387. buildInitGroups
  26388. };
  26389. var isVerticalOverlap = function(a, b2, threshold) {
  26390. if (threshold === void 0) {
  26391. threshold = 0.01;
  26392. }
  26393. return b2.bottom - a.y >= threshold && a.bottom - b2.y >= threshold;
  26394. };
  26395. var getRangeRect = function(rng) {
  26396. var rect2 = rng.getBoundingClientRect();
  26397. if (rect2.height <= 0 && rect2.width <= 0) {
  26398. var leaf$1 = leaf(SugarElement.fromDom(rng.startContainer), rng.startOffset).element;
  26399. var elm = isText$1(leaf$1) ? parent(leaf$1) : Optional.some(leaf$1);
  26400. return elm.filter(isElement$2).map(function(e) {
  26401. return e.dom.getBoundingClientRect();
  26402. }).getOr(rect2);
  26403. } else {
  26404. return rect2;
  26405. }
  26406. };
  26407. var getSelectionBounds = function(editor) {
  26408. var rng = editor.selection.getRng();
  26409. var rect2 = getRangeRect(rng);
  26410. if (editor.inline) {
  26411. var scroll_1 = get$9();
  26412. return bounds(scroll_1.left + rect2.left, scroll_1.top + rect2.top, rect2.width, rect2.height);
  26413. } else {
  26414. var bodyPos = absolute$2(SugarElement.fromDom(editor.getBody()));
  26415. return bounds(bodyPos.x + rect2.left, bodyPos.y + rect2.top, rect2.width, rect2.height);
  26416. }
  26417. };
  26418. var getAnchorElementBounds = function(editor, lastElement) {
  26419. return lastElement.filter(inBody).map(absolute$2).getOrThunk(function() {
  26420. return getSelectionBounds(editor);
  26421. });
  26422. };
  26423. var getHorizontalBounds = function(contentAreaBox, viewportBounds, margin) {
  26424. var x = Math.max(contentAreaBox.x + margin, viewportBounds.x);
  26425. var right2 = Math.min(contentAreaBox.right - margin, viewportBounds.right);
  26426. return {
  26427. x,
  26428. width: right2 - x
  26429. };
  26430. };
  26431. var getVerticalBounds = function(editor, contentAreaBox, viewportBounds, isToolbarLocationTop, toolbarType, margin) {
  26432. var container = SugarElement.fromDom(editor.getContainer());
  26433. var header = descendant(container, ".tox-editor-header").getOr(container);
  26434. var headerBox = box$1(header);
  26435. var isToolbarBelowContentArea = headerBox.y >= contentAreaBox.bottom;
  26436. var isToolbarAbove = isToolbarLocationTop && !isToolbarBelowContentArea;
  26437. if (editor.inline && isToolbarAbove) {
  26438. return {
  26439. y: Math.max(headerBox.bottom + margin, viewportBounds.y),
  26440. bottom: viewportBounds.bottom
  26441. };
  26442. }
  26443. if (editor.inline && !isToolbarAbove) {
  26444. return {
  26445. y: viewportBounds.y,
  26446. bottom: Math.min(headerBox.y - margin, viewportBounds.bottom)
  26447. };
  26448. }
  26449. var containerBounds = toolbarType === "line" ? box$1(container) : contentAreaBox;
  26450. if (isToolbarAbove) {
  26451. return {
  26452. y: Math.max(headerBox.bottom + margin, viewportBounds.y),
  26453. bottom: Math.min(containerBounds.bottom - margin, viewportBounds.bottom)
  26454. };
  26455. }
  26456. return {
  26457. y: Math.max(containerBounds.y + margin, viewportBounds.y),
  26458. bottom: Math.min(headerBox.y - margin, viewportBounds.bottom)
  26459. };
  26460. };
  26461. var getContextToolbarBounds = function(editor, sharedBackstage, toolbarType, margin) {
  26462. if (margin === void 0) {
  26463. margin = 0;
  26464. }
  26465. var viewportBounds = getBounds$3(window);
  26466. var contentAreaBox = box$1(SugarElement.fromDom(editor.getContentAreaContainer()));
  26467. var toolbarOrMenubarEnabled = isMenubarEnabled(editor) || isToolbarEnabled(editor) || isMultipleToolbars(editor);
  26468. var _a2 = getHorizontalBounds(contentAreaBox, viewportBounds, margin), x = _a2.x, width2 = _a2.width;
  26469. if (editor.inline && !toolbarOrMenubarEnabled) {
  26470. return bounds(x, viewportBounds.y, width2, viewportBounds.height);
  26471. } else {
  26472. var isToolbarTop = sharedBackstage.header.isPositionedAtTop();
  26473. var _b = getVerticalBounds(editor, contentAreaBox, viewportBounds, isToolbarTop, toolbarType, margin), y = _b.y, bottom2 = _b.bottom;
  26474. return bounds(x, y, width2, bottom2 - y);
  26475. }
  26476. };
  26477. var bubbleSize$1 = 12;
  26478. var bubbleAlignments$1 = {
  26479. valignCentre: [],
  26480. alignCentre: [],
  26481. alignLeft: ["tox-pop--align-left"],
  26482. alignRight: ["tox-pop--align-right"],
  26483. right: ["tox-pop--right"],
  26484. left: ["tox-pop--left"],
  26485. bottom: ["tox-pop--bottom"],
  26486. top: ["tox-pop--top"],
  26487. inset: ["tox-pop--inset"]
  26488. };
  26489. var anchorOverrides = {
  26490. maxHeightFunction: expandable$1(),
  26491. maxWidthFunction: expandable()
  26492. };
  26493. var isEntireElementSelected = function(editor, elem) {
  26494. var rng = editor.selection.getRng();
  26495. var leaf$1 = leaf(SugarElement.fromDom(rng.startContainer), rng.startOffset);
  26496. return rng.startContainer === rng.endContainer && rng.startOffset === rng.endOffset - 1 && eq(leaf$1.element, elem);
  26497. };
  26498. var preservePosition = function(elem, position2, f) {
  26499. var currentPosition = getRaw(elem, "position");
  26500. set$7(elem, "position", position2);
  26501. var result = f(elem);
  26502. currentPosition.each(function(pos) {
  26503. return set$7(elem, "position", pos);
  26504. });
  26505. return result;
  26506. };
  26507. var shouldUseInsetLayouts = function(position2) {
  26508. return position2 === "node";
  26509. };
  26510. var determineInsetLayout = function(editor, contextbar, elem, data, bounds2) {
  26511. var selectionBounds = getSelectionBounds(editor);
  26512. var isSameAnchorElement = data.lastElement().exists(function(prev) {
  26513. return eq(elem, prev);
  26514. });
  26515. if (isEntireElementSelected(editor, elem)) {
  26516. return isSameAnchorElement ? preserve : north;
  26517. } else if (isSameAnchorElement) {
  26518. return preservePosition(contextbar, data.getMode(), function() {
  26519. var isOverlapping = isVerticalOverlap(selectionBounds, box$1(contextbar));
  26520. return isOverlapping && !data.isReposition() ? flip$2 : preserve;
  26521. });
  26522. } else {
  26523. var yBounds = data.getMode() === "fixed" ? bounds2.y + get$9().top : bounds2.y;
  26524. var contextbarHeight = get$b(contextbar) + bubbleSize$1;
  26525. return yBounds + contextbarHeight <= selectionBounds.y ? north : south;
  26526. }
  26527. };
  26528. var getAnchorSpec$2 = function(editor, mobile, data, position2) {
  26529. var smartInsetLayout = function(elem) {
  26530. return function(anchor2, element2, bubbles, placee, bounds2) {
  26531. var layout2 = determineInsetLayout(editor, placee, elem, data, bounds2);
  26532. var newAnchor = __assign(__assign({}, anchor2), {
  26533. y: bounds2.y,
  26534. height: bounds2.height
  26535. });
  26536. return __assign(__assign({}, layout2(newAnchor, element2, bubbles, placee, bounds2)), { alwaysFit: true });
  26537. };
  26538. };
  26539. var getInsetLayouts = function(elem) {
  26540. return shouldUseInsetLayouts(position2) ? [smartInsetLayout(elem)] : [];
  26541. };
  26542. var desktopAnchorSpecLayouts = {
  26543. onLtr: function(elem) {
  26544. return [
  26545. north$2,
  26546. south$2,
  26547. northeast$2,
  26548. southeast$2,
  26549. northwest$2,
  26550. southwest$2
  26551. ].concat(getInsetLayouts(elem));
  26552. },
  26553. onRtl: function(elem) {
  26554. return [
  26555. north$2,
  26556. south$2,
  26557. northwest$2,
  26558. southwest$2,
  26559. northeast$2,
  26560. southeast$2
  26561. ].concat(getInsetLayouts(elem));
  26562. }
  26563. };
  26564. var mobileAnchorSpecLayouts = {
  26565. onLtr: function(elem) {
  26566. return [
  26567. south$2,
  26568. southeast$2,
  26569. southwest$2,
  26570. northeast$2,
  26571. northwest$2,
  26572. north$2
  26573. ].concat(getInsetLayouts(elem));
  26574. },
  26575. onRtl: function(elem) {
  26576. return [
  26577. south$2,
  26578. southwest$2,
  26579. southeast$2,
  26580. northwest$2,
  26581. northeast$2,
  26582. north$2
  26583. ].concat(getInsetLayouts(elem));
  26584. }
  26585. };
  26586. return mobile ? mobileAnchorSpecLayouts : desktopAnchorSpecLayouts;
  26587. };
  26588. var getAnchorLayout = function(editor, position2, isTouch2, data) {
  26589. if (position2 === "line") {
  26590. return {
  26591. bubble: nu$5(bubbleSize$1, 0, bubbleAlignments$1),
  26592. layouts: {
  26593. onLtr: function() {
  26594. return [east$2];
  26595. },
  26596. onRtl: function() {
  26597. return [west$2];
  26598. }
  26599. },
  26600. overrides: anchorOverrides
  26601. };
  26602. } else {
  26603. return {
  26604. bubble: nu$5(0, bubbleSize$1, bubbleAlignments$1, 1 / bubbleSize$1),
  26605. layouts: getAnchorSpec$2(editor, isTouch2, data, position2),
  26606. overrides: anchorOverrides
  26607. };
  26608. }
  26609. };
  26610. var matchTargetWith = function(elem, candidates) {
  26611. var ctxs = filter$2(candidates, function(toolbarApi) {
  26612. return toolbarApi.predicate(elem.dom);
  26613. });
  26614. var _a2 = partition$3(ctxs, function(t2) {
  26615. return t2.type === "contexttoolbar";
  26616. }), pass = _a2.pass, fail = _a2.fail;
  26617. return {
  26618. contextToolbars: pass,
  26619. contextForms: fail
  26620. };
  26621. };
  26622. var filterByPositionForStartNode = function(toolbars) {
  26623. if (toolbars.length <= 1) {
  26624. return toolbars;
  26625. } else {
  26626. var doesPositionExist = function(value2) {
  26627. return exists(toolbars, function(t2) {
  26628. return t2.position === value2;
  26629. });
  26630. };
  26631. var filterToolbarsByPosition = function(value2) {
  26632. return filter$2(toolbars, function(t2) {
  26633. return t2.position === value2;
  26634. });
  26635. };
  26636. var hasSelectionToolbars = doesPositionExist("selection");
  26637. var hasNodeToolbars = doesPositionExist("node");
  26638. if (hasSelectionToolbars || hasNodeToolbars) {
  26639. if (hasNodeToolbars && hasSelectionToolbars) {
  26640. var nodeToolbars = filterToolbarsByPosition("node");
  26641. var selectionToolbars = map$2(filterToolbarsByPosition("selection"), function(t2) {
  26642. return __assign(__assign({}, t2), { position: "node" });
  26643. });
  26644. return nodeToolbars.concat(selectionToolbars);
  26645. } else {
  26646. return hasSelectionToolbars ? filterToolbarsByPosition("selection") : filterToolbarsByPosition("node");
  26647. }
  26648. } else {
  26649. return filterToolbarsByPosition("line");
  26650. }
  26651. }
  26652. };
  26653. var filterByPositionForAncestorNode = function(toolbars) {
  26654. if (toolbars.length <= 1) {
  26655. return toolbars;
  26656. } else {
  26657. var findPosition_1 = function(value2) {
  26658. return find$5(toolbars, function(t2) {
  26659. return t2.position === value2;
  26660. });
  26661. };
  26662. var basePosition = findPosition_1("selection").orThunk(function() {
  26663. return findPosition_1("node");
  26664. }).orThunk(function() {
  26665. return findPosition_1("line");
  26666. }).map(function(t2) {
  26667. return t2.position;
  26668. });
  26669. return basePosition.fold(function() {
  26670. return [];
  26671. }, function(pos) {
  26672. return filter$2(toolbars, function(t2) {
  26673. return t2.position === pos;
  26674. });
  26675. });
  26676. }
  26677. };
  26678. var matchStartNode = function(elem, nodeCandidates, editorCandidates) {
  26679. var nodeMatches = matchTargetWith(elem, nodeCandidates);
  26680. if (nodeMatches.contextForms.length > 0) {
  26681. return Optional.some({
  26682. elem,
  26683. toolbars: [nodeMatches.contextForms[0]]
  26684. });
  26685. } else {
  26686. var editorMatches = matchTargetWith(elem, editorCandidates);
  26687. if (editorMatches.contextForms.length > 0) {
  26688. return Optional.some({
  26689. elem,
  26690. toolbars: [editorMatches.contextForms[0]]
  26691. });
  26692. } else if (nodeMatches.contextToolbars.length > 0 || editorMatches.contextToolbars.length > 0) {
  26693. var toolbars = filterByPositionForStartNode(nodeMatches.contextToolbars.concat(editorMatches.contextToolbars));
  26694. return Optional.some({
  26695. elem,
  26696. toolbars
  26697. });
  26698. } else {
  26699. return Optional.none();
  26700. }
  26701. }
  26702. };
  26703. var matchAncestor = function(isRoot, startNode, scopes) {
  26704. if (isRoot(startNode)) {
  26705. return Optional.none();
  26706. } else {
  26707. return ancestor$2(startNode, function(ancestorElem) {
  26708. if (isElement$2(ancestorElem)) {
  26709. var _a2 = matchTargetWith(ancestorElem, scopes.inNodeScope), contextToolbars = _a2.contextToolbars, contextForms = _a2.contextForms;
  26710. var toolbars = contextForms.length > 0 ? contextForms : filterByPositionForAncestorNode(contextToolbars);
  26711. return toolbars.length > 0 ? Optional.some({
  26712. elem: ancestorElem,
  26713. toolbars
  26714. }) : Optional.none();
  26715. } else {
  26716. return Optional.none();
  26717. }
  26718. }, isRoot);
  26719. }
  26720. };
  26721. var lookup$1 = function(scopes, editor) {
  26722. var rootElem = SugarElement.fromDom(editor.getBody());
  26723. var isRoot = function(elem) {
  26724. return eq(elem, rootElem);
  26725. };
  26726. var isOutsideRoot = function(startNode2) {
  26727. return !isRoot(startNode2) && !contains(rootElem, startNode2);
  26728. };
  26729. var startNode = SugarElement.fromDom(editor.selection.getNode());
  26730. if (isOutsideRoot(startNode)) {
  26731. return Optional.none();
  26732. }
  26733. return matchStartNode(startNode, scopes.inNodeScope, scopes.inEditorScope).orThunk(function() {
  26734. return matchAncestor(isRoot, startNode, scopes);
  26735. });
  26736. };
  26737. var categorise = function(contextToolbars, navigate) {
  26738. var forms = {};
  26739. var inNodeScope = [];
  26740. var inEditorScope = [];
  26741. var formNavigators = {};
  26742. var lookupTable = {};
  26743. var registerForm = function(key, toolbarSpec) {
  26744. var contextForm = getOrDie(createContextForm(toolbarSpec));
  26745. forms[key] = contextForm;
  26746. contextForm.launch.map(function(launch) {
  26747. formNavigators["form:" + key] = __assign(__assign({}, toolbarSpec.launch), {
  26748. type: launch.type === "contextformtogglebutton" ? "togglebutton" : "button",
  26749. onAction: function() {
  26750. navigate(contextForm);
  26751. }
  26752. });
  26753. });
  26754. if (contextForm.scope === "editor") {
  26755. inEditorScope.push(contextForm);
  26756. } else {
  26757. inNodeScope.push(contextForm);
  26758. }
  26759. lookupTable[key] = contextForm;
  26760. };
  26761. var registerToolbar = function(key, toolbarSpec) {
  26762. createContextToolbar(toolbarSpec).each(function(contextToolbar) {
  26763. if (toolbarSpec.scope === "editor") {
  26764. inEditorScope.push(contextToolbar);
  26765. } else {
  26766. inNodeScope.push(contextToolbar);
  26767. }
  26768. lookupTable[key] = contextToolbar;
  26769. });
  26770. };
  26771. var keys$1 = keys(contextToolbars);
  26772. each$1(keys$1, function(key) {
  26773. var toolbarApi = contextToolbars[key];
  26774. if (toolbarApi.type === "contextform") {
  26775. registerForm(key, toolbarApi);
  26776. } else if (toolbarApi.type === "contexttoolbar") {
  26777. registerToolbar(key, toolbarApi);
  26778. }
  26779. });
  26780. return {
  26781. forms,
  26782. inNodeScope,
  26783. inEditorScope,
  26784. lookupTable,
  26785. formNavigators
  26786. };
  26787. };
  26788. var forwardSlideEvent = generate$6("forward-slide");
  26789. var backSlideEvent = generate$6("backward-slide");
  26790. var changeSlideEvent = generate$6("change-slide-event");
  26791. var resizingClass = "tox-pop--resizing";
  26792. var renderContextToolbar = function(spec) {
  26793. var stack = Cell([]);
  26794. return InlineView.sketch({
  26795. dom: {
  26796. tag: "div",
  26797. classes: ["tox-pop"]
  26798. },
  26799. fireDismissalEventInstead: { event: "doNotDismissYet" },
  26800. onShow: function(comp) {
  26801. stack.set([]);
  26802. InlineView.getContent(comp).each(function(c) {
  26803. remove$6(c.element, "visibility");
  26804. });
  26805. remove$2(comp.element, resizingClass);
  26806. remove$6(comp.element, "width");
  26807. },
  26808. inlineBehaviours: derive$1([
  26809. config("context-toolbar-events", [
  26810. runOnSource(transitionend(), function(comp, se) {
  26811. if (se.event.raw.propertyName === "width") {
  26812. remove$2(comp.element, resizingClass);
  26813. remove$6(comp.element, "width");
  26814. }
  26815. }),
  26816. run$1(changeSlideEvent, function(comp, se) {
  26817. var elem = comp.element;
  26818. remove$6(elem, "width");
  26819. var currentWidth = get$a(elem);
  26820. InlineView.setContent(comp, se.event.contents);
  26821. add$2(elem, resizingClass);
  26822. var newWidth = get$a(elem);
  26823. set$7(elem, "width", currentWidth + "px");
  26824. InlineView.getContent(comp).each(function(newContents) {
  26825. se.event.focus.bind(function(f) {
  26826. focus$3(f);
  26827. return search(elem);
  26828. }).orThunk(function() {
  26829. Keying.focusIn(newContents);
  26830. return active(getRootNode(elem));
  26831. });
  26832. });
  26833. global$f.setTimeout(function() {
  26834. set$7(comp.element, "width", newWidth + "px");
  26835. }, 0);
  26836. }),
  26837. run$1(forwardSlideEvent, function(comp, se) {
  26838. InlineView.getContent(comp).each(function(oldContents) {
  26839. stack.set(stack.get().concat([{
  26840. bar: oldContents,
  26841. focus: active(getRootNode(comp.element))
  26842. }]));
  26843. });
  26844. emitWith(comp, changeSlideEvent, {
  26845. contents: se.event.forwardContents,
  26846. focus: Optional.none()
  26847. });
  26848. }),
  26849. run$1(backSlideEvent, function(comp, _se) {
  26850. last$2(stack.get()).each(function(last2) {
  26851. stack.set(stack.get().slice(0, stack.get().length - 1));
  26852. emitWith(comp, changeSlideEvent, {
  26853. contents: premade(last2.bar),
  26854. focus: last2.focus
  26855. });
  26856. });
  26857. })
  26858. ]),
  26859. Keying.config({
  26860. mode: "special",
  26861. onEscape: function(comp) {
  26862. return last$2(stack.get()).fold(function() {
  26863. return spec.onEscape();
  26864. }, function(_) {
  26865. emit(comp, backSlideEvent);
  26866. return Optional.some(true);
  26867. });
  26868. }
  26869. })
  26870. ]),
  26871. lazySink: function() {
  26872. return Result.value(spec.sink);
  26873. }
  26874. });
  26875. };
  26876. var transitionClass = "tox-pop--transition";
  26877. var register$7 = function(editor, registryContextToolbars, sink, extras) {
  26878. var backstage = extras.backstage;
  26879. var sharedBackstage = backstage.shared;
  26880. var isTouch2 = detect$1().deviceType.isTouch;
  26881. var lastElement = value$1();
  26882. var lastTrigger = value$1();
  26883. var lastContextPosition = value$1();
  26884. var contextbar = build$1(renderContextToolbar({
  26885. sink,
  26886. onEscape: function() {
  26887. editor.focus();
  26888. return Optional.some(true);
  26889. }
  26890. }));
  26891. var getBounds2 = function() {
  26892. var position2 = lastContextPosition.get().getOr("node");
  26893. var margin = shouldUseInsetLayouts(position2) ? 1 : 0;
  26894. return getContextToolbarBounds(editor, sharedBackstage, position2, margin);
  26895. };
  26896. var canLaunchToolbar = function() {
  26897. return !editor.removed && !(isTouch2() && backstage.isContextMenuOpen());
  26898. };
  26899. var isSameLaunchElement = function(elem) {
  26900. return is$1(lift2(elem, lastElement.get(), eq), true);
  26901. };
  26902. var shouldContextToolbarHide = function() {
  26903. if (!canLaunchToolbar()) {
  26904. return true;
  26905. } else {
  26906. var contextToolbarBounds = getBounds2();
  26907. var anchorBounds = is$1(lastContextPosition.get(), "node") ? getAnchorElementBounds(editor, lastElement.get()) : getSelectionBounds(editor);
  26908. return contextToolbarBounds.height <= 0 || !isVerticalOverlap(anchorBounds, contextToolbarBounds);
  26909. }
  26910. };
  26911. var close2 = function() {
  26912. lastElement.clear();
  26913. lastTrigger.clear();
  26914. lastContextPosition.clear();
  26915. InlineView.hide(contextbar);
  26916. };
  26917. var hideOrRepositionIfNecessary = function() {
  26918. if (InlineView.isOpen(contextbar)) {
  26919. var contextBarEle = contextbar.element;
  26920. remove$6(contextBarEle, "display");
  26921. if (shouldContextToolbarHide()) {
  26922. set$7(contextBarEle, "display", "none");
  26923. } else {
  26924. lastTrigger.set(0);
  26925. InlineView.reposition(contextbar);
  26926. }
  26927. }
  26928. };
  26929. var wrapInPopDialog = function(toolbarSpec) {
  26930. return {
  26931. dom: {
  26932. tag: "div",
  26933. classes: ["tox-pop__dialog"]
  26934. },
  26935. components: [toolbarSpec],
  26936. behaviours: derive$1([
  26937. Keying.config({ mode: "acyclic" }),
  26938. config("pop-dialog-wrap-events", [
  26939. runOnAttached(function(comp) {
  26940. editor.shortcuts.add("ctrl+F9", "focus statusbar", function() {
  26941. return Keying.focusIn(comp);
  26942. });
  26943. }),
  26944. runOnDetached(function(_comp) {
  26945. editor.shortcuts.remove("ctrl+F9");
  26946. })
  26947. ])
  26948. ])
  26949. };
  26950. };
  26951. var getScopes = cached(function() {
  26952. return categorise(registryContextToolbars, function(toolbarApi) {
  26953. var alloySpec = buildToolbar([toolbarApi]);
  26954. emitWith(contextbar, forwardSlideEvent, { forwardContents: wrapInPopDialog(alloySpec) });
  26955. });
  26956. });
  26957. var buildContextToolbarGroups = function(allButtons, ctx) {
  26958. return identifyButtons(editor, {
  26959. buttons: allButtons,
  26960. toolbar: ctx.items,
  26961. allowToolbarGroups: false
  26962. }, extras, Optional.some(["form:"]));
  26963. };
  26964. var buildContextFormGroups = function(ctx, providers) {
  26965. return ContextForm.buildInitGroups(ctx, providers);
  26966. };
  26967. var buildToolbar = function(toolbars) {
  26968. var buttons = editor.ui.registry.getAll().buttons;
  26969. var scopes = getScopes();
  26970. var allButtons = __assign(__assign({}, buttons), scopes.formNavigators);
  26971. var toolbarType = getToolbarMode(editor) === ToolbarMode.scrolling ? ToolbarMode.scrolling : ToolbarMode.default;
  26972. var initGroups = flatten(map$2(toolbars, function(ctx) {
  26973. return ctx.type === "contexttoolbar" ? buildContextToolbarGroups(allButtons, ctx) : buildContextFormGroups(ctx, sharedBackstage.providers);
  26974. }));
  26975. return renderToolbar({
  26976. type: toolbarType,
  26977. uid: generate$6("context-toolbar"),
  26978. initGroups,
  26979. onEscape: Optional.none,
  26980. cyclicKeying: true,
  26981. providers: sharedBackstage.providers
  26982. });
  26983. };
  26984. var getAnchor2 = function(position2, element2) {
  26985. var anchorage = position2 === "node" ? sharedBackstage.anchors.node(element2) : sharedBackstage.anchors.cursor();
  26986. var anchorLayout = getAnchorLayout(editor, position2, isTouch2(), {
  26987. lastElement: lastElement.get,
  26988. isReposition: function() {
  26989. return is$1(lastTrigger.get(), 0);
  26990. },
  26991. getMode: function() {
  26992. return Positioning.getMode(sink);
  26993. }
  26994. });
  26995. return deepMerge(anchorage, anchorLayout);
  26996. };
  26997. var launchContext = function(toolbarApi, elem) {
  26998. launchContextToolbar.cancel();
  26999. if (!canLaunchToolbar()) {
  27000. return;
  27001. }
  27002. var toolbarSpec = buildToolbar(toolbarApi);
  27003. var position2 = toolbarApi[0].position;
  27004. var anchor2 = getAnchor2(position2, elem);
  27005. lastContextPosition.set(position2);
  27006. lastTrigger.set(1);
  27007. var contextBarEle = contextbar.element;
  27008. remove$6(contextBarEle, "display");
  27009. if (!isSameLaunchElement(elem)) {
  27010. remove$2(contextBarEle, transitionClass);
  27011. Positioning.reset(sink, contextbar);
  27012. }
  27013. InlineView.showWithinBounds(contextbar, wrapInPopDialog(toolbarSpec), {
  27014. anchor: anchor2,
  27015. transition: {
  27016. classes: [transitionClass],
  27017. mode: "placement"
  27018. }
  27019. }, function() {
  27020. return Optional.some(getBounds2());
  27021. });
  27022. elem.fold(lastElement.clear, lastElement.set);
  27023. if (shouldContextToolbarHide()) {
  27024. set$7(contextBarEle, "display", "none");
  27025. }
  27026. };
  27027. var launchContextToolbar = last(function() {
  27028. if (!editor.hasFocus() || editor.removed) {
  27029. return;
  27030. }
  27031. if (has(contextbar.element, transitionClass)) {
  27032. launchContextToolbar.throttle();
  27033. } else {
  27034. var scopes = getScopes();
  27035. lookup$1(scopes, editor).fold(close2, function(info) {
  27036. launchContext(info.toolbars, Optional.some(info.elem));
  27037. });
  27038. }
  27039. }, 17);
  27040. editor.on("init", function() {
  27041. editor.on("remove", close2);
  27042. editor.on("ScrollContent ScrollWindow ObjectResized ResizeEditor longpress", hideOrRepositionIfNecessary);
  27043. editor.on("click keyup focus SetContent", launchContextToolbar.throttle);
  27044. editor.on(hideContextToolbarEvent, close2);
  27045. editor.on(showContextToolbarEvent, function(e) {
  27046. var scopes = getScopes();
  27047. get$e(scopes.lookupTable, e.toolbarKey).each(function(ctx) {
  27048. launchContext([ctx], someIf(e.target !== editor, e.target));
  27049. InlineView.getContent(contextbar).each(Keying.focusIn);
  27050. });
  27051. });
  27052. editor.on("focusout", function(_e) {
  27053. global$f.setEditorTimeout(editor, function() {
  27054. if (search(sink.element).isNone() && search(contextbar.element).isNone()) {
  27055. close2();
  27056. }
  27057. }, 0);
  27058. });
  27059. editor.on("SwitchMode", function() {
  27060. if (editor.mode.isReadOnly()) {
  27061. close2();
  27062. }
  27063. });
  27064. editor.on("AfterProgressState", function(event) {
  27065. if (event.state) {
  27066. close2();
  27067. } else if (editor.hasFocus()) {
  27068. launchContextToolbar.throttle();
  27069. }
  27070. });
  27071. editor.on("NodeChange", function(_e) {
  27072. search(contextbar.element).fold(launchContextToolbar.throttle, noop);
  27073. });
  27074. });
  27075. };
  27076. var register$6 = function(editor) {
  27077. var alignToolbarButtons = [
  27078. {
  27079. name: "alignleft",
  27080. text: "Align left",
  27081. cmd: "JustifyLeft",
  27082. icon: "align-left"
  27083. },
  27084. {
  27085. name: "aligncenter",
  27086. text: "Align center",
  27087. cmd: "JustifyCenter",
  27088. icon: "align-center"
  27089. },
  27090. {
  27091. name: "alignright",
  27092. text: "Align right",
  27093. cmd: "JustifyRight",
  27094. icon: "align-right"
  27095. },
  27096. {
  27097. name: "alignjustify",
  27098. text: "Justify",
  27099. cmd: "JustifyFull",
  27100. icon: "align-justify"
  27101. }
  27102. ];
  27103. each$1(alignToolbarButtons, function(item2) {
  27104. editor.ui.registry.addToggleButton(item2.name, {
  27105. tooltip: item2.text,
  27106. icon: item2.icon,
  27107. onAction: onActionExecCommand(editor, item2.cmd),
  27108. onSetup: onSetupFormatToggle(editor, item2.name)
  27109. });
  27110. });
  27111. editor.ui.registry.addButton("alignnone", {
  27112. tooltip: "No alignment",
  27113. icon: "align-none",
  27114. onAction: onActionExecCommand(editor, "JustifyNone")
  27115. });
  27116. };
  27117. var units = {
  27118. unsupportedLength: [
  27119. "em",
  27120. "ex",
  27121. "cap",
  27122. "ch",
  27123. "ic",
  27124. "rem",
  27125. "lh",
  27126. "rlh",
  27127. "vw",
  27128. "vh",
  27129. "vi",
  27130. "vb",
  27131. "vmin",
  27132. "vmax",
  27133. "cm",
  27134. "mm",
  27135. "Q",
  27136. "in",
  27137. "pc",
  27138. "pt",
  27139. "px"
  27140. ],
  27141. fixed: [
  27142. "px",
  27143. "pt"
  27144. ],
  27145. relative: ["%"],
  27146. empty: [""]
  27147. };
  27148. var pattern = function() {
  27149. var decimalDigits = "[0-9]+";
  27150. var signedInteger = "[+-]?" + decimalDigits;
  27151. var exponentPart = "[eE]" + signedInteger;
  27152. var dot = "\\.";
  27153. var opt = function(input2) {
  27154. return "(?:" + input2 + ")?";
  27155. };
  27156. var unsignedDecimalLiteral = [
  27157. "Infinity",
  27158. decimalDigits + dot + opt(decimalDigits) + opt(exponentPart),
  27159. dot + decimalDigits + opt(exponentPart),
  27160. decimalDigits + opt(exponentPart)
  27161. ].join("|");
  27162. var float = "[+-]?(?:" + unsignedDecimalLiteral + ")";
  27163. return new RegExp("^(" + float + ")(.*)$");
  27164. }();
  27165. var isUnit = function(unit, accepted) {
  27166. return exists(accepted, function(acc) {
  27167. return exists(units[acc], function(check) {
  27168. return unit === check;
  27169. });
  27170. });
  27171. };
  27172. var parse = function(input2, accepted) {
  27173. var match = Optional.from(pattern.exec(input2));
  27174. return match.bind(function(array) {
  27175. var value2 = Number(array[1]);
  27176. var unitRaw = array[2];
  27177. if (isUnit(unitRaw, accepted)) {
  27178. return Optional.some({
  27179. value: value2,
  27180. unit: unitRaw
  27181. });
  27182. } else {
  27183. return Optional.none();
  27184. }
  27185. });
  27186. };
  27187. var normalise = function(input2, accepted) {
  27188. return parse(input2, accepted).map(function(_a2) {
  27189. var value2 = _a2.value, unit = _a2.unit;
  27190. return value2 + unit;
  27191. });
  27192. };
  27193. var registerController = function(editor, spec) {
  27194. var getMenuItems2 = function() {
  27195. var options = spec.getOptions(editor);
  27196. var initial = spec.getCurrent(editor).map(spec.hash);
  27197. var current = value$1();
  27198. return map$2(options, function(value2) {
  27199. return {
  27200. type: "togglemenuitem",
  27201. text: spec.display(value2),
  27202. onSetup: function(api2) {
  27203. var setActive = function(active2) {
  27204. if (active2) {
  27205. current.on(function(oldApi) {
  27206. return oldApi.setActive(false);
  27207. });
  27208. current.set(api2);
  27209. }
  27210. api2.setActive(active2);
  27211. };
  27212. setActive(is$1(initial, spec.hash(value2)));
  27213. var unbindWatcher = spec.watcher(editor, value2, setActive);
  27214. return function() {
  27215. current.clear();
  27216. unbindWatcher();
  27217. };
  27218. },
  27219. onAction: function() {
  27220. return spec.setCurrent(editor, value2);
  27221. }
  27222. };
  27223. });
  27224. };
  27225. editor.ui.registry.addMenuButton(spec.name, {
  27226. tooltip: spec.text,
  27227. icon: spec.icon,
  27228. fetch: function(callback) {
  27229. return callback(getMenuItems2());
  27230. },
  27231. onSetup: spec.onToolbarSetup
  27232. });
  27233. editor.ui.registry.addNestedMenuItem(spec.name, {
  27234. type: "nestedmenuitem",
  27235. text: spec.text,
  27236. getSubmenuItems: getMenuItems2,
  27237. onSetup: spec.onMenuSetup
  27238. });
  27239. };
  27240. var lineHeightSpec = {
  27241. name: "lineheight",
  27242. text: "Line height",
  27243. icon: "line-height",
  27244. getOptions: getLineHeightFormats,
  27245. hash: function(input2) {
  27246. return normalise(input2, [
  27247. "fixed",
  27248. "relative",
  27249. "empty"
  27250. ]).getOr(input2);
  27251. },
  27252. display: identity$1,
  27253. watcher: function(editor, value2, callback) {
  27254. return editor.formatter.formatChanged("lineheight", callback, false, { value: value2 }).unbind;
  27255. },
  27256. getCurrent: function(editor) {
  27257. return Optional.from(editor.queryCommandValue("LineHeight"));
  27258. },
  27259. setCurrent: function(editor, value2) {
  27260. return editor.execCommand("LineHeight", false, value2);
  27261. }
  27262. };
  27263. var languageSpec = function(editor) {
  27264. var settingsOpt = Optional.from(getContentLanguages(editor));
  27265. return settingsOpt.map(function(settings) {
  27266. return {
  27267. name: "language",
  27268. text: "Language",
  27269. icon: "language",
  27270. getOptions: constant$1(settings),
  27271. hash: function(input2) {
  27272. return isUndefined(input2.customCode) ? input2.code : input2.code + "/" + input2.customCode;
  27273. },
  27274. display: function(input2) {
  27275. return input2.title;
  27276. },
  27277. watcher: function(editor2, value2, callback) {
  27278. return editor2.formatter.formatChanged("lang", callback, false, {
  27279. value: value2.code,
  27280. customValue: value2.customCode
  27281. }).unbind;
  27282. },
  27283. getCurrent: function(editor2) {
  27284. var node = SugarElement.fromDom(editor2.selection.getNode());
  27285. return closest$4(node, function(n) {
  27286. return Optional.some(n).filter(isElement$2).bind(function(ele) {
  27287. var codeOpt = getOpt(ele, "lang");
  27288. return codeOpt.map(function(code) {
  27289. var customCode = getOpt(ele, "data-mce-lang").getOrUndefined();
  27290. return {
  27291. code,
  27292. customCode,
  27293. title: ""
  27294. };
  27295. });
  27296. });
  27297. });
  27298. },
  27299. setCurrent: function(editor2, lang) {
  27300. return editor2.execCommand("Lang", false, lang);
  27301. },
  27302. onToolbarSetup: function(api2) {
  27303. var unbinder = unbindable();
  27304. api2.setActive(editor.formatter.match("lang", {}, void 0, true));
  27305. unbinder.set(editor.formatter.formatChanged("lang", api2.setActive, true));
  27306. return unbinder.clear;
  27307. }
  27308. };
  27309. });
  27310. };
  27311. var register$5 = function(editor) {
  27312. registerController(editor, lineHeightSpec);
  27313. languageSpec(editor).each(function(spec) {
  27314. return registerController(editor, spec);
  27315. });
  27316. };
  27317. var register$4 = function(editor, backstage) {
  27318. alignSelectMenu(editor, backstage);
  27319. fontSelectMenu(editor, backstage);
  27320. styleSelectMenu(editor, backstage);
  27321. formatSelectMenu(editor, backstage);
  27322. fontsizeSelectMenu(editor, backstage);
  27323. };
  27324. var onSetupOutdentState = function(editor) {
  27325. return onSetupEvent(editor, "NodeChange", function(api2) {
  27326. api2.setDisabled(!editor.queryCommandState("outdent"));
  27327. });
  27328. };
  27329. var registerButtons$2 = function(editor) {
  27330. editor.ui.registry.addButton("outdent", {
  27331. tooltip: "Decrease indent",
  27332. icon: "outdent",
  27333. onSetup: onSetupOutdentState(editor),
  27334. onAction: onActionExecCommand(editor, "outdent")
  27335. });
  27336. editor.ui.registry.addButton("indent", {
  27337. tooltip: "Increase indent",
  27338. icon: "indent",
  27339. onAction: onActionExecCommand(editor, "indent")
  27340. });
  27341. };
  27342. var register$3 = function(editor) {
  27343. registerButtons$2(editor);
  27344. };
  27345. var onActionToggleFormat = function(editor, fmt) {
  27346. return function() {
  27347. editor.execCommand("mceToggleFormat", false, fmt);
  27348. };
  27349. };
  27350. var registerFormatButtons = function(editor) {
  27351. global$5.each([
  27352. {
  27353. name: "bold",
  27354. text: "Bold",
  27355. icon: "bold"
  27356. },
  27357. {
  27358. name: "italic",
  27359. text: "Italic",
  27360. icon: "italic"
  27361. },
  27362. {
  27363. name: "underline",
  27364. text: "Underline",
  27365. icon: "underline"
  27366. },
  27367. {
  27368. name: "strikethrough",
  27369. text: "Strikethrough",
  27370. icon: "strike-through"
  27371. },
  27372. {
  27373. name: "subscript",
  27374. text: "Subscript",
  27375. icon: "subscript"
  27376. },
  27377. {
  27378. name: "superscript",
  27379. text: "Superscript",
  27380. icon: "superscript"
  27381. }
  27382. ], function(btn, _idx) {
  27383. editor.ui.registry.addToggleButton(btn.name, {
  27384. tooltip: btn.text,
  27385. icon: btn.icon,
  27386. onSetup: onSetupFormatToggle(editor, btn.name),
  27387. onAction: onActionToggleFormat(editor, btn.name)
  27388. });
  27389. });
  27390. for (var i = 1; i <= 6; i++) {
  27391. var name_1 = "h" + i;
  27392. editor.ui.registry.addToggleButton(name_1, {
  27393. text: name_1.toUpperCase(),
  27394. tooltip: "Heading " + i,
  27395. onSetup: onSetupFormatToggle(editor, name_1),
  27396. onAction: onActionToggleFormat(editor, name_1)
  27397. });
  27398. }
  27399. };
  27400. var registerCommandButtons = function(editor) {
  27401. global$5.each([
  27402. {
  27403. name: "cut",
  27404. text: "Cut",
  27405. action: "Cut",
  27406. icon: "cut"
  27407. },
  27408. {
  27409. name: "copy",
  27410. text: "Copy",
  27411. action: "Copy",
  27412. icon: "copy"
  27413. },
  27414. {
  27415. name: "paste",
  27416. text: "Paste",
  27417. action: "Paste",
  27418. icon: "paste"
  27419. },
  27420. {
  27421. name: "help",
  27422. text: "Help",
  27423. action: "mceHelp",
  27424. icon: "help"
  27425. },
  27426. {
  27427. name: "selectall",
  27428. text: "Select all",
  27429. action: "SelectAll",
  27430. icon: "select-all"
  27431. },
  27432. {
  27433. name: "newdocument",
  27434. text: "New document",
  27435. action: "mceNewDocument",
  27436. icon: "new-document"
  27437. },
  27438. {
  27439. name: "removeformat",
  27440. text: "Clear formatting",
  27441. action: "RemoveFormat",
  27442. icon: "remove-formatting"
  27443. },
  27444. {
  27445. name: "remove",
  27446. text: "Remove",
  27447. action: "Delete",
  27448. icon: "remove"
  27449. }
  27450. ], function(btn) {
  27451. editor.ui.registry.addButton(btn.name, {
  27452. tooltip: btn.text,
  27453. icon: btn.icon,
  27454. onAction: onActionExecCommand(editor, btn.action)
  27455. });
  27456. });
  27457. };
  27458. var registerCommandToggleButtons = function(editor) {
  27459. global$5.each([{
  27460. name: "blockquote",
  27461. text: "Blockquote",
  27462. action: "mceBlockQuote",
  27463. icon: "quote"
  27464. }], function(btn) {
  27465. editor.ui.registry.addToggleButton(btn.name, {
  27466. tooltip: btn.text,
  27467. icon: btn.icon,
  27468. onAction: onActionExecCommand(editor, btn.action),
  27469. onSetup: onSetupFormatToggle(editor, btn.name)
  27470. });
  27471. });
  27472. };
  27473. var registerButtons$1 = function(editor) {
  27474. registerFormatButtons(editor);
  27475. registerCommandButtons(editor);
  27476. registerCommandToggleButtons(editor);
  27477. };
  27478. var registerMenuItems$2 = function(editor) {
  27479. global$5.each([
  27480. {
  27481. name: "bold",
  27482. text: "Bold",
  27483. action: "Bold",
  27484. icon: "bold",
  27485. shortcut: "Meta+B"
  27486. },
  27487. {
  27488. name: "italic",
  27489. text: "Italic",
  27490. action: "Italic",
  27491. icon: "italic",
  27492. shortcut: "Meta+I"
  27493. },
  27494. {
  27495. name: "underline",
  27496. text: "Underline",
  27497. action: "Underline",
  27498. icon: "underline",
  27499. shortcut: "Meta+U"
  27500. },
  27501. {
  27502. name: "strikethrough",
  27503. text: "Strikethrough",
  27504. action: "Strikethrough",
  27505. icon: "strike-through",
  27506. shortcut: ""
  27507. },
  27508. {
  27509. name: "subscript",
  27510. text: "Subscript",
  27511. action: "Subscript",
  27512. icon: "subscript",
  27513. shortcut: ""
  27514. },
  27515. {
  27516. name: "superscript",
  27517. text: "Superscript",
  27518. action: "Superscript",
  27519. icon: "superscript",
  27520. shortcut: ""
  27521. },
  27522. {
  27523. name: "removeformat",
  27524. text: "Clear formatting",
  27525. action: "RemoveFormat",
  27526. icon: "remove-formatting",
  27527. shortcut: ""
  27528. },
  27529. {
  27530. name: "newdocument",
  27531. text: "New document",
  27532. action: "mceNewDocument",
  27533. icon: "new-document",
  27534. shortcut: ""
  27535. },
  27536. {
  27537. name: "cut",
  27538. text: "Cut",
  27539. action: "Cut",
  27540. icon: "cut",
  27541. shortcut: "Meta+X"
  27542. },
  27543. {
  27544. name: "copy",
  27545. text: "Copy",
  27546. action: "Copy",
  27547. icon: "copy",
  27548. shortcut: "Meta+C"
  27549. },
  27550. {
  27551. name: "paste",
  27552. text: "Paste",
  27553. action: "Paste",
  27554. icon: "paste",
  27555. shortcut: "Meta+V"
  27556. },
  27557. {
  27558. name: "selectall",
  27559. text: "Select all",
  27560. action: "SelectAll",
  27561. icon: "select-all",
  27562. shortcut: "Meta+A"
  27563. }
  27564. ], function(btn) {
  27565. editor.ui.registry.addMenuItem(btn.name, {
  27566. text: btn.text,
  27567. icon: btn.icon,
  27568. shortcut: btn.shortcut,
  27569. onAction: onActionExecCommand(editor, btn.action)
  27570. });
  27571. });
  27572. editor.ui.registry.addMenuItem("codeformat", {
  27573. text: "Code",
  27574. icon: "sourcecode",
  27575. onAction: onActionToggleFormat(editor, "code")
  27576. });
  27577. };
  27578. var register$2 = function(editor) {
  27579. registerButtons$1(editor);
  27580. registerMenuItems$2(editor);
  27581. };
  27582. var onSetupUndoRedoState = function(editor, type2) {
  27583. return onSetupEvent(editor, "Undo Redo AddUndo TypingUndo ClearUndos SwitchMode", function(api2) {
  27584. api2.setDisabled(editor.mode.isReadOnly() || !editor.undoManager[type2]());
  27585. });
  27586. };
  27587. var registerMenuItems$1 = function(editor) {
  27588. editor.ui.registry.addMenuItem("undo", {
  27589. text: "Undo",
  27590. icon: "undo",
  27591. shortcut: "Meta+Z",
  27592. onSetup: onSetupUndoRedoState(editor, "hasUndo"),
  27593. onAction: onActionExecCommand(editor, "undo")
  27594. });
  27595. editor.ui.registry.addMenuItem("redo", {
  27596. text: "Redo",
  27597. icon: "redo",
  27598. shortcut: "Meta+Y",
  27599. onSetup: onSetupUndoRedoState(editor, "hasRedo"),
  27600. onAction: onActionExecCommand(editor, "redo")
  27601. });
  27602. };
  27603. var registerButtons = function(editor) {
  27604. editor.ui.registry.addButton("undo", {
  27605. tooltip: "Undo",
  27606. icon: "undo",
  27607. disabled: true,
  27608. onSetup: onSetupUndoRedoState(editor, "hasUndo"),
  27609. onAction: onActionExecCommand(editor, "undo")
  27610. });
  27611. editor.ui.registry.addButton("redo", {
  27612. tooltip: "Redo",
  27613. icon: "redo",
  27614. disabled: true,
  27615. onSetup: onSetupUndoRedoState(editor, "hasRedo"),
  27616. onAction: onActionExecCommand(editor, "redo")
  27617. });
  27618. };
  27619. var register$1 = function(editor) {
  27620. registerMenuItems$1(editor);
  27621. registerButtons(editor);
  27622. };
  27623. var onSetupVisualAidState = function(editor) {
  27624. return onSetupEvent(editor, "VisualAid", function(api2) {
  27625. api2.setActive(editor.hasVisual);
  27626. });
  27627. };
  27628. var registerMenuItems = function(editor) {
  27629. editor.ui.registry.addToggleMenuItem("visualaid", {
  27630. text: "Visual aids",
  27631. onSetup: onSetupVisualAidState(editor),
  27632. onAction: onActionExecCommand(editor, "mceToggleVisualAid")
  27633. });
  27634. };
  27635. var registerToolbarButton = function(editor) {
  27636. editor.ui.registry.addButton("visualaid", {
  27637. tooltip: "Visual aids",
  27638. text: "Visual aids",
  27639. onAction: onActionExecCommand(editor, "mceToggleVisualAid")
  27640. });
  27641. };
  27642. var register = function(editor) {
  27643. registerToolbarButton(editor);
  27644. registerMenuItems(editor);
  27645. };
  27646. var setup$6 = function(editor, backstage) {
  27647. register$6(editor);
  27648. register$2(editor);
  27649. register$4(editor, backstage);
  27650. register$1(editor);
  27651. register$a(editor);
  27652. register(editor);
  27653. register$3(editor);
  27654. register$5(editor);
  27655. };
  27656. var nu = function(x, y) {
  27657. return {
  27658. type: "makeshift",
  27659. x,
  27660. y
  27661. };
  27662. };
  27663. var transpose = function(pos, dx, dy) {
  27664. return nu(pos.x + dx, pos.y + dy);
  27665. };
  27666. var isTouchEvent = function(e) {
  27667. return e.type === "longpress" || e.type.indexOf("touch") === 0;
  27668. };
  27669. var fromPageXY = function(e) {
  27670. if (isTouchEvent(e)) {
  27671. var touch2 = e.touches[0];
  27672. return nu(touch2.pageX, touch2.pageY);
  27673. } else {
  27674. return nu(e.pageX, e.pageY);
  27675. }
  27676. };
  27677. var fromClientXY = function(e) {
  27678. if (isTouchEvent(e)) {
  27679. var touch2 = e.touches[0];
  27680. return nu(touch2.clientX, touch2.clientY);
  27681. } else {
  27682. return nu(e.clientX, e.clientY);
  27683. }
  27684. };
  27685. var transposeContentAreaContainer = function(element2, pos) {
  27686. var containerPos = global$b.DOM.getPos(element2);
  27687. return transpose(pos, containerPos.x, containerPos.y);
  27688. };
  27689. var getPointAnchor = function(editor, e) {
  27690. if (e.type === "contextmenu" || e.type === "longpress") {
  27691. if (editor.inline) {
  27692. return fromPageXY(e);
  27693. } else {
  27694. return transposeContentAreaContainer(editor.getContentAreaContainer(), fromClientXY(e));
  27695. }
  27696. } else {
  27697. return getSelectionAnchor(editor);
  27698. }
  27699. };
  27700. var getSelectionAnchor = function(editor) {
  27701. return {
  27702. type: "selection",
  27703. root: SugarElement.fromDom(editor.selection.getNode())
  27704. };
  27705. };
  27706. var getNodeAnchor = function(editor) {
  27707. return {
  27708. type: "node",
  27709. node: Optional.some(SugarElement.fromDom(editor.selection.getNode())),
  27710. root: SugarElement.fromDom(editor.getBody())
  27711. };
  27712. };
  27713. var getAnchorSpec$1 = function(editor, e, anchorType) {
  27714. switch (anchorType) {
  27715. case "node":
  27716. return getNodeAnchor(editor);
  27717. case "point":
  27718. return getPointAnchor(editor, e);
  27719. case "selection":
  27720. return getSelectionAnchor(editor);
  27721. }
  27722. };
  27723. var initAndShow$1 = function(editor, e, buildMenu, backstage, contextmenu, anchorType) {
  27724. var items = buildMenu();
  27725. var anchorSpec = getAnchorSpec$1(editor, e, anchorType);
  27726. build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false).map(function(menuData) {
  27727. e.preventDefault();
  27728. InlineView.showMenuAt(contextmenu, { anchor: anchorSpec }, {
  27729. menu: { markers: markers("normal") },
  27730. data: menuData
  27731. });
  27732. });
  27733. };
  27734. var layouts = {
  27735. onLtr: function() {
  27736. return [
  27737. south$2,
  27738. southeast$2,
  27739. southwest$2,
  27740. northeast$2,
  27741. northwest$2,
  27742. north$2,
  27743. north,
  27744. south,
  27745. northeast,
  27746. southeast,
  27747. northwest,
  27748. southwest
  27749. ];
  27750. },
  27751. onRtl: function() {
  27752. return [
  27753. south$2,
  27754. southwest$2,
  27755. southeast$2,
  27756. northwest$2,
  27757. northeast$2,
  27758. north$2,
  27759. north,
  27760. south,
  27761. northwest,
  27762. southwest,
  27763. northeast,
  27764. southeast
  27765. ];
  27766. }
  27767. };
  27768. var bubbleSize = 12;
  27769. var bubbleAlignments = {
  27770. valignCentre: [],
  27771. alignCentre: [],
  27772. alignLeft: ["tox-pop--align-left"],
  27773. alignRight: ["tox-pop--align-right"],
  27774. right: ["tox-pop--right"],
  27775. left: ["tox-pop--left"],
  27776. bottom: ["tox-pop--bottom"],
  27777. top: ["tox-pop--top"]
  27778. };
  27779. var isTouchWithinSelection = function(editor, e) {
  27780. var selection = editor.selection;
  27781. if (selection.isCollapsed() || e.touches.length < 1) {
  27782. return false;
  27783. } else {
  27784. var touch_1 = e.touches[0];
  27785. var rng = selection.getRng();
  27786. var rngRectOpt = getFirstRect(editor.getWin(), SimSelection.domRange(rng));
  27787. return rngRectOpt.exists(function(rngRect) {
  27788. return rngRect.left <= touch_1.clientX && rngRect.right >= touch_1.clientX && rngRect.top <= touch_1.clientY && rngRect.bottom >= touch_1.clientY;
  27789. });
  27790. }
  27791. };
  27792. var setupiOSOverrides = function(editor) {
  27793. var originalSelection = editor.selection.getRng();
  27794. var selectionReset = function() {
  27795. global$f.setEditorTimeout(editor, function() {
  27796. editor.selection.setRng(originalSelection);
  27797. }, 10);
  27798. unbindEventListeners();
  27799. };
  27800. editor.once("touchend", selectionReset);
  27801. var preventMousedown = function(e) {
  27802. e.preventDefault();
  27803. e.stopImmediatePropagation();
  27804. };
  27805. editor.on("mousedown", preventMousedown, true);
  27806. var clearSelectionReset = function() {
  27807. return unbindEventListeners();
  27808. };
  27809. editor.once("longpresscancel", clearSelectionReset);
  27810. var unbindEventListeners = function() {
  27811. editor.off("touchend", selectionReset);
  27812. editor.off("longpresscancel", clearSelectionReset);
  27813. editor.off("mousedown", preventMousedown);
  27814. };
  27815. };
  27816. var getAnchorSpec = function(editor, e, anchorType) {
  27817. var anchorSpec = getAnchorSpec$1(editor, e, anchorType);
  27818. var bubbleYOffset = anchorType === "point" ? bubbleSize : 0;
  27819. return __assign({
  27820. bubble: nu$5(0, bubbleYOffset, bubbleAlignments),
  27821. layouts,
  27822. overrides: {
  27823. maxWidthFunction: expandable(),
  27824. maxHeightFunction: expandable$1()
  27825. }
  27826. }, anchorSpec);
  27827. };
  27828. var show = function(editor, e, items, backstage, contextmenu, anchorType, highlightImmediately) {
  27829. var anchorSpec = getAnchorSpec(editor, e, anchorType);
  27830. build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, true).map(function(menuData) {
  27831. e.preventDefault();
  27832. InlineView.showMenuWithinBounds(contextmenu, { anchor: anchorSpec }, {
  27833. menu: {
  27834. markers: markers("normal"),
  27835. highlightImmediately
  27836. },
  27837. data: menuData,
  27838. type: "horizontal"
  27839. }, function() {
  27840. return Optional.some(getContextToolbarBounds(editor, backstage.shared, anchorType === "node" ? "node" : "selection"));
  27841. });
  27842. editor.fire(hideContextToolbarEvent);
  27843. });
  27844. };
  27845. var initAndShow = function(editor, e, buildMenu, backstage, contextmenu, anchorType) {
  27846. var detection2 = detect$1();
  27847. var isiOS = detection2.os.isiOS();
  27848. var isOSX = detection2.os.isOSX();
  27849. var isAndroid = detection2.os.isAndroid();
  27850. var isTouch2 = detection2.deviceType.isTouch();
  27851. var shouldHighlightImmediately = function() {
  27852. return !(isAndroid || isiOS || isOSX && isTouch2);
  27853. };
  27854. var open2 = function() {
  27855. var items = buildMenu();
  27856. show(editor, e, items, backstage, contextmenu, anchorType, shouldHighlightImmediately());
  27857. };
  27858. if ((isOSX || isiOS) && anchorType !== "node") {
  27859. var openiOS_1 = function() {
  27860. setupiOSOverrides(editor);
  27861. open2();
  27862. };
  27863. if (isTouchWithinSelection(editor, e)) {
  27864. openiOS_1();
  27865. } else {
  27866. editor.once("selectionchange", openiOS_1);
  27867. editor.once("touchend", function() {
  27868. return editor.off("selectionchange", openiOS_1);
  27869. });
  27870. }
  27871. } else {
  27872. open2();
  27873. }
  27874. };
  27875. var patchPipeConfig = function(config2) {
  27876. return typeof config2 === "string" ? config2.split(/[ ,]/) : config2;
  27877. };
  27878. var shouldNeverUseNative = function(editor) {
  27879. return editor.getParam("contextmenu_never_use_native", false, "boolean");
  27880. };
  27881. var getMenuItems = function(editor, name2, defaultItems) {
  27882. var contextMenus = editor.ui.registry.getAll().contextMenus;
  27883. return Optional.from(editor.getParam(name2)).map(patchPipeConfig).getOrThunk(function() {
  27884. return filter$2(patchPipeConfig(defaultItems), function(item2) {
  27885. return has$2(contextMenus, item2);
  27886. });
  27887. });
  27888. };
  27889. var isContextMenuDisabled = function(editor) {
  27890. return editor.getParam("contextmenu") === false;
  27891. };
  27892. var getContextMenu = function(editor) {
  27893. return getMenuItems(editor, "contextmenu", "link linkchecker image imagetools table spellchecker configurepermanentpen");
  27894. };
  27895. var getAvoidOverlapSelector = function(editor) {
  27896. return editor.getParam("contextmenu_avoid_overlap", "", "string");
  27897. };
  27898. var isSeparator = function(item2) {
  27899. return isString(item2) ? item2 === "|" : item2.type === "separator";
  27900. };
  27901. var separator = { type: "separator" };
  27902. var makeContextItem = function(item2) {
  27903. var commonMenuItem = function(item3) {
  27904. return {
  27905. text: item3.text,
  27906. icon: item3.icon,
  27907. disabled: item3.disabled,
  27908. shortcut: item3.shortcut
  27909. };
  27910. };
  27911. if (isString(item2)) {
  27912. return item2;
  27913. } else {
  27914. switch (item2.type) {
  27915. case "separator":
  27916. return separator;
  27917. case "submenu":
  27918. return __assign(__assign({ type: "nestedmenuitem" }, commonMenuItem(item2)), {
  27919. getSubmenuItems: function() {
  27920. var items = item2.getSubmenuItems();
  27921. if (isString(items)) {
  27922. return items;
  27923. } else {
  27924. return map$2(items, makeContextItem);
  27925. }
  27926. }
  27927. });
  27928. default:
  27929. return __assign(__assign({ type: "menuitem" }, commonMenuItem(item2)), { onAction: noarg(item2.onAction) });
  27930. }
  27931. }
  27932. };
  27933. var addContextMenuGroup = function(xs, groupItems) {
  27934. if (groupItems.length === 0) {
  27935. return xs;
  27936. }
  27937. var lastMenuItem = last$2(xs).filter(function(item2) {
  27938. return !isSeparator(item2);
  27939. });
  27940. var before2 = lastMenuItem.fold(function() {
  27941. return [];
  27942. }, function(_) {
  27943. return [separator];
  27944. });
  27945. return xs.concat(before2).concat(groupItems).concat([separator]);
  27946. };
  27947. var generateContextMenu = function(contextMenus, menuConfig, selectedElement) {
  27948. var sections = foldl(menuConfig, function(acc, name2) {
  27949. return get$e(contextMenus, name2.toLowerCase()).map(function(menu2) {
  27950. var items = menu2.update(selectedElement);
  27951. if (isString(items)) {
  27952. return addContextMenuGroup(acc, items.split(" "));
  27953. } else if (items.length > 0) {
  27954. var allItems = map$2(items, makeContextItem);
  27955. return addContextMenuGroup(acc, allItems);
  27956. } else {
  27957. return acc;
  27958. }
  27959. }).getOrThunk(function() {
  27960. return acc.concat([name2]);
  27961. });
  27962. }, []);
  27963. if (sections.length > 0 && isSeparator(sections[sections.length - 1])) {
  27964. sections.pop();
  27965. }
  27966. return sections;
  27967. };
  27968. var isNativeOverrideKeyEvent = function(editor, e) {
  27969. return e.ctrlKey && !shouldNeverUseNative(editor);
  27970. };
  27971. var isTriggeredByKeyboard = function(editor, e) {
  27972. return e.type !== "longpress" && (e.button !== 2 || e.target === editor.getBody() && e.pointerType === "");
  27973. };
  27974. var getSelectedElement = function(editor, e) {
  27975. return isTriggeredByKeyboard(editor, e) ? editor.selection.getStart(true) : e.target;
  27976. };
  27977. var getAnchorType = function(editor, e) {
  27978. var selector = getAvoidOverlapSelector(editor);
  27979. var anchorType = isTriggeredByKeyboard(editor, e) ? "selection" : "point";
  27980. if (isNotEmpty(selector)) {
  27981. var target = getSelectedElement(editor, e);
  27982. var selectorExists = closest(SugarElement.fromDom(target), selector);
  27983. return selectorExists ? "node" : anchorType;
  27984. } else {
  27985. return anchorType;
  27986. }
  27987. };
  27988. var setup$5 = function(editor, lazySink, backstage) {
  27989. var detection2 = detect$1();
  27990. var isTouch2 = detection2.deviceType.isTouch;
  27991. var contextmenu = build$1(InlineView.sketch({
  27992. dom: { tag: "div" },
  27993. lazySink,
  27994. onEscape: function() {
  27995. return editor.focus();
  27996. },
  27997. onShow: function() {
  27998. return backstage.setContextMenuState(true);
  27999. },
  28000. onHide: function() {
  28001. return backstage.setContextMenuState(false);
  28002. },
  28003. fireDismissalEventInstead: {},
  28004. inlineBehaviours: derive$1([config("dismissContextMenu", [run$1(dismissRequested(), function(comp, _se) {
  28005. Sandboxing.close(comp);
  28006. editor.focus();
  28007. })])])
  28008. }));
  28009. var hideContextMenu = function(_e) {
  28010. return InlineView.hide(contextmenu);
  28011. };
  28012. var showContextMenu = function(e) {
  28013. if (shouldNeverUseNative(editor)) {
  28014. e.preventDefault();
  28015. }
  28016. if (isNativeOverrideKeyEvent(editor, e) || isContextMenuDisabled(editor)) {
  28017. return;
  28018. }
  28019. var anchorType = getAnchorType(editor, e);
  28020. var buildMenu = function() {
  28021. var selectedElement = getSelectedElement(editor, e);
  28022. var registry = editor.ui.registry.getAll();
  28023. var menuConfig = getContextMenu(editor);
  28024. return generateContextMenu(registry.contextMenus, menuConfig, selectedElement);
  28025. };
  28026. var initAndShow$2 = isTouch2() ? initAndShow : initAndShow$1;
  28027. initAndShow$2(editor, e, buildMenu, backstage, contextmenu, anchorType);
  28028. };
  28029. editor.on("init", function() {
  28030. var hideEvents = "ResizeEditor ScrollContent ScrollWindow longpresscancel" + (isTouch2() ? "" : " ResizeWindow");
  28031. editor.on(hideEvents, hideContextMenu);
  28032. editor.on("longpress contextmenu", showContextMenu);
  28033. });
  28034. };
  28035. var adt = Adt.generate([
  28036. {
  28037. offset: [
  28038. "x",
  28039. "y"
  28040. ]
  28041. },
  28042. {
  28043. absolute: [
  28044. "x",
  28045. "y"
  28046. ]
  28047. },
  28048. {
  28049. fixed: [
  28050. "x",
  28051. "y"
  28052. ]
  28053. }
  28054. ]);
  28055. var subtract = function(change2) {
  28056. return function(point2) {
  28057. return point2.translate(-change2.left, -change2.top);
  28058. };
  28059. };
  28060. var add = function(change2) {
  28061. return function(point2) {
  28062. return point2.translate(change2.left, change2.top);
  28063. };
  28064. };
  28065. var transform = function(changes) {
  28066. return function(x, y) {
  28067. return foldl(changes, function(rest, f) {
  28068. return f(rest);
  28069. }, SugarPosition(x, y));
  28070. };
  28071. };
  28072. var asFixed = function(coord, scroll, origin) {
  28073. return coord.fold(transform([
  28074. add(origin),
  28075. subtract(scroll)
  28076. ]), transform([subtract(scroll)]), transform([]));
  28077. };
  28078. var asAbsolute = function(coord, scroll, origin) {
  28079. return coord.fold(transform([add(origin)]), transform([]), transform([add(scroll)]));
  28080. };
  28081. var asOffset = function(coord, scroll, origin) {
  28082. return coord.fold(transform([]), transform([subtract(origin)]), transform([
  28083. add(scroll),
  28084. subtract(origin)
  28085. ]));
  28086. };
  28087. var withinRange = function(coord1, coord2, xRange2, yRange2, scroll, origin) {
  28088. var a1 = asAbsolute(coord1, scroll, origin);
  28089. var a2 = asAbsolute(coord2, scroll, origin);
  28090. return Math.abs(a1.left - a2.left) <= xRange2 && Math.abs(a1.top - a2.top) <= yRange2;
  28091. };
  28092. var getDeltas = function(coord1, coord2, xRange2, yRange2, scroll, origin) {
  28093. var a1 = asAbsolute(coord1, scroll, origin);
  28094. var a2 = asAbsolute(coord2, scroll, origin);
  28095. var left2 = Math.abs(a1.left - a2.left);
  28096. var top2 = Math.abs(a1.top - a2.top);
  28097. return SugarPosition(left2, top2);
  28098. };
  28099. var toStyles = function(coord, scroll, origin) {
  28100. var stylesOpt = coord.fold(function(x, y) {
  28101. return {
  28102. position: Optional.some("absolute"),
  28103. left: Optional.some(x + "px"),
  28104. top: Optional.some(y + "px")
  28105. };
  28106. }, function(x, y) {
  28107. return {
  28108. position: Optional.some("absolute"),
  28109. left: Optional.some(x - origin.left + "px"),
  28110. top: Optional.some(y - origin.top + "px")
  28111. };
  28112. }, function(x, y) {
  28113. return {
  28114. position: Optional.some("fixed"),
  28115. left: Optional.some(x + "px"),
  28116. top: Optional.some(y + "px")
  28117. };
  28118. });
  28119. return __assign({
  28120. right: Optional.none(),
  28121. bottom: Optional.none()
  28122. }, stylesOpt);
  28123. };
  28124. var translate = function(coord, deltaX, deltaY) {
  28125. return coord.fold(function(x, y) {
  28126. return offset(x + deltaX, y + deltaY);
  28127. }, function(x, y) {
  28128. return absolute(x + deltaX, y + deltaY);
  28129. }, function(x, y) {
  28130. return fixed(x + deltaX, y + deltaY);
  28131. });
  28132. };
  28133. var absorb = function(partialCoord, originalCoord, scroll, origin) {
  28134. var absorbOne = function(stencil, nu2) {
  28135. return function(optX, optY) {
  28136. var original2 = stencil(originalCoord, scroll, origin);
  28137. return nu2(optX.getOr(original2.left), optY.getOr(original2.top));
  28138. };
  28139. };
  28140. return partialCoord.fold(absorbOne(asOffset, offset), absorbOne(asAbsolute, absolute), absorbOne(asFixed, fixed));
  28141. };
  28142. var offset = adt.offset;
  28143. var absolute = adt.absolute;
  28144. var fixed = adt.fixed;
  28145. var parseAttrToInt = function(element2, name2) {
  28146. var value2 = get$d(element2, name2);
  28147. return isUndefined(value2) ? NaN : parseInt(value2, 10);
  28148. };
  28149. var get = function(component, snapsInfo) {
  28150. var element2 = component.element;
  28151. var x = parseAttrToInt(element2, snapsInfo.leftAttr);
  28152. var y = parseAttrToInt(element2, snapsInfo.topAttr);
  28153. return isNaN(x) || isNaN(y) ? Optional.none() : Optional.some(SugarPosition(x, y));
  28154. };
  28155. var set = function(component, snapsInfo, pt) {
  28156. var element2 = component.element;
  28157. set$8(element2, snapsInfo.leftAttr, pt.left + "px");
  28158. set$8(element2, snapsInfo.topAttr, pt.top + "px");
  28159. };
  28160. var clear = function(component, snapsInfo) {
  28161. var element2 = component.element;
  28162. remove$7(element2, snapsInfo.leftAttr);
  28163. remove$7(element2, snapsInfo.topAttr);
  28164. };
  28165. var getCoords = function(component, snapInfo, coord, delta) {
  28166. return get(component, snapInfo).fold(function() {
  28167. return coord;
  28168. }, function(fixed$12) {
  28169. return fixed(fixed$12.left + delta.left, fixed$12.top + delta.top);
  28170. });
  28171. };
  28172. var moveOrSnap = function(component, snapInfo, coord, delta, scroll, origin) {
  28173. var newCoord = getCoords(component, snapInfo, coord, delta);
  28174. var snap2 = snapInfo.mustSnap ? findClosestSnap(component, snapInfo, newCoord, scroll, origin) : findSnap(component, snapInfo, newCoord, scroll, origin);
  28175. var fixedCoord = asFixed(newCoord, scroll, origin);
  28176. set(component, snapInfo, fixedCoord);
  28177. return snap2.fold(function() {
  28178. return {
  28179. coord: fixed(fixedCoord.left, fixedCoord.top),
  28180. extra: Optional.none()
  28181. };
  28182. }, function(spanned) {
  28183. return {
  28184. coord: spanned.output,
  28185. extra: spanned.extra
  28186. };
  28187. });
  28188. };
  28189. var stopDrag = function(component, snapInfo) {
  28190. clear(component, snapInfo);
  28191. };
  28192. var findMatchingSnap = function(snaps, newCoord, scroll, origin) {
  28193. return findMap(snaps, function(snap2) {
  28194. var sensor = snap2.sensor;
  28195. var inRange = withinRange(newCoord, sensor, snap2.range.left, snap2.range.top, scroll, origin);
  28196. return inRange ? Optional.some({
  28197. output: absorb(snap2.output, newCoord, scroll, origin),
  28198. extra: snap2.extra
  28199. }) : Optional.none();
  28200. });
  28201. };
  28202. var findClosestSnap = function(component, snapInfo, newCoord, scroll, origin) {
  28203. var snaps = snapInfo.getSnapPoints(component);
  28204. var matchSnap = findMatchingSnap(snaps, newCoord, scroll, origin);
  28205. return matchSnap.orThunk(function() {
  28206. var bestSnap = foldl(snaps, function(acc, snap2) {
  28207. var sensor = snap2.sensor;
  28208. var deltas = getDeltas(newCoord, sensor, snap2.range.left, snap2.range.top, scroll, origin);
  28209. return acc.deltas.fold(function() {
  28210. return {
  28211. deltas: Optional.some(deltas),
  28212. snap: Optional.some(snap2)
  28213. };
  28214. }, function(bestDeltas) {
  28215. var currAvg = (deltas.left + deltas.top) / 2;
  28216. var bestAvg = (bestDeltas.left + bestDeltas.top) / 2;
  28217. if (currAvg <= bestAvg) {
  28218. return {
  28219. deltas: Optional.some(deltas),
  28220. snap: Optional.some(snap2)
  28221. };
  28222. } else {
  28223. return acc;
  28224. }
  28225. });
  28226. }, {
  28227. deltas: Optional.none(),
  28228. snap: Optional.none()
  28229. });
  28230. return bestSnap.snap.map(function(snap2) {
  28231. return {
  28232. output: absorb(snap2.output, newCoord, scroll, origin),
  28233. extra: snap2.extra
  28234. };
  28235. });
  28236. });
  28237. };
  28238. var findSnap = function(component, snapInfo, newCoord, scroll, origin) {
  28239. var snaps = snapInfo.getSnapPoints(component);
  28240. return findMatchingSnap(snaps, newCoord, scroll, origin);
  28241. };
  28242. var snapTo$1 = function(snap2, scroll, origin) {
  28243. return {
  28244. coord: absorb(snap2.output, snap2.output, scroll, origin),
  28245. extra: snap2.extra
  28246. };
  28247. };
  28248. var snapTo = function(component, dragConfig, _state, snap2) {
  28249. var target = dragConfig.getTarget(component.element);
  28250. if (dragConfig.repositionTarget) {
  28251. var doc = owner$4(component.element);
  28252. var scroll_1 = get$9(doc);
  28253. var origin_1 = getOrigin(target);
  28254. var snapPin = snapTo$1(snap2, scroll_1, origin_1);
  28255. var styles = toStyles(snapPin.coord, scroll_1, origin_1);
  28256. setOptions(target, styles);
  28257. }
  28258. };
  28259. var DraggingApis = Object.freeze({
  28260. __proto__: null,
  28261. snapTo
  28262. });
  28263. var initialAttribute = "data-initial-z-index";
  28264. var resetZIndex = function(blocker) {
  28265. parent(blocker.element).filter(isElement$2).each(function(root) {
  28266. getOpt(root, initialAttribute).fold(function() {
  28267. return remove$6(root, "z-index");
  28268. }, function(zIndex) {
  28269. return set$7(root, "z-index", zIndex);
  28270. });
  28271. remove$7(root, initialAttribute);
  28272. });
  28273. };
  28274. var changeZIndex = function(blocker) {
  28275. parent(blocker.element).filter(isElement$2).each(function(root) {
  28276. getRaw(root, "z-index").each(function(zindex) {
  28277. set$8(root, initialAttribute, zindex);
  28278. });
  28279. set$7(root, "z-index", get$c(blocker.element, "z-index"));
  28280. });
  28281. };
  28282. var instigate = function(anyComponent, blocker) {
  28283. anyComponent.getSystem().addToGui(blocker);
  28284. changeZIndex(blocker);
  28285. };
  28286. var discard = function(blocker) {
  28287. resetZIndex(blocker);
  28288. blocker.getSystem().removeFromGui(blocker);
  28289. };
  28290. var createComponent = function(component, blockerClass, blockerEvents) {
  28291. return component.getSystem().build(Container.sketch({
  28292. dom: {
  28293. styles: {
  28294. "left": "0px",
  28295. "top": "0px",
  28296. "width": "100%",
  28297. "height": "100%",
  28298. "position": "fixed",
  28299. "z-index": "1000000000000000"
  28300. },
  28301. classes: [blockerClass]
  28302. },
  28303. events: blockerEvents
  28304. }));
  28305. };
  28306. var SnapSchema = optionObjOf("snaps", [
  28307. required$1("getSnapPoints"),
  28308. onHandler("onSensor"),
  28309. required$1("leftAttr"),
  28310. required$1("topAttr"),
  28311. defaulted("lazyViewport", win),
  28312. defaulted("mustSnap", false)
  28313. ]);
  28314. var schema$6 = [
  28315. defaulted("useFixed", never),
  28316. required$1("blockerClass"),
  28317. defaulted("getTarget", identity$1),
  28318. defaulted("onDrag", noop),
  28319. defaulted("repositionTarget", true),
  28320. defaulted("onDrop", noop),
  28321. defaultedFunction("getBounds", win),
  28322. SnapSchema
  28323. ];
  28324. var getCurrentCoord = function(target) {
  28325. return lift3(getRaw(target, "left"), getRaw(target, "top"), getRaw(target, "position"), function(left2, top2, position2) {
  28326. var nu2 = position2 === "fixed" ? fixed : offset;
  28327. return nu2(parseInt(left2, 10), parseInt(top2, 10));
  28328. }).getOrThunk(function() {
  28329. var location = absolute$3(target);
  28330. return absolute(location.left, location.top);
  28331. });
  28332. };
  28333. var clampCoords = function(component, coords, scroll, origin, startData) {
  28334. var bounds2 = startData.bounds;
  28335. var absoluteCoord = asAbsolute(coords, scroll, origin);
  28336. var newX = clamp$1(absoluteCoord.left, bounds2.x, bounds2.x + bounds2.width - startData.width);
  28337. var newY = clamp$1(absoluteCoord.top, bounds2.y, bounds2.y + bounds2.height - startData.height);
  28338. var newCoords = absolute(newX, newY);
  28339. return coords.fold(function() {
  28340. var offset$1 = asOffset(newCoords, scroll, origin);
  28341. return offset(offset$1.left, offset$1.top);
  28342. }, constant$1(newCoords), function() {
  28343. var fixed$12 = asFixed(newCoords, scroll, origin);
  28344. return fixed(fixed$12.left, fixed$12.top);
  28345. });
  28346. };
  28347. var calcNewCoord = function(component, optSnaps, currentCoord, scroll, origin, delta, startData) {
  28348. var newCoord = optSnaps.fold(function() {
  28349. var translated = translate(currentCoord, delta.left, delta.top);
  28350. var fixedCoord = asFixed(translated, scroll, origin);
  28351. return fixed(fixedCoord.left, fixedCoord.top);
  28352. }, function(snapInfo) {
  28353. var snapping = moveOrSnap(component, snapInfo, currentCoord, delta, scroll, origin);
  28354. snapping.extra.each(function(extra) {
  28355. snapInfo.onSensor(component, extra);
  28356. });
  28357. return snapping.coord;
  28358. });
  28359. return clampCoords(component, newCoord, scroll, origin, startData);
  28360. };
  28361. var dragBy = function(component, dragConfig, startData, delta) {
  28362. var target = dragConfig.getTarget(component.element);
  28363. if (dragConfig.repositionTarget) {
  28364. var doc = owner$4(component.element);
  28365. var scroll_1 = get$9(doc);
  28366. var origin_1 = getOrigin(target);
  28367. var currentCoord = getCurrentCoord(target);
  28368. var newCoord = calcNewCoord(component, dragConfig.snaps, currentCoord, scroll_1, origin_1, delta, startData);
  28369. var styles = toStyles(newCoord, scroll_1, origin_1);
  28370. setOptions(target, styles);
  28371. }
  28372. dragConfig.onDrag(component, target, delta);
  28373. };
  28374. var calcStartData = function(dragConfig, comp) {
  28375. return {
  28376. bounds: dragConfig.getBounds(),
  28377. height: getOuter$2(comp.element),
  28378. width: getOuter$1(comp.element)
  28379. };
  28380. };
  28381. var move = function(component, dragConfig, dragState, dragMode, event) {
  28382. var delta = dragState.update(dragMode, event);
  28383. var dragStartData = dragState.getStartData().getOrThunk(function() {
  28384. return calcStartData(dragConfig, component);
  28385. });
  28386. delta.each(function(dlt) {
  28387. dragBy(component, dragConfig, dragStartData, dlt);
  28388. });
  28389. };
  28390. var stop = function(component, blocker, dragConfig, dragState) {
  28391. blocker.each(discard);
  28392. dragConfig.snaps.each(function(snapInfo) {
  28393. stopDrag(component, snapInfo);
  28394. });
  28395. var target = dragConfig.getTarget(component.element);
  28396. dragState.reset();
  28397. dragConfig.onDrop(component, target);
  28398. };
  28399. var handlers = function(events2) {
  28400. return function(dragConfig, dragState) {
  28401. var updateStartState = function(comp) {
  28402. dragState.setStartData(calcStartData(dragConfig, comp));
  28403. };
  28404. return derive$2(__spreadArray([run$1(windowScroll(), function(comp) {
  28405. dragState.getStartData().each(function() {
  28406. return updateStartState(comp);
  28407. });
  28408. })], events2(dragConfig, dragState, updateStartState), true));
  28409. };
  28410. };
  28411. var init$2 = function(dragApi) {
  28412. return derive$2([
  28413. run$1(mousedown(), dragApi.forceDrop),
  28414. run$1(mouseup(), dragApi.drop),
  28415. run$1(mousemove(), function(comp, simulatedEvent) {
  28416. dragApi.move(simulatedEvent.event);
  28417. }),
  28418. run$1(mouseout(), dragApi.delayDrop)
  28419. ]);
  28420. };
  28421. var getData$1 = function(event) {
  28422. return Optional.from(SugarPosition(event.x, event.y));
  28423. };
  28424. var getDelta$1 = function(old, nu2) {
  28425. return SugarPosition(nu2.left - old.left, nu2.top - old.top);
  28426. };
  28427. var MouseData = Object.freeze({
  28428. __proto__: null,
  28429. getData: getData$1,
  28430. getDelta: getDelta$1
  28431. });
  28432. var events$2 = function(dragConfig, dragState, updateStartState) {
  28433. return [run$1(mousedown(), function(component, simulatedEvent) {
  28434. var raw = simulatedEvent.event.raw;
  28435. if (raw.button !== 0) {
  28436. return;
  28437. }
  28438. simulatedEvent.stop();
  28439. var stop$1 = function() {
  28440. return stop(component, Optional.some(blocker), dragConfig, dragState);
  28441. };
  28442. var delayDrop = DelayedFunction(stop$1, 200);
  28443. var dragApi = {
  28444. drop: stop$1,
  28445. delayDrop: delayDrop.schedule,
  28446. forceDrop: stop$1,
  28447. move: function(event) {
  28448. delayDrop.cancel();
  28449. move(component, dragConfig, dragState, MouseData, event);
  28450. }
  28451. };
  28452. var blocker = createComponent(component, dragConfig.blockerClass, init$2(dragApi));
  28453. var start = function() {
  28454. updateStartState(component);
  28455. instigate(component, blocker);
  28456. };
  28457. start();
  28458. })];
  28459. };
  28460. var schema$5 = __spreadArray(__spreadArray([], schema$6, true), [output$1("dragger", { handlers: handlers(events$2) })], false);
  28461. var init$1 = function(dragApi) {
  28462. return derive$2([
  28463. run$1(touchstart(), dragApi.forceDrop),
  28464. run$1(touchend(), dragApi.drop),
  28465. run$1(touchcancel(), dragApi.drop),
  28466. run$1(touchmove(), function(comp, simulatedEvent) {
  28467. dragApi.move(simulatedEvent.event);
  28468. })
  28469. ]);
  28470. };
  28471. var getDataFrom = function(touches) {
  28472. var touch2 = touches[0];
  28473. return Optional.some(SugarPosition(touch2.clientX, touch2.clientY));
  28474. };
  28475. var getData = function(event) {
  28476. var raw = event.raw;
  28477. var touches = raw.touches;
  28478. return touches.length === 1 ? getDataFrom(touches) : Optional.none();
  28479. };
  28480. var getDelta = function(old, nu2) {
  28481. return SugarPosition(nu2.left - old.left, nu2.top - old.top);
  28482. };
  28483. var TouchData = Object.freeze({
  28484. __proto__: null,
  28485. getData,
  28486. getDelta
  28487. });
  28488. var events$1 = function(dragConfig, dragState, updateStartState) {
  28489. var blockerSingleton = value$1();
  28490. var stopBlocking = function(component) {
  28491. stop(component, blockerSingleton.get(), dragConfig, dragState);
  28492. blockerSingleton.clear();
  28493. };
  28494. return [
  28495. run$1(touchstart(), function(component, simulatedEvent) {
  28496. simulatedEvent.stop();
  28497. var stop2 = function() {
  28498. return stopBlocking(component);
  28499. };
  28500. var dragApi = {
  28501. drop: stop2,
  28502. delayDrop: noop,
  28503. forceDrop: stop2,
  28504. move: function(event) {
  28505. move(component, dragConfig, dragState, TouchData, event);
  28506. }
  28507. };
  28508. var blocker = createComponent(component, dragConfig.blockerClass, init$1(dragApi));
  28509. blockerSingleton.set(blocker);
  28510. var start = function() {
  28511. updateStartState(component);
  28512. instigate(component, blocker);
  28513. };
  28514. start();
  28515. }),
  28516. run$1(touchmove(), function(component, simulatedEvent) {
  28517. simulatedEvent.stop();
  28518. move(component, dragConfig, dragState, TouchData, simulatedEvent.event);
  28519. }),
  28520. run$1(touchend(), function(component, simulatedEvent) {
  28521. simulatedEvent.stop();
  28522. stopBlocking(component);
  28523. }),
  28524. run$1(touchcancel(), stopBlocking)
  28525. ];
  28526. };
  28527. var schema$4 = __spreadArray(__spreadArray([], schema$6, true), [output$1("dragger", { handlers: handlers(events$1) })], false);
  28528. var events = function(dragConfig, dragState, updateStartState) {
  28529. return __spreadArray(__spreadArray([], events$2(dragConfig, dragState, updateStartState), true), events$1(dragConfig, dragState, updateStartState), true);
  28530. };
  28531. var schema$3 = __spreadArray(__spreadArray([], schema$6, true), [output$1("dragger", { handlers: handlers(events) })], false);
  28532. var mouse = schema$5;
  28533. var touch = schema$4;
  28534. var mouseOrTouch = schema$3;
  28535. var DraggingBranches = Object.freeze({
  28536. __proto__: null,
  28537. mouse,
  28538. touch,
  28539. mouseOrTouch
  28540. });
  28541. var init = function() {
  28542. var previous = Optional.none();
  28543. var startData = Optional.none();
  28544. var reset2 = function() {
  28545. previous = Optional.none();
  28546. startData = Optional.none();
  28547. };
  28548. var calculateDelta = function(mode, nu2) {
  28549. var result = previous.map(function(old) {
  28550. return mode.getDelta(old, nu2);
  28551. });
  28552. previous = Optional.some(nu2);
  28553. return result;
  28554. };
  28555. var update = function(mode, dragEvent) {
  28556. return mode.getData(dragEvent).bind(function(nuData) {
  28557. return calculateDelta(mode, nuData);
  28558. });
  28559. };
  28560. var setStartData = function(data) {
  28561. startData = Optional.some(data);
  28562. };
  28563. var getStartData = function() {
  28564. return startData;
  28565. };
  28566. var readState = constant$1({});
  28567. return nu$8({
  28568. readState,
  28569. reset: reset2,
  28570. update,
  28571. getStartData,
  28572. setStartData
  28573. });
  28574. };
  28575. var DragState = Object.freeze({
  28576. __proto__: null,
  28577. init
  28578. });
  28579. var Dragging = createModes({
  28580. branchKey: "mode",
  28581. branches: DraggingBranches,
  28582. name: "dragging",
  28583. active: {
  28584. events: function(dragConfig, dragState) {
  28585. var dragger = dragConfig.dragger;
  28586. return dragger.handlers(dragConfig, dragState);
  28587. }
  28588. },
  28589. extra: {
  28590. snap: function(sConfig) {
  28591. return {
  28592. sensor: sConfig.sensor,
  28593. range: sConfig.range,
  28594. output: sConfig.output,
  28595. extra: Optional.from(sConfig.extra)
  28596. };
  28597. }
  28598. },
  28599. state: DragState,
  28600. apis: DraggingApis
  28601. });
  28602. var snapWidth = 40;
  28603. var snapOffset = snapWidth / 2;
  28604. var calcSnap = function(selectorOpt, td, x, y, width2, height2) {
  28605. return selectorOpt.fold(function() {
  28606. return Dragging.snap({
  28607. sensor: absolute(x - snapOffset, y - snapOffset),
  28608. range: SugarPosition(width2, height2),
  28609. output: absolute(Optional.some(x), Optional.some(y)),
  28610. extra: { td }
  28611. });
  28612. }, function(selectorHandle) {
  28613. var sensorLeft = x - snapOffset;
  28614. var sensorTop = y - snapOffset;
  28615. var sensorWidth = snapWidth;
  28616. var sensorHeight = snapWidth;
  28617. var rect2 = selectorHandle.element.dom.getBoundingClientRect();
  28618. return Dragging.snap({
  28619. sensor: absolute(sensorLeft, sensorTop),
  28620. range: SugarPosition(sensorWidth, sensorHeight),
  28621. output: absolute(Optional.some(x - rect2.width / 2), Optional.some(y - rect2.height / 2)),
  28622. extra: { td }
  28623. });
  28624. });
  28625. };
  28626. var getSnapsConfig = function(getSnapPoints, cell, onChange) {
  28627. var isSameCell = function(cellOpt, td) {
  28628. return cellOpt.exists(function(currentTd) {
  28629. return eq(currentTd, td);
  28630. });
  28631. };
  28632. return {
  28633. getSnapPoints,
  28634. leftAttr: "data-drag-left",
  28635. topAttr: "data-drag-top",
  28636. onSensor: function(component, extra) {
  28637. var td = extra.td;
  28638. if (!isSameCell(cell.get(), td)) {
  28639. cell.set(td);
  28640. onChange(td);
  28641. }
  28642. },
  28643. mustSnap: true
  28644. };
  28645. };
  28646. var createSelector = function(snaps) {
  28647. return record(Button.sketch({
  28648. dom: {
  28649. tag: "div",
  28650. classes: ["tox-selector"]
  28651. },
  28652. buttonBehaviours: derive$1([
  28653. Dragging.config({
  28654. mode: "mouseOrTouch",
  28655. blockerClass: "blocker",
  28656. snaps
  28657. }),
  28658. Unselecting.config({})
  28659. ]),
  28660. eventOrder: {
  28661. mousedown: [
  28662. "dragging",
  28663. "alloy.base.behaviour"
  28664. ],
  28665. touchstart: [
  28666. "dragging",
  28667. "alloy.base.behaviour"
  28668. ]
  28669. }
  28670. }));
  28671. };
  28672. var setup$4 = function(editor, sink) {
  28673. var tlTds = Cell([]);
  28674. var brTds = Cell([]);
  28675. var isVisible2 = Cell(false);
  28676. var startCell = value$1();
  28677. var finishCell = value$1();
  28678. var getTopLeftSnap = function(td) {
  28679. var box2 = absolute$2(td);
  28680. return calcSnap(memTopLeft.getOpt(sink), td, box2.x, box2.y, box2.width, box2.height);
  28681. };
  28682. var getTopLeftSnaps = function() {
  28683. return map$2(tlTds.get(), function(td) {
  28684. return getTopLeftSnap(td);
  28685. });
  28686. };
  28687. var getBottomRightSnap = function(td) {
  28688. var box2 = absolute$2(td);
  28689. return calcSnap(memBottomRight.getOpt(sink), td, box2.right, box2.bottom, box2.width, box2.height);
  28690. };
  28691. var getBottomRightSnaps = function() {
  28692. return map$2(brTds.get(), function(td) {
  28693. return getBottomRightSnap(td);
  28694. });
  28695. };
  28696. var topLeftSnaps = getSnapsConfig(getTopLeftSnaps, startCell, function(start) {
  28697. finishCell.get().each(function(finish) {
  28698. editor.fire("TableSelectorChange", {
  28699. start,
  28700. finish
  28701. });
  28702. });
  28703. });
  28704. var bottomRightSnaps = getSnapsConfig(getBottomRightSnaps, finishCell, function(finish) {
  28705. startCell.get().each(function(start) {
  28706. editor.fire("TableSelectorChange", {
  28707. start,
  28708. finish
  28709. });
  28710. });
  28711. });
  28712. var memTopLeft = createSelector(topLeftSnaps);
  28713. var memBottomRight = createSelector(bottomRightSnaps);
  28714. var topLeft = build$1(memTopLeft.asSpec());
  28715. var bottomRight = build$1(memBottomRight.asSpec());
  28716. var showOrHideHandle = function(selector, cell, isAbove, isBelow) {
  28717. var cellRect = cell.dom.getBoundingClientRect();
  28718. remove$6(selector.element, "display");
  28719. var viewportHeight = defaultView(SugarElement.fromDom(editor.getBody())).dom.innerHeight;
  28720. var aboveViewport = isAbove(cellRect);
  28721. var belowViewport = isBelow(cellRect, viewportHeight);
  28722. if (aboveViewport || belowViewport) {
  28723. set$7(selector.element, "display", "none");
  28724. }
  28725. };
  28726. var snapTo2 = function(selector, cell, getSnapConfig, pos) {
  28727. var snap2 = getSnapConfig(cell);
  28728. Dragging.snapTo(selector, snap2);
  28729. var isAbove = function(rect2) {
  28730. return rect2[pos] < 0;
  28731. };
  28732. var isBelow = function(rect2, viewportHeight) {
  28733. return rect2[pos] > viewportHeight;
  28734. };
  28735. showOrHideHandle(selector, cell, isAbove, isBelow);
  28736. };
  28737. var snapTopLeft = function(cell) {
  28738. return snapTo2(topLeft, cell, getTopLeftSnap, "top");
  28739. };
  28740. var snapLastTopLeft = function() {
  28741. return startCell.get().each(snapTopLeft);
  28742. };
  28743. var snapBottomRight = function(cell) {
  28744. return snapTo2(bottomRight, cell, getBottomRightSnap, "bottom");
  28745. };
  28746. var snapLastBottomRight = function() {
  28747. return finishCell.get().each(snapBottomRight);
  28748. };
  28749. if (detect$1().deviceType.isTouch()) {
  28750. editor.on("TableSelectionChange", function(e) {
  28751. if (!isVisible2.get()) {
  28752. attach(sink, topLeft);
  28753. attach(sink, bottomRight);
  28754. isVisible2.set(true);
  28755. }
  28756. startCell.set(e.start);
  28757. finishCell.set(e.finish);
  28758. e.otherCells.each(function(otherCells) {
  28759. tlTds.set(otherCells.upOrLeftCells);
  28760. brTds.set(otherCells.downOrRightCells);
  28761. snapTopLeft(e.start);
  28762. snapBottomRight(e.finish);
  28763. });
  28764. });
  28765. editor.on("ResizeEditor ResizeWindow ScrollContent", function() {
  28766. snapLastTopLeft();
  28767. snapLastBottomRight();
  28768. });
  28769. editor.on("TableSelectionClear", function() {
  28770. if (isVisible2.get()) {
  28771. detach(topLeft);
  28772. detach(bottomRight);
  28773. isVisible2.set(false);
  28774. }
  28775. startCell.clear();
  28776. finishCell.clear();
  28777. });
  28778. }
  28779. };
  28780. var isHidden = function(elm) {
  28781. if (elm.nodeType === 1) {
  28782. if (elm.nodeName === "BR" || !!elm.getAttribute("data-mce-bogus")) {
  28783. return true;
  28784. }
  28785. if (elm.getAttribute("data-mce-type") === "bookmark") {
  28786. return true;
  28787. }
  28788. }
  28789. return false;
  28790. };
  28791. var renderElementPath = function(editor, settings, providersBackstage) {
  28792. if (!settings.delimiter) {
  28793. settings.delimiter = "\xBB";
  28794. }
  28795. var getDataPath = function(data) {
  28796. var parts2 = data || [];
  28797. var newPathElements = map$2(parts2, function(part2, index) {
  28798. return Button.sketch({
  28799. dom: {
  28800. tag: "div",
  28801. classes: ["tox-statusbar__path-item"],
  28802. attributes: {
  28803. "role": "button",
  28804. "data-index": index,
  28805. "tab-index": -1,
  28806. "aria-level": index + 1
  28807. },
  28808. innerHtml: part2.name
  28809. },
  28810. action: function(_btn) {
  28811. editor.focus();
  28812. editor.selection.select(part2.element);
  28813. editor.nodeChanged();
  28814. },
  28815. buttonBehaviours: derive$1([
  28816. DisablingConfigs.button(providersBackstage.isDisabled),
  28817. receivingConfig()
  28818. ])
  28819. });
  28820. });
  28821. var divider = {
  28822. dom: {
  28823. tag: "div",
  28824. classes: ["tox-statusbar__path-divider"],
  28825. attributes: { "aria-hidden": true },
  28826. innerHtml: " " + settings.delimiter + " "
  28827. }
  28828. };
  28829. return foldl(newPathElements.slice(1), function(acc, element2) {
  28830. var newAcc = acc;
  28831. newAcc.push(divider);
  28832. newAcc.push(element2);
  28833. return newAcc;
  28834. }, [newPathElements[0]]);
  28835. };
  28836. var updatePath = function(parents) {
  28837. var newPath = [];
  28838. var i = parents.length;
  28839. while (i-- > 0) {
  28840. var parent_1 = parents[i];
  28841. if (parent_1.nodeType === 1 && !isHidden(parent_1)) {
  28842. var args = editor.fire("ResolveName", {
  28843. name: parent_1.nodeName.toLowerCase(),
  28844. target: parent_1
  28845. });
  28846. if (!args.isDefaultPrevented()) {
  28847. newPath.push({
  28848. name: args.name,
  28849. element: parent_1
  28850. });
  28851. }
  28852. if (args.isPropagationStopped()) {
  28853. break;
  28854. }
  28855. }
  28856. }
  28857. return newPath;
  28858. };
  28859. return {
  28860. dom: {
  28861. tag: "div",
  28862. classes: ["tox-statusbar__path"],
  28863. attributes: { role: "navigation" }
  28864. },
  28865. behaviours: derive$1([
  28866. Keying.config({
  28867. mode: "flow",
  28868. selector: "div[role=button]"
  28869. }),
  28870. Disabling.config({ disabled: providersBackstage.isDisabled }),
  28871. receivingConfig(),
  28872. Tabstopping.config({}),
  28873. Replacing.config({}),
  28874. config("elementPathEvents", [runOnAttached(function(comp, _e) {
  28875. editor.shortcuts.add("alt+F11", "focus statusbar elementpath", function() {
  28876. return Keying.focusIn(comp);
  28877. });
  28878. editor.on("NodeChange", function(e) {
  28879. var newPath = updatePath(e.parents);
  28880. if (newPath.length > 0) {
  28881. Replacing.set(comp, getDataPath(newPath));
  28882. } else {
  28883. Replacing.set(comp, []);
  28884. }
  28885. });
  28886. })])
  28887. ]),
  28888. components: []
  28889. };
  28890. };
  28891. var ResizeTypes;
  28892. (function(ResizeTypes2) {
  28893. ResizeTypes2[ResizeTypes2["None"] = 0] = "None";
  28894. ResizeTypes2[ResizeTypes2["Both"] = 1] = "Both";
  28895. ResizeTypes2[ResizeTypes2["Vertical"] = 2] = "Vertical";
  28896. })(ResizeTypes || (ResizeTypes = {}));
  28897. var getDimensions = function(editor, deltas, resizeType, originalHeight, originalWidth) {
  28898. var dimensions = {};
  28899. dimensions.height = calcCappedSize(originalHeight + deltas.top, getMinHeightSetting(editor), getMaxHeightSetting(editor));
  28900. if (resizeType === ResizeTypes.Both) {
  28901. dimensions.width = calcCappedSize(originalWidth + deltas.left, getMinWidthSetting(editor), getMaxWidthSetting(editor));
  28902. }
  28903. return dimensions;
  28904. };
  28905. var resize = function(editor, deltas, resizeType) {
  28906. var container = SugarElement.fromDom(editor.getContainer());
  28907. var dimensions = getDimensions(editor, deltas, resizeType, get$b(container), get$a(container));
  28908. each(dimensions, function(val, dim) {
  28909. return set$7(container, dim, numToPx(val));
  28910. });
  28911. fireResizeEditor(editor);
  28912. };
  28913. var getResizeType = function(editor) {
  28914. var fallback2 = !editor.hasPlugin("autoresize");
  28915. var resize2 = editor.getParam("resize", fallback2);
  28916. if (resize2 === false) {
  28917. return ResizeTypes.None;
  28918. } else if (resize2 === "both") {
  28919. return ResizeTypes.Both;
  28920. } else {
  28921. return ResizeTypes.Vertical;
  28922. }
  28923. };
  28924. var keyboardHandler = function(editor, resizeType, x, y) {
  28925. var scale2 = 20;
  28926. var delta = SugarPosition(x * scale2, y * scale2);
  28927. resize(editor, delta, resizeType);
  28928. return Optional.some(true);
  28929. };
  28930. var renderResizeHandler = function(editor, providersBackstage) {
  28931. var resizeType = getResizeType(editor);
  28932. if (resizeType === ResizeTypes.None) {
  28933. return Optional.none();
  28934. }
  28935. return Optional.some(render$3("resize-handle", {
  28936. tag: "div",
  28937. classes: ["tox-statusbar__resize-handle"],
  28938. attributes: { title: providersBackstage.translate("Resize") },
  28939. behaviours: [
  28940. Dragging.config({
  28941. mode: "mouse",
  28942. repositionTarget: false,
  28943. onDrag: function(_comp, _target, delta) {
  28944. return resize(editor, delta, resizeType);
  28945. },
  28946. blockerClass: "tox-blocker"
  28947. }),
  28948. Keying.config({
  28949. mode: "special",
  28950. onLeft: function() {
  28951. return keyboardHandler(editor, resizeType, -1, 0);
  28952. },
  28953. onRight: function() {
  28954. return keyboardHandler(editor, resizeType, 1, 0);
  28955. },
  28956. onUp: function() {
  28957. return keyboardHandler(editor, resizeType, 0, -1);
  28958. },
  28959. onDown: function() {
  28960. return keyboardHandler(editor, resizeType, 0, 1);
  28961. }
  28962. }),
  28963. Tabstopping.config({}),
  28964. Focusing.config({})
  28965. ]
  28966. }, providersBackstage.icons));
  28967. };
  28968. var renderWordCount = function(editor, providersBackstage) {
  28969. var _a2;
  28970. var replaceCountText = function(comp, count2, mode) {
  28971. return Replacing.set(comp, [text(providersBackstage.translate([
  28972. "{0} " + mode,
  28973. count2[mode]
  28974. ]))]);
  28975. };
  28976. return Button.sketch({
  28977. dom: {
  28978. tag: "button",
  28979. classes: ["tox-statusbar__wordcount"]
  28980. },
  28981. components: [],
  28982. buttonBehaviours: derive$1([
  28983. DisablingConfigs.button(providersBackstage.isDisabled),
  28984. receivingConfig(),
  28985. Tabstopping.config({}),
  28986. Replacing.config({}),
  28987. Representing.config({
  28988. store: {
  28989. mode: "memory",
  28990. initialValue: {
  28991. mode: "words",
  28992. count: {
  28993. words: 0,
  28994. characters: 0
  28995. }
  28996. }
  28997. }
  28998. }),
  28999. config("wordcount-events", [
  29000. runOnExecute$1(function(comp) {
  29001. var currentVal = Representing.getValue(comp);
  29002. var newMode = currentVal.mode === "words" ? "characters" : "words";
  29003. Representing.setValue(comp, {
  29004. mode: newMode,
  29005. count: currentVal.count
  29006. });
  29007. replaceCountText(comp, currentVal.count, newMode);
  29008. }),
  29009. runOnAttached(function(comp) {
  29010. editor.on("wordCountUpdate", function(e) {
  29011. var mode = Representing.getValue(comp).mode;
  29012. Representing.setValue(comp, {
  29013. mode,
  29014. count: e.wordCount
  29015. });
  29016. replaceCountText(comp, e.wordCount, mode);
  29017. });
  29018. })
  29019. ])
  29020. ]),
  29021. eventOrder: (_a2 = {}, _a2[execute$5()] = [
  29022. "disabling",
  29023. "alloy.base.behaviour",
  29024. "wordcount-events"
  29025. ], _a2)
  29026. });
  29027. };
  29028. var renderStatusbar = function(editor, providersBackstage) {
  29029. var renderBranding = function() {
  29030. var label = global$e.translate([
  29031. "Powered by {0}",
  29032. "Tiny"
  29033. ]);
  29034. var linkHtml = '<a href="https://www.tiny.cloud/?utm_campaign=editor_referral&amp;utm_medium=poweredby&amp;utm_source=tinymce&amp;utm_content=v5" rel="noopener" target="_blank" tabindex="-1" aria-label="' + label + '">' + label + "</a>";
  29035. return {
  29036. dom: {
  29037. tag: "span",
  29038. classes: ["tox-statusbar__branding"],
  29039. innerHtml: linkHtml
  29040. }
  29041. };
  29042. };
  29043. var getTextComponents = function() {
  29044. var components2 = [];
  29045. if (editor.getParam("elementpath", true, "boolean")) {
  29046. components2.push(renderElementPath(editor, {}, providersBackstage));
  29047. }
  29048. if (editor.hasPlugin("wordcount")) {
  29049. components2.push(renderWordCount(editor, providersBackstage));
  29050. }
  29051. if (editor.getParam("branding", true, "boolean")) {
  29052. components2.push(renderBranding());
  29053. }
  29054. if (components2.length > 0) {
  29055. return [{
  29056. dom: {
  29057. tag: "div",
  29058. classes: ["tox-statusbar__text-container"]
  29059. },
  29060. components: components2
  29061. }];
  29062. }
  29063. return [];
  29064. };
  29065. var getComponents = function() {
  29066. var components2 = getTextComponents();
  29067. var resizeHandler = renderResizeHandler(editor, providersBackstage);
  29068. return components2.concat(resizeHandler.toArray());
  29069. };
  29070. return {
  29071. dom: {
  29072. tag: "div",
  29073. classes: ["tox-statusbar"]
  29074. },
  29075. components: getComponents()
  29076. };
  29077. };
  29078. var setup$3 = function(editor) {
  29079. var _a2;
  29080. var isInline = editor.inline;
  29081. var mode = isInline ? Inline : Iframe;
  29082. var header = isStickyToolbar(editor) ? StickyHeader : StaticHeader;
  29083. var lazyOuterContainer = Optional.none();
  29084. var platform2 = detect$1();
  29085. var isIE = platform2.browser.isIE();
  29086. var platformClasses = isIE ? ["tox-platform-ie"] : [];
  29087. var isTouch2 = platform2.deviceType.isTouch();
  29088. var touchPlatformClass = "tox-platform-touch";
  29089. var deviceClasses = isTouch2 ? [touchPlatformClass] : [];
  29090. var isToolbarBottom = isToolbarLocationBottom(editor);
  29091. var uiContainer = getUiContainer(editor);
  29092. var dirAttributes = global$e.isRtl() ? { attributes: { dir: "rtl" } } : {};
  29093. var verticalDirAttributes = { attributes: (_a2 = {}, _a2[Attribute] = isToolbarBottom ? AttributeValue.BottomToTop : AttributeValue.TopToBottom, _a2) };
  29094. var lazyHeader = function() {
  29095. return lazyOuterContainer.bind(OuterContainer.getHeader);
  29096. };
  29097. var isHeaderDocked = function() {
  29098. return header.isDocked(lazyHeader);
  29099. };
  29100. var resizeUiMothership = function() {
  29101. set$7(uiMothership.element, "width", document.body.clientWidth + "px");
  29102. };
  29103. var makeSinkDefinition = function() {
  29104. var isGridUiContainer = eq(body(), uiContainer) && get$c(uiContainer, "display") === "grid";
  29105. var sinkSpec = {
  29106. dom: __assign({
  29107. tag: "div",
  29108. classes: [
  29109. "tox",
  29110. "tox-silver-sink",
  29111. "tox-tinymce-aux"
  29112. ].concat(platformClasses).concat(deviceClasses)
  29113. }, dirAttributes),
  29114. behaviours: derive$1([Positioning.config({
  29115. useFixed: function() {
  29116. return isHeaderDocked();
  29117. }
  29118. })])
  29119. };
  29120. var reactiveWidthSpec = {
  29121. dom: { styles: { width: document.body.clientWidth + "px" } },
  29122. events: derive$2([run$1(windowResize(), resizeUiMothership)])
  29123. };
  29124. return deepMerge(sinkSpec, isGridUiContainer ? reactiveWidthSpec : {});
  29125. };
  29126. var sink = build$1(makeSinkDefinition());
  29127. var lazySink = function() {
  29128. return Result.value(sink);
  29129. };
  29130. var memAnchorBar = record({
  29131. dom: {
  29132. tag: "div",
  29133. classes: ["tox-anchorbar"]
  29134. }
  29135. });
  29136. var lazyAnchorBar = function() {
  29137. return lazyOuterContainer.bind(function(container) {
  29138. return memAnchorBar.getOpt(container);
  29139. }).getOrDie("Could not find a anchor bar element");
  29140. };
  29141. var lazyToolbar = function() {
  29142. return lazyOuterContainer.bind(function(container) {
  29143. return OuterContainer.getToolbar(container);
  29144. }).getOrDie("Could not find more toolbar element");
  29145. };
  29146. var lazyThrobber = function() {
  29147. return lazyOuterContainer.bind(function(container) {
  29148. return OuterContainer.getThrobber(container);
  29149. }).getOrDie("Could not find throbber element");
  29150. };
  29151. var backstage = init$7(sink, editor, lazyAnchorBar);
  29152. var partMenubar2 = OuterContainer.parts.menubar({
  29153. dom: {
  29154. tag: "div",
  29155. classes: ["tox-menubar"]
  29156. },
  29157. backstage,
  29158. onEscape: function() {
  29159. editor.focus();
  29160. }
  29161. });
  29162. var toolbarMode = getToolbarMode(editor);
  29163. var partToolbar2 = OuterContainer.parts.toolbar(__assign({
  29164. dom: {
  29165. tag: "div",
  29166. classes: ["tox-toolbar"]
  29167. },
  29168. getSink: lazySink,
  29169. providers: backstage.shared.providers,
  29170. onEscape: function() {
  29171. editor.focus();
  29172. },
  29173. type: toolbarMode,
  29174. lazyToolbar,
  29175. lazyHeader: function() {
  29176. return lazyHeader().getOrDie("Could not find header element");
  29177. }
  29178. }, verticalDirAttributes));
  29179. var partMultipleToolbar2 = OuterContainer.parts["multiple-toolbar"]({
  29180. dom: {
  29181. tag: "div",
  29182. classes: ["tox-toolbar-overlord"]
  29183. },
  29184. providers: backstage.shared.providers,
  29185. onEscape: function() {
  29186. editor.focus();
  29187. },
  29188. type: toolbarMode
  29189. });
  29190. var partSocket2 = OuterContainer.parts.socket({
  29191. dom: {
  29192. tag: "div",
  29193. classes: ["tox-edit-area"]
  29194. }
  29195. });
  29196. var partSidebar2 = OuterContainer.parts.sidebar({
  29197. dom: {
  29198. tag: "div",
  29199. classes: ["tox-sidebar"]
  29200. }
  29201. });
  29202. var partThrobber2 = OuterContainer.parts.throbber({
  29203. dom: {
  29204. tag: "div",
  29205. classes: ["tox-throbber"]
  29206. },
  29207. backstage
  29208. });
  29209. var sb = editor.getParam("statusbar", true, "boolean");
  29210. var statusbar = sb && !isInline ? Optional.some(renderStatusbar(editor, backstage.shared.providers)) : Optional.none();
  29211. var socketSidebarContainer = {
  29212. dom: {
  29213. tag: "div",
  29214. classes: ["tox-sidebar-wrap"]
  29215. },
  29216. components: [
  29217. partSocket2,
  29218. partSidebar2
  29219. ]
  29220. };
  29221. var hasMultipleToolbar = isMultipleToolbars(editor);
  29222. var hasToolbar = isToolbarEnabled(editor);
  29223. var hasMenubar = isMenubarEnabled(editor);
  29224. var getPartToolbar = function() {
  29225. if (hasMultipleToolbar) {
  29226. return [partMultipleToolbar2];
  29227. } else if (hasToolbar) {
  29228. return [partToolbar2];
  29229. } else {
  29230. return [];
  29231. }
  29232. };
  29233. var partHeader2 = OuterContainer.parts.header({
  29234. dom: __assign({
  29235. tag: "div",
  29236. classes: ["tox-editor-header"]
  29237. }, verticalDirAttributes),
  29238. components: flatten([
  29239. hasMenubar ? [partMenubar2] : [],
  29240. getPartToolbar(),
  29241. useFixedContainer(editor) ? [] : [memAnchorBar.asSpec()]
  29242. ]),
  29243. sticky: isStickyToolbar(editor),
  29244. editor,
  29245. sharedBackstage: backstage.shared
  29246. });
  29247. var editorComponents = flatten([
  29248. isToolbarBottom ? [] : [partHeader2],
  29249. isInline ? [] : [socketSidebarContainer],
  29250. isToolbarBottom ? [partHeader2] : []
  29251. ]);
  29252. var editorContainer = {
  29253. dom: {
  29254. tag: "div",
  29255. classes: ["tox-editor-container"]
  29256. },
  29257. components: editorComponents
  29258. };
  29259. var containerComponents = flatten([
  29260. [editorContainer],
  29261. isInline ? [] : statusbar.toArray(),
  29262. [partThrobber2]
  29263. ]);
  29264. var isHidden2 = isDistractionFree(editor);
  29265. var attributes = __assign(__assign({ role: "application" }, global$e.isRtl() ? { dir: "rtl" } : {}), isHidden2 ? { "aria-hidden": "true" } : {});
  29266. var outerContainer = build$1(OuterContainer.sketch({
  29267. dom: {
  29268. tag: "div",
  29269. classes: [
  29270. "tox",
  29271. "tox-tinymce"
  29272. ].concat(isInline ? ["tox-tinymce-inline"] : []).concat(isToolbarBottom ? ["tox-tinymce--toolbar-bottom"] : []).concat(deviceClasses).concat(platformClasses),
  29273. styles: __assign({ visibility: "hidden" }, isHidden2 ? {
  29274. opacity: "0",
  29275. border: "0"
  29276. } : {}),
  29277. attributes
  29278. },
  29279. components: containerComponents,
  29280. behaviours: derive$1([
  29281. receivingConfig(),
  29282. Disabling.config({ disableClass: "tox-tinymce--disabled" }),
  29283. Keying.config({
  29284. mode: "cyclic",
  29285. selector: ".tox-menubar, .tox-toolbar, .tox-toolbar__primary, .tox-toolbar__overflow--open, .tox-sidebar__overflow--open, .tox-statusbar__path, .tox-statusbar__wordcount, .tox-statusbar__branding a, .tox-statusbar__resize-handle"
  29286. })
  29287. ])
  29288. }));
  29289. lazyOuterContainer = Optional.some(outerContainer);
  29290. editor.shortcuts.add("alt+F9", "focus menubar", function() {
  29291. OuterContainer.focusMenubar(outerContainer);
  29292. });
  29293. editor.shortcuts.add("alt+F10", "focus toolbar", function() {
  29294. OuterContainer.focusToolbar(outerContainer);
  29295. });
  29296. editor.addCommand("ToggleToolbarDrawer", function() {
  29297. OuterContainer.toggleToolbarDrawer(outerContainer);
  29298. });
  29299. editor.addQueryStateHandler("ToggleToolbarDrawer", function() {
  29300. return OuterContainer.isToolbarDrawerToggled(outerContainer);
  29301. });
  29302. var mothership = takeover(outerContainer);
  29303. var uiMothership = takeover(sink);
  29304. setup$b(editor, mothership, uiMothership);
  29305. var getUi = function() {
  29306. var channels = {
  29307. broadcastAll: uiMothership.broadcast,
  29308. broadcastOn: uiMothership.broadcastOn,
  29309. register: noop
  29310. };
  29311. return { channels };
  29312. };
  29313. var setEditorSize = function() {
  29314. var parsedHeight = numToPx(getHeightWithFallback(editor));
  29315. var parsedWidth = numToPx(getWidthWithFallback(editor));
  29316. if (!editor.inline) {
  29317. if (isValidValue("div", "width", parsedWidth)) {
  29318. set$7(outerContainer.element, "width", parsedWidth);
  29319. }
  29320. if (isValidValue("div", "height", parsedHeight)) {
  29321. set$7(outerContainer.element, "height", parsedHeight);
  29322. } else {
  29323. set$7(outerContainer.element, "height", "200px");
  29324. }
  29325. }
  29326. return parsedHeight;
  29327. };
  29328. var renderUI = function() {
  29329. header.setup(editor, backstage.shared, lazyHeader);
  29330. setup$6(editor, backstage);
  29331. setup$5(editor, lazySink, backstage);
  29332. setup$8(editor);
  29333. setup$7(editor, lazyThrobber, backstage.shared);
  29334. map$1(getToolbarGroups(editor), function(toolbarGroupButtonConfig, name2) {
  29335. editor.ui.registry.addGroupToolbarButton(name2, toolbarGroupButtonConfig);
  29336. });
  29337. var _a3 = editor.ui.registry.getAll(), buttons = _a3.buttons, menuItems = _a3.menuItems, contextToolbars = _a3.contextToolbars, sidebars = _a3.sidebars;
  29338. var toolbarOpt = getMultipleToolbarsSetting(editor);
  29339. var rawUiConfig = {
  29340. menuItems,
  29341. menus: getMenus(editor),
  29342. menubar: getMenubar(editor),
  29343. toolbar: toolbarOpt.getOrThunk(function() {
  29344. return getToolbar(editor);
  29345. }),
  29346. allowToolbarGroups: toolbarMode === ToolbarMode.floating,
  29347. buttons,
  29348. sidebar: sidebars
  29349. };
  29350. register$7(editor, contextToolbars, sink, { backstage });
  29351. setup$4(editor, sink);
  29352. var elm = editor.getElement();
  29353. var height2 = setEditorSize();
  29354. var uiComponents = {
  29355. mothership,
  29356. uiMothership,
  29357. outerContainer
  29358. };
  29359. var args = {
  29360. targetNode: elm,
  29361. height: height2
  29362. };
  29363. return mode.render(editor, uiComponents, rawUiConfig, backstage, args);
  29364. };
  29365. return {
  29366. mothership,
  29367. uiMothership,
  29368. backstage,
  29369. renderUI,
  29370. getUi
  29371. };
  29372. };
  29373. var describedBy = function(describedElement, describeElement) {
  29374. var describeId = Optional.from(get$d(describedElement, "id")).fold(function() {
  29375. var id = generate$6("dialog-describe");
  29376. set$8(describeElement, "id", id);
  29377. return id;
  29378. }, identity$1);
  29379. set$8(describedElement, "aria-describedby", describeId);
  29380. };
  29381. var labelledBy = function(labelledElement, labelElement) {
  29382. var labelId = getOpt(labelledElement, "id").fold(function() {
  29383. var id = generate$6("dialog-label");
  29384. set$8(labelElement, "id", id);
  29385. return id;
  29386. }, identity$1);
  29387. set$8(labelledElement, "aria-labelledby", labelId);
  29388. };
  29389. var schema$2 = constant$1([
  29390. required$1("lazySink"),
  29391. option("dragBlockClass"),
  29392. defaultedFunction("getBounds", win),
  29393. defaulted("useTabstopAt", always),
  29394. defaulted("eventOrder", {}),
  29395. field("modalBehaviours", [Keying]),
  29396. onKeyboardHandler("onExecute"),
  29397. onStrictKeyboardHandler("onEscape")
  29398. ]);
  29399. var basic = { sketch: identity$1 };
  29400. var parts$2 = constant$1([
  29401. optional({
  29402. name: "draghandle",
  29403. overrides: function(detail, spec) {
  29404. return {
  29405. behaviours: derive$1([Dragging.config({
  29406. mode: "mouse",
  29407. getTarget: function(handle2) {
  29408. return ancestor(handle2, '[role="dialog"]').getOr(handle2);
  29409. },
  29410. blockerClass: detail.dragBlockClass.getOrDie(new Error("The drag blocker class was not specified for a dialog with a drag handle: \n" + JSON.stringify(spec, null, 2)).message),
  29411. getBounds: detail.getDragBounds
  29412. })])
  29413. };
  29414. }
  29415. }),
  29416. required({
  29417. schema: [required$1("dom")],
  29418. name: "title"
  29419. }),
  29420. required({
  29421. factory: basic,
  29422. schema: [required$1("dom")],
  29423. name: "close"
  29424. }),
  29425. required({
  29426. factory: basic,
  29427. schema: [required$1("dom")],
  29428. name: "body"
  29429. }),
  29430. optional({
  29431. factory: basic,
  29432. schema: [required$1("dom")],
  29433. name: "footer"
  29434. }),
  29435. external$1({
  29436. factory: {
  29437. sketch: function(spec, detail) {
  29438. return __assign(__assign({}, spec), {
  29439. dom: detail.dom,
  29440. components: detail.components
  29441. });
  29442. }
  29443. },
  29444. schema: [
  29445. defaulted("dom", {
  29446. tag: "div",
  29447. styles: {
  29448. position: "fixed",
  29449. left: "0px",
  29450. top: "0px",
  29451. right: "0px",
  29452. bottom: "0px"
  29453. }
  29454. }),
  29455. defaulted("components", [])
  29456. ],
  29457. name: "blocker"
  29458. })
  29459. ]);
  29460. var factory$4 = function(detail, components2, spec, externals) {
  29461. var _a2;
  29462. var dialogComp = value$1();
  29463. var showDialog = function(dialog) {
  29464. dialogComp.set(dialog);
  29465. var sink = detail.lazySink(dialog).getOrDie();
  29466. var externalBlocker = externals.blocker();
  29467. var blocker = sink.getSystem().build(__assign(__assign({}, externalBlocker), {
  29468. components: externalBlocker.components.concat([premade(dialog)]),
  29469. behaviours: derive$1([
  29470. Focusing.config({}),
  29471. config("dialog-blocker-events", [runOnSource(focusin(), function() {
  29472. Keying.focusIn(dialog);
  29473. })])
  29474. ])
  29475. }));
  29476. attach(sink, blocker);
  29477. Keying.focusIn(dialog);
  29478. };
  29479. var hideDialog = function(dialog) {
  29480. dialogComp.clear();
  29481. parent(dialog.element).each(function(blockerDom) {
  29482. dialog.getSystem().getByDom(blockerDom).each(function(blocker) {
  29483. detach(blocker);
  29484. });
  29485. });
  29486. };
  29487. var getDialogBody = function(dialog) {
  29488. return getPartOrDie(dialog, detail, "body");
  29489. };
  29490. var getDialogFooter = function(dialog) {
  29491. return getPartOrDie(dialog, detail, "footer");
  29492. };
  29493. var setBusy = function(dialog, getBusySpec2) {
  29494. Blocking.block(dialog, getBusySpec2);
  29495. };
  29496. var setIdle = function(dialog) {
  29497. Blocking.unblock(dialog);
  29498. };
  29499. var modalEventsId = generate$6("modal-events");
  29500. var eventOrder = __assign(__assign({}, detail.eventOrder), (_a2 = {}, _a2[attachedToDom()] = [modalEventsId].concat(detail.eventOrder["alloy.system.attached"] || []), _a2));
  29501. return {
  29502. uid: detail.uid,
  29503. dom: detail.dom,
  29504. components: components2,
  29505. apis: {
  29506. show: showDialog,
  29507. hide: hideDialog,
  29508. getBody: getDialogBody,
  29509. getFooter: getDialogFooter,
  29510. setIdle,
  29511. setBusy
  29512. },
  29513. eventOrder,
  29514. domModification: {
  29515. attributes: {
  29516. "role": "dialog",
  29517. "aria-modal": "true"
  29518. }
  29519. },
  29520. behaviours: augment(detail.modalBehaviours, [
  29521. Replacing.config({}),
  29522. Keying.config({
  29523. mode: "cyclic",
  29524. onEnter: detail.onExecute,
  29525. onEscape: detail.onEscape,
  29526. useTabstopAt: detail.useTabstopAt
  29527. }),
  29528. Blocking.config({ getRoot: dialogComp.get }),
  29529. config(modalEventsId, [runOnAttached(function(c) {
  29530. labelledBy(c.element, getPartOrDie(c, detail, "title").element);
  29531. describedBy(c.element, getPartOrDie(c, detail, "body").element);
  29532. })])
  29533. ])
  29534. };
  29535. };
  29536. var ModalDialog = composite({
  29537. name: "ModalDialog",
  29538. configFields: schema$2(),
  29539. partFields: parts$2(),
  29540. factory: factory$4,
  29541. apis: {
  29542. show: function(apis, dialog) {
  29543. apis.show(dialog);
  29544. },
  29545. hide: function(apis, dialog) {
  29546. apis.hide(dialog);
  29547. },
  29548. getBody: function(apis, dialog) {
  29549. return apis.getBody(dialog);
  29550. },
  29551. getFooter: function(apis, dialog) {
  29552. return apis.getFooter(dialog);
  29553. },
  29554. setBusy: function(apis, dialog, getBusySpec2) {
  29555. apis.setBusy(dialog, getBusySpec2);
  29556. },
  29557. setIdle: function(apis, dialog) {
  29558. apis.setIdle(dialog);
  29559. }
  29560. }
  29561. });
  29562. var dialogToggleMenuItemSchema = objOf([
  29563. requiredString("type"),
  29564. requiredString("name")
  29565. ].concat(commonMenuItemFields));
  29566. var dialogToggleMenuItemDataProcessor = boolean;
  29567. var baseFooterButtonFields = [
  29568. field$1("name", "name", defaultedThunk(function() {
  29569. return generate$6("button-name");
  29570. }), string),
  29571. optionString("icon"),
  29572. defaultedStringEnum("align", "end", [
  29573. "start",
  29574. "end"
  29575. ]),
  29576. defaultedBoolean("primary", false),
  29577. defaultedBoolean("disabled", false)
  29578. ];
  29579. var dialogFooterButtonFields = __spreadArray(__spreadArray([], baseFooterButtonFields, true), [requiredString("text")], false);
  29580. var normalFooterButtonFields = __spreadArray([requiredStringEnum("type", [
  29581. "submit",
  29582. "cancel",
  29583. "custom"
  29584. ])], dialogFooterButtonFields, true);
  29585. var menuFooterButtonFields = __spreadArray([
  29586. requiredStringEnum("type", ["menu"]),
  29587. optionString("text"),
  29588. optionString("tooltip"),
  29589. optionString("icon"),
  29590. requiredArrayOf("items", dialogToggleMenuItemSchema)
  29591. ], baseFooterButtonFields, true);
  29592. var dialogFooterButtonSchema = choose$1("type", {
  29593. submit: normalFooterButtonFields,
  29594. cancel: normalFooterButtonFields,
  29595. custom: normalFooterButtonFields,
  29596. menu: menuFooterButtonFields
  29597. });
  29598. var alertBannerFields = [
  29599. requiredString("type"),
  29600. requiredString("text"),
  29601. requiredStringEnum("level", [
  29602. "info",
  29603. "warn",
  29604. "error",
  29605. "success"
  29606. ]),
  29607. requiredString("icon"),
  29608. defaulted("url", "")
  29609. ];
  29610. var alertBannerSchema = objOf(alertBannerFields);
  29611. var createBarFields = function(itemsField) {
  29612. return [
  29613. requiredString("type"),
  29614. itemsField
  29615. ];
  29616. };
  29617. var buttonFields = [
  29618. requiredString("type"),
  29619. requiredString("text"),
  29620. defaultedBoolean("disabled", false),
  29621. defaultedBoolean("primary", false),
  29622. field$1("name", "name", defaultedThunk(function() {
  29623. return generate$6("button-name");
  29624. }), string),
  29625. optionString("icon"),
  29626. defaultedBoolean("borderless", false)
  29627. ];
  29628. var buttonSchema = objOf(buttonFields);
  29629. var checkboxFields = [
  29630. requiredString("type"),
  29631. requiredString("name"),
  29632. requiredString("label"),
  29633. defaultedBoolean("disabled", false)
  29634. ];
  29635. var checkboxSchema = objOf(checkboxFields);
  29636. var checkboxDataProcessor = boolean;
  29637. var formComponentFields = [
  29638. requiredString("type"),
  29639. requiredString("name")
  29640. ];
  29641. var formComponentWithLabelFields = formComponentFields.concat([optionString("label")]);
  29642. var collectionFields = formComponentWithLabelFields.concat([defaulted("columns", "auto")]);
  29643. var collectionSchema = objOf(collectionFields);
  29644. var collectionDataProcessor = arrOfObj([
  29645. requiredString("value"),
  29646. requiredString("text"),
  29647. requiredString("icon")
  29648. ]);
  29649. var colorInputFields = formComponentWithLabelFields;
  29650. var colorInputSchema = objOf(colorInputFields);
  29651. var colorInputDataProcessor = string;
  29652. var colorPickerFields = formComponentWithLabelFields;
  29653. var colorPickerSchema = objOf(colorPickerFields);
  29654. var colorPickerDataProcessor = string;
  29655. var customEditorFields = formComponentFields.concat([
  29656. defaultedString("tag", "textarea"),
  29657. requiredString("scriptId"),
  29658. requiredString("scriptUrl"),
  29659. defaultedPostMsg("settings", void 0)
  29660. ]);
  29661. var customEditorFieldsOld = formComponentFields.concat([
  29662. defaultedString("tag", "textarea"),
  29663. requiredFunction("init")
  29664. ]);
  29665. var customEditorSchema = valueOf(function(v) {
  29666. return asRaw("customeditor.old", objOfOnly(customEditorFieldsOld), v).orThunk(function() {
  29667. return asRaw("customeditor.new", objOfOnly(customEditorFields), v);
  29668. });
  29669. });
  29670. var customEditorDataProcessor = string;
  29671. var dropZoneFields = formComponentWithLabelFields;
  29672. var dropZoneSchema = objOf(dropZoneFields);
  29673. var dropZoneDataProcessor = arrOfVal();
  29674. var createGridFields = function(itemsField) {
  29675. return [
  29676. requiredString("type"),
  29677. requiredNumber("columns"),
  29678. itemsField
  29679. ];
  29680. };
  29681. var htmlPanelFields = [
  29682. requiredString("type"),
  29683. requiredString("html"),
  29684. defaultedStringEnum("presets", "presentation", [
  29685. "presentation",
  29686. "document"
  29687. ])
  29688. ];
  29689. var htmlPanelSchema = objOf(htmlPanelFields);
  29690. var iframeFields = formComponentWithLabelFields.concat([defaultedBoolean("sandboxed", true)]);
  29691. var iframeSchema = objOf(iframeFields);
  29692. var iframeDataProcessor = string;
  29693. var imageToolsFields = formComponentWithLabelFields.concat([requiredOf("currentState", objOf([
  29694. required$1("blob"),
  29695. requiredString("url")
  29696. ]))]);
  29697. var imageToolsSchema = objOf(imageToolsFields);
  29698. var inputFields = formComponentWithLabelFields.concat([
  29699. optionString("inputMode"),
  29700. optionString("placeholder"),
  29701. defaultedBoolean("maximized", false),
  29702. defaultedBoolean("disabled", false)
  29703. ]);
  29704. var inputSchema = objOf(inputFields);
  29705. var inputDataProcessor = string;
  29706. var createLabelFields = function(itemsField) {
  29707. return [
  29708. requiredString("type"),
  29709. requiredString("label"),
  29710. itemsField
  29711. ];
  29712. };
  29713. var listBoxSingleItemFields = [
  29714. requiredString("text"),
  29715. requiredString("value")
  29716. ];
  29717. var listBoxNestedItemFields = [
  29718. requiredString("text"),
  29719. requiredArrayOf("items", thunkOf("items", function() {
  29720. return listBoxItemSchema;
  29721. }))
  29722. ];
  29723. var listBoxItemSchema = oneOf([
  29724. objOf(listBoxSingleItemFields),
  29725. objOf(listBoxNestedItemFields)
  29726. ]);
  29727. var listBoxFields = formComponentWithLabelFields.concat([
  29728. requiredArrayOf("items", listBoxItemSchema),
  29729. defaultedBoolean("disabled", false)
  29730. ]);
  29731. var listBoxSchema = objOf(listBoxFields);
  29732. var listBoxDataProcessor = string;
  29733. var selectBoxFields = formComponentWithLabelFields.concat([
  29734. requiredArrayOfObj("items", [
  29735. requiredString("text"),
  29736. requiredString("value")
  29737. ]),
  29738. defaultedNumber("size", 1),
  29739. defaultedBoolean("disabled", false)
  29740. ]);
  29741. var selectBoxSchema = objOf(selectBoxFields);
  29742. var selectBoxDataProcessor = string;
  29743. var sizeInputFields = formComponentWithLabelFields.concat([
  29744. defaultedBoolean("constrain", true),
  29745. defaultedBoolean("disabled", false)
  29746. ]);
  29747. var sizeInputSchema = objOf(sizeInputFields);
  29748. var sizeInputDataProcessor = objOf([
  29749. requiredString("width"),
  29750. requiredString("height")
  29751. ]);
  29752. var tableFields = [
  29753. requiredString("type"),
  29754. requiredArrayOf("header", string),
  29755. requiredArrayOf("cells", arrOf(string))
  29756. ];
  29757. var tableSchema = objOf(tableFields);
  29758. var textAreaFields = formComponentWithLabelFields.concat([
  29759. optionString("placeholder"),
  29760. defaultedBoolean("maximized", false),
  29761. defaultedBoolean("disabled", false)
  29762. ]);
  29763. var textAreaSchema = objOf(textAreaFields);
  29764. var textAreaDataProcessor = string;
  29765. var urlInputFields = formComponentWithLabelFields.concat([
  29766. defaultedStringEnum("filetype", "file", [
  29767. "image",
  29768. "media",
  29769. "file"
  29770. ]),
  29771. defaulted("disabled", false)
  29772. ]);
  29773. var urlInputSchema = objOf(urlInputFields);
  29774. var urlInputDataProcessor = objOf([
  29775. requiredString("value"),
  29776. defaulted("meta", {})
  29777. ]);
  29778. var createItemsField = function(name2) {
  29779. return field$1("items", "items", required$2(), arrOf(valueOf(function(v) {
  29780. return asRaw("Checking item of " + name2, itemSchema, v).fold(function(sErr) {
  29781. return Result.error(formatError(sErr));
  29782. }, function(passValue) {
  29783. return Result.value(passValue);
  29784. });
  29785. })));
  29786. };
  29787. var itemSchema = valueThunk(function() {
  29788. return choose$2("type", {
  29789. alertbanner: alertBannerSchema,
  29790. bar: objOf(createBarFields(createItemsField("bar"))),
  29791. button: buttonSchema,
  29792. checkbox: checkboxSchema,
  29793. colorinput: colorInputSchema,
  29794. colorpicker: colorPickerSchema,
  29795. dropzone: dropZoneSchema,
  29796. grid: objOf(createGridFields(createItemsField("grid"))),
  29797. iframe: iframeSchema,
  29798. input: inputSchema,
  29799. listbox: listBoxSchema,
  29800. selectbox: selectBoxSchema,
  29801. sizeinput: sizeInputSchema,
  29802. textarea: textAreaSchema,
  29803. urlinput: urlInputSchema,
  29804. customeditor: customEditorSchema,
  29805. htmlpanel: htmlPanelSchema,
  29806. imagetools: imageToolsSchema,
  29807. collection: collectionSchema,
  29808. label: objOf(createLabelFields(createItemsField("label"))),
  29809. table: tableSchema,
  29810. panel: panelSchema
  29811. });
  29812. });
  29813. var panelFields = [
  29814. requiredString("type"),
  29815. defaulted("classes", []),
  29816. requiredArrayOf("items", itemSchema)
  29817. ];
  29818. var panelSchema = objOf(panelFields);
  29819. var tabFields = [
  29820. field$1("name", "name", defaultedThunk(function() {
  29821. return generate$6("tab-name");
  29822. }), string),
  29823. requiredString("title"),
  29824. requiredArrayOf("items", itemSchema)
  29825. ];
  29826. var tabPanelFields = [
  29827. requiredString("type"),
  29828. requiredArrayOfObj("tabs", tabFields)
  29829. ];
  29830. var tabPanelSchema = objOf(tabPanelFields);
  29831. var dialogButtonFields = dialogFooterButtonFields;
  29832. var dialogButtonSchema = dialogFooterButtonSchema;
  29833. var dialogSchema = objOf([
  29834. requiredString("title"),
  29835. requiredOf("body", choose$2("type", {
  29836. panel: panelSchema,
  29837. tabpanel: tabPanelSchema
  29838. })),
  29839. defaultedString("size", "normal"),
  29840. requiredArrayOf("buttons", dialogButtonSchema),
  29841. defaulted("initialData", {}),
  29842. defaultedFunction("onAction", noop),
  29843. defaultedFunction("onChange", noop),
  29844. defaultedFunction("onSubmit", noop),
  29845. defaultedFunction("onClose", noop),
  29846. defaultedFunction("onCancel", noop),
  29847. defaulted("onTabChange", noop)
  29848. ]);
  29849. var createDialog = function(spec) {
  29850. return asRaw("dialog", dialogSchema, spec);
  29851. };
  29852. var urlDialogButtonSchema = objOf(__spreadArray([requiredStringEnum("type", [
  29853. "cancel",
  29854. "custom"
  29855. ])], dialogButtonFields, true));
  29856. var urlDialogSchema = objOf([
  29857. requiredString("title"),
  29858. requiredString("url"),
  29859. optionNumber("height"),
  29860. optionNumber("width"),
  29861. optionArrayOf("buttons", urlDialogButtonSchema),
  29862. defaultedFunction("onAction", noop),
  29863. defaultedFunction("onCancel", noop),
  29864. defaultedFunction("onClose", noop),
  29865. defaultedFunction("onMessage", noop)
  29866. ]);
  29867. var createUrlDialog = function(spec) {
  29868. return asRaw("dialog", urlDialogSchema, spec);
  29869. };
  29870. var getAllObjects = function(obj) {
  29871. if (isObject(obj)) {
  29872. return [obj].concat(bind$3(values(obj), getAllObjects));
  29873. } else if (isArray(obj)) {
  29874. return bind$3(obj, getAllObjects);
  29875. } else {
  29876. return [];
  29877. }
  29878. };
  29879. var isNamedItem = function(obj) {
  29880. return isString(obj.type) && isString(obj.name);
  29881. };
  29882. var dataProcessors = {
  29883. checkbox: checkboxDataProcessor,
  29884. colorinput: colorInputDataProcessor,
  29885. colorpicker: colorPickerDataProcessor,
  29886. dropzone: dropZoneDataProcessor,
  29887. input: inputDataProcessor,
  29888. iframe: iframeDataProcessor,
  29889. sizeinput: sizeInputDataProcessor,
  29890. selectbox: selectBoxDataProcessor,
  29891. listbox: listBoxDataProcessor,
  29892. size: sizeInputDataProcessor,
  29893. textarea: textAreaDataProcessor,
  29894. urlinput: urlInputDataProcessor,
  29895. customeditor: customEditorDataProcessor,
  29896. collection: collectionDataProcessor,
  29897. togglemenuitem: dialogToggleMenuItemDataProcessor
  29898. };
  29899. var getDataProcessor = function(item2) {
  29900. return Optional.from(dataProcessors[item2.type]);
  29901. };
  29902. var getNamedItems = function(structure) {
  29903. return filter$2(getAllObjects(structure), isNamedItem);
  29904. };
  29905. var createDataValidator = function(structure) {
  29906. var namedItems = getNamedItems(structure);
  29907. var fields = bind$3(namedItems, function(item2) {
  29908. return getDataProcessor(item2).fold(function() {
  29909. return [];
  29910. }, function(schema2) {
  29911. return [requiredOf(item2.name, schema2)];
  29912. });
  29913. });
  29914. return objOf(fields);
  29915. };
  29916. var extract = function(structure) {
  29917. var internalDialog = getOrDie(createDialog(structure));
  29918. var dataValidator = createDataValidator(structure);
  29919. var initialData = structure.initialData;
  29920. return {
  29921. internalDialog,
  29922. dataValidator,
  29923. initialData
  29924. };
  29925. };
  29926. var DialogManager = {
  29927. open: function(factory2, structure) {
  29928. var extraction = extract(structure);
  29929. return factory2(extraction.internalDialog, extraction.initialData, extraction.dataValidator);
  29930. },
  29931. openUrl: function(factory2, structure) {
  29932. var internalDialog = getOrDie(createUrlDialog(structure));
  29933. return factory2(internalDialog);
  29934. },
  29935. redial: function(structure) {
  29936. return extract(structure);
  29937. }
  29938. };
  29939. var toValidValues = function(values2) {
  29940. var errors = [];
  29941. var result = {};
  29942. each(values2, function(value2, name2) {
  29943. value2.fold(function() {
  29944. errors.push(name2);
  29945. }, function(v) {
  29946. result[name2] = v;
  29947. });
  29948. });
  29949. return errors.length > 0 ? Result.error(errors) : Result.value(result);
  29950. };
  29951. var renderBodyPanel = function(spec, backstage) {
  29952. var memForm = record(Form.sketch(function(parts2) {
  29953. return {
  29954. dom: {
  29955. tag: "div",
  29956. classes: ["tox-form"].concat(spec.classes)
  29957. },
  29958. components: map$2(spec.items, function(item2) {
  29959. return interpretInForm(parts2, item2, backstage);
  29960. })
  29961. };
  29962. }));
  29963. return {
  29964. dom: {
  29965. tag: "div",
  29966. classes: ["tox-dialog__body"]
  29967. },
  29968. components: [{
  29969. dom: {
  29970. tag: "div",
  29971. classes: ["tox-dialog__body-content"]
  29972. },
  29973. components: [memForm.asSpec()]
  29974. }],
  29975. behaviours: derive$1([
  29976. Keying.config({
  29977. mode: "acyclic",
  29978. useTabstopAt: not(isPseudoStop)
  29979. }),
  29980. ComposingConfigs.memento(memForm),
  29981. RepresentingConfigs.memento(memForm, {
  29982. postprocess: function(formValue) {
  29983. return toValidValues(formValue).fold(function(err) {
  29984. console.error(err);
  29985. return {};
  29986. }, identity$1);
  29987. }
  29988. })
  29989. ])
  29990. };
  29991. };
  29992. var factory$3 = function(detail, _spec) {
  29993. return {
  29994. uid: detail.uid,
  29995. dom: detail.dom,
  29996. components: detail.components,
  29997. events: events$a(detail.action),
  29998. behaviours: augment(detail.tabButtonBehaviours, [
  29999. Focusing.config({}),
  30000. Keying.config({
  30001. mode: "execution",
  30002. useSpace: true,
  30003. useEnter: true
  30004. }),
  30005. Representing.config({
  30006. store: {
  30007. mode: "memory",
  30008. initialValue: detail.value
  30009. }
  30010. })
  30011. ]),
  30012. domModification: detail.domModification
  30013. };
  30014. };
  30015. var TabButton = single({
  30016. name: "TabButton",
  30017. configFields: [
  30018. defaulted("uid", void 0),
  30019. required$1("value"),
  30020. field$1("dom", "dom", mergeWithThunk(function() {
  30021. return {
  30022. attributes: {
  30023. "role": "tab",
  30024. "id": generate$6("aria"),
  30025. "aria-selected": "false"
  30026. }
  30027. };
  30028. }), anyValue()),
  30029. option("action"),
  30030. defaulted("domModification", {}),
  30031. field("tabButtonBehaviours", [
  30032. Focusing,
  30033. Keying,
  30034. Representing
  30035. ]),
  30036. required$1("view")
  30037. ],
  30038. factory: factory$3
  30039. });
  30040. var schema$1 = constant$1([
  30041. required$1("tabs"),
  30042. required$1("dom"),
  30043. defaulted("clickToDismiss", false),
  30044. field("tabbarBehaviours", [
  30045. Highlighting,
  30046. Keying
  30047. ]),
  30048. markers$1([
  30049. "tabClass",
  30050. "selectedClass"
  30051. ])
  30052. ]);
  30053. var tabsPart = group({
  30054. factory: TabButton,
  30055. name: "tabs",
  30056. unit: "tab",
  30057. overrides: function(barDetail) {
  30058. var dismissTab$1 = function(tabbar, button2) {
  30059. Highlighting.dehighlight(tabbar, button2);
  30060. emitWith(tabbar, dismissTab(), {
  30061. tabbar,
  30062. button: button2
  30063. });
  30064. };
  30065. var changeTab$1 = function(tabbar, button2) {
  30066. Highlighting.highlight(tabbar, button2);
  30067. emitWith(tabbar, changeTab(), {
  30068. tabbar,
  30069. button: button2
  30070. });
  30071. };
  30072. return {
  30073. action: function(button2) {
  30074. var tabbar = button2.getSystem().getByUid(barDetail.uid).getOrDie();
  30075. var activeButton = Highlighting.isHighlighted(tabbar, button2);
  30076. var response = function() {
  30077. if (activeButton && barDetail.clickToDismiss) {
  30078. return dismissTab$1;
  30079. } else if (!activeButton) {
  30080. return changeTab$1;
  30081. } else {
  30082. return noop;
  30083. }
  30084. }();
  30085. response(tabbar, button2);
  30086. },
  30087. domModification: { classes: [barDetail.markers.tabClass] }
  30088. };
  30089. }
  30090. });
  30091. var parts$1 = constant$1([tabsPart]);
  30092. var factory$2 = function(detail, components2, _spec, _externals) {
  30093. return {
  30094. "uid": detail.uid,
  30095. "dom": detail.dom,
  30096. components: components2,
  30097. "debug.sketcher": "Tabbar",
  30098. "domModification": { attributes: { role: "tablist" } },
  30099. "behaviours": augment(detail.tabbarBehaviours, [
  30100. Highlighting.config({
  30101. highlightClass: detail.markers.selectedClass,
  30102. itemClass: detail.markers.tabClass,
  30103. onHighlight: function(tabbar, tab) {
  30104. set$8(tab.element, "aria-selected", "true");
  30105. },
  30106. onDehighlight: function(tabbar, tab) {
  30107. set$8(tab.element, "aria-selected", "false");
  30108. }
  30109. }),
  30110. Keying.config({
  30111. mode: "flow",
  30112. getInitial: function(tabbar) {
  30113. return Highlighting.getHighlighted(tabbar).map(function(tab) {
  30114. return tab.element;
  30115. });
  30116. },
  30117. selector: "." + detail.markers.tabClass,
  30118. executeOnMove: true
  30119. })
  30120. ])
  30121. };
  30122. };
  30123. var Tabbar = composite({
  30124. name: "Tabbar",
  30125. configFields: schema$1(),
  30126. partFields: parts$1(),
  30127. factory: factory$2
  30128. });
  30129. var factory$1 = function(detail, _spec) {
  30130. return {
  30131. uid: detail.uid,
  30132. dom: detail.dom,
  30133. behaviours: augment(detail.tabviewBehaviours, [Replacing.config({})]),
  30134. domModification: { attributes: { role: "tabpanel" } }
  30135. };
  30136. };
  30137. var Tabview = single({
  30138. name: "Tabview",
  30139. configFields: [field("tabviewBehaviours", [Replacing])],
  30140. factory: factory$1
  30141. });
  30142. var schema = constant$1([
  30143. defaulted("selectFirst", true),
  30144. onHandler("onChangeTab"),
  30145. onHandler("onDismissTab"),
  30146. defaulted("tabs", []),
  30147. field("tabSectionBehaviours", [])
  30148. ]);
  30149. var barPart = required({
  30150. factory: Tabbar,
  30151. schema: [
  30152. required$1("dom"),
  30153. requiredObjOf("markers", [
  30154. required$1("tabClass"),
  30155. required$1("selectedClass")
  30156. ])
  30157. ],
  30158. name: "tabbar",
  30159. defaults: function(detail) {
  30160. return { tabs: detail.tabs };
  30161. }
  30162. });
  30163. var viewPart = required({
  30164. factory: Tabview,
  30165. name: "tabview"
  30166. });
  30167. var parts = constant$1([
  30168. barPart,
  30169. viewPart
  30170. ]);
  30171. var factory = function(detail, components2, _spec, _externals) {
  30172. var changeTab$1 = function(button2) {
  30173. var tabValue = Representing.getValue(button2);
  30174. getPart(button2, detail, "tabview").each(function(tabview) {
  30175. var tabWithValue = find$5(detail.tabs, function(t2) {
  30176. return t2.value === tabValue;
  30177. });
  30178. tabWithValue.each(function(tabData) {
  30179. var panel = tabData.view();
  30180. getOpt(button2.element, "id").each(function(id) {
  30181. set$8(tabview.element, "aria-labelledby", id);
  30182. });
  30183. Replacing.set(tabview, panel);
  30184. detail.onChangeTab(tabview, button2, panel);
  30185. });
  30186. });
  30187. };
  30188. var changeTabBy = function(section, byPred) {
  30189. getPart(section, detail, "tabbar").each(function(tabbar) {
  30190. byPred(tabbar).each(emitExecute);
  30191. });
  30192. };
  30193. return {
  30194. uid: detail.uid,
  30195. dom: detail.dom,
  30196. components: components2,
  30197. behaviours: get$2(detail.tabSectionBehaviours),
  30198. events: derive$2(flatten([
  30199. detail.selectFirst ? [runOnAttached(function(section, _simulatedEvent) {
  30200. changeTabBy(section, Highlighting.getFirst);
  30201. })] : [],
  30202. [
  30203. run$1(changeTab(), function(section, simulatedEvent) {
  30204. var button2 = simulatedEvent.event.button;
  30205. changeTab$1(button2);
  30206. }),
  30207. run$1(dismissTab(), function(section, simulatedEvent) {
  30208. var button2 = simulatedEvent.event.button;
  30209. detail.onDismissTab(section, button2);
  30210. })
  30211. ]
  30212. ])),
  30213. apis: {
  30214. getViewItems: function(section) {
  30215. return getPart(section, detail, "tabview").map(function(tabview) {
  30216. return Replacing.contents(tabview);
  30217. }).getOr([]);
  30218. },
  30219. showTab: function(section, tabKey) {
  30220. var getTabIfNotActive = function(tabbar) {
  30221. var candidates = Highlighting.getCandidates(tabbar);
  30222. var optTab = find$5(candidates, function(c) {
  30223. return Representing.getValue(c) === tabKey;
  30224. });
  30225. return optTab.filter(function(tab) {
  30226. return !Highlighting.isHighlighted(tabbar, tab);
  30227. });
  30228. };
  30229. changeTabBy(section, getTabIfNotActive);
  30230. }
  30231. }
  30232. };
  30233. };
  30234. var TabSection = composite({
  30235. name: "TabSection",
  30236. configFields: schema(),
  30237. partFields: parts(),
  30238. factory,
  30239. apis: {
  30240. getViewItems: function(apis, component) {
  30241. return apis.getViewItems(component);
  30242. },
  30243. showTab: function(apis, component, tabKey) {
  30244. apis.showTab(component, tabKey);
  30245. }
  30246. }
  30247. });
  30248. var measureHeights = function(allTabs, tabview, tabviewComp) {
  30249. return map$2(allTabs, function(_tab, i) {
  30250. Replacing.set(tabviewComp, allTabs[i].view());
  30251. var rect2 = tabview.dom.getBoundingClientRect();
  30252. Replacing.set(tabviewComp, []);
  30253. return rect2.height;
  30254. });
  30255. };
  30256. var getMaxHeight = function(heights) {
  30257. return head(sort(heights, function(a, b2) {
  30258. if (a > b2) {
  30259. return -1;
  30260. } else if (a < b2) {
  30261. return 1;
  30262. } else {
  30263. return 0;
  30264. }
  30265. }));
  30266. };
  30267. var getMaxTabviewHeight = function(dialog, tabview, tablist) {
  30268. var documentElement$1 = documentElement(dialog).dom;
  30269. var rootElm = ancestor(dialog, ".tox-dialog-wrap").getOr(dialog);
  30270. var isFixed = get$c(rootElm, "position") === "fixed";
  30271. var maxHeight;
  30272. if (isFixed) {
  30273. maxHeight = Math.max(documentElement$1.clientHeight, window.innerHeight);
  30274. } else {
  30275. maxHeight = Math.max(documentElement$1.offsetHeight, documentElement$1.scrollHeight);
  30276. }
  30277. var tabviewHeight = get$b(tabview);
  30278. var isTabListBeside = tabview.dom.offsetLeft >= tablist.dom.offsetLeft + get$a(tablist);
  30279. var currentTabHeight = isTabListBeside ? Math.max(get$b(tablist), tabviewHeight) : tabviewHeight;
  30280. var dialogTopMargin = parseInt(get$c(dialog, "margin-top"), 10) || 0;
  30281. var dialogBottomMargin = parseInt(get$c(dialog, "margin-bottom"), 10) || 0;
  30282. var dialogHeight = get$b(dialog) + dialogTopMargin + dialogBottomMargin;
  30283. var chromeHeight = dialogHeight - currentTabHeight;
  30284. return maxHeight - chromeHeight;
  30285. };
  30286. var showTab = function(allTabs, comp) {
  30287. head(allTabs).each(function(tab) {
  30288. return TabSection.showTab(comp, tab.value);
  30289. });
  30290. };
  30291. var setTabviewHeight = function(tabview, height2) {
  30292. set$7(tabview, "height", height2 + "px");
  30293. if (!detect$1().browser.isIE()) {
  30294. set$7(tabview, "flex-basis", height2 + "px");
  30295. } else {
  30296. remove$6(tabview, "flex-basis");
  30297. }
  30298. };
  30299. var updateTabviewHeight = function(dialogBody, tabview, maxTabHeight) {
  30300. ancestor(dialogBody, '[role="dialog"]').each(function(dialog) {
  30301. descendant(dialog, '[role="tablist"]').each(function(tablist) {
  30302. maxTabHeight.get().map(function(height2) {
  30303. set$7(tabview, "height", "0");
  30304. set$7(tabview, "flex-basis", "0");
  30305. return Math.min(height2, getMaxTabviewHeight(dialog, tabview, tablist));
  30306. }).each(function(height2) {
  30307. setTabviewHeight(tabview, height2);
  30308. });
  30309. });
  30310. });
  30311. };
  30312. var getTabview = function(dialog) {
  30313. return descendant(dialog, '[role="tabpanel"]');
  30314. };
  30315. var setMode = function(allTabs) {
  30316. var smartTabHeight = function() {
  30317. var maxTabHeight = value$1();
  30318. var extraEvents = [
  30319. runOnAttached(function(comp) {
  30320. var dialog = comp.element;
  30321. getTabview(dialog).each(function(tabview) {
  30322. set$7(tabview, "visibility", "hidden");
  30323. comp.getSystem().getByDom(tabview).toOptional().each(function(tabviewComp) {
  30324. var heights = measureHeights(allTabs, tabview, tabviewComp);
  30325. var maxTabHeightOpt = getMaxHeight(heights);
  30326. maxTabHeightOpt.fold(maxTabHeight.clear, maxTabHeight.set);
  30327. });
  30328. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30329. remove$6(tabview, "visibility");
  30330. showTab(allTabs, comp);
  30331. global$f.requestAnimationFrame(function() {
  30332. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30333. });
  30334. });
  30335. }),
  30336. run$1(windowResize(), function(comp) {
  30337. var dialog = comp.element;
  30338. getTabview(dialog).each(function(tabview) {
  30339. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30340. });
  30341. }),
  30342. run$1(formResizeEvent, function(comp, _se) {
  30343. var dialog = comp.element;
  30344. getTabview(dialog).each(function(tabview) {
  30345. var oldFocus = active(getRootNode(tabview));
  30346. set$7(tabview, "visibility", "hidden");
  30347. var oldHeight = getRaw(tabview, "height").map(function(h) {
  30348. return parseInt(h, 10);
  30349. });
  30350. remove$6(tabview, "height");
  30351. remove$6(tabview, "flex-basis");
  30352. var newHeight = tabview.dom.getBoundingClientRect().height;
  30353. var hasGrown2 = oldHeight.forall(function(h) {
  30354. return newHeight > h;
  30355. });
  30356. if (hasGrown2) {
  30357. maxTabHeight.set(newHeight);
  30358. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30359. } else {
  30360. oldHeight.each(function(h) {
  30361. setTabviewHeight(tabview, h);
  30362. });
  30363. }
  30364. remove$6(tabview, "visibility");
  30365. oldFocus.each(focus$3);
  30366. });
  30367. })
  30368. ];
  30369. var selectFirst = false;
  30370. return {
  30371. extraEvents,
  30372. selectFirst
  30373. };
  30374. }();
  30375. var naiveTabHeight = function() {
  30376. var extraEvents = [];
  30377. var selectFirst = true;
  30378. return {
  30379. extraEvents,
  30380. selectFirst
  30381. };
  30382. }();
  30383. return {
  30384. smartTabHeight,
  30385. naiveTabHeight
  30386. };
  30387. };
  30388. var SendDataToSectionChannel = "send-data-to-section";
  30389. var SendDataToViewChannel = "send-data-to-view";
  30390. var renderTabPanel = function(spec, backstage) {
  30391. var storedValue = Cell({});
  30392. var updateDataWithForm = function(form) {
  30393. var formData = Representing.getValue(form);
  30394. var validData = toValidValues(formData).getOr({});
  30395. var currentData = storedValue.get();
  30396. var newData = deepMerge(currentData, validData);
  30397. storedValue.set(newData);
  30398. };
  30399. var setDataOnForm = function(form) {
  30400. var tabData = storedValue.get();
  30401. Representing.setValue(form, tabData);
  30402. };
  30403. var oldTab = Cell(null);
  30404. var allTabs = map$2(spec.tabs, function(tab) {
  30405. return {
  30406. value: tab.name,
  30407. dom: {
  30408. tag: "div",
  30409. classes: ["tox-dialog__body-nav-item"],
  30410. innerHtml: backstage.shared.providers.translate(tab.title)
  30411. },
  30412. view: function() {
  30413. return [Form.sketch(function(parts2) {
  30414. return {
  30415. dom: {
  30416. tag: "div",
  30417. classes: ["tox-form"]
  30418. },
  30419. components: map$2(tab.items, function(item2) {
  30420. return interpretInForm(parts2, item2, backstage);
  30421. }),
  30422. formBehaviours: derive$1([
  30423. Keying.config({
  30424. mode: "acyclic",
  30425. useTabstopAt: not(isPseudoStop)
  30426. }),
  30427. config("TabView.form.events", [
  30428. runOnAttached(setDataOnForm),
  30429. runOnDetached(updateDataWithForm)
  30430. ]),
  30431. Receiving.config({
  30432. channels: wrapAll([
  30433. {
  30434. key: SendDataToSectionChannel,
  30435. value: { onReceive: updateDataWithForm }
  30436. },
  30437. {
  30438. key: SendDataToViewChannel,
  30439. value: { onReceive: setDataOnForm }
  30440. }
  30441. ])
  30442. })
  30443. ])
  30444. };
  30445. })];
  30446. }
  30447. };
  30448. });
  30449. var tabMode = setMode(allTabs).smartTabHeight;
  30450. return TabSection.sketch({
  30451. dom: {
  30452. tag: "div",
  30453. classes: ["tox-dialog__body"]
  30454. },
  30455. onChangeTab: function(section, button2, _viewItems) {
  30456. var name2 = Representing.getValue(button2);
  30457. emitWith(section, formTabChangeEvent, {
  30458. name: name2,
  30459. oldName: oldTab.get()
  30460. });
  30461. oldTab.set(name2);
  30462. },
  30463. tabs: allTabs,
  30464. components: [
  30465. TabSection.parts.tabbar({
  30466. dom: {
  30467. tag: "div",
  30468. classes: ["tox-dialog__body-nav"]
  30469. },
  30470. components: [Tabbar.parts.tabs({})],
  30471. markers: {
  30472. tabClass: "tox-tab",
  30473. selectedClass: "tox-dialog__body-nav-item--active"
  30474. },
  30475. tabbarBehaviours: derive$1([Tabstopping.config({})])
  30476. }),
  30477. TabSection.parts.tabview({
  30478. dom: {
  30479. tag: "div",
  30480. classes: ["tox-dialog__body-content"]
  30481. }
  30482. })
  30483. ],
  30484. selectFirst: tabMode.selectFirst,
  30485. tabSectionBehaviours: derive$1([
  30486. config("tabpanel", tabMode.extraEvents),
  30487. Keying.config({ mode: "acyclic" }),
  30488. Composing.config({
  30489. find: function(comp) {
  30490. return head(TabSection.getViewItems(comp));
  30491. }
  30492. }),
  30493. Representing.config({
  30494. store: {
  30495. mode: "manual",
  30496. getValue: function(tsection) {
  30497. tsection.getSystem().broadcastOn([SendDataToSectionChannel], {});
  30498. return storedValue.get();
  30499. },
  30500. setValue: function(tsection, value2) {
  30501. storedValue.set(value2);
  30502. tsection.getSystem().broadcastOn([SendDataToViewChannel], {});
  30503. }
  30504. }
  30505. })
  30506. ])
  30507. });
  30508. };
  30509. var dialogChannel = generate$6("update-dialog");
  30510. var titleChannel = generate$6("update-title");
  30511. var bodyChannel = generate$6("update-body");
  30512. var footerChannel = generate$6("update-footer");
  30513. var bodySendMessageChannel = generate$6("body-send-message");
  30514. var renderBody = function(spec, id, backstage, ariaAttrs) {
  30515. var renderComponents2 = function(incoming) {
  30516. switch (incoming.body.type) {
  30517. case "tabpanel": {
  30518. return [renderTabPanel(incoming.body, backstage)];
  30519. }
  30520. default: {
  30521. return [renderBodyPanel(incoming.body, backstage)];
  30522. }
  30523. }
  30524. };
  30525. var updateState = function(_comp, incoming) {
  30526. return Optional.some({
  30527. isTabPanel: function() {
  30528. return incoming.body.type === "tabpanel";
  30529. }
  30530. });
  30531. };
  30532. var ariaAttributes = { "aria-live": "polite" };
  30533. return {
  30534. dom: {
  30535. tag: "div",
  30536. classes: ["tox-dialog__content-js"],
  30537. attributes: __assign(__assign({}, id.map(function(x) {
  30538. return { id: x };
  30539. }).getOr({})), ariaAttrs ? ariaAttributes : {})
  30540. },
  30541. components: [],
  30542. behaviours: derive$1([
  30543. ComposingConfigs.childAt(0),
  30544. Reflecting.config({
  30545. channel: bodyChannel,
  30546. updateState,
  30547. renderComponents: renderComponents2,
  30548. initialData: spec
  30549. })
  30550. ])
  30551. };
  30552. };
  30553. var renderInlineBody = function(spec, contentId, backstage, ariaAttrs) {
  30554. return renderBody(spec, Optional.some(contentId), backstage, ariaAttrs);
  30555. };
  30556. var renderModalBody = function(spec, backstage) {
  30557. var bodySpec = renderBody(spec, Optional.none(), backstage, false);
  30558. return ModalDialog.parts.body(bodySpec);
  30559. };
  30560. var renderIframeBody = function(spec) {
  30561. var bodySpec = {
  30562. dom: {
  30563. tag: "div",
  30564. classes: ["tox-dialog__content-js"]
  30565. },
  30566. components: [{
  30567. dom: {
  30568. tag: "div",
  30569. classes: ["tox-dialog__body-iframe"]
  30570. },
  30571. components: [craft({
  30572. dom: {
  30573. tag: "iframe",
  30574. attributes: { src: spec.url }
  30575. },
  30576. behaviours: derive$1([
  30577. Tabstopping.config({}),
  30578. Focusing.config({})
  30579. ])
  30580. })]
  30581. }],
  30582. behaviours: derive$1([Keying.config({
  30583. mode: "acyclic",
  30584. useTabstopAt: not(isPseudoStop)
  30585. })])
  30586. };
  30587. return ModalDialog.parts.body(bodySpec);
  30588. };
  30589. var isTouch = global$9.deviceType.isTouch();
  30590. var hiddenHeader = function(title, close2) {
  30591. return {
  30592. dom: {
  30593. tag: "div",
  30594. styles: { display: "none" },
  30595. classes: ["tox-dialog__header"]
  30596. },
  30597. components: [
  30598. title,
  30599. close2
  30600. ]
  30601. };
  30602. };
  30603. var pClose = function(onClose, providersBackstage) {
  30604. return ModalDialog.parts.close(Button.sketch({
  30605. dom: {
  30606. tag: "button",
  30607. classes: [
  30608. "tox-button",
  30609. "tox-button--icon",
  30610. "tox-button--naked"
  30611. ],
  30612. attributes: {
  30613. "type": "button",
  30614. "aria-label": providersBackstage.translate("Close")
  30615. }
  30616. },
  30617. action: onClose,
  30618. buttonBehaviours: derive$1([Tabstopping.config({})])
  30619. }));
  30620. };
  30621. var pUntitled = function() {
  30622. return ModalDialog.parts.title({
  30623. dom: {
  30624. tag: "div",
  30625. classes: ["tox-dialog__title"],
  30626. innerHtml: "",
  30627. styles: { display: "none" }
  30628. }
  30629. });
  30630. };
  30631. var pBodyMessage = function(message, providersBackstage) {
  30632. return ModalDialog.parts.body({
  30633. dom: {
  30634. tag: "div",
  30635. classes: ["tox-dialog__body"]
  30636. },
  30637. components: [{
  30638. dom: {
  30639. tag: "div",
  30640. classes: ["tox-dialog__body-content"]
  30641. },
  30642. components: [{ dom: fromHtml("<p>" + providersBackstage.translate(message) + "</p>") }]
  30643. }]
  30644. });
  30645. };
  30646. var pFooter = function(buttons) {
  30647. return ModalDialog.parts.footer({
  30648. dom: {
  30649. tag: "div",
  30650. classes: ["tox-dialog__footer"]
  30651. },
  30652. components: buttons
  30653. });
  30654. };
  30655. var pFooterGroup = function(startButtons, endButtons) {
  30656. return [
  30657. Container.sketch({
  30658. dom: {
  30659. tag: "div",
  30660. classes: ["tox-dialog__footer-start"]
  30661. },
  30662. components: startButtons
  30663. }),
  30664. Container.sketch({
  30665. dom: {
  30666. tag: "div",
  30667. classes: ["tox-dialog__footer-end"]
  30668. },
  30669. components: endButtons
  30670. })
  30671. ];
  30672. };
  30673. var renderDialog$1 = function(spec) {
  30674. var _a2;
  30675. var dialogClass = "tox-dialog";
  30676. var blockerClass = dialogClass + "-wrap";
  30677. var blockerBackdropClass = blockerClass + "__backdrop";
  30678. var scrollLockClass = dialogClass + "__disable-scroll";
  30679. return ModalDialog.sketch({
  30680. lazySink: spec.lazySink,
  30681. onEscape: function(comp) {
  30682. spec.onEscape(comp);
  30683. return Optional.some(true);
  30684. },
  30685. useTabstopAt: function(elem) {
  30686. return !isPseudoStop(elem);
  30687. },
  30688. dom: {
  30689. tag: "div",
  30690. classes: [dialogClass].concat(spec.extraClasses),
  30691. styles: __assign({ position: "relative" }, spec.extraStyles)
  30692. },
  30693. components: __spreadArray([
  30694. spec.header,
  30695. spec.body
  30696. ], spec.footer.toArray(), true),
  30697. parts: {
  30698. blocker: {
  30699. dom: fromHtml('<div class="' + blockerClass + '"></div>'),
  30700. components: [{
  30701. dom: {
  30702. tag: "div",
  30703. classes: isTouch ? [
  30704. blockerBackdropClass,
  30705. blockerBackdropClass + "--opaque"
  30706. ] : [blockerBackdropClass]
  30707. }
  30708. }]
  30709. }
  30710. },
  30711. dragBlockClass: blockerClass,
  30712. modalBehaviours: derive$1(__spreadArray([
  30713. Focusing.config({}),
  30714. config("dialog-events", spec.dialogEvents.concat([runOnSource(focusin(), function(comp, _se) {
  30715. Keying.focusIn(comp);
  30716. })])),
  30717. config("scroll-lock", [
  30718. runOnAttached(function() {
  30719. add$2(body(), scrollLockClass);
  30720. }),
  30721. runOnDetached(function() {
  30722. remove$2(body(), scrollLockClass);
  30723. })
  30724. ])
  30725. ], spec.extraBehaviours, true)),
  30726. eventOrder: __assign((_a2 = {}, _a2[execute$5()] = ["dialog-events"], _a2[attachedToDom()] = [
  30727. "scroll-lock",
  30728. "dialog-events",
  30729. "alloy.base.behaviour"
  30730. ], _a2[detachedFromDom()] = [
  30731. "alloy.base.behaviour",
  30732. "dialog-events",
  30733. "scroll-lock"
  30734. ], _a2), spec.eventOrder)
  30735. });
  30736. };
  30737. var renderClose = function(providersBackstage) {
  30738. return Button.sketch({
  30739. dom: {
  30740. tag: "button",
  30741. classes: [
  30742. "tox-button",
  30743. "tox-button--icon",
  30744. "tox-button--naked"
  30745. ],
  30746. attributes: {
  30747. "type": "button",
  30748. "aria-label": providersBackstage.translate("Close"),
  30749. "title": providersBackstage.translate("Close")
  30750. }
  30751. },
  30752. components: [render$3("close", {
  30753. tag: "div",
  30754. classes: ["tox-icon"]
  30755. }, providersBackstage.icons)],
  30756. action: function(comp) {
  30757. emit(comp, formCancelEvent);
  30758. }
  30759. });
  30760. };
  30761. var renderTitle = function(spec, id, providersBackstage) {
  30762. var renderComponents2 = function(data) {
  30763. return [text(providersBackstage.translate(data.title))];
  30764. };
  30765. return {
  30766. dom: {
  30767. tag: "div",
  30768. classes: ["tox-dialog__title"],
  30769. attributes: __assign({}, id.map(function(x) {
  30770. return { id: x };
  30771. }).getOr({}))
  30772. },
  30773. components: renderComponents2(spec),
  30774. behaviours: derive$1([Reflecting.config({
  30775. channel: titleChannel,
  30776. renderComponents: renderComponents2
  30777. })])
  30778. };
  30779. };
  30780. var renderDragHandle = function() {
  30781. return { dom: fromHtml('<div class="tox-dialog__draghandle"></div>') };
  30782. };
  30783. var renderInlineHeader = function(spec, titleId, providersBackstage) {
  30784. return Container.sketch({
  30785. dom: fromHtml('<div class="tox-dialog__header"></div>'),
  30786. components: [
  30787. renderTitle(spec, Optional.some(titleId), providersBackstage),
  30788. renderDragHandle(),
  30789. renderClose(providersBackstage)
  30790. ],
  30791. containerBehaviours: derive$1([Dragging.config({
  30792. mode: "mouse",
  30793. blockerClass: "blocker",
  30794. getTarget: function(handle2) {
  30795. return closest$1(handle2, '[role="dialog"]').getOrDie();
  30796. },
  30797. snaps: {
  30798. getSnapPoints: function() {
  30799. return [];
  30800. },
  30801. leftAttr: "data-drag-left",
  30802. topAttr: "data-drag-top"
  30803. }
  30804. })])
  30805. });
  30806. };
  30807. var renderModalHeader = function(spec, providersBackstage) {
  30808. var pTitle = ModalDialog.parts.title(renderTitle(spec, Optional.none(), providersBackstage));
  30809. var pHandle = ModalDialog.parts.draghandle(renderDragHandle());
  30810. var pClose2 = ModalDialog.parts.close(renderClose(providersBackstage));
  30811. var components2 = [pTitle].concat(spec.draggable ? [pHandle] : []).concat([pClose2]);
  30812. return Container.sketch({
  30813. dom: fromHtml('<div class="tox-dialog__header"></div>'),
  30814. components: components2
  30815. });
  30816. };
  30817. var getHeader = function(title, backstage) {
  30818. return renderModalHeader({
  30819. title: backstage.shared.providers.translate(title),
  30820. draggable: backstage.dialog.isDraggableModal()
  30821. }, backstage.shared.providers);
  30822. };
  30823. var getBusySpec = function(message, bs, providers) {
  30824. return {
  30825. dom: {
  30826. tag: "div",
  30827. classes: ["tox-dialog__busy-spinner"],
  30828. attributes: { "aria-label": providers.translate(message) },
  30829. styles: {
  30830. left: "0px",
  30831. right: "0px",
  30832. bottom: "0px",
  30833. top: "0px",
  30834. position: "absolute"
  30835. }
  30836. },
  30837. behaviours: bs,
  30838. components: [{ dom: fromHtml('<div class="tox-spinner"><div></div><div></div><div></div></div>') }]
  30839. };
  30840. };
  30841. var getEventExtras = function(lazyDialog, providers, extra) {
  30842. return {
  30843. onClose: function() {
  30844. return extra.closeWindow();
  30845. },
  30846. onBlock: function(blockEvent) {
  30847. ModalDialog.setBusy(lazyDialog(), function(_comp, bs) {
  30848. return getBusySpec(blockEvent.message, bs, providers);
  30849. });
  30850. },
  30851. onUnblock: function() {
  30852. ModalDialog.setIdle(lazyDialog());
  30853. }
  30854. };
  30855. };
  30856. var renderModalDialog = function(spec, initialData, dialogEvents, backstage) {
  30857. var _a2;
  30858. var updateState = function(_comp, incoming) {
  30859. return Optional.some(incoming);
  30860. };
  30861. return build$1(renderDialog$1(__assign(__assign({}, spec), {
  30862. lazySink: backstage.shared.getSink,
  30863. extraBehaviours: __spreadArray([
  30864. Reflecting.config({
  30865. channel: dialogChannel,
  30866. updateState,
  30867. initialData
  30868. }),
  30869. RepresentingConfigs.memory({})
  30870. ], spec.extraBehaviours, true),
  30871. onEscape: function(comp) {
  30872. emit(comp, formCancelEvent);
  30873. },
  30874. dialogEvents,
  30875. eventOrder: (_a2 = {}, _a2[receive()] = [
  30876. Reflecting.name(),
  30877. Receiving.name()
  30878. ], _a2[attachedToDom()] = [
  30879. "scroll-lock",
  30880. Reflecting.name(),
  30881. "messages",
  30882. "dialog-events",
  30883. "alloy.base.behaviour"
  30884. ], _a2[detachedFromDom()] = [
  30885. "alloy.base.behaviour",
  30886. "dialog-events",
  30887. "messages",
  30888. Reflecting.name(),
  30889. "scroll-lock"
  30890. ], _a2)
  30891. })));
  30892. };
  30893. var mapMenuButtons = function(buttons) {
  30894. var mapItems = function(button2) {
  30895. var items = map$2(button2.items, function(item2) {
  30896. var cell = Cell(false);
  30897. return __assign(__assign({}, item2), { storage: cell });
  30898. });
  30899. return __assign(__assign({}, button2), { items });
  30900. };
  30901. return map$2(buttons, function(button2) {
  30902. if (button2.type === "menu") {
  30903. return mapItems(button2);
  30904. }
  30905. return button2;
  30906. });
  30907. };
  30908. var extractCellsToObject = function(buttons) {
  30909. return foldl(buttons, function(acc, button2) {
  30910. if (button2.type === "menu") {
  30911. var menuButton = button2;
  30912. return foldl(menuButton.items, function(innerAcc, item2) {
  30913. innerAcc[item2.name] = item2.storage;
  30914. return innerAcc;
  30915. }, acc);
  30916. }
  30917. return acc;
  30918. }, {});
  30919. };
  30920. var initCommonEvents = function(fireApiEvent, extras) {
  30921. return [
  30922. runWithTarget(focusin(), onFocus),
  30923. fireApiEvent(formCloseEvent, function(_api, spec) {
  30924. extras.onClose();
  30925. spec.onClose();
  30926. }),
  30927. fireApiEvent(formCancelEvent, function(api2, spec, _event, self2) {
  30928. spec.onCancel(api2);
  30929. emit(self2, formCloseEvent);
  30930. }),
  30931. run$1(formUnblockEvent, function(_c, _se) {
  30932. return extras.onUnblock();
  30933. }),
  30934. run$1(formBlockEvent, function(_c, se) {
  30935. return extras.onBlock(se.event);
  30936. })
  30937. ];
  30938. };
  30939. var initUrlDialog = function(getInstanceApi, extras) {
  30940. var fireApiEvent = function(eventName, f) {
  30941. return run$1(eventName, function(c, se) {
  30942. withSpec(c, function(spec, _c) {
  30943. f(getInstanceApi(), spec, se.event, c);
  30944. });
  30945. });
  30946. };
  30947. var withSpec = function(c, f) {
  30948. Reflecting.getState(c).get().each(function(currentDialog) {
  30949. f(currentDialog, c);
  30950. });
  30951. };
  30952. return __spreadArray(__spreadArray([], initCommonEvents(fireApiEvent, extras), true), [fireApiEvent(formActionEvent, function(api2, spec, event) {
  30953. spec.onAction(api2, { name: event.name });
  30954. })], false);
  30955. };
  30956. var initDialog = function(getInstanceApi, extras, getSink2) {
  30957. var fireApiEvent = function(eventName, f) {
  30958. return run$1(eventName, function(c, se) {
  30959. withSpec(c, function(spec, _c) {
  30960. f(getInstanceApi(), spec, se.event, c);
  30961. });
  30962. });
  30963. };
  30964. var withSpec = function(c, f) {
  30965. Reflecting.getState(c).get().each(function(currentDialogInit) {
  30966. f(currentDialogInit.internalDialog, c);
  30967. });
  30968. };
  30969. return __spreadArray(__spreadArray([], initCommonEvents(fireApiEvent, extras), true), [
  30970. fireApiEvent(formSubmitEvent, function(api2, spec) {
  30971. return spec.onSubmit(api2);
  30972. }),
  30973. fireApiEvent(formChangeEvent, function(api2, spec, event) {
  30974. spec.onChange(api2, { name: event.name });
  30975. }),
  30976. fireApiEvent(formActionEvent, function(api2, spec, event, component) {
  30977. var focusIn2 = function() {
  30978. return Keying.focusIn(component);
  30979. };
  30980. var isDisabled2 = function(focused) {
  30981. return has$1(focused, "disabled") || getOpt(focused, "aria-disabled").exists(function(val) {
  30982. return val === "true";
  30983. });
  30984. };
  30985. var rootNode = getRootNode(component.element);
  30986. var current = active(rootNode);
  30987. spec.onAction(api2, {
  30988. name: event.name,
  30989. value: event.value
  30990. });
  30991. active(rootNode).fold(focusIn2, function(focused) {
  30992. if (isDisabled2(focused)) {
  30993. focusIn2();
  30994. } else if (current.exists(function(cur) {
  30995. return contains(focused, cur) && isDisabled2(cur);
  30996. })) {
  30997. focusIn2();
  30998. } else {
  30999. getSink2().toOptional().filter(function(sink) {
  31000. return !contains(sink.element, focused);
  31001. }).each(focusIn2);
  31002. }
  31003. });
  31004. }),
  31005. fireApiEvent(formTabChangeEvent, function(api2, spec, event) {
  31006. spec.onTabChange(api2, {
  31007. newTabName: event.name,
  31008. oldTabName: event.oldName
  31009. });
  31010. }),
  31011. runOnDetached(function(component) {
  31012. var api2 = getInstanceApi();
  31013. Representing.setValue(component, api2.getData());
  31014. })
  31015. ], false);
  31016. };
  31017. var SilverDialogEvents = {
  31018. initUrlDialog,
  31019. initDialog
  31020. };
  31021. var makeButton = function(button2, backstage) {
  31022. return renderFooterButton(button2, button2.type, backstage);
  31023. };
  31024. var lookup = function(compInSystem, footerButtons, buttonName) {
  31025. return find$5(footerButtons, function(button2) {
  31026. return button2.name === buttonName;
  31027. }).bind(function(memButton) {
  31028. return memButton.memento.getOpt(compInSystem);
  31029. });
  31030. };
  31031. var renderComponents = function(_data, state) {
  31032. var footerButtons = state.map(function(s) {
  31033. return s.footerButtons;
  31034. }).getOr([]);
  31035. var buttonGroups = partition$3(footerButtons, function(button2) {
  31036. return button2.align === "start";
  31037. });
  31038. var makeGroup = function(edge2, buttons) {
  31039. return Container.sketch({
  31040. dom: {
  31041. tag: "div",
  31042. classes: ["tox-dialog__footer-" + edge2]
  31043. },
  31044. components: map$2(buttons, function(button2) {
  31045. return button2.memento.asSpec();
  31046. })
  31047. });
  31048. };
  31049. var startButtons = makeGroup("start", buttonGroups.pass);
  31050. var endButtons = makeGroup("end", buttonGroups.fail);
  31051. return [
  31052. startButtons,
  31053. endButtons
  31054. ];
  31055. };
  31056. var renderFooter = function(initSpec, backstage) {
  31057. var updateState = function(_comp, data) {
  31058. var footerButtons = map$2(data.buttons, function(button2) {
  31059. var memButton = record(makeButton(button2, backstage));
  31060. return {
  31061. name: button2.name,
  31062. align: button2.align,
  31063. memento: memButton
  31064. };
  31065. });
  31066. var lookupByName = function(compInSystem, buttonName) {
  31067. return lookup(compInSystem, footerButtons, buttonName);
  31068. };
  31069. return Optional.some({
  31070. lookupByName,
  31071. footerButtons
  31072. });
  31073. };
  31074. return {
  31075. dom: fromHtml('<div class="tox-dialog__footer"></div>'),
  31076. components: [],
  31077. behaviours: derive$1([Reflecting.config({
  31078. channel: footerChannel,
  31079. initialData: initSpec,
  31080. updateState,
  31081. renderComponents
  31082. })])
  31083. };
  31084. };
  31085. var renderInlineFooter = function(initSpec, backstage) {
  31086. return renderFooter(initSpec, backstage);
  31087. };
  31088. var renderModalFooter = function(initSpec, backstage) {
  31089. return ModalDialog.parts.footer(renderFooter(initSpec, backstage));
  31090. };
  31091. var getCompByName = function(access, name2) {
  31092. var root = access.getRoot();
  31093. if (root.getSystem().isConnected()) {
  31094. var form_1 = Composing.getCurrent(access.getFormWrapper()).getOr(access.getFormWrapper());
  31095. return Form.getField(form_1, name2).fold(function() {
  31096. var footer = access.getFooter();
  31097. var footerState = Reflecting.getState(footer);
  31098. return footerState.get().bind(function(f) {
  31099. return f.lookupByName(form_1, name2);
  31100. });
  31101. }, function(comp) {
  31102. return Optional.some(comp);
  31103. });
  31104. } else {
  31105. return Optional.none();
  31106. }
  31107. };
  31108. var validateData$1 = function(access, data) {
  31109. var root = access.getRoot();
  31110. return Reflecting.getState(root).get().map(function(dialogState) {
  31111. return getOrDie(asRaw("data", dialogState.dataValidator, data));
  31112. }).getOr(data);
  31113. };
  31114. var getDialogApi = function(access, doRedial, menuItemStates) {
  31115. var withRoot = function(f) {
  31116. var root = access.getRoot();
  31117. if (root.getSystem().isConnected()) {
  31118. f(root);
  31119. }
  31120. };
  31121. var getData2 = function() {
  31122. var root = access.getRoot();
  31123. var valueComp = root.getSystem().isConnected() ? access.getFormWrapper() : root;
  31124. var representedValues = Representing.getValue(valueComp);
  31125. var menuItemCurrentState = map$1(menuItemStates, function(cell) {
  31126. return cell.get();
  31127. });
  31128. return __assign(__assign({}, representedValues), menuItemCurrentState);
  31129. };
  31130. var setData = function(newData) {
  31131. withRoot(function(_) {
  31132. var prevData = instanceApi.getData();
  31133. var mergedData = __assign(__assign({}, prevData), newData);
  31134. var newInternalData = validateData$1(access, mergedData);
  31135. var form = access.getFormWrapper();
  31136. Representing.setValue(form, newInternalData);
  31137. each(menuItemStates, function(v, k) {
  31138. if (has$2(mergedData, k)) {
  31139. v.set(mergedData[k]);
  31140. }
  31141. });
  31142. });
  31143. };
  31144. var disable2 = function(name2) {
  31145. getCompByName(access, name2).each(Disabling.disable);
  31146. };
  31147. var enable2 = function(name2) {
  31148. getCompByName(access, name2).each(Disabling.enable);
  31149. };
  31150. var focus2 = function(name2) {
  31151. getCompByName(access, name2).each(Focusing.focus);
  31152. };
  31153. var block2 = function(message) {
  31154. if (!isString(message)) {
  31155. throw new Error("The dialogInstanceAPI.block function should be passed a blocking message of type string as an argument");
  31156. }
  31157. withRoot(function(root) {
  31158. emitWith(root, formBlockEvent, { message });
  31159. });
  31160. };
  31161. var unblock2 = function() {
  31162. withRoot(function(root) {
  31163. emit(root, formUnblockEvent);
  31164. });
  31165. };
  31166. var showTab2 = function(name2) {
  31167. withRoot(function(_) {
  31168. var body2 = access.getBody();
  31169. var bodyState = Reflecting.getState(body2);
  31170. if (bodyState.get().exists(function(b2) {
  31171. return b2.isTabPanel();
  31172. })) {
  31173. Composing.getCurrent(body2).each(function(tabSection) {
  31174. TabSection.showTab(tabSection, name2);
  31175. });
  31176. }
  31177. });
  31178. };
  31179. var redial = function(d) {
  31180. withRoot(function(root) {
  31181. var dialogInit = doRedial(d);
  31182. root.getSystem().broadcastOn([dialogChannel], dialogInit);
  31183. root.getSystem().broadcastOn([titleChannel], dialogInit.internalDialog);
  31184. root.getSystem().broadcastOn([bodyChannel], dialogInit.internalDialog);
  31185. root.getSystem().broadcastOn([footerChannel], dialogInit.internalDialog);
  31186. instanceApi.setData(dialogInit.initialData);
  31187. });
  31188. };
  31189. var close2 = function() {
  31190. withRoot(function(root) {
  31191. emit(root, formCloseEvent);
  31192. });
  31193. };
  31194. var instanceApi = {
  31195. getData: getData2,
  31196. setData,
  31197. disable: disable2,
  31198. enable: enable2,
  31199. focus: focus2,
  31200. block: block2,
  31201. unblock: unblock2,
  31202. showTab: showTab2,
  31203. redial,
  31204. close: close2
  31205. };
  31206. return instanceApi;
  31207. };
  31208. var getDialogSizeClasses = function(size) {
  31209. switch (size) {
  31210. case "large":
  31211. return ["tox-dialog--width-lg"];
  31212. case "medium":
  31213. return ["tox-dialog--width-md"];
  31214. default:
  31215. return [];
  31216. }
  31217. };
  31218. var renderDialog = function(dialogInit, extra, backstage) {
  31219. var header = getHeader(dialogInit.internalDialog.title, backstage);
  31220. var body2 = renderModalBody({ body: dialogInit.internalDialog.body }, backstage);
  31221. var storagedMenuButtons = mapMenuButtons(dialogInit.internalDialog.buttons);
  31222. var objOfCells = extractCellsToObject(storagedMenuButtons);
  31223. var footer = renderModalFooter({ buttons: storagedMenuButtons }, backstage);
  31224. var dialogEvents = SilverDialogEvents.initDialog(function() {
  31225. return instanceApi;
  31226. }, getEventExtras(function() {
  31227. return dialog;
  31228. }, backstage.shared.providers, extra), backstage.shared.getSink);
  31229. var dialogSize = getDialogSizeClasses(dialogInit.internalDialog.size);
  31230. var spec = {
  31231. header,
  31232. body: body2,
  31233. footer: Optional.some(footer),
  31234. extraClasses: dialogSize,
  31235. extraBehaviours: [],
  31236. extraStyles: {}
  31237. };
  31238. var dialog = renderModalDialog(spec, dialogInit, dialogEvents, backstage);
  31239. var modalAccess = function() {
  31240. var getForm = function() {
  31241. var outerForm = ModalDialog.getBody(dialog);
  31242. return Composing.getCurrent(outerForm).getOr(outerForm);
  31243. };
  31244. return {
  31245. getRoot: constant$1(dialog),
  31246. getBody: function() {
  31247. return ModalDialog.getBody(dialog);
  31248. },
  31249. getFooter: function() {
  31250. return ModalDialog.getFooter(dialog);
  31251. },
  31252. getFormWrapper: getForm
  31253. };
  31254. }();
  31255. var instanceApi = getDialogApi(modalAccess, extra.redial, objOfCells);
  31256. return {
  31257. dialog,
  31258. instanceApi
  31259. };
  31260. };
  31261. var renderInlineDialog = function(dialogInit, extra, backstage, ariaAttrs) {
  31262. var _a2, _b;
  31263. var dialogLabelId = generate$6("dialog-label");
  31264. var dialogContentId = generate$6("dialog-content");
  31265. var updateState = function(_comp, incoming) {
  31266. return Optional.some(incoming);
  31267. };
  31268. var memHeader = record(renderInlineHeader({
  31269. title: dialogInit.internalDialog.title,
  31270. draggable: true
  31271. }, dialogLabelId, backstage.shared.providers));
  31272. var memBody = record(renderInlineBody({ body: dialogInit.internalDialog.body }, dialogContentId, backstage, ariaAttrs));
  31273. var storagedMenuButtons = mapMenuButtons(dialogInit.internalDialog.buttons);
  31274. var objOfCells = extractCellsToObject(storagedMenuButtons);
  31275. var memFooter = record(renderInlineFooter({ buttons: storagedMenuButtons }, backstage));
  31276. var dialogEvents = SilverDialogEvents.initDialog(function() {
  31277. return instanceApi;
  31278. }, {
  31279. onBlock: function(event) {
  31280. Blocking.block(dialog, function(_comp, bs) {
  31281. return getBusySpec(event.message, bs, backstage.shared.providers);
  31282. });
  31283. },
  31284. onUnblock: function() {
  31285. Blocking.unblock(dialog);
  31286. },
  31287. onClose: function() {
  31288. return extra.closeWindow();
  31289. }
  31290. }, backstage.shared.getSink);
  31291. var dialog = build$1({
  31292. dom: {
  31293. tag: "div",
  31294. classes: [
  31295. "tox-dialog",
  31296. "tox-dialog-inline"
  31297. ],
  31298. attributes: (_a2 = { role: "dialog" }, _a2["aria-labelledby"] = dialogLabelId, _a2["aria-describedby"] = dialogContentId, _a2)
  31299. },
  31300. eventOrder: (_b = {}, _b[receive()] = [
  31301. Reflecting.name(),
  31302. Receiving.name()
  31303. ], _b[execute$5()] = ["execute-on-form"], _b[attachedToDom()] = [
  31304. "reflecting",
  31305. "execute-on-form"
  31306. ], _b),
  31307. behaviours: derive$1([
  31308. Keying.config({
  31309. mode: "cyclic",
  31310. onEscape: function(c) {
  31311. emit(c, formCloseEvent);
  31312. return Optional.some(true);
  31313. },
  31314. useTabstopAt: function(elem) {
  31315. return !isPseudoStop(elem) && (name$2(elem) !== "button" || get$d(elem, "disabled") !== "disabled");
  31316. }
  31317. }),
  31318. Reflecting.config({
  31319. channel: dialogChannel,
  31320. updateState,
  31321. initialData: dialogInit
  31322. }),
  31323. Focusing.config({}),
  31324. config("execute-on-form", dialogEvents.concat([runOnSource(focusin(), function(comp, _se) {
  31325. Keying.focusIn(comp);
  31326. })])),
  31327. Blocking.config({
  31328. getRoot: function() {
  31329. return Optional.some(dialog);
  31330. }
  31331. }),
  31332. Replacing.config({}),
  31333. RepresentingConfigs.memory({})
  31334. ]),
  31335. components: [
  31336. memHeader.asSpec(),
  31337. memBody.asSpec(),
  31338. memFooter.asSpec()
  31339. ]
  31340. });
  31341. var instanceApi = getDialogApi({
  31342. getRoot: constant$1(dialog),
  31343. getFooter: function() {
  31344. return memFooter.get(dialog);
  31345. },
  31346. getBody: function() {
  31347. return memBody.get(dialog);
  31348. },
  31349. getFormWrapper: function() {
  31350. var body2 = memBody.get(dialog);
  31351. return Composing.getCurrent(body2).getOr(body2);
  31352. }
  31353. }, extra.redial, objOfCells);
  31354. return {
  31355. dialog,
  31356. instanceApi
  31357. };
  31358. };
  31359. var global$1 = tinymce.util.Tools.resolve("tinymce.util.URI");
  31360. var getUrlDialogApi = function(root) {
  31361. var withRoot = function(f) {
  31362. if (root.getSystem().isConnected()) {
  31363. f(root);
  31364. }
  31365. };
  31366. var block2 = function(message) {
  31367. if (!isString(message)) {
  31368. throw new Error("The urlDialogInstanceAPI.block function should be passed a blocking message of type string as an argument");
  31369. }
  31370. withRoot(function(root2) {
  31371. emitWith(root2, formBlockEvent, { message });
  31372. });
  31373. };
  31374. var unblock2 = function() {
  31375. withRoot(function(root2) {
  31376. emit(root2, formUnblockEvent);
  31377. });
  31378. };
  31379. var close2 = function() {
  31380. withRoot(function(root2) {
  31381. emit(root2, formCloseEvent);
  31382. });
  31383. };
  31384. var sendMessage = function(data) {
  31385. withRoot(function(root2) {
  31386. root2.getSystem().broadcastOn([bodySendMessageChannel], data);
  31387. });
  31388. };
  31389. return {
  31390. block: block2,
  31391. unblock: unblock2,
  31392. close: close2,
  31393. sendMessage
  31394. };
  31395. };
  31396. var SUPPORTED_MESSAGE_ACTIONS = [
  31397. "insertContent",
  31398. "setContent",
  31399. "execCommand",
  31400. "close",
  31401. "block",
  31402. "unblock"
  31403. ];
  31404. var isSupportedMessage = function(data) {
  31405. return isObject(data) && SUPPORTED_MESSAGE_ACTIONS.indexOf(data.mceAction) !== -1;
  31406. };
  31407. var isCustomMessage = function(data) {
  31408. return !isSupportedMessage(data) && isObject(data) && has$2(data, "mceAction");
  31409. };
  31410. var handleMessage = function(editor, api2, data) {
  31411. switch (data.mceAction) {
  31412. case "insertContent":
  31413. editor.insertContent(data.content);
  31414. break;
  31415. case "setContent":
  31416. editor.setContent(data.content);
  31417. break;
  31418. case "execCommand":
  31419. var ui = isBoolean(data.ui) ? data.ui : false;
  31420. editor.execCommand(data.cmd, ui, data.value);
  31421. break;
  31422. case "close":
  31423. api2.close();
  31424. break;
  31425. case "block":
  31426. api2.block(data.message);
  31427. break;
  31428. case "unblock":
  31429. api2.unblock();
  31430. break;
  31431. }
  31432. };
  31433. var renderUrlDialog = function(internalDialog, extra, editor, backstage) {
  31434. var _a2;
  31435. var header = getHeader(internalDialog.title, backstage);
  31436. var body2 = renderIframeBody(internalDialog);
  31437. var footer = internalDialog.buttons.bind(function(buttons) {
  31438. if (buttons.length === 0) {
  31439. return Optional.none();
  31440. } else {
  31441. return Optional.some(renderModalFooter({ buttons }, backstage));
  31442. }
  31443. });
  31444. var dialogEvents = SilverDialogEvents.initUrlDialog(function() {
  31445. return instanceApi;
  31446. }, getEventExtras(function() {
  31447. return dialog;
  31448. }, backstage.shared.providers, extra));
  31449. var styles = __assign(__assign({}, internalDialog.height.fold(function() {
  31450. return {};
  31451. }, function(height2) {
  31452. return {
  31453. "height": height2 + "px",
  31454. "max-height": height2 + "px"
  31455. };
  31456. })), internalDialog.width.fold(function() {
  31457. return {};
  31458. }, function(width2) {
  31459. return {
  31460. "width": width2 + "px",
  31461. "max-width": width2 + "px"
  31462. };
  31463. }));
  31464. var classes2 = internalDialog.width.isNone() && internalDialog.height.isNone() ? ["tox-dialog--width-lg"] : [];
  31465. var iframeUri = new global$1(internalDialog.url, { base_uri: new global$1(window.location.href) });
  31466. var iframeDomain = iframeUri.protocol + "://" + iframeUri.host + (iframeUri.port ? ":" + iframeUri.port : "");
  31467. var messageHandlerUnbinder = unbindable();
  31468. var extraBehaviours = [
  31469. config("messages", [
  31470. runOnAttached(function() {
  31471. var unbind2 = bind(SugarElement.fromDom(window), "message", function(e) {
  31472. if (iframeUri.isSameOrigin(new global$1(e.raw.origin))) {
  31473. var data = e.raw.data;
  31474. if (isSupportedMessage(data)) {
  31475. handleMessage(editor, instanceApi, data);
  31476. } else if (isCustomMessage(data)) {
  31477. internalDialog.onMessage(instanceApi, data);
  31478. }
  31479. }
  31480. });
  31481. messageHandlerUnbinder.set(unbind2);
  31482. }),
  31483. runOnDetached(messageHandlerUnbinder.clear)
  31484. ]),
  31485. Receiving.config({
  31486. channels: (_a2 = {}, _a2[bodySendMessageChannel] = {
  31487. onReceive: function(comp, data) {
  31488. descendant(comp.element, "iframe").each(function(iframeEle) {
  31489. var iframeWin = iframeEle.dom.contentWindow;
  31490. iframeWin.postMessage(data, iframeDomain);
  31491. });
  31492. }
  31493. }, _a2)
  31494. })
  31495. ];
  31496. var spec = {
  31497. header,
  31498. body: body2,
  31499. footer,
  31500. extraClasses: classes2,
  31501. extraBehaviours,
  31502. extraStyles: styles
  31503. };
  31504. var dialog = renderModalDialog(spec, internalDialog, dialogEvents, backstage);
  31505. var instanceApi = getUrlDialogApi(dialog);
  31506. return {
  31507. dialog,
  31508. instanceApi
  31509. };
  31510. };
  31511. var setup$2 = function(extras) {
  31512. var sharedBackstage = extras.backstage.shared;
  31513. var open2 = function(message, callback) {
  31514. var closeDialog = function() {
  31515. ModalDialog.hide(alertDialog);
  31516. callback();
  31517. };
  31518. var memFooterClose = record(renderFooterButton({
  31519. name: "close-alert",
  31520. text: "OK",
  31521. primary: true,
  31522. align: "end",
  31523. disabled: false,
  31524. icon: Optional.none()
  31525. }, "cancel", extras.backstage));
  31526. var titleSpec = pUntitled();
  31527. var closeSpec = pClose(closeDialog, sharedBackstage.providers);
  31528. var alertDialog = build$1(renderDialog$1({
  31529. lazySink: function() {
  31530. return sharedBackstage.getSink();
  31531. },
  31532. header: hiddenHeader(titleSpec, closeSpec),
  31533. body: pBodyMessage(message, sharedBackstage.providers),
  31534. footer: Optional.some(pFooter(pFooterGroup([], [memFooterClose.asSpec()]))),
  31535. onEscape: closeDialog,
  31536. extraClasses: ["tox-alert-dialog"],
  31537. extraBehaviours: [],
  31538. extraStyles: {},
  31539. dialogEvents: [run$1(formCancelEvent, closeDialog)],
  31540. eventOrder: {}
  31541. }));
  31542. ModalDialog.show(alertDialog);
  31543. var footerCloseButton = memFooterClose.get(alertDialog);
  31544. Focusing.focus(footerCloseButton);
  31545. };
  31546. return { open: open2 };
  31547. };
  31548. var setup$1 = function(extras) {
  31549. var sharedBackstage = extras.backstage.shared;
  31550. var open2 = function(message, callback) {
  31551. var closeDialog = function(state) {
  31552. ModalDialog.hide(confirmDialog);
  31553. callback(state);
  31554. };
  31555. var memFooterYes = record(renderFooterButton({
  31556. name: "yes",
  31557. text: "Yes",
  31558. primary: true,
  31559. align: "end",
  31560. disabled: false,
  31561. icon: Optional.none()
  31562. }, "submit", extras.backstage));
  31563. var footerNo = renderFooterButton({
  31564. name: "no",
  31565. text: "No",
  31566. primary: false,
  31567. align: "end",
  31568. disabled: false,
  31569. icon: Optional.none()
  31570. }, "cancel", extras.backstage);
  31571. var titleSpec = pUntitled();
  31572. var closeSpec = pClose(function() {
  31573. return closeDialog(false);
  31574. }, sharedBackstage.providers);
  31575. var confirmDialog = build$1(renderDialog$1({
  31576. lazySink: function() {
  31577. return sharedBackstage.getSink();
  31578. },
  31579. header: hiddenHeader(titleSpec, closeSpec),
  31580. body: pBodyMessage(message, sharedBackstage.providers),
  31581. footer: Optional.some(pFooter(pFooterGroup([], [
  31582. footerNo,
  31583. memFooterYes.asSpec()
  31584. ]))),
  31585. onEscape: function() {
  31586. return closeDialog(false);
  31587. },
  31588. extraClasses: ["tox-confirm-dialog"],
  31589. extraBehaviours: [],
  31590. extraStyles: {},
  31591. dialogEvents: [
  31592. run$1(formCancelEvent, function() {
  31593. return closeDialog(false);
  31594. }),
  31595. run$1(formSubmitEvent, function() {
  31596. return closeDialog(true);
  31597. })
  31598. ],
  31599. eventOrder: {}
  31600. }));
  31601. ModalDialog.show(confirmDialog);
  31602. var footerYesButton = memFooterYes.get(confirmDialog);
  31603. Focusing.focus(footerYesButton);
  31604. };
  31605. return { open: open2 };
  31606. };
  31607. var validateData = function(data, validator) {
  31608. return getOrDie(asRaw("data", validator, data));
  31609. };
  31610. var isAlertOrConfirmDialog = function(target) {
  31611. return closest(target, ".tox-alert-dialog") || closest(target, ".tox-confirm-dialog");
  31612. };
  31613. var inlineAdditionalBehaviours = function(editor, isStickyToolbar2, isToolbarLocationTop) {
  31614. if (isStickyToolbar2 && isToolbarLocationTop) {
  31615. return [];
  31616. } else {
  31617. return [Docking.config({
  31618. contextual: {
  31619. lazyContext: function() {
  31620. return Optional.some(box$1(SugarElement.fromDom(editor.getContentAreaContainer())));
  31621. },
  31622. fadeInClass: "tox-dialog-dock-fadein",
  31623. fadeOutClass: "tox-dialog-dock-fadeout",
  31624. transitionClass: "tox-dialog-dock-transition"
  31625. },
  31626. modes: ["top"]
  31627. })];
  31628. }
  31629. };
  31630. var setup = function(extras) {
  31631. var backstage = extras.backstage;
  31632. var editor = extras.editor;
  31633. var isStickyToolbar$1 = isStickyToolbar(editor);
  31634. var alertDialog = setup$2(extras);
  31635. var confirmDialog = setup$1(extras);
  31636. var open2 = function(config2, params, closeWindow) {
  31637. if (params !== void 0 && params.inline === "toolbar") {
  31638. return openInlineDialog(config2, backstage.shared.anchors.inlineDialog(), closeWindow, params.ariaAttrs);
  31639. } else if (params !== void 0 && params.inline === "cursor") {
  31640. return openInlineDialog(config2, backstage.shared.anchors.cursor(), closeWindow, params.ariaAttrs);
  31641. } else {
  31642. return openModalDialog(config2, closeWindow);
  31643. }
  31644. };
  31645. var openUrl = function(config2, closeWindow) {
  31646. return openModalUrlDialog(config2, closeWindow);
  31647. };
  31648. var openModalUrlDialog = function(config2, closeWindow) {
  31649. var factory2 = function(contents2) {
  31650. var dialog = renderUrlDialog(contents2, {
  31651. closeWindow: function() {
  31652. ModalDialog.hide(dialog.dialog);
  31653. closeWindow(dialog.instanceApi);
  31654. }
  31655. }, editor, backstage);
  31656. ModalDialog.show(dialog.dialog);
  31657. return dialog.instanceApi;
  31658. };
  31659. return DialogManager.openUrl(factory2, config2);
  31660. };
  31661. var openModalDialog = function(config2, closeWindow) {
  31662. var factory2 = function(contents2, internalInitialData, dataValidator) {
  31663. var initialData = internalInitialData;
  31664. var dialogInit = {
  31665. dataValidator,
  31666. initialData,
  31667. internalDialog: contents2
  31668. };
  31669. var dialog = renderDialog(dialogInit, {
  31670. redial: DialogManager.redial,
  31671. closeWindow: function() {
  31672. ModalDialog.hide(dialog.dialog);
  31673. closeWindow(dialog.instanceApi);
  31674. }
  31675. }, backstage);
  31676. ModalDialog.show(dialog.dialog);
  31677. dialog.instanceApi.setData(initialData);
  31678. return dialog.instanceApi;
  31679. };
  31680. return DialogManager.open(factory2, config2);
  31681. };
  31682. var openInlineDialog = function(config$1, anchor2, closeWindow, ariaAttrs) {
  31683. var factory2 = function(contents2, internalInitialData, dataValidator) {
  31684. var initialData = validateData(internalInitialData, dataValidator);
  31685. var inlineDialog = value$1();
  31686. var isToolbarLocationTop = backstage.shared.header.isPositionedAtTop();
  31687. var dialogInit = {
  31688. dataValidator,
  31689. initialData,
  31690. internalDialog: contents2
  31691. };
  31692. var refreshDocking = function() {
  31693. return inlineDialog.on(function(dialog) {
  31694. InlineView.reposition(dialog);
  31695. Docking.refresh(dialog);
  31696. });
  31697. };
  31698. var dialogUi = renderInlineDialog(dialogInit, {
  31699. redial: DialogManager.redial,
  31700. closeWindow: function() {
  31701. inlineDialog.on(InlineView.hide);
  31702. editor.off("ResizeEditor", refreshDocking);
  31703. inlineDialog.clear();
  31704. closeWindow(dialogUi.instanceApi);
  31705. }
  31706. }, backstage, ariaAttrs);
  31707. var inlineDialogComp = build$1(InlineView.sketch(__assign(__assign({
  31708. lazySink: backstage.shared.getSink,
  31709. dom: {
  31710. tag: "div",
  31711. classes: []
  31712. },
  31713. fireDismissalEventInstead: {}
  31714. }, isToolbarLocationTop ? {} : { fireRepositionEventInstead: {} }), {
  31715. inlineBehaviours: derive$1(__spreadArray([config("window-manager-inline-events", [run$1(dismissRequested(), function(_comp, _se) {
  31716. emit(dialogUi.dialog, formCancelEvent);
  31717. })])], inlineAdditionalBehaviours(editor, isStickyToolbar$1, isToolbarLocationTop), true)),
  31718. isExtraPart: function(_comp, target) {
  31719. return isAlertOrConfirmDialog(target);
  31720. }
  31721. })));
  31722. inlineDialog.set(inlineDialogComp);
  31723. InlineView.showWithin(inlineDialogComp, premade(dialogUi.dialog), { anchor: anchor2 }, Optional.some(body()));
  31724. if (!isStickyToolbar$1 || !isToolbarLocationTop) {
  31725. Docking.refresh(inlineDialogComp);
  31726. editor.on("ResizeEditor", refreshDocking);
  31727. }
  31728. dialogUi.instanceApi.setData(initialData);
  31729. Keying.focusIn(dialogUi.dialog);
  31730. return dialogUi.instanceApi;
  31731. };
  31732. return DialogManager.open(factory2, config$1);
  31733. };
  31734. var confirm = function(message, callback) {
  31735. confirmDialog.open(message, function(state) {
  31736. callback(state);
  31737. });
  31738. };
  31739. var alert = function(message, callback) {
  31740. alertDialog.open(message, function() {
  31741. callback();
  31742. });
  31743. };
  31744. var close2 = function(instanceApi) {
  31745. instanceApi.close();
  31746. };
  31747. return {
  31748. open: open2,
  31749. openUrl,
  31750. alert,
  31751. close: close2,
  31752. confirm
  31753. };
  31754. };
  31755. function Theme() {
  31756. global$g.add("silver", function(editor) {
  31757. var _a2 = setup$3(editor), uiMothership = _a2.uiMothership, backstage = _a2.backstage, renderUI = _a2.renderUI, getUi = _a2.getUi;
  31758. Autocompleter.register(editor, backstage.shared);
  31759. var windowMgr = setup({
  31760. editor,
  31761. backstage
  31762. });
  31763. return {
  31764. renderUI,
  31765. getWindowManagerImpl: constant$1(windowMgr),
  31766. getNotificationManagerImpl: function() {
  31767. return NotificationManagerImpl(editor, { backstage }, uiMothership);
  31768. },
  31769. ui: getUi()
  31770. };
  31771. });
  31772. }
  31773. Theme();
  31774. })();
  31775. }
  31776. });
  31777. // node_modules/tinymce/themes/silver/index.js
  31778. var require_silver = __commonJS({
  31779. "node_modules/tinymce/themes/silver/index.js"() {
  31780. init_define_APP_INFO();
  31781. require_theme();
  31782. }
  31783. });
  31784. // dep:tinymce_themes_silver
  31785. init_define_APP_INFO();
  31786. var tinymce_themes_silver_default = require_silver();
  31787. export {
  31788. tinymce_themes_silver_default as default
  31789. };
  31790. //# sourceMappingURL=tinymce_themes_silver.js.map