tinymce_themes_silver.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/themes/silver/theme.js
  5. var require_theme = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/themes/silver/theme.js"() {
  7. (function() {
  8. "use strict";
  9. var typeOf = function(x) {
  10. var t2 = typeof x;
  11. if (x === null) {
  12. return "null";
  13. } else if (t2 === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  14. return "array";
  15. } else if (t2 === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  16. return "string";
  17. } else {
  18. return t2;
  19. }
  20. };
  21. var isType$1 = function(type2) {
  22. return function(value2) {
  23. return typeOf(value2) === type2;
  24. };
  25. };
  26. var isSimpleType = function(type2) {
  27. return function(value2) {
  28. return typeof value2 === type2;
  29. };
  30. };
  31. var eq$1 = function(t2) {
  32. return function(a) {
  33. return t2 === a;
  34. };
  35. };
  36. var isString = isType$1("string");
  37. var isObject = isType$1("object");
  38. var isArray = isType$1("array");
  39. var isNull = eq$1(null);
  40. var isBoolean = isSimpleType("boolean");
  41. var isUndefined = eq$1(void 0);
  42. var isNullable = function(a) {
  43. return a === null || a === void 0;
  44. };
  45. var isNonNullable = function(a) {
  46. return !isNullable(a);
  47. };
  48. var isFunction = isSimpleType("function");
  49. var isNumber = isSimpleType("number");
  50. var isArrayOf = function(value2, pred) {
  51. if (isArray(value2)) {
  52. for (var i = 0, len = value2.length; i < len; ++i) {
  53. if (!pred(value2[i])) {
  54. return false;
  55. }
  56. }
  57. return true;
  58. }
  59. return false;
  60. };
  61. var noop = function() {
  62. };
  63. var noarg = function(f) {
  64. return function() {
  65. return f();
  66. };
  67. };
  68. var compose = function(fa, fb) {
  69. return function() {
  70. var args = [];
  71. for (var _i = 0; _i < arguments.length; _i++) {
  72. args[_i] = arguments[_i];
  73. }
  74. return fa(fb.apply(null, args));
  75. };
  76. };
  77. var compose1 = function(fbc, fab) {
  78. return function(a) {
  79. return fbc(fab(a));
  80. };
  81. };
  82. var constant$1 = function(value2) {
  83. return function() {
  84. return value2;
  85. };
  86. };
  87. var identity$1 = function(x) {
  88. return x;
  89. };
  90. var tripleEquals = function(a, b2) {
  91. return a === b2;
  92. };
  93. function curry(fn) {
  94. var initialArgs = [];
  95. for (var _i = 1; _i < arguments.length; _i++) {
  96. initialArgs[_i - 1] = arguments[_i];
  97. }
  98. return function() {
  99. var restArgs = [];
  100. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  101. restArgs[_i2] = arguments[_i2];
  102. }
  103. var all2 = initialArgs.concat(restArgs);
  104. return fn.apply(null, all2);
  105. };
  106. }
  107. var not = function(f) {
  108. return function(t2) {
  109. return !f(t2);
  110. };
  111. };
  112. var die = function(msg) {
  113. return function() {
  114. throw new Error(msg);
  115. };
  116. };
  117. var never = constant$1(false);
  118. var always = constant$1(true);
  119. var global$g = tinymce.util.Tools.resolve("tinymce.ThemeManager");
  120. var __assign = function() {
  121. __assign = Object.assign || function __assign2(t2) {
  122. for (var s, i = 1, n = arguments.length; i < n; i++) {
  123. s = arguments[i];
  124. for (var p in s)
  125. if (Object.prototype.hasOwnProperty.call(s, p))
  126. t2[p] = s[p];
  127. }
  128. return t2;
  129. };
  130. return __assign.apply(this, arguments);
  131. };
  132. function __rest(s, e) {
  133. var t2 = {};
  134. for (var p in s)
  135. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  136. t2[p] = s[p];
  137. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  138. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  139. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  140. t2[p[i]] = s[p[i]];
  141. }
  142. return t2;
  143. }
  144. function __spreadArray(to2, from2, pack) {
  145. if (pack || arguments.length === 2)
  146. for (var i = 0, l2 = from2.length, ar; i < l2; i++) {
  147. if (ar || !(i in from2)) {
  148. if (!ar)
  149. ar = Array.prototype.slice.call(from2, 0, i);
  150. ar[i] = from2[i];
  151. }
  152. }
  153. return to2.concat(ar || Array.prototype.slice.call(from2));
  154. }
  155. var none = function() {
  156. return NONE;
  157. };
  158. var NONE = function() {
  159. var call = function(thunk2) {
  160. return thunk2();
  161. };
  162. var id = identity$1;
  163. var me = {
  164. fold: function(n, _s) {
  165. return n();
  166. },
  167. isSome: never,
  168. isNone: always,
  169. getOr: id,
  170. getOrThunk: call,
  171. getOrDie: function(msg) {
  172. throw new Error(msg || "error: getOrDie called on none.");
  173. },
  174. getOrNull: constant$1(null),
  175. getOrUndefined: constant$1(void 0),
  176. or: id,
  177. orThunk: call,
  178. map: none,
  179. each: noop,
  180. bind: none,
  181. exists: never,
  182. forall: always,
  183. filter: function() {
  184. return none();
  185. },
  186. toArray: function() {
  187. return [];
  188. },
  189. toString: constant$1("none()")
  190. };
  191. return me;
  192. }();
  193. var some = function(a) {
  194. var constant_a = constant$1(a);
  195. var self2 = function() {
  196. return me;
  197. };
  198. var bind2 = function(f) {
  199. return f(a);
  200. };
  201. var me = {
  202. fold: function(n, s) {
  203. return s(a);
  204. },
  205. isSome: always,
  206. isNone: never,
  207. getOr: constant_a,
  208. getOrThunk: constant_a,
  209. getOrDie: constant_a,
  210. getOrNull: constant_a,
  211. getOrUndefined: constant_a,
  212. or: self2,
  213. orThunk: self2,
  214. map: function(f) {
  215. return some(f(a));
  216. },
  217. each: function(f) {
  218. f(a);
  219. },
  220. bind: bind2,
  221. exists: bind2,
  222. forall: bind2,
  223. filter: function(f) {
  224. return f(a) ? me : NONE;
  225. },
  226. toArray: function() {
  227. return [a];
  228. },
  229. toString: function() {
  230. return "some(" + a + ")";
  231. }
  232. };
  233. return me;
  234. };
  235. var from$1 = function(value2) {
  236. return value2 === null || value2 === void 0 ? NONE : some(value2);
  237. };
  238. var Optional = {
  239. some,
  240. none,
  241. from: from$1
  242. };
  243. var nativeSlice = Array.prototype.slice;
  244. var nativeIndexOf = Array.prototype.indexOf;
  245. var nativePush = Array.prototype.push;
  246. var rawIndexOf = function(ts, t2) {
  247. return nativeIndexOf.call(ts, t2);
  248. };
  249. var indexOf = function(xs, x) {
  250. var r2 = rawIndexOf(xs, x);
  251. return r2 === -1 ? Optional.none() : Optional.some(r2);
  252. };
  253. var contains$2 = function(xs, x) {
  254. return rawIndexOf(xs, x) > -1;
  255. };
  256. var exists = function(xs, pred) {
  257. for (var i = 0, len = xs.length; i < len; i++) {
  258. var x = xs[i];
  259. if (pred(x, i)) {
  260. return true;
  261. }
  262. }
  263. return false;
  264. };
  265. var range$2 = function(num, f) {
  266. var r2 = [];
  267. for (var i = 0; i < num; i++) {
  268. r2.push(f(i));
  269. }
  270. return r2;
  271. };
  272. var chunk$1 = function(array, size) {
  273. var r2 = [];
  274. for (var i = 0; i < array.length; i += size) {
  275. var s = nativeSlice.call(array, i, i + size);
  276. r2.push(s);
  277. }
  278. return r2;
  279. };
  280. var map$2 = function(xs, f) {
  281. var len = xs.length;
  282. var r2 = new Array(len);
  283. for (var i = 0; i < len; i++) {
  284. var x = xs[i];
  285. r2[i] = f(x, i);
  286. }
  287. return r2;
  288. };
  289. var each$1 = function(xs, f) {
  290. for (var i = 0, len = xs.length; i < len; i++) {
  291. var x = xs[i];
  292. f(x, i);
  293. }
  294. };
  295. var eachr = function(xs, f) {
  296. for (var i = xs.length - 1; i >= 0; i--) {
  297. var x = xs[i];
  298. f(x, i);
  299. }
  300. };
  301. var partition$3 = function(xs, pred) {
  302. var pass = [];
  303. var fail = [];
  304. for (var i = 0, len = xs.length; i < len; i++) {
  305. var x = xs[i];
  306. var arr = pred(x, i) ? pass : fail;
  307. arr.push(x);
  308. }
  309. return {
  310. pass,
  311. fail
  312. };
  313. };
  314. var filter$2 = function(xs, pred) {
  315. var r2 = [];
  316. for (var i = 0, len = xs.length; i < len; i++) {
  317. var x = xs[i];
  318. if (pred(x, i)) {
  319. r2.push(x);
  320. }
  321. }
  322. return r2;
  323. };
  324. var foldr = function(xs, f, acc) {
  325. eachr(xs, function(x, i) {
  326. acc = f(acc, x, i);
  327. });
  328. return acc;
  329. };
  330. var foldl = function(xs, f, acc) {
  331. each$1(xs, function(x, i) {
  332. acc = f(acc, x, i);
  333. });
  334. return acc;
  335. };
  336. var findUntil = function(xs, pred, until) {
  337. for (var i = 0, len = xs.length; i < len; i++) {
  338. var x = xs[i];
  339. if (pred(x, i)) {
  340. return Optional.some(x);
  341. } else if (until(x, i)) {
  342. break;
  343. }
  344. }
  345. return Optional.none();
  346. };
  347. var find$5 = function(xs, pred) {
  348. return findUntil(xs, pred, never);
  349. };
  350. var findIndex$1 = function(xs, pred) {
  351. for (var i = 0, len = xs.length; i < len; i++) {
  352. var x = xs[i];
  353. if (pred(x, i)) {
  354. return Optional.some(i);
  355. }
  356. }
  357. return Optional.none();
  358. };
  359. var flatten = function(xs) {
  360. var r2 = [];
  361. for (var i = 0, len = xs.length; i < len; ++i) {
  362. if (!isArray(xs[i])) {
  363. throw new Error("Arr.flatten item " + i + " was not an array, input: " + xs);
  364. }
  365. nativePush.apply(r2, xs[i]);
  366. }
  367. return r2;
  368. };
  369. var bind$3 = function(xs, f) {
  370. return flatten(map$2(xs, f));
  371. };
  372. var forall = function(xs, pred) {
  373. for (var i = 0, len = xs.length; i < len; ++i) {
  374. var x = xs[i];
  375. if (pred(x, i) !== true) {
  376. return false;
  377. }
  378. }
  379. return true;
  380. };
  381. var reverse = function(xs) {
  382. var r2 = nativeSlice.call(xs, 0);
  383. r2.reverse();
  384. return r2;
  385. };
  386. var difference = function(a1, a2) {
  387. return filter$2(a1, function(x) {
  388. return !contains$2(a2, x);
  389. });
  390. };
  391. var mapToObject = function(xs, f) {
  392. var r2 = {};
  393. for (var i = 0, len = xs.length; i < len; i++) {
  394. var x = xs[i];
  395. r2[String(x)] = f(x, i);
  396. }
  397. return r2;
  398. };
  399. var pure$2 = function(x) {
  400. return [x];
  401. };
  402. var sort = function(xs, comparator) {
  403. var copy = nativeSlice.call(xs, 0);
  404. copy.sort(comparator);
  405. return copy;
  406. };
  407. var get$f = function(xs, i) {
  408. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  409. };
  410. var head = function(xs) {
  411. return get$f(xs, 0);
  412. };
  413. var last$2 = function(xs) {
  414. return get$f(xs, xs.length - 1);
  415. };
  416. var from = isFunction(Array.from) ? Array.from : function(x) {
  417. return nativeSlice.call(x);
  418. };
  419. var findMap = function(arr, f) {
  420. for (var i = 0; i < arr.length; i++) {
  421. var r2 = f(arr[i], i);
  422. if (r2.isSome()) {
  423. return r2;
  424. }
  425. }
  426. return Optional.none();
  427. };
  428. var keys = Object.keys;
  429. var hasOwnProperty$1 = Object.hasOwnProperty;
  430. var each = function(obj, f) {
  431. var props = keys(obj);
  432. for (var k = 0, len = props.length; k < len; k++) {
  433. var i = props[k];
  434. var x = obj[i];
  435. f(x, i);
  436. }
  437. };
  438. var map$1 = function(obj, f) {
  439. return tupleMap(obj, function(x, i) {
  440. return {
  441. k: i,
  442. v: f(x, i)
  443. };
  444. });
  445. };
  446. var tupleMap = function(obj, f) {
  447. var r2 = {};
  448. each(obj, function(x, i) {
  449. var tuple = f(x, i);
  450. r2[tuple.k] = tuple.v;
  451. });
  452. return r2;
  453. };
  454. var objAcc = function(r2) {
  455. return function(x, i) {
  456. r2[i] = x;
  457. };
  458. };
  459. var internalFilter = function(obj, pred, onTrue, onFalse) {
  460. var r2 = {};
  461. each(obj, function(x, i) {
  462. (pred(x, i) ? onTrue : onFalse)(x, i);
  463. });
  464. return r2;
  465. };
  466. var filter$1 = function(obj, pred) {
  467. var t2 = {};
  468. internalFilter(obj, pred, objAcc(t2), noop);
  469. return t2;
  470. };
  471. var mapToArray = function(obj, f) {
  472. var r2 = [];
  473. each(obj, function(value2, name2) {
  474. r2.push(f(value2, name2));
  475. });
  476. return r2;
  477. };
  478. var find$4 = function(obj, pred) {
  479. var props = keys(obj);
  480. for (var k = 0, len = props.length; k < len; k++) {
  481. var i = props[k];
  482. var x = obj[i];
  483. if (pred(x, i, obj)) {
  484. return Optional.some(x);
  485. }
  486. }
  487. return Optional.none();
  488. };
  489. var values = function(obj) {
  490. return mapToArray(obj, identity$1);
  491. };
  492. var get$e = function(obj, key) {
  493. return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none();
  494. };
  495. var has$2 = function(obj, key) {
  496. return hasOwnProperty$1.call(obj, key);
  497. };
  498. var hasNonNullableKey = function(obj, key) {
  499. return has$2(obj, key) && obj[key] !== void 0 && obj[key] !== null;
  500. };
  501. var is$1 = function(lhs, rhs, comparator) {
  502. if (comparator === void 0) {
  503. comparator = tripleEquals;
  504. }
  505. return lhs.exists(function(left2) {
  506. return comparator(left2, rhs);
  507. });
  508. };
  509. var equals = function(lhs, rhs, comparator) {
  510. if (comparator === void 0) {
  511. comparator = tripleEquals;
  512. }
  513. return lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone());
  514. };
  515. var cat = function(arr) {
  516. var r2 = [];
  517. var push = function(x) {
  518. r2.push(x);
  519. };
  520. for (var i = 0; i < arr.length; i++) {
  521. arr[i].each(push);
  522. }
  523. return r2;
  524. };
  525. var sequence = function(arr) {
  526. var r2 = [];
  527. for (var i = 0; i < arr.length; i++) {
  528. var x = arr[i];
  529. if (x.isSome()) {
  530. r2.push(x.getOrDie());
  531. } else {
  532. return Optional.none();
  533. }
  534. }
  535. return Optional.some(r2);
  536. };
  537. var lift2 = function(oa, ob, f) {
  538. return oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
  539. };
  540. var lift3 = function(oa, ob, oc, f) {
  541. return oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none();
  542. };
  543. var mapFrom = function(a, f) {
  544. return a !== void 0 && a !== null ? Optional.some(f(a)) : Optional.none();
  545. };
  546. var someIf = function(b2, a) {
  547. return b2 ? Optional.some(a) : Optional.none();
  548. };
  549. var addToEnd = function(str, suffix2) {
  550. return str + suffix2;
  551. };
  552. var removeFromStart = function(str, numChars) {
  553. return str.substring(numChars);
  554. };
  555. var checkRange = function(str, substr, start) {
  556. return substr === "" || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
  557. };
  558. var removeLeading = function(str, prefix2) {
  559. return startsWith(str, prefix2) ? removeFromStart(str, prefix2.length) : str;
  560. };
  561. var ensureTrailing = function(str, suffix2) {
  562. return endsWith(str, suffix2) ? str : addToEnd(str, suffix2);
  563. };
  564. var contains$1 = function(str, substr) {
  565. return str.indexOf(substr) !== -1;
  566. };
  567. var startsWith = function(str, prefix2) {
  568. return checkRange(str, prefix2, 0);
  569. };
  570. var endsWith = function(str, suffix2) {
  571. return checkRange(str, suffix2, str.length - suffix2.length);
  572. };
  573. var blank = function(r2) {
  574. return function(s) {
  575. return s.replace(r2, "");
  576. };
  577. };
  578. var trim$1 = blank(/^\s+|\s+$/g);
  579. var isNotEmpty = function(s) {
  580. return s.length > 0;
  581. };
  582. var isEmpty = function(s) {
  583. return !isNotEmpty(s);
  584. };
  585. var isSupported$1 = function(dom2) {
  586. return dom2.style !== void 0 && isFunction(dom2.style.getPropertyValue);
  587. };
  588. var fromHtml$2 = function(html2, scope) {
  589. var doc = scope || document;
  590. var div = doc.createElement("div");
  591. div.innerHTML = html2;
  592. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  593. console.error("HTML does not have a single root node", html2);
  594. throw new Error("HTML must have a single root node");
  595. }
  596. return fromDom(div.childNodes[0]);
  597. };
  598. var fromTag = function(tag, scope) {
  599. var doc = scope || document;
  600. var node = doc.createElement(tag);
  601. return fromDom(node);
  602. };
  603. var fromText = function(text2, scope) {
  604. var doc = scope || document;
  605. var node = doc.createTextNode(text2);
  606. return fromDom(node);
  607. };
  608. var fromDom = function(node) {
  609. if (node === null || node === void 0) {
  610. throw new Error("Node cannot be null or undefined");
  611. }
  612. return { dom: node };
  613. };
  614. var fromPoint = function(docElm, x, y) {
  615. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
  616. };
  617. var SugarElement = {
  618. fromHtml: fromHtml$2,
  619. fromTag,
  620. fromText,
  621. fromDom,
  622. fromPoint
  623. };
  624. typeof window !== "undefined" ? window : Function("return this;")();
  625. var DOCUMENT = 9;
  626. var DOCUMENT_FRAGMENT = 11;
  627. var ELEMENT = 1;
  628. var TEXT = 3;
  629. var name$2 = function(element2) {
  630. var r2 = element2.dom.nodeName;
  631. return r2.toLowerCase();
  632. };
  633. var type = function(element2) {
  634. return element2.dom.nodeType;
  635. };
  636. var isType = function(t2) {
  637. return function(element2) {
  638. return type(element2) === t2;
  639. };
  640. };
  641. var isElement$2 = isType(ELEMENT);
  642. var isText$1 = isType(TEXT);
  643. var isDocument = isType(DOCUMENT);
  644. var isDocumentFragment = isType(DOCUMENT_FRAGMENT);
  645. var cached = function(f) {
  646. var called = false;
  647. var r2;
  648. return function() {
  649. var args = [];
  650. for (var _i = 0; _i < arguments.length; _i++) {
  651. args[_i] = arguments[_i];
  652. }
  653. if (!called) {
  654. called = true;
  655. r2 = f.apply(null, args);
  656. }
  657. return r2;
  658. };
  659. };
  660. var DeviceType = function(os, browser, userAgent, mediaMatch2) {
  661. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  662. var isiPhone = os.isiOS() && !isiPad;
  663. var isMobile = os.isiOS() || os.isAndroid();
  664. var isTouch2 = isMobile || mediaMatch2("(pointer:coarse)");
  665. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch2("(min-device-width:768px)");
  666. var isPhone = isiPhone || isMobile && !isTablet;
  667. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  668. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  669. return {
  670. isiPad: constant$1(isiPad),
  671. isiPhone: constant$1(isiPhone),
  672. isTablet: constant$1(isTablet),
  673. isPhone: constant$1(isPhone),
  674. isTouch: constant$1(isTouch2),
  675. isAndroid: os.isAndroid,
  676. isiOS: os.isiOS,
  677. isWebView: constant$1(iOSwebview),
  678. isDesktop: constant$1(isDesktop)
  679. };
  680. };
  681. var firstMatch = function(regexes, s) {
  682. for (var i = 0; i < regexes.length; i++) {
  683. var x = regexes[i];
  684. if (x.test(s)) {
  685. return x;
  686. }
  687. }
  688. return void 0;
  689. };
  690. var find$3 = function(regexes, agent) {
  691. var r2 = firstMatch(regexes, agent);
  692. if (!r2) {
  693. return {
  694. major: 0,
  695. minor: 0
  696. };
  697. }
  698. var group2 = function(i) {
  699. return Number(agent.replace(r2, "$" + i));
  700. };
  701. return nu$d(group2(1), group2(2));
  702. };
  703. var detect$4 = function(versionRegexes, agent) {
  704. var cleanedAgent = String(agent).toLowerCase();
  705. if (versionRegexes.length === 0) {
  706. return unknown$3();
  707. }
  708. return find$3(versionRegexes, cleanedAgent);
  709. };
  710. var unknown$3 = function() {
  711. return nu$d(0, 0);
  712. };
  713. var nu$d = function(major, minor) {
  714. return {
  715. major,
  716. minor
  717. };
  718. };
  719. var Version = {
  720. nu: nu$d,
  721. detect: detect$4,
  722. unknown: unknown$3
  723. };
  724. var detectBrowser$1 = function(browsers2, userAgentData) {
  725. return findMap(userAgentData.brands, function(uaBrand) {
  726. var lcBrand = uaBrand.brand.toLowerCase();
  727. return find$5(browsers2, function(browser) {
  728. var _a2;
  729. return lcBrand === ((_a2 = browser.brand) === null || _a2 === void 0 ? void 0 : _a2.toLowerCase());
  730. }).map(function(info) {
  731. return {
  732. current: info.name,
  733. version: Version.nu(parseInt(uaBrand.version, 10), 0)
  734. };
  735. });
  736. });
  737. };
  738. var detect$3 = function(candidates, userAgent) {
  739. var agent = String(userAgent).toLowerCase();
  740. return find$5(candidates, function(candidate) {
  741. return candidate.search(agent);
  742. });
  743. };
  744. var detectBrowser = function(browsers2, userAgent) {
  745. return detect$3(browsers2, userAgent).map(function(browser) {
  746. var version = Version.detect(browser.versionRegexes, userAgent);
  747. return {
  748. current: browser.name,
  749. version
  750. };
  751. });
  752. };
  753. var detectOs = function(oses2, userAgent) {
  754. return detect$3(oses2, userAgent).map(function(os) {
  755. var version = Version.detect(os.versionRegexes, userAgent);
  756. return {
  757. current: os.name,
  758. version
  759. };
  760. });
  761. };
  762. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  763. var checkContains = function(target) {
  764. return function(uastring) {
  765. return contains$1(uastring, target);
  766. };
  767. };
  768. var browsers = [
  769. {
  770. name: "Edge",
  771. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  772. search: function(uastring) {
  773. return contains$1(uastring, "edge/") && contains$1(uastring, "chrome") && contains$1(uastring, "safari") && contains$1(uastring, "applewebkit");
  774. }
  775. },
  776. {
  777. name: "Chrome",
  778. brand: "Chromium",
  779. versionRegexes: [
  780. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  781. normalVersionRegex
  782. ],
  783. search: function(uastring) {
  784. return contains$1(uastring, "chrome") && !contains$1(uastring, "chromeframe");
  785. }
  786. },
  787. {
  788. name: "IE",
  789. versionRegexes: [
  790. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  791. /.*?rv:([0-9]+)\.([0-9]+).*/
  792. ],
  793. search: function(uastring) {
  794. return contains$1(uastring, "msie") || contains$1(uastring, "trident");
  795. }
  796. },
  797. {
  798. name: "Opera",
  799. versionRegexes: [
  800. normalVersionRegex,
  801. /.*?opera\/([0-9]+)\.([0-9]+).*/
  802. ],
  803. search: checkContains("opera")
  804. },
  805. {
  806. name: "Firefox",
  807. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  808. search: checkContains("firefox")
  809. },
  810. {
  811. name: "Safari",
  812. versionRegexes: [
  813. normalVersionRegex,
  814. /.*?cpu os ([0-9]+)_([0-9]+).*/
  815. ],
  816. search: function(uastring) {
  817. return (contains$1(uastring, "safari") || contains$1(uastring, "mobile/")) && contains$1(uastring, "applewebkit");
  818. }
  819. }
  820. ];
  821. var oses = [
  822. {
  823. name: "Windows",
  824. search: checkContains("win"),
  825. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  826. },
  827. {
  828. name: "iOS",
  829. search: function(uastring) {
  830. return contains$1(uastring, "iphone") || contains$1(uastring, "ipad");
  831. },
  832. versionRegexes: [
  833. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  834. /.*cpu os ([0-9]+)_([0-9]+).*/,
  835. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  836. ]
  837. },
  838. {
  839. name: "Android",
  840. search: checkContains("android"),
  841. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  842. },
  843. {
  844. name: "OSX",
  845. search: checkContains("mac os x"),
  846. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  847. },
  848. {
  849. name: "Linux",
  850. search: checkContains("linux"),
  851. versionRegexes: []
  852. },
  853. {
  854. name: "Solaris",
  855. search: checkContains("sunos"),
  856. versionRegexes: []
  857. },
  858. {
  859. name: "FreeBSD",
  860. search: checkContains("freebsd"),
  861. versionRegexes: []
  862. },
  863. {
  864. name: "ChromeOS",
  865. search: checkContains("cros"),
  866. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  867. }
  868. ];
  869. var PlatformInfo = {
  870. browsers: constant$1(browsers),
  871. oses: constant$1(oses)
  872. };
  873. var edge = "Edge";
  874. var chrome = "Chrome";
  875. var ie = "IE";
  876. var opera = "Opera";
  877. var firefox = "Firefox";
  878. var safari = "Safari";
  879. var unknown$2 = function() {
  880. return nu$c({
  881. current: void 0,
  882. version: Version.unknown()
  883. });
  884. };
  885. var nu$c = function(info) {
  886. var current = info.current;
  887. var version = info.version;
  888. var isBrowser = function(name2) {
  889. return function() {
  890. return current === name2;
  891. };
  892. };
  893. return {
  894. current,
  895. version,
  896. isEdge: isBrowser(edge),
  897. isChrome: isBrowser(chrome),
  898. isIE: isBrowser(ie),
  899. isOpera: isBrowser(opera),
  900. isFirefox: isBrowser(firefox),
  901. isSafari: isBrowser(safari)
  902. };
  903. };
  904. var Browser = {
  905. unknown: unknown$2,
  906. nu: nu$c,
  907. edge: constant$1(edge),
  908. chrome: constant$1(chrome),
  909. ie: constant$1(ie),
  910. opera: constant$1(opera),
  911. firefox: constant$1(firefox),
  912. safari: constant$1(safari)
  913. };
  914. var windows = "Windows";
  915. var ios = "iOS";
  916. var android = "Android";
  917. var linux = "Linux";
  918. var osx = "OSX";
  919. var solaris = "Solaris";
  920. var freebsd = "FreeBSD";
  921. var chromeos = "ChromeOS";
  922. var unknown$1 = function() {
  923. return nu$b({
  924. current: void 0,
  925. version: Version.unknown()
  926. });
  927. };
  928. var nu$b = function(info) {
  929. var current = info.current;
  930. var version = info.version;
  931. var isOS = function(name2) {
  932. return function() {
  933. return current === name2;
  934. };
  935. };
  936. return {
  937. current,
  938. version,
  939. isWindows: isOS(windows),
  940. isiOS: isOS(ios),
  941. isAndroid: isOS(android),
  942. isOSX: isOS(osx),
  943. isLinux: isOS(linux),
  944. isSolaris: isOS(solaris),
  945. isFreeBSD: isOS(freebsd),
  946. isChromeOS: isOS(chromeos)
  947. };
  948. };
  949. var OperatingSystem = {
  950. unknown: unknown$1,
  951. nu: nu$b,
  952. windows: constant$1(windows),
  953. ios: constant$1(ios),
  954. android: constant$1(android),
  955. linux: constant$1(linux),
  956. osx: constant$1(osx),
  957. solaris: constant$1(solaris),
  958. freebsd: constant$1(freebsd),
  959. chromeos: constant$1(chromeos)
  960. };
  961. var detect$2 = function(userAgent, userAgentDataOpt, mediaMatch2) {
  962. var browsers2 = PlatformInfo.browsers();
  963. var oses2 = PlatformInfo.oses();
  964. var browser = userAgentDataOpt.bind(function(userAgentData) {
  965. return detectBrowser$1(browsers2, userAgentData);
  966. }).orThunk(function() {
  967. return detectBrowser(browsers2, userAgent);
  968. }).fold(Browser.unknown, Browser.nu);
  969. var os = detectOs(oses2, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  970. var deviceType = DeviceType(os, browser, userAgent, mediaMatch2);
  971. return {
  972. browser,
  973. os,
  974. deviceType
  975. };
  976. };
  977. var PlatformDetection = { detect: detect$2 };
  978. var mediaMatch = function(query2) {
  979. return window.matchMedia(query2).matches;
  980. };
  981. var platform = cached(function() {
  982. return PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch);
  983. });
  984. var detect$1 = function() {
  985. return platform();
  986. };
  987. var compareDocumentPosition = function(a, b2, match) {
  988. return (a.compareDocumentPosition(b2) & match) !== 0;
  989. };
  990. var documentPositionContainedBy = function(a, b2) {
  991. return compareDocumentPosition(a, b2, Node.DOCUMENT_POSITION_CONTAINED_BY);
  992. };
  993. var is = function(element2, selector) {
  994. var dom2 = element2.dom;
  995. if (dom2.nodeType !== ELEMENT) {
  996. return false;
  997. } else {
  998. var elem = dom2;
  999. if (elem.matches !== void 0) {
  1000. return elem.matches(selector);
  1001. } else if (elem.msMatchesSelector !== void 0) {
  1002. return elem.msMatchesSelector(selector);
  1003. } else if (elem.webkitMatchesSelector !== void 0) {
  1004. return elem.webkitMatchesSelector(selector);
  1005. } else if (elem.mozMatchesSelector !== void 0) {
  1006. return elem.mozMatchesSelector(selector);
  1007. } else {
  1008. throw new Error("Browser lacks native selectors");
  1009. }
  1010. }
  1011. };
  1012. var bypassSelector = function(dom2) {
  1013. return dom2.nodeType !== ELEMENT && dom2.nodeType !== DOCUMENT && dom2.nodeType !== DOCUMENT_FRAGMENT || dom2.childElementCount === 0;
  1014. };
  1015. var all$3 = function(selector, scope) {
  1016. var base2 = scope === void 0 ? document : scope.dom;
  1017. return bypassSelector(base2) ? [] : map$2(base2.querySelectorAll(selector), SugarElement.fromDom);
  1018. };
  1019. var one = function(selector, scope) {
  1020. var base2 = scope === void 0 ? document : scope.dom;
  1021. return bypassSelector(base2) ? Optional.none() : Optional.from(base2.querySelector(selector)).map(SugarElement.fromDom);
  1022. };
  1023. var eq = function(e1, e2) {
  1024. return e1.dom === e2.dom;
  1025. };
  1026. var regularContains = function(e1, e2) {
  1027. var d1 = e1.dom;
  1028. var d2 = e2.dom;
  1029. return d1 === d2 ? false : d1.contains(d2);
  1030. };
  1031. var ieContains = function(e1, e2) {
  1032. return documentPositionContainedBy(e1.dom, e2.dom);
  1033. };
  1034. var contains = function(e1, e2) {
  1035. return detect$1().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
  1036. };
  1037. var owner$4 = function(element2) {
  1038. return SugarElement.fromDom(element2.dom.ownerDocument);
  1039. };
  1040. var documentOrOwner = function(dos) {
  1041. return isDocument(dos) ? dos : owner$4(dos);
  1042. };
  1043. var documentElement = function(element2) {
  1044. return SugarElement.fromDom(documentOrOwner(element2).dom.documentElement);
  1045. };
  1046. var defaultView = function(element2) {
  1047. return SugarElement.fromDom(documentOrOwner(element2).dom.defaultView);
  1048. };
  1049. var parent = function(element2) {
  1050. return Optional.from(element2.dom.parentNode).map(SugarElement.fromDom);
  1051. };
  1052. var parentNode = function(element2) {
  1053. return parent(element2);
  1054. };
  1055. var offsetParent = function(element2) {
  1056. return Optional.from(element2.dom.offsetParent).map(SugarElement.fromDom);
  1057. };
  1058. var nextSibling = function(element2) {
  1059. return Optional.from(element2.dom.nextSibling).map(SugarElement.fromDom);
  1060. };
  1061. var children = function(element2) {
  1062. return map$2(element2.dom.childNodes, SugarElement.fromDom);
  1063. };
  1064. var child$2 = function(element2, index) {
  1065. var cs = element2.dom.childNodes;
  1066. return Optional.from(cs[index]).map(SugarElement.fromDom);
  1067. };
  1068. var firstChild = function(element2) {
  1069. return child$2(element2, 0);
  1070. };
  1071. var spot = function(element2, offset2) {
  1072. return {
  1073. element: element2,
  1074. offset: offset2
  1075. };
  1076. };
  1077. var leaf = function(element2, offset2) {
  1078. var cs = children(element2);
  1079. return cs.length > 0 && offset2 < cs.length ? spot(cs[offset2], 0) : spot(element2, offset2);
  1080. };
  1081. var isShadowRoot = function(dos) {
  1082. return isDocumentFragment(dos) && isNonNullable(dos.dom.host);
  1083. };
  1084. var supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
  1085. var isSupported = constant$1(supported);
  1086. var getRootNode = supported ? function(e) {
  1087. return SugarElement.fromDom(e.dom.getRootNode());
  1088. } : documentOrOwner;
  1089. var getContentContainer = function(dos) {
  1090. return isShadowRoot(dos) ? dos : SugarElement.fromDom(documentOrOwner(dos).dom.body);
  1091. };
  1092. var isInShadowRoot = function(e) {
  1093. return getShadowRoot(e).isSome();
  1094. };
  1095. var getShadowRoot = function(e) {
  1096. var r2 = getRootNode(e);
  1097. return isShadowRoot(r2) ? Optional.some(r2) : Optional.none();
  1098. };
  1099. var getShadowHost = function(e) {
  1100. return SugarElement.fromDom(e.dom.host);
  1101. };
  1102. var getOriginalEventTarget = function(event) {
  1103. if (isSupported() && isNonNullable(event.target)) {
  1104. var el = SugarElement.fromDom(event.target);
  1105. if (isElement$2(el) && isOpenShadowHost(el)) {
  1106. if (event.composed && event.composedPath) {
  1107. var composedPath = event.composedPath();
  1108. if (composedPath) {
  1109. return head(composedPath);
  1110. }
  1111. }
  1112. }
  1113. }
  1114. return Optional.from(event.target);
  1115. };
  1116. var isOpenShadowHost = function(element2) {
  1117. return isNonNullable(element2.dom.shadowRoot);
  1118. };
  1119. var inBody = function(element2) {
  1120. var dom2 = isText$1(element2) ? element2.dom.parentNode : element2.dom;
  1121. if (dom2 === void 0 || dom2 === null || dom2.ownerDocument === null) {
  1122. return false;
  1123. }
  1124. var doc = dom2.ownerDocument;
  1125. return getShadowRoot(SugarElement.fromDom(dom2)).fold(function() {
  1126. return doc.body.contains(dom2);
  1127. }, compose1(inBody, getShadowHost));
  1128. };
  1129. var body = function() {
  1130. return getBody(SugarElement.fromDom(document));
  1131. };
  1132. var getBody = function(doc) {
  1133. var b2 = doc.dom.body;
  1134. if (b2 === null || b2 === void 0) {
  1135. throw new Error("Body is not available yet");
  1136. }
  1137. return SugarElement.fromDom(b2);
  1138. };
  1139. var rawSet = function(dom2, key, value2) {
  1140. if (isString(value2) || isBoolean(value2) || isNumber(value2)) {
  1141. dom2.setAttribute(key, value2 + "");
  1142. } else {
  1143. console.error("Invalid call to Attribute.set. Key ", key, ":: Value ", value2, ":: Element ", dom2);
  1144. throw new Error("Attribute value was not simple");
  1145. }
  1146. };
  1147. var set$8 = function(element2, key, value2) {
  1148. rawSet(element2.dom, key, value2);
  1149. };
  1150. var setAll$1 = function(element2, attrs) {
  1151. var dom2 = element2.dom;
  1152. each(attrs, function(v, k) {
  1153. rawSet(dom2, k, v);
  1154. });
  1155. };
  1156. var get$d = function(element2, key) {
  1157. var v = element2.dom.getAttribute(key);
  1158. return v === null ? void 0 : v;
  1159. };
  1160. var getOpt = function(element2, key) {
  1161. return Optional.from(get$d(element2, key));
  1162. };
  1163. var has$1 = function(element2, key) {
  1164. var dom2 = element2.dom;
  1165. return dom2 && dom2.hasAttribute ? dom2.hasAttribute(key) : false;
  1166. };
  1167. var remove$7 = function(element2, key) {
  1168. element2.dom.removeAttribute(key);
  1169. };
  1170. var internalSet = function(dom2, property, value2) {
  1171. if (!isString(value2)) {
  1172. console.error("Invalid call to CSS.set. Property ", property, ":: Value ", value2, ":: Element ", dom2);
  1173. throw new Error("CSS value must be a string: " + value2);
  1174. }
  1175. if (isSupported$1(dom2)) {
  1176. dom2.style.setProperty(property, value2);
  1177. }
  1178. };
  1179. var internalRemove = function(dom2, property) {
  1180. if (isSupported$1(dom2)) {
  1181. dom2.style.removeProperty(property);
  1182. }
  1183. };
  1184. var set$7 = function(element2, property, value2) {
  1185. var dom2 = element2.dom;
  1186. internalSet(dom2, property, value2);
  1187. };
  1188. var setAll = function(element2, css) {
  1189. var dom2 = element2.dom;
  1190. each(css, function(v, k) {
  1191. internalSet(dom2, k, v);
  1192. });
  1193. };
  1194. var setOptions = function(element2, css) {
  1195. var dom2 = element2.dom;
  1196. each(css, function(v, k) {
  1197. v.fold(function() {
  1198. internalRemove(dom2, k);
  1199. }, function(value2) {
  1200. internalSet(dom2, k, value2);
  1201. });
  1202. });
  1203. };
  1204. var get$c = function(element2, property) {
  1205. var dom2 = element2.dom;
  1206. var styles = window.getComputedStyle(dom2);
  1207. var r2 = styles.getPropertyValue(property);
  1208. return r2 === "" && !inBody(element2) ? getUnsafeProperty(dom2, property) : r2;
  1209. };
  1210. var getUnsafeProperty = function(dom2, property) {
  1211. return isSupported$1(dom2) ? dom2.style.getPropertyValue(property) : "";
  1212. };
  1213. var getRaw = function(element2, property) {
  1214. var dom2 = element2.dom;
  1215. var raw = getUnsafeProperty(dom2, property);
  1216. return Optional.from(raw).filter(function(r2) {
  1217. return r2.length > 0;
  1218. });
  1219. };
  1220. var getAllRaw = function(element2) {
  1221. var css = {};
  1222. var dom2 = element2.dom;
  1223. if (isSupported$1(dom2)) {
  1224. for (var i = 0; i < dom2.style.length; i++) {
  1225. var ruleName = dom2.style.item(i);
  1226. css[ruleName] = dom2.style[ruleName];
  1227. }
  1228. }
  1229. return css;
  1230. };
  1231. var isValidValue = function(tag, property, value2) {
  1232. var element2 = SugarElement.fromTag(tag);
  1233. set$7(element2, property, value2);
  1234. var style = getRaw(element2, property);
  1235. return style.isSome();
  1236. };
  1237. var remove$6 = function(element2, property) {
  1238. var dom2 = element2.dom;
  1239. internalRemove(dom2, property);
  1240. if (is$1(getOpt(element2, "style").map(trim$1), "")) {
  1241. remove$7(element2, "style");
  1242. }
  1243. };
  1244. var reflow = function(e) {
  1245. return e.dom.offsetWidth;
  1246. };
  1247. var Dimension = function(name2, getOffset2) {
  1248. var set2 = function(element2, h) {
  1249. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  1250. throw new Error(name2 + ".set accepts only positive integer values. Value was " + h);
  1251. }
  1252. var dom2 = element2.dom;
  1253. if (isSupported$1(dom2)) {
  1254. dom2.style[name2] = h + "px";
  1255. }
  1256. };
  1257. var get2 = function(element2) {
  1258. var r2 = getOffset2(element2);
  1259. if (r2 <= 0 || r2 === null) {
  1260. var css = get$c(element2, name2);
  1261. return parseFloat(css) || 0;
  1262. }
  1263. return r2;
  1264. };
  1265. var getOuter2 = get2;
  1266. var aggregate = function(element2, properties2) {
  1267. return foldl(properties2, function(acc, property) {
  1268. var val = get$c(element2, property);
  1269. var value2 = val === void 0 ? 0 : parseInt(val, 10);
  1270. return isNaN(value2) ? acc : acc + value2;
  1271. }, 0);
  1272. };
  1273. var max2 = function(element2, value2, properties2) {
  1274. var cumulativeInclusions = aggregate(element2, properties2);
  1275. var absoluteMax = value2 > cumulativeInclusions ? value2 - cumulativeInclusions : 0;
  1276. return absoluteMax;
  1277. };
  1278. return {
  1279. set: set2,
  1280. get: get2,
  1281. getOuter: getOuter2,
  1282. aggregate,
  1283. max: max2
  1284. };
  1285. };
  1286. var api$3 = Dimension("height", function(element2) {
  1287. var dom2 = element2.dom;
  1288. return inBody(element2) ? dom2.getBoundingClientRect().height : dom2.offsetHeight;
  1289. });
  1290. var get$b = function(element2) {
  1291. return api$3.get(element2);
  1292. };
  1293. var getOuter$2 = function(element2) {
  1294. return api$3.getOuter(element2);
  1295. };
  1296. var setMax$1 = function(element2, value2) {
  1297. var inclusions = [
  1298. "margin-top",
  1299. "border-top-width",
  1300. "padding-top",
  1301. "padding-bottom",
  1302. "border-bottom-width",
  1303. "margin-bottom"
  1304. ];
  1305. var absMax = api$3.max(element2, value2, inclusions);
  1306. set$7(element2, "max-height", absMax + "px");
  1307. };
  1308. var r$1 = function(left2, top2) {
  1309. var translate2 = function(x, y) {
  1310. return r$1(left2 + x, top2 + y);
  1311. };
  1312. return {
  1313. left: left2,
  1314. top: top2,
  1315. translate: translate2
  1316. };
  1317. };
  1318. var SugarPosition = r$1;
  1319. var boxPosition = function(dom2) {
  1320. var box2 = dom2.getBoundingClientRect();
  1321. return SugarPosition(box2.left, box2.top);
  1322. };
  1323. var firstDefinedOrZero = function(a, b2) {
  1324. if (a !== void 0) {
  1325. return a;
  1326. } else {
  1327. return b2 !== void 0 ? b2 : 0;
  1328. }
  1329. };
  1330. var absolute$3 = function(element2) {
  1331. var doc = element2.dom.ownerDocument;
  1332. var body2 = doc.body;
  1333. var win2 = doc.defaultView;
  1334. var html2 = doc.documentElement;
  1335. if (body2 === element2.dom) {
  1336. return SugarPosition(body2.offsetLeft, body2.offsetTop);
  1337. }
  1338. var scrollTop = firstDefinedOrZero(win2 === null || win2 === void 0 ? void 0 : win2.pageYOffset, html2.scrollTop);
  1339. var scrollLeft = firstDefinedOrZero(win2 === null || win2 === void 0 ? void 0 : win2.pageXOffset, html2.scrollLeft);
  1340. var clientTop = firstDefinedOrZero(html2.clientTop, body2.clientTop);
  1341. var clientLeft = firstDefinedOrZero(html2.clientLeft, body2.clientLeft);
  1342. return viewport$1(element2).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  1343. };
  1344. var viewport$1 = function(element2) {
  1345. var dom2 = element2.dom;
  1346. var doc = dom2.ownerDocument;
  1347. var body2 = doc.body;
  1348. if (body2 === dom2) {
  1349. return SugarPosition(body2.offsetLeft, body2.offsetTop);
  1350. }
  1351. if (!inBody(element2)) {
  1352. return SugarPosition(0, 0);
  1353. }
  1354. return boxPosition(dom2);
  1355. };
  1356. var api$2 = Dimension("width", function(element2) {
  1357. return element2.dom.offsetWidth;
  1358. });
  1359. var set$6 = function(element2, h) {
  1360. return api$2.set(element2, h);
  1361. };
  1362. var get$a = function(element2) {
  1363. return api$2.get(element2);
  1364. };
  1365. var getOuter$1 = function(element2) {
  1366. return api$2.getOuter(element2);
  1367. };
  1368. var setMax = function(element2, value2) {
  1369. var inclusions = [
  1370. "margin-left",
  1371. "border-left-width",
  1372. "padding-left",
  1373. "padding-right",
  1374. "border-right-width",
  1375. "margin-right"
  1376. ];
  1377. var absMax = api$2.max(element2, value2, inclusions);
  1378. set$7(element2, "max-width", absMax + "px");
  1379. };
  1380. var mkEvent = function(target, x, y, stop2, prevent, kill, raw) {
  1381. return {
  1382. target,
  1383. x,
  1384. y,
  1385. stop: stop2,
  1386. prevent,
  1387. kill,
  1388. raw
  1389. };
  1390. };
  1391. var fromRawEvent$1 = function(rawEvent) {
  1392. var target = SugarElement.fromDom(getOriginalEventTarget(rawEvent).getOr(rawEvent.target));
  1393. var stop2 = function() {
  1394. return rawEvent.stopPropagation();
  1395. };
  1396. var prevent = function() {
  1397. return rawEvent.preventDefault();
  1398. };
  1399. var kill = compose(prevent, stop2);
  1400. return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop2, prevent, kill, rawEvent);
  1401. };
  1402. var handle = function(filter2, handler) {
  1403. return function(rawEvent) {
  1404. if (filter2(rawEvent)) {
  1405. handler(fromRawEvent$1(rawEvent));
  1406. }
  1407. };
  1408. };
  1409. var binder = function(element2, event, filter2, handler, useCapture) {
  1410. var wrapped = handle(filter2, handler);
  1411. element2.dom.addEventListener(event, wrapped, useCapture);
  1412. return { unbind: curry(unbind, element2, event, wrapped, useCapture) };
  1413. };
  1414. var bind$2 = function(element2, event, filter2, handler) {
  1415. return binder(element2, event, filter2, handler, false);
  1416. };
  1417. var capture$1 = function(element2, event, filter2, handler) {
  1418. return binder(element2, event, filter2, handler, true);
  1419. };
  1420. var unbind = function(element2, event, handler, useCapture) {
  1421. element2.dom.removeEventListener(event, handler, useCapture);
  1422. };
  1423. var before$2 = function(marker, element2) {
  1424. var parent$1 = parent(marker);
  1425. parent$1.each(function(v) {
  1426. v.dom.insertBefore(element2.dom, marker.dom);
  1427. });
  1428. };
  1429. var after$2 = function(marker, element2) {
  1430. var sibling = nextSibling(marker);
  1431. sibling.fold(function() {
  1432. var parent$1 = parent(marker);
  1433. parent$1.each(function(v) {
  1434. append$2(v, element2);
  1435. });
  1436. }, function(v) {
  1437. before$2(v, element2);
  1438. });
  1439. };
  1440. var prepend$1 = function(parent2, element2) {
  1441. var firstChild$1 = firstChild(parent2);
  1442. firstChild$1.fold(function() {
  1443. append$2(parent2, element2);
  1444. }, function(v) {
  1445. parent2.dom.insertBefore(element2.dom, v.dom);
  1446. });
  1447. };
  1448. var append$2 = function(parent2, element2) {
  1449. parent2.dom.appendChild(element2.dom);
  1450. };
  1451. var appendAt = function(parent2, element2, index) {
  1452. child$2(parent2, index).fold(function() {
  1453. append$2(parent2, element2);
  1454. }, function(v) {
  1455. before$2(v, element2);
  1456. });
  1457. };
  1458. var before$1 = function(marker, elements) {
  1459. each$1(elements, function(x) {
  1460. before$2(marker, x);
  1461. });
  1462. };
  1463. var append$1 = function(parent2, elements) {
  1464. each$1(elements, function(x) {
  1465. append$2(parent2, x);
  1466. });
  1467. };
  1468. var empty = function(element2) {
  1469. element2.dom.textContent = "";
  1470. each$1(children(element2), function(rogue) {
  1471. remove$5(rogue);
  1472. });
  1473. };
  1474. var remove$5 = function(element2) {
  1475. var dom2 = element2.dom;
  1476. if (dom2.parentNode !== null) {
  1477. dom2.parentNode.removeChild(dom2);
  1478. }
  1479. };
  1480. var unwrap = function(wrapper) {
  1481. var children$1 = children(wrapper);
  1482. if (children$1.length > 0) {
  1483. before$1(wrapper, children$1);
  1484. }
  1485. remove$5(wrapper);
  1486. };
  1487. var get$9 = function(_DOC) {
  1488. var doc = _DOC !== void 0 ? _DOC.dom : document;
  1489. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  1490. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  1491. return SugarPosition(x, y);
  1492. };
  1493. var to = function(x, y, _DOC) {
  1494. var doc = _DOC !== void 0 ? _DOC.dom : document;
  1495. var win2 = doc.defaultView;
  1496. if (win2) {
  1497. win2.scrollTo(x, y);
  1498. }
  1499. };
  1500. var get$8 = function(_win) {
  1501. var win2 = _win === void 0 ? window : _win;
  1502. if (detect$1().browser.isFirefox()) {
  1503. return Optional.none();
  1504. } else {
  1505. return Optional.from(win2["visualViewport"]);
  1506. }
  1507. };
  1508. var bounds$1 = function(x, y, width2, height2) {
  1509. return {
  1510. x,
  1511. y,
  1512. width: width2,
  1513. height: height2,
  1514. right: x + width2,
  1515. bottom: y + height2
  1516. };
  1517. };
  1518. var getBounds$3 = function(_win) {
  1519. var win2 = _win === void 0 ? window : _win;
  1520. var doc = win2.document;
  1521. var scroll = get$9(SugarElement.fromDom(doc));
  1522. return get$8(win2).fold(function() {
  1523. var html2 = win2.document.documentElement;
  1524. var width2 = html2.clientWidth;
  1525. var height2 = html2.clientHeight;
  1526. return bounds$1(scroll.left, scroll.top, width2, height2);
  1527. }, function(visualViewport) {
  1528. return bounds$1(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height);
  1529. });
  1530. };
  1531. var walkUp = function(navigation, doc) {
  1532. var frame = navigation.view(doc);
  1533. return frame.fold(constant$1([]), function(f) {
  1534. var parent2 = navigation.owner(f);
  1535. var rest = walkUp(navigation, parent2);
  1536. return [f].concat(rest);
  1537. });
  1538. };
  1539. var pathTo = function(element2, navigation) {
  1540. var d = navigation.owner(element2);
  1541. var paths = walkUp(navigation, d);
  1542. return Optional.some(paths);
  1543. };
  1544. var view = function(doc) {
  1545. var _a2;
  1546. var element2 = doc.dom === document ? Optional.none() : Optional.from((_a2 = doc.dom.defaultView) === null || _a2 === void 0 ? void 0 : _a2.frameElement);
  1547. return element2.map(SugarElement.fromDom);
  1548. };
  1549. var owner$3 = function(element2) {
  1550. return owner$4(element2);
  1551. };
  1552. var Navigation = Object.freeze({
  1553. __proto__: null,
  1554. view,
  1555. owner: owner$3
  1556. });
  1557. var find$2 = function(element2) {
  1558. var doc = SugarElement.fromDom(document);
  1559. var scroll = get$9(doc);
  1560. var path2 = pathTo(element2, Navigation);
  1561. return path2.fold(curry(absolute$3, element2), function(frames) {
  1562. var offset2 = viewport$1(element2);
  1563. var r2 = foldr(frames, function(b2, a) {
  1564. var loc = viewport$1(a);
  1565. return {
  1566. left: b2.left + loc.left,
  1567. top: b2.top + loc.top
  1568. };
  1569. }, {
  1570. left: 0,
  1571. top: 0
  1572. });
  1573. return SugarPosition(r2.left + offset2.left + scroll.left, r2.top + offset2.top + scroll.top);
  1574. });
  1575. };
  1576. var pointed = function(point2, width2, height2) {
  1577. return {
  1578. point: point2,
  1579. width: width2,
  1580. height: height2
  1581. };
  1582. };
  1583. var rect = function(x, y, width2, height2) {
  1584. return {
  1585. x,
  1586. y,
  1587. width: width2,
  1588. height: height2
  1589. };
  1590. };
  1591. var bounds = function(x, y, width2, height2) {
  1592. return {
  1593. x,
  1594. y,
  1595. width: width2,
  1596. height: height2,
  1597. right: x + width2,
  1598. bottom: y + height2
  1599. };
  1600. };
  1601. var box$1 = function(element2) {
  1602. var xy = absolute$3(element2);
  1603. var w = getOuter$1(element2);
  1604. var h = getOuter$2(element2);
  1605. return bounds(xy.left, xy.top, w, h);
  1606. };
  1607. var absolute$2 = function(element2) {
  1608. var position2 = find$2(element2);
  1609. var width2 = getOuter$1(element2);
  1610. var height2 = getOuter$2(element2);
  1611. return bounds(position2.left, position2.top, width2, height2);
  1612. };
  1613. var win = function() {
  1614. return getBounds$3(window);
  1615. };
  1616. var value$3 = function(o) {
  1617. var or = function(_opt) {
  1618. return value$3(o);
  1619. };
  1620. var orThunk = function(_f) {
  1621. return value$3(o);
  1622. };
  1623. var map2 = function(f) {
  1624. return value$3(f(o));
  1625. };
  1626. var mapError2 = function(_f) {
  1627. return value$3(o);
  1628. };
  1629. var each2 = function(f) {
  1630. f(o);
  1631. };
  1632. var bind2 = function(f) {
  1633. return f(o);
  1634. };
  1635. var fold2 = function(_, onValue) {
  1636. return onValue(o);
  1637. };
  1638. var exists2 = function(f) {
  1639. return f(o);
  1640. };
  1641. var forall2 = function(f) {
  1642. return f(o);
  1643. };
  1644. var toOptional = function() {
  1645. return Optional.some(o);
  1646. };
  1647. return {
  1648. isValue: always,
  1649. isError: never,
  1650. getOr: constant$1(o),
  1651. getOrThunk: constant$1(o),
  1652. getOrDie: constant$1(o),
  1653. or,
  1654. orThunk,
  1655. fold: fold2,
  1656. map: map2,
  1657. mapError: mapError2,
  1658. each: each2,
  1659. bind: bind2,
  1660. exists: exists2,
  1661. forall: forall2,
  1662. toOptional
  1663. };
  1664. };
  1665. var error$1 = function(message) {
  1666. var getOrThunk = function(f) {
  1667. return f();
  1668. };
  1669. var getOrDie2 = function() {
  1670. return die(String(message))();
  1671. };
  1672. var or = identity$1;
  1673. var orThunk = function(f) {
  1674. return f();
  1675. };
  1676. var map2 = function(_f) {
  1677. return error$1(message);
  1678. };
  1679. var mapError2 = function(f) {
  1680. return error$1(f(message));
  1681. };
  1682. var bind2 = function(_f) {
  1683. return error$1(message);
  1684. };
  1685. var fold2 = function(onError, _) {
  1686. return onError(message);
  1687. };
  1688. return {
  1689. isValue: never,
  1690. isError: always,
  1691. getOr: identity$1,
  1692. getOrThunk,
  1693. getOrDie: getOrDie2,
  1694. or,
  1695. orThunk,
  1696. fold: fold2,
  1697. map: map2,
  1698. mapError: mapError2,
  1699. each: noop,
  1700. bind: bind2,
  1701. exists: never,
  1702. forall: always,
  1703. toOptional: Optional.none
  1704. };
  1705. };
  1706. var fromOption = function(opt, err) {
  1707. return opt.fold(function() {
  1708. return error$1(err);
  1709. }, value$3);
  1710. };
  1711. var Result = {
  1712. value: value$3,
  1713. error: error$1,
  1714. fromOption
  1715. };
  1716. var SimpleResultType;
  1717. (function(SimpleResultType2) {
  1718. SimpleResultType2[SimpleResultType2["Error"] = 0] = "Error";
  1719. SimpleResultType2[SimpleResultType2["Value"] = 1] = "Value";
  1720. })(SimpleResultType || (SimpleResultType = {}));
  1721. var fold$1 = function(res, onError, onValue) {
  1722. return res.stype === SimpleResultType.Error ? onError(res.serror) : onValue(res.svalue);
  1723. };
  1724. var partition$2 = function(results) {
  1725. var values2 = [];
  1726. var errors = [];
  1727. each$1(results, function(obj) {
  1728. fold$1(obj, function(err) {
  1729. return errors.push(err);
  1730. }, function(val) {
  1731. return values2.push(val);
  1732. });
  1733. });
  1734. return {
  1735. values: values2,
  1736. errors
  1737. };
  1738. };
  1739. var mapError = function(res, f) {
  1740. if (res.stype === SimpleResultType.Error) {
  1741. return {
  1742. stype: SimpleResultType.Error,
  1743. serror: f(res.serror)
  1744. };
  1745. } else {
  1746. return res;
  1747. }
  1748. };
  1749. var map = function(res, f) {
  1750. if (res.stype === SimpleResultType.Value) {
  1751. return {
  1752. stype: SimpleResultType.Value,
  1753. svalue: f(res.svalue)
  1754. };
  1755. } else {
  1756. return res;
  1757. }
  1758. };
  1759. var bind$1 = function(res, f) {
  1760. if (res.stype === SimpleResultType.Value) {
  1761. return f(res.svalue);
  1762. } else {
  1763. return res;
  1764. }
  1765. };
  1766. var bindError = function(res, f) {
  1767. if (res.stype === SimpleResultType.Error) {
  1768. return f(res.serror);
  1769. } else {
  1770. return res;
  1771. }
  1772. };
  1773. var svalue = function(v) {
  1774. return {
  1775. stype: SimpleResultType.Value,
  1776. svalue: v
  1777. };
  1778. };
  1779. var serror = function(e) {
  1780. return {
  1781. stype: SimpleResultType.Error,
  1782. serror: e
  1783. };
  1784. };
  1785. var toResult$1 = function(res) {
  1786. return fold$1(res, Result.error, Result.value);
  1787. };
  1788. var fromResult$1 = function(res) {
  1789. return res.fold(serror, svalue);
  1790. };
  1791. var SimpleResult = {
  1792. fromResult: fromResult$1,
  1793. toResult: toResult$1,
  1794. svalue,
  1795. partition: partition$2,
  1796. serror,
  1797. bind: bind$1,
  1798. bindError,
  1799. map,
  1800. mapError,
  1801. fold: fold$1
  1802. };
  1803. var field$2 = function(key, newKey, presence, prop) {
  1804. return {
  1805. tag: "field",
  1806. key,
  1807. newKey,
  1808. presence,
  1809. prop
  1810. };
  1811. };
  1812. var customField$1 = function(newKey, instantiator) {
  1813. return {
  1814. tag: "custom",
  1815. newKey,
  1816. instantiator
  1817. };
  1818. };
  1819. var fold = function(value2, ifField, ifCustom) {
  1820. switch (value2.tag) {
  1821. case "field":
  1822. return ifField(value2.key, value2.newKey, value2.presence, value2.prop);
  1823. case "custom":
  1824. return ifCustom(value2.newKey, value2.instantiator);
  1825. }
  1826. };
  1827. var shallow$1 = function(old, nu2) {
  1828. return nu2;
  1829. };
  1830. var deep = function(old, nu2) {
  1831. var bothObjects = isObject(old) && isObject(nu2);
  1832. return bothObjects ? deepMerge(old, nu2) : nu2;
  1833. };
  1834. var baseMerge = function(merger) {
  1835. return function() {
  1836. var objects = [];
  1837. for (var _i = 0; _i < arguments.length; _i++) {
  1838. objects[_i] = arguments[_i];
  1839. }
  1840. if (objects.length === 0) {
  1841. throw new Error("Can't merge zero objects");
  1842. }
  1843. var ret = {};
  1844. for (var j = 0; j < objects.length; j++) {
  1845. var curObject = objects[j];
  1846. for (var key in curObject) {
  1847. if (has$2(curObject, key)) {
  1848. ret[key] = merger(ret[key], curObject[key]);
  1849. }
  1850. }
  1851. }
  1852. return ret;
  1853. };
  1854. };
  1855. var deepMerge = baseMerge(deep);
  1856. var merge$1 = baseMerge(shallow$1);
  1857. var required$2 = function() {
  1858. return {
  1859. tag: "required",
  1860. process: {}
  1861. };
  1862. };
  1863. var defaultedThunk = function(fallbackThunk) {
  1864. return {
  1865. tag: "defaultedThunk",
  1866. process: fallbackThunk
  1867. };
  1868. };
  1869. var defaulted$1 = function(fallback2) {
  1870. return defaultedThunk(constant$1(fallback2));
  1871. };
  1872. var asOption = function() {
  1873. return {
  1874. tag: "option",
  1875. process: {}
  1876. };
  1877. };
  1878. var mergeWithThunk = function(baseThunk) {
  1879. return {
  1880. tag: "mergeWithThunk",
  1881. process: baseThunk
  1882. };
  1883. };
  1884. var mergeWith = function(base2) {
  1885. return mergeWithThunk(constant$1(base2));
  1886. };
  1887. var mergeValues$1 = function(values2, base2) {
  1888. return values2.length > 0 ? SimpleResult.svalue(deepMerge(base2, merge$1.apply(void 0, values2))) : SimpleResult.svalue(base2);
  1889. };
  1890. var mergeErrors$1 = function(errors) {
  1891. return compose(SimpleResult.serror, flatten)(errors);
  1892. };
  1893. var consolidateObj = function(objects, base2) {
  1894. var partition2 = SimpleResult.partition(objects);
  1895. return partition2.errors.length > 0 ? mergeErrors$1(partition2.errors) : mergeValues$1(partition2.values, base2);
  1896. };
  1897. var consolidateArr = function(objects) {
  1898. var partitions = SimpleResult.partition(objects);
  1899. return partitions.errors.length > 0 ? mergeErrors$1(partitions.errors) : SimpleResult.svalue(partitions.values);
  1900. };
  1901. var ResultCombine = {
  1902. consolidateObj,
  1903. consolidateArr
  1904. };
  1905. var formatObj = function(input2) {
  1906. return isObject(input2) && keys(input2).length > 100 ? " removed due to size" : JSON.stringify(input2, null, 2);
  1907. };
  1908. var formatErrors = function(errors) {
  1909. var es = errors.length > 10 ? errors.slice(0, 10).concat([{
  1910. path: [],
  1911. getErrorInfo: constant$1("... (only showing first ten failures)")
  1912. }]) : errors;
  1913. return map$2(es, function(e) {
  1914. return "Failed path: (" + e.path.join(" > ") + ")\n" + e.getErrorInfo();
  1915. });
  1916. };
  1917. var nu$a = function(path2, getErrorInfo) {
  1918. return SimpleResult.serror([{
  1919. path: path2,
  1920. getErrorInfo
  1921. }]);
  1922. };
  1923. var missingRequired = function(path2, key, obj) {
  1924. return nu$a(path2, function() {
  1925. return 'Could not find valid *required* value for "' + key + '" in ' + formatObj(obj);
  1926. });
  1927. };
  1928. var missingKey = function(path2, key) {
  1929. return nu$a(path2, function() {
  1930. return 'Choice schema did not contain choice key: "' + key + '"';
  1931. });
  1932. };
  1933. var missingBranch = function(path2, branches, branch) {
  1934. return nu$a(path2, function() {
  1935. return 'The chosen schema: "' + branch + '" did not exist in branches: ' + formatObj(branches);
  1936. });
  1937. };
  1938. var unsupportedFields = function(path2, unsupported) {
  1939. return nu$a(path2, function() {
  1940. return "There are unsupported fields: [" + unsupported.join(", ") + "] specified";
  1941. });
  1942. };
  1943. var custom = function(path2, err) {
  1944. return nu$a(path2, constant$1(err));
  1945. };
  1946. var value$2 = function(validator) {
  1947. var extract2 = function(path2, val) {
  1948. return SimpleResult.bindError(validator(val), function(err) {
  1949. return custom(path2, err);
  1950. });
  1951. };
  1952. var toString2 = constant$1("val");
  1953. return {
  1954. extract: extract2,
  1955. toString: toString2
  1956. };
  1957. };
  1958. var anyValue$1 = value$2(SimpleResult.svalue);
  1959. var requiredAccess = function(path2, obj, key, bundle) {
  1960. return get$e(obj, key).fold(function() {
  1961. return missingRequired(path2, key, obj);
  1962. }, bundle);
  1963. };
  1964. var fallbackAccess = function(obj, key, fallback2, bundle) {
  1965. var v = get$e(obj, key).getOrThunk(function() {
  1966. return fallback2(obj);
  1967. });
  1968. return bundle(v);
  1969. };
  1970. var optionAccess = function(obj, key, bundle) {
  1971. return bundle(get$e(obj, key));
  1972. };
  1973. var optionDefaultedAccess = function(obj, key, fallback2, bundle) {
  1974. var opt = get$e(obj, key).map(function(val) {
  1975. return val === true ? fallback2(obj) : val;
  1976. });
  1977. return bundle(opt);
  1978. };
  1979. var extractField = function(field2, path2, obj, key, prop) {
  1980. var bundle = function(av) {
  1981. return prop.extract(path2.concat([key]), av);
  1982. };
  1983. var bundleAsOption = function(optValue) {
  1984. return optValue.fold(function() {
  1985. return SimpleResult.svalue(Optional.none());
  1986. }, function(ov) {
  1987. var result = prop.extract(path2.concat([key]), ov);
  1988. return SimpleResult.map(result, Optional.some);
  1989. });
  1990. };
  1991. switch (field2.tag) {
  1992. case "required":
  1993. return requiredAccess(path2, obj, key, bundle);
  1994. case "defaultedThunk":
  1995. return fallbackAccess(obj, key, field2.process, bundle);
  1996. case "option":
  1997. return optionAccess(obj, key, bundleAsOption);
  1998. case "defaultedOptionThunk":
  1999. return optionDefaultedAccess(obj, key, field2.process, bundleAsOption);
  2000. case "mergeWithThunk": {
  2001. return fallbackAccess(obj, key, constant$1({}), function(v) {
  2002. var result = deepMerge(field2.process(obj), v);
  2003. return bundle(result);
  2004. });
  2005. }
  2006. }
  2007. };
  2008. var extractFields = function(path2, obj, fields) {
  2009. var success = {};
  2010. var errors = [];
  2011. for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
  2012. var field2 = fields_1[_i];
  2013. fold(field2, function(key, newKey, presence, prop) {
  2014. var result = extractField(presence, path2, obj, key, prop);
  2015. SimpleResult.fold(result, function(err) {
  2016. errors.push.apply(errors, err);
  2017. }, function(res) {
  2018. success[newKey] = res;
  2019. });
  2020. }, function(newKey, instantiator) {
  2021. success[newKey] = instantiator(obj);
  2022. });
  2023. }
  2024. return errors.length > 0 ? SimpleResult.serror(errors) : SimpleResult.svalue(success);
  2025. };
  2026. var valueThunk = function(getDelegate) {
  2027. var extract2 = function(path2, val) {
  2028. return getDelegate().extract(path2, val);
  2029. };
  2030. var toString2 = function() {
  2031. return getDelegate().toString();
  2032. };
  2033. return {
  2034. extract: extract2,
  2035. toString: toString2
  2036. };
  2037. };
  2038. var getSetKeys = function(obj) {
  2039. return keys(filter$1(obj, isNonNullable));
  2040. };
  2041. var objOfOnly = function(fields) {
  2042. var delegate = objOf(fields);
  2043. var fieldNames = foldr(fields, function(acc, value2) {
  2044. return fold(value2, function(key) {
  2045. var _a2;
  2046. return deepMerge(acc, (_a2 = {}, _a2[key] = true, _a2));
  2047. }, constant$1(acc));
  2048. }, {});
  2049. var extract2 = function(path2, o) {
  2050. var keys2 = isBoolean(o) ? [] : getSetKeys(o);
  2051. var extra = filter$2(keys2, function(k) {
  2052. return !hasNonNullableKey(fieldNames, k);
  2053. });
  2054. return extra.length === 0 ? delegate.extract(path2, o) : unsupportedFields(path2, extra);
  2055. };
  2056. return {
  2057. extract: extract2,
  2058. toString: delegate.toString
  2059. };
  2060. };
  2061. var objOf = function(values2) {
  2062. var extract2 = function(path2, o) {
  2063. return extractFields(path2, o, values2);
  2064. };
  2065. var toString2 = function() {
  2066. var fieldStrings = map$2(values2, function(value2) {
  2067. return fold(value2, function(key, _okey, _presence, prop) {
  2068. return key + " -> " + prop.toString();
  2069. }, function(newKey, _instantiator) {
  2070. return "state(" + newKey + ")";
  2071. });
  2072. });
  2073. return "obj{\n" + fieldStrings.join("\n") + "}";
  2074. };
  2075. return {
  2076. extract: extract2,
  2077. toString: toString2
  2078. };
  2079. };
  2080. var arrOf = function(prop) {
  2081. var extract2 = function(path2, array) {
  2082. var results = map$2(array, function(a, i) {
  2083. return prop.extract(path2.concat(["[" + i + "]"]), a);
  2084. });
  2085. return ResultCombine.consolidateArr(results);
  2086. };
  2087. var toString2 = function() {
  2088. return "array(" + prop.toString() + ")";
  2089. };
  2090. return {
  2091. extract: extract2,
  2092. toString: toString2
  2093. };
  2094. };
  2095. var oneOf = function(props) {
  2096. var extract2 = function(path2, val) {
  2097. var errors = [];
  2098. for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
  2099. var prop = props_1[_i];
  2100. var res = prop.extract(path2, val);
  2101. if (res.stype === SimpleResultType.Value) {
  2102. return res;
  2103. }
  2104. errors.push(res);
  2105. }
  2106. return ResultCombine.consolidateArr(errors);
  2107. };
  2108. var toString2 = function() {
  2109. return "oneOf(" + map$2(props, function(prop) {
  2110. return prop.toString();
  2111. }).join(", ") + ")";
  2112. };
  2113. return {
  2114. extract: extract2,
  2115. toString: toString2
  2116. };
  2117. };
  2118. var setOf$1 = function(validator, prop) {
  2119. var validateKeys = function(path2, keys2) {
  2120. return arrOf(value$2(validator)).extract(path2, keys2);
  2121. };
  2122. var extract2 = function(path2, o) {
  2123. var keys$1 = keys(o);
  2124. var validatedKeys = validateKeys(path2, keys$1);
  2125. return SimpleResult.bind(validatedKeys, function(validKeys) {
  2126. var schema2 = map$2(validKeys, function(vk) {
  2127. return field$2(vk, vk, required$2(), prop);
  2128. });
  2129. return objOf(schema2).extract(path2, o);
  2130. });
  2131. };
  2132. var toString2 = function() {
  2133. return "setOf(" + prop.toString() + ")";
  2134. };
  2135. return {
  2136. extract: extract2,
  2137. toString: toString2
  2138. };
  2139. };
  2140. var thunk = function(_desc, processor) {
  2141. var getP = cached(processor);
  2142. var extract2 = function(path2, val) {
  2143. return getP().extract(path2, val);
  2144. };
  2145. var toString2 = function() {
  2146. return getP().toString();
  2147. };
  2148. return {
  2149. extract: extract2,
  2150. toString: toString2
  2151. };
  2152. };
  2153. var arrOfObj = compose(arrOf, objOf);
  2154. var anyValue = constant$1(anyValue$1);
  2155. var typedValue = function(validator, expectedType) {
  2156. return value$2(function(a) {
  2157. var actualType = typeof a;
  2158. return validator(a) ? SimpleResult.svalue(a) : SimpleResult.serror("Expected type: " + expectedType + " but got: " + actualType);
  2159. });
  2160. };
  2161. var number = typedValue(isNumber, "number");
  2162. var string = typedValue(isString, "string");
  2163. var boolean = typedValue(isBoolean, "boolean");
  2164. var functionProcessor = typedValue(isFunction, "function");
  2165. var isPostMessageable = function(val) {
  2166. if (Object(val) !== val) {
  2167. return true;
  2168. }
  2169. switch ({}.toString.call(val).slice(8, -1)) {
  2170. case "Boolean":
  2171. case "Number":
  2172. case "String":
  2173. case "Date":
  2174. case "RegExp":
  2175. case "Blob":
  2176. case "FileList":
  2177. case "ImageData":
  2178. case "ImageBitmap":
  2179. case "ArrayBuffer":
  2180. return true;
  2181. case "Array":
  2182. case "Object":
  2183. return Object.keys(val).every(function(prop) {
  2184. return isPostMessageable(val[prop]);
  2185. });
  2186. default:
  2187. return false;
  2188. }
  2189. };
  2190. var postMessageable = value$2(function(a) {
  2191. if (isPostMessageable(a)) {
  2192. return SimpleResult.svalue(a);
  2193. } else {
  2194. return SimpleResult.serror("Expected value to be acceptable for sending via postMessage");
  2195. }
  2196. });
  2197. var chooseFrom = function(path2, input2, branches, ch) {
  2198. var fields = get$e(branches, ch);
  2199. return fields.fold(function() {
  2200. return missingBranch(path2, branches, ch);
  2201. }, function(vp) {
  2202. return vp.extract(path2.concat(["branch: " + ch]), input2);
  2203. });
  2204. };
  2205. var choose$2 = function(key, branches) {
  2206. var extract2 = function(path2, input2) {
  2207. var choice = get$e(input2, key);
  2208. return choice.fold(function() {
  2209. return missingKey(path2, key);
  2210. }, function(chosen) {
  2211. return chooseFrom(path2, input2, branches, chosen);
  2212. });
  2213. };
  2214. var toString2 = function() {
  2215. return "chooseOn(" + key + "). Possible values: " + keys(branches);
  2216. };
  2217. return {
  2218. extract: extract2,
  2219. toString: toString2
  2220. };
  2221. };
  2222. var arrOfVal = function() {
  2223. return arrOf(anyValue$1);
  2224. };
  2225. var valueOf = function(validator) {
  2226. return value$2(function(v) {
  2227. return validator(v).fold(SimpleResult.serror, SimpleResult.svalue);
  2228. });
  2229. };
  2230. var setOf = function(validator, prop) {
  2231. return setOf$1(function(v) {
  2232. return SimpleResult.fromResult(validator(v));
  2233. }, prop);
  2234. };
  2235. var extractValue = function(label, prop, obj) {
  2236. var res = prop.extract([label], obj);
  2237. return SimpleResult.mapError(res, function(errs) {
  2238. return {
  2239. input: obj,
  2240. errors: errs
  2241. };
  2242. });
  2243. };
  2244. var asRaw = function(label, prop, obj) {
  2245. return SimpleResult.toResult(extractValue(label, prop, obj));
  2246. };
  2247. var getOrDie = function(extraction) {
  2248. return extraction.fold(function(errInfo) {
  2249. throw new Error(formatError(errInfo));
  2250. }, identity$1);
  2251. };
  2252. var asRawOrDie$1 = function(label, prop, obj) {
  2253. return getOrDie(asRaw(label, prop, obj));
  2254. };
  2255. var formatError = function(errInfo) {
  2256. return "Errors: \n" + formatErrors(errInfo.errors).join("\n") + "\n\nInput object: " + formatObj(errInfo.input);
  2257. };
  2258. var choose$1 = function(key, branches) {
  2259. return choose$2(key, map$1(branches, objOf));
  2260. };
  2261. var thunkOf = function(desc, schema2) {
  2262. return thunk(desc, schema2);
  2263. };
  2264. var field$1 = field$2;
  2265. var customField = customField$1;
  2266. var validateEnum = function(values2) {
  2267. return valueOf(function(value2) {
  2268. return contains$2(values2, value2) ? Result.value(value2) : Result.error('Unsupported value: "' + value2 + '", choose one of "' + values2.join(", ") + '".');
  2269. });
  2270. };
  2271. var required$1 = function(key) {
  2272. return field$1(key, key, required$2(), anyValue());
  2273. };
  2274. var requiredOf = function(key, schema2) {
  2275. return field$1(key, key, required$2(), schema2);
  2276. };
  2277. var requiredNumber = function(key) {
  2278. return requiredOf(key, number);
  2279. };
  2280. var requiredString = function(key) {
  2281. return requiredOf(key, string);
  2282. };
  2283. var requiredStringEnum = function(key, values2) {
  2284. return field$1(key, key, required$2(), validateEnum(values2));
  2285. };
  2286. var requiredBoolean = function(key) {
  2287. return requiredOf(key, boolean);
  2288. };
  2289. var requiredFunction = function(key) {
  2290. return requiredOf(key, functionProcessor);
  2291. };
  2292. var forbid = function(key, message) {
  2293. return field$1(key, key, asOption(), value$2(function(_v) {
  2294. return SimpleResult.serror("The field: " + key + " is forbidden. " + message);
  2295. }));
  2296. };
  2297. var requiredObjOf = function(key, objSchema) {
  2298. return field$1(key, key, required$2(), objOf(objSchema));
  2299. };
  2300. var requiredArrayOfObj = function(key, objFields) {
  2301. return field$1(key, key, required$2(), arrOfObj(objFields));
  2302. };
  2303. var requiredArrayOf = function(key, schema2) {
  2304. return field$1(key, key, required$2(), arrOf(schema2));
  2305. };
  2306. var option = function(key) {
  2307. return field$1(key, key, asOption(), anyValue());
  2308. };
  2309. var optionOf = function(key, schema2) {
  2310. return field$1(key, key, asOption(), schema2);
  2311. };
  2312. var optionNumber = function(key) {
  2313. return optionOf(key, number);
  2314. };
  2315. var optionString = function(key) {
  2316. return optionOf(key, string);
  2317. };
  2318. var optionFunction = function(key) {
  2319. return optionOf(key, functionProcessor);
  2320. };
  2321. var optionArrayOf = function(key, schema2) {
  2322. return optionOf(key, arrOf(schema2));
  2323. };
  2324. var optionObjOf = function(key, objSchema) {
  2325. return optionOf(key, objOf(objSchema));
  2326. };
  2327. var optionObjOfOnly = function(key, objSchema) {
  2328. return optionOf(key, objOfOnly(objSchema));
  2329. };
  2330. var defaulted = function(key, fallback2) {
  2331. return field$1(key, key, defaulted$1(fallback2), anyValue());
  2332. };
  2333. var defaultedOf = function(key, fallback2, schema2) {
  2334. return field$1(key, key, defaulted$1(fallback2), schema2);
  2335. };
  2336. var defaultedNumber = function(key, fallback2) {
  2337. return defaultedOf(key, fallback2, number);
  2338. };
  2339. var defaultedString = function(key, fallback2) {
  2340. return defaultedOf(key, fallback2, string);
  2341. };
  2342. var defaultedStringEnum = function(key, fallback2, values2) {
  2343. return defaultedOf(key, fallback2, validateEnum(values2));
  2344. };
  2345. var defaultedBoolean = function(key, fallback2) {
  2346. return defaultedOf(key, fallback2, boolean);
  2347. };
  2348. var defaultedFunction = function(key, fallback2) {
  2349. return defaultedOf(key, fallback2, functionProcessor);
  2350. };
  2351. var defaultedPostMsg = function(key, fallback2) {
  2352. return defaultedOf(key, fallback2, postMessageable);
  2353. };
  2354. var defaultedArrayOf = function(key, fallback2, schema2) {
  2355. return defaultedOf(key, fallback2, arrOf(schema2));
  2356. };
  2357. var defaultedObjOf = function(key, fallback2, objSchema) {
  2358. return defaultedOf(key, fallback2, objOf(objSchema));
  2359. };
  2360. var Cell = function(initial) {
  2361. var value2 = initial;
  2362. var get2 = function() {
  2363. return value2;
  2364. };
  2365. var set2 = function(v) {
  2366. value2 = v;
  2367. };
  2368. return {
  2369. get: get2,
  2370. set: set2
  2371. };
  2372. };
  2373. var generate$7 = function(cases) {
  2374. if (!isArray(cases)) {
  2375. throw new Error("cases must be an array");
  2376. }
  2377. if (cases.length === 0) {
  2378. throw new Error("there must be at least one case");
  2379. }
  2380. var constructors = [];
  2381. var adt2 = {};
  2382. each$1(cases, function(acase, count2) {
  2383. var keys$1 = keys(acase);
  2384. if (keys$1.length !== 1) {
  2385. throw new Error("one and only one name per case");
  2386. }
  2387. var key = keys$1[0];
  2388. var value2 = acase[key];
  2389. if (adt2[key] !== void 0) {
  2390. throw new Error("duplicate key detected:" + key);
  2391. } else if (key === "cata") {
  2392. throw new Error("cannot have a case named cata (sorry)");
  2393. } else if (!isArray(value2)) {
  2394. throw new Error("case arguments must be an array");
  2395. }
  2396. constructors.push(key);
  2397. adt2[key] = function() {
  2398. var args = [];
  2399. for (var _i = 0; _i < arguments.length; _i++) {
  2400. args[_i] = arguments[_i];
  2401. }
  2402. var argLength = args.length;
  2403. if (argLength !== value2.length) {
  2404. throw new Error("Wrong number of arguments to case " + key + ". Expected " + value2.length + " (" + value2 + "), got " + argLength);
  2405. }
  2406. var match = function(branches) {
  2407. var branchKeys = keys(branches);
  2408. if (constructors.length !== branchKeys.length) {
  2409. throw new Error("Wrong number of arguments to match. Expected: " + constructors.join(",") + "\nActual: " + branchKeys.join(","));
  2410. }
  2411. var allReqd = forall(constructors, function(reqKey) {
  2412. return contains$2(branchKeys, reqKey);
  2413. });
  2414. if (!allReqd) {
  2415. throw new Error("Not all branches were specified when using match. Specified: " + branchKeys.join(", ") + "\nRequired: " + constructors.join(", "));
  2416. }
  2417. return branches[key].apply(null, args);
  2418. };
  2419. return {
  2420. fold: function() {
  2421. var foldArgs = [];
  2422. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  2423. foldArgs[_i2] = arguments[_i2];
  2424. }
  2425. if (foldArgs.length !== cases.length) {
  2426. throw new Error("Wrong number of arguments to fold. Expected " + cases.length + ", got " + foldArgs.length);
  2427. }
  2428. var target = foldArgs[count2];
  2429. return target.apply(null, args);
  2430. },
  2431. match,
  2432. log: function(label) {
  2433. console.log(label, {
  2434. constructors,
  2435. constructor: key,
  2436. params: args
  2437. });
  2438. }
  2439. };
  2440. };
  2441. });
  2442. return adt2;
  2443. };
  2444. var Adt = { generate: generate$7 };
  2445. Adt.generate([
  2446. {
  2447. bothErrors: [
  2448. "error1",
  2449. "error2"
  2450. ]
  2451. },
  2452. {
  2453. firstError: [
  2454. "error1",
  2455. "value2"
  2456. ]
  2457. },
  2458. {
  2459. secondError: [
  2460. "value1",
  2461. "error2"
  2462. ]
  2463. },
  2464. {
  2465. bothValues: [
  2466. "value1",
  2467. "value2"
  2468. ]
  2469. }
  2470. ]);
  2471. var partition$1 = function(results) {
  2472. var errors = [];
  2473. var values2 = [];
  2474. each$1(results, function(result) {
  2475. result.fold(function(err) {
  2476. errors.push(err);
  2477. }, function(value2) {
  2478. values2.push(value2);
  2479. });
  2480. });
  2481. return {
  2482. errors,
  2483. values: values2
  2484. };
  2485. };
  2486. var exclude$1 = function(obj, fields) {
  2487. var r2 = {};
  2488. each(obj, function(v, k) {
  2489. if (!contains$2(fields, k)) {
  2490. r2[k] = v;
  2491. }
  2492. });
  2493. return r2;
  2494. };
  2495. var wrap$2 = function(key, value2) {
  2496. var _a2;
  2497. return _a2 = {}, _a2[key] = value2, _a2;
  2498. };
  2499. var wrapAll$1 = function(keyvalues) {
  2500. var r2 = {};
  2501. each$1(keyvalues, function(kv) {
  2502. r2[kv.key] = kv.value;
  2503. });
  2504. return r2;
  2505. };
  2506. var exclude = function(obj, fields) {
  2507. return exclude$1(obj, fields);
  2508. };
  2509. var wrap$1 = function(key, value2) {
  2510. return wrap$2(key, value2);
  2511. };
  2512. var wrapAll = function(keyvalues) {
  2513. return wrapAll$1(keyvalues);
  2514. };
  2515. var mergeValues = function(values2, base2) {
  2516. return values2.length === 0 ? Result.value(base2) : Result.value(deepMerge(base2, merge$1.apply(void 0, values2)));
  2517. };
  2518. var mergeErrors = function(errors) {
  2519. return Result.error(flatten(errors));
  2520. };
  2521. var consolidate = function(objs, base2) {
  2522. var partitions = partition$1(objs);
  2523. return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : mergeValues(partitions.values, base2);
  2524. };
  2525. var ensureIsRoot = function(isRoot) {
  2526. return isFunction(isRoot) ? isRoot : never;
  2527. };
  2528. var ancestor$2 = function(scope, transform2, isRoot) {
  2529. var element2 = scope.dom;
  2530. var stop2 = ensureIsRoot(isRoot);
  2531. while (element2.parentNode) {
  2532. element2 = element2.parentNode;
  2533. var el = SugarElement.fromDom(element2);
  2534. var transformed = transform2(el);
  2535. if (transformed.isSome()) {
  2536. return transformed;
  2537. } else if (stop2(el)) {
  2538. break;
  2539. }
  2540. }
  2541. return Optional.none();
  2542. };
  2543. var closest$4 = function(scope, transform2, isRoot) {
  2544. var current = transform2(scope);
  2545. var stop2 = ensureIsRoot(isRoot);
  2546. return current.orThunk(function() {
  2547. return stop2(scope) ? Optional.none() : ancestor$2(scope, transform2, stop2);
  2548. });
  2549. };
  2550. var isSource = function(component, simulatedEvent) {
  2551. return eq(component.element, simulatedEvent.event.target);
  2552. };
  2553. var defaultEventHandler = {
  2554. can: always,
  2555. abort: never,
  2556. run: noop
  2557. };
  2558. var nu$9 = function(parts2) {
  2559. if (!hasNonNullableKey(parts2, "can") && !hasNonNullableKey(parts2, "abort") && !hasNonNullableKey(parts2, "run")) {
  2560. throw new Error("EventHandler defined by: " + JSON.stringify(parts2, null, 2) + " does not have can, abort, or run!");
  2561. }
  2562. return __assign(__assign({}, defaultEventHandler), parts2);
  2563. };
  2564. var all$2 = function(handlers2, f) {
  2565. return function() {
  2566. var args = [];
  2567. for (var _i = 0; _i < arguments.length; _i++) {
  2568. args[_i] = arguments[_i];
  2569. }
  2570. return foldl(handlers2, function(acc, handler) {
  2571. return acc && f(handler).apply(void 0, args);
  2572. }, true);
  2573. };
  2574. };
  2575. var any = function(handlers2, f) {
  2576. return function() {
  2577. var args = [];
  2578. for (var _i = 0; _i < arguments.length; _i++) {
  2579. args[_i] = arguments[_i];
  2580. }
  2581. return foldl(handlers2, function(acc, handler) {
  2582. return acc || f(handler).apply(void 0, args);
  2583. }, false);
  2584. };
  2585. };
  2586. var read$2 = function(handler) {
  2587. return isFunction(handler) ? {
  2588. can: always,
  2589. abort: never,
  2590. run: handler
  2591. } : handler;
  2592. };
  2593. var fuse$1 = function(handlers2) {
  2594. var can2 = all$2(handlers2, function(handler) {
  2595. return handler.can;
  2596. });
  2597. var abort2 = any(handlers2, function(handler) {
  2598. return handler.abort;
  2599. });
  2600. var run2 = function() {
  2601. var args = [];
  2602. for (var _i = 0; _i < arguments.length; _i++) {
  2603. args[_i] = arguments[_i];
  2604. }
  2605. each$1(handlers2, function(handler) {
  2606. handler.run.apply(void 0, args);
  2607. });
  2608. };
  2609. return {
  2610. can: can2,
  2611. abort: abort2,
  2612. run: run2
  2613. };
  2614. };
  2615. var constant = constant$1;
  2616. var touchstart = constant("touchstart");
  2617. var touchmove = constant("touchmove");
  2618. var touchend = constant("touchend");
  2619. var touchcancel = constant("touchcancel");
  2620. var mousedown = constant("mousedown");
  2621. var mousemove = constant("mousemove");
  2622. var mouseout = constant("mouseout");
  2623. var mouseup = constant("mouseup");
  2624. var mouseover = constant("mouseover");
  2625. var focusin = constant("focusin");
  2626. var focusout = constant("focusout");
  2627. var keydown = constant("keydown");
  2628. var keyup = constant("keyup");
  2629. var input = constant("input");
  2630. var change = constant("change");
  2631. var click = constant("click");
  2632. var transitioncancel = constant("transitioncancel");
  2633. var transitionend = constant("transitionend");
  2634. var transitionstart = constant("transitionstart");
  2635. var selectstart = constant("selectstart");
  2636. var prefixName = function(name2) {
  2637. return constant$1("alloy." + name2);
  2638. };
  2639. var alloy = { tap: prefixName("tap") };
  2640. var focus$4 = prefixName("focus");
  2641. var postBlur = prefixName("blur.post");
  2642. var postPaste = prefixName("paste.post");
  2643. var receive = prefixName("receive");
  2644. var execute$5 = prefixName("execute");
  2645. var focusItem = prefixName("focus.item");
  2646. var tap = alloy.tap;
  2647. var longpress = prefixName("longpress");
  2648. var sandboxClose = prefixName("sandbox.close");
  2649. var typeaheadCancel = prefixName("typeahead.cancel");
  2650. var systemInit = prefixName("system.init");
  2651. var documentTouchmove = prefixName("system.touchmove");
  2652. var documentTouchend = prefixName("system.touchend");
  2653. var windowScroll = prefixName("system.scroll");
  2654. var windowResize = prefixName("system.resize");
  2655. var attachedToDom = prefixName("system.attached");
  2656. var detachedFromDom = prefixName("system.detached");
  2657. var dismissRequested = prefixName("system.dismissRequested");
  2658. var repositionRequested = prefixName("system.repositionRequested");
  2659. var focusShifted = prefixName("focusmanager.shifted");
  2660. var slotVisibility = prefixName("slotcontainer.visibility");
  2661. var changeTab = prefixName("change.tab");
  2662. var dismissTab = prefixName("dismiss.tab");
  2663. var highlight$1 = prefixName("highlight");
  2664. var dehighlight$1 = prefixName("dehighlight");
  2665. var emit = function(component, event) {
  2666. dispatchWith(component, component.element, event, {});
  2667. };
  2668. var emitWith = function(component, event, properties2) {
  2669. dispatchWith(component, component.element, event, properties2);
  2670. };
  2671. var emitExecute = function(component) {
  2672. emit(component, execute$5());
  2673. };
  2674. var dispatch = function(component, target, event) {
  2675. dispatchWith(component, target, event, {});
  2676. };
  2677. var dispatchWith = function(component, target, event, properties2) {
  2678. var data = __assign({ target }, properties2);
  2679. component.getSystem().triggerEvent(event, target, data);
  2680. };
  2681. var dispatchEvent = function(component, target, event, simulatedEvent) {
  2682. component.getSystem().triggerEvent(event, target, simulatedEvent.event);
  2683. };
  2684. var derive$2 = function(configs) {
  2685. return wrapAll(configs);
  2686. };
  2687. var abort = function(name2, predicate) {
  2688. return {
  2689. key: name2,
  2690. value: nu$9({ abort: predicate })
  2691. };
  2692. };
  2693. var can = function(name2, predicate) {
  2694. return {
  2695. key: name2,
  2696. value: nu$9({ can: predicate })
  2697. };
  2698. };
  2699. var preventDefault = function(name2) {
  2700. return {
  2701. key: name2,
  2702. value: nu$9({
  2703. run: function(component, simulatedEvent) {
  2704. simulatedEvent.event.prevent();
  2705. }
  2706. })
  2707. };
  2708. };
  2709. var run$1 = function(name2, handler) {
  2710. return {
  2711. key: name2,
  2712. value: nu$9({ run: handler })
  2713. };
  2714. };
  2715. var runActionExtra = function(name2, action, extra) {
  2716. return {
  2717. key: name2,
  2718. value: nu$9({
  2719. run: function(component, simulatedEvent) {
  2720. action.apply(void 0, [
  2721. component,
  2722. simulatedEvent
  2723. ].concat(extra));
  2724. }
  2725. })
  2726. };
  2727. };
  2728. var runOnName = function(name2) {
  2729. return function(handler) {
  2730. return run$1(name2, handler);
  2731. };
  2732. };
  2733. var runOnSourceName = function(name2) {
  2734. return function(handler) {
  2735. return {
  2736. key: name2,
  2737. value: nu$9({
  2738. run: function(component, simulatedEvent) {
  2739. if (isSource(component, simulatedEvent)) {
  2740. handler(component, simulatedEvent);
  2741. }
  2742. }
  2743. })
  2744. };
  2745. };
  2746. };
  2747. var redirectToUid = function(name2, uid) {
  2748. return run$1(name2, function(component, simulatedEvent) {
  2749. component.getSystem().getByUid(uid).each(function(redirectee) {
  2750. dispatchEvent(redirectee, redirectee.element, name2, simulatedEvent);
  2751. });
  2752. });
  2753. };
  2754. var redirectToPart = function(name2, detail, partName) {
  2755. var uid = detail.partUids[partName];
  2756. return redirectToUid(name2, uid);
  2757. };
  2758. var runWithTarget = function(name2, f) {
  2759. return run$1(name2, function(component, simulatedEvent) {
  2760. var ev = simulatedEvent.event;
  2761. var target = component.getSystem().getByDom(ev.target).getOrThunk(function() {
  2762. var closest2 = closest$4(ev.target, function(el) {
  2763. return component.getSystem().getByDom(el).toOptional();
  2764. }, never);
  2765. return closest2.getOr(component);
  2766. });
  2767. f(component, target, simulatedEvent);
  2768. });
  2769. };
  2770. var cutter = function(name2) {
  2771. return run$1(name2, function(component, simulatedEvent) {
  2772. simulatedEvent.cut();
  2773. });
  2774. };
  2775. var stopper = function(name2) {
  2776. return run$1(name2, function(component, simulatedEvent) {
  2777. simulatedEvent.stop();
  2778. });
  2779. };
  2780. var runOnSource = function(name2, f) {
  2781. return runOnSourceName(name2)(f);
  2782. };
  2783. var runOnAttached = runOnSourceName(attachedToDom());
  2784. var runOnDetached = runOnSourceName(detachedFromDom());
  2785. var runOnInit = runOnSourceName(systemInit());
  2786. var runOnExecute$1 = runOnName(execute$5());
  2787. var fromHtml$1 = function(html2, scope) {
  2788. var doc = scope || document;
  2789. var div = doc.createElement("div");
  2790. div.innerHTML = html2;
  2791. return children(SugarElement.fromDom(div));
  2792. };
  2793. var get$7 = function(element2) {
  2794. return element2.dom.innerHTML;
  2795. };
  2796. var set$5 = function(element2, content) {
  2797. var owner2 = owner$4(element2);
  2798. var docDom = owner2.dom;
  2799. var fragment = SugarElement.fromDom(docDom.createDocumentFragment());
  2800. var contentElements = fromHtml$1(content, docDom);
  2801. append$1(fragment, contentElements);
  2802. empty(element2);
  2803. append$2(element2, fragment);
  2804. };
  2805. var getOuter = function(element2) {
  2806. var container = SugarElement.fromTag("div");
  2807. var clone2 = SugarElement.fromDom(element2.dom.cloneNode(true));
  2808. append$2(container, clone2);
  2809. return get$7(container);
  2810. };
  2811. var clone$2 = function(original2, isDeep) {
  2812. return SugarElement.fromDom(original2.dom.cloneNode(isDeep));
  2813. };
  2814. var shallow = function(original2) {
  2815. return clone$2(original2, false);
  2816. };
  2817. var getHtml = function(element2) {
  2818. if (isShadowRoot(element2)) {
  2819. return "#shadow-root";
  2820. } else {
  2821. var clone2 = shallow(element2);
  2822. return getOuter(clone2);
  2823. }
  2824. };
  2825. var element = function(elem) {
  2826. return getHtml(elem);
  2827. };
  2828. var isRecursive = function(component, originator, target) {
  2829. return eq(originator, component.element) && !eq(originator, target);
  2830. };
  2831. var events$i = derive$2([can(focus$4(), function(component, simulatedEvent) {
  2832. var event = simulatedEvent.event;
  2833. var originator = event.originator;
  2834. var target = event.target;
  2835. if (isRecursive(component, originator, target)) {
  2836. console.warn(focus$4() + " did not get interpreted by the desired target. \nOriginator: " + element(originator) + "\nTarget: " + element(target) + "\nCheck the " + focus$4() + " event handlers");
  2837. return false;
  2838. } else {
  2839. return true;
  2840. }
  2841. })]);
  2842. var DefaultEvents = Object.freeze({
  2843. __proto__: null,
  2844. events: events$i
  2845. });
  2846. var unique = 0;
  2847. var generate$6 = function(prefix2) {
  2848. var date = /* @__PURE__ */ new Date();
  2849. var time = date.getTime();
  2850. var random = Math.floor(Math.random() * 1e9);
  2851. unique++;
  2852. return prefix2 + "_" + random + unique + String(time);
  2853. };
  2854. var prefix$1 = constant$1("alloy-id-");
  2855. var idAttr$1 = constant$1("data-alloy-id");
  2856. var prefix = prefix$1();
  2857. var idAttr = idAttr$1();
  2858. var write = function(label, elem) {
  2859. var id = generate$6(prefix + label);
  2860. writeOnly(elem, id);
  2861. return id;
  2862. };
  2863. var writeOnly = function(elem, uid) {
  2864. Object.defineProperty(elem.dom, idAttr, {
  2865. value: uid,
  2866. writable: true
  2867. });
  2868. };
  2869. var read$1 = function(elem) {
  2870. var id = isElement$2(elem) ? elem.dom[idAttr] : null;
  2871. return Optional.from(id);
  2872. };
  2873. var generate$5 = function(prefix2) {
  2874. return generate$6(prefix2);
  2875. };
  2876. var make$8 = identity$1;
  2877. var NoContextApi = function(getComp) {
  2878. var getMessage = function(event) {
  2879. return "The component must be in a context to execute: " + event + (getComp ? "\n" + element(getComp().element) + " is not in context." : "");
  2880. };
  2881. var fail = function(event) {
  2882. return function() {
  2883. throw new Error(getMessage(event));
  2884. };
  2885. };
  2886. var warn = function(event) {
  2887. return function() {
  2888. console.warn(getMessage(event));
  2889. };
  2890. };
  2891. return {
  2892. debugInfo: constant$1("fake"),
  2893. triggerEvent: warn("triggerEvent"),
  2894. triggerFocus: warn("triggerFocus"),
  2895. triggerEscape: warn("triggerEscape"),
  2896. broadcast: warn("broadcast"),
  2897. broadcastOn: warn("broadcastOn"),
  2898. broadcastEvent: warn("broadcastEvent"),
  2899. build: fail("build"),
  2900. addToWorld: fail("addToWorld"),
  2901. removeFromWorld: fail("removeFromWorld"),
  2902. addToGui: fail("addToGui"),
  2903. removeFromGui: fail("removeFromGui"),
  2904. getByUid: fail("getByUid"),
  2905. getByDom: fail("getByDom"),
  2906. isConnected: never
  2907. };
  2908. };
  2909. var singleton$1 = NoContextApi();
  2910. var markAsBehaviourApi = function(f, apiName, apiFunction) {
  2911. var delegate = apiFunction.toString();
  2912. var endIndex = delegate.indexOf(")") + 1;
  2913. var openBracketIndex = delegate.indexOf("(");
  2914. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2915. f.toFunctionAnnotation = function() {
  2916. return {
  2917. name: apiName,
  2918. parameters: cleanParameters(parameters.slice(0, 1).concat(parameters.slice(3)))
  2919. };
  2920. };
  2921. return f;
  2922. };
  2923. var cleanParameters = function(parameters) {
  2924. return map$2(parameters, function(p) {
  2925. return endsWith(p, "/*") ? p.substring(0, p.length - "/*".length) : p;
  2926. });
  2927. };
  2928. var markAsExtraApi = function(f, extraName) {
  2929. var delegate = f.toString();
  2930. var endIndex = delegate.indexOf(")") + 1;
  2931. var openBracketIndex = delegate.indexOf("(");
  2932. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2933. f.toFunctionAnnotation = function() {
  2934. return {
  2935. name: extraName,
  2936. parameters: cleanParameters(parameters)
  2937. };
  2938. };
  2939. return f;
  2940. };
  2941. var markAsSketchApi = function(f, apiFunction) {
  2942. var delegate = apiFunction.toString();
  2943. var endIndex = delegate.indexOf(")") + 1;
  2944. var openBracketIndex = delegate.indexOf("(");
  2945. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2946. f.toFunctionAnnotation = function() {
  2947. return {
  2948. name: "OVERRIDE",
  2949. parameters: cleanParameters(parameters.slice(1))
  2950. };
  2951. };
  2952. return f;
  2953. };
  2954. var premadeTag = generate$6("alloy-premade");
  2955. var premade$1 = function(comp) {
  2956. return wrap$1(premadeTag, comp);
  2957. };
  2958. var getPremade = function(spec) {
  2959. return get$e(spec, premadeTag);
  2960. };
  2961. var makeApi = function(f) {
  2962. return markAsSketchApi(function(component) {
  2963. var rest = [];
  2964. for (var _i = 1; _i < arguments.length; _i++) {
  2965. rest[_i - 1] = arguments[_i];
  2966. }
  2967. return f.apply(void 0, __spreadArray([
  2968. component.getApis(),
  2969. component
  2970. ], rest, false));
  2971. }, f);
  2972. };
  2973. var NoState = {
  2974. init: function() {
  2975. return nu$8({ readState: constant$1("No State required") });
  2976. }
  2977. };
  2978. var nu$8 = function(spec) {
  2979. return spec;
  2980. };
  2981. var generateFrom$1 = function(spec, all2) {
  2982. var schema2 = map$2(all2, function(a) {
  2983. return optionObjOf(a.name(), [
  2984. required$1("config"),
  2985. defaulted("state", NoState)
  2986. ]);
  2987. });
  2988. var validated = asRaw("component.behaviours", objOf(schema2), spec.behaviours).fold(function(errInfo) {
  2989. throw new Error(formatError(errInfo) + "\nComplete spec:\n" + JSON.stringify(spec, null, 2));
  2990. }, identity$1);
  2991. return {
  2992. list: all2,
  2993. data: map$1(validated, function(optBlobThunk) {
  2994. var output2 = optBlobThunk.map(function(blob) {
  2995. return {
  2996. config: blob.config,
  2997. state: blob.state.init(blob.config)
  2998. };
  2999. });
  3000. return constant$1(output2);
  3001. })
  3002. };
  3003. };
  3004. var getBehaviours$3 = function(bData) {
  3005. return bData.list;
  3006. };
  3007. var getData$2 = function(bData) {
  3008. return bData.data;
  3009. };
  3010. var byInnerKey = function(data, tuple) {
  3011. var r2 = {};
  3012. each(data, function(detail, key) {
  3013. each(detail, function(value2, indexKey) {
  3014. var chain = get$e(r2, indexKey).getOr([]);
  3015. r2[indexKey] = chain.concat([tuple(key, value2)]);
  3016. });
  3017. });
  3018. return r2;
  3019. };
  3020. var nu$7 = function(s) {
  3021. return {
  3022. classes: isUndefined(s.classes) ? [] : s.classes,
  3023. attributes: isUndefined(s.attributes) ? {} : s.attributes,
  3024. styles: isUndefined(s.styles) ? {} : s.styles
  3025. };
  3026. };
  3027. var merge = function(defnA, mod) {
  3028. return __assign(__assign({}, defnA), {
  3029. attributes: __assign(__assign({}, defnA.attributes), mod.attributes),
  3030. styles: __assign(__assign({}, defnA.styles), mod.styles),
  3031. classes: defnA.classes.concat(mod.classes)
  3032. });
  3033. };
  3034. var combine$2 = function(info, baseMod, behaviours2, base2) {
  3035. var modsByBehaviour = __assign({}, baseMod);
  3036. each$1(behaviours2, function(behaviour) {
  3037. modsByBehaviour[behaviour.name()] = behaviour.exhibit(info, base2);
  3038. });
  3039. var byAspect = byInnerKey(modsByBehaviour, function(name2, modification) {
  3040. return {
  3041. name: name2,
  3042. modification
  3043. };
  3044. });
  3045. var combineObjects = function(objects) {
  3046. return foldr(objects, function(b2, a) {
  3047. return __assign(__assign({}, a.modification), b2);
  3048. }, {});
  3049. };
  3050. var combinedClasses = foldr(byAspect.classes, function(b2, a) {
  3051. return a.modification.concat(b2);
  3052. }, []);
  3053. var combinedAttributes = combineObjects(byAspect.attributes);
  3054. var combinedStyles = combineObjects(byAspect.styles);
  3055. return nu$7({
  3056. classes: combinedClasses,
  3057. attributes: combinedAttributes,
  3058. styles: combinedStyles
  3059. });
  3060. };
  3061. var sortKeys = function(label, keyName, array, order) {
  3062. try {
  3063. var sorted = sort(array, function(a, b2) {
  3064. var aKey = a[keyName];
  3065. var bKey = b2[keyName];
  3066. var aIndex = order.indexOf(aKey);
  3067. var bIndex = order.indexOf(bKey);
  3068. if (aIndex === -1) {
  3069. throw new Error("The ordering for " + label + " does not have an entry for " + aKey + ".\nOrder specified: " + JSON.stringify(order, null, 2));
  3070. }
  3071. if (bIndex === -1) {
  3072. throw new Error("The ordering for " + label + " does not have an entry for " + bKey + ".\nOrder specified: " + JSON.stringify(order, null, 2));
  3073. }
  3074. if (aIndex < bIndex) {
  3075. return -1;
  3076. } else if (bIndex < aIndex) {
  3077. return 1;
  3078. } else {
  3079. return 0;
  3080. }
  3081. });
  3082. return Result.value(sorted);
  3083. } catch (err) {
  3084. return Result.error([err]);
  3085. }
  3086. };
  3087. var uncurried = function(handler, purpose) {
  3088. return {
  3089. handler,
  3090. purpose
  3091. };
  3092. };
  3093. var curried = function(handler, purpose) {
  3094. return {
  3095. cHandler: handler,
  3096. purpose
  3097. };
  3098. };
  3099. var curryArgs = function(descHandler, extraArgs) {
  3100. return curried(curry.apply(void 0, [descHandler.handler].concat(extraArgs)), descHandler.purpose);
  3101. };
  3102. var getCurried = function(descHandler) {
  3103. return descHandler.cHandler;
  3104. };
  3105. var behaviourTuple = function(name2, handler) {
  3106. return {
  3107. name: name2,
  3108. handler
  3109. };
  3110. };
  3111. var nameToHandlers = function(behaviours2, info) {
  3112. var r2 = {};
  3113. each$1(behaviours2, function(behaviour) {
  3114. r2[behaviour.name()] = behaviour.handlers(info);
  3115. });
  3116. return r2;
  3117. };
  3118. var groupByEvents = function(info, behaviours2, base2) {
  3119. var behaviourEvents = __assign(__assign({}, base2), nameToHandlers(behaviours2, info));
  3120. return byInnerKey(behaviourEvents, behaviourTuple);
  3121. };
  3122. var combine$1 = function(info, eventOrder, behaviours2, base2) {
  3123. var byEventName = groupByEvents(info, behaviours2, base2);
  3124. return combineGroups(byEventName, eventOrder);
  3125. };
  3126. var assemble = function(rawHandler) {
  3127. var handler = read$2(rawHandler);
  3128. return function(component, simulatedEvent) {
  3129. var rest = [];
  3130. for (var _i = 2; _i < arguments.length; _i++) {
  3131. rest[_i - 2] = arguments[_i];
  3132. }
  3133. var args = [
  3134. component,
  3135. simulatedEvent
  3136. ].concat(rest);
  3137. if (handler.abort.apply(void 0, args)) {
  3138. simulatedEvent.stop();
  3139. } else if (handler.can.apply(void 0, args)) {
  3140. handler.run.apply(void 0, args);
  3141. }
  3142. };
  3143. };
  3144. var missingOrderError = function(eventName, tuples) {
  3145. 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) {
  3146. return c.name;
  3147. }), null, 2)]);
  3148. };
  3149. var fuse = function(tuples, eventOrder, eventName) {
  3150. var order = eventOrder[eventName];
  3151. if (!order) {
  3152. return missingOrderError(eventName, tuples);
  3153. } else {
  3154. return sortKeys("Event: " + eventName, "name", tuples, order).map(function(sortedTuples) {
  3155. var handlers2 = map$2(sortedTuples, function(tuple) {
  3156. return tuple.handler;
  3157. });
  3158. return fuse$1(handlers2);
  3159. });
  3160. }
  3161. };
  3162. var combineGroups = function(byEventName, eventOrder) {
  3163. var r2 = mapToArray(byEventName, function(tuples, eventName) {
  3164. var combined = tuples.length === 1 ? Result.value(tuples[0].handler) : fuse(tuples, eventOrder, eventName);
  3165. return combined.map(function(handler) {
  3166. var assembled = assemble(handler);
  3167. var purpose = tuples.length > 1 ? filter$2(eventOrder[eventName], function(o) {
  3168. return exists(tuples, function(t2) {
  3169. return t2.name === o;
  3170. });
  3171. }).join(" > ") : tuples[0].name;
  3172. return wrap$1(eventName, uncurried(assembled, purpose));
  3173. });
  3174. });
  3175. return consolidate(r2, {});
  3176. };
  3177. var _a$2;
  3178. var baseBehaviour = "alloy.base.behaviour";
  3179. var schema$z = objOf([
  3180. field$1("dom", "dom", required$2(), objOf([
  3181. required$1("tag"),
  3182. defaulted("styles", {}),
  3183. defaulted("classes", []),
  3184. defaulted("attributes", {}),
  3185. option("value"),
  3186. option("innerHtml")
  3187. ])),
  3188. required$1("components"),
  3189. required$1("uid"),
  3190. defaulted("events", {}),
  3191. defaulted("apis", {}),
  3192. field$1("eventOrder", "eventOrder", mergeWith((_a$2 = {}, _a$2[execute$5()] = [
  3193. "disabling",
  3194. baseBehaviour,
  3195. "toggling",
  3196. "typeaheadevents"
  3197. ], _a$2[focus$4()] = [
  3198. baseBehaviour,
  3199. "focusing",
  3200. "keying"
  3201. ], _a$2[systemInit()] = [
  3202. baseBehaviour,
  3203. "disabling",
  3204. "toggling",
  3205. "representing"
  3206. ], _a$2[input()] = [
  3207. baseBehaviour,
  3208. "representing",
  3209. "streaming",
  3210. "invalidating"
  3211. ], _a$2[detachedFromDom()] = [
  3212. baseBehaviour,
  3213. "representing",
  3214. "item-events",
  3215. "tooltipping"
  3216. ], _a$2[mousedown()] = [
  3217. "focusing",
  3218. baseBehaviour,
  3219. "item-type-events"
  3220. ], _a$2[touchstart()] = [
  3221. "focusing",
  3222. baseBehaviour,
  3223. "item-type-events"
  3224. ], _a$2[mouseover()] = [
  3225. "item-type-events",
  3226. "tooltipping"
  3227. ], _a$2[receive()] = [
  3228. "receiving",
  3229. "reflecting",
  3230. "tooltipping"
  3231. ], _a$2)), anyValue()),
  3232. option("domModification")
  3233. ]);
  3234. var toInfo = function(spec) {
  3235. return asRaw("custom.definition", schema$z, spec);
  3236. };
  3237. var toDefinition = function(detail) {
  3238. return __assign(__assign({}, detail.dom), {
  3239. uid: detail.uid,
  3240. domChildren: map$2(detail.components, function(comp) {
  3241. return comp.element;
  3242. })
  3243. });
  3244. };
  3245. var toModification = function(detail) {
  3246. return detail.domModification.fold(function() {
  3247. return nu$7({});
  3248. }, nu$7);
  3249. };
  3250. var toEvents = function(info) {
  3251. return info.events;
  3252. };
  3253. var read = function(element2, attr) {
  3254. var value2 = get$d(element2, attr);
  3255. return value2 === void 0 || value2 === "" ? [] : value2.split(" ");
  3256. };
  3257. var add$4 = function(element2, attr, id) {
  3258. var old = read(element2, attr);
  3259. var nu2 = old.concat([id]);
  3260. set$8(element2, attr, nu2.join(" "));
  3261. return true;
  3262. };
  3263. var remove$4 = function(element2, attr, id) {
  3264. var nu2 = filter$2(read(element2, attr), function(v) {
  3265. return v !== id;
  3266. });
  3267. if (nu2.length > 0) {
  3268. set$8(element2, attr, nu2.join(" "));
  3269. } else {
  3270. remove$7(element2, attr);
  3271. }
  3272. return false;
  3273. };
  3274. var supports = function(element2) {
  3275. return element2.dom.classList !== void 0;
  3276. };
  3277. var get$6 = function(element2) {
  3278. return read(element2, "class");
  3279. };
  3280. var add$3 = function(element2, clazz) {
  3281. return add$4(element2, "class", clazz);
  3282. };
  3283. var remove$3 = function(element2, clazz) {
  3284. return remove$4(element2, "class", clazz);
  3285. };
  3286. var add$2 = function(element2, clazz) {
  3287. if (supports(element2)) {
  3288. element2.dom.classList.add(clazz);
  3289. } else {
  3290. add$3(element2, clazz);
  3291. }
  3292. };
  3293. var cleanClass = function(element2) {
  3294. var classList = supports(element2) ? element2.dom.classList : get$6(element2);
  3295. if (classList.length === 0) {
  3296. remove$7(element2, "class");
  3297. }
  3298. };
  3299. var remove$2 = function(element2, clazz) {
  3300. if (supports(element2)) {
  3301. var classList = element2.dom.classList;
  3302. classList.remove(clazz);
  3303. } else {
  3304. remove$3(element2, clazz);
  3305. }
  3306. cleanClass(element2);
  3307. };
  3308. var has = function(element2, clazz) {
  3309. return supports(element2) && element2.dom.classList.contains(clazz);
  3310. };
  3311. var add$1 = function(element2, classes2) {
  3312. each$1(classes2, function(x) {
  3313. add$2(element2, x);
  3314. });
  3315. };
  3316. var remove$1 = function(element2, classes2) {
  3317. each$1(classes2, function(x) {
  3318. remove$2(element2, x);
  3319. });
  3320. };
  3321. var hasAll = function(element2, classes2) {
  3322. return forall(classes2, function(clazz) {
  3323. return has(element2, clazz);
  3324. });
  3325. };
  3326. var get$5 = function(element2) {
  3327. return element2.dom.value;
  3328. };
  3329. var set$4 = function(element2, value2) {
  3330. if (value2 === void 0) {
  3331. throw new Error("Value.set was undefined");
  3332. }
  3333. element2.dom.value = value2;
  3334. };
  3335. var renderToDom = function(definition) {
  3336. var subject = SugarElement.fromTag(definition.tag);
  3337. setAll$1(subject, definition.attributes);
  3338. add$1(subject, definition.classes);
  3339. setAll(subject, definition.styles);
  3340. definition.innerHtml.each(function(html2) {
  3341. return set$5(subject, html2);
  3342. });
  3343. var children2 = definition.domChildren;
  3344. append$1(subject, children2);
  3345. definition.value.each(function(value2) {
  3346. set$4(subject, value2);
  3347. });
  3348. if (!definition.uid) {
  3349. debugger;
  3350. }
  3351. writeOnly(subject, definition.uid);
  3352. return subject;
  3353. };
  3354. var getBehaviours$2 = function(spec) {
  3355. var behaviours2 = get$e(spec, "behaviours").getOr({});
  3356. return bind$3(keys(behaviours2), function(name2) {
  3357. var behaviour = behaviours2[name2];
  3358. return isNonNullable(behaviour) ? [behaviour.me] : [];
  3359. });
  3360. };
  3361. var generateFrom = function(spec, all2) {
  3362. return generateFrom$1(spec, all2);
  3363. };
  3364. var generate$4 = function(spec) {
  3365. var all2 = getBehaviours$2(spec);
  3366. return generateFrom(spec, all2);
  3367. };
  3368. var getDomDefinition = function(info, bList, bData) {
  3369. var definition = toDefinition(info);
  3370. var infoModification = toModification(info);
  3371. var baseModification = { "alloy.base.modification": infoModification };
  3372. var modification = bList.length > 0 ? combine$2(bData, baseModification, bList, definition) : infoModification;
  3373. return merge(definition, modification);
  3374. };
  3375. var getEvents = function(info, bList, bData) {
  3376. var baseEvents = { "alloy.base.behaviour": toEvents(info) };
  3377. return combine$1(bData, info.eventOrder, bList, baseEvents).getOrDie();
  3378. };
  3379. var build$2 = function(spec) {
  3380. var getMe = function() {
  3381. return me;
  3382. };
  3383. var systemApi = Cell(singleton$1);
  3384. var info = getOrDie(toInfo(spec));
  3385. var bBlob = generate$4(spec);
  3386. var bList = getBehaviours$3(bBlob);
  3387. var bData = getData$2(bBlob);
  3388. var modDefinition = getDomDefinition(info, bList, bData);
  3389. var item2 = renderToDom(modDefinition);
  3390. var events2 = getEvents(info, bList, bData);
  3391. var subcomponents = Cell(info.components);
  3392. var connect = function(newApi) {
  3393. systemApi.set(newApi);
  3394. };
  3395. var disconnect = function() {
  3396. systemApi.set(NoContextApi(getMe));
  3397. };
  3398. var syncComponents = function() {
  3399. var children$1 = children(item2);
  3400. var subs2 = bind$3(children$1, function(child2) {
  3401. return systemApi.get().getByDom(child2).fold(function() {
  3402. return [];
  3403. }, pure$2);
  3404. });
  3405. subcomponents.set(subs2);
  3406. };
  3407. var config2 = function(behaviour) {
  3408. var b2 = bData;
  3409. var f = isFunction(b2[behaviour.name()]) ? b2[behaviour.name()] : function() {
  3410. throw new Error("Could not find " + behaviour.name() + " in " + JSON.stringify(spec, null, 2));
  3411. };
  3412. return f();
  3413. };
  3414. var hasConfigured = function(behaviour) {
  3415. return isFunction(bData[behaviour.name()]);
  3416. };
  3417. var getApis = function() {
  3418. return info.apis;
  3419. };
  3420. var readState = function(behaviourName) {
  3421. return bData[behaviourName]().map(function(b2) {
  3422. return b2.state.readState();
  3423. }).getOr("not enabled");
  3424. };
  3425. var me = {
  3426. uid: spec.uid,
  3427. getSystem: systemApi.get,
  3428. config: config2,
  3429. hasConfigured,
  3430. spec,
  3431. readState,
  3432. getApis,
  3433. connect,
  3434. disconnect,
  3435. element: item2,
  3436. syncComponents,
  3437. components: subcomponents.get,
  3438. events: events2
  3439. };
  3440. return me;
  3441. };
  3442. var buildSubcomponents = function(spec) {
  3443. var components2 = get$e(spec, "components").getOr([]);
  3444. return map$2(components2, build$1);
  3445. };
  3446. var buildFromSpec = function(userSpec) {
  3447. var _a2 = make$8(userSpec), specEvents = _a2.events, spec = __rest(_a2, ["events"]);
  3448. var components2 = buildSubcomponents(spec);
  3449. var completeSpec = __assign(__assign({}, spec), {
  3450. events: __assign(__assign({}, DefaultEvents), specEvents),
  3451. components: components2
  3452. });
  3453. return Result.value(build$2(completeSpec));
  3454. };
  3455. var text$1 = function(textContent) {
  3456. var element2 = SugarElement.fromText(textContent);
  3457. return external$2({ element: element2 });
  3458. };
  3459. var external$2 = function(spec) {
  3460. var extSpec = asRawOrDie$1("external.component", objOfOnly([
  3461. required$1("element"),
  3462. option("uid")
  3463. ]), spec);
  3464. var systemApi = Cell(NoContextApi());
  3465. var connect = function(newApi) {
  3466. systemApi.set(newApi);
  3467. };
  3468. var disconnect = function() {
  3469. systemApi.set(NoContextApi(function() {
  3470. return me;
  3471. }));
  3472. };
  3473. var uid = extSpec.uid.getOrThunk(function() {
  3474. return generate$5("external");
  3475. });
  3476. writeOnly(extSpec.element, uid);
  3477. var me = {
  3478. uid,
  3479. getSystem: systemApi.get,
  3480. config: Optional.none,
  3481. hasConfigured: never,
  3482. connect,
  3483. disconnect,
  3484. getApis: function() {
  3485. return {};
  3486. },
  3487. element: extSpec.element,
  3488. spec,
  3489. readState: constant$1("No state"),
  3490. syncComponents: noop,
  3491. components: constant$1([]),
  3492. events: {}
  3493. };
  3494. return premade$1(me);
  3495. };
  3496. var uids = generate$5;
  3497. var isSketchSpec$1 = function(spec) {
  3498. return has$2(spec, "uid");
  3499. };
  3500. var build$1 = function(spec) {
  3501. return getPremade(spec).getOrThunk(function() {
  3502. var userSpecWithUid = isSketchSpec$1(spec) ? spec : __assign({ uid: uids("") }, spec);
  3503. return buildFromSpec(userSpecWithUid).getOrDie();
  3504. });
  3505. };
  3506. var premade = premade$1;
  3507. function ClosestOrAncestor(is2, ancestor2, scope, a, isRoot) {
  3508. if (is2(scope, a)) {
  3509. return Optional.some(scope);
  3510. } else if (isFunction(isRoot) && isRoot(scope)) {
  3511. return Optional.none();
  3512. } else {
  3513. return ancestor2(scope, a, isRoot);
  3514. }
  3515. }
  3516. var ancestor$1 = function(scope, predicate, isRoot) {
  3517. var element2 = scope.dom;
  3518. var stop2 = isFunction(isRoot) ? isRoot : never;
  3519. while (element2.parentNode) {
  3520. element2 = element2.parentNode;
  3521. var el = SugarElement.fromDom(element2);
  3522. if (predicate(el)) {
  3523. return Optional.some(el);
  3524. } else if (stop2(el)) {
  3525. break;
  3526. }
  3527. }
  3528. return Optional.none();
  3529. };
  3530. var closest$3 = function(scope, predicate, isRoot) {
  3531. var is2 = function(s, test) {
  3532. return test(s);
  3533. };
  3534. return ClosestOrAncestor(is2, ancestor$1, scope, predicate, isRoot);
  3535. };
  3536. var child$1 = function(scope, predicate) {
  3537. var pred = function(node) {
  3538. return predicate(SugarElement.fromDom(node));
  3539. };
  3540. var result = find$5(scope.dom.childNodes, pred);
  3541. return result.map(SugarElement.fromDom);
  3542. };
  3543. var descendant$1 = function(scope, predicate) {
  3544. var descend = function(node) {
  3545. for (var i = 0; i < node.childNodes.length; i++) {
  3546. var child_1 = SugarElement.fromDom(node.childNodes[i]);
  3547. if (predicate(child_1)) {
  3548. return Optional.some(child_1);
  3549. }
  3550. var res = descend(node.childNodes[i]);
  3551. if (res.isSome()) {
  3552. return res;
  3553. }
  3554. }
  3555. return Optional.none();
  3556. };
  3557. return descend(scope.dom);
  3558. };
  3559. var closest$2 = function(scope, predicate, isRoot) {
  3560. return closest$3(scope, predicate, isRoot).isSome();
  3561. };
  3562. var ancestor = function(scope, selector, isRoot) {
  3563. return ancestor$1(scope, function(e) {
  3564. return is(e, selector);
  3565. }, isRoot);
  3566. };
  3567. var child = function(scope, selector) {
  3568. return child$1(scope, function(e) {
  3569. return is(e, selector);
  3570. });
  3571. };
  3572. var descendant = function(scope, selector) {
  3573. return one(selector, scope);
  3574. };
  3575. var closest$1 = function(scope, selector, isRoot) {
  3576. var is$12 = function(element2, selector2) {
  3577. return is(element2, selector2);
  3578. };
  3579. return ClosestOrAncestor(is$12, ancestor, scope, selector, isRoot);
  3580. };
  3581. var find$1 = function(queryElem) {
  3582. var dependent = closest$3(queryElem, function(elem) {
  3583. if (!isElement$2(elem)) {
  3584. return false;
  3585. }
  3586. var id = get$d(elem, "id");
  3587. return id !== void 0 && id.indexOf("aria-owns") > -1;
  3588. });
  3589. return dependent.bind(function(dep) {
  3590. var id = get$d(dep, "id");
  3591. var dos = getRootNode(dep);
  3592. return descendant(dos, '[aria-owns="' + id + '"]');
  3593. });
  3594. };
  3595. var manager = function() {
  3596. var ariaId = generate$6("aria-owns");
  3597. var link = function(elem) {
  3598. set$8(elem, "aria-owns", ariaId);
  3599. };
  3600. var unlink = function(elem) {
  3601. remove$7(elem, "aria-owns");
  3602. };
  3603. return {
  3604. id: ariaId,
  3605. link,
  3606. unlink
  3607. };
  3608. };
  3609. var isAriaPartOf = function(component, queryElem) {
  3610. return find$1(queryElem).exists(function(owner2) {
  3611. return isPartOf$1(component, owner2);
  3612. });
  3613. };
  3614. var isPartOf$1 = function(component, queryElem) {
  3615. return closest$2(queryElem, function(el) {
  3616. return eq(el, component.element);
  3617. }, never) || isAriaPartOf(component, queryElem);
  3618. };
  3619. var unknown = "unknown";
  3620. var EventConfiguration;
  3621. (function(EventConfiguration2) {
  3622. EventConfiguration2[EventConfiguration2["STOP"] = 0] = "STOP";
  3623. EventConfiguration2[EventConfiguration2["NORMAL"] = 1] = "NORMAL";
  3624. EventConfiguration2[EventConfiguration2["LOGGING"] = 2] = "LOGGING";
  3625. })(EventConfiguration || (EventConfiguration = {}));
  3626. var eventConfig = Cell({});
  3627. var makeEventLogger = function(eventName, initialTarget) {
  3628. var sequence2 = [];
  3629. var startTime = (/* @__PURE__ */ new Date()).getTime();
  3630. return {
  3631. logEventCut: function(_name, target, purpose) {
  3632. sequence2.push({
  3633. outcome: "cut",
  3634. target,
  3635. purpose
  3636. });
  3637. },
  3638. logEventStopped: function(_name, target, purpose) {
  3639. sequence2.push({
  3640. outcome: "stopped",
  3641. target,
  3642. purpose
  3643. });
  3644. },
  3645. logNoParent: function(_name, target, purpose) {
  3646. sequence2.push({
  3647. outcome: "no-parent",
  3648. target,
  3649. purpose
  3650. });
  3651. },
  3652. logEventNoHandlers: function(_name, target) {
  3653. sequence2.push({
  3654. outcome: "no-handlers-left",
  3655. target
  3656. });
  3657. },
  3658. logEventResponse: function(_name, target, purpose) {
  3659. sequence2.push({
  3660. outcome: "response",
  3661. purpose,
  3662. target
  3663. });
  3664. },
  3665. write: function() {
  3666. var finishTime = (/* @__PURE__ */ new Date()).getTime();
  3667. if (contains$2([
  3668. "mousemove",
  3669. "mouseover",
  3670. "mouseout",
  3671. systemInit()
  3672. ], eventName)) {
  3673. return;
  3674. }
  3675. console.log(eventName, {
  3676. event: eventName,
  3677. time: finishTime - startTime,
  3678. target: initialTarget.dom,
  3679. sequence: map$2(sequence2, function(s) {
  3680. if (!contains$2([
  3681. "cut",
  3682. "stopped",
  3683. "response"
  3684. ], s.outcome)) {
  3685. return s.outcome;
  3686. } else {
  3687. return "{" + s.purpose + "} " + s.outcome + " at (" + element(s.target) + ")";
  3688. }
  3689. })
  3690. });
  3691. }
  3692. };
  3693. };
  3694. var processEvent = function(eventName, initialTarget, f) {
  3695. var status = get$e(eventConfig.get(), eventName).orThunk(function() {
  3696. var patterns = keys(eventConfig.get());
  3697. return findMap(patterns, function(p) {
  3698. return eventName.indexOf(p) > -1 ? Optional.some(eventConfig.get()[p]) : Optional.none();
  3699. });
  3700. }).getOr(EventConfiguration.NORMAL);
  3701. switch (status) {
  3702. case EventConfiguration.NORMAL:
  3703. return f(noLogger());
  3704. case EventConfiguration.LOGGING: {
  3705. var logger = makeEventLogger(eventName, initialTarget);
  3706. var output2 = f(logger);
  3707. logger.write();
  3708. return output2;
  3709. }
  3710. case EventConfiguration.STOP:
  3711. return true;
  3712. }
  3713. };
  3714. var path = [
  3715. "alloy/data/Fields",
  3716. "alloy/debugging/Debugging"
  3717. ];
  3718. var getTrace = function() {
  3719. var err = new Error();
  3720. if (err.stack !== void 0) {
  3721. var lines = err.stack.split("\n");
  3722. return find$5(lines, function(line) {
  3723. return line.indexOf("alloy") > 0 && !exists(path, function(p) {
  3724. return line.indexOf(p) > -1;
  3725. });
  3726. }).getOr(unknown);
  3727. } else {
  3728. return unknown;
  3729. }
  3730. };
  3731. var ignoreEvent = {
  3732. logEventCut: noop,
  3733. logEventStopped: noop,
  3734. logNoParent: noop,
  3735. logEventNoHandlers: noop,
  3736. logEventResponse: noop,
  3737. write: noop
  3738. };
  3739. var monitorEvent = function(eventName, initialTarget, f) {
  3740. return processEvent(eventName, initialTarget, f);
  3741. };
  3742. var noLogger = constant$1(ignoreEvent);
  3743. var menuFields = constant$1([
  3744. required$1("menu"),
  3745. required$1("selectedMenu")
  3746. ]);
  3747. var itemFields = constant$1([
  3748. required$1("item"),
  3749. required$1("selectedItem")
  3750. ]);
  3751. constant$1(objOf(itemFields().concat(menuFields())));
  3752. var itemSchema$3 = constant$1(objOf(itemFields()));
  3753. var _initSize = requiredObjOf("initSize", [
  3754. required$1("numColumns"),
  3755. required$1("numRows")
  3756. ]);
  3757. var itemMarkers = function() {
  3758. return requiredOf("markers", itemSchema$3());
  3759. };
  3760. var tieredMenuMarkers = function() {
  3761. return requiredObjOf("markers", [required$1("backgroundMenu")].concat(menuFields()).concat(itemFields()));
  3762. };
  3763. var markers$1 = function(required2) {
  3764. return requiredObjOf("markers", map$2(required2, required$1));
  3765. };
  3766. var onPresenceHandler = function(label, fieldName, presence) {
  3767. getTrace();
  3768. return field$1(fieldName, fieldName, presence, valueOf(function(f) {
  3769. return Result.value(function() {
  3770. var args = [];
  3771. for (var _i = 0; _i < arguments.length; _i++) {
  3772. args[_i] = arguments[_i];
  3773. }
  3774. return f.apply(void 0, args);
  3775. });
  3776. }));
  3777. };
  3778. var onHandler = function(fieldName) {
  3779. return onPresenceHandler("onHandler", fieldName, defaulted$1(noop));
  3780. };
  3781. var onKeyboardHandler = function(fieldName) {
  3782. return onPresenceHandler("onKeyboardHandler", fieldName, defaulted$1(Optional.none));
  3783. };
  3784. var onStrictHandler = function(fieldName) {
  3785. return onPresenceHandler("onHandler", fieldName, required$2());
  3786. };
  3787. var onStrictKeyboardHandler = function(fieldName) {
  3788. return onPresenceHandler("onKeyboardHandler", fieldName, required$2());
  3789. };
  3790. var output$1 = function(name2, value2) {
  3791. return customField(name2, constant$1(value2));
  3792. };
  3793. var snapshot = function(name2) {
  3794. return customField(name2, identity$1);
  3795. };
  3796. var initSize = constant$1(_initSize);
  3797. var nu$6 = function(x, y, bubble, direction, placement2, boundsRestriction2, labelPrefix2, alwaysFit) {
  3798. if (alwaysFit === void 0) {
  3799. alwaysFit = false;
  3800. }
  3801. return {
  3802. x,
  3803. y,
  3804. bubble,
  3805. direction,
  3806. placement: placement2,
  3807. restriction: boundsRestriction2,
  3808. label: labelPrefix2 + "-" + placement2,
  3809. alwaysFit
  3810. };
  3811. };
  3812. var adt$a = Adt.generate([
  3813. { southeast: [] },
  3814. { southwest: [] },
  3815. { northeast: [] },
  3816. { northwest: [] },
  3817. { south: [] },
  3818. { north: [] },
  3819. { east: [] },
  3820. { west: [] }
  3821. ]);
  3822. var cata$2 = function(subject, southeast2, southwest2, northeast2, northwest2, south2, north2, east2, west2) {
  3823. return subject.fold(southeast2, southwest2, northeast2, northwest2, south2, north2, east2, west2);
  3824. };
  3825. var cataVertical = function(subject, south2, middle, north2) {
  3826. return subject.fold(south2, south2, north2, north2, south2, north2, middle, middle);
  3827. };
  3828. var cataHorizontal = function(subject, east2, middle, west2) {
  3829. return subject.fold(east2, west2, east2, west2, middle, middle, east2, west2);
  3830. };
  3831. var southeast$3 = adt$a.southeast;
  3832. var southwest$3 = adt$a.southwest;
  3833. var northeast$3 = adt$a.northeast;
  3834. var northwest$3 = adt$a.northwest;
  3835. var south$3 = adt$a.south;
  3836. var north$3 = adt$a.north;
  3837. var east$3 = adt$a.east;
  3838. var west$3 = adt$a.west;
  3839. var cycleBy = function(value2, delta, min2, max2) {
  3840. var r2 = value2 + delta;
  3841. if (r2 > max2) {
  3842. return min2;
  3843. } else if (r2 < min2) {
  3844. return max2;
  3845. } else {
  3846. return r2;
  3847. }
  3848. };
  3849. var clamp$1 = function(value2, min2, max2) {
  3850. return Math.min(Math.max(value2, min2), max2);
  3851. };
  3852. var getRestriction = function(anchor2, restriction) {
  3853. switch (restriction) {
  3854. case 1:
  3855. return anchor2.x;
  3856. case 0:
  3857. return anchor2.x + anchor2.width;
  3858. case 2:
  3859. return anchor2.y;
  3860. case 3:
  3861. return anchor2.y + anchor2.height;
  3862. }
  3863. };
  3864. var boundsRestriction = function(anchor2, restrictions) {
  3865. return mapToObject([
  3866. "left",
  3867. "right",
  3868. "top",
  3869. "bottom"
  3870. ], function(dir) {
  3871. return get$e(restrictions, dir).map(function(restriction) {
  3872. return getRestriction(anchor2, restriction);
  3873. });
  3874. });
  3875. };
  3876. var adjustBounds = function(bounds$12, restriction, bubbleOffset) {
  3877. var applyRestriction = function(dir, current) {
  3878. return restriction[dir].map(function(pos) {
  3879. var isVerticalAxis = dir === "top" || dir === "bottom";
  3880. var offset2 = isVerticalAxis ? bubbleOffset.top : bubbleOffset.left;
  3881. var comparator = dir === "left" || dir === "top" ? Math.max : Math.min;
  3882. var newPos = comparator(pos, current) + offset2;
  3883. return isVerticalAxis ? clamp$1(newPos, bounds$12.y, bounds$12.bottom) : clamp$1(newPos, bounds$12.x, bounds$12.right);
  3884. }).getOr(current);
  3885. };
  3886. var adjustedLeft = applyRestriction("left", bounds$12.x);
  3887. var adjustedTop = applyRestriction("top", bounds$12.y);
  3888. var adjustedRight = applyRestriction("right", bounds$12.right);
  3889. var adjustedBottom = applyRestriction("bottom", bounds$12.bottom);
  3890. return bounds(adjustedLeft, adjustedTop, adjustedRight - adjustedLeft, adjustedBottom - adjustedTop);
  3891. };
  3892. var labelPrefix$2 = "layout";
  3893. var eastX$1 = function(anchor2) {
  3894. return anchor2.x;
  3895. };
  3896. var middleX$1 = function(anchor2, element2) {
  3897. return anchor2.x + anchor2.width / 2 - element2.width / 2;
  3898. };
  3899. var westX$1 = function(anchor2, element2) {
  3900. return anchor2.x + anchor2.width - element2.width;
  3901. };
  3902. var northY$2 = function(anchor2, element2) {
  3903. return anchor2.y - element2.height;
  3904. };
  3905. var southY$2 = function(anchor2) {
  3906. return anchor2.y + anchor2.height;
  3907. };
  3908. var centreY$1 = function(anchor2, element2) {
  3909. return anchor2.y + anchor2.height / 2 - element2.height / 2;
  3910. };
  3911. var eastEdgeX$1 = function(anchor2) {
  3912. return anchor2.x + anchor2.width;
  3913. };
  3914. var westEdgeX$1 = function(anchor2, element2) {
  3915. return anchor2.x - element2.width;
  3916. };
  3917. var southeast$2 = function(anchor2, element2, bubbles) {
  3918. return nu$6(eastX$1(anchor2), southY$2(anchor2), bubbles.southeast(), southeast$3(), "southeast", boundsRestriction(anchor2, {
  3919. left: 1,
  3920. top: 3
  3921. }), labelPrefix$2);
  3922. };
  3923. var southwest$2 = function(anchor2, element2, bubbles) {
  3924. return nu$6(westX$1(anchor2, element2), southY$2(anchor2), bubbles.southwest(), southwest$3(), "southwest", boundsRestriction(anchor2, {
  3925. right: 0,
  3926. top: 3
  3927. }), labelPrefix$2);
  3928. };
  3929. var northeast$2 = function(anchor2, element2, bubbles) {
  3930. return nu$6(eastX$1(anchor2), northY$2(anchor2, element2), bubbles.northeast(), northeast$3(), "northeast", boundsRestriction(anchor2, {
  3931. left: 1,
  3932. bottom: 2
  3933. }), labelPrefix$2);
  3934. };
  3935. var northwest$2 = function(anchor2, element2, bubbles) {
  3936. return nu$6(westX$1(anchor2, element2), northY$2(anchor2, element2), bubbles.northwest(), northwest$3(), "northwest", boundsRestriction(anchor2, {
  3937. right: 0,
  3938. bottom: 2
  3939. }), labelPrefix$2);
  3940. };
  3941. var north$2 = function(anchor2, element2, bubbles) {
  3942. return nu$6(middleX$1(anchor2, element2), northY$2(anchor2, element2), bubbles.north(), north$3(), "north", boundsRestriction(anchor2, { bottom: 2 }), labelPrefix$2);
  3943. };
  3944. var south$2 = function(anchor2, element2, bubbles) {
  3945. return nu$6(middleX$1(anchor2, element2), southY$2(anchor2), bubbles.south(), south$3(), "south", boundsRestriction(anchor2, { top: 3 }), labelPrefix$2);
  3946. };
  3947. var east$2 = function(anchor2, element2, bubbles) {
  3948. return nu$6(eastEdgeX$1(anchor2), centreY$1(anchor2, element2), bubbles.east(), east$3(), "east", boundsRestriction(anchor2, { left: 0 }), labelPrefix$2);
  3949. };
  3950. var west$2 = function(anchor2, element2, bubbles) {
  3951. return nu$6(westEdgeX$1(anchor2, element2), centreY$1(anchor2, element2), bubbles.west(), west$3(), "west", boundsRestriction(anchor2, { right: 1 }), labelPrefix$2);
  3952. };
  3953. var all$1 = function() {
  3954. return [
  3955. southeast$2,
  3956. southwest$2,
  3957. northeast$2,
  3958. northwest$2,
  3959. south$2,
  3960. north$2,
  3961. east$2,
  3962. west$2
  3963. ];
  3964. };
  3965. var allRtl$1 = function() {
  3966. return [
  3967. southwest$2,
  3968. southeast$2,
  3969. northwest$2,
  3970. northeast$2,
  3971. south$2,
  3972. north$2,
  3973. east$2,
  3974. west$2
  3975. ];
  3976. };
  3977. var aboveOrBelow = function() {
  3978. return [
  3979. northeast$2,
  3980. northwest$2,
  3981. southeast$2,
  3982. southwest$2,
  3983. north$2,
  3984. south$2
  3985. ];
  3986. };
  3987. var aboveOrBelowRtl = function() {
  3988. return [
  3989. northwest$2,
  3990. northeast$2,
  3991. southwest$2,
  3992. southeast$2,
  3993. north$2,
  3994. south$2
  3995. ];
  3996. };
  3997. var belowOrAbove = function() {
  3998. return [
  3999. southeast$2,
  4000. southwest$2,
  4001. northeast$2,
  4002. northwest$2,
  4003. south$2,
  4004. north$2
  4005. ];
  4006. };
  4007. var belowOrAboveRtl = function() {
  4008. return [
  4009. southwest$2,
  4010. southeast$2,
  4011. northwest$2,
  4012. northeast$2,
  4013. south$2,
  4014. north$2
  4015. ];
  4016. };
  4017. var chooseChannels = function(channels, message) {
  4018. return message.universal ? channels : filter$2(channels, function(ch) {
  4019. return contains$2(message.channels, ch);
  4020. });
  4021. };
  4022. var events$h = function(receiveConfig) {
  4023. return derive$2([run$1(receive(), function(component, message) {
  4024. var channelMap = receiveConfig.channels;
  4025. var channels = keys(channelMap);
  4026. var receivingData = message;
  4027. var targetChannels = chooseChannels(channels, receivingData);
  4028. each$1(targetChannels, function(ch) {
  4029. var channelInfo = channelMap[ch];
  4030. var channelSchema = channelInfo.schema;
  4031. var data = asRawOrDie$1("channel[" + ch + "] data\nReceiver: " + element(component.element), channelSchema, receivingData.data);
  4032. channelInfo.onReceive(component, data);
  4033. });
  4034. })]);
  4035. };
  4036. var ActiveReceiving = Object.freeze({
  4037. __proto__: null,
  4038. events: events$h
  4039. });
  4040. var ReceivingSchema = [requiredOf("channels", setOf(Result.value, objOfOnly([
  4041. onStrictHandler("onReceive"),
  4042. defaulted("schema", anyValue())
  4043. ])))];
  4044. var executeEvent = function(bConfig, bState, executor) {
  4045. return runOnExecute$1(function(component) {
  4046. executor(component, bConfig, bState);
  4047. });
  4048. };
  4049. var loadEvent = function(bConfig, bState, f) {
  4050. return runOnInit(function(component, _simulatedEvent) {
  4051. f(component, bConfig, bState);
  4052. });
  4053. };
  4054. var create$9 = function(schema2, name2, active2, apis, extra, state) {
  4055. var configSchema = objOfOnly(schema2);
  4056. var schemaSchema = optionObjOf(name2, [optionObjOfOnly("config", schema2)]);
  4057. return doCreate(configSchema, schemaSchema, name2, active2, apis, extra, state);
  4058. };
  4059. var createModes$1 = function(modes, name2, active2, apis, extra, state) {
  4060. var configSchema = modes;
  4061. var schemaSchema = optionObjOf(name2, [optionOf("config", modes)]);
  4062. return doCreate(configSchema, schemaSchema, name2, active2, apis, extra, state);
  4063. };
  4064. var wrapApi = function(bName, apiFunction, apiName) {
  4065. var f = function(component) {
  4066. var rest = [];
  4067. for (var _i = 1; _i < arguments.length; _i++) {
  4068. rest[_i - 1] = arguments[_i];
  4069. }
  4070. var args = [component].concat(rest);
  4071. return component.config({ name: constant$1(bName) }).fold(function() {
  4072. throw new Error("We could not find any behaviour configuration for: " + bName + ". Using API: " + apiName);
  4073. }, function(info) {
  4074. var rest2 = Array.prototype.slice.call(args, 1);
  4075. return apiFunction.apply(void 0, [
  4076. component,
  4077. info.config,
  4078. info.state
  4079. ].concat(rest2));
  4080. });
  4081. };
  4082. return markAsBehaviourApi(f, apiName, apiFunction);
  4083. };
  4084. var revokeBehaviour = function(name2) {
  4085. return {
  4086. key: name2,
  4087. value: void 0
  4088. };
  4089. };
  4090. var doCreate = function(configSchema, schemaSchema, name2, active2, apis, extra, state) {
  4091. var getConfig = function(info) {
  4092. return hasNonNullableKey(info, name2) ? info[name2]() : Optional.none();
  4093. };
  4094. var wrappedApis = map$1(apis, function(apiF, apiName) {
  4095. return wrapApi(name2, apiF, apiName);
  4096. });
  4097. var wrappedExtra = map$1(extra, function(extraF, extraName) {
  4098. return markAsExtraApi(extraF, extraName);
  4099. });
  4100. var me = __assign(__assign(__assign({}, wrappedExtra), wrappedApis), {
  4101. revoke: curry(revokeBehaviour, name2),
  4102. config: function(spec) {
  4103. var prepared = asRawOrDie$1(name2 + "-config", configSchema, spec);
  4104. return {
  4105. key: name2,
  4106. value: {
  4107. config: prepared,
  4108. me,
  4109. configAsRaw: cached(function() {
  4110. return asRawOrDie$1(name2 + "-config", configSchema, spec);
  4111. }),
  4112. initialConfig: spec,
  4113. state
  4114. }
  4115. };
  4116. },
  4117. schema: constant$1(schemaSchema),
  4118. exhibit: function(info, base2) {
  4119. return lift2(getConfig(info), get$e(active2, "exhibit"), function(behaviourInfo, exhibitor) {
  4120. return exhibitor(base2, behaviourInfo.config, behaviourInfo.state);
  4121. }).getOrThunk(function() {
  4122. return nu$7({});
  4123. });
  4124. },
  4125. name: constant$1(name2),
  4126. handlers: function(info) {
  4127. return getConfig(info).map(function(behaviourInfo) {
  4128. var getEvents2 = get$e(active2, "events").getOr(function() {
  4129. return {};
  4130. });
  4131. return getEvents2(behaviourInfo.config, behaviourInfo.state);
  4132. }).getOr({});
  4133. }
  4134. });
  4135. return me;
  4136. };
  4137. var derive$1 = function(capabilities) {
  4138. return wrapAll(capabilities);
  4139. };
  4140. var simpleSchema = objOfOnly([
  4141. required$1("fields"),
  4142. required$1("name"),
  4143. defaulted("active", {}),
  4144. defaulted("apis", {}),
  4145. defaulted("state", NoState),
  4146. defaulted("extra", {})
  4147. ]);
  4148. var create$8 = function(data) {
  4149. var value2 = asRawOrDie$1("Creating behaviour: " + data.name, simpleSchema, data);
  4150. return create$9(value2.fields, value2.name, value2.active, value2.apis, value2.extra, value2.state);
  4151. };
  4152. var modeSchema = objOfOnly([
  4153. required$1("branchKey"),
  4154. required$1("branches"),
  4155. required$1("name"),
  4156. defaulted("active", {}),
  4157. defaulted("apis", {}),
  4158. defaulted("state", NoState),
  4159. defaulted("extra", {})
  4160. ]);
  4161. var createModes = function(data) {
  4162. var value2 = asRawOrDie$1("Creating behaviour: " + data.name, modeSchema, data);
  4163. return createModes$1(choose$1(value2.branchKey, value2.branches), value2.name, value2.active, value2.apis, value2.extra, value2.state);
  4164. };
  4165. var revoke = constant$1(void 0);
  4166. var Receiving = create$8({
  4167. fields: ReceivingSchema,
  4168. name: "receiving",
  4169. active: ActiveReceiving
  4170. });
  4171. var exhibit$6 = function(base2, posConfig) {
  4172. return nu$7({
  4173. classes: [],
  4174. styles: posConfig.useFixed() ? {} : { position: "relative" }
  4175. });
  4176. };
  4177. var ActivePosition = Object.freeze({
  4178. __proto__: null,
  4179. exhibit: exhibit$6
  4180. });
  4181. var getDocument = function() {
  4182. return SugarElement.fromDom(document);
  4183. };
  4184. var focus$3 = function(element2) {
  4185. return element2.dom.focus();
  4186. };
  4187. var blur$1 = function(element2) {
  4188. return element2.dom.blur();
  4189. };
  4190. var hasFocus = function(element2) {
  4191. var root = getRootNode(element2).dom;
  4192. return element2.dom === root.activeElement;
  4193. };
  4194. var active = function(root) {
  4195. if (root === void 0) {
  4196. root = getDocument();
  4197. }
  4198. return Optional.from(root.dom.activeElement).map(SugarElement.fromDom);
  4199. };
  4200. var search = function(element2) {
  4201. return active(getRootNode(element2)).filter(function(e) {
  4202. return element2.dom.contains(e.dom);
  4203. });
  4204. };
  4205. var preserve$1 = function(f, container) {
  4206. var dos = getRootNode(container);
  4207. var refocus = active(dos).bind(function(focused) {
  4208. var hasFocus2 = function(elem) {
  4209. return eq(focused, elem);
  4210. };
  4211. return hasFocus2(container) ? Optional.some(container) : descendant$1(container, hasFocus2);
  4212. });
  4213. var result = f(container);
  4214. refocus.each(function(oldFocus) {
  4215. active(dos).filter(function(newFocus) {
  4216. return eq(newFocus, oldFocus);
  4217. }).fold(function() {
  4218. focus$3(oldFocus);
  4219. }, noop);
  4220. });
  4221. return result;
  4222. };
  4223. var NuPositionCss = function(position2, left2, top2, right2, bottom2) {
  4224. var toPx = function(num) {
  4225. return num + "px";
  4226. };
  4227. return {
  4228. position: position2,
  4229. left: left2.map(toPx),
  4230. top: top2.map(toPx),
  4231. right: right2.map(toPx),
  4232. bottom: bottom2.map(toPx)
  4233. };
  4234. };
  4235. var toOptions = function(position2) {
  4236. return __assign(__assign({}, position2), { position: Optional.some(position2.position) });
  4237. };
  4238. var applyPositionCss = function(element2, position2) {
  4239. setOptions(element2, toOptions(position2));
  4240. };
  4241. var adt$9 = Adt.generate([
  4242. { none: [] },
  4243. {
  4244. relative: [
  4245. "x",
  4246. "y",
  4247. "width",
  4248. "height"
  4249. ]
  4250. },
  4251. {
  4252. fixed: [
  4253. "x",
  4254. "y",
  4255. "width",
  4256. "height"
  4257. ]
  4258. }
  4259. ]);
  4260. var positionWithDirection = function(posName, decision, x, y, width2, height2) {
  4261. var decisionRect = decision.rect;
  4262. var decisionX = decisionRect.x - x;
  4263. var decisionY = decisionRect.y - y;
  4264. var decisionWidth = decisionRect.width;
  4265. var decisionHeight = decisionRect.height;
  4266. var decisionRight = width2 - (decisionX + decisionWidth);
  4267. var decisionBottom = height2 - (decisionY + decisionHeight);
  4268. var left2 = Optional.some(decisionX);
  4269. var top2 = Optional.some(decisionY);
  4270. var right2 = Optional.some(decisionRight);
  4271. var bottom2 = Optional.some(decisionBottom);
  4272. var none2 = Optional.none();
  4273. return cata$2(decision.direction, function() {
  4274. return NuPositionCss(posName, left2, top2, none2, none2);
  4275. }, function() {
  4276. return NuPositionCss(posName, none2, top2, right2, none2);
  4277. }, function() {
  4278. return NuPositionCss(posName, left2, none2, none2, bottom2);
  4279. }, function() {
  4280. return NuPositionCss(posName, none2, none2, right2, bottom2);
  4281. }, function() {
  4282. return NuPositionCss(posName, left2, top2, none2, none2);
  4283. }, function() {
  4284. return NuPositionCss(posName, left2, none2, none2, bottom2);
  4285. }, function() {
  4286. return NuPositionCss(posName, left2, top2, none2, none2);
  4287. }, function() {
  4288. return NuPositionCss(posName, none2, top2, right2, none2);
  4289. });
  4290. };
  4291. var reposition = function(origin, decision) {
  4292. return origin.fold(function() {
  4293. var decisionRect = decision.rect;
  4294. return NuPositionCss("absolute", Optional.some(decisionRect.x), Optional.some(decisionRect.y), Optional.none(), Optional.none());
  4295. }, function(x, y, width2, height2) {
  4296. return positionWithDirection("absolute", decision, x, y, width2, height2);
  4297. }, function(x, y, width2, height2) {
  4298. return positionWithDirection("fixed", decision, x, y, width2, height2);
  4299. });
  4300. };
  4301. var toBox = function(origin, element2) {
  4302. var rel = curry(find$2, element2);
  4303. var position2 = origin.fold(rel, rel, function() {
  4304. var scroll = get$9();
  4305. return find$2(element2).translate(-scroll.left, -scroll.top);
  4306. });
  4307. var width2 = getOuter$1(element2);
  4308. var height2 = getOuter$2(element2);
  4309. return bounds(position2.left, position2.top, width2, height2);
  4310. };
  4311. var viewport = function(origin, getBounds2) {
  4312. return getBounds2.fold(function() {
  4313. return origin.fold(win, win, bounds);
  4314. }, function(b2) {
  4315. return origin.fold(b2, b2, function() {
  4316. var bounds$12 = b2();
  4317. var pos = translate$2(origin, bounds$12.x, bounds$12.y);
  4318. return bounds(pos.left, pos.top, bounds$12.width, bounds$12.height);
  4319. });
  4320. });
  4321. };
  4322. var translate$2 = function(origin, x, y) {
  4323. var pos = SugarPosition(x, y);
  4324. var removeScroll = function() {
  4325. var outerScroll = get$9();
  4326. return pos.translate(-outerScroll.left, -outerScroll.top);
  4327. };
  4328. return origin.fold(constant$1(pos), constant$1(pos), removeScroll);
  4329. };
  4330. var cata$1 = function(subject, onNone, onRelative, onFixed) {
  4331. return subject.fold(onNone, onRelative, onFixed);
  4332. };
  4333. adt$9.none;
  4334. var relative$1 = adt$9.relative;
  4335. var fixed$1 = adt$9.fixed;
  4336. var anchor = function(anchorBox, origin) {
  4337. return {
  4338. anchorBox,
  4339. origin
  4340. };
  4341. };
  4342. var box = function(anchorBox, origin) {
  4343. return anchor(anchorBox, origin);
  4344. };
  4345. var placementAttribute = "data-alloy-placement";
  4346. var setPlacement$1 = function(element2, placement2) {
  4347. set$8(element2, placementAttribute, placement2);
  4348. };
  4349. var getPlacement = function(element2) {
  4350. return getOpt(element2, placementAttribute);
  4351. };
  4352. var reset$2 = function(element2) {
  4353. return remove$7(element2, placementAttribute);
  4354. };
  4355. var adt$8 = Adt.generate([
  4356. { fit: ["reposition"] },
  4357. {
  4358. nofit: [
  4359. "reposition",
  4360. "visibleW",
  4361. "visibleH",
  4362. "isVisible"
  4363. ]
  4364. }
  4365. ]);
  4366. var determinePosition = function(box2, bounds2) {
  4367. var boundsX = bounds2.x, boundsY = bounds2.y, boundsRight = bounds2.right, boundsBottom = bounds2.bottom;
  4368. var x = box2.x, y = box2.y, right2 = box2.right, bottom2 = box2.bottom, width2 = box2.width, height2 = box2.height;
  4369. var xInBounds = x >= boundsX && x <= boundsRight;
  4370. var yInBounds = y >= boundsY && y <= boundsBottom;
  4371. var originInBounds = xInBounds && yInBounds;
  4372. var rightInBounds = right2 <= boundsRight && right2 >= boundsX;
  4373. var bottomInBounds = bottom2 <= boundsBottom && bottom2 >= boundsY;
  4374. var sizeInBounds = rightInBounds && bottomInBounds;
  4375. var visibleW = Math.min(width2, x >= boundsX ? boundsRight - x : right2 - boundsX);
  4376. var visibleH = Math.min(height2, y >= boundsY ? boundsBottom - y : bottom2 - boundsY);
  4377. return {
  4378. originInBounds,
  4379. sizeInBounds,
  4380. visibleW,
  4381. visibleH
  4382. };
  4383. };
  4384. var calcReposition = function(box2, bounds$12) {
  4385. var boundsX = bounds$12.x, boundsY = bounds$12.y, boundsRight = bounds$12.right, boundsBottom = bounds$12.bottom;
  4386. var x = box2.x, y = box2.y, width2 = box2.width, height2 = box2.height;
  4387. var maxX2 = Math.max(boundsX, boundsRight - width2);
  4388. var maxY2 = Math.max(boundsY, boundsBottom - height2);
  4389. var restrictedX = clamp$1(x, boundsX, maxX2);
  4390. var restrictedY = clamp$1(y, boundsY, maxY2);
  4391. var restrictedWidth = Math.min(restrictedX + width2, boundsRight) - restrictedX;
  4392. var restrictedHeight = Math.min(restrictedY + height2, boundsBottom) - restrictedY;
  4393. return bounds(restrictedX, restrictedY, restrictedWidth, restrictedHeight);
  4394. };
  4395. var calcMaxSizes = function(direction, box2, bounds2) {
  4396. var upAvailable = constant$1(box2.bottom - bounds2.y);
  4397. var downAvailable = constant$1(bounds2.bottom - box2.y);
  4398. var maxHeight = cataVertical(direction, downAvailable, downAvailable, upAvailable);
  4399. var westAvailable = constant$1(box2.right - bounds2.x);
  4400. var eastAvailable = constant$1(bounds2.right - box2.x);
  4401. var maxWidth = cataHorizontal(direction, eastAvailable, eastAvailable, westAvailable);
  4402. return {
  4403. maxWidth,
  4404. maxHeight
  4405. };
  4406. };
  4407. var attempt = function(candidate, width2, height2, bounds$12) {
  4408. var bubble = candidate.bubble;
  4409. var bubbleOffset = bubble.offset;
  4410. var adjustedBounds = adjustBounds(bounds$12, candidate.restriction, bubbleOffset);
  4411. var newX = candidate.x + bubbleOffset.left;
  4412. var newY = candidate.y + bubbleOffset.top;
  4413. var box2 = bounds(newX, newY, width2, height2);
  4414. var _a2 = determinePosition(box2, adjustedBounds), originInBounds = _a2.originInBounds, sizeInBounds = _a2.sizeInBounds, visibleW = _a2.visibleW, visibleH = _a2.visibleH;
  4415. var fits = originInBounds && sizeInBounds;
  4416. var fittedBox = fits ? box2 : calcReposition(box2, adjustedBounds);
  4417. var isPartlyVisible = fittedBox.width > 0 && fittedBox.height > 0;
  4418. var _b = calcMaxSizes(candidate.direction, fittedBox, bounds$12), maxWidth = _b.maxWidth, maxHeight = _b.maxHeight;
  4419. var reposition2 = {
  4420. rect: fittedBox,
  4421. maxHeight,
  4422. maxWidth,
  4423. direction: candidate.direction,
  4424. placement: candidate.placement,
  4425. classes: {
  4426. on: bubble.classesOn,
  4427. off: bubble.classesOff
  4428. },
  4429. layout: candidate.label,
  4430. testY: newY
  4431. };
  4432. return fits || candidate.alwaysFit ? adt$8.fit(reposition2) : adt$8.nofit(reposition2, visibleW, visibleH, isPartlyVisible);
  4433. };
  4434. var attempts = function(element2, candidates, anchorBox, elementBox, bubbles, bounds2) {
  4435. var panelWidth = elementBox.width;
  4436. var panelHeight = elementBox.height;
  4437. var attemptBestFit = function(layout2, reposition2, visibleW, visibleH, isVisible2) {
  4438. var next = layout2(anchorBox, elementBox, bubbles, element2, bounds2);
  4439. var attemptLayout = attempt(next, panelWidth, panelHeight, bounds2);
  4440. return attemptLayout.fold(constant$1(attemptLayout), function(newReposition, newVisibleW, newVisibleH, newIsVisible) {
  4441. var improved = isVisible2 === newIsVisible ? newVisibleH > visibleH || newVisibleW > visibleW : !isVisible2 && newIsVisible;
  4442. return improved ? attemptLayout : adt$8.nofit(reposition2, visibleW, visibleH, isVisible2);
  4443. });
  4444. };
  4445. var abc = foldl(candidates, function(b2, a) {
  4446. var bestNext = curry(attemptBestFit, a);
  4447. return b2.fold(constant$1(b2), bestNext);
  4448. }, adt$8.nofit({
  4449. rect: anchorBox,
  4450. maxHeight: elementBox.height,
  4451. maxWidth: elementBox.width,
  4452. direction: southeast$3(),
  4453. placement: "southeast",
  4454. classes: {
  4455. on: [],
  4456. off: []
  4457. },
  4458. layout: "none",
  4459. testY: anchorBox.y
  4460. }, -1, -1, false));
  4461. return abc.fold(identity$1, identity$1);
  4462. };
  4463. var singleton = function(doRevoke) {
  4464. var subject = Cell(Optional.none());
  4465. var revoke2 = function() {
  4466. return subject.get().each(doRevoke);
  4467. };
  4468. var clear2 = function() {
  4469. revoke2();
  4470. subject.set(Optional.none());
  4471. };
  4472. var isSet = function() {
  4473. return subject.get().isSome();
  4474. };
  4475. var get2 = function() {
  4476. return subject.get();
  4477. };
  4478. var set2 = function(s) {
  4479. revoke2();
  4480. subject.set(Optional.some(s));
  4481. };
  4482. return {
  4483. clear: clear2,
  4484. isSet,
  4485. get: get2,
  4486. set: set2
  4487. };
  4488. };
  4489. var destroyable = function() {
  4490. return singleton(function(s) {
  4491. return s.destroy();
  4492. });
  4493. };
  4494. var unbindable = function() {
  4495. return singleton(function(s) {
  4496. return s.unbind();
  4497. });
  4498. };
  4499. var api$1 = function() {
  4500. var subject = destroyable();
  4501. var run2 = function(f) {
  4502. return subject.get().each(f);
  4503. };
  4504. return __assign(__assign({}, subject), { run: run2 });
  4505. };
  4506. var value$1 = function() {
  4507. var subject = singleton(noop);
  4508. var on2 = function(f) {
  4509. return subject.get().each(f);
  4510. };
  4511. return __assign(__assign({}, subject), { on: on2 });
  4512. };
  4513. var filter = always;
  4514. var bind = function(element2, event, handler) {
  4515. return bind$2(element2, event, filter, handler);
  4516. };
  4517. var capture = function(element2, event, handler) {
  4518. return capture$1(element2, event, filter, handler);
  4519. };
  4520. var fromRawEvent = fromRawEvent$1;
  4521. var properties = [
  4522. "top",
  4523. "bottom",
  4524. "right",
  4525. "left"
  4526. ];
  4527. var timerAttr = "data-alloy-transition-timer";
  4528. var isTransitioning$1 = function(element2, transition) {
  4529. return hasAll(element2, transition.classes);
  4530. };
  4531. var shouldApplyTransitionCss = function(transition, decision, lastPlacement) {
  4532. return lastPlacement.exists(function(placer) {
  4533. var mode = transition.mode;
  4534. return mode === "all" ? true : placer[mode] !== decision[mode];
  4535. });
  4536. };
  4537. var hasChanges = function(position2, intermediate) {
  4538. var round2 = function(value2) {
  4539. return parseFloat(value2).toFixed(3);
  4540. };
  4541. return find$4(intermediate, function(value2, key) {
  4542. var newValue = position2[key].map(round2);
  4543. var val = value2.map(round2);
  4544. return !equals(newValue, val);
  4545. }).isSome();
  4546. };
  4547. var getTransitionDuration = function(element2) {
  4548. var get2 = function(name2) {
  4549. var style = get$c(element2, name2);
  4550. var times = isString(style) ? style.split(/\s*,\s*/) : [];
  4551. return filter$2(times, isNotEmpty);
  4552. };
  4553. var parse2 = function(value2) {
  4554. if (isString(value2) && /^[\d.]+/.test(value2)) {
  4555. var num = parseFloat(value2);
  4556. return endsWith(value2, "ms") ? num : num * 1e3;
  4557. } else {
  4558. return 0;
  4559. }
  4560. };
  4561. var delay = get2("transition-delay");
  4562. var duration = get2("transition-duration");
  4563. return foldl(duration, function(acc, dur, i) {
  4564. var time = parse2(delay[i]) + parse2(dur);
  4565. return Math.max(acc, time);
  4566. }, 0);
  4567. };
  4568. var setupTransitionListeners = function(element2, transition) {
  4569. var transitionEnd = unbindable();
  4570. var transitionCancel = unbindable();
  4571. var timer;
  4572. var isSourceTransition = function(e) {
  4573. var _a2;
  4574. var pseudoElement = (_a2 = e.raw.pseudoElement) !== null && _a2 !== void 0 ? _a2 : "";
  4575. return eq(e.target, element2) && isEmpty(pseudoElement) && contains$2(properties, e.raw.propertyName);
  4576. };
  4577. var transitionDone = function(e) {
  4578. if (isNullable(e) || isSourceTransition(e)) {
  4579. transitionEnd.clear();
  4580. transitionCancel.clear();
  4581. var type2 = e === null || e === void 0 ? void 0 : e.raw.type;
  4582. if (isNullable(type2) || type2 === transitionend()) {
  4583. clearTimeout(timer);
  4584. remove$7(element2, timerAttr);
  4585. remove$1(element2, transition.classes);
  4586. }
  4587. }
  4588. };
  4589. var transitionStarted = function() {
  4590. transitionEnd.set(bind(element2, transitionend(), transitionDone));
  4591. transitionCancel.set(bind(element2, transitioncancel(), transitionDone));
  4592. };
  4593. if ("ontransitionstart" in element2.dom) {
  4594. var transitionStart_1 = bind(element2, transitionstart(), function(e) {
  4595. if (isSourceTransition(e)) {
  4596. transitionStart_1.unbind();
  4597. transitionStarted();
  4598. }
  4599. });
  4600. } else {
  4601. transitionStarted();
  4602. }
  4603. var duration = getTransitionDuration(element2);
  4604. requestAnimationFrame(function() {
  4605. timer = setTimeout(transitionDone, duration + 17);
  4606. set$8(element2, timerAttr, timer);
  4607. });
  4608. };
  4609. var startTransitioning = function(element2, transition) {
  4610. add$1(element2, transition.classes);
  4611. getOpt(element2, timerAttr).each(function(timerId) {
  4612. clearTimeout(parseInt(timerId, 10));
  4613. remove$7(element2, timerAttr);
  4614. });
  4615. setupTransitionListeners(element2, transition);
  4616. };
  4617. var applyTransitionCss = function(element2, origin, position2, transition, decision, lastPlacement) {
  4618. var shouldTransition = shouldApplyTransitionCss(transition, decision, lastPlacement);
  4619. if (shouldTransition || isTransitioning$1(element2, transition)) {
  4620. set$7(element2, "position", position2.position);
  4621. var rect2 = toBox(origin, element2);
  4622. var intermediatePosition_1 = reposition(origin, __assign(__assign({}, decision), { rect: rect2 }));
  4623. var intermediateCssOptions = mapToObject(properties, function(prop) {
  4624. return intermediatePosition_1[prop];
  4625. });
  4626. if (hasChanges(position2, intermediateCssOptions)) {
  4627. setOptions(element2, intermediateCssOptions);
  4628. if (shouldTransition) {
  4629. startTransitioning(element2, transition);
  4630. }
  4631. reflow(element2);
  4632. }
  4633. } else {
  4634. remove$1(element2, transition.classes);
  4635. }
  4636. };
  4637. var elementSize = function(p) {
  4638. return {
  4639. width: getOuter$1(p),
  4640. height: getOuter$2(p)
  4641. };
  4642. };
  4643. var layout = function(anchorBox, element2, bubbles, options) {
  4644. remove$6(element2, "max-height");
  4645. remove$6(element2, "max-width");
  4646. var elementBox = elementSize(element2);
  4647. return attempts(element2, options.preference, anchorBox, elementBox, bubbles, options.bounds);
  4648. };
  4649. var setClasses = function(element2, decision) {
  4650. var classInfo = decision.classes;
  4651. remove$1(element2, classInfo.off);
  4652. add$1(element2, classInfo.on);
  4653. };
  4654. var setHeight = function(element2, decision, options) {
  4655. var maxHeightFunction = options.maxHeightFunction;
  4656. maxHeightFunction(element2, decision.maxHeight);
  4657. };
  4658. var setWidth = function(element2, decision, options) {
  4659. var maxWidthFunction = options.maxWidthFunction;
  4660. maxWidthFunction(element2, decision.maxWidth);
  4661. };
  4662. var position$2 = function(element2, decision, options) {
  4663. var positionCss = reposition(options.origin, decision);
  4664. options.transition.each(function(transition) {
  4665. applyTransitionCss(element2, options.origin, positionCss, transition, decision, options.lastPlacement);
  4666. });
  4667. applyPositionCss(element2, positionCss);
  4668. };
  4669. var setPlacement = function(element2, decision) {
  4670. setPlacement$1(element2, decision.placement);
  4671. };
  4672. var setMaxHeight = function(element2, maxHeight) {
  4673. setMax$1(element2, Math.floor(maxHeight));
  4674. };
  4675. var anchored = constant$1(function(element2, available) {
  4676. setMaxHeight(element2, available);
  4677. setAll(element2, {
  4678. "overflow-x": "hidden",
  4679. "overflow-y": "auto"
  4680. });
  4681. });
  4682. var expandable$1 = constant$1(function(element2, available) {
  4683. setMaxHeight(element2, available);
  4684. });
  4685. var defaultOr = function(options, key, dephault) {
  4686. return options[key] === void 0 ? dephault : options[key];
  4687. };
  4688. var simple = function(anchor2, element2, bubble, layouts2, lastPlacement, getBounds2, overrideOptions, transition) {
  4689. var maxHeightFunction = defaultOr(overrideOptions, "maxHeightFunction", anchored());
  4690. var maxWidthFunction = defaultOr(overrideOptions, "maxWidthFunction", noop);
  4691. var anchorBox = anchor2.anchorBox;
  4692. var origin = anchor2.origin;
  4693. var options = {
  4694. bounds: viewport(origin, getBounds2),
  4695. origin,
  4696. preference: layouts2,
  4697. maxHeightFunction,
  4698. maxWidthFunction,
  4699. lastPlacement,
  4700. transition
  4701. };
  4702. return go(anchorBox, element2, bubble, options);
  4703. };
  4704. var go = function(anchorBox, element2, bubble, options) {
  4705. var decision = layout(anchorBox, element2, bubble, options);
  4706. position$2(element2, decision, options);
  4707. setPlacement(element2, decision);
  4708. setClasses(element2, decision);
  4709. setHeight(element2, decision, options);
  4710. setWidth(element2, decision, options);
  4711. return {
  4712. layout: decision.layout,
  4713. placement: decision.placement
  4714. };
  4715. };
  4716. var allAlignments = [
  4717. "valignCentre",
  4718. "alignLeft",
  4719. "alignRight",
  4720. "alignCentre",
  4721. "top",
  4722. "bottom",
  4723. "left",
  4724. "right",
  4725. "inset"
  4726. ];
  4727. var nu$5 = function(xOffset, yOffset, classes2, insetModifier) {
  4728. if (insetModifier === void 0) {
  4729. insetModifier = 1;
  4730. }
  4731. var insetXOffset = xOffset * insetModifier;
  4732. var insetYOffset = yOffset * insetModifier;
  4733. var getClasses2 = function(prop) {
  4734. return get$e(classes2, prop).getOr([]);
  4735. };
  4736. var make2 = function(xDelta, yDelta, alignmentsOn) {
  4737. var alignmentsOff = difference(allAlignments, alignmentsOn);
  4738. return {
  4739. offset: SugarPosition(xDelta, yDelta),
  4740. classesOn: bind$3(alignmentsOn, getClasses2),
  4741. classesOff: bind$3(alignmentsOff, getClasses2)
  4742. };
  4743. };
  4744. return {
  4745. southeast: function() {
  4746. return make2(-xOffset, yOffset, [
  4747. "top",
  4748. "alignLeft"
  4749. ]);
  4750. },
  4751. southwest: function() {
  4752. return make2(xOffset, yOffset, [
  4753. "top",
  4754. "alignRight"
  4755. ]);
  4756. },
  4757. south: function() {
  4758. return make2(-xOffset / 2, yOffset, [
  4759. "top",
  4760. "alignCentre"
  4761. ]);
  4762. },
  4763. northeast: function() {
  4764. return make2(-xOffset, -yOffset, [
  4765. "bottom",
  4766. "alignLeft"
  4767. ]);
  4768. },
  4769. northwest: function() {
  4770. return make2(xOffset, -yOffset, [
  4771. "bottom",
  4772. "alignRight"
  4773. ]);
  4774. },
  4775. north: function() {
  4776. return make2(-xOffset / 2, -yOffset, [
  4777. "bottom",
  4778. "alignCentre"
  4779. ]);
  4780. },
  4781. east: function() {
  4782. return make2(xOffset, -yOffset / 2, [
  4783. "valignCentre",
  4784. "left"
  4785. ]);
  4786. },
  4787. west: function() {
  4788. return make2(-xOffset, -yOffset / 2, [
  4789. "valignCentre",
  4790. "right"
  4791. ]);
  4792. },
  4793. insetNortheast: function() {
  4794. return make2(insetXOffset, insetYOffset, [
  4795. "top",
  4796. "alignLeft",
  4797. "inset"
  4798. ]);
  4799. },
  4800. insetNorthwest: function() {
  4801. return make2(-insetXOffset, insetYOffset, [
  4802. "top",
  4803. "alignRight",
  4804. "inset"
  4805. ]);
  4806. },
  4807. insetNorth: function() {
  4808. return make2(-insetXOffset / 2, insetYOffset, [
  4809. "top",
  4810. "alignCentre",
  4811. "inset"
  4812. ]);
  4813. },
  4814. insetSoutheast: function() {
  4815. return make2(insetXOffset, -insetYOffset, [
  4816. "bottom",
  4817. "alignLeft",
  4818. "inset"
  4819. ]);
  4820. },
  4821. insetSouthwest: function() {
  4822. return make2(-insetXOffset, -insetYOffset, [
  4823. "bottom",
  4824. "alignRight",
  4825. "inset"
  4826. ]);
  4827. },
  4828. insetSouth: function() {
  4829. return make2(-insetXOffset / 2, -insetYOffset, [
  4830. "bottom",
  4831. "alignCentre",
  4832. "inset"
  4833. ]);
  4834. },
  4835. insetEast: function() {
  4836. return make2(-insetXOffset, -insetYOffset / 2, [
  4837. "valignCentre",
  4838. "right",
  4839. "inset"
  4840. ]);
  4841. },
  4842. insetWest: function() {
  4843. return make2(insetXOffset, -insetYOffset / 2, [
  4844. "valignCentre",
  4845. "left",
  4846. "inset"
  4847. ]);
  4848. }
  4849. };
  4850. };
  4851. var fallback = function() {
  4852. return nu$5(0, 0, {});
  4853. };
  4854. var nu$4 = identity$1;
  4855. var onDirection = function(isLtr, isRtl) {
  4856. return function(element2) {
  4857. return getDirection(element2) === "rtl" ? isRtl : isLtr;
  4858. };
  4859. };
  4860. var getDirection = function(element2) {
  4861. return get$c(element2, "direction") === "rtl" ? "rtl" : "ltr";
  4862. };
  4863. var AttributeValue;
  4864. (function(AttributeValue2) {
  4865. AttributeValue2["TopToBottom"] = "toptobottom";
  4866. AttributeValue2["BottomToTop"] = "bottomtotop";
  4867. })(AttributeValue || (AttributeValue = {}));
  4868. var Attribute = "data-alloy-vertical-dir";
  4869. var isBottomToTopDir = function(el) {
  4870. return closest$2(el, function(current) {
  4871. return isElement$2(current) && get$d(current, "data-alloy-vertical-dir") === AttributeValue.BottomToTop;
  4872. });
  4873. };
  4874. var schema$y = function() {
  4875. return optionObjOf("layouts", [
  4876. required$1("onLtr"),
  4877. required$1("onRtl"),
  4878. option("onBottomLtr"),
  4879. option("onBottomRtl")
  4880. ]);
  4881. };
  4882. var get$4 = function(elem, info, defaultLtr, defaultRtl, defaultBottomLtr, defaultBottomRtl, dirElement) {
  4883. var isBottomToTop = dirElement.map(isBottomToTopDir).getOr(false);
  4884. var customLtr = info.layouts.map(function(ls) {
  4885. return ls.onLtr(elem);
  4886. });
  4887. var customRtl = info.layouts.map(function(ls) {
  4888. return ls.onRtl(elem);
  4889. });
  4890. var ltr = isBottomToTop ? info.layouts.bind(function(ls) {
  4891. return ls.onBottomLtr.map(function(f2) {
  4892. return f2(elem);
  4893. });
  4894. }).or(customLtr).getOr(defaultBottomLtr) : customLtr.getOr(defaultLtr);
  4895. var rtl = isBottomToTop ? info.layouts.bind(function(ls) {
  4896. return ls.onBottomRtl.map(function(f2) {
  4897. return f2(elem);
  4898. });
  4899. }).or(customRtl).getOr(defaultBottomRtl) : customRtl.getOr(defaultRtl);
  4900. var f = onDirection(ltr, rtl);
  4901. return f(elem);
  4902. };
  4903. var placement$4 = function(component, anchorInfo, origin) {
  4904. var hotspot = anchorInfo.hotspot;
  4905. var anchorBox = toBox(origin, hotspot.element);
  4906. var layouts2 = get$4(component.element, anchorInfo, belowOrAbove(), belowOrAboveRtl(), aboveOrBelow(), aboveOrBelowRtl(), Optional.some(anchorInfo.hotspot.element));
  4907. return Optional.some(nu$4({
  4908. anchorBox,
  4909. bubble: anchorInfo.bubble.getOr(fallback()),
  4910. overrides: anchorInfo.overrides,
  4911. layouts: layouts2,
  4912. placer: Optional.none()
  4913. }));
  4914. };
  4915. var HotspotAnchor = [
  4916. required$1("hotspot"),
  4917. option("bubble"),
  4918. defaulted("overrides", {}),
  4919. schema$y(),
  4920. output$1("placement", placement$4)
  4921. ];
  4922. var placement$3 = function(component, anchorInfo, origin) {
  4923. var pos = translate$2(origin, anchorInfo.x, anchorInfo.y);
  4924. var anchorBox = bounds(pos.left, pos.top, anchorInfo.width, anchorInfo.height);
  4925. var layouts2 = get$4(component.element, anchorInfo, all$1(), allRtl$1(), all$1(), allRtl$1(), Optional.none());
  4926. return Optional.some(nu$4({
  4927. anchorBox,
  4928. bubble: anchorInfo.bubble,
  4929. overrides: anchorInfo.overrides,
  4930. layouts: layouts2,
  4931. placer: Optional.none()
  4932. }));
  4933. };
  4934. var MakeshiftAnchor = [
  4935. required$1("x"),
  4936. required$1("y"),
  4937. defaulted("height", 0),
  4938. defaulted("width", 0),
  4939. defaulted("bubble", fallback()),
  4940. defaulted("overrides", {}),
  4941. schema$y(),
  4942. output$1("placement", placement$3)
  4943. ];
  4944. var adt$7 = Adt.generate([
  4945. { screen: ["point"] },
  4946. {
  4947. absolute: [
  4948. "point",
  4949. "scrollLeft",
  4950. "scrollTop"
  4951. ]
  4952. }
  4953. ]);
  4954. var toFixed = function(pos) {
  4955. return pos.fold(identity$1, function(point2, scrollLeft, scrollTop) {
  4956. return point2.translate(-scrollLeft, -scrollTop);
  4957. });
  4958. };
  4959. var toAbsolute = function(pos) {
  4960. return pos.fold(identity$1, identity$1);
  4961. };
  4962. var sum = function(points) {
  4963. return foldl(points, function(b2, a) {
  4964. return b2.translate(a.left, a.top);
  4965. }, SugarPosition(0, 0));
  4966. };
  4967. var sumAsFixed = function(positions) {
  4968. var points = map$2(positions, toFixed);
  4969. return sum(points);
  4970. };
  4971. var sumAsAbsolute = function(positions) {
  4972. var points = map$2(positions, toAbsolute);
  4973. return sum(points);
  4974. };
  4975. var screen = adt$7.screen;
  4976. var absolute$1 = adt$7.absolute;
  4977. var getOffset = function(component, origin, anchorInfo) {
  4978. var win2 = defaultView(anchorInfo.root).dom;
  4979. var hasSameOwner = function(frame) {
  4980. var frameOwner = owner$4(frame);
  4981. var compOwner = owner$4(component.element);
  4982. return eq(frameOwner, compOwner);
  4983. };
  4984. return Optional.from(win2.frameElement).map(SugarElement.fromDom).filter(hasSameOwner).map(absolute$3);
  4985. };
  4986. var getRootPoint = function(component, origin, anchorInfo) {
  4987. var doc = owner$4(component.element);
  4988. var outerScroll = get$9(doc);
  4989. var offset2 = getOffset(component, origin, anchorInfo).getOr(outerScroll);
  4990. return absolute$1(offset2, outerScroll.left, outerScroll.top);
  4991. };
  4992. var getBox = function(left2, top2, width2, height2) {
  4993. var point2 = screen(SugarPosition(left2, top2));
  4994. return Optional.some(pointed(point2, width2, height2));
  4995. };
  4996. var calcNewAnchor = function(optBox, rootPoint, anchorInfo, origin, elem) {
  4997. return optBox.map(function(box2) {
  4998. var points = [
  4999. rootPoint,
  5000. box2.point
  5001. ];
  5002. var topLeft = cata$1(origin, function() {
  5003. return sumAsAbsolute(points);
  5004. }, function() {
  5005. return sumAsAbsolute(points);
  5006. }, function() {
  5007. return sumAsFixed(points);
  5008. });
  5009. var anchorBox = rect(topLeft.left, topLeft.top, box2.width, box2.height);
  5010. var layoutsLtr = anchorInfo.showAbove ? aboveOrBelow() : belowOrAbove();
  5011. var layoutsRtl = anchorInfo.showAbove ? aboveOrBelowRtl() : belowOrAboveRtl();
  5012. var layouts2 = get$4(elem, anchorInfo, layoutsLtr, layoutsRtl, layoutsLtr, layoutsRtl, Optional.none());
  5013. return nu$4({
  5014. anchorBox,
  5015. bubble: anchorInfo.bubble.getOr(fallback()),
  5016. overrides: anchorInfo.overrides,
  5017. layouts: layouts2,
  5018. placer: Optional.none()
  5019. });
  5020. });
  5021. };
  5022. var placement$2 = function(component, anchorInfo, origin) {
  5023. var rootPoint = getRootPoint(component, origin, anchorInfo);
  5024. return anchorInfo.node.filter(inBody).bind(function(target) {
  5025. var rect2 = target.dom.getBoundingClientRect();
  5026. var nodeBox = getBox(rect2.left, rect2.top, rect2.width, rect2.height);
  5027. var elem = anchorInfo.node.getOr(component.element);
  5028. return calcNewAnchor(nodeBox, rootPoint, anchorInfo, origin, elem);
  5029. });
  5030. };
  5031. var NodeAnchor = [
  5032. required$1("node"),
  5033. required$1("root"),
  5034. option("bubble"),
  5035. schema$y(),
  5036. defaulted("overrides", {}),
  5037. defaulted("showAbove", false),
  5038. output$1("placement", placement$2)
  5039. ];
  5040. var zeroWidth = "\uFEFF";
  5041. var nbsp = " ";
  5042. var create$7 = function(start, soffset, finish, foffset) {
  5043. return {
  5044. start,
  5045. soffset,
  5046. finish,
  5047. foffset
  5048. };
  5049. };
  5050. var SimRange = { create: create$7 };
  5051. var adt$6 = Adt.generate([
  5052. { before: ["element"] },
  5053. {
  5054. on: [
  5055. "element",
  5056. "offset"
  5057. ]
  5058. },
  5059. { after: ["element"] }
  5060. ]);
  5061. var cata = function(subject, onBefore, onOn, onAfter) {
  5062. return subject.fold(onBefore, onOn, onAfter);
  5063. };
  5064. var getStart$1 = function(situ) {
  5065. return situ.fold(identity$1, identity$1, identity$1);
  5066. };
  5067. var before = adt$6.before;
  5068. var on$1 = adt$6.on;
  5069. var after$1 = adt$6.after;
  5070. var Situ = {
  5071. before,
  5072. on: on$1,
  5073. after: after$1,
  5074. cata,
  5075. getStart: getStart$1
  5076. };
  5077. var adt$5 = Adt.generate([
  5078. { domRange: ["rng"] },
  5079. {
  5080. relative: [
  5081. "startSitu",
  5082. "finishSitu"
  5083. ]
  5084. },
  5085. {
  5086. exact: [
  5087. "start",
  5088. "soffset",
  5089. "finish",
  5090. "foffset"
  5091. ]
  5092. }
  5093. ]);
  5094. var exactFromRange = function(simRange) {
  5095. return adt$5.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset);
  5096. };
  5097. var getStart = function(selection) {
  5098. return selection.match({
  5099. domRange: function(rng) {
  5100. return SugarElement.fromDom(rng.startContainer);
  5101. },
  5102. relative: function(startSitu, _finishSitu) {
  5103. return Situ.getStart(startSitu);
  5104. },
  5105. exact: function(start, _soffset, _finish, _foffset) {
  5106. return start;
  5107. }
  5108. });
  5109. };
  5110. var domRange = adt$5.domRange;
  5111. var relative = adt$5.relative;
  5112. var exact = adt$5.exact;
  5113. var getWin = function(selection) {
  5114. var start = getStart(selection);
  5115. return defaultView(start);
  5116. };
  5117. var range$1 = SimRange.create;
  5118. var SimSelection = {
  5119. domRange,
  5120. relative,
  5121. exact,
  5122. exactFromRange,
  5123. getWin,
  5124. range: range$1
  5125. };
  5126. var setStart = function(rng, situ) {
  5127. situ.fold(function(e) {
  5128. rng.setStartBefore(e.dom);
  5129. }, function(e, o) {
  5130. rng.setStart(e.dom, o);
  5131. }, function(e) {
  5132. rng.setStartAfter(e.dom);
  5133. });
  5134. };
  5135. var setFinish = function(rng, situ) {
  5136. situ.fold(function(e) {
  5137. rng.setEndBefore(e.dom);
  5138. }, function(e, o) {
  5139. rng.setEnd(e.dom, o);
  5140. }, function(e) {
  5141. rng.setEndAfter(e.dom);
  5142. });
  5143. };
  5144. var relativeToNative = function(win2, startSitu, finishSitu) {
  5145. var range2 = win2.document.createRange();
  5146. setStart(range2, startSitu);
  5147. setFinish(range2, finishSitu);
  5148. return range2;
  5149. };
  5150. var exactToNative = function(win2, start, soffset, finish, foffset) {
  5151. var rng = win2.document.createRange();
  5152. rng.setStart(start.dom, soffset);
  5153. rng.setEnd(finish.dom, foffset);
  5154. return rng;
  5155. };
  5156. var toRect = function(rect2) {
  5157. return {
  5158. left: rect2.left,
  5159. top: rect2.top,
  5160. right: rect2.right,
  5161. bottom: rect2.bottom,
  5162. width: rect2.width,
  5163. height: rect2.height
  5164. };
  5165. };
  5166. var getFirstRect$1 = function(rng) {
  5167. var rects = rng.getClientRects();
  5168. var rect2 = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
  5169. return rect2.width > 0 || rect2.height > 0 ? Optional.some(rect2).map(toRect) : Optional.none();
  5170. };
  5171. var getBounds$2 = function(rng) {
  5172. var rect2 = rng.getBoundingClientRect();
  5173. return rect2.width > 0 || rect2.height > 0 ? Optional.some(rect2).map(toRect) : Optional.none();
  5174. };
  5175. var adt$4 = Adt.generate([
  5176. {
  5177. ltr: [
  5178. "start",
  5179. "soffset",
  5180. "finish",
  5181. "foffset"
  5182. ]
  5183. },
  5184. {
  5185. rtl: [
  5186. "start",
  5187. "soffset",
  5188. "finish",
  5189. "foffset"
  5190. ]
  5191. }
  5192. ]);
  5193. var fromRange = function(win2, type2, range2) {
  5194. return type2(SugarElement.fromDom(range2.startContainer), range2.startOffset, SugarElement.fromDom(range2.endContainer), range2.endOffset);
  5195. };
  5196. var getRanges = function(win2, selection) {
  5197. return selection.match({
  5198. domRange: function(rng) {
  5199. return {
  5200. ltr: constant$1(rng),
  5201. rtl: Optional.none
  5202. };
  5203. },
  5204. relative: function(startSitu, finishSitu) {
  5205. return {
  5206. ltr: cached(function() {
  5207. return relativeToNative(win2, startSitu, finishSitu);
  5208. }),
  5209. rtl: cached(function() {
  5210. return Optional.some(relativeToNative(win2, finishSitu, startSitu));
  5211. })
  5212. };
  5213. },
  5214. exact: function(start, soffset, finish, foffset) {
  5215. return {
  5216. ltr: cached(function() {
  5217. return exactToNative(win2, start, soffset, finish, foffset);
  5218. }),
  5219. rtl: cached(function() {
  5220. return Optional.some(exactToNative(win2, finish, foffset, start, soffset));
  5221. })
  5222. };
  5223. }
  5224. });
  5225. };
  5226. var doDiagnose = function(win2, ranges) {
  5227. var rng = ranges.ltr();
  5228. if (rng.collapsed) {
  5229. var reversed = ranges.rtl().filter(function(rev) {
  5230. return rev.collapsed === false;
  5231. });
  5232. return reversed.map(function(rev) {
  5233. return adt$4.rtl(SugarElement.fromDom(rev.endContainer), rev.endOffset, SugarElement.fromDom(rev.startContainer), rev.startOffset);
  5234. }).getOrThunk(function() {
  5235. return fromRange(win2, adt$4.ltr, rng);
  5236. });
  5237. } else {
  5238. return fromRange(win2, adt$4.ltr, rng);
  5239. }
  5240. };
  5241. var diagnose = function(win2, selection) {
  5242. var ranges = getRanges(win2, selection);
  5243. return doDiagnose(win2, ranges);
  5244. };
  5245. var asLtrRange = function(win2, selection) {
  5246. var diagnosis = diagnose(win2, selection);
  5247. return diagnosis.match({
  5248. ltr: function(start, soffset, finish, foffset) {
  5249. var rng = win2.document.createRange();
  5250. rng.setStart(start.dom, soffset);
  5251. rng.setEnd(finish.dom, foffset);
  5252. return rng;
  5253. },
  5254. rtl: function(start, soffset, finish, foffset) {
  5255. var rng = win2.document.createRange();
  5256. rng.setStart(finish.dom, foffset);
  5257. rng.setEnd(start.dom, soffset);
  5258. return rng;
  5259. }
  5260. });
  5261. };
  5262. adt$4.ltr;
  5263. adt$4.rtl;
  5264. var NodeValue = function(is2, name2) {
  5265. var get2 = function(element2) {
  5266. if (!is2(element2)) {
  5267. throw new Error("Can only get " + name2 + " value of a " + name2 + " node");
  5268. }
  5269. return getOption2(element2).getOr("");
  5270. };
  5271. var getOption2 = function(element2) {
  5272. return is2(element2) ? Optional.from(element2.dom.nodeValue) : Optional.none();
  5273. };
  5274. var set2 = function(element2, value2) {
  5275. if (!is2(element2)) {
  5276. throw new Error("Can only set raw " + name2 + " value of a " + name2 + " node");
  5277. }
  5278. element2.dom.nodeValue = value2;
  5279. };
  5280. return {
  5281. get: get2,
  5282. getOption: getOption2,
  5283. set: set2
  5284. };
  5285. };
  5286. var api = NodeValue(isText$1, "text");
  5287. var get$3 = function(element2) {
  5288. return api.get(element2);
  5289. };
  5290. var getOption = function(element2) {
  5291. return api.getOption(element2);
  5292. };
  5293. var getEnd = function(element2) {
  5294. return name$2(element2) === "img" ? 1 : getOption(element2).fold(function() {
  5295. return children(element2).length;
  5296. }, function(v) {
  5297. return v.length;
  5298. });
  5299. };
  5300. var isTextNodeWithCursorPosition = function(el) {
  5301. return getOption(el).filter(function(text2) {
  5302. return text2.trim().length !== 0 || text2.indexOf(nbsp) > -1;
  5303. }).isSome();
  5304. };
  5305. var elementsWithCursorPosition = [
  5306. "img",
  5307. "br"
  5308. ];
  5309. var isCursorPosition = function(elem) {
  5310. var hasCursorPosition = isTextNodeWithCursorPosition(elem);
  5311. return hasCursorPosition || contains$2(elementsWithCursorPosition, name$2(elem));
  5312. };
  5313. var last$1 = function(element2) {
  5314. return descendantRtl(element2, isCursorPosition);
  5315. };
  5316. var descendantRtl = function(scope, predicate) {
  5317. var descend = function(element2) {
  5318. var children$1 = children(element2);
  5319. for (var i = children$1.length - 1; i >= 0; i--) {
  5320. var child2 = children$1[i];
  5321. if (predicate(child2)) {
  5322. return Optional.some(child2);
  5323. }
  5324. var res = descend(child2);
  5325. if (res.isSome()) {
  5326. return res;
  5327. }
  5328. }
  5329. return Optional.none();
  5330. };
  5331. return descend(scope);
  5332. };
  5333. var descendants = function(scope, selector) {
  5334. return all$3(selector, scope);
  5335. };
  5336. var makeRange = function(start, soffset, finish, foffset) {
  5337. var doc = owner$4(start);
  5338. var rng = doc.dom.createRange();
  5339. rng.setStart(start.dom, soffset);
  5340. rng.setEnd(finish.dom, foffset);
  5341. return rng;
  5342. };
  5343. var after = function(start, soffset, finish, foffset) {
  5344. var r2 = makeRange(start, soffset, finish, foffset);
  5345. var same = eq(start, finish) && soffset === foffset;
  5346. return r2.collapsed && !same;
  5347. };
  5348. var getNativeSelection = function(win2) {
  5349. return Optional.from(win2.getSelection());
  5350. };
  5351. var readRange = function(selection) {
  5352. if (selection.rangeCount > 0) {
  5353. var firstRng = selection.getRangeAt(0);
  5354. var lastRng = selection.getRangeAt(selection.rangeCount - 1);
  5355. return Optional.some(SimRange.create(SugarElement.fromDom(firstRng.startContainer), firstRng.startOffset, SugarElement.fromDom(lastRng.endContainer), lastRng.endOffset));
  5356. } else {
  5357. return Optional.none();
  5358. }
  5359. };
  5360. var doGetExact = function(selection) {
  5361. if (selection.anchorNode === null || selection.focusNode === null) {
  5362. return readRange(selection);
  5363. } else {
  5364. var anchor2 = SugarElement.fromDom(selection.anchorNode);
  5365. var focus_1 = SugarElement.fromDom(selection.focusNode);
  5366. return after(anchor2, selection.anchorOffset, focus_1, selection.focusOffset) ? Optional.some(SimRange.create(anchor2, selection.anchorOffset, focus_1, selection.focusOffset)) : readRange(selection);
  5367. }
  5368. };
  5369. var getExact = function(win2) {
  5370. return getNativeSelection(win2).filter(function(sel) {
  5371. return sel.rangeCount > 0;
  5372. }).bind(doGetExact);
  5373. };
  5374. var getFirstRect = function(win2, selection) {
  5375. var rng = asLtrRange(win2, selection);
  5376. return getFirstRect$1(rng);
  5377. };
  5378. var getBounds$1 = function(win2, selection) {
  5379. var rng = asLtrRange(win2, selection);
  5380. return getBounds$2(rng);
  5381. };
  5382. var point$1 = function(element2, offset2) {
  5383. return {
  5384. element: element2,
  5385. offset: offset2
  5386. };
  5387. };
  5388. var descendOnce$1 = function(element2, offset2) {
  5389. var children$1 = children(element2);
  5390. if (children$1.length === 0) {
  5391. return point$1(element2, offset2);
  5392. } else if (offset2 < children$1.length) {
  5393. return point$1(children$1[offset2], 0);
  5394. } else {
  5395. var last2 = children$1[children$1.length - 1];
  5396. var len = isText$1(last2) ? get$3(last2).length : children(last2).length;
  5397. return point$1(last2, len);
  5398. }
  5399. };
  5400. var descendOnce = function(element2, offset2) {
  5401. return isText$1(element2) ? point$1(element2, offset2) : descendOnce$1(element2, offset2);
  5402. };
  5403. var getAnchorSelection = function(win2, anchorInfo) {
  5404. var getSelection = anchorInfo.getSelection.getOrThunk(function() {
  5405. return function() {
  5406. return getExact(win2);
  5407. };
  5408. });
  5409. return getSelection().map(function(sel) {
  5410. var modStart = descendOnce(sel.start, sel.soffset);
  5411. var modFinish = descendOnce(sel.finish, sel.foffset);
  5412. return SimSelection.range(modStart.element, modStart.offset, modFinish.element, modFinish.offset);
  5413. });
  5414. };
  5415. var placement$1 = function(component, anchorInfo, origin) {
  5416. var win2 = defaultView(anchorInfo.root).dom;
  5417. var rootPoint = getRootPoint(component, origin, anchorInfo);
  5418. var selectionBox = getAnchorSelection(win2, anchorInfo).bind(function(sel) {
  5419. var optRect = getBounds$1(win2, SimSelection.exactFromRange(sel)).orThunk(function() {
  5420. var x = SugarElement.fromText(zeroWidth);
  5421. before$2(sel.start, x);
  5422. var rect2 = getFirstRect(win2, SimSelection.exact(x, 0, x, 1));
  5423. remove$5(x);
  5424. return rect2;
  5425. });
  5426. return optRect.bind(function(rawRect) {
  5427. return getBox(rawRect.left, rawRect.top, rawRect.width, rawRect.height);
  5428. });
  5429. });
  5430. var targetElement = getAnchorSelection(win2, anchorInfo).bind(function(sel) {
  5431. return isElement$2(sel.start) ? Optional.some(sel.start) : parentNode(sel.start);
  5432. });
  5433. var elem = targetElement.getOr(component.element);
  5434. return calcNewAnchor(selectionBox, rootPoint, anchorInfo, origin, elem);
  5435. };
  5436. var SelectionAnchor = [
  5437. option("getSelection"),
  5438. required$1("root"),
  5439. option("bubble"),
  5440. schema$y(),
  5441. defaulted("overrides", {}),
  5442. defaulted("showAbove", false),
  5443. output$1("placement", placement$1)
  5444. ];
  5445. var labelPrefix$1 = "link-layout";
  5446. var eastX = function(anchor2) {
  5447. return anchor2.x + anchor2.width;
  5448. };
  5449. var westX = function(anchor2, element2) {
  5450. return anchor2.x - element2.width;
  5451. };
  5452. var northY$1 = function(anchor2, element2) {
  5453. return anchor2.y - element2.height + anchor2.height;
  5454. };
  5455. var southY$1 = function(anchor2) {
  5456. return anchor2.y;
  5457. };
  5458. var southeast$1 = function(anchor2, element2, bubbles) {
  5459. return nu$6(eastX(anchor2), southY$1(anchor2), bubbles.southeast(), southeast$3(), "southeast", boundsRestriction(anchor2, {
  5460. left: 0,
  5461. top: 2
  5462. }), labelPrefix$1);
  5463. };
  5464. var southwest$1 = function(anchor2, element2, bubbles) {
  5465. return nu$6(westX(anchor2, element2), southY$1(anchor2), bubbles.southwest(), southwest$3(), "southwest", boundsRestriction(anchor2, {
  5466. right: 1,
  5467. top: 2
  5468. }), labelPrefix$1);
  5469. };
  5470. var northeast$1 = function(anchor2, element2, bubbles) {
  5471. return nu$6(eastX(anchor2), northY$1(anchor2, element2), bubbles.northeast(), northeast$3(), "northeast", boundsRestriction(anchor2, {
  5472. left: 0,
  5473. bottom: 3
  5474. }), labelPrefix$1);
  5475. };
  5476. var northwest$1 = function(anchor2, element2, bubbles) {
  5477. return nu$6(westX(anchor2, element2), northY$1(anchor2, element2), bubbles.northwest(), northwest$3(), "northwest", boundsRestriction(anchor2, {
  5478. right: 1,
  5479. bottom: 3
  5480. }), labelPrefix$1);
  5481. };
  5482. var all = function() {
  5483. return [
  5484. southeast$1,
  5485. southwest$1,
  5486. northeast$1,
  5487. northwest$1
  5488. ];
  5489. };
  5490. var allRtl = function() {
  5491. return [
  5492. southwest$1,
  5493. southeast$1,
  5494. northwest$1,
  5495. northeast$1
  5496. ];
  5497. };
  5498. var placement = function(component, submenuInfo, origin) {
  5499. var anchorBox = toBox(origin, submenuInfo.item.element);
  5500. var layouts2 = get$4(component.element, submenuInfo, all(), allRtl(), all(), allRtl(), Optional.none());
  5501. return Optional.some(nu$4({
  5502. anchorBox,
  5503. bubble: fallback(),
  5504. overrides: submenuInfo.overrides,
  5505. layouts: layouts2,
  5506. placer: Optional.none()
  5507. }));
  5508. };
  5509. var SubmenuAnchor = [
  5510. required$1("item"),
  5511. schema$y(),
  5512. defaulted("overrides", {}),
  5513. output$1("placement", placement)
  5514. ];
  5515. var AnchorSchema = choose$1("type", {
  5516. selection: SelectionAnchor,
  5517. node: NodeAnchor,
  5518. hotspot: HotspotAnchor,
  5519. submenu: SubmenuAnchor,
  5520. makeshift: MakeshiftAnchor
  5521. });
  5522. var TransitionSchema = [
  5523. requiredArrayOf("classes", string),
  5524. defaultedStringEnum("mode", "all", [
  5525. "all",
  5526. "layout",
  5527. "placement"
  5528. ])
  5529. ];
  5530. var PositionSchema = [
  5531. defaulted("useFixed", never),
  5532. option("getBounds")
  5533. ];
  5534. var PlacementSchema = [
  5535. requiredOf("anchor", AnchorSchema),
  5536. optionObjOf("transition", TransitionSchema)
  5537. ];
  5538. var getFixedOrigin = function() {
  5539. var html2 = document.documentElement;
  5540. return fixed$1(0, 0, html2.clientWidth, html2.clientHeight);
  5541. };
  5542. var getRelativeOrigin = function(component) {
  5543. var position2 = absolute$3(component.element);
  5544. var bounds2 = component.element.dom.getBoundingClientRect();
  5545. return relative$1(position2.left, position2.top, bounds2.width, bounds2.height);
  5546. };
  5547. var place = function(component, origin, anchoring, getBounds2, placee, lastPlace, transition) {
  5548. var anchor2 = box(anchoring.anchorBox, origin);
  5549. return simple(anchor2, placee.element, anchoring.bubble, anchoring.layouts, lastPlace, getBounds2, anchoring.overrides, transition);
  5550. };
  5551. var position$1 = function(component, posConfig, posState, placee, placementSpec) {
  5552. positionWithin(component, posConfig, posState, placee, placementSpec, Optional.none());
  5553. };
  5554. var positionWithin = function(component, posConfig, posState, placee, placementSpec, boxElement) {
  5555. var boundsBox = boxElement.map(box$1);
  5556. return positionWithinBounds(component, posConfig, posState, placee, placementSpec, boundsBox);
  5557. };
  5558. var positionWithinBounds = function(component, posConfig, posState, placee, placementSpec, bounds2) {
  5559. var placeeDetail = asRawOrDie$1("placement.info", objOf(PlacementSchema), placementSpec);
  5560. var anchorage = placeeDetail.anchor;
  5561. var element2 = placee.element;
  5562. var placeeState = posState.get(placee.uid);
  5563. preserve$1(function() {
  5564. set$7(element2, "position", "fixed");
  5565. var oldVisibility = getRaw(element2, "visibility");
  5566. set$7(element2, "visibility", "hidden");
  5567. var origin = posConfig.useFixed() ? getFixedOrigin() : getRelativeOrigin(component);
  5568. var placer = anchorage.placement;
  5569. var getBounds2 = bounds2.map(constant$1).or(posConfig.getBounds);
  5570. placer(component, anchorage, origin).each(function(anchoring) {
  5571. var doPlace = anchoring.placer.getOr(place);
  5572. var newState = doPlace(component, origin, anchoring, getBounds2, placee, placeeState, placeeDetail.transition);
  5573. posState.set(placee.uid, newState);
  5574. });
  5575. oldVisibility.fold(function() {
  5576. remove$6(element2, "visibility");
  5577. }, function(vis) {
  5578. set$7(element2, "visibility", vis);
  5579. });
  5580. if (getRaw(element2, "left").isNone() && getRaw(element2, "top").isNone() && getRaw(element2, "right").isNone() && getRaw(element2, "bottom").isNone() && is$1(getRaw(element2, "position"), "fixed")) {
  5581. remove$6(element2, "position");
  5582. }
  5583. }, element2);
  5584. };
  5585. var getMode = function(component, pConfig, _pState) {
  5586. return pConfig.useFixed() ? "fixed" : "absolute";
  5587. };
  5588. var reset$1 = function(component, pConfig, posState, placee) {
  5589. var element2 = placee.element;
  5590. each$1([
  5591. "position",
  5592. "left",
  5593. "right",
  5594. "top",
  5595. "bottom"
  5596. ], function(prop) {
  5597. return remove$6(element2, prop);
  5598. });
  5599. reset$2(element2);
  5600. posState.clear(placee.uid);
  5601. };
  5602. var PositionApis = Object.freeze({
  5603. __proto__: null,
  5604. position: position$1,
  5605. positionWithin,
  5606. positionWithinBounds,
  5607. getMode,
  5608. reset: reset$1
  5609. });
  5610. var init$g = function() {
  5611. var state = {};
  5612. var set2 = function(id, data) {
  5613. state[id] = data;
  5614. };
  5615. var get2 = function(id) {
  5616. return get$e(state, id);
  5617. };
  5618. var clear2 = function(id) {
  5619. if (isNonNullable(id)) {
  5620. delete state[id];
  5621. } else {
  5622. state = {};
  5623. }
  5624. };
  5625. return nu$8({
  5626. readState: function() {
  5627. return state;
  5628. },
  5629. clear: clear2,
  5630. set: set2,
  5631. get: get2
  5632. });
  5633. };
  5634. var PositioningState = Object.freeze({
  5635. __proto__: null,
  5636. init: init$g
  5637. });
  5638. var Positioning = create$8({
  5639. fields: PositionSchema,
  5640. name: "positioning",
  5641. active: ActivePosition,
  5642. apis: PositionApis,
  5643. state: PositioningState
  5644. });
  5645. var fireDetaching = function(component) {
  5646. emit(component, detachedFromDom());
  5647. var children2 = component.components();
  5648. each$1(children2, fireDetaching);
  5649. };
  5650. var fireAttaching = function(component) {
  5651. var children2 = component.components();
  5652. each$1(children2, fireAttaching);
  5653. emit(component, attachedToDom());
  5654. };
  5655. var attach$1 = function(parent2, child2) {
  5656. append$2(parent2.element, child2.element);
  5657. };
  5658. var detachChildren$1 = function(component) {
  5659. each$1(component.components(), function(childComp) {
  5660. return remove$5(childComp.element);
  5661. });
  5662. empty(component.element);
  5663. component.syncComponents();
  5664. };
  5665. var replaceChildren = function(component, newChildren) {
  5666. var subs2 = component.components();
  5667. detachChildren$1(component);
  5668. var deleted = difference(subs2, newChildren);
  5669. each$1(deleted, function(comp) {
  5670. fireDetaching(comp);
  5671. component.getSystem().removeFromWorld(comp);
  5672. });
  5673. each$1(newChildren, function(childComp) {
  5674. if (!childComp.getSystem().isConnected()) {
  5675. component.getSystem().addToWorld(childComp);
  5676. attach$1(component, childComp);
  5677. if (inBody(component.element)) {
  5678. fireAttaching(childComp);
  5679. }
  5680. } else {
  5681. attach$1(component, childComp);
  5682. }
  5683. component.syncComponents();
  5684. });
  5685. };
  5686. var attach = function(parent2, child2) {
  5687. attachWith(parent2, child2, append$2);
  5688. };
  5689. var attachWith = function(parent2, child2, insertion) {
  5690. parent2.getSystem().addToWorld(child2);
  5691. insertion(parent2.element, child2.element);
  5692. if (inBody(parent2.element)) {
  5693. fireAttaching(child2);
  5694. }
  5695. parent2.syncComponents();
  5696. };
  5697. var doDetach = function(component) {
  5698. fireDetaching(component);
  5699. remove$5(component.element);
  5700. component.getSystem().removeFromWorld(component);
  5701. };
  5702. var detach = function(component) {
  5703. var parent$1 = parent(component.element).bind(function(p) {
  5704. return component.getSystem().getByDom(p).toOptional();
  5705. });
  5706. doDetach(component);
  5707. parent$1.each(function(p) {
  5708. p.syncComponents();
  5709. });
  5710. };
  5711. var detachChildren = function(component) {
  5712. var subs2 = component.components();
  5713. each$1(subs2, doDetach);
  5714. empty(component.element);
  5715. component.syncComponents();
  5716. };
  5717. var attachSystem = function(element2, guiSystem) {
  5718. attachSystemWith(element2, guiSystem, append$2);
  5719. };
  5720. var attachSystemAfter = function(element2, guiSystem) {
  5721. attachSystemWith(element2, guiSystem, after$2);
  5722. };
  5723. var attachSystemWith = function(element2, guiSystem, inserter) {
  5724. inserter(element2, guiSystem.element);
  5725. var children$1 = children(guiSystem.element);
  5726. each$1(children$1, function(child2) {
  5727. guiSystem.getByDom(child2).each(fireAttaching);
  5728. });
  5729. };
  5730. var detachSystem = function(guiSystem) {
  5731. var children$1 = children(guiSystem.element);
  5732. each$1(children$1, function(child2) {
  5733. guiSystem.getByDom(child2).each(fireDetaching);
  5734. });
  5735. remove$5(guiSystem.element);
  5736. };
  5737. var rebuild = function(sandbox, sConfig, sState, data) {
  5738. sState.get().each(function(_data) {
  5739. detachChildren(sandbox);
  5740. });
  5741. var point2 = sConfig.getAttachPoint(sandbox);
  5742. attach(point2, sandbox);
  5743. var built = sandbox.getSystem().build(data);
  5744. attach(sandbox, built);
  5745. sState.set(built);
  5746. return built;
  5747. };
  5748. var open$1 = function(sandbox, sConfig, sState, data) {
  5749. var newState = rebuild(sandbox, sConfig, sState, data);
  5750. sConfig.onOpen(sandbox, newState);
  5751. return newState;
  5752. };
  5753. var setContent = function(sandbox, sConfig, sState, data) {
  5754. return sState.get().map(function() {
  5755. return rebuild(sandbox, sConfig, sState, data);
  5756. });
  5757. };
  5758. var openWhileCloaked = function(sandbox, sConfig, sState, data, transaction) {
  5759. cloak(sandbox, sConfig);
  5760. open$1(sandbox, sConfig, sState, data);
  5761. transaction();
  5762. decloak(sandbox, sConfig);
  5763. };
  5764. var close$1 = function(sandbox, sConfig, sState) {
  5765. sState.get().each(function(data) {
  5766. detachChildren(sandbox);
  5767. detach(sandbox);
  5768. sConfig.onClose(sandbox, data);
  5769. sState.clear();
  5770. });
  5771. };
  5772. var isOpen$1 = function(_sandbox, _sConfig, sState) {
  5773. return sState.isOpen();
  5774. };
  5775. var isPartOf = function(sandbox, sConfig, sState, queryElem) {
  5776. return isOpen$1(sandbox, sConfig, sState) && sState.get().exists(function(data) {
  5777. return sConfig.isPartOf(sandbox, data, queryElem);
  5778. });
  5779. };
  5780. var getState$2 = function(_sandbox, _sConfig, sState) {
  5781. return sState.get();
  5782. };
  5783. var store = function(sandbox, cssKey, attr, newValue) {
  5784. getRaw(sandbox.element, cssKey).fold(function() {
  5785. remove$7(sandbox.element, attr);
  5786. }, function(v) {
  5787. set$8(sandbox.element, attr, v);
  5788. });
  5789. set$7(sandbox.element, cssKey, newValue);
  5790. };
  5791. var restore = function(sandbox, cssKey, attr) {
  5792. getOpt(sandbox.element, attr).fold(function() {
  5793. return remove$6(sandbox.element, cssKey);
  5794. }, function(oldValue) {
  5795. return set$7(sandbox.element, cssKey, oldValue);
  5796. });
  5797. };
  5798. var cloak = function(sandbox, sConfig, _sState) {
  5799. var sink = sConfig.getAttachPoint(sandbox);
  5800. set$7(sandbox.element, "position", Positioning.getMode(sink));
  5801. store(sandbox, "visibility", sConfig.cloakVisibilityAttr, "hidden");
  5802. };
  5803. var hasPosition = function(element2) {
  5804. return exists([
  5805. "top",
  5806. "left",
  5807. "right",
  5808. "bottom"
  5809. ], function(pos) {
  5810. return getRaw(element2, pos).isSome();
  5811. });
  5812. };
  5813. var decloak = function(sandbox, sConfig, _sState) {
  5814. if (!hasPosition(sandbox.element)) {
  5815. remove$6(sandbox.element, "position");
  5816. }
  5817. restore(sandbox, "visibility", sConfig.cloakVisibilityAttr);
  5818. };
  5819. var SandboxApis = Object.freeze({
  5820. __proto__: null,
  5821. cloak,
  5822. decloak,
  5823. open: open$1,
  5824. openWhileCloaked,
  5825. close: close$1,
  5826. isOpen: isOpen$1,
  5827. isPartOf,
  5828. getState: getState$2,
  5829. setContent
  5830. });
  5831. var events$g = function(sandboxConfig, sandboxState) {
  5832. return derive$2([run$1(sandboxClose(), function(sandbox, _simulatedEvent) {
  5833. close$1(sandbox, sandboxConfig, sandboxState);
  5834. })]);
  5835. };
  5836. var ActiveSandbox = Object.freeze({
  5837. __proto__: null,
  5838. events: events$g
  5839. });
  5840. var SandboxSchema = [
  5841. onHandler("onOpen"),
  5842. onHandler("onClose"),
  5843. required$1("isPartOf"),
  5844. required$1("getAttachPoint"),
  5845. defaulted("cloakVisibilityAttr", "data-precloak-visibility")
  5846. ];
  5847. var init$f = function() {
  5848. var contents2 = value$1();
  5849. var readState = constant$1("not-implemented");
  5850. return nu$8({
  5851. readState,
  5852. isOpen: contents2.isSet,
  5853. clear: contents2.clear,
  5854. set: contents2.set,
  5855. get: contents2.get
  5856. });
  5857. };
  5858. var SandboxState = Object.freeze({
  5859. __proto__: null,
  5860. init: init$f
  5861. });
  5862. var Sandboxing = create$8({
  5863. fields: SandboxSchema,
  5864. name: "sandboxing",
  5865. active: ActiveSandbox,
  5866. apis: SandboxApis,
  5867. state: SandboxState
  5868. });
  5869. var dismissPopups = constant$1("dismiss.popups");
  5870. var repositionPopups = constant$1("reposition.popups");
  5871. var mouseReleased = constant$1("mouse.released");
  5872. var schema$x = objOfOnly([
  5873. defaulted("isExtraPart", never),
  5874. optionObjOf("fireEventInstead", [defaulted("event", dismissRequested())])
  5875. ]);
  5876. var receivingChannel$1 = function(rawSpec) {
  5877. var _a2;
  5878. var detail = asRawOrDie$1("Dismissal", schema$x, rawSpec);
  5879. return _a2 = {}, _a2[dismissPopups()] = {
  5880. schema: objOfOnly([required$1("target")]),
  5881. onReceive: function(sandbox, data) {
  5882. if (Sandboxing.isOpen(sandbox)) {
  5883. var isPart = Sandboxing.isPartOf(sandbox, data.target) || detail.isExtraPart(sandbox, data.target);
  5884. if (!isPart) {
  5885. detail.fireEventInstead.fold(function() {
  5886. return Sandboxing.close(sandbox);
  5887. }, function(fe) {
  5888. return emit(sandbox, fe.event);
  5889. });
  5890. }
  5891. }
  5892. }
  5893. }, _a2;
  5894. };
  5895. var schema$w = objOfOnly([
  5896. optionObjOf("fireEventInstead", [defaulted("event", repositionRequested())]),
  5897. requiredFunction("doReposition")
  5898. ]);
  5899. var receivingChannel = function(rawSpec) {
  5900. var _a2;
  5901. var detail = asRawOrDie$1("Reposition", schema$w, rawSpec);
  5902. return _a2 = {}, _a2[repositionPopups()] = {
  5903. onReceive: function(sandbox) {
  5904. if (Sandboxing.isOpen(sandbox)) {
  5905. detail.fireEventInstead.fold(function() {
  5906. return detail.doReposition(sandbox);
  5907. }, function(fe) {
  5908. return emit(sandbox, fe.event);
  5909. });
  5910. }
  5911. }
  5912. }, _a2;
  5913. };
  5914. var onLoad$5 = function(component, repConfig, repState) {
  5915. repConfig.store.manager.onLoad(component, repConfig, repState);
  5916. };
  5917. var onUnload$2 = function(component, repConfig, repState) {
  5918. repConfig.store.manager.onUnload(component, repConfig, repState);
  5919. };
  5920. var setValue$3 = function(component, repConfig, repState, data) {
  5921. repConfig.store.manager.setValue(component, repConfig, repState, data);
  5922. };
  5923. var getValue$3 = function(component, repConfig, repState) {
  5924. return repConfig.store.manager.getValue(component, repConfig, repState);
  5925. };
  5926. var getState$1 = function(component, repConfig, repState) {
  5927. return repState;
  5928. };
  5929. var RepresentApis = Object.freeze({
  5930. __proto__: null,
  5931. onLoad: onLoad$5,
  5932. onUnload: onUnload$2,
  5933. setValue: setValue$3,
  5934. getValue: getValue$3,
  5935. getState: getState$1
  5936. });
  5937. var events$f = function(repConfig, repState) {
  5938. var es = repConfig.resetOnDom ? [
  5939. runOnAttached(function(comp, _se) {
  5940. onLoad$5(comp, repConfig, repState);
  5941. }),
  5942. runOnDetached(function(comp, _se) {
  5943. onUnload$2(comp, repConfig, repState);
  5944. })
  5945. ] : [loadEvent(repConfig, repState, onLoad$5)];
  5946. return derive$2(es);
  5947. };
  5948. var ActiveRepresenting = Object.freeze({
  5949. __proto__: null,
  5950. events: events$f
  5951. });
  5952. var memory$1 = function() {
  5953. var data = Cell(null);
  5954. var readState = function() {
  5955. return {
  5956. mode: "memory",
  5957. value: data.get()
  5958. };
  5959. };
  5960. var isNotSet = function() {
  5961. return data.get() === null;
  5962. };
  5963. var clear2 = function() {
  5964. data.set(null);
  5965. };
  5966. return nu$8({
  5967. set: data.set,
  5968. get: data.get,
  5969. isNotSet,
  5970. clear: clear2,
  5971. readState
  5972. });
  5973. };
  5974. var manual = function() {
  5975. var readState = noop;
  5976. return nu$8({ readState });
  5977. };
  5978. var dataset = function() {
  5979. var dataByValue = Cell({});
  5980. var dataByText = Cell({});
  5981. var readState = function() {
  5982. return {
  5983. mode: "dataset",
  5984. dataByValue: dataByValue.get(),
  5985. dataByText: dataByText.get()
  5986. };
  5987. };
  5988. var clear2 = function() {
  5989. dataByValue.set({});
  5990. dataByText.set({});
  5991. };
  5992. var lookup2 = function(itemString) {
  5993. return get$e(dataByValue.get(), itemString).orThunk(function() {
  5994. return get$e(dataByText.get(), itemString);
  5995. });
  5996. };
  5997. var update = function(items) {
  5998. var currentDataByValue = dataByValue.get();
  5999. var currentDataByText = dataByText.get();
  6000. var newDataByValue = {};
  6001. var newDataByText = {};
  6002. each$1(items, function(item2) {
  6003. newDataByValue[item2.value] = item2;
  6004. get$e(item2, "meta").each(function(meta) {
  6005. get$e(meta, "text").each(function(text2) {
  6006. newDataByText[text2] = item2;
  6007. });
  6008. });
  6009. });
  6010. dataByValue.set(__assign(__assign({}, currentDataByValue), newDataByValue));
  6011. dataByText.set(__assign(__assign({}, currentDataByText), newDataByText));
  6012. };
  6013. return nu$8({
  6014. readState,
  6015. lookup: lookup2,
  6016. update,
  6017. clear: clear2
  6018. });
  6019. };
  6020. var init$e = function(spec) {
  6021. return spec.store.manager.state(spec);
  6022. };
  6023. var RepresentState = Object.freeze({
  6024. __proto__: null,
  6025. memory: memory$1,
  6026. dataset,
  6027. manual,
  6028. init: init$e
  6029. });
  6030. var setValue$2 = function(component, repConfig, repState, data) {
  6031. var store2 = repConfig.store;
  6032. repState.update([data]);
  6033. store2.setValue(component, data);
  6034. repConfig.onSetValue(component, data);
  6035. };
  6036. var getValue$2 = function(component, repConfig, repState) {
  6037. var store2 = repConfig.store;
  6038. var key = store2.getDataKey(component);
  6039. return repState.lookup(key).getOrThunk(function() {
  6040. return store2.getFallbackEntry(key);
  6041. });
  6042. };
  6043. var onLoad$4 = function(component, repConfig, repState) {
  6044. var store2 = repConfig.store;
  6045. store2.initialValue.each(function(data) {
  6046. setValue$2(component, repConfig, repState, data);
  6047. });
  6048. };
  6049. var onUnload$1 = function(component, repConfig, repState) {
  6050. repState.clear();
  6051. };
  6052. var DatasetStore = [
  6053. option("initialValue"),
  6054. required$1("getFallbackEntry"),
  6055. required$1("getDataKey"),
  6056. required$1("setValue"),
  6057. output$1("manager", {
  6058. setValue: setValue$2,
  6059. getValue: getValue$2,
  6060. onLoad: onLoad$4,
  6061. onUnload: onUnload$1,
  6062. state: dataset
  6063. })
  6064. ];
  6065. var getValue$1 = function(component, repConfig, _repState) {
  6066. return repConfig.store.getValue(component);
  6067. };
  6068. var setValue$1 = function(component, repConfig, _repState, data) {
  6069. repConfig.store.setValue(component, data);
  6070. repConfig.onSetValue(component, data);
  6071. };
  6072. var onLoad$3 = function(component, repConfig, _repState) {
  6073. repConfig.store.initialValue.each(function(data) {
  6074. repConfig.store.setValue(component, data);
  6075. });
  6076. };
  6077. var ManualStore = [
  6078. required$1("getValue"),
  6079. defaulted("setValue", noop),
  6080. option("initialValue"),
  6081. output$1("manager", {
  6082. setValue: setValue$1,
  6083. getValue: getValue$1,
  6084. onLoad: onLoad$3,
  6085. onUnload: noop,
  6086. state: NoState.init
  6087. })
  6088. ];
  6089. var setValue = function(component, repConfig, repState, data) {
  6090. repState.set(data);
  6091. repConfig.onSetValue(component, data);
  6092. };
  6093. var getValue = function(component, repConfig, repState) {
  6094. return repState.get();
  6095. };
  6096. var onLoad$2 = function(component, repConfig, repState) {
  6097. repConfig.store.initialValue.each(function(initVal) {
  6098. if (repState.isNotSet()) {
  6099. repState.set(initVal);
  6100. }
  6101. });
  6102. };
  6103. var onUnload = function(component, repConfig, repState) {
  6104. repState.clear();
  6105. };
  6106. var MemoryStore = [
  6107. option("initialValue"),
  6108. output$1("manager", {
  6109. setValue,
  6110. getValue,
  6111. onLoad: onLoad$2,
  6112. onUnload,
  6113. state: memory$1
  6114. })
  6115. ];
  6116. var RepresentSchema = [
  6117. defaultedOf("store", { mode: "memory" }, choose$1("mode", {
  6118. memory: MemoryStore,
  6119. manual: ManualStore,
  6120. dataset: DatasetStore
  6121. })),
  6122. onHandler("onSetValue"),
  6123. defaulted("resetOnDom", false)
  6124. ];
  6125. var Representing = create$8({
  6126. fields: RepresentSchema,
  6127. name: "representing",
  6128. active: ActiveRepresenting,
  6129. apis: RepresentApis,
  6130. extra: {
  6131. setValueFrom: function(component, source) {
  6132. var value2 = Representing.getValue(source);
  6133. Representing.setValue(component, value2);
  6134. }
  6135. },
  6136. state: RepresentState
  6137. });
  6138. var field = function(name2, forbidden) {
  6139. return defaultedObjOf(name2, {}, map$2(forbidden, function(f) {
  6140. return forbid(f.name(), "Cannot configure " + f.name() + " for " + name2);
  6141. }).concat([customField("dump", identity$1)]));
  6142. };
  6143. var get$2 = function(data) {
  6144. return data.dump;
  6145. };
  6146. var augment = function(data, original2) {
  6147. return __assign(__assign({}, derive$1(original2)), data.dump);
  6148. };
  6149. var SketchBehaviours = {
  6150. field,
  6151. augment,
  6152. get: get$2
  6153. };
  6154. var _placeholder = "placeholder";
  6155. var adt$3 = Adt.generate([
  6156. {
  6157. single: [
  6158. "required",
  6159. "valueThunk"
  6160. ]
  6161. },
  6162. {
  6163. multiple: [
  6164. "required",
  6165. "valueThunks"
  6166. ]
  6167. }
  6168. ]);
  6169. var isSubstituted = function(spec) {
  6170. return has$2(spec, "uiType");
  6171. };
  6172. var subPlaceholder = function(owner2, detail, compSpec, placeholders) {
  6173. if (owner2.exists(function(o) {
  6174. return o !== compSpec.owner;
  6175. })) {
  6176. return adt$3.single(true, constant$1(compSpec));
  6177. }
  6178. return get$e(placeholders, compSpec.name).fold(function() {
  6179. throw new Error("Unknown placeholder component: " + compSpec.name + "\nKnown: [" + keys(placeholders) + "]\nNamespace: " + owner2.getOr("none") + "\nSpec: " + JSON.stringify(compSpec, null, 2));
  6180. }, function(newSpec) {
  6181. return newSpec.replace();
  6182. });
  6183. };
  6184. var scan = function(owner2, detail, compSpec, placeholders) {
  6185. if (isSubstituted(compSpec) && compSpec.uiType === _placeholder) {
  6186. return subPlaceholder(owner2, detail, compSpec, placeholders);
  6187. } else {
  6188. return adt$3.single(false, constant$1(compSpec));
  6189. }
  6190. };
  6191. var substitute = function(owner2, detail, compSpec, placeholders) {
  6192. var base2 = scan(owner2, detail, compSpec, placeholders);
  6193. return base2.fold(function(req, valueThunk2) {
  6194. var value2 = isSubstituted(compSpec) ? valueThunk2(detail, compSpec.config, compSpec.validated) : valueThunk2(detail);
  6195. var childSpecs = get$e(value2, "components").getOr([]);
  6196. var substituted = bind$3(childSpecs, function(c) {
  6197. return substitute(owner2, detail, c, placeholders);
  6198. });
  6199. return [__assign(__assign({}, value2), { components: substituted })];
  6200. }, function(req, valuesThunk) {
  6201. if (isSubstituted(compSpec)) {
  6202. var values2 = valuesThunk(detail, compSpec.config, compSpec.validated);
  6203. var preprocessor = compSpec.validated.preprocess.getOr(identity$1);
  6204. return preprocessor(values2);
  6205. } else {
  6206. return valuesThunk(detail);
  6207. }
  6208. });
  6209. };
  6210. var substituteAll = function(owner2, detail, components2, placeholders) {
  6211. return bind$3(components2, function(c) {
  6212. return substitute(owner2, detail, c, placeholders);
  6213. });
  6214. };
  6215. var oneReplace = function(label, replacements) {
  6216. var called = false;
  6217. var used = function() {
  6218. return called;
  6219. };
  6220. var replace = function() {
  6221. if (called) {
  6222. throw new Error("Trying to use the same placeholder more than once: " + label);
  6223. }
  6224. called = true;
  6225. return replacements;
  6226. };
  6227. var required2 = function() {
  6228. return replacements.fold(function(req, _) {
  6229. return req;
  6230. }, function(req, _) {
  6231. return req;
  6232. });
  6233. };
  6234. return {
  6235. name: constant$1(label),
  6236. required: required2,
  6237. used,
  6238. replace
  6239. };
  6240. };
  6241. var substitutePlaces = function(owner2, detail, components2, placeholders) {
  6242. var ps = map$1(placeholders, function(ph, name2) {
  6243. return oneReplace(name2, ph);
  6244. });
  6245. var outcome = substituteAll(owner2, detail, components2, ps);
  6246. each(ps, function(p) {
  6247. if (p.used() === false && p.required()) {
  6248. throw new Error("Placeholder: " + p.name() + " was not found in components list\nNamespace: " + owner2.getOr("none") + "\nComponents: " + JSON.stringify(detail.components, null, 2));
  6249. }
  6250. });
  6251. return outcome;
  6252. };
  6253. var single$2 = adt$3.single;
  6254. var multiple = adt$3.multiple;
  6255. var placeholder = constant$1(_placeholder);
  6256. var adt$2 = Adt.generate([
  6257. { required: ["data"] },
  6258. { external: ["data"] },
  6259. { optional: ["data"] },
  6260. { group: ["data"] }
  6261. ]);
  6262. var fFactory = defaulted("factory", { sketch: identity$1 });
  6263. var fSchema = defaulted("schema", []);
  6264. var fName = required$1("name");
  6265. var fPname = field$1("pname", "pname", defaultedThunk(function(typeSpec) {
  6266. return "<alloy." + generate$6(typeSpec.name) + ">";
  6267. }), anyValue());
  6268. var fGroupSchema = customField("schema", function() {
  6269. return [option("preprocess")];
  6270. });
  6271. var fDefaults = defaulted("defaults", constant$1({}));
  6272. var fOverrides = defaulted("overrides", constant$1({}));
  6273. var requiredSpec = objOf([
  6274. fFactory,
  6275. fSchema,
  6276. fName,
  6277. fPname,
  6278. fDefaults,
  6279. fOverrides
  6280. ]);
  6281. var externalSpec = objOf([
  6282. fFactory,
  6283. fSchema,
  6284. fName,
  6285. fDefaults,
  6286. fOverrides
  6287. ]);
  6288. var optionalSpec = objOf([
  6289. fFactory,
  6290. fSchema,
  6291. fName,
  6292. fPname,
  6293. fDefaults,
  6294. fOverrides
  6295. ]);
  6296. var groupSpec = objOf([
  6297. fFactory,
  6298. fGroupSchema,
  6299. fName,
  6300. required$1("unit"),
  6301. fPname,
  6302. fDefaults,
  6303. fOverrides
  6304. ]);
  6305. var asNamedPart = function(part2) {
  6306. return part2.fold(Optional.some, Optional.none, Optional.some, Optional.some);
  6307. };
  6308. var name$1 = function(part2) {
  6309. var get2 = function(data) {
  6310. return data.name;
  6311. };
  6312. return part2.fold(get2, get2, get2, get2);
  6313. };
  6314. var asCommon = function(part2) {
  6315. return part2.fold(identity$1, identity$1, identity$1, identity$1);
  6316. };
  6317. var convert = function(adtConstructor, partSchema) {
  6318. return function(spec) {
  6319. var data = asRawOrDie$1("Converting part type", partSchema, spec);
  6320. return adtConstructor(data);
  6321. };
  6322. };
  6323. var required = convert(adt$2.required, requiredSpec);
  6324. var external$1 = convert(adt$2.external, externalSpec);
  6325. var optional = convert(adt$2.optional, optionalSpec);
  6326. var group = convert(adt$2.group, groupSpec);
  6327. var original = constant$1("entirety");
  6328. var PartType = Object.freeze({
  6329. __proto__: null,
  6330. required,
  6331. external: external$1,
  6332. optional,
  6333. group,
  6334. asNamedPart,
  6335. name: name$1,
  6336. asCommon,
  6337. original
  6338. });
  6339. var combine = function(detail, data, partSpec, partValidated) {
  6340. return deepMerge(data.defaults(detail, partSpec, partValidated), partSpec, { uid: detail.partUids[data.name] }, data.overrides(detail, partSpec, partValidated));
  6341. };
  6342. var subs = function(owner2, detail, parts2) {
  6343. var internals = {};
  6344. var externals = {};
  6345. each$1(parts2, function(part2) {
  6346. part2.fold(function(data) {
  6347. internals[data.pname] = single$2(true, function(detail2, partSpec, partValidated) {
  6348. return data.factory.sketch(combine(detail2, data, partSpec, partValidated));
  6349. });
  6350. }, function(data) {
  6351. var partSpec = detail.parts[data.name];
  6352. externals[data.name] = constant$1(data.factory.sketch(combine(detail, data, partSpec[original()]), partSpec));
  6353. }, function(data) {
  6354. internals[data.pname] = single$2(false, function(detail2, partSpec, partValidated) {
  6355. return data.factory.sketch(combine(detail2, data, partSpec, partValidated));
  6356. });
  6357. }, function(data) {
  6358. internals[data.pname] = multiple(true, function(detail2, _partSpec, _partValidated) {
  6359. var units2 = detail2[data.name];
  6360. return map$2(units2, function(u) {
  6361. return data.factory.sketch(deepMerge(data.defaults(detail2, u, _partValidated), u, data.overrides(detail2, u)));
  6362. });
  6363. });
  6364. });
  6365. });
  6366. return {
  6367. internals: constant$1(internals),
  6368. externals: constant$1(externals)
  6369. };
  6370. };
  6371. var generate$3 = function(owner2, parts2) {
  6372. var r2 = {};
  6373. each$1(parts2, function(part2) {
  6374. asNamedPart(part2).each(function(np) {
  6375. var g = doGenerateOne(owner2, np.pname);
  6376. r2[np.name] = function(config2) {
  6377. var validated = asRawOrDie$1("Part: " + np.name + " in " + owner2, objOf(np.schema), config2);
  6378. return __assign(__assign({}, g), {
  6379. config: config2,
  6380. validated
  6381. });
  6382. };
  6383. });
  6384. });
  6385. return r2;
  6386. };
  6387. var doGenerateOne = function(owner2, pname) {
  6388. return {
  6389. uiType: placeholder(),
  6390. owner: owner2,
  6391. name: pname
  6392. };
  6393. };
  6394. var generateOne$1 = function(owner2, pname, config2) {
  6395. return {
  6396. uiType: placeholder(),
  6397. owner: owner2,
  6398. name: pname,
  6399. config: config2,
  6400. validated: {}
  6401. };
  6402. };
  6403. var schemas = function(parts2) {
  6404. return bind$3(parts2, function(part2) {
  6405. return part2.fold(Optional.none, Optional.some, Optional.none, Optional.none).map(function(data) {
  6406. return requiredObjOf(data.name, data.schema.concat([snapshot(original())]));
  6407. }).toArray();
  6408. });
  6409. };
  6410. var names = function(parts2) {
  6411. return map$2(parts2, name$1);
  6412. };
  6413. var substitutes = function(owner2, detail, parts2) {
  6414. return subs(owner2, detail, parts2);
  6415. };
  6416. var components$1 = function(owner2, detail, internals) {
  6417. return substitutePlaces(Optional.some(owner2), detail, detail.components, internals);
  6418. };
  6419. var getPart = function(component, detail, partKey) {
  6420. var uid = detail.partUids[partKey];
  6421. return component.getSystem().getByUid(uid).toOptional();
  6422. };
  6423. var getPartOrDie = function(component, detail, partKey) {
  6424. return getPart(component, detail, partKey).getOrDie("Could not find part: " + partKey);
  6425. };
  6426. var getParts = function(component, detail, partKeys) {
  6427. var r2 = {};
  6428. var uids2 = detail.partUids;
  6429. var system = component.getSystem();
  6430. each$1(partKeys, function(pk) {
  6431. r2[pk] = constant$1(system.getByUid(uids2[pk]));
  6432. });
  6433. return r2;
  6434. };
  6435. var getAllParts = function(component, detail) {
  6436. var system = component.getSystem();
  6437. return map$1(detail.partUids, function(pUid, _k) {
  6438. return constant$1(system.getByUid(pUid));
  6439. });
  6440. };
  6441. var getAllPartNames = function(detail) {
  6442. return keys(detail.partUids);
  6443. };
  6444. var getPartsOrDie = function(component, detail, partKeys) {
  6445. var r2 = {};
  6446. var uids2 = detail.partUids;
  6447. var system = component.getSystem();
  6448. each$1(partKeys, function(pk) {
  6449. r2[pk] = constant$1(system.getByUid(uids2[pk]).getOrDie());
  6450. });
  6451. return r2;
  6452. };
  6453. var defaultUids = function(baseUid, partTypes) {
  6454. var partNames = names(partTypes);
  6455. return wrapAll(map$2(partNames, function(pn) {
  6456. return {
  6457. key: pn,
  6458. value: baseUid + "-" + pn
  6459. };
  6460. }));
  6461. };
  6462. var defaultUidsSchema = function(partTypes) {
  6463. return field$1("partUids", "partUids", mergeWithThunk(function(spec) {
  6464. return defaultUids(spec.uid, partTypes);
  6465. }), anyValue());
  6466. };
  6467. var AlloyParts = Object.freeze({
  6468. __proto__: null,
  6469. generate: generate$3,
  6470. generateOne: generateOne$1,
  6471. schemas,
  6472. names,
  6473. substitutes,
  6474. components: components$1,
  6475. defaultUids,
  6476. defaultUidsSchema,
  6477. getAllParts,
  6478. getAllPartNames,
  6479. getPart,
  6480. getPartOrDie,
  6481. getParts,
  6482. getPartsOrDie
  6483. });
  6484. var base = function(partSchemas, partUidsSchemas) {
  6485. var ps = partSchemas.length > 0 ? [requiredObjOf("parts", partSchemas)] : [];
  6486. return ps.concat([
  6487. required$1("uid"),
  6488. defaulted("dom", {}),
  6489. defaulted("components", []),
  6490. snapshot("originalSpec"),
  6491. defaulted("debug.sketcher", {})
  6492. ]).concat(partUidsSchemas);
  6493. };
  6494. var asRawOrDie = function(label, schema2, spec, partSchemas, partUidsSchemas) {
  6495. var baseS = base(partSchemas, partUidsSchemas);
  6496. return asRawOrDie$1(label + " [SpecSchema]", objOfOnly(baseS.concat(schema2)), spec);
  6497. };
  6498. var single$1 = function(owner2, schema2, factory2, spec) {
  6499. var specWithUid = supplyUid(spec);
  6500. var detail = asRawOrDie(owner2, schema2, specWithUid, [], []);
  6501. return factory2(detail, specWithUid);
  6502. };
  6503. var composite$1 = function(owner2, schema2, partTypes, factory2, spec) {
  6504. var specWithUid = supplyUid(spec);
  6505. var partSchemas = schemas(partTypes);
  6506. var partUidsSchema = defaultUidsSchema(partTypes);
  6507. var detail = asRawOrDie(owner2, schema2, specWithUid, partSchemas, [partUidsSchema]);
  6508. var subs2 = substitutes(owner2, detail, partTypes);
  6509. var components2 = components$1(owner2, detail, subs2.internals());
  6510. return factory2(detail, components2, specWithUid, subs2.externals());
  6511. };
  6512. var hasUid = function(spec) {
  6513. return has$2(spec, "uid");
  6514. };
  6515. var supplyUid = function(spec) {
  6516. return hasUid(spec) ? spec : __assign(__assign({}, spec), { uid: generate$5("uid") });
  6517. };
  6518. var isSketchSpec = function(spec) {
  6519. return spec.uid !== void 0;
  6520. };
  6521. var singleSchema = objOfOnly([
  6522. required$1("name"),
  6523. required$1("factory"),
  6524. required$1("configFields"),
  6525. defaulted("apis", {}),
  6526. defaulted("extraApis", {})
  6527. ]);
  6528. var compositeSchema = objOfOnly([
  6529. required$1("name"),
  6530. required$1("factory"),
  6531. required$1("configFields"),
  6532. required$1("partFields"),
  6533. defaulted("apis", {}),
  6534. defaulted("extraApis", {})
  6535. ]);
  6536. var single = function(rawConfig) {
  6537. var config2 = asRawOrDie$1("Sketcher for " + rawConfig.name, singleSchema, rawConfig);
  6538. var sketch2 = function(spec) {
  6539. return single$1(config2.name, config2.configFields, config2.factory, spec);
  6540. };
  6541. var apis = map$1(config2.apis, makeApi);
  6542. var extraApis = map$1(config2.extraApis, function(f, k) {
  6543. return markAsExtraApi(f, k);
  6544. });
  6545. return __assign(__assign({
  6546. name: config2.name,
  6547. configFields: config2.configFields,
  6548. sketch: sketch2
  6549. }, apis), extraApis);
  6550. };
  6551. var composite = function(rawConfig) {
  6552. var config2 = asRawOrDie$1("Sketcher for " + rawConfig.name, compositeSchema, rawConfig);
  6553. var sketch2 = function(spec) {
  6554. return composite$1(config2.name, config2.configFields, config2.partFields, config2.factory, spec);
  6555. };
  6556. var parts2 = generate$3(config2.name, config2.partFields);
  6557. var apis = map$1(config2.apis, makeApi);
  6558. var extraApis = map$1(config2.extraApis, function(f, k) {
  6559. return markAsExtraApi(f, k);
  6560. });
  6561. return __assign(__assign({
  6562. name: config2.name,
  6563. partFields: config2.partFields,
  6564. configFields: config2.configFields,
  6565. sketch: sketch2,
  6566. parts: parts2
  6567. }, apis), extraApis);
  6568. };
  6569. var inside = function(target) {
  6570. return name$2(target) === "input" && get$d(target, "type") !== "radio" || name$2(target) === "textarea";
  6571. };
  6572. var getCurrent = function(component, composeConfig, _composeState) {
  6573. return composeConfig.find(component);
  6574. };
  6575. var ComposeApis = Object.freeze({
  6576. __proto__: null,
  6577. getCurrent
  6578. });
  6579. var ComposeSchema = [required$1("find")];
  6580. var Composing = create$8({
  6581. fields: ComposeSchema,
  6582. name: "composing",
  6583. apis: ComposeApis
  6584. });
  6585. var nativeDisabled = [
  6586. "input",
  6587. "button",
  6588. "textarea",
  6589. "select"
  6590. ];
  6591. var onLoad$1 = function(component, disableConfig, disableState) {
  6592. var f = disableConfig.disabled() ? disable$1 : enable$1;
  6593. f(component, disableConfig);
  6594. };
  6595. var hasNative = function(component, config2) {
  6596. return config2.useNative === true && contains$2(nativeDisabled, name$2(component.element));
  6597. };
  6598. var nativeIsDisabled = function(component) {
  6599. return has$1(component.element, "disabled");
  6600. };
  6601. var nativeDisable = function(component) {
  6602. set$8(component.element, "disabled", "disabled");
  6603. };
  6604. var nativeEnable = function(component) {
  6605. remove$7(component.element, "disabled");
  6606. };
  6607. var ariaIsDisabled = function(component) {
  6608. return get$d(component.element, "aria-disabled") === "true";
  6609. };
  6610. var ariaDisable = function(component) {
  6611. set$8(component.element, "aria-disabled", "true");
  6612. };
  6613. var ariaEnable = function(component) {
  6614. set$8(component.element, "aria-disabled", "false");
  6615. };
  6616. var disable$1 = function(component, disableConfig, _disableState) {
  6617. disableConfig.disableClass.each(function(disableClass) {
  6618. add$2(component.element, disableClass);
  6619. });
  6620. var f = hasNative(component, disableConfig) ? nativeDisable : ariaDisable;
  6621. f(component);
  6622. disableConfig.onDisabled(component);
  6623. };
  6624. var enable$1 = function(component, disableConfig, _disableState) {
  6625. disableConfig.disableClass.each(function(disableClass) {
  6626. remove$2(component.element, disableClass);
  6627. });
  6628. var f = hasNative(component, disableConfig) ? nativeEnable : ariaEnable;
  6629. f(component);
  6630. disableConfig.onEnabled(component);
  6631. };
  6632. var isDisabled = function(component, disableConfig) {
  6633. return hasNative(component, disableConfig) ? nativeIsDisabled(component) : ariaIsDisabled(component);
  6634. };
  6635. var set$3 = function(component, disableConfig, disableState, disabled) {
  6636. var f = disabled ? disable$1 : enable$1;
  6637. f(component, disableConfig);
  6638. };
  6639. var DisableApis = Object.freeze({
  6640. __proto__: null,
  6641. enable: enable$1,
  6642. disable: disable$1,
  6643. isDisabled,
  6644. onLoad: onLoad$1,
  6645. set: set$3
  6646. });
  6647. var exhibit$5 = function(base2, disableConfig) {
  6648. return nu$7({ classes: disableConfig.disabled() ? disableConfig.disableClass.toArray() : [] });
  6649. };
  6650. var events$e = function(disableConfig, disableState) {
  6651. return derive$2([
  6652. abort(execute$5(), function(component, _simulatedEvent) {
  6653. return isDisabled(component, disableConfig);
  6654. }),
  6655. loadEvent(disableConfig, disableState, onLoad$1)
  6656. ]);
  6657. };
  6658. var ActiveDisable = Object.freeze({
  6659. __proto__: null,
  6660. exhibit: exhibit$5,
  6661. events: events$e
  6662. });
  6663. var DisableSchema = [
  6664. defaultedFunction("disabled", never),
  6665. defaulted("useNative", true),
  6666. option("disableClass"),
  6667. onHandler("onDisabled"),
  6668. onHandler("onEnabled")
  6669. ];
  6670. var Disabling = create$8({
  6671. fields: DisableSchema,
  6672. name: "disabling",
  6673. active: ActiveDisable,
  6674. apis: DisableApis
  6675. });
  6676. var dehighlightAllExcept = function(component, hConfig, hState, skip) {
  6677. var highlighted = descendants(component.element, "." + hConfig.highlightClass);
  6678. each$1(highlighted, function(h) {
  6679. if (!exists(skip, function(skipComp) {
  6680. return skipComp.element === h;
  6681. })) {
  6682. remove$2(h, hConfig.highlightClass);
  6683. component.getSystem().getByDom(h).each(function(target) {
  6684. hConfig.onDehighlight(component, target);
  6685. emit(target, dehighlight$1());
  6686. });
  6687. }
  6688. });
  6689. };
  6690. var dehighlightAll = function(component, hConfig, hState) {
  6691. return dehighlightAllExcept(component, hConfig, hState, []);
  6692. };
  6693. var dehighlight = function(component, hConfig, hState, target) {
  6694. if (isHighlighted(component, hConfig, hState, target)) {
  6695. remove$2(target.element, hConfig.highlightClass);
  6696. hConfig.onDehighlight(component, target);
  6697. emit(target, dehighlight$1());
  6698. }
  6699. };
  6700. var highlight = function(component, hConfig, hState, target) {
  6701. dehighlightAllExcept(component, hConfig, hState, [target]);
  6702. if (!isHighlighted(component, hConfig, hState, target)) {
  6703. add$2(target.element, hConfig.highlightClass);
  6704. hConfig.onHighlight(component, target);
  6705. emit(target, highlight$1());
  6706. }
  6707. };
  6708. var highlightFirst = function(component, hConfig, hState) {
  6709. getFirst(component, hConfig).each(function(firstComp) {
  6710. highlight(component, hConfig, hState, firstComp);
  6711. });
  6712. };
  6713. var highlightLast = function(component, hConfig, hState) {
  6714. getLast(component, hConfig).each(function(lastComp) {
  6715. highlight(component, hConfig, hState, lastComp);
  6716. });
  6717. };
  6718. var highlightAt = function(component, hConfig, hState, index) {
  6719. getByIndex(component, hConfig, hState, index).fold(function(err) {
  6720. throw err;
  6721. }, function(firstComp) {
  6722. highlight(component, hConfig, hState, firstComp);
  6723. });
  6724. };
  6725. var highlightBy = function(component, hConfig, hState, predicate) {
  6726. var candidates = getCandidates(component, hConfig);
  6727. var targetComp = find$5(candidates, predicate);
  6728. targetComp.each(function(c) {
  6729. highlight(component, hConfig, hState, c);
  6730. });
  6731. };
  6732. var isHighlighted = function(component, hConfig, hState, queryTarget) {
  6733. return has(queryTarget.element, hConfig.highlightClass);
  6734. };
  6735. var getHighlighted = function(component, hConfig, _hState) {
  6736. return descendant(component.element, "." + hConfig.highlightClass).bind(function(e) {
  6737. return component.getSystem().getByDom(e).toOptional();
  6738. });
  6739. };
  6740. var getByIndex = function(component, hConfig, hState, index) {
  6741. var items = descendants(component.element, "." + hConfig.itemClass);
  6742. return Optional.from(items[index]).fold(function() {
  6743. return Result.error(new Error("No element found with index " + index));
  6744. }, component.getSystem().getByDom);
  6745. };
  6746. var getFirst = function(component, hConfig, _hState) {
  6747. return descendant(component.element, "." + hConfig.itemClass).bind(function(e) {
  6748. return component.getSystem().getByDom(e).toOptional();
  6749. });
  6750. };
  6751. var getLast = function(component, hConfig, _hState) {
  6752. var items = descendants(component.element, "." + hConfig.itemClass);
  6753. var last2 = items.length > 0 ? Optional.some(items[items.length - 1]) : Optional.none();
  6754. return last2.bind(function(c) {
  6755. return component.getSystem().getByDom(c).toOptional();
  6756. });
  6757. };
  6758. var getDelta$2 = function(component, hConfig, hState, delta) {
  6759. var items = descendants(component.element, "." + hConfig.itemClass);
  6760. var current = findIndex$1(items, function(item2) {
  6761. return has(item2, hConfig.highlightClass);
  6762. });
  6763. return current.bind(function(selected) {
  6764. var dest = cycleBy(selected, delta, 0, items.length - 1);
  6765. return component.getSystem().getByDom(items[dest]).toOptional();
  6766. });
  6767. };
  6768. var getPrevious = function(component, hConfig, hState) {
  6769. return getDelta$2(component, hConfig, hState, -1);
  6770. };
  6771. var getNext = function(component, hConfig, hState) {
  6772. return getDelta$2(component, hConfig, hState, 1);
  6773. };
  6774. var getCandidates = function(component, hConfig, _hState) {
  6775. var items = descendants(component.element, "." + hConfig.itemClass);
  6776. return cat(map$2(items, function(i) {
  6777. return component.getSystem().getByDom(i).toOptional();
  6778. }));
  6779. };
  6780. var HighlightApis = Object.freeze({
  6781. __proto__: null,
  6782. dehighlightAll,
  6783. dehighlight,
  6784. highlight,
  6785. highlightFirst,
  6786. highlightLast,
  6787. highlightAt,
  6788. highlightBy,
  6789. isHighlighted,
  6790. getHighlighted,
  6791. getFirst,
  6792. getLast,
  6793. getPrevious,
  6794. getNext,
  6795. getCandidates
  6796. });
  6797. var HighlightSchema = [
  6798. required$1("highlightClass"),
  6799. required$1("itemClass"),
  6800. onHandler("onHighlight"),
  6801. onHandler("onDehighlight")
  6802. ];
  6803. var Highlighting = create$8({
  6804. fields: HighlightSchema,
  6805. name: "highlighting",
  6806. apis: HighlightApis
  6807. });
  6808. var BACKSPACE = [8];
  6809. var TAB = [9];
  6810. var ENTER = [13];
  6811. var ESCAPE = [27];
  6812. var SPACE = [32];
  6813. var LEFT = [37];
  6814. var UP = [38];
  6815. var RIGHT = [39];
  6816. var DOWN = [40];
  6817. var cyclePrev = function(values2, index, predicate) {
  6818. var before2 = reverse(values2.slice(0, index));
  6819. var after2 = reverse(values2.slice(index + 1));
  6820. return find$5(before2.concat(after2), predicate);
  6821. };
  6822. var tryPrev = function(values2, index, predicate) {
  6823. var before2 = reverse(values2.slice(0, index));
  6824. return find$5(before2, predicate);
  6825. };
  6826. var cycleNext = function(values2, index, predicate) {
  6827. var before2 = values2.slice(0, index);
  6828. var after2 = values2.slice(index + 1);
  6829. return find$5(after2.concat(before2), predicate);
  6830. };
  6831. var tryNext = function(values2, index, predicate) {
  6832. var after2 = values2.slice(index + 1);
  6833. return find$5(after2, predicate);
  6834. };
  6835. var inSet = function(keys2) {
  6836. return function(event) {
  6837. var raw = event.raw;
  6838. return contains$2(keys2, raw.which);
  6839. };
  6840. };
  6841. var and = function(preds) {
  6842. return function(event) {
  6843. return forall(preds, function(pred) {
  6844. return pred(event);
  6845. });
  6846. };
  6847. };
  6848. var isShift = function(event) {
  6849. var raw = event.raw;
  6850. return raw.shiftKey === true;
  6851. };
  6852. var isControl = function(event) {
  6853. var raw = event.raw;
  6854. return raw.ctrlKey === true;
  6855. };
  6856. var isNotShift = not(isShift);
  6857. var rule = function(matches, action) {
  6858. return {
  6859. matches,
  6860. classification: action
  6861. };
  6862. };
  6863. var choose = function(transitions, event) {
  6864. var transition = find$5(transitions, function(t2) {
  6865. return t2.matches(event);
  6866. });
  6867. return transition.map(function(t2) {
  6868. return t2.classification;
  6869. });
  6870. };
  6871. var reportFocusShifting = function(component, prevFocus, newFocus) {
  6872. var noChange = prevFocus.exists(function(p) {
  6873. return newFocus.exists(function(n) {
  6874. return eq(n, p);
  6875. });
  6876. });
  6877. if (!noChange) {
  6878. emitWith(component, focusShifted(), {
  6879. prevFocus,
  6880. newFocus
  6881. });
  6882. }
  6883. };
  6884. var dom$2 = function() {
  6885. var get2 = function(component) {
  6886. return search(component.element);
  6887. };
  6888. var set2 = function(component, focusee) {
  6889. var prevFocus = get2(component);
  6890. component.getSystem().triggerFocus(focusee, component.element);
  6891. var newFocus = get2(component);
  6892. reportFocusShifting(component, prevFocus, newFocus);
  6893. };
  6894. return {
  6895. get: get2,
  6896. set: set2
  6897. };
  6898. };
  6899. var highlights = function() {
  6900. var get2 = function(component) {
  6901. return Highlighting.getHighlighted(component).map(function(item2) {
  6902. return item2.element;
  6903. });
  6904. };
  6905. var set2 = function(component, element2) {
  6906. var prevFocus = get2(component);
  6907. component.getSystem().getByDom(element2).fold(noop, function(item2) {
  6908. Highlighting.highlight(component, item2);
  6909. });
  6910. var newFocus = get2(component);
  6911. reportFocusShifting(component, prevFocus, newFocus);
  6912. };
  6913. return {
  6914. get: get2,
  6915. set: set2
  6916. };
  6917. };
  6918. var FocusInsideModes;
  6919. (function(FocusInsideModes2) {
  6920. FocusInsideModes2["OnFocusMode"] = "onFocus";
  6921. FocusInsideModes2["OnEnterOrSpaceMode"] = "onEnterOrSpace";
  6922. FocusInsideModes2["OnApiMode"] = "onApi";
  6923. })(FocusInsideModes || (FocusInsideModes = {}));
  6924. var typical = function(infoSchema, stateInit, getKeydownRules2, getKeyupRules2, optFocusIn) {
  6925. var schema2 = function() {
  6926. return infoSchema.concat([
  6927. defaulted("focusManager", dom$2()),
  6928. defaultedOf("focusInside", "onFocus", valueOf(function(val) {
  6929. return contains$2([
  6930. "onFocus",
  6931. "onEnterOrSpace",
  6932. "onApi"
  6933. ], val) ? Result.value(val) : Result.error("Invalid value for focusInside");
  6934. })),
  6935. output$1("handler", me),
  6936. output$1("state", stateInit),
  6937. output$1("sendFocusIn", optFocusIn)
  6938. ]);
  6939. };
  6940. var processKey = function(component, simulatedEvent, getRules, keyingConfig, keyingState) {
  6941. var rules = getRules(component, simulatedEvent, keyingConfig, keyingState);
  6942. return choose(rules, simulatedEvent.event).bind(function(rule2) {
  6943. return rule2(component, simulatedEvent, keyingConfig, keyingState);
  6944. });
  6945. };
  6946. var toEvents2 = function(keyingConfig, keyingState) {
  6947. var onFocusHandler = keyingConfig.focusInside !== FocusInsideModes.OnFocusMode ? Optional.none() : optFocusIn(keyingConfig).map(function(focusIn2) {
  6948. return run$1(focus$4(), function(component, simulatedEvent) {
  6949. focusIn2(component, keyingConfig, keyingState);
  6950. simulatedEvent.stop();
  6951. });
  6952. });
  6953. var tryGoInsideComponent = function(component, simulatedEvent) {
  6954. var isEnterOrSpace = inSet(SPACE.concat(ENTER))(simulatedEvent.event);
  6955. if (keyingConfig.focusInside === FocusInsideModes.OnEnterOrSpaceMode && isEnterOrSpace && isSource(component, simulatedEvent)) {
  6956. optFocusIn(keyingConfig).each(function(focusIn2) {
  6957. focusIn2(component, keyingConfig, keyingState);
  6958. simulatedEvent.stop();
  6959. });
  6960. }
  6961. };
  6962. var keyboardEvents = [
  6963. run$1(keydown(), function(component, simulatedEvent) {
  6964. processKey(component, simulatedEvent, getKeydownRules2, keyingConfig, keyingState).fold(function() {
  6965. tryGoInsideComponent(component, simulatedEvent);
  6966. }, function(_) {
  6967. simulatedEvent.stop();
  6968. });
  6969. }),
  6970. run$1(keyup(), function(component, simulatedEvent) {
  6971. processKey(component, simulatedEvent, getKeyupRules2, keyingConfig, keyingState).each(function(_) {
  6972. simulatedEvent.stop();
  6973. });
  6974. })
  6975. ];
  6976. return derive$2(onFocusHandler.toArray().concat(keyboardEvents));
  6977. };
  6978. var me = {
  6979. schema: schema2,
  6980. processKey,
  6981. toEvents: toEvents2
  6982. };
  6983. return me;
  6984. };
  6985. var create$6 = function(cyclicField) {
  6986. var schema2 = [
  6987. option("onEscape"),
  6988. option("onEnter"),
  6989. defaulted("selector", '[data-alloy-tabstop="true"]:not(:disabled)'),
  6990. defaulted("firstTabstop", 0),
  6991. defaulted("useTabstopAt", always),
  6992. option("visibilitySelector")
  6993. ].concat([cyclicField]);
  6994. var isVisible2 = function(tabbingConfig, element2) {
  6995. var target = tabbingConfig.visibilitySelector.bind(function(sel) {
  6996. return closest$1(element2, sel);
  6997. }).getOr(element2);
  6998. return get$b(target) > 0;
  6999. };
  7000. var findInitial = function(component, tabbingConfig) {
  7001. var tabstops = descendants(component.element, tabbingConfig.selector);
  7002. var visibles = filter$2(tabstops, function(elem) {
  7003. return isVisible2(tabbingConfig, elem);
  7004. });
  7005. return Optional.from(visibles[tabbingConfig.firstTabstop]);
  7006. };
  7007. var findCurrent2 = function(component, tabbingConfig) {
  7008. return tabbingConfig.focusManager.get(component).bind(function(elem) {
  7009. return closest$1(elem, tabbingConfig.selector);
  7010. });
  7011. };
  7012. var isTabstop = function(tabbingConfig, element2) {
  7013. return isVisible2(tabbingConfig, element2) && tabbingConfig.useTabstopAt(element2);
  7014. };
  7015. var focusIn2 = function(component, tabbingConfig, _tabbingState) {
  7016. findInitial(component, tabbingConfig).each(function(target) {
  7017. tabbingConfig.focusManager.set(component, target);
  7018. });
  7019. };
  7020. var goFromTabstop = function(component, tabstops, stopIndex, tabbingConfig, cycle) {
  7021. return cycle(tabstops, stopIndex, function(elem) {
  7022. return isTabstop(tabbingConfig, elem);
  7023. }).fold(function() {
  7024. return tabbingConfig.cyclic ? Optional.some(true) : Optional.none();
  7025. }, function(target) {
  7026. tabbingConfig.focusManager.set(component, target);
  7027. return Optional.some(true);
  7028. });
  7029. };
  7030. var go2 = function(component, _simulatedEvent, tabbingConfig, cycle) {
  7031. var tabstops = descendants(component.element, tabbingConfig.selector);
  7032. return findCurrent2(component, tabbingConfig).bind(function(tabstop) {
  7033. var optStopIndex = findIndex$1(tabstops, curry(eq, tabstop));
  7034. return optStopIndex.bind(function(stopIndex) {
  7035. return goFromTabstop(component, tabstops, stopIndex, tabbingConfig, cycle);
  7036. });
  7037. });
  7038. };
  7039. var goBackwards = function(component, simulatedEvent, tabbingConfig) {
  7040. var navigate = tabbingConfig.cyclic ? cyclePrev : tryPrev;
  7041. return go2(component, simulatedEvent, tabbingConfig, navigate);
  7042. };
  7043. var goForwards = function(component, simulatedEvent, tabbingConfig) {
  7044. var navigate = tabbingConfig.cyclic ? cycleNext : tryNext;
  7045. return go2(component, simulatedEvent, tabbingConfig, navigate);
  7046. };
  7047. var execute2 = function(component, simulatedEvent, tabbingConfig) {
  7048. return tabbingConfig.onEnter.bind(function(f) {
  7049. return f(component, simulatedEvent);
  7050. });
  7051. };
  7052. var exit = function(component, simulatedEvent, tabbingConfig) {
  7053. return tabbingConfig.onEscape.bind(function(f) {
  7054. return f(component, simulatedEvent);
  7055. });
  7056. };
  7057. var getKeydownRules2 = constant$1([
  7058. rule(and([
  7059. isShift,
  7060. inSet(TAB)
  7061. ]), goBackwards),
  7062. rule(inSet(TAB), goForwards),
  7063. rule(inSet(ESCAPE), exit),
  7064. rule(and([
  7065. isNotShift,
  7066. inSet(ENTER)
  7067. ]), execute2)
  7068. ]);
  7069. var getKeyupRules2 = constant$1([]);
  7070. return typical(schema2, NoState.init, getKeydownRules2, getKeyupRules2, function() {
  7071. return Optional.some(focusIn2);
  7072. });
  7073. };
  7074. var AcyclicType = create$6(customField("cyclic", never));
  7075. var CyclicType = create$6(customField("cyclic", always));
  7076. var doDefaultExecute = function(component, _simulatedEvent, focused) {
  7077. dispatch(component, focused, execute$5());
  7078. return Optional.some(true);
  7079. };
  7080. var defaultExecute = function(component, simulatedEvent, focused) {
  7081. var isComplex = inside(focused) && inSet(SPACE)(simulatedEvent.event);
  7082. return isComplex ? Optional.none() : doDefaultExecute(component, simulatedEvent, focused);
  7083. };
  7084. var stopEventForFirefox = function(_component, _simulatedEvent) {
  7085. return Optional.some(true);
  7086. };
  7087. var schema$v = [
  7088. defaulted("execute", defaultExecute),
  7089. defaulted("useSpace", false),
  7090. defaulted("useEnter", true),
  7091. defaulted("useControlEnter", false),
  7092. defaulted("useDown", false)
  7093. ];
  7094. var execute$4 = function(component, simulatedEvent, executeConfig) {
  7095. return executeConfig.execute(component, simulatedEvent, component.element);
  7096. };
  7097. var getKeydownRules$5 = function(component, _simulatedEvent, executeConfig, _executeState) {
  7098. var spaceExec = executeConfig.useSpace && !inside(component.element) ? SPACE : [];
  7099. var enterExec = executeConfig.useEnter ? ENTER : [];
  7100. var downExec = executeConfig.useDown ? DOWN : [];
  7101. var execKeys = spaceExec.concat(enterExec).concat(downExec);
  7102. return [rule(inSet(execKeys), execute$4)].concat(executeConfig.useControlEnter ? [rule(and([
  7103. isControl,
  7104. inSet(ENTER)
  7105. ]), execute$4)] : []);
  7106. };
  7107. var getKeyupRules$5 = function(component, _simulatedEvent, executeConfig, _executeState) {
  7108. return executeConfig.useSpace && !inside(component.element) ? [rule(inSet(SPACE), stopEventForFirefox)] : [];
  7109. };
  7110. var ExecutionType = typical(schema$v, NoState.init, getKeydownRules$5, getKeyupRules$5, function() {
  7111. return Optional.none();
  7112. });
  7113. var flatgrid$1 = function() {
  7114. var dimensions = value$1();
  7115. var setGridSize = function(numRows, numColumns) {
  7116. dimensions.set({
  7117. numRows,
  7118. numColumns
  7119. });
  7120. };
  7121. var getNumRows = function() {
  7122. return dimensions.get().map(function(d) {
  7123. return d.numRows;
  7124. });
  7125. };
  7126. var getNumColumns = function() {
  7127. return dimensions.get().map(function(d) {
  7128. return d.numColumns;
  7129. });
  7130. };
  7131. return nu$8({
  7132. readState: function() {
  7133. return dimensions.get().map(function(d) {
  7134. return {
  7135. numRows: String(d.numRows),
  7136. numColumns: String(d.numColumns)
  7137. };
  7138. }).getOr({
  7139. numRows: "?",
  7140. numColumns: "?"
  7141. });
  7142. },
  7143. setGridSize,
  7144. getNumRows,
  7145. getNumColumns
  7146. });
  7147. };
  7148. var init$d = function(spec) {
  7149. return spec.state(spec);
  7150. };
  7151. var KeyingState = Object.freeze({
  7152. __proto__: null,
  7153. flatgrid: flatgrid$1,
  7154. init: init$d
  7155. });
  7156. var useH = function(movement) {
  7157. return function(component, simulatedEvent, config2, state) {
  7158. var move2 = movement(component.element);
  7159. return use(move2, component, simulatedEvent, config2, state);
  7160. };
  7161. };
  7162. var west$1 = function(moveLeft2, moveRight2) {
  7163. var movement = onDirection(moveLeft2, moveRight2);
  7164. return useH(movement);
  7165. };
  7166. var east$1 = function(moveLeft2, moveRight2) {
  7167. var movement = onDirection(moveRight2, moveLeft2);
  7168. return useH(movement);
  7169. };
  7170. var useV = function(move2) {
  7171. return function(component, simulatedEvent, config2, state) {
  7172. return use(move2, component, simulatedEvent, config2, state);
  7173. };
  7174. };
  7175. var use = function(move2, component, simulatedEvent, config2, state) {
  7176. var outcome = config2.focusManager.get(component).bind(function(focused) {
  7177. return move2(component.element, focused, config2, state);
  7178. });
  7179. return outcome.map(function(newFocus) {
  7180. config2.focusManager.set(component, newFocus);
  7181. return true;
  7182. });
  7183. };
  7184. var north$1 = useV;
  7185. var south$1 = useV;
  7186. var move$1 = useV;
  7187. var isHidden$1 = function(dom2) {
  7188. return dom2.offsetWidth <= 0 && dom2.offsetHeight <= 0;
  7189. };
  7190. var isVisible = function(element2) {
  7191. return !isHidden$1(element2.dom);
  7192. };
  7193. var locate = function(candidates, predicate) {
  7194. return findIndex$1(candidates, predicate).map(function(index) {
  7195. return {
  7196. index,
  7197. candidates
  7198. };
  7199. });
  7200. };
  7201. var locateVisible = function(container, current, selector) {
  7202. var predicate = function(x) {
  7203. return eq(x, current);
  7204. };
  7205. var candidates = descendants(container, selector);
  7206. var visible = filter$2(candidates, isVisible);
  7207. return locate(visible, predicate);
  7208. };
  7209. var findIndex = function(elements, target) {
  7210. return findIndex$1(elements, function(elem) {
  7211. return eq(target, elem);
  7212. });
  7213. };
  7214. var withGrid = function(values2, index, numCols, f) {
  7215. var oldRow = Math.floor(index / numCols);
  7216. var oldColumn = index % numCols;
  7217. return f(oldRow, oldColumn).bind(function(address) {
  7218. var newIndex = address.row * numCols + address.column;
  7219. return newIndex >= 0 && newIndex < values2.length ? Optional.some(values2[newIndex]) : Optional.none();
  7220. });
  7221. };
  7222. var cycleHorizontal$1 = function(values2, index, numRows, numCols, delta) {
  7223. return withGrid(values2, index, numCols, function(oldRow, oldColumn) {
  7224. var onLastRow = oldRow === numRows - 1;
  7225. var colsInRow = onLastRow ? values2.length - oldRow * numCols : numCols;
  7226. var newColumn = cycleBy(oldColumn, delta, 0, colsInRow - 1);
  7227. return Optional.some({
  7228. row: oldRow,
  7229. column: newColumn
  7230. });
  7231. });
  7232. };
  7233. var cycleVertical$1 = function(values2, index, numRows, numCols, delta) {
  7234. return withGrid(values2, index, numCols, function(oldRow, oldColumn) {
  7235. var newRow = cycleBy(oldRow, delta, 0, numRows - 1);
  7236. var onLastRow = newRow === numRows - 1;
  7237. var colsInRow = onLastRow ? values2.length - newRow * numCols : numCols;
  7238. var newCol = clamp$1(oldColumn, 0, colsInRow - 1);
  7239. return Optional.some({
  7240. row: newRow,
  7241. column: newCol
  7242. });
  7243. });
  7244. };
  7245. var cycleRight$1 = function(values2, index, numRows, numCols) {
  7246. return cycleHorizontal$1(values2, index, numRows, numCols, 1);
  7247. };
  7248. var cycleLeft$1 = function(values2, index, numRows, numCols) {
  7249. return cycleHorizontal$1(values2, index, numRows, numCols, -1);
  7250. };
  7251. var cycleUp$1 = function(values2, index, numRows, numCols) {
  7252. return cycleVertical$1(values2, index, numRows, numCols, -1);
  7253. };
  7254. var cycleDown$1 = function(values2, index, numRows, numCols) {
  7255. return cycleVertical$1(values2, index, numRows, numCols, 1);
  7256. };
  7257. var schema$u = [
  7258. required$1("selector"),
  7259. defaulted("execute", defaultExecute),
  7260. onKeyboardHandler("onEscape"),
  7261. defaulted("captureTab", false),
  7262. initSize()
  7263. ];
  7264. var focusIn$3 = function(component, gridConfig, _gridState) {
  7265. descendant(component.element, gridConfig.selector).each(function(first2) {
  7266. gridConfig.focusManager.set(component, first2);
  7267. });
  7268. };
  7269. var findCurrent$1 = function(component, gridConfig) {
  7270. return gridConfig.focusManager.get(component).bind(function(elem) {
  7271. return closest$1(elem, gridConfig.selector);
  7272. });
  7273. };
  7274. var execute$3 = function(component, simulatedEvent, gridConfig, _gridState) {
  7275. return findCurrent$1(component, gridConfig).bind(function(focused) {
  7276. return gridConfig.execute(component, simulatedEvent, focused);
  7277. });
  7278. };
  7279. var doMove$2 = function(cycle) {
  7280. return function(element2, focused, gridConfig, gridState) {
  7281. return locateVisible(element2, focused, gridConfig.selector).bind(function(identified) {
  7282. return cycle(identified.candidates, identified.index, gridState.getNumRows().getOr(gridConfig.initSize.numRows), gridState.getNumColumns().getOr(gridConfig.initSize.numColumns));
  7283. });
  7284. };
  7285. };
  7286. var handleTab = function(_component, _simulatedEvent, gridConfig) {
  7287. return gridConfig.captureTab ? Optional.some(true) : Optional.none();
  7288. };
  7289. var doEscape$1 = function(component, simulatedEvent, gridConfig) {
  7290. return gridConfig.onEscape(component, simulatedEvent);
  7291. };
  7292. var moveLeft$3 = doMove$2(cycleLeft$1);
  7293. var moveRight$3 = doMove$2(cycleRight$1);
  7294. var moveNorth$1 = doMove$2(cycleUp$1);
  7295. var moveSouth$1 = doMove$2(cycleDown$1);
  7296. var getKeydownRules$4 = constant$1([
  7297. rule(inSet(LEFT), west$1(moveLeft$3, moveRight$3)),
  7298. rule(inSet(RIGHT), east$1(moveLeft$3, moveRight$3)),
  7299. rule(inSet(UP), north$1(moveNorth$1)),
  7300. rule(inSet(DOWN), south$1(moveSouth$1)),
  7301. rule(and([
  7302. isShift,
  7303. inSet(TAB)
  7304. ]), handleTab),
  7305. rule(and([
  7306. isNotShift,
  7307. inSet(TAB)
  7308. ]), handleTab),
  7309. rule(inSet(ESCAPE), doEscape$1),
  7310. rule(inSet(SPACE.concat(ENTER)), execute$3)
  7311. ]);
  7312. var getKeyupRules$4 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7313. var FlatgridType = typical(schema$u, flatgrid$1, getKeydownRules$4, getKeyupRules$4, function() {
  7314. return Optional.some(focusIn$3);
  7315. });
  7316. var horizontal = function(container, selector, current, delta) {
  7317. var isDisabledButton = function(candidate) {
  7318. return name$2(candidate) === "button" && get$d(candidate, "disabled") === "disabled";
  7319. };
  7320. var tryCycle = function(initial, index, candidates) {
  7321. var newIndex = cycleBy(index, delta, 0, candidates.length - 1);
  7322. if (newIndex === initial) {
  7323. return Optional.none();
  7324. } else {
  7325. return isDisabledButton(candidates[newIndex]) ? tryCycle(initial, newIndex, candidates) : Optional.from(candidates[newIndex]);
  7326. }
  7327. };
  7328. return locateVisible(container, current, selector).bind(function(identified) {
  7329. var index = identified.index;
  7330. var candidates = identified.candidates;
  7331. return tryCycle(index, index, candidates);
  7332. });
  7333. };
  7334. var schema$t = [
  7335. required$1("selector"),
  7336. defaulted("getInitial", Optional.none),
  7337. defaulted("execute", defaultExecute),
  7338. onKeyboardHandler("onEscape"),
  7339. defaulted("executeOnMove", false),
  7340. defaulted("allowVertical", true)
  7341. ];
  7342. var findCurrent = function(component, flowConfig) {
  7343. return flowConfig.focusManager.get(component).bind(function(elem) {
  7344. return closest$1(elem, flowConfig.selector);
  7345. });
  7346. };
  7347. var execute$2 = function(component, simulatedEvent, flowConfig) {
  7348. return findCurrent(component, flowConfig).bind(function(focused) {
  7349. return flowConfig.execute(component, simulatedEvent, focused);
  7350. });
  7351. };
  7352. var focusIn$2 = function(component, flowConfig, _state) {
  7353. flowConfig.getInitial(component).orThunk(function() {
  7354. return descendant(component.element, flowConfig.selector);
  7355. }).each(function(first2) {
  7356. flowConfig.focusManager.set(component, first2);
  7357. });
  7358. };
  7359. var moveLeft$2 = function(element2, focused, info) {
  7360. return horizontal(element2, info.selector, focused, -1);
  7361. };
  7362. var moveRight$2 = function(element2, focused, info) {
  7363. return horizontal(element2, info.selector, focused, 1);
  7364. };
  7365. var doMove$1 = function(movement) {
  7366. return function(component, simulatedEvent, flowConfig, flowState) {
  7367. return movement(component, simulatedEvent, flowConfig, flowState).bind(function() {
  7368. return flowConfig.executeOnMove ? execute$2(component, simulatedEvent, flowConfig) : Optional.some(true);
  7369. });
  7370. };
  7371. };
  7372. var doEscape = function(component, simulatedEvent, flowConfig) {
  7373. return flowConfig.onEscape(component, simulatedEvent);
  7374. };
  7375. var getKeydownRules$3 = function(_component, _se, flowConfig, _flowState) {
  7376. var westMovers = LEFT.concat(flowConfig.allowVertical ? UP : []);
  7377. var eastMovers = RIGHT.concat(flowConfig.allowVertical ? DOWN : []);
  7378. return [
  7379. rule(inSet(westMovers), doMove$1(west$1(moveLeft$2, moveRight$2))),
  7380. rule(inSet(eastMovers), doMove$1(east$1(moveLeft$2, moveRight$2))),
  7381. rule(inSet(ENTER), execute$2),
  7382. rule(inSet(SPACE), execute$2),
  7383. rule(inSet(ESCAPE), doEscape)
  7384. ];
  7385. };
  7386. var getKeyupRules$3 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7387. var FlowType = typical(schema$t, NoState.init, getKeydownRules$3, getKeyupRules$3, function() {
  7388. return Optional.some(focusIn$2);
  7389. });
  7390. var toCell = function(matrix2, rowIndex, columnIndex) {
  7391. return Optional.from(matrix2[rowIndex]).bind(function(row) {
  7392. return Optional.from(row[columnIndex]).map(function(cell) {
  7393. return {
  7394. rowIndex,
  7395. columnIndex,
  7396. cell
  7397. };
  7398. });
  7399. });
  7400. };
  7401. var cycleHorizontal = function(matrix2, rowIndex, startCol, deltaCol) {
  7402. var row = matrix2[rowIndex];
  7403. var colsInRow = row.length;
  7404. var newColIndex = cycleBy(startCol, deltaCol, 0, colsInRow - 1);
  7405. return toCell(matrix2, rowIndex, newColIndex);
  7406. };
  7407. var cycleVertical = function(matrix2, colIndex, startRow, deltaRow) {
  7408. var nextRowIndex = cycleBy(startRow, deltaRow, 0, matrix2.length - 1);
  7409. var colsInNextRow = matrix2[nextRowIndex].length;
  7410. var nextColIndex = clamp$1(colIndex, 0, colsInNextRow - 1);
  7411. return toCell(matrix2, nextRowIndex, nextColIndex);
  7412. };
  7413. var moveHorizontal = function(matrix2, rowIndex, startCol, deltaCol) {
  7414. var row = matrix2[rowIndex];
  7415. var colsInRow = row.length;
  7416. var newColIndex = clamp$1(startCol + deltaCol, 0, colsInRow - 1);
  7417. return toCell(matrix2, rowIndex, newColIndex);
  7418. };
  7419. var moveVertical = function(matrix2, colIndex, startRow, deltaRow) {
  7420. var nextRowIndex = clamp$1(startRow + deltaRow, 0, matrix2.length - 1);
  7421. var colsInNextRow = matrix2[nextRowIndex].length;
  7422. var nextColIndex = clamp$1(colIndex, 0, colsInNextRow - 1);
  7423. return toCell(matrix2, nextRowIndex, nextColIndex);
  7424. };
  7425. var cycleRight = function(matrix2, startRow, startCol) {
  7426. return cycleHorizontal(matrix2, startRow, startCol, 1);
  7427. };
  7428. var cycleLeft = function(matrix2, startRow, startCol) {
  7429. return cycleHorizontal(matrix2, startRow, startCol, -1);
  7430. };
  7431. var cycleUp = function(matrix2, startRow, startCol) {
  7432. return cycleVertical(matrix2, startCol, startRow, -1);
  7433. };
  7434. var cycleDown = function(matrix2, startRow, startCol) {
  7435. return cycleVertical(matrix2, startCol, startRow, 1);
  7436. };
  7437. var moveLeft$1 = function(matrix2, startRow, startCol) {
  7438. return moveHorizontal(matrix2, startRow, startCol, -1);
  7439. };
  7440. var moveRight$1 = function(matrix2, startRow, startCol) {
  7441. return moveHorizontal(matrix2, startRow, startCol, 1);
  7442. };
  7443. var moveUp$1 = function(matrix2, startRow, startCol) {
  7444. return moveVertical(matrix2, startCol, startRow, -1);
  7445. };
  7446. var moveDown$1 = function(matrix2, startRow, startCol) {
  7447. return moveVertical(matrix2, startCol, startRow, 1);
  7448. };
  7449. var schema$s = [
  7450. requiredObjOf("selectors", [
  7451. required$1("row"),
  7452. required$1("cell")
  7453. ]),
  7454. defaulted("cycles", true),
  7455. defaulted("previousSelector", Optional.none),
  7456. defaulted("execute", defaultExecute)
  7457. ];
  7458. var focusIn$1 = function(component, matrixConfig, _state) {
  7459. var focused = matrixConfig.previousSelector(component).orThunk(function() {
  7460. var selectors = matrixConfig.selectors;
  7461. return descendant(component.element, selectors.cell);
  7462. });
  7463. focused.each(function(cell) {
  7464. matrixConfig.focusManager.set(component, cell);
  7465. });
  7466. };
  7467. var execute$1 = function(component, simulatedEvent, matrixConfig) {
  7468. return search(component.element).bind(function(focused) {
  7469. return matrixConfig.execute(component, simulatedEvent, focused);
  7470. });
  7471. };
  7472. var toMatrix = function(rows, matrixConfig) {
  7473. return map$2(rows, function(row) {
  7474. return descendants(row, matrixConfig.selectors.cell);
  7475. });
  7476. };
  7477. var doMove = function(ifCycle, ifMove) {
  7478. return function(element2, focused, matrixConfig) {
  7479. var move2 = matrixConfig.cycles ? ifCycle : ifMove;
  7480. return closest$1(focused, matrixConfig.selectors.row).bind(function(inRow) {
  7481. var cellsInRow = descendants(inRow, matrixConfig.selectors.cell);
  7482. return findIndex(cellsInRow, focused).bind(function(colIndex) {
  7483. var allRows = descendants(element2, matrixConfig.selectors.row);
  7484. return findIndex(allRows, inRow).bind(function(rowIndex) {
  7485. var matrix2 = toMatrix(allRows, matrixConfig);
  7486. return move2(matrix2, rowIndex, colIndex).map(function(next) {
  7487. return next.cell;
  7488. });
  7489. });
  7490. });
  7491. });
  7492. };
  7493. };
  7494. var moveLeft = doMove(cycleLeft, moveLeft$1);
  7495. var moveRight = doMove(cycleRight, moveRight$1);
  7496. var moveNorth = doMove(cycleUp, moveUp$1);
  7497. var moveSouth = doMove(cycleDown, moveDown$1);
  7498. var getKeydownRules$2 = constant$1([
  7499. rule(inSet(LEFT), west$1(moveLeft, moveRight)),
  7500. rule(inSet(RIGHT), east$1(moveLeft, moveRight)),
  7501. rule(inSet(UP), north$1(moveNorth)),
  7502. rule(inSet(DOWN), south$1(moveSouth)),
  7503. rule(inSet(SPACE.concat(ENTER)), execute$1)
  7504. ]);
  7505. var getKeyupRules$2 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7506. var MatrixType = typical(schema$s, NoState.init, getKeydownRules$2, getKeyupRules$2, function() {
  7507. return Optional.some(focusIn$1);
  7508. });
  7509. var schema$r = [
  7510. required$1("selector"),
  7511. defaulted("execute", defaultExecute),
  7512. defaulted("moveOnTab", false)
  7513. ];
  7514. var execute = function(component, simulatedEvent, menuConfig) {
  7515. return menuConfig.focusManager.get(component).bind(function(focused) {
  7516. return menuConfig.execute(component, simulatedEvent, focused);
  7517. });
  7518. };
  7519. var focusIn = function(component, menuConfig, _state) {
  7520. descendant(component.element, menuConfig.selector).each(function(first2) {
  7521. menuConfig.focusManager.set(component, first2);
  7522. });
  7523. };
  7524. var moveUp = function(element2, focused, info) {
  7525. return horizontal(element2, info.selector, focused, -1);
  7526. };
  7527. var moveDown = function(element2, focused, info) {
  7528. return horizontal(element2, info.selector, focused, 1);
  7529. };
  7530. var fireShiftTab = function(component, simulatedEvent, menuConfig, menuState) {
  7531. return menuConfig.moveOnTab ? move$1(moveUp)(component, simulatedEvent, menuConfig, menuState) : Optional.none();
  7532. };
  7533. var fireTab = function(component, simulatedEvent, menuConfig, menuState) {
  7534. return menuConfig.moveOnTab ? move$1(moveDown)(component, simulatedEvent, menuConfig, menuState) : Optional.none();
  7535. };
  7536. var getKeydownRules$1 = constant$1([
  7537. rule(inSet(UP), move$1(moveUp)),
  7538. rule(inSet(DOWN), move$1(moveDown)),
  7539. rule(and([
  7540. isShift,
  7541. inSet(TAB)
  7542. ]), fireShiftTab),
  7543. rule(and([
  7544. isNotShift,
  7545. inSet(TAB)
  7546. ]), fireTab),
  7547. rule(inSet(ENTER), execute),
  7548. rule(inSet(SPACE), execute)
  7549. ]);
  7550. var getKeyupRules$1 = constant$1([rule(inSet(SPACE), stopEventForFirefox)]);
  7551. var MenuType = typical(schema$r, NoState.init, getKeydownRules$1, getKeyupRules$1, function() {
  7552. return Optional.some(focusIn);
  7553. });
  7554. var schema$q = [
  7555. onKeyboardHandler("onSpace"),
  7556. onKeyboardHandler("onEnter"),
  7557. onKeyboardHandler("onShiftEnter"),
  7558. onKeyboardHandler("onLeft"),
  7559. onKeyboardHandler("onRight"),
  7560. onKeyboardHandler("onTab"),
  7561. onKeyboardHandler("onShiftTab"),
  7562. onKeyboardHandler("onUp"),
  7563. onKeyboardHandler("onDown"),
  7564. onKeyboardHandler("onEscape"),
  7565. defaulted("stopSpaceKeyup", false),
  7566. option("focusIn")
  7567. ];
  7568. var getKeydownRules = function(component, simulatedEvent, specialInfo) {
  7569. return [
  7570. rule(inSet(SPACE), specialInfo.onSpace),
  7571. rule(and([
  7572. isNotShift,
  7573. inSet(ENTER)
  7574. ]), specialInfo.onEnter),
  7575. rule(and([
  7576. isShift,
  7577. inSet(ENTER)
  7578. ]), specialInfo.onShiftEnter),
  7579. rule(and([
  7580. isShift,
  7581. inSet(TAB)
  7582. ]), specialInfo.onShiftTab),
  7583. rule(and([
  7584. isNotShift,
  7585. inSet(TAB)
  7586. ]), specialInfo.onTab),
  7587. rule(inSet(UP), specialInfo.onUp),
  7588. rule(inSet(DOWN), specialInfo.onDown),
  7589. rule(inSet(LEFT), specialInfo.onLeft),
  7590. rule(inSet(RIGHT), specialInfo.onRight),
  7591. rule(inSet(SPACE), specialInfo.onSpace),
  7592. rule(inSet(ESCAPE), specialInfo.onEscape)
  7593. ];
  7594. };
  7595. var getKeyupRules = function(component, simulatedEvent, specialInfo) {
  7596. return specialInfo.stopSpaceKeyup ? [rule(inSet(SPACE), stopEventForFirefox)] : [];
  7597. };
  7598. var SpecialType = typical(schema$q, NoState.init, getKeydownRules, getKeyupRules, function(specialInfo) {
  7599. return specialInfo.focusIn;
  7600. });
  7601. var acyclic = AcyclicType.schema();
  7602. var cyclic = CyclicType.schema();
  7603. var flow = FlowType.schema();
  7604. var flatgrid = FlatgridType.schema();
  7605. var matrix = MatrixType.schema();
  7606. var execution = ExecutionType.schema();
  7607. var menu = MenuType.schema();
  7608. var special = SpecialType.schema();
  7609. var KeyboardBranches = Object.freeze({
  7610. __proto__: null,
  7611. acyclic,
  7612. cyclic,
  7613. flow,
  7614. flatgrid,
  7615. matrix,
  7616. execution,
  7617. menu,
  7618. special
  7619. });
  7620. var isFlatgridState = function(keyState) {
  7621. return hasNonNullableKey(keyState, "setGridSize");
  7622. };
  7623. var Keying = createModes({
  7624. branchKey: "mode",
  7625. branches: KeyboardBranches,
  7626. name: "keying",
  7627. active: {
  7628. events: function(keyingConfig, keyingState) {
  7629. var handler = keyingConfig.handler;
  7630. return handler.toEvents(keyingConfig, keyingState);
  7631. }
  7632. },
  7633. apis: {
  7634. focusIn: function(component, keyConfig, keyState) {
  7635. keyConfig.sendFocusIn(keyConfig).fold(function() {
  7636. component.getSystem().triggerFocus(component.element, component.element);
  7637. }, function(sendFocusIn) {
  7638. sendFocusIn(component, keyConfig, keyState);
  7639. });
  7640. },
  7641. setGridSize: function(component, keyConfig, keyState, numRows, numColumns) {
  7642. if (!isFlatgridState(keyState)) {
  7643. console.error("Layout does not support setGridSize");
  7644. } else {
  7645. keyState.setGridSize(numRows, numColumns);
  7646. }
  7647. }
  7648. },
  7649. state: KeyingState
  7650. });
  7651. var set$2 = function(component, replaceConfig, replaceState, data) {
  7652. preserve$1(function() {
  7653. var newChildren = map$2(data, component.getSystem().build);
  7654. replaceChildren(component, newChildren);
  7655. }, component.element);
  7656. };
  7657. var insert = function(component, replaceConfig, insertion, childSpec) {
  7658. var child2 = component.getSystem().build(childSpec);
  7659. attachWith(component, child2, insertion);
  7660. };
  7661. var append = function(component, replaceConfig, replaceState, appendee) {
  7662. insert(component, replaceConfig, append$2, appendee);
  7663. };
  7664. var prepend = function(component, replaceConfig, replaceState, prependee) {
  7665. insert(component, replaceConfig, prepend$1, prependee);
  7666. };
  7667. var remove = function(component, replaceConfig, replaceState, removee) {
  7668. var children2 = contents(component);
  7669. var foundChild = find$5(children2, function(child2) {
  7670. return eq(removee.element, child2.element);
  7671. });
  7672. foundChild.each(detach);
  7673. };
  7674. var contents = function(component, _replaceConfig) {
  7675. return component.components();
  7676. };
  7677. var replaceAt = function(component, replaceConfig, replaceState, replaceeIndex, replacer) {
  7678. var children2 = contents(component);
  7679. return Optional.from(children2[replaceeIndex]).map(function(replacee) {
  7680. remove(component, replaceConfig, replaceState, replacee);
  7681. replacer.each(function(r2) {
  7682. insert(component, replaceConfig, function(p, c) {
  7683. appendAt(p, c, replaceeIndex);
  7684. }, r2);
  7685. });
  7686. return replacee;
  7687. });
  7688. };
  7689. var replaceBy = function(component, replaceConfig, replaceState, replaceePred, replacer) {
  7690. var children2 = contents(component);
  7691. return findIndex$1(children2, replaceePred).bind(function(replaceeIndex) {
  7692. return replaceAt(component, replaceConfig, replaceState, replaceeIndex, replacer);
  7693. });
  7694. };
  7695. var ReplaceApis = Object.freeze({
  7696. __proto__: null,
  7697. append,
  7698. prepend,
  7699. remove,
  7700. replaceAt,
  7701. replaceBy,
  7702. set: set$2,
  7703. contents
  7704. });
  7705. var Replacing = create$8({
  7706. fields: [],
  7707. name: "replacing",
  7708. apis: ReplaceApis
  7709. });
  7710. var events$d = function(name2, eventHandlers) {
  7711. var events2 = derive$2(eventHandlers);
  7712. return create$8({
  7713. fields: [required$1("enabled")],
  7714. name: name2,
  7715. active: { events: constant$1(events2) }
  7716. });
  7717. };
  7718. var config = function(name2, eventHandlers) {
  7719. var me = events$d(name2, eventHandlers);
  7720. return {
  7721. key: name2,
  7722. value: {
  7723. config: {},
  7724. me,
  7725. configAsRaw: constant$1({}),
  7726. initialConfig: {},
  7727. state: NoState
  7728. }
  7729. };
  7730. };
  7731. var focus$2 = function(component, focusConfig) {
  7732. if (!focusConfig.ignore) {
  7733. focus$3(component.element);
  7734. focusConfig.onFocus(component);
  7735. }
  7736. };
  7737. var blur = function(component, focusConfig) {
  7738. if (!focusConfig.ignore) {
  7739. blur$1(component.element);
  7740. }
  7741. };
  7742. var isFocused = function(component) {
  7743. return hasFocus(component.element);
  7744. };
  7745. var FocusApis = Object.freeze({
  7746. __proto__: null,
  7747. focus: focus$2,
  7748. blur,
  7749. isFocused
  7750. });
  7751. var exhibit$4 = function(base2, focusConfig) {
  7752. var mod = focusConfig.ignore ? {} : { attributes: { tabindex: "-1" } };
  7753. return nu$7(mod);
  7754. };
  7755. var events$c = function(focusConfig) {
  7756. return derive$2([run$1(focus$4(), function(component, simulatedEvent) {
  7757. focus$2(component, focusConfig);
  7758. simulatedEvent.stop();
  7759. })].concat(focusConfig.stopMousedown ? [run$1(mousedown(), function(_, simulatedEvent) {
  7760. simulatedEvent.event.prevent();
  7761. })] : []));
  7762. };
  7763. var ActiveFocus = Object.freeze({
  7764. __proto__: null,
  7765. exhibit: exhibit$4,
  7766. events: events$c
  7767. });
  7768. var FocusSchema = [
  7769. onHandler("onFocus"),
  7770. defaulted("stopMousedown", false),
  7771. defaulted("ignore", false)
  7772. ];
  7773. var Focusing = create$8({
  7774. fields: FocusSchema,
  7775. name: "focusing",
  7776. active: ActiveFocus,
  7777. apis: FocusApis
  7778. });
  7779. var SetupBehaviourCellState = function(initialState) {
  7780. var init2 = function() {
  7781. var cell = Cell(initialState);
  7782. var get2 = function() {
  7783. return cell.get();
  7784. };
  7785. var set2 = function(newState) {
  7786. return cell.set(newState);
  7787. };
  7788. var clear2 = function() {
  7789. return cell.set(initialState);
  7790. };
  7791. var readState = function() {
  7792. return cell.get();
  7793. };
  7794. return {
  7795. get: get2,
  7796. set: set2,
  7797. clear: clear2,
  7798. readState
  7799. };
  7800. };
  7801. return { init: init2 };
  7802. };
  7803. var updateAriaState = function(component, toggleConfig, toggleState) {
  7804. var ariaInfo = toggleConfig.aria;
  7805. ariaInfo.update(component, ariaInfo, toggleState.get());
  7806. };
  7807. var updateClass = function(component, toggleConfig, toggleState) {
  7808. toggleConfig.toggleClass.each(function(toggleClass) {
  7809. if (toggleState.get()) {
  7810. add$2(component.element, toggleClass);
  7811. } else {
  7812. remove$2(component.element, toggleClass);
  7813. }
  7814. });
  7815. };
  7816. var toggle$2 = function(component, toggleConfig, toggleState) {
  7817. set$1(component, toggleConfig, toggleState, !toggleState.get());
  7818. };
  7819. var on = function(component, toggleConfig, toggleState) {
  7820. toggleState.set(true);
  7821. updateClass(component, toggleConfig, toggleState);
  7822. updateAriaState(component, toggleConfig, toggleState);
  7823. };
  7824. var off = function(component, toggleConfig, toggleState) {
  7825. toggleState.set(false);
  7826. updateClass(component, toggleConfig, toggleState);
  7827. updateAriaState(component, toggleConfig, toggleState);
  7828. };
  7829. var set$1 = function(component, toggleConfig, toggleState, state) {
  7830. var action = state ? on : off;
  7831. action(component, toggleConfig, toggleState);
  7832. };
  7833. var isOn = function(component, toggleConfig, toggleState) {
  7834. return toggleState.get();
  7835. };
  7836. var onLoad = function(component, toggleConfig, toggleState) {
  7837. set$1(component, toggleConfig, toggleState, toggleConfig.selected);
  7838. };
  7839. var ToggleApis = Object.freeze({
  7840. __proto__: null,
  7841. onLoad,
  7842. toggle: toggle$2,
  7843. isOn,
  7844. on,
  7845. off,
  7846. set: set$1
  7847. });
  7848. var exhibit$3 = function() {
  7849. return nu$7({});
  7850. };
  7851. var events$b = function(toggleConfig, toggleState) {
  7852. var execute2 = executeEvent(toggleConfig, toggleState, toggle$2);
  7853. var load = loadEvent(toggleConfig, toggleState, onLoad);
  7854. return derive$2(flatten([
  7855. toggleConfig.toggleOnExecute ? [execute2] : [],
  7856. [load]
  7857. ]));
  7858. };
  7859. var ActiveToggle = Object.freeze({
  7860. __proto__: null,
  7861. exhibit: exhibit$3,
  7862. events: events$b
  7863. });
  7864. var updatePressed = function(component, ariaInfo, status) {
  7865. set$8(component.element, "aria-pressed", status);
  7866. if (ariaInfo.syncWithExpanded) {
  7867. updateExpanded(component, ariaInfo, status);
  7868. }
  7869. };
  7870. var updateSelected = function(component, ariaInfo, status) {
  7871. set$8(component.element, "aria-selected", status);
  7872. };
  7873. var updateChecked = function(component, ariaInfo, status) {
  7874. set$8(component.element, "aria-checked", status);
  7875. };
  7876. var updateExpanded = function(component, ariaInfo, status) {
  7877. set$8(component.element, "aria-expanded", status);
  7878. };
  7879. var ToggleSchema = [
  7880. defaulted("selected", false),
  7881. option("toggleClass"),
  7882. defaulted("toggleOnExecute", true),
  7883. defaultedOf("aria", { mode: "none" }, choose$1("mode", {
  7884. pressed: [
  7885. defaulted("syncWithExpanded", false),
  7886. output$1("update", updatePressed)
  7887. ],
  7888. checked: [output$1("update", updateChecked)],
  7889. expanded: [output$1("update", updateExpanded)],
  7890. selected: [output$1("update", updateSelected)],
  7891. none: [output$1("update", noop)]
  7892. }))
  7893. ];
  7894. var Toggling = create$8({
  7895. fields: ToggleSchema,
  7896. name: "toggling",
  7897. active: ActiveToggle,
  7898. apis: ToggleApis,
  7899. state: SetupBehaviourCellState(false)
  7900. });
  7901. var pointerEvents = function() {
  7902. var onClick = function(component, simulatedEvent) {
  7903. simulatedEvent.stop();
  7904. emitExecute(component);
  7905. };
  7906. return [
  7907. run$1(click(), onClick),
  7908. run$1(tap(), onClick),
  7909. cutter(touchstart()),
  7910. cutter(mousedown())
  7911. ];
  7912. };
  7913. var events$a = function(optAction) {
  7914. var executeHandler = function(action) {
  7915. return runOnExecute$1(function(component, simulatedEvent) {
  7916. action(component);
  7917. simulatedEvent.stop();
  7918. });
  7919. };
  7920. return derive$2(flatten([
  7921. optAction.map(executeHandler).toArray(),
  7922. pointerEvents()
  7923. ]));
  7924. };
  7925. var hoverEvent = "alloy.item-hover";
  7926. var focusEvent = "alloy.item-focus";
  7927. var onHover = function(item2) {
  7928. if (search(item2.element).isNone() || Focusing.isFocused(item2)) {
  7929. if (!Focusing.isFocused(item2)) {
  7930. Focusing.focus(item2);
  7931. }
  7932. emitWith(item2, hoverEvent, { item: item2 });
  7933. }
  7934. };
  7935. var onFocus$1 = function(item2) {
  7936. emitWith(item2, focusEvent, { item: item2 });
  7937. };
  7938. var hover = constant$1(hoverEvent);
  7939. var focus$1 = constant$1(focusEvent);
  7940. var builder$2 = function(detail) {
  7941. return {
  7942. dom: detail.dom,
  7943. 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 } : {}) }),
  7944. behaviours: SketchBehaviours.augment(detail.itemBehaviours, [
  7945. detail.toggling.fold(Toggling.revoke, function(tConfig) {
  7946. return Toggling.config(__assign({ aria: { mode: "checked" } }, tConfig));
  7947. }),
  7948. Focusing.config({
  7949. ignore: detail.ignoreFocus,
  7950. stopMousedown: detail.ignoreFocus,
  7951. onFocus: function(component) {
  7952. onFocus$1(component);
  7953. }
  7954. }),
  7955. Keying.config({ mode: "execution" }),
  7956. Representing.config({
  7957. store: {
  7958. mode: "memory",
  7959. initialValue: detail.data
  7960. }
  7961. }),
  7962. config("item-type-events", __spreadArray(__spreadArray([], pointerEvents(), true), [
  7963. run$1(mouseover(), onHover),
  7964. run$1(focusItem(), Focusing.focus)
  7965. ], false))
  7966. ]),
  7967. components: detail.components,
  7968. eventOrder: detail.eventOrder
  7969. };
  7970. };
  7971. var schema$p = [
  7972. required$1("data"),
  7973. required$1("components"),
  7974. required$1("dom"),
  7975. defaulted("hasSubmenu", false),
  7976. option("toggling"),
  7977. SketchBehaviours.field("itemBehaviours", [
  7978. Toggling,
  7979. Focusing,
  7980. Keying,
  7981. Representing
  7982. ]),
  7983. defaulted("ignoreFocus", false),
  7984. defaulted("domModification", {}),
  7985. output$1("builder", builder$2),
  7986. defaulted("eventOrder", {})
  7987. ];
  7988. var builder$1 = function(detail) {
  7989. return {
  7990. dom: detail.dom,
  7991. components: detail.components,
  7992. events: derive$2([stopper(focusItem())])
  7993. };
  7994. };
  7995. var schema$o = [
  7996. required$1("dom"),
  7997. required$1("components"),
  7998. output$1("builder", builder$1)
  7999. ];
  8000. var owner$2 = constant$1("item-widget");
  8001. var parts$h = constant$1([required({
  8002. name: "widget",
  8003. overrides: function(detail) {
  8004. return {
  8005. behaviours: derive$1([Representing.config({
  8006. store: {
  8007. mode: "manual",
  8008. getValue: function(_component) {
  8009. return detail.data;
  8010. },
  8011. setValue: noop
  8012. }
  8013. })])
  8014. };
  8015. }
  8016. })]);
  8017. var builder = function(detail) {
  8018. var subs2 = substitutes(owner$2(), detail, parts$h());
  8019. var components2 = components$1(owner$2(), detail, subs2.internals());
  8020. var focusWidget = function(component) {
  8021. return getPart(component, detail, "widget").map(function(widget) {
  8022. Keying.focusIn(widget);
  8023. return widget;
  8024. });
  8025. };
  8026. var onHorizontalArrow = function(component, simulatedEvent) {
  8027. return inside(simulatedEvent.event.target) ? Optional.none() : function() {
  8028. if (detail.autofocus) {
  8029. simulatedEvent.setSource(component.element);
  8030. return Optional.none();
  8031. } else {
  8032. return Optional.none();
  8033. }
  8034. }();
  8035. };
  8036. return {
  8037. dom: detail.dom,
  8038. components: components2,
  8039. domModification: detail.domModification,
  8040. events: derive$2([
  8041. runOnExecute$1(function(component, simulatedEvent) {
  8042. focusWidget(component).each(function(_widget) {
  8043. simulatedEvent.stop();
  8044. });
  8045. }),
  8046. run$1(mouseover(), onHover),
  8047. run$1(focusItem(), function(component, _simulatedEvent) {
  8048. if (detail.autofocus) {
  8049. focusWidget(component);
  8050. } else {
  8051. Focusing.focus(component);
  8052. }
  8053. })
  8054. ]),
  8055. behaviours: SketchBehaviours.augment(detail.widgetBehaviours, [
  8056. Representing.config({
  8057. store: {
  8058. mode: "memory",
  8059. initialValue: detail.data
  8060. }
  8061. }),
  8062. Focusing.config({
  8063. ignore: detail.ignoreFocus,
  8064. onFocus: function(component) {
  8065. onFocus$1(component);
  8066. }
  8067. }),
  8068. Keying.config({
  8069. mode: "special",
  8070. focusIn: detail.autofocus ? function(component) {
  8071. focusWidget(component);
  8072. } : revoke(),
  8073. onLeft: onHorizontalArrow,
  8074. onRight: onHorizontalArrow,
  8075. onEscape: function(component, simulatedEvent) {
  8076. if (!Focusing.isFocused(component) && !detail.autofocus) {
  8077. Focusing.focus(component);
  8078. return Optional.some(true);
  8079. } else if (detail.autofocus) {
  8080. simulatedEvent.setSource(component.element);
  8081. return Optional.none();
  8082. } else {
  8083. return Optional.none();
  8084. }
  8085. }
  8086. })
  8087. ])
  8088. };
  8089. };
  8090. var schema$n = [
  8091. required$1("uid"),
  8092. required$1("data"),
  8093. required$1("components"),
  8094. required$1("dom"),
  8095. defaulted("autofocus", false),
  8096. defaulted("ignoreFocus", false),
  8097. SketchBehaviours.field("widgetBehaviours", [
  8098. Representing,
  8099. Focusing,
  8100. Keying
  8101. ]),
  8102. defaulted("domModification", {}),
  8103. defaultUidsSchema(parts$h()),
  8104. output$1("builder", builder)
  8105. ];
  8106. var itemSchema$2 = choose$1("type", {
  8107. widget: schema$n,
  8108. item: schema$p,
  8109. separator: schema$o
  8110. });
  8111. var configureGrid = function(detail, movementInfo) {
  8112. return {
  8113. mode: "flatgrid",
  8114. selector: "." + detail.markers.item,
  8115. initSize: {
  8116. numColumns: movementInfo.initSize.numColumns,
  8117. numRows: movementInfo.initSize.numRows
  8118. },
  8119. focusManager: detail.focusManager
  8120. };
  8121. };
  8122. var configureMatrix = function(detail, movementInfo) {
  8123. return {
  8124. mode: "matrix",
  8125. selectors: {
  8126. row: movementInfo.rowSelector,
  8127. cell: "." + detail.markers.item
  8128. },
  8129. focusManager: detail.focusManager
  8130. };
  8131. };
  8132. var configureMenu = function(detail, movementInfo) {
  8133. return {
  8134. mode: "menu",
  8135. selector: "." + detail.markers.item,
  8136. moveOnTab: movementInfo.moveOnTab,
  8137. focusManager: detail.focusManager
  8138. };
  8139. };
  8140. var parts$g = constant$1([group({
  8141. factory: {
  8142. sketch: function(spec) {
  8143. var itemInfo = asRawOrDie$1("menu.spec item", itemSchema$2, spec);
  8144. return itemInfo.builder(itemInfo);
  8145. }
  8146. },
  8147. name: "items",
  8148. unit: "item",
  8149. defaults: function(detail, u) {
  8150. return has$2(u, "uid") ? u : __assign(__assign({}, u), { uid: generate$5("item") });
  8151. },
  8152. overrides: function(detail, u) {
  8153. return {
  8154. type: u.type,
  8155. ignoreFocus: detail.fakeFocus,
  8156. domModification: { classes: [detail.markers.item] }
  8157. };
  8158. }
  8159. })]);
  8160. var schema$m = constant$1([
  8161. required$1("value"),
  8162. required$1("items"),
  8163. required$1("dom"),
  8164. required$1("components"),
  8165. defaulted("eventOrder", {}),
  8166. field("menuBehaviours", [
  8167. Highlighting,
  8168. Representing,
  8169. Composing,
  8170. Keying
  8171. ]),
  8172. defaultedOf("movement", {
  8173. mode: "menu",
  8174. moveOnTab: true
  8175. }, choose$1("mode", {
  8176. grid: [
  8177. initSize(),
  8178. output$1("config", configureGrid)
  8179. ],
  8180. matrix: [
  8181. output$1("config", configureMatrix),
  8182. required$1("rowSelector")
  8183. ],
  8184. menu: [
  8185. defaulted("moveOnTab", true),
  8186. output$1("config", configureMenu)
  8187. ]
  8188. })),
  8189. itemMarkers(),
  8190. defaulted("fakeFocus", false),
  8191. defaulted("focusManager", dom$2()),
  8192. onHandler("onHighlight")
  8193. ]);
  8194. var focus = constant$1("alloy.menu-focus");
  8195. var make$7 = function(detail, components2, _spec, _externals) {
  8196. return {
  8197. uid: detail.uid,
  8198. dom: detail.dom,
  8199. markers: detail.markers,
  8200. behaviours: augment(detail.menuBehaviours, [
  8201. Highlighting.config({
  8202. highlightClass: detail.markers.selectedItem,
  8203. itemClass: detail.markers.item,
  8204. onHighlight: detail.onHighlight
  8205. }),
  8206. Representing.config({
  8207. store: {
  8208. mode: "memory",
  8209. initialValue: detail.value
  8210. }
  8211. }),
  8212. Composing.config({ find: Optional.some }),
  8213. Keying.config(detail.movement.config(detail, detail.movement))
  8214. ]),
  8215. events: derive$2([
  8216. run$1(focus$1(), function(menu2, simulatedEvent) {
  8217. var event = simulatedEvent.event;
  8218. menu2.getSystem().getByDom(event.target).each(function(item2) {
  8219. Highlighting.highlight(menu2, item2);
  8220. simulatedEvent.stop();
  8221. emitWith(menu2, focus(), {
  8222. menu: menu2,
  8223. item: item2
  8224. });
  8225. });
  8226. }),
  8227. run$1(hover(), function(menu2, simulatedEvent) {
  8228. var item2 = simulatedEvent.event.item;
  8229. Highlighting.highlight(menu2, item2);
  8230. })
  8231. ]),
  8232. components: components2,
  8233. eventOrder: detail.eventOrder,
  8234. domModification: { attributes: { role: "menu" } }
  8235. };
  8236. };
  8237. var Menu = composite({
  8238. name: "Menu",
  8239. configFields: schema$m(),
  8240. partFields: parts$g(),
  8241. factory: make$7
  8242. });
  8243. var transpose$1 = function(obj) {
  8244. return tupleMap(obj, function(v, k) {
  8245. return {
  8246. k: v,
  8247. v: k
  8248. };
  8249. });
  8250. };
  8251. var trace = function(items, byItem, byMenu, finish) {
  8252. return get$e(byMenu, finish).bind(function(triggerItem) {
  8253. return get$e(items, triggerItem).bind(function(triggerMenu) {
  8254. var rest = trace(items, byItem, byMenu, triggerMenu);
  8255. return Optional.some([triggerMenu].concat(rest));
  8256. });
  8257. }).getOr([]);
  8258. };
  8259. var generate$2 = function(menus, expansions) {
  8260. var items = {};
  8261. each(menus, function(menuItems, menu2) {
  8262. each$1(menuItems, function(item2) {
  8263. items[item2] = menu2;
  8264. });
  8265. });
  8266. var byItem = expansions;
  8267. var byMenu = transpose$1(expansions);
  8268. var menuPaths = map$1(byMenu, function(_triggerItem, submenu) {
  8269. return [submenu].concat(trace(items, byItem, byMenu, submenu));
  8270. });
  8271. return map$1(items, function(menu2) {
  8272. return get$e(menuPaths, menu2).getOr([menu2]);
  8273. });
  8274. };
  8275. var init$c = function() {
  8276. var expansions = Cell({});
  8277. var menus = Cell({});
  8278. var paths = Cell({});
  8279. var primary = value$1();
  8280. var directory = Cell({});
  8281. var clear2 = function() {
  8282. expansions.set({});
  8283. menus.set({});
  8284. paths.set({});
  8285. primary.clear();
  8286. };
  8287. var isClear = function() {
  8288. return primary.get().isNone();
  8289. };
  8290. var setMenuBuilt = function(menuName, built) {
  8291. var _a2;
  8292. menus.set(__assign(__assign({}, menus.get()), (_a2 = {}, _a2[menuName] = {
  8293. type: "prepared",
  8294. menu: built
  8295. }, _a2)));
  8296. };
  8297. var setContents = function(sPrimary, sMenus, sExpansions, dir) {
  8298. primary.set(sPrimary);
  8299. expansions.set(sExpansions);
  8300. menus.set(sMenus);
  8301. directory.set(dir);
  8302. var sPaths = generate$2(dir, sExpansions);
  8303. paths.set(sPaths);
  8304. };
  8305. var getTriggeringItem = function(menuValue) {
  8306. return find$4(expansions.get(), function(v, _k) {
  8307. return v === menuValue;
  8308. });
  8309. };
  8310. var getTriggerData = function(menuValue, getItemByValue, path2) {
  8311. return getPreparedMenu(menuValue).bind(function(menu2) {
  8312. return getTriggeringItem(menuValue).bind(function(triggeringItemValue) {
  8313. return getItemByValue(triggeringItemValue).map(function(triggeredItem) {
  8314. return {
  8315. triggeredMenu: menu2,
  8316. triggeringItem: triggeredItem,
  8317. triggeringPath: path2
  8318. };
  8319. });
  8320. });
  8321. });
  8322. };
  8323. var getTriggeringPath = function(itemValue, getItemByValue) {
  8324. var extraPath = filter$2(lookupItem(itemValue).toArray(), function(menuValue) {
  8325. return getPreparedMenu(menuValue).isSome();
  8326. });
  8327. return get$e(paths.get(), itemValue).bind(function(path2) {
  8328. var revPath = reverse(extraPath.concat(path2));
  8329. var triggers = bind$3(revPath, function(menuValue, menuIndex) {
  8330. return getTriggerData(menuValue, getItemByValue, revPath.slice(0, menuIndex + 1)).fold(function() {
  8331. return is$1(primary.get(), menuValue) ? [] : [Optional.none()];
  8332. }, function(data) {
  8333. return [Optional.some(data)];
  8334. });
  8335. });
  8336. return sequence(triggers);
  8337. });
  8338. };
  8339. var expand2 = function(itemValue) {
  8340. return get$e(expansions.get(), itemValue).map(function(menu2) {
  8341. var current = get$e(paths.get(), itemValue).getOr([]);
  8342. return [menu2].concat(current);
  8343. });
  8344. };
  8345. var collapse = function(itemValue) {
  8346. return get$e(paths.get(), itemValue).bind(function(path2) {
  8347. return path2.length > 1 ? Optional.some(path2.slice(1)) : Optional.none();
  8348. });
  8349. };
  8350. var refresh2 = function(itemValue) {
  8351. return get$e(paths.get(), itemValue);
  8352. };
  8353. var getPreparedMenu = function(menuValue) {
  8354. return lookupMenu(menuValue).bind(extractPreparedMenu);
  8355. };
  8356. var lookupMenu = function(menuValue) {
  8357. return get$e(menus.get(), menuValue);
  8358. };
  8359. var lookupItem = function(itemValue) {
  8360. return get$e(expansions.get(), itemValue);
  8361. };
  8362. var otherMenus = function(path2) {
  8363. var menuValues = directory.get();
  8364. return difference(keys(menuValues), path2);
  8365. };
  8366. var getPrimary = function() {
  8367. return primary.get().bind(getPreparedMenu);
  8368. };
  8369. var getMenus2 = function() {
  8370. return menus.get();
  8371. };
  8372. return {
  8373. setMenuBuilt,
  8374. setContents,
  8375. expand: expand2,
  8376. refresh: refresh2,
  8377. collapse,
  8378. lookupMenu,
  8379. lookupItem,
  8380. otherMenus,
  8381. getPrimary,
  8382. getMenus: getMenus2,
  8383. clear: clear2,
  8384. isClear,
  8385. getTriggeringPath
  8386. };
  8387. };
  8388. var extractPreparedMenu = function(prep) {
  8389. return prep.type === "prepared" ? Optional.some(prep.menu) : Optional.none();
  8390. };
  8391. var LayeredState = {
  8392. init: init$c,
  8393. extractPreparedMenu
  8394. };
  8395. var make$6 = function(detail, _rawUiSpec) {
  8396. var submenuParentItems = value$1();
  8397. var buildMenus = function(container, primaryName, menus) {
  8398. return map$1(menus, function(spec, name2) {
  8399. var makeSketch = function() {
  8400. return Menu.sketch(__assign(__assign({}, spec), {
  8401. value: name2,
  8402. markers: detail.markers,
  8403. fakeFocus: detail.fakeFocus,
  8404. onHighlight: detail.onHighlight,
  8405. focusManager: detail.fakeFocus ? highlights() : dom$2()
  8406. }));
  8407. };
  8408. return name2 === primaryName ? {
  8409. type: "prepared",
  8410. menu: container.getSystem().build(makeSketch())
  8411. } : {
  8412. type: "notbuilt",
  8413. nbMenu: makeSketch
  8414. };
  8415. });
  8416. };
  8417. var layeredState = LayeredState.init();
  8418. var setup2 = function(container) {
  8419. var componentMap = buildMenus(container, detail.data.primary, detail.data.menus);
  8420. var directory = toDirectory();
  8421. layeredState.setContents(detail.data.primary, componentMap, detail.data.expansions, directory);
  8422. return layeredState.getPrimary();
  8423. };
  8424. var getItemValue = function(item2) {
  8425. return Representing.getValue(item2).value;
  8426. };
  8427. var getItemByValue = function(_container, menus, itemValue) {
  8428. return findMap(menus, function(menu2) {
  8429. if (!menu2.getSystem().isConnected()) {
  8430. return Optional.none();
  8431. }
  8432. var candidates = Highlighting.getCandidates(menu2);
  8433. return find$5(candidates, function(c) {
  8434. return getItemValue(c) === itemValue;
  8435. });
  8436. });
  8437. };
  8438. var toDirectory = function(_container) {
  8439. return map$1(detail.data.menus, function(data, _menuName) {
  8440. return bind$3(data.items, function(item2) {
  8441. return item2.type === "separator" ? [] : [item2.data.value];
  8442. });
  8443. });
  8444. };
  8445. var setActiveMenu = function(container, menu2) {
  8446. Highlighting.highlight(container, menu2);
  8447. Highlighting.getHighlighted(menu2).orThunk(function() {
  8448. return Highlighting.getFirst(menu2);
  8449. }).each(function(item2) {
  8450. dispatch(container, item2.element, focusItem());
  8451. });
  8452. };
  8453. var getMenus2 = function(state, menuValues) {
  8454. return cat(map$2(menuValues, function(mv) {
  8455. return state.lookupMenu(mv).bind(function(prep) {
  8456. return prep.type === "prepared" ? Optional.some(prep.menu) : Optional.none();
  8457. });
  8458. }));
  8459. };
  8460. var closeOthers = function(container, state, path2) {
  8461. var others = getMenus2(state, state.otherMenus(path2));
  8462. each$1(others, function(o) {
  8463. remove$1(o.element, [detail.markers.backgroundMenu]);
  8464. if (!detail.stayInDom) {
  8465. Replacing.remove(container, o);
  8466. }
  8467. });
  8468. };
  8469. var getSubmenuParents = function(container) {
  8470. return submenuParentItems.get().getOrThunk(function() {
  8471. var r2 = {};
  8472. var items = descendants(container.element, "." + detail.markers.item);
  8473. var parentItems = filter$2(items, function(i) {
  8474. return get$d(i, "aria-haspopup") === "true";
  8475. });
  8476. each$1(parentItems, function(i) {
  8477. container.getSystem().getByDom(i).each(function(itemComp) {
  8478. var key = getItemValue(itemComp);
  8479. r2[key] = itemComp;
  8480. });
  8481. });
  8482. submenuParentItems.set(r2);
  8483. return r2;
  8484. });
  8485. };
  8486. var updateAriaExpansions = function(container, path2) {
  8487. var parentItems = getSubmenuParents(container);
  8488. each(parentItems, function(v, k) {
  8489. var expanded = contains$2(path2, k);
  8490. set$8(v.element, "aria-expanded", expanded);
  8491. });
  8492. };
  8493. var updateMenuPath = function(container, state, path2) {
  8494. return Optional.from(path2[0]).bind(function(latestMenuName) {
  8495. return state.lookupMenu(latestMenuName).bind(function(menuPrep) {
  8496. if (menuPrep.type === "notbuilt") {
  8497. return Optional.none();
  8498. } else {
  8499. var activeMenu = menuPrep.menu;
  8500. var rest = getMenus2(state, path2.slice(1));
  8501. each$1(rest, function(r2) {
  8502. add$2(r2.element, detail.markers.backgroundMenu);
  8503. });
  8504. if (!inBody(activeMenu.element)) {
  8505. Replacing.append(container, premade(activeMenu));
  8506. }
  8507. remove$1(activeMenu.element, [detail.markers.backgroundMenu]);
  8508. setActiveMenu(container, activeMenu);
  8509. closeOthers(container, state, path2);
  8510. return Optional.some(activeMenu);
  8511. }
  8512. });
  8513. });
  8514. };
  8515. var ExpandHighlightDecision;
  8516. (function(ExpandHighlightDecision2) {
  8517. ExpandHighlightDecision2[ExpandHighlightDecision2["HighlightSubmenu"] = 0] = "HighlightSubmenu";
  8518. ExpandHighlightDecision2[ExpandHighlightDecision2["HighlightParent"] = 1] = "HighlightParent";
  8519. })(ExpandHighlightDecision || (ExpandHighlightDecision = {}));
  8520. var buildIfRequired = function(container, menuName, menuPrep) {
  8521. if (menuPrep.type === "notbuilt") {
  8522. var menu2 = container.getSystem().build(menuPrep.nbMenu());
  8523. layeredState.setMenuBuilt(menuName, menu2);
  8524. return menu2;
  8525. } else {
  8526. return menuPrep.menu;
  8527. }
  8528. };
  8529. var expandRight = function(container, item2, decision) {
  8530. if (decision === void 0) {
  8531. decision = ExpandHighlightDecision.HighlightSubmenu;
  8532. }
  8533. if (item2.hasConfigured(Disabling) && Disabling.isDisabled(item2)) {
  8534. return Optional.some(item2);
  8535. } else {
  8536. var value2 = getItemValue(item2);
  8537. return layeredState.expand(value2).bind(function(path2) {
  8538. updateAriaExpansions(container, path2);
  8539. return Optional.from(path2[0]).bind(function(menuName) {
  8540. return layeredState.lookupMenu(menuName).bind(function(activeMenuPrep) {
  8541. var activeMenu = buildIfRequired(container, menuName, activeMenuPrep);
  8542. if (!inBody(activeMenu.element)) {
  8543. Replacing.append(container, premade(activeMenu));
  8544. }
  8545. detail.onOpenSubmenu(container, item2, activeMenu, reverse(path2));
  8546. if (decision === ExpandHighlightDecision.HighlightSubmenu) {
  8547. Highlighting.highlightFirst(activeMenu);
  8548. return updateMenuPath(container, layeredState, path2);
  8549. } else {
  8550. Highlighting.dehighlightAll(activeMenu);
  8551. return Optional.some(item2);
  8552. }
  8553. });
  8554. });
  8555. });
  8556. }
  8557. };
  8558. var collapseLeft = function(container, item2) {
  8559. var value2 = getItemValue(item2);
  8560. return layeredState.collapse(value2).bind(function(path2) {
  8561. updateAriaExpansions(container, path2);
  8562. return updateMenuPath(container, layeredState, path2).map(function(activeMenu) {
  8563. detail.onCollapseMenu(container, item2, activeMenu);
  8564. return activeMenu;
  8565. });
  8566. });
  8567. };
  8568. var updateView = function(container, item2) {
  8569. var value2 = getItemValue(item2);
  8570. return layeredState.refresh(value2).bind(function(path2) {
  8571. updateAriaExpansions(container, path2);
  8572. return updateMenuPath(container, layeredState, path2);
  8573. });
  8574. };
  8575. var onRight2 = function(container, item2) {
  8576. return inside(item2.element) ? Optional.none() : expandRight(container, item2, ExpandHighlightDecision.HighlightSubmenu);
  8577. };
  8578. var onLeft2 = function(container, item2) {
  8579. return inside(item2.element) ? Optional.none() : collapseLeft(container, item2);
  8580. };
  8581. var onEscape = function(container, item2) {
  8582. return collapseLeft(container, item2).orThunk(function() {
  8583. return detail.onEscape(container, item2).map(function() {
  8584. return container;
  8585. });
  8586. });
  8587. };
  8588. var keyOnItem = function(f) {
  8589. return function(container, simulatedEvent) {
  8590. return closest$1(simulatedEvent.getSource(), "." + detail.markers.item).bind(function(target) {
  8591. return container.getSystem().getByDom(target).toOptional().bind(function(item2) {
  8592. return f(container, item2).map(always);
  8593. });
  8594. });
  8595. };
  8596. };
  8597. var events2 = derive$2([
  8598. run$1(focus(), function(sandbox, simulatedEvent) {
  8599. var item2 = simulatedEvent.event.item;
  8600. layeredState.lookupItem(getItemValue(item2)).each(function() {
  8601. var menu2 = simulatedEvent.event.menu;
  8602. Highlighting.highlight(sandbox, menu2);
  8603. var value2 = getItemValue(simulatedEvent.event.item);
  8604. layeredState.refresh(value2).each(function(path2) {
  8605. return closeOthers(sandbox, layeredState, path2);
  8606. });
  8607. });
  8608. }),
  8609. runOnExecute$1(function(component, simulatedEvent) {
  8610. var target = simulatedEvent.event.target;
  8611. component.getSystem().getByDom(target).each(function(item2) {
  8612. var itemValue = getItemValue(item2);
  8613. if (itemValue.indexOf("collapse-item") === 0) {
  8614. collapseLeft(component, item2);
  8615. }
  8616. expandRight(component, item2, ExpandHighlightDecision.HighlightSubmenu).fold(function() {
  8617. detail.onExecute(component, item2);
  8618. }, noop);
  8619. });
  8620. }),
  8621. runOnAttached(function(container, _simulatedEvent) {
  8622. setup2(container).each(function(primary) {
  8623. Replacing.append(container, premade(primary));
  8624. detail.onOpenMenu(container, primary);
  8625. if (detail.highlightImmediately) {
  8626. setActiveMenu(container, primary);
  8627. }
  8628. });
  8629. })
  8630. ].concat(detail.navigateOnHover ? [run$1(hover(), function(sandbox, simulatedEvent) {
  8631. var item2 = simulatedEvent.event.item;
  8632. updateView(sandbox, item2);
  8633. expandRight(sandbox, item2, ExpandHighlightDecision.HighlightParent);
  8634. detail.onHover(sandbox, item2);
  8635. })] : []));
  8636. var getActiveItem = function(container) {
  8637. return Highlighting.getHighlighted(container).bind(Highlighting.getHighlighted);
  8638. };
  8639. var collapseMenuApi = function(container) {
  8640. getActiveItem(container).each(function(currentItem) {
  8641. collapseLeft(container, currentItem);
  8642. });
  8643. };
  8644. var highlightPrimary = function(container) {
  8645. layeredState.getPrimary().each(function(primary) {
  8646. setActiveMenu(container, primary);
  8647. });
  8648. };
  8649. var extractMenuFromContainer = function(container) {
  8650. return Optional.from(container.components()[0]).filter(function(comp) {
  8651. return get$d(comp.element, "role") === "menu";
  8652. });
  8653. };
  8654. var repositionMenus2 = function(container) {
  8655. var maybeActivePrimary = layeredState.getPrimary().bind(function(primary) {
  8656. return getActiveItem(container).bind(function(currentItem) {
  8657. var itemValue = getItemValue(currentItem);
  8658. var allMenus = values(layeredState.getMenus());
  8659. var preparedMenus = cat(map$2(allMenus, LayeredState.extractPreparedMenu));
  8660. return layeredState.getTriggeringPath(itemValue, function(v) {
  8661. return getItemByValue(container, preparedMenus, v);
  8662. });
  8663. }).map(function(triggeringPath) {
  8664. return {
  8665. primary,
  8666. triggeringPath
  8667. };
  8668. });
  8669. });
  8670. maybeActivePrimary.fold(function() {
  8671. extractMenuFromContainer(container).each(function(primaryMenu) {
  8672. detail.onRepositionMenu(container, primaryMenu, []);
  8673. });
  8674. }, function(_a2) {
  8675. var primary = _a2.primary, triggeringPath = _a2.triggeringPath;
  8676. detail.onRepositionMenu(container, primary, triggeringPath);
  8677. });
  8678. };
  8679. var apis = {
  8680. collapseMenu: collapseMenuApi,
  8681. highlightPrimary,
  8682. repositionMenus: repositionMenus2
  8683. };
  8684. return {
  8685. uid: detail.uid,
  8686. dom: detail.dom,
  8687. markers: detail.markers,
  8688. behaviours: augment(detail.tmenuBehaviours, [
  8689. Keying.config({
  8690. mode: "special",
  8691. onRight: keyOnItem(onRight2),
  8692. onLeft: keyOnItem(onLeft2),
  8693. onEscape: keyOnItem(onEscape),
  8694. focusIn: function(container, _keyInfo) {
  8695. layeredState.getPrimary().each(function(primary) {
  8696. dispatch(container, primary.element, focusItem());
  8697. });
  8698. }
  8699. }),
  8700. Highlighting.config({
  8701. highlightClass: detail.markers.selectedMenu,
  8702. itemClass: detail.markers.menu
  8703. }),
  8704. Composing.config({
  8705. find: function(container) {
  8706. return Highlighting.getHighlighted(container);
  8707. }
  8708. }),
  8709. Replacing.config({})
  8710. ]),
  8711. eventOrder: detail.eventOrder,
  8712. apis,
  8713. events: events2
  8714. };
  8715. };
  8716. var collapseItem$1 = constant$1("collapse-item");
  8717. var tieredData = function(primary, menus, expansions) {
  8718. return {
  8719. primary,
  8720. menus,
  8721. expansions
  8722. };
  8723. };
  8724. var singleData = function(name2, menu2) {
  8725. return {
  8726. primary: name2,
  8727. menus: wrap$1(name2, menu2),
  8728. expansions: {}
  8729. };
  8730. };
  8731. var collapseItem = function(text2) {
  8732. return {
  8733. value: generate$6(collapseItem$1()),
  8734. meta: { text: text2 }
  8735. };
  8736. };
  8737. var tieredMenu = single({
  8738. name: "TieredMenu",
  8739. configFields: [
  8740. onStrictKeyboardHandler("onExecute"),
  8741. onStrictKeyboardHandler("onEscape"),
  8742. onStrictHandler("onOpenMenu"),
  8743. onStrictHandler("onOpenSubmenu"),
  8744. onHandler("onRepositionMenu"),
  8745. onHandler("onCollapseMenu"),
  8746. defaulted("highlightImmediately", true),
  8747. requiredObjOf("data", [
  8748. required$1("primary"),
  8749. required$1("menus"),
  8750. required$1("expansions")
  8751. ]),
  8752. defaulted("fakeFocus", false),
  8753. onHandler("onHighlight"),
  8754. onHandler("onHover"),
  8755. tieredMenuMarkers(),
  8756. required$1("dom"),
  8757. defaulted("navigateOnHover", true),
  8758. defaulted("stayInDom", false),
  8759. field("tmenuBehaviours", [
  8760. Keying,
  8761. Highlighting,
  8762. Composing,
  8763. Replacing
  8764. ]),
  8765. defaulted("eventOrder", {})
  8766. ],
  8767. apis: {
  8768. collapseMenu: function(apis, tmenu) {
  8769. apis.collapseMenu(tmenu);
  8770. },
  8771. highlightPrimary: function(apis, tmenu) {
  8772. apis.highlightPrimary(tmenu);
  8773. },
  8774. repositionMenus: function(apis, tmenu) {
  8775. apis.repositionMenus(tmenu);
  8776. }
  8777. },
  8778. factory: make$6,
  8779. extraApis: {
  8780. tieredData,
  8781. singleData,
  8782. collapseItem
  8783. }
  8784. });
  8785. var makeMenu = function(detail, menuSandbox, placementSpec, menuSpec, getBounds2) {
  8786. var lazySink = function() {
  8787. return detail.lazySink(menuSandbox);
  8788. };
  8789. var layouts2 = menuSpec.type === "horizontal" ? {
  8790. layouts: {
  8791. onLtr: function() {
  8792. return belowOrAbove();
  8793. },
  8794. onRtl: function() {
  8795. return belowOrAboveRtl();
  8796. }
  8797. }
  8798. } : {};
  8799. var isFirstTierSubmenu = function(triggeringPaths) {
  8800. return triggeringPaths.length === 2;
  8801. };
  8802. var getSubmenuLayouts = function(triggeringPaths) {
  8803. return isFirstTierSubmenu(triggeringPaths) ? layouts2 : {};
  8804. };
  8805. return tieredMenu.sketch({
  8806. dom: { tag: "div" },
  8807. data: menuSpec.data,
  8808. markers: menuSpec.menu.markers,
  8809. highlightImmediately: menuSpec.menu.highlightImmediately,
  8810. onEscape: function() {
  8811. Sandboxing.close(menuSandbox);
  8812. detail.onEscape.map(function(handler) {
  8813. return handler(menuSandbox);
  8814. });
  8815. return Optional.some(true);
  8816. },
  8817. onExecute: function() {
  8818. return Optional.some(true);
  8819. },
  8820. onOpenMenu: function(tmenu, menu2) {
  8821. Positioning.positionWithinBounds(lazySink().getOrDie(), menu2, placementSpec, getBounds2());
  8822. },
  8823. onOpenSubmenu: function(tmenu, item2, submenu, triggeringPaths) {
  8824. var sink = lazySink().getOrDie();
  8825. Positioning.position(sink, submenu, {
  8826. anchor: __assign({
  8827. type: "submenu",
  8828. item: item2
  8829. }, getSubmenuLayouts(triggeringPaths))
  8830. });
  8831. },
  8832. onRepositionMenu: function(tmenu, primaryMenu, submenuTriggers) {
  8833. var sink = lazySink().getOrDie();
  8834. Positioning.positionWithinBounds(sink, primaryMenu, placementSpec, getBounds2());
  8835. each$1(submenuTriggers, function(st) {
  8836. var submenuLayouts = getSubmenuLayouts(st.triggeringPath);
  8837. Positioning.position(sink, st.triggeredMenu, {
  8838. anchor: __assign({
  8839. type: "submenu",
  8840. item: st.triggeringItem
  8841. }, submenuLayouts)
  8842. });
  8843. });
  8844. }
  8845. });
  8846. };
  8847. var factory$m = function(detail, spec) {
  8848. var isPartOfRelated = function(sandbox, queryElem) {
  8849. var related = detail.getRelated(sandbox);
  8850. return related.exists(function(rel) {
  8851. return isPartOf$1(rel, queryElem);
  8852. });
  8853. };
  8854. var setContent2 = function(sandbox, thing) {
  8855. Sandboxing.setContent(sandbox, thing);
  8856. };
  8857. var showAt = function(sandbox, thing, placementSpec) {
  8858. showWithin(sandbox, thing, placementSpec, Optional.none());
  8859. };
  8860. var showWithin = function(sandbox, thing, placementSpec, boxElement) {
  8861. showWithinBounds(sandbox, thing, placementSpec, function() {
  8862. return boxElement.map(function(elem) {
  8863. return box$1(elem);
  8864. });
  8865. });
  8866. };
  8867. var showWithinBounds = function(sandbox, thing, placementSpec, getBounds2) {
  8868. var sink = detail.lazySink(sandbox).getOrDie();
  8869. Sandboxing.openWhileCloaked(sandbox, thing, function() {
  8870. return Positioning.positionWithinBounds(sink, sandbox, placementSpec, getBounds2());
  8871. });
  8872. Representing.setValue(sandbox, Optional.some({
  8873. mode: "position",
  8874. config: placementSpec,
  8875. getBounds: getBounds2
  8876. }));
  8877. };
  8878. var showMenuAt = function(sandbox, placementSpec, menuSpec) {
  8879. showMenuWithinBounds(sandbox, placementSpec, menuSpec, Optional.none);
  8880. };
  8881. var showMenuWithinBounds = function(sandbox, placementSpec, menuSpec, getBounds2) {
  8882. var menu2 = makeMenu(detail, sandbox, placementSpec, menuSpec, getBounds2);
  8883. Sandboxing.open(sandbox, menu2);
  8884. Representing.setValue(sandbox, Optional.some({
  8885. mode: "menu",
  8886. menu: menu2
  8887. }));
  8888. };
  8889. var hide = function(sandbox) {
  8890. if (Sandboxing.isOpen(sandbox)) {
  8891. Representing.setValue(sandbox, Optional.none());
  8892. Sandboxing.close(sandbox);
  8893. }
  8894. };
  8895. var getContent = function(sandbox) {
  8896. return Sandboxing.getState(sandbox);
  8897. };
  8898. var reposition2 = function(sandbox) {
  8899. if (Sandboxing.isOpen(sandbox)) {
  8900. Representing.getValue(sandbox).each(function(state) {
  8901. switch (state.mode) {
  8902. case "menu":
  8903. Sandboxing.getState(sandbox).each(tieredMenu.repositionMenus);
  8904. break;
  8905. case "position":
  8906. var sink = detail.lazySink(sandbox).getOrDie();
  8907. Positioning.positionWithinBounds(sink, sandbox, state.config, state.getBounds());
  8908. break;
  8909. }
  8910. });
  8911. }
  8912. };
  8913. var apis = {
  8914. setContent: setContent2,
  8915. showAt,
  8916. showWithin,
  8917. showWithinBounds,
  8918. showMenuAt,
  8919. showMenuWithinBounds,
  8920. hide,
  8921. getContent,
  8922. reposition: reposition2,
  8923. isOpen: Sandboxing.isOpen
  8924. };
  8925. return {
  8926. uid: detail.uid,
  8927. dom: detail.dom,
  8928. behaviours: augment(detail.inlineBehaviours, [
  8929. Sandboxing.config({
  8930. isPartOf: function(sandbox, data, queryElem) {
  8931. return isPartOf$1(data, queryElem) || isPartOfRelated(sandbox, queryElem);
  8932. },
  8933. getAttachPoint: function(sandbox) {
  8934. return detail.lazySink(sandbox).getOrDie();
  8935. },
  8936. onOpen: function(sandbox) {
  8937. detail.onShow(sandbox);
  8938. },
  8939. onClose: function(sandbox) {
  8940. detail.onHide(sandbox);
  8941. }
  8942. }),
  8943. Representing.config({
  8944. store: {
  8945. mode: "memory",
  8946. initialValue: Optional.none()
  8947. }
  8948. }),
  8949. Receiving.config({
  8950. channels: __assign(__assign({}, receivingChannel$1(__assign({ isExtraPart: spec.isExtraPart }, detail.fireDismissalEventInstead.map(function(fe) {
  8951. return { fireEventInstead: { event: fe.event } };
  8952. }).getOr({})))), receivingChannel(__assign(__assign({}, detail.fireRepositionEventInstead.map(function(fe) {
  8953. return { fireEventInstead: { event: fe.event } };
  8954. }).getOr({})), { doReposition: reposition2 })))
  8955. })
  8956. ]),
  8957. eventOrder: detail.eventOrder,
  8958. apis
  8959. };
  8960. };
  8961. var InlineView = single({
  8962. name: "InlineView",
  8963. configFields: [
  8964. required$1("lazySink"),
  8965. onHandler("onShow"),
  8966. onHandler("onHide"),
  8967. optionFunction("onEscape"),
  8968. field("inlineBehaviours", [
  8969. Sandboxing,
  8970. Representing,
  8971. Receiving
  8972. ]),
  8973. optionObjOf("fireDismissalEventInstead", [defaulted("event", dismissRequested())]),
  8974. optionObjOf("fireRepositionEventInstead", [defaulted("event", repositionRequested())]),
  8975. defaulted("getRelated", Optional.none),
  8976. defaulted("isExtraPart", never),
  8977. defaulted("eventOrder", Optional.none)
  8978. ],
  8979. factory: factory$m,
  8980. apis: {
  8981. showAt: function(apis, component, anchor2, thing) {
  8982. apis.showAt(component, anchor2, thing);
  8983. },
  8984. showWithin: function(apis, component, anchor2, thing, boxElement) {
  8985. apis.showWithin(component, anchor2, thing, boxElement);
  8986. },
  8987. showWithinBounds: function(apis, component, anchor2, thing, bounds2) {
  8988. apis.showWithinBounds(component, anchor2, thing, bounds2);
  8989. },
  8990. showMenuAt: function(apis, component, anchor2, menuSpec) {
  8991. apis.showMenuAt(component, anchor2, menuSpec);
  8992. },
  8993. showMenuWithinBounds: function(apis, component, anchor2, menuSpec, bounds2) {
  8994. apis.showMenuWithinBounds(component, anchor2, menuSpec, bounds2);
  8995. },
  8996. hide: function(apis, component) {
  8997. apis.hide(component);
  8998. },
  8999. isOpen: function(apis, component) {
  9000. return apis.isOpen(component);
  9001. },
  9002. getContent: function(apis, component) {
  9003. return apis.getContent(component);
  9004. },
  9005. setContent: function(apis, component, thing) {
  9006. apis.setContent(component, thing);
  9007. },
  9008. reposition: function(apis, component) {
  9009. apis.reposition(component);
  9010. }
  9011. }
  9012. });
  9013. var labelPrefix = "layout-inset";
  9014. var westEdgeX = function(anchor2) {
  9015. return anchor2.x;
  9016. };
  9017. var middleX = function(anchor2, element2) {
  9018. return anchor2.x + anchor2.width / 2 - element2.width / 2;
  9019. };
  9020. var eastEdgeX = function(anchor2, element2) {
  9021. return anchor2.x + anchor2.width - element2.width;
  9022. };
  9023. var northY = function(anchor2) {
  9024. return anchor2.y;
  9025. };
  9026. var southY = function(anchor2, element2) {
  9027. return anchor2.y + anchor2.height - element2.height;
  9028. };
  9029. var centreY = function(anchor2, element2) {
  9030. return anchor2.y + anchor2.height / 2 - element2.height / 2;
  9031. };
  9032. var southwest = function(anchor2, element2, bubbles) {
  9033. return nu$6(eastEdgeX(anchor2, element2), southY(anchor2, element2), bubbles.insetSouthwest(), northwest$3(), "southwest", boundsRestriction(anchor2, {
  9034. right: 0,
  9035. bottom: 3
  9036. }), labelPrefix);
  9037. };
  9038. var southeast = function(anchor2, element2, bubbles) {
  9039. return nu$6(westEdgeX(anchor2), southY(anchor2, element2), bubbles.insetSoutheast(), northeast$3(), "southeast", boundsRestriction(anchor2, {
  9040. left: 1,
  9041. bottom: 3
  9042. }), labelPrefix);
  9043. };
  9044. var northwest = function(anchor2, element2, bubbles) {
  9045. return nu$6(eastEdgeX(anchor2, element2), northY(anchor2), bubbles.insetNorthwest(), southwest$3(), "northwest", boundsRestriction(anchor2, {
  9046. right: 0,
  9047. top: 2
  9048. }), labelPrefix);
  9049. };
  9050. var northeast = function(anchor2, element2, bubbles) {
  9051. return nu$6(westEdgeX(anchor2), northY(anchor2), bubbles.insetNortheast(), southeast$3(), "northeast", boundsRestriction(anchor2, {
  9052. left: 1,
  9053. top: 2
  9054. }), labelPrefix);
  9055. };
  9056. var north = function(anchor2, element2, bubbles) {
  9057. return nu$6(middleX(anchor2, element2), northY(anchor2), bubbles.insetNorth(), south$3(), "north", boundsRestriction(anchor2, { top: 2 }), labelPrefix);
  9058. };
  9059. var south = function(anchor2, element2, bubbles) {
  9060. return nu$6(middleX(anchor2, element2), southY(anchor2, element2), bubbles.insetSouth(), north$3(), "south", boundsRestriction(anchor2, { bottom: 3 }), labelPrefix);
  9061. };
  9062. var east = function(anchor2, element2, bubbles) {
  9063. return nu$6(eastEdgeX(anchor2, element2), centreY(anchor2, element2), bubbles.insetEast(), west$3(), "east", boundsRestriction(anchor2, { right: 0 }), labelPrefix);
  9064. };
  9065. var west = function(anchor2, element2, bubbles) {
  9066. return nu$6(westEdgeX(anchor2), centreY(anchor2, element2), bubbles.insetWest(), east$3(), "west", boundsRestriction(anchor2, { left: 1 }), labelPrefix);
  9067. };
  9068. var lookupPreserveLayout = function(lastPlacement) {
  9069. switch (lastPlacement) {
  9070. case "north":
  9071. return north;
  9072. case "northeast":
  9073. return northeast;
  9074. case "northwest":
  9075. return northwest;
  9076. case "south":
  9077. return south;
  9078. case "southeast":
  9079. return southeast;
  9080. case "southwest":
  9081. return southwest;
  9082. case "east":
  9083. return east;
  9084. case "west":
  9085. return west;
  9086. }
  9087. };
  9088. var preserve = function(anchor2, element2, bubbles, placee, bounds2) {
  9089. var layout2 = getPlacement(placee).map(lookupPreserveLayout).getOr(north);
  9090. return layout2(anchor2, element2, bubbles, placee, bounds2);
  9091. };
  9092. var lookupFlippedLayout = function(lastPlacement) {
  9093. switch (lastPlacement) {
  9094. case "north":
  9095. return south;
  9096. case "northeast":
  9097. return southeast;
  9098. case "northwest":
  9099. return southwest;
  9100. case "south":
  9101. return north;
  9102. case "southeast":
  9103. return northeast;
  9104. case "southwest":
  9105. return northwest;
  9106. case "east":
  9107. return west;
  9108. case "west":
  9109. return east;
  9110. }
  9111. };
  9112. var flip$2 = function(anchor2, element2, bubbles, placee, bounds2) {
  9113. var layout2 = getPlacement(placee).map(lookupFlippedLayout).getOr(north);
  9114. return layout2(anchor2, element2, bubbles, placee, bounds2);
  9115. };
  9116. var global$f = tinymce.util.Tools.resolve("tinymce.util.Delay");
  9117. var factory$l = function(detail) {
  9118. var events2 = events$a(detail.action);
  9119. var tag = detail.dom.tag;
  9120. var lookupAttr = function(attr) {
  9121. return get$e(detail.dom, "attributes").bind(function(attrs) {
  9122. return get$e(attrs, attr);
  9123. });
  9124. };
  9125. var getModAttributes = function() {
  9126. if (tag === "button") {
  9127. var type2 = lookupAttr("type").getOr("button");
  9128. var roleAttrs = lookupAttr("role").map(function(role2) {
  9129. return { role: role2 };
  9130. }).getOr({});
  9131. return __assign({ type: type2 }, roleAttrs);
  9132. } else {
  9133. var role = lookupAttr("role").getOr("button");
  9134. return { role };
  9135. }
  9136. };
  9137. return {
  9138. uid: detail.uid,
  9139. dom: detail.dom,
  9140. components: detail.components,
  9141. events: events2,
  9142. behaviours: SketchBehaviours.augment(detail.buttonBehaviours, [
  9143. Focusing.config({}),
  9144. Keying.config({
  9145. mode: "execution",
  9146. useSpace: true,
  9147. useEnter: true
  9148. })
  9149. ]),
  9150. domModification: { attributes: getModAttributes() },
  9151. eventOrder: detail.eventOrder
  9152. };
  9153. };
  9154. var Button = single({
  9155. name: "Button",
  9156. factory: factory$l,
  9157. configFields: [
  9158. defaulted("uid", void 0),
  9159. required$1("dom"),
  9160. defaulted("components", []),
  9161. SketchBehaviours.field("buttonBehaviours", [
  9162. Focusing,
  9163. Keying
  9164. ]),
  9165. option("action"),
  9166. option("role"),
  9167. defaulted("eventOrder", {})
  9168. ]
  9169. });
  9170. var record = function(spec) {
  9171. var uid = isSketchSpec(spec) && hasNonNullableKey(spec, "uid") ? spec.uid : generate$5("memento");
  9172. var get2 = function(anyInSystem) {
  9173. return anyInSystem.getSystem().getByUid(uid).getOrDie();
  9174. };
  9175. var getOpt2 = function(anyInSystem) {
  9176. return anyInSystem.getSystem().getByUid(uid).toOptional();
  9177. };
  9178. var asSpec = function() {
  9179. return __assign(__assign({}, spec), { uid });
  9180. };
  9181. return {
  9182. get: get2,
  9183. getOpt: getOpt2,
  9184. asSpec
  9185. };
  9186. };
  9187. var global$e = tinymce.util.Tools.resolve("tinymce.util.I18n");
  9188. var rtlTransform = {
  9189. "indent": true,
  9190. "outdent": true,
  9191. "table-insert-column-after": true,
  9192. "table-insert-column-before": true,
  9193. "paste-column-after": true,
  9194. "paste-column-before": true,
  9195. "unordered-list": true,
  9196. "list-bull-circle": true,
  9197. "list-bull-default": true,
  9198. "list-bull-square": true
  9199. };
  9200. var defaultIconName = "temporary-placeholder";
  9201. var defaultIcon = function(icons) {
  9202. return function() {
  9203. return get$e(icons, defaultIconName).getOr("!not found!");
  9204. };
  9205. };
  9206. var getIconName = function(name2, icons) {
  9207. var lcName = name2.toLowerCase();
  9208. if (global$e.isRtl()) {
  9209. var rtlName = ensureTrailing(lcName, "-rtl");
  9210. return has$2(icons, rtlName) ? rtlName : lcName;
  9211. } else {
  9212. return lcName;
  9213. }
  9214. };
  9215. var lookupIcon = function(name2, icons) {
  9216. return get$e(icons, getIconName(name2, icons));
  9217. };
  9218. var get$1 = function(name2, iconProvider) {
  9219. var icons = iconProvider();
  9220. return lookupIcon(name2, icons).getOrThunk(defaultIcon(icons));
  9221. };
  9222. var getOr = function(name2, iconProvider, fallbackIcon) {
  9223. var icons = iconProvider();
  9224. return lookupIcon(name2, icons).or(fallbackIcon).getOrThunk(defaultIcon(icons));
  9225. };
  9226. var needsRtlTransform = function(iconName) {
  9227. return global$e.isRtl() ? has$2(rtlTransform, iconName) : false;
  9228. };
  9229. var addFocusableBehaviour = function() {
  9230. return config("add-focusable", [runOnAttached(function(comp) {
  9231. child(comp.element, "svg").each(function(svg2) {
  9232. return set$8(svg2, "focusable", "false");
  9233. });
  9234. })]);
  9235. };
  9236. var renderIcon$2 = function(spec, iconName, icons, fallbackIcon) {
  9237. var _a2, _b;
  9238. var rtlIconClasses = needsRtlTransform(iconName) ? ["tox-icon--flip"] : [];
  9239. var iconHtml = get$e(icons, getIconName(iconName, icons)).or(fallbackIcon).getOrThunk(defaultIcon(icons));
  9240. return {
  9241. dom: {
  9242. tag: spec.tag,
  9243. attributes: (_a2 = spec.attributes) !== null && _a2 !== void 0 ? _a2 : {},
  9244. classes: spec.classes.concat(rtlIconClasses),
  9245. innerHtml: iconHtml
  9246. },
  9247. behaviours: derive$1(__spreadArray(__spreadArray([], (_b = spec.behaviours) !== null && _b !== void 0 ? _b : [], true), [addFocusableBehaviour()], false))
  9248. };
  9249. };
  9250. var render$3 = function(iconName, spec, iconProvider, fallbackIcon) {
  9251. if (fallbackIcon === void 0) {
  9252. fallbackIcon = Optional.none();
  9253. }
  9254. return renderIcon$2(spec, iconName, iconProvider(), fallbackIcon);
  9255. };
  9256. var renderFirst = function(iconNames, spec, iconProvider) {
  9257. var icons = iconProvider();
  9258. var iconName = find$5(iconNames, function(name2) {
  9259. return has$2(icons, getIconName(name2, icons));
  9260. });
  9261. return renderIcon$2(spec, iconName.getOr(defaultIconName), icons, Optional.none());
  9262. };
  9263. var notificationIconMap = {
  9264. success: "checkmark",
  9265. error: "warning",
  9266. err: "error",
  9267. warning: "warning",
  9268. warn: "warning",
  9269. info: "info"
  9270. };
  9271. var factory$k = function(detail) {
  9272. var memBannerText = record({
  9273. dom: {
  9274. tag: "p",
  9275. innerHtml: detail.translationProvider(detail.text)
  9276. },
  9277. behaviours: derive$1([Replacing.config({})])
  9278. });
  9279. var renderPercentBar = function(percent) {
  9280. return {
  9281. dom: {
  9282. tag: "div",
  9283. classes: ["tox-bar"],
  9284. attributes: { style: "width: " + percent + "%" }
  9285. }
  9286. };
  9287. };
  9288. var renderPercentText = function(percent) {
  9289. return {
  9290. dom: {
  9291. tag: "div",
  9292. classes: ["tox-text"],
  9293. innerHtml: percent + "%"
  9294. }
  9295. };
  9296. };
  9297. var memBannerProgress = record({
  9298. dom: {
  9299. tag: "div",
  9300. classes: detail.progress ? [
  9301. "tox-progress-bar",
  9302. "tox-progress-indicator"
  9303. ] : ["tox-progress-bar"]
  9304. },
  9305. components: [
  9306. {
  9307. dom: {
  9308. tag: "div",
  9309. classes: ["tox-bar-container"]
  9310. },
  9311. components: [renderPercentBar(0)]
  9312. },
  9313. renderPercentText(0)
  9314. ],
  9315. behaviours: derive$1([Replacing.config({})])
  9316. });
  9317. var updateProgress = function(comp, percent) {
  9318. if (comp.getSystem().isConnected()) {
  9319. memBannerProgress.getOpt(comp).each(function(progress) {
  9320. Replacing.set(progress, [
  9321. {
  9322. dom: {
  9323. tag: "div",
  9324. classes: ["tox-bar-container"]
  9325. },
  9326. components: [renderPercentBar(percent)]
  9327. },
  9328. renderPercentText(percent)
  9329. ]);
  9330. });
  9331. }
  9332. };
  9333. var updateText = function(comp, text2) {
  9334. if (comp.getSystem().isConnected()) {
  9335. var banner = memBannerText.get(comp);
  9336. Replacing.set(banner, [text$1(text2)]);
  9337. }
  9338. };
  9339. var apis = {
  9340. updateProgress,
  9341. updateText
  9342. };
  9343. var iconChoices = flatten([
  9344. detail.icon.toArray(),
  9345. detail.level.toArray(),
  9346. detail.level.bind(function(level) {
  9347. return Optional.from(notificationIconMap[level]);
  9348. }).toArray()
  9349. ]);
  9350. var memButton = record(Button.sketch({
  9351. dom: {
  9352. tag: "button",
  9353. classes: [
  9354. "tox-notification__dismiss",
  9355. "tox-button",
  9356. "tox-button--naked",
  9357. "tox-button--icon"
  9358. ]
  9359. },
  9360. components: [render$3("close", {
  9361. tag: "div",
  9362. classes: ["tox-icon"],
  9363. attributes: { "aria-label": detail.translationProvider("Close") }
  9364. }, detail.iconProvider)],
  9365. action: function(comp) {
  9366. detail.onAction(comp);
  9367. }
  9368. }));
  9369. var notificationIconSpec = renderFirst(iconChoices, {
  9370. tag: "div",
  9371. classes: ["tox-notification__icon"]
  9372. }, detail.iconProvider);
  9373. var notificationBodySpec = {
  9374. dom: {
  9375. tag: "div",
  9376. classes: ["tox-notification__body"]
  9377. },
  9378. components: [memBannerText.asSpec()],
  9379. behaviours: derive$1([Replacing.config({})])
  9380. };
  9381. var components2 = [
  9382. notificationIconSpec,
  9383. notificationBodySpec
  9384. ];
  9385. return {
  9386. uid: detail.uid,
  9387. dom: {
  9388. tag: "div",
  9389. attributes: { role: "alert" },
  9390. classes: detail.level.map(function(level) {
  9391. return [
  9392. "tox-notification",
  9393. "tox-notification--in",
  9394. "tox-notification--" + level
  9395. ];
  9396. }).getOr([
  9397. "tox-notification",
  9398. "tox-notification--in"
  9399. ])
  9400. },
  9401. behaviours: derive$1([
  9402. Focusing.config({}),
  9403. config("notification-events", [run$1(focusin(), function(comp) {
  9404. memButton.getOpt(comp).each(Focusing.focus);
  9405. })])
  9406. ]),
  9407. components: components2.concat(detail.progress ? [memBannerProgress.asSpec()] : []).concat(!detail.closeButton ? [] : [memButton.asSpec()]),
  9408. apis
  9409. };
  9410. };
  9411. var Notification = single({
  9412. name: "Notification",
  9413. factory: factory$k,
  9414. configFields: [
  9415. option("level"),
  9416. required$1("progress"),
  9417. required$1("icon"),
  9418. required$1("onAction"),
  9419. required$1("text"),
  9420. required$1("iconProvider"),
  9421. required$1("translationProvider"),
  9422. defaultedBoolean("closeButton", true)
  9423. ],
  9424. apis: {
  9425. updateProgress: function(apis, comp, percent) {
  9426. apis.updateProgress(comp, percent);
  9427. },
  9428. updateText: function(apis, comp, text2) {
  9429. apis.updateText(comp, text2);
  9430. }
  9431. }
  9432. });
  9433. function NotificationManagerImpl(editor, extras, uiMothership) {
  9434. var sharedBackstage = extras.backstage.shared;
  9435. var getLayoutDirection = function(rel) {
  9436. switch (rel) {
  9437. case "bc-bc":
  9438. return south;
  9439. case "tc-tc":
  9440. return north;
  9441. case "tc-bc":
  9442. return north$2;
  9443. case "bc-tc":
  9444. default:
  9445. return south$2;
  9446. }
  9447. };
  9448. var reposition2 = function(notifications) {
  9449. if (notifications.length > 0) {
  9450. each$1(notifications, function(notification, index) {
  9451. if (index === 0) {
  9452. notification.moveRel(null, "banner");
  9453. } else {
  9454. notification.moveRel(notifications[index - 1].getEl(), "bc-tc");
  9455. }
  9456. });
  9457. }
  9458. };
  9459. var open2 = function(settings, closeCallback) {
  9460. var hideCloseButton = !settings.closeButton && settings.timeout && (settings.timeout > 0 || settings.timeout < 0);
  9461. var close3 = function() {
  9462. closeCallback();
  9463. InlineView.hide(notificationWrapper);
  9464. };
  9465. var notification = build$1(Notification.sketch({
  9466. text: settings.text,
  9467. level: contains$2([
  9468. "success",
  9469. "error",
  9470. "warning",
  9471. "warn",
  9472. "info"
  9473. ], settings.type) ? settings.type : void 0,
  9474. progress: settings.progressBar === true,
  9475. icon: Optional.from(settings.icon),
  9476. closeButton: !hideCloseButton,
  9477. onAction: close3,
  9478. iconProvider: sharedBackstage.providers.icons,
  9479. translationProvider: sharedBackstage.providers.translate
  9480. }));
  9481. var notificationWrapper = build$1(InlineView.sketch(__assign({
  9482. dom: {
  9483. tag: "div",
  9484. classes: ["tox-notifications-container"]
  9485. },
  9486. lazySink: sharedBackstage.getSink,
  9487. fireDismissalEventInstead: {}
  9488. }, sharedBackstage.header.isPositionedAtTop() ? {} : { fireRepositionEventInstead: {} })));
  9489. uiMothership.add(notificationWrapper);
  9490. if (settings.timeout > 0) {
  9491. global$f.setTimeout(function() {
  9492. close3();
  9493. }, settings.timeout);
  9494. }
  9495. var getBounds2 = function() {
  9496. var contentArea = box$1(SugarElement.fromDom(editor.getContentAreaContainer()));
  9497. var win$1 = win();
  9498. var x = clamp$1(win$1.x, contentArea.x, contentArea.right);
  9499. var y = clamp$1(win$1.y, contentArea.y, contentArea.bottom);
  9500. var right2 = Math.max(contentArea.right, win$1.right);
  9501. var bottom2 = Math.max(contentArea.bottom, win$1.bottom);
  9502. return Optional.some(bounds(x, y, right2 - x, bottom2 - y));
  9503. };
  9504. return {
  9505. close: close3,
  9506. moveTo: function(x, y) {
  9507. InlineView.showAt(notificationWrapper, premade(notification), {
  9508. anchor: {
  9509. type: "makeshift",
  9510. x,
  9511. y
  9512. }
  9513. });
  9514. },
  9515. moveRel: function(element2, rel) {
  9516. var notificationSpec = premade(notification);
  9517. var anchorOverrides2 = { maxHeightFunction: expandable$1() };
  9518. if (rel !== "banner" && isNonNullable(element2)) {
  9519. var layoutDirection_1 = getLayoutDirection(rel);
  9520. var nodeAnchor = {
  9521. type: "node",
  9522. root: body(),
  9523. node: Optional.some(SugarElement.fromDom(element2)),
  9524. overrides: anchorOverrides2,
  9525. layouts: {
  9526. onRtl: function() {
  9527. return [layoutDirection_1];
  9528. },
  9529. onLtr: function() {
  9530. return [layoutDirection_1];
  9531. }
  9532. }
  9533. };
  9534. InlineView.showWithinBounds(notificationWrapper, notificationSpec, { anchor: nodeAnchor }, getBounds2);
  9535. } else {
  9536. var anchor2 = __assign(__assign({}, sharedBackstage.anchors.banner()), { overrides: anchorOverrides2 });
  9537. InlineView.showWithinBounds(notificationWrapper, notificationSpec, { anchor: anchor2 }, getBounds2);
  9538. }
  9539. },
  9540. text: function(nuText) {
  9541. Notification.updateText(notification, nuText);
  9542. },
  9543. settings,
  9544. getEl: function() {
  9545. return notification.element.dom;
  9546. },
  9547. progressBar: {
  9548. value: function(percent) {
  9549. Notification.updateProgress(notification, percent);
  9550. }
  9551. }
  9552. };
  9553. };
  9554. var close2 = function(notification) {
  9555. notification.close();
  9556. };
  9557. var getArgs = function(notification) {
  9558. return notification.settings;
  9559. };
  9560. return {
  9561. open: open2,
  9562. close: close2,
  9563. reposition: reposition2,
  9564. getArgs
  9565. };
  9566. }
  9567. var first = function(fn, rate) {
  9568. var timer = null;
  9569. var cancel = function() {
  9570. if (!isNull(timer)) {
  9571. clearTimeout(timer);
  9572. timer = null;
  9573. }
  9574. };
  9575. var throttle2 = function() {
  9576. var args = [];
  9577. for (var _i = 0; _i < arguments.length; _i++) {
  9578. args[_i] = arguments[_i];
  9579. }
  9580. if (isNull(timer)) {
  9581. timer = setTimeout(function() {
  9582. timer = null;
  9583. fn.apply(null, args);
  9584. }, rate);
  9585. }
  9586. };
  9587. return {
  9588. cancel,
  9589. throttle: throttle2
  9590. };
  9591. };
  9592. var last = function(fn, rate) {
  9593. var timer = null;
  9594. var cancel = function() {
  9595. if (!isNull(timer)) {
  9596. clearTimeout(timer);
  9597. timer = null;
  9598. }
  9599. };
  9600. var throttle2 = function() {
  9601. var args = [];
  9602. for (var _i = 0; _i < arguments.length; _i++) {
  9603. args[_i] = arguments[_i];
  9604. }
  9605. cancel();
  9606. timer = setTimeout(function() {
  9607. timer = null;
  9608. fn.apply(null, args);
  9609. }, rate);
  9610. };
  9611. return {
  9612. cancel,
  9613. throttle: throttle2
  9614. };
  9615. };
  9616. var global$d = tinymce.util.Tools.resolve("tinymce.dom.TextSeeker");
  9617. var isBoundary = function(dom2, node) {
  9618. return dom2.isBlock(node) || contains$2([
  9619. "BR",
  9620. "IMG",
  9621. "HR",
  9622. "INPUT"
  9623. ], node.nodeName) || dom2.getContentEditable(node) === "false";
  9624. };
  9625. var repeatLeft = function(dom2, node, offset2, process2, rootNode) {
  9626. var search2 = global$d(dom2, function(node2) {
  9627. return isBoundary(dom2, node2);
  9628. });
  9629. return Optional.from(search2.backwards(node, offset2, process2, rootNode));
  9630. };
  9631. var autocompleteSelector = "[data-mce-autocompleter]";
  9632. var create$5 = function(editor, range2) {
  9633. return detect(SugarElement.fromDom(editor.selection.getNode())).getOrThunk(function() {
  9634. var wrapper = SugarElement.fromHtml('<span data-mce-autocompleter="1" data-mce-bogus="1"></span>', editor.getDoc());
  9635. append$2(wrapper, SugarElement.fromDom(range2.extractContents()));
  9636. range2.insertNode(wrapper.dom);
  9637. parent(wrapper).each(function(elm) {
  9638. return elm.dom.normalize();
  9639. });
  9640. last$1(wrapper).map(function(last2) {
  9641. editor.selection.setCursorLocation(last2.dom, getEnd(last2));
  9642. });
  9643. return wrapper;
  9644. });
  9645. };
  9646. var detect = function(elm) {
  9647. return closest$1(elm, autocompleteSelector);
  9648. };
  9649. var isValidTextRange = function(rng) {
  9650. return rng.collapsed && rng.startContainer.nodeType === 3;
  9651. };
  9652. var getText = function(rng) {
  9653. return rng.toString().replace(/\u00A0/g, " ").replace(/\uFEFF/g, "");
  9654. };
  9655. var isWhitespace = function(chr) {
  9656. return chr !== "" && "  \f\n\r \v".indexOf(chr) !== -1;
  9657. };
  9658. var stripTriggerChar = function(text2, triggerCh) {
  9659. return text2.substring(triggerCh.length);
  9660. };
  9661. var findChar = function(text2, index, ch) {
  9662. var i;
  9663. for (i = index - 1; i >= 0; i--) {
  9664. var char = text2.charAt(i);
  9665. if (isWhitespace(char)) {
  9666. return Optional.none();
  9667. }
  9668. if (char === ch) {
  9669. break;
  9670. }
  9671. }
  9672. return Optional.some(i);
  9673. };
  9674. var findStart = function(dom2, initRange, ch, minChars) {
  9675. if (minChars === void 0) {
  9676. minChars = 0;
  9677. }
  9678. if (!isValidTextRange(initRange)) {
  9679. return Optional.none();
  9680. }
  9681. var findTriggerChIndex = function(element2, offset2, text2) {
  9682. return findChar(text2, offset2, ch).getOr(offset2);
  9683. };
  9684. var root = dom2.getParent(initRange.startContainer, dom2.isBlock) || dom2.getRoot();
  9685. return repeatLeft(dom2, initRange.startContainer, initRange.startOffset, findTriggerChIndex, root).bind(function(spot2) {
  9686. var range2 = initRange.cloneRange();
  9687. range2.setStart(spot2.container, spot2.offset);
  9688. range2.setEnd(initRange.endContainer, initRange.endOffset);
  9689. if (range2.collapsed) {
  9690. return Optional.none();
  9691. }
  9692. var text2 = getText(range2);
  9693. var triggerCharIndex = text2.lastIndexOf(ch);
  9694. if (triggerCharIndex !== 0 || stripTriggerChar(text2, ch).length < minChars) {
  9695. return Optional.none();
  9696. } else {
  9697. return Optional.some({
  9698. text: stripTriggerChar(text2, ch),
  9699. range: range2,
  9700. triggerChar: ch
  9701. });
  9702. }
  9703. });
  9704. };
  9705. var getContext = function(dom2, initRange, ch, minChars) {
  9706. if (minChars === void 0) {
  9707. minChars = 0;
  9708. }
  9709. return detect(SugarElement.fromDom(initRange.startContainer)).fold(function() {
  9710. return findStart(dom2, initRange, ch, minChars);
  9711. }, function(elm) {
  9712. var range2 = dom2.createRng();
  9713. range2.selectNode(elm.dom);
  9714. var text2 = getText(range2);
  9715. return Optional.some({
  9716. range: range2,
  9717. text: stripTriggerChar(text2, ch),
  9718. triggerChar: ch
  9719. });
  9720. });
  9721. };
  9722. var setup$e = function(api2, editor) {
  9723. editor.on("keypress compositionend", api2.onKeypress.throttle);
  9724. editor.on("remove", api2.onKeypress.cancel);
  9725. var redirectKeyToItem = function(item2, e) {
  9726. emitWith(item2, keydown(), { raw: e });
  9727. };
  9728. editor.on("keydown", function(e) {
  9729. var getItem = function() {
  9730. return api2.getView().bind(Highlighting.getHighlighted);
  9731. };
  9732. if (e.which === 8) {
  9733. api2.onKeypress.throttle(e);
  9734. }
  9735. if (api2.isActive()) {
  9736. if (e.which === 27) {
  9737. api2.cancelIfNecessary();
  9738. }
  9739. if (api2.isMenuOpen()) {
  9740. if (e.which === 13) {
  9741. getItem().each(emitExecute);
  9742. e.preventDefault();
  9743. } else if (e.which === 40) {
  9744. getItem().fold(function() {
  9745. api2.getView().each(Highlighting.highlightFirst);
  9746. }, function(item2) {
  9747. redirectKeyToItem(item2, e);
  9748. });
  9749. e.preventDefault();
  9750. e.stopImmediatePropagation();
  9751. } else if (e.which === 37 || e.which === 38 || e.which === 39) {
  9752. getItem().each(function(item2) {
  9753. redirectKeyToItem(item2, e);
  9754. e.preventDefault();
  9755. e.stopImmediatePropagation();
  9756. });
  9757. }
  9758. } else {
  9759. if (e.which === 13 || e.which === 38 || e.which === 40) {
  9760. api2.cancelIfNecessary();
  9761. }
  9762. }
  9763. }
  9764. });
  9765. editor.on("NodeChange", function(e) {
  9766. if (api2.isActive() && !api2.isProcessingAction() && detect(SugarElement.fromDom(e.element)).isNone()) {
  9767. api2.cancelIfNecessary();
  9768. }
  9769. });
  9770. };
  9771. var AutocompleterEditorEvents = { setup: setup$e };
  9772. var global$c = tinymce.util.Tools.resolve("tinymce.util.Promise");
  9773. var point = function(container, offset2) {
  9774. return {
  9775. container,
  9776. offset: offset2
  9777. };
  9778. };
  9779. var isText = function(node) {
  9780. return node.nodeType === TEXT;
  9781. };
  9782. var isElement$1 = function(node) {
  9783. return node.nodeType === ELEMENT;
  9784. };
  9785. var toLast = function(node) {
  9786. if (isText(node)) {
  9787. return point(node, node.data.length);
  9788. } else {
  9789. var children2 = node.childNodes;
  9790. return children2.length > 0 ? toLast(children2[children2.length - 1]) : point(node, children2.length);
  9791. }
  9792. };
  9793. var toLeaf = function(node, offset2) {
  9794. var children2 = node.childNodes;
  9795. if (children2.length > 0 && offset2 < children2.length) {
  9796. return toLeaf(children2[offset2], 0);
  9797. } else if (children2.length > 0 && isElement$1(node) && children2.length === offset2) {
  9798. return toLast(children2[children2.length - 1]);
  9799. } else {
  9800. return point(node, offset2);
  9801. }
  9802. };
  9803. var isPreviousCharContent = function(dom2, leaf2) {
  9804. return repeatLeft(dom2, leaf2.container, leaf2.offset, function(element2, offset2) {
  9805. return offset2 === 0 ? -1 : offset2;
  9806. }, dom2.getRoot()).filter(function(spot2) {
  9807. var char = spot2.container.data.charAt(spot2.offset - 1);
  9808. return !isWhitespace(char);
  9809. }).isSome();
  9810. };
  9811. var isStartOfWord = function(dom2) {
  9812. return function(rng) {
  9813. var leaf2 = toLeaf(rng.startContainer, rng.startOffset);
  9814. return !isPreviousCharContent(dom2, leaf2);
  9815. };
  9816. };
  9817. var getTriggerContext = function(dom2, initRange, database) {
  9818. return findMap(database.triggerChars, function(ch) {
  9819. return getContext(dom2, initRange, ch);
  9820. });
  9821. };
  9822. var lookup$2 = function(editor, getDatabase) {
  9823. var database = getDatabase();
  9824. var rng = editor.selection.getRng();
  9825. return getTriggerContext(editor.dom, rng, database).bind(function(context) {
  9826. return lookupWithContext(editor, getDatabase, context);
  9827. });
  9828. };
  9829. var lookupWithContext = function(editor, getDatabase, context, fetchOptions) {
  9830. if (fetchOptions === void 0) {
  9831. fetchOptions = {};
  9832. }
  9833. var database = getDatabase();
  9834. var rng = editor.selection.getRng();
  9835. var startText = rng.startContainer.nodeValue;
  9836. var autocompleters = filter$2(database.lookupByChar(context.triggerChar), function(autocompleter) {
  9837. return context.text.length >= autocompleter.minChars && autocompleter.matches.getOrThunk(function() {
  9838. return isStartOfWord(editor.dom);
  9839. })(context.range, startText, context.text);
  9840. });
  9841. if (autocompleters.length === 0) {
  9842. return Optional.none();
  9843. }
  9844. var lookupData = global$c.all(map$2(autocompleters, function(ac) {
  9845. var fetchResult = ac.fetch(context.text, ac.maxResults, fetchOptions);
  9846. return fetchResult.then(function(results) {
  9847. return {
  9848. matchText: context.text,
  9849. items: results,
  9850. columns: ac.columns,
  9851. onAction: ac.onAction,
  9852. highlightOn: ac.highlightOn
  9853. };
  9854. });
  9855. }));
  9856. return Optional.some({
  9857. lookupData,
  9858. context
  9859. });
  9860. };
  9861. var separatorMenuItemSchema = objOf([
  9862. requiredString("type"),
  9863. optionString("text")
  9864. ]);
  9865. var createSeparatorMenuItem = function(spec) {
  9866. return asRaw("separatormenuitem", separatorMenuItemSchema, spec);
  9867. };
  9868. var autocompleterItemSchema = objOf([
  9869. defaulted("type", "autocompleteitem"),
  9870. defaulted("active", false),
  9871. defaulted("disabled", false),
  9872. defaulted("meta", {}),
  9873. requiredString("value"),
  9874. optionString("text"),
  9875. optionString("icon")
  9876. ]);
  9877. var autocompleterSchema = objOf([
  9878. requiredString("type"),
  9879. requiredString("ch"),
  9880. defaultedNumber("minChars", 1),
  9881. defaulted("columns", 1),
  9882. defaultedNumber("maxResults", 10),
  9883. optionFunction("matches"),
  9884. requiredFunction("fetch"),
  9885. requiredFunction("onAction"),
  9886. defaultedArrayOf("highlightOn", [], string)
  9887. ]);
  9888. var createSeparatorItem = function(spec) {
  9889. return asRaw("Autocompleter.Separator", separatorMenuItemSchema, spec);
  9890. };
  9891. var createAutocompleterItem = function(spec) {
  9892. return asRaw("Autocompleter.Item", autocompleterItemSchema, spec);
  9893. };
  9894. var createAutocompleter = function(spec) {
  9895. return asRaw("Autocompleter", autocompleterSchema, spec);
  9896. };
  9897. var baseToolbarButtonFields = [
  9898. defaultedBoolean("disabled", false),
  9899. optionString("tooltip"),
  9900. optionString("icon"),
  9901. optionString("text"),
  9902. defaultedFunction("onSetup", function() {
  9903. return noop;
  9904. })
  9905. ];
  9906. var toolbarButtonSchema = objOf([
  9907. requiredString("type"),
  9908. requiredFunction("onAction")
  9909. ].concat(baseToolbarButtonFields));
  9910. var createToolbarButton = function(spec) {
  9911. return asRaw("toolbarbutton", toolbarButtonSchema, spec);
  9912. };
  9913. var baseToolbarToggleButtonFields = [defaultedBoolean("active", false)].concat(baseToolbarButtonFields);
  9914. var toggleButtonSchema = objOf(baseToolbarToggleButtonFields.concat([
  9915. requiredString("type"),
  9916. requiredFunction("onAction")
  9917. ]));
  9918. var createToggleButton = function(spec) {
  9919. return asRaw("ToggleButton", toggleButtonSchema, spec);
  9920. };
  9921. var contextBarFields = [
  9922. defaultedFunction("predicate", never),
  9923. defaultedStringEnum("scope", "node", [
  9924. "node",
  9925. "editor"
  9926. ]),
  9927. defaultedStringEnum("position", "selection", [
  9928. "node",
  9929. "selection",
  9930. "line"
  9931. ])
  9932. ];
  9933. var contextButtonFields = baseToolbarButtonFields.concat([
  9934. defaulted("type", "contextformbutton"),
  9935. defaulted("primary", false),
  9936. requiredFunction("onAction"),
  9937. customField("original", identity$1)
  9938. ]);
  9939. var contextToggleButtonFields = baseToolbarToggleButtonFields.concat([
  9940. defaulted("type", "contextformbutton"),
  9941. defaulted("primary", false),
  9942. requiredFunction("onAction"),
  9943. customField("original", identity$1)
  9944. ]);
  9945. var launchButtonFields = baseToolbarButtonFields.concat([defaulted("type", "contextformbutton")]);
  9946. var launchToggleButtonFields = baseToolbarToggleButtonFields.concat([defaulted("type", "contextformtogglebutton")]);
  9947. var toggleOrNormal = choose$1("type", {
  9948. contextformbutton: contextButtonFields,
  9949. contextformtogglebutton: contextToggleButtonFields
  9950. });
  9951. var contextFormSchema = objOf([
  9952. defaulted("type", "contextform"),
  9953. defaultedFunction("initValue", constant$1("")),
  9954. optionString("label"),
  9955. requiredArrayOf("commands", toggleOrNormal),
  9956. optionOf("launch", choose$1("type", {
  9957. contextformbutton: launchButtonFields,
  9958. contextformtogglebutton: launchToggleButtonFields
  9959. }))
  9960. ].concat(contextBarFields));
  9961. var createContextForm = function(spec) {
  9962. return asRaw("ContextForm", contextFormSchema, spec);
  9963. };
  9964. var contextToolbarSchema = objOf([
  9965. defaulted("type", "contexttoolbar"),
  9966. requiredString("items")
  9967. ].concat(contextBarFields));
  9968. var createContextToolbar = function(spec) {
  9969. return asRaw("ContextToolbar", contextToolbarSchema, spec);
  9970. };
  9971. var stringArray = function(a) {
  9972. var all2 = {};
  9973. each$1(a, function(key) {
  9974. all2[key] = {};
  9975. });
  9976. return keys(all2);
  9977. };
  9978. var register$b = function(editor) {
  9979. var popups = editor.ui.registry.getAll().popups;
  9980. var dataset2 = map$1(popups, function(popup) {
  9981. return createAutocompleter(popup).fold(function(err) {
  9982. throw new Error(formatError(err));
  9983. }, identity$1);
  9984. });
  9985. var triggerChars = stringArray(mapToArray(dataset2, function(v) {
  9986. return v.ch;
  9987. }));
  9988. var datasetValues = values(dataset2);
  9989. var lookupByChar = function(ch) {
  9990. return filter$2(datasetValues, function(dv) {
  9991. return dv.ch === ch;
  9992. });
  9993. };
  9994. return {
  9995. dataset: dataset2,
  9996. triggerChars,
  9997. lookupByChar
  9998. };
  9999. };
  10000. var ItemResponse;
  10001. (function(ItemResponse2) {
  10002. ItemResponse2[ItemResponse2["CLOSE_ON_EXECUTE"] = 0] = "CLOSE_ON_EXECUTE";
  10003. ItemResponse2[ItemResponse2["BUBBLE_TO_SANDBOX"] = 1] = "BUBBLE_TO_SANDBOX";
  10004. })(ItemResponse || (ItemResponse = {}));
  10005. var ItemResponse$1 = ItemResponse;
  10006. var navClass = "tox-menu-nav__js";
  10007. var selectableClass = "tox-collection__item";
  10008. var colorClass = "tox-swatch";
  10009. var presetClasses = {
  10010. normal: navClass,
  10011. color: colorClass
  10012. };
  10013. var tickedClass = "tox-collection__item--enabled";
  10014. var groupHeadingClass = "tox-collection__group-heading";
  10015. var iconClass = "tox-collection__item-icon";
  10016. var textClass = "tox-collection__item-label";
  10017. var accessoryClass = "tox-collection__item-accessory";
  10018. var caretClass = "tox-collection__item-caret";
  10019. var checkmarkClass = "tox-collection__item-checkmark";
  10020. var activeClass = "tox-collection__item--active";
  10021. var containerClass = "tox-collection__item-container";
  10022. var containerColumnClass = "tox-collection__item-container--column";
  10023. var containerRowClass = "tox-collection__item-container--row";
  10024. var containerAlignRightClass = "tox-collection__item-container--align-right";
  10025. var containerAlignLeftClass = "tox-collection__item-container--align-left";
  10026. var containerValignTopClass = "tox-collection__item-container--valign-top";
  10027. var containerValignMiddleClass = "tox-collection__item-container--valign-middle";
  10028. var containerValignBottomClass = "tox-collection__item-container--valign-bottom";
  10029. var classForPreset = function(presets) {
  10030. return get$e(presetClasses, presets).getOr(navClass);
  10031. };
  10032. var forMenu = function(presets) {
  10033. if (presets === "color") {
  10034. return "tox-swatches";
  10035. } else {
  10036. return "tox-menu";
  10037. }
  10038. };
  10039. var classes = function(presets) {
  10040. return {
  10041. backgroundMenu: "tox-background-menu",
  10042. selectedMenu: "tox-selected-menu",
  10043. selectedItem: "tox-collection__item--active",
  10044. hasIcons: "tox-menu--has-icons",
  10045. menu: forMenu(presets),
  10046. tieredMenu: "tox-tiered-menu"
  10047. };
  10048. };
  10049. var markers = function(presets) {
  10050. var menuClasses = classes(presets);
  10051. return {
  10052. backgroundMenu: menuClasses.backgroundMenu,
  10053. selectedMenu: menuClasses.selectedMenu,
  10054. menu: menuClasses.menu,
  10055. selectedItem: menuClasses.selectedItem,
  10056. item: classForPreset(presets)
  10057. };
  10058. };
  10059. var dom$1 = function(hasIcons, columns, presets) {
  10060. var menuClasses = classes(presets);
  10061. return {
  10062. tag: "div",
  10063. classes: flatten([
  10064. [
  10065. menuClasses.menu,
  10066. "tox-menu-" + columns + "-column"
  10067. ],
  10068. hasIcons ? [menuClasses.hasIcons] : []
  10069. ])
  10070. };
  10071. };
  10072. var components = [Menu.parts.items({})];
  10073. var part = function(hasIcons, columns, presets) {
  10074. var menuClasses = classes(presets);
  10075. var d = {
  10076. tag: "div",
  10077. classes: flatten([[menuClasses.tieredMenu]])
  10078. };
  10079. return {
  10080. dom: d,
  10081. markers: markers(presets)
  10082. };
  10083. };
  10084. var chunk = function(rowDom, numColumns) {
  10085. return function(items) {
  10086. var chunks = chunk$1(items, numColumns);
  10087. return map$2(chunks, function(c) {
  10088. return {
  10089. dom: rowDom,
  10090. components: c
  10091. };
  10092. });
  10093. };
  10094. };
  10095. var forSwatch = function(columns) {
  10096. return {
  10097. dom: {
  10098. tag: "div",
  10099. classes: [
  10100. "tox-menu",
  10101. "tox-swatches-menu"
  10102. ]
  10103. },
  10104. components: [{
  10105. dom: {
  10106. tag: "div",
  10107. classes: ["tox-swatches"]
  10108. },
  10109. components: [Menu.parts.items({
  10110. preprocess: columns !== "auto" ? chunk({
  10111. tag: "div",
  10112. classes: ["tox-swatches__row"]
  10113. }, columns) : identity$1
  10114. })]
  10115. }]
  10116. };
  10117. };
  10118. var forToolbar = function(columns) {
  10119. return {
  10120. dom: {
  10121. tag: "div",
  10122. classes: [
  10123. "tox-menu",
  10124. "tox-collection",
  10125. "tox-collection--toolbar",
  10126. "tox-collection--toolbar-lg"
  10127. ]
  10128. },
  10129. components: [Menu.parts.items({
  10130. preprocess: chunk({
  10131. tag: "div",
  10132. classes: ["tox-collection__group"]
  10133. }, columns)
  10134. })]
  10135. };
  10136. };
  10137. var preprocessCollection = function(items, isSeparator2) {
  10138. var allSplits = [];
  10139. var currentSplit = [];
  10140. each$1(items, function(item2, i) {
  10141. if (isSeparator2(item2, i)) {
  10142. if (currentSplit.length > 0) {
  10143. allSplits.push(currentSplit);
  10144. }
  10145. currentSplit = [];
  10146. if (has$2(item2.dom, "innerHtml")) {
  10147. currentSplit.push(item2);
  10148. }
  10149. } else {
  10150. currentSplit.push(item2);
  10151. }
  10152. });
  10153. if (currentSplit.length > 0) {
  10154. allSplits.push(currentSplit);
  10155. }
  10156. return map$2(allSplits, function(s) {
  10157. return {
  10158. dom: {
  10159. tag: "div",
  10160. classes: ["tox-collection__group"]
  10161. },
  10162. components: s
  10163. };
  10164. });
  10165. };
  10166. var forCollection = function(columns, initItems, _hasIcons) {
  10167. return {
  10168. dom: {
  10169. tag: "div",
  10170. classes: [
  10171. "tox-menu",
  10172. "tox-collection"
  10173. ].concat(columns === 1 ? ["tox-collection--list"] : ["tox-collection--grid"])
  10174. },
  10175. components: [Menu.parts.items({
  10176. preprocess: function(items) {
  10177. if (columns !== "auto" && columns > 1) {
  10178. return chunk({
  10179. tag: "div",
  10180. classes: ["tox-collection__group"]
  10181. }, columns)(items);
  10182. } else {
  10183. return preprocessCollection(items, function(_item, i) {
  10184. return initItems[i].type === "separator";
  10185. });
  10186. }
  10187. }
  10188. })]
  10189. };
  10190. };
  10191. var forHorizontalCollection = function(initItems, _hasIcons) {
  10192. return {
  10193. dom: {
  10194. tag: "div",
  10195. classes: [
  10196. "tox-collection",
  10197. "tox-collection--horizontal"
  10198. ]
  10199. },
  10200. components: [Menu.parts.items({
  10201. preprocess: function(items) {
  10202. return preprocessCollection(items, function(_item, i) {
  10203. return initItems[i].type === "separator";
  10204. });
  10205. }
  10206. })]
  10207. };
  10208. };
  10209. var menuHasIcons = function(xs) {
  10210. return exists(xs, function(item2) {
  10211. return "icon" in item2 && item2.icon !== void 0;
  10212. });
  10213. };
  10214. var handleError = function(error2) {
  10215. console.error(formatError(error2));
  10216. console.log(error2);
  10217. return Optional.none();
  10218. };
  10219. var createHorizontalPartialMenuWithAlloyItems = function(value2, _hasIcons, items, _columns, _presets) {
  10220. var structure = forHorizontalCollection(items);
  10221. return {
  10222. value: value2,
  10223. dom: structure.dom,
  10224. components: structure.components,
  10225. items
  10226. };
  10227. };
  10228. var createPartialMenuWithAlloyItems = function(value2, hasIcons, items, columns, presets) {
  10229. if (presets === "color") {
  10230. var structure = forSwatch(columns);
  10231. return {
  10232. value: value2,
  10233. dom: structure.dom,
  10234. components: structure.components,
  10235. items
  10236. };
  10237. }
  10238. if (presets === "normal" && columns === "auto") {
  10239. var structure = forCollection(columns, items);
  10240. return {
  10241. value: value2,
  10242. dom: structure.dom,
  10243. components: structure.components,
  10244. items
  10245. };
  10246. }
  10247. if (presets === "normal" && columns === 1) {
  10248. var structure = forCollection(1, items);
  10249. return {
  10250. value: value2,
  10251. dom: structure.dom,
  10252. components: structure.components,
  10253. items
  10254. };
  10255. }
  10256. if (presets === "normal") {
  10257. var structure = forCollection(columns, items);
  10258. return {
  10259. value: value2,
  10260. dom: structure.dom,
  10261. components: structure.components,
  10262. items
  10263. };
  10264. }
  10265. if (presets === "listpreview" && columns !== "auto") {
  10266. var structure = forToolbar(columns);
  10267. return {
  10268. value: value2,
  10269. dom: structure.dom,
  10270. components: structure.components,
  10271. items
  10272. };
  10273. }
  10274. return {
  10275. value: value2,
  10276. dom: dom$1(hasIcons, columns, presets),
  10277. components,
  10278. items
  10279. };
  10280. };
  10281. var cardImageFields = [
  10282. requiredString("type"),
  10283. requiredString("src"),
  10284. optionString("alt"),
  10285. defaultedArrayOf("classes", [], string)
  10286. ];
  10287. var cardImageSchema = objOf(cardImageFields);
  10288. var cardTextFields = [
  10289. requiredString("type"),
  10290. requiredString("text"),
  10291. optionString("name"),
  10292. defaultedArrayOf("classes", ["tox-collection__item-label"], string)
  10293. ];
  10294. var cardTextSchema = objOf(cardTextFields);
  10295. var itemSchema$1 = valueThunk(function() {
  10296. return choose$2("type", {
  10297. cardimage: cardImageSchema,
  10298. cardtext: cardTextSchema,
  10299. cardcontainer: cardContainerSchema
  10300. });
  10301. });
  10302. var cardContainerSchema = objOf([
  10303. requiredString("type"),
  10304. defaultedString("direction", "horizontal"),
  10305. defaultedString("align", "left"),
  10306. defaultedString("valign", "middle"),
  10307. requiredArrayOf("items", itemSchema$1)
  10308. ]);
  10309. var commonMenuItemFields = [
  10310. defaultedBoolean("disabled", false),
  10311. optionString("text"),
  10312. optionString("shortcut"),
  10313. field$1("value", "value", defaultedThunk(function() {
  10314. return generate$6("menuitem-value");
  10315. }), anyValue()),
  10316. defaulted("meta", {})
  10317. ];
  10318. var cardMenuItemSchema = objOf([
  10319. requiredString("type"),
  10320. optionString("label"),
  10321. requiredArrayOf("items", itemSchema$1),
  10322. defaultedFunction("onSetup", function() {
  10323. return noop;
  10324. }),
  10325. defaultedFunction("onAction", noop)
  10326. ].concat(commonMenuItemFields));
  10327. var createCardMenuItem = function(spec) {
  10328. return asRaw("cardmenuitem", cardMenuItemSchema, spec);
  10329. };
  10330. var choiceMenuItemSchema = objOf([
  10331. requiredString("type"),
  10332. defaultedBoolean("active", false),
  10333. optionString("icon")
  10334. ].concat(commonMenuItemFields));
  10335. var createChoiceMenuItem = function(spec) {
  10336. return asRaw("choicemenuitem", choiceMenuItemSchema, spec);
  10337. };
  10338. var baseFields = [
  10339. requiredString("type"),
  10340. requiredString("fancytype"),
  10341. defaultedFunction("onAction", noop)
  10342. ];
  10343. var insertTableFields = [defaulted("initData", {})].concat(baseFields);
  10344. var colorSwatchFields = [defaultedObjOf("initData", {}, [
  10345. defaultedBoolean("allowCustomColors", true),
  10346. optionArrayOf("colors", anyValue())
  10347. ])].concat(baseFields);
  10348. var fancyMenuItemSchema = choose$1("fancytype", {
  10349. inserttable: insertTableFields,
  10350. colorswatch: colorSwatchFields
  10351. });
  10352. var createFancyMenuItem = function(spec) {
  10353. return asRaw("fancymenuitem", fancyMenuItemSchema, spec);
  10354. };
  10355. var menuItemSchema = objOf([
  10356. requiredString("type"),
  10357. defaultedFunction("onSetup", function() {
  10358. return noop;
  10359. }),
  10360. defaultedFunction("onAction", noop),
  10361. optionString("icon")
  10362. ].concat(commonMenuItemFields));
  10363. var createMenuItem = function(spec) {
  10364. return asRaw("menuitem", menuItemSchema, spec);
  10365. };
  10366. var nestedMenuItemSchema = objOf([
  10367. requiredString("type"),
  10368. requiredFunction("getSubmenuItems"),
  10369. defaultedFunction("onSetup", function() {
  10370. return noop;
  10371. }),
  10372. optionString("icon")
  10373. ].concat(commonMenuItemFields));
  10374. var createNestedMenuItem = function(spec) {
  10375. return asRaw("nestedmenuitem", nestedMenuItemSchema, spec);
  10376. };
  10377. var toggleMenuItemSchema = objOf([
  10378. requiredString("type"),
  10379. optionString("icon"),
  10380. defaultedBoolean("active", false),
  10381. defaultedFunction("onSetup", function() {
  10382. return noop;
  10383. }),
  10384. requiredFunction("onAction")
  10385. ].concat(commonMenuItemFields));
  10386. var createToggleMenuItem = function(spec) {
  10387. return asRaw("togglemenuitem", toggleMenuItemSchema, spec);
  10388. };
  10389. var detectSize = function(comp, margin, selectorClass) {
  10390. var descendants$1 = descendants(comp.element, "." + selectorClass);
  10391. if (descendants$1.length > 0) {
  10392. var columnLength = findIndex$1(descendants$1, function(c) {
  10393. var thisTop = c.dom.getBoundingClientRect().top;
  10394. var cTop = descendants$1[0].dom.getBoundingClientRect().top;
  10395. return Math.abs(thisTop - cTop) > margin;
  10396. }).getOr(descendants$1.length);
  10397. return Optional.some({
  10398. numColumns: columnLength,
  10399. numRows: Math.ceil(descendants$1.length / columnLength)
  10400. });
  10401. } else {
  10402. return Optional.none();
  10403. }
  10404. };
  10405. var namedEvents = function(name2, handlers2) {
  10406. return derive$1([config(name2, handlers2)]);
  10407. };
  10408. var unnamedEvents = function(handlers2) {
  10409. return namedEvents(generate$6("unnamed-events"), handlers2);
  10410. };
  10411. var SimpleBehaviours = {
  10412. namedEvents,
  10413. unnamedEvents
  10414. };
  10415. var ExclusivityChannel = generate$6("tooltip.exclusive");
  10416. var ShowTooltipEvent = generate$6("tooltip.show");
  10417. var HideTooltipEvent = generate$6("tooltip.hide");
  10418. var hideAllExclusive = function(component, _tConfig, _tState) {
  10419. component.getSystem().broadcastOn([ExclusivityChannel], {});
  10420. };
  10421. var setComponents = function(component, tConfig, tState, specs) {
  10422. tState.getTooltip().each(function(tooltip) {
  10423. if (tooltip.getSystem().isConnected()) {
  10424. Replacing.set(tooltip, specs);
  10425. }
  10426. });
  10427. };
  10428. var TooltippingApis = Object.freeze({
  10429. __proto__: null,
  10430. hideAllExclusive,
  10431. setComponents
  10432. });
  10433. var events$9 = function(tooltipConfig, state) {
  10434. var hide = function(comp) {
  10435. state.getTooltip().each(function(p) {
  10436. detach(p);
  10437. tooltipConfig.onHide(comp, p);
  10438. state.clearTooltip();
  10439. });
  10440. state.clearTimer();
  10441. };
  10442. var show2 = function(comp) {
  10443. if (!state.isShowing()) {
  10444. hideAllExclusive(comp);
  10445. var sink = tooltipConfig.lazySink(comp).getOrDie();
  10446. var popup = comp.getSystem().build({
  10447. dom: tooltipConfig.tooltipDom,
  10448. components: tooltipConfig.tooltipComponents,
  10449. events: derive$2(tooltipConfig.mode === "normal" ? [
  10450. run$1(mouseover(), function(_) {
  10451. emit(comp, ShowTooltipEvent);
  10452. }),
  10453. run$1(mouseout(), function(_) {
  10454. emit(comp, HideTooltipEvent);
  10455. })
  10456. ] : []),
  10457. behaviours: derive$1([Replacing.config({})])
  10458. });
  10459. state.setTooltip(popup);
  10460. attach(sink, popup);
  10461. tooltipConfig.onShow(comp, popup);
  10462. Positioning.position(sink, popup, { anchor: tooltipConfig.anchor(comp) });
  10463. }
  10464. };
  10465. return derive$2(flatten([
  10466. [
  10467. run$1(ShowTooltipEvent, function(comp) {
  10468. state.resetTimer(function() {
  10469. show2(comp);
  10470. }, tooltipConfig.delay);
  10471. }),
  10472. run$1(HideTooltipEvent, function(comp) {
  10473. state.resetTimer(function() {
  10474. hide(comp);
  10475. }, tooltipConfig.delay);
  10476. }),
  10477. run$1(receive(), function(comp, message) {
  10478. var receivingData = message;
  10479. if (!receivingData.universal) {
  10480. if (contains$2(receivingData.channels, ExclusivityChannel)) {
  10481. hide(comp);
  10482. }
  10483. }
  10484. }),
  10485. runOnDetached(function(comp) {
  10486. hide(comp);
  10487. })
  10488. ],
  10489. tooltipConfig.mode === "normal" ? [
  10490. run$1(focusin(), function(comp) {
  10491. emit(comp, ShowTooltipEvent);
  10492. }),
  10493. run$1(postBlur(), function(comp) {
  10494. emit(comp, HideTooltipEvent);
  10495. }),
  10496. run$1(mouseover(), function(comp) {
  10497. emit(comp, ShowTooltipEvent);
  10498. }),
  10499. run$1(mouseout(), function(comp) {
  10500. emit(comp, HideTooltipEvent);
  10501. })
  10502. ] : [
  10503. run$1(highlight$1(), function(comp, _se) {
  10504. emit(comp, ShowTooltipEvent);
  10505. }),
  10506. run$1(dehighlight$1(), function(comp) {
  10507. emit(comp, HideTooltipEvent);
  10508. })
  10509. ]
  10510. ]));
  10511. };
  10512. var ActiveTooltipping = Object.freeze({
  10513. __proto__: null,
  10514. events: events$9
  10515. });
  10516. var TooltippingSchema = [
  10517. required$1("lazySink"),
  10518. required$1("tooltipDom"),
  10519. defaulted("exclusive", true),
  10520. defaulted("tooltipComponents", []),
  10521. defaulted("delay", 300),
  10522. defaultedStringEnum("mode", "normal", [
  10523. "normal",
  10524. "follow-highlight"
  10525. ]),
  10526. defaulted("anchor", function(comp) {
  10527. return {
  10528. type: "hotspot",
  10529. hotspot: comp,
  10530. layouts: {
  10531. onLtr: constant$1([
  10532. south$2,
  10533. north$2,
  10534. southeast$2,
  10535. northeast$2,
  10536. southwest$2,
  10537. northwest$2
  10538. ]),
  10539. onRtl: constant$1([
  10540. south$2,
  10541. north$2,
  10542. southeast$2,
  10543. northeast$2,
  10544. southwest$2,
  10545. northwest$2
  10546. ])
  10547. }
  10548. };
  10549. }),
  10550. onHandler("onHide"),
  10551. onHandler("onShow")
  10552. ];
  10553. var init$b = function() {
  10554. var timer = value$1();
  10555. var popup = value$1();
  10556. var clearTimer = function() {
  10557. timer.on(clearTimeout);
  10558. };
  10559. var resetTimer = function(f, delay) {
  10560. clearTimer();
  10561. timer.set(setTimeout(f, delay));
  10562. };
  10563. var readState = constant$1("not-implemented");
  10564. return nu$8({
  10565. getTooltip: popup.get,
  10566. isShowing: popup.isSet,
  10567. setTooltip: popup.set,
  10568. clearTooltip: popup.clear,
  10569. clearTimer,
  10570. resetTimer,
  10571. readState
  10572. });
  10573. };
  10574. var TooltippingState = Object.freeze({
  10575. __proto__: null,
  10576. init: init$b
  10577. });
  10578. var Tooltipping = create$8({
  10579. fields: TooltippingSchema,
  10580. name: "tooltipping",
  10581. active: ActiveTooltipping,
  10582. state: TooltippingState,
  10583. apis: TooltippingApis
  10584. });
  10585. var escape = function(text2) {
  10586. return text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  10587. };
  10588. var global$b = tinymce.util.Tools.resolve("tinymce.dom.DOMUtils");
  10589. var global$a = tinymce.util.Tools.resolve("tinymce.EditorManager");
  10590. var getSkinUrl = function(editor) {
  10591. var skin = editor.getParam("skin");
  10592. var skinUrl = editor.getParam("skin_url");
  10593. if (skin !== false) {
  10594. var skinName = skin ? skin : "oxide";
  10595. if (skinUrl) {
  10596. skinUrl = editor.documentBaseURI.toAbsolute(skinUrl);
  10597. } else {
  10598. skinUrl = global$a.baseURL + "/skins/ui/" + skinName;
  10599. }
  10600. }
  10601. return skinUrl;
  10602. };
  10603. var isReadOnly = function(editor) {
  10604. return editor.getParam("readonly", false, "boolean");
  10605. };
  10606. var isSkinDisabled = function(editor) {
  10607. return editor.getParam("skin") === false;
  10608. };
  10609. var getHeightSetting = function(editor) {
  10610. return editor.getParam("height", Math.max(editor.getElement().offsetHeight, 200));
  10611. };
  10612. var getWidthSetting = function(editor) {
  10613. return editor.getParam("width", global$b.DOM.getStyle(editor.getElement(), "width"));
  10614. };
  10615. var getMinWidthSetting = function(editor) {
  10616. return Optional.from(editor.getParam("min_width")).filter(isNumber);
  10617. };
  10618. var getMinHeightSetting = function(editor) {
  10619. return Optional.from(editor.getParam("min_height")).filter(isNumber);
  10620. };
  10621. var getMaxWidthSetting = function(editor) {
  10622. return Optional.from(editor.getParam("max_width")).filter(isNumber);
  10623. };
  10624. var getMaxHeightSetting = function(editor) {
  10625. return Optional.from(editor.getParam("max_height")).filter(isNumber);
  10626. };
  10627. var getUserStyleFormats = function(editor) {
  10628. return Optional.from(editor.getParam("style_formats")).filter(isArray);
  10629. };
  10630. var isMergeStyleFormats = function(editor) {
  10631. return editor.getParam("style_formats_merge", false, "boolean");
  10632. };
  10633. var getLineHeightFormats = function(editor) {
  10634. return editor.getParam("lineheight_formats", "1 1.1 1.2 1.3 1.4 1.5 2", "string").split(" ");
  10635. };
  10636. var getContentLanguages = function(editor) {
  10637. return editor.getParam("content_langs", void 0, "array");
  10638. };
  10639. var getRemovedMenuItems = function(editor) {
  10640. return editor.getParam("removed_menuitems", "");
  10641. };
  10642. var isMenubarEnabled = function(editor) {
  10643. return editor.getParam("menubar", true, "boolean") !== false;
  10644. };
  10645. var isToolbarEnabled = function(editor) {
  10646. var toolbar = editor.getParam("toolbar", true);
  10647. var isToolbarTrue = toolbar === true;
  10648. var isToolbarString = isString(toolbar);
  10649. var isToolbarObjectArray = isArray(toolbar) && toolbar.length > 0;
  10650. return !isMultipleToolbars(editor) && (isToolbarObjectArray || isToolbarString || isToolbarTrue);
  10651. };
  10652. var getMultipleToolbarsSetting = function(editor) {
  10653. var toolbars = range$2(9, function(num) {
  10654. return editor.getParam("toolbar" + (num + 1), false, "string");
  10655. });
  10656. var toolbarArray = filter$2(toolbars, function(toolbar) {
  10657. return typeof toolbar === "string";
  10658. });
  10659. return toolbarArray.length > 0 ? Optional.some(toolbarArray) : Optional.none();
  10660. };
  10661. var isMultipleToolbars = function(editor) {
  10662. return getMultipleToolbarsSetting(editor).fold(function() {
  10663. var toolbar = editor.getParam("toolbar", [], "string[]");
  10664. return toolbar.length > 0;
  10665. }, always);
  10666. };
  10667. var ToolbarMode;
  10668. (function(ToolbarMode2) {
  10669. ToolbarMode2["default"] = "wrap";
  10670. ToolbarMode2["floating"] = "floating";
  10671. ToolbarMode2["sliding"] = "sliding";
  10672. ToolbarMode2["scrolling"] = "scrolling";
  10673. })(ToolbarMode || (ToolbarMode = {}));
  10674. var getToolbarMode = function(editor) {
  10675. return editor.getParam("toolbar_mode", "", "string");
  10676. };
  10677. var ToolbarLocation;
  10678. (function(ToolbarLocation2) {
  10679. ToolbarLocation2["auto"] = "auto";
  10680. ToolbarLocation2["top"] = "top";
  10681. ToolbarLocation2["bottom"] = "bottom";
  10682. })(ToolbarLocation || (ToolbarLocation = {}));
  10683. var getToolbarGroups = function(editor) {
  10684. return editor.getParam("toolbar_groups", {}, "object");
  10685. };
  10686. var getToolbarLocation = function(editor) {
  10687. return editor.getParam("toolbar_location", ToolbarLocation.auto, "string");
  10688. };
  10689. var isToolbarLocationBottom = function(editor) {
  10690. return getToolbarLocation(editor) === ToolbarLocation.bottom;
  10691. };
  10692. var fixedContainerSelector = function(editor) {
  10693. return editor.getParam("fixed_toolbar_container", "", "string");
  10694. };
  10695. var fixedToolbarContainerTarget = function(editor) {
  10696. return editor.getParam("fixed_toolbar_container_target");
  10697. };
  10698. var isToolbarPersist = function(editor) {
  10699. return editor.getParam("toolbar_persist", false, "boolean");
  10700. };
  10701. var fixedContainerTarget = function(editor) {
  10702. if (!editor.inline) {
  10703. return Optional.none();
  10704. }
  10705. var selector = fixedContainerSelector(editor);
  10706. if (selector.length > 0) {
  10707. return descendant(body(), selector);
  10708. }
  10709. var element2 = fixedToolbarContainerTarget(editor);
  10710. if (isNonNullable(element2)) {
  10711. return Optional.some(SugarElement.fromDom(element2));
  10712. }
  10713. return Optional.none();
  10714. };
  10715. var useFixedContainer = function(editor) {
  10716. return editor.inline && fixedContainerTarget(editor).isSome();
  10717. };
  10718. var getUiContainer = function(editor) {
  10719. var fixedContainer = fixedContainerTarget(editor);
  10720. return fixedContainer.getOrThunk(function() {
  10721. return getContentContainer(getRootNode(SugarElement.fromDom(editor.getElement())));
  10722. });
  10723. };
  10724. var isDistractionFree = function(editor) {
  10725. return editor.inline && !isMenubarEnabled(editor) && !isToolbarEnabled(editor) && !isMultipleToolbars(editor);
  10726. };
  10727. var isStickyToolbar = function(editor) {
  10728. var isStickyToolbar2 = editor.getParam("toolbar_sticky", false, "boolean");
  10729. return (isStickyToolbar2 || editor.inline) && !useFixedContainer(editor) && !isDistractionFree(editor);
  10730. };
  10731. var getStickyToolbarOffset = function(editor) {
  10732. return editor.getParam("toolbar_sticky_offset", 0, "number");
  10733. };
  10734. var isDraggableModal$1 = function(editor) {
  10735. return editor.getParam("draggable_modal", false, "boolean");
  10736. };
  10737. var getMenus = function(editor) {
  10738. var menu2 = editor.getParam("menu");
  10739. if (menu2) {
  10740. return map$1(menu2, function(menu3) {
  10741. return __assign(__assign({}, menu3), { items: menu3.items });
  10742. });
  10743. } else {
  10744. return {};
  10745. }
  10746. };
  10747. var getMenubar = function(editor) {
  10748. return editor.getParam("menubar");
  10749. };
  10750. var getToolbar = function(editor) {
  10751. return editor.getParam("toolbar", true);
  10752. };
  10753. var getFilePickerCallback = function(editor) {
  10754. return editor.getParam("file_picker_callback");
  10755. };
  10756. var getFilePickerTypes = function(editor) {
  10757. return editor.getParam("file_picker_types");
  10758. };
  10759. var getFileBrowserCallbackTypes = function(editor) {
  10760. return editor.getParam("file_browser_callback_types");
  10761. };
  10762. var noTypeaheadUrls = function(editor) {
  10763. return editor.getParam("typeahead_urls") === false;
  10764. };
  10765. var getAnchorTop = function(editor) {
  10766. return editor.getParam("anchor_top", "#top");
  10767. };
  10768. var getAnchorBottom = function(editor) {
  10769. return editor.getParam("anchor_bottom", "#bottom");
  10770. };
  10771. var getFilePickerValidatorHandler = function(editor) {
  10772. var handler = editor.getParam("file_picker_validator_handler", void 0, "function");
  10773. if (handler === void 0) {
  10774. return editor.getParam("filepicker_validator_handler", void 0, "function");
  10775. } else {
  10776. return handler;
  10777. }
  10778. };
  10779. var ReadOnlyChannel = "silver.readonly";
  10780. var ReadOnlyDataSchema = objOf([requiredBoolean("readonly")]);
  10781. var broadcastReadonly = function(uiComponents, readonly) {
  10782. var outerContainer = uiComponents.outerContainer;
  10783. var target = outerContainer.element;
  10784. if (readonly) {
  10785. uiComponents.mothership.broadcastOn([dismissPopups()], { target });
  10786. uiComponents.uiMothership.broadcastOn([dismissPopups()], { target });
  10787. }
  10788. uiComponents.mothership.broadcastOn([ReadOnlyChannel], { readonly });
  10789. uiComponents.uiMothership.broadcastOn([ReadOnlyChannel], { readonly });
  10790. };
  10791. var setupReadonlyModeSwitch = function(editor, uiComponents) {
  10792. editor.on("init", function() {
  10793. if (editor.mode.isReadOnly()) {
  10794. broadcastReadonly(uiComponents, true);
  10795. }
  10796. });
  10797. editor.on("SwitchMode", function() {
  10798. return broadcastReadonly(uiComponents, editor.mode.isReadOnly());
  10799. });
  10800. if (isReadOnly(editor)) {
  10801. editor.setMode("readonly");
  10802. }
  10803. };
  10804. var receivingConfig = function() {
  10805. var _a2;
  10806. return Receiving.config({
  10807. channels: (_a2 = {}, _a2[ReadOnlyChannel] = {
  10808. schema: ReadOnlyDataSchema,
  10809. onReceive: function(comp, data) {
  10810. Disabling.set(comp, data.readonly);
  10811. }
  10812. }, _a2)
  10813. });
  10814. };
  10815. var item = function(disabled) {
  10816. return Disabling.config({
  10817. disabled,
  10818. disableClass: "tox-collection__item--state-disabled"
  10819. });
  10820. };
  10821. var button = function(disabled) {
  10822. return Disabling.config({ disabled });
  10823. };
  10824. var splitButton = function(disabled) {
  10825. return Disabling.config({
  10826. disabled,
  10827. disableClass: "tox-tbtn--disabled"
  10828. });
  10829. };
  10830. var toolbarButton = function(disabled) {
  10831. return Disabling.config({
  10832. disabled,
  10833. disableClass: "tox-tbtn--disabled",
  10834. useNative: false
  10835. });
  10836. };
  10837. var DisablingConfigs = {
  10838. item,
  10839. button,
  10840. splitButton,
  10841. toolbarButton
  10842. };
  10843. var runWithApi = function(info, comp) {
  10844. var api2 = info.getApi(comp);
  10845. return function(f) {
  10846. f(api2);
  10847. };
  10848. };
  10849. var onControlAttached = function(info, editorOffCell) {
  10850. return runOnAttached(function(comp) {
  10851. var run2 = runWithApi(info, comp);
  10852. run2(function(api2) {
  10853. var onDestroy = info.onSetup(api2);
  10854. if (isFunction(onDestroy)) {
  10855. editorOffCell.set(onDestroy);
  10856. }
  10857. });
  10858. });
  10859. };
  10860. var onControlDetached = function(getApi2, editorOffCell) {
  10861. return runOnDetached(function(comp) {
  10862. return runWithApi(getApi2, comp)(editorOffCell.get());
  10863. });
  10864. };
  10865. var _a$1;
  10866. var onMenuItemExecute = function(info, itemResponse) {
  10867. return runOnExecute$1(function(comp, simulatedEvent) {
  10868. runWithApi(info, comp)(info.onAction);
  10869. if (!info.triggersSubmenu && itemResponse === ItemResponse$1.CLOSE_ON_EXECUTE) {
  10870. emit(comp, sandboxClose());
  10871. simulatedEvent.stop();
  10872. }
  10873. });
  10874. };
  10875. var menuItemEventOrder = (_a$1 = {}, _a$1[execute$5()] = [
  10876. "disabling",
  10877. "alloy.base.behaviour",
  10878. "toggling",
  10879. "item-events"
  10880. ], _a$1);
  10881. var componentRenderPipeline = cat;
  10882. var renderCommonItem = function(spec, structure, itemResponse, providersbackstage) {
  10883. var editorOffCell = Cell(noop);
  10884. return {
  10885. type: "item",
  10886. dom: structure.dom,
  10887. components: componentRenderPipeline(structure.optComponents),
  10888. data: spec.data,
  10889. eventOrder: menuItemEventOrder,
  10890. hasSubmenu: spec.triggersSubmenu,
  10891. itemBehaviours: derive$1([
  10892. config("item-events", [
  10893. onMenuItemExecute(spec, itemResponse),
  10894. onControlAttached(spec, editorOffCell),
  10895. onControlDetached(spec, editorOffCell)
  10896. ]),
  10897. DisablingConfigs.item(function() {
  10898. return spec.disabled || providersbackstage.isDisabled();
  10899. }),
  10900. receivingConfig(),
  10901. Replacing.config({})
  10902. ].concat(spec.itemBehaviours))
  10903. };
  10904. };
  10905. var buildData = function(source) {
  10906. return {
  10907. value: source.value,
  10908. meta: __assign({ text: source.text.getOr("") }, source.meta)
  10909. };
  10910. };
  10911. var global$9 = tinymce.util.Tools.resolve("tinymce.Env");
  10912. var convertText = function(source) {
  10913. var mac = {
  10914. alt: "&#x2325;",
  10915. ctrl: "&#x2303;",
  10916. shift: "&#x21E7;",
  10917. meta: "&#x2318;",
  10918. access: "&#x2303;&#x2325;"
  10919. };
  10920. var other = {
  10921. meta: "Ctrl",
  10922. access: "Shift+Alt"
  10923. };
  10924. var replace = global$9.mac ? mac : other;
  10925. var shortcut = source.split("+");
  10926. var updated = map$2(shortcut, function(segment) {
  10927. var search2 = segment.toLowerCase().trim();
  10928. return has$2(replace, search2) ? replace[search2] : segment;
  10929. });
  10930. return global$9.mac ? updated.join("") : updated.join("+");
  10931. };
  10932. var renderIcon$1 = function(name2, icons, classes2) {
  10933. if (classes2 === void 0) {
  10934. classes2 = [iconClass];
  10935. }
  10936. return render$3(name2, {
  10937. tag: "div",
  10938. classes: classes2
  10939. }, icons);
  10940. };
  10941. var renderText = function(text2) {
  10942. return {
  10943. dom: {
  10944. tag: "div",
  10945. classes: [textClass]
  10946. },
  10947. components: [text$1(global$e.translate(text2))]
  10948. };
  10949. };
  10950. var renderHtml = function(html2, classes2) {
  10951. return {
  10952. dom: {
  10953. tag: "div",
  10954. classes: classes2,
  10955. innerHtml: html2
  10956. }
  10957. };
  10958. };
  10959. var renderStyledText = function(style, text2) {
  10960. return {
  10961. dom: {
  10962. tag: "div",
  10963. classes: [textClass]
  10964. },
  10965. components: [{
  10966. dom: {
  10967. tag: style.tag,
  10968. styles: style.styles
  10969. },
  10970. components: [text$1(global$e.translate(text2))]
  10971. }]
  10972. };
  10973. };
  10974. var renderShortcut = function(shortcut) {
  10975. return {
  10976. dom: {
  10977. tag: "div",
  10978. classes: [accessoryClass],
  10979. innerHtml: convertText(shortcut)
  10980. }
  10981. };
  10982. };
  10983. var renderCheckmark = function(icons) {
  10984. return renderIcon$1("checkmark", icons, [checkmarkClass]);
  10985. };
  10986. var renderSubmenuCaret = function(icons) {
  10987. return renderIcon$1("chevron-right", icons, [caretClass]);
  10988. };
  10989. var renderDownwardsCaret = function(icons) {
  10990. return renderIcon$1("chevron-down", icons, [caretClass]);
  10991. };
  10992. var renderContainer = function(container, components2) {
  10993. var directionClass = container.direction === "vertical" ? containerColumnClass : containerRowClass;
  10994. var alignClass = container.align === "left" ? containerAlignLeftClass : containerAlignRightClass;
  10995. var getValignClass = function() {
  10996. switch (container.valign) {
  10997. case "top":
  10998. return containerValignTopClass;
  10999. case "middle":
  11000. return containerValignMiddleClass;
  11001. case "bottom":
  11002. return containerValignBottomClass;
  11003. }
  11004. };
  11005. return {
  11006. dom: {
  11007. tag: "div",
  11008. classes: [
  11009. containerClass,
  11010. directionClass,
  11011. alignClass,
  11012. getValignClass()
  11013. ]
  11014. },
  11015. components: components2
  11016. };
  11017. };
  11018. var renderImage = function(src, classes2, alt) {
  11019. return {
  11020. dom: {
  11021. tag: "img",
  11022. classes: classes2,
  11023. attributes: {
  11024. src,
  11025. alt: alt.getOr("")
  11026. }
  11027. }
  11028. };
  11029. };
  11030. var renderColorStructure = function(item2, providerBackstage, fallbackIcon) {
  11031. var colorPickerCommand = "custom";
  11032. var removeColorCommand = "remove";
  11033. var itemText = item2.ariaLabel;
  11034. var itemValue = item2.value;
  11035. var iconSvg = item2.iconContent.map(function(name2) {
  11036. return getOr(name2, providerBackstage.icons, fallbackIcon);
  11037. });
  11038. var getDom = function() {
  11039. var common = colorClass;
  11040. var icon = iconSvg.getOr("");
  11041. var attributes = itemText.map(function(text2) {
  11042. return { title: providerBackstage.translate(text2) };
  11043. }).getOr({});
  11044. var baseDom = {
  11045. tag: "div",
  11046. attributes,
  11047. classes: [common]
  11048. };
  11049. if (itemValue === colorPickerCommand) {
  11050. return __assign(__assign({}, baseDom), {
  11051. tag: "button",
  11052. classes: __spreadArray(__spreadArray([], baseDom.classes, true), ["tox-swatches__picker-btn"], false),
  11053. innerHtml: icon
  11054. });
  11055. } else if (itemValue === removeColorCommand) {
  11056. return __assign(__assign({}, baseDom), {
  11057. classes: __spreadArray(__spreadArray([], baseDom.classes, true), ["tox-swatch--remove"], false),
  11058. innerHtml: icon
  11059. });
  11060. } else {
  11061. return __assign(__assign({}, baseDom), {
  11062. attributes: __assign(__assign({}, baseDom.attributes), { "data-mce-color": itemValue }),
  11063. styles: { "background-color": itemValue }
  11064. });
  11065. }
  11066. };
  11067. return {
  11068. dom: getDom(),
  11069. optComponents: []
  11070. };
  11071. };
  11072. var renderItemDomStructure = function(ariaLabel) {
  11073. var domTitle = ariaLabel.map(function(label) {
  11074. return { attributes: { title: global$e.translate(label) } };
  11075. }).getOr({});
  11076. return __assign({
  11077. tag: "div",
  11078. classes: [
  11079. navClass,
  11080. selectableClass
  11081. ]
  11082. }, domTitle);
  11083. };
  11084. var renderNormalItemStructure = function(info, providersBackstage, renderIcons, fallbackIcon) {
  11085. var iconSpec = {
  11086. tag: "div",
  11087. classes: [iconClass]
  11088. };
  11089. var renderIcon2 = function(iconName) {
  11090. return render$3(iconName, iconSpec, providersBackstage.icons, fallbackIcon);
  11091. };
  11092. var renderEmptyIcon = function() {
  11093. return Optional.some({ dom: iconSpec });
  11094. };
  11095. var leftIcon = renderIcons ? info.iconContent.map(renderIcon2).orThunk(renderEmptyIcon) : Optional.none();
  11096. var checkmark = info.checkMark;
  11097. var textRender = Optional.from(info.meta).fold(function() {
  11098. return renderText;
  11099. }, function(meta) {
  11100. return has$2(meta, "style") ? curry(renderStyledText, meta.style) : renderText;
  11101. });
  11102. var content = info.htmlContent.fold(function() {
  11103. return info.textContent.map(textRender);
  11104. }, function(html2) {
  11105. return Optional.some(renderHtml(html2, [textClass]));
  11106. });
  11107. var menuItem = {
  11108. dom: renderItemDomStructure(info.ariaLabel),
  11109. optComponents: [
  11110. leftIcon,
  11111. content,
  11112. info.shortcutContent.map(renderShortcut),
  11113. checkmark,
  11114. info.caret
  11115. ]
  11116. };
  11117. return menuItem;
  11118. };
  11119. var renderItemStructure = function(info, providersBackstage, renderIcons, fallbackIcon) {
  11120. if (fallbackIcon === void 0) {
  11121. fallbackIcon = Optional.none();
  11122. }
  11123. if (info.presets === "color") {
  11124. return renderColorStructure(info, providersBackstage, fallbackIcon);
  11125. } else {
  11126. return renderNormalItemStructure(info, providersBackstage, renderIcons, fallbackIcon);
  11127. }
  11128. };
  11129. var tooltipBehaviour = function(meta, sharedBackstage) {
  11130. return get$e(meta, "tooltipWorker").map(function(tooltipWorker) {
  11131. return [Tooltipping.config({
  11132. lazySink: sharedBackstage.getSink,
  11133. tooltipDom: {
  11134. tag: "div",
  11135. classes: ["tox-tooltip-worker-container"]
  11136. },
  11137. tooltipComponents: [],
  11138. anchor: function(comp) {
  11139. return {
  11140. type: "submenu",
  11141. item: comp,
  11142. overrides: { maxHeightFunction: expandable$1 }
  11143. };
  11144. },
  11145. mode: "follow-highlight",
  11146. onShow: function(component, _tooltip) {
  11147. tooltipWorker(function(elm) {
  11148. Tooltipping.setComponents(component, [external$2({ element: SugarElement.fromDom(elm) })]);
  11149. });
  11150. }
  11151. })];
  11152. }).getOr([]);
  11153. };
  11154. var encodeText = function(text2) {
  11155. return global$b.DOM.encode(text2);
  11156. };
  11157. var replaceText = function(text2, matchText) {
  11158. var translated = global$e.translate(text2);
  11159. var encoded = encodeText(translated);
  11160. if (matchText.length > 0) {
  11161. var escapedMatchRegex = new RegExp(escape(matchText), "gi");
  11162. return encoded.replace(escapedMatchRegex, function(match) {
  11163. return '<span class="tox-autocompleter-highlight">' + match + "</span>";
  11164. });
  11165. } else {
  11166. return encoded;
  11167. }
  11168. };
  11169. var renderAutocompleteItem = function(spec, matchText, useText, presets, onItemValueHandler, itemResponse, sharedBackstage, renderIcons) {
  11170. if (renderIcons === void 0) {
  11171. renderIcons = true;
  11172. }
  11173. var structure = renderItemStructure({
  11174. presets,
  11175. textContent: Optional.none(),
  11176. htmlContent: useText ? spec.text.map(function(text2) {
  11177. return replaceText(text2, matchText);
  11178. }) : Optional.none(),
  11179. ariaLabel: spec.text,
  11180. iconContent: spec.icon,
  11181. shortcutContent: Optional.none(),
  11182. checkMark: Optional.none(),
  11183. caret: Optional.none(),
  11184. value: spec.value
  11185. }, sharedBackstage.providers, renderIcons, spec.icon);
  11186. return renderCommonItem({
  11187. data: buildData(spec),
  11188. disabled: spec.disabled,
  11189. getApi: constant$1({}),
  11190. onAction: function(_api) {
  11191. return onItemValueHandler(spec.value, spec.meta);
  11192. },
  11193. onSetup: constant$1(noop),
  11194. triggersSubmenu: false,
  11195. itemBehaviours: tooltipBehaviour(spec.meta, sharedBackstage)
  11196. }, structure, itemResponse, sharedBackstage.providers);
  11197. };
  11198. var render$2 = function(items, extras) {
  11199. return map$2(items, function(item2) {
  11200. switch (item2.type) {
  11201. case "cardcontainer":
  11202. return renderContainer(item2, render$2(item2.items, extras));
  11203. case "cardimage":
  11204. return renderImage(item2.src, item2.classes, item2.alt);
  11205. case "cardtext":
  11206. var shouldHighlight = item2.name.exists(function(name2) {
  11207. return contains$2(extras.cardText.highlightOn, name2);
  11208. });
  11209. var matchText = shouldHighlight ? Optional.from(extras.cardText.matchText).getOr("") : "";
  11210. return renderHtml(replaceText(item2.text, matchText), item2.classes);
  11211. }
  11212. });
  11213. };
  11214. var renderCardMenuItem = function(spec, itemResponse, sharedBackstage, extras) {
  11215. var getApi2 = function(component) {
  11216. return {
  11217. isDisabled: function() {
  11218. return Disabling.isDisabled(component);
  11219. },
  11220. setDisabled: function(state) {
  11221. Disabling.set(component, state);
  11222. each$1(descendants(component.element, "*"), function(elm) {
  11223. component.getSystem().getByDom(elm).each(function(comp) {
  11224. if (comp.hasConfigured(Disabling)) {
  11225. Disabling.set(comp, state);
  11226. }
  11227. });
  11228. });
  11229. }
  11230. };
  11231. };
  11232. var structure = {
  11233. dom: renderItemDomStructure(spec.label),
  11234. optComponents: [Optional.some({
  11235. dom: {
  11236. tag: "div",
  11237. classes: [
  11238. containerClass,
  11239. containerRowClass
  11240. ]
  11241. },
  11242. components: render$2(spec.items, extras)
  11243. })]
  11244. };
  11245. return renderCommonItem({
  11246. data: buildData(__assign({ text: Optional.none() }, spec)),
  11247. disabled: spec.disabled,
  11248. getApi: getApi2,
  11249. onAction: spec.onAction,
  11250. onSetup: spec.onSetup,
  11251. triggersSubmenu: false,
  11252. itemBehaviours: Optional.from(extras.itemBehaviours).getOr([])
  11253. }, structure, itemResponse, sharedBackstage.providers);
  11254. };
  11255. var renderChoiceItem = function(spec, useText, presets, onItemValueHandler, isSelected, itemResponse, providersBackstage, renderIcons) {
  11256. if (renderIcons === void 0) {
  11257. renderIcons = true;
  11258. }
  11259. var getApi2 = function(component) {
  11260. return {
  11261. setActive: function(state) {
  11262. Toggling.set(component, state);
  11263. },
  11264. isActive: function() {
  11265. return Toggling.isOn(component);
  11266. },
  11267. isDisabled: function() {
  11268. return Disabling.isDisabled(component);
  11269. },
  11270. setDisabled: function(state) {
  11271. return Disabling.set(component, state);
  11272. }
  11273. };
  11274. };
  11275. var structure = renderItemStructure({
  11276. presets,
  11277. textContent: useText ? spec.text : Optional.none(),
  11278. htmlContent: Optional.none(),
  11279. ariaLabel: spec.text,
  11280. iconContent: spec.icon,
  11281. shortcutContent: useText ? spec.shortcut : Optional.none(),
  11282. checkMark: useText ? Optional.some(renderCheckmark(providersBackstage.icons)) : Optional.none(),
  11283. caret: Optional.none(),
  11284. value: spec.value
  11285. }, providersBackstage, renderIcons);
  11286. return deepMerge(renderCommonItem({
  11287. data: buildData(spec),
  11288. disabled: spec.disabled,
  11289. getApi: getApi2,
  11290. onAction: function(_api) {
  11291. return onItemValueHandler(spec.value);
  11292. },
  11293. onSetup: function(api2) {
  11294. api2.setActive(isSelected);
  11295. return noop;
  11296. },
  11297. triggersSubmenu: false,
  11298. itemBehaviours: []
  11299. }, structure, itemResponse, providersBackstage), {
  11300. toggling: {
  11301. toggleClass: tickedClass,
  11302. toggleOnExecute: false,
  11303. selected: spec.active
  11304. }
  11305. });
  11306. };
  11307. var parts$f = generate$3(owner$2(), parts$h());
  11308. var hexColour = function(value2) {
  11309. return { value: value2 };
  11310. };
  11311. var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  11312. var longformRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
  11313. var isHexString = function(hex) {
  11314. return shorthandRegex.test(hex) || longformRegex.test(hex);
  11315. };
  11316. var normalizeHex = function(hex) {
  11317. return removeLeading(hex, "#").toUpperCase();
  11318. };
  11319. var fromString$1 = function(hex) {
  11320. return isHexString(hex) ? Optional.some({ value: normalizeHex(hex) }) : Optional.none();
  11321. };
  11322. var getLongForm = function(hex) {
  11323. var hexString = hex.value.replace(shorthandRegex, function(m, r2, g, b2) {
  11324. return r2 + r2 + g + g + b2 + b2;
  11325. });
  11326. return { value: hexString };
  11327. };
  11328. var extractValues = function(hex) {
  11329. var longForm = getLongForm(hex);
  11330. var splitForm = longformRegex.exec(longForm.value);
  11331. return splitForm === null ? [
  11332. "FFFFFF",
  11333. "FF",
  11334. "FF",
  11335. "FF"
  11336. ] : splitForm;
  11337. };
  11338. var toHex = function(component) {
  11339. var hex = component.toString(16);
  11340. return (hex.length === 1 ? "0" + hex : hex).toUpperCase();
  11341. };
  11342. var fromRgba = function(rgbaColour2) {
  11343. var value2 = toHex(rgbaColour2.red) + toHex(rgbaColour2.green) + toHex(rgbaColour2.blue);
  11344. return hexColour(value2);
  11345. };
  11346. var min = Math.min;
  11347. var max = Math.max;
  11348. var round$1 = Math.round;
  11349. var rgbRegex = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)/;
  11350. var rgbaRegex = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d?(?:\.\d+)?)\)/;
  11351. var rgbaColour = function(red2, green, blue, alpha) {
  11352. return {
  11353. red: red2,
  11354. green,
  11355. blue,
  11356. alpha
  11357. };
  11358. };
  11359. var isRgbaComponent = function(value2) {
  11360. var num = parseInt(value2, 10);
  11361. return num.toString() === value2 && num >= 0 && num <= 255;
  11362. };
  11363. var fromHsv = function(hsv) {
  11364. var r2;
  11365. var g;
  11366. var b2;
  11367. var hue = (hsv.hue || 0) % 360;
  11368. var saturation = hsv.saturation / 100;
  11369. var brightness2 = hsv.value / 100;
  11370. saturation = max(0, min(saturation, 1));
  11371. brightness2 = max(0, min(brightness2, 1));
  11372. if (saturation === 0) {
  11373. r2 = g = b2 = round$1(255 * brightness2);
  11374. return rgbaColour(r2, g, b2, 1);
  11375. }
  11376. var side = hue / 60;
  11377. var chroma = brightness2 * saturation;
  11378. var x = chroma * (1 - Math.abs(side % 2 - 1));
  11379. var match = brightness2 - chroma;
  11380. switch (Math.floor(side)) {
  11381. case 0:
  11382. r2 = chroma;
  11383. g = x;
  11384. b2 = 0;
  11385. break;
  11386. case 1:
  11387. r2 = x;
  11388. g = chroma;
  11389. b2 = 0;
  11390. break;
  11391. case 2:
  11392. r2 = 0;
  11393. g = chroma;
  11394. b2 = x;
  11395. break;
  11396. case 3:
  11397. r2 = 0;
  11398. g = x;
  11399. b2 = chroma;
  11400. break;
  11401. case 4:
  11402. r2 = x;
  11403. g = 0;
  11404. b2 = chroma;
  11405. break;
  11406. case 5:
  11407. r2 = chroma;
  11408. g = 0;
  11409. b2 = x;
  11410. break;
  11411. default:
  11412. r2 = g = b2 = 0;
  11413. }
  11414. r2 = round$1(255 * (r2 + match));
  11415. g = round$1(255 * (g + match));
  11416. b2 = round$1(255 * (b2 + match));
  11417. return rgbaColour(r2, g, b2, 1);
  11418. };
  11419. var fromHex = function(hexColour2) {
  11420. var result = extractValues(hexColour2);
  11421. var red2 = parseInt(result[1], 16);
  11422. var green = parseInt(result[2], 16);
  11423. var blue = parseInt(result[3], 16);
  11424. return rgbaColour(red2, green, blue, 1);
  11425. };
  11426. var fromStringValues = function(red2, green, blue, alpha) {
  11427. var r2 = parseInt(red2, 10);
  11428. var g = parseInt(green, 10);
  11429. var b2 = parseInt(blue, 10);
  11430. var a = parseFloat(alpha);
  11431. return rgbaColour(r2, g, b2, a);
  11432. };
  11433. var fromString = function(rgbaString) {
  11434. if (rgbaString === "transparent") {
  11435. return Optional.some(rgbaColour(0, 0, 0, 0));
  11436. }
  11437. var rgbMatch = rgbRegex.exec(rgbaString);
  11438. if (rgbMatch !== null) {
  11439. return Optional.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], "1"));
  11440. }
  11441. var rgbaMatch = rgbaRegex.exec(rgbaString);
  11442. if (rgbaMatch !== null) {
  11443. return Optional.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
  11444. }
  11445. return Optional.none();
  11446. };
  11447. var toString = function(rgba) {
  11448. return "rgba(" + rgba.red + "," + rgba.green + "," + rgba.blue + "," + rgba.alpha + ")";
  11449. };
  11450. var red = rgbaColour(255, 0, 0, 1);
  11451. var fireSkinLoaded$1 = function(editor) {
  11452. return editor.fire("SkinLoaded");
  11453. };
  11454. var fireSkinLoadError$1 = function(editor, error2) {
  11455. return editor.fire("SkinLoadError", error2);
  11456. };
  11457. var fireResizeEditor = function(editor) {
  11458. return editor.fire("ResizeEditor");
  11459. };
  11460. var fireResizeContent = function(editor, e) {
  11461. return editor.fire("ResizeContent", e);
  11462. };
  11463. var fireScrollContent = function(editor, e) {
  11464. return editor.fire("ScrollContent", e);
  11465. };
  11466. var fireTextColorChange = function(editor, data) {
  11467. return editor.fire("TextColorChange", data);
  11468. };
  11469. var hsvColour = function(hue, saturation, value2) {
  11470. return {
  11471. hue,
  11472. saturation,
  11473. value: value2
  11474. };
  11475. };
  11476. var fromRgb = function(rgbaColour2) {
  11477. var h = 0;
  11478. var s = 0;
  11479. var v = 0;
  11480. var r2 = rgbaColour2.red / 255;
  11481. var g = rgbaColour2.green / 255;
  11482. var b2 = rgbaColour2.blue / 255;
  11483. var minRGB = Math.min(r2, Math.min(g, b2));
  11484. var maxRGB = Math.max(r2, Math.max(g, b2));
  11485. if (minRGB === maxRGB) {
  11486. v = minRGB;
  11487. return hsvColour(0, 0, v * 100);
  11488. }
  11489. var d = r2 === minRGB ? g - b2 : b2 === minRGB ? r2 - g : b2 - r2;
  11490. h = r2 === minRGB ? 3 : b2 === minRGB ? 1 : 5;
  11491. h = 60 * (h - d / (maxRGB - minRGB));
  11492. s = (maxRGB - minRGB) / maxRGB;
  11493. v = maxRGB;
  11494. return hsvColour(Math.round(h), Math.round(s * 100), Math.round(v * 100));
  11495. };
  11496. var hexToHsv = function(hex) {
  11497. return fromRgb(fromHex(hex));
  11498. };
  11499. var hsvToHex = function(hsv) {
  11500. return fromRgba(fromHsv(hsv));
  11501. };
  11502. var anyToHex = function(color) {
  11503. return fromString$1(color).orThunk(function() {
  11504. return fromString(color).map(fromRgba);
  11505. }).getOrThunk(function() {
  11506. var canvas = document.createElement("canvas");
  11507. canvas.height = 1;
  11508. canvas.width = 1;
  11509. var canvasContext = canvas.getContext("2d");
  11510. canvasContext.clearRect(0, 0, canvas.width, canvas.height);
  11511. canvasContext.fillStyle = "#FFFFFF";
  11512. canvasContext.fillStyle = color;
  11513. canvasContext.fillRect(0, 0, 1, 1);
  11514. var rgba = canvasContext.getImageData(0, 0, 1, 1).data;
  11515. var r2 = rgba[0];
  11516. var g = rgba[1];
  11517. var b2 = rgba[2];
  11518. var a = rgba[3];
  11519. return fromRgba(rgbaColour(r2, g, b2, a));
  11520. });
  11521. };
  11522. var global$8 = tinymce.util.Tools.resolve("tinymce.util.LocalStorage");
  11523. var storageName = "tinymce-custom-colors";
  11524. function ColorCache(max2) {
  11525. if (max2 === void 0) {
  11526. max2 = 10;
  11527. }
  11528. var storageString = global$8.getItem(storageName);
  11529. var localstorage = isString(storageString) ? JSON.parse(storageString) : [];
  11530. var prune = function(list) {
  11531. var diff = max2 - list.length;
  11532. return diff < 0 ? list.slice(0, max2) : list;
  11533. };
  11534. var cache = prune(localstorage);
  11535. var add2 = function(key) {
  11536. indexOf(cache, key).each(remove2);
  11537. cache.unshift(key);
  11538. if (cache.length > max2) {
  11539. cache.pop();
  11540. }
  11541. global$8.setItem(storageName, JSON.stringify(cache));
  11542. };
  11543. var remove2 = function(idx) {
  11544. cache.splice(idx, 1);
  11545. };
  11546. var state = function() {
  11547. return cache.slice(0);
  11548. };
  11549. return {
  11550. add: add2,
  11551. state
  11552. };
  11553. }
  11554. var choiceItem = "choiceitem";
  11555. var defaultColors = [
  11556. {
  11557. type: choiceItem,
  11558. text: "Light Green",
  11559. value: "#BFEDD2"
  11560. },
  11561. {
  11562. type: choiceItem,
  11563. text: "Light Yellow",
  11564. value: "#FBEEB8"
  11565. },
  11566. {
  11567. type: choiceItem,
  11568. text: "Light Red",
  11569. value: "#F8CAC6"
  11570. },
  11571. {
  11572. type: choiceItem,
  11573. text: "Light Purple",
  11574. value: "#ECCAFA"
  11575. },
  11576. {
  11577. type: choiceItem,
  11578. text: "Light Blue",
  11579. value: "#C2E0F4"
  11580. },
  11581. {
  11582. type: choiceItem,
  11583. text: "Green",
  11584. value: "#2DC26B"
  11585. },
  11586. {
  11587. type: choiceItem,
  11588. text: "Yellow",
  11589. value: "#F1C40F"
  11590. },
  11591. {
  11592. type: choiceItem,
  11593. text: "Red",
  11594. value: "#E03E2D"
  11595. },
  11596. {
  11597. type: choiceItem,
  11598. text: "Purple",
  11599. value: "#B96AD9"
  11600. },
  11601. {
  11602. type: choiceItem,
  11603. text: "Blue",
  11604. value: "#3598DB"
  11605. },
  11606. {
  11607. type: choiceItem,
  11608. text: "Dark Turquoise",
  11609. value: "#169179"
  11610. },
  11611. {
  11612. type: choiceItem,
  11613. text: "Orange",
  11614. value: "#E67E23"
  11615. },
  11616. {
  11617. type: choiceItem,
  11618. text: "Dark Red",
  11619. value: "#BA372A"
  11620. },
  11621. {
  11622. type: choiceItem,
  11623. text: "Dark Purple",
  11624. value: "#843FA1"
  11625. },
  11626. {
  11627. type: choiceItem,
  11628. text: "Dark Blue",
  11629. value: "#236FA1"
  11630. },
  11631. {
  11632. type: choiceItem,
  11633. text: "Light Gray",
  11634. value: "#ECF0F1"
  11635. },
  11636. {
  11637. type: choiceItem,
  11638. text: "Medium Gray",
  11639. value: "#CED4D9"
  11640. },
  11641. {
  11642. type: choiceItem,
  11643. text: "Gray",
  11644. value: "#95A5A6"
  11645. },
  11646. {
  11647. type: choiceItem,
  11648. text: "Dark Gray",
  11649. value: "#7E8C8D"
  11650. },
  11651. {
  11652. type: choiceItem,
  11653. text: "Navy Blue",
  11654. value: "#34495E"
  11655. },
  11656. {
  11657. type: choiceItem,
  11658. text: "Black",
  11659. value: "#000000"
  11660. },
  11661. {
  11662. type: choiceItem,
  11663. text: "White",
  11664. value: "#ffffff"
  11665. }
  11666. ];
  11667. var colorCache = ColorCache(10);
  11668. var mapColors = function(colorMap) {
  11669. var colors = [];
  11670. for (var i = 0; i < colorMap.length; i += 2) {
  11671. colors.push({
  11672. text: colorMap[i + 1],
  11673. value: "#" + anyToHex(colorMap[i]).value,
  11674. type: "choiceitem"
  11675. });
  11676. }
  11677. return colors;
  11678. };
  11679. var getColorCols$2 = function(editor, defaultCols) {
  11680. return editor.getParam("color_cols", defaultCols, "number");
  11681. };
  11682. var hasCustomColors$1 = function(editor) {
  11683. return editor.getParam("custom_colors") !== false;
  11684. };
  11685. var getColorMap = function(editor) {
  11686. return editor.getParam("color_map");
  11687. };
  11688. var getColors$2 = function(editor) {
  11689. var unmapped = getColorMap(editor);
  11690. return unmapped !== void 0 ? mapColors(unmapped) : defaultColors;
  11691. };
  11692. var getCurrentColors = function() {
  11693. return map$2(colorCache.state(), function(color) {
  11694. return {
  11695. type: choiceItem,
  11696. text: color,
  11697. value: color
  11698. };
  11699. });
  11700. };
  11701. var addColor = function(color) {
  11702. colorCache.add(color);
  11703. };
  11704. var fallbackColor = "#000000";
  11705. var getCurrentColor = function(editor, format) {
  11706. var color;
  11707. editor.dom.getParents(editor.selection.getStart(), function(elm) {
  11708. var value2;
  11709. if (value2 = elm.style[format === "forecolor" ? "color" : "background-color"]) {
  11710. color = color ? color : value2;
  11711. }
  11712. });
  11713. return Optional.from(color);
  11714. };
  11715. var applyFormat = function(editor, format, value2) {
  11716. editor.undoManager.transact(function() {
  11717. editor.focus();
  11718. editor.formatter.apply(format, { value: value2 });
  11719. editor.nodeChanged();
  11720. });
  11721. };
  11722. var removeFormat = function(editor, format) {
  11723. editor.undoManager.transact(function() {
  11724. editor.focus();
  11725. editor.formatter.remove(format, { value: null }, null, true);
  11726. editor.nodeChanged();
  11727. });
  11728. };
  11729. var registerCommands = function(editor) {
  11730. editor.addCommand("mceApplyTextcolor", function(format, value2) {
  11731. applyFormat(editor, format, value2);
  11732. });
  11733. editor.addCommand("mceRemoveTextcolor", function(format) {
  11734. removeFormat(editor, format);
  11735. });
  11736. };
  11737. var calcCols = function(colors) {
  11738. return Math.max(5, Math.ceil(Math.sqrt(colors)));
  11739. };
  11740. var getColorCols$1 = function(editor) {
  11741. var colors = getColors$2(editor);
  11742. var defaultCols = calcCols(colors.length);
  11743. return getColorCols$2(editor, defaultCols);
  11744. };
  11745. var getAdditionalColors = function(hasCustom) {
  11746. var type2 = "choiceitem";
  11747. var remove2 = {
  11748. type: type2,
  11749. text: "Remove color",
  11750. icon: "color-swatch-remove-color",
  11751. value: "remove"
  11752. };
  11753. var custom2 = {
  11754. type: type2,
  11755. text: "Custom color",
  11756. icon: "color-picker",
  11757. value: "custom"
  11758. };
  11759. return hasCustom ? [
  11760. remove2,
  11761. custom2
  11762. ] : [remove2];
  11763. };
  11764. var applyColor = function(editor, format, value2, onChoice) {
  11765. if (value2 === "custom") {
  11766. var dialog = colorPickerDialog(editor);
  11767. dialog(function(colorOpt) {
  11768. colorOpt.each(function(color) {
  11769. addColor(color);
  11770. editor.execCommand("mceApplyTextcolor", format, color);
  11771. onChoice(color);
  11772. });
  11773. }, fallbackColor);
  11774. } else if (value2 === "remove") {
  11775. onChoice("");
  11776. editor.execCommand("mceRemoveTextcolor", format);
  11777. } else {
  11778. onChoice(value2);
  11779. editor.execCommand("mceApplyTextcolor", format, value2);
  11780. }
  11781. };
  11782. var getColors$1 = function(colors, hasCustom) {
  11783. return colors.concat(getCurrentColors().concat(getAdditionalColors(hasCustom)));
  11784. };
  11785. var getFetch$1 = function(colors, hasCustom) {
  11786. return function(callback) {
  11787. callback(getColors$1(colors, hasCustom));
  11788. };
  11789. };
  11790. var setIconColor = function(splitButtonApi, name2, newColor) {
  11791. var id = name2 === "forecolor" ? "tox-icon-text-color__color" : "tox-icon-highlight-bg-color__color";
  11792. splitButtonApi.setIconFill(id, newColor);
  11793. };
  11794. var registerTextColorButton = function(editor, name2, format, tooltip, lastColor) {
  11795. editor.ui.registry.addSplitButton(name2, {
  11796. tooltip,
  11797. presets: "color",
  11798. icon: name2 === "forecolor" ? "text-color" : "highlight-bg-color",
  11799. select: function(value2) {
  11800. var optCurrentRgb = getCurrentColor(editor, format);
  11801. return optCurrentRgb.bind(function(currentRgb) {
  11802. return fromString(currentRgb).map(function(rgba) {
  11803. var currentHex = fromRgba(rgba).value;
  11804. return contains$1(value2.toLowerCase(), currentHex);
  11805. });
  11806. }).getOr(false);
  11807. },
  11808. columns: getColorCols$1(editor),
  11809. fetch: getFetch$1(getColors$2(editor), hasCustomColors$1(editor)),
  11810. onAction: function(_splitButtonApi) {
  11811. applyColor(editor, format, lastColor.get(), noop);
  11812. },
  11813. onItemAction: function(_splitButtonApi, value2) {
  11814. applyColor(editor, format, value2, function(newColor) {
  11815. lastColor.set(newColor);
  11816. fireTextColorChange(editor, {
  11817. name: name2,
  11818. color: newColor
  11819. });
  11820. });
  11821. },
  11822. onSetup: function(splitButtonApi) {
  11823. setIconColor(splitButtonApi, name2, lastColor.get());
  11824. var handler = function(e) {
  11825. if (e.name === name2) {
  11826. setIconColor(splitButtonApi, e.name, e.color);
  11827. }
  11828. };
  11829. editor.on("TextColorChange", handler);
  11830. return function() {
  11831. editor.off("TextColorChange", handler);
  11832. };
  11833. }
  11834. });
  11835. };
  11836. var registerTextColorMenuItem = function(editor, name2, format, text2) {
  11837. editor.ui.registry.addNestedMenuItem(name2, {
  11838. text: text2,
  11839. icon: name2 === "forecolor" ? "text-color" : "highlight-bg-color",
  11840. getSubmenuItems: function() {
  11841. return [{
  11842. type: "fancymenuitem",
  11843. fancytype: "colorswatch",
  11844. onAction: function(data) {
  11845. applyColor(editor, format, data.value, noop);
  11846. }
  11847. }];
  11848. }
  11849. });
  11850. };
  11851. var colorPickerDialog = function(editor) {
  11852. return function(callback, value2) {
  11853. var isValid = false;
  11854. var onSubmit = function(api2) {
  11855. var data = api2.getData();
  11856. var hex = data.colorpicker;
  11857. if (isValid) {
  11858. callback(Optional.from(hex));
  11859. api2.close();
  11860. } else {
  11861. editor.windowManager.alert(editor.translate([
  11862. "Invalid hex color code: {0}",
  11863. hex
  11864. ]));
  11865. }
  11866. };
  11867. var onAction = function(_api, details) {
  11868. if (details.name === "hex-valid") {
  11869. isValid = details.value;
  11870. }
  11871. };
  11872. var initialData = { colorpicker: value2 };
  11873. editor.windowManager.open({
  11874. title: "Color Picker",
  11875. size: "normal",
  11876. body: {
  11877. type: "panel",
  11878. items: [{
  11879. type: "colorpicker",
  11880. name: "colorpicker",
  11881. label: "Color"
  11882. }]
  11883. },
  11884. buttons: [
  11885. {
  11886. type: "cancel",
  11887. name: "cancel",
  11888. text: "Cancel"
  11889. },
  11890. {
  11891. type: "submit",
  11892. name: "save",
  11893. text: "Save",
  11894. primary: true
  11895. }
  11896. ],
  11897. initialData,
  11898. onAction,
  11899. onSubmit,
  11900. onClose: noop,
  11901. onCancel: function() {
  11902. callback(Optional.none());
  11903. }
  11904. });
  11905. };
  11906. };
  11907. var register$a = function(editor) {
  11908. registerCommands(editor);
  11909. var lastForeColor = Cell(fallbackColor);
  11910. var lastBackColor = Cell(fallbackColor);
  11911. registerTextColorButton(editor, "forecolor", "forecolor", "Text color", lastForeColor);
  11912. registerTextColorButton(editor, "backcolor", "hilitecolor", "Background color", lastBackColor);
  11913. registerTextColorMenuItem(editor, "forecolor", "forecolor", "Text color");
  11914. registerTextColorMenuItem(editor, "backcolor", "hilitecolor", "Background color");
  11915. };
  11916. var createPartialChoiceMenu = function(value2, items, onItemValueHandler, columns, presets, itemResponse, select2, providersBackstage) {
  11917. var hasIcons = menuHasIcons(items);
  11918. var presetItemTypes = presets !== "color" ? "normal" : "color";
  11919. var alloyItems = createChoiceItems(items, onItemValueHandler, columns, presetItemTypes, itemResponse, select2, providersBackstage);
  11920. return createPartialMenuWithAlloyItems(value2, hasIcons, alloyItems, columns, presets);
  11921. };
  11922. var createChoiceItems = function(items, onItemValueHandler, columns, itemPresets, itemResponse, select2, providersBackstage) {
  11923. return cat(map$2(items, function(item2) {
  11924. if (item2.type === "choiceitem") {
  11925. return createChoiceMenuItem(item2).fold(handleError, function(d) {
  11926. return Optional.some(renderChoiceItem(d, columns === 1, itemPresets, onItemValueHandler, select2(item2.value), itemResponse, providersBackstage, menuHasIcons(items)));
  11927. });
  11928. } else {
  11929. return Optional.none();
  11930. }
  11931. }));
  11932. };
  11933. var deriveMenuMovement = function(columns, presets) {
  11934. var menuMarkers = markers(presets);
  11935. if (columns === 1) {
  11936. return {
  11937. mode: "menu",
  11938. moveOnTab: true
  11939. };
  11940. } else if (columns === "auto") {
  11941. return {
  11942. mode: "grid",
  11943. selector: "." + menuMarkers.item,
  11944. initSize: {
  11945. numColumns: 1,
  11946. numRows: 1
  11947. }
  11948. };
  11949. } else {
  11950. var rowClass = presets === "color" ? "tox-swatches__row" : "tox-collection__group";
  11951. return {
  11952. mode: "matrix",
  11953. rowSelector: "." + rowClass
  11954. };
  11955. }
  11956. };
  11957. var deriveCollectionMovement = function(columns, presets) {
  11958. if (columns === 1) {
  11959. return {
  11960. mode: "menu",
  11961. moveOnTab: false,
  11962. selector: ".tox-collection__item"
  11963. };
  11964. } else if (columns === "auto") {
  11965. return {
  11966. mode: "flatgrid",
  11967. selector: ".tox-collection__item",
  11968. initSize: {
  11969. numColumns: 1,
  11970. numRows: 1
  11971. }
  11972. };
  11973. } else {
  11974. return {
  11975. mode: "matrix",
  11976. selectors: {
  11977. row: presets === "color" ? ".tox-swatches__row" : ".tox-collection__group",
  11978. cell: presets === "color" ? "." + colorClass : "." + selectableClass
  11979. }
  11980. };
  11981. }
  11982. };
  11983. var renderColorSwatchItem = function(spec, backstage) {
  11984. var items = getColorItems(spec, backstage);
  11985. var columns = backstage.colorinput.getColorCols();
  11986. var presets = "color";
  11987. var menuSpec = createPartialChoiceMenu(generate$6("menu-value"), items, function(value2) {
  11988. spec.onAction({ value: value2 });
  11989. }, columns, presets, ItemResponse$1.CLOSE_ON_EXECUTE, never, backstage.shared.providers);
  11990. var widgetSpec = __assign(__assign({}, menuSpec), {
  11991. markers: markers(presets),
  11992. movement: deriveMenuMovement(columns, presets)
  11993. });
  11994. return {
  11995. type: "widget",
  11996. data: { value: generate$6("widget-id") },
  11997. dom: {
  11998. tag: "div",
  11999. classes: ["tox-fancymenuitem"]
  12000. },
  12001. autofocus: true,
  12002. components: [parts$f.widget(Menu.sketch(widgetSpec))]
  12003. };
  12004. };
  12005. var getColorItems = function(spec, backstage) {
  12006. var useCustomColors = spec.initData.allowCustomColors && backstage.colorinput.hasCustomColors();
  12007. return spec.initData.colors.fold(function() {
  12008. return getColors$1(backstage.colorinput.getColors(), useCustomColors);
  12009. }, function(colors) {
  12010. return colors.concat(getAdditionalColors(useCustomColors));
  12011. });
  12012. };
  12013. var cellOverEvent = generate$6("cell-over");
  12014. var cellExecuteEvent = generate$6("cell-execute");
  12015. var makeCell = function(row, col, labelId) {
  12016. var _a2;
  12017. var emitCellOver = function(c) {
  12018. return emitWith(c, cellOverEvent, {
  12019. row,
  12020. col
  12021. });
  12022. };
  12023. var emitExecute2 = function(c) {
  12024. return emitWith(c, cellExecuteEvent, {
  12025. row,
  12026. col
  12027. });
  12028. };
  12029. var onClick = function(c, se) {
  12030. se.stop();
  12031. emitExecute2(c);
  12032. };
  12033. return build$1({
  12034. dom: {
  12035. tag: "div",
  12036. attributes: (_a2 = { role: "button" }, _a2["aria-labelledby"] = labelId, _a2)
  12037. },
  12038. behaviours: derive$1([
  12039. config("insert-table-picker-cell", [
  12040. run$1(mouseover(), Focusing.focus),
  12041. run$1(execute$5(), emitExecute2),
  12042. run$1(click(), onClick),
  12043. run$1(tap(), onClick)
  12044. ]),
  12045. Toggling.config({
  12046. toggleClass: "tox-insert-table-picker__selected",
  12047. toggleOnExecute: false
  12048. }),
  12049. Focusing.config({ onFocus: emitCellOver })
  12050. ])
  12051. });
  12052. };
  12053. var makeCells = function(labelId, numRows, numCols) {
  12054. var cells = [];
  12055. for (var i = 0; i < numRows; i++) {
  12056. var row = [];
  12057. for (var j = 0; j < numCols; j++) {
  12058. row.push(makeCell(i, j, labelId));
  12059. }
  12060. cells.push(row);
  12061. }
  12062. return cells;
  12063. };
  12064. var selectCells = function(cells, selectedRow, selectedColumn, numRows, numColumns) {
  12065. for (var i = 0; i < numRows; i++) {
  12066. for (var j = 0; j < numColumns; j++) {
  12067. Toggling.set(cells[i][j], i <= selectedRow && j <= selectedColumn);
  12068. }
  12069. }
  12070. };
  12071. var makeComponents = function(cells) {
  12072. return bind$3(cells, function(cellRow) {
  12073. return map$2(cellRow, premade);
  12074. });
  12075. };
  12076. var makeLabelText = function(row, col) {
  12077. return text$1(col + "x" + row);
  12078. };
  12079. var renderInsertTableMenuItem = function(spec) {
  12080. var numRows = 10;
  12081. var numColumns = 10;
  12082. var sizeLabelId = generate$6("size-label");
  12083. var cells = makeCells(sizeLabelId, numRows, numColumns);
  12084. var emptyLabelText = makeLabelText(0, 0);
  12085. var memLabel = record({
  12086. dom: {
  12087. tag: "span",
  12088. classes: ["tox-insert-table-picker__label"],
  12089. attributes: { id: sizeLabelId }
  12090. },
  12091. components: [emptyLabelText],
  12092. behaviours: derive$1([Replacing.config({})])
  12093. });
  12094. return {
  12095. type: "widget",
  12096. data: { value: generate$6("widget-id") },
  12097. dom: {
  12098. tag: "div",
  12099. classes: ["tox-fancymenuitem"]
  12100. },
  12101. autofocus: true,
  12102. components: [parts$f.widget({
  12103. dom: {
  12104. tag: "div",
  12105. classes: ["tox-insert-table-picker"]
  12106. },
  12107. components: makeComponents(cells).concat(memLabel.asSpec()),
  12108. behaviours: derive$1([
  12109. config("insert-table-picker", [
  12110. runOnAttached(function(c) {
  12111. Replacing.set(memLabel.get(c), [emptyLabelText]);
  12112. }),
  12113. runWithTarget(cellOverEvent, function(c, t2, e) {
  12114. var _a2 = e.event, row = _a2.row, col = _a2.col;
  12115. selectCells(cells, row, col, numRows, numColumns);
  12116. Replacing.set(memLabel.get(c), [makeLabelText(row + 1, col + 1)]);
  12117. }),
  12118. runWithTarget(cellExecuteEvent, function(c, _, e) {
  12119. var _a2 = e.event, row = _a2.row, col = _a2.col;
  12120. spec.onAction({
  12121. numRows: row + 1,
  12122. numColumns: col + 1
  12123. });
  12124. emit(c, sandboxClose());
  12125. })
  12126. ]),
  12127. Keying.config({
  12128. initSize: {
  12129. numRows,
  12130. numColumns
  12131. },
  12132. mode: "flatgrid",
  12133. selector: '[role="button"]'
  12134. })
  12135. ])
  12136. })]
  12137. };
  12138. };
  12139. var fancyMenuItems = {
  12140. inserttable: renderInsertTableMenuItem,
  12141. colorswatch: renderColorSwatchItem
  12142. };
  12143. var renderFancyMenuItem = function(spec, backstage) {
  12144. return get$e(fancyMenuItems, spec.fancytype).map(function(render2) {
  12145. return render2(spec, backstage);
  12146. });
  12147. };
  12148. var renderNestedItem = function(spec, itemResponse, providersBackstage, renderIcons, downwardsCaret) {
  12149. if (renderIcons === void 0) {
  12150. renderIcons = true;
  12151. }
  12152. if (downwardsCaret === void 0) {
  12153. downwardsCaret = false;
  12154. }
  12155. var caret = downwardsCaret ? renderDownwardsCaret(providersBackstage.icons) : renderSubmenuCaret(providersBackstage.icons);
  12156. var getApi2 = function(component) {
  12157. return {
  12158. isDisabled: function() {
  12159. return Disabling.isDisabled(component);
  12160. },
  12161. setDisabled: function(state) {
  12162. return Disabling.set(component, state);
  12163. }
  12164. };
  12165. };
  12166. var structure = renderItemStructure({
  12167. presets: "normal",
  12168. iconContent: spec.icon,
  12169. textContent: spec.text,
  12170. htmlContent: Optional.none(),
  12171. ariaLabel: spec.text,
  12172. caret: Optional.some(caret),
  12173. checkMark: Optional.none(),
  12174. shortcutContent: spec.shortcut
  12175. }, providersBackstage, renderIcons);
  12176. return renderCommonItem({
  12177. data: buildData(spec),
  12178. getApi: getApi2,
  12179. disabled: spec.disabled,
  12180. onAction: noop,
  12181. onSetup: spec.onSetup,
  12182. triggersSubmenu: true,
  12183. itemBehaviours: []
  12184. }, structure, itemResponse, providersBackstage);
  12185. };
  12186. var renderNormalItem = function(spec, itemResponse, providersBackstage, renderIcons) {
  12187. if (renderIcons === void 0) {
  12188. renderIcons = true;
  12189. }
  12190. var getApi2 = function(component) {
  12191. return {
  12192. isDisabled: function() {
  12193. return Disabling.isDisabled(component);
  12194. },
  12195. setDisabled: function(state) {
  12196. return Disabling.set(component, state);
  12197. }
  12198. };
  12199. };
  12200. var structure = renderItemStructure({
  12201. presets: "normal",
  12202. iconContent: spec.icon,
  12203. textContent: spec.text,
  12204. htmlContent: Optional.none(),
  12205. ariaLabel: spec.text,
  12206. caret: Optional.none(),
  12207. checkMark: Optional.none(),
  12208. shortcutContent: spec.shortcut
  12209. }, providersBackstage, renderIcons);
  12210. return renderCommonItem({
  12211. data: buildData(spec),
  12212. getApi: getApi2,
  12213. disabled: spec.disabled,
  12214. onAction: spec.onAction,
  12215. onSetup: spec.onSetup,
  12216. triggersSubmenu: false,
  12217. itemBehaviours: []
  12218. }, structure, itemResponse, providersBackstage);
  12219. };
  12220. var renderSeparatorItem = function(spec) {
  12221. var innerHtml = spec.text.fold(function() {
  12222. return {};
  12223. }, function(text2) {
  12224. return { innerHtml: text2 };
  12225. });
  12226. return {
  12227. type: "separator",
  12228. dom: __assign({
  12229. tag: "div",
  12230. classes: [
  12231. selectableClass,
  12232. groupHeadingClass
  12233. ]
  12234. }, innerHtml),
  12235. components: []
  12236. };
  12237. };
  12238. var renderToggleMenuItem = function(spec, itemResponse, providersBackstage, renderIcons) {
  12239. if (renderIcons === void 0) {
  12240. renderIcons = true;
  12241. }
  12242. var getApi2 = function(component) {
  12243. return {
  12244. setActive: function(state) {
  12245. Toggling.set(component, state);
  12246. },
  12247. isActive: function() {
  12248. return Toggling.isOn(component);
  12249. },
  12250. isDisabled: function() {
  12251. return Disabling.isDisabled(component);
  12252. },
  12253. setDisabled: function(state) {
  12254. return Disabling.set(component, state);
  12255. }
  12256. };
  12257. };
  12258. var structure = renderItemStructure({
  12259. iconContent: spec.icon,
  12260. textContent: spec.text,
  12261. htmlContent: Optional.none(),
  12262. ariaLabel: spec.text,
  12263. checkMark: Optional.some(renderCheckmark(providersBackstage.icons)),
  12264. caret: Optional.none(),
  12265. shortcutContent: spec.shortcut,
  12266. presets: "normal",
  12267. meta: spec.meta
  12268. }, providersBackstage, renderIcons);
  12269. return deepMerge(renderCommonItem({
  12270. data: buildData(spec),
  12271. disabled: spec.disabled,
  12272. getApi: getApi2,
  12273. onAction: spec.onAction,
  12274. onSetup: spec.onSetup,
  12275. triggersSubmenu: false,
  12276. itemBehaviours: []
  12277. }, structure, itemResponse, providersBackstage), {
  12278. toggling: {
  12279. toggleClass: tickedClass,
  12280. toggleOnExecute: false,
  12281. selected: spec.active
  12282. }
  12283. });
  12284. };
  12285. var autocomplete = renderAutocompleteItem;
  12286. var separator$3 = renderSeparatorItem;
  12287. var normal = renderNormalItem;
  12288. var nested = renderNestedItem;
  12289. var toggle$1 = renderToggleMenuItem;
  12290. var fancy = renderFancyMenuItem;
  12291. var card = renderCardMenuItem;
  12292. var FocusMode;
  12293. (function(FocusMode2) {
  12294. FocusMode2[FocusMode2["ContentFocus"] = 0] = "ContentFocus";
  12295. FocusMode2[FocusMode2["UiFocus"] = 1] = "UiFocus";
  12296. })(FocusMode || (FocusMode = {}));
  12297. var createMenuItemFromBridge = function(item2, itemResponse, backstage, menuHasIcons2, isHorizontalMenu) {
  12298. var providersBackstage = backstage.shared.providers;
  12299. var parseForHorizontalMenu = function(menuitem) {
  12300. return !isHorizontalMenu ? menuitem : __assign(__assign({}, menuitem), {
  12301. shortcut: Optional.none(),
  12302. icon: menuitem.text.isSome() ? Optional.none() : menuitem.icon
  12303. });
  12304. };
  12305. switch (item2.type) {
  12306. case "menuitem":
  12307. return createMenuItem(item2).fold(handleError, function(d) {
  12308. return Optional.some(normal(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons2));
  12309. });
  12310. case "nestedmenuitem":
  12311. return createNestedMenuItem(item2).fold(handleError, function(d) {
  12312. return Optional.some(nested(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons2, isHorizontalMenu));
  12313. });
  12314. case "togglemenuitem":
  12315. return createToggleMenuItem(item2).fold(handleError, function(d) {
  12316. return Optional.some(toggle$1(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons2));
  12317. });
  12318. case "separator":
  12319. return createSeparatorMenuItem(item2).fold(handleError, function(d) {
  12320. return Optional.some(separator$3(d));
  12321. });
  12322. case "fancymenuitem":
  12323. return createFancyMenuItem(item2).fold(handleError, function(d) {
  12324. return fancy(parseForHorizontalMenu(d), backstage);
  12325. });
  12326. default: {
  12327. console.error("Unknown item in general menu", item2);
  12328. return Optional.none();
  12329. }
  12330. }
  12331. };
  12332. var createAutocompleteItems = function(items, matchText, onItemValueHandler, columns, itemResponse, sharedBackstage, highlightOn) {
  12333. var renderText2 = columns === 1;
  12334. var renderIcons = !renderText2 || menuHasIcons(items);
  12335. return cat(map$2(items, function(item2) {
  12336. switch (item2.type) {
  12337. case "separator":
  12338. return createSeparatorItem(item2).fold(handleError, function(d) {
  12339. return Optional.some(separator$3(d));
  12340. });
  12341. case "cardmenuitem":
  12342. return createCardMenuItem(item2).fold(handleError, function(d) {
  12343. return Optional.some(card(__assign(__assign({}, d), {
  12344. onAction: function(api2) {
  12345. d.onAction(api2);
  12346. onItemValueHandler(d.value, d.meta);
  12347. }
  12348. }), itemResponse, sharedBackstage, {
  12349. itemBehaviours: tooltipBehaviour(d.meta, sharedBackstage),
  12350. cardText: {
  12351. matchText,
  12352. highlightOn
  12353. }
  12354. }));
  12355. });
  12356. case "autocompleteitem":
  12357. default:
  12358. return createAutocompleterItem(item2).fold(handleError, function(d) {
  12359. return Optional.some(autocomplete(d, matchText, renderText2, "normal", onItemValueHandler, itemResponse, sharedBackstage, renderIcons));
  12360. });
  12361. }
  12362. }));
  12363. };
  12364. var createPartialMenu = function(value2, items, itemResponse, backstage, isHorizontalMenu) {
  12365. var hasIcons = menuHasIcons(items);
  12366. var alloyItems = cat(map$2(items, function(item2) {
  12367. var itemHasIcon = function(i) {
  12368. return isHorizontalMenu ? !has$2(i, "text") : hasIcons;
  12369. };
  12370. var createItem = function(i) {
  12371. return createMenuItemFromBridge(i, itemResponse, backstage, itemHasIcon(i), isHorizontalMenu);
  12372. };
  12373. if (item2.type === "nestedmenuitem" && item2.getSubmenuItems().length <= 0) {
  12374. return createItem(__assign(__assign({}, item2), { disabled: true }));
  12375. } else {
  12376. return createItem(item2);
  12377. }
  12378. }));
  12379. var createPartial = isHorizontalMenu ? createHorizontalPartialMenuWithAlloyItems : createPartialMenuWithAlloyItems;
  12380. return createPartial(value2, hasIcons, alloyItems, 1, "normal");
  12381. };
  12382. var createTieredDataFrom = function(partialMenu) {
  12383. return tieredMenu.singleData(partialMenu.value, partialMenu);
  12384. };
  12385. var createMenuFrom = function(partialMenu, columns, focusMode, presets) {
  12386. var focusManager = focusMode === FocusMode.ContentFocus ? highlights() : dom$2();
  12387. var movement = deriveMenuMovement(columns, presets);
  12388. var menuMarkers = markers(presets);
  12389. return {
  12390. dom: partialMenu.dom,
  12391. components: partialMenu.components,
  12392. items: partialMenu.items,
  12393. value: partialMenu.value,
  12394. markers: {
  12395. selectedItem: menuMarkers.selectedItem,
  12396. item: menuMarkers.item
  12397. },
  12398. movement,
  12399. fakeFocus: focusMode === FocusMode.ContentFocus,
  12400. focusManager,
  12401. menuBehaviours: SimpleBehaviours.unnamedEvents(columns !== "auto" ? [] : [runOnAttached(function(comp, _se) {
  12402. detectSize(comp, 4, menuMarkers.item).each(function(_a2) {
  12403. var numColumns = _a2.numColumns, numRows = _a2.numRows;
  12404. Keying.setGridSize(comp, numRows, numColumns);
  12405. });
  12406. })])
  12407. };
  12408. };
  12409. var register$9 = function(editor, sharedBackstage) {
  12410. var activeAutocompleter = value$1();
  12411. var processingAction = Cell(false);
  12412. var autocompleter = build$1(InlineView.sketch({
  12413. dom: {
  12414. tag: "div",
  12415. classes: ["tox-autocompleter"]
  12416. },
  12417. components: [],
  12418. fireDismissalEventInstead: {},
  12419. inlineBehaviours: derive$1([config("dismissAutocompleter", [run$1(dismissRequested(), function() {
  12420. return cancelIfNecessary();
  12421. })])]),
  12422. lazySink: sharedBackstage.getSink
  12423. }));
  12424. var isMenuOpen = function() {
  12425. return InlineView.isOpen(autocompleter);
  12426. };
  12427. var isActive = function() {
  12428. return activeAutocompleter.get().isSome();
  12429. };
  12430. var hideIfNecessary = function() {
  12431. if (isActive()) {
  12432. InlineView.hide(autocompleter);
  12433. }
  12434. };
  12435. var cancelIfNecessary = function() {
  12436. if (isActive()) {
  12437. var lastElement = activeAutocompleter.get().map(function(ac) {
  12438. return ac.element;
  12439. });
  12440. detect(lastElement.getOr(SugarElement.fromDom(editor.selection.getNode()))).each(unwrap);
  12441. hideIfNecessary();
  12442. activeAutocompleter.clear();
  12443. processingAction.set(false);
  12444. }
  12445. };
  12446. var getAutocompleters = cached(function() {
  12447. return register$b(editor);
  12448. });
  12449. var getCombinedItems = function(triggerChar, matches) {
  12450. var columns = findMap(matches, function(m) {
  12451. return Optional.from(m.columns);
  12452. }).getOr(1);
  12453. return bind$3(matches, function(match) {
  12454. var choices = match.items;
  12455. return createAutocompleteItems(choices, match.matchText, function(itemValue, itemMeta) {
  12456. var nr = editor.selection.getRng();
  12457. getContext(editor.dom, nr, triggerChar).fold(function() {
  12458. return console.error("Lost context. Cursor probably moved");
  12459. }, function(_a2) {
  12460. var range2 = _a2.range;
  12461. var autocompleterApi = {
  12462. hide: function() {
  12463. cancelIfNecessary();
  12464. },
  12465. reload: function(fetchOptions) {
  12466. hideIfNecessary();
  12467. load(fetchOptions);
  12468. }
  12469. };
  12470. processingAction.set(true);
  12471. match.onAction(autocompleterApi, range2, itemValue, itemMeta);
  12472. processingAction.set(false);
  12473. });
  12474. }, columns, ItemResponse$1.BUBBLE_TO_SANDBOX, sharedBackstage, match.highlightOn);
  12475. });
  12476. };
  12477. var commenceIfNecessary = function(context) {
  12478. if (!isActive()) {
  12479. var wrapper = create$5(editor, context.range);
  12480. activeAutocompleter.set({
  12481. triggerChar: context.triggerChar,
  12482. element: wrapper,
  12483. matchLength: context.text.length
  12484. });
  12485. processingAction.set(false);
  12486. }
  12487. };
  12488. var display = function(ac, context, lookupData, items) {
  12489. ac.matchLength = context.text.length;
  12490. var columns = findMap(lookupData, function(ld) {
  12491. return Optional.from(ld.columns);
  12492. }).getOr(1);
  12493. InlineView.showAt(autocompleter, Menu.sketch(createMenuFrom(createPartialMenuWithAlloyItems("autocompleter-value", true, items, columns, "normal"), columns, FocusMode.ContentFocus, "normal")), {
  12494. anchor: {
  12495. type: "node",
  12496. root: SugarElement.fromDom(editor.getBody()),
  12497. node: Optional.from(ac.element)
  12498. }
  12499. });
  12500. InlineView.getContent(autocompleter).each(Highlighting.highlightFirst);
  12501. };
  12502. var doLookup = function(fetchOptions) {
  12503. return activeAutocompleter.get().map(function(ac) {
  12504. return getContext(editor.dom, editor.selection.getRng(), ac.triggerChar).bind(function(newContext) {
  12505. return lookupWithContext(editor, getAutocompleters, newContext, fetchOptions);
  12506. });
  12507. }).getOrThunk(function() {
  12508. return lookup$2(editor, getAutocompleters);
  12509. });
  12510. };
  12511. var load = function(fetchOptions) {
  12512. doLookup(fetchOptions).fold(cancelIfNecessary, function(lookupInfo) {
  12513. commenceIfNecessary(lookupInfo.context);
  12514. lookupInfo.lookupData.then(function(lookupData) {
  12515. activeAutocompleter.get().map(function(ac) {
  12516. var context = lookupInfo.context;
  12517. if (ac.triggerChar === context.triggerChar) {
  12518. var combinedItems = getCombinedItems(context.triggerChar, lookupData);
  12519. if (combinedItems.length > 0) {
  12520. display(ac, context, lookupData, combinedItems);
  12521. } else if (context.text.length - ac.matchLength >= 10) {
  12522. cancelIfNecessary();
  12523. } else {
  12524. hideIfNecessary();
  12525. }
  12526. }
  12527. });
  12528. });
  12529. });
  12530. };
  12531. var onKeypress = last(function(e) {
  12532. if (e.which === 27) {
  12533. return;
  12534. }
  12535. load();
  12536. }, 50);
  12537. var autocompleterUiApi = {
  12538. onKeypress,
  12539. cancelIfNecessary,
  12540. isMenuOpen,
  12541. isActive,
  12542. isProcessingAction: processingAction.get,
  12543. getView: function() {
  12544. return InlineView.getContent(autocompleter);
  12545. }
  12546. };
  12547. if (editor.hasPlugin("rtc") === false) {
  12548. AutocompleterEditorEvents.setup(autocompleterUiApi, editor);
  12549. }
  12550. };
  12551. var Autocompleter = { register: register$9 };
  12552. var closest = function(scope, selector, isRoot) {
  12553. return closest$1(scope, selector, isRoot).isSome();
  12554. };
  12555. var DelayedFunction = function(fun, delay) {
  12556. var ref = null;
  12557. var schedule = function() {
  12558. var args = [];
  12559. for (var _i = 0; _i < arguments.length; _i++) {
  12560. args[_i] = arguments[_i];
  12561. }
  12562. ref = setTimeout(function() {
  12563. fun.apply(null, args);
  12564. ref = null;
  12565. }, delay);
  12566. };
  12567. var cancel = function() {
  12568. if (ref !== null) {
  12569. clearTimeout(ref);
  12570. ref = null;
  12571. }
  12572. };
  12573. return {
  12574. cancel,
  12575. schedule
  12576. };
  12577. };
  12578. var SIGNIFICANT_MOVE = 5;
  12579. var LONGPRESS_DELAY = 400;
  12580. var getTouch = function(event) {
  12581. var raw = event.raw;
  12582. if (raw.touches === void 0 || raw.touches.length !== 1) {
  12583. return Optional.none();
  12584. }
  12585. return Optional.some(raw.touches[0]);
  12586. };
  12587. var isFarEnough = function(touch2, data) {
  12588. var distX = Math.abs(touch2.clientX - data.x);
  12589. var distY = Math.abs(touch2.clientY - data.y);
  12590. return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
  12591. };
  12592. var monitor = function(settings) {
  12593. var startData = value$1();
  12594. var longpressFired = Cell(false);
  12595. var longpress$1 = DelayedFunction(function(event) {
  12596. settings.triggerEvent(longpress(), event);
  12597. longpressFired.set(true);
  12598. }, LONGPRESS_DELAY);
  12599. var handleTouchstart = function(event) {
  12600. getTouch(event).each(function(touch2) {
  12601. longpress$1.cancel();
  12602. var data = {
  12603. x: touch2.clientX,
  12604. y: touch2.clientY,
  12605. target: event.target
  12606. };
  12607. longpress$1.schedule(event);
  12608. longpressFired.set(false);
  12609. startData.set(data);
  12610. });
  12611. return Optional.none();
  12612. };
  12613. var handleTouchmove = function(event) {
  12614. longpress$1.cancel();
  12615. getTouch(event).each(function(touch2) {
  12616. startData.on(function(data) {
  12617. if (isFarEnough(touch2, data)) {
  12618. startData.clear();
  12619. }
  12620. });
  12621. });
  12622. return Optional.none();
  12623. };
  12624. var handleTouchend = function(event) {
  12625. longpress$1.cancel();
  12626. var isSame = function(data) {
  12627. return eq(data.target, event.target);
  12628. };
  12629. return startData.get().filter(isSame).map(function(_data) {
  12630. if (longpressFired.get()) {
  12631. event.prevent();
  12632. return false;
  12633. } else {
  12634. return settings.triggerEvent(tap(), event);
  12635. }
  12636. });
  12637. };
  12638. var handlers2 = wrapAll([
  12639. {
  12640. key: touchstart(),
  12641. value: handleTouchstart
  12642. },
  12643. {
  12644. key: touchmove(),
  12645. value: handleTouchmove
  12646. },
  12647. {
  12648. key: touchend(),
  12649. value: handleTouchend
  12650. }
  12651. ]);
  12652. var fireIfReady = function(event, type2) {
  12653. return get$e(handlers2, type2).bind(function(handler) {
  12654. return handler(event);
  12655. });
  12656. };
  12657. return { fireIfReady };
  12658. };
  12659. var isDangerous = function(event) {
  12660. var keyEv = event.raw;
  12661. return keyEv.which === BACKSPACE[0] && !contains$2([
  12662. "input",
  12663. "textarea"
  12664. ], name$2(event.target)) && !closest(event.target, '[contenteditable="true"]');
  12665. };
  12666. var isFirefox = function() {
  12667. return detect$1().browser.isFirefox();
  12668. };
  12669. var bindFocus = function(container, handler) {
  12670. if (isFirefox()) {
  12671. return capture(container, "focus", handler);
  12672. } else {
  12673. return bind(container, "focusin", handler);
  12674. }
  12675. };
  12676. var bindBlur = function(container, handler) {
  12677. if (isFirefox()) {
  12678. return capture(container, "blur", handler);
  12679. } else {
  12680. return bind(container, "focusout", handler);
  12681. }
  12682. };
  12683. var setup$d = function(container, rawSettings) {
  12684. var settings = __assign({ stopBackspace: true }, rawSettings);
  12685. var pointerEvents2 = [
  12686. "touchstart",
  12687. "touchmove",
  12688. "touchend",
  12689. "touchcancel",
  12690. "gesturestart",
  12691. "mousedown",
  12692. "mouseup",
  12693. "mouseover",
  12694. "mousemove",
  12695. "mouseout",
  12696. "click"
  12697. ];
  12698. var tapEvent = monitor(settings);
  12699. var simpleEvents = map$2(pointerEvents2.concat([
  12700. "selectstart",
  12701. "input",
  12702. "contextmenu",
  12703. "change",
  12704. "transitionend",
  12705. "transitioncancel",
  12706. "drag",
  12707. "dragstart",
  12708. "dragend",
  12709. "dragenter",
  12710. "dragleave",
  12711. "dragover",
  12712. "drop",
  12713. "keyup"
  12714. ]), function(type2) {
  12715. return bind(container, type2, function(event) {
  12716. tapEvent.fireIfReady(event, type2).each(function(tapStopped) {
  12717. if (tapStopped) {
  12718. event.kill();
  12719. }
  12720. });
  12721. var stopped = settings.triggerEvent(type2, event);
  12722. if (stopped) {
  12723. event.kill();
  12724. }
  12725. });
  12726. });
  12727. var pasteTimeout = value$1();
  12728. var onPaste = bind(container, "paste", function(event) {
  12729. tapEvent.fireIfReady(event, "paste").each(function(tapStopped) {
  12730. if (tapStopped) {
  12731. event.kill();
  12732. }
  12733. });
  12734. var stopped = settings.triggerEvent("paste", event);
  12735. if (stopped) {
  12736. event.kill();
  12737. }
  12738. pasteTimeout.set(setTimeout(function() {
  12739. settings.triggerEvent(postPaste(), event);
  12740. }, 0));
  12741. });
  12742. var onKeydown = bind(container, "keydown", function(event) {
  12743. var stopped = settings.triggerEvent("keydown", event);
  12744. if (stopped) {
  12745. event.kill();
  12746. } else if (settings.stopBackspace && isDangerous(event)) {
  12747. event.prevent();
  12748. }
  12749. });
  12750. var onFocusIn = bindFocus(container, function(event) {
  12751. var stopped = settings.triggerEvent("focusin", event);
  12752. if (stopped) {
  12753. event.kill();
  12754. }
  12755. });
  12756. var focusoutTimeout = value$1();
  12757. var onFocusOut = bindBlur(container, function(event) {
  12758. var stopped = settings.triggerEvent("focusout", event);
  12759. if (stopped) {
  12760. event.kill();
  12761. }
  12762. focusoutTimeout.set(setTimeout(function() {
  12763. settings.triggerEvent(postBlur(), event);
  12764. }, 0));
  12765. });
  12766. var unbind2 = function() {
  12767. each$1(simpleEvents, function(e) {
  12768. e.unbind();
  12769. });
  12770. onKeydown.unbind();
  12771. onFocusIn.unbind();
  12772. onFocusOut.unbind();
  12773. onPaste.unbind();
  12774. pasteTimeout.on(clearTimeout);
  12775. focusoutTimeout.on(clearTimeout);
  12776. };
  12777. return { unbind: unbind2 };
  12778. };
  12779. var derive = function(rawEvent, rawTarget) {
  12780. var source = get$e(rawEvent, "target").getOr(rawTarget);
  12781. return Cell(source);
  12782. };
  12783. var fromSource = function(event, source) {
  12784. var stopper2 = Cell(false);
  12785. var cutter2 = Cell(false);
  12786. var stop2 = function() {
  12787. stopper2.set(true);
  12788. };
  12789. var cut = function() {
  12790. cutter2.set(true);
  12791. };
  12792. return {
  12793. stop: stop2,
  12794. cut,
  12795. isStopped: stopper2.get,
  12796. isCut: cutter2.get,
  12797. event,
  12798. setSource: source.set,
  12799. getSource: source.get
  12800. };
  12801. };
  12802. var fromExternal = function(event) {
  12803. var stopper2 = Cell(false);
  12804. var stop2 = function() {
  12805. stopper2.set(true);
  12806. };
  12807. return {
  12808. stop: stop2,
  12809. cut: noop,
  12810. isStopped: stopper2.get,
  12811. isCut: never,
  12812. event,
  12813. setSource: die("Cannot set source of a broadcasted event"),
  12814. getSource: die("Cannot get source of a broadcasted event")
  12815. };
  12816. };
  12817. var adt$1 = Adt.generate([
  12818. { stopped: [] },
  12819. { resume: ["element"] },
  12820. { complete: [] }
  12821. ]);
  12822. var doTriggerHandler = function(lookup2, eventType, rawEvent, target, source, logger) {
  12823. var handler = lookup2(eventType, target);
  12824. var simulatedEvent = fromSource(rawEvent, source);
  12825. return handler.fold(function() {
  12826. logger.logEventNoHandlers(eventType, target);
  12827. return adt$1.complete();
  12828. }, function(handlerInfo) {
  12829. var descHandler = handlerInfo.descHandler;
  12830. var eventHandler2 = getCurried(descHandler);
  12831. eventHandler2(simulatedEvent);
  12832. if (simulatedEvent.isStopped()) {
  12833. logger.logEventStopped(eventType, handlerInfo.element, descHandler.purpose);
  12834. return adt$1.stopped();
  12835. } else if (simulatedEvent.isCut()) {
  12836. logger.logEventCut(eventType, handlerInfo.element, descHandler.purpose);
  12837. return adt$1.complete();
  12838. } else {
  12839. return parent(handlerInfo.element).fold(function() {
  12840. logger.logNoParent(eventType, handlerInfo.element, descHandler.purpose);
  12841. return adt$1.complete();
  12842. }, function(parent2) {
  12843. logger.logEventResponse(eventType, handlerInfo.element, descHandler.purpose);
  12844. return adt$1.resume(parent2);
  12845. });
  12846. }
  12847. });
  12848. };
  12849. var doTriggerOnUntilStopped = function(lookup2, eventType, rawEvent, rawTarget, source, logger) {
  12850. return doTriggerHandler(lookup2, eventType, rawEvent, rawTarget, source, logger).fold(always, function(parent2) {
  12851. return doTriggerOnUntilStopped(lookup2, eventType, rawEvent, parent2, source, logger);
  12852. }, never);
  12853. };
  12854. var triggerHandler = function(lookup2, eventType, rawEvent, target, logger) {
  12855. var source = derive(rawEvent, target);
  12856. return doTriggerHandler(lookup2, eventType, rawEvent, target, source, logger);
  12857. };
  12858. var broadcast = function(listeners, rawEvent, _logger) {
  12859. var simulatedEvent = fromExternal(rawEvent);
  12860. each$1(listeners, function(listener) {
  12861. var descHandler = listener.descHandler;
  12862. var handler = getCurried(descHandler);
  12863. handler(simulatedEvent);
  12864. });
  12865. return simulatedEvent.isStopped();
  12866. };
  12867. var triggerUntilStopped = function(lookup2, eventType, rawEvent, logger) {
  12868. return triggerOnUntilStopped(lookup2, eventType, rawEvent, rawEvent.target, logger);
  12869. };
  12870. var triggerOnUntilStopped = function(lookup2, eventType, rawEvent, rawTarget, logger) {
  12871. var source = derive(rawEvent, rawTarget);
  12872. return doTriggerOnUntilStopped(lookup2, eventType, rawEvent, rawTarget, source, logger);
  12873. };
  12874. var eventHandler = function(element2, descHandler) {
  12875. return {
  12876. element: element2,
  12877. descHandler
  12878. };
  12879. };
  12880. var broadcastHandler = function(id, handler) {
  12881. return {
  12882. id,
  12883. descHandler: handler
  12884. };
  12885. };
  12886. var EventRegistry = function() {
  12887. var registry = {};
  12888. var registerId = function(extraArgs, id, events2) {
  12889. each(events2, function(v, k) {
  12890. var handlers2 = registry[k] !== void 0 ? registry[k] : {};
  12891. handlers2[id] = curryArgs(v, extraArgs);
  12892. registry[k] = handlers2;
  12893. });
  12894. };
  12895. var findHandler = function(handlers2, elem) {
  12896. return read$1(elem).bind(function(id) {
  12897. return get$e(handlers2, id);
  12898. }).map(function(descHandler) {
  12899. return eventHandler(elem, descHandler);
  12900. });
  12901. };
  12902. var filterByType = function(type2) {
  12903. return get$e(registry, type2).map(function(handlers2) {
  12904. return mapToArray(handlers2, function(f, id) {
  12905. return broadcastHandler(id, f);
  12906. });
  12907. }).getOr([]);
  12908. };
  12909. var find2 = function(isAboveRoot, type2, target) {
  12910. return get$e(registry, type2).bind(function(handlers2) {
  12911. return closest$4(target, function(elem) {
  12912. return findHandler(handlers2, elem);
  12913. }, isAboveRoot);
  12914. });
  12915. };
  12916. var unregisterId = function(id) {
  12917. each(registry, function(handlersById, _eventName) {
  12918. if (has$2(handlersById, id)) {
  12919. delete handlersById[id];
  12920. }
  12921. });
  12922. };
  12923. return {
  12924. registerId,
  12925. unregisterId,
  12926. filterByType,
  12927. find: find2
  12928. };
  12929. };
  12930. var Registry = function() {
  12931. var events2 = EventRegistry();
  12932. var components2 = {};
  12933. var readOrTag = function(component) {
  12934. var elem = component.element;
  12935. return read$1(elem).getOrThunk(function() {
  12936. return write("uid-", component.element);
  12937. });
  12938. };
  12939. var failOnDuplicate = function(component, tagId) {
  12940. var conflict = components2[tagId];
  12941. if (conflict === component) {
  12942. unregister(component);
  12943. } else {
  12944. 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");
  12945. }
  12946. };
  12947. var register2 = function(component) {
  12948. var tagId = readOrTag(component);
  12949. if (hasNonNullableKey(components2, tagId)) {
  12950. failOnDuplicate(component, tagId);
  12951. }
  12952. var extraArgs = [component];
  12953. events2.registerId(extraArgs, tagId, component.events);
  12954. components2[tagId] = component;
  12955. };
  12956. var unregister = function(component) {
  12957. read$1(component.element).each(function(tagId) {
  12958. delete components2[tagId];
  12959. events2.unregisterId(tagId);
  12960. });
  12961. };
  12962. var filter2 = function(type2) {
  12963. return events2.filterByType(type2);
  12964. };
  12965. var find2 = function(isAboveRoot, type2, target) {
  12966. return events2.find(isAboveRoot, type2, target);
  12967. };
  12968. var getById = function(id) {
  12969. return get$e(components2, id);
  12970. };
  12971. return {
  12972. find: find2,
  12973. filter: filter2,
  12974. register: register2,
  12975. unregister,
  12976. getById
  12977. };
  12978. };
  12979. var factory$j = function(detail) {
  12980. var _a2 = detail.dom, attributes = _a2.attributes, domWithoutAttributes = __rest(_a2, ["attributes"]);
  12981. return {
  12982. uid: detail.uid,
  12983. dom: __assign({
  12984. tag: "div",
  12985. attributes: __assign({ role: "presentation" }, attributes)
  12986. }, domWithoutAttributes),
  12987. components: detail.components,
  12988. behaviours: get$2(detail.containerBehaviours),
  12989. events: detail.events,
  12990. domModification: detail.domModification,
  12991. eventOrder: detail.eventOrder
  12992. };
  12993. };
  12994. var Container = single({
  12995. name: "Container",
  12996. factory: factory$j,
  12997. configFields: [
  12998. defaulted("components", []),
  12999. field("containerBehaviours", []),
  13000. defaulted("events", {}),
  13001. defaulted("domModification", {}),
  13002. defaulted("eventOrder", {})
  13003. ]
  13004. });
  13005. var takeover = function(root) {
  13006. var isAboveRoot = function(el) {
  13007. return parent(root.element).fold(always, function(parent2) {
  13008. return eq(el, parent2);
  13009. });
  13010. };
  13011. var registry = Registry();
  13012. var lookup2 = function(eventName, target) {
  13013. return registry.find(isAboveRoot, eventName, target);
  13014. };
  13015. var domEvents = setup$d(root.element, {
  13016. triggerEvent: function(eventName, event) {
  13017. return monitorEvent(eventName, event.target, function(logger) {
  13018. return triggerUntilStopped(lookup2, eventName, event, logger);
  13019. });
  13020. }
  13021. });
  13022. var systemApi = {
  13023. debugInfo: constant$1("real"),
  13024. triggerEvent: function(eventName, target, data) {
  13025. monitorEvent(eventName, target, function(logger) {
  13026. return triggerOnUntilStopped(lookup2, eventName, data, target, logger);
  13027. });
  13028. },
  13029. triggerFocus: function(target, originator) {
  13030. read$1(target).fold(function() {
  13031. focus$3(target);
  13032. }, function(_alloyId) {
  13033. monitorEvent(focus$4(), target, function(logger) {
  13034. triggerHandler(lookup2, focus$4(), {
  13035. originator,
  13036. kill: noop,
  13037. prevent: noop,
  13038. target
  13039. }, target, logger);
  13040. return false;
  13041. });
  13042. });
  13043. },
  13044. triggerEscape: function(comp, simulatedEvent) {
  13045. systemApi.triggerEvent("keydown", comp.element, simulatedEvent.event);
  13046. },
  13047. getByUid: function(uid) {
  13048. return getByUid(uid);
  13049. },
  13050. getByDom: function(elem) {
  13051. return getByDom(elem);
  13052. },
  13053. build: build$1,
  13054. addToGui: function(c) {
  13055. add2(c);
  13056. },
  13057. removeFromGui: function(c) {
  13058. remove2(c);
  13059. },
  13060. addToWorld: function(c) {
  13061. addToWorld(c);
  13062. },
  13063. removeFromWorld: function(c) {
  13064. removeFromWorld(c);
  13065. },
  13066. broadcast: function(message) {
  13067. broadcast$1(message);
  13068. },
  13069. broadcastOn: function(channels, message) {
  13070. broadcastOn(channels, message);
  13071. },
  13072. broadcastEvent: function(eventName, event) {
  13073. broadcastEvent(eventName, event);
  13074. },
  13075. isConnected: always
  13076. };
  13077. var addToWorld = function(component) {
  13078. component.connect(systemApi);
  13079. if (!isText$1(component.element)) {
  13080. registry.register(component);
  13081. each$1(component.components(), addToWorld);
  13082. systemApi.triggerEvent(systemInit(), component.element, { target: component.element });
  13083. }
  13084. };
  13085. var removeFromWorld = function(component) {
  13086. if (!isText$1(component.element)) {
  13087. each$1(component.components(), removeFromWorld);
  13088. registry.unregister(component);
  13089. }
  13090. component.disconnect();
  13091. };
  13092. var add2 = function(component) {
  13093. attach(root, component);
  13094. };
  13095. var remove2 = function(component) {
  13096. detach(component);
  13097. };
  13098. var destroy = function() {
  13099. domEvents.unbind();
  13100. remove$5(root.element);
  13101. };
  13102. var broadcastData = function(data) {
  13103. var receivers = registry.filter(receive());
  13104. each$1(receivers, function(receiver) {
  13105. var descHandler = receiver.descHandler;
  13106. var handler = getCurried(descHandler);
  13107. handler(data);
  13108. });
  13109. };
  13110. var broadcast$1 = function(message) {
  13111. broadcastData({
  13112. universal: true,
  13113. data: message
  13114. });
  13115. };
  13116. var broadcastOn = function(channels, message) {
  13117. broadcastData({
  13118. universal: false,
  13119. channels,
  13120. data: message
  13121. });
  13122. };
  13123. var broadcastEvent = function(eventName, event) {
  13124. var listeners = registry.filter(eventName);
  13125. return broadcast(listeners, event);
  13126. };
  13127. var getByUid = function(uid) {
  13128. return registry.getById(uid).fold(function() {
  13129. return Result.error(new Error('Could not find component with uid: "' + uid + '" in system.'));
  13130. }, Result.value);
  13131. };
  13132. var getByDom = function(elem) {
  13133. var uid = read$1(elem).getOr("not found");
  13134. return getByUid(uid);
  13135. };
  13136. addToWorld(root);
  13137. return {
  13138. root,
  13139. element: root.element,
  13140. destroy,
  13141. add: add2,
  13142. remove: remove2,
  13143. getByUid,
  13144. getByDom,
  13145. addToWorld,
  13146. removeFromWorld,
  13147. broadcast: broadcast$1,
  13148. broadcastOn,
  13149. broadcastEvent
  13150. };
  13151. };
  13152. var renderBar = function(spec, backstage) {
  13153. return {
  13154. dom: {
  13155. tag: "div",
  13156. classes: [
  13157. "tox-bar",
  13158. "tox-form__controls-h-stack"
  13159. ]
  13160. },
  13161. components: map$2(spec.items, backstage.interpreter)
  13162. };
  13163. };
  13164. var schema$l = constant$1([
  13165. defaulted("prefix", "form-field"),
  13166. field("fieldBehaviours", [
  13167. Composing,
  13168. Representing
  13169. ])
  13170. ]);
  13171. var parts$e = constant$1([
  13172. optional({
  13173. schema: [required$1("dom")],
  13174. name: "label"
  13175. }),
  13176. optional({
  13177. factory: {
  13178. sketch: function(spec) {
  13179. return {
  13180. uid: spec.uid,
  13181. dom: {
  13182. tag: "span",
  13183. styles: { display: "none" },
  13184. attributes: { "aria-hidden": "true" },
  13185. innerHtml: spec.text
  13186. }
  13187. };
  13188. }
  13189. },
  13190. schema: [required$1("text")],
  13191. name: "aria-descriptor"
  13192. }),
  13193. required({
  13194. factory: {
  13195. sketch: function(spec) {
  13196. var excludeFactory = exclude(spec, ["factory"]);
  13197. return spec.factory.sketch(excludeFactory);
  13198. }
  13199. },
  13200. schema: [required$1("factory")],
  13201. name: "field"
  13202. })
  13203. ]);
  13204. var factory$i = function(detail, components2, _spec, _externals) {
  13205. var behaviours2 = augment(detail.fieldBehaviours, [
  13206. Composing.config({
  13207. find: function(container) {
  13208. return getPart(container, detail, "field");
  13209. }
  13210. }),
  13211. Representing.config({
  13212. store: {
  13213. mode: "manual",
  13214. getValue: function(field2) {
  13215. return Composing.getCurrent(field2).bind(Representing.getValue);
  13216. },
  13217. setValue: function(field2, value2) {
  13218. Composing.getCurrent(field2).each(function(current) {
  13219. Representing.setValue(current, value2);
  13220. });
  13221. }
  13222. }
  13223. })
  13224. ]);
  13225. var events2 = derive$2([runOnAttached(function(component, _simulatedEvent) {
  13226. var ps = getParts(component, detail, [
  13227. "label",
  13228. "field",
  13229. "aria-descriptor"
  13230. ]);
  13231. ps.field().each(function(field2) {
  13232. var id = generate$6(detail.prefix);
  13233. ps.label().each(function(label) {
  13234. set$8(label.element, "for", id);
  13235. set$8(field2.element, "id", id);
  13236. });
  13237. ps["aria-descriptor"]().each(function(descriptor) {
  13238. var descriptorId = generate$6(detail.prefix);
  13239. set$8(descriptor.element, "id", descriptorId);
  13240. set$8(field2.element, "aria-describedby", descriptorId);
  13241. });
  13242. });
  13243. })]);
  13244. var apis = {
  13245. getField: function(container) {
  13246. return getPart(container, detail, "field");
  13247. },
  13248. getLabel: function(container) {
  13249. return getPart(container, detail, "label");
  13250. }
  13251. };
  13252. return {
  13253. uid: detail.uid,
  13254. dom: detail.dom,
  13255. components: components2,
  13256. behaviours: behaviours2,
  13257. events: events2,
  13258. apis
  13259. };
  13260. };
  13261. var FormField = composite({
  13262. name: "FormField",
  13263. configFields: schema$l(),
  13264. partFields: parts$e(),
  13265. factory: factory$i,
  13266. apis: {
  13267. getField: function(apis, comp) {
  13268. return apis.getField(comp);
  13269. },
  13270. getLabel: function(apis, comp) {
  13271. return apis.getLabel(comp);
  13272. }
  13273. }
  13274. });
  13275. var exhibit$2 = function(base2, tabConfig) {
  13276. return nu$7({
  13277. attributes: wrapAll([{
  13278. key: tabConfig.tabAttr,
  13279. value: "true"
  13280. }])
  13281. });
  13282. };
  13283. var ActiveTabstopping = Object.freeze({
  13284. __proto__: null,
  13285. exhibit: exhibit$2
  13286. });
  13287. var TabstopSchema = [defaulted("tabAttr", "data-alloy-tabstop")];
  13288. var Tabstopping = create$8({
  13289. fields: TabstopSchema,
  13290. name: "tabstopping",
  13291. active: ActiveTabstopping
  13292. });
  13293. var global$7 = tinymce.util.Tools.resolve("tinymce.html.Entities");
  13294. var renderFormFieldWith = function(pLabel, pField, extraClasses, extraBehaviours) {
  13295. var spec = renderFormFieldSpecWith(pLabel, pField, extraClasses, extraBehaviours);
  13296. return FormField.sketch(spec);
  13297. };
  13298. var renderFormField = function(pLabel, pField) {
  13299. return renderFormFieldWith(pLabel, pField, [], []);
  13300. };
  13301. var renderFormFieldSpecWith = function(pLabel, pField, extraClasses, extraBehaviours) {
  13302. return {
  13303. dom: renderFormFieldDomWith(extraClasses),
  13304. components: pLabel.toArray().concat([pField]),
  13305. fieldBehaviours: derive$1(extraBehaviours)
  13306. };
  13307. };
  13308. var renderFormFieldDom = function() {
  13309. return renderFormFieldDomWith([]);
  13310. };
  13311. var renderFormFieldDomWith = function(extraClasses) {
  13312. return {
  13313. tag: "div",
  13314. classes: ["tox-form__group"].concat(extraClasses)
  13315. };
  13316. };
  13317. var renderLabel$2 = function(label, providersBackstage) {
  13318. return FormField.parts.label({
  13319. dom: {
  13320. tag: "label",
  13321. classes: ["tox-label"],
  13322. innerHtml: providersBackstage.translate(label)
  13323. }
  13324. });
  13325. };
  13326. var formChangeEvent = generate$6("form-component-change");
  13327. var formCloseEvent = generate$6("form-close");
  13328. var formCancelEvent = generate$6("form-cancel");
  13329. var formActionEvent = generate$6("form-action");
  13330. var formSubmitEvent = generate$6("form-submit");
  13331. var formBlockEvent = generate$6("form-block");
  13332. var formUnblockEvent = generate$6("form-unblock");
  13333. var formTabChangeEvent = generate$6("form-tabchange");
  13334. var formResizeEvent = generate$6("form-resize");
  13335. var renderCollection = function(spec, providersBackstage) {
  13336. var _a2;
  13337. var pLabel = spec.label.map(function(label) {
  13338. return renderLabel$2(label, providersBackstage);
  13339. });
  13340. var runOnItem = function(f) {
  13341. return function(comp, se) {
  13342. closest$1(se.event.target, "[data-collection-item-value]").each(function(target) {
  13343. f(comp, se, target, get$d(target, "data-collection-item-value"));
  13344. });
  13345. };
  13346. };
  13347. var setContents = function(comp, items) {
  13348. var htmlLines = map$2(items, function(item2) {
  13349. var itemText = global$e.translate(item2.text);
  13350. var textContent = spec.columns === 1 ? '<div class="tox-collection__item-label">' + itemText + "</div>" : "";
  13351. var iconContent = '<div class="tox-collection__item-icon">' + item2.icon + "</div>";
  13352. var mapItemName = {
  13353. "_": " ",
  13354. " - ": " ",
  13355. "-": " "
  13356. };
  13357. var ariaLabel = itemText.replace(/\_| \- |\-/g, function(match) {
  13358. return mapItemName[match];
  13359. });
  13360. var disabledClass = providersBackstage.isDisabled() ? " tox-collection__item--state-disabled" : "";
  13361. 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>";
  13362. });
  13363. var chunks = spec.columns !== "auto" && spec.columns > 1 ? chunk$1(htmlLines, spec.columns) : [htmlLines];
  13364. var html2 = map$2(chunks, function(ch) {
  13365. return '<div class="tox-collection__group">' + ch.join("") + "</div>";
  13366. });
  13367. set$5(comp.element, html2.join(""));
  13368. };
  13369. var onClick = runOnItem(function(comp, se, tgt, itemValue) {
  13370. se.stop();
  13371. if (!providersBackstage.isDisabled()) {
  13372. emitWith(comp, formActionEvent, {
  13373. name: spec.name,
  13374. value: itemValue
  13375. });
  13376. }
  13377. });
  13378. var collectionEvents = [
  13379. run$1(mouseover(), runOnItem(function(comp, se, tgt) {
  13380. focus$3(tgt);
  13381. })),
  13382. run$1(click(), onClick),
  13383. run$1(tap(), onClick),
  13384. run$1(focusin(), runOnItem(function(comp, se, tgt) {
  13385. descendant(comp.element, "." + activeClass).each(function(currentActive) {
  13386. remove$2(currentActive, activeClass);
  13387. });
  13388. add$2(tgt, activeClass);
  13389. })),
  13390. run$1(focusout(), runOnItem(function(comp) {
  13391. descendant(comp.element, "." + activeClass).each(function(currentActive) {
  13392. remove$2(currentActive, activeClass);
  13393. });
  13394. })),
  13395. runOnExecute$1(runOnItem(function(comp, se, tgt, itemValue) {
  13396. emitWith(comp, formActionEvent, {
  13397. name: spec.name,
  13398. value: itemValue
  13399. });
  13400. }))
  13401. ];
  13402. var iterCollectionItems = function(comp, applyAttributes) {
  13403. return map$2(descendants(comp.element, ".tox-collection__item"), applyAttributes);
  13404. };
  13405. var pField = FormField.parts.field({
  13406. dom: {
  13407. tag: "div",
  13408. classes: ["tox-collection"].concat(spec.columns !== 1 ? ["tox-collection--grid"] : ["tox-collection--list"])
  13409. },
  13410. components: [],
  13411. factory: { sketch: identity$1 },
  13412. behaviours: derive$1([
  13413. Disabling.config({
  13414. disabled: providersBackstage.isDisabled,
  13415. onDisabled: function(comp) {
  13416. iterCollectionItems(comp, function(childElm) {
  13417. add$2(childElm, "tox-collection__item--state-disabled");
  13418. set$8(childElm, "aria-disabled", true);
  13419. });
  13420. },
  13421. onEnabled: function(comp) {
  13422. iterCollectionItems(comp, function(childElm) {
  13423. remove$2(childElm, "tox-collection__item--state-disabled");
  13424. remove$7(childElm, "aria-disabled");
  13425. });
  13426. }
  13427. }),
  13428. receivingConfig(),
  13429. Replacing.config({}),
  13430. Representing.config({
  13431. store: {
  13432. mode: "memory",
  13433. initialValue: []
  13434. },
  13435. onSetValue: function(comp, items) {
  13436. setContents(comp, items);
  13437. if (spec.columns === "auto") {
  13438. detectSize(comp, 5, "tox-collection__item").each(function(_a3) {
  13439. var numRows = _a3.numRows, numColumns = _a3.numColumns;
  13440. Keying.setGridSize(comp, numRows, numColumns);
  13441. });
  13442. }
  13443. emit(comp, formResizeEvent);
  13444. }
  13445. }),
  13446. Tabstopping.config({}),
  13447. Keying.config(deriveCollectionMovement(spec.columns, "normal")),
  13448. config("collection-events", collectionEvents)
  13449. ]),
  13450. eventOrder: (_a2 = {}, _a2[execute$5()] = [
  13451. "disabling",
  13452. "alloy.base.behaviour",
  13453. "collection-events"
  13454. ], _a2)
  13455. });
  13456. var extraClasses = ["tox-form__group--collection"];
  13457. return renderFormFieldWith(pLabel, pField, extraClasses, []);
  13458. };
  13459. var schema$k = constant$1([
  13460. option("data"),
  13461. defaulted("inputAttributes", {}),
  13462. defaulted("inputStyles", {}),
  13463. defaulted("tag", "input"),
  13464. defaulted("inputClasses", []),
  13465. onHandler("onSetValue"),
  13466. defaulted("styles", {}),
  13467. defaulted("eventOrder", {}),
  13468. field("inputBehaviours", [
  13469. Representing,
  13470. Focusing
  13471. ]),
  13472. defaulted("selectOnFocus", true)
  13473. ]);
  13474. var focusBehaviours = function(detail) {
  13475. return derive$1([Focusing.config({
  13476. onFocus: !detail.selectOnFocus ? noop : function(component) {
  13477. var input2 = component.element;
  13478. var value2 = get$5(input2);
  13479. input2.dom.setSelectionRange(0, value2.length);
  13480. }
  13481. })]);
  13482. };
  13483. var behaviours = function(detail) {
  13484. return __assign(__assign({}, focusBehaviours(detail)), augment(detail.inputBehaviours, [Representing.config({
  13485. store: __assign(__assign({ mode: "manual" }, detail.data.map(function(data) {
  13486. return { initialValue: data };
  13487. }).getOr({})), {
  13488. getValue: function(input2) {
  13489. return get$5(input2.element);
  13490. },
  13491. setValue: function(input2, data) {
  13492. var current = get$5(input2.element);
  13493. if (current !== data) {
  13494. set$4(input2.element, data);
  13495. }
  13496. }
  13497. }),
  13498. onSetValue: detail.onSetValue
  13499. })]));
  13500. };
  13501. var dom = function(detail) {
  13502. return {
  13503. tag: detail.tag,
  13504. attributes: __assign({ type: "text" }, detail.inputAttributes),
  13505. styles: detail.inputStyles,
  13506. classes: detail.inputClasses
  13507. };
  13508. };
  13509. var factory$h = function(detail, _spec) {
  13510. return {
  13511. uid: detail.uid,
  13512. dom: dom(detail),
  13513. components: [],
  13514. behaviours: behaviours(detail),
  13515. eventOrder: detail.eventOrder
  13516. };
  13517. };
  13518. var Input = single({
  13519. name: "Input",
  13520. configFields: schema$k(),
  13521. factory: factory$h
  13522. });
  13523. var exports$1 = {}, module2 = { exports: exports$1 };
  13524. (function(define, exports2, module3, require2) {
  13525. (function(global2, factory2) {
  13526. 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());
  13527. })(this, function() {
  13528. var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  13529. var promise = { exports: {} };
  13530. (function(module4) {
  13531. (function(root) {
  13532. var setTimeoutFunc = setTimeout;
  13533. function noop2() {
  13534. }
  13535. function bind2(fn, thisArg) {
  13536. return function() {
  13537. fn.apply(thisArg, arguments);
  13538. };
  13539. }
  13540. function Promise2(fn) {
  13541. if (typeof this !== "object")
  13542. throw new TypeError("Promises must be constructed via new");
  13543. if (typeof fn !== "function")
  13544. throw new TypeError("not a function");
  13545. this._state = 0;
  13546. this._handled = false;
  13547. this._value = void 0;
  13548. this._deferreds = [];
  13549. doResolve(fn, this);
  13550. }
  13551. function handle2(self2, deferred) {
  13552. while (self2._state === 3) {
  13553. self2 = self2._value;
  13554. }
  13555. if (self2._state === 0) {
  13556. self2._deferreds.push(deferred);
  13557. return;
  13558. }
  13559. self2._handled = true;
  13560. Promise2._immediateFn(function() {
  13561. var cb = self2._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  13562. if (cb === null) {
  13563. (self2._state === 1 ? resolve : reject)(deferred.promise, self2._value);
  13564. return;
  13565. }
  13566. var ret;
  13567. try {
  13568. ret = cb(self2._value);
  13569. } catch (e) {
  13570. reject(deferred.promise, e);
  13571. return;
  13572. }
  13573. resolve(deferred.promise, ret);
  13574. });
  13575. }
  13576. function resolve(self2, newValue) {
  13577. try {
  13578. if (newValue === self2)
  13579. throw new TypeError("A promise cannot be resolved with itself.");
  13580. if (newValue && (typeof newValue === "object" || typeof newValue === "function")) {
  13581. var then = newValue.then;
  13582. if (newValue instanceof Promise2) {
  13583. self2._state = 3;
  13584. self2._value = newValue;
  13585. finale(self2);
  13586. return;
  13587. } else if (typeof then === "function") {
  13588. doResolve(bind2(then, newValue), self2);
  13589. return;
  13590. }
  13591. }
  13592. self2._state = 1;
  13593. self2._value = newValue;
  13594. finale(self2);
  13595. } catch (e) {
  13596. reject(self2, e);
  13597. }
  13598. }
  13599. function reject(self2, newValue) {
  13600. self2._state = 2;
  13601. self2._value = newValue;
  13602. finale(self2);
  13603. }
  13604. function finale(self2) {
  13605. if (self2._state === 2 && self2._deferreds.length === 0) {
  13606. Promise2._immediateFn(function() {
  13607. if (!self2._handled) {
  13608. Promise2._unhandledRejectionFn(self2._value);
  13609. }
  13610. });
  13611. }
  13612. for (var i = 0, len = self2._deferreds.length; i < len; i++) {
  13613. handle2(self2, self2._deferreds[i]);
  13614. }
  13615. self2._deferreds = null;
  13616. }
  13617. function Handler(onFulfilled, onRejected, promise2) {
  13618. this.onFulfilled = typeof onFulfilled === "function" ? onFulfilled : null;
  13619. this.onRejected = typeof onRejected === "function" ? onRejected : null;
  13620. this.promise = promise2;
  13621. }
  13622. function doResolve(fn, self2) {
  13623. var done = false;
  13624. try {
  13625. fn(function(value2) {
  13626. if (done)
  13627. return;
  13628. done = true;
  13629. resolve(self2, value2);
  13630. }, function(reason) {
  13631. if (done)
  13632. return;
  13633. done = true;
  13634. reject(self2, reason);
  13635. });
  13636. } catch (ex) {
  13637. if (done)
  13638. return;
  13639. done = true;
  13640. reject(self2, ex);
  13641. }
  13642. }
  13643. Promise2.prototype["catch"] = function(onRejected) {
  13644. return this.then(null, onRejected);
  13645. };
  13646. Promise2.prototype.then = function(onFulfilled, onRejected) {
  13647. var prom = new this.constructor(noop2);
  13648. handle2(this, new Handler(onFulfilled, onRejected, prom));
  13649. return prom;
  13650. };
  13651. Promise2.all = function(arr) {
  13652. var args = Array.prototype.slice.call(arr);
  13653. return new Promise2(function(resolve2, reject2) {
  13654. if (args.length === 0)
  13655. return resolve2([]);
  13656. var remaining = args.length;
  13657. function res(i2, val) {
  13658. try {
  13659. if (val && (typeof val === "object" || typeof val === "function")) {
  13660. var then = val.then;
  13661. if (typeof then === "function") {
  13662. then.call(val, function(val2) {
  13663. res(i2, val2);
  13664. }, reject2);
  13665. return;
  13666. }
  13667. }
  13668. args[i2] = val;
  13669. if (--remaining === 0) {
  13670. resolve2(args);
  13671. }
  13672. } catch (ex) {
  13673. reject2(ex);
  13674. }
  13675. }
  13676. for (var i = 0; i < args.length; i++) {
  13677. res(i, args[i]);
  13678. }
  13679. });
  13680. };
  13681. Promise2.resolve = function(value2) {
  13682. if (value2 && typeof value2 === "object" && value2.constructor === Promise2) {
  13683. return value2;
  13684. }
  13685. return new Promise2(function(resolve2) {
  13686. resolve2(value2);
  13687. });
  13688. };
  13689. Promise2.reject = function(value2) {
  13690. return new Promise2(function(resolve2, reject2) {
  13691. reject2(value2);
  13692. });
  13693. };
  13694. Promise2.race = function(values2) {
  13695. return new Promise2(function(resolve2, reject2) {
  13696. for (var i = 0, len = values2.length; i < len; i++) {
  13697. values2[i].then(resolve2, reject2);
  13698. }
  13699. });
  13700. };
  13701. Promise2._immediateFn = typeof setImmediate === "function" ? function(fn) {
  13702. setImmediate(fn);
  13703. } : function(fn) {
  13704. setTimeoutFunc(fn, 0);
  13705. };
  13706. Promise2._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  13707. if (typeof console !== "undefined" && console) {
  13708. console.warn("Possible Unhandled Promise Rejection:", err);
  13709. }
  13710. };
  13711. Promise2._setImmediateFn = function _setImmediateFn(fn) {
  13712. Promise2._immediateFn = fn;
  13713. };
  13714. Promise2._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  13715. Promise2._unhandledRejectionFn = fn;
  13716. };
  13717. if (module4.exports) {
  13718. module4.exports = Promise2;
  13719. } else if (!root.Promise) {
  13720. root.Promise = Promise2;
  13721. }
  13722. })(commonjsGlobal);
  13723. })(promise);
  13724. var promisePolyfill = promise.exports;
  13725. var Global = function() {
  13726. if (typeof window !== "undefined") {
  13727. return window;
  13728. } else {
  13729. return Function("return this;")();
  13730. }
  13731. }();
  13732. var promisePolyfill_1 = { boltExport: Global.Promise || promisePolyfill };
  13733. return promisePolyfill_1;
  13734. });
  13735. })(void 0, exports$1, module2);
  13736. var Promise$1 = module2.exports.boltExport;
  13737. var nu$3 = function(baseFn) {
  13738. var data = Optional.none();
  13739. var callbacks = [];
  13740. var map2 = function(f) {
  13741. return nu$3(function(nCallback) {
  13742. get2(function(data2) {
  13743. nCallback(f(data2));
  13744. });
  13745. });
  13746. };
  13747. var get2 = function(nCallback) {
  13748. if (isReady()) {
  13749. call(nCallback);
  13750. } else {
  13751. callbacks.push(nCallback);
  13752. }
  13753. };
  13754. var set2 = function(x) {
  13755. if (!isReady()) {
  13756. data = Optional.some(x);
  13757. run2(callbacks);
  13758. callbacks = [];
  13759. }
  13760. };
  13761. var isReady = function() {
  13762. return data.isSome();
  13763. };
  13764. var run2 = function(cbs) {
  13765. each$1(cbs, call);
  13766. };
  13767. var call = function(cb) {
  13768. data.each(function(x) {
  13769. setTimeout(function() {
  13770. cb(x);
  13771. }, 0);
  13772. });
  13773. };
  13774. baseFn(set2);
  13775. return {
  13776. get: get2,
  13777. map: map2,
  13778. isReady
  13779. };
  13780. };
  13781. var pure$1 = function(a) {
  13782. return nu$3(function(callback) {
  13783. callback(a);
  13784. });
  13785. };
  13786. var LazyValue = {
  13787. nu: nu$3,
  13788. pure: pure$1
  13789. };
  13790. var errorReporter = function(err) {
  13791. setTimeout(function() {
  13792. throw err;
  13793. }, 0);
  13794. };
  13795. var make$5 = function(run2) {
  13796. var get2 = function(callback) {
  13797. run2().then(callback, errorReporter);
  13798. };
  13799. var map2 = function(fab) {
  13800. return make$5(function() {
  13801. return run2().then(fab);
  13802. });
  13803. };
  13804. var bind2 = function(aFutureB) {
  13805. return make$5(function() {
  13806. return run2().then(function(v) {
  13807. return aFutureB(v).toPromise();
  13808. });
  13809. });
  13810. };
  13811. var anonBind = function(futureB) {
  13812. return make$5(function() {
  13813. return run2().then(function() {
  13814. return futureB.toPromise();
  13815. });
  13816. });
  13817. };
  13818. var toLazy = function() {
  13819. return LazyValue.nu(get2);
  13820. };
  13821. var toCached = function() {
  13822. var cache = null;
  13823. return make$5(function() {
  13824. if (cache === null) {
  13825. cache = run2();
  13826. }
  13827. return cache;
  13828. });
  13829. };
  13830. var toPromise = run2;
  13831. return {
  13832. map: map2,
  13833. bind: bind2,
  13834. anonBind,
  13835. toLazy,
  13836. toCached,
  13837. toPromise,
  13838. get: get2
  13839. };
  13840. };
  13841. var nu$2 = function(baseFn) {
  13842. return make$5(function() {
  13843. return new Promise$1(baseFn);
  13844. });
  13845. };
  13846. var pure = function(a) {
  13847. return make$5(function() {
  13848. return Promise$1.resolve(a);
  13849. });
  13850. };
  13851. var Future = {
  13852. nu: nu$2,
  13853. pure
  13854. };
  13855. var ariaElements = [
  13856. "input",
  13857. "textarea"
  13858. ];
  13859. var isAriaElement = function(elem) {
  13860. var name2 = name$2(elem);
  13861. return contains$2(ariaElements, name2);
  13862. };
  13863. var markValid = function(component, invalidConfig) {
  13864. var elem = invalidConfig.getRoot(component).getOr(component.element);
  13865. remove$2(elem, invalidConfig.invalidClass);
  13866. invalidConfig.notify.each(function(notifyInfo) {
  13867. if (isAriaElement(component.element)) {
  13868. set$8(component.element, "aria-invalid", false);
  13869. }
  13870. notifyInfo.getContainer(component).each(function(container) {
  13871. set$5(container, notifyInfo.validHtml);
  13872. });
  13873. notifyInfo.onValid(component);
  13874. });
  13875. };
  13876. var markInvalid = function(component, invalidConfig, invalidState, text2) {
  13877. var elem = invalidConfig.getRoot(component).getOr(component.element);
  13878. add$2(elem, invalidConfig.invalidClass);
  13879. invalidConfig.notify.each(function(notifyInfo) {
  13880. if (isAriaElement(component.element)) {
  13881. set$8(component.element, "aria-invalid", true);
  13882. }
  13883. notifyInfo.getContainer(component).each(function(container) {
  13884. set$5(container, text2);
  13885. });
  13886. notifyInfo.onInvalid(component, text2);
  13887. });
  13888. };
  13889. var query = function(component, invalidConfig, _invalidState) {
  13890. return invalidConfig.validator.fold(function() {
  13891. return Future.pure(Result.value(true));
  13892. }, function(validatorInfo) {
  13893. return validatorInfo.validate(component);
  13894. });
  13895. };
  13896. var run = function(component, invalidConfig, invalidState) {
  13897. invalidConfig.notify.each(function(notifyInfo) {
  13898. notifyInfo.onValidate(component);
  13899. });
  13900. return query(component, invalidConfig).map(function(valid) {
  13901. if (component.getSystem().isConnected()) {
  13902. return valid.fold(function(err) {
  13903. markInvalid(component, invalidConfig, invalidState, err);
  13904. return Result.error(err);
  13905. }, function(v) {
  13906. markValid(component, invalidConfig);
  13907. return Result.value(v);
  13908. });
  13909. } else {
  13910. return Result.error("No longer in system");
  13911. }
  13912. });
  13913. };
  13914. var isInvalid = function(component, invalidConfig) {
  13915. var elem = invalidConfig.getRoot(component).getOr(component.element);
  13916. return has(elem, invalidConfig.invalidClass);
  13917. };
  13918. var InvalidateApis = Object.freeze({
  13919. __proto__: null,
  13920. markValid,
  13921. markInvalid,
  13922. query,
  13923. run,
  13924. isInvalid
  13925. });
  13926. var events$8 = function(invalidConfig, invalidState) {
  13927. return invalidConfig.validator.map(function(validatorInfo) {
  13928. return derive$2([run$1(validatorInfo.onEvent, function(component) {
  13929. run(component, invalidConfig, invalidState).get(identity$1);
  13930. })].concat(validatorInfo.validateOnLoad ? [runOnAttached(function(component) {
  13931. run(component, invalidConfig, invalidState).get(noop);
  13932. })] : []));
  13933. }).getOr({});
  13934. };
  13935. var ActiveInvalidate = Object.freeze({
  13936. __proto__: null,
  13937. events: events$8
  13938. });
  13939. var InvalidateSchema = [
  13940. required$1("invalidClass"),
  13941. defaulted("getRoot", Optional.none),
  13942. optionObjOf("notify", [
  13943. defaulted("aria", "alert"),
  13944. defaulted("getContainer", Optional.none),
  13945. defaulted("validHtml", ""),
  13946. onHandler("onValid"),
  13947. onHandler("onInvalid"),
  13948. onHandler("onValidate")
  13949. ]),
  13950. optionObjOf("validator", [
  13951. required$1("validate"),
  13952. defaulted("onEvent", "input"),
  13953. defaulted("validateOnLoad", true)
  13954. ])
  13955. ];
  13956. var Invalidating = create$8({
  13957. fields: InvalidateSchema,
  13958. name: "invalidating",
  13959. active: ActiveInvalidate,
  13960. apis: InvalidateApis,
  13961. extra: {
  13962. validation: function(validator) {
  13963. return function(component) {
  13964. var v = Representing.getValue(component);
  13965. return Future.pure(validator(v));
  13966. };
  13967. }
  13968. }
  13969. });
  13970. var getCoupled = function(component, coupleConfig, coupleState, name2) {
  13971. return coupleState.getOrCreate(component, coupleConfig, name2);
  13972. };
  13973. var CouplingApis = Object.freeze({
  13974. __proto__: null,
  13975. getCoupled
  13976. });
  13977. var CouplingSchema = [requiredOf("others", setOf(Result.value, anyValue()))];
  13978. var init$a = function() {
  13979. var coupled = {};
  13980. var getOrCreate = function(component, coupleConfig, name2) {
  13981. var available = keys(coupleConfig.others);
  13982. if (!available) {
  13983. throw new Error("Cannot find coupled component: " + name2 + ". Known coupled components: " + JSON.stringify(available, null, 2));
  13984. } else {
  13985. return get$e(coupled, name2).getOrThunk(function() {
  13986. var builder2 = get$e(coupleConfig.others, name2).getOrDie("No information found for coupled component: " + name2);
  13987. var spec = builder2(component);
  13988. var built = component.getSystem().build(spec);
  13989. coupled[name2] = built;
  13990. return built;
  13991. });
  13992. }
  13993. };
  13994. var readState = constant$1({});
  13995. return nu$8({
  13996. readState,
  13997. getOrCreate
  13998. });
  13999. };
  14000. var CouplingState = Object.freeze({
  14001. __proto__: null,
  14002. init: init$a
  14003. });
  14004. var Coupling = create$8({
  14005. fields: CouplingSchema,
  14006. name: "coupling",
  14007. apis: CouplingApis,
  14008. state: CouplingState
  14009. });
  14010. var suffix = constant$1("sink");
  14011. var partType$1 = constant$1(optional({
  14012. name: suffix(),
  14013. overrides: constant$1({
  14014. dom: { tag: "div" },
  14015. behaviours: derive$1([Positioning.config({ useFixed: always })]),
  14016. events: derive$2([
  14017. cutter(keydown()),
  14018. cutter(mousedown()),
  14019. cutter(click())
  14020. ])
  14021. })
  14022. }));
  14023. var HighlightOnOpen;
  14024. (function(HighlightOnOpen2) {
  14025. HighlightOnOpen2[HighlightOnOpen2["HighlightFirst"] = 0] = "HighlightFirst";
  14026. HighlightOnOpen2[HighlightOnOpen2["HighlightNone"] = 1] = "HighlightNone";
  14027. })(HighlightOnOpen || (HighlightOnOpen = {}));
  14028. var getAnchor = function(detail, component) {
  14029. var hotspot = detail.getHotspot(component).getOr(component);
  14030. var type2 = "hotspot";
  14031. var overrides = detail.getAnchorOverrides();
  14032. return detail.layouts.fold(function() {
  14033. return {
  14034. type: type2,
  14035. hotspot,
  14036. overrides
  14037. };
  14038. }, function(layouts2) {
  14039. return {
  14040. type: type2,
  14041. hotspot,
  14042. overrides,
  14043. layouts: layouts2
  14044. };
  14045. });
  14046. };
  14047. var fetch = function(detail, mapFetch, component) {
  14048. var fetcher = detail.fetch;
  14049. return fetcher(component).map(mapFetch);
  14050. };
  14051. var openF = function(detail, mapFetch, anchor2, component, sandbox, externals, highlightOnOpen) {
  14052. var futureData = fetch(detail, mapFetch, component);
  14053. var getLazySink = getSink(component, detail);
  14054. return futureData.map(function(tdata) {
  14055. return tdata.bind(function(data) {
  14056. return Optional.from(tieredMenu.sketch(__assign(__assign({}, externals.menu()), {
  14057. uid: generate$5(""),
  14058. data,
  14059. highlightImmediately: highlightOnOpen === HighlightOnOpen.HighlightFirst,
  14060. onOpenMenu: function(tmenu, menu2) {
  14061. var sink = getLazySink().getOrDie();
  14062. Positioning.position(sink, menu2, { anchor: anchor2 });
  14063. Sandboxing.decloak(sandbox);
  14064. },
  14065. onOpenSubmenu: function(tmenu, item2, submenu) {
  14066. var sink = getLazySink().getOrDie();
  14067. Positioning.position(sink, submenu, {
  14068. anchor: {
  14069. type: "submenu",
  14070. item: item2
  14071. }
  14072. });
  14073. Sandboxing.decloak(sandbox);
  14074. },
  14075. onRepositionMenu: function(tmenu, primaryMenu, submenuTriggers) {
  14076. var sink = getLazySink().getOrDie();
  14077. Positioning.position(sink, primaryMenu, { anchor: anchor2 });
  14078. each$1(submenuTriggers, function(st) {
  14079. Positioning.position(sink, st.triggeredMenu, {
  14080. anchor: {
  14081. type: "submenu",
  14082. item: st.triggeringItem
  14083. }
  14084. });
  14085. });
  14086. },
  14087. onEscape: function() {
  14088. Focusing.focus(component);
  14089. Sandboxing.close(sandbox);
  14090. return Optional.some(true);
  14091. }
  14092. })));
  14093. });
  14094. });
  14095. };
  14096. var open = function(detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen) {
  14097. var anchor2 = getAnchor(detail, hotspot);
  14098. var processed = openF(detail, mapFetch, anchor2, hotspot, sandbox, externals, highlightOnOpen);
  14099. return processed.map(function(tdata) {
  14100. tdata.fold(function() {
  14101. if (Sandboxing.isOpen(sandbox)) {
  14102. Sandboxing.close(sandbox);
  14103. }
  14104. }, function(data) {
  14105. Sandboxing.cloak(sandbox);
  14106. Sandboxing.open(sandbox, data);
  14107. onOpenSync(sandbox);
  14108. });
  14109. return sandbox;
  14110. });
  14111. };
  14112. var close = function(detail, mapFetch, component, sandbox, _externals, _onOpenSync, _highlightOnOpen) {
  14113. Sandboxing.close(sandbox);
  14114. return Future.pure(sandbox);
  14115. };
  14116. var togglePopup = function(detail, mapFetch, hotspot, externals, onOpenSync, highlightOnOpen) {
  14117. var sandbox = Coupling.getCoupled(hotspot, "sandbox");
  14118. var showing = Sandboxing.isOpen(sandbox);
  14119. var action = showing ? close : open;
  14120. return action(detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen);
  14121. };
  14122. var matchWidth = function(hotspot, container, useMinWidth) {
  14123. var menu2 = Composing.getCurrent(container).getOr(container);
  14124. var buttonWidth = get$a(hotspot.element);
  14125. if (useMinWidth) {
  14126. set$7(menu2.element, "min-width", buttonWidth + "px");
  14127. } else {
  14128. set$6(menu2.element, buttonWidth);
  14129. }
  14130. };
  14131. var getSink = function(anyInSystem, sinkDetail) {
  14132. return anyInSystem.getSystem().getByUid(sinkDetail.uid + "-" + suffix()).map(function(internalSink) {
  14133. return function() {
  14134. return Result.value(internalSink);
  14135. };
  14136. }).getOrThunk(function() {
  14137. return sinkDetail.lazySink.fold(function() {
  14138. return function() {
  14139. return Result.error(new Error("No internal sink is specified, nor could an external sink be found"));
  14140. };
  14141. }, function(lazySinkFn) {
  14142. return function() {
  14143. return lazySinkFn(anyInSystem);
  14144. };
  14145. });
  14146. });
  14147. };
  14148. var doRepositionMenus = function(sandbox) {
  14149. Sandboxing.getState(sandbox).each(function(tmenu) {
  14150. tieredMenu.repositionMenus(tmenu);
  14151. });
  14152. };
  14153. var makeSandbox$1 = function(detail, hotspot, extras) {
  14154. var ariaOwner = manager();
  14155. var onOpen = function(component, menu2) {
  14156. var anchor2 = getAnchor(detail, hotspot);
  14157. ariaOwner.link(hotspot.element);
  14158. if (detail.matchWidth) {
  14159. matchWidth(anchor2.hotspot, menu2, detail.useMinWidth);
  14160. }
  14161. detail.onOpen(anchor2, component, menu2);
  14162. if (extras !== void 0 && extras.onOpen !== void 0) {
  14163. extras.onOpen(component, menu2);
  14164. }
  14165. };
  14166. var onClose = function(component, menu2) {
  14167. ariaOwner.unlink(hotspot.element);
  14168. if (extras !== void 0 && extras.onClose !== void 0) {
  14169. extras.onClose(component, menu2);
  14170. }
  14171. };
  14172. var lazySink = getSink(hotspot, detail);
  14173. return {
  14174. dom: {
  14175. tag: "div",
  14176. classes: detail.sandboxClasses,
  14177. attributes: {
  14178. id: ariaOwner.id,
  14179. role: "listbox"
  14180. }
  14181. },
  14182. behaviours: SketchBehaviours.augment(detail.sandboxBehaviours, [
  14183. Representing.config({
  14184. store: {
  14185. mode: "memory",
  14186. initialValue: hotspot
  14187. }
  14188. }),
  14189. Sandboxing.config({
  14190. onOpen,
  14191. onClose,
  14192. isPartOf: function(container, data, queryElem) {
  14193. return isPartOf$1(data, queryElem) || isPartOf$1(hotspot, queryElem);
  14194. },
  14195. getAttachPoint: function() {
  14196. return lazySink().getOrDie();
  14197. }
  14198. }),
  14199. Composing.config({
  14200. find: function(sandbox) {
  14201. return Sandboxing.getState(sandbox).bind(function(menu2) {
  14202. return Composing.getCurrent(menu2);
  14203. });
  14204. }
  14205. }),
  14206. Receiving.config({ channels: __assign(__assign({}, receivingChannel$1({ isExtraPart: never })), receivingChannel({ doReposition: doRepositionMenus })) })
  14207. ])
  14208. };
  14209. };
  14210. var repositionMenus = function(comp) {
  14211. var sandbox = Coupling.getCoupled(comp, "sandbox");
  14212. doRepositionMenus(sandbox);
  14213. };
  14214. var sandboxFields = function() {
  14215. return [
  14216. defaulted("sandboxClasses", []),
  14217. SketchBehaviours.field("sandboxBehaviours", [
  14218. Composing,
  14219. Receiving,
  14220. Sandboxing,
  14221. Representing
  14222. ])
  14223. ];
  14224. };
  14225. var schema$j = constant$1([
  14226. required$1("dom"),
  14227. required$1("fetch"),
  14228. onHandler("onOpen"),
  14229. onKeyboardHandler("onExecute"),
  14230. defaulted("getHotspot", Optional.some),
  14231. defaulted("getAnchorOverrides", constant$1({})),
  14232. schema$y(),
  14233. field("dropdownBehaviours", [
  14234. Toggling,
  14235. Coupling,
  14236. Keying,
  14237. Focusing
  14238. ]),
  14239. required$1("toggleClass"),
  14240. defaulted("eventOrder", {}),
  14241. option("lazySink"),
  14242. defaulted("matchWidth", false),
  14243. defaulted("useMinWidth", false),
  14244. option("role")
  14245. ].concat(sandboxFields()));
  14246. var parts$d = constant$1([
  14247. external$1({
  14248. schema: [tieredMenuMarkers()],
  14249. name: "menu",
  14250. defaults: function(detail) {
  14251. return { onExecute: detail.onExecute };
  14252. }
  14253. }),
  14254. partType$1()
  14255. ]);
  14256. var factory$g = function(detail, components2, _spec, externals) {
  14257. var _a2;
  14258. var lookupAttr = function(attr) {
  14259. return get$e(detail.dom, "attributes").bind(function(attrs) {
  14260. return get$e(attrs, attr);
  14261. });
  14262. };
  14263. var switchToMenu = function(sandbox) {
  14264. Sandboxing.getState(sandbox).each(function(tmenu) {
  14265. tieredMenu.highlightPrimary(tmenu);
  14266. });
  14267. };
  14268. var action = function(component) {
  14269. var onOpenSync = switchToMenu;
  14270. togglePopup(detail, identity$1, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  14271. };
  14272. var apis = {
  14273. expand: function(comp) {
  14274. if (!Toggling.isOn(comp)) {
  14275. togglePopup(detail, identity$1, comp, externals, noop, HighlightOnOpen.HighlightNone).get(noop);
  14276. }
  14277. },
  14278. open: function(comp) {
  14279. if (!Toggling.isOn(comp)) {
  14280. togglePopup(detail, identity$1, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
  14281. }
  14282. },
  14283. isOpen: Toggling.isOn,
  14284. close: function(comp) {
  14285. if (Toggling.isOn(comp)) {
  14286. togglePopup(detail, identity$1, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
  14287. }
  14288. },
  14289. repositionMenus: function(comp) {
  14290. if (Toggling.isOn(comp)) {
  14291. repositionMenus(comp);
  14292. }
  14293. }
  14294. };
  14295. var triggerExecute = function(comp, _se) {
  14296. emitExecute(comp);
  14297. return Optional.some(true);
  14298. };
  14299. return {
  14300. uid: detail.uid,
  14301. dom: detail.dom,
  14302. components: components2,
  14303. behaviours: augment(detail.dropdownBehaviours, [
  14304. Toggling.config({
  14305. toggleClass: detail.toggleClass,
  14306. aria: { mode: "expanded" }
  14307. }),
  14308. Coupling.config({
  14309. others: {
  14310. sandbox: function(hotspot) {
  14311. return makeSandbox$1(detail, hotspot, {
  14312. onOpen: function() {
  14313. return Toggling.on(hotspot);
  14314. },
  14315. onClose: function() {
  14316. return Toggling.off(hotspot);
  14317. }
  14318. });
  14319. }
  14320. }
  14321. }),
  14322. Keying.config({
  14323. mode: "special",
  14324. onSpace: triggerExecute,
  14325. onEnter: triggerExecute,
  14326. onDown: function(comp, _se) {
  14327. if (Dropdown.isOpen(comp)) {
  14328. var sandbox = Coupling.getCoupled(comp, "sandbox");
  14329. switchToMenu(sandbox);
  14330. } else {
  14331. Dropdown.open(comp);
  14332. }
  14333. return Optional.some(true);
  14334. },
  14335. onEscape: function(comp, _se) {
  14336. if (Dropdown.isOpen(comp)) {
  14337. Dropdown.close(comp);
  14338. return Optional.some(true);
  14339. } else {
  14340. return Optional.none();
  14341. }
  14342. }
  14343. }),
  14344. Focusing.config({})
  14345. ]),
  14346. events: events$a(Optional.some(action)),
  14347. eventOrder: __assign(__assign({}, detail.eventOrder), (_a2 = {}, _a2[execute$5()] = [
  14348. "disabling",
  14349. "toggling",
  14350. "alloy.base.behaviour"
  14351. ], _a2)),
  14352. apis,
  14353. domModification: {
  14354. attributes: __assign(__assign({ "aria-haspopup": "true" }, detail.role.fold(function() {
  14355. return {};
  14356. }, function(role) {
  14357. return { role };
  14358. })), detail.dom.tag === "button" ? { type: lookupAttr("type").getOr("button") } : {})
  14359. }
  14360. };
  14361. };
  14362. var Dropdown = composite({
  14363. name: "Dropdown",
  14364. configFields: schema$j(),
  14365. partFields: parts$d(),
  14366. factory: factory$g,
  14367. apis: {
  14368. open: function(apis, comp) {
  14369. return apis.open(comp);
  14370. },
  14371. expand: function(apis, comp) {
  14372. return apis.expand(comp);
  14373. },
  14374. close: function(apis, comp) {
  14375. return apis.close(comp);
  14376. },
  14377. isOpen: function(apis, comp) {
  14378. return apis.isOpen(comp);
  14379. },
  14380. repositionMenus: function(apis, comp) {
  14381. return apis.repositionMenus(comp);
  14382. }
  14383. }
  14384. });
  14385. var exhibit$1 = function() {
  14386. return nu$7({
  14387. styles: {
  14388. "-webkit-user-select": "none",
  14389. "user-select": "none",
  14390. "-ms-user-select": "none",
  14391. "-moz-user-select": "-moz-none"
  14392. },
  14393. attributes: { unselectable: "on" }
  14394. });
  14395. };
  14396. var events$7 = function() {
  14397. return derive$2([abort(selectstart(), always)]);
  14398. };
  14399. var ActiveUnselecting = Object.freeze({
  14400. __proto__: null,
  14401. events: events$7,
  14402. exhibit: exhibit$1
  14403. });
  14404. var Unselecting = create$8({
  14405. fields: [],
  14406. name: "unselecting",
  14407. active: ActiveUnselecting
  14408. });
  14409. var renderPanelButton = function(spec, sharedBackstage) {
  14410. return Dropdown.sketch({
  14411. dom: spec.dom,
  14412. components: spec.components,
  14413. toggleClass: "mce-active",
  14414. dropdownBehaviours: derive$1([
  14415. DisablingConfigs.button(sharedBackstage.providers.isDisabled),
  14416. receivingConfig(),
  14417. Unselecting.config({}),
  14418. Tabstopping.config({})
  14419. ]),
  14420. layouts: spec.layouts,
  14421. sandboxClasses: ["tox-dialog__popups"],
  14422. lazySink: sharedBackstage.getSink,
  14423. fetch: function(comp) {
  14424. return Future.nu(function(callback) {
  14425. return spec.fetch(callback);
  14426. }).map(function(items) {
  14427. return Optional.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$6("menu-value"), items, function(value2) {
  14428. spec.onItemAction(comp, value2);
  14429. }, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, never, sharedBackstage.providers), { movement: deriveMenuMovement(spec.columns, spec.presets) })));
  14430. });
  14431. },
  14432. parts: { menu: part(false, 1, spec.presets) }
  14433. });
  14434. };
  14435. var colorInputChangeEvent = generate$6("color-input-change");
  14436. var colorSwatchChangeEvent = generate$6("color-swatch-change");
  14437. var colorPickerCancelEvent = generate$6("color-picker-cancel");
  14438. var renderColorInput = function(spec, sharedBackstage, colorInputBackstage) {
  14439. var pField = FormField.parts.field({
  14440. factory: Input,
  14441. inputClasses: ["tox-textfield"],
  14442. onSetValue: function(c) {
  14443. return Invalidating.run(c).get(noop);
  14444. },
  14445. inputBehaviours: derive$1([
  14446. Disabling.config({ disabled: sharedBackstage.providers.isDisabled }),
  14447. receivingConfig(),
  14448. Tabstopping.config({}),
  14449. Invalidating.config({
  14450. invalidClass: "tox-textbox-field-invalid",
  14451. getRoot: function(comp) {
  14452. return parent(comp.element);
  14453. },
  14454. notify: {
  14455. onValid: function(comp) {
  14456. var val = Representing.getValue(comp);
  14457. emitWith(comp, colorInputChangeEvent, { color: val });
  14458. }
  14459. },
  14460. validator: {
  14461. validateOnLoad: false,
  14462. validate: function(input2) {
  14463. var inputValue = Representing.getValue(input2);
  14464. if (inputValue.length === 0) {
  14465. return Future.pure(Result.value(true));
  14466. } else {
  14467. var span = SugarElement.fromTag("span");
  14468. set$7(span, "background-color", inputValue);
  14469. var res = getRaw(span, "background-color").fold(function() {
  14470. return Result.error("blah");
  14471. }, function(_) {
  14472. return Result.value(inputValue);
  14473. });
  14474. return Future.pure(res);
  14475. }
  14476. }
  14477. }
  14478. })
  14479. ]),
  14480. selectOnFocus: false
  14481. });
  14482. var pLabel = spec.label.map(function(label) {
  14483. return renderLabel$2(label, sharedBackstage.providers);
  14484. });
  14485. var emitSwatchChange = function(colorBit, value2) {
  14486. emitWith(colorBit, colorSwatchChangeEvent, { value: value2 });
  14487. };
  14488. var onItemAction = function(comp, value2) {
  14489. memColorButton.getOpt(comp).each(function(colorBit) {
  14490. if (value2 === "custom") {
  14491. colorInputBackstage.colorPicker(function(valueOpt) {
  14492. valueOpt.fold(function() {
  14493. return emit(colorBit, colorPickerCancelEvent);
  14494. }, function(value3) {
  14495. emitSwatchChange(colorBit, value3);
  14496. addColor(value3);
  14497. });
  14498. }, "#ffffff");
  14499. } else if (value2 === "remove") {
  14500. emitSwatchChange(colorBit, "");
  14501. } else {
  14502. emitSwatchChange(colorBit, value2);
  14503. }
  14504. });
  14505. };
  14506. var memColorButton = record(renderPanelButton({
  14507. dom: {
  14508. tag: "span",
  14509. attributes: { "aria-label": sharedBackstage.providers.translate("Color swatch") }
  14510. },
  14511. layouts: {
  14512. onRtl: function() {
  14513. return [
  14514. southwest$2,
  14515. southeast$2,
  14516. south$2
  14517. ];
  14518. },
  14519. onLtr: function() {
  14520. return [
  14521. southeast$2,
  14522. southwest$2,
  14523. south$2
  14524. ];
  14525. }
  14526. },
  14527. components: [],
  14528. fetch: getFetch$1(colorInputBackstage.getColors(), colorInputBackstage.hasCustomColors()),
  14529. columns: colorInputBackstage.getColorCols(),
  14530. presets: "color",
  14531. onItemAction
  14532. }, sharedBackstage));
  14533. return FormField.sketch({
  14534. dom: {
  14535. tag: "div",
  14536. classes: ["tox-form__group"]
  14537. },
  14538. components: pLabel.toArray().concat([{
  14539. dom: {
  14540. tag: "div",
  14541. classes: ["tox-color-input"]
  14542. },
  14543. components: [
  14544. pField,
  14545. memColorButton.asSpec()
  14546. ]
  14547. }]),
  14548. fieldBehaviours: derive$1([config("form-field-events", [
  14549. run$1(colorInputChangeEvent, function(comp, se) {
  14550. memColorButton.getOpt(comp).each(function(colorButton) {
  14551. set$7(colorButton.element, "background-color", se.event.color);
  14552. });
  14553. emitWith(comp, formChangeEvent, { name: spec.name });
  14554. }),
  14555. run$1(colorSwatchChangeEvent, function(comp, se) {
  14556. FormField.getField(comp).each(function(field2) {
  14557. Representing.setValue(field2, se.event.value);
  14558. Composing.getCurrent(comp).each(Focusing.focus);
  14559. });
  14560. }),
  14561. run$1(colorPickerCancelEvent, function(comp, _se) {
  14562. FormField.getField(comp).each(function(_field) {
  14563. Composing.getCurrent(comp).each(Focusing.focus);
  14564. });
  14565. })
  14566. ])])
  14567. });
  14568. };
  14569. var labelPart = optional({
  14570. schema: [required$1("dom")],
  14571. name: "label"
  14572. });
  14573. var edgePart = function(name2) {
  14574. return optional({
  14575. name: "" + name2 + "-edge",
  14576. overrides: function(detail) {
  14577. var action = detail.model.manager.edgeActions[name2];
  14578. return action.fold(function() {
  14579. return {};
  14580. }, function(a) {
  14581. return {
  14582. events: derive$2([
  14583. runActionExtra(touchstart(), function(comp, se, d) {
  14584. return a(comp, d);
  14585. }, [detail]),
  14586. runActionExtra(mousedown(), function(comp, se, d) {
  14587. return a(comp, d);
  14588. }, [detail]),
  14589. runActionExtra(mousemove(), function(comp, se, det) {
  14590. if (det.mouseIsDown.get()) {
  14591. a(comp, det);
  14592. }
  14593. }, [detail])
  14594. ])
  14595. };
  14596. });
  14597. }
  14598. });
  14599. };
  14600. var tlEdgePart = edgePart("top-left");
  14601. var tedgePart = edgePart("top");
  14602. var trEdgePart = edgePart("top-right");
  14603. var redgePart = edgePart("right");
  14604. var brEdgePart = edgePart("bottom-right");
  14605. var bedgePart = edgePart("bottom");
  14606. var blEdgePart = edgePart("bottom-left");
  14607. var ledgePart = edgePart("left");
  14608. var thumbPart = required({
  14609. name: "thumb",
  14610. defaults: constant$1({ dom: { styles: { position: "absolute" } } }),
  14611. overrides: function(detail) {
  14612. return {
  14613. events: derive$2([
  14614. redirectToPart(touchstart(), detail, "spectrum"),
  14615. redirectToPart(touchmove(), detail, "spectrum"),
  14616. redirectToPart(touchend(), detail, "spectrum"),
  14617. redirectToPart(mousedown(), detail, "spectrum"),
  14618. redirectToPart(mousemove(), detail, "spectrum"),
  14619. redirectToPart(mouseup(), detail, "spectrum")
  14620. ])
  14621. };
  14622. }
  14623. });
  14624. var spectrumPart = required({
  14625. schema: [customField("mouseIsDown", function() {
  14626. return Cell(false);
  14627. })],
  14628. name: "spectrum",
  14629. overrides: function(detail) {
  14630. var modelDetail = detail.model;
  14631. var model = modelDetail.manager;
  14632. var setValueFrom2 = function(component, simulatedEvent) {
  14633. return model.getValueFromEvent(simulatedEvent).map(function(value2) {
  14634. return model.setValueFrom(component, detail, value2);
  14635. });
  14636. };
  14637. return {
  14638. behaviours: derive$1([
  14639. Keying.config({
  14640. mode: "special",
  14641. onLeft: function(spectrum) {
  14642. return model.onLeft(spectrum, detail);
  14643. },
  14644. onRight: function(spectrum) {
  14645. return model.onRight(spectrum, detail);
  14646. },
  14647. onUp: function(spectrum) {
  14648. return model.onUp(spectrum, detail);
  14649. },
  14650. onDown: function(spectrum) {
  14651. return model.onDown(spectrum, detail);
  14652. }
  14653. }),
  14654. Focusing.config({})
  14655. ]),
  14656. events: derive$2([
  14657. run$1(touchstart(), setValueFrom2),
  14658. run$1(touchmove(), setValueFrom2),
  14659. run$1(mousedown(), setValueFrom2),
  14660. run$1(mousemove(), function(spectrum, se) {
  14661. if (detail.mouseIsDown.get()) {
  14662. setValueFrom2(spectrum, se);
  14663. }
  14664. })
  14665. ])
  14666. };
  14667. }
  14668. });
  14669. var SliderParts = [
  14670. labelPart,
  14671. ledgePart,
  14672. redgePart,
  14673. tedgePart,
  14674. bedgePart,
  14675. tlEdgePart,
  14676. trEdgePart,
  14677. blEdgePart,
  14678. brEdgePart,
  14679. thumbPart,
  14680. spectrumPart
  14681. ];
  14682. var _sliderChangeEvent = "slider.change.value";
  14683. var sliderChangeEvent = constant$1(_sliderChangeEvent);
  14684. var isTouchEvent$2 = function(evt) {
  14685. return evt.type.indexOf("touch") !== -1;
  14686. };
  14687. var getEventSource = function(simulatedEvent) {
  14688. var evt = simulatedEvent.event.raw;
  14689. if (isTouchEvent$2(evt)) {
  14690. var touchEvent = evt;
  14691. return touchEvent.touches !== void 0 && touchEvent.touches.length === 1 ? Optional.some(touchEvent.touches[0]).map(function(t2) {
  14692. return SugarPosition(t2.clientX, t2.clientY);
  14693. }) : Optional.none();
  14694. } else {
  14695. var mouseEvent = evt;
  14696. return mouseEvent.clientX !== void 0 ? Optional.some(mouseEvent).map(function(me) {
  14697. return SugarPosition(me.clientX, me.clientY);
  14698. }) : Optional.none();
  14699. }
  14700. };
  14701. var t = "top", r = "right", b = "bottom", l = "left";
  14702. var minX = function(detail) {
  14703. return detail.model.minX;
  14704. };
  14705. var minY = function(detail) {
  14706. return detail.model.minY;
  14707. };
  14708. var min1X = function(detail) {
  14709. return detail.model.minX - 1;
  14710. };
  14711. var min1Y = function(detail) {
  14712. return detail.model.minY - 1;
  14713. };
  14714. var maxX = function(detail) {
  14715. return detail.model.maxX;
  14716. };
  14717. var maxY = function(detail) {
  14718. return detail.model.maxY;
  14719. };
  14720. var max1X = function(detail) {
  14721. return detail.model.maxX + 1;
  14722. };
  14723. var max1Y = function(detail) {
  14724. return detail.model.maxY + 1;
  14725. };
  14726. var range = function(detail, max2, min2) {
  14727. return max2(detail) - min2(detail);
  14728. };
  14729. var xRange = function(detail) {
  14730. return range(detail, maxX, minX);
  14731. };
  14732. var yRange = function(detail) {
  14733. return range(detail, maxY, minY);
  14734. };
  14735. var halfX = function(detail) {
  14736. return xRange(detail) / 2;
  14737. };
  14738. var halfY = function(detail) {
  14739. return yRange(detail) / 2;
  14740. };
  14741. var step = function(detail) {
  14742. return detail.stepSize;
  14743. };
  14744. var snap = function(detail) {
  14745. return detail.snapToGrid;
  14746. };
  14747. var snapStart = function(detail) {
  14748. return detail.snapStart;
  14749. };
  14750. var rounded = function(detail) {
  14751. return detail.rounded;
  14752. };
  14753. var hasEdge = function(detail, edgeName) {
  14754. return detail[edgeName + "-edge"] !== void 0;
  14755. };
  14756. var hasLEdge = function(detail) {
  14757. return hasEdge(detail, l);
  14758. };
  14759. var hasREdge = function(detail) {
  14760. return hasEdge(detail, r);
  14761. };
  14762. var hasTEdge = function(detail) {
  14763. return hasEdge(detail, t);
  14764. };
  14765. var hasBEdge = function(detail) {
  14766. return hasEdge(detail, b);
  14767. };
  14768. var currentValue = function(detail) {
  14769. return detail.model.value.get();
  14770. };
  14771. var xValue = function(x) {
  14772. return { x };
  14773. };
  14774. var yValue = function(y) {
  14775. return { y };
  14776. };
  14777. var xyValue = function(x, y) {
  14778. return {
  14779. x,
  14780. y
  14781. };
  14782. };
  14783. var fireSliderChange$3 = function(component, value2) {
  14784. emitWith(component, sliderChangeEvent(), { value: value2 });
  14785. };
  14786. var setToTLEdgeXY = function(edge2, detail) {
  14787. fireSliderChange$3(edge2, xyValue(min1X(detail), min1Y(detail)));
  14788. };
  14789. var setToTEdge = function(edge2, detail) {
  14790. fireSliderChange$3(edge2, yValue(min1Y(detail)));
  14791. };
  14792. var setToTEdgeXY = function(edge2, detail) {
  14793. fireSliderChange$3(edge2, xyValue(halfX(detail), min1Y(detail)));
  14794. };
  14795. var setToTREdgeXY = function(edge2, detail) {
  14796. fireSliderChange$3(edge2, xyValue(max1X(detail), min1Y(detail)));
  14797. };
  14798. var setToREdge = function(edge2, detail) {
  14799. fireSliderChange$3(edge2, xValue(max1X(detail)));
  14800. };
  14801. var setToREdgeXY = function(edge2, detail) {
  14802. fireSliderChange$3(edge2, xyValue(max1X(detail), halfY(detail)));
  14803. };
  14804. var setToBREdgeXY = function(edge2, detail) {
  14805. fireSliderChange$3(edge2, xyValue(max1X(detail), max1Y(detail)));
  14806. };
  14807. var setToBEdge = function(edge2, detail) {
  14808. fireSliderChange$3(edge2, yValue(max1Y(detail)));
  14809. };
  14810. var setToBEdgeXY = function(edge2, detail) {
  14811. fireSliderChange$3(edge2, xyValue(halfX(detail), max1Y(detail)));
  14812. };
  14813. var setToBLEdgeXY = function(edge2, detail) {
  14814. fireSliderChange$3(edge2, xyValue(min1X(detail), max1Y(detail)));
  14815. };
  14816. var setToLEdge = function(edge2, detail) {
  14817. fireSliderChange$3(edge2, xValue(min1X(detail)));
  14818. };
  14819. var setToLEdgeXY = function(edge2, detail) {
  14820. fireSliderChange$3(edge2, xyValue(min1X(detail), halfY(detail)));
  14821. };
  14822. var reduceBy = function(value2, min2, max2, step2) {
  14823. if (value2 < min2) {
  14824. return value2;
  14825. } else if (value2 > max2) {
  14826. return max2;
  14827. } else if (value2 === min2) {
  14828. return min2 - 1;
  14829. } else {
  14830. return Math.max(min2, value2 - step2);
  14831. }
  14832. };
  14833. var increaseBy = function(value2, min2, max2, step2) {
  14834. if (value2 > max2) {
  14835. return value2;
  14836. } else if (value2 < min2) {
  14837. return min2;
  14838. } else if (value2 === max2) {
  14839. return max2 + 1;
  14840. } else {
  14841. return Math.min(max2, value2 + step2);
  14842. }
  14843. };
  14844. var capValue = function(value2, min2, max2) {
  14845. return Math.max(min2, Math.min(max2, value2));
  14846. };
  14847. var snapValueOf = function(value2, min2, max2, step2, snapStart2) {
  14848. return snapStart2.fold(function() {
  14849. var initValue = value2 - min2;
  14850. var extraValue = Math.round(initValue / step2) * step2;
  14851. return capValue(min2 + extraValue, min2 - 1, max2 + 1);
  14852. }, function(start) {
  14853. var remainder = (value2 - start) % step2;
  14854. var adjustment = Math.round(remainder / step2);
  14855. var rawSteps = Math.floor((value2 - start) / step2);
  14856. var maxSteps = Math.floor((max2 - start) / step2);
  14857. var numSteps = Math.min(maxSteps, rawSteps + adjustment);
  14858. var r2 = start + numSteps * step2;
  14859. return Math.max(start, r2);
  14860. });
  14861. };
  14862. var findOffsetOf = function(value2, min2, max2) {
  14863. return Math.min(max2, Math.max(value2, min2)) - min2;
  14864. };
  14865. var findValueOf = function(args) {
  14866. 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;
  14867. var capMin = hasMinEdge ? min2 - 1 : min2;
  14868. var capMax = hasMaxEdge ? max2 + 1 : max2;
  14869. if (value2 < minBound) {
  14870. return capMin;
  14871. } else if (value2 > maxBound) {
  14872. return capMax;
  14873. } else {
  14874. var offset2 = findOffsetOf(value2, minBound, maxBound);
  14875. var newValue = capValue(offset2 / screenRange * range2 + min2, capMin, capMax);
  14876. if (snap2 && newValue >= min2 && newValue <= max2) {
  14877. return snapValueOf(newValue, min2, max2, step2, snapStart2);
  14878. } else if (rounded2) {
  14879. return Math.round(newValue);
  14880. } else {
  14881. return newValue;
  14882. }
  14883. }
  14884. };
  14885. var findOffsetOfValue$2 = function(args) {
  14886. 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;
  14887. if (value2 < min2) {
  14888. return hasMinEdge ? 0 : centerMinEdge;
  14889. } else if (value2 > max2) {
  14890. return hasMaxEdge ? maxBound : centerMaxEdge;
  14891. } else {
  14892. return (value2 - min2) / range2 * maxOffset;
  14893. }
  14894. };
  14895. var top = "top", right = "right", bottom = "bottom", left = "left", width = "width", height = "height";
  14896. var getBounds = function(component) {
  14897. return component.element.dom.getBoundingClientRect();
  14898. };
  14899. var getBoundsProperty = function(bounds2, property) {
  14900. return bounds2[property];
  14901. };
  14902. var getMinXBounds = function(component) {
  14903. var bounds2 = getBounds(component);
  14904. return getBoundsProperty(bounds2, left);
  14905. };
  14906. var getMaxXBounds = function(component) {
  14907. var bounds2 = getBounds(component);
  14908. return getBoundsProperty(bounds2, right);
  14909. };
  14910. var getMinYBounds = function(component) {
  14911. var bounds2 = getBounds(component);
  14912. return getBoundsProperty(bounds2, top);
  14913. };
  14914. var getMaxYBounds = function(component) {
  14915. var bounds2 = getBounds(component);
  14916. return getBoundsProperty(bounds2, bottom);
  14917. };
  14918. var getXScreenRange = function(component) {
  14919. var bounds2 = getBounds(component);
  14920. return getBoundsProperty(bounds2, width);
  14921. };
  14922. var getYScreenRange = function(component) {
  14923. var bounds2 = getBounds(component);
  14924. return getBoundsProperty(bounds2, height);
  14925. };
  14926. var getCenterOffsetOf = function(componentMinEdge, componentMaxEdge, spectrumMinEdge) {
  14927. return (componentMinEdge + componentMaxEdge) / 2 - spectrumMinEdge;
  14928. };
  14929. var getXCenterOffSetOf = function(component, spectrum) {
  14930. var componentBounds = getBounds(component);
  14931. var spectrumBounds = getBounds(spectrum);
  14932. var componentMinEdge = getBoundsProperty(componentBounds, left);
  14933. var componentMaxEdge = getBoundsProperty(componentBounds, right);
  14934. var spectrumMinEdge = getBoundsProperty(spectrumBounds, left);
  14935. return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
  14936. };
  14937. var getYCenterOffSetOf = function(component, spectrum) {
  14938. var componentBounds = getBounds(component);
  14939. var spectrumBounds = getBounds(spectrum);
  14940. var componentMinEdge = getBoundsProperty(componentBounds, top);
  14941. var componentMaxEdge = getBoundsProperty(componentBounds, bottom);
  14942. var spectrumMinEdge = getBoundsProperty(spectrumBounds, top);
  14943. return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
  14944. };
  14945. var fireSliderChange$2 = function(spectrum, value2) {
  14946. emitWith(spectrum, sliderChangeEvent(), { value: value2 });
  14947. };
  14948. var sliderValue$2 = function(x) {
  14949. return { x };
  14950. };
  14951. var findValueOfOffset$1 = function(spectrum, detail, left2) {
  14952. var args = {
  14953. min: minX(detail),
  14954. max: maxX(detail),
  14955. range: xRange(detail),
  14956. value: left2,
  14957. step: step(detail),
  14958. snap: snap(detail),
  14959. snapStart: snapStart(detail),
  14960. rounded: rounded(detail),
  14961. hasMinEdge: hasLEdge(detail),
  14962. hasMaxEdge: hasREdge(detail),
  14963. minBound: getMinXBounds(spectrum),
  14964. maxBound: getMaxXBounds(spectrum),
  14965. screenRange: getXScreenRange(spectrum)
  14966. };
  14967. return findValueOf(args);
  14968. };
  14969. var setValueFrom$2 = function(spectrum, detail, value2) {
  14970. var xValue2 = findValueOfOffset$1(spectrum, detail, value2);
  14971. var sliderVal = sliderValue$2(xValue2);
  14972. fireSliderChange$2(spectrum, sliderVal);
  14973. return xValue2;
  14974. };
  14975. var setToMin$2 = function(spectrum, detail) {
  14976. var min2 = minX(detail);
  14977. fireSliderChange$2(spectrum, sliderValue$2(min2));
  14978. };
  14979. var setToMax$2 = function(spectrum, detail) {
  14980. var max2 = maxX(detail);
  14981. fireSliderChange$2(spectrum, sliderValue$2(max2));
  14982. };
  14983. var moveBy$2 = function(direction, spectrum, detail) {
  14984. var f = direction > 0 ? increaseBy : reduceBy;
  14985. var xValue2 = f(currentValue(detail).x, minX(detail), maxX(detail), step(detail));
  14986. fireSliderChange$2(spectrum, sliderValue$2(xValue2));
  14987. return Optional.some(xValue2);
  14988. };
  14989. var handleMovement$2 = function(direction) {
  14990. return function(spectrum, detail) {
  14991. return moveBy$2(direction, spectrum, detail).map(always);
  14992. };
  14993. };
  14994. var getValueFromEvent$2 = function(simulatedEvent) {
  14995. var pos = getEventSource(simulatedEvent);
  14996. return pos.map(function(p) {
  14997. return p.left;
  14998. });
  14999. };
  15000. var findOffsetOfValue$1 = function(spectrum, detail, value2, minEdge, maxEdge) {
  15001. var minOffset = 0;
  15002. var maxOffset = getXScreenRange(spectrum);
  15003. var centerMinEdge = minEdge.bind(function(edge2) {
  15004. return Optional.some(getXCenterOffSetOf(edge2, spectrum));
  15005. }).getOr(minOffset);
  15006. var centerMaxEdge = maxEdge.bind(function(edge2) {
  15007. return Optional.some(getXCenterOffSetOf(edge2, spectrum));
  15008. }).getOr(maxOffset);
  15009. var args = {
  15010. min: minX(detail),
  15011. max: maxX(detail),
  15012. range: xRange(detail),
  15013. value: value2,
  15014. hasMinEdge: hasLEdge(detail),
  15015. hasMaxEdge: hasREdge(detail),
  15016. minBound: getMinXBounds(spectrum),
  15017. minOffset,
  15018. maxBound: getMaxXBounds(spectrum),
  15019. maxOffset,
  15020. centerMinEdge,
  15021. centerMaxEdge
  15022. };
  15023. return findOffsetOfValue$2(args);
  15024. };
  15025. var findPositionOfValue$1 = function(slider, spectrum, value2, minEdge, maxEdge, detail) {
  15026. var offset2 = findOffsetOfValue$1(spectrum, detail, value2, minEdge, maxEdge);
  15027. return getMinXBounds(spectrum) - getMinXBounds(slider) + offset2;
  15028. };
  15029. var setPositionFromValue$2 = function(slider, thumb, detail, edges) {
  15030. var value2 = currentValue(detail);
  15031. var pos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value2.x, edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
  15032. var thumbRadius = get$a(thumb.element) / 2;
  15033. set$7(thumb.element, "left", pos - thumbRadius + "px");
  15034. };
  15035. var onLeft$2 = handleMovement$2(-1);
  15036. var onRight$2 = handleMovement$2(1);
  15037. var onUp$2 = Optional.none;
  15038. var onDown$2 = Optional.none;
  15039. var edgeActions$2 = {
  15040. "top-left": Optional.none(),
  15041. "top": Optional.none(),
  15042. "top-right": Optional.none(),
  15043. "right": Optional.some(setToREdge),
  15044. "bottom-right": Optional.none(),
  15045. "bottom": Optional.none(),
  15046. "bottom-left": Optional.none(),
  15047. "left": Optional.some(setToLEdge)
  15048. };
  15049. var HorizontalModel = Object.freeze({
  15050. __proto__: null,
  15051. setValueFrom: setValueFrom$2,
  15052. setToMin: setToMin$2,
  15053. setToMax: setToMax$2,
  15054. findValueOfOffset: findValueOfOffset$1,
  15055. getValueFromEvent: getValueFromEvent$2,
  15056. findPositionOfValue: findPositionOfValue$1,
  15057. setPositionFromValue: setPositionFromValue$2,
  15058. onLeft: onLeft$2,
  15059. onRight: onRight$2,
  15060. onUp: onUp$2,
  15061. onDown: onDown$2,
  15062. edgeActions: edgeActions$2
  15063. });
  15064. var fireSliderChange$1 = function(spectrum, value2) {
  15065. emitWith(spectrum, sliderChangeEvent(), { value: value2 });
  15066. };
  15067. var sliderValue$1 = function(y) {
  15068. return { y };
  15069. };
  15070. var findValueOfOffset = function(spectrum, detail, top2) {
  15071. var args = {
  15072. min: minY(detail),
  15073. max: maxY(detail),
  15074. range: yRange(detail),
  15075. value: top2,
  15076. step: step(detail),
  15077. snap: snap(detail),
  15078. snapStart: snapStart(detail),
  15079. rounded: rounded(detail),
  15080. hasMinEdge: hasTEdge(detail),
  15081. hasMaxEdge: hasBEdge(detail),
  15082. minBound: getMinYBounds(spectrum),
  15083. maxBound: getMaxYBounds(spectrum),
  15084. screenRange: getYScreenRange(spectrum)
  15085. };
  15086. return findValueOf(args);
  15087. };
  15088. var setValueFrom$1 = function(spectrum, detail, value2) {
  15089. var yValue2 = findValueOfOffset(spectrum, detail, value2);
  15090. var sliderVal = sliderValue$1(yValue2);
  15091. fireSliderChange$1(spectrum, sliderVal);
  15092. return yValue2;
  15093. };
  15094. var setToMin$1 = function(spectrum, detail) {
  15095. var min2 = minY(detail);
  15096. fireSliderChange$1(spectrum, sliderValue$1(min2));
  15097. };
  15098. var setToMax$1 = function(spectrum, detail) {
  15099. var max2 = maxY(detail);
  15100. fireSliderChange$1(spectrum, sliderValue$1(max2));
  15101. };
  15102. var moveBy$1 = function(direction, spectrum, detail) {
  15103. var f = direction > 0 ? increaseBy : reduceBy;
  15104. var yValue2 = f(currentValue(detail).y, minY(detail), maxY(detail), step(detail));
  15105. fireSliderChange$1(spectrum, sliderValue$1(yValue2));
  15106. return Optional.some(yValue2);
  15107. };
  15108. var handleMovement$1 = function(direction) {
  15109. return function(spectrum, detail) {
  15110. return moveBy$1(direction, spectrum, detail).map(always);
  15111. };
  15112. };
  15113. var getValueFromEvent$1 = function(simulatedEvent) {
  15114. var pos = getEventSource(simulatedEvent);
  15115. return pos.map(function(p) {
  15116. return p.top;
  15117. });
  15118. };
  15119. var findOffsetOfValue = function(spectrum, detail, value2, minEdge, maxEdge) {
  15120. var minOffset = 0;
  15121. var maxOffset = getYScreenRange(spectrum);
  15122. var centerMinEdge = minEdge.bind(function(edge2) {
  15123. return Optional.some(getYCenterOffSetOf(edge2, spectrum));
  15124. }).getOr(minOffset);
  15125. var centerMaxEdge = maxEdge.bind(function(edge2) {
  15126. return Optional.some(getYCenterOffSetOf(edge2, spectrum));
  15127. }).getOr(maxOffset);
  15128. var args = {
  15129. min: minY(detail),
  15130. max: maxY(detail),
  15131. range: yRange(detail),
  15132. value: value2,
  15133. hasMinEdge: hasTEdge(detail),
  15134. hasMaxEdge: hasBEdge(detail),
  15135. minBound: getMinYBounds(spectrum),
  15136. minOffset,
  15137. maxBound: getMaxYBounds(spectrum),
  15138. maxOffset,
  15139. centerMinEdge,
  15140. centerMaxEdge
  15141. };
  15142. return findOffsetOfValue$2(args);
  15143. };
  15144. var findPositionOfValue = function(slider, spectrum, value2, minEdge, maxEdge, detail) {
  15145. var offset2 = findOffsetOfValue(spectrum, detail, value2, minEdge, maxEdge);
  15146. return getMinYBounds(spectrum) - getMinYBounds(slider) + offset2;
  15147. };
  15148. var setPositionFromValue$1 = function(slider, thumb, detail, edges) {
  15149. var value2 = currentValue(detail);
  15150. var pos = findPositionOfValue(slider, edges.getSpectrum(slider), value2.y, edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
  15151. var thumbRadius = get$b(thumb.element) / 2;
  15152. set$7(thumb.element, "top", pos - thumbRadius + "px");
  15153. };
  15154. var onLeft$1 = Optional.none;
  15155. var onRight$1 = Optional.none;
  15156. var onUp$1 = handleMovement$1(-1);
  15157. var onDown$1 = handleMovement$1(1);
  15158. var edgeActions$1 = {
  15159. "top-left": Optional.none(),
  15160. "top": Optional.some(setToTEdge),
  15161. "top-right": Optional.none(),
  15162. "right": Optional.none(),
  15163. "bottom-right": Optional.none(),
  15164. "bottom": Optional.some(setToBEdge),
  15165. "bottom-left": Optional.none(),
  15166. "left": Optional.none()
  15167. };
  15168. var VerticalModel = Object.freeze({
  15169. __proto__: null,
  15170. setValueFrom: setValueFrom$1,
  15171. setToMin: setToMin$1,
  15172. setToMax: setToMax$1,
  15173. findValueOfOffset,
  15174. getValueFromEvent: getValueFromEvent$1,
  15175. findPositionOfValue,
  15176. setPositionFromValue: setPositionFromValue$1,
  15177. onLeft: onLeft$1,
  15178. onRight: onRight$1,
  15179. onUp: onUp$1,
  15180. onDown: onDown$1,
  15181. edgeActions: edgeActions$1
  15182. });
  15183. var fireSliderChange = function(spectrum, value2) {
  15184. emitWith(spectrum, sliderChangeEvent(), { value: value2 });
  15185. };
  15186. var sliderValue = function(x, y) {
  15187. return {
  15188. x,
  15189. y
  15190. };
  15191. };
  15192. var setValueFrom = function(spectrum, detail, value2) {
  15193. var xValue2 = findValueOfOffset$1(spectrum, detail, value2.left);
  15194. var yValue2 = findValueOfOffset(spectrum, detail, value2.top);
  15195. var val = sliderValue(xValue2, yValue2);
  15196. fireSliderChange(spectrum, val);
  15197. return val;
  15198. };
  15199. var moveBy = function(direction, isVerticalMovement, spectrum, detail) {
  15200. var f = direction > 0 ? increaseBy : reduceBy;
  15201. var xValue2 = isVerticalMovement ? currentValue(detail).x : f(currentValue(detail).x, minX(detail), maxX(detail), step(detail));
  15202. var yValue2 = !isVerticalMovement ? currentValue(detail).y : f(currentValue(detail).y, minY(detail), maxY(detail), step(detail));
  15203. fireSliderChange(spectrum, sliderValue(xValue2, yValue2));
  15204. return Optional.some(xValue2);
  15205. };
  15206. var handleMovement = function(direction, isVerticalMovement) {
  15207. return function(spectrum, detail) {
  15208. return moveBy(direction, isVerticalMovement, spectrum, detail).map(always);
  15209. };
  15210. };
  15211. var setToMin = function(spectrum, detail) {
  15212. var mX = minX(detail);
  15213. var mY = minY(detail);
  15214. fireSliderChange(spectrum, sliderValue(mX, mY));
  15215. };
  15216. var setToMax = function(spectrum, detail) {
  15217. var mX = maxX(detail);
  15218. var mY = maxY(detail);
  15219. fireSliderChange(spectrum, sliderValue(mX, mY));
  15220. };
  15221. var getValueFromEvent = function(simulatedEvent) {
  15222. return getEventSource(simulatedEvent);
  15223. };
  15224. var setPositionFromValue = function(slider, thumb, detail, edges) {
  15225. var value2 = currentValue(detail);
  15226. var xPos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value2.x, edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
  15227. var yPos = findPositionOfValue(slider, edges.getSpectrum(slider), value2.y, edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
  15228. var thumbXRadius = get$a(thumb.element) / 2;
  15229. var thumbYRadius = get$b(thumb.element) / 2;
  15230. set$7(thumb.element, "left", xPos - thumbXRadius + "px");
  15231. set$7(thumb.element, "top", yPos - thumbYRadius + "px");
  15232. };
  15233. var onLeft = handleMovement(-1, false);
  15234. var onRight = handleMovement(1, false);
  15235. var onUp = handleMovement(-1, true);
  15236. var onDown = handleMovement(1, true);
  15237. var edgeActions = {
  15238. "top-left": Optional.some(setToTLEdgeXY),
  15239. "top": Optional.some(setToTEdgeXY),
  15240. "top-right": Optional.some(setToTREdgeXY),
  15241. "right": Optional.some(setToREdgeXY),
  15242. "bottom-right": Optional.some(setToBREdgeXY),
  15243. "bottom": Optional.some(setToBEdgeXY),
  15244. "bottom-left": Optional.some(setToBLEdgeXY),
  15245. "left": Optional.some(setToLEdgeXY)
  15246. };
  15247. var TwoDModel = Object.freeze({
  15248. __proto__: null,
  15249. setValueFrom,
  15250. setToMin,
  15251. setToMax,
  15252. getValueFromEvent,
  15253. setPositionFromValue,
  15254. onLeft,
  15255. onRight,
  15256. onUp,
  15257. onDown,
  15258. edgeActions
  15259. });
  15260. var SliderSchema = [
  15261. defaulted("stepSize", 1),
  15262. defaulted("onChange", noop),
  15263. defaulted("onChoose", noop),
  15264. defaulted("onInit", noop),
  15265. defaulted("onDragStart", noop),
  15266. defaulted("onDragEnd", noop),
  15267. defaulted("snapToGrid", false),
  15268. defaulted("rounded", true),
  15269. option("snapStart"),
  15270. requiredOf("model", choose$1("mode", {
  15271. x: [
  15272. defaulted("minX", 0),
  15273. defaulted("maxX", 100),
  15274. customField("value", function(spec) {
  15275. return Cell(spec.mode.minX);
  15276. }),
  15277. required$1("getInitialValue"),
  15278. output$1("manager", HorizontalModel)
  15279. ],
  15280. y: [
  15281. defaulted("minY", 0),
  15282. defaulted("maxY", 100),
  15283. customField("value", function(spec) {
  15284. return Cell(spec.mode.minY);
  15285. }),
  15286. required$1("getInitialValue"),
  15287. output$1("manager", VerticalModel)
  15288. ],
  15289. xy: [
  15290. defaulted("minX", 0),
  15291. defaulted("maxX", 100),
  15292. defaulted("minY", 0),
  15293. defaulted("maxY", 100),
  15294. customField("value", function(spec) {
  15295. return Cell({
  15296. x: spec.mode.minX,
  15297. y: spec.mode.minY
  15298. });
  15299. }),
  15300. required$1("getInitialValue"),
  15301. output$1("manager", TwoDModel)
  15302. ]
  15303. })),
  15304. field("sliderBehaviours", [
  15305. Keying,
  15306. Representing
  15307. ]),
  15308. customField("mouseIsDown", function() {
  15309. return Cell(false);
  15310. })
  15311. ];
  15312. var sketch$2 = function(detail, components2, _spec, _externals) {
  15313. var _a2;
  15314. var getThumb = function(component) {
  15315. return getPartOrDie(component, detail, "thumb");
  15316. };
  15317. var getSpectrum = function(component) {
  15318. return getPartOrDie(component, detail, "spectrum");
  15319. };
  15320. var getLeftEdge = function(component) {
  15321. return getPart(component, detail, "left-edge");
  15322. };
  15323. var getRightEdge = function(component) {
  15324. return getPart(component, detail, "right-edge");
  15325. };
  15326. var getTopEdge = function(component) {
  15327. return getPart(component, detail, "top-edge");
  15328. };
  15329. var getBottomEdge = function(component) {
  15330. return getPart(component, detail, "bottom-edge");
  15331. };
  15332. var modelDetail = detail.model;
  15333. var model = modelDetail.manager;
  15334. var refresh2 = function(slider, thumb) {
  15335. model.setPositionFromValue(slider, thumb, detail, {
  15336. getLeftEdge,
  15337. getRightEdge,
  15338. getTopEdge,
  15339. getBottomEdge,
  15340. getSpectrum
  15341. });
  15342. };
  15343. var setValue2 = function(slider, newValue) {
  15344. modelDetail.value.set(newValue);
  15345. var thumb = getThumb(slider);
  15346. refresh2(slider, thumb);
  15347. };
  15348. var changeValue = function(slider, newValue) {
  15349. setValue2(slider, newValue);
  15350. var thumb = getThumb(slider);
  15351. detail.onChange(slider, thumb, newValue);
  15352. return Optional.some(true);
  15353. };
  15354. var resetToMin = function(slider) {
  15355. model.setToMin(slider, detail);
  15356. };
  15357. var resetToMax = function(slider) {
  15358. model.setToMax(slider, detail);
  15359. };
  15360. var choose2 = function(slider) {
  15361. var fireOnChoose = function() {
  15362. getPart(slider, detail, "thumb").each(function(thumb) {
  15363. var value2 = modelDetail.value.get();
  15364. detail.onChoose(slider, thumb, value2);
  15365. });
  15366. };
  15367. var wasDown = detail.mouseIsDown.get();
  15368. detail.mouseIsDown.set(false);
  15369. if (wasDown) {
  15370. fireOnChoose();
  15371. }
  15372. };
  15373. var onDragStart = function(slider, simulatedEvent) {
  15374. simulatedEvent.stop();
  15375. detail.mouseIsDown.set(true);
  15376. detail.onDragStart(slider, getThumb(slider));
  15377. };
  15378. var onDragEnd = function(slider, simulatedEvent) {
  15379. simulatedEvent.stop();
  15380. detail.onDragEnd(slider, getThumb(slider));
  15381. choose2(slider);
  15382. };
  15383. return {
  15384. uid: detail.uid,
  15385. dom: detail.dom,
  15386. components: components2,
  15387. behaviours: augment(detail.sliderBehaviours, [
  15388. Keying.config({
  15389. mode: "special",
  15390. focusIn: function(slider) {
  15391. return getPart(slider, detail, "spectrum").map(Keying.focusIn).map(always);
  15392. }
  15393. }),
  15394. Representing.config({
  15395. store: {
  15396. mode: "manual",
  15397. getValue: function(_) {
  15398. return modelDetail.value.get();
  15399. }
  15400. }
  15401. }),
  15402. Receiving.config({ channels: (_a2 = {}, _a2[mouseReleased()] = { onReceive: choose2 }, _a2) })
  15403. ]),
  15404. events: derive$2([
  15405. run$1(sliderChangeEvent(), function(slider, simulatedEvent) {
  15406. changeValue(slider, simulatedEvent.event.value);
  15407. }),
  15408. runOnAttached(function(slider, _simulatedEvent) {
  15409. var getInitial = modelDetail.getInitialValue();
  15410. modelDetail.value.set(getInitial);
  15411. var thumb = getThumb(slider);
  15412. refresh2(slider, thumb);
  15413. var spectrum = getSpectrum(slider);
  15414. detail.onInit(slider, thumb, spectrum, modelDetail.value.get());
  15415. }),
  15416. run$1(touchstart(), onDragStart),
  15417. run$1(touchend(), onDragEnd),
  15418. run$1(mousedown(), onDragStart),
  15419. run$1(mouseup(), onDragEnd)
  15420. ]),
  15421. apis: {
  15422. resetToMin,
  15423. resetToMax,
  15424. setValue: setValue2,
  15425. refresh: refresh2
  15426. },
  15427. domModification: { styles: { position: "relative" } }
  15428. };
  15429. };
  15430. var Slider = composite({
  15431. name: "Slider",
  15432. configFields: SliderSchema,
  15433. partFields: SliderParts,
  15434. factory: sketch$2,
  15435. apis: {
  15436. setValue: function(apis, slider, value2) {
  15437. apis.setValue(slider, value2);
  15438. },
  15439. resetToMin: function(apis, slider) {
  15440. apis.resetToMin(slider);
  15441. },
  15442. resetToMax: function(apis, slider) {
  15443. apis.resetToMax(slider);
  15444. },
  15445. refresh: function(apis, slider) {
  15446. apis.refresh(slider);
  15447. }
  15448. }
  15449. });
  15450. var fieldsUpdate = generate$6("rgb-hex-update");
  15451. var sliderUpdate = generate$6("slider-update");
  15452. var paletteUpdate = generate$6("palette-update");
  15453. var sliderFactory = function(translate2, getClass) {
  15454. var spectrum = Slider.parts.spectrum({
  15455. dom: {
  15456. tag: "div",
  15457. classes: [getClass("hue-slider-spectrum")],
  15458. attributes: { role: "presentation" }
  15459. }
  15460. });
  15461. var thumb = Slider.parts.thumb({
  15462. dom: {
  15463. tag: "div",
  15464. classes: [getClass("hue-slider-thumb")],
  15465. attributes: { role: "presentation" }
  15466. }
  15467. });
  15468. return Slider.sketch({
  15469. dom: {
  15470. tag: "div",
  15471. classes: [getClass("hue-slider")],
  15472. attributes: { role: "presentation" }
  15473. },
  15474. rounded: false,
  15475. model: {
  15476. mode: "y",
  15477. getInitialValue: constant$1({ y: 0 })
  15478. },
  15479. components: [
  15480. spectrum,
  15481. thumb
  15482. ],
  15483. sliderBehaviours: derive$1([Focusing.config({})]),
  15484. onChange: function(slider, _thumb, value2) {
  15485. emitWith(slider, sliderUpdate, { value: value2 });
  15486. }
  15487. });
  15488. };
  15489. var owner$1 = "form";
  15490. var schema$i = [field("formBehaviours", [Representing])];
  15491. var getPartName$1 = function(name2) {
  15492. return "<alloy.field." + name2 + ">";
  15493. };
  15494. var sketch$1 = function(fSpec) {
  15495. var parts2 = function() {
  15496. var record2 = [];
  15497. var field2 = function(name2, config2) {
  15498. record2.push(name2);
  15499. return generateOne$1(owner$1, getPartName$1(name2), config2);
  15500. };
  15501. return {
  15502. field: field2,
  15503. record: constant$1(record2)
  15504. };
  15505. }();
  15506. var spec = fSpec(parts2);
  15507. var partNames = parts2.record();
  15508. var fieldParts = map$2(partNames, function(n) {
  15509. return required({
  15510. name: n,
  15511. pname: getPartName$1(n)
  15512. });
  15513. });
  15514. return composite$1(owner$1, schema$i, fieldParts, make$4, spec);
  15515. };
  15516. var toResult = function(o, e) {
  15517. return o.fold(function() {
  15518. return Result.error(e);
  15519. }, Result.value);
  15520. };
  15521. var make$4 = function(detail, components2) {
  15522. return {
  15523. uid: detail.uid,
  15524. dom: detail.dom,
  15525. components: components2,
  15526. behaviours: augment(detail.formBehaviours, [Representing.config({
  15527. store: {
  15528. mode: "manual",
  15529. getValue: function(form) {
  15530. var resPs = getAllParts(form, detail);
  15531. return map$1(resPs, function(resPThunk, pName) {
  15532. return resPThunk().bind(function(v) {
  15533. var opt = Composing.getCurrent(v);
  15534. return toResult(opt, new Error("Cannot find a current component to extract the value from for form part '" + pName + "': " + element(v.element)));
  15535. }).map(Representing.getValue);
  15536. });
  15537. },
  15538. setValue: function(form, values2) {
  15539. each(values2, function(newValue, key) {
  15540. getPart(form, detail, key).each(function(wrapper) {
  15541. Composing.getCurrent(wrapper).each(function(field2) {
  15542. Representing.setValue(field2, newValue);
  15543. });
  15544. });
  15545. });
  15546. }
  15547. }
  15548. })]),
  15549. apis: {
  15550. getField: function(form, key) {
  15551. return getPart(form, detail, key).bind(Composing.getCurrent);
  15552. }
  15553. }
  15554. };
  15555. };
  15556. var Form = {
  15557. getField: makeApi(function(apis, component, key) {
  15558. return apis.getField(component, key);
  15559. }),
  15560. sketch: sketch$1
  15561. };
  15562. var validInput = generate$6("valid-input");
  15563. var invalidInput = generate$6("invalid-input");
  15564. var validatingInput = generate$6("validating-input");
  15565. var translatePrefix = "colorcustom.rgb.";
  15566. var rgbFormFactory = function(translate2, getClass, onValidHexx, onInvalidHexx) {
  15567. var invalidation = function(label, isValid) {
  15568. return Invalidating.config({
  15569. invalidClass: getClass("invalid"),
  15570. notify: {
  15571. onValidate: function(comp) {
  15572. emitWith(comp, validatingInput, { type: label });
  15573. },
  15574. onValid: function(comp) {
  15575. emitWith(comp, validInput, {
  15576. type: label,
  15577. value: Representing.getValue(comp)
  15578. });
  15579. },
  15580. onInvalid: function(comp) {
  15581. emitWith(comp, invalidInput, {
  15582. type: label,
  15583. value: Representing.getValue(comp)
  15584. });
  15585. }
  15586. },
  15587. validator: {
  15588. validate: function(comp) {
  15589. var value2 = Representing.getValue(comp);
  15590. var res = isValid(value2) ? Result.value(true) : Result.error(translate2("aria.input.invalid"));
  15591. return Future.pure(res);
  15592. },
  15593. validateOnLoad: false
  15594. }
  15595. });
  15596. };
  15597. var renderTextField2 = function(isValid, name2, label, description, data) {
  15598. var helptext = translate2(translatePrefix + "range");
  15599. var pLabel = FormField.parts.label({
  15600. dom: {
  15601. tag: "label",
  15602. innerHtml: label,
  15603. attributes: { "aria-label": description }
  15604. }
  15605. });
  15606. var pField = FormField.parts.field({
  15607. data,
  15608. factory: Input,
  15609. inputAttributes: __assign({ type: "text" }, name2 === "hex" ? { "aria-live": "polite" } : {}),
  15610. inputClasses: [getClass("textfield")],
  15611. inputBehaviours: derive$1([
  15612. invalidation(name2, isValid),
  15613. Tabstopping.config({})
  15614. ]),
  15615. onSetValue: function(input2) {
  15616. if (Invalidating.isInvalid(input2)) {
  15617. var run2 = Invalidating.run(input2);
  15618. run2.get(noop);
  15619. }
  15620. }
  15621. });
  15622. var comps = [
  15623. pLabel,
  15624. pField
  15625. ];
  15626. var concats = name2 !== "hex" ? [FormField.parts["aria-descriptor"]({ text: helptext })] : [];
  15627. var components2 = comps.concat(concats);
  15628. return {
  15629. dom: {
  15630. tag: "div",
  15631. attributes: { role: "presentation" }
  15632. },
  15633. components: components2
  15634. };
  15635. };
  15636. var copyRgbToHex = function(form, rgba) {
  15637. var hex = fromRgba(rgba);
  15638. Form.getField(form, "hex").each(function(hexField) {
  15639. if (!Focusing.isFocused(hexField)) {
  15640. Representing.setValue(form, { hex: hex.value });
  15641. }
  15642. });
  15643. return hex;
  15644. };
  15645. var copyRgbToForm = function(form, rgb) {
  15646. var red2 = rgb.red;
  15647. var green = rgb.green;
  15648. var blue = rgb.blue;
  15649. Representing.setValue(form, {
  15650. red: red2,
  15651. green,
  15652. blue
  15653. });
  15654. };
  15655. var memPreview = record({
  15656. dom: {
  15657. tag: "div",
  15658. classes: [getClass("rgba-preview")],
  15659. styles: { "background-color": "white" },
  15660. attributes: { role: "presentation" }
  15661. }
  15662. });
  15663. var updatePreview = function(anyInSystem, hex) {
  15664. memPreview.getOpt(anyInSystem).each(function(preview) {
  15665. set$7(preview.element, "background-color", "#" + hex.value);
  15666. });
  15667. };
  15668. var factory2 = function() {
  15669. var state = {
  15670. red: Cell(Optional.some(255)),
  15671. green: Cell(Optional.some(255)),
  15672. blue: Cell(Optional.some(255)),
  15673. hex: Cell(Optional.some("ffffff"))
  15674. };
  15675. var copyHexToRgb = function(form, hex) {
  15676. var rgb = fromHex(hex);
  15677. copyRgbToForm(form, rgb);
  15678. setValueRgb(rgb);
  15679. };
  15680. var get2 = function(prop) {
  15681. return state[prop].get();
  15682. };
  15683. var set2 = function(prop, value2) {
  15684. state[prop].set(value2);
  15685. };
  15686. var getValueRgb = function() {
  15687. return get2("red").bind(function(red2) {
  15688. return get2("green").bind(function(green) {
  15689. return get2("blue").map(function(blue) {
  15690. return rgbaColour(red2, green, blue, 1);
  15691. });
  15692. });
  15693. });
  15694. };
  15695. var setValueRgb = function(rgb) {
  15696. var red2 = rgb.red;
  15697. var green = rgb.green;
  15698. var blue = rgb.blue;
  15699. set2("red", Optional.some(red2));
  15700. set2("green", Optional.some(green));
  15701. set2("blue", Optional.some(blue));
  15702. };
  15703. var onInvalidInput = function(form, simulatedEvent) {
  15704. var data = simulatedEvent.event;
  15705. if (data.type !== "hex") {
  15706. set2(data.type, Optional.none());
  15707. } else {
  15708. onInvalidHexx(form);
  15709. }
  15710. };
  15711. var onValidHex = function(form, value2) {
  15712. onValidHexx(form);
  15713. var hex = hexColour(value2);
  15714. set2("hex", Optional.some(value2));
  15715. var rgb = fromHex(hex);
  15716. copyRgbToForm(form, rgb);
  15717. setValueRgb(rgb);
  15718. emitWith(form, fieldsUpdate, { hex });
  15719. updatePreview(form, hex);
  15720. };
  15721. var onValidRgb = function(form, prop, value2) {
  15722. var val = parseInt(value2, 10);
  15723. set2(prop, Optional.some(val));
  15724. getValueRgb().each(function(rgb) {
  15725. var hex = copyRgbToHex(form, rgb);
  15726. emitWith(form, fieldsUpdate, { hex });
  15727. updatePreview(form, hex);
  15728. });
  15729. };
  15730. var isHexInputEvent = function(data) {
  15731. return data.type === "hex";
  15732. };
  15733. var onValidInput = function(form, simulatedEvent) {
  15734. var data = simulatedEvent.event;
  15735. if (isHexInputEvent(data)) {
  15736. onValidHex(form, data.value);
  15737. } else {
  15738. onValidRgb(form, data.type, data.value);
  15739. }
  15740. };
  15741. var formPartStrings = function(key) {
  15742. return {
  15743. label: translate2(translatePrefix + key + ".label"),
  15744. description: translate2(translatePrefix + key + ".description")
  15745. };
  15746. };
  15747. var redStrings = formPartStrings("red");
  15748. var greenStrings = formPartStrings("green");
  15749. var blueStrings = formPartStrings("blue");
  15750. var hexStrings = formPartStrings("hex");
  15751. return deepMerge(Form.sketch(function(parts2) {
  15752. return {
  15753. dom: {
  15754. tag: "form",
  15755. classes: [getClass("rgb-form")],
  15756. attributes: { "aria-label": translate2("aria.color.picker") }
  15757. },
  15758. components: [
  15759. parts2.field("red", FormField.sketch(renderTextField2(isRgbaComponent, "red", redStrings.label, redStrings.description, 255))),
  15760. parts2.field("green", FormField.sketch(renderTextField2(isRgbaComponent, "green", greenStrings.label, greenStrings.description, 255))),
  15761. parts2.field("blue", FormField.sketch(renderTextField2(isRgbaComponent, "blue", blueStrings.label, blueStrings.description, 255))),
  15762. parts2.field("hex", FormField.sketch(renderTextField2(isHexString, "hex", hexStrings.label, hexStrings.description, "ffffff"))),
  15763. memPreview.asSpec()
  15764. ],
  15765. formBehaviours: derive$1([
  15766. Invalidating.config({ invalidClass: getClass("form-invalid") }),
  15767. config("rgb-form-events", [
  15768. run$1(validInput, onValidInput),
  15769. run$1(invalidInput, onInvalidInput),
  15770. run$1(validatingInput, onInvalidInput)
  15771. ])
  15772. ])
  15773. };
  15774. }), {
  15775. apis: {
  15776. updateHex: function(form, hex) {
  15777. Representing.setValue(form, { hex: hex.value });
  15778. copyHexToRgb(form, hex);
  15779. updatePreview(form, hex);
  15780. }
  15781. }
  15782. });
  15783. };
  15784. var rgbFormSketcher = single({
  15785. factory: factory2,
  15786. name: "RgbForm",
  15787. configFields: [],
  15788. apis: {
  15789. updateHex: function(apis, form, hex) {
  15790. apis.updateHex(form, hex);
  15791. }
  15792. },
  15793. extraApis: {}
  15794. });
  15795. return rgbFormSketcher;
  15796. };
  15797. var paletteFactory = function(_translate, getClass) {
  15798. var spectrumPart2 = Slider.parts.spectrum({
  15799. dom: {
  15800. tag: "canvas",
  15801. attributes: { role: "presentation" },
  15802. classes: [getClass("sv-palette-spectrum")]
  15803. }
  15804. });
  15805. var thumbPart2 = Slider.parts.thumb({
  15806. dom: {
  15807. tag: "div",
  15808. attributes: { role: "presentation" },
  15809. classes: [getClass("sv-palette-thumb")],
  15810. innerHtml: "<div class=" + getClass("sv-palette-inner-thumb") + ' role="presentation"></div>'
  15811. }
  15812. });
  15813. var setColour = function(canvas, rgba) {
  15814. var width2 = canvas.width, height2 = canvas.height;
  15815. var ctx = canvas.getContext("2d");
  15816. if (ctx === null) {
  15817. return;
  15818. }
  15819. ctx.fillStyle = rgba;
  15820. ctx.fillRect(0, 0, width2, height2);
  15821. var grdWhite = ctx.createLinearGradient(0, 0, width2, 0);
  15822. grdWhite.addColorStop(0, "rgba(255,255,255,1)");
  15823. grdWhite.addColorStop(1, "rgba(255,255,255,0)");
  15824. ctx.fillStyle = grdWhite;
  15825. ctx.fillRect(0, 0, width2, height2);
  15826. var grdBlack = ctx.createLinearGradient(0, 0, 0, height2);
  15827. grdBlack.addColorStop(0, "rgba(0,0,0,0)");
  15828. grdBlack.addColorStop(1, "rgba(0,0,0,1)");
  15829. ctx.fillStyle = grdBlack;
  15830. ctx.fillRect(0, 0, width2, height2);
  15831. };
  15832. var setPaletteHue = function(slider, hue) {
  15833. var canvas = slider.components()[0].element.dom;
  15834. var hsv = hsvColour(hue, 100, 100);
  15835. var rgba = fromHsv(hsv);
  15836. setColour(canvas, toString(rgba));
  15837. };
  15838. var setPaletteThumb = function(slider, hex) {
  15839. var hsv = fromRgb(fromHex(hex));
  15840. Slider.setValue(slider, {
  15841. x: hsv.saturation,
  15842. y: 100 - hsv.value
  15843. });
  15844. };
  15845. var factory2 = function(_detail) {
  15846. var getInitialValue = constant$1({
  15847. x: 0,
  15848. y: 0
  15849. });
  15850. var onChange = function(slider, _thumb, value2) {
  15851. emitWith(slider, paletteUpdate, { value: value2 });
  15852. };
  15853. var onInit = function(_slider, _thumb, spectrum, _value) {
  15854. setColour(spectrum.element.dom, toString(red));
  15855. };
  15856. var sliderBehaviours = derive$1([
  15857. Composing.config({ find: Optional.some }),
  15858. Focusing.config({})
  15859. ]);
  15860. return Slider.sketch({
  15861. dom: {
  15862. tag: "div",
  15863. attributes: { role: "presentation" },
  15864. classes: [getClass("sv-palette")]
  15865. },
  15866. model: {
  15867. mode: "xy",
  15868. getInitialValue
  15869. },
  15870. rounded: false,
  15871. components: [
  15872. spectrumPart2,
  15873. thumbPart2
  15874. ],
  15875. onChange,
  15876. onInit,
  15877. sliderBehaviours
  15878. });
  15879. };
  15880. var saturationBrightnessPaletteSketcher = single({
  15881. factory: factory2,
  15882. name: "SaturationBrightnessPalette",
  15883. configFields: [],
  15884. apis: {
  15885. setHue: function(_apis, slider, hue) {
  15886. setPaletteHue(slider, hue);
  15887. },
  15888. setThumb: function(_apis, slider, hex) {
  15889. setPaletteThumb(slider, hex);
  15890. }
  15891. },
  15892. extraApis: {}
  15893. });
  15894. return saturationBrightnessPaletteSketcher;
  15895. };
  15896. var makeFactory = function(translate2, getClass) {
  15897. var factory2 = function(detail) {
  15898. var rgbForm = rgbFormFactory(translate2, getClass, detail.onValidHex, detail.onInvalidHex);
  15899. var sbPalette = paletteFactory(translate2, getClass);
  15900. var hueSliderToDegrees = function(hue) {
  15901. return (100 - hue) / 100 * 360;
  15902. };
  15903. var hueDegreesToSlider = function(hue) {
  15904. return 100 - hue / 360 * 100;
  15905. };
  15906. var state = {
  15907. paletteRgba: Cell(red),
  15908. paletteHue: Cell(0)
  15909. };
  15910. var memSlider = record(sliderFactory(translate2, getClass));
  15911. var memPalette = record(sbPalette.sketch({}));
  15912. var memRgb = record(rgbForm.sketch({}));
  15913. var updatePalette = function(anyInSystem, _hex, hue) {
  15914. memPalette.getOpt(anyInSystem).each(function(palette) {
  15915. sbPalette.setHue(palette, hue);
  15916. });
  15917. };
  15918. var updateFields = function(anyInSystem, hex) {
  15919. memRgb.getOpt(anyInSystem).each(function(form) {
  15920. rgbForm.updateHex(form, hex);
  15921. });
  15922. };
  15923. var updateSlider = function(anyInSystem, _hex, hue) {
  15924. memSlider.getOpt(anyInSystem).each(function(slider) {
  15925. Slider.setValue(slider, { y: hueDegreesToSlider(hue) });
  15926. });
  15927. };
  15928. var updatePaletteThumb = function(anyInSystem, hex) {
  15929. memPalette.getOpt(anyInSystem).each(function(palette) {
  15930. sbPalette.setThumb(palette, hex);
  15931. });
  15932. };
  15933. var updateState = function(hex, hue) {
  15934. var rgba = fromHex(hex);
  15935. state.paletteRgba.set(rgba);
  15936. state.paletteHue.set(hue);
  15937. };
  15938. var runUpdates = function(anyInSystem, hex, hue, updates) {
  15939. updateState(hex, hue);
  15940. each$1(updates, function(update) {
  15941. update(anyInSystem, hex, hue);
  15942. });
  15943. };
  15944. var onPaletteUpdate = function() {
  15945. var updates = [updateFields];
  15946. return function(form, simulatedEvent) {
  15947. var value2 = simulatedEvent.event.value;
  15948. var oldHue = state.paletteHue.get();
  15949. var newHsv = hsvColour(oldHue, value2.x, 100 - value2.y);
  15950. var newHex = hsvToHex(newHsv);
  15951. runUpdates(form, newHex, oldHue, updates);
  15952. };
  15953. };
  15954. var onSliderUpdate = function() {
  15955. var updates = [
  15956. updatePalette,
  15957. updateFields
  15958. ];
  15959. return function(form, simulatedEvent) {
  15960. var hue = hueSliderToDegrees(simulatedEvent.event.value.y);
  15961. var oldRgb = state.paletteRgba.get();
  15962. var oldHsv = fromRgb(oldRgb);
  15963. var newHsv = hsvColour(hue, oldHsv.saturation, oldHsv.value);
  15964. var newHex = hsvToHex(newHsv);
  15965. runUpdates(form, newHex, hue, updates);
  15966. };
  15967. };
  15968. var onFieldsUpdate = function() {
  15969. var updates = [
  15970. updatePalette,
  15971. updateSlider,
  15972. updatePaletteThumb
  15973. ];
  15974. return function(form, simulatedEvent) {
  15975. var hex = simulatedEvent.event.hex;
  15976. var hsv = hexToHsv(hex);
  15977. runUpdates(form, hex, hsv.hue, updates);
  15978. };
  15979. };
  15980. return {
  15981. uid: detail.uid,
  15982. dom: detail.dom,
  15983. components: [
  15984. memPalette.asSpec(),
  15985. memSlider.asSpec(),
  15986. memRgb.asSpec()
  15987. ],
  15988. behaviours: derive$1([
  15989. config("colour-picker-events", [
  15990. run$1(fieldsUpdate, onFieldsUpdate()),
  15991. run$1(paletteUpdate, onPaletteUpdate()),
  15992. run$1(sliderUpdate, onSliderUpdate())
  15993. ]),
  15994. Composing.config({
  15995. find: function(comp) {
  15996. return memRgb.getOpt(comp);
  15997. }
  15998. }),
  15999. Keying.config({ mode: "acyclic" })
  16000. ])
  16001. };
  16002. };
  16003. var colourPickerSketcher = single({
  16004. name: "ColourPicker",
  16005. configFields: [
  16006. required$1("dom"),
  16007. defaulted("onValidHex", noop),
  16008. defaulted("onInvalidHex", noop)
  16009. ],
  16010. factory: factory2
  16011. });
  16012. return colourPickerSketcher;
  16013. };
  16014. var self$1 = function() {
  16015. return Composing.config({ find: Optional.some });
  16016. };
  16017. var memento$1 = function(mem) {
  16018. return Composing.config({ find: mem.getOpt });
  16019. };
  16020. var childAt = function(index) {
  16021. return Composing.config({
  16022. find: function(comp) {
  16023. return child$2(comp.element, index).bind(function(element2) {
  16024. return comp.getSystem().getByDom(element2).toOptional();
  16025. });
  16026. }
  16027. });
  16028. };
  16029. var ComposingConfigs = {
  16030. self: self$1,
  16031. memento: memento$1,
  16032. childAt
  16033. };
  16034. var english = {
  16035. "colorcustom.rgb.red.label": "R",
  16036. "colorcustom.rgb.red.description": "Red component",
  16037. "colorcustom.rgb.green.label": "G",
  16038. "colorcustom.rgb.green.description": "Green component",
  16039. "colorcustom.rgb.blue.label": "B",
  16040. "colorcustom.rgb.blue.description": "Blue component",
  16041. "colorcustom.rgb.hex.label": "#",
  16042. "colorcustom.rgb.hex.description": "Hex color code",
  16043. "colorcustom.rgb.range": "Range 0 to 255",
  16044. "colorcustom.sb.saturation": "Saturation",
  16045. "colorcustom.sb.brightness": "Brightness",
  16046. "colorcustom.sb.picker": "Saturation and Brightness Picker",
  16047. "colorcustom.sb.palette": "Saturation and Brightness Palette",
  16048. "colorcustom.sb.instructions": "Use arrow keys to select saturation and brightness, on x and y axes",
  16049. "colorcustom.hue.hue": "Hue",
  16050. "colorcustom.hue.slider": "Hue Slider",
  16051. "colorcustom.hue.palette": "Hue Palette",
  16052. "colorcustom.hue.instructions": "Use arrow keys to select a hue",
  16053. "aria.color.picker": "Color Picker",
  16054. "aria.input.invalid": "Invalid input"
  16055. };
  16056. var getEnglishText = function(key) {
  16057. return english[key];
  16058. };
  16059. var translate$1 = function(key) {
  16060. return getEnglishText(key);
  16061. };
  16062. var renderColorPicker = function(_spec) {
  16063. var getClass = function(key) {
  16064. return "tox-" + key;
  16065. };
  16066. var colourPickerFactory = makeFactory(translate$1, getClass);
  16067. var onValidHex = function(form) {
  16068. emitWith(form, formActionEvent, {
  16069. name: "hex-valid",
  16070. value: true
  16071. });
  16072. };
  16073. var onInvalidHex = function(form) {
  16074. emitWith(form, formActionEvent, {
  16075. name: "hex-valid",
  16076. value: false
  16077. });
  16078. };
  16079. var memPicker = record(colourPickerFactory.sketch({
  16080. dom: {
  16081. tag: "div",
  16082. classes: [getClass("color-picker-container")],
  16083. attributes: { role: "presentation" }
  16084. },
  16085. onValidHex,
  16086. onInvalidHex
  16087. }));
  16088. return {
  16089. dom: { tag: "div" },
  16090. components: [memPicker.asSpec()],
  16091. behaviours: derive$1([
  16092. Representing.config({
  16093. store: {
  16094. mode: "manual",
  16095. getValue: function(comp) {
  16096. var picker = memPicker.get(comp);
  16097. var optRgbForm = Composing.getCurrent(picker);
  16098. var optHex = optRgbForm.bind(function(rgbForm) {
  16099. var formValues = Representing.getValue(rgbForm);
  16100. return formValues.hex;
  16101. });
  16102. return optHex.map(function(hex) {
  16103. return "#" + hex;
  16104. }).getOr("");
  16105. },
  16106. setValue: function(comp, newValue) {
  16107. var pattern2 = /^#([a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?)/;
  16108. var m = pattern2.exec(newValue);
  16109. var picker = memPicker.get(comp);
  16110. var optRgbForm = Composing.getCurrent(picker);
  16111. optRgbForm.fold(function() {
  16112. console.log("Can not find form");
  16113. }, function(rgbForm) {
  16114. Representing.setValue(rgbForm, { hex: Optional.from(m[1]).getOr("") });
  16115. Form.getField(rgbForm, "hex").each(function(hexField) {
  16116. emit(hexField, input());
  16117. });
  16118. });
  16119. }
  16120. }
  16121. }),
  16122. ComposingConfigs.self()
  16123. ])
  16124. };
  16125. };
  16126. var global$6 = tinymce.util.Tools.resolve("tinymce.Resource");
  16127. var isOldCustomEditor = function(spec) {
  16128. return has$2(spec, "init");
  16129. };
  16130. var renderCustomEditor = function(spec) {
  16131. var editorApi = value$1();
  16132. var memReplaced = record({ dom: { tag: spec.tag } });
  16133. var initialValue = value$1();
  16134. return {
  16135. dom: {
  16136. tag: "div",
  16137. classes: ["tox-custom-editor"]
  16138. },
  16139. behaviours: derive$1([
  16140. config("custom-editor-events", [runOnAttached(function(component) {
  16141. memReplaced.getOpt(component).each(function(ta) {
  16142. (isOldCustomEditor(spec) ? spec.init(ta.element.dom) : global$6.load(spec.scriptId, spec.scriptUrl).then(function(init2) {
  16143. return init2(ta.element.dom, spec.settings);
  16144. })).then(function(ea) {
  16145. initialValue.on(function(cvalue) {
  16146. ea.setValue(cvalue);
  16147. });
  16148. initialValue.clear();
  16149. editorApi.set(ea);
  16150. });
  16151. });
  16152. })]),
  16153. Representing.config({
  16154. store: {
  16155. mode: "manual",
  16156. getValue: function() {
  16157. return editorApi.get().fold(function() {
  16158. return initialValue.get().getOr("");
  16159. }, function(ed) {
  16160. return ed.getValue();
  16161. });
  16162. },
  16163. setValue: function(component, value2) {
  16164. editorApi.get().fold(function() {
  16165. initialValue.set(value2);
  16166. }, function(ed) {
  16167. return ed.setValue(value2);
  16168. });
  16169. }
  16170. }
  16171. }),
  16172. ComposingConfigs.self()
  16173. ]),
  16174. components: [memReplaced.asSpec()]
  16175. };
  16176. };
  16177. var global$5 = tinymce.util.Tools.resolve("tinymce.util.Tools");
  16178. var processors = objOf([
  16179. defaulted("preprocess", identity$1),
  16180. defaulted("postprocess", identity$1)
  16181. ]);
  16182. var memento = function(mem, rawProcessors) {
  16183. var ps = asRawOrDie$1("RepresentingConfigs.memento processors", processors, rawProcessors);
  16184. return Representing.config({
  16185. store: {
  16186. mode: "manual",
  16187. getValue: function(comp) {
  16188. var other = mem.get(comp);
  16189. var rawValue = Representing.getValue(other);
  16190. return ps.postprocess(rawValue);
  16191. },
  16192. setValue: function(comp, rawValue) {
  16193. var newValue = ps.preprocess(rawValue);
  16194. var other = mem.get(comp);
  16195. Representing.setValue(other, newValue);
  16196. }
  16197. }
  16198. });
  16199. };
  16200. var withComp = function(optInitialValue, getter, setter) {
  16201. return Representing.config(deepMerge({
  16202. store: {
  16203. mode: "manual",
  16204. getValue: getter,
  16205. setValue: setter
  16206. }
  16207. }, optInitialValue.map(function(initialValue) {
  16208. return { store: { initialValue } };
  16209. }).getOr({})));
  16210. };
  16211. var withElement = function(initialValue, getter, setter) {
  16212. return withComp(initialValue, function(c) {
  16213. return getter(c.element);
  16214. }, function(c, v) {
  16215. return setter(c.element, v);
  16216. });
  16217. };
  16218. var domValue = function(optInitialValue) {
  16219. return withElement(optInitialValue, get$5, set$4);
  16220. };
  16221. var domHtml = function(optInitialValue) {
  16222. return withElement(optInitialValue, get$7, set$5);
  16223. };
  16224. var memory = function(initialValue) {
  16225. return Representing.config({
  16226. store: {
  16227. mode: "memory",
  16228. initialValue
  16229. }
  16230. });
  16231. };
  16232. var RepresentingConfigs = {
  16233. memento,
  16234. withElement,
  16235. withComp,
  16236. domValue,
  16237. domHtml,
  16238. memory
  16239. };
  16240. var defaultImageFileTypes = "jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp";
  16241. var filterByExtension = function(files, providersBackstage) {
  16242. var allowedImageFileTypes = global$5.explode(providersBackstage.getSetting("images_file_types", defaultImageFileTypes, "string"));
  16243. var isFileInAllowedTypes = function(file) {
  16244. return exists(allowedImageFileTypes, function(type2) {
  16245. return endsWith(file.name.toLowerCase(), "." + type2.toLowerCase());
  16246. });
  16247. };
  16248. return filter$2(from(files), isFileInAllowedTypes);
  16249. };
  16250. var renderDropZone = function(spec, providersBackstage) {
  16251. var stopper2 = function(_, se) {
  16252. se.stop();
  16253. };
  16254. var sequence2 = function(actions) {
  16255. return function(comp, se) {
  16256. each$1(actions, function(a) {
  16257. a(comp, se);
  16258. });
  16259. };
  16260. };
  16261. var onDrop = function(comp, se) {
  16262. if (!Disabling.isDisabled(comp)) {
  16263. var transferEvent = se.event.raw;
  16264. handleFiles(comp, transferEvent.dataTransfer.files);
  16265. }
  16266. };
  16267. var onSelect = function(component, simulatedEvent) {
  16268. var input2 = simulatedEvent.event.raw.target;
  16269. handleFiles(component, input2.files);
  16270. };
  16271. var handleFiles = function(component, files) {
  16272. Representing.setValue(component, filterByExtension(files, providersBackstage));
  16273. emitWith(component, formChangeEvent, { name: spec.name });
  16274. };
  16275. var memInput = record({
  16276. dom: {
  16277. tag: "input",
  16278. attributes: {
  16279. type: "file",
  16280. accept: "image/*"
  16281. },
  16282. styles: { display: "none" }
  16283. },
  16284. behaviours: derive$1([config("input-file-events", [
  16285. cutter(click()),
  16286. cutter(tap())
  16287. ])])
  16288. });
  16289. var renderField = function(s) {
  16290. return {
  16291. uid: s.uid,
  16292. dom: {
  16293. tag: "div",
  16294. classes: ["tox-dropzone-container"]
  16295. },
  16296. behaviours: derive$1([
  16297. RepresentingConfigs.memory([]),
  16298. ComposingConfigs.self(),
  16299. Disabling.config({}),
  16300. Toggling.config({
  16301. toggleClass: "dragenter",
  16302. toggleOnExecute: false
  16303. }),
  16304. config("dropzone-events", [
  16305. run$1("dragenter", sequence2([
  16306. stopper2,
  16307. Toggling.toggle
  16308. ])),
  16309. run$1("dragleave", sequence2([
  16310. stopper2,
  16311. Toggling.toggle
  16312. ])),
  16313. run$1("dragover", stopper2),
  16314. run$1("drop", sequence2([
  16315. stopper2,
  16316. onDrop
  16317. ])),
  16318. run$1(change(), onSelect)
  16319. ])
  16320. ]),
  16321. components: [{
  16322. dom: {
  16323. tag: "div",
  16324. classes: ["tox-dropzone"],
  16325. styles: {}
  16326. },
  16327. components: [
  16328. {
  16329. dom: {
  16330. tag: "p",
  16331. innerHtml: providersBackstage.translate("Drop an image here")
  16332. }
  16333. },
  16334. Button.sketch({
  16335. dom: {
  16336. tag: "button",
  16337. innerHtml: providersBackstage.translate("Browse for an image"),
  16338. styles: { position: "relative" },
  16339. classes: [
  16340. "tox-button",
  16341. "tox-button--secondary"
  16342. ]
  16343. },
  16344. components: [memInput.asSpec()],
  16345. action: function(comp) {
  16346. var inputComp = memInput.get(comp);
  16347. inputComp.element.dom.click();
  16348. },
  16349. buttonBehaviours: derive$1([
  16350. Tabstopping.config({}),
  16351. DisablingConfigs.button(providersBackstage.isDisabled),
  16352. receivingConfig()
  16353. ])
  16354. })
  16355. ]
  16356. }]
  16357. };
  16358. };
  16359. var pLabel = spec.label.map(function(label) {
  16360. return renderLabel$2(label, providersBackstage);
  16361. });
  16362. var pField = FormField.parts.field({ factory: { sketch: renderField } });
  16363. return renderFormFieldWith(pLabel, pField, ["tox-form__group--stretched"], []);
  16364. };
  16365. var renderGrid = function(spec, backstage) {
  16366. return {
  16367. dom: {
  16368. tag: "div",
  16369. classes: [
  16370. "tox-form__grid",
  16371. "tox-form__grid--" + spec.columns + "col"
  16372. ]
  16373. },
  16374. components: map$2(spec.items, backstage.interpreter)
  16375. };
  16376. };
  16377. var beforeObject = generate$6("alloy-fake-before-tabstop");
  16378. var afterObject = generate$6("alloy-fake-after-tabstop");
  16379. var craftWithClasses = function(classes2) {
  16380. return {
  16381. dom: {
  16382. tag: "div",
  16383. styles: {
  16384. width: "1px",
  16385. height: "1px",
  16386. outline: "none"
  16387. },
  16388. attributes: { tabindex: "0" },
  16389. classes: classes2
  16390. },
  16391. behaviours: derive$1([
  16392. Focusing.config({ ignore: true }),
  16393. Tabstopping.config({})
  16394. ])
  16395. };
  16396. };
  16397. var craft = function(spec) {
  16398. return {
  16399. dom: {
  16400. tag: "div",
  16401. classes: ["tox-navobj"]
  16402. },
  16403. components: [
  16404. craftWithClasses([beforeObject]),
  16405. spec,
  16406. craftWithClasses([afterObject])
  16407. ],
  16408. behaviours: derive$1([ComposingConfigs.childAt(1)])
  16409. };
  16410. };
  16411. var triggerTab = function(placeholder2, shiftKey) {
  16412. emitWith(placeholder2, keydown(), {
  16413. raw: {
  16414. which: 9,
  16415. shiftKey
  16416. }
  16417. });
  16418. };
  16419. var onFocus = function(container, targetComp) {
  16420. var target = targetComp.element;
  16421. if (has(target, beforeObject)) {
  16422. triggerTab(container, true);
  16423. } else if (has(target, afterObject)) {
  16424. triggerTab(container, false);
  16425. }
  16426. };
  16427. var isPseudoStop = function(element2) {
  16428. return closest(element2, [
  16429. "." + beforeObject,
  16430. "." + afterObject
  16431. ].join(","), never);
  16432. };
  16433. var platformNeedsSandboxing = !(detect$1().browser.isIE() || detect$1().browser.isEdge());
  16434. var getDynamicSource = function(isSandbox) {
  16435. var cachedValue = Cell("");
  16436. return {
  16437. getValue: function(_frameComponent) {
  16438. return cachedValue.get();
  16439. },
  16440. setValue: function(frameComponent, html2) {
  16441. if (!isSandbox) {
  16442. set$8(frameComponent.element, "src", "javascript:''");
  16443. var doc = frameComponent.element.dom.contentWindow.document;
  16444. doc.open();
  16445. doc.write(html2);
  16446. doc.close();
  16447. } else {
  16448. set$8(frameComponent.element, "srcdoc", html2);
  16449. }
  16450. cachedValue.set(html2);
  16451. }
  16452. };
  16453. };
  16454. var renderIFrame = function(spec, providersBackstage) {
  16455. var isSandbox = platformNeedsSandboxing && spec.sandboxed;
  16456. var attributes = __assign(__assign({}, spec.label.map(function(title) {
  16457. return { title };
  16458. }).getOr({})), isSandbox ? { sandbox: "allow-scripts allow-same-origin" } : {});
  16459. var sourcing = getDynamicSource(isSandbox);
  16460. var pLabel = spec.label.map(function(label) {
  16461. return renderLabel$2(label, providersBackstage);
  16462. });
  16463. var factory2 = function(newSpec) {
  16464. return craft({
  16465. uid: newSpec.uid,
  16466. dom: {
  16467. tag: "iframe",
  16468. attributes
  16469. },
  16470. behaviours: derive$1([
  16471. Tabstopping.config({}),
  16472. Focusing.config({}),
  16473. RepresentingConfigs.withComp(Optional.none(), sourcing.getValue, sourcing.setValue)
  16474. ])
  16475. });
  16476. };
  16477. var pField = FormField.parts.field({ factory: { sketch: factory2 } });
  16478. return renderFormFieldWith(pLabel, pField, ["tox-form__group--stretched"], []);
  16479. };
  16480. var create$4 = function(width2, height2) {
  16481. return resize$3(document.createElement("canvas"), width2, height2);
  16482. };
  16483. var clone$1 = function(canvas) {
  16484. var tCanvas = create$4(canvas.width, canvas.height);
  16485. var ctx = get2dContext(tCanvas);
  16486. ctx.drawImage(canvas, 0, 0);
  16487. return tCanvas;
  16488. };
  16489. var get2dContext = function(canvas) {
  16490. return canvas.getContext("2d");
  16491. };
  16492. var resize$3 = function(canvas, width2, height2) {
  16493. canvas.width = width2;
  16494. canvas.height = height2;
  16495. return canvas;
  16496. };
  16497. var getWidth$1 = function(image) {
  16498. return image.naturalWidth || image.width;
  16499. };
  16500. var getHeight$1 = function(image) {
  16501. return image.naturalHeight || image.height;
  16502. };
  16503. var blobToImage = function(blob) {
  16504. return new Promise$1(function(resolve, reject) {
  16505. var blobUrl = URL.createObjectURL(blob);
  16506. var image = new Image();
  16507. var removeListeners = function() {
  16508. image.removeEventListener("load", loaded);
  16509. image.removeEventListener("error", error2);
  16510. };
  16511. var loaded = function() {
  16512. removeListeners();
  16513. resolve(image);
  16514. };
  16515. var error2 = function() {
  16516. removeListeners();
  16517. reject("Unable to load data of type " + blob.type + ": " + blobUrl);
  16518. };
  16519. image.addEventListener("load", loaded);
  16520. image.addEventListener("error", error2);
  16521. image.src = blobUrl;
  16522. if (image.complete) {
  16523. setTimeout(loaded, 0);
  16524. }
  16525. });
  16526. };
  16527. var dataUriToBlobSync = function(uri) {
  16528. var data = uri.split(",");
  16529. var matches = /data:([^;]+)/.exec(data[0]);
  16530. if (!matches) {
  16531. return Optional.none();
  16532. }
  16533. var mimetype = matches[1];
  16534. var base64 = data[1];
  16535. var sliceSize = 1024;
  16536. var byteCharacters = atob(base64);
  16537. var bytesLength = byteCharacters.length;
  16538. var slicesCount = Math.ceil(bytesLength / sliceSize);
  16539. var byteArrays = new Array(slicesCount);
  16540. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
  16541. var begin = sliceIndex * sliceSize;
  16542. var end = Math.min(begin + sliceSize, bytesLength);
  16543. var bytes = new Array(end - begin);
  16544. for (var offset2 = begin, i = 0; offset2 < end; ++i, ++offset2) {
  16545. bytes[i] = byteCharacters[offset2].charCodeAt(0);
  16546. }
  16547. byteArrays[sliceIndex] = new Uint8Array(bytes);
  16548. }
  16549. return Optional.some(new Blob(byteArrays, { type: mimetype }));
  16550. };
  16551. var dataUriToBlob = function(uri) {
  16552. return new Promise$1(function(resolve, reject) {
  16553. dataUriToBlobSync(uri).fold(function() {
  16554. reject("uri is not base64: " + uri);
  16555. }, resolve);
  16556. });
  16557. };
  16558. var canvasToBlob = function(canvas, type2, quality) {
  16559. type2 = type2 || "image/png";
  16560. if (isFunction(HTMLCanvasElement.prototype.toBlob)) {
  16561. return new Promise$1(function(resolve, reject) {
  16562. canvas.toBlob(function(blob) {
  16563. if (blob) {
  16564. resolve(blob);
  16565. } else {
  16566. reject();
  16567. }
  16568. }, type2, quality);
  16569. });
  16570. } else {
  16571. return dataUriToBlob(canvas.toDataURL(type2, quality));
  16572. }
  16573. };
  16574. var canvasToDataURL = function(canvas, type2, quality) {
  16575. type2 = type2 || "image/png";
  16576. return canvas.toDataURL(type2, quality);
  16577. };
  16578. var blobToCanvas = function(blob) {
  16579. return blobToImage(blob).then(function(image) {
  16580. revokeImageUrl(image);
  16581. var canvas = create$4(getWidth$1(image), getHeight$1(image));
  16582. var context = get2dContext(canvas);
  16583. context.drawImage(image, 0, 0);
  16584. return canvas;
  16585. });
  16586. };
  16587. var blobToDataUri = function(blob) {
  16588. return new Promise$1(function(resolve) {
  16589. var reader = new FileReader();
  16590. reader.onloadend = function() {
  16591. resolve(reader.result);
  16592. };
  16593. reader.readAsDataURL(blob);
  16594. });
  16595. };
  16596. var revokeImageUrl = function(image) {
  16597. URL.revokeObjectURL(image.src);
  16598. };
  16599. var create$3 = function(getCanvas, blob, uri) {
  16600. var initialType = blob.type;
  16601. var getType = constant$1(initialType);
  16602. var toBlob = function() {
  16603. return Promise$1.resolve(blob);
  16604. };
  16605. var toDataURL = constant$1(uri);
  16606. var toBase64 = function() {
  16607. return uri.split(",")[1];
  16608. };
  16609. var toAdjustedBlob = function(type2, quality) {
  16610. return getCanvas.then(function(canvas) {
  16611. return canvasToBlob(canvas, type2, quality);
  16612. });
  16613. };
  16614. var toAdjustedDataURL = function(type2, quality) {
  16615. return getCanvas.then(function(canvas) {
  16616. return canvasToDataURL(canvas, type2, quality);
  16617. });
  16618. };
  16619. var toAdjustedBase64 = function(type2, quality) {
  16620. return toAdjustedDataURL(type2, quality).then(function(dataurl) {
  16621. return dataurl.split(",")[1];
  16622. });
  16623. };
  16624. var toCanvas = function() {
  16625. return getCanvas.then(clone$1);
  16626. };
  16627. return {
  16628. getType,
  16629. toBlob,
  16630. toDataURL,
  16631. toBase64,
  16632. toAdjustedBlob,
  16633. toAdjustedDataURL,
  16634. toAdjustedBase64,
  16635. toCanvas
  16636. };
  16637. };
  16638. var fromBlob = function(blob) {
  16639. return blobToDataUri(blob).then(function(uri) {
  16640. return create$3(blobToCanvas(blob), blob, uri);
  16641. });
  16642. };
  16643. var fromCanvas = function(canvas, type2) {
  16644. return canvasToBlob(canvas, type2).then(function(blob) {
  16645. return create$3(Promise$1.resolve(canvas), blob, canvas.toDataURL());
  16646. });
  16647. };
  16648. var blobToImageResult = function(blob) {
  16649. return fromBlob(blob);
  16650. };
  16651. var clamp = function(value2, min2, max2) {
  16652. var parsedValue = typeof value2 === "string" ? parseFloat(value2) : value2;
  16653. if (parsedValue > max2) {
  16654. parsedValue = max2;
  16655. } else if (parsedValue < min2) {
  16656. parsedValue = min2;
  16657. }
  16658. return parsedValue;
  16659. };
  16660. var identity = function() {
  16661. return [
  16662. 1,
  16663. 0,
  16664. 0,
  16665. 0,
  16666. 0,
  16667. 0,
  16668. 1,
  16669. 0,
  16670. 0,
  16671. 0,
  16672. 0,
  16673. 0,
  16674. 1,
  16675. 0,
  16676. 0,
  16677. 0,
  16678. 0,
  16679. 0,
  16680. 1,
  16681. 0,
  16682. 0,
  16683. 0,
  16684. 0,
  16685. 0,
  16686. 1
  16687. ];
  16688. };
  16689. var DELTA_INDEX = [
  16690. 0,
  16691. 0.01,
  16692. 0.02,
  16693. 0.04,
  16694. 0.05,
  16695. 0.06,
  16696. 0.07,
  16697. 0.08,
  16698. 0.1,
  16699. 0.11,
  16700. 0.12,
  16701. 0.14,
  16702. 0.15,
  16703. 0.16,
  16704. 0.17,
  16705. 0.18,
  16706. 0.2,
  16707. 0.21,
  16708. 0.22,
  16709. 0.24,
  16710. 0.25,
  16711. 0.27,
  16712. 0.28,
  16713. 0.3,
  16714. 0.32,
  16715. 0.34,
  16716. 0.36,
  16717. 0.38,
  16718. 0.4,
  16719. 0.42,
  16720. 0.44,
  16721. 0.46,
  16722. 0.48,
  16723. 0.5,
  16724. 0.53,
  16725. 0.56,
  16726. 0.59,
  16727. 0.62,
  16728. 0.65,
  16729. 0.68,
  16730. 0.71,
  16731. 0.74,
  16732. 0.77,
  16733. 0.8,
  16734. 0.83,
  16735. 0.86,
  16736. 0.89,
  16737. 0.92,
  16738. 0.95,
  16739. 0.98,
  16740. 1,
  16741. 1.06,
  16742. 1.12,
  16743. 1.18,
  16744. 1.24,
  16745. 1.3,
  16746. 1.36,
  16747. 1.42,
  16748. 1.48,
  16749. 1.54,
  16750. 1.6,
  16751. 1.66,
  16752. 1.72,
  16753. 1.78,
  16754. 1.84,
  16755. 1.9,
  16756. 1.96,
  16757. 2,
  16758. 2.12,
  16759. 2.25,
  16760. 2.37,
  16761. 2.5,
  16762. 2.62,
  16763. 2.75,
  16764. 2.87,
  16765. 3,
  16766. 3.2,
  16767. 3.4,
  16768. 3.6,
  16769. 3.8,
  16770. 4,
  16771. 4.3,
  16772. 4.7,
  16773. 4.9,
  16774. 5,
  16775. 5.5,
  16776. 6,
  16777. 6.5,
  16778. 6.8,
  16779. 7,
  16780. 7.3,
  16781. 7.5,
  16782. 7.8,
  16783. 8,
  16784. 8.4,
  16785. 8.7,
  16786. 9,
  16787. 9.4,
  16788. 9.6,
  16789. 9.8,
  16790. 10
  16791. ];
  16792. var multiply = function(matrix1, matrix2) {
  16793. var col = [];
  16794. var out = new Array(25);
  16795. var val;
  16796. for (var i = 0; i < 5; i++) {
  16797. for (var j = 0; j < 5; j++) {
  16798. col[j] = matrix2[j + i * 5];
  16799. }
  16800. for (var j = 0; j < 5; j++) {
  16801. val = 0;
  16802. for (var k = 0; k < 5; k++) {
  16803. val += matrix1[j + k * 5] * col[k];
  16804. }
  16805. out[j + i * 5] = val;
  16806. }
  16807. }
  16808. return out;
  16809. };
  16810. var adjustContrast = function(matrix2, value2) {
  16811. var x;
  16812. value2 = clamp(value2, -1, 1);
  16813. value2 *= 100;
  16814. if (value2 < 0) {
  16815. x = 127 + value2 / 100 * 127;
  16816. } else {
  16817. x = value2 % 1;
  16818. if (x === 0) {
  16819. x = DELTA_INDEX[value2];
  16820. } else {
  16821. x = DELTA_INDEX[Math.floor(value2)] * (1 - x) + DELTA_INDEX[Math.floor(value2) + 1] * x;
  16822. }
  16823. x = x * 127 + 127;
  16824. }
  16825. return multiply(matrix2, [
  16826. x / 127,
  16827. 0,
  16828. 0,
  16829. 0,
  16830. 0.5 * (127 - x),
  16831. 0,
  16832. x / 127,
  16833. 0,
  16834. 0,
  16835. 0.5 * (127 - x),
  16836. 0,
  16837. 0,
  16838. x / 127,
  16839. 0,
  16840. 0.5 * (127 - x),
  16841. 0,
  16842. 0,
  16843. 0,
  16844. 1,
  16845. 0,
  16846. 0,
  16847. 0,
  16848. 0,
  16849. 0,
  16850. 1
  16851. ]);
  16852. };
  16853. var adjustBrightness = function(matrix2, value2) {
  16854. value2 = clamp(255 * value2, -255, 255);
  16855. return multiply(matrix2, [
  16856. 1,
  16857. 0,
  16858. 0,
  16859. 0,
  16860. value2,
  16861. 0,
  16862. 1,
  16863. 0,
  16864. 0,
  16865. value2,
  16866. 0,
  16867. 0,
  16868. 1,
  16869. 0,
  16870. value2,
  16871. 0,
  16872. 0,
  16873. 0,
  16874. 1,
  16875. 0,
  16876. 0,
  16877. 0,
  16878. 0,
  16879. 0,
  16880. 1
  16881. ]);
  16882. };
  16883. var adjustColors = function(matrix2, adjustR, adjustG, adjustB) {
  16884. adjustR = clamp(adjustR, 0, 2);
  16885. adjustG = clamp(adjustG, 0, 2);
  16886. adjustB = clamp(adjustB, 0, 2);
  16887. return multiply(matrix2, [
  16888. adjustR,
  16889. 0,
  16890. 0,
  16891. 0,
  16892. 0,
  16893. 0,
  16894. adjustG,
  16895. 0,
  16896. 0,
  16897. 0,
  16898. 0,
  16899. 0,
  16900. adjustB,
  16901. 0,
  16902. 0,
  16903. 0,
  16904. 0,
  16905. 0,
  16906. 1,
  16907. 0,
  16908. 0,
  16909. 0,
  16910. 0,
  16911. 0,
  16912. 1
  16913. ]);
  16914. };
  16915. var colorFilter = function(ir, matrix2) {
  16916. return ir.toCanvas().then(function(canvas) {
  16917. return applyColorFilter(canvas, ir.getType(), matrix2);
  16918. });
  16919. };
  16920. var applyColorFilter = function(canvas, type2, matrix2) {
  16921. var context = get2dContext(canvas);
  16922. var applyMatrix = function(pixelsData, m) {
  16923. var r2, g, b2, a;
  16924. 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];
  16925. for (var i = 0; i < data.length; i += 4) {
  16926. r2 = data[i];
  16927. g = data[i + 1];
  16928. b2 = data[i + 2];
  16929. a = data[i + 3];
  16930. data[i] = r2 * m0 + g * m1 + b2 * m2 + a * m3 + m4;
  16931. data[i + 1] = r2 * m5 + g * m6 + b2 * m7 + a * m8 + m9;
  16932. data[i + 2] = r2 * m10 + g * m11 + b2 * m12 + a * m13 + m14;
  16933. data[i + 3] = r2 * m15 + g * m16 + b2 * m17 + a * m18 + m19;
  16934. }
  16935. return pixelsData;
  16936. };
  16937. var pixels = applyMatrix(context.getImageData(0, 0, canvas.width, canvas.height), matrix2);
  16938. context.putImageData(pixels, 0, 0);
  16939. return fromCanvas(canvas, type2);
  16940. };
  16941. var convoluteFilter = function(ir, matrix2) {
  16942. return ir.toCanvas().then(function(canvas) {
  16943. return applyConvoluteFilter(canvas, ir.getType(), matrix2);
  16944. });
  16945. };
  16946. var applyConvoluteFilter = function(canvas, type2, matrix2) {
  16947. var context = get2dContext(canvas);
  16948. var applyMatrix = function(pIn, pOut, aMatrix) {
  16949. var clamp2 = function(value2, min2, max2) {
  16950. if (value2 > max2) {
  16951. value2 = max2;
  16952. } else if (value2 < min2) {
  16953. value2 = min2;
  16954. }
  16955. return value2;
  16956. };
  16957. var side = Math.round(Math.sqrt(aMatrix.length));
  16958. var halfSide = Math.floor(side / 2);
  16959. var rgba = pIn.data;
  16960. var drgba = pOut.data;
  16961. var w = pIn.width;
  16962. var h = pIn.height;
  16963. for (var y = 0; y < h; y++) {
  16964. for (var x = 0; x < w; x++) {
  16965. var r2 = 0;
  16966. var g = 0;
  16967. var b2 = 0;
  16968. for (var cy = 0; cy < side; cy++) {
  16969. for (var cx = 0; cx < side; cx++) {
  16970. var scx = clamp2(x + cx - halfSide, 0, w - 1);
  16971. var scy = clamp2(y + cy - halfSide, 0, h - 1);
  16972. var innerOffset = (scy * w + scx) * 4;
  16973. var wt = aMatrix[cy * side + cx];
  16974. r2 += rgba[innerOffset] * wt;
  16975. g += rgba[innerOffset + 1] * wt;
  16976. b2 += rgba[innerOffset + 2] * wt;
  16977. }
  16978. }
  16979. var offset2 = (y * w + x) * 4;
  16980. drgba[offset2] = clamp2(r2, 0, 255);
  16981. drgba[offset2 + 1] = clamp2(g, 0, 255);
  16982. drgba[offset2 + 2] = clamp2(b2, 0, 255);
  16983. }
  16984. }
  16985. return pOut;
  16986. };
  16987. var pixelsIn = context.getImageData(0, 0, canvas.width, canvas.height);
  16988. var pixelsOut = context.getImageData(0, 0, canvas.width, canvas.height);
  16989. pixelsOut = applyMatrix(pixelsIn, pixelsOut, matrix2);
  16990. context.putImageData(pixelsOut, 0, 0);
  16991. return fromCanvas(canvas, type2);
  16992. };
  16993. var functionColorFilter = function(colorFn) {
  16994. var filterImpl = function(canvas, type2, value2) {
  16995. var context = get2dContext(canvas);
  16996. var lookup2 = new Array(256);
  16997. var applyLookup = function(pixelsData, lookupData) {
  16998. var data = pixelsData.data;
  16999. for (var i2 = 0; i2 < data.length; i2 += 4) {
  17000. data[i2] = lookupData[data[i2]];
  17001. data[i2 + 1] = lookupData[data[i2 + 1]];
  17002. data[i2 + 2] = lookupData[data[i2 + 2]];
  17003. }
  17004. return pixelsData;
  17005. };
  17006. for (var i = 0; i < lookup2.length; i++) {
  17007. lookup2[i] = colorFn(i, value2);
  17008. }
  17009. var pixels = applyLookup(context.getImageData(0, 0, canvas.width, canvas.height), lookup2);
  17010. context.putImageData(pixels, 0, 0);
  17011. return fromCanvas(canvas, type2);
  17012. };
  17013. return function(ir, value2) {
  17014. return ir.toCanvas().then(function(canvas) {
  17015. return filterImpl(canvas, ir.getType(), value2);
  17016. });
  17017. };
  17018. };
  17019. var complexAdjustableColorFilter = function(matrixAdjustFn) {
  17020. return function(ir, adjust) {
  17021. return colorFilter(ir, matrixAdjustFn(identity(), adjust));
  17022. };
  17023. };
  17024. var basicColorFilter = function(matrix2) {
  17025. return function(ir) {
  17026. return colorFilter(ir, matrix2);
  17027. };
  17028. };
  17029. var basicConvolutionFilter = function(kernel) {
  17030. return function(ir) {
  17031. return convoluteFilter(ir, kernel);
  17032. };
  17033. };
  17034. var invert$1 = basicColorFilter([
  17035. -1,
  17036. 0,
  17037. 0,
  17038. 0,
  17039. 255,
  17040. 0,
  17041. -1,
  17042. 0,
  17043. 0,
  17044. 255,
  17045. 0,
  17046. 0,
  17047. -1,
  17048. 0,
  17049. 255,
  17050. 0,
  17051. 0,
  17052. 0,
  17053. 1,
  17054. 0,
  17055. 0,
  17056. 0,
  17057. 0,
  17058. 0,
  17059. 1
  17060. ]);
  17061. var brightness$1 = complexAdjustableColorFilter(adjustBrightness);
  17062. var contrast$1 = complexAdjustableColorFilter(adjustContrast);
  17063. var colorize$1 = function(ir, adjustR, adjustG, adjustB) {
  17064. return colorFilter(ir, adjustColors(identity(), adjustR, adjustG, adjustB));
  17065. };
  17066. var sharpen$1 = basicConvolutionFilter([
  17067. 0,
  17068. -1,
  17069. 0,
  17070. -1,
  17071. 5,
  17072. -1,
  17073. 0,
  17074. -1,
  17075. 0
  17076. ]);
  17077. var gamma$1 = functionColorFilter(function(color, value2) {
  17078. return Math.pow(color / 255, 1 - value2) * 255;
  17079. });
  17080. var scale = function(image, dW, dH) {
  17081. var sW = getWidth$1(image);
  17082. var sH = getHeight$1(image);
  17083. var wRatio = dW / sW;
  17084. var hRatio = dH / sH;
  17085. var scaleCapped = false;
  17086. if (wRatio < 0.5 || wRatio > 2) {
  17087. wRatio = wRatio < 0.5 ? 0.5 : 2;
  17088. scaleCapped = true;
  17089. }
  17090. if (hRatio < 0.5 || hRatio > 2) {
  17091. hRatio = hRatio < 0.5 ? 0.5 : 2;
  17092. scaleCapped = true;
  17093. }
  17094. var scaled = _scale(image, wRatio, hRatio);
  17095. return !scaleCapped ? scaled : scaled.then(function(tCanvas) {
  17096. return scale(tCanvas, dW, dH);
  17097. });
  17098. };
  17099. var _scale = function(image, wRatio, hRatio) {
  17100. return new Promise$1(function(resolve) {
  17101. var sW = getWidth$1(image);
  17102. var sH = getHeight$1(image);
  17103. var dW = Math.floor(sW * wRatio);
  17104. var dH = Math.floor(sH * hRatio);
  17105. var canvas = create$4(dW, dH);
  17106. var context = get2dContext(canvas);
  17107. context.drawImage(image, 0, 0, sW, sH, 0, 0, dW, dH);
  17108. resolve(canvas);
  17109. });
  17110. };
  17111. var ceilWithPrecision = function(num, precision) {
  17112. if (precision === void 0) {
  17113. precision = 2;
  17114. }
  17115. var mul = Math.pow(10, precision);
  17116. var upper = Math.round(num * mul);
  17117. return Math.ceil(upper / mul);
  17118. };
  17119. var rotate$1 = function(ir, angle) {
  17120. return ir.toCanvas().then(function(canvas) {
  17121. return applyRotate(canvas, ir.getType(), angle);
  17122. });
  17123. };
  17124. var applyRotate = function(image, type2, angle) {
  17125. var degrees = angle < 0 ? 360 + angle : angle;
  17126. var rad = degrees * Math.PI / 180;
  17127. var width2 = image.width;
  17128. var height2 = image.height;
  17129. var sin = Math.sin(rad);
  17130. var cos = Math.cos(rad);
  17131. var newWidth = ceilWithPrecision(Math.abs(width2 * cos) + Math.abs(height2 * sin));
  17132. var newHeight = ceilWithPrecision(Math.abs(width2 * sin) + Math.abs(height2 * cos));
  17133. var canvas = create$4(newWidth, newHeight);
  17134. var context = get2dContext(canvas);
  17135. context.translate(newWidth / 2, newHeight / 2);
  17136. context.rotate(rad);
  17137. context.drawImage(image, -width2 / 2, -height2 / 2);
  17138. return fromCanvas(canvas, type2);
  17139. };
  17140. var flip$1 = function(ir, axis) {
  17141. return ir.toCanvas().then(function(canvas) {
  17142. return applyFlip(canvas, ir.getType(), axis);
  17143. });
  17144. };
  17145. var applyFlip = function(image, type2, axis) {
  17146. var canvas = create$4(image.width, image.height);
  17147. var context = get2dContext(canvas);
  17148. if (axis === "v") {
  17149. context.scale(1, -1);
  17150. context.drawImage(image, 0, -canvas.height);
  17151. } else {
  17152. context.scale(-1, 1);
  17153. context.drawImage(image, -canvas.width, 0);
  17154. }
  17155. return fromCanvas(canvas, type2);
  17156. };
  17157. var crop$1 = function(ir, x, y, w, h) {
  17158. return ir.toCanvas().then(function(canvas) {
  17159. return applyCrop(canvas, ir.getType(), x, y, w, h);
  17160. });
  17161. };
  17162. var applyCrop = function(image, type2, x, y, w, h) {
  17163. var canvas = create$4(w, h);
  17164. var context = get2dContext(canvas);
  17165. context.drawImage(image, -x, -y);
  17166. return fromCanvas(canvas, type2);
  17167. };
  17168. var resize$2 = function(ir, w, h) {
  17169. return ir.toCanvas().then(function(canvas) {
  17170. return scale(canvas, w, h).then(function(newCanvas) {
  17171. return fromCanvas(newCanvas, ir.getType());
  17172. });
  17173. });
  17174. };
  17175. var invert = function(ir) {
  17176. return invert$1(ir);
  17177. };
  17178. var sharpen = function(ir) {
  17179. return sharpen$1(ir);
  17180. };
  17181. var gamma = function(ir, value2) {
  17182. return gamma$1(ir, value2);
  17183. };
  17184. var colorize = function(ir, adjustR, adjustG, adjustB) {
  17185. return colorize$1(ir, adjustR, adjustG, adjustB);
  17186. };
  17187. var brightness = function(ir, adjust) {
  17188. return brightness$1(ir, adjust);
  17189. };
  17190. var contrast = function(ir, adjust) {
  17191. return contrast$1(ir, adjust);
  17192. };
  17193. var flip = function(ir, axis) {
  17194. return flip$1(ir, axis);
  17195. };
  17196. var crop = function(ir, x, y, w, h) {
  17197. return crop$1(ir, x, y, w, h);
  17198. };
  17199. var resize$1 = function(ir, w, h) {
  17200. return resize$2(ir, w, h);
  17201. };
  17202. var rotate = function(ir, angle) {
  17203. return rotate$1(ir, angle);
  17204. };
  17205. var renderIcon = function(iconName, iconsProvider, behaviours2) {
  17206. return render$3(iconName, {
  17207. tag: "span",
  17208. classes: [
  17209. "tox-icon",
  17210. "tox-tbtn__icon-wrap"
  17211. ],
  17212. behaviours: behaviours2
  17213. }, iconsProvider);
  17214. };
  17215. var renderIconFromPack = function(iconName, iconsProvider) {
  17216. return renderIcon(iconName, iconsProvider, []);
  17217. };
  17218. var renderReplacableIconFromPack = function(iconName, iconsProvider) {
  17219. return renderIcon(iconName, iconsProvider, [Replacing.config({})]);
  17220. };
  17221. var renderLabel$1 = function(text2, prefix2, providersBackstage) {
  17222. return {
  17223. dom: {
  17224. tag: "span",
  17225. innerHtml: providersBackstage.translate(text2),
  17226. classes: [prefix2 + "__select-label"]
  17227. },
  17228. behaviours: derive$1([Replacing.config({})])
  17229. };
  17230. };
  17231. var _a;
  17232. var internalToolbarButtonExecute = generate$6("toolbar.button.execute");
  17233. var onToolbarButtonExecute = function(info) {
  17234. return runOnExecute$1(function(comp, _simulatedEvent) {
  17235. runWithApi(info, comp)(function(itemApi) {
  17236. emitWith(comp, internalToolbarButtonExecute, { buttonApi: itemApi });
  17237. info.onAction(itemApi);
  17238. });
  17239. });
  17240. };
  17241. var toolbarButtonEventOrder = (_a = {}, _a[execute$5()] = [
  17242. "disabling",
  17243. "alloy.base.behaviour",
  17244. "toggling",
  17245. "toolbar-button-events"
  17246. ], _a);
  17247. var updateMenuText = generate$6("update-menu-text");
  17248. var updateMenuIcon = generate$6("update-menu-icon");
  17249. var renderCommonDropdown = function(spec, prefix2, sharedBackstage) {
  17250. var editorOffCell = Cell(noop);
  17251. var optMemDisplayText = spec.text.map(function(text2) {
  17252. return record(renderLabel$1(text2, prefix2, sharedBackstage.providers));
  17253. });
  17254. var optMemDisplayIcon = spec.icon.map(function(iconName) {
  17255. return record(renderReplacableIconFromPack(iconName, sharedBackstage.providers.icons));
  17256. });
  17257. var onLeftOrRightInMenu = function(comp, se) {
  17258. var dropdown = Representing.getValue(comp);
  17259. Focusing.focus(dropdown);
  17260. emitWith(dropdown, "keydown", { raw: se.event.raw });
  17261. Dropdown.close(dropdown);
  17262. return Optional.some(true);
  17263. };
  17264. var role = spec.role.fold(function() {
  17265. return {};
  17266. }, function(role2) {
  17267. return { role: role2 };
  17268. });
  17269. var tooltipAttributes = spec.tooltip.fold(function() {
  17270. return {};
  17271. }, function(tooltip) {
  17272. var translatedTooltip = sharedBackstage.providers.translate(tooltip);
  17273. return {
  17274. "title": translatedTooltip,
  17275. "aria-label": translatedTooltip
  17276. };
  17277. });
  17278. var iconSpec = render$3("chevron-down", {
  17279. tag: "div",
  17280. classes: [prefix2 + "__select-chevron"]
  17281. }, sharedBackstage.providers.icons);
  17282. var memDropdown = record(Dropdown.sketch(__assign(__assign(__assign({}, spec.uid ? { uid: spec.uid } : {}), role), {
  17283. dom: {
  17284. tag: "button",
  17285. classes: [
  17286. prefix2,
  17287. prefix2 + "--select"
  17288. ].concat(map$2(spec.classes, function(c) {
  17289. return prefix2 + "--" + c;
  17290. })),
  17291. attributes: __assign({}, tooltipAttributes)
  17292. },
  17293. components: componentRenderPipeline([
  17294. optMemDisplayIcon.map(function(mem) {
  17295. return mem.asSpec();
  17296. }),
  17297. optMemDisplayText.map(function(mem) {
  17298. return mem.asSpec();
  17299. }),
  17300. Optional.some(iconSpec)
  17301. ]),
  17302. matchWidth: true,
  17303. useMinWidth: true,
  17304. dropdownBehaviours: derive$1(__spreadArray(__spreadArray([], spec.dropdownBehaviours, true), [
  17305. DisablingConfigs.button(function() {
  17306. return spec.disabled || sharedBackstage.providers.isDisabled();
  17307. }),
  17308. receivingConfig(),
  17309. Unselecting.config({}),
  17310. Replacing.config({}),
  17311. config("dropdown-events", [
  17312. onControlAttached(spec, editorOffCell),
  17313. onControlDetached(spec, editorOffCell)
  17314. ]),
  17315. config("menubutton-update-display-text", [
  17316. run$1(updateMenuText, function(comp, se) {
  17317. optMemDisplayText.bind(function(mem) {
  17318. return mem.getOpt(comp);
  17319. }).each(function(displayText) {
  17320. Replacing.set(displayText, [text$1(sharedBackstage.providers.translate(se.event.text))]);
  17321. });
  17322. }),
  17323. run$1(updateMenuIcon, function(comp, se) {
  17324. optMemDisplayIcon.bind(function(mem) {
  17325. return mem.getOpt(comp);
  17326. }).each(function(displayIcon) {
  17327. Replacing.set(displayIcon, [renderReplacableIconFromPack(se.event.icon, sharedBackstage.providers.icons)]);
  17328. });
  17329. })
  17330. ])
  17331. ], false)),
  17332. eventOrder: deepMerge(toolbarButtonEventOrder, {
  17333. mousedown: [
  17334. "focusing",
  17335. "alloy.base.behaviour",
  17336. "item-type-events",
  17337. "normal-dropdown-events"
  17338. ]
  17339. }),
  17340. sandboxBehaviours: derive$1([Keying.config({
  17341. mode: "special",
  17342. onLeft: onLeftOrRightInMenu,
  17343. onRight: onLeftOrRightInMenu
  17344. })]),
  17345. lazySink: sharedBackstage.getSink,
  17346. toggleClass: prefix2 + "--active",
  17347. parts: { menu: part(false, spec.columns, spec.presets) },
  17348. fetch: function(comp) {
  17349. return Future.nu(curry(spec.fetch, comp));
  17350. }
  17351. })));
  17352. return memDropdown.asSpec();
  17353. };
  17354. var isMenuItemReference = function(item2) {
  17355. return isString(item2);
  17356. };
  17357. var isSeparator$1 = function(item2) {
  17358. return item2.type === "separator";
  17359. };
  17360. var isExpandingMenuItem = function(item2) {
  17361. return has$2(item2, "getSubmenuItems");
  17362. };
  17363. var separator$2 = { type: "separator" };
  17364. var unwrapReferences = function(items, menuItems) {
  17365. var realItems = foldl(items, function(acc, item2) {
  17366. if (isMenuItemReference(item2)) {
  17367. if (item2 === "") {
  17368. return acc;
  17369. } else if (item2 === "|") {
  17370. return acc.length > 0 && !isSeparator$1(acc[acc.length - 1]) ? acc.concat([separator$2]) : acc;
  17371. } else if (has$2(menuItems, item2.toLowerCase())) {
  17372. return acc.concat([menuItems[item2.toLowerCase()]]);
  17373. } else {
  17374. return acc;
  17375. }
  17376. } else {
  17377. return acc.concat([item2]);
  17378. }
  17379. }, []);
  17380. if (realItems.length > 0 && isSeparator$1(realItems[realItems.length - 1])) {
  17381. realItems.pop();
  17382. }
  17383. return realItems;
  17384. };
  17385. var getFromExpandingItem = function(item2, menuItems) {
  17386. var submenuItems = item2.getSubmenuItems();
  17387. var rest = expand(submenuItems, menuItems);
  17388. var newMenus = deepMerge(rest.menus, wrap$1(item2.value, rest.items));
  17389. var newExpansions = deepMerge(rest.expansions, wrap$1(item2.value, item2.value));
  17390. return {
  17391. item: item2,
  17392. menus: newMenus,
  17393. expansions: newExpansions
  17394. };
  17395. };
  17396. var getFromItem = function(item2, menuItems) {
  17397. return isExpandingMenuItem(item2) ? getFromExpandingItem(item2, menuItems) : {
  17398. item: item2,
  17399. menus: {},
  17400. expansions: {}
  17401. };
  17402. };
  17403. var generateValueIfRequired = function(item2) {
  17404. if (isSeparator$1(item2)) {
  17405. return item2;
  17406. } else {
  17407. var itemValue = get$e(item2, "value").getOrThunk(function() {
  17408. return generate$6("generated-menu-item");
  17409. });
  17410. return deepMerge({ value: itemValue }, item2);
  17411. }
  17412. };
  17413. var expand = function(items, menuItems) {
  17414. var realItems = unwrapReferences(isString(items) ? items.split(" ") : items, menuItems);
  17415. return foldr(realItems, function(acc, item2) {
  17416. var itemWithValue = generateValueIfRequired(item2);
  17417. var newData = getFromItem(itemWithValue, menuItems);
  17418. return {
  17419. menus: deepMerge(acc.menus, newData.menus),
  17420. items: [newData.item].concat(acc.items),
  17421. expansions: deepMerge(acc.expansions, newData.expansions)
  17422. };
  17423. }, {
  17424. menus: {},
  17425. expansions: {},
  17426. items: []
  17427. });
  17428. };
  17429. var build = function(items, itemResponse, backstage, isHorizontalMenu) {
  17430. var primary = generate$6("primary-menu");
  17431. var data = expand(items, backstage.shared.providers.menuItems());
  17432. if (data.items.length === 0) {
  17433. return Optional.none();
  17434. }
  17435. var mainMenu = createPartialMenu(primary, data.items, itemResponse, backstage, isHorizontalMenu);
  17436. var submenus = map$1(data.menus, function(menuItems, menuName) {
  17437. return createPartialMenu(menuName, menuItems, itemResponse, backstage, false);
  17438. });
  17439. var menus = deepMerge(submenus, wrap$1(primary, mainMenu));
  17440. return Optional.from(tieredMenu.tieredData(primary, menus, data.expansions));
  17441. };
  17442. var getMenuButtonApi = function(component) {
  17443. return {
  17444. isDisabled: function() {
  17445. return Disabling.isDisabled(component);
  17446. },
  17447. setDisabled: function(state) {
  17448. return Disabling.set(component, state);
  17449. },
  17450. setActive: function(state) {
  17451. var elm = component.element;
  17452. if (state) {
  17453. add$2(elm, "tox-tbtn--enabled");
  17454. set$8(elm, "aria-pressed", true);
  17455. } else {
  17456. remove$2(elm, "tox-tbtn--enabled");
  17457. remove$7(elm, "aria-pressed");
  17458. }
  17459. },
  17460. isActive: function() {
  17461. return has(component.element, "tox-tbtn--enabled");
  17462. }
  17463. };
  17464. };
  17465. var renderMenuButton = function(spec, prefix2, backstage, role) {
  17466. return renderCommonDropdown({
  17467. text: spec.text,
  17468. icon: spec.icon,
  17469. tooltip: spec.tooltip,
  17470. role,
  17471. fetch: function(_comp, callback) {
  17472. spec.fetch(function(items) {
  17473. callback(build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false));
  17474. });
  17475. },
  17476. onSetup: spec.onSetup,
  17477. getApi: getMenuButtonApi,
  17478. columns: 1,
  17479. presets: "normal",
  17480. classes: [],
  17481. dropdownBehaviours: [Tabstopping.config({})]
  17482. }, prefix2, backstage.shared);
  17483. };
  17484. var getFetch = function(items, getButton, backstage) {
  17485. var getMenuItemAction = function(item2) {
  17486. return function(api2) {
  17487. var newValue = !api2.isActive();
  17488. api2.setActive(newValue);
  17489. item2.storage.set(newValue);
  17490. backstage.shared.getSink().each(function(sink) {
  17491. getButton().getOpt(sink).each(function(orig) {
  17492. focus$3(orig.element);
  17493. emitWith(orig, formActionEvent, {
  17494. name: item2.name,
  17495. value: item2.storage.get()
  17496. });
  17497. });
  17498. });
  17499. };
  17500. };
  17501. var getMenuItemSetup = function(item2) {
  17502. return function(api2) {
  17503. api2.setActive(item2.storage.get());
  17504. };
  17505. };
  17506. return function(success) {
  17507. success(map$2(items, function(item2) {
  17508. var text2 = item2.text.fold(function() {
  17509. return {};
  17510. }, function(text3) {
  17511. return { text: text3 };
  17512. });
  17513. return __assign(__assign({
  17514. type: item2.type,
  17515. active: false
  17516. }, text2), {
  17517. onAction: getMenuItemAction(item2),
  17518. onSetup: getMenuItemSetup(item2)
  17519. });
  17520. }));
  17521. };
  17522. };
  17523. var renderCommonSpec = function(spec, actionOpt, extraBehaviours, dom2, components2, providersBackstage) {
  17524. if (extraBehaviours === void 0) {
  17525. extraBehaviours = [];
  17526. }
  17527. var action = actionOpt.fold(function() {
  17528. return {};
  17529. }, function(action2) {
  17530. return { action: action2 };
  17531. });
  17532. var common = __assign({
  17533. buttonBehaviours: derive$1([
  17534. DisablingConfigs.button(function() {
  17535. return spec.disabled || providersBackstage.isDisabled();
  17536. }),
  17537. receivingConfig(),
  17538. Tabstopping.config({}),
  17539. config("button press", [
  17540. preventDefault("click"),
  17541. preventDefault("mousedown")
  17542. ])
  17543. ].concat(extraBehaviours)),
  17544. eventOrder: {
  17545. click: [
  17546. "button press",
  17547. "alloy.base.behaviour"
  17548. ],
  17549. mousedown: [
  17550. "button press",
  17551. "alloy.base.behaviour"
  17552. ]
  17553. }
  17554. }, action);
  17555. var domFinal = deepMerge(common, { dom: dom2 });
  17556. return deepMerge(domFinal, { components: components2 });
  17557. };
  17558. var renderIconButtonSpec = function(spec, action, providersBackstage, extraBehaviours) {
  17559. if (extraBehaviours === void 0) {
  17560. extraBehaviours = [];
  17561. }
  17562. var tooltipAttributes = spec.tooltip.map(function(tooltip) {
  17563. return {
  17564. "aria-label": providersBackstage.translate(tooltip),
  17565. "title": providersBackstage.translate(tooltip)
  17566. };
  17567. }).getOr({});
  17568. var dom2 = {
  17569. tag: "button",
  17570. classes: ["tox-tbtn"],
  17571. attributes: tooltipAttributes
  17572. };
  17573. var icon = spec.icon.map(function(iconName) {
  17574. return renderIconFromPack(iconName, providersBackstage.icons);
  17575. });
  17576. var components2 = componentRenderPipeline([icon]);
  17577. return renderCommonSpec(spec, action, extraBehaviours, dom2, components2, providersBackstage);
  17578. };
  17579. var renderIconButton = function(spec, action, providersBackstage, extraBehaviours) {
  17580. if (extraBehaviours === void 0) {
  17581. extraBehaviours = [];
  17582. }
  17583. var iconButtonSpec = renderIconButtonSpec(spec, Optional.some(action), providersBackstage, extraBehaviours);
  17584. return Button.sketch(iconButtonSpec);
  17585. };
  17586. var renderButtonSpec = function(spec, action, providersBackstage, extraBehaviours, extraClasses) {
  17587. if (extraBehaviours === void 0) {
  17588. extraBehaviours = [];
  17589. }
  17590. if (extraClasses === void 0) {
  17591. extraClasses = [];
  17592. }
  17593. var translatedText = providersBackstage.translate(spec.text);
  17594. var icon = spec.icon ? spec.icon.map(function(iconName) {
  17595. return renderIconFromPack(iconName, providersBackstage.icons);
  17596. }) : Optional.none();
  17597. var components2 = icon.isSome() ? componentRenderPipeline([icon]) : [];
  17598. var innerHtml = icon.isSome() ? {} : { innerHtml: translatedText };
  17599. var classes2 = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], !spec.primary && !spec.borderless ? [
  17600. "tox-button",
  17601. "tox-button--secondary"
  17602. ] : ["tox-button"], true), icon.isSome() ? ["tox-button--icon"] : [], true), spec.borderless ? ["tox-button--naked"] : [], true), extraClasses, true);
  17603. var dom2 = __assign(__assign({
  17604. tag: "button",
  17605. classes: classes2
  17606. }, innerHtml), { attributes: { title: translatedText } });
  17607. return renderCommonSpec(spec, action, extraBehaviours, dom2, components2, providersBackstage);
  17608. };
  17609. var renderButton = function(spec, action, providersBackstage, extraBehaviours, extraClasses) {
  17610. if (extraBehaviours === void 0) {
  17611. extraBehaviours = [];
  17612. }
  17613. if (extraClasses === void 0) {
  17614. extraClasses = [];
  17615. }
  17616. var buttonSpec = renderButtonSpec(spec, Optional.some(action), providersBackstage, extraBehaviours, extraClasses);
  17617. return Button.sketch(buttonSpec);
  17618. };
  17619. var getAction = function(name2, buttonType) {
  17620. return function(comp) {
  17621. if (buttonType === "custom") {
  17622. emitWith(comp, formActionEvent, {
  17623. name: name2,
  17624. value: {}
  17625. });
  17626. } else if (buttonType === "submit") {
  17627. emit(comp, formSubmitEvent);
  17628. } else if (buttonType === "cancel") {
  17629. emit(comp, formCancelEvent);
  17630. } else {
  17631. console.error("Unknown button type: ", buttonType);
  17632. }
  17633. };
  17634. };
  17635. var isMenuFooterButtonSpec = function(spec, buttonType) {
  17636. return buttonType === "menu";
  17637. };
  17638. var isNormalFooterButtonSpec = function(spec, buttonType) {
  17639. return buttonType === "custom" || buttonType === "cancel" || buttonType === "submit";
  17640. };
  17641. var renderFooterButton = function(spec, buttonType, backstage) {
  17642. if (isMenuFooterButtonSpec(spec, buttonType)) {
  17643. var getButton = function() {
  17644. return memButton_1;
  17645. };
  17646. var menuButtonSpec = spec;
  17647. var fixedSpec = __assign(__assign({}, spec), {
  17648. onSetup: function(api2) {
  17649. api2.setDisabled(spec.disabled);
  17650. return noop;
  17651. },
  17652. fetch: getFetch(menuButtonSpec.items, getButton, backstage)
  17653. });
  17654. var memButton_1 = record(renderMenuButton(fixedSpec, "tox-tbtn", backstage, Optional.none()));
  17655. return memButton_1.asSpec();
  17656. } else if (isNormalFooterButtonSpec(spec, buttonType)) {
  17657. var action = getAction(spec.name, buttonType);
  17658. var buttonSpec = __assign(__assign({}, spec), { borderless: false });
  17659. return renderButton(buttonSpec, action, backstage.shared.providers, []);
  17660. } else {
  17661. console.error("Unknown footer button type: ", buttonType);
  17662. }
  17663. };
  17664. var renderDialogButton = function(spec, providersBackstage) {
  17665. var action = getAction(spec.name, "custom");
  17666. return renderFormField(Optional.none(), FormField.parts.field(__assign({ factory: Button }, renderButtonSpec(spec, Optional.some(action), providersBackstage, [
  17667. RepresentingConfigs.memory(""),
  17668. ComposingConfigs.self()
  17669. ]))));
  17670. };
  17671. var schema$h = constant$1([
  17672. defaulted("field1Name", "field1"),
  17673. defaulted("field2Name", "field2"),
  17674. onStrictHandler("onLockedChange"),
  17675. markers$1(["lockClass"]),
  17676. defaulted("locked", false),
  17677. SketchBehaviours.field("coupledFieldBehaviours", [
  17678. Composing,
  17679. Representing
  17680. ])
  17681. ]);
  17682. var getField = function(comp, detail, partName) {
  17683. return getPart(comp, detail, partName).bind(Composing.getCurrent);
  17684. };
  17685. var coupledPart = function(selfName, otherName) {
  17686. return required({
  17687. factory: FormField,
  17688. name: selfName,
  17689. overrides: function(detail) {
  17690. return {
  17691. fieldBehaviours: derive$1([config("coupled-input-behaviour", [run$1(input(), function(me) {
  17692. getField(me, detail, otherName).each(function(other) {
  17693. getPart(me, detail, "lock").each(function(lock) {
  17694. if (Toggling.isOn(lock)) {
  17695. detail.onLockedChange(me, other, lock);
  17696. }
  17697. });
  17698. });
  17699. })])])
  17700. };
  17701. }
  17702. });
  17703. };
  17704. var parts$c = constant$1([
  17705. coupledPart("field1", "field2"),
  17706. coupledPart("field2", "field1"),
  17707. required({
  17708. factory: Button,
  17709. schema: [required$1("dom")],
  17710. name: "lock",
  17711. overrides: function(detail) {
  17712. return {
  17713. buttonBehaviours: derive$1([Toggling.config({
  17714. selected: detail.locked,
  17715. toggleClass: detail.markers.lockClass,
  17716. aria: { mode: "pressed" }
  17717. })])
  17718. };
  17719. }
  17720. })
  17721. ]);
  17722. var factory$f = function(detail, components2, _spec, _externals) {
  17723. return {
  17724. uid: detail.uid,
  17725. dom: detail.dom,
  17726. components: components2,
  17727. behaviours: SketchBehaviours.augment(detail.coupledFieldBehaviours, [
  17728. Composing.config({ find: Optional.some }),
  17729. Representing.config({
  17730. store: {
  17731. mode: "manual",
  17732. getValue: function(comp) {
  17733. var _a2;
  17734. var parts2 = getPartsOrDie(comp, detail, [
  17735. "field1",
  17736. "field2"
  17737. ]);
  17738. return _a2 = {}, _a2[detail.field1Name] = Representing.getValue(parts2.field1()), _a2[detail.field2Name] = Representing.getValue(parts2.field2()), _a2;
  17739. },
  17740. setValue: function(comp, value2) {
  17741. var parts2 = getPartsOrDie(comp, detail, [
  17742. "field1",
  17743. "field2"
  17744. ]);
  17745. if (hasNonNullableKey(value2, detail.field1Name)) {
  17746. Representing.setValue(parts2.field1(), value2[detail.field1Name]);
  17747. }
  17748. if (hasNonNullableKey(value2, detail.field2Name)) {
  17749. Representing.setValue(parts2.field2(), value2[detail.field2Name]);
  17750. }
  17751. }
  17752. }
  17753. })
  17754. ]),
  17755. apis: {
  17756. getField1: function(component) {
  17757. return getPart(component, detail, "field1");
  17758. },
  17759. getField2: function(component) {
  17760. return getPart(component, detail, "field2");
  17761. },
  17762. getLock: function(component) {
  17763. return getPart(component, detail, "lock");
  17764. }
  17765. }
  17766. };
  17767. };
  17768. var FormCoupledInputs = composite({
  17769. name: "FormCoupledInputs",
  17770. configFields: schema$h(),
  17771. partFields: parts$c(),
  17772. factory: factory$f,
  17773. apis: {
  17774. getField1: function(apis, component) {
  17775. return apis.getField1(component);
  17776. },
  17777. getField2: function(apis, component) {
  17778. return apis.getField2(component);
  17779. },
  17780. getLock: function(apis, component) {
  17781. return apis.getLock(component);
  17782. }
  17783. }
  17784. });
  17785. var formatSize = function(size) {
  17786. var unitDec = {
  17787. "": 0,
  17788. "px": 0,
  17789. "pt": 1,
  17790. "mm": 1,
  17791. "pc": 2,
  17792. "ex": 2,
  17793. "em": 2,
  17794. "ch": 2,
  17795. "rem": 2,
  17796. "cm": 3,
  17797. "in": 4,
  17798. "%": 4
  17799. };
  17800. var maxDecimal = function(unit) {
  17801. return unit in unitDec ? unitDec[unit] : 1;
  17802. };
  17803. var numText = size.value.toFixed(maxDecimal(size.unit));
  17804. if (numText.indexOf(".") !== -1) {
  17805. numText = numText.replace(/\.?0*$/, "");
  17806. }
  17807. return numText + size.unit;
  17808. };
  17809. var parseSize = function(sizeText) {
  17810. var numPattern = /^\s*(\d+(?:\.\d+)?)\s*(|cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)\s*$/;
  17811. var match = numPattern.exec(sizeText);
  17812. if (match !== null) {
  17813. var value2 = parseFloat(match[1]);
  17814. var unit = match[2];
  17815. return Result.value({
  17816. value: value2,
  17817. unit
  17818. });
  17819. } else {
  17820. return Result.error(sizeText);
  17821. }
  17822. };
  17823. var convertUnit = function(size, unit) {
  17824. var inInch = {
  17825. "": 96,
  17826. "px": 96,
  17827. "pt": 72,
  17828. "cm": 2.54,
  17829. "pc": 12,
  17830. "mm": 25.4,
  17831. "in": 1
  17832. };
  17833. var supported2 = function(u) {
  17834. return has$2(inInch, u);
  17835. };
  17836. if (size.unit === unit) {
  17837. return Optional.some(size.value);
  17838. } else if (supported2(size.unit) && supported2(unit)) {
  17839. if (inInch[size.unit] === inInch[unit]) {
  17840. return Optional.some(size.value);
  17841. } else {
  17842. return Optional.some(size.value / inInch[size.unit] * inInch[unit]);
  17843. }
  17844. } else {
  17845. return Optional.none();
  17846. }
  17847. };
  17848. var noSizeConversion = function(_input) {
  17849. return Optional.none();
  17850. };
  17851. var ratioSizeConversion = function(scale2, unit) {
  17852. return function(size) {
  17853. return convertUnit(size, unit).map(function(value2) {
  17854. return {
  17855. value: value2 * scale2,
  17856. unit
  17857. };
  17858. });
  17859. };
  17860. };
  17861. var makeRatioConverter = function(currentFieldText, otherFieldText) {
  17862. var cValue = parseSize(currentFieldText).toOptional();
  17863. var oValue = parseSize(otherFieldText).toOptional();
  17864. return lift2(cValue, oValue, function(cSize, oSize) {
  17865. return convertUnit(cSize, oSize.unit).map(function(val) {
  17866. return oSize.value / val;
  17867. }).map(function(r2) {
  17868. return ratioSizeConversion(r2, oSize.unit);
  17869. }).getOr(noSizeConversion);
  17870. }).getOr(noSizeConversion);
  17871. };
  17872. var renderSizeInput = function(spec, providersBackstage) {
  17873. var converter = noSizeConversion;
  17874. var ratioEvent = generate$6("ratio-event");
  17875. var makeIcon = function(iconName) {
  17876. return render$3(iconName, {
  17877. tag: "span",
  17878. classes: [
  17879. "tox-icon",
  17880. "tox-lock-icon__" + iconName
  17881. ]
  17882. }, providersBackstage.icons);
  17883. };
  17884. var pLock = FormCoupledInputs.parts.lock({
  17885. dom: {
  17886. tag: "button",
  17887. classes: [
  17888. "tox-lock",
  17889. "tox-button",
  17890. "tox-button--naked",
  17891. "tox-button--icon"
  17892. ],
  17893. attributes: { title: providersBackstage.translate(spec.label.getOr("Constrain proportions")) }
  17894. },
  17895. components: [
  17896. makeIcon("lock"),
  17897. makeIcon("unlock")
  17898. ],
  17899. buttonBehaviours: derive$1([
  17900. Disabling.config({
  17901. disabled: function() {
  17902. return spec.disabled || providersBackstage.isDisabled();
  17903. }
  17904. }),
  17905. receivingConfig(),
  17906. Tabstopping.config({})
  17907. ])
  17908. });
  17909. var formGroup = function(components2) {
  17910. return {
  17911. dom: {
  17912. tag: "div",
  17913. classes: ["tox-form__group"]
  17914. },
  17915. components: components2
  17916. };
  17917. };
  17918. var getFieldPart = function(isField1) {
  17919. return FormField.parts.field({
  17920. factory: Input,
  17921. inputClasses: ["tox-textfield"],
  17922. inputBehaviours: derive$1([
  17923. Disabling.config({
  17924. disabled: function() {
  17925. return spec.disabled || providersBackstage.isDisabled();
  17926. }
  17927. }),
  17928. receivingConfig(),
  17929. Tabstopping.config({}),
  17930. config("size-input-events", [
  17931. run$1(focusin(), function(component, _simulatedEvent) {
  17932. emitWith(component, ratioEvent, { isField1 });
  17933. }),
  17934. run$1(change(), function(component, _simulatedEvent) {
  17935. emitWith(component, formChangeEvent, { name: spec.name });
  17936. })
  17937. ])
  17938. ]),
  17939. selectOnFocus: false
  17940. });
  17941. };
  17942. var getLabel = function(label) {
  17943. return {
  17944. dom: {
  17945. tag: "label",
  17946. classes: ["tox-label"],
  17947. innerHtml: providersBackstage.translate(label)
  17948. }
  17949. };
  17950. };
  17951. var widthField = FormCoupledInputs.parts.field1(formGroup([
  17952. FormField.parts.label(getLabel("Width")),
  17953. getFieldPart(true)
  17954. ]));
  17955. var heightField = FormCoupledInputs.parts.field2(formGroup([
  17956. FormField.parts.label(getLabel("Height")),
  17957. getFieldPart(false)
  17958. ]));
  17959. return FormCoupledInputs.sketch({
  17960. dom: {
  17961. tag: "div",
  17962. classes: ["tox-form__group"]
  17963. },
  17964. components: [{
  17965. dom: {
  17966. tag: "div",
  17967. classes: ["tox-form__controls-h-stack"]
  17968. },
  17969. components: [
  17970. widthField,
  17971. heightField,
  17972. formGroup([
  17973. getLabel("&nbsp;"),
  17974. pLock
  17975. ])
  17976. ]
  17977. }],
  17978. field1Name: "width",
  17979. field2Name: "height",
  17980. locked: true,
  17981. markers: { lockClass: "tox-locked" },
  17982. onLockedChange: function(current, other, _lock) {
  17983. parseSize(Representing.getValue(current)).each(function(size) {
  17984. converter(size).each(function(newSize) {
  17985. Representing.setValue(other, formatSize(newSize));
  17986. });
  17987. });
  17988. },
  17989. coupledFieldBehaviours: derive$1([
  17990. Disabling.config({
  17991. disabled: function() {
  17992. return spec.disabled || providersBackstage.isDisabled();
  17993. },
  17994. onDisabled: function(comp) {
  17995. FormCoupledInputs.getField1(comp).bind(FormField.getField).each(Disabling.disable);
  17996. FormCoupledInputs.getField2(comp).bind(FormField.getField).each(Disabling.disable);
  17997. FormCoupledInputs.getLock(comp).each(Disabling.disable);
  17998. },
  17999. onEnabled: function(comp) {
  18000. FormCoupledInputs.getField1(comp).bind(FormField.getField).each(Disabling.enable);
  18001. FormCoupledInputs.getField2(comp).bind(FormField.getField).each(Disabling.enable);
  18002. FormCoupledInputs.getLock(comp).each(Disabling.enable);
  18003. }
  18004. }),
  18005. receivingConfig(),
  18006. config("size-input-events2", [run$1(ratioEvent, function(component, simulatedEvent) {
  18007. var isField1 = simulatedEvent.event.isField1;
  18008. var optCurrent = isField1 ? FormCoupledInputs.getField1(component) : FormCoupledInputs.getField2(component);
  18009. var optOther = isField1 ? FormCoupledInputs.getField2(component) : FormCoupledInputs.getField1(component);
  18010. var value1 = optCurrent.map(Representing.getValue).getOr("");
  18011. var value2 = optOther.map(Representing.getValue).getOr("");
  18012. converter = makeRatioConverter(value1, value2);
  18013. })])
  18014. ])
  18015. });
  18016. };
  18017. var undo = constant$1(generate$6("undo"));
  18018. var redo = constant$1(generate$6("redo"));
  18019. var zoom = constant$1(generate$6("zoom"));
  18020. var back = constant$1(generate$6("back"));
  18021. var apply$1 = constant$1(generate$6("apply"));
  18022. var swap = constant$1(generate$6("swap"));
  18023. var transform$1 = constant$1(generate$6("transform"));
  18024. var tempTransform = constant$1(generate$6("temp-transform"));
  18025. var transformApply = constant$1(generate$6("transform-apply"));
  18026. var internal = {
  18027. undo,
  18028. redo,
  18029. zoom,
  18030. back,
  18031. apply: apply$1,
  18032. swap,
  18033. transform: transform$1,
  18034. tempTransform,
  18035. transformApply
  18036. };
  18037. var saveState = constant$1("save-state");
  18038. var disable = constant$1("disable");
  18039. var enable = constant$1("enable");
  18040. var external = {
  18041. formActionEvent,
  18042. saveState,
  18043. disable,
  18044. enable
  18045. };
  18046. var renderEditPanel = function(imagePanel, providersBackstage) {
  18047. var createButton2 = function(text2, action, disabled, primary) {
  18048. return record(renderButton({
  18049. name: text2,
  18050. text: text2,
  18051. disabled,
  18052. primary,
  18053. icon: Optional.none(),
  18054. borderless: false
  18055. }, action, providersBackstage));
  18056. };
  18057. var createIconButton = function(icon, tooltip, action, disabled) {
  18058. return record(renderIconButton({
  18059. name: icon,
  18060. icon: Optional.some(icon),
  18061. tooltip: Optional.some(tooltip),
  18062. disabled,
  18063. primary: false,
  18064. borderless: false
  18065. }, action, providersBackstage));
  18066. };
  18067. var disableAllComponents = function(comps, eventcomp) {
  18068. comps.map(function(mem) {
  18069. var component = mem.get(eventcomp);
  18070. if (component.hasConfigured(Disabling)) {
  18071. Disabling.disable(component);
  18072. }
  18073. });
  18074. };
  18075. var enableAllComponents = function(comps, eventcomp) {
  18076. comps.map(function(mem) {
  18077. var component = mem.get(eventcomp);
  18078. if (component.hasConfigured(Disabling)) {
  18079. Disabling.enable(component);
  18080. }
  18081. });
  18082. };
  18083. var panelDom = {
  18084. tag: "div",
  18085. classes: [
  18086. "tox-image-tools__toolbar",
  18087. "tox-image-tools-edit-panel"
  18088. ]
  18089. };
  18090. var noop$1 = noop;
  18091. var emit$1 = function(comp, event, data) {
  18092. emitWith(comp, event, data);
  18093. };
  18094. var emitDisable = function(component) {
  18095. return emit(component, external.disable());
  18096. };
  18097. var emitEnable = function(component) {
  18098. return emit(component, external.enable());
  18099. };
  18100. var emitTransform = function(comp, transform2) {
  18101. emitDisable(comp);
  18102. emit$1(comp, internal.transform(), { transform: transform2 });
  18103. emitEnable(comp);
  18104. };
  18105. var emitTempTransform = function(comp, transform2) {
  18106. emitDisable(comp);
  18107. emit$1(comp, internal.tempTransform(), { transform: transform2 });
  18108. emitEnable(comp);
  18109. };
  18110. var getBackSwap = function(anyInSystem) {
  18111. return function() {
  18112. memContainer.getOpt(anyInSystem).each(function(container2) {
  18113. Replacing.set(container2, [ButtonPanel]);
  18114. });
  18115. };
  18116. };
  18117. var emitTransformApply = function(comp, transform2) {
  18118. emitDisable(comp);
  18119. emit$1(comp, internal.transformApply(), {
  18120. transform: transform2,
  18121. swap: getBackSwap(comp)
  18122. });
  18123. emitEnable(comp);
  18124. };
  18125. var createBackButton = function() {
  18126. return createButton2("Back", function(button2) {
  18127. return emit$1(button2, internal.back(), { swap: getBackSwap(button2) });
  18128. }, false, false);
  18129. };
  18130. var createSpacer = function() {
  18131. return record({
  18132. dom: {
  18133. tag: "div",
  18134. classes: ["tox-spacer"]
  18135. },
  18136. behaviours: derive$1([Disabling.config({})])
  18137. });
  18138. };
  18139. var createApplyButton = function() {
  18140. return createButton2("Apply", function(button2) {
  18141. return emit$1(button2, internal.apply(), { swap: getBackSwap(button2) });
  18142. }, true, true);
  18143. };
  18144. var makeCropTransform = function() {
  18145. return function(ir) {
  18146. var rect2 = imagePanel.getRect();
  18147. return crop(ir, rect2.x, rect2.y, rect2.w, rect2.h);
  18148. };
  18149. };
  18150. var cropPanelComponents = [
  18151. createBackButton(),
  18152. createSpacer(),
  18153. createButton2("Apply", function(button2) {
  18154. var transform2 = makeCropTransform();
  18155. emitTransformApply(button2, transform2);
  18156. imagePanel.hideCrop();
  18157. }, false, true)
  18158. ];
  18159. var CropPanel = Container.sketch({
  18160. dom: panelDom,
  18161. components: cropPanelComponents.map(function(mem) {
  18162. return mem.asSpec();
  18163. }),
  18164. containerBehaviours: derive$1([config("image-tools-crop-buttons-events", [
  18165. run$1(external.disable(), function(comp, _se) {
  18166. disableAllComponents(cropPanelComponents, comp);
  18167. }),
  18168. run$1(external.enable(), function(comp, _se) {
  18169. enableAllComponents(cropPanelComponents, comp);
  18170. })
  18171. ])])
  18172. });
  18173. var memSize = record(renderSizeInput({
  18174. name: "size",
  18175. label: Optional.none(),
  18176. constrain: true,
  18177. disabled: false
  18178. }, providersBackstage));
  18179. var makeResizeTransform = function(width2, height2) {
  18180. return function(ir) {
  18181. return resize$1(ir, width2, height2);
  18182. };
  18183. };
  18184. var resizePanelComponents = [
  18185. createBackButton(),
  18186. createSpacer(),
  18187. memSize,
  18188. createSpacer(),
  18189. createButton2("Apply", function(button2) {
  18190. memSize.getOpt(button2).each(function(sizeInput) {
  18191. var value2 = Representing.getValue(sizeInput);
  18192. var width2 = parseInt(value2.width, 10);
  18193. var height2 = parseInt(value2.height, 10);
  18194. var transform2 = makeResizeTransform(width2, height2);
  18195. emitTransformApply(button2, transform2);
  18196. });
  18197. }, false, true)
  18198. ];
  18199. var ResizePanel = Container.sketch({
  18200. dom: panelDom,
  18201. components: resizePanelComponents.map(function(mem) {
  18202. return mem.asSpec();
  18203. }),
  18204. containerBehaviours: derive$1([config("image-tools-resize-buttons-events", [
  18205. run$1(external.disable(), function(comp, _se) {
  18206. disableAllComponents(resizePanelComponents, comp);
  18207. }),
  18208. run$1(external.enable(), function(comp, _se) {
  18209. enableAllComponents(resizePanelComponents, comp);
  18210. })
  18211. ])])
  18212. });
  18213. var makeValueTransform = function(transform2, value2) {
  18214. return function(ir) {
  18215. return transform2(ir, value2);
  18216. };
  18217. };
  18218. var horizontalFlip = makeValueTransform(flip, "h");
  18219. var verticalFlip = makeValueTransform(flip, "v");
  18220. var counterclockwiseRotate = makeValueTransform(rotate, -90);
  18221. var clockwiseRotate = makeValueTransform(rotate, 90);
  18222. var flipRotateOnAction = function(comp, operation) {
  18223. emitTempTransform(comp, operation);
  18224. };
  18225. var flipRotateComponents = [
  18226. createBackButton(),
  18227. createSpacer(),
  18228. createIconButton("flip-horizontally", "Flip horizontally", function(button2) {
  18229. flipRotateOnAction(button2, horizontalFlip);
  18230. }, false),
  18231. createIconButton("flip-vertically", "Flip vertically", function(button2) {
  18232. flipRotateOnAction(button2, verticalFlip);
  18233. }, false),
  18234. createIconButton("rotate-left", "Rotate counterclockwise", function(button2) {
  18235. flipRotateOnAction(button2, counterclockwiseRotate);
  18236. }, false),
  18237. createIconButton("rotate-right", "Rotate clockwise", function(button2) {
  18238. flipRotateOnAction(button2, clockwiseRotate);
  18239. }, false),
  18240. createSpacer(),
  18241. createApplyButton()
  18242. ];
  18243. var FlipRotatePanel = Container.sketch({
  18244. dom: panelDom,
  18245. components: flipRotateComponents.map(function(mem) {
  18246. return mem.asSpec();
  18247. }),
  18248. containerBehaviours: derive$1([config("image-tools-fliprotate-buttons-events", [
  18249. run$1(external.disable(), function(comp, _se) {
  18250. disableAllComponents(flipRotateComponents, comp);
  18251. }),
  18252. run$1(external.enable(), function(comp, _se) {
  18253. enableAllComponents(flipRotateComponents, comp);
  18254. })
  18255. ])])
  18256. });
  18257. var makeSlider = function(label, onChoose, min2, value2, max2) {
  18258. var labelPart2 = Slider.parts.label({
  18259. dom: {
  18260. tag: "label",
  18261. classes: ["tox-label"],
  18262. innerHtml: providersBackstage.translate(label)
  18263. }
  18264. });
  18265. var spectrum = Slider.parts.spectrum({
  18266. dom: {
  18267. tag: "div",
  18268. classes: ["tox-slider__rail"],
  18269. attributes: { role: "presentation" }
  18270. }
  18271. });
  18272. var thumb = Slider.parts.thumb({
  18273. dom: {
  18274. tag: "div",
  18275. classes: ["tox-slider__handle"],
  18276. attributes: { role: "presentation" }
  18277. }
  18278. });
  18279. return record(Slider.sketch({
  18280. dom: {
  18281. tag: "div",
  18282. classes: ["tox-slider"],
  18283. attributes: { role: "presentation" }
  18284. },
  18285. model: {
  18286. mode: "x",
  18287. minX: min2,
  18288. maxX: max2,
  18289. getInitialValue: constant$1({ x: value2 })
  18290. },
  18291. components: [
  18292. labelPart2,
  18293. spectrum,
  18294. thumb
  18295. ],
  18296. sliderBehaviours: derive$1([Focusing.config({})]),
  18297. onChoose
  18298. }));
  18299. };
  18300. var makeVariableSlider = function(label, transform2, min2, value2, max2) {
  18301. var onChoose = function(slider, _thumb, value3) {
  18302. var valTransform = makeValueTransform(transform2, value3.x / 100);
  18303. emitTransform(slider, valTransform);
  18304. };
  18305. return makeSlider(label, onChoose, min2, value2, max2);
  18306. };
  18307. var variableFilterPanelComponents = function(label, transform2, min2, value2, max2) {
  18308. return [
  18309. createBackButton(),
  18310. makeVariableSlider(label, transform2, min2, value2, max2),
  18311. createApplyButton()
  18312. ];
  18313. };
  18314. var createVariableFilterPanel = function(label, transform2, min2, value2, max2) {
  18315. var filterPanelComponents2 = variableFilterPanelComponents(label, transform2, min2, value2, max2);
  18316. return Container.sketch({
  18317. dom: panelDom,
  18318. components: filterPanelComponents2.map(function(mem) {
  18319. return mem.asSpec();
  18320. }),
  18321. containerBehaviours: derive$1([config("image-tools-filter-panel-buttons-events", [
  18322. run$1(external.disable(), function(comp, _se) {
  18323. disableAllComponents(filterPanelComponents2, comp);
  18324. }),
  18325. run$1(external.enable(), function(comp, _se) {
  18326. enableAllComponents(filterPanelComponents2, comp);
  18327. })
  18328. ])])
  18329. });
  18330. };
  18331. var filterPanelComponents = [
  18332. createBackButton(),
  18333. createSpacer(),
  18334. createApplyButton()
  18335. ];
  18336. var FilterPanel = Container.sketch({
  18337. dom: panelDom,
  18338. components: filterPanelComponents.map(function(mem) {
  18339. return mem.asSpec();
  18340. })
  18341. });
  18342. var BrightnessPanel = createVariableFilterPanel("Brightness", brightness, -100, 0, 100);
  18343. var ContrastPanel = createVariableFilterPanel("Contrast", contrast, -100, 0, 100);
  18344. var GammaPanel = createVariableFilterPanel("Gamma", gamma, -100, 0, 100);
  18345. var makeColorTransform = function(red2, green, blue) {
  18346. return function(ir) {
  18347. return colorize(ir, red2, green, blue);
  18348. };
  18349. };
  18350. var makeColorSlider = function(label) {
  18351. var onChoose = function(slider, _thumb, _value) {
  18352. var redOpt = memRed.getOpt(slider);
  18353. var blueOpt = memBlue.getOpt(slider);
  18354. var greenOpt = memGreen.getOpt(slider);
  18355. redOpt.each(function(red2) {
  18356. blueOpt.each(function(blue) {
  18357. greenOpt.each(function(green) {
  18358. var r2 = Representing.getValue(red2).x / 100;
  18359. var g = Representing.getValue(green).x / 100;
  18360. var b2 = Representing.getValue(blue).x / 100;
  18361. var transform2 = makeColorTransform(r2, g, b2);
  18362. emitTransform(slider, transform2);
  18363. });
  18364. });
  18365. });
  18366. };
  18367. return makeSlider(label, onChoose, 0, 100, 200);
  18368. };
  18369. var memRed = makeColorSlider("R");
  18370. var memGreen = makeColorSlider("G");
  18371. var memBlue = makeColorSlider("B");
  18372. var colorizePanelComponents = [
  18373. createBackButton(),
  18374. memRed,
  18375. memGreen,
  18376. memBlue,
  18377. createApplyButton()
  18378. ];
  18379. var ColorizePanel = Container.sketch({
  18380. dom: panelDom,
  18381. components: colorizePanelComponents.map(function(mem) {
  18382. return mem.asSpec();
  18383. })
  18384. });
  18385. var getTransformPanelEvent = function(panel, transform2, update) {
  18386. return function(button2) {
  18387. var swap2 = function() {
  18388. memContainer.getOpt(button2).each(function(container2) {
  18389. Replacing.set(container2, [panel]);
  18390. update(container2);
  18391. });
  18392. };
  18393. emit$1(button2, internal.swap(), {
  18394. transform: transform2,
  18395. swap: swap2
  18396. });
  18397. };
  18398. };
  18399. var cropPanelUpdate = function(_anyInSystem) {
  18400. imagePanel.showCrop();
  18401. };
  18402. var resizePanelUpdate = function(anyInSystem) {
  18403. memSize.getOpt(anyInSystem).each(function(sizeInput) {
  18404. var measurements = imagePanel.getMeasurements();
  18405. var width2 = measurements.width;
  18406. var height2 = measurements.height;
  18407. Representing.setValue(sizeInput, {
  18408. width: width2,
  18409. height: height2
  18410. });
  18411. });
  18412. };
  18413. var sharpenTransform = Optional.some(sharpen);
  18414. var invertTransform = Optional.some(invert);
  18415. var buttonPanelComponents = [
  18416. createIconButton("crop", "Crop", getTransformPanelEvent(CropPanel, Optional.none(), cropPanelUpdate), false),
  18417. createIconButton("resize", "Resize", getTransformPanelEvent(ResizePanel, Optional.none(), resizePanelUpdate), false),
  18418. createIconButton("orientation", "Orientation", getTransformPanelEvent(FlipRotatePanel, Optional.none(), noop$1), false),
  18419. createIconButton("brightness", "Brightness", getTransformPanelEvent(BrightnessPanel, Optional.none(), noop$1), false),
  18420. createIconButton("sharpen", "Sharpen", getTransformPanelEvent(FilterPanel, sharpenTransform, noop$1), false),
  18421. createIconButton("contrast", "Contrast", getTransformPanelEvent(ContrastPanel, Optional.none(), noop$1), false),
  18422. createIconButton("color-levels", "Color levels", getTransformPanelEvent(ColorizePanel, Optional.none(), noop$1), false),
  18423. createIconButton("gamma", "Gamma", getTransformPanelEvent(GammaPanel, Optional.none(), noop$1), false),
  18424. createIconButton("invert", "Invert", getTransformPanelEvent(FilterPanel, invertTransform, noop$1), false)
  18425. ];
  18426. var ButtonPanel = Container.sketch({
  18427. dom: panelDom,
  18428. components: buttonPanelComponents.map(function(mem) {
  18429. return mem.asSpec();
  18430. })
  18431. });
  18432. var container = Container.sketch({
  18433. dom: { tag: "div" },
  18434. components: [ButtonPanel],
  18435. containerBehaviours: derive$1([Replacing.config({})])
  18436. });
  18437. var memContainer = record(container);
  18438. var getApplyButton = function(anyInSystem) {
  18439. return memContainer.getOpt(anyInSystem).map(function(container2) {
  18440. var panel = container2.components()[0];
  18441. return panel.components()[panel.components().length - 1];
  18442. });
  18443. };
  18444. return {
  18445. memContainer,
  18446. getApplyButton
  18447. };
  18448. };
  18449. var global$4 = tinymce.util.Tools.resolve("tinymce.geom.Rect");
  18450. var global$3 = tinymce.util.Tools.resolve("tinymce.util.Observable");
  18451. var global$2 = tinymce.util.Tools.resolve("tinymce.util.VK");
  18452. var getDocumentSize = function(doc) {
  18453. var max2 = Math.max;
  18454. var documentElement2 = doc.documentElement;
  18455. var body2 = doc.body;
  18456. var scrollWidth = max2(documentElement2.scrollWidth, body2.scrollWidth);
  18457. var clientWidth = max2(documentElement2.clientWidth, body2.clientWidth);
  18458. var offsetWidth = max2(documentElement2.offsetWidth, body2.offsetWidth);
  18459. var scrollHeight = max2(documentElement2.scrollHeight, body2.scrollHeight);
  18460. var clientHeight = max2(documentElement2.clientHeight, body2.clientHeight);
  18461. var offsetHeight = max2(documentElement2.offsetHeight, body2.offsetHeight);
  18462. return {
  18463. width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
  18464. height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
  18465. };
  18466. };
  18467. var isTouchEvent$1 = function(e) {
  18468. return isNonNullable(e.changedTouches);
  18469. };
  18470. var updateWithTouchData = function(e) {
  18471. if (isTouchEvent$1(e)) {
  18472. var keys2 = "screenX screenY pageX pageY clientX clientY".split(" ");
  18473. for (var i = 0; i < keys2.length; i++) {
  18474. e[keys2[i]] = e.changedTouches[0][keys2[i]];
  18475. }
  18476. }
  18477. };
  18478. function DragHelper(id, settings) {
  18479. var _a2, _b, _c;
  18480. var eventOverlay;
  18481. var handleEvents = [];
  18482. var overlayEvents = [];
  18483. var doc = (_a2 = settings.document) !== null && _a2 !== void 0 ? _a2 : document;
  18484. var root = (_b = settings.root) !== null && _b !== void 0 ? _b : doc;
  18485. var sugarDoc = SugarElement.fromDom(doc);
  18486. var downButton;
  18487. var startX;
  18488. var startY;
  18489. var handleElement = SugarElement.fromDom(root.getElementById((_c = settings.handle) !== null && _c !== void 0 ? _c : id));
  18490. var start = function(e) {
  18491. var rawEvent = e.raw;
  18492. var docSize = getDocumentSize(doc);
  18493. updateWithTouchData(rawEvent);
  18494. e.prevent();
  18495. downButton = rawEvent.button;
  18496. startX = rawEvent.screenX;
  18497. startY = rawEvent.screenY;
  18498. var cursor = get$c(handleElement, "cursor");
  18499. eventOverlay = SugarElement.fromTag("div", doc);
  18500. setAll(eventOverlay, {
  18501. "position": "absolute",
  18502. "top": "0",
  18503. "left": "0",
  18504. "width": docSize.width + "px",
  18505. "height": docSize.height + "px",
  18506. "z-index": "2147483647",
  18507. "opacity": "0.0001",
  18508. cursor
  18509. });
  18510. append$2(getBody(sugarDoc), eventOverlay);
  18511. overlayEvents.push(bind(sugarDoc, "mousemove", drag), bind(sugarDoc, "touchmove", drag), bind(sugarDoc, "mouseup", stop2), bind(sugarDoc, "touchend", stop2));
  18512. settings.start(rawEvent);
  18513. };
  18514. var drag = function(e) {
  18515. var rawEvent = e.raw;
  18516. updateWithTouchData(rawEvent);
  18517. if (rawEvent.button !== downButton) {
  18518. return stop2(e);
  18519. }
  18520. rawEvent.deltaX = rawEvent.screenX - startX;
  18521. rawEvent.deltaY = rawEvent.screenY - startY;
  18522. e.prevent();
  18523. settings.drag(rawEvent);
  18524. };
  18525. var stop2 = function(e) {
  18526. updateWithTouchData(e.raw);
  18527. each$1(overlayEvents, function(e2) {
  18528. return e2.unbind();
  18529. });
  18530. overlayEvents = [];
  18531. remove$5(eventOverlay);
  18532. if (settings.stop) {
  18533. settings.stop(e.raw);
  18534. }
  18535. };
  18536. var destroy = function() {
  18537. each$1(overlayEvents.concat(handleEvents), function(e) {
  18538. return e.unbind();
  18539. });
  18540. overlayEvents = [];
  18541. handleEvents = [];
  18542. if (isNonNullable(eventOverlay)) {
  18543. remove$5(eventOverlay);
  18544. }
  18545. };
  18546. handleEvents.push(bind(handleElement, "mousedown", start), bind(handleElement, "touchstart", start));
  18547. return { destroy };
  18548. }
  18549. var count = 0;
  18550. var create$2 = function(currentRect, viewPortRect, clampRect, containerElm, action) {
  18551. var dragHelpers;
  18552. var events2 = [];
  18553. var prefix2 = "tox-";
  18554. var id = prefix2 + "crid-" + count++;
  18555. var container = SugarElement.fromDom(containerElm);
  18556. var handles = [
  18557. {
  18558. name: "move",
  18559. xMul: 0,
  18560. yMul: 0,
  18561. deltaX: 1,
  18562. deltaY: 1,
  18563. deltaW: 0,
  18564. deltaH: 0,
  18565. label: "Crop Mask"
  18566. },
  18567. {
  18568. name: "nw",
  18569. xMul: 0,
  18570. yMul: 0,
  18571. deltaX: 1,
  18572. deltaY: 1,
  18573. deltaW: -1,
  18574. deltaH: -1,
  18575. label: "Top Left Crop Handle"
  18576. },
  18577. {
  18578. name: "ne",
  18579. xMul: 1,
  18580. yMul: 0,
  18581. deltaX: 0,
  18582. deltaY: 1,
  18583. deltaW: 1,
  18584. deltaH: -1,
  18585. label: "Top Right Crop Handle"
  18586. },
  18587. {
  18588. name: "sw",
  18589. xMul: 0,
  18590. yMul: 1,
  18591. deltaX: 1,
  18592. deltaY: 0,
  18593. deltaW: -1,
  18594. deltaH: 1,
  18595. label: "Bottom Left Crop Handle"
  18596. },
  18597. {
  18598. name: "se",
  18599. xMul: 1,
  18600. yMul: 1,
  18601. deltaX: 0,
  18602. deltaY: 0,
  18603. deltaW: 1,
  18604. deltaH: 1,
  18605. label: "Bottom Right Crop Handle"
  18606. }
  18607. ];
  18608. var blockers = [
  18609. "top",
  18610. "right",
  18611. "bottom",
  18612. "left"
  18613. ];
  18614. var getAbsoluteRect = function(outerRect, relativeRect) {
  18615. return {
  18616. x: relativeRect.x + outerRect.x,
  18617. y: relativeRect.y + outerRect.y,
  18618. w: relativeRect.w,
  18619. h: relativeRect.h
  18620. };
  18621. };
  18622. var getRelativeRect = function(outerRect, innerRect) {
  18623. return {
  18624. x: innerRect.x - outerRect.x,
  18625. y: innerRect.y - outerRect.y,
  18626. w: innerRect.w,
  18627. h: innerRect.h
  18628. };
  18629. };
  18630. var getInnerRect = function() {
  18631. return getRelativeRect(clampRect, currentRect);
  18632. };
  18633. var moveRect = function(handle2, startRect, deltaX, deltaY) {
  18634. var x = startRect.x + deltaX * handle2.deltaX;
  18635. var y = startRect.y + deltaY * handle2.deltaY;
  18636. var w = Math.max(20, startRect.w + deltaX * handle2.deltaW);
  18637. var h = Math.max(20, startRect.h + deltaY * handle2.deltaH);
  18638. var rect2 = currentRect = global$4.clamp({
  18639. x,
  18640. y,
  18641. w,
  18642. h
  18643. }, clampRect, handle2.name === "move");
  18644. rect2 = getRelativeRect(clampRect, rect2);
  18645. instance.fire("updateRect", { rect: rect2 });
  18646. setInnerRect(rect2);
  18647. };
  18648. var render2 = function() {
  18649. var createDragHelper = function(handle2) {
  18650. var startRect;
  18651. return DragHelper(id, {
  18652. document: containerElm.ownerDocument,
  18653. root: getRootNode(container).dom,
  18654. handle: id + "-" + handle2.name,
  18655. start: function() {
  18656. startRect = currentRect;
  18657. },
  18658. drag: function(e) {
  18659. moveRect(handle2, startRect, e.deltaX, e.deltaY);
  18660. }
  18661. });
  18662. };
  18663. var cropContainer = SugarElement.fromTag("div");
  18664. setAll$1(cropContainer, {
  18665. id,
  18666. "class": prefix2 + "croprect-container",
  18667. "role": "grid",
  18668. "aria-dropeffect": "execute"
  18669. });
  18670. append$2(container, cropContainer);
  18671. each$1(blockers, function(blocker) {
  18672. descendant(container, "#" + id).each(function(blockerElm) {
  18673. var cropBlocker = SugarElement.fromTag("div");
  18674. setAll$1(cropBlocker, {
  18675. "id": id + "-" + blocker,
  18676. "class": prefix2 + "croprect-block",
  18677. "data-mce-bogus": "all"
  18678. });
  18679. set$7(cropBlocker, "display", "none");
  18680. append$2(blockerElm, cropBlocker);
  18681. });
  18682. });
  18683. each$1(handles, function(handle2) {
  18684. descendant(container, "#" + id).each(function(handleElm) {
  18685. var cropHandle = SugarElement.fromTag("div");
  18686. setAll$1(cropHandle, {
  18687. "id": id + "-" + handle2.name,
  18688. "aria-label": handle2.label,
  18689. "aria-grabbed": "false",
  18690. "data-mce-bogus": "all",
  18691. "role": "gridcell",
  18692. "tabindex": "-1",
  18693. "title": handle2.label
  18694. });
  18695. add$1(cropHandle, [
  18696. prefix2 + "croprect-handle",
  18697. prefix2 + "croprect-handle-" + handle2.name
  18698. ]);
  18699. set$7(cropHandle, "display", "none");
  18700. append$2(handleElm, cropHandle);
  18701. });
  18702. });
  18703. dragHelpers = map$2(handles, createDragHelper);
  18704. repaint(currentRect);
  18705. var handleFocus = function(e) {
  18706. set$8(e.target, "aria-grabbed", e.raw.type === "focus" ? "true" : "false");
  18707. };
  18708. var handleKeydown = function(e) {
  18709. var activeHandle;
  18710. each$1(handles, function(handle2) {
  18711. if (get$d(e.target, "id") === id + "-" + handle2.name) {
  18712. activeHandle = handle2;
  18713. return false;
  18714. }
  18715. });
  18716. var moveAndBlock = function(evt, handle2, startRect, deltaX, deltaY) {
  18717. evt.stopPropagation();
  18718. evt.preventDefault();
  18719. moveRect(activeHandle, startRect, deltaX, deltaY);
  18720. };
  18721. switch (e.raw.keyCode) {
  18722. case global$2.LEFT:
  18723. moveAndBlock(e, activeHandle, currentRect, -10, 0);
  18724. break;
  18725. case global$2.RIGHT:
  18726. moveAndBlock(e, activeHandle, currentRect, 10, 0);
  18727. break;
  18728. case global$2.UP:
  18729. moveAndBlock(e, activeHandle, currentRect, 0, -10);
  18730. break;
  18731. case global$2.DOWN:
  18732. moveAndBlock(e, activeHandle, currentRect, 0, 10);
  18733. break;
  18734. case global$2.ENTER:
  18735. case global$2.SPACEBAR:
  18736. e.prevent();
  18737. action();
  18738. break;
  18739. }
  18740. };
  18741. events2.push(bind(container, "focusin", handleFocus), bind(container, "focusout", handleFocus), bind(container, "keydown", handleKeydown));
  18742. };
  18743. var toggleVisibility = function(state) {
  18744. var selectors = __spreadArray(__spreadArray([], map$2(handles, function(handle2) {
  18745. return "#" + id + "-" + handle2.name;
  18746. }), true), map$2(blockers, function(blocker) {
  18747. return "#" + id + "-" + blocker;
  18748. }), true).join(",");
  18749. var elems = descendants(container, selectors);
  18750. if (state) {
  18751. each$1(elems, function(elm) {
  18752. return remove$6(elm, "display");
  18753. });
  18754. } else {
  18755. each$1(elems, function(elm) {
  18756. return set$7(elm, "display", "none");
  18757. });
  18758. }
  18759. };
  18760. var repaint = function(rect2) {
  18761. var updateElementRect = function(name2, newRect) {
  18762. descendant(container, "#" + id + "-" + name2).each(function(elm) {
  18763. setAll(elm, {
  18764. left: newRect.x + "px",
  18765. top: newRect.y + "px",
  18766. width: Math.max(0, newRect.w) + "px",
  18767. height: Math.max(0, newRect.h) + "px"
  18768. });
  18769. });
  18770. };
  18771. each$1(handles, function(handle2) {
  18772. descendant(container, "#" + id + "-" + handle2.name).each(function(elm) {
  18773. setAll(elm, {
  18774. left: rect2.w * handle2.xMul + rect2.x + "px",
  18775. top: rect2.h * handle2.yMul + rect2.y + "px"
  18776. });
  18777. });
  18778. });
  18779. updateElementRect("top", {
  18780. x: viewPortRect.x,
  18781. y: viewPortRect.y,
  18782. w: viewPortRect.w,
  18783. h: rect2.y - viewPortRect.y
  18784. });
  18785. updateElementRect("right", {
  18786. x: rect2.x + rect2.w,
  18787. y: rect2.y,
  18788. w: viewPortRect.w - rect2.x - rect2.w + viewPortRect.x,
  18789. h: rect2.h
  18790. });
  18791. updateElementRect("bottom", {
  18792. x: viewPortRect.x,
  18793. y: rect2.y + rect2.h,
  18794. w: viewPortRect.w,
  18795. h: viewPortRect.h - rect2.y - rect2.h + viewPortRect.y
  18796. });
  18797. updateElementRect("left", {
  18798. x: viewPortRect.x,
  18799. y: rect2.y,
  18800. w: rect2.x - viewPortRect.x,
  18801. h: rect2.h
  18802. });
  18803. updateElementRect("move", rect2);
  18804. };
  18805. var setRect = function(rect2) {
  18806. currentRect = rect2;
  18807. repaint(currentRect);
  18808. };
  18809. var setViewPortRect = function(rect2) {
  18810. viewPortRect = rect2;
  18811. repaint(currentRect);
  18812. };
  18813. var setInnerRect = function(rect2) {
  18814. setRect(getAbsoluteRect(clampRect, rect2));
  18815. };
  18816. var setClampRect = function(rect2) {
  18817. clampRect = rect2;
  18818. repaint(currentRect);
  18819. };
  18820. var destroy = function() {
  18821. each$1(dragHelpers, function(helper) {
  18822. return helper.destroy();
  18823. });
  18824. dragHelpers = [];
  18825. each$1(events2, function(e) {
  18826. return e.unbind();
  18827. });
  18828. events2 = [];
  18829. };
  18830. render2();
  18831. var instance = __assign(__assign({}, global$3), {
  18832. toggleVisibility,
  18833. setClampRect,
  18834. setRect,
  18835. getInnerRect,
  18836. setInnerRect,
  18837. setViewPortRect,
  18838. destroy
  18839. });
  18840. return instance;
  18841. };
  18842. var CropRect = { create: create$2 };
  18843. var loadImage = function(image) {
  18844. return new global$c(function(resolve) {
  18845. var loaded = function() {
  18846. image.removeEventListener("load", loaded);
  18847. resolve(image);
  18848. };
  18849. if (image.complete) {
  18850. resolve(image);
  18851. } else {
  18852. image.addEventListener("load", loaded);
  18853. }
  18854. });
  18855. };
  18856. var renderImagePanel = function(initialUrl) {
  18857. var memBg = record({
  18858. dom: {
  18859. tag: "div",
  18860. classes: ["tox-image-tools__image-bg"],
  18861. attributes: { role: "presentation" }
  18862. }
  18863. });
  18864. var zoomState = Cell(1);
  18865. var cropRect = api$1();
  18866. var rectState = Cell({
  18867. x: 0,
  18868. y: 0,
  18869. w: 1,
  18870. h: 1
  18871. });
  18872. var viewRectState = Cell({
  18873. x: 0,
  18874. y: 0,
  18875. w: 1,
  18876. h: 1
  18877. });
  18878. var repaintImg = function(anyInSystem, img) {
  18879. memContainer.getOpt(anyInSystem).each(function(panel) {
  18880. var zoom3 = zoomState.get();
  18881. var panelW = get$a(panel.element);
  18882. var panelH = get$b(panel.element);
  18883. var width2 = img.dom.naturalWidth * zoom3;
  18884. var height2 = img.dom.naturalHeight * zoom3;
  18885. var left2 = Math.max(0, panelW / 2 - width2 / 2);
  18886. var top2 = Math.max(0, panelH / 2 - height2 / 2);
  18887. var css = {
  18888. left: left2.toString() + "px",
  18889. top: top2.toString() + "px",
  18890. width: width2.toString() + "px",
  18891. height: height2.toString() + "px",
  18892. position: "absolute"
  18893. };
  18894. setAll(img, css);
  18895. memBg.getOpt(panel).each(function(bg) {
  18896. setAll(bg.element, css);
  18897. });
  18898. cropRect.run(function(cRect) {
  18899. var rect2 = rectState.get();
  18900. cRect.setRect({
  18901. x: rect2.x * zoom3 + left2,
  18902. y: rect2.y * zoom3 + top2,
  18903. w: rect2.w * zoom3,
  18904. h: rect2.h * zoom3
  18905. });
  18906. cRect.setClampRect({
  18907. x: left2,
  18908. y: top2,
  18909. w: width2,
  18910. h: height2
  18911. });
  18912. cRect.setViewPortRect({
  18913. x: 0,
  18914. y: 0,
  18915. w: panelW,
  18916. h: panelH
  18917. });
  18918. });
  18919. });
  18920. };
  18921. var zoomFit = function(anyInSystem, img) {
  18922. memContainer.getOpt(anyInSystem).each(function(panel) {
  18923. var panelW = get$a(panel.element);
  18924. var panelH = get$b(panel.element);
  18925. var width2 = img.dom.naturalWidth;
  18926. var height2 = img.dom.naturalHeight;
  18927. var zoom3 = Math.min(panelW / width2, panelH / height2);
  18928. if (zoom3 >= 1) {
  18929. zoomState.set(1);
  18930. } else {
  18931. zoomState.set(zoom3);
  18932. }
  18933. });
  18934. };
  18935. var updateSrc = function(anyInSystem, url) {
  18936. var img = SugarElement.fromTag("img");
  18937. set$8(img, "src", url);
  18938. return loadImage(img.dom).then(function() {
  18939. if (anyInSystem.getSystem().isConnected()) {
  18940. memContainer.getOpt(anyInSystem).map(function(panel) {
  18941. var aImg = external$2({ element: img });
  18942. Replacing.replaceAt(panel, 1, Optional.some(aImg));
  18943. var lastViewRect = viewRectState.get();
  18944. var viewRect = {
  18945. x: 0,
  18946. y: 0,
  18947. w: img.dom.naturalWidth,
  18948. h: img.dom.naturalHeight
  18949. };
  18950. viewRectState.set(viewRect);
  18951. var rect2 = global$4.inflate(viewRect, -20, -20);
  18952. rectState.set(rect2);
  18953. if (lastViewRect.w !== viewRect.w || lastViewRect.h !== viewRect.h) {
  18954. zoomFit(panel, img);
  18955. }
  18956. repaintImg(panel, img);
  18957. });
  18958. }
  18959. });
  18960. };
  18961. var zoom2 = function(anyInSystem, direction) {
  18962. var currentZoom = zoomState.get();
  18963. var newZoom = direction > 0 ? Math.min(2, currentZoom + 0.1) : Math.max(0.1, currentZoom - 0.1);
  18964. zoomState.set(newZoom);
  18965. memContainer.getOpt(anyInSystem).each(function(panel) {
  18966. var img = panel.components()[1].element;
  18967. repaintImg(panel, img);
  18968. });
  18969. };
  18970. var showCrop = function() {
  18971. cropRect.run(function(cRect) {
  18972. cRect.toggleVisibility(true);
  18973. });
  18974. };
  18975. var hideCrop = function() {
  18976. cropRect.run(function(cRect) {
  18977. cRect.toggleVisibility(false);
  18978. });
  18979. };
  18980. var getRect = function() {
  18981. return rectState.get();
  18982. };
  18983. var container = Container.sketch({
  18984. dom: {
  18985. tag: "div",
  18986. classes: ["tox-image-tools__image"]
  18987. },
  18988. components: [
  18989. memBg.asSpec(),
  18990. {
  18991. dom: {
  18992. tag: "img",
  18993. attributes: { src: initialUrl }
  18994. }
  18995. },
  18996. {
  18997. dom: { tag: "div" },
  18998. behaviours: derive$1([config("image-panel-crop-events", [
  18999. runOnAttached(function(comp) {
  19000. memContainer.getOpt(comp).each(function(container2) {
  19001. var el = container2.element.dom;
  19002. var cRect = CropRect.create({
  19003. x: 10,
  19004. y: 10,
  19005. w: 100,
  19006. h: 100
  19007. }, {
  19008. x: 0,
  19009. y: 0,
  19010. w: 200,
  19011. h: 200
  19012. }, {
  19013. x: 0,
  19014. y: 0,
  19015. w: 200,
  19016. h: 200
  19017. }, el, noop);
  19018. cRect.toggleVisibility(false);
  19019. cRect.on("updateRect", function(e) {
  19020. var rect2 = e.rect;
  19021. var zoom3 = zoomState.get();
  19022. var newRect = {
  19023. x: Math.round(rect2.x / zoom3),
  19024. y: Math.round(rect2.y / zoom3),
  19025. w: Math.round(rect2.w / zoom3),
  19026. h: Math.round(rect2.h / zoom3)
  19027. };
  19028. rectState.set(newRect);
  19029. });
  19030. cropRect.set(cRect);
  19031. });
  19032. }),
  19033. runOnDetached(function() {
  19034. cropRect.clear();
  19035. })
  19036. ])])
  19037. }
  19038. ],
  19039. containerBehaviours: derive$1([
  19040. Replacing.config({}),
  19041. config("image-panel-events", [runOnAttached(function(comp) {
  19042. updateSrc(comp, initialUrl);
  19043. })])
  19044. ])
  19045. });
  19046. var memContainer = record(container);
  19047. var getMeasurements = function() {
  19048. var viewRect = viewRectState.get();
  19049. return {
  19050. width: viewRect.w,
  19051. height: viewRect.h
  19052. };
  19053. };
  19054. return {
  19055. memContainer,
  19056. updateSrc,
  19057. zoom: zoom2,
  19058. showCrop,
  19059. hideCrop,
  19060. getRect,
  19061. getMeasurements
  19062. };
  19063. };
  19064. var createButton = function(innerHtml, icon, disabled, action, providersBackstage) {
  19065. return renderIconButton({
  19066. name: innerHtml,
  19067. icon: Optional.some(icon),
  19068. disabled,
  19069. tooltip: Optional.some(innerHtml),
  19070. primary: false,
  19071. borderless: false
  19072. }, action, providersBackstage);
  19073. };
  19074. var setButtonEnabled = function(button2, enabled) {
  19075. if (enabled) {
  19076. Disabling.enable(button2);
  19077. } else {
  19078. Disabling.disable(button2);
  19079. }
  19080. };
  19081. var renderSideBar = function(providersBackstage) {
  19082. var updateButtonUndoStates = function(anyInSystem, undoEnabled, redoEnabled) {
  19083. memUndo.getOpt(anyInSystem).each(function(undo2) {
  19084. setButtonEnabled(undo2, undoEnabled);
  19085. });
  19086. memRedo.getOpt(anyInSystem).each(function(redo2) {
  19087. setButtonEnabled(redo2, redoEnabled);
  19088. });
  19089. };
  19090. var memUndo = record(createButton("Undo", "undo", true, function(button2) {
  19091. emitWith(button2, internal.undo(), { direction: 1 });
  19092. }, providersBackstage));
  19093. var memRedo = record(createButton("Redo", "redo", true, function(button2) {
  19094. emitWith(button2, internal.redo(), { direction: 1 });
  19095. }, providersBackstage));
  19096. var container = Container.sketch({
  19097. dom: {
  19098. tag: "div",
  19099. classes: [
  19100. "tox-image-tools__toolbar",
  19101. "tox-image-tools__sidebar"
  19102. ]
  19103. },
  19104. components: [
  19105. memUndo.asSpec(),
  19106. memRedo.asSpec(),
  19107. createButton("Zoom in", "zoom-in", false, function(button2) {
  19108. emitWith(button2, internal.zoom(), { direction: 1 });
  19109. }, providersBackstage),
  19110. createButton("Zoom out", "zoom-out", false, function(button2) {
  19111. emitWith(button2, internal.zoom(), { direction: -1 });
  19112. }, providersBackstage)
  19113. ]
  19114. });
  19115. return {
  19116. container,
  19117. updateButtonUndoStates
  19118. };
  19119. };
  19120. function UndoStack() {
  19121. var data = [];
  19122. var index = -1;
  19123. var add2 = function(state) {
  19124. var removed = data.splice(++index);
  19125. data.push(state);
  19126. return {
  19127. state,
  19128. removed
  19129. };
  19130. };
  19131. var undo2 = function() {
  19132. if (canUndo()) {
  19133. return data[--index];
  19134. }
  19135. };
  19136. var redo2 = function() {
  19137. if (canRedo()) {
  19138. return data[++index];
  19139. }
  19140. };
  19141. var canUndo = function() {
  19142. return index > 0;
  19143. };
  19144. var canRedo = function() {
  19145. return index !== -1 && index < data.length - 1;
  19146. };
  19147. return {
  19148. data,
  19149. add: add2,
  19150. undo: undo2,
  19151. redo: redo2,
  19152. canUndo,
  19153. canRedo
  19154. };
  19155. }
  19156. var makeState = function(initialState) {
  19157. var blobState = Cell(initialState);
  19158. var tempState = value$1();
  19159. var undoStack = UndoStack();
  19160. undoStack.add(initialState);
  19161. var getBlobState = function() {
  19162. return blobState.get();
  19163. };
  19164. var setBlobState = function(state) {
  19165. blobState.set(state);
  19166. };
  19167. var getTempState = function() {
  19168. return tempState.get().getOrThunk(blobState.get);
  19169. };
  19170. var updateTempState = function(blob) {
  19171. var newTempState = createState(blob);
  19172. destroyTempState();
  19173. tempState.set(newTempState);
  19174. return newTempState.url;
  19175. };
  19176. var createState = function(blob) {
  19177. return {
  19178. blob,
  19179. url: URL.createObjectURL(blob)
  19180. };
  19181. };
  19182. var destroyState = function(state) {
  19183. URL.revokeObjectURL(state.url);
  19184. };
  19185. var destroyStates = function(states) {
  19186. global$5.each(states, destroyState);
  19187. };
  19188. var destroyTempState = function() {
  19189. tempState.on(destroyState);
  19190. tempState.clear();
  19191. };
  19192. var addBlobState = function(blob) {
  19193. var newState = createState(blob);
  19194. setBlobState(newState);
  19195. var removed = undoStack.add(newState).removed;
  19196. destroyStates(removed);
  19197. return newState.url;
  19198. };
  19199. var addTempState = function(blob) {
  19200. var newState = createState(blob);
  19201. tempState.set(newState);
  19202. return newState.url;
  19203. };
  19204. var applyTempState = function(postApply) {
  19205. return tempState.get().fold(noop, function(temp) {
  19206. addBlobState(temp.blob);
  19207. postApply();
  19208. });
  19209. };
  19210. var undo2 = function() {
  19211. var currentState = undoStack.undo();
  19212. setBlobState(currentState);
  19213. return currentState.url;
  19214. };
  19215. var redo2 = function() {
  19216. var currentState = undoStack.redo();
  19217. setBlobState(currentState);
  19218. return currentState.url;
  19219. };
  19220. var getHistoryStates = function() {
  19221. var undoEnabled = undoStack.canUndo();
  19222. var redoEnabled = undoStack.canRedo();
  19223. return {
  19224. undoEnabled,
  19225. redoEnabled
  19226. };
  19227. };
  19228. return {
  19229. getBlobState,
  19230. setBlobState,
  19231. addBlobState,
  19232. getTempState,
  19233. updateTempState,
  19234. addTempState,
  19235. applyTempState,
  19236. destroyTempState,
  19237. undo: undo2,
  19238. redo: redo2,
  19239. getHistoryStates
  19240. };
  19241. };
  19242. var renderImageTools = function(detail, providersBackstage) {
  19243. var state = makeState(detail.currentState);
  19244. var zoom2 = function(anyInSystem, simulatedEvent) {
  19245. var direction = simulatedEvent.event.direction;
  19246. imagePanel.zoom(anyInSystem, direction);
  19247. };
  19248. var updateButtonUndoStates = function(anyInSystem) {
  19249. var historyStates = state.getHistoryStates();
  19250. sideBar.updateButtonUndoStates(anyInSystem, historyStates.undoEnabled, historyStates.redoEnabled);
  19251. emitWith(anyInSystem, external.formActionEvent, {
  19252. name: external.saveState(),
  19253. value: historyStates.undoEnabled
  19254. });
  19255. };
  19256. var disableUndoRedo = function(anyInSystem) {
  19257. sideBar.updateButtonUndoStates(anyInSystem, false, false);
  19258. };
  19259. var undo2 = function(anyInSystem, _simulatedEvent) {
  19260. var url = state.undo();
  19261. updateSrc(anyInSystem, url).then(function(_oImg) {
  19262. unblock2(anyInSystem);
  19263. updateButtonUndoStates(anyInSystem);
  19264. });
  19265. };
  19266. var redo2 = function(anyInSystem, _simulatedEvent) {
  19267. var url = state.redo();
  19268. updateSrc(anyInSystem, url).then(function(_oImg) {
  19269. unblock2(anyInSystem);
  19270. updateButtonUndoStates(anyInSystem);
  19271. });
  19272. };
  19273. var imageResultToBlob = function(ir) {
  19274. return ir.toBlob();
  19275. };
  19276. var block2 = function(anyInSystem) {
  19277. emitWith(anyInSystem, external.formActionEvent, {
  19278. name: external.disable(),
  19279. value: {}
  19280. });
  19281. };
  19282. var unblock2 = function(anyInSystem) {
  19283. editPanel.getApplyButton(anyInSystem).each(function(applyButton) {
  19284. Disabling.enable(applyButton);
  19285. });
  19286. emitWith(anyInSystem, external.formActionEvent, {
  19287. name: external.enable(),
  19288. value: {}
  19289. });
  19290. };
  19291. var updateSrc = function(anyInSystem, src) {
  19292. block2(anyInSystem);
  19293. return imagePanel.updateSrc(anyInSystem, src);
  19294. };
  19295. var blobManipulate = function(anyInSystem, blob, filter2, action, swap3) {
  19296. block2(anyInSystem);
  19297. blobToImageResult(blob).then(filter2).then(imageResultToBlob).then(action).then(function(url) {
  19298. return updateSrc(anyInSystem, url);
  19299. }).then(function() {
  19300. updateButtonUndoStates(anyInSystem);
  19301. swap3();
  19302. unblock2(anyInSystem);
  19303. }).catch(function(err) {
  19304. console.log(err);
  19305. if (anyInSystem.getSystem().isConnected()) {
  19306. unblock2(anyInSystem);
  19307. }
  19308. });
  19309. };
  19310. var manipulate = function(anyInSystem, filter2, swap3) {
  19311. var blob = state.getBlobState().blob;
  19312. var action = function(blob2) {
  19313. return state.updateTempState(blob2);
  19314. };
  19315. blobManipulate(anyInSystem, blob, filter2, action, swap3);
  19316. };
  19317. var tempManipulate = function(anyInSystem, filter2) {
  19318. var blob = state.getTempState().blob;
  19319. var action = function(blob2) {
  19320. return state.addTempState(blob2);
  19321. };
  19322. blobManipulate(anyInSystem, blob, filter2, action, noop);
  19323. };
  19324. var manipulateApply = function(anyInSystem, filter2, swap3) {
  19325. var blob = state.getBlobState().blob;
  19326. var action = function(blob2) {
  19327. var url = state.addBlobState(blob2);
  19328. destroyTempState(anyInSystem);
  19329. return url;
  19330. };
  19331. blobManipulate(anyInSystem, blob, filter2, action, swap3);
  19332. };
  19333. var apply2 = function(anyInSystem, simulatedEvent) {
  19334. var postApply = function() {
  19335. destroyTempState(anyInSystem);
  19336. var swap3 = simulatedEvent.event.swap;
  19337. swap3();
  19338. };
  19339. state.applyTempState(postApply);
  19340. };
  19341. var destroyTempState = function(anyInSystem) {
  19342. var currentUrl = state.getBlobState().url;
  19343. state.destroyTempState();
  19344. updateButtonUndoStates(anyInSystem);
  19345. return currentUrl;
  19346. };
  19347. var cancel = function(anyInSystem) {
  19348. var currentUrl = destroyTempState(anyInSystem);
  19349. updateSrc(anyInSystem, currentUrl).then(function(_oImg) {
  19350. unblock2(anyInSystem);
  19351. });
  19352. };
  19353. var back2 = function(anyInSystem, simulatedEvent) {
  19354. cancel(anyInSystem);
  19355. var swap3 = simulatedEvent.event.swap;
  19356. swap3();
  19357. imagePanel.hideCrop();
  19358. };
  19359. var transform2 = function(anyInSystem, simulatedEvent) {
  19360. return manipulate(anyInSystem, simulatedEvent.event.transform, noop);
  19361. };
  19362. var tempTransform2 = function(anyInSystem, simulatedEvent) {
  19363. return tempManipulate(anyInSystem, simulatedEvent.event.transform);
  19364. };
  19365. var transformApply2 = function(anyInSystem, simulatedEvent) {
  19366. return manipulateApply(anyInSystem, simulatedEvent.event.transform, simulatedEvent.event.swap);
  19367. };
  19368. var imagePanel = renderImagePanel(detail.currentState.url);
  19369. var sideBar = renderSideBar(providersBackstage);
  19370. var editPanel = renderEditPanel(imagePanel, providersBackstage);
  19371. var swap2 = function(anyInSystem, simulatedEvent) {
  19372. disableUndoRedo(anyInSystem);
  19373. var transform3 = simulatedEvent.event.transform;
  19374. var swap3 = simulatedEvent.event.swap;
  19375. transform3.fold(function() {
  19376. swap3();
  19377. }, function(transform4) {
  19378. manipulate(anyInSystem, transform4, swap3);
  19379. });
  19380. };
  19381. return {
  19382. dom: {
  19383. tag: "div",
  19384. attributes: { role: "presentation" }
  19385. },
  19386. components: [
  19387. editPanel.memContainer.asSpec(),
  19388. imagePanel.memContainer.asSpec(),
  19389. sideBar.container
  19390. ],
  19391. behaviours: derive$1([
  19392. Representing.config({
  19393. store: {
  19394. mode: "manual",
  19395. getValue: function() {
  19396. return state.getBlobState();
  19397. }
  19398. }
  19399. }),
  19400. config("image-tools-events", [
  19401. run$1(internal.undo(), undo2),
  19402. run$1(internal.redo(), redo2),
  19403. run$1(internal.zoom(), zoom2),
  19404. run$1(internal.back(), back2),
  19405. run$1(internal.apply(), apply2),
  19406. run$1(internal.transform(), transform2),
  19407. run$1(internal.tempTransform(), tempTransform2),
  19408. run$1(internal.transformApply(), transformApply2),
  19409. run$1(internal.swap(), swap2)
  19410. ]),
  19411. ComposingConfigs.self()
  19412. ])
  19413. };
  19414. };
  19415. var renderLabel = function(spec, backstageShared) {
  19416. var label = {
  19417. dom: {
  19418. tag: "label",
  19419. innerHtml: backstageShared.providers.translate(spec.label),
  19420. classes: ["tox-label"]
  19421. }
  19422. };
  19423. var comps = map$2(spec.items, backstageShared.interpreter);
  19424. return {
  19425. dom: {
  19426. tag: "div",
  19427. classes: ["tox-form__group"]
  19428. },
  19429. components: [label].concat(comps),
  19430. behaviours: derive$1([
  19431. ComposingConfigs.self(),
  19432. Replacing.config({}),
  19433. RepresentingConfigs.domHtml(Optional.none()),
  19434. Keying.config({ mode: "acyclic" })
  19435. ])
  19436. };
  19437. };
  19438. var isSingleListItem = function(item2) {
  19439. return !has$2(item2, "items");
  19440. };
  19441. var dataAttribute = "data-value";
  19442. var fetchItems = function(dropdownComp, name2, items, selectedValue) {
  19443. return map$2(items, function(item2) {
  19444. if (!isSingleListItem(item2)) {
  19445. return {
  19446. type: "nestedmenuitem",
  19447. text: item2.text,
  19448. getSubmenuItems: function() {
  19449. return fetchItems(dropdownComp, name2, item2.items, selectedValue);
  19450. }
  19451. };
  19452. } else {
  19453. return {
  19454. type: "togglemenuitem",
  19455. text: item2.text,
  19456. value: item2.value,
  19457. active: item2.value === selectedValue,
  19458. onAction: function() {
  19459. Representing.setValue(dropdownComp, item2.value);
  19460. emitWith(dropdownComp, formChangeEvent, { name: name2 });
  19461. Focusing.focus(dropdownComp);
  19462. }
  19463. };
  19464. }
  19465. });
  19466. };
  19467. var findItemByValue = function(items, value2) {
  19468. return findMap(items, function(item2) {
  19469. if (!isSingleListItem(item2)) {
  19470. return findItemByValue(item2.items, value2);
  19471. } else {
  19472. return someIf(item2.value === value2, item2);
  19473. }
  19474. });
  19475. };
  19476. var renderListBox = function(spec, backstage) {
  19477. var providersBackstage = backstage.shared.providers;
  19478. var initialItem = head(spec.items).filter(isSingleListItem);
  19479. var pLabel = spec.label.map(function(label) {
  19480. return renderLabel$2(label, providersBackstage);
  19481. });
  19482. var pField = FormField.parts.field({
  19483. dom: {},
  19484. factory: {
  19485. sketch: function(sketchSpec) {
  19486. return renderCommonDropdown({
  19487. uid: sketchSpec.uid,
  19488. text: initialItem.map(function(item2) {
  19489. return item2.text;
  19490. }),
  19491. icon: Optional.none(),
  19492. tooltip: spec.label,
  19493. role: Optional.none(),
  19494. fetch: function(comp, callback) {
  19495. var items = fetchItems(comp, spec.name, spec.items, Representing.getValue(comp));
  19496. callback(build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false));
  19497. },
  19498. onSetup: constant$1(noop),
  19499. getApi: constant$1({}),
  19500. columns: 1,
  19501. presets: "normal",
  19502. classes: [],
  19503. dropdownBehaviours: [
  19504. Tabstopping.config({}),
  19505. Representing.config({
  19506. store: {
  19507. mode: "manual",
  19508. initialValue: initialItem.map(function(item2) {
  19509. return item2.value;
  19510. }).getOr(""),
  19511. getValue: function(comp) {
  19512. return get$d(comp.element, dataAttribute);
  19513. },
  19514. setValue: function(comp, data) {
  19515. findItemByValue(spec.items, data).each(function(item2) {
  19516. set$8(comp.element, dataAttribute, item2.value);
  19517. emitWith(comp, updateMenuText, { text: item2.text });
  19518. });
  19519. }
  19520. }
  19521. })
  19522. ]
  19523. }, "tox-listbox", backstage.shared);
  19524. }
  19525. }
  19526. });
  19527. var listBoxWrap = {
  19528. dom: {
  19529. tag: "div",
  19530. classes: ["tox-listboxfield"]
  19531. },
  19532. components: [pField]
  19533. };
  19534. return FormField.sketch({
  19535. dom: {
  19536. tag: "div",
  19537. classes: ["tox-form__group"]
  19538. },
  19539. components: flatten([
  19540. pLabel.toArray(),
  19541. [listBoxWrap]
  19542. ]),
  19543. fieldBehaviours: derive$1([Disabling.config({
  19544. disabled: constant$1(spec.disabled),
  19545. onDisabled: function(comp) {
  19546. FormField.getField(comp).each(Disabling.disable);
  19547. },
  19548. onEnabled: function(comp) {
  19549. FormField.getField(comp).each(Disabling.enable);
  19550. }
  19551. })])
  19552. });
  19553. };
  19554. var renderPanel = function(spec, backstage) {
  19555. return {
  19556. dom: {
  19557. tag: "div",
  19558. classes: spec.classes
  19559. },
  19560. components: map$2(spec.items, backstage.shared.interpreter)
  19561. };
  19562. };
  19563. var factory$e = function(detail, _spec) {
  19564. var options = map$2(detail.options, function(option2) {
  19565. return {
  19566. dom: {
  19567. tag: "option",
  19568. value: option2.value,
  19569. innerHtml: option2.text
  19570. }
  19571. };
  19572. });
  19573. var initialValues = detail.data.map(function(v) {
  19574. return wrap$1("initialValue", v);
  19575. }).getOr({});
  19576. return {
  19577. uid: detail.uid,
  19578. dom: {
  19579. tag: "select",
  19580. classes: detail.selectClasses,
  19581. attributes: detail.selectAttributes
  19582. },
  19583. components: options,
  19584. behaviours: augment(detail.selectBehaviours, [
  19585. Focusing.config({}),
  19586. Representing.config({
  19587. store: __assign({
  19588. mode: "manual",
  19589. getValue: function(select2) {
  19590. return get$5(select2.element);
  19591. },
  19592. setValue: function(select2, newValue) {
  19593. var found = find$5(detail.options, function(opt) {
  19594. return opt.value === newValue;
  19595. });
  19596. if (found.isSome()) {
  19597. set$4(select2.element, newValue);
  19598. }
  19599. }
  19600. }, initialValues)
  19601. })
  19602. ])
  19603. };
  19604. };
  19605. var HtmlSelect = single({
  19606. name: "HtmlSelect",
  19607. configFields: [
  19608. required$1("options"),
  19609. field("selectBehaviours", [
  19610. Focusing,
  19611. Representing
  19612. ]),
  19613. defaulted("selectClasses", []),
  19614. defaulted("selectAttributes", {}),
  19615. option("data")
  19616. ],
  19617. factory: factory$e
  19618. });
  19619. var renderSelectBox = function(spec, providersBackstage) {
  19620. var translatedOptions = map$2(spec.items, function(item2) {
  19621. return {
  19622. text: providersBackstage.translate(item2.text),
  19623. value: item2.value
  19624. };
  19625. });
  19626. var pLabel = spec.label.map(function(label) {
  19627. return renderLabel$2(label, providersBackstage);
  19628. });
  19629. var pField = FormField.parts.field({
  19630. dom: {},
  19631. selectAttributes: { size: spec.size },
  19632. options: translatedOptions,
  19633. factory: HtmlSelect,
  19634. selectBehaviours: derive$1([
  19635. Disabling.config({
  19636. disabled: function() {
  19637. return spec.disabled || providersBackstage.isDisabled();
  19638. }
  19639. }),
  19640. Tabstopping.config({}),
  19641. config("selectbox-change", [run$1(change(), function(component, _) {
  19642. emitWith(component, formChangeEvent, { name: spec.name });
  19643. })])
  19644. ])
  19645. });
  19646. var chevron = spec.size > 1 ? Optional.none() : Optional.some(render$3("chevron-down", {
  19647. tag: "div",
  19648. classes: ["tox-selectfield__icon-js"]
  19649. }, providersBackstage.icons));
  19650. var selectWrap = {
  19651. dom: {
  19652. tag: "div",
  19653. classes: ["tox-selectfield"]
  19654. },
  19655. components: flatten([
  19656. [pField],
  19657. chevron.toArray()
  19658. ])
  19659. };
  19660. return FormField.sketch({
  19661. dom: {
  19662. tag: "div",
  19663. classes: ["tox-form__group"]
  19664. },
  19665. components: flatten([
  19666. pLabel.toArray(),
  19667. [selectWrap]
  19668. ]),
  19669. fieldBehaviours: derive$1([
  19670. Disabling.config({
  19671. disabled: function() {
  19672. return spec.disabled || providersBackstage.isDisabled();
  19673. },
  19674. onDisabled: function(comp) {
  19675. FormField.getField(comp).each(Disabling.disable);
  19676. },
  19677. onEnabled: function(comp) {
  19678. FormField.getField(comp).each(Disabling.enable);
  19679. }
  19680. }),
  19681. receivingConfig()
  19682. ])
  19683. });
  19684. };
  19685. var renderTable = function(spec, providersBackstage) {
  19686. var renderTh = function(text2) {
  19687. return {
  19688. dom: {
  19689. tag: "th",
  19690. innerHtml: providersBackstage.translate(text2)
  19691. }
  19692. };
  19693. };
  19694. var renderHeader2 = function(header) {
  19695. return {
  19696. dom: { tag: "thead" },
  19697. components: [{
  19698. dom: { tag: "tr" },
  19699. components: map$2(header, renderTh)
  19700. }]
  19701. };
  19702. };
  19703. var renderTd = function(text2) {
  19704. return {
  19705. dom: {
  19706. tag: "td",
  19707. innerHtml: providersBackstage.translate(text2)
  19708. }
  19709. };
  19710. };
  19711. var renderTr = function(row) {
  19712. return {
  19713. dom: { tag: "tr" },
  19714. components: map$2(row, renderTd)
  19715. };
  19716. };
  19717. var renderRows = function(rows) {
  19718. return {
  19719. dom: { tag: "tbody" },
  19720. components: map$2(rows, renderTr)
  19721. };
  19722. };
  19723. return {
  19724. dom: {
  19725. tag: "table",
  19726. classes: ["tox-dialog__table"]
  19727. },
  19728. components: [
  19729. renderHeader2(spec.header),
  19730. renderRows(spec.cells)
  19731. ],
  19732. behaviours: derive$1([
  19733. Tabstopping.config({}),
  19734. Focusing.config({})
  19735. ])
  19736. };
  19737. };
  19738. var renderTextField = function(spec, providersBackstage) {
  19739. var pLabel = spec.label.map(function(label) {
  19740. return renderLabel$2(label, providersBackstage);
  19741. });
  19742. var baseInputBehaviours = [
  19743. Disabling.config({
  19744. disabled: function() {
  19745. return spec.disabled || providersBackstage.isDisabled();
  19746. }
  19747. }),
  19748. receivingConfig(),
  19749. Keying.config({
  19750. mode: "execution",
  19751. useEnter: spec.multiline !== true,
  19752. useControlEnter: spec.multiline === true,
  19753. execute: function(comp) {
  19754. emit(comp, formSubmitEvent);
  19755. return Optional.some(true);
  19756. }
  19757. }),
  19758. config("textfield-change", [
  19759. run$1(input(), function(component, _) {
  19760. emitWith(component, formChangeEvent, { name: spec.name });
  19761. }),
  19762. run$1(postPaste(), function(component, _) {
  19763. emitWith(component, formChangeEvent, { name: spec.name });
  19764. })
  19765. ]),
  19766. Tabstopping.config({})
  19767. ];
  19768. var validatingBehaviours = spec.validation.map(function(vl) {
  19769. return Invalidating.config({
  19770. getRoot: function(input2) {
  19771. return parent(input2.element);
  19772. },
  19773. invalidClass: "tox-invalid",
  19774. validator: {
  19775. validate: function(input2) {
  19776. var v = Representing.getValue(input2);
  19777. var result = vl.validator(v);
  19778. return Future.pure(result === true ? Result.value(v) : Result.error(result));
  19779. },
  19780. validateOnLoad: vl.validateOnLoad
  19781. }
  19782. });
  19783. }).toArray();
  19784. var placeholder2 = spec.placeholder.fold(constant$1({}), function(p) {
  19785. return { placeholder: providersBackstage.translate(p) };
  19786. });
  19787. var inputMode = spec.inputMode.fold(constant$1({}), function(mode) {
  19788. return { inputmode: mode };
  19789. });
  19790. var inputAttributes = __assign(__assign({}, placeholder2), inputMode);
  19791. var pField = FormField.parts.field({
  19792. tag: spec.multiline === true ? "textarea" : "input",
  19793. inputAttributes,
  19794. inputClasses: [spec.classname],
  19795. inputBehaviours: derive$1(flatten([
  19796. baseInputBehaviours,
  19797. validatingBehaviours
  19798. ])),
  19799. selectOnFocus: false,
  19800. factory: Input
  19801. });
  19802. var extraClasses = spec.flex ? ["tox-form__group--stretched"] : [];
  19803. var extraClasses2 = extraClasses.concat(spec.maximized ? ["tox-form-group--maximize"] : []);
  19804. var extraBehaviours = [
  19805. Disabling.config({
  19806. disabled: function() {
  19807. return spec.disabled || providersBackstage.isDisabled();
  19808. },
  19809. onDisabled: function(comp) {
  19810. FormField.getField(comp).each(Disabling.disable);
  19811. },
  19812. onEnabled: function(comp) {
  19813. FormField.getField(comp).each(Disabling.enable);
  19814. }
  19815. }),
  19816. receivingConfig()
  19817. ];
  19818. return renderFormFieldWith(pLabel, pField, extraClasses2, extraBehaviours);
  19819. };
  19820. var renderInput = function(spec, providersBackstage) {
  19821. return renderTextField({
  19822. name: spec.name,
  19823. multiline: false,
  19824. label: spec.label,
  19825. inputMode: spec.inputMode,
  19826. placeholder: spec.placeholder,
  19827. flex: false,
  19828. disabled: spec.disabled,
  19829. classname: "tox-textfield",
  19830. validation: Optional.none(),
  19831. maximized: spec.maximized
  19832. }, providersBackstage);
  19833. };
  19834. var renderTextarea = function(spec, providersBackstage) {
  19835. return renderTextField({
  19836. name: spec.name,
  19837. multiline: true,
  19838. label: spec.label,
  19839. inputMode: Optional.none(),
  19840. placeholder: spec.placeholder,
  19841. flex: true,
  19842. disabled: spec.disabled,
  19843. classname: "tox-textarea",
  19844. validation: Optional.none(),
  19845. maximized: spec.maximized
  19846. }, providersBackstage);
  19847. };
  19848. var events$6 = function(streamConfig, streamState) {
  19849. var streams = streamConfig.stream.streams;
  19850. var processor = streams.setup(streamConfig, streamState);
  19851. return derive$2([
  19852. run$1(streamConfig.event, processor),
  19853. runOnDetached(function() {
  19854. return streamState.cancel();
  19855. })
  19856. ].concat(streamConfig.cancelEvent.map(function(e) {
  19857. return [run$1(e, function() {
  19858. return streamState.cancel();
  19859. })];
  19860. }).getOr([])));
  19861. };
  19862. var ActiveStreaming = Object.freeze({
  19863. __proto__: null,
  19864. events: events$6
  19865. });
  19866. var throttle = function(_config) {
  19867. var state = Cell(null);
  19868. var readState = function() {
  19869. return { timer: state.get() !== null ? "set" : "unset" };
  19870. };
  19871. var setTimer = function(t2) {
  19872. state.set(t2);
  19873. };
  19874. var cancel = function() {
  19875. var t2 = state.get();
  19876. if (t2 !== null) {
  19877. t2.cancel();
  19878. }
  19879. };
  19880. return nu$8({
  19881. readState,
  19882. setTimer,
  19883. cancel
  19884. });
  19885. };
  19886. var init$9 = function(spec) {
  19887. return spec.stream.streams.state(spec);
  19888. };
  19889. var StreamingState = Object.freeze({
  19890. __proto__: null,
  19891. throttle,
  19892. init: init$9
  19893. });
  19894. var setup$c = function(streamInfo, streamState) {
  19895. var sInfo = streamInfo.stream;
  19896. var throttler = last(streamInfo.onStream, sInfo.delay);
  19897. streamState.setTimer(throttler);
  19898. return function(component, simulatedEvent) {
  19899. throttler.throttle(component, simulatedEvent);
  19900. if (sInfo.stopEvent) {
  19901. simulatedEvent.stop();
  19902. }
  19903. };
  19904. };
  19905. var StreamingSchema = [
  19906. requiredOf("stream", choose$1("mode", {
  19907. throttle: [
  19908. required$1("delay"),
  19909. defaulted("stopEvent", true),
  19910. output$1("streams", {
  19911. setup: setup$c,
  19912. state: throttle
  19913. })
  19914. ]
  19915. })),
  19916. defaulted("event", "input"),
  19917. option("cancelEvent"),
  19918. onStrictHandler("onStream")
  19919. ];
  19920. var Streaming = create$8({
  19921. fields: StreamingSchema,
  19922. name: "streaming",
  19923. active: ActiveStreaming,
  19924. state: StreamingState
  19925. });
  19926. var setValueFromItem = function(model, input2, item2) {
  19927. var itemData = Representing.getValue(item2);
  19928. Representing.setValue(input2, itemData);
  19929. setCursorAtEnd(input2);
  19930. };
  19931. var setSelectionOn = function(input2, f) {
  19932. var el = input2.element;
  19933. var value2 = get$5(el);
  19934. var node = el.dom;
  19935. if (get$d(el, "type") !== "number") {
  19936. f(node, value2);
  19937. }
  19938. };
  19939. var setCursorAtEnd = function(input2) {
  19940. setSelectionOn(input2, function(node, value2) {
  19941. return node.setSelectionRange(value2.length, value2.length);
  19942. });
  19943. };
  19944. var setSelectionToEnd = function(input2, startOffset) {
  19945. setSelectionOn(input2, function(node, value2) {
  19946. return node.setSelectionRange(startOffset, value2.length);
  19947. });
  19948. };
  19949. var attemptSelectOver = function(model, input2, item2) {
  19950. if (!model.selectsOver) {
  19951. return Optional.none();
  19952. } else {
  19953. var currentValue2 = Representing.getValue(input2);
  19954. var inputDisplay_1 = model.getDisplayText(currentValue2);
  19955. var itemValue = Representing.getValue(item2);
  19956. var itemDisplay = model.getDisplayText(itemValue);
  19957. return itemDisplay.indexOf(inputDisplay_1) === 0 ? Optional.some(function() {
  19958. setValueFromItem(model, input2, item2);
  19959. setSelectionToEnd(input2, inputDisplay_1.length);
  19960. }) : Optional.none();
  19961. }
  19962. };
  19963. var itemExecute = constant$1("alloy.typeahead.itemexecute");
  19964. var make$3 = function(detail, components2, spec, externals) {
  19965. var navigateList = function(comp, simulatedEvent, highlighter) {
  19966. detail.previewing.set(false);
  19967. var sandbox = Coupling.getCoupled(comp, "sandbox");
  19968. if (Sandboxing.isOpen(sandbox)) {
  19969. Composing.getCurrent(sandbox).each(function(menu2) {
  19970. Highlighting.getHighlighted(menu2).fold(function() {
  19971. highlighter(menu2);
  19972. }, function() {
  19973. dispatchEvent(sandbox, menu2.element, "keydown", simulatedEvent);
  19974. });
  19975. });
  19976. } else {
  19977. var onOpenSync = function(sandbox2) {
  19978. Composing.getCurrent(sandbox2).each(highlighter);
  19979. };
  19980. open(detail, mapFetch(comp), comp, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  19981. }
  19982. };
  19983. var focusBehaviours$1 = focusBehaviours(detail);
  19984. var mapFetch = function(comp) {
  19985. return function(tdata) {
  19986. return tdata.map(function(data) {
  19987. var menus = values(data.menus);
  19988. var items = bind$3(menus, function(menu2) {
  19989. return filter$2(menu2.items, function(item2) {
  19990. return item2.type === "item";
  19991. });
  19992. });
  19993. var repState = Representing.getState(comp);
  19994. repState.update(map$2(items, function(item2) {
  19995. return item2.data;
  19996. }));
  19997. return data;
  19998. });
  19999. };
  20000. };
  20001. var behaviours2 = [
  20002. Focusing.config({}),
  20003. Representing.config({
  20004. onSetValue: detail.onSetValue,
  20005. store: __assign({
  20006. mode: "dataset",
  20007. getDataKey: function(comp) {
  20008. return get$5(comp.element);
  20009. },
  20010. getFallbackEntry: function(itemString) {
  20011. return {
  20012. value: itemString,
  20013. meta: {}
  20014. };
  20015. },
  20016. setValue: function(comp, data) {
  20017. set$4(comp.element, detail.model.getDisplayText(data));
  20018. }
  20019. }, detail.initialData.map(function(d) {
  20020. return wrap$1("initialValue", d);
  20021. }).getOr({}))
  20022. }),
  20023. Streaming.config({
  20024. stream: {
  20025. mode: "throttle",
  20026. delay: detail.responseTime,
  20027. stopEvent: false
  20028. },
  20029. onStream: function(component, _simulatedEvent) {
  20030. var sandbox = Coupling.getCoupled(component, "sandbox");
  20031. var focusInInput = Focusing.isFocused(component);
  20032. if (focusInInput) {
  20033. if (get$5(component.element).length >= detail.minChars) {
  20034. var previousValue_1 = Composing.getCurrent(sandbox).bind(function(menu2) {
  20035. return Highlighting.getHighlighted(menu2).map(Representing.getValue);
  20036. });
  20037. detail.previewing.set(true);
  20038. var onOpenSync = function(_sandbox) {
  20039. Composing.getCurrent(sandbox).each(function(menu2) {
  20040. previousValue_1.fold(function() {
  20041. if (detail.model.selectsOver) {
  20042. Highlighting.highlightFirst(menu2);
  20043. }
  20044. }, function(pv) {
  20045. Highlighting.highlightBy(menu2, function(item2) {
  20046. var itemData = Representing.getValue(item2);
  20047. return itemData.value === pv.value;
  20048. });
  20049. Highlighting.getHighlighted(menu2).orThunk(function() {
  20050. Highlighting.highlightFirst(menu2);
  20051. return Optional.none();
  20052. });
  20053. });
  20054. });
  20055. };
  20056. open(detail, mapFetch(component), component, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  20057. }
  20058. }
  20059. },
  20060. cancelEvent: typeaheadCancel()
  20061. }),
  20062. Keying.config({
  20063. mode: "special",
  20064. onDown: function(comp, simulatedEvent) {
  20065. navigateList(comp, simulatedEvent, Highlighting.highlightFirst);
  20066. return Optional.some(true);
  20067. },
  20068. onEscape: function(comp) {
  20069. var sandbox = Coupling.getCoupled(comp, "sandbox");
  20070. if (Sandboxing.isOpen(sandbox)) {
  20071. Sandboxing.close(sandbox);
  20072. return Optional.some(true);
  20073. }
  20074. return Optional.none();
  20075. },
  20076. onUp: function(comp, simulatedEvent) {
  20077. navigateList(comp, simulatedEvent, Highlighting.highlightLast);
  20078. return Optional.some(true);
  20079. },
  20080. onEnter: function(comp) {
  20081. var sandbox = Coupling.getCoupled(comp, "sandbox");
  20082. var sandboxIsOpen = Sandboxing.isOpen(sandbox);
  20083. if (sandboxIsOpen && !detail.previewing.get()) {
  20084. return Composing.getCurrent(sandbox).bind(function(menu2) {
  20085. return Highlighting.getHighlighted(menu2);
  20086. }).map(function(item2) {
  20087. emitWith(comp, itemExecute(), { item: item2 });
  20088. return true;
  20089. });
  20090. } else {
  20091. var currentValue2 = Representing.getValue(comp);
  20092. emit(comp, typeaheadCancel());
  20093. detail.onExecute(sandbox, comp, currentValue2);
  20094. if (sandboxIsOpen) {
  20095. Sandboxing.close(sandbox);
  20096. }
  20097. return Optional.some(true);
  20098. }
  20099. }
  20100. }),
  20101. Toggling.config({
  20102. toggleClass: detail.markers.openClass,
  20103. aria: { mode: "expanded" }
  20104. }),
  20105. Coupling.config({
  20106. others: {
  20107. sandbox: function(hotspot) {
  20108. return makeSandbox$1(detail, hotspot, {
  20109. onOpen: function() {
  20110. return Toggling.on(hotspot);
  20111. },
  20112. onClose: function() {
  20113. return Toggling.off(hotspot);
  20114. }
  20115. });
  20116. }
  20117. }
  20118. }),
  20119. config("typeaheadevents", [
  20120. runOnExecute$1(function(comp) {
  20121. var onOpenSync = noop;
  20122. togglePopup(detail, mapFetch(comp), comp, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  20123. }),
  20124. run$1(itemExecute(), function(comp, se) {
  20125. var sandbox = Coupling.getCoupled(comp, "sandbox");
  20126. setValueFromItem(detail.model, comp, se.event.item);
  20127. emit(comp, typeaheadCancel());
  20128. detail.onItemExecute(comp, sandbox, se.event.item, Representing.getValue(comp));
  20129. Sandboxing.close(sandbox);
  20130. setCursorAtEnd(comp);
  20131. })
  20132. ].concat(detail.dismissOnBlur ? [run$1(postBlur(), function(typeahead) {
  20133. var sandbox = Coupling.getCoupled(typeahead, "sandbox");
  20134. if (search(sandbox.element).isNone()) {
  20135. Sandboxing.close(sandbox);
  20136. }
  20137. })] : []))
  20138. ];
  20139. return {
  20140. uid: detail.uid,
  20141. dom: dom(deepMerge(detail, {
  20142. inputAttributes: {
  20143. "role": "combobox",
  20144. "aria-autocomplete": "list",
  20145. "aria-haspopup": "true"
  20146. }
  20147. })),
  20148. behaviours: __assign(__assign({}, focusBehaviours$1), augment(detail.typeaheadBehaviours, behaviours2)),
  20149. eventOrder: detail.eventOrder
  20150. };
  20151. };
  20152. var schema$g = constant$1([
  20153. option("lazySink"),
  20154. required$1("fetch"),
  20155. defaulted("minChars", 5),
  20156. defaulted("responseTime", 1e3),
  20157. onHandler("onOpen"),
  20158. defaulted("getHotspot", Optional.some),
  20159. defaulted("getAnchorOverrides", constant$1({})),
  20160. defaulted("layouts", Optional.none()),
  20161. defaulted("eventOrder", {}),
  20162. defaultedObjOf("model", {}, [
  20163. defaulted("getDisplayText", function(itemData) {
  20164. return itemData.meta !== void 0 && itemData.meta.text !== void 0 ? itemData.meta.text : itemData.value;
  20165. }),
  20166. defaulted("selectsOver", true),
  20167. defaulted("populateFromBrowse", true)
  20168. ]),
  20169. onHandler("onSetValue"),
  20170. onKeyboardHandler("onExecute"),
  20171. onHandler("onItemExecute"),
  20172. defaulted("inputClasses", []),
  20173. defaulted("inputAttributes", {}),
  20174. defaulted("inputStyles", {}),
  20175. defaulted("matchWidth", true),
  20176. defaulted("useMinWidth", false),
  20177. defaulted("dismissOnBlur", true),
  20178. markers$1(["openClass"]),
  20179. option("initialData"),
  20180. field("typeaheadBehaviours", [
  20181. Focusing,
  20182. Representing,
  20183. Streaming,
  20184. Keying,
  20185. Toggling,
  20186. Coupling
  20187. ]),
  20188. customField("previewing", function() {
  20189. return Cell(true);
  20190. })
  20191. ].concat(schema$k()).concat(sandboxFields()));
  20192. var parts$b = constant$1([external$1({
  20193. schema: [tieredMenuMarkers()],
  20194. name: "menu",
  20195. overrides: function(detail) {
  20196. return {
  20197. fakeFocus: true,
  20198. onHighlight: function(menu2, item2) {
  20199. if (!detail.previewing.get()) {
  20200. menu2.getSystem().getByUid(detail.uid).each(function(input2) {
  20201. if (detail.model.populateFromBrowse) {
  20202. setValueFromItem(detail.model, input2, item2);
  20203. }
  20204. });
  20205. } else {
  20206. menu2.getSystem().getByUid(detail.uid).each(function(input2) {
  20207. attemptSelectOver(detail.model, input2, item2).fold(function() {
  20208. return Highlighting.dehighlight(menu2, item2);
  20209. }, function(fn) {
  20210. return fn();
  20211. });
  20212. });
  20213. }
  20214. detail.previewing.set(false);
  20215. },
  20216. onExecute: function(menu2, item2) {
  20217. return menu2.getSystem().getByUid(detail.uid).toOptional().map(function(typeahead) {
  20218. emitWith(typeahead, itemExecute(), { item: item2 });
  20219. return true;
  20220. });
  20221. },
  20222. onHover: function(menu2, item2) {
  20223. detail.previewing.set(false);
  20224. menu2.getSystem().getByUid(detail.uid).each(function(input2) {
  20225. if (detail.model.populateFromBrowse) {
  20226. setValueFromItem(detail.model, input2, item2);
  20227. }
  20228. });
  20229. }
  20230. };
  20231. }
  20232. })]);
  20233. var Typeahead = composite({
  20234. name: "Typeahead",
  20235. configFields: schema$g(),
  20236. partFields: parts$b(),
  20237. factory: make$3
  20238. });
  20239. var wrap = function(delegate) {
  20240. var toCached = function() {
  20241. return wrap(delegate.toCached());
  20242. };
  20243. var bindFuture = function(f) {
  20244. return wrap(delegate.bind(function(resA) {
  20245. return resA.fold(function(err) {
  20246. return Future.pure(Result.error(err));
  20247. }, function(a) {
  20248. return f(a);
  20249. });
  20250. }));
  20251. };
  20252. var bindResult = function(f) {
  20253. return wrap(delegate.map(function(resA) {
  20254. return resA.bind(f);
  20255. }));
  20256. };
  20257. var mapResult = function(f) {
  20258. return wrap(delegate.map(function(resA) {
  20259. return resA.map(f);
  20260. }));
  20261. };
  20262. var mapError2 = function(f) {
  20263. return wrap(delegate.map(function(resA) {
  20264. return resA.mapError(f);
  20265. }));
  20266. };
  20267. var foldResult = function(whenError, whenValue) {
  20268. return delegate.map(function(res) {
  20269. return res.fold(whenError, whenValue);
  20270. });
  20271. };
  20272. var withTimeout = function(timeout, errorThunk) {
  20273. return wrap(Future.nu(function(callback) {
  20274. var timedOut = false;
  20275. var timer = setTimeout(function() {
  20276. timedOut = true;
  20277. callback(Result.error(errorThunk()));
  20278. }, timeout);
  20279. delegate.get(function(result) {
  20280. if (!timedOut) {
  20281. clearTimeout(timer);
  20282. callback(result);
  20283. }
  20284. });
  20285. }));
  20286. };
  20287. return __assign(__assign({}, delegate), {
  20288. toCached,
  20289. bindFuture,
  20290. bindResult,
  20291. mapResult,
  20292. mapError: mapError2,
  20293. foldResult,
  20294. withTimeout
  20295. });
  20296. };
  20297. var nu$1 = function(worker) {
  20298. return wrap(Future.nu(worker));
  20299. };
  20300. var value = function(value2) {
  20301. return wrap(Future.pure(Result.value(value2)));
  20302. };
  20303. var error = function(error2) {
  20304. return wrap(Future.pure(Result.error(error2)));
  20305. };
  20306. var fromResult = function(result) {
  20307. return wrap(Future.pure(result));
  20308. };
  20309. var fromFuture = function(future) {
  20310. return wrap(future.map(Result.value));
  20311. };
  20312. var fromPromise = function(promise) {
  20313. return nu$1(function(completer) {
  20314. promise.then(function(value2) {
  20315. completer(Result.value(value2));
  20316. }, function(error2) {
  20317. completer(Result.error(error2));
  20318. });
  20319. });
  20320. };
  20321. var FutureResult = {
  20322. nu: nu$1,
  20323. wrap,
  20324. pure: value,
  20325. value,
  20326. error,
  20327. fromResult,
  20328. fromFuture,
  20329. fromPromise
  20330. };
  20331. var separator$1 = { type: "separator" };
  20332. var toMenuItem = function(target) {
  20333. return {
  20334. type: "menuitem",
  20335. value: target.url,
  20336. text: target.title,
  20337. meta: { attach: target.attach },
  20338. onAction: noop
  20339. };
  20340. };
  20341. var staticMenuItem = function(title, url) {
  20342. return {
  20343. type: "menuitem",
  20344. value: url,
  20345. text: title,
  20346. meta: { attach: void 0 },
  20347. onAction: noop
  20348. };
  20349. };
  20350. var toMenuItems = function(targets) {
  20351. return map$2(targets, toMenuItem);
  20352. };
  20353. var filterLinkTargets = function(type2, targets) {
  20354. return filter$2(targets, function(target) {
  20355. return target.type === type2;
  20356. });
  20357. };
  20358. var filteredTargets = function(type2, targets) {
  20359. return toMenuItems(filterLinkTargets(type2, targets));
  20360. };
  20361. var headerTargets = function(linkInfo) {
  20362. return filteredTargets("header", linkInfo.targets);
  20363. };
  20364. var anchorTargets = function(linkInfo) {
  20365. return filteredTargets("anchor", linkInfo.targets);
  20366. };
  20367. var anchorTargetTop = function(linkInfo) {
  20368. return Optional.from(linkInfo.anchorTop).map(function(url) {
  20369. return staticMenuItem("<top>", url);
  20370. }).toArray();
  20371. };
  20372. var anchorTargetBottom = function(linkInfo) {
  20373. return Optional.from(linkInfo.anchorBottom).map(function(url) {
  20374. return staticMenuItem("<bottom>", url);
  20375. }).toArray();
  20376. };
  20377. var historyTargets = function(history) {
  20378. return map$2(history, function(url) {
  20379. return staticMenuItem(url, url);
  20380. });
  20381. };
  20382. var joinMenuLists = function(items) {
  20383. return foldl(items, function(a, b2) {
  20384. var bothEmpty = a.length === 0 || b2.length === 0;
  20385. return bothEmpty ? a.concat(b2) : a.concat(separator$1, b2);
  20386. }, []);
  20387. };
  20388. var filterByQuery = function(term, menuItems) {
  20389. var lowerCaseTerm = term.toLowerCase();
  20390. return filter$2(menuItems, function(item2) {
  20391. var text2 = item2.meta !== void 0 && item2.meta.text !== void 0 ? item2.meta.text : item2.text;
  20392. return contains$1(text2.toLowerCase(), lowerCaseTerm) || contains$1(item2.value.toLowerCase(), lowerCaseTerm);
  20393. });
  20394. };
  20395. var getItems = function(fileType, input2, urlBackstage) {
  20396. var urlInputValue = Representing.getValue(input2);
  20397. var term = urlInputValue.meta.text !== void 0 ? urlInputValue.meta.text : urlInputValue.value;
  20398. var info = urlBackstage.getLinkInformation();
  20399. return info.fold(function() {
  20400. return [];
  20401. }, function(linkInfo) {
  20402. var history = filterByQuery(term, historyTargets(urlBackstage.getHistory(fileType)));
  20403. return fileType === "file" ? joinMenuLists([
  20404. history,
  20405. filterByQuery(term, headerTargets(linkInfo)),
  20406. filterByQuery(term, flatten([
  20407. anchorTargetTop(linkInfo),
  20408. anchorTargets(linkInfo),
  20409. anchorTargetBottom(linkInfo)
  20410. ]))
  20411. ]) : history;
  20412. });
  20413. };
  20414. var errorId = generate$6("aria-invalid");
  20415. var renderUrlInput = function(spec, backstage, urlBackstage) {
  20416. var _a2;
  20417. var providersBackstage = backstage.shared.providers;
  20418. var updateHistory = function(component) {
  20419. var urlEntry = Representing.getValue(component);
  20420. urlBackstage.addToHistory(urlEntry.value, spec.filetype);
  20421. };
  20422. var pField = FormField.parts.field({
  20423. factory: Typeahead,
  20424. dismissOnBlur: true,
  20425. inputClasses: ["tox-textfield"],
  20426. sandboxClasses: ["tox-dialog__popups"],
  20427. inputAttributes: {
  20428. "aria-errormessage": errorId,
  20429. "type": "url"
  20430. },
  20431. minChars: 0,
  20432. responseTime: 0,
  20433. fetch: function(input2) {
  20434. var items = getItems(spec.filetype, input2, urlBackstage);
  20435. var tdata = build(items, ItemResponse$1.BUBBLE_TO_SANDBOX, backstage, false);
  20436. return Future.pure(tdata);
  20437. },
  20438. getHotspot: function(comp) {
  20439. return memUrlBox.getOpt(comp);
  20440. },
  20441. onSetValue: function(comp, _newValue) {
  20442. if (comp.hasConfigured(Invalidating)) {
  20443. Invalidating.run(comp).get(noop);
  20444. }
  20445. },
  20446. typeaheadBehaviours: derive$1(flatten([
  20447. urlBackstage.getValidationHandler().map(function(handler) {
  20448. return Invalidating.config({
  20449. getRoot: function(comp) {
  20450. return parent(comp.element);
  20451. },
  20452. invalidClass: "tox-control-wrap--status-invalid",
  20453. notify: {
  20454. onInvalid: function(comp, err) {
  20455. memInvalidIcon.getOpt(comp).each(function(invalidComp) {
  20456. set$8(invalidComp.element, "title", providersBackstage.translate(err));
  20457. });
  20458. }
  20459. },
  20460. validator: {
  20461. validate: function(input2) {
  20462. var urlEntry = Representing.getValue(input2);
  20463. return FutureResult.nu(function(completer) {
  20464. handler({
  20465. type: spec.filetype,
  20466. url: urlEntry.value
  20467. }, function(validation) {
  20468. if (validation.status === "invalid") {
  20469. var err = Result.error(validation.message);
  20470. completer(err);
  20471. } else {
  20472. var val = Result.value(validation.message);
  20473. completer(val);
  20474. }
  20475. });
  20476. });
  20477. },
  20478. validateOnLoad: false
  20479. }
  20480. });
  20481. }).toArray(),
  20482. [
  20483. Disabling.config({
  20484. disabled: function() {
  20485. return spec.disabled || providersBackstage.isDisabled();
  20486. }
  20487. }),
  20488. Tabstopping.config({}),
  20489. config("urlinput-events", flatten([
  20490. spec.filetype === "file" ? [run$1(input(), function(comp) {
  20491. emitWith(comp, formChangeEvent, { name: spec.name });
  20492. })] : [],
  20493. [
  20494. run$1(change(), function(comp) {
  20495. emitWith(comp, formChangeEvent, { name: spec.name });
  20496. updateHistory(comp);
  20497. }),
  20498. run$1(postPaste(), function(comp) {
  20499. emitWith(comp, formChangeEvent, { name: spec.name });
  20500. updateHistory(comp);
  20501. })
  20502. ]
  20503. ]))
  20504. ]
  20505. ])),
  20506. eventOrder: (_a2 = {}, _a2[input()] = [
  20507. "streaming",
  20508. "urlinput-events",
  20509. "invalidating"
  20510. ], _a2),
  20511. model: {
  20512. getDisplayText: function(itemData) {
  20513. return itemData.value;
  20514. },
  20515. selectsOver: false,
  20516. populateFromBrowse: false
  20517. },
  20518. markers: { openClass: "tox-textfield--popup-open" },
  20519. lazySink: backstage.shared.getSink,
  20520. parts: { menu: part(false, 1, "normal") },
  20521. onExecute: function(_menu, component, _entry) {
  20522. emitWith(component, formSubmitEvent, {});
  20523. },
  20524. onItemExecute: function(typeahead, _sandbox, _item, _value) {
  20525. updateHistory(typeahead);
  20526. emitWith(typeahead, formChangeEvent, { name: spec.name });
  20527. }
  20528. });
  20529. var pLabel = spec.label.map(function(label) {
  20530. return renderLabel$2(label, providersBackstage);
  20531. });
  20532. var makeIcon = function(name2, errId, icon, label) {
  20533. if (icon === void 0) {
  20534. icon = name2;
  20535. }
  20536. if (label === void 0) {
  20537. label = name2;
  20538. }
  20539. return render$3(icon, {
  20540. tag: "div",
  20541. classes: [
  20542. "tox-icon",
  20543. "tox-control-wrap__status-icon-" + name2
  20544. ],
  20545. attributes: __assign({
  20546. "title": providersBackstage.translate(label),
  20547. "aria-live": "polite"
  20548. }, errId.fold(function() {
  20549. return {};
  20550. }, function(id) {
  20551. return { id };
  20552. }))
  20553. }, providersBackstage.icons);
  20554. };
  20555. var memInvalidIcon = record(makeIcon("invalid", Optional.some(errorId), "warning"));
  20556. var memStatus = record({
  20557. dom: {
  20558. tag: "div",
  20559. classes: ["tox-control-wrap__status-icon-wrap"]
  20560. },
  20561. components: [memInvalidIcon.asSpec()]
  20562. });
  20563. var optUrlPicker = urlBackstage.getUrlPicker(spec.filetype);
  20564. var browseUrlEvent = generate$6("browser.url.event");
  20565. var memUrlBox = record({
  20566. dom: {
  20567. tag: "div",
  20568. classes: ["tox-control-wrap"]
  20569. },
  20570. components: [
  20571. pField,
  20572. memStatus.asSpec()
  20573. ],
  20574. behaviours: derive$1([Disabling.config({
  20575. disabled: function() {
  20576. return spec.disabled || providersBackstage.isDisabled();
  20577. }
  20578. })])
  20579. });
  20580. var memUrlPickerButton = record(renderButton({
  20581. name: spec.name,
  20582. icon: Optional.some("browse"),
  20583. text: spec.label.getOr(""),
  20584. disabled: spec.disabled,
  20585. primary: false,
  20586. borderless: true
  20587. }, function(component) {
  20588. return emit(component, browseUrlEvent);
  20589. }, providersBackstage, [], ["tox-browse-url"]));
  20590. var controlHWrapper = function() {
  20591. return {
  20592. dom: {
  20593. tag: "div",
  20594. classes: ["tox-form__controls-h-stack"]
  20595. },
  20596. components: flatten([
  20597. [memUrlBox.asSpec()],
  20598. optUrlPicker.map(function() {
  20599. return memUrlPickerButton.asSpec();
  20600. }).toArray()
  20601. ])
  20602. };
  20603. };
  20604. var openUrlPicker = function(comp) {
  20605. Composing.getCurrent(comp).each(function(field2) {
  20606. var componentData = Representing.getValue(field2);
  20607. var urlData = __assign({ fieldname: spec.name }, componentData);
  20608. optUrlPicker.each(function(picker) {
  20609. picker(urlData).get(function(chosenData) {
  20610. Representing.setValue(field2, chosenData);
  20611. emitWith(comp, formChangeEvent, { name: spec.name });
  20612. });
  20613. });
  20614. });
  20615. };
  20616. return FormField.sketch({
  20617. dom: renderFormFieldDom(),
  20618. components: pLabel.toArray().concat([controlHWrapper()]),
  20619. fieldBehaviours: derive$1([
  20620. Disabling.config({
  20621. disabled: function() {
  20622. return spec.disabled || providersBackstage.isDisabled();
  20623. },
  20624. onDisabled: function(comp) {
  20625. FormField.getField(comp).each(Disabling.disable);
  20626. memUrlPickerButton.getOpt(comp).each(Disabling.disable);
  20627. },
  20628. onEnabled: function(comp) {
  20629. FormField.getField(comp).each(Disabling.enable);
  20630. memUrlPickerButton.getOpt(comp).each(Disabling.enable);
  20631. }
  20632. }),
  20633. receivingConfig(),
  20634. config("url-input-events", [run$1(browseUrlEvent, openUrlPicker)])
  20635. ])
  20636. });
  20637. };
  20638. var renderAlertBanner = function(spec, providersBackstage) {
  20639. return Container.sketch({
  20640. dom: {
  20641. tag: "div",
  20642. attributes: { role: "alert" },
  20643. classes: [
  20644. "tox-notification",
  20645. "tox-notification--in",
  20646. "tox-notification--" + spec.level
  20647. ]
  20648. },
  20649. components: [
  20650. {
  20651. dom: {
  20652. tag: "div",
  20653. classes: ["tox-notification__icon"]
  20654. },
  20655. components: [Button.sketch({
  20656. dom: {
  20657. tag: "button",
  20658. classes: [
  20659. "tox-button",
  20660. "tox-button--naked",
  20661. "tox-button--icon"
  20662. ],
  20663. innerHtml: get$1(spec.icon, providersBackstage.icons),
  20664. attributes: { title: providersBackstage.translate(spec.iconTooltip) }
  20665. },
  20666. action: function(comp) {
  20667. emitWith(comp, formActionEvent, {
  20668. name: "alert-banner",
  20669. value: spec.url
  20670. });
  20671. },
  20672. buttonBehaviours: derive$1([addFocusableBehaviour()])
  20673. })]
  20674. },
  20675. {
  20676. dom: {
  20677. tag: "div",
  20678. classes: ["tox-notification__body"],
  20679. innerHtml: providersBackstage.translate(spec.text)
  20680. }
  20681. }
  20682. ]
  20683. });
  20684. };
  20685. var renderCheckbox = function(spec, providerBackstage) {
  20686. var repBehaviour = Representing.config({
  20687. store: {
  20688. mode: "manual",
  20689. getValue: function(comp) {
  20690. var el = comp.element.dom;
  20691. return el.checked;
  20692. },
  20693. setValue: function(comp, value2) {
  20694. var el = comp.element.dom;
  20695. el.checked = value2;
  20696. }
  20697. }
  20698. });
  20699. var toggleCheckboxHandler = function(comp) {
  20700. comp.element.dom.click();
  20701. return Optional.some(true);
  20702. };
  20703. var pField = FormField.parts.field({
  20704. factory: { sketch: identity$1 },
  20705. dom: {
  20706. tag: "input",
  20707. classes: ["tox-checkbox__input"],
  20708. attributes: { type: "checkbox" }
  20709. },
  20710. behaviours: derive$1([
  20711. ComposingConfigs.self(),
  20712. Disabling.config({
  20713. disabled: function() {
  20714. return spec.disabled || providerBackstage.isDisabled();
  20715. }
  20716. }),
  20717. Tabstopping.config({}),
  20718. Focusing.config({}),
  20719. repBehaviour,
  20720. Keying.config({
  20721. mode: "special",
  20722. onEnter: toggleCheckboxHandler,
  20723. onSpace: toggleCheckboxHandler,
  20724. stopSpaceKeyup: true
  20725. }),
  20726. config("checkbox-events", [run$1(change(), function(component, _) {
  20727. emitWith(component, formChangeEvent, { name: spec.name });
  20728. })])
  20729. ])
  20730. });
  20731. var pLabel = FormField.parts.label({
  20732. dom: {
  20733. tag: "span",
  20734. classes: ["tox-checkbox__label"],
  20735. innerHtml: providerBackstage.translate(spec.label)
  20736. },
  20737. behaviours: derive$1([Unselecting.config({})])
  20738. });
  20739. var makeIcon = function(className) {
  20740. var iconName = className === "checked" ? "selected" : "unselected";
  20741. return render$3(iconName, {
  20742. tag: "span",
  20743. classes: [
  20744. "tox-icon",
  20745. "tox-checkbox-icon__" + className
  20746. ]
  20747. }, providerBackstage.icons);
  20748. };
  20749. var memIcons = record({
  20750. dom: {
  20751. tag: "div",
  20752. classes: ["tox-checkbox__icons"]
  20753. },
  20754. components: [
  20755. makeIcon("checked"),
  20756. makeIcon("unchecked")
  20757. ]
  20758. });
  20759. return FormField.sketch({
  20760. dom: {
  20761. tag: "label",
  20762. classes: ["tox-checkbox"]
  20763. },
  20764. components: [
  20765. pField,
  20766. memIcons.asSpec(),
  20767. pLabel
  20768. ],
  20769. fieldBehaviours: derive$1([
  20770. Disabling.config({
  20771. disabled: function() {
  20772. return spec.disabled || providerBackstage.isDisabled();
  20773. },
  20774. disableClass: "tox-checkbox--disabled",
  20775. onDisabled: function(comp) {
  20776. FormField.getField(comp).each(Disabling.disable);
  20777. },
  20778. onEnabled: function(comp) {
  20779. FormField.getField(comp).each(Disabling.enable);
  20780. }
  20781. }),
  20782. receivingConfig()
  20783. ])
  20784. });
  20785. };
  20786. var renderHtmlPanel = function(spec) {
  20787. if (spec.presets === "presentation") {
  20788. return Container.sketch({
  20789. dom: {
  20790. tag: "div",
  20791. classes: ["tox-form__group"],
  20792. innerHtml: spec.html
  20793. }
  20794. });
  20795. } else {
  20796. return Container.sketch({
  20797. dom: {
  20798. tag: "div",
  20799. classes: ["tox-form__group"],
  20800. innerHtml: spec.html,
  20801. attributes: { role: "document" }
  20802. },
  20803. containerBehaviours: derive$1([
  20804. Tabstopping.config({}),
  20805. Focusing.config({})
  20806. ])
  20807. });
  20808. }
  20809. };
  20810. var make$2 = function(render2) {
  20811. return function(parts2, spec, backstage) {
  20812. return get$e(spec, "name").fold(function() {
  20813. return render2(spec, backstage);
  20814. }, function(fieldName) {
  20815. return parts2.field(fieldName, render2(spec, backstage));
  20816. });
  20817. };
  20818. };
  20819. var makeIframe = function(render2) {
  20820. return function(parts2, spec, backstage) {
  20821. var iframeSpec = deepMerge(spec, { source: "dynamic" });
  20822. return make$2(render2)(parts2, iframeSpec, backstage);
  20823. };
  20824. };
  20825. var factories = {
  20826. bar: make$2(function(spec, backstage) {
  20827. return renderBar(spec, backstage.shared);
  20828. }),
  20829. collection: make$2(function(spec, backstage) {
  20830. return renderCollection(spec, backstage.shared.providers);
  20831. }),
  20832. alertbanner: make$2(function(spec, backstage) {
  20833. return renderAlertBanner(spec, backstage.shared.providers);
  20834. }),
  20835. input: make$2(function(spec, backstage) {
  20836. return renderInput(spec, backstage.shared.providers);
  20837. }),
  20838. textarea: make$2(function(spec, backstage) {
  20839. return renderTextarea(spec, backstage.shared.providers);
  20840. }),
  20841. label: make$2(function(spec, backstage) {
  20842. return renderLabel(spec, backstage.shared);
  20843. }),
  20844. iframe: makeIframe(function(spec, backstage) {
  20845. return renderIFrame(spec, backstage.shared.providers);
  20846. }),
  20847. button: make$2(function(spec, backstage) {
  20848. return renderDialogButton(spec, backstage.shared.providers);
  20849. }),
  20850. checkbox: make$2(function(spec, backstage) {
  20851. return renderCheckbox(spec, backstage.shared.providers);
  20852. }),
  20853. colorinput: make$2(function(spec, backstage) {
  20854. return renderColorInput(spec, backstage.shared, backstage.colorinput);
  20855. }),
  20856. colorpicker: make$2(renderColorPicker),
  20857. dropzone: make$2(function(spec, backstage) {
  20858. return renderDropZone(spec, backstage.shared.providers);
  20859. }),
  20860. grid: make$2(function(spec, backstage) {
  20861. return renderGrid(spec, backstage.shared);
  20862. }),
  20863. listbox: make$2(function(spec, backstage) {
  20864. return renderListBox(spec, backstage);
  20865. }),
  20866. selectbox: make$2(function(spec, backstage) {
  20867. return renderSelectBox(spec, backstage.shared.providers);
  20868. }),
  20869. sizeinput: make$2(function(spec, backstage) {
  20870. return renderSizeInput(spec, backstage.shared.providers);
  20871. }),
  20872. urlinput: make$2(function(spec, backstage) {
  20873. return renderUrlInput(spec, backstage, backstage.urlinput);
  20874. }),
  20875. customeditor: make$2(renderCustomEditor),
  20876. htmlpanel: make$2(renderHtmlPanel),
  20877. imagetools: make$2(function(spec, backstage) {
  20878. return renderImageTools(spec, backstage.shared.providers);
  20879. }),
  20880. table: make$2(function(spec, backstage) {
  20881. return renderTable(spec, backstage.shared.providers);
  20882. }),
  20883. panel: make$2(function(spec, backstage) {
  20884. return renderPanel(spec, backstage);
  20885. })
  20886. };
  20887. var noFormParts = {
  20888. field: function(_name, spec) {
  20889. return spec;
  20890. }
  20891. };
  20892. var interpretInForm = function(parts2, spec, oldBackstage) {
  20893. var newBackstage = deepMerge(oldBackstage, {
  20894. shared: {
  20895. interpreter: function(childSpec) {
  20896. return interpretParts(parts2, childSpec, newBackstage);
  20897. }
  20898. }
  20899. });
  20900. return interpretParts(parts2, spec, newBackstage);
  20901. };
  20902. var interpretParts = function(parts2, spec, backstage) {
  20903. return get$e(factories, spec.type).fold(function() {
  20904. console.error('Unknown factory type "' + spec.type + '", defaulting to container: ', spec);
  20905. return spec;
  20906. }, function(factory2) {
  20907. return factory2(parts2, spec, backstage);
  20908. });
  20909. };
  20910. var interpretWithoutForm = function(spec, backstage) {
  20911. var parts2 = noFormParts;
  20912. return interpretParts(parts2, spec, backstage);
  20913. };
  20914. var bubbleAlignments$2 = {
  20915. valignCentre: [],
  20916. alignCentre: [],
  20917. alignLeft: [],
  20918. alignRight: [],
  20919. right: [],
  20920. left: [],
  20921. bottom: [],
  20922. top: []
  20923. };
  20924. var getInlineDialogAnchor = function(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor) {
  20925. var bubbleSize2 = 12;
  20926. var overrides = { maxHeightFunction: expandable$1() };
  20927. var editableAreaAnchor = function() {
  20928. return {
  20929. type: "node",
  20930. root: getContentContainer(contentAreaElement()),
  20931. node: Optional.from(contentAreaElement()),
  20932. bubble: nu$5(bubbleSize2, bubbleSize2, bubbleAlignments$2),
  20933. layouts: {
  20934. onRtl: function() {
  20935. return [northeast];
  20936. },
  20937. onLtr: function() {
  20938. return [northwest];
  20939. }
  20940. },
  20941. overrides
  20942. };
  20943. };
  20944. var standardAnchor = function() {
  20945. return {
  20946. type: "hotspot",
  20947. hotspot: lazyAnchorbar(),
  20948. bubble: nu$5(-bubbleSize2, bubbleSize2, bubbleAlignments$2),
  20949. layouts: {
  20950. onRtl: function() {
  20951. return [southeast$2];
  20952. },
  20953. onLtr: function() {
  20954. return [southwest$2];
  20955. }
  20956. },
  20957. overrides
  20958. };
  20959. };
  20960. return function() {
  20961. return lazyUseEditableAreaAnchor() ? editableAreaAnchor() : standardAnchor();
  20962. };
  20963. };
  20964. var getBannerAnchor = function(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor) {
  20965. var editableAreaAnchor = function() {
  20966. return {
  20967. type: "node",
  20968. root: getContentContainer(contentAreaElement()),
  20969. node: Optional.from(contentAreaElement()),
  20970. layouts: {
  20971. onRtl: function() {
  20972. return [north];
  20973. },
  20974. onLtr: function() {
  20975. return [north];
  20976. }
  20977. }
  20978. };
  20979. };
  20980. var standardAnchor = function() {
  20981. return {
  20982. type: "hotspot",
  20983. hotspot: lazyAnchorbar(),
  20984. layouts: {
  20985. onRtl: function() {
  20986. return [south$2];
  20987. },
  20988. onLtr: function() {
  20989. return [south$2];
  20990. }
  20991. }
  20992. };
  20993. };
  20994. return function() {
  20995. return lazyUseEditableAreaAnchor() ? editableAreaAnchor() : standardAnchor();
  20996. };
  20997. };
  20998. var getCursorAnchor = function(editor, bodyElement) {
  20999. return function() {
  21000. return {
  21001. type: "selection",
  21002. root: bodyElement(),
  21003. getSelection: function() {
  21004. var rng = editor.selection.getRng();
  21005. return Optional.some(SimSelection.range(SugarElement.fromDom(rng.startContainer), rng.startOffset, SugarElement.fromDom(rng.endContainer), rng.endOffset));
  21006. }
  21007. };
  21008. };
  21009. };
  21010. var getNodeAnchor$1 = function(bodyElement) {
  21011. return function(element2) {
  21012. return {
  21013. type: "node",
  21014. root: bodyElement(),
  21015. node: element2
  21016. };
  21017. };
  21018. };
  21019. var getAnchors = function(editor, lazyAnchorbar, isToolbarTop) {
  21020. var useFixedToolbarContainer = useFixedContainer(editor);
  21021. var bodyElement = function() {
  21022. return SugarElement.fromDom(editor.getBody());
  21023. };
  21024. var contentAreaElement = function() {
  21025. return SugarElement.fromDom(editor.getContentAreaContainer());
  21026. };
  21027. var lazyUseEditableAreaAnchor = function() {
  21028. return useFixedToolbarContainer || !isToolbarTop();
  21029. };
  21030. return {
  21031. inlineDialog: getInlineDialogAnchor(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor),
  21032. banner: getBannerAnchor(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor),
  21033. cursor: getCursorAnchor(editor, bodyElement),
  21034. node: getNodeAnchor$1(bodyElement)
  21035. };
  21036. };
  21037. var colorPicker = function(editor) {
  21038. return function(callback, value2) {
  21039. var dialog = colorPickerDialog(editor);
  21040. dialog(callback, value2);
  21041. };
  21042. };
  21043. var hasCustomColors = function(editor) {
  21044. return function() {
  21045. return hasCustomColors$1(editor);
  21046. };
  21047. };
  21048. var getColors = function(editor) {
  21049. return function() {
  21050. return getColors$2(editor);
  21051. };
  21052. };
  21053. var getColorCols = function(editor) {
  21054. return function() {
  21055. return getColorCols$1(editor);
  21056. };
  21057. };
  21058. var ColorInputBackstage = function(editor) {
  21059. return {
  21060. colorPicker: colorPicker(editor),
  21061. hasCustomColors: hasCustomColors(editor),
  21062. getColors: getColors(editor),
  21063. getColorCols: getColorCols(editor)
  21064. };
  21065. };
  21066. var isDraggableModal = function(editor) {
  21067. return function() {
  21068. return isDraggableModal$1(editor);
  21069. };
  21070. };
  21071. var DialogBackstage = function(editor) {
  21072. return { isDraggableModal: isDraggableModal(editor) };
  21073. };
  21074. var HeaderBackstage = function(editor) {
  21075. var mode = Cell(isToolbarLocationBottom(editor) ? "bottom" : "top");
  21076. return {
  21077. isPositionedAtTop: function() {
  21078. return mode.get() === "top";
  21079. },
  21080. getDockingMode: mode.get,
  21081. setDockingMode: mode.set
  21082. };
  21083. };
  21084. var defaultStyleFormats = [
  21085. {
  21086. title: "Headings",
  21087. items: [
  21088. {
  21089. title: "Heading 1",
  21090. format: "h1"
  21091. },
  21092. {
  21093. title: "Heading 2",
  21094. format: "h2"
  21095. },
  21096. {
  21097. title: "Heading 3",
  21098. format: "h3"
  21099. },
  21100. {
  21101. title: "Heading 4",
  21102. format: "h4"
  21103. },
  21104. {
  21105. title: "Heading 5",
  21106. format: "h5"
  21107. },
  21108. {
  21109. title: "Heading 6",
  21110. format: "h6"
  21111. }
  21112. ]
  21113. },
  21114. {
  21115. title: "Inline",
  21116. items: [
  21117. {
  21118. title: "Bold",
  21119. format: "bold"
  21120. },
  21121. {
  21122. title: "Italic",
  21123. format: "italic"
  21124. },
  21125. {
  21126. title: "Underline",
  21127. format: "underline"
  21128. },
  21129. {
  21130. title: "Strikethrough",
  21131. format: "strikethrough"
  21132. },
  21133. {
  21134. title: "Superscript",
  21135. format: "superscript"
  21136. },
  21137. {
  21138. title: "Subscript",
  21139. format: "subscript"
  21140. },
  21141. {
  21142. title: "Code",
  21143. format: "code"
  21144. }
  21145. ]
  21146. },
  21147. {
  21148. title: "Blocks",
  21149. items: [
  21150. {
  21151. title: "Paragraph",
  21152. format: "p"
  21153. },
  21154. {
  21155. title: "Blockquote",
  21156. format: "blockquote"
  21157. },
  21158. {
  21159. title: "Div",
  21160. format: "div"
  21161. },
  21162. {
  21163. title: "Pre",
  21164. format: "pre"
  21165. }
  21166. ]
  21167. },
  21168. {
  21169. title: "Align",
  21170. items: [
  21171. {
  21172. title: "Left",
  21173. format: "alignleft"
  21174. },
  21175. {
  21176. title: "Center",
  21177. format: "aligncenter"
  21178. },
  21179. {
  21180. title: "Right",
  21181. format: "alignright"
  21182. },
  21183. {
  21184. title: "Justify",
  21185. format: "alignjustify"
  21186. }
  21187. ]
  21188. }
  21189. ];
  21190. var isNestedFormat = function(format) {
  21191. return has$2(format, "items");
  21192. };
  21193. var isBlockFormat = function(format) {
  21194. return has$2(format, "block");
  21195. };
  21196. var isInlineFormat = function(format) {
  21197. return has$2(format, "inline");
  21198. };
  21199. var isSelectorFormat = function(format) {
  21200. return has$2(format, "selector");
  21201. };
  21202. var mapFormats = function(userFormats) {
  21203. return foldl(userFormats, function(acc, fmt) {
  21204. if (isNestedFormat(fmt)) {
  21205. var result = mapFormats(fmt.items);
  21206. return {
  21207. customFormats: acc.customFormats.concat(result.customFormats),
  21208. formats: acc.formats.concat([{
  21209. title: fmt.title,
  21210. items: result.formats
  21211. }])
  21212. };
  21213. } else if (isInlineFormat(fmt) || isBlockFormat(fmt) || isSelectorFormat(fmt)) {
  21214. var formatName = isString(fmt.name) ? fmt.name : fmt.title.toLowerCase();
  21215. var formatNameWithPrefix = "custom-" + formatName;
  21216. return {
  21217. customFormats: acc.customFormats.concat([{
  21218. name: formatNameWithPrefix,
  21219. format: fmt
  21220. }]),
  21221. formats: acc.formats.concat([{
  21222. title: fmt.title,
  21223. format: formatNameWithPrefix,
  21224. icon: fmt.icon
  21225. }])
  21226. };
  21227. } else {
  21228. return __assign(__assign({}, acc), { formats: acc.formats.concat(fmt) });
  21229. }
  21230. }, {
  21231. customFormats: [],
  21232. formats: []
  21233. });
  21234. };
  21235. var registerCustomFormats = function(editor, userFormats) {
  21236. var result = mapFormats(userFormats);
  21237. var registerFormats = function(customFormats) {
  21238. each$1(customFormats, function(fmt) {
  21239. if (!editor.formatter.has(fmt.name)) {
  21240. editor.formatter.register(fmt.name, fmt.format);
  21241. }
  21242. });
  21243. };
  21244. if (editor.formatter) {
  21245. registerFormats(result.customFormats);
  21246. } else {
  21247. editor.on("init", function() {
  21248. registerFormats(result.customFormats);
  21249. });
  21250. }
  21251. return result.formats;
  21252. };
  21253. var getStyleFormats = function(editor) {
  21254. return getUserStyleFormats(editor).map(function(userFormats) {
  21255. var registeredUserFormats = registerCustomFormats(editor, userFormats);
  21256. return isMergeStyleFormats(editor) ? defaultStyleFormats.concat(registeredUserFormats) : registeredUserFormats;
  21257. }).getOr(defaultStyleFormats);
  21258. };
  21259. var processBasic = function(item2, isSelectedFor, getPreviewFor) {
  21260. var formatterSpec = {
  21261. type: "formatter",
  21262. isSelected: isSelectedFor(item2.format),
  21263. getStylePreview: getPreviewFor(item2.format)
  21264. };
  21265. return deepMerge(item2, formatterSpec);
  21266. };
  21267. var register$8 = function(editor, formats, isSelectedFor, getPreviewFor) {
  21268. var enrichSupported = function(item2) {
  21269. return processBasic(item2, isSelectedFor, getPreviewFor);
  21270. };
  21271. var enrichMenu = function(item2) {
  21272. var submenuSpec = { type: "submenu" };
  21273. return deepMerge(item2, submenuSpec);
  21274. };
  21275. var enrichCustom = function(item2) {
  21276. var formatName = isString(item2.name) ? item2.name : generate$6(item2.title);
  21277. var formatNameWithPrefix = "custom-" + formatName;
  21278. var customSpec = {
  21279. type: "formatter",
  21280. format: formatNameWithPrefix,
  21281. isSelected: isSelectedFor(formatNameWithPrefix),
  21282. getStylePreview: getPreviewFor(formatNameWithPrefix)
  21283. };
  21284. var newItem = deepMerge(item2, customSpec);
  21285. editor.formatter.register(formatName, newItem);
  21286. return newItem;
  21287. };
  21288. var doEnrich = function(items) {
  21289. return map$2(items, function(item2) {
  21290. var keys$1 = keys(item2);
  21291. if (hasNonNullableKey(item2, "items")) {
  21292. var newItems = doEnrich(item2.items);
  21293. return deepMerge(enrichMenu(item2), { getStyleItems: constant$1(newItems) });
  21294. } else if (hasNonNullableKey(item2, "format")) {
  21295. return enrichSupported(item2);
  21296. } else if (keys$1.length === 1 && contains$2(keys$1, "title")) {
  21297. return deepMerge(item2, { type: "separator" });
  21298. } else {
  21299. return enrichCustom(item2);
  21300. }
  21301. });
  21302. };
  21303. return doEnrich(formats);
  21304. };
  21305. var init$8 = function(editor) {
  21306. var isSelectedFor = function(format) {
  21307. return function() {
  21308. return editor.formatter.match(format);
  21309. };
  21310. };
  21311. var getPreviewFor = function(format) {
  21312. return function() {
  21313. var fmt = editor.formatter.get(format);
  21314. return fmt !== void 0 ? Optional.some({
  21315. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || "div" : "div",
  21316. styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
  21317. }) : Optional.none();
  21318. };
  21319. };
  21320. var flatten2 = function(fmt) {
  21321. var subs2 = fmt.items;
  21322. return subs2 !== void 0 && subs2.length > 0 ? bind$3(subs2, flatten2) : [fmt.format];
  21323. };
  21324. var settingsFormats = Cell([]);
  21325. var settingsFlattenedFormats = Cell([]);
  21326. var eventsFormats = Cell([]);
  21327. var eventsFlattenedFormats = Cell([]);
  21328. var replaceSettings = Cell(false);
  21329. editor.on("PreInit", function(_e) {
  21330. var formats = getStyleFormats(editor);
  21331. var enriched = register$8(editor, formats, isSelectedFor, getPreviewFor);
  21332. settingsFormats.set(enriched);
  21333. settingsFlattenedFormats.set(bind$3(enriched, flatten2));
  21334. });
  21335. editor.on("addStyleModifications", function(e) {
  21336. var modifications = register$8(editor, e.items, isSelectedFor, getPreviewFor);
  21337. eventsFormats.set(modifications);
  21338. replaceSettings.set(e.replace);
  21339. eventsFlattenedFormats.set(bind$3(modifications, flatten2));
  21340. });
  21341. var getData2 = function() {
  21342. var fromSettings = replaceSettings.get() ? [] : settingsFormats.get();
  21343. var fromEvents = eventsFormats.get();
  21344. return fromSettings.concat(fromEvents);
  21345. };
  21346. var getFlattenedKeys = function() {
  21347. var fromSettings = replaceSettings.get() ? [] : settingsFlattenedFormats.get();
  21348. var fromEvents = eventsFlattenedFormats.get();
  21349. return fromSettings.concat(fromEvents);
  21350. };
  21351. return {
  21352. getData: getData2,
  21353. getFlattenedKeys
  21354. };
  21355. };
  21356. var isElement = function(node) {
  21357. return isNonNullable(node) && node.nodeType === 1;
  21358. };
  21359. var trim = global$5.trim;
  21360. var hasContentEditableState = function(value2) {
  21361. return function(node) {
  21362. if (isElement(node)) {
  21363. if (node.contentEditable === value2) {
  21364. return true;
  21365. }
  21366. if (node.getAttribute("data-mce-contenteditable") === value2) {
  21367. return true;
  21368. }
  21369. }
  21370. return false;
  21371. };
  21372. };
  21373. var isContentEditableTrue = hasContentEditableState("true");
  21374. var isContentEditableFalse = hasContentEditableState("false");
  21375. var create$1 = function(type2, title, url, level, attach2) {
  21376. return {
  21377. type: type2,
  21378. title,
  21379. url,
  21380. level,
  21381. attach: attach2
  21382. };
  21383. };
  21384. var isChildOfContentEditableTrue = function(node) {
  21385. while (node = node.parentNode) {
  21386. var value2 = node.contentEditable;
  21387. if (value2 && value2 !== "inherit") {
  21388. return isContentEditableTrue(node);
  21389. }
  21390. }
  21391. return false;
  21392. };
  21393. var select = function(selector, root) {
  21394. return map$2(descendants(SugarElement.fromDom(root), selector), function(element2) {
  21395. return element2.dom;
  21396. });
  21397. };
  21398. var getElementText = function(elm) {
  21399. return elm.innerText || elm.textContent;
  21400. };
  21401. var getOrGenerateId = function(elm) {
  21402. return elm.id ? elm.id : generate$6("h");
  21403. };
  21404. var isAnchor = function(elm) {
  21405. return elm && elm.nodeName === "A" && (elm.id || elm.name) !== void 0;
  21406. };
  21407. var isValidAnchor = function(elm) {
  21408. return isAnchor(elm) && isEditable(elm);
  21409. };
  21410. var isHeader = function(elm) {
  21411. return elm && /^(H[1-6])$/.test(elm.nodeName);
  21412. };
  21413. var isEditable = function(elm) {
  21414. return isChildOfContentEditableTrue(elm) && !isContentEditableFalse(elm);
  21415. };
  21416. var isValidHeader = function(elm) {
  21417. return isHeader(elm) && isEditable(elm);
  21418. };
  21419. var getLevel = function(elm) {
  21420. return isHeader(elm) ? parseInt(elm.nodeName.substr(1), 10) : 0;
  21421. };
  21422. var headerTarget = function(elm) {
  21423. var headerId = getOrGenerateId(elm);
  21424. var attach2 = function() {
  21425. elm.id = headerId;
  21426. };
  21427. return create$1("header", getElementText(elm), "#" + headerId, getLevel(elm), attach2);
  21428. };
  21429. var anchorTarget = function(elm) {
  21430. var anchorId = elm.id || elm.name;
  21431. var anchorText = getElementText(elm);
  21432. return create$1("anchor", anchorText ? anchorText : "#" + anchorId, "#" + anchorId, 0, noop);
  21433. };
  21434. var getHeaderTargets = function(elms) {
  21435. return map$2(filter$2(elms, isValidHeader), headerTarget);
  21436. };
  21437. var getAnchorTargets = function(elms) {
  21438. return map$2(filter$2(elms, isValidAnchor), anchorTarget);
  21439. };
  21440. var getTargetElements = function(elm) {
  21441. var elms = select("h1,h2,h3,h4,h5,h6,a:not([href])", elm);
  21442. return elms;
  21443. };
  21444. var hasTitle = function(target) {
  21445. return trim(target.title).length > 0;
  21446. };
  21447. var find = function(elm) {
  21448. var elms = getTargetElements(elm);
  21449. return filter$2(getHeaderTargets(elms).concat(getAnchorTargets(elms)), hasTitle);
  21450. };
  21451. var LinkTargets = { find };
  21452. var STORAGE_KEY = "tinymce-url-history";
  21453. var HISTORY_LENGTH = 5;
  21454. var isHttpUrl = function(url) {
  21455. return isString(url) && /^https?/.test(url);
  21456. };
  21457. var isArrayOfUrl = function(a) {
  21458. return isArray(a) && a.length <= HISTORY_LENGTH && forall(a, isHttpUrl);
  21459. };
  21460. var isRecordOfUrlArray = function(r2) {
  21461. return isObject(r2) && find$4(r2, function(value2) {
  21462. return !isArrayOfUrl(value2);
  21463. }).isNone();
  21464. };
  21465. var getAllHistory = function() {
  21466. var unparsedHistory = global$8.getItem(STORAGE_KEY);
  21467. if (unparsedHistory === null) {
  21468. return {};
  21469. }
  21470. var history;
  21471. try {
  21472. history = JSON.parse(unparsedHistory);
  21473. } catch (e) {
  21474. if (e instanceof SyntaxError) {
  21475. console.log("Local storage " + STORAGE_KEY + " was not valid JSON", e);
  21476. return {};
  21477. }
  21478. throw e;
  21479. }
  21480. if (!isRecordOfUrlArray(history)) {
  21481. console.log("Local storage " + STORAGE_KEY + " was not valid format", history);
  21482. return {};
  21483. }
  21484. return history;
  21485. };
  21486. var setAllHistory = function(history) {
  21487. if (!isRecordOfUrlArray(history)) {
  21488. throw new Error("Bad format for history:\n" + JSON.stringify(history));
  21489. }
  21490. global$8.setItem(STORAGE_KEY, JSON.stringify(history));
  21491. };
  21492. var getHistory = function(fileType) {
  21493. var history = getAllHistory();
  21494. return get$e(history, fileType).getOr([]);
  21495. };
  21496. var addToHistory = function(url, fileType) {
  21497. if (!isHttpUrl(url)) {
  21498. return;
  21499. }
  21500. var history = getAllHistory();
  21501. var items = get$e(history, fileType).getOr([]);
  21502. var itemsWithoutUrl = filter$2(items, function(item2) {
  21503. return item2 !== url;
  21504. });
  21505. history[fileType] = [url].concat(itemsWithoutUrl).slice(0, HISTORY_LENGTH);
  21506. setAllHistory(history);
  21507. };
  21508. var isTruthy = function(value2) {
  21509. return !!value2;
  21510. };
  21511. var makeMap = function(value2) {
  21512. return map$1(global$5.makeMap(value2, /[, ]/), isTruthy);
  21513. };
  21514. var getPicker = function(editor) {
  21515. return Optional.from(getFilePickerCallback(editor)).filter(isFunction);
  21516. };
  21517. var getPickerTypes = function(editor) {
  21518. var optFileTypes = Optional.some(getFilePickerTypes(editor)).filter(isTruthy);
  21519. var optLegacyTypes = Optional.some(getFileBrowserCallbackTypes(editor)).filter(isTruthy);
  21520. var optTypes = optFileTypes.or(optLegacyTypes).map(makeMap);
  21521. return getPicker(editor).fold(never, function(_picker) {
  21522. return optTypes.fold(always, function(types2) {
  21523. return keys(types2).length > 0 ? types2 : false;
  21524. });
  21525. });
  21526. };
  21527. var getPickerSetting = function(editor, filetype) {
  21528. var pickerTypes = getPickerTypes(editor);
  21529. if (isBoolean(pickerTypes)) {
  21530. return pickerTypes ? getPicker(editor) : Optional.none();
  21531. } else {
  21532. return pickerTypes[filetype] ? getPicker(editor) : Optional.none();
  21533. }
  21534. };
  21535. var getUrlPicker = function(editor, filetype) {
  21536. return getPickerSetting(editor, filetype).map(function(picker) {
  21537. return function(entry) {
  21538. return Future.nu(function(completer) {
  21539. var handler = function(value2, meta2) {
  21540. if (!isString(value2)) {
  21541. throw new Error("Expected value to be string");
  21542. }
  21543. if (meta2 !== void 0 && !isObject(meta2)) {
  21544. throw new Error("Expected meta to be a object");
  21545. }
  21546. var r2 = {
  21547. value: value2,
  21548. meta: meta2
  21549. };
  21550. completer(r2);
  21551. };
  21552. var meta = __assign({
  21553. filetype,
  21554. fieldname: entry.fieldname
  21555. }, Optional.from(entry.meta).getOr({}));
  21556. picker.call(editor, handler, entry.value, meta);
  21557. });
  21558. };
  21559. });
  21560. };
  21561. var getTextSetting = function(value2) {
  21562. return Optional.from(value2).filter(isString).getOrUndefined();
  21563. };
  21564. var getLinkInformation = function(editor) {
  21565. if (noTypeaheadUrls(editor)) {
  21566. return Optional.none();
  21567. }
  21568. return Optional.some({
  21569. targets: LinkTargets.find(editor.getBody()),
  21570. anchorTop: getTextSetting(getAnchorTop(editor)),
  21571. anchorBottom: getTextSetting(getAnchorBottom(editor))
  21572. });
  21573. };
  21574. var getValidationHandler = function(editor) {
  21575. return Optional.from(getFilePickerValidatorHandler(editor));
  21576. };
  21577. var UrlInputBackstage = function(editor) {
  21578. return {
  21579. getHistory,
  21580. addToHistory,
  21581. getLinkInformation: function() {
  21582. return getLinkInformation(editor);
  21583. },
  21584. getValidationHandler: function() {
  21585. return getValidationHandler(editor);
  21586. },
  21587. getUrlPicker: function(filetype) {
  21588. return getUrlPicker(editor, filetype);
  21589. }
  21590. };
  21591. };
  21592. var init$7 = function(sink, editor, lazyAnchorbar) {
  21593. var contextMenuState = Cell(false);
  21594. var toolbar = HeaderBackstage(editor);
  21595. var backstage = {
  21596. shared: {
  21597. providers: {
  21598. icons: function() {
  21599. return editor.ui.registry.getAll().icons;
  21600. },
  21601. menuItems: function() {
  21602. return editor.ui.registry.getAll().menuItems;
  21603. },
  21604. translate: global$e.translate,
  21605. isDisabled: function() {
  21606. return editor.mode.isReadOnly() || editor.ui.isDisabled();
  21607. },
  21608. getSetting: editor.getParam.bind(editor)
  21609. },
  21610. interpreter: function(s) {
  21611. return interpretWithoutForm(s, backstage);
  21612. },
  21613. anchors: getAnchors(editor, lazyAnchorbar, toolbar.isPositionedAtTop),
  21614. header: toolbar,
  21615. getSink: function() {
  21616. return Result.value(sink);
  21617. }
  21618. },
  21619. urlinput: UrlInputBackstage(editor),
  21620. styleselect: init$8(editor),
  21621. colorinput: ColorInputBackstage(editor),
  21622. dialog: DialogBackstage(editor),
  21623. isContextMenuOpen: function() {
  21624. return contextMenuState.get();
  21625. },
  21626. setContextMenuState: function(state) {
  21627. return contextMenuState.set(state);
  21628. }
  21629. };
  21630. return backstage;
  21631. };
  21632. var setup$b = function(editor, mothership, uiMothership) {
  21633. var broadcastEvent = function(name2, evt) {
  21634. each$1([
  21635. mothership,
  21636. uiMothership
  21637. ], function(ship) {
  21638. ship.broadcastEvent(name2, evt);
  21639. });
  21640. };
  21641. var broadcastOn = function(channel, message) {
  21642. each$1([
  21643. mothership,
  21644. uiMothership
  21645. ], function(ship) {
  21646. ship.broadcastOn([channel], message);
  21647. });
  21648. };
  21649. var fireDismissPopups = function(evt) {
  21650. return broadcastOn(dismissPopups(), { target: evt.target });
  21651. };
  21652. var doc = getDocument();
  21653. var onTouchstart = bind(doc, "touchstart", fireDismissPopups);
  21654. var onTouchmove = bind(doc, "touchmove", function(evt) {
  21655. return broadcastEvent(documentTouchmove(), evt);
  21656. });
  21657. var onTouchend = bind(doc, "touchend", function(evt) {
  21658. return broadcastEvent(documentTouchend(), evt);
  21659. });
  21660. var onMousedown = bind(doc, "mousedown", fireDismissPopups);
  21661. var onMouseup = bind(doc, "mouseup", function(evt) {
  21662. if (evt.raw.button === 0) {
  21663. broadcastOn(mouseReleased(), { target: evt.target });
  21664. }
  21665. });
  21666. var onContentClick = function(raw) {
  21667. return broadcastOn(dismissPopups(), { target: SugarElement.fromDom(raw.target) });
  21668. };
  21669. var onContentMouseup = function(raw) {
  21670. if (raw.button === 0) {
  21671. broadcastOn(mouseReleased(), { target: SugarElement.fromDom(raw.target) });
  21672. }
  21673. };
  21674. var onContentMousedown = function() {
  21675. each$1(editor.editorManager.get(), function(loopEditor) {
  21676. if (editor !== loopEditor) {
  21677. loopEditor.fire("DismissPopups", { relatedTarget: editor });
  21678. }
  21679. });
  21680. };
  21681. var onWindowScroll = function(evt) {
  21682. return broadcastEvent(windowScroll(), fromRawEvent(evt));
  21683. };
  21684. var onWindowResize = function(evt) {
  21685. broadcastOn(repositionPopups(), {});
  21686. broadcastEvent(windowResize(), fromRawEvent(evt));
  21687. };
  21688. var onEditorResize = function() {
  21689. return broadcastOn(repositionPopups(), {});
  21690. };
  21691. var onEditorProgress = function(evt) {
  21692. if (evt.state) {
  21693. broadcastOn(dismissPopups(), { target: SugarElement.fromDom(editor.getContainer()) });
  21694. }
  21695. };
  21696. var onDismissPopups = function(event) {
  21697. broadcastOn(dismissPopups(), { target: SugarElement.fromDom(event.relatedTarget.getContainer()) });
  21698. };
  21699. editor.on("PostRender", function() {
  21700. editor.on("click", onContentClick);
  21701. editor.on("tap", onContentClick);
  21702. editor.on("mouseup", onContentMouseup);
  21703. editor.on("mousedown", onContentMousedown);
  21704. editor.on("ScrollWindow", onWindowScroll);
  21705. editor.on("ResizeWindow", onWindowResize);
  21706. editor.on("ResizeEditor", onEditorResize);
  21707. editor.on("AfterProgressState", onEditorProgress);
  21708. editor.on("DismissPopups", onDismissPopups);
  21709. });
  21710. editor.on("remove", function() {
  21711. editor.off("click", onContentClick);
  21712. editor.off("tap", onContentClick);
  21713. editor.off("mouseup", onContentMouseup);
  21714. editor.off("mousedown", onContentMousedown);
  21715. editor.off("ScrollWindow", onWindowScroll);
  21716. editor.off("ResizeWindow", onWindowResize);
  21717. editor.off("ResizeEditor", onEditorResize);
  21718. editor.off("AfterProgressState", onEditorProgress);
  21719. editor.off("DismissPopups", onDismissPopups);
  21720. onMousedown.unbind();
  21721. onTouchstart.unbind();
  21722. onTouchmove.unbind();
  21723. onTouchend.unbind();
  21724. onMouseup.unbind();
  21725. });
  21726. editor.on("detach", function() {
  21727. detachSystem(mothership);
  21728. detachSystem(uiMothership);
  21729. mothership.destroy();
  21730. uiMothership.destroy();
  21731. });
  21732. };
  21733. var parts$a = AlloyParts;
  21734. var partType = PartType;
  21735. var schema$f = constant$1([
  21736. defaulted("shell", false),
  21737. required$1("makeItem"),
  21738. defaulted("setupItem", noop),
  21739. SketchBehaviours.field("listBehaviours", [Replacing])
  21740. ]);
  21741. var customListDetail = function() {
  21742. return { behaviours: derive$1([Replacing.config({})]) };
  21743. };
  21744. var itemsPart = optional({
  21745. name: "items",
  21746. overrides: customListDetail
  21747. });
  21748. var parts$9 = constant$1([itemsPart]);
  21749. var name = constant$1("CustomList");
  21750. var factory$d = function(detail, components2, _spec, _external) {
  21751. var setItems = function(list, items) {
  21752. getListContainer(list).fold(function() {
  21753. console.error("Custom List was defined to not be a shell, but no item container was specified in components");
  21754. throw new Error("Custom List was defined to not be a shell, but no item container was specified in components");
  21755. }, function(container) {
  21756. var itemComps = Replacing.contents(container);
  21757. var numListsRequired = items.length;
  21758. var numListsToAdd = numListsRequired - itemComps.length;
  21759. var itemsToAdd = numListsToAdd > 0 ? range$2(numListsToAdd, function() {
  21760. return detail.makeItem();
  21761. }) : [];
  21762. var itemsToRemove = itemComps.slice(numListsRequired);
  21763. each$1(itemsToRemove, function(item2) {
  21764. return Replacing.remove(container, item2);
  21765. });
  21766. each$1(itemsToAdd, function(item2) {
  21767. return Replacing.append(container, item2);
  21768. });
  21769. var builtLists = Replacing.contents(container);
  21770. each$1(builtLists, function(item2, i) {
  21771. detail.setupItem(list, item2, items[i], i);
  21772. });
  21773. });
  21774. };
  21775. var extra = detail.shell ? {
  21776. behaviours: [Replacing.config({})],
  21777. components: []
  21778. } : {
  21779. behaviours: [],
  21780. components: components2
  21781. };
  21782. var getListContainer = function(component) {
  21783. return detail.shell ? Optional.some(component) : getPart(component, detail, "items");
  21784. };
  21785. return {
  21786. uid: detail.uid,
  21787. dom: detail.dom,
  21788. components: extra.components,
  21789. behaviours: augment(detail.listBehaviours, extra.behaviours),
  21790. apis: { setItems }
  21791. };
  21792. };
  21793. var CustomList = composite({
  21794. name: name(),
  21795. configFields: schema$f(),
  21796. partFields: parts$9(),
  21797. factory: factory$d,
  21798. apis: {
  21799. setItems: function(apis, list, items) {
  21800. apis.setItems(list, items);
  21801. }
  21802. }
  21803. });
  21804. var schema$e = constant$1([
  21805. required$1("dom"),
  21806. defaulted("shell", true),
  21807. field("toolbarBehaviours", [Replacing])
  21808. ]);
  21809. var enhanceGroups = function() {
  21810. return { behaviours: derive$1([Replacing.config({})]) };
  21811. };
  21812. var parts$8 = constant$1([optional({
  21813. name: "groups",
  21814. overrides: enhanceGroups
  21815. })]);
  21816. var factory$c = function(detail, components2, _spec, _externals) {
  21817. var setGroups2 = function(toolbar, groups) {
  21818. getGroupContainer(toolbar).fold(function() {
  21819. console.error("Toolbar was defined to not be a shell, but no groups container was specified in components");
  21820. throw new Error("Toolbar was defined to not be a shell, but no groups container was specified in components");
  21821. }, function(container) {
  21822. Replacing.set(container, groups);
  21823. });
  21824. };
  21825. var getGroupContainer = function(component) {
  21826. return detail.shell ? Optional.some(component) : getPart(component, detail, "groups");
  21827. };
  21828. var extra = detail.shell ? {
  21829. behaviours: [Replacing.config({})],
  21830. components: []
  21831. } : {
  21832. behaviours: [],
  21833. components: components2
  21834. };
  21835. return {
  21836. uid: detail.uid,
  21837. dom: detail.dom,
  21838. components: extra.components,
  21839. behaviours: augment(detail.toolbarBehaviours, extra.behaviours),
  21840. apis: { setGroups: setGroups2 },
  21841. domModification: { attributes: { role: "group" } }
  21842. };
  21843. };
  21844. var Toolbar = composite({
  21845. name: "Toolbar",
  21846. configFields: schema$e(),
  21847. partFields: parts$8(),
  21848. factory: factory$c,
  21849. apis: {
  21850. setGroups: function(apis, toolbar, groups) {
  21851. apis.setGroups(toolbar, groups);
  21852. }
  21853. }
  21854. });
  21855. var setup$a = noop;
  21856. var isDocked$2 = never;
  21857. var getBehaviours$1 = constant$1([]);
  21858. var StaticHeader = Object.freeze({
  21859. __proto__: null,
  21860. setup: setup$a,
  21861. isDocked: isDocked$2,
  21862. getBehaviours: getBehaviours$1
  21863. });
  21864. var getOffsetParent = function(element2) {
  21865. var isFixed = is$1(getRaw(element2, "position"), "fixed");
  21866. var offsetParent$1 = isFixed ? Optional.none() : offsetParent(element2);
  21867. return offsetParent$1.orThunk(function() {
  21868. var marker = SugarElement.fromTag("span");
  21869. return parent(element2).bind(function(parent2) {
  21870. append$2(parent2, marker);
  21871. var offsetParent$12 = offsetParent(marker);
  21872. remove$5(marker);
  21873. return offsetParent$12;
  21874. });
  21875. });
  21876. };
  21877. var getOrigin = function(element2) {
  21878. return getOffsetParent(element2).map(absolute$3).getOrThunk(function() {
  21879. return SugarPosition(0, 0);
  21880. });
  21881. };
  21882. var morphAdt = Adt.generate([
  21883. { static: [] },
  21884. { absolute: ["positionCss"] },
  21885. { fixed: ["positionCss"] }
  21886. ]);
  21887. var appear = function(component, contextualInfo) {
  21888. var elem = component.element;
  21889. add$2(elem, contextualInfo.transitionClass);
  21890. remove$2(elem, contextualInfo.fadeOutClass);
  21891. add$2(elem, contextualInfo.fadeInClass);
  21892. contextualInfo.onShow(component);
  21893. };
  21894. var disappear = function(component, contextualInfo) {
  21895. var elem = component.element;
  21896. add$2(elem, contextualInfo.transitionClass);
  21897. remove$2(elem, contextualInfo.fadeInClass);
  21898. add$2(elem, contextualInfo.fadeOutClass);
  21899. contextualInfo.onHide(component);
  21900. };
  21901. var isPartiallyVisible = function(box2, viewport2) {
  21902. return box2.y < viewport2.bottom && box2.bottom > viewport2.y;
  21903. };
  21904. var isTopCompletelyVisible = function(box2, viewport2) {
  21905. return box2.y >= viewport2.y;
  21906. };
  21907. var isBottomCompletelyVisible = function(box2, viewport2) {
  21908. return box2.bottom <= viewport2.bottom;
  21909. };
  21910. var isVisibleForModes = function(modes, box2, viewport2) {
  21911. return forall(modes, function(mode) {
  21912. switch (mode) {
  21913. case "bottom":
  21914. return isBottomCompletelyVisible(box2, viewport2);
  21915. case "top":
  21916. return isTopCompletelyVisible(box2, viewport2);
  21917. }
  21918. });
  21919. };
  21920. var getPrior = function(elem, state) {
  21921. return state.getInitialPos().map(function(pos) {
  21922. return bounds(pos.bounds.x, pos.bounds.y, get$a(elem), get$b(elem));
  21923. });
  21924. };
  21925. var storePrior = function(elem, box2, state) {
  21926. state.setInitialPos({
  21927. style: getAllRaw(elem),
  21928. position: get$c(elem, "position") || "static",
  21929. bounds: box2
  21930. });
  21931. };
  21932. var revertToOriginal = function(elem, box2, state) {
  21933. return state.getInitialPos().bind(function(position2) {
  21934. state.clearInitialPos();
  21935. switch (position2.position) {
  21936. case "static":
  21937. return Optional.some(morphAdt.static());
  21938. case "absolute":
  21939. var offsetBox_1 = getOffsetParent(elem).map(box$1).getOrThunk(function() {
  21940. return box$1(body());
  21941. });
  21942. return Optional.some(morphAdt.absolute(NuPositionCss("absolute", get$e(position2.style, "left").map(function(_left) {
  21943. return box2.x - offsetBox_1.x;
  21944. }), get$e(position2.style, "top").map(function(_top) {
  21945. return box2.y - offsetBox_1.y;
  21946. }), get$e(position2.style, "right").map(function(_right) {
  21947. return offsetBox_1.right - box2.right;
  21948. }), get$e(position2.style, "bottom").map(function(_bottom) {
  21949. return offsetBox_1.bottom - box2.bottom;
  21950. }))));
  21951. default:
  21952. return Optional.none();
  21953. }
  21954. });
  21955. };
  21956. var morphToOriginal = function(elem, viewport2, state) {
  21957. return getPrior(elem, state).filter(function(box2) {
  21958. return isVisibleForModes(state.getModes(), box2, viewport2);
  21959. }).bind(function(box2) {
  21960. return revertToOriginal(elem, box2, state);
  21961. });
  21962. };
  21963. var morphToFixed = function(elem, viewport2, state) {
  21964. var box2 = box$1(elem);
  21965. if (!isVisibleForModes(state.getModes(), box2, viewport2)) {
  21966. storePrior(elem, box2, state);
  21967. var winBox = win();
  21968. var left2 = box2.x - winBox.x;
  21969. var top_1 = viewport2.y - winBox.y;
  21970. var bottom2 = winBox.bottom - viewport2.bottom;
  21971. var isTop = box2.y <= viewport2.y;
  21972. 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())));
  21973. } else {
  21974. return Optional.none();
  21975. }
  21976. };
  21977. var getMorph = function(component, viewport2, state) {
  21978. var elem = component.element;
  21979. var isDocked2 = is$1(getRaw(elem, "position"), "fixed");
  21980. return isDocked2 ? morphToOriginal(elem, viewport2, state) : morphToFixed(elem, viewport2, state);
  21981. };
  21982. var getMorphToOriginal = function(component, state) {
  21983. var elem = component.element;
  21984. return getPrior(elem, state).bind(function(box2) {
  21985. return revertToOriginal(elem, box2, state);
  21986. });
  21987. };
  21988. var morphToStatic = function(component, config2, state) {
  21989. state.setDocked(false);
  21990. each$1([
  21991. "left",
  21992. "right",
  21993. "top",
  21994. "bottom",
  21995. "position"
  21996. ], function(prop) {
  21997. return remove$6(component.element, prop);
  21998. });
  21999. config2.onUndocked(component);
  22000. };
  22001. var morphToCoord = function(component, config2, state, position2) {
  22002. var isDocked2 = position2.position === "fixed";
  22003. state.setDocked(isDocked2);
  22004. applyPositionCss(component.element, position2);
  22005. var method = isDocked2 ? config2.onDocked : config2.onUndocked;
  22006. method(component);
  22007. };
  22008. var updateVisibility = function(component, config2, state, viewport2, morphToDocked) {
  22009. if (morphToDocked === void 0) {
  22010. morphToDocked = false;
  22011. }
  22012. config2.contextual.each(function(contextInfo) {
  22013. contextInfo.lazyContext(component).each(function(box2) {
  22014. var isVisible2 = isPartiallyVisible(box2, viewport2);
  22015. if (isVisible2 !== state.isVisible()) {
  22016. state.setVisible(isVisible2);
  22017. if (morphToDocked && !isVisible2) {
  22018. add$1(component.element, [contextInfo.fadeOutClass]);
  22019. contextInfo.onHide(component);
  22020. } else {
  22021. var method = isVisible2 ? appear : disappear;
  22022. method(component, contextInfo);
  22023. }
  22024. }
  22025. });
  22026. });
  22027. };
  22028. var refreshInternal = function(component, config2, state) {
  22029. var viewport2 = config2.lazyViewport(component);
  22030. var isDocked2 = state.isDocked();
  22031. if (isDocked2) {
  22032. updateVisibility(component, config2, state, viewport2);
  22033. }
  22034. getMorph(component, viewport2, state).each(function(morph) {
  22035. morph.fold(function() {
  22036. return morphToStatic(component, config2, state);
  22037. }, function(position2) {
  22038. return morphToCoord(component, config2, state, position2);
  22039. }, function(position2) {
  22040. updateVisibility(component, config2, state, viewport2, true);
  22041. morphToCoord(component, config2, state, position2);
  22042. });
  22043. });
  22044. };
  22045. var resetInternal = function(component, config2, state) {
  22046. var elem = component.element;
  22047. state.setDocked(false);
  22048. getMorphToOriginal(component, state).each(function(morph) {
  22049. morph.fold(function() {
  22050. return morphToStatic(component, config2, state);
  22051. }, function(position2) {
  22052. return morphToCoord(component, config2, state, position2);
  22053. }, noop);
  22054. });
  22055. state.setVisible(true);
  22056. config2.contextual.each(function(contextInfo) {
  22057. remove$1(elem, [
  22058. contextInfo.fadeInClass,
  22059. contextInfo.fadeOutClass,
  22060. contextInfo.transitionClass
  22061. ]);
  22062. contextInfo.onShow(component);
  22063. });
  22064. refresh$4(component, config2, state);
  22065. };
  22066. var refresh$4 = function(component, config2, state) {
  22067. if (component.getSystem().isConnected()) {
  22068. refreshInternal(component, config2, state);
  22069. }
  22070. };
  22071. var reset = function(component, config2, state) {
  22072. if (state.isDocked()) {
  22073. resetInternal(component, config2, state);
  22074. }
  22075. };
  22076. var isDocked$1 = function(component, config2, state) {
  22077. return state.isDocked();
  22078. };
  22079. var setModes = function(component, config2, state, modes) {
  22080. return state.setModes(modes);
  22081. };
  22082. var getModes = function(component, config2, state) {
  22083. return state.getModes();
  22084. };
  22085. var DockingApis = Object.freeze({
  22086. __proto__: null,
  22087. refresh: refresh$4,
  22088. reset,
  22089. isDocked: isDocked$1,
  22090. getModes,
  22091. setModes
  22092. });
  22093. var events$5 = function(dockInfo, dockState) {
  22094. return derive$2([
  22095. runOnSource(transitionend(), function(component, simulatedEvent) {
  22096. dockInfo.contextual.each(function(contextInfo) {
  22097. if (has(component.element, contextInfo.transitionClass)) {
  22098. remove$1(component.element, [
  22099. contextInfo.transitionClass,
  22100. contextInfo.fadeInClass
  22101. ]);
  22102. var notify = dockState.isVisible() ? contextInfo.onShown : contextInfo.onHidden;
  22103. notify(component);
  22104. }
  22105. simulatedEvent.stop();
  22106. });
  22107. }),
  22108. run$1(windowScroll(), function(component, _) {
  22109. refresh$4(component, dockInfo, dockState);
  22110. }),
  22111. run$1(windowResize(), function(component, _) {
  22112. reset(component, dockInfo, dockState);
  22113. })
  22114. ]);
  22115. };
  22116. var ActiveDocking = Object.freeze({
  22117. __proto__: null,
  22118. events: events$5
  22119. });
  22120. var DockingSchema = [
  22121. optionObjOf("contextual", [
  22122. requiredString("fadeInClass"),
  22123. requiredString("fadeOutClass"),
  22124. requiredString("transitionClass"),
  22125. requiredFunction("lazyContext"),
  22126. onHandler("onShow"),
  22127. onHandler("onShown"),
  22128. onHandler("onHide"),
  22129. onHandler("onHidden")
  22130. ]),
  22131. defaultedFunction("lazyViewport", win),
  22132. defaultedArrayOf("modes", [
  22133. "top",
  22134. "bottom"
  22135. ], string),
  22136. onHandler("onDocked"),
  22137. onHandler("onUndocked")
  22138. ];
  22139. var init$6 = function(spec) {
  22140. var docked = Cell(false);
  22141. var visible = Cell(true);
  22142. var initialBounds = value$1();
  22143. var modes = Cell(spec.modes);
  22144. var readState = function() {
  22145. return "docked: " + docked.get() + ", visible: " + visible.get() + ", modes: " + modes.get().join(",");
  22146. };
  22147. return nu$8({
  22148. isDocked: docked.get,
  22149. setDocked: docked.set,
  22150. getInitialPos: initialBounds.get,
  22151. setInitialPos: initialBounds.set,
  22152. clearInitialPos: initialBounds.clear,
  22153. isVisible: visible.get,
  22154. setVisible: visible.set,
  22155. getModes: modes.get,
  22156. setModes: modes.set,
  22157. readState
  22158. });
  22159. };
  22160. var DockingState = Object.freeze({
  22161. __proto__: null,
  22162. init: init$6
  22163. });
  22164. var Docking = create$8({
  22165. fields: DockingSchema,
  22166. name: "docking",
  22167. active: ActiveDocking,
  22168. apis: DockingApis,
  22169. state: DockingState
  22170. });
  22171. var toolbarHeightChange = constant$1(generate$6("toolbar-height-change"));
  22172. var visibility = {
  22173. fadeInClass: "tox-editor-dock-fadein",
  22174. fadeOutClass: "tox-editor-dock-fadeout",
  22175. transitionClass: "tox-editor-dock-transition"
  22176. };
  22177. var editorStickyOnClass = "tox-tinymce--toolbar-sticky-on";
  22178. var editorStickyOffClass = "tox-tinymce--toolbar-sticky-off";
  22179. var scrollFromBehindHeader = function(e, containerHeader) {
  22180. var doc = owner$4(containerHeader);
  22181. var viewHeight = doc.dom.defaultView.innerHeight;
  22182. var scrollPos = get$9(doc);
  22183. var markerElement = SugarElement.fromDom(e.elm);
  22184. var markerPos = absolute$2(markerElement);
  22185. var markerHeight = get$b(markerElement);
  22186. var markerTop = markerPos.y;
  22187. var markerBottom = markerTop + markerHeight;
  22188. var editorHeaderPos = absolute$3(containerHeader);
  22189. var editorHeaderHeight = get$b(containerHeader);
  22190. var editorHeaderTop = editorHeaderPos.top;
  22191. var editorHeaderBottom = editorHeaderTop + editorHeaderHeight;
  22192. var editorHeaderDockedAtTop = Math.abs(editorHeaderTop - scrollPos.top) < 2;
  22193. var editorHeaderDockedAtBottom = Math.abs(editorHeaderBottom - (scrollPos.top + viewHeight)) < 2;
  22194. if (editorHeaderDockedAtTop && markerTop < editorHeaderBottom) {
  22195. to(scrollPos.left, markerTop - editorHeaderHeight, doc);
  22196. } else if (editorHeaderDockedAtBottom && markerBottom > editorHeaderTop) {
  22197. var y = markerTop - viewHeight + markerHeight + editorHeaderHeight;
  22198. to(scrollPos.left, y, doc);
  22199. }
  22200. };
  22201. var isDockedMode = function(header, mode) {
  22202. return contains$2(Docking.getModes(header), mode);
  22203. };
  22204. var updateIframeContentFlow = function(header) {
  22205. var getOccupiedHeight = function(elm2) {
  22206. return getOuter$2(elm2) + (parseInt(get$c(elm2, "margin-top"), 10) || 0) + (parseInt(get$c(elm2, "margin-bottom"), 10) || 0);
  22207. };
  22208. var elm = header.element;
  22209. parent(elm).each(function(parentElem) {
  22210. var padding = "padding-" + Docking.getModes(header)[0];
  22211. if (Docking.isDocked(header)) {
  22212. var parentWidth = get$a(parentElem);
  22213. set$7(elm, "width", parentWidth + "px");
  22214. set$7(parentElem, padding, getOccupiedHeight(elm) + "px");
  22215. } else {
  22216. remove$6(elm, "width");
  22217. remove$6(parentElem, padding);
  22218. }
  22219. });
  22220. };
  22221. var updateSinkVisibility = function(sinkElem, visible) {
  22222. if (visible) {
  22223. remove$2(sinkElem, visibility.fadeOutClass);
  22224. add$1(sinkElem, [
  22225. visibility.transitionClass,
  22226. visibility.fadeInClass
  22227. ]);
  22228. } else {
  22229. remove$2(sinkElem, visibility.fadeInClass);
  22230. add$1(sinkElem, [
  22231. visibility.fadeOutClass,
  22232. visibility.transitionClass
  22233. ]);
  22234. }
  22235. };
  22236. var updateEditorClasses = function(editor, docked) {
  22237. var editorContainer = SugarElement.fromDom(editor.getContainer());
  22238. if (docked) {
  22239. add$2(editorContainer, editorStickyOnClass);
  22240. remove$2(editorContainer, editorStickyOffClass);
  22241. } else {
  22242. add$2(editorContainer, editorStickyOffClass);
  22243. remove$2(editorContainer, editorStickyOnClass);
  22244. }
  22245. };
  22246. var restoreFocus = function(headerElem, focusedElem) {
  22247. var ownerDoc = owner$4(focusedElem);
  22248. active(ownerDoc).filter(function(activeElm) {
  22249. return !eq(focusedElem, activeElm);
  22250. }).filter(function(activeElm) {
  22251. return eq(activeElm, SugarElement.fromDom(ownerDoc.dom.body)) || contains(headerElem, activeElm);
  22252. }).each(function() {
  22253. return focus$3(focusedElem);
  22254. });
  22255. };
  22256. var findFocusedElem = function(rootElm, lazySink) {
  22257. return search(rootElm).orThunk(function() {
  22258. return lazySink().toOptional().bind(function(sink) {
  22259. return search(sink.element);
  22260. });
  22261. });
  22262. };
  22263. var setup$9 = function(editor, sharedBackstage, lazyHeader) {
  22264. if (!editor.inline) {
  22265. if (!sharedBackstage.header.isPositionedAtTop()) {
  22266. editor.on("ResizeEditor", function() {
  22267. lazyHeader().each(Docking.reset);
  22268. });
  22269. }
  22270. editor.on("ResizeWindow ResizeEditor", function() {
  22271. lazyHeader().each(updateIframeContentFlow);
  22272. });
  22273. editor.on("SkinLoaded", function() {
  22274. lazyHeader().each(function(comp) {
  22275. Docking.isDocked(comp) ? Docking.reset(comp) : Docking.refresh(comp);
  22276. });
  22277. });
  22278. editor.on("FullscreenStateChanged", function() {
  22279. lazyHeader().each(Docking.reset);
  22280. });
  22281. }
  22282. editor.on("AfterScrollIntoView", function(e) {
  22283. lazyHeader().each(function(header) {
  22284. Docking.refresh(header);
  22285. var headerElem = header.element;
  22286. if (isVisible(headerElem)) {
  22287. scrollFromBehindHeader(e, headerElem);
  22288. }
  22289. });
  22290. });
  22291. editor.on("PostRender", function() {
  22292. updateEditorClasses(editor, false);
  22293. });
  22294. };
  22295. var isDocked = function(lazyHeader) {
  22296. return lazyHeader().map(Docking.isDocked).getOr(false);
  22297. };
  22298. var getIframeBehaviours = function() {
  22299. var _a2;
  22300. return [Receiving.config({ channels: (_a2 = {}, _a2[toolbarHeightChange()] = { onReceive: updateIframeContentFlow }, _a2) })];
  22301. };
  22302. var getBehaviours = function(editor, sharedBackstage) {
  22303. var focusedElm = value$1();
  22304. var lazySink = sharedBackstage.getSink;
  22305. var runOnSinkElement = function(f) {
  22306. lazySink().each(function(sink) {
  22307. return f(sink.element);
  22308. });
  22309. };
  22310. var onDockingSwitch = function(comp) {
  22311. if (!editor.inline) {
  22312. updateIframeContentFlow(comp);
  22313. }
  22314. updateEditorClasses(editor, Docking.isDocked(comp));
  22315. comp.getSystem().broadcastOn([repositionPopups()], {});
  22316. lazySink().each(function(sink) {
  22317. return sink.getSystem().broadcastOn([repositionPopups()], {});
  22318. });
  22319. };
  22320. var additionalBehaviours = editor.inline ? [] : getIframeBehaviours();
  22321. return __spreadArray([
  22322. Focusing.config({}),
  22323. Docking.config({
  22324. contextual: __assign({
  22325. lazyContext: function(comp) {
  22326. var headerHeight = getOuter$2(comp.element);
  22327. var container = editor.inline ? editor.getContentAreaContainer() : editor.getContainer();
  22328. var box2 = box$1(SugarElement.fromDom(container));
  22329. var boxHeight = box2.height - headerHeight;
  22330. var topBound = box2.y + (isDockedMode(comp, "top") ? 0 : headerHeight);
  22331. return Optional.some(bounds(box2.x, topBound, box2.width, boxHeight));
  22332. },
  22333. onShow: function() {
  22334. runOnSinkElement(function(elem) {
  22335. return updateSinkVisibility(elem, true);
  22336. });
  22337. },
  22338. onShown: function(comp) {
  22339. runOnSinkElement(function(elem) {
  22340. return remove$1(elem, [
  22341. visibility.transitionClass,
  22342. visibility.fadeInClass
  22343. ]);
  22344. });
  22345. focusedElm.get().each(function(elem) {
  22346. restoreFocus(comp.element, elem);
  22347. focusedElm.clear();
  22348. });
  22349. },
  22350. onHide: function(comp) {
  22351. findFocusedElem(comp.element, lazySink).fold(focusedElm.clear, focusedElm.set);
  22352. runOnSinkElement(function(elem) {
  22353. return updateSinkVisibility(elem, false);
  22354. });
  22355. },
  22356. onHidden: function() {
  22357. runOnSinkElement(function(elem) {
  22358. return remove$1(elem, [visibility.transitionClass]);
  22359. });
  22360. }
  22361. }, visibility),
  22362. lazyViewport: function(comp) {
  22363. var win$1 = win();
  22364. var offset2 = getStickyToolbarOffset(editor);
  22365. var top2 = win$1.y + (isDockedMode(comp, "top") ? offset2 : 0);
  22366. var height2 = win$1.height - (isDockedMode(comp, "bottom") ? offset2 : 0);
  22367. return bounds(win$1.x, top2, win$1.width, height2);
  22368. },
  22369. modes: [sharedBackstage.header.getDockingMode()],
  22370. onDocked: onDockingSwitch,
  22371. onUndocked: onDockingSwitch
  22372. })
  22373. ], additionalBehaviours, true);
  22374. };
  22375. var StickyHeader = Object.freeze({
  22376. __proto__: null,
  22377. setup: setup$9,
  22378. isDocked,
  22379. getBehaviours
  22380. });
  22381. var renderHeader = function(spec) {
  22382. var editor = spec.editor;
  22383. var getBehaviours$22 = spec.sticky ? getBehaviours : getBehaviours$1;
  22384. return {
  22385. uid: spec.uid,
  22386. dom: spec.dom,
  22387. components: spec.components,
  22388. behaviours: derive$1(getBehaviours$22(editor, spec.sharedBackstage))
  22389. };
  22390. };
  22391. var groupToolbarButtonSchema = objOf([
  22392. requiredString("type"),
  22393. requiredOf("items", oneOf([
  22394. arrOfObj([
  22395. requiredString("name"),
  22396. requiredArrayOf("items", string)
  22397. ]),
  22398. string
  22399. ]))
  22400. ].concat(baseToolbarButtonFields));
  22401. var createGroupToolbarButton = function(spec) {
  22402. return asRaw("GroupToolbarButton", groupToolbarButtonSchema, spec);
  22403. };
  22404. var baseMenuButtonFields = [
  22405. optionString("text"),
  22406. optionString("tooltip"),
  22407. optionString("icon"),
  22408. requiredFunction("fetch"),
  22409. defaultedFunction("onSetup", function() {
  22410. return noop;
  22411. })
  22412. ];
  22413. var MenuButtonSchema = objOf(__spreadArray([requiredString("type")], baseMenuButtonFields, true));
  22414. var createMenuButton = function(spec) {
  22415. return asRaw("menubutton", MenuButtonSchema, spec);
  22416. };
  22417. var splitButtonSchema = objOf([
  22418. requiredString("type"),
  22419. optionString("tooltip"),
  22420. optionString("icon"),
  22421. optionString("text"),
  22422. optionFunction("select"),
  22423. requiredFunction("fetch"),
  22424. defaultedFunction("onSetup", function() {
  22425. return noop;
  22426. }),
  22427. defaultedStringEnum("presets", "normal", [
  22428. "normal",
  22429. "color",
  22430. "listpreview"
  22431. ]),
  22432. defaulted("columns", 1),
  22433. requiredFunction("onAction"),
  22434. requiredFunction("onItemAction")
  22435. ]);
  22436. var createSplitButton = function(spec) {
  22437. return asRaw("SplitButton", splitButtonSchema, spec);
  22438. };
  22439. var factory$b = function(detail, spec) {
  22440. var setMenus = function(comp, menus) {
  22441. var newMenus = map$2(menus, function(m) {
  22442. var buttonSpec = {
  22443. type: "menubutton",
  22444. text: m.text,
  22445. fetch: function(callback) {
  22446. callback(m.getItems());
  22447. }
  22448. };
  22449. var internal2 = createMenuButton(buttonSpec).mapError(function(errInfo) {
  22450. return formatError(errInfo);
  22451. }).getOrDie();
  22452. return renderMenuButton(internal2, "tox-mbtn", spec.backstage, Optional.some("menuitem"));
  22453. });
  22454. Replacing.set(comp, newMenus);
  22455. };
  22456. var apis = {
  22457. focus: Keying.focusIn,
  22458. setMenus
  22459. };
  22460. return {
  22461. uid: detail.uid,
  22462. dom: detail.dom,
  22463. components: [],
  22464. behaviours: derive$1([
  22465. Replacing.config({}),
  22466. config("menubar-events", [
  22467. runOnAttached(function(component) {
  22468. detail.onSetup(component);
  22469. }),
  22470. run$1(mouseover(), function(comp, se) {
  22471. descendant(comp.element, ".tox-mbtn--active").each(function(activeButton) {
  22472. closest$1(se.event.target, ".tox-mbtn").each(function(hoveredButton) {
  22473. if (!eq(activeButton, hoveredButton)) {
  22474. comp.getSystem().getByDom(activeButton).each(function(activeComp) {
  22475. comp.getSystem().getByDom(hoveredButton).each(function(hoveredComp) {
  22476. Dropdown.expand(hoveredComp);
  22477. Dropdown.close(activeComp);
  22478. Focusing.focus(hoveredComp);
  22479. });
  22480. });
  22481. }
  22482. });
  22483. });
  22484. }),
  22485. run$1(focusShifted(), function(comp, se) {
  22486. se.event.prevFocus.bind(function(prev) {
  22487. return comp.getSystem().getByDom(prev).toOptional();
  22488. }).each(function(prev) {
  22489. se.event.newFocus.bind(function(nu2) {
  22490. return comp.getSystem().getByDom(nu2).toOptional();
  22491. }).each(function(nu2) {
  22492. if (Dropdown.isOpen(prev)) {
  22493. Dropdown.expand(nu2);
  22494. Dropdown.close(prev);
  22495. }
  22496. });
  22497. });
  22498. })
  22499. ]),
  22500. Keying.config({
  22501. mode: "flow",
  22502. selector: ".tox-mbtn",
  22503. onEscape: function(comp) {
  22504. detail.onEscape(comp);
  22505. return Optional.some(true);
  22506. }
  22507. }),
  22508. Tabstopping.config({})
  22509. ]),
  22510. apis,
  22511. domModification: { attributes: { role: "menubar" } }
  22512. };
  22513. };
  22514. var SilverMenubar = single({
  22515. factory: factory$b,
  22516. name: "silver.Menubar",
  22517. configFields: [
  22518. required$1("dom"),
  22519. required$1("uid"),
  22520. required$1("onEscape"),
  22521. required$1("backstage"),
  22522. defaulted("onSetup", noop)
  22523. ],
  22524. apis: {
  22525. focus: function(apis, comp) {
  22526. apis.focus(comp);
  22527. },
  22528. setMenus: function(apis, comp, menus) {
  22529. apis.setMenus(comp, menus);
  22530. }
  22531. }
  22532. });
  22533. var getAnimationRoot = function(component, slideConfig) {
  22534. return slideConfig.getAnimationRoot.fold(function() {
  22535. return component.element;
  22536. }, function(get2) {
  22537. return get2(component);
  22538. });
  22539. };
  22540. var getDimensionProperty = function(slideConfig) {
  22541. return slideConfig.dimension.property;
  22542. };
  22543. var getDimension = function(slideConfig, elem) {
  22544. return slideConfig.dimension.getDimension(elem);
  22545. };
  22546. var disableTransitions = function(component, slideConfig) {
  22547. var root = getAnimationRoot(component, slideConfig);
  22548. remove$1(root, [
  22549. slideConfig.shrinkingClass,
  22550. slideConfig.growingClass
  22551. ]);
  22552. };
  22553. var setShrunk = function(component, slideConfig) {
  22554. remove$2(component.element, slideConfig.openClass);
  22555. add$2(component.element, slideConfig.closedClass);
  22556. set$7(component.element, getDimensionProperty(slideConfig), "0px");
  22557. reflow(component.element);
  22558. };
  22559. var setGrown = function(component, slideConfig) {
  22560. remove$2(component.element, slideConfig.closedClass);
  22561. add$2(component.element, slideConfig.openClass);
  22562. remove$6(component.element, getDimensionProperty(slideConfig));
  22563. };
  22564. var doImmediateShrink = function(component, slideConfig, slideState, _calculatedSize) {
  22565. slideState.setCollapsed();
  22566. set$7(component.element, getDimensionProperty(slideConfig), getDimension(slideConfig, component.element));
  22567. reflow(component.element);
  22568. disableTransitions(component, slideConfig);
  22569. setShrunk(component, slideConfig);
  22570. slideConfig.onStartShrink(component);
  22571. slideConfig.onShrunk(component);
  22572. };
  22573. var doStartShrink = function(component, slideConfig, slideState, calculatedSize) {
  22574. var size = calculatedSize.getOrThunk(function() {
  22575. return getDimension(slideConfig, component.element);
  22576. });
  22577. slideState.setCollapsed();
  22578. set$7(component.element, getDimensionProperty(slideConfig), size);
  22579. reflow(component.element);
  22580. var root = getAnimationRoot(component, slideConfig);
  22581. remove$2(root, slideConfig.growingClass);
  22582. add$2(root, slideConfig.shrinkingClass);
  22583. setShrunk(component, slideConfig);
  22584. slideConfig.onStartShrink(component);
  22585. };
  22586. var doStartSmartShrink = function(component, slideConfig, slideState) {
  22587. var size = getDimension(slideConfig, component.element);
  22588. var shrinker = size === "0px" ? doImmediateShrink : doStartShrink;
  22589. shrinker(component, slideConfig, slideState, Optional.some(size));
  22590. };
  22591. var doStartGrow = function(component, slideConfig, slideState) {
  22592. var root = getAnimationRoot(component, slideConfig);
  22593. var wasShrinking = has(root, slideConfig.shrinkingClass);
  22594. var beforeSize = getDimension(slideConfig, component.element);
  22595. setGrown(component, slideConfig);
  22596. var fullSize = getDimension(slideConfig, component.element);
  22597. var startPartialGrow = function() {
  22598. set$7(component.element, getDimensionProperty(slideConfig), beforeSize);
  22599. reflow(component.element);
  22600. };
  22601. var startCompleteGrow = function() {
  22602. setShrunk(component, slideConfig);
  22603. };
  22604. var setStartSize = wasShrinking ? startPartialGrow : startCompleteGrow;
  22605. setStartSize();
  22606. remove$2(root, slideConfig.shrinkingClass);
  22607. add$2(root, slideConfig.growingClass);
  22608. setGrown(component, slideConfig);
  22609. set$7(component.element, getDimensionProperty(slideConfig), fullSize);
  22610. slideState.setExpanded();
  22611. slideConfig.onStartGrow(component);
  22612. };
  22613. var refresh$3 = function(component, slideConfig, slideState) {
  22614. if (slideState.isExpanded()) {
  22615. remove$6(component.element, getDimensionProperty(slideConfig));
  22616. var fullSize = getDimension(slideConfig, component.element);
  22617. set$7(component.element, getDimensionProperty(slideConfig), fullSize);
  22618. }
  22619. };
  22620. var grow = function(component, slideConfig, slideState) {
  22621. if (!slideState.isExpanded()) {
  22622. doStartGrow(component, slideConfig, slideState);
  22623. }
  22624. };
  22625. var shrink = function(component, slideConfig, slideState) {
  22626. if (slideState.isExpanded()) {
  22627. doStartSmartShrink(component, slideConfig, slideState);
  22628. }
  22629. };
  22630. var immediateShrink = function(component, slideConfig, slideState) {
  22631. if (slideState.isExpanded()) {
  22632. doImmediateShrink(component, slideConfig, slideState);
  22633. }
  22634. };
  22635. var hasGrown = function(component, slideConfig, slideState) {
  22636. return slideState.isExpanded();
  22637. };
  22638. var hasShrunk = function(component, slideConfig, slideState) {
  22639. return slideState.isCollapsed();
  22640. };
  22641. var isGrowing = function(component, slideConfig, _slideState) {
  22642. var root = getAnimationRoot(component, slideConfig);
  22643. return has(root, slideConfig.growingClass) === true;
  22644. };
  22645. var isShrinking = function(component, slideConfig, _slideState) {
  22646. var root = getAnimationRoot(component, slideConfig);
  22647. return has(root, slideConfig.shrinkingClass) === true;
  22648. };
  22649. var isTransitioning = function(component, slideConfig, slideState) {
  22650. return isGrowing(component, slideConfig) || isShrinking(component, slideConfig);
  22651. };
  22652. var toggleGrow = function(component, slideConfig, slideState) {
  22653. var f = slideState.isExpanded() ? doStartSmartShrink : doStartGrow;
  22654. f(component, slideConfig, slideState);
  22655. };
  22656. var SlidingApis = Object.freeze({
  22657. __proto__: null,
  22658. refresh: refresh$3,
  22659. grow,
  22660. shrink,
  22661. immediateShrink,
  22662. hasGrown,
  22663. hasShrunk,
  22664. isGrowing,
  22665. isShrinking,
  22666. isTransitioning,
  22667. toggleGrow,
  22668. disableTransitions
  22669. });
  22670. var exhibit = function(base2, slideConfig, _slideState) {
  22671. var expanded = slideConfig.expanded;
  22672. return expanded ? nu$7({
  22673. classes: [slideConfig.openClass],
  22674. styles: {}
  22675. }) : nu$7({
  22676. classes: [slideConfig.closedClass],
  22677. styles: wrap$1(slideConfig.dimension.property, "0px")
  22678. });
  22679. };
  22680. var events$4 = function(slideConfig, slideState) {
  22681. return derive$2([runOnSource(transitionend(), function(component, simulatedEvent) {
  22682. var raw = simulatedEvent.event.raw;
  22683. if (raw.propertyName === slideConfig.dimension.property) {
  22684. disableTransitions(component, slideConfig);
  22685. if (slideState.isExpanded()) {
  22686. remove$6(component.element, slideConfig.dimension.property);
  22687. }
  22688. var notify = slideState.isExpanded() ? slideConfig.onGrown : slideConfig.onShrunk;
  22689. notify(component);
  22690. }
  22691. })]);
  22692. };
  22693. var ActiveSliding = Object.freeze({
  22694. __proto__: null,
  22695. exhibit,
  22696. events: events$4
  22697. });
  22698. var SlidingSchema = [
  22699. required$1("closedClass"),
  22700. required$1("openClass"),
  22701. required$1("shrinkingClass"),
  22702. required$1("growingClass"),
  22703. option("getAnimationRoot"),
  22704. onHandler("onShrunk"),
  22705. onHandler("onStartShrink"),
  22706. onHandler("onGrown"),
  22707. onHandler("onStartGrow"),
  22708. defaulted("expanded", false),
  22709. requiredOf("dimension", choose$1("property", {
  22710. width: [
  22711. output$1("property", "width"),
  22712. output$1("getDimension", function(elem) {
  22713. return get$a(elem) + "px";
  22714. })
  22715. ],
  22716. height: [
  22717. output$1("property", "height"),
  22718. output$1("getDimension", function(elem) {
  22719. return get$b(elem) + "px";
  22720. })
  22721. ]
  22722. }))
  22723. ];
  22724. var init$5 = function(spec) {
  22725. var state = Cell(spec.expanded);
  22726. var readState = function() {
  22727. return "expanded: " + state.get();
  22728. };
  22729. return nu$8({
  22730. isExpanded: function() {
  22731. return state.get() === true;
  22732. },
  22733. isCollapsed: function() {
  22734. return state.get() === false;
  22735. },
  22736. setCollapsed: curry(state.set, false),
  22737. setExpanded: curry(state.set, true),
  22738. readState
  22739. });
  22740. };
  22741. var SlidingState = Object.freeze({
  22742. __proto__: null,
  22743. init: init$5
  22744. });
  22745. var Sliding = create$8({
  22746. fields: SlidingSchema,
  22747. name: "sliding",
  22748. active: ActiveSliding,
  22749. apis: SlidingApis,
  22750. state: SlidingState
  22751. });
  22752. var owner = "container";
  22753. var schema$d = [field("slotBehaviours", [])];
  22754. var getPartName = function(name2) {
  22755. return "<alloy.field." + name2 + ">";
  22756. };
  22757. var sketch = function(sSpec) {
  22758. var parts2 = function() {
  22759. var record2 = [];
  22760. var slot = function(name2, config2) {
  22761. record2.push(name2);
  22762. return generateOne$1(owner, getPartName(name2), config2);
  22763. };
  22764. return {
  22765. slot,
  22766. record: constant$1(record2)
  22767. };
  22768. }();
  22769. var spec = sSpec(parts2);
  22770. var partNames = parts2.record();
  22771. var fieldParts = map$2(partNames, function(n) {
  22772. return required({
  22773. name: n,
  22774. pname: getPartName(n)
  22775. });
  22776. });
  22777. return composite$1(owner, schema$d, fieldParts, make$1, spec);
  22778. };
  22779. var make$1 = function(detail, components2) {
  22780. var getSlotNames = function(_) {
  22781. return getAllPartNames(detail);
  22782. };
  22783. var getSlot = function(container, key) {
  22784. return getPart(container, detail, key);
  22785. };
  22786. var onSlot = function(f, def) {
  22787. return function(container, key) {
  22788. return getPart(container, detail, key).map(function(slot) {
  22789. return f(slot, key);
  22790. }).getOr(def);
  22791. };
  22792. };
  22793. var onSlots = function(f) {
  22794. return function(container, keys2) {
  22795. each$1(keys2, function(key) {
  22796. return f(container, key);
  22797. });
  22798. };
  22799. };
  22800. var doShowing = function(comp, _key) {
  22801. return get$d(comp.element, "aria-hidden") !== "true";
  22802. };
  22803. var doShow = function(comp, key) {
  22804. if (!doShowing(comp)) {
  22805. var element2 = comp.element;
  22806. remove$6(element2, "display");
  22807. remove$7(element2, "aria-hidden");
  22808. emitWith(comp, slotVisibility(), {
  22809. name: key,
  22810. visible: true
  22811. });
  22812. }
  22813. };
  22814. var doHide = function(comp, key) {
  22815. if (doShowing(comp)) {
  22816. var element2 = comp.element;
  22817. set$7(element2, "display", "none");
  22818. set$8(element2, "aria-hidden", "true");
  22819. emitWith(comp, slotVisibility(), {
  22820. name: key,
  22821. visible: false
  22822. });
  22823. }
  22824. };
  22825. var isShowing = onSlot(doShowing, false);
  22826. var hideSlot = onSlot(doHide);
  22827. var hideSlots = onSlots(hideSlot);
  22828. var hideAllSlots = function(container) {
  22829. return hideSlots(container, getSlotNames());
  22830. };
  22831. var showSlot = onSlot(doShow);
  22832. var apis = {
  22833. getSlotNames,
  22834. getSlot,
  22835. isShowing,
  22836. hideSlot,
  22837. hideAllSlots,
  22838. showSlot
  22839. };
  22840. return {
  22841. uid: detail.uid,
  22842. dom: detail.dom,
  22843. components: components2,
  22844. behaviours: get$2(detail.slotBehaviours),
  22845. apis
  22846. };
  22847. };
  22848. var slotApis = map$1({
  22849. getSlotNames: function(apis, c) {
  22850. return apis.getSlotNames(c);
  22851. },
  22852. getSlot: function(apis, c, key) {
  22853. return apis.getSlot(c, key);
  22854. },
  22855. isShowing: function(apis, c, key) {
  22856. return apis.isShowing(c, key);
  22857. },
  22858. hideSlot: function(apis, c, key) {
  22859. return apis.hideSlot(c, key);
  22860. },
  22861. hideAllSlots: function(apis, c) {
  22862. return apis.hideAllSlots(c);
  22863. },
  22864. showSlot: function(apis, c, key) {
  22865. return apis.showSlot(c, key);
  22866. }
  22867. }, function(value2) {
  22868. return makeApi(value2);
  22869. });
  22870. var SlotContainer = __assign(__assign({}, slotApis), { sketch });
  22871. var sidebarSchema = objOf([
  22872. optionString("icon"),
  22873. optionString("tooltip"),
  22874. defaultedFunction("onShow", noop),
  22875. defaultedFunction("onHide", noop),
  22876. defaultedFunction("onSetup", function() {
  22877. return noop;
  22878. })
  22879. ]);
  22880. var createSidebar = function(spec) {
  22881. return asRaw("sidebar", sidebarSchema, spec);
  22882. };
  22883. var setup$8 = function(editor) {
  22884. var sidebars = editor.ui.registry.getAll().sidebars;
  22885. each$1(keys(sidebars), function(name2) {
  22886. var spec = sidebars[name2];
  22887. var isActive = function() {
  22888. return is$1(Optional.from(editor.queryCommandValue("ToggleSidebar")), name2);
  22889. };
  22890. editor.ui.registry.addToggleButton(name2, {
  22891. icon: spec.icon,
  22892. tooltip: spec.tooltip,
  22893. onAction: function(buttonApi) {
  22894. editor.execCommand("ToggleSidebar", false, name2);
  22895. buttonApi.setActive(isActive());
  22896. },
  22897. onSetup: function(buttonApi) {
  22898. var handleToggle = function() {
  22899. return buttonApi.setActive(isActive());
  22900. };
  22901. editor.on("ToggleSidebar", handleToggle);
  22902. return function() {
  22903. editor.off("ToggleSidebar", handleToggle);
  22904. };
  22905. }
  22906. });
  22907. });
  22908. };
  22909. var getApi = function(comp) {
  22910. return {
  22911. element: function() {
  22912. return comp.element.dom;
  22913. }
  22914. };
  22915. };
  22916. var makePanels = function(parts2, panelConfigs) {
  22917. var specs = map$2(keys(panelConfigs), function(name2) {
  22918. var spec = panelConfigs[name2];
  22919. var bridged = getOrDie(createSidebar(spec));
  22920. return {
  22921. name: name2,
  22922. getApi,
  22923. onSetup: bridged.onSetup,
  22924. onShow: bridged.onShow,
  22925. onHide: bridged.onHide
  22926. };
  22927. });
  22928. return map$2(specs, function(spec) {
  22929. var editorOffCell = Cell(noop);
  22930. return parts2.slot(spec.name, {
  22931. dom: {
  22932. tag: "div",
  22933. classes: ["tox-sidebar__pane"]
  22934. },
  22935. behaviours: SimpleBehaviours.unnamedEvents([
  22936. onControlAttached(spec, editorOffCell),
  22937. onControlDetached(spec, editorOffCell),
  22938. run$1(slotVisibility(), function(sidepanel, se) {
  22939. var data = se.event;
  22940. var optSidePanelSpec = find$5(specs, function(config2) {
  22941. return config2.name === data.name;
  22942. });
  22943. optSidePanelSpec.each(function(sidePanelSpec) {
  22944. var handler = data.visible ? sidePanelSpec.onShow : sidePanelSpec.onHide;
  22945. handler(sidePanelSpec.getApi(sidepanel));
  22946. });
  22947. })
  22948. ])
  22949. });
  22950. });
  22951. };
  22952. var makeSidebar = function(panelConfigs) {
  22953. return SlotContainer.sketch(function(parts2) {
  22954. return {
  22955. dom: {
  22956. tag: "div",
  22957. classes: ["tox-sidebar__pane-container"]
  22958. },
  22959. components: makePanels(parts2, panelConfigs),
  22960. slotBehaviours: SimpleBehaviours.unnamedEvents([runOnAttached(function(slotContainer) {
  22961. return SlotContainer.hideAllSlots(slotContainer);
  22962. })])
  22963. };
  22964. });
  22965. };
  22966. var setSidebar = function(sidebar, panelConfigs) {
  22967. var optSlider = Composing.getCurrent(sidebar);
  22968. optSlider.each(function(slider) {
  22969. return Replacing.set(slider, [makeSidebar(panelConfigs)]);
  22970. });
  22971. };
  22972. var toggleSidebar = function(sidebar, name2) {
  22973. var optSlider = Composing.getCurrent(sidebar);
  22974. optSlider.each(function(slider) {
  22975. var optSlotContainer = Composing.getCurrent(slider);
  22976. optSlotContainer.each(function(slotContainer) {
  22977. if (Sliding.hasGrown(slider)) {
  22978. if (SlotContainer.isShowing(slotContainer, name2)) {
  22979. Sliding.shrink(slider);
  22980. } else {
  22981. SlotContainer.hideAllSlots(slotContainer);
  22982. SlotContainer.showSlot(slotContainer, name2);
  22983. }
  22984. } else {
  22985. SlotContainer.hideAllSlots(slotContainer);
  22986. SlotContainer.showSlot(slotContainer, name2);
  22987. Sliding.grow(slider);
  22988. }
  22989. });
  22990. });
  22991. };
  22992. var whichSidebar = function(sidebar) {
  22993. var optSlider = Composing.getCurrent(sidebar);
  22994. return optSlider.bind(function(slider) {
  22995. var sidebarOpen = Sliding.isGrowing(slider) || Sliding.hasGrown(slider);
  22996. if (sidebarOpen) {
  22997. var optSlotContainer = Composing.getCurrent(slider);
  22998. return optSlotContainer.bind(function(slotContainer) {
  22999. return find$5(SlotContainer.getSlotNames(slotContainer), function(name2) {
  23000. return SlotContainer.isShowing(slotContainer, name2);
  23001. });
  23002. });
  23003. } else {
  23004. return Optional.none();
  23005. }
  23006. });
  23007. };
  23008. var fixSize = generate$6("FixSizeEvent");
  23009. var autoSize = generate$6("AutoSizeEvent");
  23010. var renderSidebar = function(spec) {
  23011. return {
  23012. uid: spec.uid,
  23013. dom: {
  23014. tag: "div",
  23015. classes: ["tox-sidebar"],
  23016. attributes: { role: "complementary" }
  23017. },
  23018. components: [{
  23019. dom: {
  23020. tag: "div",
  23021. classes: ["tox-sidebar__slider"]
  23022. },
  23023. components: [],
  23024. behaviours: derive$1([
  23025. Tabstopping.config({}),
  23026. Focusing.config({}),
  23027. Sliding.config({
  23028. dimension: { property: "width" },
  23029. closedClass: "tox-sidebar--sliding-closed",
  23030. openClass: "tox-sidebar--sliding-open",
  23031. shrinkingClass: "tox-sidebar--sliding-shrinking",
  23032. growingClass: "tox-sidebar--sliding-growing",
  23033. onShrunk: function(slider) {
  23034. var optSlotContainer = Composing.getCurrent(slider);
  23035. optSlotContainer.each(SlotContainer.hideAllSlots);
  23036. emit(slider, autoSize);
  23037. },
  23038. onGrown: function(slider) {
  23039. emit(slider, autoSize);
  23040. },
  23041. onStartGrow: function(slider) {
  23042. emitWith(slider, fixSize, { width: getRaw(slider.element, "width").getOr("") });
  23043. },
  23044. onStartShrink: function(slider) {
  23045. emitWith(slider, fixSize, { width: get$a(slider.element) + "px" });
  23046. }
  23047. }),
  23048. Replacing.config({}),
  23049. Composing.config({
  23050. find: function(comp) {
  23051. var children2 = Replacing.contents(comp);
  23052. return head(children2);
  23053. }
  23054. })
  23055. ])
  23056. }],
  23057. behaviours: derive$1([
  23058. ComposingConfigs.childAt(0),
  23059. config("sidebar-sliding-events", [
  23060. run$1(fixSize, function(comp, se) {
  23061. set$7(comp.element, "width", se.event.width);
  23062. }),
  23063. run$1(autoSize, function(comp, _se) {
  23064. remove$6(comp.element, "width");
  23065. })
  23066. ])
  23067. ])
  23068. };
  23069. };
  23070. var block = function(component, config2, state, getBusySpec2) {
  23071. set$8(component.element, "aria-busy", true);
  23072. var root = config2.getRoot(component).getOr(component);
  23073. var blockerBehaviours = derive$1([
  23074. Keying.config({
  23075. mode: "special",
  23076. onTab: function() {
  23077. return Optional.some(true);
  23078. },
  23079. onShiftTab: function() {
  23080. return Optional.some(true);
  23081. }
  23082. }),
  23083. Focusing.config({})
  23084. ]);
  23085. var blockSpec = getBusySpec2(root, blockerBehaviours);
  23086. var blocker = root.getSystem().build(blockSpec);
  23087. Replacing.append(root, premade(blocker));
  23088. if (blocker.hasConfigured(Keying) && config2.focus) {
  23089. Keying.focusIn(blocker);
  23090. }
  23091. if (!state.isBlocked()) {
  23092. config2.onBlock(component);
  23093. }
  23094. state.blockWith(function() {
  23095. return Replacing.remove(root, blocker);
  23096. });
  23097. };
  23098. var unblock = function(component, config2, state) {
  23099. remove$7(component.element, "aria-busy");
  23100. if (state.isBlocked()) {
  23101. config2.onUnblock(component);
  23102. }
  23103. state.clear();
  23104. };
  23105. var BlockingApis = Object.freeze({
  23106. __proto__: null,
  23107. block,
  23108. unblock
  23109. });
  23110. var BlockingSchema = [
  23111. defaultedFunction("getRoot", Optional.none),
  23112. defaultedBoolean("focus", true),
  23113. onHandler("onBlock"),
  23114. onHandler("onUnblock")
  23115. ];
  23116. var init$4 = function() {
  23117. var blocker = destroyable();
  23118. var blockWith = function(destroy) {
  23119. blocker.set({ destroy });
  23120. };
  23121. return nu$8({
  23122. readState: blocker.isSet,
  23123. blockWith,
  23124. clear: blocker.clear,
  23125. isBlocked: blocker.isSet
  23126. });
  23127. };
  23128. var BlockingState = Object.freeze({
  23129. __proto__: null,
  23130. init: init$4
  23131. });
  23132. var Blocking = create$8({
  23133. fields: BlockingSchema,
  23134. name: "blocking",
  23135. apis: BlockingApis,
  23136. state: BlockingState
  23137. });
  23138. var getAttrs = function(elem) {
  23139. var attributes = elem.dom.attributes !== void 0 ? elem.dom.attributes : [];
  23140. return foldl(attributes, function(b2, attr) {
  23141. var _a2;
  23142. if (attr.name === "class") {
  23143. return b2;
  23144. } else {
  23145. return __assign(__assign({}, b2), (_a2 = {}, _a2[attr.name] = attr.value, _a2));
  23146. }
  23147. }, {});
  23148. };
  23149. var getClasses = function(elem) {
  23150. return Array.prototype.slice.call(elem.dom.classList, 0);
  23151. };
  23152. var fromHtml = function(html2) {
  23153. var elem = SugarElement.fromHtml(html2);
  23154. var children$1 = children(elem);
  23155. var attrs = getAttrs(elem);
  23156. var classes2 = getClasses(elem);
  23157. var contents2 = children$1.length === 0 ? {} : { innerHtml: get$7(elem) };
  23158. return __assign({
  23159. tag: name$2(elem),
  23160. classes: classes2,
  23161. attributes: attrs
  23162. }, contents2);
  23163. };
  23164. var getBusySpec$1 = function(providerBackstage) {
  23165. return function(_root, _behaviours) {
  23166. return {
  23167. dom: {
  23168. tag: "div",
  23169. attributes: {
  23170. "aria-label": providerBackstage.translate("Loading..."),
  23171. "tabindex": "0"
  23172. },
  23173. classes: ["tox-throbber__busy-spinner"]
  23174. },
  23175. components: [{ dom: fromHtml('<div class="tox-spinner"><div></div><div></div><div></div></div>') }]
  23176. };
  23177. };
  23178. };
  23179. var focusBusyComponent = function(throbber) {
  23180. return Composing.getCurrent(throbber).each(function(comp) {
  23181. return focus$3(comp.element);
  23182. });
  23183. };
  23184. var toggleEditorTabIndex = function(editor, state) {
  23185. var tabIndexAttr = "tabindex";
  23186. var dataTabIndexAttr = "data-mce-" + tabIndexAttr;
  23187. Optional.from(editor.iframeElement).map(SugarElement.fromDom).each(function(iframe2) {
  23188. if (state) {
  23189. getOpt(iframe2, tabIndexAttr).each(function(tabIndex) {
  23190. return set$8(iframe2, dataTabIndexAttr, tabIndex);
  23191. });
  23192. set$8(iframe2, tabIndexAttr, -1);
  23193. } else {
  23194. remove$7(iframe2, tabIndexAttr);
  23195. getOpt(iframe2, dataTabIndexAttr).each(function(tabIndex) {
  23196. set$8(iframe2, tabIndexAttr, tabIndex);
  23197. remove$7(iframe2, dataTabIndexAttr);
  23198. });
  23199. }
  23200. });
  23201. };
  23202. var toggleThrobber = function(editor, comp, state, providerBackstage) {
  23203. var element2 = comp.element;
  23204. toggleEditorTabIndex(editor, state);
  23205. if (state) {
  23206. Blocking.block(comp, getBusySpec$1(providerBackstage));
  23207. remove$6(element2, "display");
  23208. remove$7(element2, "aria-hidden");
  23209. if (editor.hasFocus()) {
  23210. focusBusyComponent(comp);
  23211. }
  23212. } else {
  23213. var throbberFocus = Composing.getCurrent(comp).exists(function(busyComp) {
  23214. return hasFocus(busyComp.element);
  23215. });
  23216. Blocking.unblock(comp);
  23217. set$7(element2, "display", "none");
  23218. set$8(element2, "aria-hidden", "true");
  23219. if (throbberFocus) {
  23220. editor.focus();
  23221. }
  23222. }
  23223. };
  23224. var renderThrobber = function(spec) {
  23225. return {
  23226. uid: spec.uid,
  23227. dom: {
  23228. tag: "div",
  23229. attributes: { "aria-hidden": "true" },
  23230. classes: ["tox-throbber"],
  23231. styles: { display: "none" }
  23232. },
  23233. behaviours: derive$1([
  23234. Replacing.config({}),
  23235. Blocking.config({ focus: false }),
  23236. Composing.config({
  23237. find: function(comp) {
  23238. return head(comp.components());
  23239. }
  23240. })
  23241. ]),
  23242. components: []
  23243. };
  23244. };
  23245. var isFocusEvent = function(event) {
  23246. return event.type === "focusin";
  23247. };
  23248. var isPasteBinTarget = function(event) {
  23249. if (isFocusEvent(event)) {
  23250. var node = event.composed ? head(event.composedPath()) : Optional.from(event.target);
  23251. return node.map(SugarElement.fromDom).filter(isElement$2).exists(function(targetElm) {
  23252. return has(targetElm, "mce-pastebin");
  23253. });
  23254. } else {
  23255. return false;
  23256. }
  23257. };
  23258. var setup$7 = function(editor, lazyThrobber, sharedBackstage) {
  23259. var throbberState = Cell(false);
  23260. var timer = value$1();
  23261. var stealFocus = function(e) {
  23262. if (throbberState.get() && !isPasteBinTarget(e)) {
  23263. e.preventDefault();
  23264. focusBusyComponent(lazyThrobber());
  23265. editor.editorManager.setActive(editor);
  23266. }
  23267. };
  23268. if (!editor.inline) {
  23269. editor.on("PreInit", function() {
  23270. editor.dom.bind(editor.getWin(), "focusin", stealFocus);
  23271. editor.on("BeforeExecCommand", function(e) {
  23272. if (e.command.toLowerCase() === "mcefocus" && e.value !== true) {
  23273. stealFocus(e);
  23274. }
  23275. });
  23276. });
  23277. }
  23278. var toggle2 = function(state) {
  23279. if (state !== throbberState.get()) {
  23280. throbberState.set(state);
  23281. toggleThrobber(editor, lazyThrobber(), state, sharedBackstage.providers);
  23282. editor.fire("AfterProgressState", { state });
  23283. }
  23284. };
  23285. editor.on("ProgressState", function(e) {
  23286. timer.on(global$f.clearTimeout);
  23287. if (isNumber(e.time)) {
  23288. var timerId = global$f.setEditorTimeout(editor, function() {
  23289. return toggle2(e.state);
  23290. }, e.time);
  23291. timer.set(timerId);
  23292. } else {
  23293. toggle2(e.state);
  23294. timer.clear();
  23295. }
  23296. });
  23297. };
  23298. var generate$1 = function(xs, f) {
  23299. var init2 = {
  23300. len: 0,
  23301. list: []
  23302. };
  23303. var r2 = foldl(xs, function(b2, a) {
  23304. var value2 = f(a, b2.len);
  23305. return value2.fold(constant$1(b2), function(v) {
  23306. return {
  23307. len: v.finish,
  23308. list: b2.list.concat([v])
  23309. };
  23310. });
  23311. }, init2);
  23312. return r2.list;
  23313. };
  23314. var output = function(within, extra, withinWidth) {
  23315. return {
  23316. within,
  23317. extra,
  23318. withinWidth
  23319. };
  23320. };
  23321. var apportion = function(units2, total, len) {
  23322. var parray = generate$1(units2, function(unit, current) {
  23323. var width2 = len(unit);
  23324. return Optional.some({
  23325. element: unit,
  23326. start: current,
  23327. finish: current + width2,
  23328. width: width2
  23329. });
  23330. });
  23331. var within = filter$2(parray, function(unit) {
  23332. return unit.finish <= total;
  23333. });
  23334. var withinWidth = foldr(within, function(acc, el) {
  23335. return acc + el.width;
  23336. }, 0);
  23337. var extra = parray.slice(within.length);
  23338. return {
  23339. within,
  23340. extra,
  23341. withinWidth
  23342. };
  23343. };
  23344. var toUnit = function(parray) {
  23345. return map$2(parray, function(unit) {
  23346. return unit.element;
  23347. });
  23348. };
  23349. var fitLast = function(within, extra, withinWidth) {
  23350. var fits = toUnit(within.concat(extra));
  23351. return output(fits, [], withinWidth);
  23352. };
  23353. var overflow = function(within, extra, overflower, withinWidth) {
  23354. var fits = toUnit(within).concat([overflower]);
  23355. return output(fits, toUnit(extra), withinWidth);
  23356. };
  23357. var fitAll = function(within, extra, withinWidth) {
  23358. return output(toUnit(within), [], withinWidth);
  23359. };
  23360. var tryFit = function(total, units2, len) {
  23361. var divide = apportion(units2, total, len);
  23362. return divide.extra.length === 0 ? Optional.some(divide) : Optional.none();
  23363. };
  23364. var partition = function(total, units2, len, overflower) {
  23365. var divide = tryFit(total, units2, len).getOrThunk(function() {
  23366. return apportion(units2, total - len(overflower), len);
  23367. });
  23368. var within = divide.within;
  23369. var extra = divide.extra;
  23370. var withinWidth = divide.withinWidth;
  23371. if (extra.length === 1 && extra[0].width <= len(overflower)) {
  23372. return fitLast(within, extra, withinWidth);
  23373. } else if (extra.length >= 1) {
  23374. return overflow(within, extra, overflower, withinWidth);
  23375. } else {
  23376. return fitAll(within, extra, withinWidth);
  23377. }
  23378. };
  23379. var setGroups$1 = function(toolbar, storedGroups) {
  23380. var bGroups = map$2(storedGroups, function(g) {
  23381. return premade(g);
  23382. });
  23383. Toolbar.setGroups(toolbar, bGroups);
  23384. };
  23385. var findFocusedComp = function(comps) {
  23386. return findMap(comps, function(comp) {
  23387. return search(comp.element).bind(function(focusedElm) {
  23388. return comp.getSystem().getByDom(focusedElm).toOptional();
  23389. });
  23390. });
  23391. };
  23392. var refresh$2 = function(toolbar, detail, setOverflow) {
  23393. var builtGroups = detail.builtGroups.get();
  23394. if (builtGroups.length === 0) {
  23395. return;
  23396. }
  23397. var primary = getPartOrDie(toolbar, detail, "primary");
  23398. var overflowGroup = Coupling.getCoupled(toolbar, "overflowGroup");
  23399. set$7(primary.element, "visibility", "hidden");
  23400. var groups = builtGroups.concat([overflowGroup]);
  23401. var focusedComp = findFocusedComp(groups);
  23402. setOverflow([]);
  23403. setGroups$1(primary, groups);
  23404. var availableWidth = get$a(primary.element);
  23405. var overflows = partition(availableWidth, detail.builtGroups.get(), function(comp) {
  23406. return get$a(comp.element);
  23407. }, overflowGroup);
  23408. if (overflows.extra.length === 0) {
  23409. Replacing.remove(primary, overflowGroup);
  23410. setOverflow([]);
  23411. } else {
  23412. setGroups$1(primary, overflows.within);
  23413. setOverflow(overflows.extra);
  23414. }
  23415. remove$6(primary.element, "visibility");
  23416. reflow(primary.element);
  23417. focusedComp.each(Focusing.focus);
  23418. };
  23419. var schema$c = constant$1([
  23420. field("splitToolbarBehaviours", [Coupling]),
  23421. customField("builtGroups", function() {
  23422. return Cell([]);
  23423. })
  23424. ]);
  23425. var schema$b = constant$1([
  23426. markers$1(["overflowToggledClass"]),
  23427. optionFunction("getOverflowBounds"),
  23428. required$1("lazySink"),
  23429. customField("overflowGroups", function() {
  23430. return Cell([]);
  23431. })
  23432. ].concat(schema$c()));
  23433. var parts$7 = constant$1([
  23434. required({
  23435. factory: Toolbar,
  23436. schema: schema$e(),
  23437. name: "primary"
  23438. }),
  23439. external$1({
  23440. schema: schema$e(),
  23441. name: "overflow"
  23442. }),
  23443. external$1({ name: "overflow-button" }),
  23444. external$1({ name: "overflow-group" })
  23445. ]);
  23446. var expandable = constant$1(function(element2, available) {
  23447. setMax(element2, Math.floor(available));
  23448. });
  23449. var schema$a = constant$1([
  23450. markers$1(["toggledClass"]),
  23451. required$1("lazySink"),
  23452. requiredFunction("fetch"),
  23453. optionFunction("getBounds"),
  23454. optionObjOf("fireDismissalEventInstead", [defaulted("event", dismissRequested())]),
  23455. schema$y()
  23456. ]);
  23457. var parts$6 = constant$1([
  23458. external$1({
  23459. name: "button",
  23460. overrides: function(detail) {
  23461. return {
  23462. dom: { attributes: { "aria-haspopup": "true" } },
  23463. buttonBehaviours: derive$1([Toggling.config({
  23464. toggleClass: detail.markers.toggledClass,
  23465. aria: { mode: "expanded" },
  23466. toggleOnExecute: false
  23467. })])
  23468. };
  23469. }
  23470. }),
  23471. external$1({
  23472. factory: Toolbar,
  23473. schema: schema$e(),
  23474. name: "toolbar",
  23475. overrides: function(detail) {
  23476. return {
  23477. toolbarBehaviours: derive$1([Keying.config({
  23478. mode: "cyclic",
  23479. onEscape: function(comp) {
  23480. getPart(comp, detail, "button").each(Focusing.focus);
  23481. return Optional.none();
  23482. }
  23483. })])
  23484. };
  23485. }
  23486. })
  23487. ]);
  23488. var toggle = function(button2, externals) {
  23489. var toolbarSandbox = Coupling.getCoupled(button2, "toolbarSandbox");
  23490. if (Sandboxing.isOpen(toolbarSandbox)) {
  23491. Sandboxing.close(toolbarSandbox);
  23492. } else {
  23493. Sandboxing.open(toolbarSandbox, externals.toolbar());
  23494. }
  23495. };
  23496. var position = function(button2, toolbar, detail, layouts2) {
  23497. var bounds2 = detail.getBounds.map(function(bounder) {
  23498. return bounder();
  23499. });
  23500. var sink = detail.lazySink(button2).getOrDie();
  23501. Positioning.positionWithinBounds(sink, toolbar, {
  23502. anchor: {
  23503. type: "hotspot",
  23504. hotspot: button2,
  23505. layouts: layouts2,
  23506. overrides: { maxWidthFunction: expandable() }
  23507. }
  23508. }, bounds2);
  23509. };
  23510. var setGroups = function(button2, toolbar, detail, layouts2, groups) {
  23511. Toolbar.setGroups(toolbar, groups);
  23512. position(button2, toolbar, detail, layouts2);
  23513. Toggling.on(button2);
  23514. };
  23515. var makeSandbox = function(button2, spec, detail) {
  23516. var ariaOwner = manager();
  23517. var onOpen = function(sandbox, toolbar) {
  23518. detail.fetch().get(function(groups) {
  23519. setGroups(button2, toolbar, detail, spec.layouts, groups);
  23520. ariaOwner.link(button2.element);
  23521. Keying.focusIn(toolbar);
  23522. });
  23523. };
  23524. var onClose = function() {
  23525. Toggling.off(button2);
  23526. Focusing.focus(button2);
  23527. ariaOwner.unlink(button2.element);
  23528. };
  23529. return {
  23530. dom: {
  23531. tag: "div",
  23532. attributes: { id: ariaOwner.id }
  23533. },
  23534. behaviours: derive$1([
  23535. Keying.config({
  23536. mode: "special",
  23537. onEscape: function(comp) {
  23538. Sandboxing.close(comp);
  23539. return Optional.some(true);
  23540. }
  23541. }),
  23542. Sandboxing.config({
  23543. onOpen,
  23544. onClose,
  23545. isPartOf: function(container, data, queryElem) {
  23546. return isPartOf$1(data, queryElem) || isPartOf$1(button2, queryElem);
  23547. },
  23548. getAttachPoint: function() {
  23549. return detail.lazySink(button2).getOrDie();
  23550. }
  23551. }),
  23552. Receiving.config({
  23553. channels: __assign(__assign({}, receivingChannel$1(__assign({ isExtraPart: never }, detail.fireDismissalEventInstead.map(function(fe) {
  23554. return { fireEventInstead: { event: fe.event } };
  23555. }).getOr({})))), receivingChannel({
  23556. doReposition: function() {
  23557. Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox")).each(function(toolbar) {
  23558. position(button2, toolbar, detail, spec.layouts);
  23559. });
  23560. }
  23561. }))
  23562. })
  23563. ])
  23564. };
  23565. };
  23566. var factory$a = function(detail, components2, spec, externals) {
  23567. return __assign(__assign({}, Button.sketch(__assign(__assign({}, externals.button()), {
  23568. action: function(button2) {
  23569. toggle(button2, externals);
  23570. },
  23571. buttonBehaviours: SketchBehaviours.augment({ dump: externals.button().buttonBehaviours }, [Coupling.config({
  23572. others: {
  23573. toolbarSandbox: function(button2) {
  23574. return makeSandbox(button2, spec, detail);
  23575. }
  23576. }
  23577. })])
  23578. }))), {
  23579. apis: {
  23580. setGroups: function(button2, groups) {
  23581. Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox")).each(function(toolbar) {
  23582. setGroups(button2, toolbar, detail, spec.layouts, groups);
  23583. });
  23584. },
  23585. reposition: function(button2) {
  23586. Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox")).each(function(toolbar) {
  23587. position(button2, toolbar, detail, spec.layouts);
  23588. });
  23589. },
  23590. toggle: function(button2) {
  23591. toggle(button2, externals);
  23592. },
  23593. getToolbar: function(button2) {
  23594. return Sandboxing.getState(Coupling.getCoupled(button2, "toolbarSandbox"));
  23595. },
  23596. isOpen: function(button2) {
  23597. return Sandboxing.isOpen(Coupling.getCoupled(button2, "toolbarSandbox"));
  23598. }
  23599. }
  23600. });
  23601. };
  23602. var FloatingToolbarButton = composite({
  23603. name: "FloatingToolbarButton",
  23604. factory: factory$a,
  23605. configFields: schema$a(),
  23606. partFields: parts$6(),
  23607. apis: {
  23608. setGroups: function(apis, button2, groups) {
  23609. apis.setGroups(button2, groups);
  23610. },
  23611. reposition: function(apis, button2) {
  23612. apis.reposition(button2);
  23613. },
  23614. toggle: function(apis, button2) {
  23615. apis.toggle(button2);
  23616. },
  23617. getToolbar: function(apis, button2) {
  23618. return apis.getToolbar(button2);
  23619. },
  23620. isOpen: function(apis, button2) {
  23621. return apis.isOpen(button2);
  23622. }
  23623. }
  23624. });
  23625. var schema$9 = constant$1([
  23626. required$1("items"),
  23627. markers$1(["itemSelector"]),
  23628. field("tgroupBehaviours", [Keying])
  23629. ]);
  23630. var parts$5 = constant$1([group({
  23631. name: "items",
  23632. unit: "item"
  23633. })]);
  23634. var factory$9 = function(detail, components2, _spec, _externals) {
  23635. return {
  23636. uid: detail.uid,
  23637. dom: detail.dom,
  23638. components: components2,
  23639. behaviours: augment(detail.tgroupBehaviours, [Keying.config({
  23640. mode: "flow",
  23641. selector: detail.markers.itemSelector
  23642. })]),
  23643. domModification: { attributes: { role: "toolbar" } }
  23644. };
  23645. };
  23646. var ToolbarGroup = composite({
  23647. name: "ToolbarGroup",
  23648. configFields: schema$9(),
  23649. partFields: parts$5(),
  23650. factory: factory$9
  23651. });
  23652. var buildGroups = function(comps) {
  23653. return map$2(comps, function(g) {
  23654. return premade(g);
  23655. });
  23656. };
  23657. var refresh$1 = function(toolbar, memFloatingToolbarButton, detail) {
  23658. refresh$2(toolbar, detail, function(overflowGroups) {
  23659. detail.overflowGroups.set(overflowGroups);
  23660. memFloatingToolbarButton.getOpt(toolbar).each(function(floatingToolbarButton) {
  23661. FloatingToolbarButton.setGroups(floatingToolbarButton, buildGroups(overflowGroups));
  23662. });
  23663. });
  23664. };
  23665. var factory$8 = function(detail, components2, spec, externals) {
  23666. var memFloatingToolbarButton = record(FloatingToolbarButton.sketch({
  23667. fetch: function() {
  23668. return Future.nu(function(resolve) {
  23669. resolve(buildGroups(detail.overflowGroups.get()));
  23670. });
  23671. },
  23672. layouts: {
  23673. onLtr: function() {
  23674. return [
  23675. southwest$2,
  23676. southeast$2
  23677. ];
  23678. },
  23679. onRtl: function() {
  23680. return [
  23681. southeast$2,
  23682. southwest$2
  23683. ];
  23684. },
  23685. onBottomLtr: function() {
  23686. return [
  23687. northwest$2,
  23688. northeast$2
  23689. ];
  23690. },
  23691. onBottomRtl: function() {
  23692. return [
  23693. northeast$2,
  23694. northwest$2
  23695. ];
  23696. }
  23697. },
  23698. getBounds: spec.getOverflowBounds,
  23699. lazySink: detail.lazySink,
  23700. fireDismissalEventInstead: {},
  23701. markers: { toggledClass: detail.markers.overflowToggledClass },
  23702. parts: {
  23703. button: externals["overflow-button"](),
  23704. toolbar: externals.overflow()
  23705. }
  23706. }));
  23707. return {
  23708. uid: detail.uid,
  23709. dom: detail.dom,
  23710. components: components2,
  23711. behaviours: augment(detail.splitToolbarBehaviours, [Coupling.config({
  23712. others: {
  23713. overflowGroup: function() {
  23714. return ToolbarGroup.sketch(__assign(__assign({}, externals["overflow-group"]()), { items: [memFloatingToolbarButton.asSpec()] }));
  23715. }
  23716. }
  23717. })]),
  23718. apis: {
  23719. setGroups: function(toolbar, groups) {
  23720. detail.builtGroups.set(map$2(groups, toolbar.getSystem().build));
  23721. refresh$1(toolbar, memFloatingToolbarButton, detail);
  23722. },
  23723. refresh: function(toolbar) {
  23724. return refresh$1(toolbar, memFloatingToolbarButton, detail);
  23725. },
  23726. toggle: function(toolbar) {
  23727. memFloatingToolbarButton.getOpt(toolbar).each(function(floatingToolbarButton) {
  23728. FloatingToolbarButton.toggle(floatingToolbarButton);
  23729. });
  23730. },
  23731. isOpen: function(toolbar) {
  23732. return memFloatingToolbarButton.getOpt(toolbar).map(FloatingToolbarButton.isOpen).getOr(false);
  23733. },
  23734. reposition: function(toolbar) {
  23735. memFloatingToolbarButton.getOpt(toolbar).each(function(floatingToolbarButton) {
  23736. FloatingToolbarButton.reposition(floatingToolbarButton);
  23737. });
  23738. },
  23739. getOverflow: function(toolbar) {
  23740. return memFloatingToolbarButton.getOpt(toolbar).bind(FloatingToolbarButton.getToolbar);
  23741. }
  23742. },
  23743. domModification: { attributes: { role: "group" } }
  23744. };
  23745. };
  23746. var SplitFloatingToolbar = composite({
  23747. name: "SplitFloatingToolbar",
  23748. configFields: schema$b(),
  23749. partFields: parts$7(),
  23750. factory: factory$8,
  23751. apis: {
  23752. setGroups: function(apis, toolbar, groups) {
  23753. apis.setGroups(toolbar, groups);
  23754. },
  23755. refresh: function(apis, toolbar) {
  23756. apis.refresh(toolbar);
  23757. },
  23758. reposition: function(apis, toolbar) {
  23759. apis.reposition(toolbar);
  23760. },
  23761. toggle: function(apis, toolbar) {
  23762. apis.toggle(toolbar);
  23763. },
  23764. isOpen: function(apis, toolbar) {
  23765. return apis.isOpen(toolbar);
  23766. },
  23767. getOverflow: function(apis, toolbar) {
  23768. return apis.getOverflow(toolbar);
  23769. }
  23770. }
  23771. });
  23772. var schema$8 = constant$1([
  23773. markers$1([
  23774. "closedClass",
  23775. "openClass",
  23776. "shrinkingClass",
  23777. "growingClass",
  23778. "overflowToggledClass"
  23779. ]),
  23780. onHandler("onOpened"),
  23781. onHandler("onClosed")
  23782. ].concat(schema$c()));
  23783. var parts$4 = constant$1([
  23784. required({
  23785. factory: Toolbar,
  23786. schema: schema$e(),
  23787. name: "primary"
  23788. }),
  23789. required({
  23790. factory: Toolbar,
  23791. schema: schema$e(),
  23792. name: "overflow",
  23793. overrides: function(detail) {
  23794. return {
  23795. toolbarBehaviours: derive$1([
  23796. Sliding.config({
  23797. dimension: { property: "height" },
  23798. closedClass: detail.markers.closedClass,
  23799. openClass: detail.markers.openClass,
  23800. shrinkingClass: detail.markers.shrinkingClass,
  23801. growingClass: detail.markers.growingClass,
  23802. onShrunk: function(comp) {
  23803. getPart(comp, detail, "overflow-button").each(function(button2) {
  23804. Toggling.off(button2);
  23805. Focusing.focus(button2);
  23806. });
  23807. detail.onClosed(comp);
  23808. },
  23809. onGrown: function(comp) {
  23810. Keying.focusIn(comp);
  23811. detail.onOpened(comp);
  23812. },
  23813. onStartGrow: function(comp) {
  23814. getPart(comp, detail, "overflow-button").each(Toggling.on);
  23815. }
  23816. }),
  23817. Keying.config({
  23818. mode: "acyclic",
  23819. onEscape: function(comp) {
  23820. getPart(comp, detail, "overflow-button").each(Focusing.focus);
  23821. return Optional.some(true);
  23822. }
  23823. })
  23824. ])
  23825. };
  23826. }
  23827. }),
  23828. external$1({
  23829. name: "overflow-button",
  23830. overrides: function(detail) {
  23831. return {
  23832. buttonBehaviours: derive$1([Toggling.config({
  23833. toggleClass: detail.markers.overflowToggledClass,
  23834. aria: { mode: "pressed" },
  23835. toggleOnExecute: false
  23836. })])
  23837. };
  23838. }
  23839. }),
  23840. external$1({ name: "overflow-group" })
  23841. ]);
  23842. var isOpen = function(toolbar, detail) {
  23843. return getPart(toolbar, detail, "overflow").map(Sliding.hasGrown).getOr(false);
  23844. };
  23845. var toggleToolbar = function(toolbar, detail) {
  23846. getPart(toolbar, detail, "overflow-button").bind(function() {
  23847. return getPart(toolbar, detail, "overflow");
  23848. }).each(function(overf) {
  23849. refresh(toolbar, detail);
  23850. Sliding.toggleGrow(overf);
  23851. });
  23852. };
  23853. var refresh = function(toolbar, detail) {
  23854. getPart(toolbar, detail, "overflow").each(function(overflow2) {
  23855. refresh$2(toolbar, detail, function(groups) {
  23856. var builtGroups = map$2(groups, function(g) {
  23857. return premade(g);
  23858. });
  23859. Toolbar.setGroups(overflow2, builtGroups);
  23860. });
  23861. getPart(toolbar, detail, "overflow-button").each(function(button2) {
  23862. if (Sliding.hasGrown(overflow2)) {
  23863. Toggling.on(button2);
  23864. }
  23865. });
  23866. Sliding.refresh(overflow2);
  23867. });
  23868. };
  23869. var factory$7 = function(detail, components2, spec, externals) {
  23870. var toolbarToggleEvent = "alloy.toolbar.toggle";
  23871. var doSetGroups = function(toolbar, groups) {
  23872. var built = map$2(groups, toolbar.getSystem().build);
  23873. detail.builtGroups.set(built);
  23874. };
  23875. return {
  23876. uid: detail.uid,
  23877. dom: detail.dom,
  23878. components: components2,
  23879. behaviours: augment(detail.splitToolbarBehaviours, [
  23880. Coupling.config({
  23881. others: {
  23882. overflowGroup: function(toolbar) {
  23883. return ToolbarGroup.sketch(__assign(__assign({}, externals["overflow-group"]()), {
  23884. items: [Button.sketch(__assign(__assign({}, externals["overflow-button"]()), {
  23885. action: function(_button) {
  23886. emit(toolbar, toolbarToggleEvent);
  23887. }
  23888. }))]
  23889. }));
  23890. }
  23891. }
  23892. }),
  23893. config("toolbar-toggle-events", [run$1(toolbarToggleEvent, function(toolbar) {
  23894. toggleToolbar(toolbar, detail);
  23895. })])
  23896. ]),
  23897. apis: {
  23898. setGroups: function(toolbar, groups) {
  23899. doSetGroups(toolbar, groups);
  23900. refresh(toolbar, detail);
  23901. },
  23902. refresh: function(toolbar) {
  23903. return refresh(toolbar, detail);
  23904. },
  23905. toggle: function(toolbar) {
  23906. return toggleToolbar(toolbar, detail);
  23907. },
  23908. isOpen: function(toolbar) {
  23909. return isOpen(toolbar, detail);
  23910. }
  23911. },
  23912. domModification: { attributes: { role: "group" } }
  23913. };
  23914. };
  23915. var SplitSlidingToolbar = composite({
  23916. name: "SplitSlidingToolbar",
  23917. configFields: schema$8(),
  23918. partFields: parts$4(),
  23919. factory: factory$7,
  23920. apis: {
  23921. setGroups: function(apis, toolbar, groups) {
  23922. apis.setGroups(toolbar, groups);
  23923. },
  23924. refresh: function(apis, toolbar) {
  23925. apis.refresh(toolbar);
  23926. },
  23927. toggle: function(apis, toolbar) {
  23928. apis.toggle(toolbar);
  23929. },
  23930. isOpen: function(apis, toolbar) {
  23931. return apis.isOpen(toolbar);
  23932. }
  23933. }
  23934. });
  23935. var renderToolbarGroupCommon = function(toolbarGroup) {
  23936. var attributes = toolbarGroup.title.fold(function() {
  23937. return {};
  23938. }, function(title) {
  23939. return { attributes: { title } };
  23940. });
  23941. return {
  23942. dom: __assign({
  23943. tag: "div",
  23944. classes: ["tox-toolbar__group"]
  23945. }, attributes),
  23946. components: [ToolbarGroup.parts.items({})],
  23947. items: toolbarGroup.items,
  23948. markers: { itemSelector: "*:not(.tox-split-button) > .tox-tbtn:not([disabled]), .tox-split-button:not([disabled]), .tox-toolbar-nav-js:not([disabled])" },
  23949. tgroupBehaviours: derive$1([
  23950. Tabstopping.config({}),
  23951. Focusing.config({})
  23952. ])
  23953. };
  23954. };
  23955. var renderToolbarGroup = function(toolbarGroup) {
  23956. return ToolbarGroup.sketch(renderToolbarGroupCommon(toolbarGroup));
  23957. };
  23958. var getToolbarbehaviours = function(toolbarSpec, modeName) {
  23959. var onAttached = runOnAttached(function(component) {
  23960. var groups = map$2(toolbarSpec.initGroups, renderToolbarGroup);
  23961. Toolbar.setGroups(component, groups);
  23962. });
  23963. return derive$1([
  23964. DisablingConfigs.toolbarButton(toolbarSpec.providers.isDisabled),
  23965. receivingConfig(),
  23966. Keying.config({
  23967. mode: modeName,
  23968. onEscape: toolbarSpec.onEscape,
  23969. selector: ".tox-toolbar__group"
  23970. }),
  23971. config("toolbar-events", [onAttached])
  23972. ]);
  23973. };
  23974. var renderMoreToolbarCommon = function(toolbarSpec) {
  23975. var modeName = toolbarSpec.cyclicKeying ? "cyclic" : "acyclic";
  23976. return {
  23977. uid: toolbarSpec.uid,
  23978. dom: {
  23979. tag: "div",
  23980. classes: ["tox-toolbar-overlord"]
  23981. },
  23982. parts: {
  23983. "overflow-group": renderToolbarGroupCommon({
  23984. title: Optional.none(),
  23985. items: []
  23986. }),
  23987. "overflow-button": renderIconButtonSpec({
  23988. name: "more",
  23989. icon: Optional.some("more-drawer"),
  23990. disabled: false,
  23991. tooltip: Optional.some("More..."),
  23992. primary: false,
  23993. borderless: false
  23994. }, Optional.none(), toolbarSpec.providers)
  23995. },
  23996. splitToolbarBehaviours: getToolbarbehaviours(toolbarSpec, modeName)
  23997. };
  23998. };
  23999. var renderFloatingMoreToolbar = function(toolbarSpec) {
  24000. var baseSpec = renderMoreToolbarCommon(toolbarSpec);
  24001. var overflowXOffset = 4;
  24002. var primary = SplitFloatingToolbar.parts.primary({
  24003. dom: {
  24004. tag: "div",
  24005. classes: ["tox-toolbar__primary"]
  24006. }
  24007. });
  24008. return SplitFloatingToolbar.sketch(__assign(__assign({}, baseSpec), {
  24009. lazySink: toolbarSpec.getSink,
  24010. getOverflowBounds: function() {
  24011. var headerElem = toolbarSpec.moreDrawerData.lazyHeader().element;
  24012. var headerBounds = absolute$2(headerElem);
  24013. var docElem = documentElement(headerElem);
  24014. var docBounds = absolute$2(docElem);
  24015. var height2 = Math.max(docElem.dom.scrollHeight, docBounds.height);
  24016. return bounds(headerBounds.x + overflowXOffset, docBounds.y, headerBounds.width - overflowXOffset * 2, height2);
  24017. },
  24018. parts: __assign(__assign({}, baseSpec.parts), {
  24019. overflow: {
  24020. dom: {
  24021. tag: "div",
  24022. classes: ["tox-toolbar__overflow"],
  24023. attributes: toolbarSpec.attributes
  24024. }
  24025. }
  24026. }),
  24027. components: [primary],
  24028. markers: { overflowToggledClass: "tox-tbtn--enabled" }
  24029. }));
  24030. };
  24031. var renderSlidingMoreToolbar = function(toolbarSpec) {
  24032. var primary = SplitSlidingToolbar.parts.primary({
  24033. dom: {
  24034. tag: "div",
  24035. classes: ["tox-toolbar__primary"]
  24036. }
  24037. });
  24038. var overflow2 = SplitSlidingToolbar.parts.overflow({
  24039. dom: {
  24040. tag: "div",
  24041. classes: ["tox-toolbar__overflow"]
  24042. }
  24043. });
  24044. var baseSpec = renderMoreToolbarCommon(toolbarSpec);
  24045. return SplitSlidingToolbar.sketch(__assign(__assign({}, baseSpec), {
  24046. components: [
  24047. primary,
  24048. overflow2
  24049. ],
  24050. markers: {
  24051. openClass: "tox-toolbar__overflow--open",
  24052. closedClass: "tox-toolbar__overflow--closed",
  24053. growingClass: "tox-toolbar__overflow--growing",
  24054. shrinkingClass: "tox-toolbar__overflow--shrinking",
  24055. overflowToggledClass: "tox-tbtn--enabled"
  24056. },
  24057. onOpened: function(comp) {
  24058. comp.getSystem().broadcastOn([toolbarHeightChange()], { type: "opened" });
  24059. },
  24060. onClosed: function(comp) {
  24061. comp.getSystem().broadcastOn([toolbarHeightChange()], { type: "closed" });
  24062. }
  24063. }));
  24064. };
  24065. var renderToolbar = function(toolbarSpec) {
  24066. var modeName = toolbarSpec.cyclicKeying ? "cyclic" : "acyclic";
  24067. return Toolbar.sketch({
  24068. uid: toolbarSpec.uid,
  24069. dom: {
  24070. tag: "div",
  24071. classes: ["tox-toolbar"].concat(toolbarSpec.type === ToolbarMode.scrolling ? ["tox-toolbar--scrolling"] : [])
  24072. },
  24073. components: [Toolbar.parts.groups({})],
  24074. toolbarBehaviours: getToolbarbehaviours(toolbarSpec, modeName)
  24075. });
  24076. };
  24077. var factory$6 = function(detail, components2, _spec) {
  24078. var apis = {
  24079. getSocket: function(comp) {
  24080. return parts$a.getPart(comp, detail, "socket");
  24081. },
  24082. setSidebar: function(comp, panelConfigs) {
  24083. parts$a.getPart(comp, detail, "sidebar").each(function(sidebar) {
  24084. return setSidebar(sidebar, panelConfigs);
  24085. });
  24086. },
  24087. toggleSidebar: function(comp, name2) {
  24088. parts$a.getPart(comp, detail, "sidebar").each(function(sidebar) {
  24089. return toggleSidebar(sidebar, name2);
  24090. });
  24091. },
  24092. whichSidebar: function(comp) {
  24093. return parts$a.getPart(comp, detail, "sidebar").bind(whichSidebar).getOrNull();
  24094. },
  24095. getHeader: function(comp) {
  24096. return parts$a.getPart(comp, detail, "header");
  24097. },
  24098. getToolbar: function(comp) {
  24099. return parts$a.getPart(comp, detail, "toolbar");
  24100. },
  24101. setToolbar: function(comp, groups) {
  24102. parts$a.getPart(comp, detail, "toolbar").each(function(toolbar) {
  24103. toolbar.getApis().setGroups(toolbar, groups);
  24104. });
  24105. },
  24106. setToolbars: function(comp, toolbars) {
  24107. parts$a.getPart(comp, detail, "multiple-toolbar").each(function(mToolbar) {
  24108. CustomList.setItems(mToolbar, toolbars);
  24109. });
  24110. },
  24111. refreshToolbar: function(comp) {
  24112. var toolbar = parts$a.getPart(comp, detail, "toolbar");
  24113. toolbar.each(function(toolbar2) {
  24114. return toolbar2.getApis().refresh(toolbar2);
  24115. });
  24116. },
  24117. toggleToolbarDrawer: function(comp) {
  24118. parts$a.getPart(comp, detail, "toolbar").each(function(toolbar) {
  24119. mapFrom(toolbar.getApis().toggle, function(toggle2) {
  24120. return toggle2(toolbar);
  24121. });
  24122. });
  24123. },
  24124. isToolbarDrawerToggled: function(comp) {
  24125. return parts$a.getPart(comp, detail, "toolbar").bind(function(toolbar) {
  24126. return Optional.from(toolbar.getApis().isOpen).map(function(isOpen2) {
  24127. return isOpen2(toolbar);
  24128. });
  24129. }).getOr(false);
  24130. },
  24131. getThrobber: function(comp) {
  24132. return parts$a.getPart(comp, detail, "throbber");
  24133. },
  24134. focusToolbar: function(comp) {
  24135. var optToolbar = parts$a.getPart(comp, detail, "toolbar").orThunk(function() {
  24136. return parts$a.getPart(comp, detail, "multiple-toolbar");
  24137. });
  24138. optToolbar.each(function(toolbar) {
  24139. Keying.focusIn(toolbar);
  24140. });
  24141. },
  24142. setMenubar: function(comp, menus) {
  24143. parts$a.getPart(comp, detail, "menubar").each(function(menubar) {
  24144. SilverMenubar.setMenus(menubar, menus);
  24145. });
  24146. },
  24147. focusMenubar: function(comp) {
  24148. parts$a.getPart(comp, detail, "menubar").each(function(menubar) {
  24149. SilverMenubar.focus(menubar);
  24150. });
  24151. }
  24152. };
  24153. return {
  24154. uid: detail.uid,
  24155. dom: detail.dom,
  24156. components: components2,
  24157. apis,
  24158. behaviours: detail.behaviours
  24159. };
  24160. };
  24161. var partMenubar = partType.optional({
  24162. factory: SilverMenubar,
  24163. name: "menubar",
  24164. schema: [required$1("backstage")]
  24165. });
  24166. var toolbarFactory = function(spec) {
  24167. if (spec.type === ToolbarMode.sliding) {
  24168. return renderSlidingMoreToolbar;
  24169. } else if (spec.type === ToolbarMode.floating) {
  24170. return renderFloatingMoreToolbar;
  24171. } else {
  24172. return renderToolbar;
  24173. }
  24174. };
  24175. var partMultipleToolbar = partType.optional({
  24176. factory: {
  24177. sketch: function(spec) {
  24178. return CustomList.sketch({
  24179. uid: spec.uid,
  24180. dom: spec.dom,
  24181. listBehaviours: derive$1([Keying.config({
  24182. mode: "acyclic",
  24183. selector: ".tox-toolbar"
  24184. })]),
  24185. makeItem: function() {
  24186. return renderToolbar({
  24187. type: spec.type,
  24188. uid: generate$6("multiple-toolbar-item"),
  24189. cyclicKeying: false,
  24190. initGroups: [],
  24191. providers: spec.providers,
  24192. onEscape: function() {
  24193. spec.onEscape();
  24194. return Optional.some(true);
  24195. }
  24196. });
  24197. },
  24198. setupItem: function(_mToolbar, tc, data, _index) {
  24199. Toolbar.setGroups(tc, data);
  24200. },
  24201. shell: true
  24202. });
  24203. }
  24204. },
  24205. name: "multiple-toolbar",
  24206. schema: [
  24207. required$1("dom"),
  24208. required$1("onEscape")
  24209. ]
  24210. });
  24211. var partToolbar = partType.optional({
  24212. factory: {
  24213. sketch: function(spec) {
  24214. var renderer = toolbarFactory(spec);
  24215. var toolbarSpec = {
  24216. type: spec.type,
  24217. uid: spec.uid,
  24218. onEscape: function() {
  24219. spec.onEscape();
  24220. return Optional.some(true);
  24221. },
  24222. cyclicKeying: false,
  24223. initGroups: [],
  24224. getSink: spec.getSink,
  24225. providers: spec.providers,
  24226. moreDrawerData: {
  24227. lazyToolbar: spec.lazyToolbar,
  24228. lazyMoreButton: spec.lazyMoreButton,
  24229. lazyHeader: spec.lazyHeader
  24230. },
  24231. attributes: spec.attributes
  24232. };
  24233. return renderer(toolbarSpec);
  24234. }
  24235. },
  24236. name: "toolbar",
  24237. schema: [
  24238. required$1("dom"),
  24239. required$1("onEscape"),
  24240. required$1("getSink")
  24241. ]
  24242. });
  24243. var partHeader = partType.optional({
  24244. factory: { sketch: renderHeader },
  24245. name: "header",
  24246. schema: [required$1("dom")]
  24247. });
  24248. var partSocket = partType.optional({
  24249. name: "socket",
  24250. schema: [required$1("dom")]
  24251. });
  24252. var partSidebar = partType.optional({
  24253. factory: { sketch: renderSidebar },
  24254. name: "sidebar",
  24255. schema: [required$1("dom")]
  24256. });
  24257. var partThrobber = partType.optional({
  24258. factory: { sketch: renderThrobber },
  24259. name: "throbber",
  24260. schema: [required$1("dom")]
  24261. });
  24262. var OuterContainer = composite({
  24263. name: "OuterContainer",
  24264. factory: factory$6,
  24265. configFields: [
  24266. required$1("dom"),
  24267. required$1("behaviours")
  24268. ],
  24269. partFields: [
  24270. partHeader,
  24271. partMenubar,
  24272. partToolbar,
  24273. partMultipleToolbar,
  24274. partSocket,
  24275. partSidebar,
  24276. partThrobber
  24277. ],
  24278. apis: {
  24279. getSocket: function(apis, comp) {
  24280. return apis.getSocket(comp);
  24281. },
  24282. setSidebar: function(apis, comp, panelConfigs) {
  24283. apis.setSidebar(comp, panelConfigs);
  24284. },
  24285. toggleSidebar: function(apis, comp, name2) {
  24286. apis.toggleSidebar(comp, name2);
  24287. },
  24288. whichSidebar: function(apis, comp) {
  24289. return apis.whichSidebar(comp);
  24290. },
  24291. getHeader: function(apis, comp) {
  24292. return apis.getHeader(comp);
  24293. },
  24294. getToolbar: function(apis, comp) {
  24295. return apis.getToolbar(comp);
  24296. },
  24297. setToolbar: function(apis, comp, grps) {
  24298. var groups = map$2(grps, function(grp) {
  24299. return renderToolbarGroup(grp);
  24300. });
  24301. apis.setToolbar(comp, groups);
  24302. },
  24303. setToolbars: function(apis, comp, ts) {
  24304. var renderedToolbars = map$2(ts, function(g) {
  24305. return map$2(g, renderToolbarGroup);
  24306. });
  24307. apis.setToolbars(comp, renderedToolbars);
  24308. },
  24309. refreshToolbar: function(apis, comp) {
  24310. return apis.refreshToolbar(comp);
  24311. },
  24312. toggleToolbarDrawer: function(apis, comp) {
  24313. apis.toggleToolbarDrawer(comp);
  24314. },
  24315. isToolbarDrawerToggled: function(apis, comp) {
  24316. return apis.isToolbarDrawerToggled(comp);
  24317. },
  24318. getThrobber: function(apis, comp) {
  24319. return apis.getThrobber(comp);
  24320. },
  24321. setMenubar: function(apis, comp, menus) {
  24322. apis.setMenubar(comp, menus);
  24323. },
  24324. focusMenubar: function(apis, comp) {
  24325. apis.focusMenubar(comp);
  24326. },
  24327. focusToolbar: function(apis, comp) {
  24328. apis.focusToolbar(comp);
  24329. }
  24330. }
  24331. });
  24332. var defaultMenubar = "file edit view insert format tools table help";
  24333. var defaultMenus = {
  24334. file: {
  24335. title: "File",
  24336. items: "newdocument restoredraft | preview | export print | deleteallconversations"
  24337. },
  24338. edit: {
  24339. title: "Edit",
  24340. items: "undo redo | cut copy paste pastetext | selectall | searchreplace"
  24341. },
  24342. view: {
  24343. title: "View",
  24344. items: "code | visualaid visualchars visualblocks | spellchecker | preview fullscreen | showcomments"
  24345. },
  24346. insert: {
  24347. title: "Insert",
  24348. items: "image link media addcomment pageembed template codesample inserttable | charmap emoticons hr | pagebreak nonbreaking anchor toc | insertdatetime"
  24349. },
  24350. format: {
  24351. title: "Format",
  24352. items: "bold italic underline strikethrough superscript subscript codeformat | formats blockformats fontformats fontsizes align lineheight | forecolor backcolor | language | removeformat"
  24353. },
  24354. tools: {
  24355. title: "Tools",
  24356. items: "spellchecker spellcheckerlanguage | a11ycheck code wordcount"
  24357. },
  24358. table: {
  24359. title: "Table",
  24360. items: "inserttable | cell row column | advtablesort | tableprops deletetable"
  24361. },
  24362. help: {
  24363. title: "Help",
  24364. items: "help"
  24365. }
  24366. };
  24367. var make = function(menu2, registry, editor) {
  24368. var removedMenuItems = getRemovedMenuItems(editor).split(/[ ,]/);
  24369. return {
  24370. text: menu2.title,
  24371. getItems: function() {
  24372. return bind$3(menu2.items, function(i) {
  24373. var itemName = i.toLowerCase();
  24374. if (itemName.trim().length === 0) {
  24375. return [];
  24376. } else if (exists(removedMenuItems, function(removedMenuItem) {
  24377. return removedMenuItem === itemName;
  24378. })) {
  24379. return [];
  24380. } else if (itemName === "separator" || itemName === "|") {
  24381. return [{ type: "separator" }];
  24382. } else if (registry.menuItems[itemName]) {
  24383. return [registry.menuItems[itemName]];
  24384. } else {
  24385. return [];
  24386. }
  24387. });
  24388. }
  24389. };
  24390. };
  24391. var parseItemsString = function(items) {
  24392. if (typeof items === "string") {
  24393. return items.split(" ");
  24394. }
  24395. return items;
  24396. };
  24397. var identifyMenus = function(editor, registry) {
  24398. var rawMenuData = __assign(__assign({}, defaultMenus), registry.menus);
  24399. var userDefinedMenus = keys(registry.menus).length > 0;
  24400. var menubar = registry.menubar === void 0 || registry.menubar === true ? parseItemsString(defaultMenubar) : parseItemsString(registry.menubar === false ? "" : registry.menubar);
  24401. var validMenus = filter$2(menubar, function(menuName) {
  24402. var isDefaultMenu = has$2(defaultMenus, menuName);
  24403. if (userDefinedMenus) {
  24404. return isDefaultMenu || get$e(registry.menus, menuName).exists(function(menu2) {
  24405. return has$2(menu2, "items");
  24406. });
  24407. } else {
  24408. return isDefaultMenu;
  24409. }
  24410. });
  24411. var menus = map$2(validMenus, function(menuName) {
  24412. var menuData = rawMenuData[menuName];
  24413. return make({
  24414. title: menuData.title,
  24415. items: parseItemsString(menuData.items)
  24416. }, registry, editor);
  24417. });
  24418. return filter$2(menus, function(menu2) {
  24419. var isNotSeparator = function(item2) {
  24420. return item2.type !== "separator";
  24421. };
  24422. return menu2.getItems().length > 0 && exists(menu2.getItems(), isNotSeparator);
  24423. });
  24424. };
  24425. var fireSkinLoaded = function(editor) {
  24426. var done = function() {
  24427. editor._skinLoaded = true;
  24428. fireSkinLoaded$1(editor);
  24429. };
  24430. return function() {
  24431. if (editor.initialized) {
  24432. done();
  24433. } else {
  24434. editor.on("init", done);
  24435. }
  24436. };
  24437. };
  24438. var fireSkinLoadError = function(editor, err) {
  24439. return function() {
  24440. return fireSkinLoadError$1(editor, { message: err });
  24441. };
  24442. };
  24443. var loadStylesheet = function(editor, stylesheetUrl, styleSheetLoader) {
  24444. return new global$c(function(resolve, reject) {
  24445. styleSheetLoader.load(stylesheetUrl, resolve, reject);
  24446. editor.on("remove", function() {
  24447. return styleSheetLoader.unload(stylesheetUrl);
  24448. });
  24449. });
  24450. };
  24451. var loadUiSkins = function(editor, skinUrl) {
  24452. var skinUiCss = skinUrl + "/skin.min.css";
  24453. return loadStylesheet(editor, skinUiCss, editor.ui.styleSheetLoader);
  24454. };
  24455. var loadShadowDomUiSkins = function(editor, skinUrl) {
  24456. var isInShadowRoot$1 = isInShadowRoot(SugarElement.fromDom(editor.getElement()));
  24457. if (isInShadowRoot$1) {
  24458. var shadowDomSkinCss = skinUrl + "/skin.shadowdom.min.css";
  24459. return loadStylesheet(editor, shadowDomSkinCss, global$b.DOM.styleSheetLoader);
  24460. } else {
  24461. return global$c.resolve();
  24462. }
  24463. };
  24464. var loadSkin = function(isInline, editor) {
  24465. var skinUrl = getSkinUrl(editor);
  24466. if (skinUrl) {
  24467. editor.contentCSS.push(skinUrl + (isInline ? "/content.inline" : "/content") + ".min.css");
  24468. }
  24469. if (isSkinDisabled(editor) === false && isString(skinUrl)) {
  24470. global$c.all([
  24471. loadUiSkins(editor, skinUrl),
  24472. loadShadowDomUiSkins(editor, skinUrl)
  24473. ]).then(fireSkinLoaded(editor), fireSkinLoadError(editor, "Skin could not be loaded"));
  24474. } else {
  24475. fireSkinLoaded(editor)();
  24476. }
  24477. };
  24478. var iframe = curry(loadSkin, false);
  24479. var inline = curry(loadSkin, true);
  24480. var onSetupFormatToggle = function(editor, name2) {
  24481. return function(api2) {
  24482. var boundCallback = unbindable();
  24483. var init2 = function() {
  24484. api2.setActive(editor.formatter.match(name2));
  24485. var binding = editor.formatter.formatChanged(name2, api2.setActive);
  24486. boundCallback.set(binding);
  24487. };
  24488. editor.initialized ? init2() : editor.once("init", init2);
  24489. return function() {
  24490. editor.off("init", init2);
  24491. boundCallback.clear();
  24492. };
  24493. };
  24494. };
  24495. var onSetupEvent = function(editor, event, f) {
  24496. return function(api2) {
  24497. var handleEvent = function() {
  24498. return f(api2);
  24499. };
  24500. var init2 = function() {
  24501. f(api2);
  24502. editor.on(event, handleEvent);
  24503. };
  24504. editor.initialized ? init2() : editor.once("init", init2);
  24505. return function() {
  24506. editor.off("init", init2);
  24507. editor.off(event, handleEvent);
  24508. };
  24509. };
  24510. };
  24511. var onActionToggleFormat$1 = function(editor) {
  24512. return function(rawItem) {
  24513. return function() {
  24514. editor.undoManager.transact(function() {
  24515. editor.focus();
  24516. editor.execCommand("mceToggleFormat", false, rawItem.format);
  24517. });
  24518. };
  24519. };
  24520. };
  24521. var onActionExecCommand = function(editor, command) {
  24522. return function() {
  24523. return editor.execCommand(command);
  24524. };
  24525. };
  24526. var generateSelectItems = function(_editor, backstage, spec) {
  24527. var generateItem = function(rawItem, response, disabled, value2) {
  24528. var translatedText = backstage.shared.providers.translate(rawItem.title);
  24529. if (rawItem.type === "separator") {
  24530. return Optional.some({
  24531. type: "separator",
  24532. text: translatedText
  24533. });
  24534. } else if (rawItem.type === "submenu") {
  24535. var items = bind$3(rawItem.getStyleItems(), function(si) {
  24536. return validate(si, response, value2);
  24537. });
  24538. if (response === 0 && items.length <= 0) {
  24539. return Optional.none();
  24540. } else {
  24541. return Optional.some({
  24542. type: "nestedmenuitem",
  24543. text: translatedText,
  24544. disabled: items.length <= 0,
  24545. getSubmenuItems: function() {
  24546. return bind$3(rawItem.getStyleItems(), function(si) {
  24547. return validate(si, response, value2);
  24548. });
  24549. }
  24550. });
  24551. }
  24552. } else {
  24553. return Optional.some(__assign({
  24554. type: "togglemenuitem",
  24555. text: translatedText,
  24556. icon: rawItem.icon,
  24557. active: rawItem.isSelected(value2),
  24558. disabled,
  24559. onAction: spec.onAction(rawItem)
  24560. }, rawItem.getStylePreview().fold(function() {
  24561. return {};
  24562. }, function(preview) {
  24563. return { meta: { style: preview } };
  24564. })));
  24565. }
  24566. };
  24567. var validate = function(item2, response, value2) {
  24568. var invalid = item2.type === "formatter" && spec.isInvalid(item2);
  24569. if (response === 0) {
  24570. return invalid ? [] : generateItem(item2, response, false, value2).toArray();
  24571. } else {
  24572. return generateItem(item2, response, invalid, value2).toArray();
  24573. }
  24574. };
  24575. var validateItems = function(preItems) {
  24576. var value2 = spec.getCurrentValue();
  24577. var response = spec.shouldHide ? 0 : 1;
  24578. return bind$3(preItems, function(item2) {
  24579. return validate(item2, response, value2);
  24580. });
  24581. };
  24582. var getFetch2 = function(backstage2, getStyleItems) {
  24583. return function(comp, callback) {
  24584. var preItems = getStyleItems();
  24585. var items = validateItems(preItems);
  24586. var menu2 = build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage2, false);
  24587. callback(menu2);
  24588. };
  24589. };
  24590. return {
  24591. validateItems,
  24592. getFetch: getFetch2
  24593. };
  24594. };
  24595. var createMenuItems = function(editor, backstage, spec) {
  24596. var dataset2 = spec.dataset;
  24597. var getStyleItems = dataset2.type === "basic" ? function() {
  24598. return map$2(dataset2.data, function(d) {
  24599. return processBasic(d, spec.isSelectedFor, spec.getPreviewFor);
  24600. });
  24601. } : dataset2.getData;
  24602. return {
  24603. items: generateSelectItems(editor, backstage, spec),
  24604. getStyleItems
  24605. };
  24606. };
  24607. var createSelectButton = function(editor, backstage, spec) {
  24608. var _a2 = createMenuItems(editor, backstage, spec), items = _a2.items, getStyleItems = _a2.getStyleItems;
  24609. var getApi2 = function(comp) {
  24610. return { getComponent: constant$1(comp) };
  24611. };
  24612. var onSetup = onSetupEvent(editor, "NodeChange", function(api2) {
  24613. var comp = api2.getComponent();
  24614. spec.updateText(comp);
  24615. });
  24616. return renderCommonDropdown({
  24617. text: spec.icon.isSome() ? Optional.none() : spec.text,
  24618. icon: spec.icon,
  24619. tooltip: Optional.from(spec.tooltip),
  24620. role: Optional.none(),
  24621. fetch: items.getFetch(backstage, getStyleItems),
  24622. onSetup,
  24623. getApi: getApi2,
  24624. columns: 1,
  24625. presets: "normal",
  24626. classes: spec.icon.isSome() ? [] : ["bespoke"],
  24627. dropdownBehaviours: []
  24628. }, "tox-tbtn", backstage.shared);
  24629. };
  24630. var process = function(rawFormats) {
  24631. return map$2(rawFormats, function(item2) {
  24632. var title = item2, format = item2;
  24633. var values2 = item2.split("=");
  24634. if (values2.length > 1) {
  24635. title = values2[0];
  24636. format = values2[1];
  24637. }
  24638. return {
  24639. title,
  24640. format
  24641. };
  24642. });
  24643. };
  24644. var buildBasicStaticDataset = function(data) {
  24645. return {
  24646. type: "basic",
  24647. data
  24648. };
  24649. };
  24650. var Delimiter;
  24651. (function(Delimiter2) {
  24652. Delimiter2[Delimiter2["SemiColon"] = 0] = "SemiColon";
  24653. Delimiter2[Delimiter2["Space"] = 1] = "Space";
  24654. })(Delimiter || (Delimiter = {}));
  24655. var split = function(rawFormats, delimiter) {
  24656. if (delimiter === Delimiter.SemiColon) {
  24657. return rawFormats.replace(/;$/, "").split(";");
  24658. } else {
  24659. return rawFormats.split(" ");
  24660. }
  24661. };
  24662. var buildBasicSettingsDataset = function(editor, settingName, defaults, delimiter) {
  24663. var rawFormats = editor.getParam(settingName, defaults, "string");
  24664. var data = process(split(rawFormats, delimiter));
  24665. return {
  24666. type: "basic",
  24667. data
  24668. };
  24669. };
  24670. var alignMenuItems = [
  24671. {
  24672. title: "Left",
  24673. icon: "align-left",
  24674. format: "alignleft",
  24675. command: "JustifyLeft"
  24676. },
  24677. {
  24678. title: "Center",
  24679. icon: "align-center",
  24680. format: "aligncenter",
  24681. command: "JustifyCenter"
  24682. },
  24683. {
  24684. title: "Right",
  24685. icon: "align-right",
  24686. format: "alignright",
  24687. command: "JustifyRight"
  24688. },
  24689. {
  24690. title: "Justify",
  24691. icon: "align-justify",
  24692. format: "alignjustify",
  24693. command: "JustifyFull"
  24694. }
  24695. ];
  24696. var getSpec$4 = function(editor) {
  24697. var getMatchingValue = function() {
  24698. return find$5(alignMenuItems, function(item2) {
  24699. return editor.formatter.match(item2.format);
  24700. });
  24701. };
  24702. var isSelectedFor = function(format) {
  24703. return function() {
  24704. return editor.formatter.match(format);
  24705. };
  24706. };
  24707. var getPreviewFor = function(_format) {
  24708. return Optional.none;
  24709. };
  24710. var updateSelectMenuIcon = function(comp) {
  24711. var match = getMatchingValue();
  24712. var alignment = match.fold(constant$1("left"), function(item2) {
  24713. return item2.title.toLowerCase();
  24714. });
  24715. emitWith(comp, updateMenuIcon, { icon: "align-" + alignment });
  24716. };
  24717. var dataset2 = buildBasicStaticDataset(alignMenuItems);
  24718. var onAction = function(rawItem) {
  24719. return function() {
  24720. return find$5(alignMenuItems, function(item2) {
  24721. return item2.format === rawItem.format;
  24722. }).each(function(item2) {
  24723. return editor.execCommand(item2.command);
  24724. });
  24725. };
  24726. };
  24727. return {
  24728. tooltip: "Align",
  24729. text: Optional.none(),
  24730. icon: Optional.some("align-left"),
  24731. isSelectedFor,
  24732. getCurrentValue: Optional.none,
  24733. getPreviewFor,
  24734. onAction,
  24735. updateText: updateSelectMenuIcon,
  24736. dataset: dataset2,
  24737. shouldHide: false,
  24738. isInvalid: function(item2) {
  24739. return !editor.formatter.canApply(item2.format);
  24740. }
  24741. };
  24742. };
  24743. var createAlignSelect = function(editor, backstage) {
  24744. return createSelectButton(editor, backstage, getSpec$4(editor));
  24745. };
  24746. var alignSelectMenu = function(editor, backstage) {
  24747. var menuItems = createMenuItems(editor, backstage, getSpec$4(editor));
  24748. editor.ui.registry.addNestedMenuItem("align", {
  24749. text: backstage.shared.providers.translate("Align"),
  24750. getSubmenuItems: function() {
  24751. return menuItems.items.validateItems(menuItems.getStyleItems());
  24752. }
  24753. });
  24754. };
  24755. 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";
  24756. var systemStackFonts = [
  24757. "-apple-system",
  24758. "Segoe UI",
  24759. "Roboto",
  24760. "Helvetica Neue",
  24761. "sans-serif"
  24762. ];
  24763. var splitFonts = function(fontFamily) {
  24764. var fonts = fontFamily.split(/\s*,\s*/);
  24765. return map$2(fonts, function(font) {
  24766. return font.replace(/^['"]+|['"]+$/g, "");
  24767. });
  24768. };
  24769. var isSystemFontStack = function(fontFamily) {
  24770. var matchesSystemStack = function() {
  24771. var fonts = splitFonts(fontFamily.toLowerCase());
  24772. return forall(systemStackFonts, function(font) {
  24773. return fonts.indexOf(font.toLowerCase()) > -1;
  24774. });
  24775. };
  24776. return fontFamily.indexOf("-apple-system") === 0 && matchesSystemStack();
  24777. };
  24778. var getSpec$3 = function(editor) {
  24779. var systemFont = "System Font";
  24780. var getMatchingValue = function() {
  24781. var getFirstFont = function(fontFamily2) {
  24782. return fontFamily2 ? splitFonts(fontFamily2)[0] : "";
  24783. };
  24784. var fontFamily = editor.queryCommandValue("FontName");
  24785. var items = dataset2.data;
  24786. var font = fontFamily ? fontFamily.toLowerCase() : "";
  24787. var matchOpt = find$5(items, function(item2) {
  24788. var format = item2.format;
  24789. return format.toLowerCase() === font || getFirstFont(format).toLowerCase() === getFirstFont(font).toLowerCase();
  24790. }).orThunk(function() {
  24791. return someIf(isSystemFontStack(font), {
  24792. title: systemFont,
  24793. format: font
  24794. });
  24795. });
  24796. return {
  24797. matchOpt,
  24798. font: fontFamily
  24799. };
  24800. };
  24801. var isSelectedFor = function(item2) {
  24802. return function(valueOpt) {
  24803. return valueOpt.exists(function(value2) {
  24804. return value2.format === item2;
  24805. });
  24806. };
  24807. };
  24808. var getCurrentValue = function() {
  24809. var matchOpt = getMatchingValue().matchOpt;
  24810. return matchOpt;
  24811. };
  24812. var getPreviewFor = function(item2) {
  24813. return function() {
  24814. return Optional.some({
  24815. tag: "div",
  24816. styles: item2.indexOf("dings") === -1 ? { "font-family": item2 } : {}
  24817. });
  24818. };
  24819. };
  24820. var onAction = function(rawItem) {
  24821. return function() {
  24822. editor.undoManager.transact(function() {
  24823. editor.focus();
  24824. editor.execCommand("FontName", false, rawItem.format);
  24825. });
  24826. };
  24827. };
  24828. var updateSelectMenuText = function(comp) {
  24829. var _a2 = getMatchingValue(), matchOpt = _a2.matchOpt, font = _a2.font;
  24830. var text2 = matchOpt.fold(constant$1(font), function(item2) {
  24831. return item2.title;
  24832. });
  24833. emitWith(comp, updateMenuText, { text: text2 });
  24834. };
  24835. var dataset2 = buildBasicSettingsDataset(editor, "font_formats", defaultFontsFormats, Delimiter.SemiColon);
  24836. return {
  24837. tooltip: "Fonts",
  24838. text: Optional.some(systemFont),
  24839. icon: Optional.none(),
  24840. isSelectedFor,
  24841. getCurrentValue,
  24842. getPreviewFor,
  24843. onAction,
  24844. updateText: updateSelectMenuText,
  24845. dataset: dataset2,
  24846. shouldHide: false,
  24847. isInvalid: never
  24848. };
  24849. };
  24850. var createFontSelect = function(editor, backstage) {
  24851. return createSelectButton(editor, backstage, getSpec$3(editor));
  24852. };
  24853. var fontSelectMenu = function(editor, backstage) {
  24854. var menuItems = createMenuItems(editor, backstage, getSpec$3(editor));
  24855. editor.ui.registry.addNestedMenuItem("fontformats", {
  24856. text: backstage.shared.providers.translate("Fonts"),
  24857. getSubmenuItems: function() {
  24858. return menuItems.items.validateItems(menuItems.getStyleItems());
  24859. }
  24860. });
  24861. };
  24862. var defaultFontsizeFormats = "8pt 10pt 12pt 14pt 18pt 24pt 36pt";
  24863. var legacyFontSizes = {
  24864. "8pt": "1",
  24865. "10pt": "2",
  24866. "12pt": "3",
  24867. "14pt": "4",
  24868. "18pt": "5",
  24869. "24pt": "6",
  24870. "36pt": "7"
  24871. };
  24872. var keywordFontSizes = {
  24873. "xx-small": "7pt",
  24874. "x-small": "8pt",
  24875. "small": "10pt",
  24876. "medium": "12pt",
  24877. "large": "14pt",
  24878. "x-large": "18pt",
  24879. "xx-large": "24pt"
  24880. };
  24881. var round = function(number2, precision) {
  24882. var factor = Math.pow(10, precision);
  24883. return Math.round(number2 * factor) / factor;
  24884. };
  24885. var toPt = function(fontSize, precision) {
  24886. if (/[0-9.]+px$/.test(fontSize)) {
  24887. return round(parseInt(fontSize, 10) * 72 / 96, precision || 0) + "pt";
  24888. } else {
  24889. return get$e(keywordFontSizes, fontSize).getOr(fontSize);
  24890. }
  24891. };
  24892. var toLegacy = function(fontSize) {
  24893. return get$e(legacyFontSizes, fontSize).getOr("");
  24894. };
  24895. var getSpec$2 = function(editor) {
  24896. var getMatchingValue = function() {
  24897. var matchOpt = Optional.none();
  24898. var items = dataset2.data;
  24899. var fontSize = editor.queryCommandValue("FontSize");
  24900. if (fontSize) {
  24901. var _loop_1 = function(precision2) {
  24902. var pt = toPt(fontSize, precision2);
  24903. var legacy = toLegacy(pt);
  24904. matchOpt = find$5(items, function(item2) {
  24905. return item2.format === fontSize || item2.format === pt || item2.format === legacy;
  24906. });
  24907. };
  24908. for (var precision = 3; matchOpt.isNone() && precision >= 0; precision--) {
  24909. _loop_1(precision);
  24910. }
  24911. }
  24912. return {
  24913. matchOpt,
  24914. size: fontSize
  24915. };
  24916. };
  24917. var isSelectedFor = function(item2) {
  24918. return function(valueOpt) {
  24919. return valueOpt.exists(function(value2) {
  24920. return value2.format === item2;
  24921. });
  24922. };
  24923. };
  24924. var getCurrentValue = function() {
  24925. var matchOpt = getMatchingValue().matchOpt;
  24926. return matchOpt;
  24927. };
  24928. var getPreviewFor = constant$1(Optional.none);
  24929. var onAction = function(rawItem) {
  24930. return function() {
  24931. editor.undoManager.transact(function() {
  24932. editor.focus();
  24933. editor.execCommand("FontSize", false, rawItem.format);
  24934. });
  24935. };
  24936. };
  24937. var updateSelectMenuText = function(comp) {
  24938. var _a2 = getMatchingValue(), matchOpt = _a2.matchOpt, size = _a2.size;
  24939. var text2 = matchOpt.fold(constant$1(size), function(match) {
  24940. return match.title;
  24941. });
  24942. emitWith(comp, updateMenuText, { text: text2 });
  24943. };
  24944. var dataset2 = buildBasicSettingsDataset(editor, "fontsize_formats", defaultFontsizeFormats, Delimiter.Space);
  24945. return {
  24946. tooltip: "Font sizes",
  24947. text: Optional.some("12pt"),
  24948. icon: Optional.none(),
  24949. isSelectedFor,
  24950. getPreviewFor,
  24951. getCurrentValue,
  24952. onAction,
  24953. updateText: updateSelectMenuText,
  24954. dataset: dataset2,
  24955. shouldHide: false,
  24956. isInvalid: never
  24957. };
  24958. };
  24959. var createFontsizeSelect = function(editor, backstage) {
  24960. return createSelectButton(editor, backstage, getSpec$2(editor));
  24961. };
  24962. var fontsizeSelectMenu = function(editor, backstage) {
  24963. var menuItems = createMenuItems(editor, backstage, getSpec$2(editor));
  24964. editor.ui.registry.addNestedMenuItem("fontsizes", {
  24965. text: "Font sizes",
  24966. getSubmenuItems: function() {
  24967. return menuItems.items.validateItems(menuItems.getStyleItems());
  24968. }
  24969. });
  24970. };
  24971. var findNearest = function(editor, getStyles) {
  24972. var styles = getStyles();
  24973. var formats = map$2(styles, function(style) {
  24974. return style.format;
  24975. });
  24976. return Optional.from(editor.formatter.closest(formats)).bind(function(fmt) {
  24977. return find$5(styles, function(data) {
  24978. return data.format === fmt;
  24979. });
  24980. }).orThunk(function() {
  24981. return someIf(editor.formatter.match("p"), {
  24982. title: "Paragraph",
  24983. format: "p"
  24984. });
  24985. });
  24986. };
  24987. var defaultBlocks = "Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Preformatted=pre";
  24988. var getSpec$1 = function(editor) {
  24989. var fallbackFormat = "Paragraph";
  24990. var isSelectedFor = function(format) {
  24991. return function() {
  24992. return editor.formatter.match(format);
  24993. };
  24994. };
  24995. var getPreviewFor = function(format) {
  24996. return function() {
  24997. var fmt = editor.formatter.get(format);
  24998. return Optional.some({
  24999. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || "div" : "div",
  25000. styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
  25001. });
  25002. };
  25003. };
  25004. var updateSelectMenuText = function(comp) {
  25005. var detectedFormat = findNearest(editor, function() {
  25006. return dataset2.data;
  25007. });
  25008. var text2 = detectedFormat.fold(constant$1(fallbackFormat), function(fmt) {
  25009. return fmt.title;
  25010. });
  25011. emitWith(comp, updateMenuText, { text: text2 });
  25012. };
  25013. var dataset2 = buildBasicSettingsDataset(editor, "block_formats", defaultBlocks, Delimiter.SemiColon);
  25014. return {
  25015. tooltip: "Blocks",
  25016. text: Optional.some(fallbackFormat),
  25017. icon: Optional.none(),
  25018. isSelectedFor,
  25019. getCurrentValue: Optional.none,
  25020. getPreviewFor,
  25021. onAction: onActionToggleFormat$1(editor),
  25022. updateText: updateSelectMenuText,
  25023. dataset: dataset2,
  25024. shouldHide: false,
  25025. isInvalid: function(item2) {
  25026. return !editor.formatter.canApply(item2.format);
  25027. }
  25028. };
  25029. };
  25030. var createFormatSelect = function(editor, backstage) {
  25031. return createSelectButton(editor, backstage, getSpec$1(editor));
  25032. };
  25033. var formatSelectMenu = function(editor, backstage) {
  25034. var menuItems = createMenuItems(editor, backstage, getSpec$1(editor));
  25035. editor.ui.registry.addNestedMenuItem("blockformats", {
  25036. text: "Blocks",
  25037. getSubmenuItems: function() {
  25038. return menuItems.items.validateItems(menuItems.getStyleItems());
  25039. }
  25040. });
  25041. };
  25042. var getSpec = function(editor, dataset2) {
  25043. var fallbackFormat = "Paragraph";
  25044. var isSelectedFor = function(format) {
  25045. return function() {
  25046. return editor.formatter.match(format);
  25047. };
  25048. };
  25049. var getPreviewFor = function(format) {
  25050. return function() {
  25051. var fmt = editor.formatter.get(format);
  25052. return fmt !== void 0 ? Optional.some({
  25053. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || "div" : "div",
  25054. styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
  25055. }) : Optional.none();
  25056. };
  25057. };
  25058. var updateSelectMenuText = function(comp) {
  25059. var getFormatItems = function(fmt) {
  25060. var subs2 = fmt.items;
  25061. return subs2 !== void 0 && subs2.length > 0 ? bind$3(subs2, getFormatItems) : [{
  25062. title: fmt.title,
  25063. format: fmt.format
  25064. }];
  25065. };
  25066. var flattenedItems = bind$3(getStyleFormats(editor), getFormatItems);
  25067. var detectedFormat = findNearest(editor, constant$1(flattenedItems));
  25068. var text2 = detectedFormat.fold(constant$1(fallbackFormat), function(fmt) {
  25069. return fmt.title;
  25070. });
  25071. emitWith(comp, updateMenuText, { text: text2 });
  25072. };
  25073. return {
  25074. tooltip: "Formats",
  25075. text: Optional.some(fallbackFormat),
  25076. icon: Optional.none(),
  25077. isSelectedFor,
  25078. getCurrentValue: Optional.none,
  25079. getPreviewFor,
  25080. onAction: onActionToggleFormat$1(editor),
  25081. updateText: updateSelectMenuText,
  25082. shouldHide: editor.getParam("style_formats_autohide", false, "boolean"),
  25083. isInvalid: function(item2) {
  25084. return !editor.formatter.canApply(item2.format);
  25085. },
  25086. dataset: dataset2
  25087. };
  25088. };
  25089. var createStyleSelect = function(editor, backstage) {
  25090. var dataset2 = __assign({ type: "advanced" }, backstage.styleselect);
  25091. return createSelectButton(editor, backstage, getSpec(editor, dataset2));
  25092. };
  25093. var styleSelectMenu = function(editor, backstage) {
  25094. var dataset2 = __assign({ type: "advanced" }, backstage.styleselect);
  25095. var menuItems = createMenuItems(editor, backstage, getSpec(editor, dataset2));
  25096. editor.ui.registry.addNestedMenuItem("formats", {
  25097. text: "Formats",
  25098. getSubmenuItems: function() {
  25099. return menuItems.items.validateItems(menuItems.getStyleItems());
  25100. }
  25101. });
  25102. };
  25103. var events$3 = function(reflectingConfig, reflectingState) {
  25104. var update = function(component, data) {
  25105. reflectingConfig.updateState.each(function(updateState) {
  25106. var newState = updateState(component, data);
  25107. reflectingState.set(newState);
  25108. });
  25109. reflectingConfig.renderComponents.each(function(renderComponents2) {
  25110. var newComponents = renderComponents2(data, reflectingState.get());
  25111. var newChildren = map$2(newComponents, component.getSystem().build);
  25112. replaceChildren(component, newChildren);
  25113. });
  25114. };
  25115. return derive$2([
  25116. run$1(receive(), function(component, message) {
  25117. var receivingData = message;
  25118. if (!receivingData.universal) {
  25119. var channel = reflectingConfig.channel;
  25120. if (contains$2(receivingData.channels, channel)) {
  25121. update(component, receivingData.data);
  25122. }
  25123. }
  25124. }),
  25125. runOnAttached(function(comp, _se) {
  25126. reflectingConfig.initialData.each(function(rawData) {
  25127. update(comp, rawData);
  25128. });
  25129. })
  25130. ]);
  25131. };
  25132. var ActiveReflecting = Object.freeze({
  25133. __proto__: null,
  25134. events: events$3
  25135. });
  25136. var getState = function(component, replaceConfig, reflectState) {
  25137. return reflectState;
  25138. };
  25139. var ReflectingApis = Object.freeze({
  25140. __proto__: null,
  25141. getState
  25142. });
  25143. var ReflectingSchema = [
  25144. required$1("channel"),
  25145. option("renderComponents"),
  25146. option("updateState"),
  25147. option("initialData")
  25148. ];
  25149. var init$3 = function() {
  25150. var cell = Cell(Optional.none());
  25151. var clear2 = function() {
  25152. return cell.set(Optional.none());
  25153. };
  25154. var readState = function() {
  25155. return cell.get().getOr("none");
  25156. };
  25157. return {
  25158. readState,
  25159. get: cell.get,
  25160. set: cell.set,
  25161. clear: clear2
  25162. };
  25163. };
  25164. var ReflectingState = Object.freeze({
  25165. __proto__: null,
  25166. init: init$3
  25167. });
  25168. var Reflecting = create$8({
  25169. fields: ReflectingSchema,
  25170. name: "reflecting",
  25171. active: ActiveReflecting,
  25172. apis: ReflectingApis,
  25173. state: ReflectingState
  25174. });
  25175. var schema$7 = constant$1([
  25176. required$1("toggleClass"),
  25177. required$1("fetch"),
  25178. onStrictHandler("onExecute"),
  25179. defaulted("getHotspot", Optional.some),
  25180. defaulted("getAnchorOverrides", constant$1({})),
  25181. schema$y(),
  25182. onStrictHandler("onItemExecute"),
  25183. option("lazySink"),
  25184. required$1("dom"),
  25185. onHandler("onOpen"),
  25186. field("splitDropdownBehaviours", [
  25187. Coupling,
  25188. Keying,
  25189. Focusing
  25190. ]),
  25191. defaulted("matchWidth", false),
  25192. defaulted("useMinWidth", false),
  25193. defaulted("eventOrder", {}),
  25194. option("role")
  25195. ].concat(sandboxFields()));
  25196. var arrowPart = required({
  25197. factory: Button,
  25198. schema: [required$1("dom")],
  25199. name: "arrow",
  25200. defaults: function() {
  25201. return { buttonBehaviours: derive$1([Focusing.revoke()]) };
  25202. },
  25203. overrides: function(detail) {
  25204. return {
  25205. dom: {
  25206. tag: "span",
  25207. attributes: { role: "presentation" }
  25208. },
  25209. action: function(arrow) {
  25210. arrow.getSystem().getByUid(detail.uid).each(emitExecute);
  25211. },
  25212. buttonBehaviours: derive$1([Toggling.config({
  25213. toggleOnExecute: false,
  25214. toggleClass: detail.toggleClass
  25215. })])
  25216. };
  25217. }
  25218. });
  25219. var buttonPart = required({
  25220. factory: Button,
  25221. schema: [required$1("dom")],
  25222. name: "button",
  25223. defaults: function() {
  25224. return { buttonBehaviours: derive$1([Focusing.revoke()]) };
  25225. },
  25226. overrides: function(detail) {
  25227. return {
  25228. dom: {
  25229. tag: "span",
  25230. attributes: { role: "presentation" }
  25231. },
  25232. action: function(btn) {
  25233. btn.getSystem().getByUid(detail.uid).each(function(splitDropdown) {
  25234. detail.onExecute(splitDropdown, btn);
  25235. });
  25236. }
  25237. };
  25238. }
  25239. });
  25240. var parts$3 = constant$1([
  25241. arrowPart,
  25242. buttonPart,
  25243. optional({
  25244. factory: {
  25245. sketch: function(spec) {
  25246. return {
  25247. uid: spec.uid,
  25248. dom: {
  25249. tag: "span",
  25250. styles: { display: "none" },
  25251. attributes: { "aria-hidden": "true" },
  25252. innerHtml: spec.text
  25253. }
  25254. };
  25255. }
  25256. },
  25257. schema: [required$1("text")],
  25258. name: "aria-descriptor"
  25259. }),
  25260. external$1({
  25261. schema: [tieredMenuMarkers()],
  25262. name: "menu",
  25263. defaults: function(detail) {
  25264. return {
  25265. onExecute: function(tmenu, item2) {
  25266. tmenu.getSystem().getByUid(detail.uid).each(function(splitDropdown) {
  25267. detail.onItemExecute(splitDropdown, tmenu, item2);
  25268. });
  25269. }
  25270. };
  25271. }
  25272. }),
  25273. partType$1()
  25274. ]);
  25275. var factory$5 = function(detail, components2, spec, externals) {
  25276. var _a2;
  25277. var switchToMenu = function(sandbox) {
  25278. Composing.getCurrent(sandbox).each(function(current) {
  25279. Highlighting.highlightFirst(current);
  25280. Keying.focusIn(current);
  25281. });
  25282. };
  25283. var action = function(component) {
  25284. var onOpenSync = switchToMenu;
  25285. togglePopup(detail, identity$1, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  25286. };
  25287. var openMenu = function(comp) {
  25288. action(comp);
  25289. return Optional.some(true);
  25290. };
  25291. var executeOnButton = function(comp) {
  25292. var button2 = getPartOrDie(comp, detail, "button");
  25293. emitExecute(button2);
  25294. return Optional.some(true);
  25295. };
  25296. var buttonEvents = __assign(__assign({}, derive$2([runOnAttached(function(component, _simulatedEvent) {
  25297. var ariaDescriptor = getPart(component, detail, "aria-descriptor");
  25298. ariaDescriptor.each(function(descriptor) {
  25299. var descriptorId = generate$6("aria");
  25300. set$8(descriptor.element, "id", descriptorId);
  25301. set$8(component.element, "aria-describedby", descriptorId);
  25302. });
  25303. })])), events$a(Optional.some(action)));
  25304. var apis = {
  25305. repositionMenus: function(comp) {
  25306. if (Toggling.isOn(comp)) {
  25307. repositionMenus(comp);
  25308. }
  25309. }
  25310. };
  25311. return {
  25312. uid: detail.uid,
  25313. dom: detail.dom,
  25314. components: components2,
  25315. apis,
  25316. eventOrder: __assign(__assign({}, detail.eventOrder), (_a2 = {}, _a2[execute$5()] = [
  25317. "disabling",
  25318. "toggling",
  25319. "alloy.base.behaviour"
  25320. ], _a2)),
  25321. events: buttonEvents,
  25322. behaviours: augment(detail.splitDropdownBehaviours, [
  25323. Coupling.config({
  25324. others: {
  25325. sandbox: function(hotspot) {
  25326. var arrow = getPartOrDie(hotspot, detail, "arrow");
  25327. var extras = {
  25328. onOpen: function() {
  25329. Toggling.on(arrow);
  25330. Toggling.on(hotspot);
  25331. },
  25332. onClose: function() {
  25333. Toggling.off(arrow);
  25334. Toggling.off(hotspot);
  25335. }
  25336. };
  25337. return makeSandbox$1(detail, hotspot, extras);
  25338. }
  25339. }
  25340. }),
  25341. Keying.config({
  25342. mode: "special",
  25343. onSpace: executeOnButton,
  25344. onEnter: executeOnButton,
  25345. onDown: openMenu
  25346. }),
  25347. Focusing.config({}),
  25348. Toggling.config({
  25349. toggleOnExecute: false,
  25350. aria: { mode: "expanded" }
  25351. })
  25352. ]),
  25353. domModification: {
  25354. attributes: {
  25355. "role": detail.role.getOr("button"),
  25356. "aria-haspopup": true
  25357. }
  25358. }
  25359. };
  25360. };
  25361. var SplitDropdown = composite({
  25362. name: "SplitDropdown",
  25363. configFields: schema$7(),
  25364. partFields: parts$3(),
  25365. factory: factory$5,
  25366. apis: {
  25367. repositionMenus: function(apis, comp) {
  25368. return apis.repositionMenus(comp);
  25369. }
  25370. }
  25371. });
  25372. var getButtonApi = function(component) {
  25373. return {
  25374. isDisabled: function() {
  25375. return Disabling.isDisabled(component);
  25376. },
  25377. setDisabled: function(state) {
  25378. return Disabling.set(component, state);
  25379. }
  25380. };
  25381. };
  25382. var getToggleApi = function(component) {
  25383. return {
  25384. setActive: function(state) {
  25385. Toggling.set(component, state);
  25386. },
  25387. isActive: function() {
  25388. return Toggling.isOn(component);
  25389. },
  25390. isDisabled: function() {
  25391. return Disabling.isDisabled(component);
  25392. },
  25393. setDisabled: function(state) {
  25394. return Disabling.set(component, state);
  25395. }
  25396. };
  25397. };
  25398. var getTooltipAttributes = function(tooltip, providersBackstage) {
  25399. return tooltip.map(function(tooltip2) {
  25400. return {
  25401. "aria-label": providersBackstage.translate(tooltip2),
  25402. "title": providersBackstage.translate(tooltip2)
  25403. };
  25404. }).getOr({});
  25405. };
  25406. var focusButtonEvent = generate$6("focus-button");
  25407. var renderCommonStructure = function(icon, text2, tooltip, receiver, behaviours2, providersBackstage) {
  25408. var _d;
  25409. return {
  25410. dom: {
  25411. tag: "button",
  25412. classes: ["tox-tbtn"].concat(text2.isSome() ? ["tox-tbtn--select"] : []),
  25413. attributes: getTooltipAttributes(tooltip, providersBackstage)
  25414. },
  25415. components: componentRenderPipeline([
  25416. icon.map(function(iconName) {
  25417. return renderIconFromPack(iconName, providersBackstage.icons);
  25418. }),
  25419. text2.map(function(text3) {
  25420. return renderLabel$1(text3, "tox-tbtn", providersBackstage);
  25421. })
  25422. ]),
  25423. eventOrder: (_d = {}, _d[mousedown()] = [
  25424. "focusing",
  25425. "alloy.base.behaviour",
  25426. "common-button-display-events"
  25427. ], _d),
  25428. buttonBehaviours: derive$1([
  25429. DisablingConfigs.toolbarButton(providersBackstage.isDisabled),
  25430. receivingConfig(),
  25431. config("common-button-display-events", [run$1(mousedown(), function(button2, se) {
  25432. se.event.prevent();
  25433. emit(button2, focusButtonEvent);
  25434. })])
  25435. ].concat(receiver.map(function(r2) {
  25436. return Reflecting.config({
  25437. channel: r2,
  25438. initialData: {
  25439. icon,
  25440. text: text2
  25441. },
  25442. renderComponents: function(data, _state) {
  25443. return componentRenderPipeline([
  25444. data.icon.map(function(iconName) {
  25445. return renderIconFromPack(iconName, providersBackstage.icons);
  25446. }),
  25447. data.text.map(function(text3) {
  25448. return renderLabel$1(text3, "tox-tbtn", providersBackstage);
  25449. })
  25450. ]);
  25451. }
  25452. });
  25453. }).toArray()).concat(behaviours2.getOr([])))
  25454. };
  25455. };
  25456. var renderFloatingToolbarButton = function(spec, backstage, identifyButtons2, attributes) {
  25457. var sharedBackstage = backstage.shared;
  25458. return FloatingToolbarButton.sketch({
  25459. lazySink: sharedBackstage.getSink,
  25460. fetch: function() {
  25461. return Future.nu(function(resolve) {
  25462. resolve(map$2(identifyButtons2(spec.items), renderToolbarGroup));
  25463. });
  25464. },
  25465. markers: { toggledClass: "tox-tbtn--enabled" },
  25466. parts: {
  25467. button: renderCommonStructure(spec.icon, spec.text, spec.tooltip, Optional.none(), Optional.none(), sharedBackstage.providers),
  25468. toolbar: {
  25469. dom: {
  25470. tag: "div",
  25471. classes: ["tox-toolbar__overflow"],
  25472. attributes
  25473. }
  25474. }
  25475. }
  25476. });
  25477. };
  25478. var renderCommonToolbarButton = function(spec, specialisation, providersBackstage) {
  25479. var editorOffCell = Cell(noop);
  25480. var structure = renderCommonStructure(spec.icon, spec.text, spec.tooltip, Optional.none(), Optional.none(), providersBackstage);
  25481. return Button.sketch({
  25482. dom: structure.dom,
  25483. components: structure.components,
  25484. eventOrder: toolbarButtonEventOrder,
  25485. buttonBehaviours: derive$1([
  25486. config("toolbar-button-events", [
  25487. onToolbarButtonExecute({
  25488. onAction: spec.onAction,
  25489. getApi: specialisation.getApi
  25490. }),
  25491. onControlAttached(specialisation, editorOffCell),
  25492. onControlDetached(specialisation, editorOffCell)
  25493. ]),
  25494. DisablingConfigs.toolbarButton(function() {
  25495. return spec.disabled || providersBackstage.isDisabled();
  25496. }),
  25497. receivingConfig()
  25498. ].concat(specialisation.toolbarButtonBehaviours))
  25499. });
  25500. };
  25501. var renderToolbarButton = function(spec, providersBackstage) {
  25502. return renderToolbarButtonWith(spec, providersBackstage, []);
  25503. };
  25504. var renderToolbarButtonWith = function(spec, providersBackstage, bonusEvents) {
  25505. return renderCommonToolbarButton(spec, {
  25506. toolbarButtonBehaviours: [].concat(bonusEvents.length > 0 ? [config("toolbarButtonWith", bonusEvents)] : []),
  25507. getApi: getButtonApi,
  25508. onSetup: spec.onSetup
  25509. }, providersBackstage);
  25510. };
  25511. var renderToolbarToggleButton = function(spec, providersBackstage) {
  25512. return renderToolbarToggleButtonWith(spec, providersBackstage, []);
  25513. };
  25514. var renderToolbarToggleButtonWith = function(spec, providersBackstage, bonusEvents) {
  25515. return deepMerge(renderCommonToolbarButton(spec, {
  25516. toolbarButtonBehaviours: [
  25517. Replacing.config({}),
  25518. Toggling.config({
  25519. toggleClass: "tox-tbtn--enabled",
  25520. aria: { mode: "pressed" },
  25521. toggleOnExecute: false
  25522. })
  25523. ].concat(bonusEvents.length > 0 ? [config("toolbarToggleButtonWith", bonusEvents)] : []),
  25524. getApi: getToggleApi,
  25525. onSetup: spec.onSetup
  25526. }, providersBackstage));
  25527. };
  25528. var fetchChoices = function(getApi2, spec, providersBackstage) {
  25529. return function(comp) {
  25530. return Future.nu(function(callback) {
  25531. return spec.fetch(callback);
  25532. }).map(function(items) {
  25533. return Optional.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$6("menu-value"), items, function(value2) {
  25534. spec.onItemAction(getApi2(comp), value2);
  25535. }, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, spec.select.getOr(never), providersBackstage), {
  25536. movement: deriveMenuMovement(spec.columns, spec.presets),
  25537. menuBehaviours: SimpleBehaviours.unnamedEvents(spec.columns !== "auto" ? [] : [runOnAttached(function(comp2, _se) {
  25538. detectSize(comp2, 4, classForPreset(spec.presets)).each(function(_d) {
  25539. var numRows = _d.numRows, numColumns = _d.numColumns;
  25540. Keying.setGridSize(comp2, numRows, numColumns);
  25541. });
  25542. })])
  25543. })));
  25544. });
  25545. };
  25546. };
  25547. var renderSplitButton = function(spec, sharedBackstage) {
  25548. var _d;
  25549. var displayChannel = generate$6("channel-update-split-dropdown-display");
  25550. var getApi2 = function(comp) {
  25551. return {
  25552. isDisabled: function() {
  25553. return Disabling.isDisabled(comp);
  25554. },
  25555. setDisabled: function(state) {
  25556. return Disabling.set(comp, state);
  25557. },
  25558. setIconFill: function(id, value2) {
  25559. descendant(comp.element, 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function(underlinePath) {
  25560. set$8(underlinePath, "fill", value2);
  25561. });
  25562. },
  25563. setIconStroke: function(id, value2) {
  25564. descendant(comp.element, 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function(underlinePath) {
  25565. set$8(underlinePath, "stroke", value2);
  25566. });
  25567. },
  25568. setActive: function(state) {
  25569. set$8(comp.element, "aria-pressed", state);
  25570. descendant(comp.element, "span").each(function(button2) {
  25571. comp.getSystem().getByDom(button2).each(function(buttonComp) {
  25572. return Toggling.set(buttonComp, state);
  25573. });
  25574. });
  25575. },
  25576. isActive: function() {
  25577. return descendant(comp.element, "span").exists(function(button2) {
  25578. return comp.getSystem().getByDom(button2).exists(Toggling.isOn);
  25579. });
  25580. }
  25581. };
  25582. };
  25583. var editorOffCell = Cell(noop);
  25584. var specialisation = {
  25585. getApi: getApi2,
  25586. onSetup: spec.onSetup
  25587. };
  25588. return SplitDropdown.sketch({
  25589. dom: {
  25590. tag: "div",
  25591. classes: ["tox-split-button"],
  25592. attributes: __assign({ "aria-pressed": false }, getTooltipAttributes(spec.tooltip, sharedBackstage.providers))
  25593. },
  25594. onExecute: function(button2) {
  25595. spec.onAction(getApi2(button2));
  25596. },
  25597. onItemExecute: function(_a2, _b, _c) {
  25598. },
  25599. splitDropdownBehaviours: derive$1([
  25600. DisablingConfigs.splitButton(sharedBackstage.providers.isDisabled),
  25601. receivingConfig(),
  25602. config("split-dropdown-events", [
  25603. run$1(focusButtonEvent, Focusing.focus),
  25604. onControlAttached(specialisation, editorOffCell),
  25605. onControlDetached(specialisation, editorOffCell)
  25606. ]),
  25607. Unselecting.config({})
  25608. ]),
  25609. eventOrder: (_d = {}, _d[attachedToDom()] = [
  25610. "alloy.base.behaviour",
  25611. "split-dropdown-events"
  25612. ], _d),
  25613. toggleClass: "tox-tbtn--enabled",
  25614. lazySink: sharedBackstage.getSink,
  25615. fetch: fetchChoices(getApi2, spec, sharedBackstage.providers),
  25616. parts: { menu: part(false, spec.columns, spec.presets) },
  25617. components: [
  25618. SplitDropdown.parts.button(renderCommonStructure(spec.icon, spec.text, Optional.none(), Optional.some(displayChannel), Optional.some([Toggling.config({
  25619. toggleClass: "tox-tbtn--enabled",
  25620. toggleOnExecute: false
  25621. })]), sharedBackstage.providers)),
  25622. SplitDropdown.parts.arrow({
  25623. dom: {
  25624. tag: "button",
  25625. classes: [
  25626. "tox-tbtn",
  25627. "tox-split-button__chevron"
  25628. ],
  25629. innerHtml: get$1("chevron-down", sharedBackstage.providers.icons)
  25630. },
  25631. buttonBehaviours: derive$1([
  25632. DisablingConfigs.splitButton(sharedBackstage.providers.isDisabled),
  25633. receivingConfig(),
  25634. addFocusableBehaviour()
  25635. ])
  25636. }),
  25637. SplitDropdown.parts["aria-descriptor"]({ text: sharedBackstage.providers.translate("To open the popup, press Shift+Enter") })
  25638. ]
  25639. });
  25640. };
  25641. var defaultToolbar = [
  25642. {
  25643. name: "history",
  25644. items: [
  25645. "undo",
  25646. "redo"
  25647. ]
  25648. },
  25649. {
  25650. name: "styles",
  25651. items: ["styleselect"]
  25652. },
  25653. {
  25654. name: "formatting",
  25655. items: [
  25656. "bold",
  25657. "italic"
  25658. ]
  25659. },
  25660. {
  25661. name: "alignment",
  25662. items: [
  25663. "alignleft",
  25664. "aligncenter",
  25665. "alignright",
  25666. "alignjustify"
  25667. ]
  25668. },
  25669. {
  25670. name: "indentation",
  25671. items: [
  25672. "outdent",
  25673. "indent"
  25674. ]
  25675. },
  25676. {
  25677. name: "permanent pen",
  25678. items: ["permanentpen"]
  25679. },
  25680. {
  25681. name: "comments",
  25682. items: ["addcomment"]
  25683. }
  25684. ];
  25685. var renderFromBridge = function(bridgeBuilder, render2) {
  25686. return function(spec, extras, editor) {
  25687. var internal2 = bridgeBuilder(spec).mapError(function(errInfo) {
  25688. return formatError(errInfo);
  25689. }).getOrDie();
  25690. return render2(internal2, extras, editor);
  25691. };
  25692. };
  25693. var types = {
  25694. button: renderFromBridge(createToolbarButton, function(s, extras) {
  25695. return renderToolbarButton(s, extras.backstage.shared.providers);
  25696. }),
  25697. togglebutton: renderFromBridge(createToggleButton, function(s, extras) {
  25698. return renderToolbarToggleButton(s, extras.backstage.shared.providers);
  25699. }),
  25700. menubutton: renderFromBridge(createMenuButton, function(s, extras) {
  25701. return renderMenuButton(s, "tox-tbtn", extras.backstage, Optional.none());
  25702. }),
  25703. splitbutton: renderFromBridge(createSplitButton, function(s, extras) {
  25704. return renderSplitButton(s, extras.backstage.shared);
  25705. }),
  25706. grouptoolbarbutton: renderFromBridge(createGroupToolbarButton, function(s, extras, editor) {
  25707. var _a2;
  25708. var buttons = editor.ui.registry.getAll().buttons;
  25709. var identify = function(toolbar) {
  25710. return identifyButtons(editor, {
  25711. buttons,
  25712. toolbar,
  25713. allowToolbarGroups: false
  25714. }, extras, Optional.none());
  25715. };
  25716. var attributes = (_a2 = {}, _a2[Attribute] = extras.backstage.shared.header.isPositionedAtTop() ? AttributeValue.TopToBottom : AttributeValue.BottomToTop, _a2);
  25717. switch (getToolbarMode(editor)) {
  25718. case ToolbarMode.floating:
  25719. return renderFloatingToolbarButton(s, extras.backstage, identify, attributes);
  25720. default:
  25721. throw new Error("Toolbar groups are only supported when using floating toolbar mode");
  25722. }
  25723. }),
  25724. styleSelectButton: function(editor, extras) {
  25725. return createStyleSelect(editor, extras.backstage);
  25726. },
  25727. fontsizeSelectButton: function(editor, extras) {
  25728. return createFontsizeSelect(editor, extras.backstage);
  25729. },
  25730. fontSelectButton: function(editor, extras) {
  25731. return createFontSelect(editor, extras.backstage);
  25732. },
  25733. formatButton: function(editor, extras) {
  25734. return createFormatSelect(editor, extras.backstage);
  25735. },
  25736. alignMenuButton: function(editor, extras) {
  25737. return createAlignSelect(editor, extras.backstage);
  25738. }
  25739. };
  25740. var extractFrom = function(spec, extras, editor) {
  25741. return get$e(types, spec.type).fold(function() {
  25742. console.error("skipping button defined by", spec);
  25743. return Optional.none();
  25744. }, function(render2) {
  25745. return Optional.some(render2(spec, extras, editor));
  25746. });
  25747. };
  25748. var bespokeButtons = {
  25749. styleselect: types.styleSelectButton,
  25750. fontsizeselect: types.fontsizeSelectButton,
  25751. fontselect: types.fontSelectButton,
  25752. formatselect: types.formatButton,
  25753. align: types.alignMenuButton
  25754. };
  25755. var removeUnusedDefaults = function(buttons) {
  25756. var filteredItemGroups = map$2(defaultToolbar, function(group2) {
  25757. var items = filter$2(group2.items, function(subItem) {
  25758. return has$2(buttons, subItem) || has$2(bespokeButtons, subItem);
  25759. });
  25760. return {
  25761. name: group2.name,
  25762. items
  25763. };
  25764. });
  25765. return filter$2(filteredItemGroups, function(group2) {
  25766. return group2.items.length > 0;
  25767. });
  25768. };
  25769. var convertStringToolbar = function(strToolbar) {
  25770. var groupsStrings = strToolbar.split("|");
  25771. return map$2(groupsStrings, function(g) {
  25772. return { items: g.trim().split(" ") };
  25773. });
  25774. };
  25775. var isToolbarGroupSettingArray = function(toolbar) {
  25776. return isArrayOf(toolbar, function(t2) {
  25777. return has$2(t2, "name") && has$2(t2, "items");
  25778. });
  25779. };
  25780. var createToolbar = function(toolbarConfig) {
  25781. var toolbar = toolbarConfig.toolbar;
  25782. var buttons = toolbarConfig.buttons;
  25783. if (toolbar === false) {
  25784. return [];
  25785. } else if (toolbar === void 0 || toolbar === true) {
  25786. return removeUnusedDefaults(buttons);
  25787. } else if (isString(toolbar)) {
  25788. return convertStringToolbar(toolbar);
  25789. } else if (isToolbarGroupSettingArray(toolbar)) {
  25790. return toolbar;
  25791. } else {
  25792. console.error("Toolbar type should be string, string[], boolean or ToolbarGroup[]");
  25793. return [];
  25794. }
  25795. };
  25796. var lookupButton = function(editor, buttons, toolbarItem, allowToolbarGroups, extras, prefixes) {
  25797. return get$e(buttons, toolbarItem.toLowerCase()).orThunk(function() {
  25798. return prefixes.bind(function(ps) {
  25799. return findMap(ps, function(prefix2) {
  25800. return get$e(buttons, prefix2 + toolbarItem.toLowerCase());
  25801. });
  25802. });
  25803. }).fold(function() {
  25804. return get$e(bespokeButtons, toolbarItem.toLowerCase()).map(function(r2) {
  25805. return r2(editor, extras);
  25806. }).orThunk(function() {
  25807. return Optional.none();
  25808. });
  25809. }, function(spec) {
  25810. if (spec.type === "grouptoolbarbutton" && !allowToolbarGroups) {
  25811. console.warn("Ignoring the '" + toolbarItem + "' toolbar button. Group toolbar buttons are only supported when using floating toolbar mode and cannot be nested.");
  25812. return Optional.none();
  25813. } else {
  25814. return extractFrom(spec, extras, editor);
  25815. }
  25816. });
  25817. };
  25818. var identifyButtons = function(editor, toolbarConfig, extras, prefixes) {
  25819. var toolbarGroups = createToolbar(toolbarConfig);
  25820. var groups = map$2(toolbarGroups, function(group2) {
  25821. var items = bind$3(group2.items, function(toolbarItem) {
  25822. return toolbarItem.trim().length === 0 ? [] : lookupButton(editor, toolbarConfig.buttons, toolbarItem, toolbarConfig.allowToolbarGroups, extras, prefixes).toArray();
  25823. });
  25824. return {
  25825. title: Optional.from(editor.translate(group2.name)),
  25826. items
  25827. };
  25828. });
  25829. return filter$2(groups, function(group2) {
  25830. return group2.items.length > 0;
  25831. });
  25832. };
  25833. var setToolbar = function(editor, uiComponents, rawUiConfig, backstage) {
  25834. var comp = uiComponents.outerContainer;
  25835. var toolbarConfig = rawUiConfig.toolbar;
  25836. var toolbarButtonsConfig = rawUiConfig.buttons;
  25837. if (isArrayOf(toolbarConfig, isString)) {
  25838. var toolbars = toolbarConfig.map(function(t2) {
  25839. var config2 = {
  25840. toolbar: t2,
  25841. buttons: toolbarButtonsConfig,
  25842. allowToolbarGroups: rawUiConfig.allowToolbarGroups
  25843. };
  25844. return identifyButtons(editor, config2, { backstage }, Optional.none());
  25845. });
  25846. OuterContainer.setToolbars(comp, toolbars);
  25847. } else {
  25848. OuterContainer.setToolbar(comp, identifyButtons(editor, rawUiConfig, { backstage }, Optional.none()));
  25849. }
  25850. };
  25851. var detection = detect$1();
  25852. var isiOS12 = detection.os.isiOS() && detection.os.version.major <= 12;
  25853. var setupEvents$1 = function(editor, uiComponents) {
  25854. var dom2 = editor.dom;
  25855. var contentWindow = editor.getWin();
  25856. var initialDocEle = editor.getDoc().documentElement;
  25857. var lastWindowDimensions = Cell(SugarPosition(contentWindow.innerWidth, contentWindow.innerHeight));
  25858. var lastDocumentDimensions = Cell(SugarPosition(initialDocEle.offsetWidth, initialDocEle.offsetHeight));
  25859. var resizeWindow = function() {
  25860. var outer = lastWindowDimensions.get();
  25861. if (outer.left !== contentWindow.innerWidth || outer.top !== contentWindow.innerHeight) {
  25862. lastWindowDimensions.set(SugarPosition(contentWindow.innerWidth, contentWindow.innerHeight));
  25863. fireResizeContent(editor);
  25864. }
  25865. };
  25866. var resizeDocument = function() {
  25867. var docEle = editor.getDoc().documentElement;
  25868. var inner = lastDocumentDimensions.get();
  25869. if (inner.left !== docEle.offsetWidth || inner.top !== docEle.offsetHeight) {
  25870. lastDocumentDimensions.set(SugarPosition(docEle.offsetWidth, docEle.offsetHeight));
  25871. fireResizeContent(editor);
  25872. }
  25873. };
  25874. var scroll = function(e) {
  25875. return fireScrollContent(editor, e);
  25876. };
  25877. dom2.bind(contentWindow, "resize", resizeWindow);
  25878. dom2.bind(contentWindow, "scroll", scroll);
  25879. var elementLoad = capture(SugarElement.fromDom(editor.getBody()), "load", resizeDocument);
  25880. var mothership = uiComponents.uiMothership.element;
  25881. editor.on("hide", function() {
  25882. set$7(mothership, "display", "none");
  25883. });
  25884. editor.on("show", function() {
  25885. remove$6(mothership, "display");
  25886. });
  25887. editor.on("NodeChange", resizeDocument);
  25888. editor.on("remove", function() {
  25889. elementLoad.unbind();
  25890. dom2.unbind(contentWindow, "resize", resizeWindow);
  25891. dom2.unbind(contentWindow, "scroll", scroll);
  25892. contentWindow = null;
  25893. });
  25894. };
  25895. var render$1 = function(editor, uiComponents, rawUiConfig, backstage, args) {
  25896. var lastToolbarWidth = Cell(0);
  25897. var outerContainer = uiComponents.outerContainer;
  25898. iframe(editor);
  25899. var eTargetNode = SugarElement.fromDom(args.targetNode);
  25900. var uiRoot = getContentContainer(getRootNode(eTargetNode));
  25901. attachSystemAfter(eTargetNode, uiComponents.mothership);
  25902. attachSystem(uiRoot, uiComponents.uiMothership);
  25903. editor.on("PostRender", function() {
  25904. setToolbar(editor, uiComponents, rawUiConfig, backstage);
  25905. lastToolbarWidth.set(editor.getWin().innerWidth);
  25906. OuterContainer.setMenubar(outerContainer, identifyMenus(editor, rawUiConfig));
  25907. OuterContainer.setSidebar(outerContainer, rawUiConfig.sidebar);
  25908. setupEvents$1(editor, uiComponents);
  25909. });
  25910. var socket = OuterContainer.getSocket(outerContainer).getOrDie("Could not find expected socket element");
  25911. if (isiOS12) {
  25912. setAll(socket.element, {
  25913. "overflow": "scroll",
  25914. "-webkit-overflow-scrolling": "touch"
  25915. });
  25916. var limit = first(function() {
  25917. editor.fire("ScrollContent");
  25918. }, 20);
  25919. var unbinder = bind(socket.element, "scroll", limit.throttle);
  25920. editor.on("remove", unbinder.unbind);
  25921. }
  25922. setupReadonlyModeSwitch(editor, uiComponents);
  25923. editor.addCommand("ToggleSidebar", function(_ui, value2) {
  25924. OuterContainer.toggleSidebar(outerContainer, value2);
  25925. editor.fire("ToggleSidebar");
  25926. });
  25927. editor.addQueryValueHandler("ToggleSidebar", function() {
  25928. return OuterContainer.whichSidebar(outerContainer);
  25929. });
  25930. var toolbarMode = getToolbarMode(editor);
  25931. var refreshDrawer = function() {
  25932. OuterContainer.refreshToolbar(uiComponents.outerContainer);
  25933. };
  25934. if (toolbarMode === ToolbarMode.sliding || toolbarMode === ToolbarMode.floating) {
  25935. editor.on("ResizeWindow ResizeEditor ResizeContent", function() {
  25936. var width2 = editor.getWin().innerWidth;
  25937. if (width2 !== lastToolbarWidth.get()) {
  25938. refreshDrawer();
  25939. lastToolbarWidth.set(width2);
  25940. }
  25941. });
  25942. }
  25943. var api2 = {
  25944. enable: function() {
  25945. broadcastReadonly(uiComponents, false);
  25946. },
  25947. disable: function() {
  25948. broadcastReadonly(uiComponents, true);
  25949. },
  25950. isDisabled: function() {
  25951. return Disabling.isDisabled(outerContainer);
  25952. }
  25953. };
  25954. return {
  25955. iframeContainer: socket.element.dom,
  25956. editorContainer: outerContainer.element.dom,
  25957. api: api2
  25958. };
  25959. };
  25960. var Iframe = Object.freeze({
  25961. __proto__: null,
  25962. render: render$1
  25963. });
  25964. var parseToInt = function(val) {
  25965. var re = /^[0-9\.]+(|px)$/i;
  25966. if (re.test("" + val)) {
  25967. return Optional.some(parseInt("" + val, 10));
  25968. }
  25969. return Optional.none();
  25970. };
  25971. var numToPx = function(val) {
  25972. return isNumber(val) ? val + "px" : val;
  25973. };
  25974. var calcCappedSize = function(size, minSize, maxSize) {
  25975. var minOverride = minSize.filter(function(min2) {
  25976. return size < min2;
  25977. });
  25978. var maxOverride = maxSize.filter(function(max2) {
  25979. return size > max2;
  25980. });
  25981. return minOverride.or(maxOverride).getOr(size);
  25982. };
  25983. var getHeight = function(editor) {
  25984. var baseHeight = getHeightSetting(editor);
  25985. var minHeight = getMinHeightSetting(editor);
  25986. var maxHeight = getMaxHeightSetting(editor);
  25987. return parseToInt(baseHeight).map(function(height2) {
  25988. return calcCappedSize(height2, minHeight, maxHeight);
  25989. });
  25990. };
  25991. var getHeightWithFallback = function(editor) {
  25992. var height2 = getHeight(editor);
  25993. return height2.getOr(getHeightSetting(editor));
  25994. };
  25995. var getWidth = function(editor) {
  25996. var baseWidth = getWidthSetting(editor);
  25997. var minWidth = getMinWidthSetting(editor);
  25998. var maxWidth = getMaxWidthSetting(editor);
  25999. return parseToInt(baseWidth).map(function(width2) {
  26000. return calcCappedSize(width2, minWidth, maxWidth);
  26001. });
  26002. };
  26003. var getWidthWithFallback = function(editor) {
  26004. var width2 = getWidth(editor);
  26005. return width2.getOr(getWidthSetting(editor));
  26006. };
  26007. var InlineHeader = function(editor, targetElm, uiComponents, backstage, floatContainer) {
  26008. var uiMothership = uiComponents.uiMothership, outerContainer = uiComponents.outerContainer;
  26009. var DOM = global$b.DOM;
  26010. var useFixedToolbarContainer = useFixedContainer(editor);
  26011. var isSticky = isStickyToolbar(editor);
  26012. var editorMaxWidthOpt = getMaxWidthSetting(editor).or(getWidth(editor));
  26013. var headerBackstage = backstage.shared.header;
  26014. var isPositionedAtTop = headerBackstage.isPositionedAtTop;
  26015. var toolbarMode = getToolbarMode(editor);
  26016. var isSplitToolbar = toolbarMode === ToolbarMode.sliding || toolbarMode === ToolbarMode.floating;
  26017. var visible = Cell(false);
  26018. var isVisible2 = function() {
  26019. return visible.get() && !editor.removed;
  26020. };
  26021. var calcToolbarOffset = function(toolbar) {
  26022. return isSplitToolbar ? toolbar.fold(constant$1(0), function(tbar) {
  26023. return tbar.components().length > 1 ? get$b(tbar.components()[1].element) : 0;
  26024. }) : 0;
  26025. };
  26026. var calcMode = function(container) {
  26027. switch (getToolbarLocation(editor)) {
  26028. case ToolbarLocation.auto:
  26029. var toolbar_1 = OuterContainer.getToolbar(outerContainer);
  26030. var offset2 = calcToolbarOffset(toolbar_1);
  26031. var toolbarHeight = get$b(container.element) - offset2;
  26032. var targetBounds = box$1(targetElm);
  26033. var roomAtTop = targetBounds.y > toolbarHeight;
  26034. if (roomAtTop) {
  26035. return "top";
  26036. } else {
  26037. var doc = documentElement(targetElm);
  26038. var docHeight = Math.max(doc.dom.scrollHeight, get$b(doc));
  26039. var roomAtBottom = targetBounds.bottom < docHeight - toolbarHeight;
  26040. if (roomAtBottom) {
  26041. return "bottom";
  26042. } else {
  26043. var winBounds = win();
  26044. var isRoomAtBottomViewport = winBounds.bottom < targetBounds.bottom - toolbarHeight;
  26045. return isRoomAtBottomViewport ? "bottom" : "top";
  26046. }
  26047. }
  26048. case ToolbarLocation.bottom:
  26049. return "bottom";
  26050. case ToolbarLocation.top:
  26051. default:
  26052. return "top";
  26053. }
  26054. };
  26055. var setupMode = function(mode) {
  26056. var container = floatContainer.get();
  26057. Docking.setModes(container, [mode]);
  26058. headerBackstage.setDockingMode(mode);
  26059. var verticalDir = isPositionedAtTop() ? AttributeValue.TopToBottom : AttributeValue.BottomToTop;
  26060. set$8(container.element, Attribute, verticalDir);
  26061. };
  26062. var updateChromeWidth = function() {
  26063. var maxWidth = editorMaxWidthOpt.getOrThunk(function() {
  26064. var bodyMargin = parseToInt(get$c(body(), "margin-left")).getOr(0);
  26065. return get$a(body()) - absolute$3(targetElm).left + bodyMargin;
  26066. });
  26067. set$7(floatContainer.get().element, "max-width", maxWidth + "px");
  26068. };
  26069. var updateChromePosition = function() {
  26070. var toolbar = OuterContainer.getToolbar(outerContainer);
  26071. var offset2 = calcToolbarOffset(toolbar);
  26072. var targetBounds = box$1(targetElm);
  26073. var top2 = isPositionedAtTop() ? Math.max(targetBounds.y - get$b(floatContainer.get().element) + offset2, 0) : targetBounds.bottom;
  26074. setAll(outerContainer.element, {
  26075. position: "absolute",
  26076. top: Math.round(top2) + "px",
  26077. left: Math.round(targetBounds.x) + "px"
  26078. });
  26079. };
  26080. var repositionPopups$1 = function() {
  26081. uiMothership.broadcastOn([repositionPopups()], {});
  26082. };
  26083. var updateChromeUi = function(resetDocking) {
  26084. if (resetDocking === void 0) {
  26085. resetDocking = false;
  26086. }
  26087. if (!isVisible2()) {
  26088. return;
  26089. }
  26090. if (!useFixedToolbarContainer) {
  26091. updateChromeWidth();
  26092. }
  26093. if (isSplitToolbar) {
  26094. OuterContainer.refreshToolbar(outerContainer);
  26095. }
  26096. if (!useFixedToolbarContainer) {
  26097. updateChromePosition();
  26098. }
  26099. if (isSticky) {
  26100. var floatContainerComp = floatContainer.get();
  26101. resetDocking ? Docking.reset(floatContainerComp) : Docking.refresh(floatContainerComp);
  26102. }
  26103. repositionPopups$1();
  26104. };
  26105. var updateMode = function(updateUi) {
  26106. if (updateUi === void 0) {
  26107. updateUi = true;
  26108. }
  26109. if (useFixedToolbarContainer || !isSticky || !isVisible2()) {
  26110. return;
  26111. }
  26112. var currentMode = headerBackstage.getDockingMode();
  26113. var newMode = calcMode(floatContainer.get());
  26114. if (newMode !== currentMode) {
  26115. setupMode(newMode);
  26116. if (updateUi) {
  26117. updateChromeUi(true);
  26118. }
  26119. }
  26120. };
  26121. var show2 = function() {
  26122. visible.set(true);
  26123. set$7(outerContainer.element, "display", "flex");
  26124. DOM.addClass(editor.getBody(), "mce-edit-focus");
  26125. remove$6(uiMothership.element, "display");
  26126. updateMode(false);
  26127. updateChromeUi();
  26128. };
  26129. var hide = function() {
  26130. visible.set(false);
  26131. if (uiComponents.outerContainer) {
  26132. set$7(outerContainer.element, "display", "none");
  26133. DOM.removeClass(editor.getBody(), "mce-edit-focus");
  26134. }
  26135. set$7(uiMothership.element, "display", "none");
  26136. };
  26137. return {
  26138. isVisible: isVisible2,
  26139. isPositionedAtTop,
  26140. show: show2,
  26141. hide,
  26142. update: updateChromeUi,
  26143. updateMode,
  26144. repositionPopups: repositionPopups$1
  26145. };
  26146. };
  26147. var getTargetPosAndBounds = function(targetElm, isToolbarTop) {
  26148. var bounds2 = box$1(targetElm);
  26149. return {
  26150. pos: isToolbarTop ? bounds2.y : bounds2.bottom,
  26151. bounds: bounds2
  26152. };
  26153. };
  26154. var setupEvents = function(editor, targetElm, ui, toolbarPersist) {
  26155. var prevPosAndBounds = Cell(getTargetPosAndBounds(targetElm, ui.isPositionedAtTop()));
  26156. var resizeContent = function(e) {
  26157. var _a2 = getTargetPosAndBounds(targetElm, ui.isPositionedAtTop()), pos = _a2.pos, bounds2 = _a2.bounds;
  26158. var _b = prevPosAndBounds.get(), prevPos = _b.pos, prevBounds = _b.bounds;
  26159. var hasResized = bounds2.height !== prevBounds.height || bounds2.width !== prevBounds.width;
  26160. prevPosAndBounds.set({
  26161. pos,
  26162. bounds: bounds2
  26163. });
  26164. if (hasResized) {
  26165. fireResizeContent(editor, e);
  26166. }
  26167. if (ui.isVisible()) {
  26168. if (prevPos !== pos) {
  26169. ui.update(true);
  26170. } else if (hasResized) {
  26171. ui.updateMode();
  26172. ui.repositionPopups();
  26173. }
  26174. }
  26175. };
  26176. if (!toolbarPersist) {
  26177. editor.on("activate", ui.show);
  26178. editor.on("deactivate", ui.hide);
  26179. }
  26180. editor.on("SkinLoaded ResizeWindow", function() {
  26181. return ui.update(true);
  26182. });
  26183. editor.on("NodeChange keydown", function(e) {
  26184. global$f.requestAnimationFrame(function() {
  26185. return resizeContent(e);
  26186. });
  26187. });
  26188. editor.on("ScrollWindow", function() {
  26189. return ui.updateMode();
  26190. });
  26191. var elementLoad = unbindable();
  26192. elementLoad.set(capture(SugarElement.fromDom(editor.getBody()), "load", resizeContent));
  26193. editor.on("remove", function() {
  26194. elementLoad.clear();
  26195. });
  26196. };
  26197. var render = function(editor, uiComponents, rawUiConfig, backstage, args) {
  26198. var mothership = uiComponents.mothership, uiMothership = uiComponents.uiMothership, outerContainer = uiComponents.outerContainer;
  26199. var floatContainer = Cell(null);
  26200. var targetElm = SugarElement.fromDom(args.targetNode);
  26201. var ui = InlineHeader(editor, targetElm, uiComponents, backstage, floatContainer);
  26202. var toolbarPersist = isToolbarPersist(editor);
  26203. inline(editor);
  26204. var render2 = function() {
  26205. if (floatContainer.get()) {
  26206. ui.show();
  26207. return;
  26208. }
  26209. floatContainer.set(OuterContainer.getHeader(outerContainer).getOrDie());
  26210. var uiContainer = getUiContainer(editor);
  26211. attachSystem(uiContainer, mothership);
  26212. attachSystem(uiContainer, uiMothership);
  26213. setToolbar(editor, uiComponents, rawUiConfig, backstage);
  26214. OuterContainer.setMenubar(outerContainer, identifyMenus(editor, rawUiConfig));
  26215. ui.show();
  26216. setupEvents(editor, targetElm, ui, toolbarPersist);
  26217. editor.nodeChanged();
  26218. };
  26219. editor.on("show", render2);
  26220. editor.on("hide", ui.hide);
  26221. if (!toolbarPersist) {
  26222. editor.on("focus", render2);
  26223. editor.on("blur", ui.hide);
  26224. }
  26225. editor.on("init", function() {
  26226. if (editor.hasFocus() || toolbarPersist) {
  26227. render2();
  26228. }
  26229. });
  26230. setupReadonlyModeSwitch(editor, uiComponents);
  26231. var api2 = {
  26232. show: function() {
  26233. ui.show();
  26234. },
  26235. hide: function() {
  26236. ui.hide();
  26237. },
  26238. enable: function() {
  26239. broadcastReadonly(uiComponents, false);
  26240. },
  26241. disable: function() {
  26242. broadcastReadonly(uiComponents, true);
  26243. },
  26244. isDisabled: function() {
  26245. return Disabling.isDisabled(outerContainer);
  26246. }
  26247. };
  26248. return {
  26249. editorContainer: outerContainer.element.dom,
  26250. api: api2
  26251. };
  26252. };
  26253. var Inline = Object.freeze({
  26254. __proto__: null,
  26255. render
  26256. });
  26257. var showContextToolbarEvent = "contexttoolbar-show";
  26258. var hideContextToolbarEvent = "contexttoolbar-hide";
  26259. var getFormApi = function(input2) {
  26260. return {
  26261. hide: function() {
  26262. return emit(input2, sandboxClose());
  26263. },
  26264. getValue: function() {
  26265. return Representing.getValue(input2);
  26266. }
  26267. };
  26268. };
  26269. var runOnExecute = function(memInput, original2) {
  26270. return run$1(internalToolbarButtonExecute, function(comp, se) {
  26271. var input2 = memInput.get(comp);
  26272. var formApi = getFormApi(input2);
  26273. original2.onAction(formApi, se.event.buttonApi);
  26274. });
  26275. };
  26276. var renderContextButton = function(memInput, button2, extras) {
  26277. var _a2 = button2.original;
  26278. _a2.primary;
  26279. var rest = __rest(_a2, ["primary"]);
  26280. var bridged = getOrDie(createToolbarButton(__assign(__assign({}, rest), {
  26281. type: "button",
  26282. onAction: noop
  26283. })));
  26284. return renderToolbarButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute(memInput, button2)]);
  26285. };
  26286. var renderContextToggleButton = function(memInput, button2, extras) {
  26287. var _a2 = button2.original;
  26288. _a2.primary;
  26289. var rest = __rest(_a2, ["primary"]);
  26290. var bridged = getOrDie(createToggleButton(__assign(__assign({}, rest), {
  26291. type: "togglebutton",
  26292. onAction: noop
  26293. })));
  26294. return renderToolbarToggleButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute(memInput, button2)]);
  26295. };
  26296. var generateOne = function(memInput, button2, providersBackstage) {
  26297. var extras = { backstage: { shared: { providers: providersBackstage } } };
  26298. if (button2.type === "contextformtogglebutton") {
  26299. return renderContextToggleButton(memInput, button2, extras);
  26300. } else {
  26301. return renderContextButton(memInput, button2, extras);
  26302. }
  26303. };
  26304. var generate = function(memInput, buttons, providersBackstage) {
  26305. var mementos = map$2(buttons, function(button2) {
  26306. return record(generateOne(memInput, button2, providersBackstage));
  26307. });
  26308. var asSpecs = function() {
  26309. return map$2(mementos, function(mem) {
  26310. return mem.asSpec();
  26311. });
  26312. };
  26313. var findPrimary = function(compInSystem) {
  26314. return findMap(buttons, function(button2, i) {
  26315. if (button2.primary) {
  26316. return Optional.from(mementos[i]).bind(function(mem) {
  26317. return mem.getOpt(compInSystem);
  26318. }).filter(not(Disabling.isDisabled));
  26319. } else {
  26320. return Optional.none();
  26321. }
  26322. });
  26323. };
  26324. return {
  26325. asSpecs,
  26326. findPrimary
  26327. };
  26328. };
  26329. var buildInitGroups = function(ctx, providers) {
  26330. var inputAttributes = ctx.label.fold(function() {
  26331. return {};
  26332. }, function(label) {
  26333. return { "aria-label": label };
  26334. });
  26335. var memInput = record(Input.sketch({
  26336. inputClasses: [
  26337. "tox-toolbar-textfield",
  26338. "tox-toolbar-nav-js"
  26339. ],
  26340. data: ctx.initValue(),
  26341. inputAttributes,
  26342. selectOnFocus: true,
  26343. inputBehaviours: derive$1([Keying.config({
  26344. mode: "special",
  26345. onEnter: function(input2) {
  26346. return commands.findPrimary(input2).map(function(primary) {
  26347. emitExecute(primary);
  26348. return true;
  26349. });
  26350. },
  26351. onLeft: function(comp, se) {
  26352. se.cut();
  26353. return Optional.none();
  26354. },
  26355. onRight: function(comp, se) {
  26356. se.cut();
  26357. return Optional.none();
  26358. }
  26359. })])
  26360. }));
  26361. var commands = generate(memInput, ctx.commands, providers);
  26362. return [
  26363. {
  26364. title: Optional.none(),
  26365. items: [memInput.asSpec()]
  26366. },
  26367. {
  26368. title: Optional.none(),
  26369. items: commands.asSpecs()
  26370. }
  26371. ];
  26372. };
  26373. var renderContextForm = function(toolbarType, ctx, providers) {
  26374. return renderToolbar({
  26375. type: toolbarType,
  26376. uid: generate$6("context-toolbar"),
  26377. initGroups: buildInitGroups(ctx, providers),
  26378. onEscape: Optional.none,
  26379. cyclicKeying: true,
  26380. providers
  26381. });
  26382. };
  26383. var ContextForm = {
  26384. renderContextForm,
  26385. buildInitGroups
  26386. };
  26387. var isVerticalOverlap = function(a, b2, threshold) {
  26388. if (threshold === void 0) {
  26389. threshold = 0.01;
  26390. }
  26391. return b2.bottom - a.y >= threshold && a.bottom - b2.y >= threshold;
  26392. };
  26393. var getRangeRect = function(rng) {
  26394. var rect2 = rng.getBoundingClientRect();
  26395. if (rect2.height <= 0 && rect2.width <= 0) {
  26396. var leaf$1 = leaf(SugarElement.fromDom(rng.startContainer), rng.startOffset).element;
  26397. var elm = isText$1(leaf$1) ? parent(leaf$1) : Optional.some(leaf$1);
  26398. return elm.filter(isElement$2).map(function(e) {
  26399. return e.dom.getBoundingClientRect();
  26400. }).getOr(rect2);
  26401. } else {
  26402. return rect2;
  26403. }
  26404. };
  26405. var getSelectionBounds = function(editor) {
  26406. var rng = editor.selection.getRng();
  26407. var rect2 = getRangeRect(rng);
  26408. if (editor.inline) {
  26409. var scroll_1 = get$9();
  26410. return bounds(scroll_1.left + rect2.left, scroll_1.top + rect2.top, rect2.width, rect2.height);
  26411. } else {
  26412. var bodyPos = absolute$2(SugarElement.fromDom(editor.getBody()));
  26413. return bounds(bodyPos.x + rect2.left, bodyPos.y + rect2.top, rect2.width, rect2.height);
  26414. }
  26415. };
  26416. var getAnchorElementBounds = function(editor, lastElement) {
  26417. return lastElement.filter(inBody).map(absolute$2).getOrThunk(function() {
  26418. return getSelectionBounds(editor);
  26419. });
  26420. };
  26421. var getHorizontalBounds = function(contentAreaBox, viewportBounds, margin) {
  26422. var x = Math.max(contentAreaBox.x + margin, viewportBounds.x);
  26423. var right2 = Math.min(contentAreaBox.right - margin, viewportBounds.right);
  26424. return {
  26425. x,
  26426. width: right2 - x
  26427. };
  26428. };
  26429. var getVerticalBounds = function(editor, contentAreaBox, viewportBounds, isToolbarLocationTop, toolbarType, margin) {
  26430. var container = SugarElement.fromDom(editor.getContainer());
  26431. var header = descendant(container, ".tox-editor-header").getOr(container);
  26432. var headerBox = box$1(header);
  26433. var isToolbarBelowContentArea = headerBox.y >= contentAreaBox.bottom;
  26434. var isToolbarAbove = isToolbarLocationTop && !isToolbarBelowContentArea;
  26435. if (editor.inline && isToolbarAbove) {
  26436. return {
  26437. y: Math.max(headerBox.bottom + margin, viewportBounds.y),
  26438. bottom: viewportBounds.bottom
  26439. };
  26440. }
  26441. if (editor.inline && !isToolbarAbove) {
  26442. return {
  26443. y: viewportBounds.y,
  26444. bottom: Math.min(headerBox.y - margin, viewportBounds.bottom)
  26445. };
  26446. }
  26447. var containerBounds = toolbarType === "line" ? box$1(container) : contentAreaBox;
  26448. if (isToolbarAbove) {
  26449. return {
  26450. y: Math.max(headerBox.bottom + margin, viewportBounds.y),
  26451. bottom: Math.min(containerBounds.bottom - margin, viewportBounds.bottom)
  26452. };
  26453. }
  26454. return {
  26455. y: Math.max(containerBounds.y + margin, viewportBounds.y),
  26456. bottom: Math.min(headerBox.y - margin, viewportBounds.bottom)
  26457. };
  26458. };
  26459. var getContextToolbarBounds = function(editor, sharedBackstage, toolbarType, margin) {
  26460. if (margin === void 0) {
  26461. margin = 0;
  26462. }
  26463. var viewportBounds = getBounds$3(window);
  26464. var contentAreaBox = box$1(SugarElement.fromDom(editor.getContentAreaContainer()));
  26465. var toolbarOrMenubarEnabled = isMenubarEnabled(editor) || isToolbarEnabled(editor) || isMultipleToolbars(editor);
  26466. var _a2 = getHorizontalBounds(contentAreaBox, viewportBounds, margin), x = _a2.x, width2 = _a2.width;
  26467. if (editor.inline && !toolbarOrMenubarEnabled) {
  26468. return bounds(x, viewportBounds.y, width2, viewportBounds.height);
  26469. } else {
  26470. var isToolbarTop = sharedBackstage.header.isPositionedAtTop();
  26471. var _b = getVerticalBounds(editor, contentAreaBox, viewportBounds, isToolbarTop, toolbarType, margin), y = _b.y, bottom2 = _b.bottom;
  26472. return bounds(x, y, width2, bottom2 - y);
  26473. }
  26474. };
  26475. var bubbleSize$1 = 12;
  26476. var bubbleAlignments$1 = {
  26477. valignCentre: [],
  26478. alignCentre: [],
  26479. alignLeft: ["tox-pop--align-left"],
  26480. alignRight: ["tox-pop--align-right"],
  26481. right: ["tox-pop--right"],
  26482. left: ["tox-pop--left"],
  26483. bottom: ["tox-pop--bottom"],
  26484. top: ["tox-pop--top"],
  26485. inset: ["tox-pop--inset"]
  26486. };
  26487. var anchorOverrides = {
  26488. maxHeightFunction: expandable$1(),
  26489. maxWidthFunction: expandable()
  26490. };
  26491. var isEntireElementSelected = function(editor, elem) {
  26492. var rng = editor.selection.getRng();
  26493. var leaf$1 = leaf(SugarElement.fromDom(rng.startContainer), rng.startOffset);
  26494. return rng.startContainer === rng.endContainer && rng.startOffset === rng.endOffset - 1 && eq(leaf$1.element, elem);
  26495. };
  26496. var preservePosition = function(elem, position2, f) {
  26497. var currentPosition = getRaw(elem, "position");
  26498. set$7(elem, "position", position2);
  26499. var result = f(elem);
  26500. currentPosition.each(function(pos) {
  26501. return set$7(elem, "position", pos);
  26502. });
  26503. return result;
  26504. };
  26505. var shouldUseInsetLayouts = function(position2) {
  26506. return position2 === "node";
  26507. };
  26508. var determineInsetLayout = function(editor, contextbar, elem, data, bounds2) {
  26509. var selectionBounds = getSelectionBounds(editor);
  26510. var isSameAnchorElement = data.lastElement().exists(function(prev) {
  26511. return eq(elem, prev);
  26512. });
  26513. if (isEntireElementSelected(editor, elem)) {
  26514. return isSameAnchorElement ? preserve : north;
  26515. } else if (isSameAnchorElement) {
  26516. return preservePosition(contextbar, data.getMode(), function() {
  26517. var isOverlapping = isVerticalOverlap(selectionBounds, box$1(contextbar));
  26518. return isOverlapping && !data.isReposition() ? flip$2 : preserve;
  26519. });
  26520. } else {
  26521. var yBounds = data.getMode() === "fixed" ? bounds2.y + get$9().top : bounds2.y;
  26522. var contextbarHeight = get$b(contextbar) + bubbleSize$1;
  26523. return yBounds + contextbarHeight <= selectionBounds.y ? north : south;
  26524. }
  26525. };
  26526. var getAnchorSpec$2 = function(editor, mobile, data, position2) {
  26527. var smartInsetLayout = function(elem) {
  26528. return function(anchor2, element2, bubbles, placee, bounds2) {
  26529. var layout2 = determineInsetLayout(editor, placee, elem, data, bounds2);
  26530. var newAnchor = __assign(__assign({}, anchor2), {
  26531. y: bounds2.y,
  26532. height: bounds2.height
  26533. });
  26534. return __assign(__assign({}, layout2(newAnchor, element2, bubbles, placee, bounds2)), { alwaysFit: true });
  26535. };
  26536. };
  26537. var getInsetLayouts = function(elem) {
  26538. return shouldUseInsetLayouts(position2) ? [smartInsetLayout(elem)] : [];
  26539. };
  26540. var desktopAnchorSpecLayouts = {
  26541. onLtr: function(elem) {
  26542. return [
  26543. north$2,
  26544. south$2,
  26545. northeast$2,
  26546. southeast$2,
  26547. northwest$2,
  26548. southwest$2
  26549. ].concat(getInsetLayouts(elem));
  26550. },
  26551. onRtl: function(elem) {
  26552. return [
  26553. north$2,
  26554. south$2,
  26555. northwest$2,
  26556. southwest$2,
  26557. northeast$2,
  26558. southeast$2
  26559. ].concat(getInsetLayouts(elem));
  26560. }
  26561. };
  26562. var mobileAnchorSpecLayouts = {
  26563. onLtr: function(elem) {
  26564. return [
  26565. south$2,
  26566. southeast$2,
  26567. southwest$2,
  26568. northeast$2,
  26569. northwest$2,
  26570. north$2
  26571. ].concat(getInsetLayouts(elem));
  26572. },
  26573. onRtl: function(elem) {
  26574. return [
  26575. south$2,
  26576. southwest$2,
  26577. southeast$2,
  26578. northwest$2,
  26579. northeast$2,
  26580. north$2
  26581. ].concat(getInsetLayouts(elem));
  26582. }
  26583. };
  26584. return mobile ? mobileAnchorSpecLayouts : desktopAnchorSpecLayouts;
  26585. };
  26586. var getAnchorLayout = function(editor, position2, isTouch2, data) {
  26587. if (position2 === "line") {
  26588. return {
  26589. bubble: nu$5(bubbleSize$1, 0, bubbleAlignments$1),
  26590. layouts: {
  26591. onLtr: function() {
  26592. return [east$2];
  26593. },
  26594. onRtl: function() {
  26595. return [west$2];
  26596. }
  26597. },
  26598. overrides: anchorOverrides
  26599. };
  26600. } else {
  26601. return {
  26602. bubble: nu$5(0, bubbleSize$1, bubbleAlignments$1, 1 / bubbleSize$1),
  26603. layouts: getAnchorSpec$2(editor, isTouch2, data, position2),
  26604. overrides: anchorOverrides
  26605. };
  26606. }
  26607. };
  26608. var matchTargetWith = function(elem, candidates) {
  26609. var ctxs = filter$2(candidates, function(toolbarApi) {
  26610. return toolbarApi.predicate(elem.dom);
  26611. });
  26612. var _a2 = partition$3(ctxs, function(t2) {
  26613. return t2.type === "contexttoolbar";
  26614. }), pass = _a2.pass, fail = _a2.fail;
  26615. return {
  26616. contextToolbars: pass,
  26617. contextForms: fail
  26618. };
  26619. };
  26620. var filterByPositionForStartNode = function(toolbars) {
  26621. if (toolbars.length <= 1) {
  26622. return toolbars;
  26623. } else {
  26624. var doesPositionExist = function(value2) {
  26625. return exists(toolbars, function(t2) {
  26626. return t2.position === value2;
  26627. });
  26628. };
  26629. var filterToolbarsByPosition = function(value2) {
  26630. return filter$2(toolbars, function(t2) {
  26631. return t2.position === value2;
  26632. });
  26633. };
  26634. var hasSelectionToolbars = doesPositionExist("selection");
  26635. var hasNodeToolbars = doesPositionExist("node");
  26636. if (hasSelectionToolbars || hasNodeToolbars) {
  26637. if (hasNodeToolbars && hasSelectionToolbars) {
  26638. var nodeToolbars = filterToolbarsByPosition("node");
  26639. var selectionToolbars = map$2(filterToolbarsByPosition("selection"), function(t2) {
  26640. return __assign(__assign({}, t2), { position: "node" });
  26641. });
  26642. return nodeToolbars.concat(selectionToolbars);
  26643. } else {
  26644. return hasSelectionToolbars ? filterToolbarsByPosition("selection") : filterToolbarsByPosition("node");
  26645. }
  26646. } else {
  26647. return filterToolbarsByPosition("line");
  26648. }
  26649. }
  26650. };
  26651. var filterByPositionForAncestorNode = function(toolbars) {
  26652. if (toolbars.length <= 1) {
  26653. return toolbars;
  26654. } else {
  26655. var findPosition_1 = function(value2) {
  26656. return find$5(toolbars, function(t2) {
  26657. return t2.position === value2;
  26658. });
  26659. };
  26660. var basePosition = findPosition_1("selection").orThunk(function() {
  26661. return findPosition_1("node");
  26662. }).orThunk(function() {
  26663. return findPosition_1("line");
  26664. }).map(function(t2) {
  26665. return t2.position;
  26666. });
  26667. return basePosition.fold(function() {
  26668. return [];
  26669. }, function(pos) {
  26670. return filter$2(toolbars, function(t2) {
  26671. return t2.position === pos;
  26672. });
  26673. });
  26674. }
  26675. };
  26676. var matchStartNode = function(elem, nodeCandidates, editorCandidates) {
  26677. var nodeMatches = matchTargetWith(elem, nodeCandidates);
  26678. if (nodeMatches.contextForms.length > 0) {
  26679. return Optional.some({
  26680. elem,
  26681. toolbars: [nodeMatches.contextForms[0]]
  26682. });
  26683. } else {
  26684. var editorMatches = matchTargetWith(elem, editorCandidates);
  26685. if (editorMatches.contextForms.length > 0) {
  26686. return Optional.some({
  26687. elem,
  26688. toolbars: [editorMatches.contextForms[0]]
  26689. });
  26690. } else if (nodeMatches.contextToolbars.length > 0 || editorMatches.contextToolbars.length > 0) {
  26691. var toolbars = filterByPositionForStartNode(nodeMatches.contextToolbars.concat(editorMatches.contextToolbars));
  26692. return Optional.some({
  26693. elem,
  26694. toolbars
  26695. });
  26696. } else {
  26697. return Optional.none();
  26698. }
  26699. }
  26700. };
  26701. var matchAncestor = function(isRoot, startNode, scopes) {
  26702. if (isRoot(startNode)) {
  26703. return Optional.none();
  26704. } else {
  26705. return ancestor$2(startNode, function(ancestorElem) {
  26706. if (isElement$2(ancestorElem)) {
  26707. var _a2 = matchTargetWith(ancestorElem, scopes.inNodeScope), contextToolbars = _a2.contextToolbars, contextForms = _a2.contextForms;
  26708. var toolbars = contextForms.length > 0 ? contextForms : filterByPositionForAncestorNode(contextToolbars);
  26709. return toolbars.length > 0 ? Optional.some({
  26710. elem: ancestorElem,
  26711. toolbars
  26712. }) : Optional.none();
  26713. } else {
  26714. return Optional.none();
  26715. }
  26716. }, isRoot);
  26717. }
  26718. };
  26719. var lookup$1 = function(scopes, editor) {
  26720. var rootElem = SugarElement.fromDom(editor.getBody());
  26721. var isRoot = function(elem) {
  26722. return eq(elem, rootElem);
  26723. };
  26724. var isOutsideRoot = function(startNode2) {
  26725. return !isRoot(startNode2) && !contains(rootElem, startNode2);
  26726. };
  26727. var startNode = SugarElement.fromDom(editor.selection.getNode());
  26728. if (isOutsideRoot(startNode)) {
  26729. return Optional.none();
  26730. }
  26731. return matchStartNode(startNode, scopes.inNodeScope, scopes.inEditorScope).orThunk(function() {
  26732. return matchAncestor(isRoot, startNode, scopes);
  26733. });
  26734. };
  26735. var categorise = function(contextToolbars, navigate) {
  26736. var forms = {};
  26737. var inNodeScope = [];
  26738. var inEditorScope = [];
  26739. var formNavigators = {};
  26740. var lookupTable = {};
  26741. var registerForm = function(key, toolbarSpec) {
  26742. var contextForm = getOrDie(createContextForm(toolbarSpec));
  26743. forms[key] = contextForm;
  26744. contextForm.launch.map(function(launch) {
  26745. formNavigators["form:" + key] = __assign(__assign({}, toolbarSpec.launch), {
  26746. type: launch.type === "contextformtogglebutton" ? "togglebutton" : "button",
  26747. onAction: function() {
  26748. navigate(contextForm);
  26749. }
  26750. });
  26751. });
  26752. if (contextForm.scope === "editor") {
  26753. inEditorScope.push(contextForm);
  26754. } else {
  26755. inNodeScope.push(contextForm);
  26756. }
  26757. lookupTable[key] = contextForm;
  26758. };
  26759. var registerToolbar = function(key, toolbarSpec) {
  26760. createContextToolbar(toolbarSpec).each(function(contextToolbar) {
  26761. if (toolbarSpec.scope === "editor") {
  26762. inEditorScope.push(contextToolbar);
  26763. } else {
  26764. inNodeScope.push(contextToolbar);
  26765. }
  26766. lookupTable[key] = contextToolbar;
  26767. });
  26768. };
  26769. var keys$1 = keys(contextToolbars);
  26770. each$1(keys$1, function(key) {
  26771. var toolbarApi = contextToolbars[key];
  26772. if (toolbarApi.type === "contextform") {
  26773. registerForm(key, toolbarApi);
  26774. } else if (toolbarApi.type === "contexttoolbar") {
  26775. registerToolbar(key, toolbarApi);
  26776. }
  26777. });
  26778. return {
  26779. forms,
  26780. inNodeScope,
  26781. inEditorScope,
  26782. lookupTable,
  26783. formNavigators
  26784. };
  26785. };
  26786. var forwardSlideEvent = generate$6("forward-slide");
  26787. var backSlideEvent = generate$6("backward-slide");
  26788. var changeSlideEvent = generate$6("change-slide-event");
  26789. var resizingClass = "tox-pop--resizing";
  26790. var renderContextToolbar = function(spec) {
  26791. var stack = Cell([]);
  26792. return InlineView.sketch({
  26793. dom: {
  26794. tag: "div",
  26795. classes: ["tox-pop"]
  26796. },
  26797. fireDismissalEventInstead: { event: "doNotDismissYet" },
  26798. onShow: function(comp) {
  26799. stack.set([]);
  26800. InlineView.getContent(comp).each(function(c) {
  26801. remove$6(c.element, "visibility");
  26802. });
  26803. remove$2(comp.element, resizingClass);
  26804. remove$6(comp.element, "width");
  26805. },
  26806. inlineBehaviours: derive$1([
  26807. config("context-toolbar-events", [
  26808. runOnSource(transitionend(), function(comp, se) {
  26809. if (se.event.raw.propertyName === "width") {
  26810. remove$2(comp.element, resizingClass);
  26811. remove$6(comp.element, "width");
  26812. }
  26813. }),
  26814. run$1(changeSlideEvent, function(comp, se) {
  26815. var elem = comp.element;
  26816. remove$6(elem, "width");
  26817. var currentWidth = get$a(elem);
  26818. InlineView.setContent(comp, se.event.contents);
  26819. add$2(elem, resizingClass);
  26820. var newWidth = get$a(elem);
  26821. set$7(elem, "width", currentWidth + "px");
  26822. InlineView.getContent(comp).each(function(newContents) {
  26823. se.event.focus.bind(function(f) {
  26824. focus$3(f);
  26825. return search(elem);
  26826. }).orThunk(function() {
  26827. Keying.focusIn(newContents);
  26828. return active(getRootNode(elem));
  26829. });
  26830. });
  26831. global$f.setTimeout(function() {
  26832. set$7(comp.element, "width", newWidth + "px");
  26833. }, 0);
  26834. }),
  26835. run$1(forwardSlideEvent, function(comp, se) {
  26836. InlineView.getContent(comp).each(function(oldContents) {
  26837. stack.set(stack.get().concat([{
  26838. bar: oldContents,
  26839. focus: active(getRootNode(comp.element))
  26840. }]));
  26841. });
  26842. emitWith(comp, changeSlideEvent, {
  26843. contents: se.event.forwardContents,
  26844. focus: Optional.none()
  26845. });
  26846. }),
  26847. run$1(backSlideEvent, function(comp, _se) {
  26848. last$2(stack.get()).each(function(last2) {
  26849. stack.set(stack.get().slice(0, stack.get().length - 1));
  26850. emitWith(comp, changeSlideEvent, {
  26851. contents: premade(last2.bar),
  26852. focus: last2.focus
  26853. });
  26854. });
  26855. })
  26856. ]),
  26857. Keying.config({
  26858. mode: "special",
  26859. onEscape: function(comp) {
  26860. return last$2(stack.get()).fold(function() {
  26861. return spec.onEscape();
  26862. }, function(_) {
  26863. emit(comp, backSlideEvent);
  26864. return Optional.some(true);
  26865. });
  26866. }
  26867. })
  26868. ]),
  26869. lazySink: function() {
  26870. return Result.value(spec.sink);
  26871. }
  26872. });
  26873. };
  26874. var transitionClass = "tox-pop--transition";
  26875. var register$7 = function(editor, registryContextToolbars, sink, extras) {
  26876. var backstage = extras.backstage;
  26877. var sharedBackstage = backstage.shared;
  26878. var isTouch2 = detect$1().deviceType.isTouch;
  26879. var lastElement = value$1();
  26880. var lastTrigger = value$1();
  26881. var lastContextPosition = value$1();
  26882. var contextbar = build$1(renderContextToolbar({
  26883. sink,
  26884. onEscape: function() {
  26885. editor.focus();
  26886. return Optional.some(true);
  26887. }
  26888. }));
  26889. var getBounds2 = function() {
  26890. var position2 = lastContextPosition.get().getOr("node");
  26891. var margin = shouldUseInsetLayouts(position2) ? 1 : 0;
  26892. return getContextToolbarBounds(editor, sharedBackstage, position2, margin);
  26893. };
  26894. var canLaunchToolbar = function() {
  26895. return !editor.removed && !(isTouch2() && backstage.isContextMenuOpen());
  26896. };
  26897. var isSameLaunchElement = function(elem) {
  26898. return is$1(lift2(elem, lastElement.get(), eq), true);
  26899. };
  26900. var shouldContextToolbarHide = function() {
  26901. if (!canLaunchToolbar()) {
  26902. return true;
  26903. } else {
  26904. var contextToolbarBounds = getBounds2();
  26905. var anchorBounds = is$1(lastContextPosition.get(), "node") ? getAnchorElementBounds(editor, lastElement.get()) : getSelectionBounds(editor);
  26906. return contextToolbarBounds.height <= 0 || !isVerticalOverlap(anchorBounds, contextToolbarBounds);
  26907. }
  26908. };
  26909. var close2 = function() {
  26910. lastElement.clear();
  26911. lastTrigger.clear();
  26912. lastContextPosition.clear();
  26913. InlineView.hide(contextbar);
  26914. };
  26915. var hideOrRepositionIfNecessary = function() {
  26916. if (InlineView.isOpen(contextbar)) {
  26917. var contextBarEle = contextbar.element;
  26918. remove$6(contextBarEle, "display");
  26919. if (shouldContextToolbarHide()) {
  26920. set$7(contextBarEle, "display", "none");
  26921. } else {
  26922. lastTrigger.set(0);
  26923. InlineView.reposition(contextbar);
  26924. }
  26925. }
  26926. };
  26927. var wrapInPopDialog = function(toolbarSpec) {
  26928. return {
  26929. dom: {
  26930. tag: "div",
  26931. classes: ["tox-pop__dialog"]
  26932. },
  26933. components: [toolbarSpec],
  26934. behaviours: derive$1([
  26935. Keying.config({ mode: "acyclic" }),
  26936. config("pop-dialog-wrap-events", [
  26937. runOnAttached(function(comp) {
  26938. editor.shortcuts.add("ctrl+F9", "focus statusbar", function() {
  26939. return Keying.focusIn(comp);
  26940. });
  26941. }),
  26942. runOnDetached(function(_comp) {
  26943. editor.shortcuts.remove("ctrl+F9");
  26944. })
  26945. ])
  26946. ])
  26947. };
  26948. };
  26949. var getScopes = cached(function() {
  26950. return categorise(registryContextToolbars, function(toolbarApi) {
  26951. var alloySpec = buildToolbar([toolbarApi]);
  26952. emitWith(contextbar, forwardSlideEvent, { forwardContents: wrapInPopDialog(alloySpec) });
  26953. });
  26954. });
  26955. var buildContextToolbarGroups = function(allButtons, ctx) {
  26956. return identifyButtons(editor, {
  26957. buttons: allButtons,
  26958. toolbar: ctx.items,
  26959. allowToolbarGroups: false
  26960. }, extras, Optional.some(["form:"]));
  26961. };
  26962. var buildContextFormGroups = function(ctx, providers) {
  26963. return ContextForm.buildInitGroups(ctx, providers);
  26964. };
  26965. var buildToolbar = function(toolbars) {
  26966. var buttons = editor.ui.registry.getAll().buttons;
  26967. var scopes = getScopes();
  26968. var allButtons = __assign(__assign({}, buttons), scopes.formNavigators);
  26969. var toolbarType = getToolbarMode(editor) === ToolbarMode.scrolling ? ToolbarMode.scrolling : ToolbarMode.default;
  26970. var initGroups = flatten(map$2(toolbars, function(ctx) {
  26971. return ctx.type === "contexttoolbar" ? buildContextToolbarGroups(allButtons, ctx) : buildContextFormGroups(ctx, sharedBackstage.providers);
  26972. }));
  26973. return renderToolbar({
  26974. type: toolbarType,
  26975. uid: generate$6("context-toolbar"),
  26976. initGroups,
  26977. onEscape: Optional.none,
  26978. cyclicKeying: true,
  26979. providers: sharedBackstage.providers
  26980. });
  26981. };
  26982. var getAnchor2 = function(position2, element2) {
  26983. var anchorage = position2 === "node" ? sharedBackstage.anchors.node(element2) : sharedBackstage.anchors.cursor();
  26984. var anchorLayout = getAnchorLayout(editor, position2, isTouch2(), {
  26985. lastElement: lastElement.get,
  26986. isReposition: function() {
  26987. return is$1(lastTrigger.get(), 0);
  26988. },
  26989. getMode: function() {
  26990. return Positioning.getMode(sink);
  26991. }
  26992. });
  26993. return deepMerge(anchorage, anchorLayout);
  26994. };
  26995. var launchContext = function(toolbarApi, elem) {
  26996. launchContextToolbar.cancel();
  26997. if (!canLaunchToolbar()) {
  26998. return;
  26999. }
  27000. var toolbarSpec = buildToolbar(toolbarApi);
  27001. var position2 = toolbarApi[0].position;
  27002. var anchor2 = getAnchor2(position2, elem);
  27003. lastContextPosition.set(position2);
  27004. lastTrigger.set(1);
  27005. var contextBarEle = contextbar.element;
  27006. remove$6(contextBarEle, "display");
  27007. if (!isSameLaunchElement(elem)) {
  27008. remove$2(contextBarEle, transitionClass);
  27009. Positioning.reset(sink, contextbar);
  27010. }
  27011. InlineView.showWithinBounds(contextbar, wrapInPopDialog(toolbarSpec), {
  27012. anchor: anchor2,
  27013. transition: {
  27014. classes: [transitionClass],
  27015. mode: "placement"
  27016. }
  27017. }, function() {
  27018. return Optional.some(getBounds2());
  27019. });
  27020. elem.fold(lastElement.clear, lastElement.set);
  27021. if (shouldContextToolbarHide()) {
  27022. set$7(contextBarEle, "display", "none");
  27023. }
  27024. };
  27025. var launchContextToolbar = last(function() {
  27026. if (!editor.hasFocus() || editor.removed) {
  27027. return;
  27028. }
  27029. if (has(contextbar.element, transitionClass)) {
  27030. launchContextToolbar.throttle();
  27031. } else {
  27032. var scopes = getScopes();
  27033. lookup$1(scopes, editor).fold(close2, function(info) {
  27034. launchContext(info.toolbars, Optional.some(info.elem));
  27035. });
  27036. }
  27037. }, 17);
  27038. editor.on("init", function() {
  27039. editor.on("remove", close2);
  27040. editor.on("ScrollContent ScrollWindow ObjectResized ResizeEditor longpress", hideOrRepositionIfNecessary);
  27041. editor.on("click keyup focus SetContent", launchContextToolbar.throttle);
  27042. editor.on(hideContextToolbarEvent, close2);
  27043. editor.on(showContextToolbarEvent, function(e) {
  27044. var scopes = getScopes();
  27045. get$e(scopes.lookupTable, e.toolbarKey).each(function(ctx) {
  27046. launchContext([ctx], someIf(e.target !== editor, e.target));
  27047. InlineView.getContent(contextbar).each(Keying.focusIn);
  27048. });
  27049. });
  27050. editor.on("focusout", function(_e) {
  27051. global$f.setEditorTimeout(editor, function() {
  27052. if (search(sink.element).isNone() && search(contextbar.element).isNone()) {
  27053. close2();
  27054. }
  27055. }, 0);
  27056. });
  27057. editor.on("SwitchMode", function() {
  27058. if (editor.mode.isReadOnly()) {
  27059. close2();
  27060. }
  27061. });
  27062. editor.on("AfterProgressState", function(event) {
  27063. if (event.state) {
  27064. close2();
  27065. } else if (editor.hasFocus()) {
  27066. launchContextToolbar.throttle();
  27067. }
  27068. });
  27069. editor.on("NodeChange", function(_e) {
  27070. search(contextbar.element).fold(launchContextToolbar.throttle, noop);
  27071. });
  27072. });
  27073. };
  27074. var register$6 = function(editor) {
  27075. var alignToolbarButtons = [
  27076. {
  27077. name: "alignleft",
  27078. text: "Align left",
  27079. cmd: "JustifyLeft",
  27080. icon: "align-left"
  27081. },
  27082. {
  27083. name: "aligncenter",
  27084. text: "Align center",
  27085. cmd: "JustifyCenter",
  27086. icon: "align-center"
  27087. },
  27088. {
  27089. name: "alignright",
  27090. text: "Align right",
  27091. cmd: "JustifyRight",
  27092. icon: "align-right"
  27093. },
  27094. {
  27095. name: "alignjustify",
  27096. text: "Justify",
  27097. cmd: "JustifyFull",
  27098. icon: "align-justify"
  27099. }
  27100. ];
  27101. each$1(alignToolbarButtons, function(item2) {
  27102. editor.ui.registry.addToggleButton(item2.name, {
  27103. tooltip: item2.text,
  27104. icon: item2.icon,
  27105. onAction: onActionExecCommand(editor, item2.cmd),
  27106. onSetup: onSetupFormatToggle(editor, item2.name)
  27107. });
  27108. });
  27109. editor.ui.registry.addButton("alignnone", {
  27110. tooltip: "No alignment",
  27111. icon: "align-none",
  27112. onAction: onActionExecCommand(editor, "JustifyNone")
  27113. });
  27114. };
  27115. var units = {
  27116. unsupportedLength: [
  27117. "em",
  27118. "ex",
  27119. "cap",
  27120. "ch",
  27121. "ic",
  27122. "rem",
  27123. "lh",
  27124. "rlh",
  27125. "vw",
  27126. "vh",
  27127. "vi",
  27128. "vb",
  27129. "vmin",
  27130. "vmax",
  27131. "cm",
  27132. "mm",
  27133. "Q",
  27134. "in",
  27135. "pc",
  27136. "pt",
  27137. "px"
  27138. ],
  27139. fixed: [
  27140. "px",
  27141. "pt"
  27142. ],
  27143. relative: ["%"],
  27144. empty: [""]
  27145. };
  27146. var pattern = function() {
  27147. var decimalDigits = "[0-9]+";
  27148. var signedInteger = "[+-]?" + decimalDigits;
  27149. var exponentPart = "[eE]" + signedInteger;
  27150. var dot = "\\.";
  27151. var opt = function(input2) {
  27152. return "(?:" + input2 + ")?";
  27153. };
  27154. var unsignedDecimalLiteral = [
  27155. "Infinity",
  27156. decimalDigits + dot + opt(decimalDigits) + opt(exponentPart),
  27157. dot + decimalDigits + opt(exponentPart),
  27158. decimalDigits + opt(exponentPart)
  27159. ].join("|");
  27160. var float = "[+-]?(?:" + unsignedDecimalLiteral + ")";
  27161. return new RegExp("^(" + float + ")(.*)$");
  27162. }();
  27163. var isUnit = function(unit, accepted) {
  27164. return exists(accepted, function(acc) {
  27165. return exists(units[acc], function(check) {
  27166. return unit === check;
  27167. });
  27168. });
  27169. };
  27170. var parse = function(input2, accepted) {
  27171. var match = Optional.from(pattern.exec(input2));
  27172. return match.bind(function(array) {
  27173. var value2 = Number(array[1]);
  27174. var unitRaw = array[2];
  27175. if (isUnit(unitRaw, accepted)) {
  27176. return Optional.some({
  27177. value: value2,
  27178. unit: unitRaw
  27179. });
  27180. } else {
  27181. return Optional.none();
  27182. }
  27183. });
  27184. };
  27185. var normalise = function(input2, accepted) {
  27186. return parse(input2, accepted).map(function(_a2) {
  27187. var value2 = _a2.value, unit = _a2.unit;
  27188. return value2 + unit;
  27189. });
  27190. };
  27191. var registerController = function(editor, spec) {
  27192. var getMenuItems2 = function() {
  27193. var options = spec.getOptions(editor);
  27194. var initial = spec.getCurrent(editor).map(spec.hash);
  27195. var current = value$1();
  27196. return map$2(options, function(value2) {
  27197. return {
  27198. type: "togglemenuitem",
  27199. text: spec.display(value2),
  27200. onSetup: function(api2) {
  27201. var setActive = function(active2) {
  27202. if (active2) {
  27203. current.on(function(oldApi) {
  27204. return oldApi.setActive(false);
  27205. });
  27206. current.set(api2);
  27207. }
  27208. api2.setActive(active2);
  27209. };
  27210. setActive(is$1(initial, spec.hash(value2)));
  27211. var unbindWatcher = spec.watcher(editor, value2, setActive);
  27212. return function() {
  27213. current.clear();
  27214. unbindWatcher();
  27215. };
  27216. },
  27217. onAction: function() {
  27218. return spec.setCurrent(editor, value2);
  27219. }
  27220. };
  27221. });
  27222. };
  27223. editor.ui.registry.addMenuButton(spec.name, {
  27224. tooltip: spec.text,
  27225. icon: spec.icon,
  27226. fetch: function(callback) {
  27227. return callback(getMenuItems2());
  27228. },
  27229. onSetup: spec.onToolbarSetup
  27230. });
  27231. editor.ui.registry.addNestedMenuItem(spec.name, {
  27232. type: "nestedmenuitem",
  27233. text: spec.text,
  27234. getSubmenuItems: getMenuItems2,
  27235. onSetup: spec.onMenuSetup
  27236. });
  27237. };
  27238. var lineHeightSpec = {
  27239. name: "lineheight",
  27240. text: "Line height",
  27241. icon: "line-height",
  27242. getOptions: getLineHeightFormats,
  27243. hash: function(input2) {
  27244. return normalise(input2, [
  27245. "fixed",
  27246. "relative",
  27247. "empty"
  27248. ]).getOr(input2);
  27249. },
  27250. display: identity$1,
  27251. watcher: function(editor, value2, callback) {
  27252. return editor.formatter.formatChanged("lineheight", callback, false, { value: value2 }).unbind;
  27253. },
  27254. getCurrent: function(editor) {
  27255. return Optional.from(editor.queryCommandValue("LineHeight"));
  27256. },
  27257. setCurrent: function(editor, value2) {
  27258. return editor.execCommand("LineHeight", false, value2);
  27259. }
  27260. };
  27261. var languageSpec = function(editor) {
  27262. var settingsOpt = Optional.from(getContentLanguages(editor));
  27263. return settingsOpt.map(function(settings) {
  27264. return {
  27265. name: "language",
  27266. text: "Language",
  27267. icon: "language",
  27268. getOptions: constant$1(settings),
  27269. hash: function(input2) {
  27270. return isUndefined(input2.customCode) ? input2.code : input2.code + "/" + input2.customCode;
  27271. },
  27272. display: function(input2) {
  27273. return input2.title;
  27274. },
  27275. watcher: function(editor2, value2, callback) {
  27276. return editor2.formatter.formatChanged("lang", callback, false, {
  27277. value: value2.code,
  27278. customValue: value2.customCode
  27279. }).unbind;
  27280. },
  27281. getCurrent: function(editor2) {
  27282. var node = SugarElement.fromDom(editor2.selection.getNode());
  27283. return closest$4(node, function(n) {
  27284. return Optional.some(n).filter(isElement$2).bind(function(ele) {
  27285. var codeOpt = getOpt(ele, "lang");
  27286. return codeOpt.map(function(code) {
  27287. var customCode = getOpt(ele, "data-mce-lang").getOrUndefined();
  27288. return {
  27289. code,
  27290. customCode,
  27291. title: ""
  27292. };
  27293. });
  27294. });
  27295. });
  27296. },
  27297. setCurrent: function(editor2, lang) {
  27298. return editor2.execCommand("Lang", false, lang);
  27299. },
  27300. onToolbarSetup: function(api2) {
  27301. var unbinder = unbindable();
  27302. api2.setActive(editor.formatter.match("lang", {}, void 0, true));
  27303. unbinder.set(editor.formatter.formatChanged("lang", api2.setActive, true));
  27304. return unbinder.clear;
  27305. }
  27306. };
  27307. });
  27308. };
  27309. var register$5 = function(editor) {
  27310. registerController(editor, lineHeightSpec);
  27311. languageSpec(editor).each(function(spec) {
  27312. return registerController(editor, spec);
  27313. });
  27314. };
  27315. var register$4 = function(editor, backstage) {
  27316. alignSelectMenu(editor, backstage);
  27317. fontSelectMenu(editor, backstage);
  27318. styleSelectMenu(editor, backstage);
  27319. formatSelectMenu(editor, backstage);
  27320. fontsizeSelectMenu(editor, backstage);
  27321. };
  27322. var onSetupOutdentState = function(editor) {
  27323. return onSetupEvent(editor, "NodeChange", function(api2) {
  27324. api2.setDisabled(!editor.queryCommandState("outdent"));
  27325. });
  27326. };
  27327. var registerButtons$2 = function(editor) {
  27328. editor.ui.registry.addButton("outdent", {
  27329. tooltip: "Decrease indent",
  27330. icon: "outdent",
  27331. onSetup: onSetupOutdentState(editor),
  27332. onAction: onActionExecCommand(editor, "outdent")
  27333. });
  27334. editor.ui.registry.addButton("indent", {
  27335. tooltip: "Increase indent",
  27336. icon: "indent",
  27337. onAction: onActionExecCommand(editor, "indent")
  27338. });
  27339. };
  27340. var register$3 = function(editor) {
  27341. registerButtons$2(editor);
  27342. };
  27343. var onActionToggleFormat = function(editor, fmt) {
  27344. return function() {
  27345. editor.execCommand("mceToggleFormat", false, fmt);
  27346. };
  27347. };
  27348. var registerFormatButtons = function(editor) {
  27349. global$5.each([
  27350. {
  27351. name: "bold",
  27352. text: "Bold",
  27353. icon: "bold"
  27354. },
  27355. {
  27356. name: "italic",
  27357. text: "Italic",
  27358. icon: "italic"
  27359. },
  27360. {
  27361. name: "underline",
  27362. text: "Underline",
  27363. icon: "underline"
  27364. },
  27365. {
  27366. name: "strikethrough",
  27367. text: "Strikethrough",
  27368. icon: "strike-through"
  27369. },
  27370. {
  27371. name: "subscript",
  27372. text: "Subscript",
  27373. icon: "subscript"
  27374. },
  27375. {
  27376. name: "superscript",
  27377. text: "Superscript",
  27378. icon: "superscript"
  27379. }
  27380. ], function(btn, _idx) {
  27381. editor.ui.registry.addToggleButton(btn.name, {
  27382. tooltip: btn.text,
  27383. icon: btn.icon,
  27384. onSetup: onSetupFormatToggle(editor, btn.name),
  27385. onAction: onActionToggleFormat(editor, btn.name)
  27386. });
  27387. });
  27388. for (var i = 1; i <= 6; i++) {
  27389. var name_1 = "h" + i;
  27390. editor.ui.registry.addToggleButton(name_1, {
  27391. text: name_1.toUpperCase(),
  27392. tooltip: "Heading " + i,
  27393. onSetup: onSetupFormatToggle(editor, name_1),
  27394. onAction: onActionToggleFormat(editor, name_1)
  27395. });
  27396. }
  27397. };
  27398. var registerCommandButtons = function(editor) {
  27399. global$5.each([
  27400. {
  27401. name: "cut",
  27402. text: "Cut",
  27403. action: "Cut",
  27404. icon: "cut"
  27405. },
  27406. {
  27407. name: "copy",
  27408. text: "Copy",
  27409. action: "Copy",
  27410. icon: "copy"
  27411. },
  27412. {
  27413. name: "paste",
  27414. text: "Paste",
  27415. action: "Paste",
  27416. icon: "paste"
  27417. },
  27418. {
  27419. name: "help",
  27420. text: "Help",
  27421. action: "mceHelp",
  27422. icon: "help"
  27423. },
  27424. {
  27425. name: "selectall",
  27426. text: "Select all",
  27427. action: "SelectAll",
  27428. icon: "select-all"
  27429. },
  27430. {
  27431. name: "newdocument",
  27432. text: "New document",
  27433. action: "mceNewDocument",
  27434. icon: "new-document"
  27435. },
  27436. {
  27437. name: "removeformat",
  27438. text: "Clear formatting",
  27439. action: "RemoveFormat",
  27440. icon: "remove-formatting"
  27441. },
  27442. {
  27443. name: "remove",
  27444. text: "Remove",
  27445. action: "Delete",
  27446. icon: "remove"
  27447. }
  27448. ], function(btn) {
  27449. editor.ui.registry.addButton(btn.name, {
  27450. tooltip: btn.text,
  27451. icon: btn.icon,
  27452. onAction: onActionExecCommand(editor, btn.action)
  27453. });
  27454. });
  27455. };
  27456. var registerCommandToggleButtons = function(editor) {
  27457. global$5.each([{
  27458. name: "blockquote",
  27459. text: "Blockquote",
  27460. action: "mceBlockQuote",
  27461. icon: "quote"
  27462. }], function(btn) {
  27463. editor.ui.registry.addToggleButton(btn.name, {
  27464. tooltip: btn.text,
  27465. icon: btn.icon,
  27466. onAction: onActionExecCommand(editor, btn.action),
  27467. onSetup: onSetupFormatToggle(editor, btn.name)
  27468. });
  27469. });
  27470. };
  27471. var registerButtons$1 = function(editor) {
  27472. registerFormatButtons(editor);
  27473. registerCommandButtons(editor);
  27474. registerCommandToggleButtons(editor);
  27475. };
  27476. var registerMenuItems$2 = function(editor) {
  27477. global$5.each([
  27478. {
  27479. name: "bold",
  27480. text: "Bold",
  27481. action: "Bold",
  27482. icon: "bold",
  27483. shortcut: "Meta+B"
  27484. },
  27485. {
  27486. name: "italic",
  27487. text: "Italic",
  27488. action: "Italic",
  27489. icon: "italic",
  27490. shortcut: "Meta+I"
  27491. },
  27492. {
  27493. name: "underline",
  27494. text: "Underline",
  27495. action: "Underline",
  27496. icon: "underline",
  27497. shortcut: "Meta+U"
  27498. },
  27499. {
  27500. name: "strikethrough",
  27501. text: "Strikethrough",
  27502. action: "Strikethrough",
  27503. icon: "strike-through",
  27504. shortcut: ""
  27505. },
  27506. {
  27507. name: "subscript",
  27508. text: "Subscript",
  27509. action: "Subscript",
  27510. icon: "subscript",
  27511. shortcut: ""
  27512. },
  27513. {
  27514. name: "superscript",
  27515. text: "Superscript",
  27516. action: "Superscript",
  27517. icon: "superscript",
  27518. shortcut: ""
  27519. },
  27520. {
  27521. name: "removeformat",
  27522. text: "Clear formatting",
  27523. action: "RemoveFormat",
  27524. icon: "remove-formatting",
  27525. shortcut: ""
  27526. },
  27527. {
  27528. name: "newdocument",
  27529. text: "New document",
  27530. action: "mceNewDocument",
  27531. icon: "new-document",
  27532. shortcut: ""
  27533. },
  27534. {
  27535. name: "cut",
  27536. text: "Cut",
  27537. action: "Cut",
  27538. icon: "cut",
  27539. shortcut: "Meta+X"
  27540. },
  27541. {
  27542. name: "copy",
  27543. text: "Copy",
  27544. action: "Copy",
  27545. icon: "copy",
  27546. shortcut: "Meta+C"
  27547. },
  27548. {
  27549. name: "paste",
  27550. text: "Paste",
  27551. action: "Paste",
  27552. icon: "paste",
  27553. shortcut: "Meta+V"
  27554. },
  27555. {
  27556. name: "selectall",
  27557. text: "Select all",
  27558. action: "SelectAll",
  27559. icon: "select-all",
  27560. shortcut: "Meta+A"
  27561. }
  27562. ], function(btn) {
  27563. editor.ui.registry.addMenuItem(btn.name, {
  27564. text: btn.text,
  27565. icon: btn.icon,
  27566. shortcut: btn.shortcut,
  27567. onAction: onActionExecCommand(editor, btn.action)
  27568. });
  27569. });
  27570. editor.ui.registry.addMenuItem("codeformat", {
  27571. text: "Code",
  27572. icon: "sourcecode",
  27573. onAction: onActionToggleFormat(editor, "code")
  27574. });
  27575. };
  27576. var register$2 = function(editor) {
  27577. registerButtons$1(editor);
  27578. registerMenuItems$2(editor);
  27579. };
  27580. var onSetupUndoRedoState = function(editor, type2) {
  27581. return onSetupEvent(editor, "Undo Redo AddUndo TypingUndo ClearUndos SwitchMode", function(api2) {
  27582. api2.setDisabled(editor.mode.isReadOnly() || !editor.undoManager[type2]());
  27583. });
  27584. };
  27585. var registerMenuItems$1 = function(editor) {
  27586. editor.ui.registry.addMenuItem("undo", {
  27587. text: "Undo",
  27588. icon: "undo",
  27589. shortcut: "Meta+Z",
  27590. onSetup: onSetupUndoRedoState(editor, "hasUndo"),
  27591. onAction: onActionExecCommand(editor, "undo")
  27592. });
  27593. editor.ui.registry.addMenuItem("redo", {
  27594. text: "Redo",
  27595. icon: "redo",
  27596. shortcut: "Meta+Y",
  27597. onSetup: onSetupUndoRedoState(editor, "hasRedo"),
  27598. onAction: onActionExecCommand(editor, "redo")
  27599. });
  27600. };
  27601. var registerButtons = function(editor) {
  27602. editor.ui.registry.addButton("undo", {
  27603. tooltip: "Undo",
  27604. icon: "undo",
  27605. disabled: true,
  27606. onSetup: onSetupUndoRedoState(editor, "hasUndo"),
  27607. onAction: onActionExecCommand(editor, "undo")
  27608. });
  27609. editor.ui.registry.addButton("redo", {
  27610. tooltip: "Redo",
  27611. icon: "redo",
  27612. disabled: true,
  27613. onSetup: onSetupUndoRedoState(editor, "hasRedo"),
  27614. onAction: onActionExecCommand(editor, "redo")
  27615. });
  27616. };
  27617. var register$1 = function(editor) {
  27618. registerMenuItems$1(editor);
  27619. registerButtons(editor);
  27620. };
  27621. var onSetupVisualAidState = function(editor) {
  27622. return onSetupEvent(editor, "VisualAid", function(api2) {
  27623. api2.setActive(editor.hasVisual);
  27624. });
  27625. };
  27626. var registerMenuItems = function(editor) {
  27627. editor.ui.registry.addToggleMenuItem("visualaid", {
  27628. text: "Visual aids",
  27629. onSetup: onSetupVisualAidState(editor),
  27630. onAction: onActionExecCommand(editor, "mceToggleVisualAid")
  27631. });
  27632. };
  27633. var registerToolbarButton = function(editor) {
  27634. editor.ui.registry.addButton("visualaid", {
  27635. tooltip: "Visual aids",
  27636. text: "Visual aids",
  27637. onAction: onActionExecCommand(editor, "mceToggleVisualAid")
  27638. });
  27639. };
  27640. var register = function(editor) {
  27641. registerToolbarButton(editor);
  27642. registerMenuItems(editor);
  27643. };
  27644. var setup$6 = function(editor, backstage) {
  27645. register$6(editor);
  27646. register$2(editor);
  27647. register$4(editor, backstage);
  27648. register$1(editor);
  27649. register$a(editor);
  27650. register(editor);
  27651. register$3(editor);
  27652. register$5(editor);
  27653. };
  27654. var nu = function(x, y) {
  27655. return {
  27656. type: "makeshift",
  27657. x,
  27658. y
  27659. };
  27660. };
  27661. var transpose = function(pos, dx, dy) {
  27662. return nu(pos.x + dx, pos.y + dy);
  27663. };
  27664. var isTouchEvent = function(e) {
  27665. return e.type === "longpress" || e.type.indexOf("touch") === 0;
  27666. };
  27667. var fromPageXY = function(e) {
  27668. if (isTouchEvent(e)) {
  27669. var touch2 = e.touches[0];
  27670. return nu(touch2.pageX, touch2.pageY);
  27671. } else {
  27672. return nu(e.pageX, e.pageY);
  27673. }
  27674. };
  27675. var fromClientXY = function(e) {
  27676. if (isTouchEvent(e)) {
  27677. var touch2 = e.touches[0];
  27678. return nu(touch2.clientX, touch2.clientY);
  27679. } else {
  27680. return nu(e.clientX, e.clientY);
  27681. }
  27682. };
  27683. var transposeContentAreaContainer = function(element2, pos) {
  27684. var containerPos = global$b.DOM.getPos(element2);
  27685. return transpose(pos, containerPos.x, containerPos.y);
  27686. };
  27687. var getPointAnchor = function(editor, e) {
  27688. if (e.type === "contextmenu" || e.type === "longpress") {
  27689. if (editor.inline) {
  27690. return fromPageXY(e);
  27691. } else {
  27692. return transposeContentAreaContainer(editor.getContentAreaContainer(), fromClientXY(e));
  27693. }
  27694. } else {
  27695. return getSelectionAnchor(editor);
  27696. }
  27697. };
  27698. var getSelectionAnchor = function(editor) {
  27699. return {
  27700. type: "selection",
  27701. root: SugarElement.fromDom(editor.selection.getNode())
  27702. };
  27703. };
  27704. var getNodeAnchor = function(editor) {
  27705. return {
  27706. type: "node",
  27707. node: Optional.some(SugarElement.fromDom(editor.selection.getNode())),
  27708. root: SugarElement.fromDom(editor.getBody())
  27709. };
  27710. };
  27711. var getAnchorSpec$1 = function(editor, e, anchorType) {
  27712. switch (anchorType) {
  27713. case "node":
  27714. return getNodeAnchor(editor);
  27715. case "point":
  27716. return getPointAnchor(editor, e);
  27717. case "selection":
  27718. return getSelectionAnchor(editor);
  27719. }
  27720. };
  27721. var initAndShow$1 = function(editor, e, buildMenu, backstage, contextmenu, anchorType) {
  27722. var items = buildMenu();
  27723. var anchorSpec = getAnchorSpec$1(editor, e, anchorType);
  27724. build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false).map(function(menuData) {
  27725. e.preventDefault();
  27726. InlineView.showMenuAt(contextmenu, { anchor: anchorSpec }, {
  27727. menu: { markers: markers("normal") },
  27728. data: menuData
  27729. });
  27730. });
  27731. };
  27732. var layouts = {
  27733. onLtr: function() {
  27734. return [
  27735. south$2,
  27736. southeast$2,
  27737. southwest$2,
  27738. northeast$2,
  27739. northwest$2,
  27740. north$2,
  27741. north,
  27742. south,
  27743. northeast,
  27744. southeast,
  27745. northwest,
  27746. southwest
  27747. ];
  27748. },
  27749. onRtl: function() {
  27750. return [
  27751. south$2,
  27752. southwest$2,
  27753. southeast$2,
  27754. northwest$2,
  27755. northeast$2,
  27756. north$2,
  27757. north,
  27758. south,
  27759. northwest,
  27760. southwest,
  27761. northeast,
  27762. southeast
  27763. ];
  27764. }
  27765. };
  27766. var bubbleSize = 12;
  27767. var bubbleAlignments = {
  27768. valignCentre: [],
  27769. alignCentre: [],
  27770. alignLeft: ["tox-pop--align-left"],
  27771. alignRight: ["tox-pop--align-right"],
  27772. right: ["tox-pop--right"],
  27773. left: ["tox-pop--left"],
  27774. bottom: ["tox-pop--bottom"],
  27775. top: ["tox-pop--top"]
  27776. };
  27777. var isTouchWithinSelection = function(editor, e) {
  27778. var selection = editor.selection;
  27779. if (selection.isCollapsed() || e.touches.length < 1) {
  27780. return false;
  27781. } else {
  27782. var touch_1 = e.touches[0];
  27783. var rng = selection.getRng();
  27784. var rngRectOpt = getFirstRect(editor.getWin(), SimSelection.domRange(rng));
  27785. return rngRectOpt.exists(function(rngRect) {
  27786. return rngRect.left <= touch_1.clientX && rngRect.right >= touch_1.clientX && rngRect.top <= touch_1.clientY && rngRect.bottom >= touch_1.clientY;
  27787. });
  27788. }
  27789. };
  27790. var setupiOSOverrides = function(editor) {
  27791. var originalSelection = editor.selection.getRng();
  27792. var selectionReset = function() {
  27793. global$f.setEditorTimeout(editor, function() {
  27794. editor.selection.setRng(originalSelection);
  27795. }, 10);
  27796. unbindEventListeners();
  27797. };
  27798. editor.once("touchend", selectionReset);
  27799. var preventMousedown = function(e) {
  27800. e.preventDefault();
  27801. e.stopImmediatePropagation();
  27802. };
  27803. editor.on("mousedown", preventMousedown, true);
  27804. var clearSelectionReset = function() {
  27805. return unbindEventListeners();
  27806. };
  27807. editor.once("longpresscancel", clearSelectionReset);
  27808. var unbindEventListeners = function() {
  27809. editor.off("touchend", selectionReset);
  27810. editor.off("longpresscancel", clearSelectionReset);
  27811. editor.off("mousedown", preventMousedown);
  27812. };
  27813. };
  27814. var getAnchorSpec = function(editor, e, anchorType) {
  27815. var anchorSpec = getAnchorSpec$1(editor, e, anchorType);
  27816. var bubbleYOffset = anchorType === "point" ? bubbleSize : 0;
  27817. return __assign({
  27818. bubble: nu$5(0, bubbleYOffset, bubbleAlignments),
  27819. layouts,
  27820. overrides: {
  27821. maxWidthFunction: expandable(),
  27822. maxHeightFunction: expandable$1()
  27823. }
  27824. }, anchorSpec);
  27825. };
  27826. var show = function(editor, e, items, backstage, contextmenu, anchorType, highlightImmediately) {
  27827. var anchorSpec = getAnchorSpec(editor, e, anchorType);
  27828. build(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, true).map(function(menuData) {
  27829. e.preventDefault();
  27830. InlineView.showMenuWithinBounds(contextmenu, { anchor: anchorSpec }, {
  27831. menu: {
  27832. markers: markers("normal"),
  27833. highlightImmediately
  27834. },
  27835. data: menuData,
  27836. type: "horizontal"
  27837. }, function() {
  27838. return Optional.some(getContextToolbarBounds(editor, backstage.shared, anchorType === "node" ? "node" : "selection"));
  27839. });
  27840. editor.fire(hideContextToolbarEvent);
  27841. });
  27842. };
  27843. var initAndShow = function(editor, e, buildMenu, backstage, contextmenu, anchorType) {
  27844. var detection2 = detect$1();
  27845. var isiOS = detection2.os.isiOS();
  27846. var isOSX = detection2.os.isOSX();
  27847. var isAndroid = detection2.os.isAndroid();
  27848. var isTouch2 = detection2.deviceType.isTouch();
  27849. var shouldHighlightImmediately = function() {
  27850. return !(isAndroid || isiOS || isOSX && isTouch2);
  27851. };
  27852. var open2 = function() {
  27853. var items = buildMenu();
  27854. show(editor, e, items, backstage, contextmenu, anchorType, shouldHighlightImmediately());
  27855. };
  27856. if ((isOSX || isiOS) && anchorType !== "node") {
  27857. var openiOS_1 = function() {
  27858. setupiOSOverrides(editor);
  27859. open2();
  27860. };
  27861. if (isTouchWithinSelection(editor, e)) {
  27862. openiOS_1();
  27863. } else {
  27864. editor.once("selectionchange", openiOS_1);
  27865. editor.once("touchend", function() {
  27866. return editor.off("selectionchange", openiOS_1);
  27867. });
  27868. }
  27869. } else {
  27870. open2();
  27871. }
  27872. };
  27873. var patchPipeConfig = function(config2) {
  27874. return typeof config2 === "string" ? config2.split(/[ ,]/) : config2;
  27875. };
  27876. var shouldNeverUseNative = function(editor) {
  27877. return editor.getParam("contextmenu_never_use_native", false, "boolean");
  27878. };
  27879. var getMenuItems = function(editor, name2, defaultItems) {
  27880. var contextMenus = editor.ui.registry.getAll().contextMenus;
  27881. return Optional.from(editor.getParam(name2)).map(patchPipeConfig).getOrThunk(function() {
  27882. return filter$2(patchPipeConfig(defaultItems), function(item2) {
  27883. return has$2(contextMenus, item2);
  27884. });
  27885. });
  27886. };
  27887. var isContextMenuDisabled = function(editor) {
  27888. return editor.getParam("contextmenu") === false;
  27889. };
  27890. var getContextMenu = function(editor) {
  27891. return getMenuItems(editor, "contextmenu", "link linkchecker image imagetools table spellchecker configurepermanentpen");
  27892. };
  27893. var getAvoidOverlapSelector = function(editor) {
  27894. return editor.getParam("contextmenu_avoid_overlap", "", "string");
  27895. };
  27896. var isSeparator = function(item2) {
  27897. return isString(item2) ? item2 === "|" : item2.type === "separator";
  27898. };
  27899. var separator = { type: "separator" };
  27900. var makeContextItem = function(item2) {
  27901. var commonMenuItem = function(item3) {
  27902. return {
  27903. text: item3.text,
  27904. icon: item3.icon,
  27905. disabled: item3.disabled,
  27906. shortcut: item3.shortcut
  27907. };
  27908. };
  27909. if (isString(item2)) {
  27910. return item2;
  27911. } else {
  27912. switch (item2.type) {
  27913. case "separator":
  27914. return separator;
  27915. case "submenu":
  27916. return __assign(__assign({ type: "nestedmenuitem" }, commonMenuItem(item2)), {
  27917. getSubmenuItems: function() {
  27918. var items = item2.getSubmenuItems();
  27919. if (isString(items)) {
  27920. return items;
  27921. } else {
  27922. return map$2(items, makeContextItem);
  27923. }
  27924. }
  27925. });
  27926. default:
  27927. return __assign(__assign({ type: "menuitem" }, commonMenuItem(item2)), { onAction: noarg(item2.onAction) });
  27928. }
  27929. }
  27930. };
  27931. var addContextMenuGroup = function(xs, groupItems) {
  27932. if (groupItems.length === 0) {
  27933. return xs;
  27934. }
  27935. var lastMenuItem = last$2(xs).filter(function(item2) {
  27936. return !isSeparator(item2);
  27937. });
  27938. var before2 = lastMenuItem.fold(function() {
  27939. return [];
  27940. }, function(_) {
  27941. return [separator];
  27942. });
  27943. return xs.concat(before2).concat(groupItems).concat([separator]);
  27944. };
  27945. var generateContextMenu = function(contextMenus, menuConfig, selectedElement) {
  27946. var sections = foldl(menuConfig, function(acc, name2) {
  27947. return get$e(contextMenus, name2.toLowerCase()).map(function(menu2) {
  27948. var items = menu2.update(selectedElement);
  27949. if (isString(items)) {
  27950. return addContextMenuGroup(acc, items.split(" "));
  27951. } else if (items.length > 0) {
  27952. var allItems = map$2(items, makeContextItem);
  27953. return addContextMenuGroup(acc, allItems);
  27954. } else {
  27955. return acc;
  27956. }
  27957. }).getOrThunk(function() {
  27958. return acc.concat([name2]);
  27959. });
  27960. }, []);
  27961. if (sections.length > 0 && isSeparator(sections[sections.length - 1])) {
  27962. sections.pop();
  27963. }
  27964. return sections;
  27965. };
  27966. var isNativeOverrideKeyEvent = function(editor, e) {
  27967. return e.ctrlKey && !shouldNeverUseNative(editor);
  27968. };
  27969. var isTriggeredByKeyboard = function(editor, e) {
  27970. return e.type !== "longpress" && (e.button !== 2 || e.target === editor.getBody() && e.pointerType === "");
  27971. };
  27972. var getSelectedElement = function(editor, e) {
  27973. return isTriggeredByKeyboard(editor, e) ? editor.selection.getStart(true) : e.target;
  27974. };
  27975. var getAnchorType = function(editor, e) {
  27976. var selector = getAvoidOverlapSelector(editor);
  27977. var anchorType = isTriggeredByKeyboard(editor, e) ? "selection" : "point";
  27978. if (isNotEmpty(selector)) {
  27979. var target = getSelectedElement(editor, e);
  27980. var selectorExists = closest(SugarElement.fromDom(target), selector);
  27981. return selectorExists ? "node" : anchorType;
  27982. } else {
  27983. return anchorType;
  27984. }
  27985. };
  27986. var setup$5 = function(editor, lazySink, backstage) {
  27987. var detection2 = detect$1();
  27988. var isTouch2 = detection2.deviceType.isTouch;
  27989. var contextmenu = build$1(InlineView.sketch({
  27990. dom: { tag: "div" },
  27991. lazySink,
  27992. onEscape: function() {
  27993. return editor.focus();
  27994. },
  27995. onShow: function() {
  27996. return backstage.setContextMenuState(true);
  27997. },
  27998. onHide: function() {
  27999. return backstage.setContextMenuState(false);
  28000. },
  28001. fireDismissalEventInstead: {},
  28002. inlineBehaviours: derive$1([config("dismissContextMenu", [run$1(dismissRequested(), function(comp, _se) {
  28003. Sandboxing.close(comp);
  28004. editor.focus();
  28005. })])])
  28006. }));
  28007. var hideContextMenu = function(_e) {
  28008. return InlineView.hide(contextmenu);
  28009. };
  28010. var showContextMenu = function(e) {
  28011. if (shouldNeverUseNative(editor)) {
  28012. e.preventDefault();
  28013. }
  28014. if (isNativeOverrideKeyEvent(editor, e) || isContextMenuDisabled(editor)) {
  28015. return;
  28016. }
  28017. var anchorType = getAnchorType(editor, e);
  28018. var buildMenu = function() {
  28019. var selectedElement = getSelectedElement(editor, e);
  28020. var registry = editor.ui.registry.getAll();
  28021. var menuConfig = getContextMenu(editor);
  28022. return generateContextMenu(registry.contextMenus, menuConfig, selectedElement);
  28023. };
  28024. var initAndShow$2 = isTouch2() ? initAndShow : initAndShow$1;
  28025. initAndShow$2(editor, e, buildMenu, backstage, contextmenu, anchorType);
  28026. };
  28027. editor.on("init", function() {
  28028. var hideEvents = "ResizeEditor ScrollContent ScrollWindow longpresscancel" + (isTouch2() ? "" : " ResizeWindow");
  28029. editor.on(hideEvents, hideContextMenu);
  28030. editor.on("longpress contextmenu", showContextMenu);
  28031. });
  28032. };
  28033. var adt = Adt.generate([
  28034. {
  28035. offset: [
  28036. "x",
  28037. "y"
  28038. ]
  28039. },
  28040. {
  28041. absolute: [
  28042. "x",
  28043. "y"
  28044. ]
  28045. },
  28046. {
  28047. fixed: [
  28048. "x",
  28049. "y"
  28050. ]
  28051. }
  28052. ]);
  28053. var subtract = function(change2) {
  28054. return function(point2) {
  28055. return point2.translate(-change2.left, -change2.top);
  28056. };
  28057. };
  28058. var add = function(change2) {
  28059. return function(point2) {
  28060. return point2.translate(change2.left, change2.top);
  28061. };
  28062. };
  28063. var transform = function(changes) {
  28064. return function(x, y) {
  28065. return foldl(changes, function(rest, f) {
  28066. return f(rest);
  28067. }, SugarPosition(x, y));
  28068. };
  28069. };
  28070. var asFixed = function(coord, scroll, origin) {
  28071. return coord.fold(transform([
  28072. add(origin),
  28073. subtract(scroll)
  28074. ]), transform([subtract(scroll)]), transform([]));
  28075. };
  28076. var asAbsolute = function(coord, scroll, origin) {
  28077. return coord.fold(transform([add(origin)]), transform([]), transform([add(scroll)]));
  28078. };
  28079. var asOffset = function(coord, scroll, origin) {
  28080. return coord.fold(transform([]), transform([subtract(origin)]), transform([
  28081. add(scroll),
  28082. subtract(origin)
  28083. ]));
  28084. };
  28085. var withinRange = function(coord1, coord2, xRange2, yRange2, scroll, origin) {
  28086. var a1 = asAbsolute(coord1, scroll, origin);
  28087. var a2 = asAbsolute(coord2, scroll, origin);
  28088. return Math.abs(a1.left - a2.left) <= xRange2 && Math.abs(a1.top - a2.top) <= yRange2;
  28089. };
  28090. var getDeltas = function(coord1, coord2, xRange2, yRange2, scroll, origin) {
  28091. var a1 = asAbsolute(coord1, scroll, origin);
  28092. var a2 = asAbsolute(coord2, scroll, origin);
  28093. var left2 = Math.abs(a1.left - a2.left);
  28094. var top2 = Math.abs(a1.top - a2.top);
  28095. return SugarPosition(left2, top2);
  28096. };
  28097. var toStyles = function(coord, scroll, origin) {
  28098. var stylesOpt = coord.fold(function(x, y) {
  28099. return {
  28100. position: Optional.some("absolute"),
  28101. left: Optional.some(x + "px"),
  28102. top: Optional.some(y + "px")
  28103. };
  28104. }, function(x, y) {
  28105. return {
  28106. position: Optional.some("absolute"),
  28107. left: Optional.some(x - origin.left + "px"),
  28108. top: Optional.some(y - origin.top + "px")
  28109. };
  28110. }, function(x, y) {
  28111. return {
  28112. position: Optional.some("fixed"),
  28113. left: Optional.some(x + "px"),
  28114. top: Optional.some(y + "px")
  28115. };
  28116. });
  28117. return __assign({
  28118. right: Optional.none(),
  28119. bottom: Optional.none()
  28120. }, stylesOpt);
  28121. };
  28122. var translate = function(coord, deltaX, deltaY) {
  28123. return coord.fold(function(x, y) {
  28124. return offset(x + deltaX, y + deltaY);
  28125. }, function(x, y) {
  28126. return absolute(x + deltaX, y + deltaY);
  28127. }, function(x, y) {
  28128. return fixed(x + deltaX, y + deltaY);
  28129. });
  28130. };
  28131. var absorb = function(partialCoord, originalCoord, scroll, origin) {
  28132. var absorbOne = function(stencil, nu2) {
  28133. return function(optX, optY) {
  28134. var original2 = stencil(originalCoord, scroll, origin);
  28135. return nu2(optX.getOr(original2.left), optY.getOr(original2.top));
  28136. };
  28137. };
  28138. return partialCoord.fold(absorbOne(asOffset, offset), absorbOne(asAbsolute, absolute), absorbOne(asFixed, fixed));
  28139. };
  28140. var offset = adt.offset;
  28141. var absolute = adt.absolute;
  28142. var fixed = adt.fixed;
  28143. var parseAttrToInt = function(element2, name2) {
  28144. var value2 = get$d(element2, name2);
  28145. return isUndefined(value2) ? NaN : parseInt(value2, 10);
  28146. };
  28147. var get = function(component, snapsInfo) {
  28148. var element2 = component.element;
  28149. var x = parseAttrToInt(element2, snapsInfo.leftAttr);
  28150. var y = parseAttrToInt(element2, snapsInfo.topAttr);
  28151. return isNaN(x) || isNaN(y) ? Optional.none() : Optional.some(SugarPosition(x, y));
  28152. };
  28153. var set = function(component, snapsInfo, pt) {
  28154. var element2 = component.element;
  28155. set$8(element2, snapsInfo.leftAttr, pt.left + "px");
  28156. set$8(element2, snapsInfo.topAttr, pt.top + "px");
  28157. };
  28158. var clear = function(component, snapsInfo) {
  28159. var element2 = component.element;
  28160. remove$7(element2, snapsInfo.leftAttr);
  28161. remove$7(element2, snapsInfo.topAttr);
  28162. };
  28163. var getCoords = function(component, snapInfo, coord, delta) {
  28164. return get(component, snapInfo).fold(function() {
  28165. return coord;
  28166. }, function(fixed$12) {
  28167. return fixed(fixed$12.left + delta.left, fixed$12.top + delta.top);
  28168. });
  28169. };
  28170. var moveOrSnap = function(component, snapInfo, coord, delta, scroll, origin) {
  28171. var newCoord = getCoords(component, snapInfo, coord, delta);
  28172. var snap2 = snapInfo.mustSnap ? findClosestSnap(component, snapInfo, newCoord, scroll, origin) : findSnap(component, snapInfo, newCoord, scroll, origin);
  28173. var fixedCoord = asFixed(newCoord, scroll, origin);
  28174. set(component, snapInfo, fixedCoord);
  28175. return snap2.fold(function() {
  28176. return {
  28177. coord: fixed(fixedCoord.left, fixedCoord.top),
  28178. extra: Optional.none()
  28179. };
  28180. }, function(spanned) {
  28181. return {
  28182. coord: spanned.output,
  28183. extra: spanned.extra
  28184. };
  28185. });
  28186. };
  28187. var stopDrag = function(component, snapInfo) {
  28188. clear(component, snapInfo);
  28189. };
  28190. var findMatchingSnap = function(snaps, newCoord, scroll, origin) {
  28191. return findMap(snaps, function(snap2) {
  28192. var sensor = snap2.sensor;
  28193. var inRange = withinRange(newCoord, sensor, snap2.range.left, snap2.range.top, scroll, origin);
  28194. return inRange ? Optional.some({
  28195. output: absorb(snap2.output, newCoord, scroll, origin),
  28196. extra: snap2.extra
  28197. }) : Optional.none();
  28198. });
  28199. };
  28200. var findClosestSnap = function(component, snapInfo, newCoord, scroll, origin) {
  28201. var snaps = snapInfo.getSnapPoints(component);
  28202. var matchSnap = findMatchingSnap(snaps, newCoord, scroll, origin);
  28203. return matchSnap.orThunk(function() {
  28204. var bestSnap = foldl(snaps, function(acc, snap2) {
  28205. var sensor = snap2.sensor;
  28206. var deltas = getDeltas(newCoord, sensor, snap2.range.left, snap2.range.top, scroll, origin);
  28207. return acc.deltas.fold(function() {
  28208. return {
  28209. deltas: Optional.some(deltas),
  28210. snap: Optional.some(snap2)
  28211. };
  28212. }, function(bestDeltas) {
  28213. var currAvg = (deltas.left + deltas.top) / 2;
  28214. var bestAvg = (bestDeltas.left + bestDeltas.top) / 2;
  28215. if (currAvg <= bestAvg) {
  28216. return {
  28217. deltas: Optional.some(deltas),
  28218. snap: Optional.some(snap2)
  28219. };
  28220. } else {
  28221. return acc;
  28222. }
  28223. });
  28224. }, {
  28225. deltas: Optional.none(),
  28226. snap: Optional.none()
  28227. });
  28228. return bestSnap.snap.map(function(snap2) {
  28229. return {
  28230. output: absorb(snap2.output, newCoord, scroll, origin),
  28231. extra: snap2.extra
  28232. };
  28233. });
  28234. });
  28235. };
  28236. var findSnap = function(component, snapInfo, newCoord, scroll, origin) {
  28237. var snaps = snapInfo.getSnapPoints(component);
  28238. return findMatchingSnap(snaps, newCoord, scroll, origin);
  28239. };
  28240. var snapTo$1 = function(snap2, scroll, origin) {
  28241. return {
  28242. coord: absorb(snap2.output, snap2.output, scroll, origin),
  28243. extra: snap2.extra
  28244. };
  28245. };
  28246. var snapTo = function(component, dragConfig, _state, snap2) {
  28247. var target = dragConfig.getTarget(component.element);
  28248. if (dragConfig.repositionTarget) {
  28249. var doc = owner$4(component.element);
  28250. var scroll_1 = get$9(doc);
  28251. var origin_1 = getOrigin(target);
  28252. var snapPin = snapTo$1(snap2, scroll_1, origin_1);
  28253. var styles = toStyles(snapPin.coord, scroll_1, origin_1);
  28254. setOptions(target, styles);
  28255. }
  28256. };
  28257. var DraggingApis = Object.freeze({
  28258. __proto__: null,
  28259. snapTo
  28260. });
  28261. var initialAttribute = "data-initial-z-index";
  28262. var resetZIndex = function(blocker) {
  28263. parent(blocker.element).filter(isElement$2).each(function(root) {
  28264. getOpt(root, initialAttribute).fold(function() {
  28265. return remove$6(root, "z-index");
  28266. }, function(zIndex) {
  28267. return set$7(root, "z-index", zIndex);
  28268. });
  28269. remove$7(root, initialAttribute);
  28270. });
  28271. };
  28272. var changeZIndex = function(blocker) {
  28273. parent(blocker.element).filter(isElement$2).each(function(root) {
  28274. getRaw(root, "z-index").each(function(zindex) {
  28275. set$8(root, initialAttribute, zindex);
  28276. });
  28277. set$7(root, "z-index", get$c(blocker.element, "z-index"));
  28278. });
  28279. };
  28280. var instigate = function(anyComponent, blocker) {
  28281. anyComponent.getSystem().addToGui(blocker);
  28282. changeZIndex(blocker);
  28283. };
  28284. var discard = function(blocker) {
  28285. resetZIndex(blocker);
  28286. blocker.getSystem().removeFromGui(blocker);
  28287. };
  28288. var createComponent = function(component, blockerClass, blockerEvents) {
  28289. return component.getSystem().build(Container.sketch({
  28290. dom: {
  28291. styles: {
  28292. "left": "0px",
  28293. "top": "0px",
  28294. "width": "100%",
  28295. "height": "100%",
  28296. "position": "fixed",
  28297. "z-index": "1000000000000000"
  28298. },
  28299. classes: [blockerClass]
  28300. },
  28301. events: blockerEvents
  28302. }));
  28303. };
  28304. var SnapSchema = optionObjOf("snaps", [
  28305. required$1("getSnapPoints"),
  28306. onHandler("onSensor"),
  28307. required$1("leftAttr"),
  28308. required$1("topAttr"),
  28309. defaulted("lazyViewport", win),
  28310. defaulted("mustSnap", false)
  28311. ]);
  28312. var schema$6 = [
  28313. defaulted("useFixed", never),
  28314. required$1("blockerClass"),
  28315. defaulted("getTarget", identity$1),
  28316. defaulted("onDrag", noop),
  28317. defaulted("repositionTarget", true),
  28318. defaulted("onDrop", noop),
  28319. defaultedFunction("getBounds", win),
  28320. SnapSchema
  28321. ];
  28322. var getCurrentCoord = function(target) {
  28323. return lift3(getRaw(target, "left"), getRaw(target, "top"), getRaw(target, "position"), function(left2, top2, position2) {
  28324. var nu2 = position2 === "fixed" ? fixed : offset;
  28325. return nu2(parseInt(left2, 10), parseInt(top2, 10));
  28326. }).getOrThunk(function() {
  28327. var location = absolute$3(target);
  28328. return absolute(location.left, location.top);
  28329. });
  28330. };
  28331. var clampCoords = function(component, coords, scroll, origin, startData) {
  28332. var bounds2 = startData.bounds;
  28333. var absoluteCoord = asAbsolute(coords, scroll, origin);
  28334. var newX = clamp$1(absoluteCoord.left, bounds2.x, bounds2.x + bounds2.width - startData.width);
  28335. var newY = clamp$1(absoluteCoord.top, bounds2.y, bounds2.y + bounds2.height - startData.height);
  28336. var newCoords = absolute(newX, newY);
  28337. return coords.fold(function() {
  28338. var offset$1 = asOffset(newCoords, scroll, origin);
  28339. return offset(offset$1.left, offset$1.top);
  28340. }, constant$1(newCoords), function() {
  28341. var fixed$12 = asFixed(newCoords, scroll, origin);
  28342. return fixed(fixed$12.left, fixed$12.top);
  28343. });
  28344. };
  28345. var calcNewCoord = function(component, optSnaps, currentCoord, scroll, origin, delta, startData) {
  28346. var newCoord = optSnaps.fold(function() {
  28347. var translated = translate(currentCoord, delta.left, delta.top);
  28348. var fixedCoord = asFixed(translated, scroll, origin);
  28349. return fixed(fixedCoord.left, fixedCoord.top);
  28350. }, function(snapInfo) {
  28351. var snapping = moveOrSnap(component, snapInfo, currentCoord, delta, scroll, origin);
  28352. snapping.extra.each(function(extra) {
  28353. snapInfo.onSensor(component, extra);
  28354. });
  28355. return snapping.coord;
  28356. });
  28357. return clampCoords(component, newCoord, scroll, origin, startData);
  28358. };
  28359. var dragBy = function(component, dragConfig, startData, delta) {
  28360. var target = dragConfig.getTarget(component.element);
  28361. if (dragConfig.repositionTarget) {
  28362. var doc = owner$4(component.element);
  28363. var scroll_1 = get$9(doc);
  28364. var origin_1 = getOrigin(target);
  28365. var currentCoord = getCurrentCoord(target);
  28366. var newCoord = calcNewCoord(component, dragConfig.snaps, currentCoord, scroll_1, origin_1, delta, startData);
  28367. var styles = toStyles(newCoord, scroll_1, origin_1);
  28368. setOptions(target, styles);
  28369. }
  28370. dragConfig.onDrag(component, target, delta);
  28371. };
  28372. var calcStartData = function(dragConfig, comp) {
  28373. return {
  28374. bounds: dragConfig.getBounds(),
  28375. height: getOuter$2(comp.element),
  28376. width: getOuter$1(comp.element)
  28377. };
  28378. };
  28379. var move = function(component, dragConfig, dragState, dragMode, event) {
  28380. var delta = dragState.update(dragMode, event);
  28381. var dragStartData = dragState.getStartData().getOrThunk(function() {
  28382. return calcStartData(dragConfig, component);
  28383. });
  28384. delta.each(function(dlt) {
  28385. dragBy(component, dragConfig, dragStartData, dlt);
  28386. });
  28387. };
  28388. var stop = function(component, blocker, dragConfig, dragState) {
  28389. blocker.each(discard);
  28390. dragConfig.snaps.each(function(snapInfo) {
  28391. stopDrag(component, snapInfo);
  28392. });
  28393. var target = dragConfig.getTarget(component.element);
  28394. dragState.reset();
  28395. dragConfig.onDrop(component, target);
  28396. };
  28397. var handlers = function(events2) {
  28398. return function(dragConfig, dragState) {
  28399. var updateStartState = function(comp) {
  28400. dragState.setStartData(calcStartData(dragConfig, comp));
  28401. };
  28402. return derive$2(__spreadArray([run$1(windowScroll(), function(comp) {
  28403. dragState.getStartData().each(function() {
  28404. return updateStartState(comp);
  28405. });
  28406. })], events2(dragConfig, dragState, updateStartState), true));
  28407. };
  28408. };
  28409. var init$2 = function(dragApi) {
  28410. return derive$2([
  28411. run$1(mousedown(), dragApi.forceDrop),
  28412. run$1(mouseup(), dragApi.drop),
  28413. run$1(mousemove(), function(comp, simulatedEvent) {
  28414. dragApi.move(simulatedEvent.event);
  28415. }),
  28416. run$1(mouseout(), dragApi.delayDrop)
  28417. ]);
  28418. };
  28419. var getData$1 = function(event) {
  28420. return Optional.from(SugarPosition(event.x, event.y));
  28421. };
  28422. var getDelta$1 = function(old, nu2) {
  28423. return SugarPosition(nu2.left - old.left, nu2.top - old.top);
  28424. };
  28425. var MouseData = Object.freeze({
  28426. __proto__: null,
  28427. getData: getData$1,
  28428. getDelta: getDelta$1
  28429. });
  28430. var events$2 = function(dragConfig, dragState, updateStartState) {
  28431. return [run$1(mousedown(), function(component, simulatedEvent) {
  28432. var raw = simulatedEvent.event.raw;
  28433. if (raw.button !== 0) {
  28434. return;
  28435. }
  28436. simulatedEvent.stop();
  28437. var stop$1 = function() {
  28438. return stop(component, Optional.some(blocker), dragConfig, dragState);
  28439. };
  28440. var delayDrop = DelayedFunction(stop$1, 200);
  28441. var dragApi = {
  28442. drop: stop$1,
  28443. delayDrop: delayDrop.schedule,
  28444. forceDrop: stop$1,
  28445. move: function(event) {
  28446. delayDrop.cancel();
  28447. move(component, dragConfig, dragState, MouseData, event);
  28448. }
  28449. };
  28450. var blocker = createComponent(component, dragConfig.blockerClass, init$2(dragApi));
  28451. var start = function() {
  28452. updateStartState(component);
  28453. instigate(component, blocker);
  28454. };
  28455. start();
  28456. })];
  28457. };
  28458. var schema$5 = __spreadArray(__spreadArray([], schema$6, true), [output$1("dragger", { handlers: handlers(events$2) })], false);
  28459. var init$1 = function(dragApi) {
  28460. return derive$2([
  28461. run$1(touchstart(), dragApi.forceDrop),
  28462. run$1(touchend(), dragApi.drop),
  28463. run$1(touchcancel(), dragApi.drop),
  28464. run$1(touchmove(), function(comp, simulatedEvent) {
  28465. dragApi.move(simulatedEvent.event);
  28466. })
  28467. ]);
  28468. };
  28469. var getDataFrom = function(touches) {
  28470. var touch2 = touches[0];
  28471. return Optional.some(SugarPosition(touch2.clientX, touch2.clientY));
  28472. };
  28473. var getData = function(event) {
  28474. var raw = event.raw;
  28475. var touches = raw.touches;
  28476. return touches.length === 1 ? getDataFrom(touches) : Optional.none();
  28477. };
  28478. var getDelta = function(old, nu2) {
  28479. return SugarPosition(nu2.left - old.left, nu2.top - old.top);
  28480. };
  28481. var TouchData = Object.freeze({
  28482. __proto__: null,
  28483. getData,
  28484. getDelta
  28485. });
  28486. var events$1 = function(dragConfig, dragState, updateStartState) {
  28487. var blockerSingleton = value$1();
  28488. var stopBlocking = function(component) {
  28489. stop(component, blockerSingleton.get(), dragConfig, dragState);
  28490. blockerSingleton.clear();
  28491. };
  28492. return [
  28493. run$1(touchstart(), function(component, simulatedEvent) {
  28494. simulatedEvent.stop();
  28495. var stop2 = function() {
  28496. return stopBlocking(component);
  28497. };
  28498. var dragApi = {
  28499. drop: stop2,
  28500. delayDrop: noop,
  28501. forceDrop: stop2,
  28502. move: function(event) {
  28503. move(component, dragConfig, dragState, TouchData, event);
  28504. }
  28505. };
  28506. var blocker = createComponent(component, dragConfig.blockerClass, init$1(dragApi));
  28507. blockerSingleton.set(blocker);
  28508. var start = function() {
  28509. updateStartState(component);
  28510. instigate(component, blocker);
  28511. };
  28512. start();
  28513. }),
  28514. run$1(touchmove(), function(component, simulatedEvent) {
  28515. simulatedEvent.stop();
  28516. move(component, dragConfig, dragState, TouchData, simulatedEvent.event);
  28517. }),
  28518. run$1(touchend(), function(component, simulatedEvent) {
  28519. simulatedEvent.stop();
  28520. stopBlocking(component);
  28521. }),
  28522. run$1(touchcancel(), stopBlocking)
  28523. ];
  28524. };
  28525. var schema$4 = __spreadArray(__spreadArray([], schema$6, true), [output$1("dragger", { handlers: handlers(events$1) })], false);
  28526. var events = function(dragConfig, dragState, updateStartState) {
  28527. return __spreadArray(__spreadArray([], events$2(dragConfig, dragState, updateStartState), true), events$1(dragConfig, dragState, updateStartState), true);
  28528. };
  28529. var schema$3 = __spreadArray(__spreadArray([], schema$6, true), [output$1("dragger", { handlers: handlers(events) })], false);
  28530. var mouse = schema$5;
  28531. var touch = schema$4;
  28532. var mouseOrTouch = schema$3;
  28533. var DraggingBranches = Object.freeze({
  28534. __proto__: null,
  28535. mouse,
  28536. touch,
  28537. mouseOrTouch
  28538. });
  28539. var init = function() {
  28540. var previous = Optional.none();
  28541. var startData = Optional.none();
  28542. var reset2 = function() {
  28543. previous = Optional.none();
  28544. startData = Optional.none();
  28545. };
  28546. var calculateDelta = function(mode, nu2) {
  28547. var result = previous.map(function(old) {
  28548. return mode.getDelta(old, nu2);
  28549. });
  28550. previous = Optional.some(nu2);
  28551. return result;
  28552. };
  28553. var update = function(mode, dragEvent) {
  28554. return mode.getData(dragEvent).bind(function(nuData) {
  28555. return calculateDelta(mode, nuData);
  28556. });
  28557. };
  28558. var setStartData = function(data) {
  28559. startData = Optional.some(data);
  28560. };
  28561. var getStartData = function() {
  28562. return startData;
  28563. };
  28564. var readState = constant$1({});
  28565. return nu$8({
  28566. readState,
  28567. reset: reset2,
  28568. update,
  28569. getStartData,
  28570. setStartData
  28571. });
  28572. };
  28573. var DragState = Object.freeze({
  28574. __proto__: null,
  28575. init
  28576. });
  28577. var Dragging = createModes({
  28578. branchKey: "mode",
  28579. branches: DraggingBranches,
  28580. name: "dragging",
  28581. active: {
  28582. events: function(dragConfig, dragState) {
  28583. var dragger = dragConfig.dragger;
  28584. return dragger.handlers(dragConfig, dragState);
  28585. }
  28586. },
  28587. extra: {
  28588. snap: function(sConfig) {
  28589. return {
  28590. sensor: sConfig.sensor,
  28591. range: sConfig.range,
  28592. output: sConfig.output,
  28593. extra: Optional.from(sConfig.extra)
  28594. };
  28595. }
  28596. },
  28597. state: DragState,
  28598. apis: DraggingApis
  28599. });
  28600. var snapWidth = 40;
  28601. var snapOffset = snapWidth / 2;
  28602. var calcSnap = function(selectorOpt, td, x, y, width2, height2) {
  28603. return selectorOpt.fold(function() {
  28604. return Dragging.snap({
  28605. sensor: absolute(x - snapOffset, y - snapOffset),
  28606. range: SugarPosition(width2, height2),
  28607. output: absolute(Optional.some(x), Optional.some(y)),
  28608. extra: { td }
  28609. });
  28610. }, function(selectorHandle) {
  28611. var sensorLeft = x - snapOffset;
  28612. var sensorTop = y - snapOffset;
  28613. var sensorWidth = snapWidth;
  28614. var sensorHeight = snapWidth;
  28615. var rect2 = selectorHandle.element.dom.getBoundingClientRect();
  28616. return Dragging.snap({
  28617. sensor: absolute(sensorLeft, sensorTop),
  28618. range: SugarPosition(sensorWidth, sensorHeight),
  28619. output: absolute(Optional.some(x - rect2.width / 2), Optional.some(y - rect2.height / 2)),
  28620. extra: { td }
  28621. });
  28622. });
  28623. };
  28624. var getSnapsConfig = function(getSnapPoints, cell, onChange) {
  28625. var isSameCell = function(cellOpt, td) {
  28626. return cellOpt.exists(function(currentTd) {
  28627. return eq(currentTd, td);
  28628. });
  28629. };
  28630. return {
  28631. getSnapPoints,
  28632. leftAttr: "data-drag-left",
  28633. topAttr: "data-drag-top",
  28634. onSensor: function(component, extra) {
  28635. var td = extra.td;
  28636. if (!isSameCell(cell.get(), td)) {
  28637. cell.set(td);
  28638. onChange(td);
  28639. }
  28640. },
  28641. mustSnap: true
  28642. };
  28643. };
  28644. var createSelector = function(snaps) {
  28645. return record(Button.sketch({
  28646. dom: {
  28647. tag: "div",
  28648. classes: ["tox-selector"]
  28649. },
  28650. buttonBehaviours: derive$1([
  28651. Dragging.config({
  28652. mode: "mouseOrTouch",
  28653. blockerClass: "blocker",
  28654. snaps
  28655. }),
  28656. Unselecting.config({})
  28657. ]),
  28658. eventOrder: {
  28659. mousedown: [
  28660. "dragging",
  28661. "alloy.base.behaviour"
  28662. ],
  28663. touchstart: [
  28664. "dragging",
  28665. "alloy.base.behaviour"
  28666. ]
  28667. }
  28668. }));
  28669. };
  28670. var setup$4 = function(editor, sink) {
  28671. var tlTds = Cell([]);
  28672. var brTds = Cell([]);
  28673. var isVisible2 = Cell(false);
  28674. var startCell = value$1();
  28675. var finishCell = value$1();
  28676. var getTopLeftSnap = function(td) {
  28677. var box2 = absolute$2(td);
  28678. return calcSnap(memTopLeft.getOpt(sink), td, box2.x, box2.y, box2.width, box2.height);
  28679. };
  28680. var getTopLeftSnaps = function() {
  28681. return map$2(tlTds.get(), function(td) {
  28682. return getTopLeftSnap(td);
  28683. });
  28684. };
  28685. var getBottomRightSnap = function(td) {
  28686. var box2 = absolute$2(td);
  28687. return calcSnap(memBottomRight.getOpt(sink), td, box2.right, box2.bottom, box2.width, box2.height);
  28688. };
  28689. var getBottomRightSnaps = function() {
  28690. return map$2(brTds.get(), function(td) {
  28691. return getBottomRightSnap(td);
  28692. });
  28693. };
  28694. var topLeftSnaps = getSnapsConfig(getTopLeftSnaps, startCell, function(start) {
  28695. finishCell.get().each(function(finish) {
  28696. editor.fire("TableSelectorChange", {
  28697. start,
  28698. finish
  28699. });
  28700. });
  28701. });
  28702. var bottomRightSnaps = getSnapsConfig(getBottomRightSnaps, finishCell, function(finish) {
  28703. startCell.get().each(function(start) {
  28704. editor.fire("TableSelectorChange", {
  28705. start,
  28706. finish
  28707. });
  28708. });
  28709. });
  28710. var memTopLeft = createSelector(topLeftSnaps);
  28711. var memBottomRight = createSelector(bottomRightSnaps);
  28712. var topLeft = build$1(memTopLeft.asSpec());
  28713. var bottomRight = build$1(memBottomRight.asSpec());
  28714. var showOrHideHandle = function(selector, cell, isAbove, isBelow) {
  28715. var cellRect = cell.dom.getBoundingClientRect();
  28716. remove$6(selector.element, "display");
  28717. var viewportHeight = defaultView(SugarElement.fromDom(editor.getBody())).dom.innerHeight;
  28718. var aboveViewport = isAbove(cellRect);
  28719. var belowViewport = isBelow(cellRect, viewportHeight);
  28720. if (aboveViewport || belowViewport) {
  28721. set$7(selector.element, "display", "none");
  28722. }
  28723. };
  28724. var snapTo2 = function(selector, cell, getSnapConfig, pos) {
  28725. var snap2 = getSnapConfig(cell);
  28726. Dragging.snapTo(selector, snap2);
  28727. var isAbove = function(rect2) {
  28728. return rect2[pos] < 0;
  28729. };
  28730. var isBelow = function(rect2, viewportHeight) {
  28731. return rect2[pos] > viewportHeight;
  28732. };
  28733. showOrHideHandle(selector, cell, isAbove, isBelow);
  28734. };
  28735. var snapTopLeft = function(cell) {
  28736. return snapTo2(topLeft, cell, getTopLeftSnap, "top");
  28737. };
  28738. var snapLastTopLeft = function() {
  28739. return startCell.get().each(snapTopLeft);
  28740. };
  28741. var snapBottomRight = function(cell) {
  28742. return snapTo2(bottomRight, cell, getBottomRightSnap, "bottom");
  28743. };
  28744. var snapLastBottomRight = function() {
  28745. return finishCell.get().each(snapBottomRight);
  28746. };
  28747. if (detect$1().deviceType.isTouch()) {
  28748. editor.on("TableSelectionChange", function(e) {
  28749. if (!isVisible2.get()) {
  28750. attach(sink, topLeft);
  28751. attach(sink, bottomRight);
  28752. isVisible2.set(true);
  28753. }
  28754. startCell.set(e.start);
  28755. finishCell.set(e.finish);
  28756. e.otherCells.each(function(otherCells) {
  28757. tlTds.set(otherCells.upOrLeftCells);
  28758. brTds.set(otherCells.downOrRightCells);
  28759. snapTopLeft(e.start);
  28760. snapBottomRight(e.finish);
  28761. });
  28762. });
  28763. editor.on("ResizeEditor ResizeWindow ScrollContent", function() {
  28764. snapLastTopLeft();
  28765. snapLastBottomRight();
  28766. });
  28767. editor.on("TableSelectionClear", function() {
  28768. if (isVisible2.get()) {
  28769. detach(topLeft);
  28770. detach(bottomRight);
  28771. isVisible2.set(false);
  28772. }
  28773. startCell.clear();
  28774. finishCell.clear();
  28775. });
  28776. }
  28777. };
  28778. var isHidden = function(elm) {
  28779. if (elm.nodeType === 1) {
  28780. if (elm.nodeName === "BR" || !!elm.getAttribute("data-mce-bogus")) {
  28781. return true;
  28782. }
  28783. if (elm.getAttribute("data-mce-type") === "bookmark") {
  28784. return true;
  28785. }
  28786. }
  28787. return false;
  28788. };
  28789. var renderElementPath = function(editor, settings, providersBackstage) {
  28790. if (!settings.delimiter) {
  28791. settings.delimiter = "»";
  28792. }
  28793. var getDataPath = function(data) {
  28794. var parts2 = data || [];
  28795. var newPathElements = map$2(parts2, function(part2, index) {
  28796. return Button.sketch({
  28797. dom: {
  28798. tag: "div",
  28799. classes: ["tox-statusbar__path-item"],
  28800. attributes: {
  28801. "role": "button",
  28802. "data-index": index,
  28803. "tab-index": -1,
  28804. "aria-level": index + 1
  28805. },
  28806. innerHtml: part2.name
  28807. },
  28808. action: function(_btn) {
  28809. editor.focus();
  28810. editor.selection.select(part2.element);
  28811. editor.nodeChanged();
  28812. },
  28813. buttonBehaviours: derive$1([
  28814. DisablingConfigs.button(providersBackstage.isDisabled),
  28815. receivingConfig()
  28816. ])
  28817. });
  28818. });
  28819. var divider = {
  28820. dom: {
  28821. tag: "div",
  28822. classes: ["tox-statusbar__path-divider"],
  28823. attributes: { "aria-hidden": true },
  28824. innerHtml: " " + settings.delimiter + " "
  28825. }
  28826. };
  28827. return foldl(newPathElements.slice(1), function(acc, element2) {
  28828. var newAcc = acc;
  28829. newAcc.push(divider);
  28830. newAcc.push(element2);
  28831. return newAcc;
  28832. }, [newPathElements[0]]);
  28833. };
  28834. var updatePath = function(parents) {
  28835. var newPath = [];
  28836. var i = parents.length;
  28837. while (i-- > 0) {
  28838. var parent_1 = parents[i];
  28839. if (parent_1.nodeType === 1 && !isHidden(parent_1)) {
  28840. var args = editor.fire("ResolveName", {
  28841. name: parent_1.nodeName.toLowerCase(),
  28842. target: parent_1
  28843. });
  28844. if (!args.isDefaultPrevented()) {
  28845. newPath.push({
  28846. name: args.name,
  28847. element: parent_1
  28848. });
  28849. }
  28850. if (args.isPropagationStopped()) {
  28851. break;
  28852. }
  28853. }
  28854. }
  28855. return newPath;
  28856. };
  28857. return {
  28858. dom: {
  28859. tag: "div",
  28860. classes: ["tox-statusbar__path"],
  28861. attributes: { role: "navigation" }
  28862. },
  28863. behaviours: derive$1([
  28864. Keying.config({
  28865. mode: "flow",
  28866. selector: "div[role=button]"
  28867. }),
  28868. Disabling.config({ disabled: providersBackstage.isDisabled }),
  28869. receivingConfig(),
  28870. Tabstopping.config({}),
  28871. Replacing.config({}),
  28872. config("elementPathEvents", [runOnAttached(function(comp, _e) {
  28873. editor.shortcuts.add("alt+F11", "focus statusbar elementpath", function() {
  28874. return Keying.focusIn(comp);
  28875. });
  28876. editor.on("NodeChange", function(e) {
  28877. var newPath = updatePath(e.parents);
  28878. if (newPath.length > 0) {
  28879. Replacing.set(comp, getDataPath(newPath));
  28880. } else {
  28881. Replacing.set(comp, []);
  28882. }
  28883. });
  28884. })])
  28885. ]),
  28886. components: []
  28887. };
  28888. };
  28889. var ResizeTypes;
  28890. (function(ResizeTypes2) {
  28891. ResizeTypes2[ResizeTypes2["None"] = 0] = "None";
  28892. ResizeTypes2[ResizeTypes2["Both"] = 1] = "Both";
  28893. ResizeTypes2[ResizeTypes2["Vertical"] = 2] = "Vertical";
  28894. })(ResizeTypes || (ResizeTypes = {}));
  28895. var getDimensions = function(editor, deltas, resizeType, originalHeight, originalWidth) {
  28896. var dimensions = {};
  28897. dimensions.height = calcCappedSize(originalHeight + deltas.top, getMinHeightSetting(editor), getMaxHeightSetting(editor));
  28898. if (resizeType === ResizeTypes.Both) {
  28899. dimensions.width = calcCappedSize(originalWidth + deltas.left, getMinWidthSetting(editor), getMaxWidthSetting(editor));
  28900. }
  28901. return dimensions;
  28902. };
  28903. var resize = function(editor, deltas, resizeType) {
  28904. var container = SugarElement.fromDom(editor.getContainer());
  28905. var dimensions = getDimensions(editor, deltas, resizeType, get$b(container), get$a(container));
  28906. each(dimensions, function(val, dim) {
  28907. return set$7(container, dim, numToPx(val));
  28908. });
  28909. fireResizeEditor(editor);
  28910. };
  28911. var getResizeType = function(editor) {
  28912. var fallback2 = !editor.hasPlugin("autoresize");
  28913. var resize2 = editor.getParam("resize", fallback2);
  28914. if (resize2 === false) {
  28915. return ResizeTypes.None;
  28916. } else if (resize2 === "both") {
  28917. return ResizeTypes.Both;
  28918. } else {
  28919. return ResizeTypes.Vertical;
  28920. }
  28921. };
  28922. var keyboardHandler = function(editor, resizeType, x, y) {
  28923. var scale2 = 20;
  28924. var delta = SugarPosition(x * scale2, y * scale2);
  28925. resize(editor, delta, resizeType);
  28926. return Optional.some(true);
  28927. };
  28928. var renderResizeHandler = function(editor, providersBackstage) {
  28929. var resizeType = getResizeType(editor);
  28930. if (resizeType === ResizeTypes.None) {
  28931. return Optional.none();
  28932. }
  28933. return Optional.some(render$3("resize-handle", {
  28934. tag: "div",
  28935. classes: ["tox-statusbar__resize-handle"],
  28936. attributes: { title: providersBackstage.translate("Resize") },
  28937. behaviours: [
  28938. Dragging.config({
  28939. mode: "mouse",
  28940. repositionTarget: false,
  28941. onDrag: function(_comp, _target, delta) {
  28942. return resize(editor, delta, resizeType);
  28943. },
  28944. blockerClass: "tox-blocker"
  28945. }),
  28946. Keying.config({
  28947. mode: "special",
  28948. onLeft: function() {
  28949. return keyboardHandler(editor, resizeType, -1, 0);
  28950. },
  28951. onRight: function() {
  28952. return keyboardHandler(editor, resizeType, 1, 0);
  28953. },
  28954. onUp: function() {
  28955. return keyboardHandler(editor, resizeType, 0, -1);
  28956. },
  28957. onDown: function() {
  28958. return keyboardHandler(editor, resizeType, 0, 1);
  28959. }
  28960. }),
  28961. Tabstopping.config({}),
  28962. Focusing.config({})
  28963. ]
  28964. }, providersBackstage.icons));
  28965. };
  28966. var renderWordCount = function(editor, providersBackstage) {
  28967. var _a2;
  28968. var replaceCountText = function(comp, count2, mode) {
  28969. return Replacing.set(comp, [text$1(providersBackstage.translate([
  28970. "{0} " + mode,
  28971. count2[mode]
  28972. ]))]);
  28973. };
  28974. return Button.sketch({
  28975. dom: {
  28976. tag: "button",
  28977. classes: ["tox-statusbar__wordcount"]
  28978. },
  28979. components: [],
  28980. buttonBehaviours: derive$1([
  28981. DisablingConfigs.button(providersBackstage.isDisabled),
  28982. receivingConfig(),
  28983. Tabstopping.config({}),
  28984. Replacing.config({}),
  28985. Representing.config({
  28986. store: {
  28987. mode: "memory",
  28988. initialValue: {
  28989. mode: "words",
  28990. count: {
  28991. words: 0,
  28992. characters: 0
  28993. }
  28994. }
  28995. }
  28996. }),
  28997. config("wordcount-events", [
  28998. runOnExecute$1(function(comp) {
  28999. var currentVal = Representing.getValue(comp);
  29000. var newMode = currentVal.mode === "words" ? "characters" : "words";
  29001. Representing.setValue(comp, {
  29002. mode: newMode,
  29003. count: currentVal.count
  29004. });
  29005. replaceCountText(comp, currentVal.count, newMode);
  29006. }),
  29007. runOnAttached(function(comp) {
  29008. editor.on("wordCountUpdate", function(e) {
  29009. var mode = Representing.getValue(comp).mode;
  29010. Representing.setValue(comp, {
  29011. mode,
  29012. count: e.wordCount
  29013. });
  29014. replaceCountText(comp, e.wordCount, mode);
  29015. });
  29016. })
  29017. ])
  29018. ]),
  29019. eventOrder: (_a2 = {}, _a2[execute$5()] = [
  29020. "disabling",
  29021. "alloy.base.behaviour",
  29022. "wordcount-events"
  29023. ], _a2)
  29024. });
  29025. };
  29026. var renderStatusbar = function(editor, providersBackstage) {
  29027. var renderBranding = function() {
  29028. var label = global$e.translate([
  29029. "Powered by {0}",
  29030. "Tiny"
  29031. ]);
  29032. 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>";
  29033. return {
  29034. dom: {
  29035. tag: "span",
  29036. classes: ["tox-statusbar__branding"],
  29037. innerHtml: linkHtml
  29038. }
  29039. };
  29040. };
  29041. var getTextComponents = function() {
  29042. var components2 = [];
  29043. if (editor.getParam("elementpath", true, "boolean")) {
  29044. components2.push(renderElementPath(editor, {}, providersBackstage));
  29045. }
  29046. if (editor.hasPlugin("wordcount")) {
  29047. components2.push(renderWordCount(editor, providersBackstage));
  29048. }
  29049. if (editor.getParam("branding", true, "boolean")) {
  29050. components2.push(renderBranding());
  29051. }
  29052. if (components2.length > 0) {
  29053. return [{
  29054. dom: {
  29055. tag: "div",
  29056. classes: ["tox-statusbar__text-container"]
  29057. },
  29058. components: components2
  29059. }];
  29060. }
  29061. return [];
  29062. };
  29063. var getComponents = function() {
  29064. var components2 = getTextComponents();
  29065. var resizeHandler = renderResizeHandler(editor, providersBackstage);
  29066. return components2.concat(resizeHandler.toArray());
  29067. };
  29068. return {
  29069. dom: {
  29070. tag: "div",
  29071. classes: ["tox-statusbar"]
  29072. },
  29073. components: getComponents()
  29074. };
  29075. };
  29076. var setup$3 = function(editor) {
  29077. var _a2;
  29078. var isInline = editor.inline;
  29079. var mode = isInline ? Inline : Iframe;
  29080. var header = isStickyToolbar(editor) ? StickyHeader : StaticHeader;
  29081. var lazyOuterContainer = Optional.none();
  29082. var platform2 = detect$1();
  29083. var isIE = platform2.browser.isIE();
  29084. var platformClasses = isIE ? ["tox-platform-ie"] : [];
  29085. var isTouch2 = platform2.deviceType.isTouch();
  29086. var touchPlatformClass = "tox-platform-touch";
  29087. var deviceClasses = isTouch2 ? [touchPlatformClass] : [];
  29088. var isToolbarBottom = isToolbarLocationBottom(editor);
  29089. var uiContainer = getUiContainer(editor);
  29090. var dirAttributes = global$e.isRtl() ? { attributes: { dir: "rtl" } } : {};
  29091. var verticalDirAttributes = { attributes: (_a2 = {}, _a2[Attribute] = isToolbarBottom ? AttributeValue.BottomToTop : AttributeValue.TopToBottom, _a2) };
  29092. var lazyHeader = function() {
  29093. return lazyOuterContainer.bind(OuterContainer.getHeader);
  29094. };
  29095. var isHeaderDocked = function() {
  29096. return header.isDocked(lazyHeader);
  29097. };
  29098. var resizeUiMothership = function() {
  29099. set$7(uiMothership.element, "width", document.body.clientWidth + "px");
  29100. };
  29101. var makeSinkDefinition = function() {
  29102. var isGridUiContainer = eq(body(), uiContainer) && get$c(uiContainer, "display") === "grid";
  29103. var sinkSpec = {
  29104. dom: __assign({
  29105. tag: "div",
  29106. classes: [
  29107. "tox",
  29108. "tox-silver-sink",
  29109. "tox-tinymce-aux"
  29110. ].concat(platformClasses).concat(deviceClasses)
  29111. }, dirAttributes),
  29112. behaviours: derive$1([Positioning.config({
  29113. useFixed: function() {
  29114. return isHeaderDocked();
  29115. }
  29116. })])
  29117. };
  29118. var reactiveWidthSpec = {
  29119. dom: { styles: { width: document.body.clientWidth + "px" } },
  29120. events: derive$2([run$1(windowResize(), resizeUiMothership)])
  29121. };
  29122. return deepMerge(sinkSpec, isGridUiContainer ? reactiveWidthSpec : {});
  29123. };
  29124. var sink = build$1(makeSinkDefinition());
  29125. var lazySink = function() {
  29126. return Result.value(sink);
  29127. };
  29128. var memAnchorBar = record({
  29129. dom: {
  29130. tag: "div",
  29131. classes: ["tox-anchorbar"]
  29132. }
  29133. });
  29134. var lazyAnchorBar = function() {
  29135. return lazyOuterContainer.bind(function(container) {
  29136. return memAnchorBar.getOpt(container);
  29137. }).getOrDie("Could not find a anchor bar element");
  29138. };
  29139. var lazyToolbar = function() {
  29140. return lazyOuterContainer.bind(function(container) {
  29141. return OuterContainer.getToolbar(container);
  29142. }).getOrDie("Could not find more toolbar element");
  29143. };
  29144. var lazyThrobber = function() {
  29145. return lazyOuterContainer.bind(function(container) {
  29146. return OuterContainer.getThrobber(container);
  29147. }).getOrDie("Could not find throbber element");
  29148. };
  29149. var backstage = init$7(sink, editor, lazyAnchorBar);
  29150. var partMenubar2 = OuterContainer.parts.menubar({
  29151. dom: {
  29152. tag: "div",
  29153. classes: ["tox-menubar"]
  29154. },
  29155. backstage,
  29156. onEscape: function() {
  29157. editor.focus();
  29158. }
  29159. });
  29160. var toolbarMode = getToolbarMode(editor);
  29161. var partToolbar2 = OuterContainer.parts.toolbar(__assign({
  29162. dom: {
  29163. tag: "div",
  29164. classes: ["tox-toolbar"]
  29165. },
  29166. getSink: lazySink,
  29167. providers: backstage.shared.providers,
  29168. onEscape: function() {
  29169. editor.focus();
  29170. },
  29171. type: toolbarMode,
  29172. lazyToolbar,
  29173. lazyHeader: function() {
  29174. return lazyHeader().getOrDie("Could not find header element");
  29175. }
  29176. }, verticalDirAttributes));
  29177. var partMultipleToolbar2 = OuterContainer.parts["multiple-toolbar"]({
  29178. dom: {
  29179. tag: "div",
  29180. classes: ["tox-toolbar-overlord"]
  29181. },
  29182. providers: backstage.shared.providers,
  29183. onEscape: function() {
  29184. editor.focus();
  29185. },
  29186. type: toolbarMode
  29187. });
  29188. var partSocket2 = OuterContainer.parts.socket({
  29189. dom: {
  29190. tag: "div",
  29191. classes: ["tox-edit-area"]
  29192. }
  29193. });
  29194. var partSidebar2 = OuterContainer.parts.sidebar({
  29195. dom: {
  29196. tag: "div",
  29197. classes: ["tox-sidebar"]
  29198. }
  29199. });
  29200. var partThrobber2 = OuterContainer.parts.throbber({
  29201. dom: {
  29202. tag: "div",
  29203. classes: ["tox-throbber"]
  29204. },
  29205. backstage
  29206. });
  29207. var sb = editor.getParam("statusbar", true, "boolean");
  29208. var statusbar = sb && !isInline ? Optional.some(renderStatusbar(editor, backstage.shared.providers)) : Optional.none();
  29209. var socketSidebarContainer = {
  29210. dom: {
  29211. tag: "div",
  29212. classes: ["tox-sidebar-wrap"]
  29213. },
  29214. components: [
  29215. partSocket2,
  29216. partSidebar2
  29217. ]
  29218. };
  29219. var hasMultipleToolbar = isMultipleToolbars(editor);
  29220. var hasToolbar = isToolbarEnabled(editor);
  29221. var hasMenubar = isMenubarEnabled(editor);
  29222. var getPartToolbar = function() {
  29223. if (hasMultipleToolbar) {
  29224. return [partMultipleToolbar2];
  29225. } else if (hasToolbar) {
  29226. return [partToolbar2];
  29227. } else {
  29228. return [];
  29229. }
  29230. };
  29231. var partHeader2 = OuterContainer.parts.header({
  29232. dom: __assign({
  29233. tag: "div",
  29234. classes: ["tox-editor-header"]
  29235. }, verticalDirAttributes),
  29236. components: flatten([
  29237. hasMenubar ? [partMenubar2] : [],
  29238. getPartToolbar(),
  29239. useFixedContainer(editor) ? [] : [memAnchorBar.asSpec()]
  29240. ]),
  29241. sticky: isStickyToolbar(editor),
  29242. editor,
  29243. sharedBackstage: backstage.shared
  29244. });
  29245. var editorComponents = flatten([
  29246. isToolbarBottom ? [] : [partHeader2],
  29247. isInline ? [] : [socketSidebarContainer],
  29248. isToolbarBottom ? [partHeader2] : []
  29249. ]);
  29250. var editorContainer = {
  29251. dom: {
  29252. tag: "div",
  29253. classes: ["tox-editor-container"]
  29254. },
  29255. components: editorComponents
  29256. };
  29257. var containerComponents = flatten([
  29258. [editorContainer],
  29259. isInline ? [] : statusbar.toArray(),
  29260. [partThrobber2]
  29261. ]);
  29262. var isHidden2 = isDistractionFree(editor);
  29263. var attributes = __assign(__assign({ role: "application" }, global$e.isRtl() ? { dir: "rtl" } : {}), isHidden2 ? { "aria-hidden": "true" } : {});
  29264. var outerContainer = build$1(OuterContainer.sketch({
  29265. dom: {
  29266. tag: "div",
  29267. classes: [
  29268. "tox",
  29269. "tox-tinymce"
  29270. ].concat(isInline ? ["tox-tinymce-inline"] : []).concat(isToolbarBottom ? ["tox-tinymce--toolbar-bottom"] : []).concat(deviceClasses).concat(platformClasses),
  29271. styles: __assign({ visibility: "hidden" }, isHidden2 ? {
  29272. opacity: "0",
  29273. border: "0"
  29274. } : {}),
  29275. attributes
  29276. },
  29277. components: containerComponents,
  29278. behaviours: derive$1([
  29279. receivingConfig(),
  29280. Disabling.config({ disableClass: "tox-tinymce--disabled" }),
  29281. Keying.config({
  29282. mode: "cyclic",
  29283. 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"
  29284. })
  29285. ])
  29286. }));
  29287. lazyOuterContainer = Optional.some(outerContainer);
  29288. editor.shortcuts.add("alt+F9", "focus menubar", function() {
  29289. OuterContainer.focusMenubar(outerContainer);
  29290. });
  29291. editor.shortcuts.add("alt+F10", "focus toolbar", function() {
  29292. OuterContainer.focusToolbar(outerContainer);
  29293. });
  29294. editor.addCommand("ToggleToolbarDrawer", function() {
  29295. OuterContainer.toggleToolbarDrawer(outerContainer);
  29296. });
  29297. editor.addQueryStateHandler("ToggleToolbarDrawer", function() {
  29298. return OuterContainer.isToolbarDrawerToggled(outerContainer);
  29299. });
  29300. var mothership = takeover(outerContainer);
  29301. var uiMothership = takeover(sink);
  29302. setup$b(editor, mothership, uiMothership);
  29303. var getUi = function() {
  29304. var channels = {
  29305. broadcastAll: uiMothership.broadcast,
  29306. broadcastOn: uiMothership.broadcastOn,
  29307. register: noop
  29308. };
  29309. return { channels };
  29310. };
  29311. var setEditorSize = function() {
  29312. var parsedHeight = numToPx(getHeightWithFallback(editor));
  29313. var parsedWidth = numToPx(getWidthWithFallback(editor));
  29314. if (!editor.inline) {
  29315. if (isValidValue("div", "width", parsedWidth)) {
  29316. set$7(outerContainer.element, "width", parsedWidth);
  29317. }
  29318. if (isValidValue("div", "height", parsedHeight)) {
  29319. set$7(outerContainer.element, "height", parsedHeight);
  29320. } else {
  29321. set$7(outerContainer.element, "height", "200px");
  29322. }
  29323. }
  29324. return parsedHeight;
  29325. };
  29326. var renderUI = function() {
  29327. header.setup(editor, backstage.shared, lazyHeader);
  29328. setup$6(editor, backstage);
  29329. setup$5(editor, lazySink, backstage);
  29330. setup$8(editor);
  29331. setup$7(editor, lazyThrobber, backstage.shared);
  29332. map$1(getToolbarGroups(editor), function(toolbarGroupButtonConfig, name2) {
  29333. editor.ui.registry.addGroupToolbarButton(name2, toolbarGroupButtonConfig);
  29334. });
  29335. var _a3 = editor.ui.registry.getAll(), buttons = _a3.buttons, menuItems = _a3.menuItems, contextToolbars = _a3.contextToolbars, sidebars = _a3.sidebars;
  29336. var toolbarOpt = getMultipleToolbarsSetting(editor);
  29337. var rawUiConfig = {
  29338. menuItems,
  29339. menus: getMenus(editor),
  29340. menubar: getMenubar(editor),
  29341. toolbar: toolbarOpt.getOrThunk(function() {
  29342. return getToolbar(editor);
  29343. }),
  29344. allowToolbarGroups: toolbarMode === ToolbarMode.floating,
  29345. buttons,
  29346. sidebar: sidebars
  29347. };
  29348. register$7(editor, contextToolbars, sink, { backstage });
  29349. setup$4(editor, sink);
  29350. var elm = editor.getElement();
  29351. var height2 = setEditorSize();
  29352. var uiComponents = {
  29353. mothership,
  29354. uiMothership,
  29355. outerContainer
  29356. };
  29357. var args = {
  29358. targetNode: elm,
  29359. height: height2
  29360. };
  29361. return mode.render(editor, uiComponents, rawUiConfig, backstage, args);
  29362. };
  29363. return {
  29364. mothership,
  29365. uiMothership,
  29366. backstage,
  29367. renderUI,
  29368. getUi
  29369. };
  29370. };
  29371. var describedBy = function(describedElement, describeElement) {
  29372. var describeId = Optional.from(get$d(describedElement, "id")).fold(function() {
  29373. var id = generate$6("dialog-describe");
  29374. set$8(describeElement, "id", id);
  29375. return id;
  29376. }, identity$1);
  29377. set$8(describedElement, "aria-describedby", describeId);
  29378. };
  29379. var labelledBy = function(labelledElement, labelElement) {
  29380. var labelId = getOpt(labelledElement, "id").fold(function() {
  29381. var id = generate$6("dialog-label");
  29382. set$8(labelElement, "id", id);
  29383. return id;
  29384. }, identity$1);
  29385. set$8(labelledElement, "aria-labelledby", labelId);
  29386. };
  29387. var schema$2 = constant$1([
  29388. required$1("lazySink"),
  29389. option("dragBlockClass"),
  29390. defaultedFunction("getBounds", win),
  29391. defaulted("useTabstopAt", always),
  29392. defaulted("eventOrder", {}),
  29393. field("modalBehaviours", [Keying]),
  29394. onKeyboardHandler("onExecute"),
  29395. onStrictKeyboardHandler("onEscape")
  29396. ]);
  29397. var basic = { sketch: identity$1 };
  29398. var parts$2 = constant$1([
  29399. optional({
  29400. name: "draghandle",
  29401. overrides: function(detail, spec) {
  29402. return {
  29403. behaviours: derive$1([Dragging.config({
  29404. mode: "mouse",
  29405. getTarget: function(handle2) {
  29406. return ancestor(handle2, '[role="dialog"]').getOr(handle2);
  29407. },
  29408. 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),
  29409. getBounds: detail.getDragBounds
  29410. })])
  29411. };
  29412. }
  29413. }),
  29414. required({
  29415. schema: [required$1("dom")],
  29416. name: "title"
  29417. }),
  29418. required({
  29419. factory: basic,
  29420. schema: [required$1("dom")],
  29421. name: "close"
  29422. }),
  29423. required({
  29424. factory: basic,
  29425. schema: [required$1("dom")],
  29426. name: "body"
  29427. }),
  29428. optional({
  29429. factory: basic,
  29430. schema: [required$1("dom")],
  29431. name: "footer"
  29432. }),
  29433. external$1({
  29434. factory: {
  29435. sketch: function(spec, detail) {
  29436. return __assign(__assign({}, spec), {
  29437. dom: detail.dom,
  29438. components: detail.components
  29439. });
  29440. }
  29441. },
  29442. schema: [
  29443. defaulted("dom", {
  29444. tag: "div",
  29445. styles: {
  29446. position: "fixed",
  29447. left: "0px",
  29448. top: "0px",
  29449. right: "0px",
  29450. bottom: "0px"
  29451. }
  29452. }),
  29453. defaulted("components", [])
  29454. ],
  29455. name: "blocker"
  29456. })
  29457. ]);
  29458. var factory$4 = function(detail, components2, spec, externals) {
  29459. var _a2;
  29460. var dialogComp = value$1();
  29461. var showDialog = function(dialog) {
  29462. dialogComp.set(dialog);
  29463. var sink = detail.lazySink(dialog).getOrDie();
  29464. var externalBlocker = externals.blocker();
  29465. var blocker = sink.getSystem().build(__assign(__assign({}, externalBlocker), {
  29466. components: externalBlocker.components.concat([premade(dialog)]),
  29467. behaviours: derive$1([
  29468. Focusing.config({}),
  29469. config("dialog-blocker-events", [runOnSource(focusin(), function() {
  29470. Keying.focusIn(dialog);
  29471. })])
  29472. ])
  29473. }));
  29474. attach(sink, blocker);
  29475. Keying.focusIn(dialog);
  29476. };
  29477. var hideDialog = function(dialog) {
  29478. dialogComp.clear();
  29479. parent(dialog.element).each(function(blockerDom) {
  29480. dialog.getSystem().getByDom(blockerDom).each(function(blocker) {
  29481. detach(blocker);
  29482. });
  29483. });
  29484. };
  29485. var getDialogBody = function(dialog) {
  29486. return getPartOrDie(dialog, detail, "body");
  29487. };
  29488. var getDialogFooter = function(dialog) {
  29489. return getPartOrDie(dialog, detail, "footer");
  29490. };
  29491. var setBusy = function(dialog, getBusySpec2) {
  29492. Blocking.block(dialog, getBusySpec2);
  29493. };
  29494. var setIdle = function(dialog) {
  29495. Blocking.unblock(dialog);
  29496. };
  29497. var modalEventsId = generate$6("modal-events");
  29498. var eventOrder = __assign(__assign({}, detail.eventOrder), (_a2 = {}, _a2[attachedToDom()] = [modalEventsId].concat(detail.eventOrder["alloy.system.attached"] || []), _a2));
  29499. return {
  29500. uid: detail.uid,
  29501. dom: detail.dom,
  29502. components: components2,
  29503. apis: {
  29504. show: showDialog,
  29505. hide: hideDialog,
  29506. getBody: getDialogBody,
  29507. getFooter: getDialogFooter,
  29508. setIdle,
  29509. setBusy
  29510. },
  29511. eventOrder,
  29512. domModification: {
  29513. attributes: {
  29514. "role": "dialog",
  29515. "aria-modal": "true"
  29516. }
  29517. },
  29518. behaviours: augment(detail.modalBehaviours, [
  29519. Replacing.config({}),
  29520. Keying.config({
  29521. mode: "cyclic",
  29522. onEnter: detail.onExecute,
  29523. onEscape: detail.onEscape,
  29524. useTabstopAt: detail.useTabstopAt
  29525. }),
  29526. Blocking.config({ getRoot: dialogComp.get }),
  29527. config(modalEventsId, [runOnAttached(function(c) {
  29528. labelledBy(c.element, getPartOrDie(c, detail, "title").element);
  29529. describedBy(c.element, getPartOrDie(c, detail, "body").element);
  29530. })])
  29531. ])
  29532. };
  29533. };
  29534. var ModalDialog = composite({
  29535. name: "ModalDialog",
  29536. configFields: schema$2(),
  29537. partFields: parts$2(),
  29538. factory: factory$4,
  29539. apis: {
  29540. show: function(apis, dialog) {
  29541. apis.show(dialog);
  29542. },
  29543. hide: function(apis, dialog) {
  29544. apis.hide(dialog);
  29545. },
  29546. getBody: function(apis, dialog) {
  29547. return apis.getBody(dialog);
  29548. },
  29549. getFooter: function(apis, dialog) {
  29550. return apis.getFooter(dialog);
  29551. },
  29552. setBusy: function(apis, dialog, getBusySpec2) {
  29553. apis.setBusy(dialog, getBusySpec2);
  29554. },
  29555. setIdle: function(apis, dialog) {
  29556. apis.setIdle(dialog);
  29557. }
  29558. }
  29559. });
  29560. var dialogToggleMenuItemSchema = objOf([
  29561. requiredString("type"),
  29562. requiredString("name")
  29563. ].concat(commonMenuItemFields));
  29564. var dialogToggleMenuItemDataProcessor = boolean;
  29565. var baseFooterButtonFields = [
  29566. field$1("name", "name", defaultedThunk(function() {
  29567. return generate$6("button-name");
  29568. }), string),
  29569. optionString("icon"),
  29570. defaultedStringEnum("align", "end", [
  29571. "start",
  29572. "end"
  29573. ]),
  29574. defaultedBoolean("primary", false),
  29575. defaultedBoolean("disabled", false)
  29576. ];
  29577. var dialogFooterButtonFields = __spreadArray(__spreadArray([], baseFooterButtonFields, true), [requiredString("text")], false);
  29578. var normalFooterButtonFields = __spreadArray([requiredStringEnum("type", [
  29579. "submit",
  29580. "cancel",
  29581. "custom"
  29582. ])], dialogFooterButtonFields, true);
  29583. var menuFooterButtonFields = __spreadArray([
  29584. requiredStringEnum("type", ["menu"]),
  29585. optionString("text"),
  29586. optionString("tooltip"),
  29587. optionString("icon"),
  29588. requiredArrayOf("items", dialogToggleMenuItemSchema)
  29589. ], baseFooterButtonFields, true);
  29590. var dialogFooterButtonSchema = choose$1("type", {
  29591. submit: normalFooterButtonFields,
  29592. cancel: normalFooterButtonFields,
  29593. custom: normalFooterButtonFields,
  29594. menu: menuFooterButtonFields
  29595. });
  29596. var alertBannerFields = [
  29597. requiredString("type"),
  29598. requiredString("text"),
  29599. requiredStringEnum("level", [
  29600. "info",
  29601. "warn",
  29602. "error",
  29603. "success"
  29604. ]),
  29605. requiredString("icon"),
  29606. defaulted("url", "")
  29607. ];
  29608. var alertBannerSchema = objOf(alertBannerFields);
  29609. var createBarFields = function(itemsField) {
  29610. return [
  29611. requiredString("type"),
  29612. itemsField
  29613. ];
  29614. };
  29615. var buttonFields = [
  29616. requiredString("type"),
  29617. requiredString("text"),
  29618. defaultedBoolean("disabled", false),
  29619. defaultedBoolean("primary", false),
  29620. field$1("name", "name", defaultedThunk(function() {
  29621. return generate$6("button-name");
  29622. }), string),
  29623. optionString("icon"),
  29624. defaultedBoolean("borderless", false)
  29625. ];
  29626. var buttonSchema = objOf(buttonFields);
  29627. var checkboxFields = [
  29628. requiredString("type"),
  29629. requiredString("name"),
  29630. requiredString("label"),
  29631. defaultedBoolean("disabled", false)
  29632. ];
  29633. var checkboxSchema = objOf(checkboxFields);
  29634. var checkboxDataProcessor = boolean;
  29635. var formComponentFields = [
  29636. requiredString("type"),
  29637. requiredString("name")
  29638. ];
  29639. var formComponentWithLabelFields = formComponentFields.concat([optionString("label")]);
  29640. var collectionFields = formComponentWithLabelFields.concat([defaulted("columns", "auto")]);
  29641. var collectionSchema = objOf(collectionFields);
  29642. var collectionDataProcessor = arrOfObj([
  29643. requiredString("value"),
  29644. requiredString("text"),
  29645. requiredString("icon")
  29646. ]);
  29647. var colorInputFields = formComponentWithLabelFields;
  29648. var colorInputSchema = objOf(colorInputFields);
  29649. var colorInputDataProcessor = string;
  29650. var colorPickerFields = formComponentWithLabelFields;
  29651. var colorPickerSchema = objOf(colorPickerFields);
  29652. var colorPickerDataProcessor = string;
  29653. var customEditorFields = formComponentFields.concat([
  29654. defaultedString("tag", "textarea"),
  29655. requiredString("scriptId"),
  29656. requiredString("scriptUrl"),
  29657. defaultedPostMsg("settings", void 0)
  29658. ]);
  29659. var customEditorFieldsOld = formComponentFields.concat([
  29660. defaultedString("tag", "textarea"),
  29661. requiredFunction("init")
  29662. ]);
  29663. var customEditorSchema = valueOf(function(v) {
  29664. return asRaw("customeditor.old", objOfOnly(customEditorFieldsOld), v).orThunk(function() {
  29665. return asRaw("customeditor.new", objOfOnly(customEditorFields), v);
  29666. });
  29667. });
  29668. var customEditorDataProcessor = string;
  29669. var dropZoneFields = formComponentWithLabelFields;
  29670. var dropZoneSchema = objOf(dropZoneFields);
  29671. var dropZoneDataProcessor = arrOfVal();
  29672. var createGridFields = function(itemsField) {
  29673. return [
  29674. requiredString("type"),
  29675. requiredNumber("columns"),
  29676. itemsField
  29677. ];
  29678. };
  29679. var htmlPanelFields = [
  29680. requiredString("type"),
  29681. requiredString("html"),
  29682. defaultedStringEnum("presets", "presentation", [
  29683. "presentation",
  29684. "document"
  29685. ])
  29686. ];
  29687. var htmlPanelSchema = objOf(htmlPanelFields);
  29688. var iframeFields = formComponentWithLabelFields.concat([defaultedBoolean("sandboxed", true)]);
  29689. var iframeSchema = objOf(iframeFields);
  29690. var iframeDataProcessor = string;
  29691. var imageToolsFields = formComponentWithLabelFields.concat([requiredOf("currentState", objOf([
  29692. required$1("blob"),
  29693. requiredString("url")
  29694. ]))]);
  29695. var imageToolsSchema = objOf(imageToolsFields);
  29696. var inputFields = formComponentWithLabelFields.concat([
  29697. optionString("inputMode"),
  29698. optionString("placeholder"),
  29699. defaultedBoolean("maximized", false),
  29700. defaultedBoolean("disabled", false)
  29701. ]);
  29702. var inputSchema = objOf(inputFields);
  29703. var inputDataProcessor = string;
  29704. var createLabelFields = function(itemsField) {
  29705. return [
  29706. requiredString("type"),
  29707. requiredString("label"),
  29708. itemsField
  29709. ];
  29710. };
  29711. var listBoxSingleItemFields = [
  29712. requiredString("text"),
  29713. requiredString("value")
  29714. ];
  29715. var listBoxNestedItemFields = [
  29716. requiredString("text"),
  29717. requiredArrayOf("items", thunkOf("items", function() {
  29718. return listBoxItemSchema;
  29719. }))
  29720. ];
  29721. var listBoxItemSchema = oneOf([
  29722. objOf(listBoxSingleItemFields),
  29723. objOf(listBoxNestedItemFields)
  29724. ]);
  29725. var listBoxFields = formComponentWithLabelFields.concat([
  29726. requiredArrayOf("items", listBoxItemSchema),
  29727. defaultedBoolean("disabled", false)
  29728. ]);
  29729. var listBoxSchema = objOf(listBoxFields);
  29730. var listBoxDataProcessor = string;
  29731. var selectBoxFields = formComponentWithLabelFields.concat([
  29732. requiredArrayOfObj("items", [
  29733. requiredString("text"),
  29734. requiredString("value")
  29735. ]),
  29736. defaultedNumber("size", 1),
  29737. defaultedBoolean("disabled", false)
  29738. ]);
  29739. var selectBoxSchema = objOf(selectBoxFields);
  29740. var selectBoxDataProcessor = string;
  29741. var sizeInputFields = formComponentWithLabelFields.concat([
  29742. defaultedBoolean("constrain", true),
  29743. defaultedBoolean("disabled", false)
  29744. ]);
  29745. var sizeInputSchema = objOf(sizeInputFields);
  29746. var sizeInputDataProcessor = objOf([
  29747. requiredString("width"),
  29748. requiredString("height")
  29749. ]);
  29750. var tableFields = [
  29751. requiredString("type"),
  29752. requiredArrayOf("header", string),
  29753. requiredArrayOf("cells", arrOf(string))
  29754. ];
  29755. var tableSchema = objOf(tableFields);
  29756. var textAreaFields = formComponentWithLabelFields.concat([
  29757. optionString("placeholder"),
  29758. defaultedBoolean("maximized", false),
  29759. defaultedBoolean("disabled", false)
  29760. ]);
  29761. var textAreaSchema = objOf(textAreaFields);
  29762. var textAreaDataProcessor = string;
  29763. var urlInputFields = formComponentWithLabelFields.concat([
  29764. defaultedStringEnum("filetype", "file", [
  29765. "image",
  29766. "media",
  29767. "file"
  29768. ]),
  29769. defaulted("disabled", false)
  29770. ]);
  29771. var urlInputSchema = objOf(urlInputFields);
  29772. var urlInputDataProcessor = objOf([
  29773. requiredString("value"),
  29774. defaulted("meta", {})
  29775. ]);
  29776. var createItemsField = function(name2) {
  29777. return field$1("items", "items", required$2(), arrOf(valueOf(function(v) {
  29778. return asRaw("Checking item of " + name2, itemSchema, v).fold(function(sErr) {
  29779. return Result.error(formatError(sErr));
  29780. }, function(passValue) {
  29781. return Result.value(passValue);
  29782. });
  29783. })));
  29784. };
  29785. var itemSchema = valueThunk(function() {
  29786. return choose$2("type", {
  29787. alertbanner: alertBannerSchema,
  29788. bar: objOf(createBarFields(createItemsField("bar"))),
  29789. button: buttonSchema,
  29790. checkbox: checkboxSchema,
  29791. colorinput: colorInputSchema,
  29792. colorpicker: colorPickerSchema,
  29793. dropzone: dropZoneSchema,
  29794. grid: objOf(createGridFields(createItemsField("grid"))),
  29795. iframe: iframeSchema,
  29796. input: inputSchema,
  29797. listbox: listBoxSchema,
  29798. selectbox: selectBoxSchema,
  29799. sizeinput: sizeInputSchema,
  29800. textarea: textAreaSchema,
  29801. urlinput: urlInputSchema,
  29802. customeditor: customEditorSchema,
  29803. htmlpanel: htmlPanelSchema,
  29804. imagetools: imageToolsSchema,
  29805. collection: collectionSchema,
  29806. label: objOf(createLabelFields(createItemsField("label"))),
  29807. table: tableSchema,
  29808. panel: panelSchema
  29809. });
  29810. });
  29811. var panelFields = [
  29812. requiredString("type"),
  29813. defaulted("classes", []),
  29814. requiredArrayOf("items", itemSchema)
  29815. ];
  29816. var panelSchema = objOf(panelFields);
  29817. var tabFields = [
  29818. field$1("name", "name", defaultedThunk(function() {
  29819. return generate$6("tab-name");
  29820. }), string),
  29821. requiredString("title"),
  29822. requiredArrayOf("items", itemSchema)
  29823. ];
  29824. var tabPanelFields = [
  29825. requiredString("type"),
  29826. requiredArrayOfObj("tabs", tabFields)
  29827. ];
  29828. var tabPanelSchema = objOf(tabPanelFields);
  29829. var dialogButtonFields = dialogFooterButtonFields;
  29830. var dialogButtonSchema = dialogFooterButtonSchema;
  29831. var dialogSchema = objOf([
  29832. requiredString("title"),
  29833. requiredOf("body", choose$2("type", {
  29834. panel: panelSchema,
  29835. tabpanel: tabPanelSchema
  29836. })),
  29837. defaultedString("size", "normal"),
  29838. requiredArrayOf("buttons", dialogButtonSchema),
  29839. defaulted("initialData", {}),
  29840. defaultedFunction("onAction", noop),
  29841. defaultedFunction("onChange", noop),
  29842. defaultedFunction("onSubmit", noop),
  29843. defaultedFunction("onClose", noop),
  29844. defaultedFunction("onCancel", noop),
  29845. defaulted("onTabChange", noop)
  29846. ]);
  29847. var createDialog = function(spec) {
  29848. return asRaw("dialog", dialogSchema, spec);
  29849. };
  29850. var urlDialogButtonSchema = objOf(__spreadArray([requiredStringEnum("type", [
  29851. "cancel",
  29852. "custom"
  29853. ])], dialogButtonFields, true));
  29854. var urlDialogSchema = objOf([
  29855. requiredString("title"),
  29856. requiredString("url"),
  29857. optionNumber("height"),
  29858. optionNumber("width"),
  29859. optionArrayOf("buttons", urlDialogButtonSchema),
  29860. defaultedFunction("onAction", noop),
  29861. defaultedFunction("onCancel", noop),
  29862. defaultedFunction("onClose", noop),
  29863. defaultedFunction("onMessage", noop)
  29864. ]);
  29865. var createUrlDialog = function(spec) {
  29866. return asRaw("dialog", urlDialogSchema, spec);
  29867. };
  29868. var getAllObjects = function(obj) {
  29869. if (isObject(obj)) {
  29870. return [obj].concat(bind$3(values(obj), getAllObjects));
  29871. } else if (isArray(obj)) {
  29872. return bind$3(obj, getAllObjects);
  29873. } else {
  29874. return [];
  29875. }
  29876. };
  29877. var isNamedItem = function(obj) {
  29878. return isString(obj.type) && isString(obj.name);
  29879. };
  29880. var dataProcessors = {
  29881. checkbox: checkboxDataProcessor,
  29882. colorinput: colorInputDataProcessor,
  29883. colorpicker: colorPickerDataProcessor,
  29884. dropzone: dropZoneDataProcessor,
  29885. input: inputDataProcessor,
  29886. iframe: iframeDataProcessor,
  29887. sizeinput: sizeInputDataProcessor,
  29888. selectbox: selectBoxDataProcessor,
  29889. listbox: listBoxDataProcessor,
  29890. size: sizeInputDataProcessor,
  29891. textarea: textAreaDataProcessor,
  29892. urlinput: urlInputDataProcessor,
  29893. customeditor: customEditorDataProcessor,
  29894. collection: collectionDataProcessor,
  29895. togglemenuitem: dialogToggleMenuItemDataProcessor
  29896. };
  29897. var getDataProcessor = function(item2) {
  29898. return Optional.from(dataProcessors[item2.type]);
  29899. };
  29900. var getNamedItems = function(structure) {
  29901. return filter$2(getAllObjects(structure), isNamedItem);
  29902. };
  29903. var createDataValidator = function(structure) {
  29904. var namedItems = getNamedItems(structure);
  29905. var fields = bind$3(namedItems, function(item2) {
  29906. return getDataProcessor(item2).fold(function() {
  29907. return [];
  29908. }, function(schema2) {
  29909. return [requiredOf(item2.name, schema2)];
  29910. });
  29911. });
  29912. return objOf(fields);
  29913. };
  29914. var extract = function(structure) {
  29915. var internalDialog = getOrDie(createDialog(structure));
  29916. var dataValidator = createDataValidator(structure);
  29917. var initialData = structure.initialData;
  29918. return {
  29919. internalDialog,
  29920. dataValidator,
  29921. initialData
  29922. };
  29923. };
  29924. var DialogManager = {
  29925. open: function(factory2, structure) {
  29926. var extraction = extract(structure);
  29927. return factory2(extraction.internalDialog, extraction.initialData, extraction.dataValidator);
  29928. },
  29929. openUrl: function(factory2, structure) {
  29930. var internalDialog = getOrDie(createUrlDialog(structure));
  29931. return factory2(internalDialog);
  29932. },
  29933. redial: function(structure) {
  29934. return extract(structure);
  29935. }
  29936. };
  29937. var toValidValues = function(values2) {
  29938. var errors = [];
  29939. var result = {};
  29940. each(values2, function(value2, name2) {
  29941. value2.fold(function() {
  29942. errors.push(name2);
  29943. }, function(v) {
  29944. result[name2] = v;
  29945. });
  29946. });
  29947. return errors.length > 0 ? Result.error(errors) : Result.value(result);
  29948. };
  29949. var renderBodyPanel = function(spec, backstage) {
  29950. var memForm = record(Form.sketch(function(parts2) {
  29951. return {
  29952. dom: {
  29953. tag: "div",
  29954. classes: ["tox-form"].concat(spec.classes)
  29955. },
  29956. components: map$2(spec.items, function(item2) {
  29957. return interpretInForm(parts2, item2, backstage);
  29958. })
  29959. };
  29960. }));
  29961. return {
  29962. dom: {
  29963. tag: "div",
  29964. classes: ["tox-dialog__body"]
  29965. },
  29966. components: [{
  29967. dom: {
  29968. tag: "div",
  29969. classes: ["tox-dialog__body-content"]
  29970. },
  29971. components: [memForm.asSpec()]
  29972. }],
  29973. behaviours: derive$1([
  29974. Keying.config({
  29975. mode: "acyclic",
  29976. useTabstopAt: not(isPseudoStop)
  29977. }),
  29978. ComposingConfigs.memento(memForm),
  29979. RepresentingConfigs.memento(memForm, {
  29980. postprocess: function(formValue) {
  29981. return toValidValues(formValue).fold(function(err) {
  29982. console.error(err);
  29983. return {};
  29984. }, identity$1);
  29985. }
  29986. })
  29987. ])
  29988. };
  29989. };
  29990. var factory$3 = function(detail, _spec) {
  29991. return {
  29992. uid: detail.uid,
  29993. dom: detail.dom,
  29994. components: detail.components,
  29995. events: events$a(detail.action),
  29996. behaviours: augment(detail.tabButtonBehaviours, [
  29997. Focusing.config({}),
  29998. Keying.config({
  29999. mode: "execution",
  30000. useSpace: true,
  30001. useEnter: true
  30002. }),
  30003. Representing.config({
  30004. store: {
  30005. mode: "memory",
  30006. initialValue: detail.value
  30007. }
  30008. })
  30009. ]),
  30010. domModification: detail.domModification
  30011. };
  30012. };
  30013. var TabButton = single({
  30014. name: "TabButton",
  30015. configFields: [
  30016. defaulted("uid", void 0),
  30017. required$1("value"),
  30018. field$1("dom", "dom", mergeWithThunk(function() {
  30019. return {
  30020. attributes: {
  30021. "role": "tab",
  30022. "id": generate$6("aria"),
  30023. "aria-selected": "false"
  30024. }
  30025. };
  30026. }), anyValue()),
  30027. option("action"),
  30028. defaulted("domModification", {}),
  30029. field("tabButtonBehaviours", [
  30030. Focusing,
  30031. Keying,
  30032. Representing
  30033. ]),
  30034. required$1("view")
  30035. ],
  30036. factory: factory$3
  30037. });
  30038. var schema$1 = constant$1([
  30039. required$1("tabs"),
  30040. required$1("dom"),
  30041. defaulted("clickToDismiss", false),
  30042. field("tabbarBehaviours", [
  30043. Highlighting,
  30044. Keying
  30045. ]),
  30046. markers$1([
  30047. "tabClass",
  30048. "selectedClass"
  30049. ])
  30050. ]);
  30051. var tabsPart = group({
  30052. factory: TabButton,
  30053. name: "tabs",
  30054. unit: "tab",
  30055. overrides: function(barDetail) {
  30056. var dismissTab$1 = function(tabbar, button2) {
  30057. Highlighting.dehighlight(tabbar, button2);
  30058. emitWith(tabbar, dismissTab(), {
  30059. tabbar,
  30060. button: button2
  30061. });
  30062. };
  30063. var changeTab$1 = function(tabbar, button2) {
  30064. Highlighting.highlight(tabbar, button2);
  30065. emitWith(tabbar, changeTab(), {
  30066. tabbar,
  30067. button: button2
  30068. });
  30069. };
  30070. return {
  30071. action: function(button2) {
  30072. var tabbar = button2.getSystem().getByUid(barDetail.uid).getOrDie();
  30073. var activeButton = Highlighting.isHighlighted(tabbar, button2);
  30074. var response = function() {
  30075. if (activeButton && barDetail.clickToDismiss) {
  30076. return dismissTab$1;
  30077. } else if (!activeButton) {
  30078. return changeTab$1;
  30079. } else {
  30080. return noop;
  30081. }
  30082. }();
  30083. response(tabbar, button2);
  30084. },
  30085. domModification: { classes: [barDetail.markers.tabClass] }
  30086. };
  30087. }
  30088. });
  30089. var parts$1 = constant$1([tabsPart]);
  30090. var factory$2 = function(detail, components2, _spec, _externals) {
  30091. return {
  30092. "uid": detail.uid,
  30093. "dom": detail.dom,
  30094. components: components2,
  30095. "debug.sketcher": "Tabbar",
  30096. "domModification": { attributes: { role: "tablist" } },
  30097. "behaviours": augment(detail.tabbarBehaviours, [
  30098. Highlighting.config({
  30099. highlightClass: detail.markers.selectedClass,
  30100. itemClass: detail.markers.tabClass,
  30101. onHighlight: function(tabbar, tab) {
  30102. set$8(tab.element, "aria-selected", "true");
  30103. },
  30104. onDehighlight: function(tabbar, tab) {
  30105. set$8(tab.element, "aria-selected", "false");
  30106. }
  30107. }),
  30108. Keying.config({
  30109. mode: "flow",
  30110. getInitial: function(tabbar) {
  30111. return Highlighting.getHighlighted(tabbar).map(function(tab) {
  30112. return tab.element;
  30113. });
  30114. },
  30115. selector: "." + detail.markers.tabClass,
  30116. executeOnMove: true
  30117. })
  30118. ])
  30119. };
  30120. };
  30121. var Tabbar = composite({
  30122. name: "Tabbar",
  30123. configFields: schema$1(),
  30124. partFields: parts$1(),
  30125. factory: factory$2
  30126. });
  30127. var factory$1 = function(detail, _spec) {
  30128. return {
  30129. uid: detail.uid,
  30130. dom: detail.dom,
  30131. behaviours: augment(detail.tabviewBehaviours, [Replacing.config({})]),
  30132. domModification: { attributes: { role: "tabpanel" } }
  30133. };
  30134. };
  30135. var Tabview = single({
  30136. name: "Tabview",
  30137. configFields: [field("tabviewBehaviours", [Replacing])],
  30138. factory: factory$1
  30139. });
  30140. var schema = constant$1([
  30141. defaulted("selectFirst", true),
  30142. onHandler("onChangeTab"),
  30143. onHandler("onDismissTab"),
  30144. defaulted("tabs", []),
  30145. field("tabSectionBehaviours", [])
  30146. ]);
  30147. var barPart = required({
  30148. factory: Tabbar,
  30149. schema: [
  30150. required$1("dom"),
  30151. requiredObjOf("markers", [
  30152. required$1("tabClass"),
  30153. required$1("selectedClass")
  30154. ])
  30155. ],
  30156. name: "tabbar",
  30157. defaults: function(detail) {
  30158. return { tabs: detail.tabs };
  30159. }
  30160. });
  30161. var viewPart = required({
  30162. factory: Tabview,
  30163. name: "tabview"
  30164. });
  30165. var parts = constant$1([
  30166. barPart,
  30167. viewPart
  30168. ]);
  30169. var factory = function(detail, components2, _spec, _externals) {
  30170. var changeTab$1 = function(button2) {
  30171. var tabValue = Representing.getValue(button2);
  30172. getPart(button2, detail, "tabview").each(function(tabview) {
  30173. var tabWithValue = find$5(detail.tabs, function(t2) {
  30174. return t2.value === tabValue;
  30175. });
  30176. tabWithValue.each(function(tabData) {
  30177. var panel = tabData.view();
  30178. getOpt(button2.element, "id").each(function(id) {
  30179. set$8(tabview.element, "aria-labelledby", id);
  30180. });
  30181. Replacing.set(tabview, panel);
  30182. detail.onChangeTab(tabview, button2, panel);
  30183. });
  30184. });
  30185. };
  30186. var changeTabBy = function(section, byPred) {
  30187. getPart(section, detail, "tabbar").each(function(tabbar) {
  30188. byPred(tabbar).each(emitExecute);
  30189. });
  30190. };
  30191. return {
  30192. uid: detail.uid,
  30193. dom: detail.dom,
  30194. components: components2,
  30195. behaviours: get$2(detail.tabSectionBehaviours),
  30196. events: derive$2(flatten([
  30197. detail.selectFirst ? [runOnAttached(function(section, _simulatedEvent) {
  30198. changeTabBy(section, Highlighting.getFirst);
  30199. })] : [],
  30200. [
  30201. run$1(changeTab(), function(section, simulatedEvent) {
  30202. var button2 = simulatedEvent.event.button;
  30203. changeTab$1(button2);
  30204. }),
  30205. run$1(dismissTab(), function(section, simulatedEvent) {
  30206. var button2 = simulatedEvent.event.button;
  30207. detail.onDismissTab(section, button2);
  30208. })
  30209. ]
  30210. ])),
  30211. apis: {
  30212. getViewItems: function(section) {
  30213. return getPart(section, detail, "tabview").map(function(tabview) {
  30214. return Replacing.contents(tabview);
  30215. }).getOr([]);
  30216. },
  30217. showTab: function(section, tabKey) {
  30218. var getTabIfNotActive = function(tabbar) {
  30219. var candidates = Highlighting.getCandidates(tabbar);
  30220. var optTab = find$5(candidates, function(c) {
  30221. return Representing.getValue(c) === tabKey;
  30222. });
  30223. return optTab.filter(function(tab) {
  30224. return !Highlighting.isHighlighted(tabbar, tab);
  30225. });
  30226. };
  30227. changeTabBy(section, getTabIfNotActive);
  30228. }
  30229. }
  30230. };
  30231. };
  30232. var TabSection = composite({
  30233. name: "TabSection",
  30234. configFields: schema(),
  30235. partFields: parts(),
  30236. factory,
  30237. apis: {
  30238. getViewItems: function(apis, component) {
  30239. return apis.getViewItems(component);
  30240. },
  30241. showTab: function(apis, component, tabKey) {
  30242. apis.showTab(component, tabKey);
  30243. }
  30244. }
  30245. });
  30246. var measureHeights = function(allTabs, tabview, tabviewComp) {
  30247. return map$2(allTabs, function(_tab, i) {
  30248. Replacing.set(tabviewComp, allTabs[i].view());
  30249. var rect2 = tabview.dom.getBoundingClientRect();
  30250. Replacing.set(tabviewComp, []);
  30251. return rect2.height;
  30252. });
  30253. };
  30254. var getMaxHeight = function(heights) {
  30255. return head(sort(heights, function(a, b2) {
  30256. if (a > b2) {
  30257. return -1;
  30258. } else if (a < b2) {
  30259. return 1;
  30260. } else {
  30261. return 0;
  30262. }
  30263. }));
  30264. };
  30265. var getMaxTabviewHeight = function(dialog, tabview, tablist) {
  30266. var documentElement$1 = documentElement(dialog).dom;
  30267. var rootElm = ancestor(dialog, ".tox-dialog-wrap").getOr(dialog);
  30268. var isFixed = get$c(rootElm, "position") === "fixed";
  30269. var maxHeight;
  30270. if (isFixed) {
  30271. maxHeight = Math.max(documentElement$1.clientHeight, window.innerHeight);
  30272. } else {
  30273. maxHeight = Math.max(documentElement$1.offsetHeight, documentElement$1.scrollHeight);
  30274. }
  30275. var tabviewHeight = get$b(tabview);
  30276. var isTabListBeside = tabview.dom.offsetLeft >= tablist.dom.offsetLeft + get$a(tablist);
  30277. var currentTabHeight = isTabListBeside ? Math.max(get$b(tablist), tabviewHeight) : tabviewHeight;
  30278. var dialogTopMargin = parseInt(get$c(dialog, "margin-top"), 10) || 0;
  30279. var dialogBottomMargin = parseInt(get$c(dialog, "margin-bottom"), 10) || 0;
  30280. var dialogHeight = get$b(dialog) + dialogTopMargin + dialogBottomMargin;
  30281. var chromeHeight = dialogHeight - currentTabHeight;
  30282. return maxHeight - chromeHeight;
  30283. };
  30284. var showTab = function(allTabs, comp) {
  30285. head(allTabs).each(function(tab) {
  30286. return TabSection.showTab(comp, tab.value);
  30287. });
  30288. };
  30289. var setTabviewHeight = function(tabview, height2) {
  30290. set$7(tabview, "height", height2 + "px");
  30291. if (!detect$1().browser.isIE()) {
  30292. set$7(tabview, "flex-basis", height2 + "px");
  30293. } else {
  30294. remove$6(tabview, "flex-basis");
  30295. }
  30296. };
  30297. var updateTabviewHeight = function(dialogBody, tabview, maxTabHeight) {
  30298. ancestor(dialogBody, '[role="dialog"]').each(function(dialog) {
  30299. descendant(dialog, '[role="tablist"]').each(function(tablist) {
  30300. maxTabHeight.get().map(function(height2) {
  30301. set$7(tabview, "height", "0");
  30302. set$7(tabview, "flex-basis", "0");
  30303. return Math.min(height2, getMaxTabviewHeight(dialog, tabview, tablist));
  30304. }).each(function(height2) {
  30305. setTabviewHeight(tabview, height2);
  30306. });
  30307. });
  30308. });
  30309. };
  30310. var getTabview = function(dialog) {
  30311. return descendant(dialog, '[role="tabpanel"]');
  30312. };
  30313. var setMode = function(allTabs) {
  30314. var smartTabHeight = function() {
  30315. var maxTabHeight = value$1();
  30316. var extraEvents = [
  30317. runOnAttached(function(comp) {
  30318. var dialog = comp.element;
  30319. getTabview(dialog).each(function(tabview) {
  30320. set$7(tabview, "visibility", "hidden");
  30321. comp.getSystem().getByDom(tabview).toOptional().each(function(tabviewComp) {
  30322. var heights = measureHeights(allTabs, tabview, tabviewComp);
  30323. var maxTabHeightOpt = getMaxHeight(heights);
  30324. maxTabHeightOpt.fold(maxTabHeight.clear, maxTabHeight.set);
  30325. });
  30326. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30327. remove$6(tabview, "visibility");
  30328. showTab(allTabs, comp);
  30329. global$f.requestAnimationFrame(function() {
  30330. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30331. });
  30332. });
  30333. }),
  30334. run$1(windowResize(), function(comp) {
  30335. var dialog = comp.element;
  30336. getTabview(dialog).each(function(tabview) {
  30337. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30338. });
  30339. }),
  30340. run$1(formResizeEvent, function(comp, _se) {
  30341. var dialog = comp.element;
  30342. getTabview(dialog).each(function(tabview) {
  30343. var oldFocus = active(getRootNode(tabview));
  30344. set$7(tabview, "visibility", "hidden");
  30345. var oldHeight = getRaw(tabview, "height").map(function(h) {
  30346. return parseInt(h, 10);
  30347. });
  30348. remove$6(tabview, "height");
  30349. remove$6(tabview, "flex-basis");
  30350. var newHeight = tabview.dom.getBoundingClientRect().height;
  30351. var hasGrown2 = oldHeight.forall(function(h) {
  30352. return newHeight > h;
  30353. });
  30354. if (hasGrown2) {
  30355. maxTabHeight.set(newHeight);
  30356. updateTabviewHeight(dialog, tabview, maxTabHeight);
  30357. } else {
  30358. oldHeight.each(function(h) {
  30359. setTabviewHeight(tabview, h);
  30360. });
  30361. }
  30362. remove$6(tabview, "visibility");
  30363. oldFocus.each(focus$3);
  30364. });
  30365. })
  30366. ];
  30367. var selectFirst = false;
  30368. return {
  30369. extraEvents,
  30370. selectFirst
  30371. };
  30372. }();
  30373. var naiveTabHeight = function() {
  30374. var extraEvents = [];
  30375. var selectFirst = true;
  30376. return {
  30377. extraEvents,
  30378. selectFirst
  30379. };
  30380. }();
  30381. return {
  30382. smartTabHeight,
  30383. naiveTabHeight
  30384. };
  30385. };
  30386. var SendDataToSectionChannel = "send-data-to-section";
  30387. var SendDataToViewChannel = "send-data-to-view";
  30388. var renderTabPanel = function(spec, backstage) {
  30389. var storedValue = Cell({});
  30390. var updateDataWithForm = function(form) {
  30391. var formData = Representing.getValue(form);
  30392. var validData = toValidValues(formData).getOr({});
  30393. var currentData = storedValue.get();
  30394. var newData = deepMerge(currentData, validData);
  30395. storedValue.set(newData);
  30396. };
  30397. var setDataOnForm = function(form) {
  30398. var tabData = storedValue.get();
  30399. Representing.setValue(form, tabData);
  30400. };
  30401. var oldTab = Cell(null);
  30402. var allTabs = map$2(spec.tabs, function(tab) {
  30403. return {
  30404. value: tab.name,
  30405. dom: {
  30406. tag: "div",
  30407. classes: ["tox-dialog__body-nav-item"],
  30408. innerHtml: backstage.shared.providers.translate(tab.title)
  30409. },
  30410. view: function() {
  30411. return [Form.sketch(function(parts2) {
  30412. return {
  30413. dom: {
  30414. tag: "div",
  30415. classes: ["tox-form"]
  30416. },
  30417. components: map$2(tab.items, function(item2) {
  30418. return interpretInForm(parts2, item2, backstage);
  30419. }),
  30420. formBehaviours: derive$1([
  30421. Keying.config({
  30422. mode: "acyclic",
  30423. useTabstopAt: not(isPseudoStop)
  30424. }),
  30425. config("TabView.form.events", [
  30426. runOnAttached(setDataOnForm),
  30427. runOnDetached(updateDataWithForm)
  30428. ]),
  30429. Receiving.config({
  30430. channels: wrapAll([
  30431. {
  30432. key: SendDataToSectionChannel,
  30433. value: { onReceive: updateDataWithForm }
  30434. },
  30435. {
  30436. key: SendDataToViewChannel,
  30437. value: { onReceive: setDataOnForm }
  30438. }
  30439. ])
  30440. })
  30441. ])
  30442. };
  30443. })];
  30444. }
  30445. };
  30446. });
  30447. var tabMode = setMode(allTabs).smartTabHeight;
  30448. return TabSection.sketch({
  30449. dom: {
  30450. tag: "div",
  30451. classes: ["tox-dialog__body"]
  30452. },
  30453. onChangeTab: function(section, button2, _viewItems) {
  30454. var name2 = Representing.getValue(button2);
  30455. emitWith(section, formTabChangeEvent, {
  30456. name: name2,
  30457. oldName: oldTab.get()
  30458. });
  30459. oldTab.set(name2);
  30460. },
  30461. tabs: allTabs,
  30462. components: [
  30463. TabSection.parts.tabbar({
  30464. dom: {
  30465. tag: "div",
  30466. classes: ["tox-dialog__body-nav"]
  30467. },
  30468. components: [Tabbar.parts.tabs({})],
  30469. markers: {
  30470. tabClass: "tox-tab",
  30471. selectedClass: "tox-dialog__body-nav-item--active"
  30472. },
  30473. tabbarBehaviours: derive$1([Tabstopping.config({})])
  30474. }),
  30475. TabSection.parts.tabview({
  30476. dom: {
  30477. tag: "div",
  30478. classes: ["tox-dialog__body-content"]
  30479. }
  30480. })
  30481. ],
  30482. selectFirst: tabMode.selectFirst,
  30483. tabSectionBehaviours: derive$1([
  30484. config("tabpanel", tabMode.extraEvents),
  30485. Keying.config({ mode: "acyclic" }),
  30486. Composing.config({
  30487. find: function(comp) {
  30488. return head(TabSection.getViewItems(comp));
  30489. }
  30490. }),
  30491. Representing.config({
  30492. store: {
  30493. mode: "manual",
  30494. getValue: function(tsection) {
  30495. tsection.getSystem().broadcastOn([SendDataToSectionChannel], {});
  30496. return storedValue.get();
  30497. },
  30498. setValue: function(tsection, value2) {
  30499. storedValue.set(value2);
  30500. tsection.getSystem().broadcastOn([SendDataToViewChannel], {});
  30501. }
  30502. }
  30503. })
  30504. ])
  30505. });
  30506. };
  30507. var dialogChannel = generate$6("update-dialog");
  30508. var titleChannel = generate$6("update-title");
  30509. var bodyChannel = generate$6("update-body");
  30510. var footerChannel = generate$6("update-footer");
  30511. var bodySendMessageChannel = generate$6("body-send-message");
  30512. var renderBody = function(spec, id, backstage, ariaAttrs) {
  30513. var renderComponents2 = function(incoming) {
  30514. switch (incoming.body.type) {
  30515. case "tabpanel": {
  30516. return [renderTabPanel(incoming.body, backstage)];
  30517. }
  30518. default: {
  30519. return [renderBodyPanel(incoming.body, backstage)];
  30520. }
  30521. }
  30522. };
  30523. var updateState = function(_comp, incoming) {
  30524. return Optional.some({
  30525. isTabPanel: function() {
  30526. return incoming.body.type === "tabpanel";
  30527. }
  30528. });
  30529. };
  30530. var ariaAttributes = { "aria-live": "polite" };
  30531. return {
  30532. dom: {
  30533. tag: "div",
  30534. classes: ["tox-dialog__content-js"],
  30535. attributes: __assign(__assign({}, id.map(function(x) {
  30536. return { id: x };
  30537. }).getOr({})), ariaAttrs ? ariaAttributes : {})
  30538. },
  30539. components: [],
  30540. behaviours: derive$1([
  30541. ComposingConfigs.childAt(0),
  30542. Reflecting.config({
  30543. channel: bodyChannel,
  30544. updateState,
  30545. renderComponents: renderComponents2,
  30546. initialData: spec
  30547. })
  30548. ])
  30549. };
  30550. };
  30551. var renderInlineBody = function(spec, contentId, backstage, ariaAttrs) {
  30552. return renderBody(spec, Optional.some(contentId), backstage, ariaAttrs);
  30553. };
  30554. var renderModalBody = function(spec, backstage) {
  30555. var bodySpec = renderBody(spec, Optional.none(), backstage, false);
  30556. return ModalDialog.parts.body(bodySpec);
  30557. };
  30558. var renderIframeBody = function(spec) {
  30559. var bodySpec = {
  30560. dom: {
  30561. tag: "div",
  30562. classes: ["tox-dialog__content-js"]
  30563. },
  30564. components: [{
  30565. dom: {
  30566. tag: "div",
  30567. classes: ["tox-dialog__body-iframe"]
  30568. },
  30569. components: [craft({
  30570. dom: {
  30571. tag: "iframe",
  30572. attributes: { src: spec.url }
  30573. },
  30574. behaviours: derive$1([
  30575. Tabstopping.config({}),
  30576. Focusing.config({})
  30577. ])
  30578. })]
  30579. }],
  30580. behaviours: derive$1([Keying.config({
  30581. mode: "acyclic",
  30582. useTabstopAt: not(isPseudoStop)
  30583. })])
  30584. };
  30585. return ModalDialog.parts.body(bodySpec);
  30586. };
  30587. function _typeof(obj) {
  30588. "@babel/helpers - typeof";
  30589. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
  30590. return typeof obj2;
  30591. } : function(obj2) {
  30592. return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
  30593. }, _typeof(obj);
  30594. }
  30595. function _setPrototypeOf(o, p) {
  30596. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
  30597. o2.__proto__ = p2;
  30598. return o2;
  30599. };
  30600. return _setPrototypeOf(o, p);
  30601. }
  30602. function _isNativeReflectConstruct() {
  30603. if (typeof Reflect === "undefined" || !Reflect.construct)
  30604. return false;
  30605. if (Reflect.construct.sham)
  30606. return false;
  30607. if (typeof Proxy === "function")
  30608. return true;
  30609. try {
  30610. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
  30611. }));
  30612. return true;
  30613. } catch (e) {
  30614. return false;
  30615. }
  30616. }
  30617. function _construct(Parent, args, Class) {
  30618. if (_isNativeReflectConstruct()) {
  30619. _construct = Reflect.construct;
  30620. } else {
  30621. _construct = function _construct2(Parent2, args2, Class2) {
  30622. var a = [null];
  30623. a.push.apply(a, args2);
  30624. var Constructor = Function.bind.apply(Parent2, a);
  30625. var instance = new Constructor();
  30626. if (Class2)
  30627. _setPrototypeOf(instance, Class2.prototype);
  30628. return instance;
  30629. };
  30630. }
  30631. return _construct.apply(null, arguments);
  30632. }
  30633. function _toConsumableArray(arr) {
  30634. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  30635. }
  30636. function _arrayWithoutHoles(arr) {
  30637. if (Array.isArray(arr))
  30638. return _arrayLikeToArray(arr);
  30639. }
  30640. function _iterableToArray(iter) {
  30641. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
  30642. return Array.from(iter);
  30643. }
  30644. function _unsupportedIterableToArray(o, minLen) {
  30645. if (!o)
  30646. return;
  30647. if (typeof o === "string")
  30648. return _arrayLikeToArray(o, minLen);
  30649. var n = Object.prototype.toString.call(o).slice(8, -1);
  30650. if (n === "Object" && o.constructor)
  30651. n = o.constructor.name;
  30652. if (n === "Map" || n === "Set")
  30653. return Array.from(o);
  30654. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
  30655. return _arrayLikeToArray(o, minLen);
  30656. }
  30657. function _arrayLikeToArray(arr, len) {
  30658. if (len == null || len > arr.length)
  30659. len = arr.length;
  30660. for (var i = 0, arr2 = new Array(len); i < len; i++)
  30661. arr2[i] = arr[i];
  30662. return arr2;
  30663. }
  30664. function _nonIterableSpread() {
  30665. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  30666. }
  30667. var hasOwnProperty = Object.hasOwnProperty, setPrototypeOf = Object.setPrototypeOf, isFrozen = Object.isFrozen, getPrototypeOf = Object.getPrototypeOf, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  30668. var freeze = Object.freeze, seal = Object.seal, create = Object.create;
  30669. var _ref = typeof Reflect !== "undefined" && Reflect, apply = _ref.apply, construct = _ref.construct;
  30670. if (!apply) {
  30671. apply = function apply2(fun, thisValue, args) {
  30672. return fun.apply(thisValue, args);
  30673. };
  30674. }
  30675. if (!freeze) {
  30676. freeze = function freeze2(x) {
  30677. return x;
  30678. };
  30679. }
  30680. if (!seal) {
  30681. seal = function seal2(x) {
  30682. return x;
  30683. };
  30684. }
  30685. if (!construct) {
  30686. construct = function construct2(Func, args) {
  30687. return _construct(Func, _toConsumableArray(args));
  30688. };
  30689. }
  30690. var arrayForEach = unapply(Array.prototype.forEach);
  30691. var arrayPop = unapply(Array.prototype.pop);
  30692. var arrayPush = unapply(Array.prototype.push);
  30693. var stringToLowerCase = unapply(String.prototype.toLowerCase);
  30694. var stringMatch = unapply(String.prototype.match);
  30695. var stringReplace = unapply(String.prototype.replace);
  30696. var stringIndexOf = unapply(String.prototype.indexOf);
  30697. var stringTrim = unapply(String.prototype.trim);
  30698. var regExpTest = unapply(RegExp.prototype.test);
  30699. var typeErrorCreate = unconstruct(TypeError);
  30700. function unapply(func) {
  30701. return function(thisArg) {
  30702. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  30703. args[_key - 1] = arguments[_key];
  30704. }
  30705. return apply(func, thisArg, args);
  30706. };
  30707. }
  30708. function unconstruct(func) {
  30709. return function() {
  30710. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  30711. args[_key2] = arguments[_key2];
  30712. }
  30713. return construct(func, args);
  30714. };
  30715. }
  30716. function addToSet(set2, array) {
  30717. if (setPrototypeOf) {
  30718. setPrototypeOf(set2, null);
  30719. }
  30720. var l2 = array.length;
  30721. while (l2--) {
  30722. var element2 = array[l2];
  30723. if (typeof element2 === "string") {
  30724. var lcElement = stringToLowerCase(element2);
  30725. if (lcElement !== element2) {
  30726. if (!isFrozen(array)) {
  30727. array[l2] = lcElement;
  30728. }
  30729. element2 = lcElement;
  30730. }
  30731. }
  30732. set2[element2] = true;
  30733. }
  30734. return set2;
  30735. }
  30736. function clone(object) {
  30737. var newObject = create(null);
  30738. var property;
  30739. for (property in object) {
  30740. if (apply(hasOwnProperty, object, [property])) {
  30741. newObject[property] = object[property];
  30742. }
  30743. }
  30744. return newObject;
  30745. }
  30746. function lookupGetter(object, prop) {
  30747. while (object !== null) {
  30748. var desc = getOwnPropertyDescriptor(object, prop);
  30749. if (desc) {
  30750. if (desc.get) {
  30751. return unapply(desc.get);
  30752. }
  30753. if (typeof desc.value === "function") {
  30754. return unapply(desc.value);
  30755. }
  30756. }
  30757. object = getPrototypeOf(object);
  30758. }
  30759. function fallbackValue(element2) {
  30760. console.warn("fallback value for", element2);
  30761. return null;
  30762. }
  30763. return fallbackValue;
  30764. }
  30765. var html$1 = freeze([
  30766. "a",
  30767. "abbr",
  30768. "acronym",
  30769. "address",
  30770. "area",
  30771. "article",
  30772. "aside",
  30773. "audio",
  30774. "b",
  30775. "bdi",
  30776. "bdo",
  30777. "big",
  30778. "blink",
  30779. "blockquote",
  30780. "body",
  30781. "br",
  30782. "button",
  30783. "canvas",
  30784. "caption",
  30785. "center",
  30786. "cite",
  30787. "code",
  30788. "col",
  30789. "colgroup",
  30790. "content",
  30791. "data",
  30792. "datalist",
  30793. "dd",
  30794. "decorator",
  30795. "del",
  30796. "details",
  30797. "dfn",
  30798. "dialog",
  30799. "dir",
  30800. "div",
  30801. "dl",
  30802. "dt",
  30803. "element",
  30804. "em",
  30805. "fieldset",
  30806. "figcaption",
  30807. "figure",
  30808. "font",
  30809. "footer",
  30810. "form",
  30811. "h1",
  30812. "h2",
  30813. "h3",
  30814. "h4",
  30815. "h5",
  30816. "h6",
  30817. "head",
  30818. "header",
  30819. "hgroup",
  30820. "hr",
  30821. "html",
  30822. "i",
  30823. "img",
  30824. "input",
  30825. "ins",
  30826. "kbd",
  30827. "label",
  30828. "legend",
  30829. "li",
  30830. "main",
  30831. "map",
  30832. "mark",
  30833. "marquee",
  30834. "menu",
  30835. "menuitem",
  30836. "meter",
  30837. "nav",
  30838. "nobr",
  30839. "ol",
  30840. "optgroup",
  30841. "option",
  30842. "output",
  30843. "p",
  30844. "picture",
  30845. "pre",
  30846. "progress",
  30847. "q",
  30848. "rp",
  30849. "rt",
  30850. "ruby",
  30851. "s",
  30852. "samp",
  30853. "section",
  30854. "select",
  30855. "shadow",
  30856. "small",
  30857. "source",
  30858. "spacer",
  30859. "span",
  30860. "strike",
  30861. "strong",
  30862. "style",
  30863. "sub",
  30864. "summary",
  30865. "sup",
  30866. "table",
  30867. "tbody",
  30868. "td",
  30869. "template",
  30870. "textarea",
  30871. "tfoot",
  30872. "th",
  30873. "thead",
  30874. "time",
  30875. "tr",
  30876. "track",
  30877. "tt",
  30878. "u",
  30879. "ul",
  30880. "var",
  30881. "video",
  30882. "wbr"
  30883. ]);
  30884. var svg$1 = freeze([
  30885. "svg",
  30886. "a",
  30887. "altglyph",
  30888. "altglyphdef",
  30889. "altglyphitem",
  30890. "animatecolor",
  30891. "animatemotion",
  30892. "animatetransform",
  30893. "circle",
  30894. "clippath",
  30895. "defs",
  30896. "desc",
  30897. "ellipse",
  30898. "filter",
  30899. "font",
  30900. "g",
  30901. "glyph",
  30902. "glyphref",
  30903. "hkern",
  30904. "image",
  30905. "line",
  30906. "lineargradient",
  30907. "marker",
  30908. "mask",
  30909. "metadata",
  30910. "mpath",
  30911. "path",
  30912. "pattern",
  30913. "polygon",
  30914. "polyline",
  30915. "radialgradient",
  30916. "rect",
  30917. "stop",
  30918. "style",
  30919. "switch",
  30920. "symbol",
  30921. "text",
  30922. "textpath",
  30923. "title",
  30924. "tref",
  30925. "tspan",
  30926. "view",
  30927. "vkern"
  30928. ]);
  30929. var svgFilters = freeze([
  30930. "feBlend",
  30931. "feColorMatrix",
  30932. "feComponentTransfer",
  30933. "feComposite",
  30934. "feConvolveMatrix",
  30935. "feDiffuseLighting",
  30936. "feDisplacementMap",
  30937. "feDistantLight",
  30938. "feFlood",
  30939. "feFuncA",
  30940. "feFuncB",
  30941. "feFuncG",
  30942. "feFuncR",
  30943. "feGaussianBlur",
  30944. "feImage",
  30945. "feMerge",
  30946. "feMergeNode",
  30947. "feMorphology",
  30948. "feOffset",
  30949. "fePointLight",
  30950. "feSpecularLighting",
  30951. "feSpotLight",
  30952. "feTile",
  30953. "feTurbulence"
  30954. ]);
  30955. var svgDisallowed = freeze([
  30956. "animate",
  30957. "color-profile",
  30958. "cursor",
  30959. "discard",
  30960. "fedropshadow",
  30961. "font-face",
  30962. "font-face-format",
  30963. "font-face-name",
  30964. "font-face-src",
  30965. "font-face-uri",
  30966. "foreignobject",
  30967. "hatch",
  30968. "hatchpath",
  30969. "mesh",
  30970. "meshgradient",
  30971. "meshpatch",
  30972. "meshrow",
  30973. "missing-glyph",
  30974. "script",
  30975. "set",
  30976. "solidcolor",
  30977. "unknown",
  30978. "use"
  30979. ]);
  30980. var mathMl$1 = freeze([
  30981. "math",
  30982. "menclose",
  30983. "merror",
  30984. "mfenced",
  30985. "mfrac",
  30986. "mglyph",
  30987. "mi",
  30988. "mlabeledtr",
  30989. "mmultiscripts",
  30990. "mn",
  30991. "mo",
  30992. "mover",
  30993. "mpadded",
  30994. "mphantom",
  30995. "mroot",
  30996. "mrow",
  30997. "ms",
  30998. "mspace",
  30999. "msqrt",
  31000. "mstyle",
  31001. "msub",
  31002. "msup",
  31003. "msubsup",
  31004. "mtable",
  31005. "mtd",
  31006. "mtext",
  31007. "mtr",
  31008. "munder",
  31009. "munderover"
  31010. ]);
  31011. var mathMlDisallowed = freeze([
  31012. "maction",
  31013. "maligngroup",
  31014. "malignmark",
  31015. "mlongdiv",
  31016. "mscarries",
  31017. "mscarry",
  31018. "msgroup",
  31019. "mstack",
  31020. "msline",
  31021. "msrow",
  31022. "semantics",
  31023. "annotation",
  31024. "annotation-xml",
  31025. "mprescripts",
  31026. "none"
  31027. ]);
  31028. var text = freeze(["#text"]);
  31029. var html = freeze([
  31030. "accept",
  31031. "action",
  31032. "align",
  31033. "alt",
  31034. "autocapitalize",
  31035. "autocomplete",
  31036. "autopictureinpicture",
  31037. "autoplay",
  31038. "background",
  31039. "bgcolor",
  31040. "border",
  31041. "capture",
  31042. "cellpadding",
  31043. "cellspacing",
  31044. "checked",
  31045. "cite",
  31046. "class",
  31047. "clear",
  31048. "color",
  31049. "cols",
  31050. "colspan",
  31051. "controls",
  31052. "controlslist",
  31053. "coords",
  31054. "crossorigin",
  31055. "datetime",
  31056. "decoding",
  31057. "default",
  31058. "dir",
  31059. "disabled",
  31060. "disablepictureinpicture",
  31061. "disableremoteplayback",
  31062. "download",
  31063. "draggable",
  31064. "enctype",
  31065. "enterkeyhint",
  31066. "face",
  31067. "for",
  31068. "headers",
  31069. "height",
  31070. "hidden",
  31071. "high",
  31072. "href",
  31073. "hreflang",
  31074. "id",
  31075. "inputmode",
  31076. "integrity",
  31077. "ismap",
  31078. "kind",
  31079. "label",
  31080. "lang",
  31081. "list",
  31082. "loading",
  31083. "loop",
  31084. "low",
  31085. "max",
  31086. "maxlength",
  31087. "media",
  31088. "method",
  31089. "min",
  31090. "minlength",
  31091. "multiple",
  31092. "muted",
  31093. "name",
  31094. "nonce",
  31095. "noshade",
  31096. "novalidate",
  31097. "nowrap",
  31098. "open",
  31099. "optimum",
  31100. "pattern",
  31101. "placeholder",
  31102. "playsinline",
  31103. "poster",
  31104. "preload",
  31105. "pubdate",
  31106. "radiogroup",
  31107. "readonly",
  31108. "rel",
  31109. "required",
  31110. "rev",
  31111. "reversed",
  31112. "role",
  31113. "rows",
  31114. "rowspan",
  31115. "spellcheck",
  31116. "scope",
  31117. "selected",
  31118. "shape",
  31119. "size",
  31120. "sizes",
  31121. "span",
  31122. "srclang",
  31123. "start",
  31124. "src",
  31125. "srcset",
  31126. "step",
  31127. "style",
  31128. "summary",
  31129. "tabindex",
  31130. "title",
  31131. "translate",
  31132. "type",
  31133. "usemap",
  31134. "valign",
  31135. "value",
  31136. "width",
  31137. "xmlns",
  31138. "slot"
  31139. ]);
  31140. var svg = freeze([
  31141. "accent-height",
  31142. "accumulate",
  31143. "additive",
  31144. "alignment-baseline",
  31145. "ascent",
  31146. "attributename",
  31147. "attributetype",
  31148. "azimuth",
  31149. "basefrequency",
  31150. "baseline-shift",
  31151. "begin",
  31152. "bias",
  31153. "by",
  31154. "class",
  31155. "clip",
  31156. "clippathunits",
  31157. "clip-path",
  31158. "clip-rule",
  31159. "color",
  31160. "color-interpolation",
  31161. "color-interpolation-filters",
  31162. "color-profile",
  31163. "color-rendering",
  31164. "cx",
  31165. "cy",
  31166. "d",
  31167. "dx",
  31168. "dy",
  31169. "diffuseconstant",
  31170. "direction",
  31171. "display",
  31172. "divisor",
  31173. "dur",
  31174. "edgemode",
  31175. "elevation",
  31176. "end",
  31177. "fill",
  31178. "fill-opacity",
  31179. "fill-rule",
  31180. "filter",
  31181. "filterunits",
  31182. "flood-color",
  31183. "flood-opacity",
  31184. "font-family",
  31185. "font-size",
  31186. "font-size-adjust",
  31187. "font-stretch",
  31188. "font-style",
  31189. "font-variant",
  31190. "font-weight",
  31191. "fx",
  31192. "fy",
  31193. "g1",
  31194. "g2",
  31195. "glyph-name",
  31196. "glyphref",
  31197. "gradientunits",
  31198. "gradienttransform",
  31199. "height",
  31200. "href",
  31201. "id",
  31202. "image-rendering",
  31203. "in",
  31204. "in2",
  31205. "k",
  31206. "k1",
  31207. "k2",
  31208. "k3",
  31209. "k4",
  31210. "kerning",
  31211. "keypoints",
  31212. "keysplines",
  31213. "keytimes",
  31214. "lang",
  31215. "lengthadjust",
  31216. "letter-spacing",
  31217. "kernelmatrix",
  31218. "kernelunitlength",
  31219. "lighting-color",
  31220. "local",
  31221. "marker-end",
  31222. "marker-mid",
  31223. "marker-start",
  31224. "markerheight",
  31225. "markerunits",
  31226. "markerwidth",
  31227. "maskcontentunits",
  31228. "maskunits",
  31229. "max",
  31230. "mask",
  31231. "media",
  31232. "method",
  31233. "mode",
  31234. "min",
  31235. "name",
  31236. "numoctaves",
  31237. "offset",
  31238. "operator",
  31239. "opacity",
  31240. "order",
  31241. "orient",
  31242. "orientation",
  31243. "origin",
  31244. "overflow",
  31245. "paint-order",
  31246. "path",
  31247. "pathlength",
  31248. "patterncontentunits",
  31249. "patterntransform",
  31250. "patternunits",
  31251. "points",
  31252. "preservealpha",
  31253. "preserveaspectratio",
  31254. "primitiveunits",
  31255. "r",
  31256. "rx",
  31257. "ry",
  31258. "radius",
  31259. "refx",
  31260. "refy",
  31261. "repeatcount",
  31262. "repeatdur",
  31263. "restart",
  31264. "result",
  31265. "rotate",
  31266. "scale",
  31267. "seed",
  31268. "shape-rendering",
  31269. "specularconstant",
  31270. "specularexponent",
  31271. "spreadmethod",
  31272. "startoffset",
  31273. "stddeviation",
  31274. "stitchtiles",
  31275. "stop-color",
  31276. "stop-opacity",
  31277. "stroke-dasharray",
  31278. "stroke-dashoffset",
  31279. "stroke-linecap",
  31280. "stroke-linejoin",
  31281. "stroke-miterlimit",
  31282. "stroke-opacity",
  31283. "stroke",
  31284. "stroke-width",
  31285. "style",
  31286. "surfacescale",
  31287. "systemlanguage",
  31288. "tabindex",
  31289. "targetx",
  31290. "targety",
  31291. "transform",
  31292. "transform-origin",
  31293. "text-anchor",
  31294. "text-decoration",
  31295. "text-rendering",
  31296. "textlength",
  31297. "type",
  31298. "u1",
  31299. "u2",
  31300. "unicode",
  31301. "values",
  31302. "viewbox",
  31303. "visibility",
  31304. "version",
  31305. "vert-adv-y",
  31306. "vert-origin-x",
  31307. "vert-origin-y",
  31308. "width",
  31309. "word-spacing",
  31310. "wrap",
  31311. "writing-mode",
  31312. "xchannelselector",
  31313. "ychannelselector",
  31314. "x",
  31315. "x1",
  31316. "x2",
  31317. "xmlns",
  31318. "y",
  31319. "y1",
  31320. "y2",
  31321. "z",
  31322. "zoomandpan"
  31323. ]);
  31324. var mathMl = freeze([
  31325. "accent",
  31326. "accentunder",
  31327. "align",
  31328. "bevelled",
  31329. "close",
  31330. "columnsalign",
  31331. "columnlines",
  31332. "columnspan",
  31333. "denomalign",
  31334. "depth",
  31335. "dir",
  31336. "display",
  31337. "displaystyle",
  31338. "encoding",
  31339. "fence",
  31340. "frame",
  31341. "height",
  31342. "href",
  31343. "id",
  31344. "largeop",
  31345. "length",
  31346. "linethickness",
  31347. "lspace",
  31348. "lquote",
  31349. "mathbackground",
  31350. "mathcolor",
  31351. "mathsize",
  31352. "mathvariant",
  31353. "maxsize",
  31354. "minsize",
  31355. "movablelimits",
  31356. "notation",
  31357. "numalign",
  31358. "open",
  31359. "rowalign",
  31360. "rowlines",
  31361. "rowspacing",
  31362. "rowspan",
  31363. "rspace",
  31364. "rquote",
  31365. "scriptlevel",
  31366. "scriptminsize",
  31367. "scriptsizemultiplier",
  31368. "selection",
  31369. "separator",
  31370. "separators",
  31371. "stretchy",
  31372. "subscriptshift",
  31373. "supscriptshift",
  31374. "symmetric",
  31375. "voffset",
  31376. "width",
  31377. "xmlns"
  31378. ]);
  31379. var xml = freeze([
  31380. "xlink:href",
  31381. "xml:id",
  31382. "xlink:title",
  31383. "xml:space",
  31384. "xmlns:xlink"
  31385. ]);
  31386. var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
  31387. var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
  31388. var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/);
  31389. var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
  31390. var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
  31391. var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
  31392. var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
  31393. var DOCTYPE_NAME = seal(/^html$/i);
  31394. var getGlobal = function getGlobal2() {
  31395. return typeof window === "undefined" ? null : window;
  31396. };
  31397. var _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, document2) {
  31398. if (_typeof(trustedTypes) !== "object" || typeof trustedTypes.createPolicy !== "function") {
  31399. return null;
  31400. }
  31401. var suffix2 = null;
  31402. var ATTR_NAME = "data-tt-policy-suffix";
  31403. if (document2.currentScript && document2.currentScript.hasAttribute(ATTR_NAME)) {
  31404. suffix2 = document2.currentScript.getAttribute(ATTR_NAME);
  31405. }
  31406. var policyName = "dompurify" + (suffix2 ? "#" + suffix2 : "");
  31407. try {
  31408. return trustedTypes.createPolicy(policyName, {
  31409. createHTML: function createHTML(html2) {
  31410. return html2;
  31411. }
  31412. });
  31413. } catch (_) {
  31414. console.warn("TrustedTypes policy " + policyName + " could not be created.");
  31415. return null;
  31416. }
  31417. };
  31418. function createDOMPurify() {
  31419. var window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
  31420. var DOMPurify = function DOMPurify2(root) {
  31421. return createDOMPurify(root);
  31422. };
  31423. DOMPurify.version = "2.3.8";
  31424. DOMPurify.removed = [];
  31425. if (!window2 || !window2.document || window2.document.nodeType !== 9) {
  31426. DOMPurify.isSupported = false;
  31427. return DOMPurify;
  31428. }
  31429. var originalDocument = window2.document;
  31430. var document2 = window2.document;
  31431. var DocumentFragment = window2.DocumentFragment, HTMLTemplateElement = window2.HTMLTemplateElement, Node2 = window2.Node, Element2 = window2.Element, NodeFilter = window2.NodeFilter, _window$NamedNodeMap = window2.NamedNodeMap, NamedNodeMap = _window$NamedNodeMap === void 0 ? window2.NamedNodeMap || window2.MozNamedAttrMap : _window$NamedNodeMap, HTMLFormElement = window2.HTMLFormElement, DOMParser = window2.DOMParser, trustedTypes = window2.trustedTypes;
  31432. var ElementPrototype = Element2.prototype;
  31433. var cloneNode = lookupGetter(ElementPrototype, "cloneNode");
  31434. var getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
  31435. var getChildNodes = lookupGetter(ElementPrototype, "childNodes");
  31436. var getParentNode = lookupGetter(ElementPrototype, "parentNode");
  31437. if (typeof HTMLTemplateElement === "function") {
  31438. var template = document2.createElement("template");
  31439. if (template.content && template.content.ownerDocument) {
  31440. document2 = template.content.ownerDocument;
  31441. }
  31442. }
  31443. var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
  31444. var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML("") : "";
  31445. var _document = document2, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
  31446. var importNode = originalDocument.importNode;
  31447. var documentMode = {};
  31448. try {
  31449. documentMode = clone(document2).documentMode ? document2.documentMode : {};
  31450. } catch (_) {
  31451. }
  31452. var hooks = {};
  31453. DOMPurify.isSupported = typeof getParentNode === "function" && implementation && typeof implementation.createHTMLDocument !== "undefined" && documentMode !== 9;
  31454. var MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE;
  31455. var IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
  31456. var ALLOWED_TAGS = null;
  31457. var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray(html$1), _toConsumableArray(svg$1), _toConsumableArray(svgFilters), _toConsumableArray(mathMl$1), _toConsumableArray(text)));
  31458. var ALLOWED_ATTR = null;
  31459. var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray(html), _toConsumableArray(svg), _toConsumableArray(mathMl), _toConsumableArray(xml)));
  31460. var CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
  31461. tagNameCheck: {
  31462. writable: true,
  31463. configurable: false,
  31464. enumerable: true,
  31465. value: null
  31466. },
  31467. attributeNameCheck: {
  31468. writable: true,
  31469. configurable: false,
  31470. enumerable: true,
  31471. value: null
  31472. },
  31473. allowCustomizedBuiltInElements: {
  31474. writable: true,
  31475. configurable: false,
  31476. enumerable: true,
  31477. value: false
  31478. }
  31479. }));
  31480. var FORBID_TAGS = null;
  31481. var FORBID_ATTR = null;
  31482. var ALLOW_ARIA_ATTR = true;
  31483. var ALLOW_DATA_ATTR = true;
  31484. var ALLOW_UNKNOWN_PROTOCOLS = false;
  31485. var SAFE_FOR_TEMPLATES = false;
  31486. var WHOLE_DOCUMENT = false;
  31487. var SET_CONFIG = false;
  31488. var FORCE_BODY = false;
  31489. var RETURN_DOM = false;
  31490. var RETURN_DOM_FRAGMENT = false;
  31491. var RETURN_TRUSTED_TYPE = false;
  31492. var SANITIZE_DOM = true;
  31493. var KEEP_CONTENT = true;
  31494. var IN_PLACE = false;
  31495. var USE_PROFILES = {};
  31496. var FORBID_CONTENTS = null;
  31497. var DEFAULT_FORBID_CONTENTS = addToSet({}, [
  31498. "annotation-xml",
  31499. "audio",
  31500. "colgroup",
  31501. "desc",
  31502. "foreignobject",
  31503. "head",
  31504. "iframe",
  31505. "math",
  31506. "mi",
  31507. "mn",
  31508. "mo",
  31509. "ms",
  31510. "mtext",
  31511. "noembed",
  31512. "noframes",
  31513. "noscript",
  31514. "plaintext",
  31515. "script",
  31516. "style",
  31517. "svg",
  31518. "template",
  31519. "thead",
  31520. "title",
  31521. "video",
  31522. "xmp"
  31523. ]);
  31524. var DATA_URI_TAGS = null;
  31525. var DEFAULT_DATA_URI_TAGS = addToSet({}, [
  31526. "audio",
  31527. "video",
  31528. "img",
  31529. "source",
  31530. "image",
  31531. "track"
  31532. ]);
  31533. var URI_SAFE_ATTRIBUTES = null;
  31534. var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
  31535. "alt",
  31536. "class",
  31537. "for",
  31538. "id",
  31539. "label",
  31540. "name",
  31541. "pattern",
  31542. "placeholder",
  31543. "role",
  31544. "summary",
  31545. "title",
  31546. "value",
  31547. "style",
  31548. "xmlns"
  31549. ]);
  31550. var MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
  31551. var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
  31552. var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
  31553. var NAMESPACE = HTML_NAMESPACE;
  31554. var IS_EMPTY_INPUT = false;
  31555. var PARSER_MEDIA_TYPE;
  31556. var SUPPORTED_PARSER_MEDIA_TYPES = [
  31557. "application/xhtml+xml",
  31558. "text/html"
  31559. ];
  31560. var DEFAULT_PARSER_MEDIA_TYPE = "text/html";
  31561. var transformCaseFunc;
  31562. var CONFIG = null;
  31563. var formElement = document2.createElement("form");
  31564. var isRegexOrFunction = function isRegexOrFunction2(testValue) {
  31565. return testValue instanceof RegExp || testValue instanceof Function;
  31566. };
  31567. var _parseConfig = function _parseConfig2(cfg) {
  31568. if (CONFIG && CONFIG === cfg) {
  31569. return;
  31570. }
  31571. if (!cfg || _typeof(cfg) !== "object") {
  31572. cfg = {};
  31573. }
  31574. cfg = clone(cfg);
  31575. ALLOWED_TAGS = "ALLOWED_TAGS" in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
  31576. ALLOWED_ATTR = "ALLOWED_ATTR" in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
  31577. URI_SAFE_ATTRIBUTES = "ADD_URI_SAFE_ATTR" in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;
  31578. DATA_URI_TAGS = "ADD_DATA_URI_TAGS" in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;
  31579. FORBID_CONTENTS = "FORBID_CONTENTS" in cfg ? addToSet({}, cfg.FORBID_CONTENTS) : DEFAULT_FORBID_CONTENTS;
  31580. FORBID_TAGS = "FORBID_TAGS" in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};
  31581. FORBID_ATTR = "FORBID_ATTR" in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};
  31582. USE_PROFILES = "USE_PROFILES" in cfg ? cfg.USE_PROFILES : false;
  31583. ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
  31584. ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
  31585. ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
  31586. SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
  31587. WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
  31588. RETURN_DOM = cfg.RETURN_DOM || false;
  31589. RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
  31590. RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
  31591. FORCE_BODY = cfg.FORCE_BODY || false;
  31592. SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
  31593. KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
  31594. IN_PLACE = cfg.IN_PLACE || false;
  31595. IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$1;
  31596. NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
  31597. if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
  31598. CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
  31599. }
  31600. if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
  31601. CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
  31602. }
  31603. if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
  31604. CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
  31605. }
  31606. PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE;
  31607. transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? function(x) {
  31608. return x;
  31609. } : stringToLowerCase;
  31610. if (SAFE_FOR_TEMPLATES) {
  31611. ALLOW_DATA_ATTR = false;
  31612. }
  31613. if (RETURN_DOM_FRAGMENT) {
  31614. RETURN_DOM = true;
  31615. }
  31616. if (USE_PROFILES) {
  31617. ALLOWED_TAGS = addToSet({}, _toConsumableArray(text));
  31618. ALLOWED_ATTR = [];
  31619. if (USE_PROFILES.html === true) {
  31620. addToSet(ALLOWED_TAGS, html$1);
  31621. addToSet(ALLOWED_ATTR, html);
  31622. }
  31623. if (USE_PROFILES.svg === true) {
  31624. addToSet(ALLOWED_TAGS, svg$1);
  31625. addToSet(ALLOWED_ATTR, svg);
  31626. addToSet(ALLOWED_ATTR, xml);
  31627. }
  31628. if (USE_PROFILES.svgFilters === true) {
  31629. addToSet(ALLOWED_TAGS, svgFilters);
  31630. addToSet(ALLOWED_ATTR, svg);
  31631. addToSet(ALLOWED_ATTR, xml);
  31632. }
  31633. if (USE_PROFILES.mathMl === true) {
  31634. addToSet(ALLOWED_TAGS, mathMl$1);
  31635. addToSet(ALLOWED_ATTR, mathMl);
  31636. addToSet(ALLOWED_ATTR, xml);
  31637. }
  31638. }
  31639. if (cfg.ADD_TAGS) {
  31640. if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
  31641. ALLOWED_TAGS = clone(ALLOWED_TAGS);
  31642. }
  31643. addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);
  31644. }
  31645. if (cfg.ADD_ATTR) {
  31646. if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
  31647. ALLOWED_ATTR = clone(ALLOWED_ATTR);
  31648. }
  31649. addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);
  31650. }
  31651. if (cfg.ADD_URI_SAFE_ATTR) {
  31652. addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);
  31653. }
  31654. if (cfg.FORBID_CONTENTS) {
  31655. if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
  31656. FORBID_CONTENTS = clone(FORBID_CONTENTS);
  31657. }
  31658. addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS);
  31659. }
  31660. if (KEEP_CONTENT) {
  31661. ALLOWED_TAGS["#text"] = true;
  31662. }
  31663. if (WHOLE_DOCUMENT) {
  31664. addToSet(ALLOWED_TAGS, [
  31665. "html",
  31666. "head",
  31667. "body"
  31668. ]);
  31669. }
  31670. if (ALLOWED_TAGS.table) {
  31671. addToSet(ALLOWED_TAGS, ["tbody"]);
  31672. delete FORBID_TAGS.tbody;
  31673. }
  31674. if (freeze) {
  31675. freeze(cfg);
  31676. }
  31677. CONFIG = cfg;
  31678. };
  31679. var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
  31680. "mi",
  31681. "mo",
  31682. "mn",
  31683. "ms",
  31684. "mtext"
  31685. ]);
  31686. var HTML_INTEGRATION_POINTS = addToSet({}, [
  31687. "foreignobject",
  31688. "desc",
  31689. "title",
  31690. "annotation-xml"
  31691. ]);
  31692. var COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
  31693. "title",
  31694. "style",
  31695. "font",
  31696. "a",
  31697. "script"
  31698. ]);
  31699. var ALL_SVG_TAGS = addToSet({}, svg$1);
  31700. addToSet(ALL_SVG_TAGS, svgFilters);
  31701. addToSet(ALL_SVG_TAGS, svgDisallowed);
  31702. var ALL_MATHML_TAGS = addToSet({}, mathMl$1);
  31703. addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
  31704. var _checkValidNamespace = function _checkValidNamespace2(element2) {
  31705. var parent2 = getParentNode(element2);
  31706. if (!parent2 || !parent2.tagName) {
  31707. parent2 = {
  31708. namespaceURI: HTML_NAMESPACE,
  31709. tagName: "template"
  31710. };
  31711. }
  31712. var tagName = stringToLowerCase(element2.tagName);
  31713. var parentTagName = stringToLowerCase(parent2.tagName);
  31714. if (element2.namespaceURI === SVG_NAMESPACE) {
  31715. if (parent2.namespaceURI === HTML_NAMESPACE) {
  31716. return tagName === "svg";
  31717. }
  31718. if (parent2.namespaceURI === MATHML_NAMESPACE) {
  31719. return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
  31720. }
  31721. return Boolean(ALL_SVG_TAGS[tagName]);
  31722. }
  31723. if (element2.namespaceURI === MATHML_NAMESPACE) {
  31724. if (parent2.namespaceURI === HTML_NAMESPACE) {
  31725. return tagName === "math";
  31726. }
  31727. if (parent2.namespaceURI === SVG_NAMESPACE) {
  31728. return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
  31729. }
  31730. return Boolean(ALL_MATHML_TAGS[tagName]);
  31731. }
  31732. if (element2.namespaceURI === HTML_NAMESPACE) {
  31733. if (parent2.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
  31734. return false;
  31735. }
  31736. if (parent2.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
  31737. return false;
  31738. }
  31739. return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
  31740. }
  31741. return false;
  31742. };
  31743. var _forceRemove = function _forceRemove2(node) {
  31744. arrayPush(DOMPurify.removed, { element: node });
  31745. try {
  31746. node.parentNode.removeChild(node);
  31747. } catch (_) {
  31748. try {
  31749. node.outerHTML = emptyHTML;
  31750. } catch (_2) {
  31751. node.remove();
  31752. }
  31753. }
  31754. };
  31755. var _removeAttribute = function _removeAttribute2(name2, node) {
  31756. try {
  31757. arrayPush(DOMPurify.removed, {
  31758. attribute: node.getAttributeNode(name2),
  31759. from: node
  31760. });
  31761. } catch (_) {
  31762. arrayPush(DOMPurify.removed, {
  31763. attribute: null,
  31764. from: node
  31765. });
  31766. }
  31767. node.removeAttribute(name2);
  31768. if (name2 === "is" && !ALLOWED_ATTR[name2]) {
  31769. if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
  31770. try {
  31771. _forceRemove(node);
  31772. } catch (_) {
  31773. }
  31774. } else {
  31775. try {
  31776. node.setAttribute(name2, "");
  31777. } catch (_) {
  31778. }
  31779. }
  31780. }
  31781. };
  31782. var _initDocument = function _initDocument2(dirty) {
  31783. var doc;
  31784. var leadingWhitespace;
  31785. if (FORCE_BODY) {
  31786. dirty = "<remove></remove>" + dirty;
  31787. } else {
  31788. var matches = stringMatch(dirty, /^[\r\n\t ]+/);
  31789. leadingWhitespace = matches && matches[0];
  31790. }
  31791. if (PARSER_MEDIA_TYPE === "application/xhtml+xml") {
  31792. dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
  31793. }
  31794. var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
  31795. if (NAMESPACE === HTML_NAMESPACE) {
  31796. try {
  31797. doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
  31798. } catch (_) {
  31799. }
  31800. }
  31801. if (!doc || !doc.documentElement) {
  31802. doc = implementation.createDocument(NAMESPACE, "template", null);
  31803. try {
  31804. doc.documentElement.innerHTML = IS_EMPTY_INPUT ? "" : dirtyPayload;
  31805. } catch (_) {
  31806. }
  31807. }
  31808. var body2 = doc.body || doc.documentElement;
  31809. if (dirty && leadingWhitespace) {
  31810. body2.insertBefore(document2.createTextNode(leadingWhitespace), body2.childNodes[0] || null);
  31811. }
  31812. if (NAMESPACE === HTML_NAMESPACE) {
  31813. return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
  31814. }
  31815. return WHOLE_DOCUMENT ? doc.documentElement : body2;
  31816. };
  31817. var _createIterator = function _createIterator2(root) {
  31818. return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
  31819. };
  31820. var _isClobbered = function _isClobbered2(elm) {
  31821. return elm instanceof HTMLFormElement && (typeof elm.nodeName !== "string" || typeof elm.textContent !== "string" || typeof elm.removeChild !== "function" || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== "function" || typeof elm.setAttribute !== "function" || typeof elm.namespaceURI !== "string" || typeof elm.insertBefore !== "function");
  31822. };
  31823. var _isNode = function _isNode2(object) {
  31824. return _typeof(Node2) === "object" ? object instanceof Node2 : object && _typeof(object) === "object" && typeof object.nodeType === "number" && typeof object.nodeName === "string";
  31825. };
  31826. var _executeHook = function _executeHook2(entryPoint, currentNode, data) {
  31827. if (!hooks[entryPoint]) {
  31828. return;
  31829. }
  31830. arrayForEach(hooks[entryPoint], function(hook) {
  31831. hook.call(DOMPurify, currentNode, data, CONFIG);
  31832. });
  31833. };
  31834. var _sanitizeElements = function _sanitizeElements2(currentNode) {
  31835. var content;
  31836. _executeHook("beforeSanitizeElements", currentNode, null);
  31837. if (_isClobbered(currentNode)) {
  31838. _forceRemove(currentNode);
  31839. return true;
  31840. }
  31841. if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
  31842. _forceRemove(currentNode);
  31843. return true;
  31844. }
  31845. var tagName = transformCaseFunc(currentNode.nodeName);
  31846. _executeHook("uponSanitizeElement", currentNode, {
  31847. tagName,
  31848. allowedTags: ALLOWED_TAGS
  31849. });
  31850. if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
  31851. _forceRemove(currentNode);
  31852. return true;
  31853. }
  31854. if (tagName === "select" && regExpTest(/<template/i, currentNode.innerHTML)) {
  31855. _forceRemove(currentNode);
  31856. return true;
  31857. }
  31858. if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
  31859. if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
  31860. if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName))
  31861. return false;
  31862. if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName))
  31863. return false;
  31864. }
  31865. if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
  31866. var parentNode2 = getParentNode(currentNode) || currentNode.parentNode;
  31867. var childNodes = getChildNodes(currentNode) || currentNode.childNodes;
  31868. if (childNodes && parentNode2) {
  31869. var childCount = childNodes.length;
  31870. for (var i = childCount - 1; i >= 0; --i) {
  31871. parentNode2.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
  31872. }
  31873. }
  31874. }
  31875. _forceRemove(currentNode);
  31876. return true;
  31877. }
  31878. if (currentNode instanceof Element2 && !_checkValidNamespace(currentNode)) {
  31879. _forceRemove(currentNode);
  31880. return true;
  31881. }
  31882. if ((tagName === "noscript" || tagName === "noembed") && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
  31883. _forceRemove(currentNode);
  31884. return true;
  31885. }
  31886. if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
  31887. content = currentNode.textContent;
  31888. content = stringReplace(content, MUSTACHE_EXPR$1, " ");
  31889. content = stringReplace(content, ERB_EXPR$1, " ");
  31890. if (currentNode.textContent !== content) {
  31891. arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
  31892. currentNode.textContent = content;
  31893. }
  31894. }
  31895. _executeHook("afterSanitizeElements", currentNode, null);
  31896. return false;
  31897. };
  31898. var _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value2) {
  31899. if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value2 in document2 || value2 in formElement)) {
  31900. return false;
  31901. }
  31902. if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$1, lcName))
  31903. ;
  31904. else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName))
  31905. ;
  31906. else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
  31907. if (_basicCustomElementTest(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value2) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value2)))
  31908. ;
  31909. else {
  31910. return false;
  31911. }
  31912. } else if (URI_SAFE_ATTRIBUTES[lcName])
  31913. ;
  31914. else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value2, ATTR_WHITESPACE$1, "")))
  31915. ;
  31916. else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value2, "data:") === 0 && DATA_URI_TAGS[lcTag])
  31917. ;
  31918. else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value2, ATTR_WHITESPACE$1, "")))
  31919. ;
  31920. else if (!value2)
  31921. ;
  31922. else {
  31923. return false;
  31924. }
  31925. return true;
  31926. };
  31927. var _basicCustomElementTest = function _basicCustomElementTest2(tagName) {
  31928. return tagName.indexOf("-") > 0;
  31929. };
  31930. var _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
  31931. var attr;
  31932. var value2;
  31933. var lcName;
  31934. var l2;
  31935. _executeHook("beforeSanitizeAttributes", currentNode, null);
  31936. var attributes = currentNode.attributes;
  31937. if (!attributes) {
  31938. return;
  31939. }
  31940. var hookEvent = {
  31941. attrName: "",
  31942. attrValue: "",
  31943. keepAttr: true,
  31944. allowedAttributes: ALLOWED_ATTR
  31945. };
  31946. l2 = attributes.length;
  31947. while (l2--) {
  31948. attr = attributes[l2];
  31949. var _attr = attr, name2 = _attr.name, namespaceURI = _attr.namespaceURI;
  31950. value2 = name2 === "value" ? attr.value : stringTrim(attr.value);
  31951. lcName = transformCaseFunc(name2);
  31952. hookEvent.attrName = lcName;
  31953. hookEvent.attrValue = value2;
  31954. hookEvent.keepAttr = true;
  31955. hookEvent.forceKeepAttr = void 0;
  31956. _executeHook("uponSanitizeAttribute", currentNode, hookEvent);
  31957. value2 = hookEvent.attrValue;
  31958. if (hookEvent.forceKeepAttr) {
  31959. continue;
  31960. }
  31961. _removeAttribute(name2, currentNode);
  31962. if (!hookEvent.keepAttr) {
  31963. continue;
  31964. }
  31965. if (regExpTest(/\/>/i, value2)) {
  31966. _removeAttribute(name2, currentNode);
  31967. continue;
  31968. }
  31969. if (SAFE_FOR_TEMPLATES) {
  31970. value2 = stringReplace(value2, MUSTACHE_EXPR$1, " ");
  31971. value2 = stringReplace(value2, ERB_EXPR$1, " ");
  31972. }
  31973. var lcTag = transformCaseFunc(currentNode.nodeName);
  31974. if (!_isValidAttribute(lcTag, lcName, value2)) {
  31975. continue;
  31976. }
  31977. try {
  31978. if (namespaceURI) {
  31979. currentNode.setAttributeNS(namespaceURI, name2, value2);
  31980. } else {
  31981. currentNode.setAttribute(name2, value2);
  31982. }
  31983. arrayPop(DOMPurify.removed);
  31984. } catch (_) {
  31985. }
  31986. }
  31987. _executeHook("afterSanitizeAttributes", currentNode, null);
  31988. };
  31989. var _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
  31990. var shadowNode;
  31991. var shadowIterator = _createIterator(fragment);
  31992. _executeHook("beforeSanitizeShadowDOM", fragment, null);
  31993. while (shadowNode = shadowIterator.nextNode()) {
  31994. _executeHook("uponSanitizeShadowNode", shadowNode, null);
  31995. if (_sanitizeElements(shadowNode)) {
  31996. continue;
  31997. }
  31998. if (shadowNode.content instanceof DocumentFragment) {
  31999. _sanitizeShadowDOM2(shadowNode.content);
  32000. }
  32001. _sanitizeAttributes(shadowNode);
  32002. }
  32003. _executeHook("afterSanitizeShadowDOM", fragment, null);
  32004. };
  32005. DOMPurify.sanitize = function(dirty, cfg) {
  32006. var body2;
  32007. var importedNode;
  32008. var currentNode;
  32009. var oldNode;
  32010. var returnNode;
  32011. IS_EMPTY_INPUT = !dirty;
  32012. if (IS_EMPTY_INPUT) {
  32013. dirty = "<!-->";
  32014. }
  32015. if (typeof dirty !== "string" && !_isNode(dirty)) {
  32016. if (typeof dirty.toString !== "function") {
  32017. throw typeErrorCreate("toString is not a function");
  32018. } else {
  32019. dirty = dirty.toString();
  32020. if (typeof dirty !== "string") {
  32021. throw typeErrorCreate("dirty is not a string, aborting");
  32022. }
  32023. }
  32024. }
  32025. if (!DOMPurify.isSupported) {
  32026. if (_typeof(window2.toStaticHTML) === "object" || typeof window2.toStaticHTML === "function") {
  32027. if (typeof dirty === "string") {
  32028. return window2.toStaticHTML(dirty);
  32029. }
  32030. if (_isNode(dirty)) {
  32031. return window2.toStaticHTML(dirty.outerHTML);
  32032. }
  32033. }
  32034. return dirty;
  32035. }
  32036. if (!SET_CONFIG) {
  32037. _parseConfig(cfg);
  32038. }
  32039. DOMPurify.removed = [];
  32040. if (typeof dirty === "string") {
  32041. IN_PLACE = false;
  32042. }
  32043. if (IN_PLACE) {
  32044. if (dirty.nodeName) {
  32045. var tagName = transformCaseFunc(dirty.nodeName);
  32046. if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
  32047. throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
  32048. }
  32049. }
  32050. } else if (dirty instanceof Node2) {
  32051. body2 = _initDocument("<!---->");
  32052. importedNode = body2.ownerDocument.importNode(dirty, true);
  32053. if (importedNode.nodeType === 1 && importedNode.nodeName === "BODY") {
  32054. body2 = importedNode;
  32055. } else if (importedNode.nodeName === "HTML") {
  32056. body2 = importedNode;
  32057. } else {
  32058. body2.appendChild(importedNode);
  32059. }
  32060. } else {
  32061. if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) {
  32062. return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
  32063. }
  32064. body2 = _initDocument(dirty);
  32065. if (!body2) {
  32066. return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
  32067. }
  32068. }
  32069. if (body2 && FORCE_BODY) {
  32070. _forceRemove(body2.firstChild);
  32071. }
  32072. var nodeIterator = _createIterator(IN_PLACE ? dirty : body2);
  32073. while (currentNode = nodeIterator.nextNode()) {
  32074. if (currentNode.nodeType === 3 && currentNode === oldNode) {
  32075. continue;
  32076. }
  32077. if (_sanitizeElements(currentNode)) {
  32078. continue;
  32079. }
  32080. if (currentNode.content instanceof DocumentFragment) {
  32081. _sanitizeShadowDOM(currentNode.content);
  32082. }
  32083. _sanitizeAttributes(currentNode);
  32084. oldNode = currentNode;
  32085. }
  32086. oldNode = null;
  32087. if (IN_PLACE) {
  32088. return dirty;
  32089. }
  32090. if (RETURN_DOM) {
  32091. if (RETURN_DOM_FRAGMENT) {
  32092. returnNode = createDocumentFragment.call(body2.ownerDocument);
  32093. while (body2.firstChild) {
  32094. returnNode.appendChild(body2.firstChild);
  32095. }
  32096. } else {
  32097. returnNode = body2;
  32098. }
  32099. if (ALLOWED_ATTR.shadowroot) {
  32100. returnNode = importNode.call(originalDocument, returnNode, true);
  32101. }
  32102. return returnNode;
  32103. }
  32104. var serializedHTML = WHOLE_DOCUMENT ? body2.outerHTML : body2.innerHTML;
  32105. if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body2.ownerDocument && body2.ownerDocument.doctype && body2.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body2.ownerDocument.doctype.name)) {
  32106. serializedHTML = "<!DOCTYPE " + body2.ownerDocument.doctype.name + ">\n" + serializedHTML;
  32107. }
  32108. if (SAFE_FOR_TEMPLATES) {
  32109. serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$1, " ");
  32110. serializedHTML = stringReplace(serializedHTML, ERB_EXPR$1, " ");
  32111. }
  32112. return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
  32113. };
  32114. DOMPurify.setConfig = function(cfg) {
  32115. _parseConfig(cfg);
  32116. SET_CONFIG = true;
  32117. };
  32118. DOMPurify.clearConfig = function() {
  32119. CONFIG = null;
  32120. SET_CONFIG = false;
  32121. };
  32122. DOMPurify.isValidAttribute = function(tag, attr, value2) {
  32123. if (!CONFIG) {
  32124. _parseConfig({});
  32125. }
  32126. var lcTag = transformCaseFunc(tag);
  32127. var lcName = transformCaseFunc(attr);
  32128. return _isValidAttribute(lcTag, lcName, value2);
  32129. };
  32130. DOMPurify.addHook = function(entryPoint, hookFunction) {
  32131. if (typeof hookFunction !== "function") {
  32132. return;
  32133. }
  32134. hooks[entryPoint] = hooks[entryPoint] || [];
  32135. arrayPush(hooks[entryPoint], hookFunction);
  32136. };
  32137. DOMPurify.removeHook = function(entryPoint) {
  32138. if (hooks[entryPoint]) {
  32139. return arrayPop(hooks[entryPoint]);
  32140. }
  32141. };
  32142. DOMPurify.removeHooks = function(entryPoint) {
  32143. if (hooks[entryPoint]) {
  32144. hooks[entryPoint] = [];
  32145. }
  32146. };
  32147. DOMPurify.removeAllHooks = function() {
  32148. hooks = {};
  32149. };
  32150. return DOMPurify;
  32151. }
  32152. var purify = createDOMPurify();
  32153. var sanitizeHtmlString = function(html2) {
  32154. return purify().sanitize(html2);
  32155. };
  32156. var isTouch = global$9.deviceType.isTouch();
  32157. var hiddenHeader = function(title, close2) {
  32158. return {
  32159. dom: {
  32160. tag: "div",
  32161. styles: { display: "none" },
  32162. classes: ["tox-dialog__header"]
  32163. },
  32164. components: [
  32165. title,
  32166. close2
  32167. ]
  32168. };
  32169. };
  32170. var pClose = function(onClose, providersBackstage) {
  32171. return ModalDialog.parts.close(Button.sketch({
  32172. dom: {
  32173. tag: "button",
  32174. classes: [
  32175. "tox-button",
  32176. "tox-button--icon",
  32177. "tox-button--naked"
  32178. ],
  32179. attributes: {
  32180. "type": "button",
  32181. "aria-label": providersBackstage.translate("Close")
  32182. }
  32183. },
  32184. action: onClose,
  32185. buttonBehaviours: derive$1([Tabstopping.config({})])
  32186. }));
  32187. };
  32188. var pUntitled = function() {
  32189. return ModalDialog.parts.title({
  32190. dom: {
  32191. tag: "div",
  32192. classes: ["tox-dialog__title"],
  32193. innerHtml: "",
  32194. styles: { display: "none" }
  32195. }
  32196. });
  32197. };
  32198. var pBodyMessage = function(message, providersBackstage) {
  32199. return ModalDialog.parts.body({
  32200. dom: {
  32201. tag: "div",
  32202. classes: ["tox-dialog__body"]
  32203. },
  32204. components: [{
  32205. dom: {
  32206. tag: "div",
  32207. classes: ["tox-dialog__body-content"]
  32208. },
  32209. components: [{ dom: fromHtml("<p>" + sanitizeHtmlString(providersBackstage.translate(message)) + "</p>") }]
  32210. }]
  32211. });
  32212. };
  32213. var pFooter = function(buttons) {
  32214. return ModalDialog.parts.footer({
  32215. dom: {
  32216. tag: "div",
  32217. classes: ["tox-dialog__footer"]
  32218. },
  32219. components: buttons
  32220. });
  32221. };
  32222. var pFooterGroup = function(startButtons, endButtons) {
  32223. return [
  32224. Container.sketch({
  32225. dom: {
  32226. tag: "div",
  32227. classes: ["tox-dialog__footer-start"]
  32228. },
  32229. components: startButtons
  32230. }),
  32231. Container.sketch({
  32232. dom: {
  32233. tag: "div",
  32234. classes: ["tox-dialog__footer-end"]
  32235. },
  32236. components: endButtons
  32237. })
  32238. ];
  32239. };
  32240. var renderDialog$1 = function(spec) {
  32241. var _a2;
  32242. var dialogClass = "tox-dialog";
  32243. var blockerClass = dialogClass + "-wrap";
  32244. var blockerBackdropClass = blockerClass + "__backdrop";
  32245. var scrollLockClass = dialogClass + "__disable-scroll";
  32246. return ModalDialog.sketch({
  32247. lazySink: spec.lazySink,
  32248. onEscape: function(comp) {
  32249. spec.onEscape(comp);
  32250. return Optional.some(true);
  32251. },
  32252. useTabstopAt: function(elem) {
  32253. return !isPseudoStop(elem);
  32254. },
  32255. dom: {
  32256. tag: "div",
  32257. classes: [dialogClass].concat(spec.extraClasses),
  32258. styles: __assign({ position: "relative" }, spec.extraStyles)
  32259. },
  32260. components: __spreadArray([
  32261. spec.header,
  32262. spec.body
  32263. ], spec.footer.toArray(), true),
  32264. parts: {
  32265. blocker: {
  32266. dom: fromHtml('<div class="' + blockerClass + '"></div>'),
  32267. components: [{
  32268. dom: {
  32269. tag: "div",
  32270. classes: isTouch ? [
  32271. blockerBackdropClass,
  32272. blockerBackdropClass + "--opaque"
  32273. ] : [blockerBackdropClass]
  32274. }
  32275. }]
  32276. }
  32277. },
  32278. dragBlockClass: blockerClass,
  32279. modalBehaviours: derive$1(__spreadArray([
  32280. Focusing.config({}),
  32281. config("dialog-events", spec.dialogEvents.concat([runOnSource(focusin(), function(comp, _se) {
  32282. Keying.focusIn(comp);
  32283. })])),
  32284. config("scroll-lock", [
  32285. runOnAttached(function() {
  32286. add$2(body(), scrollLockClass);
  32287. }),
  32288. runOnDetached(function() {
  32289. remove$2(body(), scrollLockClass);
  32290. })
  32291. ])
  32292. ], spec.extraBehaviours, true)),
  32293. eventOrder: __assign((_a2 = {}, _a2[execute$5()] = ["dialog-events"], _a2[attachedToDom()] = [
  32294. "scroll-lock",
  32295. "dialog-events",
  32296. "alloy.base.behaviour"
  32297. ], _a2[detachedFromDom()] = [
  32298. "alloy.base.behaviour",
  32299. "dialog-events",
  32300. "scroll-lock"
  32301. ], _a2), spec.eventOrder)
  32302. });
  32303. };
  32304. var renderClose = function(providersBackstage) {
  32305. return Button.sketch({
  32306. dom: {
  32307. tag: "button",
  32308. classes: [
  32309. "tox-button",
  32310. "tox-button--icon",
  32311. "tox-button--naked"
  32312. ],
  32313. attributes: {
  32314. "type": "button",
  32315. "aria-label": providersBackstage.translate("Close"),
  32316. "title": providersBackstage.translate("Close")
  32317. }
  32318. },
  32319. components: [render$3("close", {
  32320. tag: "div",
  32321. classes: ["tox-icon"]
  32322. }, providersBackstage.icons)],
  32323. action: function(comp) {
  32324. emit(comp, formCancelEvent);
  32325. }
  32326. });
  32327. };
  32328. var renderTitle = function(spec, id, providersBackstage) {
  32329. var renderComponents2 = function(data) {
  32330. return [text$1(providersBackstage.translate(data.title))];
  32331. };
  32332. return {
  32333. dom: {
  32334. tag: "div",
  32335. classes: ["tox-dialog__title"],
  32336. attributes: __assign({}, id.map(function(x) {
  32337. return { id: x };
  32338. }).getOr({}))
  32339. },
  32340. components: renderComponents2(spec),
  32341. behaviours: derive$1([Reflecting.config({
  32342. channel: titleChannel,
  32343. renderComponents: renderComponents2
  32344. })])
  32345. };
  32346. };
  32347. var renderDragHandle = function() {
  32348. return { dom: fromHtml('<div class="tox-dialog__draghandle"></div>') };
  32349. };
  32350. var renderInlineHeader = function(spec, titleId, providersBackstage) {
  32351. return Container.sketch({
  32352. dom: fromHtml('<div class="tox-dialog__header"></div>'),
  32353. components: [
  32354. renderTitle(spec, Optional.some(titleId), providersBackstage),
  32355. renderDragHandle(),
  32356. renderClose(providersBackstage)
  32357. ],
  32358. containerBehaviours: derive$1([Dragging.config({
  32359. mode: "mouse",
  32360. blockerClass: "blocker",
  32361. getTarget: function(handle2) {
  32362. return closest$1(handle2, '[role="dialog"]').getOrDie();
  32363. },
  32364. snaps: {
  32365. getSnapPoints: function() {
  32366. return [];
  32367. },
  32368. leftAttr: "data-drag-left",
  32369. topAttr: "data-drag-top"
  32370. }
  32371. })])
  32372. });
  32373. };
  32374. var renderModalHeader = function(spec, providersBackstage) {
  32375. var pTitle = ModalDialog.parts.title(renderTitle(spec, Optional.none(), providersBackstage));
  32376. var pHandle = ModalDialog.parts.draghandle(renderDragHandle());
  32377. var pClose2 = ModalDialog.parts.close(renderClose(providersBackstage));
  32378. var components2 = [pTitle].concat(spec.draggable ? [pHandle] : []).concat([pClose2]);
  32379. return Container.sketch({
  32380. dom: fromHtml('<div class="tox-dialog__header"></div>'),
  32381. components: components2
  32382. });
  32383. };
  32384. var getHeader = function(title, backstage) {
  32385. return renderModalHeader({
  32386. title: backstage.shared.providers.translate(title),
  32387. draggable: backstage.dialog.isDraggableModal()
  32388. }, backstage.shared.providers);
  32389. };
  32390. var getBusySpec = function(message, bs, providers) {
  32391. return {
  32392. dom: {
  32393. tag: "div",
  32394. classes: ["tox-dialog__busy-spinner"],
  32395. attributes: { "aria-label": providers.translate(message) },
  32396. styles: {
  32397. left: "0px",
  32398. right: "0px",
  32399. bottom: "0px",
  32400. top: "0px",
  32401. position: "absolute"
  32402. }
  32403. },
  32404. behaviours: bs,
  32405. components: [{ dom: fromHtml('<div class="tox-spinner"><div></div><div></div><div></div></div>') }]
  32406. };
  32407. };
  32408. var getEventExtras = function(lazyDialog, providers, extra) {
  32409. return {
  32410. onClose: function() {
  32411. return extra.closeWindow();
  32412. },
  32413. onBlock: function(blockEvent) {
  32414. ModalDialog.setBusy(lazyDialog(), function(_comp, bs) {
  32415. return getBusySpec(blockEvent.message, bs, providers);
  32416. });
  32417. },
  32418. onUnblock: function() {
  32419. ModalDialog.setIdle(lazyDialog());
  32420. }
  32421. };
  32422. };
  32423. var renderModalDialog = function(spec, initialData, dialogEvents, backstage) {
  32424. var _a2;
  32425. var updateState = function(_comp, incoming) {
  32426. return Optional.some(incoming);
  32427. };
  32428. return build$1(renderDialog$1(__assign(__assign({}, spec), {
  32429. lazySink: backstage.shared.getSink,
  32430. extraBehaviours: __spreadArray([
  32431. Reflecting.config({
  32432. channel: dialogChannel,
  32433. updateState,
  32434. initialData
  32435. }),
  32436. RepresentingConfigs.memory({})
  32437. ], spec.extraBehaviours, true),
  32438. onEscape: function(comp) {
  32439. emit(comp, formCancelEvent);
  32440. },
  32441. dialogEvents,
  32442. eventOrder: (_a2 = {}, _a2[receive()] = [
  32443. Reflecting.name(),
  32444. Receiving.name()
  32445. ], _a2[attachedToDom()] = [
  32446. "scroll-lock",
  32447. Reflecting.name(),
  32448. "messages",
  32449. "dialog-events",
  32450. "alloy.base.behaviour"
  32451. ], _a2[detachedFromDom()] = [
  32452. "alloy.base.behaviour",
  32453. "dialog-events",
  32454. "messages",
  32455. Reflecting.name(),
  32456. "scroll-lock"
  32457. ], _a2)
  32458. })));
  32459. };
  32460. var mapMenuButtons = function(buttons) {
  32461. var mapItems = function(button2) {
  32462. var items = map$2(button2.items, function(item2) {
  32463. var cell = Cell(false);
  32464. return __assign(__assign({}, item2), { storage: cell });
  32465. });
  32466. return __assign(__assign({}, button2), { items });
  32467. };
  32468. return map$2(buttons, function(button2) {
  32469. if (button2.type === "menu") {
  32470. return mapItems(button2);
  32471. }
  32472. return button2;
  32473. });
  32474. };
  32475. var extractCellsToObject = function(buttons) {
  32476. return foldl(buttons, function(acc, button2) {
  32477. if (button2.type === "menu") {
  32478. var menuButton = button2;
  32479. return foldl(menuButton.items, function(innerAcc, item2) {
  32480. innerAcc[item2.name] = item2.storage;
  32481. return innerAcc;
  32482. }, acc);
  32483. }
  32484. return acc;
  32485. }, {});
  32486. };
  32487. var initCommonEvents = function(fireApiEvent, extras) {
  32488. return [
  32489. runWithTarget(focusin(), onFocus),
  32490. fireApiEvent(formCloseEvent, function(_api, spec) {
  32491. extras.onClose();
  32492. spec.onClose();
  32493. }),
  32494. fireApiEvent(formCancelEvent, function(api2, spec, _event, self2) {
  32495. spec.onCancel(api2);
  32496. emit(self2, formCloseEvent);
  32497. }),
  32498. run$1(formUnblockEvent, function(_c, _se) {
  32499. return extras.onUnblock();
  32500. }),
  32501. run$1(formBlockEvent, function(_c, se) {
  32502. return extras.onBlock(se.event);
  32503. })
  32504. ];
  32505. };
  32506. var initUrlDialog = function(getInstanceApi, extras) {
  32507. var fireApiEvent = function(eventName, f) {
  32508. return run$1(eventName, function(c, se) {
  32509. withSpec(c, function(spec, _c) {
  32510. f(getInstanceApi(), spec, se.event, c);
  32511. });
  32512. });
  32513. };
  32514. var withSpec = function(c, f) {
  32515. Reflecting.getState(c).get().each(function(currentDialog) {
  32516. f(currentDialog, c);
  32517. });
  32518. };
  32519. return __spreadArray(__spreadArray([], initCommonEvents(fireApiEvent, extras), true), [fireApiEvent(formActionEvent, function(api2, spec, event) {
  32520. spec.onAction(api2, { name: event.name });
  32521. })], false);
  32522. };
  32523. var initDialog = function(getInstanceApi, extras, getSink2) {
  32524. var fireApiEvent = function(eventName, f) {
  32525. return run$1(eventName, function(c, se) {
  32526. withSpec(c, function(spec, _c) {
  32527. f(getInstanceApi(), spec, se.event, c);
  32528. });
  32529. });
  32530. };
  32531. var withSpec = function(c, f) {
  32532. Reflecting.getState(c).get().each(function(currentDialogInit) {
  32533. f(currentDialogInit.internalDialog, c);
  32534. });
  32535. };
  32536. return __spreadArray(__spreadArray([], initCommonEvents(fireApiEvent, extras), true), [
  32537. fireApiEvent(formSubmitEvent, function(api2, spec) {
  32538. return spec.onSubmit(api2);
  32539. }),
  32540. fireApiEvent(formChangeEvent, function(api2, spec, event) {
  32541. spec.onChange(api2, { name: event.name });
  32542. }),
  32543. fireApiEvent(formActionEvent, function(api2, spec, event, component) {
  32544. var focusIn2 = function() {
  32545. return Keying.focusIn(component);
  32546. };
  32547. var isDisabled2 = function(focused) {
  32548. return has$1(focused, "disabled") || getOpt(focused, "aria-disabled").exists(function(val) {
  32549. return val === "true";
  32550. });
  32551. };
  32552. var rootNode = getRootNode(component.element);
  32553. var current = active(rootNode);
  32554. spec.onAction(api2, {
  32555. name: event.name,
  32556. value: event.value
  32557. });
  32558. active(rootNode).fold(focusIn2, function(focused) {
  32559. if (isDisabled2(focused)) {
  32560. focusIn2();
  32561. } else if (current.exists(function(cur) {
  32562. return contains(focused, cur) && isDisabled2(cur);
  32563. })) {
  32564. focusIn2();
  32565. } else {
  32566. getSink2().toOptional().filter(function(sink) {
  32567. return !contains(sink.element, focused);
  32568. }).each(focusIn2);
  32569. }
  32570. });
  32571. }),
  32572. fireApiEvent(formTabChangeEvent, function(api2, spec, event) {
  32573. spec.onTabChange(api2, {
  32574. newTabName: event.name,
  32575. oldTabName: event.oldName
  32576. });
  32577. }),
  32578. runOnDetached(function(component) {
  32579. var api2 = getInstanceApi();
  32580. Representing.setValue(component, api2.getData());
  32581. })
  32582. ], false);
  32583. };
  32584. var SilverDialogEvents = {
  32585. initUrlDialog,
  32586. initDialog
  32587. };
  32588. var makeButton = function(button2, backstage) {
  32589. return renderFooterButton(button2, button2.type, backstage);
  32590. };
  32591. var lookup = function(compInSystem, footerButtons, buttonName) {
  32592. return find$5(footerButtons, function(button2) {
  32593. return button2.name === buttonName;
  32594. }).bind(function(memButton) {
  32595. return memButton.memento.getOpt(compInSystem);
  32596. });
  32597. };
  32598. var renderComponents = function(_data, state) {
  32599. var footerButtons = state.map(function(s) {
  32600. return s.footerButtons;
  32601. }).getOr([]);
  32602. var buttonGroups = partition$3(footerButtons, function(button2) {
  32603. return button2.align === "start";
  32604. });
  32605. var makeGroup = function(edge2, buttons) {
  32606. return Container.sketch({
  32607. dom: {
  32608. tag: "div",
  32609. classes: ["tox-dialog__footer-" + edge2]
  32610. },
  32611. components: map$2(buttons, function(button2) {
  32612. return button2.memento.asSpec();
  32613. })
  32614. });
  32615. };
  32616. var startButtons = makeGroup("start", buttonGroups.pass);
  32617. var endButtons = makeGroup("end", buttonGroups.fail);
  32618. return [
  32619. startButtons,
  32620. endButtons
  32621. ];
  32622. };
  32623. var renderFooter = function(initSpec, backstage) {
  32624. var updateState = function(_comp, data) {
  32625. var footerButtons = map$2(data.buttons, function(button2) {
  32626. var memButton = record(makeButton(button2, backstage));
  32627. return {
  32628. name: button2.name,
  32629. align: button2.align,
  32630. memento: memButton
  32631. };
  32632. });
  32633. var lookupByName = function(compInSystem, buttonName) {
  32634. return lookup(compInSystem, footerButtons, buttonName);
  32635. };
  32636. return Optional.some({
  32637. lookupByName,
  32638. footerButtons
  32639. });
  32640. };
  32641. return {
  32642. dom: fromHtml('<div class="tox-dialog__footer"></div>'),
  32643. components: [],
  32644. behaviours: derive$1([Reflecting.config({
  32645. channel: footerChannel,
  32646. initialData: initSpec,
  32647. updateState,
  32648. renderComponents
  32649. })])
  32650. };
  32651. };
  32652. var renderInlineFooter = function(initSpec, backstage) {
  32653. return renderFooter(initSpec, backstage);
  32654. };
  32655. var renderModalFooter = function(initSpec, backstage) {
  32656. return ModalDialog.parts.footer(renderFooter(initSpec, backstage));
  32657. };
  32658. var getCompByName = function(access, name2) {
  32659. var root = access.getRoot();
  32660. if (root.getSystem().isConnected()) {
  32661. var form_1 = Composing.getCurrent(access.getFormWrapper()).getOr(access.getFormWrapper());
  32662. return Form.getField(form_1, name2).fold(function() {
  32663. var footer = access.getFooter();
  32664. var footerState = Reflecting.getState(footer);
  32665. return footerState.get().bind(function(f) {
  32666. return f.lookupByName(form_1, name2);
  32667. });
  32668. }, function(comp) {
  32669. return Optional.some(comp);
  32670. });
  32671. } else {
  32672. return Optional.none();
  32673. }
  32674. };
  32675. var validateData$1 = function(access, data) {
  32676. var root = access.getRoot();
  32677. return Reflecting.getState(root).get().map(function(dialogState) {
  32678. return getOrDie(asRaw("data", dialogState.dataValidator, data));
  32679. }).getOr(data);
  32680. };
  32681. var getDialogApi = function(access, doRedial, menuItemStates) {
  32682. var withRoot = function(f) {
  32683. var root = access.getRoot();
  32684. if (root.getSystem().isConnected()) {
  32685. f(root);
  32686. }
  32687. };
  32688. var getData2 = function() {
  32689. var root = access.getRoot();
  32690. var valueComp = root.getSystem().isConnected() ? access.getFormWrapper() : root;
  32691. var representedValues = Representing.getValue(valueComp);
  32692. var menuItemCurrentState = map$1(menuItemStates, function(cell) {
  32693. return cell.get();
  32694. });
  32695. return __assign(__assign({}, representedValues), menuItemCurrentState);
  32696. };
  32697. var setData = function(newData) {
  32698. withRoot(function(_) {
  32699. var prevData = instanceApi.getData();
  32700. var mergedData = __assign(__assign({}, prevData), newData);
  32701. var newInternalData = validateData$1(access, mergedData);
  32702. var form = access.getFormWrapper();
  32703. Representing.setValue(form, newInternalData);
  32704. each(menuItemStates, function(v, k) {
  32705. if (has$2(mergedData, k)) {
  32706. v.set(mergedData[k]);
  32707. }
  32708. });
  32709. });
  32710. };
  32711. var disable2 = function(name2) {
  32712. getCompByName(access, name2).each(Disabling.disable);
  32713. };
  32714. var enable2 = function(name2) {
  32715. getCompByName(access, name2).each(Disabling.enable);
  32716. };
  32717. var focus2 = function(name2) {
  32718. getCompByName(access, name2).each(Focusing.focus);
  32719. };
  32720. var block2 = function(message) {
  32721. if (!isString(message)) {
  32722. throw new Error("The dialogInstanceAPI.block function should be passed a blocking message of type string as an argument");
  32723. }
  32724. withRoot(function(root) {
  32725. emitWith(root, formBlockEvent, { message });
  32726. });
  32727. };
  32728. var unblock2 = function() {
  32729. withRoot(function(root) {
  32730. emit(root, formUnblockEvent);
  32731. });
  32732. };
  32733. var showTab2 = function(name2) {
  32734. withRoot(function(_) {
  32735. var body2 = access.getBody();
  32736. var bodyState = Reflecting.getState(body2);
  32737. if (bodyState.get().exists(function(b2) {
  32738. return b2.isTabPanel();
  32739. })) {
  32740. Composing.getCurrent(body2).each(function(tabSection) {
  32741. TabSection.showTab(tabSection, name2);
  32742. });
  32743. }
  32744. });
  32745. };
  32746. var redial = function(d) {
  32747. withRoot(function(root) {
  32748. var dialogInit = doRedial(d);
  32749. root.getSystem().broadcastOn([dialogChannel], dialogInit);
  32750. root.getSystem().broadcastOn([titleChannel], dialogInit.internalDialog);
  32751. root.getSystem().broadcastOn([bodyChannel], dialogInit.internalDialog);
  32752. root.getSystem().broadcastOn([footerChannel], dialogInit.internalDialog);
  32753. instanceApi.setData(dialogInit.initialData);
  32754. });
  32755. };
  32756. var close2 = function() {
  32757. withRoot(function(root) {
  32758. emit(root, formCloseEvent);
  32759. });
  32760. };
  32761. var instanceApi = {
  32762. getData: getData2,
  32763. setData,
  32764. disable: disable2,
  32765. enable: enable2,
  32766. focus: focus2,
  32767. block: block2,
  32768. unblock: unblock2,
  32769. showTab: showTab2,
  32770. redial,
  32771. close: close2
  32772. };
  32773. return instanceApi;
  32774. };
  32775. var getDialogSizeClasses = function(size) {
  32776. switch (size) {
  32777. case "large":
  32778. return ["tox-dialog--width-lg"];
  32779. case "medium":
  32780. return ["tox-dialog--width-md"];
  32781. default:
  32782. return [];
  32783. }
  32784. };
  32785. var renderDialog = function(dialogInit, extra, backstage) {
  32786. var header = getHeader(dialogInit.internalDialog.title, backstage);
  32787. var body2 = renderModalBody({ body: dialogInit.internalDialog.body }, backstage);
  32788. var storagedMenuButtons = mapMenuButtons(dialogInit.internalDialog.buttons);
  32789. var objOfCells = extractCellsToObject(storagedMenuButtons);
  32790. var footer = renderModalFooter({ buttons: storagedMenuButtons }, backstage);
  32791. var dialogEvents = SilverDialogEvents.initDialog(function() {
  32792. return instanceApi;
  32793. }, getEventExtras(function() {
  32794. return dialog;
  32795. }, backstage.shared.providers, extra), backstage.shared.getSink);
  32796. var dialogSize = getDialogSizeClasses(dialogInit.internalDialog.size);
  32797. var spec = {
  32798. header,
  32799. body: body2,
  32800. footer: Optional.some(footer),
  32801. extraClasses: dialogSize,
  32802. extraBehaviours: [],
  32803. extraStyles: {}
  32804. };
  32805. var dialog = renderModalDialog(spec, dialogInit, dialogEvents, backstage);
  32806. var modalAccess = function() {
  32807. var getForm = function() {
  32808. var outerForm = ModalDialog.getBody(dialog);
  32809. return Composing.getCurrent(outerForm).getOr(outerForm);
  32810. };
  32811. return {
  32812. getRoot: constant$1(dialog),
  32813. getBody: function() {
  32814. return ModalDialog.getBody(dialog);
  32815. },
  32816. getFooter: function() {
  32817. return ModalDialog.getFooter(dialog);
  32818. },
  32819. getFormWrapper: getForm
  32820. };
  32821. }();
  32822. var instanceApi = getDialogApi(modalAccess, extra.redial, objOfCells);
  32823. return {
  32824. dialog,
  32825. instanceApi
  32826. };
  32827. };
  32828. var renderInlineDialog = function(dialogInit, extra, backstage, ariaAttrs) {
  32829. var _a2, _b;
  32830. var dialogLabelId = generate$6("dialog-label");
  32831. var dialogContentId = generate$6("dialog-content");
  32832. var updateState = function(_comp, incoming) {
  32833. return Optional.some(incoming);
  32834. };
  32835. var memHeader = record(renderInlineHeader({
  32836. title: dialogInit.internalDialog.title,
  32837. draggable: true
  32838. }, dialogLabelId, backstage.shared.providers));
  32839. var memBody = record(renderInlineBody({ body: dialogInit.internalDialog.body }, dialogContentId, backstage, ariaAttrs));
  32840. var storagedMenuButtons = mapMenuButtons(dialogInit.internalDialog.buttons);
  32841. var objOfCells = extractCellsToObject(storagedMenuButtons);
  32842. var memFooter = record(renderInlineFooter({ buttons: storagedMenuButtons }, backstage));
  32843. var dialogEvents = SilverDialogEvents.initDialog(function() {
  32844. return instanceApi;
  32845. }, {
  32846. onBlock: function(event) {
  32847. Blocking.block(dialog, function(_comp, bs) {
  32848. return getBusySpec(event.message, bs, backstage.shared.providers);
  32849. });
  32850. },
  32851. onUnblock: function() {
  32852. Blocking.unblock(dialog);
  32853. },
  32854. onClose: function() {
  32855. return extra.closeWindow();
  32856. }
  32857. }, backstage.shared.getSink);
  32858. var dialog = build$1({
  32859. dom: {
  32860. tag: "div",
  32861. classes: [
  32862. "tox-dialog",
  32863. "tox-dialog-inline"
  32864. ],
  32865. attributes: (_a2 = { role: "dialog" }, _a2["aria-labelledby"] = dialogLabelId, _a2["aria-describedby"] = dialogContentId, _a2)
  32866. },
  32867. eventOrder: (_b = {}, _b[receive()] = [
  32868. Reflecting.name(),
  32869. Receiving.name()
  32870. ], _b[execute$5()] = ["execute-on-form"], _b[attachedToDom()] = [
  32871. "reflecting",
  32872. "execute-on-form"
  32873. ], _b),
  32874. behaviours: derive$1([
  32875. Keying.config({
  32876. mode: "cyclic",
  32877. onEscape: function(c) {
  32878. emit(c, formCloseEvent);
  32879. return Optional.some(true);
  32880. },
  32881. useTabstopAt: function(elem) {
  32882. return !isPseudoStop(elem) && (name$2(elem) !== "button" || get$d(elem, "disabled") !== "disabled");
  32883. }
  32884. }),
  32885. Reflecting.config({
  32886. channel: dialogChannel,
  32887. updateState,
  32888. initialData: dialogInit
  32889. }),
  32890. Focusing.config({}),
  32891. config("execute-on-form", dialogEvents.concat([runOnSource(focusin(), function(comp, _se) {
  32892. Keying.focusIn(comp);
  32893. })])),
  32894. Blocking.config({
  32895. getRoot: function() {
  32896. return Optional.some(dialog);
  32897. }
  32898. }),
  32899. Replacing.config({}),
  32900. RepresentingConfigs.memory({})
  32901. ]),
  32902. components: [
  32903. memHeader.asSpec(),
  32904. memBody.asSpec(),
  32905. memFooter.asSpec()
  32906. ]
  32907. });
  32908. var instanceApi = getDialogApi({
  32909. getRoot: constant$1(dialog),
  32910. getFooter: function() {
  32911. return memFooter.get(dialog);
  32912. },
  32913. getBody: function() {
  32914. return memBody.get(dialog);
  32915. },
  32916. getFormWrapper: function() {
  32917. var body2 = memBody.get(dialog);
  32918. return Composing.getCurrent(body2).getOr(body2);
  32919. }
  32920. }, extra.redial, objOfCells);
  32921. return {
  32922. dialog,
  32923. instanceApi
  32924. };
  32925. };
  32926. var global$1 = tinymce.util.Tools.resolve("tinymce.util.URI");
  32927. var getUrlDialogApi = function(root) {
  32928. var withRoot = function(f) {
  32929. if (root.getSystem().isConnected()) {
  32930. f(root);
  32931. }
  32932. };
  32933. var block2 = function(message) {
  32934. if (!isString(message)) {
  32935. throw new Error("The urlDialogInstanceAPI.block function should be passed a blocking message of type string as an argument");
  32936. }
  32937. withRoot(function(root2) {
  32938. emitWith(root2, formBlockEvent, { message });
  32939. });
  32940. };
  32941. var unblock2 = function() {
  32942. withRoot(function(root2) {
  32943. emit(root2, formUnblockEvent);
  32944. });
  32945. };
  32946. var close2 = function() {
  32947. withRoot(function(root2) {
  32948. emit(root2, formCloseEvent);
  32949. });
  32950. };
  32951. var sendMessage = function(data) {
  32952. withRoot(function(root2) {
  32953. root2.getSystem().broadcastOn([bodySendMessageChannel], data);
  32954. });
  32955. };
  32956. return {
  32957. block: block2,
  32958. unblock: unblock2,
  32959. close: close2,
  32960. sendMessage
  32961. };
  32962. };
  32963. var SUPPORTED_MESSAGE_ACTIONS = [
  32964. "insertContent",
  32965. "setContent",
  32966. "execCommand",
  32967. "close",
  32968. "block",
  32969. "unblock"
  32970. ];
  32971. var isSupportedMessage = function(data) {
  32972. return isObject(data) && SUPPORTED_MESSAGE_ACTIONS.indexOf(data.mceAction) !== -1;
  32973. };
  32974. var isCustomMessage = function(data) {
  32975. return !isSupportedMessage(data) && isObject(data) && has$2(data, "mceAction");
  32976. };
  32977. var handleMessage = function(editor, api2, data) {
  32978. switch (data.mceAction) {
  32979. case "insertContent":
  32980. editor.insertContent(data.content);
  32981. break;
  32982. case "setContent":
  32983. editor.setContent(data.content);
  32984. break;
  32985. case "execCommand":
  32986. var ui = isBoolean(data.ui) ? data.ui : false;
  32987. editor.execCommand(data.cmd, ui, data.value);
  32988. break;
  32989. case "close":
  32990. api2.close();
  32991. break;
  32992. case "block":
  32993. api2.block(data.message);
  32994. break;
  32995. case "unblock":
  32996. api2.unblock();
  32997. break;
  32998. }
  32999. };
  33000. var renderUrlDialog = function(internalDialog, extra, editor, backstage) {
  33001. var _a2;
  33002. var header = getHeader(internalDialog.title, backstage);
  33003. var body2 = renderIframeBody(internalDialog);
  33004. var footer = internalDialog.buttons.bind(function(buttons) {
  33005. if (buttons.length === 0) {
  33006. return Optional.none();
  33007. } else {
  33008. return Optional.some(renderModalFooter({ buttons }, backstage));
  33009. }
  33010. });
  33011. var dialogEvents = SilverDialogEvents.initUrlDialog(function() {
  33012. return instanceApi;
  33013. }, getEventExtras(function() {
  33014. return dialog;
  33015. }, backstage.shared.providers, extra));
  33016. var styles = __assign(__assign({}, internalDialog.height.fold(function() {
  33017. return {};
  33018. }, function(height2) {
  33019. return {
  33020. "height": height2 + "px",
  33021. "max-height": height2 + "px"
  33022. };
  33023. })), internalDialog.width.fold(function() {
  33024. return {};
  33025. }, function(width2) {
  33026. return {
  33027. "width": width2 + "px",
  33028. "max-width": width2 + "px"
  33029. };
  33030. }));
  33031. var classes2 = internalDialog.width.isNone() && internalDialog.height.isNone() ? ["tox-dialog--width-lg"] : [];
  33032. var iframeUri = new global$1(internalDialog.url, { base_uri: new global$1(window.location.href) });
  33033. var iframeDomain = iframeUri.protocol + "://" + iframeUri.host + (iframeUri.port ? ":" + iframeUri.port : "");
  33034. var messageHandlerUnbinder = unbindable();
  33035. var extraBehaviours = [
  33036. config("messages", [
  33037. runOnAttached(function() {
  33038. var unbind2 = bind(SugarElement.fromDom(window), "message", function(e) {
  33039. if (iframeUri.isSameOrigin(new global$1(e.raw.origin))) {
  33040. var data = e.raw.data;
  33041. if (isSupportedMessage(data)) {
  33042. handleMessage(editor, instanceApi, data);
  33043. } else if (isCustomMessage(data)) {
  33044. internalDialog.onMessage(instanceApi, data);
  33045. }
  33046. }
  33047. });
  33048. messageHandlerUnbinder.set(unbind2);
  33049. }),
  33050. runOnDetached(messageHandlerUnbinder.clear)
  33051. ]),
  33052. Receiving.config({
  33053. channels: (_a2 = {}, _a2[bodySendMessageChannel] = {
  33054. onReceive: function(comp, data) {
  33055. descendant(comp.element, "iframe").each(function(iframeEle) {
  33056. var iframeWin = iframeEle.dom.contentWindow;
  33057. iframeWin.postMessage(data, iframeDomain);
  33058. });
  33059. }
  33060. }, _a2)
  33061. })
  33062. ];
  33063. var spec = {
  33064. header,
  33065. body: body2,
  33066. footer,
  33067. extraClasses: classes2,
  33068. extraBehaviours,
  33069. extraStyles: styles
  33070. };
  33071. var dialog = renderModalDialog(spec, internalDialog, dialogEvents, backstage);
  33072. var instanceApi = getUrlDialogApi(dialog);
  33073. return {
  33074. dialog,
  33075. instanceApi
  33076. };
  33077. };
  33078. var setup$2 = function(extras) {
  33079. var sharedBackstage = extras.backstage.shared;
  33080. var open2 = function(message, callback) {
  33081. var closeDialog = function() {
  33082. ModalDialog.hide(alertDialog);
  33083. callback();
  33084. };
  33085. var memFooterClose = record(renderFooterButton({
  33086. name: "close-alert",
  33087. text: "OK",
  33088. primary: true,
  33089. align: "end",
  33090. disabled: false,
  33091. icon: Optional.none()
  33092. }, "cancel", extras.backstage));
  33093. var titleSpec = pUntitled();
  33094. var closeSpec = pClose(closeDialog, sharedBackstage.providers);
  33095. var alertDialog = build$1(renderDialog$1({
  33096. lazySink: function() {
  33097. return sharedBackstage.getSink();
  33098. },
  33099. header: hiddenHeader(titleSpec, closeSpec),
  33100. body: pBodyMessage(message, sharedBackstage.providers),
  33101. footer: Optional.some(pFooter(pFooterGroup([], [memFooterClose.asSpec()]))),
  33102. onEscape: closeDialog,
  33103. extraClasses: ["tox-alert-dialog"],
  33104. extraBehaviours: [],
  33105. extraStyles: {},
  33106. dialogEvents: [run$1(formCancelEvent, closeDialog)],
  33107. eventOrder: {}
  33108. }));
  33109. ModalDialog.show(alertDialog);
  33110. var footerCloseButton = memFooterClose.get(alertDialog);
  33111. Focusing.focus(footerCloseButton);
  33112. };
  33113. return { open: open2 };
  33114. };
  33115. var setup$1 = function(extras) {
  33116. var sharedBackstage = extras.backstage.shared;
  33117. var open2 = function(message, callback) {
  33118. var closeDialog = function(state) {
  33119. ModalDialog.hide(confirmDialog);
  33120. callback(state);
  33121. };
  33122. var memFooterYes = record(renderFooterButton({
  33123. name: "yes",
  33124. text: "Yes",
  33125. primary: true,
  33126. align: "end",
  33127. disabled: false,
  33128. icon: Optional.none()
  33129. }, "submit", extras.backstage));
  33130. var footerNo = renderFooterButton({
  33131. name: "no",
  33132. text: "No",
  33133. primary: false,
  33134. align: "end",
  33135. disabled: false,
  33136. icon: Optional.none()
  33137. }, "cancel", extras.backstage);
  33138. var titleSpec = pUntitled();
  33139. var closeSpec = pClose(function() {
  33140. return closeDialog(false);
  33141. }, sharedBackstage.providers);
  33142. var confirmDialog = build$1(renderDialog$1({
  33143. lazySink: function() {
  33144. return sharedBackstage.getSink();
  33145. },
  33146. header: hiddenHeader(titleSpec, closeSpec),
  33147. body: pBodyMessage(message, sharedBackstage.providers),
  33148. footer: Optional.some(pFooter(pFooterGroup([], [
  33149. footerNo,
  33150. memFooterYes.asSpec()
  33151. ]))),
  33152. onEscape: function() {
  33153. return closeDialog(false);
  33154. },
  33155. extraClasses: ["tox-confirm-dialog"],
  33156. extraBehaviours: [],
  33157. extraStyles: {},
  33158. dialogEvents: [
  33159. run$1(formCancelEvent, function() {
  33160. return closeDialog(false);
  33161. }),
  33162. run$1(formSubmitEvent, function() {
  33163. return closeDialog(true);
  33164. })
  33165. ],
  33166. eventOrder: {}
  33167. }));
  33168. ModalDialog.show(confirmDialog);
  33169. var footerYesButton = memFooterYes.get(confirmDialog);
  33170. Focusing.focus(footerYesButton);
  33171. };
  33172. return { open: open2 };
  33173. };
  33174. var validateData = function(data, validator) {
  33175. return getOrDie(asRaw("data", validator, data));
  33176. };
  33177. var isAlertOrConfirmDialog = function(target) {
  33178. return closest(target, ".tox-alert-dialog") || closest(target, ".tox-confirm-dialog");
  33179. };
  33180. var inlineAdditionalBehaviours = function(editor, isStickyToolbar2, isToolbarLocationTop) {
  33181. if (isStickyToolbar2 && isToolbarLocationTop) {
  33182. return [];
  33183. } else {
  33184. return [Docking.config({
  33185. contextual: {
  33186. lazyContext: function() {
  33187. return Optional.some(box$1(SugarElement.fromDom(editor.getContentAreaContainer())));
  33188. },
  33189. fadeInClass: "tox-dialog-dock-fadein",
  33190. fadeOutClass: "tox-dialog-dock-fadeout",
  33191. transitionClass: "tox-dialog-dock-transition"
  33192. },
  33193. modes: ["top"]
  33194. })];
  33195. }
  33196. };
  33197. var setup = function(extras) {
  33198. var backstage = extras.backstage;
  33199. var editor = extras.editor;
  33200. var isStickyToolbar$1 = isStickyToolbar(editor);
  33201. var alertDialog = setup$2(extras);
  33202. var confirmDialog = setup$1(extras);
  33203. var open2 = function(config2, params, closeWindow) {
  33204. if (params !== void 0 && params.inline === "toolbar") {
  33205. return openInlineDialog(config2, backstage.shared.anchors.inlineDialog(), closeWindow, params.ariaAttrs);
  33206. } else if (params !== void 0 && params.inline === "cursor") {
  33207. return openInlineDialog(config2, backstage.shared.anchors.cursor(), closeWindow, params.ariaAttrs);
  33208. } else {
  33209. return openModalDialog(config2, closeWindow);
  33210. }
  33211. };
  33212. var openUrl = function(config2, closeWindow) {
  33213. return openModalUrlDialog(config2, closeWindow);
  33214. };
  33215. var openModalUrlDialog = function(config2, closeWindow) {
  33216. var factory2 = function(contents2) {
  33217. var dialog = renderUrlDialog(contents2, {
  33218. closeWindow: function() {
  33219. ModalDialog.hide(dialog.dialog);
  33220. closeWindow(dialog.instanceApi);
  33221. }
  33222. }, editor, backstage);
  33223. ModalDialog.show(dialog.dialog);
  33224. return dialog.instanceApi;
  33225. };
  33226. return DialogManager.openUrl(factory2, config2);
  33227. };
  33228. var openModalDialog = function(config2, closeWindow) {
  33229. var factory2 = function(contents2, internalInitialData, dataValidator) {
  33230. var initialData = internalInitialData;
  33231. var dialogInit = {
  33232. dataValidator,
  33233. initialData,
  33234. internalDialog: contents2
  33235. };
  33236. var dialog = renderDialog(dialogInit, {
  33237. redial: DialogManager.redial,
  33238. closeWindow: function() {
  33239. ModalDialog.hide(dialog.dialog);
  33240. closeWindow(dialog.instanceApi);
  33241. }
  33242. }, backstage);
  33243. ModalDialog.show(dialog.dialog);
  33244. dialog.instanceApi.setData(initialData);
  33245. return dialog.instanceApi;
  33246. };
  33247. return DialogManager.open(factory2, config2);
  33248. };
  33249. var openInlineDialog = function(config$1, anchor2, closeWindow, ariaAttrs) {
  33250. var factory2 = function(contents2, internalInitialData, dataValidator) {
  33251. var initialData = validateData(internalInitialData, dataValidator);
  33252. var inlineDialog = value$1();
  33253. var isToolbarLocationTop = backstage.shared.header.isPositionedAtTop();
  33254. var dialogInit = {
  33255. dataValidator,
  33256. initialData,
  33257. internalDialog: contents2
  33258. };
  33259. var refreshDocking = function() {
  33260. return inlineDialog.on(function(dialog) {
  33261. InlineView.reposition(dialog);
  33262. Docking.refresh(dialog);
  33263. });
  33264. };
  33265. var dialogUi = renderInlineDialog(dialogInit, {
  33266. redial: DialogManager.redial,
  33267. closeWindow: function() {
  33268. inlineDialog.on(InlineView.hide);
  33269. editor.off("ResizeEditor", refreshDocking);
  33270. inlineDialog.clear();
  33271. closeWindow(dialogUi.instanceApi);
  33272. }
  33273. }, backstage, ariaAttrs);
  33274. var inlineDialogComp = build$1(InlineView.sketch(__assign(__assign({
  33275. lazySink: backstage.shared.getSink,
  33276. dom: {
  33277. tag: "div",
  33278. classes: []
  33279. },
  33280. fireDismissalEventInstead: {}
  33281. }, isToolbarLocationTop ? {} : { fireRepositionEventInstead: {} }), {
  33282. inlineBehaviours: derive$1(__spreadArray([config("window-manager-inline-events", [run$1(dismissRequested(), function(_comp, _se) {
  33283. emit(dialogUi.dialog, formCancelEvent);
  33284. })])], inlineAdditionalBehaviours(editor, isStickyToolbar$1, isToolbarLocationTop), true)),
  33285. isExtraPart: function(_comp, target) {
  33286. return isAlertOrConfirmDialog(target);
  33287. }
  33288. })));
  33289. inlineDialog.set(inlineDialogComp);
  33290. InlineView.showWithin(inlineDialogComp, premade(dialogUi.dialog), { anchor: anchor2 }, Optional.some(body()));
  33291. if (!isStickyToolbar$1 || !isToolbarLocationTop) {
  33292. Docking.refresh(inlineDialogComp);
  33293. editor.on("ResizeEditor", refreshDocking);
  33294. }
  33295. dialogUi.instanceApi.setData(initialData);
  33296. Keying.focusIn(dialogUi.dialog);
  33297. return dialogUi.instanceApi;
  33298. };
  33299. return DialogManager.open(factory2, config$1);
  33300. };
  33301. var confirm = function(message, callback) {
  33302. confirmDialog.open(message, function(state) {
  33303. callback(state);
  33304. });
  33305. };
  33306. var alert = function(message, callback) {
  33307. alertDialog.open(message, function() {
  33308. callback();
  33309. });
  33310. };
  33311. var close2 = function(instanceApi) {
  33312. instanceApi.close();
  33313. };
  33314. return {
  33315. open: open2,
  33316. openUrl,
  33317. alert,
  33318. close: close2,
  33319. confirm
  33320. };
  33321. };
  33322. function Theme() {
  33323. global$g.add("silver", function(editor) {
  33324. var _a2 = setup$3(editor), uiMothership = _a2.uiMothership, backstage = _a2.backstage, renderUI = _a2.renderUI, getUi = _a2.getUi;
  33325. Autocompleter.register(editor, backstage.shared);
  33326. var windowMgr = setup({
  33327. editor,
  33328. backstage
  33329. });
  33330. return {
  33331. renderUI,
  33332. getWindowManagerImpl: constant$1(windowMgr),
  33333. getNotificationManagerImpl: function() {
  33334. return NotificationManagerImpl(editor, { backstage }, uiMothership);
  33335. },
  33336. ui: getUi()
  33337. };
  33338. });
  33339. }
  33340. Theme();
  33341. })();
  33342. }
  33343. });
  33344. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/themes/silver/index.js
  33345. require_theme();
  33346. //# sourceMappingURL=tinymce_themes_silver.js.map