theme.js 895 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.0.1 (2019-02-21)
  8. */
  9. (function () {
  10. var silver = (function (domGlobals) {
  11. 'use strict';
  12. var noop = function () {
  13. var args = [];
  14. for (var _i = 0; _i < arguments.length; _i++) {
  15. args[_i] = arguments[_i];
  16. }
  17. };
  18. var noarg = function (f) {
  19. return function () {
  20. var args = [];
  21. for (var _i = 0; _i < arguments.length; _i++) {
  22. args[_i] = arguments[_i];
  23. }
  24. return f();
  25. };
  26. };
  27. var compose = function (fa, fb) {
  28. return function () {
  29. var args = [];
  30. for (var _i = 0; _i < arguments.length; _i++) {
  31. args[_i] = arguments[_i];
  32. }
  33. return fa(fb.apply(null, args));
  34. };
  35. };
  36. var constant = function (value) {
  37. return function () {
  38. return value;
  39. };
  40. };
  41. var identity = function (x) {
  42. return x;
  43. };
  44. function curry(fn) {
  45. var initialArgs = [];
  46. for (var _i = 1; _i < arguments.length; _i++) {
  47. initialArgs[_i - 1] = arguments[_i];
  48. }
  49. return function () {
  50. var restArgs = [];
  51. for (var _i = 0; _i < arguments.length; _i++) {
  52. restArgs[_i] = arguments[_i];
  53. }
  54. var all = initialArgs.concat(restArgs);
  55. return fn.apply(null, all);
  56. };
  57. }
  58. var not = function (f) {
  59. return function () {
  60. var args = [];
  61. for (var _i = 0; _i < arguments.length; _i++) {
  62. args[_i] = arguments[_i];
  63. }
  64. return !f.apply(null, args);
  65. };
  66. };
  67. var die = function (msg) {
  68. return function () {
  69. throw new Error(msg);
  70. };
  71. };
  72. var never = constant(false);
  73. var always = constant(true);
  74. var never$1 = never;
  75. var always$1 = always;
  76. var none = function () {
  77. return NONE;
  78. };
  79. var NONE = function () {
  80. var eq = function (o) {
  81. return o.isNone();
  82. };
  83. var call = function (thunk) {
  84. return thunk();
  85. };
  86. var id = function (n) {
  87. return n;
  88. };
  89. var noop = function () {
  90. };
  91. var nul = function () {
  92. return null;
  93. };
  94. var undef = function () {
  95. return undefined;
  96. };
  97. var me = {
  98. fold: function (n, s) {
  99. return n();
  100. },
  101. is: never$1,
  102. isSome: never$1,
  103. isNone: always$1,
  104. getOr: id,
  105. getOrThunk: call,
  106. getOrDie: function (msg) {
  107. throw new Error(msg || 'error: getOrDie called on none.');
  108. },
  109. getOrNull: nul,
  110. getOrUndefined: undef,
  111. or: id,
  112. orThunk: call,
  113. map: none,
  114. ap: none,
  115. each: noop,
  116. bind: none,
  117. flatten: none,
  118. exists: never$1,
  119. forall: always$1,
  120. filter: none,
  121. equals: eq,
  122. equals_: eq,
  123. toArray: function () {
  124. return [];
  125. },
  126. toString: constant('none()')
  127. };
  128. if (Object.freeze)
  129. Object.freeze(me);
  130. return me;
  131. }();
  132. var some = function (a) {
  133. var constant_a = function () {
  134. return a;
  135. };
  136. var self = function () {
  137. return me;
  138. };
  139. var map = function (f) {
  140. return some(f(a));
  141. };
  142. var bind = function (f) {
  143. return f(a);
  144. };
  145. var me = {
  146. fold: function (n, s) {
  147. return s(a);
  148. },
  149. is: function (v) {
  150. return a === v;
  151. },
  152. isSome: always$1,
  153. isNone: never$1,
  154. getOr: constant_a,
  155. getOrThunk: constant_a,
  156. getOrDie: constant_a,
  157. getOrNull: constant_a,
  158. getOrUndefined: constant_a,
  159. or: self,
  160. orThunk: self,
  161. map: map,
  162. ap: function (optfab) {
  163. return optfab.fold(none, function (fab) {
  164. return some(fab(a));
  165. });
  166. },
  167. each: function (f) {
  168. f(a);
  169. },
  170. bind: bind,
  171. flatten: constant_a,
  172. exists: bind,
  173. forall: bind,
  174. filter: function (f) {
  175. return f(a) ? me : NONE;
  176. },
  177. equals: function (o) {
  178. return o.is(a);
  179. },
  180. equals_: function (o, elementEq) {
  181. return o.fold(never$1, function (b) {
  182. return elementEq(a, b);
  183. });
  184. },
  185. toArray: function () {
  186. return [a];
  187. },
  188. toString: function () {
  189. return 'some(' + a + ')';
  190. }
  191. };
  192. return me;
  193. };
  194. var from = function (value) {
  195. return value === null || value === undefined ? NONE : some(value);
  196. };
  197. var Option = {
  198. some: some,
  199. none: none,
  200. from: from
  201. };
  202. var typeOf = function (x) {
  203. if (x === null)
  204. return 'null';
  205. var t = typeof x;
  206. if (t === 'object' && Array.prototype.isPrototypeOf(x))
  207. return 'array';
  208. if (t === 'object' && String.prototype.isPrototypeOf(x))
  209. return 'string';
  210. return t;
  211. };
  212. var isType = function (type) {
  213. return function (value) {
  214. return typeOf(value) === type;
  215. };
  216. };
  217. var isString = isType('string');
  218. var isObject = isType('object');
  219. var isArray = isType('array');
  220. var isBoolean = isType('boolean');
  221. var isFunction = isType('function');
  222. var isNumber = isType('number');
  223. var rawIndexOf = function () {
  224. var pIndexOf = Array.prototype.indexOf;
  225. var fastIndex = function (xs, x) {
  226. return pIndexOf.call(xs, x);
  227. };
  228. var slowIndex = function (xs, x) {
  229. return slowIndexOf(xs, x);
  230. };
  231. return pIndexOf === undefined ? slowIndex : fastIndex;
  232. }();
  233. var indexOf = function (xs, x) {
  234. var r = rawIndexOf(xs, x);
  235. return r === -1 ? Option.none() : Option.some(r);
  236. };
  237. var contains = function (xs, x) {
  238. return rawIndexOf(xs, x) > -1;
  239. };
  240. var exists = function (xs, pred) {
  241. return findIndex(xs, pred).isSome();
  242. };
  243. var chunk = function (array, size) {
  244. var r = [];
  245. for (var i = 0; i < array.length; i += size) {
  246. var s = array.slice(i, i + size);
  247. r.push(s);
  248. }
  249. return r;
  250. };
  251. var map = function (xs, f) {
  252. var len = xs.length;
  253. var r = new Array(len);
  254. for (var i = 0; i < len; i++) {
  255. var x = xs[i];
  256. r[i] = f(x, i, xs);
  257. }
  258. return r;
  259. };
  260. var each = function (xs, f) {
  261. for (var i = 0, len = xs.length; i < len; i++) {
  262. var x = xs[i];
  263. f(x, i, xs);
  264. }
  265. };
  266. var eachr = function (xs, f) {
  267. for (var i = xs.length - 1; i >= 0; i--) {
  268. var x = xs[i];
  269. f(x, i, xs);
  270. }
  271. };
  272. var partition = function (xs, pred) {
  273. var pass = [];
  274. var fail = [];
  275. for (var i = 0, len = xs.length; i < len; i++) {
  276. var x = xs[i];
  277. var arr = pred(x, i, xs) ? pass : fail;
  278. arr.push(x);
  279. }
  280. return {
  281. pass: pass,
  282. fail: fail
  283. };
  284. };
  285. var filter = function (xs, pred) {
  286. var r = [];
  287. for (var i = 0, len = xs.length; i < len; i++) {
  288. var x = xs[i];
  289. if (pred(x, i, xs)) {
  290. r.push(x);
  291. }
  292. }
  293. return r;
  294. };
  295. var foldr = function (xs, f, acc) {
  296. eachr(xs, function (x) {
  297. acc = f(acc, x);
  298. });
  299. return acc;
  300. };
  301. var foldl = function (xs, f, acc) {
  302. each(xs, function (x) {
  303. acc = f(acc, x);
  304. });
  305. return acc;
  306. };
  307. var find = function (xs, pred) {
  308. for (var i = 0, len = xs.length; i < len; i++) {
  309. var x = xs[i];
  310. if (pred(x, i, xs)) {
  311. return Option.some(x);
  312. }
  313. }
  314. return Option.none();
  315. };
  316. var findIndex = function (xs, pred) {
  317. for (var i = 0, len = xs.length; i < len; i++) {
  318. var x = xs[i];
  319. if (pred(x, i, xs)) {
  320. return Option.some(i);
  321. }
  322. }
  323. return Option.none();
  324. };
  325. var slowIndexOf = function (xs, x) {
  326. for (var i = 0, len = xs.length; i < len; ++i) {
  327. if (xs[i] === x) {
  328. return i;
  329. }
  330. }
  331. return -1;
  332. };
  333. var push = Array.prototype.push;
  334. var flatten = function (xs) {
  335. var r = [];
  336. for (var i = 0, len = xs.length; i < len; ++i) {
  337. if (!Array.prototype.isPrototypeOf(xs[i]))
  338. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  339. push.apply(r, xs[i]);
  340. }
  341. return r;
  342. };
  343. var bind = function (xs, f) {
  344. var output = map(xs, f);
  345. return flatten(output);
  346. };
  347. var forall = function (xs, pred) {
  348. for (var i = 0, len = xs.length; i < len; ++i) {
  349. var x = xs[i];
  350. if (pred(x, i, xs) !== true) {
  351. return false;
  352. }
  353. }
  354. return true;
  355. };
  356. var slice = Array.prototype.slice;
  357. var reverse = function (xs) {
  358. var r = slice.call(xs, 0);
  359. r.reverse();
  360. return r;
  361. };
  362. var difference = function (a1, a2) {
  363. return filter(a1, function (x) {
  364. return !contains(a2, x);
  365. });
  366. };
  367. var pure = function (x) {
  368. return [x];
  369. };
  370. var sort = function (xs, comparator) {
  371. var copy = slice.call(xs, 0);
  372. copy.sort(comparator);
  373. return copy;
  374. };
  375. var head = function (xs) {
  376. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  377. };
  378. var last = function (xs) {
  379. return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
  380. };
  381. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  382. return slice.call(x);
  383. };
  384. var keys = Object.keys;
  385. var hasOwnProperty = Object.hasOwnProperty;
  386. var each$1 = function (obj, f) {
  387. var props = keys(obj);
  388. for (var k = 0, len = props.length; k < len; k++) {
  389. var i = props[k];
  390. var x = obj[i];
  391. f(x, i, obj);
  392. }
  393. };
  394. var map$1 = function (obj, f) {
  395. return tupleMap(obj, function (x, i, obj) {
  396. return {
  397. k: i,
  398. v: f(x, i, obj)
  399. };
  400. });
  401. };
  402. var tupleMap = function (obj, f) {
  403. var r = {};
  404. each$1(obj, function (x, i) {
  405. var tuple = f(x, i, obj);
  406. r[tuple.k] = tuple.v;
  407. });
  408. return r;
  409. };
  410. var mapToArray = function (obj, f) {
  411. var r = [];
  412. each$1(obj, function (value, name) {
  413. r.push(f(value, name));
  414. });
  415. return r;
  416. };
  417. var find$1 = function (obj, pred) {
  418. var props = keys(obj);
  419. for (var k = 0, len = props.length; k < len; k++) {
  420. var i = props[k];
  421. var x = obj[i];
  422. if (pred(x, i, obj)) {
  423. return Option.some(x);
  424. }
  425. }
  426. return Option.none();
  427. };
  428. var values = function (obj) {
  429. return mapToArray(obj, function (v) {
  430. return v;
  431. });
  432. };
  433. var get = function (obj, key) {
  434. return has(obj, key) ? Option.some(obj[key]) : Option.none();
  435. };
  436. var has = function (obj, key) {
  437. return hasOwnProperty.call(obj, key);
  438. };
  439. var exclude = function (obj, fields) {
  440. var r = {};
  441. each$1(obj, function (v, k) {
  442. if (!contains(fields, k)) {
  443. r[k] = v;
  444. }
  445. });
  446. return r;
  447. };
  448. var readOpt = function (key) {
  449. return function (obj) {
  450. return has(obj, key) ? Option.from(obj[key]) : Option.none();
  451. };
  452. };
  453. var readOr = function (key, fallback) {
  454. return function (obj) {
  455. return has(obj, key) ? obj[key] : fallback;
  456. };
  457. };
  458. var readOptFrom = function (obj, key) {
  459. return readOpt(key)(obj);
  460. };
  461. var hasKey = function (obj, key) {
  462. return has(obj, key) && obj[key] !== undefined && obj[key] !== null;
  463. };
  464. var wrap = function (key, value) {
  465. var r = {};
  466. r[key] = value;
  467. return r;
  468. };
  469. var wrapAll = function (keyvalues) {
  470. var r = {};
  471. each(keyvalues, function (kv) {
  472. r[kv.key] = kv.value;
  473. });
  474. return r;
  475. };
  476. var value = function (o) {
  477. var is = function (v) {
  478. return o === v;
  479. };
  480. var or = function (opt) {
  481. return value(o);
  482. };
  483. var orThunk = function (f) {
  484. return value(o);
  485. };
  486. var map = function (f) {
  487. return value(f(o));
  488. };
  489. var mapError = function (f) {
  490. return value(o);
  491. };
  492. var each = function (f) {
  493. f(o);
  494. };
  495. var bind = function (f) {
  496. return f(o);
  497. };
  498. var fold = function (_, onValue) {
  499. return onValue(o);
  500. };
  501. var exists = function (f) {
  502. return f(o);
  503. };
  504. var forall = function (f) {
  505. return f(o);
  506. };
  507. var toOption = function () {
  508. return Option.some(o);
  509. };
  510. return {
  511. is: is,
  512. isValue: always,
  513. isError: never,
  514. getOr: constant(o),
  515. getOrThunk: constant(o),
  516. getOrDie: constant(o),
  517. or: or,
  518. orThunk: orThunk,
  519. fold: fold,
  520. map: map,
  521. mapError: mapError,
  522. each: each,
  523. bind: bind,
  524. exists: exists,
  525. forall: forall,
  526. toOption: toOption
  527. };
  528. };
  529. var error = function (message) {
  530. var getOrThunk = function (f) {
  531. return f();
  532. };
  533. var getOrDie = function () {
  534. return die(String(message))();
  535. };
  536. var or = function (opt) {
  537. return opt;
  538. };
  539. var orThunk = function (f) {
  540. return f();
  541. };
  542. var map = function (f) {
  543. return error(message);
  544. };
  545. var mapError = function (f) {
  546. return error(f(message));
  547. };
  548. var bind = function (f) {
  549. return error(message);
  550. };
  551. var fold = function (onError, _) {
  552. return onError(message);
  553. };
  554. return {
  555. is: never,
  556. isValue: never,
  557. isError: always,
  558. getOr: identity,
  559. getOrThunk: getOrThunk,
  560. getOrDie: getOrDie,
  561. or: or,
  562. orThunk: orThunk,
  563. fold: fold,
  564. map: map,
  565. mapError: mapError,
  566. each: noop,
  567. bind: bind,
  568. exists: never,
  569. forall: always,
  570. toOption: Option.none
  571. };
  572. };
  573. var Result = {
  574. value: value,
  575. error: error
  576. };
  577. var generate = function (cases) {
  578. if (!isArray(cases)) {
  579. throw new Error('cases must be an array');
  580. }
  581. if (cases.length === 0) {
  582. throw new Error('there must be at least one case');
  583. }
  584. var constructors = [];
  585. var adt = {};
  586. each(cases, function (acase, count) {
  587. var keys$1 = keys(acase);
  588. if (keys$1.length !== 1) {
  589. throw new Error('one and only one name per case');
  590. }
  591. var key = keys$1[0];
  592. var value = acase[key];
  593. if (adt[key] !== undefined) {
  594. throw new Error('duplicate key detected:' + key);
  595. } else if (key === 'cata') {
  596. throw new Error('cannot have a case named cata (sorry)');
  597. } else if (!isArray(value)) {
  598. throw new Error('case arguments must be an array');
  599. }
  600. constructors.push(key);
  601. adt[key] = function () {
  602. var argLength = arguments.length;
  603. if (argLength !== value.length) {
  604. throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
  605. }
  606. var args = new Array(argLength);
  607. for (var i = 0; i < args.length; i++)
  608. args[i] = arguments[i];
  609. var match = function (branches) {
  610. var branchKeys = keys(branches);
  611. if (constructors.length !== branchKeys.length) {
  612. throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
  613. }
  614. var allReqd = forall(constructors, function (reqKey) {
  615. return contains(branchKeys, reqKey);
  616. });
  617. if (!allReqd)
  618. throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
  619. return branches[key].apply(null, args);
  620. };
  621. return {
  622. fold: function () {
  623. if (arguments.length !== cases.length) {
  624. throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
  625. }
  626. var target = arguments[count];
  627. return target.apply(null, args);
  628. },
  629. match: match,
  630. log: function (label) {
  631. console.log(label, {
  632. constructors: constructors,
  633. constructor: key,
  634. params: args
  635. });
  636. }
  637. };
  638. };
  639. });
  640. return adt;
  641. };
  642. var Adt = { generate: generate };
  643. var comparison = Adt.generate([
  644. {
  645. bothErrors: [
  646. 'error1',
  647. 'error2'
  648. ]
  649. },
  650. {
  651. firstError: [
  652. 'error1',
  653. 'value2'
  654. ]
  655. },
  656. {
  657. secondError: [
  658. 'value1',
  659. 'error2'
  660. ]
  661. },
  662. {
  663. bothValues: [
  664. 'value1',
  665. 'value2'
  666. ]
  667. }
  668. ]);
  669. var partition$1 = function (results) {
  670. var errors = [];
  671. var values = [];
  672. each(results, function (result) {
  673. result.fold(function (err) {
  674. errors.push(err);
  675. }, function (value) {
  676. values.push(value);
  677. });
  678. });
  679. return {
  680. errors: errors,
  681. values: values
  682. };
  683. };
  684. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  685. var shallow = function (old, nu) {
  686. return nu;
  687. };
  688. var deep = function (old, nu) {
  689. var bothObjects = isObject(old) && isObject(nu);
  690. return bothObjects ? deepMerge(old, nu) : nu;
  691. };
  692. var baseMerge = function (merger) {
  693. return function () {
  694. var objects = new Array(arguments.length);
  695. for (var i = 0; i < objects.length; i++)
  696. objects[i] = arguments[i];
  697. if (objects.length === 0)
  698. throw new Error('Can\'t merge zero objects');
  699. var ret = {};
  700. for (var j = 0; j < objects.length; j++) {
  701. var curObject = objects[j];
  702. for (var key in curObject)
  703. if (hasOwnProperty$1.call(curObject, key)) {
  704. ret[key] = merger(ret[key], curObject[key]);
  705. }
  706. }
  707. return ret;
  708. };
  709. };
  710. var deepMerge = baseMerge(deep);
  711. var merge = baseMerge(shallow);
  712. var exclude$1 = function (obj, fields) {
  713. return exclude(obj, fields);
  714. };
  715. var readOpt$1 = function (key) {
  716. return readOpt(key);
  717. };
  718. var readOr$1 = function (key, fallback) {
  719. return readOr(key, fallback);
  720. };
  721. var readOptFrom$1 = function (obj, key) {
  722. return readOptFrom(obj, key);
  723. };
  724. var wrap$1 = function (key, value) {
  725. return wrap(key, value);
  726. };
  727. var wrapAll$1 = function (keyvalues) {
  728. return wrapAll(keyvalues);
  729. };
  730. var mergeValues = function (values, base) {
  731. return values.length === 0 ? Result.value(base) : Result.value(deepMerge(base, merge.apply(undefined, values)));
  732. };
  733. var mergeErrors = function (errors) {
  734. return compose(Result.error, flatten)(errors);
  735. };
  736. var consolidate = function (objs, base) {
  737. var partitions = partition$1(objs);
  738. return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : mergeValues(partitions.values, base);
  739. };
  740. var hasKey$1 = function (obj, key) {
  741. return hasKey(obj, key);
  742. };
  743. var Cell = function (initial) {
  744. var value = initial;
  745. var get = function () {
  746. return value;
  747. };
  748. var set = function (v) {
  749. value = v;
  750. };
  751. var clone = function () {
  752. return Cell(get());
  753. };
  754. return {
  755. get: get,
  756. set: set,
  757. clone: clone
  758. };
  759. };
  760. var cat = function (arr) {
  761. var r = [];
  762. var push = function (x) {
  763. r.push(x);
  764. };
  765. for (var i = 0; i < arr.length; i++) {
  766. arr[i].each(push);
  767. }
  768. return r;
  769. };
  770. var findMap = function (arr, f) {
  771. for (var i = 0; i < arr.length; i++) {
  772. var r = f(arr[i], i);
  773. if (r.isSome()) {
  774. return r;
  775. }
  776. }
  777. return Option.none();
  778. };
  779. var liftN = function (arr, f) {
  780. var r = [];
  781. for (var i = 0; i < arr.length; i++) {
  782. var x = arr[i];
  783. if (x.isSome()) {
  784. r.push(x.getOrDie());
  785. } else {
  786. return Option.none();
  787. }
  788. }
  789. return Option.some(f.apply(null, r));
  790. };
  791. var touchstart = constant('touchstart');
  792. var touchmove = constant('touchmove');
  793. var touchend = constant('touchend');
  794. var mousedown = constant('mousedown');
  795. var mousemove = constant('mousemove');
  796. var mouseout = constant('mouseout');
  797. var mouseup = constant('mouseup');
  798. var mouseover = constant('mouseover');
  799. var focusin = constant('focusin');
  800. var focusout = constant('focusout');
  801. var keydown = constant('keydown');
  802. var keyup = constant('keyup');
  803. var input = constant('input');
  804. var change = constant('change');
  805. var click = constant('click');
  806. var transitionend = constant('transitionend');
  807. var selectstart = constant('selectstart');
  808. var cached = function (f) {
  809. var called = false;
  810. var r;
  811. return function () {
  812. var args = [];
  813. for (var _i = 0; _i < arguments.length; _i++) {
  814. args[_i] = arguments[_i];
  815. }
  816. if (!called) {
  817. called = true;
  818. r = f.apply(null, args);
  819. }
  820. return r;
  821. };
  822. };
  823. var firstMatch = function (regexes, s) {
  824. for (var i = 0; i < regexes.length; i++) {
  825. var x = regexes[i];
  826. if (x.test(s))
  827. return x;
  828. }
  829. return undefined;
  830. };
  831. var find$2 = function (regexes, agent) {
  832. var r = firstMatch(regexes, agent);
  833. if (!r)
  834. return {
  835. major: 0,
  836. minor: 0
  837. };
  838. var group = function (i) {
  839. return Number(agent.replace(r, '$' + i));
  840. };
  841. return nu(group(1), group(2));
  842. };
  843. var detect = function (versionRegexes, agent) {
  844. var cleanedAgent = String(agent).toLowerCase();
  845. if (versionRegexes.length === 0)
  846. return unknown();
  847. return find$2(versionRegexes, cleanedAgent);
  848. };
  849. var unknown = function () {
  850. return nu(0, 0);
  851. };
  852. var nu = function (major, minor) {
  853. return {
  854. major: major,
  855. minor: minor
  856. };
  857. };
  858. var Version = {
  859. nu: nu,
  860. detect: detect,
  861. unknown: unknown
  862. };
  863. var edge = 'Edge';
  864. var chrome = 'Chrome';
  865. var ie = 'IE';
  866. var opera = 'Opera';
  867. var firefox = 'Firefox';
  868. var safari = 'Safari';
  869. var isBrowser = function (name, current) {
  870. return function () {
  871. return current === name;
  872. };
  873. };
  874. var unknown$1 = function () {
  875. return nu$1({
  876. current: undefined,
  877. version: Version.unknown()
  878. });
  879. };
  880. var nu$1 = function (info) {
  881. var current = info.current;
  882. var version = info.version;
  883. return {
  884. current: current,
  885. version: version,
  886. isEdge: isBrowser(edge, current),
  887. isChrome: isBrowser(chrome, current),
  888. isIE: isBrowser(ie, current),
  889. isOpera: isBrowser(opera, current),
  890. isFirefox: isBrowser(firefox, current),
  891. isSafari: isBrowser(safari, current)
  892. };
  893. };
  894. var Browser = {
  895. unknown: unknown$1,
  896. nu: nu$1,
  897. edge: constant(edge),
  898. chrome: constant(chrome),
  899. ie: constant(ie),
  900. opera: constant(opera),
  901. firefox: constant(firefox),
  902. safari: constant(safari)
  903. };
  904. var windows = 'Windows';
  905. var ios = 'iOS';
  906. var android = 'Android';
  907. var linux = 'Linux';
  908. var osx = 'OSX';
  909. var solaris = 'Solaris';
  910. var freebsd = 'FreeBSD';
  911. var isOS = function (name, current) {
  912. return function () {
  913. return current === name;
  914. };
  915. };
  916. var unknown$2 = function () {
  917. return nu$2({
  918. current: undefined,
  919. version: Version.unknown()
  920. });
  921. };
  922. var nu$2 = function (info) {
  923. var current = info.current;
  924. var version = info.version;
  925. return {
  926. current: current,
  927. version: version,
  928. isWindows: isOS(windows, current),
  929. isiOS: isOS(ios, current),
  930. isAndroid: isOS(android, current),
  931. isOSX: isOS(osx, current),
  932. isLinux: isOS(linux, current),
  933. isSolaris: isOS(solaris, current),
  934. isFreeBSD: isOS(freebsd, current)
  935. };
  936. };
  937. var OperatingSystem = {
  938. unknown: unknown$2,
  939. nu: nu$2,
  940. windows: constant(windows),
  941. ios: constant(ios),
  942. android: constant(android),
  943. linux: constant(linux),
  944. osx: constant(osx),
  945. solaris: constant(solaris),
  946. freebsd: constant(freebsd)
  947. };
  948. var DeviceType = function (os, browser, userAgent) {
  949. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  950. var isiPhone = os.isiOS() && !isiPad;
  951. var isAndroid3 = os.isAndroid() && os.version.major === 3;
  952. var isAndroid4 = os.isAndroid() && os.version.major === 4;
  953. var isTablet = isiPad || isAndroid3 || isAndroid4 && /mobile/i.test(userAgent) === true;
  954. var isTouch = os.isiOS() || os.isAndroid();
  955. var isPhone = isTouch && !isTablet;
  956. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  957. return {
  958. isiPad: constant(isiPad),
  959. isiPhone: constant(isiPhone),
  960. isTablet: constant(isTablet),
  961. isPhone: constant(isPhone),
  962. isTouch: constant(isTouch),
  963. isAndroid: os.isAndroid,
  964. isiOS: os.isiOS,
  965. isWebView: constant(iOSwebview)
  966. };
  967. };
  968. var detect$1 = function (candidates, userAgent) {
  969. var agent = String(userAgent).toLowerCase();
  970. return find(candidates, function (candidate) {
  971. return candidate.search(agent);
  972. });
  973. };
  974. var detectBrowser = function (browsers, userAgent) {
  975. return detect$1(browsers, userAgent).map(function (browser) {
  976. var version = Version.detect(browser.versionRegexes, userAgent);
  977. return {
  978. current: browser.name,
  979. version: version
  980. };
  981. });
  982. };
  983. var detectOs = function (oses, userAgent) {
  984. return detect$1(oses, userAgent).map(function (os) {
  985. var version = Version.detect(os.versionRegexes, userAgent);
  986. return {
  987. current: os.name,
  988. version: version
  989. };
  990. });
  991. };
  992. var UaString = {
  993. detectBrowser: detectBrowser,
  994. detectOs: detectOs
  995. };
  996. var checkRange = function (str, substr, start) {
  997. if (substr === '')
  998. return true;
  999. if (str.length < substr.length)
  1000. return false;
  1001. var x = str.substr(start, start + substr.length);
  1002. return x === substr;
  1003. };
  1004. var contains$1 = function (str, substr) {
  1005. return str.indexOf(substr) !== -1;
  1006. };
  1007. var endsWith = function (str, suffix) {
  1008. return checkRange(str, suffix, str.length - suffix.length);
  1009. };
  1010. var trim = function (str) {
  1011. return str.replace(/^\s+|\s+$/g, '');
  1012. };
  1013. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  1014. var checkContains = function (target) {
  1015. return function (uastring) {
  1016. return contains$1(uastring, target);
  1017. };
  1018. };
  1019. var browsers = [
  1020. {
  1021. name: 'Edge',
  1022. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  1023. search: function (uastring) {
  1024. var monstrosity = contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
  1025. return monstrosity;
  1026. }
  1027. },
  1028. {
  1029. name: 'Chrome',
  1030. versionRegexes: [
  1031. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  1032. normalVersionRegex
  1033. ],
  1034. search: function (uastring) {
  1035. return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
  1036. }
  1037. },
  1038. {
  1039. name: 'IE',
  1040. versionRegexes: [
  1041. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  1042. /.*?rv:([0-9]+)\.([0-9]+).*/
  1043. ],
  1044. search: function (uastring) {
  1045. return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
  1046. }
  1047. },
  1048. {
  1049. name: 'Opera',
  1050. versionRegexes: [
  1051. normalVersionRegex,
  1052. /.*?opera\/([0-9]+)\.([0-9]+).*/
  1053. ],
  1054. search: checkContains('opera')
  1055. },
  1056. {
  1057. name: 'Firefox',
  1058. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  1059. search: checkContains('firefox')
  1060. },
  1061. {
  1062. name: 'Safari',
  1063. versionRegexes: [
  1064. normalVersionRegex,
  1065. /.*?cpu os ([0-9]+)_([0-9]+).*/
  1066. ],
  1067. search: function (uastring) {
  1068. return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
  1069. }
  1070. }
  1071. ];
  1072. var oses = [
  1073. {
  1074. name: 'Windows',
  1075. search: checkContains('win'),
  1076. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  1077. },
  1078. {
  1079. name: 'iOS',
  1080. search: function (uastring) {
  1081. return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
  1082. },
  1083. versionRegexes: [
  1084. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  1085. /.*cpu os ([0-9]+)_([0-9]+).*/,
  1086. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  1087. ]
  1088. },
  1089. {
  1090. name: 'Android',
  1091. search: checkContains('android'),
  1092. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  1093. },
  1094. {
  1095. name: 'OSX',
  1096. search: checkContains('os x'),
  1097. versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
  1098. },
  1099. {
  1100. name: 'Linux',
  1101. search: checkContains('linux'),
  1102. versionRegexes: []
  1103. },
  1104. {
  1105. name: 'Solaris',
  1106. search: checkContains('sunos'),
  1107. versionRegexes: []
  1108. },
  1109. {
  1110. name: 'FreeBSD',
  1111. search: checkContains('freebsd'),
  1112. versionRegexes: []
  1113. }
  1114. ];
  1115. var PlatformInfo = {
  1116. browsers: constant(browsers),
  1117. oses: constant(oses)
  1118. };
  1119. var detect$2 = function (userAgent) {
  1120. var browsers = PlatformInfo.browsers();
  1121. var oses = PlatformInfo.oses();
  1122. var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
  1123. var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  1124. var deviceType = DeviceType(os, browser, userAgent);
  1125. return {
  1126. browser: browser,
  1127. os: os,
  1128. deviceType: deviceType
  1129. };
  1130. };
  1131. var PlatformDetection = { detect: detect$2 };
  1132. var detect$3 = cached(function () {
  1133. var userAgent = domGlobals.navigator.userAgent;
  1134. return PlatformDetection.detect(userAgent);
  1135. });
  1136. var PlatformDetection$1 = { detect: detect$3 };
  1137. var alloy = { tap: constant('alloy.tap') };
  1138. var focus = constant('alloy.focus');
  1139. var postBlur = constant('alloy.blur.post');
  1140. var postPaste = constant('alloy.paste.post');
  1141. var receive = constant('alloy.receive');
  1142. var execute = constant('alloy.execute');
  1143. var focusItem = constant('alloy.focus.item');
  1144. var tap = alloy.tap;
  1145. var tapOrClick = PlatformDetection$1.detect().deviceType.isTouch() ? alloy.tap : click;
  1146. var longpress = constant('alloy.longpress');
  1147. var sandboxClose = constant('alloy.sandbox.close');
  1148. var typeaheadCancel = constant('alloy.typeahead.cancel');
  1149. var systemInit = constant('alloy.system.init');
  1150. var windowScroll = constant('alloy.system.scroll');
  1151. var windowResize = constant('alloy.system.resize');
  1152. var attachedToDom = constant('alloy.system.attached');
  1153. var detachedFromDom = constant('alloy.system.detached');
  1154. var dismissRequested = constant('alloy.system.dismissRequested');
  1155. var focusShifted = constant('alloy.focusmanager.shifted');
  1156. var slotVisibility = constant('alloy.slotcontainer.visibility');
  1157. var changeTab = constant('alloy.change.tab');
  1158. var dismissTab = constant('alloy.dismiss.tab');
  1159. var highlight = constant('alloy.highlight');
  1160. var dehighlight = constant('alloy.dehighlight');
  1161. var fromHtml = function (html, scope) {
  1162. var doc = scope || domGlobals.document;
  1163. var div = doc.createElement('div');
  1164. div.innerHTML = html;
  1165. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  1166. domGlobals.console.error('HTML does not have a single root node', html);
  1167. throw new Error('HTML must have a single root node');
  1168. }
  1169. return fromDom(div.childNodes[0]);
  1170. };
  1171. var fromTag = function (tag, scope) {
  1172. var doc = scope || domGlobals.document;
  1173. var node = doc.createElement(tag);
  1174. return fromDom(node);
  1175. };
  1176. var fromText = function (text, scope) {
  1177. var doc = scope || domGlobals.document;
  1178. var node = doc.createTextNode(text);
  1179. return fromDom(node);
  1180. };
  1181. var fromDom = function (node) {
  1182. if (node === null || node === undefined) {
  1183. throw new Error('Node cannot be null or undefined');
  1184. }
  1185. return { dom: constant(node) };
  1186. };
  1187. var fromPoint = function (docElm, x, y) {
  1188. var doc = docElm.dom();
  1189. return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
  1190. };
  1191. var Element = {
  1192. fromHtml: fromHtml,
  1193. fromTag: fromTag,
  1194. fromText: fromText,
  1195. fromDom: fromDom,
  1196. fromPoint: fromPoint
  1197. };
  1198. var Immutable = function () {
  1199. var fields = [];
  1200. for (var _i = 0; _i < arguments.length; _i++) {
  1201. fields[_i] = arguments[_i];
  1202. }
  1203. return function () {
  1204. var values = [];
  1205. for (var _i = 0; _i < arguments.length; _i++) {
  1206. values[_i] = arguments[_i];
  1207. }
  1208. if (fields.length !== values.length) {
  1209. throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
  1210. }
  1211. var struct = {};
  1212. each(fields, function (name, i) {
  1213. struct[name] = constant(values[i]);
  1214. });
  1215. return struct;
  1216. };
  1217. };
  1218. var sort$1 = function (arr) {
  1219. return arr.slice(0).sort();
  1220. };
  1221. var reqMessage = function (required, keys) {
  1222. throw new Error('All required keys (' + sort$1(required).join(', ') + ') were not specified. Specified keys were: ' + sort$1(keys).join(', ') + '.');
  1223. };
  1224. var unsuppMessage = function (unsupported) {
  1225. throw new Error('Unsupported keys for object: ' + sort$1(unsupported).join(', '));
  1226. };
  1227. var validateStrArr = function (label, array) {
  1228. if (!isArray(array))
  1229. throw new Error('The ' + label + ' fields must be an array. Was: ' + array + '.');
  1230. each(array, function (a) {
  1231. if (!isString(a))
  1232. throw new Error('The value ' + a + ' in the ' + label + ' fields was not a string.');
  1233. });
  1234. };
  1235. var checkDupes = function (everything) {
  1236. var sorted = sort$1(everything);
  1237. var dupe = find(sorted, function (s, i) {
  1238. return i < sorted.length - 1 && s === sorted[i + 1];
  1239. });
  1240. dupe.each(function (d) {
  1241. throw new Error('The field: ' + d + ' occurs more than once in the combined fields: [' + sorted.join(', ') + '].');
  1242. });
  1243. };
  1244. var MixedBag = function (required, optional) {
  1245. var everything = required.concat(optional);
  1246. if (everything.length === 0)
  1247. throw new Error('You must specify at least one required or optional field.');
  1248. validateStrArr('required', required);
  1249. validateStrArr('optional', optional);
  1250. checkDupes(everything);
  1251. return function (obj) {
  1252. var keys$1 = keys(obj);
  1253. var allReqd = forall(required, function (req) {
  1254. return contains(keys$1, req);
  1255. });
  1256. if (!allReqd)
  1257. reqMessage(required, keys$1);
  1258. var unsupported = filter(keys$1, function (key) {
  1259. return !contains(everything, key);
  1260. });
  1261. if (unsupported.length > 0)
  1262. unsuppMessage(unsupported);
  1263. var r = {};
  1264. each(required, function (req) {
  1265. r[req] = constant(obj[req]);
  1266. });
  1267. each(optional, function (opt) {
  1268. r[opt] = constant(Object.prototype.hasOwnProperty.call(obj, opt) ? Option.some(obj[opt]) : Option.none());
  1269. });
  1270. return r;
  1271. };
  1272. };
  1273. var Global = typeof window !== 'undefined' ? window : Function('return this;')();
  1274. var path = function (parts, scope) {
  1275. var o = scope !== undefined && scope !== null ? scope : Global;
  1276. for (var i = 0; i < parts.length && o !== undefined && o !== null; ++i)
  1277. o = o[parts[i]];
  1278. return o;
  1279. };
  1280. var resolve = function (p, scope) {
  1281. var parts = p.split('.');
  1282. return path(parts, scope);
  1283. };
  1284. var unsafe = function (name, scope) {
  1285. return resolve(name, scope);
  1286. };
  1287. var getOrDie = function (name, scope) {
  1288. var actual = unsafe(name, scope);
  1289. if (actual === undefined || actual === null)
  1290. throw name + ' not available on this browser';
  1291. return actual;
  1292. };
  1293. var Global$1 = { getOrDie: getOrDie };
  1294. var node = function () {
  1295. var f = Global$1.getOrDie('Node');
  1296. return f;
  1297. };
  1298. var compareDocumentPosition = function (a, b, match) {
  1299. return (a.compareDocumentPosition(b) & match) !== 0;
  1300. };
  1301. var documentPositionPreceding = function (a, b) {
  1302. return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_PRECEDING);
  1303. };
  1304. var documentPositionContainedBy = function (a, b) {
  1305. return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_CONTAINED_BY);
  1306. };
  1307. var Node = {
  1308. documentPositionPreceding: documentPositionPreceding,
  1309. documentPositionContainedBy: documentPositionContainedBy
  1310. };
  1311. var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
  1312. var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
  1313. var COMMENT = domGlobals.Node.COMMENT_NODE;
  1314. var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
  1315. var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
  1316. var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
  1317. var ELEMENT = domGlobals.Node.ELEMENT_NODE;
  1318. var TEXT = domGlobals.Node.TEXT_NODE;
  1319. var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
  1320. var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
  1321. var ENTITY = domGlobals.Node.ENTITY_NODE;
  1322. var NOTATION = domGlobals.Node.NOTATION_NODE;
  1323. var ELEMENT$1 = ELEMENT;
  1324. var DOCUMENT$1 = DOCUMENT;
  1325. var is = function (element, selector) {
  1326. var elem = element.dom();
  1327. if (elem.nodeType !== ELEMENT$1) {
  1328. return false;
  1329. } else if (elem.matches !== undefined) {
  1330. return elem.matches(selector);
  1331. } else if (elem.msMatchesSelector !== undefined) {
  1332. return elem.msMatchesSelector(selector);
  1333. } else if (elem.webkitMatchesSelector !== undefined) {
  1334. return elem.webkitMatchesSelector(selector);
  1335. } else if (elem.mozMatchesSelector !== undefined) {
  1336. return elem.mozMatchesSelector(selector);
  1337. } else {
  1338. throw new Error('Browser lacks native selectors');
  1339. }
  1340. };
  1341. var bypassSelector = function (dom) {
  1342. return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
  1343. };
  1344. var all = function (selector, scope) {
  1345. var base = scope === undefined ? domGlobals.document : scope.dom();
  1346. return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
  1347. };
  1348. var one = function (selector, scope) {
  1349. var base = scope === undefined ? domGlobals.document : scope.dom();
  1350. return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
  1351. };
  1352. var eq = function (e1, e2) {
  1353. return e1.dom() === e2.dom();
  1354. };
  1355. var regularContains = function (e1, e2) {
  1356. var d1 = e1.dom();
  1357. var d2 = e2.dom();
  1358. return d1 === d2 ? false : d1.contains(d2);
  1359. };
  1360. var ieContains = function (e1, e2) {
  1361. return Node.documentPositionContainedBy(e1.dom(), e2.dom());
  1362. };
  1363. var browser = PlatformDetection$1.detect().browser;
  1364. var contains$2 = browser.isIE() ? ieContains : regularContains;
  1365. var owner = function (element) {
  1366. return Element.fromDom(element.dom().ownerDocument);
  1367. };
  1368. var defaultView = function (element) {
  1369. var el = element.dom();
  1370. var defView = el.ownerDocument.defaultView;
  1371. return Element.fromDom(defView);
  1372. };
  1373. var parent = function (element) {
  1374. var dom = element.dom();
  1375. return Option.from(dom.parentNode).map(Element.fromDom);
  1376. };
  1377. var offsetParent = function (element) {
  1378. var dom = element.dom();
  1379. return Option.from(dom.offsetParent).map(Element.fromDom);
  1380. };
  1381. var nextSibling = function (element) {
  1382. var dom = element.dom();
  1383. return Option.from(dom.nextSibling).map(Element.fromDom);
  1384. };
  1385. var children = function (element) {
  1386. var dom = element.dom();
  1387. return map(dom.childNodes, Element.fromDom);
  1388. };
  1389. var child = function (element, index) {
  1390. var cs = element.dom().childNodes;
  1391. return Option.from(cs[index]).map(Element.fromDom);
  1392. };
  1393. var firstChild = function (element) {
  1394. return child(element, 0);
  1395. };
  1396. var spot = Immutable('element', 'offset');
  1397. var fromHtml$1 = function (html, scope) {
  1398. var doc = scope || domGlobals.document;
  1399. var div = doc.createElement('div');
  1400. div.innerHTML = html;
  1401. return children(Element.fromDom(div));
  1402. };
  1403. var before = function (marker, element) {
  1404. var parent$1 = parent(marker);
  1405. parent$1.each(function (v) {
  1406. v.dom().insertBefore(element.dom(), marker.dom());
  1407. });
  1408. };
  1409. var after = function (marker, element) {
  1410. var sibling = nextSibling(marker);
  1411. sibling.fold(function () {
  1412. var parent$1 = parent(marker);
  1413. parent$1.each(function (v) {
  1414. append(v, element);
  1415. });
  1416. }, function (v) {
  1417. before(v, element);
  1418. });
  1419. };
  1420. var prepend = function (parent, element) {
  1421. var firstChild$1 = firstChild(parent);
  1422. firstChild$1.fold(function () {
  1423. append(parent, element);
  1424. }, function (v) {
  1425. parent.dom().insertBefore(element.dom(), v.dom());
  1426. });
  1427. };
  1428. var append = function (parent, element) {
  1429. parent.dom().appendChild(element.dom());
  1430. };
  1431. var appendAt = function (parent, element, index) {
  1432. child(parent, index).fold(function () {
  1433. append(parent, element);
  1434. }, function (v) {
  1435. before(v, element);
  1436. });
  1437. };
  1438. var append$1 = function (parent, elements) {
  1439. each(elements, function (x) {
  1440. append(parent, x);
  1441. });
  1442. };
  1443. var empty = function (element) {
  1444. element.dom().textContent = '';
  1445. each(children(element), function (rogue) {
  1446. remove(rogue);
  1447. });
  1448. };
  1449. var remove = function (element) {
  1450. var dom = element.dom();
  1451. if (dom.parentNode !== null) {
  1452. dom.parentNode.removeChild(dom);
  1453. }
  1454. };
  1455. var get$1 = function (element) {
  1456. return element.dom().innerHTML;
  1457. };
  1458. var set = function (element, content) {
  1459. var owner$1 = owner(element);
  1460. var docDom = owner$1.dom();
  1461. var fragment = Element.fromDom(docDom.createDocumentFragment());
  1462. var contentElements = fromHtml$1(content, docDom);
  1463. append$1(fragment, contentElements);
  1464. empty(element);
  1465. append(element, fragment);
  1466. };
  1467. var getOuter = function (element) {
  1468. var container = Element.fromTag('div');
  1469. var clone = Element.fromDom(element.dom().cloneNode(true));
  1470. append(container, clone);
  1471. return get$1(container);
  1472. };
  1473. var name = function (element) {
  1474. var r = element.dom().nodeName;
  1475. return r.toLowerCase();
  1476. };
  1477. var type = function (element) {
  1478. return element.dom().nodeType;
  1479. };
  1480. var isType$1 = function (t) {
  1481. return function (element) {
  1482. return type(element) === t;
  1483. };
  1484. };
  1485. var isElement = isType$1(ELEMENT);
  1486. var isText = isType$1(TEXT);
  1487. var isDocument = isType$1(DOCUMENT);
  1488. var rawSet = function (dom, key, value) {
  1489. if (isString(value) || isBoolean(value) || isNumber(value)) {
  1490. dom.setAttribute(key, value + '');
  1491. } else {
  1492. domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  1493. throw new Error('Attribute value was not simple');
  1494. }
  1495. };
  1496. var set$1 = function (element, key, value) {
  1497. rawSet(element.dom(), key, value);
  1498. };
  1499. var setAll = function (element, attrs) {
  1500. var dom = element.dom();
  1501. each$1(attrs, function (v, k) {
  1502. rawSet(dom, k, v);
  1503. });
  1504. };
  1505. var get$2 = function (element, key) {
  1506. var v = element.dom().getAttribute(key);
  1507. return v === null ? undefined : v;
  1508. };
  1509. var has$1 = function (element, key) {
  1510. var dom = element.dom();
  1511. return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
  1512. };
  1513. var remove$1 = function (element, key) {
  1514. element.dom().removeAttribute(key);
  1515. };
  1516. var clone = function (original, isDeep) {
  1517. return Element.fromDom(original.dom().cloneNode(isDeep));
  1518. };
  1519. var shallow$1 = function (original) {
  1520. return clone(original, false);
  1521. };
  1522. var getHtml = function (element) {
  1523. var clone = shallow$1(element);
  1524. return getOuter(clone);
  1525. };
  1526. var element = function (elem) {
  1527. return getHtml(elem);
  1528. };
  1529. var unknown$3 = 'unknown';
  1530. var CHROME_INSPECTOR_GLOBAL = '__CHROME_INSPECTOR_CONNECTION_TO_ALLOY__';
  1531. var EventConfiguration;
  1532. (function (EventConfiguration) {
  1533. EventConfiguration[EventConfiguration['STOP'] = 0] = 'STOP';
  1534. EventConfiguration[EventConfiguration['NORMAL'] = 1] = 'NORMAL';
  1535. EventConfiguration[EventConfiguration['LOGGING'] = 2] = 'LOGGING';
  1536. }(EventConfiguration || (EventConfiguration = {})));
  1537. var eventConfig = Cell({});
  1538. var makeEventLogger = function (eventName, initialTarget) {
  1539. var sequence = [];
  1540. var startTime = new Date().getTime();
  1541. return {
  1542. logEventCut: function (name, target, purpose) {
  1543. sequence.push({
  1544. outcome: 'cut',
  1545. target: target,
  1546. purpose: purpose
  1547. });
  1548. },
  1549. logEventStopped: function (name, target, purpose) {
  1550. sequence.push({
  1551. outcome: 'stopped',
  1552. target: target,
  1553. purpose: purpose
  1554. });
  1555. },
  1556. logNoParent: function (name, target, purpose) {
  1557. sequence.push({
  1558. outcome: 'no-parent',
  1559. target: target,
  1560. purpose: purpose
  1561. });
  1562. },
  1563. logEventNoHandlers: function (name, target) {
  1564. sequence.push({
  1565. outcome: 'no-handlers-left',
  1566. target: target
  1567. });
  1568. },
  1569. logEventResponse: function (name, target, purpose) {
  1570. sequence.push({
  1571. outcome: 'response',
  1572. purpose: purpose,
  1573. target: target
  1574. });
  1575. },
  1576. write: function () {
  1577. var finishTime = new Date().getTime();
  1578. if (contains([
  1579. 'mousemove',
  1580. 'mouseover',
  1581. 'mouseout',
  1582. systemInit()
  1583. ], eventName)) {
  1584. return;
  1585. }
  1586. domGlobals.console.log(eventName, {
  1587. event: eventName,
  1588. time: finishTime - startTime,
  1589. target: initialTarget.dom(),
  1590. sequence: map(sequence, function (s) {
  1591. if (!contains([
  1592. 'cut',
  1593. 'stopped',
  1594. 'response'
  1595. ], s.outcome)) {
  1596. return s.outcome;
  1597. } else {
  1598. return '{' + s.purpose + '} ' + s.outcome + ' at (' + element(s.target) + ')';
  1599. }
  1600. })
  1601. });
  1602. }
  1603. };
  1604. };
  1605. var processEvent = function (eventName, initialTarget, f) {
  1606. var status = readOptFrom$1(eventConfig.get(), eventName).orThunk(function () {
  1607. var patterns = keys(eventConfig.get());
  1608. return findMap(patterns, function (p) {
  1609. return eventName.indexOf(p) > -1 ? Option.some(eventConfig.get()[p]) : Option.none();
  1610. });
  1611. }).getOr(EventConfiguration.NORMAL);
  1612. switch (status) {
  1613. case EventConfiguration.NORMAL:
  1614. return f(noLogger());
  1615. case EventConfiguration.LOGGING: {
  1616. var logger = makeEventLogger(eventName, initialTarget);
  1617. var output = f(logger);
  1618. logger.write();
  1619. return output;
  1620. }
  1621. case EventConfiguration.STOP:
  1622. return true;
  1623. }
  1624. };
  1625. var path$1 = [
  1626. 'alloy/data/Fields',
  1627. 'alloy/debugging/Debugging'
  1628. ];
  1629. var getTrace = function () {
  1630. var err = new Error();
  1631. if (err.stack !== undefined) {
  1632. var lines = err.stack.split('\n');
  1633. return find(lines, function (line) {
  1634. return line.indexOf('alloy') > 0 && !exists(path$1, function (p) {
  1635. return line.indexOf(p) > -1;
  1636. });
  1637. }).getOr(unknown$3);
  1638. } else {
  1639. return unknown$3;
  1640. }
  1641. };
  1642. var ignoreEvent = {
  1643. logEventCut: noop,
  1644. logEventStopped: noop,
  1645. logNoParent: noop,
  1646. logEventNoHandlers: noop,
  1647. logEventResponse: noop,
  1648. write: noop
  1649. };
  1650. var monitorEvent = function (eventName, initialTarget, f) {
  1651. return processEvent(eventName, initialTarget, f);
  1652. };
  1653. var inspectorInfo = function (comp) {
  1654. var go = function (c) {
  1655. var cSpec = c.spec();
  1656. return {
  1657. '(original.spec)': cSpec,
  1658. '(dom.ref)': c.element().dom(),
  1659. '(element)': element(c.element()),
  1660. '(initComponents)': map(cSpec.components !== undefined ? cSpec.components : [], go),
  1661. '(components)': map(c.components(), go),
  1662. '(bound.events)': mapToArray(c.events(), function (v, k) {
  1663. return [k];
  1664. }).join(', '),
  1665. '(behaviours)': cSpec.behaviours !== undefined ? map$1(cSpec.behaviours, function (v, k) {
  1666. return v === undefined ? '--revoked--' : {
  1667. 'config': v.configAsRaw(),
  1668. 'original-config': v.initialConfig,
  1669. 'state': c.readState(k)
  1670. };
  1671. }) : 'none'
  1672. };
  1673. };
  1674. return go(comp);
  1675. };
  1676. var getOrInitConnection = function () {
  1677. if (domGlobals.window[CHROME_INSPECTOR_GLOBAL] !== undefined) {
  1678. return domGlobals.window[CHROME_INSPECTOR_GLOBAL];
  1679. } else {
  1680. var setEventStatus_1 = function (eventName, status) {
  1681. var evs = eventConfig.get();
  1682. evs[eventName] = status;
  1683. eventConfig.set(evs);
  1684. };
  1685. domGlobals.window[CHROME_INSPECTOR_GLOBAL] = {
  1686. systems: {},
  1687. lookup: function (uid) {
  1688. var systems = domGlobals.window[CHROME_INSPECTOR_GLOBAL].systems;
  1689. var connections = keys(systems);
  1690. return findMap(connections, function (conn) {
  1691. var connGui = systems[conn];
  1692. return connGui.getByUid(uid).toOption().map(function (comp) {
  1693. return wrap$1(element(comp.element()), inspectorInfo(comp));
  1694. });
  1695. }).orThunk(function () {
  1696. return Option.some({ error: 'Systems (' + connections.join(', ') + ') did not contain uid: ' + uid });
  1697. });
  1698. },
  1699. events: {
  1700. setToNormal: function (eventName) {
  1701. setEventStatus_1(eventName, EventConfiguration.NORMAL);
  1702. },
  1703. setToLogging: function (eventName) {
  1704. setEventStatus_1(eventName, EventConfiguration.LOGGING);
  1705. },
  1706. setToStop: function (eventName) {
  1707. setEventStatus_1(eventName, EventConfiguration.STOP);
  1708. }
  1709. }
  1710. };
  1711. return domGlobals.window[CHROME_INSPECTOR_GLOBAL];
  1712. }
  1713. };
  1714. var registerInspector = function (name, gui) {
  1715. var connection = getOrInitConnection();
  1716. connection.systems[name] = gui;
  1717. };
  1718. var noLogger = constant(ignoreEvent);
  1719. var unique = 0;
  1720. var generate$1 = function (prefix) {
  1721. var date = new Date();
  1722. var time = date.getTime();
  1723. var random = Math.floor(Math.random() * 1000000000);
  1724. unique++;
  1725. return prefix + '_' + random + unique + String(time);
  1726. };
  1727. var global = tinymce.util.Tools.resolve('tinymce.ThemeManager');
  1728. var __assign = function () {
  1729. __assign = Object.assign || function __assign(t) {
  1730. for (var s, i = 1, n = arguments.length; i < n; i++) {
  1731. s = arguments[i];
  1732. for (var p in s)
  1733. if (Object.prototype.hasOwnProperty.call(s, p))
  1734. t[p] = s[p];
  1735. }
  1736. return t;
  1737. };
  1738. return __assign.apply(this, arguments);
  1739. };
  1740. function __rest(s, e) {
  1741. var t = {};
  1742. for (var p in s)
  1743. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  1744. t[p] = s[p];
  1745. if (s != null && typeof Object.getOwnPropertySymbols === 'function')
  1746. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
  1747. if (e.indexOf(p[i]) < 0)
  1748. t[p[i]] = s[p[i]];
  1749. return t;
  1750. }
  1751. var adt = Adt.generate([
  1752. { strict: [] },
  1753. { defaultedThunk: ['fallbackThunk'] },
  1754. { asOption: [] },
  1755. { asDefaultedOptionThunk: ['fallbackThunk'] },
  1756. { mergeWithThunk: ['baseThunk'] }
  1757. ]);
  1758. var defaulted = function (fallback) {
  1759. return adt.defaultedThunk(constant(fallback));
  1760. };
  1761. var mergeWith = function (base) {
  1762. return adt.mergeWithThunk(constant(base));
  1763. };
  1764. var strict = adt.strict;
  1765. var asOption = adt.asOption;
  1766. var defaultedThunk = adt.defaultedThunk;
  1767. var mergeWithThunk = adt.mergeWithThunk;
  1768. var SimpleResultType;
  1769. (function (SimpleResultType) {
  1770. SimpleResultType[SimpleResultType['Error'] = 0] = 'Error';
  1771. SimpleResultType[SimpleResultType['Value'] = 1] = 'Value';
  1772. }(SimpleResultType || (SimpleResultType = {})));
  1773. var fold = function (res, onError, onValue) {
  1774. return res.stype === SimpleResultType.Error ? onError(res.serror) : onValue(res.svalue);
  1775. };
  1776. var partition$2 = function (results) {
  1777. var values = [];
  1778. var errors = [];
  1779. each(results, function (obj) {
  1780. fold(obj, function (err) {
  1781. return errors.push(err);
  1782. }, function (val) {
  1783. return values.push(val);
  1784. });
  1785. });
  1786. return {
  1787. values: values,
  1788. errors: errors
  1789. };
  1790. };
  1791. var mapError = function (res, f) {
  1792. if (res.stype === SimpleResultType.Error) {
  1793. return {
  1794. stype: SimpleResultType.Error,
  1795. serror: f(res.serror)
  1796. };
  1797. } else {
  1798. return res;
  1799. }
  1800. };
  1801. var map$2 = function (res, f) {
  1802. if (res.stype === SimpleResultType.Value) {
  1803. return {
  1804. stype: SimpleResultType.Value,
  1805. svalue: f(res.svalue)
  1806. };
  1807. } else {
  1808. return res;
  1809. }
  1810. };
  1811. var bind$1 = function (res, f) {
  1812. if (res.stype === SimpleResultType.Value) {
  1813. return f(res.svalue);
  1814. } else {
  1815. return res;
  1816. }
  1817. };
  1818. var bindError = function (res, f) {
  1819. if (res.stype === SimpleResultType.Error) {
  1820. return f(res.serror);
  1821. } else {
  1822. return res;
  1823. }
  1824. };
  1825. var svalue = function (v) {
  1826. return {
  1827. stype: SimpleResultType.Value,
  1828. svalue: v
  1829. };
  1830. };
  1831. var serror = function (e) {
  1832. return {
  1833. stype: SimpleResultType.Error,
  1834. serror: e
  1835. };
  1836. };
  1837. var toResult = function (res) {
  1838. return fold(res, Result.error, Result.value);
  1839. };
  1840. var fromResult = function (res) {
  1841. return res.fold(serror, svalue);
  1842. };
  1843. var SimpleResult = {
  1844. fromResult: fromResult,
  1845. toResult: toResult,
  1846. svalue: svalue,
  1847. partition: partition$2,
  1848. serror: serror,
  1849. bind: bind$1,
  1850. bindError: bindError,
  1851. map: map$2,
  1852. mapError: mapError,
  1853. fold: fold
  1854. };
  1855. var mergeValues$1 = function (values, base) {
  1856. return values.length > 0 ? SimpleResult.svalue(deepMerge(base, merge.apply(undefined, values))) : SimpleResult.svalue(base);
  1857. };
  1858. var mergeErrors$1 = function (errors) {
  1859. return compose(SimpleResult.serror, flatten)(errors);
  1860. };
  1861. var consolidateObj = function (objects, base) {
  1862. var partition = SimpleResult.partition(objects);
  1863. return partition.errors.length > 0 ? mergeErrors$1(partition.errors) : mergeValues$1(partition.values, base);
  1864. };
  1865. var consolidateArr = function (objects) {
  1866. var partitions = SimpleResult.partition(objects);
  1867. return partitions.errors.length > 0 ? mergeErrors$1(partitions.errors) : SimpleResult.svalue(partitions.values);
  1868. };
  1869. var ResultCombine = {
  1870. consolidateObj: consolidateObj,
  1871. consolidateArr: consolidateArr
  1872. };
  1873. var typeAdt = Adt.generate([
  1874. {
  1875. setOf: [
  1876. 'validator',
  1877. 'valueType'
  1878. ]
  1879. },
  1880. { arrOf: ['valueType'] },
  1881. { objOf: ['fields'] },
  1882. { itemOf: ['validator'] },
  1883. {
  1884. choiceOf: [
  1885. 'key',
  1886. 'branches'
  1887. ]
  1888. },
  1889. { thunk: ['description'] },
  1890. {
  1891. func: [
  1892. 'args',
  1893. 'outputSchema'
  1894. ]
  1895. }
  1896. ]);
  1897. var fieldAdt = Adt.generate([
  1898. {
  1899. field: [
  1900. 'name',
  1901. 'presence',
  1902. 'type'
  1903. ]
  1904. },
  1905. { state: ['name'] }
  1906. ]);
  1907. var json = function () {
  1908. return Global$1.getOrDie('JSON');
  1909. };
  1910. var parse = function (text) {
  1911. return json().parse(text);
  1912. };
  1913. var stringify = function (obj, replacer, space) {
  1914. return json().stringify(obj, replacer, space);
  1915. };
  1916. var JSON$1 = {
  1917. parse: parse,
  1918. stringify: stringify
  1919. };
  1920. var formatObj = function (input) {
  1921. return isObject(input) && keys(input).length > 100 ? ' removed due to size' : JSON$1.stringify(input, null, 2);
  1922. };
  1923. var formatErrors = function (errors) {
  1924. var es = errors.length > 10 ? errors.slice(0, 10).concat([{
  1925. path: [],
  1926. getErrorInfo: function () {
  1927. return '... (only showing first ten failures)';
  1928. }
  1929. }]) : errors;
  1930. return map(es, function (e) {
  1931. return 'Failed path: (' + e.path.join(' > ') + ')\n' + e.getErrorInfo();
  1932. });
  1933. };
  1934. var nu$3 = function (path, getErrorInfo) {
  1935. return SimpleResult.serror([{
  1936. path: path,
  1937. getErrorInfo: getErrorInfo
  1938. }]);
  1939. };
  1940. var missingStrict = function (path, key, obj) {
  1941. return nu$3(path, function () {
  1942. return 'Could not find valid *strict* value for "' + key + '" in ' + formatObj(obj);
  1943. });
  1944. };
  1945. var missingKey = function (path, key) {
  1946. return nu$3(path, function () {
  1947. return 'Choice schema did not contain choice key: "' + key + '"';
  1948. });
  1949. };
  1950. var missingBranch = function (path, branches, branch) {
  1951. return nu$3(path, function () {
  1952. return 'The chosen schema: "' + branch + '" did not exist in branches: ' + formatObj(branches);
  1953. });
  1954. };
  1955. var unsupportedFields = function (path, unsupported) {
  1956. return nu$3(path, function () {
  1957. return 'There are unsupported fields: [' + unsupported.join(', ') + '] specified';
  1958. });
  1959. };
  1960. var custom = function (path, err) {
  1961. return nu$3(path, function () {
  1962. return err;
  1963. });
  1964. };
  1965. var adt$1 = Adt.generate([
  1966. {
  1967. field: [
  1968. 'key',
  1969. 'okey',
  1970. 'presence',
  1971. 'prop'
  1972. ]
  1973. },
  1974. {
  1975. state: [
  1976. 'okey',
  1977. 'instantiator'
  1978. ]
  1979. }
  1980. ]);
  1981. var strictAccess = function (path, obj, key) {
  1982. return readOptFrom(obj, key).fold(function () {
  1983. return missingStrict(path, key, obj);
  1984. }, SimpleResult.svalue);
  1985. };
  1986. var fallbackAccess = function (obj, key, fallbackThunk) {
  1987. var v = readOptFrom(obj, key).fold(function () {
  1988. return fallbackThunk(obj);
  1989. }, identity);
  1990. return SimpleResult.svalue(v);
  1991. };
  1992. var optionAccess = function (obj, key) {
  1993. return SimpleResult.svalue(readOptFrom(obj, key));
  1994. };
  1995. var optionDefaultedAccess = function (obj, key, fallback) {
  1996. var opt = readOptFrom(obj, key).map(function (val) {
  1997. return val === true ? fallback(obj) : val;
  1998. });
  1999. return SimpleResult.svalue(opt);
  2000. };
  2001. var cExtractOne = function (path, obj, field, strength) {
  2002. return field.fold(function (key, okey, presence, prop) {
  2003. var bundle = function (av) {
  2004. var result = prop.extract(path.concat([key]), strength, av);
  2005. return SimpleResult.map(result, function (res) {
  2006. return wrap(okey, strength(res));
  2007. });
  2008. };
  2009. var bundleAsOption = function (optValue) {
  2010. return optValue.fold(function () {
  2011. var outcome = wrap(okey, strength(Option.none()));
  2012. return SimpleResult.svalue(outcome);
  2013. }, function (ov) {
  2014. var result = prop.extract(path.concat([key]), strength, ov);
  2015. return SimpleResult.map(result, function (res) {
  2016. return wrap(okey, strength(Option.some(res)));
  2017. });
  2018. });
  2019. };
  2020. return function () {
  2021. return presence.fold(function () {
  2022. return SimpleResult.bind(strictAccess(path, obj, key), bundle);
  2023. }, function (fallbackThunk) {
  2024. return SimpleResult.bind(fallbackAccess(obj, key, fallbackThunk), bundle);
  2025. }, function () {
  2026. return SimpleResult.bind(optionAccess(obj, key), bundleAsOption);
  2027. }, function (fallbackThunk) {
  2028. return SimpleResult.bind(optionDefaultedAccess(obj, key, fallbackThunk), bundleAsOption);
  2029. }, function (baseThunk) {
  2030. var base = baseThunk(obj);
  2031. var result = SimpleResult.map(fallbackAccess(obj, key, constant({})), function (v) {
  2032. return deepMerge(base, v);
  2033. });
  2034. return SimpleResult.bind(result, bundle);
  2035. });
  2036. }();
  2037. }, function (okey, instantiator) {
  2038. var state = instantiator(obj);
  2039. return SimpleResult.svalue(wrap(okey, strength(state)));
  2040. });
  2041. };
  2042. var cExtract = function (path, obj, fields, strength) {
  2043. var results = map(fields, function (field) {
  2044. return cExtractOne(path, obj, field, strength);
  2045. });
  2046. return ResultCombine.consolidateObj(results, {});
  2047. };
  2048. var value$1 = function (validator) {
  2049. var extract = function (path, strength, val) {
  2050. return SimpleResult.bindError(validator(val, strength), function (err) {
  2051. return custom(path, err);
  2052. });
  2053. };
  2054. var toString = function () {
  2055. return 'val';
  2056. };
  2057. var toDsl = function () {
  2058. return typeAdt.itemOf(validator);
  2059. };
  2060. return {
  2061. extract: extract,
  2062. toString: toString,
  2063. toDsl: toDsl
  2064. };
  2065. };
  2066. var getSetKeys = function (obj) {
  2067. var keys$1 = keys(obj);
  2068. return filter(keys$1, function (k) {
  2069. return hasKey$1(obj, k);
  2070. });
  2071. };
  2072. var objOfOnly = function (fields) {
  2073. var delegate = objOf(fields);
  2074. var fieldNames = foldr(fields, function (acc, f) {
  2075. return f.fold(function (key) {
  2076. return deepMerge(acc, wrap$1(key, true));
  2077. }, constant(acc));
  2078. }, {});
  2079. var extract = function (path, strength, o) {
  2080. var keys = isBoolean(o) ? [] : getSetKeys(o);
  2081. var extra = filter(keys, function (k) {
  2082. return !hasKey$1(fieldNames, k);
  2083. });
  2084. return extra.length === 0 ? delegate.extract(path, strength, o) : unsupportedFields(path, extra);
  2085. };
  2086. return {
  2087. extract: extract,
  2088. toString: delegate.toString,
  2089. toDsl: delegate.toDsl
  2090. };
  2091. };
  2092. var objOf = function (fields) {
  2093. var extract = function (path, strength, o) {
  2094. return cExtract(path, o, fields, strength);
  2095. };
  2096. var toString = function () {
  2097. var fieldStrings = map(fields, function (field) {
  2098. return field.fold(function (key, okey, presence, prop) {
  2099. return key + ' -> ' + prop.toString();
  2100. }, function (okey, instantiator) {
  2101. return 'state(' + okey + ')';
  2102. });
  2103. });
  2104. return 'obj{\n' + fieldStrings.join('\n') + '}';
  2105. };
  2106. var toDsl = function () {
  2107. return typeAdt.objOf(map(fields, function (f) {
  2108. return f.fold(function (key, okey, presence, prop) {
  2109. return fieldAdt.field(key, presence, prop);
  2110. }, function (okey, instantiator) {
  2111. return fieldAdt.state(okey);
  2112. });
  2113. }));
  2114. };
  2115. return {
  2116. extract: extract,
  2117. toString: toString,
  2118. toDsl: toDsl
  2119. };
  2120. };
  2121. var arrOf = function (prop) {
  2122. var extract = function (path, strength, array) {
  2123. var results = map(array, function (a, i) {
  2124. return prop.extract(path.concat(['[' + i + ']']), strength, a);
  2125. });
  2126. return ResultCombine.consolidateArr(results);
  2127. };
  2128. var toString = function () {
  2129. return 'array(' + prop.toString() + ')';
  2130. };
  2131. var toDsl = function () {
  2132. return typeAdt.arrOf(prop);
  2133. };
  2134. return {
  2135. extract: extract,
  2136. toString: toString,
  2137. toDsl: toDsl
  2138. };
  2139. };
  2140. var setOf = function (validator, prop) {
  2141. var validateKeys = function (path, keys) {
  2142. return arrOf(value$1(validator)).extract(path, identity, keys);
  2143. };
  2144. var extract = function (path, strength, o) {
  2145. var keys$1 = keys(o);
  2146. var validatedKeys = validateKeys(path, keys$1);
  2147. return SimpleResult.bind(validatedKeys, function (validKeys) {
  2148. var schema = map(validKeys, function (vk) {
  2149. return adt$1.field(vk, vk, strict(), prop);
  2150. });
  2151. return objOf(schema).extract(path, strength, o);
  2152. });
  2153. };
  2154. var toString = function () {
  2155. return 'setOf(' + prop.toString() + ')';
  2156. };
  2157. var toDsl = function () {
  2158. return typeAdt.setOf(validator, prop);
  2159. };
  2160. return {
  2161. extract: extract,
  2162. toString: toString,
  2163. toDsl: toDsl
  2164. };
  2165. };
  2166. var anyValue = constant(value$1(SimpleResult.svalue));
  2167. var arrOfObj = compose(arrOf, objOf);
  2168. var state = adt$1.state;
  2169. var field = adt$1.field;
  2170. var chooseFrom = function (path, strength, input, branches, ch) {
  2171. var fields = readOptFrom$1(branches, ch);
  2172. return fields.fold(function () {
  2173. return missingBranch(path, branches, ch);
  2174. }, function (fs) {
  2175. return objOf(fs).extract(path.concat(['branch: ' + ch]), strength, input);
  2176. });
  2177. };
  2178. var choose = function (key, branches) {
  2179. var extract = function (path, strength, input) {
  2180. var choice = readOptFrom$1(input, key);
  2181. return choice.fold(function () {
  2182. return missingKey(path, key);
  2183. }, function (chosen) {
  2184. return chooseFrom(path, strength, input, branches, chosen);
  2185. });
  2186. };
  2187. var toString = function () {
  2188. return 'chooseOn(' + key + '). Possible values: ' + keys(branches);
  2189. };
  2190. var toDsl = function () {
  2191. return typeAdt.choiceOf(key, branches);
  2192. };
  2193. return {
  2194. extract: extract,
  2195. toString: toString,
  2196. toDsl: toDsl
  2197. };
  2198. };
  2199. var _anyValue = value$1(SimpleResult.svalue);
  2200. var arrOfObj$1 = function (objFields) {
  2201. return arrOfObj(objFields);
  2202. };
  2203. var arrOfVal = function () {
  2204. return arrOf(_anyValue);
  2205. };
  2206. var valueOf = function (validator) {
  2207. return value$1(function (v) {
  2208. return validator(v).fold(SimpleResult.serror, SimpleResult.svalue);
  2209. });
  2210. };
  2211. var setOf$1 = function (validator, prop) {
  2212. return setOf(function (v) {
  2213. return SimpleResult.fromResult(validator(v));
  2214. }, prop);
  2215. };
  2216. var extract = function (label, prop, strength, obj) {
  2217. var res = prop.extract([label], strength, obj);
  2218. return SimpleResult.mapError(res, function (errs) {
  2219. return {
  2220. input: obj,
  2221. errors: errs
  2222. };
  2223. });
  2224. };
  2225. var asRaw = function (label, prop, obj) {
  2226. return SimpleResult.toResult(extract(label, prop, identity, obj));
  2227. };
  2228. var getOrDie$1 = function (extraction) {
  2229. return extraction.fold(function (errInfo) {
  2230. throw new Error(formatError(errInfo));
  2231. }, identity);
  2232. };
  2233. var asRawOrDie = function (label, prop, obj) {
  2234. return getOrDie$1(asRaw(label, prop, obj));
  2235. };
  2236. var formatError = function (errInfo) {
  2237. return 'Errors: \n' + formatErrors(errInfo.errors) + '\n\nInput object: ' + formatObj(errInfo.input);
  2238. };
  2239. var choose$1 = function (key, branches) {
  2240. return choose(key, branches);
  2241. };
  2242. var anyValue$1 = constant(_anyValue);
  2243. var typedValue = function (validator, expectedType) {
  2244. return value$1(function (a) {
  2245. var actualType = typeof a;
  2246. return validator(a) ? SimpleResult.svalue(a) : SimpleResult.serror('Expected type: ' + expectedType + ' but got: ' + actualType);
  2247. });
  2248. };
  2249. var number = typedValue(isNumber, 'number');
  2250. var string = typedValue(isString, 'string');
  2251. var boolean = typedValue(isBoolean, 'boolean');
  2252. var functionProcessor = typedValue(isFunction, 'function');
  2253. var validateEnum = function (values) {
  2254. return valueOf(function (value) {
  2255. return contains(values, value) ? Result.value(value) : Result.error('Unsupported value: "' + value + '", choose one of "' + values.join(', ') + '".');
  2256. });
  2257. };
  2258. var strict$1 = function (key) {
  2259. return field(key, key, strict(), anyValue());
  2260. };
  2261. var strictOf = function (key, schema) {
  2262. return field(key, key, strict(), schema);
  2263. };
  2264. var strictNumber = function (key) {
  2265. return strictOf(key, number);
  2266. };
  2267. var strictString = function (key) {
  2268. return strictOf(key, string);
  2269. };
  2270. var strictStringEnum = function (key, values) {
  2271. return field(key, key, strict(), validateEnum(values));
  2272. };
  2273. var strictFunction = function (key) {
  2274. return strictOf(key, functionProcessor);
  2275. };
  2276. var forbid = function (key, message) {
  2277. return field(key, key, asOption(), value$1(function (v) {
  2278. return SimpleResult.serror('The field: ' + key + ' is forbidden. ' + message);
  2279. }));
  2280. };
  2281. var strictObjOf = function (key, objSchema) {
  2282. return field(key, key, strict(), objOf(objSchema));
  2283. };
  2284. var strictArrayOfObj = function (key, objFields) {
  2285. return field(key, key, strict(), arrOfObj(objFields));
  2286. };
  2287. var strictArrayOf = function (key, schema) {
  2288. return field(key, key, strict(), arrOf(schema));
  2289. };
  2290. var option = function (key) {
  2291. return field(key, key, asOption(), anyValue());
  2292. };
  2293. var optionOf = function (key, schema) {
  2294. return field(key, key, asOption(), schema);
  2295. };
  2296. var optionString = function (key) {
  2297. return optionOf(key, string);
  2298. };
  2299. var optionFunction = function (key) {
  2300. return optionOf(key, functionProcessor);
  2301. };
  2302. var optionObjOf = function (key, objSchema) {
  2303. return field(key, key, asOption(), objOf(objSchema));
  2304. };
  2305. var optionObjOfOnly = function (key, objSchema) {
  2306. return field(key, key, asOption(), objOfOnly(objSchema));
  2307. };
  2308. var defaulted$1 = function (key, fallback) {
  2309. return field(key, key, defaulted(fallback), anyValue());
  2310. };
  2311. var defaultedOf = function (key, fallback, schema) {
  2312. return field(key, key, defaulted(fallback), schema);
  2313. };
  2314. var defaultedNumber = function (key, fallback) {
  2315. return defaultedOf(key, fallback, number);
  2316. };
  2317. var defaultedString = function (key, fallback) {
  2318. return defaultedOf(key, fallback, string);
  2319. };
  2320. var defaultedStringEnum = function (key, fallback, values) {
  2321. return defaultedOf(key, fallback, validateEnum(values));
  2322. };
  2323. var defaultedBoolean = function (key, fallback) {
  2324. return defaultedOf(key, fallback, boolean);
  2325. };
  2326. var defaultedFunction = function (key, fallback) {
  2327. return defaultedOf(key, fallback, functionProcessor);
  2328. };
  2329. var defaultedObjOf = function (key, fallback, objSchema) {
  2330. return field(key, key, defaulted(fallback), objOf(objSchema));
  2331. };
  2332. var state$1 = function (okey, instantiator) {
  2333. return state(okey, instantiator);
  2334. };
  2335. var isSource = function (component, simulatedEvent) {
  2336. return eq(component.element(), simulatedEvent.event().target());
  2337. };
  2338. var nu$4 = function (parts) {
  2339. if (!hasKey$1(parts, 'can') && !hasKey$1(parts, 'abort') && !hasKey$1(parts, 'run')) {
  2340. throw new Error('EventHandler defined by: ' + JSON$1.stringify(parts, null, 2) + ' does not have can, abort, or run!');
  2341. }
  2342. return asRawOrDie('Extracting event.handler', objOfOnly([
  2343. defaulted$1('can', constant(true)),
  2344. defaulted$1('abort', constant(false)),
  2345. defaulted$1('run', noop)
  2346. ]), parts);
  2347. };
  2348. var all$1 = function (handlers, f) {
  2349. return function () {
  2350. var args = [];
  2351. for (var _i = 0; _i < arguments.length; _i++) {
  2352. args[_i] = arguments[_i];
  2353. }
  2354. return foldl(handlers, function (acc, handler) {
  2355. return acc && f(handler).apply(undefined, args);
  2356. }, true);
  2357. };
  2358. };
  2359. var any = function (handlers, f) {
  2360. return function () {
  2361. var args = [];
  2362. for (var _i = 0; _i < arguments.length; _i++) {
  2363. args[_i] = arguments[_i];
  2364. }
  2365. return foldl(handlers, function (acc, handler) {
  2366. return acc || f(handler).apply(undefined, args);
  2367. }, false);
  2368. };
  2369. };
  2370. var read = function (handler) {
  2371. return isFunction(handler) ? {
  2372. can: constant(true),
  2373. abort: constant(false),
  2374. run: handler
  2375. } : handler;
  2376. };
  2377. var fuse = function (handlers) {
  2378. var can = all$1(handlers, function (handler) {
  2379. return handler.can;
  2380. });
  2381. var abort = any(handlers, function (handler) {
  2382. return handler.abort;
  2383. });
  2384. var run = function () {
  2385. var args = [];
  2386. for (var _i = 0; _i < arguments.length; _i++) {
  2387. args[_i] = arguments[_i];
  2388. }
  2389. each(handlers, function (handler) {
  2390. handler.run.apply(undefined, args);
  2391. });
  2392. };
  2393. return nu$4({
  2394. can: can,
  2395. abort: abort,
  2396. run: run
  2397. });
  2398. };
  2399. var emit = function (component, event) {
  2400. dispatchWith(component, component.element(), event, {});
  2401. };
  2402. var emitWith = function (component, event, properties) {
  2403. dispatchWith(component, component.element(), event, properties);
  2404. };
  2405. var emitExecute = function (component) {
  2406. emit(component, execute());
  2407. };
  2408. var dispatch = function (component, target, event) {
  2409. dispatchWith(component, target, event, {});
  2410. };
  2411. var dispatchWith = function (component, target, event, properties) {
  2412. var data = __assign({ target: target }, properties);
  2413. component.getSystem().triggerEvent(event, target, map$1(data, constant));
  2414. };
  2415. var dispatchEvent = function (component, target, event, simulatedEvent) {
  2416. component.getSystem().triggerEvent(event, target, simulatedEvent.event());
  2417. };
  2418. function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
  2419. return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
  2420. }
  2421. var inBody = function (element) {
  2422. var dom = isText(element) ? element.dom().parentNode : element.dom();
  2423. return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
  2424. };
  2425. var body = cached(function () {
  2426. return getBody(Element.fromDom(domGlobals.document));
  2427. });
  2428. var getBody = function (doc) {
  2429. var b = doc.dom().body;
  2430. if (b === null || b === undefined) {
  2431. throw new Error('Body is not available yet');
  2432. }
  2433. return Element.fromDom(b);
  2434. };
  2435. var ancestor = function (scope, predicate, isRoot) {
  2436. var element = scope.dom();
  2437. var stop = isFunction(isRoot) ? isRoot : constant(false);
  2438. while (element.parentNode) {
  2439. element = element.parentNode;
  2440. var el = Element.fromDom(element);
  2441. if (predicate(el)) {
  2442. return Option.some(el);
  2443. } else if (stop(el)) {
  2444. break;
  2445. }
  2446. }
  2447. return Option.none();
  2448. };
  2449. var closest = function (scope, predicate, isRoot) {
  2450. var is = function (s) {
  2451. return predicate(s);
  2452. };
  2453. return ClosestOrAncestor(is, ancestor, scope, predicate, isRoot);
  2454. };
  2455. var descendant = function (scope, predicate) {
  2456. var descend = function (node) {
  2457. for (var i = 0; i < node.childNodes.length; i++) {
  2458. if (predicate(Element.fromDom(node.childNodes[i]))) {
  2459. return Option.some(Element.fromDom(node.childNodes[i]));
  2460. }
  2461. var res = descend(node.childNodes[i]);
  2462. if (res.isSome()) {
  2463. return res;
  2464. }
  2465. }
  2466. return Option.none();
  2467. };
  2468. return descend(scope.dom());
  2469. };
  2470. var closest$1 = function (target, transform, isRoot) {
  2471. var delegate = closest(target, function (elem) {
  2472. return transform(elem).isSome();
  2473. }, isRoot);
  2474. return delegate.bind(transform);
  2475. };
  2476. var derive = function (configs) {
  2477. return wrapAll$1(configs);
  2478. };
  2479. var abort = function (name, predicate) {
  2480. return {
  2481. key: name,
  2482. value: nu$4({ abort: predicate })
  2483. };
  2484. };
  2485. var can = function (name, predicate) {
  2486. return {
  2487. key: name,
  2488. value: nu$4({ can: predicate })
  2489. };
  2490. };
  2491. var preventDefault = function (name) {
  2492. return {
  2493. key: name,
  2494. value: nu$4({
  2495. run: function (component, simulatedEvent) {
  2496. simulatedEvent.event().prevent();
  2497. }
  2498. })
  2499. };
  2500. };
  2501. var run = function (name, handler) {
  2502. return {
  2503. key: name,
  2504. value: nu$4({ run: handler })
  2505. };
  2506. };
  2507. var runActionExtra = function (name, action, extra) {
  2508. return {
  2509. key: name,
  2510. value: nu$4({
  2511. run: function (component) {
  2512. action.apply(undefined, [component].concat(extra));
  2513. }
  2514. })
  2515. };
  2516. };
  2517. var runOnName = function (name) {
  2518. return function (handler) {
  2519. return run(name, handler);
  2520. };
  2521. };
  2522. var runOnSourceName = function (name) {
  2523. return function (handler) {
  2524. return {
  2525. key: name,
  2526. value: nu$4({
  2527. run: function (component, simulatedEvent) {
  2528. if (isSource(component, simulatedEvent)) {
  2529. handler(component, simulatedEvent);
  2530. }
  2531. }
  2532. })
  2533. };
  2534. };
  2535. };
  2536. var redirectToUid = function (name, uid) {
  2537. return run(name, function (component, simulatedEvent) {
  2538. component.getSystem().getByUid(uid).each(function (redirectee) {
  2539. dispatchEvent(redirectee, redirectee.element(), name, simulatedEvent);
  2540. });
  2541. });
  2542. };
  2543. var redirectToPart = function (name, detail, partName) {
  2544. var uid = detail.partUids[partName];
  2545. return redirectToUid(name, uid);
  2546. };
  2547. var runWithTarget = function (name, f) {
  2548. return run(name, function (component, simulatedEvent) {
  2549. var ev = simulatedEvent.event();
  2550. var target = component.getSystem().getByDom(ev.target()).fold(function () {
  2551. var closest = closest$1(ev.target(), function (el) {
  2552. return component.getSystem().getByDom(el).toOption();
  2553. }, constant(false));
  2554. return closest.getOr(component);
  2555. }, function (c) {
  2556. return c;
  2557. });
  2558. f(component, target, simulatedEvent);
  2559. });
  2560. };
  2561. var cutter = function (name) {
  2562. return run(name, function (component, simulatedEvent) {
  2563. simulatedEvent.cut();
  2564. });
  2565. };
  2566. var stopper = function (name) {
  2567. return run(name, function (component, simulatedEvent) {
  2568. simulatedEvent.stop();
  2569. });
  2570. };
  2571. var runOnSource = function (name, f) {
  2572. return runOnSourceName(name)(f);
  2573. };
  2574. var runOnAttached = runOnSourceName(attachedToDom());
  2575. var runOnDetached = runOnSourceName(detachedFromDom());
  2576. var runOnInit = runOnSourceName(systemInit());
  2577. var runOnExecute = runOnName(execute());
  2578. var isRecursive = function (component, originator, target) {
  2579. return eq(originator, component.element()) && !eq(originator, target);
  2580. };
  2581. var events = derive([can(focus(), function (component, simulatedEvent) {
  2582. var originator = simulatedEvent.event().originator();
  2583. var target = simulatedEvent.event().target();
  2584. if (isRecursive(component, originator, target)) {
  2585. domGlobals.console.warn(focus() + ' did not get interpreted by the desired target. ' + '\nOriginator: ' + element(originator) + '\nTarget: ' + element(target) + '\nCheck the ' + focus() + ' event handlers');
  2586. return false;
  2587. } else {
  2588. return true;
  2589. }
  2590. })]);
  2591. var DefaultEvents = /*#__PURE__*/Object.freeze({
  2592. events: events
  2593. });
  2594. var prefix = constant('alloy-id-');
  2595. var idAttr = constant('data-alloy-id');
  2596. var prefix$1 = prefix();
  2597. var idAttr$1 = idAttr();
  2598. var write = function (label, elem) {
  2599. var id = generate$1(prefix$1 + label);
  2600. writeOnly(elem, id);
  2601. return id;
  2602. };
  2603. var writeOnly = function (elem, uid) {
  2604. Object.defineProperty(elem.dom(), idAttr$1, {
  2605. value: uid,
  2606. writable: true
  2607. });
  2608. };
  2609. var read$1 = function (elem) {
  2610. var id = isElement(elem) ? elem.dom()[idAttr$1] : null;
  2611. return Option.from(id);
  2612. };
  2613. var generate$2 = function (prefix) {
  2614. return generate$1(prefix);
  2615. };
  2616. var make = identity;
  2617. var NoContextApi = function (getComp) {
  2618. var fail = function (event) {
  2619. return function () {
  2620. throw new Error('The component must be in a context to send: ' + event + '\n' + element(getComp().element()) + ' is not in context.');
  2621. };
  2622. };
  2623. return {
  2624. debugInfo: constant('fake'),
  2625. triggerEvent: fail('triggerEvent'),
  2626. triggerFocus: fail('triggerFocus'),
  2627. triggerEscape: fail('triggerEscape'),
  2628. build: fail('build'),
  2629. addToWorld: fail('addToWorld'),
  2630. removeFromWorld: fail('removeFromWorld'),
  2631. addToGui: fail('addToGui'),
  2632. removeFromGui: fail('removeFromGui'),
  2633. getByUid: fail('getByUid'),
  2634. getByDom: fail('getByDom'),
  2635. broadcast: fail('broadcast'),
  2636. broadcastOn: fail('broadcastOn'),
  2637. broadcastEvent: fail('broadcastEvent'),
  2638. isConnected: constant(false)
  2639. };
  2640. };
  2641. var singleton = NoContextApi();
  2642. var markAsBehaviourApi = function (f, apiName, apiFunction) {
  2643. var delegate = apiFunction.toString();
  2644. var endIndex = delegate.indexOf(')') + 1;
  2645. var openBracketIndex = delegate.indexOf('(');
  2646. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2647. f.toFunctionAnnotation = function () {
  2648. return {
  2649. name: apiName,
  2650. parameters: cleanParameters(parameters.slice(0, 1).concat(parameters.slice(3)))
  2651. };
  2652. };
  2653. return f;
  2654. };
  2655. var cleanParameters = function (parameters) {
  2656. return map(parameters, function (p) {
  2657. return endsWith(p, '/*') ? p.substring(0, p.length - '/*'.length) : p;
  2658. });
  2659. };
  2660. var markAsExtraApi = function (f, extraName) {
  2661. var delegate = f.toString();
  2662. var endIndex = delegate.indexOf(')') + 1;
  2663. var openBracketIndex = delegate.indexOf('(');
  2664. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2665. f.toFunctionAnnotation = function () {
  2666. return {
  2667. name: extraName,
  2668. parameters: cleanParameters(parameters)
  2669. };
  2670. };
  2671. return f;
  2672. };
  2673. var markAsSketchApi = function (f, apiFunction) {
  2674. var delegate = apiFunction.toString();
  2675. var endIndex = delegate.indexOf(')') + 1;
  2676. var openBracketIndex = delegate.indexOf('(');
  2677. var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
  2678. f.toFunctionAnnotation = function () {
  2679. return {
  2680. name: 'OVERRIDE',
  2681. parameters: cleanParameters(parameters.slice(1))
  2682. };
  2683. };
  2684. return f;
  2685. };
  2686. var premadeTag = generate$1('alloy-premade');
  2687. var premade = function (comp) {
  2688. return wrap$1(premadeTag, comp);
  2689. };
  2690. var getPremade = function (spec) {
  2691. return readOptFrom$1(spec, premadeTag);
  2692. };
  2693. var makeApi = function (f) {
  2694. return markAsSketchApi(function (component) {
  2695. var rest = [];
  2696. for (var _i = 1; _i < arguments.length; _i++) {
  2697. rest[_i - 1] = arguments[_i];
  2698. }
  2699. return f.apply(undefined, [component.getApis()].concat([component].concat(rest)));
  2700. }, f);
  2701. };
  2702. var NoState = {
  2703. init: function () {
  2704. return nu$5({
  2705. readState: function () {
  2706. return 'No State required';
  2707. }
  2708. });
  2709. }
  2710. };
  2711. var nu$5 = function (spec) {
  2712. return spec;
  2713. };
  2714. var generateFrom = function (spec, all) {
  2715. var schema = map(all, function (a) {
  2716. return optionObjOf(a.name(), [
  2717. strict$1('config'),
  2718. defaulted$1('state', NoState)
  2719. ]);
  2720. });
  2721. var validated = asRaw('component.behaviours', objOf(schema), spec.behaviours).fold(function (errInfo) {
  2722. throw new Error(formatError(errInfo) + '\nComplete spec:\n' + JSON$1.stringify(spec, null, 2));
  2723. }, function (v) {
  2724. return v;
  2725. });
  2726. return {
  2727. list: all,
  2728. data: map$1(validated, function (optBlobThunk) {
  2729. var optBlob = optBlobThunk;
  2730. var output = optBlob.map(function (blob) {
  2731. return {
  2732. config: blob.config,
  2733. state: blob.state.init(blob.config)
  2734. };
  2735. });
  2736. return function () {
  2737. return output;
  2738. };
  2739. })
  2740. };
  2741. };
  2742. var getBehaviours = function (bData) {
  2743. return bData.list;
  2744. };
  2745. var getData = function (bData) {
  2746. return bData.data;
  2747. };
  2748. var byInnerKey = function (data, tuple) {
  2749. var r = {};
  2750. each$1(data, function (detail, key) {
  2751. each$1(detail, function (value, indexKey) {
  2752. var chain = readOr$1(indexKey, [])(r);
  2753. r[indexKey] = chain.concat([tuple(key, value)]);
  2754. });
  2755. });
  2756. return r;
  2757. };
  2758. var nu$6 = function (s) {
  2759. return {
  2760. classes: s.classes !== undefined ? s.classes : [],
  2761. attributes: s.attributes !== undefined ? s.attributes : {},
  2762. styles: s.styles !== undefined ? s.styles : {}
  2763. };
  2764. };
  2765. var merge$1 = function (defnA, mod) {
  2766. return __assign({}, defnA, {
  2767. attributes: __assign({}, defnA.attributes, mod.attributes),
  2768. styles: __assign({}, defnA.styles, mod.styles),
  2769. classes: defnA.classes.concat(mod.classes)
  2770. });
  2771. };
  2772. var combine = function (info, baseMod, behaviours, base) {
  2773. var modsByBehaviour = __assign({}, baseMod);
  2774. each(behaviours, function (behaviour) {
  2775. modsByBehaviour[behaviour.name()] = behaviour.exhibit(info, base);
  2776. });
  2777. var nameAndMod = function (name, modification) {
  2778. return {
  2779. name: name,
  2780. modification: modification
  2781. };
  2782. };
  2783. var byAspect = byInnerKey(modsByBehaviour, nameAndMod);
  2784. var combineObjects = function (objects) {
  2785. return foldr(objects, function (b, a) {
  2786. return __assign({}, a.modification, b);
  2787. }, {});
  2788. };
  2789. var combinedClasses = foldr(byAspect.classes, function (b, a) {
  2790. return a.modification.concat(b);
  2791. }, []);
  2792. var combinedAttributes = combineObjects(byAspect.attributes);
  2793. var combinedStyles = combineObjects(byAspect.styles);
  2794. return nu$6({
  2795. classes: combinedClasses,
  2796. attributes: combinedAttributes,
  2797. styles: combinedStyles
  2798. });
  2799. };
  2800. var sortKeys = function (label, keyName, array, order) {
  2801. var sliced = array.slice(0);
  2802. try {
  2803. var sorted = sliced.sort(function (a, b) {
  2804. var aKey = a[keyName]();
  2805. var bKey = b[keyName]();
  2806. var aIndex = order.indexOf(aKey);
  2807. var bIndex = order.indexOf(bKey);
  2808. if (aIndex === -1) {
  2809. throw new Error('The ordering for ' + label + ' does not have an entry for ' + aKey + '.\nOrder specified: ' + JSON$1.stringify(order, null, 2));
  2810. }
  2811. if (bIndex === -1) {
  2812. throw new Error('The ordering for ' + label + ' does not have an entry for ' + bKey + '.\nOrder specified: ' + JSON$1.stringify(order, null, 2));
  2813. }
  2814. if (aIndex < bIndex) {
  2815. return -1;
  2816. } else if (bIndex < aIndex) {
  2817. return 1;
  2818. } else {
  2819. return 0;
  2820. }
  2821. });
  2822. return Result.value(sorted);
  2823. } catch (err) {
  2824. return Result.error([err]);
  2825. }
  2826. };
  2827. var uncurried = function (handler, purpose) {
  2828. return {
  2829. handler: handler,
  2830. purpose: constant(purpose)
  2831. };
  2832. };
  2833. var curried = function (handler, purpose) {
  2834. return {
  2835. cHandler: handler,
  2836. purpose: constant(purpose)
  2837. };
  2838. };
  2839. var curryArgs = function (descHandler, extraArgs) {
  2840. return curried(curry.apply(undefined, [descHandler.handler].concat(extraArgs)), descHandler.purpose());
  2841. };
  2842. var getCurried = function (descHandler) {
  2843. return descHandler.cHandler;
  2844. };
  2845. var behaviourTuple = function (name, handler) {
  2846. return {
  2847. name: constant(name),
  2848. handler: constant(handler)
  2849. };
  2850. };
  2851. var nameToHandlers = function (behaviours, info) {
  2852. var r = {};
  2853. each(behaviours, function (behaviour) {
  2854. r[behaviour.name()] = behaviour.handlers(info);
  2855. });
  2856. return r;
  2857. };
  2858. var groupByEvents = function (info, behaviours, base) {
  2859. var behaviourEvents = __assign({}, base, nameToHandlers(behaviours, info));
  2860. return byInnerKey(behaviourEvents, behaviourTuple);
  2861. };
  2862. var combine$1 = function (info, eventOrder, behaviours, base) {
  2863. var byEventName = groupByEvents(info, behaviours, base);
  2864. return combineGroups(byEventName, eventOrder);
  2865. };
  2866. var assemble = function (rawHandler) {
  2867. var handler = read(rawHandler);
  2868. return function (component, simulatedEvent) {
  2869. var rest = [];
  2870. for (var _i = 2; _i < arguments.length; _i++) {
  2871. rest[_i - 2] = arguments[_i];
  2872. }
  2873. var args = [
  2874. component,
  2875. simulatedEvent
  2876. ].concat(rest);
  2877. if (handler.abort.apply(undefined, args)) {
  2878. simulatedEvent.stop();
  2879. } else if (handler.can.apply(undefined, args)) {
  2880. handler.run.apply(undefined, args);
  2881. }
  2882. };
  2883. };
  2884. var missingOrderError = function (eventName, tuples) {
  2885. 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$1.stringify(map(tuples, function (c) {
  2886. return c.name();
  2887. }), null, 2)]);
  2888. };
  2889. var fuse$1 = function (tuples, eventOrder, eventName) {
  2890. var order = eventOrder[eventName];
  2891. if (!order) {
  2892. return missingOrderError(eventName, tuples);
  2893. } else {
  2894. return sortKeys('Event: ' + eventName, 'name', tuples, order).map(function (sortedTuples) {
  2895. var handlers = map(sortedTuples, function (tuple) {
  2896. return tuple.handler();
  2897. });
  2898. return fuse(handlers);
  2899. });
  2900. }
  2901. };
  2902. var combineGroups = function (byEventName, eventOrder) {
  2903. var r = mapToArray(byEventName, function (tuples, eventName) {
  2904. var combined = tuples.length === 1 ? Result.value(tuples[0].handler()) : fuse$1(tuples, eventOrder, eventName);
  2905. return combined.map(function (handler) {
  2906. var assembled = assemble(handler);
  2907. var purpose = tuples.length > 1 ? filter(eventOrder, function (o) {
  2908. return contains(tuples, function (t) {
  2909. return t.name() === o;
  2910. });
  2911. }).join(' > ') : tuples[0].name();
  2912. return wrap$1(eventName, uncurried(assembled, purpose));
  2913. });
  2914. });
  2915. return consolidate(r, {});
  2916. };
  2917. var toInfo = function (spec) {
  2918. return asRaw('custom.definition', objOf([
  2919. field('dom', 'dom', strict(), objOf([
  2920. strict$1('tag'),
  2921. defaulted$1('styles', {}),
  2922. defaulted$1('classes', []),
  2923. defaulted$1('attributes', {}),
  2924. option('value'),
  2925. option('innerHtml')
  2926. ])),
  2927. strict$1('components'),
  2928. strict$1('uid'),
  2929. defaulted$1('events', {}),
  2930. defaulted$1('apis', {}),
  2931. field('eventOrder', 'eventOrder', mergeWith({
  2932. 'alloy.execute': [
  2933. 'disabling',
  2934. 'alloy.base.behaviour',
  2935. 'toggling',
  2936. 'typeaheadevents'
  2937. ],
  2938. 'alloy.focus': [
  2939. 'alloy.base.behaviour',
  2940. 'focusing',
  2941. 'keying'
  2942. ],
  2943. 'alloy.system.init': [
  2944. 'alloy.base.behaviour',
  2945. 'disabling',
  2946. 'toggling',
  2947. 'representing'
  2948. ],
  2949. 'input': [
  2950. 'alloy.base.behaviour',
  2951. 'representing',
  2952. 'streaming',
  2953. 'invalidating'
  2954. ],
  2955. 'alloy.system.detached': [
  2956. 'alloy.base.behaviour',
  2957. 'representing',
  2958. 'item-events',
  2959. 'tooltipping'
  2960. ],
  2961. 'mousedown': [
  2962. 'focusing',
  2963. 'alloy.base.behaviour',
  2964. 'item-type-events'
  2965. ],
  2966. 'mouseover': [
  2967. 'item-type-events',
  2968. 'tooltipping'
  2969. ]
  2970. }), anyValue$1()),
  2971. option('domModification')
  2972. ]), spec);
  2973. };
  2974. var toDefinition = function (detail) {
  2975. return __assign({}, detail.dom, {
  2976. uid: detail.uid,
  2977. domChildren: map(detail.components, function (comp) {
  2978. return comp.element();
  2979. })
  2980. });
  2981. };
  2982. var toModification = function (detail) {
  2983. return detail.domModification.fold(function () {
  2984. return nu$6({});
  2985. }, nu$6);
  2986. };
  2987. var toEvents = function (info) {
  2988. return info.events;
  2989. };
  2990. var read$2 = function (element, attr) {
  2991. var value = get$2(element, attr);
  2992. return value === undefined || value === '' ? [] : value.split(' ');
  2993. };
  2994. var add = function (element, attr, id) {
  2995. var old = read$2(element, attr);
  2996. var nu = old.concat([id]);
  2997. set$1(element, attr, nu.join(' '));
  2998. return true;
  2999. };
  3000. var remove$2 = function (element, attr, id) {
  3001. var nu = filter(read$2(element, attr), function (v) {
  3002. return v !== id;
  3003. });
  3004. if (nu.length > 0) {
  3005. set$1(element, attr, nu.join(' '));
  3006. } else {
  3007. remove$1(element, attr);
  3008. }
  3009. return false;
  3010. };
  3011. var supports = function (element) {
  3012. return element.dom().classList !== undefined;
  3013. };
  3014. var get$3 = function (element) {
  3015. return read$2(element, 'class');
  3016. };
  3017. var add$1 = function (element, clazz) {
  3018. return add(element, 'class', clazz);
  3019. };
  3020. var remove$3 = function (element, clazz) {
  3021. return remove$2(element, 'class', clazz);
  3022. };
  3023. var add$2 = function (element, clazz) {
  3024. if (supports(element)) {
  3025. element.dom().classList.add(clazz);
  3026. } else {
  3027. add$1(element, clazz);
  3028. }
  3029. };
  3030. var cleanClass = function (element) {
  3031. var classList = supports(element) ? element.dom().classList : get$3(element);
  3032. if (classList.length === 0) {
  3033. remove$1(element, 'class');
  3034. }
  3035. };
  3036. var remove$4 = function (element, clazz) {
  3037. if (supports(element)) {
  3038. var classList = element.dom().classList;
  3039. classList.remove(clazz);
  3040. } else {
  3041. remove$3(element, clazz);
  3042. }
  3043. cleanClass(element);
  3044. };
  3045. var has$2 = function (element, clazz) {
  3046. return supports(element) && element.dom().classList.contains(clazz);
  3047. };
  3048. var add$3 = function (element, classes) {
  3049. each(classes, function (x) {
  3050. add$2(element, x);
  3051. });
  3052. };
  3053. var remove$5 = function (element, classes) {
  3054. each(classes, function (x) {
  3055. remove$4(element, x);
  3056. });
  3057. };
  3058. var isSupported = function (dom) {
  3059. return dom.style !== undefined;
  3060. };
  3061. var internalSet = function (dom, property, value) {
  3062. if (!isString(value)) {
  3063. domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
  3064. throw new Error('CSS value must be a string: ' + value);
  3065. }
  3066. if (isSupported(dom)) {
  3067. dom.style.setProperty(property, value);
  3068. }
  3069. };
  3070. var internalRemove = function (dom, property) {
  3071. if (isSupported(dom)) {
  3072. dom.style.removeProperty(property);
  3073. }
  3074. };
  3075. var set$2 = function (element, property, value) {
  3076. var dom = element.dom();
  3077. internalSet(dom, property, value);
  3078. };
  3079. var setAll$1 = function (element, css) {
  3080. var dom = element.dom();
  3081. each$1(css, function (v, k) {
  3082. internalSet(dom, k, v);
  3083. });
  3084. };
  3085. var setOptions = function (element, css) {
  3086. var dom = element.dom();
  3087. each$1(css, function (v, k) {
  3088. v.fold(function () {
  3089. internalRemove(dom, k);
  3090. }, function (value) {
  3091. internalSet(dom, k, value);
  3092. });
  3093. });
  3094. };
  3095. var get$4 = function (element, property) {
  3096. var dom = element.dom();
  3097. var styles = domGlobals.window.getComputedStyle(dom);
  3098. var r = styles.getPropertyValue(property);
  3099. var v = r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
  3100. return v === null ? undefined : v;
  3101. };
  3102. var getUnsafeProperty = function (dom, property) {
  3103. return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
  3104. };
  3105. var getRaw = function (element, property) {
  3106. var dom = element.dom();
  3107. var raw = getUnsafeProperty(dom, property);
  3108. return Option.from(raw).filter(function (r) {
  3109. return r.length > 0;
  3110. });
  3111. };
  3112. var isValidValue = function (tag, property, value) {
  3113. var element = Element.fromTag(tag);
  3114. set$2(element, property, value);
  3115. var style = getRaw(element, property);
  3116. return style.isSome();
  3117. };
  3118. var remove$6 = function (element, property) {
  3119. var dom = element.dom();
  3120. internalRemove(dom, property);
  3121. if (has$1(element, 'style') && trim(get$2(element, 'style')) === '') {
  3122. remove$1(element, 'style');
  3123. }
  3124. };
  3125. var reflow = function (e) {
  3126. return e.dom().offsetWidth;
  3127. };
  3128. var get$5 = function (element) {
  3129. return element.dom().value;
  3130. };
  3131. var set$3 = function (element, value) {
  3132. if (value === undefined) {
  3133. throw new Error('Value.set was undefined');
  3134. }
  3135. element.dom().value = value;
  3136. };
  3137. var renderToDom = function (definition) {
  3138. var subject = Element.fromTag(definition.tag);
  3139. setAll(subject, definition.attributes);
  3140. add$3(subject, definition.classes);
  3141. setAll$1(subject, definition.styles);
  3142. definition.innerHtml.each(function (html) {
  3143. return set(subject, html);
  3144. });
  3145. var children = definition.domChildren;
  3146. append$1(subject, children);
  3147. definition.value.each(function (value) {
  3148. set$3(subject, value);
  3149. });
  3150. if (!definition.uid) {
  3151. debugger;
  3152. }
  3153. writeOnly(subject, definition.uid);
  3154. return subject;
  3155. };
  3156. var getBehaviours$1 = function (spec) {
  3157. var behaviours = readOr$1('behaviours', {})(spec);
  3158. var keys$1 = filter(keys(behaviours), function (k) {
  3159. return behaviours[k] !== undefined;
  3160. });
  3161. return map(keys$1, function (k) {
  3162. return behaviours[k].me;
  3163. });
  3164. };
  3165. var generateFrom$1 = function (spec, all) {
  3166. return generateFrom(spec, all);
  3167. };
  3168. var generate$3 = function (spec) {
  3169. var all = getBehaviours$1(spec);
  3170. return generateFrom$1(spec, all);
  3171. };
  3172. var getDomDefinition = function (info, bList, bData) {
  3173. var definition = toDefinition(info);
  3174. var infoModification = toModification(info);
  3175. var baseModification = { 'alloy.base.modification': infoModification };
  3176. var modification = bList.length > 0 ? combine(bData, baseModification, bList, definition) : infoModification;
  3177. return merge$1(definition, modification);
  3178. };
  3179. var getEvents = function (info, bList, bData) {
  3180. var baseEvents = { 'alloy.base.behaviour': toEvents(info) };
  3181. return combine$1(bData, info.eventOrder, bList, baseEvents).getOrDie();
  3182. };
  3183. var build = function (spec) {
  3184. var getMe = function () {
  3185. return me;
  3186. };
  3187. var systemApi = Cell(singleton);
  3188. var info = getOrDie$1(toInfo(spec));
  3189. var bBlob = generate$3(spec);
  3190. var bList = getBehaviours(bBlob);
  3191. var bData = getData(bBlob);
  3192. var modDefinition = getDomDefinition(info, bList, bData);
  3193. var item = renderToDom(modDefinition);
  3194. var events = getEvents(info, bList, bData);
  3195. var subcomponents = Cell(info.components);
  3196. var connect = function (newApi) {
  3197. systemApi.set(newApi);
  3198. };
  3199. var disconnect = function () {
  3200. systemApi.set(NoContextApi(getMe));
  3201. };
  3202. var syncComponents = function () {
  3203. var children$1 = children(item);
  3204. var subs = bind(children$1, function (child) {
  3205. return systemApi.get().getByDom(child).fold(function () {
  3206. return [];
  3207. }, function (c) {
  3208. return [c];
  3209. });
  3210. });
  3211. subcomponents.set(subs);
  3212. };
  3213. var config = function (behaviour) {
  3214. var b = bData;
  3215. var f = isFunction(b[behaviour.name()]) ? b[behaviour.name()] : function () {
  3216. throw new Error('Could not find ' + behaviour.name() + ' in ' + JSON$1.stringify(spec, null, 2));
  3217. };
  3218. return f();
  3219. };
  3220. var hasConfigured = function (behaviour) {
  3221. return isFunction(bData[behaviour.name()]);
  3222. };
  3223. var getApis = function () {
  3224. return info.apis;
  3225. };
  3226. var readState = function (behaviourName) {
  3227. return bData[behaviourName]().map(function (b) {
  3228. return b.state.readState();
  3229. }).getOr('not enabled');
  3230. };
  3231. var me = {
  3232. getSystem: systemApi.get,
  3233. config: config,
  3234. hasConfigured: hasConfigured,
  3235. spec: constant(spec),
  3236. readState: readState,
  3237. getApis: getApis,
  3238. connect: connect,
  3239. disconnect: disconnect,
  3240. element: constant(item),
  3241. syncComponents: syncComponents,
  3242. components: subcomponents.get,
  3243. events: constant(events)
  3244. };
  3245. return me;
  3246. };
  3247. var buildSubcomponents = function (spec) {
  3248. var components = readOr$1('components', [])(spec);
  3249. return map(components, build$1);
  3250. };
  3251. var buildFromSpec = function (userSpec) {
  3252. var _a = make(userSpec), specEvents = _a.events, spec = __rest(_a, ['events']);
  3253. var components = buildSubcomponents(spec);
  3254. var completeSpec = __assign({}, spec, {
  3255. events: __assign({}, DefaultEvents, specEvents),
  3256. components: components
  3257. });
  3258. return Result.value(build(completeSpec));
  3259. };
  3260. var text = function (textContent) {
  3261. var element = Element.fromText(textContent);
  3262. return external({ element: element });
  3263. };
  3264. var external = function (spec) {
  3265. var extSpec = asRawOrDie('external.component', objOfOnly([
  3266. strict$1('element'),
  3267. option('uid')
  3268. ]), spec);
  3269. var systemApi = Cell(NoContextApi());
  3270. var connect = function (newApi) {
  3271. systemApi.set(newApi);
  3272. };
  3273. var disconnect = function () {
  3274. systemApi.set(NoContextApi(function () {
  3275. return me;
  3276. }));
  3277. };
  3278. extSpec.uid.each(function (uid) {
  3279. writeOnly(extSpec.element, uid);
  3280. });
  3281. var me = {
  3282. getSystem: systemApi.get,
  3283. config: Option.none,
  3284. hasConfigured: constant(false),
  3285. connect: connect,
  3286. disconnect: disconnect,
  3287. getApis: function () {
  3288. return {};
  3289. },
  3290. element: constant(extSpec.element),
  3291. spec: constant(spec),
  3292. readState: constant('No state'),
  3293. syncComponents: noop,
  3294. components: constant([]),
  3295. events: constant({})
  3296. };
  3297. return premade(me);
  3298. };
  3299. var uids = generate$2;
  3300. var build$1 = function (spec) {
  3301. return getPremade(spec).fold(function () {
  3302. var userSpecWithUid = spec.hasOwnProperty('uid') ? spec : __assign({ uid: uids('') }, spec);
  3303. return buildFromSpec(userSpecWithUid).getOrDie();
  3304. }, function (prebuilt) {
  3305. return prebuilt;
  3306. });
  3307. };
  3308. var premade$1 = premade;
  3309. var closest$2 = function (scope, predicate, isRoot) {
  3310. return closest(scope, predicate, isRoot).isSome();
  3311. };
  3312. var ancestor$1 = function (scope, selector, isRoot) {
  3313. return ancestor(scope, function (e) {
  3314. return is(e, selector);
  3315. }, isRoot);
  3316. };
  3317. var descendant$1 = function (scope, selector) {
  3318. return one(selector, scope);
  3319. };
  3320. var closest$3 = function (scope, selector, isRoot) {
  3321. return ClosestOrAncestor(is, ancestor$1, scope, selector, isRoot);
  3322. };
  3323. var find$3 = function (queryElem) {
  3324. var dependent = closest(queryElem, function (elem) {
  3325. if (!isElement(elem)) {
  3326. return false;
  3327. }
  3328. var id = get$2(elem, 'id');
  3329. return id !== undefined && id.indexOf('aria-owns') > -1;
  3330. });
  3331. return dependent.bind(function (dep) {
  3332. var id = get$2(dep, 'id');
  3333. var doc = owner(dep);
  3334. return descendant$1(doc, '[aria-owns="' + id + '"]');
  3335. });
  3336. };
  3337. var manager = function () {
  3338. var ariaId = generate$1('aria-owns');
  3339. var link = function (elem) {
  3340. set$1(elem, 'aria-owns', ariaId);
  3341. };
  3342. var unlink = function (elem) {
  3343. remove$1(elem, 'aria-owns');
  3344. };
  3345. return {
  3346. id: constant(ariaId),
  3347. link: link,
  3348. unlink: unlink
  3349. };
  3350. };
  3351. var isAriaPartOf = function (component, queryElem) {
  3352. return find$3(queryElem).exists(function (owner) {
  3353. return isPartOf(component, owner);
  3354. });
  3355. };
  3356. var isPartOf = function (component, queryElem) {
  3357. return closest$2(queryElem, function (el) {
  3358. return eq(el, component.element());
  3359. }, constant(false)) || isAriaPartOf(component, queryElem);
  3360. };
  3361. var menuFields = constant([
  3362. strict$1('menu'),
  3363. strict$1('selectedMenu')
  3364. ]);
  3365. var itemFields = constant([
  3366. strict$1('item'),
  3367. strict$1('selectedItem')
  3368. ]);
  3369. var schema = constant(objOf(itemFields().concat(menuFields())));
  3370. var itemSchema = constant(objOf(itemFields()));
  3371. var _initSize = strictObjOf('initSize', [
  3372. strict$1('numColumns'),
  3373. strict$1('numRows')
  3374. ]);
  3375. var itemMarkers = function () {
  3376. return strictOf('markers', itemSchema());
  3377. };
  3378. var tieredMenuMarkers = function () {
  3379. return strictObjOf('markers', [strict$1('backgroundMenu')].concat(menuFields()).concat(itemFields()));
  3380. };
  3381. var markers = function (required) {
  3382. return strictObjOf('markers', map(required, strict$1));
  3383. };
  3384. var onPresenceHandler = function (label, fieldName, presence) {
  3385. var trace = getTrace();
  3386. return field(fieldName, fieldName, presence, valueOf(function (f) {
  3387. return Result.value(function () {
  3388. var args = [];
  3389. for (var _i = 0; _i < arguments.length; _i++) {
  3390. args[_i] = arguments[_i];
  3391. }
  3392. return f.apply(undefined, args);
  3393. });
  3394. }));
  3395. };
  3396. var onHandler = function (fieldName) {
  3397. return onPresenceHandler('onHandler', fieldName, defaulted(noop));
  3398. };
  3399. var onKeyboardHandler = function (fieldName) {
  3400. return onPresenceHandler('onKeyboardHandler', fieldName, defaulted(Option.none));
  3401. };
  3402. var onStrictHandler = function (fieldName) {
  3403. return onPresenceHandler('onHandler', fieldName, strict());
  3404. };
  3405. var onStrictKeyboardHandler = function (fieldName) {
  3406. return onPresenceHandler('onKeyboardHandler', fieldName, strict());
  3407. };
  3408. var output = function (name, value) {
  3409. return state$1(name, constant(value));
  3410. };
  3411. var snapshot = function (name) {
  3412. return state$1(name, identity);
  3413. };
  3414. var initSize = constant(_initSize);
  3415. var executeEvent = function (bConfig, bState, executor) {
  3416. return runOnExecute(function (component) {
  3417. executor(component, bConfig, bState);
  3418. });
  3419. };
  3420. var loadEvent = function (bConfig, bState, f) {
  3421. return runOnInit(function (component, simulatedEvent) {
  3422. f(component, bConfig, bState);
  3423. });
  3424. };
  3425. var create = function (schema, name, active, apis, extra, state) {
  3426. var configSchema = objOfOnly(schema);
  3427. var schemaSchema = optionObjOf(name, [optionObjOfOnly('config', schema)]);
  3428. return doCreate(configSchema, schemaSchema, name, active, apis, extra, state);
  3429. };
  3430. var createModes = function (modes, name, active, apis, extra, state) {
  3431. var configSchema = modes;
  3432. var schemaSchema = optionObjOf(name, [optionOf('config', modes)]);
  3433. return doCreate(configSchema, schemaSchema, name, active, apis, extra, state);
  3434. };
  3435. var wrapApi = function (bName, apiFunction, apiName) {
  3436. var f = function (component) {
  3437. var rest = [];
  3438. for (var _i = 1; _i < arguments.length; _i++) {
  3439. rest[_i - 1] = arguments[_i];
  3440. }
  3441. var args = [component].concat(rest);
  3442. return component.config({ name: constant(bName) }).fold(function () {
  3443. throw new Error('We could not find any behaviour configuration for: ' + bName + '. Using API: ' + apiName);
  3444. }, function (info) {
  3445. var rest = Array.prototype.slice.call(args, 1);
  3446. return apiFunction.apply(undefined, [
  3447. component,
  3448. info.config,
  3449. info.state
  3450. ].concat(rest));
  3451. });
  3452. };
  3453. return markAsBehaviourApi(f, apiName, apiFunction);
  3454. };
  3455. var revokeBehaviour = function (name) {
  3456. return {
  3457. key: name,
  3458. value: undefined
  3459. };
  3460. };
  3461. var doCreate = function (configSchema, schemaSchema, name, active, apis, extra, state) {
  3462. var getConfig = function (info) {
  3463. return hasKey$1(info, name) ? info[name]() : Option.none();
  3464. };
  3465. var wrappedApis = map$1(apis, function (apiF, apiName) {
  3466. return wrapApi(name, apiF, apiName);
  3467. });
  3468. var wrappedExtra = map$1(extra, function (extraF, extraName) {
  3469. return markAsExtraApi(extraF, extraName);
  3470. });
  3471. var me = __assign({}, wrappedExtra, wrappedApis, {
  3472. revoke: curry(revokeBehaviour, name),
  3473. config: function (spec) {
  3474. var prepared = asRawOrDie(name + '-config', configSchema, spec);
  3475. return {
  3476. key: name,
  3477. value: {
  3478. config: prepared,
  3479. me: me,
  3480. configAsRaw: cached(function () {
  3481. return asRawOrDie(name + '-config', configSchema, spec);
  3482. }),
  3483. initialConfig: spec,
  3484. state: state
  3485. }
  3486. };
  3487. },
  3488. schema: function () {
  3489. return schemaSchema;
  3490. },
  3491. exhibit: function (info, base) {
  3492. return getConfig(info).bind(function (behaviourInfo) {
  3493. return readOptFrom$1(active, 'exhibit').map(function (exhibitor) {
  3494. return exhibitor(base, behaviourInfo.config, behaviourInfo.state);
  3495. });
  3496. }).getOr(nu$6({}));
  3497. },
  3498. name: function () {
  3499. return name;
  3500. },
  3501. handlers: function (info) {
  3502. return getConfig(info).map(function (behaviourInfo) {
  3503. var getEvents = readOr$1('events', function (a, b) {
  3504. return {};
  3505. })(active);
  3506. return getEvents(behaviourInfo.config, behaviourInfo.state);
  3507. }).getOr({});
  3508. }
  3509. });
  3510. return me;
  3511. };
  3512. var derive$1 = function (capabilities) {
  3513. return wrapAll$1(capabilities);
  3514. };
  3515. var simpleSchema = objOfOnly([
  3516. strict$1('fields'),
  3517. strict$1('name'),
  3518. defaulted$1('active', {}),
  3519. defaulted$1('apis', {}),
  3520. defaulted$1('state', NoState),
  3521. defaulted$1('extra', {})
  3522. ]);
  3523. var create$1 = function (data) {
  3524. var value = asRawOrDie('Creating behaviour: ' + data.name, simpleSchema, data);
  3525. return create(value.fields, value.name, value.active, value.apis, value.extra, value.state);
  3526. };
  3527. var modeSchema = objOfOnly([
  3528. strict$1('branchKey'),
  3529. strict$1('branches'),
  3530. strict$1('name'),
  3531. defaulted$1('active', {}),
  3532. defaulted$1('apis', {}),
  3533. defaulted$1('state', NoState),
  3534. defaulted$1('extra', {})
  3535. ]);
  3536. var createModes$1 = function (data) {
  3537. var value = asRawOrDie('Creating behaviour: ' + data.name, modeSchema, data);
  3538. return createModes(choose$1(value.branchKey, value.branches), value.name, value.active, value.apis, value.extra, value.state);
  3539. };
  3540. var revoke = constant(undefined);
  3541. var chooseChannels = function (channels, message) {
  3542. return message.universal() ? channels : filter(channels, function (ch) {
  3543. return contains(message.channels(), ch);
  3544. });
  3545. };
  3546. var events$1 = function (receiveConfig) {
  3547. return derive([run(receive(), function (component, message) {
  3548. var channelMap = receiveConfig.channels;
  3549. var channels = keys(channelMap);
  3550. var targetChannels = chooseChannels(channels, message);
  3551. each(targetChannels, function (ch) {
  3552. var channelInfo = channelMap[ch];
  3553. var channelSchema = channelInfo.schema;
  3554. var data = asRawOrDie('channel[' + ch + '] data\nReceiver: ' + element(component.element()), channelSchema, message.data());
  3555. channelInfo.onReceive(component, data);
  3556. });
  3557. })]);
  3558. };
  3559. var ActiveReceiving = /*#__PURE__*/Object.freeze({
  3560. events: events$1
  3561. });
  3562. var ReceivingSchema = [strictOf('channels', setOf$1(Result.value, objOfOnly([
  3563. onStrictHandler('onReceive'),
  3564. defaulted$1('schema', anyValue$1())
  3565. ])))];
  3566. var Receiving = create$1({
  3567. fields: ReceivingSchema,
  3568. name: 'receiving',
  3569. active: ActiveReceiving
  3570. });
  3571. var exhibit = function (base, posConfig) {
  3572. return nu$6({
  3573. classes: [],
  3574. styles: posConfig.useFixed ? {} : { position: 'relative' }
  3575. });
  3576. };
  3577. var ActivePosition = /*#__PURE__*/Object.freeze({
  3578. exhibit: exhibit
  3579. });
  3580. var attached = function (element, scope) {
  3581. var doc = scope || Element.fromDom(domGlobals.document.documentElement);
  3582. return ancestor(element, curry(eq, doc)).isSome();
  3583. };
  3584. var windowOf = function (element) {
  3585. var dom = element.dom();
  3586. if (dom === dom.window && element instanceof domGlobals.Window) {
  3587. return element;
  3588. }
  3589. return isDocument(element) ? dom.defaultView || dom.parentWindow : null;
  3590. };
  3591. var r = function (left, top) {
  3592. var translate = function (x, y) {
  3593. return r(left + x, top + y);
  3594. };
  3595. return {
  3596. left: constant(left),
  3597. top: constant(top),
  3598. translate: translate
  3599. };
  3600. };
  3601. var Position = r;
  3602. var boxPosition = function (dom) {
  3603. var box = dom.getBoundingClientRect();
  3604. return Position(box.left, box.top);
  3605. };
  3606. var firstDefinedOrZero = function (a, b) {
  3607. return a !== undefined ? a : b !== undefined ? b : 0;
  3608. };
  3609. var absolute = function (element) {
  3610. var doc = element.dom().ownerDocument;
  3611. var body = doc.body;
  3612. var win = windowOf(Element.fromDom(doc));
  3613. var html = doc.documentElement;
  3614. var scrollTop = firstDefinedOrZero(win.pageYOffset, html.scrollTop);
  3615. var scrollLeft = firstDefinedOrZero(win.pageXOffset, html.scrollLeft);
  3616. var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
  3617. var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
  3618. return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
  3619. };
  3620. var viewport = function (element) {
  3621. var dom = element.dom();
  3622. var doc = dom.ownerDocument;
  3623. var body = doc.body;
  3624. var html = Element.fromDom(doc.documentElement);
  3625. if (body === dom) {
  3626. return Position(body.offsetLeft, body.offsetTop);
  3627. }
  3628. if (!attached(element, html)) {
  3629. return Position(0, 0);
  3630. }
  3631. return boxPosition(dom);
  3632. };
  3633. var isSafari = PlatformDetection$1.detect().browser.isSafari();
  3634. var get$6 = function (_DOC) {
  3635. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  3636. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  3637. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  3638. return Position(x, y);
  3639. };
  3640. function Dimension (name, getOffset) {
  3641. var set = function (element, h) {
  3642. if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
  3643. throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
  3644. }
  3645. var dom = element.dom();
  3646. if (isSupported(dom)) {
  3647. dom.style[name] = h + 'px';
  3648. }
  3649. };
  3650. var get = function (element) {
  3651. var r = getOffset(element);
  3652. if (r <= 0 || r === null) {
  3653. var css = get$4(element, name);
  3654. return parseFloat(css) || 0;
  3655. }
  3656. return r;
  3657. };
  3658. var getOuter = get;
  3659. var aggregate = function (element, properties) {
  3660. return foldl(properties, function (acc, property) {
  3661. var val = get$4(element, property);
  3662. var value = val === undefined ? 0 : parseInt(val, 10);
  3663. return isNaN(value) ? acc : acc + value;
  3664. }, 0);
  3665. };
  3666. var max = function (element, value, properties) {
  3667. var cumulativeInclusions = aggregate(element, properties);
  3668. var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
  3669. return absoluteMax;
  3670. };
  3671. return {
  3672. set: set,
  3673. get: get,
  3674. getOuter: getOuter,
  3675. aggregate: aggregate,
  3676. max: max
  3677. };
  3678. }
  3679. var api = Dimension('width', function (element) {
  3680. return element.dom().offsetWidth;
  3681. });
  3682. var set$4 = function (element, h) {
  3683. api.set(element, h);
  3684. };
  3685. var get$7 = function (element) {
  3686. return api.get(element);
  3687. };
  3688. var getOuter$1 = function (element) {
  3689. return api.getOuter(element);
  3690. };
  3691. var api$1 = Dimension('height', function (element) {
  3692. var dom = element.dom();
  3693. return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
  3694. });
  3695. var get$8 = function (element) {
  3696. return api$1.get(element);
  3697. };
  3698. var getOuter$2 = function (element) {
  3699. return api$1.getOuter(element);
  3700. };
  3701. var setMax = function (element, value) {
  3702. var inclusions = [
  3703. 'margin-top',
  3704. 'border-top-width',
  3705. 'padding-top',
  3706. 'padding-bottom',
  3707. 'border-bottom-width',
  3708. 'margin-bottom'
  3709. ];
  3710. var absMax = api$1.max(element, value, inclusions);
  3711. set$2(element, 'max-height', absMax + 'px');
  3712. };
  3713. var decision = MixedBag([
  3714. 'x',
  3715. 'y',
  3716. 'width',
  3717. 'height',
  3718. 'maxHeight',
  3719. 'direction',
  3720. 'classes',
  3721. 'label',
  3722. 'candidateYforTest'
  3723. ], []);
  3724. var css = Immutable('position', 'left', 'top', 'right', 'bottom');
  3725. var adt$2 = Adt.generate([
  3726. { southeast: [] },
  3727. { southwest: [] },
  3728. { northeast: [] },
  3729. { northwest: [] },
  3730. { south: [] },
  3731. { north: [] },
  3732. { east: [] },
  3733. { west: [] }
  3734. ]);
  3735. var cata = function (subject, southeast, southwest, northeast, northwest, south, north, east, west) {
  3736. return subject.fold(southeast, southwest, northeast, northwest, south, north, east, west);
  3737. };
  3738. var cataVertical = function (subject, south, middle, north) {
  3739. return subject.fold(south, south, north, north, south, north, middle, middle);
  3740. };
  3741. var southeast = adt$2.southeast;
  3742. var southwest = adt$2.southwest;
  3743. var northeast = adt$2.northeast;
  3744. var northwest = adt$2.northwest;
  3745. var south = adt$2.south;
  3746. var north = adt$2.north;
  3747. var east = adt$2.east;
  3748. var west = adt$2.west;
  3749. var pointed = Immutable('point', 'width', 'height');
  3750. var rect = Immutable('x', 'y', 'width', 'height');
  3751. var bounds = function (x, y, width, height) {
  3752. return {
  3753. x: constant(x),
  3754. y: constant(y),
  3755. width: constant(width),
  3756. height: constant(height),
  3757. right: constant(x + width),
  3758. bottom: constant(y + height)
  3759. };
  3760. };
  3761. var box = function (element) {
  3762. var xy = absolute(element);
  3763. var w = getOuter$1(element);
  3764. var h = getOuter$2(element);
  3765. return bounds(xy.left(), xy.top(), w, h);
  3766. };
  3767. var walkUp = function (navigation, doc) {
  3768. var frame = navigation.view(doc);
  3769. return frame.fold(constant([]), function (f) {
  3770. var parent = navigation.owner(f);
  3771. var rest = walkUp(navigation, parent);
  3772. return [f].concat(rest);
  3773. });
  3774. };
  3775. var pathTo = function (element, navigation) {
  3776. var d = navigation.owner(element);
  3777. var paths = walkUp(navigation, d);
  3778. return Option.some(paths);
  3779. };
  3780. var view = function (doc) {
  3781. var element = doc.dom() === domGlobals.document ? Option.none() : Option.from(doc.dom().defaultView.frameElement);
  3782. return element.map(Element.fromDom);
  3783. };
  3784. var owner$1 = function (element) {
  3785. return owner(element);
  3786. };
  3787. var Navigation = /*#__PURE__*/Object.freeze({
  3788. view: view,
  3789. owner: owner$1
  3790. });
  3791. var find$4 = function (element) {
  3792. var doc = Element.fromDom(domGlobals.document);
  3793. var scroll = get$6(doc);
  3794. var path = pathTo(element, Navigation);
  3795. return path.fold(curry(absolute, element), function (frames) {
  3796. var offset = viewport(element);
  3797. var r = foldr(frames, function (b, a) {
  3798. var loc = viewport(a);
  3799. return {
  3800. left: b.left + loc.left(),
  3801. top: b.top + loc.top()
  3802. };
  3803. }, {
  3804. left: 0,
  3805. top: 0
  3806. });
  3807. return Position(r.left + offset.left() + scroll.left(), r.top + offset.top() + scroll.top());
  3808. });
  3809. };
  3810. var win = function () {
  3811. var width = domGlobals.window.innerWidth;
  3812. var height = domGlobals.window.innerHeight;
  3813. var doc = Element.fromDom(domGlobals.document);
  3814. var scroll = get$6(doc);
  3815. return bounds(scroll.left(), scroll.top(), width, height);
  3816. };
  3817. var adt$3 = Adt.generate([
  3818. { none: [] },
  3819. {
  3820. relative: [
  3821. 'x',
  3822. 'y',
  3823. 'width',
  3824. 'height'
  3825. ]
  3826. },
  3827. {
  3828. fixed: [
  3829. 'x',
  3830. 'y',
  3831. 'width',
  3832. 'height'
  3833. ]
  3834. }
  3835. ]);
  3836. var positionWithDirection = function (posName, decision, x, y, width, height) {
  3837. var decisionX = decision.x() - x;
  3838. var decisionY = decision.y() - y;
  3839. var decisionWidth = decision.width();
  3840. var decisionHeight = decision.height();
  3841. var decisionRight = width - (decisionX + decisionWidth);
  3842. var decisionBottom = height - (decisionY + decisionHeight);
  3843. var left = Option.some(decisionX);
  3844. var top = Option.some(decisionY);
  3845. var right = Option.some(decisionRight);
  3846. var bottom = Option.some(decisionBottom);
  3847. var none = Option.none();
  3848. return cata(decision.direction(), function () {
  3849. return css(posName, left, top, none, none);
  3850. }, function () {
  3851. return css(posName, none, top, right, none);
  3852. }, function () {
  3853. return css(posName, left, none, none, bottom);
  3854. }, function () {
  3855. return css(posName, none, none, right, bottom);
  3856. }, function () {
  3857. return css(posName, left, top, none, none);
  3858. }, function () {
  3859. return css(posName, left, none, none, bottom);
  3860. }, function () {
  3861. return css(posName, left, top, none, none);
  3862. }, function () {
  3863. return css(posName, none, top, right, none);
  3864. });
  3865. };
  3866. var reposition = function (origin, decision) {
  3867. return origin.fold(function () {
  3868. return css('absolute', Option.some(decision.x()), Option.some(decision.y()), Option.none(), Option.none());
  3869. }, function (x, y, width, height) {
  3870. return positionWithDirection('absolute', decision, x, y, width, height);
  3871. }, function (x, y, width, height) {
  3872. return positionWithDirection('fixed', decision, x, y, width, height);
  3873. });
  3874. };
  3875. var toBox = function (origin, element) {
  3876. var rel = curry(find$4, element);
  3877. var position = origin.fold(rel, rel, function () {
  3878. var scroll = get$6();
  3879. return find$4(element).translate(-scroll.left(), -scroll.top());
  3880. });
  3881. var width = getOuter$1(element);
  3882. var height = getOuter$2(element);
  3883. return bounds(position.left(), position.top(), width, height);
  3884. };
  3885. var viewport$1 = function (origin, getBounds) {
  3886. return getBounds.fold(function () {
  3887. return origin.fold(win, win, bounds);
  3888. }, function (b) {
  3889. return origin.fold(b, b, bounds);
  3890. });
  3891. };
  3892. var cata$1 = function (subject, onNone, onRelative, onFixed) {
  3893. return subject.fold(onNone, onRelative, onFixed);
  3894. };
  3895. var relative = adt$3.relative;
  3896. var fixed = adt$3.fixed;
  3897. var anchor = Immutable('anchorBox', 'origin');
  3898. var box$1 = function (anchorBox, origin) {
  3899. return anchor(anchorBox, origin);
  3900. };
  3901. var adt$4 = Adt.generate([
  3902. { fit: ['reposition'] },
  3903. {
  3904. nofit: [
  3905. 'reposition',
  3906. 'deltaW',
  3907. 'deltaH'
  3908. ]
  3909. }
  3910. ]);
  3911. var attempt = function (candidate, width, height, bounds) {
  3912. var candidateX = candidate.x();
  3913. var candidateY = candidate.y();
  3914. var bubbleLeft = candidate.bubble().offset().left();
  3915. var bubbleTop = candidate.bubble().offset().top();
  3916. var boundsX = bounds.x();
  3917. var boundsY = bounds.y();
  3918. var boundsWidth = bounds.width();
  3919. var boundsHeight = bounds.height();
  3920. var newX = candidateX + bubbleLeft;
  3921. var newY = candidateY + bubbleTop;
  3922. var xInBounds = newX >= boundsX;
  3923. var yInBounds = newY >= boundsY;
  3924. var originInBounds = xInBounds && yInBounds;
  3925. var xFit = newX + width <= boundsX + boundsWidth;
  3926. var yFit = newY + height <= boundsY + boundsHeight;
  3927. var sizeInBounds = xFit && yFit;
  3928. var deltaW = xInBounds ? Math.min(width, boundsX + boundsWidth - newX) : Math.abs(boundsX - (newX + width));
  3929. var deltaH = yInBounds ? Math.min(height, boundsY + boundsHeight - newY) : Math.abs(boundsY - (newY + height));
  3930. var maxX = bounds.x() + bounds.width();
  3931. var minX = Math.max(bounds.x(), newX);
  3932. var limitX = Math.min(minX, maxX);
  3933. var limitY = yInBounds ? newY : newY + (height - deltaH);
  3934. var upAvailable = constant(limitY + deltaH - boundsY);
  3935. var downAvailable = constant(boundsY + boundsHeight - limitY);
  3936. var maxHeight = cataVertical(candidate.direction(), downAvailable, downAvailable, upAvailable);
  3937. var reposition = decision({
  3938. x: limitX,
  3939. y: limitY,
  3940. width: deltaW,
  3941. height: deltaH,
  3942. maxHeight: maxHeight,
  3943. direction: candidate.direction(),
  3944. classes: {
  3945. on: candidate.bubble().classesOn(),
  3946. off: candidate.bubble().classesOff()
  3947. },
  3948. label: candidate.label(),
  3949. candidateYforTest: newY
  3950. });
  3951. return originInBounds && sizeInBounds ? adt$4.fit(reposition) : adt$4.nofit(reposition, deltaW, deltaH);
  3952. };
  3953. var attempts = function (candidates, anchorBox, elementBox, bubbles, bounds) {
  3954. var panelWidth = elementBox.width();
  3955. var panelHeight = elementBox.height();
  3956. var attemptBestFit = function (layout, reposition, deltaW, deltaH) {
  3957. var next = layout(anchorBox, elementBox, bubbles);
  3958. var attemptLayout = attempt(next, panelWidth, panelHeight, bounds);
  3959. return attemptLayout.fold(adt$4.fit, function (newReposition, newDeltaW, newDeltaH) {
  3960. var improved = newDeltaH > deltaH || newDeltaW > deltaW;
  3961. return improved ? adt$4.nofit(newReposition, newDeltaW, newDeltaH) : adt$4.nofit(reposition, deltaW, deltaH);
  3962. });
  3963. };
  3964. var abc = foldl(candidates, function (b, a) {
  3965. var bestNext = curry(attemptBestFit, a);
  3966. return b.fold(adt$4.fit, bestNext);
  3967. }, adt$4.nofit(decision({
  3968. x: anchorBox.x(),
  3969. y: anchorBox.y(),
  3970. width: elementBox.width(),
  3971. height: elementBox.height(),
  3972. maxHeight: elementBox.height(),
  3973. direction: southeast(),
  3974. classes: [],
  3975. label: 'none',
  3976. candidateYforTest: anchorBox.y()
  3977. }), -1, -1));
  3978. return abc.fold(identity, identity);
  3979. };
  3980. var elementSize = function (p) {
  3981. return {
  3982. width: constant(getOuter$1(p)),
  3983. height: constant(getOuter$2(p))
  3984. };
  3985. };
  3986. var layout = function (anchorBox, element, bubbles, options) {
  3987. remove$6(element, 'max-height');
  3988. var elementBox = elementSize(element);
  3989. return attempts(options.preference(), anchorBox, elementBox, bubbles, options.bounds());
  3990. };
  3991. var setClasses = function (element, decision) {
  3992. var classInfo = decision.classes();
  3993. remove$5(element, classInfo.off);
  3994. add$3(element, classInfo.on);
  3995. };
  3996. var setHeight = function (element, decision, options) {
  3997. var maxHeightFunction = options.maxHeightFunction();
  3998. maxHeightFunction(element, decision.maxHeight());
  3999. };
  4000. var position = function (element, decision, options) {
  4001. var addPx = function (num) {
  4002. return num + 'px';
  4003. };
  4004. var newPosition = reposition(options.origin(), decision);
  4005. setOptions(element, {
  4006. position: Option.some(newPosition.position()),
  4007. left: newPosition.left().map(addPx),
  4008. top: newPosition.top().map(addPx),
  4009. right: newPosition.right().map(addPx),
  4010. bottom: newPosition.bottom().map(addPx)
  4011. });
  4012. };
  4013. var setMaxHeight = function (element, maxHeight) {
  4014. setMax(element, Math.floor(maxHeight));
  4015. };
  4016. var anchored = constant(function (element, available) {
  4017. setMaxHeight(element, available);
  4018. setAll$1(element, {
  4019. 'overflow-x': 'hidden',
  4020. 'overflow-y': 'auto'
  4021. });
  4022. });
  4023. var expandable = constant(function (element, available) {
  4024. setMaxHeight(element, available);
  4025. });
  4026. var reparteeOptions = MixedBag([
  4027. 'bounds',
  4028. 'origin',
  4029. 'preference',
  4030. 'maxHeightFunction'
  4031. ], []);
  4032. var defaultOr = function (options, key, dephault) {
  4033. return options[key] === undefined ? dephault : options[key];
  4034. };
  4035. var simple = function (anchor, element, bubble, layouts, getBounds, overrideOptions) {
  4036. var maxHeightFunction = defaultOr(overrideOptions, 'maxHeightFunction', anchored());
  4037. var anchorBox = anchor.anchorBox();
  4038. var origin = anchor.origin();
  4039. var options = reparteeOptions({
  4040. bounds: viewport$1(origin, getBounds),
  4041. origin: origin,
  4042. preference: layouts,
  4043. maxHeightFunction: maxHeightFunction
  4044. });
  4045. go(anchorBox, element, bubble, options);
  4046. };
  4047. var go = function (anchorBox, element, bubble, options) {
  4048. var decision = layout(anchorBox, element, bubble, options);
  4049. position(element, decision, options);
  4050. setClasses(element, decision);
  4051. setHeight(element, decision, options);
  4052. };
  4053. var allAlignments = [
  4054. 'valignCentre',
  4055. 'alignLeft',
  4056. 'alignRight',
  4057. 'alignCentre',
  4058. 'top',
  4059. 'bottom',
  4060. 'left',
  4061. 'right'
  4062. ];
  4063. var nu$7 = function (width, yoffset, classes) {
  4064. var getClasses = function (prop) {
  4065. return readOptFrom$1(classes, prop).getOr([]);
  4066. };
  4067. var make = function (xDelta, yDelta, alignmentsOn) {
  4068. var alignmentsOff = difference(allAlignments, alignmentsOn);
  4069. return {
  4070. offset: function () {
  4071. return Position(xDelta, yDelta);
  4072. },
  4073. classesOn: function () {
  4074. return bind(alignmentsOn, getClasses);
  4075. },
  4076. classesOff: function () {
  4077. return bind(alignmentsOff, getClasses);
  4078. }
  4079. };
  4080. };
  4081. return {
  4082. southeast: function () {
  4083. return make(-width, yoffset, [
  4084. 'top',
  4085. 'alignLeft'
  4086. ]);
  4087. },
  4088. southwest: function () {
  4089. return make(width, yoffset, [
  4090. 'top',
  4091. 'alignRight'
  4092. ]);
  4093. },
  4094. south: function () {
  4095. return make(-width / 2, yoffset, [
  4096. 'top',
  4097. 'alignCentre'
  4098. ]);
  4099. },
  4100. northeast: function () {
  4101. return make(-width, -yoffset, [
  4102. 'bottom',
  4103. 'alignLeft'
  4104. ]);
  4105. },
  4106. northwest: function () {
  4107. return make(width, -yoffset, [
  4108. 'bottom',
  4109. 'alignRight'
  4110. ]);
  4111. },
  4112. north: function () {
  4113. return make(-width / 2, -yoffset, [
  4114. 'bottom',
  4115. 'alignCentre'
  4116. ]);
  4117. },
  4118. east: function () {
  4119. return make(width, -yoffset / 2, [
  4120. 'valignCentre',
  4121. 'left'
  4122. ]);
  4123. },
  4124. west: function () {
  4125. return make(-width, -yoffset / 2, [
  4126. 'valignCentre',
  4127. 'right'
  4128. ]);
  4129. }
  4130. };
  4131. };
  4132. var fallback = function () {
  4133. return nu$7(0, 0, {});
  4134. };
  4135. var nu$8 = Immutable('x', 'y', 'bubble', 'direction', 'label');
  4136. var eastX = function (anchor) {
  4137. return anchor.x();
  4138. };
  4139. var middleX = function (anchor, element) {
  4140. return anchor.x() + anchor.width() / 2 - element.width() / 2;
  4141. };
  4142. var westX = function (anchor, element) {
  4143. return anchor.x() + anchor.width() - element.width();
  4144. };
  4145. var northY = function (anchor, element) {
  4146. return anchor.y() - element.height();
  4147. };
  4148. var southY = function (anchor) {
  4149. return anchor.y() + anchor.height();
  4150. };
  4151. var centreY = function (anchor, element) {
  4152. return anchor.y() + anchor.height() / 2 - element.height() / 2;
  4153. };
  4154. var eastEdgeX = function (anchor) {
  4155. return anchor.x() + anchor.width();
  4156. };
  4157. var westEdgeX = function (anchor, element) {
  4158. return anchor.x() - element.width();
  4159. };
  4160. var southeast$1 = function (anchor, element, bubbles) {
  4161. return nu$8(eastX(anchor), southY(anchor), bubbles.southeast(), southeast(), 'layout-se');
  4162. };
  4163. var southwest$1 = function (anchor, element, bubbles) {
  4164. return nu$8(westX(anchor, element), southY(anchor), bubbles.southwest(), southwest(), 'layout-sw');
  4165. };
  4166. var northeast$1 = function (anchor, element, bubbles) {
  4167. return nu$8(eastX(anchor), northY(anchor, element), bubbles.northeast(), northeast(), 'layout-ne');
  4168. };
  4169. var northwest$1 = function (anchor, element, bubbles) {
  4170. return nu$8(westX(anchor, element), northY(anchor, element), bubbles.northwest(), northwest(), 'layout-nw');
  4171. };
  4172. var north$1 = function (anchor, element, bubbles) {
  4173. return nu$8(middleX(anchor, element), northY(anchor, element), bubbles.north(), north(), 'layout-n');
  4174. };
  4175. var south$1 = function (anchor, element, bubbles) {
  4176. return nu$8(middleX(anchor, element), southY(anchor), bubbles.south(), south(), 'layout-s');
  4177. };
  4178. var east$1 = function (anchor, element, bubbles) {
  4179. return nu$8(eastEdgeX(anchor), centreY(anchor, element), bubbles.east(), east(), 'layout-e');
  4180. };
  4181. var west$1 = function (anchor, element, bubbles) {
  4182. return nu$8(westEdgeX(anchor, element), centreY(anchor, element), bubbles.west(), west(), 'layout-w');
  4183. };
  4184. var all$2 = function () {
  4185. return [
  4186. southeast$1,
  4187. southwest$1,
  4188. northeast$1,
  4189. northwest$1,
  4190. south$1,
  4191. north$1,
  4192. east$1,
  4193. west$1
  4194. ];
  4195. };
  4196. var allRtl = function () {
  4197. return [
  4198. southwest$1,
  4199. southeast$1,
  4200. northwest$1,
  4201. northeast$1,
  4202. south$1,
  4203. north$1,
  4204. east$1,
  4205. west$1
  4206. ];
  4207. };
  4208. var nu$9 = function (x) {
  4209. return x;
  4210. };
  4211. var onDirection = function (isLtr, isRtl) {
  4212. return function (element) {
  4213. return getDirection(element) === 'rtl' ? isRtl : isLtr;
  4214. };
  4215. };
  4216. var getDirection = function (element) {
  4217. return get$4(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
  4218. };
  4219. var schema$1 = function () {
  4220. return optionObjOf('layouts', [
  4221. strict$1('onLtr'),
  4222. strict$1('onRtl')
  4223. ]);
  4224. };
  4225. var get$9 = function (elem, info, defaultLtr, defaultRtl) {
  4226. var ltr = info.layouts.map(function (ls) {
  4227. return ls.onLtr(elem);
  4228. }).getOr(defaultLtr);
  4229. var rtl = info.layouts.map(function (ls) {
  4230. return ls.onRtl(elem);
  4231. }).getOr(defaultRtl);
  4232. var f = onDirection(ltr, rtl);
  4233. return f(elem);
  4234. };
  4235. var placement = function (component, anchorInfo, origin) {
  4236. var hotspot = anchorInfo.hotspot;
  4237. var anchorBox = toBox(origin, hotspot.element());
  4238. var layouts = get$9(component.element(), anchorInfo, all$2(), allRtl());
  4239. return Option.some(nu$9({
  4240. anchorBox: anchorBox,
  4241. bubble: anchorInfo.bubble.getOr(fallback()),
  4242. overrides: {},
  4243. layouts: layouts,
  4244. placer: Option.none()
  4245. }));
  4246. };
  4247. var HotspotAnchor = [
  4248. strict$1('hotspot'),
  4249. option('bubble'),
  4250. schema$1(),
  4251. output('placement', placement)
  4252. ];
  4253. var placement$1 = function (component, anchorInfo, origin) {
  4254. var anchorBox = bounds(anchorInfo.x, anchorInfo.y, anchorInfo.width, anchorInfo.height);
  4255. var layouts = get$9(component.element(), anchorInfo, all$2(), allRtl());
  4256. return Option.some(nu$9({
  4257. anchorBox: anchorBox,
  4258. bubble: anchorInfo.bubble,
  4259. overrides: {},
  4260. layouts: layouts,
  4261. placer: Option.none()
  4262. }));
  4263. };
  4264. var MakeshiftAnchor = [
  4265. strict$1('x'),
  4266. strict$1('y'),
  4267. defaulted$1('height', 0),
  4268. defaulted$1('width', 0),
  4269. defaulted$1('bubble', fallback()),
  4270. schema$1(),
  4271. output('placement', placement$1)
  4272. ];
  4273. var zeroWidth = function () {
  4274. return '\uFEFF';
  4275. };
  4276. var adt$5 = Adt.generate([
  4277. { before: ['element'] },
  4278. {
  4279. on: [
  4280. 'element',
  4281. 'offset'
  4282. ]
  4283. },
  4284. { after: ['element'] }
  4285. ]);
  4286. var type$1 = Adt.generate([
  4287. { domRange: ['rng'] },
  4288. {
  4289. relative: [
  4290. 'startSitu',
  4291. 'finishSitu'
  4292. ]
  4293. },
  4294. {
  4295. exact: [
  4296. 'start',
  4297. 'soffset',
  4298. 'finish',
  4299. 'foffset'
  4300. ]
  4301. }
  4302. ]);
  4303. var range = Immutable('start', 'soffset', 'finish', 'foffset');
  4304. var exactFromRange = function (simRange) {
  4305. return type$1.exact(simRange.start(), simRange.soffset(), simRange.finish(), simRange.foffset());
  4306. };
  4307. var domRange = type$1.domRange;
  4308. var relative$1 = type$1.relative;
  4309. var exact = type$1.exact;
  4310. var makeRange = function (start, soffset, finish, foffset) {
  4311. var doc = owner(start);
  4312. var rng = doc.dom().createRange();
  4313. rng.setStart(start.dom(), soffset);
  4314. rng.setEnd(finish.dom(), foffset);
  4315. return rng;
  4316. };
  4317. var after$1 = function (start, soffset, finish, foffset) {
  4318. var r = makeRange(start, soffset, finish, foffset);
  4319. var same = eq(start, finish) && soffset === foffset;
  4320. return r.collapsed && !same;
  4321. };
  4322. var setStart = function (rng, situ) {
  4323. situ.fold(function (e) {
  4324. rng.setStartBefore(e.dom());
  4325. }, function (e, o) {
  4326. rng.setStart(e.dom(), o);
  4327. }, function (e) {
  4328. rng.setStartAfter(e.dom());
  4329. });
  4330. };
  4331. var setFinish = function (rng, situ) {
  4332. situ.fold(function (e) {
  4333. rng.setEndBefore(e.dom());
  4334. }, function (e, o) {
  4335. rng.setEnd(e.dom(), o);
  4336. }, function (e) {
  4337. rng.setEndAfter(e.dom());
  4338. });
  4339. };
  4340. var relativeToNative = function (win, startSitu, finishSitu) {
  4341. var range = win.document.createRange();
  4342. setStart(range, startSitu);
  4343. setFinish(range, finishSitu);
  4344. return range;
  4345. };
  4346. var exactToNative = function (win, start, soffset, finish, foffset) {
  4347. var rng = win.document.createRange();
  4348. rng.setStart(start.dom(), soffset);
  4349. rng.setEnd(finish.dom(), foffset);
  4350. return rng;
  4351. };
  4352. var toRect = function (rect) {
  4353. return {
  4354. left: constant(rect.left),
  4355. top: constant(rect.top),
  4356. right: constant(rect.right),
  4357. bottom: constant(rect.bottom),
  4358. width: constant(rect.width),
  4359. height: constant(rect.height)
  4360. };
  4361. };
  4362. var getFirstRect = function (rng) {
  4363. var rects = rng.getClientRects();
  4364. var rect = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
  4365. return rect.width > 0 || rect.height > 0 ? Option.some(rect).map(toRect) : Option.none();
  4366. };
  4367. var adt$6 = Adt.generate([
  4368. {
  4369. ltr: [
  4370. 'start',
  4371. 'soffset',
  4372. 'finish',
  4373. 'foffset'
  4374. ]
  4375. },
  4376. {
  4377. rtl: [
  4378. 'start',
  4379. 'soffset',
  4380. 'finish',
  4381. 'foffset'
  4382. ]
  4383. }
  4384. ]);
  4385. var fromRange = function (win, type, range) {
  4386. return type(Element.fromDom(range.startContainer), range.startOffset, Element.fromDom(range.endContainer), range.endOffset);
  4387. };
  4388. var getRanges = function (win, selection) {
  4389. return selection.match({
  4390. domRange: function (rng) {
  4391. return {
  4392. ltr: constant(rng),
  4393. rtl: Option.none
  4394. };
  4395. },
  4396. relative: function (startSitu, finishSitu) {
  4397. return {
  4398. ltr: cached(function () {
  4399. return relativeToNative(win, startSitu, finishSitu);
  4400. }),
  4401. rtl: cached(function () {
  4402. return Option.some(relativeToNative(win, finishSitu, startSitu));
  4403. })
  4404. };
  4405. },
  4406. exact: function (start, soffset, finish, foffset) {
  4407. return {
  4408. ltr: cached(function () {
  4409. return exactToNative(win, start, soffset, finish, foffset);
  4410. }),
  4411. rtl: cached(function () {
  4412. return Option.some(exactToNative(win, finish, foffset, start, soffset));
  4413. })
  4414. };
  4415. }
  4416. });
  4417. };
  4418. var doDiagnose = function (win, ranges) {
  4419. var rng = ranges.ltr();
  4420. if (rng.collapsed) {
  4421. var reversed = ranges.rtl().filter(function (rev) {
  4422. return rev.collapsed === false;
  4423. });
  4424. return reversed.map(function (rev) {
  4425. return adt$6.rtl(Element.fromDom(rev.endContainer), rev.endOffset, Element.fromDom(rev.startContainer), rev.startOffset);
  4426. }).getOrThunk(function () {
  4427. return fromRange(win, adt$6.ltr, rng);
  4428. });
  4429. } else {
  4430. return fromRange(win, adt$6.ltr, rng);
  4431. }
  4432. };
  4433. var diagnose = function (win, selection) {
  4434. var ranges = getRanges(win, selection);
  4435. return doDiagnose(win, ranges);
  4436. };
  4437. var asLtrRange = function (win, selection) {
  4438. var diagnosis = diagnose(win, selection);
  4439. return diagnosis.match({
  4440. ltr: function (start, soffset, finish, foffset) {
  4441. var rng = win.document.createRange();
  4442. rng.setStart(start.dom(), soffset);
  4443. rng.setEnd(finish.dom(), foffset);
  4444. return rng;
  4445. },
  4446. rtl: function (start, soffset, finish, foffset) {
  4447. var rng = win.document.createRange();
  4448. rng.setStart(finish.dom(), foffset);
  4449. rng.setEnd(start.dom(), soffset);
  4450. return rng;
  4451. }
  4452. });
  4453. };
  4454. var searchForPoint = function (rectForOffset, x, y, maxX, length) {
  4455. if (length === 0) {
  4456. return 0;
  4457. } else if (x === maxX) {
  4458. return length - 1;
  4459. }
  4460. var xDelta = maxX;
  4461. for (var i = 1; i < length; i++) {
  4462. var rect = rectForOffset(i);
  4463. var curDeltaX = Math.abs(x - rect.left);
  4464. if (y <= rect.bottom) {
  4465. if (y < rect.top || curDeltaX > xDelta) {
  4466. return i - 1;
  4467. } else {
  4468. xDelta = curDeltaX;
  4469. }
  4470. }
  4471. }
  4472. return 0;
  4473. };
  4474. var inRect = function (rect, x, y) {
  4475. return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
  4476. };
  4477. function NodeValue (is, name) {
  4478. var get = function (element) {
  4479. if (!is(element)) {
  4480. throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
  4481. }
  4482. return getOption(element).getOr('');
  4483. };
  4484. var getOptionIE10 = function (element) {
  4485. try {
  4486. return getOptionSafe(element);
  4487. } catch (e) {
  4488. return Option.none();
  4489. }
  4490. };
  4491. var getOptionSafe = function (element) {
  4492. return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
  4493. };
  4494. var browser = PlatformDetection$1.detect().browser;
  4495. var getOption = browser.isIE() && browser.version.major === 10 ? getOptionIE10 : getOptionSafe;
  4496. var set = function (element, value) {
  4497. if (!is(element)) {
  4498. throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
  4499. }
  4500. element.dom().nodeValue = value;
  4501. };
  4502. return {
  4503. get: get,
  4504. getOption: getOption,
  4505. set: set
  4506. };
  4507. }
  4508. var api$2 = NodeValue(isText, 'text');
  4509. var get$a = function (element) {
  4510. return api$2.get(element);
  4511. };
  4512. var getOption = function (element) {
  4513. return api$2.getOption(element);
  4514. };
  4515. var locateOffset = function (doc, textnode, x, y, rect) {
  4516. var rangeForOffset = function (o) {
  4517. var r = doc.dom().createRange();
  4518. r.setStart(textnode.dom(), o);
  4519. r.collapse(true);
  4520. return r;
  4521. };
  4522. var rectForOffset = function (o) {
  4523. var r = rangeForOffset(o);
  4524. return r.getBoundingClientRect();
  4525. };
  4526. var length = get$a(textnode).length;
  4527. var offset = searchForPoint(rectForOffset, x, y, rect.right, length);
  4528. return rangeForOffset(offset);
  4529. };
  4530. var locate = function (doc, node, x, y) {
  4531. var r = doc.dom().createRange();
  4532. r.selectNode(node.dom());
  4533. var rects = r.getClientRects();
  4534. var foundRect = findMap(rects, function (rect) {
  4535. return inRect(rect, x, y) ? Option.some(rect) : Option.none();
  4536. });
  4537. return foundRect.map(function (rect) {
  4538. return locateOffset(doc, node, x, y, rect);
  4539. });
  4540. };
  4541. var searchInChildren = function (doc, node, x, y) {
  4542. var r = doc.dom().createRange();
  4543. var nodes = children(node);
  4544. return findMap(nodes, function (n) {
  4545. r.selectNode(n.dom());
  4546. return inRect(r.getBoundingClientRect(), x, y) ? locateNode(doc, n, x, y) : Option.none();
  4547. });
  4548. };
  4549. var locateNode = function (doc, node, x, y) {
  4550. var locator = isText(node) ? locate : searchInChildren;
  4551. return locator(doc, node, x, y);
  4552. };
  4553. var locate$1 = function (doc, node, x, y) {
  4554. var r = doc.dom().createRange();
  4555. r.selectNode(node.dom());
  4556. var rect = r.getBoundingClientRect();
  4557. var boundedX = Math.max(rect.left, Math.min(rect.right, x));
  4558. var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
  4559. return locateNode(doc, node, boundedX, boundedY);
  4560. };
  4561. var NBSP = '\xA0';
  4562. var isTextNodeWithCursorPosition = function (el) {
  4563. return getOption(el).filter(function (text) {
  4564. return text.trim().length !== 0 || text.indexOf(NBSP) > -1;
  4565. }).isSome();
  4566. };
  4567. var elementsWithCursorPosition = [
  4568. 'img',
  4569. 'br'
  4570. ];
  4571. var isCursorPosition = function (elem) {
  4572. var hasCursorPosition = isTextNodeWithCursorPosition(elem);
  4573. return hasCursorPosition || contains(elementsWithCursorPosition, name(elem));
  4574. };
  4575. var first = function (element) {
  4576. return descendant(element, isCursorPosition);
  4577. };
  4578. var last$1 = function (element) {
  4579. return descendantRtl(element, isCursorPosition);
  4580. };
  4581. var descendantRtl = function (scope, predicate) {
  4582. var descend = function (element) {
  4583. var children$1 = children(element);
  4584. for (var i = children$1.length - 1; i >= 0; i--) {
  4585. var child = children$1[i];
  4586. if (predicate(child)) {
  4587. return Option.some(child);
  4588. }
  4589. var res = descend(child);
  4590. if (res.isSome()) {
  4591. return res;
  4592. }
  4593. }
  4594. return Option.none();
  4595. };
  4596. return descend(scope);
  4597. };
  4598. var COLLAPSE_TO_LEFT = true;
  4599. var COLLAPSE_TO_RIGHT = false;
  4600. var getCollapseDirection = function (rect, x) {
  4601. return x - rect.left < rect.right - x ? COLLAPSE_TO_LEFT : COLLAPSE_TO_RIGHT;
  4602. };
  4603. var createCollapsedNode = function (doc, target, collapseDirection) {
  4604. var r = doc.dom().createRange();
  4605. r.selectNode(target.dom());
  4606. r.collapse(collapseDirection);
  4607. return r;
  4608. };
  4609. var locateInElement = function (doc, node, x) {
  4610. var cursorRange = doc.dom().createRange();
  4611. cursorRange.selectNode(node.dom());
  4612. var rect = cursorRange.getBoundingClientRect();
  4613. var collapseDirection = getCollapseDirection(rect, x);
  4614. var f = collapseDirection === COLLAPSE_TO_LEFT ? first : last$1;
  4615. return f(node).map(function (target) {
  4616. return createCollapsedNode(doc, target, collapseDirection);
  4617. });
  4618. };
  4619. var locateInEmpty = function (doc, node, x) {
  4620. var rect = node.dom().getBoundingClientRect();
  4621. var collapseDirection = getCollapseDirection(rect, x);
  4622. return Option.some(createCollapsedNode(doc, node, collapseDirection));
  4623. };
  4624. var search = function (doc, node, x) {
  4625. var f = children(node).length === 0 ? locateInEmpty : locateInElement;
  4626. return f(doc, node, x);
  4627. };
  4628. var caretPositionFromPoint = function (doc, x, y) {
  4629. return Option.from(doc.dom().caretPositionFromPoint(x, y)).bind(function (pos) {
  4630. if (pos.offsetNode === null) {
  4631. return Option.none();
  4632. }
  4633. var r = doc.dom().createRange();
  4634. r.setStart(pos.offsetNode, pos.offset);
  4635. r.collapse();
  4636. return Option.some(r);
  4637. });
  4638. };
  4639. var caretRangeFromPoint = function (doc, x, y) {
  4640. return Option.from(doc.dom().caretRangeFromPoint(x, y));
  4641. };
  4642. var searchTextNodes = function (doc, node, x, y) {
  4643. var r = doc.dom().createRange();
  4644. r.selectNode(node.dom());
  4645. var rect = r.getBoundingClientRect();
  4646. var boundedX = Math.max(rect.left, Math.min(rect.right, x));
  4647. var boundedY = Math.max(rect.top, Math.min(rect.bottom, y));
  4648. return locate$1(doc, node, boundedX, boundedY);
  4649. };
  4650. var searchFromPoint = function (doc, x, y) {
  4651. return Element.fromPoint(doc, x, y).bind(function (elem) {
  4652. var fallback = function () {
  4653. return search(doc, elem, x);
  4654. };
  4655. return children(elem).length === 0 ? fallback() : searchTextNodes(doc, elem, x, y).orThunk(fallback);
  4656. });
  4657. };
  4658. var availableSearch = document.caretPositionFromPoint ? caretPositionFromPoint : document.caretRangeFromPoint ? caretRangeFromPoint : searchFromPoint;
  4659. var descendants = function (scope, selector) {
  4660. return all(selector, scope);
  4661. };
  4662. var readRange = function (selection) {
  4663. if (selection.rangeCount > 0) {
  4664. var firstRng = selection.getRangeAt(0);
  4665. var lastRng = selection.getRangeAt(selection.rangeCount - 1);
  4666. return Option.some(range(Element.fromDom(firstRng.startContainer), firstRng.startOffset, Element.fromDom(lastRng.endContainer), lastRng.endOffset));
  4667. } else {
  4668. return Option.none();
  4669. }
  4670. };
  4671. var doGetExact = function (selection) {
  4672. var anchor = Element.fromDom(selection.anchorNode);
  4673. var focus = Element.fromDom(selection.focusNode);
  4674. return after$1(anchor, selection.anchorOffset, focus, selection.focusOffset) ? Option.some(range(anchor, selection.anchorOffset, focus, selection.focusOffset)) : readRange(selection);
  4675. };
  4676. var getExact = function (win) {
  4677. return Option.from(win.getSelection()).filter(function (sel) {
  4678. return sel.rangeCount > 0;
  4679. }).bind(doGetExact);
  4680. };
  4681. var getFirstRect$1 = function (win, selection) {
  4682. var rng = asLtrRange(win, selection);
  4683. return getFirstRect(rng);
  4684. };
  4685. var point = Immutable('element', 'offset');
  4686. var descendOnce = function (element, offset) {
  4687. var children$1 = children(element);
  4688. if (children$1.length === 0) {
  4689. return point(element, offset);
  4690. } else if (offset < children$1.length) {
  4691. return point(children$1[offset], 0);
  4692. } else {
  4693. var last = children$1[children$1.length - 1];
  4694. var len = isText(last) ? get$a(last).length : children(last).length;
  4695. return point(last, len);
  4696. }
  4697. };
  4698. var adt$7 = Adt.generate([
  4699. { screen: ['point'] },
  4700. {
  4701. absolute: [
  4702. 'point',
  4703. 'scrollLeft',
  4704. 'scrollTop'
  4705. ]
  4706. }
  4707. ]);
  4708. var toFixed = function (pos) {
  4709. return pos.fold(function (point) {
  4710. return point;
  4711. }, function (point, scrollLeft, scrollTop) {
  4712. return point.translate(-scrollLeft, -scrollTop);
  4713. });
  4714. };
  4715. var toAbsolute = function (pos) {
  4716. return pos.fold(function (point) {
  4717. return point;
  4718. }, function (point, scrollLeft, scrollTop) {
  4719. return point;
  4720. });
  4721. };
  4722. var sum = function (points) {
  4723. return foldl(points, function (b, a) {
  4724. return b.translate(a.left(), a.top());
  4725. }, Position(0, 0));
  4726. };
  4727. var sumAsFixed = function (positions) {
  4728. var points = map(positions, toFixed);
  4729. return sum(points);
  4730. };
  4731. var sumAsAbsolute = function (positions) {
  4732. var points = map(positions, toAbsolute);
  4733. return sum(points);
  4734. };
  4735. var screen = adt$7.screen;
  4736. var absolute$1 = adt$7.absolute;
  4737. var getOffset = function (component, origin, anchorInfo) {
  4738. var win = defaultView(anchorInfo.root).dom();
  4739. var hasSameOwner = function (frame) {
  4740. var frameOwner = owner(frame);
  4741. var compOwner = owner(component.element());
  4742. return eq(frameOwner, compOwner);
  4743. };
  4744. return Option.from(win.frameElement).map(Element.fromDom).filter(hasSameOwner).map(absolute);
  4745. };
  4746. var getRootPoint = function (component, origin, anchorInfo) {
  4747. var doc = owner(component.element());
  4748. var outerScroll = get$6(doc);
  4749. var offset = getOffset(component, origin, anchorInfo).getOr(outerScroll);
  4750. return absolute$1(offset, outerScroll.left(), outerScroll.top());
  4751. };
  4752. var capRect = function (left, top, width, height) {
  4753. var newLeft = left, newTop = top, newWidth = width, newHeight = height;
  4754. if (left < 0) {
  4755. newLeft = 0;
  4756. newWidth = width + left;
  4757. }
  4758. if (top < 0) {
  4759. newTop = 0;
  4760. newHeight = height + top;
  4761. }
  4762. var point = screen(Position(newLeft, newTop));
  4763. return Option.some(pointed(point, newWidth, newHeight));
  4764. };
  4765. var calcNewAnchor = function (optBox, rootPoint, anchorInfo, origin, elem) {
  4766. return optBox.map(function (box) {
  4767. var points = [
  4768. rootPoint,
  4769. box.point()
  4770. ];
  4771. var topLeft = cata$1(origin, function () {
  4772. return sumAsAbsolute(points);
  4773. }, function () {
  4774. return sumAsAbsolute(points);
  4775. }, function () {
  4776. return sumAsFixed(points);
  4777. });
  4778. var anchorBox = rect(topLeft.left(), topLeft.top(), box.width(), box.height());
  4779. var layoutsLtr = function () {
  4780. return anchorInfo.showAbove ? [
  4781. northeast$1,
  4782. northwest$1,
  4783. southeast$1,
  4784. southwest$1,
  4785. north$1,
  4786. south$1
  4787. ] : [
  4788. southeast$1,
  4789. southwest$1,
  4790. northeast$1,
  4791. northwest$1,
  4792. south$1,
  4793. south$1
  4794. ];
  4795. };
  4796. var layoutsRtl = function () {
  4797. return anchorInfo.showAbove ? [
  4798. northwest$1,
  4799. northeast$1,
  4800. southwest$1,
  4801. southeast$1,
  4802. north$1,
  4803. south$1
  4804. ] : [
  4805. southwest$1,
  4806. southeast$1,
  4807. northwest$1,
  4808. northeast$1,
  4809. south$1,
  4810. north$1
  4811. ];
  4812. };
  4813. var layouts = get$9(elem, anchorInfo, layoutsLtr(), layoutsRtl());
  4814. return nu$9({
  4815. anchorBox: anchorBox,
  4816. bubble: anchorInfo.bubble.getOr(fallback()),
  4817. overrides: anchorInfo.overrides,
  4818. layouts: layouts,
  4819. placer: Option.none()
  4820. });
  4821. });
  4822. };
  4823. var ContentAnchorCommon = {
  4824. capRect: capRect,
  4825. calcNewAnchor: calcNewAnchor
  4826. };
  4827. var point$1 = Immutable('element', 'offset');
  4828. var descendOnce$1 = function (element, offset) {
  4829. return isText(element) ? point$1(element, offset) : descendOnce(element, offset);
  4830. };
  4831. var getAnchorSelection = function (win, anchorInfo) {
  4832. var getSelection = anchorInfo.getSelection.getOrThunk(function () {
  4833. return function () {
  4834. return getExact(win);
  4835. };
  4836. });
  4837. return getSelection().map(function (sel) {
  4838. var modStart = descendOnce$1(sel.start(), sel.soffset());
  4839. var modFinish = descendOnce$1(sel.finish(), sel.foffset());
  4840. return range(modStart.element(), modStart.offset(), modFinish.element(), modFinish.offset());
  4841. });
  4842. };
  4843. var placement$2 = function (component, anchorInfo, origin) {
  4844. var win = defaultView(anchorInfo.root).dom();
  4845. var rootPoint = getRootPoint(component, origin, anchorInfo);
  4846. var selectionBox = getAnchorSelection(win, anchorInfo).bind(function (sel) {
  4847. var optRect = getFirstRect$1(win, exactFromRange(sel)).orThunk(function () {
  4848. var x = Element.fromText(zeroWidth());
  4849. before(sel.start(), x);
  4850. return getFirstRect$1(win, exact(x, 0, x, 1)).map(function (rect) {
  4851. remove(x);
  4852. return rect;
  4853. });
  4854. });
  4855. return optRect.bind(function (rawRect) {
  4856. return ContentAnchorCommon.capRect(rawRect.left(), rawRect.top(), rawRect.width(), rawRect.height());
  4857. });
  4858. });
  4859. var targetElement = getAnchorSelection(win, anchorInfo).bind(function (sel) {
  4860. return isElement(sel.start()) ? Option.some(sel.start()) : parent(sel.start());
  4861. });
  4862. var elem = targetElement.getOr(component.element());
  4863. return ContentAnchorCommon.calcNewAnchor(selectionBox, rootPoint, anchorInfo, origin, elem);
  4864. };
  4865. var SelectionAnchor = [
  4866. option('getSelection'),
  4867. strict$1('root'),
  4868. option('bubble'),
  4869. schema$1(),
  4870. defaulted$1('overrides', {}),
  4871. defaulted$1('showAbove', false),
  4872. output('placement', placement$2)
  4873. ];
  4874. var placement$3 = function (component, anchorInfo, origin) {
  4875. var rootPoint = getRootPoint(component, origin, anchorInfo);
  4876. return anchorInfo.node.bind(function (target) {
  4877. var rect = target.dom().getBoundingClientRect();
  4878. var nodeBox = ContentAnchorCommon.capRect(rect.left, rect.top, rect.width, rect.height);
  4879. var elem = anchorInfo.node.getOr(component.element());
  4880. return ContentAnchorCommon.calcNewAnchor(nodeBox, rootPoint, anchorInfo, origin, elem);
  4881. });
  4882. };
  4883. var NodeAnchor = [
  4884. strict$1('node'),
  4885. strict$1('root'),
  4886. option('bubble'),
  4887. schema$1(),
  4888. defaulted$1('overrides', {}),
  4889. defaulted$1('showAbove', false),
  4890. output('placement', placement$3)
  4891. ];
  4892. var eastX$1 = function (anchor) {
  4893. return anchor.x() + anchor.width();
  4894. };
  4895. var westX$1 = function (anchor, element) {
  4896. return anchor.x() - element.width();
  4897. };
  4898. var northY$1 = function (anchor, element) {
  4899. return anchor.y() - element.height() + anchor.height();
  4900. };
  4901. var southY$1 = function (anchor) {
  4902. return anchor.y();
  4903. };
  4904. var southeast$2 = function (anchor, element, bubbles) {
  4905. return nu$8(eastX$1(anchor), southY$1(anchor), bubbles.southeast(), southeast(), 'link-layout-se');
  4906. };
  4907. var southwest$2 = function (anchor, element, bubbles) {
  4908. return nu$8(westX$1(anchor, element), southY$1(anchor), bubbles.southwest(), southwest(), 'link-layout-sw');
  4909. };
  4910. var northeast$2 = function (anchor, element, bubbles) {
  4911. return nu$8(eastX$1(anchor), northY$1(anchor, element), bubbles.northeast(), northeast(), 'link-layout-ne');
  4912. };
  4913. var northwest$2 = function (anchor, element, bubbles) {
  4914. return nu$8(westX$1(anchor, element), northY$1(anchor, element), bubbles.northwest(), northwest(), 'link-layout-nw');
  4915. };
  4916. var all$3 = function () {
  4917. return [
  4918. southeast$2,
  4919. southwest$2,
  4920. northeast$2,
  4921. northwest$2
  4922. ];
  4923. };
  4924. var allRtl$1 = function () {
  4925. return [
  4926. southwest$2,
  4927. southeast$2,
  4928. northwest$2,
  4929. northeast$2
  4930. ];
  4931. };
  4932. var placement$4 = function (component, submenuInfo, origin) {
  4933. var anchorBox = toBox(origin, submenuInfo.item.element());
  4934. var layouts = get$9(component.element(), submenuInfo, all$3(), allRtl$1());
  4935. return Option.some(nu$9({
  4936. anchorBox: anchorBox,
  4937. bubble: fallback(),
  4938. overrides: {},
  4939. layouts: layouts,
  4940. placer: Option.none()
  4941. }));
  4942. };
  4943. var SubmenuAnchor = [
  4944. strict$1('item'),
  4945. schema$1(),
  4946. output('placement', placement$4)
  4947. ];
  4948. var AnchorSchema = choose$1('anchor', {
  4949. selection: SelectionAnchor,
  4950. node: NodeAnchor,
  4951. hotspot: HotspotAnchor,
  4952. submenu: SubmenuAnchor,
  4953. makeshift: MakeshiftAnchor
  4954. });
  4955. var getFixedOrigin = function () {
  4956. return fixed(0, 0, domGlobals.window.innerWidth, domGlobals.window.innerHeight);
  4957. };
  4958. var getRelativeOrigin = function (component) {
  4959. var position = absolute(component.element());
  4960. var bounds = component.element().dom().getBoundingClientRect();
  4961. return relative(position.left(), position.top(), bounds.width, bounds.height);
  4962. };
  4963. var place = function (component, origin, anchoring, getBounds, placee) {
  4964. var anchor = box$1(anchoring.anchorBox, origin);
  4965. simple(anchor, placee.element(), anchoring.bubble, anchoring.layouts, getBounds, anchoring.overrides);
  4966. };
  4967. var position$1 = function (component, posConfig, posState, anchor, placee) {
  4968. var boxElement = Option.none();
  4969. positionWithin(component, posConfig, posState, anchor, placee, boxElement);
  4970. };
  4971. var positionWithin = function (component, posConfig, posState, anchor, placee, boxElement) {
  4972. var anchorage = asRawOrDie('positioning anchor.info', AnchorSchema, anchor);
  4973. set$2(placee.element(), 'position', 'fixed');
  4974. var oldVisibility = getRaw(placee.element(), 'visibility');
  4975. set$2(placee.element(), 'visibility', 'hidden');
  4976. var origin = posConfig.useFixed ? getFixedOrigin() : getRelativeOrigin(component);
  4977. var placer = anchorage.placement;
  4978. var getBounds = boxElement.map(function (boxElem) {
  4979. return function () {
  4980. return box(boxElem);
  4981. };
  4982. }).or(posConfig.getBounds);
  4983. placer(component, anchorage, origin).each(function (anchoring) {
  4984. var doPlace = anchoring.placer.getOr(place);
  4985. doPlace(component, origin, anchoring, getBounds, placee);
  4986. });
  4987. oldVisibility.fold(function () {
  4988. remove$6(placee.element(), 'visibility');
  4989. }, function (vis) {
  4990. set$2(placee.element(), 'visibility', vis);
  4991. });
  4992. if (getRaw(placee.element(), 'left').isNone() && getRaw(placee.element(), 'top').isNone() && getRaw(placee.element(), 'right').isNone() && getRaw(placee.element(), 'bottom').isNone() && getRaw(placee.element(), 'position').is('fixed')) {
  4993. remove$6(placee.element(), 'position');
  4994. }
  4995. };
  4996. var getMode = function (component, pConfig, pState) {
  4997. return pConfig.useFixed ? 'fixed' : 'absolute';
  4998. };
  4999. var PositionApis = /*#__PURE__*/Object.freeze({
  5000. position: position$1,
  5001. positionWithin: positionWithin,
  5002. getMode: getMode
  5003. });
  5004. var PositionSchema = [
  5005. defaulted$1('useFixed', false),
  5006. option('getBounds')
  5007. ];
  5008. var Positioning = create$1({
  5009. fields: PositionSchema,
  5010. name: 'positioning',
  5011. active: ActivePosition,
  5012. apis: PositionApis
  5013. });
  5014. var fireDetaching = function (component) {
  5015. emit(component, detachedFromDom());
  5016. var children = component.components();
  5017. each(children, fireDetaching);
  5018. };
  5019. var fireAttaching = function (component) {
  5020. var children = component.components();
  5021. each(children, fireAttaching);
  5022. emit(component, attachedToDom());
  5023. };
  5024. var attach = function (parent, child) {
  5025. attachWith(parent, child, append);
  5026. };
  5027. var attachWith = function (parent, child, insertion) {
  5028. parent.getSystem().addToWorld(child);
  5029. insertion(parent.element(), child.element());
  5030. if (inBody(parent.element())) {
  5031. fireAttaching(child);
  5032. }
  5033. parent.syncComponents();
  5034. };
  5035. var doDetach = function (component) {
  5036. fireDetaching(component);
  5037. remove(component.element());
  5038. component.getSystem().removeFromWorld(component);
  5039. };
  5040. var detach = function (component) {
  5041. var parent$1 = parent(component.element()).bind(function (p) {
  5042. return component.getSystem().getByDom(p).fold(Option.none, Option.some);
  5043. });
  5044. doDetach(component);
  5045. parent$1.each(function (p) {
  5046. p.syncComponents();
  5047. });
  5048. };
  5049. var detachChildren = function (component) {
  5050. var subs = component.components();
  5051. each(subs, doDetach);
  5052. empty(component.element());
  5053. component.syncComponents();
  5054. };
  5055. var attachSystem = function (element, guiSystem) {
  5056. attachSystemInternal(element, guiSystem, append);
  5057. };
  5058. var attachSystemAfter = function (element, guiSystem) {
  5059. attachSystemInternal(element, guiSystem, after);
  5060. };
  5061. var attachSystemInternal = function (element, guiSystem, inserter) {
  5062. inserter(element, guiSystem.element());
  5063. var children$1 = children(guiSystem.element());
  5064. each(children$1, function (child) {
  5065. guiSystem.getByDom(child).each(fireAttaching);
  5066. });
  5067. };
  5068. var detachSystem = function (guiSystem) {
  5069. var children$1 = children(guiSystem.element());
  5070. each(children$1, function (child) {
  5071. guiSystem.getByDom(child).each(fireDetaching);
  5072. });
  5073. remove(guiSystem.element());
  5074. };
  5075. var rebuild = function (sandbox, sConfig, sState, data) {
  5076. sState.get().each(function (data) {
  5077. detachChildren(sandbox);
  5078. });
  5079. var point = sConfig.getAttachPoint(sandbox);
  5080. attach(point, sandbox);
  5081. var built = sandbox.getSystem().build(data);
  5082. attach(sandbox, built);
  5083. sState.set(built);
  5084. return built;
  5085. };
  5086. var open = function (sandbox, sConfig, sState, data) {
  5087. var newState = rebuild(sandbox, sConfig, sState, data);
  5088. sConfig.onOpen(sandbox, newState);
  5089. return newState;
  5090. };
  5091. var openWhileCloaked = function (sandbox, sConfig, sState, data, transaction) {
  5092. cloak(sandbox, sConfig, sState);
  5093. open(sandbox, sConfig, sState, data);
  5094. transaction();
  5095. decloak(sandbox, sConfig, sState);
  5096. };
  5097. var close = function (sandbox, sConfig, sState) {
  5098. sState.get().each(function (data) {
  5099. detachChildren(sandbox);
  5100. detach(sandbox);
  5101. sConfig.onClose(sandbox, data);
  5102. sState.clear();
  5103. });
  5104. };
  5105. var isOpen = function (sandbox, sConfig, sState) {
  5106. return sState.isOpen();
  5107. };
  5108. var isPartOf$1 = function (sandbox, sConfig, sState, queryElem) {
  5109. return isOpen(sandbox, sConfig, sState) && sState.get().exists(function (data) {
  5110. return sConfig.isPartOf(sandbox, data, queryElem);
  5111. });
  5112. };
  5113. var getState = function (sandbox, sConfig, sState) {
  5114. return sState.get();
  5115. };
  5116. var store = function (sandbox, cssKey, attr, newValue) {
  5117. getRaw(sandbox.element(), cssKey).fold(function () {
  5118. remove$1(sandbox.element(), attr);
  5119. }, function (v) {
  5120. set$1(sandbox.element(), attr, v);
  5121. });
  5122. set$2(sandbox.element(), cssKey, newValue);
  5123. };
  5124. var restore = function (sandbox, cssKey, attr) {
  5125. if (has$1(sandbox.element(), attr)) {
  5126. var oldValue = get$2(sandbox.element(), attr);
  5127. set$2(sandbox.element(), cssKey, oldValue);
  5128. } else {
  5129. remove$6(sandbox.element(), cssKey);
  5130. }
  5131. };
  5132. var cloak = function (sandbox, sConfig, sState) {
  5133. var sink = sConfig.getAttachPoint(sandbox);
  5134. set$2(sandbox.element(), 'position', Positioning.getMode(sink));
  5135. store(sandbox, 'visibility', sConfig.cloakVisibilityAttr, 'hidden');
  5136. };
  5137. var hasPosition = function (element) {
  5138. return exists([
  5139. 'top',
  5140. 'left',
  5141. 'right',
  5142. 'bottom'
  5143. ], function (pos) {
  5144. return getRaw(element, pos).isSome();
  5145. });
  5146. };
  5147. var decloak = function (sandbox, sConfig, sState) {
  5148. if (!hasPosition(sandbox.element())) {
  5149. remove$6(sandbox.element(), 'position');
  5150. }
  5151. restore(sandbox, 'visibility', sConfig.cloakVisibilityAttr);
  5152. };
  5153. var SandboxApis = /*#__PURE__*/Object.freeze({
  5154. cloak: cloak,
  5155. decloak: decloak,
  5156. open: open,
  5157. openWhileCloaked: openWhileCloaked,
  5158. close: close,
  5159. isOpen: isOpen,
  5160. isPartOf: isPartOf$1,
  5161. getState: getState
  5162. });
  5163. var events$2 = function (sandboxConfig, sandboxState) {
  5164. return derive([run(sandboxClose(), function (sandbox, simulatedEvent) {
  5165. close(sandbox, sandboxConfig, sandboxState);
  5166. })]);
  5167. };
  5168. var ActiveSandbox = /*#__PURE__*/Object.freeze({
  5169. events: events$2
  5170. });
  5171. var SandboxSchema = [
  5172. onHandler('onOpen'),
  5173. onHandler('onClose'),
  5174. strict$1('isPartOf'),
  5175. strict$1('getAttachPoint'),
  5176. defaulted$1('cloakVisibilityAttr', 'data-precloak-visibility')
  5177. ];
  5178. var init = function () {
  5179. var contents = Cell(Option.none());
  5180. var readState = constant('not-implemented');
  5181. var isOpen = function () {
  5182. return contents.get().isSome();
  5183. };
  5184. var set = function (c) {
  5185. contents.set(Option.some(c));
  5186. };
  5187. var get = function (c) {
  5188. return contents.get();
  5189. };
  5190. var clear = function () {
  5191. contents.set(Option.none());
  5192. };
  5193. return nu$5({
  5194. readState: readState,
  5195. isOpen: isOpen,
  5196. clear: clear,
  5197. set: set,
  5198. get: get
  5199. });
  5200. };
  5201. var SandboxState = /*#__PURE__*/Object.freeze({
  5202. init: init
  5203. });
  5204. var Sandboxing = create$1({
  5205. fields: SandboxSchema,
  5206. name: 'sandboxing',
  5207. active: ActiveSandbox,
  5208. apis: SandboxApis,
  5209. state: SandboxState
  5210. });
  5211. var dismissPopups = constant('dismiss.popups');
  5212. var mouseReleased = constant('mouse.released');
  5213. var schema$2 = objOfOnly([
  5214. defaulted$1('isExtraPart', constant(false)),
  5215. optionObjOf('fireEventInstead', [defaulted$1('event', dismissRequested())])
  5216. ]);
  5217. var receivingConfig = function (rawSpec) {
  5218. var c = receiving(rawSpec);
  5219. return Receiving.config(c);
  5220. };
  5221. var receiving = function (rawSpec) {
  5222. var spec = asRawOrDie('Dismissal', schema$2, rawSpec);
  5223. return {
  5224. channels: wrap$1(dismissPopups(), {
  5225. schema: objOfOnly([strict$1('target')]),
  5226. onReceive: function (sandbox, data) {
  5227. if (Sandboxing.isOpen(sandbox)) {
  5228. var isPart = Sandboxing.isPartOf(sandbox, data.target) || spec.isExtraPart(sandbox, data.target);
  5229. if (!isPart) {
  5230. spec.fireEventInstead.fold(function () {
  5231. return Sandboxing.close(sandbox);
  5232. }, function (fe) {
  5233. return emit(sandbox, fe.event);
  5234. });
  5235. }
  5236. }
  5237. }
  5238. })
  5239. };
  5240. };
  5241. var field$1 = function (name, forbidden) {
  5242. return defaultedObjOf(name, {}, map(forbidden, function (f) {
  5243. return forbid(f.name(), 'Cannot configure ' + f.name() + ' for ' + name);
  5244. }).concat([state$1('dump', identity)]));
  5245. };
  5246. var get$b = function (data) {
  5247. return data.dump;
  5248. };
  5249. var augment = function (data, original) {
  5250. return __assign({}, data.dump, derive$1(original));
  5251. };
  5252. var SketchBehaviours = {
  5253. field: field$1,
  5254. augment: augment,
  5255. get: get$b
  5256. };
  5257. var _placeholder = 'placeholder';
  5258. var adt$8 = Adt.generate([
  5259. {
  5260. single: [
  5261. 'required',
  5262. 'valueThunk'
  5263. ]
  5264. },
  5265. {
  5266. multiple: [
  5267. 'required',
  5268. 'valueThunks'
  5269. ]
  5270. }
  5271. ]);
  5272. var subPlaceholder = function (owner, detail, compSpec, placeholders) {
  5273. if (owner.exists(function (o) {
  5274. return o !== compSpec.owner;
  5275. })) {
  5276. return adt$8.single(true, constant(compSpec));
  5277. }
  5278. return readOptFrom$1(placeholders, compSpec.name).fold(function () {
  5279. throw new Error('Unknown placeholder component: ' + compSpec.name + '\nKnown: [' + keys(placeholders) + ']\nNamespace: ' + owner.getOr('none') + '\nSpec: ' + JSON$1.stringify(compSpec, null, 2));
  5280. }, function (newSpec) {
  5281. return newSpec.replace();
  5282. });
  5283. };
  5284. var scan = function (owner, detail, compSpec, placeholders) {
  5285. if (compSpec.uiType === _placeholder) {
  5286. return subPlaceholder(owner, detail, compSpec, placeholders);
  5287. } else {
  5288. return adt$8.single(false, constant(compSpec));
  5289. }
  5290. };
  5291. var substitute = function (owner, detail, compSpec, placeholders) {
  5292. var base = scan(owner, detail, compSpec, placeholders);
  5293. return base.fold(function (req, valueThunk) {
  5294. var value = valueThunk(detail, compSpec.config, compSpec.validated);
  5295. var childSpecs = readOptFrom$1(value, 'components').getOr([]);
  5296. var substituted = bind(childSpecs, function (c) {
  5297. return substitute(owner, detail, c, placeholders);
  5298. });
  5299. return [__assign({}, value, { components: substituted })];
  5300. }, function (req, valuesThunk) {
  5301. var values = valuesThunk(detail, compSpec.config, compSpec.validated);
  5302. var preprocessor = compSpec.validated.preprocess.getOr(identity);
  5303. return preprocessor(values);
  5304. });
  5305. };
  5306. var substituteAll = function (owner, detail, components, placeholders) {
  5307. return bind(components, function (c) {
  5308. return substitute(owner, detail, c, placeholders);
  5309. });
  5310. };
  5311. var oneReplace = function (label, replacements) {
  5312. var called = false;
  5313. var used = function () {
  5314. return called;
  5315. };
  5316. var replace = function () {
  5317. if (called === true) {
  5318. throw new Error('Trying to use the same placeholder more than once: ' + label);
  5319. }
  5320. called = true;
  5321. return replacements;
  5322. };
  5323. var required = function () {
  5324. return replacements.fold(function (req, _) {
  5325. return req;
  5326. }, function (req, _) {
  5327. return req;
  5328. });
  5329. };
  5330. return {
  5331. name: constant(label),
  5332. required: required,
  5333. used: used,
  5334. replace: replace
  5335. };
  5336. };
  5337. var substitutePlaces = function (owner, detail, components, placeholders) {
  5338. var ps = map$1(placeholders, function (ph, name) {
  5339. return oneReplace(name, ph);
  5340. });
  5341. var outcome = substituteAll(owner, detail, components, ps);
  5342. each$1(ps, function (p) {
  5343. if (p.used() === false && p.required()) {
  5344. throw new Error('Placeholder: ' + p.name() + ' was not found in components list\nNamespace: ' + owner.getOr('none') + '\nComponents: ' + JSON$1.stringify(detail.components, null, 2));
  5345. }
  5346. });
  5347. return outcome;
  5348. };
  5349. var single = adt$8.single;
  5350. var multiple = adt$8.multiple;
  5351. var placeholder = constant(_placeholder);
  5352. var adt$9 = Adt.generate([
  5353. { required: ['data'] },
  5354. { external: ['data'] },
  5355. { optional: ['data'] },
  5356. { group: ['data'] }
  5357. ]);
  5358. var fFactory = defaulted$1('factory', { sketch: identity });
  5359. var fSchema = defaulted$1('schema', []);
  5360. var fName = strict$1('name');
  5361. var fPname = field('pname', 'pname', defaultedThunk(function (typeSpec) {
  5362. return '<alloy.' + generate$1(typeSpec.name) + '>';
  5363. }), anyValue$1());
  5364. var fGroupSchema = state$1('schema', function () {
  5365. return [option('preprocess')];
  5366. });
  5367. var fDefaults = defaulted$1('defaults', constant({}));
  5368. var fOverrides = defaulted$1('overrides', constant({}));
  5369. var requiredSpec = objOf([
  5370. fFactory,
  5371. fSchema,
  5372. fName,
  5373. fPname,
  5374. fDefaults,
  5375. fOverrides
  5376. ]);
  5377. var externalSpec = objOf([
  5378. fFactory,
  5379. fSchema,
  5380. fName,
  5381. fDefaults,
  5382. fOverrides
  5383. ]);
  5384. var optionalSpec = objOf([
  5385. fFactory,
  5386. fSchema,
  5387. fName,
  5388. fPname,
  5389. fDefaults,
  5390. fOverrides
  5391. ]);
  5392. var groupSpec = objOf([
  5393. fFactory,
  5394. fGroupSchema,
  5395. fName,
  5396. strict$1('unit'),
  5397. fPname,
  5398. fDefaults,
  5399. fOverrides
  5400. ]);
  5401. var asNamedPart = function (part) {
  5402. return part.fold(Option.some, Option.none, Option.some, Option.some);
  5403. };
  5404. var name$1 = function (part) {
  5405. var get = function (data) {
  5406. return data.name;
  5407. };
  5408. return part.fold(get, get, get, get);
  5409. };
  5410. var asCommon = function (part) {
  5411. return part.fold(identity, identity, identity, identity);
  5412. };
  5413. var convert = function (adtConstructor, partSchema) {
  5414. return function (spec) {
  5415. var data = asRawOrDie('Converting part type', partSchema, spec);
  5416. return adtConstructor(data);
  5417. };
  5418. };
  5419. var required = convert(adt$9.required, requiredSpec);
  5420. var external$1 = convert(adt$9.external, externalSpec);
  5421. var optional = convert(adt$9.optional, optionalSpec);
  5422. var group = convert(adt$9.group, groupSpec);
  5423. var original = constant('entirety');
  5424. var PartType = /*#__PURE__*/Object.freeze({
  5425. required: required,
  5426. external: external$1,
  5427. optional: optional,
  5428. group: group,
  5429. asNamedPart: asNamedPart,
  5430. name: name$1,
  5431. asCommon: asCommon,
  5432. original: original
  5433. });
  5434. var combine$2 = function (detail, data, partSpec, partValidated) {
  5435. return deepMerge(data.defaults(detail, partSpec, partValidated), partSpec, { uid: detail.partUids[data.name] }, data.overrides(detail, partSpec, partValidated));
  5436. };
  5437. var subs = function (owner, detail, parts) {
  5438. var internals = {};
  5439. var externals = {};
  5440. each(parts, function (part) {
  5441. part.fold(function (data) {
  5442. internals[data.pname] = single(true, function (detail, partSpec, partValidated) {
  5443. return data.factory.sketch(combine$2(detail, data, partSpec, partValidated));
  5444. });
  5445. }, function (data) {
  5446. var partSpec = detail.parts[data.name];
  5447. externals[data.name] = constant(data.factory.sketch(combine$2(detail, data, partSpec[original()]), partSpec));
  5448. }, function (data) {
  5449. internals[data.pname] = single(false, function (detail, partSpec, partValidated) {
  5450. return data.factory.sketch(combine$2(detail, data, partSpec, partValidated));
  5451. });
  5452. }, function (data) {
  5453. internals[data.pname] = multiple(true, function (detail, _partSpec, _partValidated) {
  5454. var units = detail[data.name];
  5455. return map(units, function (u) {
  5456. return data.factory.sketch(deepMerge(data.defaults(detail, u, _partValidated), u, data.overrides(detail, u)));
  5457. });
  5458. });
  5459. });
  5460. });
  5461. return {
  5462. internals: constant(internals),
  5463. externals: constant(externals)
  5464. };
  5465. };
  5466. var generate$4 = function (owner, parts) {
  5467. var r = {};
  5468. each(parts, function (part) {
  5469. asNamedPart(part).each(function (np) {
  5470. var g = doGenerateOne(owner, np.pname);
  5471. r[np.name] = function (config) {
  5472. var validated = asRawOrDie('Part: ' + np.name + ' in ' + owner, objOf(np.schema), config);
  5473. return __assign({}, g, {
  5474. config: config,
  5475. validated: validated
  5476. });
  5477. };
  5478. });
  5479. });
  5480. return r;
  5481. };
  5482. var doGenerateOne = function (owner, pname) {
  5483. return {
  5484. uiType: placeholder(),
  5485. owner: owner,
  5486. name: pname
  5487. };
  5488. };
  5489. var generateOne = function (owner, pname, config) {
  5490. return {
  5491. uiType: placeholder(),
  5492. owner: owner,
  5493. name: pname,
  5494. config: config,
  5495. validated: {}
  5496. };
  5497. };
  5498. var schemas = function (parts) {
  5499. return bind(parts, function (part) {
  5500. return part.fold(Option.none, Option.some, Option.none, Option.none).map(function (data) {
  5501. return strictObjOf(data.name, data.schema.concat([snapshot(original())]));
  5502. }).toArray();
  5503. });
  5504. };
  5505. var names = function (parts) {
  5506. return map(parts, name$1);
  5507. };
  5508. var substitutes = function (owner, detail, parts) {
  5509. return subs(owner, detail, parts);
  5510. };
  5511. var components = function (owner, detail, internals) {
  5512. return substitutePlaces(Option.some(owner), detail, detail.components, internals);
  5513. };
  5514. var getPart = function (component, detail, partKey) {
  5515. var uid = detail.partUids[partKey];
  5516. return component.getSystem().getByUid(uid).toOption();
  5517. };
  5518. var getPartOrDie = function (component, detail, partKey) {
  5519. return getPart(component, detail, partKey).getOrDie('Could not find part: ' + partKey);
  5520. };
  5521. var getParts = function (component, detail, partKeys) {
  5522. var r = {};
  5523. var uids = detail.partUids;
  5524. var system = component.getSystem();
  5525. each(partKeys, function (pk) {
  5526. r[pk] = system.getByUid(uids[pk]);
  5527. });
  5528. return map$1(r, constant);
  5529. };
  5530. var getAllParts = function (component, detail) {
  5531. var system = component.getSystem();
  5532. return map$1(detail.partUids, function (pUid, k) {
  5533. return constant(system.getByUid(pUid));
  5534. });
  5535. };
  5536. var getAllPartNames = function (detail) {
  5537. return keys(detail.partUids);
  5538. };
  5539. var getPartsOrDie = function (component, detail, partKeys) {
  5540. var r = {};
  5541. var uids = detail.partUids;
  5542. var system = component.getSystem();
  5543. each(partKeys, function (pk) {
  5544. r[pk] = system.getByUid(uids[pk]).getOrDie();
  5545. });
  5546. return map$1(r, constant);
  5547. };
  5548. var defaultUids = function (baseUid, partTypes) {
  5549. var partNames = names(partTypes);
  5550. return wrapAll$1(map(partNames, function (pn) {
  5551. return {
  5552. key: pn,
  5553. value: baseUid + '-' + pn
  5554. };
  5555. }));
  5556. };
  5557. var defaultUidsSchema = function (partTypes) {
  5558. return field('partUids', 'partUids', mergeWithThunk(function (spec) {
  5559. return defaultUids(spec.uid, partTypes);
  5560. }), anyValue$1());
  5561. };
  5562. var AlloyParts = /*#__PURE__*/Object.freeze({
  5563. generate: generate$4,
  5564. generateOne: generateOne,
  5565. schemas: schemas,
  5566. names: names,
  5567. substitutes: substitutes,
  5568. components: components,
  5569. defaultUids: defaultUids,
  5570. defaultUidsSchema: defaultUidsSchema,
  5571. getAllParts: getAllParts,
  5572. getAllPartNames: getAllPartNames,
  5573. getPart: getPart,
  5574. getPartOrDie: getPartOrDie,
  5575. getParts: getParts,
  5576. getPartsOrDie: getPartsOrDie
  5577. });
  5578. var base = function (label, partSchemas, partUidsSchemas, spec) {
  5579. var ps = partSchemas.length > 0 ? [strictObjOf('parts', partSchemas)] : [];
  5580. return ps.concat([
  5581. strict$1('uid'),
  5582. defaulted$1('dom', {}),
  5583. defaulted$1('components', []),
  5584. snapshot('originalSpec'),
  5585. defaulted$1('debug.sketcher', {})
  5586. ]).concat(partUidsSchemas);
  5587. };
  5588. var asRawOrDie$1 = function (label, schema, spec, partSchemas, partUidsSchemas) {
  5589. var baseS = base(label, partSchemas, partUidsSchemas, spec);
  5590. return asRawOrDie(label + ' [SpecSchema]', objOfOnly(baseS.concat(schema)), spec);
  5591. };
  5592. var single$1 = function (owner, schema, factory, spec) {
  5593. var specWithUid = supplyUid(spec);
  5594. var detail = asRawOrDie$1(owner, schema, specWithUid, [], []);
  5595. return factory(detail, specWithUid);
  5596. };
  5597. var composite = function (owner, schema, partTypes, factory, spec) {
  5598. var specWithUid = supplyUid(spec);
  5599. var partSchemas = schemas(partTypes);
  5600. var partUidsSchema = defaultUidsSchema(partTypes);
  5601. var detail = asRawOrDie$1(owner, schema, specWithUid, partSchemas, [partUidsSchema]);
  5602. var subs = substitutes(owner, detail, partTypes);
  5603. var components$1 = components(owner, detail, subs.internals());
  5604. return factory(detail, components$1, specWithUid, subs.externals());
  5605. };
  5606. var supplyUid = function (spec) {
  5607. return spec.hasOwnProperty('uid') ? spec : __assign({}, spec, { uid: generate$2('uid') });
  5608. };
  5609. function isSketchSpec(spec) {
  5610. return spec.uid !== undefined;
  5611. }
  5612. var singleSchema = objOfOnly([
  5613. strict$1('name'),
  5614. strict$1('factory'),
  5615. strict$1('configFields'),
  5616. defaulted$1('apis', {}),
  5617. defaulted$1('extraApis', {})
  5618. ]);
  5619. var compositeSchema = objOfOnly([
  5620. strict$1('name'),
  5621. strict$1('factory'),
  5622. strict$1('configFields'),
  5623. strict$1('partFields'),
  5624. defaulted$1('apis', {}),
  5625. defaulted$1('extraApis', {})
  5626. ]);
  5627. var single$2 = function (rawConfig) {
  5628. var config = asRawOrDie('Sketcher for ' + rawConfig.name, singleSchema, rawConfig);
  5629. var sketch = function (spec) {
  5630. return single$1(config.name, config.configFields, config.factory, spec);
  5631. };
  5632. var apis = map$1(config.apis, makeApi);
  5633. var extraApis = map$1(config.extraApis, function (f, k) {
  5634. return markAsExtraApi(f, k);
  5635. });
  5636. return __assign({
  5637. name: constant(config.name),
  5638. partFields: constant([]),
  5639. configFields: constant(config.configFields),
  5640. sketch: sketch
  5641. }, apis, extraApis);
  5642. };
  5643. var composite$1 = function (rawConfig) {
  5644. var config = asRawOrDie('Sketcher for ' + rawConfig.name, compositeSchema, rawConfig);
  5645. var sketch = function (spec) {
  5646. return composite(config.name, config.configFields, config.partFields, config.factory, spec);
  5647. };
  5648. var parts = generate$4(config.name, config.partFields);
  5649. var apis = map$1(config.apis, makeApi);
  5650. var extraApis = map$1(config.extraApis, function (f, k) {
  5651. return markAsExtraApi(f, k);
  5652. });
  5653. return __assign({
  5654. name: constant(config.name),
  5655. partFields: constant(config.partFields),
  5656. configFields: constant(config.configFields),
  5657. sketch: sketch,
  5658. parts: constant(parts)
  5659. }, apis, extraApis);
  5660. };
  5661. var inside = function (target) {
  5662. return name(target) === 'input' && get$2(target, 'type') !== 'radio' || name(target) === 'textarea';
  5663. };
  5664. var getCurrent = function (component, composeConfig, composeState) {
  5665. return composeConfig.find(component);
  5666. };
  5667. var ComposeApis = /*#__PURE__*/Object.freeze({
  5668. getCurrent: getCurrent
  5669. });
  5670. var ComposeSchema = [strict$1('find')];
  5671. var Composing = create$1({
  5672. fields: ComposeSchema,
  5673. name: 'composing',
  5674. apis: ComposeApis
  5675. });
  5676. var cycleBy = function (value, delta, min, max) {
  5677. var r = value + delta;
  5678. if (r > max) {
  5679. return min;
  5680. } else {
  5681. return r < min ? max : r;
  5682. }
  5683. };
  5684. var cap = function (value, min, max) {
  5685. if (value <= min) {
  5686. return min;
  5687. } else {
  5688. return value >= max ? max : value;
  5689. }
  5690. };
  5691. var dehighlightAllExcept = function (component, hConfig, hState, skip) {
  5692. var highlighted = descendants(component.element(), '.' + hConfig.highlightClass);
  5693. each(highlighted, function (h) {
  5694. if (!exists(skip, function (skipComp) {
  5695. return skipComp.element() === h;
  5696. })) {
  5697. remove$4(h, hConfig.highlightClass);
  5698. component.getSystem().getByDom(h).each(function (target) {
  5699. hConfig.onDehighlight(component, target);
  5700. emit(target, dehighlight());
  5701. });
  5702. }
  5703. });
  5704. };
  5705. var dehighlightAll = function (component, hConfig, hState) {
  5706. return dehighlightAllExcept(component, hConfig, hState, []);
  5707. };
  5708. var dehighlight$1 = function (component, hConfig, hState, target) {
  5709. if (isHighlighted(component, hConfig, hState, target)) {
  5710. remove$4(target.element(), hConfig.highlightClass);
  5711. hConfig.onDehighlight(component, target);
  5712. emit(target, dehighlight());
  5713. }
  5714. };
  5715. var highlight$1 = function (component, hConfig, hState, target) {
  5716. dehighlightAllExcept(component, hConfig, hState, [target]);
  5717. if (!isHighlighted(component, hConfig, hState, target)) {
  5718. add$2(target.element(), hConfig.highlightClass);
  5719. hConfig.onHighlight(component, target);
  5720. emit(target, highlight());
  5721. }
  5722. };
  5723. var highlightFirst = function (component, hConfig, hState) {
  5724. getFirst(component, hConfig, hState).each(function (firstComp) {
  5725. highlight$1(component, hConfig, hState, firstComp);
  5726. });
  5727. };
  5728. var highlightLast = function (component, hConfig, hState) {
  5729. getLast(component, hConfig, hState).each(function (lastComp) {
  5730. highlight$1(component, hConfig, hState, lastComp);
  5731. });
  5732. };
  5733. var highlightAt = function (component, hConfig, hState, index) {
  5734. getByIndex(component, hConfig, hState, index).fold(function (err) {
  5735. throw new Error(err);
  5736. }, function (firstComp) {
  5737. highlight$1(component, hConfig, hState, firstComp);
  5738. });
  5739. };
  5740. var highlightBy = function (component, hConfig, hState, predicate) {
  5741. var candidates = getCandidates(component, hConfig, hState);
  5742. var targetComp = find(candidates, predicate);
  5743. targetComp.each(function (c) {
  5744. highlight$1(component, hConfig, hState, c);
  5745. });
  5746. };
  5747. var isHighlighted = function (component, hConfig, hState, queryTarget) {
  5748. return has$2(queryTarget.element(), hConfig.highlightClass);
  5749. };
  5750. var getHighlighted = function (component, hConfig, hState) {
  5751. return descendant$1(component.element(), '.' + hConfig.highlightClass).bind(function (e) {
  5752. return component.getSystem().getByDom(e).toOption();
  5753. });
  5754. };
  5755. var getByIndex = function (component, hConfig, hState, index) {
  5756. var items = descendants(component.element(), '.' + hConfig.itemClass);
  5757. return Option.from(items[index]).fold(function () {
  5758. return Result.error('No element found with index ' + index);
  5759. }, component.getSystem().getByDom);
  5760. };
  5761. var getFirst = function (component, hConfig, hState) {
  5762. return descendant$1(component.element(), '.' + hConfig.itemClass).bind(function (e) {
  5763. return component.getSystem().getByDom(e).toOption();
  5764. });
  5765. };
  5766. var getLast = function (component, hConfig, hState) {
  5767. var items = descendants(component.element(), '.' + hConfig.itemClass);
  5768. var last = items.length > 0 ? Option.some(items[items.length - 1]) : Option.none();
  5769. return last.bind(function (c) {
  5770. return component.getSystem().getByDom(c).toOption();
  5771. });
  5772. };
  5773. var getDelta = function (component, hConfig, hState, delta) {
  5774. var items = descendants(component.element(), '.' + hConfig.itemClass);
  5775. var current = findIndex(items, function (item) {
  5776. return has$2(item, hConfig.highlightClass);
  5777. });
  5778. return current.bind(function (selected) {
  5779. var dest = cycleBy(selected, delta, 0, items.length - 1);
  5780. return component.getSystem().getByDom(items[dest]).toOption();
  5781. });
  5782. };
  5783. var getPrevious = function (component, hConfig, hState) {
  5784. return getDelta(component, hConfig, hState, -1);
  5785. };
  5786. var getNext = function (component, hConfig, hState) {
  5787. return getDelta(component, hConfig, hState, +1);
  5788. };
  5789. var getCandidates = function (component, hConfig, hState) {
  5790. var items = descendants(component.element(), '.' + hConfig.itemClass);
  5791. return cat(map(items, function (i) {
  5792. return component.getSystem().getByDom(i).toOption();
  5793. }));
  5794. };
  5795. var HighlightApis = /*#__PURE__*/Object.freeze({
  5796. dehighlightAll: dehighlightAll,
  5797. dehighlight: dehighlight$1,
  5798. highlight: highlight$1,
  5799. highlightFirst: highlightFirst,
  5800. highlightLast: highlightLast,
  5801. highlightAt: highlightAt,
  5802. highlightBy: highlightBy,
  5803. isHighlighted: isHighlighted,
  5804. getHighlighted: getHighlighted,
  5805. getFirst: getFirst,
  5806. getLast: getLast,
  5807. getPrevious: getPrevious,
  5808. getNext: getNext,
  5809. getCandidates: getCandidates
  5810. });
  5811. var HighlightSchema = [
  5812. strict$1('highlightClass'),
  5813. strict$1('itemClass'),
  5814. onHandler('onHighlight'),
  5815. onHandler('onDehighlight')
  5816. ];
  5817. var Highlighting = create$1({
  5818. fields: HighlightSchema,
  5819. name: 'highlighting',
  5820. apis: HighlightApis
  5821. });
  5822. var BACKSPACE = function () {
  5823. return [8];
  5824. };
  5825. var TAB = function () {
  5826. return [9];
  5827. };
  5828. var ENTER = function () {
  5829. return [13];
  5830. };
  5831. var ESCAPE = function () {
  5832. return [27];
  5833. };
  5834. var SPACE = function () {
  5835. return [32];
  5836. };
  5837. var LEFT = function () {
  5838. return [37];
  5839. };
  5840. var UP = function () {
  5841. return [38];
  5842. };
  5843. var RIGHT = function () {
  5844. return [39];
  5845. };
  5846. var DOWN = function () {
  5847. return [40];
  5848. };
  5849. var cyclePrev = function (values, index, predicate) {
  5850. var before = reverse(values.slice(0, index));
  5851. var after = reverse(values.slice(index + 1));
  5852. return find(before.concat(after), predicate);
  5853. };
  5854. var tryPrev = function (values, index, predicate) {
  5855. var before = reverse(values.slice(0, index));
  5856. return find(before, predicate);
  5857. };
  5858. var cycleNext = function (values, index, predicate) {
  5859. var before = values.slice(0, index);
  5860. var after = values.slice(index + 1);
  5861. return find(after.concat(before), predicate);
  5862. };
  5863. var tryNext = function (values, index, predicate) {
  5864. var after = values.slice(index + 1);
  5865. return find(after, predicate);
  5866. };
  5867. var inSet = function (keys) {
  5868. return function (event) {
  5869. var raw = event.raw();
  5870. return contains(keys, raw.which);
  5871. };
  5872. };
  5873. var and = function (preds) {
  5874. return function (event) {
  5875. return forall(preds, function (pred) {
  5876. return pred(event);
  5877. });
  5878. };
  5879. };
  5880. var isShift = function (event) {
  5881. var raw = event.raw();
  5882. return raw.shiftKey === true;
  5883. };
  5884. var isControl = function (event) {
  5885. var raw = event.raw();
  5886. return raw.ctrlKey === true;
  5887. };
  5888. var isNotShift = not(isShift);
  5889. var rule = function (matches, action) {
  5890. return {
  5891. matches: matches,
  5892. classification: action
  5893. };
  5894. };
  5895. var choose$2 = function (transitions, event) {
  5896. var transition = find(transitions, function (t) {
  5897. return t.matches(event);
  5898. });
  5899. return transition.map(function (t) {
  5900. return t.classification;
  5901. });
  5902. };
  5903. var focus$1 = function (element) {
  5904. element.dom().focus();
  5905. };
  5906. var blur = function (element) {
  5907. element.dom().blur();
  5908. };
  5909. var hasFocus = function (element) {
  5910. var doc = owner(element).dom();
  5911. return element.dom() === doc.activeElement;
  5912. };
  5913. var active = function (_DOC) {
  5914. var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
  5915. return Option.from(doc.activeElement).map(Element.fromDom);
  5916. };
  5917. var search$1 = function (element) {
  5918. return active(owner(element)).filter(function (e) {
  5919. return element.dom().contains(e.dom());
  5920. });
  5921. };
  5922. var reportFocusShifting = function (component, prevFocus, newFocus) {
  5923. var noChange = prevFocus.exists(function (p) {
  5924. return newFocus.exists(function (n) {
  5925. return eq(n, p);
  5926. });
  5927. });
  5928. if (!noChange) {
  5929. emitWith(component, focusShifted(), {
  5930. prevFocus: prevFocus,
  5931. newFocus: newFocus
  5932. });
  5933. }
  5934. };
  5935. var dom = function () {
  5936. var get = function (component) {
  5937. return search$1(component.element());
  5938. };
  5939. var set = function (component, focusee) {
  5940. var prevFocus = get(component);
  5941. component.getSystem().triggerFocus(focusee, component.element());
  5942. var newFocus = get(component);
  5943. reportFocusShifting(component, prevFocus, newFocus);
  5944. };
  5945. return {
  5946. get: get,
  5947. set: set
  5948. };
  5949. };
  5950. var highlights = function () {
  5951. var get = function (component) {
  5952. return Highlighting.getHighlighted(component).map(function (item) {
  5953. return item.element();
  5954. });
  5955. };
  5956. var set = function (component, element) {
  5957. var prevFocus = get(component);
  5958. component.getSystem().getByDom(element).fold(noop, function (item) {
  5959. Highlighting.highlight(component, item);
  5960. });
  5961. var newFocus = get(component);
  5962. reportFocusShifting(component, prevFocus, newFocus);
  5963. };
  5964. return {
  5965. get: get,
  5966. set: set
  5967. };
  5968. };
  5969. var FocusInsideModes;
  5970. (function (FocusInsideModes) {
  5971. FocusInsideModes['OnFocusMode'] = 'onFocus';
  5972. FocusInsideModes['OnEnterOrSpaceMode'] = 'onEnterOrSpace';
  5973. FocusInsideModes['OnApiMode'] = 'onApi';
  5974. }(FocusInsideModes || (FocusInsideModes = {})));
  5975. var typical = function (infoSchema, stateInit, getKeydownRules, getKeyupRules, optFocusIn) {
  5976. var schema = function () {
  5977. return infoSchema.concat([
  5978. defaulted$1('focusManager', dom()),
  5979. defaultedOf('focusInside', 'onFocus', valueOf(function (val) {
  5980. return contains([
  5981. 'onFocus',
  5982. 'onEnterOrSpace',
  5983. 'onApi'
  5984. ], val) ? Result.value(val) : Result.error('Invalid value for focusInside');
  5985. })),
  5986. output('handler', me),
  5987. output('state', stateInit),
  5988. output('sendFocusIn', optFocusIn)
  5989. ]);
  5990. };
  5991. var processKey = function (component, simulatedEvent, getRules, keyingConfig, keyingState) {
  5992. var rules = getRules(component, simulatedEvent, keyingConfig, keyingState);
  5993. return choose$2(rules, simulatedEvent.event()).bind(function (rule) {
  5994. return rule(component, simulatedEvent, keyingConfig, keyingState);
  5995. });
  5996. };
  5997. var toEvents = function (keyingConfig, keyingState) {
  5998. var onFocusHandler = keyingConfig.focusInside !== FocusInsideModes.OnFocusMode ? Option.none() : optFocusIn(keyingConfig).map(function (focusIn) {
  5999. return run(focus(), function (component, simulatedEvent) {
  6000. focusIn(component, keyingConfig, keyingState);
  6001. simulatedEvent.stop();
  6002. });
  6003. });
  6004. var tryGoInsideComponent = function (component, simulatedEvent) {
  6005. var isEnterOrSpace = inSet(SPACE().concat(ENTER()))(simulatedEvent.event());
  6006. if (keyingConfig.focusInside === FocusInsideModes.OnEnterOrSpaceMode && isEnterOrSpace && isSource(component, simulatedEvent)) {
  6007. optFocusIn(keyingConfig).each(function (focusIn) {
  6008. focusIn(component, keyingConfig, keyingState);
  6009. simulatedEvent.stop();
  6010. });
  6011. }
  6012. };
  6013. return derive(onFocusHandler.toArray().concat([
  6014. run(keydown(), function (component, simulatedEvent) {
  6015. processKey(component, simulatedEvent, getKeydownRules, keyingConfig, keyingState).fold(function () {
  6016. tryGoInsideComponent(component, simulatedEvent);
  6017. }, function (_) {
  6018. simulatedEvent.stop();
  6019. });
  6020. }),
  6021. run(keyup(), function (component, simulatedEvent) {
  6022. processKey(component, simulatedEvent, getKeyupRules, keyingConfig, keyingState).each(function (_) {
  6023. simulatedEvent.stop();
  6024. });
  6025. })
  6026. ]));
  6027. };
  6028. var me = {
  6029. schema: schema,
  6030. processKey: processKey,
  6031. toEvents: toEvents
  6032. };
  6033. return me;
  6034. };
  6035. var create$2 = function (cyclicField) {
  6036. var schema = [
  6037. option('onEscape'),
  6038. option('onEnter'),
  6039. defaulted$1('selector', '[data-alloy-tabstop="true"]'),
  6040. defaulted$1('firstTabstop', 0),
  6041. defaulted$1('useTabstopAt', constant(true)),
  6042. option('visibilitySelector')
  6043. ].concat([cyclicField]);
  6044. var isVisible = function (tabbingConfig, element) {
  6045. var target = tabbingConfig.visibilitySelector.bind(function (sel) {
  6046. return closest$3(element, sel);
  6047. }).getOr(element);
  6048. return get$8(target) > 0;
  6049. };
  6050. var findInitial = function (component, tabbingConfig) {
  6051. var tabstops = descendants(component.element(), tabbingConfig.selector);
  6052. var visibles = filter(tabstops, function (elem) {
  6053. return isVisible(tabbingConfig, elem);
  6054. });
  6055. return Option.from(visibles[tabbingConfig.firstTabstop]);
  6056. };
  6057. var findCurrent = function (component, tabbingConfig) {
  6058. return tabbingConfig.focusManager.get(component).bind(function (elem) {
  6059. return closest$3(elem, tabbingConfig.selector);
  6060. });
  6061. };
  6062. var isTabstop = function (tabbingConfig, element) {
  6063. return isVisible(tabbingConfig, element) && tabbingConfig.useTabstopAt(element);
  6064. };
  6065. var focusIn = function (component, tabbingConfig) {
  6066. findInitial(component, tabbingConfig).each(function (target) {
  6067. tabbingConfig.focusManager.set(component, target);
  6068. });
  6069. };
  6070. var goFromTabstop = function (component, tabstops, stopIndex, tabbingConfig, cycle) {
  6071. return cycle(tabstops, stopIndex, function (elem) {
  6072. return isTabstop(tabbingConfig, elem);
  6073. }).fold(function () {
  6074. return tabbingConfig.cyclic ? Option.some(true) : Option.none();
  6075. }, function (target) {
  6076. tabbingConfig.focusManager.set(component, target);
  6077. return Option.some(true);
  6078. });
  6079. };
  6080. var go = function (component, simulatedEvent, tabbingConfig, cycle) {
  6081. var tabstops = descendants(component.element(), tabbingConfig.selector);
  6082. return findCurrent(component, tabbingConfig).bind(function (tabstop) {
  6083. var optStopIndex = findIndex(tabstops, curry(eq, tabstop));
  6084. return optStopIndex.bind(function (stopIndex) {
  6085. return goFromTabstop(component, tabstops, stopIndex, tabbingConfig, cycle);
  6086. });
  6087. });
  6088. };
  6089. var goBackwards = function (component, simulatedEvent, tabbingConfig, tabbingState) {
  6090. var navigate = tabbingConfig.cyclic ? cyclePrev : tryPrev;
  6091. return go(component, simulatedEvent, tabbingConfig, navigate);
  6092. };
  6093. var goForwards = function (component, simulatedEvent, tabbingConfig, tabbingState) {
  6094. var navigate = tabbingConfig.cyclic ? cycleNext : tryNext;
  6095. return go(component, simulatedEvent, tabbingConfig, navigate);
  6096. };
  6097. var execute = function (component, simulatedEvent, tabbingConfig, tabbingState) {
  6098. return tabbingConfig.onEnter.bind(function (f) {
  6099. return f(component, simulatedEvent);
  6100. });
  6101. };
  6102. var exit = function (component, simulatedEvent, tabbingConfig, tabbingState) {
  6103. return tabbingConfig.onEscape.bind(function (f) {
  6104. return f(component, simulatedEvent);
  6105. });
  6106. };
  6107. var getKeydownRules = constant([
  6108. rule(and([
  6109. isShift,
  6110. inSet(TAB())
  6111. ]), goBackwards),
  6112. rule(inSet(TAB()), goForwards),
  6113. rule(inSet(ESCAPE()), exit),
  6114. rule(and([
  6115. isNotShift,
  6116. inSet(ENTER())
  6117. ]), execute)
  6118. ]);
  6119. var getKeyupRules = constant([]);
  6120. return typical(schema, NoState.init, getKeydownRules, getKeyupRules, function () {
  6121. return Option.some(focusIn);
  6122. });
  6123. };
  6124. var AcyclicType = create$2(state$1('cyclic', constant(false)));
  6125. var CyclicType = create$2(state$1('cyclic', constant(true)));
  6126. var doDefaultExecute = function (component, simulatedEvent, focused) {
  6127. dispatch(component, focused, execute());
  6128. return Option.some(true);
  6129. };
  6130. var defaultExecute = function (component, simulatedEvent, focused) {
  6131. return inside(focused) && inSet(SPACE())(simulatedEvent.event()) ? Option.none() : doDefaultExecute(component, simulatedEvent, focused);
  6132. };
  6133. var stopEventForFirefox = function (component, simulatedEvent) {
  6134. return Option.some(true);
  6135. };
  6136. var schema$3 = [
  6137. defaulted$1('execute', defaultExecute),
  6138. defaulted$1('useSpace', false),
  6139. defaulted$1('useEnter', true),
  6140. defaulted$1('useControlEnter', false),
  6141. defaulted$1('useDown', false)
  6142. ];
  6143. var execute$1 = function (component, simulatedEvent, executeConfig) {
  6144. return executeConfig.execute(component, simulatedEvent, component.element());
  6145. };
  6146. var getKeydownRules = function (component, simulatedEvent, executeConfig, executeState) {
  6147. var spaceExec = executeConfig.useSpace && !inside(component.element()) ? SPACE() : [];
  6148. var enterExec = executeConfig.useEnter ? ENTER() : [];
  6149. var downExec = executeConfig.useDown ? DOWN() : [];
  6150. var execKeys = spaceExec.concat(enterExec).concat(downExec);
  6151. return [rule(inSet(execKeys), execute$1)].concat(executeConfig.useControlEnter ? [rule(and([
  6152. isControl,
  6153. inSet(ENTER())
  6154. ]), execute$1)] : []);
  6155. };
  6156. var getKeyupRules = function (component, simulatedEvent, executeConfig, executeState) {
  6157. return executeConfig.useSpace && !inside(component.element()) ? [rule(inSet(SPACE()), stopEventForFirefox)] : [];
  6158. };
  6159. var ExecutionType = typical(schema$3, NoState.init, getKeydownRules, getKeyupRules, function () {
  6160. return Option.none();
  6161. });
  6162. var flatgrid = function (spec) {
  6163. var dimensions = Cell(Option.none());
  6164. var setGridSize = function (numRows, numColumns) {
  6165. dimensions.set(Option.some({
  6166. numRows: constant(numRows),
  6167. numColumns: constant(numColumns)
  6168. }));
  6169. };
  6170. var getNumRows = function () {
  6171. return dimensions.get().map(function (d) {
  6172. return d.numRows();
  6173. });
  6174. };
  6175. var getNumColumns = function () {
  6176. return dimensions.get().map(function (d) {
  6177. return d.numColumns();
  6178. });
  6179. };
  6180. return nu$5({
  6181. readState: function () {
  6182. return dimensions.get().map(function (d) {
  6183. return {
  6184. numRows: d.numRows(),
  6185. numColumns: d.numColumns()
  6186. };
  6187. }).getOr({
  6188. numRows: '?',
  6189. numColumns: '?'
  6190. });
  6191. },
  6192. setGridSize: setGridSize,
  6193. getNumRows: getNumRows,
  6194. getNumColumns: getNumColumns
  6195. });
  6196. };
  6197. var init$1 = function (spec) {
  6198. return spec.state(spec);
  6199. };
  6200. var KeyingState = /*#__PURE__*/Object.freeze({
  6201. flatgrid: flatgrid,
  6202. init: init$1
  6203. });
  6204. var useH = function (movement) {
  6205. return function (component, simulatedEvent, config, state) {
  6206. var move = movement(component.element());
  6207. return use(move, component, simulatedEvent, config, state);
  6208. };
  6209. };
  6210. var west$2 = function (moveLeft, moveRight) {
  6211. var movement = onDirection(moveLeft, moveRight);
  6212. return useH(movement);
  6213. };
  6214. var east$2 = function (moveLeft, moveRight) {
  6215. var movement = onDirection(moveRight, moveLeft);
  6216. return useH(movement);
  6217. };
  6218. var useV = function (move) {
  6219. return function (component, simulatedEvent, config, state) {
  6220. return use(move, component, simulatedEvent, config, state);
  6221. };
  6222. };
  6223. var use = function (move, component, simulatedEvent, config, state) {
  6224. var outcome = config.focusManager.get(component).bind(function (focused) {
  6225. return move(component.element(), focused, config, state);
  6226. });
  6227. return outcome.map(function (newFocus) {
  6228. config.focusManager.set(component, newFocus);
  6229. return true;
  6230. });
  6231. };
  6232. var north$2 = useV;
  6233. var south$2 = useV;
  6234. var move = useV;
  6235. var isHidden = function (dom) {
  6236. return dom.offsetWidth <= 0 && dom.offsetHeight <= 0;
  6237. };
  6238. var isVisible = function (element) {
  6239. var dom = element.dom();
  6240. return !isHidden(dom);
  6241. };
  6242. var indexInfo = MixedBag([
  6243. 'index',
  6244. 'candidates'
  6245. ], []);
  6246. var locate$2 = function (candidates, predicate) {
  6247. return findIndex(candidates, predicate).map(function (index) {
  6248. return indexInfo({
  6249. index: index,
  6250. candidates: candidates
  6251. });
  6252. });
  6253. };
  6254. var locateVisible = function (container, current, selector) {
  6255. var filter = isVisible;
  6256. return locateIn(container, current, selector, filter);
  6257. };
  6258. var locateIn = function (container, current, selector, filter$1) {
  6259. var predicate = curry(eq, current);
  6260. var candidates = descendants(container, selector);
  6261. var visible = filter(candidates, isVisible);
  6262. return locate$2(visible, predicate);
  6263. };
  6264. var findIndex$1 = function (elements, target) {
  6265. return findIndex(elements, function (elem) {
  6266. return eq(target, elem);
  6267. });
  6268. };
  6269. var withGrid = function (values, index, numCols, f) {
  6270. var oldRow = Math.floor(index / numCols);
  6271. var oldColumn = index % numCols;
  6272. return f(oldRow, oldColumn).bind(function (address) {
  6273. var newIndex = address.row() * numCols + address.column();
  6274. return newIndex >= 0 && newIndex < values.length ? Option.some(values[newIndex]) : Option.none();
  6275. });
  6276. };
  6277. var cycleHorizontal = function (values, index, numRows, numCols, delta) {
  6278. return withGrid(values, index, numCols, function (oldRow, oldColumn) {
  6279. var onLastRow = oldRow === numRows - 1;
  6280. var colsInRow = onLastRow ? values.length - oldRow * numCols : numCols;
  6281. var newColumn = cycleBy(oldColumn, delta, 0, colsInRow - 1);
  6282. return Option.some({
  6283. row: constant(oldRow),
  6284. column: constant(newColumn)
  6285. });
  6286. });
  6287. };
  6288. var cycleVertical = function (values, index, numRows, numCols, delta) {
  6289. return withGrid(values, index, numCols, function (oldRow, oldColumn) {
  6290. var newRow = cycleBy(oldRow, delta, 0, numRows - 1);
  6291. var onLastRow = newRow === numRows - 1;
  6292. var colsInRow = onLastRow ? values.length - newRow * numCols : numCols;
  6293. var newCol = cap(oldColumn, 0, colsInRow - 1);
  6294. return Option.some({
  6295. row: constant(newRow),
  6296. column: constant(newCol)
  6297. });
  6298. });
  6299. };
  6300. var cycleRight = function (values, index, numRows, numCols) {
  6301. return cycleHorizontal(values, index, numRows, numCols, +1);
  6302. };
  6303. var cycleLeft = function (values, index, numRows, numCols) {
  6304. return cycleHorizontal(values, index, numRows, numCols, -1);
  6305. };
  6306. var cycleUp = function (values, index, numRows, numCols) {
  6307. return cycleVertical(values, index, numRows, numCols, -1);
  6308. };
  6309. var cycleDown = function (values, index, numRows, numCols) {
  6310. return cycleVertical(values, index, numRows, numCols, +1);
  6311. };
  6312. var schema$4 = [
  6313. strict$1('selector'),
  6314. defaulted$1('execute', defaultExecute),
  6315. onKeyboardHandler('onEscape'),
  6316. defaulted$1('captureTab', false),
  6317. initSize()
  6318. ];
  6319. var focusIn = function (component, gridConfig, gridState) {
  6320. descendant$1(component.element(), gridConfig.selector).each(function (first) {
  6321. gridConfig.focusManager.set(component, first);
  6322. });
  6323. };
  6324. var findCurrent = function (component, gridConfig) {
  6325. return gridConfig.focusManager.get(component).bind(function (elem) {
  6326. return closest$3(elem, gridConfig.selector);
  6327. });
  6328. };
  6329. var execute$2 = function (component, simulatedEvent, gridConfig, gridState) {
  6330. return findCurrent(component, gridConfig).bind(function (focused) {
  6331. return gridConfig.execute(component, simulatedEvent, focused);
  6332. });
  6333. };
  6334. var doMove = function (cycle) {
  6335. return function (element, focused, gridConfig, gridState) {
  6336. return locateVisible(element, focused, gridConfig.selector).bind(function (identified) {
  6337. return cycle(identified.candidates(), identified.index(), gridState.getNumRows().getOr(gridConfig.initSize.numRows), gridState.getNumColumns().getOr(gridConfig.initSize.numColumns));
  6338. });
  6339. };
  6340. };
  6341. var handleTab = function (component, simulatedEvent, gridConfig, gridState) {
  6342. return gridConfig.captureTab ? Option.some(true) : Option.none();
  6343. };
  6344. var doEscape = function (component, simulatedEvent, gridConfig, gridState) {
  6345. return gridConfig.onEscape(component, simulatedEvent);
  6346. };
  6347. var moveLeft = doMove(cycleLeft);
  6348. var moveRight = doMove(cycleRight);
  6349. var moveNorth = doMove(cycleUp);
  6350. var moveSouth = doMove(cycleDown);
  6351. var getKeydownRules$1 = constant([
  6352. rule(inSet(LEFT()), west$2(moveLeft, moveRight)),
  6353. rule(inSet(RIGHT()), east$2(moveLeft, moveRight)),
  6354. rule(inSet(UP()), north$2(moveNorth)),
  6355. rule(inSet(DOWN()), south$2(moveSouth)),
  6356. rule(and([
  6357. isShift,
  6358. inSet(TAB())
  6359. ]), handleTab),
  6360. rule(and([
  6361. isNotShift,
  6362. inSet(TAB())
  6363. ]), handleTab),
  6364. rule(inSet(ESCAPE()), doEscape),
  6365. rule(inSet(SPACE().concat(ENTER())), execute$2)
  6366. ]);
  6367. var getKeyupRules$1 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
  6368. var FlatgridType = typical(schema$4, flatgrid, getKeydownRules$1, getKeyupRules$1, function () {
  6369. return Option.some(focusIn);
  6370. });
  6371. var horizontal = function (container, selector, current, delta) {
  6372. var isDisabledButton = function (candidate) {
  6373. return name(candidate) === 'button' && get$2(candidate, 'disabled') === 'disabled';
  6374. };
  6375. var tryCycle = function (initial, index, candidates) {
  6376. var newIndex = cycleBy(index, delta, 0, candidates.length - 1);
  6377. if (newIndex === initial) {
  6378. return Option.none();
  6379. } else {
  6380. return isDisabledButton(candidates[newIndex]) ? tryCycle(initial, newIndex, candidates) : Option.from(candidates[newIndex]);
  6381. }
  6382. };
  6383. return locateVisible(container, current, selector).bind(function (identified) {
  6384. var index = identified.index();
  6385. var candidates = identified.candidates();
  6386. return tryCycle(index, index, candidates);
  6387. });
  6388. };
  6389. var schema$5 = [
  6390. strict$1('selector'),
  6391. defaulted$1('getInitial', Option.none),
  6392. defaulted$1('execute', defaultExecute),
  6393. onKeyboardHandler('onEscape'),
  6394. defaulted$1('executeOnMove', false),
  6395. defaulted$1('allowVertical', true)
  6396. ];
  6397. var findCurrent$1 = function (component, flowConfig) {
  6398. return flowConfig.focusManager.get(component).bind(function (elem) {
  6399. return closest$3(elem, flowConfig.selector);
  6400. });
  6401. };
  6402. var execute$3 = function (component, simulatedEvent, flowConfig) {
  6403. return findCurrent$1(component, flowConfig).bind(function (focused) {
  6404. return flowConfig.execute(component, simulatedEvent, focused);
  6405. });
  6406. };
  6407. var focusIn$1 = function (component, flowConfig) {
  6408. flowConfig.getInitial(component).orThunk(function () {
  6409. return descendant$1(component.element(), flowConfig.selector);
  6410. }).each(function (first) {
  6411. flowConfig.focusManager.set(component, first);
  6412. });
  6413. };
  6414. var moveLeft$1 = function (element, focused, info) {
  6415. return horizontal(element, info.selector, focused, -1);
  6416. };
  6417. var moveRight$1 = function (element, focused, info) {
  6418. return horizontal(element, info.selector, focused, +1);
  6419. };
  6420. var doMove$1 = function (movement) {
  6421. return function (component, simulatedEvent, flowConfig) {
  6422. return movement(component, simulatedEvent, flowConfig).bind(function () {
  6423. return flowConfig.executeOnMove ? execute$3(component, simulatedEvent, flowConfig) : Option.some(true);
  6424. });
  6425. };
  6426. };
  6427. var doEscape$1 = function (component, simulatedEvent, flowConfig, _flowState) {
  6428. return flowConfig.onEscape(component, simulatedEvent);
  6429. };
  6430. var getKeydownRules$2 = function (_component, _se, flowConfig, _flowState) {
  6431. var westMovers = LEFT().concat(flowConfig.allowVertical ? UP() : []);
  6432. var eastMovers = RIGHT().concat(flowConfig.allowVertical ? DOWN() : []);
  6433. return [
  6434. rule(inSet(westMovers), doMove$1(west$2(moveLeft$1, moveRight$1))),
  6435. rule(inSet(eastMovers), doMove$1(east$2(moveLeft$1, moveRight$1))),
  6436. rule(inSet(ENTER()), execute$3),
  6437. rule(inSet(SPACE()), execute$3),
  6438. rule(inSet(ESCAPE()), doEscape$1)
  6439. ];
  6440. };
  6441. var getKeyupRules$2 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
  6442. var FlowType = typical(schema$5, NoState.init, getKeydownRules$2, getKeyupRules$2, function () {
  6443. return Option.some(focusIn$1);
  6444. });
  6445. var outcome = MixedBag([
  6446. 'rowIndex',
  6447. 'columnIndex',
  6448. 'cell'
  6449. ], []);
  6450. var toCell = function (matrix, rowIndex, columnIndex) {
  6451. return Option.from(matrix[rowIndex]).bind(function (row) {
  6452. return Option.from(row[columnIndex]).map(function (cell) {
  6453. return outcome({
  6454. rowIndex: rowIndex,
  6455. columnIndex: columnIndex,
  6456. cell: cell
  6457. });
  6458. });
  6459. });
  6460. };
  6461. var cycleHorizontal$1 = function (matrix, rowIndex, startCol, deltaCol) {
  6462. var row = matrix[rowIndex];
  6463. var colsInRow = row.length;
  6464. var newColIndex = cycleBy(startCol, deltaCol, 0, colsInRow - 1);
  6465. return toCell(matrix, rowIndex, newColIndex);
  6466. };
  6467. var cycleVertical$1 = function (matrix, colIndex, startRow, deltaRow) {
  6468. var nextRowIndex = cycleBy(startRow, deltaRow, 0, matrix.length - 1);
  6469. var colsInNextRow = matrix[nextRowIndex].length;
  6470. var nextColIndex = cap(colIndex, 0, colsInNextRow - 1);
  6471. return toCell(matrix, nextRowIndex, nextColIndex);
  6472. };
  6473. var moveHorizontal = function (matrix, rowIndex, startCol, deltaCol) {
  6474. var row = matrix[rowIndex];
  6475. var colsInRow = row.length;
  6476. var newColIndex = cap(startCol + deltaCol, 0, colsInRow - 1);
  6477. return toCell(matrix, rowIndex, newColIndex);
  6478. };
  6479. var moveVertical = function (matrix, colIndex, startRow, deltaRow) {
  6480. var nextRowIndex = cap(startRow + deltaRow, 0, matrix.length - 1);
  6481. var colsInNextRow = matrix[nextRowIndex].length;
  6482. var nextColIndex = cap(colIndex, 0, colsInNextRow - 1);
  6483. return toCell(matrix, nextRowIndex, nextColIndex);
  6484. };
  6485. var cycleRight$1 = function (matrix, startRow, startCol) {
  6486. return cycleHorizontal$1(matrix, startRow, startCol, +1);
  6487. };
  6488. var cycleLeft$1 = function (matrix, startRow, startCol) {
  6489. return cycleHorizontal$1(matrix, startRow, startCol, -1);
  6490. };
  6491. var cycleUp$1 = function (matrix, startRow, startCol) {
  6492. return cycleVertical$1(matrix, startCol, startRow, -1);
  6493. };
  6494. var cycleDown$1 = function (matrix, startRow, startCol) {
  6495. return cycleVertical$1(matrix, startCol, startRow, +1);
  6496. };
  6497. var moveLeft$2 = function (matrix, startRow, startCol) {
  6498. return moveHorizontal(matrix, startRow, startCol, -1);
  6499. };
  6500. var moveRight$2 = function (matrix, startRow, startCol) {
  6501. return moveHorizontal(matrix, startRow, startCol, +1);
  6502. };
  6503. var moveUp = function (matrix, startRow, startCol) {
  6504. return moveVertical(matrix, startCol, startRow, -1);
  6505. };
  6506. var moveDown = function (matrix, startRow, startCol) {
  6507. return moveVertical(matrix, startCol, startRow, +1);
  6508. };
  6509. var schema$6 = [
  6510. strictObjOf('selectors', [
  6511. strict$1('row'),
  6512. strict$1('cell')
  6513. ]),
  6514. defaulted$1('cycles', true),
  6515. defaulted$1('previousSelector', Option.none),
  6516. defaulted$1('execute', defaultExecute)
  6517. ];
  6518. var focusIn$2 = function (component, matrixConfig) {
  6519. var focused = matrixConfig.previousSelector(component).orThunk(function () {
  6520. var selectors = matrixConfig.selectors;
  6521. return descendant$1(component.element(), selectors.cell);
  6522. });
  6523. focused.each(function (cell) {
  6524. matrixConfig.focusManager.set(component, cell);
  6525. });
  6526. };
  6527. var execute$4 = function (component, simulatedEvent, matrixConfig) {
  6528. return search$1(component.element()).bind(function (focused) {
  6529. return matrixConfig.execute(component, simulatedEvent, focused);
  6530. });
  6531. };
  6532. var toMatrix = function (rows, matrixConfig) {
  6533. return map(rows, function (row) {
  6534. return descendants(row, matrixConfig.selectors.cell);
  6535. });
  6536. };
  6537. var doMove$2 = function (ifCycle, ifMove) {
  6538. return function (element, focused, matrixConfig) {
  6539. var move = matrixConfig.cycles ? ifCycle : ifMove;
  6540. return closest$3(focused, matrixConfig.selectors.row).bind(function (inRow) {
  6541. var cellsInRow = descendants(inRow, matrixConfig.selectors.cell);
  6542. return findIndex$1(cellsInRow, focused).bind(function (colIndex) {
  6543. var allRows = descendants(element, matrixConfig.selectors.row);
  6544. return findIndex$1(allRows, inRow).bind(function (rowIndex) {
  6545. var matrix = toMatrix(allRows, matrixConfig);
  6546. return move(matrix, rowIndex, colIndex).map(function (next) {
  6547. return next.cell();
  6548. });
  6549. });
  6550. });
  6551. });
  6552. };
  6553. };
  6554. var moveLeft$3 = doMove$2(cycleLeft$1, moveLeft$2);
  6555. var moveRight$3 = doMove$2(cycleRight$1, moveRight$2);
  6556. var moveNorth$1 = doMove$2(cycleUp$1, moveUp);
  6557. var moveSouth$1 = doMove$2(cycleDown$1, moveDown);
  6558. var getKeydownRules$3 = constant([
  6559. rule(inSet(LEFT()), west$2(moveLeft$3, moveRight$3)),
  6560. rule(inSet(RIGHT()), east$2(moveLeft$3, moveRight$3)),
  6561. rule(inSet(UP()), north$2(moveNorth$1)),
  6562. rule(inSet(DOWN()), south$2(moveSouth$1)),
  6563. rule(inSet(SPACE().concat(ENTER())), execute$4)
  6564. ]);
  6565. var getKeyupRules$3 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
  6566. var MatrixType = typical(schema$6, NoState.init, getKeydownRules$3, getKeyupRules$3, function () {
  6567. return Option.some(focusIn$2);
  6568. });
  6569. var schema$7 = [
  6570. strict$1('selector'),
  6571. defaulted$1('execute', defaultExecute),
  6572. defaulted$1('moveOnTab', false)
  6573. ];
  6574. var execute$5 = function (component, simulatedEvent, menuConfig) {
  6575. return menuConfig.focusManager.get(component).bind(function (focused) {
  6576. return menuConfig.execute(component, simulatedEvent, focused);
  6577. });
  6578. };
  6579. var focusIn$3 = function (component, menuConfig) {
  6580. descendant$1(component.element(), menuConfig.selector).each(function (first) {
  6581. menuConfig.focusManager.set(component, first);
  6582. });
  6583. };
  6584. var moveUp$1 = function (element, focused, info) {
  6585. return horizontal(element, info.selector, focused, -1);
  6586. };
  6587. var moveDown$1 = function (element, focused, info) {
  6588. return horizontal(element, info.selector, focused, +1);
  6589. };
  6590. var fireShiftTab = function (component, simulatedEvent, menuConfig) {
  6591. return menuConfig.moveOnTab ? move(moveUp$1)(component, simulatedEvent, menuConfig) : Option.none();
  6592. };
  6593. var fireTab = function (component, simulatedEvent, menuConfig) {
  6594. return menuConfig.moveOnTab ? move(moveDown$1)(component, simulatedEvent, menuConfig) : Option.none();
  6595. };
  6596. var getKeydownRules$4 = constant([
  6597. rule(inSet(UP()), move(moveUp$1)),
  6598. rule(inSet(DOWN()), move(moveDown$1)),
  6599. rule(and([
  6600. isShift,
  6601. inSet(TAB())
  6602. ]), fireShiftTab),
  6603. rule(and([
  6604. isNotShift,
  6605. inSet(TAB())
  6606. ]), fireTab),
  6607. rule(inSet(ENTER()), execute$5),
  6608. rule(inSet(SPACE()), execute$5)
  6609. ]);
  6610. var getKeyupRules$4 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
  6611. var MenuType = typical(schema$7, NoState.init, getKeydownRules$4, getKeyupRules$4, function () {
  6612. return Option.some(focusIn$3);
  6613. });
  6614. var schema$8 = [
  6615. onKeyboardHandler('onSpace'),
  6616. onKeyboardHandler('onEnter'),
  6617. onKeyboardHandler('onShiftEnter'),
  6618. onKeyboardHandler('onLeft'),
  6619. onKeyboardHandler('onRight'),
  6620. onKeyboardHandler('onTab'),
  6621. onKeyboardHandler('onShiftTab'),
  6622. onKeyboardHandler('onUp'),
  6623. onKeyboardHandler('onDown'),
  6624. onKeyboardHandler('onEscape'),
  6625. defaulted$1('stopSpaceKeyup', false),
  6626. option('focusIn')
  6627. ];
  6628. var getKeydownRules$5 = function (component, simulatedEvent, specialInfo) {
  6629. return [
  6630. rule(inSet(SPACE()), specialInfo.onSpace),
  6631. rule(and([
  6632. isNotShift,
  6633. inSet(ENTER())
  6634. ]), specialInfo.onEnter),
  6635. rule(and([
  6636. isShift,
  6637. inSet(ENTER())
  6638. ]), specialInfo.onShiftEnter),
  6639. rule(and([
  6640. isShift,
  6641. inSet(TAB())
  6642. ]), specialInfo.onShiftTab),
  6643. rule(and([
  6644. isNotShift,
  6645. inSet(TAB())
  6646. ]), specialInfo.onTab),
  6647. rule(inSet(UP()), specialInfo.onUp),
  6648. rule(inSet(DOWN()), specialInfo.onDown),
  6649. rule(inSet(LEFT()), specialInfo.onLeft),
  6650. rule(inSet(RIGHT()), specialInfo.onRight),
  6651. rule(inSet(SPACE()), specialInfo.onSpace),
  6652. rule(inSet(ESCAPE()), specialInfo.onEscape)
  6653. ];
  6654. };
  6655. var getKeyupRules$5 = function (component, simulatedEvent, specialInfo) {
  6656. return specialInfo.stopSpaceKeyup ? [rule(inSet(SPACE()), stopEventForFirefox)] : [];
  6657. };
  6658. var SpecialType = typical(schema$8, NoState.init, getKeydownRules$5, getKeyupRules$5, function (specialInfo) {
  6659. return specialInfo.focusIn;
  6660. });
  6661. var acyclic = AcyclicType.schema();
  6662. var cyclic = CyclicType.schema();
  6663. var flow = FlowType.schema();
  6664. var flatgrid$1 = FlatgridType.schema();
  6665. var matrix = MatrixType.schema();
  6666. var execution = ExecutionType.schema();
  6667. var menu = MenuType.schema();
  6668. var special = SpecialType.schema();
  6669. var KeyboardBranches = /*#__PURE__*/Object.freeze({
  6670. acyclic: acyclic,
  6671. cyclic: cyclic,
  6672. flow: flow,
  6673. flatgrid: flatgrid$1,
  6674. matrix: matrix,
  6675. execution: execution,
  6676. menu: menu,
  6677. special: special
  6678. });
  6679. var Keying = createModes$1({
  6680. branchKey: 'mode',
  6681. branches: KeyboardBranches,
  6682. name: 'keying',
  6683. active: {
  6684. events: function (keyingConfig, keyingState) {
  6685. var handler = keyingConfig.handler;
  6686. return handler.toEvents(keyingConfig, keyingState);
  6687. }
  6688. },
  6689. apis: {
  6690. focusIn: function (component, keyConfig, keyState) {
  6691. keyConfig.sendFocusIn(keyConfig).fold(function () {
  6692. component.getSystem().triggerFocus(component.element(), component.element());
  6693. }, function (sendFocusIn) {
  6694. sendFocusIn(component, keyConfig, keyState);
  6695. });
  6696. },
  6697. setGridSize: function (component, keyConfig, keyState, numRows, numColumns) {
  6698. if (!hasKey$1(keyState, 'setGridSize')) {
  6699. domGlobals.console.error('Layout does not support setGridSize');
  6700. } else {
  6701. keyState.setGridSize(numRows, numColumns);
  6702. }
  6703. }
  6704. },
  6705. state: KeyingState
  6706. });
  6707. var preserve = function (f, container) {
  6708. var ownerDoc = owner(container);
  6709. var refocus = active(ownerDoc).bind(function (focused) {
  6710. var hasFocus = function (elem) {
  6711. return eq(focused, elem);
  6712. };
  6713. return hasFocus(container) ? Option.some(container) : descendant(container, hasFocus);
  6714. });
  6715. var result = f(container);
  6716. refocus.each(function (oldFocus) {
  6717. active(ownerDoc).filter(function (newFocus) {
  6718. return eq(newFocus, oldFocus);
  6719. }).fold(function () {
  6720. focus$1(oldFocus);
  6721. }, noop);
  6722. });
  6723. return result;
  6724. };
  6725. var set$5 = function (component, replaceConfig, replaceState, data) {
  6726. detachChildren(component);
  6727. preserve(function () {
  6728. var children = map(data, component.getSystem().build);
  6729. each(children, function (l) {
  6730. attach(component, l);
  6731. });
  6732. }, component.element());
  6733. };
  6734. var insert = function (component, replaceConfig, insertion, childSpec) {
  6735. var child = component.getSystem().build(childSpec);
  6736. attachWith(component, child, insertion);
  6737. };
  6738. var append$2 = function (component, replaceConfig, replaceState, appendee) {
  6739. insert(component, replaceConfig, append, appendee);
  6740. };
  6741. var prepend$1 = function (component, replaceConfig, replaceState, prependee) {
  6742. insert(component, replaceConfig, prepend, prependee);
  6743. };
  6744. var remove$7 = function (component, replaceConfig, replaceState, removee) {
  6745. var children = contents(component, replaceConfig);
  6746. var foundChild = find(children, function (child) {
  6747. return eq(removee.element(), child.element());
  6748. });
  6749. foundChild.each(detach);
  6750. };
  6751. var contents = function (component, replaceConfig) {
  6752. return component.components();
  6753. };
  6754. var replaceAt = function (component, replaceConfig, replaceState, replaceeIndex, replacer) {
  6755. var children = contents(component, replaceConfig);
  6756. return Option.from(children[replaceeIndex]).map(function (replacee) {
  6757. remove$7(component, replaceConfig, replaceState, replacee);
  6758. replacer.each(function (r) {
  6759. insert(component, replaceConfig, function (p, c) {
  6760. appendAt(p, c, replaceeIndex);
  6761. }, r);
  6762. });
  6763. return replacee;
  6764. });
  6765. };
  6766. var replaceBy = function (component, replaceConfig, replaceState, replaceePred, replacer) {
  6767. var children = contents(component, replaceConfig);
  6768. return findIndex(children, replaceePred).bind(function (replaceeIndex) {
  6769. return replaceAt(component, replaceConfig, replaceState, replaceeIndex, replacer);
  6770. });
  6771. };
  6772. var ReplaceApis = /*#__PURE__*/Object.freeze({
  6773. append: append$2,
  6774. prepend: prepend$1,
  6775. remove: remove$7,
  6776. replaceAt: replaceAt,
  6777. replaceBy: replaceBy,
  6778. set: set$5,
  6779. contents: contents
  6780. });
  6781. var Replacing = create$1({
  6782. fields: [],
  6783. name: 'replacing',
  6784. apis: ReplaceApis
  6785. });
  6786. var onLoad = function (component, repConfig, repState) {
  6787. repConfig.store.manager.onLoad(component, repConfig, repState);
  6788. };
  6789. var onUnload = function (component, repConfig, repState) {
  6790. repConfig.store.manager.onUnload(component, repConfig, repState);
  6791. };
  6792. var setValue = function (component, repConfig, repState, data) {
  6793. repConfig.store.manager.setValue(component, repConfig, repState, data);
  6794. };
  6795. var getValue = function (component, repConfig, repState) {
  6796. return repConfig.store.manager.getValue(component, repConfig, repState);
  6797. };
  6798. var getState$1 = function (component, repConfig, repState) {
  6799. return repState;
  6800. };
  6801. var RepresentApis = /*#__PURE__*/Object.freeze({
  6802. onLoad: onLoad,
  6803. onUnload: onUnload,
  6804. setValue: setValue,
  6805. getValue: getValue,
  6806. getState: getState$1
  6807. });
  6808. var events$3 = function (repConfig, repState) {
  6809. var es = repConfig.resetOnDom ? [
  6810. runOnAttached(function (comp, se) {
  6811. onLoad(comp, repConfig, repState);
  6812. }),
  6813. runOnDetached(function (comp, se) {
  6814. onUnload(comp, repConfig, repState);
  6815. })
  6816. ] : [loadEvent(repConfig, repState, onLoad)];
  6817. return derive(es);
  6818. };
  6819. var ActiveRepresenting = /*#__PURE__*/Object.freeze({
  6820. events: events$3
  6821. });
  6822. var memory = function () {
  6823. var data = Cell(null);
  6824. var readState = function () {
  6825. return {
  6826. mode: 'memory',
  6827. value: data.get()
  6828. };
  6829. };
  6830. var isNotSet = function () {
  6831. return data.get() === null;
  6832. };
  6833. var clear = function () {
  6834. data.set(null);
  6835. };
  6836. return nu$5({
  6837. set: data.set,
  6838. get: data.get,
  6839. isNotSet: isNotSet,
  6840. clear: clear,
  6841. readState: readState
  6842. });
  6843. };
  6844. var manual = function () {
  6845. var readState = function () {
  6846. };
  6847. return nu$5({ readState: readState });
  6848. };
  6849. var dataset = function () {
  6850. var dataByValue = Cell({});
  6851. var dataByText = Cell({});
  6852. var readState = function () {
  6853. return {
  6854. mode: 'dataset',
  6855. dataByValue: dataByValue.get(),
  6856. dataByText: dataByText.get()
  6857. };
  6858. };
  6859. var clear = function () {
  6860. dataByValue.set({});
  6861. dataByText.set({});
  6862. };
  6863. var lookup = function (itemString) {
  6864. return readOptFrom$1(dataByValue.get(), itemString).orThunk(function () {
  6865. return readOptFrom$1(dataByText.get(), itemString);
  6866. });
  6867. };
  6868. var update = function (items) {
  6869. var currentDataByValue = dataByValue.get();
  6870. var currentDataByText = dataByText.get();
  6871. var newDataByValue = {};
  6872. var newDataByText = {};
  6873. each(items, function (item) {
  6874. newDataByValue[item.value] = item;
  6875. readOptFrom$1(item, 'meta').each(function (meta) {
  6876. readOptFrom$1(meta, 'text').each(function (text) {
  6877. newDataByText[text] = item;
  6878. });
  6879. });
  6880. });
  6881. dataByValue.set(__assign({}, currentDataByValue, newDataByValue));
  6882. dataByText.set(__assign({}, currentDataByText, newDataByText));
  6883. };
  6884. return nu$5({
  6885. readState: readState,
  6886. lookup: lookup,
  6887. update: update,
  6888. clear: clear
  6889. });
  6890. };
  6891. var init$2 = function (spec) {
  6892. return spec.store.manager.state(spec);
  6893. };
  6894. var RepresentState = /*#__PURE__*/Object.freeze({
  6895. memory: memory,
  6896. dataset: dataset,
  6897. manual: manual,
  6898. init: init$2
  6899. });
  6900. var setValue$1 = function (component, repConfig, repState, data) {
  6901. var store = repConfig.store;
  6902. repState.update([data]);
  6903. store.setValue(component, data);
  6904. repConfig.onSetValue(component, data);
  6905. };
  6906. var getValue$1 = function (component, repConfig, repState) {
  6907. var store = repConfig.store;
  6908. var key = store.getDataKey(component);
  6909. return repState.lookup(key).fold(function () {
  6910. return store.getFallbackEntry(key);
  6911. }, function (data) {
  6912. return data;
  6913. });
  6914. };
  6915. var onLoad$1 = function (component, repConfig, repState) {
  6916. var store = repConfig.store;
  6917. store.initialValue.each(function (data) {
  6918. setValue$1(component, repConfig, repState, data);
  6919. });
  6920. };
  6921. var onUnload$1 = function (component, repConfig, repState) {
  6922. repState.clear();
  6923. };
  6924. var DatasetStore = [
  6925. option('initialValue'),
  6926. strict$1('getFallbackEntry'),
  6927. strict$1('getDataKey'),
  6928. strict$1('setValue'),
  6929. output('manager', {
  6930. setValue: setValue$1,
  6931. getValue: getValue$1,
  6932. onLoad: onLoad$1,
  6933. onUnload: onUnload$1,
  6934. state: dataset
  6935. })
  6936. ];
  6937. var getValue$2 = function (component, repConfig, repState) {
  6938. return repConfig.store.getValue(component);
  6939. };
  6940. var setValue$2 = function (component, repConfig, repState, data) {
  6941. repConfig.store.setValue(component, data);
  6942. repConfig.onSetValue(component, data);
  6943. };
  6944. var onLoad$2 = function (component, repConfig, repState) {
  6945. repConfig.store.initialValue.each(function (data) {
  6946. repConfig.store.setValue(component, data);
  6947. });
  6948. };
  6949. var ManualStore = [
  6950. strict$1('getValue'),
  6951. defaulted$1('setValue', noop),
  6952. option('initialValue'),
  6953. output('manager', {
  6954. setValue: setValue$2,
  6955. getValue: getValue$2,
  6956. onLoad: onLoad$2,
  6957. onUnload: noop,
  6958. state: NoState.init
  6959. })
  6960. ];
  6961. var setValue$3 = function (component, repConfig, repState, data) {
  6962. repState.set(data);
  6963. repConfig.onSetValue(component, data);
  6964. };
  6965. var getValue$3 = function (component, repConfig, repState) {
  6966. return repState.get();
  6967. };
  6968. var onLoad$3 = function (component, repConfig, repState) {
  6969. repConfig.store.initialValue.each(function (initVal) {
  6970. if (repState.isNotSet()) {
  6971. repState.set(initVal);
  6972. }
  6973. });
  6974. };
  6975. var onUnload$2 = function (component, repConfig, repState) {
  6976. repState.clear();
  6977. };
  6978. var MemoryStore = [
  6979. option('initialValue'),
  6980. output('manager', {
  6981. setValue: setValue$3,
  6982. getValue: getValue$3,
  6983. onLoad: onLoad$3,
  6984. onUnload: onUnload$2,
  6985. state: memory
  6986. })
  6987. ];
  6988. var RepresentSchema = [
  6989. defaultedOf('store', { mode: 'memory' }, choose$1('mode', {
  6990. memory: MemoryStore,
  6991. manual: ManualStore,
  6992. dataset: DatasetStore
  6993. })),
  6994. onHandler('onSetValue'),
  6995. defaulted$1('resetOnDom', false)
  6996. ];
  6997. var Representing = create$1({
  6998. fields: RepresentSchema,
  6999. name: 'representing',
  7000. active: ActiveRepresenting,
  7001. apis: RepresentApis,
  7002. extra: {
  7003. setValueFrom: function (component, source) {
  7004. var value = Representing.getValue(source);
  7005. Representing.setValue(component, value);
  7006. }
  7007. },
  7008. state: RepresentState
  7009. });
  7010. var focus$2 = function (component, focusConfig) {
  7011. if (!focusConfig.ignore) {
  7012. focus$1(component.element());
  7013. focusConfig.onFocus(component);
  7014. }
  7015. };
  7016. var blur$1 = function (component, focusConfig) {
  7017. if (!focusConfig.ignore) {
  7018. blur(component.element());
  7019. }
  7020. };
  7021. var isFocused = function (component) {
  7022. return hasFocus(component.element());
  7023. };
  7024. var FocusApis = /*#__PURE__*/Object.freeze({
  7025. focus: focus$2,
  7026. blur: blur$1,
  7027. isFocused: isFocused
  7028. });
  7029. var exhibit$1 = function (base, focusConfig) {
  7030. var mod = focusConfig.ignore ? {} : { attributes: { tabindex: '-1' } };
  7031. return nu$6(mod);
  7032. };
  7033. var events$4 = function (focusConfig) {
  7034. return derive([run(focus(), function (component, simulatedEvent) {
  7035. focus$2(component, focusConfig);
  7036. simulatedEvent.stop();
  7037. })].concat(focusConfig.stopMousedown ? [run(mousedown(), function (_, simulatedEvent) {
  7038. simulatedEvent.event().prevent();
  7039. })] : []));
  7040. };
  7041. var ActiveFocus = /*#__PURE__*/Object.freeze({
  7042. exhibit: exhibit$1,
  7043. events: events$4
  7044. });
  7045. var FocusSchema = [
  7046. onHandler('onFocus'),
  7047. defaulted$1('stopMousedown', false),
  7048. defaulted$1('ignore', false)
  7049. ];
  7050. var Focusing = create$1({
  7051. fields: FocusSchema,
  7052. name: 'focusing',
  7053. active: ActiveFocus,
  7054. apis: FocusApis
  7055. });
  7056. var updateAriaState = function (component, toggleConfig, toggleState) {
  7057. var ariaInfo = toggleConfig.aria;
  7058. ariaInfo.update(component, ariaInfo, toggleState.get());
  7059. };
  7060. var updateClass = function (component, toggleConfig, toggleState) {
  7061. toggleConfig.toggleClass.each(function (toggleClass) {
  7062. if (toggleState.get()) {
  7063. add$2(component.element(), toggleClass);
  7064. } else {
  7065. remove$4(component.element(), toggleClass);
  7066. }
  7067. });
  7068. };
  7069. var toggle = function (component, toggleConfig, toggleState) {
  7070. set$6(component, toggleConfig, toggleState, !toggleState.get());
  7071. };
  7072. var on = function (component, toggleConfig, toggleState) {
  7073. toggleState.set(true);
  7074. updateClass(component, toggleConfig, toggleState);
  7075. updateAriaState(component, toggleConfig, toggleState);
  7076. };
  7077. var off = function (component, toggleConfig, toggleState) {
  7078. toggleState.set(false);
  7079. updateClass(component, toggleConfig, toggleState);
  7080. updateAriaState(component, toggleConfig, toggleState);
  7081. };
  7082. var set$6 = function (component, toggleConfig, toggleState, state) {
  7083. var action = state ? on : off;
  7084. action(component, toggleConfig, toggleState);
  7085. };
  7086. var isOn = function (component, toggleConfig, toggleState) {
  7087. return toggleState.get();
  7088. };
  7089. var onLoad$4 = function (component, toggleConfig, toggleState) {
  7090. set$6(component, toggleConfig, toggleState, toggleConfig.selected);
  7091. };
  7092. var ToggleApis = /*#__PURE__*/Object.freeze({
  7093. onLoad: onLoad$4,
  7094. toggle: toggle,
  7095. isOn: isOn,
  7096. on: on,
  7097. off: off,
  7098. set: set$6
  7099. });
  7100. var exhibit$2 = function (base, toggleConfig, toggleState) {
  7101. return nu$6({});
  7102. };
  7103. var events$5 = function (toggleConfig, toggleState) {
  7104. var execute = executeEvent(toggleConfig, toggleState, toggle);
  7105. var load = loadEvent(toggleConfig, toggleState, onLoad$4);
  7106. return derive(flatten([
  7107. toggleConfig.toggleOnExecute ? [execute] : [],
  7108. [load]
  7109. ]));
  7110. };
  7111. var ActiveToggle = /*#__PURE__*/Object.freeze({
  7112. exhibit: exhibit$2,
  7113. events: events$5
  7114. });
  7115. var init$3 = function (spec) {
  7116. var cell = Cell(false);
  7117. var set = function (state) {
  7118. return cell.set(state);
  7119. };
  7120. var clear = function () {
  7121. return cell.set(false);
  7122. };
  7123. var get = function () {
  7124. return cell.get();
  7125. };
  7126. var readState = function () {
  7127. return cell.get();
  7128. };
  7129. return {
  7130. readState: readState,
  7131. get: get,
  7132. set: set,
  7133. clear: clear
  7134. };
  7135. };
  7136. var TogglingState = /*#__PURE__*/Object.freeze({
  7137. init: init$3
  7138. });
  7139. var updatePressed = function (component, ariaInfo, status) {
  7140. set$1(component.element(), 'aria-pressed', status);
  7141. if (ariaInfo.syncWithExpanded) {
  7142. updateExpanded(component, ariaInfo, status);
  7143. }
  7144. };
  7145. var updateSelected = function (component, ariaInfo, status) {
  7146. set$1(component.element(), 'aria-selected', status);
  7147. };
  7148. var updateChecked = function (component, ariaInfo, status) {
  7149. set$1(component.element(), 'aria-checked', status);
  7150. };
  7151. var updateExpanded = function (component, ariaInfo, status) {
  7152. set$1(component.element(), 'aria-expanded', status);
  7153. };
  7154. var ToggleSchema = [
  7155. defaulted$1('selected', false),
  7156. option('toggleClass'),
  7157. defaulted$1('toggleOnExecute', true),
  7158. defaultedOf('aria', { mode: 'none' }, choose$1('mode', {
  7159. pressed: [
  7160. defaulted$1('syncWithExpanded', false),
  7161. output('update', updatePressed)
  7162. ],
  7163. checked: [output('update', updateChecked)],
  7164. expanded: [output('update', updateExpanded)],
  7165. selected: [output('update', updateSelected)],
  7166. none: [output('update', noop)]
  7167. }))
  7168. ];
  7169. var Toggling = create$1({
  7170. fields: ToggleSchema,
  7171. name: 'toggling',
  7172. active: ActiveToggle,
  7173. apis: ToggleApis,
  7174. state: TogglingState
  7175. });
  7176. var hoverEvent = 'alloy.item-hover';
  7177. var focusEvent = 'alloy.item-focus';
  7178. var onHover = function (item) {
  7179. if (search$1(item.element()).isNone() || Focusing.isFocused(item)) {
  7180. if (!Focusing.isFocused(item)) {
  7181. Focusing.focus(item);
  7182. }
  7183. emitWith(item, hoverEvent, { item: item });
  7184. }
  7185. };
  7186. var onFocus = function (item) {
  7187. emitWith(item, focusEvent, { item: item });
  7188. };
  7189. var hover = constant(hoverEvent);
  7190. var focus$3 = constant(focusEvent);
  7191. var events$6 = function (name, eventHandlers) {
  7192. var events = derive(eventHandlers);
  7193. return create$1({
  7194. fields: [strict$1('enabled')],
  7195. name: name,
  7196. active: { events: constant(events) }
  7197. });
  7198. };
  7199. var config = function (name, eventHandlers) {
  7200. var me = events$6(name, eventHandlers);
  7201. return {
  7202. key: name,
  7203. value: {
  7204. config: {},
  7205. me: me,
  7206. configAsRaw: constant({}),
  7207. initialConfig: {},
  7208. state: NoState
  7209. }
  7210. };
  7211. };
  7212. var builder = function (detail) {
  7213. return {
  7214. dom: detail.dom,
  7215. domModification: __assign({}, detail.domModification, { attributes: __assign({ 'role': detail.toggling.isSome() ? 'menuitemcheckbox' : 'menuitem' }, detail.domModification.attributes, { 'aria-haspopup': detail.hasSubmenu }, detail.hasSubmenu ? { 'aria-expanded': false } : {}) }),
  7216. behaviours: SketchBehaviours.augment(detail.itemBehaviours, [
  7217. detail.toggling.fold(Toggling.revoke, function (tConfig) {
  7218. return Toggling.config(__assign({ aria: { mode: 'checked' } }, tConfig));
  7219. }),
  7220. Focusing.config({
  7221. ignore: detail.ignoreFocus,
  7222. stopMousedown: detail.ignoreFocus,
  7223. onFocus: function (component) {
  7224. onFocus(component);
  7225. }
  7226. }),
  7227. Keying.config({ mode: 'execution' }),
  7228. Representing.config({
  7229. store: {
  7230. mode: 'memory',
  7231. initialValue: detail.data
  7232. }
  7233. }),
  7234. config('item-type-events', [
  7235. run(tapOrClick(), emitExecute),
  7236. cutter(mousedown()),
  7237. run(mouseover(), onHover),
  7238. run(focusItem(), Focusing.focus)
  7239. ])
  7240. ]),
  7241. components: detail.components,
  7242. eventOrder: detail.eventOrder
  7243. };
  7244. };
  7245. var schema$9 = [
  7246. strict$1('data'),
  7247. strict$1('components'),
  7248. strict$1('dom'),
  7249. defaulted$1('hasSubmenu', false),
  7250. option('toggling'),
  7251. SketchBehaviours.field('itemBehaviours', [
  7252. Toggling,
  7253. Focusing,
  7254. Keying,
  7255. Representing
  7256. ]),
  7257. defaulted$1('ignoreFocus', false),
  7258. defaulted$1('domModification', {}),
  7259. output('builder', builder),
  7260. defaulted$1('eventOrder', {})
  7261. ];
  7262. var builder$1 = function (detail) {
  7263. return {
  7264. dom: detail.dom,
  7265. components: detail.components,
  7266. events: derive([stopper(focusItem())])
  7267. };
  7268. };
  7269. var schema$a = [
  7270. strict$1('dom'),
  7271. strict$1('components'),
  7272. output('builder', builder$1)
  7273. ];
  7274. var owner$2 = function () {
  7275. return 'item-widget';
  7276. };
  7277. var parts = constant([required({
  7278. name: 'widget',
  7279. overrides: function (detail) {
  7280. return {
  7281. behaviours: derive$1([Representing.config({
  7282. store: {
  7283. mode: 'manual',
  7284. getValue: function (component) {
  7285. return detail.data;
  7286. },
  7287. setValue: function () {
  7288. }
  7289. }
  7290. })])
  7291. };
  7292. }
  7293. })]);
  7294. var builder$2 = function (detail) {
  7295. var subs = substitutes(owner$2(), detail, parts());
  7296. var components$1 = components(owner$2(), detail, subs.internals());
  7297. var focusWidget = function (component) {
  7298. return getPart(component, detail, 'widget').map(function (widget) {
  7299. Keying.focusIn(widget);
  7300. return widget;
  7301. });
  7302. };
  7303. var onHorizontalArrow = function (component, simulatedEvent) {
  7304. return inside(simulatedEvent.event().target()) ? Option.none() : function () {
  7305. if (detail.autofocus) {
  7306. simulatedEvent.setSource(component.element());
  7307. return Option.none();
  7308. } else {
  7309. return Option.none();
  7310. }
  7311. }();
  7312. };
  7313. return {
  7314. dom: detail.dom,
  7315. components: components$1,
  7316. domModification: detail.domModification,
  7317. events: derive([
  7318. runOnExecute(function (component, simulatedEvent) {
  7319. focusWidget(component).each(function (widget) {
  7320. simulatedEvent.stop();
  7321. });
  7322. }),
  7323. run(mouseover(), onHover),
  7324. run(focusItem(), function (component, simulatedEvent) {
  7325. if (detail.autofocus) {
  7326. focusWidget(component);
  7327. } else {
  7328. Focusing.focus(component);
  7329. }
  7330. })
  7331. ]),
  7332. behaviours: SketchBehaviours.augment(detail.widgetBehaviours, [
  7333. Representing.config({
  7334. store: {
  7335. mode: 'memory',
  7336. initialValue: detail.data
  7337. }
  7338. }),
  7339. Focusing.config({
  7340. ignore: detail.ignoreFocus,
  7341. onFocus: function (component) {
  7342. onFocus(component);
  7343. }
  7344. }),
  7345. Keying.config({
  7346. mode: 'special',
  7347. focusIn: detail.autofocus ? function (component) {
  7348. focusWidget(component);
  7349. } : revoke(),
  7350. onLeft: onHorizontalArrow,
  7351. onRight: onHorizontalArrow,
  7352. onEscape: function (component, simulatedEvent) {
  7353. if (!Focusing.isFocused(component) && !detail.autofocus) {
  7354. Focusing.focus(component);
  7355. return Option.some(true);
  7356. } else if (detail.autofocus) {
  7357. simulatedEvent.setSource(component.element());
  7358. return Option.none();
  7359. } else {
  7360. return Option.none();
  7361. }
  7362. }
  7363. })
  7364. ])
  7365. };
  7366. };
  7367. var schema$b = [
  7368. strict$1('uid'),
  7369. strict$1('data'),
  7370. strict$1('components'),
  7371. strict$1('dom'),
  7372. defaulted$1('autofocus', false),
  7373. defaulted$1('ignoreFocus', false),
  7374. SketchBehaviours.field('widgetBehaviours', [
  7375. Representing,
  7376. Focusing,
  7377. Keying
  7378. ]),
  7379. defaulted$1('domModification', {}),
  7380. defaultUidsSchema(parts()),
  7381. output('builder', builder$2)
  7382. ];
  7383. var itemSchema$1 = choose$1('type', {
  7384. widget: schema$b,
  7385. item: schema$9,
  7386. separator: schema$a
  7387. });
  7388. var configureGrid = function (detail, movementInfo) {
  7389. return {
  7390. mode: 'flatgrid',
  7391. selector: '.' + detail.markers.item,
  7392. initSize: {
  7393. numColumns: movementInfo.initSize.numColumns,
  7394. numRows: movementInfo.initSize.numRows
  7395. },
  7396. focusManager: detail.focusManager
  7397. };
  7398. };
  7399. var configureMatrix = function (detail, movementInfo) {
  7400. return {
  7401. mode: 'matrix',
  7402. selectors: {
  7403. row: movementInfo.rowSelector,
  7404. cell: '.' + detail.markers.item
  7405. },
  7406. focusManager: detail.focusManager
  7407. };
  7408. };
  7409. var configureMenu = function (detail, movementInfo) {
  7410. return {
  7411. mode: 'menu',
  7412. selector: '.' + detail.markers.item,
  7413. moveOnTab: movementInfo.moveOnTab,
  7414. focusManager: detail.focusManager
  7415. };
  7416. };
  7417. var parts$1 = constant([group({
  7418. factory: {
  7419. sketch: function (spec) {
  7420. var itemInfo = asRawOrDie('menu.spec item', itemSchema$1, spec);
  7421. return itemInfo.builder(itemInfo);
  7422. }
  7423. },
  7424. name: 'items',
  7425. unit: 'item',
  7426. defaults: function (detail, u) {
  7427. return u.hasOwnProperty('uid') ? u : __assign({}, u, { uid: generate$2('item') });
  7428. },
  7429. overrides: function (detail, u) {
  7430. return {
  7431. type: u.type,
  7432. ignoreFocus: detail.fakeFocus,
  7433. domModification: { classes: [detail.markers.item] }
  7434. };
  7435. }
  7436. })]);
  7437. var schema$c = constant([
  7438. strict$1('value'),
  7439. strict$1('items'),
  7440. strict$1('dom'),
  7441. strict$1('components'),
  7442. defaulted$1('eventOrder', {}),
  7443. field$1('menuBehaviours', [
  7444. Highlighting,
  7445. Representing,
  7446. Composing,
  7447. Keying
  7448. ]),
  7449. defaultedOf('movement', {
  7450. mode: 'menu',
  7451. moveOnTab: true
  7452. }, choose$1('mode', {
  7453. grid: [
  7454. initSize(),
  7455. output('config', configureGrid)
  7456. ],
  7457. matrix: [
  7458. output('config', configureMatrix),
  7459. strict$1('rowSelector')
  7460. ],
  7461. menu: [
  7462. defaulted$1('moveOnTab', true),
  7463. output('config', configureMenu)
  7464. ]
  7465. })),
  7466. itemMarkers(),
  7467. defaulted$1('fakeFocus', false),
  7468. defaulted$1('focusManager', dom()),
  7469. onHandler('onHighlight')
  7470. ]);
  7471. var focus$4 = constant('alloy.menu-focus');
  7472. var make$1 = function (detail, components, spec, externals) {
  7473. return {
  7474. uid: detail.uid,
  7475. dom: detail.dom,
  7476. markers: detail.markers,
  7477. behaviours: augment(detail.menuBehaviours, [
  7478. Highlighting.config({
  7479. highlightClass: detail.markers.selectedItem,
  7480. itemClass: detail.markers.item,
  7481. onHighlight: detail.onHighlight
  7482. }),
  7483. Representing.config({
  7484. store: {
  7485. mode: 'memory',
  7486. initialValue: detail.value
  7487. }
  7488. }),
  7489. Composing.config({ find: Option.some }),
  7490. Keying.config(detail.movement.config(detail, detail.movement))
  7491. ]),
  7492. events: derive([
  7493. run(focus$3(), function (menu, simulatedEvent) {
  7494. var event = simulatedEvent.event();
  7495. menu.getSystem().getByDom(event.target()).each(function (item) {
  7496. Highlighting.highlight(menu, item);
  7497. simulatedEvent.stop();
  7498. emitWith(menu, focus$4(), {
  7499. menu: menu,
  7500. item: item
  7501. });
  7502. });
  7503. }),
  7504. run(hover(), function (menu, simulatedEvent) {
  7505. var item = simulatedEvent.event().item();
  7506. Highlighting.highlight(menu, item);
  7507. })
  7508. ]),
  7509. components: components,
  7510. eventOrder: detail.eventOrder,
  7511. domModification: { attributes: { role: 'menu' } }
  7512. };
  7513. };
  7514. var Menu = composite$1({
  7515. name: 'Menu',
  7516. configFields: schema$c(),
  7517. partFields: parts$1(),
  7518. factory: make$1
  7519. });
  7520. var transpose = function (obj) {
  7521. return tupleMap(obj, function (v, k) {
  7522. return {
  7523. k: v,
  7524. v: k
  7525. };
  7526. });
  7527. };
  7528. var trace = function (items, byItem, byMenu, finish) {
  7529. return readOptFrom$1(byMenu, finish).bind(function (triggerItem) {
  7530. return readOptFrom$1(items, triggerItem).bind(function (triggerMenu) {
  7531. var rest = trace(items, byItem, byMenu, triggerMenu);
  7532. return Option.some([triggerMenu].concat(rest));
  7533. });
  7534. }).getOr([]);
  7535. };
  7536. var generate$5 = function (menus, expansions) {
  7537. var items = {};
  7538. each$1(menus, function (menuItems, menu) {
  7539. each(menuItems, function (item) {
  7540. items[item] = menu;
  7541. });
  7542. });
  7543. var byItem = expansions;
  7544. var byMenu = transpose(expansions);
  7545. var menuPaths = map$1(byMenu, function (_triggerItem, submenu) {
  7546. return [submenu].concat(trace(items, byItem, byMenu, submenu));
  7547. });
  7548. return map$1(items, function (menu) {
  7549. return readOptFrom$1(menuPaths, menu).getOr([menu]);
  7550. });
  7551. };
  7552. var init$4 = function () {
  7553. var expansions = Cell({});
  7554. var menus = Cell({});
  7555. var paths = Cell({});
  7556. var primary = Cell(Option.none());
  7557. var directory = Cell({});
  7558. var clear = function () {
  7559. expansions.set({});
  7560. menus.set({});
  7561. paths.set({});
  7562. primary.set(Option.none());
  7563. };
  7564. var isClear = function () {
  7565. return primary.get().isNone();
  7566. };
  7567. var setMenuBuilt = function (menuName, built) {
  7568. var _a;
  7569. menus.set(__assign({}, menus.get(), (_a = {}, _a[menuName] = {
  7570. type: 'prepared',
  7571. menu: built
  7572. }, _a)));
  7573. };
  7574. var setContents = function (sPrimary, sMenus, sExpansions, dir) {
  7575. primary.set(Option.some(sPrimary));
  7576. expansions.set(sExpansions);
  7577. menus.set(sMenus);
  7578. directory.set(dir);
  7579. var sPaths = generate$5(dir, sExpansions);
  7580. paths.set(sPaths);
  7581. };
  7582. var expand = function (itemValue) {
  7583. return readOptFrom$1(expansions.get(), itemValue).map(function (menu) {
  7584. var current = readOptFrom$1(paths.get(), itemValue).getOr([]);
  7585. return [menu].concat(current);
  7586. });
  7587. };
  7588. var collapse = function (itemValue) {
  7589. return readOptFrom$1(paths.get(), itemValue).bind(function (path) {
  7590. return path.length > 1 ? Option.some(path.slice(1)) : Option.none();
  7591. });
  7592. };
  7593. var refresh = function (itemValue) {
  7594. return readOptFrom$1(paths.get(), itemValue);
  7595. };
  7596. var lookupMenu = function (menuValue) {
  7597. return readOptFrom$1(menus.get(), menuValue);
  7598. };
  7599. var otherMenus = function (path) {
  7600. var menuValues = directory.get();
  7601. return difference(keys(menuValues), path);
  7602. };
  7603. var getPrimary = function () {
  7604. return primary.get().bind(function (primaryName) {
  7605. return lookupMenu(primaryName).bind(function (prep) {
  7606. return prep.type === 'prepared' ? Option.some(prep.menu) : Option.none();
  7607. });
  7608. });
  7609. };
  7610. var getMenus = function () {
  7611. return menus.get();
  7612. };
  7613. return {
  7614. setMenuBuilt: setMenuBuilt,
  7615. setContents: setContents,
  7616. expand: expand,
  7617. refresh: refresh,
  7618. collapse: collapse,
  7619. lookupMenu: lookupMenu,
  7620. otherMenus: otherMenus,
  7621. getPrimary: getPrimary,
  7622. getMenus: getMenus,
  7623. clear: clear,
  7624. isClear: isClear
  7625. };
  7626. };
  7627. var LayeredState = { init: init$4 };
  7628. var make$2 = function (detail, rawUiSpec) {
  7629. var submenuParentItems = Cell(Option.none());
  7630. var buildMenus = function (container, primaryName, menus) {
  7631. return map$1(menus, function (spec, name) {
  7632. var makeSketch = function () {
  7633. return Menu.sketch(__assign({ dom: spec.dom }, spec, {
  7634. value: name,
  7635. items: spec.items,
  7636. markers: detail.markers,
  7637. fakeFocus: detail.fakeFocus,
  7638. onHighlight: detail.onHighlight,
  7639. focusManager: detail.fakeFocus ? highlights() : dom()
  7640. }));
  7641. };
  7642. return name === primaryName ? {
  7643. type: 'prepared',
  7644. menu: container.getSystem().build(makeSketch())
  7645. } : {
  7646. type: 'notbuilt',
  7647. nbMenu: makeSketch
  7648. };
  7649. });
  7650. };
  7651. var layeredState = LayeredState.init();
  7652. var setup = function (container) {
  7653. var componentMap = buildMenus(container, detail.data.primary, detail.data.menus);
  7654. var directory = toDirectory(container);
  7655. layeredState.setContents(detail.data.primary, componentMap, detail.data.expansions, directory);
  7656. return layeredState.getPrimary();
  7657. };
  7658. var getItemValue = function (item) {
  7659. return Representing.getValue(item).value;
  7660. };
  7661. var toDirectory = function (container) {
  7662. return map$1(detail.data.menus, function (data, menuName) {
  7663. return bind(data.items, function (item) {
  7664. return item.type === 'separator' ? [] : [item.data.value];
  7665. });
  7666. });
  7667. };
  7668. var setActiveMenu = function (container, menu) {
  7669. Highlighting.highlight(container, menu);
  7670. Highlighting.getHighlighted(menu).orThunk(function () {
  7671. return Highlighting.getFirst(menu);
  7672. }).each(function (item) {
  7673. dispatch(container, item.element(), focusItem());
  7674. });
  7675. };
  7676. var getMenus = function (state, menuValues) {
  7677. return cat(map(menuValues, function (mv) {
  7678. return state.lookupMenu(mv).bind(function (prep) {
  7679. return prep.type === 'prepared' ? Option.some(prep.menu) : Option.none();
  7680. });
  7681. }));
  7682. };
  7683. var closeOthers = function (container, state, path) {
  7684. var others = getMenus(state, state.otherMenus(path));
  7685. each(others, function (o) {
  7686. remove$5(o.element(), [detail.markers.backgroundMenu]);
  7687. if (!detail.stayInDom) {
  7688. Replacing.remove(container, o);
  7689. }
  7690. });
  7691. };
  7692. var getSubmenuParents = function (container) {
  7693. return submenuParentItems.get().getOrThunk(function () {
  7694. var r = {};
  7695. var items = descendants(container.element(), '.' + detail.markers.item);
  7696. var parentItems = filter(items, function (i) {
  7697. return get$2(i, 'aria-haspopup') === 'true';
  7698. });
  7699. each(parentItems, function (i) {
  7700. container.getSystem().getByDom(i).each(function (itemComp) {
  7701. var key = getItemValue(itemComp);
  7702. r[key] = itemComp;
  7703. });
  7704. });
  7705. submenuParentItems.set(Option.some(r));
  7706. return r;
  7707. });
  7708. };
  7709. var updateAriaExpansions = function (container, path) {
  7710. var parentItems = getSubmenuParents(container);
  7711. each$1(parentItems, function (v, k) {
  7712. var expanded = contains(path, k);
  7713. set$1(v.element(), 'aria-expanded', expanded);
  7714. });
  7715. };
  7716. var updateMenuPath = function (container, state, path) {
  7717. return Option.from(path[0]).bind(function (latestMenuName) {
  7718. return state.lookupMenu(latestMenuName).bind(function (menuPrep) {
  7719. if (menuPrep.type === 'notbuilt') {
  7720. return Option.none();
  7721. } else {
  7722. var activeMenu = menuPrep.menu;
  7723. var rest = getMenus(state, path.slice(1));
  7724. each(rest, function (r) {
  7725. add$2(r.element(), detail.markers.backgroundMenu);
  7726. });
  7727. if (!inBody(activeMenu.element())) {
  7728. Replacing.append(container, premade$1(activeMenu));
  7729. }
  7730. remove$5(activeMenu.element(), [detail.markers.backgroundMenu]);
  7731. setActiveMenu(container, activeMenu);
  7732. closeOthers(container, state, path);
  7733. return Option.some(activeMenu);
  7734. }
  7735. });
  7736. });
  7737. };
  7738. var ExpandHighlightDecision;
  7739. (function (ExpandHighlightDecision) {
  7740. ExpandHighlightDecision[ExpandHighlightDecision['HighlightSubmenu'] = 0] = 'HighlightSubmenu';
  7741. ExpandHighlightDecision[ExpandHighlightDecision['HighlightParent'] = 1] = 'HighlightParent';
  7742. }(ExpandHighlightDecision || (ExpandHighlightDecision = {})));
  7743. var buildIfRequired = function (container, menuName, menuPrep) {
  7744. if (menuPrep.type === 'notbuilt') {
  7745. var menu = container.getSystem().build(menuPrep.nbMenu());
  7746. layeredState.setMenuBuilt(menuName, menu);
  7747. return menu;
  7748. } else {
  7749. return menuPrep.menu;
  7750. }
  7751. };
  7752. var expandRight = function (container, item, decision) {
  7753. if (decision === void 0) {
  7754. decision = ExpandHighlightDecision.HighlightSubmenu;
  7755. }
  7756. var value = getItemValue(item);
  7757. return layeredState.expand(value).bind(function (path) {
  7758. updateAriaExpansions(container, path);
  7759. return Option.from(path[0]).bind(function (menuName) {
  7760. return layeredState.lookupMenu(menuName).bind(function (activeMenuPrep) {
  7761. var activeMenu = buildIfRequired(container, menuName, activeMenuPrep);
  7762. if (!inBody(activeMenu.element())) {
  7763. Replacing.append(container, premade$1(activeMenu));
  7764. }
  7765. detail.onOpenSubmenu(container, item, activeMenu);
  7766. if (decision === ExpandHighlightDecision.HighlightSubmenu) {
  7767. Highlighting.highlightFirst(activeMenu);
  7768. return updateMenuPath(container, layeredState, path);
  7769. } else {
  7770. Highlighting.dehighlightAll(activeMenu);
  7771. return Option.some(item);
  7772. }
  7773. });
  7774. });
  7775. });
  7776. };
  7777. var collapseLeft = function (container, item) {
  7778. var value = getItemValue(item);
  7779. return layeredState.collapse(value).bind(function (path) {
  7780. updateAriaExpansions(container, path);
  7781. return updateMenuPath(container, layeredState, path).map(function (activeMenu) {
  7782. detail.onCollapseMenu(container, item, activeMenu);
  7783. return activeMenu;
  7784. });
  7785. });
  7786. };
  7787. var updateView = function (container, item) {
  7788. var value = getItemValue(item);
  7789. return layeredState.refresh(value).bind(function (path) {
  7790. updateAriaExpansions(container, path);
  7791. return updateMenuPath(container, layeredState, path);
  7792. });
  7793. };
  7794. var onRight = function (container, item) {
  7795. return inside(item.element()) ? Option.none() : expandRight(container, item, ExpandHighlightDecision.HighlightSubmenu);
  7796. };
  7797. var onLeft = function (container, item) {
  7798. return inside(item.element()) ? Option.none() : collapseLeft(container, item);
  7799. };
  7800. var onEscape = function (container, item) {
  7801. return collapseLeft(container, item).orThunk(function () {
  7802. return detail.onEscape(container, item).map(function () {
  7803. return container;
  7804. });
  7805. });
  7806. };
  7807. var keyOnItem = function (f) {
  7808. return function (container, simulatedEvent) {
  7809. return closest$3(simulatedEvent.getSource(), '.' + detail.markers.item).bind(function (target) {
  7810. return container.getSystem().getByDom(target).toOption().bind(function (item) {
  7811. return f(container, item).map(function () {
  7812. return true;
  7813. });
  7814. });
  7815. });
  7816. };
  7817. };
  7818. var events = derive([
  7819. run(focus$4(), function (sandbox, simulatedEvent) {
  7820. var menu = simulatedEvent.event().menu();
  7821. Highlighting.highlight(sandbox, menu);
  7822. var value = getItemValue(simulatedEvent.event().item());
  7823. layeredState.refresh(value).each(function (path) {
  7824. return closeOthers(sandbox, layeredState, path);
  7825. });
  7826. }),
  7827. runOnExecute(function (component, simulatedEvent) {
  7828. var target = simulatedEvent.event().target();
  7829. component.getSystem().getByDom(target).each(function (item) {
  7830. var itemValue = getItemValue(item);
  7831. if (itemValue.indexOf('collapse-item') === 0) {
  7832. collapseLeft(component, item);
  7833. }
  7834. expandRight(component, item, ExpandHighlightDecision.HighlightSubmenu).fold(function () {
  7835. detail.onExecute(component, item);
  7836. }, function () {
  7837. });
  7838. });
  7839. }),
  7840. runOnAttached(function (container, simulatedEvent) {
  7841. setup(container).each(function (primary) {
  7842. Replacing.append(container, premade$1(primary));
  7843. detail.onOpenMenu(container, primary);
  7844. if (detail.highlightImmediately) {
  7845. setActiveMenu(container, primary);
  7846. }
  7847. });
  7848. })
  7849. ].concat(detail.navigateOnHover ? [run(hover(), function (sandbox, simulatedEvent) {
  7850. var item = simulatedEvent.event().item();
  7851. updateView(sandbox, item);
  7852. expandRight(sandbox, item, ExpandHighlightDecision.HighlightParent);
  7853. detail.onHover(sandbox, item);
  7854. })] : []));
  7855. var collapseMenuApi = function (container) {
  7856. Highlighting.getHighlighted(container).each(function (currentMenu) {
  7857. Highlighting.getHighlighted(currentMenu).each(function (currentItem) {
  7858. collapseLeft(container, currentItem);
  7859. });
  7860. });
  7861. };
  7862. var highlightPrimary = function (container) {
  7863. layeredState.getPrimary().each(function (primary) {
  7864. setActiveMenu(container, primary);
  7865. });
  7866. };
  7867. var apis = {
  7868. collapseMenu: collapseMenuApi,
  7869. highlightPrimary: highlightPrimary
  7870. };
  7871. return {
  7872. uid: detail.uid,
  7873. dom: detail.dom,
  7874. markers: detail.markers,
  7875. behaviours: augment(detail.tmenuBehaviours, [
  7876. Keying.config({
  7877. mode: 'special',
  7878. onRight: keyOnItem(onRight),
  7879. onLeft: keyOnItem(onLeft),
  7880. onEscape: keyOnItem(onEscape),
  7881. focusIn: function (container, keyInfo) {
  7882. layeredState.getPrimary().each(function (primary) {
  7883. dispatch(container, primary.element(), focusItem());
  7884. });
  7885. }
  7886. }),
  7887. Highlighting.config({
  7888. highlightClass: detail.markers.selectedMenu,
  7889. itemClass: detail.markers.menu
  7890. }),
  7891. Composing.config({
  7892. find: function (container) {
  7893. return Highlighting.getHighlighted(container);
  7894. }
  7895. }),
  7896. Replacing.config({})
  7897. ]),
  7898. eventOrder: detail.eventOrder,
  7899. apis: apis,
  7900. events: events
  7901. };
  7902. };
  7903. var collapseItem = constant('collapse-item');
  7904. var tieredData = function (primary, menus, expansions) {
  7905. return {
  7906. primary: primary,
  7907. menus: menus,
  7908. expansions: expansions
  7909. };
  7910. };
  7911. var singleData = function (name, menu) {
  7912. return {
  7913. primary: name,
  7914. menus: wrap$1(name, menu),
  7915. expansions: {}
  7916. };
  7917. };
  7918. var collapseItem$1 = function (text) {
  7919. return {
  7920. value: generate$1(collapseItem()),
  7921. meta: { text: text }
  7922. };
  7923. };
  7924. var tieredMenu = single$2({
  7925. name: 'TieredMenu',
  7926. configFields: [
  7927. onStrictKeyboardHandler('onExecute'),
  7928. onStrictKeyboardHandler('onEscape'),
  7929. onStrictHandler('onOpenMenu'),
  7930. onStrictHandler('onOpenSubmenu'),
  7931. onHandler('onCollapseMenu'),
  7932. defaulted$1('highlightImmediately', true),
  7933. strictObjOf('data', [
  7934. strict$1('primary'),
  7935. strict$1('menus'),
  7936. strict$1('expansions')
  7937. ]),
  7938. defaulted$1('fakeFocus', false),
  7939. onHandler('onHighlight'),
  7940. onHandler('onHover'),
  7941. tieredMenuMarkers(),
  7942. strict$1('dom'),
  7943. defaulted$1('navigateOnHover', true),
  7944. defaulted$1('stayInDom', false),
  7945. field$1('tmenuBehaviours', [
  7946. Keying,
  7947. Highlighting,
  7948. Composing,
  7949. Replacing
  7950. ]),
  7951. defaulted$1('eventOrder', {})
  7952. ],
  7953. apis: {
  7954. collapseMenu: function (apis, tmenu) {
  7955. apis.collapseMenu(tmenu);
  7956. },
  7957. highlightPrimary: function (apis, tmenu) {
  7958. apis.highlightPrimary(tmenu);
  7959. }
  7960. },
  7961. factory: make$2,
  7962. extraApis: {
  7963. tieredData: tieredData,
  7964. singleData: singleData,
  7965. collapseItem: collapseItem$1
  7966. }
  7967. });
  7968. var makeMenu = function (detail, menuSandbox, anchor, menuSpec) {
  7969. var lazySink = function () {
  7970. return detail.lazySink(menuSandbox);
  7971. };
  7972. return tieredMenu.sketch({
  7973. dom: { tag: 'div' },
  7974. data: menuSpec.data,
  7975. markers: menuSpec.menu.markers,
  7976. onEscape: function () {
  7977. Sandboxing.close(menuSandbox);
  7978. detail.onEscape.map(function (handler) {
  7979. return handler(menuSandbox);
  7980. });
  7981. return Option.some(true);
  7982. },
  7983. onExecute: function () {
  7984. return Option.some(true);
  7985. },
  7986. onOpenMenu: function (tmenu, menu) {
  7987. Positioning.position(lazySink().getOrDie(), anchor, menu);
  7988. },
  7989. onOpenSubmenu: function (tmenu, item, submenu) {
  7990. var sink = lazySink().getOrDie();
  7991. Positioning.position(sink, {
  7992. anchor: 'submenu',
  7993. item: item
  7994. }, submenu);
  7995. }
  7996. });
  7997. };
  7998. var factory = function (detail, spec) {
  7999. var isPartOfRelated = function (sandbox, queryElem) {
  8000. var related = detail.getRelated(sandbox);
  8001. return related.exists(function (rel) {
  8002. return isPartOf(rel, queryElem);
  8003. });
  8004. };
  8005. var setContent = function (sandbox, thing) {
  8006. Sandboxing.open(sandbox, thing);
  8007. };
  8008. var showAt = function (sandbox, anchor, thing) {
  8009. var getBounds = Option.none();
  8010. showWithin(sandbox, anchor, thing, getBounds);
  8011. };
  8012. var showWithin = function (sandbox, anchor, thing, boxElement) {
  8013. var sink = detail.lazySink(sandbox).getOrDie();
  8014. Sandboxing.openWhileCloaked(sandbox, thing, function () {
  8015. return Positioning.positionWithin(sink, anchor, sandbox, boxElement);
  8016. });
  8017. detail.onShow(sandbox);
  8018. };
  8019. var showMenuAt = function (sandbox, anchor, menuSpec) {
  8020. var menu = makeMenu(detail, sandbox, anchor, menuSpec);
  8021. Sandboxing.open(sandbox, menu);
  8022. detail.onShow(sandbox);
  8023. };
  8024. var hide = function (sandbox) {
  8025. Sandboxing.close(sandbox);
  8026. detail.onHide(sandbox);
  8027. };
  8028. var getContent = function (sandbox) {
  8029. return Sandboxing.getState(sandbox);
  8030. };
  8031. var apis = {
  8032. setContent: setContent,
  8033. showAt: showAt,
  8034. showWithin: showWithin,
  8035. showMenuAt: showMenuAt,
  8036. hide: hide,
  8037. getContent: getContent,
  8038. isOpen: Sandboxing.isOpen
  8039. };
  8040. return {
  8041. uid: detail.uid,
  8042. dom: detail.dom,
  8043. behaviours: augment(detail.inlineBehaviours, [
  8044. Sandboxing.config({
  8045. isPartOf: function (sandbox, data, queryElem) {
  8046. return isPartOf(data, queryElem) || isPartOfRelated(sandbox, queryElem);
  8047. },
  8048. getAttachPoint: function (sandbox) {
  8049. return detail.lazySink(sandbox).getOrDie();
  8050. }
  8051. }),
  8052. receivingConfig(__assign({ isExtraPart: constant(false) }, detail.fireDismissalEventInstead.map(function (fe) {
  8053. return { fireEventInstead: { event: fe.event } };
  8054. }).getOr({})))
  8055. ]),
  8056. eventOrder: detail.eventOrder,
  8057. apis: apis
  8058. };
  8059. };
  8060. var InlineView = single$2({
  8061. name: 'InlineView',
  8062. configFields: [
  8063. strict$1('lazySink'),
  8064. onHandler('onShow'),
  8065. onHandler('onHide'),
  8066. optionFunction('onEscape'),
  8067. field$1('inlineBehaviours', [
  8068. Sandboxing,
  8069. Receiving
  8070. ]),
  8071. optionObjOf('fireDismissalEventInstead', [defaulted$1('event', dismissRequested())]),
  8072. defaulted$1('getRelated', Option.none),
  8073. defaulted$1('eventOrder', Option.none)
  8074. ],
  8075. factory: factory,
  8076. apis: {
  8077. showAt: function (apis, component, anchor, thing) {
  8078. apis.showAt(component, anchor, thing);
  8079. },
  8080. showWithin: function (apis, component, anchor, thing, boxElement) {
  8081. apis.showWithin(component, anchor, thing, boxElement);
  8082. },
  8083. showMenuAt: function (apis, component, anchor, menuSpec) {
  8084. apis.showMenuAt(component, anchor, menuSpec);
  8085. },
  8086. hide: function (apis, component) {
  8087. apis.hide(component);
  8088. },
  8089. isOpen: function (apis, component) {
  8090. return apis.isOpen(component);
  8091. },
  8092. getContent: function (apis, component) {
  8093. return apis.getContent(component);
  8094. },
  8095. setContent: function (apis, component, thing) {
  8096. apis.setContent(component, thing);
  8097. }
  8098. }
  8099. });
  8100. var events$7 = function (optAction) {
  8101. var executeHandler = function (action) {
  8102. return run(execute(), function (component, simulatedEvent) {
  8103. action(component);
  8104. simulatedEvent.stop();
  8105. });
  8106. };
  8107. var onClick = function (component, simulatedEvent) {
  8108. simulatedEvent.stop();
  8109. emitExecute(component);
  8110. };
  8111. var onMousedown = function (component, simulatedEvent) {
  8112. simulatedEvent.cut();
  8113. };
  8114. var pointerEvents = PlatformDetection$1.detect().deviceType.isTouch() ? [run(tap(), onClick)] : [
  8115. run(click(), onClick),
  8116. run(mousedown(), onMousedown)
  8117. ];
  8118. return derive(flatten([
  8119. optAction.map(executeHandler).toArray(),
  8120. pointerEvents
  8121. ]));
  8122. };
  8123. var factory$1 = function (detail) {
  8124. var events = events$7(detail.action);
  8125. var tag = detail.dom.tag;
  8126. var lookupAttr = function (attr) {
  8127. return readOptFrom$1(detail.dom, 'attributes').bind(function (attrs) {
  8128. return readOptFrom$1(attrs, attr);
  8129. });
  8130. };
  8131. var getModAttributes = function () {
  8132. if (tag === 'button') {
  8133. var type = lookupAttr('type').getOr('button');
  8134. var roleAttrs = lookupAttr('role').map(function (role) {
  8135. return { role: role };
  8136. }).getOr({});
  8137. return __assign({ type: type }, roleAttrs);
  8138. } else {
  8139. var role = lookupAttr('role').getOr('button');
  8140. return { role: role };
  8141. }
  8142. };
  8143. return {
  8144. uid: detail.uid,
  8145. dom: detail.dom,
  8146. components: detail.components,
  8147. events: events,
  8148. behaviours: SketchBehaviours.augment(detail.buttonBehaviours, [
  8149. Focusing.config({}),
  8150. Keying.config({
  8151. mode: 'execution',
  8152. useSpace: true,
  8153. useEnter: true
  8154. })
  8155. ]),
  8156. domModification: { attributes: getModAttributes() },
  8157. eventOrder: detail.eventOrder
  8158. };
  8159. };
  8160. var Button = single$2({
  8161. name: 'Button',
  8162. factory: factory$1,
  8163. configFields: [
  8164. defaulted$1('uid', undefined),
  8165. strict$1('dom'),
  8166. defaulted$1('components', []),
  8167. SketchBehaviours.field('buttonBehaviours', [
  8168. Focusing,
  8169. Keying
  8170. ]),
  8171. option('action'),
  8172. option('role'),
  8173. defaulted$1('eventOrder', {})
  8174. ]
  8175. });
  8176. var record = function (spec) {
  8177. var uid = isSketchSpec(spec) && hasKey$1(spec, 'uid') ? spec.uid : generate$2('memento');
  8178. var get = function (anyInSystem) {
  8179. return anyInSystem.getSystem().getByUid(uid).getOrDie();
  8180. };
  8181. var getOpt = function (anyInSystem) {
  8182. return anyInSystem.getSystem().getByUid(uid).fold(Option.none, Option.some);
  8183. };
  8184. var asSpec = function () {
  8185. return __assign({}, spec, { uid: uid });
  8186. };
  8187. return {
  8188. get: get,
  8189. getOpt: getOpt,
  8190. asSpec: asSpec
  8191. };
  8192. };
  8193. var defaultIcon = function (icons) {
  8194. return Option.from(icons()['temporary-placeholder']).getOr('!not found!');
  8195. };
  8196. var get$c = function (name, icons) {
  8197. return Option.from(icons()[name]).getOrThunk(function () {
  8198. return defaultIcon(icons);
  8199. });
  8200. };
  8201. var getOr = function (name, icons, fallback) {
  8202. return Option.from(icons()[name]).or(fallback).getOrThunk(function () {
  8203. return defaultIcon(icons);
  8204. });
  8205. };
  8206. var getFirst$1 = function (names, icons) {
  8207. return findMap(names, function (name) {
  8208. return Option.from(icons()[name]);
  8209. }).getOrThunk(function () {
  8210. return defaultIcon(icons);
  8211. });
  8212. };
  8213. var notificationIconMap = {
  8214. success: 'checkmark',
  8215. error: 'warning',
  8216. err: 'error',
  8217. warning: 'warning',
  8218. warn: 'warning',
  8219. info: 'info'
  8220. };
  8221. var factory$2 = function (detail) {
  8222. var memBannerText = record({
  8223. dom: {
  8224. tag: 'p',
  8225. innerHtml: detail.translationProvider(detail.text)
  8226. },
  8227. behaviours: derive$1([Replacing.config({})])
  8228. });
  8229. var renderPercentBar = function (percent) {
  8230. return {
  8231. dom: {
  8232. tag: 'div',
  8233. classes: ['tox-bar'],
  8234. attributes: { style: 'width: ' + percent + '%' }
  8235. }
  8236. };
  8237. };
  8238. var renderPercentText = function (percent) {
  8239. return {
  8240. dom: {
  8241. tag: 'div',
  8242. classes: ['tox-text'],
  8243. innerHtml: percent + '%'
  8244. }
  8245. };
  8246. };
  8247. var memBannerProgress = record({
  8248. dom: {
  8249. tag: 'div',
  8250. classes: detail.progress ? [
  8251. 'tox-progress-bar',
  8252. 'tox-progress-indicator'
  8253. ] : ['tox-progress-bar']
  8254. },
  8255. components: [
  8256. {
  8257. dom: {
  8258. tag: 'div',
  8259. classes: ['tox-bar-container']
  8260. },
  8261. components: [renderPercentBar(0)]
  8262. },
  8263. renderPercentText(0)
  8264. ],
  8265. behaviours: derive$1([Replacing.config({})])
  8266. });
  8267. var updateProgress = function (comp, percent) {
  8268. if (comp.getSystem().isConnected()) {
  8269. memBannerProgress.getOpt(comp).each(function (progress) {
  8270. Replacing.set(progress, [
  8271. {
  8272. dom: {
  8273. tag: 'div',
  8274. classes: ['tox-bar-container']
  8275. },
  8276. components: [renderPercentBar(percent)]
  8277. },
  8278. renderPercentText(percent)
  8279. ]);
  8280. });
  8281. }
  8282. };
  8283. var updateText = function (comp, text$1) {
  8284. if (comp.getSystem().isConnected()) {
  8285. var banner = memBannerText.get(comp);
  8286. Replacing.set(banner, [text(text$1)]);
  8287. }
  8288. };
  8289. var apis = {
  8290. updateProgress: updateProgress,
  8291. updateText: updateText
  8292. };
  8293. var iconChoices = flatten([
  8294. detail.icon.toArray(),
  8295. detail.level.toArray(),
  8296. detail.level.bind(function (level) {
  8297. return Option.from(notificationIconMap[level]);
  8298. }).toArray()
  8299. ]);
  8300. return {
  8301. uid: detail.uid,
  8302. dom: {
  8303. tag: 'div',
  8304. attributes: { role: 'alert' },
  8305. classes: detail.level.map(function (level) {
  8306. return [
  8307. 'tox-notification',
  8308. 'tox-notification--in',
  8309. 'tox-notification--' + level
  8310. ];
  8311. }).getOr([
  8312. 'tox-notification',
  8313. 'tox-notification--in'
  8314. ])
  8315. },
  8316. components: [
  8317. {
  8318. dom: {
  8319. tag: 'div',
  8320. classes: ['tox-notification__icon'],
  8321. innerHtml: getFirst$1(iconChoices, detail.iconProvider)
  8322. }
  8323. },
  8324. {
  8325. dom: {
  8326. tag: 'div',
  8327. classes: ['tox-notification__body']
  8328. },
  8329. components: [memBannerText.asSpec()],
  8330. behaviours: derive$1([Replacing.config({})])
  8331. }
  8332. ].concat(detail.progress ? [memBannerProgress.asSpec()] : []).concat(Button.sketch({
  8333. dom: {
  8334. tag: 'button',
  8335. classes: [
  8336. 'tox-notification__dismiss',
  8337. 'tox-button',
  8338. 'tox-button--naked',
  8339. 'tox-button--icon'
  8340. ]
  8341. },
  8342. components: [{
  8343. dom: {
  8344. tag: 'div',
  8345. classes: ['tox-icon'],
  8346. innerHtml: get$c('close', detail.iconProvider),
  8347. attributes: { 'aria-label': detail.translationProvider('Close') }
  8348. }
  8349. }],
  8350. action: function (comp) {
  8351. detail.onAction(comp);
  8352. }
  8353. })),
  8354. apis: apis
  8355. };
  8356. };
  8357. var Notification = single$2({
  8358. name: 'Notification',
  8359. factory: factory$2,
  8360. configFields: [
  8361. option('level'),
  8362. strict$1('progress'),
  8363. strict$1('icon'),
  8364. strict$1('onAction'),
  8365. strict$1('text'),
  8366. strict$1('iconProvider'),
  8367. strict$1('translationProvider')
  8368. ],
  8369. apis: {
  8370. updateProgress: function (apis, comp, percent) {
  8371. apis.updateProgress(comp, percent);
  8372. },
  8373. updateText: function (apis, comp, text) {
  8374. apis.updateText(comp, text);
  8375. }
  8376. }
  8377. });
  8378. function NotificationManagerImpl (editor, extras, uiMothership) {
  8379. var backstage = extras.backstage;
  8380. var getEditorContainer = function (editor) {
  8381. return editor.inline ? editor.getElement() : editor.getContentAreaContainer();
  8382. };
  8383. var prePositionNotifications = function (notifications) {
  8384. each(notifications, function (notification) {
  8385. notification.moveTo(0, 0);
  8386. });
  8387. };
  8388. var positionNotifications = function (notifications) {
  8389. if (notifications.length > 0) {
  8390. var firstItem = notifications.slice(0, 1)[0];
  8391. var container = getEditorContainer(editor);
  8392. firstItem.moveRel(container, 'tc-tc');
  8393. each(notifications, function (notification, index) {
  8394. if (index > 0) {
  8395. notification.moveRel(notifications[index - 1].getEl(), 'bc-tc');
  8396. }
  8397. });
  8398. }
  8399. };
  8400. var reposition = function (notifications) {
  8401. prePositionNotifications(notifications);
  8402. positionNotifications(notifications);
  8403. };
  8404. var open = function (settings, closeCallback) {
  8405. var close = function () {
  8406. closeCallback();
  8407. InlineView.hide(notificationWrapper);
  8408. };
  8409. var notification = build$1(Notification.sketch({
  8410. text: settings.text,
  8411. level: contains([
  8412. 'success',
  8413. 'error',
  8414. 'warning',
  8415. 'info'
  8416. ], settings.type) ? settings.type : undefined,
  8417. progress: settings.progressBar === true ? true : false,
  8418. icon: Option.from(settings.icon),
  8419. onAction: close,
  8420. iconProvider: backstage.shared.providers.icons,
  8421. translationProvider: backstage.shared.providers.translate
  8422. }));
  8423. var notificationWrapper = build$1(InlineView.sketch({
  8424. dom: {
  8425. tag: 'div',
  8426. classes: ['tox-notifications-container']
  8427. },
  8428. lazySink: extras.backstage.shared.getSink,
  8429. fireDismissalEventInstead: {}
  8430. }));
  8431. uiMothership.add(notificationWrapper);
  8432. if (settings.timeout) {
  8433. setTimeout(function () {
  8434. close();
  8435. }, settings.timeout);
  8436. }
  8437. return {
  8438. close: close,
  8439. moveTo: function (x, y) {
  8440. InlineView.showAt(notificationWrapper, {
  8441. anchor: 'makeshift',
  8442. x: x,
  8443. y: y
  8444. }, premade$1(notification));
  8445. },
  8446. moveRel: function (element, rel) {
  8447. InlineView.showAt(notificationWrapper, extras.backstage.shared.anchors.banner(), premade$1(notification));
  8448. },
  8449. text: function (nuText) {
  8450. Notification.updateText(notification, nuText);
  8451. },
  8452. settings: settings,
  8453. getEl: function () {
  8454. },
  8455. progressBar: {
  8456. value: function (percent) {
  8457. Notification.updateProgress(notification, percent);
  8458. }
  8459. }
  8460. };
  8461. };
  8462. var close = function (notification) {
  8463. notification.close();
  8464. };
  8465. var getArgs = function (notification) {
  8466. return notification.settings;
  8467. };
  8468. return {
  8469. open: open,
  8470. close: close,
  8471. reposition: reposition,
  8472. getArgs: getArgs
  8473. };
  8474. }
  8475. var last$2 = function (fn, rate) {
  8476. var timer = null;
  8477. var cancel = function () {
  8478. if (timer !== null) {
  8479. clearTimeout(timer);
  8480. timer = null;
  8481. }
  8482. };
  8483. var throttle = function () {
  8484. var args = [];
  8485. for (var _i = 0; _i < arguments.length; _i++) {
  8486. args[_i] = arguments[_i];
  8487. }
  8488. if (timer !== null)
  8489. clearTimeout(timer);
  8490. timer = setTimeout(function () {
  8491. fn.apply(null, args);
  8492. timer = null;
  8493. }, rate);
  8494. };
  8495. return {
  8496. cancel: cancel,
  8497. throttle: throttle
  8498. };
  8499. };
  8500. var isValidTextRange = function (rng) {
  8501. return rng.collapsed && rng.startContainer.nodeType === 3;
  8502. };
  8503. var whiteSpace = /[\u00a0 \t\r\n]/;
  8504. var parse$1 = function (text, index, ch, minChars) {
  8505. var i;
  8506. for (i = index - 1; i >= 0; i--) {
  8507. if (whiteSpace.test(text.charAt(i))) {
  8508. return Option.none();
  8509. }
  8510. if (text.charAt(i) === ch) {
  8511. break;
  8512. }
  8513. }
  8514. if (i === -1 || index - i < minChars) {
  8515. return Option.none();
  8516. }
  8517. return Option.some(text.substring(i + 1, index));
  8518. };
  8519. var getContext = function (initRange, ch, text, index, minChars) {
  8520. if (minChars === void 0) {
  8521. minChars = 0;
  8522. }
  8523. if (!isValidTextRange(initRange)) {
  8524. return Option.none();
  8525. }
  8526. return parse$1(text, index, ch, minChars).map(function (newText) {
  8527. var rng = initRange.cloneRange();
  8528. rng.setStart(initRange.startContainer, initRange.startOffset - newText.length - 1);
  8529. rng.setEnd(initRange.startContainer, initRange.startOffset);
  8530. return {
  8531. text: newText,
  8532. rng: rng
  8533. };
  8534. });
  8535. };
  8536. var setup = function (api, editor) {
  8537. editor.on('keypress', api.onKeypress.throttle);
  8538. editor.on('remove', api.onKeypress.cancel);
  8539. var redirectKeyToItem = function (item, e) {
  8540. emitWith(item, keydown(), { raw: e });
  8541. };
  8542. editor.on('keydown', function (e) {
  8543. var getItem = function () {
  8544. return api.getView().bind(Highlighting.getHighlighted);
  8545. };
  8546. if (e.which === 8) {
  8547. api.onKeypress.throttle(e);
  8548. }
  8549. if (api.isActive()) {
  8550. if (e.which === 27) {
  8551. api.closeIfNecessary();
  8552. } else if (e.which === 32) {
  8553. api.closeIfNecessary();
  8554. } else if (e.which === 13) {
  8555. getItem().each(emitExecute);
  8556. e.preventDefault();
  8557. } else if (e.which === 40) {
  8558. getItem().fold(function () {
  8559. api.getView().each(Highlighting.highlightFirst);
  8560. }, function (item) {
  8561. redirectKeyToItem(item, e);
  8562. });
  8563. e.preventDefault();
  8564. } else if (e.which === 37 || e.which === 38 || e.which === 39) {
  8565. getItem().each(function (item) {
  8566. redirectKeyToItem(item, e);
  8567. e.preventDefault();
  8568. });
  8569. }
  8570. }
  8571. });
  8572. };
  8573. var AutocompleterEditorEvents = { setup: setup };
  8574. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Promise');
  8575. var isStartOfWord = function (rng, text) {
  8576. return rng.startOffset === 0 || /\s/.test(text.charAt(rng.startOffset - 1));
  8577. };
  8578. var getTriggerContext = function (initRange, initText, database) {
  8579. return findMap(database.triggerChars, function (ch) {
  8580. return getContext(initRange, ch, initText, initRange.startOffset).map(function (_a) {
  8581. var rng = _a.rng, text = _a.text;
  8582. return {
  8583. range: rng,
  8584. text: text,
  8585. triggerChar: ch
  8586. };
  8587. });
  8588. });
  8589. };
  8590. var lookup = function (editor, getDatabase) {
  8591. var database = getDatabase();
  8592. var rng = editor.selection.getRng();
  8593. var startText = rng.startContainer.nodeValue;
  8594. return getTriggerContext(rng, startText, database).map(function (context) {
  8595. var autocompleters = filter(database.lookupByChar(context.triggerChar), function (autocompleter) {
  8596. return context.text.length >= autocompleter.minChars && autocompleter.matches.getOr(isStartOfWord)(context.range, startText, context.text);
  8597. });
  8598. var lookupData = global$1.all(map(autocompleters, function (ac) {
  8599. var fetchResult = ac.fetch(context.text, ac.maxResults);
  8600. return fetchResult.then(function (results) {
  8601. return {
  8602. items: results,
  8603. columns: ac.columns,
  8604. onAction: ac.onAction
  8605. };
  8606. });
  8607. }));
  8608. return {
  8609. lookupData: lookupData,
  8610. triggerChar: context.triggerChar,
  8611. range: context.range
  8612. };
  8613. });
  8614. };
  8615. var autocompleterItemSchema = objOf([
  8616. state$1('type', function () {
  8617. return 'autocompleteitem';
  8618. }),
  8619. state$1('active', function () {
  8620. return false;
  8621. }),
  8622. state$1('disabled', function () {
  8623. return false;
  8624. }),
  8625. defaulted$1('meta', {}),
  8626. strictString('value'),
  8627. optionString('text'),
  8628. optionString('icon')
  8629. ]);
  8630. var autocompleterSchema = objOf([
  8631. strictString('type'),
  8632. strictString('ch'),
  8633. defaultedNumber('minChars', 1),
  8634. defaulted$1('columns', 1),
  8635. defaultedNumber('maxResults', 10),
  8636. optionFunction('matches'),
  8637. strictFunction('fetch'),
  8638. strictFunction('onAction')
  8639. ]);
  8640. var createAutocompleterItem = function (spec) {
  8641. return asRaw('Autocompleter.Item', autocompleterItemSchema, spec);
  8642. };
  8643. var createAutocompleter = function (spec) {
  8644. return asRaw('Autocompleter', autocompleterSchema, spec);
  8645. };
  8646. var stringArray = function (a) {
  8647. var all = {};
  8648. each(a, function (key) {
  8649. all[key] = {};
  8650. });
  8651. return keys(all);
  8652. };
  8653. var register = function (editor) {
  8654. var popups = editor.ui.registry.getAll().popups;
  8655. var dataset = map$1(popups, function (popup) {
  8656. return createAutocompleter(popup).fold(function (err) {
  8657. throw new Error(formatError(err));
  8658. }, function (x) {
  8659. return x;
  8660. });
  8661. });
  8662. var triggerChars = stringArray(mapToArray(dataset, function (v) {
  8663. return v.ch;
  8664. }));
  8665. var datasetValues = values(dataset);
  8666. var lookupByChar = function (ch) {
  8667. return filter(datasetValues, function (dv) {
  8668. return dv.ch === ch;
  8669. });
  8670. };
  8671. return {
  8672. dataset: dataset,
  8673. triggerChars: triggerChars,
  8674. lookupByChar: lookupByChar
  8675. };
  8676. };
  8677. var commonMenuItemFields = [
  8678. defaultedBoolean('disabled', false),
  8679. optionString('text'),
  8680. optionString('shortcut'),
  8681. field('value', 'value', defaultedThunk(function () {
  8682. return generate$1('menuitem-value');
  8683. }), anyValue$1()),
  8684. defaulted$1('meta', {})
  8685. ];
  8686. var menuItemSchema = objOf([
  8687. strictString('type'),
  8688. defaultedFunction('onSetup', function () {
  8689. return noop;
  8690. }),
  8691. defaultedFunction('onAction', noop),
  8692. optionString('icon')
  8693. ].concat(commonMenuItemFields));
  8694. var createMenuItem = function (spec) {
  8695. return asRaw('menuitem', menuItemSchema, spec);
  8696. };
  8697. var nestedMenuItemSchema = objOf([
  8698. strictString('type'),
  8699. strictFunction('getSubmenuItems'),
  8700. defaultedFunction('onSetup', function () {
  8701. return noop;
  8702. }),
  8703. optionString('icon')
  8704. ].concat(commonMenuItemFields));
  8705. var createNestedMenuItem = function (spec) {
  8706. return asRaw('nestedmenuitem', nestedMenuItemSchema, spec);
  8707. };
  8708. var toggleMenuItemSchema = objOf([
  8709. strictString('type'),
  8710. defaultedBoolean('active', false),
  8711. defaultedFunction('onSetup', function () {
  8712. return noop;
  8713. }),
  8714. strictFunction('onAction')
  8715. ].concat(commonMenuItemFields));
  8716. var createToggleMenuItem = function (spec) {
  8717. return asRaw('togglemenuitem', toggleMenuItemSchema, spec);
  8718. };
  8719. var choiceMenuItemSchema = objOf([
  8720. strictString('type'),
  8721. defaultedBoolean('active', false),
  8722. optionString('icon')
  8723. ].concat(commonMenuItemFields));
  8724. var createChoiceMenuItem = function (spec) {
  8725. return asRaw('choicemenuitem', choiceMenuItemSchema, spec);
  8726. };
  8727. var separatorMenuItemSchema = objOf([
  8728. strictString('type'),
  8729. optionString('text')
  8730. ]);
  8731. var createSeparatorMenuItem = function (spec) {
  8732. return asRaw('separatormenuitem', separatorMenuItemSchema, spec);
  8733. };
  8734. var fancyMenuItemSchema = objOf([
  8735. strictString('type'),
  8736. strictStringEnum('fancytype', ['inserttable']),
  8737. defaultedFunction('onAction', noop)
  8738. ]);
  8739. var createFancyMenuItem = function (spec) {
  8740. return asRaw('fancymenuitem', fancyMenuItemSchema, spec);
  8741. };
  8742. var detectSize = function (comp, margin, selectorClass) {
  8743. var descendants$1 = descendants(comp.element(), '.' + selectorClass);
  8744. if (descendants$1.length > 0) {
  8745. var columnLength = findIndex(descendants$1, function (c) {
  8746. var thisTop = c.dom().getBoundingClientRect().top;
  8747. var cTop = descendants$1[0].dom().getBoundingClientRect().top;
  8748. return Math.abs(thisTop - cTop) > margin;
  8749. }).getOr(descendants$1.length);
  8750. return Option.some({
  8751. numColumns: columnLength,
  8752. numRows: Math.ceil(descendants$1.length / columnLength)
  8753. });
  8754. } else {
  8755. return Option.none();
  8756. }
  8757. };
  8758. var namedEvents = function (name, handlers) {
  8759. return derive$1([config(name, handlers)]);
  8760. };
  8761. var unnamedEvents = function (handlers) {
  8762. return namedEvents(generate$1('unnamed-events'), handlers);
  8763. };
  8764. var SimpleBehaviours = {
  8765. namedEvents: namedEvents,
  8766. unnamedEvents: unnamedEvents
  8767. };
  8768. var TooltippingSchema = [
  8769. strict$1('lazySink'),
  8770. strict$1('tooltipDom'),
  8771. defaulted$1('exclusive', true),
  8772. defaulted$1('tooltipComponents', []),
  8773. defaulted$1('delay', 300),
  8774. defaultedStringEnum('mode', 'normal', [
  8775. 'normal',
  8776. 'follow-highlight'
  8777. ]),
  8778. defaulted$1('anchor', function (comp) {
  8779. return {
  8780. anchor: 'hotspot',
  8781. hotspot: comp,
  8782. layouts: {
  8783. onLtr: constant([
  8784. south$1,
  8785. north$1,
  8786. southeast$1,
  8787. northeast$1,
  8788. southwest$1,
  8789. northwest$1
  8790. ]),
  8791. onRtl: constant([
  8792. south$1,
  8793. north$1,
  8794. southeast$1,
  8795. northeast$1,
  8796. southwest$1,
  8797. northwest$1
  8798. ])
  8799. }
  8800. };
  8801. }),
  8802. onHandler('onHide'),
  8803. onHandler('onShow')
  8804. ];
  8805. var init$5 = function () {
  8806. var timer = Cell(Option.none());
  8807. var popup = Cell(Option.none());
  8808. var getTooltip = function () {
  8809. return popup.get();
  8810. };
  8811. var setTooltip = function (s) {
  8812. popup.set(Option.some(s));
  8813. };
  8814. var clearTooltip = function () {
  8815. popup.set(Option.none());
  8816. };
  8817. var clearTimer = function () {
  8818. timer.get().each(function (t) {
  8819. domGlobals.clearTimeout(t);
  8820. });
  8821. };
  8822. var resetTimer = function (f, delay) {
  8823. clearTimer();
  8824. timer.set(Option.some(domGlobals.setTimeout(function () {
  8825. f();
  8826. }, delay)));
  8827. };
  8828. var isShowing = function () {
  8829. return popup.get().isSome();
  8830. };
  8831. var readState = constant('not-implemented');
  8832. return nu$5({
  8833. getTooltip: getTooltip,
  8834. isShowing: isShowing,
  8835. setTooltip: setTooltip,
  8836. clearTooltip: clearTooltip,
  8837. clearTimer: clearTimer,
  8838. resetTimer: resetTimer,
  8839. readState: readState
  8840. });
  8841. };
  8842. var TooltippingState = /*#__PURE__*/Object.freeze({
  8843. init: init$5
  8844. });
  8845. var ExclusivityChannel = generate$1('tooltip.exclusive');
  8846. var ShowTooltipEvent = generate$1('tooltip.show');
  8847. var HideTooltipEvent = generate$1('tooltip.hide');
  8848. var hideAllExclusive = function (component, tConfig, tState) {
  8849. component.getSystem().broadcastOn([ExclusivityChannel], {});
  8850. };
  8851. var setComponents = function (component, tConfig, tState, specs) {
  8852. tState.getTooltip().each(function (tooltip) {
  8853. if (tooltip.getSystem().isConnected()) {
  8854. Replacing.set(tooltip, specs);
  8855. }
  8856. });
  8857. };
  8858. var TooltippingApis = /*#__PURE__*/Object.freeze({
  8859. hideAllExclusive: hideAllExclusive,
  8860. setComponents: setComponents
  8861. });
  8862. var events$8 = function (tooltipConfig, state) {
  8863. var hide = function (comp) {
  8864. state.getTooltip().each(function (p) {
  8865. detach(p);
  8866. tooltipConfig.onHide(comp, p);
  8867. state.clearTooltip();
  8868. });
  8869. state.clearTimer();
  8870. };
  8871. var show = function (comp) {
  8872. if (!state.isShowing()) {
  8873. hideAllExclusive(comp, tooltipConfig, state);
  8874. var sink = tooltipConfig.lazySink(comp).getOrDie();
  8875. var popup = comp.getSystem().build({
  8876. dom: tooltipConfig.tooltipDom,
  8877. components: tooltipConfig.tooltipComponents,
  8878. events: derive(tooltipConfig.mode === 'normal' ? [
  8879. run(mouseover(), function (_) {
  8880. emit(comp, ShowTooltipEvent);
  8881. }),
  8882. run(mouseout(), function (_) {
  8883. emit(comp, HideTooltipEvent);
  8884. })
  8885. ] : []),
  8886. behaviours: derive$1([Replacing.config({})])
  8887. });
  8888. state.setTooltip(popup);
  8889. attach(sink, popup);
  8890. tooltipConfig.onShow(comp, popup);
  8891. Positioning.position(sink, tooltipConfig.anchor(comp), popup);
  8892. }
  8893. };
  8894. return derive(flatten([
  8895. [
  8896. run(ShowTooltipEvent, function (comp) {
  8897. state.resetTimer(function () {
  8898. show(comp);
  8899. }, tooltipConfig.delay);
  8900. }),
  8901. run(HideTooltipEvent, function (comp) {
  8902. state.resetTimer(function () {
  8903. hide(comp);
  8904. }, tooltipConfig.delay);
  8905. }),
  8906. run(receive(), function (comp, message) {
  8907. var receivingData = message;
  8908. if (contains(receivingData.channels(), ExclusivityChannel)) {
  8909. hide(comp);
  8910. }
  8911. }),
  8912. runOnDetached(function (comp) {
  8913. hide(comp);
  8914. })
  8915. ],
  8916. tooltipConfig.mode === 'normal' ? [
  8917. run(focusin(), function (comp) {
  8918. emit(comp, ShowTooltipEvent);
  8919. }),
  8920. run(postBlur(), function (comp) {
  8921. emit(comp, HideTooltipEvent);
  8922. }),
  8923. run(mouseover(), function (comp) {
  8924. emit(comp, ShowTooltipEvent);
  8925. }),
  8926. run(mouseout(), function (comp) {
  8927. emit(comp, HideTooltipEvent);
  8928. })
  8929. ] : [
  8930. run(highlight(), function (comp, se) {
  8931. emit(comp, ShowTooltipEvent);
  8932. }),
  8933. run(dehighlight(), function (comp) {
  8934. emit(comp, HideTooltipEvent);
  8935. })
  8936. ]
  8937. ]));
  8938. };
  8939. var ActiveTooltipping = /*#__PURE__*/Object.freeze({
  8940. events: events$8
  8941. });
  8942. var Tooltipping = create$1({
  8943. fields: TooltippingSchema,
  8944. name: 'tooltipping',
  8945. active: ActiveTooltipping,
  8946. state: TooltippingState,
  8947. apis: TooltippingApis
  8948. });
  8949. var getAttrs = function (elem) {
  8950. var attributes = elem.dom().attributes !== undefined ? elem.dom().attributes : [];
  8951. return foldl(attributes, function (b, attr) {
  8952. var _a;
  8953. if (attr.name === 'class') {
  8954. return b;
  8955. } else {
  8956. return __assign({}, b, (_a = {}, _a[attr.name] = attr.value, _a));
  8957. }
  8958. }, {});
  8959. };
  8960. var getClasses = function (elem) {
  8961. return Array.prototype.slice.call(elem.dom().classList, 0);
  8962. };
  8963. var fromHtml$2 = function (html) {
  8964. var elem = Element.fromHtml(html);
  8965. var children$1 = children(elem);
  8966. var attrs = getAttrs(elem);
  8967. var classes = getClasses(elem);
  8968. var contents = children$1.length === 0 ? {} : { innerHtml: get$1(elem) };
  8969. return __assign({
  8970. tag: name(elem),
  8971. classes: classes,
  8972. attributes: attrs
  8973. }, contents);
  8974. };
  8975. var global$2 = tinymce.util.Tools.resolve('tinymce.util.I18n');
  8976. var navClass = 'tox-menu-nav__js';
  8977. var selectableClass = 'tox-collection__item';
  8978. var colorClass = 'tox-swatch';
  8979. var presetClasses = {
  8980. normal: navClass,
  8981. color: colorClass
  8982. };
  8983. var tickedClass = 'tox-collection__item--enabled';
  8984. var groupHeadingClass = 'tox-collection__group-heading';
  8985. var iconClass = 'tox-collection__item-icon';
  8986. var textClass = 'tox-collection__item-label';
  8987. var accessoryClass = 'tox-collection__item-accessory';
  8988. var caretClass = 'tox-collection__item-caret';
  8989. var checkmarkClass = 'tox-collection__item-checkmark';
  8990. var activeClass = 'tox-collection__item--active';
  8991. var classForPreset = function (presets) {
  8992. return readOptFrom$1(presetClasses, presets).getOr(navClass);
  8993. };
  8994. var global$3 = tinymce.util.Tools.resolve('tinymce.Env');
  8995. var convertText = function (source) {
  8996. var mac = {
  8997. alt: '&#x2325;',
  8998. ctrl: '&#x2303;',
  8999. shift: '&#x21E7;',
  9000. meta: '&#x2318;',
  9001. access: '&#x2303;&#x2325;'
  9002. };
  9003. var other = {
  9004. meta: 'Ctrl',
  9005. access: 'Shift+Alt'
  9006. };
  9007. var replace = global$3.mac ? mac : other;
  9008. var shortcut = source.split('+');
  9009. var updated = map(shortcut, function (segment) {
  9010. var search = segment.toLowerCase().trim();
  9011. return has(replace, search) ? replace[search] : segment;
  9012. });
  9013. return global$3.mac ? updated.join('') : updated.join('+');
  9014. };
  9015. var ConvertShortcut = { convertText: convertText };
  9016. var renderIcon = function (iconHtml) {
  9017. return {
  9018. dom: {
  9019. tag: 'span',
  9020. classes: [iconClass],
  9021. innerHtml: iconHtml
  9022. }
  9023. };
  9024. };
  9025. var renderText = function (text$1) {
  9026. return {
  9027. dom: {
  9028. tag: 'span',
  9029. classes: [textClass]
  9030. },
  9031. components: [text(global$2.translate(text$1))]
  9032. };
  9033. };
  9034. var renderStyledText = function (style, text$1) {
  9035. return {
  9036. dom: {
  9037. tag: 'span',
  9038. classes: [textClass]
  9039. },
  9040. components: [{
  9041. dom: {
  9042. tag: style.tag,
  9043. attributes: { style: style.styleAttr }
  9044. },
  9045. components: [text(global$2.translate(text$1))]
  9046. }]
  9047. };
  9048. };
  9049. var renderShortcut = function (shortcut) {
  9050. return {
  9051. dom: {
  9052. tag: 'span',
  9053. classes: [accessoryClass],
  9054. innerHtml: ConvertShortcut.convertText(shortcut)
  9055. }
  9056. };
  9057. };
  9058. var renderCheckmark = function (icons) {
  9059. return {
  9060. dom: {
  9061. tag: 'span',
  9062. classes: [
  9063. iconClass,
  9064. checkmarkClass
  9065. ],
  9066. innerHtml: get$c('checkmark', icons)
  9067. }
  9068. };
  9069. };
  9070. var renderSubmenuCaret = function (icons) {
  9071. return {
  9072. dom: {
  9073. tag: 'span',
  9074. classes: [caretClass],
  9075. innerHtml: get$c('chevron-right', icons)
  9076. }
  9077. };
  9078. };
  9079. var renderColorStructure = function (itemText, itemValue, iconSvg) {
  9080. var colorPickerCommand = 'custom';
  9081. var removeColorCommand = 'remove';
  9082. var getDom = function () {
  9083. var common = colorClass;
  9084. var icon = iconSvg.getOr('');
  9085. var title = itemText.map(function (text) {
  9086. return ' title="' + text + '"';
  9087. }).getOr('');
  9088. if (itemValue === colorPickerCommand) {
  9089. return fromHtml$2('<button class="' + common + ' tox-swatches__picker-btn"' + title + '>' + icon + '</button>');
  9090. } else if (itemValue === removeColorCommand) {
  9091. return fromHtml$2('<div class="' + common + ' tox-swatch--remove"' + title + '>' + icon + '</div>');
  9092. } else {
  9093. return fromHtml$2('<div class="' + common + '" style="background-color: ' + itemValue + '" data-mce-color="' + itemValue + '"' + title + '></div>');
  9094. }
  9095. };
  9096. return {
  9097. dom: getDom(),
  9098. optComponents: []
  9099. };
  9100. };
  9101. var renderNormalItemStructure = function (info, icon, renderIcons, textRender) {
  9102. var leftIcon = renderIcons ? info.checkMark.orThunk(function () {
  9103. return icon.or(Option.some('')).map(renderIcon);
  9104. }) : Option.none();
  9105. var domTitle = info.ariaLabel.map(function (label) {
  9106. return { attributes: { title: global$2.translate(label) } };
  9107. }).getOr({});
  9108. var dom = merge({
  9109. tag: 'div',
  9110. classes: [
  9111. navClass,
  9112. selectableClass
  9113. ]
  9114. }, domTitle);
  9115. var menuItem = {
  9116. dom: dom,
  9117. optComponents: [
  9118. leftIcon,
  9119. info.textContent.map(textRender),
  9120. info.shortcutContent.map(renderShortcut),
  9121. info.caret
  9122. ]
  9123. };
  9124. return menuItem;
  9125. };
  9126. var renderItemStructure = function (info, providersBackstage, renderIcons, fallbackIcon) {
  9127. if (fallbackIcon === void 0) {
  9128. fallbackIcon = Option.none();
  9129. }
  9130. var icon = info.iconContent.map(function (iconName) {
  9131. return getOr(iconName, providersBackstage.icons, fallbackIcon);
  9132. });
  9133. var textRender = Option.from(info.meta).fold(function () {
  9134. return renderText;
  9135. }, function (meta) {
  9136. return has(meta, 'style') ? curry(renderStyledText, meta.style) : renderText;
  9137. });
  9138. if (info.presets === 'color') {
  9139. return renderColorStructure(info.ariaLabel, info.value, icon);
  9140. } else {
  9141. return renderNormalItemStructure(info, icon, renderIcons, textRender);
  9142. }
  9143. };
  9144. var nativeDisabled = [
  9145. 'input',
  9146. 'button',
  9147. 'textarea'
  9148. ];
  9149. var onLoad$5 = function (component, disableConfig, disableState) {
  9150. if (disableConfig.disabled) {
  9151. disable(component, disableConfig, disableState);
  9152. }
  9153. };
  9154. var hasNative = function (component) {
  9155. return contains(nativeDisabled, name(component.element()));
  9156. };
  9157. var nativeIsDisabled = function (component) {
  9158. return has$1(component.element(), 'disabled');
  9159. };
  9160. var nativeDisable = function (component) {
  9161. set$1(component.element(), 'disabled', 'disabled');
  9162. };
  9163. var nativeEnable = function (component) {
  9164. remove$1(component.element(), 'disabled');
  9165. };
  9166. var ariaIsDisabled = function (component) {
  9167. return get$2(component.element(), 'aria-disabled') === 'true';
  9168. };
  9169. var ariaDisable = function (component) {
  9170. set$1(component.element(), 'aria-disabled', 'true');
  9171. };
  9172. var ariaEnable = function (component) {
  9173. set$1(component.element(), 'aria-disabled', 'false');
  9174. };
  9175. var disable = function (component, disableConfig, disableState) {
  9176. disableConfig.disableClass.each(function (disableClass) {
  9177. add$2(component.element(), disableClass);
  9178. });
  9179. var f = hasNative(component) ? nativeDisable : ariaDisable;
  9180. f(component);
  9181. };
  9182. var enable = function (component, disableConfig, disableState) {
  9183. disableConfig.disableClass.each(function (disableClass) {
  9184. remove$4(component.element(), disableClass);
  9185. });
  9186. var f = hasNative(component) ? nativeEnable : ariaEnable;
  9187. f(component);
  9188. };
  9189. var isDisabled = function (component) {
  9190. return hasNative(component) ? nativeIsDisabled(component) : ariaIsDisabled(component);
  9191. };
  9192. var DisableApis = /*#__PURE__*/Object.freeze({
  9193. enable: enable,
  9194. disable: disable,
  9195. isDisabled: isDisabled,
  9196. onLoad: onLoad$5
  9197. });
  9198. var exhibit$3 = function (base, disableConfig, disableState) {
  9199. return nu$6({ classes: disableConfig.disabled ? disableConfig.disableClass.map(pure).getOr([]) : [] });
  9200. };
  9201. var events$9 = function (disableConfig, disableState) {
  9202. return derive([
  9203. abort(execute(), function (component, simulatedEvent) {
  9204. return isDisabled(component);
  9205. }),
  9206. loadEvent(disableConfig, disableState, onLoad$5)
  9207. ]);
  9208. };
  9209. var ActiveDisable = /*#__PURE__*/Object.freeze({
  9210. exhibit: exhibit$3,
  9211. events: events$9
  9212. });
  9213. var DisableSchema = [
  9214. defaulted$1('disabled', false),
  9215. option('disableClass')
  9216. ];
  9217. var Disabling = create$1({
  9218. fields: DisableSchema,
  9219. name: 'disabling',
  9220. active: ActiveDisable,
  9221. apis: DisableApis
  9222. });
  9223. var item = function (disabled) {
  9224. return Disabling.config({
  9225. disabled: disabled,
  9226. disableClass: 'tox-collection__item--state-disabled'
  9227. });
  9228. };
  9229. var button = function (disabled) {
  9230. return Disabling.config({ disabled: disabled });
  9231. };
  9232. var splitButton = function (disabled) {
  9233. return Disabling.config({
  9234. disabled: disabled,
  9235. disableClass: 'tox-tbtn--disabled'
  9236. });
  9237. };
  9238. var DisablingConfigs = {
  9239. item: item,
  9240. button: button,
  9241. splitButton: splitButton
  9242. };
  9243. var runWithApi = function (info, comp) {
  9244. var api = info.getApi(comp);
  9245. return function (f) {
  9246. f(api);
  9247. };
  9248. };
  9249. var onControlAttached = function (info, editorOffCell) {
  9250. return runOnAttached(function (comp) {
  9251. var run = runWithApi(info, comp);
  9252. run(function (api) {
  9253. var onDestroy = info.onSetup(api);
  9254. if (onDestroy !== null && onDestroy !== undefined) {
  9255. editorOffCell.set(onDestroy);
  9256. }
  9257. });
  9258. });
  9259. };
  9260. var onControlDetached = function (getApi, editorOffCell) {
  9261. return runOnDetached(function (comp) {
  9262. return runWithApi(getApi, comp)(editorOffCell.get());
  9263. });
  9264. };
  9265. var ItemResponse;
  9266. (function (ItemResponse) {
  9267. ItemResponse[ItemResponse['CLOSE_ON_EXECUTE'] = 0] = 'CLOSE_ON_EXECUTE';
  9268. ItemResponse[ItemResponse['BUBBLE_TO_SANDBOX'] = 1] = 'BUBBLE_TO_SANDBOX';
  9269. }(ItemResponse || (ItemResponse = {})));
  9270. var ItemResponse$1 = ItemResponse;
  9271. var onMenuItemExecute = function (info, itemResponse) {
  9272. return runOnExecute(function (comp, simulatedEvent) {
  9273. runWithApi(info, comp)(info.onAction);
  9274. if (!info.triggersSubmenu && itemResponse === ItemResponse$1.CLOSE_ON_EXECUTE) {
  9275. emit(comp, sandboxClose());
  9276. simulatedEvent.stop();
  9277. }
  9278. });
  9279. };
  9280. var menuItemEventOrder = {
  9281. 'alloy.execute': [
  9282. 'disabling',
  9283. 'alloy.base.behaviour',
  9284. 'toggling',
  9285. 'item-events'
  9286. ]
  9287. };
  9288. var componentRenderPipeline = function (xs) {
  9289. return bind(xs, function (o) {
  9290. return o.toArray();
  9291. });
  9292. };
  9293. var renderCommonItem = function (spec, structure, itemResponse) {
  9294. var editorOffCell = Cell(noop);
  9295. return {
  9296. type: 'item',
  9297. dom: structure.dom,
  9298. components: componentRenderPipeline(structure.optComponents),
  9299. data: spec.data,
  9300. eventOrder: menuItemEventOrder,
  9301. hasSubmenu: spec.triggersSubmenu,
  9302. itemBehaviours: derive$1([
  9303. config('item-events', [
  9304. onMenuItemExecute(spec, itemResponse),
  9305. onControlAttached(spec, editorOffCell),
  9306. onControlDetached(spec, editorOffCell)
  9307. ]),
  9308. DisablingConfigs.item(spec.disabled),
  9309. Replacing.config({})
  9310. ].concat(spec.itemBehaviours))
  9311. };
  9312. };
  9313. var buildData = function (source) {
  9314. return {
  9315. value: source.value,
  9316. meta: merge({ text: source.text.getOr('') }, source.meta)
  9317. };
  9318. };
  9319. var tooltipBehaviour = function (meta, sharedBackstage) {
  9320. return get(meta, 'tooltipWorker').map(function (tooltipWorker) {
  9321. return [Tooltipping.config({
  9322. lazySink: sharedBackstage.getSink,
  9323. tooltipDom: { tag: 'div' },
  9324. tooltipComponents: [],
  9325. anchor: function (comp) {
  9326. return {
  9327. anchor: 'submenu',
  9328. item: comp
  9329. };
  9330. },
  9331. mode: 'follow-highlight',
  9332. onShow: function (component, _tooltip) {
  9333. tooltipWorker(function (elm) {
  9334. Tooltipping.setComponents(component, [external({ element: Element.fromDom(elm) })]);
  9335. });
  9336. }
  9337. })];
  9338. }).getOr([]);
  9339. };
  9340. var renderAutocompleteItem = function (spec, useText, presets, onItemValueHandler, itemResponse, sharedBackstage, renderIcons) {
  9341. if (renderIcons === void 0) {
  9342. renderIcons = true;
  9343. }
  9344. var structure = renderItemStructure({
  9345. presets: presets,
  9346. textContent: useText ? spec.text : Option.none(),
  9347. ariaLabel: spec.text,
  9348. iconContent: spec.icon,
  9349. shortcutContent: Option.none(),
  9350. checkMark: Option.none(),
  9351. caret: Option.none(),
  9352. value: spec.value
  9353. }, sharedBackstage.providers, renderIcons, spec.icon);
  9354. return renderCommonItem({
  9355. data: buildData(spec),
  9356. disabled: spec.disabled,
  9357. getApi: function () {
  9358. return {};
  9359. },
  9360. onAction: function (_api) {
  9361. return onItemValueHandler(spec.value, spec.meta);
  9362. },
  9363. onSetup: function () {
  9364. return function () {
  9365. };
  9366. },
  9367. triggersSubmenu: false,
  9368. itemBehaviours: tooltipBehaviour(spec.meta, sharedBackstage)
  9369. }, structure, itemResponse);
  9370. };
  9371. var renderChoiceItem = function (spec, useText, presets, onItemValueHandler, isSelected, itemResponse, providersBackstage) {
  9372. var getApi = function (component) {
  9373. return {
  9374. setActive: function (state) {
  9375. Toggling.set(component, state);
  9376. },
  9377. isActive: function () {
  9378. return Toggling.isOn(component);
  9379. },
  9380. isDisabled: function () {
  9381. return Disabling.isDisabled(component);
  9382. },
  9383. setDisabled: function (state) {
  9384. return state ? Disabling.disable(component) : Disabling.enable(component);
  9385. }
  9386. };
  9387. };
  9388. var structure = renderItemStructure({
  9389. presets: presets,
  9390. textContent: useText ? spec.text : Option.none(),
  9391. ariaLabel: spec.text,
  9392. iconContent: spec.icon,
  9393. shortcutContent: useText ? spec.shortcut : Option.none(),
  9394. checkMark: useText ? Option.some(renderCheckmark(providersBackstage.icons)) : Option.none(),
  9395. caret: Option.none(),
  9396. value: spec.value
  9397. }, providersBackstage, true);
  9398. return deepMerge(renderCommonItem({
  9399. data: buildData(spec),
  9400. disabled: spec.disabled,
  9401. getApi: getApi,
  9402. onAction: function (_api) {
  9403. return onItemValueHandler(spec.value);
  9404. },
  9405. onSetup: function (api) {
  9406. api.setActive(isSelected);
  9407. return function () {
  9408. };
  9409. },
  9410. triggersSubmenu: false,
  9411. itemBehaviours: []
  9412. }, structure, itemResponse), {
  9413. toggling: {
  9414. toggleClass: tickedClass,
  9415. toggleOnExecute: false,
  9416. selected: spec.active
  9417. }
  9418. });
  9419. };
  9420. var parts$2 = constant(generate$4(owner$2(), parts()));
  9421. var cellOverEvent = generate$1('cell-over');
  9422. var cellExecuteEvent = generate$1('cell-execute');
  9423. var makeCell = function (row, col, labelId) {
  9424. var _a;
  9425. var emitCellOver = function (c) {
  9426. return emitWith(c, cellOverEvent, {
  9427. row: row,
  9428. col: col
  9429. });
  9430. };
  9431. var emitExecute = function (c) {
  9432. return emitWith(c, cellExecuteEvent, {
  9433. row: row,
  9434. col: col
  9435. });
  9436. };
  9437. return build$1({
  9438. dom: {
  9439. tag: 'div',
  9440. attributes: (_a = { role: 'button' }, _a['aria-labelledby'] = labelId, _a)
  9441. },
  9442. behaviours: derive$1([
  9443. config('insert-table-picker-cell', [
  9444. run(mouseover(), Focusing.focus),
  9445. run(execute(), emitExecute),
  9446. run(tapOrClick(), emitExecute)
  9447. ]),
  9448. Toggling.config({
  9449. toggleClass: 'tox-insert-table-picker__selected',
  9450. toggleOnExecute: false
  9451. }),
  9452. Focusing.config({ onFocus: emitCellOver })
  9453. ])
  9454. });
  9455. };
  9456. var makeCells = function (labelId, numRows, numCols) {
  9457. var cells = [];
  9458. for (var i = 0; i < numRows; i++) {
  9459. var row = [];
  9460. for (var j = 0; j < numCols; j++) {
  9461. row.push(makeCell(i, j, labelId));
  9462. }
  9463. cells.push(row);
  9464. }
  9465. return cells;
  9466. };
  9467. var selectCells = function (cells, selectedRow, selectedColumn, numRows, numColumns) {
  9468. for (var i = 0; i < numRows; i++) {
  9469. for (var j = 0; j < numColumns; j++) {
  9470. Toggling.set(cells[i][j], i <= selectedRow && j <= selectedColumn);
  9471. }
  9472. }
  9473. };
  9474. var makeComponents = function (cells) {
  9475. return bind(cells, function (cellRow) {
  9476. return map(cellRow, premade$1);
  9477. });
  9478. };
  9479. var makeLabelText = function (row, col) {
  9480. return text(col + 1 + 'x' + (row + 1));
  9481. };
  9482. function renderInsertTableMenuItem(spec) {
  9483. var numRows = 10;
  9484. var numColumns = 10;
  9485. var sizeLabelId = generate$1('size-label');
  9486. var cells = makeCells(sizeLabelId, numRows, numColumns);
  9487. var memLabel = record({
  9488. dom: {
  9489. tag: 'span',
  9490. classes: ['tox-insert-table-picker__label'],
  9491. attributes: { id: sizeLabelId }
  9492. },
  9493. components: [text('0x0')],
  9494. behaviours: derive$1([Replacing.config({})])
  9495. });
  9496. return {
  9497. type: 'widget',
  9498. data: { value: generate$1('widget-id') },
  9499. dom: {
  9500. tag: 'div',
  9501. classes: ['tox-fancymenuitem']
  9502. },
  9503. autofocus: true,
  9504. components: [parts$2().widget({
  9505. dom: {
  9506. tag: 'div',
  9507. classes: ['tox-insert-table-picker']
  9508. },
  9509. components: makeComponents(cells).concat(memLabel.asSpec()),
  9510. behaviours: derive$1([
  9511. config('insert-table-picker', [
  9512. runWithTarget(cellOverEvent, function (c, t, e) {
  9513. var row = e.event().row();
  9514. var col = e.event().col();
  9515. selectCells(cells, row, col, numRows, numColumns);
  9516. Replacing.set(memLabel.get(c), [makeLabelText(row, col)]);
  9517. }),
  9518. runWithTarget(cellExecuteEvent, function (c, _, e) {
  9519. spec.onAction({
  9520. numRows: e.event().row() + 1,
  9521. numColumns: e.event().col() + 1
  9522. });
  9523. emit(c, sandboxClose());
  9524. })
  9525. ]),
  9526. Keying.config({
  9527. initSize: {
  9528. numRows: numRows,
  9529. numColumns: numColumns
  9530. },
  9531. mode: 'flatgrid',
  9532. selector: '[role="button"]'
  9533. })
  9534. ])
  9535. })]
  9536. };
  9537. }
  9538. var fancyMenuItems = { inserttable: renderInsertTableMenuItem };
  9539. var valueOpt = function (obj, key) {
  9540. return Object.prototype.hasOwnProperty.call(obj, key) ? Option.some(obj[key]) : Option.none();
  9541. };
  9542. var renderFancyMenuItem = function (spec) {
  9543. return valueOpt(fancyMenuItems, spec.fancytype).map(function (render) {
  9544. return render(spec);
  9545. });
  9546. };
  9547. var renderNormalItem = function (spec, itemResponse, providersBackstage, renderIcons) {
  9548. if (renderIcons === void 0) {
  9549. renderIcons = true;
  9550. }
  9551. var getApi = function (component) {
  9552. return {
  9553. isDisabled: function () {
  9554. return Disabling.isDisabled(component);
  9555. },
  9556. setDisabled: function (state) {
  9557. return state ? Disabling.disable(component) : Disabling.enable(component);
  9558. }
  9559. };
  9560. };
  9561. var structure = renderItemStructure({
  9562. presets: 'normal',
  9563. iconContent: spec.icon,
  9564. textContent: spec.text,
  9565. ariaLabel: spec.text,
  9566. caret: Option.none(),
  9567. checkMark: Option.none(),
  9568. shortcutContent: spec.shortcut
  9569. }, providersBackstage, renderIcons);
  9570. return renderCommonItem({
  9571. data: buildData(spec),
  9572. getApi: getApi,
  9573. disabled: spec.disabled,
  9574. onAction: spec.onAction,
  9575. onSetup: spec.onSetup,
  9576. triggersSubmenu: false,
  9577. itemBehaviours: []
  9578. }, structure, itemResponse);
  9579. };
  9580. var renderNestedItem = function (spec, itemResponse, providersBackstage, renderIcons) {
  9581. if (renderIcons === void 0) {
  9582. renderIcons = true;
  9583. }
  9584. var caret = renderSubmenuCaret(providersBackstage.icons);
  9585. var getApi = function (component) {
  9586. return {
  9587. isDisabled: function () {
  9588. return Disabling.isDisabled(component);
  9589. },
  9590. setDisabled: function (state) {
  9591. return state ? Disabling.disable(component) : Disabling.enable(component);
  9592. }
  9593. };
  9594. };
  9595. var structure = renderItemStructure({
  9596. presets: 'normal',
  9597. iconContent: spec.icon,
  9598. textContent: spec.text,
  9599. ariaLabel: spec.text,
  9600. caret: Option.some(caret),
  9601. checkMark: Option.none(),
  9602. shortcutContent: spec.shortcut
  9603. }, providersBackstage, renderIcons);
  9604. return renderCommonItem({
  9605. data: buildData(spec),
  9606. getApi: getApi,
  9607. disabled: spec.disabled,
  9608. onAction: noop,
  9609. onSetup: spec.onSetup,
  9610. triggersSubmenu: true,
  9611. itemBehaviours: []
  9612. }, structure, itemResponse);
  9613. };
  9614. var renderSeparatorItem = function (spec) {
  9615. var innerHtml = spec.text.fold(function () {
  9616. return {};
  9617. }, function (text) {
  9618. return { innerHtml: text };
  9619. });
  9620. return {
  9621. type: 'separator',
  9622. dom: __assign({
  9623. tag: 'div',
  9624. classes: [
  9625. selectableClass,
  9626. groupHeadingClass
  9627. ]
  9628. }, innerHtml),
  9629. components: []
  9630. };
  9631. };
  9632. var renderToggleMenuItem = function (spec, itemResponse, providersBackstage) {
  9633. var getApi = function (component) {
  9634. return {
  9635. setActive: function (state) {
  9636. Toggling.set(component, state);
  9637. },
  9638. isActive: function () {
  9639. return Toggling.isOn(component);
  9640. },
  9641. isDisabled: function () {
  9642. return Disabling.isDisabled(component);
  9643. },
  9644. setDisabled: function (state) {
  9645. return state ? Disabling.disable(component) : Disabling.enable(component);
  9646. }
  9647. };
  9648. };
  9649. var structure = renderItemStructure({
  9650. iconContent: Option.none(),
  9651. textContent: spec.text,
  9652. ariaLabel: spec.text,
  9653. checkMark: Option.some(renderCheckmark(providersBackstage.icons)),
  9654. caret: Option.none(),
  9655. shortcutContent: spec.shortcut,
  9656. presets: 'normal',
  9657. meta: spec.meta
  9658. }, providersBackstage, true);
  9659. return deepMerge(renderCommonItem({
  9660. data: buildData(spec),
  9661. disabled: spec.disabled,
  9662. getApi: getApi,
  9663. onAction: spec.onAction,
  9664. onSetup: spec.onSetup,
  9665. triggersSubmenu: false,
  9666. itemBehaviours: []
  9667. }, structure, itemResponse), {
  9668. toggling: {
  9669. toggleClass: tickedClass,
  9670. toggleOnExecute: false,
  9671. selected: spec.active
  9672. }
  9673. });
  9674. };
  9675. var choice = renderChoiceItem;
  9676. var autocomplete = renderAutocompleteItem;
  9677. var separator = renderSeparatorItem;
  9678. var normal = renderNormalItem;
  9679. var nested = renderNestedItem;
  9680. var toggle$1 = renderToggleMenuItem;
  9681. var fancy = renderFancyMenuItem;
  9682. var forMenu = function (presets) {
  9683. if (presets === 'color') {
  9684. return 'tox-swatches';
  9685. } else {
  9686. return 'tox-menu';
  9687. }
  9688. };
  9689. var classes = function (presets) {
  9690. return {
  9691. backgroundMenu: 'tox-background-menu',
  9692. selectedMenu: 'tox-selected-menu',
  9693. selectedItem: 'tox-collection__item--active',
  9694. hasIcons: 'tox-menu--has-icons',
  9695. menu: forMenu(presets),
  9696. tieredMenu: 'tox-tiered-menu'
  9697. };
  9698. };
  9699. var markers$1 = function (presets) {
  9700. var menuClasses = classes(presets);
  9701. return {
  9702. backgroundMenu: menuClasses.backgroundMenu,
  9703. selectedMenu: menuClasses.selectedMenu,
  9704. menu: menuClasses.menu,
  9705. selectedItem: menuClasses.selectedItem,
  9706. item: classForPreset(presets)
  9707. };
  9708. };
  9709. var dom$1 = function (hasIcons, columns, presets) {
  9710. var menuClasses = classes(presets);
  9711. return {
  9712. tag: 'div',
  9713. classes: flatten([
  9714. [
  9715. menuClasses.menu,
  9716. 'tox-menu-' + columns + '-column'
  9717. ],
  9718. hasIcons ? [menuClasses.hasIcons] : []
  9719. ])
  9720. };
  9721. };
  9722. var components$1 = [Menu.parts().items({})];
  9723. var part = function (hasIcons, columns, presets) {
  9724. var menuClasses = classes(presets);
  9725. var d = {
  9726. tag: 'div',
  9727. classes: flatten([[menuClasses.tieredMenu]])
  9728. };
  9729. return {
  9730. dom: d,
  9731. markers: markers$1(presets)
  9732. };
  9733. };
  9734. var deriveMenuMovement = function (columns, presets) {
  9735. var menuMarkers = markers$1(presets);
  9736. if (columns === 1) {
  9737. return {
  9738. mode: 'menu',
  9739. moveOnTab: true
  9740. };
  9741. } else if (columns === 'auto') {
  9742. return {
  9743. mode: 'grid',
  9744. selector: '.' + menuMarkers.item,
  9745. initSize: {
  9746. numColumns: 1,
  9747. numRows: 1
  9748. }
  9749. };
  9750. } else {
  9751. var rowClass = presets === 'color' ? 'tox-swatches__row' : 'tox-collection__group';
  9752. return {
  9753. mode: 'matrix',
  9754. rowSelector: '.' + rowClass
  9755. };
  9756. }
  9757. };
  9758. var deriveCollectionMovement = function (columns, presets) {
  9759. if (columns === 1) {
  9760. return {
  9761. mode: 'menu',
  9762. moveOnTab: false,
  9763. selector: '.tox-collection__item'
  9764. };
  9765. } else if (columns === 'auto') {
  9766. return {
  9767. mode: 'flatgrid',
  9768. selector: '.' + 'tox-collection__item',
  9769. initSize: {
  9770. numColumns: 1,
  9771. numRows: 1
  9772. }
  9773. };
  9774. } else {
  9775. return {
  9776. mode: 'matrix',
  9777. selectors: {
  9778. row: presets === 'color' ? '.tox-swatches__row' : '.tox-collection__group',
  9779. cell: presets === 'color' ? '.' + colorClass : '.' + selectableClass
  9780. }
  9781. };
  9782. }
  9783. };
  9784. var chunk$1 = function (rowDom, numColumns) {
  9785. return function (items) {
  9786. var chunks = chunk(items, numColumns);
  9787. return map(chunks, function (c) {
  9788. return {
  9789. dom: rowDom,
  9790. components: c
  9791. };
  9792. });
  9793. };
  9794. };
  9795. var forSwatch = function (columns) {
  9796. return {
  9797. dom: {
  9798. tag: 'div',
  9799. classes: ['tox-menu']
  9800. },
  9801. components: [{
  9802. dom: {
  9803. tag: 'div',
  9804. classes: ['tox-swatches']
  9805. },
  9806. components: [Menu.parts().items({
  9807. preprocess: columns !== 'auto' ? chunk$1({
  9808. tag: 'div',
  9809. classes: ['tox-swatches__row']
  9810. }, columns) : identity
  9811. })]
  9812. }]
  9813. };
  9814. };
  9815. var forToolbar = function (columns) {
  9816. return {
  9817. dom: {
  9818. tag: 'div',
  9819. classes: [
  9820. 'tox-menu',
  9821. 'tox-collection',
  9822. 'tox-collection--toolbar',
  9823. 'tox-collection--toolbar-lg'
  9824. ]
  9825. },
  9826. components: [Menu.parts().items({
  9827. preprocess: chunk$1({
  9828. tag: 'div',
  9829. classes: ['tox-collection__group']
  9830. }, columns)
  9831. })]
  9832. };
  9833. };
  9834. var preprocessCollection = function (items, isSeparator) {
  9835. var allSplits = [];
  9836. var currentSplit = [];
  9837. each(items, function (item, i) {
  9838. if (isSeparator(item, i)) {
  9839. if (currentSplit.length > 0) {
  9840. allSplits.push(currentSplit);
  9841. }
  9842. currentSplit = [];
  9843. if (has(item.dom, 'innerHtml')) {
  9844. currentSplit.push(item);
  9845. }
  9846. } else {
  9847. currentSplit.push(item);
  9848. }
  9849. });
  9850. if (currentSplit.length > 0) {
  9851. allSplits.push(currentSplit);
  9852. }
  9853. return map(allSplits, function (s) {
  9854. return {
  9855. dom: {
  9856. tag: 'div',
  9857. classes: ['tox-collection__group']
  9858. },
  9859. components: s
  9860. };
  9861. });
  9862. };
  9863. var forCollection = function (columns, initItems, hasIcons) {
  9864. if (hasIcons === void 0) {
  9865. hasIcons = true;
  9866. }
  9867. return {
  9868. dom: {
  9869. tag: 'div',
  9870. classes: [
  9871. 'tox-menu',
  9872. 'tox-collection'
  9873. ].concat(columns === 1 ? ['tox-collection--list'] : ['tox-collection--grid'])
  9874. },
  9875. components: [Menu.parts().items({
  9876. preprocess: function (items) {
  9877. if (columns !== 'auto' && columns > 1) {
  9878. return chunk$1({
  9879. tag: 'div',
  9880. classes: ['tox-collection__group']
  9881. }, columns)(items);
  9882. } else {
  9883. return preprocessCollection(items, function (item, i) {
  9884. return initItems[i].type === 'separator';
  9885. });
  9886. }
  9887. }
  9888. })]
  9889. };
  9890. };
  9891. var FocusMode;
  9892. (function (FocusMode) {
  9893. FocusMode[FocusMode['ContentFocus'] = 0] = 'ContentFocus';
  9894. FocusMode[FocusMode['UiFocus'] = 1] = 'UiFocus';
  9895. }(FocusMode || (FocusMode = {})));
  9896. var handleError = function (error) {
  9897. console.error(formatError(error));
  9898. console.log(error);
  9899. return Option.none();
  9900. };
  9901. var hasIcon = function (item) {
  9902. return item.icon !== undefined || item.type === 'togglemenuitem' || item.type === 'choicemenuitem';
  9903. };
  9904. var menuHasIcons = function (xs) {
  9905. return exists(xs, hasIcon);
  9906. };
  9907. var createMenuItemFromBridge = function (item, itemResponse, providersBackstage, menuHasIcons) {
  9908. if (menuHasIcons === void 0) {
  9909. menuHasIcons = true;
  9910. }
  9911. switch (item.type) {
  9912. case 'menuitem':
  9913. return createMenuItem(item).fold(handleError, function (d) {
  9914. return Option.some(normal(d, itemResponse, providersBackstage, menuHasIcons));
  9915. });
  9916. case 'nestedmenuitem':
  9917. return createNestedMenuItem(item).fold(handleError, function (d) {
  9918. return Option.some(nested(d, itemResponse, providersBackstage, menuHasIcons));
  9919. });
  9920. case 'togglemenuitem':
  9921. return createToggleMenuItem(item).fold(handleError, function (d) {
  9922. return Option.some(toggle$1(d, itemResponse, providersBackstage));
  9923. });
  9924. case 'separator':
  9925. return createSeparatorMenuItem(item).fold(handleError, function (d) {
  9926. return Option.some(separator(d));
  9927. });
  9928. case 'fancymenuitem':
  9929. return createFancyMenuItem(item).fold(handleError, function (d) {
  9930. return fancy(d);
  9931. });
  9932. default: {
  9933. console.error('Unknown item in general menu', item);
  9934. return Option.none();
  9935. }
  9936. }
  9937. };
  9938. var createPartialMenuWithAlloyItems = function (value, hasIcons, items, columns, presets) {
  9939. if (presets === 'color') {
  9940. var structure = forSwatch(columns);
  9941. return {
  9942. value: value,
  9943. dom: structure.dom,
  9944. components: structure.components,
  9945. items: items
  9946. };
  9947. }
  9948. if (presets === 'normal' && columns === 'auto') {
  9949. var structure = forCollection(columns, items);
  9950. return {
  9951. value: value,
  9952. dom: structure.dom,
  9953. components: structure.components,
  9954. items: items
  9955. };
  9956. }
  9957. if (presets === 'normal' && columns === 1) {
  9958. var structure = forCollection(1, items);
  9959. return {
  9960. value: value,
  9961. dom: structure.dom,
  9962. components: structure.components,
  9963. items: items
  9964. };
  9965. }
  9966. if (presets === 'normal') {
  9967. var structure = forCollection(columns, items);
  9968. return {
  9969. value: value,
  9970. dom: structure.dom,
  9971. components: structure.components,
  9972. items: items
  9973. };
  9974. }
  9975. if (presets === 'listpreview' && columns !== 'auto') {
  9976. var structure = forToolbar(columns);
  9977. return {
  9978. value: value,
  9979. dom: structure.dom,
  9980. components: structure.components,
  9981. items: items
  9982. };
  9983. }
  9984. return {
  9985. value: value,
  9986. dom: dom$1(hasIcons, columns, presets),
  9987. components: components$1,
  9988. items: items
  9989. };
  9990. };
  9991. var createChoiceItems = function (items, onItemValueHandler, columns, itemPresets, itemResponse, select, providersBackstage) {
  9992. return cat(map(items, function (item) {
  9993. if (item.type === 'choiceitem') {
  9994. return createChoiceMenuItem(item).fold(handleError, function (d) {
  9995. return Option.some(choice(d, columns === 1, itemPresets, onItemValueHandler, select(item.value), itemResponse, providersBackstage));
  9996. });
  9997. } else {
  9998. return Option.none();
  9999. }
  10000. }));
  10001. };
  10002. var createAutocompleteItems = function (items, onItemValueHandler, columns, itemResponse, sharedBackstage) {
  10003. var renderText = columns === 1;
  10004. var renderIcons = !renderText || menuHasIcons(items);
  10005. return cat(map(items, function (item) {
  10006. return createAutocompleterItem(item).fold(handleError, function (d) {
  10007. return Option.some(autocomplete(d, renderText, 'normal', onItemValueHandler, itemResponse, sharedBackstage, renderIcons));
  10008. });
  10009. }));
  10010. };
  10011. var createPartialChoiceMenu = function (value, items, onItemValueHandler, columns, presets, itemResponse, select, providersBackstage) {
  10012. var hasIcons = menuHasIcons(items);
  10013. var presetItemTypes = presets !== 'color' ? 'normal' : 'color';
  10014. var alloyItems = createChoiceItems(items, onItemValueHandler, columns, presetItemTypes, itemResponse, select, providersBackstage);
  10015. return createPartialMenuWithAlloyItems(value, hasIcons, alloyItems, columns, presets);
  10016. };
  10017. var createPartialMenu = function (value, items, itemResponse, providersBackstage) {
  10018. var hasIcons = menuHasIcons(items);
  10019. var alloyItems = cat(map(items, function (item) {
  10020. return createMenuItemFromBridge(item, itemResponse, providersBackstage, hasIcons);
  10021. }));
  10022. return createPartialMenuWithAlloyItems(value, hasIcons, alloyItems, 1, 'normal');
  10023. };
  10024. var createTieredDataFrom = function (partialMenu) {
  10025. return tieredMenu.singleData(partialMenu.value, partialMenu);
  10026. };
  10027. var createMenuFrom = function (partialMenu, columns, focusMode, presets) {
  10028. var focusManager = focusMode === FocusMode.ContentFocus ? highlights() : dom();
  10029. var movement = deriveMenuMovement(columns, presets);
  10030. var menuMarkers = markers$1(presets);
  10031. return {
  10032. dom: partialMenu.dom,
  10033. components: partialMenu.components,
  10034. items: partialMenu.items,
  10035. value: partialMenu.value,
  10036. markers: {
  10037. selectedItem: menuMarkers.selectedItem,
  10038. item: menuMarkers.item
  10039. },
  10040. movement: movement,
  10041. fakeFocus: focusMode === FocusMode.ContentFocus,
  10042. focusManager: focusManager,
  10043. menuBehaviours: SimpleBehaviours.unnamedEvents(columns !== 'auto' ? [] : [runOnAttached(function (comp, se) {
  10044. detectSize(comp, 4, menuMarkers.item).each(function (_a) {
  10045. var numColumns = _a.numColumns, numRows = _a.numRows;
  10046. Keying.setGridSize(comp, numRows, numColumns);
  10047. });
  10048. })])
  10049. };
  10050. };
  10051. var register$1 = function (editor, sharedBackstage) {
  10052. var autocompleter = build$1(InlineView.sketch({
  10053. dom: {
  10054. tag: 'div',
  10055. classes: ['tox-autocompleter']
  10056. },
  10057. components: [],
  10058. lazySink: sharedBackstage.getSink
  10059. }));
  10060. var isActive = function () {
  10061. return InlineView.isOpen(autocompleter);
  10062. };
  10063. var closeIfNecessary = function () {
  10064. if (isActive()) {
  10065. InlineView.hide(autocompleter);
  10066. }
  10067. };
  10068. var getAutocompleters = cached(function () {
  10069. return register(editor);
  10070. });
  10071. var getCombinedItems = function (triggerChar, matches) {
  10072. var columns = findMap(matches, function (m) {
  10073. return Option.from(m.columns);
  10074. }).getOr(1);
  10075. return bind(matches, function (match) {
  10076. var choices = match.items;
  10077. return createAutocompleteItems(choices, function (itemValue, itemMeta) {
  10078. var nr = editor.selection.getRng();
  10079. var textNode = nr.startContainer;
  10080. getContext(nr, triggerChar, textNode.data, nr.startOffset).fold(function () {
  10081. return console.error('Lost context. Cursor probably moved');
  10082. }, function (_a) {
  10083. var rng = _a.rng;
  10084. var autocompleterApi = { hide: closeIfNecessary };
  10085. match.onAction(autocompleterApi, rng, itemValue, itemMeta);
  10086. });
  10087. }, columns, ItemResponse$1.BUBBLE_TO_SANDBOX, sharedBackstage);
  10088. });
  10089. };
  10090. var onKeypress = last$2(function (e) {
  10091. var optMatches = e.key === ' ' ? Option.none() : lookup(editor, getAutocompleters);
  10092. optMatches.fold(closeIfNecessary, function (lookupInfo) {
  10093. lookupInfo.lookupData.then(function (lookupData) {
  10094. var combinedItems = getCombinedItems(lookupInfo.triggerChar, lookupData);
  10095. if (combinedItems.length > 0) {
  10096. var columns = findMap(lookupData, function (ld) {
  10097. return Option.from(ld.columns);
  10098. }).getOr(1);
  10099. InlineView.showAt(autocompleter, {
  10100. anchor: 'selection',
  10101. root: Element.fromDom(editor.getBody()),
  10102. getSelection: function () {
  10103. return Option.some({
  10104. start: function () {
  10105. return Element.fromDom(lookupInfo.range.startContainer);
  10106. },
  10107. soffset: function () {
  10108. return lookupInfo.range.startOffset;
  10109. },
  10110. finish: function () {
  10111. return Element.fromDom(lookupInfo.range.endContainer);
  10112. },
  10113. foffset: function () {
  10114. return lookupInfo.range.endOffset;
  10115. }
  10116. });
  10117. }
  10118. }, Menu.sketch(createMenuFrom(createPartialMenuWithAlloyItems('autocompleter-value', true, combinedItems, columns, 'normal'), columns, FocusMode.ContentFocus, 'normal')));
  10119. InlineView.getContent(autocompleter).each(Highlighting.highlightFirst);
  10120. } else {
  10121. closeIfNecessary();
  10122. }
  10123. });
  10124. });
  10125. }, 50);
  10126. var autocompleterUiApi = {
  10127. onKeypress: onKeypress,
  10128. closeIfNecessary: closeIfNecessary,
  10129. isActive: isActive,
  10130. getView: function () {
  10131. return InlineView.getContent(autocompleter);
  10132. }
  10133. };
  10134. AutocompleterEditorEvents.setup(autocompleterUiApi, editor);
  10135. };
  10136. var Autocompleter = { register: register$1 };
  10137. var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
  10138. return {
  10139. target: constant(target),
  10140. x: constant(x),
  10141. y: constant(y),
  10142. stop: stop,
  10143. prevent: prevent,
  10144. kill: kill,
  10145. raw: constant(raw)
  10146. };
  10147. };
  10148. var handle = function (filter, handler) {
  10149. return function (rawEvent) {
  10150. if (!filter(rawEvent)) {
  10151. return;
  10152. }
  10153. var target = Element.fromDom(rawEvent.target);
  10154. var stop = function () {
  10155. rawEvent.stopPropagation();
  10156. };
  10157. var prevent = function () {
  10158. rawEvent.preventDefault();
  10159. };
  10160. var kill = compose(prevent, stop);
  10161. var evt = mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
  10162. handler(evt);
  10163. };
  10164. };
  10165. var binder = function (element, event, filter, handler, useCapture) {
  10166. var wrapped = handle(filter, handler);
  10167. element.dom().addEventListener(event, wrapped, useCapture);
  10168. return { unbind: curry(unbind, element, event, wrapped, useCapture) };
  10169. };
  10170. var bind$2 = function (element, event, filter, handler) {
  10171. return binder(element, event, filter, handler, false);
  10172. };
  10173. var capture = function (element, event, filter, handler) {
  10174. return binder(element, event, filter, handler, true);
  10175. };
  10176. var unbind = function (element, event, handler, useCapture) {
  10177. element.dom().removeEventListener(event, handler, useCapture);
  10178. };
  10179. var filter$1 = constant(true);
  10180. var bind$3 = function (element, event, handler) {
  10181. return bind$2(element, event, filter$1, handler);
  10182. };
  10183. var capture$1 = function (element, event, handler) {
  10184. return capture(element, event, filter$1, handler);
  10185. };
  10186. var closest$4 = function (scope, selector, isRoot) {
  10187. return closest$3(scope, selector, isRoot).isSome();
  10188. };
  10189. function DelayedFunction (fun, delay) {
  10190. var ref = null;
  10191. var schedule = function () {
  10192. var args = [];
  10193. for (var _i = 0; _i < arguments.length; _i++) {
  10194. args[_i] = arguments[_i];
  10195. }
  10196. ref = domGlobals.setTimeout(function () {
  10197. fun.apply(null, args);
  10198. ref = null;
  10199. }, delay);
  10200. };
  10201. var cancel = function () {
  10202. if (ref !== null) {
  10203. domGlobals.clearTimeout(ref);
  10204. ref = null;
  10205. }
  10206. };
  10207. return {
  10208. cancel: cancel,
  10209. schedule: schedule
  10210. };
  10211. }
  10212. var SIGNIFICANT_MOVE = 5;
  10213. var LONGPRESS_DELAY = 400;
  10214. var getTouch = function (event) {
  10215. var raw = event.raw();
  10216. if (raw.touches === undefined || raw.touches.length !== 1) {
  10217. return Option.none();
  10218. }
  10219. return Option.some(raw.touches[0]);
  10220. };
  10221. var isFarEnough = function (touch, data) {
  10222. var distX = Math.abs(touch.clientX - data.x());
  10223. var distY = Math.abs(touch.clientY - data.y());
  10224. return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
  10225. };
  10226. var monitor = function (settings) {
  10227. var startData = Cell(Option.none());
  10228. var longpress$1 = DelayedFunction(function (event) {
  10229. startData.set(Option.none());
  10230. settings.triggerEvent(longpress(), event);
  10231. }, LONGPRESS_DELAY);
  10232. var handleTouchstart = function (event) {
  10233. getTouch(event).each(function (touch) {
  10234. longpress$1.cancel();
  10235. var data = {
  10236. x: constant(touch.clientX),
  10237. y: constant(touch.clientY),
  10238. target: event.target
  10239. };
  10240. longpress$1.schedule(event);
  10241. startData.set(Option.some(data));
  10242. });
  10243. return Option.none();
  10244. };
  10245. var handleTouchmove = function (event) {
  10246. longpress$1.cancel();
  10247. getTouch(event).each(function (touch) {
  10248. startData.get().each(function (data) {
  10249. if (isFarEnough(touch, data)) {
  10250. startData.set(Option.none());
  10251. }
  10252. });
  10253. });
  10254. return Option.none();
  10255. };
  10256. var handleTouchend = function (event) {
  10257. longpress$1.cancel();
  10258. var isSame = function (data) {
  10259. return eq(data.target(), event.target());
  10260. };
  10261. return startData.get().filter(isSame).map(function (data) {
  10262. return settings.triggerEvent(tap(), event);
  10263. });
  10264. };
  10265. var handlers = wrapAll$1([
  10266. {
  10267. key: touchstart(),
  10268. value: handleTouchstart
  10269. },
  10270. {
  10271. key: touchmove(),
  10272. value: handleTouchmove
  10273. },
  10274. {
  10275. key: touchend(),
  10276. value: handleTouchend
  10277. }
  10278. ]);
  10279. var fireIfReady = function (event, type) {
  10280. return readOptFrom$1(handlers, type).bind(function (handler) {
  10281. return handler(event);
  10282. });
  10283. };
  10284. return { fireIfReady: fireIfReady };
  10285. };
  10286. var isDangerous = function (event) {
  10287. var keyEv = event.raw();
  10288. return keyEv.which === BACKSPACE()[0] && !contains([
  10289. 'input',
  10290. 'textarea'
  10291. ], name(event.target())) && !closest$4(event.target(), '[contenteditable="true"]');
  10292. };
  10293. var isFirefox = PlatformDetection$1.detect().browser.isFirefox();
  10294. var settingsSchema = objOfOnly([
  10295. strictFunction('triggerEvent'),
  10296. defaulted$1('stopBackspace', true)
  10297. ]);
  10298. var bindFocus = function (container, handler) {
  10299. if (isFirefox) {
  10300. return capture$1(container, 'focus', handler);
  10301. } else {
  10302. return bind$3(container, 'focusin', handler);
  10303. }
  10304. };
  10305. var bindBlur = function (container, handler) {
  10306. if (isFirefox) {
  10307. return capture$1(container, 'blur', handler);
  10308. } else {
  10309. return bind$3(container, 'focusout', handler);
  10310. }
  10311. };
  10312. var setup$1 = function (container, rawSettings) {
  10313. var settings = asRawOrDie('Getting GUI events settings', settingsSchema, rawSettings);
  10314. var pointerEvents = PlatformDetection$1.detect().deviceType.isTouch() ? [
  10315. 'touchstart',
  10316. 'touchmove',
  10317. 'touchend',
  10318. 'gesturestart'
  10319. ] : [
  10320. 'mousedown',
  10321. 'mouseup',
  10322. 'mouseover',
  10323. 'mousemove',
  10324. 'mouseout',
  10325. 'click'
  10326. ];
  10327. var tapEvent = monitor(settings);
  10328. var simpleEvents = map(pointerEvents.concat([
  10329. 'selectstart',
  10330. 'input',
  10331. 'contextmenu',
  10332. 'change',
  10333. 'transitionend',
  10334. 'drag',
  10335. 'dragstart',
  10336. 'dragend',
  10337. 'dragenter',
  10338. 'dragleave',
  10339. 'dragover',
  10340. 'drop',
  10341. 'keyup'
  10342. ]), function (type) {
  10343. return bind$3(container, type, function (event) {
  10344. tapEvent.fireIfReady(event, type).each(function (tapStopped) {
  10345. if (tapStopped) {
  10346. event.kill();
  10347. }
  10348. });
  10349. var stopped = settings.triggerEvent(type, event);
  10350. if (stopped) {
  10351. event.kill();
  10352. }
  10353. });
  10354. });
  10355. var pasteTimeout = Cell(Option.none());
  10356. var onPaste = bind$3(container, 'paste', function (event) {
  10357. tapEvent.fireIfReady(event, 'paste').each(function (tapStopped) {
  10358. if (tapStopped) {
  10359. event.kill();
  10360. }
  10361. });
  10362. var stopped = settings.triggerEvent('paste', event);
  10363. if (stopped) {
  10364. event.kill();
  10365. }
  10366. pasteTimeout.set(Option.some(domGlobals.setTimeout(function () {
  10367. settings.triggerEvent(postPaste(), event);
  10368. }, 0)));
  10369. });
  10370. var onKeydown = bind$3(container, 'keydown', function (event) {
  10371. var stopped = settings.triggerEvent('keydown', event);
  10372. if (stopped) {
  10373. event.kill();
  10374. } else if (settings.stopBackspace === true && isDangerous(event)) {
  10375. event.prevent();
  10376. }
  10377. });
  10378. var onFocusIn = bindFocus(container, function (event) {
  10379. var stopped = settings.triggerEvent('focusin', event);
  10380. if (stopped) {
  10381. event.kill();
  10382. }
  10383. });
  10384. var focusoutTimeout = Cell(Option.none());
  10385. var onFocusOut = bindBlur(container, function (event) {
  10386. var stopped = settings.triggerEvent('focusout', event);
  10387. if (stopped) {
  10388. event.kill();
  10389. }
  10390. focusoutTimeout.set(Option.some(domGlobals.setTimeout(function () {
  10391. settings.triggerEvent(postBlur(), event);
  10392. }, 0)));
  10393. });
  10394. var unbind = function () {
  10395. each(simpleEvents, function (e) {
  10396. e.unbind();
  10397. });
  10398. onKeydown.unbind();
  10399. onFocusIn.unbind();
  10400. onFocusOut.unbind();
  10401. onPaste.unbind();
  10402. pasteTimeout.get().each(domGlobals.clearTimeout);
  10403. focusoutTimeout.get().each(domGlobals.clearTimeout);
  10404. };
  10405. return { unbind: unbind };
  10406. };
  10407. var derive$2 = function (rawEvent, rawTarget) {
  10408. var source = readOptFrom$1(rawEvent, 'target').map(function (getTarget) {
  10409. return getTarget();
  10410. }).getOr(rawTarget);
  10411. return Cell(source);
  10412. };
  10413. var fromSource = function (event, source) {
  10414. var stopper = Cell(false);
  10415. var cutter = Cell(false);
  10416. var stop = function () {
  10417. stopper.set(true);
  10418. };
  10419. var cut = function () {
  10420. cutter.set(true);
  10421. };
  10422. return {
  10423. stop: stop,
  10424. cut: cut,
  10425. isStopped: stopper.get,
  10426. isCut: cutter.get,
  10427. event: constant(event),
  10428. setSource: source.set,
  10429. getSource: source.get
  10430. };
  10431. };
  10432. var fromExternal = function (event) {
  10433. var stopper = Cell(false);
  10434. var stop = function () {
  10435. stopper.set(true);
  10436. };
  10437. return {
  10438. stop: stop,
  10439. cut: noop,
  10440. isStopped: stopper.get,
  10441. isCut: constant(false),
  10442. event: constant(event),
  10443. setSource: die('Cannot set source of a broadcasted event'),
  10444. getSource: die('Cannot get source of a broadcasted event')
  10445. };
  10446. };
  10447. var adt$a = Adt.generate([
  10448. { stopped: [] },
  10449. { resume: ['element'] },
  10450. { complete: [] }
  10451. ]);
  10452. var doTriggerHandler = function (lookup, eventType, rawEvent, target, source, logger) {
  10453. var handler = lookup(eventType, target);
  10454. var simulatedEvent = fromSource(rawEvent, source);
  10455. return handler.fold(function () {
  10456. logger.logEventNoHandlers(eventType, target);
  10457. return adt$a.complete();
  10458. }, function (handlerInfo) {
  10459. var descHandler = handlerInfo.descHandler();
  10460. var eventHandler = getCurried(descHandler);
  10461. eventHandler(simulatedEvent);
  10462. if (simulatedEvent.isStopped()) {
  10463. logger.logEventStopped(eventType, handlerInfo.element(), descHandler.purpose());
  10464. return adt$a.stopped();
  10465. } else if (simulatedEvent.isCut()) {
  10466. logger.logEventCut(eventType, handlerInfo.element(), descHandler.purpose());
  10467. return adt$a.complete();
  10468. } else {
  10469. return parent(handlerInfo.element()).fold(function () {
  10470. logger.logNoParent(eventType, handlerInfo.element(), descHandler.purpose());
  10471. return adt$a.complete();
  10472. }, function (parent) {
  10473. logger.logEventResponse(eventType, handlerInfo.element(), descHandler.purpose());
  10474. return adt$a.resume(parent);
  10475. });
  10476. }
  10477. });
  10478. };
  10479. var doTriggerOnUntilStopped = function (lookup, eventType, rawEvent, rawTarget, source, logger) {
  10480. return doTriggerHandler(lookup, eventType, rawEvent, rawTarget, source, logger).fold(function () {
  10481. return true;
  10482. }, function (parent) {
  10483. return doTriggerOnUntilStopped(lookup, eventType, rawEvent, parent, source, logger);
  10484. }, function () {
  10485. return false;
  10486. });
  10487. };
  10488. var triggerHandler = function (lookup, eventType, rawEvent, target, logger) {
  10489. var source = derive$2(rawEvent, target);
  10490. return doTriggerHandler(lookup, eventType, rawEvent, target, source, logger);
  10491. };
  10492. var broadcast = function (listeners, rawEvent, logger) {
  10493. var simulatedEvent = fromExternal(rawEvent);
  10494. each(listeners, function (listener) {
  10495. var descHandler = listener.descHandler();
  10496. var handler = getCurried(descHandler);
  10497. handler(simulatedEvent);
  10498. });
  10499. return simulatedEvent.isStopped();
  10500. };
  10501. var triggerUntilStopped = function (lookup, eventType, rawEvent, logger) {
  10502. var rawTarget = rawEvent.target();
  10503. return triggerOnUntilStopped(lookup, eventType, rawEvent, rawTarget, logger);
  10504. };
  10505. var triggerOnUntilStopped = function (lookup, eventType, rawEvent, rawTarget, logger) {
  10506. var source = derive$2(rawEvent, rawTarget);
  10507. return doTriggerOnUntilStopped(lookup, eventType, rawEvent, rawTarget, source, logger);
  10508. };
  10509. var eventHandler = Immutable('element', 'descHandler');
  10510. var broadcastHandler = function (id, handler) {
  10511. return {
  10512. id: constant(id),
  10513. descHandler: constant(handler)
  10514. };
  10515. };
  10516. function EventRegistry () {
  10517. var registry = {};
  10518. var registerId = function (extraArgs, id, events) {
  10519. each$1(events, function (v, k) {
  10520. var handlers = registry[k] !== undefined ? registry[k] : {};
  10521. handlers[id] = curryArgs(v, extraArgs);
  10522. registry[k] = handlers;
  10523. });
  10524. };
  10525. var findHandler = function (handlers, elem) {
  10526. return read$1(elem).fold(function () {
  10527. return Option.none();
  10528. }, function (id) {
  10529. var reader = readOpt$1(id);
  10530. return handlers.bind(reader).map(function (descHandler) {
  10531. return eventHandler(elem, descHandler);
  10532. });
  10533. });
  10534. };
  10535. var filterByType = function (type) {
  10536. return readOptFrom$1(registry, type).map(function (handlers) {
  10537. return mapToArray(handlers, function (f, id) {
  10538. return broadcastHandler(id, f);
  10539. });
  10540. }).getOr([]);
  10541. };
  10542. var find = function (isAboveRoot, type, target) {
  10543. var readType = readOpt$1(type);
  10544. var handlers = readType(registry);
  10545. return closest$1(target, function (elem) {
  10546. return findHandler(handlers, elem);
  10547. }, isAboveRoot);
  10548. };
  10549. var unregisterId = function (id) {
  10550. each$1(registry, function (handlersById, eventName) {
  10551. if (handlersById.hasOwnProperty(id)) {
  10552. delete handlersById[id];
  10553. }
  10554. });
  10555. };
  10556. return {
  10557. registerId: registerId,
  10558. unregisterId: unregisterId,
  10559. filterByType: filterByType,
  10560. find: find
  10561. };
  10562. }
  10563. function Registry () {
  10564. var events = EventRegistry();
  10565. var components = {};
  10566. var readOrTag = function (component) {
  10567. var elem = component.element();
  10568. return read$1(elem).fold(function () {
  10569. return write('uid-', component.element());
  10570. }, function (uid) {
  10571. return uid;
  10572. });
  10573. };
  10574. var failOnDuplicate = function (component, tagId) {
  10575. var conflict = components[tagId];
  10576. if (conflict === component) {
  10577. unregister(component);
  10578. } else {
  10579. throw new Error('The tagId "' + tagId + '" is already used by: ' + element(conflict.element()) + '\nCannot use it for: ' + element(component.element()) + '\n' + 'The conflicting element is' + (inBody(conflict.element()) ? ' ' : ' not ') + 'already in the DOM');
  10580. }
  10581. };
  10582. var register = function (component) {
  10583. var tagId = readOrTag(component);
  10584. if (hasKey$1(components, tagId)) {
  10585. failOnDuplicate(component, tagId);
  10586. }
  10587. var extraArgs = [component];
  10588. events.registerId(extraArgs, tagId, component.events());
  10589. components[tagId] = component;
  10590. };
  10591. var unregister = function (component) {
  10592. read$1(component.element()).each(function (tagId) {
  10593. components[tagId] = undefined;
  10594. events.unregisterId(tagId);
  10595. });
  10596. };
  10597. var filter = function (type) {
  10598. return events.filterByType(type);
  10599. };
  10600. var find = function (isAboveRoot, type, target) {
  10601. return events.find(isAboveRoot, type, target);
  10602. };
  10603. var getById = function (id) {
  10604. return readOpt$1(id)(components);
  10605. };
  10606. return {
  10607. find: find,
  10608. filter: filter,
  10609. register: register,
  10610. unregister: unregister,
  10611. getById: getById
  10612. };
  10613. }
  10614. var factory$3 = function (detail) {
  10615. var _a = detail.dom, attributes = _a.attributes, domWithoutAttributes = __rest(_a, ['attributes']);
  10616. return {
  10617. uid: detail.uid,
  10618. dom: __assign({
  10619. tag: 'div',
  10620. attributes: __assign({ role: 'presentation' }, attributes)
  10621. }, domWithoutAttributes),
  10622. components: detail.components,
  10623. behaviours: get$b(detail.containerBehaviours),
  10624. events: detail.events,
  10625. domModification: detail.domModification,
  10626. eventOrder: detail.eventOrder
  10627. };
  10628. };
  10629. var Container = single$2({
  10630. name: 'Container',
  10631. factory: factory$3,
  10632. configFields: [
  10633. defaulted$1('components', []),
  10634. field$1('containerBehaviours', []),
  10635. defaulted$1('events', {}),
  10636. defaulted$1('domModification', {}),
  10637. defaulted$1('eventOrder', {})
  10638. ]
  10639. });
  10640. var takeover = function (root) {
  10641. var isAboveRoot = function (el) {
  10642. return parent(root.element()).fold(function () {
  10643. return true;
  10644. }, function (parent) {
  10645. return eq(el, parent);
  10646. });
  10647. };
  10648. var registry = Registry();
  10649. var lookup = function (eventName, target) {
  10650. return registry.find(isAboveRoot, eventName, target);
  10651. };
  10652. var domEvents = setup$1(root.element(), {
  10653. triggerEvent: function (eventName, event) {
  10654. return monitorEvent(eventName, event.target(), function (logger) {
  10655. return triggerUntilStopped(lookup, eventName, event, logger);
  10656. });
  10657. }
  10658. });
  10659. var systemApi = {
  10660. debugInfo: constant('real'),
  10661. triggerEvent: function (eventName, target, data) {
  10662. monitorEvent(eventName, target, function (logger) {
  10663. triggerOnUntilStopped(lookup, eventName, data, target, logger);
  10664. });
  10665. },
  10666. triggerFocus: function (target, originator) {
  10667. read$1(target).fold(function () {
  10668. focus$1(target);
  10669. }, function (_alloyId) {
  10670. monitorEvent(focus(), target, function (logger) {
  10671. triggerHandler(lookup, focus(), {
  10672. originator: constant(originator),
  10673. kill: noop,
  10674. prevent: noop,
  10675. target: constant(target)
  10676. }, target, logger);
  10677. });
  10678. });
  10679. },
  10680. triggerEscape: function (comp, simulatedEvent) {
  10681. systemApi.triggerEvent('keydown', comp.element(), simulatedEvent.event());
  10682. },
  10683. getByUid: function (uid) {
  10684. return getByUid(uid);
  10685. },
  10686. getByDom: function (elem) {
  10687. return getByDom(elem);
  10688. },
  10689. build: build$1,
  10690. addToGui: function (c) {
  10691. add(c);
  10692. },
  10693. removeFromGui: function (c) {
  10694. remove$1(c);
  10695. },
  10696. addToWorld: function (c) {
  10697. addToWorld(c);
  10698. },
  10699. removeFromWorld: function (c) {
  10700. removeFromWorld(c);
  10701. },
  10702. broadcast: function (message) {
  10703. broadcast$1(message);
  10704. },
  10705. broadcastOn: function (channels, message) {
  10706. broadcastOn(channels, message);
  10707. },
  10708. broadcastEvent: function (eventName, event) {
  10709. broadcastEvent(eventName, event);
  10710. },
  10711. isConnected: constant(true)
  10712. };
  10713. var addToWorld = function (component) {
  10714. component.connect(systemApi);
  10715. if (!isText(component.element())) {
  10716. registry.register(component);
  10717. each(component.components(), addToWorld);
  10718. systemApi.triggerEvent(systemInit(), component.element(), { target: constant(component.element()) });
  10719. }
  10720. };
  10721. var removeFromWorld = function (component) {
  10722. if (!isText(component.element())) {
  10723. each(component.components(), removeFromWorld);
  10724. registry.unregister(component);
  10725. }
  10726. component.disconnect();
  10727. };
  10728. var add = function (component) {
  10729. attach(root, component);
  10730. };
  10731. var remove$1 = function (component) {
  10732. detach(component);
  10733. };
  10734. var destroy = function () {
  10735. domEvents.unbind();
  10736. remove(root.element());
  10737. };
  10738. var broadcastData = function (data) {
  10739. var receivers = registry.filter(receive());
  10740. each(receivers, function (receiver) {
  10741. var descHandler = receiver.descHandler();
  10742. var handler = getCurried(descHandler);
  10743. handler(data);
  10744. });
  10745. };
  10746. var broadcast$1 = function (message) {
  10747. broadcastData({
  10748. universal: constant(true),
  10749. data: constant(message)
  10750. });
  10751. };
  10752. var broadcastOn = function (channels, message) {
  10753. broadcastData({
  10754. universal: constant(false),
  10755. channels: constant(channels),
  10756. data: constant(message)
  10757. });
  10758. };
  10759. var broadcastEvent = function (eventName, event) {
  10760. var listeners = registry.filter(eventName);
  10761. return broadcast(listeners, event);
  10762. };
  10763. var getByUid = function (uid) {
  10764. return registry.getById(uid).fold(function () {
  10765. return Result.error(new Error('Could not find component with uid: "' + uid + '" in system.'));
  10766. }, Result.value);
  10767. };
  10768. var getByDom = function (elem) {
  10769. var uid = read$1(elem).getOr('not found');
  10770. return getByUid(uid);
  10771. };
  10772. addToWorld(root);
  10773. return {
  10774. root: constant(root),
  10775. element: root.element,
  10776. destroy: destroy,
  10777. add: add,
  10778. remove: remove$1,
  10779. getByUid: getByUid,
  10780. getByDom: getByDom,
  10781. addToWorld: addToWorld,
  10782. removeFromWorld: removeFromWorld,
  10783. broadcast: broadcast$1,
  10784. broadcastOn: broadcastOn,
  10785. broadcastEvent: broadcastEvent
  10786. };
  10787. };
  10788. var global$4 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  10789. var global$5 = tinymce.util.Tools.resolve('tinymce.EditorManager');
  10790. var getSkinUrl = function (editor) {
  10791. var settings = editor.settings;
  10792. var skin = settings.skin;
  10793. var skinUrl = settings.skin_url;
  10794. if (skin !== false) {
  10795. var skinName = skin ? skin : 'oxide';
  10796. if (skinUrl) {
  10797. skinUrl = editor.documentBaseURI.toAbsolute(skinUrl);
  10798. } else {
  10799. skinUrl = global$5.baseURL + '/skins/ui/' + skinName;
  10800. }
  10801. }
  10802. return skinUrl;
  10803. };
  10804. var isReadOnly = function (editor) {
  10805. return editor.getParam('readonly', false, 'boolean');
  10806. };
  10807. var isSkinDisabled = function (editor) {
  10808. return editor.getParam('skin') === false;
  10809. };
  10810. var getHeightSetting = function (editor) {
  10811. return editor.getParam('height', Math.max(editor.getElement().offsetHeight, 200));
  10812. };
  10813. var getMinWidthSetting = function (editor) {
  10814. return Option.from(editor.settings.min_width).filter(isNumber);
  10815. };
  10816. var getMinHeightSetting = function (editor) {
  10817. return Option.from(editor.settings.min_height).filter(isNumber);
  10818. };
  10819. var getMaxWidthSetting = function (editor) {
  10820. return Option.from(editor.getParam('max_width')).filter(isNumber);
  10821. };
  10822. var getMaxHeightSetting = function (editor) {
  10823. return Option.from(editor.getParam('max_height')).filter(isNumber);
  10824. };
  10825. var getUserStyleFormats = function (editor) {
  10826. return Option.from(editor.getParam('style_formats')).filter(isArray);
  10827. };
  10828. var isMergeStyleFormats = function (editor) {
  10829. return editor.getParam('style_formats_merge', false, 'boolean');
  10830. };
  10831. var getRemovedMenuItems = function (editor) {
  10832. return editor.getParam('removed_menuitems', '');
  10833. };
  10834. var isMenubarEnabled = function (editor) {
  10835. return editor.getParam('menubar', true, 'boolean') !== false;
  10836. };
  10837. var isToolbarEnabled = function (editor) {
  10838. var toolbarConfig = editor.getParam('toolbar');
  10839. if (isArray(toolbarConfig)) {
  10840. return toolbarConfig.length > 0;
  10841. } else {
  10842. return editor.getParam('toolbar', true, 'boolean') !== false;
  10843. }
  10844. };
  10845. var getMultipleToolbarsSetting = function (editor) {
  10846. var keys$1 = keys(editor.settings);
  10847. var toolbarKeys = filter(keys$1, function (key) {
  10848. return /^toolbar([1-9])$/.test(key);
  10849. });
  10850. var toolbars = map(toolbarKeys, function (key) {
  10851. return editor.getParam(key, false, 'string');
  10852. });
  10853. var toolbarArray = filter(toolbars, function (toolbar) {
  10854. return typeof toolbar === 'string';
  10855. });
  10856. return toolbarArray.length > 0 ? Option.some(toolbarArray) : Option.none();
  10857. };
  10858. var isSplitToolbar = function (editor) {
  10859. return editor.getParam('toolbar_drawer', false, 'boolean');
  10860. };
  10861. var formChangeEvent = generate$1('form-component-change');
  10862. var formCloseEvent = generate$1('form-close');
  10863. var formCancelEvent = generate$1('form-cancel');
  10864. var formActionEvent = generate$1('form-action');
  10865. var formSubmitEvent = generate$1('form-submit');
  10866. var formBlockEvent = generate$1('form-block');
  10867. var formUnblockEvent = generate$1('form-unblock');
  10868. var formTabChangeEvent = generate$1('form-tabchange');
  10869. var formResizeEvent = generate$1('form-resize');
  10870. var renderAlertBanner = function (spec, providersBackstage) {
  10871. return Container.sketch({
  10872. dom: {
  10873. tag: 'div',
  10874. attributes: { role: 'alert' },
  10875. classes: [
  10876. 'tox-notification',
  10877. 'tox-notification--in',
  10878. 'tox-notification--' + spec.level
  10879. ]
  10880. },
  10881. components: [
  10882. {
  10883. dom: {
  10884. tag: 'div',
  10885. classes: ['tox-notification__icon']
  10886. },
  10887. components: [Button.sketch({
  10888. dom: {
  10889. tag: 'button',
  10890. classes: [
  10891. 'tox-button',
  10892. 'tox-button--naked',
  10893. 'tox-button--icon'
  10894. ],
  10895. innerHtml: get$c(spec.icon, providersBackstage.icons),
  10896. attributes: { title: providersBackstage.translate(spec.actionLabel) }
  10897. },
  10898. action: function (comp) {
  10899. emitWith(comp, formActionEvent, {
  10900. name: 'alert-banner',
  10901. value: spec.url
  10902. });
  10903. }
  10904. })]
  10905. },
  10906. {
  10907. dom: {
  10908. tag: 'div',
  10909. classes: ['tox-notification__body'],
  10910. innerHtml: providersBackstage.translate(spec.text)
  10911. }
  10912. }
  10913. ]
  10914. });
  10915. };
  10916. var schema$d = constant([
  10917. defaulted$1('prefix', 'form-field'),
  10918. field$1('fieldBehaviours', [
  10919. Composing,
  10920. Representing
  10921. ])
  10922. ]);
  10923. var parts$3 = constant([
  10924. optional({
  10925. schema: [strict$1('dom')],
  10926. name: 'label'
  10927. }),
  10928. optional({
  10929. factory: {
  10930. sketch: function (spec) {
  10931. return {
  10932. uid: spec.uid,
  10933. dom: {
  10934. tag: 'span',
  10935. styles: { display: 'none' },
  10936. attributes: { 'aria-hidden': 'true' },
  10937. innerHtml: spec.text
  10938. }
  10939. };
  10940. }
  10941. },
  10942. schema: [strict$1('text')],
  10943. name: 'aria-descriptor'
  10944. }),
  10945. required({
  10946. factory: {
  10947. sketch: function (spec) {
  10948. var excludeFactory = exclude$1(spec, ['factory']);
  10949. return spec.factory.sketch(excludeFactory);
  10950. }
  10951. },
  10952. schema: [strict$1('factory')],
  10953. name: 'field'
  10954. })
  10955. ]);
  10956. var factory$4 = function (detail, components, spec, externals) {
  10957. var behaviours = augment(detail.fieldBehaviours, [
  10958. Composing.config({
  10959. find: function (container) {
  10960. return getPart(container, detail, 'field');
  10961. }
  10962. }),
  10963. Representing.config({
  10964. store: {
  10965. mode: 'manual',
  10966. getValue: function (field) {
  10967. return Composing.getCurrent(field).bind(Representing.getValue);
  10968. },
  10969. setValue: function (field, value) {
  10970. Composing.getCurrent(field).each(function (current) {
  10971. Representing.setValue(current, value);
  10972. });
  10973. }
  10974. }
  10975. })
  10976. ]);
  10977. var events = derive([runOnAttached(function (component, simulatedEvent) {
  10978. var ps = getParts(component, detail, [
  10979. 'label',
  10980. 'field',
  10981. 'aria-descriptor'
  10982. ]);
  10983. ps.field().each(function (field) {
  10984. var id = generate$1(detail.prefix);
  10985. ps.label().each(function (label) {
  10986. set$1(label.element(), 'for', id);
  10987. set$1(field.element(), 'id', id);
  10988. });
  10989. ps['aria-descriptor']().each(function (descriptor) {
  10990. var descriptorId = generate$1(detail.prefix);
  10991. set$1(descriptor.element(), 'id', descriptorId);
  10992. set$1(field.element(), 'aria-describedby', descriptorId);
  10993. });
  10994. });
  10995. })]);
  10996. var apis = {
  10997. getField: function (container) {
  10998. return getPart(container, detail, 'field');
  10999. },
  11000. getLabel: function (container) {
  11001. return getPart(container, detail, 'label');
  11002. }
  11003. };
  11004. return {
  11005. uid: detail.uid,
  11006. dom: detail.dom,
  11007. components: components,
  11008. behaviours: behaviours,
  11009. events: events,
  11010. apis: apis
  11011. };
  11012. };
  11013. var FormField = composite$1({
  11014. name: 'FormField',
  11015. configFields: schema$d(),
  11016. partFields: parts$3(),
  11017. factory: factory$4,
  11018. apis: {
  11019. getField: function (apis, comp) {
  11020. return apis.getField(comp);
  11021. },
  11022. getLabel: function (apis, comp) {
  11023. return apis.getLabel(comp);
  11024. }
  11025. }
  11026. });
  11027. var getCoupled = function (component, coupleConfig, coupleState, name) {
  11028. return coupleState.getOrCreate(component, coupleConfig, name);
  11029. };
  11030. var CouplingApis = /*#__PURE__*/Object.freeze({
  11031. getCoupled: getCoupled
  11032. });
  11033. var CouplingSchema = [strictOf('others', setOf$1(Result.value, anyValue$1()))];
  11034. var init$6 = function (spec) {
  11035. var coupled = {};
  11036. var getOrCreate = function (component, coupleConfig, name) {
  11037. var available = keys(coupleConfig.others);
  11038. if (!available) {
  11039. throw new Error('Cannot find coupled component: ' + name + '. Known coupled components: ' + JSON$1.stringify(available, null, 2));
  11040. } else {
  11041. return readOptFrom$1(coupled, name).getOrThunk(function () {
  11042. var builder = readOptFrom$1(coupleConfig.others, name).getOrDie('No information found for coupled component: ' + name);
  11043. var spec = builder(component);
  11044. var built = component.getSystem().build(spec);
  11045. coupled[name] = built;
  11046. return built;
  11047. });
  11048. }
  11049. };
  11050. var readState = constant({});
  11051. return nu$5({
  11052. readState: readState,
  11053. getOrCreate: getOrCreate
  11054. });
  11055. };
  11056. var CouplingState = /*#__PURE__*/Object.freeze({
  11057. init: init$6
  11058. });
  11059. var Coupling = create$1({
  11060. fields: CouplingSchema,
  11061. name: 'coupling',
  11062. apis: CouplingApis,
  11063. state: CouplingState
  11064. });
  11065. var events$a = function (streamConfig, streamState) {
  11066. var streams = streamConfig.stream.streams;
  11067. var processor = streams.setup(streamConfig, streamState);
  11068. return derive([
  11069. run(streamConfig.event, processor),
  11070. runOnDetached(function () {
  11071. return streamState.cancel();
  11072. })
  11073. ].concat(streamConfig.cancelEvent.map(function (e) {
  11074. return [run(e, function () {
  11075. return streamState.cancel();
  11076. })];
  11077. }).getOr([])));
  11078. };
  11079. var ActiveStreaming = /*#__PURE__*/Object.freeze({
  11080. events: events$a
  11081. });
  11082. var throttle = function (_config) {
  11083. var state = Cell(null);
  11084. var readState = function () {
  11085. return { timer: state.get() !== null ? 'set' : 'unset' };
  11086. };
  11087. var setTimer = function (t) {
  11088. state.set(t);
  11089. };
  11090. var cancel = function () {
  11091. var t = state.get();
  11092. if (t !== null) {
  11093. t.cancel();
  11094. }
  11095. };
  11096. return nu$5({
  11097. readState: readState,
  11098. setTimer: setTimer,
  11099. cancel: cancel
  11100. });
  11101. };
  11102. var init$7 = function (spec) {
  11103. return spec.stream.streams.state(spec);
  11104. };
  11105. var StreamingState = /*#__PURE__*/Object.freeze({
  11106. throttle: throttle,
  11107. init: init$7
  11108. });
  11109. var setup$2 = function (streamInfo, streamState) {
  11110. var sInfo = streamInfo.stream;
  11111. var throttler = last$2(streamInfo.onStream, sInfo.delay);
  11112. streamState.setTimer(throttler);
  11113. return function (component, simulatedEvent) {
  11114. throttler.throttle(component, simulatedEvent);
  11115. if (sInfo.stopEvent) {
  11116. simulatedEvent.stop();
  11117. }
  11118. };
  11119. };
  11120. var StreamingSchema = [
  11121. strictOf('stream', choose$1('mode', {
  11122. throttle: [
  11123. strict$1('delay'),
  11124. defaulted$1('stopEvent', true),
  11125. output('streams', {
  11126. setup: setup$2,
  11127. state: throttle
  11128. })
  11129. ]
  11130. })),
  11131. defaulted$1('event', 'input'),
  11132. option('cancelEvent'),
  11133. onStrictHandler('onStream')
  11134. ];
  11135. var Streaming = create$1({
  11136. fields: StreamingSchema,
  11137. name: 'streaming',
  11138. active: ActiveStreaming,
  11139. state: StreamingState
  11140. });
  11141. var nu$a = function (baseFn) {
  11142. var data = Option.none();
  11143. var callbacks = [];
  11144. var map = function (f) {
  11145. return nu$a(function (nCallback) {
  11146. get(function (data) {
  11147. nCallback(f(data));
  11148. });
  11149. });
  11150. };
  11151. var get = function (nCallback) {
  11152. if (isReady())
  11153. call(nCallback);
  11154. else
  11155. callbacks.push(nCallback);
  11156. };
  11157. var set = function (x) {
  11158. data = Option.some(x);
  11159. run(callbacks);
  11160. callbacks = [];
  11161. };
  11162. var isReady = function () {
  11163. return data.isSome();
  11164. };
  11165. var run = function (cbs) {
  11166. each(cbs, call);
  11167. };
  11168. var call = function (cb) {
  11169. data.each(function (x) {
  11170. setTimeout(function () {
  11171. cb(x);
  11172. }, 0);
  11173. });
  11174. };
  11175. baseFn(set);
  11176. return {
  11177. get: get,
  11178. map: map,
  11179. isReady: isReady
  11180. };
  11181. };
  11182. var pure$1 = function (a) {
  11183. return nu$a(function (callback) {
  11184. callback(a);
  11185. });
  11186. };
  11187. var LazyValue = {
  11188. nu: nu$a,
  11189. pure: pure$1
  11190. };
  11191. var bounce = function (f) {
  11192. return function () {
  11193. var args = [];
  11194. for (var _i = 0; _i < arguments.length; _i++) {
  11195. args[_i] = arguments[_i];
  11196. }
  11197. var me = this;
  11198. setTimeout(function () {
  11199. f.apply(me, args);
  11200. }, 0);
  11201. };
  11202. };
  11203. var nu$b = function (baseFn) {
  11204. var get = function (callback) {
  11205. baseFn(bounce(callback));
  11206. };
  11207. var map = function (fab) {
  11208. return nu$b(function (callback) {
  11209. get(function (a) {
  11210. var value = fab(a);
  11211. callback(value);
  11212. });
  11213. });
  11214. };
  11215. var bind = function (aFutureB) {
  11216. return nu$b(function (callback) {
  11217. get(function (a) {
  11218. aFutureB(a).get(callback);
  11219. });
  11220. });
  11221. };
  11222. var anonBind = function (futureB) {
  11223. return nu$b(function (callback) {
  11224. get(function (a) {
  11225. futureB.get(callback);
  11226. });
  11227. });
  11228. };
  11229. var toLazy = function () {
  11230. return LazyValue.nu(get);
  11231. };
  11232. var toCached = function () {
  11233. var cache = null;
  11234. return nu$b(function (callback) {
  11235. if (cache === null) {
  11236. cache = toLazy();
  11237. }
  11238. cache.get(callback);
  11239. });
  11240. };
  11241. return {
  11242. map: map,
  11243. bind: bind,
  11244. anonBind: anonBind,
  11245. toLazy: toLazy,
  11246. toCached: toCached,
  11247. get: get
  11248. };
  11249. };
  11250. var pure$2 = function (a) {
  11251. return nu$b(function (callback) {
  11252. callback(a);
  11253. });
  11254. };
  11255. var Future = {
  11256. nu: nu$b,
  11257. pure: pure$2
  11258. };
  11259. var suffix = constant('sink');
  11260. var partType = constant(optional({
  11261. name: suffix(),
  11262. overrides: constant({
  11263. dom: { tag: 'div' },
  11264. behaviours: derive$1([Positioning.config({ useFixed: true })]),
  11265. events: derive([
  11266. cutter(keydown()),
  11267. cutter(mousedown()),
  11268. cutter(click())
  11269. ])
  11270. })
  11271. }));
  11272. var HighlightOnOpen;
  11273. (function (HighlightOnOpen) {
  11274. HighlightOnOpen[HighlightOnOpen['HighlightFirst'] = 0] = 'HighlightFirst';
  11275. HighlightOnOpen[HighlightOnOpen['HighlightNone'] = 1] = 'HighlightNone';
  11276. }(HighlightOnOpen || (HighlightOnOpen = {})));
  11277. var getAnchor = function (detail, component) {
  11278. var ourHotspot = detail.getHotspot(component).getOr(component);
  11279. var anchor = 'hotspot';
  11280. return detail.layouts.fold(function () {
  11281. return {
  11282. anchor: anchor,
  11283. hotspot: ourHotspot
  11284. };
  11285. }, function (layouts) {
  11286. return {
  11287. anchor: anchor,
  11288. hotspot: ourHotspot,
  11289. layouts: layouts
  11290. };
  11291. });
  11292. };
  11293. var fetch = function (detail, mapFetch, component) {
  11294. var fetcher = detail.fetch;
  11295. return fetcher(component).map(mapFetch);
  11296. };
  11297. var openF = function (detail, mapFetch, anchor, component, sandbox, externals, highlightOnOpen) {
  11298. var futureData = fetch(detail, mapFetch, component);
  11299. var getLazySink = getSink(component, detail);
  11300. return futureData.map(function (tdata) {
  11301. return tdata.bind(function (data) {
  11302. return Option.from(tieredMenu.sketch(__assign({}, externals.menu(), {
  11303. uid: generate$2(''),
  11304. data: data,
  11305. highlightImmediately: highlightOnOpen === HighlightOnOpen.HighlightFirst,
  11306. onOpenMenu: function (tmenu, menu) {
  11307. var sink = getLazySink().getOrDie();
  11308. Positioning.position(sink, anchor, menu);
  11309. Sandboxing.decloak(sandbox);
  11310. },
  11311. onOpenSubmenu: function (tmenu, item, submenu) {
  11312. var sink = getLazySink().getOrDie();
  11313. Positioning.position(sink, {
  11314. anchor: 'submenu',
  11315. item: item
  11316. }, submenu);
  11317. Sandboxing.decloak(sandbox);
  11318. },
  11319. onEscape: function () {
  11320. Focusing.focus(component);
  11321. Sandboxing.close(sandbox);
  11322. return Option.some(true);
  11323. }
  11324. })));
  11325. });
  11326. });
  11327. };
  11328. var open$1 = function (detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen) {
  11329. var anchor = getAnchor(detail, hotspot);
  11330. var processed = openF(detail, mapFetch, anchor, hotspot, sandbox, externals, highlightOnOpen);
  11331. return processed.map(function (tdata) {
  11332. tdata.fold(function () {
  11333. if (Sandboxing.isOpen(sandbox)) {
  11334. Sandboxing.close(sandbox);
  11335. }
  11336. }, function (data) {
  11337. Sandboxing.cloak(sandbox);
  11338. Sandboxing.open(sandbox, data);
  11339. onOpenSync(sandbox);
  11340. });
  11341. return sandbox;
  11342. });
  11343. };
  11344. var close$1 = function (detail, mapFetch, component, sandbox, _externals, _onOpenSync, _highlightOnOpen) {
  11345. Sandboxing.close(sandbox);
  11346. return Future.pure(sandbox);
  11347. };
  11348. var togglePopup = function (detail, mapFetch, hotspot, externals, onOpenSync, highlightOnOpen) {
  11349. var sandbox = Coupling.getCoupled(hotspot, 'sandbox');
  11350. var showing = Sandboxing.isOpen(sandbox);
  11351. var action = showing ? close$1 : open$1;
  11352. return action(detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen);
  11353. };
  11354. var matchWidth = function (hotspot, container, useMinWidth) {
  11355. var menu = Composing.getCurrent(container).getOr(container);
  11356. var buttonWidth = get$7(hotspot.element());
  11357. if (useMinWidth) {
  11358. set$2(menu.element(), 'min-width', buttonWidth + 'px');
  11359. } else {
  11360. set$4(menu.element(), buttonWidth);
  11361. }
  11362. };
  11363. var getSink = function (anyInSystem, sinkDetail) {
  11364. return anyInSystem.getSystem().getByUid(sinkDetail.uid + '-' + suffix()).map(function (internalSink) {
  11365. return function () {
  11366. return Result.value(internalSink);
  11367. };
  11368. }).getOrThunk(function () {
  11369. return sinkDetail.lazySink.fold(function () {
  11370. return function () {
  11371. return Result.error(new Error('No internal sink is specified, nor could an external sink be found'));
  11372. };
  11373. }, function (lazySinkFn) {
  11374. return function () {
  11375. return lazySinkFn(anyInSystem);
  11376. };
  11377. });
  11378. });
  11379. };
  11380. var makeSandbox = function (detail, hotspot, extras) {
  11381. var ariaOwner = manager();
  11382. var onOpen = function (component, menu) {
  11383. var anchor = getAnchor(detail, hotspot);
  11384. ariaOwner.link(hotspot.element());
  11385. if (detail.matchWidth) {
  11386. matchWidth(anchor.hotspot, menu, detail.useMinWidth);
  11387. }
  11388. detail.onOpen(anchor, component, menu);
  11389. if (extras !== undefined && extras.onOpen !== undefined) {
  11390. extras.onOpen(component, menu);
  11391. }
  11392. };
  11393. var onClose = function (component, menu) {
  11394. ariaOwner.unlink(hotspot.element());
  11395. if (extras !== undefined && extras.onClose !== undefined) {
  11396. extras.onClose(component, menu);
  11397. }
  11398. };
  11399. var lazySink = getSink(hotspot, detail);
  11400. return {
  11401. dom: {
  11402. tag: 'div',
  11403. classes: detail.sandboxClasses,
  11404. attributes: { id: ariaOwner.id() }
  11405. },
  11406. behaviours: SketchBehaviours.augment(detail.sandboxBehaviours, [
  11407. Representing.config({
  11408. store: {
  11409. mode: 'memory',
  11410. initialValue: hotspot
  11411. }
  11412. }),
  11413. Sandboxing.config({
  11414. onOpen: onOpen,
  11415. onClose: onClose,
  11416. isPartOf: function (container, data, queryElem) {
  11417. return isPartOf(data, queryElem) || isPartOf(hotspot, queryElem);
  11418. },
  11419. getAttachPoint: function () {
  11420. return lazySink().getOrDie();
  11421. }
  11422. }),
  11423. Composing.config({
  11424. find: function (sandbox) {
  11425. return Sandboxing.getState(sandbox).bind(function (menu) {
  11426. return Composing.getCurrent(menu);
  11427. });
  11428. }
  11429. }),
  11430. receivingConfig({ isExtraPart: constant(false) })
  11431. ])
  11432. };
  11433. };
  11434. var setValueFromItem = function (model, input, item) {
  11435. var itemData = Representing.getValue(item);
  11436. Representing.setValue(input, itemData);
  11437. setCursorAtEnd(input);
  11438. };
  11439. var setSelectionOn = function (input, f) {
  11440. var el = input.element();
  11441. var value = get$5(el);
  11442. var node = el.dom();
  11443. if (get$2(el, 'type') !== 'number') {
  11444. f(node, value);
  11445. }
  11446. };
  11447. var setCursorAtEnd = function (input) {
  11448. setSelectionOn(input, function (node, value) {
  11449. return node.setSelectionRange(value.length, value.length);
  11450. });
  11451. };
  11452. var setSelectionToEnd = function (input, startOffset) {
  11453. setSelectionOn(input, function (node, value) {
  11454. return node.setSelectionRange(startOffset, value.length);
  11455. });
  11456. };
  11457. var attemptSelectOver = function (model, input, item) {
  11458. if (!model.selectsOver) {
  11459. return Option.none();
  11460. } else {
  11461. var currentValue = Representing.getValue(input);
  11462. var inputDisplay_1 = model.getDisplayText(currentValue);
  11463. var itemValue = Representing.getValue(item);
  11464. var itemDisplay = model.getDisplayText(itemValue);
  11465. return itemDisplay.indexOf(inputDisplay_1) === 0 ? Option.some(function () {
  11466. setValueFromItem(model, input, item);
  11467. setSelectionToEnd(input, inputDisplay_1.length);
  11468. }) : Option.none();
  11469. }
  11470. };
  11471. var schema$e = constant([
  11472. option('data'),
  11473. defaulted$1('inputAttributes', {}),
  11474. defaulted$1('inputStyles', {}),
  11475. defaulted$1('tag', 'input'),
  11476. defaulted$1('inputClasses', []),
  11477. onHandler('onSetValue'),
  11478. defaulted$1('styles', {}),
  11479. defaulted$1('eventOrder', {}),
  11480. field$1('inputBehaviours', [
  11481. Representing,
  11482. Focusing
  11483. ]),
  11484. defaulted$1('selectOnFocus', true)
  11485. ]);
  11486. var focusBehaviours = function (detail) {
  11487. return derive$1([Focusing.config({
  11488. onFocus: detail.selectOnFocus === false ? noop : function (component) {
  11489. var input = component.element();
  11490. var value = get$5(input);
  11491. input.dom().setSelectionRange(0, value.length);
  11492. }
  11493. })]);
  11494. };
  11495. var behaviours = function (detail) {
  11496. return __assign({}, focusBehaviours(detail), augment(detail.inputBehaviours, [Representing.config({
  11497. store: {
  11498. mode: 'manual',
  11499. initialValue: detail.data.getOr(undefined),
  11500. getValue: function (input) {
  11501. return get$5(input.element());
  11502. },
  11503. setValue: function (input, data) {
  11504. var current = get$5(input.element());
  11505. if (current !== data) {
  11506. set$3(input.element(), data);
  11507. }
  11508. }
  11509. },
  11510. onSetValue: detail.onSetValue
  11511. })]));
  11512. };
  11513. var dom$2 = function (detail) {
  11514. return {
  11515. tag: detail.tag,
  11516. attributes: __assign({ type: 'input' }, detail.inputAttributes),
  11517. styles: detail.inputStyles,
  11518. classes: detail.inputClasses
  11519. };
  11520. };
  11521. var itemExecute = constant('alloy.typeahead.itemexecute');
  11522. var make$3 = function (detail, components, spec, externals) {
  11523. var navigateList = function (comp, simulatedEvent, highlighter) {
  11524. detail.previewing.set(false);
  11525. var sandbox = Coupling.getCoupled(comp, 'sandbox');
  11526. if (Sandboxing.isOpen(sandbox)) {
  11527. Composing.getCurrent(sandbox).each(function (menu) {
  11528. Highlighting.getHighlighted(menu).fold(function () {
  11529. highlighter(menu);
  11530. }, function () {
  11531. dispatchEvent(sandbox, menu.element(), 'keydown', simulatedEvent);
  11532. });
  11533. });
  11534. } else {
  11535. var onOpenSync = function (sandbox) {
  11536. Composing.getCurrent(sandbox).each(highlighter);
  11537. };
  11538. open$1(detail, mapFetch(comp), comp, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  11539. }
  11540. };
  11541. var focusBehaviours$1 = focusBehaviours(detail);
  11542. var mapFetch = function (comp) {
  11543. return function (tdata) {
  11544. return tdata.map(function (data) {
  11545. var menus = values(data.menus);
  11546. var items = bind(menus, function (menu) {
  11547. return filter(menu.items, function (item) {
  11548. return item.type === 'item';
  11549. });
  11550. });
  11551. var repState = Representing.getState(comp);
  11552. repState.update(map(items, function (item) {
  11553. return item.data;
  11554. }));
  11555. return data;
  11556. });
  11557. };
  11558. };
  11559. var behaviours = [
  11560. Focusing.config({}),
  11561. Representing.config({
  11562. onSetValue: detail.onSetValue,
  11563. store: __assign({
  11564. mode: 'dataset',
  11565. getDataKey: function (comp) {
  11566. return get$5(comp.element());
  11567. },
  11568. getFallbackEntry: function (itemString) {
  11569. return {
  11570. value: itemString,
  11571. meta: {}
  11572. };
  11573. },
  11574. setValue: function (comp, data) {
  11575. set$3(comp.element(), detail.model.getDisplayText(data));
  11576. }
  11577. }, detail.initialData.map(function (d) {
  11578. return wrap$1('initialValue', d);
  11579. }).getOr({}))
  11580. }),
  11581. Streaming.config({
  11582. stream: {
  11583. mode: 'throttle',
  11584. delay: detail.responseTime,
  11585. stopEvent: false
  11586. },
  11587. onStream: function (component, simulatedEvent) {
  11588. var sandbox = Coupling.getCoupled(component, 'sandbox');
  11589. var focusInInput = Focusing.isFocused(component);
  11590. if (focusInInput) {
  11591. if (get$5(component.element()).length >= detail.minChars) {
  11592. var previousValue_1 = Composing.getCurrent(sandbox).bind(function (menu) {
  11593. return Highlighting.getHighlighted(menu).map(Representing.getValue);
  11594. });
  11595. detail.previewing.set(true);
  11596. var onOpenSync = function (_sandbox) {
  11597. Composing.getCurrent(sandbox).each(function (menu) {
  11598. previousValue_1.fold(function () {
  11599. if (detail.model.selectsOver) {
  11600. Highlighting.highlightFirst(menu);
  11601. }
  11602. }, function (pv) {
  11603. Highlighting.highlightBy(menu, function (item) {
  11604. var itemData = Representing.getValue(item);
  11605. return itemData.value === pv.value;
  11606. });
  11607. Highlighting.getHighlighted(menu).orThunk(function () {
  11608. Highlighting.highlightFirst(menu);
  11609. return Option.none();
  11610. });
  11611. });
  11612. });
  11613. };
  11614. open$1(detail, mapFetch(component), component, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  11615. }
  11616. }
  11617. },
  11618. cancelEvent: typeaheadCancel()
  11619. }),
  11620. Keying.config({
  11621. mode: 'special',
  11622. onDown: function (comp, simulatedEvent) {
  11623. navigateList(comp, simulatedEvent, Highlighting.highlightFirst);
  11624. return Option.some(true);
  11625. },
  11626. onEscape: function (comp) {
  11627. var sandbox = Coupling.getCoupled(comp, 'sandbox');
  11628. if (Sandboxing.isOpen(sandbox)) {
  11629. Sandboxing.close(sandbox);
  11630. return Option.some(true);
  11631. }
  11632. return Option.none();
  11633. },
  11634. onUp: function (comp, simulatedEvent) {
  11635. navigateList(comp, simulatedEvent, Highlighting.highlightLast);
  11636. return Option.some(true);
  11637. },
  11638. onEnter: function (comp) {
  11639. var sandbox = Coupling.getCoupled(comp, 'sandbox');
  11640. var sandboxIsOpen = Sandboxing.isOpen(sandbox);
  11641. if (sandboxIsOpen && !detail.previewing.get()) {
  11642. return Composing.getCurrent(sandbox).bind(function (menu) {
  11643. return Highlighting.getHighlighted(menu);
  11644. }).map(function (item) {
  11645. emitWith(comp, itemExecute(), { item: item });
  11646. return true;
  11647. });
  11648. } else {
  11649. var currentValue = Representing.getValue(comp);
  11650. emit(comp, typeaheadCancel());
  11651. detail.onExecute(sandbox, comp, currentValue);
  11652. if (sandboxIsOpen) {
  11653. Sandboxing.close(sandbox);
  11654. }
  11655. return Option.some(true);
  11656. }
  11657. }
  11658. }),
  11659. Toggling.config({
  11660. toggleClass: detail.markers.openClass,
  11661. aria: {
  11662. mode: 'pressed',
  11663. syncWithExpanded: true
  11664. }
  11665. }),
  11666. Coupling.config({
  11667. others: {
  11668. sandbox: function (hotspot) {
  11669. return makeSandbox(detail, hotspot, {
  11670. onOpen: identity,
  11671. onClose: identity
  11672. });
  11673. }
  11674. }
  11675. }),
  11676. config('typeaheadevents', [
  11677. runOnExecute(function (comp) {
  11678. var onOpenSync = noop;
  11679. togglePopup(detail, mapFetch(comp), comp, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  11680. }),
  11681. run(itemExecute(), function (comp, se) {
  11682. var sandbox = Coupling.getCoupled(comp, 'sandbox');
  11683. setValueFromItem(detail.model, comp, se.event().item());
  11684. emit(comp, typeaheadCancel());
  11685. detail.onItemExecute(comp, sandbox, se.event().item(), Representing.getValue(comp));
  11686. Sandboxing.close(sandbox);
  11687. setCursorAtEnd(comp);
  11688. })
  11689. ].concat(detail.dismissOnBlur ? [run(postBlur(), function (typeahead) {
  11690. var sandbox = Coupling.getCoupled(typeahead, 'sandbox');
  11691. if (search$1(sandbox.element()).isNone()) {
  11692. Sandboxing.close(sandbox);
  11693. }
  11694. })] : []))
  11695. ];
  11696. return {
  11697. uid: detail.uid,
  11698. dom: dom$2(detail),
  11699. behaviours: __assign({}, focusBehaviours$1, augment(detail.typeaheadBehaviours, behaviours)),
  11700. eventOrder: detail.eventOrder
  11701. };
  11702. };
  11703. var sandboxFields = function () {
  11704. return [
  11705. defaulted$1('sandboxClasses', []),
  11706. SketchBehaviours.field('sandboxBehaviours', [
  11707. Composing,
  11708. Receiving,
  11709. Sandboxing,
  11710. Representing
  11711. ])
  11712. ];
  11713. };
  11714. var schema$f = constant([
  11715. option('lazySink'),
  11716. strict$1('fetch'),
  11717. defaulted$1('minChars', 5),
  11718. defaulted$1('responseTime', 1000),
  11719. onHandler('onOpen'),
  11720. defaulted$1('getHotspot', Option.some),
  11721. defaulted$1('layouts', Option.none()),
  11722. defaulted$1('eventOrder', {}),
  11723. defaultedObjOf('model', {}, [
  11724. defaulted$1('getDisplayText', function (itemData) {
  11725. return itemData.meta !== undefined && itemData.meta.text !== undefined ? itemData.meta.text : itemData.value;
  11726. }),
  11727. defaulted$1('selectsOver', true),
  11728. defaulted$1('populateFromBrowse', true)
  11729. ]),
  11730. onHandler('onSetValue'),
  11731. onKeyboardHandler('onExecute'),
  11732. onHandler('onItemExecute'),
  11733. defaulted$1('inputClasses', []),
  11734. defaulted$1('inputAttributes', {}),
  11735. defaulted$1('inputStyles', {}),
  11736. defaulted$1('matchWidth', true),
  11737. defaulted$1('useMinWidth', false),
  11738. defaulted$1('dismissOnBlur', true),
  11739. markers(['openClass']),
  11740. option('initialData'),
  11741. field$1('typeaheadBehaviours', [
  11742. Focusing,
  11743. Representing,
  11744. Streaming,
  11745. Keying,
  11746. Toggling,
  11747. Coupling
  11748. ]),
  11749. state$1('previewing', function () {
  11750. return Cell(true);
  11751. })
  11752. ].concat(schema$e()).concat(sandboxFields()));
  11753. var parts$4 = constant([external$1({
  11754. schema: [tieredMenuMarkers()],
  11755. name: 'menu',
  11756. overrides: function (detail) {
  11757. return {
  11758. fakeFocus: true,
  11759. onHighlight: function (menu, item) {
  11760. if (!detail.previewing.get()) {
  11761. menu.getSystem().getByUid(detail.uid).each(function (input) {
  11762. if (detail.model.populateFromBrowse) {
  11763. setValueFromItem(detail.model, input, item);
  11764. }
  11765. });
  11766. } else {
  11767. menu.getSystem().getByUid(detail.uid).each(function (input) {
  11768. attemptSelectOver(detail.model, input, item).fold(function () {
  11769. return Highlighting.dehighlight(menu, item);
  11770. }, function (fn) {
  11771. return fn();
  11772. });
  11773. });
  11774. }
  11775. detail.previewing.set(false);
  11776. },
  11777. onExecute: function (menu, item) {
  11778. return menu.getSystem().getByUid(detail.uid).toOption().map(function (typeahead) {
  11779. emitWith(typeahead, itemExecute(), { item: item });
  11780. return true;
  11781. });
  11782. },
  11783. onHover: function (menu, item) {
  11784. detail.previewing.set(false);
  11785. menu.getSystem().getByUid(detail.uid).each(function (input) {
  11786. if (detail.model.populateFromBrowse) {
  11787. setValueFromItem(detail.model, input, item);
  11788. }
  11789. });
  11790. }
  11791. };
  11792. }
  11793. })]);
  11794. var Typeahead = composite$1({
  11795. name: 'Typeahead',
  11796. configFields: schema$f(),
  11797. partFields: parts$4(),
  11798. factory: make$3
  11799. });
  11800. var renderFormFieldWith = function (pLabel, pField, extraClasses) {
  11801. var spec = renderFormFieldSpecWith(pLabel, pField, extraClasses);
  11802. return FormField.sketch(spec);
  11803. };
  11804. var renderFormField = function (pLabel, pField) {
  11805. return renderFormFieldWith(pLabel, pField, []);
  11806. };
  11807. var renderFormFieldSpecWith = function (pLabel, pField, extraClasses) {
  11808. return {
  11809. dom: renderFormFieldDomWith(extraClasses),
  11810. components: pLabel.toArray().concat([pField])
  11811. };
  11812. };
  11813. var renderFormFieldDom = function () {
  11814. return renderFormFieldDomWith([]);
  11815. };
  11816. var renderFormFieldDomWith = function (extraClasses) {
  11817. return {
  11818. tag: 'div',
  11819. classes: ['tox-form__group'].concat(extraClasses)
  11820. };
  11821. };
  11822. var renderLabel = function (label, providersBackstage) {
  11823. return FormField.parts().label({
  11824. dom: {
  11825. tag: 'label',
  11826. classes: ['tox-label'],
  11827. innerHtml: providersBackstage.translate(label)
  11828. }
  11829. });
  11830. };
  11831. var isMenuItemReference = function (item) {
  11832. return isString(item);
  11833. };
  11834. var isSeparator = function (item) {
  11835. return item.type === 'separator';
  11836. };
  11837. var isExpandingMenuItem = function (item) {
  11838. return has(item, 'getSubmenuItems');
  11839. };
  11840. var separator$1 = { type: 'separator' };
  11841. var unwrapReferences = function (items, menuItems) {
  11842. var realItems = foldl(items, function (acc, item) {
  11843. if (isMenuItemReference(item)) {
  11844. if (item === '') {
  11845. return acc;
  11846. } else if (item === '|') {
  11847. return acc.length > 0 && !isSeparator(acc[acc.length - 1]) ? acc.concat([separator$1]) : acc;
  11848. } else if (has(menuItems, item.toLowerCase())) {
  11849. return acc.concat([menuItems[item.toLowerCase()]]);
  11850. } else {
  11851. return acc;
  11852. }
  11853. } else {
  11854. return acc.concat([item]);
  11855. }
  11856. }, []);
  11857. if (realItems.length > 0 && isSeparator(realItems[realItems.length - 1])) {
  11858. realItems.pop();
  11859. }
  11860. return realItems;
  11861. };
  11862. var getFromExpandingItem = function (item, menuItems) {
  11863. var submenuItems = item.getSubmenuItems();
  11864. var rest = expand(submenuItems, menuItems);
  11865. var newMenus = deepMerge(rest.menus, wrap$1(item.value, rest.items));
  11866. var newExpansions = deepMerge(rest.expansions, wrap$1(item.value, item.value));
  11867. return {
  11868. item: item,
  11869. menus: newMenus,
  11870. expansions: newExpansions
  11871. };
  11872. };
  11873. var getFromItem = function (item, menuItems) {
  11874. return isExpandingMenuItem(item) ? getFromExpandingItem(item, menuItems) : {
  11875. item: item,
  11876. menus: {},
  11877. expansions: {}
  11878. };
  11879. };
  11880. var generateValueIfRequired = function (item) {
  11881. if (isSeparator(item)) {
  11882. return item;
  11883. } else {
  11884. var itemValue = readOptFrom$1(item, 'value').getOrThunk(function () {
  11885. return generate$1('generated-menu-item');
  11886. });
  11887. return deepMerge({ value: itemValue }, item);
  11888. }
  11889. };
  11890. var expand = function (items, menuItems) {
  11891. var realItems = unwrapReferences(isString(items) ? items.split(' ') : items, menuItems);
  11892. return foldr(realItems, function (acc, item) {
  11893. var itemWithValue = generateValueIfRequired(item);
  11894. var newData = getFromItem(itemWithValue, menuItems);
  11895. return {
  11896. menus: deepMerge(acc.menus, newData.menus),
  11897. items: [newData.item].concat(acc.items),
  11898. expansions: deepMerge(acc.expansions, newData.expansions)
  11899. };
  11900. }, {
  11901. menus: {},
  11902. expansions: {},
  11903. items: []
  11904. });
  11905. };
  11906. var build$2 = function (items, itemResponse, providersBackstage) {
  11907. var primary = generate$1('primary-menu');
  11908. var data = expand(items, providersBackstage.menuItems());
  11909. if (data.items.length === 0) {
  11910. return Option.none();
  11911. }
  11912. var mainMenu = createPartialMenu(primary, data.items, itemResponse, providersBackstage);
  11913. var submenus = map$1(data.menus, function (menuItems, menuName) {
  11914. return createPartialMenu(menuName, menuItems, itemResponse, providersBackstage);
  11915. });
  11916. var menus = deepMerge(submenus, wrap$1(primary, mainMenu));
  11917. return Option.from(tieredMenu.tieredData(primary, menus, data.expansions));
  11918. };
  11919. var renderAutocomplete = function (spec, sharedBackstage) {
  11920. var pLabel = renderLabel(spec.label.getOr('?'), sharedBackstage.providers);
  11921. var pField = FormField.parts().field({
  11922. factory: Typeahead,
  11923. dismissOnBlur: false,
  11924. inputClasses: ['tox-textfield'],
  11925. minChars: 1,
  11926. fetch: function (input) {
  11927. var value = Representing.getValue(input);
  11928. var items = spec.getItems(value);
  11929. var tdata = build$2(items, ItemResponse$1.BUBBLE_TO_SANDBOX, sharedBackstage.providers);
  11930. return Future.pure(tdata);
  11931. },
  11932. markers: { openClass: 'dog' },
  11933. lazySink: sharedBackstage.getSink,
  11934. parts: { menu: part(false, 1, 'normal') }
  11935. });
  11936. return renderFormField(Option.some(pLabel), pField);
  11937. };
  11938. var renderBar = function (spec, backstage) {
  11939. return {
  11940. dom: {
  11941. tag: 'div',
  11942. classes: ['tox-bar']
  11943. },
  11944. components: map(spec.items, backstage.interpreter)
  11945. };
  11946. };
  11947. var factory$5 = function (detail, spec) {
  11948. return {
  11949. uid: detail.uid,
  11950. dom: dom$2(detail),
  11951. components: [],
  11952. behaviours: behaviours(detail),
  11953. eventOrder: detail.eventOrder
  11954. };
  11955. };
  11956. var Input = single$2({
  11957. name: 'Input',
  11958. configFields: schema$e(),
  11959. factory: factory$5
  11960. });
  11961. var isFirefox$1 = PlatformDetection$1.detect().browser.isFirefox();
  11962. var offscreen = {
  11963. position: 'absolute',
  11964. left: '-9999px'
  11965. };
  11966. var create$3 = function (doc, text) {
  11967. var span = Element.fromTag('span', doc.dom());
  11968. set$1(span, 'role', 'presentation');
  11969. var contents = Element.fromText(text, doc.dom());
  11970. append(span, contents);
  11971. return span;
  11972. };
  11973. var linkToDescription = function (item, token) {
  11974. var id = generate$1('ephox-alloy-aria-voice');
  11975. set$1(token, 'id', id);
  11976. set$1(item, 'aria-describedby', id);
  11977. };
  11978. var base$1 = function (getAttrs, parent, text) {
  11979. var doc = owner(parent);
  11980. var token = create$3(doc, text);
  11981. if (isFirefox$1) {
  11982. linkToDescription(parent, token);
  11983. }
  11984. setAll(token, getAttrs(text));
  11985. setAll$1(token, offscreen);
  11986. append(parent, token);
  11987. domGlobals.setTimeout(function () {
  11988. remove$1(token, 'aria-live');
  11989. remove(token);
  11990. }, 1000);
  11991. };
  11992. var getShoutAttrs = function (_text) {
  11993. return {
  11994. 'aria-live': 'assertive',
  11995. 'aria-atomic': 'true',
  11996. 'role': 'alert'
  11997. };
  11998. };
  11999. var shout = function (parent, text) {
  12000. return base$1(getShoutAttrs, parent, text);
  12001. };
  12002. var ariaElements = [
  12003. 'input',
  12004. 'textarea'
  12005. ];
  12006. var isAriaElement = function (elem) {
  12007. var name$1 = name(elem);
  12008. return contains(ariaElements, name$1);
  12009. };
  12010. var markValid = function (component, invalidConfig) {
  12011. var elem = invalidConfig.getRoot(component).getOr(component.element());
  12012. remove$4(elem, invalidConfig.invalidClass);
  12013. invalidConfig.notify.each(function (notifyInfo) {
  12014. if (isAriaElement(component.element())) {
  12015. remove$1(elem, 'title');
  12016. }
  12017. notifyInfo.getContainer(component).each(function (container) {
  12018. set(container, notifyInfo.validHtml);
  12019. });
  12020. notifyInfo.onValid(component);
  12021. });
  12022. };
  12023. var markInvalid = function (component, invalidConfig, invalidState, text) {
  12024. var elem = invalidConfig.getRoot(component).getOr(component.element());
  12025. add$2(elem, invalidConfig.invalidClass);
  12026. invalidConfig.notify.each(function (notifyInfo) {
  12027. if (isAriaElement(component.element())) {
  12028. set$1(component.element(), 'title', text);
  12029. }
  12030. shout(body(), text);
  12031. notifyInfo.getContainer(component).each(function (container) {
  12032. set(container, text);
  12033. });
  12034. notifyInfo.onInvalid(component, text);
  12035. });
  12036. };
  12037. var query = function (component, invalidConfig, invalidState) {
  12038. return invalidConfig.validator.fold(function () {
  12039. return Future.pure(Result.value(true));
  12040. }, function (validatorInfo) {
  12041. return validatorInfo.validate(component);
  12042. });
  12043. };
  12044. var run$1 = function (component, invalidConfig, invalidState) {
  12045. invalidConfig.notify.each(function (notifyInfo) {
  12046. notifyInfo.onValidate(component);
  12047. });
  12048. return query(component, invalidConfig, invalidState).map(function (valid) {
  12049. if (component.getSystem().isConnected()) {
  12050. return valid.fold(function (err) {
  12051. markInvalid(component, invalidConfig, invalidState, err);
  12052. return Result.error(err);
  12053. }, function (v) {
  12054. markValid(component, invalidConfig);
  12055. return Result.value(v);
  12056. });
  12057. } else {
  12058. return Result.error('No longer in system');
  12059. }
  12060. });
  12061. };
  12062. var isInvalid = function (component, invalidConfig) {
  12063. var elem = invalidConfig.getRoot(component).getOr(component.element());
  12064. return has$2(elem, invalidConfig.invalidClass);
  12065. };
  12066. var InvalidateApis = /*#__PURE__*/Object.freeze({
  12067. markValid: markValid,
  12068. markInvalid: markInvalid,
  12069. query: query,
  12070. run: run$1,
  12071. isInvalid: isInvalid
  12072. });
  12073. var events$b = function (invalidConfig, invalidState) {
  12074. return invalidConfig.validator.map(function (validatorInfo) {
  12075. return derive([run(validatorInfo.onEvent, function (component) {
  12076. run$1(component, invalidConfig, invalidState).get(identity);
  12077. })].concat(validatorInfo.validateOnLoad ? [runOnAttached(function (component) {
  12078. run$1(component, invalidConfig, invalidState).get(noop);
  12079. })] : []));
  12080. }).getOr({});
  12081. };
  12082. var ActiveInvalidate = /*#__PURE__*/Object.freeze({
  12083. events: events$b
  12084. });
  12085. var InvalidateSchema = [
  12086. strict$1('invalidClass'),
  12087. defaulted$1('getRoot', Option.none),
  12088. optionObjOf('notify', [
  12089. defaulted$1('aria', 'alert'),
  12090. defaulted$1('getContainer', Option.none),
  12091. defaulted$1('validHtml', ''),
  12092. onHandler('onValid'),
  12093. onHandler('onInvalid'),
  12094. onHandler('onValidate')
  12095. ]),
  12096. optionObjOf('validator', [
  12097. strict$1('validate'),
  12098. defaulted$1('onEvent', 'input'),
  12099. defaulted$1('validateOnLoad', true)
  12100. ])
  12101. ];
  12102. var Invalidating = create$1({
  12103. fields: InvalidateSchema,
  12104. name: 'invalidating',
  12105. active: ActiveInvalidate,
  12106. apis: InvalidateApis,
  12107. extra: {
  12108. validation: function (validator) {
  12109. return function (component) {
  12110. var v = Representing.getValue(component);
  12111. return Future.pure(validator(v));
  12112. };
  12113. }
  12114. }
  12115. });
  12116. var exhibit$4 = function (base, tabConfig) {
  12117. return nu$6({
  12118. attributes: wrapAll$1([{
  12119. key: tabConfig.tabAttr,
  12120. value: 'true'
  12121. }])
  12122. });
  12123. };
  12124. var ActiveTabstopping = /*#__PURE__*/Object.freeze({
  12125. exhibit: exhibit$4
  12126. });
  12127. var TabstopSchema = [defaulted$1('tabAttr', 'data-alloy-tabstop')];
  12128. var Tabstopping = create$1({
  12129. fields: TabstopSchema,
  12130. name: 'tabstopping',
  12131. active: ActiveTabstopping
  12132. });
  12133. var hexColour = function (hexString) {
  12134. return { value: constant(hexString) };
  12135. };
  12136. var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  12137. var longformRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
  12138. var isHexString = function (hex) {
  12139. return shorthandRegex.test(hex) || longformRegex.test(hex);
  12140. };
  12141. var getLongForm = function (hexColour) {
  12142. var hexString = hexColour.value().replace(shorthandRegex, function (m, r, g, b) {
  12143. return r + r + g + g + b + b;
  12144. });
  12145. return { value: constant(hexString) };
  12146. };
  12147. var extractValues = function (hexColour) {
  12148. var longForm = getLongForm(hexColour);
  12149. return longformRegex.exec(longForm.value());
  12150. };
  12151. var toHex = function (component) {
  12152. var hex = component.toString(16);
  12153. return hex.length == 1 ? '0' + hex : hex;
  12154. };
  12155. var fromRgba = function (rgbaColour) {
  12156. var value = toHex(rgbaColour.red()) + toHex(rgbaColour.green()) + toHex(rgbaColour.blue());
  12157. return hexColour(value);
  12158. };
  12159. var min = Math.min, max = Math.max, round = Math.round;
  12160. var rgbRegex = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)/;
  12161. var rgbaRegex = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d?(?:\.\d+)?)\)/;
  12162. var rgbaColour = function (red, green, blue, alpha) {
  12163. return {
  12164. red: constant(red),
  12165. green: constant(green),
  12166. blue: constant(blue),
  12167. alpha: constant(alpha)
  12168. };
  12169. };
  12170. var isRgbaComponent = function (value) {
  12171. var num = parseInt(value, 10);
  12172. return num.toString() === value && num >= 0 && num <= 255;
  12173. };
  12174. var fromHsv = function (hsv) {
  12175. var side, chroma, x, match, hue, saturation, brightness, r, g, b;
  12176. hue = (hsv.hue() || 0) % 360;
  12177. saturation = hsv.saturation() / 100;
  12178. brightness = hsv.value() / 100;
  12179. saturation = max(0, min(saturation, 1));
  12180. brightness = max(0, min(brightness, 1));
  12181. if (saturation === 0) {
  12182. r = g = b = round(255 * brightness);
  12183. return rgbaColour(r, g, b, 1);
  12184. }
  12185. side = hue / 60;
  12186. chroma = brightness * saturation;
  12187. x = chroma * (1 - Math.abs(side % 2 - 1));
  12188. match = brightness - chroma;
  12189. switch (Math.floor(side)) {
  12190. case 0:
  12191. r = chroma;
  12192. g = x;
  12193. b = 0;
  12194. break;
  12195. case 1:
  12196. r = x;
  12197. g = chroma;
  12198. b = 0;
  12199. break;
  12200. case 2:
  12201. r = 0;
  12202. g = chroma;
  12203. b = x;
  12204. break;
  12205. case 3:
  12206. r = 0;
  12207. g = x;
  12208. b = chroma;
  12209. break;
  12210. case 4:
  12211. r = x;
  12212. g = 0;
  12213. b = chroma;
  12214. break;
  12215. case 5:
  12216. r = chroma;
  12217. g = 0;
  12218. b = x;
  12219. break;
  12220. default:
  12221. r = g = b = 0;
  12222. }
  12223. r = round(255 * (r + match));
  12224. g = round(255 * (g + match));
  12225. b = round(255 * (b + match));
  12226. return rgbaColour(r, g, b, 1);
  12227. };
  12228. var fromHex = function (hexColour) {
  12229. var result = extractValues(hexColour);
  12230. var red = parseInt(result[1], 16);
  12231. var green = parseInt(result[2], 16);
  12232. var blue = parseInt(result[3], 16);
  12233. return rgbaColour(red, green, blue, 1);
  12234. };
  12235. var fromStringValues = function (red, green, blue, alpha) {
  12236. var r = parseInt(red, 10);
  12237. var g = parseInt(green, 10);
  12238. var b = parseInt(blue, 10);
  12239. var a = parseFloat(alpha);
  12240. return rgbaColour(r, g, b, a);
  12241. };
  12242. var fromString = function (rgbaString) {
  12243. if (rgbaString === 'transparent') {
  12244. return Option.some(rgbaColour(0, 0, 0, 0));
  12245. } else if (rgbRegex.test(rgbaString)) {
  12246. var rgbMatch = rgbRegex.exec(rgbaString);
  12247. return Option.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], '1'));
  12248. } else if (rgbaRegex.test(rgbaString)) {
  12249. var rgbaMatch = rgbRegex.exec(rgbaString);
  12250. return Option.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
  12251. } else {
  12252. return Option.none();
  12253. }
  12254. };
  12255. var toString = function (rgba) {
  12256. return 'rgba(' + rgba.red() + ',' + rgba.green() + ',' + rgba.blue() + ',' + rgba.alpha() + ')';
  12257. };
  12258. var red = constant(rgbaColour(255, 0, 0, 1));
  12259. var global$6 = tinymce.util.Tools.resolve('tinymce.util.LocalStorage');
  12260. var storageName = 'tinymce-custom-colors';
  12261. function ColorCache (max) {
  12262. if (max === void 0) {
  12263. max = 10;
  12264. }
  12265. var storageString = global$6.getItem(storageName);
  12266. var localstorage = isString(storageString) ? JSON.parse(storageString) : [];
  12267. var prune = function (list) {
  12268. var diff = max - list.length;
  12269. return diff < 0 ? list.slice(0, max) : list;
  12270. };
  12271. var cache = prune(localstorage);
  12272. var add = function (key) {
  12273. indexOf(cache, key).each(remove);
  12274. cache.unshift(key);
  12275. if (cache.length > max) {
  12276. cache.pop();
  12277. }
  12278. global$6.setItem(storageName, JSON.stringify(cache));
  12279. };
  12280. var remove = function (idx) {
  12281. cache.splice(idx, 1);
  12282. };
  12283. var state = function () {
  12284. return cache.slice(0);
  12285. };
  12286. return {
  12287. add: add,
  12288. state: state
  12289. };
  12290. }
  12291. var choiceItem = 'choiceitem';
  12292. var defaultColors = [
  12293. {
  12294. type: choiceItem,
  12295. text: 'Turquoise',
  12296. value: '#18BC9B'
  12297. },
  12298. {
  12299. type: choiceItem,
  12300. text: 'Green',
  12301. value: '#2FCC71'
  12302. },
  12303. {
  12304. type: choiceItem,
  12305. text: 'Blue',
  12306. value: '#3598DB'
  12307. },
  12308. {
  12309. type: choiceItem,
  12310. text: 'Purple',
  12311. value: '#9B59B6'
  12312. },
  12313. {
  12314. type: choiceItem,
  12315. text: 'Navy Blue',
  12316. value: '#34495E'
  12317. },
  12318. {
  12319. type: choiceItem,
  12320. text: 'Dark Turquoise',
  12321. value: '#18A085'
  12322. },
  12323. {
  12324. type: choiceItem,
  12325. text: 'Dark Green',
  12326. value: '#27AE60'
  12327. },
  12328. {
  12329. type: choiceItem,
  12330. text: 'Medium Blue',
  12331. value: '#2880B9'
  12332. },
  12333. {
  12334. type: choiceItem,
  12335. text: 'Medium Purple',
  12336. value: '#8E44AD'
  12337. },
  12338. {
  12339. type: choiceItem,
  12340. text: 'Midnight Blue',
  12341. value: '#2B3E50'
  12342. },
  12343. {
  12344. type: choiceItem,
  12345. text: 'Yellow',
  12346. value: '#F1C40F'
  12347. },
  12348. {
  12349. type: choiceItem,
  12350. text: 'Orange',
  12351. value: '#E67E23'
  12352. },
  12353. {
  12354. type: choiceItem,
  12355. text: 'Red',
  12356. value: '#E74C3C'
  12357. },
  12358. {
  12359. type: choiceItem,
  12360. text: 'Light Gray',
  12361. value: '#ECF0F1'
  12362. },
  12363. {
  12364. type: choiceItem,
  12365. text: 'Gray',
  12366. value: '#95A5A6'
  12367. },
  12368. {
  12369. type: choiceItem,
  12370. text: 'Dark Yellow',
  12371. value: '#F29D12'
  12372. },
  12373. {
  12374. type: choiceItem,
  12375. text: 'Dark Orange',
  12376. value: '#D35400'
  12377. },
  12378. {
  12379. type: choiceItem,
  12380. text: 'Dark Red',
  12381. value: '#E74C3C'
  12382. },
  12383. {
  12384. type: choiceItem,
  12385. text: 'Medium Gray',
  12386. value: '#BDC3C7'
  12387. },
  12388. {
  12389. type: choiceItem,
  12390. text: 'Dark Gray',
  12391. value: '#7E8C8D'
  12392. },
  12393. {
  12394. type: choiceItem,
  12395. text: 'Black',
  12396. value: '#000000'
  12397. },
  12398. {
  12399. type: choiceItem,
  12400. text: 'White',
  12401. value: '#ffffff'
  12402. }
  12403. ];
  12404. var colorCache = ColorCache(10);
  12405. var mapColors = function (colorMap) {
  12406. var i;
  12407. var colors = [];
  12408. for (i = 0; i < colorMap.length; i += 2) {
  12409. colors.push({
  12410. text: colorMap[i + 1],
  12411. value: '#' + colorMap[i],
  12412. type: 'choiceitem'
  12413. });
  12414. }
  12415. return colors;
  12416. };
  12417. var getColorCols = function (editor, defaultCols) {
  12418. return editor.getParam('color_cols', defaultCols, 'number');
  12419. };
  12420. var hasCustomColors = function (editor) {
  12421. return editor.getParam('custom_colors') !== false;
  12422. };
  12423. var getColorMap = function (editor) {
  12424. return editor.getParam('color_map');
  12425. };
  12426. var getColors = function (editor) {
  12427. var unmapped = getColorMap(editor);
  12428. return unmapped !== undefined ? mapColors(unmapped) : defaultColors;
  12429. };
  12430. var getCurrentColors = function () {
  12431. return map(colorCache.state(), function (color) {
  12432. return {
  12433. type: choiceItem,
  12434. text: color,
  12435. value: color
  12436. };
  12437. });
  12438. };
  12439. var addColor = function (color) {
  12440. colorCache.add(color);
  12441. };
  12442. var Settings = {
  12443. mapColors: mapColors,
  12444. getColorCols: getColorCols,
  12445. hasCustomColors: hasCustomColors,
  12446. getColorMap: getColorMap,
  12447. getColors: getColors,
  12448. getCurrentColors: getCurrentColors,
  12449. addColor: addColor
  12450. };
  12451. var getCurrentColor = function (editor, format) {
  12452. var color;
  12453. editor.dom.getParents(editor.selection.getStart(), function (elm) {
  12454. var value;
  12455. if (value = elm.style[format === 'forecolor' ? 'color' : 'background-color']) {
  12456. color = color ? color : value;
  12457. }
  12458. });
  12459. return color;
  12460. };
  12461. var applyFormat = function (editor, format, value) {
  12462. editor.undoManager.transact(function () {
  12463. editor.focus();
  12464. editor.formatter.apply(format, { value: value });
  12465. editor.nodeChanged();
  12466. });
  12467. };
  12468. var removeFormat = function (editor, format) {
  12469. editor.undoManager.transact(function () {
  12470. editor.focus();
  12471. editor.formatter.remove(format, { value: null }, null, true);
  12472. editor.nodeChanged();
  12473. });
  12474. };
  12475. var registerCommands = function (editor) {
  12476. editor.addCommand('mceApplyTextcolor', function (format, value) {
  12477. applyFormat(editor, format, value);
  12478. });
  12479. editor.addCommand('mceRemoveTextcolor', function (format) {
  12480. removeFormat(editor, format);
  12481. });
  12482. };
  12483. var calcCols = function (colors) {
  12484. return Math.max(5, Math.ceil(Math.sqrt(colors)));
  12485. };
  12486. var getColorCols$1 = function (editor) {
  12487. var colors = Settings.getColors(editor);
  12488. var defaultCols = calcCols(colors.length);
  12489. return Settings.getColorCols(editor, defaultCols);
  12490. };
  12491. var getAdditionalColors = function (hasCustom) {
  12492. var type = 'choiceitem';
  12493. var remove = {
  12494. type: type,
  12495. text: 'Remove color',
  12496. icon: 'color-swatch-remove-color',
  12497. value: 'remove'
  12498. };
  12499. var custom = {
  12500. type: type,
  12501. text: 'Custom color',
  12502. icon: 'color-picker',
  12503. value: 'custom'
  12504. };
  12505. return hasCustom ? [
  12506. remove,
  12507. custom
  12508. ] : [remove];
  12509. };
  12510. var applyColour = function (editor, format, value, onChoice) {
  12511. if (value === 'custom') {
  12512. var dialog = colorPickerDialog(editor);
  12513. dialog(function (colorOpt) {
  12514. colorOpt.each(function (color) {
  12515. Settings.addColor(color);
  12516. editor.execCommand('mceApplyTextcolor', format, color);
  12517. onChoice(color);
  12518. });
  12519. }, '#000000');
  12520. } else if (value === 'remove') {
  12521. onChoice('');
  12522. editor.execCommand('mceRemoveTextcolor', format);
  12523. } else {
  12524. onChoice(value);
  12525. editor.execCommand('mceApplyTextcolor', format, value);
  12526. }
  12527. };
  12528. var getFetch = function (colors, hasCustom) {
  12529. return function (callback) {
  12530. callback(colors.concat(Settings.getCurrentColors().concat(getAdditionalColors(hasCustom))));
  12531. };
  12532. };
  12533. var setIconColor = function (splitButtonApi, name, newColor) {
  12534. var setIconFillAndStroke = function (pathId, color) {
  12535. splitButtonApi.setIconFill(pathId, color);
  12536. splitButtonApi.setIconStroke(pathId, color);
  12537. };
  12538. var id = name === 'forecolor' ? 'tox-icon-text-color__color' : 'tox-icon-highlight-bg-color__color';
  12539. setIconFillAndStroke(id, newColor);
  12540. };
  12541. var registerTextColorButton = function (editor, name, format, tooltip, lastColor) {
  12542. editor.ui.registry.addSplitButton(name, {
  12543. tooltip: tooltip,
  12544. presets: 'color',
  12545. icon: name === 'forecolor' ? 'text-color' : 'highlight-bg-color',
  12546. select: function (value) {
  12547. var optCurrentRgb = Option.from(getCurrentColor(editor, format));
  12548. return optCurrentRgb.bind(function (currentRgb) {
  12549. return fromString(currentRgb).map(function (rgba) {
  12550. var currentHex = fromRgba(rgba).value();
  12551. return contains$1(value.toLowerCase(), currentHex);
  12552. });
  12553. }).getOr(false);
  12554. },
  12555. columns: getColorCols$1(editor),
  12556. fetch: getFetch(Settings.getColors(editor), Settings.hasCustomColors(editor)),
  12557. onAction: function (splitButtonApi) {
  12558. if (lastColor.get() !== null) {
  12559. applyColour(editor, format, lastColor.get(), function () {
  12560. });
  12561. }
  12562. },
  12563. onItemAction: function (splitButtonApi, value) {
  12564. applyColour(editor, format, value, function (newColour) {
  12565. lastColor.set(newColour);
  12566. setIconColor(splitButtonApi, name, newColour);
  12567. });
  12568. },
  12569. onSetup: function (splitButtonApi) {
  12570. if (lastColor.get() !== null) {
  12571. setIconColor(splitButtonApi, name, lastColor.get());
  12572. }
  12573. return function () {
  12574. };
  12575. }
  12576. });
  12577. };
  12578. var colorPickerDialog = function (editor) {
  12579. return function (callback, value) {
  12580. var getOnSubmit = function (callback) {
  12581. return function (api) {
  12582. var data = api.getData();
  12583. callback(Option.from(data.colorpicker));
  12584. api.close();
  12585. };
  12586. };
  12587. var onAction = function (api, details) {
  12588. if (details.name === 'hex-valid') {
  12589. if (details.value) {
  12590. api.enable('ok');
  12591. } else {
  12592. api.disable('ok');
  12593. }
  12594. }
  12595. };
  12596. var initialData = { colorpicker: value };
  12597. var submit = getOnSubmit(callback);
  12598. editor.windowManager.open({
  12599. title: 'Color Picker',
  12600. size: 'normal',
  12601. body: {
  12602. type: 'panel',
  12603. items: [{
  12604. type: 'colorpicker',
  12605. name: 'colorpicker',
  12606. label: 'Color'
  12607. }]
  12608. },
  12609. buttons: [
  12610. {
  12611. type: 'cancel',
  12612. name: 'cancel',
  12613. text: 'Cancel'
  12614. },
  12615. {
  12616. type: 'submit',
  12617. name: 'save',
  12618. text: 'Save',
  12619. primary: true
  12620. }
  12621. ],
  12622. initialData: initialData,
  12623. onAction: onAction,
  12624. onSubmit: submit,
  12625. onClose: function () {
  12626. },
  12627. onCancel: function () {
  12628. callback(Option.none());
  12629. }
  12630. });
  12631. };
  12632. };
  12633. var register$2 = function (editor) {
  12634. registerCommands(editor);
  12635. var lastForeColor = Cell(null);
  12636. var lastBackColor = Cell(null);
  12637. registerTextColorButton(editor, 'forecolor', 'forecolor', 'Text color', lastForeColor);
  12638. registerTextColorButton(editor, 'backcolor', 'hilitecolor', 'Background color', lastBackColor);
  12639. };
  12640. var ColorSwatch = {
  12641. register: register$2,
  12642. getFetch: getFetch,
  12643. colorPickerDialog: colorPickerDialog,
  12644. getCurrentColor: getCurrentColor,
  12645. getColorCols: getColorCols$1,
  12646. calcCols: calcCols
  12647. };
  12648. var schema$g = constant([
  12649. strict$1('dom'),
  12650. strict$1('fetch'),
  12651. onHandler('onOpen'),
  12652. onKeyboardHandler('onExecute'),
  12653. defaulted$1('getHotspot', Option.some),
  12654. defaulted$1('layouts', Option.none()),
  12655. field$1('dropdownBehaviours', [
  12656. Toggling,
  12657. Coupling,
  12658. Keying,
  12659. Focusing
  12660. ]),
  12661. strict$1('toggleClass'),
  12662. defaulted$1('eventOrder', {}),
  12663. option('lazySink'),
  12664. defaulted$1('matchWidth', false),
  12665. defaulted$1('useMinWidth', false),
  12666. option('role')
  12667. ].concat(sandboxFields()));
  12668. var parts$5 = constant([
  12669. external$1({
  12670. schema: [tieredMenuMarkers()],
  12671. name: 'menu',
  12672. defaults: function (detail) {
  12673. return { onExecute: detail.onExecute };
  12674. }
  12675. }),
  12676. partType()
  12677. ]);
  12678. var factory$6 = function (detail, components, _spec, externals) {
  12679. var _a;
  12680. var lookupAttr = function (attr) {
  12681. return readOptFrom$1(detail.dom, 'attributes').bind(function (attrs) {
  12682. return readOptFrom$1(attrs, attr);
  12683. });
  12684. };
  12685. var switchToMenu = function (sandbox) {
  12686. Sandboxing.getState(sandbox).each(function (tmenu) {
  12687. tieredMenu.highlightPrimary(tmenu);
  12688. });
  12689. };
  12690. var action = function (component) {
  12691. var onOpenSync = switchToMenu;
  12692. togglePopup(detail, function (x) {
  12693. return x;
  12694. }, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  12695. };
  12696. var apis = {
  12697. expand: function (comp) {
  12698. if (!Toggling.isOn(comp)) {
  12699. togglePopup(detail, function (x) {
  12700. return x;
  12701. }, comp, externals, noop, HighlightOnOpen.HighlightNone).get(noop);
  12702. }
  12703. },
  12704. open: function (comp) {
  12705. if (!Toggling.isOn(comp)) {
  12706. togglePopup(detail, function (x) {
  12707. return x;
  12708. }, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
  12709. }
  12710. },
  12711. isOpen: Toggling.isOn,
  12712. close: function (comp) {
  12713. if (Toggling.isOn(comp)) {
  12714. togglePopup(detail, function (x) {
  12715. return x;
  12716. }, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
  12717. }
  12718. }
  12719. };
  12720. var triggerExecute = function (comp, se) {
  12721. emitExecute(comp);
  12722. return Option.some(true);
  12723. };
  12724. return {
  12725. uid: detail.uid,
  12726. dom: detail.dom,
  12727. components: components,
  12728. behaviours: augment(detail.dropdownBehaviours, [
  12729. Toggling.config({
  12730. toggleClass: detail.toggleClass,
  12731. aria: { mode: 'expanded' }
  12732. }),
  12733. Coupling.config({
  12734. others: {
  12735. sandbox: function (hotspot) {
  12736. return makeSandbox(detail, hotspot, {
  12737. onOpen: function () {
  12738. Toggling.on(hotspot);
  12739. },
  12740. onClose: function () {
  12741. Toggling.off(hotspot);
  12742. }
  12743. });
  12744. }
  12745. }
  12746. }),
  12747. Keying.config({
  12748. mode: 'special',
  12749. onSpace: triggerExecute,
  12750. onEnter: triggerExecute,
  12751. onDown: function (comp, se) {
  12752. if (Dropdown.isOpen(comp)) {
  12753. var sandbox = Coupling.getCoupled(comp, 'sandbox');
  12754. switchToMenu(sandbox);
  12755. } else {
  12756. Dropdown.open(comp);
  12757. }
  12758. return Option.some(true);
  12759. },
  12760. onEscape: function (comp, se) {
  12761. if (Dropdown.isOpen(comp)) {
  12762. Dropdown.close(comp);
  12763. return Option.some(true);
  12764. } else {
  12765. return Option.none();
  12766. }
  12767. }
  12768. }),
  12769. Focusing.config({})
  12770. ]),
  12771. events: events$7(Option.some(action)),
  12772. eventOrder: __assign({}, detail.eventOrder, (_a = {}, _a[execute()] = [
  12773. 'disabling',
  12774. 'toggling',
  12775. 'alloy.base.behaviour'
  12776. ], _a)),
  12777. apis: apis,
  12778. domModification: {
  12779. attributes: __assign({ 'aria-haspopup': 'true' }, detail.role.fold(function () {
  12780. return {};
  12781. }, function (role) {
  12782. return { role: role };
  12783. }), detail.dom.tag === 'button' ? { type: lookupAttr('type').getOr('button') } : {})
  12784. }
  12785. };
  12786. };
  12787. var Dropdown = composite$1({
  12788. name: 'Dropdown',
  12789. configFields: schema$g(),
  12790. partFields: parts$5(),
  12791. factory: factory$6,
  12792. apis: {
  12793. open: function (apis, comp) {
  12794. return apis.open(comp);
  12795. },
  12796. expand: function (apis, comp) {
  12797. return apis.expand(comp);
  12798. },
  12799. close: function (apis, comp) {
  12800. return apis.close(comp);
  12801. },
  12802. isOpen: function (apis, comp) {
  12803. return apis.isOpen(comp);
  12804. }
  12805. }
  12806. });
  12807. var exhibit$5 = function (base, unselectConfig) {
  12808. return nu$6({
  12809. styles: {
  12810. '-webkit-user-select': 'none',
  12811. 'user-select': 'none',
  12812. '-ms-user-select': 'none',
  12813. '-moz-user-select': '-moz-none'
  12814. },
  12815. attributes: { unselectable: 'on' }
  12816. });
  12817. };
  12818. var events$c = function (unselectConfig) {
  12819. return derive([abort(selectstart(), constant(true))]);
  12820. };
  12821. var ActiveUnselecting = /*#__PURE__*/Object.freeze({
  12822. events: events$c,
  12823. exhibit: exhibit$5
  12824. });
  12825. var Unselecting = create$1({
  12826. fields: [],
  12827. name: 'unselecting',
  12828. active: ActiveUnselecting
  12829. });
  12830. var renderPanelButton = function (spec, sharedBackstage) {
  12831. return Dropdown.sketch({
  12832. dom: spec.dom,
  12833. components: spec.components,
  12834. toggleClass: 'mce-active',
  12835. dropdownBehaviours: derive$1([
  12836. Unselecting.config({}),
  12837. Tabstopping.config({})
  12838. ]),
  12839. layouts: spec.layouts,
  12840. sandboxClasses: ['tox-dialog__popups'],
  12841. lazySink: sharedBackstage.getSink,
  12842. fetch: function () {
  12843. return Future.nu(function (callback) {
  12844. return spec.fetch(callback);
  12845. }).map(function (items) {
  12846. return Option.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$1('menu-value'), items, function (value) {
  12847. spec.onItemAction(value);
  12848. }, 5, 'color', ItemResponse$1.CLOSE_ON_EXECUTE, function () {
  12849. return false;
  12850. }, sharedBackstage.providers), { movement: deriveMenuMovement(5, 'color') })));
  12851. });
  12852. },
  12853. parts: { menu: part(false, 1, 'color') }
  12854. });
  12855. };
  12856. var colorInputChangeEvent = generate$1('color-input-change');
  12857. var colorSwatchChangeEvent = generate$1('color-swatch-change');
  12858. var colorPickerCancelEvent = generate$1('color-picker-cancel');
  12859. var renderColorInput = function (spec, sharedBackstage, colorInputBackstage) {
  12860. var pField = FormField.parts().field({
  12861. factory: Input,
  12862. inputClasses: ['tox-textfield'],
  12863. onSetValue: function (c) {
  12864. return Invalidating.run(c).get(function () {
  12865. });
  12866. },
  12867. inputBehaviours: derive$1([
  12868. Tabstopping.config({}),
  12869. Invalidating.config({
  12870. invalidClass: 'tox-textbox-field-invalid',
  12871. getRoot: function (comp) {
  12872. return parent(comp.element());
  12873. },
  12874. notify: {
  12875. onValid: function (comp) {
  12876. var val = Representing.getValue(comp);
  12877. emitWith(comp, colorInputChangeEvent, { color: val });
  12878. }
  12879. },
  12880. validator: {
  12881. validateOnLoad: false,
  12882. validate: function (input) {
  12883. var inputValue = Representing.getValue(input);
  12884. if (inputValue.length === 0) {
  12885. return Future.pure(Result.value(true));
  12886. } else {
  12887. var span = Element.fromTag('span');
  12888. set$2(span, 'background-color', inputValue);
  12889. var res = getRaw(span, 'background-color').fold(function () {
  12890. return Result.error('blah');
  12891. }, function (_) {
  12892. return Result.value(inputValue);
  12893. });
  12894. return Future.pure(res);
  12895. }
  12896. }
  12897. }
  12898. })
  12899. ]),
  12900. selectOnFocus: false
  12901. });
  12902. var pLabel = spec.label.map(function (label) {
  12903. return renderLabel(label, sharedBackstage.providers);
  12904. });
  12905. var emitSwatchChange = function (colorBit, value) {
  12906. emitWith(colorBit, colorSwatchChangeEvent, { value: value });
  12907. };
  12908. var onItemAction = function (value) {
  12909. sharedBackstage.getSink().each(function (sink) {
  12910. memColorButton.getOpt(sink).each(function (colorBit) {
  12911. if (value === 'custom') {
  12912. colorInputBackstage.colorPicker(function (valueOpt) {
  12913. valueOpt.fold(function () {
  12914. return emit(colorBit, colorPickerCancelEvent);
  12915. }, function (value) {
  12916. emitSwatchChange(colorBit, value);
  12917. Settings.addColor(value);
  12918. });
  12919. }, '#ffffff');
  12920. } else if (value === 'remove') {
  12921. emitSwatchChange(colorBit, '');
  12922. } else {
  12923. emitSwatchChange(colorBit, value);
  12924. }
  12925. });
  12926. });
  12927. };
  12928. var memColorButton = record(renderPanelButton({
  12929. dom: {
  12930. tag: 'span',
  12931. attributes: { 'aria-label': sharedBackstage.providers.translate('Color swatch') }
  12932. },
  12933. layouts: Option.some({
  12934. onRtl: function () {
  12935. return [southeast$1];
  12936. },
  12937. onLtr: function () {
  12938. return [southwest$1];
  12939. }
  12940. }),
  12941. components: [],
  12942. fetch: ColorSwatch.getFetch(colorInputBackstage.getColors(), colorInputBackstage.hasCustomColors()),
  12943. onItemAction: onItemAction
  12944. }, sharedBackstage));
  12945. return FormField.sketch({
  12946. dom: {
  12947. tag: 'div',
  12948. classes: ['tox-form__group']
  12949. },
  12950. components: pLabel.toArray().concat([{
  12951. dom: {
  12952. tag: 'div',
  12953. classes: ['tox-color-input']
  12954. },
  12955. components: [
  12956. pField,
  12957. memColorButton.asSpec()
  12958. ]
  12959. }]),
  12960. fieldBehaviours: derive$1([config('form-field-events', [
  12961. run(colorInputChangeEvent, function (comp, se) {
  12962. memColorButton.getOpt(comp).each(function (colorButton) {
  12963. set$2(colorButton.element(), 'background-color', se.event().color());
  12964. });
  12965. }),
  12966. run(colorSwatchChangeEvent, function (comp, se) {
  12967. FormField.getField(comp).each(function (field) {
  12968. Representing.setValue(field, se.event().value());
  12969. Composing.getCurrent(comp).each(Focusing.focus);
  12970. });
  12971. }),
  12972. run(colorPickerCancelEvent, function (comp, se) {
  12973. FormField.getField(comp).each(function (field) {
  12974. Composing.getCurrent(comp).each(Focusing.focus);
  12975. });
  12976. })
  12977. ])])
  12978. });
  12979. };
  12980. var platform = PlatformDetection$1.detect();
  12981. var isTouch = platform.deviceType.isTouch();
  12982. var labelPart = optional({
  12983. schema: [strict$1('dom')],
  12984. name: 'label'
  12985. });
  12986. var edgePart = function (name) {
  12987. return optional({
  12988. name: '' + name + '-edge',
  12989. overrides: function (detail) {
  12990. var action = detail.model.manager.edgeActions[name];
  12991. return action.fold(function () {
  12992. return {};
  12993. }, function (a) {
  12994. var touchEvents = derive([runActionExtra(touchstart(), a, [detail])]);
  12995. var mouseEvents = derive([
  12996. runActionExtra(mousedown(), a, [detail]),
  12997. runActionExtra(mousemove(), function (l, det) {
  12998. if (det.mouseIsDown.get()) {
  12999. a(l, det);
  13000. }
  13001. }, [detail])
  13002. ]);
  13003. return { events: isTouch ? touchEvents : mouseEvents };
  13004. });
  13005. }
  13006. });
  13007. };
  13008. var tlEdgePart = edgePart('top-left');
  13009. var tedgePart = edgePart('top');
  13010. var trEdgePart = edgePart('top-right');
  13011. var redgePart = edgePart('right');
  13012. var brEdgePart = edgePart('bottom-right');
  13013. var bedgePart = edgePart('bottom');
  13014. var blEdgePart = edgePart('bottom-left');
  13015. var ledgePart = edgePart('left');
  13016. var thumbPart = required({
  13017. name: 'thumb',
  13018. defaults: constant({ dom: { styles: { position: 'absolute' } } }),
  13019. overrides: function (detail) {
  13020. return {
  13021. events: derive([
  13022. redirectToPart(touchstart(), detail, 'spectrum'),
  13023. redirectToPart(touchmove(), detail, 'spectrum'),
  13024. redirectToPart(touchend(), detail, 'spectrum'),
  13025. redirectToPart(mousedown(), detail, 'spectrum'),
  13026. redirectToPart(mousemove(), detail, 'spectrum'),
  13027. redirectToPart(mouseup(), detail, 'spectrum')
  13028. ])
  13029. };
  13030. }
  13031. });
  13032. var spectrumPart = required({
  13033. schema: [state$1('mouseIsDown', function () {
  13034. return Cell(false);
  13035. })],
  13036. name: 'spectrum',
  13037. overrides: function (detail) {
  13038. var modelDetail = detail.model;
  13039. var model = modelDetail.manager;
  13040. var setValueFrom = function (component, simulatedEvent) {
  13041. return model.getValueFromEvent(simulatedEvent).map(function (value) {
  13042. return model.setValueFrom(component, detail, value);
  13043. });
  13044. };
  13045. var touchEvents = derive([
  13046. run(touchstart(), setValueFrom),
  13047. run(touchmove(), setValueFrom)
  13048. ]);
  13049. var mouseEvents = derive([
  13050. run(mousedown(), setValueFrom),
  13051. run(mousemove(), function (spectrum, se) {
  13052. if (detail.mouseIsDown.get()) {
  13053. setValueFrom(spectrum, se);
  13054. }
  13055. })
  13056. ]);
  13057. return {
  13058. behaviours: derive$1(isTouch ? [] : [
  13059. Keying.config({
  13060. mode: 'special',
  13061. onLeft: function (spectrum) {
  13062. return model.onLeft(spectrum, detail);
  13063. },
  13064. onRight: function (spectrum) {
  13065. return model.onRight(spectrum, detail);
  13066. },
  13067. onUp: function (spectrum) {
  13068. return model.onUp(spectrum, detail);
  13069. },
  13070. onDown: function (spectrum) {
  13071. return model.onDown(spectrum, detail);
  13072. }
  13073. }),
  13074. Focusing.config({})
  13075. ]),
  13076. events: isTouch ? touchEvents : mouseEvents
  13077. };
  13078. }
  13079. });
  13080. var SliderParts = [
  13081. labelPart,
  13082. ledgePart,
  13083. redgePart,
  13084. tedgePart,
  13085. bedgePart,
  13086. tlEdgePart,
  13087. trEdgePart,
  13088. blEdgePart,
  13089. brEdgePart,
  13090. thumbPart,
  13091. spectrumPart
  13092. ];
  13093. var isTouch$1 = PlatformDetection$1.detect().deviceType.isTouch();
  13094. var _sliderChangeEvent = 'slider.change.value';
  13095. var sliderChangeEvent = constant(_sliderChangeEvent);
  13096. var getEventSource = function (simulatedEvent) {
  13097. var evt = simulatedEvent.event().raw();
  13098. if (isTouch$1) {
  13099. var touchEvent = evt;
  13100. return touchEvent.touches !== undefined && touchEvent.touches.length === 1 ? Option.some(touchEvent.touches[0]).map(function (t) {
  13101. return Position(t.clientX, t.clientY);
  13102. }) : Option.none();
  13103. } else {
  13104. var mouseEvent = evt;
  13105. return mouseEvent.clientX !== undefined ? Option.some(mouseEvent).map(function (me) {
  13106. return Position(me.clientX, me.clientY);
  13107. }) : Option.none();
  13108. }
  13109. };
  13110. var reduceBy = function (value, min, max, step) {
  13111. if (value < min) {
  13112. return value;
  13113. } else if (value > max) {
  13114. return max;
  13115. } else if (value === min) {
  13116. return min - 1;
  13117. } else {
  13118. return Math.max(min, value - step);
  13119. }
  13120. };
  13121. var increaseBy = function (value, min, max, step) {
  13122. if (value > max) {
  13123. return value;
  13124. } else if (value < min) {
  13125. return min;
  13126. } else if (value === max) {
  13127. return max + 1;
  13128. } else {
  13129. return Math.min(max, value + step);
  13130. }
  13131. };
  13132. var capValue = function (value, min, max) {
  13133. return Math.max(min, Math.min(max, value));
  13134. };
  13135. var snapValueOf = function (value, min, max, step, snapStart) {
  13136. return snapStart.fold(function () {
  13137. var initValue = value - min;
  13138. var extraValue = Math.round(initValue / step) * step;
  13139. return capValue(min + extraValue, min - 1, max + 1);
  13140. }, function (start) {
  13141. var remainder = (value - start) % step;
  13142. var adjustment = Math.round(remainder / step);
  13143. var rawSteps = Math.floor((value - start) / step);
  13144. var maxSteps = Math.floor((max - start) / step);
  13145. var numSteps = Math.min(maxSteps, rawSteps + adjustment);
  13146. var r = start + numSteps * step;
  13147. return Math.max(start, r);
  13148. });
  13149. };
  13150. var findOffsetOf = function (value, min, max) {
  13151. return Math.min(max, Math.max(value, min)) - min;
  13152. };
  13153. var findValueOf = function (args) {
  13154. var min = args.min, max = args.max, range = args.range, value = args.value, step = args.step, snap = args.snap, snapStart = args.snapStart, rounded = args.rounded, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, minBound = args.minBound, maxBound = args.maxBound, screenRange = args.screenRange;
  13155. var capMin = hasMinEdge ? min - 1 : min;
  13156. var capMax = hasMaxEdge ? max + 1 : max;
  13157. if (value < minBound) {
  13158. return capMin;
  13159. } else if (value > maxBound) {
  13160. return capMax;
  13161. } else {
  13162. var offset = findOffsetOf(value, minBound, maxBound);
  13163. var newValue = capValue(offset / screenRange * range + min, capMin, capMax);
  13164. if (snap && newValue >= min && newValue <= max) {
  13165. return snapValueOf(newValue, min, max, step, snapStart);
  13166. } else if (rounded) {
  13167. return Math.round(newValue);
  13168. } else {
  13169. return newValue;
  13170. }
  13171. }
  13172. };
  13173. var findOffsetOfValue = function (args) {
  13174. var min = args.min, max = args.max, range = args.range, value = args.value, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, maxBound = args.maxBound, maxOffset = args.maxOffset, centerMinEdge = args.centerMinEdge, centerMaxEdge = args.centerMaxEdge;
  13175. if (value < min) {
  13176. return hasMinEdge ? 0 : centerMinEdge;
  13177. } else if (value > max) {
  13178. return hasMaxEdge ? maxBound : centerMaxEdge;
  13179. } else {
  13180. return (value - min) / range * maxOffset;
  13181. }
  13182. };
  13183. var t = 'top', r$1 = 'right', b = 'bottom', l = 'left';
  13184. var minX = function (detail) {
  13185. return detail.model.minX;
  13186. };
  13187. var minY = function (detail) {
  13188. return detail.model.minY;
  13189. };
  13190. var min1X = function (detail) {
  13191. return detail.model.minX - 1;
  13192. };
  13193. var min1Y = function (detail) {
  13194. return detail.model.minY - 1;
  13195. };
  13196. var maxX = function (detail) {
  13197. return detail.model.maxX;
  13198. };
  13199. var maxY = function (detail) {
  13200. return detail.model.maxY;
  13201. };
  13202. var max1X = function (detail) {
  13203. return detail.model.maxX + 1;
  13204. };
  13205. var max1Y = function (detail) {
  13206. return detail.model.maxY + 1;
  13207. };
  13208. var range$1 = function (detail, max, min) {
  13209. return max(detail) - min(detail);
  13210. };
  13211. var xRange = function (detail) {
  13212. return range$1(detail, maxX, minX);
  13213. };
  13214. var yRange = function (detail) {
  13215. return range$1(detail, maxY, minY);
  13216. };
  13217. var halfX = function (detail) {
  13218. return xRange(detail) / 2;
  13219. };
  13220. var halfY = function (detail) {
  13221. return yRange(detail) / 2;
  13222. };
  13223. var step = function (detail) {
  13224. return detail.stepSize;
  13225. };
  13226. var snap = function (detail) {
  13227. return detail.snapToGrid;
  13228. };
  13229. var snapStart = function (detail) {
  13230. return detail.snapStart;
  13231. };
  13232. var rounded = function (detail) {
  13233. return detail.rounded;
  13234. };
  13235. var hasEdge = function (detail, edgeName) {
  13236. return detail[edgeName + '-edge'] !== undefined;
  13237. };
  13238. var hasLEdge = function (detail) {
  13239. return hasEdge(detail, l);
  13240. };
  13241. var hasREdge = function (detail) {
  13242. return hasEdge(detail, r$1);
  13243. };
  13244. var hasTEdge = function (detail) {
  13245. return hasEdge(detail, t);
  13246. };
  13247. var hasBEdge = function (detail) {
  13248. return hasEdge(detail, b);
  13249. };
  13250. var currentValue = function (detail) {
  13251. return detail.model.value.get();
  13252. };
  13253. var xValue = function (x) {
  13254. return { x: constant(x) };
  13255. };
  13256. var yValue = function (y) {
  13257. return { y: constant(y) };
  13258. };
  13259. var xyValue = function (x, y) {
  13260. return {
  13261. x: constant(x),
  13262. y: constant(y)
  13263. };
  13264. };
  13265. var fireSliderChange = function (component, value) {
  13266. emitWith(component, sliderChangeEvent(), { value: value });
  13267. };
  13268. var setToTLEdgeXY = function (edge, detail) {
  13269. fireSliderChange(edge, xyValue(min1X(detail), min1Y(detail)));
  13270. };
  13271. var setToTEdge = function (edge, detail) {
  13272. fireSliderChange(edge, yValue(min1Y(detail)));
  13273. };
  13274. var setToTEdgeXY = function (edge, detail) {
  13275. fireSliderChange(edge, xyValue(halfX(detail), min1Y(detail)));
  13276. };
  13277. var setToTREdgeXY = function (edge, detail) {
  13278. fireSliderChange(edge, xyValue(max1X(detail), min1Y(detail)));
  13279. };
  13280. var setToREdge = function (edge, detail) {
  13281. fireSliderChange(edge, xValue(max1X(detail)));
  13282. };
  13283. var setToREdgeXY = function (edge, detail) {
  13284. fireSliderChange(edge, xyValue(max1X(detail), halfY(detail)));
  13285. };
  13286. var setToBREdgeXY = function (edge, detail) {
  13287. fireSliderChange(edge, xyValue(max1X(detail), max1Y(detail)));
  13288. };
  13289. var setToBEdge = function (edge, detail) {
  13290. fireSliderChange(edge, yValue(max1Y(detail)));
  13291. };
  13292. var setToBEdgeXY = function (edge, detail) {
  13293. fireSliderChange(edge, xyValue(halfX(detail), max1Y(detail)));
  13294. };
  13295. var setToBLEdgeXY = function (edge, detail) {
  13296. fireSliderChange(edge, xyValue(min1X(detail), max1Y(detail)));
  13297. };
  13298. var setToLEdge = function (edge, detail) {
  13299. fireSliderChange(edge, xValue(min1X(detail)));
  13300. };
  13301. var setToLEdgeXY = function (edge, detail) {
  13302. fireSliderChange(edge, xyValue(min1X(detail), halfY(detail)));
  13303. };
  13304. var top = 'top', right = 'right', bottom = 'bottom', left = 'left', width = 'width', height = 'height';
  13305. var getBounds = function (component) {
  13306. return component.element().dom().getBoundingClientRect();
  13307. };
  13308. var getBoundsProperty = function (bounds, property) {
  13309. return bounds[property];
  13310. };
  13311. var getMinXBounds = function (component) {
  13312. var bounds = getBounds(component);
  13313. return getBoundsProperty(bounds, left);
  13314. };
  13315. var getMaxXBounds = function (component) {
  13316. var bounds = getBounds(component);
  13317. return getBoundsProperty(bounds, right);
  13318. };
  13319. var getMinYBounds = function (component) {
  13320. var bounds = getBounds(component);
  13321. return getBoundsProperty(bounds, top);
  13322. };
  13323. var getMaxYBounds = function (component) {
  13324. var bounds = getBounds(component);
  13325. return getBoundsProperty(bounds, bottom);
  13326. };
  13327. var getXScreenRange = function (component) {
  13328. var bounds = getBounds(component);
  13329. return getBoundsProperty(bounds, width);
  13330. };
  13331. var getYScreenRange = function (component) {
  13332. var bounds = getBounds(component);
  13333. return getBoundsProperty(bounds, height);
  13334. };
  13335. var getCenterOffsetOf = function (componentMinEdge, componentMaxEdge, spectrumMinEdge) {
  13336. return (componentMinEdge + componentMaxEdge) / 2 - spectrumMinEdge;
  13337. };
  13338. var getXCenterOffSetOf = function (component, spectrum) {
  13339. var componentBounds = getBounds(component);
  13340. var spectrumBounds = getBounds(spectrum);
  13341. var componentMinEdge = getBoundsProperty(componentBounds, left);
  13342. var componentMaxEdge = getBoundsProperty(componentBounds, right);
  13343. var spectrumMinEdge = getBoundsProperty(spectrumBounds, left);
  13344. return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
  13345. };
  13346. var getYCenterOffSetOf = function (component, spectrum) {
  13347. var componentBounds = getBounds(component);
  13348. var spectrumBounds = getBounds(spectrum);
  13349. var componentMinEdge = getBoundsProperty(componentBounds, top);
  13350. var componentMaxEdge = getBoundsProperty(componentBounds, bottom);
  13351. var spectrumMinEdge = getBoundsProperty(spectrumBounds, top);
  13352. return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
  13353. };
  13354. var fireSliderChange$1 = function (spectrum, value) {
  13355. emitWith(spectrum, sliderChangeEvent(), { value: value });
  13356. };
  13357. var sliderValue = function (x) {
  13358. return { x: constant(x) };
  13359. };
  13360. var findValueOfOffset = function (spectrum, detail, left) {
  13361. var args = {
  13362. min: minX(detail),
  13363. max: maxX(detail),
  13364. range: xRange(detail),
  13365. value: left,
  13366. step: step(detail),
  13367. snap: snap(detail),
  13368. snapStart: snapStart(detail),
  13369. rounded: rounded(detail),
  13370. hasMinEdge: hasLEdge(detail),
  13371. hasMaxEdge: hasREdge(detail),
  13372. minBound: getMinXBounds(spectrum),
  13373. maxBound: getMaxXBounds(spectrum),
  13374. screenRange: getXScreenRange(spectrum)
  13375. };
  13376. return findValueOf(args);
  13377. };
  13378. var setValueFrom = function (spectrum, detail, value) {
  13379. var xValue = findValueOfOffset(spectrum, detail, value);
  13380. var sliderVal = sliderValue(xValue);
  13381. fireSliderChange$1(spectrum, sliderVal);
  13382. return xValue;
  13383. };
  13384. var setToMin = function (spectrum, detail) {
  13385. var min = minX(detail);
  13386. fireSliderChange$1(spectrum, sliderValue(min));
  13387. };
  13388. var setToMax = function (spectrum, detail) {
  13389. var max = maxX(detail);
  13390. fireSliderChange$1(spectrum, sliderValue(max));
  13391. };
  13392. var moveBy = function (direction, spectrum, detail) {
  13393. var f = direction > 0 ? increaseBy : reduceBy;
  13394. var xValue = f(currentValue(detail).x(), minX(detail), maxX(detail), step(detail));
  13395. fireSliderChange$1(spectrum, sliderValue(xValue));
  13396. return Option.some(xValue);
  13397. };
  13398. var handleMovement = function (direction) {
  13399. return function (spectrum, detail) {
  13400. return moveBy(direction, spectrum, detail).map(function () {
  13401. return true;
  13402. });
  13403. };
  13404. };
  13405. var getValueFromEvent = function (simulatedEvent) {
  13406. var pos = getEventSource(simulatedEvent);
  13407. return pos.map(function (p) {
  13408. return p.left();
  13409. });
  13410. };
  13411. var findOffsetOfValue$1 = function (spectrum, detail, value, minEdge, maxEdge) {
  13412. var minOffset = 0;
  13413. var maxOffset = getXScreenRange(spectrum);
  13414. var centerMinEdge = minEdge.bind(function (edge) {
  13415. return Option.some(getXCenterOffSetOf(edge, spectrum));
  13416. }).getOr(minOffset);
  13417. var centerMaxEdge = maxEdge.bind(function (edge) {
  13418. return Option.some(getXCenterOffSetOf(edge, spectrum));
  13419. }).getOr(maxOffset);
  13420. var args = {
  13421. min: minX(detail),
  13422. max: maxX(detail),
  13423. range: xRange(detail),
  13424. value: value,
  13425. hasMinEdge: hasLEdge(detail),
  13426. hasMaxEdge: hasREdge(detail),
  13427. minBound: getMinXBounds(spectrum),
  13428. minOffset: minOffset,
  13429. maxBound: getMaxXBounds(spectrum),
  13430. maxOffset: maxOffset,
  13431. centerMinEdge: centerMinEdge,
  13432. centerMaxEdge: centerMaxEdge
  13433. };
  13434. return findOffsetOfValue(args);
  13435. };
  13436. var findPositionOfValue = function (slider, spectrum, value, minEdge, maxEdge, detail) {
  13437. var offset = findOffsetOfValue$1(spectrum, detail, value, minEdge, maxEdge);
  13438. return getMinXBounds(spectrum) - getMinXBounds(slider) + offset;
  13439. };
  13440. var setPositionFromValue = function (slider, thumb, detail, edges) {
  13441. var value = currentValue(detail);
  13442. var pos = findPositionOfValue(slider, edges.getSpectrum(slider), value.x(), edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
  13443. var thumbRadius = get$7(thumb.element()) / 2;
  13444. set$2(thumb.element(), 'left', pos - thumbRadius + 'px');
  13445. };
  13446. var onLeft = handleMovement(-1);
  13447. var onRight = handleMovement(1);
  13448. var onUp = Option.none;
  13449. var onDown = Option.none;
  13450. var edgeActions = {
  13451. 'top-left': Option.none(),
  13452. 'top': Option.none(),
  13453. 'top-right': Option.none(),
  13454. 'right': Option.some(setToREdge),
  13455. 'bottom-right': Option.none(),
  13456. 'bottom': Option.none(),
  13457. 'bottom-left': Option.none(),
  13458. 'left': Option.some(setToLEdge)
  13459. };
  13460. var HorizontalModel = /*#__PURE__*/Object.freeze({
  13461. setValueFrom: setValueFrom,
  13462. setToMin: setToMin,
  13463. setToMax: setToMax,
  13464. findValueOfOffset: findValueOfOffset,
  13465. getValueFromEvent: getValueFromEvent,
  13466. findPositionOfValue: findPositionOfValue,
  13467. setPositionFromValue: setPositionFromValue,
  13468. onLeft: onLeft,
  13469. onRight: onRight,
  13470. onUp: onUp,
  13471. onDown: onDown,
  13472. edgeActions: edgeActions
  13473. });
  13474. var fireSliderChange$2 = function (spectrum, value) {
  13475. emitWith(spectrum, sliderChangeEvent(), { value: value });
  13476. };
  13477. var sliderValue$1 = function (y) {
  13478. return { y: constant(y) };
  13479. };
  13480. var findValueOfOffset$1 = function (spectrum, detail, top) {
  13481. var args = {
  13482. min: minY(detail),
  13483. max: maxY(detail),
  13484. range: yRange(detail),
  13485. value: top,
  13486. step: step(detail),
  13487. snap: snap(detail),
  13488. snapStart: snapStart(detail),
  13489. rounded: rounded(detail),
  13490. hasMinEdge: hasTEdge(detail),
  13491. hasMaxEdge: hasBEdge(detail),
  13492. minBound: getMinYBounds(spectrum),
  13493. maxBound: getMaxYBounds(spectrum),
  13494. screenRange: getYScreenRange(spectrum)
  13495. };
  13496. return findValueOf(args);
  13497. };
  13498. var setValueFrom$1 = function (spectrum, detail, value) {
  13499. var yValue = findValueOfOffset$1(spectrum, detail, value);
  13500. var sliderVal = sliderValue$1(yValue);
  13501. fireSliderChange$2(spectrum, sliderVal);
  13502. return yValue;
  13503. };
  13504. var setToMin$1 = function (spectrum, detail) {
  13505. var min = minY(detail);
  13506. fireSliderChange$2(spectrum, sliderValue$1(min));
  13507. };
  13508. var setToMax$1 = function (spectrum, detail) {
  13509. var max = maxY(detail);
  13510. fireSliderChange$2(spectrum, sliderValue$1(max));
  13511. };
  13512. var moveBy$1 = function (direction, spectrum, detail) {
  13513. var f = direction > 0 ? increaseBy : reduceBy;
  13514. var yValue = f(currentValue(detail).y(), minY(detail), maxY(detail), step(detail));
  13515. fireSliderChange$2(spectrum, sliderValue$1(yValue));
  13516. return Option.some(yValue);
  13517. };
  13518. var handleMovement$1 = function (direction) {
  13519. return function (spectrum, detail) {
  13520. return moveBy$1(direction, spectrum, detail).map(function () {
  13521. return true;
  13522. });
  13523. };
  13524. };
  13525. var getValueFromEvent$1 = function (simulatedEvent) {
  13526. var pos = getEventSource(simulatedEvent);
  13527. return pos.map(function (p) {
  13528. return p.top();
  13529. });
  13530. };
  13531. var findOffsetOfValue$2 = function (spectrum, detail, value, minEdge, maxEdge) {
  13532. var minOffset = 0;
  13533. var maxOffset = getYScreenRange(spectrum);
  13534. var centerMinEdge = minEdge.bind(function (edge) {
  13535. return Option.some(getYCenterOffSetOf(edge, spectrum));
  13536. }).getOr(minOffset);
  13537. var centerMaxEdge = maxEdge.bind(function (edge) {
  13538. return Option.some(getYCenterOffSetOf(edge, spectrum));
  13539. }).getOr(maxOffset);
  13540. var args = {
  13541. min: minY(detail),
  13542. max: maxY(detail),
  13543. range: yRange(detail),
  13544. value: value,
  13545. hasMinEdge: hasTEdge(detail),
  13546. hasMaxEdge: hasBEdge(detail),
  13547. minBound: getMinYBounds(spectrum),
  13548. minOffset: minOffset,
  13549. maxBound: getMaxYBounds(spectrum),
  13550. maxOffset: maxOffset,
  13551. centerMinEdge: centerMinEdge,
  13552. centerMaxEdge: centerMaxEdge
  13553. };
  13554. return findOffsetOfValue(args);
  13555. };
  13556. var findPositionOfValue$1 = function (slider, spectrum, value, minEdge, maxEdge, detail) {
  13557. var offset = findOffsetOfValue$2(spectrum, detail, value, minEdge, maxEdge);
  13558. return getMinYBounds(spectrum) - getMinYBounds(slider) + offset;
  13559. };
  13560. var setPositionFromValue$1 = function (slider, thumb, detail, edges) {
  13561. var value = currentValue(detail);
  13562. var pos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value.y(), edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
  13563. var thumbRadius = get$8(thumb.element()) / 2;
  13564. set$2(thumb.element(), 'top', pos - thumbRadius + 'px');
  13565. };
  13566. var onLeft$1 = Option.none;
  13567. var onRight$1 = Option.none;
  13568. var onUp$1 = handleMovement$1(-1);
  13569. var onDown$1 = handleMovement$1(1);
  13570. var edgeActions$1 = {
  13571. 'top-left': Option.none(),
  13572. 'top': Option.some(setToTEdge),
  13573. 'top-right': Option.none(),
  13574. 'right': Option.none(),
  13575. 'bottom-right': Option.none(),
  13576. 'bottom': Option.some(setToBEdge),
  13577. 'bottom-left': Option.none(),
  13578. 'left': Option.none()
  13579. };
  13580. var VerticalModel = /*#__PURE__*/Object.freeze({
  13581. setValueFrom: setValueFrom$1,
  13582. setToMin: setToMin$1,
  13583. setToMax: setToMax$1,
  13584. findValueOfOffset: findValueOfOffset$1,
  13585. getValueFromEvent: getValueFromEvent$1,
  13586. findPositionOfValue: findPositionOfValue$1,
  13587. setPositionFromValue: setPositionFromValue$1,
  13588. onLeft: onLeft$1,
  13589. onRight: onRight$1,
  13590. onUp: onUp$1,
  13591. onDown: onDown$1,
  13592. edgeActions: edgeActions$1
  13593. });
  13594. var fireSliderChange$3 = function (spectrum, value) {
  13595. emitWith(spectrum, sliderChangeEvent(), { value: value });
  13596. };
  13597. var sliderValue$2 = function (x, y) {
  13598. return {
  13599. x: constant(x),
  13600. y: constant(y)
  13601. };
  13602. };
  13603. var setValueFrom$2 = function (spectrum, detail, value) {
  13604. var xValue = findValueOfOffset(spectrum, detail, value.left());
  13605. var yValue = findValueOfOffset$1(spectrum, detail, value.top());
  13606. var val = sliderValue$2(xValue, yValue);
  13607. fireSliderChange$3(spectrum, val);
  13608. return val;
  13609. };
  13610. var moveBy$2 = function (direction, isVerticalMovement, spectrum, detail) {
  13611. var f = direction > 0 ? increaseBy : reduceBy;
  13612. var xValue = isVerticalMovement ? currentValue(detail).x() : f(currentValue(detail).x(), minX(detail), maxX(detail), step(detail));
  13613. var yValue = !isVerticalMovement ? currentValue(detail).y() : f(currentValue(detail).y(), minY(detail), maxY(detail), step(detail));
  13614. fireSliderChange$3(spectrum, sliderValue$2(xValue, yValue));
  13615. return Option.some(xValue);
  13616. };
  13617. var handleMovement$2 = function (direction, isVerticalMovement) {
  13618. return function (spectrum, detail) {
  13619. return moveBy$2(direction, isVerticalMovement, spectrum, detail).map(function () {
  13620. return true;
  13621. });
  13622. };
  13623. };
  13624. var setToMin$2 = function (spectrum, detail) {
  13625. var mX = minX(detail);
  13626. var mY = minY(detail);
  13627. fireSliderChange$3(spectrum, sliderValue$2(mX, mY));
  13628. };
  13629. var setToMax$2 = function (spectrum, detail) {
  13630. var mX = maxX(detail);
  13631. var mY = maxY(detail);
  13632. fireSliderChange$3(spectrum, sliderValue$2(mX, mY));
  13633. };
  13634. var getValueFromEvent$2 = function (simulatedEvent) {
  13635. return getEventSource(simulatedEvent);
  13636. };
  13637. var setPositionFromValue$2 = function (slider, thumb, detail, edges) {
  13638. var value = currentValue(detail);
  13639. var xPos = findPositionOfValue(slider, edges.getSpectrum(slider), value.x(), edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
  13640. var yPos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value.y(), edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
  13641. var thumbXRadius = get$7(thumb.element()) / 2;
  13642. var thumbYRadius = get$8(thumb.element()) / 2;
  13643. set$2(thumb.element(), 'left', xPos - thumbXRadius + 'px');
  13644. set$2(thumb.element(), 'top', yPos - thumbYRadius + 'px');
  13645. };
  13646. var onLeft$2 = handleMovement$2(-1, false);
  13647. var onRight$2 = handleMovement$2(1, false);
  13648. var onUp$2 = handleMovement$2(-1, true);
  13649. var onDown$2 = handleMovement$2(1, true);
  13650. var edgeActions$2 = {
  13651. 'top-left': Option.some(setToTLEdgeXY),
  13652. 'top': Option.some(setToTEdgeXY),
  13653. 'top-right': Option.some(setToTREdgeXY),
  13654. 'right': Option.some(setToREdgeXY),
  13655. 'bottom-right': Option.some(setToBREdgeXY),
  13656. 'bottom': Option.some(setToBEdgeXY),
  13657. 'bottom-left': Option.some(setToBLEdgeXY),
  13658. 'left': Option.some(setToLEdgeXY)
  13659. };
  13660. var TwoDModel = /*#__PURE__*/Object.freeze({
  13661. setValueFrom: setValueFrom$2,
  13662. setToMin: setToMin$2,
  13663. setToMax: setToMax$2,
  13664. getValueFromEvent: getValueFromEvent$2,
  13665. setPositionFromValue: setPositionFromValue$2,
  13666. onLeft: onLeft$2,
  13667. onRight: onRight$2,
  13668. onUp: onUp$2,
  13669. onDown: onDown$2,
  13670. edgeActions: edgeActions$2
  13671. });
  13672. var isTouch$2 = PlatformDetection$1.detect().deviceType.isTouch();
  13673. var SliderSchema = [
  13674. defaulted$1('stepSize', 1),
  13675. defaulted$1('onChange', noop),
  13676. defaulted$1('onChoose', noop),
  13677. defaulted$1('onInit', noop),
  13678. defaulted$1('onDragStart', noop),
  13679. defaulted$1('onDragEnd', noop),
  13680. defaulted$1('snapToGrid', false),
  13681. defaulted$1('rounded', true),
  13682. option('snapStart'),
  13683. strictOf('model', choose$1('mode', {
  13684. x: [
  13685. defaulted$1('minX', 0),
  13686. defaulted$1('maxX', 100),
  13687. state$1('value', function (spec) {
  13688. return Cell(spec.mode.minX);
  13689. }),
  13690. strict$1('getInitialValue'),
  13691. output('manager', HorizontalModel)
  13692. ],
  13693. y: [
  13694. defaulted$1('minY', 0),
  13695. defaulted$1('maxY', 100),
  13696. state$1('value', function (spec) {
  13697. return Cell(spec.mode.minY);
  13698. }),
  13699. strict$1('getInitialValue'),
  13700. output('manager', VerticalModel)
  13701. ],
  13702. xy: [
  13703. defaulted$1('minX', 0),
  13704. defaulted$1('maxX', 100),
  13705. defaulted$1('minY', 0),
  13706. defaulted$1('maxY', 100),
  13707. state$1('value', function (spec) {
  13708. return Cell({
  13709. x: constant(spec.mode.minX),
  13710. y: constant(spec.mode.minY)
  13711. });
  13712. }),
  13713. strict$1('getInitialValue'),
  13714. output('manager', TwoDModel)
  13715. ]
  13716. })),
  13717. field$1('sliderBehaviours', [
  13718. Keying,
  13719. Representing
  13720. ])
  13721. ].concat(!isTouch$2 ? [state$1('mouseIsDown', function () {
  13722. return Cell(false);
  13723. })] : []);
  13724. var isTouch$3 = PlatformDetection$1.detect().deviceType.isTouch();
  13725. var sketch = function (detail, components, _spec, _externals) {
  13726. var getThumb = function (component) {
  13727. return getPartOrDie(component, detail, 'thumb');
  13728. };
  13729. var getSpectrum = function (component) {
  13730. return getPartOrDie(component, detail, 'spectrum');
  13731. };
  13732. var getLeftEdge = function (component) {
  13733. return getPart(component, detail, 'left-edge');
  13734. };
  13735. var getRightEdge = function (component) {
  13736. return getPart(component, detail, 'right-edge');
  13737. };
  13738. var getTopEdge = function (component) {
  13739. return getPart(component, detail, 'top-edge');
  13740. };
  13741. var getBottomEdge = function (component) {
  13742. return getPart(component, detail, 'bottom-edge');
  13743. };
  13744. var modelDetail = detail.model;
  13745. var model = modelDetail.manager;
  13746. var refresh = function (slider, thumb) {
  13747. model.setPositionFromValue(slider, thumb, detail, {
  13748. getLeftEdge: getLeftEdge,
  13749. getRightEdge: getRightEdge,
  13750. getTopEdge: getTopEdge,
  13751. getBottomEdge: getBottomEdge,
  13752. getSpectrum: getSpectrum
  13753. });
  13754. };
  13755. var changeValue = function (slider, newValue) {
  13756. modelDetail.value.set(newValue);
  13757. var thumb = getThumb(slider);
  13758. refresh(slider, thumb);
  13759. detail.onChange(slider, thumb, newValue);
  13760. return Option.some(true);
  13761. };
  13762. var resetToMin = function (slider) {
  13763. model.setToMin(slider, detail);
  13764. };
  13765. var resetToMax = function (slider) {
  13766. model.setToMax(slider, detail);
  13767. };
  13768. var touchEvents = [
  13769. run(touchstart(), function (slider, _simulatedEvent) {
  13770. detail.onDragStart(slider, getThumb(slider));
  13771. }),
  13772. run(touchend(), function (slider, _simulatedEvent) {
  13773. detail.onDragEnd(slider, getThumb(slider));
  13774. })
  13775. ];
  13776. var mouseEvents = [
  13777. run(mousedown(), function (slider, simulatedEvent) {
  13778. simulatedEvent.stop();
  13779. detail.onDragStart(slider, getThumb(slider));
  13780. detail.mouseIsDown.set(true);
  13781. }),
  13782. run(mouseup(), function (slider, _simulatedEvent) {
  13783. detail.onDragEnd(slider, getThumb(slider));
  13784. })
  13785. ];
  13786. var uiEventsArr = isTouch$3 ? touchEvents : mouseEvents;
  13787. return {
  13788. uid: detail.uid,
  13789. dom: detail.dom,
  13790. components: components,
  13791. behaviours: augment(detail.sliderBehaviours, flatten([
  13792. !isTouch$3 ? [Keying.config({
  13793. mode: 'special',
  13794. focusIn: function (slider) {
  13795. return getPart(slider, detail, 'spectrum').map(Keying.focusIn).map(constant(true));
  13796. }
  13797. })] : [],
  13798. [
  13799. Representing.config({
  13800. store: {
  13801. mode: 'manual',
  13802. getValue: function (_) {
  13803. return modelDetail.value.get();
  13804. }
  13805. }
  13806. }),
  13807. Receiving.config({
  13808. channels: {
  13809. 'mouse.released': {
  13810. onReceive: function (slider, se) {
  13811. var wasDown = detail.mouseIsDown.get();
  13812. detail.mouseIsDown.set(false);
  13813. if (wasDown) {
  13814. getPart(slider, detail, 'thumb').each(function (thumb) {
  13815. var value = modelDetail.value.get();
  13816. detail.onChoose(slider, thumb, value);
  13817. });
  13818. }
  13819. }
  13820. }
  13821. }
  13822. })
  13823. ]
  13824. ])),
  13825. events: derive([
  13826. run(sliderChangeEvent(), function (slider, simulatedEvent) {
  13827. changeValue(slider, simulatedEvent.event().value());
  13828. }),
  13829. runOnAttached(function (slider, simulatedEvent) {
  13830. var getInitial = modelDetail.getInitialValue();
  13831. modelDetail.value.set(getInitial);
  13832. var thumb = getThumb(slider);
  13833. refresh(slider, thumb);
  13834. var spectrum = getSpectrum(slider);
  13835. detail.onInit(slider, thumb, spectrum, modelDetail.value.get());
  13836. })
  13837. ].concat(uiEventsArr)),
  13838. apis: {
  13839. resetToMin: resetToMin,
  13840. resetToMax: resetToMax,
  13841. changeValue: changeValue,
  13842. refresh: refresh
  13843. },
  13844. domModification: { styles: { position: 'relative' } }
  13845. };
  13846. };
  13847. var Slider = composite$1({
  13848. name: 'Slider',
  13849. configFields: SliderSchema,
  13850. partFields: SliderParts,
  13851. factory: sketch,
  13852. apis: {
  13853. resetToMin: function (apis, slider) {
  13854. apis.resetToMin(slider);
  13855. },
  13856. resetToMax: function (apis, slider) {
  13857. apis.resetToMax(slider);
  13858. },
  13859. refresh: function (apis, slider) {
  13860. apis.refresh(slider);
  13861. }
  13862. }
  13863. });
  13864. var fieldsUpdate = constant(generate$1('rgb-hex-update'));
  13865. var sliderUpdate = constant(generate$1('slider-update'));
  13866. var paletteUpdate = constant(generate$1('palette-update'));
  13867. var paletteFactory = function (translate, getClass) {
  13868. var spectrum = Slider.parts().spectrum({
  13869. dom: {
  13870. tag: 'canvas',
  13871. attributes: { role: 'presentation' },
  13872. classes: [getClass('sv-palette-spectrum')]
  13873. }
  13874. });
  13875. var thumb = Slider.parts().thumb({
  13876. dom: {
  13877. tag: 'div',
  13878. attributes: { role: 'presentation' },
  13879. classes: [getClass('sv-palette-thumb')],
  13880. innerHtml: '<div class=' + getClass('sv-palette-inner-thumb') + ' role="presentation"></div>'
  13881. }
  13882. });
  13883. var setColour = function (canvas, rgba) {
  13884. var width = canvas.width, height = canvas.height;
  13885. var ctx = canvas.getContext('2d');
  13886. ctx.fillStyle = rgba;
  13887. ctx.fillRect(0, 0, width, height);
  13888. var grdWhite = ctx.createLinearGradient(0, 0, width, 0);
  13889. grdWhite.addColorStop(0, 'rgba(255,255,255,1)');
  13890. grdWhite.addColorStop(1, 'rgba(255,255,255,0)');
  13891. ctx.fillStyle = grdWhite;
  13892. ctx.fillRect(0, 0, width, height);
  13893. var grdBlack = ctx.createLinearGradient(0, 0, 0, height);
  13894. grdBlack.addColorStop(0, 'rgba(0,0,0,0)');
  13895. grdBlack.addColorStop(1, 'rgba(0,0,0,1)');
  13896. ctx.fillStyle = grdBlack;
  13897. ctx.fillRect(0, 0, width, height);
  13898. };
  13899. var setSliderColour = function (slider, rgba) {
  13900. var canvas = slider.components()[0].element().dom();
  13901. setColour(canvas, toString(rgba));
  13902. };
  13903. var factory = function (detail) {
  13904. var getInitialValue = constant({
  13905. x: constant(0),
  13906. y: constant(0)
  13907. });
  13908. var onChange = function (slider, _thumb, value) {
  13909. emitWith(slider, paletteUpdate(), { value: value });
  13910. };
  13911. var onInit = function (_slider, _thumb, spectrum, _value) {
  13912. setColour(spectrum.element().dom(), toString(red()));
  13913. };
  13914. var sliderBehaviours = derive$1([
  13915. Composing.config({ find: Option.some }),
  13916. Focusing.config({})
  13917. ]);
  13918. return Slider.sketch({
  13919. dom: {
  13920. tag: 'div',
  13921. attributes: { role: 'presentation' },
  13922. classes: [getClass('sv-palette')]
  13923. },
  13924. model: {
  13925. mode: 'xy',
  13926. getInitialValue: getInitialValue
  13927. },
  13928. rounded: false,
  13929. components: [
  13930. spectrum,
  13931. thumb
  13932. ],
  13933. onChange: onChange,
  13934. onInit: onInit,
  13935. sliderBehaviours: sliderBehaviours
  13936. });
  13937. };
  13938. var SaturationBrightnessPalette = single$2({
  13939. factory: factory,
  13940. name: 'SaturationBrightnessPalette',
  13941. configFields: [],
  13942. apis: {
  13943. setRgba: function (apis, slider, rgba) {
  13944. setSliderColour(slider, rgba);
  13945. }
  13946. },
  13947. extraApis: {}
  13948. });
  13949. return SaturationBrightnessPalette;
  13950. };
  13951. var SaturationBrightnessPalette = { paletteFactory: paletteFactory };
  13952. var sliderFactory = function (translate, getClass) {
  13953. var spectrum = Slider.parts().spectrum({
  13954. dom: {
  13955. tag: 'div',
  13956. classes: [getClass('hue-slider-spectrum')],
  13957. attributes: { role: 'presentation' }
  13958. }
  13959. });
  13960. var thumb = Slider.parts().thumb({
  13961. dom: {
  13962. tag: 'div',
  13963. classes: [getClass('hue-slider-thumb')],
  13964. attributes: { role: 'presentation' }
  13965. }
  13966. });
  13967. return Slider.sketch({
  13968. dom: {
  13969. tag: 'div',
  13970. classes: [getClass('hue-slider')],
  13971. attributes: { role: 'presentation' }
  13972. },
  13973. rounded: false,
  13974. model: {
  13975. mode: 'y',
  13976. getInitialValue: constant({ y: constant(0) })
  13977. },
  13978. components: [
  13979. spectrum,
  13980. thumb
  13981. ],
  13982. sliderBehaviours: derive$1([Focusing.config({})]),
  13983. onChange: function (slider, thumb, value) {
  13984. emitWith(slider, sliderUpdate(), { value: value });
  13985. }
  13986. });
  13987. };
  13988. var HueSlider = { sliderFactory: sliderFactory };
  13989. var owner$3 = 'form';
  13990. var schema$h = [field$1('formBehaviours', [Representing])];
  13991. var getPartName = function (name) {
  13992. return '<alloy.field.' + name + '>';
  13993. };
  13994. var sketch$1 = function (fSpec) {
  13995. var parts = function () {
  13996. var record = [];
  13997. var field = function (name, config) {
  13998. record.push(name);
  13999. return generateOne(owner$3, getPartName(name), config);
  14000. };
  14001. return {
  14002. field: field,
  14003. record: function () {
  14004. return record;
  14005. }
  14006. };
  14007. }();
  14008. var spec = fSpec(parts);
  14009. var partNames = parts.record();
  14010. var fieldParts = map(partNames, function (n) {
  14011. return required({
  14012. name: n,
  14013. pname: getPartName(n)
  14014. });
  14015. });
  14016. return composite(owner$3, schema$h, fieldParts, make$4, spec);
  14017. };
  14018. var toResult$1 = function (o, e) {
  14019. return o.fold(function () {
  14020. return Result.error(e);
  14021. }, Result.value);
  14022. };
  14023. var make$4 = function (detail, components, spec) {
  14024. return {
  14025. 'uid': detail.uid,
  14026. 'dom': detail.dom,
  14027. 'components': components,
  14028. 'behaviours': augment(detail.formBehaviours, [Representing.config({
  14029. store: {
  14030. mode: 'manual',
  14031. getValue: function (form) {
  14032. var resPs = getAllParts(form, detail);
  14033. return map$1(resPs, function (resPThunk, pName) {
  14034. return resPThunk().bind(function (v) {
  14035. var opt = Composing.getCurrent(v);
  14036. return toResult$1(opt, 'missing current');
  14037. }).map(Representing.getValue);
  14038. });
  14039. },
  14040. setValue: function (form, values) {
  14041. each$1(values, function (newValue, key) {
  14042. getPart(form, detail, key).each(function (wrapper) {
  14043. Composing.getCurrent(wrapper).each(function (field) {
  14044. Representing.setValue(field, newValue);
  14045. });
  14046. });
  14047. });
  14048. }
  14049. }
  14050. })]),
  14051. 'apis': {
  14052. getField: function (form, key) {
  14053. return getPart(form, detail, key).bind(Composing.getCurrent);
  14054. }
  14055. }
  14056. };
  14057. };
  14058. var Form = {
  14059. getField: makeApi(function (apis, component, key) {
  14060. return apis.getField(component, key);
  14061. }),
  14062. sketch: sketch$1
  14063. };
  14064. var validInput = generate$1('valid-input');
  14065. var invalidInput = generate$1('invalid-input');
  14066. var validatingInput = generate$1('validating-input');
  14067. var translatePrefix = 'colorcustom.rgb.';
  14068. var rgbFormFactory = function (translate, getClass, onValidHexx, onInvalidHexx) {
  14069. var invalidation = function (label, isValid) {
  14070. return Invalidating.config({
  14071. invalidClass: getClass('invalid'),
  14072. notify: {
  14073. onValidate: function (comp) {
  14074. emitWith(comp, validatingInput, { type: label });
  14075. },
  14076. onValid: function (comp) {
  14077. emitWith(comp, validInput, {
  14078. type: label,
  14079. value: Representing.getValue(comp)
  14080. });
  14081. },
  14082. onInvalid: function (comp) {
  14083. emitWith(comp, invalidInput, {
  14084. type: label,
  14085. value: Representing.getValue(comp)
  14086. });
  14087. }
  14088. },
  14089. validator: {
  14090. validate: function (comp) {
  14091. var value = Representing.getValue(comp);
  14092. var res = isValid(value) ? Result.value(true) : Result.error(translate('aria.input.invalid'));
  14093. return Future.pure(res);
  14094. },
  14095. validateOnLoad: false
  14096. }
  14097. });
  14098. };
  14099. var renderTextField = function (isValid, name, label, description, data) {
  14100. var helptext = translate(translatePrefix + 'range');
  14101. var pLabel = FormField.parts().label({
  14102. dom: {
  14103. tag: 'label',
  14104. innerHtml: label,
  14105. attributes: { 'aria-label': description }
  14106. }
  14107. });
  14108. var pField = FormField.parts().field({
  14109. data: data,
  14110. factory: Input,
  14111. inputAttributes: __assign({ type: 'text' }, name === 'hex' ? { 'aria-live': 'polite' } : {}),
  14112. inputClasses: [getClass('textfield')],
  14113. inputBehaviours: derive$1([
  14114. invalidation(name, isValid),
  14115. Tabstopping.config({})
  14116. ]),
  14117. onSetValue: function (input) {
  14118. if (Invalidating.isInvalid(input)) {
  14119. var run = Invalidating.run(input);
  14120. run.get(noop);
  14121. }
  14122. }
  14123. });
  14124. var comps = [
  14125. pLabel,
  14126. pField
  14127. ];
  14128. var concats = name !== 'hex' ? [FormField.parts()['aria-descriptor']({ text: helptext })] : [];
  14129. var components = comps.concat(concats);
  14130. return {
  14131. dom: {
  14132. tag: 'div',
  14133. attributes: { role: 'presentation' }
  14134. },
  14135. components: components
  14136. };
  14137. };
  14138. var copyRgbToHex = function (form, rgba) {
  14139. var hex = fromRgba(rgba);
  14140. Form.getField(form, 'hex').each(function (hexField) {
  14141. if (!Focusing.isFocused(hexField)) {
  14142. Representing.setValue(form, { hex: hex.value() });
  14143. }
  14144. });
  14145. return hex;
  14146. };
  14147. var copyRgbToForm = function (form, rgb) {
  14148. var red = rgb.red(), green = rgb.green(), blue = rgb.blue();
  14149. Representing.setValue(form, {
  14150. red: red,
  14151. green: green,
  14152. blue: blue
  14153. });
  14154. };
  14155. var memPreview = record({
  14156. dom: {
  14157. tag: 'div',
  14158. classes: [getClass('rgba-preview')],
  14159. styles: { 'background-color': 'white' },
  14160. attributes: { role: 'presentation' }
  14161. }
  14162. });
  14163. var updatePreview = function (anyInSystem, hex) {
  14164. memPreview.getOpt(anyInSystem).each(function (preview) {
  14165. set$2(preview.element(), 'background-color', '#' + hex.value());
  14166. });
  14167. };
  14168. var factory = function (detail) {
  14169. var state = {
  14170. red: constant(Cell(Option.some(255))),
  14171. green: constant(Cell(Option.some(255))),
  14172. blue: constant(Cell(Option.some(255))),
  14173. hex: constant(Cell(Option.some('ffffff')))
  14174. };
  14175. var copyHexToRgb = function (form, hex) {
  14176. var rgb = fromHex(hex);
  14177. copyRgbToForm(form, rgb);
  14178. setValueRgb(rgb);
  14179. };
  14180. var get = function (prop) {
  14181. return state[prop]().get();
  14182. };
  14183. var set = function (prop, value) {
  14184. state[prop]().set(value);
  14185. };
  14186. var getValueRgb = function () {
  14187. return get('red').bind(function (red) {
  14188. return get('green').bind(function (green) {
  14189. return get('blue').map(function (blue) {
  14190. return rgbaColour(red, green, blue, 1);
  14191. });
  14192. });
  14193. });
  14194. };
  14195. var setValueRgb = function (rgb) {
  14196. var red = rgb.red(), green = rgb.green(), blue = rgb.blue();
  14197. set('red', Option.some(red));
  14198. set('green', Option.some(green));
  14199. set('blue', Option.some(blue));
  14200. };
  14201. var onInvalidInput = function (form, simulatedEvent) {
  14202. var data = simulatedEvent.event();
  14203. if (data.type() !== 'hex') {
  14204. set(data.type(), Option.none());
  14205. } else {
  14206. onInvalidHexx(form);
  14207. }
  14208. };
  14209. var onValidHex = function (form, value) {
  14210. onValidHexx(form);
  14211. var hex = hexColour(value);
  14212. set('hex', Option.some(value));
  14213. var rgb = fromHex(hex);
  14214. copyRgbToForm(form, rgb);
  14215. setValueRgb(rgb);
  14216. emitWith(form, fieldsUpdate(), { hex: hex });
  14217. updatePreview(form, hex);
  14218. };
  14219. var onValidRgb = function (form, prop, value) {
  14220. var val = parseInt(value, 10);
  14221. set(prop, Option.some(val));
  14222. getValueRgb().each(function (rgb) {
  14223. var hex = copyRgbToHex(form, rgb);
  14224. updatePreview(form, hex);
  14225. });
  14226. };
  14227. var onValidInput = function (form, simulatedEvent) {
  14228. var data = simulatedEvent.event();
  14229. if (data.type() === 'hex') {
  14230. onValidHex(form, data.value());
  14231. } else {
  14232. onValidRgb(form, data.type(), data.value());
  14233. }
  14234. };
  14235. var formPartStrings = function (key) {
  14236. return {
  14237. label: translate(translatePrefix + key + '.label'),
  14238. description: translate(translatePrefix + key + '.description')
  14239. };
  14240. };
  14241. var redStrings = formPartStrings('red');
  14242. var greenStrings = formPartStrings('green');
  14243. var blueStrings = formPartStrings('blue');
  14244. var hexStrings = formPartStrings('hex');
  14245. return deepMerge(Form.sketch(function (parts) {
  14246. return {
  14247. dom: {
  14248. tag: 'form',
  14249. classes: [getClass('rgb-form')],
  14250. attributes: { 'aria-label': translate('aria.color.picker') }
  14251. },
  14252. components: [
  14253. parts.field('red', FormField.sketch(renderTextField(isRgbaComponent, 'red', redStrings.label, redStrings.description, 255))),
  14254. parts.field('green', FormField.sketch(renderTextField(isRgbaComponent, 'green', greenStrings.label, greenStrings.description, 255))),
  14255. parts.field('blue', FormField.sketch(renderTextField(isRgbaComponent, 'blue', blueStrings.label, blueStrings.description, 255))),
  14256. parts.field('hex', FormField.sketch(renderTextField(isHexString, 'hex', hexStrings.label, hexStrings.description, 'ffffff'))),
  14257. memPreview.asSpec()
  14258. ],
  14259. formBehaviours: derive$1([
  14260. Invalidating.config({ invalidClass: getClass('form-invalid') }),
  14261. config('rgb-form-events', [
  14262. run(validInput, onValidInput),
  14263. run(invalidInput, onInvalidInput),
  14264. run(validatingInput, onInvalidInput)
  14265. ])
  14266. ])
  14267. };
  14268. }), {
  14269. apis: {
  14270. updateHex: function (form, hex) {
  14271. Representing.setValue(form, { hex: hex.value() });
  14272. copyHexToRgb(form, hex);
  14273. updatePreview(form, hex);
  14274. }
  14275. }
  14276. });
  14277. };
  14278. var RgbForm = single$2({
  14279. factory: factory,
  14280. name: 'RgbForm',
  14281. configFields: [],
  14282. apis: {
  14283. updateHex: function (apis, form, hex) {
  14284. apis.updateHex(form, hex);
  14285. }
  14286. },
  14287. extraApis: {}
  14288. });
  14289. return RgbForm;
  14290. };
  14291. var RgbForm = { rgbFormFactory: rgbFormFactory };
  14292. var hsvColour = function (hue, saturation, value) {
  14293. return {
  14294. hue: constant(hue),
  14295. saturation: constant(saturation),
  14296. value: constant(value)
  14297. };
  14298. };
  14299. var fromRgb = function (rgbaColour) {
  14300. var r, g, b, h, s, v, d, minRGB, maxRGB;
  14301. h = 0;
  14302. s = 0;
  14303. v = 0;
  14304. r = rgbaColour.red() / 255;
  14305. g = rgbaColour.green() / 255;
  14306. b = rgbaColour.blue() / 255;
  14307. minRGB = Math.min(r, Math.min(g, b));
  14308. maxRGB = Math.max(r, Math.max(g, b));
  14309. if (minRGB === maxRGB) {
  14310. v = minRGB;
  14311. return hsvColour(0, 0, v * 100);
  14312. }
  14313. d = r === minRGB ? g - b : b === minRGB ? r - g : b - r;
  14314. h = r === minRGB ? 3 : b === minRGB ? 1 : 5;
  14315. h = 60 * (h - d / (maxRGB - minRGB));
  14316. s = (maxRGB - minRGB) / maxRGB;
  14317. v = maxRGB;
  14318. return hsvColour(Math.round(h), Math.round(s * 100), Math.round(v * 100));
  14319. };
  14320. var calcHex = function (value) {
  14321. var hue = (100 - value / 100) * 360;
  14322. var hsv = hsvColour(hue, 100, 100);
  14323. var rgb = fromHsv(hsv);
  14324. return fromRgba(rgb);
  14325. };
  14326. var makeFactory = function (translate, getClass) {
  14327. var factory = function (detail) {
  14328. var rgbForm = RgbForm.rgbFormFactory(translate, getClass, detail.onValidHex, detail.onInvalidHex);
  14329. var sbPalette = SaturationBrightnessPalette.paletteFactory(translate, getClass);
  14330. var state = { paletteRgba: constant(Cell(red())) };
  14331. var memPalette = record(sbPalette.sketch({}));
  14332. var memRgb = record(rgbForm.sketch({}));
  14333. var updatePalette = function (anyInSystem, hex) {
  14334. memPalette.getOpt(anyInSystem).each(function (palette) {
  14335. var rgba = fromHex(hex);
  14336. state.paletteRgba().set(rgba);
  14337. sbPalette.setRgba(palette, rgba);
  14338. });
  14339. };
  14340. var updateFields = function (anyInSystem, hex) {
  14341. memRgb.getOpt(anyInSystem).each(function (form) {
  14342. rgbForm.updateHex(form, hex);
  14343. });
  14344. };
  14345. var runUpdates = function (anyInSystem, hex, updates) {
  14346. each(updates, function (update) {
  14347. update(anyInSystem, hex);
  14348. });
  14349. };
  14350. var paletteUpdates = function () {
  14351. var updates = [updateFields];
  14352. return function (form, simulatedEvent) {
  14353. var value = simulatedEvent.event().value();
  14354. var oldRgb = state.paletteRgba().get();
  14355. var hsvColour$1 = fromRgb(oldRgb);
  14356. var newHsvColour = hsvColour(hsvColour$1.hue(), value.x(), 100 - value.y());
  14357. var rgb = fromHsv(newHsvColour);
  14358. var nuHex = fromRgba(rgb);
  14359. runUpdates(form, nuHex, updates);
  14360. };
  14361. };
  14362. var sliderUpdates = function () {
  14363. var updates = [
  14364. updatePalette,
  14365. updateFields
  14366. ];
  14367. return function (form, simulatedEvent) {
  14368. var value = simulatedEvent.event().value();
  14369. var hex = calcHex(value.y());
  14370. runUpdates(form, hex, updates);
  14371. };
  14372. };
  14373. return {
  14374. uid: detail.uid,
  14375. dom: detail.dom,
  14376. components: [
  14377. memPalette.asSpec(),
  14378. HueSlider.sliderFactory(translate, getClass),
  14379. memRgb.asSpec()
  14380. ],
  14381. behaviours: derive$1([
  14382. config('colour-picker-events', [
  14383. run(paletteUpdate(), paletteUpdates()),
  14384. run(sliderUpdate(), sliderUpdates())
  14385. ]),
  14386. Composing.config({
  14387. find: function (comp) {
  14388. return memRgb.getOpt(comp);
  14389. }
  14390. }),
  14391. Keying.config({ mode: 'acyclic' })
  14392. ])
  14393. };
  14394. };
  14395. var ColourPicker = single$2({
  14396. name: 'ColourPicker',
  14397. configFields: [
  14398. defaulted$1('onValidHex', noop),
  14399. defaulted$1('onInvalidHex', noop),
  14400. optionString('formChangeEvent')
  14401. ],
  14402. factory: factory
  14403. });
  14404. return ColourPicker;
  14405. };
  14406. var ColourPicker = { makeFactory: makeFactory };
  14407. var self = function () {
  14408. return Composing.config({ find: Option.some });
  14409. };
  14410. var memento = function (mem) {
  14411. return Composing.config({ find: mem.getOpt });
  14412. };
  14413. var childAt = function (index) {
  14414. return Composing.config({
  14415. find: function (comp) {
  14416. return child(comp.element(), index).bind(function (element) {
  14417. return comp.getSystem().getByDom(element).toOption();
  14418. });
  14419. }
  14420. });
  14421. };
  14422. var ComposingConfigs = {
  14423. self: self,
  14424. memento: memento,
  14425. childAt: childAt
  14426. };
  14427. var english = {
  14428. 'colorcustom.rgb.red.label': 'R',
  14429. 'colorcustom.rgb.red.description': 'Red component',
  14430. 'colorcustom.rgb.green.label': 'G',
  14431. 'colorcustom.rgb.green.description': 'Green component',
  14432. 'colorcustom.rgb.blue.label': 'B',
  14433. 'colorcustom.rgb.blue.description': 'Blue component',
  14434. 'colorcustom.rgb.hex.label': '#',
  14435. 'colorcustom.rgb.hex.description': 'Hex color code',
  14436. 'colorcustom.rgb.range': 'Range 0 to 255',
  14437. 'colorcustom.sb.saturation': 'Saturation',
  14438. 'colorcustom.sb.brightness': 'Brightness',
  14439. 'colorcustom.sb.picker': 'Saturation and Brightness Picker',
  14440. 'colorcustom.sb.palette': 'Saturation and Brightness Palette',
  14441. 'colorcustom.sb.instructions': 'Use arrow keys to select saturation and brightness, on x and y axes',
  14442. 'colorcustom.hue.hue': 'Hue',
  14443. 'colorcustom.hue.slider': 'Hue Slider',
  14444. 'colorcustom.hue.palette': 'Hue Palette',
  14445. 'colorcustom.hue.instructions': 'Use arrow keys to select a hue',
  14446. 'aria.color.picker': 'Color Picker',
  14447. 'aria.input.invalid': 'Invalid input'
  14448. };
  14449. var getEnglishText = function (key) {
  14450. return english[key];
  14451. };
  14452. var translate = function (key) {
  14453. return getEnglishText(key);
  14454. };
  14455. var renderColorPicker = function (spec) {
  14456. var getClass = function (key) {
  14457. return 'tox-' + key;
  14458. };
  14459. var colourPickerFactory = ColourPicker.makeFactory(translate, getClass);
  14460. var onValidHex = function (form) {
  14461. emitWith(form, formActionEvent, {
  14462. name: 'hex-valid',
  14463. value: true
  14464. });
  14465. };
  14466. var onInvalidHex = function (form) {
  14467. emitWith(form, formActionEvent, {
  14468. name: 'hex-valid',
  14469. value: false
  14470. });
  14471. };
  14472. var memPicker = record(colourPickerFactory.sketch({
  14473. dom: {
  14474. tag: 'div',
  14475. classes: [getClass('color-picker-container')],
  14476. attributes: { role: 'presentation' }
  14477. },
  14478. onValidHex: onValidHex,
  14479. onInvalidHex: onInvalidHex
  14480. }));
  14481. return {
  14482. dom: { tag: 'div' },
  14483. components: [memPicker.asSpec()],
  14484. behaviours: derive$1([
  14485. Representing.config({
  14486. store: {
  14487. mode: 'manual',
  14488. getValue: function (comp) {
  14489. var picker = memPicker.get(comp);
  14490. var optRgbForm = Composing.getCurrent(picker);
  14491. var optHex = optRgbForm.bind(function (rgbForm) {
  14492. var formValues = Representing.getValue(rgbForm);
  14493. return formValues.hex;
  14494. });
  14495. return optHex.map(function (hex) {
  14496. return '#' + hex;
  14497. }).getOr('');
  14498. },
  14499. setValue: function (comp, newValue) {
  14500. var pattern = /^#([a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?)/;
  14501. var m = pattern.exec(newValue);
  14502. var picker = memPicker.get(comp);
  14503. var optRgbForm = Composing.getCurrent(picker);
  14504. optRgbForm.fold(function () {
  14505. console.log('Can not find form');
  14506. }, function (rgbForm) {
  14507. Representing.setValue(rgbForm, { hex: Option.from(m[1]).getOr('') });
  14508. Form.getField(rgbForm, 'hex').each(function (hexField) {
  14509. emit(hexField, input());
  14510. });
  14511. });
  14512. }
  14513. }
  14514. }),
  14515. ComposingConfigs.self()
  14516. ])
  14517. };
  14518. };
  14519. var renderCustomEditor = function (spec) {
  14520. var editorApi = Cell(Option.none());
  14521. var memReplaced = record({ dom: { tag: spec.tag } });
  14522. var initialValue = Cell(Option.none());
  14523. return {
  14524. dom: {
  14525. tag: 'div',
  14526. classes: ['tox-custom-editor']
  14527. },
  14528. behaviours: derive$1([
  14529. config('editor-foo-events', [runOnAttached(function (component) {
  14530. memReplaced.getOpt(component).each(function (ta) {
  14531. spec.init(ta.element().dom()).then(function (ea) {
  14532. initialValue.get().each(function (cvalue) {
  14533. ea.setValue(cvalue);
  14534. });
  14535. initialValue.set(Option.none());
  14536. editorApi.set(Option.some(ea));
  14537. });
  14538. });
  14539. })]),
  14540. Representing.config({
  14541. store: {
  14542. mode: 'manual',
  14543. getValue: function () {
  14544. return editorApi.get().fold(function () {
  14545. return initialValue.get().getOr('');
  14546. }, function (ed) {
  14547. return ed.getValue();
  14548. });
  14549. },
  14550. setValue: function (component, value) {
  14551. editorApi.get().fold(function () {
  14552. initialValue.set(Option.some(value));
  14553. }, function (ed) {
  14554. return ed.setValue(value);
  14555. });
  14556. }
  14557. }
  14558. }),
  14559. ComposingConfigs.self()
  14560. ]),
  14561. components: [memReplaced.asSpec()]
  14562. };
  14563. };
  14564. var processors = objOf([
  14565. defaulted$1('preprocess', identity),
  14566. defaulted$1('postprocess', identity)
  14567. ]);
  14568. var memento$1 = function (mem, rawProcessors) {
  14569. var ps = asRawOrDie('RepresentingConfigs.memento processors', processors, rawProcessors);
  14570. return Representing.config({
  14571. store: {
  14572. mode: 'manual',
  14573. getValue: function (comp) {
  14574. var other = mem.get(comp);
  14575. var rawValue = Representing.getValue(other);
  14576. return ps.postprocess(rawValue);
  14577. },
  14578. setValue: function (comp, rawValue) {
  14579. var newValue = ps.preprocess(rawValue);
  14580. var other = mem.get(comp);
  14581. Representing.setValue(other, newValue);
  14582. }
  14583. }
  14584. });
  14585. };
  14586. var withComp = function (optInitialValue, getter, setter) {
  14587. return Representing.config(deepMerge({
  14588. store: {
  14589. mode: 'manual',
  14590. getValue: getter,
  14591. setValue: setter
  14592. }
  14593. }, optInitialValue.map(function (initialValue) {
  14594. return { store: { initialValue: initialValue } };
  14595. }).getOr({})));
  14596. };
  14597. var withElement = function (initialValue, getter, setter) {
  14598. return withComp(initialValue, function (c) {
  14599. return getter(c.element());
  14600. }, function (c, v) {
  14601. return setter(c.element(), v);
  14602. });
  14603. };
  14604. var domValue = function (optInitialValue) {
  14605. return withElement(optInitialValue, get$5, set$3);
  14606. };
  14607. var domHtml = function (optInitialValue) {
  14608. return withElement(optInitialValue, get$1, set);
  14609. };
  14610. var memory$1 = function (initialValue) {
  14611. return Representing.config({
  14612. store: {
  14613. mode: 'memory',
  14614. initialValue: initialValue
  14615. }
  14616. });
  14617. };
  14618. var RepresentingConfigs = {
  14619. memento: memento$1,
  14620. withElement: withElement,
  14621. withComp: withComp,
  14622. domValue: domValue,
  14623. domHtml: domHtml,
  14624. memory: memory$1
  14625. };
  14626. var extensionsAccepted = '.jpg,.jpeg,.png,.gif';
  14627. var filterByExtension = function (files) {
  14628. var re = new RegExp('(' + extensionsAccepted.split(/\s*,\s*/).join('|') + ')$', 'i');
  14629. return filter(from$1(files), function (file) {
  14630. return re.test(file.name);
  14631. });
  14632. };
  14633. var renderDropZone = function (spec, providersBackstage) {
  14634. var stopper = function (_, se) {
  14635. se.stop();
  14636. };
  14637. var sequence = function (actions) {
  14638. return function (comp, se) {
  14639. each(actions, function (a) {
  14640. a(comp, se);
  14641. });
  14642. };
  14643. };
  14644. var onDrop = function (comp, se) {
  14645. if (!Disabling.isDisabled(comp)) {
  14646. var transferEvent = se.event().raw();
  14647. handleFiles(comp, transferEvent.dataTransfer.files);
  14648. }
  14649. };
  14650. var onSelect = function (component, simulatedEvent) {
  14651. var files = simulatedEvent.event().raw().target.files;
  14652. handleFiles(component, files);
  14653. };
  14654. var handleFiles = function (component, files) {
  14655. Representing.setValue(component, filterByExtension(files));
  14656. emitWith(component, formChangeEvent, { name: spec.name });
  14657. };
  14658. var memInput = record({
  14659. dom: {
  14660. tag: 'input',
  14661. attributes: {
  14662. type: 'file',
  14663. accept: 'image/*'
  14664. },
  14665. styles: { display: 'none' }
  14666. },
  14667. behaviours: derive$1([config('input-file-events', [cutter(click())])])
  14668. });
  14669. var renderField = function (s) {
  14670. return {
  14671. uid: s.uid,
  14672. dom: {
  14673. tag: 'div',
  14674. classes: ['tox-dropzone-container']
  14675. },
  14676. behaviours: derive$1([
  14677. RepresentingConfigs.memory([]),
  14678. ComposingConfigs.self(),
  14679. Disabling.config({}),
  14680. Toggling.config({
  14681. toggleClass: 'dragenter',
  14682. toggleOnExecute: false
  14683. }),
  14684. config('dropzone-events', [
  14685. run('dragenter', sequence([
  14686. stopper,
  14687. Toggling.toggle
  14688. ])),
  14689. run('dragleave', sequence([
  14690. stopper,
  14691. Toggling.toggle
  14692. ])),
  14693. run('dragover', stopper),
  14694. run('drop', sequence([
  14695. stopper,
  14696. onDrop
  14697. ])),
  14698. run(change(), onSelect)
  14699. ])
  14700. ]),
  14701. components: [{
  14702. dom: {
  14703. tag: 'div',
  14704. classes: ['tox-dropzone'],
  14705. styles: {}
  14706. },
  14707. components: [
  14708. {
  14709. dom: {
  14710. tag: 'p',
  14711. innerHtml: providersBackstage.translate('Drop an image here')
  14712. }
  14713. },
  14714. Button.sketch({
  14715. dom: {
  14716. tag: 'button',
  14717. innerHtml: providersBackstage.translate('Browse for an image'),
  14718. styles: { position: 'relative' },
  14719. classes: [
  14720. 'tox-button',
  14721. 'tox-button--secondary'
  14722. ]
  14723. },
  14724. components: [memInput.asSpec()],
  14725. action: function (comp) {
  14726. var inputComp = memInput.get(comp);
  14727. inputComp.element().dom().click();
  14728. },
  14729. buttonBehaviours: derive$1([Tabstopping.config({})])
  14730. })
  14731. ]
  14732. }]
  14733. };
  14734. };
  14735. var pLabel = spec.label.map(function (label) {
  14736. return renderLabel(label, providersBackstage);
  14737. });
  14738. var pField = FormField.parts().field({ factory: { sketch: renderField } });
  14739. return renderFormFieldWith(pLabel, pField, ['tox-form__group--stretched']);
  14740. };
  14741. var renderGrid = function (spec, backstage) {
  14742. return {
  14743. dom: {
  14744. tag: 'div',
  14745. classes: [
  14746. 'tox-form__grid',
  14747. 'tox-form__grid--' + spec.columns + 'col'
  14748. ]
  14749. },
  14750. components: map(spec.items, backstage.interpreter)
  14751. };
  14752. };
  14753. var beforeObject = generate$1('alloy-fake-before-tabstop');
  14754. var afterObject = generate$1('alloy-fake-after-tabstop');
  14755. var craftWithClasses = function (classes) {
  14756. return {
  14757. dom: {
  14758. tag: 'div',
  14759. styles: {
  14760. width: '1px',
  14761. height: '1px',
  14762. outline: 'none'
  14763. },
  14764. attributes: { tabindex: '0' },
  14765. classes: classes
  14766. },
  14767. behaviours: derive$1([
  14768. Focusing.config({ ignore: true }),
  14769. Tabstopping.config({})
  14770. ])
  14771. };
  14772. };
  14773. var craft = function (spec) {
  14774. return {
  14775. dom: {
  14776. tag: 'div',
  14777. classes: ['tox-navobj']
  14778. },
  14779. components: [
  14780. craftWithClasses([beforeObject]),
  14781. spec,
  14782. craftWithClasses([afterObject])
  14783. ],
  14784. behaviours: derive$1([ComposingConfigs.childAt(1)])
  14785. };
  14786. };
  14787. var triggerTab = function (placeholder, shiftKey) {
  14788. emitWith(placeholder, keydown(), {
  14789. raw: {
  14790. which: 9,
  14791. shiftKey: shiftKey
  14792. }
  14793. });
  14794. };
  14795. var onFocus$1 = function (container, targetComp) {
  14796. var target = targetComp.element();
  14797. if (has$2(target, beforeObject)) {
  14798. triggerTab(container, true);
  14799. } else if (has$2(target, afterObject)) {
  14800. triggerTab(container, false);
  14801. }
  14802. };
  14803. var isPseudoStop = function (element) {
  14804. return closest$4(element, [
  14805. '.' + beforeObject,
  14806. '.' + afterObject
  14807. ].join(','), constant(false));
  14808. };
  14809. var NavigableObject = {
  14810. isPseudoStop: isPseudoStop,
  14811. onFocus: onFocus$1,
  14812. craft: craft
  14813. };
  14814. var platformNeedsSandboxing = !(PlatformDetection$1.detect().browser.isIE() || PlatformDetection$1.detect().browser.isEdge());
  14815. var getDynamicSource = function (isSandbox) {
  14816. var cachedValue = Cell('');
  14817. return {
  14818. getValue: function (frameComponent) {
  14819. return cachedValue.get();
  14820. },
  14821. setValue: function (frameComponent, html) {
  14822. if (!isSandbox) {
  14823. set$1(frameComponent.element(), 'src', 'javascript:\'\'');
  14824. var doc = frameComponent.element().dom().contentWindow.document;
  14825. doc.open();
  14826. doc.write(html);
  14827. doc.close();
  14828. } else {
  14829. set$1(frameComponent.element(), 'src', 'data:text/html;charset=utf-8,' + encodeURIComponent(html));
  14830. }
  14831. cachedValue.set(html);
  14832. }
  14833. };
  14834. };
  14835. var renderIFrame = function (spec, providersBackstage) {
  14836. var isSandbox = platformNeedsSandboxing && spec.sandboxed;
  14837. var attributes = __assign({}, spec.label.map(function (title) {
  14838. return { title: title };
  14839. }).getOr({}), isSandbox ? { sandbox: 'allow-scripts' } : {});
  14840. var sourcing = getDynamicSource(isSandbox);
  14841. var pLabel = spec.label.map(function (label) {
  14842. return renderLabel(label, providersBackstage);
  14843. });
  14844. var factory = function (newSpec) {
  14845. return NavigableObject.craft({
  14846. uid: newSpec.uid,
  14847. dom: {
  14848. tag: 'iframe',
  14849. attributes: attributes
  14850. },
  14851. behaviours: derive$1([
  14852. Tabstopping.config({}),
  14853. Focusing.config({}),
  14854. RepresentingConfigs.withComp(Option.none(), sourcing.getValue, sourcing.setValue)
  14855. ])
  14856. });
  14857. };
  14858. var pField = FormField.parts().field({ factory: { sketch: factory } });
  14859. return renderFormFieldWith(pLabel, pField, ['tox-form__group--stretched']);
  14860. };
  14861. function create$4(width, height) {
  14862. return resize(domGlobals.document.createElement('canvas'), width, height);
  14863. }
  14864. function clone$1(canvas) {
  14865. var tCanvas, ctx;
  14866. tCanvas = create$4(canvas.width, canvas.height);
  14867. ctx = get2dContext(tCanvas);
  14868. ctx.drawImage(canvas, 0, 0);
  14869. return tCanvas;
  14870. }
  14871. function get2dContext(canvas) {
  14872. return canvas.getContext('2d');
  14873. }
  14874. function get3dContext(canvas) {
  14875. var gl = null;
  14876. try {
  14877. gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
  14878. } catch (e) {
  14879. }
  14880. if (!gl) {
  14881. gl = null;
  14882. }
  14883. return gl;
  14884. }
  14885. function resize(canvas, width, height) {
  14886. canvas.width = width;
  14887. canvas.height = height;
  14888. return canvas;
  14889. }
  14890. var Canvas = {
  14891. create: create$4,
  14892. clone: clone$1,
  14893. resize: resize,
  14894. get2dContext: get2dContext,
  14895. get3dContext: get3dContext
  14896. };
  14897. function getWidth(image) {
  14898. return image.naturalWidth || image.width;
  14899. }
  14900. function getHeight(image) {
  14901. return image.naturalHeight || image.height;
  14902. }
  14903. var ImageSize = {
  14904. getWidth: getWidth,
  14905. getHeight: getHeight
  14906. };
  14907. var promise = function () {
  14908. var Promise = function (fn) {
  14909. if (typeof this !== 'object')
  14910. throw new TypeError('Promises must be constructed via new');
  14911. if (typeof fn !== 'function')
  14912. throw new TypeError('not a function');
  14913. this._state = null;
  14914. this._value = null;
  14915. this._deferreds = [];
  14916. doResolve(fn, bind(resolve, this), bind(reject, this));
  14917. };
  14918. var asap = Promise.immediateFn || typeof window.setImmediate === 'function' && window.setImmediate || function (fn) {
  14919. domGlobals.setTimeout(fn, 1);
  14920. };
  14921. function bind(fn, thisArg) {
  14922. return function () {
  14923. fn.apply(thisArg, arguments);
  14924. };
  14925. }
  14926. var isArray = Array.isArray || function (value) {
  14927. return Object.prototype.toString.call(value) === '[object Array]';
  14928. };
  14929. function handle(deferred) {
  14930. var me = this;
  14931. if (this._state === null) {
  14932. this._deferreds.push(deferred);
  14933. return;
  14934. }
  14935. asap(function () {
  14936. var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
  14937. if (cb === null) {
  14938. (me._state ? deferred.resolve : deferred.reject)(me._value);
  14939. return;
  14940. }
  14941. var ret;
  14942. try {
  14943. ret = cb(me._value);
  14944. } catch (e) {
  14945. deferred.reject(e);
  14946. return;
  14947. }
  14948. deferred.resolve(ret);
  14949. });
  14950. }
  14951. function resolve(newValue) {
  14952. try {
  14953. if (newValue === this)
  14954. throw new TypeError('A promise cannot be resolved with itself.');
  14955. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  14956. var then = newValue.then;
  14957. if (typeof then === 'function') {
  14958. doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
  14959. return;
  14960. }
  14961. }
  14962. this._state = true;
  14963. this._value = newValue;
  14964. finale.call(this);
  14965. } catch (e) {
  14966. reject.call(this, e);
  14967. }
  14968. }
  14969. function reject(newValue) {
  14970. this._state = false;
  14971. this._value = newValue;
  14972. finale.call(this);
  14973. }
  14974. function finale() {
  14975. for (var i = 0, len = this._deferreds.length; i < len; i++) {
  14976. handle.call(this, this._deferreds[i]);
  14977. }
  14978. this._deferreds = null;
  14979. }
  14980. function Handler(onFulfilled, onRejected, resolve, reject) {
  14981. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  14982. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  14983. this.resolve = resolve;
  14984. this.reject = reject;
  14985. }
  14986. function doResolve(fn, onFulfilled, onRejected) {
  14987. var done = false;
  14988. try {
  14989. fn(function (value) {
  14990. if (done)
  14991. return;
  14992. done = true;
  14993. onFulfilled(value);
  14994. }, function (reason) {
  14995. if (done)
  14996. return;
  14997. done = true;
  14998. onRejected(reason);
  14999. });
  15000. } catch (ex) {
  15001. if (done)
  15002. return;
  15003. done = true;
  15004. onRejected(ex);
  15005. }
  15006. }
  15007. Promise.prototype['catch'] = function (onRejected) {
  15008. return this.then(null, onRejected);
  15009. };
  15010. Promise.prototype.then = function (onFulfilled, onRejected) {
  15011. var me = this;
  15012. return new Promise(function (resolve, reject) {
  15013. handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
  15014. });
  15015. };
  15016. Promise.all = function () {
  15017. var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
  15018. return new Promise(function (resolve, reject) {
  15019. if (args.length === 0)
  15020. return resolve([]);
  15021. var remaining = args.length;
  15022. function res(i, val) {
  15023. try {
  15024. if (val && (typeof val === 'object' || typeof val === 'function')) {
  15025. var then = val.then;
  15026. if (typeof then === 'function') {
  15027. then.call(val, function (val) {
  15028. res(i, val);
  15029. }, reject);
  15030. return;
  15031. }
  15032. }
  15033. args[i] = val;
  15034. if (--remaining === 0) {
  15035. resolve(args);
  15036. }
  15037. } catch (ex) {
  15038. reject(ex);
  15039. }
  15040. }
  15041. for (var i = 0; i < args.length; i++) {
  15042. res(i, args[i]);
  15043. }
  15044. });
  15045. };
  15046. Promise.resolve = function (value) {
  15047. if (value && typeof value === 'object' && value.constructor === Promise) {
  15048. return value;
  15049. }
  15050. return new Promise(function (resolve) {
  15051. resolve(value);
  15052. });
  15053. };
  15054. Promise.reject = function (value) {
  15055. return new Promise(function (resolve, reject) {
  15056. reject(value);
  15057. });
  15058. };
  15059. Promise.race = function (values) {
  15060. return new Promise(function (resolve, reject) {
  15061. for (var i = 0, len = values.length; i < len; i++) {
  15062. values[i].then(resolve, reject);
  15063. }
  15064. });
  15065. };
  15066. return Promise;
  15067. };
  15068. var Promise = window.Promise ? window.Promise : promise();
  15069. function Blob (parts, properties) {
  15070. var f = Global$1.getOrDie('Blob');
  15071. return new f(parts, properties);
  15072. }
  15073. function FileReader () {
  15074. var f = Global$1.getOrDie('FileReader');
  15075. return new f();
  15076. }
  15077. function Uint8Array (arr) {
  15078. var f = Global$1.getOrDie('Uint8Array');
  15079. return new f(arr);
  15080. }
  15081. var requestAnimationFrame = function (callback) {
  15082. var f = Global$1.getOrDie('requestAnimationFrame');
  15083. f(callback);
  15084. };
  15085. var atob = function (base64) {
  15086. var f = Global$1.getOrDie('atob');
  15087. return f(base64);
  15088. };
  15089. var Window = {
  15090. atob: atob,
  15091. requestAnimationFrame: requestAnimationFrame
  15092. };
  15093. function imageToBlob(image) {
  15094. var src = image.src;
  15095. if (src.indexOf('data:') === 0) {
  15096. return dataUriToBlob(src);
  15097. }
  15098. return anyUriToBlob(src);
  15099. }
  15100. function blobToImage(blob) {
  15101. return new Promise(function (resolve, reject) {
  15102. var blobUrl = domGlobals.URL.createObjectURL(blob);
  15103. var image = new domGlobals.Image();
  15104. var removeListeners = function () {
  15105. image.removeEventListener('load', loaded);
  15106. image.removeEventListener('error', error);
  15107. };
  15108. function loaded() {
  15109. removeListeners();
  15110. resolve(image);
  15111. }
  15112. function error() {
  15113. removeListeners();
  15114. reject('Unable to load data of type ' + blob.type + ': ' + blobUrl);
  15115. }
  15116. image.addEventListener('load', loaded);
  15117. image.addEventListener('error', error);
  15118. image.src = blobUrl;
  15119. if (image.complete) {
  15120. loaded();
  15121. }
  15122. });
  15123. }
  15124. function anyUriToBlob(url) {
  15125. return new Promise(function (resolve, reject) {
  15126. var xhr = new domGlobals.XMLHttpRequest();
  15127. xhr.open('GET', url, true);
  15128. xhr.responseType = 'blob';
  15129. xhr.onload = function () {
  15130. if (this.status == 200) {
  15131. resolve(this.response);
  15132. }
  15133. };
  15134. xhr.onerror = function () {
  15135. var _this = this;
  15136. var corsError = function () {
  15137. var obj = new Error('No access to download image');
  15138. obj.code = 18;
  15139. obj.name = 'SecurityError';
  15140. return obj;
  15141. };
  15142. var genericError = function () {
  15143. return new Error('Error ' + _this.status + ' downloading image');
  15144. };
  15145. reject(this.status === 0 ? corsError() : genericError());
  15146. };
  15147. xhr.send();
  15148. });
  15149. }
  15150. function dataUriToBlobSync(uri) {
  15151. var data = uri.split(',');
  15152. var matches = /data:([^;]+)/.exec(data[0]);
  15153. if (!matches)
  15154. return Option.none();
  15155. var mimetype = matches[1];
  15156. var base64 = data[1];
  15157. var sliceSize = 1024;
  15158. var byteCharacters = Window.atob(base64);
  15159. var bytesLength = byteCharacters.length;
  15160. var slicesCount = Math.ceil(bytesLength / sliceSize);
  15161. var byteArrays = new Array(slicesCount);
  15162. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
  15163. var begin = sliceIndex * sliceSize;
  15164. var end = Math.min(begin + sliceSize, bytesLength);
  15165. var bytes = new Array(end - begin);
  15166. for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
  15167. bytes[i] = byteCharacters[offset].charCodeAt(0);
  15168. }
  15169. byteArrays[sliceIndex] = Uint8Array(bytes);
  15170. }
  15171. return Option.some(Blob(byteArrays, { type: mimetype }));
  15172. }
  15173. function dataUriToBlob(uri) {
  15174. return new Promise(function (resolve, reject) {
  15175. dataUriToBlobSync(uri).fold(function () {
  15176. reject('uri is not base64: ' + uri);
  15177. }, resolve);
  15178. });
  15179. }
  15180. function uriToBlob(url) {
  15181. if (url.indexOf('blob:') === 0) {
  15182. return anyUriToBlob(url);
  15183. }
  15184. if (url.indexOf('data:') === 0) {
  15185. return dataUriToBlob(url);
  15186. }
  15187. return null;
  15188. }
  15189. function canvasToBlob(canvas, type, quality) {
  15190. type = type || 'image/png';
  15191. if (domGlobals.HTMLCanvasElement.prototype.toBlob) {
  15192. return new Promise(function (resolve) {
  15193. canvas.toBlob(function (blob) {
  15194. resolve(blob);
  15195. }, type, quality);
  15196. });
  15197. } else {
  15198. return dataUriToBlob(canvas.toDataURL(type, quality));
  15199. }
  15200. }
  15201. function canvasToDataURL(getCanvas, type, quality) {
  15202. type = type || 'image/png';
  15203. return getCanvas.then(function (canvas) {
  15204. return canvas.toDataURL(type, quality);
  15205. });
  15206. }
  15207. function blobToCanvas(blob) {
  15208. return blobToImage(blob).then(function (image) {
  15209. revokeImageUrl(image);
  15210. var context, canvas;
  15211. canvas = Canvas.create(ImageSize.getWidth(image), ImageSize.getHeight(image));
  15212. context = Canvas.get2dContext(canvas);
  15213. context.drawImage(image, 0, 0);
  15214. return canvas;
  15215. });
  15216. }
  15217. function blobToDataUri(blob) {
  15218. return new Promise(function (resolve) {
  15219. var reader = FileReader();
  15220. reader.onloadend = function () {
  15221. resolve(reader.result);
  15222. };
  15223. reader.readAsDataURL(blob);
  15224. });
  15225. }
  15226. function blobToArrayBuffer(blob) {
  15227. return new Promise(function (resolve) {
  15228. var reader = FileReader();
  15229. reader.onloadend = function () {
  15230. resolve(reader.result);
  15231. };
  15232. reader.readAsArrayBuffer(blob);
  15233. });
  15234. }
  15235. function blobToBase64(blob) {
  15236. return blobToDataUri(blob).then(function (dataUri) {
  15237. return dataUri.split(',')[1];
  15238. });
  15239. }
  15240. function revokeImageUrl(image) {
  15241. domGlobals.URL.revokeObjectURL(image.src);
  15242. }
  15243. var Conversions = {
  15244. blobToImage: blobToImage,
  15245. imageToBlob: imageToBlob,
  15246. blobToArrayBuffer: blobToArrayBuffer,
  15247. blobToDataUri: blobToDataUri,
  15248. blobToBase64: blobToBase64,
  15249. dataUriToBlobSync: dataUriToBlobSync,
  15250. canvasToBlob: canvasToBlob,
  15251. canvasToDataURL: canvasToDataURL,
  15252. blobToCanvas: blobToCanvas,
  15253. uriToBlob: uriToBlob
  15254. };
  15255. function create$5(getCanvas, blob, uri) {
  15256. var initialType = blob.type;
  15257. var getType = constant(initialType);
  15258. function toBlob() {
  15259. return Promise.resolve(blob);
  15260. }
  15261. function toDataURL() {
  15262. return uri;
  15263. }
  15264. function toBase64() {
  15265. return uri.split(',')[1];
  15266. }
  15267. function toAdjustedBlob(type, quality) {
  15268. return getCanvas.then(function (canvas) {
  15269. return Conversions.canvasToBlob(canvas, type, quality);
  15270. });
  15271. }
  15272. function toAdjustedDataURL(type, quality) {
  15273. return getCanvas.then(function (canvas) {
  15274. return Conversions.canvasToDataURL(canvas, type, quality);
  15275. });
  15276. }
  15277. function toAdjustedBase64(type, quality) {
  15278. return toAdjustedDataURL(type, quality).then(function (dataurl) {
  15279. return dataurl.split(',')[1];
  15280. });
  15281. }
  15282. function toCanvas() {
  15283. return getCanvas.then(Canvas.clone);
  15284. }
  15285. return {
  15286. getType: getType,
  15287. toBlob: toBlob,
  15288. toDataURL: toDataURL,
  15289. toBase64: toBase64,
  15290. toAdjustedBlob: toAdjustedBlob,
  15291. toAdjustedDataURL: toAdjustedDataURL,
  15292. toAdjustedBase64: toAdjustedBase64,
  15293. toCanvas: toCanvas
  15294. };
  15295. }
  15296. function fromBlob(blob) {
  15297. return Conversions.blobToDataUri(blob).then(function (uri) {
  15298. return create$5(Conversions.blobToCanvas(blob), blob, uri);
  15299. });
  15300. }
  15301. function fromCanvas(canvas, type) {
  15302. return Conversions.canvasToBlob(canvas, type).then(function (blob) {
  15303. return create$5(Promise.resolve(canvas), blob, canvas.toDataURL());
  15304. });
  15305. }
  15306. function fromImage(image) {
  15307. return Conversions.imageToBlob(image).then(function (blob) {
  15308. return fromBlob(blob);
  15309. });
  15310. }
  15311. var fromBlobAndUrlSync = function (blob, url) {
  15312. return create$5(Conversions.blobToCanvas(blob), blob, url);
  15313. };
  15314. var ImageResult = {
  15315. fromBlob: fromBlob,
  15316. fromCanvas: fromCanvas,
  15317. fromImage: fromImage,
  15318. fromBlobAndUrlSync: fromBlobAndUrlSync
  15319. };
  15320. var blobToImageResult = function (blob) {
  15321. return ImageResult.fromBlob(blob);
  15322. };
  15323. var fromBlobAndUrlSync$1 = function (blob, uri) {
  15324. return ImageResult.fromBlobAndUrlSync(blob, uri);
  15325. };
  15326. var imageToImageResult = function (image) {
  15327. return ImageResult.fromImage(image);
  15328. };
  15329. var imageResultToBlob = function (ir, type, quality) {
  15330. if (type === undefined && quality === undefined) {
  15331. return imageResultToOriginalBlob(ir);
  15332. } else {
  15333. return ir.toAdjustedBlob(type, quality);
  15334. }
  15335. };
  15336. var imageResultToOriginalBlob = function (ir) {
  15337. return ir.toBlob();
  15338. };
  15339. var imageResultToDataURL = function (ir) {
  15340. return ir.toDataURL();
  15341. };
  15342. var ResultConversions = {
  15343. blobToImageResult: blobToImageResult,
  15344. fromBlobAndUrlSync: fromBlobAndUrlSync$1,
  15345. imageToImageResult: imageToImageResult,
  15346. imageResultToBlob: imageResultToBlob,
  15347. imageResultToOriginalBlob: imageResultToOriginalBlob,
  15348. imageResultToDataURL: imageResultToDataURL
  15349. };
  15350. function clamp(value, min, max) {
  15351. value = parseFloat(value);
  15352. if (value > max) {
  15353. value = max;
  15354. } else if (value < min) {
  15355. value = min;
  15356. }
  15357. return value;
  15358. }
  15359. function identity$1() {
  15360. return [
  15361. 1,
  15362. 0,
  15363. 0,
  15364. 0,
  15365. 0,
  15366. 0,
  15367. 1,
  15368. 0,
  15369. 0,
  15370. 0,
  15371. 0,
  15372. 0,
  15373. 1,
  15374. 0,
  15375. 0,
  15376. 0,
  15377. 0,
  15378. 0,
  15379. 1,
  15380. 0,
  15381. 0,
  15382. 0,
  15383. 0,
  15384. 0,
  15385. 1
  15386. ];
  15387. }
  15388. var DELTA_INDEX = [
  15389. 0,
  15390. 0.01,
  15391. 0.02,
  15392. 0.04,
  15393. 0.05,
  15394. 0.06,
  15395. 0.07,
  15396. 0.08,
  15397. 0.1,
  15398. 0.11,
  15399. 0.12,
  15400. 0.14,
  15401. 0.15,
  15402. 0.16,
  15403. 0.17,
  15404. 0.18,
  15405. 0.2,
  15406. 0.21,
  15407. 0.22,
  15408. 0.24,
  15409. 0.25,
  15410. 0.27,
  15411. 0.28,
  15412. 0.3,
  15413. 0.32,
  15414. 0.34,
  15415. 0.36,
  15416. 0.38,
  15417. 0.4,
  15418. 0.42,
  15419. 0.44,
  15420. 0.46,
  15421. 0.48,
  15422. 0.5,
  15423. 0.53,
  15424. 0.56,
  15425. 0.59,
  15426. 0.62,
  15427. 0.65,
  15428. 0.68,
  15429. 0.71,
  15430. 0.74,
  15431. 0.77,
  15432. 0.8,
  15433. 0.83,
  15434. 0.86,
  15435. 0.89,
  15436. 0.92,
  15437. 0.95,
  15438. 0.98,
  15439. 1,
  15440. 1.06,
  15441. 1.12,
  15442. 1.18,
  15443. 1.24,
  15444. 1.3,
  15445. 1.36,
  15446. 1.42,
  15447. 1.48,
  15448. 1.54,
  15449. 1.6,
  15450. 1.66,
  15451. 1.72,
  15452. 1.78,
  15453. 1.84,
  15454. 1.9,
  15455. 1.96,
  15456. 2,
  15457. 2.12,
  15458. 2.25,
  15459. 2.37,
  15460. 2.5,
  15461. 2.62,
  15462. 2.75,
  15463. 2.87,
  15464. 3,
  15465. 3.2,
  15466. 3.4,
  15467. 3.6,
  15468. 3.8,
  15469. 4,
  15470. 4.3,
  15471. 4.7,
  15472. 4.9,
  15473. 5,
  15474. 5.5,
  15475. 6,
  15476. 6.5,
  15477. 6.8,
  15478. 7,
  15479. 7.3,
  15480. 7.5,
  15481. 7.8,
  15482. 8,
  15483. 8.4,
  15484. 8.7,
  15485. 9,
  15486. 9.4,
  15487. 9.6,
  15488. 9.8,
  15489. 10
  15490. ];
  15491. function multiply(matrix1, matrix2) {
  15492. var i, j, k, val, col = [], out = new Array(10);
  15493. for (i = 0; i < 5; i++) {
  15494. for (j = 0; j < 5; j++) {
  15495. col[j] = matrix2[j + i * 5];
  15496. }
  15497. for (j = 0; j < 5; j++) {
  15498. val = 0;
  15499. for (k = 0; k < 5; k++) {
  15500. val += matrix1[j + k * 5] * col[k];
  15501. }
  15502. out[j + i * 5] = val;
  15503. }
  15504. }
  15505. return out;
  15506. }
  15507. function adjust(matrix, adjustValue) {
  15508. adjustValue = clamp(adjustValue, 0, 1);
  15509. return matrix.map(function (value, index) {
  15510. if (index % 6 === 0) {
  15511. value = 1 - (1 - value) * adjustValue;
  15512. } else {
  15513. value *= adjustValue;
  15514. }
  15515. return clamp(value, 0, 1);
  15516. });
  15517. }
  15518. function adjustContrast(matrix, value) {
  15519. var x;
  15520. value = clamp(value, -1, 1);
  15521. value *= 100;
  15522. if (value < 0) {
  15523. x = 127 + value / 100 * 127;
  15524. } else {
  15525. x = value % 1;
  15526. if (x === 0) {
  15527. x = DELTA_INDEX[value];
  15528. } else {
  15529. x = DELTA_INDEX[Math.floor(value)] * (1 - x) + DELTA_INDEX[Math.floor(value) + 1] * x;
  15530. }
  15531. x = x * 127 + 127;
  15532. }
  15533. return multiply(matrix, [
  15534. x / 127,
  15535. 0,
  15536. 0,
  15537. 0,
  15538. 0.5 * (127 - x),
  15539. 0,
  15540. x / 127,
  15541. 0,
  15542. 0,
  15543. 0.5 * (127 - x),
  15544. 0,
  15545. 0,
  15546. x / 127,
  15547. 0,
  15548. 0.5 * (127 - x),
  15549. 0,
  15550. 0,
  15551. 0,
  15552. 1,
  15553. 0,
  15554. 0,
  15555. 0,
  15556. 0,
  15557. 0,
  15558. 1
  15559. ]);
  15560. }
  15561. function adjustSaturation(matrix, value) {
  15562. var x, lumR, lumG, lumB;
  15563. value = clamp(value, -1, 1);
  15564. x = 1 + (value > 0 ? 3 * value : value);
  15565. lumR = 0.3086;
  15566. lumG = 0.6094;
  15567. lumB = 0.082;
  15568. return multiply(matrix, [
  15569. lumR * (1 - x) + x,
  15570. lumG * (1 - x),
  15571. lumB * (1 - x),
  15572. 0,
  15573. 0,
  15574. lumR * (1 - x),
  15575. lumG * (1 - x) + x,
  15576. lumB * (1 - x),
  15577. 0,
  15578. 0,
  15579. lumR * (1 - x),
  15580. lumG * (1 - x),
  15581. lumB * (1 - x) + x,
  15582. 0,
  15583. 0,
  15584. 0,
  15585. 0,
  15586. 0,
  15587. 1,
  15588. 0,
  15589. 0,
  15590. 0,
  15591. 0,
  15592. 0,
  15593. 1
  15594. ]);
  15595. }
  15596. function adjustHue(matrix, angle) {
  15597. var cosVal, sinVal, lumR, lumG, lumB;
  15598. angle = clamp(angle, -180, 180) / 180 * Math.PI;
  15599. cosVal = Math.cos(angle);
  15600. sinVal = Math.sin(angle);
  15601. lumR = 0.213;
  15602. lumG = 0.715;
  15603. lumB = 0.072;
  15604. return multiply(matrix, [
  15605. lumR + cosVal * (1 - lumR) + sinVal * -lumR,
  15606. lumG + cosVal * -lumG + sinVal * -lumG,
  15607. lumB + cosVal * -lumB + sinVal * (1 - lumB),
  15608. 0,
  15609. 0,
  15610. lumR + cosVal * -lumR + sinVal * 0.143,
  15611. lumG + cosVal * (1 - lumG) + sinVal * 0.14,
  15612. lumB + cosVal * -lumB + sinVal * -0.283,
  15613. 0,
  15614. 0,
  15615. lumR + cosVal * -lumR + sinVal * -(1 - lumR),
  15616. lumG + cosVal * -lumG + sinVal * lumG,
  15617. lumB + cosVal * (1 - lumB) + sinVal * lumB,
  15618. 0,
  15619. 0,
  15620. 0,
  15621. 0,
  15622. 0,
  15623. 1,
  15624. 0,
  15625. 0,
  15626. 0,
  15627. 0,
  15628. 0,
  15629. 1
  15630. ]);
  15631. }
  15632. function adjustBrightness(matrix, value) {
  15633. value = clamp(255 * value, -255, 255);
  15634. return multiply(matrix, [
  15635. 1,
  15636. 0,
  15637. 0,
  15638. 0,
  15639. value,
  15640. 0,
  15641. 1,
  15642. 0,
  15643. 0,
  15644. value,
  15645. 0,
  15646. 0,
  15647. 1,
  15648. 0,
  15649. value,
  15650. 0,
  15651. 0,
  15652. 0,
  15653. 1,
  15654. 0,
  15655. 0,
  15656. 0,
  15657. 0,
  15658. 0,
  15659. 1
  15660. ]);
  15661. }
  15662. function adjustColors(matrix, adjustR, adjustG, adjustB) {
  15663. adjustR = clamp(adjustR, 0, 2);
  15664. adjustG = clamp(adjustG, 0, 2);
  15665. adjustB = clamp(adjustB, 0, 2);
  15666. return multiply(matrix, [
  15667. adjustR,
  15668. 0,
  15669. 0,
  15670. 0,
  15671. 0,
  15672. 0,
  15673. adjustG,
  15674. 0,
  15675. 0,
  15676. 0,
  15677. 0,
  15678. 0,
  15679. adjustB,
  15680. 0,
  15681. 0,
  15682. 0,
  15683. 0,
  15684. 0,
  15685. 1,
  15686. 0,
  15687. 0,
  15688. 0,
  15689. 0,
  15690. 0,
  15691. 1
  15692. ]);
  15693. }
  15694. function adjustSepia(matrix, value) {
  15695. value = clamp(value, 0, 1);
  15696. return multiply(matrix, adjust([
  15697. 0.393,
  15698. 0.769,
  15699. 0.189,
  15700. 0,
  15701. 0,
  15702. 0.349,
  15703. 0.686,
  15704. 0.168,
  15705. 0,
  15706. 0,
  15707. 0.272,
  15708. 0.534,
  15709. 0.131,
  15710. 0,
  15711. 0,
  15712. 0,
  15713. 0,
  15714. 0,
  15715. 1,
  15716. 0,
  15717. 0,
  15718. 0,
  15719. 0,
  15720. 0,
  15721. 1
  15722. ], value));
  15723. }
  15724. function adjustGrayscale(matrix, value) {
  15725. value = clamp(value, 0, 1);
  15726. return multiply(matrix, adjust([
  15727. 0.33,
  15728. 0.34,
  15729. 0.33,
  15730. 0,
  15731. 0,
  15732. 0.33,
  15733. 0.34,
  15734. 0.33,
  15735. 0,
  15736. 0,
  15737. 0.33,
  15738. 0.34,
  15739. 0.33,
  15740. 0,
  15741. 0,
  15742. 0,
  15743. 0,
  15744. 0,
  15745. 1,
  15746. 0,
  15747. 0,
  15748. 0,
  15749. 0,
  15750. 0,
  15751. 1
  15752. ], value));
  15753. }
  15754. var ColorMatrix = {
  15755. identity: identity$1,
  15756. adjust: adjust,
  15757. multiply: multiply,
  15758. adjustContrast: adjustContrast,
  15759. adjustBrightness: adjustBrightness,
  15760. adjustSaturation: adjustSaturation,
  15761. adjustHue: adjustHue,
  15762. adjustColors: adjustColors,
  15763. adjustSepia: adjustSepia,
  15764. adjustGrayscale: adjustGrayscale
  15765. };
  15766. function colorFilter(ir, matrix) {
  15767. return ir.toCanvas().then(function (canvas) {
  15768. return applyColorFilter(canvas, ir.getType(), matrix);
  15769. });
  15770. }
  15771. function applyColorFilter(canvas, type, matrix) {
  15772. var context = Canvas.get2dContext(canvas);
  15773. var pixels;
  15774. function applyMatrix(pixels, m) {
  15775. var d = pixels.data, r, g, b, a, i, 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];
  15776. for (i = 0; i < d.length; i += 4) {
  15777. r = d[i];
  15778. g = d[i + 1];
  15779. b = d[i + 2];
  15780. a = d[i + 3];
  15781. d[i] = r * m0 + g * m1 + b * m2 + a * m3 + m4;
  15782. d[i + 1] = r * m5 + g * m6 + b * m7 + a * m8 + m9;
  15783. d[i + 2] = r * m10 + g * m11 + b * m12 + a * m13 + m14;
  15784. d[i + 3] = r * m15 + g * m16 + b * m17 + a * m18 + m19;
  15785. }
  15786. return pixels;
  15787. }
  15788. pixels = applyMatrix(context.getImageData(0, 0, canvas.width, canvas.height), matrix);
  15789. context.putImageData(pixels, 0, 0);
  15790. return ImageResult.fromCanvas(canvas, type);
  15791. }
  15792. function convoluteFilter(ir, matrix) {
  15793. return ir.toCanvas().then(function (canvas) {
  15794. return applyConvoluteFilter(canvas, ir.getType(), matrix);
  15795. });
  15796. }
  15797. function applyConvoluteFilter(canvas, type, matrix) {
  15798. var context = Canvas.get2dContext(canvas);
  15799. var pixelsIn, pixelsOut;
  15800. function applyMatrix(pixelsIn, pixelsOut, matrix) {
  15801. var rgba, drgba, side, halfSide, x, y, r, g, b, cx, cy, scx, scy, offset, wt, w, h;
  15802. function clamp(value, min, max) {
  15803. if (value > max) {
  15804. value = max;
  15805. } else if (value < min) {
  15806. value = min;
  15807. }
  15808. return value;
  15809. }
  15810. side = Math.round(Math.sqrt(matrix.length));
  15811. halfSide = Math.floor(side / 2);
  15812. rgba = pixelsIn.data;
  15813. drgba = pixelsOut.data;
  15814. w = pixelsIn.width;
  15815. h = pixelsIn.height;
  15816. for (y = 0; y < h; y++) {
  15817. for (x = 0; x < w; x++) {
  15818. r = g = b = 0;
  15819. for (cy = 0; cy < side; cy++) {
  15820. for (cx = 0; cx < side; cx++) {
  15821. scx = clamp(x + cx - halfSide, 0, w - 1);
  15822. scy = clamp(y + cy - halfSide, 0, h - 1);
  15823. offset = (scy * w + scx) * 4;
  15824. wt = matrix[cy * side + cx];
  15825. r += rgba[offset] * wt;
  15826. g += rgba[offset + 1] * wt;
  15827. b += rgba[offset + 2] * wt;
  15828. }
  15829. }
  15830. offset = (y * w + x) * 4;
  15831. drgba[offset] = clamp(r, 0, 255);
  15832. drgba[offset + 1] = clamp(g, 0, 255);
  15833. drgba[offset + 2] = clamp(b, 0, 255);
  15834. }
  15835. }
  15836. return pixelsOut;
  15837. }
  15838. pixelsIn = context.getImageData(0, 0, canvas.width, canvas.height);
  15839. pixelsOut = context.getImageData(0, 0, canvas.width, canvas.height);
  15840. pixelsOut = applyMatrix(pixelsIn, pixelsOut, matrix);
  15841. context.putImageData(pixelsOut, 0, 0);
  15842. return ImageResult.fromCanvas(canvas, type);
  15843. }
  15844. function functionColorFilter(colorFn) {
  15845. var filterImpl = function (canvas, type, value) {
  15846. var context = Canvas.get2dContext(canvas);
  15847. var pixels, i, lookup = new Array(256);
  15848. function applyLookup(pixels, lookup) {
  15849. var d = pixels.data, i;
  15850. for (i = 0; i < d.length; i += 4) {
  15851. d[i] = lookup[d[i]];
  15852. d[i + 1] = lookup[d[i + 1]];
  15853. d[i + 2] = lookup[d[i + 2]];
  15854. }
  15855. return pixels;
  15856. }
  15857. for (i = 0; i < lookup.length; i++) {
  15858. lookup[i] = colorFn(i, value);
  15859. }
  15860. pixels = applyLookup(context.getImageData(0, 0, canvas.width, canvas.height), lookup);
  15861. context.putImageData(pixels, 0, 0);
  15862. return ImageResult.fromCanvas(canvas, type);
  15863. };
  15864. return function (ir, value) {
  15865. return ir.toCanvas().then(function (canvas) {
  15866. return filterImpl(canvas, ir.getType(), value);
  15867. });
  15868. };
  15869. }
  15870. function complexAdjustableColorFilter(matrixAdjustFn) {
  15871. return function (ir, adjust) {
  15872. return colorFilter(ir, matrixAdjustFn(ColorMatrix.identity(), adjust));
  15873. };
  15874. }
  15875. function basicColorFilter(matrix) {
  15876. return function (ir) {
  15877. return colorFilter(ir, matrix);
  15878. };
  15879. }
  15880. function basicConvolutionFilter(kernel) {
  15881. return function (ir) {
  15882. return convoluteFilter(ir, kernel);
  15883. };
  15884. }
  15885. var Filters = {
  15886. invert: basicColorFilter([
  15887. -1,
  15888. 0,
  15889. 0,
  15890. 0,
  15891. 255,
  15892. 0,
  15893. -1,
  15894. 0,
  15895. 0,
  15896. 255,
  15897. 0,
  15898. 0,
  15899. -1,
  15900. 0,
  15901. 255,
  15902. 0,
  15903. 0,
  15904. 0,
  15905. 1,
  15906. 0
  15907. ]),
  15908. brightness: complexAdjustableColorFilter(ColorMatrix.adjustBrightness),
  15909. hue: complexAdjustableColorFilter(ColorMatrix.adjustHue),
  15910. saturate: complexAdjustableColorFilter(ColorMatrix.adjustSaturation),
  15911. contrast: complexAdjustableColorFilter(ColorMatrix.adjustContrast),
  15912. grayscale: complexAdjustableColorFilter(ColorMatrix.adjustGrayscale),
  15913. sepia: complexAdjustableColorFilter(ColorMatrix.adjustSepia),
  15914. colorize: function (ir, adjustR, adjustG, adjustB) {
  15915. return colorFilter(ir, ColorMatrix.adjustColors(ColorMatrix.identity(), adjustR, adjustG, adjustB));
  15916. },
  15917. sharpen: basicConvolutionFilter([
  15918. 0,
  15919. -1,
  15920. 0,
  15921. -1,
  15922. 5,
  15923. -1,
  15924. 0,
  15925. -1,
  15926. 0
  15927. ]),
  15928. emboss: basicConvolutionFilter([
  15929. -2,
  15930. -1,
  15931. 0,
  15932. -1,
  15933. 1,
  15934. 1,
  15935. 0,
  15936. 1,
  15937. 2
  15938. ]),
  15939. gamma: functionColorFilter(function (color, value) {
  15940. return Math.pow(color / 255, 1 - value) * 255;
  15941. }),
  15942. exposure: functionColorFilter(function (color, value) {
  15943. return 255 * (1 - Math.exp(-(color / 255) * value));
  15944. }),
  15945. colorFilter: colorFilter,
  15946. convoluteFilter: convoluteFilter
  15947. };
  15948. function scale(image, dW, dH) {
  15949. var sW = ImageSize.getWidth(image);
  15950. var sH = ImageSize.getHeight(image);
  15951. var wRatio = dW / sW;
  15952. var hRatio = dH / sH;
  15953. var scaleCapped = false;
  15954. if (wRatio < 0.5 || wRatio > 2) {
  15955. wRatio = wRatio < 0.5 ? 0.5 : 2;
  15956. scaleCapped = true;
  15957. }
  15958. if (hRatio < 0.5 || hRatio > 2) {
  15959. hRatio = hRatio < 0.5 ? 0.5 : 2;
  15960. scaleCapped = true;
  15961. }
  15962. var scaled = _scale(image, wRatio, hRatio);
  15963. return !scaleCapped ? scaled : scaled.then(function (tCanvas) {
  15964. return scale(tCanvas, dW, dH);
  15965. });
  15966. }
  15967. function _scale(image, wRatio, hRatio) {
  15968. return new Promise(function (resolve) {
  15969. var sW = ImageSize.getWidth(image);
  15970. var sH = ImageSize.getHeight(image);
  15971. var dW = Math.floor(sW * wRatio);
  15972. var dH = Math.floor(sH * hRatio);
  15973. var canvas = Canvas.create(dW, dH);
  15974. var context = Canvas.get2dContext(canvas);
  15975. context.drawImage(image, 0, 0, sW, sH, 0, 0, dW, dH);
  15976. resolve(canvas);
  15977. });
  15978. }
  15979. var ImageResizerCanvas = { scale: scale };
  15980. function rotate(ir, angle) {
  15981. return ir.toCanvas().then(function (canvas) {
  15982. return applyRotate(canvas, ir.getType(), angle);
  15983. });
  15984. }
  15985. function applyRotate(image, type, angle) {
  15986. var canvas = Canvas.create(image.width, image.height);
  15987. var context = Canvas.get2dContext(canvas);
  15988. var translateX = 0, translateY = 0;
  15989. angle = angle < 0 ? 360 + angle : angle;
  15990. if (angle == 90 || angle == 270) {
  15991. Canvas.resize(canvas, canvas.height, canvas.width);
  15992. }
  15993. if (angle == 90 || angle == 180) {
  15994. translateX = canvas.width;
  15995. }
  15996. if (angle == 270 || angle == 180) {
  15997. translateY = canvas.height;
  15998. }
  15999. context.translate(translateX, translateY);
  16000. context.rotate(angle * Math.PI / 180);
  16001. context.drawImage(image, 0, 0);
  16002. return ImageResult.fromCanvas(canvas, type);
  16003. }
  16004. function flip(ir, axis) {
  16005. return ir.toCanvas().then(function (canvas) {
  16006. return applyFlip(canvas, ir.getType(), axis);
  16007. });
  16008. }
  16009. function applyFlip(image, type, axis) {
  16010. var canvas = Canvas.create(image.width, image.height);
  16011. var context = Canvas.get2dContext(canvas);
  16012. if (axis == 'v') {
  16013. context.scale(1, -1);
  16014. context.drawImage(image, 0, -canvas.height);
  16015. } else {
  16016. context.scale(-1, 1);
  16017. context.drawImage(image, -canvas.width, 0);
  16018. }
  16019. return ImageResult.fromCanvas(canvas, type);
  16020. }
  16021. function crop(ir, x, y, w, h) {
  16022. return ir.toCanvas().then(function (canvas) {
  16023. return applyCrop(canvas, ir.getType(), x, y, w, h);
  16024. });
  16025. }
  16026. function applyCrop(image, type, x, y, w, h) {
  16027. var canvas = Canvas.create(w, h);
  16028. var context = Canvas.get2dContext(canvas);
  16029. context.drawImage(image, -x, -y);
  16030. return ImageResult.fromCanvas(canvas, type);
  16031. }
  16032. function resize$1(ir, w, h) {
  16033. return ir.toCanvas().then(function (canvas) {
  16034. return ImageResizerCanvas.scale(canvas, w, h).then(function (newCanvas) {
  16035. return ImageResult.fromCanvas(newCanvas, ir.getType());
  16036. });
  16037. });
  16038. }
  16039. var ImageTools = {
  16040. rotate: rotate,
  16041. flip: flip,
  16042. crop: crop,
  16043. resize: resize$1
  16044. };
  16045. var BinaryReader = function () {
  16046. function BinaryReader(ar) {
  16047. this.littleEndian = false;
  16048. this._dv = new DataView(ar);
  16049. }
  16050. BinaryReader.prototype.readByteAt = function (idx) {
  16051. return this._dv.getUint8(idx);
  16052. };
  16053. BinaryReader.prototype.read = function (idx, size) {
  16054. if (idx + size > this.length()) {
  16055. return null;
  16056. }
  16057. var mv = this.littleEndian ? 0 : -8 * (size - 1);
  16058. for (var i = 0, sum = 0; i < size; i++) {
  16059. sum |= this.readByteAt(idx + i) << Math.abs(mv + i * 8);
  16060. }
  16061. return sum;
  16062. };
  16063. BinaryReader.prototype.BYTE = function (idx) {
  16064. return this.read(idx, 1);
  16065. };
  16066. BinaryReader.prototype.SHORT = function (idx) {
  16067. return this.read(idx, 2);
  16068. };
  16069. BinaryReader.prototype.LONG = function (idx) {
  16070. return this.read(idx, 4);
  16071. };
  16072. BinaryReader.prototype.SLONG = function (idx) {
  16073. var num = this.read(idx, 4);
  16074. return num > 2147483647 ? num - 4294967296 : num;
  16075. };
  16076. BinaryReader.prototype.CHAR = function (idx) {
  16077. return String.fromCharCode(this.read(idx, 1));
  16078. };
  16079. BinaryReader.prototype.STRING = function (idx, count) {
  16080. return this.asArray('CHAR', idx, count).join('');
  16081. };
  16082. BinaryReader.prototype.SEGMENT = function (idx, size) {
  16083. var ar = this._dv.buffer;
  16084. switch (arguments.length) {
  16085. case 2:
  16086. return ar.slice(idx, idx + size);
  16087. case 1:
  16088. return ar.slice(idx);
  16089. default:
  16090. return ar;
  16091. }
  16092. };
  16093. BinaryReader.prototype.asArray = function (type, idx, count) {
  16094. var values = [];
  16095. for (var i = 0; i < count; i++) {
  16096. values[i] = this[type](idx + i);
  16097. }
  16098. return values;
  16099. };
  16100. BinaryReader.prototype.length = function () {
  16101. return this._dv ? this._dv.byteLength : 0;
  16102. };
  16103. return BinaryReader;
  16104. }();
  16105. var tags = {
  16106. tiff: {
  16107. 274: 'Orientation',
  16108. 270: 'ImageDescription',
  16109. 271: 'Make',
  16110. 272: 'Model',
  16111. 305: 'Software',
  16112. 34665: 'ExifIFDPointer',
  16113. 34853: 'GPSInfoIFDPointer'
  16114. },
  16115. exif: {
  16116. 36864: 'ExifVersion',
  16117. 40961: 'ColorSpace',
  16118. 40962: 'PixelXDimension',
  16119. 40963: 'PixelYDimension',
  16120. 36867: 'DateTimeOriginal',
  16121. 33434: 'ExposureTime',
  16122. 33437: 'FNumber',
  16123. 34855: 'ISOSpeedRatings',
  16124. 37377: 'ShutterSpeedValue',
  16125. 37378: 'ApertureValue',
  16126. 37383: 'MeteringMode',
  16127. 37384: 'LightSource',
  16128. 37385: 'Flash',
  16129. 37386: 'FocalLength',
  16130. 41986: 'ExposureMode',
  16131. 41987: 'WhiteBalance',
  16132. 41990: 'SceneCaptureType',
  16133. 41988: 'DigitalZoomRatio',
  16134. 41992: 'Contrast',
  16135. 41993: 'Saturation',
  16136. 41994: 'Sharpness'
  16137. },
  16138. gps: {
  16139. 0: 'GPSVersionID',
  16140. 1: 'GPSLatitudeRef',
  16141. 2: 'GPSLatitude',
  16142. 3: 'GPSLongitudeRef',
  16143. 4: 'GPSLongitude'
  16144. },
  16145. thumb: {
  16146. 513: 'JPEGInterchangeFormat',
  16147. 514: 'JPEGInterchangeFormatLength'
  16148. }
  16149. };
  16150. var tagDescs = {
  16151. 'ColorSpace': {
  16152. 1: 'sRGB',
  16153. 0: 'Uncalibrated'
  16154. },
  16155. 'MeteringMode': {
  16156. 0: 'Unknown',
  16157. 1: 'Average',
  16158. 2: 'CenterWeightedAverage',
  16159. 3: 'Spot',
  16160. 4: 'MultiSpot',
  16161. 5: 'Pattern',
  16162. 6: 'Partial',
  16163. 255: 'Other'
  16164. },
  16165. 'LightSource': {
  16166. 1: 'Daylight',
  16167. 2: 'Fliorescent',
  16168. 3: 'Tungsten',
  16169. 4: 'Flash',
  16170. 9: 'Fine weather',
  16171. 10: 'Cloudy weather',
  16172. 11: 'Shade',
  16173. 12: 'Daylight fluorescent (D 5700 - 7100K)',
  16174. 13: 'Day white fluorescent (N 4600 -5400K)',
  16175. 14: 'Cool white fluorescent (W 3900 - 4500K)',
  16176. 15: 'White fluorescent (WW 3200 - 3700K)',
  16177. 17: 'Standard light A',
  16178. 18: 'Standard light B',
  16179. 19: 'Standard light C',
  16180. 20: 'D55',
  16181. 21: 'D65',
  16182. 22: 'D75',
  16183. 23: 'D50',
  16184. 24: 'ISO studio tungsten',
  16185. 255: 'Other'
  16186. },
  16187. 'Flash': {
  16188. 0: 'Flash did not fire',
  16189. 1: 'Flash fired',
  16190. 5: 'Strobe return light not detected',
  16191. 7: 'Strobe return light detected',
  16192. 9: 'Flash fired, compulsory flash mode',
  16193. 13: 'Flash fired, compulsory flash mode, return light not detected',
  16194. 15: 'Flash fired, compulsory flash mode, return light detected',
  16195. 16: 'Flash did not fire, compulsory flash mode',
  16196. 24: 'Flash did not fire, auto mode',
  16197. 25: 'Flash fired, auto mode',
  16198. 29: 'Flash fired, auto mode, return light not detected',
  16199. 31: 'Flash fired, auto mode, return light detected',
  16200. 32: 'No flash function',
  16201. 65: 'Flash fired, red-eye reduction mode',
  16202. 69: 'Flash fired, red-eye reduction mode, return light not detected',
  16203. 71: 'Flash fired, red-eye reduction mode, return light detected',
  16204. 73: 'Flash fired, compulsory flash mode, red-eye reduction mode',
  16205. 77: 'Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected',
  16206. 79: 'Flash fired, compulsory flash mode, red-eye reduction mode, return light detected',
  16207. 89: 'Flash fired, auto mode, red-eye reduction mode',
  16208. 93: 'Flash fired, auto mode, return light not detected, red-eye reduction mode',
  16209. 95: 'Flash fired, auto mode, return light detected, red-eye reduction mode'
  16210. },
  16211. 'ExposureMode': {
  16212. 0: 'Auto exposure',
  16213. 1: 'Manual exposure',
  16214. 2: 'Auto bracket'
  16215. },
  16216. 'WhiteBalance': {
  16217. 0: 'Auto white balance',
  16218. 1: 'Manual white balance'
  16219. },
  16220. 'SceneCaptureType': {
  16221. 0: 'Standard',
  16222. 1: 'Landscape',
  16223. 2: 'Portrait',
  16224. 3: 'Night scene'
  16225. },
  16226. 'Contrast': {
  16227. 0: 'Normal',
  16228. 1: 'Soft',
  16229. 2: 'Hard'
  16230. },
  16231. 'Saturation': {
  16232. 0: 'Normal',
  16233. 1: 'Low saturation',
  16234. 2: 'High saturation'
  16235. },
  16236. 'Sharpness': {
  16237. 0: 'Normal',
  16238. 1: 'Soft',
  16239. 2: 'Hard'
  16240. },
  16241. 'GPSLatitudeRef': {
  16242. N: 'North latitude',
  16243. S: 'South latitude'
  16244. },
  16245. 'GPSLongitudeRef': {
  16246. E: 'East longitude',
  16247. W: 'West longitude'
  16248. }
  16249. };
  16250. var ExifReader = function () {
  16251. function ExifReader(ar) {
  16252. this._offsets = {
  16253. tiffHeader: 10,
  16254. IFD0: null,
  16255. IFD1: null,
  16256. exifIFD: null,
  16257. gpsIFD: null
  16258. };
  16259. this._tiffTags = {};
  16260. var self = this;
  16261. self._reader = new BinaryReader(ar);
  16262. self._idx = self._offsets.tiffHeader;
  16263. if (self.SHORT(0) !== 65505 || self.STRING(4, 5).toUpperCase() !== 'EXIF\0') {
  16264. throw new Error('Exif data cannot be read or not available.');
  16265. }
  16266. self._reader.littleEndian = self.SHORT(self._idx) == 18761;
  16267. if (self.SHORT(self._idx += 2) !== 42) {
  16268. throw new Error('Invalid Exif data.');
  16269. }
  16270. self._offsets.IFD0 = self._offsets.tiffHeader + self.LONG(self._idx += 2);
  16271. self._tiffTags = self.extractTags(self._offsets.IFD0, tags.tiff);
  16272. if ('ExifIFDPointer' in self._tiffTags) {
  16273. self._offsets.exifIFD = self._offsets.tiffHeader + self._tiffTags.ExifIFDPointer;
  16274. delete self._tiffTags.ExifIFDPointer;
  16275. }
  16276. if ('GPSInfoIFDPointer' in self._tiffTags) {
  16277. self._offsets.gpsIFD = self._offsets.tiffHeader + self._tiffTags.GPSInfoIFDPointer;
  16278. delete self._tiffTags.GPSInfoIFDPointer;
  16279. }
  16280. var IFD1Offset = self.LONG(self._offsets.IFD0 + self.SHORT(self._offsets.IFD0) * 12 + 2);
  16281. if (IFD1Offset) {
  16282. self._offsets.IFD1 = self._offsets.tiffHeader + IFD1Offset;
  16283. }
  16284. }
  16285. ExifReader.prototype.BYTE = function (idx) {
  16286. return this._reader.BYTE(idx);
  16287. };
  16288. ExifReader.prototype.SHORT = function (idx) {
  16289. return this._reader.SHORT(idx);
  16290. };
  16291. ExifReader.prototype.LONG = function (idx) {
  16292. return this._reader.LONG(idx);
  16293. };
  16294. ExifReader.prototype.SLONG = function (idx) {
  16295. return this._reader.SLONG(idx);
  16296. };
  16297. ExifReader.prototype.CHAR = function (idx) {
  16298. return this._reader.CHAR(idx);
  16299. };
  16300. ExifReader.prototype.STRING = function (idx, count) {
  16301. return this._reader.STRING(idx, count);
  16302. };
  16303. ExifReader.prototype.SEGMENT = function (idx, size) {
  16304. return this._reader.SEGMENT(idx, size);
  16305. };
  16306. ExifReader.prototype.asArray = function (type, idx, count) {
  16307. var values = [];
  16308. for (var i = 0; i < count; i++) {
  16309. values[i] = this[type](idx + i);
  16310. }
  16311. return values;
  16312. };
  16313. ExifReader.prototype.length = function () {
  16314. return this._reader.length();
  16315. };
  16316. ExifReader.prototype.UNDEFINED = function () {
  16317. return this.BYTE.apply(this, arguments);
  16318. };
  16319. ExifReader.prototype.RATIONAL = function (idx) {
  16320. return this.LONG(idx) / this.LONG(idx + 4);
  16321. };
  16322. ExifReader.prototype.SRATIONAL = function (idx) {
  16323. return this.SLONG(idx) / this.SLONG(idx + 4);
  16324. };
  16325. ExifReader.prototype.ASCII = function (idx) {
  16326. return this.CHAR(idx);
  16327. };
  16328. ExifReader.prototype.TIFF = function () {
  16329. return this._tiffTags;
  16330. };
  16331. ExifReader.prototype.EXIF = function () {
  16332. var self = this;
  16333. var Exif = null;
  16334. if (self._offsets.exifIFD) {
  16335. try {
  16336. Exif = self.extractTags(self._offsets.exifIFD, tags.exif);
  16337. } catch (ex) {
  16338. return null;
  16339. }
  16340. if (Exif.ExifVersion && Array.isArray(Exif.ExifVersion)) {
  16341. for (var i = 0, exifVersion = ''; i < Exif.ExifVersion.length; i++) {
  16342. exifVersion += String.fromCharCode(Exif.ExifVersion[i]);
  16343. }
  16344. Exif.ExifVersion = exifVersion;
  16345. }
  16346. }
  16347. return Exif;
  16348. };
  16349. ExifReader.prototype.GPS = function () {
  16350. var self = this;
  16351. var GPS = null;
  16352. if (self._offsets.gpsIFD) {
  16353. try {
  16354. GPS = self.extractTags(self._offsets.gpsIFD, tags.gps);
  16355. } catch (ex) {
  16356. return null;
  16357. }
  16358. if (GPS.GPSVersionID && Array.isArray(GPS.GPSVersionID)) {
  16359. GPS.GPSVersionID = GPS.GPSVersionID.join('.');
  16360. }
  16361. }
  16362. return GPS;
  16363. };
  16364. ExifReader.prototype.thumb = function () {
  16365. var self = this;
  16366. if (self._offsets.IFD1) {
  16367. try {
  16368. var IFD1Tags = self.extractTags(self._offsets.IFD1, tags.thumb);
  16369. if ('JPEGInterchangeFormat' in IFD1Tags) {
  16370. return self.SEGMENT(self._offsets.tiffHeader + IFD1Tags.JPEGInterchangeFormat, IFD1Tags.JPEGInterchangeFormatLength);
  16371. }
  16372. } catch (ex) {
  16373. }
  16374. }
  16375. return null;
  16376. };
  16377. ExifReader.prototype.extractTags = function (IFD_offset, tags2extract) {
  16378. var self = this;
  16379. var length, i, tag, type, count, size, offset, value, values = [], hash = {};
  16380. var types = {
  16381. 1: 'BYTE',
  16382. 7: 'UNDEFINED',
  16383. 2: 'ASCII',
  16384. 3: 'SHORT',
  16385. 4: 'LONG',
  16386. 5: 'RATIONAL',
  16387. 9: 'SLONG',
  16388. 10: 'SRATIONAL'
  16389. };
  16390. var sizes = {
  16391. 'BYTE': 1,
  16392. 'UNDEFINED': 1,
  16393. 'ASCII': 1,
  16394. 'SHORT': 2,
  16395. 'LONG': 4,
  16396. 'RATIONAL': 8,
  16397. 'SLONG': 4,
  16398. 'SRATIONAL': 8
  16399. };
  16400. length = self.SHORT(IFD_offset);
  16401. for (i = 0; i < length; i++) {
  16402. values = [];
  16403. offset = IFD_offset + 2 + i * 12;
  16404. tag = tags2extract[self.SHORT(offset)];
  16405. if (tag === undefined) {
  16406. continue;
  16407. }
  16408. type = types[self.SHORT(offset += 2)];
  16409. count = self.LONG(offset += 2);
  16410. size = sizes[type];
  16411. if (!size) {
  16412. throw new Error('Invalid Exif data.');
  16413. }
  16414. offset += 4;
  16415. if (size * count > 4) {
  16416. offset = self.LONG(offset) + self._offsets.tiffHeader;
  16417. }
  16418. if (offset + size * count >= self.length()) {
  16419. throw new Error('Invalid Exif data.');
  16420. }
  16421. if (type === 'ASCII') {
  16422. hash[tag] = self.STRING(offset, count).replace(/\0$/, '').trim();
  16423. continue;
  16424. } else {
  16425. values = self.asArray(type, offset, count);
  16426. value = count == 1 ? values[0] : values;
  16427. if (tagDescs.hasOwnProperty(tag) && typeof value != 'object') {
  16428. hash[tag] = tagDescs[tag][value];
  16429. } else {
  16430. hash[tag] = value;
  16431. }
  16432. }
  16433. }
  16434. return hash;
  16435. };
  16436. return ExifReader;
  16437. }();
  16438. var extractFrom = function (blob) {
  16439. return Conversions.blobToArrayBuffer(blob).then(function (ar) {
  16440. try {
  16441. var br = new BinaryReader(ar);
  16442. if (br.SHORT(0) === 65496) {
  16443. var headers = extractHeaders(br);
  16444. var app1 = headers.filter(function (header) {
  16445. return header.name === 'APP1';
  16446. });
  16447. var meta = {};
  16448. if (app1.length) {
  16449. var exifReader = new ExifReader(app1[0].segment);
  16450. meta = {
  16451. tiff: exifReader.TIFF(),
  16452. exif: exifReader.EXIF(),
  16453. gps: exifReader.GPS(),
  16454. thumb: exifReader.thumb()
  16455. };
  16456. } else {
  16457. return Promise.reject('Headers did not include required information');
  16458. }
  16459. meta.rawHeaders = headers;
  16460. return meta;
  16461. }
  16462. return Promise.reject('Image was not a jpeg');
  16463. } catch (ex) {
  16464. return Promise.reject('Unsupported format or not an image: ' + blob.type + ' (Exception: ' + ex.message + ')');
  16465. }
  16466. });
  16467. };
  16468. var extractHeaders = function (br) {
  16469. var headers = [], idx, marker, length = 0;
  16470. idx = 2;
  16471. while (idx <= br.length()) {
  16472. marker = br.SHORT(idx);
  16473. if (marker >= 65488 && marker <= 65495) {
  16474. idx += 2;
  16475. continue;
  16476. }
  16477. if (marker === 65498 || marker === 65497) {
  16478. break;
  16479. }
  16480. length = br.SHORT(idx + 2) + 2;
  16481. if (marker >= 65505 && marker <= 65519) {
  16482. headers.push({
  16483. hex: marker,
  16484. name: 'APP' + (marker & 15),
  16485. start: idx,
  16486. length: length,
  16487. segment: br.SEGMENT(idx, length)
  16488. });
  16489. }
  16490. idx += length;
  16491. }
  16492. return headers;
  16493. };
  16494. var JPEGMeta = { extractFrom: extractFrom };
  16495. var invert = function (ir) {
  16496. return Filters.invert(ir);
  16497. };
  16498. var sharpen = function (ir) {
  16499. return Filters.sharpen(ir);
  16500. };
  16501. var emboss = function (ir) {
  16502. return Filters.emboss(ir);
  16503. };
  16504. var gamma = function (ir, value) {
  16505. return Filters.gamma(ir, value);
  16506. };
  16507. var exposure = function (ir, value) {
  16508. return Filters.exposure(ir, value);
  16509. };
  16510. var colorize = function (ir, adjustR, adjustG, adjustB) {
  16511. return Filters.colorize(ir, adjustR, adjustG, adjustB);
  16512. };
  16513. var brightness = function (ir, adjust) {
  16514. return Filters.brightness(ir, adjust);
  16515. };
  16516. var hue = function (ir, adjust) {
  16517. return Filters.hue(ir, adjust);
  16518. };
  16519. var saturate = function (ir, adjust) {
  16520. return Filters.saturate(ir, adjust);
  16521. };
  16522. var contrast = function (ir, adjust) {
  16523. return Filters.contrast(ir, adjust);
  16524. };
  16525. var grayscale = function (ir, adjust) {
  16526. return Filters.grayscale(ir, adjust);
  16527. };
  16528. var sepia = function (ir, adjust) {
  16529. return Filters.sepia(ir, adjust);
  16530. };
  16531. var flip$1 = function (ir, axis) {
  16532. return ImageTools.flip(ir, axis);
  16533. };
  16534. var crop$1 = function (ir, x, y, w, h) {
  16535. return ImageTools.crop(ir, x, y, w, h);
  16536. };
  16537. var resize$2 = function (ir, w, h) {
  16538. return ImageTools.resize(ir, w, h);
  16539. };
  16540. var rotate$1 = function (ir, angle) {
  16541. return ImageTools.rotate(ir, angle);
  16542. };
  16543. var exifRotate = function (ir) {
  16544. var ROTATE_90 = 6;
  16545. var ROTATE_180 = 3;
  16546. var ROTATE_270 = 8;
  16547. var checkRotation = function (data) {
  16548. var orientation = data.tiff.Orientation;
  16549. switch (orientation) {
  16550. case ROTATE_90:
  16551. return rotate$1(ir, 90);
  16552. case ROTATE_180:
  16553. return rotate$1(ir, 180);
  16554. case ROTATE_270:
  16555. return rotate$1(ir, 270);
  16556. default:
  16557. return ir;
  16558. }
  16559. };
  16560. var notJpeg = function () {
  16561. return ir;
  16562. };
  16563. return ir.toBlob().then(JPEGMeta.extractFrom).then(checkRotation, notJpeg);
  16564. };
  16565. var ImageTransformations = {
  16566. invert: invert,
  16567. sharpen: sharpen,
  16568. emboss: emboss,
  16569. brightness: brightness,
  16570. hue: hue,
  16571. saturate: saturate,
  16572. contrast: contrast,
  16573. grayscale: grayscale,
  16574. sepia: sepia,
  16575. colorize: colorize,
  16576. gamma: gamma,
  16577. exposure: exposure,
  16578. flip: flip$1,
  16579. crop: crop$1,
  16580. resize: resize$2,
  16581. rotate: rotate$1,
  16582. exifRotate: exifRotate
  16583. };
  16584. var renderIcon$1 = function (iconHtml, behaviours) {
  16585. return __assign({
  16586. dom: {
  16587. tag: 'span',
  16588. innerHtml: iconHtml,
  16589. classes: [
  16590. 'tox-icon',
  16591. 'tox-tbtn__icon-wrap'
  16592. ]
  16593. }
  16594. }, behaviours);
  16595. };
  16596. var renderIconFromPack = function (iconName, iconsProvider) {
  16597. return renderIcon$1(get$c(iconName, iconsProvider), {});
  16598. };
  16599. var renderReplacableIconFromPack = function (iconName, iconsProvider) {
  16600. return renderIcon$1(get$c(iconName, iconsProvider), { behaviours: derive$1([Replacing.config({})]) });
  16601. };
  16602. var renderLabel$1 = function (text, prefix, providersBackstage) {
  16603. return {
  16604. dom: {
  16605. tag: 'span',
  16606. innerHtml: providersBackstage.translate(text),
  16607. classes: [prefix + '__select-label']
  16608. },
  16609. behaviours: derive$1([Replacing.config({})])
  16610. };
  16611. };
  16612. var renderCommonSpec = function (spec, actionOpt, extraBehaviours, dom, components) {
  16613. if (extraBehaviours === void 0) {
  16614. extraBehaviours = [];
  16615. }
  16616. var action = actionOpt.fold(function () {
  16617. return {};
  16618. }, function (action) {
  16619. return { action: action };
  16620. });
  16621. var common = __assign({
  16622. buttonBehaviours: derive$1([
  16623. DisablingConfigs.button(spec.disabled),
  16624. Tabstopping.config({}),
  16625. config('button press', [
  16626. preventDefault('click'),
  16627. preventDefault('mousedown')
  16628. ])
  16629. ].concat(extraBehaviours)),
  16630. eventOrder: {
  16631. click: [
  16632. 'button press',
  16633. 'alloy.base.behaviour'
  16634. ],
  16635. mousedown: [
  16636. 'button press',
  16637. 'alloy.base.behaviour'
  16638. ]
  16639. }
  16640. }, action);
  16641. var domFinal = deepMerge(common, { dom: dom });
  16642. return deepMerge(domFinal, { components: components });
  16643. };
  16644. var renderCommon = function (spec, action, extraBehaviours, dom, components) {
  16645. if (extraBehaviours === void 0) {
  16646. extraBehaviours = [];
  16647. }
  16648. var specFinal = renderCommonSpec(spec, Option.some(action), extraBehaviours, dom, components);
  16649. return Button.sketch(specFinal);
  16650. };
  16651. var renderIconButtonSpec = function (spec, action, providersBackstage, extraBehaviours) {
  16652. if (extraBehaviours === void 0) {
  16653. extraBehaviours = [];
  16654. }
  16655. var tooltipAttributes = spec.tooltip.map(function (tooltip) {
  16656. return {
  16657. 'aria-label': providersBackstage.translate(tooltip),
  16658. 'title': providersBackstage.translate(tooltip)
  16659. };
  16660. }).getOr({});
  16661. var dom = {
  16662. tag: 'button',
  16663. classes: ['tox-tbtn'],
  16664. attributes: tooltipAttributes
  16665. };
  16666. var icon = spec.icon.map(function (iconName) {
  16667. return renderIconFromPack(iconName, providersBackstage.icons);
  16668. });
  16669. var components = componentRenderPipeline([icon]);
  16670. return renderCommonSpec(spec, action, extraBehaviours, dom, components);
  16671. };
  16672. var renderIconButton = function (spec, action, providersBackstage, extraBehaviours) {
  16673. if (extraBehaviours === void 0) {
  16674. extraBehaviours = [];
  16675. }
  16676. var iconButtonSpec = renderIconButtonSpec(spec, Option.some(action), providersBackstage, extraBehaviours);
  16677. return Button.sketch(iconButtonSpec);
  16678. };
  16679. var renderButton = function (spec, action, providersBackstage, extraBehaviours) {
  16680. if (extraBehaviours === void 0) {
  16681. extraBehaviours = [];
  16682. }
  16683. var translatedText = providersBackstage.translate(spec.text);
  16684. var icon = spec.icon ? spec.icon.map(function (iconName) {
  16685. return renderIconFromPack(iconName, providersBackstage.icons);
  16686. }) : Option.none();
  16687. var components = icon.isSome() ? componentRenderPipeline([icon]) : [];
  16688. var innerHtml = icon.isSome() ? {} : { innerHtml: translatedText };
  16689. var classes = (spec.primary ? ['tox-button'] : [
  16690. 'tox-button',
  16691. 'tox-button--secondary'
  16692. ]).concat(icon.isSome() ? ['tox-button--icon'] : []);
  16693. var dom = __assign({
  16694. tag: 'button',
  16695. classes: classes
  16696. }, innerHtml, { attributes: { title: translatedText } });
  16697. return renderCommon(spec, action, extraBehaviours, dom, components);
  16698. };
  16699. var getAction = function (name, buttonType) {
  16700. return function (comp) {
  16701. if (buttonType === 'custom') {
  16702. emitWith(comp, formActionEvent, {
  16703. name: name,
  16704. value: {}
  16705. });
  16706. } else if (buttonType === 'submit') {
  16707. emit(comp, formSubmitEvent);
  16708. } else if (buttonType === 'cancel') {
  16709. emit(comp, formCancelEvent);
  16710. } else {
  16711. console.error('Unknown button type: ', buttonType);
  16712. }
  16713. };
  16714. };
  16715. var renderFooterButton = function (spec, buttonType, providersBackstage) {
  16716. var action = getAction(spec.name, buttonType);
  16717. return renderButton(spec, action, providersBackstage, []);
  16718. };
  16719. var renderDialogButton = function (spec, providersBackstage) {
  16720. var action = getAction(spec.name, 'custom');
  16721. return renderButton(spec, action, providersBackstage, [
  16722. RepresentingConfigs.memory(''),
  16723. ComposingConfigs.self()
  16724. ]);
  16725. };
  16726. var schema$i = constant([
  16727. defaulted$1('field1Name', 'field1'),
  16728. defaulted$1('field2Name', 'field2'),
  16729. onStrictHandler('onLockedChange'),
  16730. markers(['lockClass']),
  16731. defaulted$1('locked', false),
  16732. SketchBehaviours.field('coupledFieldBehaviours', [
  16733. Composing,
  16734. Representing
  16735. ])
  16736. ]);
  16737. var getField = function (comp, detail, partName) {
  16738. return getPart(comp, detail, partName).bind(Composing.getCurrent);
  16739. };
  16740. var coupledPart = function (selfName, otherName) {
  16741. return required({
  16742. factory: FormField,
  16743. name: selfName,
  16744. overrides: function (detail) {
  16745. return {
  16746. fieldBehaviours: derive$1([config('coupled-input-behaviour', [run(input(), function (me) {
  16747. getField(me, detail, otherName).each(function (other) {
  16748. getPart(me, detail, 'lock').each(function (lock) {
  16749. if (Toggling.isOn(lock)) {
  16750. detail.onLockedChange(me, other, lock);
  16751. }
  16752. });
  16753. });
  16754. })])])
  16755. };
  16756. }
  16757. });
  16758. };
  16759. var parts$6 = constant([
  16760. coupledPart('field1', 'field2'),
  16761. coupledPart('field2', 'field1'),
  16762. required({
  16763. factory: Button,
  16764. schema: [strict$1('dom')],
  16765. name: 'lock',
  16766. overrides: function (detail) {
  16767. return {
  16768. buttonBehaviours: derive$1([Toggling.config({
  16769. selected: detail.locked,
  16770. toggleClass: detail.markers.lockClass,
  16771. aria: { mode: 'pressed' }
  16772. })])
  16773. };
  16774. }
  16775. })
  16776. ]);
  16777. var factory$7 = function (detail, components, spec, externals) {
  16778. return {
  16779. uid: detail.uid,
  16780. dom: detail.dom,
  16781. components: components,
  16782. behaviours: SketchBehaviours.augment(detail.coupledFieldBehaviours, [
  16783. Composing.config({ find: Option.some }),
  16784. Representing.config({
  16785. store: {
  16786. mode: 'manual',
  16787. getValue: function (comp) {
  16788. var _a;
  16789. var parts = getPartsOrDie(comp, detail, [
  16790. 'field1',
  16791. 'field2'
  16792. ]);
  16793. return _a = {}, _a[detail.field1Name] = Representing.getValue(parts.field1()), _a[detail.field2Name] = Representing.getValue(parts.field2()), _a;
  16794. },
  16795. setValue: function (comp, value) {
  16796. var parts = getPartsOrDie(comp, detail, [
  16797. 'field1',
  16798. 'field2'
  16799. ]);
  16800. if (hasKey$1(value, detail.field1Name)) {
  16801. Representing.setValue(parts.field1(), value[detail.field1Name]);
  16802. }
  16803. if (hasKey$1(value, detail.field2Name)) {
  16804. Representing.setValue(parts.field2(), value[detail.field2Name]);
  16805. }
  16806. }
  16807. }
  16808. })
  16809. ]),
  16810. apis: {
  16811. getField1: function (component) {
  16812. return getPart(component, detail, 'field1');
  16813. },
  16814. getField2: function (component) {
  16815. return getPart(component, detail, 'field2');
  16816. },
  16817. getLock: function (component) {
  16818. return getPart(component, detail, 'lock');
  16819. }
  16820. }
  16821. };
  16822. };
  16823. var FormCoupledInputs = composite$1({
  16824. name: 'FormCoupledInputs',
  16825. configFields: schema$i(),
  16826. partFields: parts$6(),
  16827. factory: factory$7,
  16828. apis: {
  16829. getField1: function (apis, component) {
  16830. return apis.getField1(component);
  16831. },
  16832. getField2: function (apis, component) {
  16833. return apis.getField2(component);
  16834. },
  16835. getLock: function (apis, component) {
  16836. return apis.getLock(component);
  16837. }
  16838. }
  16839. });
  16840. var formatSize = function (size) {
  16841. var unitDec = {
  16842. '': 0,
  16843. 'px': 0,
  16844. 'pt': 1,
  16845. 'mm': 1,
  16846. 'pc': 2,
  16847. 'ex': 2,
  16848. 'em': 2,
  16849. 'ch': 2,
  16850. 'rem': 2,
  16851. 'cm': 3,
  16852. 'in': 4,
  16853. '%': 4
  16854. };
  16855. var maxDecimal = function (unit) {
  16856. return unit in unitDec ? unitDec[unit] : 1;
  16857. };
  16858. var numText = size.value.toFixed(maxDecimal(size.unit));
  16859. if (numText.indexOf('.') !== -1) {
  16860. numText = numText.replace(/\.?0*$/, '');
  16861. }
  16862. return numText + size.unit;
  16863. };
  16864. var parseSize = function (sizeText) {
  16865. var numPattern = /^\s*(\d+(?:\.\d+)?)\s*(|cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)\s*$/;
  16866. var match = numPattern.exec(sizeText);
  16867. if (match !== null) {
  16868. var value = parseFloat(match[1]);
  16869. var unit = match[2];
  16870. return Result.value({
  16871. value: value,
  16872. unit: unit
  16873. });
  16874. } else {
  16875. return Result.error(sizeText);
  16876. }
  16877. };
  16878. var convertUnit = function (size, unit) {
  16879. var inInch = {
  16880. '': 96,
  16881. 'px': 96,
  16882. 'pt': 72,
  16883. 'cm': 2.54,
  16884. 'pc': 12,
  16885. 'mm': 25.4,
  16886. 'in': 1
  16887. };
  16888. var supported = function (u) {
  16889. return Object.prototype.hasOwnProperty.call(inInch, u);
  16890. };
  16891. if (size.unit === unit) {
  16892. return Option.some(size.value);
  16893. } else if (supported(size.unit) && supported(unit)) {
  16894. if (inInch[size.unit] === inInch[unit]) {
  16895. return Option.some(size.value);
  16896. } else {
  16897. return Option.some(size.value / inInch[size.unit] * inInch[unit]);
  16898. }
  16899. } else {
  16900. return Option.none();
  16901. }
  16902. };
  16903. var noSizeConversion = function (input) {
  16904. return Option.none();
  16905. };
  16906. var ratioSizeConversion = function (scale, unit) {
  16907. return function (size) {
  16908. return convertUnit(size, unit).map(function (value) {
  16909. return {
  16910. value: value * scale,
  16911. unit: unit
  16912. };
  16913. });
  16914. };
  16915. };
  16916. var makeRatioConverter = function (currentFieldText, otherFieldText) {
  16917. var cValue = parseSize(currentFieldText).toOption();
  16918. var oValue = parseSize(otherFieldText).toOption();
  16919. return liftN([
  16920. cValue,
  16921. oValue
  16922. ], function (cSize, oSize) {
  16923. return convertUnit(cSize, oSize.unit).map(function (val) {
  16924. return oSize.value / val;
  16925. }).map(function (r) {
  16926. return ratioSizeConversion(r, oSize.unit);
  16927. }).getOr(noSizeConversion);
  16928. }).getOr(noSizeConversion);
  16929. };
  16930. var renderSizeInput = function (spec, providersBackstage) {
  16931. var converter = noSizeConversion;
  16932. var ratioEvent = generate$1('ratio-event');
  16933. var pLock = FormCoupledInputs.parts().lock({
  16934. dom: {
  16935. tag: 'button',
  16936. classes: [
  16937. 'tox-lock',
  16938. 'tox-button',
  16939. 'tox-button--naked',
  16940. 'tox-button--icon'
  16941. ],
  16942. attributes: { title: providersBackstage.translate(spec.label.getOr('Constrain proportions')) }
  16943. },
  16944. components: [
  16945. {
  16946. dom: {
  16947. tag: 'span',
  16948. classes: [
  16949. 'tox-icon',
  16950. 'tox-lock-icon__lock'
  16951. ],
  16952. innerHtml: get$c('lock', providersBackstage.icons)
  16953. }
  16954. },
  16955. {
  16956. dom: {
  16957. tag: 'span',
  16958. classes: [
  16959. 'tox-icon',
  16960. 'tox-lock-icon__unlock'
  16961. ],
  16962. innerHtml: get$c('unlock', providersBackstage.icons)
  16963. }
  16964. }
  16965. ],
  16966. buttonBehaviours: derive$1([Tabstopping.config({})])
  16967. });
  16968. var formGroup = function (components) {
  16969. return {
  16970. dom: {
  16971. tag: 'div',
  16972. classes: ['tox-form__group']
  16973. },
  16974. components: components
  16975. };
  16976. };
  16977. var getFieldPart = function (isField1) {
  16978. return FormField.parts().field({
  16979. factory: Input,
  16980. inputClasses: ['tox-textfield'],
  16981. inputBehaviours: derive$1([
  16982. Tabstopping.config({}),
  16983. config('size-input-events', [
  16984. run(focusin(), function (component, simulatedEvent) {
  16985. emitWith(component, ratioEvent, { isField1: isField1 });
  16986. }),
  16987. run(change(), function (component, simulatedEvent) {
  16988. emitWith(component, formChangeEvent, { name: spec.name });
  16989. })
  16990. ])
  16991. ]),
  16992. selectOnFocus: false
  16993. });
  16994. };
  16995. var getLabel = function (label) {
  16996. return {
  16997. dom: {
  16998. tag: 'label',
  16999. classes: ['tox-label'],
  17000. innerHtml: providersBackstage.translate(label)
  17001. }
  17002. };
  17003. };
  17004. var widthField = FormCoupledInputs.parts().field1(formGroup([
  17005. FormField.parts().label(getLabel('Width')),
  17006. getFieldPart(true)
  17007. ]));
  17008. var heightField = FormCoupledInputs.parts().field2(formGroup([
  17009. FormField.parts().label(getLabel('Height')),
  17010. getFieldPart(false)
  17011. ]));
  17012. return FormCoupledInputs.sketch({
  17013. dom: {
  17014. tag: 'div',
  17015. classes: ['tox-form__group']
  17016. },
  17017. components: [{
  17018. dom: {
  17019. tag: 'div',
  17020. classes: ['tox-form__controls-h-stack']
  17021. },
  17022. components: [
  17023. widthField,
  17024. heightField,
  17025. formGroup([
  17026. getLabel('&nbsp;'),
  17027. pLock
  17028. ])
  17029. ]
  17030. }],
  17031. field1Name: 'width',
  17032. field2Name: 'height',
  17033. locked: true,
  17034. markers: { lockClass: 'tox-locked' },
  17035. onLockedChange: function (current, other, lock) {
  17036. parseSize(Representing.getValue(current)).each(function (size) {
  17037. converter(size).each(function (newSize) {
  17038. Representing.setValue(other, formatSize(newSize));
  17039. });
  17040. });
  17041. },
  17042. coupledFieldBehaviours: derive$1([
  17043. Disabling.config({}),
  17044. config('size-input-events2', [run(ratioEvent, function (component, simulatedEvent) {
  17045. var isField1 = simulatedEvent.event().isField1();
  17046. var optCurrent = isField1 ? FormCoupledInputs.getField1(component) : FormCoupledInputs.getField2(component);
  17047. var optOther = isField1 ? FormCoupledInputs.getField2(component) : FormCoupledInputs.getField1(component);
  17048. var value1 = optCurrent.map(Representing.getValue).getOr('');
  17049. var value2 = optOther.map(Representing.getValue).getOr('');
  17050. converter = makeRatioConverter(value1, value2);
  17051. })])
  17052. ])
  17053. });
  17054. };
  17055. var undo = constant(generate$1('undo'));
  17056. var redo = constant(generate$1('redo'));
  17057. var zoom = constant(generate$1('zoom'));
  17058. var back = constant(generate$1('back'));
  17059. var apply = constant(generate$1('apply'));
  17060. var swap = constant(generate$1('swap'));
  17061. var transform = constant(generate$1('transform'));
  17062. var tempTransform = constant(generate$1('temp-transform'));
  17063. var transformApply = constant(generate$1('transform-apply'));
  17064. var internal = {
  17065. undo: undo,
  17066. redo: redo,
  17067. zoom: zoom,
  17068. back: back,
  17069. apply: apply,
  17070. swap: swap,
  17071. transform: transform,
  17072. tempTransform: tempTransform,
  17073. transformApply: transformApply
  17074. };
  17075. var saveState = constant('save-state');
  17076. var disable$1 = constant('disable');
  17077. var enable$1 = constant('enable');
  17078. var external$2 = {
  17079. formActionEvent: formActionEvent,
  17080. saveState: saveState,
  17081. disable: disable$1,
  17082. enable: enable$1
  17083. };
  17084. var renderEditPanel = function (imagePanel, providersBackstage) {
  17085. var createButton = function (text, action, disabled, primary) {
  17086. return record(renderButton({
  17087. name: text,
  17088. text: text,
  17089. disabled: disabled,
  17090. primary: primary
  17091. }, action, providersBackstage));
  17092. };
  17093. var createIconButton = function (icon, tooltip, action, disabled) {
  17094. return record(renderIconButton({
  17095. name: icon,
  17096. icon: Option.some(icon),
  17097. tooltip: Option.some(tooltip),
  17098. disabled: disabled
  17099. }, action, providersBackstage));
  17100. };
  17101. var disableAllComponents = function (comps, eventcomp) {
  17102. comps.map(function (mem) {
  17103. var component = mem.get(eventcomp);
  17104. if (component.hasConfigured(Disabling)) {
  17105. Disabling.disable(component);
  17106. }
  17107. });
  17108. };
  17109. var enableAllComponents = function (comps, eventcomp) {
  17110. comps.map(function (mem) {
  17111. var component = mem.get(eventcomp);
  17112. if (component.hasConfigured(Disabling)) {
  17113. Disabling.enable(component);
  17114. }
  17115. });
  17116. };
  17117. var panelDom = {
  17118. tag: 'div',
  17119. classes: [
  17120. 'tox-image-tools__toolbar',
  17121. 'tox-image-tools-edit-panel'
  17122. ]
  17123. };
  17124. var none = Option.none();
  17125. var noop$1 = noop;
  17126. var emit$1 = function (comp, event, data) {
  17127. emitWith(comp, event, data);
  17128. };
  17129. var emitDisable = function (component) {
  17130. return emit(component, external$2.disable());
  17131. };
  17132. var emitEnable = function (component) {
  17133. return emit(component, external$2.enable());
  17134. };
  17135. var emitTransform = function (comp, transform) {
  17136. emitDisable(comp);
  17137. emit$1(comp, internal.transform(), { transform: transform });
  17138. emitEnable(comp);
  17139. };
  17140. var emitTempTransform = function (comp, transform) {
  17141. emitDisable(comp);
  17142. emit$1(comp, internal.tempTransform(), { transform: transform });
  17143. emitEnable(comp);
  17144. };
  17145. var getBackSwap = function (anyInSystem) {
  17146. return function () {
  17147. memContainer.getOpt(anyInSystem).each(function (container) {
  17148. Replacing.set(container, [ButtonPanel]);
  17149. });
  17150. };
  17151. };
  17152. var emitTransformApply = function (comp, transform) {
  17153. emitDisable(comp);
  17154. emit$1(comp, internal.transformApply(), {
  17155. transform: transform,
  17156. swap: getBackSwap(comp)
  17157. });
  17158. emitEnable(comp);
  17159. };
  17160. var createBackButton = function () {
  17161. return createButton('Back', function (button) {
  17162. return emit$1(button, internal.back(), { swap: getBackSwap(button) });
  17163. }, false, false);
  17164. };
  17165. var createSpacer = function () {
  17166. return record({
  17167. dom: {
  17168. tag: 'div',
  17169. classes: ['tox-spacer']
  17170. },
  17171. behaviours: derive$1([Disabling.config({})])
  17172. });
  17173. };
  17174. var createApplyButton = function () {
  17175. return createButton('Apply', function (button) {
  17176. return emit$1(button, internal.apply(), { swap: getBackSwap(button) });
  17177. }, true, true);
  17178. };
  17179. var makeCropTransform = function () {
  17180. return function (ir) {
  17181. var rect = imagePanel.getRect();
  17182. return ImageTransformations.crop(ir, rect.x, rect.y, rect.w, rect.h);
  17183. };
  17184. };
  17185. var cropPanelComponents = [
  17186. createBackButton(),
  17187. createSpacer(),
  17188. createButton('Apply', function (button) {
  17189. var transform = makeCropTransform();
  17190. emitTransformApply(button, transform);
  17191. imagePanel.hideCrop();
  17192. }, false, true)
  17193. ];
  17194. var CropPanel = Container.sketch({
  17195. dom: panelDom,
  17196. components: cropPanelComponents.map(function (mem) {
  17197. return mem.asSpec();
  17198. }),
  17199. containerBehaviours: derive$1([config('image-tools-crop-buttons-events', [
  17200. run(external$2.disable(), function (comp, se) {
  17201. disableAllComponents(cropPanelComponents, comp);
  17202. }),
  17203. run(external$2.enable(), function (comp, se) {
  17204. enableAllComponents(cropPanelComponents, comp);
  17205. })
  17206. ])])
  17207. });
  17208. var memSize = record(renderSizeInput({
  17209. name: 'size',
  17210. label: none,
  17211. type: 'sizeinput',
  17212. constrain: true
  17213. }, providersBackstage));
  17214. var makeResizeTransform = function (width, height) {
  17215. return function (ir) {
  17216. return ImageTransformations.resize(ir, width, height);
  17217. };
  17218. };
  17219. var resizePanelComponents = [
  17220. createBackButton(),
  17221. createSpacer(),
  17222. memSize,
  17223. createSpacer(),
  17224. createButton('Apply', function (button) {
  17225. memSize.getOpt(button).each(function (sizeInput) {
  17226. var value = Representing.getValue(sizeInput);
  17227. var width = parseInt(value.width, 10);
  17228. var height = parseInt(value.height, 10);
  17229. var transform = makeResizeTransform(width, height);
  17230. emitTransformApply(button, transform);
  17231. });
  17232. }, false, true)
  17233. ];
  17234. var ResizePanel = Container.sketch({
  17235. dom: panelDom,
  17236. components: resizePanelComponents.map(function (mem) {
  17237. return mem.asSpec();
  17238. }),
  17239. containerBehaviours: derive$1([config('image-tools-resize-buttons-events', [
  17240. run(external$2.disable(), function (comp, se) {
  17241. disableAllComponents(resizePanelComponents, comp);
  17242. }),
  17243. run(external$2.enable(), function (comp, se) {
  17244. enableAllComponents(resizePanelComponents, comp);
  17245. })
  17246. ])])
  17247. });
  17248. var makeValueTransform = function (transform, value) {
  17249. return function (ir) {
  17250. return transform(ir, value);
  17251. };
  17252. };
  17253. var horizontalFlip = makeValueTransform(ImageTransformations.flip, 'h');
  17254. var verticalFlip = makeValueTransform(ImageTransformations.flip, 'v');
  17255. var counterclockwiseRotate = makeValueTransform(ImageTransformations.rotate, -90);
  17256. var clockwiseRotate = makeValueTransform(ImageTransformations.rotate, 90);
  17257. var flipRotateOnAction = function (comp, operation) {
  17258. emitTempTransform(comp, operation);
  17259. };
  17260. var flipRotateComponents = [
  17261. createBackButton(),
  17262. createSpacer(),
  17263. createIconButton('flip-horizontally', 'Flip horizontally', function (button) {
  17264. flipRotateOnAction(button, horizontalFlip);
  17265. }, false),
  17266. createIconButton('flip-vertically', 'Flip vertically', function (button) {
  17267. flipRotateOnAction(button, verticalFlip);
  17268. }, false),
  17269. createIconButton('rotate-left', 'Rotate counterclockwise', function (button) {
  17270. flipRotateOnAction(button, counterclockwiseRotate);
  17271. }, false),
  17272. createIconButton('rotate-right', 'Rotate clockwise', function (button) {
  17273. flipRotateOnAction(button, clockwiseRotate);
  17274. }, false),
  17275. createSpacer(),
  17276. createApplyButton()
  17277. ];
  17278. var FlipRotatePanel = Container.sketch({
  17279. dom: panelDom,
  17280. components: flipRotateComponents.map(function (mem) {
  17281. return mem.asSpec();
  17282. }),
  17283. containerBehaviours: derive$1([config('image-tools-fliprotate-buttons-events', [
  17284. run(external$2.disable(), function (comp, se) {
  17285. disableAllComponents(flipRotateComponents, comp);
  17286. }),
  17287. run(external$2.enable(), function (comp, se) {
  17288. enableAllComponents(flipRotateComponents, comp);
  17289. })
  17290. ])])
  17291. });
  17292. var makeSlider = function (label, onChoose, min, value, max) {
  17293. var labelPart = Slider.parts().label({
  17294. dom: {
  17295. tag: 'label',
  17296. classes: ['tox-label'],
  17297. innerHtml: providersBackstage.translate(label)
  17298. }
  17299. });
  17300. var spectrum = Slider.parts().spectrum({
  17301. dom: {
  17302. tag: 'div',
  17303. classes: ['tox-slider__rail'],
  17304. attributes: { role: 'presentation' }
  17305. }
  17306. });
  17307. var thumb = Slider.parts().thumb({
  17308. dom: {
  17309. tag: 'div',
  17310. classes: ['tox-slider__handle'],
  17311. attributes: { role: 'presentation' }
  17312. }
  17313. });
  17314. return record(Slider.sketch({
  17315. dom: {
  17316. tag: 'div',
  17317. classes: ['tox-slider'],
  17318. attributes: { role: 'presentation' }
  17319. },
  17320. model: {
  17321. mode: 'x',
  17322. minX: min,
  17323. maxX: max,
  17324. getInitialValue: constant({ x: constant(value) })
  17325. },
  17326. components: [
  17327. labelPart,
  17328. spectrum,
  17329. thumb
  17330. ],
  17331. sliderBehaviours: derive$1([Focusing.config({})]),
  17332. onChoose: onChoose
  17333. }));
  17334. };
  17335. var makeVariableSlider = function (label, transform, min, value, max) {
  17336. var onChoose = function (slider, thumb, value) {
  17337. var valTransform = makeValueTransform(transform, value.x() / 100);
  17338. emitTransform(slider, valTransform);
  17339. };
  17340. return makeSlider(label, onChoose, min, value, max);
  17341. };
  17342. var variableFilterPanelComponents = function (label, transform, min, value, max) {
  17343. return [
  17344. createBackButton(),
  17345. makeVariableSlider(label, transform, min, value, max),
  17346. createApplyButton()
  17347. ];
  17348. };
  17349. var createVariableFilterPanel = function (label, transform, min, value, max) {
  17350. var filterPanelComponents = variableFilterPanelComponents(label, transform, min, value, max);
  17351. return Container.sketch({
  17352. dom: panelDom,
  17353. components: filterPanelComponents.map(function (mem) {
  17354. return mem.asSpec();
  17355. }),
  17356. containerBehaviours: derive$1([config('image-tools-filter-panel-buttons-events', [
  17357. run(external$2.disable(), function (comp, se) {
  17358. disableAllComponents(filterPanelComponents, comp);
  17359. }),
  17360. run(external$2.enable(), function (comp, se) {
  17361. enableAllComponents(filterPanelComponents, comp);
  17362. })
  17363. ])])
  17364. });
  17365. };
  17366. var filterPanelComponents = [
  17367. createBackButton(),
  17368. createSpacer(),
  17369. createApplyButton()
  17370. ];
  17371. var FilterPanel = Container.sketch({
  17372. dom: panelDom,
  17373. components: filterPanelComponents.map(function (mem) {
  17374. return mem.asSpec();
  17375. })
  17376. });
  17377. var BrightnessPanel = createVariableFilterPanel('Brightness', ImageTransformations.brightness, -100, 0, 100);
  17378. var ContrastPanel = createVariableFilterPanel('Contrast', ImageTransformations.contrast, -100, 0, 100);
  17379. var GammaPanel = createVariableFilterPanel('Gamma', ImageTransformations.gamma, -100, 0, 100);
  17380. var makeColorTransform = function (red, green, blue) {
  17381. return function (ir) {
  17382. return ImageTransformations.colorize(ir, red, green, blue);
  17383. };
  17384. };
  17385. var makeColorSlider = function (label) {
  17386. var onChoose = function (slider, thumb, value) {
  17387. var redOpt = memRed.getOpt(slider);
  17388. var blueOpt = memBlue.getOpt(slider);
  17389. var greenOpt = memGreen.getOpt(slider);
  17390. redOpt.each(function (red) {
  17391. blueOpt.each(function (blue) {
  17392. greenOpt.each(function (green) {
  17393. var r = Representing.getValue(red).x() / 100;
  17394. var g = Representing.getValue(green).x() / 100;
  17395. var b = Representing.getValue(blue).x() / 100;
  17396. var transform = makeColorTransform(r, g, b);
  17397. emitTransform(slider, transform);
  17398. });
  17399. });
  17400. });
  17401. };
  17402. return makeSlider(label, onChoose, 0, 100, 200);
  17403. };
  17404. var memRed = makeColorSlider('R');
  17405. var memGreen = makeColorSlider('G');
  17406. var memBlue = makeColorSlider('B');
  17407. var colorizePanelComponents = [
  17408. createBackButton(),
  17409. memRed,
  17410. memGreen,
  17411. memBlue,
  17412. createApplyButton()
  17413. ];
  17414. var ColorizePanel = Container.sketch({
  17415. dom: panelDom,
  17416. components: colorizePanelComponents.map(function (mem) {
  17417. return mem.asSpec();
  17418. })
  17419. });
  17420. var getTransformPanelEvent = function (panel, transform, update) {
  17421. return function (button) {
  17422. var swap = function () {
  17423. memContainer.getOpt(button).each(function (container) {
  17424. Replacing.set(container, [panel]);
  17425. update(container);
  17426. });
  17427. };
  17428. emit$1(button, internal.swap(), {
  17429. transform: transform,
  17430. swap: swap
  17431. });
  17432. };
  17433. };
  17434. var cropPanelUpdate = function (_anyInSystem) {
  17435. imagePanel.showCrop();
  17436. };
  17437. var resizePanelUpdate = function (anyInSystem) {
  17438. memSize.getOpt(anyInSystem).each(function (sizeInput) {
  17439. var measurements = imagePanel.getMeasurements();
  17440. var width = measurements.width;
  17441. var height = measurements.height;
  17442. Representing.setValue(sizeInput, {
  17443. width: width,
  17444. height: height
  17445. });
  17446. });
  17447. };
  17448. var sharpenTransform = Option.some(ImageTransformations.sharpen);
  17449. var invertTransform = Option.some(ImageTransformations.invert);
  17450. var buttonPanelComponents = [
  17451. createIconButton('crop', 'Crop', getTransformPanelEvent(CropPanel, none, cropPanelUpdate), false),
  17452. createIconButton('resize', 'Resize', getTransformPanelEvent(ResizePanel, none, resizePanelUpdate), false),
  17453. createIconButton('orientation', 'Orientation', getTransformPanelEvent(FlipRotatePanel, none, noop$1), false),
  17454. createIconButton('brightness', 'Brightness', getTransformPanelEvent(BrightnessPanel, none, noop$1), false),
  17455. createIconButton('sharpen', 'Sharpen', getTransformPanelEvent(FilterPanel, sharpenTransform, noop$1), false),
  17456. createIconButton('contrast', 'Contrast', getTransformPanelEvent(ContrastPanel, none, noop$1), false),
  17457. createIconButton('color-levels', 'Color levels', getTransformPanelEvent(ColorizePanel, none, noop$1), false),
  17458. createIconButton('gamma', 'Gamma', getTransformPanelEvent(GammaPanel, none, noop$1), false),
  17459. createIconButton('invert', 'Invert', getTransformPanelEvent(FilterPanel, invertTransform, noop$1), false)
  17460. ];
  17461. var ButtonPanel = Container.sketch({
  17462. dom: panelDom,
  17463. components: buttonPanelComponents.map(function (mem) {
  17464. return mem.asSpec();
  17465. })
  17466. });
  17467. var container = Container.sketch({
  17468. dom: { tag: 'div' },
  17469. components: [ButtonPanel],
  17470. containerBehaviours: derive$1([Replacing.config({})])
  17471. });
  17472. var memContainer = record(container);
  17473. var getApplyButton = function (anyInSystem) {
  17474. return memContainer.getOpt(anyInSystem).map(function (container) {
  17475. var panel = container.components()[0];
  17476. return panel.components()[panel.components().length - 1];
  17477. });
  17478. };
  17479. return {
  17480. memContainer: memContainer,
  17481. getApplyButton: getApplyButton
  17482. };
  17483. };
  17484. var global$7 = tinymce.util.Tools.resolve('tinymce.dom.DomQuery');
  17485. var global$8 = tinymce.util.Tools.resolve('tinymce.geom.Rect');
  17486. var global$9 = tinymce.util.Tools.resolve('tinymce.util.Observable');
  17487. var global$a = tinymce.util.Tools.resolve('tinymce.util.Tools');
  17488. var global$b = tinymce.util.Tools.resolve('tinymce.util.VK');
  17489. function getDocumentSize(doc) {
  17490. var documentElement, body, scrollWidth, clientWidth;
  17491. var offsetWidth, scrollHeight, clientHeight, offsetHeight;
  17492. var max = Math.max;
  17493. documentElement = doc.documentElement;
  17494. body = doc.body;
  17495. scrollWidth = max(documentElement.scrollWidth, body.scrollWidth);
  17496. clientWidth = max(documentElement.clientWidth, body.clientWidth);
  17497. offsetWidth = max(documentElement.offsetWidth, body.offsetWidth);
  17498. scrollHeight = max(documentElement.scrollHeight, body.scrollHeight);
  17499. clientHeight = max(documentElement.clientHeight, body.clientHeight);
  17500. offsetHeight = max(documentElement.offsetHeight, body.offsetHeight);
  17501. return {
  17502. width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
  17503. height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
  17504. };
  17505. }
  17506. function updateWithTouchData(e) {
  17507. var keys, i;
  17508. if (e.changedTouches) {
  17509. keys = 'screenX screenY pageX pageY clientX clientY'.split(' ');
  17510. for (i = 0; i < keys.length; i++) {
  17511. e[keys[i]] = e.changedTouches[0][keys[i]];
  17512. }
  17513. }
  17514. }
  17515. function DragHelper (id, settings) {
  17516. var $eventOverlay;
  17517. var doc = settings.document || domGlobals.document;
  17518. var downButton;
  17519. var start, stop, drag, startX, startY;
  17520. settings = settings || {};
  17521. var handleElement = doc.getElementById(settings.handle || id);
  17522. start = function (e) {
  17523. var docSize = getDocumentSize(doc);
  17524. var handleElm, cursor;
  17525. updateWithTouchData(e);
  17526. e.preventDefault();
  17527. downButton = e.button;
  17528. handleElm = handleElement;
  17529. startX = e.screenX;
  17530. startY = e.screenY;
  17531. if (domGlobals.window.getComputedStyle) {
  17532. cursor = domGlobals.window.getComputedStyle(handleElm, null).getPropertyValue('cursor');
  17533. } else {
  17534. cursor = handleElm.runtimeStyle.cursor;
  17535. }
  17536. $eventOverlay = global$7('<div></div>').css({
  17537. position: 'absolute',
  17538. top: 0,
  17539. left: 0,
  17540. width: docSize.width,
  17541. height: docSize.height,
  17542. zIndex: 2147483647,
  17543. opacity: 0.0001,
  17544. cursor: cursor
  17545. }).appendTo(doc.body);
  17546. global$7(doc).on('mousemove touchmove', drag).on('mouseup touchend', stop);
  17547. settings.start(e);
  17548. };
  17549. drag = function (e) {
  17550. updateWithTouchData(e);
  17551. if (e.button !== downButton) {
  17552. return stop(e);
  17553. }
  17554. e.deltaX = e.screenX - startX;
  17555. e.deltaY = e.screenY - startY;
  17556. e.preventDefault();
  17557. settings.drag(e);
  17558. };
  17559. stop = function (e) {
  17560. updateWithTouchData(e);
  17561. global$7(doc).off('mousemove touchmove', drag).off('mouseup touchend', stop);
  17562. $eventOverlay.remove();
  17563. if (settings.stop) {
  17564. settings.stop(e);
  17565. }
  17566. };
  17567. this.destroy = function () {
  17568. global$7(handleElement).off();
  17569. };
  17570. global$7(handleElement).on('mousedown touchstart', start);
  17571. }
  17572. var count = 0;
  17573. function CropRect (currentRect, viewPortRect, clampRect, containerElm, action) {
  17574. var instance;
  17575. var handles;
  17576. var dragHelpers;
  17577. var blockers;
  17578. var prefix = 'tox-';
  17579. var id = prefix + 'crid-' + count++;
  17580. handles = [
  17581. {
  17582. name: 'move',
  17583. xMul: 0,
  17584. yMul: 0,
  17585. deltaX: 1,
  17586. deltaY: 1,
  17587. deltaW: 0,
  17588. deltaH: 0,
  17589. label: 'Crop Mask'
  17590. },
  17591. {
  17592. name: 'nw',
  17593. xMul: 0,
  17594. yMul: 0,
  17595. deltaX: 1,
  17596. deltaY: 1,
  17597. deltaW: -1,
  17598. deltaH: -1,
  17599. label: 'Top Left Crop Handle'
  17600. },
  17601. {
  17602. name: 'ne',
  17603. xMul: 1,
  17604. yMul: 0,
  17605. deltaX: 0,
  17606. deltaY: 1,
  17607. deltaW: 1,
  17608. deltaH: -1,
  17609. label: 'Top Right Crop Handle'
  17610. },
  17611. {
  17612. name: 'sw',
  17613. xMul: 0,
  17614. yMul: 1,
  17615. deltaX: 1,
  17616. deltaY: 0,
  17617. deltaW: -1,
  17618. deltaH: 1,
  17619. label: 'Bottom Left Crop Handle'
  17620. },
  17621. {
  17622. name: 'se',
  17623. xMul: 1,
  17624. yMul: 1,
  17625. deltaX: 0,
  17626. deltaY: 0,
  17627. deltaW: 1,
  17628. deltaH: 1,
  17629. label: 'Bottom Right Crop Handle'
  17630. }
  17631. ];
  17632. blockers = [
  17633. 'top',
  17634. 'right',
  17635. 'bottom',
  17636. 'left'
  17637. ];
  17638. function getAbsoluteRect(outerRect, relativeRect) {
  17639. return {
  17640. x: relativeRect.x + outerRect.x,
  17641. y: relativeRect.y + outerRect.y,
  17642. w: relativeRect.w,
  17643. h: relativeRect.h
  17644. };
  17645. }
  17646. function getRelativeRect(outerRect, innerRect) {
  17647. return {
  17648. x: innerRect.x - outerRect.x,
  17649. y: innerRect.y - outerRect.y,
  17650. w: innerRect.w,
  17651. h: innerRect.h
  17652. };
  17653. }
  17654. function getInnerRect() {
  17655. return getRelativeRect(clampRect, currentRect);
  17656. }
  17657. function moveRect(handle, startRect, deltaX, deltaY) {
  17658. var x, y, w, h, rect;
  17659. x = startRect.x;
  17660. y = startRect.y;
  17661. w = startRect.w;
  17662. h = startRect.h;
  17663. x += deltaX * handle.deltaX;
  17664. y += deltaY * handle.deltaY;
  17665. w += deltaX * handle.deltaW;
  17666. h += deltaY * handle.deltaH;
  17667. if (w < 20) {
  17668. w = 20;
  17669. }
  17670. if (h < 20) {
  17671. h = 20;
  17672. }
  17673. rect = currentRect = global$8.clamp({
  17674. x: x,
  17675. y: y,
  17676. w: w,
  17677. h: h
  17678. }, clampRect, handle.name === 'move');
  17679. rect = getRelativeRect(clampRect, rect);
  17680. instance.fire('updateRect', { rect: rect });
  17681. setInnerRect(rect);
  17682. }
  17683. function render() {
  17684. function createDragHelper(handle) {
  17685. var startRect;
  17686. return new DragHelper(id, {
  17687. document: containerElm.ownerDocument,
  17688. handle: id + '-' + handle.name,
  17689. start: function () {
  17690. startRect = currentRect;
  17691. },
  17692. drag: function (e) {
  17693. moveRect(handle, startRect, e.deltaX, e.deltaY);
  17694. }
  17695. });
  17696. }
  17697. global$7('<div id="' + id + '" class="' + prefix + 'croprect-container"' + ' role="grid" aria-dropeffect="execute">').appendTo(containerElm);
  17698. global$a.each(blockers, function (blocker) {
  17699. global$7('#' + id, containerElm).append('<div id="' + id + '-' + blocker + '"class="' + prefix + 'croprect-block" style="display: none" data-mce-bogus="all">');
  17700. });
  17701. global$a.each(handles, function (handle) {
  17702. global$7('#' + id, containerElm).append('<div id="' + id + '-' + handle.name + '" class="' + prefix + 'croprect-handle ' + prefix + 'croprect-handle-' + handle.name + '"' + 'style="display: none" data-mce-bogus="all" role="gridcell" tabindex="-1"' + ' aria-label="' + handle.label + '" aria-grabbed="false" title="' + handle.label + '">');
  17703. });
  17704. dragHelpers = global$a.map(handles, createDragHelper);
  17705. repaint(currentRect);
  17706. global$7(containerElm).on('focusin focusout', function (e) {
  17707. global$7(e.target).attr('aria-grabbed', e.type === 'focus');
  17708. });
  17709. global$7(containerElm).on('keydown', function (e) {
  17710. var activeHandle;
  17711. global$a.each(handles, function (handle) {
  17712. if (e.target.id === id + '-' + handle.name) {
  17713. activeHandle = handle;
  17714. return false;
  17715. }
  17716. });
  17717. function moveAndBlock(evt, handle, startRect, deltaX, deltaY) {
  17718. evt.stopPropagation();
  17719. evt.preventDefault();
  17720. moveRect(activeHandle, startRect, deltaX, deltaY);
  17721. }
  17722. switch (e.keyCode) {
  17723. case global$b.LEFT:
  17724. moveAndBlock(e, activeHandle, currentRect, -10, 0);
  17725. break;
  17726. case global$b.RIGHT:
  17727. moveAndBlock(e, activeHandle, currentRect, 10, 0);
  17728. break;
  17729. case global$b.UP:
  17730. moveAndBlock(e, activeHandle, currentRect, 0, -10);
  17731. break;
  17732. case global$b.DOWN:
  17733. moveAndBlock(e, activeHandle, currentRect, 0, 10);
  17734. break;
  17735. case global$b.ENTER:
  17736. case global$b.SPACEBAR:
  17737. e.preventDefault();
  17738. action();
  17739. break;
  17740. }
  17741. });
  17742. }
  17743. function toggleVisibility(state) {
  17744. var selectors;
  17745. selectors = global$a.map(handles, function (handle) {
  17746. return '#' + id + '-' + handle.name;
  17747. }).concat(global$a.map(blockers, function (blocker) {
  17748. return '#' + id + '-' + blocker;
  17749. })).join(',');
  17750. if (state) {
  17751. global$7(selectors, containerElm).show();
  17752. } else {
  17753. global$7(selectors, containerElm).hide();
  17754. }
  17755. }
  17756. function repaint(rect) {
  17757. function updateElementRect(name, rect) {
  17758. if (rect.h < 0) {
  17759. rect.h = 0;
  17760. }
  17761. if (rect.w < 0) {
  17762. rect.w = 0;
  17763. }
  17764. global$7('#' + id + '-' + name, containerElm).css({
  17765. left: rect.x,
  17766. top: rect.y,
  17767. width: rect.w,
  17768. height: rect.h
  17769. });
  17770. }
  17771. global$a.each(handles, function (handle) {
  17772. global$7('#' + id + '-' + handle.name, containerElm).css({
  17773. left: rect.w * handle.xMul + rect.x,
  17774. top: rect.h * handle.yMul + rect.y
  17775. });
  17776. });
  17777. updateElementRect('top', {
  17778. x: viewPortRect.x,
  17779. y: viewPortRect.y,
  17780. w: viewPortRect.w,
  17781. h: rect.y - viewPortRect.y
  17782. });
  17783. updateElementRect('right', {
  17784. x: rect.x + rect.w,
  17785. y: rect.y,
  17786. w: viewPortRect.w - rect.x - rect.w + viewPortRect.x,
  17787. h: rect.h
  17788. });
  17789. updateElementRect('bottom', {
  17790. x: viewPortRect.x,
  17791. y: rect.y + rect.h,
  17792. w: viewPortRect.w,
  17793. h: viewPortRect.h - rect.y - rect.h + viewPortRect.y
  17794. });
  17795. updateElementRect('left', {
  17796. x: viewPortRect.x,
  17797. y: rect.y,
  17798. w: rect.x - viewPortRect.x,
  17799. h: rect.h
  17800. });
  17801. updateElementRect('move', rect);
  17802. }
  17803. function setRect(rect) {
  17804. currentRect = rect;
  17805. repaint(currentRect);
  17806. }
  17807. function setViewPortRect(rect) {
  17808. viewPortRect = rect;
  17809. repaint(currentRect);
  17810. }
  17811. function setInnerRect(rect) {
  17812. setRect(getAbsoluteRect(clampRect, rect));
  17813. }
  17814. function setClampRect(rect) {
  17815. clampRect = rect;
  17816. repaint(currentRect);
  17817. }
  17818. function destroy() {
  17819. global$a.each(dragHelpers, function (helper) {
  17820. helper.destroy();
  17821. });
  17822. dragHelpers = [];
  17823. }
  17824. render();
  17825. instance = global$a.extend({
  17826. toggleVisibility: toggleVisibility,
  17827. setClampRect: setClampRect,
  17828. setRect: setRect,
  17829. getInnerRect: getInnerRect,
  17830. setInnerRect: setInnerRect,
  17831. setViewPortRect: setViewPortRect,
  17832. destroy: destroy
  17833. }, global$9);
  17834. return instance;
  17835. }
  17836. var loadImage = function (image) {
  17837. return new global$1(function (resolve) {
  17838. var loaded = function () {
  17839. image.removeEventListener('load', loaded);
  17840. resolve(image);
  17841. };
  17842. if (image.complete) {
  17843. resolve(image);
  17844. } else {
  17845. image.addEventListener('load', loaded);
  17846. }
  17847. });
  17848. };
  17849. var renderImagePanel = function (initialUrl) {
  17850. var memBg = record({
  17851. dom: {
  17852. tag: 'div',
  17853. classes: ['tox-image-tools__image-bg'],
  17854. attributes: { role: 'presentation' }
  17855. }
  17856. });
  17857. var zoomState = Cell(1);
  17858. var cropRect = Cell(Option.none());
  17859. var rectState = Cell({
  17860. x: 0,
  17861. y: 0,
  17862. w: 1,
  17863. h: 1
  17864. });
  17865. var viewRectState = Cell({
  17866. x: 0,
  17867. y: 0,
  17868. w: 1,
  17869. h: 1
  17870. });
  17871. var repaintImg = function (anyInSystem, img) {
  17872. memContainer.getOpt(anyInSystem).each(function (panel) {
  17873. var zoom = zoomState.get();
  17874. var panelW = get$7(panel.element());
  17875. var panelH = get$8(panel.element());
  17876. var width = img.dom().naturalWidth * zoom;
  17877. var height = img.dom().naturalHeight * zoom;
  17878. var left = Math.max(0, panelW / 2 - width / 2);
  17879. var top = Math.max(0, panelH / 2 - height / 2);
  17880. var css = {
  17881. left: left.toString() + 'px',
  17882. top: top.toString() + 'px',
  17883. width: width.toString() + 'px',
  17884. height: height.toString() + 'px',
  17885. position: 'absolute'
  17886. };
  17887. setAll$1(img, css);
  17888. memBg.getOpt(panel).each(function (bg) {
  17889. setAll$1(bg.element(), css);
  17890. });
  17891. cropRect.get().each(function (cRect) {
  17892. var rect = rectState.get();
  17893. cRect.setRect({
  17894. x: rect.x * zoom + left,
  17895. y: rect.y * zoom + top,
  17896. w: rect.w * zoom,
  17897. h: rect.h * zoom
  17898. });
  17899. cRect.setClampRect({
  17900. x: left,
  17901. y: top,
  17902. w: width,
  17903. h: height
  17904. });
  17905. cRect.setViewPortRect({
  17906. x: 0,
  17907. y: 0,
  17908. w: panelW,
  17909. h: panelH
  17910. });
  17911. });
  17912. });
  17913. };
  17914. var zoomFit = function (anyInSystem, img) {
  17915. memContainer.getOpt(anyInSystem).each(function (panel) {
  17916. var panelW = get$7(panel.element());
  17917. var panelH = get$8(panel.element());
  17918. var width = img.dom().naturalWidth;
  17919. var height = img.dom().naturalHeight;
  17920. var zoom = Math.min(panelW / width, panelH / height);
  17921. if (zoom >= 1) {
  17922. zoomState.set(1);
  17923. } else {
  17924. zoomState.set(zoom);
  17925. }
  17926. });
  17927. };
  17928. var updateSrc = function (anyInSystem, url) {
  17929. var img = Element.fromTag('img');
  17930. set$1(img, 'src', url);
  17931. return loadImage(img.dom()).then(function () {
  17932. return memContainer.getOpt(anyInSystem).map(function (panel) {
  17933. var aImg = external({ element: img });
  17934. Replacing.replaceAt(panel, 1, Option.some(aImg));
  17935. var lastViewRect = viewRectState.get();
  17936. var viewRect = {
  17937. x: 0,
  17938. y: 0,
  17939. w: img.dom().naturalWidth,
  17940. h: img.dom().naturalHeight
  17941. };
  17942. viewRectState.set(viewRect);
  17943. var rect = global$8.inflate(viewRect, -20, -20);
  17944. rectState.set(rect);
  17945. if (lastViewRect.w !== viewRect.w || lastViewRect.h !== viewRect.h) {
  17946. zoomFit(panel, img);
  17947. }
  17948. repaintImg(panel, img);
  17949. return img;
  17950. });
  17951. });
  17952. };
  17953. var zoom = function (anyInSystem, direction) {
  17954. var currentZoom = zoomState.get();
  17955. var newZoom = direction > 0 ? Math.min(2, currentZoom + 0.1) : Math.max(0.1, currentZoom - 0.1);
  17956. zoomState.set(newZoom);
  17957. memContainer.getOpt(anyInSystem).each(function (panel) {
  17958. var img = panel.components()[1].element();
  17959. repaintImg(panel, img);
  17960. });
  17961. };
  17962. var showCrop = function () {
  17963. cropRect.get().each(function (cRect) {
  17964. cRect.toggleVisibility(true);
  17965. });
  17966. };
  17967. var hideCrop = function () {
  17968. cropRect.get().each(function (cRect) {
  17969. cRect.toggleVisibility(false);
  17970. });
  17971. };
  17972. var getRect = function () {
  17973. return rectState.get();
  17974. };
  17975. var container = Container.sketch({
  17976. dom: {
  17977. tag: 'div',
  17978. classes: ['tox-image-tools__image']
  17979. },
  17980. components: [
  17981. memBg.asSpec(),
  17982. {
  17983. dom: {
  17984. tag: 'img',
  17985. attributes: { src: initialUrl }
  17986. }
  17987. },
  17988. {
  17989. dom: { tag: 'div' },
  17990. behaviours: derive$1([config('image-panel-crop-events', [runOnAttached(function (comp) {
  17991. memContainer.getOpt(comp).each(function (container) {
  17992. var el = container.element().dom();
  17993. var cRect = CropRect({
  17994. x: 10,
  17995. y: 10,
  17996. w: 100,
  17997. h: 100
  17998. }, {
  17999. x: 0,
  18000. y: 0,
  18001. w: 200,
  18002. h: 200
  18003. }, {
  18004. x: 0,
  18005. y: 0,
  18006. w: 200,
  18007. h: 200
  18008. }, el, function () {
  18009. });
  18010. cRect.toggleVisibility(false);
  18011. cRect.on('updateRect', function (e) {
  18012. var rect = e.rect;
  18013. var zoom = zoomState.get();
  18014. var newRect = {
  18015. x: Math.round(rect.x / zoom),
  18016. y: Math.round(rect.y / zoom),
  18017. w: Math.round(rect.w / zoom),
  18018. h: Math.round(rect.h / zoom)
  18019. };
  18020. rectState.set(newRect);
  18021. });
  18022. cropRect.set(Option.some(cRect));
  18023. });
  18024. })])])
  18025. }
  18026. ],
  18027. containerBehaviours: derive$1([
  18028. Replacing.config({}),
  18029. config('image-panel-events', [runOnAttached(function (comp) {
  18030. updateSrc(comp, initialUrl);
  18031. })])
  18032. ])
  18033. });
  18034. var memContainer = record(container);
  18035. var getMeasurements = function () {
  18036. var viewRect = viewRectState.get();
  18037. return {
  18038. width: viewRect.w,
  18039. height: viewRect.h
  18040. };
  18041. };
  18042. return {
  18043. memContainer: memContainer,
  18044. updateSrc: updateSrc,
  18045. zoom: zoom,
  18046. showCrop: showCrop,
  18047. hideCrop: hideCrop,
  18048. getRect: getRect,
  18049. getMeasurements: getMeasurements
  18050. };
  18051. };
  18052. var createButton = function (innerHtml, icon, disabled, action, providersBackstage) {
  18053. return renderIconButton({
  18054. name: innerHtml,
  18055. icon: Option.some(icon),
  18056. disabled: disabled,
  18057. tooltip: Option.some(innerHtml)
  18058. }, action, providersBackstage);
  18059. };
  18060. var setButtonEnabled = function (button, enabled) {
  18061. if (enabled) {
  18062. Disabling.enable(button);
  18063. } else {
  18064. Disabling.disable(button);
  18065. }
  18066. };
  18067. var renderSideBar = function (providersBackstage) {
  18068. var updateButtonUndoStates = function (anyInSystem, undoEnabled, redoEnabled) {
  18069. memUndo.getOpt(anyInSystem).each(function (undo) {
  18070. setButtonEnabled(undo, undoEnabled);
  18071. });
  18072. memRedo.getOpt(anyInSystem).each(function (redo) {
  18073. setButtonEnabled(redo, redoEnabled);
  18074. });
  18075. };
  18076. var memUndo = record(createButton('Undo', 'undo', true, function (button) {
  18077. emitWith(button, internal.undo(), { direction: 1 });
  18078. }, providersBackstage));
  18079. var memRedo = record(createButton('Redo', 'redo', true, function (button) {
  18080. emitWith(button, internal.redo(), { direction: 1 });
  18081. }, providersBackstage));
  18082. var container = Container.sketch({
  18083. dom: {
  18084. tag: 'div',
  18085. classes: [
  18086. 'tox-image-tools__toolbar',
  18087. 'tox-image-tools__sidebar'
  18088. ]
  18089. },
  18090. components: [
  18091. memUndo.asSpec(),
  18092. memRedo.asSpec(),
  18093. createButton('Zoom in', 'zoom-in', false, function (button) {
  18094. emitWith(button, internal.zoom(), { direction: 1 });
  18095. }, providersBackstage),
  18096. createButton('Zoom out', 'zoom-out', false, function (button) {
  18097. emitWith(button, internal.zoom(), { direction: -1 });
  18098. }, providersBackstage)
  18099. ]
  18100. });
  18101. return {
  18102. container: container,
  18103. updateButtonUndoStates: updateButtonUndoStates
  18104. };
  18105. };
  18106. var url = function () {
  18107. return Global$1.getOrDie('URL');
  18108. };
  18109. var createObjectURL = function (blob) {
  18110. return url().createObjectURL(blob);
  18111. };
  18112. var revokeObjectURL = function (u) {
  18113. url().revokeObjectURL(u);
  18114. };
  18115. var URL = {
  18116. createObjectURL: createObjectURL,
  18117. revokeObjectURL: revokeObjectURL
  18118. };
  18119. function UndoStack () {
  18120. var data = [];
  18121. var index = -1;
  18122. function add(state) {
  18123. var removed;
  18124. removed = data.splice(++index);
  18125. data.push(state);
  18126. return {
  18127. state: state,
  18128. removed: removed
  18129. };
  18130. }
  18131. function undo() {
  18132. if (canUndo()) {
  18133. return data[--index];
  18134. }
  18135. }
  18136. function redo() {
  18137. if (canRedo()) {
  18138. return data[++index];
  18139. }
  18140. }
  18141. function canUndo() {
  18142. return index > 0;
  18143. }
  18144. function canRedo() {
  18145. return index !== -1 && index < data.length - 1;
  18146. }
  18147. return {
  18148. data: data,
  18149. add: add,
  18150. undo: undo,
  18151. redo: redo,
  18152. canUndo: canUndo,
  18153. canRedo: canRedo
  18154. };
  18155. }
  18156. var makeState = function (initialState) {
  18157. var blobState = Cell(initialState);
  18158. var tempState = Cell(Option.none());
  18159. var undoStack = UndoStack();
  18160. undoStack.add(initialState);
  18161. var getBlobState = function () {
  18162. return blobState.get();
  18163. };
  18164. var setBlobState = function (state) {
  18165. blobState.set(state);
  18166. };
  18167. var getTempState = function () {
  18168. return tempState.get().fold(function () {
  18169. return blobState.get();
  18170. }, function (temp) {
  18171. return temp;
  18172. });
  18173. };
  18174. var updateTempState = function (blob) {
  18175. var newTempState = createState(blob);
  18176. destroyTempState();
  18177. tempState.set(Option.some(newTempState));
  18178. return newTempState.url;
  18179. };
  18180. var createState = function (blob) {
  18181. return {
  18182. blob: blob,
  18183. url: URL.createObjectURL(blob)
  18184. };
  18185. };
  18186. var destroyState = function (state) {
  18187. URL.revokeObjectURL(state.url);
  18188. };
  18189. var destroyStates = function (states) {
  18190. global$a.each(states, destroyState);
  18191. };
  18192. var destroyTempState = function () {
  18193. tempState.get().each(destroyState);
  18194. tempState.set(Option.none());
  18195. };
  18196. var addBlobState = function (blob) {
  18197. var newState = createState(blob);
  18198. setBlobState(newState);
  18199. var removed = undoStack.add(newState).removed;
  18200. destroyStates(removed);
  18201. return newState.url;
  18202. };
  18203. var addTempState = function (blob) {
  18204. var newState = createState(blob);
  18205. tempState.set(Option.some(newState));
  18206. return newState.url;
  18207. };
  18208. var applyTempState = function (postApply) {
  18209. return tempState.get().fold(function () {
  18210. }, function (temp) {
  18211. addBlobState(temp.blob);
  18212. postApply();
  18213. });
  18214. };
  18215. var undo = function () {
  18216. var currentState = undoStack.undo();
  18217. setBlobState(currentState);
  18218. return currentState.url;
  18219. };
  18220. var redo = function () {
  18221. var currentState = undoStack.redo();
  18222. setBlobState(currentState);
  18223. return currentState.url;
  18224. };
  18225. var getHistoryStates = function () {
  18226. var undoEnabled = undoStack.canUndo();
  18227. var redoEnabled = undoStack.canRedo();
  18228. return {
  18229. undoEnabled: undoEnabled,
  18230. redoEnabled: redoEnabled
  18231. };
  18232. };
  18233. return {
  18234. getBlobState: getBlobState,
  18235. setBlobState: setBlobState,
  18236. addBlobState: addBlobState,
  18237. getTempState: getTempState,
  18238. updateTempState: updateTempState,
  18239. addTempState: addTempState,
  18240. applyTempState: applyTempState,
  18241. destroyTempState: destroyTempState,
  18242. undo: undo,
  18243. redo: redo,
  18244. getHistoryStates: getHistoryStates
  18245. };
  18246. };
  18247. var renderImageTools = function (detail, providersBackstage) {
  18248. var state = makeState(detail.currentState);
  18249. var zoom = function (anyInSystem, simulatedEvent) {
  18250. var direction = simulatedEvent.event().direction();
  18251. imagePanel.zoom(anyInSystem, direction);
  18252. };
  18253. var updateButtonUndoStates = function (anyInSystem) {
  18254. var historyStates = state.getHistoryStates();
  18255. sideBar.updateButtonUndoStates(anyInSystem, historyStates.undoEnabled, historyStates.redoEnabled);
  18256. emitWith(anyInSystem, external$2.formActionEvent, {
  18257. name: external$2.saveState(),
  18258. value: historyStates.undoEnabled
  18259. });
  18260. };
  18261. var disableUndoRedo = function (anyInSystem) {
  18262. sideBar.updateButtonUndoStates(anyInSystem, false, false);
  18263. };
  18264. var undo = function (anyInSystem, _simulatedEvent) {
  18265. var url = state.undo();
  18266. updateSrc(anyInSystem, url).then(function (oImg) {
  18267. unblock(anyInSystem);
  18268. updateButtonUndoStates(anyInSystem);
  18269. });
  18270. };
  18271. var redo = function (anyInSystem, _simulatedEvent) {
  18272. var url = state.redo();
  18273. updateSrc(anyInSystem, url).then(function (oImg) {
  18274. unblock(anyInSystem);
  18275. updateButtonUndoStates(anyInSystem);
  18276. });
  18277. };
  18278. var imageResultToBlob = function (ir) {
  18279. return ir.toBlob();
  18280. };
  18281. var block = function (anyInSystem) {
  18282. emitWith(anyInSystem, external$2.formActionEvent, {
  18283. name: external$2.disable(),
  18284. value: {}
  18285. });
  18286. };
  18287. var unblock = function (anyInSystem) {
  18288. editPanel.getApplyButton(anyInSystem).each(function (applyButton) {
  18289. Disabling.enable(applyButton);
  18290. });
  18291. emitWith(anyInSystem, external$2.formActionEvent, {
  18292. name: external$2.enable(),
  18293. value: {}
  18294. });
  18295. };
  18296. var updateSrc = function (anyInSystem, src) {
  18297. block(anyInSystem);
  18298. return imagePanel.updateSrc(anyInSystem, src);
  18299. };
  18300. var blobManipulate = function (anyInSystem, blob, filter, action, swap) {
  18301. block(anyInSystem);
  18302. return ResultConversions.blobToImageResult(blob).then(filter).then(imageResultToBlob).then(action).then(function (url) {
  18303. return updateSrc(anyInSystem, url).then(function (oImg) {
  18304. updateButtonUndoStates(anyInSystem);
  18305. swap();
  18306. unblock(anyInSystem);
  18307. return oImg;
  18308. });
  18309. }).catch(function (err) {
  18310. console.log(err);
  18311. unblock(anyInSystem);
  18312. });
  18313. };
  18314. var manipulate = function (anyInSystem, filter, swap) {
  18315. var blob = state.getBlobState().blob;
  18316. var action = function (blob) {
  18317. return state.updateTempState(blob);
  18318. };
  18319. blobManipulate(anyInSystem, blob, filter, action, swap);
  18320. };
  18321. var tempManipulate = function (anyInSystem, filter) {
  18322. var blob = state.getTempState().blob;
  18323. var action = function (blob) {
  18324. return state.addTempState(blob);
  18325. };
  18326. blobManipulate(anyInSystem, blob, filter, action, noop);
  18327. };
  18328. var manipulateApply = function (anyInSystem, filter, swap) {
  18329. var blob = state.getBlobState().blob;
  18330. var action = function (blob) {
  18331. var url = state.addBlobState(blob);
  18332. destroyTempState(anyInSystem);
  18333. return url;
  18334. };
  18335. blobManipulate(anyInSystem, blob, filter, action, swap);
  18336. };
  18337. var apply = function (anyInSystem, simulatedEvent) {
  18338. var postApply = function () {
  18339. destroyTempState(anyInSystem);
  18340. var swap = simulatedEvent.event().swap();
  18341. swap();
  18342. };
  18343. state.applyTempState(postApply);
  18344. };
  18345. var destroyTempState = function (anyInSystem) {
  18346. var currentUrl = state.getBlobState().url;
  18347. state.destroyTempState();
  18348. updateButtonUndoStates(anyInSystem);
  18349. return currentUrl;
  18350. };
  18351. var cancel = function (anyInSystem) {
  18352. var currentUrl = destroyTempState(anyInSystem);
  18353. updateSrc(anyInSystem, currentUrl).then(function (oImg) {
  18354. unblock(anyInSystem);
  18355. });
  18356. };
  18357. var back = function (anyInSystem, simulatedEvent) {
  18358. cancel(anyInSystem);
  18359. var swap = simulatedEvent.event().swap();
  18360. swap();
  18361. imagePanel.hideCrop();
  18362. };
  18363. var transform = function (anyInSystem, simulatedEvent) {
  18364. return manipulate(anyInSystem, simulatedEvent.event().transform(), noop);
  18365. };
  18366. var tempTransform = function (anyInSystem, simulatedEvent) {
  18367. return tempManipulate(anyInSystem, simulatedEvent.event().transform());
  18368. };
  18369. var transformApply = function (anyInSystem, simulatedEvent) {
  18370. return manipulateApply(anyInSystem, simulatedEvent.event().transform(), simulatedEvent.event().swap());
  18371. };
  18372. var imagePanel = renderImagePanel(detail.currentState.url);
  18373. var sideBar = renderSideBar(providersBackstage);
  18374. var editPanel = renderEditPanel(imagePanel, providersBackstage);
  18375. var swap = function (anyInSystem, simulatedEvent) {
  18376. disableUndoRedo(anyInSystem);
  18377. var transform = simulatedEvent.event().transform();
  18378. var swap = simulatedEvent.event().swap();
  18379. transform.fold(function () {
  18380. swap();
  18381. }, function (transform) {
  18382. manipulate(anyInSystem, transform, swap);
  18383. });
  18384. };
  18385. return {
  18386. dom: {
  18387. tag: 'div',
  18388. attributes: { role: 'presentation' }
  18389. },
  18390. components: [
  18391. editPanel.memContainer.asSpec(),
  18392. imagePanel.memContainer.asSpec(),
  18393. sideBar.container
  18394. ],
  18395. behaviours: derive$1([
  18396. Representing.config({
  18397. store: {
  18398. mode: 'manual',
  18399. getValue: function () {
  18400. return state.getBlobState();
  18401. }
  18402. }
  18403. }),
  18404. config('image-tools-events', [
  18405. run(internal.undo(), undo),
  18406. run(internal.redo(), redo),
  18407. run(internal.zoom(), zoom),
  18408. run(internal.back(), back),
  18409. run(internal.apply(), apply),
  18410. run(internal.transform(), transform),
  18411. run(internal.tempTransform(), tempTransform),
  18412. run(internal.transformApply(), transformApply),
  18413. run(internal.swap(), swap)
  18414. ]),
  18415. ComposingConfigs.self()
  18416. ])
  18417. };
  18418. };
  18419. var factory$8 = function (detail, spec) {
  18420. var options = map(detail.options, function (option) {
  18421. return {
  18422. dom: {
  18423. tag: 'option',
  18424. value: option.value,
  18425. innerHtml: option.text
  18426. }
  18427. };
  18428. });
  18429. var initialValues = detail.data.map(function (v) {
  18430. return wrap$1('initialValue', v);
  18431. }).getOr({});
  18432. return {
  18433. uid: detail.uid,
  18434. dom: {
  18435. tag: 'select',
  18436. classes: detail.selectClasses,
  18437. attributes: detail.selectAttributes
  18438. },
  18439. components: options,
  18440. behaviours: augment(detail.selectBehaviours, [
  18441. Focusing.config({}),
  18442. Representing.config({
  18443. store: __assign({
  18444. mode: 'manual',
  18445. getValue: function (select) {
  18446. return get$5(select.element());
  18447. },
  18448. setValue: function (select, newValue) {
  18449. var found = find(detail.options, function (opt) {
  18450. return opt.value === newValue;
  18451. });
  18452. if (found.isSome()) {
  18453. set$3(select.element(), newValue);
  18454. }
  18455. }
  18456. }, initialValues)
  18457. })
  18458. ])
  18459. };
  18460. };
  18461. var HtmlSelect = single$2({
  18462. name: 'HtmlSelect',
  18463. configFields: [
  18464. strict$1('options'),
  18465. field$1('selectBehaviours', [
  18466. Focusing,
  18467. Representing
  18468. ]),
  18469. defaulted$1('selectClasses', []),
  18470. defaulted$1('selectAttributes', {}),
  18471. option('data')
  18472. ],
  18473. factory: factory$8
  18474. });
  18475. var renderSelectBox = function (spec, providersBackstage) {
  18476. var pLabel = spec.label.map(function (label) {
  18477. return renderLabel(label, providersBackstage);
  18478. });
  18479. var pField = FormField.parts().field({
  18480. dom: {},
  18481. selectAttributes: { size: spec.size },
  18482. options: spec.items,
  18483. factory: HtmlSelect,
  18484. selectBehaviours: derive$1([
  18485. Tabstopping.config({}),
  18486. config('selectbox-change', [run(change(), function (component, _) {
  18487. emitWith(component, formChangeEvent, { name: spec.name });
  18488. })])
  18489. ])
  18490. });
  18491. var chevron = spec.size > 1 ? Option.none() : Option.some({
  18492. dom: {
  18493. tag: 'div',
  18494. classes: ['tox-selectfield__icon-js'],
  18495. innerHtml: get$c('chevron-down', providersBackstage.icons)
  18496. }
  18497. });
  18498. var selectWrap = {
  18499. dom: {
  18500. tag: 'div',
  18501. classes: ['tox-selectfield']
  18502. },
  18503. components: flatten([
  18504. [pField],
  18505. chevron.toArray()
  18506. ])
  18507. };
  18508. return FormField.sketch({
  18509. dom: {
  18510. tag: 'div',
  18511. classes: ['tox-form__group']
  18512. },
  18513. components: flatten([
  18514. pLabel.toArray(),
  18515. [selectWrap]
  18516. ])
  18517. });
  18518. };
  18519. var renderTextField = function (spec, providersBackstage) {
  18520. var pLabel = spec.label.map(function (label) {
  18521. return renderLabel(label, providersBackstage);
  18522. });
  18523. var baseInputBehaviours = [
  18524. Keying.config({
  18525. mode: 'execution',
  18526. useEnter: spec.multiline !== true,
  18527. useControlEnter: spec.multiline === true,
  18528. execute: function (comp) {
  18529. emit(comp, formSubmitEvent);
  18530. return Option.some(true);
  18531. }
  18532. }),
  18533. config('textfield-change', [
  18534. run(input(), function (component, _) {
  18535. emitWith(component, formChangeEvent, { name: spec.name });
  18536. }),
  18537. run(postPaste(), function (component, _) {
  18538. emitWith(component, formChangeEvent, { name: spec.name });
  18539. })
  18540. ]),
  18541. Tabstopping.config({})
  18542. ];
  18543. var validatingBehaviours = spec.validation.map(function (vl) {
  18544. return Invalidating.config({
  18545. getRoot: function (input) {
  18546. return parent(input.element());
  18547. },
  18548. invalidClass: 'tox-invalid',
  18549. validator: {
  18550. validate: function (input) {
  18551. var v = Representing.getValue(input);
  18552. var result = vl.validator(v);
  18553. return Future.pure(result === true ? Result.value(v) : Result.error(result));
  18554. },
  18555. validateOnLoad: vl.validateOnLoad
  18556. }
  18557. });
  18558. }).toArray();
  18559. var pField = FormField.parts().field({
  18560. tag: spec.multiline === true ? 'textarea' : 'input',
  18561. inputAttributes: spec.placeholder.fold(function () {
  18562. }, function (placeholder) {
  18563. return { placeholder: providersBackstage.translate(placeholder) };
  18564. }),
  18565. inputClasses: [spec.classname],
  18566. inputBehaviours: derive$1(flatten([
  18567. baseInputBehaviours,
  18568. validatingBehaviours
  18569. ])),
  18570. selectOnFocus: false,
  18571. factory: Input
  18572. });
  18573. var extraClasses = spec.flex ? ['tox-form__group--stretched'] : [];
  18574. return renderFormFieldWith(pLabel, pField, extraClasses);
  18575. };
  18576. var renderInput = function (spec, providersBackstage) {
  18577. return renderTextField({
  18578. name: spec.name,
  18579. multiline: false,
  18580. label: spec.label,
  18581. placeholder: spec.placeholder,
  18582. flex: false,
  18583. classname: 'tox-textfield',
  18584. validation: Option.none()
  18585. }, providersBackstage);
  18586. };
  18587. var renderTextarea = function (spec, providersBackstage) {
  18588. return renderTextField({
  18589. name: spec.name,
  18590. multiline: true,
  18591. label: spec.label,
  18592. placeholder: spec.placeholder,
  18593. flex: true,
  18594. classname: 'tox-textarea',
  18595. validation: Option.none()
  18596. }, providersBackstage);
  18597. };
  18598. var wrap$2 = function (delegate) {
  18599. var toCached = function () {
  18600. return wrap$2(delegate.toCached());
  18601. };
  18602. var bindFuture = function (f) {
  18603. return wrap$2(delegate.bind(function (resA) {
  18604. return resA.fold(function (err) {
  18605. return Future.pure(Result.error(err));
  18606. }, function (a) {
  18607. return f(a);
  18608. });
  18609. }));
  18610. };
  18611. var bindResult = function (f) {
  18612. return wrap$2(delegate.map(function (resA) {
  18613. return resA.bind(f);
  18614. }));
  18615. };
  18616. var mapResult = function (f) {
  18617. return wrap$2(delegate.map(function (resA) {
  18618. return resA.map(f);
  18619. }));
  18620. };
  18621. var mapError = function (f) {
  18622. return wrap$2(delegate.map(function (resA) {
  18623. return resA.mapError(f);
  18624. }));
  18625. };
  18626. var foldResult = function (whenError, whenValue) {
  18627. return delegate.map(function (res) {
  18628. return res.fold(whenError, whenValue);
  18629. });
  18630. };
  18631. var withTimeout = function (timeout, errorThunk) {
  18632. return wrap$2(Future.nu(function (callback) {
  18633. var timedOut = false;
  18634. var timer = window.setTimeout(function () {
  18635. timedOut = true;
  18636. callback(Result.error(errorThunk()));
  18637. }, timeout);
  18638. delegate.get(function (result) {
  18639. if (!timedOut) {
  18640. window.clearTimeout(timer);
  18641. callback(result);
  18642. }
  18643. });
  18644. }));
  18645. };
  18646. return __assign({}, delegate, {
  18647. toCached: toCached,
  18648. bindFuture: bindFuture,
  18649. bindResult: bindResult,
  18650. mapResult: mapResult,
  18651. mapError: mapError,
  18652. foldResult: foldResult,
  18653. withTimeout: withTimeout
  18654. });
  18655. };
  18656. var nu$c = function (worker) {
  18657. return wrap$2(Future.nu(worker));
  18658. };
  18659. var value$2 = function (value) {
  18660. return wrap$2(Future.pure(Result.value(value)));
  18661. };
  18662. var error$1 = function (error) {
  18663. return wrap$2(Future.pure(Result.error(error)));
  18664. };
  18665. var fromResult$1 = function (result) {
  18666. return wrap$2(Future.pure(result));
  18667. };
  18668. var fromFuture = function (future) {
  18669. return wrap$2(future.map(Result.value));
  18670. };
  18671. var fromPromise = function (promise) {
  18672. return nu$c(function (completer) {
  18673. promise.then(function (value) {
  18674. completer(Result.value(value));
  18675. }, function (error) {
  18676. completer(Result.error(error));
  18677. });
  18678. });
  18679. };
  18680. var FutureResult = {
  18681. nu: nu$c,
  18682. wrap: wrap$2,
  18683. pure: value$2,
  18684. value: value$2,
  18685. error: error$1,
  18686. fromResult: fromResult$1,
  18687. fromFuture: fromFuture,
  18688. fromPromise: fromPromise
  18689. };
  18690. var separator$2 = { type: 'separator' };
  18691. var toMenuItem = function (target) {
  18692. return {
  18693. type: 'menuitem',
  18694. value: target.url,
  18695. text: target.title,
  18696. meta: { attach: target.attach },
  18697. onAction: function () {
  18698. }
  18699. };
  18700. };
  18701. var staticMenuItem = function (title, url) {
  18702. return {
  18703. type: 'menuitem',
  18704. value: url,
  18705. text: title,
  18706. meta: { attach: noop },
  18707. onAction: function () {
  18708. }
  18709. };
  18710. };
  18711. var toMenuItems = function (targets) {
  18712. return map(targets, toMenuItem);
  18713. };
  18714. var filterLinkTargets = function (type, targets) {
  18715. return filter(targets, function (target) {
  18716. return target.type === type;
  18717. });
  18718. };
  18719. var filteredTargets = function (type, targets) {
  18720. return toMenuItems(filterLinkTargets(type, targets));
  18721. };
  18722. var headerTargets = function (linkInfo) {
  18723. return filteredTargets('header', linkInfo.targets);
  18724. };
  18725. var anchorTargets = function (linkInfo) {
  18726. return filteredTargets('anchor', linkInfo.targets);
  18727. };
  18728. var anchorTargetTop = function (linkInfo) {
  18729. return linkInfo.anchorTop.map(function (url) {
  18730. return staticMenuItem('<top>', url);
  18731. }).toArray();
  18732. };
  18733. var anchorTargetBottom = function (linkInfo) {
  18734. return linkInfo.anchorBottom.map(function (url) {
  18735. return staticMenuItem('<bottom>', url);
  18736. }).toArray();
  18737. };
  18738. var historyTargets = function (history) {
  18739. return map(history, function (url) {
  18740. return staticMenuItem(url, url);
  18741. });
  18742. };
  18743. var joinMenuLists = function (items) {
  18744. return foldl(items, function (a, b) {
  18745. var bothEmpty = a.length === 0 || b.length === 0;
  18746. return bothEmpty ? a.concat(b) : a.concat(separator$2, b);
  18747. }, []);
  18748. };
  18749. var filterByQuery = function (term, menuItems) {
  18750. var lowerCaseTerm = term.toLowerCase();
  18751. return filter(menuItems, function (item) {
  18752. var text = item.meta !== undefined && item.meta.text !== undefined ? item.meta.text : item.text;
  18753. return contains$1(text.toLowerCase(), lowerCaseTerm) || contains$1(item.value.toLowerCase(), lowerCaseTerm);
  18754. });
  18755. };
  18756. var getItems = function (fileType, input, urlBackstage) {
  18757. var urlInputValue = Representing.getValue(input);
  18758. var term = urlInputValue.meta.text !== undefined ? urlInputValue.meta.text : urlInputValue.value;
  18759. var info = urlBackstage.getLinkInformation();
  18760. return info.fold(function () {
  18761. return [];
  18762. }, function (linkInfo) {
  18763. var history = filterByQuery(term, historyTargets(urlBackstage.getHistory(fileType)));
  18764. return fileType === 'file' ? joinMenuLists([
  18765. history,
  18766. filterByQuery(term, headerTargets(linkInfo)),
  18767. filterByQuery(term, flatten([
  18768. anchorTargetTop(linkInfo),
  18769. anchorTargets(linkInfo),
  18770. anchorTargetBottom(linkInfo)
  18771. ]))
  18772. ]) : history;
  18773. });
  18774. };
  18775. var renderInputButton = function (label, eventName, className, iconName, providersBackstage) {
  18776. return Button.sketch({
  18777. dom: {
  18778. tag: 'button',
  18779. classes: [
  18780. 'tox-tbtn',
  18781. className
  18782. ],
  18783. innerHtml: get$c(iconName, providersBackstage.icons),
  18784. attributes: { title: providersBackstage.translate(label.getOr('')) }
  18785. },
  18786. buttonBehaviours: derive$1([Tabstopping.config({})]),
  18787. action: function (component) {
  18788. emit(component, eventName);
  18789. }
  18790. });
  18791. };
  18792. var renderUrlInput = function (spec, sharedBackstage, urlBackstage) {
  18793. var _a;
  18794. var updateHistory = function (component) {
  18795. var urlEntry = Representing.getValue(component);
  18796. urlBackstage.addToHistory(urlEntry.value, spec.filetype);
  18797. };
  18798. var pField = FormField.parts().field({
  18799. factory: Typeahead,
  18800. dismissOnBlur: true,
  18801. inputClasses: ['tox-textfield'],
  18802. sandboxClasses: ['tox-dialog__popups'],
  18803. minChars: 0,
  18804. responseTime: 0,
  18805. fetch: function (input) {
  18806. var items = getItems(spec.filetype, input, urlBackstage);
  18807. var tdata = build$2(items, ItemResponse$1.BUBBLE_TO_SANDBOX, sharedBackstage.providers);
  18808. return Future.pure(tdata);
  18809. },
  18810. getHotspot: function (comp) {
  18811. return memUrlBox.getOpt(comp);
  18812. },
  18813. onSetValue: function (comp, newValue) {
  18814. if (comp.hasConfigured(Invalidating)) {
  18815. Invalidating.run(comp).get(noop);
  18816. }
  18817. },
  18818. typeaheadBehaviours: derive$1(flatten([
  18819. urlBackstage.getValidationHandler().map(function (handler) {
  18820. return Invalidating.config({
  18821. getRoot: function (comp) {
  18822. return parent(comp.element());
  18823. },
  18824. invalidClass: 'tox-control-wrap--status-invalid',
  18825. notify: {},
  18826. validator: {
  18827. validate: function (input) {
  18828. var urlEntry = Representing.getValue(input);
  18829. return FutureResult.nu(function (completer) {
  18830. handler({
  18831. type: spec.filetype,
  18832. url: urlEntry.value
  18833. }, function (validation) {
  18834. memUrlBox.getOpt(input).each(function (urlBox) {
  18835. var toggle = function (component, clazz, b) {
  18836. (b ? add$2 : remove$4)(component.element(), clazz);
  18837. };
  18838. toggle(urlBox, 'tox-control-wrap--status-valid', validation.status === 'valid');
  18839. toggle(urlBox, 'tox-control-wrap--status-unknown', validation.status === 'unknown');
  18840. });
  18841. completer((validation.status === 'invalid' ? Result.error : Result.value)(validation.message));
  18842. });
  18843. });
  18844. },
  18845. validateOnLoad: false
  18846. }
  18847. });
  18848. }).toArray(),
  18849. [
  18850. Tabstopping.config({}),
  18851. config('urlinput-events', flatten([
  18852. spec.filetype === 'file' ? [run(input(), function (comp) {
  18853. emitWith(comp, formChangeEvent, { name: spec.name });
  18854. })] : [],
  18855. [
  18856. run(change(), function (comp) {
  18857. emitWith(comp, formChangeEvent, { name: spec.name });
  18858. updateHistory(comp);
  18859. }),
  18860. run(postPaste(), function (comp) {
  18861. emitWith(comp, formChangeEvent, { name: spec.name });
  18862. updateHistory(comp);
  18863. })
  18864. ]
  18865. ]))
  18866. ]
  18867. ])),
  18868. eventOrder: (_a = {}, _a[input()] = [
  18869. 'streaming',
  18870. 'urlinput-events',
  18871. 'invalidating'
  18872. ], _a),
  18873. model: {
  18874. getDisplayText: function (itemData) {
  18875. return itemData.value;
  18876. },
  18877. selectsOver: false,
  18878. populateFromBrowse: false
  18879. },
  18880. markers: { openClass: 'dog' },
  18881. lazySink: sharedBackstage.getSink,
  18882. parts: { menu: part(false, 1, 'normal') },
  18883. onExecute: function (_menu, component, _entry) {
  18884. emitWith(component, formSubmitEvent, {});
  18885. },
  18886. onItemExecute: function (typeahead, _sandbox, _item, _value) {
  18887. updateHistory(typeahead);
  18888. emitWith(typeahead, formChangeEvent, { name: spec.name });
  18889. }
  18890. });
  18891. var pLabel = spec.label.map(function (label) {
  18892. return renderLabel(label, sharedBackstage.providers);
  18893. });
  18894. var makeIcon = function (name, icon, label) {
  18895. if (icon === void 0) {
  18896. icon = name;
  18897. }
  18898. if (label === void 0) {
  18899. label = name;
  18900. }
  18901. return {
  18902. dom: {
  18903. tag: 'div',
  18904. classes: [
  18905. 'tox-icon',
  18906. 'tox-control-wrap__status-icon-' + name
  18907. ],
  18908. innerHtml: get$c(icon, sharedBackstage.providers.icons),
  18909. attributes: { title: sharedBackstage.providers.translate(label) }
  18910. }
  18911. };
  18912. };
  18913. var memStatus = record({
  18914. dom: {
  18915. tag: 'div',
  18916. classes: ['tox-control-wrap__status-icon-wrap']
  18917. },
  18918. components: [
  18919. makeIcon('valid', 'checkmark', 'valid'),
  18920. makeIcon('unknown', 'warning'),
  18921. makeIcon('invalid', 'warning')
  18922. ]
  18923. });
  18924. var optUrlPicker = urlBackstage.getUrlPicker(spec.filetype);
  18925. var browseUrlEvent = generate$1('browser.url.event');
  18926. var memUrlBox = record({
  18927. dom: {
  18928. tag: 'div',
  18929. classes: ['tox-control-wrap']
  18930. },
  18931. components: [
  18932. pField,
  18933. memStatus.asSpec()
  18934. ]
  18935. });
  18936. var controlHWrapper = function () {
  18937. return {
  18938. dom: {
  18939. tag: 'div',
  18940. classes: ['tox-form__controls-h-stack']
  18941. },
  18942. components: flatten([
  18943. [memUrlBox.asSpec()],
  18944. optUrlPicker.map(function () {
  18945. return renderInputButton(spec.label, browseUrlEvent, 'tox-browse-url', 'browse', sharedBackstage.providers);
  18946. }).toArray()
  18947. ])
  18948. };
  18949. };
  18950. var openUrlPicker = function (comp) {
  18951. Composing.getCurrent(comp).each(function (field) {
  18952. var urlData = Representing.getValue(field);
  18953. optUrlPicker.each(function (picker) {
  18954. picker(urlData).get(function (chosenData) {
  18955. Representing.setValue(field, chosenData);
  18956. emitWith(comp, formChangeEvent, { name: spec.name });
  18957. });
  18958. });
  18959. });
  18960. };
  18961. return FormField.sketch({
  18962. dom: renderFormFieldDom(),
  18963. components: pLabel.toArray().concat([controlHWrapper()]),
  18964. fieldBehaviours: derive$1([config('url-input-events', [run(browseUrlEvent, openUrlPicker)])])
  18965. });
  18966. };
  18967. var renderCheckbox = function (spec, providerBackstage) {
  18968. var repBehaviour = Representing.config({
  18969. store: {
  18970. mode: 'manual',
  18971. getValue: function (comp) {
  18972. var el = comp.element().dom();
  18973. return el.checked;
  18974. },
  18975. setValue: function (comp, value) {
  18976. var el = comp.element().dom();
  18977. el.checked = value;
  18978. }
  18979. }
  18980. });
  18981. var toggleCheckboxHandler = function (comp) {
  18982. comp.element().dom().click();
  18983. return Option.some(true);
  18984. };
  18985. var pField = FormField.parts().field({
  18986. factory: { sketch: identity },
  18987. dom: {
  18988. tag: 'input',
  18989. classes: ['tox-checkbox__input'],
  18990. attributes: { type: 'checkbox' }
  18991. },
  18992. behaviours: derive$1([
  18993. ComposingConfigs.self(),
  18994. Tabstopping.config({}),
  18995. Focusing.config({}),
  18996. repBehaviour,
  18997. Keying.config({
  18998. mode: 'special',
  18999. onEnter: toggleCheckboxHandler,
  19000. onSpace: toggleCheckboxHandler,
  19001. stopSpaceKeyup: true
  19002. }),
  19003. config('checkbox-events', [run(change(), function (component, _) {
  19004. emitWith(component, formChangeEvent, { name: spec.name });
  19005. })])
  19006. ])
  19007. });
  19008. var pLabel = FormField.parts().label({
  19009. dom: {
  19010. tag: 'span',
  19011. classes: ['tox-checkbox__label'],
  19012. innerHtml: providerBackstage.translate(spec.label)
  19013. },
  19014. behaviours: derive$1([Unselecting.config({})])
  19015. });
  19016. var makeIcon = function (className) {
  19017. var iconName = className === 'checked' ? 'selected' : 'unselected';
  19018. return {
  19019. dom: {
  19020. tag: 'span',
  19021. classes: [
  19022. 'tox-icon',
  19023. 'tox-checkbox-icon__' + className
  19024. ],
  19025. innerHtml: get$c(iconName, providerBackstage.icons)
  19026. }
  19027. };
  19028. };
  19029. var memIcons = record({
  19030. dom: {
  19031. tag: 'div',
  19032. classes: ['tox-checkbox__icons']
  19033. },
  19034. components: [
  19035. makeIcon('checked'),
  19036. makeIcon('unchecked')
  19037. ]
  19038. });
  19039. return FormField.sketch({
  19040. dom: {
  19041. tag: 'label',
  19042. classes: ['tox-checkbox']
  19043. },
  19044. components: [
  19045. pField,
  19046. memIcons.asSpec(),
  19047. pLabel
  19048. ]
  19049. });
  19050. };
  19051. var renderHtmlPanel = function (spec) {
  19052. return Container.sketch({
  19053. dom: {
  19054. tag: 'div',
  19055. innerHtml: spec.html
  19056. },
  19057. containerBehaviours: derive$1([
  19058. Tabstopping.config({}),
  19059. Focusing.config({})
  19060. ])
  19061. });
  19062. };
  19063. var renderListbox = function (spec, providersBackstage) {
  19064. var pLabel = renderLabel(spec.label, providersBackstage);
  19065. var pField = FormField.parts().field({
  19066. factory: HtmlSelect,
  19067. dom: { classes: ['mce-select-field'] },
  19068. selectBehaviours: derive$1([Tabstopping.config({})]),
  19069. options: spec.values,
  19070. data: spec.initialValue.getOr(undefined)
  19071. });
  19072. return renderFormField(Option.some(pLabel), pField);
  19073. };
  19074. var renderLabel$2 = function (spec, backstageShared) {
  19075. var label = {
  19076. dom: {
  19077. tag: 'label',
  19078. innerHtml: backstageShared.providers.translate(spec.label),
  19079. classes: ['tox-label']
  19080. }
  19081. };
  19082. var comps = map(spec.items, backstageShared.interpreter);
  19083. return {
  19084. dom: {
  19085. tag: 'div',
  19086. classes: ['tox-form__group']
  19087. },
  19088. components: [label].concat(comps),
  19089. behaviours: derive$1([
  19090. ComposingConfigs.self(),
  19091. Replacing.config({}),
  19092. RepresentingConfigs.domHtml(Option.none()),
  19093. Keying.config({ mode: 'acyclic' })
  19094. ])
  19095. };
  19096. };
  19097. var renderCollection = function (spec, providersBackstage) {
  19098. var pLabel = spec.label.map(function (label) {
  19099. return renderLabel(label, providersBackstage);
  19100. });
  19101. var runOnItem = function (f) {
  19102. return function (comp, se) {
  19103. closest$3(se.event().target(), '[data-collection-item-value]').each(function (target) {
  19104. f(comp, target, get$2(target, 'data-collection-item-value'));
  19105. });
  19106. };
  19107. };
  19108. var escapeAttribute = function (ch) {
  19109. if (ch === '"') {
  19110. return '&quot;';
  19111. }
  19112. return ch;
  19113. };
  19114. var setContents = function (comp, items) {
  19115. var htmlLines = map(items, function (item) {
  19116. var textContent = spec.columns === 1 ? item.text.map(function (text) {
  19117. return '<span class="tox-collection__item-label">' + text + '</span>';
  19118. }).getOr('') : '';
  19119. var iconContent = item.icon.map(function (icon) {
  19120. return '<span class="tox-collection__item-icon">' + icon + '</span>';
  19121. }).getOr('');
  19122. var mapItemName = {
  19123. '_': ' ',
  19124. ' - ': ' ',
  19125. '-': ' '
  19126. };
  19127. var ariaLabel = item.text.getOr('').replace(/\_| \- |\-/g, function (match) {
  19128. return mapItemName[match];
  19129. });
  19130. return '<div class="tox-collection__item" tabindex="-1" data-collection-item-value="' + escapeAttribute(item.value) + '" title="' + ariaLabel + '" aria-label="' + ariaLabel + '">' + iconContent + textContent + '</div>';
  19131. });
  19132. var chunks = spec.columns > 1 && spec.columns !== 'auto' ? chunk(htmlLines, spec.columns) : [htmlLines];
  19133. var html = map(chunks, function (ch) {
  19134. return '<div class="tox-collection__group">' + ch.join('') + '</div>';
  19135. });
  19136. set(comp.element(), html.join(''));
  19137. };
  19138. var collectionEvents = [
  19139. run(mouseover(), runOnItem(function (comp, tgt) {
  19140. focus$1(tgt);
  19141. })),
  19142. run(click(), runOnItem(function (comp, tgt, itemValue) {
  19143. emitWith(comp, formActionEvent, {
  19144. name: spec.name,
  19145. value: itemValue
  19146. });
  19147. })),
  19148. run(focusin(), runOnItem(function (comp, tgt, itemValue) {
  19149. descendant$1(comp.element(), '.' + activeClass).each(function (currentActive) {
  19150. remove$4(currentActive, activeClass);
  19151. });
  19152. add$2(tgt, activeClass);
  19153. })),
  19154. run(focusout(), runOnItem(function (comp, tgt, itemValue) {
  19155. descendant$1(comp.element(), '.' + activeClass).each(function (currentActive) {
  19156. remove$4(currentActive, activeClass);
  19157. });
  19158. })),
  19159. runOnExecute(runOnItem(function (comp, tgt, itemValue) {
  19160. emitWith(comp, formActionEvent, {
  19161. name: spec.name,
  19162. value: itemValue
  19163. });
  19164. }))
  19165. ];
  19166. var pField = FormField.parts().field({
  19167. dom: {
  19168. tag: 'div',
  19169. classes: ['tox-collection'].concat(spec.columns !== 1 ? ['tox-collection--grid'] : ['tox-collection--list'])
  19170. },
  19171. components: [],
  19172. factory: { sketch: identity },
  19173. behaviours: derive$1([
  19174. Replacing.config({}),
  19175. Representing.config({
  19176. store: {
  19177. mode: 'memory',
  19178. initialValue: []
  19179. },
  19180. onSetValue: function (comp, items) {
  19181. setContents(comp, items);
  19182. if (spec.columns === 'auto') {
  19183. detectSize(comp, 5, 'tox-collection__item').each(function (_a) {
  19184. var numRows = _a.numRows, numColumns = _a.numColumns;
  19185. Keying.setGridSize(comp, numRows, numColumns);
  19186. });
  19187. }
  19188. emit(comp, formResizeEvent);
  19189. }
  19190. }),
  19191. Tabstopping.config({}),
  19192. Keying.config(deriveCollectionMovement(spec.columns, 'normal')),
  19193. config('collection-events', collectionEvents)
  19194. ])
  19195. });
  19196. var extraClasses = ['tox-form__group--collection'];
  19197. return renderFormFieldWith(pLabel, pField, extraClasses);
  19198. };
  19199. var renderTable = function (spec, providersBackstage) {
  19200. var renderTh = function (text) {
  19201. return {
  19202. dom: {
  19203. tag: 'th',
  19204. innerHtml: providersBackstage.translate(text)
  19205. }
  19206. };
  19207. };
  19208. var renderHeader = function (header) {
  19209. return {
  19210. dom: { tag: 'thead' },
  19211. components: [{
  19212. dom: { tag: 'tr' },
  19213. components: map(header, renderTh)
  19214. }]
  19215. };
  19216. };
  19217. var renderTd = function (text) {
  19218. return {
  19219. dom: {
  19220. tag: 'td',
  19221. innerHtml: providersBackstage.translate(text)
  19222. }
  19223. };
  19224. };
  19225. var renderTr = function (row) {
  19226. return {
  19227. dom: { tag: 'tr' },
  19228. components: map(row, renderTd)
  19229. };
  19230. };
  19231. var renderRows = function (rows) {
  19232. return {
  19233. dom: { tag: 'tbody' },
  19234. components: map(rows, renderTr)
  19235. };
  19236. };
  19237. return {
  19238. dom: {
  19239. tag: 'table',
  19240. classes: ['tox-dialog__table']
  19241. },
  19242. components: [
  19243. renderHeader(spec.header),
  19244. renderRows(spec.cells)
  19245. ],
  19246. behaviours: derive$1([
  19247. Tabstopping.config({}),
  19248. Focusing.config({})
  19249. ])
  19250. };
  19251. };
  19252. var make$5 = function (render) {
  19253. return function (parts, spec, backstage) {
  19254. return readOptFrom$1(spec, 'name').fold(function () {
  19255. return render(spec, backstage);
  19256. }, function (fieldName) {
  19257. return parts.field(fieldName, render(spec, backstage));
  19258. });
  19259. };
  19260. };
  19261. var makeIframe = function (render) {
  19262. return function (parts, spec, backstage) {
  19263. var iframeSpec = deepMerge(spec, { source: 'dynamic' });
  19264. return make$5(render)(parts, iframeSpec, backstage);
  19265. };
  19266. };
  19267. var factories = {
  19268. bar: make$5(function (spec, backstage) {
  19269. return renderBar(spec, backstage.shared);
  19270. }),
  19271. collection: make$5(function (spec, backstage) {
  19272. return renderCollection(spec, backstage.shared.providers);
  19273. }),
  19274. alloy: make$5(identity),
  19275. alertbanner: make$5(function (spec, backstage) {
  19276. return renderAlertBanner(spec, backstage.shared.providers);
  19277. }),
  19278. input: make$5(function (spec, backstage) {
  19279. return renderInput(spec, backstage.shared.providers);
  19280. }),
  19281. textarea: make$5(function (spec, backstage) {
  19282. return renderTextarea(spec, backstage.shared.providers);
  19283. }),
  19284. listbox: make$5(function (spec, backstage) {
  19285. return renderListbox(spec, backstage.shared.providers);
  19286. }),
  19287. label: make$5(function (spec, backstage) {
  19288. return renderLabel$2(spec, backstage.shared);
  19289. }),
  19290. iframe: makeIframe(function (spec, backstage) {
  19291. return renderIFrame(spec, backstage.shared.providers);
  19292. }),
  19293. autocomplete: make$5(function (spec, backstage) {
  19294. return renderAutocomplete(spec, backstage.shared);
  19295. }),
  19296. button: make$5(function (spec, backstage) {
  19297. return renderDialogButton(spec, backstage.shared.providers);
  19298. }),
  19299. checkbox: make$5(function (spec, backstage) {
  19300. return renderCheckbox(spec, backstage.shared.providers);
  19301. }),
  19302. colorinput: make$5(function (spec, backstage) {
  19303. return renderColorInput(spec, backstage.shared, backstage.colorinput);
  19304. }),
  19305. colorpicker: make$5(renderColorPicker),
  19306. dropzone: make$5(function (spec, backstage) {
  19307. return renderDropZone(spec, backstage.shared.providers);
  19308. }),
  19309. grid: make$5(function (spec, backstage) {
  19310. return renderGrid(spec, backstage.shared);
  19311. }),
  19312. selectbox: make$5(function (spec, backstage) {
  19313. return renderSelectBox(spec, backstage.shared.providers);
  19314. }),
  19315. sizeinput: make$5(function (spec, backstage) {
  19316. return renderSizeInput(spec, backstage.shared.providers);
  19317. }),
  19318. urlinput: make$5(function (spec, backstage) {
  19319. return renderUrlInput(spec, backstage.shared, backstage.urlinput);
  19320. }),
  19321. customeditor: make$5(renderCustomEditor),
  19322. htmlpanel: make$5(renderHtmlPanel),
  19323. imagetools: make$5(function (spec, backstage) {
  19324. return renderImageTools(spec, backstage.shared.providers);
  19325. }),
  19326. table: make$5(function (spec, backstage) {
  19327. return renderTable(spec, backstage.shared.providers);
  19328. })
  19329. };
  19330. var noFormParts = {
  19331. field: function (_name, spec) {
  19332. return spec;
  19333. }
  19334. };
  19335. var interpretInForm = function (parts, spec, oldBackstage) {
  19336. var newBackstage = deepMerge(oldBackstage, {
  19337. shared: {
  19338. interpreter: function (childSpec) {
  19339. return interpretParts(parts, childSpec, newBackstage);
  19340. }
  19341. }
  19342. });
  19343. return interpretParts(parts, spec, newBackstage);
  19344. };
  19345. var interpretParts = function (parts, spec, backstage) {
  19346. return readOptFrom$1(factories, spec.type).fold(function () {
  19347. console.error('Unknown factory type "' + spec.type + '", defaulting to container: ', spec);
  19348. return spec;
  19349. }, function (factory) {
  19350. return factory(parts, spec, backstage);
  19351. });
  19352. };
  19353. var interpretWithoutForm = function (spec, backstage) {
  19354. var parts = noFormParts;
  19355. return interpretParts(parts, spec, backstage);
  19356. };
  19357. var colorPicker = function (editor) {
  19358. return function (callback, value) {
  19359. var dialog = ColorSwatch.colorPickerDialog(editor);
  19360. dialog(callback, value);
  19361. };
  19362. };
  19363. var hasCustomColors$1 = function (editor) {
  19364. return function () {
  19365. return Settings.hasCustomColors(editor);
  19366. };
  19367. };
  19368. var getColors$1 = function (editor) {
  19369. return function () {
  19370. return Settings.getColors(editor);
  19371. };
  19372. };
  19373. var ColorInputBackstage = function (editor) {
  19374. return {
  19375. colorPicker: colorPicker(editor),
  19376. hasCustomColors: hasCustomColors$1(editor),
  19377. getColors: getColors$1(editor)
  19378. };
  19379. };
  19380. var defaultStyleFormats = [
  19381. {
  19382. title: 'Headings',
  19383. items: [
  19384. {
  19385. title: 'Heading 1',
  19386. format: 'h1'
  19387. },
  19388. {
  19389. title: 'Heading 2',
  19390. format: 'h2'
  19391. },
  19392. {
  19393. title: 'Heading 3',
  19394. format: 'h3'
  19395. },
  19396. {
  19397. title: 'Heading 4',
  19398. format: 'h4'
  19399. },
  19400. {
  19401. title: 'Heading 5',
  19402. format: 'h5'
  19403. },
  19404. {
  19405. title: 'Heading 6',
  19406. format: 'h6'
  19407. }
  19408. ]
  19409. },
  19410. {
  19411. title: 'Inline',
  19412. items: [
  19413. {
  19414. title: 'Bold',
  19415. icon: 'bold',
  19416. format: 'bold'
  19417. },
  19418. {
  19419. title: 'Italic',
  19420. icon: 'italic',
  19421. format: 'italic'
  19422. },
  19423. {
  19424. title: 'Underline',
  19425. icon: 'underline',
  19426. format: 'underline'
  19427. },
  19428. {
  19429. title: 'Strikethrough',
  19430. icon: 'strike-through',
  19431. format: 'strikethrough'
  19432. },
  19433. {
  19434. title: 'Superscript',
  19435. icon: 'superscript',
  19436. format: 'superscript'
  19437. },
  19438. {
  19439. title: 'Subscript',
  19440. icon: 'subscript',
  19441. format: 'subscript'
  19442. },
  19443. {
  19444. title: 'Code',
  19445. icon: 'code',
  19446. format: 'code'
  19447. }
  19448. ]
  19449. },
  19450. {
  19451. title: 'Blocks',
  19452. items: [
  19453. {
  19454. title: 'Paragraph',
  19455. format: 'p'
  19456. },
  19457. {
  19458. title: 'Blockquote',
  19459. format: 'blockquote'
  19460. },
  19461. {
  19462. title: 'Div',
  19463. format: 'div'
  19464. },
  19465. {
  19466. title: 'Pre',
  19467. format: 'pre'
  19468. }
  19469. ]
  19470. },
  19471. {
  19472. title: 'Align',
  19473. items: [
  19474. {
  19475. title: 'Left',
  19476. icon: 'align-left',
  19477. format: 'alignleft'
  19478. },
  19479. {
  19480. title: 'Center',
  19481. icon: 'align-center',
  19482. format: 'aligncenter'
  19483. },
  19484. {
  19485. title: 'Right',
  19486. icon: 'align-right',
  19487. format: 'alignright'
  19488. },
  19489. {
  19490. title: 'Justify',
  19491. icon: 'align-justify',
  19492. format: 'alignjustify'
  19493. }
  19494. ]
  19495. }
  19496. ];
  19497. var isNestedFormat = function (format) {
  19498. return has(format, 'items');
  19499. };
  19500. var isBlockFormat = function (format) {
  19501. return has(format, 'block');
  19502. };
  19503. var isInlineFormat = function (format) {
  19504. return has(format, 'inline');
  19505. };
  19506. var isSelectorFormat = function (format) {
  19507. return has(format, 'selector');
  19508. };
  19509. var mapFormats = function (userFormats) {
  19510. return foldl(userFormats, function (acc, fmt) {
  19511. if (isNestedFormat(fmt)) {
  19512. var result = mapFormats(fmt.items);
  19513. return {
  19514. customFormats: acc.customFormats.concat(result.customFormats),
  19515. formats: acc.formats.concat([{
  19516. title: fmt.title,
  19517. items: result.formats
  19518. }])
  19519. };
  19520. } else if (isInlineFormat(fmt) || isBlockFormat(fmt) || isSelectorFormat(fmt)) {
  19521. var formatName = 'custom-' + fmt.title.toLowerCase();
  19522. return {
  19523. customFormats: acc.customFormats.concat([{
  19524. name: formatName,
  19525. format: fmt
  19526. }]),
  19527. formats: acc.formats.concat([{
  19528. title: fmt.title,
  19529. format: formatName,
  19530. icon: fmt.icon
  19531. }])
  19532. };
  19533. } else {
  19534. return __assign({}, acc, { formats: acc.formats.concat(fmt) });
  19535. }
  19536. }, {
  19537. customFormats: [],
  19538. formats: []
  19539. });
  19540. };
  19541. var registerCustomFormats = function (editor, userFormats) {
  19542. var result = mapFormats(userFormats);
  19543. var registerFormats = function (customFormats) {
  19544. each(customFormats, function (fmt) {
  19545. if (!editor.formatter.has(fmt.name)) {
  19546. editor.formatter.register(fmt.name, fmt.format);
  19547. }
  19548. });
  19549. };
  19550. if (editor.formatter) {
  19551. registerFormats(result.customFormats);
  19552. } else {
  19553. editor.on('init', function () {
  19554. registerFormats(result.customFormats);
  19555. });
  19556. }
  19557. return result.formats;
  19558. };
  19559. var getStyleFormats = function (editor) {
  19560. return getUserStyleFormats(editor).map(function (userFormats) {
  19561. var registeredUserFormats = registerCustomFormats(editor, userFormats);
  19562. return isMergeStyleFormats(editor) ? defaultStyleFormats.concat(registeredUserFormats) : registeredUserFormats;
  19563. }).getOr(defaultStyleFormats);
  19564. };
  19565. var processBasic = function (item, isSelectedFor, getPreviewFor) {
  19566. var formatterSpec = {
  19567. type: 'formatter',
  19568. isSelected: isSelectedFor(item.format),
  19569. getStylePreview: getPreviewFor(item.format)
  19570. };
  19571. return deepMerge(item, formatterSpec);
  19572. };
  19573. var register$3 = function (editor, formats, isSelectedFor, getPreviewFor) {
  19574. var enrichSupported = function (item) {
  19575. return processBasic(item, isSelectedFor, getPreviewFor);
  19576. };
  19577. var enrichMenu = function (item) {
  19578. var submenuSpec = {
  19579. type: 'submenu',
  19580. isSelected: constant(false),
  19581. getStylePreview: function () {
  19582. return Option.none();
  19583. }
  19584. };
  19585. return deepMerge(item, submenuSpec);
  19586. };
  19587. var enrichCustom = function (item) {
  19588. var formatName = generate$1(item.title);
  19589. var customSpec = {
  19590. type: 'formatter',
  19591. format: formatName,
  19592. isSelected: isSelectedFor(formatName),
  19593. getStylePreview: getPreviewFor(formatName)
  19594. };
  19595. var newItem = deepMerge(item, customSpec);
  19596. editor.formatter.register(formatName, newItem);
  19597. return newItem;
  19598. };
  19599. var doEnrich = function (items) {
  19600. return map(items, function (item) {
  19601. var keys$1 = keys(item);
  19602. if (hasKey$1(item, 'items')) {
  19603. var newItems_1 = doEnrich(item.items);
  19604. return deepMerge(enrichMenu(item), {
  19605. getStyleItems: function () {
  19606. return newItems_1;
  19607. }
  19608. });
  19609. } else if (hasKey$1(item, 'format')) {
  19610. return enrichSupported(item);
  19611. } else if (keys$1.length === 1 && contains(keys$1, 'title')) {
  19612. return deepMerge(item, { type: 'separator' });
  19613. } else {
  19614. return enrichCustom(item);
  19615. }
  19616. });
  19617. };
  19618. return doEnrich(formats);
  19619. };
  19620. var init$8 = function (editor) {
  19621. var isSelectedFor = function (format) {
  19622. return function () {
  19623. return editor.formatter.match(format);
  19624. };
  19625. };
  19626. var getPreviewFor = function (format) {
  19627. return function () {
  19628. var fmt = editor.formatter.get(format);
  19629. return fmt !== undefined ? Option.some({
  19630. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || 'div' : 'div',
  19631. styleAttr: editor.formatter.getCssText(format)
  19632. }) : Option.none();
  19633. };
  19634. };
  19635. var flatten = function (fmt) {
  19636. var subs = fmt.items;
  19637. return subs !== undefined && subs.length > 0 ? bind(subs, flatten) : [fmt.format];
  19638. };
  19639. var settingsFormats = Cell([]);
  19640. var settingsFlattenedFormats = Cell([]);
  19641. var eventsFormats = Cell([]);
  19642. var eventsFlattenedFormats = Cell([]);
  19643. var replaceSettings = Cell(false);
  19644. editor.on('init', function () {
  19645. var formats = getStyleFormats(editor);
  19646. var enriched = register$3(editor, formats, isSelectedFor, getPreviewFor);
  19647. settingsFormats.set(enriched);
  19648. settingsFlattenedFormats.set(bind(enriched, flatten));
  19649. });
  19650. editor.on('addStyleModifications', function (e) {
  19651. var modifications = register$3(editor, e.items, isSelectedFor, getPreviewFor);
  19652. eventsFormats.set(modifications);
  19653. replaceSettings.set(e.replace);
  19654. eventsFlattenedFormats.set(bind(modifications, flatten));
  19655. });
  19656. var getData = function () {
  19657. var fromSettings = replaceSettings.get() ? [] : settingsFormats.get();
  19658. var fromEvents = eventsFormats.get();
  19659. return fromSettings.concat(fromEvents);
  19660. };
  19661. var getFlattenedKeys = function () {
  19662. var fromSettings = replaceSettings.get() ? [] : settingsFlattenedFormats.get();
  19663. var fromEvents = eventsFlattenedFormats.get();
  19664. return fromSettings.concat(fromEvents);
  19665. };
  19666. return {
  19667. getData: getData,
  19668. getFlattenedKeys: getFlattenedKeys
  19669. };
  19670. };
  19671. var trim$1 = global$a.trim;
  19672. var hasContentEditableState = function (value) {
  19673. return function (node) {
  19674. if (node && node.nodeType === 1) {
  19675. if (node.contentEditable === value) {
  19676. return true;
  19677. }
  19678. if (node.getAttribute('data-mce-contenteditable') === value) {
  19679. return true;
  19680. }
  19681. }
  19682. return false;
  19683. };
  19684. };
  19685. var isContentEditableTrue = hasContentEditableState('true');
  19686. var isContentEditableFalse = hasContentEditableState('false');
  19687. var create$6 = function (type, title, url, level, attach) {
  19688. return {
  19689. type: type,
  19690. title: title,
  19691. url: url,
  19692. level: level,
  19693. attach: attach
  19694. };
  19695. };
  19696. var isChildOfContentEditableTrue = function (node) {
  19697. while (node = node.parentNode) {
  19698. var value = node.contentEditable;
  19699. if (value && value !== 'inherit') {
  19700. return isContentEditableTrue(node);
  19701. }
  19702. }
  19703. return false;
  19704. };
  19705. var select = function (selector, root) {
  19706. return map(descendants(Element.fromDom(root), selector), function (element) {
  19707. return element.dom();
  19708. });
  19709. };
  19710. var getElementText = function (elm) {
  19711. return elm.innerText || elm.textContent;
  19712. };
  19713. var getOrGenerateId = function (elm) {
  19714. return elm.id ? elm.id : generate$1('h');
  19715. };
  19716. var isAnchor = function (elm) {
  19717. return elm && elm.nodeName === 'A' && (elm.id || elm.name) !== undefined;
  19718. };
  19719. var isValidAnchor = function (elm) {
  19720. return isAnchor(elm) && isEditable(elm);
  19721. };
  19722. var isHeader = function (elm) {
  19723. return elm && /^(H[1-6])$/.test(elm.nodeName);
  19724. };
  19725. var isEditable = function (elm) {
  19726. return isChildOfContentEditableTrue(elm) && !isContentEditableFalse(elm);
  19727. };
  19728. var isValidHeader = function (elm) {
  19729. return isHeader(elm) && isEditable(elm);
  19730. };
  19731. var getLevel = function (elm) {
  19732. return isHeader(elm) ? parseInt(elm.nodeName.substr(1), 10) : 0;
  19733. };
  19734. var headerTarget = function (elm) {
  19735. var headerId = getOrGenerateId(elm);
  19736. var attach = function () {
  19737. elm.id = headerId;
  19738. };
  19739. return create$6('header', getElementText(elm), '#' + headerId, getLevel(elm), attach);
  19740. };
  19741. var anchorTarget = function (elm) {
  19742. var anchorId = elm.id || elm.name;
  19743. var anchorText = getElementText(elm);
  19744. return create$6('anchor', anchorText ? anchorText : '#' + anchorId, '#' + anchorId, 0, noop);
  19745. };
  19746. var getHeaderTargets = function (elms) {
  19747. return map(filter(elms, isValidHeader), headerTarget);
  19748. };
  19749. var getAnchorTargets = function (elms) {
  19750. return map(filter(elms, isValidAnchor), anchorTarget);
  19751. };
  19752. var getTargetElements = function (elm) {
  19753. var elms = select('h1,h2,h3,h4,h5,h6,a:not([href])', elm);
  19754. return elms;
  19755. };
  19756. var hasTitle = function (target) {
  19757. return trim$1(target.title).length > 0;
  19758. };
  19759. var find$5 = function (elm) {
  19760. var elms = getTargetElements(elm);
  19761. return filter(getHeaderTargets(elms).concat(getAnchorTargets(elms)), hasTitle);
  19762. };
  19763. var LinkTargets = { find: find$5 };
  19764. var STORAGE_KEY = 'tinymce-url-history';
  19765. var HISTORY_LENGTH = 5;
  19766. var isHttpUrl = function (url) {
  19767. return isString(url) && /^https?/.test(url);
  19768. };
  19769. var isArrayOfUrl = function (a) {
  19770. return isArray(a) && a.length <= HISTORY_LENGTH && forall(a, isHttpUrl);
  19771. };
  19772. var isRecordOfUrlArray = function (r) {
  19773. return isObject(r) && find$1(r, function (value) {
  19774. return !isArrayOfUrl(value);
  19775. }).isNone();
  19776. };
  19777. var getAllHistory = function () {
  19778. var unparsedHistory = domGlobals.localStorage.getItem(STORAGE_KEY);
  19779. if (unparsedHistory === null) {
  19780. return {};
  19781. }
  19782. var history;
  19783. try {
  19784. history = JSON.parse(unparsedHistory);
  19785. } catch (e) {
  19786. if (e instanceof SyntaxError) {
  19787. console.log('Local storage ' + STORAGE_KEY + ' was not valid JSON', e);
  19788. return {};
  19789. }
  19790. throw e;
  19791. }
  19792. if (!isRecordOfUrlArray(history)) {
  19793. console.log('Local storage ' + STORAGE_KEY + ' was not valid format', history);
  19794. return {};
  19795. }
  19796. return history;
  19797. };
  19798. var setAllHistory = function (history) {
  19799. if (!isRecordOfUrlArray(history)) {
  19800. throw new Error('Bad format for history:\n' + JSON.stringify(history));
  19801. }
  19802. domGlobals.localStorage.setItem(STORAGE_KEY, JSON.stringify(history));
  19803. };
  19804. var getHistory = function (fileType) {
  19805. var history = getAllHistory();
  19806. return Object.prototype.hasOwnProperty.call(history, fileType) ? history[fileType] : [];
  19807. };
  19808. var addToHistory = function (url, fileType) {
  19809. if (!isHttpUrl(url)) {
  19810. return;
  19811. }
  19812. var history = getAllHistory();
  19813. var items = Object.prototype.hasOwnProperty.call(history, fileType) ? history[fileType] : [];
  19814. var itemsWithoutUrl = filter(items, function (item) {
  19815. return item !== url;
  19816. });
  19817. history[fileType] = [url].concat(itemsWithoutUrl).slice(0, HISTORY_LENGTH);
  19818. setAllHistory(history);
  19819. };
  19820. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  19821. var isTruthy = function (value) {
  19822. return !!value;
  19823. };
  19824. var makeMap = function (value) {
  19825. return map$1(global$a.makeMap(value, /[, ]/), isTruthy);
  19826. };
  19827. var getOpt = function (obj, key) {
  19828. return hasOwnProperty$2.call(obj, key) ? Option.some(obj[key]) : Option.none();
  19829. };
  19830. var getTextSetting = function (settings, name, defaultValue) {
  19831. var value = getOpt(settings, name).getOr(defaultValue);
  19832. return isString(value) ? Option.some(value) : Option.none();
  19833. };
  19834. var getPickerSetting = function (settings, filetype) {
  19835. var optFileTypes = Option.some(settings.file_picker_types).filter(isTruthy);
  19836. var optLegacyTypes = Option.some(settings.file_browser_callback_types).filter(isTruthy);
  19837. var optTypes = optFileTypes.or(optLegacyTypes).map(makeMap);
  19838. var on = optTypes.fold(function () {
  19839. return true;
  19840. }, function (types) {
  19841. return getOpt(types, filetype).getOr(false);
  19842. });
  19843. var optPicker = Option.some(settings.file_picker_callback).filter(isFunction);
  19844. return !on ? Option.none() : optPicker;
  19845. };
  19846. var getLinkInformation = function (editor) {
  19847. return function () {
  19848. if (editor.settings.typeahead_urls === false) {
  19849. return Option.none();
  19850. }
  19851. return Option.some({
  19852. targets: LinkTargets.find(editor.getBody()),
  19853. anchorTop: getTextSetting(editor.settings, 'anchor_top', '#top'),
  19854. anchorBottom: getTextSetting(editor.settings, 'anchor_bottom', '#bottom')
  19855. });
  19856. };
  19857. };
  19858. var getValidationHandler = function (editor) {
  19859. return function () {
  19860. var validatorHandler = editor.settings.filepicker_validator_handler;
  19861. return isFunction(validatorHandler) ? Option.some(validatorHandler) : Option.none();
  19862. };
  19863. };
  19864. var getUrlPicker = function (editor) {
  19865. return function (filetype) {
  19866. return getPickerSetting(editor.settings, filetype).map(function (picker) {
  19867. return function (entry) {
  19868. return Future.nu(function (completer) {
  19869. var handler = function (value, meta) {
  19870. if (!isString(value)) {
  19871. throw new Error('Expected value to be string');
  19872. }
  19873. if (meta !== undefined && !isObject(meta)) {
  19874. throw new Error('Expected meta to be a object');
  19875. }
  19876. var r = {
  19877. value: value,
  19878. meta: meta
  19879. };
  19880. completer(r);
  19881. };
  19882. var meta = global$a.extend({ filetype: filetype }, Option.from(entry.meta).getOr({}));
  19883. picker.call(editor, handler, entry.value, meta);
  19884. });
  19885. };
  19886. });
  19887. };
  19888. };
  19889. var UrlInputBackstage = function (editor) {
  19890. return {
  19891. getHistory: getHistory,
  19892. addToHistory: addToHistory,
  19893. getLinkInformation: getLinkInformation(editor),
  19894. getValidationHandler: getValidationHandler(editor),
  19895. getUrlPicker: getUrlPicker(editor)
  19896. };
  19897. };
  19898. var bubbleAlignments = {
  19899. valignCentre: [],
  19900. alignCentre: [],
  19901. alignLeft: [],
  19902. alignRight: [],
  19903. right: [],
  19904. left: [],
  19905. bottom: [],
  19906. top: []
  19907. };
  19908. var init$9 = function (sink, editor, lazyAnchorbar) {
  19909. var backstage = {
  19910. shared: {
  19911. providers: {
  19912. icons: function () {
  19913. return editor.ui.registry.getAll().icons;
  19914. },
  19915. menuItems: function () {
  19916. return editor.ui.registry.getAll().menuItems;
  19917. },
  19918. translate: global$2.translate
  19919. },
  19920. interpreter: function (s) {
  19921. return interpretWithoutForm(s, backstage);
  19922. },
  19923. anchors: {
  19924. toolbar: function () {
  19925. return {
  19926. anchor: 'hotspot',
  19927. hotspot: lazyAnchorbar(),
  19928. bubble: nu$7(-12, 12, bubbleAlignments),
  19929. layouts: {
  19930. onRtl: function () {
  19931. return [southeast$1];
  19932. },
  19933. onLtr: function () {
  19934. return [southwest$1];
  19935. }
  19936. }
  19937. };
  19938. },
  19939. banner: function () {
  19940. return {
  19941. anchor: 'hotspot',
  19942. hotspot: lazyAnchorbar(),
  19943. layouts: {
  19944. onRtl: function () {
  19945. return [south$1];
  19946. },
  19947. onLtr: function () {
  19948. return [south$1];
  19949. }
  19950. }
  19951. };
  19952. },
  19953. cursor: function () {
  19954. return {
  19955. anchor: 'selection',
  19956. root: Element.fromDom(editor.getBody()),
  19957. getSelection: function () {
  19958. var rng = editor.selection.getRng();
  19959. return Option.some(range(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset));
  19960. }
  19961. };
  19962. },
  19963. node: function (element) {
  19964. return {
  19965. anchor: 'node',
  19966. root: Element.fromDom(editor.getBody()),
  19967. node: element
  19968. };
  19969. }
  19970. },
  19971. getSink: function () {
  19972. return Result.value(sink);
  19973. }
  19974. },
  19975. urlinput: UrlInputBackstage(editor),
  19976. styleselect: init$8(editor),
  19977. colorinput: ColorInputBackstage(editor)
  19978. };
  19979. return backstage;
  19980. };
  19981. var global$c = tinymce.util.Tools.resolve('tinymce.util.Delay');
  19982. var showContextToolbarEvent = 'contexttoolbar-show';
  19983. var generate$6 = function (xs, f) {
  19984. var init = {
  19985. len: 0,
  19986. list: []
  19987. };
  19988. var r = foldl(xs, function (b, a) {
  19989. var value = f(a, b.len);
  19990. return value.fold(constant(b), function (v) {
  19991. return {
  19992. len: v.finish(),
  19993. list: b.list.concat([v])
  19994. };
  19995. });
  19996. }, init);
  19997. return r.list;
  19998. };
  19999. var output$1 = Immutable('within', 'extra', 'withinWidth');
  20000. var apportion = function (units, total, len) {
  20001. var parray = generate$6(units, function (unit, current) {
  20002. var width = len(unit);
  20003. return Option.some({
  20004. element: constant(unit),
  20005. start: constant(current),
  20006. finish: constant(current + width),
  20007. width: constant(width)
  20008. });
  20009. });
  20010. var within = filter(parray, function (unit) {
  20011. return unit.finish() <= total;
  20012. });
  20013. var withinWidth = foldr(within, function (acc, el) {
  20014. return acc + el.width();
  20015. }, 0);
  20016. var extra = parray.slice(within.length);
  20017. return {
  20018. within: constant(within),
  20019. extra: constant(extra),
  20020. withinWidth: constant(withinWidth)
  20021. };
  20022. };
  20023. var toUnit = function (parray) {
  20024. return map(parray, function (unit) {
  20025. return unit.element();
  20026. });
  20027. };
  20028. var fitLast = function (within, extra, withinWidth) {
  20029. var fits = toUnit(within.concat(extra));
  20030. return output$1(fits, [], withinWidth);
  20031. };
  20032. var overflow = function (within, extra, overflower, withinWidth) {
  20033. var fits = toUnit(within).concat([overflower]);
  20034. return output$1(fits, toUnit(extra), withinWidth);
  20035. };
  20036. var fitAll = function (within, extra, withinWidth) {
  20037. return output$1(toUnit(within), [], withinWidth);
  20038. };
  20039. var tryFit = function (total, units, len) {
  20040. var divide = apportion(units, total, len);
  20041. return divide.extra().length === 0 ? Option.some(divide) : Option.none();
  20042. };
  20043. var partition$3 = function (total, units, len, overflower) {
  20044. var divide = tryFit(total, units, len).getOrThunk(function () {
  20045. return apportion(units, total - len(overflower), len);
  20046. });
  20047. var within = divide.within();
  20048. var extra = divide.extra();
  20049. var withinWidth = divide.withinWidth();
  20050. if (extra.length === 1 && extra[0].width() <= len(overflower)) {
  20051. return fitLast(within, extra, withinWidth);
  20052. } else if (extra.length >= 1) {
  20053. return overflow(within, extra, overflower, withinWidth);
  20054. } else {
  20055. return fitAll(within, extra, withinWidth);
  20056. }
  20057. };
  20058. var getAnimationRoot = function (component, slideConfig) {
  20059. return slideConfig.getAnimationRoot.fold(function () {
  20060. return component.element();
  20061. }, function (get) {
  20062. return get(component);
  20063. });
  20064. };
  20065. var getDimensionProperty = function (slideConfig) {
  20066. return slideConfig.dimension.property;
  20067. };
  20068. var getDimension = function (slideConfig, elem) {
  20069. return slideConfig.dimension.getDimension(elem);
  20070. };
  20071. var disableTransitions = function (component, slideConfig) {
  20072. var root = getAnimationRoot(component, slideConfig);
  20073. remove$5(root, [
  20074. slideConfig.shrinkingClass,
  20075. slideConfig.growingClass
  20076. ]);
  20077. };
  20078. var setShrunk = function (component, slideConfig) {
  20079. remove$4(component.element(), slideConfig.openClass);
  20080. add$2(component.element(), slideConfig.closedClass);
  20081. set$2(component.element(), getDimensionProperty(slideConfig), '0px');
  20082. reflow(component.element());
  20083. };
  20084. var setGrown = function (component, slideConfig) {
  20085. remove$4(component.element(), slideConfig.closedClass);
  20086. add$2(component.element(), slideConfig.openClass);
  20087. remove$6(component.element(), getDimensionProperty(slideConfig));
  20088. };
  20089. var doImmediateShrink = function (component, slideConfig, slideState, _calculatedSize) {
  20090. slideState.setCollapsed();
  20091. set$2(component.element(), getDimensionProperty(slideConfig), getDimension(slideConfig, component.element()));
  20092. reflow(component.element());
  20093. disableTransitions(component, slideConfig);
  20094. setShrunk(component, slideConfig);
  20095. slideConfig.onStartShrink(component);
  20096. slideConfig.onShrunk(component);
  20097. };
  20098. var doStartShrink = function (component, slideConfig, slideState, calculatedSize) {
  20099. var size = calculatedSize.getOrThunk(function () {
  20100. return getDimension(slideConfig, component.element());
  20101. });
  20102. slideState.setCollapsed();
  20103. set$2(component.element(), getDimensionProperty(slideConfig), size);
  20104. reflow(component.element());
  20105. var root = getAnimationRoot(component, slideConfig);
  20106. remove$4(root, slideConfig.growingClass);
  20107. add$2(root, slideConfig.shrinkingClass);
  20108. setShrunk(component, slideConfig);
  20109. slideConfig.onStartShrink(component);
  20110. };
  20111. var doStartSmartShrink = function (component, slideConfig, slideState) {
  20112. var size = getDimension(slideConfig, component.element());
  20113. var shrinker = size === '0px' ? doImmediateShrink : doStartShrink;
  20114. shrinker(component, slideConfig, slideState, Option.some(size));
  20115. };
  20116. var doStartGrow = function (component, slideConfig, slideState) {
  20117. var root = getAnimationRoot(component, slideConfig);
  20118. var wasShrinking = has$2(root, slideConfig.shrinkingClass);
  20119. var beforeSize = getDimension(slideConfig, component.element());
  20120. setGrown(component, slideConfig);
  20121. var fullSize = getDimension(slideConfig, component.element());
  20122. var startPartialGrow = function () {
  20123. set$2(component.element(), getDimensionProperty(slideConfig), beforeSize);
  20124. reflow(component.element());
  20125. };
  20126. var startCompleteGrow = function () {
  20127. setShrunk(component, slideConfig);
  20128. };
  20129. var setStartSize = wasShrinking ? startPartialGrow : startCompleteGrow;
  20130. setStartSize();
  20131. remove$4(root, slideConfig.shrinkingClass);
  20132. add$2(root, slideConfig.growingClass);
  20133. setGrown(component, slideConfig);
  20134. set$2(component.element(), getDimensionProperty(slideConfig), fullSize);
  20135. slideState.setExpanded();
  20136. slideConfig.onStartGrow(component);
  20137. };
  20138. var refresh = function (component, slideConfig, slideState) {
  20139. if (slideState.isExpanded()) {
  20140. remove$6(component.element(), getDimensionProperty(slideConfig));
  20141. var fullSize = getDimension(slideConfig, component.element());
  20142. set$2(component.element(), getDimensionProperty(slideConfig), fullSize);
  20143. }
  20144. };
  20145. var grow = function (component, slideConfig, slideState) {
  20146. if (!slideState.isExpanded()) {
  20147. doStartGrow(component, slideConfig, slideState);
  20148. }
  20149. };
  20150. var shrink = function (component, slideConfig, slideState) {
  20151. if (slideState.isExpanded()) {
  20152. doStartSmartShrink(component, slideConfig, slideState);
  20153. }
  20154. };
  20155. var immediateShrink = function (component, slideConfig, slideState) {
  20156. if (slideState.isExpanded()) {
  20157. doImmediateShrink(component, slideConfig, slideState, Option.none());
  20158. }
  20159. };
  20160. var hasGrown = function (component, slideConfig, slideState) {
  20161. return slideState.isExpanded();
  20162. };
  20163. var hasShrunk = function (component, slideConfig, slideState) {
  20164. return slideState.isCollapsed();
  20165. };
  20166. var isGrowing = function (component, slideConfig, slideState) {
  20167. var root = getAnimationRoot(component, slideConfig);
  20168. return has$2(root, slideConfig.growingClass) === true;
  20169. };
  20170. var isShrinking = function (component, slideConfig, slideState) {
  20171. var root = getAnimationRoot(component, slideConfig);
  20172. return has$2(root, slideConfig.shrinkingClass) === true;
  20173. };
  20174. var isTransitioning = function (component, slideConfig, slideState) {
  20175. return isGrowing(component, slideConfig, slideState) === true || isShrinking(component, slideConfig, slideState) === true;
  20176. };
  20177. var toggleGrow = function (component, slideConfig, slideState) {
  20178. var f = slideState.isExpanded() ? doStartSmartShrink : doStartGrow;
  20179. f(component, slideConfig, slideState);
  20180. };
  20181. var SlidingApis = /*#__PURE__*/Object.freeze({
  20182. refresh: refresh,
  20183. grow: grow,
  20184. shrink: shrink,
  20185. immediateShrink: immediateShrink,
  20186. hasGrown: hasGrown,
  20187. hasShrunk: hasShrunk,
  20188. isGrowing: isGrowing,
  20189. isShrinking: isShrinking,
  20190. isTransitioning: isTransitioning,
  20191. toggleGrow: toggleGrow,
  20192. disableTransitions: disableTransitions
  20193. });
  20194. var exhibit$6 = function (base, slideConfig) {
  20195. var expanded = slideConfig.expanded;
  20196. return expanded ? nu$6({
  20197. classes: [slideConfig.openClass],
  20198. styles: {}
  20199. }) : nu$6({
  20200. classes: [slideConfig.closedClass],
  20201. styles: wrap$1(slideConfig.dimension.property, '0px')
  20202. });
  20203. };
  20204. var events$d = function (slideConfig, slideState) {
  20205. return derive([runOnSource(transitionend(), function (component, simulatedEvent) {
  20206. var raw = simulatedEvent.event().raw();
  20207. if (raw.propertyName === slideConfig.dimension.property) {
  20208. disableTransitions(component, slideConfig);
  20209. if (slideState.isExpanded()) {
  20210. remove$6(component.element(), slideConfig.dimension.property);
  20211. }
  20212. var notify = slideState.isExpanded() ? slideConfig.onGrown : slideConfig.onShrunk;
  20213. notify(component);
  20214. }
  20215. })]);
  20216. };
  20217. var ActiveSliding = /*#__PURE__*/Object.freeze({
  20218. exhibit: exhibit$6,
  20219. events: events$d
  20220. });
  20221. var SlidingSchema = [
  20222. strict$1('closedClass'),
  20223. strict$1('openClass'),
  20224. strict$1('shrinkingClass'),
  20225. strict$1('growingClass'),
  20226. option('getAnimationRoot'),
  20227. onHandler('onShrunk'),
  20228. onHandler('onStartShrink'),
  20229. onHandler('onGrown'),
  20230. onHandler('onStartGrow'),
  20231. defaulted$1('expanded', false),
  20232. strictOf('dimension', choose$1('property', {
  20233. width: [
  20234. output('property', 'width'),
  20235. output('getDimension', function (elem) {
  20236. return get$7(elem) + 'px';
  20237. })
  20238. ],
  20239. height: [
  20240. output('property', 'height'),
  20241. output('getDimension', function (elem) {
  20242. return get$8(elem) + 'px';
  20243. })
  20244. ]
  20245. }))
  20246. ];
  20247. var init$a = function (spec) {
  20248. var state = Cell(spec.expanded);
  20249. var readState = function () {
  20250. return 'expanded: ' + state.get();
  20251. };
  20252. return nu$5({
  20253. isExpanded: function () {
  20254. return state.get() === true;
  20255. },
  20256. isCollapsed: function () {
  20257. return state.get() === false;
  20258. },
  20259. setCollapsed: curry(state.set, false),
  20260. setExpanded: curry(state.set, true),
  20261. readState: readState
  20262. });
  20263. };
  20264. var SlidingState = /*#__PURE__*/Object.freeze({
  20265. init: init$a
  20266. });
  20267. var Sliding = create$1({
  20268. fields: SlidingSchema,
  20269. name: 'sliding',
  20270. active: ActiveSliding,
  20271. apis: SlidingApis,
  20272. state: SlidingState
  20273. });
  20274. var schema$j = constant([
  20275. defaulted$1('shell', true),
  20276. field$1('toolbarBehaviours', [Replacing])
  20277. ]);
  20278. var enhanceGroups = function (detail) {
  20279. return { behaviours: derive$1([Replacing.config({})]) };
  20280. };
  20281. var parts$7 = constant([optional({
  20282. name: 'groups',
  20283. overrides: enhanceGroups
  20284. })]);
  20285. var factory$9 = function (detail, components, spec, _externals) {
  20286. var setGroups = function (toolbar, groups) {
  20287. getGroupContainer(toolbar).fold(function () {
  20288. domGlobals.console.error('Toolbar was defined to not be a shell, but no groups container was specified in components');
  20289. throw new Error('Toolbar was defined to not be a shell, but no groups container was specified in components');
  20290. }, function (container) {
  20291. Replacing.set(container, groups);
  20292. });
  20293. };
  20294. var getGroupContainer = function (component) {
  20295. return detail.shell ? Option.some(component) : getPart(component, detail, 'groups');
  20296. };
  20297. var extra = detail.shell ? {
  20298. behaviours: [Replacing.config({})],
  20299. components: []
  20300. } : {
  20301. behaviours: [],
  20302. components: components
  20303. };
  20304. return {
  20305. uid: detail.uid,
  20306. dom: detail.dom,
  20307. components: extra.components,
  20308. behaviours: augment(detail.toolbarBehaviours, extra.behaviours),
  20309. apis: { setGroups: setGroups },
  20310. domModification: { attributes: { role: 'group' } }
  20311. };
  20312. };
  20313. var Toolbar = composite$1({
  20314. name: 'Toolbar',
  20315. configFields: schema$j(),
  20316. partFields: parts$7(),
  20317. factory: factory$9,
  20318. apis: {
  20319. setGroups: function (apis, toolbar, groups) {
  20320. apis.setGroups(toolbar, groups);
  20321. }
  20322. }
  20323. });
  20324. var schema$k = constant([
  20325. markers([
  20326. 'closedClass',
  20327. 'openClass',
  20328. 'shrinkingClass',
  20329. 'growingClass',
  20330. 'overflowToggledClass'
  20331. ]),
  20332. field$1('splitToolbarBehaviours', []),
  20333. state$1('builtGroups', function () {
  20334. return Cell([]);
  20335. })
  20336. ]);
  20337. var toolbarSchema = [strict$1('dom')];
  20338. var parts$8 = constant([
  20339. required({
  20340. factory: Toolbar,
  20341. schema: toolbarSchema,
  20342. name: 'primary'
  20343. }),
  20344. required({
  20345. factory: Toolbar,
  20346. schema: toolbarSchema,
  20347. name: 'overflow',
  20348. overrides: function (detail) {
  20349. return {
  20350. toolbarBehaviours: derive$1([Sliding.config({
  20351. dimension: { property: 'height' },
  20352. closedClass: detail.markers.closedClass,
  20353. openClass: detail.markers.openClass,
  20354. shrinkingClass: detail.markers.shrinkingClass,
  20355. growingClass: detail.markers.growingClass
  20356. })])
  20357. };
  20358. }
  20359. }),
  20360. external$1({
  20361. name: 'overflow-button',
  20362. overrides: function (toolbarDetail) {
  20363. return {
  20364. buttonBehaviours: derive$1([Toggling.config({
  20365. toggleClass: toolbarDetail.markers.overflowToggledClass,
  20366. aria: { mode: 'pressed' }
  20367. })])
  20368. };
  20369. }
  20370. }),
  20371. external$1({ name: 'overflow-group' })
  20372. ]);
  20373. var schema$l = constant([
  20374. strict$1('items'),
  20375. markers(['itemSelector']),
  20376. field$1('tgroupBehaviours', [Keying])
  20377. ]);
  20378. var parts$9 = constant([group({
  20379. name: 'items',
  20380. unit: 'item'
  20381. })]);
  20382. var factory$a = function (detail, components, spec, _externals) {
  20383. return {
  20384. 'uid': detail.uid,
  20385. 'dom': detail.dom,
  20386. 'components': components,
  20387. 'behaviours': augment(detail.tgroupBehaviours, [Keying.config({
  20388. mode: 'flow',
  20389. selector: detail.markers.itemSelector
  20390. })]),
  20391. domModification: { attributes: { role: 'toolbar' } }
  20392. };
  20393. };
  20394. var ToolbarGroup = composite$1({
  20395. name: 'ToolbarGroup',
  20396. configFields: schema$l(),
  20397. partFields: parts$9(),
  20398. factory: factory$a
  20399. });
  20400. var setStoredGroups = function (bar, storedGroups) {
  20401. var bGroups = map(storedGroups, function (g) {
  20402. return premade$1(g);
  20403. });
  20404. Toolbar.setGroups(bar, bGroups);
  20405. };
  20406. var refresh$1 = function (toolbar, detail, externals) {
  20407. var ps = getPartsOrDie(toolbar, detail, [
  20408. 'primary',
  20409. 'overflow'
  20410. ]);
  20411. var primary = ps.primary();
  20412. var overflow = ps.overflow();
  20413. set$2(primary.element(), 'visibility', 'hidden');
  20414. Toolbar.setGroups(overflow, []);
  20415. var groups = detail.builtGroups.get();
  20416. var overflowGroupSpec = ToolbarGroup.sketch(__assign({}, externals['overflow-group'](), {
  20417. items: [Button.sketch(__assign({}, externals['overflow-button'](), {
  20418. action: function (button) {
  20419. Sliding.toggleGrow(ps.overflow());
  20420. }
  20421. }))]
  20422. }));
  20423. var overflowGroup = toolbar.getSystem().build(overflowGroupSpec);
  20424. setStoredGroups(primary, groups.concat([overflowGroup]));
  20425. var total = get$7(primary.element());
  20426. var overflows = partition$3(total, groups, function (comp) {
  20427. return get$7(comp.element());
  20428. }, overflowGroup);
  20429. if (overflows.extra().length === 0) {
  20430. Replacing.remove(primary, overflowGroup);
  20431. Toolbar.setGroups(overflow, []);
  20432. } else {
  20433. setStoredGroups(primary, overflows.within());
  20434. setStoredGroups(overflow, overflows.extra());
  20435. }
  20436. remove$6(primary.element(), 'visibility');
  20437. reflow(primary.element());
  20438. Sliding.refresh(overflow);
  20439. getPart(toolbar, detail, 'overflow-button').each(function (moreButton) {
  20440. Toggling.set(moreButton, Sliding.hasGrown(overflow));
  20441. });
  20442. };
  20443. var factory$b = function (detail, components, spec, externals) {
  20444. var doSetGroups = function (toolbar, groups) {
  20445. var built = map(groups, toolbar.getSystem().build);
  20446. detail.builtGroups.set(built);
  20447. };
  20448. var setGroups = function (toolbar, groups) {
  20449. doSetGroups(toolbar, groups);
  20450. refresh$1(toolbar, detail, externals);
  20451. };
  20452. return {
  20453. uid: detail.uid,
  20454. dom: detail.dom,
  20455. components: components,
  20456. behaviours: augment(detail.splitToolbarBehaviours, []),
  20457. apis: {
  20458. setGroups: setGroups,
  20459. refresh: function (toolbar) {
  20460. refresh$1(toolbar, detail, externals);
  20461. }
  20462. },
  20463. domModification: { attributes: { role: 'group' } }
  20464. };
  20465. };
  20466. var SplitToolbar = composite$1({
  20467. name: 'SplitToolbar',
  20468. configFields: schema$k(),
  20469. partFields: parts$8(),
  20470. factory: factory$b,
  20471. apis: {
  20472. setGroups: function (apis, toolbar, groups) {
  20473. apis.setGroups(toolbar, groups);
  20474. },
  20475. refresh: function (apis, toolbar) {
  20476. apis.refresh(toolbar);
  20477. }
  20478. }
  20479. });
  20480. var renderToolbarGroupCommon = function (foo) {
  20481. var attributes = foo.title.fold(function () {
  20482. return {};
  20483. }, function (title) {
  20484. return { attributes: { title: title } };
  20485. });
  20486. return {
  20487. dom: __assign({
  20488. tag: 'div',
  20489. classes: ['tox-toolbar__group']
  20490. }, attributes),
  20491. components: [ToolbarGroup.parts().items({})],
  20492. items: foo.items,
  20493. markers: { itemSelector: '*:not(.tox-split-button) > .tox-tbtn:not([disabled]), .tox-split-button:not([disabled]), .tox-toolbar-nav-js:not([disabled])' },
  20494. tgroupBehaviours: derive$1([
  20495. Tabstopping.config({}),
  20496. Focusing.config({})
  20497. ])
  20498. };
  20499. };
  20500. var renderToolbarGroup = function (foo) {
  20501. return ToolbarGroup.sketch(renderToolbarGroupCommon(foo));
  20502. };
  20503. var getToolbarbehaviours = function (foo, modeName) {
  20504. return derive$1([
  20505. Keying.config({
  20506. mode: modeName,
  20507. onEscape: foo.onEscape,
  20508. selector: '.tox-toolbar__group'
  20509. }),
  20510. config('toolbar-events', [runOnAttached(function (component) {
  20511. var groups = map(foo.initGroups, renderToolbarGroup);
  20512. Toolbar.setGroups(component, groups);
  20513. })])
  20514. ]);
  20515. };
  20516. var renderMoreToolbar = function (foo) {
  20517. var modeName = foo.cyclicKeying ? 'cyclic' : 'acyclic';
  20518. return SplitToolbar.sketch({
  20519. uid: foo.uid,
  20520. dom: {
  20521. tag: 'div',
  20522. classes: ['tox-toolbar-overlord']
  20523. },
  20524. parts: {
  20525. 'overflow-group': renderToolbarGroupCommon({
  20526. title: Option.none(),
  20527. items: []
  20528. }),
  20529. 'overflow-button': renderIconButtonSpec({
  20530. name: 'more',
  20531. icon: Option.some('more-drawer'),
  20532. disabled: false,
  20533. tooltip: Option.some('More...')
  20534. }, Option.none(), foo.backstage.shared.providers)
  20535. },
  20536. components: [
  20537. SplitToolbar.parts().primary({
  20538. dom: {
  20539. tag: 'div',
  20540. classes: ['tox-toolbar__primary']
  20541. }
  20542. }),
  20543. SplitToolbar.parts().overflow({
  20544. dom: {
  20545. tag: 'div',
  20546. classes: ['tox-toolbar__overflow']
  20547. }
  20548. })
  20549. ],
  20550. markers: {
  20551. openClass: 'tox-toolbar__overflow--open',
  20552. closedClass: 'tox-toolbar__overflow--closed',
  20553. growingClass: 'tox-toolbar__overflow--growing',
  20554. shrinkingClass: 'tox-toolbar__overflow--shrinking',
  20555. overflowToggledClass: 'tox-tbtn--enabled'
  20556. },
  20557. splitToolbarBehaviours: getToolbarbehaviours(foo, modeName)
  20558. });
  20559. };
  20560. var renderToolbar = function (foo) {
  20561. var modeName = foo.cyclicKeying ? 'cyclic' : 'acyclic';
  20562. return Toolbar.sketch({
  20563. uid: foo.uid,
  20564. dom: {
  20565. tag: 'div',
  20566. classes: ['tox-toolbar']
  20567. },
  20568. components: [Toolbar.parts().groups({})],
  20569. toolbarBehaviours: getToolbarbehaviours(foo, modeName)
  20570. });
  20571. };
  20572. var baseToolbarButtonFields = [
  20573. defaultedBoolean('disabled', false),
  20574. optionString('tooltip'),
  20575. optionString('icon'),
  20576. optionString('text'),
  20577. defaultedFunction('onSetup', function () {
  20578. return noop;
  20579. })
  20580. ];
  20581. var toolbarButtonSchema = objOf([
  20582. strictString('type'),
  20583. strictFunction('onAction')
  20584. ].concat(baseToolbarButtonFields));
  20585. var createToolbarButton = function (spec) {
  20586. return asRaw('toolbarbutton', toolbarButtonSchema, spec);
  20587. };
  20588. var MenuButtonSchema = objOf([
  20589. strictString('type'),
  20590. optionString('tooltip'),
  20591. optionString('icon'),
  20592. optionString('text'),
  20593. strictFunction('fetch'),
  20594. defaultedFunction('onSetup', function () {
  20595. return noop;
  20596. })
  20597. ]);
  20598. var createMenuButton = function (spec) {
  20599. return asRaw('menubutton', MenuButtonSchema, spec);
  20600. };
  20601. var splitButtonSchema = objOf([
  20602. strictString('type'),
  20603. optionString('tooltip'),
  20604. optionString('icon'),
  20605. optionString('text'),
  20606. optionFunction('select'),
  20607. strictFunction('fetch'),
  20608. defaultedFunction('onSetup', function () {
  20609. return noop;
  20610. }),
  20611. defaultedStringEnum('presets', 'normal', [
  20612. 'normal',
  20613. 'color',
  20614. 'listpreview'
  20615. ]),
  20616. defaulted$1('columns', 1),
  20617. strictFunction('onAction'),
  20618. strictFunction('onItemAction')
  20619. ]);
  20620. var createSplitButton = function (spec) {
  20621. return asRaw('SplitButton', splitButtonSchema, spec);
  20622. };
  20623. var baseToolbarToggleButtonFields = [defaultedBoolean('active', false)].concat(baseToolbarButtonFields);
  20624. var toggleButtonSchema = objOf(baseToolbarToggleButtonFields.concat([
  20625. strictString('type'),
  20626. strictFunction('onAction')
  20627. ]));
  20628. var createToggleButton = function (spec) {
  20629. return asRaw('ToggleButton', toggleButtonSchema, spec);
  20630. };
  20631. var contextBarFields = [
  20632. defaultedFunction('predicate', function () {
  20633. return false;
  20634. }),
  20635. defaultedStringEnum('scope', 'node', [
  20636. 'node',
  20637. 'editor'
  20638. ]),
  20639. defaultedStringEnum('position', 'selection', [
  20640. 'node',
  20641. 'selection',
  20642. 'line'
  20643. ])
  20644. ];
  20645. var contextButtonFields = baseToolbarButtonFields.concat([
  20646. defaulted$1('type', 'contextformbutton'),
  20647. defaulted$1('primary', false),
  20648. strictFunction('onAction'),
  20649. state$1('original', identity)
  20650. ]);
  20651. var contextToggleButtonFields = baseToolbarToggleButtonFields.concat([
  20652. defaulted$1('type', 'contextformbutton'),
  20653. defaulted$1('primary', false),
  20654. strictFunction('onAction'),
  20655. state$1('original', identity)
  20656. ]);
  20657. var launchButtonFields = baseToolbarButtonFields.concat([defaulted$1('type', 'contextformbutton')]);
  20658. var launchToggleButtonFields = baseToolbarToggleButtonFields.concat([defaulted$1('type', 'contextformtogglebutton')]);
  20659. var toggleOrNormal = choose$1('type', {
  20660. contextformbutton: contextButtonFields,
  20661. contextformtogglebutton: contextToggleButtonFields
  20662. });
  20663. var contextFormSchema = objOf([
  20664. defaulted$1('type', 'contextform'),
  20665. defaultedFunction('initValue', function () {
  20666. return '';
  20667. }),
  20668. optionString('label'),
  20669. strictArrayOf('commands', toggleOrNormal),
  20670. optionOf('launch', choose$1('type', {
  20671. contextformbutton: launchButtonFields,
  20672. contextformtogglebutton: launchToggleButtonFields
  20673. }))
  20674. ].concat(contextBarFields));
  20675. var contextToolbarSchema = objOf([
  20676. defaulted$1('type', 'contexttoolbar'),
  20677. strictString('items')
  20678. ].concat(contextBarFields));
  20679. var createContextToolbar = function (spec) {
  20680. return asRaw('ContextToolbar', contextToolbarSchema, spec);
  20681. };
  20682. var createContextForm = function (spec) {
  20683. return asRaw('ContextForm', contextFormSchema, spec);
  20684. };
  20685. var internalToolbarButtonExecute = generate$1('toolbar.button.execute');
  20686. var onToolbarButtonExecute = function (info) {
  20687. return runOnExecute(function (comp, simulatedEvent) {
  20688. runWithApi(info, comp)(function (itemApi) {
  20689. emitWith(comp, internalToolbarButtonExecute, { buttonApi: itemApi });
  20690. info.onAction(itemApi);
  20691. });
  20692. });
  20693. };
  20694. var toolbarButtonEventOrder = {
  20695. 'alloy.execute': [
  20696. 'disabling',
  20697. 'alloy.base.behaviour',
  20698. 'toggling',
  20699. 'toolbar-button-events'
  20700. ]
  20701. };
  20702. var getState$2 = function (component, replaceConfig, reflectState) {
  20703. return reflectState;
  20704. };
  20705. var ReflectingApis = /*#__PURE__*/Object.freeze({
  20706. getState: getState$2
  20707. });
  20708. var events$e = function (reflectingConfig, reflectingState) {
  20709. var update = function (component, data) {
  20710. reflectingConfig.updateState.each(function (updateState) {
  20711. var newState = updateState(component, data);
  20712. reflectingState.set(newState);
  20713. });
  20714. reflectingConfig.renderComponents.each(function (renderComponents) {
  20715. var newComponents = renderComponents(data, reflectingState.get());
  20716. detachChildren(component);
  20717. each(newComponents, function (c) {
  20718. attach(component, component.getSystem().build(c));
  20719. });
  20720. });
  20721. };
  20722. return derive([
  20723. run(receive(), function (component, message) {
  20724. var channel = reflectingConfig.channel;
  20725. if (contains(message.channels(), channel)) {
  20726. update(component, message.data());
  20727. }
  20728. }),
  20729. runOnAttached(function (comp, se) {
  20730. reflectingConfig.initialData.each(function (rawData) {
  20731. update(comp, rawData);
  20732. });
  20733. })
  20734. ]);
  20735. };
  20736. var ActiveReflecting = /*#__PURE__*/Object.freeze({
  20737. events: events$e
  20738. });
  20739. var init$b = function (spec) {
  20740. var cell = Cell(Option.none());
  20741. var set = function (optS) {
  20742. return cell.set(optS);
  20743. };
  20744. var clear = function () {
  20745. return cell.set(Option.none());
  20746. };
  20747. var get = function () {
  20748. return cell.get();
  20749. };
  20750. var readState = function () {
  20751. return cell.get().getOr('none');
  20752. };
  20753. return {
  20754. readState: readState,
  20755. get: get,
  20756. set: set,
  20757. clear: clear
  20758. };
  20759. };
  20760. var ReflectingState = /*#__PURE__*/Object.freeze({
  20761. init: init$b
  20762. });
  20763. var ReflectingSchema = [
  20764. strict$1('channel'),
  20765. option('renderComponents'),
  20766. option('updateState'),
  20767. option('initialData')
  20768. ];
  20769. var Reflecting = create$1({
  20770. fields: ReflectingSchema,
  20771. name: 'reflecting',
  20772. active: ActiveReflecting,
  20773. apis: ReflectingApis,
  20774. state: ReflectingState
  20775. });
  20776. var schema$m = constant([
  20777. strict$1('toggleClass'),
  20778. strict$1('fetch'),
  20779. onStrictHandler('onExecute'),
  20780. defaulted$1('getHotspot', Option.some),
  20781. defaulted$1('layouts', Option.none()),
  20782. onStrictHandler('onItemExecute'),
  20783. option('lazySink'),
  20784. strict$1('dom'),
  20785. onHandler('onOpen'),
  20786. field$1('splitDropdownBehaviours', [
  20787. Coupling,
  20788. Keying,
  20789. Focusing
  20790. ]),
  20791. defaulted$1('matchWidth', false),
  20792. defaulted$1('useMinWidth', false),
  20793. defaulted$1('eventOrder', {}),
  20794. option('role')
  20795. ].concat(sandboxFields()));
  20796. var arrowPart = required({
  20797. factory: Button,
  20798. schema: [strict$1('dom')],
  20799. name: 'arrow',
  20800. defaults: function (detail) {
  20801. return { buttonBehaviours: derive$1([Focusing.revoke()]) };
  20802. },
  20803. overrides: function (detail) {
  20804. return {
  20805. dom: {
  20806. tag: 'span',
  20807. attributes: { role: 'presentation' }
  20808. },
  20809. action: function (arrow) {
  20810. arrow.getSystem().getByUid(detail.uid).each(emitExecute);
  20811. },
  20812. buttonBehaviours: derive$1([Toggling.config({
  20813. toggleOnExecute: false,
  20814. toggleClass: detail.toggleClass
  20815. })])
  20816. };
  20817. }
  20818. });
  20819. var buttonPart = required({
  20820. factory: Button,
  20821. schema: [strict$1('dom')],
  20822. name: 'button',
  20823. defaults: function (detail) {
  20824. return { buttonBehaviours: derive$1([Focusing.revoke()]) };
  20825. },
  20826. overrides: function (detail) {
  20827. return {
  20828. dom: {
  20829. tag: 'span',
  20830. attributes: { role: 'presentation' }
  20831. },
  20832. action: function (btn) {
  20833. btn.getSystem().getByUid(detail.uid).each(function (splitDropdown) {
  20834. detail.onExecute(splitDropdown, btn);
  20835. });
  20836. }
  20837. };
  20838. }
  20839. });
  20840. var parts$a = constant([
  20841. arrowPart,
  20842. buttonPart,
  20843. optional({
  20844. factory: {
  20845. sketch: function (spec) {
  20846. return {
  20847. uid: spec.uid,
  20848. dom: {
  20849. tag: 'span',
  20850. styles: { display: 'none' },
  20851. attributes: { 'aria-hidden': 'true' },
  20852. innerHtml: spec.text
  20853. }
  20854. };
  20855. }
  20856. },
  20857. schema: [strict$1('text')],
  20858. name: 'aria-descriptor'
  20859. }),
  20860. external$1({
  20861. schema: [tieredMenuMarkers()],
  20862. name: 'menu',
  20863. defaults: function (detail) {
  20864. return {
  20865. onExecute: function (tmenu, item) {
  20866. tmenu.getSystem().getByUid(detail.uid).each(function (splitDropdown) {
  20867. detail.onItemExecute(splitDropdown, tmenu, item);
  20868. });
  20869. }
  20870. };
  20871. }
  20872. }),
  20873. partType()
  20874. ]);
  20875. var factory$c = function (detail, components, spec, externals) {
  20876. var switchToMenu = function (sandbox) {
  20877. Composing.getCurrent(sandbox).each(function (current) {
  20878. Highlighting.highlightFirst(current);
  20879. Keying.focusIn(current);
  20880. });
  20881. };
  20882. var action = function (component) {
  20883. var onOpenSync = switchToMenu;
  20884. togglePopup(detail, function (x) {
  20885. return x;
  20886. }, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
  20887. };
  20888. var openMenu = function (comp) {
  20889. action(comp);
  20890. return Option.some(true);
  20891. };
  20892. var executeOnButton = function (comp) {
  20893. var button = getPartOrDie(comp, detail, 'button');
  20894. emitExecute(button);
  20895. return Option.some(true);
  20896. };
  20897. var buttonEvents = merge(derive([runOnAttached(function (component, simulatedEvent) {
  20898. var ariaDescriptor = getPart(component, detail, 'aria-descriptor');
  20899. ariaDescriptor.each(function (descriptor) {
  20900. var descriptorId = generate$1('aria');
  20901. set$1(descriptor.element(), 'id', descriptorId);
  20902. set$1(component.element(), 'aria-describedby', descriptorId);
  20903. });
  20904. })]), events$7(Option.some(action)));
  20905. return {
  20906. uid: detail.uid,
  20907. dom: detail.dom,
  20908. components: components,
  20909. eventOrder: __assign({}, detail.eventOrder, {
  20910. 'alloy.execute': [
  20911. 'disabling',
  20912. 'toggling',
  20913. 'alloy.base.behaviour'
  20914. ]
  20915. }),
  20916. events: buttonEvents,
  20917. behaviours: augment(detail.splitDropdownBehaviours, [
  20918. Coupling.config({
  20919. others: {
  20920. sandbox: function (hotspot) {
  20921. var arrow = getPartOrDie(hotspot, detail, 'arrow');
  20922. var extras = {
  20923. onOpen: function () {
  20924. Toggling.on(arrow);
  20925. Toggling.on(hotspot);
  20926. },
  20927. onClose: function () {
  20928. Toggling.off(arrow);
  20929. Toggling.off(hotspot);
  20930. }
  20931. };
  20932. return makeSandbox(detail, hotspot, extras);
  20933. }
  20934. }
  20935. }),
  20936. Keying.config({
  20937. mode: 'special',
  20938. onSpace: executeOnButton,
  20939. onEnter: executeOnButton,
  20940. onDown: openMenu
  20941. }),
  20942. Focusing.config({}),
  20943. Toggling.config({
  20944. toggleOnExecute: false,
  20945. aria: { mode: 'expanded' }
  20946. })
  20947. ]),
  20948. domModification: {
  20949. attributes: {
  20950. 'role': detail.role.getOr('button'),
  20951. 'aria-haspopup': true
  20952. }
  20953. }
  20954. };
  20955. };
  20956. var SplitDropdown = composite$1({
  20957. name: 'SplitDropdown',
  20958. configFields: schema$m(),
  20959. partFields: parts$a(),
  20960. factory: factory$c
  20961. });
  20962. var getButtonApi = function (component) {
  20963. return {
  20964. isDisabled: function () {
  20965. return Disabling.isDisabled(component);
  20966. },
  20967. setDisabled: function (state) {
  20968. return state ? Disabling.disable(component) : Disabling.enable(component);
  20969. }
  20970. };
  20971. };
  20972. var getToggleApi = function (component) {
  20973. return {
  20974. setActive: function (state) {
  20975. Toggling.set(component, state);
  20976. },
  20977. isActive: function () {
  20978. return Toggling.isOn(component);
  20979. },
  20980. isDisabled: function () {
  20981. return Disabling.isDisabled(component);
  20982. },
  20983. setDisabled: function (state) {
  20984. return state ? Disabling.disable(component) : Disabling.enable(component);
  20985. }
  20986. };
  20987. };
  20988. var getTooltipAttributes = function (tooltip, providersBackstage) {
  20989. return tooltip.map(function (tooltip) {
  20990. return {
  20991. 'aria-label': providersBackstage.translate(tooltip),
  20992. 'title': providersBackstage.translate(tooltip)
  20993. };
  20994. }).getOr({});
  20995. };
  20996. var focusButtonEvent = generate$1('focus-button');
  20997. var renderCommonStructure = function (icon, text, tooltip, receiver, behaviours, providersBackstage) {
  20998. var _a;
  20999. return {
  21000. dom: {
  21001. tag: 'button',
  21002. classes: ['tox-tbtn'].concat(text.isSome() ? ['tox-tbtn--select'] : []),
  21003. attributes: getTooltipAttributes(tooltip, providersBackstage)
  21004. },
  21005. components: componentRenderPipeline([
  21006. icon.map(function (iconName) {
  21007. return renderIconFromPack(iconName, providersBackstage.icons);
  21008. }),
  21009. text.map(function (text) {
  21010. return renderLabel$1(text, 'tox-tbtn', providersBackstage);
  21011. })
  21012. ]),
  21013. eventOrder: (_a = {}, _a[mousedown()] = [
  21014. 'focusing',
  21015. 'alloy.base.behaviour',
  21016. 'common-button-display-events'
  21017. ], _a),
  21018. buttonBehaviours: derive$1([config('common-button-display-events', [run(mousedown(), function (button, se) {
  21019. se.event().prevent();
  21020. emit(button, focusButtonEvent);
  21021. })])].concat(receiver.map(function (r) {
  21022. return Reflecting.config({
  21023. channel: r,
  21024. initialData: {
  21025. icon: icon,
  21026. text: text
  21027. },
  21028. renderComponents: function (data, _state) {
  21029. return componentRenderPipeline([
  21030. data.icon.map(function (iconName) {
  21031. return renderIconFromPack(iconName, providersBackstage.icons);
  21032. }),
  21033. data.text.map(function (text) {
  21034. return renderLabel$1(text, 'tox-tbtn', providersBackstage);
  21035. })
  21036. ]);
  21037. }
  21038. });
  21039. }).toArray()).concat(behaviours.getOr([])))
  21040. };
  21041. };
  21042. var renderCommonToolbarButton = function (spec, specialisation, providersBackstage) {
  21043. var editorOffCell = Cell(noop);
  21044. var structure = renderCommonStructure(spec.icon, spec.text, spec.tooltip, Option.none(), Option.none(), providersBackstage);
  21045. return Button.sketch({
  21046. dom: structure.dom,
  21047. components: structure.components,
  21048. eventOrder: toolbarButtonEventOrder,
  21049. buttonBehaviours: derive$1([
  21050. config('toolbar-button-events', [
  21051. onToolbarButtonExecute({
  21052. onAction: spec.onAction,
  21053. getApi: specialisation.getApi
  21054. }),
  21055. onControlAttached(specialisation, editorOffCell),
  21056. onControlDetached(specialisation, editorOffCell)
  21057. ]),
  21058. DisablingConfigs.button(spec.disabled)
  21059. ].concat(specialisation.toolbarButtonBehaviours))
  21060. });
  21061. };
  21062. var renderToolbarButton = function (spec, providersBackstage) {
  21063. return renderToolbarButtonWith(spec, providersBackstage, []);
  21064. };
  21065. var renderToolbarButtonWith = function (spec, providersBackstage, bonusEvents) {
  21066. return renderCommonToolbarButton(spec, {
  21067. toolbarButtonBehaviours: [].concat(bonusEvents.length > 0 ? [config('toolbarButtonWith', bonusEvents)] : []),
  21068. getApi: getButtonApi,
  21069. onSetup: spec.onSetup
  21070. }, providersBackstage);
  21071. };
  21072. var renderToolbarToggleButton = function (spec, providersBackstage) {
  21073. return renderToolbarToggleButtonWith(spec, providersBackstage, []);
  21074. };
  21075. var renderToolbarToggleButtonWith = function (spec, providersBackstage, bonusEvents) {
  21076. return deepMerge(renderCommonToolbarButton(spec, {
  21077. toolbarButtonBehaviours: [
  21078. Replacing.config({}),
  21079. Toggling.config({
  21080. toggleClass: 'tox-tbtn--enabled',
  21081. aria: { mode: 'pressed' },
  21082. toggleOnExecute: false
  21083. })
  21084. ].concat(bonusEvents.length > 0 ? [config('toolbarToggleButtonWith', bonusEvents)] : []),
  21085. getApi: getToggleApi,
  21086. onSetup: spec.onSetup
  21087. }, providersBackstage));
  21088. };
  21089. var fetchChoices = function (getApi, spec, providersBackstage) {
  21090. return function (comp) {
  21091. return Future.nu(function (callback) {
  21092. return spec.fetch(callback);
  21093. }).map(function (items) {
  21094. return Option.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$1('menu-value'), items, function (value) {
  21095. spec.onItemAction(getApi(comp), value);
  21096. }, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, spec.select.getOr(function () {
  21097. return false;
  21098. }), providersBackstage), {
  21099. movement: deriveMenuMovement(spec.columns, spec.presets),
  21100. menuBehaviours: SimpleBehaviours.unnamedEvents(spec.columns !== 'auto' ? [] : [runOnAttached(function (comp, se) {
  21101. detectSize(comp, 4, classForPreset(spec.presets)).each(function (_a) {
  21102. var numRows = _a.numRows, numColumns = _a.numColumns;
  21103. Keying.setGridSize(comp, numRows, numColumns);
  21104. });
  21105. })])
  21106. })));
  21107. });
  21108. };
  21109. };
  21110. var renderSplitButton = function (spec, sharedBackstage) {
  21111. var _a;
  21112. var displayChannel = generate$1('channel-update-split-dropdown-display');
  21113. var getApi = function (comp) {
  21114. return {
  21115. isDisabled: function () {
  21116. return Disabling.isDisabled(comp);
  21117. },
  21118. setDisabled: function (state) {
  21119. return state ? Disabling.disable(comp) : Disabling.enable(comp);
  21120. },
  21121. setIconFill: function (id, value) {
  21122. descendant$1(comp.element(), 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function (underlinePath) {
  21123. set$1(underlinePath, 'fill', value);
  21124. });
  21125. },
  21126. setIconStroke: function (id, value) {
  21127. descendant$1(comp.element(), 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function (underlinePath) {
  21128. set$1(underlinePath, 'stroke', value);
  21129. });
  21130. },
  21131. setActive: function (state) {
  21132. set$1(comp.element(), 'aria-pressed', state);
  21133. descendant$1(comp.element(), 'span').each(function (button) {
  21134. comp.getSystem().getByDom(button).each(function (buttonComp) {
  21135. return Toggling.set(buttonComp, state);
  21136. });
  21137. });
  21138. },
  21139. isActive: function () {
  21140. return descendant$1(comp.element(), 'span').exists(function (button) {
  21141. return comp.getSystem().getByDom(button).exists(Toggling.isOn);
  21142. });
  21143. }
  21144. };
  21145. };
  21146. var editorOffCell = Cell(noop);
  21147. var specialisation = {
  21148. getApi: getApi,
  21149. onSetup: spec.onSetup
  21150. };
  21151. return SplitDropdown.sketch({
  21152. dom: {
  21153. tag: 'div',
  21154. classes: ['tox-split-button'],
  21155. attributes: merge({ 'aria-pressed': false }, getTooltipAttributes(spec.tooltip, sharedBackstage.providers))
  21156. },
  21157. onExecute: function (button) {
  21158. spec.onAction(getApi(button));
  21159. },
  21160. onItemExecute: function (a, b, c) {
  21161. },
  21162. splitDropdownBehaviours: derive$1([
  21163. DisablingConfigs.splitButton(false),
  21164. config('split-dropdown-events', [
  21165. run(focusButtonEvent, Focusing.focus),
  21166. onControlAttached(specialisation, editorOffCell),
  21167. onControlDetached(specialisation, editorOffCell)
  21168. ])
  21169. ]),
  21170. eventOrder: (_a = {}, _a[attachedToDom()] = [
  21171. 'alloy.base.behaviour',
  21172. 'split-dropdown-events'
  21173. ], _a),
  21174. toggleClass: 'tox-tbtn--enabled',
  21175. lazySink: sharedBackstage.getSink,
  21176. fetch: fetchChoices(getApi, spec, sharedBackstage.providers),
  21177. parts: { menu: part(false, spec.columns, spec.presets) },
  21178. components: [
  21179. SplitDropdown.parts().button(renderCommonStructure(spec.icon, spec.text, Option.none(), Option.some(displayChannel), Option.some([Toggling.config({
  21180. toggleClass: 'tox-tbtn--enabled',
  21181. toggleOnExecute: false
  21182. })]), sharedBackstage.providers)),
  21183. SplitDropdown.parts().arrow({
  21184. dom: {
  21185. tag: 'button',
  21186. classes: [
  21187. 'tox-tbtn',
  21188. 'tox-split-button__chevron'
  21189. ],
  21190. innerHtml: get$c('chevron-down', sharedBackstage.providers.icons)
  21191. }
  21192. }),
  21193. SplitDropdown.parts()['aria-descriptor']({ text: sharedBackstage.providers.translate('To open the popup, press Shift+Enter') })
  21194. ]
  21195. });
  21196. };
  21197. var getFormApi = function (input) {
  21198. return {
  21199. hide: function () {
  21200. return emit(input, sandboxClose());
  21201. },
  21202. getValue: function () {
  21203. return Representing.getValue(input);
  21204. }
  21205. };
  21206. };
  21207. var runOnExecute$1 = function (memInput, original) {
  21208. return run(internalToolbarButtonExecute, function (comp, se) {
  21209. var input = memInput.get(comp);
  21210. var formApi = getFormApi(input);
  21211. original.onAction(formApi, se.event().buttonApi());
  21212. });
  21213. };
  21214. var renderContextButton = function (memInput, button, extras) {
  21215. var _a = button.original, primary = _a.primary, rest = __rest(_a, ['primary']);
  21216. var bridged = getOrDie$1(createToolbarButton(__assign({}, rest, {
  21217. type: 'button',
  21218. onAction: function () {
  21219. }
  21220. })));
  21221. return renderToolbarButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute$1(memInput, button)]);
  21222. };
  21223. var renderContextToggleButton = function (memInput, button, extras) {
  21224. var _a = button.original, primary = _a.primary, rest = __rest(_a, ['primary']);
  21225. var bridged = getOrDie$1(createToggleButton(__assign({}, rest, {
  21226. type: 'togglebutton',
  21227. onAction: function () {
  21228. }
  21229. })));
  21230. return renderToolbarToggleButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute$1(memInput, button)]);
  21231. };
  21232. var generateOne$1 = function (memInput, button, providersBackstage) {
  21233. var extras = { backstage: { shared: { providers: providersBackstage } } };
  21234. if (button.type === 'contextformtogglebutton') {
  21235. return renderContextToggleButton(memInput, button, extras);
  21236. } else {
  21237. return renderContextButton(memInput, button, extras);
  21238. }
  21239. };
  21240. var generate$7 = function (memInput, buttons, providersBackstage) {
  21241. var mementos = map(buttons, function (button) {
  21242. return record(generateOne$1(memInput, button, providersBackstage));
  21243. });
  21244. var asSpecs = function () {
  21245. return map(mementos, function (mem) {
  21246. return mem.asSpec();
  21247. });
  21248. };
  21249. var findPrimary = function (compInSystem) {
  21250. return findMap(buttons, function (button, i) {
  21251. if (button.primary) {
  21252. return Option.from(mementos[i]).bind(function (mem) {
  21253. return mem.getOpt(compInSystem);
  21254. }).filter(not(Disabling.isDisabled));
  21255. } else {
  21256. return Option.none();
  21257. }
  21258. });
  21259. };
  21260. return {
  21261. asSpecs: asSpecs,
  21262. findPrimary: findPrimary
  21263. };
  21264. };
  21265. var renderContextForm = function (ctx, backstage) {
  21266. var inputAttributes = ctx.label.fold(function () {
  21267. return {};
  21268. }, function (label) {
  21269. return { 'aria-label': label };
  21270. });
  21271. var memInput = record(Input.sketch({
  21272. inputClasses: [
  21273. 'tox-toolbar-textfield',
  21274. 'tox-toolbar-nav-js'
  21275. ],
  21276. data: ctx.initValue(),
  21277. inputAttributes: inputAttributes,
  21278. selectOnFocus: true,
  21279. inputBehaviours: derive$1([Keying.config({
  21280. mode: 'special',
  21281. onEnter: function (input) {
  21282. return commands.findPrimary(input).map(function (primary) {
  21283. emitExecute(primary);
  21284. return true;
  21285. });
  21286. },
  21287. onLeft: function (comp, se) {
  21288. se.cut();
  21289. return Option.none();
  21290. },
  21291. onRight: function (comp, se) {
  21292. se.cut();
  21293. return Option.none();
  21294. }
  21295. })])
  21296. }));
  21297. var commands = generate$7(memInput, ctx.commands, backstage.shared.providers);
  21298. return renderToolbar({
  21299. uid: generate$1('context-toolbar'),
  21300. initGroups: [
  21301. {
  21302. title: Option.none(),
  21303. items: [memInput.asSpec()]
  21304. },
  21305. {
  21306. title: Option.none(),
  21307. items: commands.asSpecs()
  21308. }
  21309. ],
  21310. onEscape: Option.none,
  21311. cyclicKeying: true,
  21312. backstage: backstage
  21313. });
  21314. };
  21315. var ContextForm = { renderContextForm: renderContextForm };
  21316. var forwardSlideEvent = generate$1('forward-slide');
  21317. var backSlideEvent = generate$1('backward-slide');
  21318. var changeSlideEvent = generate$1('change-slide-event');
  21319. var resizingClass = 'tox-pop--resizing';
  21320. var renderContextToolbar = function (spec) {
  21321. var stack = Cell([]);
  21322. return InlineView.sketch({
  21323. dom: {
  21324. tag: 'div',
  21325. classes: ['tox-pop']
  21326. },
  21327. fireDismissalEventInstead: { event: 'doNotDismissYet' },
  21328. onShow: function (comp) {
  21329. stack.set([]);
  21330. InlineView.getContent(comp).each(function (c) {
  21331. remove$6(c.element(), 'visibility');
  21332. });
  21333. remove$4(comp.element(), resizingClass);
  21334. remove$6(comp.element(), 'width');
  21335. },
  21336. inlineBehaviours: derive$1([
  21337. config('context-toolbar-events', [
  21338. runOnSource(transitionend(), function (comp, se) {
  21339. InlineView.getContent(comp).each(function (c) {
  21340. });
  21341. remove$4(comp.element(), resizingClass);
  21342. remove$6(comp.element(), 'width');
  21343. }),
  21344. run(changeSlideEvent, function (comp, se) {
  21345. remove$6(comp.element(), 'width');
  21346. var currentWidth = get$7(comp.element());
  21347. InlineView.setContent(comp, se.event().contents());
  21348. add$2(comp.element(), resizingClass);
  21349. var newWidth = get$7(comp.element());
  21350. set$2(comp.element(), 'width', currentWidth + 'px');
  21351. InlineView.getContent(comp).each(function (newContents) {
  21352. se.event().focus().bind(function (f) {
  21353. focus$1(f);
  21354. return search$1(comp.element());
  21355. }).orThunk(function () {
  21356. Keying.focusIn(newContents);
  21357. return active();
  21358. });
  21359. });
  21360. setTimeout(function () {
  21361. set$2(comp.element(), 'width', newWidth + 'px');
  21362. }, 0);
  21363. }),
  21364. run(forwardSlideEvent, function (comp, se) {
  21365. InlineView.getContent(comp).each(function (oldContents) {
  21366. stack.set(stack.get().concat([{
  21367. bar: oldContents,
  21368. focus: active()
  21369. }]));
  21370. });
  21371. emitWith(comp, changeSlideEvent, {
  21372. contents: se.event().forwardContents(),
  21373. focus: Option.none()
  21374. });
  21375. }),
  21376. run(backSlideEvent, function (comp, se) {
  21377. last(stack.get()).each(function (last) {
  21378. stack.set(stack.get().slice(0, stack.get().length - 1));
  21379. emitWith(comp, changeSlideEvent, {
  21380. contents: premade$1(last.bar),
  21381. focus: last.focus
  21382. });
  21383. });
  21384. })
  21385. ]),
  21386. Keying.config({
  21387. mode: 'special',
  21388. onEscape: function (comp) {
  21389. return last(stack.get()).fold(function () {
  21390. return spec.onEscape();
  21391. }, function (_) {
  21392. emit(comp, backSlideEvent);
  21393. return Option.some(true);
  21394. });
  21395. }
  21396. })
  21397. ]),
  21398. lazySink: function () {
  21399. return Result.value(spec.sink);
  21400. }
  21401. });
  21402. };
  21403. var ancestor$2 = function (scope, transform, isRoot) {
  21404. var element = scope.dom();
  21405. var stop = isFunction(isRoot) ? isRoot : constant(false);
  21406. while (element.parentNode) {
  21407. element = element.parentNode;
  21408. var el = Element.fromDom(element);
  21409. var transformed = transform(el);
  21410. if (transformed.isSome()) {
  21411. return transformed;
  21412. } else if (stop(el)) {
  21413. break;
  21414. }
  21415. }
  21416. return Option.none();
  21417. };
  21418. var matchTargetWith = function (elem, toolbars) {
  21419. return findMap(toolbars, function (toolbarApi) {
  21420. return toolbarApi.predicate(elem.dom()) ? Option.some({
  21421. toolbarApi: toolbarApi,
  21422. elem: elem
  21423. }) : Option.none();
  21424. });
  21425. };
  21426. var lookup$1 = function (scopes, editor) {
  21427. var isRoot = function (elem) {
  21428. return elem.dom() === editor.getBody();
  21429. };
  21430. var startNode = Element.fromDom(editor.selection.getNode());
  21431. return matchTargetWith(startNode, scopes.inNodeScope).orThunk(function () {
  21432. return matchTargetWith(startNode, scopes.inEditorScope).orThunk(function () {
  21433. return ancestor$2(startNode, function (elem) {
  21434. return matchTargetWith(elem, scopes.inNodeScope);
  21435. }, isRoot);
  21436. });
  21437. });
  21438. };
  21439. var ToolbarLookup = { lookup: lookup$1 };
  21440. var categorise = function (contextToolbars, navigate) {
  21441. var forms = {};
  21442. var inNodeScope = [];
  21443. var inEditorScope = [];
  21444. var formNavigators = {};
  21445. var lookupTable = {};
  21446. var registerForm = function (key, toolbarApi) {
  21447. var contextForm = getOrDie$1(createContextForm(toolbarApi));
  21448. forms[key] = contextForm;
  21449. contextForm.launch.map(function (launch) {
  21450. formNavigators['form:' + key + ''] = __assign({}, toolbarApi.launch, {
  21451. type: launch.type === 'contextformtogglebutton' ? 'togglebutton' : 'button',
  21452. onAction: function () {
  21453. navigate(contextForm);
  21454. }
  21455. });
  21456. });
  21457. if (contextForm.scope === 'editor') {
  21458. inEditorScope.push(contextForm);
  21459. } else {
  21460. inNodeScope.push(contextForm);
  21461. }
  21462. lookupTable[key] = contextForm;
  21463. };
  21464. var registerToolbar = function (key, toolbarApi) {
  21465. createContextToolbar(toolbarApi).each(function (contextToolbar) {
  21466. if (toolbarApi.scope === 'editor') {
  21467. inEditorScope.push(contextToolbar);
  21468. } else {
  21469. inNodeScope.push(contextToolbar);
  21470. }
  21471. lookupTable[key] = contextToolbar;
  21472. });
  21473. };
  21474. var keys$1 = keys(contextToolbars);
  21475. each(keys$1, function (key) {
  21476. var toolbarApi = contextToolbars[key];
  21477. if (toolbarApi.type === 'contextform') {
  21478. registerForm(key, toolbarApi);
  21479. } else if (toolbarApi.type === 'contexttoolbar') {
  21480. registerToolbar(key, toolbarApi);
  21481. }
  21482. });
  21483. return {
  21484. forms: forms,
  21485. inNodeScope: inNodeScope,
  21486. inEditorScope: inEditorScope,
  21487. lookupTable: lookupTable,
  21488. formNavigators: formNavigators
  21489. };
  21490. };
  21491. var ToolbarScopes = { categorise: categorise };
  21492. var updateMenuText = generate$1('update-menu-text');
  21493. var updateMenuIcon = generate$1('update-menu-icon');
  21494. var renderCommonDropdown = function (spec, prefix, sharedBackstage) {
  21495. var optMemDisplayText = spec.text.map(function (text) {
  21496. return record(renderLabel$1(text, prefix, sharedBackstage.providers));
  21497. });
  21498. var optMemDisplayIcon = spec.icon.map(function (iconName) {
  21499. return record(renderReplacableIconFromPack(iconName, sharedBackstage.providers.icons));
  21500. });
  21501. var onLeftOrRightInMenu = function (comp, se) {
  21502. var dropdown = Representing.getValue(comp);
  21503. Focusing.focus(dropdown);
  21504. emitWith(dropdown, 'keydown', { raw: se.event().raw() });
  21505. Dropdown.close(dropdown);
  21506. return Option.some(true);
  21507. };
  21508. var role = spec.role.fold(function () {
  21509. return {};
  21510. }, function (role) {
  21511. return { role: role };
  21512. });
  21513. var tooltipAttributes = spec.tooltip.fold(function () {
  21514. return {};
  21515. }, function (tooltip) {
  21516. var translatedTooltip = sharedBackstage.providers.translate(tooltip);
  21517. return {
  21518. 'title': translatedTooltip,
  21519. 'aria-label': translatedTooltip
  21520. };
  21521. });
  21522. var memDropdown = record(Dropdown.sketch(__assign({}, role, {
  21523. dom: {
  21524. tag: 'button',
  21525. classes: [
  21526. prefix,
  21527. prefix + '--select'
  21528. ].concat(map(spec.classes, function (c) {
  21529. return prefix + '--' + c;
  21530. })),
  21531. attributes: __assign({}, tooltipAttributes)
  21532. },
  21533. components: componentRenderPipeline([
  21534. optMemDisplayIcon.map(function (mem) {
  21535. return mem.asSpec();
  21536. }),
  21537. optMemDisplayText.map(function (mem) {
  21538. return mem.asSpec();
  21539. }),
  21540. Option.some({
  21541. dom: {
  21542. tag: 'div',
  21543. classes: [prefix + '__select-chevron'],
  21544. innerHtml: get$c('chevron-down', sharedBackstage.providers.icons)
  21545. }
  21546. })
  21547. ]),
  21548. matchWidth: true,
  21549. useMinWidth: true,
  21550. dropdownBehaviours: derive$1([
  21551. DisablingConfigs.button(spec.disabled),
  21552. Unselecting.config({}),
  21553. Replacing.config({}),
  21554. config('menubutton-update-display-text', [
  21555. runOnAttached(spec.onAttach),
  21556. runOnDetached(spec.onDetach),
  21557. run(updateMenuText, function (comp, se) {
  21558. optMemDisplayText.bind(function (mem) {
  21559. return mem.getOpt(comp);
  21560. }).each(function (displayText) {
  21561. Replacing.set(displayText, [text(sharedBackstage.providers.translate(se.event().text()))]);
  21562. });
  21563. }),
  21564. run(updateMenuIcon, function (comp, se) {
  21565. optMemDisplayIcon.bind(function (mem) {
  21566. return mem.getOpt(comp);
  21567. }).each(function (displayIcon) {
  21568. Replacing.set(displayIcon, [renderReplacableIconFromPack(se.event().icon(), sharedBackstage.providers.icons)]);
  21569. });
  21570. })
  21571. ])
  21572. ]),
  21573. eventOrder: deepMerge(toolbarButtonEventOrder, {
  21574. mousedown: [
  21575. 'focusing',
  21576. 'alloy.base.behaviour',
  21577. 'item-type-events',
  21578. 'normal-dropdown-events'
  21579. ]
  21580. }),
  21581. sandboxBehaviours: derive$1([Keying.config({
  21582. mode: 'special',
  21583. onLeft: onLeftOrRightInMenu,
  21584. onRight: onLeftOrRightInMenu
  21585. })]),
  21586. lazySink: sharedBackstage.getSink,
  21587. toggleClass: prefix + '--active',
  21588. parts: { menu: part(false, spec.columns, spec.presets) },
  21589. fetch: function () {
  21590. return Future.nu(spec.fetch);
  21591. }
  21592. })));
  21593. return memDropdown.asSpec();
  21594. };
  21595. var generateSelectItems = function (editor, backstage, spec) {
  21596. var generateItem = function (rawItem, response, disabled) {
  21597. var translatedText = backstage.shared.providers.translate(rawItem.title);
  21598. if (rawItem.type === 'separator') {
  21599. return {
  21600. type: 'separator',
  21601. text: translatedText
  21602. };
  21603. } else if (rawItem.type === 'submenu') {
  21604. return {
  21605. type: 'nestedmenuitem',
  21606. text: translatedText,
  21607. disabled: disabled,
  21608. getSubmenuItems: function () {
  21609. return bind(rawItem.getStyleItems(), function (si) {
  21610. return validate(si, response);
  21611. });
  21612. }
  21613. };
  21614. } else {
  21615. return __assign({
  21616. type: 'togglemenuitem',
  21617. text: translatedText,
  21618. active: rawItem.isSelected(),
  21619. disabled: disabled,
  21620. onAction: spec.onAction(rawItem)
  21621. }, rawItem.getStylePreview().fold(function () {
  21622. return {};
  21623. }, function (preview) {
  21624. return { meta: { style: preview } };
  21625. }));
  21626. }
  21627. };
  21628. var validate = function (item, response) {
  21629. var invalid = item.type === 'formatter' && spec.isInvalid(item);
  21630. if (response === 0) {
  21631. return invalid ? [] : [generateItem(item, response, false)];
  21632. } else {
  21633. return [generateItem(item, response, invalid)];
  21634. }
  21635. };
  21636. var validateItems = function (preItems) {
  21637. var response = spec.shouldHide ? 0 : 1;
  21638. return bind(preItems, function (item) {
  21639. return validate(item, response);
  21640. });
  21641. };
  21642. var getFetch = function (backstage, getStyleItems) {
  21643. return function (callback) {
  21644. var preItems = getStyleItems();
  21645. var items = validateItems(preItems);
  21646. var menu = build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage.shared.providers);
  21647. callback(menu);
  21648. };
  21649. };
  21650. return {
  21651. validateItems: validateItems,
  21652. getFetch: getFetch
  21653. };
  21654. };
  21655. var createMenuItems = function (editor, backstage, dataset, spec) {
  21656. var getStyleItems = dataset.type === 'basic' ? function () {
  21657. return map(dataset.data, function (d) {
  21658. return processBasic(d, spec.isSelectedFor, spec.getPreviewFor);
  21659. });
  21660. } : dataset.getData;
  21661. return {
  21662. items: generateSelectItems(editor, backstage, spec),
  21663. getStyleItems: getStyleItems
  21664. };
  21665. };
  21666. var createSelectButton = function (editor, backstage, dataset, spec) {
  21667. var _a = createMenuItems(editor, backstage, dataset, spec), items = _a.items, getStyleItems = _a.getStyleItems;
  21668. return renderCommonDropdown({
  21669. text: spec.icon.isSome() ? Option.none() : Option.some(''),
  21670. icon: spec.icon,
  21671. tooltip: Option.from(spec.tooltip),
  21672. role: Option.none(),
  21673. fetch: items.getFetch(backstage, getStyleItems),
  21674. onAttach: spec.nodeChangeHandler.map(function (f) {
  21675. return function (comp) {
  21676. return editor.on('nodeChange', f(comp));
  21677. };
  21678. }).getOr(function () {
  21679. }),
  21680. onDetach: spec.nodeChangeHandler.map(function (f) {
  21681. return function (comp) {
  21682. return editor.off('nodeChange', f(comp));
  21683. };
  21684. }).getOr(function () {
  21685. }),
  21686. columns: 1,
  21687. presets: 'normal',
  21688. classes: spec.icon.isSome() ? [] : ['bespoke']
  21689. }, 'tox-tbtn', backstage.shared);
  21690. };
  21691. var process = function (rawFormats) {
  21692. return map(rawFormats, function (item) {
  21693. var title = item, format = item;
  21694. var values = item.split('=');
  21695. if (values.length > 1) {
  21696. title = values[0];
  21697. format = values[1];
  21698. }
  21699. return {
  21700. title: title,
  21701. format: format
  21702. };
  21703. });
  21704. };
  21705. var buildBasicStaticDataset = function (data) {
  21706. return {
  21707. type: 'basic',
  21708. data: data
  21709. };
  21710. };
  21711. var Delimiter;
  21712. (function (Delimiter) {
  21713. Delimiter[Delimiter['SemiColon'] = 0] = 'SemiColon';
  21714. Delimiter[Delimiter['Space'] = 1] = 'Space';
  21715. }(Delimiter || (Delimiter = {})));
  21716. var split = function (rawFormats, delimiter) {
  21717. if (delimiter === Delimiter.SemiColon) {
  21718. return rawFormats.replace(/;$/, '').split(';');
  21719. } else {
  21720. return rawFormats.split(' ');
  21721. }
  21722. };
  21723. var buildBasicSettingsDataset = function (editor, settingName, defaults, delimiter) {
  21724. var rawFormats = readOptFrom$1(editor.settings, settingName).getOr(defaults);
  21725. var data = process(split(rawFormats, delimiter));
  21726. return {
  21727. type: 'basic',
  21728. data: data
  21729. };
  21730. };
  21731. var alignMenuItems = [
  21732. {
  21733. title: 'Left',
  21734. icon: 'align-left',
  21735. format: 'alignleft'
  21736. },
  21737. {
  21738. title: 'Center',
  21739. icon: 'align-center',
  21740. format: 'aligncenter'
  21741. },
  21742. {
  21743. title: 'Right',
  21744. icon: 'align-right',
  21745. format: 'alignright'
  21746. },
  21747. {
  21748. title: 'Justify',
  21749. icon: 'align-justify',
  21750. format: 'alignjustify'
  21751. }
  21752. ];
  21753. var getSpec = function (editor) {
  21754. var getMatchingValue = function () {
  21755. return find(alignMenuItems, function (item) {
  21756. return editor.formatter.match(item.format);
  21757. });
  21758. };
  21759. var isSelectedFor = function (format) {
  21760. return function () {
  21761. return editor.formatter.match(format);
  21762. };
  21763. };
  21764. var getPreviewFor = function (format) {
  21765. return function () {
  21766. return Option.none();
  21767. };
  21768. };
  21769. var onAction = function (rawItem) {
  21770. return function () {
  21771. editor.undoManager.transact(function () {
  21772. editor.focus();
  21773. if (editor.formatter.match(rawItem.format)) {
  21774. editor.formatter.remove(rawItem.format);
  21775. } else {
  21776. editor.formatter.apply(rawItem.format);
  21777. }
  21778. });
  21779. };
  21780. };
  21781. var nodeChangeHandler = Option.some(function (comp) {
  21782. return function () {
  21783. var match = getMatchingValue();
  21784. var alignment = match.fold(function () {
  21785. return 'left';
  21786. }, function (item) {
  21787. return item.title.toLowerCase();
  21788. });
  21789. emitWith(comp, updateMenuIcon, { icon: 'align-' + alignment });
  21790. };
  21791. });
  21792. var dataset = buildBasicStaticDataset(alignMenuItems);
  21793. return {
  21794. tooltip: 'Align',
  21795. icon: Option.some('align-left'),
  21796. isSelectedFor: isSelectedFor,
  21797. getPreviewFor: getPreviewFor,
  21798. onAction: onAction,
  21799. nodeChangeHandler: nodeChangeHandler,
  21800. dataset: dataset,
  21801. shouldHide: false,
  21802. isInvalid: function (item) {
  21803. return !editor.formatter.canApply(item.format);
  21804. }
  21805. };
  21806. };
  21807. var createAlignSelect = function (editor, backstage) {
  21808. var spec = getSpec(editor);
  21809. return createSelectButton(editor, backstage, spec.dataset, spec);
  21810. };
  21811. var alignSelectMenu = function (editor, backstage) {
  21812. var spec = getSpec(editor);
  21813. var menuItems = createMenuItems(editor, backstage, spec.dataset, spec);
  21814. editor.ui.registry.addNestedMenuItem('align', {
  21815. text: backstage.shared.providers.translate('Align'),
  21816. getSubmenuItems: function () {
  21817. return menuItems.items.validateItems(menuItems.getStyleItems());
  21818. }
  21819. });
  21820. };
  21821. 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';
  21822. var systemStackFonts = [
  21823. '-apple-system',
  21824. 'Segoe UI',
  21825. 'Roboto',
  21826. 'Helvetica Neue',
  21827. 'sans-serif'
  21828. ];
  21829. var isSystemFontStack = function (fontFamily) {
  21830. var matchesSystemStack = function () {
  21831. var fonts = fontFamily.toLowerCase().split(/['"]?\s*,\s*['"]?/);
  21832. return forall(systemStackFonts, function (font) {
  21833. return fonts.indexOf(font.toLowerCase()) > -1;
  21834. });
  21835. };
  21836. return fontFamily.indexOf('-apple-system') === 0 && matchesSystemStack();
  21837. };
  21838. var getSpec$1 = function (editor) {
  21839. var getMatchingValue = function () {
  21840. var getFirstFont = function (fontFamily) {
  21841. return fontFamily ? fontFamily.split(',')[0] : '';
  21842. };
  21843. var fontFamily = editor.queryCommandValue('FontName');
  21844. var items = dataset.data;
  21845. var font = fontFamily ? fontFamily.toLowerCase() : '';
  21846. return find(items, function (item) {
  21847. var format = item.format;
  21848. return format.toLowerCase() === font || getFirstFont(format).toLowerCase() === getFirstFont(font).toLowerCase();
  21849. }).orThunk(function () {
  21850. if (isSystemFontStack(font)) {
  21851. return Option.from({
  21852. title: 'System Font',
  21853. format: font
  21854. });
  21855. } else {
  21856. return Option.none();
  21857. }
  21858. });
  21859. };
  21860. var isSelectedFor = function (item) {
  21861. return function () {
  21862. return getMatchingValue().exists(function (match) {
  21863. return match.format === item;
  21864. });
  21865. };
  21866. };
  21867. var getPreviewFor = function (item) {
  21868. return function () {
  21869. return Option.some({
  21870. tag: 'div',
  21871. styleAttr: item.indexOf('dings') === -1 ? 'font-family:' + item : ''
  21872. });
  21873. };
  21874. };
  21875. var onAction = function (rawItem) {
  21876. return function () {
  21877. editor.undoManager.transact(function () {
  21878. editor.focus();
  21879. editor.execCommand('FontName', false, rawItem.format);
  21880. });
  21881. };
  21882. };
  21883. var nodeChangeHandler = Option.some(function (comp) {
  21884. return function () {
  21885. var fontFamily = editor.queryCommandValue('FontName');
  21886. var match = getMatchingValue();
  21887. var text = match.fold(function () {
  21888. return fontFamily;
  21889. }, function (item) {
  21890. return item.title;
  21891. });
  21892. emitWith(comp, updateMenuText, { text: text });
  21893. };
  21894. });
  21895. var dataset = buildBasicSettingsDataset(editor, 'font_formats', defaultFontsFormats, Delimiter.SemiColon);
  21896. return {
  21897. tooltip: 'Fonts',
  21898. icon: Option.none(),
  21899. isSelectedFor: isSelectedFor,
  21900. getPreviewFor: getPreviewFor,
  21901. onAction: onAction,
  21902. nodeChangeHandler: nodeChangeHandler,
  21903. dataset: dataset,
  21904. shouldHide: false,
  21905. isInvalid: function () {
  21906. return false;
  21907. }
  21908. };
  21909. };
  21910. var createFontSelect = function (editor, backstage) {
  21911. var spec = getSpec$1(editor);
  21912. return createSelectButton(editor, backstage, spec.dataset, spec);
  21913. };
  21914. var fontSelectMenu = function (editor, backstage) {
  21915. var spec = getSpec$1(editor);
  21916. var menuItems = createMenuItems(editor, backstage, spec.dataset, spec);
  21917. editor.ui.registry.addNestedMenuItem('fontformats', {
  21918. text: backstage.shared.providers.translate('Fonts'),
  21919. getSubmenuItems: function () {
  21920. return menuItems.items.validateItems(menuItems.getStyleItems());
  21921. }
  21922. });
  21923. };
  21924. var defaultFontsizeFormats = '8pt 10pt 12pt 14pt 18pt 24pt 36pt';
  21925. var round$1 = function (number, precision) {
  21926. var factor = Math.pow(10, precision);
  21927. return Math.round(number * factor) / factor;
  21928. };
  21929. var toPt = function (fontSize, precision) {
  21930. if (/[0-9.]+px$/.test(fontSize)) {
  21931. return round$1(parseInt(fontSize, 10) * 72 / 96, precision || 0) + 'pt';
  21932. }
  21933. return fontSize;
  21934. };
  21935. var getSpec$2 = function (editor) {
  21936. var getMatchingValue = function () {
  21937. var matchOpt = Option.none();
  21938. var items = dataset.data;
  21939. var px = editor.queryCommandValue('FontSize');
  21940. if (px) {
  21941. var _loop_1 = function (precision) {
  21942. var pt = toPt(px, precision);
  21943. matchOpt = find(items, function (item) {
  21944. return item.format === px || item.format === pt;
  21945. });
  21946. };
  21947. for (var precision = 3; matchOpt.isNone() && precision >= 0; precision--) {
  21948. _loop_1(precision);
  21949. }
  21950. }
  21951. return {
  21952. matchOpt: matchOpt,
  21953. px: px
  21954. };
  21955. };
  21956. var isSelectedFor = function (item) {
  21957. return function () {
  21958. var matchOpt = getMatchingValue().matchOpt;
  21959. return matchOpt.exists(function (match) {
  21960. return match.format === item;
  21961. });
  21962. };
  21963. };
  21964. var getPreviewFor = function () {
  21965. return function () {
  21966. return Option.none();
  21967. };
  21968. };
  21969. var onAction = function (rawItem) {
  21970. return function () {
  21971. editor.undoManager.transact(function () {
  21972. editor.focus();
  21973. editor.execCommand('FontSize', false, rawItem.format);
  21974. });
  21975. };
  21976. };
  21977. var nodeChangeHandler = Option.some(function (comp) {
  21978. return function () {
  21979. var _a = getMatchingValue(), matchOpt = _a.matchOpt, px = _a.px;
  21980. var text = matchOpt.fold(function () {
  21981. return px;
  21982. }, function (match) {
  21983. return match.title;
  21984. });
  21985. emitWith(comp, updateMenuText, { text: text });
  21986. };
  21987. });
  21988. var dataset = buildBasicSettingsDataset(editor, 'fontsize_formats', defaultFontsizeFormats, Delimiter.Space);
  21989. return {
  21990. tooltip: 'Font sizes',
  21991. icon: Option.none(),
  21992. isSelectedFor: isSelectedFor,
  21993. getPreviewFor: getPreviewFor,
  21994. onAction: onAction,
  21995. nodeChangeHandler: nodeChangeHandler,
  21996. dataset: dataset,
  21997. shouldHide: false,
  21998. isInvalid: function () {
  21999. return false;
  22000. }
  22001. };
  22002. };
  22003. var createFontsizeSelect = function (editor, backstage) {
  22004. var spec = getSpec$2(editor);
  22005. return createSelectButton(editor, backstage, spec.dataset, spec);
  22006. };
  22007. var fontsizeSelectMenu = function (editor, backstage) {
  22008. var spec = getSpec$2(editor);
  22009. var menuItems = createMenuItems(editor, backstage, spec.dataset, spec);
  22010. editor.ui.registry.addNestedMenuItem('fontsizes', {
  22011. text: 'Font sizes',
  22012. getSubmenuItems: function () {
  22013. return menuItems.items.validateItems(menuItems.getStyleItems());
  22014. }
  22015. });
  22016. };
  22017. var findNearest = function (editor, getStyles, nodeChangeEvent) {
  22018. var parents = nodeChangeEvent.parents;
  22019. var styles = getStyles();
  22020. return findMap(parents, function (parent) {
  22021. return find(styles, function (fmt) {
  22022. return editor.formatter.matchNode(parent, fmt.format);
  22023. });
  22024. }).orThunk(function () {
  22025. if (editor.formatter.match('p')) {
  22026. return Option.some({
  22027. title: 'Paragraph',
  22028. format: 'p'
  22029. });
  22030. }
  22031. return Option.none();
  22032. });
  22033. };
  22034. var defaultBlocks = 'Paragraph=p;' + 'Heading 1=h1;' + 'Heading 2=h2;' + 'Heading 3=h3;' + 'Heading 4=h4;' + 'Heading 5=h5;' + 'Heading 6=h6;' + 'Preformatted=pre';
  22035. var getSpec$3 = function (editor) {
  22036. var getMatchingValue = function (nodeChangeEvent) {
  22037. return findNearest(editor, function () {
  22038. return dataset.data;
  22039. }, nodeChangeEvent);
  22040. };
  22041. var isSelectedFor = function (format) {
  22042. return function () {
  22043. return editor.formatter.match(format);
  22044. };
  22045. };
  22046. var getPreviewFor = function (format) {
  22047. return function () {
  22048. var fmt = editor.formatter.get(format);
  22049. return Option.some({
  22050. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || 'div' : 'div',
  22051. styleAttr: editor.formatter.getCssText(format)
  22052. });
  22053. };
  22054. };
  22055. var onAction = function (rawItem) {
  22056. return function () {
  22057. editor.undoManager.transact(function () {
  22058. editor.focus();
  22059. if (editor.formatter.match(rawItem.format)) {
  22060. editor.formatter.remove(rawItem.format);
  22061. } else {
  22062. editor.formatter.apply(rawItem.format);
  22063. }
  22064. });
  22065. };
  22066. };
  22067. var nodeChangeHandler = Option.some(function (comp) {
  22068. return function (e) {
  22069. var detectedFormat = getMatchingValue(e);
  22070. var text = detectedFormat.fold(function () {
  22071. return 'Paragraph';
  22072. }, function (fmt) {
  22073. return fmt.title;
  22074. });
  22075. emitWith(comp, updateMenuText, { text: text });
  22076. };
  22077. });
  22078. var dataset = buildBasicSettingsDataset(editor, 'block_formats', defaultBlocks, Delimiter.SemiColon);
  22079. return {
  22080. tooltip: 'Blocks',
  22081. icon: Option.none(),
  22082. isSelectedFor: isSelectedFor,
  22083. getPreviewFor: getPreviewFor,
  22084. onAction: onAction,
  22085. nodeChangeHandler: nodeChangeHandler,
  22086. dataset: dataset,
  22087. shouldHide: false,
  22088. isInvalid: function (item) {
  22089. return !editor.formatter.canApply(item.format);
  22090. }
  22091. };
  22092. };
  22093. var createFormatSelect = function (editor, backstage) {
  22094. var spec = getSpec$3(editor);
  22095. return createSelectButton(editor, backstage, spec.dataset, spec);
  22096. };
  22097. var formatSelectMenu = function (editor, backstage) {
  22098. var spec = getSpec$3(editor);
  22099. var menuItems = createMenuItems(editor, backstage, spec.dataset, spec);
  22100. editor.ui.registry.addNestedMenuItem('blockformats', {
  22101. text: 'Blocks',
  22102. getSubmenuItems: function () {
  22103. return menuItems.items.validateItems(menuItems.getStyleItems());
  22104. }
  22105. });
  22106. };
  22107. var getSpec$4 = function (editor) {
  22108. var isSelectedFor = function (format) {
  22109. return function () {
  22110. return editor.formatter.match(format);
  22111. };
  22112. };
  22113. var getPreviewFor = function (format) {
  22114. return function () {
  22115. var fmt = editor.formatter.get(format);
  22116. return fmt !== undefined ? Option.some({
  22117. tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || 'div' : 'div',
  22118. styleAttr: editor.formatter.getCssText(format)
  22119. }) : Option.none();
  22120. };
  22121. };
  22122. var onAction = function (rawItem) {
  22123. return function () {
  22124. editor.undoManager.transact(function () {
  22125. editor.focus();
  22126. if (editor.formatter.match(rawItem.format)) {
  22127. editor.formatter.remove(rawItem.format);
  22128. } else {
  22129. editor.formatter.apply(rawItem.format);
  22130. }
  22131. });
  22132. };
  22133. };
  22134. var nodeChangeHandler = Option.some(function (comp) {
  22135. var getFormatItems = function (fmt) {
  22136. var subs = fmt.items;
  22137. return subs !== undefined && subs.length > 0 ? bind(subs, getFormatItems) : [{
  22138. title: fmt.title,
  22139. format: fmt.format
  22140. }];
  22141. };
  22142. var flattenedItems = bind(getStyleFormats(editor), getFormatItems);
  22143. return function (e) {
  22144. var detectedFormat = findNearest(editor, function () {
  22145. return flattenedItems;
  22146. }, e);
  22147. var text = detectedFormat.fold(function () {
  22148. return 'Paragraph';
  22149. }, function (fmt) {
  22150. return fmt.title;
  22151. });
  22152. emitWith(comp, updateMenuText, { text: text });
  22153. };
  22154. });
  22155. return {
  22156. tooltip: 'Formats',
  22157. icon: Option.none(),
  22158. isSelectedFor: isSelectedFor,
  22159. getPreviewFor: getPreviewFor,
  22160. onAction: onAction,
  22161. nodeChangeHandler: nodeChangeHandler,
  22162. shouldHide: editor.getParam('style_formats_autohide', false, 'boolean'),
  22163. isInvalid: function (item) {
  22164. return !editor.formatter.canApply(item.format);
  22165. }
  22166. };
  22167. };
  22168. var createStyleSelect = function (editor, backstage) {
  22169. var data = backstage.styleselect;
  22170. return createSelectButton(editor, backstage, data, getSpec$4(editor));
  22171. };
  22172. var styleSelectMenu = function (editor, backstage) {
  22173. var data = backstage.styleselect;
  22174. var menuItems = createMenuItems(editor, backstage, data, getSpec$4(editor));
  22175. editor.ui.registry.addNestedMenuItem('formats', {
  22176. text: 'Formats',
  22177. getSubmenuItems: function () {
  22178. return menuItems.items.validateItems(menuItems.getStyleItems());
  22179. }
  22180. });
  22181. };
  22182. var defaultMenubar = 'file edit view insert format tools table help';
  22183. var defaultMenus = {
  22184. file: {
  22185. title: 'File',
  22186. items: 'newdocument restoredraft | preview | print | deleteallconversations'
  22187. },
  22188. edit: {
  22189. title: 'Edit',
  22190. items: 'undo redo | cut copy paste pastetext | selectall | searchreplace'
  22191. },
  22192. view: {
  22193. title: 'View',
  22194. items: 'code | visualaid visualchars visualblocks | spellchecker | preview fullscreen | showcomments'
  22195. },
  22196. insert: {
  22197. title: 'Insert',
  22198. items: 'image link media addcomment pageembed template codesample inserttable | charmap emoticons hr | pagebreak nonbreaking anchor toc | insertdatetime'
  22199. },
  22200. format: {
  22201. title: 'Format',
  22202. items: 'bold italic underline strikethrough superscript subscript codeformat | formats blockformats fontformats fontsizes align | removeformat'
  22203. },
  22204. tools: {
  22205. title: 'Tools',
  22206. items: 'spellchecker spellcheckerlanguage | a11ycheck code wordcount'
  22207. },
  22208. table: {
  22209. title: 'Table',
  22210. items: 'inserttable tableprops deletetable row column cell'
  22211. },
  22212. help: {
  22213. title: 'Help',
  22214. items: 'help'
  22215. }
  22216. };
  22217. var renderMenuButton = function (spec, prefix, sharedBackstage, role) {
  22218. return renderCommonDropdown({
  22219. text: spec.text,
  22220. icon: spec.icon,
  22221. tooltip: spec.tooltip,
  22222. role: role,
  22223. fetch: function (callback) {
  22224. spec.fetch(function (items) {
  22225. callback(build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, sharedBackstage.providers));
  22226. });
  22227. },
  22228. onAttach: function () {
  22229. },
  22230. onDetach: function () {
  22231. },
  22232. columns: 1,
  22233. presets: 'normal',
  22234. classes: []
  22235. }, prefix, sharedBackstage);
  22236. };
  22237. var make$6 = function (menu, registry, editor) {
  22238. var removedMenuItems = getRemovedMenuItems(editor).split(/[ ,]/);
  22239. return {
  22240. text: menu.title,
  22241. getItems: function () {
  22242. return bind(menu.items, function (i) {
  22243. var itemName = i.toLowerCase();
  22244. if (itemName.trim().length === 0) {
  22245. return [];
  22246. } else if (exists(removedMenuItems, function (removedMenuItem) {
  22247. return removedMenuItem === itemName;
  22248. })) {
  22249. return [];
  22250. } else if (itemName === 'separator' || itemName === '|') {
  22251. return [{ type: 'separator' }];
  22252. } else if (registry.menuItems[itemName]) {
  22253. return [registry.menuItems[itemName]];
  22254. } else {
  22255. return [];
  22256. }
  22257. });
  22258. }
  22259. };
  22260. };
  22261. var parseItemsString = function (items) {
  22262. if (typeof items === 'string') {
  22263. return items.split(' ');
  22264. }
  22265. return items;
  22266. };
  22267. var identifyMenus = function (editor, registry) {
  22268. var rawMenuData = merge(defaultMenus, registry.menus);
  22269. var userDefinedMenus = keys(registry.menus).length > 0;
  22270. var menubar = registry.menubar === undefined || registry.menubar === true ? parseItemsString(defaultMenubar) : parseItemsString(registry.menubar === false ? '' : registry.menubar);
  22271. var validMenus = filter(menubar, function (menuName) {
  22272. return userDefinedMenus ? registry.menus.hasOwnProperty(menuName) && registry.menus[menuName].hasOwnProperty('items') || defaultMenus.hasOwnProperty(menuName) : defaultMenus.hasOwnProperty(menuName);
  22273. });
  22274. var menus = map(validMenus, function (menuName) {
  22275. var menuData = rawMenuData[menuName];
  22276. return make$6({
  22277. title: menuData.title,
  22278. items: parseItemsString(menuData.items)
  22279. }, registry, editor);
  22280. });
  22281. return filter(menus, function (menu) {
  22282. var isNotSeparator = function (item) {
  22283. return item.type !== 'separator';
  22284. };
  22285. return menu.getItems().length > 0 && exists(menu.getItems(), isNotSeparator);
  22286. });
  22287. };
  22288. var defaultToolbar = [
  22289. {
  22290. name: 'history',
  22291. items: [
  22292. 'undo',
  22293. 'redo'
  22294. ]
  22295. },
  22296. {
  22297. name: 'styles',
  22298. items: ['styleselect']
  22299. },
  22300. {
  22301. name: 'formatting',
  22302. items: [
  22303. 'bold',
  22304. 'italic'
  22305. ]
  22306. },
  22307. {
  22308. name: 'alignment',
  22309. items: [
  22310. 'alignleft',
  22311. 'aligncenter',
  22312. 'alignright',
  22313. 'alignjustify'
  22314. ]
  22315. },
  22316. {
  22317. name: 'indentation',
  22318. items: [
  22319. 'outdent',
  22320. 'indent'
  22321. ]
  22322. },
  22323. {
  22324. name: 'permanent pen',
  22325. items: ['permanentpen']
  22326. },
  22327. {
  22328. name: 'comments',
  22329. items: ['addcomment']
  22330. }
  22331. ];
  22332. var renderFromBridge = function (bridgeBuilder, render) {
  22333. return function (spec, extras) {
  22334. var internal = bridgeBuilder(spec).fold(compose(Result.error, formatError), Result.value).getOrDie();
  22335. return render(internal, extras);
  22336. };
  22337. };
  22338. var types = {
  22339. button: renderFromBridge(createToolbarButton, function (s, extras) {
  22340. return renderToolbarButton(s, extras.backstage.shared.providers);
  22341. }),
  22342. togglebutton: renderFromBridge(createToggleButton, function (s, extras) {
  22343. return renderToolbarToggleButton(s, extras.backstage.shared.providers);
  22344. }),
  22345. menubutton: renderFromBridge(createMenuButton, function (s, extras) {
  22346. return renderMenuButton(s, 'tox-tbtn', extras.backstage.shared, Option.none());
  22347. }),
  22348. splitbutton: renderFromBridge(createSplitButton, function (s, extras) {
  22349. return renderSplitButton(s, extras.backstage.shared);
  22350. }),
  22351. styleSelectButton: function (editor, extras) {
  22352. return createStyleSelect(editor, extras.backstage);
  22353. },
  22354. fontsizeSelectButton: function (editor, extras) {
  22355. return createFontsizeSelect(editor, extras.backstage);
  22356. },
  22357. fontSelectButton: function (editor, extras) {
  22358. return createFontSelect(editor, extras.backstage);
  22359. },
  22360. formatButton: function (editor, extras) {
  22361. return createFormatSelect(editor, extras.backstage);
  22362. },
  22363. alignMenuButton: function (editor, extras) {
  22364. return createAlignSelect(editor, extras.backstage);
  22365. }
  22366. };
  22367. var extractFrom$1 = function (spec, extras) {
  22368. return readOptFrom$1(types, spec.type).fold(function () {
  22369. console.error('skipping button defined by', spec);
  22370. return Option.none();
  22371. }, function (render) {
  22372. return Option.some(render(spec, extras));
  22373. });
  22374. };
  22375. var bespokeButtons = {
  22376. styleselect: types.styleSelectButton,
  22377. fontsizeselect: types.fontsizeSelectButton,
  22378. fontselect: types.fontSelectButton,
  22379. formatselect: types.formatButton,
  22380. align: types.alignMenuButton
  22381. };
  22382. var removeUnusedDefaults = function (buttons) {
  22383. var filteredItemGroups = map(defaultToolbar, function (group) {
  22384. var items = filter(group.items, function (subItem) {
  22385. return has(buttons, subItem) || has(bespokeButtons, subItem);
  22386. });
  22387. return {
  22388. name: group.name,
  22389. items: items
  22390. };
  22391. });
  22392. return filter(filteredItemGroups, function (group) {
  22393. return group.items.length > 0;
  22394. });
  22395. };
  22396. var convertStringToolbar = function (strToolbar) {
  22397. var groupsStrings = strToolbar.split('|');
  22398. return map(groupsStrings, function (g) {
  22399. return { items: g.trim().split(' ') };
  22400. });
  22401. };
  22402. var createToolbar = function (toolbarConfig) {
  22403. if (toolbarConfig.toolbar === false) {
  22404. return [];
  22405. } else if (toolbarConfig.toolbar === undefined || toolbarConfig.toolbar === true) {
  22406. return removeUnusedDefaults(toolbarConfig.buttons);
  22407. } else if (isString(toolbarConfig.toolbar)) {
  22408. return convertStringToolbar(toolbarConfig.toolbar);
  22409. } else if (isArray(toolbarConfig.toolbar) && isString(toolbarConfig.toolbar[0])) {
  22410. return convertStringToolbar(toolbarConfig.toolbar.join(' | '));
  22411. } else {
  22412. return toolbarConfig.toolbar;
  22413. }
  22414. };
  22415. var identifyButtons = function (editor, toolbarConfig, extras) {
  22416. var toolbarGroups = createToolbar(toolbarConfig);
  22417. var groups = map(toolbarGroups, function (group) {
  22418. var items = bind(group.items, function (toolbarItem) {
  22419. return toolbarItem.trim().length === 0 ? [] : readOptFrom$1(toolbarConfig.buttons, toolbarItem.toLowerCase()).fold(function () {
  22420. return readOptFrom$1(bespokeButtons, toolbarItem.toLowerCase()).map(function (r) {
  22421. return r(editor, extras);
  22422. }).orThunk(function () {
  22423. return Option.none();
  22424. });
  22425. }, function (spec) {
  22426. return extractFrom$1(spec, extras);
  22427. }).toArray();
  22428. });
  22429. return {
  22430. title: Option.from(editor.translate(group.name)),
  22431. items: items
  22432. };
  22433. });
  22434. return filter(groups, function (group) {
  22435. return group.items.length > 0;
  22436. });
  22437. };
  22438. var register$4 = function (editor, registryContextToolbars, sink, extras) {
  22439. var contextbar = build$1(renderContextToolbar({
  22440. sink: sink,
  22441. onEscape: function () {
  22442. editor.focus();
  22443. return Option.some(true);
  22444. }
  22445. }));
  22446. var getBoxElement = function () {
  22447. return Option.some(Element.fromDom(editor.contentAreaContainer));
  22448. };
  22449. editor.on('init', function () {
  22450. var scroller = editor.getBody().ownerDocument.defaultView;
  22451. var onScroll = bind$3(Element.fromDom(scroller), 'scroll', function () {
  22452. lastAnchor.get().each(function (anchor) {
  22453. var elem = lastElement.get().getOr(editor.selection.getNode());
  22454. var nodeBounds = elem.getBoundingClientRect();
  22455. var contentAreaBounds = editor.contentAreaContainer.getBoundingClientRect();
  22456. var aboveEditor = nodeBounds.bottom < 0;
  22457. var belowEditor = nodeBounds.top > contentAreaBounds.height;
  22458. if (aboveEditor || belowEditor) {
  22459. set$2(contextbar.element(), 'display', 'none');
  22460. } else {
  22461. remove$6(contextbar.element(), 'display');
  22462. Positioning.positionWithin(sink, anchor, contextbar, getBoxElement());
  22463. }
  22464. });
  22465. });
  22466. editor.on('remove', function () {
  22467. onScroll.unbind();
  22468. });
  22469. });
  22470. var lastAnchor = Cell(Option.none());
  22471. var lastElement = Cell(Option.none());
  22472. var timer = Cell(null);
  22473. var wrapInPopDialog = function (toolbarSpec) {
  22474. return {
  22475. dom: {
  22476. tag: 'div',
  22477. classes: ['tox-pop__dialog']
  22478. },
  22479. components: [toolbarSpec],
  22480. behaviours: derive$1([
  22481. Keying.config({ mode: 'acyclic' }),
  22482. config('pop-dialog-wrap-events', [
  22483. runOnAttached(function (comp) {
  22484. editor.shortcuts.add('ctrl+F9', 'focus statusbar', function () {
  22485. return Keying.focusIn(comp);
  22486. });
  22487. }),
  22488. runOnDetached(function (comp) {
  22489. editor.shortcuts.remove('ctrl+F9');
  22490. })
  22491. ])
  22492. ])
  22493. };
  22494. };
  22495. var getScopes = cached(function () {
  22496. return ToolbarScopes.categorise(registryContextToolbars, function (toolbarApi) {
  22497. var alloySpec = buildToolbar(toolbarApi);
  22498. emitWith(contextbar, forwardSlideEvent, { forwardContents: wrapInPopDialog(alloySpec) });
  22499. });
  22500. });
  22501. var buildToolbar = function (ctx) {
  22502. var buttons = editor.ui.registry.getAll().buttons;
  22503. var scopes = getScopes();
  22504. return ctx.type === 'contexttoolbar' ? function () {
  22505. var allButtons = merge(buttons, scopes.formNavigators);
  22506. var initGroups = identifyButtons(editor, {
  22507. buttons: allButtons,
  22508. toolbar: ctx.items
  22509. }, extras);
  22510. return renderToolbar({
  22511. uid: generate$1('context-toolbar'),
  22512. initGroups: initGroups,
  22513. onEscape: Option.none,
  22514. cyclicKeying: true,
  22515. backstage: extras.backstage
  22516. });
  22517. }() : function () {
  22518. return ContextForm.renderContextForm(ctx, extras.backstage);
  22519. }();
  22520. };
  22521. editor.on(showContextToolbarEvent, function (e) {
  22522. var scopes = getScopes();
  22523. readOptFrom$1(scopes.lookupTable, e.toolbarKey).each(function (ctx) {
  22524. launchContext(ctx, e.target === editor ? Option.none() : Option.some(e));
  22525. InlineView.getContent(contextbar).each(Keying.focusIn);
  22526. });
  22527. });
  22528. var bubbleAlignments = {
  22529. valignCentre: [],
  22530. alignCentre: [],
  22531. alignLeft: ['tox-pop--align-left'],
  22532. alignRight: ['tox-pop--align-right'],
  22533. right: ['tox-pop--right'],
  22534. left: ['tox-pop--left'],
  22535. bottom: ['tox-pop--bottom'],
  22536. top: ['tox-pop--top']
  22537. };
  22538. var anchorOverrides = { maxHeightFunction: expandable() };
  22539. var lineAnchorSpec = {
  22540. bubble: nu$7(12, 0, bubbleAlignments),
  22541. layouts: {
  22542. onLtr: function () {
  22543. return [east$1];
  22544. },
  22545. onRtl: function () {
  22546. return [west$1];
  22547. }
  22548. },
  22549. overrides: anchorOverrides
  22550. };
  22551. var anchorSpec = {
  22552. bubble: nu$7(0, 12, bubbleAlignments),
  22553. layouts: {
  22554. onLtr: function () {
  22555. return [
  22556. north$1,
  22557. south$1,
  22558. northeast$1,
  22559. southeast$1,
  22560. northwest$1,
  22561. southwest$1
  22562. ];
  22563. },
  22564. onRtl: function () {
  22565. return [
  22566. north$1,
  22567. south$1,
  22568. northwest$1,
  22569. southwest$1,
  22570. northeast$1,
  22571. southeast$1
  22572. ];
  22573. }
  22574. },
  22575. overrides: anchorOverrides
  22576. };
  22577. var getAnchor = function (position, element) {
  22578. var anchorage = position === 'node' ? extras.backstage.shared.anchors.node(element) : extras.backstage.shared.anchors.cursor();
  22579. var anchor = deepMerge(anchorage, position === 'line' ? lineAnchorSpec : anchorSpec);
  22580. return anchor;
  22581. };
  22582. var launchContext = function (toolbarApi, elem) {
  22583. clearTimer();
  22584. var toolbarSpec = buildToolbar(toolbarApi);
  22585. var sElem = elem.map(Element.fromDom);
  22586. var anchor = getAnchor(toolbarApi.position, sElem);
  22587. lastAnchor.set(Option.some(anchor));
  22588. lastElement.set(elem);
  22589. InlineView.showWithin(contextbar, anchor, wrapInPopDialog(toolbarSpec), getBoxElement());
  22590. remove$6(contextbar.element(), 'display');
  22591. };
  22592. var launchContextToolbar = function () {
  22593. var scopes = getScopes();
  22594. ToolbarLookup.lookup(scopes, editor).fold(function () {
  22595. lastAnchor.set(Option.none());
  22596. InlineView.hide(contextbar);
  22597. }, function (info) {
  22598. launchContext(info.toolbarApi, Option.some(info.elem.dom()));
  22599. });
  22600. };
  22601. var clearTimer = function () {
  22602. var current = timer.get();
  22603. if (current !== null) {
  22604. clearTimeout(current);
  22605. timer.set(null);
  22606. }
  22607. };
  22608. var resetTimer = function (t) {
  22609. clearTimer();
  22610. timer.set(t);
  22611. };
  22612. editor.on('init', function () {
  22613. editor.on('click keyup setContent ObjectResized ResizeEditor', function (e) {
  22614. resetTimer(global$c.setEditorTimeout(editor, launchContextToolbar, 0));
  22615. });
  22616. editor.on('focusout', function (e) {
  22617. global$c.setEditorTimeout(editor, function () {
  22618. if (search$1(sink.element()).isNone() && search$1(contextbar.element()).isNone()) {
  22619. lastAnchor.set(Option.none());
  22620. InlineView.hide(contextbar);
  22621. }
  22622. }, 0);
  22623. });
  22624. editor.on('nodeChange', function (e) {
  22625. search$1(contextbar.element()).fold(function () {
  22626. resetTimer(global$c.setEditorTimeout(editor, launchContextToolbar, 0));
  22627. }, function (_) {
  22628. });
  22629. });
  22630. });
  22631. };
  22632. var ContextToolbar = { register: register$4 };
  22633. var setup$3 = function (editor, mothership, uiMothership) {
  22634. var onMousedown = bind$3(Element.fromDom(domGlobals.document), 'mousedown', function (evt) {
  22635. each([
  22636. mothership,
  22637. uiMothership
  22638. ], function (ship) {
  22639. ship.broadcastOn([dismissPopups()], { target: evt.target() });
  22640. });
  22641. });
  22642. var onTouchstart = bind$3(Element.fromDom(domGlobals.document), 'touchstart', function (evt) {
  22643. each([
  22644. mothership,
  22645. uiMothership
  22646. ], function (ship) {
  22647. ship.broadcastOn([dismissPopups()], { target: evt.target() });
  22648. });
  22649. });
  22650. var onMouseup = bind$3(Element.fromDom(domGlobals.document), 'mouseup', function (evt) {
  22651. if (evt.raw().button === 0) {
  22652. each([
  22653. mothership,
  22654. uiMothership
  22655. ], function (ship) {
  22656. ship.broadcastOn([mouseReleased()], { target: evt.target() });
  22657. });
  22658. }
  22659. });
  22660. var onContentMousedown = function (raw) {
  22661. each([
  22662. mothership,
  22663. uiMothership
  22664. ], function (ship) {
  22665. ship.broadcastOn([dismissPopups()], { target: Element.fromDom(raw.target) });
  22666. });
  22667. };
  22668. editor.on('mousedown', onContentMousedown);
  22669. editor.on('touchstart', onContentMousedown);
  22670. var onContentMouseup = function (raw) {
  22671. if (raw.button === 0) {
  22672. each([
  22673. mothership,
  22674. uiMothership
  22675. ], function (ship) {
  22676. ship.broadcastOn([mouseReleased()], { target: Element.fromDom(raw.target) });
  22677. });
  22678. }
  22679. };
  22680. editor.on('mouseup', onContentMouseup);
  22681. var onWindowScroll = function (evt) {
  22682. each([
  22683. mothership,
  22684. uiMothership
  22685. ], function (ship) {
  22686. ship.broadcastEvent(windowScroll(), evt);
  22687. });
  22688. };
  22689. editor.on('ScrollWindow', onWindowScroll);
  22690. var onWindowResize = function (evt) {
  22691. each([
  22692. mothership,
  22693. uiMothership
  22694. ], function (ship) {
  22695. ship.broadcastEvent(windowResize(), evt);
  22696. });
  22697. };
  22698. editor.on('ResizeWindow', onWindowResize);
  22699. editor.on('remove', function () {
  22700. editor.off('mousedown', onContentMousedown);
  22701. editor.off('touchstart', onContentMousedown);
  22702. editor.off('mouseup', onContentMouseup);
  22703. editor.off('ResizeWindow', onWindowResize);
  22704. editor.off('ScrollWindow', onWindowScroll);
  22705. onMousedown.unbind();
  22706. onTouchstart.unbind();
  22707. onMouseup.unbind();
  22708. });
  22709. editor.on('detach', function () {
  22710. detachSystem(mothership);
  22711. detachSystem(uiMothership);
  22712. mothership.destroy();
  22713. uiMothership.destroy();
  22714. });
  22715. };
  22716. var Events = { setup: setup$3 };
  22717. var parts$b = AlloyParts;
  22718. var partType$1 = PartType;
  22719. var factory$d = function (detail, spec) {
  22720. var setMenus = function (comp, menus) {
  22721. var newMenus = map(menus, function (m) {
  22722. var buttonSpec = {
  22723. text: Option.some(m.text),
  22724. icon: Option.none(),
  22725. tooltip: Option.none(),
  22726. fetch: function (callback) {
  22727. callback(m.getItems());
  22728. }
  22729. };
  22730. return renderMenuButton(buttonSpec, 'tox-mbtn', {
  22731. getSink: detail.getSink,
  22732. providers: detail.providers
  22733. }, Option.some('menuitem'));
  22734. });
  22735. Replacing.set(comp, newMenus);
  22736. };
  22737. var apis = {
  22738. focus: Keying.focusIn,
  22739. setMenus: setMenus
  22740. };
  22741. return {
  22742. uid: detail.uid,
  22743. dom: detail.dom,
  22744. components: [],
  22745. behaviours: derive$1([
  22746. Replacing.config({}),
  22747. config('menubar-events', [
  22748. runOnAttached(function (component) {
  22749. detail.onSetup(component);
  22750. }),
  22751. run(mouseover(), function (comp, se) {
  22752. descendant$1(comp.element(), '.' + 'tox-mbtn--active').each(function (activeButton) {
  22753. closest$3(se.event().target(), '.' + 'tox-mbtn').each(function (hoveredButton) {
  22754. if (!eq(activeButton, hoveredButton)) {
  22755. comp.getSystem().getByDom(activeButton).each(function (activeComp) {
  22756. comp.getSystem().getByDom(hoveredButton).each(function (hoveredComp) {
  22757. Dropdown.expand(hoveredComp);
  22758. Dropdown.close(activeComp);
  22759. Focusing.focus(hoveredComp);
  22760. });
  22761. });
  22762. }
  22763. });
  22764. });
  22765. }),
  22766. run(focusShifted(), function (comp, se) {
  22767. se.event().prevFocus().bind(function (prev) {
  22768. return comp.getSystem().getByDom(prev).toOption();
  22769. }).each(function (prev) {
  22770. se.event().newFocus().bind(function (nu) {
  22771. return comp.getSystem().getByDom(nu).toOption();
  22772. }).each(function (nu) {
  22773. if (Dropdown.isOpen(prev)) {
  22774. Dropdown.expand(nu);
  22775. Dropdown.close(prev);
  22776. }
  22777. });
  22778. });
  22779. })
  22780. ]),
  22781. Keying.config({
  22782. mode: 'flow',
  22783. selector: '.' + 'tox-mbtn',
  22784. onEscape: function (comp) {
  22785. detail.onEscape(comp);
  22786. return Option.some(true);
  22787. }
  22788. }),
  22789. Tabstopping.config({})
  22790. ]),
  22791. apis: apis,
  22792. domModification: { attributes: { role: 'menubar' } }
  22793. };
  22794. };
  22795. var SilverMenubar = single$2({
  22796. factory: factory$d,
  22797. name: 'silver.Menubar',
  22798. configFields: [
  22799. strict$1('dom'),
  22800. strict$1('uid'),
  22801. strict$1('onEscape'),
  22802. strict$1('getSink'),
  22803. strict$1('providers'),
  22804. defaulted$1('onSetup', noop)
  22805. ],
  22806. apis: {
  22807. focus: function (apis, comp) {
  22808. apis.focus(comp);
  22809. },
  22810. setMenus: function (apis, comp, menus) {
  22811. apis.setMenus(comp, menus);
  22812. }
  22813. }
  22814. });
  22815. var owner$4 = 'container';
  22816. var schema$n = [field$1('slotBehaviours', [])];
  22817. var getPartName$1 = function (name) {
  22818. return '<alloy.field.' + name + '>';
  22819. };
  22820. var sketch$2 = function (sSpec) {
  22821. var parts = function () {
  22822. var record = [];
  22823. var slot = function (name, config) {
  22824. record.push(name);
  22825. return generateOne(owner$4, getPartName$1(name), config);
  22826. };
  22827. return {
  22828. slot: slot,
  22829. record: function () {
  22830. return record;
  22831. }
  22832. };
  22833. }();
  22834. var spec = sSpec(parts);
  22835. var partNames = parts.record();
  22836. var fieldParts = map(partNames, function (n) {
  22837. return required({
  22838. name: n,
  22839. pname: getPartName$1(n)
  22840. });
  22841. });
  22842. return composite(owner$4, schema$n, fieldParts, make$7, spec);
  22843. };
  22844. var make$7 = function (detail, components, spec) {
  22845. var getSlotNames = function (_) {
  22846. return getAllPartNames(detail);
  22847. };
  22848. var getSlot = function (container, key) {
  22849. return getPart(container, detail, key);
  22850. };
  22851. var onSlot = function (f, def) {
  22852. if (def === void 0) {
  22853. def = undefined;
  22854. }
  22855. return function (container, key) {
  22856. return getPart(container, detail, key).map(function (slot) {
  22857. return f(slot, key);
  22858. }).getOr(def);
  22859. };
  22860. };
  22861. var onSlots = function (f) {
  22862. return function (container, keys) {
  22863. each(keys, function (key) {
  22864. return f(container, key);
  22865. });
  22866. };
  22867. };
  22868. var doShowing = function (comp, key) {
  22869. return get$2(comp.element(), 'aria-hidden') !== 'true';
  22870. };
  22871. var doShow = function (comp, key) {
  22872. if (!doShowing(comp, key)) {
  22873. var element = comp.element();
  22874. remove$6(element, 'display');
  22875. remove$1(element, 'aria-hidden');
  22876. emitWith(comp, slotVisibility(), {
  22877. name: key,
  22878. visible: true
  22879. });
  22880. }
  22881. };
  22882. var doHide = function (comp, key) {
  22883. if (doShowing(comp, key)) {
  22884. var element = comp.element();
  22885. set$2(element, 'display', 'none');
  22886. set$1(element, 'aria-hidden', 'true');
  22887. emitWith(comp, slotVisibility(), {
  22888. name: key,
  22889. visible: false
  22890. });
  22891. }
  22892. };
  22893. var isShowing = onSlot(doShowing, false);
  22894. var hideSlot = onSlot(doHide);
  22895. var hideSlots = onSlots(hideSlot);
  22896. var hideAllSlots = function (container) {
  22897. return hideSlots(container, getSlotNames(container));
  22898. };
  22899. var showSlot = onSlot(doShow);
  22900. var apis = {
  22901. getSlotNames: getSlotNames,
  22902. getSlot: getSlot,
  22903. isShowing: isShowing,
  22904. hideSlot: hideSlot,
  22905. hideAllSlots: hideAllSlots,
  22906. showSlot: showSlot
  22907. };
  22908. return {
  22909. 'uid': detail.uid,
  22910. 'dom': detail.dom,
  22911. 'components': components,
  22912. 'behaviours': get$b(detail.slotBehaviours),
  22913. 'apis': apis
  22914. };
  22915. };
  22916. var slotApis = map$1({
  22917. getSlotNames: function (apis, c) {
  22918. return apis.getSlotNames(c);
  22919. },
  22920. getSlot: function (apis, c, key) {
  22921. return apis.getSlot(c, key);
  22922. },
  22923. isShowing: function (apis, c, key) {
  22924. return apis.isShowing(c, key);
  22925. },
  22926. hideSlot: function (apis, c, key) {
  22927. return apis.hideSlot(c, key);
  22928. },
  22929. hideAllSlots: function (apis, c) {
  22930. return apis.hideAllSlots(c);
  22931. },
  22932. showSlot: function (apis, c, key) {
  22933. return apis.showSlot(c, key);
  22934. }
  22935. }, makeApi);
  22936. var SlotContainer = __assign({}, slotApis, { sketch: sketch$2 });
  22937. var sidebarSchema = objOf([
  22938. optionString('icon'),
  22939. optionString('tooltip'),
  22940. defaultedFunction('onShow', noop),
  22941. defaultedFunction('onHide', noop),
  22942. defaultedFunction('onSetup', function () {
  22943. return noop;
  22944. })
  22945. ]);
  22946. var createSidebar = function (spec) {
  22947. return asRaw('sidebar', sidebarSchema, spec);
  22948. };
  22949. var setup$4 = function (editor) {
  22950. var sidebars = editor.ui.registry.getAll().sidebars;
  22951. each(keys(sidebars), function (name) {
  22952. var spec = sidebars[name];
  22953. var isActive = function () {
  22954. return Option.from(editor.queryCommandValue('ToggleSidebar')).is(name);
  22955. };
  22956. editor.ui.registry.addToggleButton(name, {
  22957. icon: spec.icon,
  22958. tooltip: spec.tooltip,
  22959. onAction: function (buttonApi) {
  22960. editor.execCommand('ToggleSidebar', false, name);
  22961. buttonApi.setActive(isActive());
  22962. },
  22963. onSetup: function (buttonApi) {
  22964. var handleToggle = function () {
  22965. return buttonApi.setActive(isActive());
  22966. };
  22967. editor.on('ToggleSidebar', handleToggle);
  22968. return function () {
  22969. editor.off('ToggleSidebar', handleToggle);
  22970. };
  22971. }
  22972. });
  22973. });
  22974. };
  22975. var getApi = function (comp) {
  22976. return {
  22977. element: function () {
  22978. return comp.element().dom();
  22979. }
  22980. };
  22981. };
  22982. var makePanels = function (parts, panelConfigs) {
  22983. var specs = map(keys(panelConfigs), function (name) {
  22984. var spec = panelConfigs[name];
  22985. var bridged = getOrDie$1(createSidebar(spec));
  22986. return {
  22987. name: name,
  22988. getApi: getApi,
  22989. onSetup: bridged.onSetup,
  22990. onShow: bridged.onShow,
  22991. onHide: bridged.onHide
  22992. };
  22993. });
  22994. return map(specs, function (spec) {
  22995. var editorOffCell = Cell(noop);
  22996. return parts.slot(spec.name, {
  22997. dom: {
  22998. tag: 'div',
  22999. classes: ['tox-sidebar__pane']
  23000. },
  23001. behaviours: SimpleBehaviours.unnamedEvents([
  23002. onControlAttached(spec, editorOffCell),
  23003. onControlDetached(spec, editorOffCell),
  23004. run(slotVisibility(), function (sidepanel, se) {
  23005. var data = se.event();
  23006. var optSidePanelSpec = find(specs, function (config) {
  23007. return config.name === data.name();
  23008. });
  23009. optSidePanelSpec.each(function (sidePanelSpec) {
  23010. var handler = data.visible() ? sidePanelSpec.onShow : sidePanelSpec.onHide;
  23011. handler(sidePanelSpec.getApi(sidepanel));
  23012. });
  23013. })
  23014. ])
  23015. });
  23016. });
  23017. };
  23018. var makeSidebar = function (panelConfigs) {
  23019. return SlotContainer.sketch(function (parts) {
  23020. return {
  23021. dom: {
  23022. tag: 'div',
  23023. classes: ['tox-sidebar__pane-container']
  23024. },
  23025. components: makePanels(parts, panelConfigs),
  23026. slotBehaviours: SimpleBehaviours.unnamedEvents([runOnAttached(function (slotContainer) {
  23027. return SlotContainer.hideAllSlots(slotContainer);
  23028. })])
  23029. };
  23030. });
  23031. };
  23032. var setSidebar = function (sidebar, panelConfigs) {
  23033. var optSlider = Composing.getCurrent(sidebar);
  23034. optSlider.each(function (slider) {
  23035. return Replacing.set(slider, [makeSidebar(panelConfigs)]);
  23036. });
  23037. };
  23038. var toggleSidebar = function (sidebar, name) {
  23039. var optSlider = Composing.getCurrent(sidebar);
  23040. optSlider.each(function (slider) {
  23041. var optSlotContainer = Composing.getCurrent(slider);
  23042. optSlotContainer.each(function (slotContainer) {
  23043. if (Sliding.hasGrown(slider)) {
  23044. if (SlotContainer.isShowing(slotContainer, name)) {
  23045. Sliding.shrink(slider);
  23046. } else {
  23047. SlotContainer.hideAllSlots(slotContainer);
  23048. SlotContainer.showSlot(slotContainer, name);
  23049. }
  23050. } else {
  23051. SlotContainer.hideAllSlots(slotContainer);
  23052. SlotContainer.showSlot(slotContainer, name);
  23053. Sliding.grow(slider);
  23054. }
  23055. });
  23056. });
  23057. };
  23058. var whichSidebar = function (sidebar) {
  23059. var optSlider = Composing.getCurrent(sidebar);
  23060. return optSlider.bind(function (slider) {
  23061. var sidebarOpen = Sliding.isGrowing(slider) || Sliding.hasGrown(slider);
  23062. if (sidebarOpen) {
  23063. var optSlotContainer = Composing.getCurrent(slider);
  23064. return optSlotContainer.bind(function (slotContainer) {
  23065. return find(SlotContainer.getSlotNames(slotContainer), function (name) {
  23066. return SlotContainer.isShowing(slotContainer, name);
  23067. });
  23068. });
  23069. } else {
  23070. return Option.none();
  23071. }
  23072. });
  23073. };
  23074. var fixSize = generate$1('FixSizeEvent');
  23075. var autoSize = generate$1('AutoSizeEvent');
  23076. var renderSidebar = function (spec) {
  23077. return {
  23078. uid: spec.uid,
  23079. dom: {
  23080. tag: 'div',
  23081. classes: ['tox-sidebar'],
  23082. attributes: { role: 'complementary' }
  23083. },
  23084. components: [{
  23085. dom: {
  23086. tag: 'div',
  23087. classes: ['tox-sidebar__slider']
  23088. },
  23089. components: [],
  23090. behaviours: derive$1([
  23091. Tabstopping.config({}),
  23092. Focusing.config({}),
  23093. Sliding.config({
  23094. dimension: { property: 'width' },
  23095. closedClass: 'tox-sidebar--sliding-closed',
  23096. openClass: 'tox-sidebar--sliding-open',
  23097. shrinkingClass: 'tox-sidebar--sliding-shrinking',
  23098. growingClass: 'tox-sidebar--sliding-growing',
  23099. onShrunk: function (slider) {
  23100. var optSlotContainer = Composing.getCurrent(slider);
  23101. optSlotContainer.each(SlotContainer.hideAllSlots);
  23102. emit(slider, autoSize);
  23103. },
  23104. onGrown: function (slider) {
  23105. emit(slider, autoSize);
  23106. },
  23107. onStartGrow: function (slider) {
  23108. emitWith(slider, fixSize, { width: getRaw(slider.element(), 'width').getOr('') });
  23109. },
  23110. onStartShrink: function (slider) {
  23111. emitWith(slider, fixSize, { width: get$7(slider.element()) + 'px' });
  23112. }
  23113. }),
  23114. Replacing.config({}),
  23115. Composing.config({
  23116. find: function (comp) {
  23117. var children = Replacing.contents(comp);
  23118. return head(children);
  23119. }
  23120. })
  23121. ])
  23122. }],
  23123. behaviours: derive$1([
  23124. ComposingConfigs.childAt(0),
  23125. config('sidebar-sliding-events', [
  23126. run(fixSize, function (comp, se) {
  23127. set$2(comp.element(), 'width', se.event().width());
  23128. }),
  23129. run(autoSize, function (comp, se) {
  23130. remove$6(comp.element(), 'width');
  23131. })
  23132. ])
  23133. ])
  23134. };
  23135. };
  23136. var factory$e = function (detail, components, spec) {
  23137. var apis = {
  23138. getSocket: function (comp) {
  23139. return parts$b.getPart(comp, detail, 'socket');
  23140. },
  23141. setSidebar: function (comp, panelConfigs) {
  23142. parts$b.getPart(comp, detail, 'sidebar').each(function (sidebar) {
  23143. return setSidebar(sidebar, panelConfigs);
  23144. });
  23145. },
  23146. toggleSidebar: function (comp, name) {
  23147. parts$b.getPart(comp, detail, 'sidebar').each(function (sidebar) {
  23148. return toggleSidebar(sidebar, name);
  23149. });
  23150. },
  23151. whichSidebar: function (comp) {
  23152. return parts$b.getPart(comp, detail, 'sidebar').bind(whichSidebar).getOrNull();
  23153. },
  23154. getToolbar: function (comp) {
  23155. return parts$b.getPart(comp, detail, 'toolbar');
  23156. },
  23157. setToolbar: function (comp, groups) {
  23158. parts$b.getPart(comp, detail, 'toolbar').each(function (toolbar) {
  23159. Toolbar.setGroups(toolbar, groups);
  23160. });
  23161. },
  23162. focusToolbar: function (comp) {
  23163. parts$b.getPart(comp, detail, 'toolbar').each(function (toolbar) {
  23164. Keying.focusIn(toolbar);
  23165. });
  23166. },
  23167. setMenubar: function (comp, menus) {
  23168. parts$b.getPart(comp, detail, 'menubar').each(function (menubar) {
  23169. SilverMenubar.setMenus(menubar, menus);
  23170. });
  23171. },
  23172. focusMenubar: function (comp) {
  23173. parts$b.getPart(comp, detail, 'menubar').each(function (menubar) {
  23174. SilverMenubar.focus(menubar);
  23175. });
  23176. }
  23177. };
  23178. return {
  23179. uid: detail.uid,
  23180. dom: detail.dom,
  23181. components: components,
  23182. apis: apis,
  23183. behaviours: detail.behaviours
  23184. };
  23185. };
  23186. var partMenubar = partType$1.optional({
  23187. factory: SilverMenubar,
  23188. name: 'menubar',
  23189. schema: [
  23190. strict$1('dom'),
  23191. strict$1('getSink')
  23192. ]
  23193. });
  23194. var partToolbar = partType$1.optional({
  23195. factory: {
  23196. sketch: function (spec) {
  23197. var renderer = spec.split ? renderMoreToolbar : renderToolbar;
  23198. return renderer({
  23199. uid: spec.uid,
  23200. onEscape: function () {
  23201. spec.onEscape();
  23202. return Option.some(true);
  23203. },
  23204. cyclicKeying: false,
  23205. initGroups: [],
  23206. backstage: spec.backstage
  23207. });
  23208. }
  23209. },
  23210. name: 'toolbar',
  23211. schema: [
  23212. strict$1('dom'),
  23213. strict$1('onEscape')
  23214. ]
  23215. });
  23216. var partSocket = partType$1.optional({
  23217. name: 'socket',
  23218. schema: [strict$1('dom')]
  23219. });
  23220. var partSidebar = partType$1.optional({
  23221. factory: { sketch: renderSidebar },
  23222. name: 'sidebar',
  23223. schema: [strict$1('dom')]
  23224. });
  23225. var OuterContainer = composite$1({
  23226. name: 'OuterContainer',
  23227. factory: factory$e,
  23228. configFields: [
  23229. strict$1('dom'),
  23230. strict$1('behaviours')
  23231. ],
  23232. partFields: [
  23233. partMenubar,
  23234. partToolbar,
  23235. partSocket,
  23236. partSidebar
  23237. ],
  23238. apis: {
  23239. getSocket: function (apis, comp) {
  23240. return apis.getSocket(comp);
  23241. },
  23242. setSidebar: function (apis, comp, panelConfigs) {
  23243. apis.setSidebar(comp, panelConfigs);
  23244. },
  23245. toggleSidebar: function (apis, comp, name) {
  23246. apis.toggleSidebar(comp, name);
  23247. },
  23248. whichSidebar: function (apis, comp) {
  23249. return apis.whichSidebar(comp);
  23250. },
  23251. getToolbar: function (apis, comp) {
  23252. return apis.getToolbar(comp);
  23253. },
  23254. setToolbar: function (apis, comp, grps) {
  23255. var groups = map(grps, function (grp) {
  23256. return renderToolbarGroup(grp);
  23257. });
  23258. apis.setToolbar(comp, groups);
  23259. },
  23260. setMenubar: function (apis, comp, menus) {
  23261. apis.setMenubar(comp, menus);
  23262. },
  23263. focusMenubar: function (apis, comp) {
  23264. apis.focusMenubar(comp);
  23265. },
  23266. focusToolbar: function (apis, comp) {
  23267. apis.focusToolbar(comp);
  23268. }
  23269. }
  23270. });
  23271. var fireSkinLoaded = function (editor) {
  23272. return editor.fire('SkinLoaded');
  23273. };
  23274. var fireResizeEditor = function (editor) {
  23275. return editor.fire('ResizeEditor');
  23276. };
  23277. var fireBeforeRenderUI = function (editor) {
  23278. return editor.fire('BeforeRenderUI');
  23279. };
  23280. var fireResizeContent = function (editor) {
  23281. return editor.fire('ResizeContent');
  23282. };
  23283. var Events$1 = {
  23284. fireSkinLoaded: fireSkinLoaded,
  23285. fireResizeEditor: fireResizeEditor,
  23286. fireBeforeRenderUI: fireBeforeRenderUI,
  23287. fireResizeContent: fireResizeContent
  23288. };
  23289. var fireSkinLoaded$1 = function (editor) {
  23290. var done = function () {
  23291. editor._skinLoaded = true;
  23292. Events$1.fireSkinLoaded(editor);
  23293. };
  23294. return function () {
  23295. if (editor.initialized) {
  23296. done();
  23297. } else {
  23298. editor.on('init', done);
  23299. }
  23300. };
  23301. };
  23302. var SkinLoaded = { fireSkinLoaded: fireSkinLoaded$1 };
  23303. var loadSkin = function (isInline, editor) {
  23304. var skinUrl = getSkinUrl(editor);
  23305. var skinUiCss;
  23306. if (skinUrl) {
  23307. skinUiCss = skinUrl + '/skin.min.css';
  23308. editor.contentCSS.push(skinUrl + (isInline ? '/content.inline' : '/content') + '.min.css');
  23309. }
  23310. if (isSkinDisabled(editor) === false && skinUiCss) {
  23311. global$4.DOM.styleSheetLoader.load(skinUiCss, SkinLoaded.fireSkinLoaded(editor));
  23312. } else {
  23313. SkinLoaded.fireSkinLoaded(editor)();
  23314. }
  23315. };
  23316. var iframe = curry(loadSkin, false);
  23317. var inline = curry(loadSkin, true);
  23318. var DOM = global$4.DOM;
  23319. var handleSwitchMode = function (uiComponents) {
  23320. return function (e) {
  23321. var outerContainer = uiComponents.outerContainer;
  23322. all('*', outerContainer.element()).forEach(function (elm) {
  23323. outerContainer.getSystem().getByDom(elm).each(function (comp) {
  23324. if (comp.hasConfigured(Disabling)) {
  23325. if (e.mode === 'readonly') {
  23326. Disabling.disable(comp);
  23327. } else {
  23328. Disabling.enable(comp);
  23329. }
  23330. }
  23331. });
  23332. });
  23333. };
  23334. };
  23335. var render = function (editor, uiComponents, rawUiConfig, backstage, args) {
  23336. iframe(editor);
  23337. attachSystemAfter(Element.fromDom(args.targetNode), uiComponents.mothership);
  23338. attachSystem(body(), uiComponents.uiMothership);
  23339. editor.on('init', function () {
  23340. OuterContainer.setToolbar(uiComponents.outerContainer, identifyButtons(editor, rawUiConfig, { backstage: backstage }));
  23341. OuterContainer.setMenubar(uiComponents.outerContainer, identifyMenus(editor, rawUiConfig));
  23342. OuterContainer.setSidebar(uiComponents.outerContainer, rawUiConfig.sidebar);
  23343. if (editor.readonly) {
  23344. handleSwitchMode(uiComponents)({ mode: 'readonly' });
  23345. }
  23346. var lastDimensions = Cell(Position(0, 0));
  23347. var window = editor.contentWindow;
  23348. var resize = function () {
  23349. var last = lastDimensions.get();
  23350. if (last.left() !== window.innerWidth || last.top() !== window.innerHeight) {
  23351. var next = Position(window.innerWidth, window.innerHeight);
  23352. lastDimensions.set(next);
  23353. Events$1.fireResizeContent(editor);
  23354. }
  23355. };
  23356. DOM.bind(window, 'resize', resize);
  23357. var removeResize = function () {
  23358. DOM.unbind(window, 'resize', resize);
  23359. };
  23360. editor.on('remove', removeResize);
  23361. });
  23362. var socket = OuterContainer.getSocket(uiComponents.outerContainer).getOrDie('Could not find expected socket element');
  23363. editor.on('SwitchMode', handleSwitchMode(uiComponents));
  23364. if (isReadOnly(editor)) {
  23365. editor.setMode('readonly');
  23366. }
  23367. editor.addCommand('ToggleSidebar', function (ui, value) {
  23368. OuterContainer.toggleSidebar(uiComponents.outerContainer, value);
  23369. editor.fire('ToggleSidebar');
  23370. });
  23371. editor.addQueryValueHandler('ToggleSidebar', function () {
  23372. return OuterContainer.whichSidebar(uiComponents.outerContainer);
  23373. });
  23374. var split = isSplitToolbar(editor);
  23375. var refreshMore = function () {
  23376. if (split) {
  23377. var toolbar = OuterContainer.getToolbar(uiComponents.outerContainer);
  23378. toolbar.each(SplitToolbar.refresh);
  23379. }
  23380. };
  23381. editor.on('ResizeContent', refreshMore);
  23382. return {
  23383. iframeContainer: socket.element().dom(),
  23384. editorContainer: uiComponents.outerContainer.element().dom()
  23385. };
  23386. };
  23387. var Iframe = {
  23388. render: render,
  23389. getBehaviours: function (_) {
  23390. return [];
  23391. }
  23392. };
  23393. var getOrigin = function (element, scroll) {
  23394. return offsetParent(element).orThunk(function () {
  23395. var marker = Element.fromTag('span');
  23396. before(element, marker);
  23397. var offsetParent$1 = offsetParent(marker);
  23398. remove(marker);
  23399. return offsetParent$1;
  23400. }).map(function (offsetP) {
  23401. var loc = absolute(offsetP);
  23402. return loc.translate(-scroll.left(), -scroll.top());
  23403. }).getOrThunk(function () {
  23404. return Position(0, 0);
  23405. });
  23406. };
  23407. var adt$b = Adt.generate([
  23408. {
  23409. offset: [
  23410. 'x',
  23411. 'y'
  23412. ]
  23413. },
  23414. {
  23415. absolute: [
  23416. 'x',
  23417. 'y'
  23418. ]
  23419. },
  23420. {
  23421. fixed: [
  23422. 'x',
  23423. 'y'
  23424. ]
  23425. }
  23426. ]);
  23427. var subtract = function (change) {
  23428. return function (point) {
  23429. return point.translate(-change.left(), -change.top());
  23430. };
  23431. };
  23432. var add$4 = function (change) {
  23433. return function (point) {
  23434. return point.translate(change.left(), change.top());
  23435. };
  23436. };
  23437. var transform$1 = function (changes) {
  23438. return function (x, y) {
  23439. return foldl(changes, function (rest, f) {
  23440. return f(rest);
  23441. }, Position(x, y));
  23442. };
  23443. };
  23444. var asFixed = function (coord, scroll, origin) {
  23445. return coord.fold(transform$1([
  23446. add$4(origin),
  23447. subtract(scroll)
  23448. ]), transform$1([subtract(scroll)]), transform$1([]));
  23449. };
  23450. var asAbsolute = function (coord, scroll, origin) {
  23451. return coord.fold(transform$1([add$4(origin)]), transform$1([]), transform$1([add$4(scroll)]));
  23452. };
  23453. var asOffset = function (coord, scroll, origin) {
  23454. return coord.fold(transform$1([]), transform$1([subtract(origin)]), transform$1([
  23455. add$4(scroll),
  23456. subtract(origin)
  23457. ]));
  23458. };
  23459. var withinRange = function (coord1, coord2, xRange, yRange, scroll, origin) {
  23460. var a1 = asAbsolute(coord1, scroll, origin);
  23461. var a2 = asAbsolute(coord2, scroll, origin);
  23462. return Math.abs(a1.left() - a2.left()) <= xRange && Math.abs(a1.top() - a2.top()) <= yRange;
  23463. };
  23464. var toStyles = function (coord, scroll, origin) {
  23465. return coord.fold(function (x, y) {
  23466. return {
  23467. position: 'absolute',
  23468. left: x + 'px',
  23469. top: y + 'px'
  23470. };
  23471. }, function (x, y) {
  23472. return {
  23473. position: 'absolute',
  23474. left: x - origin.left() + 'px',
  23475. top: y - origin.top() + 'px'
  23476. };
  23477. }, function (x, y) {
  23478. return {
  23479. position: 'fixed',
  23480. left: x + 'px',
  23481. top: y + 'px'
  23482. };
  23483. });
  23484. };
  23485. var translate$1 = function (coord, deltaX, deltaY) {
  23486. return coord.fold(function (x, y) {
  23487. return adt$b.offset(x + deltaX, y + deltaY);
  23488. }, function (x, y) {
  23489. return adt$b.absolute(x + deltaX, y + deltaY);
  23490. }, function (x, y) {
  23491. return adt$b.fixed(x + deltaX, y + deltaY);
  23492. });
  23493. };
  23494. var absorb = function (partialCoord, originalCoord, scroll, origin) {
  23495. var absorbOne = function (stencil, nu) {
  23496. return function (optX, optY) {
  23497. var original = stencil(originalCoord, scroll, origin);
  23498. return nu(optX.getOr(original.left()), optY.getOr(original.top()));
  23499. };
  23500. };
  23501. return partialCoord.fold(absorbOne(asOffset, adt$b.offset), absorbOne(asAbsolute, adt$b.absolute), absorbOne(asFixed, adt$b.fixed));
  23502. };
  23503. var offset = adt$b.offset;
  23504. var absolute$2 = adt$b.absolute;
  23505. var fixed$1 = adt$b.fixed;
  23506. var appear = function (component, contextualInfo) {
  23507. add$2(component.element(), contextualInfo.transitionClass);
  23508. remove$4(component.element(), contextualInfo.fadeOutClass);
  23509. add$2(component.element(), contextualInfo.fadeInClass);
  23510. };
  23511. var disappear = function (component, contextualInfo) {
  23512. add$2(component.element(), contextualInfo.transitionClass);
  23513. remove$4(component.element(), contextualInfo.fadeInClass);
  23514. add$2(component.element(), contextualInfo.fadeOutClass);
  23515. };
  23516. var isPartiallyVisible = function (box, viewport) {
  23517. return box.y() < viewport.bottom() && box.bottom() > viewport.y();
  23518. };
  23519. var isCompletelyVisible = function (box, viewport) {
  23520. return box.y() >= viewport.y() && box.bottom() <= viewport.bottom();
  23521. };
  23522. var getAttr = function (elem, attr) {
  23523. return has$1(elem, attr) ? Option.some(parseInt(get$2(elem, attr), 10)) : Option.none();
  23524. };
  23525. var getPrior = function (component, dockInfo) {
  23526. var elem = component.element();
  23527. return getAttr(elem, dockInfo.leftAttr).bind(function (left) {
  23528. return getAttr(elem, dockInfo.topAttr).map(function (top) {
  23529. var w = get$7(component.element());
  23530. var h = get$8(component.element());
  23531. return bounds(left, top, w, h);
  23532. });
  23533. });
  23534. };
  23535. var setPrior = function (component, dockInfo, absLeft, absTop) {
  23536. var elem = component.element();
  23537. set$1(elem, dockInfo.leftAttr, absLeft);
  23538. set$1(elem, dockInfo.topAttr, absTop);
  23539. };
  23540. var clearPrior = function (component, dockInfo) {
  23541. var elem = component.element();
  23542. remove$1(elem, dockInfo.leftAttr);
  23543. remove$1(elem, dockInfo.topAttr);
  23544. };
  23545. var morphToAbsolute = function (component, dockInfo, viewport) {
  23546. return getPrior(component, dockInfo).bind(function (box) {
  23547. if (isCompletelyVisible(box, viewport)) {
  23548. clearPrior(component, dockInfo);
  23549. return Option.some(absolute$2(box.x(), box.y()));
  23550. } else {
  23551. return Option.none();
  23552. }
  23553. });
  23554. };
  23555. var morphToFixed = function (component, dockInfo, viewport, scroll, origin) {
  23556. var loc = absolute(component.element());
  23557. var box = bounds(loc.left(), loc.top(), get$7(component.element()), get$8(component.element()));
  23558. if (!isCompletelyVisible(box, viewport)) {
  23559. setPrior(component, dockInfo, loc.left(), loc.top());
  23560. var coord = absolute$2(loc.left(), loc.top());
  23561. var asFixed$1 = asFixed(coord, scroll, origin);
  23562. var viewportPt = absolute$2(viewport.x(), viewport.y());
  23563. var fixedViewport = asFixed(viewportPt, scroll, origin);
  23564. var fixedY = box.y() <= viewport.y() ? fixedViewport.top() : fixedViewport.top() + viewport.height() - box.height();
  23565. return Option.some(fixed$1(asFixed$1.left(), fixedY));
  23566. } else {
  23567. return Option.none();
  23568. }
  23569. };
  23570. var getMorph = function (component, dockInfo, viewport, scroll, origin) {
  23571. var isDocked = getRaw(component.element(), 'position').is('fixed');
  23572. return isDocked ? morphToAbsolute(component, dockInfo, viewport) : morphToFixed(component, dockInfo, viewport, scroll, origin);
  23573. };
  23574. var refresh$2 = function (component, config, state) {
  23575. var viewport = config.lazyViewport(component);
  23576. config.contextual.each(function (contextInfo) {
  23577. contextInfo.lazyContext(component).each(function (elem) {
  23578. var box$1 = box(elem);
  23579. var isVisible = isPartiallyVisible(box$1, viewport);
  23580. var method = isVisible ? appear : disappear;
  23581. method(component, contextInfo);
  23582. });
  23583. });
  23584. var doc = owner(component.element());
  23585. var scroll = get$6(doc);
  23586. var origin = getOrigin(component.element(), scroll);
  23587. getMorph(component, config, viewport, scroll, origin).each(function (morph) {
  23588. var styles = toStyles(morph, scroll, origin);
  23589. setAll$1(component.element(), styles);
  23590. });
  23591. };
  23592. var DockingApis = /*#__PURE__*/Object.freeze({
  23593. refresh: refresh$2
  23594. });
  23595. var events$f = function (dockInfo, dockState) {
  23596. return derive([
  23597. run(transitionend(), function (component, simulatedEvent) {
  23598. dockInfo.contextual.each(function (contextInfo) {
  23599. if (eq(component.element(), simulatedEvent.event().target())) {
  23600. remove$4(component.element(), contextInfo.transitionClass);
  23601. simulatedEvent.stop();
  23602. }
  23603. });
  23604. }),
  23605. run(windowScroll(), function (component, _) {
  23606. refresh$2(component, dockInfo, dockState);
  23607. })
  23608. ]);
  23609. };
  23610. var ActiveDocking = /*#__PURE__*/Object.freeze({
  23611. events: events$f
  23612. });
  23613. var defaultLazyViewport = function (_component) {
  23614. var scroll = get$6();
  23615. return bounds(scroll.left(), scroll.top(), domGlobals.window.innerWidth, domGlobals.window.innerHeight);
  23616. };
  23617. var DockingSchema = [
  23618. optionObjOf('contextual', [
  23619. strict$1('fadeInClass'),
  23620. strict$1('fadeOutClass'),
  23621. strict$1('transitionClass'),
  23622. strict$1('lazyContext')
  23623. ]),
  23624. defaulted$1('lazyViewport', defaultLazyViewport),
  23625. strict$1('leftAttr'),
  23626. strict$1('topAttr')
  23627. ];
  23628. var Docking = create$1({
  23629. fields: DockingSchema,
  23630. name: 'docking',
  23631. active: ActiveDocking,
  23632. apis: DockingApis
  23633. });
  23634. var render$1 = function (editor, uiComponents, rawUiConfig, backstage, args) {
  23635. var floatContainer;
  23636. var DOM = global$4.DOM;
  23637. inline(editor);
  23638. var split = isSplitToolbar(editor);
  23639. var calcPosition = function (offset) {
  23640. if (offset === void 0) {
  23641. offset = 0;
  23642. }
  23643. var location = absolute(Element.fromDom(editor.getBody()));
  23644. return {
  23645. top: Math.round(location.top() - get$8(floatContainer.element())) + offset + 'px',
  23646. left: Math.round(location.left()) + 'px'
  23647. };
  23648. };
  23649. var setPosition = function () {
  23650. var toolbar = OuterContainer.getToolbar(uiComponents.outerContainer);
  23651. if (split) {
  23652. toolbar.each(SplitToolbar.refresh);
  23653. }
  23654. var isDocked = getRaw(floatContainer.element(), 'position').is('fixed');
  23655. if (!isDocked) {
  23656. var offset = split ? toolbar.fold(function () {
  23657. return 0;
  23658. }, function (tbar) {
  23659. return get$8(tbar.components()[1].element());
  23660. }) : 0;
  23661. setAll$1(floatContainer.element(), calcPosition(offset));
  23662. }
  23663. Docking.refresh(floatContainer);
  23664. };
  23665. var show = function () {
  23666. set$2(uiComponents.outerContainer.element(), 'display', 'flex');
  23667. DOM.addClass(editor.getBody(), 'mce-edit-focus');
  23668. setPosition();
  23669. Docking.refresh(floatContainer);
  23670. };
  23671. var hide = function () {
  23672. if (uiComponents.outerContainer) {
  23673. set$2(uiComponents.outerContainer.element(), 'display', 'none');
  23674. DOM.removeClass(editor.getBody(), 'mce-edit-focus');
  23675. }
  23676. };
  23677. var render = function () {
  23678. if (floatContainer) {
  23679. show();
  23680. return;
  23681. }
  23682. floatContainer = uiComponents.outerContainer;
  23683. attachSystem(body(), uiComponents.mothership);
  23684. attachSystem(body(), uiComponents.uiMothership);
  23685. OuterContainer.setToolbar(uiComponents.outerContainer, identifyButtons(editor, rawUiConfig, { backstage: backstage }));
  23686. OuterContainer.setMenubar(uiComponents.outerContainer, identifyMenus(editor, rawUiConfig));
  23687. set$2(floatContainer.element(), 'position', 'absolute');
  23688. setPosition();
  23689. show();
  23690. editor.on('nodeChange ResizeWindow', setPosition);
  23691. editor.on('activate', show);
  23692. editor.on('deactivate', hide);
  23693. editor.nodeChanged();
  23694. };
  23695. editor.on('focus', render);
  23696. editor.on('blur hide', hide);
  23697. editor.on('init', function () {
  23698. if (editor.hasFocus()) {
  23699. render();
  23700. }
  23701. });
  23702. return { editorContainer: uiComponents.outerContainer.element().dom() };
  23703. };
  23704. var getBehaviours$2 = function (editor) {
  23705. return [
  23706. Docking.config({
  23707. leftAttr: 'data-dock-left',
  23708. topAttr: 'data-dock-top',
  23709. contextual: {
  23710. lazyContext: function (_) {
  23711. return Option.from(editor).map(function (ed) {
  23712. return Element.fromDom(ed.getBody());
  23713. });
  23714. },
  23715. fadeInClass: 'tox-toolbar-dock-fadein',
  23716. fadeOutClass: 'tox-toolbar-dock-fadeout',
  23717. transitionClass: 'tox-toolbar-dock-transition'
  23718. }
  23719. }),
  23720. Focusing.config({})
  23721. ];
  23722. };
  23723. var Inline = {
  23724. render: render$1,
  23725. getBehaviours: getBehaviours$2
  23726. };
  23727. var nu$d = function (x, y) {
  23728. return {
  23729. anchor: 'makeshift',
  23730. x: x,
  23731. y: y
  23732. };
  23733. };
  23734. var transpose$1 = function (pos, dx, dy) {
  23735. return nu$d(pos.x + dx, pos.y + dy);
  23736. };
  23737. var fromPageXY = function (e) {
  23738. return nu$d(e.pageX, e.pageY);
  23739. };
  23740. var fromClientXY = function (e) {
  23741. return nu$d(e.clientX, e.clientY);
  23742. };
  23743. var transposeContentAreaContainer = function (element, pos) {
  23744. var containerPos = global$4.DOM.getPos(element);
  23745. return transpose$1(pos, containerPos.x, containerPos.y);
  23746. };
  23747. var getPointAnchor = function (editor, e) {
  23748. if (e.type === 'contextmenu') {
  23749. if (editor.inline) {
  23750. return fromPageXY(e);
  23751. } else {
  23752. return transposeContentAreaContainer(editor.getContentAreaContainer(), fromClientXY(e));
  23753. }
  23754. } else {
  23755. return getSelectionAnchor(editor);
  23756. }
  23757. };
  23758. var getSelectionAnchor = function (editor) {
  23759. return {
  23760. anchor: 'selection',
  23761. root: Element.fromDom(editor.selection.getNode())
  23762. };
  23763. };
  23764. var getNodeAnchor = function (editor) {
  23765. return {
  23766. anchor: 'node',
  23767. node: Option.some(Element.fromDom(editor.selection.getNode())),
  23768. root: Element.fromDom(editor.getBody())
  23769. };
  23770. };
  23771. var patchPipeConfig = function (config) {
  23772. return typeof config === 'string' ? config.split(/[ ,]/) : config;
  23773. };
  23774. var shouldNeverUseNative = function (editor) {
  23775. return editor.settings.contextmenu_never_use_native || false;
  23776. };
  23777. var getMenuItems = function (editor, name, defaultItems) {
  23778. var contextMenus = editor.ui.registry.getAll().contextMenus;
  23779. return get(editor.settings, name).map(patchPipeConfig).getOrThunk(function () {
  23780. return filter(patchPipeConfig(defaultItems), function (item) {
  23781. return has(contextMenus, item);
  23782. });
  23783. });
  23784. };
  23785. var getContextMenu = function (editor) {
  23786. return getMenuItems(editor, 'contextmenu', 'link image imagetools table spellchecker configurepermanentpen');
  23787. };
  23788. var Settings$1 = {
  23789. shouldNeverUseNative: shouldNeverUseNative,
  23790. getContextMenu: getContextMenu
  23791. };
  23792. var isSeparator$1 = function (item) {
  23793. return isString(item) ? item === '|' : item.type === 'separator';
  23794. };
  23795. var separator$3 = { type: 'separator' };
  23796. var makeContextItem = function (item) {
  23797. if (isString(item)) {
  23798. return item;
  23799. } else {
  23800. switch (item.type) {
  23801. case 'separator':
  23802. return separator$3;
  23803. case 'submenu':
  23804. return {
  23805. type: 'nestedmenuitem',
  23806. text: item.text,
  23807. icon: item.icon,
  23808. getSubmenuItems: function () {
  23809. var items = item.getSubmenuItems();
  23810. if (isString(items)) {
  23811. return items;
  23812. } else {
  23813. return map(items, makeContextItem);
  23814. }
  23815. }
  23816. };
  23817. default:
  23818. return {
  23819. type: 'menuitem',
  23820. text: item.text,
  23821. icon: item.icon,
  23822. onAction: noarg(item.onAction)
  23823. };
  23824. }
  23825. }
  23826. };
  23827. var addContextMenuGroup = function (xs, groupItems) {
  23828. if (groupItems.length === 0) {
  23829. return xs;
  23830. }
  23831. var lastMenuItem = last(xs).filter(function (item) {
  23832. return !isSeparator$1(item);
  23833. });
  23834. var before = lastMenuItem.fold(function () {
  23835. return [];
  23836. }, function (_) {
  23837. return [separator$3];
  23838. });
  23839. return xs.concat(before).concat(groupItems).concat([separator$3]);
  23840. };
  23841. var generateContextMenu = function (contextMenus, menuConfig, selectedElement) {
  23842. var items = foldl(menuConfig, function (acc, name) {
  23843. if (has(contextMenus, name)) {
  23844. var items_1 = contextMenus[name].update(selectedElement);
  23845. if (isString(items_1)) {
  23846. return addContextMenuGroup(acc, items_1.split(' '));
  23847. } else if (items_1.length > 0) {
  23848. var allItems = map(items_1, makeContextItem);
  23849. return addContextMenuGroup(acc, allItems);
  23850. } else {
  23851. return acc;
  23852. }
  23853. } else {
  23854. return acc.concat([name]);
  23855. }
  23856. }, []);
  23857. if (items.length > 0 && isSeparator$1(items[items.length - 1])) {
  23858. items.pop();
  23859. }
  23860. return items;
  23861. };
  23862. var isNativeOverrideKeyEvent = function (editor, e) {
  23863. return e.ctrlKey && !Settings$1.shouldNeverUseNative(editor);
  23864. };
  23865. var setup$5 = function (editor, lazySink, sharedBackstage) {
  23866. var contextmenu = build$1(InlineView.sketch({
  23867. dom: { tag: 'div' },
  23868. lazySink: lazySink,
  23869. onEscape: function () {
  23870. return editor.focus();
  23871. },
  23872. fireDismissalEventInstead: {},
  23873. inlineBehaviours: derive$1([config('dismissContextMenu', [run(dismissRequested(), function (comp, se) {
  23874. Sandboxing.close(comp);
  23875. editor.focus();
  23876. })])])
  23877. }));
  23878. editor.on('init', function () {
  23879. editor.on('contextmenu', function (e) {
  23880. if (isNativeOverrideKeyEvent(editor, e)) {
  23881. return;
  23882. }
  23883. var isTriggeredByKeyboardEvent = e.button !== 2 || e.target === editor.getBody();
  23884. var anchorSpec = isTriggeredByKeyboardEvent ? getNodeAnchor(editor) : getPointAnchor(editor, e);
  23885. var registry = editor.ui.registry.getAll();
  23886. var menuConfig = Settings$1.getContextMenu(editor);
  23887. var selectedElement = isTriggeredByKeyboardEvent ? editor.selection.getStart(true) : e.target;
  23888. var items = generateContextMenu(registry.contextMenus, menuConfig, selectedElement);
  23889. build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, sharedBackstage.providers).map(function (menuData) {
  23890. e.preventDefault();
  23891. InlineView.showMenuAt(contextmenu, anchorSpec, {
  23892. menu: { markers: markers$1('normal') },
  23893. data: menuData
  23894. });
  23895. });
  23896. });
  23897. });
  23898. };
  23899. var parseToInt = function (val) {
  23900. var re = /^[0-9\.]+(|px)$/i;
  23901. if (re.test('' + val)) {
  23902. return Option.some(parseInt(val, 10));
  23903. }
  23904. return Option.none();
  23905. };
  23906. var numToPx = function (val) {
  23907. return isNumber(val) ? val + 'px' : val;
  23908. };
  23909. var Utils = {
  23910. parseToInt: parseToInt,
  23911. numToPx: numToPx
  23912. };
  23913. var initialAttribute = 'data-initial-z-index';
  23914. var resetZIndex = function (blocker) {
  23915. parent(blocker.element()).each(function (root) {
  23916. var initZIndex = get$2(root, initialAttribute);
  23917. if (has$1(root, initialAttribute)) {
  23918. set$2(root, 'z-index', initZIndex);
  23919. } else {
  23920. remove$6(root, 'z-index');
  23921. }
  23922. remove$1(root, initialAttribute);
  23923. });
  23924. };
  23925. var changeZIndex = function (blocker) {
  23926. parent(blocker.element()).each(function (root) {
  23927. getRaw(root, 'z-index').each(function (zindex) {
  23928. set$1(root, initialAttribute, zindex);
  23929. });
  23930. set$2(root, 'z-index', get$4(blocker.element(), 'z-index'));
  23931. });
  23932. };
  23933. var instigate = function (anyComponent, blocker) {
  23934. anyComponent.getSystem().addToGui(blocker);
  23935. changeZIndex(blocker);
  23936. };
  23937. var discard = function (blocker) {
  23938. resetZIndex(blocker);
  23939. blocker.getSystem().removeFromGui(blocker);
  23940. };
  23941. var get$d = function (component, snapsInfo) {
  23942. var element = component.element();
  23943. var x = parseInt(get$2(element, snapsInfo.leftAttr), 10);
  23944. var y = parseInt(get$2(element, snapsInfo.topAttr), 10);
  23945. return isNaN(x) || isNaN(y) ? Option.none() : Option.some(Position(x, y));
  23946. };
  23947. var set$7 = function (component, snapsInfo, pt) {
  23948. var element = component.element();
  23949. set$1(element, snapsInfo.leftAttr, pt.left() + 'px');
  23950. set$1(element, snapsInfo.topAttr, pt.top() + 'px');
  23951. };
  23952. var clear = function (component, snapsInfo) {
  23953. var element = component.element();
  23954. remove$1(element, snapsInfo.leftAttr);
  23955. remove$1(element, snapsInfo.topAttr);
  23956. };
  23957. var getCoords = function (component, snapInfo, coord, delta) {
  23958. return get$d(component, snapInfo).fold(function () {
  23959. return coord;
  23960. }, function (fixed) {
  23961. return fixed$1(fixed.left() + delta.left(), fixed.top() + delta.top());
  23962. });
  23963. };
  23964. var moveOrSnap = function (component, snapInfo, coord, delta, scroll, origin) {
  23965. var newCoord = getCoords(component, snapInfo, coord, delta);
  23966. var snap = findSnap(component, snapInfo, newCoord, scroll, origin);
  23967. var fixedCoord = asFixed(newCoord, scroll, origin);
  23968. set$7(component, snapInfo, fixedCoord);
  23969. return snap.fold(function () {
  23970. return {
  23971. coord: fixed$1(fixedCoord.left(), fixedCoord.top()),
  23972. extra: Option.none()
  23973. };
  23974. }, function (spanned) {
  23975. return {
  23976. coord: spanned.output(),
  23977. extra: spanned.extra()
  23978. };
  23979. });
  23980. };
  23981. var stopDrag = function (component, snapInfo) {
  23982. clear(component, snapInfo);
  23983. };
  23984. var findSnap = function (component, snapInfo, newCoord, scroll, origin) {
  23985. var snaps = snapInfo.getSnapPoints(component);
  23986. return findMap(snaps, function (snap) {
  23987. var sensor = snap.sensor();
  23988. var inRange = withinRange(newCoord, sensor, snap.range().left(), snap.range().top(), scroll, origin);
  23989. return inRange ? Option.some({
  23990. output: constant(absorb(snap.output(), newCoord, scroll, origin)),
  23991. extra: snap.extra
  23992. }) : Option.none();
  23993. });
  23994. };
  23995. var getCurrentCoord = function (target) {
  23996. return getRaw(target, 'left').bind(function (left) {
  23997. return getRaw(target, 'top').bind(function (top) {
  23998. return getRaw(target, 'position').map(function (position) {
  23999. var nu = position === 'fixed' ? fixed$1 : offset;
  24000. return nu(parseInt(left, 10), parseInt(top, 10));
  24001. });
  24002. });
  24003. }).getOrThunk(function () {
  24004. var location = absolute(target);
  24005. return absolute$2(location.left(), location.top());
  24006. });
  24007. };
  24008. var calcNewCoord = function (component, optSnaps, currentCoord, scroll, origin, delta) {
  24009. return optSnaps.fold(function () {
  24010. var translated = translate$1(currentCoord, delta.left(), delta.top());
  24011. var fixedCoord = asFixed(translated, scroll, origin);
  24012. return fixed$1(fixedCoord.left(), fixedCoord.top());
  24013. }, function (snapInfo) {
  24014. var snapping = moveOrSnap(component, snapInfo, currentCoord, delta, scroll, origin);
  24015. snapping.extra.each(function (extra) {
  24016. snapInfo.onSensor(component, extra);
  24017. });
  24018. return snapping.coord;
  24019. });
  24020. };
  24021. var dragBy = function (component, dragConfig, delta) {
  24022. var target = dragConfig.getTarget(component.element());
  24023. if (dragConfig.repositionTarget) {
  24024. var doc = owner(component.element());
  24025. var scroll = get$6(doc);
  24026. var origin = getOrigin(target, scroll);
  24027. var currentCoord = getCurrentCoord(target);
  24028. var newCoord = calcNewCoord(component, dragConfig.snaps, currentCoord, scroll, origin, delta);
  24029. var styles = toStyles(newCoord, scroll, origin);
  24030. setAll$1(target, styles);
  24031. }
  24032. dragConfig.onDrag(component, target, delta);
  24033. };
  24034. var defaultLazyViewport$1 = function () {
  24035. var scroll = get$6();
  24036. return {
  24037. x: scroll.left,
  24038. y: scroll.top,
  24039. width: constant(domGlobals.window.innerWidth),
  24040. height: constant(domGlobals.window.innerHeight),
  24041. bottom: constant(scroll.top() + domGlobals.window.innerHeight),
  24042. right: constant(scroll.left() + domGlobals.window.innerWidth)
  24043. };
  24044. };
  24045. var SnapSchema = optionObjOf('snaps', [
  24046. strict$1('getSnapPoints'),
  24047. onHandler('onSensor'),
  24048. strict$1('leftAttr'),
  24049. strict$1('topAttr'),
  24050. defaulted$1('lazyViewport', defaultLazyViewport$1)
  24051. ]);
  24052. var init$c = function (dragApi) {
  24053. return derive([
  24054. run(mousedown(), dragApi.forceDrop),
  24055. run(mouseup(), dragApi.drop),
  24056. run(mousemove(), function (comp, simulatedEvent) {
  24057. dragApi.move(simulatedEvent.event());
  24058. }),
  24059. run(mouseout(), dragApi.delayDrop)
  24060. ]);
  24061. };
  24062. var getData$1 = function (event) {
  24063. return Option.from(Position(event.x(), event.y()));
  24064. };
  24065. var getDelta$1 = function (old, nu) {
  24066. return Position(nu.left() - old.left(), nu.top() - old.top());
  24067. };
  24068. var MouseData = /*#__PURE__*/Object.freeze({
  24069. getData: getData$1,
  24070. getDelta: getDelta$1
  24071. });
  24072. var handlers = function (dragConfig, dragState) {
  24073. return derive([run(mousedown(), function (component, simulatedEvent) {
  24074. var raw = simulatedEvent.event().raw();
  24075. if (raw.button !== 0) {
  24076. return;
  24077. }
  24078. simulatedEvent.stop();
  24079. var dragApi = {
  24080. drop: function () {
  24081. stop();
  24082. },
  24083. delayDrop: function () {
  24084. delayDrop.schedule();
  24085. },
  24086. forceDrop: function () {
  24087. stop();
  24088. },
  24089. move: function (event) {
  24090. delayDrop.cancel();
  24091. var delta = dragState.update(MouseData, event);
  24092. delta.each(function (dlt) {
  24093. dragBy(component, dragConfig, dlt);
  24094. });
  24095. }
  24096. };
  24097. var blocker = component.getSystem().build(Container.sketch({
  24098. dom: {
  24099. styles: {
  24100. 'left': '0px',
  24101. 'top': '0px',
  24102. 'width': '100%',
  24103. 'height': '100%',
  24104. 'position': 'fixed',
  24105. 'z-index': '1000000000000000'
  24106. },
  24107. classes: [dragConfig.blockerClass]
  24108. },
  24109. events: init$c(dragApi)
  24110. }));
  24111. var stop = function () {
  24112. discard(blocker);
  24113. dragConfig.snaps.each(function (snapInfo) {
  24114. stopDrag(component, snapInfo);
  24115. });
  24116. var target = dragConfig.getTarget(component.element());
  24117. dragConfig.onDrop(component, target);
  24118. };
  24119. var delayDrop = DelayedFunction(stop, 200);
  24120. var start = function () {
  24121. dragState.reset();
  24122. instigate(component, blocker);
  24123. };
  24124. start();
  24125. })]);
  24126. };
  24127. var schema$o = [
  24128. defaulted$1('useFixed', false),
  24129. strict$1('blockerClass'),
  24130. defaulted$1('getTarget', identity),
  24131. defaulted$1('onDrag', noop),
  24132. defaulted$1('repositionTarget', true),
  24133. onHandler('onDrop'),
  24134. SnapSchema,
  24135. output('dragger', { handlers: handlers })
  24136. ];
  24137. var getDataFrom = function (touches) {
  24138. var touch = touches[0];
  24139. return Option.some(Position(touch.clientX, touch.clientY));
  24140. };
  24141. var getData$2 = function (event) {
  24142. var raw = event.raw();
  24143. var touches = raw.touches;
  24144. return touches.length === 1 ? getDataFrom(touches) : Option.none();
  24145. };
  24146. var getDelta$2 = function (old, nu) {
  24147. return Position(nu.left() - old.left(), nu.top() - old.top());
  24148. };
  24149. var TouchData = /*#__PURE__*/Object.freeze({
  24150. getData: getData$2,
  24151. getDelta: getDelta$2
  24152. });
  24153. var handlers$1 = function (dragConfig, dragState) {
  24154. return derive([
  24155. stopper(touchstart()),
  24156. run(touchmove(), function (component, simulatedEvent) {
  24157. simulatedEvent.stop();
  24158. var delta = dragState.update(TouchData, simulatedEvent.event());
  24159. delta.each(function (dlt) {
  24160. dragBy(component, dragConfig, dlt);
  24161. });
  24162. }),
  24163. run(touchend(), function (component, simulatedEvent) {
  24164. dragConfig.snaps.each(function (snapInfo) {
  24165. stopDrag(component, snapInfo);
  24166. });
  24167. var target = dragConfig.getTarget(component.element());
  24168. dragState.reset();
  24169. dragConfig.onDrop(component, target);
  24170. })
  24171. ]);
  24172. };
  24173. var schema$p = [
  24174. defaulted$1('useFixed', false),
  24175. defaulted$1('getTarget', identity),
  24176. defaulted$1('onDrag', noop),
  24177. defaulted$1('repositionTarget', true),
  24178. defaulted$1('onDrop', noop),
  24179. SnapSchema,
  24180. output('dragger', { handlers: handlers$1 })
  24181. ];
  24182. var mouse = schema$o;
  24183. var touch = schema$p;
  24184. var DraggingBranches = /*#__PURE__*/Object.freeze({
  24185. mouse: mouse,
  24186. touch: touch
  24187. });
  24188. var init$d = function () {
  24189. var previous = Option.none();
  24190. var reset = function () {
  24191. previous = Option.none();
  24192. };
  24193. var calculateDelta = function (mode, nu) {
  24194. var result = previous.map(function (old) {
  24195. return mode.getDelta(old, nu);
  24196. });
  24197. previous = Option.some(nu);
  24198. return result;
  24199. };
  24200. var update = function (mode, dragEvent) {
  24201. return mode.getData(dragEvent).bind(function (nuData) {
  24202. return calculateDelta(mode, nuData);
  24203. });
  24204. };
  24205. var readState = constant({});
  24206. return nu$5({
  24207. readState: readState,
  24208. reset: reset,
  24209. update: update
  24210. });
  24211. };
  24212. var DragState = /*#__PURE__*/Object.freeze({
  24213. init: init$d
  24214. });
  24215. var Dragging = createModes$1({
  24216. branchKey: 'mode',
  24217. branches: DraggingBranches,
  24218. name: 'dragging',
  24219. active: {
  24220. events: function (dragConfig, dragState) {
  24221. var dragger = dragConfig.dragger;
  24222. return dragger.handlers(dragConfig, dragState);
  24223. }
  24224. },
  24225. extra: {
  24226. snap: MixedBag([
  24227. 'sensor',
  24228. 'range',
  24229. 'output'
  24230. ], ['extra'])
  24231. },
  24232. state: DragState
  24233. });
  24234. var ResizeTypes;
  24235. (function (ResizeTypes) {
  24236. ResizeTypes[ResizeTypes['None'] = 0] = 'None';
  24237. ResizeTypes[ResizeTypes['Both'] = 1] = 'Both';
  24238. ResizeTypes[ResizeTypes['Vertical'] = 2] = 'Vertical';
  24239. }(ResizeTypes || (ResizeTypes = {})));
  24240. var calcCappedSize = function (originalSize, delta, minSize, maxSize) {
  24241. var newSize = originalSize + delta;
  24242. var minOverride = minSize.filter(function (min) {
  24243. return newSize < min;
  24244. });
  24245. var maxOverride = maxSize.filter(function (max) {
  24246. return newSize > max;
  24247. });
  24248. return minOverride.or(maxOverride).getOr(newSize);
  24249. };
  24250. var getDimensions = function (editor, deltas, resizeType, originalHeight, originalWidth) {
  24251. var dimensions = {};
  24252. dimensions.height = calcCappedSize(originalHeight, deltas.top(), getMinHeightSetting(editor), getMaxHeightSetting(editor));
  24253. if (resizeType === ResizeTypes.Both) {
  24254. dimensions.width = calcCappedSize(originalWidth, deltas.left(), getMinWidthSetting(editor), getMaxWidthSetting(editor));
  24255. }
  24256. return dimensions;
  24257. };
  24258. var resize$3 = function (editor, deltas, resizeType) {
  24259. var container = Element.fromDom(editor.getContainer());
  24260. var dimensions = getDimensions(editor, deltas, resizeType, get$8(container), get$7(container));
  24261. each$1(dimensions, function (val, dim) {
  24262. return set$2(container, dim, Utils.numToPx(val));
  24263. });
  24264. Events$1.fireResizeEditor(editor);
  24265. };
  24266. var isHidden$1 = function (elm) {
  24267. if (elm.nodeType === 1) {
  24268. if (elm.nodeName === 'BR' || !!elm.getAttribute('data-mce-bogus')) {
  24269. return true;
  24270. }
  24271. if (elm.getAttribute('data-mce-type') === 'bookmark') {
  24272. return true;
  24273. }
  24274. }
  24275. return false;
  24276. };
  24277. var renderElementPath = function (editor, settings) {
  24278. if (!settings.delimiter) {
  24279. settings.delimiter = '\xBB';
  24280. }
  24281. var getDataPath = function (data) {
  24282. var parts = data || [];
  24283. var newPathElements = map(parts, function (part, index) {
  24284. return Button.sketch({
  24285. dom: {
  24286. tag: 'div',
  24287. classes: ['tox-statusbar__path-item'],
  24288. attributes: {
  24289. 'role': 'button',
  24290. 'data-index': index,
  24291. 'tab-index': -1,
  24292. 'aria-level': index + 1
  24293. },
  24294. innerHtml: part.name
  24295. },
  24296. action: function (btn) {
  24297. editor.focus();
  24298. editor.selection.select(part.element);
  24299. editor.nodeChanged();
  24300. }
  24301. });
  24302. });
  24303. var divider = {
  24304. dom: {
  24305. tag: 'div',
  24306. classes: ['tox-statusbar__path-divider'],
  24307. attributes: { 'aria-hidden': true },
  24308. innerHtml: ' ' + settings.delimiter + ' '
  24309. }
  24310. };
  24311. return foldl(newPathElements.slice(1), function (acc, element) {
  24312. var newAcc = acc;
  24313. newAcc.push(divider);
  24314. newAcc.push(element);
  24315. return newAcc;
  24316. }, [newPathElements[0]]);
  24317. };
  24318. var updatePath = function (parents) {
  24319. var newPath = [];
  24320. var i = parents.length;
  24321. while (i-- > 0) {
  24322. var parent = parents[i];
  24323. if (parent.nodeType === 1 && !isHidden$1(parent)) {
  24324. var args = editor.fire('ResolveName', {
  24325. name: parent.nodeName.toLowerCase(),
  24326. target: parent
  24327. });
  24328. if (!args.isDefaultPrevented()) {
  24329. newPath.push({
  24330. name: args.name,
  24331. element: parent
  24332. });
  24333. }
  24334. if (args.isPropagationStopped()) {
  24335. break;
  24336. }
  24337. }
  24338. }
  24339. return newPath;
  24340. };
  24341. return {
  24342. dom: {
  24343. tag: 'div',
  24344. classes: ['tox-statusbar__path'],
  24345. attributes: { role: 'navigation' }
  24346. },
  24347. behaviours: derive$1([
  24348. Keying.config({
  24349. mode: 'flow',
  24350. selector: 'div[role=button]'
  24351. }),
  24352. Tabstopping.config({}),
  24353. Replacing.config({}),
  24354. config('elementPathEvents', [runOnAttached(function (comp, e) {
  24355. editor.shortcuts.add('alt+F11', 'focus statusbar elementpath', function () {
  24356. return Keying.focusIn(comp);
  24357. });
  24358. editor.on('nodeChange', function (e) {
  24359. var newPath = updatePath(e.parents);
  24360. if (newPath.length > 0) {
  24361. Replacing.set(comp, getDataPath(newPath));
  24362. }
  24363. });
  24364. })])
  24365. ]),
  24366. components: []
  24367. };
  24368. };
  24369. var ElementPath = { renderElementPath: renderElementPath };
  24370. var renderWordCount = function (editor, providersBackstage) {
  24371. var _a;
  24372. var replaceCountText = function (comp, count, mode) {
  24373. return Replacing.set(comp, [text(providersBackstage.translate([
  24374. '{0} ' + mode,
  24375. count[mode]
  24376. ]))]);
  24377. };
  24378. return Button.sketch({
  24379. dom: {
  24380. tag: 'button',
  24381. classes: ['tox-statusbar__wordcount']
  24382. },
  24383. components: [],
  24384. buttonBehaviours: derive$1([
  24385. Tabstopping.config({}),
  24386. Replacing.config({}),
  24387. Representing.config({
  24388. store: {
  24389. mode: 'memory',
  24390. initialValue: {
  24391. mode: 'words',
  24392. count: {
  24393. words: 0,
  24394. characters: 0
  24395. }
  24396. }
  24397. }
  24398. }),
  24399. config('wordcount-events', [
  24400. run(click(), function (comp) {
  24401. var currentVal = Representing.getValue(comp);
  24402. var newMode = currentVal.mode === 'words' ? 'characters' : 'words';
  24403. Representing.setValue(comp, {
  24404. mode: newMode,
  24405. count: currentVal.count
  24406. });
  24407. replaceCountText(comp, currentVal.count, newMode);
  24408. }),
  24409. runOnAttached(function (comp) {
  24410. editor.on('wordCountUpdate', function (e) {
  24411. var mode = Representing.getValue(comp).mode;
  24412. Representing.setValue(comp, {
  24413. mode: mode,
  24414. count: e.wordCount
  24415. });
  24416. replaceCountText(comp, e.wordCount, mode);
  24417. });
  24418. })
  24419. ])
  24420. ]),
  24421. eventOrder: (_a = {}, _a[click()] = [
  24422. 'wordcount-events',
  24423. 'alloy.base.behaviour'
  24424. ], _a)
  24425. });
  24426. };
  24427. var renderStatusbar = function (editor, providersBackstage) {
  24428. var renderResizeHandlerIcon = function (resizeType) {
  24429. return {
  24430. dom: {
  24431. tag: 'div',
  24432. classes: ['tox-statusbar__resize-handle'],
  24433. attributes: { title: providersBackstage.translate('Resize') },
  24434. innerHtml: get$c('resize-handle', providersBackstage.icons)
  24435. },
  24436. behaviours: derive$1([Dragging.config({
  24437. mode: 'mouse',
  24438. repositionTarget: false,
  24439. onDrag: function (comp, target, delta) {
  24440. resize$3(editor, delta, resizeType);
  24441. },
  24442. blockerClass: 'tox-blocker'
  24443. })])
  24444. };
  24445. };
  24446. var renderBranding = function () {
  24447. var label = global$2.translate([
  24448. 'Powered by {0}',
  24449. 'Tiny'
  24450. ]);
  24451. 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 + '">Tiny</a>';
  24452. var html = global$2.translate([
  24453. 'Powered by {0}',
  24454. linkHtml
  24455. ]);
  24456. return {
  24457. dom: {
  24458. tag: 'span',
  24459. classes: ['tox-statusbar__branding'],
  24460. innerHtml: html
  24461. }
  24462. };
  24463. };
  24464. var getResizeType = function (editor) {
  24465. var fallback = !contains$1(editor.settings.plugins, 'autoresize');
  24466. var resize = editor.getParam('resize', fallback);
  24467. if (resize === false) {
  24468. return ResizeTypes.None;
  24469. } else if (resize === 'both') {
  24470. return ResizeTypes.Both;
  24471. } else {
  24472. return ResizeTypes.Vertical;
  24473. }
  24474. };
  24475. var getTextComponents = function () {
  24476. var components = [];
  24477. if (editor.getParam('elementpath', true, 'boolean')) {
  24478. components.push(ElementPath.renderElementPath(editor, {}));
  24479. }
  24480. if (contains$1(editor.settings.plugins, 'wordcount')) {
  24481. components.push(renderWordCount(editor, providersBackstage));
  24482. }
  24483. if (editor.getParam('branding', true, 'boolean')) {
  24484. components.push(renderBranding());
  24485. }
  24486. if (components.length > 0) {
  24487. return [{
  24488. dom: {
  24489. tag: 'div',
  24490. classes: ['tox-statusbar__text-container']
  24491. },
  24492. components: components
  24493. }];
  24494. }
  24495. return [];
  24496. };
  24497. var getComponents = function () {
  24498. var components = getTextComponents();
  24499. var resizeType = getResizeType(editor);
  24500. if (resizeType !== ResizeTypes.None) {
  24501. components.push(renderResizeHandlerIcon(resizeType));
  24502. }
  24503. return components;
  24504. };
  24505. return {
  24506. dom: {
  24507. tag: 'div',
  24508. classes: ['tox-statusbar']
  24509. },
  24510. components: getComponents()
  24511. };
  24512. };
  24513. var setup$6 = function (editor) {
  24514. var isInline = editor.getParam('inline', false, 'boolean');
  24515. var mode = isInline ? Inline : Iframe;
  24516. var lazyOuterContainer = Option.none();
  24517. var dirAttributes = global$2.isRtl() ? { attributes: { dir: 'rtl' } } : {};
  24518. var sink = build$1({
  24519. dom: __assign({
  24520. tag: 'div',
  24521. classes: [
  24522. 'tox',
  24523. 'tox-silver-sink',
  24524. 'tox-tinymce-aux'
  24525. ]
  24526. }, dirAttributes),
  24527. behaviours: derive$1([Positioning.config({ useFixed: false })])
  24528. });
  24529. var memAnchorBar = record({
  24530. dom: {
  24531. tag: 'div',
  24532. classes: ['tox-anchorbar']
  24533. }
  24534. });
  24535. var lazyAnchorBar = function () {
  24536. return lazyOuterContainer.bind(function (container) {
  24537. return memAnchorBar.getOpt(container);
  24538. }).getOrDie('Could not find a toolbar element');
  24539. };
  24540. var backstage = init$9(sink, editor, lazyAnchorBar);
  24541. var lazySink = function () {
  24542. return Result.value(sink);
  24543. };
  24544. var partMenubar = OuterContainer.parts().menubar({
  24545. dom: {
  24546. tag: 'div',
  24547. classes: ['tox-menubar']
  24548. },
  24549. getSink: lazySink,
  24550. providers: backstage.shared.providers,
  24551. onEscape: function () {
  24552. editor.focus();
  24553. }
  24554. });
  24555. var partToolbar = OuterContainer.parts().toolbar({
  24556. dom: {
  24557. tag: 'div',
  24558. classes: ['tox-toolbar']
  24559. },
  24560. getSink: lazySink,
  24561. backstage: backstage,
  24562. onEscape: function () {
  24563. editor.focus();
  24564. },
  24565. split: isSplitToolbar(editor)
  24566. });
  24567. var partSocket = OuterContainer.parts().socket({
  24568. dom: {
  24569. tag: 'div',
  24570. classes: ['tox-edit-area']
  24571. }
  24572. });
  24573. var partSidebar = OuterContainer.parts().sidebar({
  24574. dom: {
  24575. tag: 'div',
  24576. classes: ['tox-sidebar']
  24577. }
  24578. });
  24579. var statusbar = editor.getParam('statusbar', true, 'boolean') && !isInline ? Option.some(renderStatusbar(editor, backstage.shared.providers)) : Option.none();
  24580. var socketSidebarContainer = {
  24581. dom: {
  24582. tag: 'div',
  24583. classes: ['tox-sidebar-wrap']
  24584. },
  24585. components: [
  24586. partSocket,
  24587. partSidebar
  24588. ]
  24589. };
  24590. var hasToolbar = isToolbarEnabled(editor) || getMultipleToolbarsSetting(editor).isSome();
  24591. var hasMenubar = isMenubarEnabled(editor);
  24592. var editorComponents = flatten([
  24593. hasMenubar ? [partMenubar] : [],
  24594. hasToolbar ? [partToolbar] : [],
  24595. [memAnchorBar.asSpec()],
  24596. isInline ? [] : [socketSidebarContainer]
  24597. ]);
  24598. var editorContainer = {
  24599. dom: {
  24600. tag: 'div',
  24601. classes: ['tox-editor-container']
  24602. },
  24603. components: editorComponents
  24604. };
  24605. var containerComponents = flatten([
  24606. [editorContainer],
  24607. isInline ? [] : statusbar.toArray()
  24608. ]);
  24609. var attributes = __assign({ role: 'application' }, global$2.isRtl() ? { dir: 'rtl' } : {});
  24610. var outerContainer = build$1(OuterContainer.sketch({
  24611. dom: {
  24612. tag: 'div',
  24613. classes: [
  24614. 'tox',
  24615. 'tox-tinymce'
  24616. ].concat(isInline ? ['tox-tinymce-inline'] : []),
  24617. styles: { visibility: 'hidden' },
  24618. attributes: attributes
  24619. },
  24620. components: containerComponents,
  24621. behaviours: derive$1(mode.getBehaviours(editor).concat([Keying.config({
  24622. mode: 'cyclic',
  24623. selector: '.tox-menubar, .tox-toolbar, .tox-sidebar--sliding-open, .tox-statusbar__path, .tox-statusbar__wordcount, .tox-statusbar__branding a'
  24624. })]))
  24625. }));
  24626. lazyOuterContainer = Option.some(outerContainer);
  24627. editor.shortcuts.add('alt+F9', 'focus menubar', function () {
  24628. OuterContainer.focusMenubar(outerContainer);
  24629. });
  24630. editor.shortcuts.add('alt+F10', 'focus toolbar', function () {
  24631. OuterContainer.focusToolbar(outerContainer);
  24632. });
  24633. var mothership = takeover(outerContainer);
  24634. var uiMothership = takeover(sink);
  24635. Events.setup(editor, mothership, uiMothership);
  24636. var getUi = function () {
  24637. var channels = {
  24638. broadcastAll: uiMothership.broadcast,
  24639. broadcastOn: uiMothership.broadcastOn,
  24640. register: function () {
  24641. }
  24642. };
  24643. return { channels: channels };
  24644. };
  24645. var setEditorSize = function (elm) {
  24646. var DOM = global$4.DOM;
  24647. var baseWidth = editor.getParam('width', DOM.getStyle(elm, 'width'));
  24648. var baseHeight = getHeightSetting(editor);
  24649. var minWidth = getMinWidthSetting(editor);
  24650. var minHeight = getMinHeightSetting(editor);
  24651. var parsedWidth = Utils.parseToInt(baseWidth).bind(function (w) {
  24652. return Utils.numToPx(minWidth.map(function (mw) {
  24653. return Math.max(w, mw);
  24654. }));
  24655. }).getOr(Utils.numToPx(baseWidth));
  24656. var parsedHeight = Utils.parseToInt(baseHeight).bind(function (h) {
  24657. return minHeight.map(function (mh) {
  24658. return Math.max(h, mh);
  24659. });
  24660. }).getOr(baseHeight);
  24661. var stringWidth = Utils.numToPx(parsedWidth);
  24662. if (isValidValue('div', 'width', stringWidth)) {
  24663. set$2(outerContainer.element(), 'width', stringWidth);
  24664. }
  24665. if (!editor.inline) {
  24666. var stringHeight = Utils.numToPx(parsedHeight);
  24667. if (isValidValue('div', 'height', stringHeight)) {
  24668. set$2(outerContainer.element(), 'height', stringHeight);
  24669. } else {
  24670. set$2(outerContainer.element(), 'height', '200px');
  24671. }
  24672. }
  24673. return parsedHeight;
  24674. };
  24675. var renderUI = function () {
  24676. setup$5(editor, lazySink, backstage.shared);
  24677. setup$4(editor);
  24678. var _a = editor.ui.registry.getAll(), buttons = _a.buttons, menuItems = _a.menuItems, contextToolbars = _a.contextToolbars, sidebars = _a.sidebars;
  24679. var rawUiConfig = {
  24680. menuItems: menuItems,
  24681. buttons: buttons,
  24682. menus: !editor.settings.menu ? {} : map$1(editor.settings.menu, function (menu) {
  24683. return merge(menu, { items: menu.items });
  24684. }),
  24685. menubar: editor.settings.menubar,
  24686. toolbar: getMultipleToolbarsSetting(editor).getOr(editor.getParam('toolbar', true)),
  24687. sidebar: sidebars
  24688. };
  24689. ContextToolbar.register(editor, contextToolbars, sink, { backstage: backstage });
  24690. var elm = editor.getElement();
  24691. var height = setEditorSize(elm);
  24692. var uiComponents = {
  24693. mothership: mothership,
  24694. uiMothership: uiMothership,
  24695. outerContainer: outerContainer
  24696. };
  24697. var args = {
  24698. targetNode: elm,
  24699. height: height
  24700. };
  24701. return mode.render(editor, uiComponents, rawUiConfig, backstage, args);
  24702. };
  24703. return {
  24704. mothership: mothership,
  24705. uiMothership: uiMothership,
  24706. backstage: backstage,
  24707. renderUI: renderUI,
  24708. getUi: getUi
  24709. };
  24710. };
  24711. var Render = { setup: setup$6 };
  24712. var register$5 = function (editor) {
  24713. var alignToolbarButtons = [
  24714. {
  24715. name: 'alignleft',
  24716. text: 'Align left',
  24717. cmd: 'JustifyLeft',
  24718. icon: 'align-left'
  24719. },
  24720. {
  24721. name: 'aligncenter',
  24722. text: 'Align center',
  24723. cmd: 'JustifyCenter',
  24724. icon: 'align-center'
  24725. },
  24726. {
  24727. name: 'alignright',
  24728. text: 'Align right',
  24729. cmd: 'JustifyRight',
  24730. icon: 'align-right'
  24731. },
  24732. {
  24733. name: 'alignjustify',
  24734. text: 'Justify',
  24735. cmd: 'JustifyFull',
  24736. icon: 'align-justify'
  24737. }
  24738. ];
  24739. var onSetupToggleButton = function (item) {
  24740. return function (api) {
  24741. var handler = function (state) {
  24742. api.setActive(state);
  24743. };
  24744. if (editor.formatter) {
  24745. api.setActive(editor.formatter.match(item.name));
  24746. editor.formatter.formatChanged(item.name, handler);
  24747. } else {
  24748. editor.on('init', function () {
  24749. api.setActive(editor.formatter.match(item.name));
  24750. editor.formatter.formatChanged(item.name, handler);
  24751. });
  24752. }
  24753. return function () {
  24754. };
  24755. };
  24756. };
  24757. global$a.each(alignToolbarButtons, function (item) {
  24758. editor.ui.registry.addToggleButton(item.name, {
  24759. tooltip: item.text,
  24760. onAction: function () {
  24761. return editor.execCommand(item.cmd);
  24762. },
  24763. icon: item.icon,
  24764. onSetup: onSetupToggleButton(item)
  24765. });
  24766. });
  24767. var alignNoneToolbarButton = {
  24768. name: 'alignnone',
  24769. text: 'No alignment',
  24770. cmd: 'JustifyNone',
  24771. icon: 'align-none'
  24772. };
  24773. editor.ui.registry.addButton(alignNoneToolbarButton.name, {
  24774. tooltip: alignNoneToolbarButton.text,
  24775. onAction: function () {
  24776. return editor.execCommand(alignNoneToolbarButton.cmd);
  24777. },
  24778. icon: alignNoneToolbarButton.icon
  24779. });
  24780. };
  24781. var AlignmentButtons = { register: register$5 };
  24782. var toggleFormat = function (editor, fmt) {
  24783. return function () {
  24784. editor.execCommand('mceToggleFormat', false, fmt);
  24785. };
  24786. };
  24787. var onSetupFormatToggle = function (editor, name) {
  24788. return function (api) {
  24789. var handler = function (state) {
  24790. api.setActive(state);
  24791. };
  24792. if (editor.formatter) {
  24793. api.setActive(editor.formatter.match(name));
  24794. editor.formatter.formatChanged(name, handler);
  24795. } else {
  24796. editor.on('init', function () {
  24797. api.setActive(editor.formatter.match(name));
  24798. editor.formatter.formatChanged(name, handler);
  24799. });
  24800. }
  24801. return function () {
  24802. };
  24803. };
  24804. };
  24805. var registerFormatButtons = function (editor) {
  24806. global$a.each([
  24807. {
  24808. name: 'bold',
  24809. text: 'Bold',
  24810. icon: 'bold'
  24811. },
  24812. {
  24813. name: 'italic',
  24814. text: 'Italic',
  24815. icon: 'italic'
  24816. },
  24817. {
  24818. name: 'underline',
  24819. text: 'Underline',
  24820. icon: 'underline'
  24821. },
  24822. {
  24823. name: 'strikethrough',
  24824. text: 'Strikethrough',
  24825. icon: 'strike-through'
  24826. },
  24827. {
  24828. name: 'subscript',
  24829. text: 'Subscript',
  24830. icon: 'subscript'
  24831. },
  24832. {
  24833. name: 'superscript',
  24834. text: 'Superscript',
  24835. icon: 'superscript'
  24836. }
  24837. ], function (btn) {
  24838. editor.ui.registry.addToggleButton(btn.name, {
  24839. tooltip: btn.text,
  24840. icon: btn.icon,
  24841. onSetup: onSetupFormatToggle(editor, btn.name),
  24842. onAction: toggleFormat(editor, btn.name)
  24843. });
  24844. });
  24845. for (var i = 1; i <= 6; i++) {
  24846. var name = 'h' + i;
  24847. editor.ui.registry.addToggleButton(name, {
  24848. text: name.toUpperCase(),
  24849. tooltip: 'Heading ' + i,
  24850. onSetup: onSetupFormatToggle(editor, name),
  24851. onAction: toggleFormat(editor, name)
  24852. });
  24853. }
  24854. };
  24855. var registerCommandButtons = function (editor) {
  24856. global$a.each([
  24857. {
  24858. name: 'cut',
  24859. text: 'Cut',
  24860. action: 'Cut',
  24861. icon: 'cut'
  24862. },
  24863. {
  24864. name: 'copy',
  24865. text: 'Copy',
  24866. action: 'Copy',
  24867. icon: 'copy'
  24868. },
  24869. {
  24870. name: 'paste',
  24871. text: 'Paste',
  24872. action: 'Paste',
  24873. icon: 'paste'
  24874. },
  24875. {
  24876. name: 'help',
  24877. text: 'Help',
  24878. action: 'mceHelp',
  24879. icon: 'help'
  24880. },
  24881. {
  24882. name: 'selectall',
  24883. text: 'Select all',
  24884. action: 'SelectAll',
  24885. icon: 'select-all'
  24886. },
  24887. {
  24888. name: 'newdocument',
  24889. text: 'New document',
  24890. action: 'mceNewDocument',
  24891. icon: 'new-document'
  24892. },
  24893. {
  24894. name: 'removeformat',
  24895. text: 'Clear formatting',
  24896. action: 'RemoveFormat',
  24897. icon: 'remove-formatting'
  24898. },
  24899. {
  24900. name: 'remove',
  24901. text: 'Remove',
  24902. action: 'Delete',
  24903. icon: 'remove'
  24904. }
  24905. ], function (btn) {
  24906. editor.ui.registry.addButton(btn.name, {
  24907. tooltip: btn.text,
  24908. icon: btn.icon,
  24909. onAction: function () {
  24910. return editor.execCommand(btn.action);
  24911. }
  24912. });
  24913. });
  24914. };
  24915. var registerCommandToggleButtons = function (editor) {
  24916. global$a.each([{
  24917. name: 'blockquote',
  24918. text: 'Blockquote',
  24919. action: 'mceBlockQuote',
  24920. icon: 'quote'
  24921. }], function (btn) {
  24922. editor.ui.registry.addToggleButton(btn.name, {
  24923. tooltip: btn.text,
  24924. icon: btn.icon,
  24925. onAction: function () {
  24926. return editor.execCommand(btn.action);
  24927. },
  24928. onSetup: onSetupFormatToggle(editor, btn.name)
  24929. });
  24930. });
  24931. };
  24932. var registerButtons = function (editor) {
  24933. registerFormatButtons(editor);
  24934. registerCommandButtons(editor);
  24935. registerCommandToggleButtons(editor);
  24936. };
  24937. var registerMenuItems = function (editor) {
  24938. global$a.each([
  24939. {
  24940. name: 'bold',
  24941. text: 'Bold',
  24942. action: 'Bold',
  24943. icon: 'bold',
  24944. shortcut: 'Meta+B'
  24945. },
  24946. {
  24947. name: 'italic',
  24948. text: 'Italic',
  24949. action: 'Italic',
  24950. icon: 'italic',
  24951. shortcut: 'Meta+I'
  24952. },
  24953. {
  24954. name: 'underline',
  24955. text: 'Underline',
  24956. action: 'Underline',
  24957. icon: 'underline',
  24958. shortcut: 'Meta+U'
  24959. },
  24960. {
  24961. name: 'strikethrough',
  24962. text: 'Strikethrough',
  24963. action: 'Strikethrough',
  24964. icon: 'strike-through',
  24965. shortcut: ''
  24966. },
  24967. {
  24968. name: 'subscript',
  24969. text: 'Subscript',
  24970. action: 'Subscript',
  24971. icon: 'subscript',
  24972. shortcut: ''
  24973. },
  24974. {
  24975. name: 'superscript',
  24976. text: 'Superscript',
  24977. action: 'Superscript',
  24978. icon: 'superscript',
  24979. shortcut: ''
  24980. },
  24981. {
  24982. name: 'removeformat',
  24983. text: 'Clear formatting',
  24984. action: 'RemoveFormat',
  24985. icon: 'remove-formatting',
  24986. shortcut: ''
  24987. },
  24988. {
  24989. name: 'newdocument',
  24990. text: 'New document',
  24991. action: 'mceNewDocument',
  24992. icon: 'new-document',
  24993. shortcut: ''
  24994. },
  24995. {
  24996. name: 'cut',
  24997. text: 'Cut',
  24998. action: 'Cut',
  24999. icon: 'cut',
  25000. shortcut: 'Meta+X'
  25001. },
  25002. {
  25003. name: 'copy',
  25004. text: 'Copy',
  25005. action: 'Copy',
  25006. icon: 'copy',
  25007. shortcut: 'Meta+C'
  25008. },
  25009. {
  25010. name: 'paste',
  25011. text: 'Paste',
  25012. action: 'Paste',
  25013. icon: 'paste',
  25014. shortcut: 'Meta+V'
  25015. },
  25016. {
  25017. name: 'selectall',
  25018. text: 'Select all',
  25019. action: 'SelectAll',
  25020. icon: 'select-all',
  25021. shortcut: 'Meta+A'
  25022. }
  25023. ], function (btn) {
  25024. editor.ui.registry.addMenuItem(btn.name, {
  25025. text: btn.text,
  25026. icon: btn.icon,
  25027. shortcut: btn.shortcut,
  25028. onAction: function () {
  25029. return editor.execCommand(btn.action);
  25030. }
  25031. });
  25032. });
  25033. editor.ui.registry.addMenuItem('codeformat', {
  25034. text: 'Code',
  25035. icon: 'sourcecode',
  25036. onAction: toggleFormat(editor, 'code')
  25037. });
  25038. };
  25039. var register$6 = function (editor) {
  25040. registerButtons(editor);
  25041. registerMenuItems(editor);
  25042. };
  25043. var SimpleControls = { register: register$6 };
  25044. var toggleUndoRedoState = function (api, editor, type) {
  25045. var checkState = function () {
  25046. return editor.undoManager ? editor.undoManager[type]() : false;
  25047. };
  25048. var onUndoStateChange = function () {
  25049. api.setDisabled(editor.readonly || !checkState());
  25050. };
  25051. api.setDisabled(!checkState());
  25052. editor.on('Undo Redo AddUndo TypingUndo ClearUndos SwitchMode', onUndoStateChange);
  25053. return function () {
  25054. return editor.off('Undo Redo AddUndo TypingUndo ClearUndos SwitchMode', onUndoStateChange);
  25055. };
  25056. };
  25057. var registerMenuItems$1 = function (editor) {
  25058. editor.ui.registry.addMenuItem('undo', {
  25059. text: 'Undo',
  25060. icon: 'undo',
  25061. shortcut: 'Meta+Z',
  25062. onSetup: function (api) {
  25063. return toggleUndoRedoState(api, editor, 'hasUndo');
  25064. },
  25065. onAction: function () {
  25066. return editor.execCommand('undo');
  25067. }
  25068. });
  25069. editor.ui.registry.addMenuItem('redo', {
  25070. text: 'Redo',
  25071. icon: 'redo',
  25072. shortcut: 'Meta+Y',
  25073. onSetup: function (api) {
  25074. return toggleUndoRedoState(api, editor, 'hasRedo');
  25075. },
  25076. onAction: function () {
  25077. return editor.execCommand('redo');
  25078. }
  25079. });
  25080. };
  25081. var registerButtons$1 = function (editor) {
  25082. editor.ui.registry.addButton('undo', {
  25083. tooltip: 'Undo',
  25084. icon: 'undo',
  25085. onSetup: function (api) {
  25086. return toggleUndoRedoState(api, editor, 'hasUndo');
  25087. },
  25088. onAction: function () {
  25089. return editor.execCommand('undo');
  25090. }
  25091. });
  25092. editor.ui.registry.addButton('redo', {
  25093. tooltip: 'Redo',
  25094. icon: 'redo',
  25095. onSetup: function (api) {
  25096. return toggleUndoRedoState(api, editor, 'hasRedo');
  25097. },
  25098. onAction: function () {
  25099. return editor.execCommand('redo');
  25100. }
  25101. });
  25102. };
  25103. var register$7 = function (editor) {
  25104. registerMenuItems$1(editor);
  25105. registerButtons$1(editor);
  25106. };
  25107. var UndoRedo = { register: register$7 };
  25108. var toggleVisualAidState = function (api, editor) {
  25109. api.setActive(editor.hasVisual);
  25110. var onVisualAid = function (e) {
  25111. api.setActive(e.hasVisual);
  25112. };
  25113. editor.on('VisualAid', onVisualAid);
  25114. return function () {
  25115. return editor.off('VisualAid', onVisualAid);
  25116. };
  25117. };
  25118. var registerMenuItems$2 = function (editor) {
  25119. editor.ui.registry.addToggleMenuItem('visualaid', {
  25120. text: 'Visual aids',
  25121. onSetup: function (api) {
  25122. return toggleVisualAidState(api, editor);
  25123. },
  25124. onAction: function () {
  25125. editor.execCommand('mceToggleVisualAid');
  25126. }
  25127. });
  25128. };
  25129. var registerToolbarButton = function (editor) {
  25130. editor.ui.registry.addButton('visualaid', {
  25131. tooltip: 'Visual aids',
  25132. text: 'Visual aids',
  25133. onAction: function () {
  25134. return editor.execCommand('mceToggleVisualAid');
  25135. }
  25136. });
  25137. };
  25138. var register$8 = function (editor) {
  25139. registerToolbarButton(editor);
  25140. registerMenuItems$2(editor);
  25141. };
  25142. var VisualAid = { register: register$8 };
  25143. var toggleOutdentState = function (api, editor) {
  25144. api.setDisabled(!editor.queryCommandState('outdent'));
  25145. var onNodeChange = function () {
  25146. api.setDisabled(!editor.queryCommandState('outdent'));
  25147. };
  25148. editor.on('NodeChange', onNodeChange);
  25149. return function () {
  25150. return editor.off('NodeChange', onNodeChange);
  25151. };
  25152. };
  25153. var registerButtons$2 = function (editor) {
  25154. editor.ui.registry.addButton('outdent', {
  25155. tooltip: 'Decrease indent',
  25156. icon: 'outdent',
  25157. onSetup: function (api) {
  25158. return toggleOutdentState(api, editor);
  25159. },
  25160. onAction: function () {
  25161. return editor.execCommand('outdent');
  25162. }
  25163. });
  25164. editor.ui.registry.addButton('indent', {
  25165. tooltip: 'Increase indent',
  25166. icon: 'indent',
  25167. onAction: function () {
  25168. return editor.execCommand('indent');
  25169. }
  25170. });
  25171. };
  25172. var register$9 = function (editor) {
  25173. registerButtons$2(editor);
  25174. };
  25175. var IndentOutdent = { register: register$9 };
  25176. var register$a = function (editor, backstage) {
  25177. alignSelectMenu(editor, backstage);
  25178. fontSelectMenu(editor, backstage);
  25179. styleSelectMenu(editor, backstage);
  25180. formatSelectMenu(editor, backstage);
  25181. fontsizeSelectMenu(editor, backstage);
  25182. };
  25183. var ComplexControls = { register: register$a };
  25184. var setup$7 = function (editor, backstage) {
  25185. AlignmentButtons.register(editor);
  25186. SimpleControls.register(editor);
  25187. ComplexControls.register(editor, backstage);
  25188. UndoRedo.register(editor);
  25189. ColorSwatch.register(editor);
  25190. VisualAid.register(editor);
  25191. IndentOutdent.register(editor);
  25192. };
  25193. var FormatControls = { setup: setup$7 };
  25194. var AriaLabel = {
  25195. labelledBy: function (labelledElement, labelElement) {
  25196. var labelId = Option.from(get$2(labelledElement, 'id')).fold(function () {
  25197. var id = generate$1('dialog-label');
  25198. set$1(labelElement, 'id', id);
  25199. return id;
  25200. }, identity);
  25201. set$1(labelledElement, 'aria-labelledby', labelId);
  25202. }
  25203. };
  25204. var schema$q = constant([
  25205. strict$1('lazySink'),
  25206. option('dragBlockClass'),
  25207. defaulted$1('useTabstopAt', constant(true)),
  25208. defaulted$1('eventOrder', {}),
  25209. field$1('modalBehaviours', [Keying]),
  25210. onKeyboardHandler('onExecute'),
  25211. onStrictKeyboardHandler('onEscape')
  25212. ]);
  25213. var basic = { sketch: identity };
  25214. var parts$c = constant([
  25215. optional({
  25216. name: 'draghandle',
  25217. overrides: function (detail, spec) {
  25218. return {
  25219. behaviours: derive$1([Dragging.config({
  25220. mode: 'mouse',
  25221. getTarget: function (handle) {
  25222. return ancestor$1(handle, '[role="dialog"]').getOr(handle);
  25223. },
  25224. blockerClass: detail.dragBlockClass.getOrDie(new Error('The drag blocker class was not specified for a dialog with a drag handle: \n' + JSON$1.stringify(spec, null, 2)).message)
  25225. })])
  25226. };
  25227. }
  25228. }),
  25229. required({
  25230. schema: [strict$1('dom')],
  25231. name: 'title'
  25232. }),
  25233. required({
  25234. factory: basic,
  25235. schema: [strict$1('dom')],
  25236. name: 'close'
  25237. }),
  25238. required({
  25239. factory: basic,
  25240. schema: [strict$1('dom')],
  25241. name: 'body'
  25242. }),
  25243. required({
  25244. factory: basic,
  25245. schema: [strict$1('dom')],
  25246. name: 'footer'
  25247. }),
  25248. external$1({
  25249. factory: {
  25250. sketch: function (spec, detail) {
  25251. return __assign({}, spec, {
  25252. dom: detail.dom,
  25253. components: detail.components
  25254. });
  25255. }
  25256. },
  25257. schema: [
  25258. defaulted$1('dom', {
  25259. tag: 'div',
  25260. styles: {
  25261. position: 'fixed',
  25262. left: '0px',
  25263. top: '0px',
  25264. right: '0px',
  25265. bottom: '0px'
  25266. }
  25267. }),
  25268. defaulted$1('components', [])
  25269. ],
  25270. name: 'blocker'
  25271. })
  25272. ]);
  25273. var describedBy = function (describedElement, describeElement) {
  25274. var describeId = Option.from(get$2(describedElement, 'id')).fold(function () {
  25275. var id = generate$1('dialog-describe');
  25276. set$1(describeElement, 'id', id);
  25277. return id;
  25278. }, identity);
  25279. set$1(describedElement, 'aria-describedby', describeId);
  25280. };
  25281. var factory$f = function (detail, components, spec, externals) {
  25282. var dialogBusyEvent = generate$1('alloy.dialog.busy');
  25283. var dialogIdleEvent = generate$1('alloy.dialog.idle');
  25284. var busyBehaviours = derive$1([
  25285. Keying.config({
  25286. mode: 'special',
  25287. onTab: function () {
  25288. return Option.some(true);
  25289. },
  25290. onShiftTab: function () {
  25291. return Option.some(true);
  25292. }
  25293. }),
  25294. Focusing.config({})
  25295. ]);
  25296. var showDialog = function (dialog) {
  25297. var sink = detail.lazySink(dialog).getOrDie();
  25298. var busyComp = Cell(Option.none());
  25299. var externalBlocker = externals.blocker();
  25300. var blocker = sink.getSystem().build(__assign({}, externalBlocker, {
  25301. components: externalBlocker.components.concat([premade$1(dialog)]),
  25302. behaviours: derive$1([config('dialog-blocker-events', [
  25303. run(dialogIdleEvent, function (blocker, se) {
  25304. if (has$1(dialog.element(), 'aria-busy')) {
  25305. remove$1(dialog.element(), 'aria-busy');
  25306. busyComp.get().each(function (bc) {
  25307. return Replacing.remove(dialog, bc);
  25308. });
  25309. }
  25310. }),
  25311. run(dialogBusyEvent, function (blocker, se) {
  25312. set$1(dialog.element(), 'aria-busy', 'true');
  25313. var getBusySpec = se.event().getBusySpec();
  25314. busyComp.get().each(function (bc) {
  25315. Replacing.remove(dialog, bc);
  25316. });
  25317. var busySpec = getBusySpec(dialog, busyBehaviours);
  25318. var busy = blocker.getSystem().build(busySpec);
  25319. busyComp.set(Option.some(busy));
  25320. Replacing.append(dialog, premade$1(busy));
  25321. if (busy.hasConfigured(Keying)) {
  25322. Keying.focusIn(busy);
  25323. }
  25324. })
  25325. ])])
  25326. }));
  25327. attach(sink, blocker);
  25328. Keying.focusIn(dialog);
  25329. };
  25330. var hideDialog = function (dialog) {
  25331. parent(dialog.element()).each(function (blockerDom) {
  25332. dialog.getSystem().getByDom(blockerDom).each(function (blocker) {
  25333. detach(blocker);
  25334. });
  25335. });
  25336. };
  25337. var getDialogBody = function (dialog) {
  25338. return getPartOrDie(dialog, detail, 'body');
  25339. };
  25340. var getDialogFooter = function (dialog) {
  25341. return getPartOrDie(dialog, detail, 'footer');
  25342. };
  25343. var setBusy = function (dialog, getBusySpec) {
  25344. emitWith(dialog, dialogBusyEvent, { getBusySpec: getBusySpec });
  25345. };
  25346. var setIdle = function (dialog) {
  25347. emit(dialog, dialogIdleEvent);
  25348. };
  25349. var modalEventsId = generate$1('modal-events');
  25350. var eventOrder = __assign({}, detail.eventOrder, { 'alloy.system.attached': [modalEventsId].concat(detail.eventOrder['alloy.system.attached'] || []) });
  25351. return {
  25352. uid: detail.uid,
  25353. dom: detail.dom,
  25354. components: components,
  25355. apis: {
  25356. show: showDialog,
  25357. hide: hideDialog,
  25358. getBody: getDialogBody,
  25359. getFooter: getDialogFooter,
  25360. setIdle: setIdle,
  25361. setBusy: setBusy
  25362. },
  25363. eventOrder: eventOrder,
  25364. domModification: {
  25365. attributes: {
  25366. 'role': 'dialog',
  25367. 'aria-modal': 'true'
  25368. }
  25369. },
  25370. behaviours: augment(detail.modalBehaviours, [
  25371. Replacing.config({}),
  25372. Keying.config({
  25373. mode: 'cyclic',
  25374. onEnter: detail.onExecute,
  25375. onEscape: detail.onEscape,
  25376. useTabstopAt: detail.useTabstopAt
  25377. }),
  25378. config(modalEventsId, [runOnAttached(function (c) {
  25379. AriaLabel.labelledBy(c.element(), getPartOrDie(c, detail, 'title').element());
  25380. describedBy(c.element(), getPartOrDie(c, detail, 'body').element());
  25381. })])
  25382. ])
  25383. };
  25384. };
  25385. var ModalDialog = composite$1({
  25386. name: 'ModalDialog',
  25387. configFields: schema$q(),
  25388. partFields: parts$c(),
  25389. factory: factory$f,
  25390. apis: {
  25391. show: function (apis, dialog) {
  25392. apis.show(dialog);
  25393. },
  25394. hide: function (apis, dialog) {
  25395. apis.hide(dialog);
  25396. },
  25397. getBody: function (apis, dialog) {
  25398. return apis.getBody(dialog);
  25399. },
  25400. getFooter: function (apis, dialog) {
  25401. return apis.getFooter(dialog);
  25402. },
  25403. setBusy: function (apis, dialog, getBusySpec) {
  25404. apis.setBusy(dialog, getBusySpec);
  25405. },
  25406. setIdle: function (apis, dialog) {
  25407. apis.setIdle(dialog);
  25408. }
  25409. }
  25410. });
  25411. var alertBannerFields = [
  25412. strictString('type'),
  25413. strictString('text'),
  25414. strictStringEnum('level', [
  25415. 'info',
  25416. 'warn',
  25417. 'error',
  25418. 'success'
  25419. ]),
  25420. strictString('icon'),
  25421. defaulted$1('url', '')
  25422. ];
  25423. var createBarFields = function (itemsField) {
  25424. return [
  25425. strictString('type'),
  25426. itemsField
  25427. ];
  25428. };
  25429. var buttonFields = [
  25430. strictString('type'),
  25431. strictString('text'),
  25432. defaultedBoolean('primary', false),
  25433. field('name', 'name', defaultedThunk(function () {
  25434. return generate$1('button-name');
  25435. }), string),
  25436. optionString('icon')
  25437. ];
  25438. var checkboxFields = [
  25439. strictString('type'),
  25440. strictString('name'),
  25441. strictString('label')
  25442. ];
  25443. var checkboxDataProcessor = boolean;
  25444. var formComponentFields = [
  25445. strictString('type'),
  25446. strictString('name'),
  25447. optionString('label')
  25448. ];
  25449. var colorInputFields = formComponentFields;
  25450. var colorInputDataProcessor = string;
  25451. var colorPickerFields = formComponentFields;
  25452. var colorPickerDataProcessor = string;
  25453. var dropZoneFields = formComponentFields;
  25454. var dropZoneDataProcessor = arrOfVal();
  25455. var createGridFields = function (itemsField) {
  25456. return [
  25457. strictString('type'),
  25458. strictNumber('columns'),
  25459. itemsField
  25460. ];
  25461. };
  25462. var iframeFields = formComponentFields.concat([defaultedBoolean('sandboxed', true)]);
  25463. var iframeDataProcessor = string;
  25464. var inputFields = formComponentFields.concat([optionString('placeholder')]);
  25465. var inputDataProcessor = string;
  25466. var selectBoxFields = formComponentFields.concat([
  25467. strictArrayOfObj('items', [
  25468. strictString('text'),
  25469. strictString('value')
  25470. ]),
  25471. defaultedNumber('size', 1)
  25472. ]);
  25473. var selectBoxDataProcessor = string;
  25474. var sizeInputFields = formComponentFields.concat([defaultedBoolean('constrain', true)]);
  25475. var sizeInputDataProcessor = objOf([
  25476. strictString('width'),
  25477. strictString('height')
  25478. ]);
  25479. var textAreaFields = formComponentFields.concat([optionString('placeholder')]);
  25480. var textAreaDataProcessor = string;
  25481. var urlInputFields = formComponentFields.concat([defaultedStringEnum('filetype', 'file', [
  25482. 'image',
  25483. 'media',
  25484. 'file'
  25485. ])]);
  25486. var urlInputDataProcessor = objOf([
  25487. strictString('value'),
  25488. defaulted$1('meta', {})
  25489. ]);
  25490. var customEditorFields = formComponentFields.concat([
  25491. strictString('type'),
  25492. defaultedString('tag', 'textarea'),
  25493. strictFunction('init')
  25494. ]);
  25495. var customEditorDataProcessor = string;
  25496. var htmlPanelFields = [
  25497. strictString('type'),
  25498. strictString('html'),
  25499. defaultedStringEnum('presets', 'presentation', [
  25500. 'presentation',
  25501. 'document'
  25502. ])
  25503. ];
  25504. var imageToolsFields = formComponentFields.concat([strictOf('currentState', objOf([
  25505. strict$1('blob'),
  25506. strictString('url')
  25507. ]))]);
  25508. var collectionFields = formComponentFields.concat([defaulted$1('columns', 'auto')]);
  25509. var collectionDataProcessor = arrOfObj$1([
  25510. strictString('value'),
  25511. optionString('text'),
  25512. optionString('icon')
  25513. ]);
  25514. var createLabelFields = function (itemsField) {
  25515. return [
  25516. strictString('type'),
  25517. strictString('label'),
  25518. itemsField
  25519. ];
  25520. };
  25521. var tableFields = [
  25522. strictString('type'),
  25523. strictArrayOf('header', string),
  25524. strictArrayOf('cells', arrOf(string))
  25525. ];
  25526. var createItemsField = function (name) {
  25527. return field('items', 'items', strict(), arrOf(valueOf(function (v) {
  25528. return asRaw('Checking item of ' + name, itemSchema$2, v).fold(function (sErr) {
  25529. return Result.error(formatError(sErr));
  25530. }, function (passValue) {
  25531. return Result.value(passValue);
  25532. });
  25533. })));
  25534. };
  25535. var itemSchema$2 = choose$1('type', {
  25536. alertbanner: alertBannerFields,
  25537. bar: createBarFields(createItemsField('bar')),
  25538. button: buttonFields,
  25539. checkbox: checkboxFields,
  25540. colorinput: colorInputFields,
  25541. colorpicker: colorPickerFields,
  25542. dropzone: dropZoneFields,
  25543. grid: createGridFields(createItemsField('grid')),
  25544. iframe: iframeFields,
  25545. input: inputFields,
  25546. selectbox: selectBoxFields,
  25547. sizeinput: sizeInputFields,
  25548. textarea: textAreaFields,
  25549. urlinput: urlInputFields,
  25550. customeditor: customEditorFields,
  25551. htmlpanel: htmlPanelFields,
  25552. imagetools: imageToolsFields,
  25553. collection: collectionFields,
  25554. label: createLabelFields(createItemsField('label')),
  25555. table: tableFields
  25556. });
  25557. var panelFields = [
  25558. strictString('type'),
  25559. strictArrayOf('items', itemSchema$2)
  25560. ];
  25561. var tabFields = [
  25562. strictString('title'),
  25563. strictArrayOf('items', itemSchema$2)
  25564. ];
  25565. var tabPanelFields = [
  25566. strictString('type'),
  25567. strictArrayOfObj('tabs', tabFields)
  25568. ];
  25569. var dialogButtonSchema = objOf([
  25570. strictStringEnum('type', [
  25571. 'submit',
  25572. 'cancel',
  25573. 'custom'
  25574. ]),
  25575. field('name', 'name', defaultedThunk(function () {
  25576. return generate$1('button-name');
  25577. }), string),
  25578. strictString('text'),
  25579. optionString('icon'),
  25580. defaultedStringEnum('align', 'end', [
  25581. 'start',
  25582. 'end'
  25583. ]),
  25584. defaultedBoolean('primary', false),
  25585. defaultedBoolean('disabled', false)
  25586. ]);
  25587. var dialogSchema = objOf([
  25588. strictString('title'),
  25589. strictOf('body', choose$1('type', {
  25590. panel: panelFields,
  25591. tabpanel: tabPanelFields
  25592. })),
  25593. defaultedString('size', 'normal'),
  25594. strictArrayOf('buttons', dialogButtonSchema),
  25595. defaulted$1('initialData', {}),
  25596. defaultedFunction('onAction', noop),
  25597. defaultedFunction('onChange', noop),
  25598. defaultedFunction('onSubmit', noop),
  25599. defaultedFunction('onClose', noop),
  25600. defaultedFunction('onCancel', noop),
  25601. defaulted$1('onTabChange', noop)
  25602. ]);
  25603. var createDialog = function (spec) {
  25604. return asRaw('dialog', dialogSchema, spec);
  25605. };
  25606. var getAllObjects = function (obj) {
  25607. if (isObject(obj)) {
  25608. return [obj].concat(bind(values(obj), getAllObjects));
  25609. } else if (isArray(obj)) {
  25610. return bind(obj, getAllObjects);
  25611. } else {
  25612. return [];
  25613. }
  25614. };
  25615. var isNamedItem = function (obj) {
  25616. return isString(obj.type) && isString(obj.name);
  25617. };
  25618. var dataProcessors = {
  25619. checkbox: checkboxDataProcessor,
  25620. colorinput: colorInputDataProcessor,
  25621. colorpicker: colorPickerDataProcessor,
  25622. dropzone: dropZoneDataProcessor,
  25623. input: inputDataProcessor,
  25624. iframe: iframeDataProcessor,
  25625. sizeinput: sizeInputDataProcessor,
  25626. selectbox: selectBoxDataProcessor,
  25627. size: sizeInputDataProcessor,
  25628. textarea: textAreaDataProcessor,
  25629. urlinput: urlInputDataProcessor,
  25630. customeditor: customEditorDataProcessor,
  25631. collection: collectionDataProcessor
  25632. };
  25633. var getDataProcessor = function (item) {
  25634. return Option.from(dataProcessors[item.type]);
  25635. };
  25636. var getNamedItems = function (structure) {
  25637. return filter(getAllObjects(structure), isNamedItem);
  25638. };
  25639. var createDataValidator = function (structure) {
  25640. var fields = bind(getNamedItems(structure), function (item) {
  25641. return getDataProcessor(item).fold(function () {
  25642. return [];
  25643. }, function (schema) {
  25644. return [strictOf(item.name, schema)];
  25645. });
  25646. });
  25647. return objOf(fields);
  25648. };
  25649. var extract$1 = function (structure) {
  25650. var internalDialog = getOrDie$1(createDialog(structure));
  25651. var dataValidator = createDataValidator(structure);
  25652. var initialData = structure.initialData;
  25653. return {
  25654. internalDialog: internalDialog,
  25655. dataValidator: dataValidator,
  25656. initialData: initialData
  25657. };
  25658. };
  25659. var DialogManager = {
  25660. open: function (factory, structure) {
  25661. var extraction = extract$1(structure);
  25662. return factory(extraction.internalDialog, extraction.initialData, extraction.dataValidator);
  25663. },
  25664. redial: function (structure) {
  25665. return extract$1(structure);
  25666. }
  25667. };
  25668. var dialogChannel = generate$1('update-dialog');
  25669. var titleChannel = generate$1('update-title');
  25670. var bodyChannel = generate$1('update-body');
  25671. var footerChannel = generate$1('update-footer');
  25672. var toValidValues = function (values) {
  25673. var errors = [];
  25674. var result = {};
  25675. each$1(values, function (value, name) {
  25676. value.fold(function () {
  25677. errors.push(name);
  25678. }, function (v) {
  25679. result[name] = v;
  25680. });
  25681. });
  25682. return errors.length > 0 ? Result.error(errors) : Result.value(result);
  25683. };
  25684. var renderBodyPanel = function (spec, backstage) {
  25685. var memForm = record(Form.sketch(function (parts) {
  25686. return {
  25687. dom: {
  25688. tag: 'div',
  25689. classes: ['tox-dialog__body-content']
  25690. },
  25691. components: map(spec.items, function (item) {
  25692. return interpretInForm(parts, item, backstage);
  25693. })
  25694. };
  25695. }));
  25696. return {
  25697. dom: {
  25698. tag: 'div',
  25699. classes: ['tox-dialog__body']
  25700. },
  25701. components: [memForm.asSpec()],
  25702. behaviours: derive$1([
  25703. Keying.config({
  25704. mode: 'acyclic',
  25705. useTabstopAt: not(NavigableObject.isPseudoStop)
  25706. }),
  25707. ComposingConfigs.memento(memForm),
  25708. RepresentingConfigs.memento(memForm, {
  25709. postprocess: function (formValue) {
  25710. return toValidValues(formValue).fold(function (err) {
  25711. console.error(err);
  25712. return {};
  25713. }, function (vals) {
  25714. return vals;
  25715. });
  25716. }
  25717. })
  25718. ])
  25719. };
  25720. };
  25721. var factory$g = function (detail, spec) {
  25722. return {
  25723. uid: detail.uid,
  25724. dom: detail.dom,
  25725. components: detail.components,
  25726. events: events$7(detail.action),
  25727. behaviours: augment(detail.tabButtonBehaviours, [
  25728. Focusing.config({}),
  25729. Keying.config({
  25730. mode: 'execution',
  25731. useSpace: true,
  25732. useEnter: true
  25733. }),
  25734. Representing.config({
  25735. store: {
  25736. mode: 'memory',
  25737. initialValue: detail.value
  25738. }
  25739. })
  25740. ]),
  25741. domModification: detail.domModification
  25742. };
  25743. };
  25744. var TabButton = single$2({
  25745. name: 'TabButton',
  25746. configFields: [
  25747. defaulted$1('uid', undefined),
  25748. strict$1('value'),
  25749. field('dom', 'dom', mergeWithThunk(function (spec) {
  25750. return {
  25751. attributes: {
  25752. 'role': 'tab',
  25753. 'id': generate$1('aria'),
  25754. 'aria-selected': 'false'
  25755. }
  25756. };
  25757. }), anyValue$1()),
  25758. option('action'),
  25759. defaulted$1('domModification', {}),
  25760. field$1('tabButtonBehaviours', [
  25761. Focusing,
  25762. Keying,
  25763. Representing
  25764. ]),
  25765. strict$1('view')
  25766. ],
  25767. factory: factory$g
  25768. });
  25769. var schema$r = constant([
  25770. strict$1('tabs'),
  25771. strict$1('dom'),
  25772. defaulted$1('clickToDismiss', false),
  25773. field$1('tabbarBehaviours', [
  25774. Highlighting,
  25775. Keying
  25776. ]),
  25777. markers([
  25778. 'tabClass',
  25779. 'selectedClass'
  25780. ])
  25781. ]);
  25782. var tabsPart = group({
  25783. factory: TabButton,
  25784. name: 'tabs',
  25785. unit: 'tab',
  25786. overrides: function (barDetail, tabSpec) {
  25787. var dismissTab$1 = function (tabbar, button) {
  25788. Highlighting.dehighlight(tabbar, button);
  25789. emitWith(tabbar, dismissTab(), {
  25790. tabbar: tabbar,
  25791. button: button
  25792. });
  25793. };
  25794. var changeTab$1 = function (tabbar, button) {
  25795. Highlighting.highlight(tabbar, button);
  25796. emitWith(tabbar, changeTab(), {
  25797. tabbar: tabbar,
  25798. button: button
  25799. });
  25800. };
  25801. return {
  25802. action: function (button) {
  25803. var tabbar = button.getSystem().getByUid(barDetail.uid).getOrDie();
  25804. var activeButton = Highlighting.isHighlighted(tabbar, button);
  25805. var response = function () {
  25806. if (activeButton && barDetail.clickToDismiss) {
  25807. return dismissTab$1;
  25808. } else if (!activeButton) {
  25809. return changeTab$1;
  25810. } else {
  25811. return noop;
  25812. }
  25813. }();
  25814. response(tabbar, button);
  25815. },
  25816. domModification: { classes: [barDetail.markers.tabClass] }
  25817. };
  25818. }
  25819. });
  25820. var parts$d = constant([tabsPart]);
  25821. var factory$h = function (detail, components, spec, externals) {
  25822. return {
  25823. 'uid': detail.uid,
  25824. 'dom': detail.dom,
  25825. 'components': components,
  25826. 'debug.sketcher': 'Tabbar',
  25827. domModification: { attributes: { role: 'tablist' } },
  25828. 'behaviours': augment(detail.tabbarBehaviours, [
  25829. Highlighting.config({
  25830. highlightClass: detail.markers.selectedClass,
  25831. itemClass: detail.markers.tabClass,
  25832. onHighlight: function (tabbar, tab) {
  25833. set$1(tab.element(), 'aria-selected', 'true');
  25834. },
  25835. onDehighlight: function (tabbar, tab) {
  25836. set$1(tab.element(), 'aria-selected', 'false');
  25837. }
  25838. }),
  25839. Keying.config({
  25840. mode: 'flow',
  25841. getInitial: function (tabbar) {
  25842. return Highlighting.getHighlighted(tabbar).map(function (tab) {
  25843. return tab.element();
  25844. });
  25845. },
  25846. selector: '.' + detail.markers.tabClass,
  25847. executeOnMove: true
  25848. })
  25849. ])
  25850. };
  25851. };
  25852. var Tabbar = composite$1({
  25853. name: 'Tabbar',
  25854. configFields: schema$r(),
  25855. partFields: parts$d(),
  25856. factory: factory$h
  25857. });
  25858. var factory$i = function (detail, spec) {
  25859. return {
  25860. uid: detail.uid,
  25861. dom: detail.dom,
  25862. behaviours: augment(detail.tabviewBehaviours, [Replacing.config({})]),
  25863. domModification: { attributes: { role: 'tabpanel' } }
  25864. };
  25865. };
  25866. var Tabview = single$2({
  25867. name: 'Tabview',
  25868. configFields: [field$1('tabviewBehaviours', [Replacing])],
  25869. factory: factory$i
  25870. });
  25871. var schema$s = constant([
  25872. defaulted$1('selectFirst', true),
  25873. onHandler('onChangeTab'),
  25874. onHandler('onDismissTab'),
  25875. defaulted$1('tabs', []),
  25876. field$1('tabSectionBehaviours', [])
  25877. ]);
  25878. var barPart = required({
  25879. factory: Tabbar,
  25880. schema: [
  25881. strict$1('dom'),
  25882. strictObjOf('markers', [
  25883. strict$1('tabClass'),
  25884. strict$1('selectedClass')
  25885. ])
  25886. ],
  25887. name: 'tabbar',
  25888. defaults: function (detail) {
  25889. return { tabs: detail.tabs };
  25890. }
  25891. });
  25892. var viewPart = required({
  25893. factory: Tabview,
  25894. name: 'tabview'
  25895. });
  25896. var parts$e = constant([
  25897. barPart,
  25898. viewPart
  25899. ]);
  25900. var factory$j = function (detail, components, spec, externals) {
  25901. var changeTab$1 = function (button) {
  25902. var tabValue = Representing.getValue(button);
  25903. getPart(button, detail, 'tabview').each(function (tabview) {
  25904. var tabWithValue = find(detail.tabs, function (t) {
  25905. return t.value === tabValue;
  25906. });
  25907. tabWithValue.each(function (tabData) {
  25908. var panel = tabData.view();
  25909. set$1(tabview.element(), 'aria-labelledby', get$2(button.element(), 'id'));
  25910. Replacing.set(tabview, panel);
  25911. detail.onChangeTab(tabview, button, panel);
  25912. });
  25913. });
  25914. };
  25915. var changeTabBy = function (section, byPred) {
  25916. getPart(section, detail, 'tabbar').each(function (tabbar) {
  25917. byPred(tabbar).each(emitExecute);
  25918. });
  25919. };
  25920. return {
  25921. uid: detail.uid,
  25922. dom: detail.dom,
  25923. components: components,
  25924. behaviours: get$b(detail.tabSectionBehaviours),
  25925. events: derive(flatten([
  25926. detail.selectFirst ? [runOnAttached(function (section, simulatedEvent) {
  25927. changeTabBy(section, Highlighting.getFirst);
  25928. })] : [],
  25929. [
  25930. run(changeTab(), function (section, simulatedEvent) {
  25931. var button = simulatedEvent.event().button();
  25932. changeTab$1(button);
  25933. }),
  25934. run(dismissTab(), function (section, simulatedEvent) {
  25935. var button = simulatedEvent.event().button();
  25936. detail.onDismissTab(section, button);
  25937. })
  25938. ]
  25939. ])),
  25940. apis: {
  25941. getViewItems: function (section) {
  25942. return getPart(section, detail, 'tabview').map(function (tabview) {
  25943. return Replacing.contents(tabview);
  25944. }).getOr([]);
  25945. },
  25946. showTab: function (section, tabKey) {
  25947. var getTabIfNotActive = function (tabbar) {
  25948. var candidates = Highlighting.getCandidates(tabbar);
  25949. var optTab = find(candidates, function (c) {
  25950. return Representing.getValue(c) === tabKey;
  25951. });
  25952. return optTab.filter(function (tab) {
  25953. return !Highlighting.isHighlighted(tabbar, tab);
  25954. });
  25955. };
  25956. changeTabBy(section, getTabIfNotActive);
  25957. }
  25958. }
  25959. };
  25960. };
  25961. var TabSection = composite$1({
  25962. name: 'TabSection',
  25963. configFields: schema$s(),
  25964. partFields: parts$e(),
  25965. factory: factory$j,
  25966. apis: {
  25967. getViewItems: function (apis, component) {
  25968. return apis.getViewItems(component);
  25969. },
  25970. showTab: function (apis, component, tabKey) {
  25971. apis.showTab(component, tabKey);
  25972. }
  25973. }
  25974. });
  25975. var measureHeights = function (allTabs, tabview, tabviewComp) {
  25976. return map(allTabs, function (tab, i) {
  25977. Replacing.set(tabviewComp, allTabs[i].view());
  25978. var rect = tabview.dom().getBoundingClientRect();
  25979. Replacing.set(tabviewComp, []);
  25980. return rect.height;
  25981. });
  25982. };
  25983. var getMaxHeight = function (heights) {
  25984. return head(sort(heights, function (a, b) {
  25985. if (a > b) {
  25986. return -1;
  25987. } else if (a < b) {
  25988. return +1;
  25989. } else {
  25990. return 0;
  25991. }
  25992. }));
  25993. };
  25994. var getMaxTabviewHeight = function (dialog, dialogBody) {
  25995. var rootElm = ancestor$1(dialog, '.tox-dialog-wrap').getOr(dialog);
  25996. var isFixed = get$4(rootElm, 'position') === 'fixed';
  25997. var maxHeight;
  25998. if (isFixed) {
  25999. maxHeight = Math.max(domGlobals.document.documentElement.clientHeight, domGlobals.window.innerHeight);
  26000. } else {
  26001. maxHeight = Math.max(domGlobals.document.documentElement.offsetHeight, domGlobals.document.documentElement.scrollHeight);
  26002. }
  26003. var dialogChrome = dialog.dom().getBoundingClientRect().height - dialogBody.dom().getBoundingClientRect().height;
  26004. return maxHeight - dialogChrome;
  26005. };
  26006. var showTab = function (allTabs, comp) {
  26007. head(allTabs).each(function (tab) {
  26008. return TabSection.showTab(comp, tab.value);
  26009. });
  26010. };
  26011. var updateTabviewHeight = function (dialogBody, tabview, maxTabHeight) {
  26012. ancestor$1(dialogBody, '[role="dialog"]').each(function (dialog) {
  26013. maxTabHeight.get().map(function (height) {
  26014. set$2(tabview, 'height', '0');
  26015. return Math.min(height, getMaxTabviewHeight(dialog, dialogBody));
  26016. }).each(function (height) {
  26017. set$2(tabview, 'height', height + 'px');
  26018. });
  26019. });
  26020. };
  26021. var setMode = function (allTabs) {
  26022. var smartTabHeight = function () {
  26023. var maxTabHeight = Cell(Option.none());
  26024. var extraEvents = [
  26025. runOnAttached(function (comp) {
  26026. descendant$1(comp.element(), '[role="tabpanel"]').each(function (tabview) {
  26027. set$2(tabview, 'visibility', 'hidden');
  26028. comp.getSystem().getByDom(tabview).toOption().each(function (tabviewComp) {
  26029. var heights = measureHeights(allTabs, tabview, tabviewComp);
  26030. var maxTabHeightOpt = getMaxHeight(heights);
  26031. maxTabHeight.set(maxTabHeightOpt);
  26032. });
  26033. updateTabviewHeight(comp.element(), tabview, maxTabHeight);
  26034. remove$6(tabview, 'visibility');
  26035. showTab(allTabs, comp);
  26036. global$c.requestAnimationFrame(function () {
  26037. updateTabviewHeight(comp.element(), tabview, maxTabHeight);
  26038. });
  26039. });
  26040. }),
  26041. run(windowResize(), function (comp) {
  26042. descendant$1(comp.element(), '[role="tabpanel"]').each(function (tabview) {
  26043. updateTabviewHeight(comp.element(), tabview, maxTabHeight);
  26044. });
  26045. }),
  26046. run(formResizeEvent, function (comp, se) {
  26047. descendant$1(comp.element(), '[role="tabpanel"]').each(function (tabview) {
  26048. var oldFocus = active();
  26049. set$2(tabview, 'visibility', 'hidden');
  26050. var oldHeight = getRaw(tabview, 'height').map(function (h) {
  26051. return parseInt(h, 10);
  26052. });
  26053. remove$6(tabview, 'height');
  26054. var newHeight = tabview.dom().getBoundingClientRect().height;
  26055. var hasGrown = oldHeight.forall(function (h) {
  26056. return newHeight > h;
  26057. });
  26058. if (hasGrown) {
  26059. maxTabHeight.set(Option.from(newHeight));
  26060. updateTabviewHeight(comp.element(), tabview, maxTabHeight);
  26061. } else {
  26062. oldHeight.each(function (h) {
  26063. set$2(tabview, 'height', h + 'px');
  26064. });
  26065. }
  26066. remove$6(tabview, 'visibility');
  26067. oldFocus.each(focus$1);
  26068. });
  26069. })
  26070. ];
  26071. var selectFirst = false;
  26072. return {
  26073. extraEvents: extraEvents,
  26074. selectFirst: selectFirst
  26075. };
  26076. }();
  26077. var naiveTabHeight = function () {
  26078. var extraEvents = [];
  26079. var selectFirst = true;
  26080. return {
  26081. extraEvents: extraEvents,
  26082. selectFirst: selectFirst
  26083. };
  26084. }();
  26085. return {
  26086. smartTabHeight: smartTabHeight,
  26087. naiveTabHeight: naiveTabHeight
  26088. };
  26089. };
  26090. var SendDataToSectionChannel = 'send-data-to-section';
  26091. var SendDataToViewChannel = 'send-data-to-view';
  26092. var renderTabPanel = function (spec, backstage) {
  26093. var storedValue = Cell({});
  26094. var updateDataWithForm = function (form) {
  26095. var formData = Representing.getValue(form);
  26096. var validData = toValidValues(formData).getOr({});
  26097. var currentData = storedValue.get();
  26098. var newData = deepMerge(currentData, validData);
  26099. storedValue.set(newData);
  26100. };
  26101. var setDataOnForm = function (form) {
  26102. var tabData = storedValue.get();
  26103. Representing.setValue(form, tabData);
  26104. };
  26105. var oldTab = Cell(null);
  26106. var allTabs = map(spec.tabs, function (tab) {
  26107. return {
  26108. value: tab.title,
  26109. dom: {
  26110. tag: 'div',
  26111. classes: ['tox-dialog__body-nav-item'],
  26112. innerHtml: backstage.shared.providers.translate(tab.title)
  26113. },
  26114. view: function () {
  26115. return [Form.sketch(function (parts) {
  26116. return {
  26117. dom: {
  26118. tag: 'div',
  26119. classes: ['tox-form']
  26120. },
  26121. components: map(tab.items, function (item) {
  26122. return interpretInForm(parts, item, backstage);
  26123. }),
  26124. formBehaviours: derive$1([
  26125. Keying.config({
  26126. mode: 'acyclic',
  26127. useTabstopAt: not(NavigableObject.isPseudoStop)
  26128. }),
  26129. config('TabView.form.events', [
  26130. runOnAttached(setDataOnForm),
  26131. runOnDetached(updateDataWithForm)
  26132. ]),
  26133. Receiving.config({
  26134. channels: wrapAll$1([
  26135. {
  26136. key: SendDataToSectionChannel,
  26137. value: { onReceive: updateDataWithForm }
  26138. },
  26139. {
  26140. key: SendDataToViewChannel,
  26141. value: { onReceive: setDataOnForm }
  26142. }
  26143. ])
  26144. })
  26145. ])
  26146. };
  26147. })];
  26148. }
  26149. };
  26150. });
  26151. var tabMode = setMode(allTabs).smartTabHeight;
  26152. return TabSection.sketch({
  26153. dom: {
  26154. tag: 'div',
  26155. classes: ['tox-dialog__body']
  26156. },
  26157. onChangeTab: function (section, button, _viewItems) {
  26158. var title = Representing.getValue(button);
  26159. emitWith(section, formTabChangeEvent, {
  26160. title: title,
  26161. oldTitle: oldTab.get()
  26162. });
  26163. oldTab.set(title);
  26164. },
  26165. tabs: allTabs,
  26166. components: [
  26167. TabSection.parts().tabbar({
  26168. dom: {
  26169. tag: 'div',
  26170. classes: ['tox-dialog__body-nav']
  26171. },
  26172. components: [Tabbar.parts().tabs({})],
  26173. markers: {
  26174. tabClass: 'tox-tab',
  26175. selectedClass: 'tox-dialog__body-nav-item--active'
  26176. },
  26177. tabbarBehaviours: derive$1([Tabstopping.config({})])
  26178. }),
  26179. TabSection.parts().tabview({
  26180. dom: {
  26181. tag: 'div',
  26182. classes: ['tox-dialog__body-content']
  26183. }
  26184. })
  26185. ],
  26186. selectFirst: tabMode.selectFirst,
  26187. tabSectionBehaviours: derive$1([
  26188. config('tabpanel', tabMode.extraEvents),
  26189. Keying.config({ mode: 'acyclic' }),
  26190. Composing.config({
  26191. find: function (comp) {
  26192. return head(TabSection.getViewItems(comp));
  26193. }
  26194. }),
  26195. Representing.config({
  26196. store: {
  26197. mode: 'manual',
  26198. getValue: function (tsection) {
  26199. tsection.getSystem().broadcastOn([SendDataToSectionChannel], {});
  26200. return storedValue.get();
  26201. },
  26202. setValue: function (tsection, value) {
  26203. storedValue.set(value);
  26204. tsection.getSystem().broadcastOn([SendDataToViewChannel], {});
  26205. }
  26206. }
  26207. })
  26208. ])
  26209. });
  26210. };
  26211. var renderBody = function (foo, backstage) {
  26212. var renderComponents = function (incoming) {
  26213. switch (incoming.body.type) {
  26214. case 'tabpanel': {
  26215. return [renderTabPanel({ tabs: incoming.body.tabs }, backstage)];
  26216. }
  26217. default: {
  26218. return [renderBodyPanel({ items: incoming.body.items }, backstage)];
  26219. }
  26220. }
  26221. };
  26222. var updateState = function (_comp, incoming) {
  26223. return Option.some({
  26224. isTabPanel: function () {
  26225. return incoming.body.type === 'tabpanel';
  26226. }
  26227. });
  26228. };
  26229. return {
  26230. dom: {
  26231. tag: 'div',
  26232. classes: ['tox-dialog__content-js']
  26233. },
  26234. components: [],
  26235. behaviours: derive$1([
  26236. ComposingConfigs.childAt(0),
  26237. Reflecting.config({
  26238. channel: bodyChannel,
  26239. updateState: updateState,
  26240. renderComponents: renderComponents,
  26241. initialData: foo
  26242. })
  26243. ])
  26244. };
  26245. };
  26246. var renderInlineBody = function (foo, backstage) {
  26247. return renderBody(foo, backstage);
  26248. };
  26249. var renderModalBody = function (foo, backstage) {
  26250. return ModalDialog.parts().body(renderBody(foo, backstage));
  26251. };
  26252. var init$e = function (getInstanceApi, extras) {
  26253. var fireApiEvent = function (eventName, f) {
  26254. return run(eventName, function (c, se) {
  26255. withSpec(c, function (spec, _c) {
  26256. f(spec, se.event(), c);
  26257. });
  26258. });
  26259. };
  26260. var withSpec = function (c, f) {
  26261. Reflecting.getState(c).get().each(function (currentDialogInit) {
  26262. f(currentDialogInit.internalDialog, c);
  26263. });
  26264. };
  26265. return [
  26266. runWithTarget(focusin(), NavigableObject.onFocus),
  26267. fireApiEvent(formSubmitEvent, function (spec) {
  26268. return spec.onSubmit(getInstanceApi());
  26269. }),
  26270. fireApiEvent(formChangeEvent, function (spec, event) {
  26271. spec.onChange(getInstanceApi(), { name: event.name() });
  26272. }),
  26273. fireApiEvent(formActionEvent, function (spec, event) {
  26274. spec.onAction(getInstanceApi(), {
  26275. name: event.name(),
  26276. value: event.value()
  26277. });
  26278. }),
  26279. fireApiEvent(formTabChangeEvent, function (spec, event) {
  26280. spec.onTabChange(getInstanceApi(), event.title());
  26281. }),
  26282. fireApiEvent(formCloseEvent, function (spec) {
  26283. extras.onClose();
  26284. spec.onClose();
  26285. }),
  26286. fireApiEvent(formCancelEvent, function (spec, _event, self) {
  26287. spec.onCancel(getInstanceApi());
  26288. emit(self, formCloseEvent);
  26289. }),
  26290. runOnDetached(function (component) {
  26291. var api = getInstanceApi();
  26292. Representing.setValue(component, api.getData());
  26293. }),
  26294. run(formUnblockEvent, function (c, se) {
  26295. return extras.onUnblock();
  26296. }),
  26297. run(formBlockEvent, function (c, se) {
  26298. return extras.onBlock(se.event());
  26299. })
  26300. ];
  26301. };
  26302. var SilverDialogEvents = { init: init$e };
  26303. var makeButton = function (button, providersBackstage) {
  26304. return renderFooterButton(button, button.type, providersBackstage);
  26305. };
  26306. var lookup$2 = function (compInSystem, footerButtons, buttonName) {
  26307. return find(footerButtons, function (button) {
  26308. return button.name === buttonName;
  26309. }).bind(function (memButton) {
  26310. return memButton.memento.getOpt(compInSystem);
  26311. });
  26312. };
  26313. var renderComponents = function (_data, state) {
  26314. var footerButtons = state.map(function (s) {
  26315. return s.footerButtons;
  26316. }).getOr([]);
  26317. var buttonGroups = partition(footerButtons, function (button) {
  26318. return button.align === 'start';
  26319. });
  26320. var makeGroup = function (edge, buttons) {
  26321. return Container.sketch({
  26322. dom: {
  26323. tag: 'div',
  26324. classes: ['tox-dialog__footer-' + edge]
  26325. },
  26326. components: map(buttons, function (button) {
  26327. return button.memento.asSpec();
  26328. })
  26329. });
  26330. };
  26331. var startButtons = makeGroup('start', buttonGroups.pass);
  26332. var endButtons = makeGroup('end', buttonGroups.fail);
  26333. return [
  26334. startButtons,
  26335. endButtons
  26336. ];
  26337. };
  26338. var renderFooter = function (initFoo, providersBackstage) {
  26339. var updateState = function (_comp, data) {
  26340. var footerButtons = map(data.buttons, function (button) {
  26341. var memButton = record(makeButton(button, providersBackstage));
  26342. return {
  26343. name: button.name,
  26344. align: button.align,
  26345. memento: memButton
  26346. };
  26347. });
  26348. var lookupByName = function (compInSystem, buttonName) {
  26349. return lookup$2(compInSystem, footerButtons, buttonName);
  26350. };
  26351. return Option.some({
  26352. lookupByName: lookupByName,
  26353. footerButtons: footerButtons
  26354. });
  26355. };
  26356. return {
  26357. dom: fromHtml$2('<div class="tox-dialog__footer"></div>'),
  26358. components: [],
  26359. behaviours: derive$1([Reflecting.config({
  26360. channel: footerChannel,
  26361. initialData: initFoo,
  26362. updateState: updateState,
  26363. renderComponents: renderComponents
  26364. })])
  26365. };
  26366. };
  26367. var renderInlineFooter = function (initFoo, providersBackstage) {
  26368. return renderFooter(initFoo, providersBackstage);
  26369. };
  26370. var renderModalFooter = function (initFoo, providersBackstage) {
  26371. return ModalDialog.parts().footer(renderFooter(initFoo, providersBackstage));
  26372. };
  26373. var renderClose = function (providersBackstage) {
  26374. return Button.sketch({
  26375. dom: {
  26376. tag: 'button',
  26377. classes: [
  26378. 'tox-button',
  26379. 'tox-button--icon',
  26380. 'tox-button--naked'
  26381. ],
  26382. attributes: {
  26383. 'type': 'button',
  26384. 'aria-label': providersBackstage.translate('Close'),
  26385. 'title': providersBackstage.translate('Close')
  26386. }
  26387. },
  26388. components: [{
  26389. dom: {
  26390. tag: 'div',
  26391. classes: ['tox-icon'],
  26392. innerHtml: '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"><path d="M17.953 7.453L13.422 12l4.531 4.547-1.406 1.406L12 13.422l-4.547 4.531-1.406-1.406L10.578 12 6.047 7.453l1.406-1.406L12 10.578l4.547-4.531z" fill-rule="evenodd"></path></svg>'
  26393. }
  26394. }],
  26395. action: function (comp) {
  26396. emit(comp, formCancelEvent);
  26397. }
  26398. });
  26399. };
  26400. var renderTitle = function (foo, id, providersBackstage) {
  26401. var renderComponents = function (data) {
  26402. return [text(providersBackstage.translate(data.title))];
  26403. };
  26404. return {
  26405. dom: {
  26406. tag: 'div',
  26407. classes: ['tox-dialog__title'],
  26408. attributes: __assign({}, id.map(function (x) {
  26409. return { id: x };
  26410. }).getOr({}))
  26411. },
  26412. components: renderComponents(foo),
  26413. behaviours: derive$1([Reflecting.config({
  26414. channel: titleChannel,
  26415. renderComponents: renderComponents
  26416. })])
  26417. };
  26418. };
  26419. var renderInlineHeader = function (foo, titleId, providersBackstage) {
  26420. return Container.sketch({
  26421. dom: fromHtml$2('<div class="tox-dialog__header"></div>'),
  26422. components: [
  26423. renderTitle(foo, Option.some(titleId), providersBackstage),
  26424. renderClose(providersBackstage)
  26425. ],
  26426. containerBehaviours: derive$1([Dragging.config({
  26427. mode: 'mouse',
  26428. blockerClass: 'blocker',
  26429. getTarget: function (handle) {
  26430. return closest$3(handle, '[role="dialog"]').getOrDie();
  26431. },
  26432. snaps: {
  26433. getSnapPoints: function () {
  26434. return [];
  26435. },
  26436. leftAttr: 'data-drag-left',
  26437. topAttr: 'data-drag-top'
  26438. }
  26439. })])
  26440. });
  26441. };
  26442. var renderModalHeader = function (foo, providersBackstage) {
  26443. var pTitle = ModalDialog.parts().title(renderTitle(foo, Option.none(), providersBackstage));
  26444. var pHandle = ModalDialog.parts().draghandle({ dom: fromHtml$2('<div class="tox-dialog__draghandle"></div>') });
  26445. var pClose = ModalDialog.parts().close(renderClose(providersBackstage));
  26446. var components = [pTitle].concat(foo.draggable ? [pHandle] : []).concat([pClose]);
  26447. return Container.sketch({
  26448. dom: fromHtml$2('<div class="tox-dialog__header"></div>'),
  26449. components: components
  26450. });
  26451. };
  26452. var getCompByName = function (access, name) {
  26453. var root = access.getRoot();
  26454. if (root.getSystem().isConnected()) {
  26455. var form_1 = Composing.getCurrent(access.getFormWrapper()).getOr(access.getFormWrapper());
  26456. return Form.getField(form_1, name).fold(function () {
  26457. var footer = access.getFooter();
  26458. var footerState = Reflecting.getState(footer);
  26459. return footerState.get().bind(function (f) {
  26460. return f.lookupByName(form_1, name);
  26461. });
  26462. }, function (comp) {
  26463. return Option.some(comp);
  26464. });
  26465. } else {
  26466. return Option.none();
  26467. }
  26468. };
  26469. var validateData = function (access, data) {
  26470. var root = access.getRoot();
  26471. return Reflecting.getState(root).get().map(function (dialogState) {
  26472. return getOrDie$1(asRaw('data', dialogState.dataValidator, data));
  26473. }).getOr(data);
  26474. };
  26475. var getDialogApi = function (access, doRedial) {
  26476. var withRoot = function (f) {
  26477. var root = access.getRoot();
  26478. if (root.getSystem().isConnected()) {
  26479. f(root);
  26480. }
  26481. };
  26482. var getData = function () {
  26483. var root = access.getRoot();
  26484. var valueComp = root.getSystem().isConnected() ? access.getFormWrapper() : root;
  26485. return Representing.getValue(valueComp);
  26486. };
  26487. var setData = function (newData) {
  26488. withRoot(function (_) {
  26489. var prevData = instanceApi.getData();
  26490. var mergedData = merge(prevData, newData);
  26491. var newInternalData = validateData(access, mergedData);
  26492. var form = access.getFormWrapper();
  26493. Representing.setValue(form, newInternalData);
  26494. });
  26495. };
  26496. var disable = function (name) {
  26497. getCompByName(access, name).each(Disabling.disable);
  26498. };
  26499. var enable = function (name) {
  26500. getCompByName(access, name).each(Disabling.enable);
  26501. };
  26502. var focus = function (name) {
  26503. getCompByName(access, name).each(Focusing.focus);
  26504. };
  26505. var block = function (message) {
  26506. if (!isString(message)) {
  26507. throw new Error('The dialogInstanceAPI.block function should be passed a blocking message of type string as an argument');
  26508. }
  26509. withRoot(function (root) {
  26510. emitWith(root, formBlockEvent, { message: message });
  26511. });
  26512. };
  26513. var unblock = function () {
  26514. withRoot(function (root) {
  26515. emit(root, formUnblockEvent);
  26516. });
  26517. };
  26518. var showTab = function (title) {
  26519. withRoot(function (_) {
  26520. var body = access.getBody();
  26521. var bodyState = Reflecting.getState(body);
  26522. if (bodyState.get().exists(function (b) {
  26523. return b.isTabPanel();
  26524. })) {
  26525. Composing.getCurrent(body).each(function (tabSection) {
  26526. TabSection.showTab(tabSection, title);
  26527. });
  26528. }
  26529. });
  26530. };
  26531. var redial = function (d) {
  26532. withRoot(function (root) {
  26533. var dialogInit = doRedial(d);
  26534. root.getSystem().broadcastOn([dialogChannel], dialogInit);
  26535. root.getSystem().broadcastOn([titleChannel], dialogInit.internalDialog);
  26536. root.getSystem().broadcastOn([bodyChannel], dialogInit.internalDialog);
  26537. root.getSystem().broadcastOn([footerChannel], dialogInit.internalDialog);
  26538. instanceApi.setData(dialogInit.initialData);
  26539. });
  26540. };
  26541. var close = function () {
  26542. withRoot(function (root) {
  26543. emit(root, formCloseEvent);
  26544. });
  26545. };
  26546. var instanceApi = {
  26547. getData: getData,
  26548. setData: setData,
  26549. disable: disable,
  26550. enable: enable,
  26551. focus: focus,
  26552. block: block,
  26553. unblock: unblock,
  26554. showTab: showTab,
  26555. redial: redial,
  26556. close: close
  26557. };
  26558. return instanceApi;
  26559. };
  26560. var renderDialog = function (dialogInit, extra, backstage) {
  26561. var _a;
  26562. var updateState = function (_comp, incoming) {
  26563. return Option.some(incoming);
  26564. };
  26565. var header = renderModalHeader({
  26566. title: backstage.shared.providers.translate(dialogInit.internalDialog.title),
  26567. draggable: true
  26568. }, backstage.shared.providers);
  26569. var body$1 = renderModalBody({ body: dialogInit.internalDialog.body }, backstage);
  26570. var footer = renderModalFooter({ buttons: dialogInit.internalDialog.buttons }, backstage.shared.providers);
  26571. var dialogEvents = SilverDialogEvents.init(function () {
  26572. return instanceApi;
  26573. }, {
  26574. onClose: function () {
  26575. return extra.closeWindow();
  26576. },
  26577. onBlock: function (blockEvent) {
  26578. ModalDialog.setBusy(dialog, function (d, bs) {
  26579. return {
  26580. dom: {
  26581. tag: 'div',
  26582. classes: ['tox-dialog__busy-spinner'],
  26583. attributes: { 'aria-label': blockEvent.message() },
  26584. styles: {
  26585. left: '0px',
  26586. right: '0px',
  26587. bottom: '0px',
  26588. top: '0px',
  26589. position: 'absolute'
  26590. }
  26591. },
  26592. behaviours: bs,
  26593. components: [{ dom: fromHtml$2('<div class="tox-spinner"><div></div><div></div><div></div></div>') }]
  26594. };
  26595. });
  26596. },
  26597. onUnblock: function () {
  26598. ModalDialog.setIdle(dialog);
  26599. }
  26600. });
  26601. var dialogSize = dialogInit.internalDialog.size !== 'normal' ? dialogInit.internalDialog.size === 'large' ? 'tox-dialog--width-lg' : 'tox-dialog--width-md' : [];
  26602. var dialog = build$1(ModalDialog.sketch({
  26603. lazySink: backstage.shared.getSink,
  26604. onEscape: function (c) {
  26605. emit(c, formCancelEvent);
  26606. return Option.some(true);
  26607. },
  26608. useTabstopAt: function (elem) {
  26609. return !NavigableObject.isPseudoStop(elem) && (name(elem) !== 'button' || get$2(elem, 'disabled') !== 'disabled');
  26610. },
  26611. modalBehaviours: derive$1([
  26612. Reflecting.config({
  26613. channel: dialogChannel,
  26614. updateState: updateState,
  26615. initialData: dialogInit
  26616. }),
  26617. Focusing.config({}),
  26618. config('execute-on-form', dialogEvents.concat([runOnSource(focusin(), function (comp, se) {
  26619. Keying.focusIn(comp);
  26620. })])),
  26621. config('scroll-lock', [
  26622. runOnAttached(function () {
  26623. add$2(body(), 'tox-dialog__disable-scroll');
  26624. }),
  26625. runOnDetached(function () {
  26626. remove$4(body(), 'tox-dialog__disable-scroll');
  26627. })
  26628. ]),
  26629. RepresentingConfigs.memory({})
  26630. ]),
  26631. eventOrder: (_a = {}, _a[execute()] = ['execute-on-form'], _a[attachedToDom()] = [
  26632. 'scroll-lock',
  26633. 'reflecting',
  26634. 'execute-on-form',
  26635. 'alloy.base.behaviour'
  26636. ], _a[detachedFromDom()] = [
  26637. 'alloy.base.behaviour',
  26638. 'execute-on-form',
  26639. 'reflecting',
  26640. 'scroll-lock'
  26641. ], _a),
  26642. dom: {
  26643. tag: 'div',
  26644. classes: ['tox-dialog'].concat(dialogSize),
  26645. styles: { position: 'relative' }
  26646. },
  26647. components: [
  26648. header,
  26649. body$1,
  26650. footer
  26651. ],
  26652. dragBlockClass: 'tox-dialog-wrap',
  26653. parts: {
  26654. blocker: {
  26655. dom: fromHtml$2('<div class="tox-dialog-wrap"></div>'),
  26656. components: [{
  26657. dom: {
  26658. tag: 'div',
  26659. classes: ['tox-dialog-wrap__backdrop']
  26660. }
  26661. }]
  26662. }
  26663. }
  26664. }));
  26665. var modalAccess = function () {
  26666. var getForm = function () {
  26667. var outerForm = ModalDialog.getBody(dialog);
  26668. return Composing.getCurrent(outerForm).getOr(outerForm);
  26669. };
  26670. return {
  26671. getRoot: function () {
  26672. return dialog;
  26673. },
  26674. getBody: function () {
  26675. return ModalDialog.getBody(dialog);
  26676. },
  26677. getFooter: function () {
  26678. return ModalDialog.getFooter(dialog);
  26679. },
  26680. getFormWrapper: getForm
  26681. };
  26682. }();
  26683. var instanceApi = getDialogApi(modalAccess, extra.redial);
  26684. return {
  26685. dialog: dialog,
  26686. instanceApi: instanceApi
  26687. };
  26688. };
  26689. var renderInlineDialog = function (dialogInit, extra, backstage) {
  26690. var _a, _b;
  26691. var dialogLabelId = generate$1('dialog-label');
  26692. var updateState = function (_comp, incoming) {
  26693. return Option.some(incoming);
  26694. };
  26695. var memHeader = record(renderInlineHeader({
  26696. title: dialogInit.internalDialog.title,
  26697. draggable: true
  26698. }, dialogLabelId, backstage.shared.providers));
  26699. var memBody = record(renderInlineBody({ body: dialogInit.internalDialog.body }, backstage));
  26700. var memFooter = record(renderInlineFooter({ buttons: dialogInit.internalDialog.buttons }, backstage.shared.providers));
  26701. var dialogEvents = SilverDialogEvents.init(function () {
  26702. return instanceApi;
  26703. }, {
  26704. onBlock: function () {
  26705. },
  26706. onUnblock: function () {
  26707. },
  26708. onClose: function () {
  26709. return extra.closeWindow();
  26710. }
  26711. });
  26712. var dialog = build$1({
  26713. dom: {
  26714. tag: 'div',
  26715. classes: ['tox-dialog'],
  26716. attributes: (_a = { role: 'dialog' }, _a['aria-labelledby'] = dialogLabelId, _a)
  26717. },
  26718. eventOrder: (_b = {}, _b[receive()] = [
  26719. Reflecting.name(),
  26720. Receiving.name()
  26721. ], _b[execute()] = ['execute-on-form'], _b[attachedToDom()] = [
  26722. 'reflecting',
  26723. 'execute-on-form'
  26724. ], _b),
  26725. behaviours: derive$1([
  26726. Keying.config({
  26727. mode: 'cyclic',
  26728. onEscape: function (c) {
  26729. emit(c, formCloseEvent);
  26730. return Option.some(true);
  26731. },
  26732. useTabstopAt: function (elem) {
  26733. return !NavigableObject.isPseudoStop(elem) && (name(elem) !== 'button' || get$2(elem, 'disabled') !== 'disabled');
  26734. }
  26735. }),
  26736. Reflecting.config({
  26737. channel: dialogChannel,
  26738. updateState: updateState,
  26739. initialData: dialogInit
  26740. }),
  26741. config('execute-on-form', dialogEvents),
  26742. RepresentingConfigs.memory({})
  26743. ]),
  26744. components: [
  26745. memHeader.asSpec(),
  26746. memBody.asSpec(),
  26747. memFooter.asSpec()
  26748. ]
  26749. });
  26750. var instanceApi = getDialogApi({
  26751. getRoot: function () {
  26752. return dialog;
  26753. },
  26754. getFooter: function () {
  26755. return memFooter.get(dialog);
  26756. },
  26757. getBody: function () {
  26758. return memBody.get(dialog);
  26759. },
  26760. getFormWrapper: function () {
  26761. var body = memBody.get(dialog);
  26762. return Composing.getCurrent(body).getOr(body);
  26763. }
  26764. }, extra.redial);
  26765. return {
  26766. dialog: dialog,
  26767. instanceApi: instanceApi
  26768. };
  26769. };
  26770. var pClose = function (onClose, providersBackstage) {
  26771. return ModalDialog.parts().close(Button.sketch({
  26772. dom: {
  26773. tag: 'button',
  26774. classes: [
  26775. 'tox-button',
  26776. 'tox-button--icon',
  26777. 'tox-button--naked'
  26778. ],
  26779. attributes: {
  26780. 'type': 'button',
  26781. 'aria-label': providersBackstage.translate('Close')
  26782. }
  26783. },
  26784. action: onClose,
  26785. buttonBehaviours: derive$1([Tabstopping.config({})])
  26786. }));
  26787. };
  26788. var pUntitled = function () {
  26789. return ModalDialog.parts().title({
  26790. dom: {
  26791. tag: 'div',
  26792. classes: ['tox-dialog__title'],
  26793. innerHtml: '',
  26794. styles: { display: 'none' }
  26795. }
  26796. });
  26797. };
  26798. var pBodyMessage = function (message, providersBackstage) {
  26799. return ModalDialog.parts().body({
  26800. dom: {
  26801. tag: 'div',
  26802. classes: [
  26803. 'tox-dialog__body',
  26804. 'todo-tox-fit'
  26805. ]
  26806. },
  26807. components: [{ dom: fromHtml$2('<p>' + providersBackstage.translate(message) + '</p>') }]
  26808. });
  26809. };
  26810. var pFooter = function (buttons) {
  26811. return ModalDialog.parts().footer({
  26812. dom: {
  26813. tag: 'div',
  26814. classes: ['tox-dialog__footer']
  26815. },
  26816. components: buttons
  26817. });
  26818. };
  26819. var pFooterGroup = function (startButtons, endButtons) {
  26820. return [
  26821. Container.sketch({
  26822. dom: {
  26823. tag: 'div',
  26824. classes: ['tox-dialog__footer-start']
  26825. },
  26826. components: startButtons
  26827. }),
  26828. Container.sketch({
  26829. dom: {
  26830. tag: 'div',
  26831. classes: ['tox-dialog__footer-end']
  26832. },
  26833. components: endButtons
  26834. })
  26835. ];
  26836. };
  26837. var renderDialog$1 = function (spec) {
  26838. return ModalDialog.sketch({
  26839. lazySink: spec.lazySink,
  26840. onEscape: function () {
  26841. spec.onCancel();
  26842. return Option.some(true);
  26843. },
  26844. dom: {
  26845. tag: 'div',
  26846. classes: ['tox-dialog'].concat(spec.extraClasses)
  26847. },
  26848. components: [
  26849. {
  26850. dom: {
  26851. tag: 'div',
  26852. classes: ['tox-dialog__header']
  26853. },
  26854. components: [
  26855. spec.partSpecs.title,
  26856. spec.partSpecs.close
  26857. ]
  26858. },
  26859. spec.partSpecs.body,
  26860. spec.partSpecs.footer
  26861. ],
  26862. parts: {
  26863. blocker: {
  26864. dom: fromHtml$2('<div class="tox-dialog-wrap"></div>'),
  26865. components: [{
  26866. dom: {
  26867. tag: 'div',
  26868. classes: ['tox-dialog-wrap__backdrop']
  26869. }
  26870. }]
  26871. }
  26872. },
  26873. modalBehaviours: derive$1([config('basic-dialog-events', [
  26874. run(formCancelEvent, function (comp, se) {
  26875. spec.onCancel();
  26876. }),
  26877. run(formSubmitEvent, function (comp, se) {
  26878. spec.onSubmit();
  26879. })
  26880. ])])
  26881. });
  26882. };
  26883. var setup$8 = function (extras) {
  26884. var sharedBackstage = extras.backstage.shared;
  26885. var open = function (message, callback) {
  26886. var closeDialog = function () {
  26887. ModalDialog.hide(alertDialog);
  26888. callback();
  26889. };
  26890. var memFooterClose = record(renderFooterButton({
  26891. name: 'close-alert',
  26892. text: 'OK',
  26893. primary: true,
  26894. icon: Option.none()
  26895. }, 'cancel', sharedBackstage.providers));
  26896. var alertDialog = build$1(renderDialog$1({
  26897. lazySink: function () {
  26898. return sharedBackstage.getSink();
  26899. },
  26900. partSpecs: {
  26901. title: pUntitled(),
  26902. close: pClose(function () {
  26903. closeDialog();
  26904. }, sharedBackstage.providers),
  26905. body: pBodyMessage(message, sharedBackstage.providers),
  26906. footer: pFooter(pFooterGroup([], [memFooterClose.asSpec()]))
  26907. },
  26908. onCancel: function () {
  26909. return closeDialog();
  26910. },
  26911. onSubmit: noop,
  26912. extraClasses: ['tox-alert-dialog']
  26913. }));
  26914. ModalDialog.show(alertDialog);
  26915. var footerCloseButton = memFooterClose.get(alertDialog);
  26916. Focusing.focus(footerCloseButton);
  26917. };
  26918. return { open: open };
  26919. };
  26920. var setup$9 = function (extras) {
  26921. var sharedBackstage = extras.backstage.shared;
  26922. var open = function (message, callback) {
  26923. var closeDialog = function (state) {
  26924. ModalDialog.hide(confirmDialog);
  26925. callback(state);
  26926. };
  26927. var memFooterYes = record(renderFooterButton({
  26928. name: 'yes',
  26929. text: 'Yes',
  26930. primary: true,
  26931. icon: Option.none()
  26932. }, 'submit', sharedBackstage.providers));
  26933. var footerNo = renderFooterButton({
  26934. name: 'no',
  26935. text: 'No',
  26936. primary: true,
  26937. icon: Option.none()
  26938. }, 'cancel', sharedBackstage.providers);
  26939. var confirmDialog = build$1(renderDialog$1({
  26940. lazySink: function () {
  26941. return sharedBackstage.getSink();
  26942. },
  26943. partSpecs: {
  26944. title: pUntitled(),
  26945. close: pClose(function () {
  26946. closeDialog(false);
  26947. }, sharedBackstage.providers),
  26948. body: pBodyMessage(message, sharedBackstage.providers),
  26949. footer: pFooter(pFooterGroup([], [
  26950. footerNo,
  26951. memFooterYes.asSpec()
  26952. ]))
  26953. },
  26954. onCancel: function () {
  26955. return closeDialog(false);
  26956. },
  26957. onSubmit: function () {
  26958. return closeDialog(true);
  26959. },
  26960. extraClasses: ['tox-confirm-dialog']
  26961. }));
  26962. ModalDialog.show(confirmDialog);
  26963. var footerYesButton = memFooterYes.get(confirmDialog);
  26964. Focusing.focus(footerYesButton);
  26965. };
  26966. return { open: open };
  26967. };
  26968. var validateData$1 = function (data, validator) {
  26969. return getOrDie$1(asRaw('data', validator, data));
  26970. };
  26971. var setup$a = function (extras) {
  26972. var alertDialog = setup$8(extras);
  26973. var confirmDialog = setup$9(extras);
  26974. var open = function (config, params, closeWindow) {
  26975. if (params !== undefined && params.inline === 'toolbar') {
  26976. return openInlineDialog(config, extras.backstage.shared.anchors.toolbar(), closeWindow);
  26977. } else if (params !== undefined && params.inline === 'cursor') {
  26978. return openInlineDialog(config, extras.backstage.shared.anchors.cursor(), closeWindow);
  26979. } else {
  26980. return openModalDialog(config, closeWindow);
  26981. }
  26982. };
  26983. var openModalDialog = function (config, closeWindow) {
  26984. var factory = function (contents, internalInitialData, dataValidator) {
  26985. var initialData = internalInitialData;
  26986. var dialogInit = {
  26987. dataValidator: dataValidator,
  26988. initialData: initialData,
  26989. internalDialog: contents
  26990. };
  26991. var dialog = renderDialog(dialogInit, {
  26992. redial: DialogManager.redial,
  26993. closeWindow: function () {
  26994. ModalDialog.hide(dialog.dialog);
  26995. closeWindow(dialog.instanceApi);
  26996. }
  26997. }, extras.backstage);
  26998. ModalDialog.show(dialog.dialog);
  26999. dialog.instanceApi.setData(initialData);
  27000. return dialog.instanceApi;
  27001. };
  27002. return DialogManager.open(factory, config);
  27003. };
  27004. var openInlineDialog = function (config$1, anchor, closeWindow) {
  27005. var factory = function (contents, internalInitialData, dataValidator) {
  27006. var initialData = validateData$1(internalInitialData, dataValidator);
  27007. var dialogInit = {
  27008. dataValidator: dataValidator,
  27009. initialData: initialData,
  27010. internalDialog: contents
  27011. };
  27012. var dialogUi = renderInlineDialog(dialogInit, {
  27013. redial: DialogManager.redial,
  27014. closeWindow: function () {
  27015. InlineView.hide(inlineDialog);
  27016. closeWindow(dialogUi.instanceApi);
  27017. }
  27018. }, extras.backstage);
  27019. var inlineDialog = build$1(InlineView.sketch({
  27020. lazySink: extras.backstage.shared.getSink,
  27021. dom: {
  27022. tag: 'div',
  27023. classes: []
  27024. },
  27025. fireDismissalEventInstead: {},
  27026. inlineBehaviours: derive$1([config('window-manager-inline-events', [run(dismissRequested(), function (comp, se) {
  27027. emit(dialogUi.dialog, formCancelEvent);
  27028. })])])
  27029. }));
  27030. InlineView.showAt(inlineDialog, anchor, premade$1(dialogUi.dialog));
  27031. dialogUi.instanceApi.setData(initialData);
  27032. Keying.focusIn(dialogUi.dialog);
  27033. return dialogUi.instanceApi;
  27034. };
  27035. return DialogManager.open(factory, config$1);
  27036. };
  27037. var confirm = function (message, callback) {
  27038. confirmDialog.open(message, function (state) {
  27039. callback(state);
  27040. });
  27041. };
  27042. var alert = function (message, callback) {
  27043. alertDialog.open(message, function () {
  27044. callback();
  27045. });
  27046. };
  27047. var close = function (instanceApi) {
  27048. instanceApi.close();
  27049. };
  27050. return {
  27051. open: open,
  27052. alert: alert,
  27053. close: close,
  27054. confirm: confirm
  27055. };
  27056. };
  27057. var WindowManager = { setup: setup$a };
  27058. global.add('silver', function (editor) {
  27059. var _a = Render.setup(editor), mothership = _a.mothership, uiMothership = _a.uiMothership, backstage = _a.backstage, renderUI = _a.renderUI, getUi = _a.getUi;
  27060. FormatControls.setup(editor, backstage);
  27061. registerInspector(generate$1('silver-demo'), mothership);
  27062. registerInspector(generate$1('silver-ui-demo'), uiMothership);
  27063. Autocompleter.register(editor, backstage.shared);
  27064. var windowMgr = WindowManager.setup({ backstage: backstage });
  27065. return {
  27066. renderUI: renderUI,
  27067. getWindowManagerImpl: constant(windowMgr),
  27068. getNotificationManagerImpl: function () {
  27069. return NotificationManagerImpl(editor, { backstage: backstage }, uiMothership);
  27070. },
  27071. ui: getUi()
  27072. };
  27073. });
  27074. function Theme () {
  27075. }
  27076. return Theme;
  27077. }(window));
  27078. })();