| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402 |
- /**
- * TinyMCE version 6.1.0 (2022-06-29)
- */
- (function () {
- 'use strict';
- var typeOf$1 = function (x) {
- if (x === null) {
- return 'null';
- }
- if (x === undefined) {
- return 'undefined';
- }
- var t = typeof x;
- if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
- return 'array';
- }
- if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
- return 'string';
- }
- return t;
- };
- var isEquatableType = function (x) {
- return [
- 'undefined',
- 'boolean',
- 'number',
- 'string',
- 'function',
- 'xml',
- 'null'
- ].indexOf(x) !== -1;
- };
- var sort$1 = function (xs, compareFn) {
- var clone = Array.prototype.slice.call(xs);
- return clone.sort(compareFn);
- };
- var contramap = function (eqa, f) {
- return eq$2(function (x, y) {
- return eqa.eq(f(x), f(y));
- });
- };
- var eq$2 = function (f) {
- return { eq: f };
- };
- var tripleEq = eq$2(function (x, y) {
- return x === y;
- });
- var eqString = tripleEq;
- var eqArray = function (eqa) {
- return eq$2(function (x, y) {
- if (x.length !== y.length) {
- return false;
- }
- var len = x.length;
- for (var i = 0; i < len; i++) {
- if (!eqa.eq(x[i], y[i])) {
- return false;
- }
- }
- return true;
- });
- };
- var eqSortedArray = function (eqa, compareFn) {
- return contramap(eqArray(eqa), function (xs) {
- return sort$1(xs, compareFn);
- });
- };
- var eqRecord = function (eqa) {
- return eq$2(function (x, y) {
- var kx = Object.keys(x);
- var ky = Object.keys(y);
- if (!eqSortedArray(eqString).eq(kx, ky)) {
- return false;
- }
- var len = kx.length;
- for (var i = 0; i < len; i++) {
- var q = kx[i];
- if (!eqa.eq(x[q], y[q])) {
- return false;
- }
- }
- return true;
- });
- };
- var eqAny = eq$2(function (x, y) {
- if (x === y) {
- return true;
- }
- var tx = typeOf$1(x);
- var ty = typeOf$1(y);
- if (tx !== ty) {
- return false;
- }
- if (isEquatableType(tx)) {
- return x === y;
- } else if (tx === 'array') {
- return eqArray(eqAny).eq(x, y);
- } else if (tx === 'object') {
- return eqRecord(eqAny).eq(x, y);
- }
- return false;
- });
- const getPrototypeOf$1 = Object.getPrototypeOf;
- const hasProto = (v, constructor, predicate) => {
- var _a;
- if (predicate(v, constructor.prototype)) {
- return true;
- } else {
- return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
- }
- };
- const typeOf = x => {
- const t = typeof x;
- if (x === null) {
- return 'null';
- } else if (t === 'object' && Array.isArray(x)) {
- return 'array';
- } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
- return 'string';
- } else {
- return t;
- }
- };
- const isType$1 = type => value => typeOf(value) === type;
- const isSimpleType = type => value => typeof value === type;
- const eq$1 = t => a => t === a;
- const is$4 = (value, constructor) => isObject(value) && hasProto(value, constructor, (o, proto) => getPrototypeOf$1(o) === proto);
- const isString = isType$1('string');
- const isObject = isType$1('object');
- const isPlainObject = value => is$4(value, Object);
- const isArray$1 = isType$1('array');
- const isNull = eq$1(null);
- const isBoolean = isSimpleType('boolean');
- const isUndefined = eq$1(undefined);
- const isNullable = a => a === null || a === undefined;
- const isNonNullable = a => !isNullable(a);
- const isFunction = isSimpleType('function');
- const isNumber = isSimpleType('number');
- const isArrayOf = (value, pred) => {
- if (isArray$1(value)) {
- for (let i = 0, len = value.length; i < len; ++i) {
- if (!pred(value[i])) {
- return false;
- }
- }
- return true;
- }
- return false;
- };
- const noop = () => {
- };
- const compose = (fa, fb) => {
- return (...args) => {
- return fa(fb.apply(null, args));
- };
- };
- const compose1 = (fbc, fab) => a => fbc(fab(a));
- const constant = value => {
- return () => {
- return value;
- };
- };
- const identity = x => {
- return x;
- };
- const tripleEquals = (a, b) => {
- return a === b;
- };
- function curry(fn, ...initialArgs) {
- return (...restArgs) => {
- const all = initialArgs.concat(restArgs);
- return fn.apply(null, all);
- };
- }
- const not = f => t => !f(t);
- const die = msg => {
- return () => {
- throw new Error(msg);
- };
- };
- const apply$1 = f => {
- return f();
- };
- const call = f => {
- f();
- };
- const never = constant(false);
- const always = constant(true);
- class Optional {
- constructor(tag, value) {
- this.tag = tag;
- this.value = value;
- }
- static some(value) {
- return new Optional(true, value);
- }
- static none() {
- return Optional.singletonNone;
- }
- fold(onNone, onSome) {
- if (this.tag) {
- return onSome(this.value);
- } else {
- return onNone();
- }
- }
- isSome() {
- return this.tag;
- }
- isNone() {
- return !this.tag;
- }
- map(mapper) {
- if (this.tag) {
- return Optional.some(mapper(this.value));
- } else {
- return Optional.none();
- }
- }
- bind(binder) {
- if (this.tag) {
- return binder(this.value);
- } else {
- return Optional.none();
- }
- }
- exists(predicate) {
- return this.tag && predicate(this.value);
- }
- forall(predicate) {
- return !this.tag || predicate(this.value);
- }
- filter(predicate) {
- if (!this.tag || predicate(this.value)) {
- return this;
- } else {
- return Optional.none();
- }
- }
- getOr(replacement) {
- return this.tag ? this.value : replacement;
- }
- or(replacement) {
- return this.tag ? this : replacement;
- }
- getOrThunk(thunk) {
- return this.tag ? this.value : thunk();
- }
- orThunk(thunk) {
- return this.tag ? this : thunk();
- }
- getOrDie(message) {
- if (!this.tag) {
- throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
- } else {
- return this.value;
- }
- }
- static from(value) {
- return isNonNullable(value) ? Optional.some(value) : Optional.none();
- }
- getOrNull() {
- return this.tag ? this.value : null;
- }
- getOrUndefined() {
- return this.value;
- }
- each(worker) {
- if (this.tag) {
- worker(this.value);
- }
- }
- toArray() {
- return this.tag ? [this.value] : [];
- }
- toString() {
- return this.tag ? `some(${ this.value })` : 'none()';
- }
- }
- Optional.singletonNone = new Optional(false);
- const nativeSlice = Array.prototype.slice;
- const nativeIndexOf = Array.prototype.indexOf;
- const nativePush = Array.prototype.push;
- const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t);
- const indexOf$1 = (xs, x) => {
- const r = rawIndexOf(xs, x);
- return r === -1 ? Optional.none() : Optional.some(r);
- };
- const contains$2 = (xs, x) => rawIndexOf(xs, x) > -1;
- const exists = (xs, pred) => {
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- if (pred(x, i)) {
- return true;
- }
- }
- return false;
- };
- const map$3 = (xs, f) => {
- const len = xs.length;
- const r = new Array(len);
- for (let i = 0; i < len; i++) {
- const x = xs[i];
- r[i] = f(x, i);
- }
- return r;
- };
- const each$f = (xs, f) => {
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- f(x, i);
- }
- };
- const eachr = (xs, f) => {
- for (let i = xs.length - 1; i >= 0; i--) {
- const x = xs[i];
- f(x, i);
- }
- };
- const partition$2 = (xs, pred) => {
- const pass = [];
- const fail = [];
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- const arr = pred(x, i) ? pass : fail;
- arr.push(x);
- }
- return {
- pass,
- fail
- };
- };
- const filter$6 = (xs, pred) => {
- const r = [];
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- if (pred(x, i)) {
- r.push(x);
- }
- }
- return r;
- };
- const foldr = (xs, f, acc) => {
- eachr(xs, (x, i) => {
- acc = f(acc, x, i);
- });
- return acc;
- };
- const foldl = (xs, f, acc) => {
- each$f(xs, (x, i) => {
- acc = f(acc, x, i);
- });
- return acc;
- };
- const findUntil$1 = (xs, pred, until) => {
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- if (pred(x, i)) {
- return Optional.some(x);
- } else if (until(x, i)) {
- break;
- }
- }
- return Optional.none();
- };
- const find$2 = (xs, pred) => {
- return findUntil$1(xs, pred, never);
- };
- const findIndex$2 = (xs, pred) => {
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- if (pred(x, i)) {
- return Optional.some(i);
- }
- }
- return Optional.none();
- };
- const flatten = xs => {
- const r = [];
- for (let i = 0, len = xs.length; i < len; ++i) {
- if (!isArray$1(xs[i])) {
- throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- const bind$3 = (xs, f) => flatten(map$3(xs, f));
- const forall = (xs, pred) => {
- for (let i = 0, len = xs.length; i < len; ++i) {
- const x = xs[i];
- if (pred(x, i) !== true) {
- return false;
- }
- }
- return true;
- };
- const reverse = xs => {
- const r = nativeSlice.call(xs, 0);
- r.reverse();
- return r;
- };
- const difference = (a1, a2) => filter$6(a1, x => !contains$2(a2, x));
- const mapToObject = (xs, f) => {
- const r = {};
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- r[String(x)] = f(x, i);
- }
- return r;
- };
- const sort = (xs, comparator) => {
- const copy = nativeSlice.call(xs, 0);
- copy.sort(comparator);
- return copy;
- };
- const get$b = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
- const head = xs => get$b(xs, 0);
- const last$3 = xs => get$b(xs, xs.length - 1);
- const from = isFunction(Array.from) ? Array.from : x => nativeSlice.call(x);
- const findMap = (arr, f) => {
- for (let i = 0; i < arr.length; i++) {
- const r = f(arr[i], i);
- if (r.isSome()) {
- return r;
- }
- }
- return Optional.none();
- };
- const unique$1 = (xs, comparator) => {
- const r = [];
- const isDuplicated = isFunction(comparator) ? x => exists(r, i => comparator(i, x)) : x => contains$2(r, x);
- for (let i = 0, len = xs.length; i < len; i++) {
- const x = xs[i];
- if (!isDuplicated(x)) {
- r.push(x);
- }
- }
- return r;
- };
- const keys = Object.keys;
- const hasOwnProperty$2 = Object.hasOwnProperty;
- const each$e = (obj, f) => {
- const props = keys(obj);
- for (let k = 0, len = props.length; k < len; k++) {
- const i = props[k];
- const x = obj[i];
- f(x, i);
- }
- };
- const map$2 = (obj, f) => {
- return tupleMap(obj, (x, i) => ({
- k: i,
- v: f(x, i)
- }));
- };
- const tupleMap = (obj, f) => {
- const r = {};
- each$e(obj, (x, i) => {
- const tuple = f(x, i);
- r[tuple.k] = tuple.v;
- });
- return r;
- };
- const objAcc = r => (x, i) => {
- r[i] = x;
- };
- const internalFilter = (obj, pred, onTrue, onFalse) => {
- const r = {};
- each$e(obj, (x, i) => {
- (pred(x, i) ? onTrue : onFalse)(x, i);
- });
- return r;
- };
- const bifilter = (obj, pred) => {
- const t = {};
- const f = {};
- internalFilter(obj, pred, objAcc(t), objAcc(f));
- return {
- t,
- f
- };
- };
- const filter$5 = (obj, pred) => {
- const t = {};
- internalFilter(obj, pred, objAcc(t), noop);
- return t;
- };
- const mapToArray = (obj, f) => {
- const r = [];
- each$e(obj, (value, name) => {
- r.push(f(value, name));
- });
- return r;
- };
- const values = obj => {
- return mapToArray(obj, identity);
- };
- const get$a = (obj, key) => {
- return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none();
- };
- const has$2 = (obj, key) => hasOwnProperty$2.call(obj, key);
- const hasNonNullableKey = (obj, key) => has$2(obj, key) && obj[key] !== undefined && obj[key] !== null;
- const equal$1 = (a1, a2, eq = eqAny) => eqRecord(eq).eq(a1, a2);
- const stringArray = a => {
- const all = {};
- each$f(a, key => {
- all[key] = {};
- });
- return keys(all);
- };
- const isArray = Array.isArray;
- const toArray$1 = obj => {
- if (!isArray(obj)) {
- const array = [];
- for (let i = 0, l = obj.length; i < l; i++) {
- array[i] = obj[i];
- }
- return array;
- } else {
- return obj;
- }
- };
- const each$d = (o, cb, s) => {
- let n, l;
- if (!o) {
- return false;
- }
- s = s || o;
- if (o.length !== undefined) {
- for (n = 0, l = o.length; n < l; n++) {
- if (cb.call(s, o[n], n, o) === false) {
- return false;
- }
- }
- } else {
- for (n in o) {
- if (has$2(o, n)) {
- if (cb.call(s, o[n], n, o) === false) {
- return false;
- }
- }
- }
- }
- return true;
- };
- const map$1 = (array, callback) => {
- const out = [];
- each$d(array, (item, index) => {
- out.push(callback(item, index, array));
- });
- return out;
- };
- const filter$4 = (a, f) => {
- const o = [];
- each$d(a, (v, index) => {
- if (!f || f(v, index, a)) {
- o.push(v);
- }
- });
- return o;
- };
- const indexOf = (a, v) => {
- if (a) {
- for (let i = 0, l = a.length; i < l; i++) {
- if (a[i] === v) {
- return i;
- }
- }
- }
- return -1;
- };
- const reduce = (collection, iteratee, accumulator, thisArg) => {
- let acc = isUndefined(accumulator) ? collection[0] : accumulator;
- for (let i = 0; i < collection.length; i++) {
- acc = iteratee.call(thisArg, acc, collection[i], i);
- }
- return acc;
- };
- const findIndex$1 = (array, predicate, thisArg) => {
- let i, l;
- for (i = 0, l = array.length; i < l; i++) {
- if (predicate.call(thisArg, array[i], i, array)) {
- return i;
- }
- }
- return -1;
- };
- const last$2 = collection => collection[collection.length - 1];
- const cached = f => {
- let called = false;
- let r;
- return (...args) => {
- if (!called) {
- called = true;
- r = f.apply(null, args);
- }
- return r;
- };
- };
- const DeviceType = (os, browser, userAgent, mediaMatch) => {
- const isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
- const isiPhone = os.isiOS() && !isiPad;
- const isMobile = os.isiOS() || os.isAndroid();
- const isTouch = isMobile || mediaMatch('(pointer:coarse)');
- const isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
- const isPhone = isiPhone || isMobile && !isTablet;
- const iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
- const isDesktop = !isPhone && !isTablet && !iOSwebview;
- return {
- isiPad: constant(isiPad),
- isiPhone: constant(isiPhone),
- isTablet: constant(isTablet),
- isPhone: constant(isPhone),
- isTouch: constant(isTouch),
- isAndroid: os.isAndroid,
- isiOS: os.isiOS,
- isWebView: constant(iOSwebview),
- isDesktop: constant(isDesktop)
- };
- };
- const firstMatch = (regexes, s) => {
- for (let i = 0; i < regexes.length; i++) {
- const x = regexes[i];
- if (x.test(s)) {
- return x;
- }
- }
- return undefined;
- };
- const find$1 = (regexes, agent) => {
- const r = firstMatch(regexes, agent);
- if (!r) {
- return {
- major: 0,
- minor: 0
- };
- }
- const group = i => {
- return Number(agent.replace(r, '$' + i));
- };
- return nu$3(group(1), group(2));
- };
- const detect$5 = (versionRegexes, agent) => {
- const cleanedAgent = String(agent).toLowerCase();
- if (versionRegexes.length === 0) {
- return unknown$2();
- }
- return find$1(versionRegexes, cleanedAgent);
- };
- const unknown$2 = () => {
- return nu$3(0, 0);
- };
- const nu$3 = (major, minor) => {
- return {
- major,
- minor
- };
- };
- const Version = {
- nu: nu$3,
- detect: detect$5,
- unknown: unknown$2
- };
- const detectBrowser$1 = (browsers, userAgentData) => {
- return findMap(userAgentData.brands, uaBrand => {
- const lcBrand = uaBrand.brand.toLowerCase();
- return find$2(browsers, browser => {
- var _a;
- return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase());
- }).map(info => ({
- current: info.name,
- version: Version.nu(parseInt(uaBrand.version, 10), 0)
- }));
- });
- };
- const detect$4 = (candidates, userAgent) => {
- const agent = String(userAgent).toLowerCase();
- return find$2(candidates, candidate => {
- return candidate.search(agent);
- });
- };
- const detectBrowser = (browsers, userAgent) => {
- return detect$4(browsers, userAgent).map(browser => {
- const version = Version.detect(browser.versionRegexes, userAgent);
- return {
- current: browser.name,
- version
- };
- });
- };
- const detectOs = (oses, userAgent) => {
- return detect$4(oses, userAgent).map(os => {
- const version = Version.detect(os.versionRegexes, userAgent);
- return {
- current: os.name,
- version
- };
- });
- };
- const removeFromStart = (str, numChars) => {
- return str.substring(numChars);
- };
- const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
- const removeLeading = (str, prefix) => {
- return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;
- };
- const contains$1 = (str, substr) => {
- return str.indexOf(substr) !== -1;
- };
- const startsWith = (str, prefix) => {
- return checkRange(str, prefix, 0);
- };
- const endsWith = (str, suffix) => {
- return checkRange(str, suffix, str.length - suffix.length);
- };
- const blank = r => s => s.replace(r, '');
- const trim$3 = blank(/^\s+|\s+$/g);
- const lTrim = blank(/^\s+/g);
- const rTrim = blank(/\s+$/g);
- const isNotEmpty = s => s.length > 0;
- const isEmpty$3 = s => !isNotEmpty(s);
- const repeat = (s, count) => count <= 0 ? '' : new Array(count + 1).join(s);
- const toInt = (value, radix = 10) => {
- const num = parseInt(value, radix);
- return isNaN(num) ? Optional.none() : Optional.some(num);
- };
- const normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
- const checkContains = target => {
- return uastring => {
- return contains$1(uastring, target);
- };
- };
- const browsers = [
- {
- name: 'Edge',
- versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
- search: uastring => {
- return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
- }
- },
- {
- name: 'Chromium',
- brand: 'Chromium',
- versionRegexes: [
- /.*?chrome\/([0-9]+)\.([0-9]+).*/,
- normalVersionRegex
- ],
- search: uastring => {
- return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
- }
- },
- {
- name: 'IE',
- versionRegexes: [
- /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
- /.*?rv:([0-9]+)\.([0-9]+).*/
- ],
- search: uastring => {
- return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
- }
- },
- {
- name: 'Opera',
- versionRegexes: [
- normalVersionRegex,
- /.*?opera\/([0-9]+)\.([0-9]+).*/
- ],
- search: checkContains('opera')
- },
- {
- name: 'Firefox',
- versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
- search: checkContains('firefox')
- },
- {
- name: 'Safari',
- versionRegexes: [
- normalVersionRegex,
- /.*?cpu os ([0-9]+)_([0-9]+).*/
- ],
- search: uastring => {
- return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
- }
- }
- ];
- const oses = [
- {
- name: 'Windows',
- search: checkContains('win'),
- versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'iOS',
- search: uastring => {
- return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
- },
- versionRegexes: [
- /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
- /.*cpu os ([0-9]+)_([0-9]+).*/,
- /.*cpu iphone os ([0-9]+)_([0-9]+).*/
- ]
- },
- {
- name: 'Android',
- search: checkContains('android'),
- versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'macOS',
- search: checkContains('mac os x'),
- versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
- },
- {
- name: 'Linux',
- search: checkContains('linux'),
- versionRegexes: []
- },
- {
- name: 'Solaris',
- search: checkContains('sunos'),
- versionRegexes: []
- },
- {
- name: 'FreeBSD',
- search: checkContains('freebsd'),
- versionRegexes: []
- },
- {
- name: 'ChromeOS',
- search: checkContains('cros'),
- versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
- }
- ];
- const PlatformInfo = {
- browsers: constant(browsers),
- oses: constant(oses)
- };
- const edge = 'Edge';
- const chromium = 'Chromium';
- const ie = 'IE';
- const opera = 'Opera';
- const firefox = 'Firefox';
- const safari = 'Safari';
- const unknown$1 = () => {
- return nu$2({
- current: undefined,
- version: Version.unknown()
- });
- };
- const nu$2 = info => {
- const current = info.current;
- const version = info.version;
- const isBrowser = name => () => current === name;
- return {
- current,
- version,
- isEdge: isBrowser(edge),
- isChromium: isBrowser(chromium),
- isIE: isBrowser(ie),
- isOpera: isBrowser(opera),
- isFirefox: isBrowser(firefox),
- isSafari: isBrowser(safari)
- };
- };
- const Browser = {
- unknown: unknown$1,
- nu: nu$2,
- edge: constant(edge),
- chromium: constant(chromium),
- ie: constant(ie),
- opera: constant(opera),
- firefox: constant(firefox),
- safari: constant(safari)
- };
- const windows = 'Windows';
- const ios = 'iOS';
- const android = 'Android';
- const linux = 'Linux';
- const macos = 'macOS';
- const solaris = 'Solaris';
- const freebsd = 'FreeBSD';
- const chromeos = 'ChromeOS';
- const unknown = () => {
- return nu$1({
- current: undefined,
- version: Version.unknown()
- });
- };
- const nu$1 = info => {
- const current = info.current;
- const version = info.version;
- const isOS = name => () => current === name;
- return {
- current,
- version,
- isWindows: isOS(windows),
- isiOS: isOS(ios),
- isAndroid: isOS(android),
- isMacOS: isOS(macos),
- isLinux: isOS(linux),
- isSolaris: isOS(solaris),
- isFreeBSD: isOS(freebsd),
- isChromeOS: isOS(chromeos)
- };
- };
- const OperatingSystem = {
- unknown,
- nu: nu$1,
- windows: constant(windows),
- ios: constant(ios),
- android: constant(android),
- linux: constant(linux),
- macos: constant(macos),
- solaris: constant(solaris),
- freebsd: constant(freebsd),
- chromeos: constant(chromeos)
- };
- const detect$3 = (userAgent, userAgentDataOpt, mediaMatch) => {
- const browsers = PlatformInfo.browsers();
- const oses = PlatformInfo.oses();
- const browser = userAgentDataOpt.bind(userAgentData => detectBrowser$1(browsers, userAgentData)).orThunk(() => detectBrowser(browsers, userAgent)).fold(Browser.unknown, Browser.nu);
- const os = detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
- const deviceType = DeviceType(os, browser, userAgent, mediaMatch);
- return {
- browser,
- os,
- deviceType
- };
- };
- const PlatformDetection = { detect: detect$3 };
- const mediaMatch = query => window.matchMedia(query).matches;
- let platform$2 = cached(() => PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch));
- const detect$2 = () => platform$2();
- const userAgent = navigator.userAgent;
- const platform$1 = detect$2();
- const browser$1 = platform$1.browser;
- const os = platform$1.os;
- const deviceType = platform$1.deviceType;
- const windowsPhone = userAgent.indexOf('Windows Phone') !== -1;
- const Env = {
- transparentSrc: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
- documentMode: browser$1.isIE() ? document.documentMode || 7 : 10,
- cacheSuffix: null,
- container: null,
- canHaveCSP: !browser$1.isIE(),
- windowsPhone,
- browser: {
- current: browser$1.current,
- version: browser$1.version,
- isChromium: browser$1.isChromium,
- isEdge: browser$1.isEdge,
- isFirefox: browser$1.isFirefox,
- isIE: browser$1.isIE,
- isOpera: browser$1.isOpera,
- isSafari: browser$1.isSafari
- },
- os: {
- current: os.current,
- version: os.version,
- isAndroid: os.isAndroid,
- isChromeOS: os.isChromeOS,
- isFreeBSD: os.isFreeBSD,
- isiOS: os.isiOS,
- isLinux: os.isLinux,
- isMacOS: os.isMacOS,
- isSolaris: os.isSolaris,
- isWindows: os.isWindows
- },
- deviceType: {
- isDesktop: deviceType.isDesktop,
- isiPad: deviceType.isiPad,
- isiPhone: deviceType.isiPhone,
- isPhone: deviceType.isPhone,
- isTablet: deviceType.isTablet,
- isTouch: deviceType.isTouch,
- isWebView: deviceType.isWebView
- }
- };
- const whiteSpaceRegExp$1 = /^\s*|\s*$/g;
- const trim$2 = str => {
- return str === null || str === undefined ? '' : ('' + str).replace(whiteSpaceRegExp$1, '');
- };
- const is$3 = (obj, type) => {
- if (!type) {
- return obj !== undefined;
- }
- if (type === 'array' && isArray(obj)) {
- return true;
- }
- return typeof obj === type;
- };
- const makeMap$4 = (items, delim, map) => {
- let i;
- items = items || [];
- delim = delim || ',';
- if (typeof items === 'string') {
- items = items.split(delim);
- }
- map = map || {};
- i = items.length;
- while (i--) {
- map[items[i]] = {};
- }
- return map;
- };
- const hasOwnProperty$1 = has$2;
- const extend$3 = (obj, ...exts) => {
- for (let i = 0; i < exts.length; i++) {
- const ext = exts[i];
- for (const name in ext) {
- if (has$2(ext, name)) {
- const value = ext[name];
- if (value !== undefined) {
- obj[name] = value;
- }
- }
- }
- }
- return obj;
- };
- const walk$4 = function (o, f, n, s) {
- s = s || this;
- if (o) {
- if (n) {
- o = o[n];
- }
- each$d(o, (o, i) => {
- if (f.call(s, o, i, n) === false) {
- return false;
- }
- walk$4(o, f, n, s);
- });
- }
- };
- const resolve$2 = (n, o) => {
- let i, l;
- o = o || window;
- n = n.split('.');
- for (i = 0, l = n.length; i < l; i++) {
- o = o[n[i]];
- if (!o) {
- break;
- }
- }
- return o;
- };
- const explode$3 = (s, d) => {
- if (!s || is$3(s, 'array')) {
- return s;
- }
- return map$1(s.split(d || ','), trim$2);
- };
- const _addCacheSuffix = url => {
- const cacheSuffix = Env.cacheSuffix;
- if (cacheSuffix) {
- url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix;
- }
- return url;
- };
- const Tools = {
- trim: trim$2,
- isArray: isArray,
- is: is$3,
- toArray: toArray$1,
- makeMap: makeMap$4,
- each: each$d,
- map: map$1,
- grep: filter$4,
- inArray: indexOf,
- hasOwn: hasOwnProperty$1,
- extend: extend$3,
- walk: walk$4,
- resolve: resolve$2,
- explode: explode$3,
- _addCacheSuffix
- };
- const is$2 = (lhs, rhs, comparator = tripleEquals) => lhs.exists(left => comparator(left, rhs));
- const cat = arr => {
- const r = [];
- const push = x => {
- r.push(x);
- };
- for (let i = 0; i < arr.length; i++) {
- arr[i].each(push);
- }
- return r;
- };
- const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
- const lift3 = (oa, ob, oc, f) => oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none();
- const someIf = (b, a) => b ? Optional.some(a) : Optional.none();
- typeof window !== 'undefined' ? window : Function('return this;')();
- const COMMENT = 8;
- const DOCUMENT = 9;
- const DOCUMENT_FRAGMENT = 11;
- const ELEMENT = 1;
- const TEXT = 3;
- const name = element => {
- const r = element.dom.nodeName;
- return r.toLowerCase();
- };
- const type$1 = element => element.dom.nodeType;
- const isType = t => element => type$1(element) === t;
- const isComment$1 = element => type$1(element) === COMMENT || name(element) === '#comment';
- const isElement$7 = isType(ELEMENT);
- const isText$a = isType(TEXT);
- const isDocument$2 = isType(DOCUMENT);
- const isDocumentFragment$1 = isType(DOCUMENT_FRAGMENT);
- const isTag = tag => e => isElement$7(e) && name(e) === tag;
- const rawSet = (dom, key, value) => {
- if (isString(value) || isBoolean(value) || isNumber(value)) {
- dom.setAttribute(key, value + '');
- } else {
- console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
- throw new Error('Attribute value was not simple');
- }
- };
- const set$2 = (element, key, value) => {
- rawSet(element.dom, key, value);
- };
- const setAll$1 = (element, attrs) => {
- const dom = element.dom;
- each$e(attrs, (v, k) => {
- rawSet(dom, k, v);
- });
- };
- const get$9 = (element, key) => {
- const v = element.dom.getAttribute(key);
- return v === null ? undefined : v;
- };
- const getOpt = (element, key) => Optional.from(get$9(element, key));
- const has$1 = (element, key) => {
- const dom = element.dom;
- return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
- };
- const remove$b = (element, key) => {
- element.dom.removeAttribute(key);
- };
- const hasNone = element => {
- const attrs = element.dom.attributes;
- return attrs === undefined || attrs === null || attrs.length === 0;
- };
- const clone$4 = element => foldl(element.dom.attributes, (acc, attr) => {
- acc[attr.name] = attr.value;
- return acc;
- }, {});
- const read$4 = (element, attr) => {
- const value = get$9(element, attr);
- return value === undefined || value === '' ? [] : value.split(' ');
- };
- const add$4 = (element, attr, id) => {
- const old = read$4(element, attr);
- const nu = old.concat([id]);
- set$2(element, attr, nu.join(' '));
- return true;
- };
- const remove$a = (element, attr, id) => {
- const nu = filter$6(read$4(element, attr), v => v !== id);
- if (nu.length > 0) {
- set$2(element, attr, nu.join(' '));
- } else {
- remove$b(element, attr);
- }
- return false;
- };
- const supports = element => element.dom.classList !== undefined;
- const get$8 = element => read$4(element, 'class');
- const add$3 = (element, clazz) => add$4(element, 'class', clazz);
- const remove$9 = (element, clazz) => remove$a(element, 'class', clazz);
- const toggle$2 = (element, clazz) => {
- if (contains$2(get$8(element), clazz)) {
- return remove$9(element, clazz);
- } else {
- return add$3(element, clazz);
- }
- };
- const add$2 = (element, clazz) => {
- if (supports(element)) {
- element.dom.classList.add(clazz);
- } else {
- add$3(element, clazz);
- }
- };
- const cleanClass = element => {
- const classList = supports(element) ? element.dom.classList : get$8(element);
- if (classList.length === 0) {
- remove$b(element, 'class');
- }
- };
- const remove$8 = (element, clazz) => {
- if (supports(element)) {
- const classList = element.dom.classList;
- classList.remove(clazz);
- } else {
- remove$9(element, clazz);
- }
- cleanClass(element);
- };
- const toggle$1 = (element, clazz) => {
- const result = supports(element) ? element.dom.classList.toggle(clazz) : toggle$2(element, clazz);
- cleanClass(element);
- return result;
- };
- const has = (element, clazz) => supports(element) && element.dom.classList.contains(clazz);
- const isSupported$1 = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);
- const fromHtml$1 = (html, scope) => {
- const doc = scope || document;
- const div = doc.createElement('div');
- div.innerHTML = html;
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
- const message = 'HTML does not have a single root node';
- console.error(message, html);
- throw new Error(message);
- }
- return fromDom$2(div.childNodes[0]);
- };
- const fromTag = (tag, scope) => {
- const doc = scope || document;
- const node = doc.createElement(tag);
- return fromDom$2(node);
- };
- const fromText = (text, scope) => {
- const doc = scope || document;
- const node = doc.createTextNode(text);
- return fromDom$2(node);
- };
- const fromDom$2 = node => {
- if (node === null || node === undefined) {
- throw new Error('Node cannot be null or undefined');
- }
- return { dom: node };
- };
- const fromPoint$2 = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$2);
- const SugarElement = {
- fromHtml: fromHtml$1,
- fromTag,
- fromText,
- fromDom: fromDom$2,
- fromPoint: fromPoint$2
- };
- const toArray = (target, f) => {
- const r = [];
- const recurse = e => {
- r.push(e);
- return f(e);
- };
- let cur = f(target);
- do {
- cur = cur.bind(recurse);
- } while (cur.isSome());
- return r;
- };
- const is$1 = (element, selector) => {
- const dom = element.dom;
- if (dom.nodeType !== ELEMENT) {
- return false;
- } else {
- const elem = dom;
- if (elem.matches !== undefined) {
- return elem.matches(selector);
- } else if (elem.msMatchesSelector !== undefined) {
- return elem.msMatchesSelector(selector);
- } else if (elem.webkitMatchesSelector !== undefined) {
- return elem.webkitMatchesSelector(selector);
- } else if (elem.mozMatchesSelector !== undefined) {
- return elem.mozMatchesSelector(selector);
- } else {
- throw new Error('Browser lacks native selectors');
- }
- }
- };
- const bypassSelector = dom => dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0;
- const all = (selector, scope) => {
- const base = scope === undefined ? document : scope.dom;
- return bypassSelector(base) ? [] : map$3(base.querySelectorAll(selector), SugarElement.fromDom);
- };
- const one = (selector, scope) => {
- const base = scope === undefined ? document : scope.dom;
- return bypassSelector(base) ? Optional.none() : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom);
- };
- const eq = (e1, e2) => e1.dom === e2.dom;
- const contains = (e1, e2) => {
- const d1 = e1.dom;
- const d2 = e2.dom;
- return d1 === d2 ? false : d1.contains(d2);
- };
- const owner$1 = element => SugarElement.fromDom(element.dom.ownerDocument);
- const documentOrOwner = dos => isDocument$2(dos) ? dos : owner$1(dos);
- const documentElement = element => SugarElement.fromDom(documentOrOwner(element).dom.documentElement);
- const defaultView = element => SugarElement.fromDom(documentOrOwner(element).dom.defaultView);
- const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
- const parentElement = element => Optional.from(element.dom.parentElement).map(SugarElement.fromDom);
- const parents$1 = (element, isRoot) => {
- const stop = isFunction(isRoot) ? isRoot : never;
- let dom = element.dom;
- const ret = [];
- while (dom.parentNode !== null && dom.parentNode !== undefined) {
- const rawParent = dom.parentNode;
- const p = SugarElement.fromDom(rawParent);
- ret.push(p);
- if (stop(p) === true) {
- break;
- } else {
- dom = rawParent;
- }
- }
- return ret;
- };
- const siblings = element => {
- const filterSelf = elements => filter$6(elements, x => !eq(element, x));
- return parent(element).map(children).map(filterSelf).getOr([]);
- };
- const prevSibling = element => Optional.from(element.dom.previousSibling).map(SugarElement.fromDom);
- const nextSibling = element => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);
- const prevSiblings = element => reverse(toArray(element, prevSibling));
- const nextSiblings = element => toArray(element, nextSibling);
- const children = element => map$3(element.dom.childNodes, SugarElement.fromDom);
- const child$1 = (element, index) => {
- const cs = element.dom.childNodes;
- return Optional.from(cs[index]).map(SugarElement.fromDom);
- };
- const firstChild = element => child$1(element, 0);
- const lastChild = element => child$1(element, element.dom.childNodes.length - 1);
- const childNodesCount = element => element.dom.childNodes.length;
- const getHead = doc => {
- const b = doc.dom.head;
- if (b === null || b === undefined) {
- throw new Error('Head is not available yet');
- }
- return SugarElement.fromDom(b);
- };
- const isShadowRoot = dos => isDocumentFragment$1(dos) && isNonNullable(dos.dom.host);
- const supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
- const isSupported = constant(supported);
- const getRootNode = supported ? e => SugarElement.fromDom(e.dom.getRootNode()) : documentOrOwner;
- const getStyleContainer = dos => isShadowRoot(dos) ? dos : getHead(documentOrOwner(dos));
- const getShadowRoot = e => {
- const r = getRootNode(e);
- return isShadowRoot(r) ? Optional.some(r) : Optional.none();
- };
- const getShadowHost = e => SugarElement.fromDom(e.dom.host);
- const getOriginalEventTarget = event => {
- if (isSupported() && isNonNullable(event.target)) {
- const el = SugarElement.fromDom(event.target);
- if (isElement$7(el) && isOpenShadowHost(el)) {
- if (event.composed && event.composedPath) {
- const composedPath = event.composedPath();
- if (composedPath) {
- return head(composedPath);
- }
- }
- }
- }
- return Optional.from(event.target);
- };
- const isOpenShadowHost = element => isNonNullable(element.dom.shadowRoot);
- const inBody = element => {
- const dom = isText$a(element) ? element.dom.parentNode : element.dom;
- if (dom === undefined || dom === null || dom.ownerDocument === null) {
- return false;
- }
- const doc = dom.ownerDocument;
- return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));
- };
- const internalSet = (dom, property, value) => {
- if (!isString(value)) {
- console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
- throw new Error('CSS value must be a string: ' + value);
- }
- if (isSupported$1(dom)) {
- dom.style.setProperty(property, value);
- }
- };
- const internalRemove = (dom, property) => {
- if (isSupported$1(dom)) {
- dom.style.removeProperty(property);
- }
- };
- const set$1 = (element, property, value) => {
- const dom = element.dom;
- internalSet(dom, property, value);
- };
- const setAll = (element, css) => {
- const dom = element.dom;
- each$e(css, (v, k) => {
- internalSet(dom, k, v);
- });
- };
- const get$7 = (element, property) => {
- const dom = element.dom;
- const styles = window.getComputedStyle(dom);
- const r = styles.getPropertyValue(property);
- return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
- };
- const getUnsafeProperty = (dom, property) => isSupported$1(dom) ? dom.style.getPropertyValue(property) : '';
- const getRaw$1 = (element, property) => {
- const dom = element.dom;
- const raw = getUnsafeProperty(dom, property);
- return Optional.from(raw).filter(r => r.length > 0);
- };
- const getAllRaw = element => {
- const css = {};
- const dom = element.dom;
- if (isSupported$1(dom)) {
- for (let i = 0; i < dom.style.length; i++) {
- const ruleName = dom.style.item(i);
- css[ruleName] = dom.style[ruleName];
- }
- }
- return css;
- };
- const remove$7 = (element, property) => {
- const dom = element.dom;
- internalRemove(dom, property);
- if (is$2(getOpt(element, 'style').map(trim$3), '')) {
- remove$b(element, 'style');
- }
- };
- const reflow = e => e.dom.offsetWidth;
- const before$3 = (marker, element) => {
- const parent$1 = parent(marker);
- parent$1.each(v => {
- v.dom.insertBefore(element.dom, marker.dom);
- });
- };
- const after$4 = (marker, element) => {
- const sibling = nextSibling(marker);
- sibling.fold(() => {
- const parent$1 = parent(marker);
- parent$1.each(v => {
- append$1(v, element);
- });
- }, v => {
- before$3(v, element);
- });
- };
- const prepend = (parent, element) => {
- const firstChild$1 = firstChild(parent);
- firstChild$1.fold(() => {
- append$1(parent, element);
- }, v => {
- parent.dom.insertBefore(element.dom, v.dom);
- });
- };
- const append$1 = (parent, element) => {
- parent.dom.appendChild(element.dom);
- };
- const wrap$2 = (element, wrapper) => {
- before$3(element, wrapper);
- append$1(wrapper, element);
- };
- const after$3 = (marker, elements) => {
- each$f(elements, (x, i) => {
- const e = i === 0 ? marker : elements[i - 1];
- after$4(e, x);
- });
- };
- const append = (parent, elements) => {
- each$f(elements, x => {
- append$1(parent, x);
- });
- };
- const empty = element => {
- element.dom.textContent = '';
- each$f(children(element), rogue => {
- remove$6(rogue);
- });
- };
- const remove$6 = element => {
- const dom = element.dom;
- if (dom.parentNode !== null) {
- dom.parentNode.removeChild(dom);
- }
- };
- const unwrap = wrapper => {
- const children$1 = children(wrapper);
- if (children$1.length > 0) {
- after$3(wrapper, children$1);
- }
- remove$6(wrapper);
- };
- const fromHtml = (html, scope) => {
- const doc = scope || document;
- const div = doc.createElement('div');
- div.innerHTML = html;
- return children(SugarElement.fromDom(div));
- };
- const fromDom$1 = nodes => map$3(nodes, SugarElement.fromDom);
- const get$6 = element => element.dom.innerHTML;
- const set = (element, content) => {
- const owner = owner$1(element);
- const docDom = owner.dom;
- const fragment = SugarElement.fromDom(docDom.createDocumentFragment());
- const contentElements = fromHtml(content, docDom);
- append(fragment, contentElements);
- empty(element);
- append$1(element, fragment);
- };
- const getOuter = element => {
- const container = SugarElement.fromTag('div');
- const clone = SugarElement.fromDom(element.dom.cloneNode(true));
- append$1(container, clone);
- return get$6(container);
- };
- const mkEvent = (target, x, y, stop, prevent, kill, raw) => ({
- target,
- x,
- y,
- stop,
- prevent,
- kill,
- raw
- });
- const fromRawEvent = rawEvent => {
- const target = SugarElement.fromDom(getOriginalEventTarget(rawEvent).getOr(rawEvent.target));
- const stop = () => rawEvent.stopPropagation();
- const prevent = () => rawEvent.preventDefault();
- const kill = compose(prevent, stop);
- return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
- };
- const handle$1 = (filter, handler) => rawEvent => {
- if (filter(rawEvent)) {
- handler(fromRawEvent(rawEvent));
- }
- };
- const binder = (element, event, filter, handler, useCapture) => {
- const wrapped = handle$1(filter, handler);
- element.dom.addEventListener(event, wrapped, useCapture);
- return { unbind: curry(unbind, element, event, wrapped, useCapture) };
- };
- const bind$2 = (element, event, filter, handler) => binder(element, event, filter, handler, false);
- const unbind = (element, event, handler, useCapture) => {
- element.dom.removeEventListener(event, handler, useCapture);
- };
- const r = (left, top) => {
- const translate = (x, y) => r(left + x, top + y);
- return {
- left,
- top,
- translate
- };
- };
- const SugarPosition = r;
- const boxPosition = dom => {
- const box = dom.getBoundingClientRect();
- return SugarPosition(box.left, box.top);
- };
- const firstDefinedOrZero = (a, b) => {
- if (a !== undefined) {
- return a;
- } else {
- return b !== undefined ? b : 0;
- }
- };
- const absolute = element => {
- const doc = element.dom.ownerDocument;
- const body = doc.body;
- const win = doc.defaultView;
- const html = doc.documentElement;
- if (body === element.dom) {
- return SugarPosition(body.offsetLeft, body.offsetTop);
- }
- const scrollTop = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageYOffset, html.scrollTop);
- const scrollLeft = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageXOffset, html.scrollLeft);
- const clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
- const clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
- return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
- };
- const viewport = element => {
- const dom = element.dom;
- const doc = dom.ownerDocument;
- const body = doc.body;
- if (body === dom) {
- return SugarPosition(body.offsetLeft, body.offsetTop);
- }
- if (!inBody(element)) {
- return SugarPosition(0, 0);
- }
- return boxPosition(dom);
- };
- const get$5 = _DOC => {
- const doc = _DOC !== undefined ? _DOC.dom : document;
- const x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
- const y = doc.body.scrollTop || doc.documentElement.scrollTop;
- return SugarPosition(x, y);
- };
- const to = (x, y, _DOC) => {
- const doc = _DOC !== undefined ? _DOC.dom : document;
- const win = doc.defaultView;
- if (win) {
- win.scrollTo(x, y);
- }
- };
- const intoView = (element, alignToTop) => {
- const isSafari = detect$2().browser.isSafari();
- if (isSafari && isFunction(element.dom.scrollIntoViewIfNeeded)) {
- element.dom.scrollIntoViewIfNeeded(false);
- } else {
- element.dom.scrollIntoView(alignToTop);
- }
- };
- const get$4 = _win => {
- const win = _win === undefined ? window : _win;
- if (detect$2().browser.isFirefox()) {
- return Optional.none();
- } else {
- return Optional.from(win.visualViewport);
- }
- };
- const bounds = (x, y, width, height) => ({
- x,
- y,
- width,
- height,
- right: x + width,
- bottom: y + height
- });
- const getBounds = _win => {
- const win = _win === undefined ? window : _win;
- const doc = win.document;
- const scroll = get$5(SugarElement.fromDom(doc));
- return get$4(win).fold(() => {
- const html = win.document.documentElement;
- const width = html.clientWidth;
- const height = html.clientHeight;
- return bounds(scroll.left, scroll.top, width, height);
- }, visualViewport => bounds(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height));
- };
- const isNodeType = type => {
- return node => {
- return !!node && node.nodeType === type;
- };
- };
- const isRestrictedNode = node => !!node && !Object.getPrototypeOf(node);
- const isElement$6 = isNodeType(1);
- const matchNodeNames = names => {
- const lowercasedNames = names.map(s => s.toLowerCase());
- return node => {
- if (node && node.nodeName) {
- const nodeName = node.nodeName.toLowerCase();
- return contains$2(lowercasedNames, nodeName);
- }
- return false;
- };
- };
- const matchStyleValues = (name, values) => {
- const items = values.toLowerCase().split(' ');
- return node => {
- if (isElement$6(node)) {
- for (let i = 0; i < items.length; i++) {
- const computed = node.ownerDocument.defaultView.getComputedStyle(node, null);
- const cssValue = computed ? computed.getPropertyValue(name) : null;
- if (cssValue === items[i]) {
- return true;
- }
- }
- }
- return false;
- };
- };
- const hasAttribute = attrName => {
- return node => {
- return isElement$6(node) && node.hasAttribute(attrName);
- };
- };
- const hasAttributeValue = (attrName, attrValue) => {
- return node => {
- return isElement$6(node) && node.getAttribute(attrName) === attrValue;
- };
- };
- const isBogus$2 = node => isElement$6(node) && node.hasAttribute('data-mce-bogus');
- const isBogusAll$1 = node => isElement$6(node) && node.getAttribute('data-mce-bogus') === 'all';
- const isTable$3 = node => isElement$6(node) && node.tagName === 'TABLE';
- const hasContentEditableState = value => {
- return node => {
- if (isElement$6(node)) {
- if (node.contentEditable === value) {
- return true;
- }
- if (node.getAttribute('data-mce-contenteditable') === value) {
- return true;
- }
- }
- return false;
- };
- };
- const isTextareaOrInput = matchNodeNames([
- 'textarea',
- 'input'
- ]);
- const isText$9 = isNodeType(3);
- const isCData = isNodeType(4);
- const isPi = isNodeType(7);
- const isComment = isNodeType(8);
- const isDocument$1 = isNodeType(9);
- const isDocumentFragment = isNodeType(11);
- const isBr$6 = matchNodeNames(['br']);
- const isImg = matchNodeNames(['img']);
- const isContentEditableTrue$5 = hasContentEditableState('true');
- const isContentEditableFalse$b = hasContentEditableState('false');
- const isTableCell$5 = matchNodeNames([
- 'td',
- 'th'
- ]);
- const isMedia$2 = matchNodeNames([
- 'video',
- 'audio',
- 'object',
- 'embed'
- ]);
- const browser = detect$2().browser;
- const firstElement = nodes => find$2(nodes, isElement$7);
- const getTableCaptionDeltaY = elm => {
- if (browser.isFirefox() && name(elm) === 'table') {
- return firstElement(children(elm)).filter(elm => {
- return name(elm) === 'caption';
- }).bind(caption => {
- return firstElement(nextSiblings(caption)).map(body => {
- const bodyTop = body.dom.offsetTop;
- const captionTop = caption.dom.offsetTop;
- const captionHeight = caption.dom.offsetHeight;
- return bodyTop <= captionTop ? -captionHeight : 0;
- });
- }).getOr(0);
- } else {
- return 0;
- }
- };
- const hasChild = (elm, child) => elm.children && contains$2(elm.children, child);
- const getPos = (body, elm, rootElm) => {
- let x = 0, y = 0;
- const doc = body.ownerDocument;
- rootElm = rootElm ? rootElm : body;
- if (elm) {
- if (rootElm === body && elm.getBoundingClientRect && get$7(SugarElement.fromDom(body), 'position') === 'static') {
- const pos = elm.getBoundingClientRect();
- x = pos.left + (doc.documentElement.scrollLeft || body.scrollLeft) - doc.documentElement.clientLeft;
- y = pos.top + (doc.documentElement.scrollTop || body.scrollTop) - doc.documentElement.clientTop;
- return {
- x,
- y
- };
- }
- let offsetParent = elm;
- while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
- const castOffsetParent = offsetParent;
- x += castOffsetParent.offsetLeft || 0;
- y += castOffsetParent.offsetTop || 0;
- offsetParent = castOffsetParent.offsetParent;
- }
- offsetParent = elm.parentNode;
- while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {
- x -= offsetParent.scrollLeft || 0;
- y -= offsetParent.scrollTop || 0;
- offsetParent = offsetParent.parentNode;
- }
- y += getTableCaptionDeltaY(SugarElement.fromDom(elm));
- }
- return {
- x,
- y
- };
- };
- var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => {
- if (is(scope, a)) {
- return Optional.some(scope);
- } else if (isFunction(isRoot) && isRoot(scope)) {
- return Optional.none();
- } else {
- return ancestor(scope, a, isRoot);
- }
- };
- const ancestor$3 = (scope, predicate, isRoot) => {
- let element = scope.dom;
- const stop = isFunction(isRoot) ? isRoot : never;
- while (element.parentNode) {
- element = element.parentNode;
- const el = SugarElement.fromDom(element);
- if (predicate(el)) {
- return Optional.some(el);
- } else if (stop(el)) {
- break;
- }
- }
- return Optional.none();
- };
- const closest$4 = (scope, predicate, isRoot) => {
- const is = (s, test) => test(s);
- return ClosestOrAncestor(is, ancestor$3, scope, predicate, isRoot);
- };
- const sibling$1 = (scope, predicate) => {
- const element = scope.dom;
- if (!element.parentNode) {
- return Optional.none();
- }
- return child(SugarElement.fromDom(element.parentNode), x => !eq(scope, x) && predicate(x));
- };
- const child = (scope, predicate) => {
- const pred = node => predicate(SugarElement.fromDom(node));
- const result = find$2(scope.dom.childNodes, pred);
- return result.map(SugarElement.fromDom);
- };
- const descendant$1 = (scope, predicate) => {
- const descend = node => {
- for (let i = 0; i < node.childNodes.length; i++) {
- const child = SugarElement.fromDom(node.childNodes[i]);
- if (predicate(child)) {
- return Optional.some(child);
- }
- const res = descend(node.childNodes[i]);
- if (res.isSome()) {
- return res;
- }
- }
- return Optional.none();
- };
- return descend(scope.dom);
- };
- const ancestor$2 = (scope, selector, isRoot) => ancestor$3(scope, e => is$1(e, selector), isRoot);
- const descendant = (scope, selector) => one(selector, scope);
- const closest$3 = (scope, selector, isRoot) => {
- const is = (element, selector) => is$1(element, selector);
- return ClosestOrAncestor(is, ancestor$2, scope, selector, isRoot);
- };
- const StyleSheetLoader = (documentOrShadowRoot, settings = {}) => {
- let idCount = 0;
- const loadedStates = {};
- const edos = SugarElement.fromDom(documentOrShadowRoot);
- const doc = documentOrOwner(edos);
- const maxLoadTime = settings.maxLoadTime || 5000;
- const _setReferrerPolicy = referrerPolicy => {
- settings.referrerPolicy = referrerPolicy;
- };
- const addStyle = element => {
- append$1(getStyleContainer(edos), element);
- };
- const removeStyle = id => {
- const styleContainer = getStyleContainer(edos);
- descendant(styleContainer, '#' + id).each(remove$6);
- };
- const getOrCreateState = url => get$a(loadedStates, url).getOrThunk(() => ({
- id: 'mce-u' + idCount++,
- passed: [],
- failed: [],
- count: 0
- }));
- const load = url => new Promise((success, failure) => {
- let link;
- const urlWithSuffix = Tools._addCacheSuffix(url);
- const state = getOrCreateState(urlWithSuffix);
- loadedStates[urlWithSuffix] = state;
- state.count++;
- const resolve = (callbacks, status) => {
- each$f(callbacks, call);
- state.status = status;
- state.passed = [];
- state.failed = [];
- if (link) {
- link.onload = null;
- link.onerror = null;
- link = null;
- }
- };
- const passed = () => resolve(state.passed, 2);
- const failed = () => resolve(state.failed, 3);
- const wait = (testCallback, waitCallback) => {
- if (!testCallback()) {
- if (Date.now() - startTime < maxLoadTime) {
- setTimeout(waitCallback);
- } else {
- failed();
- }
- }
- };
- const waitForWebKitLinkLoaded = () => {
- wait(() => {
- const styleSheets = documentOrShadowRoot.styleSheets;
- let i = styleSheets.length;
- while (i--) {
- const styleSheet = styleSheets[i];
- const owner = styleSheet.ownerNode;
- if (owner && owner.id === link.id) {
- passed();
- return true;
- }
- }
- return false;
- }, waitForWebKitLinkLoaded);
- };
- if (success) {
- state.passed.push(success);
- }
- if (failure) {
- state.failed.push(failure);
- }
- if (state.status === 1) {
- return;
- }
- if (state.status === 2) {
- passed();
- return;
- }
- if (state.status === 3) {
- failed();
- return;
- }
- state.status = 1;
- const linkElem = SugarElement.fromTag('link', doc.dom);
- setAll$1(linkElem, {
- rel: 'stylesheet',
- type: 'text/css',
- id: state.id
- });
- const startTime = Date.now();
- if (settings.contentCssCors) {
- set$2(linkElem, 'crossOrigin', 'anonymous');
- }
- if (settings.referrerPolicy) {
- set$2(linkElem, 'referrerpolicy', settings.referrerPolicy);
- }
- link = linkElem.dom;
- link.onload = waitForWebKitLinkLoaded;
- link.onerror = failed;
- addStyle(linkElem);
- set$2(linkElem, 'href', urlWithSuffix);
- });
- const loadAll = urls => {
- const loadedUrls = Promise.allSettled(map$3(urls, url => load(url).then(constant(url))));
- return loadedUrls.then(results => {
- const parts = partition$2(results, r => r.status === 'fulfilled');
- if (parts.fail.length > 0) {
- return Promise.reject(map$3(parts.fail, result => result.reason));
- } else {
- return map$3(parts.pass, result => result.value);
- }
- });
- };
- const unload = url => {
- const urlWithSuffix = Tools._addCacheSuffix(url);
- get$a(loadedStates, urlWithSuffix).each(state => {
- const count = --state.count;
- if (count === 0) {
- delete loadedStates[urlWithSuffix];
- removeStyle(state.id);
- }
- });
- };
- const unloadAll = urls => {
- each$f(urls, url => {
- unload(url);
- });
- };
- return {
- load,
- loadAll,
- unload,
- unloadAll,
- _setReferrerPolicy
- };
- };
- const create$d = () => {
- const map = new WeakMap();
- const forElement = (referenceElement, settings) => {
- const root = getRootNode(referenceElement);
- const rootDom = root.dom;
- return Optional.from(map.get(rootDom)).getOrThunk(() => {
- const sl = StyleSheetLoader(rootDom, settings);
- map.set(rootDom, sl);
- return sl;
- });
- };
- return { forElement };
- };
- const instance = create$d();
- class DomTreeWalker {
- constructor(startNode, rootNode) {
- this.node = startNode;
- this.rootNode = rootNode;
- this.current = this.current.bind(this);
- this.next = this.next.bind(this);
- this.prev = this.prev.bind(this);
- this.prev2 = this.prev2.bind(this);
- }
- current() {
- return this.node;
- }
- next(shallow) {
- this.node = this.findSibling(this.node, 'firstChild', 'nextSibling', shallow);
- return this.node;
- }
- prev(shallow) {
- this.node = this.findSibling(this.node, 'lastChild', 'previousSibling', shallow);
- return this.node;
- }
- prev2(shallow) {
- this.node = this.findPreviousNode(this.node, shallow);
- return this.node;
- }
- findSibling(node, startName, siblingName, shallow) {
- let sibling, parent;
- if (node) {
- if (!shallow && node[startName]) {
- return node[startName];
- }
- if (node !== this.rootNode) {
- sibling = node[siblingName];
- if (sibling) {
- return sibling;
- }
- for (parent = node.parentNode; parent && parent !== this.rootNode; parent = parent.parentNode) {
- sibling = parent[siblingName];
- if (sibling) {
- return sibling;
- }
- }
- }
- }
- }
- findPreviousNode(node, shallow) {
- let sibling, parent, child;
- if (node) {
- sibling = node.previousSibling;
- if (this.rootNode && sibling === this.rootNode) {
- return;
- }
- if (sibling) {
- if (!shallow) {
- for (child = sibling.lastChild; child; child = child.lastChild) {
- if (!child.lastChild) {
- return child;
- }
- }
- }
- return sibling;
- }
- parent = node.parentNode;
- if (parent && parent !== this.rootNode) {
- return parent;
- }
- }
- }
- }
- const blocks = [
- 'article',
- 'aside',
- 'details',
- 'div',
- 'dt',
- 'figcaption',
- 'footer',
- 'form',
- 'fieldset',
- 'header',
- 'hgroup',
- 'html',
- 'main',
- 'nav',
- 'section',
- 'summary',
- 'body',
- 'p',
- 'dl',
- 'multicol',
- 'dd',
- 'figure',
- 'address',
- 'center',
- 'blockquote',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'listing',
- 'xmp',
- 'pre',
- 'plaintext',
- 'menu',
- 'dir',
- 'ul',
- 'ol',
- 'li',
- 'hr',
- 'table',
- 'tbody',
- 'thead',
- 'tfoot',
- 'th',
- 'tr',
- 'td',
- 'caption'
- ];
- const tableCells = [
- 'td',
- 'th'
- ];
- const tableSections = [
- 'thead',
- 'tbody',
- 'tfoot'
- ];
- const textBlocks = [
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'p',
- 'div',
- 'address',
- 'pre',
- 'form',
- 'blockquote',
- 'center',
- 'dir',
- 'fieldset',
- 'header',
- 'footer',
- 'article',
- 'section',
- 'hgroup',
- 'aside',
- 'nav',
- 'figure'
- ];
- const headings = [
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6'
- ];
- const listItems$1 = [
- 'li',
- 'dd',
- 'dt'
- ];
- const lists = [
- 'ul',
- 'ol',
- 'dl'
- ];
- const wsElements = [
- 'pre',
- 'script',
- 'textarea',
- 'style'
- ];
- const wrapBlockElements = ['pre'].concat(headings);
- const lazyLookup = items => {
- let lookup;
- return node => {
- lookup = lookup ? lookup : mapToObject(items, always);
- return has$2(lookup, name(node));
- };
- };
- const isBlock$2 = lazyLookup(blocks);
- const isTable$2 = node => name(node) === 'table';
- const isInline$1 = node => isElement$7(node) && !isBlock$2(node);
- const isBr$5 = node => isElement$7(node) && name(node) === 'br';
- const isTextBlock$2 = lazyLookup(textBlocks);
- const isList = lazyLookup(lists);
- const isListItem = lazyLookup(listItems$1);
- const isTableSection = lazyLookup(tableSections);
- const isTableCell$4 = lazyLookup(tableCells);
- const isWsPreserveElement = lazyLookup(wsElements);
- const isWrapBlockElement = lazyLookup(wrapBlockElements);
- const isWrapElement = node => isWrapBlockElement(node) || isInline$1(node);
- const ancestor$1 = (scope, selector, isRoot) => ancestor$2(scope, selector, isRoot).isSome();
- const zeroWidth = '\uFEFF';
- const nbsp = '\xA0';
- const isZwsp$1 = char => char === zeroWidth;
- const removeZwsp = s => s.replace(/\uFEFF/g, '');
- const ZWSP$1 = zeroWidth;
- const isZwsp = isZwsp$1;
- const trim$1 = removeZwsp;
- const isElement$5 = isElement$6;
- const isText$8 = isText$9;
- const isCaretContainerBlock$1 = node => {
- if (isText$8(node)) {
- node = node.parentNode;
- }
- return isElement$5(node) && node.hasAttribute('data-mce-caret');
- };
- const isCaretContainerInline = node => isText$8(node) && isZwsp(node.data);
- const isCaretContainer$2 = node => isCaretContainerBlock$1(node) || isCaretContainerInline(node);
- const hasContent = node => node.firstChild !== node.lastChild || !isBr$6(node.firstChild);
- const insertInline$1 = (node, before) => {
- const doc = node.ownerDocument;
- const textNode = doc.createTextNode(ZWSP$1);
- const parentNode = node.parentNode;
- if (!before) {
- const sibling = node.nextSibling;
- if (isText$8(sibling)) {
- if (isCaretContainer$2(sibling)) {
- return sibling;
- }
- if (startsWithCaretContainer$1(sibling)) {
- sibling.splitText(1);
- return sibling;
- }
- }
- if (node.nextSibling) {
- parentNode.insertBefore(textNode, node.nextSibling);
- } else {
- parentNode.appendChild(textNode);
- }
- } else {
- const sibling = node.previousSibling;
- if (isText$8(sibling)) {
- if (isCaretContainer$2(sibling)) {
- return sibling;
- }
- if (endsWithCaretContainer$1(sibling)) {
- return sibling.splitText(sibling.data.length - 1);
- }
- }
- parentNode.insertBefore(textNode, node);
- }
- return textNode;
- };
- const isBeforeInline = pos => {
- const container = pos.container();
- if (!isText$9(container)) {
- return false;
- }
- return container.data.charAt(pos.offset()) === ZWSP$1 || pos.isAtStart() && isCaretContainerInline(container.previousSibling);
- };
- const isAfterInline = pos => {
- const container = pos.container();
- if (!isText$9(container)) {
- return false;
- }
- return container.data.charAt(pos.offset() - 1) === ZWSP$1 || pos.isAtEnd() && isCaretContainerInline(container.nextSibling);
- };
- const createBogusBr = () => {
- const br = document.createElement('br');
- br.setAttribute('data-mce-bogus', '1');
- return br;
- };
- const insertBlock = (blockName, node, before) => {
- const doc = node.ownerDocument;
- const blockNode = doc.createElement(blockName);
- blockNode.setAttribute('data-mce-caret', before ? 'before' : 'after');
- blockNode.setAttribute('data-mce-bogus', 'all');
- blockNode.appendChild(createBogusBr());
- const parentNode = node.parentNode;
- if (!before) {
- if (node.nextSibling) {
- parentNode.insertBefore(blockNode, node.nextSibling);
- } else {
- parentNode.appendChild(blockNode);
- }
- } else {
- parentNode.insertBefore(blockNode, node);
- }
- return blockNode;
- };
- const startsWithCaretContainer$1 = node => isText$8(node) && node.data[0] === ZWSP$1;
- const endsWithCaretContainer$1 = node => isText$8(node) && node.data[node.data.length - 1] === ZWSP$1;
- const trimBogusBr = elm => {
- const brs = elm.getElementsByTagName('br');
- const lastBr = brs[brs.length - 1];
- if (isBogus$2(lastBr)) {
- lastBr.parentNode.removeChild(lastBr);
- }
- };
- const showCaretContainerBlock = caretContainer => {
- if (caretContainer && caretContainer.hasAttribute('data-mce-caret')) {
- trimBogusBr(caretContainer);
- caretContainer.removeAttribute('data-mce-caret');
- caretContainer.removeAttribute('data-mce-bogus');
- caretContainer.removeAttribute('style');
- caretContainer.removeAttribute('data-mce-style');
- caretContainer.removeAttribute('_moz_abspos');
- return caretContainer;
- }
- return null;
- };
- const isRangeInCaretContainerBlock = range => isCaretContainerBlock$1(range.startContainer);
- const isContentEditableTrue$4 = isContentEditableTrue$5;
- const isContentEditableFalse$a = isContentEditableFalse$b;
- const isBr$4 = isBr$6;
- const isText$7 = isText$9;
- const isInvalidTextElement = matchNodeNames([
- 'script',
- 'style',
- 'textarea'
- ]);
- const isAtomicInline = matchNodeNames([
- 'img',
- 'input',
- 'textarea',
- 'hr',
- 'iframe',
- 'video',
- 'audio',
- 'object',
- 'embed'
- ]);
- const isTable$1 = matchNodeNames(['table']);
- const isCaretContainer$1 = isCaretContainer$2;
- const isCaretCandidate$3 = node => {
- if (isCaretContainer$1(node)) {
- return false;
- }
- if (isText$7(node)) {
- return !isInvalidTextElement(node.parentNode);
- }
- return isAtomicInline(node) || isBr$4(node) || isTable$1(node) || isNonUiContentEditableFalse(node);
- };
- const isUnselectable = node => isElement$6(node) && node.getAttribute('unselectable') === 'true';
- const isNonUiContentEditableFalse = node => isUnselectable(node) === false && isContentEditableFalse$a(node);
- const isInEditable = (node, root) => {
- for (node = node.parentNode; node && node !== root; node = node.parentNode) {
- if (isNonUiContentEditableFalse(node)) {
- return false;
- }
- if (isContentEditableTrue$4(node)) {
- return true;
- }
- }
- return true;
- };
- const isAtomicContentEditableFalse = node => {
- if (!isNonUiContentEditableFalse(node)) {
- return false;
- }
- return foldl(from(node.getElementsByTagName('*')), (result, elm) => {
- return result || isContentEditableTrue$4(elm);
- }, false) !== true;
- };
- const isAtomic$1 = node => isAtomicInline(node) || isAtomicContentEditableFalse(node);
- const isEditableCaretCandidate$1 = (node, root) => isCaretCandidate$3(node) && isInEditable(node, root);
- const whiteSpaceRegExp = /^[ \t\r\n]*$/;
- const isWhitespaceText = text => whiteSpaceRegExp.test(text);
- const isCollapsibleWhitespace$1 = c => ' \f\t\x0B'.indexOf(c) !== -1;
- const isNewLineChar = c => c === '\n' || c === '\r';
- const isNewline = (text, idx) => idx < text.length && idx >= 0 ? isNewLineChar(text[idx]) : false;
- const normalize$4 = (text, tabSpaces = 4, isStartOfContent = true, isEndOfContent = true) => {
- const tabSpace = repeat(' ', tabSpaces);
- const normalizedText = text.replace(/\t/g, tabSpace);
- const result = foldl(normalizedText, (acc, c) => {
- if (isCollapsibleWhitespace$1(c) || c === nbsp) {
- if (acc.pcIsSpace || acc.str === '' && isStartOfContent || acc.str.length === normalizedText.length - 1 && isEndOfContent || isNewline(normalizedText, acc.str.length + 1)) {
- return {
- pcIsSpace: false,
- str: acc.str + nbsp
- };
- } else {
- return {
- pcIsSpace: true,
- str: acc.str + ' '
- };
- }
- } else {
- return {
- pcIsSpace: isNewLineChar(c),
- str: acc.str + c
- };
- }
- }, {
- pcIsSpace: false,
- str: ''
- });
- return result.str;
- };
- const hasWhitespacePreserveParent = (node, rootNode) => {
- const rootElement = SugarElement.fromDom(rootNode);
- const startNode = SugarElement.fromDom(node);
- return ancestor$1(startNode, 'pre,code', curry(eq, rootElement));
- };
- const isWhitespace$1 = (node, rootNode) => {
- return isText$9(node) && isWhitespaceText(node.data) && hasWhitespacePreserveParent(node, rootNode) === false;
- };
- const isNamedAnchor = node => {
- return isElement$6(node) && node.nodeName === 'A' && !node.hasAttribute('href') && (node.hasAttribute('name') || node.hasAttribute('id'));
- };
- const isContent$1 = (node, rootNode) => {
- return isCaretCandidate$3(node) && isWhitespace$1(node, rootNode) === false || isNamedAnchor(node) || isBookmark(node);
- };
- const isBookmark = hasAttribute('data-mce-bookmark');
- const isBogus$1 = hasAttribute('data-mce-bogus');
- const isBogusAll = hasAttributeValue('data-mce-bogus', 'all');
- const isEmptyNode = (targetNode, skipBogus) => {
- let brCount = 0;
- if (isContent$1(targetNode, targetNode)) {
- return false;
- } else {
- let node = targetNode.firstChild;
- if (!node) {
- return true;
- }
- const walker = new DomTreeWalker(node, targetNode);
- do {
- if (skipBogus) {
- if (isBogusAll(node)) {
- node = walker.next(true);
- continue;
- }
- if (isBogus$1(node)) {
- node = walker.next();
- continue;
- }
- }
- if (isBr$6(node)) {
- brCount++;
- node = walker.next();
- continue;
- }
- if (isContent$1(node, targetNode)) {
- return false;
- }
- node = walker.next();
- } while (node);
- return brCount <= 1;
- }
- };
- const isEmpty$2 = (elm, skipBogus = true) => isEmptyNode(elm.dom, skipBogus);
- const isSpan = node => node.nodeName.toLowerCase() === 'span';
- const isInlineContent = (node, root) => isNonNullable(node) && (isContent$1(node, root) || isInline$1(SugarElement.fromDom(node)));
- const surroundedByInlineContent = (node, root) => {
- const prev = new DomTreeWalker(node, root).prev(false);
- const next = new DomTreeWalker(node, root).next(false);
- const prevIsInline = isUndefined(prev) || isInlineContent(prev, root);
- const nextIsInline = isUndefined(next) || isInlineContent(next, root);
- return prevIsInline && nextIsInline;
- };
- const isBookmarkNode$2 = node => isSpan(node) && node.getAttribute('data-mce-type') === 'bookmark';
- const isKeepTextNode = (node, root) => isText$9(node) && node.data.length > 0 && surroundedByInlineContent(node, root);
- const isKeepElement = node => isElement$6(node) ? node.childNodes.length > 0 : false;
- const isDocument = node => isDocumentFragment(node) || isDocument$1(node);
- const trimNode = (dom, node, root) => {
- const rootNode = root || node;
- if (isElement$6(node) && isBookmarkNode$2(node)) {
- return node;
- }
- const children = node.childNodes;
- for (let i = children.length - 1; i >= 0; i--) {
- trimNode(dom, children[i], rootNode);
- }
- if (isElement$6(node)) {
- const currentChildren = node.childNodes;
- if (currentChildren.length === 1 && isBookmarkNode$2(currentChildren[0])) {
- node.parentNode.insertBefore(currentChildren[0], node);
- }
- }
- if (!isDocument(node) && !isContent$1(node, rootNode) && !isKeepElement(node) && !isKeepTextNode(node, rootNode)) {
- dom.remove(node);
- }
- return node;
- };
- const makeMap$3 = Tools.makeMap;
- const attrsCharsRegExp = /[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
- const textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
- const rawCharsRegExp = /[<>&\"\']/g;
- const entityRegExp = /&#([a-z0-9]+);?|&([a-z0-9]+);/gi;
- const asciiMap = {
- 128: '\u20AC',
- 130: '\u201A',
- 131: '\u0192',
- 132: '\u201E',
- 133: '\u2026',
- 134: '\u2020',
- 135: '\u2021',
- 136: '\u02c6',
- 137: '\u2030',
- 138: '\u0160',
- 139: '\u2039',
- 140: '\u0152',
- 142: '\u017d',
- 145: '\u2018',
- 146: '\u2019',
- 147: '\u201C',
- 148: '\u201D',
- 149: '\u2022',
- 150: '\u2013',
- 151: '\u2014',
- 152: '\u02DC',
- 153: '\u2122',
- 154: '\u0161',
- 155: '\u203A',
- 156: '\u0153',
- 158: '\u017e',
- 159: '\u0178'
- };
- const baseEntities = {
- '"': '"',
- '\'': ''',
- '<': '<',
- '>': '>',
- '&': '&',
- '`': '`'
- };
- const reverseEntities = {
- '<': '<',
- '>': '>',
- '&': '&',
- '"': '"',
- ''': `'`
- };
- const nativeDecode = text => {
- const elm = SugarElement.fromTag('div').dom;
- elm.innerHTML = text;
- return elm.textContent || elm.innerText || text;
- };
- const buildEntitiesLookup = (items, radix) => {
- let i, chr, entity;
- const lookup = {};
- if (items) {
- items = items.split(',');
- radix = radix || 10;
- for (i = 0; i < items.length; i += 2) {
- chr = String.fromCharCode(parseInt(items[i], radix));
- if (!baseEntities[chr]) {
- entity = '&' + items[i + 1] + ';';
- lookup[chr] = entity;
- lookup[entity] = chr;
- }
- }
- return lookup;
- }
- };
- const namedEntities = buildEntitiesLookup('50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' + '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' + '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' + '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' + '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' + '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' + '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' + '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' + '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' + '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' + 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' + 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' + 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' + 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' + 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' + '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' + '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' + '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' + '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' + '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' + 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' + 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' + 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' + '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' + '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
- const encodeRaw = (text, attr) => text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {
- return baseEntities[chr] || chr;
- });
- const encodeAllRaw = text => ('' + text).replace(rawCharsRegExp, chr => {
- return baseEntities[chr] || chr;
- });
- const encodeNumeric = (text, attr) => text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {
- if (chr.length > 1) {
- return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';
- }
- return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
- });
- const encodeNamed = (text, attr, entities) => {
- entities = entities || namedEntities;
- return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {
- return baseEntities[chr] || entities[chr] || chr;
- });
- };
- const getEncodeFunc = (name, entities) => {
- const entitiesMap = buildEntitiesLookup(entities) || namedEntities;
- const encodeNamedAndNumeric = (text, attr) => text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {
- if (baseEntities[chr] !== undefined) {
- return baseEntities[chr];
- }
- if (entitiesMap[chr] !== undefined) {
- return entitiesMap[chr];
- }
- if (chr.length > 1) {
- return '&#' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';
- }
- return '&#' + chr.charCodeAt(0) + ';';
- });
- const encodeCustomNamed = (text, attr) => {
- return encodeNamed(text, attr, entitiesMap);
- };
- const nameMap = makeMap$3(name.replace(/\+/g, ','));
- if (nameMap.named && nameMap.numeric) {
- return encodeNamedAndNumeric;
- }
- if (nameMap.named) {
- if (entities) {
- return encodeCustomNamed;
- }
- return encodeNamed;
- }
- if (nameMap.numeric) {
- return encodeNumeric;
- }
- return encodeRaw;
- };
- const decode = text => text.replace(entityRegExp, (all, numeric) => {
- if (numeric) {
- if (numeric.charAt(0).toLowerCase() === 'x') {
- numeric = parseInt(numeric.substr(1), 16);
- } else {
- numeric = parseInt(numeric, 10);
- }
- if (numeric > 65535) {
- numeric -= 65536;
- return String.fromCharCode(55296 + (numeric >> 10), 56320 + (numeric & 1023));
- }
- return asciiMap[numeric] || String.fromCharCode(numeric);
- }
- return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
- });
- const Entities = {
- encodeRaw,
- encodeAllRaw,
- encodeNumeric,
- encodeNamed,
- getEncodeFunc,
- decode
- };
- const mapCache = {}, dummyObj = {};
- const makeMap$2 = Tools.makeMap, each$c = Tools.each, extend$2 = Tools.extend, explode$2 = Tools.explode, inArray = Tools.inArray;
- const split$1 = (items, delim) => {
- items = Tools.trim(items);
- return items ? items.split(delim || ' ') : [];
- };
- const createMap = (defaultValue, extendWith) => {
- const value = makeMap$2(defaultValue, ' ', makeMap$2(defaultValue.toUpperCase(), ' '));
- return extend$2(value, extendWith);
- };
- const getTextRootBlockElements = schema => createMap('td th li dt dd figcaption caption details summary', schema.getTextBlockElements());
- const compileSchema = type => {
- const schema = {};
- let globalAttributes, blockContent;
- let phrasingContent, flowContent, html4BlockContent, html4PhrasingContent;
- const add = (name, attributes = '', children = '') => {
- const childNames = split$1(children);
- const names = split$1(name);
- let ni = names.length;
- while (ni--) {
- const attributesOrder = split$1([
- globalAttributes,
- attributes
- ].join(' '));
- schema[names[ni]] = {
- attributes: mapToObject(attributesOrder, () => ({})),
- attributesOrder,
- children: mapToObject(childNames, constant(dummyObj))
- };
- }
- };
- const addAttrs = (name, attributes) => {
- const names = split$1(name);
- const attrs = split$1(attributes);
- let ni = names.length;
- while (ni--) {
- const schemaItem = schema[names[ni]];
- for (let i = 0, l = attrs.length; i < l; i++) {
- schemaItem.attributes[attrs[i]] = {};
- schemaItem.attributesOrder.push(attrs[i]);
- }
- }
- };
- if (mapCache[type]) {
- return mapCache[type];
- }
- globalAttributes = 'id accesskey class dir lang style tabindex title role';
- blockContent = 'address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul';
- phrasingContent = 'a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd ' + 'label map noscript object q s samp script select small span strong sub sup ' + 'textarea u var #text #comment';
- if (type !== 'html4') {
- globalAttributes += ' contenteditable contextmenu draggable dropzone ' + 'hidden spellcheck translate';
- blockContent += ' article aside details dialog figure main header footer hgroup section nav';
- phrasingContent += ' audio canvas command datalist mark meter output picture ' + 'progress time wbr video ruby bdi keygen';
- }
- if (type !== 'html5-strict') {
- globalAttributes += ' xml:lang';
- html4PhrasingContent = 'acronym applet basefont big font strike tt';
- phrasingContent = [
- phrasingContent,
- html4PhrasingContent
- ].join(' ');
- each$c(split$1(html4PhrasingContent), name => {
- add(name, '', phrasingContent);
- });
- html4BlockContent = 'center dir isindex noframes';
- blockContent = [
- blockContent,
- html4BlockContent
- ].join(' ');
- flowContent = [
- blockContent,
- phrasingContent
- ].join(' ');
- each$c(split$1(html4BlockContent), name => {
- add(name, '', flowContent);
- });
- }
- flowContent = flowContent || [
- blockContent,
- phrasingContent
- ].join(' ');
- add('html', 'manifest', 'head body');
- add('head', '', 'base command link meta noscript script style title');
- add('title hr noscript br');
- add('base', 'href target');
- add('link', 'href rel media hreflang type sizes hreflang');
- add('meta', 'name http-equiv content charset');
- add('style', 'media type scoped');
- add('script', 'src async defer type charset');
- add('body', 'onafterprint onbeforeprint onbeforeunload onblur onerror onfocus ' + 'onhashchange onload onmessage onoffline ononline onpagehide onpageshow ' + 'onpopstate onresize onscroll onstorage onunload', flowContent);
- add('address dt dd div caption', '', flowContent);
- add('h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn', '', phrasingContent);
- add('blockquote', 'cite', flowContent);
- add('ol', 'reversed start type', 'li');
- add('ul', '', 'li');
- add('li', 'value', flowContent);
- add('dl', '', 'dt dd');
- add('a', 'href target rel media hreflang type', phrasingContent);
- add('q', 'cite', phrasingContent);
- add('ins del', 'cite datetime', flowContent);
- add('img', 'src sizes srcset alt usemap ismap width height');
- add('iframe', 'src name width height', flowContent);
- add('embed', 'src type width height');
- add('object', 'data type typemustmatch name usemap form width height', [
- flowContent,
- 'param'
- ].join(' '));
- add('param', 'name value');
- add('map', 'name', [
- flowContent,
- 'area'
- ].join(' '));
- add('area', 'alt coords shape href target rel media hreflang type');
- add('table', 'border', 'caption colgroup thead tfoot tbody tr' + (type === 'html4' ? ' col' : ''));
- add('colgroup', 'span', 'col');
- add('col', 'span');
- add('tbody thead tfoot', '', 'tr');
- add('tr', '', 'td th');
- add('td', 'colspan rowspan headers', flowContent);
- add('th', 'colspan rowspan headers scope abbr', flowContent);
- add('form', 'accept-charset action autocomplete enctype method name novalidate target', flowContent);
- add('fieldset', 'disabled form name', [
- flowContent,
- 'legend'
- ].join(' '));
- add('label', 'form for', phrasingContent);
- add('input', 'accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate ' + 'formtarget height list max maxlength min multiple name pattern readonly required size src step type value width');
- add('button', 'disabled form formaction formenctype formmethod formnovalidate formtarget name type value', type === 'html4' ? flowContent : phrasingContent);
- add('select', 'disabled form multiple name required size', 'option optgroup');
- add('optgroup', 'disabled label', 'option');
- add('option', 'disabled label selected value');
- add('textarea', 'cols dirname disabled form maxlength name readonly required rows wrap');
- add('menu', 'type label', [
- flowContent,
- 'li'
- ].join(' '));
- add('noscript', '', flowContent);
- if (type !== 'html4') {
- add('wbr');
- add('ruby', '', [
- phrasingContent,
- 'rt rp'
- ].join(' '));
- add('figcaption', '', flowContent);
- add('mark rt rp summary bdi', '', phrasingContent);
- add('canvas', 'width height', flowContent);
- add('video', 'src crossorigin poster preload autoplay mediagroup loop ' + 'muted controls width height buffered', [
- flowContent,
- 'track source'
- ].join(' '));
- add('audio', 'src crossorigin preload autoplay mediagroup loop muted controls ' + 'buffered volume', [
- flowContent,
- 'track source'
- ].join(' '));
- add('picture', '', 'img source');
- add('source', 'src srcset type media sizes');
- add('track', 'kind src srclang label default');
- add('datalist', '', [
- phrasingContent,
- 'option'
- ].join(' '));
- add('article section nav aside main header footer', '', flowContent);
- add('hgroup', '', 'h1 h2 h3 h4 h5 h6');
- add('figure', '', [
- flowContent,
- 'figcaption'
- ].join(' '));
- add('time', 'datetime', phrasingContent);
- add('dialog', 'open', flowContent);
- add('command', 'type label icon disabled checked radiogroup command');
- add('output', 'for form name', phrasingContent);
- add('progress', 'value max', phrasingContent);
- add('meter', 'value min max low high optimum', phrasingContent);
- add('details', 'open', [
- flowContent,
- 'summary'
- ].join(' '));
- add('keygen', 'autofocus challenge disabled form keytype name');
- }
- if (type !== 'html5-strict') {
- addAttrs('script', 'language xml:space');
- addAttrs('style', 'xml:space');
- addAttrs('object', 'declare classid code codebase codetype archive standby align border hspace vspace');
- addAttrs('embed', 'align name hspace vspace');
- addAttrs('param', 'valuetype type');
- addAttrs('a', 'charset name rev shape coords');
- addAttrs('br', 'clear');
- addAttrs('applet', 'codebase archive code object alt name width height align hspace vspace');
- addAttrs('img', 'name longdesc align border hspace vspace');
- addAttrs('iframe', 'longdesc frameborder marginwidth marginheight scrolling align');
- addAttrs('font basefont', 'size color face');
- addAttrs('input', 'usemap align');
- addAttrs('select');
- addAttrs('textarea');
- addAttrs('h1 h2 h3 h4 h5 h6 div p legend caption', 'align');
- addAttrs('ul', 'type compact');
- addAttrs('li', 'type');
- addAttrs('ol dl menu dir', 'compact');
- addAttrs('pre', 'width xml:space');
- addAttrs('hr', 'align noshade size width');
- addAttrs('isindex', 'prompt');
- addAttrs('table', 'summary width frame rules cellspacing cellpadding align bgcolor');
- addAttrs('col', 'width align char charoff valign');
- addAttrs('colgroup', 'width align char charoff valign');
- addAttrs('thead', 'align char charoff valign');
- addAttrs('tr', 'align char charoff valign bgcolor');
- addAttrs('th', 'axis align char charoff valign nowrap bgcolor width height');
- addAttrs('form', 'accept');
- addAttrs('td', 'abbr axis scope align char charoff valign nowrap bgcolor width height');
- addAttrs('tfoot', 'align char charoff valign');
- addAttrs('tbody', 'align char charoff valign');
- addAttrs('area', 'nohref');
- addAttrs('body', 'background bgcolor text link vlink alink');
- }
- if (type !== 'html4') {
- addAttrs('input button select textarea', 'autofocus');
- addAttrs('input textarea', 'placeholder');
- addAttrs('a', 'download');
- addAttrs('link script img', 'crossorigin');
- addAttrs('img', 'loading');
- addAttrs('iframe', 'sandbox seamless allowfullscreen loading');
- }
- if (type !== 'html4') {
- each$f([
- schema.video,
- schema.audio
- ], item => {
- delete item.children.audio;
- delete item.children.video;
- });
- }
- each$c(split$1('a form meter progress dfn'), name => {
- if (schema[name]) {
- delete schema[name].children[name];
- }
- });
- delete schema.caption.children.table;
- delete schema.script;
- mapCache[type] = schema;
- return schema;
- };
- const compileElementMap = (value, mode) => {
- let styles;
- if (value) {
- styles = {};
- if (typeof value === 'string') {
- value = { '*': value };
- }
- each$c(value, (value, key) => {
- styles[key] = styles[key.toUpperCase()] = mode === 'map' ? makeMap$2(value, /[, ]/) : explode$2(value, /[, ]/);
- });
- }
- return styles;
- };
- const Schema = settings => {
- var _a;
- const elements = {};
- const children = {};
- let patternElements = [];
- const customElementsMap = {}, specialElements = {};
- const createLookupTable = (option, defaultValue, extendWith) => {
- let value = settings[option];
- if (!value) {
- value = mapCache[option];
- if (!value) {
- value = createMap(defaultValue, extendWith);
- mapCache[option] = value;
- }
- } else {
- value = makeMap$2(value, /[, ]/, makeMap$2(value.toUpperCase(), /[, ]/));
- }
- return value;
- };
- settings = settings || {};
- const schemaType = (_a = settings.schema) !== null && _a !== void 0 ? _a : 'html5';
- const schemaItems = compileSchema(schemaType);
- if (settings.verify_html === false) {
- settings.valid_elements = '*[*]';
- }
- const validStyles = compileElementMap(settings.valid_styles);
- const invalidStyles = compileElementMap(settings.invalid_styles, 'map');
- const validClasses = compileElementMap(settings.valid_classes, 'map');
- const whitespaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea video audio iframe object code');
- const selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
- const voidElementsMap = createLookupTable('void_elements', 'area base basefont br col frame hr img input isindex link ' + 'meta param embed source wbr track');
- const boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize ' + 'noshade nowrap readonly selected autoplay loop controls allowfullscreen');
- const nonEmptyOrMoveCaretBeforeOnEnter = 'td th iframe video audio object script code';
- const nonEmptyElementsMap = createLookupTable('non_empty_elements', nonEmptyOrMoveCaretBeforeOnEnter + ' pre', voidElementsMap);
- const moveCaretBeforeOnEnterElementsMap = createLookupTable('move_caret_before_on_enter_elements', nonEmptyOrMoveCaretBeforeOnEnter + ' table', voidElementsMap);
- const textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' + 'blockquote center dir fieldset header footer article section hgroup aside main nav figure');
- const blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + 'th tr td li ol ul caption dl dt dd noscript menu isindex option ' + 'datalist select optgroup figcaption details summary', textBlockElementsMap);
- const textInlineElementsMap = createLookupTable('text_inline_elements', 'span strong b em i font s strike u var cite ' + 'dfn code mark q sup sub samp');
- each$c('script noscript iframe noframes noembed title style textarea xmp plaintext'.split(' '), name => {
- specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi');
- });
- const patternToRegExp = str => new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
- const addValidElements = validElements => {
- let ei, el, ai, al, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, prefix, outputName, globalAttributes, globalAttributesOrder, value;
- const elementRuleRegExp = /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)])?$/, attrRuleRegExp = /^([!\-])?(\w+[\\:]:\w+|[^=~<]+)?(?:([=~<])(.*))?$/, hasPatternsRegExp = /[*?+]/;
- if (validElements) {
- const validElementsArr = split$1(validElements, ',');
- if (elements['@']) {
- globalAttributes = elements['@'].attributes;
- globalAttributesOrder = elements['@'].attributesOrder;
- }
- for (ei = 0, el = validElementsArr.length; ei < el; ei++) {
- matches = elementRuleRegExp.exec(validElementsArr[ei]);
- if (matches) {
- prefix = matches[1];
- elementName = matches[2];
- outputName = matches[3];
- attrData = matches[5];
- attributes = {};
- attributesOrder = [];
- element = {
- attributes,
- attributesOrder
- };
- if (prefix === '#') {
- element.paddEmpty = true;
- }
- if (prefix === '-') {
- element.removeEmpty = true;
- }
- if (matches[4] === '!') {
- element.removeEmptyAttrs = true;
- }
- if (globalAttributes) {
- each$e(globalAttributes, (value, key) => {
- attributes[key] = value;
- });
- attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
- }
- if (attrData) {
- attrData = split$1(attrData, '|');
- for (ai = 0, al = attrData.length; ai < al; ai++) {
- matches = attrRuleRegExp.exec(attrData[ai]);
- if (matches) {
- attr = {};
- attrType = matches[1];
- attrName = matches[2].replace(/[\\:]:/g, ':');
- prefix = matches[3];
- value = matches[4];
- if (attrType === '!') {
- element.attributesRequired = element.attributesRequired || [];
- element.attributesRequired.push(attrName);
- attr.required = true;
- }
- if (attrType === '-') {
- delete attributes[attrName];
- attributesOrder.splice(inArray(attributesOrder, attrName), 1);
- continue;
- }
- if (prefix) {
- if (prefix === '=') {
- element.attributesDefault = element.attributesDefault || [];
- element.attributesDefault.push({
- name: attrName,
- value
- });
- attr.defaultValue = value;
- }
- if (prefix === '~') {
- element.attributesForced = element.attributesForced || [];
- element.attributesForced.push({
- name: attrName,
- value
- });
- attr.forcedValue = value;
- }
- if (prefix === '<') {
- attr.validValues = makeMap$2(value, '?');
- }
- }
- if (hasPatternsRegExp.test(attrName)) {
- element.attributePatterns = element.attributePatterns || [];
- attr.pattern = patternToRegExp(attrName);
- element.attributePatterns.push(attr);
- } else {
- if (!attributes[attrName]) {
- attributesOrder.push(attrName);
- }
- attributes[attrName] = attr;
- }
- }
- }
- }
- if (!globalAttributes && elementName === '@') {
- globalAttributes = attributes;
- globalAttributesOrder = attributesOrder;
- }
- if (outputName) {
- element.outputName = elementName;
- elements[outputName] = element;
- }
- if (hasPatternsRegExp.test(elementName)) {
- element.pattern = patternToRegExp(elementName);
- patternElements.push(element);
- } else {
- elements[elementName] = element;
- }
- }
- }
- }
- };
- const setValidElements = validElements => {
- patternElements = [];
- each$f(keys(elements), name => {
- delete elements[name];
- });
- addValidElements(validElements);
- each$c(schemaItems, (element, name) => {
- children[name] = element.children;
- });
- };
- const addCustomElements = customElements => {
- const customElementRegExp = /^(~)?(.+)$/;
- if (customElements) {
- mapCache.text_block_elements = mapCache.block_elements = null;
- each$c(split$1(customElements, ','), rule => {
- const matches = customElementRegExp.exec(rule), inline = matches[1] === '~', cloneName = inline ? 'span' : 'div', name = matches[2];
- children[name] = children[cloneName];
- customElementsMap[name] = cloneName;
- nonEmptyElementsMap[name.toUpperCase()] = {};
- nonEmptyElementsMap[name] = {};
- if (!inline) {
- blockElementsMap[name.toUpperCase()] = {};
- blockElementsMap[name] = {};
- }
- if (!elements[name]) {
- let customRule = elements[cloneName];
- customRule = extend$2({}, customRule);
- delete customRule.removeEmptyAttrs;
- delete customRule.removeEmpty;
- elements[name] = customRule;
- }
- each$c(children, (element, elmName) => {
- if (element[cloneName]) {
- children[elmName] = element = extend$2({}, children[elmName]);
- element[name] = element[cloneName];
- }
- });
- });
- }
- };
- const addValidChildren = validChildren => {
- const childRuleRegExp = /^([+\-]?)([A-Za-z0-9_\-.\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]+)\[([^\]]+)]$/;
- mapCache[schemaType] = null;
- if (validChildren) {
- each$c(split$1(validChildren, ','), rule => {
- const matches = childRuleRegExp.exec(rule);
- let parent, prefix;
- if (matches) {
- prefix = matches[1];
- if (prefix) {
- parent = children[matches[2]];
- } else {
- parent = children[matches[2]] = { '#comment': {} };
- }
- parent = children[matches[2]];
- each$c(split$1(matches[3], '|'), child => {
- if (prefix === '-') {
- delete parent[child];
- } else {
- parent[child] = {};
- }
- });
- }
- });
- }
- };
- const getElementRule = name => {
- let element = elements[name], i;
- if (element) {
- return element;
- }
- i = patternElements.length;
- while (i--) {
- element = patternElements[i];
- if (element.pattern.test(name)) {
- return element;
- }
- }
- };
- if (!settings.valid_elements) {
- each$c(schemaItems, (element, name) => {
- elements[name] = {
- attributes: element.attributes,
- attributesOrder: element.attributesOrder
- };
- children[name] = element.children;
- });
- each$c(split$1('strong/b em/i'), item => {
- const items = split$1(item, '/');
- elements[items[1]].outputName = items[0];
- });
- each$c(textInlineElementsMap, (_val, name) => {
- if (elements[name]) {
- if (settings.padd_empty_block_inline_children) {
- elements[name].paddInEmptyBlock = true;
- }
- elements[name].removeEmpty = true;
- }
- });
- each$c(split$1('ol ul blockquote a table tbody'), name => {
- if (elements[name]) {
- elements[name].removeEmpty = true;
- }
- });
- each$c(split$1('p h1 h2 h3 h4 h5 h6 th td pre div address caption li'), name => {
- elements[name].paddEmpty = true;
- });
- each$c(split$1('span'), name => {
- elements[name].removeEmptyAttrs = true;
- });
- } else {
- setValidElements(settings.valid_elements);
- }
- addCustomElements(settings.custom_elements);
- addValidChildren(settings.valid_children);
- addValidElements(settings.extended_valid_elements);
- addValidChildren('+ol[ul|ol],+ul[ul|ol]');
- each$c({
- dd: 'dl',
- dt: 'dl',
- li: 'ul ol',
- td: 'tr',
- th: 'tr',
- tr: 'tbody thead tfoot',
- tbody: 'table',
- thead: 'table',
- tfoot: 'table',
- legend: 'fieldset',
- area: 'map',
- param: 'video audio object'
- }, (parents, item) => {
- if (elements[item]) {
- elements[item].parentsRequired = split$1(parents);
- }
- });
- if (settings.invalid_elements) {
- each$c(explode$2(settings.invalid_elements), item => {
- if (elements[item]) {
- delete elements[item];
- }
- });
- }
- if (!getElementRule('span')) {
- addValidElements('span[!data-mce-type|*]');
- }
- const getValidStyles = constant(validStyles);
- const getInvalidStyles = constant(invalidStyles);
- const getValidClasses = constant(validClasses);
- const getBoolAttrs = constant(boolAttrMap);
- const getBlockElements = constant(blockElementsMap);
- const getTextBlockElements = constant(textBlockElementsMap);
- const getTextInlineElements = constant(textInlineElementsMap);
- const getVoidElements = constant(Object.seal(voidElementsMap));
- const getSelfClosingElements = constant(selfClosingElementsMap);
- const getNonEmptyElements = constant(nonEmptyElementsMap);
- const getMoveCaretBeforeOnEnterElements = constant(moveCaretBeforeOnEnterElementsMap);
- const getWhitespaceElements = constant(whitespaceElementsMap);
- const getSpecialElements = constant(Object.seal(specialElements));
- const isValidChild = (name, child) => {
- const parent = children[name.toLowerCase()];
- return !!(parent && parent[child.toLowerCase()]);
- };
- const isValid = (name, attr) => {
- let attrPatterns, i;
- const rule = getElementRule(name);
- if (rule) {
- if (attr) {
- if (rule.attributes[attr]) {
- return true;
- }
- attrPatterns = rule.attributePatterns;
- if (attrPatterns) {
- i = attrPatterns.length;
- while (i--) {
- if (attrPatterns[i].pattern.test(attr)) {
- return true;
- }
- }
- }
- } else {
- return true;
- }
- }
- return false;
- };
- const getCustomElements = constant(customElementsMap);
- return {
- type: schemaType,
- children,
- elements,
- getValidStyles,
- getValidClasses,
- getBlockElements,
- getInvalidStyles,
- getVoidElements,
- getTextBlockElements,
- getTextInlineElements,
- getBoolAttrs,
- getElementRule,
- getSelfClosingElements,
- getNonEmptyElements,
- getMoveCaretBeforeOnEnterElements,
- getWhitespaceElements,
- getSpecialElements,
- isValidChild,
- isValid,
- getCustomElements,
- addValidElements,
- setValidElements,
- addCustomElements,
- addValidChildren
- };
- };
- const Styles = (settings, schema) => {
- const urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi;
- const styleRegExp = /\s*([^:]+):\s*([^;]+);?/g;
- const trimRightRegExp = /\s+$/;
- let i;
- const encodingLookup = {};
- let validStyles;
- let invalidStyles;
- const invisibleChar = zeroWidth;
- settings = settings || {};
- if (schema) {
- validStyles = schema.getValidStyles();
- invalidStyles = schema.getInvalidStyles();
- }
- const encodingItems = (`\\" \\' \\; \\: ; : ` + invisibleChar).split(' ');
- for (i = 0; i < encodingItems.length; i++) {
- encodingLookup[encodingItems[i]] = invisibleChar + i;
- encodingLookup[invisibleChar + i] = encodingItems[i];
- }
- const self = {
- parse: css => {
- const styles = {};
- let matches, name, value, isEncoded;
- const urlConverter = settings.url_converter;
- const urlConverterScope = settings.url_converter_scope || self;
- const compress = (prefix, suffix, noJoin) => {
- const top = styles[prefix + '-top' + suffix];
- if (!top) {
- return;
- }
- const right = styles[prefix + '-right' + suffix];
- if (!right) {
- return;
- }
- const bottom = styles[prefix + '-bottom' + suffix];
- if (!bottom) {
- return;
- }
- const left = styles[prefix + '-left' + suffix];
- if (!left) {
- return;
- }
- const box = [
- top,
- right,
- bottom,
- left
- ];
- i = box.length - 1;
- while (i--) {
- if (box[i] !== box[i + 1]) {
- break;
- }
- }
- if (i > -1 && noJoin) {
- return;
- }
- styles[prefix + suffix] = i === -1 ? box[0] : box.join(' ');
- delete styles[prefix + '-top' + suffix];
- delete styles[prefix + '-right' + suffix];
- delete styles[prefix + '-bottom' + suffix];
- delete styles[prefix + '-left' + suffix];
- };
- const canCompress = key => {
- let value = styles[key], i;
- if (!value) {
- return;
- }
- value = value.split(' ');
- i = value.length;
- while (i--) {
- if (value[i] !== value[0]) {
- return false;
- }
- }
- styles[key] = value[0];
- return true;
- };
- const compress2 = (target, a, b, c) => {
- if (!canCompress(a)) {
- return;
- }
- if (!canCompress(b)) {
- return;
- }
- if (!canCompress(c)) {
- return;
- }
- styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
- delete styles[a];
- delete styles[b];
- delete styles[c];
- };
- const encode = str => {
- isEncoded = true;
- return encodingLookup[str];
- };
- const decode = (str, keepSlashes) => {
- if (isEncoded) {
- str = str.replace(/\uFEFF[0-9]/g, str => {
- return encodingLookup[str];
- });
- }
- if (!keepSlashes) {
- str = str.replace(/\\([\'\";:])/g, '$1');
- }
- return str;
- };
- const decodeSingleHexSequence = escSeq => {
- return String.fromCharCode(parseInt(escSeq.slice(1), 16));
- };
- const decodeHexSequences = value => {
- return value.replace(/\\[0-9a-f]+/gi, decodeSingleHexSequence);
- };
- const processUrl = (match, url, url2, url3, str, str2) => {
- str = str || str2;
- if (str) {
- str = decode(str);
- return `'` + str.replace(/\'/g, `\\'`) + `'`;
- }
- url = decode(url || url2 || url3);
- if (!settings.allow_script_urls) {
- const scriptUrl = url.replace(/[\s\r\n]+/g, '');
- if (/(java|vb)script:/i.test(scriptUrl)) {
- return '';
- }
- if (!settings.allow_svg_data_urls && /^data:image\/svg/i.test(scriptUrl)) {
- return '';
- }
- }
- if (urlConverter) {
- url = urlConverter.call(urlConverterScope, url, 'style');
- }
- return `url('` + url.replace(/\'/g, `\\'`) + `')`;
- };
- if (css) {
- css = css.replace(/[\u0000-\u001F]/g, '');
- css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, str => {
- return str.replace(/[;:]/g, encode);
- });
- while (matches = styleRegExp.exec(css)) {
- styleRegExp.lastIndex = matches.index + matches[0].length;
- name = matches[1].replace(trimRightRegExp, '').toLowerCase();
- value = matches[2].replace(trimRightRegExp, '');
- if (name && value) {
- name = decodeHexSequences(name);
- value = decodeHexSequences(value);
- if (name.indexOf(invisibleChar) !== -1 || name.indexOf('"') !== -1) {
- continue;
- }
- if (!settings.allow_script_urls && (name === 'behavior' || /expression\s*\(|\/\*|\*\//.test(value))) {
- continue;
- }
- if (name === 'font-weight' && value === '700') {
- value = 'bold';
- } else if (name === 'color' || name === 'background-color') {
- value = value.toLowerCase();
- }
- value = value.replace(urlOrStrRegExp, processUrl);
- styles[name] = isEncoded ? decode(value, true) : value;
- }
- }
- compress('border', '', true);
- compress('border', '-width');
- compress('border', '-color');
- compress('border', '-style');
- compress('padding', '');
- compress('margin', '');
- compress2('border', 'border-width', 'border-style', 'border-color');
- if (styles.border === 'medium none') {
- delete styles.border;
- }
- if (styles['border-image'] === 'none') {
- delete styles['border-image'];
- }
- }
- return styles;
- },
- serialize: (styles, elementName) => {
- let css = '';
- const serializeStyles = name => {
- let value;
- const styleList = validStyles[name];
- if (styleList) {
- for (let i = 0, l = styleList.length; i < l; i++) {
- name = styleList[i];
- value = styles[name];
- if (value) {
- css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
- }
- }
- }
- };
- const isValid = (name, elementName) => {
- let styleMap = invalidStyles['*'];
- if (styleMap && styleMap[name]) {
- return false;
- }
- styleMap = invalidStyles[elementName];
- return !(styleMap && styleMap[name]);
- };
- if (elementName && validStyles) {
- serializeStyles('*');
- serializeStyles(elementName);
- } else {
- each$e(styles, (value, name) => {
- if (value && (!invalidStyles || isValid(name, elementName))) {
- css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
- }
- });
- }
- return css;
- }
- };
- return self;
- };
- const deprecated = {
- keyLocation: true,
- layerX: true,
- layerY: true,
- returnValue: true,
- webkitMovementX: true,
- webkitMovementY: true,
- keyIdentifier: true,
- mozPressure: true
- };
- const isNativeEvent = event => event instanceof Event || isFunction(event.initEvent);
- const hasIsDefaultPrevented = event => event.isDefaultPrevented === always || event.isDefaultPrevented === never;
- const needsNormalizing = event => isNullable(event.preventDefault) || isNativeEvent(event);
- const clone$3 = (originalEvent, data) => {
- const event = data !== null && data !== void 0 ? data : {};
- for (const name in originalEvent) {
- if (!has$2(deprecated, name)) {
- event[name] = originalEvent[name];
- }
- }
- if (isNonNullable(event.composedPath)) {
- event.composedPath = () => originalEvent.composedPath();
- }
- return event;
- };
- const normalize$3 = (type, originalEvent, fallbackTarget, data) => {
- var _a;
- const event = clone$3(originalEvent, data);
- event.type = type;
- if (isNullable(event.target)) {
- event.target = (_a = event.srcElement) !== null && _a !== void 0 ? _a : fallbackTarget;
- }
- if (needsNormalizing(originalEvent)) {
- event.preventDefault = () => {
- event.defaultPrevented = true;
- event.isDefaultPrevented = always;
- if (isFunction(originalEvent.preventDefault)) {
- originalEvent.preventDefault();
- }
- };
- event.stopPropagation = () => {
- event.cancelBubble = true;
- event.isPropagationStopped = always;
- if (isFunction(originalEvent.stopPropagation)) {
- originalEvent.stopPropagation();
- }
- };
- event.stopImmediatePropagation = () => {
- event.isImmediatePropagationStopped = always;
- event.stopPropagation();
- };
- if (!hasIsDefaultPrevented(event)) {
- event.isDefaultPrevented = event.defaultPrevented === true ? always : never;
- event.isPropagationStopped = event.cancelBubble === true ? always : never;
- event.isImmediatePropagationStopped = never;
- }
- }
- return event;
- };
- const eventExpandoPrefix = 'mce-data-';
- const mouseEventRe = /^(?:mouse|contextmenu)|click/;
- const addEvent = (target, name, callback, capture) => {
- if (target.addEventListener) {
- target.addEventListener(name, callback, capture || false);
- } else if (target.attachEvent) {
- target.attachEvent('on' + name, callback);
- }
- };
- const removeEvent = (target, name, callback, capture) => {
- if (target.removeEventListener) {
- target.removeEventListener(name, callback, capture || false);
- } else if (target.detachEvent) {
- target.detachEvent('on' + name, callback);
- }
- };
- const isMouseEvent = event => isNonNullable(event) && mouseEventRe.test(event.type);
- const fix = (originalEvent, data) => {
- const event = normalize$3(originalEvent.type, originalEvent, document, data);
- if (isMouseEvent(originalEvent) && isUndefined(originalEvent.pageX) && !isUndefined(originalEvent.clientX)) {
- const eventDoc = event.target.ownerDocument || document;
- const doc = eventDoc.documentElement;
- const body = eventDoc.body;
- const mouseEvent = event;
- mouseEvent.pageX = originalEvent.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
- mouseEvent.pageY = originalEvent.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
- }
- return event;
- };
- const bindOnReady = (win, callback, eventUtils) => {
- const doc = win.document, event = { type: 'ready' };
- if (eventUtils.domLoaded) {
- callback(event);
- return;
- }
- const isDocReady = () => {
- return doc.readyState === 'complete' || doc.readyState === 'interactive' && doc.body;
- };
- const readyHandler = () => {
- removeEvent(win, 'DOMContentLoaded', readyHandler);
- removeEvent(win, 'load', readyHandler);
- if (!eventUtils.domLoaded) {
- eventUtils.domLoaded = true;
- callback(event);
- }
- win = null;
- };
- if (isDocReady()) {
- readyHandler();
- } else {
- addEvent(win, 'DOMContentLoaded', readyHandler);
- }
- if (!eventUtils.domLoaded) {
- addEvent(win, 'load', readyHandler);
- }
- };
- class EventUtils {
- constructor() {
- this.domLoaded = false;
- this.events = {};
- this.count = 1;
- this.expando = eventExpandoPrefix + (+new Date()).toString(32);
- this.hasMouseEnterLeave = 'onmouseenter' in document.documentElement;
- this.hasFocusIn = 'onfocusin' in document.documentElement;
- this.count = 1;
- }
- bind(target, names, callback, scope) {
- const self = this;
- let id, callbackList, i, name, fakeName, nativeHandler, capture;
- const win = window;
- const defaultNativeHandler = evt => {
- self.executeHandlers(fix(evt || win.event), id);
- };
- if (!target || target.nodeType === 3 || target.nodeType === 8) {
- return;
- }
- if (!target[self.expando]) {
- id = self.count++;
- target[self.expando] = id;
- self.events[id] = {};
- } else {
- id = target[self.expando];
- }
- scope = scope || target;
- const namesList = names.split(' ');
- i = namesList.length;
- while (i--) {
- name = namesList[i];
- nativeHandler = defaultNativeHandler;
- fakeName = capture = false;
- if (name === 'DOMContentLoaded') {
- name = 'ready';
- }
- if (self.domLoaded && name === 'ready' && target.readyState === 'complete') {
- callback.call(scope, fix({ type: name }));
- continue;
- }
- if (!self.hasMouseEnterLeave) {
- fakeName = self.mouseEnterLeave[name];
- if (fakeName) {
- nativeHandler = evt => {
- const current = evt.currentTarget;
- let related = evt.relatedTarget;
- if (related && current.contains) {
- related = current.contains(related);
- } else {
- while (related && related !== current) {
- related = related.parentNode;
- }
- }
- if (!related) {
- evt = fix(evt || win.event);
- evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
- evt.target = current;
- self.executeHandlers(evt, id);
- }
- };
- }
- }
- if (!self.hasFocusIn && (name === 'focusin' || name === 'focusout')) {
- capture = true;
- fakeName = name === 'focusin' ? 'focus' : 'blur';
- nativeHandler = evt => {
- evt = fix(evt || win.event);
- evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
- self.executeHandlers(evt, id);
- };
- }
- callbackList = self.events[id][name];
- if (!callbackList) {
- self.events[id][name] = callbackList = [{
- func: callback,
- scope
- }];
- callbackList.fakeName = fakeName;
- callbackList.capture = capture;
- callbackList.nativeHandler = nativeHandler;
- if (name === 'ready') {
- bindOnReady(target, nativeHandler, self);
- } else {
- addEvent(target, fakeName || name, nativeHandler, capture);
- }
- } else {
- if (name === 'ready' && self.domLoaded) {
- callback(fix({ type: name }));
- } else {
- callbackList.push({
- func: callback,
- scope
- });
- }
- }
- }
- target = callbackList = null;
- return callback;
- }
- unbind(target, names, callback) {
- let callbackList, i, ci, name, eventMap;
- if (!target || target.nodeType === 3 || target.nodeType === 8) {
- return this;
- }
- const id = target[this.expando];
- if (id) {
- eventMap = this.events[id];
- if (names) {
- const namesList = names.split(' ');
- i = namesList.length;
- while (i--) {
- name = namesList[i];
- callbackList = eventMap[name];
- if (callbackList) {
- if (callback) {
- ci = callbackList.length;
- while (ci--) {
- if (callbackList[ci].func === callback) {
- const nativeHandler = callbackList.nativeHandler;
- const fakeName = callbackList.fakeName, capture = callbackList.capture;
- callbackList = callbackList.slice(0, ci).concat(callbackList.slice(ci + 1));
- callbackList.nativeHandler = nativeHandler;
- callbackList.fakeName = fakeName;
- callbackList.capture = capture;
- eventMap[name] = callbackList;
- }
- }
- }
- if (!callback || callbackList.length === 0) {
- delete eventMap[name];
- removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
- }
- }
- }
- } else {
- each$e(eventMap, (callbackList, name) => {
- removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
- });
- eventMap = {};
- }
- for (name in eventMap) {
- if (has$2(eventMap, name)) {
- return this;
- }
- }
- delete this.events[id];
- try {
- delete target[this.expando];
- } catch (ex) {
- target[this.expando] = null;
- }
- }
- return this;
- }
- fire(target, name, args) {
- return this.dispatch(target, name, args);
- }
- dispatch(target, name, args) {
- let id;
- if (!target || target.nodeType === 3 || target.nodeType === 8) {
- return this;
- }
- const event = fix({
- type: name,
- target
- }, args);
- do {
- id = target[this.expando];
- if (id) {
- this.executeHandlers(event, id);
- }
- target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
- } while (target && !event.isPropagationStopped());
- return this;
- }
- clean(target) {
- let i, children;
- if (!target || target.nodeType === 3 || target.nodeType === 8) {
- return this;
- }
- if (target[this.expando]) {
- this.unbind(target);
- }
- if (!target.getElementsByTagName) {
- target = target.document;
- }
- if (target && target.getElementsByTagName) {
- this.unbind(target);
- children = target.getElementsByTagName('*');
- i = children.length;
- while (i--) {
- target = children[i];
- if (target[this.expando]) {
- this.unbind(target);
- }
- }
- }
- return this;
- }
- destroy() {
- this.events = {};
- }
- cancel(e) {
- if (e) {
- e.preventDefault();
- e.stopImmediatePropagation();
- }
- return false;
- }
- executeHandlers(evt, id) {
- const container = this.events[id];
- const callbackList = container && container[evt.type];
- if (callbackList) {
- for (let i = 0, l = callbackList.length; i < l; i++) {
- const callback = callbackList[i];
- if (callback && callback.func.call(callback.scope, evt) === false) {
- evt.preventDefault();
- }
- if (evt.isImmediatePropagationStopped()) {
- return;
- }
- }
- }
- }
- }
- EventUtils.Event = new EventUtils();
- const each$b = Tools.each;
- const grep = Tools.grep;
- const internalStyleName = 'data-mce-style';
- const legacySetAttribute = (elm, name, value) => {
- if (isNullable(value) || value === '') {
- remove$b(elm, name);
- } else {
- set$2(elm, name, value);
- }
- };
- const setupAttrHooks = (styles, settings, getContext) => {
- const keepValues = settings.keep_values;
- const keepUrlHook = {
- set: (elm, value, name) => {
- const sugarElm = SugarElement.fromDom(elm);
- if (isFunction(settings.url_converter) && isNonNullable(value)) {
- value = settings.url_converter.call(settings.url_converter_scope || getContext(), value, name, elm[0]);
- }
- const internalName = 'data-mce-' + name;
- legacySetAttribute(sugarElm, internalName, value);
- legacySetAttribute(sugarElm, name, value);
- },
- get: (elm, name) => {
- const sugarElm = SugarElement.fromDom(elm);
- return get$9(sugarElm, 'data-mce-' + name) || get$9(sugarElm, name);
- }
- };
- const attrHooks = {
- style: {
- set: (elm, value) => {
- const sugarElm = SugarElement.fromDom(elm);
- if (isObject(value)) {
- setAll(sugarElm, value);
- return;
- }
- if (keepValues) {
- legacySetAttribute(sugarElm, internalStyleName, value);
- }
- remove$b(sugarElm, 'style');
- if (isString(value)) {
- setAll(sugarElm, styles.parse(value));
- }
- },
- get: elm => {
- const sugarElm = SugarElement.fromDom(elm);
- const value = get$9(sugarElm, internalStyleName) || get$9(sugarElm, 'style');
- return styles.serialize(styles.parse(value), name(sugarElm));
- }
- }
- };
- if (keepValues) {
- attrHooks.href = attrHooks.src = keepUrlHook;
- }
- return attrHooks;
- };
- const updateInternalStyleAttr = (styles, elm) => {
- const rawValue = get$9(elm, 'style');
- const value = styles.serialize(styles.parse(rawValue), name(elm));
- legacySetAttribute(elm, internalStyleName, value);
- };
- const findNodeIndex = (node, normalized) => {
- let idx = 0, lastNodeType, nodeType;
- if (node) {
- for (lastNodeType = node.nodeType, node = node.previousSibling; node; node = node.previousSibling) {
- nodeType = node.nodeType;
- if (normalized && nodeType === 3) {
- if (nodeType === lastNodeType || !node.nodeValue.length) {
- continue;
- }
- }
- idx++;
- lastNodeType = nodeType;
- }
- }
- return idx;
- };
- const numericalCssMap = Tools.makeMap('fill-opacity font-weight line-height opacity orphans widows z-index zoom', ' ');
- const camelCaseToHyphens = name => name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());
- const DOMUtils = (doc, settings = {}) => {
- const addedStyles = {};
- const win = window;
- const files = {};
- let counter = 0;
- const stdMode = true;
- const boxModel = true;
- const styleSheetLoader = instance.forElement(SugarElement.fromDom(doc), {
- contentCssCors: settings.contentCssCors,
- referrerPolicy: settings.referrerPolicy
- });
- const boundEvents = [];
- const schema = settings.schema ? settings.schema : Schema({});
- const styles = Styles({
- url_converter: settings.url_converter,
- url_converter_scope: settings.url_converter_scope
- }, settings.schema);
- const events = settings.ownEvents ? new EventUtils() : EventUtils.Event;
- const blockElementsMap = schema.getBlockElements();
- const isBlock = node => {
- if (isString(node)) {
- return has$2(blockElementsMap, node);
- } else {
- return isElement$6(node) && has$2(blockElementsMap, node.nodeName);
- }
- };
- const get = elm => elm && doc && isString(elm) ? doc.getElementById(elm) : elm;
- const _get = elm => {
- const value = get(elm);
- return isNonNullable(value) ? SugarElement.fromDom(value) : null;
- };
- const getAttrib = (elm, name, defaultVal) => {
- let value;
- const $elm = _get(elm);
- if (isNonNullable($elm) && isElement$7($elm)) {
- const hook = attrHooks[name];
- if (hook && hook.get) {
- value = hook.get($elm.dom, name);
- } else {
- value = get$9($elm, name);
- }
- }
- return isNonNullable(value) ? value : defaultVal !== null && defaultVal !== void 0 ? defaultVal : '';
- };
- const getAttribs = elm => {
- const node = get(elm);
- return isNullable(node) ? [] : node.attributes;
- };
- const setAttrib = (elm, name, value) => {
- run(elm, e => {
- if (isElement$6(e)) {
- const $elm = SugarElement.fromDom(e);
- if (value === '') {
- value = null;
- }
- const originalValue = get$9($elm, name);
- const hook = attrHooks[name];
- if (hook && hook.set) {
- hook.set($elm.dom, value, name);
- } else {
- legacySetAttribute($elm, name, value);
- }
- if (originalValue !== value && settings.onSetAttrib) {
- settings.onSetAttrib({
- attrElm: $elm,
- attrName: name,
- attrValue: value
- });
- }
- }
- });
- };
- const clone = (node, deep) => {
- return node.cloneNode(deep);
- };
- const getRoot = () => settings.root_element || doc.body;
- const getViewPort = argWin => {
- const vp = getBounds(argWin);
- return {
- x: vp.x,
- y: vp.y,
- w: vp.width,
- h: vp.height
- };
- };
- const getPos$1 = (elm, rootElm) => getPos(doc.body, get(elm), rootElm);
- const setStyle = (elm, name, value) => {
- const convertStyleToString = (cssValue, cssName) => {
- if (isString(cssValue)) {
- return cssValue;
- } else if (isNumber(cssValue)) {
- return has$2(numericalCssMap, cssName) ? cssValue + '' : cssValue + 'px';
- } else {
- return map$2(cssValue, convertStyleToString);
- }
- };
- const applyStyle = ($elm, cssName, cssValue) => {
- const normalizedName = camelCaseToHyphens(cssName);
- if (isNullable(cssValue) || cssValue === '') {
- remove$7($elm, normalizedName);
- } else {
- set$1($elm, normalizedName, convertStyleToString(cssValue, normalizedName));
- }
- };
- run(elm, e => {
- const $elm = SugarElement.fromDom(e);
- if (isString(name)) {
- applyStyle($elm, name, value);
- } else {
- each$e(name, (v, n) => {
- applyStyle($elm, n, v);
- });
- }
- if (settings.update_styles) {
- updateInternalStyleAttr(styles, $elm);
- }
- });
- };
- const setStyles = (elm, stylesArg) => {
- setStyle(elm, stylesArg);
- };
- const getStyle = (elm, name, computed) => {
- const $elm = get(elm);
- if (isNullable($elm) || !isElement$6($elm)) {
- return undefined;
- }
- if (computed) {
- return get$7(SugarElement.fromDom($elm), camelCaseToHyphens(name));
- } else {
- name = name.replace(/-(\D)/g, (a, b) => b.toUpperCase());
- if (name === 'float') {
- name = 'cssFloat';
- }
- return $elm.style ? $elm.style[name] : undefined;
- }
- };
- const getSize = elm => {
- let w, h;
- const $elm = get(elm);
- w = getStyle($elm, 'width');
- h = getStyle($elm, 'height');
- if (w.indexOf('px') === -1) {
- w = 0;
- }
- if (h.indexOf('px') === -1) {
- h = 0;
- }
- return {
- w: parseInt(w, 10) || $elm.offsetWidth || $elm.clientWidth,
- h: parseInt(h, 10) || $elm.offsetHeight || $elm.clientHeight
- };
- };
- const getRect = elm => {
- const $elm = get(elm);
- const pos = getPos$1($elm);
- const size = getSize($elm);
- return {
- x: pos.x,
- y: pos.y,
- w: size.w,
- h: size.h
- };
- };
- const is = (elm, selector) => {
- if (!elm) {
- return false;
- }
- const elms = isArray$1(elm) ? elm : [elm];
- return exists(elms, e => {
- return is$1(SugarElement.fromDom(e), selector);
- });
- };
- const getParents = (elm, selector, root, collect) => {
- const result = [];
- let selectorVal;
- let node = get(elm);
- collect = collect === undefined;
- root = root || (getRoot().nodeName !== 'BODY' ? getRoot().parentNode : null);
- if (isString(selector)) {
- selectorVal = selector;
- if (selector === '*') {
- selector = isElement$6;
- } else {
- selector = node => is(node, selectorVal);
- }
- }
- while (node) {
- if (node === root || isNullable(node.nodeType) || isDocument$1(node) || isDocumentFragment(node)) {
- break;
- }
- if (!selector || selector(node)) {
- if (collect) {
- result.push(node);
- } else {
- return [node];
- }
- }
- node = node.parentNode;
- }
- return collect ? result : null;
- };
- const getParent = (node, selector, root) => {
- const parents = getParents(node, selector, root, false);
- return parents && parents.length > 0 ? parents[0] : null;
- };
- const _findSib = (node, selector, name) => {
- let func = selector;
- if (node) {
- if (isString(selector)) {
- func = node => {
- return is(node, selector);
- };
- }
- for (node = node[name]; node; node = node[name]) {
- if (isFunction(func) && func(node)) {
- return node;
- }
- }
- }
- return null;
- };
- const getNext = (node, selector) => _findSib(node, selector, 'nextSibling');
- const getPrev = (node, selector) => _findSib(node, selector, 'previousSibling');
- const select = (selector, scope) => {
- var _a, _b;
- const elm = (_b = (_a = get(scope)) !== null && _a !== void 0 ? _a : settings.root_element) !== null && _b !== void 0 ? _b : doc;
- return from(elm.querySelectorAll(selector));
- };
- const run = function (elm, func, scope) {
- const context = scope !== null && scope !== void 0 ? scope : this;
- const node = isString(elm) ? get(elm) : elm;
- if (!node) {
- return false;
- }
- if (isArray$1(node) && (node.length || node.length === 0)) {
- const result = [];
- each$b(node, (elm, i) => {
- if (elm) {
- result.push(func.call(context, isString(elm) ? get(elm) : elm, i));
- }
- });
- return result;
- } else {
- return func.call(context, node);
- }
- };
- const setAttribs = (elm, attrs) => {
- run(elm, $elm => {
- each$e(attrs, (value, name) => {
- setAttrib($elm, name, value);
- });
- });
- };
- const setHTML = (elm, html) => {
- run(elm, e => {
- const $elm = SugarElement.fromDom(e);
- set($elm, html);
- });
- };
- const add = (parentElm, name, attrs, html, create) => run(parentElm, parentElm => {
- const newElm = isString(name) ? doc.createElement(name) : name;
- if (isNonNullable(attrs)) {
- setAttribs(newElm, attrs);
- }
- if (html) {
- if (!isString(html) && html.nodeType) {
- newElm.appendChild(html);
- } else if (isString(html)) {
- setHTML(newElm, html);
- }
- }
- return !create ? parentElm.appendChild(newElm) : newElm;
- });
- const create = (name, attrs, html) => add(doc.createElement(name), name, attrs, html, true);
- const decode = Entities.decode;
- const encode = Entities.encodeAllRaw;
- const createHTML = (name, attrs, html = '') => {
- let outHtml = '', key;
- outHtml += '<' + name;
- for (key in attrs) {
- if (hasNonNullableKey(attrs, key)) {
- outHtml += ' ' + key + '="' + encode(attrs[key]) + '"';
- }
- }
- if (isEmpty$3(html) && has$2(schema.getVoidElements(), name)) {
- return outHtml + ' />';
- } else {
- return outHtml + '>' + html + '</' + name + '>';
- }
- };
- const createFragment = html => {
- let node;
- const container = doc.createElement('div');
- const frag = doc.createDocumentFragment();
- frag.appendChild(container);
- if (html) {
- container.innerHTML = html;
- }
- while (node = container.firstChild) {
- frag.appendChild(node);
- }
- frag.removeChild(container);
- return frag;
- };
- const remove = (node, keepChildren) => {
- return run(node, n => {
- const $node = SugarElement.fromDom(n);
- if (keepChildren) {
- each$f(children($node), child => {
- if (isText$a(child) && child.dom.length === 0) {
- remove$6(child);
- } else {
- before$3($node, child);
- }
- });
- }
- remove$6($node);
- return $node.dom;
- });
- };
- const removeAllAttribs = e => run(e, e => {
- const attrs = e.attributes;
- for (let i = attrs.length - 1; i >= 0; i--) {
- e.removeAttributeNode(attrs.item(i));
- }
- });
- const parseStyle = cssText => styles.parse(cssText);
- const serializeStyle = (stylesArg, name) => styles.serialize(stylesArg, name);
- const addStyle = cssText => {
- let head, styleElm;
- if (self !== DOMUtils.DOM && doc === document) {
- if (addedStyles[cssText]) {
- return;
- }
- addedStyles[cssText] = true;
- }
- styleElm = doc.getElementById('mceDefaultStyles');
- if (!styleElm) {
- styleElm = doc.createElement('style');
- styleElm.id = 'mceDefaultStyles';
- styleElm.type = 'text/css';
- head = doc.getElementsByTagName('head')[0];
- if (head.firstChild) {
- head.insertBefore(styleElm, head.firstChild);
- } else {
- head.appendChild(styleElm);
- }
- }
- if (styleElm.styleSheet) {
- styleElm.styleSheet.cssText += cssText;
- } else {
- styleElm.appendChild(doc.createTextNode(cssText));
- }
- };
- const loadCSS = urls => {
- if (!urls) {
- urls = '';
- }
- each$f(urls.split(','), url => {
- files[url] = true;
- styleSheetLoader.load(url).catch(noop);
- });
- };
- const toggleClass = (elm, cls, state) => {
- run(elm, e => {
- if (isElement$6(e)) {
- const $elm = SugarElement.fromDom(e);
- const classes = cls.split(' ');
- each$f(classes, c => {
- if (isNonNullable(state)) {
- const fn = state ? add$2 : remove$8;
- fn($elm, c);
- } else {
- toggle$1($elm, c);
- }
- });
- }
- });
- };
- const addClass = (elm, cls) => {
- toggleClass(elm, cls, true);
- };
- const removeClass = (elm, cls) => {
- toggleClass(elm, cls, false);
- };
- const hasClass = (elm, cls) => {
- const $elm = _get(elm);
- const classes = cls.split(' ');
- return forall(classes, c => has($elm, c));
- };
- const show = elm => {
- run(elm, e => remove$7(SugarElement.fromDom(e), 'display'));
- };
- const hide = elm => {
- run(elm, e => set$1(SugarElement.fromDom(e), 'display', 'none'));
- };
- const isHidden = elm => {
- const $elm = _get(elm);
- return is$2(getRaw$1($elm, 'display'), 'none');
- };
- const uniqueId = prefix => (!prefix ? 'mce_' : prefix) + counter++;
- const getOuterHTML = elm => {
- const $elm = _get(elm);
- return isElement$6($elm.dom) ? $elm.dom.outerHTML : getOuter($elm);
- };
- const setOuterHTML = (elm, html) => {
- run(elm, $elm => {
- if (isElement$6($elm)) {
- $elm.outerHTML = html;
- }
- });
- };
- const insertAfter = (node, reference) => {
- const referenceNode = get(reference);
- return run(node, node => {
- const parent = referenceNode.parentNode;
- const nextSibling = referenceNode.nextSibling;
- if (nextSibling) {
- parent.insertBefore(node, nextSibling);
- } else {
- parent.appendChild(node);
- }
- return node;
- });
- };
- const replace = (newElm, oldElm, keepChildren) => run(oldElm, oldElm => {
- if (isArray$1(oldElm)) {
- newElm = newElm.cloneNode(true);
- }
- if (keepChildren) {
- each$b(grep(oldElm.childNodes), node => {
- newElm.appendChild(node);
- });
- }
- return oldElm.parentNode.replaceChild(newElm, oldElm);
- });
- const rename = (elm, name) => {
- let newElm;
- if (elm.nodeName !== name.toUpperCase()) {
- newElm = create(name);
- each$b(getAttribs(elm), attrNode => {
- setAttrib(newElm, attrNode.nodeName, getAttrib(elm, attrNode.nodeName));
- });
- replace(newElm, elm, true);
- }
- return newElm || elm;
- };
- const findCommonAncestor = (a, b) => {
- let ps = a, pe;
- while (ps) {
- pe = b;
- while (pe && ps !== pe) {
- pe = pe.parentNode;
- }
- if (ps === pe) {
- break;
- }
- ps = ps.parentNode;
- }
- if (!ps && a.ownerDocument) {
- return a.ownerDocument.documentElement;
- }
- return ps;
- };
- const isNonEmptyElement = node => {
- if (isElement$6(node)) {
- const isNamedAnchor = node.nodeName.toLowerCase() === 'a' && !getAttrib(node, 'href') && getAttrib(node, 'id');
- if (getAttrib(node, 'name') || getAttrib(node, 'data-mce-bookmark') || isNamedAnchor) {
- return true;
- }
- }
- return false;
- };
- const isEmpty = (node, elements) => {
- let type, name, brCount = 0;
- if (isNonEmptyElement(node)) {
- return false;
- }
- node = node.firstChild;
- if (node) {
- const walker = new DomTreeWalker(node, node.parentNode);
- const whitespace = schema ? schema.getWhitespaceElements() : {};
- elements = elements || (schema ? schema.getNonEmptyElements() : null);
- do {
- type = node.nodeType;
- if (isElement$6(node)) {
- const bogusVal = node.getAttribute('data-mce-bogus');
- if (bogusVal) {
- node = walker.next(bogusVal === 'all');
- continue;
- }
- name = node.nodeName.toLowerCase();
- if (elements && elements[name]) {
- if (name === 'br') {
- brCount++;
- node = walker.next();
- continue;
- }
- return false;
- }
- if (isNonEmptyElement(node)) {
- return false;
- }
- }
- if (type === 8) {
- return false;
- }
- if (type === 3 && !isWhitespaceText(node.nodeValue)) {
- return false;
- }
- if (type === 3 && node.parentNode && whitespace[node.parentNode.nodeName] && isWhitespaceText(node.nodeValue)) {
- return false;
- }
- node = walker.next();
- } while (node);
- }
- return brCount <= 1;
- };
- const createRng = () => doc.createRange();
- const split = (parentElm, splitElm, replacementElm) => {
- let range = createRng();
- let beforeFragment;
- let afterFragment;
- let parentNode;
- if (parentElm && splitElm) {
- range.setStart(parentElm.parentNode, findNodeIndex(parentElm));
- range.setEnd(splitElm.parentNode, findNodeIndex(splitElm));
- beforeFragment = range.extractContents();
- range = createRng();
- range.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1);
- range.setEnd(parentElm.parentNode, findNodeIndex(parentElm) + 1);
- afterFragment = range.extractContents();
- parentNode = parentElm.parentNode;
- parentNode.insertBefore(trimNode(self, beforeFragment), parentElm);
- if (replacementElm) {
- parentNode.insertBefore(replacementElm, parentElm);
- } else {
- parentNode.insertBefore(splitElm, parentElm);
- }
- parentNode.insertBefore(trimNode(self, afterFragment), parentElm);
- remove(parentElm);
- return replacementElm || splitElm;
- }
- };
- const bind = (target, name, func, scope) => {
- if (isArray$1(target)) {
- let i = target.length;
- const rv = [];
- while (i--) {
- rv[i] = bind(target[i], name, func, scope);
- }
- return rv;
- } else {
- if (settings.collect && (target === doc || target === win)) {
- boundEvents.push([
- target,
- name,
- func,
- scope
- ]);
- }
- return events.bind(target, name, func, scope || self);
- }
- };
- const unbind = (target, name, func) => {
- if (isArray$1(target)) {
- let i = target.length;
- const rv = [];
- while (i--) {
- rv[i] = unbind(target[i], name, func);
- }
- return rv;
- } else {
- if (boundEvents.length > 0 && (target === doc || target === win)) {
- let i = boundEvents.length;
- while (i--) {
- const item = boundEvents[i];
- if (target === item[0] && (!name || name === item[1]) && (!func || func === item[2])) {
- events.unbind(item[0], item[1], item[2]);
- }
- }
- }
- return events.unbind(target, name, func);
- }
- };
- const dispatch = (target, name, evt) => events.dispatch(target, name, evt);
- const fire = (target, name, evt) => events.dispatch(target, name, evt);
- const getContentEditable = node => {
- if (node && isElement$6(node)) {
- const contentEditable = node.getAttribute('data-mce-contenteditable');
- if (contentEditable && contentEditable !== 'inherit') {
- return contentEditable;
- }
- return node.contentEditable !== 'inherit' ? node.contentEditable : null;
- } else {
- return null;
- }
- };
- const getContentEditableParent = node => {
- const root = getRoot();
- let state = null;
- for (; node && node !== root; node = node.parentNode) {
- state = getContentEditable(node);
- if (state !== null) {
- break;
- }
- }
- return state;
- };
- const destroy = () => {
- if (boundEvents.length > 0) {
- let i = boundEvents.length;
- while (i--) {
- const item = boundEvents[i];
- events.unbind(item[0], item[1], item[2]);
- }
- }
- each$e(files, (_, url) => {
- styleSheetLoader.unload(url);
- delete files[url];
- });
- };
- const isChildOf = (node, parent) => {
- return node === parent || parent.contains(node);
- };
- const dumpRng = r => 'startContainer: ' + r.startContainer.nodeName + ', startOffset: ' + r.startOffset + ', endContainer: ' + r.endContainer.nodeName + ', endOffset: ' + r.endOffset;
- const self = {
- doc,
- settings,
- win,
- files,
- stdMode,
- boxModel,
- styleSheetLoader,
- boundEvents,
- styles,
- schema,
- events,
- isBlock,
- root: null,
- clone,
- getRoot,
- getViewPort,
- getRect,
- getSize,
- getParent,
- getParents,
- get,
- getNext,
- getPrev,
- select,
- is,
- add,
- create,
- createHTML,
- createFragment,
- remove,
- setStyle,
- getStyle,
- setStyles,
- removeAllAttribs,
- setAttrib,
- setAttribs,
- getAttrib,
- getPos: getPos$1,
- parseStyle,
- serializeStyle,
- addStyle,
- loadCSS,
- addClass,
- removeClass,
- hasClass,
- toggleClass,
- show,
- hide,
- isHidden,
- uniqueId,
- setHTML,
- getOuterHTML,
- setOuterHTML,
- decode,
- encode,
- insertAfter,
- replace,
- rename,
- findCommonAncestor,
- run,
- getAttribs,
- isEmpty,
- createRng,
- nodeIndex: findNodeIndex,
- split,
- bind: bind,
- unbind: unbind,
- fire,
- dispatch,
- getContentEditable,
- getContentEditableParent,
- destroy,
- isChildOf,
- dumpRng
- };
- const attrHooks = setupAttrHooks(styles, settings, constant(self));
- return self;
- };
- DOMUtils.DOM = DOMUtils(document);
- DOMUtils.nodeIndex = findNodeIndex;
- const DOM$b = DOMUtils.DOM;
- const QUEUED = 0;
- const LOADING = 1;
- const LOADED = 2;
- const FAILED = 3;
- class ScriptLoader {
- constructor(settings = {}) {
- this.states = {};
- this.queue = [];
- this.scriptLoadedCallbacks = {};
- this.queueLoadedCallbacks = [];
- this.loading = false;
- this.settings = settings;
- }
- _setReferrerPolicy(referrerPolicy) {
- this.settings.referrerPolicy = referrerPolicy;
- }
- loadScript(url) {
- return new Promise((resolve, reject) => {
- const dom = DOM$b;
- let elm;
- const cleanup = () => {
- dom.remove(id);
- if (elm) {
- elm.onerror = elm.onload = elm = null;
- }
- };
- const done = () => {
- cleanup();
- resolve();
- };
- const error = () => {
- cleanup();
- reject('Failed to load script: ' + url);
- };
- const id = dom.uniqueId();
- elm = document.createElement('script');
- elm.id = id;
- elm.type = 'text/javascript';
- elm.src = Tools._addCacheSuffix(url);
- if (this.settings.referrerPolicy) {
- dom.setAttrib(elm, 'referrerpolicy', this.settings.referrerPolicy);
- }
- elm.onload = done;
- elm.onerror = error;
- (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
- });
- }
- isDone(url) {
- return this.states[url] === LOADED;
- }
- markDone(url) {
- this.states[url] = LOADED;
- }
- add(url) {
- const self = this;
- self.queue.push(url);
- const state = self.states[url];
- if (state === undefined) {
- self.states[url] = QUEUED;
- }
- return new Promise((resolve, reject) => {
- if (!self.scriptLoadedCallbacks[url]) {
- self.scriptLoadedCallbacks[url] = [];
- }
- self.scriptLoadedCallbacks[url].push({
- resolve,
- reject
- });
- });
- }
- load(url) {
- return this.add(url);
- }
- remove(url) {
- delete this.states[url];
- delete this.scriptLoadedCallbacks[url];
- }
- loadQueue() {
- const queue = this.queue;
- this.queue = [];
- return this.loadScripts(queue);
- }
- loadScripts(scripts) {
- const self = this;
- const execCallbacks = (name, url) => {
- get$a(self.scriptLoadedCallbacks, url).each(callbacks => {
- each$f(callbacks, callback => callback[name](url));
- });
- delete self.scriptLoadedCallbacks[url];
- };
- const processResults = results => {
- const failures = filter$6(results, result => result.status === 'rejected');
- if (failures.length > 0) {
- return Promise.reject(bind$3(failures, ({reason}) => isArray$1(reason) ? reason : [reason]));
- } else {
- return Promise.resolve();
- }
- };
- const load = urls => Promise.allSettled(map$3(urls, url => {
- if (self.states[url] === LOADED) {
- execCallbacks('resolve', url);
- return Promise.resolve();
- } else if (self.states[url] === FAILED) {
- execCallbacks('reject', url);
- return Promise.reject(url);
- } else {
- self.states[url] = LOADING;
- return self.loadScript(url).then(() => {
- self.states[url] = LOADED;
- execCallbacks('resolve', url);
- const queue = self.queue;
- if (queue.length > 0) {
- self.queue = [];
- return load(queue).then(processResults);
- }
- }, () => {
- self.states[url] = FAILED;
- execCallbacks('reject', url);
- return Promise.reject(url);
- });
- }
- }));
- const processQueue = urls => {
- self.loading = true;
- return load(urls).then(results => {
- self.loading = false;
- const nextQueuedItem = self.queueLoadedCallbacks.shift();
- Optional.from(nextQueuedItem).each(call);
- return processResults(results);
- });
- };
- const uniqueScripts = stringArray(scripts);
- if (self.loading) {
- return new Promise((resolve, reject) => {
- self.queueLoadedCallbacks.push(() => processQueue(uniqueScripts).then(resolve, reject));
- });
- } else {
- return processQueue(uniqueScripts);
- }
- }
- }
- ScriptLoader.ScriptLoader = new ScriptLoader();
- const Cell = initial => {
- let value = initial;
- const get = () => {
- return value;
- };
- const set = v => {
- value = v;
- };
- return {
- get,
- set
- };
- };
- const isRaw = str => isObject(str) && has$2(str, 'raw');
- const isTokenised = str => isArray$1(str) && str.length > 1;
- const data = {};
- const currentCode = Cell('en');
- const getLanguageData = () => get$a(data, currentCode.get());
- const getData$1 = () => map$2(data, value => ({ ...value }));
- const setCode = newCode => {
- if (newCode) {
- currentCode.set(newCode);
- }
- };
- const getCode = () => currentCode.get();
- const add$1 = (code, items) => {
- let langData = data[code];
- if (!langData) {
- data[code] = langData = {};
- }
- each$e(items, (translation, name) => {
- langData[name.toLowerCase()] = translation;
- });
- };
- const translate = text => {
- const langData = getLanguageData().getOr({});
- const toString = obj => {
- if (isFunction(obj)) {
- return Object.prototype.toString.call(obj);
- }
- return !isEmpty(obj) ? '' + obj : '';
- };
- const isEmpty = text => text === '' || text === null || text === undefined;
- const getLangData = text => {
- const textstr = toString(text);
- return get$a(langData, textstr.toLowerCase()).map(toString).getOr(textstr);
- };
- const removeContext = str => str.replace(/{context:\w+}$/, '');
- if (isEmpty(text)) {
- return '';
- }
- if (isRaw(text)) {
- return toString(text.raw);
- }
- if (isTokenised(text)) {
- const values = text.slice(1);
- const substitued = getLangData(text[0]).replace(/\{([0-9]+)\}/g, ($1, $2) => has$2(values, $2) ? toString(values[$2]) : $1);
- return removeContext(substitued);
- }
- return removeContext(getLangData(text));
- };
- const isRtl$1 = () => getLanguageData().bind(items => get$a(items, '_dir')).exists(dir => dir === 'rtl');
- const hasCode = code => has$2(data, code);
- const I18n = {
- getData: getData$1,
- setCode,
- getCode,
- add: add$1,
- translate,
- isRtl: isRtl$1,
- hasCode
- };
- const AddOnManager = () => {
- const items = [];
- const urls = {};
- const lookup = {};
- const _listeners = [];
- const runListeners = (name, state) => {
- const matchedListeners = filter$6(_listeners, listener => listener.name === name && listener.state === state);
- each$f(matchedListeners, listener => listener.resolve());
- };
- const isLoaded = name => has$2(urls, name);
- const isAdded = name => has$2(lookup, name);
- const get = name => {
- if (lookup[name]) {
- return lookup[name].instance;
- }
- return undefined;
- };
- const loadLanguagePack = (name, languages) => {
- const language = I18n.getCode();
- const wrappedLanguages = ',' + (languages || '') + ',';
- if (!language || languages && wrappedLanguages.indexOf(',' + language + ',') === -1) {
- return;
- }
- ScriptLoader.ScriptLoader.add(urls[name] + '/langs/' + language + '.js');
- };
- const requireLangPack = (name, languages) => {
- if (AddOnManager.languageLoad !== false) {
- if (isLoaded(name)) {
- loadLanguagePack(name, languages);
- } else {
- waitFor(name, 'loaded').then(() => loadLanguagePack(name, languages));
- }
- }
- };
- const add = (id, addOn) => {
- items.push(addOn);
- lookup[id] = { instance: addOn };
- runListeners(id, 'added');
- return addOn;
- };
- const remove = name => {
- delete urls[name];
- delete lookup[name];
- };
- const createUrl = (baseUrl, dep) => {
- if (isString(dep)) {
- return isString(baseUrl) ? {
- prefix: '',
- resource: dep,
- suffix: ''
- } : {
- prefix: baseUrl.prefix,
- resource: dep,
- suffix: baseUrl.suffix
- };
- } else {
- return dep;
- }
- };
- const load = (name, addOnUrl) => {
- if (urls[name]) {
- return Promise.resolve();
- }
- let urlString = isString(addOnUrl) ? addOnUrl : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix;
- if (urlString.indexOf('/') !== 0 && urlString.indexOf('://') === -1) {
- urlString = AddOnManager.baseURL + '/' + urlString;
- }
- urls[name] = urlString.substring(0, urlString.lastIndexOf('/'));
- const done = () => {
- runListeners(name, 'loaded');
- return Promise.resolve();
- };
- if (lookup[name]) {
- return done();
- } else {
- return ScriptLoader.ScriptLoader.add(urlString).then(done);
- }
- };
- const waitFor = (name, state = 'added') => {
- if (state === 'added' && isAdded(name)) {
- return Promise.resolve();
- } else if (state === 'loaded' && isLoaded(name)) {
- return Promise.resolve();
- } else {
- return new Promise(resolve => {
- _listeners.push({
- name,
- state,
- resolve
- });
- });
- }
- };
- return {
- items,
- urls,
- lookup,
- get,
- requireLangPack,
- add,
- remove,
- createUrl,
- load,
- waitFor
- };
- };
- AddOnManager.languageLoad = true;
- AddOnManager.baseURL = '';
- AddOnManager.PluginManager = AddOnManager();
- AddOnManager.ThemeManager = AddOnManager();
- AddOnManager.ModelManager = AddOnManager();
- const singleton = doRevoke => {
- const subject = Cell(Optional.none());
- const revoke = () => subject.get().each(doRevoke);
- const clear = () => {
- revoke();
- subject.set(Optional.none());
- };
- const isSet = () => subject.get().isSome();
- const get = () => subject.get();
- const set = s => {
- revoke();
- subject.set(Optional.some(s));
- };
- return {
- clear,
- isSet,
- get,
- set
- };
- };
- const value$2 = () => {
- const subject = singleton(noop);
- const on = f => subject.get().each(f);
- return {
- ...subject,
- on
- };
- };
- const first$1 = (fn, rate) => {
- let timer = null;
- const cancel = () => {
- if (!isNull(timer)) {
- clearTimeout(timer);
- timer = null;
- }
- };
- const throttle = (...args) => {
- if (isNull(timer)) {
- timer = setTimeout(() => {
- timer = null;
- fn.apply(null, args);
- }, rate);
- }
- };
- return {
- cancel,
- throttle
- };
- };
- const last$1 = (fn, rate) => {
- let timer = null;
- const cancel = () => {
- if (!isNull(timer)) {
- clearTimeout(timer);
- timer = null;
- }
- };
- const throttle = (...args) => {
- cancel();
- timer = setTimeout(() => {
- timer = null;
- fn.apply(null, args);
- }, rate);
- };
- return {
- cancel,
- throttle
- };
- };
- const descendants$1 = (scope, predicate) => {
- let result = [];
- each$f(children(scope), x => {
- if (predicate(x)) {
- result = result.concat([x]);
- }
- result = result.concat(descendants$1(x, predicate));
- });
- return result;
- };
- const descendants = (scope, selector) => all(selector, scope);
- const annotation = constant('mce-annotation');
- const dataAnnotation = constant('data-mce-annotation');
- const dataAnnotationId = constant('data-mce-annotation-uid');
- const dataAnnotationActive = constant('data-mce-annotation-active');
- const dataAnnotationClasses = constant('data-mce-annotation-classes');
- const dataAnnotationAttributes = constant('data-mce-annotation-attrs');
- const isRoot$1 = root => node => eq(node, root);
- const identify = (editor, annotationName) => {
- const rng = editor.selection.getRng();
- const start = SugarElement.fromDom(rng.startContainer);
- const root = SugarElement.fromDom(editor.getBody());
- const selector = annotationName.fold(() => '.' + annotation(), an => `[${ dataAnnotation() }="${ an }"]`);
- const newStart = child$1(start, rng.startOffset).getOr(start);
- const closest = closest$3(newStart, selector, isRoot$1(root));
- const getAttr = (c, property) => {
- if (has$1(c, property)) {
- return Optional.some(get$9(c, property));
- } else {
- return Optional.none();
- }
- };
- return closest.bind(c => getAttr(c, `${ dataAnnotationId() }`).bind(uid => getAttr(c, `${ dataAnnotation() }`).map(name => {
- const elements = findMarkers(editor, uid);
- return {
- uid,
- name,
- elements
- };
- })));
- };
- const isAnnotation = elem => isElement$7(elem) && has(elem, annotation());
- const isBogusElement = (elem, root) => has$1(elem, 'data-mce-bogus') || ancestor$1(elem, '[data-mce-bogus="all"]', isRoot$1(root));
- const findMarkers = (editor, uid) => {
- const body = SugarElement.fromDom(editor.getBody());
- const descendants$1 = descendants(body, `[${ dataAnnotationId() }="${ uid }"]`);
- return filter$6(descendants$1, descendant => !isBogusElement(descendant, body));
- };
- const findAll = (editor, name) => {
- const body = SugarElement.fromDom(editor.getBody());
- const markers = descendants(body, `[${ dataAnnotation() }="${ name }"]`);
- const directory = {};
- each$f(markers, m => {
- if (!isBogusElement(m, body)) {
- const uid = get$9(m, dataAnnotationId());
- const nodesAlready = get$a(directory, uid).getOr([]);
- directory[uid] = nodesAlready.concat([m]);
- }
- });
- return directory;
- };
- const setup$x = (editor, registry) => {
- const changeCallbacks = Cell({});
- const initData = () => ({
- listeners: [],
- previous: value$2()
- });
- const withCallbacks = (name, f) => {
- updateCallbacks(name, data => {
- f(data);
- return data;
- });
- };
- const updateCallbacks = (name, f) => {
- const callbackMap = changeCallbacks.get();
- const data = get$a(callbackMap, name).getOrThunk(initData);
- const outputData = f(data);
- callbackMap[name] = outputData;
- changeCallbacks.set(callbackMap);
- };
- const fireCallbacks = (name, uid, elements) => {
- withCallbacks(name, data => {
- each$f(data.listeners, f => f(true, name, {
- uid,
- nodes: map$3(elements, elem => elem.dom)
- }));
- });
- };
- const fireNoAnnotation = name => {
- withCallbacks(name, data => {
- each$f(data.listeners, f => f(false, name));
- });
- };
- const toggleActiveAttr = (uid, state) => {
- each$f(findMarkers(editor, uid), elem => {
- if (state) {
- set$2(elem, dataAnnotationActive(), 'true');
- } else {
- remove$b(elem, dataAnnotationActive());
- }
- });
- };
- const onNodeChange = last$1(() => {
- const annotations = sort(registry.getNames());
- each$f(annotations, name => {
- updateCallbacks(name, data => {
- const prev = data.previous.get();
- identify(editor, Optional.some(name)).fold(() => {
- prev.each(uid => {
- fireNoAnnotation(name);
- data.previous.clear();
- toggleActiveAttr(uid, false);
- });
- }, ({uid, name, elements}) => {
- if (!is$2(prev, uid)) {
- prev.each(uid => toggleActiveAttr(uid, false));
- fireCallbacks(name, uid, elements);
- data.previous.set(uid);
- toggleActiveAttr(uid, true);
- }
- });
- return {
- previous: data.previous,
- listeners: data.listeners
- };
- });
- });
- }, 30);
- editor.on('remove', () => {
- onNodeChange.cancel();
- });
- editor.on('NodeChange', () => {
- onNodeChange.throttle();
- });
- const addListener = (name, f) => {
- updateCallbacks(name, data => ({
- previous: data.previous,
- listeners: data.listeners.concat([f])
- }));
- };
- return { addListener };
- };
- const setup$w = (editor, registry) => {
- const dataAnnotation$1 = dataAnnotation();
- const identifyParserNode = node => Optional.from(node.attr(dataAnnotation$1)).bind(registry.lookup);
- const removeDirectAnnotation = node => {
- var _a, _b;
- node.attr(dataAnnotationId(), null);
- node.attr(dataAnnotation(), null);
- node.attr(dataAnnotationActive(), null);
- const customAttrNames = Optional.from(node.attr(dataAnnotationAttributes())).map(names => names.split(',')).getOr([]);
- const customClasses = Optional.from(node.attr(dataAnnotationClasses())).map(names => names.split(',')).getOr([]);
- each$f(customAttrNames, name => node.attr(name, null));
- const classList = (_b = (_a = node.attr('class')) === null || _a === void 0 ? void 0 : _a.split(' ')) !== null && _b !== void 0 ? _b : [];
- const newClassList = difference(classList, [annotation()].concat(customClasses));
- node.attr('class', newClassList.length > 0 ? newClassList.join(' ') : null);
- node.attr(dataAnnotationClasses(), null);
- node.attr(dataAnnotationAttributes(), null);
- };
- editor.serializer.addTempAttr(dataAnnotationActive());
- editor.serializer.addAttributeFilter(dataAnnotation$1, nodes => {
- for (const node of nodes) {
- identifyParserNode(node).each(settings => {
- if (settings.persistent === false) {
- if (node.name === 'span') {
- node.unwrap();
- } else {
- removeDirectAnnotation(node);
- }
- }
- });
- }
- });
- };
- const create$c = () => {
- const annotations = {};
- const register = (name, settings) => {
- annotations[name] = {
- name,
- settings
- };
- };
- const lookup = name => get$a(annotations, name).map(a => a.settings);
- const getNames = () => keys(annotations);
- return {
- register,
- lookup,
- getNames
- };
- };
- let unique = 0;
- const generate$1 = prefix => {
- const date = new Date();
- const time = date.getTime();
- const random = Math.floor(Math.random() * 1000000000);
- unique++;
- return prefix + '_' + random + unique + String(time);
- };
- const add = (element, classes) => {
- each$f(classes, x => {
- add$2(element, x);
- });
- };
- const remove$5 = (element, classes) => {
- each$f(classes, x => {
- remove$8(element, x);
- });
- };
- const clone$2 = (original, isDeep) => SugarElement.fromDom(original.dom.cloneNode(isDeep));
- const shallow$1 = original => clone$2(original, false);
- const deep$1 = original => clone$2(original, true);
- const shallowAs = (original, tag) => {
- const nu = SugarElement.fromTag(tag);
- const attributes = clone$4(original);
- setAll$1(nu, attributes);
- return nu;
- };
- const mutate = (original, tag) => {
- const nu = shallowAs(original, tag);
- after$4(original, nu);
- const children$1 = children(original);
- append(nu, children$1);
- remove$6(original);
- return nu;
- };
- const TextWalker = (startNode, rootNode, isBoundary = never) => {
- const walker = new DomTreeWalker(startNode, rootNode);
- const walk = direction => {
- let next;
- do {
- next = walker[direction]();
- } while (next && !isText$9(next) && !isBoundary(next));
- return Optional.from(next).filter(isText$9);
- };
- return {
- current: () => Optional.from(walker.current()).filter(isText$9),
- next: () => walk('next'),
- prev: () => walk('prev'),
- prev2: () => walk('prev2')
- };
- };
- const TextSeeker = (dom, isBoundary) => {
- const isBlockBoundary = isBoundary ? isBoundary : node => dom.isBlock(node) || isBr$6(node) || isContentEditableFalse$b(node);
- const walk = (node, offset, walker, process) => {
- if (isText$9(node)) {
- const newOffset = process(node, offset, node.data);
- if (newOffset !== -1) {
- return Optional.some({
- container: node,
- offset: newOffset
- });
- }
- }
- return walker().bind(next => walk(next.container, next.offset, walker, process));
- };
- const backwards = (node, offset, process, root) => {
- const walker = TextWalker(node, root, isBlockBoundary);
- return walk(node, offset, () => walker.prev().map(prev => ({
- container: prev,
- offset: prev.length
- })), process).getOrNull();
- };
- const forwards = (node, offset, process, root) => {
- const walker = TextWalker(node, root, isBlockBoundary);
- return walk(node, offset, () => walker.next().map(next => ({
- container: next,
- offset: 0
- })), process).getOrNull();
- };
- return {
- backwards,
- forwards
- };
- };
- const round$2 = Math.round;
- const clone$1 = rect => {
- if (!rect) {
- return {
- left: 0,
- top: 0,
- bottom: 0,
- right: 0,
- width: 0,
- height: 0
- };
- }
- return {
- left: round$2(rect.left),
- top: round$2(rect.top),
- bottom: round$2(rect.bottom),
- right: round$2(rect.right),
- width: round$2(rect.width),
- height: round$2(rect.height)
- };
- };
- const collapse = (rect, toStart) => {
- rect = clone$1(rect);
- if (toStart) {
- rect.right = rect.left;
- } else {
- rect.left = rect.left + rect.width;
- rect.right = rect.left;
- }
- rect.width = 0;
- return rect;
- };
- const isEqual = (rect1, rect2) => rect1.left === rect2.left && rect1.top === rect2.top && rect1.bottom === rect2.bottom && rect1.right === rect2.right;
- const isValidOverflow = (overflowY, rect1, rect2) => overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2;
- const isAbove$1 = (rect1, rect2) => {
- const halfHeight = Math.min(rect2.height / 2, rect1.height / 2);
- if (rect1.bottom - halfHeight < rect2.top) {
- return true;
- }
- if (rect1.top > rect2.bottom) {
- return false;
- }
- return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2);
- };
- const isBelow$1 = (rect1, rect2) => {
- if (rect1.top > rect2.bottom) {
- return true;
- }
- if (rect1.bottom < rect2.top) {
- return false;
- }
- return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2);
- };
- const containsXY = (rect, clientX, clientY) => clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
- const boundingClientRectFromRects = rects => {
- return foldl(rects, (acc, rect) => {
- return acc.fold(() => Optional.some(rect), prevRect => {
- const left = Math.min(rect.left, prevRect.left);
- const top = Math.min(rect.top, prevRect.top);
- const right = Math.max(rect.right, prevRect.right);
- const bottom = Math.max(rect.bottom, prevRect.bottom);
- return Optional.some({
- top,
- right,
- bottom,
- left,
- width: right - left,
- height: bottom - top
- });
- });
- }, Optional.none());
- };
- const distanceToRectEdgeFromXY = (rect, x, y) => {
- const cx = Math.max(Math.min(x, rect.left + rect.width), rect.left);
- const cy = Math.max(Math.min(y, rect.top + rect.height), rect.top);
- return Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
- };
- const overlapY = (r1, r2) => Math.max(0, Math.min(r1.bottom, r2.bottom) - Math.max(r1.top, r2.top));
- const clamp$2 = (value, min, max) => Math.min(Math.max(value, min), max);
- const getSelectedNode = range => {
- const startContainer = range.startContainer, startOffset = range.startOffset;
- if (startContainer === range.endContainer && startContainer.hasChildNodes() && range.endOffset === startOffset + 1) {
- return startContainer.childNodes[startOffset];
- }
- return null;
- };
- const getNode$1 = (container, offset) => {
- if (isElement$6(container) && container.hasChildNodes()) {
- const childNodes = container.childNodes;
- const safeOffset = clamp$2(offset, 0, childNodes.length - 1);
- return childNodes[safeOffset];
- } else {
- return container;
- }
- };
- const getNodeUnsafe = (container, offset) => {
- if (offset < 0 && isElement$6(container) && container.hasChildNodes()) {
- return undefined;
- } else {
- return getNode$1(container, offset);
- }
- };
- const extendingChars = new RegExp('[\u0300-\u036f\u0483-\u0487\u0488-\u0489\u0591-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u061a' + '\u064b-\u065f\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0' + '\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0902\u093a\u093c' + '\u0941-\u0948\u094d\u0951-\u0957\u0962-\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2-\u09e3' + '\u0a01-\u0a02\u0a3c\u0a41-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a51\u0a70-\u0a71\u0a75\u0a81-\u0a82\u0abc' + '\u0ac1-\u0ac5\u0ac7-\u0ac8\u0acd\u0ae2-\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57' + '\u0b62-\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c00\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56' + '\u0c62-\u0c63\u0c81\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc-\u0ccd\u0cd5-\u0cd6\u0ce2-\u0ce3\u0d01\u0d3e\u0d41-\u0d44' + '\u0d4d\u0d57\u0d62-\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9' + '\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86-\u0f87\u0f8d-\u0f97' + '\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039-\u103a\u103d-\u103e\u1058-\u1059\u105e-\u1060\u1071-\u1074' + '\u1082\u1085-\u1086\u108d\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b4-\u17b5' + '\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193b\u1a17-\u1a18' + '\u1a1b\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1ab0-\u1abd\u1ABE\u1b00-\u1b03\u1b34' + '\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80-\u1b81\u1ba2-\u1ba5\u1ba8-\u1ba9\u1bab-\u1bad\u1be6\u1be8-\u1be9' + '\u1bed\u1bef-\u1bf1\u1c2c-\u1c33\u1c36-\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1cf4\u1cf8-\u1cf9' + '\u1dc0-\u1df5\u1dfc-\u1dff\u200c-\u200d\u20d0-\u20dc\u20DD-\u20E0\u20e1\u20E2-\u20E4\u20e5-\u20f0\u2cef-\u2cf1' + '\u2d7f\u2de0-\u2dff\u302a-\u302d\u302e-\u302f\u3099-\u309a\ua66f\uA670-\uA672\ua674-\ua67d\ua69e-\ua69f\ua6f0-\ua6f1' + '\ua802\ua806\ua80b\ua825-\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc' + '\ua9e5\uaa29-\uaa2e\uaa31-\uaa32\uaa35-\uaa36\uaa43\uaa4c\uaa7c\uaab0\uaab2-\uaab4\uaab7-\uaab8\uaabe-\uaabf\uaac1' + '\uaaec-\uaaed\uaaf6\uabe5\uabe8\uabed\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\uff9e-\uff9f]');
- const isExtendingChar = ch => typeof ch === 'string' && ch.charCodeAt(0) >= 768 && extendingChars.test(ch);
- const or = (...args) => {
- return x => {
- for (let i = 0; i < args.length; i++) {
- if (args[i](x)) {
- return true;
- }
- }
- return false;
- };
- };
- const and = (...args) => {
- return x => {
- for (let i = 0; i < args.length; i++) {
- if (!args[i](x)) {
- return false;
- }
- }
- return true;
- };
- };
- const isElement$4 = isElement$6;
- const isCaretCandidate$2 = isCaretCandidate$3;
- const isBlock$1 = matchStyleValues('display', 'block table');
- const isFloated = matchStyleValues('float', 'left right');
- const isValidElementCaretCandidate = and(isElement$4, isCaretCandidate$2, not(isFloated));
- const isNotPre = not(matchStyleValues('white-space', 'pre pre-line pre-wrap'));
- const isText$6 = isText$9;
- const isBr$3 = isBr$6;
- const nodeIndex$1 = DOMUtils.nodeIndex;
- const resolveIndex$1 = getNodeUnsafe;
- const createRange$1 = doc => 'createRange' in doc ? doc.createRange() : DOMUtils.DOM.createRng();
- const isWhiteSpace$1 = chr => chr && /[\r\n\t ]/.test(chr);
- const isRange = rng => !!rng.setStart && !!rng.setEnd;
- const isHiddenWhiteSpaceRange = range => {
- const container = range.startContainer;
- const offset = range.startOffset;
- if (isWhiteSpace$1(range.toString()) && isNotPre(container.parentNode) && isText$9(container)) {
- const text = container.data;
- if (isWhiteSpace$1(text[offset - 1]) || isWhiteSpace$1(text[offset + 1])) {
- return true;
- }
- }
- return false;
- };
- const getBrClientRect = brNode => {
- const doc = brNode.ownerDocument;
- const rng = createRange$1(doc);
- const nbsp$1 = doc.createTextNode(nbsp);
- const parentNode = brNode.parentNode;
- parentNode.insertBefore(nbsp$1, brNode);
- rng.setStart(nbsp$1, 0);
- rng.setEnd(nbsp$1, 1);
- const clientRect = clone$1(rng.getBoundingClientRect());
- parentNode.removeChild(nbsp$1);
- return clientRect;
- };
- const getBoundingClientRectWebKitText = rng => {
- const sc = rng.startContainer;
- const ec = rng.endContainer;
- const so = rng.startOffset;
- const eo = rng.endOffset;
- if (sc === ec && isText$9(ec) && so === 0 && eo === 1) {
- const newRng = rng.cloneRange();
- newRng.setEndAfter(ec);
- return getBoundingClientRect$1(newRng);
- } else {
- return null;
- }
- };
- const isZeroRect = r => r.left === 0 && r.right === 0 && r.top === 0 && r.bottom === 0;
- const getBoundingClientRect$1 = item => {
- let clientRect;
- const clientRects = item.getClientRects();
- if (clientRects.length > 0) {
- clientRect = clone$1(clientRects[0]);
- } else {
- clientRect = clone$1(item.getBoundingClientRect());
- }
- if (!isRange(item) && isBr$3(item) && isZeroRect(clientRect)) {
- return getBrClientRect(item);
- }
- if (isZeroRect(clientRect) && isRange(item)) {
- return getBoundingClientRectWebKitText(item);
- }
- return clientRect;
- };
- const collapseAndInflateWidth = (clientRect, toStart) => {
- const newClientRect = collapse(clientRect, toStart);
- newClientRect.width = 1;
- newClientRect.right = newClientRect.left + 1;
- return newClientRect;
- };
- const getCaretPositionClientRects = caretPosition => {
- const clientRects = [];
- const addUniqueAndValidRect = clientRect => {
- if (clientRect.height === 0) {
- return;
- }
- if (clientRects.length > 0) {
- if (isEqual(clientRect, clientRects[clientRects.length - 1])) {
- return;
- }
- }
- clientRects.push(clientRect);
- };
- const addCharacterOffset = (container, offset) => {
- const range = createRange$1(container.ownerDocument);
- if (offset < container.data.length) {
- if (isExtendingChar(container.data[offset])) {
- return clientRects;
- }
- if (isExtendingChar(container.data[offset - 1])) {
- range.setStart(container, offset);
- range.setEnd(container, offset + 1);
- if (!isHiddenWhiteSpaceRange(range)) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), false));
- return clientRects;
- }
- }
- }
- if (offset > 0) {
- range.setStart(container, offset - 1);
- range.setEnd(container, offset);
- if (!isHiddenWhiteSpaceRange(range)) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), false));
- }
- }
- if (offset < container.data.length) {
- range.setStart(container, offset);
- range.setEnd(container, offset + 1);
- if (!isHiddenWhiteSpaceRange(range)) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), true));
- }
- }
- };
- const container = caretPosition.container();
- const offset = caretPosition.offset();
- if (isText$6(container)) {
- addCharacterOffset(container, offset);
- return clientRects;
- }
- if (isElement$4(container)) {
- if (caretPosition.isAtEnd()) {
- const node = resolveIndex$1(container, offset);
- if (isText$6(node)) {
- addCharacterOffset(node, node.data.length);
- }
- if (isValidElementCaretCandidate(node) && !isBr$3(node)) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false));
- }
- } else {
- const node = resolveIndex$1(container, offset);
- if (isText$6(node)) {
- addCharacterOffset(node, 0);
- }
- if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false));
- return clientRects;
- }
- const beforeNode = resolveIndex$1(caretPosition.container(), caretPosition.offset() - 1);
- if (isValidElementCaretCandidate(beforeNode) && !isBr$3(beforeNode)) {
- if (isBlock$1(beforeNode) || isBlock$1(node) || !isValidElementCaretCandidate(node)) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(beforeNode), false));
- }
- }
- if (isValidElementCaretCandidate(node)) {
- addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), true));
- }
- }
- }
- return clientRects;
- };
- const CaretPosition = (container, offset, clientRects) => {
- const isAtStart = () => {
- if (isText$6(container)) {
- return offset === 0;
- }
- return offset === 0;
- };
- const isAtEnd = () => {
- if (isText$6(container)) {
- return offset >= container.data.length;
- }
- return offset >= container.childNodes.length;
- };
- const toRange = () => {
- const range = createRange$1(container.ownerDocument);
- range.setStart(container, offset);
- range.setEnd(container, offset);
- return range;
- };
- const getClientRects = () => {
- if (!clientRects) {
- clientRects = getCaretPositionClientRects(CaretPosition(container, offset));
- }
- return clientRects;
- };
- const isVisible = () => getClientRects().length > 0;
- const isEqual = caretPosition => caretPosition && container === caretPosition.container() && offset === caretPosition.offset();
- const getNode = before => resolveIndex$1(container, before ? offset - 1 : offset);
- return {
- container: constant(container),
- offset: constant(offset),
- toRange,
- getClientRects,
- isVisible,
- isAtStart,
- isAtEnd,
- isEqual,
- getNode
- };
- };
- CaretPosition.fromRangeStart = range => CaretPosition(range.startContainer, range.startOffset);
- CaretPosition.fromRangeEnd = range => CaretPosition(range.endContainer, range.endOffset);
- CaretPosition.after = node => CaretPosition(node.parentNode, nodeIndex$1(node) + 1);
- CaretPosition.before = node => CaretPosition(node.parentNode, nodeIndex$1(node));
- CaretPosition.isAbove = (pos1, pos2) => lift2(head(pos2.getClientRects()), last$3(pos1.getClientRects()), isAbove$1).getOr(false);
- CaretPosition.isBelow = (pos1, pos2) => lift2(last$3(pos2.getClientRects()), head(pos1.getClientRects()), isBelow$1).getOr(false);
- CaretPosition.isAtStart = pos => pos ? pos.isAtStart() : false;
- CaretPosition.isAtEnd = pos => pos ? pos.isAtEnd() : false;
- CaretPosition.isTextPosition = pos => pos ? isText$9(pos.container()) : false;
- CaretPosition.isElementPosition = pos => CaretPosition.isTextPosition(pos) === false;
- const trimEmptyTextNode$1 = (dom, node) => {
- if (isText$9(node) && node.data.length === 0) {
- dom.remove(node);
- }
- };
- const insertNode = (dom, rng, node) => {
- rng.insertNode(node);
- trimEmptyTextNode$1(dom, node.previousSibling);
- trimEmptyTextNode$1(dom, node.nextSibling);
- };
- const insertFragment = (dom, rng, frag) => {
- const firstChild = Optional.from(frag.firstChild);
- const lastChild = Optional.from(frag.lastChild);
- rng.insertNode(frag);
- firstChild.each(child => trimEmptyTextNode$1(dom, child.previousSibling));
- lastChild.each(child => trimEmptyTextNode$1(dom, child.nextSibling));
- };
- const rangeInsertNode = (dom, rng, node) => {
- if (isDocumentFragment(node)) {
- insertFragment(dom, rng, node);
- } else {
- insertNode(dom, rng, node);
- }
- };
- const isText$5 = isText$9;
- const isBogus = isBogus$2;
- const nodeIndex = DOMUtils.nodeIndex;
- const normalizedParent = node => {
- const parentNode = node.parentNode;
- if (isBogus(parentNode)) {
- return normalizedParent(parentNode);
- }
- return parentNode;
- };
- const getChildNodes = node => {
- if (!node) {
- return [];
- }
- return reduce(node.childNodes, (result, node) => {
- if (isBogus(node) && node.nodeName !== 'BR') {
- result = result.concat(getChildNodes(node));
- } else {
- result.push(node);
- }
- return result;
- }, []);
- };
- const normalizedTextOffset = (node, offset) => {
- while (node = node.previousSibling) {
- if (!isText$5(node)) {
- break;
- }
- offset += node.data.length;
- }
- return offset;
- };
- const equal = a => b => a === b;
- const normalizedNodeIndex = node => {
- let nodes, index;
- nodes = getChildNodes(normalizedParent(node));
- index = findIndex$1(nodes, equal(node), node);
- nodes = nodes.slice(0, index + 1);
- const numTextFragments = reduce(nodes, (result, node, i) => {
- if (isText$5(node) && isText$5(nodes[i - 1])) {
- result++;
- }
- return result;
- }, 0);
- nodes = filter$4(nodes, matchNodeNames([node.nodeName]));
- index = findIndex$1(nodes, equal(node), node);
- return index - numTextFragments;
- };
- const createPathItem = node => {
- let name;
- if (isText$5(node)) {
- name = 'text()';
- } else {
- name = node.nodeName.toLowerCase();
- }
- return name + '[' + normalizedNodeIndex(node) + ']';
- };
- const parentsUntil$1 = (root, node, predicate) => {
- const parents = [];
- for (node = node.parentNode; node !== root; node = node.parentNode) {
- if (predicate && predicate(node)) {
- break;
- }
- parents.push(node);
- }
- return parents;
- };
- const create$b = (root, caretPosition) => {
- let container, offset, path = [], outputOffset, childNodes, parents;
- container = caretPosition.container();
- offset = caretPosition.offset();
- if (isText$5(container)) {
- outputOffset = normalizedTextOffset(container, offset);
- } else {
- childNodes = container.childNodes;
- if (offset >= childNodes.length) {
- outputOffset = 'after';
- offset = childNodes.length - 1;
- } else {
- outputOffset = 'before';
- }
- container = childNodes[offset];
- }
- path.push(createPathItem(container));
- parents = parentsUntil$1(root, container);
- parents = filter$4(parents, not(isBogus$2));
- path = path.concat(map$1(parents, node => {
- return createPathItem(node);
- }));
- return path.reverse().join('/') + ',' + outputOffset;
- };
- const resolvePathItem = (node, name, index) => {
- let nodes = getChildNodes(node);
- nodes = filter$4(nodes, (node, index) => {
- return !isText$5(node) || !isText$5(nodes[index - 1]);
- });
- nodes = filter$4(nodes, matchNodeNames([name]));
- return nodes[index];
- };
- const findTextPosition = (container, offset) => {
- let node = container, targetOffset = 0, dataLen;
- while (isText$5(node)) {
- dataLen = node.data.length;
- if (offset >= targetOffset && offset <= targetOffset + dataLen) {
- container = node;
- offset = offset - targetOffset;
- break;
- }
- if (!isText$5(node.nextSibling)) {
- container = node;
- offset = dataLen;
- break;
- }
- targetOffset += dataLen;
- node = node.nextSibling;
- }
- if (isText$5(container) && offset > container.data.length) {
- offset = container.data.length;
- }
- return CaretPosition(container, offset);
- };
- const resolve$1 = (root, path) => {
- let offset;
- if (!path) {
- return null;
- }
- const parts = path.split(',');
- const paths = parts[0].split('/');
- offset = parts.length > 1 ? parts[1] : 'before';
- const container = reduce(paths, (result, value) => {
- const match = /([\w\-\(\)]+)\[([0-9]+)\]/.exec(value);
- if (!match) {
- return null;
- }
- if (match[1] === 'text()') {
- match[1] = '#text';
- }
- return resolvePathItem(result, match[1], parseInt(match[2], 10));
- }, root);
- if (!container) {
- return null;
- }
- if (!isText$5(container)) {
- if (offset === 'after') {
- offset = nodeIndex(container) + 1;
- } else {
- offset = nodeIndex(container);
- }
- return CaretPosition(container.parentNode, offset);
- }
- return findTextPosition(container, parseInt(offset, 10));
- };
- const isContentEditableFalse$9 = isContentEditableFalse$b;
- const getNormalizedTextOffset = (trim, container, offset) => {
- let node, trimmedOffset;
- trimmedOffset = trim(container.data.slice(0, offset)).length;
- for (node = container.previousSibling; node && isText$9(node); node = node.previousSibling) {
- trimmedOffset += trim(node.data).length;
- }
- return trimmedOffset;
- };
- const getPoint = (dom, trim, normalized, rng, start) => {
- let container = rng[start ? 'startContainer' : 'endContainer'];
- let offset = rng[start ? 'startOffset' : 'endOffset'];
- const point = [];
- let childNodes, after = 0;
- const root = dom.getRoot();
- if (isText$9(container)) {
- point.push(normalized ? getNormalizedTextOffset(trim, container, offset) : offset);
- } else {
- childNodes = container.childNodes;
- if (offset >= childNodes.length && childNodes.length) {
- after = 1;
- offset = Math.max(0, childNodes.length - 1);
- }
- point.push(dom.nodeIndex(childNodes[offset], normalized) + after);
- }
- for (; container && container !== root; container = container.parentNode) {
- point.push(dom.nodeIndex(container, normalized));
- }
- return point;
- };
- const getLocation = (trim, selection, normalized, rng) => {
- const dom = selection.dom;
- const start = getPoint(dom, trim, normalized, rng, true);
- const forward = selection.isForward();
- const fakeCaret = isRangeInCaretContainerBlock(rng) ? { isFakeCaret: true } : {};
- if (!selection.isCollapsed()) {
- const end = getPoint(dom, trim, normalized, rng, false);
- return {
- start,
- end,
- forward,
- ...fakeCaret
- };
- } else {
- return {
- start,
- forward,
- ...fakeCaret
- };
- }
- };
- const findIndex = (dom, name, element) => {
- let count = 0;
- Tools.each(dom.select(name), node => {
- if (node.getAttribute('data-mce-bogus') === 'all') {
- return;
- }
- if (node === element) {
- return false;
- }
- count++;
- });
- return count;
- };
- const moveEndPoint$1 = (rng, start) => {
- let container, offset;
- const prefix = start ? 'start' : 'end';
- container = rng[prefix + 'Container'];
- offset = rng[prefix + 'Offset'];
- if (isElement$6(container) && container.nodeName === 'TR') {
- const childNodes = container.childNodes;
- container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
- if (container) {
- offset = start ? 0 : container.childNodes.length;
- rng['set' + (start ? 'Start' : 'End')](container, offset);
- }
- }
- };
- const normalizeTableCellSelection = rng => {
- moveEndPoint$1(rng, true);
- moveEndPoint$1(rng, false);
- return rng;
- };
- const findSibling = (node, offset) => {
- let sibling;
- if (isElement$6(node)) {
- node = getNode$1(node, offset);
- if (isContentEditableFalse$9(node)) {
- return node;
- }
- }
- if (isCaretContainer$2(node)) {
- if (isText$9(node) && isCaretContainerBlock$1(node)) {
- node = node.parentNode;
- }
- sibling = node.previousSibling;
- if (isContentEditableFalse$9(sibling)) {
- return sibling;
- }
- sibling = node.nextSibling;
- if (isContentEditableFalse$9(sibling)) {
- return sibling;
- }
- }
- };
- const findAdjacentContentEditableFalseElm = rng => {
- return findSibling(rng.startContainer, rng.startOffset) || findSibling(rng.endContainer, rng.endOffset);
- };
- const getOffsetBookmark = (trim, normalized, selection) => {
- const element = selection.getNode();
- let name = element ? element.nodeName : null;
- const rng = selection.getRng();
- if (isContentEditableFalse$9(element) || name === 'IMG') {
- return {
- name,
- index: findIndex(selection.dom, name, element)
- };
- }
- const sibling = findAdjacentContentEditableFalseElm(rng);
- if (sibling) {
- name = sibling.tagName;
- return {
- name,
- index: findIndex(selection.dom, name, sibling)
- };
- }
- return getLocation(trim, selection, normalized, rng);
- };
- const getCaretBookmark = selection => {
- const rng = selection.getRng();
- return {
- start: create$b(selection.dom.getRoot(), CaretPosition.fromRangeStart(rng)),
- end: create$b(selection.dom.getRoot(), CaretPosition.fromRangeEnd(rng)),
- forward: selection.isForward()
- };
- };
- const getRangeBookmark = selection => {
- return {
- rng: selection.getRng(),
- forward: selection.isForward()
- };
- };
- const createBookmarkSpan = (dom, id, filled) => {
- const args = {
- 'data-mce-type': 'bookmark',
- id,
- 'style': 'overflow:hidden;line-height:0px'
- };
- return filled ? dom.create('span', args, '') : dom.create('span', args);
- };
- const getPersistentBookmark = (selection, filled) => {
- const dom = selection.dom;
- let rng = selection.getRng();
- const id = dom.uniqueId();
- const collapsed = selection.isCollapsed();
- const element = selection.getNode();
- const name = element.nodeName;
- const forward = selection.isForward();
- if (name === 'IMG') {
- return {
- name,
- index: findIndex(dom, name, element)
- };
- }
- const rng2 = normalizeTableCellSelection(rng.cloneRange());
- if (!collapsed) {
- rng2.collapse(false);
- const endBookmarkNode = createBookmarkSpan(dom, id + '_end', filled);
- rangeInsertNode(dom, rng2, endBookmarkNode);
- }
- rng = normalizeTableCellSelection(rng);
- rng.collapse(true);
- const startBookmarkNode = createBookmarkSpan(dom, id + '_start', filled);
- rangeInsertNode(dom, rng, startBookmarkNode);
- selection.moveToBookmark({
- id,
- keep: true,
- forward
- });
- return {
- id,
- forward
- };
- };
- const getBookmark$2 = (selection, type, normalized) => {
- if (type === 2) {
- return getOffsetBookmark(trim$1, normalized, selection);
- } else if (type === 3) {
- return getCaretBookmark(selection);
- } else if (type) {
- return getRangeBookmark(selection);
- } else {
- return getPersistentBookmark(selection, false);
- }
- };
- const getUndoBookmark = curry(getOffsetBookmark, identity, true);
- const value$1 = value => {
- const applyHelper = fn => fn(value);
- const constHelper = constant(value);
- const outputHelper = () => output;
- const output = {
- tag: true,
- inner: value,
- fold: (_onError, onValue) => onValue(value),
- isValue: always,
- isError: never,
- map: mapper => Result.value(mapper(value)),
- mapError: outputHelper,
- bind: applyHelper,
- exists: applyHelper,
- forall: applyHelper,
- getOr: constHelper,
- or: outputHelper,
- getOrThunk: constHelper,
- orThunk: outputHelper,
- getOrDie: constHelper,
- each: fn => {
- fn(value);
- },
- toOptional: () => Optional.some(value)
- };
- return output;
- };
- const error = error => {
- const outputHelper = () => output;
- const output = {
- tag: false,
- inner: error,
- fold: (onError, _onValue) => onError(error),
- isValue: never,
- isError: always,
- map: outputHelper,
- mapError: mapper => Result.error(mapper(error)),
- bind: outputHelper,
- exists: never,
- forall: always,
- getOr: identity,
- or: identity,
- getOrThunk: apply$1,
- orThunk: apply$1,
- getOrDie: die(String(error)),
- each: noop,
- toOptional: Optional.none
- };
- return output;
- };
- const fromOption = (optional, err) => optional.fold(() => error(err), value$1);
- const Result = {
- value: value$1,
- error,
- fromOption
- };
- const generate = cases => {
- if (!isArray$1(cases)) {
- throw new Error('cases must be an array');
- }
- if (cases.length === 0) {
- throw new Error('there must be at least one case');
- }
- const constructors = [];
- const adt = {};
- each$f(cases, (acase, count) => {
- const keys$1 = keys(acase);
- if (keys$1.length !== 1) {
- throw new Error('one and only one name per case');
- }
- const key = keys$1[0];
- const value = acase[key];
- if (adt[key] !== undefined) {
- throw new Error('duplicate key detected:' + key);
- } else if (key === 'cata') {
- throw new Error('cannot have a case named cata (sorry)');
- } else if (!isArray$1(value)) {
- throw new Error('case arguments must be an array');
- }
- constructors.push(key);
- adt[key] = (...args) => {
- const argLength = args.length;
- if (argLength !== value.length) {
- throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
- }
- const match = branches => {
- const branchKeys = keys(branches);
- if (constructors.length !== branchKeys.length) {
- throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
- }
- const allReqd = forall(constructors, reqKey => {
- return contains$2(branchKeys, reqKey);
- });
- if (!allReqd) {
- throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
- }
- return branches[key].apply(null, args);
- };
- return {
- fold: (...foldArgs) => {
- if (foldArgs.length !== cases.length) {
- throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + foldArgs.length);
- }
- const target = foldArgs[count];
- return target.apply(null, args);
- },
- match,
- log: label => {
- console.log(label, {
- constructors,
- constructor: key,
- params: args
- });
- }
- };
- };
- });
- return adt;
- };
- const Adt = { generate };
- Adt.generate([
- {
- bothErrors: [
- 'error1',
- 'error2'
- ]
- },
- {
- firstError: [
- 'error1',
- 'value2'
- ]
- },
- {
- secondError: [
- 'value1',
- 'error2'
- ]
- },
- {
- bothValues: [
- 'value1',
- 'value2'
- ]
- }
- ]);
- const partition$1 = results => {
- const errors = [];
- const values = [];
- each$f(results, result => {
- result.fold(err => {
- errors.push(err);
- }, value => {
- values.push(value);
- });
- });
- return {
- errors,
- values
- };
- };
- const isInlinePattern = pattern => pattern.type === 'inline-command' || pattern.type === 'inline-format';
- const isBlockPattern = pattern => pattern.type === 'block-command' || pattern.type === 'block-format';
- const sortPatterns = patterns => sort(patterns, (a, b) => {
- if (a.start.length === b.start.length) {
- return 0;
- }
- return a.start.length > b.start.length ? -1 : 1;
- });
- const normalizePattern = pattern => {
- const err = message => Result.error({
- message,
- pattern
- });
- const formatOrCmd = (name, onFormat, onCommand) => {
- if (pattern.format !== undefined) {
- let formats;
- if (isArray$1(pattern.format)) {
- if (!forall(pattern.format, isString)) {
- return err(name + ' pattern has non-string items in the `format` array');
- }
- formats = pattern.format;
- } else if (isString(pattern.format)) {
- formats = [pattern.format];
- } else {
- return err(name + ' pattern has non-string `format` parameter');
- }
- return Result.value(onFormat(formats));
- } else if (pattern.cmd !== undefined) {
- if (!isString(pattern.cmd)) {
- return err(name + ' pattern has non-string `cmd` parameter');
- }
- return Result.value(onCommand(pattern.cmd, pattern.value));
- } else {
- return err(name + ' pattern is missing both `format` and `cmd` parameters');
- }
- };
- if (!isObject(pattern)) {
- return err('Raw pattern is not an object');
- }
- if (!isString(pattern.start)) {
- return err('Raw pattern is missing `start` parameter');
- }
- if (pattern.end !== undefined) {
- if (!isString(pattern.end)) {
- return err('Inline pattern has non-string `end` parameter');
- }
- if (pattern.start.length === 0 && pattern.end.length === 0) {
- return err('Inline pattern has empty `start` and `end` parameters');
- }
- let start = pattern.start;
- let end = pattern.end;
- if (end.length === 0) {
- end = start;
- start = '';
- }
- return formatOrCmd('Inline', format => ({
- type: 'inline-format',
- start,
- end,
- format
- }), (cmd, value) => ({
- type: 'inline-command',
- start,
- end,
- cmd,
- value
- }));
- } else if (pattern.replacement !== undefined) {
- if (!isString(pattern.replacement)) {
- return err('Replacement pattern has non-string `replacement` parameter');
- }
- if (pattern.start.length === 0) {
- return err('Replacement pattern has empty `start` parameter');
- }
- return Result.value({
- type: 'inline-command',
- start: '',
- end: pattern.start,
- cmd: 'mceInsertContent',
- value: pattern.replacement
- });
- } else {
- if (pattern.start.length === 0) {
- return err('Block pattern has empty `start` parameter');
- }
- return formatOrCmd('Block', formats => ({
- type: 'block-format',
- start: pattern.start,
- format: formats[0]
- }), (command, commandValue) => ({
- type: 'block-command',
- start: pattern.start,
- cmd: command,
- value: commandValue
- }));
- }
- };
- const getBlockPatterns = patterns => sortPatterns(filter$6(patterns, isBlockPattern));
- const getInlinePatterns = patterns => filter$6(patterns, isInlinePattern);
- const createPatternSet = patterns => ({
- inlinePatterns: getInlinePatterns(patterns),
- blockPatterns: getBlockPatterns(patterns)
- });
- const fromRawPatterns = patterns => {
- const normalized = partition$1(map$3(patterns, normalizePattern));
- each$f(normalized.errors, err => console.error(err.message, err.pattern));
- return normalized.values;
- };
- const deviceDetection$1 = detect$2().deviceType;
- const isTouch = deviceDetection$1.isTouch();
- const DOM$a = DOMUtils.DOM;
- const getHash = value => {
- const items = value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(',');
- return foldl(items, (output, item) => {
- const arr = item.split('=');
- const key = arr[0];
- const val = arr.length > 1 ? arr[1] : key;
- output[trim$3(key)] = trim$3(val);
- return output;
- }, {});
- };
- const isRegExp = x => is$4(x, RegExp);
- const option = name => editor => editor.options.get(name);
- const stringOrObjectProcessor = value => isString(value) || isObject(value);
- const bodyOptionProcessor = (editor, defaultValue = '') => value => {
- const valid = isString(value);
- if (valid) {
- if (value.indexOf('=') !== -1) {
- const bodyObj = getHash(value);
- return {
- value: get$a(bodyObj, editor.id).getOr(defaultValue),
- valid
- };
- } else {
- return {
- value,
- valid
- };
- }
- } else {
- return {
- valid: false,
- message: 'Must be a string.'
- };
- }
- };
- const register$7 = editor => {
- const registerOption = editor.options.register;
- registerOption('id', {
- processor: 'string',
- default: editor.id
- });
- registerOption('selector', { processor: 'string' });
- registerOption('target', { processor: 'object' });
- registerOption('suffix', { processor: 'string' });
- registerOption('cache_suffix', { processor: 'string' });
- registerOption('base_url', { processor: 'string' });
- registerOption('referrer_policy', {
- processor: 'string',
- default: ''
- });
- registerOption('language_load', { processor: 'boolean' });
- registerOption('inline', {
- processor: 'boolean',
- default: false
- });
- registerOption('iframe_attrs', {
- processor: 'object',
- default: {}
- });
- registerOption('doctype', {
- processor: 'string',
- default: '<!DOCTYPE html>'
- });
- registerOption('document_base_url', {
- processor: 'string',
- default: editor.documentBaseUrl
- });
- registerOption('body_id', {
- processor: bodyOptionProcessor(editor, 'tinymce'),
- default: 'tinymce'
- });
- registerOption('body_class', {
- processor: bodyOptionProcessor(editor),
- default: ''
- });
- registerOption('content_security_policy', {
- processor: 'string',
- default: ''
- });
- registerOption('br_in_pre', {
- processor: 'boolean',
- default: true
- });
- registerOption('forced_root_block', {
- processor: value => {
- const valid = isString(value) && isNotEmpty(value);
- if (valid) {
- return {
- value,
- valid
- };
- } else {
- return {
- valid: false,
- message: 'Must be a non-empty string.'
- };
- }
- },
- default: 'p'
- });
- registerOption('forced_root_block_attrs', {
- processor: 'object',
- default: {}
- });
- registerOption('newline_behavior', {
- processor: value => {
- const valid = contains$2([
- 'block',
- 'linebreak',
- 'invert',
- 'default'
- ], value);
- return valid ? {
- value,
- valid
- } : {
- valid: false,
- message: 'Must be one of: block, linebreak, invert or default.'
- };
- },
- default: 'default'
- });
- registerOption('br_newline_selector', {
- processor: 'string',
- default: '.mce-toc h2,figcaption,caption'
- });
- registerOption('no_newline_selector', {
- processor: 'string',
- default: ''
- });
- registerOption('keep_styles', {
- processor: 'boolean',
- default: true
- });
- registerOption('end_container_on_empty_block', {
- processor: value => {
- if (isBoolean(value)) {
- return {
- valid: true,
- value
- };
- } else if (isString(value)) {
- return {
- valid: true,
- value
- };
- } else {
- return {
- valid: false,
- message: 'Must be boolean or a string'
- };
- }
- },
- default: 'blockquote'
- });
- registerOption('font_size_style_values', {
- processor: 'string',
- default: 'xx-small,x-small,small,medium,large,x-large,xx-large'
- });
- registerOption('font_size_legacy_values', {
- processor: 'string',
- default: 'xx-small,small,medium,large,x-large,xx-large,300%'
- });
- registerOption('font_size_classes', {
- processor: 'string',
- default: ''
- });
- registerOption('automatic_uploads', {
- processor: 'boolean',
- default: true
- });
- registerOption('images_reuse_filename', {
- processor: 'boolean',
- default: false
- });
- registerOption('images_replace_blob_uris', {
- processor: 'boolean',
- default: true
- });
- registerOption('icons', {
- processor: 'string',
- default: ''
- });
- registerOption('icons_url', {
- processor: 'string',
- default: ''
- });
- registerOption('images_upload_url', {
- processor: 'string',
- default: ''
- });
- registerOption('images_upload_base_path', {
- processor: 'string',
- default: ''
- });
- registerOption('images_upload_base_path', {
- processor: 'string',
- default: ''
- });
- registerOption('images_upload_credentials', {
- processor: 'boolean',
- default: false
- });
- registerOption('images_upload_handler', { processor: 'function' });
- registerOption('language', {
- processor: 'string',
- default: 'en'
- });
- registerOption('language_url', {
- processor: 'string',
- default: ''
- });
- registerOption('entity_encoding', {
- processor: 'string',
- default: 'named'
- });
- registerOption('indent', {
- processor: 'boolean',
- default: true
- });
- registerOption('indent_before', {
- processor: 'string',
- default: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist'
- });
- registerOption('indent_after', {
- processor: 'string',
- default: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist'
- });
- registerOption('indent_use_margin', {
- processor: 'boolean',
- default: false
- });
- registerOption('indentation', {
- processor: 'string',
- default: '40px'
- });
- registerOption('content_css', {
- processor: value => {
- const valid = value === false || isString(value) || isArrayOf(value, isString);
- if (valid) {
- if (isString(value)) {
- return {
- value: map$3(value.split(','), trim$3),
- valid
- };
- } else if (isArray$1(value)) {
- return {
- value,
- valid
- };
- } else if (value === false) {
- return {
- value: [],
- valid
- };
- } else {
- return {
- value,
- valid
- };
- }
- } else {
- return {
- valid: false,
- message: 'Must be false, a string or an array of strings.'
- };
- }
- },
- default: isInline(editor) ? [] : ['default']
- });
- registerOption('content_style', { processor: 'string' });
- registerOption('content_css_cors', {
- processor: 'boolean',
- default: false
- });
- registerOption('font_css', {
- processor: value => {
- const valid = isString(value) || isArrayOf(value, isString);
- if (valid) {
- const newValue = isArray$1(value) ? value : map$3(value.split(','), trim$3);
- return {
- value: newValue,
- valid
- };
- } else {
- return {
- valid: false,
- message: 'Must be a string or an array of strings.'
- };
- }
- },
- default: []
- });
- registerOption('inline_boundaries', {
- processor: 'boolean',
- default: true
- });
- registerOption('inline_boundaries_selector', {
- processor: 'string',
- default: 'a[href],code,span.mce-annotation'
- });
- registerOption('object_resizing', {
- processor: value => {
- const valid = isBoolean(value) || isString(value);
- if (valid) {
- if (value === false || deviceDetection$1.isiPhone() || deviceDetection$1.isiPad()) {
- return {
- value: '',
- valid
- };
- } else {
- return {
- value: value === true ? 'table,img,figure.image,div,video,iframe' : value,
- valid
- };
- }
- } else {
- return {
- valid: false,
- message: 'Must be boolean or a string'
- };
- }
- },
- default: !isTouch
- });
- registerOption('resize_img_proportional', {
- processor: 'boolean',
- default: true
- });
- registerOption('event_root', { processor: 'object' });
- registerOption('service_message', { processor: 'string' });
- registerOption('theme', {
- processor: value => value === false || isString(value) || isFunction(value),
- default: 'silver'
- });
- registerOption('theme_url', { processor: 'string' });
- registerOption('formats', { processor: 'object' });
- registerOption('format_empty_lines', {
- processor: 'boolean',
- default: false
- });
- registerOption('preview_styles', {
- processor: value => {
- const valid = value === false || isString(value);
- if (valid) {
- return {
- value: value === false ? '' : value,
- valid
- };
- } else {
- return {
- valid: false,
- message: 'Must be false or a string'
- };
- }
- },
- default: 'font-family font-size font-weight font-style text-decoration text-transform color background-color border border-radius outline text-shadow'
- });
- registerOption('custom_ui_selector', {
- processor: 'string',
- default: ''
- });
- registerOption('hidden_input', {
- processor: 'boolean',
- default: true
- });
- registerOption('submit_patch', {
- processor: 'boolean',
- default: true
- });
- registerOption('encoding', { processor: 'string' });
- registerOption('add_form_submit_trigger', {
- processor: 'boolean',
- default: true
- });
- registerOption('add_unload_trigger', {
- processor: 'boolean',
- default: true
- });
- registerOption('custom_undo_redo_levels', {
- processor: 'number',
- default: 0
- });
- registerOption('disable_nodechange', {
- processor: 'boolean',
- default: false
- });
- registerOption('readonly', {
- processor: 'boolean',
- default: false
- });
- registerOption('plugins', {
- processor: 'string[]',
- default: []
- });
- registerOption('external_plugins', { processor: 'object' });
- registerOption('forced_plugins', { processor: 'string[]' });
- registerOption('model', {
- processor: 'string',
- default: editor.hasPlugin('rtc') ? 'plugin' : 'dom'
- });
- registerOption('model_url', { processor: 'string' });
- registerOption('block_unsupported_drop', {
- processor: 'boolean',
- default: true
- });
- registerOption('visual', {
- processor: 'boolean',
- default: true
- });
- registerOption('visual_table_class', {
- processor: 'string',
- default: 'mce-item-table'
- });
- registerOption('visual_anchor_class', {
- processor: 'string',
- default: 'mce-item-anchor'
- });
- registerOption('iframe_aria_text', {
- processor: 'string',
- default: 'Rich Text Area. Press ALT-0 for help.'
- });
- registerOption('setup', { processor: 'function' });
- registerOption('init_instance_callback', { processor: 'function' });
- registerOption('url_converter', {
- processor: 'function',
- default: editor.convertURL
- });
- registerOption('url_converter_scope', {
- processor: 'object',
- default: editor
- });
- registerOption('urlconverter_callback', { processor: 'function' });
- registerOption('allow_conditional_comments', {
- processor: 'boolean',
- default: false
- });
- registerOption('allow_html_data_urls', {
- processor: 'boolean',
- default: false
- });
- registerOption('allow_svg_data_urls', { processor: 'boolean' });
- registerOption('allow_html_in_named_anchor', {
- processor: 'boolean',
- default: false
- });
- registerOption('allow_script_urls', {
- processor: 'boolean',
- default: false
- });
- registerOption('allow_unsafe_link_target', {
- processor: 'boolean',
- default: false
- });
- registerOption('convert_fonts_to_spans', {
- processor: 'boolean',
- default: true,
- deprecated: true
- });
- registerOption('fix_list_elements', {
- processor: 'boolean',
- default: false
- });
- registerOption('preserve_cdata', {
- processor: 'boolean',
- default: false
- });
- registerOption('remove_trailing_brs', { processor: 'boolean' });
- registerOption('inline_styles', {
- processor: 'boolean',
- default: true,
- deprecated: true
- });
- registerOption('element_format', {
- processor: 'string',
- default: 'html'
- });
- registerOption('entities', { processor: 'string' });
- registerOption('schema', {
- processor: 'string',
- default: 'html5'
- });
- registerOption('convert_urls', {
- processor: 'boolean',
- default: true
- });
- registerOption('relative_urls', {
- processor: 'boolean',
- default: true
- });
- registerOption('remove_script_host', {
- processor: 'boolean',
- default: true
- });
- registerOption('custom_elements', { processor: 'string' });
- registerOption('extended_valid_elements', { processor: 'string' });
- registerOption('invalid_elements', { processor: 'string' });
- registerOption('invalid_styles', { processor: stringOrObjectProcessor });
- registerOption('valid_children', { processor: 'string' });
- registerOption('valid_classes', { processor: stringOrObjectProcessor });
- registerOption('valid_elements', { processor: 'string' });
- registerOption('valid_styles', { processor: stringOrObjectProcessor });
- registerOption('verify_html', {
- processor: 'boolean',
- default: true
- });
- registerOption('auto_focus', { processor: value => isString(value) || value === true });
- registerOption('browser_spellcheck', {
- processor: 'boolean',
- default: false
- });
- registerOption('protect', { processor: 'array' });
- registerOption('images_file_types', {
- processor: 'string',
- default: 'jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp'
- });
- registerOption('deprecation_warnings', {
- processor: 'boolean',
- default: true
- });
- registerOption('a11y_advanced_options', {
- processor: 'boolean',
- default: false
- });
- registerOption('api_key', { processor: 'string' });
- registerOption('paste_block_drop', {
- processor: 'boolean',
- default: false
- });
- registerOption('paste_data_images', {
- processor: 'boolean',
- default: true
- });
- registerOption('paste_preprocess', { processor: 'function' });
- registerOption('paste_postprocess', { processor: 'function' });
- registerOption('paste_webkit_styles', {
- processor: 'string',
- default: 'none'
- });
- registerOption('paste_remove_styles_if_webkit', {
- processor: 'boolean',
- default: true
- });
- registerOption('paste_merge_formats', {
- processor: 'boolean',
- default: true
- });
- registerOption('smart_paste', {
- processor: 'boolean',
- default: true
- });
- registerOption('paste_as_text', {
- processor: 'boolean',
- default: false
- });
- registerOption('paste_tab_spaces', {
- processor: 'number',
- default: 4
- });
- registerOption('text_patterns', {
- processor: value => {
- if (isArrayOf(value, isObject) || value === false) {
- const patterns = value === false ? [] : value;
- return {
- value: fromRawPatterns(patterns),
- valid: true
- };
- } else {
- return {
- valid: false,
- message: 'Must be an array of objects or false.'
- };
- }
- },
- default: [
- {
- start: '*',
- end: '*',
- format: 'italic'
- },
- {
- start: '**',
- end: '**',
- format: 'bold'
- },
- {
- start: '#',
- format: 'h1'
- },
- {
- start: '##',
- format: 'h2'
- },
- {
- start: '###',
- format: 'h3'
- },
- {
- start: '####',
- format: 'h4'
- },
- {
- start: '#####',
- format: 'h5'
- },
- {
- start: '######',
- format: 'h6'
- },
- {
- start: '1. ',
- cmd: 'InsertOrderedList'
- },
- {
- start: '* ',
- cmd: 'InsertUnorderedList'
- },
- {
- start: '- ',
- cmd: 'InsertUnorderedList'
- }
- ]
- });
- registerOption('noneditable_class', {
- processor: 'string',
- default: 'mceNonEditable'
- });
- registerOption('editable_class', {
- processor: 'string',
- default: 'mceEditable'
- });
- registerOption('noneditable_regexp', {
- processor: value => {
- if (isArrayOf(value, isRegExp)) {
- return {
- value,
- valid: true
- };
- } else if (isRegExp(value)) {
- return {
- value: [value],
- valid: true
- };
- } else {
- return {
- valid: false,
- message: 'Must be a RegExp or an array of RegExp.'
- };
- }
- },
- default: []
- });
- registerOption('table_tab_navigation', {
- processor: 'boolean',
- default: true
- });
- editor.on('ScriptsLoaded', () => {
- registerOption('directionality', {
- processor: 'string',
- default: I18n.isRtl() ? 'rtl' : undefined
- });
- registerOption('placeholder', {
- processor: 'string',
- default: DOM$a.getAttrib(editor.getElement(), 'placeholder')
- });
- });
- };
- const getIframeAttrs = option('iframe_attrs');
- const getDocType = option('doctype');
- const getDocumentBaseUrl = option('document_base_url');
- const getBodyId = option('body_id');
- const getBodyClass = option('body_class');
- const getContentSecurityPolicy = option('content_security_policy');
- const shouldPutBrInPre$1 = option('br_in_pre');
- const getForcedRootBlock = option('forced_root_block');
- const getForcedRootBlockAttrs = option('forced_root_block_attrs');
- const getNewlineBehavior = option('newline_behavior');
- const getBrNewLineSelector = option('br_newline_selector');
- const getNoNewLineSelector = option('no_newline_selector');
- const shouldKeepStyles = option('keep_styles');
- const shouldEndContainerOnEmptyBlock = option('end_container_on_empty_block');
- const isAutomaticUploadsEnabled = option('automatic_uploads');
- const shouldReuseFileName = option('images_reuse_filename');
- const shouldReplaceBlobUris = option('images_replace_blob_uris');
- const getIconPackName = option('icons');
- const getIconsUrl = option('icons_url');
- const getImageUploadUrl = option('images_upload_url');
- const getImageUploadBasePath = option('images_upload_base_path');
- const getImagesUploadCredentials = option('images_upload_credentials');
- const getImagesUploadHandler = option('images_upload_handler');
- const shouldUseContentCssCors = option('content_css_cors');
- const getReferrerPolicy = option('referrer_policy');
- const getLanguageCode = option('language');
- const getLanguageUrl = option('language_url');
- const shouldIndentUseMargin = option('indent_use_margin');
- const getIndentation = option('indentation');
- const getContentCss = option('content_css');
- const getContentStyle = option('content_style');
- const getFontCss = option('font_css');
- const getDirectionality = option('directionality');
- const getInlineBoundarySelector = option('inline_boundaries_selector');
- const getObjectResizing = option('object_resizing');
- const getResizeImgProportional = option('resize_img_proportional');
- const getPlaceholder = option('placeholder');
- const getEventRoot = option('event_root');
- const getServiceMessage = option('service_message');
- const getTheme = option('theme');
- const getThemeUrl = option('theme_url');
- const getModel = option('model');
- const getModelUrl = option('model_url');
- const isInlineBoundariesEnabled = option('inline_boundaries');
- const getFormats = option('formats');
- const getPreviewStyles = option('preview_styles');
- const canFormatEmptyLines = option('format_empty_lines');
- const getCustomUiSelector = option('custom_ui_selector');
- const isInline = option('inline');
- const hasHiddenInput = option('hidden_input');
- const shouldPatchSubmit = option('submit_patch');
- const shouldAddFormSubmitTrigger = option('add_form_submit_trigger');
- const shouldAddUnloadTrigger = option('add_unload_trigger');
- const getCustomUndoRedoLevels = option('custom_undo_redo_levels');
- const shouldDisableNodeChange = option('disable_nodechange');
- const isReadOnly$1 = option('readonly');
- const hasContentCssCors = option('content_css_cors');
- const getPlugins = option('plugins');
- const getExternalPlugins$1 = option('external_plugins');
- const shouldBlockUnsupportedDrop = option('block_unsupported_drop');
- const isVisualAidsEnabled = option('visual');
- const getVisualAidsTableClass = option('visual_table_class');
- const getVisualAidsAnchorClass = option('visual_anchor_class');
- const getIframeAriaText = option('iframe_aria_text');
- const getSetupCallback = option('setup');
- const getInitInstanceCallback = option('init_instance_callback');
- const getUrlConverterCallback = option('urlconverter_callback');
- const getAutoFocus = option('auto_focus');
- const shouldBrowserSpellcheck = option('browser_spellcheck');
- const getProtect = option('protect');
- const shouldPasteBlockDrop = option('paste_block_drop');
- const shouldPasteDataImages = option('paste_data_images');
- const getPastePreProcess = option('paste_preprocess');
- const getPastePostProcess = option('paste_postprocess');
- const getPasteWebkitStyles = option('paste_webkit_styles');
- const shouldPasteRemoveWebKitStyles = option('paste_remove_styles_if_webkit');
- const shouldPasteMergeFormats = option('paste_merge_formats');
- const isSmartPasteEnabled = option('smart_paste');
- const isPasteAsTextEnabled = option('paste_as_text');
- const getPasteTabSpaces = option('paste_tab_spaces');
- const shouldAllowHtmlDataUrls = option('allow_html_data_urls');
- const getTextPatterns = option('text_patterns');
- const getNonEditableClass = option('noneditable_class');
- const getEditableClass = option('editable_class');
- const getNonEditableRegExps = option('noneditable_regexp');
- const getFontStyleValues = editor => Tools.explode(editor.options.get('font_size_style_values'));
- const getFontSizeClasses = editor => Tools.explode(editor.options.get('font_size_classes'));
- const isEncodingXml = editor => editor.options.get('encoding') === 'xml';
- const getAllowedImageFileTypes = editor => Tools.explode(editor.options.get('images_file_types'));
- const hasTableTabNavigation = option('table_tab_navigation');
- const isElement$3 = isElement$6;
- const isText$4 = isText$9;
- const removeNode$1 = node => {
- const parentNode = node.parentNode;
- if (parentNode) {
- parentNode.removeChild(node);
- }
- };
- const trimCount = text => {
- const trimmedText = trim$1(text);
- return {
- count: text.length - trimmedText.length,
- text: trimmedText
- };
- };
- const deleteZwspChars = caretContainer => {
- let idx;
- while ((idx = caretContainer.data.lastIndexOf(ZWSP$1)) !== -1) {
- caretContainer.deleteData(idx, 1);
- }
- };
- const removeUnchanged = (caretContainer, pos) => {
- remove$4(caretContainer);
- return pos;
- };
- const removeTextAndReposition = (caretContainer, pos) => {
- const before = trimCount(caretContainer.data.substr(0, pos.offset()));
- const after = trimCount(caretContainer.data.substr(pos.offset()));
- const text = before.text + after.text;
- if (text.length > 0) {
- deleteZwspChars(caretContainer);
- return CaretPosition(caretContainer, pos.offset() - before.count);
- } else {
- return pos;
- }
- };
- const removeElementAndReposition = (caretContainer, pos) => {
- const parentNode = pos.container();
- const newPosition = indexOf$1(from(parentNode.childNodes), caretContainer).map(index => {
- return index < pos.offset() ? CaretPosition(parentNode, pos.offset() - 1) : pos;
- }).getOr(pos);
- remove$4(caretContainer);
- return newPosition;
- };
- const removeTextCaretContainer = (caretContainer, pos) => isText$4(caretContainer) && pos.container() === caretContainer ? removeTextAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
- const removeElementCaretContainer = (caretContainer, pos) => pos.container() === caretContainer.parentNode ? removeElementAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);
- const removeAndReposition = (container, pos) => CaretPosition.isTextPosition(pos) ? removeTextCaretContainer(container, pos) : removeElementCaretContainer(container, pos);
- const remove$4 = caretContainerNode => {
- if (isElement$3(caretContainerNode) && isCaretContainer$2(caretContainerNode)) {
- if (hasContent(caretContainerNode)) {
- caretContainerNode.removeAttribute('data-mce-caret');
- } else {
- removeNode$1(caretContainerNode);
- }
- }
- if (isText$4(caretContainerNode)) {
- deleteZwspChars(caretContainerNode);
- if (caretContainerNode.data.length === 0) {
- removeNode$1(caretContainerNode);
- }
- }
- };
- const isContentEditableFalse$8 = isContentEditableFalse$b;
- const isMedia$1 = isMedia$2;
- const isTableCell$3 = isTableCell$5;
- const inlineFakeCaretSelector = '*[contentEditable=false],video,audio,embed,object';
- const getAbsoluteClientRect = (root, element, before) => {
- const clientRect = collapse(element.getBoundingClientRect(), before);
- let scrollX;
- let scrollY;
- if (root.tagName === 'BODY') {
- const docElm = root.ownerDocument.documentElement;
- scrollX = root.scrollLeft || docElm.scrollLeft;
- scrollY = root.scrollTop || docElm.scrollTop;
- } else {
- const rootRect = root.getBoundingClientRect();
- scrollX = root.scrollLeft - rootRect.left;
- scrollY = root.scrollTop - rootRect.top;
- }
- clientRect.left += scrollX;
- clientRect.right += scrollX;
- clientRect.top += scrollY;
- clientRect.bottom += scrollY;
- clientRect.width = 1;
- let margin = element.offsetWidth - element.clientWidth;
- if (margin > 0) {
- if (before) {
- margin *= -1;
- }
- clientRect.left += margin;
- clientRect.right += margin;
- }
- return clientRect;
- };
- const trimInlineCaretContainers = root => {
- const fakeCaretTargetNodes = descendants(SugarElement.fromDom(root), inlineFakeCaretSelector);
- for (let i = 0; i < fakeCaretTargetNodes.length; i++) {
- const node = fakeCaretTargetNodes[i].dom;
- let sibling = node.previousSibling;
- if (endsWithCaretContainer$1(sibling)) {
- const data = sibling.data;
- if (data.length === 1) {
- sibling.parentNode.removeChild(sibling);
- } else {
- sibling.deleteData(data.length - 1, 1);
- }
- }
- sibling = node.nextSibling;
- if (startsWithCaretContainer$1(sibling)) {
- const data = sibling.data;
- if (data.length === 1) {
- sibling.parentNode.removeChild(sibling);
- } else {
- sibling.deleteData(0, 1);
- }
- }
- }
- };
- const FakeCaret = (editor, root, isBlock, hasFocus) => {
- const lastVisualCaret = value$2();
- let cursorInterval;
- let caretContainerNode;
- const caretBlock = getForcedRootBlock(editor);
- const dom = editor.dom;
- const show = (before, element) => {
- let rng;
- hide();
- if (isTableCell$3(element)) {
- return null;
- }
- if (isBlock(element)) {
- caretContainerNode = insertBlock(caretBlock, element, before);
- const clientRect = getAbsoluteClientRect(root, element, before);
- dom.setStyle(caretContainerNode, 'top', clientRect.top);
- const caret = dom.create('div', {
- 'class': 'mce-visual-caret',
- 'data-mce-bogus': 'all'
- });
- dom.setStyles(caret, { ...clientRect });
- dom.add(root, caret);
- lastVisualCaret.set({
- caret,
- element,
- before
- });
- if (before) {
- dom.addClass(caret, 'mce-visual-caret-before');
- }
- startBlink();
- rng = element.ownerDocument.createRange();
- rng.setStart(caretContainerNode, 0);
- rng.setEnd(caretContainerNode, 0);
- } else {
- caretContainerNode = insertInline$1(element, before);
- rng = element.ownerDocument.createRange();
- if (isInlineFakeCaretTarget(caretContainerNode.nextSibling)) {
- rng.setStart(caretContainerNode, 0);
- rng.setEnd(caretContainerNode, 0);
- } else {
- rng.setStart(caretContainerNode, 1);
- rng.setEnd(caretContainerNode, 1);
- }
- return rng;
- }
- return rng;
- };
- const hide = () => {
- trimInlineCaretContainers(root);
- if (caretContainerNode) {
- remove$4(caretContainerNode);
- caretContainerNode = null;
- }
- lastVisualCaret.on(caretState => {
- dom.remove(caretState.caret);
- lastVisualCaret.clear();
- });
- if (cursorInterval) {
- clearInterval(cursorInterval);
- cursorInterval = undefined;
- }
- };
- const startBlink = () => {
- cursorInterval = setInterval(() => {
- lastVisualCaret.on(caretState => {
- if (hasFocus()) {
- dom.toggleClass(caretState.caret, 'mce-visual-caret-hidden');
- } else {
- dom.addClass(caretState.caret, 'mce-visual-caret-hidden');
- }
- });
- }, 500);
- };
- const reposition = () => {
- lastVisualCaret.on(caretState => {
- const clientRect = getAbsoluteClientRect(root, caretState.element, caretState.before);
- dom.setStyles(caretState.caret, { ...clientRect });
- });
- };
- const destroy = () => clearInterval(cursorInterval);
- const getCss = () => '.mce-visual-caret {' + 'position: absolute;' + 'background-color: black;' + 'background-color: currentcolor;' + '}' + '.mce-visual-caret-hidden {' + 'display: none;' + '}' + '*[data-mce-caret] {' + 'position: absolute;' + 'left: -1000px;' + 'right: auto;' + 'top: 0;' + 'margin: 0;' + 'padding: 0;' + '}';
- return {
- show,
- hide,
- getCss,
- reposition,
- destroy
- };
- };
- const isFakeCaretTableBrowser = () => Env.browser.isFirefox();
- const isInlineFakeCaretTarget = node => isContentEditableFalse$8(node) || isMedia$1(node);
- const isFakeCaretTarget = node => isInlineFakeCaretTarget(node) || isTable$3(node) && isFakeCaretTableBrowser();
- const isContentEditableTrue$3 = isContentEditableTrue$5;
- const isContentEditableFalse$7 = isContentEditableFalse$b;
- const isMedia = isMedia$2;
- const isBlockLike = matchStyleValues('display', 'block table table-cell table-caption list-item');
- const isCaretContainer = isCaretContainer$2;
- const isCaretContainerBlock = isCaretContainerBlock$1;
- const isElement$2 = isElement$6;
- const isCaretCandidate$1 = isCaretCandidate$3;
- const isForwards = direction => direction > 0;
- const isBackwards = direction => direction < 0;
- const skipCaretContainers = (walk, shallow) => {
- let node;
- while (node = walk(shallow)) {
- if (!isCaretContainerBlock(node)) {
- return node;
- }
- }
- return null;
- };
- const findNode = (node, direction, predicateFn, rootNode, shallow) => {
- const walker = new DomTreeWalker(node, rootNode);
- const isCefOrCaretContainer = isContentEditableFalse$7(node) || isCaretContainerBlock(node);
- if (isBackwards(direction)) {
- if (isCefOrCaretContainer) {
- node = skipCaretContainers(walker.prev.bind(walker), true);
- if (predicateFn(node)) {
- return node;
- }
- }
- while (node = skipCaretContainers(walker.prev.bind(walker), shallow)) {
- if (predicateFn(node)) {
- return node;
- }
- }
- }
- if (isForwards(direction)) {
- if (isCefOrCaretContainer) {
- node = skipCaretContainers(walker.next.bind(walker), true);
- if (predicateFn(node)) {
- return node;
- }
- }
- while (node = skipCaretContainers(walker.next.bind(walker), shallow)) {
- if (predicateFn(node)) {
- return node;
- }
- }
- }
- return null;
- };
- const getEditingHost = (node, rootNode) => {
- const isCETrue = node => isContentEditableTrue$3(node.dom);
- const isRoot = node => node.dom === rootNode;
- return ancestor$3(SugarElement.fromDom(node), isCETrue, isRoot).map(elm => elm.dom).getOr(rootNode);
- };
- const getParentBlock$3 = (node, rootNode) => {
- while (node && node !== rootNode) {
- if (isBlockLike(node)) {
- return node;
- }
- node = node.parentNode;
- }
- return null;
- };
- const isInSameBlock = (caretPosition1, caretPosition2, rootNode) => getParentBlock$3(caretPosition1.container(), rootNode) === getParentBlock$3(caretPosition2.container(), rootNode);
- const getChildNodeAtRelativeOffset = (relativeOffset, caretPosition) => {
- if (!caretPosition) {
- return null;
- }
- const container = caretPosition.container();
- const offset = caretPosition.offset();
- if (!isElement$2(container)) {
- return null;
- }
- return container.childNodes[offset + relativeOffset];
- };
- const beforeAfter = (before, node) => {
- const range = node.ownerDocument.createRange();
- if (before) {
- range.setStartBefore(node);
- range.setEndBefore(node);
- } else {
- range.setStartAfter(node);
- range.setEndAfter(node);
- }
- return range;
- };
- const isNodesInSameBlock = (root, node1, node2) => getParentBlock$3(node1, root) === getParentBlock$3(node2, root);
- const lean = (left, root, node) => {
- const siblingName = left ? 'previousSibling' : 'nextSibling';
- while (node && node !== root) {
- let sibling = node[siblingName];
- if (isCaretContainer(sibling)) {
- sibling = sibling[siblingName];
- }
- if (isContentEditableFalse$7(sibling) || isMedia(sibling)) {
- if (isNodesInSameBlock(root, sibling, node)) {
- return sibling;
- }
- break;
- }
- if (isCaretCandidate$1(sibling)) {
- break;
- }
- node = node.parentNode;
- }
- return null;
- };
- const before$2 = curry(beforeAfter, true);
- const after$2 = curry(beforeAfter, false);
- const normalizeRange = (direction, root, range) => {
- let node;
- const leanLeft = curry(lean, true, root);
- const leanRight = curry(lean, false, root);
- let container = range.startContainer;
- const offset = range.startOffset;
- if (isCaretContainerBlock$1(container)) {
- if (!isElement$2(container)) {
- container = container.parentNode;
- }
- const location = container.getAttribute('data-mce-caret');
- if (location === 'before') {
- node = container.nextSibling;
- if (isFakeCaretTarget(node)) {
- return before$2(node);
- }
- }
- if (location === 'after') {
- node = container.previousSibling;
- if (isFakeCaretTarget(node)) {
- return after$2(node);
- }
- }
- }
- if (!range.collapsed) {
- return range;
- }
- if (isText$9(container)) {
- if (isCaretContainer(container)) {
- if (direction === 1) {
- node = leanRight(container);
- if (node) {
- return before$2(node);
- }
- node = leanLeft(container);
- if (node) {
- return after$2(node);
- }
- }
- if (direction === -1) {
- node = leanLeft(container);
- if (node) {
- return after$2(node);
- }
- node = leanRight(container);
- if (node) {
- return before$2(node);
- }
- }
- return range;
- }
- if (endsWithCaretContainer$1(container) && offset >= container.data.length - 1) {
- if (direction === 1) {
- node = leanRight(container);
- if (node) {
- return before$2(node);
- }
- }
- return range;
- }
- if (startsWithCaretContainer$1(container) && offset <= 1) {
- if (direction === -1) {
- node = leanLeft(container);
- if (node) {
- return after$2(node);
- }
- }
- return range;
- }
- if (offset === container.data.length) {
- node = leanRight(container);
- if (node) {
- return before$2(node);
- }
- return range;
- }
- if (offset === 0) {
- node = leanLeft(container);
- if (node) {
- return after$2(node);
- }
- return range;
- }
- }
- return range;
- };
- const getRelativeCefElm = (forward, caretPosition) => Optional.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition)).filter(isContentEditableFalse$7);
- const getNormalizedRangeEndPoint = (direction, root, range) => {
- const normalizedRange = normalizeRange(direction, root, range);
- if (direction === -1) {
- return CaretPosition.fromRangeStart(normalizedRange);
- }
- return CaretPosition.fromRangeEnd(normalizedRange);
- };
- const getElementFromPosition = pos => Optional.from(pos.getNode()).map(SugarElement.fromDom);
- const getElementFromPrevPosition = pos => Optional.from(pos.getNode(true)).map(SugarElement.fromDom);
- const getVisualCaretPosition = (walkFn, caretPosition) => {
- while (caretPosition = walkFn(caretPosition)) {
- if (caretPosition.isVisible()) {
- return caretPosition;
- }
- }
- return caretPosition;
- };
- const isMoveInsideSameBlock = (from, to) => {
- const inSameBlock = isInSameBlock(from, to);
- if (!inSameBlock && isBr$6(from.getNode())) {
- return true;
- }
- return inSameBlock;
- };
- var HDirection;
- (function (HDirection) {
- HDirection[HDirection['Backwards'] = -1] = 'Backwards';
- HDirection[HDirection['Forwards'] = 1] = 'Forwards';
- }(HDirection || (HDirection = {})));
- const isContentEditableFalse$6 = isContentEditableFalse$b;
- const isText$3 = isText$9;
- const isElement$1 = isElement$6;
- const isBr$2 = isBr$6;
- const isCaretCandidate = isCaretCandidate$3;
- const isAtomic = isAtomic$1;
- const isEditableCaretCandidate = isEditableCaretCandidate$1;
- const getParents$3 = (node, root) => {
- const parents = [];
- while (node && node !== root) {
- parents.push(node);
- node = node.parentNode;
- }
- return parents;
- };
- const nodeAtIndex = (container, offset) => {
- if (container.hasChildNodes() && offset < container.childNodes.length) {
- return container.childNodes[offset];
- }
- return null;
- };
- const getCaretCandidatePosition = (direction, node) => {
- if (isForwards(direction)) {
- if (isCaretCandidate(node.previousSibling) && !isText$3(node.previousSibling)) {
- return CaretPosition.before(node);
- }
- if (isText$3(node)) {
- return CaretPosition(node, 0);
- }
- }
- if (isBackwards(direction)) {
- if (isCaretCandidate(node.nextSibling) && !isText$3(node.nextSibling)) {
- return CaretPosition.after(node);
- }
- if (isText$3(node)) {
- return CaretPosition(node, node.data.length);
- }
- }
- if (isBackwards(direction)) {
- if (isBr$2(node)) {
- return CaretPosition.before(node);
- }
- return CaretPosition.after(node);
- }
- return CaretPosition.before(node);
- };
- const moveForwardFromBr = (root, nextNode) => {
- const nextSibling = nextNode.nextSibling;
- if (nextSibling && isCaretCandidate(nextSibling)) {
- if (isText$3(nextSibling)) {
- return CaretPosition(nextSibling, 0);
- } else {
- return CaretPosition.before(nextSibling);
- }
- } else {
- return findCaretPosition$1(HDirection.Forwards, CaretPosition.after(nextNode), root);
- }
- };
- const findCaretPosition$1 = (direction, startPos, root) => {
- let node;
- let nextNode;
- let innerNode;
- let caretPosition;
- if (!isElement$1(root) || !startPos) {
- return null;
- }
- if (startPos.isEqual(CaretPosition.after(root)) && root.lastChild) {
- caretPosition = CaretPosition.after(root.lastChild);
- if (isBackwards(direction) && isCaretCandidate(root.lastChild) && isElement$1(root.lastChild)) {
- return isBr$2(root.lastChild) ? CaretPosition.before(root.lastChild) : caretPosition;
- }
- } else {
- caretPosition = startPos;
- }
- const container = caretPosition.container();
- let offset = caretPosition.offset();
- if (isText$3(container)) {
- if (isBackwards(direction) && offset > 0) {
- return CaretPosition(container, --offset);
- }
- if (isForwards(direction) && offset < container.length) {
- return CaretPosition(container, ++offset);
- }
- node = container;
- } else {
- if (isBackwards(direction) && offset > 0) {
- nextNode = nodeAtIndex(container, offset - 1);
- if (isCaretCandidate(nextNode)) {
- if (!isAtomic(nextNode)) {
- innerNode = findNode(nextNode, direction, isEditableCaretCandidate, nextNode);
- if (innerNode) {
- if (isText$3(innerNode)) {
- return CaretPosition(innerNode, innerNode.data.length);
- }
- return CaretPosition.after(innerNode);
- }
- }
- if (isText$3(nextNode)) {
- return CaretPosition(nextNode, nextNode.data.length);
- }
- return CaretPosition.before(nextNode);
- }
- }
- if (isForwards(direction) && offset < container.childNodes.length) {
- nextNode = nodeAtIndex(container, offset);
- if (isCaretCandidate(nextNode)) {
- if (isBr$2(nextNode)) {
- return moveForwardFromBr(root, nextNode);
- }
- if (!isAtomic(nextNode)) {
- innerNode = findNode(nextNode, direction, isEditableCaretCandidate, nextNode);
- if (innerNode) {
- if (isText$3(innerNode)) {
- return CaretPosition(innerNode, 0);
- }
- return CaretPosition.before(innerNode);
- }
- }
- if (isText$3(nextNode)) {
- return CaretPosition(nextNode, 0);
- }
- return CaretPosition.after(nextNode);
- }
- }
- node = nextNode ? nextNode : caretPosition.getNode();
- }
- if (isForwards(direction) && caretPosition.isAtEnd() || isBackwards(direction) && caretPosition.isAtStart()) {
- node = findNode(node, direction, always, root, true);
- if (isEditableCaretCandidate(node, root)) {
- return getCaretCandidatePosition(direction, node);
- }
- }
- nextNode = findNode(node, direction, isEditableCaretCandidate, root);
- const rootContentEditableFalseElm = last$2(filter$6(getParents$3(container, root), isContentEditableFalse$6));
- if (rootContentEditableFalseElm && (!nextNode || !rootContentEditableFalseElm.contains(nextNode))) {
- if (isForwards(direction)) {
- caretPosition = CaretPosition.after(rootContentEditableFalseElm);
- } else {
- caretPosition = CaretPosition.before(rootContentEditableFalseElm);
- }
- return caretPosition;
- }
- if (nextNode) {
- return getCaretCandidatePosition(direction, nextNode);
- }
- return null;
- };
- const CaretWalker = root => ({
- next: caretPosition => {
- return findCaretPosition$1(HDirection.Forwards, caretPosition, root);
- },
- prev: caretPosition => {
- return findCaretPosition$1(HDirection.Backwards, caretPosition, root);
- }
- });
- const walkToPositionIn = (forward, root, start) => {
- const position = forward ? CaretPosition.before(start) : CaretPosition.after(start);
- return fromPosition(forward, root, position);
- };
- const afterElement = node => isBr$6(node) ? CaretPosition.before(node) : CaretPosition.after(node);
- const isBeforeOrStart = position => {
- if (CaretPosition.isTextPosition(position)) {
- return position.offset() === 0;
- } else {
- return isCaretCandidate$3(position.getNode());
- }
- };
- const isAfterOrEnd = position => {
- if (CaretPosition.isTextPosition(position)) {
- const container = position.container();
- return position.offset() === container.data.length;
- } else {
- return isCaretCandidate$3(position.getNode(true));
- }
- };
- const isBeforeAfterSameElement = (from, to) => !CaretPosition.isTextPosition(from) && !CaretPosition.isTextPosition(to) && from.getNode() === to.getNode(true);
- const isAtBr = position => !CaretPosition.isTextPosition(position) && isBr$6(position.getNode());
- const shouldSkipPosition = (forward, from, to) => {
- if (forward) {
- return !isBeforeAfterSameElement(from, to) && !isAtBr(from) && isAfterOrEnd(from) && isBeforeOrStart(to);
- } else {
- return !isBeforeAfterSameElement(to, from) && isBeforeOrStart(from) && isAfterOrEnd(to);
- }
- };
- const fromPosition = (forward, root, pos) => {
- const walker = CaretWalker(root);
- return Optional.from(forward ? walker.next(pos) : walker.prev(pos));
- };
- const navigate = (forward, root, from) => fromPosition(forward, root, from).bind(to => {
- if (isInSameBlock(from, to, root) && shouldSkipPosition(forward, from, to)) {
- return fromPosition(forward, root, to);
- } else {
- return Optional.some(to);
- }
- });
- const navigateIgnore = (forward, root, from, ignoreFilter) => navigate(forward, root, from).bind(pos => ignoreFilter(pos) ? navigateIgnore(forward, root, pos, ignoreFilter) : Optional.some(pos));
- const positionIn = (forward, element) => {
- const startNode = forward ? element.firstChild : element.lastChild;
- if (isText$9(startNode)) {
- return Optional.some(CaretPosition(startNode, forward ? 0 : startNode.data.length));
- } else if (startNode) {
- if (isCaretCandidate$3(startNode)) {
- return Optional.some(forward ? CaretPosition.before(startNode) : afterElement(startNode));
- } else {
- return walkToPositionIn(forward, element, startNode);
- }
- } else {
- return Optional.none();
- }
- };
- const nextPosition = curry(fromPosition, true);
- const prevPosition = curry(fromPosition, false);
- const firstPositionIn = curry(positionIn, true);
- const lastPositionIn = curry(positionIn, false);
- const CARET_ID$1 = '_mce_caret';
- const isCaretNode = node => isElement$6(node) && node.id === CARET_ID$1;
- const getParentCaretContainer = (body, node) => {
- while (node && node !== body) {
- if (node.id === CARET_ID$1) {
- return node;
- }
- node = node.parentNode;
- }
- return null;
- };
- const isStringPathBookmark = bookmark => isString(bookmark.start);
- const isRangeBookmark = bookmark => has$2(bookmark, 'rng');
- const isIdBookmark = bookmark => has$2(bookmark, 'id');
- const isIndexBookmark = bookmark => has$2(bookmark, 'name');
- const isPathBookmark = bookmark => Tools.isArray(bookmark.start);
- const isForwardBookmark = bookmark => !isIndexBookmark(bookmark) && isBoolean(bookmark.forward) ? bookmark.forward : true;
- const addBogus = (dom, node) => {
- if (isElement$6(node) && dom.isBlock(node) && !node.innerHTML) {
- node.innerHTML = '<br data-mce-bogus="1" />';
- }
- return node;
- };
- const resolveCaretPositionBookmark = (dom, bookmark) => {
- const range = dom.createRng();
- const startPos = resolve$1(dom.getRoot(), bookmark.start);
- range.setStart(startPos.container(), startPos.offset());
- const endPos = resolve$1(dom.getRoot(), bookmark.end);
- range.setEnd(endPos.container(), endPos.offset());
- return {
- range,
- forward: isForwardBookmark(bookmark)
- };
- };
- const insertZwsp = (node, rng) => {
- const textNode = node.ownerDocument.createTextNode(ZWSP$1);
- node.appendChild(textNode);
- rng.setStart(textNode, 0);
- rng.setEnd(textNode, 0);
- };
- const isEmpty$1 = node => node.hasChildNodes() === false;
- const tryFindRangePosition = (node, rng) => lastPositionIn(node).fold(never, pos => {
- rng.setStart(pos.container(), pos.offset());
- rng.setEnd(pos.container(), pos.offset());
- return true;
- });
- const padEmptyCaretContainer = (root, node, rng) => {
- if (isEmpty$1(node) && getParentCaretContainer(root, node)) {
- insertZwsp(node, rng);
- return true;
- } else {
- return false;
- }
- };
- const setEndPoint = (dom, start, bookmark, rng) => {
- const point = bookmark[start ? 'start' : 'end'];
- let i, node, offset, children;
- const root = dom.getRoot();
- if (point) {
- offset = point[0];
- for (node = root, i = point.length - 1; i >= 1; i--) {
- children = node.childNodes;
- if (padEmptyCaretContainer(root, node, rng)) {
- return true;
- }
- if (point[i] > children.length - 1) {
- if (padEmptyCaretContainer(root, node, rng)) {
- return true;
- }
- return tryFindRangePosition(node, rng);
- }
- node = children[point[i]];
- }
- if (node.nodeType === 3) {
- offset = Math.min(point[0], node.nodeValue.length);
- }
- if (node.nodeType === 1) {
- offset = Math.min(point[0], node.childNodes.length);
- }
- if (start) {
- rng.setStart(node, offset);
- } else {
- rng.setEnd(node, offset);
- }
- }
- return true;
- };
- const isValidTextNode = node => isText$9(node) && node.data.length > 0;
- const restoreEndPoint = (dom, suffix, bookmark) => {
- let marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev;
- const keep = bookmark.keep;
- let container, offset;
- if (marker) {
- node = marker.parentNode;
- if (suffix === 'start') {
- if (!keep) {
- idx = dom.nodeIndex(marker);
- } else {
- if (marker.hasChildNodes()) {
- node = marker.firstChild;
- idx = 1;
- } else if (isValidTextNode(marker.nextSibling)) {
- node = marker.nextSibling;
- idx = 0;
- } else if (isValidTextNode(marker.previousSibling)) {
- node = marker.previousSibling;
- idx = marker.previousSibling.data.length;
- } else {
- node = marker.parentNode;
- idx = dom.nodeIndex(marker) + 1;
- }
- }
- container = node;
- offset = idx;
- } else {
- if (!keep) {
- idx = dom.nodeIndex(marker);
- } else {
- if (marker.hasChildNodes()) {
- node = marker.firstChild;
- idx = 1;
- } else if (isValidTextNode(marker.previousSibling)) {
- node = marker.previousSibling;
- idx = marker.previousSibling.data.length;
- } else {
- node = marker.parentNode;
- idx = dom.nodeIndex(marker);
- }
- }
- container = node;
- offset = idx;
- }
- if (!keep) {
- prev = marker.previousSibling;
- next = marker.nextSibling;
- Tools.each(Tools.grep(marker.childNodes), node => {
- if (isText$9(node)) {
- node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
- }
- });
- while (marker = dom.get(bookmark.id + '_' + suffix)) {
- dom.remove(marker, true);
- }
- if (prev && next && prev.nodeType === next.nodeType && isText$9(prev) && !Env.browser.isOpera()) {
- idx = prev.nodeValue.length;
- prev.appendData(next.nodeValue);
- dom.remove(next);
- container = prev;
- offset = idx;
- }
- }
- return Optional.some(CaretPosition(container, offset));
- } else {
- return Optional.none();
- }
- };
- const resolvePaths = (dom, bookmark) => {
- const range = dom.createRng();
- if (setEndPoint(dom, true, bookmark, range) && setEndPoint(dom, false, bookmark, range)) {
- return Optional.some({
- range,
- forward: isForwardBookmark(bookmark)
- });
- } else {
- return Optional.none();
- }
- };
- const resolveId = (dom, bookmark) => {
- const startPos = restoreEndPoint(dom, 'start', bookmark);
- const endPos = restoreEndPoint(dom, 'end', bookmark);
- return lift2(startPos, endPos.or(startPos), (spos, epos) => {
- const range = dom.createRng();
- range.setStart(addBogus(dom, spos.container()), spos.offset());
- range.setEnd(addBogus(dom, epos.container()), epos.offset());
- return {
- range,
- forward: isForwardBookmark(bookmark)
- };
- });
- };
- const resolveIndex = (dom, bookmark) => Optional.from(dom.select(bookmark.name)[bookmark.index]).map(elm => {
- const range = dom.createRng();
- range.selectNode(elm);
- return {
- range,
- forward: true
- };
- });
- const resolve = (selection, bookmark) => {
- const dom = selection.dom;
- if (bookmark) {
- if (isPathBookmark(bookmark)) {
- return resolvePaths(dom, bookmark);
- } else if (isStringPathBookmark(bookmark)) {
- return Optional.some(resolveCaretPositionBookmark(dom, bookmark));
- } else if (isIdBookmark(bookmark)) {
- return resolveId(dom, bookmark);
- } else if (isIndexBookmark(bookmark)) {
- return resolveIndex(dom, bookmark);
- } else if (isRangeBookmark(bookmark)) {
- return Optional.some({
- range: bookmark.rng,
- forward: isForwardBookmark(bookmark)
- });
- }
- }
- return Optional.none();
- };
- const getBookmark$1 = (selection, type, normalized) => {
- return getBookmark$2(selection, type, normalized);
- };
- const moveToBookmark = (selection, bookmark) => {
- resolve(selection, bookmark).each(({range, forward}) => {
- selection.setRng(range, forward);
- });
- };
- const isBookmarkNode$1 = node => {
- return isElement$6(node) && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark';
- };
- const is = expected => actual => expected === actual;
- const isNbsp = is(nbsp);
- const isWhiteSpace = chr => chr !== '' && ' \f\n\r\t\x0B'.indexOf(chr) !== -1;
- const isContent = chr => !isWhiteSpace(chr) && !isNbsp(chr) && !isZwsp$1(chr);
- const hexColour = value => ({ value });
- const toHex = component => {
- const hex = component.toString(16);
- return (hex.length === 1 ? '0' + hex : hex).toUpperCase();
- };
- const fromRgba = rgbaColour => {
- const value = toHex(rgbaColour.red) + toHex(rgbaColour.green) + toHex(rgbaColour.blue);
- return hexColour(value);
- };
- const rgbRegex = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i;
- const rgbaRegex = /^\s*rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?(?:\.\d+)?)\s*\)\s*$/i;
- const rgbaColour = (red, green, blue, alpha) => ({
- red,
- green,
- blue,
- alpha
- });
- const fromStringValues = (red, green, blue, alpha) => {
- const r = parseInt(red, 10);
- const g = parseInt(green, 10);
- const b = parseInt(blue, 10);
- const a = parseFloat(alpha);
- return rgbaColour(r, g, b, a);
- };
- const fromString = rgbaString => {
- if (rgbaString === 'transparent') {
- return Optional.some(rgbaColour(0, 0, 0, 0));
- }
- const rgbMatch = rgbRegex.exec(rgbaString);
- if (rgbMatch !== null) {
- return Optional.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], '1'));
- }
- const rgbaMatch = rgbaRegex.exec(rgbaString);
- if (rgbaMatch !== null) {
- return Optional.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
- }
- return Optional.none();
- };
- const rgbaToHexString = color => fromString(color).map(fromRgba).map(h => '#' + h.value).getOr(color);
- const isNode = node => !!node.nodeType;
- const isInlineBlock = node => {
- return node && /^(IMG)$/.test(node.nodeName);
- };
- const moveStart = (dom, selection, rng) => {
- const offset = rng.startOffset;
- let container = rng.startContainer;
- if (container === rng.endContainer) {
- if (isInlineBlock(container.childNodes[offset])) {
- return;
- }
- }
- if (isElement$6(container)) {
- const nodes = container.childNodes;
- let walker;
- if (offset < nodes.length) {
- container = nodes[offset];
- walker = new DomTreeWalker(container, dom.getParent(container, dom.isBlock));
- } else {
- container = nodes[nodes.length - 1];
- walker = new DomTreeWalker(container, dom.getParent(container, dom.isBlock));
- walker.next(true);
- }
- for (let node = walker.current(); node; node = walker.next()) {
- if (isText$9(node) && !isWhiteSpaceNode$1(node)) {
- rng.setStart(node, 0);
- selection.setRng(rng);
- return;
- }
- }
- }
- };
- const getNonWhiteSpaceSibling = (node, next, inc) => {
- if (node) {
- const nextName = next ? 'nextSibling' : 'previousSibling';
- for (node = inc ? node : node[nextName]; node; node = node[nextName]) {
- if (isElement$6(node) || !isWhiteSpaceNode$1(node)) {
- return node;
- }
- }
- }
- };
- const isTextBlock$1 = (editor, name) => {
- if (isNode(name)) {
- name = name.nodeName;
- }
- return !!editor.schema.getTextBlockElements()[name.toLowerCase()];
- };
- const isValid = (ed, parent, child) => {
- return ed.schema.isValidChild(parent, child);
- };
- const isWhiteSpaceNode$1 = (node, allowSpaces = false) => {
- if (isNonNullable(node) && isText$9(node)) {
- const data = allowSpaces ? node.data.replace(/ /g, '\xA0') : node.data;
- return isWhitespaceText(data);
- } else {
- return false;
- }
- };
- const isEmptyTextNode$1 = node => {
- return isNonNullable(node) && isText$9(node) && node.length === 0;
- };
- const replaceVars = (value, vars) => {
- if (isFunction(value)) {
- value = value(vars);
- } else if (isNonNullable(vars)) {
- value = value.replace(/%(\w+)/g, (str, name) => {
- return vars[name] || str;
- });
- }
- return value;
- };
- const isEq$5 = (str1, str2) => {
- str1 = str1 || '';
- str2 = str2 || '';
- str1 = '' + (str1.nodeName || str1);
- str2 = '' + (str2.nodeName || str2);
- return str1.toLowerCase() === str2.toLowerCase();
- };
- const normalizeStyleValue = (value, name) => {
- if (name === 'color' || name === 'backgroundColor') {
- value = rgbaToHexString(value);
- }
- if (name === 'fontWeight' && value === 700) {
- value = 'bold';
- }
- if (name === 'fontFamily') {
- value = value.replace(/[\'\"]/g, '').replace(/,\s+/g, ',');
- }
- return '' + value;
- };
- const getStyle = (dom, node, name) => {
- return normalizeStyleValue(dom.getStyle(node, name), name);
- };
- const getTextDecoration = (dom, node) => {
- let decoration;
- dom.getParent(node, n => {
- decoration = dom.getStyle(n, 'text-decoration');
- return decoration && decoration !== 'none';
- });
- return decoration;
- };
- const getParents$2 = (dom, node, selector) => {
- return dom.getParents(node, selector, dom.getRoot());
- };
- const isVariableFormatName = (editor, formatName) => {
- const hasVariableValues = format => {
- const isVariableValue = val => val.length > 1 && val.charAt(0) === '%';
- return exists([
- 'styles',
- 'attributes'
- ], key => get$a(format, key).exists(field => {
- const fieldValues = isArray$1(field) ? field : values(field);
- return exists(fieldValues, isVariableValue);
- }));
- };
- return exists(editor.formatter.get(formatName), hasVariableValues);
- };
- const areSimilarFormats = (editor, formatName, otherFormatName) => {
- const validKeys = [
- 'inline',
- 'block',
- 'selector',
- 'attributes',
- 'styles',
- 'classes'
- ];
- const filterObj = format => filter$5(format, (_, key) => exists(validKeys, validKey => validKey === key));
- return exists(editor.formatter.get(formatName), fmt1 => {
- const filteredFmt1 = filterObj(fmt1);
- return exists(editor.formatter.get(otherFormatName), fmt2 => {
- const filteredFmt2 = filterObj(fmt2);
- return equal$1(filteredFmt1, filteredFmt2);
- });
- });
- };
- const isBlockFormat = format => hasNonNullableKey(format, 'block');
- const isSelectorFormat = format => hasNonNullableKey(format, 'selector');
- const isInlineFormat = format => hasNonNullableKey(format, 'inline');
- const isMixedFormat = format => isSelectorFormat(format) && isInlineFormat(format) && is$2(get$a(format, 'mixed'), true);
- const shouldExpandToSelector = format => isSelectorFormat(format) && format.expand !== false && !isInlineFormat(format);
- const isBookmarkNode = isBookmarkNode$1;
- const getParents$1 = getParents$2;
- const isWhiteSpaceNode = isWhiteSpaceNode$1;
- const isTextBlock = isTextBlock$1;
- const isBogusBr = node => {
- return isBr$6(node) && node.getAttribute('data-mce-bogus') && !node.nextSibling;
- };
- const findParentContentEditable = (dom, node) => {
- let parent = node;
- while (parent) {
- if (isElement$6(parent) && dom.getContentEditable(parent)) {
- return dom.getContentEditable(parent) === 'false' ? parent : node;
- }
- parent = parent.parentNode;
- }
- return node;
- };
- const walkText = (start, node, offset, predicate) => {
- const str = node.data;
- for (let i = offset; start ? i >= 0 : i < str.length; start ? i-- : i++) {
- if (predicate(str.charAt(i))) {
- return start ? i + 1 : i;
- }
- }
- return -1;
- };
- const findSpace = (start, node, offset) => walkText(start, node, offset, c => isNbsp(c) || isWhiteSpace(c));
- const findContent = (start, node, offset) => walkText(start, node, offset, isContent);
- const findWordEndPoint = (dom, body, container, offset, start, includeTrailingSpaces) => {
- let lastTextNode;
- const rootNode = dom.getParent(container, dom.isBlock) || body;
- const walk = (container, offset, pred) => {
- const textSeeker = TextSeeker(dom);
- const walker = start ? textSeeker.backwards : textSeeker.forwards;
- return Optional.from(walker(container, offset, (text, textOffset) => {
- if (isBookmarkNode(text.parentNode)) {
- return -1;
- } else {
- lastTextNode = text;
- return pred(start, text, textOffset);
- }
- }, rootNode));
- };
- const spaceResult = walk(container, offset, findSpace);
- return spaceResult.bind(result => includeTrailingSpaces ? walk(result.container, result.offset + (start ? -1 : 0), findContent) : Optional.some(result)).orThunk(() => lastTextNode ? Optional.some({
- container: lastTextNode,
- offset: start ? 0 : lastTextNode.length
- }) : Optional.none());
- };
- const findSelectorEndPoint = (dom, formatList, rng, container, siblingName) => {
- if (isText$9(container) && isEmpty$3(container.data) && container[siblingName]) {
- container = container[siblingName];
- }
- const parents = getParents$1(dom, container);
- for (let i = 0; i < parents.length; i++) {
- for (let y = 0; y < formatList.length; y++) {
- const curFormat = formatList[y];
- if (isNonNullable(curFormat.collapsed) && curFormat.collapsed !== rng.collapsed) {
- continue;
- }
- if (isSelectorFormat(curFormat) && dom.is(parents[i], curFormat.selector)) {
- return parents[i];
- }
- }
- }
- return container;
- };
- const findBlockEndPoint = (editor, formatList, container, siblingName) => {
- let node = container;
- const dom = editor.dom;
- const root = dom.getRoot();
- const format = formatList[0];
- if (isBlockFormat(format)) {
- node = format.wrapper ? null : dom.getParent(container, format.block, root);
- }
- if (!node) {
- const scopeRoot = dom.getParent(container, 'LI,TD,TH');
- node = dom.getParent(isText$9(container) ? container.parentNode : container, node => node !== root && isTextBlock(editor, node), scopeRoot);
- }
- if (node && isBlockFormat(format) && format.wrapper) {
- node = getParents$1(dom, node, 'ul,ol').reverse()[0] || node;
- }
- if (!node) {
- node = container;
- while (node[siblingName] && !dom.isBlock(node[siblingName])) {
- node = node[siblingName];
- if (isEq$5(node, 'br')) {
- break;
- }
- }
- }
- return node || container;
- };
- const isAtBlockBoundary$1 = (dom, root, container, siblingName) => {
- const parent = container.parentNode;
- if (isNonNullable(container[siblingName])) {
- return false;
- } else if (parent === root || isNullable(parent) || dom.isBlock(parent)) {
- return true;
- } else {
- return isAtBlockBoundary$1(dom, root, parent, siblingName);
- }
- };
- const findParentContainer = (dom, formatList, container, offset, start) => {
- let parent = container;
- const siblingName = start ? 'previousSibling' : 'nextSibling';
- const root = dom.getRoot();
- if (isText$9(container) && !isWhiteSpaceNode(container)) {
- if (start ? offset > 0 : offset < container.data.length) {
- return container;
- }
- }
- while (true) {
- if (!formatList[0].block_expand && dom.isBlock(parent)) {
- return parent;
- }
- for (let sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
- const allowSpaces = isText$9(sibling) && !isAtBlockBoundary$1(dom, root, sibling, siblingName);
- if (!isBookmarkNode(sibling) && !isBogusBr(sibling) && !isWhiteSpaceNode(sibling, allowSpaces)) {
- return parent;
- }
- }
- if (parent === root || parent.parentNode === root) {
- container = parent;
- break;
- }
- parent = parent.parentNode;
- }
- return container;
- };
- const isSelfOrParentBookmark = container => isBookmarkNode(container.parentNode) || isBookmarkNode(container);
- const expandRng = (editor, rng, formatList, includeTrailingSpace = false) => {
- let {startContainer, startOffset, endContainer, endOffset} = rng;
- const dom = editor.dom;
- const format = formatList[0];
- if (isElement$6(startContainer) && startContainer.hasChildNodes()) {
- startContainer = getNode$1(startContainer, startOffset);
- if (isText$9(startContainer)) {
- startOffset = 0;
- }
- }
- if (isElement$6(endContainer) && endContainer.hasChildNodes()) {
- endContainer = getNode$1(endContainer, rng.collapsed ? endOffset : endOffset - 1);
- if (isText$9(endContainer)) {
- endOffset = endContainer.nodeValue.length;
- }
- }
- startContainer = findParentContentEditable(dom, startContainer);
- endContainer = findParentContentEditable(dom, endContainer);
- if (isSelfOrParentBookmark(startContainer)) {
- startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
- if (rng.collapsed) {
- startContainer = startContainer.previousSibling || startContainer;
- } else {
- startContainer = startContainer.nextSibling || startContainer;
- }
- if (isText$9(startContainer)) {
- startOffset = rng.collapsed ? startContainer.length : 0;
- }
- }
- if (isSelfOrParentBookmark(endContainer)) {
- endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
- if (rng.collapsed) {
- endContainer = endContainer.nextSibling || endContainer;
- } else {
- endContainer = endContainer.previousSibling || endContainer;
- }
- if (isText$9(endContainer)) {
- endOffset = rng.collapsed ? 0 : endContainer.length;
- }
- }
- if (rng.collapsed) {
- const startPoint = findWordEndPoint(dom, editor.getBody(), startContainer, startOffset, true, includeTrailingSpace);
- startPoint.each(({container, offset}) => {
- startContainer = container;
- startOffset = offset;
- });
- const endPoint = findWordEndPoint(dom, editor.getBody(), endContainer, endOffset, false, includeTrailingSpace);
- endPoint.each(({container, offset}) => {
- endContainer = container;
- endOffset = offset;
- });
- }
- if (isInlineFormat(format) || format.block_expand) {
- if (!isInlineFormat(format) || (!isText$9(startContainer) || startOffset === 0)) {
- startContainer = findParentContainer(dom, formatList, startContainer, startOffset, true);
- }
- if (!isInlineFormat(format) || (!isText$9(endContainer) || endOffset === endContainer.nodeValue.length)) {
- endContainer = findParentContainer(dom, formatList, endContainer, endOffset, false);
- }
- }
- if (shouldExpandToSelector(format)) {
- startContainer = findSelectorEndPoint(dom, formatList, rng, startContainer, 'previousSibling');
- endContainer = findSelectorEndPoint(dom, formatList, rng, endContainer, 'nextSibling');
- }
- if (isBlockFormat(format) || isSelectorFormat(format)) {
- startContainer = findBlockEndPoint(editor, formatList, startContainer, 'previousSibling');
- endContainer = findBlockEndPoint(editor, formatList, endContainer, 'nextSibling');
- if (isBlockFormat(format)) {
- if (!dom.isBlock(startContainer)) {
- startContainer = findParentContainer(dom, formatList, startContainer, startOffset, true);
- }
- if (!dom.isBlock(endContainer)) {
- endContainer = findParentContainer(dom, formatList, endContainer, endOffset, false);
- }
- }
- }
- if (isElement$6(startContainer)) {
- startOffset = dom.nodeIndex(startContainer);
- startContainer = startContainer.parentNode;
- }
- if (isElement$6(endContainer)) {
- endOffset = dom.nodeIndex(endContainer) + 1;
- endContainer = endContainer.parentNode;
- }
- return {
- startContainer,
- startOffset,
- endContainer,
- endOffset
- };
- };
- const walk$3 = (dom, rng, callback) => {
- const startOffset = rng.startOffset;
- const startContainer = getNode$1(rng.startContainer, startOffset);
- const endOffset = rng.endOffset;
- const endContainer = getNode$1(rng.endContainer, endOffset - 1);
- const exclude = nodes => {
- const firstNode = nodes[0];
- if (isText$9(firstNode) && firstNode === startContainer && startOffset >= firstNode.data.length) {
- nodes.splice(0, 1);
- }
- const lastNode = nodes[nodes.length - 1];
- if (endOffset === 0 && nodes.length > 0 && lastNode === endContainer && isText$9(lastNode)) {
- nodes.splice(nodes.length - 1, 1);
- }
- return nodes;
- };
- const collectSiblings = (node, name, endNode) => {
- const siblings = [];
- for (; node && node !== endNode; node = node[name]) {
- siblings.push(node);
- }
- return siblings;
- };
- const findEndPoint = (node, root) => dom.getParent(node, node => node.parentNode === root, root);
- const walkBoundary = (startNode, endNode, next) => {
- const siblingName = next ? 'nextSibling' : 'previousSibling';
- for (let node = startNode, parent = node.parentNode; node && node !== endNode; node = parent) {
- parent = node.parentNode;
- const siblings = collectSiblings(node === startNode ? node : node[siblingName], siblingName);
- if (siblings.length) {
- if (!next) {
- siblings.reverse();
- }
- callback(exclude(siblings));
- }
- }
- };
- if (startContainer === endContainer) {
- return callback(exclude([startContainer]));
- }
- const ancestor = dom.findCommonAncestor(startContainer, endContainer);
- if (dom.isChildOf(startContainer, endContainer)) {
- return walkBoundary(startContainer, ancestor, true);
- }
- if (dom.isChildOf(endContainer, startContainer)) {
- return walkBoundary(endContainer, ancestor);
- }
- const startPoint = findEndPoint(startContainer, ancestor) || startContainer;
- const endPoint = findEndPoint(endContainer, ancestor) || endContainer;
- walkBoundary(startContainer, startPoint, true);
- const siblings = collectSiblings(startPoint === startContainer ? startPoint : startPoint.nextSibling, 'nextSibling', endPoint === endContainer ? endPoint.nextSibling : endPoint);
- if (siblings.length) {
- callback(exclude(siblings));
- }
- walkBoundary(endContainer, endPoint);
- };
- const getRanges$1 = selection => {
- const ranges = [];
- if (selection) {
- for (let i = 0; i < selection.rangeCount; i++) {
- ranges.push(selection.getRangeAt(i));
- }
- }
- return ranges;
- };
- const getSelectedNodes = ranges => {
- return bind$3(ranges, range => {
- const node = getSelectedNode(range);
- return node ? [SugarElement.fromDom(node)] : [];
- });
- };
- const hasMultipleRanges = selection => {
- return getRanges$1(selection).length > 1;
- };
- const getCellsFromRanges = ranges => filter$6(getSelectedNodes(ranges), isTableCell$4);
- const getCellsFromElement = elm => descendants(elm, 'td[data-mce-selected],th[data-mce-selected]');
- const getCellsFromElementOrRanges = (ranges, element) => {
- const selectedCells = getCellsFromElement(element);
- return selectedCells.length > 0 ? selectedCells : getCellsFromRanges(ranges);
- };
- const getCellsFromEditor = editor => getCellsFromElementOrRanges(getRanges$1(editor.selection.getSel()), SugarElement.fromDom(editor.getBody()));
- const getClosestTable = (cell, isRoot) => ancestor$2(cell, 'table', isRoot);
- const getStartNode = rng => {
- const sc = rng.startContainer, so = rng.startOffset;
- if (isText$9(sc)) {
- return so === 0 ? Optional.some(SugarElement.fromDom(sc)) : Optional.none();
- } else {
- return Optional.from(sc.childNodes[so]).map(SugarElement.fromDom);
- }
- };
- const getEndNode = rng => {
- const ec = rng.endContainer, eo = rng.endOffset;
- if (isText$9(ec)) {
- return eo === ec.data.length ? Optional.some(SugarElement.fromDom(ec)) : Optional.none();
- } else {
- return Optional.from(ec.childNodes[eo - 1]).map(SugarElement.fromDom);
- }
- };
- const getFirstChildren = node => {
- return firstChild(node).fold(constant([node]), child => {
- return [node].concat(getFirstChildren(child));
- });
- };
- const getLastChildren$1 = node => {
- return lastChild(node).fold(constant([node]), child => {
- if (name(child) === 'br') {
- return prevSibling(child).map(sibling => {
- return [node].concat(getLastChildren$1(sibling));
- }).getOr([]);
- } else {
- return [node].concat(getLastChildren$1(child));
- }
- });
- };
- const hasAllContentsSelected = (elm, rng) => {
- return lift2(getStartNode(rng), getEndNode(rng), (startNode, endNode) => {
- const start = find$2(getFirstChildren(elm), curry(eq, startNode));
- const end = find$2(getLastChildren$1(elm), curry(eq, endNode));
- return start.isSome() && end.isSome();
- }).getOr(false);
- };
- const moveEndPoint = (dom, rng, node, start) => {
- const root = node, walker = new DomTreeWalker(node, root);
- const moveCaretBeforeOnEnterElementsMap = filter$5(dom.schema.getMoveCaretBeforeOnEnterElements(), (_, name) => !contains$2([
- 'td',
- 'th',
- 'table'
- ], name.toLowerCase()));
- do {
- if (isText$9(node) && Tools.trim(node.nodeValue).length !== 0) {
- if (start) {
- rng.setStart(node, 0);
- } else {
- rng.setEnd(node, node.nodeValue.length);
- }
- return;
- }
- if (moveCaretBeforeOnEnterElementsMap[node.nodeName]) {
- if (start) {
- rng.setStartBefore(node);
- } else {
- if (node.nodeName === 'BR') {
- rng.setEndBefore(node);
- } else {
- rng.setEndAfter(node);
- }
- }
- return;
- }
- } while (node = start ? walker.next() : walker.prev());
- if (root.nodeName === 'BODY') {
- if (start) {
- rng.setStart(root, 0);
- } else {
- rng.setEnd(root, root.childNodes.length);
- }
- }
- };
- const hasAnyRanges = editor => {
- const sel = editor.selection.getSel();
- return sel && sel.rangeCount > 0;
- };
- const runOnRanges = (editor, executor) => {
- const fakeSelectionNodes = getCellsFromEditor(editor);
- if (fakeSelectionNodes.length > 0) {
- each$f(fakeSelectionNodes, elem => {
- const node = elem.dom;
- const fakeNodeRng = editor.dom.createRng();
- fakeNodeRng.setStartBefore(node);
- fakeNodeRng.setEndAfter(node);
- executor(fakeNodeRng, true);
- });
- } else {
- executor(editor.selection.getRng(), false);
- }
- };
- const preserve = (selection, fillBookmark, executor) => {
- const bookmark = getPersistentBookmark(selection, fillBookmark);
- executor(bookmark);
- selection.moveToBookmark(bookmark);
- };
- const NodeValue = (is, name) => {
- const get = element => {
- if (!is(element)) {
- throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
- }
- return getOption(element).getOr('');
- };
- const getOption = element => is(element) ? Optional.from(element.dom.nodeValue) : Optional.none();
- const set = (element, value) => {
- if (!is(element)) {
- throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
- }
- element.dom.nodeValue = value;
- };
- return {
- get,
- getOption,
- set
- };
- };
- const api$1 = NodeValue(isText$a, 'text');
- const get$3 = element => api$1.get(element);
- const getOption = element => api$1.getOption(element);
- const validBlocks = [
- 'pre[class*=language-][contenteditable="false"]',
- 'figure.image',
- 'div[data-ephox-embed-iri]',
- 'div.tiny-pageembed',
- 'div.mce-toc',
- 'div[data-mce-toc]'
- ];
- const isZeroWidth = elem => isText$a(elem) && get$3(elem) === ZWSP$1;
- const context = (editor, elem, wrapName, nodeName) => parent(elem).fold(() => 'skipping', parent => {
- if (nodeName === 'br' || isZeroWidth(elem)) {
- return 'valid';
- } else if (isAnnotation(elem)) {
- return 'existing';
- } else if (isCaretNode(elem.dom)) {
- return 'caret';
- } else if (exists(validBlocks, selector => is$1(elem, selector))) {
- return 'valid-block';
- } else if (!isValid(editor, wrapName, nodeName) || !isValid(editor, name(parent), wrapName)) {
- return 'invalid-child';
- } else {
- return 'valid';
- }
- });
- const applyWordGrab = (editor, rng) => {
- const r = expandRng(editor, rng, [{ inline: 'span' }]);
- rng.setStart(r.startContainer, r.startOffset);
- rng.setEnd(r.endContainer, r.endOffset);
- editor.selection.setRng(rng);
- };
- const applyAnnotation = (elem, masterUId, data, annotationName, decorate, directAnnotation) => {
- const {uid = masterUId, ...otherData} = data;
- add$2(elem, annotation());
- set$2(elem, `${ dataAnnotationId() }`, uid);
- set$2(elem, `${ dataAnnotation() }`, annotationName);
- const {attributes = {}, classes = []} = decorate(uid, otherData);
- setAll$1(elem, attributes);
- add(elem, classes);
- if (directAnnotation) {
- if (classes.length > 0) {
- set$2(elem, `${ dataAnnotationClasses() }`, classes.join(','));
- }
- const attributeNames = keys(attributes);
- if (attributeNames.length > 0) {
- set$2(elem, `${ dataAnnotationAttributes() }`, attributeNames.join(','));
- }
- }
- };
- const removeDirectAnnotation = elem => {
- remove$8(elem, annotation());
- remove$b(elem, `${ dataAnnotationId() }`);
- remove$b(elem, `${ dataAnnotation() }`);
- remove$b(elem, `${ dataAnnotationActive() }`);
- const customAttrNames = getOpt(elem, `${ dataAnnotationAttributes() }`).map(names => names.split(',')).getOr([]);
- const customClasses = getOpt(elem, `${ dataAnnotationClasses() }`).map(names => names.split(',')).getOr([]);
- each$f(customAttrNames, name => remove$b(elem, name));
- remove$5(elem, customClasses);
- remove$b(elem, `${ dataAnnotationClasses() }`);
- remove$b(elem, `${ dataAnnotationAttributes() }`);
- };
- const makeAnnotation = (eDoc, uid, data, annotationName, decorate) => {
- const master = SugarElement.fromTag('span', eDoc);
- applyAnnotation(master, uid, data, annotationName, decorate, false);
- return master;
- };
- const annotate = (editor, rng, uid, annotationName, decorate, data) => {
- const newWrappers = [];
- const master = makeAnnotation(editor.getDoc(), uid, data, annotationName, decorate);
- const wrapper = value$2();
- const finishWrapper = () => {
- wrapper.clear();
- };
- const getOrOpenWrapper = () => wrapper.get().getOrThunk(() => {
- const nu = shallow$1(master);
- newWrappers.push(nu);
- wrapper.set(nu);
- return nu;
- });
- const processElements = elems => {
- each$f(elems, processElement);
- };
- const processElement = elem => {
- const ctx = context(editor, elem, 'span', name(elem));
- switch (ctx) {
- case 'invalid-child': {
- finishWrapper();
- const children$1 = children(elem);
- processElements(children$1);
- finishWrapper();
- break;
- }
- case 'valid-block': {
- finishWrapper();
- applyAnnotation(elem, uid, data, annotationName, decorate, true);
- break;
- }
- case 'valid': {
- const w = getOrOpenWrapper();
- wrap$2(elem, w);
- break;
- }
- }
- };
- const processNodes = nodes => {
- const elems = map$3(nodes, SugarElement.fromDom);
- processElements(elems);
- };
- walk$3(editor.dom, rng, nodes => {
- finishWrapper();
- processNodes(nodes);
- });
- return newWrappers;
- };
- const annotateWithBookmark = (editor, name, settings, data) => {
- editor.undoManager.transact(() => {
- const selection = editor.selection;
- const initialRng = selection.getRng();
- const hasFakeSelection = getCellsFromEditor(editor).length > 0;
- const masterUid = generate$1('mce-annotation');
- if (initialRng.collapsed && !hasFakeSelection) {
- applyWordGrab(editor, initialRng);
- }
- if (selection.getRng().collapsed && !hasFakeSelection) {
- const wrapper = makeAnnotation(editor.getDoc(), masterUid, data, name, settings.decorate);
- set(wrapper, nbsp);
- selection.getRng().insertNode(wrapper.dom);
- selection.select(wrapper.dom);
- } else {
- preserve(selection, false, () => {
- runOnRanges(editor, selectionRng => {
- annotate(editor, selectionRng, masterUid, name, settings.decorate, data);
- });
- });
- }
- });
- };
- const Annotator = editor => {
- const registry = create$c();
- setup$w(editor, registry);
- const changes = setup$x(editor, registry);
- const isSpan = isTag('span');
- const removeAnnotations = elements => {
- each$f(elements, element => {
- if (isSpan(element)) {
- unwrap(element);
- } else {
- removeDirectAnnotation(element);
- }
- });
- };
- return {
- register: (name, settings) => {
- registry.register(name, settings);
- },
- annotate: (name, data) => {
- registry.lookup(name).each(settings => {
- annotateWithBookmark(editor, name, settings, data);
- });
- },
- annotationChanged: (name, callback) => {
- changes.addListener(name, callback);
- },
- remove: name => {
- const bookmark = editor.selection.getBookmark();
- identify(editor, Optional.some(name)).each(({elements}) => {
- removeAnnotations(elements);
- });
- editor.selection.moveToBookmark(bookmark);
- },
- removeAll: name => {
- const bookmark = editor.selection.getBookmark();
- each$e(findAll(editor, name), (elements, _) => {
- removeAnnotations(elements);
- });
- editor.selection.moveToBookmark(bookmark);
- },
- getAll: name => {
- const directory = findAll(editor, name);
- return map$2(directory, elems => map$3(elems, elem => elem.dom));
- }
- };
- };
- const BookmarkManager = selection => {
- return {
- getBookmark: curry(getBookmark$1, selection),
- moveToBookmark: curry(moveToBookmark, selection)
- };
- };
- BookmarkManager.isBookmarkNode = isBookmarkNode$1;
- const isXYWithinRange = (clientX, clientY, range) => {
- if (range.collapsed) {
- return false;
- } else {
- return exists(range.getClientRects(), rect => containsXY(rect, clientX, clientY));
- }
- };
- const firePreProcess = (editor, args) => editor.dispatch('PreProcess', args);
- const firePostProcess = (editor, args) => editor.dispatch('PostProcess', args);
- const fireRemove = editor => editor.dispatch('remove');
- const fireDetach = editor => editor.dispatch('detach');
- const fireSwitchMode = (editor, mode) => editor.dispatch('SwitchMode', { mode });
- const fireObjectResizeStart = (editor, target, width, height, origin) => {
- editor.dispatch('ObjectResizeStart', {
- target,
- width,
- height,
- origin
- });
- };
- const fireObjectResized = (editor, target, width, height, origin) => {
- editor.dispatch('ObjectResized', {
- target,
- width,
- height,
- origin
- });
- };
- const firePreInit = editor => editor.dispatch('PreInit');
- const firePostRender = editor => editor.dispatch('PostRender');
- const fireInit = editor => editor.dispatch('Init');
- const firePlaceholderToggle = (editor, state) => editor.dispatch('PlaceholderToggle', { state });
- const fireError = (editor, errorType, error) => editor.dispatch(errorType, error);
- const fireFormatApply = (editor, format, node, vars) => editor.dispatch('FormatApply', {
- format,
- node,
- vars
- });
- const fireFormatRemove = (editor, format, node, vars) => editor.dispatch('FormatRemove', {
- format,
- node,
- vars
- });
- const fireBeforeSetContent = (editor, args) => editor.dispatch('BeforeSetContent', args);
- const fireSetContent = (editor, args) => editor.dispatch('SetContent', args);
- const fireBeforeGetContent = (editor, args) => editor.dispatch('BeforeGetContent', args);
- const fireGetContent = (editor, args) => editor.dispatch('GetContent', args);
- const fireAutocompleterStart = (editor, args) => editor.dispatch('AutocompleterStart', args);
- const fireAutocompleterUpdate = (editor, args) => editor.dispatch('AutocompleterUpdate', args);
- const fireAutocompleterEnd = editor => editor.dispatch('AutocompleterEnd');
- const firePastePreProcess = (editor, html, internal) => editor.dispatch('PastePreProcess', {
- content: html,
- internal
- });
- const firePastePostProcess = (editor, node, internal) => editor.dispatch('PastePostProcess', {
- node,
- internal
- });
- const firePastePlainTextToggle = (editor, state) => editor.dispatch('PastePlainTextToggle', { state });
- const VK = {
- BACKSPACE: 8,
- DELETE: 46,
- DOWN: 40,
- ENTER: 13,
- ESC: 27,
- LEFT: 37,
- RIGHT: 39,
- SPACEBAR: 32,
- TAB: 9,
- UP: 38,
- PAGE_UP: 33,
- PAGE_DOWN: 34,
- END: 35,
- HOME: 36,
- modifierPressed: e => {
- return e.shiftKey || e.ctrlKey || e.altKey || VK.metaKeyPressed(e);
- },
- metaKeyPressed: e => {
- return Env.os.isMacOS() || Env.os.isiOS() ? e.metaKey : e.ctrlKey && !e.altKey;
- }
- };
- const elementSelectionAttr = 'data-mce-selected';
- const controlElmSelector = 'table,img,figure.image,hr,video,span.mce-preview-object';
- const abs = Math.abs;
- const round$1 = Math.round;
- const resizeHandles = {
- nw: [
- 0,
- 0,
- -1,
- -1
- ],
- ne: [
- 1,
- 0,
- 1,
- -1
- ],
- se: [
- 1,
- 1,
- 1,
- 1
- ],
- sw: [
- 0,
- 1,
- -1,
- 1
- ]
- };
- const isTouchEvent = evt => evt.type === 'longpress' || evt.type.indexOf('touch') === 0;
- const ControlSelection = (selection, editor) => {
- const dom = editor.dom;
- const editableDoc = editor.getDoc();
- const rootDocument = document;
- const rootElement = editor.getBody();
- let selectedElm, selectedElmGhost, resizeHelper, selectedHandle, resizeBackdrop;
- let startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted;
- let width;
- let height;
- let startScrollWidth;
- let startScrollHeight;
- const isImage = elm => isNonNullable(elm) && (isImg(elm) || dom.is(elm, 'figure.image'));
- const isMedia = elm => isMedia$2(elm) || dom.hasClass(elm, 'mce-preview-object');
- const isEventOnImageOutsideRange = (evt, range) => {
- if (isTouchEvent(evt)) {
- const touch = evt.touches[0];
- return isImage(evt.target) && !isXYWithinRange(touch.clientX, touch.clientY, range);
- } else {
- return isImage(evt.target) && !isXYWithinRange(evt.clientX, evt.clientY, range);
- }
- };
- const contextMenuSelectImage = evt => {
- const target = evt.target;
- if (isEventOnImageOutsideRange(evt, editor.selection.getRng()) && !evt.isDefaultPrevented()) {
- editor.selection.select(target);
- }
- };
- const getResizeTargets = elm => {
- if (dom.is(elm, 'figure.image')) {
- return [elm.querySelector('img')];
- } else if (dom.hasClass(elm, 'mce-preview-object') && isNonNullable(elm.firstElementChild)) {
- return [
- elm,
- elm.firstElementChild
- ];
- } else {
- return [elm];
- }
- };
- const isResizable = elm => {
- const selector = getObjectResizing(editor);
- if (!selector) {
- return false;
- }
- if (elm.getAttribute('data-mce-resize') === 'false') {
- return false;
- }
- if (elm === editor.getBody()) {
- return false;
- }
- if (dom.hasClass(elm, 'mce-preview-object')) {
- return is$1(SugarElement.fromDom(elm.firstElementChild), selector);
- } else {
- return is$1(SugarElement.fromDom(elm), selector);
- }
- };
- const createGhostElement = elm => {
- if (isMedia(elm)) {
- return dom.create('img', { src: Env.transparentSrc });
- } else {
- return elm.cloneNode(true);
- }
- };
- const setSizeProp = (element, name, value) => {
- if (isNonNullable(value)) {
- const targets = getResizeTargets(element);
- each$f(targets, target => {
- if (target.style[name] || !editor.schema.isValid(target.nodeName.toLowerCase(), name)) {
- dom.setStyle(target, name, value);
- } else {
- dom.setAttrib(target, name, '' + value);
- }
- });
- }
- };
- const setGhostElmSize = (ghostElm, width, height) => {
- setSizeProp(ghostElm, 'width', width);
- setSizeProp(ghostElm, 'height', height);
- };
- const resizeGhostElement = e => {
- let deltaX, deltaY, proportional;
- let resizeHelperX, resizeHelperY;
- deltaX = e.screenX - startX;
- deltaY = e.screenY - startY;
- width = deltaX * selectedHandle[2] + startW;
- height = deltaY * selectedHandle[3] + startH;
- width = width < 5 ? 5 : width;
- height = height < 5 ? 5 : height;
- if ((isImage(selectedElm) || isMedia(selectedElm)) && getResizeImgProportional(editor) !== false) {
- proportional = !VK.modifierPressed(e);
- } else {
- proportional = VK.modifierPressed(e);
- }
- if (proportional) {
- if (abs(deltaX) > abs(deltaY)) {
- height = round$1(width * ratio);
- width = round$1(height / ratio);
- } else {
- width = round$1(height / ratio);
- height = round$1(width * ratio);
- }
- }
- setGhostElmSize(selectedElmGhost, width, height);
- resizeHelperX = selectedHandle.startPos.x + deltaX;
- resizeHelperY = selectedHandle.startPos.y + deltaY;
- resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0;
- resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0;
- dom.setStyles(resizeHelper, {
- left: resizeHelperX,
- top: resizeHelperY,
- display: 'block'
- });
- resizeHelper.innerHTML = width + ' × ' + height;
- if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
- dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
- }
- if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
- dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
- }
- deltaX = rootElement.scrollWidth - startScrollWidth;
- deltaY = rootElement.scrollHeight - startScrollHeight;
- if (deltaX + deltaY !== 0) {
- dom.setStyles(resizeHelper, {
- left: resizeHelperX - deltaX,
- top: resizeHelperY - deltaY
- });
- }
- if (!resizeStarted) {
- fireObjectResizeStart(editor, selectedElm, startW, startH, 'corner-' + selectedHandle.name);
- resizeStarted = true;
- }
- };
- const endGhostResize = () => {
- const wasResizeStarted = resizeStarted;
- resizeStarted = false;
- if (wasResizeStarted) {
- setSizeProp(selectedElm, 'width', width);
- setSizeProp(selectedElm, 'height', height);
- }
- dom.unbind(editableDoc, 'mousemove', resizeGhostElement);
- dom.unbind(editableDoc, 'mouseup', endGhostResize);
- if (rootDocument !== editableDoc) {
- dom.unbind(rootDocument, 'mousemove', resizeGhostElement);
- dom.unbind(rootDocument, 'mouseup', endGhostResize);
- }
- dom.remove(selectedElmGhost);
- dom.remove(resizeHelper);
- dom.remove(resizeBackdrop);
- showResizeRect(selectedElm);
- if (wasResizeStarted) {
- fireObjectResized(editor, selectedElm, width, height, 'corner-' + selectedHandle.name);
- dom.setAttrib(selectedElm, 'style', dom.getAttrib(selectedElm, 'style'));
- }
- editor.nodeChanged();
- };
- const showResizeRect = targetElm => {
- unbindResizeHandleEvents();
- const position = dom.getPos(targetElm, rootElement);
- const selectedElmX = position.x;
- const selectedElmY = position.y;
- const rect = targetElm.getBoundingClientRect();
- const targetWidth = rect.width || rect.right - rect.left;
- const targetHeight = rect.height || rect.bottom - rect.top;
- if (selectedElm !== targetElm) {
- hideResizeRect();
- selectedElm = targetElm;
- width = height = 0;
- }
- const e = editor.dispatch('ObjectSelected', { target: targetElm });
- if (isResizable(targetElm) && !e.isDefaultPrevented()) {
- each$e(resizeHandles, (handle, name) => {
- let handleElm;
- const startDrag = e => {
- const target = getResizeTargets(selectedElm)[0];
- startX = e.screenX;
- startY = e.screenY;
- startW = target.clientWidth;
- startH = target.clientHeight;
- ratio = startH / startW;
- selectedHandle = handle;
- selectedHandle.name = name;
- selectedHandle.startPos = {
- x: targetWidth * handle[0] + selectedElmX,
- y: targetHeight * handle[1] + selectedElmY
- };
- startScrollWidth = rootElement.scrollWidth;
- startScrollHeight = rootElement.scrollHeight;
- resizeBackdrop = dom.add(rootElement, 'div', {
- 'class': 'mce-resize-backdrop',
- 'data-mce-bogus': 'all'
- });
- dom.setStyles(resizeBackdrop, {
- position: 'fixed',
- left: '0',
- top: '0',
- width: '100%',
- height: '100%'
- });
- selectedElmGhost = createGhostElement(selectedElm);
- dom.addClass(selectedElmGhost, 'mce-clonedresizable');
- dom.setAttrib(selectedElmGhost, 'data-mce-bogus', 'all');
- selectedElmGhost.contentEditable = 'false';
- dom.setStyles(selectedElmGhost, {
- left: selectedElmX,
- top: selectedElmY,
- margin: 0
- });
- setGhostElmSize(selectedElmGhost, targetWidth, targetHeight);
- selectedElmGhost.removeAttribute(elementSelectionAttr);
- rootElement.appendChild(selectedElmGhost);
- dom.bind(editableDoc, 'mousemove', resizeGhostElement);
- dom.bind(editableDoc, 'mouseup', endGhostResize);
- if (rootDocument !== editableDoc) {
- dom.bind(rootDocument, 'mousemove', resizeGhostElement);
- dom.bind(rootDocument, 'mouseup', endGhostResize);
- }
- resizeHelper = dom.add(rootElement, 'div', {
- 'class': 'mce-resize-helper',
- 'data-mce-bogus': 'all'
- }, startW + ' × ' + startH);
- };
- handleElm = dom.get('mceResizeHandle' + name);
- if (handleElm) {
- dom.remove(handleElm);
- }
- handleElm = dom.add(rootElement, 'div', {
- 'id': 'mceResizeHandle' + name,
- 'data-mce-bogus': 'all',
- 'class': 'mce-resizehandle',
- 'unselectable': true,
- 'style': 'cursor:' + name + '-resize; margin:0; padding:0'
- });
- dom.bind(handleElm, 'mousedown', e => {
- e.stopImmediatePropagation();
- e.preventDefault();
- startDrag(e);
- });
- handle.elm = handleElm;
- dom.setStyles(handleElm, {
- left: targetWidth * handle[0] + selectedElmX - handleElm.offsetWidth / 2,
- top: targetHeight * handle[1] + selectedElmY - handleElm.offsetHeight / 2
- });
- });
- } else {
- hideResizeRect(false);
- }
- };
- const throttledShowResizeRect = first$1(showResizeRect, 0);
- const hideResizeRect = (removeSelected = true) => {
- throttledShowResizeRect.cancel();
- unbindResizeHandleEvents();
- if (selectedElm && removeSelected) {
- selectedElm.removeAttribute(elementSelectionAttr);
- }
- each$e(resizeHandles, (value, name) => {
- const handleElm = dom.get('mceResizeHandle' + name);
- if (handleElm) {
- dom.unbind(handleElm);
- dom.remove(handleElm);
- }
- });
- };
- const isChildOrEqual = (node, parent) => isNonNullable(node) && dom.isChildOf(node, parent);
- const updateResizeRect = e => {
- if (resizeStarted || editor.removed || editor.composing) {
- return;
- }
- const targetElm = e.type === 'mousedown' ? e.target : selection.getNode();
- const controlElm = closest$3(SugarElement.fromDom(targetElm), controlElmSelector).map(e => e.dom).getOrUndefined();
- const selectedValue = isNonNullable(controlElm) ? dom.getAttrib(controlElm, elementSelectionAttr, '1') : '1';
- each$f(dom.select(`img[${ elementSelectionAttr }],hr[${ elementSelectionAttr }]`), img => {
- img.removeAttribute(elementSelectionAttr);
- });
- if (isChildOrEqual(controlElm, rootElement)) {
- disableGeckoResize();
- const startElm = selection.getStart(true);
- if (isChildOrEqual(startElm, controlElm) && isChildOrEqual(selection.getEnd(true), controlElm)) {
- dom.setAttrib(controlElm, elementSelectionAttr, selectedValue);
- throttledShowResizeRect.throttle(controlElm);
- return;
- }
- }
- hideResizeRect();
- };
- const unbindResizeHandleEvents = () => {
- each$e(resizeHandles, handle => {
- if (handle.elm) {
- dom.unbind(handle.elm);
- delete handle.elm;
- }
- });
- };
- const disableGeckoResize = () => {
- try {
- editor.getDoc().execCommand('enableObjectResizing', false, 'false');
- } catch (ex) {
- }
- };
- editor.on('init', () => {
- disableGeckoResize();
- editor.on('NodeChange ResizeEditor ResizeWindow ResizeContent drop', updateResizeRect);
- editor.on('keyup compositionend', e => {
- if (selectedElm && selectedElm.nodeName === 'TABLE') {
- updateResizeRect(e);
- }
- });
- editor.on('hide blur', hideResizeRect);
- editor.on('contextmenu longpress', contextMenuSelectImage, true);
- });
- editor.on('remove', unbindResizeHandleEvents);
- const destroy = () => {
- throttledShowResizeRect.cancel();
- selectedElm = selectedElmGhost = resizeBackdrop = null;
- };
- return {
- isResizable,
- showResizeRect,
- hideResizeRect,
- updateResizeRect,
- destroy
- };
- };
- const setStart = (rng, situ) => {
- situ.fold(e => {
- rng.setStartBefore(e.dom);
- }, (e, o) => {
- rng.setStart(e.dom, o);
- }, e => {
- rng.setStartAfter(e.dom);
- });
- };
- const setFinish = (rng, situ) => {
- situ.fold(e => {
- rng.setEndBefore(e.dom);
- }, (e, o) => {
- rng.setEnd(e.dom, o);
- }, e => {
- rng.setEndAfter(e.dom);
- });
- };
- const relativeToNative = (win, startSitu, finishSitu) => {
- const range = win.document.createRange();
- setStart(range, startSitu);
- setFinish(range, finishSitu);
- return range;
- };
- const exactToNative = (win, start, soffset, finish, foffset) => {
- const rng = win.document.createRange();
- rng.setStart(start.dom, soffset);
- rng.setEnd(finish.dom, foffset);
- return rng;
- };
- const adt$3 = Adt.generate([
- {
- ltr: [
- 'start',
- 'soffset',
- 'finish',
- 'foffset'
- ]
- },
- {
- rtl: [
- 'start',
- 'soffset',
- 'finish',
- 'foffset'
- ]
- }
- ]);
- const fromRange = (win, type, range) => type(SugarElement.fromDom(range.startContainer), range.startOffset, SugarElement.fromDom(range.endContainer), range.endOffset);
- const getRanges = (win, selection) => selection.match({
- domRange: rng => {
- return {
- ltr: constant(rng),
- rtl: Optional.none
- };
- },
- relative: (startSitu, finishSitu) => {
- return {
- ltr: cached(() => relativeToNative(win, startSitu, finishSitu)),
- rtl: cached(() => Optional.some(relativeToNative(win, finishSitu, startSitu)))
- };
- },
- exact: (start, soffset, finish, foffset) => {
- return {
- ltr: cached(() => exactToNative(win, start, soffset, finish, foffset)),
- rtl: cached(() => Optional.some(exactToNative(win, finish, foffset, start, soffset)))
- };
- }
- });
- const doDiagnose = (win, ranges) => {
- const rng = ranges.ltr();
- if (rng.collapsed) {
- const reversed = ranges.rtl().filter(rev => rev.collapsed === false);
- return reversed.map(rev => adt$3.rtl(SugarElement.fromDom(rev.endContainer), rev.endOffset, SugarElement.fromDom(rev.startContainer), rev.startOffset)).getOrThunk(() => fromRange(win, adt$3.ltr, rng));
- } else {
- return fromRange(win, adt$3.ltr, rng);
- }
- };
- const diagnose = (win, selection) => {
- const ranges = getRanges(win, selection);
- return doDiagnose(win, ranges);
- };
- adt$3.ltr;
- adt$3.rtl;
- const create$a = (start, soffset, finish, foffset) => ({
- start,
- soffset,
- finish,
- foffset
- });
- const SimRange = { create: create$a };
- const caretPositionFromPoint = (doc, x, y) => {
- var _a, _b;
- return Optional.from((_b = (_a = doc.dom).caretPositionFromPoint) === null || _b === void 0 ? void 0 : _b.call(_a, x, y)).bind(pos => {
- if (pos.offsetNode === null) {
- return Optional.none();
- }
- const r = doc.dom.createRange();
- r.setStart(pos.offsetNode, pos.offset);
- r.collapse();
- return Optional.some(r);
- });
- };
- const caretRangeFromPoint = (doc, x, y) => {
- var _a, _b;
- return Optional.from((_b = (_a = doc.dom).caretRangeFromPoint) === null || _b === void 0 ? void 0 : _b.call(_a, x, y));
- };
- const availableSearch = (() => {
- if (document.caretPositionFromPoint) {
- return caretPositionFromPoint;
- } else if (document.caretRangeFromPoint) {
- return caretRangeFromPoint;
- } else {
- return Optional.none;
- }
- })();
- const fromPoint$1 = (win, x, y) => {
- const doc = SugarElement.fromDom(win.document);
- return availableSearch(doc, x, y).map(rng => SimRange.create(SugarElement.fromDom(rng.startContainer), rng.startOffset, SugarElement.fromDom(rng.endContainer), rng.endOffset));
- };
- const adt$2 = Adt.generate([
- { before: ['element'] },
- {
- on: [
- 'element',
- 'offset'
- ]
- },
- { after: ['element'] }
- ]);
- const cata = (subject, onBefore, onOn, onAfter) => subject.fold(onBefore, onOn, onAfter);
- const getStart$2 = situ => situ.fold(identity, identity, identity);
- const before$1 = adt$2.before;
- const on = adt$2.on;
- const after$1 = adt$2.after;
- const Situ = {
- before: before$1,
- on,
- after: after$1,
- cata,
- getStart: getStart$2
- };
- const adt$1 = Adt.generate([
- { domRange: ['rng'] },
- {
- relative: [
- 'startSitu',
- 'finishSitu'
- ]
- },
- {
- exact: [
- 'start',
- 'soffset',
- 'finish',
- 'foffset'
- ]
- }
- ]);
- const exactFromRange = simRange => adt$1.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset);
- const getStart$1 = selection => selection.match({
- domRange: rng => SugarElement.fromDom(rng.startContainer),
- relative: (startSitu, _finishSitu) => Situ.getStart(startSitu),
- exact: (start, _soffset, _finish, _foffset) => start
- });
- const domRange = adt$1.domRange;
- const relative = adt$1.relative;
- const exact = adt$1.exact;
- const getWin = selection => {
- const start = getStart$1(selection);
- return defaultView(start);
- };
- const range = SimRange.create;
- const SimSelection = {
- domRange,
- relative,
- exact,
- exactFromRange,
- getWin,
- range
- };
- const beforeSpecial = (element, offset) => {
- const name$1 = name(element);
- if ('input' === name$1) {
- return Situ.after(element);
- } else if (!contains$2([
- 'br',
- 'img'
- ], name$1)) {
- return Situ.on(element, offset);
- } else {
- return offset === 0 ? Situ.before(element) : Situ.after(element);
- }
- };
- const preprocessRelative = (startSitu, finishSitu) => {
- const start = startSitu.fold(Situ.before, beforeSpecial, Situ.after);
- const finish = finishSitu.fold(Situ.before, beforeSpecial, Situ.after);
- return SimSelection.relative(start, finish);
- };
- const preprocessExact = (start, soffset, finish, foffset) => {
- const startSitu = beforeSpecial(start, soffset);
- const finishSitu = beforeSpecial(finish, foffset);
- return SimSelection.relative(startSitu, finishSitu);
- };
- const preprocess = selection => selection.match({
- domRange: rng => {
- const start = SugarElement.fromDom(rng.startContainer);
- const finish = SugarElement.fromDom(rng.endContainer);
- return preprocessExact(start, rng.startOffset, finish, rng.endOffset);
- },
- relative: preprocessRelative,
- exact: preprocessExact
- });
- const fromElements = (elements, scope) => {
- const doc = scope || document;
- const fragment = doc.createDocumentFragment();
- each$f(elements, element => {
- fragment.appendChild(element.dom);
- });
- return SugarElement.fromDom(fragment);
- };
- const toNative = selection => {
- const win = SimSelection.getWin(selection).dom;
- const getDomRange = (start, soffset, finish, foffset) => exactToNative(win, start, soffset, finish, foffset);
- const filtered = preprocess(selection);
- return diagnose(win, filtered).match({
- ltr: getDomRange,
- rtl: getDomRange
- });
- };
- const getAtPoint = (win, x, y) => fromPoint$1(win, x, y);
- const fromPoint = (clientX, clientY, doc) => getAtPoint(doc.defaultView, clientX, clientY).map(simRange => {
- const rng = doc.createRange();
- rng.setStart(simRange.start.dom, simRange.soffset);
- rng.setEnd(simRange.finish.dom, simRange.foffset);
- return rng;
- }).getOrUndefined();
- const isEq$4 = (rng1, rng2) => {
- return rng1 && rng2 && (rng1.startContainer === rng2.startContainer && rng1.startOffset === rng2.startOffset) && (rng1.endContainer === rng2.endContainer && rng1.endOffset === rng2.endOffset);
- };
- const findParent = (node, rootNode, predicate) => {
- while (node && node !== rootNode) {
- if (predicate(node)) {
- return node;
- }
- node = node.parentNode;
- }
- return null;
- };
- const hasParent$1 = (node, rootNode, predicate) => findParent(node, rootNode, predicate) !== null;
- const hasParentWithName = (node, rootNode, name) => hasParent$1(node, rootNode, node => {
- return node.nodeName === name;
- });
- const isTable = node => node && node.nodeName === 'TABLE';
- const isTableCell$2 = node => node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
- const isCeFalseCaretContainer = (node, rootNode) => isCaretContainer$2(node) && hasParent$1(node, rootNode, isCaretNode) === false;
- const hasBrBeforeAfter = (dom, node, left) => {
- const walker = new DomTreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || dom.getRoot());
- while (node = walker[left ? 'prev' : 'next']()) {
- if (isBr$6(node)) {
- return true;
- }
- }
- };
- const isPrevNode = (node, name) => node.previousSibling && node.previousSibling.nodeName === name;
- const hasContentEditableFalseParent = (body, node) => {
- while (node && node !== body) {
- if (isContentEditableFalse$b(node)) {
- return true;
- }
- node = node.parentNode;
- }
- return false;
- };
- const findTextNodeRelative = (dom, isAfterNode, collapsed, left, startNode) => {
- let lastInlineElement;
- const body = dom.getRoot();
- let node;
- const nonEmptyElementsMap = dom.schema.getNonEmptyElements();
- const parentBlockContainer = dom.getParent(startNode.parentNode, dom.isBlock) || body;
- if (left && isBr$6(startNode) && isAfterNode && dom.isEmpty(parentBlockContainer)) {
- return Optional.some(CaretPosition(startNode.parentNode, dom.nodeIndex(startNode)));
- }
- const walker = new DomTreeWalker(startNode, parentBlockContainer);
- while (node = walker[left ? 'prev' : 'next']()) {
- if (dom.getContentEditableParent(node) === 'false' || isCeFalseCaretContainer(node, body)) {
- return Optional.none();
- }
- if (isText$9(node) && node.nodeValue.length > 0) {
- if (hasParentWithName(node, body, 'A') === false) {
- return Optional.some(CaretPosition(node, left ? node.nodeValue.length : 0));
- }
- return Optional.none();
- }
- if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
- return Optional.none();
- }
- lastInlineElement = node;
- }
- if (isComment(lastInlineElement)) {
- return Optional.none();
- }
- if (collapsed && lastInlineElement) {
- return Optional.some(CaretPosition(lastInlineElement, 0));
- }
- return Optional.none();
- };
- const normalizeEndPoint = (dom, collapsed, start, rng) => {
- let container, offset;
- const body = dom.getRoot();
- let node;
- let directionLeft, normalized = false;
- container = rng[(start ? 'start' : 'end') + 'Container'];
- offset = rng[(start ? 'start' : 'end') + 'Offset'];
- const isAfterNode = isElement$6(container) && offset === container.childNodes.length;
- const nonEmptyElementsMap = dom.schema.getNonEmptyElements();
- directionLeft = start;
- if (isCaretContainer$2(container)) {
- return Optional.none();
- }
- if (isElement$6(container) && offset > container.childNodes.length - 1) {
- directionLeft = false;
- }
- if (isDocument$1(container)) {
- container = body;
- offset = 0;
- }
- if (container === body) {
- if (directionLeft) {
- node = container.childNodes[offset > 0 ? offset - 1 : 0];
- if (node) {
- if (isCaretContainer$2(node)) {
- return Optional.none();
- }
- if (nonEmptyElementsMap[node.nodeName] || isTable(node)) {
- return Optional.none();
- }
- }
- }
- if (container.hasChildNodes()) {
- offset = Math.min(!directionLeft && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1);
- container = container.childNodes[offset];
- offset = isText$9(container) && isAfterNode ? container.data.length : 0;
- if (!collapsed && container === body.lastChild && isTable(container)) {
- return Optional.none();
- }
- if (hasContentEditableFalseParent(body, container) || isCaretContainer$2(container)) {
- return Optional.none();
- }
- if (container.hasChildNodes() && isTable(container) === false) {
- node = container;
- const walker = new DomTreeWalker(container, body);
- do {
- if (isContentEditableFalse$b(node) || isCaretContainer$2(node)) {
- normalized = false;
- break;
- }
- if (isText$9(node) && node.nodeValue.length > 0) {
- offset = directionLeft ? 0 : node.nodeValue.length;
- container = node;
- normalized = true;
- break;
- }
- if (nonEmptyElementsMap[node.nodeName.toLowerCase()] && !isTableCell$2(node)) {
- offset = dom.nodeIndex(node);
- container = node.parentNode;
- if (!directionLeft) {
- offset++;
- }
- normalized = true;
- break;
- }
- } while (node = directionLeft ? walker.next() : walker.prev());
- }
- }
- }
- if (collapsed) {
- if (isText$9(container) && offset === 0) {
- findTextNodeRelative(dom, isAfterNode, collapsed, true, container).each(pos => {
- container = pos.container();
- offset = pos.offset();
- normalized = true;
- });
- }
- if (isElement$6(container)) {
- node = container.childNodes[offset];
- if (!node) {
- node = container.childNodes[offset - 1];
- }
- if (node && isBr$6(node) && !isPrevNode(node, 'A') && !hasBrBeforeAfter(dom, node, false) && !hasBrBeforeAfter(dom, node, true)) {
- findTextNodeRelative(dom, isAfterNode, collapsed, true, node).each(pos => {
- container = pos.container();
- offset = pos.offset();
- normalized = true;
- });
- }
- }
- }
- if (directionLeft && !collapsed && isText$9(container) && offset === container.nodeValue.length) {
- findTextNodeRelative(dom, isAfterNode, collapsed, false, container).each(pos => {
- container = pos.container();
- offset = pos.offset();
- normalized = true;
- });
- }
- return normalized ? Optional.some(CaretPosition(container, offset)) : Optional.none();
- };
- const normalize$2 = (dom, rng) => {
- const collapsed = rng.collapsed, normRng = rng.cloneRange();
- const startPos = CaretPosition.fromRangeStart(rng);
- normalizeEndPoint(dom, collapsed, true, normRng).each(pos => {
- if (!collapsed || !CaretPosition.isAbove(startPos, pos)) {
- normRng.setStart(pos.container(), pos.offset());
- }
- });
- if (!collapsed) {
- normalizeEndPoint(dom, collapsed, false, normRng).each(pos => {
- normRng.setEnd(pos.container(), pos.offset());
- });
- }
- if (collapsed) {
- normRng.collapse(true);
- }
- return isEq$4(rng, normRng) ? Optional.none() : Optional.some(normRng);
- };
- const splitText = (node, offset) => {
- return node.splitText(offset);
- };
- const split = rng => {
- let startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;
- if (startContainer === endContainer && isText$9(startContainer)) {
- if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
- endContainer = splitText(startContainer, startOffset);
- startContainer = endContainer.previousSibling;
- if (endOffset > startOffset) {
- endOffset = endOffset - startOffset;
- startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
- endOffset = endContainer.nodeValue.length;
- startOffset = 0;
- } else {
- endOffset = 0;
- }
- }
- } else {
- if (isText$9(startContainer) && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
- startContainer = splitText(startContainer, startOffset);
- startOffset = 0;
- }
- if (isText$9(endContainer) && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
- endContainer = splitText(endContainer, endOffset).previousSibling;
- endOffset = endContainer.nodeValue.length;
- }
- }
- return {
- startContainer,
- startOffset,
- endContainer,
- endOffset
- };
- };
- const RangeUtils = dom => {
- const walk = (rng, callback) => {
- return walk$3(dom, rng, callback);
- };
- const split$1 = split;
- const normalize = rng => {
- return normalize$2(dom, rng).fold(never, normalizedRng => {
- rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);
- rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);
- return true;
- });
- };
- return {
- walk,
- split: split$1,
- normalize
- };
- };
- RangeUtils.compareRanges = isEq$4;
- RangeUtils.getCaretRangeFromPoint = fromPoint;
- RangeUtils.getSelectedNode = getSelectedNode;
- RangeUtils.getNode = getNode$1;
- const Dimension = (name, getOffset) => {
- const set = (element, h) => {
- if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
- throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
- }
- const dom = element.dom;
- if (isSupported$1(dom)) {
- dom.style[name] = h + 'px';
- }
- };
- const get = element => {
- const r = getOffset(element);
- if (r <= 0 || r === null) {
- const css = get$7(element, name);
- return parseFloat(css) || 0;
- }
- return r;
- };
- const getOuter = get;
- const aggregate = (element, properties) => foldl(properties, (acc, property) => {
- const val = get$7(element, property);
- const value = val === undefined ? 0 : parseInt(val, 10);
- return isNaN(value) ? acc : acc + value;
- }, 0);
- const max = (element, value, properties) => {
- const cumulativeInclusions = aggregate(element, properties);
- const absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
- return absoluteMax;
- };
- return {
- set,
- get,
- getOuter,
- aggregate,
- max
- };
- };
- const api = Dimension('height', element => {
- const dom = element.dom;
- return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
- });
- const get$2 = element => api.get(element);
- const getDocument = () => SugarElement.fromDom(document);
- const walkUp = (navigation, doc) => {
- const frame = navigation.view(doc);
- return frame.fold(constant([]), f => {
- const parent = navigation.owner(f);
- const rest = walkUp(navigation, parent);
- return [f].concat(rest);
- });
- };
- const pathTo = (element, navigation) => {
- const d = navigation.owner(element);
- return walkUp(navigation, d);
- };
- const view = doc => {
- var _a;
- const element = doc.dom === document ? Optional.none() : Optional.from((_a = doc.dom.defaultView) === null || _a === void 0 ? void 0 : _a.frameElement);
- return element.map(SugarElement.fromDom);
- };
- const owner = element => documentOrOwner(element);
- var Navigation = /*#__PURE__*/Object.freeze({
- __proto__: null,
- view: view,
- owner: owner
- });
- const find = element => {
- const doc = getDocument();
- const scroll = get$5(doc);
- const frames = pathTo(element, Navigation);
- const offset = viewport(element);
- const r = foldr(frames, (b, a) => {
- const loc = viewport(a);
- return {
- left: b.left + loc.left,
- top: b.top + loc.top
- };
- }, {
- left: 0,
- top: 0
- });
- return SugarPosition(r.left + offset.left + scroll.left, r.top + offset.top + scroll.top);
- };
- const excludeFromDescend = element => name(element) === 'textarea';
- const fireScrollIntoViewEvent = (editor, data) => {
- const scrollEvent = editor.dispatch('ScrollIntoView', data);
- return scrollEvent.isDefaultPrevented();
- };
- const fireAfterScrollIntoViewEvent = (editor, data) => {
- editor.dispatch('AfterScrollIntoView', data);
- };
- const descend = (element, offset) => {
- const children$1 = children(element);
- if (children$1.length === 0 || excludeFromDescend(element)) {
- return {
- element,
- offset
- };
- } else if (offset < children$1.length && !excludeFromDescend(children$1[offset])) {
- return {
- element: children$1[offset],
- offset: 0
- };
- } else {
- const last = children$1[children$1.length - 1];
- if (excludeFromDescend(last)) {
- return {
- element,
- offset
- };
- } else {
- if (name(last) === 'img') {
- return {
- element: last,
- offset: 1
- };
- } else if (isText$a(last)) {
- return {
- element: last,
- offset: get$3(last).length
- };
- } else {
- return {
- element: last,
- offset: children(last).length
- };
- }
- }
- }
- };
- const markerInfo = (element, cleanupFun) => {
- const pos = absolute(element);
- const height = get$2(element);
- return {
- element,
- bottom: pos.top + height,
- height,
- pos,
- cleanup: cleanupFun
- };
- };
- const createMarker$1 = (element, offset) => {
- const startPoint = descend(element, offset);
- const span = SugarElement.fromHtml('<span data-mce-bogus="all" style="display: inline-block;">' + ZWSP$1 + '</span>');
- before$3(startPoint.element, span);
- return markerInfo(span, () => remove$6(span));
- };
- const elementMarker = element => markerInfo(SugarElement.fromDom(element), noop);
- const withMarker = (editor, f, rng, alignToTop) => {
- preserveWith(editor, (_s, _e) => applyWithMarker(editor, f, rng, alignToTop), rng);
- };
- const withScrollEvents = (editor, doc, f, marker, alignToTop) => {
- const data = {
- elm: marker.element.dom,
- alignToTop
- };
- if (fireScrollIntoViewEvent(editor, data)) {
- return;
- }
- const scrollTop = get$5(doc).top;
- f(doc, scrollTop, marker, alignToTop);
- fireAfterScrollIntoViewEvent(editor, data);
- };
- const applyWithMarker = (editor, f, rng, alignToTop) => {
- const body = SugarElement.fromDom(editor.getBody());
- const doc = SugarElement.fromDom(editor.getDoc());
- reflow(body);
- const marker = createMarker$1(SugarElement.fromDom(rng.startContainer), rng.startOffset);
- withScrollEvents(editor, doc, f, marker, alignToTop);
- marker.cleanup();
- };
- const withElement = (editor, element, f, alignToTop) => {
- const doc = SugarElement.fromDom(editor.getDoc());
- withScrollEvents(editor, doc, f, elementMarker(element), alignToTop);
- };
- const preserveWith = (editor, f, rng) => {
- const startElement = rng.startContainer;
- const startOffset = rng.startOffset;
- const endElement = rng.endContainer;
- const endOffset = rng.endOffset;
- f(SugarElement.fromDom(startElement), SugarElement.fromDom(endElement));
- const newRng = editor.dom.createRng();
- newRng.setStart(startElement, startOffset);
- newRng.setEnd(endElement, endOffset);
- editor.selection.setRng(rng);
- };
- const scrollToMarker = (marker, viewHeight, alignToTop, doc) => {
- const pos = marker.pos;
- if (alignToTop) {
- to(pos.left, pos.top, doc);
- } else {
- const y = pos.top - viewHeight + marker.height;
- to(pos.left, y, doc);
- }
- };
- const intoWindowIfNeeded = (doc, scrollTop, viewHeight, marker, alignToTop) => {
- const viewportBottom = viewHeight + scrollTop;
- const markerTop = marker.pos.top;
- const markerBottom = marker.bottom;
- const largerThanViewport = markerBottom - markerTop >= viewHeight;
- if (markerTop < scrollTop) {
- scrollToMarker(marker, viewHeight, alignToTop !== false, doc);
- } else if (markerTop > viewportBottom) {
- const align = largerThanViewport ? alignToTop !== false : alignToTop === true;
- scrollToMarker(marker, viewHeight, align, doc);
- } else if (markerBottom > viewportBottom && !largerThanViewport) {
- scrollToMarker(marker, viewHeight, alignToTop === true, doc);
- }
- };
- const intoWindow = (doc, scrollTop, marker, alignToTop) => {
- const viewHeight = doc.dom.defaultView.innerHeight;
- intoWindowIfNeeded(doc, scrollTop, viewHeight, marker, alignToTop);
- };
- const intoFrame = (doc, scrollTop, marker, alignToTop) => {
- const frameViewHeight = doc.dom.defaultView.innerHeight;
- intoWindowIfNeeded(doc, scrollTop, frameViewHeight, marker, alignToTop);
- const op = find(marker.element);
- const viewportBounds = getBounds(window);
- if (op.top < viewportBounds.y) {
- intoView(marker.element, alignToTop !== false);
- } else if (op.top > viewportBounds.bottom) {
- intoView(marker.element, alignToTop === true);
- }
- };
- const rangeIntoWindow = (editor, rng, alignToTop) => withMarker(editor, intoWindow, rng, alignToTop);
- const elementIntoWindow = (editor, element, alignToTop) => withElement(editor, element, intoWindow, alignToTop);
- const rangeIntoFrame = (editor, rng, alignToTop) => withMarker(editor, intoFrame, rng, alignToTop);
- const elementIntoFrame = (editor, element, alignToTop) => withElement(editor, element, intoFrame, alignToTop);
- const scrollElementIntoView = (editor, element, alignToTop) => {
- const scroller = editor.inline ? elementIntoWindow : elementIntoFrame;
- scroller(editor, element, alignToTop);
- };
- const scrollRangeIntoView = (editor, rng, alignToTop) => {
- const scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame;
- scroller(editor, rng, alignToTop);
- };
- const focus$1 = element => element.dom.focus();
- const hasFocus$1 = element => {
- const root = getRootNode(element).dom;
- return element.dom === root.activeElement;
- };
- const active$1 = (root = getDocument()) => Optional.from(root.dom.activeElement).map(SugarElement.fromDom);
- const search = element => active$1(getRootNode(element)).filter(e => element.dom.contains(e.dom));
- const clamp$1 = (offset, element) => {
- const max = isText$a(element) ? get$3(element).length : children(element).length + 1;
- if (offset > max) {
- return max;
- } else if (offset < 0) {
- return 0;
- }
- return offset;
- };
- const normalizeRng = rng => SimSelection.range(rng.start, clamp$1(rng.soffset, rng.start), rng.finish, clamp$1(rng.foffset, rng.finish));
- const isOrContains = (root, elm) => !isRestrictedNode(elm.dom) && (contains(root, elm) || eq(root, elm));
- const isRngInRoot = root => rng => isOrContains(root, rng.start) && isOrContains(root, rng.finish);
- const shouldStore = editor => editor.inline;
- const nativeRangeToSelectionRange = r => SimSelection.range(SugarElement.fromDom(r.startContainer), r.startOffset, SugarElement.fromDom(r.endContainer), r.endOffset);
- const readRange = win => {
- const selection = win.getSelection();
- const rng = !selection || selection.rangeCount === 0 ? Optional.none() : Optional.from(selection.getRangeAt(0));
- return rng.map(nativeRangeToSelectionRange);
- };
- const getBookmark = root => {
- const win = defaultView(root);
- return readRange(win.dom).filter(isRngInRoot(root));
- };
- const validate = (root, bookmark) => Optional.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng);
- const bookmarkToNativeRng = bookmark => {
- const rng = document.createRange();
- try {
- rng.setStart(bookmark.start.dom, bookmark.soffset);
- rng.setEnd(bookmark.finish.dom, bookmark.foffset);
- return Optional.some(rng);
- } catch (_) {
- return Optional.none();
- }
- };
- const store = editor => {
- const newBookmark = shouldStore(editor) ? getBookmark(SugarElement.fromDom(editor.getBody())) : Optional.none();
- editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;
- };
- const getRng = editor => {
- const bookmark = editor.bookmark ? editor.bookmark : Optional.none();
- return bookmark.bind(x => validate(SugarElement.fromDom(editor.getBody()), x)).bind(bookmarkToNativeRng);
- };
- const restore = editor => {
- getRng(editor).each(rng => editor.selection.setRng(rng));
- };
- const isEditorUIElement$1 = elm => {
- const className = elm.className.toString();
- return className.indexOf('tox-') !== -1 || className.indexOf('mce-') !== -1;
- };
- const FocusManager = { isEditorUIElement: isEditorUIElement$1 };
- const wrappedSetTimeout = (callback, time) => {
- if (!isNumber(time)) {
- time = 0;
- }
- return setTimeout(callback, time);
- };
- const wrappedSetInterval = (callback, time) => {
- if (!isNumber(time)) {
- time = 0;
- }
- return setInterval(callback, time);
- };
- const Delay = {
- setEditorTimeout: (editor, callback, time) => {
- return wrappedSetTimeout(() => {
- if (!editor.removed) {
- callback();
- }
- }, time);
- },
- setEditorInterval: (editor, callback, time) => {
- const timer = wrappedSetInterval(() => {
- if (!editor.removed) {
- callback();
- } else {
- clearInterval(timer);
- }
- }, time);
- return timer;
- }
- };
- const isManualNodeChange = e => {
- return e.type === 'nodechange' && e.selectionChange;
- };
- const registerPageMouseUp = (editor, throttledStore) => {
- const mouseUpPage = () => {
- throttledStore.throttle();
- };
- DOMUtils.DOM.bind(document, 'mouseup', mouseUpPage);
- editor.on('remove', () => {
- DOMUtils.DOM.unbind(document, 'mouseup', mouseUpPage);
- });
- };
- const registerMouseUp = (editor, throttledStore) => {
- editor.on('mouseup touchend', _e => {
- throttledStore.throttle();
- });
- };
- const registerEditorEvents = (editor, throttledStore) => {
- registerMouseUp(editor, throttledStore);
- editor.on('keyup NodeChange AfterSetSelectionRange', e => {
- if (!isManualNodeChange(e)) {
- store(editor);
- }
- });
- };
- const register$6 = editor => {
- const throttledStore = first$1(() => {
- store(editor);
- }, 0);
- editor.on('init', () => {
- if (editor.inline) {
- registerPageMouseUp(editor, throttledStore);
- }
- registerEditorEvents(editor, throttledStore);
- });
- editor.on('remove', () => {
- throttledStore.cancel();
- });
- };
- let documentFocusInHandler;
- const DOM$9 = DOMUtils.DOM;
- const isEditorUIElement = elm => {
- return FocusManager.isEditorUIElement(elm);
- };
- const isEditorContentAreaElement = elm => {
- const classList = elm.classList;
- if (classList !== undefined) {
- return classList.contains('tox-edit-area') || classList.contains('tox-edit-area__iframe') || classList.contains('mce-content-body');
- } else {
- return false;
- }
- };
- const isUIElement = (editor, elm) => {
- const customSelector = getCustomUiSelector(editor);
- const parent = DOM$9.getParent(elm, elm => {
- return isEditorUIElement(elm) || (customSelector ? editor.dom.is(elm, customSelector) : false);
- });
- return parent !== null;
- };
- const getActiveElement = editor => {
- try {
- const root = getRootNode(SugarElement.fromDom(editor.getElement()));
- return active$1(root).fold(() => document.body, x => x.dom);
- } catch (ex) {
- return document.body;
- }
- };
- const registerEvents$1 = (editorManager, e) => {
- const editor = e.editor;
- register$6(editor);
- editor.on('focusin', () => {
- const focusedEditor = editorManager.focusedEditor;
- if (focusedEditor !== editor) {
- if (focusedEditor) {
- focusedEditor.dispatch('blur', { focusedEditor: editor });
- }
- editorManager.setActive(editor);
- editorManager.focusedEditor = editor;
- editor.dispatch('focus', { blurredEditor: focusedEditor });
- editor.focus(true);
- }
- });
- editor.on('focusout', () => {
- Delay.setEditorTimeout(editor, () => {
- const focusedEditor = editorManager.focusedEditor;
- if (!isUIElement(editor, getActiveElement(editor)) && focusedEditor === editor) {
- editor.dispatch('blur', { focusedEditor: null });
- editorManager.focusedEditor = null;
- }
- });
- });
- if (!documentFocusInHandler) {
- documentFocusInHandler = e => {
- const activeEditor = editorManager.activeEditor;
- if (activeEditor) {
- getOriginalEventTarget(e).each(target => {
- if (target.ownerDocument === document) {
- if (target !== document.body && !isUIElement(activeEditor, target) && editorManager.focusedEditor === activeEditor) {
- activeEditor.dispatch('blur', { focusedEditor: null });
- editorManager.focusedEditor = null;
- }
- }
- });
- }
- };
- DOM$9.bind(document, 'focusin', documentFocusInHandler);
- }
- };
- const unregisterDocumentEvents = (editorManager, e) => {
- if (editorManager.focusedEditor === e.editor) {
- editorManager.focusedEditor = null;
- }
- if (!editorManager.activeEditor) {
- DOM$9.unbind(document, 'focusin', documentFocusInHandler);
- documentFocusInHandler = null;
- }
- };
- const setup$v = editorManager => {
- editorManager.on('AddEditor', curry(registerEvents$1, editorManager));
- editorManager.on('RemoveEditor', curry(unregisterDocumentEvents, editorManager));
- };
- const getContentEditableHost = (editor, node) => editor.dom.getParent(node, node => editor.dom.getContentEditable(node) === 'true');
- const getCollapsedNode = rng => rng.collapsed ? Optional.from(getNode$1(rng.startContainer, rng.startOffset)).map(SugarElement.fromDom) : Optional.none();
- const getFocusInElement = (root, rng) => getCollapsedNode(rng).bind(node => {
- if (isTableSection(node)) {
- return Optional.some(node);
- } else if (contains(root, node) === false) {
- return Optional.some(root);
- } else {
- return Optional.none();
- }
- });
- const normalizeSelection = (editor, rng) => {
- getFocusInElement(SugarElement.fromDom(editor.getBody()), rng).bind(elm => {
- return firstPositionIn(elm.dom);
- }).fold(() => {
- editor.selection.normalize();
- return;
- }, caretPos => editor.selection.setRng(caretPos.toRange()));
- };
- const focusBody = body => {
- if (body.setActive) {
- try {
- body.setActive();
- } catch (ex) {
- body.focus();
- }
- } else {
- body.focus();
- }
- };
- const hasElementFocus = elm => hasFocus$1(elm) || search(elm).isSome();
- const hasIframeFocus = editor => editor.iframeElement && hasFocus$1(SugarElement.fromDom(editor.iframeElement));
- const hasInlineFocus = editor => {
- const rawBody = editor.getBody();
- return rawBody && hasElementFocus(SugarElement.fromDom(rawBody));
- };
- const hasUiFocus = editor => {
- const dos = getRootNode(SugarElement.fromDom(editor.getElement()));
- return active$1(dos).filter(elem => !isEditorContentAreaElement(elem.dom) && isUIElement(editor, elem.dom)).isSome();
- };
- const hasFocus = editor => editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor);
- const hasEditorOrUiFocus = editor => hasFocus(editor) || hasUiFocus(editor);
- const focusEditor = editor => {
- const selection = editor.selection;
- const body = editor.getBody();
- let rng = selection.getRng();
- editor.quirks.refreshContentEditable();
- if (editor.bookmark !== undefined && hasFocus(editor) === false) {
- getRng(editor).each(bookmarkRng => {
- editor.selection.setRng(bookmarkRng);
- rng = bookmarkRng;
- });
- }
- const contentEditableHost = getContentEditableHost(editor, selection.getNode());
- if (editor.dom.isChildOf(contentEditableHost, body)) {
- focusBody(contentEditableHost);
- normalizeSelection(editor, rng);
- activateEditor(editor);
- return;
- }
- if (!editor.inline) {
- if (!Env.browser.isOpera()) {
- focusBody(body);
- }
- editor.getWin().focus();
- }
- if (Env.browser.isFirefox() || editor.inline) {
- focusBody(body);
- normalizeSelection(editor, rng);
- }
- activateEditor(editor);
- };
- const activateEditor = editor => editor.editorManager.setActive(editor);
- const focus = (editor, skipFocus) => {
- if (editor.removed) {
- return;
- }
- if (skipFocus) {
- activateEditor(editor);
- } else {
- focusEditor(editor);
- }
- };
- const getEndpointElement = (root, rng, start, real, resolve) => {
- const container = start ? rng.startContainer : rng.endContainer;
- const offset = start ? rng.startOffset : rng.endOffset;
- return Optional.from(container).map(SugarElement.fromDom).map(elm => !real || !rng.collapsed ? child$1(elm, resolve(elm, offset)).getOr(elm) : elm).bind(elm => isElement$7(elm) ? Optional.some(elm) : parent(elm).filter(isElement$7)).map(elm => elm.dom).getOr(root);
- };
- const getStart = (root, rng, real) => getEndpointElement(root, rng, true, real, (elm, offset) => Math.min(childNodesCount(elm), offset));
- const getEnd$1 = (root, rng, real) => getEndpointElement(root, rng, false, real, (elm, offset) => offset > 0 ? offset - 1 : offset);
- const skipEmptyTextNodes = (node, forwards) => {
- const orig = node;
- while (node && isText$9(node) && node.length === 0) {
- node = forwards ? node.nextSibling : node.previousSibling;
- }
- return node || orig;
- };
- const getNode = (root, rng) => {
- let elm, startContainer, endContainer;
- if (!rng) {
- return root;
- }
- startContainer = rng.startContainer;
- endContainer = rng.endContainer;
- const startOffset = rng.startOffset;
- const endOffset = rng.endOffset;
- elm = rng.commonAncestorContainer;
- if (!rng.collapsed) {
- if (startContainer === endContainer) {
- if (endOffset - startOffset < 2) {
- if (startContainer.hasChildNodes()) {
- elm = startContainer.childNodes[startOffset];
- }
- }
- }
- if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
- if (startContainer.length === startOffset) {
- startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);
- } else {
- startContainer = startContainer.parentNode;
- }
- if (endOffset === 0) {
- endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);
- } else {
- endContainer = endContainer.parentNode;
- }
- if (startContainer && startContainer === endContainer) {
- return startContainer;
- }
- }
- }
- if (elm && elm.nodeType === 3) {
- return elm.parentNode;
- }
- return elm;
- };
- const getSelectedBlocks = (dom, rng, startElm, endElm) => {
- let node;
- const selectedBlocks = [];
- const root = dom.getRoot();
- startElm = dom.getParent(startElm || getStart(root, rng, rng.collapsed), dom.isBlock);
- endElm = dom.getParent(endElm || getEnd$1(root, rng, rng.collapsed), dom.isBlock);
- if (startElm && startElm !== root) {
- selectedBlocks.push(startElm);
- }
- if (startElm && endElm && startElm !== endElm) {
- node = startElm;
- const walker = new DomTreeWalker(startElm, root);
- while ((node = walker.next()) && node !== endElm) {
- if (dom.isBlock(node)) {
- selectedBlocks.push(node);
- }
- }
- }
- if (endElm && startElm !== endElm && endElm !== root) {
- selectedBlocks.push(endElm);
- }
- return selectedBlocks;
- };
- const select = (dom, node, content) => Optional.from(node).map(node => {
- const idx = dom.nodeIndex(node);
- const rng = dom.createRng();
- rng.setStart(node.parentNode, idx);
- rng.setEnd(node.parentNode, idx + 1);
- if (content) {
- moveEndPoint(dom, rng, node, true);
- moveEndPoint(dom, rng, node, false);
- }
- return rng;
- });
- const processRanges = (editor, ranges) => map$3(ranges, range => {
- const evt = editor.dispatch('GetSelectionRange', { range });
- return evt.range !== range ? evt.range : range;
- });
- const getEnd = element => name(element) === 'img' ? 1 : getOption(element).fold(() => children(element).length, v => v.length);
- const isTextNodeWithCursorPosition = el => getOption(el).filter(text => text.trim().length !== 0 || text.indexOf(nbsp) > -1).isSome();
- const elementsWithCursorPosition = [
- 'img',
- 'br'
- ];
- const isCursorPosition = elem => {
- const hasCursorPosition = isTextNodeWithCursorPosition(elem);
- return hasCursorPosition || contains$2(elementsWithCursorPosition, name(elem));
- };
- const first = element => descendant$1(element, isCursorPosition);
- const last = element => descendantRtl(element, isCursorPosition);
- const descendantRtl = (scope, predicate) => {
- const descend = element => {
- const children$1 = children(element);
- for (let i = children$1.length - 1; i >= 0; i--) {
- const child = children$1[i];
- if (predicate(child)) {
- return Optional.some(child);
- }
- const res = descend(child);
- if (res.isSome()) {
- return res;
- }
- }
- return Optional.none();
- };
- return descend(scope);
- };
- const autocompleteSelector = '[data-mce-autocompleter]';
- const create$9 = (editor, range) => {
- if (findIn(SugarElement.fromDom(editor.getBody())).isNone()) {
- const wrapper = SugarElement.fromHtml('<span data-mce-autocompleter="1" data-mce-bogus="1"></span>', editor.getDoc());
- append$1(wrapper, SugarElement.fromDom(range.extractContents()));
- range.insertNode(wrapper.dom);
- parent(wrapper).each(elm => elm.dom.normalize());
- last(wrapper).map(last => {
- editor.selection.setCursorLocation(last.dom, getEnd(last));
- });
- }
- };
- const detect$1 = elm => closest$3(elm, autocompleteSelector);
- const findIn = elm => descendant(elm, autocompleteSelector);
- const remove$3 = (editor, elm) => findIn(elm).each(wrapper => {
- const bookmark = editor.selection.getBookmark();
- unwrap(wrapper);
- editor.selection.moveToBookmark(bookmark);
- });
- const typeLookup = {
- '#text': 3,
- '#comment': 8,
- '#cdata': 4,
- '#pi': 7,
- '#doctype': 10,
- '#document-fragment': 11
- };
- const walk$2 = (node, root, prev) => {
- const startName = prev ? 'lastChild' : 'firstChild';
- const siblingName = prev ? 'prev' : 'next';
- if (node[startName]) {
- return node[startName];
- }
- if (node !== root) {
- let sibling = node[siblingName];
- if (sibling) {
- return sibling;
- }
- for (let parent = node.parent; parent && parent !== root; parent = parent.parent) {
- sibling = parent[siblingName];
- if (sibling) {
- return sibling;
- }
- }
- }
- };
- const isEmptyTextNode = node => {
- if (!isWhitespaceText(node.value)) {
- return false;
- }
- const parentNode = node.parent;
- if (parentNode && (parentNode.name !== 'span' || parentNode.attr('style')) && /^[ ]+$/.test(node.value)) {
- return false;
- }
- return true;
- };
- const isNonEmptyElement = node => {
- const isNamedAnchor = node.name === 'a' && !node.attr('href') && node.attr('id');
- return node.attr('name') || node.attr('id') && !node.firstChild || node.attr('data-mce-bookmark') || isNamedAnchor;
- };
- class AstNode {
- constructor(name, type) {
- this.name = name;
- this.type = type;
- if (type === 1) {
- this.attributes = [];
- this.attributes.map = {};
- }
- }
- static create(name, attrs) {
- const node = new AstNode(name, typeLookup[name] || 1);
- if (attrs) {
- each$e(attrs, (value, attrName) => {
- node.attr(attrName, value);
- });
- }
- return node;
- }
- replace(node) {
- const self = this;
- if (node.parent) {
- node.remove();
- }
- self.insert(node, self);
- self.remove();
- return self;
- }
- attr(name, value) {
- const self = this;
- let attrs;
- if (typeof name !== 'string') {
- if (name !== undefined && name !== null) {
- each$e(name, (value, key) => {
- self.attr(key, value);
- });
- }
- return self;
- }
- if (attrs = self.attributes) {
- if (value !== undefined) {
- if (value === null) {
- if (name in attrs.map) {
- delete attrs.map[name];
- let i = attrs.length;
- while (i--) {
- if (attrs[i].name === name) {
- attrs.splice(i, 1);
- return self;
- }
- }
- }
- return self;
- }
- if (name in attrs.map) {
- let i = attrs.length;
- while (i--) {
- if (attrs[i].name === name) {
- attrs[i].value = value;
- break;
- }
- }
- } else {
- attrs.push({
- name,
- value
- });
- }
- attrs.map[name] = value;
- return self;
- }
- return attrs.map[name];
- }
- }
- clone() {
- const self = this;
- const clone = new AstNode(self.name, self.type);
- let selfAttrs;
- if (selfAttrs = self.attributes) {
- const cloneAttrs = [];
- cloneAttrs.map = {};
- for (let i = 0, l = selfAttrs.length; i < l; i++) {
- const selfAttr = selfAttrs[i];
- if (selfAttr.name !== 'id') {
- cloneAttrs[cloneAttrs.length] = {
- name: selfAttr.name,
- value: selfAttr.value
- };
- cloneAttrs.map[selfAttr.name] = selfAttr.value;
- }
- }
- clone.attributes = cloneAttrs;
- }
- clone.value = self.value;
- return clone;
- }
- wrap(wrapper) {
- const self = this;
- self.parent.insert(wrapper, self);
- wrapper.append(self);
- return self;
- }
- unwrap() {
- const self = this;
- for (let node = self.firstChild; node;) {
- const next = node.next;
- self.insert(node, self, true);
- node = next;
- }
- self.remove();
- }
- remove() {
- const self = this, parent = self.parent, next = self.next, prev = self.prev;
- if (parent) {
- if (parent.firstChild === self) {
- parent.firstChild = next;
- if (next) {
- next.prev = null;
- }
- } else {
- prev.next = next;
- }
- if (parent.lastChild === self) {
- parent.lastChild = prev;
- if (prev) {
- prev.next = null;
- }
- } else {
- next.prev = prev;
- }
- self.parent = self.next = self.prev = null;
- }
- return self;
- }
- append(node) {
- const self = this;
- if (node.parent) {
- node.remove();
- }
- const last = self.lastChild;
- if (last) {
- last.next = node;
- node.prev = last;
- self.lastChild = node;
- } else {
- self.lastChild = self.firstChild = node;
- }
- node.parent = self;
- return node;
- }
- insert(node, refNode, before) {
- if (node.parent) {
- node.remove();
- }
- const parent = refNode.parent || this;
- if (before) {
- if (refNode === parent.firstChild) {
- parent.firstChild = node;
- } else {
- refNode.prev.next = node;
- }
- node.prev = refNode.prev;
- node.next = refNode;
- refNode.prev = node;
- } else {
- if (refNode === parent.lastChild) {
- parent.lastChild = node;
- } else {
- refNode.next.prev = node;
- }
- node.next = refNode.next;
- node.prev = refNode;
- refNode.next = node;
- }
- node.parent = parent;
- return node;
- }
- getAll(name) {
- const self = this;
- const collection = [];
- for (let node = self.firstChild; node; node = walk$2(node, self)) {
- if (node.name === name) {
- collection.push(node);
- }
- }
- return collection;
- }
- children() {
- const self = this;
- const collection = [];
- for (let node = self.firstChild; node; node = node.next) {
- collection.push(node);
- }
- return collection;
- }
- empty() {
- const self = this;
- if (self.firstChild) {
- const nodes = [];
- for (let node = self.firstChild; node; node = walk$2(node, self)) {
- nodes.push(node);
- }
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
- }
- }
- self.firstChild = self.lastChild = null;
- return self;
- }
- isEmpty(elements, whitespace = {}, predicate) {
- const self = this;
- let node = self.firstChild;
- if (isNonEmptyElement(self)) {
- return false;
- }
- if (node) {
- do {
- if (node.type === 1) {
- if (node.attr('data-mce-bogus')) {
- continue;
- }
- if (elements[node.name]) {
- return false;
- }
- if (isNonEmptyElement(node)) {
- return false;
- }
- }
- if (node.type === 8) {
- return false;
- }
- if (node.type === 3 && !isEmptyTextNode(node)) {
- return false;
- }
- if (node.type === 3 && node.parent && whitespace[node.parent.name] && isWhitespaceText(node.value)) {
- return false;
- }
- if (predicate && predicate(node)) {
- return false;
- }
- } while (node = walk$2(node, self));
- }
- return true;
- }
- walk(prev) {
- return walk$2(this, null, prev);
- }
- }
- const isConditionalComment = (html, startIndex) => /^\s*\[if [\w\W]+\]>.*<!\[endif\](--!?)?>/.test(html.substr(startIndex));
- const findCommentEndIndex = (html, isBogus, startIndex = 0) => {
- const lcHtml = html.toLowerCase();
- if (lcHtml.indexOf('[if ', startIndex) !== -1 && isConditionalComment(lcHtml, startIndex)) {
- const endIfIndex = lcHtml.indexOf('[endif]', startIndex);
- return lcHtml.indexOf('>', endIfIndex);
- } else {
- if (isBogus) {
- const endIndex = lcHtml.indexOf('>', startIndex);
- return endIndex !== -1 ? endIndex : lcHtml.length;
- } else {
- const endCommentRegexp = /--!?>/g;
- endCommentRegexp.lastIndex = startIndex;
- const match = endCommentRegexp.exec(html);
- return match ? match.index + match[0].length : lcHtml.length;
- }
- }
- };
- const findMatchingEndTagIndex = (schema, html, startIndex) => {
- const startTagRegExp = /<([!?\/])?([A-Za-z0-9\-_:.]+)/g;
- const endTagRegExp = /(?:\s(?:[^'">]+(?:"[^"]*"|'[^']*'))*[^"'>]*(?:"[^">]*|'[^'>]*)?|\s*|\/)>/g;
- const voidElements = schema.getVoidElements();
- let count = 1, index = startIndex;
- while (count !== 0) {
- startTagRegExp.lastIndex = index;
- while (true) {
- const startMatch = startTagRegExp.exec(html);
- if (startMatch === null) {
- return index;
- } else if (startMatch[1] === '!') {
- if (startsWith(startMatch[2], '--')) {
- index = findCommentEndIndex(html, false, startMatch.index + '!--'.length);
- } else {
- index = findCommentEndIndex(html, true, startMatch.index + 1);
- }
- break;
- } else {
- endTagRegExp.lastIndex = startTagRegExp.lastIndex;
- const endMatch = endTagRegExp.exec(html);
- if (isNull(endMatch) || endMatch.index !== startTagRegExp.lastIndex) {
- continue;
- }
- if (startMatch[1] === '/') {
- count -= 1;
- } else if (!has$2(voidElements, startMatch[2])) {
- count += 1;
- }
- index = startTagRegExp.lastIndex + endMatch[0].length;
- break;
- }
- }
- }
- return index;
- };
- const trimHtml$1 = (tempAttrs, html) => {
- const trimContentRegExp = new RegExp(['\\s?(' + tempAttrs.join('|') + ')="[^"]+"'].join('|'), 'gi');
- return html.replace(trimContentRegExp, '');
- };
- const trimInternal = (serializer, html) => {
- const bogusAllRegExp = /<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g;
- const schema = serializer.schema;
- let content = trimHtml$1(serializer.getTempAttrs(), html);
- const voidElements = schema.getVoidElements();
- let matches;
- while (matches = bogusAllRegExp.exec(content)) {
- const index = bogusAllRegExp.lastIndex;
- const matchLength = matches[0].length;
- let endTagIndex;
- if (voidElements[matches[1]]) {
- endTagIndex = index;
- } else {
- endTagIndex = findMatchingEndTagIndex(schema, content, index);
- }
- content = content.substring(0, index - matchLength) + content.substring(endTagIndex);
- bogusAllRegExp.lastIndex = index - matchLength;
- }
- return trim$1(content);
- };
- const trimExternal = trimInternal;
- const trimEmptyContents = (editor, html) => {
- const blockName = getForcedRootBlock(editor);
- const emptyRegExp = new RegExp(`^(<${ blockName }[^>]*>( | |\\s|\u00a0|<br \\/>|)<\\/${ blockName }>[\r\n]*|<br \\/>[\r\n]*)$`);
- return html.replace(emptyRegExp, '');
- };
- const getContentFromBody = (editor, args, body) => {
- let content;
- if (args.format === 'raw') {
- content = Tools.trim(trimExternal(editor.serializer, body.innerHTML));
- } else if (args.format === 'text') {
- content = trim$1(body.innerText);
- content = content === '\n' ? '' : content;
- } else if (args.format === 'tree') {
- content = editor.serializer.serialize(body, args);
- } else {
- content = trimEmptyContents(editor, editor.serializer.serialize(body, args));
- }
- const shouldTrim = args.format !== 'text' && !isWsPreserveElement(SugarElement.fromDom(body));
- return shouldTrim && isString(content) ? Tools.trim(content) : content;
- };
- const getContentInternal = (editor, args) => Optional.from(editor.getBody()).fold(constant(args.format === 'tree' ? new AstNode('body', 11) : ''), body => getContentFromBody(editor, args, body));
- const each$a = Tools.each;
- const ElementUtils = dom => {
- const compare = (node1, node2) => {
- if (node1.nodeName !== node2.nodeName) {
- return false;
- }
- const getAttribs = node => {
- const attribs = {};
- each$a(dom.getAttribs(node), attr => {
- const name = attr.nodeName.toLowerCase();
- if (name.indexOf('_') !== 0 && name !== 'style' && name.indexOf('data-') !== 0) {
- attribs[name] = dom.getAttrib(node, name);
- }
- });
- return attribs;
- };
- const compareObjects = (obj1, obj2) => {
- let value, name;
- for (name in obj1) {
- if (has$2(obj1, name)) {
- value = obj2[name];
- if (typeof value === 'undefined') {
- return false;
- }
- if (obj1[name] !== value) {
- return false;
- }
- delete obj2[name];
- }
- }
- for (name in obj2) {
- if (has$2(obj2, name)) {
- return false;
- }
- }
- return true;
- };
- if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
- return false;
- }
- if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) {
- return false;
- }
- return !isBookmarkNode$1(node1) && !isBookmarkNode$1(node2);
- };
- return { compare };
- };
- const makeMap$1 = Tools.makeMap;
- const Writer = settings => {
- const html = [];
- settings = settings || {};
- const indent = settings.indent;
- const indentBefore = makeMap$1(settings.indent_before || '');
- const indentAfter = makeMap$1(settings.indent_after || '');
- const encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
- const htmlOutput = settings.element_format !== 'xhtml';
- return {
- start: (name, attrs, empty) => {
- let i, l, attr, value;
- if (indent && indentBefore[name] && html.length > 0) {
- value = html[html.length - 1];
- if (value.length > 0 && value !== '\n') {
- html.push('\n');
- }
- }
- html.push('<', name);
- if (attrs) {
- for (i = 0, l = attrs.length; i < l; i++) {
- attr = attrs[i];
- html.push(' ', attr.name, '="', encode(attr.value, true), '"');
- }
- }
- if (!empty || htmlOutput) {
- html[html.length] = '>';
- } else {
- html[html.length] = ' />';
- }
- if (empty && indent && indentAfter[name] && html.length > 0) {
- value = html[html.length - 1];
- if (value.length > 0 && value !== '\n') {
- html.push('\n');
- }
- }
- },
- end: name => {
- let value;
- html.push('</', name, '>');
- if (indent && indentAfter[name] && html.length > 0) {
- value = html[html.length - 1];
- if (value.length > 0 && value !== '\n') {
- html.push('\n');
- }
- }
- },
- text: (text, raw) => {
- if (text.length > 0) {
- html[html.length] = raw ? text : encode(text);
- }
- },
- cdata: text => {
- html.push('<![CDATA[', text, ']]>');
- },
- comment: text => {
- html.push('<!--', text, '-->');
- },
- pi: (name, text) => {
- if (text) {
- html.push('<?', name, ' ', encode(text), '?>');
- } else {
- html.push('<?', name, '?>');
- }
- if (indent) {
- html.push('\n');
- }
- },
- doctype: text => {
- html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
- },
- reset: () => {
- html.length = 0;
- },
- getContent: () => {
- return html.join('').replace(/\n$/, '');
- }
- };
- };
- const HtmlSerializer = (settings, schema = Schema()) => {
- const writer = Writer(settings);
- settings = settings || {};
- settings.validate = 'validate' in settings ? settings.validate : true;
- const serialize = node => {
- const validate = settings.validate;
- const handlers = {
- 3: node => {
- writer.text(node.value, node.raw);
- },
- 8: node => {
- writer.comment(node.value);
- },
- 7: node => {
- writer.pi(node.name, node.value);
- },
- 10: node => {
- writer.doctype(node.value);
- },
- 4: node => {
- writer.cdata(node.value);
- },
- 11: node => {
- if (node = node.firstChild) {
- do {
- walk(node);
- } while (node = node.next);
- }
- }
- };
- writer.reset();
- const walk = node => {
- const handler = handlers[node.type];
- if (!handler) {
- const name = node.name;
- const isEmpty = name in schema.getVoidElements();
- let attrs = node.attributes;
- if (validate && attrs && attrs.length > 1) {
- const sortedAttrs = [];
- sortedAttrs.map = {};
- const elementRule = schema.getElementRule(node.name);
- if (elementRule) {
- for (let i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
- const attrName = elementRule.attributesOrder[i];
- if (attrName in attrs.map) {
- const attrValue = attrs.map[attrName];
- sortedAttrs.map[attrName] = attrValue;
- sortedAttrs.push({
- name: attrName,
- value: attrValue
- });
- }
- }
- for (let i = 0, l = attrs.length; i < l; i++) {
- const attrName = attrs[i].name;
- if (!(attrName in sortedAttrs.map)) {
- const attrValue = attrs.map[attrName];
- sortedAttrs.map[attrName] = attrValue;
- sortedAttrs.push({
- name: attrName,
- value: attrValue
- });
- }
- }
- attrs = sortedAttrs;
- }
- }
- writer.start(name, attrs, isEmpty);
- if (!isEmpty) {
- let child = node.firstChild;
- if (child) {
- if ((name === 'pre' || name === 'textarea') && child.type === 3 && child.value[0] === '\n') {
- writer.text('\n', true);
- }
- do {
- walk(child);
- } while (child = child.next);
- }
- writer.end(name);
- }
- } else {
- handler(node);
- }
- };
- if (node.type === 1 && !settings.inner) {
- walk(node);
- } else if (node.type === 3) {
- handlers[3](node);
- } else {
- handlers[11](node);
- }
- return writer.getContent();
- };
- return { serialize };
- };
- const nonInheritableStyles = new Set();
- (() => {
- const nonInheritableStylesArr = [
- 'margin',
- 'margin-left',
- 'margin-right',
- 'margin-top',
- 'margin-bottom',
- 'padding',
- 'padding-left',
- 'padding-right',
- 'padding-top',
- 'padding-bottom',
- 'border',
- 'border-width',
- 'border-style',
- 'border-color',
- 'background',
- 'background-attachment',
- 'background-clip',
- 'background-color',
- 'background-image',
- 'background-origin',
- 'background-position',
- 'background-repeat',
- 'background-size',
- 'float',
- 'position',
- 'left',
- 'right',
- 'top',
- 'bottom',
- 'z-index',
- 'display',
- 'transform',
- 'width',
- 'max-width',
- 'min-width',
- 'height',
- 'max-height',
- 'min-height',
- 'overflow',
- 'overflow-x',
- 'overflow-y',
- 'text-overflow',
- 'vertical-align',
- 'transition',
- 'transition-delay',
- 'transition-duration',
- 'transition-property',
- 'transition-timing-function'
- ];
- each$f(nonInheritableStylesArr, style => {
- nonInheritableStyles.add(style);
- });
- })();
- const shorthandStyleProps = [
- 'font',
- 'text-decoration',
- 'text-emphasis'
- ];
- const getStyleProps = (dom, node) => keys(dom.parseStyle(dom.getAttrib(node, 'style')));
- const isNonInheritableStyle = style => nonInheritableStyles.has(style);
- const hasInheritableStyles = (dom, node) => forall(getStyleProps(dom, node), style => !isNonInheritableStyle(style));
- const getLonghandStyleProps = styles => filter$6(styles, style => exists(shorthandStyleProps, prop => startsWith(style, prop)));
- const hasStyleConflict = (dom, node, parentNode) => {
- const nodeStyleProps = getStyleProps(dom, node);
- const parentNodeStyleProps = getStyleProps(dom, parentNode);
- const valueMismatch = prop => {
- var _a, _b;
- const nodeValue = (_a = dom.getStyle(node, prop)) !== null && _a !== void 0 ? _a : '';
- const parentValue = (_b = dom.getStyle(parentNode, prop)) !== null && _b !== void 0 ? _b : '';
- return isNotEmpty(nodeValue) && isNotEmpty(parentValue) && nodeValue !== parentValue;
- };
- return exists(nodeStyleProps, nodeStyleProp => {
- const propExists = props => exists(props, prop => prop === nodeStyleProp);
- if (!propExists(parentNodeStyleProps) && propExists(shorthandStyleProps)) {
- const longhandProps = getLonghandStyleProps(parentNodeStyleProps);
- return exists(longhandProps, valueMismatch);
- } else {
- return valueMismatch(nodeStyleProp);
- }
- });
- };
- const isChar = (forward, predicate, pos) => Optional.from(pos.container()).filter(isText$9).exists(text => {
- const delta = forward ? 0 : -1;
- return predicate(text.data.charAt(pos.offset() + delta));
- });
- const isBeforeSpace = curry(isChar, true, isWhiteSpace);
- const isAfterSpace = curry(isChar, false, isWhiteSpace);
- const isEmptyText = pos => {
- const container = pos.container();
- return isText$9(container) && (container.data.length === 0 || isZwsp(container.data) && BookmarkManager.isBookmarkNode(container.parentNode));
- };
- const matchesElementPosition = (before, predicate) => pos => Optional.from(getChildNodeAtRelativeOffset(before ? 0 : -1, pos)).filter(predicate).isSome();
- const isImageBlock = node => isImg(node) && get$7(SugarElement.fromDom(node), 'display') === 'block';
- const isCefNode = node => isContentEditableFalse$b(node) && !isBogusAll$1(node);
- const isBeforeImageBlock = matchesElementPosition(true, isImageBlock);
- const isAfterImageBlock = matchesElementPosition(false, isImageBlock);
- const isBeforeMedia = matchesElementPosition(true, isMedia$2);
- const isAfterMedia = matchesElementPosition(false, isMedia$2);
- const isBeforeTable = matchesElementPosition(true, isTable$3);
- const isAfterTable = matchesElementPosition(false, isTable$3);
- const isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode);
- const isAfterContentEditableFalse = matchesElementPosition(false, isCefNode);
- const getLastChildren = elm => {
- const children = [];
- let rawNode = elm.dom;
- while (rawNode) {
- children.push(SugarElement.fromDom(rawNode));
- rawNode = rawNode.lastChild;
- }
- return children;
- };
- const removeTrailingBr = elm => {
- const allBrs = descendants(elm, 'br');
- const brs = filter$6(getLastChildren(elm).slice(-1), isBr$5);
- if (allBrs.length === brs.length) {
- each$f(brs, remove$6);
- }
- };
- const fillWithPaddingBr = elm => {
- empty(elm);
- append$1(elm, SugarElement.fromHtml('<br data-mce-bogus="1">'));
- };
- const trimBlockTrailingBr = elm => {
- lastChild(elm).each(lastChild => {
- prevSibling(lastChild).each(lastChildPrevSibling => {
- if (isBlock$2(elm) && isBr$5(lastChild) && isBlock$2(lastChildPrevSibling)) {
- remove$6(lastChild);
- }
- });
- });
- };
- const dropLast = xs => xs.slice(0, -1);
- const parentsUntil = (start, root, predicate) => {
- if (contains(root, start)) {
- return dropLast(parents$1(start, elm => {
- return predicate(elm) || eq(elm, root);
- }));
- } else {
- return [];
- }
- };
- const parents = (start, root) => parentsUntil(start, root, never);
- const parentsAndSelf = (start, root) => [start].concat(parents(start, root));
- const navigateIgnoreEmptyTextNodes = (forward, root, from) => navigateIgnore(forward, root, from, isEmptyText);
- const getClosestBlock$1 = (root, pos) => find$2(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2);
- const isAtBeforeAfterBlockBoundary = (forward, root, pos) => navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(newPos => getClosestBlock$1(root, pos).fold(() => isInSameBlock(newPos, pos, root.dom) === false, fromBlock => isInSameBlock(newPos, pos, root.dom) === false && contains(fromBlock, SugarElement.fromDom(newPos.container()))));
- const isAtBlockBoundary = (forward, root, pos) => getClosestBlock$1(root, pos).fold(() => navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(newPos => isInSameBlock(newPos, pos, root.dom) === false), parent => navigateIgnoreEmptyTextNodes(forward, parent.dom, pos).isNone());
- const isAtStartOfBlock = curry(isAtBlockBoundary, false);
- const isAtEndOfBlock = curry(isAtBlockBoundary, true);
- const isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false);
- const isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true);
- const isBr$1 = pos => getElementFromPosition(pos).exists(isBr$5);
- const findBr = (forward, root, pos) => {
- const parentBlocks = filter$6(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2);
- const scope = head(parentBlocks).getOr(root);
- return fromPosition(forward, scope.dom, pos).filter(isBr$1);
- };
- const isBeforeBr$1 = (root, pos) => getElementFromPosition(pos).exists(isBr$5) || findBr(true, root, pos).isSome();
- const isAfterBr = (root, pos) => getElementFromPrevPosition(pos).exists(isBr$5) || findBr(false, root, pos).isSome();
- const findPreviousBr = curry(findBr, false);
- const findNextBr = curry(findBr, true);
- const isInMiddleOfText = pos => CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd();
- const getClosestBlock = (root, pos) => {
- const parentBlocks = filter$6(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$2);
- return head(parentBlocks).getOr(root);
- };
- const hasSpaceBefore = (root, pos) => {
- if (isInMiddleOfText(pos)) {
- return isAfterSpace(pos);
- } else {
- return isAfterSpace(pos) || prevPosition(getClosestBlock(root, pos).dom, pos).exists(isAfterSpace);
- }
- };
- const hasSpaceAfter = (root, pos) => {
- if (isInMiddleOfText(pos)) {
- return isBeforeSpace(pos);
- } else {
- return isBeforeSpace(pos) || nextPosition(getClosestBlock(root, pos).dom, pos).exists(isBeforeSpace);
- }
- };
- const isPreValue = value => contains$2([
- 'pre',
- 'pre-wrap'
- ], value);
- const isInPre = pos => getElementFromPosition(pos).bind(elm => closest$4(elm, isElement$7)).exists(elm => isPreValue(get$7(elm, 'white-space')));
- const isAtBeginningOfBody = (root, pos) => prevPosition(root.dom, pos).isNone();
- const isAtEndOfBody = (root, pos) => nextPosition(root.dom, pos).isNone();
- const isAtLineBoundary = (root, pos) => isAtBeginningOfBody(root, pos) || isAtEndOfBody(root, pos) || isAtStartOfBlock(root, pos) || isAtEndOfBlock(root, pos) || isAfterBr(root, pos) || isBeforeBr$1(root, pos);
- const isCefBlock = node => isNonNullable(node) && isContentEditableFalse$b(node) && isBlockLike(node);
- const isSiblingCefBlock = root => container => isCefBlock(new DomTreeWalker(container, root).next());
- const isBeforeCefBlock = (root, pos) => {
- const nextPos = nextPosition(root.dom, pos).getOr(pos);
- const isNextCefBlock = isSiblingCefBlock(root.dom);
- return pos.isAtEnd() && (isNextCefBlock(pos.container()) || isNextCefBlock(nextPos.container()));
- };
- const needsToHaveNbsp = (root, pos) => {
- if (isInPre(pos)) {
- return false;
- } else {
- return isAtLineBoundary(root, pos) || hasSpaceBefore(root, pos) || hasSpaceAfter(root, pos);
- }
- };
- const needsToBeNbspLeft = (root, pos) => {
- if (isInPre(pos)) {
- return false;
- } else {
- return isAtStartOfBlock(root, pos) || isBeforeBlock(root, pos) || isAfterBr(root, pos) || hasSpaceBefore(root, pos);
- }
- };
- const leanRight = pos => {
- const container = pos.container();
- const offset = pos.offset();
- if (isText$9(container) && offset < container.data.length) {
- return CaretPosition(container, offset + 1);
- } else {
- return pos;
- }
- };
- const needsToBeNbspRight = (root, pos) => {
- if (isInPre(pos)) {
- return false;
- } else {
- return isAtEndOfBlock(root, pos) || isAfterBlock(root, pos) || isBeforeBr$1(root, pos) || hasSpaceAfter(root, pos) || isBeforeCefBlock(root, pos);
- }
- };
- const needsToBeNbsp = (root, pos) => needsToBeNbspLeft(root, pos) || needsToBeNbspRight(root, leanRight(pos));
- const isNbspAt = (text, offset) => isNbsp(text.charAt(offset));
- const hasNbsp = pos => {
- const container = pos.container();
- return isText$9(container) && contains$1(container.data, nbsp);
- };
- const normalizeNbspMiddle = text => {
- const chars = text.split('');
- return map$3(chars, (chr, i) => {
- if (isNbsp(chr) && i > 0 && i < chars.length - 1 && isContent(chars[i - 1]) && isContent(chars[i + 1])) {
- return ' ';
- } else {
- return chr;
- }
- }).join('');
- };
- const normalizeNbspAtStart = (root, node) => {
- const text = node.data;
- const firstPos = CaretPosition(node, 0);
- if (isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos)) {
- node.data = ' ' + text.slice(1);
- return true;
- } else {
- return false;
- }
- };
- const normalizeNbspInMiddleOfTextNode = node => {
- const text = node.data;
- const newText = normalizeNbspMiddle(text);
- if (newText !== text) {
- node.data = newText;
- return true;
- } else {
- return false;
- }
- };
- const normalizeNbspAtEnd = (root, node) => {
- const text = node.data;
- const lastPos = CaretPosition(node, text.length - 1);
- if (isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos)) {
- node.data = text.slice(0, -1) + ' ';
- return true;
- } else {
- return false;
- }
- };
- const normalizeNbsps = (root, pos) => Optional.some(pos).filter(hasNbsp).bind(pos => {
- const container = pos.container();
- const normalized = normalizeNbspAtStart(root, container) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container);
- return normalized ? Optional.some(pos) : Optional.none();
- });
- const normalizeNbspsInEditor = editor => {
- const root = SugarElement.fromDom(editor.getBody());
- if (editor.selection.isCollapsed()) {
- normalizeNbsps(root, CaretPosition.fromRangeStart(editor.selection.getRng())).each(pos => {
- editor.selection.setRng(pos.toRange());
- });
- }
- };
- const normalize$1 = (node, offset, count) => {
- if (count === 0) {
- return;
- }
- const elm = SugarElement.fromDom(node);
- const root = ancestor$3(elm, isBlock$2).getOr(elm);
- const whitespace = node.data.slice(offset, offset + count);
- const isEndOfContent = offset + count >= node.data.length && needsToBeNbspRight(root, CaretPosition(node, node.data.length));
- const isStartOfContent = offset === 0 && needsToBeNbspLeft(root, CaretPosition(node, 0));
- node.replaceData(offset, count, normalize$4(whitespace, 4, isStartOfContent, isEndOfContent));
- };
- const normalizeWhitespaceAfter = (node, offset) => {
- const content = node.data.slice(offset);
- const whitespaceCount = content.length - lTrim(content).length;
- normalize$1(node, offset, whitespaceCount);
- };
- const normalizeWhitespaceBefore = (node, offset) => {
- const content = node.data.slice(0, offset);
- const whitespaceCount = content.length - rTrim(content).length;
- normalize$1(node, offset - whitespaceCount, whitespaceCount);
- };
- const mergeTextNodes = (prevNode, nextNode, normalizeWhitespace, mergeToPrev = true) => {
- const whitespaceOffset = rTrim(prevNode.data).length;
- const newNode = mergeToPrev ? prevNode : nextNode;
- const removeNode = mergeToPrev ? nextNode : prevNode;
- if (mergeToPrev) {
- newNode.appendData(removeNode.data);
- } else {
- newNode.insertData(0, removeNode.data);
- }
- remove$6(SugarElement.fromDom(removeNode));
- if (normalizeWhitespace) {
- normalizeWhitespaceAfter(newNode, whitespaceOffset);
- }
- return newNode;
- };
- const needsReposition = (pos, elm) => {
- const container = pos.container();
- const offset = pos.offset();
- return CaretPosition.isTextPosition(pos) === false && container === elm.parentNode && offset > CaretPosition.before(elm).offset();
- };
- const reposition = (elm, pos) => needsReposition(pos, elm) ? CaretPosition(pos.container(), pos.offset() - 1) : pos;
- const beforeOrStartOf = node => isText$9(node) ? CaretPosition(node, 0) : CaretPosition.before(node);
- const afterOrEndOf = node => isText$9(node) ? CaretPosition(node, node.data.length) : CaretPosition.after(node);
- const getPreviousSiblingCaretPosition = elm => {
- if (isCaretCandidate$3(elm.previousSibling)) {
- return Optional.some(afterOrEndOf(elm.previousSibling));
- } else {
- return elm.previousSibling ? lastPositionIn(elm.previousSibling) : Optional.none();
- }
- };
- const getNextSiblingCaretPosition = elm => {
- if (isCaretCandidate$3(elm.nextSibling)) {
- return Optional.some(beforeOrStartOf(elm.nextSibling));
- } else {
- return elm.nextSibling ? firstPositionIn(elm.nextSibling) : Optional.none();
- }
- };
- const findCaretPositionBackwardsFromElm = (rootElement, elm) => {
- const startPosition = CaretPosition.before(elm.previousSibling ? elm.previousSibling : elm.parentNode);
- return prevPosition(rootElement, startPosition).fold(() => nextPosition(rootElement, CaretPosition.after(elm)), Optional.some);
- };
- const findCaretPositionForwardsFromElm = (rootElement, elm) => nextPosition(rootElement, CaretPosition.after(elm)).fold(() => prevPosition(rootElement, CaretPosition.before(elm)), Optional.some);
- const findCaretPositionBackwards = (rootElement, elm) => getPreviousSiblingCaretPosition(elm).orThunk(() => getNextSiblingCaretPosition(elm)).orThunk(() => findCaretPositionBackwardsFromElm(rootElement, elm));
- const findCaretPositionForward = (rootElement, elm) => getNextSiblingCaretPosition(elm).orThunk(() => getPreviousSiblingCaretPosition(elm)).orThunk(() => findCaretPositionForwardsFromElm(rootElement, elm));
- const findCaretPosition = (forward, rootElement, elm) => forward ? findCaretPositionForward(rootElement, elm) : findCaretPositionBackwards(rootElement, elm);
- const findCaretPosOutsideElmAfterDelete = (forward, rootElement, elm) => findCaretPosition(forward, rootElement, elm).map(curry(reposition, elm));
- const setSelection$1 = (editor, forward, pos) => {
- pos.fold(() => {
- editor.focus();
- }, pos => {
- editor.selection.setRng(pos.toRange(), forward);
- });
- };
- const eqRawNode = rawNode => elm => elm.dom === rawNode;
- const isBlock = (editor, elm) => elm && has$2(editor.schema.getBlockElements(), name(elm));
- const paddEmptyBlock = elm => {
- if (isEmpty$2(elm)) {
- const br = SugarElement.fromHtml('<br data-mce-bogus="1">');
- empty(elm);
- append$1(elm, br);
- return Optional.some(CaretPosition.before(br.dom));
- } else {
- return Optional.none();
- }
- };
- const deleteNormalized = (elm, afterDeletePosOpt, normalizeWhitespace) => {
- const prevTextOpt = prevSibling(elm).filter(isText$a);
- const nextTextOpt = nextSibling(elm).filter(isText$a);
- remove$6(elm);
- return lift3(prevTextOpt, nextTextOpt, afterDeletePosOpt, (prev, next, pos) => {
- const prevNode = prev.dom, nextNode = next.dom;
- const offset = prevNode.data.length;
- mergeTextNodes(prevNode, nextNode, normalizeWhitespace);
- return pos.container() === nextNode ? CaretPosition(prevNode, offset) : pos;
- }).orThunk(() => {
- if (normalizeWhitespace) {
- prevTextOpt.each(elm => normalizeWhitespaceBefore(elm.dom, elm.dom.length));
- nextTextOpt.each(elm => normalizeWhitespaceAfter(elm.dom, 0));
- }
- return afterDeletePosOpt;
- });
- };
- const isInlineElement = (editor, element) => has$2(editor.schema.getTextInlineElements(), name(element));
- const deleteElement$2 = (editor, forward, elm, moveCaret = true) => {
- const afterDeletePos = findCaretPosOutsideElmAfterDelete(forward, editor.getBody(), elm.dom);
- const parentBlock = ancestor$3(elm, curry(isBlock, editor), eqRawNode(editor.getBody()));
- const normalizedAfterDeletePos = deleteNormalized(elm, afterDeletePos, isInlineElement(editor, elm));
- if (editor.dom.isEmpty(editor.getBody())) {
- editor.setContent('');
- editor.selection.setCursorLocation();
- } else {
- parentBlock.bind(paddEmptyBlock).fold(() => {
- if (moveCaret) {
- setSelection$1(editor, forward, normalizedAfterDeletePos);
- }
- }, paddPos => {
- if (moveCaret) {
- setSelection$1(editor, forward, Optional.some(paddPos));
- }
- });
- }
- };
- const strongRtl = /[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/;
- const hasStrongRtl = text => strongRtl.test(text);
- const isInlineTarget = (editor, elm) => is$1(SugarElement.fromDom(elm), getInlineBoundarySelector(editor));
- const isRtl = element => DOMUtils.DOM.getStyle(element, 'direction', true) === 'rtl' || hasStrongRtl(element.textContent);
- const findInlineParents = (isInlineTarget, rootNode, pos) => filter$6(DOMUtils.DOM.getParents(pos.container(), '*', rootNode), isInlineTarget);
- const findRootInline = (isInlineTarget, rootNode, pos) => {
- const parents = findInlineParents(isInlineTarget, rootNode, pos);
- return Optional.from(parents[parents.length - 1]);
- };
- const hasSameParentBlock = (rootNode, node1, node2) => {
- const block1 = getParentBlock$3(node1, rootNode);
- const block2 = getParentBlock$3(node2, rootNode);
- return block1 && block1 === block2;
- };
- const isAtZwsp = pos => isBeforeInline(pos) || isAfterInline(pos);
- const normalizePosition = (forward, pos) => {
- if (!pos) {
- return pos;
- }
- const container = pos.container(), offset = pos.offset();
- if (forward) {
- if (isCaretContainerInline(container)) {
- if (isText$9(container.nextSibling)) {
- return CaretPosition(container.nextSibling, 0);
- } else {
- return CaretPosition.after(container);
- }
- } else {
- return isBeforeInline(pos) ? CaretPosition(container, offset + 1) : pos;
- }
- } else {
- if (isCaretContainerInline(container)) {
- if (isText$9(container.previousSibling)) {
- return CaretPosition(container.previousSibling, container.previousSibling.data.length);
- } else {
- return CaretPosition.before(container);
- }
- } else {
- return isAfterInline(pos) ? CaretPosition(container, offset - 1) : pos;
- }
- }
- };
- const normalizeForwards = curry(normalizePosition, true);
- const normalizeBackwards = curry(normalizePosition, false);
- const execCommandIgnoreInputEvents = (editor, command) => {
- const inputBlocker = e => e.stopImmediatePropagation();
- editor.on('beforeinput input', inputBlocker, true);
- editor.getDoc().execCommand(command);
- editor.off('beforeinput input', inputBlocker);
- };
- const execDeleteCommand = editor => execCommandIgnoreInputEvents(editor, 'Delete');
- const execForwardDeleteCommand = editor => execCommandIgnoreInputEvents(editor, 'ForwardDelete');
- const isBeforeRoot = rootNode => elm => eq(rootNode, SugarElement.fromDom(elm.dom.parentNode));
- const isTextBlockOrListItem = element => isTextBlock$2(element) || isListItem(element);
- const getParentBlock$2 = (rootNode, elm) => {
- if (contains(rootNode, elm)) {
- return closest$4(elm, isTextBlockOrListItem, isBeforeRoot(rootNode));
- } else {
- return Optional.none();
- }
- };
- const placeCaretInEmptyBody = editor => {
- const body = editor.getBody();
- const node = body.firstChild && editor.dom.isBlock(body.firstChild) ? body.firstChild : body;
- editor.selection.setCursorLocation(node, 0);
- };
- const paddEmptyBody = editor => {
- if (editor.dom.isEmpty(editor.getBody())) {
- editor.setContent('');
- placeCaretInEmptyBody(editor);
- }
- };
- const willDeleteLastPositionInElement = (forward, fromPos, elm) => lift2(firstPositionIn(elm), lastPositionIn(elm), (firstPos, lastPos) => {
- const normalizedFirstPos = normalizePosition(true, firstPos);
- const normalizedLastPos = normalizePosition(false, lastPos);
- const normalizedFromPos = normalizePosition(false, fromPos);
- if (forward) {
- return nextPosition(elm, normalizedFromPos).exists(nextPos => nextPos.isEqual(normalizedLastPos) && fromPos.isEqual(normalizedFirstPos));
- } else {
- return prevPosition(elm, normalizedFromPos).exists(prevPos => prevPos.isEqual(normalizedFirstPos) && fromPos.isEqual(normalizedLastPos));
- }
- }).getOr(true);
- const freefallRtl = root => {
- const child = isComment$1(root) ? prevSibling(root) : lastChild(root);
- return child.bind(freefallRtl).orThunk(() => Optional.some(root));
- };
- const deleteRangeContents = (editor, rng, root, moveSelection = true) => {
- rng.deleteContents();
- const lastNode = freefallRtl(root).getOr(root);
- const lastBlock = SugarElement.fromDom(editor.dom.getParent(lastNode.dom, editor.dom.isBlock));
- if (isEmpty$2(lastBlock)) {
- fillWithPaddingBr(lastBlock);
- if (moveSelection) {
- editor.selection.setCursorLocation(lastBlock.dom, 0);
- }
- }
- if (!eq(root, lastBlock)) {
- const additionalCleanupNodes = is$2(parent(lastBlock), root) ? [] : siblings(lastBlock);
- each$f(additionalCleanupNodes.concat(children(root)), node => {
- if (!eq(node, lastBlock) && !contains(node, lastBlock) && isEmpty$2(node)) {
- remove$6(node);
- }
- });
- }
- };
- const isRootFromElement = root => cur => eq(root, cur);
- const getTableCells = table => descendants(table, 'td,th');
- const getTableDetailsFromRange = (rng, isRoot) => {
- const getTable = node => getClosestTable(SugarElement.fromDom(node), isRoot);
- const startTable = getTable(rng.startContainer);
- const endTable = getTable(rng.endContainer);
- const isStartInTable = startTable.isSome();
- const isEndInTable = endTable.isSome();
- const isSameTable = lift2(startTable, endTable, eq).getOr(false);
- const isMultiTable = !isSameTable && isStartInTable && isEndInTable;
- return {
- startTable,
- endTable,
- isStartInTable,
- isEndInTable,
- isSameTable,
- isMultiTable
- };
- };
- const tableCellRng = (start, end) => ({
- start,
- end
- });
- const tableSelection = (rng, table, cells) => ({
- rng,
- table,
- cells
- });
- const deleteAction = Adt.generate([
- {
- singleCellTable: [
- 'rng',
- 'cell'
- ]
- },
- { fullTable: ['table'] },
- {
- partialTable: [
- 'cells',
- 'outsideDetails'
- ]
- },
- {
- multiTable: [
- 'startTableCells',
- 'endTableCells',
- 'betweenRng'
- ]
- }
- ]);
- const getClosestCell$1 = (container, isRoot) => closest$3(SugarElement.fromDom(container), 'td,th', isRoot);
- const isExpandedCellRng = cellRng => !eq(cellRng.start, cellRng.end);
- const getTableFromCellRng = (cellRng, isRoot) => getClosestTable(cellRng.start, isRoot).bind(startParentTable => getClosestTable(cellRng.end, isRoot).bind(endParentTable => someIf(eq(startParentTable, endParentTable), startParentTable)));
- const isSingleCellTable = (cellRng, isRoot) => !isExpandedCellRng(cellRng) && getTableFromCellRng(cellRng, isRoot).exists(table => {
- const rows = table.dom.rows;
- return rows.length === 1 && rows[0].cells.length === 1;
- });
- const getCellRng = (rng, isRoot) => {
- const startCell = getClosestCell$1(rng.startContainer, isRoot);
- const endCell = getClosestCell$1(rng.endContainer, isRoot);
- return lift2(startCell, endCell, tableCellRng);
- };
- const getCellRangeFromStartTable = isRoot => startCell => getClosestTable(startCell, isRoot).bind(table => last$3(getTableCells(table)).map(endCell => tableCellRng(startCell, endCell)));
- const getCellRangeFromEndTable = isRoot => endCell => getClosestTable(endCell, isRoot).bind(table => head(getTableCells(table)).map(startCell => tableCellRng(startCell, endCell)));
- const getTableSelectionFromCellRng = isRoot => cellRng => getTableFromCellRng(cellRng, isRoot).map(table => tableSelection(cellRng, table, getTableCells(table)));
- const getTableSelections = (cellRng, selectionDetails, rng, isRoot) => {
- if (rng.collapsed || !cellRng.forall(isExpandedCellRng)) {
- return Optional.none();
- } else if (selectionDetails.isSameTable) {
- const sameTableSelection = cellRng.bind(getTableSelectionFromCellRng(isRoot));
- return Optional.some({
- start: sameTableSelection,
- end: sameTableSelection
- });
- } else {
- const startCell = getClosestCell$1(rng.startContainer, isRoot);
- const endCell = getClosestCell$1(rng.endContainer, isRoot);
- const startTableSelection = startCell.bind(getCellRangeFromStartTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot));
- const endTableSelection = endCell.bind(getCellRangeFromEndTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot));
- return Optional.some({
- start: startTableSelection,
- end: endTableSelection
- });
- }
- };
- const getCellIndex = (cells, cell) => findIndex$2(cells, x => eq(x, cell));
- const getSelectedCells = tableSelection => lift2(getCellIndex(tableSelection.cells, tableSelection.rng.start), getCellIndex(tableSelection.cells, tableSelection.rng.end), (startIndex, endIndex) => tableSelection.cells.slice(startIndex, endIndex + 1));
- const isSingleCellTableContentSelected = (optCellRng, rng, isRoot) => optCellRng.exists(cellRng => isSingleCellTable(cellRng, isRoot) && hasAllContentsSelected(cellRng.start, rng));
- const unselectCells = (rng, selectionDetails) => {
- const {startTable, endTable} = selectionDetails;
- const otherContentRng = rng.cloneRange();
- startTable.each(table => otherContentRng.setStartAfter(table.dom));
- endTable.each(table => otherContentRng.setEndBefore(table.dom));
- return otherContentRng;
- };
- const handleSingleTable = (cellRng, selectionDetails, rng, isRoot) => getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(({start, end}) => start.or(end)).bind(tableSelection => {
- const {isSameTable} = selectionDetails;
- const selectedCells = getSelectedCells(tableSelection).getOr([]);
- if (isSameTable && tableSelection.cells.length === selectedCells.length) {
- return Optional.some(deleteAction.fullTable(tableSelection.table));
- } else if (selectedCells.length > 0) {
- if (isSameTable) {
- return Optional.some(deleteAction.partialTable(selectedCells, Optional.none()));
- } else {
- const otherContentRng = unselectCells(rng, selectionDetails);
- return Optional.some(deleteAction.partialTable(selectedCells, Optional.some({
- ...selectionDetails,
- rng: otherContentRng
- })));
- }
- } else {
- return Optional.none();
- }
- });
- const handleMultiTable = (cellRng, selectionDetails, rng, isRoot) => getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(({start, end}) => {
- const startTableSelectedCells = start.bind(getSelectedCells).getOr([]);
- const endTableSelectedCells = end.bind(getSelectedCells).getOr([]);
- if (startTableSelectedCells.length > 0 && endTableSelectedCells.length > 0) {
- const otherContentRng = unselectCells(rng, selectionDetails);
- return Optional.some(deleteAction.multiTable(startTableSelectedCells, endTableSelectedCells, otherContentRng));
- } else {
- return Optional.none();
- }
- });
- const getActionFromRange = (root, rng) => {
- const isRoot = isRootFromElement(root);
- const optCellRng = getCellRng(rng, isRoot);
- const selectionDetails = getTableDetailsFromRange(rng, isRoot);
- if (isSingleCellTableContentSelected(optCellRng, rng, isRoot)) {
- return optCellRng.map(cellRng => deleteAction.singleCellTable(rng, cellRng.start));
- } else if (selectionDetails.isMultiTable) {
- return handleMultiTable(optCellRng, selectionDetails, rng, isRoot);
- } else {
- return handleSingleTable(optCellRng, selectionDetails, rng, isRoot);
- }
- };
- const cleanCells = cells => each$f(cells, cell => {
- remove$b(cell, 'contenteditable');
- fillWithPaddingBr(cell);
- });
- const getOutsideBlock = (editor, container) => Optional.from(editor.dom.getParent(container, editor.dom.isBlock)).map(SugarElement.fromDom);
- const handleEmptyBlock = (editor, startInTable, emptyBlock) => {
- emptyBlock.each(block => {
- if (startInTable) {
- remove$6(block);
- } else {
- fillWithPaddingBr(block);
- editor.selection.setCursorLocation(block.dom, 0);
- }
- });
- };
- const deleteContentInsideCell = (editor, cell, rng, isFirstCellInSelection) => {
- const insideTableRng = rng.cloneRange();
- if (isFirstCellInSelection) {
- insideTableRng.setStart(rng.startContainer, rng.startOffset);
- insideTableRng.setEndAfter(cell.dom.lastChild);
- } else {
- insideTableRng.setStartBefore(cell.dom.firstChild);
- insideTableRng.setEnd(rng.endContainer, rng.endOffset);
- }
- deleteCellContents(editor, insideTableRng, cell, false).each(action => action());
- };
- const collapseAndRestoreCellSelection = editor => {
- const selectedCells = getCellsFromEditor(editor);
- const selectedNode = SugarElement.fromDom(editor.selection.getNode());
- if (isTableCell$5(selectedNode.dom) && isEmpty$2(selectedNode)) {
- editor.selection.setCursorLocation(selectedNode.dom, 0);
- } else {
- editor.selection.collapse(true);
- }
- if (selectedCells.length > 1 && exists(selectedCells, cell => eq(cell, selectedNode))) {
- set$2(selectedNode, 'data-mce-selected', '1');
- }
- };
- const emptySingleTableCells = (editor, cells, outsideDetails) => Optional.some(() => {
- const editorRng = editor.selection.getRng();
- const cellsToClean = outsideDetails.bind(({rng, isStartInTable}) => {
- const outsideBlock = getOutsideBlock(editor, isStartInTable ? rng.endContainer : rng.startContainer);
- rng.deleteContents();
- handleEmptyBlock(editor, isStartInTable, outsideBlock.filter(isEmpty$2));
- const endPointCell = isStartInTable ? cells[0] : cells[cells.length - 1];
- deleteContentInsideCell(editor, endPointCell, editorRng, isStartInTable);
- if (!isEmpty$2(endPointCell)) {
- return Optional.some(isStartInTable ? cells.slice(1) : cells.slice(0, -1));
- } else {
- return Optional.none();
- }
- }).getOr(cells);
- cleanCells(cellsToClean);
- collapseAndRestoreCellSelection(editor);
- });
- const emptyMultiTableCells = (editor, startTableCells, endTableCells, betweenRng) => Optional.some(() => {
- const rng = editor.selection.getRng();
- const startCell = startTableCells[0];
- const endCell = endTableCells[endTableCells.length - 1];
- deleteContentInsideCell(editor, startCell, rng, true);
- deleteContentInsideCell(editor, endCell, rng, false);
- const startTableCellsToClean = isEmpty$2(startCell) ? startTableCells : startTableCells.slice(1);
- const endTableCellsToClean = isEmpty$2(endCell) ? endTableCells : endTableCells.slice(0, -1);
- cleanCells(startTableCellsToClean.concat(endTableCellsToClean));
- betweenRng.deleteContents();
- collapseAndRestoreCellSelection(editor);
- });
- const deleteCellContents = (editor, rng, cell, moveSelection = true) => Optional.some(() => {
- deleteRangeContents(editor, rng, cell, moveSelection);
- });
- const deleteTableElement = (editor, table) => Optional.some(() => deleteElement$2(editor, false, table));
- const deleteCellRange = (editor, rootElm, rng) => getActionFromRange(rootElm, rng).bind(action => action.fold(curry(deleteCellContents, editor), curry(deleteTableElement, editor), curry(emptySingleTableCells, editor), curry(emptyMultiTableCells, editor)));
- const deleteCaptionRange = (editor, caption) => emptyElement(editor, caption);
- const deleteTableRange = (editor, rootElm, rng, startElm) => getParentCaption(rootElm, startElm).fold(() => deleteCellRange(editor, rootElm, rng), caption => deleteCaptionRange(editor, caption));
- const deleteRange$2 = (editor, startElm, selectedCells) => {
- const rootNode = SugarElement.fromDom(editor.getBody());
- const rng = editor.selection.getRng();
- return selectedCells.length !== 0 ? emptySingleTableCells(editor, selectedCells, Optional.none()) : deleteTableRange(editor, rootNode, rng, startElm);
- };
- const getParentCell = (rootElm, elm) => find$2(parentsAndSelf(elm, rootElm), isTableCell$4);
- const getParentCaption = (rootElm, elm) => find$2(parentsAndSelf(elm, rootElm), isTag('caption'));
- const deleteBetweenCells = (editor, rootElm, forward, fromCell, from) => navigate(forward, editor.getBody(), from).bind(to => getParentCell(rootElm, SugarElement.fromDom(to.getNode())).bind(toCell => eq(toCell, fromCell) ? Optional.none() : Optional.some(noop)));
- const emptyElement = (editor, elm) => Optional.some(() => {
- fillWithPaddingBr(elm);
- editor.selection.setCursorLocation(elm.dom, 0);
- });
- const isDeleteOfLastCharPos = (fromCaption, forward, from, to) => firstPositionIn(fromCaption.dom).bind(first => lastPositionIn(fromCaption.dom).map(last => forward ? from.isEqual(first) && to.isEqual(last) : from.isEqual(last) && to.isEqual(first))).getOr(true);
- const emptyCaretCaption = (editor, elm) => emptyElement(editor, elm);
- const validateCaretCaption = (rootElm, fromCaption, to) => getParentCaption(rootElm, SugarElement.fromDom(to.getNode())).fold(() => Optional.some(noop), toCaption => someIf(!eq(toCaption, fromCaption), noop));
- const deleteCaretInsideCaption = (editor, rootElm, forward, fromCaption, from) => navigate(forward, editor.getBody(), from).fold(() => Optional.some(noop), to => isDeleteOfLastCharPos(fromCaption, forward, from, to) ? emptyCaretCaption(editor, fromCaption) : validateCaretCaption(rootElm, fromCaption, to));
- const deleteCaretCells = (editor, forward, rootElm, startElm) => {
- const from = CaretPosition.fromRangeStart(editor.selection.getRng());
- return getParentCell(rootElm, startElm).bind(fromCell => isEmpty$2(fromCell) ? emptyElement(editor, fromCell) : deleteBetweenCells(editor, rootElm, forward, fromCell, from));
- };
- const deleteCaretCaption = (editor, forward, rootElm, fromCaption) => {
- const from = CaretPosition.fromRangeStart(editor.selection.getRng());
- return isEmpty$2(fromCaption) ? emptyElement(editor, fromCaption) : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from);
- };
- const isNearTable = (forward, pos) => forward ? isBeforeTable(pos) : isAfterTable(pos);
- const isBeforeOrAfterTable = (editor, forward) => {
- const fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
- return isNearTable(forward, fromPos) || fromPosition(forward, editor.getBody(), fromPos).exists(pos => isNearTable(forward, pos));
- };
- const deleteCaret$3 = (editor, forward, startElm) => {
- const rootElm = SugarElement.fromDom(editor.getBody());
- return getParentCaption(rootElm, startElm).fold(() => deleteCaretCells(editor, forward, rootElm, startElm).orThunk(() => someIf(isBeforeOrAfterTable(editor, forward), noop)), fromCaption => deleteCaretCaption(editor, forward, rootElm, fromCaption));
- };
- const backspaceDelete$9 = (editor, forward) => {
- const startElm = SugarElement.fromDom(editor.selection.getStart(true));
- const cells = getCellsFromEditor(editor);
- return editor.selection.isCollapsed() && cells.length === 0 ? deleteCaret$3(editor, forward, startElm) : deleteRange$2(editor, startElm, cells);
- };
- const getContentEditableRoot$1 = (root, node) => {
- while (node && node !== root) {
- if (isContentEditableTrue$5(node) || isContentEditableFalse$b(node)) {
- return node;
- }
- node = node.parentNode;
- }
- return null;
- };
- const traverse = (node, fn) => {
- fn(node);
- if (node.firstChild) {
- traverse(node.firstChild, fn);
- }
- if (node.next) {
- traverse(node.next, fn);
- }
- };
- const matchNode$1 = (nodeFilters, attributeFilters, node, matches) => {
- const name = node.name;
- for (let ni = 0, nl = nodeFilters.length; ni < nl; ni++) {
- const filter = nodeFilters[ni];
- if (filter.name === name) {
- const match = matches.nodes[name];
- if (match) {
- match.nodes.push(node);
- } else {
- matches.nodes[name] = {
- filter,
- nodes: [node]
- };
- }
- }
- }
- if (node.attributes) {
- for (let ai = 0, al = attributeFilters.length; ai < al; ai++) {
- const filter = attributeFilters[ai];
- const attrName = filter.name;
- if (attrName in node.attributes.map) {
- const match = matches.attributes[attrName];
- if (match) {
- match.nodes.push(node);
- } else {
- matches.attributes[attrName] = {
- filter,
- nodes: [node]
- };
- }
- }
- }
- }
- };
- const findMatchingNodes = (nodeFilters, attributeFilters, node) => {
- const matches = {
- nodes: {},
- attributes: {}
- };
- if (node.firstChild) {
- traverse(node.firstChild, node => {
- matchNode$1(nodeFilters, attributeFilters, node, matches);
- });
- }
- return matches;
- };
- const runFilters = (matches, args) => {
- const run = matchRecord => {
- each$e(matchRecord, match => {
- const nodes = filter$6(match.nodes, node => isNonNullable(node.parent));
- each$f(match.filter.callbacks, callback => {
- callback(nodes, match.filter.name, args);
- });
- });
- };
- run(matches.nodes);
- run(matches.attributes);
- };
- const filter$3 = (nodeFilters, attributeFilters, node, args = {}) => {
- const matches = findMatchingNodes(nodeFilters, attributeFilters, node);
- runFilters(matches, args);
- };
- const paddEmptyNode = (settings, args, blockElements, node) => {
- if (args.insert && blockElements[node.name]) {
- node.empty().append(new AstNode('br', 1));
- } else {
- node.empty().append(new AstNode('#text', 3)).value = nbsp;
- }
- };
- const isPaddedWithNbsp = node => hasOnlyChild(node, '#text') && node.firstChild.value === nbsp;
- const hasOnlyChild = (node, name) => node && node.firstChild && node.firstChild === node.lastChild && node.firstChild.name === name;
- const isPadded = (schema, node) => {
- const rule = schema.getElementRule(node.name);
- return rule && rule.paddEmpty;
- };
- const isEmpty = (schema, nonEmptyElements, whitespaceElements, node) => node.isEmpty(nonEmptyElements, whitespaceElements, node => isPadded(schema, node));
- const isLineBreakNode = (node, blockElements) => node && (node.name in blockElements || node.name === 'br');
- const removeOrUnwrapInvalidNode = (node, schema, originalNodeParent = node.parent) => {
- if (schema.getSpecialElements()[node.name]) {
- node.empty().remove();
- } else {
- const children = node.children();
- for (const childNode of children) {
- if (!schema.isValidChild(originalNodeParent.name, childNode.name)) {
- removeOrUnwrapInvalidNode(childNode, schema, originalNodeParent);
- }
- }
- node.unwrap();
- }
- };
- const cleanInvalidNodes = (nodes, schema, onCreate = noop) => {
- const textBlockElements = schema.getTextBlockElements();
- const nonEmptyElements = schema.getNonEmptyElements();
- const whitespaceElements = schema.getWhitespaceElements();
- const nonSplittableElements = Tools.makeMap('tr,td,th,tbody,thead,tfoot,table');
- const fixed = new Set();
- for (let ni = 0; ni < nodes.length; ni++) {
- const node = nodes[ni];
- let parent;
- let newParent;
- let tempNode;
- if (!node.parent || fixed.has(node)) {
- continue;
- }
- if (textBlockElements[node.name] && node.parent.name === 'li') {
- let sibling = node.next;
- while (sibling) {
- if (textBlockElements[sibling.name]) {
- sibling.name = 'li';
- fixed.add(sibling);
- node.parent.insert(sibling, node.parent);
- } else {
- break;
- }
- sibling = sibling.next;
- }
- node.unwrap();
- continue;
- }
- const parents = [node];
- for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplittableElements[parent.name]; parent = parent.parent) {
- parents.push(parent);
- }
- if (parent && parents.length > 1) {
- if (schema.isValidChild(parent.name, node.name)) {
- parents.reverse();
- newParent = parents[0].clone();
- onCreate(newParent);
- let currentNode = newParent;
- for (let i = 0; i < parents.length - 1; i++) {
- if (schema.isValidChild(currentNode.name, parents[i].name)) {
- tempNode = parents[i].clone();
- onCreate(tempNode);
- currentNode.append(tempNode);
- } else {
- tempNode = currentNode;
- }
- for (let childNode = parents[i].firstChild; childNode && childNode !== parents[i + 1];) {
- const nextNode = childNode.next;
- tempNode.append(childNode);
- childNode = nextNode;
- }
- currentNode = tempNode;
- }
- if (!isEmpty(schema, nonEmptyElements, whitespaceElements, newParent)) {
- parent.insert(newParent, parents[0], true);
- parent.insert(node, newParent);
- } else {
- parent.insert(node, parents[0], true);
- }
- parent = parents[0];
- if (isEmpty(schema, nonEmptyElements, whitespaceElements, parent) || hasOnlyChild(parent, 'br')) {
- parent.empty().remove();
- }
- } else {
- removeOrUnwrapInvalidNode(node, schema);
- }
- } else if (node.parent) {
- if (node.name === 'li') {
- let sibling = node.prev;
- if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {
- sibling.append(node);
- continue;
- }
- sibling = node.next;
- if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {
- sibling.insert(node, sibling.firstChild, true);
- continue;
- }
- const wrapper = new AstNode('ul', 1);
- onCreate(wrapper);
- node.wrap(wrapper);
- continue;
- }
- if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
- const wrapper = new AstNode('div', 1);
- onCreate(wrapper);
- node.wrap(wrapper);
- } else {
- removeOrUnwrapInvalidNode(node, schema);
- }
- }
- }
- };
- const createRange = (sc, so, ec, eo) => {
- const rng = document.createRange();
- rng.setStart(sc, so);
- rng.setEnd(ec, eo);
- return rng;
- };
- const normalizeBlockSelectionRange = rng => {
- const startPos = CaretPosition.fromRangeStart(rng);
- const endPos = CaretPosition.fromRangeEnd(rng);
- const rootNode = rng.commonAncestorContainer;
- return fromPosition(false, rootNode, endPos).map(newEndPos => {
- if (!isInSameBlock(startPos, endPos, rootNode) && isInSameBlock(startPos, newEndPos, rootNode)) {
- return createRange(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset());
- } else {
- return rng;
- }
- }).getOr(rng);
- };
- const normalize = rng => rng.collapsed ? rng : normalizeBlockSelectionRange(rng);
- const hasOnlyOneChild$1 = node => {
- return node.firstChild && node.firstChild === node.lastChild;
- };
- const isPaddingNode = node => {
- return node.name === 'br' || node.value === nbsp;
- };
- const isPaddedEmptyBlock = (schema, node) => {
- const blockElements = schema.getBlockElements();
- return blockElements[node.name] && hasOnlyOneChild$1(node) && isPaddingNode(node.firstChild);
- };
- const isEmptyFragmentElement = (schema, node) => {
- const nonEmptyElements = schema.getNonEmptyElements();
- return node && (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node));
- };
- const isListFragment = (schema, fragment) => {
- let firstChild = fragment.firstChild;
- let lastChild = fragment.lastChild;
- if (firstChild && firstChild.name === 'meta') {
- firstChild = firstChild.next;
- }
- if (lastChild && lastChild.attr('id') === 'mce_marker') {
- lastChild = lastChild.prev;
- }
- if (isEmptyFragmentElement(schema, lastChild)) {
- lastChild = lastChild.prev;
- }
- if (!firstChild || firstChild !== lastChild) {
- return false;
- }
- return firstChild.name === 'ul' || firstChild.name === 'ol';
- };
- const cleanupDomFragment = domFragment => {
- const firstChild = domFragment.firstChild;
- const lastChild = domFragment.lastChild;
- if (firstChild && firstChild.nodeName === 'META') {
- firstChild.parentNode.removeChild(firstChild);
- }
- if (lastChild && lastChild.id === 'mce_marker') {
- lastChild.parentNode.removeChild(lastChild);
- }
- return domFragment;
- };
- const toDomFragment = (dom, serializer, fragment) => {
- const html = serializer.serialize(fragment);
- const domFragment = dom.createFragment(html);
- return cleanupDomFragment(domFragment);
- };
- const listItems = elm => {
- return filter$6(elm.childNodes, child => {
- return child.nodeName === 'LI';
- });
- };
- const isPadding = node => {
- return node.data === nbsp || isBr$6(node);
- };
- const isListItemPadded = node => {
- return node && node.firstChild && node.firstChild === node.lastChild && isPadding(node.firstChild);
- };
- const isEmptyOrPadded = elm => {
- return !elm.firstChild || isListItemPadded(elm);
- };
- const trimListItems = elms => {
- return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1]) ? elms.slice(0, -1) : elms;
- };
- const getParentLi = (dom, node) => {
- const parentBlock = dom.getParent(node, dom.isBlock);
- return parentBlock && parentBlock.nodeName === 'LI' ? parentBlock : null;
- };
- const isParentBlockLi = (dom, node) => {
- return !!getParentLi(dom, node);
- };
- const getSplit = (parentNode, rng) => {
- const beforeRng = rng.cloneRange();
- const afterRng = rng.cloneRange();
- beforeRng.setStartBefore(parentNode);
- afterRng.setEndAfter(parentNode);
- return [
- beforeRng.cloneContents(),
- afterRng.cloneContents()
- ];
- };
- const findFirstIn = (node, rootNode) => {
- const caretPos = CaretPosition.before(node);
- const caretWalker = CaretWalker(rootNode);
- const newCaretPos = caretWalker.next(caretPos);
- return newCaretPos ? newCaretPos.toRange() : null;
- };
- const findLastOf = (node, rootNode) => {
- const caretPos = CaretPosition.after(node);
- const caretWalker = CaretWalker(rootNode);
- const newCaretPos = caretWalker.prev(caretPos);
- return newCaretPos ? newCaretPos.toRange() : null;
- };
- const insertMiddle = (target, elms, rootNode, rng) => {
- const parts = getSplit(target, rng);
- const parentElm = target.parentNode;
- parentElm.insertBefore(parts[0], target);
- Tools.each(elms, li => {
- parentElm.insertBefore(li, target);
- });
- parentElm.insertBefore(parts[1], target);
- parentElm.removeChild(target);
- return findLastOf(elms[elms.length - 1], rootNode);
- };
- const insertBefore$1 = (target, elms, rootNode) => {
- const parentElm = target.parentNode;
- Tools.each(elms, elm => {
- parentElm.insertBefore(elm, target);
- });
- return findFirstIn(target, rootNode);
- };
- const insertAfter$1 = (target, elms, rootNode, dom) => {
- dom.insertAfter(elms.reverse(), target);
- return findLastOf(elms[0], rootNode);
- };
- const insertAtCaret$1 = (serializer, dom, rng, fragment) => {
- const domFragment = toDomFragment(dom, serializer, fragment);
- const liTarget = getParentLi(dom, rng.startContainer);
- const liElms = trimListItems(listItems(domFragment.firstChild));
- const BEGINNING = 1, END = 2;
- const rootNode = dom.getRoot();
- const isAt = location => {
- const caretPos = CaretPosition.fromRangeStart(rng);
- const caretWalker = CaretWalker(dom.getRoot());
- const newPos = location === BEGINNING ? caretWalker.prev(caretPos) : caretWalker.next(caretPos);
- return newPos ? getParentLi(dom, newPos.getNode()) !== liTarget : true;
- };
- if (isAt(BEGINNING)) {
- return insertBefore$1(liTarget, liElms, rootNode);
- } else if (isAt(END)) {
- return insertAfter$1(liTarget, liElms, rootNode, dom);
- }
- return insertMiddle(liTarget, liElms, rootNode, rng);
- };
- const wrappedElements = ['pre'];
- const shouldPasteContentOnly = (fragment, parentNode) => {
- const firstNode = fragment.firstChild;
- const isAFlattenableTag = contains$2(wrappedElements, firstNode.name);
- const isPastingInTheSameTag = firstNode.name === parentNode.tagName.toLowerCase();
- const lastNode = fragment.lastChild.attr('data-mce-type') === 'bookmark' ? fragment.lastChild.prev : fragment.lastChild;
- const isCopingOnlyOneTag = firstNode === lastNode;
- return isCopingOnlyOneTag && isAFlattenableTag && isPastingInTheSameTag;
- };
- const isTableCell$1 = isTableCell$5;
- const isTableCellContentSelected = (dom, rng, cell) => {
- if (cell !== null) {
- const endCell = dom.getParent(rng.endContainer, isTableCell$1);
- return cell === endCell && hasAllContentsSelected(SugarElement.fromDom(cell), rng);
- } else {
- return false;
- }
- };
- const validInsertion = (editor, value, parentNode) => {
- if (parentNode.getAttribute('data-mce-bogus') === 'all') {
- parentNode.parentNode.insertBefore(editor.dom.createFragment(value), parentNode);
- } else {
- const node = parentNode.firstChild;
- const node2 = parentNode.lastChild;
- if (!node || node === node2 && node.nodeName === 'BR') {
- editor.dom.setHTML(parentNode, value);
- } else {
- editor.selection.setContent(value, { no_events: true });
- }
- }
- };
- const trimBrsFromTableCell = (dom, elm) => {
- Optional.from(dom.getParent(elm, 'td,th')).map(SugarElement.fromDom).each(trimBlockTrailingBr);
- };
- const reduceInlineTextElements = (editor, merge) => {
- const textInlineElements = editor.schema.getTextInlineElements();
- const dom = editor.dom;
- if (merge) {
- const root = editor.getBody();
- const elementUtils = ElementUtils(dom);
- Tools.each(dom.select('*[data-mce-fragment]'), node => {
- const isInline = isNonNullable(textInlineElements[node.nodeName.toLowerCase()]);
- if (isInline && hasInheritableStyles(dom, node)) {
- for (let parentNode = node.parentNode; isNonNullable(parentNode) && parentNode !== root; parentNode = parentNode.parentNode) {
- const styleConflict = hasStyleConflict(dom, node, parentNode);
- if (styleConflict) {
- break;
- }
- if (elementUtils.compare(parentNode, node)) {
- dom.remove(node, true);
- break;
- }
- }
- }
- });
- }
- };
- const markFragmentElements = fragment => {
- let node = fragment;
- while (node = node.walk()) {
- if (node.type === 1) {
- node.attr('data-mce-fragment', '1');
- }
- }
- };
- const unmarkFragmentElements = elm => {
- Tools.each(elm.getElementsByTagName('*'), elm => {
- elm.removeAttribute('data-mce-fragment');
- });
- };
- const isPartOfFragment = node => {
- return !!node.getAttribute('data-mce-fragment');
- };
- const canHaveChildren = (editor, node) => {
- return node && !editor.schema.getVoidElements()[node.nodeName];
- };
- const moveSelectionToMarker = (editor, marker) => {
- let nextRng;
- const dom = editor.dom;
- const selection = editor.selection;
- if (!marker) {
- return;
- }
- selection.scrollIntoView(marker);
- const parentEditableElm = getContentEditableRoot$1(editor.getBody(), marker);
- if (dom.getContentEditable(parentEditableElm) === 'false') {
- dom.remove(marker);
- selection.select(parentEditableElm);
- return;
- }
- let rng = dom.createRng();
- const node = marker.previousSibling;
- if (isText$9(node)) {
- rng.setStart(node, node.nodeValue.length);
- const node2 = marker.nextSibling;
- if (isText$9(node2)) {
- node.appendData(node2.data);
- node2.parentNode.removeChild(node2);
- }
- } else {
- rng.setStartBefore(marker);
- rng.setEndBefore(marker);
- }
- const findNextCaretRng = rng => {
- let caretPos = CaretPosition.fromRangeStart(rng);
- const caretWalker = CaretWalker(editor.getBody());
- caretPos = caretWalker.next(caretPos);
- if (caretPos) {
- return caretPos.toRange();
- }
- };
- const parentBlock = dom.getParent(marker, dom.isBlock);
- dom.remove(marker);
- if (parentBlock && dom.isEmpty(parentBlock)) {
- empty(SugarElement.fromDom(parentBlock));
- rng.setStart(parentBlock, 0);
- rng.setEnd(parentBlock, 0);
- if (!isTableCell$1(parentBlock) && !isPartOfFragment(parentBlock) && (nextRng = findNextCaretRng(rng))) {
- rng = nextRng;
- dom.remove(parentBlock);
- } else {
- dom.add(parentBlock, dom.create('br', { 'data-mce-bogus': '1' }));
- }
- }
- selection.setRng(rng);
- };
- const deleteSelectedContent = editor => {
- const dom = editor.dom;
- const rng = normalize(editor.selection.getRng());
- editor.selection.setRng(rng);
- const startCell = dom.getParent(rng.startContainer, isTableCell$1);
- if (isTableCellContentSelected(dom, rng, startCell)) {
- deleteCellContents(editor, rng, SugarElement.fromDom(startCell));
- } else {
- editor.getDoc().execCommand('Delete', false, null);
- }
- };
- const insertHtmlAtCaret = (editor, value, details) => {
- let parentNode;
- let rng, node;
- const selection = editor.selection;
- const dom = editor.dom;
- const parser = editor.parser;
- const merge = details.merge;
- const serializer = HtmlSerializer({ validate: true }, editor.schema);
- const bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark"></span>';
- if (value.indexOf('{$caret}') === -1) {
- value += '{$caret}';
- }
- value = value.replace(/\{\$caret\}/, bookmarkHtml);
- rng = selection.getRng();
- const caretElement = rng.startContainer || (rng.parentElement ? rng.parentElement() : null);
- const body = editor.getBody();
- if (caretElement === body && selection.isCollapsed()) {
- if (dom.isBlock(body.firstChild) && canHaveChildren(editor, body.firstChild) && dom.isEmpty(body.firstChild)) {
- rng = dom.createRng();
- rng.setStart(body.firstChild, 0);
- rng.setEnd(body.firstChild, 0);
- selection.setRng(rng);
- }
- }
- if (!selection.isCollapsed()) {
- deleteSelectedContent(editor);
- }
- parentNode = selection.getNode();
- const parserArgs = {
- context: parentNode.nodeName.toLowerCase(),
- data: details.data,
- insert: true
- };
- const fragment = parser.parse(value, parserArgs);
- if (details.paste === true && isListFragment(editor.schema, fragment) && isParentBlockLi(dom, parentNode)) {
- rng = insertAtCaret$1(serializer, dom, selection.getRng(), fragment);
- selection.setRng(rng);
- return value;
- }
- if (details.paste === true && shouldPasteContentOnly(fragment, parentNode)) {
- fragment.firstChild.unwrap();
- }
- markFragmentElements(fragment);
- node = fragment.lastChild;
- if (node.attr('id') === 'mce_marker') {
- const marker = node;
- for (node = node.prev; node; node = node.walk(true)) {
- if (node.type === 3 || !dom.isBlock(node.name)) {
- if (editor.schema.isValidChild(node.parent.name, 'span')) {
- node.parent.insert(marker, node, node.name === 'br');
- }
- break;
- }
- }
- }
- editor._selectionOverrides.showBlockCaretContainer(parentNode);
- if (!parserArgs.invalid) {
- value = serializer.serialize(fragment);
- validInsertion(editor, value, parentNode);
- } else {
- editor.selection.setContent(bookmarkHtml);
- parentNode = selection.getNode();
- const rootNode = editor.getBody();
- if (parentNode.nodeType === 9) {
- parentNode = node = rootNode;
- } else {
- node = parentNode;
- }
- while (node !== rootNode) {
- parentNode = node;
- node = node.parentNode;
- }
- value = parentNode === rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
- const root = parser.parse(value);
- for (let markerNode = root; markerNode; markerNode = markerNode.walk()) {
- if (markerNode.attr('id') === 'mce_marker') {
- markerNode.replace(fragment);
- break;
- }
- }
- const toExtract = fragment.children();
- const parent = fragment.parent.name;
- fragment.unwrap();
- const invalidChildren = filter$6(toExtract, node => !editor.schema.isValidChild(parent, node.name));
- cleanInvalidNodes(invalidChildren, editor.schema);
- filter$3(parser.getNodeFilters(), parser.getAttributeFilters(), root);
- value = serializer.serialize(root);
- if (parentNode === rootNode) {
- dom.setHTML(rootNode, value);
- } else {
- dom.setOuterHTML(parentNode, value);
- }
- }
- reduceInlineTextElements(editor, merge);
- moveSelectionToMarker(editor, dom.get('mce_marker'));
- unmarkFragmentElements(editor.getBody());
- trimBrsFromTableCell(dom, selection.getStart());
- return value;
- };
- const isTreeNode = content => content instanceof AstNode;
- const moveSelection = editor => {
- if (hasFocus(editor)) {
- firstPositionIn(editor.getBody()).each(pos => {
- const node = pos.getNode();
- const caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos;
- editor.selection.setRng(caretPos.toRange());
- });
- }
- };
- const setEditorHtml = (editor, html, noSelection) => {
- editor.dom.setHTML(editor.getBody(), html);
- if (noSelection !== true) {
- moveSelection(editor);
- }
- };
- const setContentString = (editor, body, content, args) => {
- if (content.length === 0 || /^\s+$/.test(content)) {
- const padd = '<br data-mce-bogus="1">';
- if (body.nodeName === 'TABLE') {
- content = '<tr><td>' + padd + '</td></tr>';
- } else if (/^(UL|OL)$/.test(body.nodeName)) {
- content = '<li>' + padd + '</li>';
- }
- const forcedRootBlockName = getForcedRootBlock(editor);
- if (editor.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) {
- content = padd;
- content = editor.dom.createHTML(forcedRootBlockName, getForcedRootBlockAttrs(editor), content);
- } else if (!content) {
- content = padd;
- }
- setEditorHtml(editor, content, args.no_selection);
- return {
- content,
- html: content
- };
- } else {
- if (args.format !== 'raw') {
- content = HtmlSerializer({ validate: false }, editor.schema).serialize(editor.parser.parse(content, {
- isRootContent: true,
- insert: true
- }));
- }
- const trimmedHtml = isWsPreserveElement(SugarElement.fromDom(body)) ? content : Tools.trim(content);
- setEditorHtml(editor, trimmedHtml, args.no_selection);
- return {
- content: trimmedHtml,
- html: trimmedHtml
- };
- }
- };
- const setContentTree = (editor, body, content, args) => {
- filter$3(editor.parser.getNodeFilters(), editor.parser.getAttributeFilters(), content);
- const html = HtmlSerializer({ validate: false }, editor.schema).serialize(content);
- const trimmedHtml = isWsPreserveElement(SugarElement.fromDom(body)) ? html : Tools.trim(html);
- setEditorHtml(editor, trimmedHtml, args.no_selection);
- return {
- content,
- html: trimmedHtml
- };
- };
- const setContentInternal = (editor, content, args) => {
- return Optional.from(editor.getBody()).map(body => {
- if (isTreeNode(content)) {
- return setContentTree(editor, body, content, args);
- } else {
- return setContentString(editor, body, content, args);
- }
- }).getOr({
- content,
- html: isTreeNode(args.content) ? '' : args.content
- });
- };
- const sibling = (scope, predicate) => sibling$1(scope, predicate).isSome();
- const ensureIsRoot = isRoot => isFunction(isRoot) ? isRoot : never;
- const ancestor = (scope, transform, isRoot) => {
- let element = scope.dom;
- const stop = ensureIsRoot(isRoot);
- while (element.parentNode) {
- element = element.parentNode;
- const el = SugarElement.fromDom(element);
- const transformed = transform(el);
- if (transformed.isSome()) {
- return transformed;
- } else if (stop(el)) {
- break;
- }
- }
- return Optional.none();
- };
- const closest$2 = (scope, transform, isRoot) => {
- const current = transform(scope);
- const stop = ensureIsRoot(isRoot);
- return current.orThunk(() => stop(scope) ? Optional.none() : ancestor(scope, transform, stop));
- };
- const isEq$3 = isEq$5;
- const matchesUnInheritedFormatSelector = (ed, node, name) => {
- const formatList = ed.formatter.get(name);
- if (formatList) {
- for (let i = 0; i < formatList.length; i++) {
- const format = formatList[i];
- if (isSelectorFormat(format) && format.inherit === false && ed.dom.is(node, format.selector)) {
- return true;
- }
- }
- }
- return false;
- };
- const matchParents = (editor, node, name, vars, similar) => {
- const root = editor.dom.getRoot();
- if (node === root) {
- return false;
- }
- node = editor.dom.getParent(node, node => {
- if (matchesUnInheritedFormatSelector(editor, node, name)) {
- return true;
- }
- return node.parentNode === root || !!matchNode(editor, node, name, vars, true);
- });
- return !!matchNode(editor, node, name, vars, similar);
- };
- const matchName = (dom, node, format) => {
- if (isInlineFormat(format) && isEq$3(node, format.inline)) {
- return true;
- }
- if (isBlockFormat(format) && isEq$3(node, format.block)) {
- return true;
- }
- if (isSelectorFormat(format)) {
- return isElement$6(node) && dom.is(node, format.selector);
- }
- return false;
- };
- const matchItems = (dom, node, format, itemName, similar, vars) => {
- const items = format[itemName];
- if (isFunction(format.onmatch)) {
- return format.onmatch(node, format, itemName);
- }
- if (items) {
- if (isUndefined(items.length)) {
- for (const key in items) {
- if (has$2(items, key)) {
- const value = itemName === 'attributes' ? dom.getAttrib(node, key) : getStyle(dom, node, key);
- const expectedValue = replaceVars(items[key], vars);
- const isEmptyValue = isNullable(value) || isEmpty$3(value);
- if (isEmptyValue && isNullable(expectedValue)) {
- continue;
- }
- if (similar && isEmptyValue && !format.exact) {
- return false;
- }
- if ((!similar || format.exact) && !isEq$3(value, normalizeStyleValue(expectedValue, key))) {
- return false;
- }
- }
- }
- } else {
- for (let i = 0; i < items.length; i++) {
- if (itemName === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(dom, node, items[i])) {
- return true;
- }
- }
- }
- }
- return true;
- };
- const matchNode = (ed, node, name, vars, similar) => {
- const formatList = ed.formatter.get(name);
- const dom = ed.dom;
- if (formatList && node) {
- for (let i = 0; i < formatList.length; i++) {
- const format = formatList[i];
- if (matchName(ed.dom, node, format) && matchItems(dom, node, format, 'attributes', similar, vars) && matchItems(dom, node, format, 'styles', similar, vars)) {
- const classes = format.classes;
- if (classes) {
- for (let x = 0; x < classes.length; x++) {
- if (!ed.dom.hasClass(node, replaceVars(classes[x], vars))) {
- return;
- }
- }
- }
- return format;
- }
- }
- }
- };
- const match$2 = (editor, name, vars, node, similar) => {
- if (node) {
- return matchParents(editor, node, name, vars, similar);
- }
- node = editor.selection.getNode();
- if (matchParents(editor, node, name, vars, similar)) {
- return true;
- }
- const startNode = editor.selection.getStart();
- if (startNode !== node) {
- if (matchParents(editor, startNode, name, vars, similar)) {
- return true;
- }
- }
- return false;
- };
- const matchAll = (editor, names, vars) => {
- const matchedFormatNames = [];
- const checkedMap = {};
- const startElement = editor.selection.getStart();
- editor.dom.getParent(startElement, node => {
- for (let i = 0; i < names.length; i++) {
- const name = names[i];
- if (!checkedMap[name] && matchNode(editor, node, name, vars)) {
- checkedMap[name] = true;
- matchedFormatNames.push(name);
- }
- }
- }, editor.dom.getRoot());
- return matchedFormatNames;
- };
- const closest$1 = (editor, names) => {
- const isRoot = elm => eq(elm, SugarElement.fromDom(editor.getBody()));
- const match = (elm, name) => matchNode(editor, elm.dom, name) ? Optional.some(name) : Optional.none();
- return Optional.from(editor.selection.getStart(true)).bind(rawElm => closest$2(SugarElement.fromDom(rawElm), elm => findMap(names, name => match(elm, name)), isRoot)).getOrNull();
- };
- const canApply = (editor, name) => {
- const formatList = editor.formatter.get(name);
- const dom = editor.dom;
- if (formatList) {
- const startNode = editor.selection.getStart();
- const parents = getParents$2(dom, startNode);
- for (let x = formatList.length - 1; x >= 0; x--) {
- const format = formatList[x];
- if (!isSelectorFormat(format)) {
- return true;
- }
- for (let i = parents.length - 1; i >= 0; i--) {
- if (dom.is(parents[i], format.selector)) {
- return true;
- }
- }
- }
- }
- return false;
- };
- const matchAllOnNode = (editor, node, formatNames) => foldl(formatNames, (acc, name) => {
- const matchSimilar = isVariableFormatName(editor, name);
- if (editor.formatter.matchNode(node, name, {}, matchSimilar)) {
- return acc.concat([name]);
- } else {
- return acc;
- }
- }, []);
- const ZWSP = ZWSP$1, CARET_ID = '_mce_caret';
- const importNode = (ownerDocument, node) => {
- return ownerDocument.importNode(node, true);
- };
- const getEmptyCaretContainers = node => {
- const nodes = [];
- while (node) {
- if (node.nodeType === 3 && node.nodeValue !== ZWSP || node.childNodes.length > 1) {
- return [];
- }
- if (node.nodeType === 1) {
- nodes.push(node);
- }
- node = node.firstChild;
- }
- return nodes;
- };
- const isCaretContainerEmpty = node => {
- return getEmptyCaretContainers(node).length > 0;
- };
- const findFirstTextNode = node => {
- if (node) {
- const walker = new DomTreeWalker(node, node);
- for (node = walker.current(); node; node = walker.next()) {
- if (isText$9(node)) {
- return node;
- }
- }
- }
- return null;
- };
- const createCaretContainer = fill => {
- const caretContainer = SugarElement.fromTag('span');
- setAll$1(caretContainer, {
- 'id': CARET_ID,
- 'data-mce-bogus': '1',
- 'data-mce-type': 'format-caret'
- });
- if (fill) {
- append$1(caretContainer, SugarElement.fromText(ZWSP));
- }
- return caretContainer;
- };
- const trimZwspFromCaretContainer = caretContainerNode => {
- const textNode = findFirstTextNode(caretContainerNode);
- if (textNode && textNode.nodeValue.charAt(0) === ZWSP) {
- textNode.deleteData(0, 1);
- }
- return textNode;
- };
- const removeCaretContainerNode = (editor, node, moveCaret = true) => {
- const dom = editor.dom, selection = editor.selection;
- if (isCaretContainerEmpty(node)) {
- deleteElement$2(editor, false, SugarElement.fromDom(node), moveCaret);
- } else {
- const rng = selection.getRng();
- const block = dom.getParent(node, dom.isBlock);
- const startContainer = rng.startContainer;
- const startOffset = rng.startOffset;
- const endContainer = rng.endContainer;
- const endOffset = rng.endOffset;
- const textNode = trimZwspFromCaretContainer(node);
- dom.remove(node, true);
- if (startContainer === textNode && startOffset > 0) {
- rng.setStart(textNode, startOffset - 1);
- }
- if (endContainer === textNode && endOffset > 0) {
- rng.setEnd(textNode, endOffset - 1);
- }
- if (block && dom.isEmpty(block)) {
- fillWithPaddingBr(SugarElement.fromDom(block));
- }
- selection.setRng(rng);
- }
- };
- const removeCaretContainer = (editor, node, moveCaret = true) => {
- const dom = editor.dom, selection = editor.selection;
- if (!node) {
- node = getParentCaretContainer(editor.getBody(), selection.getStart());
- if (!node) {
- while (node = dom.get(CARET_ID)) {
- removeCaretContainerNode(editor, node, false);
- }
- }
- } else {
- removeCaretContainerNode(editor, node, moveCaret);
- }
- };
- const insertCaretContainerNode = (editor, caretContainer, formatNode) => {
- const dom = editor.dom, block = dom.getParent(formatNode, curry(isTextBlock$1, editor));
- if (block && dom.isEmpty(block)) {
- formatNode.parentNode.replaceChild(caretContainer, formatNode);
- } else {
- removeTrailingBr(SugarElement.fromDom(formatNode));
- if (dom.isEmpty(formatNode)) {
- formatNode.parentNode.replaceChild(caretContainer, formatNode);
- } else {
- dom.insertAfter(caretContainer, formatNode);
- }
- }
- };
- const appendNode = (parentNode, node) => {
- parentNode.appendChild(node);
- return node;
- };
- const insertFormatNodesIntoCaretContainer = (formatNodes, caretContainer) => {
- const innerMostFormatNode = foldr(formatNodes, (parentNode, formatNode) => {
- return appendNode(parentNode, formatNode.cloneNode(false));
- }, caretContainer);
- return appendNode(innerMostFormatNode, innerMostFormatNode.ownerDocument.createTextNode(ZWSP));
- };
- const cleanFormatNode = (editor, caretContainer, formatNode, name, vars, similar) => {
- const formatter = editor.formatter;
- const dom = editor.dom;
- const validFormats = filter$6(keys(formatter.get()), formatName => formatName !== name && !contains$1(formatName, 'removeformat'));
- const matchedFormats = matchAllOnNode(editor, formatNode, validFormats);
- const uniqueFormats = filter$6(matchedFormats, fmtName => !areSimilarFormats(editor, fmtName, name));
- if (uniqueFormats.length > 0) {
- const clonedFormatNode = formatNode.cloneNode(false);
- dom.add(caretContainer, clonedFormatNode);
- formatter.remove(name, vars, clonedFormatNode, similar);
- dom.remove(clonedFormatNode);
- return Optional.some(clonedFormatNode);
- } else {
- return Optional.none();
- }
- };
- const applyCaretFormat = (editor, name, vars) => {
- let caretContainer, textNode;
- const selection = editor.selection;
- const selectionRng = selection.getRng();
- let offset = selectionRng.startOffset;
- const container = selectionRng.startContainer;
- const text = container.nodeValue;
- caretContainer = getParentCaretContainer(editor.getBody(), selection.getStart());
- if (caretContainer) {
- textNode = findFirstTextNode(caretContainer);
- }
- const wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/;
- if (text && offset > 0 && offset < text.length && wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) {
- const bookmark = selection.getBookmark();
- selectionRng.collapse(true);
- let rng = expandRng(editor, selectionRng, editor.formatter.get(name));
- rng = split(rng);
- editor.formatter.apply(name, vars, rng);
- selection.moveToBookmark(bookmark);
- } else {
- if (!caretContainer || textNode.nodeValue !== ZWSP) {
- caretContainer = importNode(editor.getDoc(), createCaretContainer(true).dom);
- textNode = caretContainer.firstChild;
- selectionRng.insertNode(caretContainer);
- offset = 1;
- editor.formatter.apply(name, vars, caretContainer);
- } else {
- editor.formatter.apply(name, vars, caretContainer);
- }
- selection.setCursorLocation(textNode, offset);
- }
- };
- const removeCaretFormat = (editor, name, vars, similar) => {
- const dom = editor.dom;
- const selection = editor.selection;
- let hasContentAfter, node, formatNode;
- const parents = [];
- const rng = selection.getRng();
- const container = rng.startContainer;
- const offset = rng.startOffset;
- node = container;
- if (container.nodeType === 3) {
- if (offset !== container.nodeValue.length) {
- hasContentAfter = true;
- }
- node = node.parentNode;
- }
- while (node) {
- if (matchNode(editor, node, name, vars, similar)) {
- formatNode = node;
- break;
- }
- if (node.nextSibling) {
- hasContentAfter = true;
- }
- parents.push(node);
- node = node.parentNode;
- }
- if (!formatNode) {
- return;
- }
- if (hasContentAfter) {
- const bookmark = selection.getBookmark();
- rng.collapse(true);
- let expandedRng = expandRng(editor, rng, editor.formatter.get(name), true);
- expandedRng = split(expandedRng);
- editor.formatter.remove(name, vars, expandedRng, similar);
- selection.moveToBookmark(bookmark);
- } else {
- const caretContainer = getParentCaretContainer(editor.getBody(), formatNode);
- const newCaretContainer = createCaretContainer(false).dom;
- insertCaretContainerNode(editor, newCaretContainer, caretContainer !== null ? caretContainer : formatNode);
- const cleanedFormatNode = cleanFormatNode(editor, newCaretContainer, formatNode, name, vars, similar);
- const caretTextNode = insertFormatNodesIntoCaretContainer(parents.concat(cleanedFormatNode.toArray()), newCaretContainer);
- removeCaretContainerNode(editor, caretContainer, false);
- selection.setCursorLocation(caretTextNode, 1);
- if (dom.isEmpty(formatNode)) {
- dom.remove(formatNode);
- }
- }
- };
- const disableCaretContainer = (editor, keyCode) => {
- const selection = editor.selection, body = editor.getBody();
- removeCaretContainer(editor, null, false);
- if ((keyCode === 8 || keyCode === 46) && selection.isCollapsed() && selection.getStart().innerHTML === ZWSP) {
- removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
- }
- if (keyCode === 37 || keyCode === 39) {
- removeCaretContainer(editor, getParentCaretContainer(body, selection.getStart()));
- }
- };
- const setup$u = editor => {
- editor.on('mouseup keydown', e => {
- disableCaretContainer(editor, e.keyCode);
- });
- };
- const replaceWithCaretFormat = (targetNode, formatNodes) => {
- const caretContainer = createCaretContainer(false);
- const innerMost = insertFormatNodesIntoCaretContainer(formatNodes, caretContainer.dom);
- before$3(SugarElement.fromDom(targetNode), caretContainer);
- remove$6(SugarElement.fromDom(targetNode));
- return CaretPosition(innerMost, 0);
- };
- const isFormatElement = (editor, element) => {
- const inlineElements = editor.schema.getTextInlineElements();
- return has$2(inlineElements, name(element)) && !isCaretNode(element.dom) && !isBogus$2(element.dom);
- };
- const isEmptyCaretFormatElement = element => {
- return isCaretNode(element.dom) && isCaretContainerEmpty(element.dom);
- };
- const postProcessHooks = {};
- const filter$2 = filter$4;
- const each$9 = each$d;
- const addPostProcessHook = (name, hook) => {
- const hooks = postProcessHooks[name];
- if (!hooks) {
- postProcessHooks[name] = [];
- }
- postProcessHooks[name].push(hook);
- };
- const postProcess$1 = (name, editor) => {
- each$9(postProcessHooks[name], hook => {
- hook(editor);
- });
- };
- addPostProcessHook('pre', editor => {
- const rng = editor.selection.getRng();
- let blocks;
- const hasPreSibling = pre => {
- return isPre(pre.previousSibling) && indexOf(blocks, pre.previousSibling) !== -1;
- };
- const joinPre = (pre1, pre2) => {
- const sPre2 = SugarElement.fromDom(pre2);
- const doc = documentOrOwner(sPre2).dom;
- remove$6(sPre2);
- append(SugarElement.fromDom(pre1), [
- SugarElement.fromTag('br', doc),
- SugarElement.fromTag('br', doc),
- ...children(sPre2)
- ]);
- };
- const isPre = matchNodeNames(['pre']);
- if (!rng.collapsed) {
- blocks = editor.selection.getSelectedBlocks();
- each$9(filter$2(filter$2(blocks, isPre), hasPreSibling), pre => {
- joinPre(pre.previousSibling, pre);
- });
- }
- });
- const each$8 = Tools.each;
- const isElementNode$1 = node => isElement$6(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$2(node);
- const findElementSibling = (node, siblingName) => {
- for (let sibling = node; sibling; sibling = sibling[siblingName]) {
- if (isText$9(sibling) && isNotEmpty(sibling.data)) {
- return node;
- }
- if (isElement$6(sibling) && !isBookmarkNode$1(sibling)) {
- return sibling;
- }
- }
- return node;
- };
- const mergeSiblingsNodes = (dom, prev, next) => {
- const elementUtils = ElementUtils(dom);
- if (prev && next) {
- prev = findElementSibling(prev, 'previousSibling');
- next = findElementSibling(next, 'nextSibling');
- if (elementUtils.compare(prev, next)) {
- for (let sibling = prev.nextSibling; sibling && sibling !== next;) {
- const tmpSibling = sibling;
- sibling = sibling.nextSibling;
- prev.appendChild(tmpSibling);
- }
- dom.remove(next);
- Tools.each(Tools.grep(next.childNodes), node => {
- prev.appendChild(node);
- });
- return prev;
- }
- }
- return next;
- };
- const mergeSiblings = (dom, format, vars, node) => {
- if (node && format.merge_siblings !== false) {
- const newNode = mergeSiblingsNodes(dom, getNonWhiteSpaceSibling(node), node);
- mergeSiblingsNodes(dom, newNode, getNonWhiteSpaceSibling(newNode, true));
- }
- };
- const clearChildStyles = (dom, format, node) => {
- if (format.clear_child_styles) {
- const selector = format.links ? '*:not(a)' : '*';
- each$8(dom.select(selector, node), node => {
- if (isElementNode$1(node)) {
- each$8(format.styles, (value, name) => {
- dom.setStyle(node, name, '');
- });
- }
- });
- }
- };
- const processChildElements = (node, filter, process) => {
- each$8(node.childNodes, node => {
- if (isElementNode$1(node)) {
- if (filter(node)) {
- process(node);
- }
- if (node.hasChildNodes()) {
- processChildElements(node, filter, process);
- }
- }
- });
- };
- const unwrapEmptySpan = (dom, node) => {
- if (node.nodeName === 'SPAN' && dom.getAttribs(node).length === 0) {
- dom.remove(node, true);
- }
- };
- const hasStyle = (dom, name) => node => !!(node && getStyle(dom, node, name));
- const applyStyle = (dom, name, value) => node => {
- dom.setStyle(node, name, value);
- if (node.getAttribute('style') === '') {
- node.removeAttribute('style');
- }
- unwrapEmptySpan(dom, node);
- };
- const removeResult = Adt.generate([
- { keep: [] },
- { rename: ['name'] },
- { removed: [] }
- ]);
- const MCE_ATTR_RE = /^(src|href|style)$/;
- const each$7 = Tools.each;
- const isEq$2 = isEq$5;
- const isTableCellOrRow = node => /^(TR|TH|TD)$/.test(node.nodeName);
- const isChildOfInlineParent = (dom, node, parent) => dom.isChildOf(node, parent) && node !== parent && !dom.isBlock(parent);
- const getContainer = (ed, rng, start) => {
- let container = rng[start ? 'startContainer' : 'endContainer'];
- let offset = rng[start ? 'startOffset' : 'endOffset'];
- if (isElement$6(container)) {
- const lastIdx = container.childNodes.length - 1;
- if (!start && offset) {
- offset--;
- }
- container = container.childNodes[offset > lastIdx ? lastIdx : offset];
- }
- if (isText$9(container) && start && offset >= container.nodeValue.length) {
- container = new DomTreeWalker(container, ed.getBody()).next() || container;
- }
- if (isText$9(container) && !start && offset === 0) {
- container = new DomTreeWalker(container, ed.getBody()).prev() || container;
- }
- return container;
- };
- const normalizeTableSelection = (node, start) => {
- const prop = start ? 'firstChild' : 'lastChild';
- if (isTableCellOrRow(node) && node[prop]) {
- const childNode = node[prop];
- if (node.nodeName === 'TR') {
- return childNode[prop] || childNode;
- } else {
- return childNode;
- }
- }
- return node;
- };
- const wrap$1 = (dom, node, name, attrs) => {
- const wrapper = dom.create(name, attrs);
- node.parentNode.insertBefore(wrapper, node);
- wrapper.appendChild(node);
- return wrapper;
- };
- const wrapWithSiblings = (dom, node, next, name, attrs) => {
- const start = SugarElement.fromDom(node);
- const wrapper = SugarElement.fromDom(dom.create(name, attrs));
- const siblings = next ? nextSiblings(start) : prevSiblings(start);
- append(wrapper, siblings);
- if (next) {
- before$3(start, wrapper);
- prepend(wrapper, start);
- } else {
- after$4(start, wrapper);
- append$1(wrapper, start);
- }
- return wrapper.dom;
- };
- const isColorFormatAndAnchor = (node, format) => format.links && node.nodeName === 'A';
- const removeNode = (ed, node, format) => {
- const parentNode = node.parentNode;
- let rootBlockElm;
- const dom = ed.dom;
- const forcedRootBlock = getForcedRootBlock(ed);
- if (isBlockFormat(format)) {
- if (parentNode === dom.getRoot()) {
- if (!format.list_block || !isEq$2(node, format.list_block)) {
- each$f(from(node.childNodes), node => {
- if (isValid(ed, forcedRootBlock, node.nodeName.toLowerCase())) {
- if (!rootBlockElm) {
- rootBlockElm = wrap$1(dom, node, forcedRootBlock);
- dom.setAttribs(rootBlockElm, getForcedRootBlockAttrs(ed));
- } else {
- rootBlockElm.appendChild(node);
- }
- } else {
- rootBlockElm = null;
- }
- });
- }
- }
- }
- if (isMixedFormat(format) && !isEq$2(format.inline, node)) {
- return;
- }
- dom.remove(node, true);
- };
- const removeFormatInternal = (ed, format, vars, node, compareNode) => {
- let stylesModified;
- const dom = ed.dom;
- if (!matchName(dom, node, format) && !isColorFormatAndAnchor(node, format)) {
- return removeResult.keep();
- }
- const elm = node;
- if (isInlineFormat(format) && format.remove === 'all' && isArray$1(format.preserve_attributes)) {
- const attrsToPreserve = filter$6(dom.getAttribs(elm), attr => contains$2(format.preserve_attributes, attr.name.toLowerCase()));
- dom.removeAllAttribs(elm);
- each$f(attrsToPreserve, attr => dom.setAttrib(elm, attr.name, attr.value));
- if (attrsToPreserve.length > 0) {
- return removeResult.rename('span');
- }
- }
- if (format.remove !== 'all') {
- each$7(format.styles, (value, name) => {
- value = normalizeStyleValue(replaceVars(value, vars), name + '');
- if (isNumber(name)) {
- name = value;
- compareNode = null;
- }
- if (format.remove_similar || (!compareNode || isEq$2(getStyle(dom, compareNode, name), value))) {
- dom.setStyle(elm, name, '');
- }
- stylesModified = true;
- });
- if (stylesModified && dom.getAttrib(elm, 'style') === '') {
- elm.removeAttribute('style');
- elm.removeAttribute('data-mce-style');
- }
- each$7(format.attributes, (value, name) => {
- let valueOut;
- value = replaceVars(value, vars);
- if (isNumber(name)) {
- name = value;
- compareNode = null;
- }
- if (format.remove_similar || (!compareNode || isEq$2(dom.getAttrib(compareNode, name), value))) {
- if (name === 'class') {
- value = dom.getAttrib(elm, name);
- if (value) {
- valueOut = '';
- each$f(value.split(/\s+/), cls => {
- if (/mce\-\w+/.test(cls)) {
- valueOut += (valueOut ? ' ' : '') + cls;
- }
- });
- if (valueOut) {
- dom.setAttrib(elm, name, valueOut);
- return;
- }
- }
- }
- if (MCE_ATTR_RE.test(name)) {
- elm.removeAttribute('data-mce-' + name);
- }
- if (name === 'style' && matchNodeNames(['li'])(elm) && dom.getStyle(elm, 'list-style-type') === 'none') {
- elm.removeAttribute(name);
- dom.setStyle(elm, 'list-style-type', 'none');
- return;
- }
- if (name === 'class') {
- elm.removeAttribute('className');
- }
- elm.removeAttribute(name);
- }
- });
- each$7(format.classes, value => {
- value = replaceVars(value, vars);
- if (!compareNode || dom.hasClass(compareNode, value)) {
- dom.removeClass(elm, value);
- }
- });
- const attrs = dom.getAttribs(elm);
- for (let i = 0; i < attrs.length; i++) {
- const attrName = attrs[i].nodeName;
- if (attrName.indexOf('_') !== 0 && attrName.indexOf('data-') !== 0) {
- return removeResult.keep();
- }
- }
- }
- if (format.remove !== 'none') {
- removeNode(ed, elm, format);
- return removeResult.removed();
- }
- return removeResult.keep();
- };
- const removeFormat$1 = (ed, format, vars, node, compareNode) => removeFormatInternal(ed, format, vars, node, compareNode).fold(never, newName => {
- ed.dom.rename(node, newName);
- return true;
- }, always);
- const findFormatRoot = (editor, container, name, vars, similar) => {
- let formatRoot;
- each$f(getParents$2(editor.dom, container.parentNode).reverse(), parent => {
- if (!formatRoot && parent.id !== '_start' && parent.id !== '_end') {
- const format = matchNode(editor, parent, name, vars, similar);
- if (format && format.split !== false) {
- formatRoot = parent;
- }
- }
- });
- return formatRoot;
- };
- const removeFormatFromClone = (editor, format, vars, clone) => removeFormatInternal(editor, format, vars, clone, clone).fold(constant(clone), newName => {
- const fragment = editor.dom.createFragment();
- fragment.appendChild(clone);
- return editor.dom.rename(clone, newName);
- }, constant(null));
- const wrapAndSplit = (editor, formatList, formatRoot, container, target, split, format, vars) => {
- let clone, lastClone, firstClone;
- const dom = editor.dom;
- if (formatRoot) {
- const formatRootParent = formatRoot.parentNode;
- for (let parent = container.parentNode; parent && parent !== formatRootParent; parent = parent.parentNode) {
- clone = dom.clone(parent, false);
- for (let i = 0; i < formatList.length; i++) {
- clone = removeFormatFromClone(editor, formatList[i], vars, clone);
- if (clone === null) {
- break;
- }
- }
- if (clone) {
- if (lastClone) {
- clone.appendChild(lastClone);
- }
- if (!firstClone) {
- firstClone = clone;
- }
- lastClone = clone;
- }
- }
- if (split && (!format.mixed || !dom.isBlock(formatRoot))) {
- container = dom.split(formatRoot, container);
- }
- if (lastClone) {
- target.parentNode.insertBefore(lastClone, target);
- firstClone.appendChild(target);
- if (isInlineFormat(format)) {
- mergeSiblings(dom, format, vars, lastClone);
- }
- }
- }
- return container;
- };
- const remove$2 = (ed, name, vars, node, similar) => {
- const formatList = ed.formatter.get(name);
- const format = formatList[0];
- let contentEditable = true;
- const dom = ed.dom;
- const selection = ed.selection;
- const splitToFormatRoot = container => {
- const formatRoot = findFormatRoot(ed, container, name, vars, similar);
- return wrapAndSplit(ed, formatList, formatRoot, container, container, true, format, vars);
- };
- const isRemoveBookmarkNode = node => isBookmarkNode$1(node) && isElement$6(node) && (node.id === '_start' || node.id === '_end');
- const removeNodeFormat = node => exists(formatList, fmt => removeFormat$1(ed, fmt, vars, node, node));
- const process = node => {
- let lastContentEditable = true;
- let hasContentEditableState = false;
- if (isElement$6(node) && dom.getContentEditable(node)) {
- lastContentEditable = contentEditable;
- contentEditable = dom.getContentEditable(node) === 'true';
- hasContentEditableState = true;
- }
- const children = from(node.childNodes);
- if (contentEditable && !hasContentEditableState) {
- const removed = removeNodeFormat(node);
- const currentNodeMatches = removed || exists(formatList, f => matchName(dom, node, f));
- const parentNode = node.parentNode;
- if (!currentNodeMatches && isNonNullable(parentNode) && shouldExpandToSelector(format)) {
- removeNodeFormat(parentNode);
- }
- }
- if (format.deep) {
- if (children.length) {
- for (let i = 0; i < children.length; i++) {
- process(children[i]);
- }
- if (hasContentEditableState) {
- contentEditable = lastContentEditable;
- }
- }
- }
- const textDecorations = [
- 'underline',
- 'line-through',
- 'overline'
- ];
- each$f(textDecorations, decoration => {
- if (isElement$6(node) && ed.dom.getStyle(node, 'text-decoration') === decoration && node.parentNode && getTextDecoration(dom, node.parentNode) === decoration) {
- removeFormat$1(ed, {
- deep: false,
- exact: true,
- inline: 'span',
- styles: { textDecoration: decoration }
- }, null, node);
- }
- });
- };
- const unwrap = start => {
- const node = dom.get(start ? '_start' : '_end');
- let out = node[start ? 'firstChild' : 'lastChild'];
- if (isRemoveBookmarkNode(out)) {
- out = out[start ? 'firstChild' : 'lastChild'];
- }
- if (isText$9(out) && out.data.length === 0) {
- out = start ? node.previousSibling || node.nextSibling : node.nextSibling || node.previousSibling;
- }
- dom.remove(node, true);
- return out;
- };
- const removeRngStyle = rng => {
- let startContainer, endContainer;
- let expandedRng = expandRng(ed, rng, formatList, rng.collapsed);
- if (format.split) {
- expandedRng = split(expandedRng);
- startContainer = getContainer(ed, expandedRng, true);
- endContainer = getContainer(ed, expandedRng);
- if (startContainer !== endContainer) {
- startContainer = normalizeTableSelection(startContainer, true);
- endContainer = normalizeTableSelection(endContainer, false);
- if (isChildOfInlineParent(dom, startContainer, endContainer)) {
- const marker = Optional.from(startContainer.firstChild).getOr(startContainer);
- splitToFormatRoot(wrapWithSiblings(dom, marker, true, 'span', {
- 'id': '_start',
- 'data-mce-type': 'bookmark'
- }));
- unwrap(true);
- return;
- }
- if (isChildOfInlineParent(dom, endContainer, startContainer)) {
- const marker = Optional.from(endContainer.lastChild).getOr(endContainer);
- splitToFormatRoot(wrapWithSiblings(dom, marker, false, 'span', {
- 'id': '_end',
- 'data-mce-type': 'bookmark'
- }));
- unwrap(false);
- return;
- }
- startContainer = wrap$1(dom, startContainer, 'span', {
- 'id': '_start',
- 'data-mce-type': 'bookmark'
- });
- endContainer = wrap$1(dom, endContainer, 'span', {
- 'id': '_end',
- 'data-mce-type': 'bookmark'
- });
- const newRng = dom.createRng();
- newRng.setStartAfter(startContainer);
- newRng.setEndBefore(endContainer);
- walk$3(dom, newRng, nodes => {
- each$f(nodes, n => {
- if (!isBookmarkNode$1(n) && !isBookmarkNode$1(n.parentNode)) {
- splitToFormatRoot(n);
- }
- });
- });
- splitToFormatRoot(startContainer);
- splitToFormatRoot(endContainer);
- startContainer = unwrap(true);
- endContainer = unwrap();
- } else {
- startContainer = endContainer = splitToFormatRoot(startContainer);
- }
- expandedRng.startContainer = startContainer.parentNode ? startContainer.parentNode : startContainer;
- expandedRng.startOffset = dom.nodeIndex(startContainer);
- expandedRng.endContainer = endContainer.parentNode ? endContainer.parentNode : endContainer;
- expandedRng.endOffset = dom.nodeIndex(endContainer) + 1;
- }
- walk$3(dom, expandedRng, nodes => {
- each$f(nodes, process);
- });
- };
- if (node) {
- if (isNode(node)) {
- const rng = dom.createRng();
- rng.setStartBefore(node);
- rng.setEndAfter(node);
- removeRngStyle(rng);
- } else {
- removeRngStyle(node);
- }
- fireFormatRemove(ed, name, node, vars);
- return;
- }
- if (dom.getContentEditable(selection.getNode()) === 'false') {
- node = selection.getNode();
- for (let i = 0; i < formatList.length; i++) {
- if (formatList[i].ceFalseOverride) {
- if (removeFormat$1(ed, formatList[i], vars, node, node)) {
- break;
- }
- }
- }
- fireFormatRemove(ed, name, node, vars);
- return;
- }
- if (!selection.isCollapsed() || !isInlineFormat(format) || getCellsFromEditor(ed).length) {
- preserve(selection, true, () => {
- runOnRanges(ed, removeRngStyle);
- });
- if (isInlineFormat(format) && match$2(ed, name, vars, selection.getStart())) {
- moveStart(dom, selection, selection.getRng());
- }
- ed.nodeChanged();
- } else {
- removeCaretFormat(ed, name, vars, similar);
- }
- fireFormatRemove(ed, name, node, vars);
- };
- const each$6 = Tools.each;
- const mergeTextDecorationsAndColor = (dom, format, vars, node) => {
- const processTextDecorationsAndColor = n => {
- if (n.nodeType === 1 && n.parentNode && n.parentNode.nodeType === 1) {
- const textDecoration = getTextDecoration(dom, n.parentNode);
- if (dom.getStyle(n, 'color') && textDecoration) {
- dom.setStyle(n, 'text-decoration', textDecoration);
- } else if (dom.getStyle(n, 'text-decoration') === textDecoration) {
- dom.setStyle(n, 'text-decoration', null);
- }
- }
- };
- if (format.styles && (format.styles.color || format.styles.textDecoration)) {
- Tools.walk(node, processTextDecorationsAndColor, 'childNodes');
- processTextDecorationsAndColor(node);
- }
- };
- const mergeBackgroundColorAndFontSize = (dom, format, vars, node) => {
- if (format.styles && format.styles.backgroundColor) {
- processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'backgroundColor', replaceVars(format.styles.backgroundColor, vars)));
- }
- };
- const mergeSubSup = (dom, format, vars, node) => {
- if (isInlineFormat(format) && (format.inline === 'sub' || format.inline === 'sup')) {
- processChildElements(node, hasStyle(dom, 'fontSize'), applyStyle(dom, 'fontSize', ''));
- dom.remove(dom.select(format.inline === 'sup' ? 'sub' : 'sup', node), true);
- }
- };
- const mergeWithChildren = (editor, formatList, vars, node) => {
- each$6(formatList, format => {
- if (isInlineFormat(format)) {
- each$6(editor.dom.select(format.inline, node), child => {
- if (!isElementNode$1(child)) {
- return;
- }
- removeFormat$1(editor, format, vars, child, format.exact ? child : null);
- });
- }
- clearChildStyles(editor.dom, format, node);
- });
- };
- const mergeWithParents = (editor, format, name, vars, node) => {
- if (matchNode(editor, node.parentNode, name, vars)) {
- if (removeFormat$1(editor, format, vars, node)) {
- return;
- }
- }
- if (format.merge_with_parents) {
- editor.dom.getParent(node.parentNode, parent => {
- if (matchNode(editor, parent, name, vars)) {
- removeFormat$1(editor, format, vars, node);
- return true;
- }
- });
- }
- };
- const each$5 = Tools.each;
- const isElementNode = node => {
- return isElement$6(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$2(node);
- };
- const canFormatBR = (editor, format, node, parentName) => {
- if (canFormatEmptyLines(editor) && isInlineFormat(format)) {
- const validBRParentElements = getTextRootBlockElements(editor.schema);
- const hasCaretNodeSibling = sibling(SugarElement.fromDom(node), sibling => isCaretNode(sibling.dom));
- return hasNonNullableKey(validBRParentElements, parentName) && isEmpty$2(SugarElement.fromDom(node.parentNode), false) && !hasCaretNodeSibling;
- } else {
- return false;
- }
- };
- const applyFormat$1 = (ed, name, vars, node) => {
- const formatList = ed.formatter.get(name);
- const format = formatList[0];
- const isCollapsed = !node && ed.selection.isCollapsed();
- const dom = ed.dom;
- const selection = ed.selection;
- const setElementFormat = (elm, fmt = format) => {
- if (isFunction(fmt.onformat)) {
- fmt.onformat(elm, fmt, vars, node);
- }
- each$5(fmt.styles, (value, name) => {
- dom.setStyle(elm, name, replaceVars(value, vars));
- });
- if (fmt.styles) {
- const styleVal = dom.getAttrib(elm, 'style');
- if (styleVal) {
- dom.setAttrib(elm, 'data-mce-style', styleVal);
- }
- }
- each$5(fmt.attributes, (value, name) => {
- dom.setAttrib(elm, name, replaceVars(value, vars));
- });
- each$5(fmt.classes, value => {
- value = replaceVars(value, vars);
- if (!dom.hasClass(elm, value)) {
- dom.addClass(elm, value);
- }
- });
- };
- const applyNodeStyle = (formatList, node) => {
- let found = false;
- each$5(formatList, format => {
- if (!isSelectorFormat(format)) {
- return false;
- }
- if (isNonNullable(format.collapsed) && format.collapsed !== isCollapsed) {
- return;
- }
- if (dom.is(node, format.selector) && !isCaretNode(node)) {
- setElementFormat(node, format);
- found = true;
- return false;
- }
- });
- return found;
- };
- const createWrapElement = wrapName => {
- if (isString(wrapName)) {
- const wrapElm = dom.create(wrapName);
- setElementFormat(wrapElm);
- return wrapElm;
- } else {
- return null;
- }
- };
- const applyRngStyle = (dom, rng, nodeSpecific) => {
- const newWrappers = [];
- let contentEditable = true;
- const wrapName = format.inline || format.block;
- const wrapElm = createWrapElement(wrapName);
- walk$3(dom, rng, nodes => {
- let currentWrapElm;
- const process = node => {
- let hasContentEditableState = false;
- let lastContentEditable = contentEditable;
- const nodeName = node.nodeName.toLowerCase();
- const parentNode = node.parentNode;
- const parentName = parentNode.nodeName.toLowerCase();
- if (isElement$6(node) && dom.getContentEditable(node)) {
- lastContentEditable = contentEditable;
- contentEditable = dom.getContentEditable(node) === 'true';
- hasContentEditableState = true;
- }
- if (isBr$6(node) && !canFormatBR(ed, format, node, parentName)) {
- currentWrapElm = null;
- if (isBlockFormat(format)) {
- dom.remove(node);
- }
- return;
- }
- if (isBlockFormat(format) && format.wrapper && matchNode(ed, node, name, vars)) {
- currentWrapElm = null;
- return;
- }
- if (contentEditable && !hasContentEditableState && isBlockFormat(format) && !format.wrapper && isTextBlock$1(ed, nodeName) && isValid(ed, parentName, wrapName)) {
- const elm = dom.rename(node, wrapName);
- setElementFormat(elm);
- newWrappers.push(elm);
- currentWrapElm = null;
- return;
- }
- if (isSelectorFormat(format)) {
- let found = applyNodeStyle(formatList, node);
- if (!found && isNonNullable(parentNode) && shouldExpandToSelector(format)) {
- found = applyNodeStyle(formatList, parentNode);
- }
- if (!isInlineFormat(format) || found) {
- currentWrapElm = null;
- return;
- }
- }
- if (contentEditable && !hasContentEditableState && isValid(ed, wrapName, nodeName) && isValid(ed, parentName, wrapName) && !(!nodeSpecific && isText$9(node) && isZwsp(node.data)) && !isCaretNode(node) && (!isInlineFormat(format) || !dom.isBlock(node))) {
- if (!currentWrapElm) {
- currentWrapElm = dom.clone(wrapElm, false);
- node.parentNode.insertBefore(currentWrapElm, node);
- newWrappers.push(currentWrapElm);
- }
- currentWrapElm.appendChild(node);
- } else {
- currentWrapElm = null;
- each$f(from(node.childNodes), process);
- if (hasContentEditableState) {
- contentEditable = lastContentEditable;
- }
- currentWrapElm = null;
- }
- };
- each$f(nodes, process);
- });
- if (format.links === true) {
- each$f(newWrappers, node => {
- const process = node => {
- if (node.nodeName === 'A') {
- setElementFormat(node, format);
- }
- each$f(from(node.childNodes), process);
- };
- process(node);
- });
- }
- each$f(newWrappers, node => {
- const getChildCount = node => {
- let count = 0;
- each$f(node.childNodes, node => {
- if (!isEmptyTextNode$1(node) && !isBookmarkNode$1(node)) {
- count++;
- }
- });
- return count;
- };
- const mergeStyles = node => {
- const childElement = find$2(node.childNodes, isElementNode).filter(child => matchName(dom, child, format));
- return childElement.map(child => {
- const clone = dom.clone(child, false);
- setElementFormat(clone);
- dom.replace(clone, node, true);
- dom.remove(child, true);
- return clone;
- }).getOr(node);
- };
- const childCount = getChildCount(node);
- if ((newWrappers.length > 1 || !dom.isBlock(node)) && childCount === 0) {
- dom.remove(node, true);
- return;
- }
- if (isInlineFormat(format) || isBlockFormat(format) && format.wrapper) {
- if (!format.exact && childCount === 1) {
- node = mergeStyles(node);
- }
- mergeWithChildren(ed, formatList, vars, node);
- mergeWithParents(ed, format, name, vars, node);
- mergeBackgroundColorAndFontSize(dom, format, vars, node);
- mergeTextDecorationsAndColor(dom, format, vars, node);
- mergeSubSup(dom, format, vars, node);
- mergeSiblings(dom, format, vars, node);
- }
- });
- };
- if (dom.getContentEditable(selection.getNode()) === 'false') {
- node = selection.getNode();
- for (let i = 0, l = formatList.length; i < l; i++) {
- const formatItem = formatList[i];
- if (formatItem.ceFalseOverride && isSelectorFormat(formatItem) && dom.is(node, formatItem.selector)) {
- setElementFormat(node, formatItem);
- break;
- }
- }
- fireFormatApply(ed, name, node, vars);
- return;
- }
- if (format) {
- if (node) {
- if (isNode(node)) {
- if (!applyNodeStyle(formatList, node)) {
- const rng = dom.createRng();
- rng.setStartBefore(node);
- rng.setEndAfter(node);
- applyRngStyle(dom, expandRng(ed, rng, formatList), true);
- }
- } else {
- applyRngStyle(dom, node, true);
- }
- } else {
- if (!isCollapsed || !isInlineFormat(format) || getCellsFromEditor(ed).length) {
- selection.setRng(normalize(selection.getRng()));
- preserve(selection, true, () => {
- runOnRanges(ed, (selectionRng, fake) => {
- const expandedRng = fake ? selectionRng : expandRng(ed, selectionRng, formatList);
- applyRngStyle(dom, expandedRng, false);
- });
- });
- moveStart(dom, selection, selection.getRng());
- ed.nodeChanged();
- } else {
- applyCaretFormat(ed, name, vars);
- }
- }
- postProcess$1(name, ed);
- }
- fireFormatApply(ed, name, node, vars);
- };
- const hasVars = value => has$2(value, 'vars');
- const setup$t = (registeredFormatListeners, editor) => {
- registeredFormatListeners.set({});
- editor.on('NodeChange', e => {
- updateAndFireChangeCallbacks(editor, e.element, registeredFormatListeners.get());
- });
- editor.on('FormatApply FormatRemove', e => {
- const element = Optional.from(e.node).map(nodeOrRange => isNode(nodeOrRange) ? nodeOrRange : nodeOrRange.startContainer).bind(node => isElement$6(node) ? Optional.some(node) : Optional.from(node.parentElement)).getOrThunk(() => fallbackElement(editor));
- updateAndFireChangeCallbacks(editor, element, registeredFormatListeners.get());
- });
- };
- const fallbackElement = editor => editor.selection.getStart();
- const matchingNode = (editor, parents, format, similar, vars) => {
- const isMatchingNode = node => {
- const matchingFormat = editor.formatter.matchNode(node, format, vars !== null && vars !== void 0 ? vars : {}, similar);
- return !isUndefined(matchingFormat);
- };
- const isUnableToMatch = node => {
- if (matchesUnInheritedFormatSelector(editor, node, format)) {
- return true;
- } else {
- if (!similar) {
- return isNonNullable(editor.formatter.matchNode(node, format, vars, true));
- } else {
- return false;
- }
- }
- };
- return findUntil$1(parents, isMatchingNode, isUnableToMatch);
- };
- const getParents = (editor, elm) => {
- const element = elm !== null && elm !== void 0 ? elm : fallbackElement(editor);
- return filter$6(getParents$2(editor.dom, element), node => isElement$6(node) && !isBogus$2(node));
- };
- const updateAndFireChangeCallbacks = (editor, elm, registeredCallbacks) => {
- const parents = getParents(editor, elm);
- each$e(registeredCallbacks, (data, format) => {
- const runIfChanged = spec => {
- const match = matchingNode(editor, parents, format, spec.similar, hasVars(spec) ? spec.vars : undefined);
- const isSet = match.isSome();
- if (spec.state.get() !== isSet) {
- spec.state.set(isSet);
- const node = match.getOr(elm);
- if (hasVars(spec)) {
- spec.callback(isSet, {
- node,
- format,
- parents
- });
- } else {
- each$f(spec.callbacks, callback => callback(isSet, {
- node,
- format,
- parents
- }));
- }
- }
- };
- each$f([
- data.withSimilar,
- data.withoutSimilar
- ], runIfChanged);
- each$f(data.withVars, runIfChanged);
- });
- };
- const addListeners = (editor, registeredFormatListeners, formats, callback, similar, vars) => {
- const formatChangeItems = registeredFormatListeners.get();
- each$f(formats.split(','), format => {
- const group = get$a(formatChangeItems, format).getOrThunk(() => {
- const base = {
- withSimilar: {
- state: Cell(false),
- similar: true,
- callbacks: []
- },
- withoutSimilar: {
- state: Cell(false),
- similar: false,
- callbacks: []
- },
- withVars: []
- };
- formatChangeItems[format] = base;
- return base;
- });
- const getCurrent = () => {
- const parents = getParents(editor);
- return matchingNode(editor, parents, format, similar, vars).isSome();
- };
- if (isUndefined(vars)) {
- const toAppendTo = similar ? group.withSimilar : group.withoutSimilar;
- toAppendTo.callbacks.push(callback);
- if (toAppendTo.callbacks.length === 1) {
- toAppendTo.state.set(getCurrent());
- }
- } else {
- group.withVars.push({
- state: Cell(getCurrent()),
- similar,
- vars,
- callback
- });
- }
- });
- registeredFormatListeners.set(formatChangeItems);
- };
- const removeListeners = (registeredFormatListeners, formats, callback) => {
- const formatChangeItems = registeredFormatListeners.get();
- each$f(formats.split(','), format => get$a(formatChangeItems, format).each(group => {
- formatChangeItems[format] = {
- withSimilar: {
- ...group.withSimilar,
- callbacks: filter$6(group.withSimilar.callbacks, cb => cb !== callback)
- },
- withoutSimilar: {
- ...group.withoutSimilar,
- callbacks: filter$6(group.withoutSimilar.callbacks, cb => cb !== callback)
- },
- withVars: filter$6(group.withVars, item => item.callback !== callback)
- };
- }));
- registeredFormatListeners.set(formatChangeItems);
- };
- const formatChangedInternal = (editor, registeredFormatListeners, formats, callback, similar, vars) => {
- if (registeredFormatListeners.get() === null) {
- setup$t(registeredFormatListeners, editor);
- }
- addListeners(editor, registeredFormatListeners, formats, callback, similar, vars);
- return { unbind: () => removeListeners(registeredFormatListeners, formats, callback) };
- };
- const toggle = (editor, name, vars, node) => {
- const fmt = editor.formatter.get(name);
- if (match$2(editor, name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle)) {
- remove$2(editor, name, vars, node);
- } else {
- applyFormat$1(editor, name, vars, node);
- }
- };
- function _typeof(obj) {
- '@babel/helpers - typeof';
- return _typeof = 'function' == typeof Symbol && 'symbol' == typeof Symbol.iterator ? function (obj) {
- return typeof obj;
- } : function (obj) {
- return obj && 'function' == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj;
- }, _typeof(obj);
- }
- function _setPrototypeOf(o, p) {
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
- o.__proto__ = p;
- return o;
- };
- return _setPrototypeOf(o, p);
- }
- function _isNativeReflectConstruct() {
- if (typeof Reflect === 'undefined' || !Reflect.construct)
- return false;
- if (Reflect.construct.sham)
- return false;
- if (typeof Proxy === 'function')
- return true;
- try {
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {
- }));
- return true;
- } catch (e) {
- return false;
- }
- }
- function _construct(Parent, args, Class) {
- if (_isNativeReflectConstruct()) {
- _construct = Reflect.construct;
- } else {
- _construct = function _construct(Parent, args, Class) {
- var a = [null];
- a.push.apply(a, args);
- var Constructor = Function.bind.apply(Parent, a);
- var instance = new Constructor();
- if (Class)
- _setPrototypeOf(instance, Class.prototype);
- return instance;
- };
- }
- return _construct.apply(null, arguments);
- }
- function _toConsumableArray(arr) {
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
- }
- function _arrayWithoutHoles(arr) {
- if (Array.isArray(arr))
- return _arrayLikeToArray(arr);
- }
- function _iterableToArray(iter) {
- if (typeof Symbol !== 'undefined' && iter[Symbol.iterator] != null || iter['@@iterator'] != null)
- return Array.from(iter);
- }
- function _unsupportedIterableToArray(o, minLen) {
- if (!o)
- return;
- if (typeof o === 'string')
- return _arrayLikeToArray(o, minLen);
- var n = Object.prototype.toString.call(o).slice(8, -1);
- if (n === 'Object' && o.constructor)
- n = o.constructor.name;
- if (n === 'Map' || n === 'Set')
- return Array.from(o);
- if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
- return _arrayLikeToArray(o, minLen);
- }
- function _arrayLikeToArray(arr, len) {
- if (len == null || len > arr.length)
- len = arr.length;
- for (var i = 0, arr2 = new Array(len); i < len; i++)
- arr2[i] = arr[i];
- return arr2;
- }
- function _nonIterableSpread() {
- throw new TypeError('Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
- }
- var hasOwnProperty = Object.hasOwnProperty, setPrototypeOf = Object.setPrototypeOf, isFrozen = Object.isFrozen, getPrototypeOf = Object.getPrototypeOf, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
- var freeze = Object.freeze, seal = Object.seal, create$8 = Object.create;
- var _ref = typeof Reflect !== 'undefined' && Reflect, apply = _ref.apply, construct = _ref.construct;
- if (!apply) {
- apply = function apply(fun, thisValue, args) {
- return fun.apply(thisValue, args);
- };
- }
- if (!freeze) {
- freeze = function freeze(x) {
- return x;
- };
- }
- if (!seal) {
- seal = function seal(x) {
- return x;
- };
- }
- if (!construct) {
- construct = function construct(Func, args) {
- return _construct(Func, _toConsumableArray(args));
- };
- }
- var arrayForEach = unapply(Array.prototype.forEach);
- var arrayPop = unapply(Array.prototype.pop);
- var arrayPush = unapply(Array.prototype.push);
- var stringToLowerCase = unapply(String.prototype.toLowerCase);
- var stringMatch = unapply(String.prototype.match);
- var stringReplace = unapply(String.prototype.replace);
- var stringIndexOf = unapply(String.prototype.indexOf);
- var stringTrim = unapply(String.prototype.trim);
- var regExpTest = unapply(RegExp.prototype.test);
- var typeErrorCreate = unconstruct(TypeError);
- function unapply(func) {
- return function (thisArg) {
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- args[_key - 1] = arguments[_key];
- }
- return apply(func, thisArg, args);
- };
- }
- function unconstruct(func) {
- return function () {
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
- args[_key2] = arguments[_key2];
- }
- return construct(func, args);
- };
- }
- function addToSet(set, array) {
- if (setPrototypeOf) {
- setPrototypeOf(set, null);
- }
- var l = array.length;
- while (l--) {
- var element = array[l];
- if (typeof element === 'string') {
- var lcElement = stringToLowerCase(element);
- if (lcElement !== element) {
- if (!isFrozen(array)) {
- array[l] = lcElement;
- }
- element = lcElement;
- }
- }
- set[element] = true;
- }
- return set;
- }
- function clone(object) {
- var newObject = create$8(null);
- var property;
- for (property in object) {
- if (apply(hasOwnProperty, object, [property])) {
- newObject[property] = object[property];
- }
- }
- return newObject;
- }
- function lookupGetter(object, prop) {
- while (object !== null) {
- var desc = getOwnPropertyDescriptor(object, prop);
- if (desc) {
- if (desc.get) {
- return unapply(desc.get);
- }
- if (typeof desc.value === 'function') {
- return unapply(desc.value);
- }
- }
- object = getPrototypeOf(object);
- }
- function fallbackValue(element) {
- console.warn('fallback value for', element);
- return null;
- }
- return fallbackValue;
- }
- var html$1 = freeze([
- 'a',
- 'abbr',
- 'acronym',
- 'address',
- 'area',
- 'article',
- 'aside',
- 'audio',
- 'b',
- 'bdi',
- 'bdo',
- 'big',
- 'blink',
- 'blockquote',
- 'body',
- 'br',
- 'button',
- 'canvas',
- 'caption',
- 'center',
- 'cite',
- 'code',
- 'col',
- 'colgroup',
- 'content',
- 'data',
- 'datalist',
- 'dd',
- 'decorator',
- 'del',
- 'details',
- 'dfn',
- 'dialog',
- 'dir',
- 'div',
- 'dl',
- 'dt',
- 'element',
- 'em',
- 'fieldset',
- 'figcaption',
- 'figure',
- 'font',
- 'footer',
- 'form',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'head',
- 'header',
- 'hgroup',
- 'hr',
- 'html',
- 'i',
- 'img',
- 'input',
- 'ins',
- 'kbd',
- 'label',
- 'legend',
- 'li',
- 'main',
- 'map',
- 'mark',
- 'marquee',
- 'menu',
- 'menuitem',
- 'meter',
- 'nav',
- 'nobr',
- 'ol',
- 'optgroup',
- 'option',
- 'output',
- 'p',
- 'picture',
- 'pre',
- 'progress',
- 'q',
- 'rp',
- 'rt',
- 'ruby',
- 's',
- 'samp',
- 'section',
- 'select',
- 'shadow',
- 'small',
- 'source',
- 'spacer',
- 'span',
- 'strike',
- 'strong',
- 'style',
- 'sub',
- 'summary',
- 'sup',
- 'table',
- 'tbody',
- 'td',
- 'template',
- 'textarea',
- 'tfoot',
- 'th',
- 'thead',
- 'time',
- 'tr',
- 'track',
- 'tt',
- 'u',
- 'ul',
- 'var',
- 'video',
- 'wbr'
- ]);
- var svg$1 = freeze([
- 'svg',
- 'a',
- 'altglyph',
- 'altglyphdef',
- 'altglyphitem',
- 'animatecolor',
- 'animatemotion',
- 'animatetransform',
- 'circle',
- 'clippath',
- 'defs',
- 'desc',
- 'ellipse',
- 'filter',
- 'font',
- 'g',
- 'glyph',
- 'glyphref',
- 'hkern',
- 'image',
- 'line',
- 'lineargradient',
- 'marker',
- 'mask',
- 'metadata',
- 'mpath',
- 'path',
- 'pattern',
- 'polygon',
- 'polyline',
- 'radialgradient',
- 'rect',
- 'stop',
- 'style',
- 'switch',
- 'symbol',
- 'text',
- 'textpath',
- 'title',
- 'tref',
- 'tspan',
- 'view',
- 'vkern'
- ]);
- var svgFilters = freeze([
- 'feBlend',
- 'feColorMatrix',
- 'feComponentTransfer',
- 'feComposite',
- 'feConvolveMatrix',
- 'feDiffuseLighting',
- 'feDisplacementMap',
- 'feDistantLight',
- 'feFlood',
- 'feFuncA',
- 'feFuncB',
- 'feFuncG',
- 'feFuncR',
- 'feGaussianBlur',
- 'feImage',
- 'feMerge',
- 'feMergeNode',
- 'feMorphology',
- 'feOffset',
- 'fePointLight',
- 'feSpecularLighting',
- 'feSpotLight',
- 'feTile',
- 'feTurbulence'
- ]);
- var svgDisallowed = freeze([
- 'animate',
- 'color-profile',
- 'cursor',
- 'discard',
- 'fedropshadow',
- 'font-face',
- 'font-face-format',
- 'font-face-name',
- 'font-face-src',
- 'font-face-uri',
- 'foreignobject',
- 'hatch',
- 'hatchpath',
- 'mesh',
- 'meshgradient',
- 'meshpatch',
- 'meshrow',
- 'missing-glyph',
- 'script',
- 'set',
- 'solidcolor',
- 'unknown',
- 'use'
- ]);
- var mathMl$1 = freeze([
- 'math',
- 'menclose',
- 'merror',
- 'mfenced',
- 'mfrac',
- 'mglyph',
- 'mi',
- 'mlabeledtr',
- 'mmultiscripts',
- 'mn',
- 'mo',
- 'mover',
- 'mpadded',
- 'mphantom',
- 'mroot',
- 'mrow',
- 'ms',
- 'mspace',
- 'msqrt',
- 'mstyle',
- 'msub',
- 'msup',
- 'msubsup',
- 'mtable',
- 'mtd',
- 'mtext',
- 'mtr',
- 'munder',
- 'munderover'
- ]);
- var mathMlDisallowed = freeze([
- 'maction',
- 'maligngroup',
- 'malignmark',
- 'mlongdiv',
- 'mscarries',
- 'mscarry',
- 'msgroup',
- 'mstack',
- 'msline',
- 'msrow',
- 'semantics',
- 'annotation',
- 'annotation-xml',
- 'mprescripts',
- 'none'
- ]);
- var text = freeze(['#text']);
- var html = freeze([
- 'accept',
- 'action',
- 'align',
- 'alt',
- 'autocapitalize',
- 'autocomplete',
- 'autopictureinpicture',
- 'autoplay',
- 'background',
- 'bgcolor',
- 'border',
- 'capture',
- 'cellpadding',
- 'cellspacing',
- 'checked',
- 'cite',
- 'class',
- 'clear',
- 'color',
- 'cols',
- 'colspan',
- 'controls',
- 'controlslist',
- 'coords',
- 'crossorigin',
- 'datetime',
- 'decoding',
- 'default',
- 'dir',
- 'disabled',
- 'disablepictureinpicture',
- 'disableremoteplayback',
- 'download',
- 'draggable',
- 'enctype',
- 'enterkeyhint',
- 'face',
- 'for',
- 'headers',
- 'height',
- 'hidden',
- 'high',
- 'href',
- 'hreflang',
- 'id',
- 'inputmode',
- 'integrity',
- 'ismap',
- 'kind',
- 'label',
- 'lang',
- 'list',
- 'loading',
- 'loop',
- 'low',
- 'max',
- 'maxlength',
- 'media',
- 'method',
- 'min',
- 'minlength',
- 'multiple',
- 'muted',
- 'name',
- 'nonce',
- 'noshade',
- 'novalidate',
- 'nowrap',
- 'open',
- 'optimum',
- 'pattern',
- 'placeholder',
- 'playsinline',
- 'poster',
- 'preload',
- 'pubdate',
- 'radiogroup',
- 'readonly',
- 'rel',
- 'required',
- 'rev',
- 'reversed',
- 'role',
- 'rows',
- 'rowspan',
- 'spellcheck',
- 'scope',
- 'selected',
- 'shape',
- 'size',
- 'sizes',
- 'span',
- 'srclang',
- 'start',
- 'src',
- 'srcset',
- 'step',
- 'style',
- 'summary',
- 'tabindex',
- 'title',
- 'translate',
- 'type',
- 'usemap',
- 'valign',
- 'value',
- 'width',
- 'xmlns',
- 'slot'
- ]);
- var svg = freeze([
- 'accent-height',
- 'accumulate',
- 'additive',
- 'alignment-baseline',
- 'ascent',
- 'attributename',
- 'attributetype',
- 'azimuth',
- 'basefrequency',
- 'baseline-shift',
- 'begin',
- 'bias',
- 'by',
- 'class',
- 'clip',
- 'clippathunits',
- 'clip-path',
- 'clip-rule',
- 'color',
- 'color-interpolation',
- 'color-interpolation-filters',
- 'color-profile',
- 'color-rendering',
- 'cx',
- 'cy',
- 'd',
- 'dx',
- 'dy',
- 'diffuseconstant',
- 'direction',
- 'display',
- 'divisor',
- 'dur',
- 'edgemode',
- 'elevation',
- 'end',
- 'fill',
- 'fill-opacity',
- 'fill-rule',
- 'filter',
- 'filterunits',
- 'flood-color',
- 'flood-opacity',
- 'font-family',
- 'font-size',
- 'font-size-adjust',
- 'font-stretch',
- 'font-style',
- 'font-variant',
- 'font-weight',
- 'fx',
- 'fy',
- 'g1',
- 'g2',
- 'glyph-name',
- 'glyphref',
- 'gradientunits',
- 'gradienttransform',
- 'height',
- 'href',
- 'id',
- 'image-rendering',
- 'in',
- 'in2',
- 'k',
- 'k1',
- 'k2',
- 'k3',
- 'k4',
- 'kerning',
- 'keypoints',
- 'keysplines',
- 'keytimes',
- 'lang',
- 'lengthadjust',
- 'letter-spacing',
- 'kernelmatrix',
- 'kernelunitlength',
- 'lighting-color',
- 'local',
- 'marker-end',
- 'marker-mid',
- 'marker-start',
- 'markerheight',
- 'markerunits',
- 'markerwidth',
- 'maskcontentunits',
- 'maskunits',
- 'max',
- 'mask',
- 'media',
- 'method',
- 'mode',
- 'min',
- 'name',
- 'numoctaves',
- 'offset',
- 'operator',
- 'opacity',
- 'order',
- 'orient',
- 'orientation',
- 'origin',
- 'overflow',
- 'paint-order',
- 'path',
- 'pathlength',
- 'patterncontentunits',
- 'patterntransform',
- 'patternunits',
- 'points',
- 'preservealpha',
- 'preserveaspectratio',
- 'primitiveunits',
- 'r',
- 'rx',
- 'ry',
- 'radius',
- 'refx',
- 'refy',
- 'repeatcount',
- 'repeatdur',
- 'restart',
- 'result',
- 'rotate',
- 'scale',
- 'seed',
- 'shape-rendering',
- 'specularconstant',
- 'specularexponent',
- 'spreadmethod',
- 'startoffset',
- 'stddeviation',
- 'stitchtiles',
- 'stop-color',
- 'stop-opacity',
- 'stroke-dasharray',
- 'stroke-dashoffset',
- 'stroke-linecap',
- 'stroke-linejoin',
- 'stroke-miterlimit',
- 'stroke-opacity',
- 'stroke',
- 'stroke-width',
- 'style',
- 'surfacescale',
- 'systemlanguage',
- 'tabindex',
- 'targetx',
- 'targety',
- 'transform',
- 'transform-origin',
- 'text-anchor',
- 'text-decoration',
- 'text-rendering',
- 'textlength',
- 'type',
- 'u1',
- 'u2',
- 'unicode',
- 'values',
- 'viewbox',
- 'visibility',
- 'version',
- 'vert-adv-y',
- 'vert-origin-x',
- 'vert-origin-y',
- 'width',
- 'word-spacing',
- 'wrap',
- 'writing-mode',
- 'xchannelselector',
- 'ychannelselector',
- 'x',
- 'x1',
- 'x2',
- 'xmlns',
- 'y',
- 'y1',
- 'y2',
- 'z',
- 'zoomandpan'
- ]);
- var mathMl = freeze([
- 'accent',
- 'accentunder',
- 'align',
- 'bevelled',
- 'close',
- 'columnsalign',
- 'columnlines',
- 'columnspan',
- 'denomalign',
- 'depth',
- 'dir',
- 'display',
- 'displaystyle',
- 'encoding',
- 'fence',
- 'frame',
- 'height',
- 'href',
- 'id',
- 'largeop',
- 'length',
- 'linethickness',
- 'lspace',
- 'lquote',
- 'mathbackground',
- 'mathcolor',
- 'mathsize',
- 'mathvariant',
- 'maxsize',
- 'minsize',
- 'movablelimits',
- 'notation',
- 'numalign',
- 'open',
- 'rowalign',
- 'rowlines',
- 'rowspacing',
- 'rowspan',
- 'rspace',
- 'rquote',
- 'scriptlevel',
- 'scriptminsize',
- 'scriptsizemultiplier',
- 'selection',
- 'separator',
- 'separators',
- 'stretchy',
- 'subscriptshift',
- 'supscriptshift',
- 'symmetric',
- 'voffset',
- 'width',
- 'xmlns'
- ]);
- var xml = freeze([
- 'xlink:href',
- 'xml:id',
- 'xlink:title',
- 'xml:space',
- 'xmlns:xlink'
- ]);
- var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
- var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
- var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/);
- var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
- var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
- var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
- var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g);
- var DOCTYPE_NAME = seal(/^html$/i);
- var getGlobal = function getGlobal() {
- return typeof window === 'undefined' ? null : window;
- };
- var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
- if (_typeof(trustedTypes) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
- return null;
- }
- var suffix = null;
- var ATTR_NAME = 'data-tt-policy-suffix';
- if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
- suffix = document.currentScript.getAttribute(ATTR_NAME);
- }
- var policyName = 'dompurify' + (suffix ? '#' + suffix : '');
- try {
- return trustedTypes.createPolicy(policyName, {
- createHTML: function createHTML(html) {
- return html;
- }
- });
- } catch (_) {
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
- return null;
- }
- };
- function createDOMPurify() {
- var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
- var DOMPurify = function DOMPurify(root) {
- return createDOMPurify(root);
- };
- DOMPurify.version = '2.3.8';
- DOMPurify.removed = [];
- if (!window || !window.document || window.document.nodeType !== 9) {
- DOMPurify.isSupported = false;
- return DOMPurify;
- }
- var originalDocument = window.document;
- var document = window.document;
- var DocumentFragment = window.DocumentFragment, HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter, _window$NamedNodeMap = window.NamedNodeMap, NamedNodeMap = _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap, HTMLFormElement = window.HTMLFormElement, DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
- var ElementPrototype = Element.prototype;
- var cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
- var getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
- var getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
- var getParentNode = lookupGetter(ElementPrototype, 'parentNode');
- if (typeof HTMLTemplateElement === 'function') {
- var template = document.createElement('template');
- if (template.content && template.content.ownerDocument) {
- document = template.content.ownerDocument;
- }
- }
- var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
- var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
- var _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
- var importNode = originalDocument.importNode;
- var documentMode = {};
- try {
- documentMode = clone(document).documentMode ? document.documentMode : {};
- } catch (_) {
- }
- var hooks = {};
- DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
- var MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE;
- var IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
- var ALLOWED_TAGS = null;
- var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray(html$1), _toConsumableArray(svg$1), _toConsumableArray(svgFilters), _toConsumableArray(mathMl$1), _toConsumableArray(text)));
- var ALLOWED_ATTR = null;
- var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray(html), _toConsumableArray(svg), _toConsumableArray(mathMl), _toConsumableArray(xml)));
- var CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
- tagNameCheck: {
- writable: true,
- configurable: false,
- enumerable: true,
- value: null
- },
- attributeNameCheck: {
- writable: true,
- configurable: false,
- enumerable: true,
- value: null
- },
- allowCustomizedBuiltInElements: {
- writable: true,
- configurable: false,
- enumerable: true,
- value: false
- }
- }));
- var FORBID_TAGS = null;
- var FORBID_ATTR = null;
- var ALLOW_ARIA_ATTR = true;
- var ALLOW_DATA_ATTR = true;
- var ALLOW_UNKNOWN_PROTOCOLS = false;
- var SAFE_FOR_TEMPLATES = false;
- var WHOLE_DOCUMENT = false;
- var SET_CONFIG = false;
- var FORCE_BODY = false;
- var RETURN_DOM = false;
- var RETURN_DOM_FRAGMENT = false;
- var RETURN_TRUSTED_TYPE = false;
- var SANITIZE_DOM = true;
- var KEEP_CONTENT = true;
- var IN_PLACE = false;
- var USE_PROFILES = {};
- var FORBID_CONTENTS = null;
- var DEFAULT_FORBID_CONTENTS = addToSet({}, [
- 'annotation-xml',
- 'audio',
- 'colgroup',
- 'desc',
- 'foreignobject',
- 'head',
- 'iframe',
- 'math',
- 'mi',
- 'mn',
- 'mo',
- 'ms',
- 'mtext',
- 'noembed',
- 'noframes',
- 'noscript',
- 'plaintext',
- 'script',
- 'style',
- 'svg',
- 'template',
- 'thead',
- 'title',
- 'video',
- 'xmp'
- ]);
- var DATA_URI_TAGS = null;
- var DEFAULT_DATA_URI_TAGS = addToSet({}, [
- 'audio',
- 'video',
- 'img',
- 'source',
- 'image',
- 'track'
- ]);
- var URI_SAFE_ATTRIBUTES = null;
- var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
- 'alt',
- 'class',
- 'for',
- 'id',
- 'label',
- 'name',
- 'pattern',
- 'placeholder',
- 'role',
- 'summary',
- 'title',
- 'value',
- 'style',
- 'xmlns'
- ]);
- var MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
- var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
- var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
- var NAMESPACE = HTML_NAMESPACE;
- var IS_EMPTY_INPUT = false;
- var PARSER_MEDIA_TYPE;
- var SUPPORTED_PARSER_MEDIA_TYPES = [
- 'application/xhtml+xml',
- 'text/html'
- ];
- var DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
- var transformCaseFunc;
- var CONFIG = null;
- var formElement = document.createElement('form');
- var isRegexOrFunction = function isRegexOrFunction(testValue) {
- return testValue instanceof RegExp || testValue instanceof Function;
- };
- var _parseConfig = function _parseConfig(cfg) {
- if (CONFIG && CONFIG === cfg) {
- return;
- }
- if (!cfg || _typeof(cfg) !== 'object') {
- cfg = {};
- }
- cfg = clone(cfg);
- ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
- ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
- URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;
- DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;
- FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS) : DEFAULT_FORBID_CONTENTS;
- FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};
- FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};
- USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
- RETURN_DOM = cfg.RETURN_DOM || false;
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
- FORCE_BODY = cfg.FORCE_BODY || false;
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
- IN_PLACE = cfg.IN_PLACE || false;
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$1;
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
- }
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
- }
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
- }
- PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE;
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? function (x) {
- return x;
- } : stringToLowerCase;
- if (SAFE_FOR_TEMPLATES) {
- ALLOW_DATA_ATTR = false;
- }
- if (RETURN_DOM_FRAGMENT) {
- RETURN_DOM = true;
- }
- if (USE_PROFILES) {
- ALLOWED_TAGS = addToSet({}, _toConsumableArray(text));
- ALLOWED_ATTR = [];
- if (USE_PROFILES.html === true) {
- addToSet(ALLOWED_TAGS, html$1);
- addToSet(ALLOWED_ATTR, html);
- }
- if (USE_PROFILES.svg === true) {
- addToSet(ALLOWED_TAGS, svg$1);
- addToSet(ALLOWED_ATTR, svg);
- addToSet(ALLOWED_ATTR, xml);
- }
- if (USE_PROFILES.svgFilters === true) {
- addToSet(ALLOWED_TAGS, svgFilters);
- addToSet(ALLOWED_ATTR, svg);
- addToSet(ALLOWED_ATTR, xml);
- }
- if (USE_PROFILES.mathMl === true) {
- addToSet(ALLOWED_TAGS, mathMl$1);
- addToSet(ALLOWED_ATTR, mathMl);
- addToSet(ALLOWED_ATTR, xml);
- }
- }
- if (cfg.ADD_TAGS) {
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
- }
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);
- }
- if (cfg.ADD_ATTR) {
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
- }
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);
- }
- if (cfg.ADD_URI_SAFE_ATTR) {
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);
- }
- if (cfg.FORBID_CONTENTS) {
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
- }
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS);
- }
- if (KEEP_CONTENT) {
- ALLOWED_TAGS['#text'] = true;
- }
- if (WHOLE_DOCUMENT) {
- addToSet(ALLOWED_TAGS, [
- 'html',
- 'head',
- 'body'
- ]);
- }
- if (ALLOWED_TAGS.table) {
- addToSet(ALLOWED_TAGS, ['tbody']);
- delete FORBID_TAGS.tbody;
- }
- if (freeze) {
- freeze(cfg);
- }
- CONFIG = cfg;
- };
- var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
- 'mi',
- 'mo',
- 'mn',
- 'ms',
- 'mtext'
- ]);
- var HTML_INTEGRATION_POINTS = addToSet({}, [
- 'foreignobject',
- 'desc',
- 'title',
- 'annotation-xml'
- ]);
- var COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
- 'title',
- 'style',
- 'font',
- 'a',
- 'script'
- ]);
- var ALL_SVG_TAGS = addToSet({}, svg$1);
- addToSet(ALL_SVG_TAGS, svgFilters);
- addToSet(ALL_SVG_TAGS, svgDisallowed);
- var ALL_MATHML_TAGS = addToSet({}, mathMl$1);
- addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
- var _checkValidNamespace = function _checkValidNamespace(element) {
- var parent = getParentNode(element);
- if (!parent || !parent.tagName) {
- parent = {
- namespaceURI: HTML_NAMESPACE,
- tagName: 'template'
- };
- }
- var tagName = stringToLowerCase(element.tagName);
- var parentTagName = stringToLowerCase(parent.tagName);
- if (element.namespaceURI === SVG_NAMESPACE) {
- if (parent.namespaceURI === HTML_NAMESPACE) {
- return tagName === 'svg';
- }
- if (parent.namespaceURI === MATHML_NAMESPACE) {
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
- }
- return Boolean(ALL_SVG_TAGS[tagName]);
- }
- if (element.namespaceURI === MATHML_NAMESPACE) {
- if (parent.namespaceURI === HTML_NAMESPACE) {
- return tagName === 'math';
- }
- if (parent.namespaceURI === SVG_NAMESPACE) {
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
- }
- return Boolean(ALL_MATHML_TAGS[tagName]);
- }
- if (element.namespaceURI === HTML_NAMESPACE) {
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
- return false;
- }
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
- return false;
- }
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
- }
- return false;
- };
- var _forceRemove = function _forceRemove(node) {
- arrayPush(DOMPurify.removed, { element: node });
- try {
- node.parentNode.removeChild(node);
- } catch (_) {
- try {
- node.outerHTML = emptyHTML;
- } catch (_) {
- node.remove();
- }
- }
- };
- var _removeAttribute = function _removeAttribute(name, node) {
- try {
- arrayPush(DOMPurify.removed, {
- attribute: node.getAttributeNode(name),
- from: node
- });
- } catch (_) {
- arrayPush(DOMPurify.removed, {
- attribute: null,
- from: node
- });
- }
- node.removeAttribute(name);
- if (name === 'is' && !ALLOWED_ATTR[name]) {
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
- try {
- _forceRemove(node);
- } catch (_) {
- }
- } else {
- try {
- node.setAttribute(name, '');
- } catch (_) {
- }
- }
- }
- };
- var _initDocument = function _initDocument(dirty) {
- var doc;
- var leadingWhitespace;
- if (FORCE_BODY) {
- dirty = '<remove></remove>' + dirty;
- } else {
- var matches = stringMatch(dirty, /^[\r\n\t ]+/);
- leadingWhitespace = matches && matches[0];
- }
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml') {
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
- }
- var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
- if (NAMESPACE === HTML_NAMESPACE) {
- try {
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
- } catch (_) {
- }
- }
- if (!doc || !doc.documentElement) {
- doc = implementation.createDocument(NAMESPACE, 'template', null);
- try {
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? '' : dirtyPayload;
- } catch (_) {
- }
- }
- var body = doc.body || doc.documentElement;
- if (dirty && leadingWhitespace) {
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
- }
- if (NAMESPACE === HTML_NAMESPACE) {
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
- }
- return WHOLE_DOCUMENT ? doc.documentElement : body;
- };
- var _createIterator = function _createIterator(root) {
- return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
- };
- var _isClobbered = function _isClobbered(elm) {
- return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function');
- };
- var _isNode = function _isNode(object) {
- return _typeof(Node) === 'object' ? object instanceof Node : object && _typeof(object) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
- };
- var _executeHook = function _executeHook(entryPoint, currentNode, data) {
- if (!hooks[entryPoint]) {
- return;
- }
- arrayForEach(hooks[entryPoint], function (hook) {
- hook.call(DOMPurify, currentNode, data, CONFIG);
- });
- };
- var _sanitizeElements = function _sanitizeElements(currentNode) {
- var content;
- _executeHook('beforeSanitizeElements', currentNode, null);
- if (_isClobbered(currentNode)) {
- _forceRemove(currentNode);
- return true;
- }
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
- _forceRemove(currentNode);
- return true;
- }
- var tagName = transformCaseFunc(currentNode.nodeName);
- _executeHook('uponSanitizeElement', currentNode, {
- tagName: tagName,
- allowedTags: ALLOWED_TAGS
- });
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
- _forceRemove(currentNode);
- return true;
- }
- if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
- _forceRemove(currentNode);
- return true;
- }
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
- if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName))
- return false;
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName))
- return false;
- }
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
- var parentNode = getParentNode(currentNode) || currentNode.parentNode;
- var childNodes = getChildNodes(currentNode) || currentNode.childNodes;
- if (childNodes && parentNode) {
- var childCount = childNodes.length;
- for (var i = childCount - 1; i >= 0; --i) {
- parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
- }
- }
- }
- _forceRemove(currentNode);
- return true;
- }
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
- _forceRemove(currentNode);
- return true;
- }
- if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
- _forceRemove(currentNode);
- return true;
- }
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
- content = currentNode.textContent;
- content = stringReplace(content, MUSTACHE_EXPR$1, ' ');
- content = stringReplace(content, ERB_EXPR$1, ' ');
- if (currentNode.textContent !== content) {
- arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
- currentNode.textContent = content;
- }
- }
- _executeHook('afterSanitizeElements', currentNode, null);
- return false;
- };
- var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
- return false;
- }
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$1, lcName));
- else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName));
- else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
- if (_basicCustomElementTest(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value)));
- else {
- return false;
- }
- } else if (URI_SAFE_ATTRIBUTES[lcName]);
- else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, '')));
- else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]);
- else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, '')));
- else if (!value);
- else {
- return false;
- }
- return true;
- };
- var _basicCustomElementTest = function _basicCustomElementTest(tagName) {
- return tagName.indexOf('-') > 0;
- };
- var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
- var attr;
- var value;
- var lcName;
- var l;
- _executeHook('beforeSanitizeAttributes', currentNode, null);
- var attributes = currentNode.attributes;
- if (!attributes) {
- return;
- }
- var hookEvent = {
- attrName: '',
- attrValue: '',
- keepAttr: true,
- allowedAttributes: ALLOWED_ATTR
- };
- l = attributes.length;
- while (l--) {
- attr = attributes[l];
- var _attr = attr, name = _attr.name, namespaceURI = _attr.namespaceURI;
- value = name === 'value' ? attr.value : stringTrim(attr.value);
- lcName = transformCaseFunc(name);
- var initValue = value;
- hookEvent.attrName = lcName;
- hookEvent.attrValue = value;
- hookEvent.keepAttr = true;
- hookEvent.forceKeepAttr = undefined;
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
- value = hookEvent.attrValue;
- if (hookEvent.forceKeepAttr) {
- continue;
- }
- if (!hookEvent.keepAttr) {
- _removeAttribute(name, currentNode);
- continue;
- }
- if (regExpTest(/\/>/i, value)) {
- _removeAttribute(name, currentNode);
- continue;
- }
- if (SAFE_FOR_TEMPLATES) {
- value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
- value = stringReplace(value, ERB_EXPR$1, ' ');
- }
- var lcTag = transformCaseFunc(currentNode.nodeName);
- if (!_isValidAttribute(lcTag, lcName, value)) {
- _removeAttribute(name, currentNode);
- continue;
- }
- if (value !== initValue) {
- try {
- if (namespaceURI) {
- currentNode.setAttributeNS(namespaceURI, name, value);
- } else {
- currentNode.setAttribute(name, value);
- }
- } catch (_) {
- _removeAttribute(name, currentNode);
- }
- }
- }
- _executeHook('afterSanitizeAttributes', currentNode, null);
- };
- var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
- var shadowNode;
- var shadowIterator = _createIterator(fragment);
- _executeHook('beforeSanitizeShadowDOM', fragment, null);
- while (shadowNode = shadowIterator.nextNode()) {
- _executeHook('uponSanitizeShadowNode', shadowNode, null);
- if (_sanitizeElements(shadowNode)) {
- continue;
- }
- if (shadowNode.content instanceof DocumentFragment) {
- _sanitizeShadowDOM(shadowNode.content);
- }
- _sanitizeAttributes(shadowNode);
- }
- _executeHook('afterSanitizeShadowDOM', fragment, null);
- };
- DOMPurify.sanitize = function (dirty, cfg) {
- var body;
- var importedNode;
- var currentNode;
- var oldNode;
- var returnNode;
- IS_EMPTY_INPUT = !dirty;
- if (IS_EMPTY_INPUT) {
- dirty = '<!-->';
- }
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
- if (typeof dirty.toString !== 'function') {
- throw typeErrorCreate('toString is not a function');
- } else {
- dirty = dirty.toString();
- if (typeof dirty !== 'string') {
- throw typeErrorCreate('dirty is not a string, aborting');
- }
- }
- }
- if (!DOMPurify.isSupported) {
- if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
- if (typeof dirty === 'string') {
- return window.toStaticHTML(dirty);
- }
- if (_isNode(dirty)) {
- return window.toStaticHTML(dirty.outerHTML);
- }
- }
- return dirty;
- }
- if (!SET_CONFIG) {
- _parseConfig(cfg);
- }
- DOMPurify.removed = [];
- if (typeof dirty === 'string') {
- IN_PLACE = false;
- }
- if (IN_PLACE) {
- if (dirty.nodeName) {
- var tagName = transformCaseFunc(dirty.nodeName);
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
- }
- }
- } else if (dirty instanceof Node) {
- body = _initDocument('<!---->');
- importedNode = body.ownerDocument.importNode(dirty, true);
- if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
- body = importedNode;
- } else if (importedNode.nodeName === 'HTML') {
- body = importedNode;
- } else {
- body.appendChild(importedNode);
- }
- } else {
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf('<') === -1) {
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
- }
- body = _initDocument(dirty);
- if (!body) {
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
- }
- }
- if (body && FORCE_BODY) {
- _forceRemove(body.firstChild);
- }
- var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
- while (currentNode = nodeIterator.nextNode()) {
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
- continue;
- }
- if (_sanitizeElements(currentNode)) {
- continue;
- }
- if (currentNode.content instanceof DocumentFragment) {
- _sanitizeShadowDOM(currentNode.content);
- }
- _sanitizeAttributes(currentNode);
- oldNode = currentNode;
- }
- oldNode = null;
- if (IN_PLACE) {
- return dirty;
- }
- if (RETURN_DOM) {
- if (RETURN_DOM_FRAGMENT) {
- returnNode = createDocumentFragment.call(body.ownerDocument);
- while (body.firstChild) {
- returnNode.appendChild(body.firstChild);
- }
- } else {
- returnNode = body;
- }
- if (ALLOWED_ATTR.shadowroot) {
- returnNode = importNode.call(originalDocument, returnNode, true);
- }
- return returnNode;
- }
- var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
- }
- if (SAFE_FOR_TEMPLATES) {
- serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$1, ' ');
- serializedHTML = stringReplace(serializedHTML, ERB_EXPR$1, ' ');
- }
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
- };
- DOMPurify.setConfig = function (cfg) {
- _parseConfig(cfg);
- SET_CONFIG = true;
- };
- DOMPurify.clearConfig = function () {
- CONFIG = null;
- SET_CONFIG = false;
- };
- DOMPurify.isValidAttribute = function (tag, attr, value) {
- if (!CONFIG) {
- _parseConfig({});
- }
- var lcTag = transformCaseFunc(tag);
- var lcName = transformCaseFunc(attr);
- return _isValidAttribute(lcTag, lcName, value);
- };
- DOMPurify.addHook = function (entryPoint, hookFunction) {
- if (typeof hookFunction !== 'function') {
- return;
- }
- hooks[entryPoint] = hooks[entryPoint] || [];
- arrayPush(hooks[entryPoint], hookFunction);
- };
- DOMPurify.removeHook = function (entryPoint) {
- if (hooks[entryPoint]) {
- return arrayPop(hooks[entryPoint]);
- }
- };
- DOMPurify.removeHooks = function (entryPoint) {
- if (hooks[entryPoint]) {
- hooks[entryPoint] = [];
- }
- };
- DOMPurify.removeAllHooks = function () {
- hooks = {};
- };
- return DOMPurify;
- }
- var purify = createDOMPurify();
- const explode$1 = Tools.explode;
- const create$7 = () => {
- const filters = {};
- const addFilter = (name, callback) => {
- each$f(explode$1(name), name => {
- if (!has$2(filters, name)) {
- filters[name] = {
- name,
- callbacks: []
- };
- }
- filters[name].callbacks.push(callback);
- });
- };
- const getFilters = () => values(filters);
- const removeFilter = (name, callback) => {
- each$f(explode$1(name), name => {
- if (has$2(filters, name)) {
- if (isNonNullable(callback)) {
- const filter = filters[name];
- const newCallbacks = filter$6(filter.callbacks, c => c !== callback);
- if (newCallbacks.length > 0) {
- filter.callbacks = newCallbacks;
- } else {
- delete filters[name];
- }
- } else {
- delete filters[name];
- }
- }
- });
- };
- return {
- addFilter,
- getFilters,
- removeFilter
- };
- };
- const removeAttrs = (node, names) => {
- each$f(names, name => {
- node.attr(name, null);
- });
- };
- const addFontToSpansFilter = (domParser, styles, fontSizes) => {
- domParser.addNodeFilter('font', nodes => {
- each$f(nodes, node => {
- const props = styles.parse(node.attr('style'));
- const color = node.attr('color');
- const face = node.attr('face');
- const size = node.attr('size');
- if (color) {
- props.color = color;
- }
- if (face) {
- props['font-family'] = face;
- }
- if (size) {
- props['font-size'] = fontSizes[parseInt(node.attr('size'), 10) - 1];
- }
- node.name = 'span';
- node.attr('style', styles.serialize(props));
- removeAttrs(node, [
- 'color',
- 'face',
- 'size'
- ]);
- });
- });
- };
- const addStrikeFilter = (domParser, schema, styles) => {
- domParser.addNodeFilter('strike', nodes => {
- const convertToSTag = schema.type !== 'html4';
- each$f(nodes, node => {
- if (convertToSTag) {
- node.name = 's';
- } else {
- const props = styles.parse(node.attr('style'));
- props['text-decoration'] = 'line-through';
- node.name = 'span';
- node.attr('style', styles.serialize(props));
- }
- });
- });
- };
- const addFilters = (domParser, settings, schema) => {
- const styles = Styles();
- if (settings.convert_fonts_to_spans) {
- addFontToSpansFilter(domParser, styles, Tools.explode(settings.font_size_legacy_values));
- }
- addStrikeFilter(domParser, schema, styles);
- };
- const register$5 = (domParser, settings, schema) => {
- if (settings.inline_styles) {
- addFilters(domParser, settings, schema);
- }
- };
- const blobUriToBlob = url => fetch(url).then(res => res.ok ? res.blob() : Promise.reject()).catch(() => Promise.reject(`Cannot convert ${ url } to Blob. Resource might not exist or is inaccessible.`));
- const extractBase64Data = data => {
- const matches = /([a-z0-9+\/=\s]+)/i.exec(data);
- return matches ? matches[1] : '';
- };
- const parseDataUri = uri => {
- const [type, ...rest] = uri.split(',');
- const data = rest.join(',');
- const matches = /data:([^/]+\/[^;]+)(;.+)?/.exec(type);
- if (matches) {
- const base64Encoded = matches[2] === ';base64';
- const extractedData = base64Encoded ? extractBase64Data(data) : decodeURIComponent(data);
- return Optional.some({
- type: matches[1],
- data: extractedData,
- base64Encoded
- });
- } else {
- return Optional.none();
- }
- };
- const buildBlob = (type, data, base64Encoded = true) => {
- let str = data;
- if (base64Encoded) {
- try {
- str = atob(data);
- } catch (e) {
- return Optional.none();
- }
- }
- const arr = new Uint8Array(str.length);
- for (let i = 0; i < arr.length; i++) {
- arr[i] = str.charCodeAt(i);
- }
- return Optional.some(new Blob([arr], { type }));
- };
- const dataUriToBlob = uri => {
- return new Promise((resolve, reject) => {
- parseDataUri(uri).bind(({type, data, base64Encoded}) => buildBlob(type, data, base64Encoded)).fold(() => reject('Invalid data URI'), resolve);
- });
- };
- const uriToBlob = url => {
- if (startsWith(url, 'blob:')) {
- return blobUriToBlob(url);
- } else if (startsWith(url, 'data:')) {
- return dataUriToBlob(url);
- } else {
- return Promise.reject('Unknown URI format');
- }
- };
- const blobToDataUri = blob => {
- return new Promise((resolve, reject) => {
- const reader = new FileReader();
- reader.onloadend = () => {
- resolve(reader.result);
- };
- reader.onerror = () => {
- reject(reader.error.message);
- };
- reader.readAsDataURL(blob);
- });
- };
- let count$1 = 0;
- const uniqueId$1 = prefix => {
- return (prefix || 'blobid') + count$1++;
- };
- const processDataUri = (dataUri, base64Only, generateBlobInfo) => {
- return parseDataUri(dataUri).bind(({data, type, base64Encoded}) => {
- if (base64Only && !base64Encoded) {
- return Optional.none();
- } else {
- const base64 = base64Encoded ? data : btoa(data);
- return generateBlobInfo(base64, type);
- }
- });
- };
- const createBlobInfo$1 = (blobCache, blob, base64) => {
- const blobInfo = blobCache.create(uniqueId$1(), blob, base64);
- blobCache.add(blobInfo);
- return blobInfo;
- };
- const dataUriToBlobInfo = (blobCache, dataUri, base64Only = false) => {
- return processDataUri(dataUri, base64Only, (base64, type) => Optional.from(blobCache.getByData(base64, type)).orThunk(() => buildBlob(type, base64).map(blob => createBlobInfo$1(blobCache, blob, base64))));
- };
- const imageToBlobInfo = (blobCache, imageSrc) => {
- const invalidDataUri = () => Promise.reject('Invalid data URI');
- if (startsWith(imageSrc, 'blob:')) {
- const blobInfo = blobCache.getByUri(imageSrc);
- if (isNonNullable(blobInfo)) {
- return Promise.resolve(blobInfo);
- } else {
- return uriToBlob(imageSrc).then(blob => {
- return blobToDataUri(blob).then(dataUri => {
- return processDataUri(dataUri, false, base64 => {
- return Optional.some(createBlobInfo$1(blobCache, blob, base64));
- }).getOrThunk(invalidDataUri);
- });
- });
- }
- } else if (startsWith(imageSrc, 'data:')) {
- return dataUriToBlobInfo(blobCache, imageSrc).fold(invalidDataUri, blobInfo => Promise.resolve(blobInfo));
- } else {
- return Promise.reject('Unknown image data format');
- }
- };
- const isBogusImage = img => isNonNullable(img.attr('data-mce-bogus'));
- const isInternalImageSource = img => img.attr('src') === Env.transparentSrc || isNonNullable(img.attr('data-mce-placeholder'));
- const registerBase64ImageFilter = (parser, settings) => {
- const {blob_cache: blobCache} = settings;
- const processImage = img => {
- const inputSrc = img.attr('src');
- if (isInternalImageSource(img) || isBogusImage(img)) {
- return;
- }
- dataUriToBlobInfo(blobCache, inputSrc, true).each(blobInfo => {
- img.attr('src', blobInfo.blobUri());
- });
- };
- if (blobCache) {
- parser.addAttributeFilter('src', nodes => each$f(nodes, processImage));
- }
- };
- const register$4 = (parser, settings) => {
- const schema = parser.schema;
- if (settings.remove_trailing_brs) {
- parser.addNodeFilter('br', (nodes, _, args) => {
- const blockElements = Tools.extend({}, schema.getBlockElements());
- const nonEmptyElements = schema.getNonEmptyElements();
- const whitespaceElements = schema.getWhitespaceElements();
- blockElements.body = 1;
- for (let i = 0, l = nodes.length; i < l; i++) {
- let node = nodes[i];
- let parent = node.parent;
- if (blockElements[node.parent.name] && node === parent.lastChild) {
- let prev = node.prev;
- while (prev) {
- const prevName = prev.name;
- if (prevName !== 'span' || prev.attr('data-mce-type') !== 'bookmark') {
- if (prevName === 'br') {
- node = null;
- }
- break;
- }
- prev = prev.prev;
- }
- if (node) {
- node.remove();
- if (isEmpty(schema, nonEmptyElements, whitespaceElements, parent)) {
- const elementRule = schema.getElementRule(parent.name);
- if (elementRule) {
- if (elementRule.removeEmpty) {
- parent.remove();
- } else if (elementRule.paddEmpty) {
- paddEmptyNode(settings, args, blockElements, parent);
- }
- }
- }
- }
- } else {
- let lastParent = node;
- while (parent && parent.firstChild === lastParent && parent.lastChild === lastParent) {
- lastParent = parent;
- if (blockElements[parent.name]) {
- break;
- }
- parent = parent.parent;
- }
- if (lastParent === parent) {
- const textNode = new AstNode('#text', 3);
- textNode.value = nbsp;
- node.replace(textNode);
- }
- }
- }
- });
- }
- parser.addAttributeFilter('href', nodes => {
- let i = nodes.length;
- const appendRel = rel => {
- const parts = rel.split(' ').filter(p => p.length > 0);
- return parts.concat(['noopener']).sort().join(' ');
- };
- const addNoOpener = rel => {
- const newRel = rel ? Tools.trim(rel) : '';
- if (!/\b(noopener)\b/g.test(newRel)) {
- return appendRel(newRel);
- } else {
- return newRel;
- }
- };
- if (!settings.allow_unsafe_link_target) {
- while (i--) {
- const node = nodes[i];
- if (node.name === 'a' && node.attr('target') === '_blank') {
- node.attr('rel', addNoOpener(node.attr('rel')));
- }
- }
- }
- });
- if (!settings.allow_html_in_named_anchor) {
- parser.addAttributeFilter('id,name', nodes => {
- let i = nodes.length, sibling, prevSibling, parent, node;
- while (i--) {
- node = nodes[i];
- if (node.name === 'a' && node.firstChild && !node.attr('href')) {
- parent = node.parent;
- sibling = node.lastChild;
- do {
- prevSibling = sibling.prev;
- parent.insert(sibling, node);
- sibling = prevSibling;
- } while (sibling);
- }
- }
- });
- }
- if (settings.fix_list_elements) {
- parser.addNodeFilter('ul,ol', nodes => {
- let i = nodes.length, node, parentNode;
- while (i--) {
- node = nodes[i];
- parentNode = node.parent;
- if (parentNode.name === 'ul' || parentNode.name === 'ol') {
- if (node.prev && node.prev.name === 'li') {
- node.prev.append(node);
- } else {
- const li = new AstNode('li', 1);
- li.attr('style', 'list-style-type: none');
- node.wrap(li);
- }
- }
- }
- });
- }
- if (settings.validate && schema.getValidClasses()) {
- parser.addAttributeFilter('class', nodes => {
- const validClasses = schema.getValidClasses();
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- const classList = node.attr('class').split(' ');
- let classValue = '';
- for (let ci = 0; ci < classList.length; ci++) {
- const className = classList[ci];
- let valid = false;
- let validClassesMap = validClasses['*'];
- if (validClassesMap && validClassesMap[className]) {
- valid = true;
- }
- validClassesMap = validClasses[node.name];
- if (!valid && validClassesMap && validClassesMap[className]) {
- valid = true;
- }
- if (valid) {
- if (classValue) {
- classValue += ' ';
- }
- classValue += className;
- }
- }
- if (!classValue.length) {
- classValue = null;
- }
- node.attr('class', classValue);
- }
- });
- }
- registerBase64ImageFilter(parser, settings);
- };
- const each$4 = Tools.each, trim = Tools.trim;
- const queryParts = 'source protocol authority userInfo user password host port relative path directory file query anchor'.split(' ');
- const DEFAULT_PORTS = {
- ftp: 21,
- http: 80,
- https: 443,
- mailto: 25
- };
- const safeSvgDataUrlElements = [
- 'img',
- 'video'
- ];
- const blockSvgDataUris = (allowSvgDataUrls, tagName) => {
- if (isNonNullable(allowSvgDataUrls)) {
- return !allowSvgDataUrls;
- } else {
- return isNonNullable(tagName) ? !contains$2(safeSvgDataUrlElements, tagName) : true;
- }
- };
- const decodeUri = encodedUri => {
- try {
- return decodeURIComponent(encodedUri);
- } catch (ex) {
- return unescape(encodedUri);
- }
- };
- const isInvalidUri = (settings, uri, tagName) => {
- const decodedUri = decodeUri(uri);
- if (settings.allow_script_urls) {
- return false;
- } else if (/((java|vb)script|mhtml):/i.test(decodedUri)) {
- return true;
- } else if (settings.allow_html_data_urls) {
- return false;
- } else if (/^data:image\//i.test(decodedUri)) {
- return blockSvgDataUris(settings.allow_svg_data_urls, tagName) && /^data:image\/svg\+xml/i.test(decodedUri);
- } else {
- return /^data:/i.test(decodedUri);
- }
- };
- class URI {
- constructor(url, settings) {
- url = trim(url);
- this.settings = settings || {};
- const baseUri = this.settings.base_uri;
- const self = this;
- if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
- self.source = url;
- return;
- }
- const isProtocolRelative = url.indexOf('//') === 0;
- if (url.indexOf('/') === 0 && !isProtocolRelative) {
- url = (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url;
- }
- if (!/^[\w\-]*:?\/\//.test(url)) {
- const baseUrl = this.settings.base_uri ? this.settings.base_uri.path : new URI(document.location.href).directory;
- if (this.settings.base_uri && this.settings.base_uri.protocol == '') {
- url = '//mce_host' + self.toAbsPath(baseUrl, url);
- } else {
- const match = /([^#?]*)([#?]?.*)/.exec(url);
- url = (baseUri && baseUri.protocol || 'http') + '://mce_host' + self.toAbsPath(baseUrl, match[1]) + match[2];
- }
- }
- url = url.replace(/@@/g, '(mce_at)');
- const urlMatch = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?(\[[a-zA-Z0-9:.%]+\]|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
- each$4(queryParts, (v, i) => {
- let part = urlMatch[i];
- if (part) {
- part = part.replace(/\(mce_at\)/g, '@@');
- }
- self[v] = part;
- });
- if (baseUri) {
- if (!self.protocol) {
- self.protocol = baseUri.protocol;
- }
- if (!self.userInfo) {
- self.userInfo = baseUri.userInfo;
- }
- if (!self.port && self.host === 'mce_host') {
- self.port = baseUri.port;
- }
- if (!self.host || self.host === 'mce_host') {
- self.host = baseUri.host;
- }
- self.source = '';
- }
- if (isProtocolRelative) {
- self.protocol = '';
- }
- }
- static parseDataUri(uri) {
- let type;
- const uriComponents = decodeURIComponent(uri).split(',');
- const matches = /data:([^;]+)/.exec(uriComponents[0]);
- if (matches) {
- type = matches[1];
- }
- return {
- type,
- data: uriComponents[1]
- };
- }
- static isDomSafe(uri, context, options = {}) {
- if (options.allow_script_urls) {
- return true;
- } else {
- const decodedUri = Entities.decode(uri).replace(/[\s\u0000-\u001F]+/g, '');
- return !isInvalidUri(options, decodedUri, context);
- }
- }
- static getDocumentBaseUrl(loc) {
- let baseUrl;
- if (loc.protocol.indexOf('http') !== 0 && loc.protocol !== 'file:') {
- baseUrl = loc.href;
- } else {
- baseUrl = loc.protocol + '//' + loc.host + loc.pathname;
- }
- if (/^[^:]+:\/\/\/?[^\/]+\//.test(baseUrl)) {
- baseUrl = baseUrl.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
- if (!/[\/\\]$/.test(baseUrl)) {
- baseUrl += '/';
- }
- }
- return baseUrl;
- }
- setPath(path) {
- const pathMatch = /^(.*?)\/?(\w+)?$/.exec(path);
- this.path = pathMatch[0];
- this.directory = pathMatch[1];
- this.file = pathMatch[2];
- this.source = '';
- this.getURI();
- }
- toRelative(uri) {
- let output;
- if (uri === './') {
- return uri;
- }
- const relativeUri = new URI(uri, { base_uri: this });
- if (relativeUri.host !== 'mce_host' && this.host !== relativeUri.host && relativeUri.host || this.port !== relativeUri.port || this.protocol !== relativeUri.protocol && relativeUri.protocol !== '') {
- return relativeUri.getURI();
- }
- const tu = this.getURI(), uu = relativeUri.getURI();
- if (tu === uu || tu.charAt(tu.length - 1) === '/' && tu.substr(0, tu.length - 1) === uu) {
- return tu;
- }
- output = this.toRelPath(this.path, relativeUri.path);
- if (relativeUri.query) {
- output += '?' + relativeUri.query;
- }
- if (relativeUri.anchor) {
- output += '#' + relativeUri.anchor;
- }
- return output;
- }
- toAbsolute(uri, noHost) {
- const absoluteUri = new URI(uri, { base_uri: this });
- return absoluteUri.getURI(noHost && this.isSameOrigin(absoluteUri));
- }
- isSameOrigin(uri) {
- if (this.host == uri.host && this.protocol == uri.protocol) {
- if (this.port == uri.port) {
- return true;
- }
- const defaultPort = DEFAULT_PORTS[this.protocol];
- if (defaultPort && (this.port || defaultPort) == (uri.port || defaultPort)) {
- return true;
- }
- }
- return false;
- }
- toRelPath(base, path) {
- let breakPoint = 0, out = '', i, l;
- const normalizedBase = base.substring(0, base.lastIndexOf('/')).split('/');
- const items = path.split('/');
- if (normalizedBase.length >= items.length) {
- for (i = 0, l = normalizedBase.length; i < l; i++) {
- if (i >= items.length || normalizedBase[i] !== items[i]) {
- breakPoint = i + 1;
- break;
- }
- }
- }
- if (normalizedBase.length < items.length) {
- for (i = 0, l = items.length; i < l; i++) {
- if (i >= normalizedBase.length || normalizedBase[i] !== items[i]) {
- breakPoint = i + 1;
- break;
- }
- }
- }
- if (breakPoint === 1) {
- return path;
- }
- for (i = 0, l = normalizedBase.length - (breakPoint - 1); i < l; i++) {
- out += '../';
- }
- for (i = breakPoint - 1, l = items.length; i < l; i++) {
- if (i !== breakPoint - 1) {
- out += '/' + items[i];
- } else {
- out += items[i];
- }
- }
- return out;
- }
- toAbsPath(base, path) {
- let i, nb = 0, o = [], outPath;
- const tr = /\/$/.test(path) ? '/' : '';
- let normalizedBase = base.split('/');
- const normalizedPath = path.split('/');
- each$4(normalizedBase, k => {
- if (k) {
- o.push(k);
- }
- });
- normalizedBase = o;
- for (i = normalizedPath.length - 1, o = []; i >= 0; i--) {
- if (normalizedPath[i].length === 0 || normalizedPath[i] === '.') {
- continue;
- }
- if (normalizedPath[i] === '..') {
- nb++;
- continue;
- }
- if (nb > 0) {
- nb--;
- continue;
- }
- o.push(normalizedPath[i]);
- }
- i = normalizedBase.length - nb;
- if (i <= 0) {
- outPath = reverse(o).join('/');
- } else {
- outPath = normalizedBase.slice(0, i).join('/') + '/' + reverse(o).join('/');
- }
- if (outPath.indexOf('/') !== 0) {
- outPath = '/' + outPath;
- }
- if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) {
- outPath += tr;
- }
- return outPath;
- }
- getURI(noProtoHost = false) {
- let s;
- if (!this.source || noProtoHost) {
- s = '';
- if (!noProtoHost) {
- if (this.protocol) {
- s += this.protocol + '://';
- } else {
- s += '//';
- }
- if (this.userInfo) {
- s += this.userInfo + '@';
- }
- if (this.host) {
- s += this.host;
- }
- if (this.port) {
- s += ':' + this.port;
- }
- }
- if (this.path) {
- s += this.path;
- }
- if (this.query) {
- s += '?' + this.query;
- }
- if (this.anchor) {
- s += '#' + this.anchor;
- }
- this.source = s;
- }
- return this.source;
- }
- }
- const makeMap = Tools.makeMap, extend$1 = Tools.extend;
- const basePurifyConfig = {
- IN_PLACE: true,
- ALLOW_UNKNOWN_PROTOCOLS: true,
- ALLOWED_TAGS: [
- '#comment',
- '#cdata-section',
- 'body'
- ],
- ALLOWED_ATTR: []
- };
- const filteredUrlAttrs = Tools.makeMap('src,href,data,background,action,formaction,poster,xlink:href');
- const internalElementAttr = 'data-mce-type';
- const getPurifyConfig = (settings, mimeType) => {
- const config = { ...basePurifyConfig };
- config.PARSER_MEDIA_TYPE = mimeType;
- if (settings.allow_script_urls) {
- config.ALLOWED_URI_REGEXP = /.*/;
- } else if (settings.allow_html_data_urls) {
- config.ALLOWED_URI_REGEXP = /^(?!(\w+script|mhtml):)/i;
- }
- return config;
- };
- const setupPurify = (settings, schema) => {
- const purify$1 = purify();
- const validate = settings.validate;
- let uid = 0;
- purify$1.addHook('uponSanitizeElement', (ele, evt) => {
- var _a, _b;
- if (ele.nodeType === COMMENT && !settings.allow_conditional_comments && /^\[if/i.test(ele.nodeValue)) {
- ele.nodeValue = ' ' + ele.nodeValue;
- }
- const tagName = evt.tagName;
- if (ele.nodeType !== ELEMENT || tagName === 'body') {
- return;
- }
- const element = SugarElement.fromDom(ele);
- const isInternalElement = has$1(element, internalElementAttr);
- const bogus = get$9(element, 'data-mce-bogus');
- if (!isInternalElement && isString(bogus)) {
- if (bogus === 'all') {
- remove$6(element);
- } else {
- unwrap(element);
- }
- return;
- }
- const rule = schema.getElementRule(tagName.toLowerCase());
- if (validate && !rule) {
- unwrap(element);
- return;
- } else {
- evt.allowedTags[tagName] = true;
- }
- if (validate && !isInternalElement) {
- each$f((_a = rule.attributesForced) !== null && _a !== void 0 ? _a : [], attr => {
- set$2(element, attr.name, attr.value === '{$uid}' ? `mce_${ uid++ }` : attr.value);
- });
- each$f((_b = rule.attributesDefault) !== null && _b !== void 0 ? _b : [], attr => {
- if (!has$1(element, attr.name)) {
- set$2(element, attr.name, attr.value === '{$uid}' ? `mce_${ uid++ }` : attr.value);
- }
- });
- if (rule.attributesRequired && !exists(rule.attributesRequired, attr => has$1(element, attr))) {
- unwrap(element);
- return;
- }
- if (rule.removeEmptyAttrs && hasNone(element)) {
- unwrap(element);
- return;
- }
- if (rule.outputName && rule.outputName !== tagName.toLowerCase()) {
- mutate(element, rule.outputName);
- }
- }
- });
- purify$1.addHook('uponSanitizeAttribute', (ele, evt) => {
- const tagName = ele.tagName.toLowerCase();
- const {attrName, attrValue} = evt;
- evt.keepAttr = !validate || schema.isValid(tagName, attrName) || startsWith(attrName, 'data-') || startsWith(attrName, 'aria-');
- if (attrName in filteredUrlAttrs && isInvalidUri(settings, attrValue, tagName)) {
- evt.keepAttr = false;
- }
- if (evt.keepAttr) {
- evt.allowedAttributes[attrName] = true;
- if (attrName in schema.getBoolAttrs()) {
- evt.attrValue = attrName;
- }
- if (settings.allow_svg_data_urls && startsWith(attrValue, 'data:image/svg+xml')) {
- evt.forceKeepAttr = true;
- }
- } else if (ele.hasAttribute(internalElementAttr) && (attrName === 'id' || attrName === 'class' || attrName === 'style')) {
- evt.forceKeepAttr = true;
- }
- });
- return purify$1;
- };
- const transferChildren = (parent, nativeParent, specialElements) => {
- const parentName = parent.name;
- const isSpecial = parentName in specialElements && parentName !== 'title' && parentName !== 'textarea';
- const childNodes = nativeParent.childNodes;
- for (let ni = 0, nl = childNodes.length; ni < nl; ni++) {
- const nativeChild = childNodes[ni];
- const child = new AstNode(nativeChild.nodeName.toLowerCase(), nativeChild.nodeType);
- if (isElement$6(nativeChild)) {
- const attributes = nativeChild.attributes;
- for (let ai = 0, al = attributes.length; ai < al; ai++) {
- const attr = attributes[ai];
- child.attr(attr.name, attr.value);
- }
- } else if (isText$9(nativeChild)) {
- child.value = nativeChild.data;
- if (isSpecial) {
- child.raw = true;
- }
- } else if (isComment(nativeChild) || isCData(nativeChild) || isPi(nativeChild)) {
- child.value = nativeChild.data;
- }
- transferChildren(child, nativeChild, specialElements);
- parent.append(child);
- }
- };
- const walkTree = (root, preprocessors, postprocessors) => {
- const traverseOrder = [];
- for (let node = root, lastNode = node; isNonNullable(node); lastNode = node, node = node.walk()) {
- each$f(preprocessors, preprocess => preprocess(node));
- if (isNullable(node.parent) && node !== root) {
- node = lastNode;
- } else {
- traverseOrder.push(node);
- }
- }
- for (let i = traverseOrder.length - 1; i >= 0; i--) {
- const node = traverseOrder[i];
- each$f(postprocessors, postprocess => postprocess(node));
- }
- };
- const whitespaceCleaner = (root, schema, settings, args) => {
- const validate = settings.validate;
- const nonEmptyElements = schema.getNonEmptyElements();
- const whitespaceElements = schema.getWhitespaceElements();
- const blockElements = extend$1(makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
- const textRootBlockElements = getTextRootBlockElements(schema);
- const allWhiteSpaceRegExp = /[ \t\r\n]+/g;
- const startWhiteSpaceRegExp = /^[ \t\r\n]+/;
- const endWhiteSpaceRegExp = /[ \t\r\n]+$/;
- const hasWhitespaceParent = node => {
- node = node.parent;
- while (isNonNullable(node)) {
- if (node.name in whitespaceElements) {
- return true;
- } else {
- node = node.parent;
- }
- }
- return false;
- };
- const isTextRootBlockEmpty = node => {
- let tempNode = node;
- while (isNonNullable(tempNode)) {
- if (tempNode.name in textRootBlockElements) {
- return isEmpty(schema, nonEmptyElements, whitespaceElements, tempNode);
- } else {
- tempNode = tempNode.parent;
- }
- }
- return false;
- };
- const isAtEdgeOfBlock = (node, start) => {
- const neighbour = start ? node.prev : node.next;
- if (isNonNullable(neighbour)) {
- return false;
- }
- return node.parent.name in blockElements && (node.parent !== root || args.isRootContent);
- };
- const preprocess = node => {
- if (node.type === 3) {
- if (!hasWhitespaceParent(node)) {
- let text = node.value;
- text = text.replace(allWhiteSpaceRegExp, ' ');
- if (isLineBreakNode(node.prev, blockElements) || isAtEdgeOfBlock(node, true)) {
- text = text.replace(startWhiteSpaceRegExp, '');
- }
- if (text.length === 0) {
- node.remove();
- } else {
- node.value = text;
- }
- }
- }
- };
- const postprocess = node => {
- var _a;
- if (node.type === 1) {
- const elementRule = schema.getElementRule(node.name);
- if (validate && elementRule) {
- const isNodeEmpty = isEmpty(schema, nonEmptyElements, whitespaceElements, node);
- if (elementRule.paddInEmptyBlock && isNodeEmpty && isTextRootBlockEmpty(node)) {
- paddEmptyNode(settings, args, blockElements, node);
- } else if (elementRule.removeEmpty && isNodeEmpty) {
- if (blockElements[node.name]) {
- node.remove();
- } else {
- node.unwrap();
- }
- } else if (elementRule.paddEmpty && (isNodeEmpty || isPaddedWithNbsp(node))) {
- paddEmptyNode(settings, args, blockElements, node);
- }
- }
- } else if (node.type === 3) {
- if (!hasWhitespaceParent(node)) {
- let text = node.value;
- if (blockElements[(_a = node.next) === null || _a === void 0 ? void 0 : _a.name] || isAtEdgeOfBlock(node, false)) {
- text = text.replace(endWhiteSpaceRegExp, '');
- }
- if (text.length === 0) {
- node.remove();
- } else {
- node.value = text;
- }
- }
- }
- };
- return [
- preprocess,
- postprocess
- ];
- };
- const getRootBlockName = (settings, args) => {
- var _a;
- const name = (_a = args.forced_root_block) !== null && _a !== void 0 ? _a : settings.forced_root_block;
- if (name === false) {
- return '';
- } else if (name === true) {
- return 'p';
- } else {
- return name;
- }
- };
- const DomParser = (settings = {}, schema = Schema()) => {
- const nodeFilterRegistry = create$7();
- const attributeFilterRegistry = create$7();
- const defaultedSettings = {
- validate: true,
- root_name: 'body',
- ...settings
- };
- const parser = new DOMParser();
- const purify = setupPurify(defaultedSettings, schema);
- const parseAndSanitizeWithContext = (html, rootName, format = 'html') => {
- const mimeType = format === 'xhtml' ? 'application/xhtml+xml' : 'text/html';
- const isSpecialRoot = has$2(schema.getSpecialElements(), rootName.toLowerCase());
- const content = isSpecialRoot ? `<${ rootName }>${ html }</${ rootName }>` : html;
- const wrappedHtml = format === 'xhtml' ? `<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>${ content }</body></html>` : `<body>${ content }</body>`;
- const body = parser.parseFromString(wrappedHtml, mimeType).body;
- purify.sanitize(body, getPurifyConfig(defaultedSettings, mimeType));
- purify.removed = [];
- return isSpecialRoot ? body.firstChild : body;
- };
- const addNodeFilter = nodeFilterRegistry.addFilter;
- const getNodeFilters = nodeFilterRegistry.getFilters;
- const removeNodeFilter = nodeFilterRegistry.removeFilter;
- const addAttributeFilter = attributeFilterRegistry.addFilter;
- const getAttributeFilters = attributeFilterRegistry.getFilters;
- const removeAttributeFilter = attributeFilterRegistry.removeFilter;
- const findInvalidChildren = (node, invalidChildren) => {
- const parent = node.parent;
- if (parent && schema.children[node.name] && !schema.isValidChild(parent.name, node.name)) {
- invalidChildren.push(node);
- }
- };
- const addRootBlocks = (rootNode, rootBlockName) => {
- const blockElements = extend$1(makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
- const startWhiteSpaceRegExp = /^[ \t\r\n]+/;
- const endWhiteSpaceRegExp = /[ \t\r\n]+$/;
- let node = rootNode.firstChild, rootBlockNode = null;
- const trim = rootBlock => {
- if (rootBlock) {
- node = rootBlock.firstChild;
- if (node && node.type === 3) {
- node.value = node.value.replace(startWhiteSpaceRegExp, '');
- }
- node = rootBlock.lastChild;
- if (node && node.type === 3) {
- node.value = node.value.replace(endWhiteSpaceRegExp, '');
- }
- }
- };
- if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
- return;
- }
- while (node) {
- const next = node.next;
- if (node.type === 3 || node.type === 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr(internalElementAttr)) {
- if (!rootBlockNode) {
- rootBlockNode = new AstNode(rootBlockName, 1);
- rootBlockNode.attr(defaultedSettings.forced_root_block_attrs);
- rootNode.insert(rootBlockNode, node);
- rootBlockNode.append(node);
- } else {
- rootBlockNode.append(node);
- }
- } else {
- trim(rootBlockNode);
- rootBlockNode = null;
- }
- node = next;
- }
- trim(rootBlockNode);
- };
- const parse = (html, args = {}) => {
- var _a;
- const validate = defaultedSettings.validate;
- const rootName = (_a = args.context) !== null && _a !== void 0 ? _a : defaultedSettings.root_name;
- const element = parseAndSanitizeWithContext(html, rootName, args.format);
- const rootNode = new AstNode(rootName, 11);
- transferChildren(rootNode, element, schema.getSpecialElements());
- const [whitespacePre, whitespacePost] = whitespaceCleaner(rootNode, schema, defaultedSettings, args);
- const invalidChildren = [];
- const invalidFinder = validate ? node => findInvalidChildren(node, invalidChildren) : noop;
- const matches = {
- nodes: {},
- attributes: {}
- };
- const matchFinder = node => matchNode$1(getNodeFilters(), getAttributeFilters(), node, matches);
- walkTree(rootNode, [
- whitespacePre,
- matchFinder
- ], [
- whitespacePost,
- invalidFinder
- ]);
- invalidChildren.reverse();
- if (validate && invalidChildren.length > 0) {
- if (args.context) {
- const {
- pass: topLevelChildren,
- fail: otherChildren
- } = partition$2(invalidChildren, child => child.parent === rootNode);
- cleanInvalidNodes(otherChildren, schema, matchFinder);
- args.invalid = topLevelChildren.length > 0;
- } else {
- cleanInvalidNodes(invalidChildren, schema, matchFinder);
- }
- }
- const rootBlockName = getRootBlockName(defaultedSettings, args);
- if (rootBlockName && (rootNode.name === 'body' || args.isRootContent)) {
- addRootBlocks(rootNode, rootBlockName);
- }
- if (!args.invalid) {
- runFilters(matches, args);
- }
- return rootNode;
- };
- const exports = {
- schema,
- addAttributeFilter,
- getAttributeFilters,
- removeAttributeFilter,
- addNodeFilter,
- getNodeFilters,
- removeNodeFilter,
- parse
- };
- register$4(exports, defaultedSettings);
- register$5(exports, defaultedSettings, schema);
- return exports;
- };
- const serializeContent = content => isTreeNode(content) ? HtmlSerializer({ validate: false }).serialize(content) : content;
- const withSerializedContent = (content, fireEvent) => {
- const serializedContent = serializeContent(content);
- const eventArgs = fireEvent(serializedContent);
- if (eventArgs.isDefaultPrevented()) {
- return eventArgs;
- } else if (isTreeNode(content)) {
- if (eventArgs.content !== serializedContent) {
- const rootNode = DomParser({
- validate: false,
- forced_root_block: false
- }).parse(eventArgs.content, { context: content.name });
- return {
- ...eventArgs,
- content: rootNode
- };
- } else {
- return {
- ...eventArgs,
- content
- };
- }
- } else {
- return eventArgs;
- }
- };
- const preProcessGetContent = (editor, args) => {
- if (args.no_events) {
- return Result.value(args);
- } else {
- const eventArgs = fireBeforeGetContent(editor, args);
- if (eventArgs.isDefaultPrevented()) {
- return Result.error(fireGetContent(editor, {
- content: '',
- ...eventArgs
- }).content);
- } else {
- return Result.value(eventArgs);
- }
- }
- };
- const postProcessGetContent = (editor, content, args) => {
- if (args.no_events) {
- return content;
- } else {
- const processedEventArgs = withSerializedContent(content, c => fireGetContent(editor, {
- ...args,
- content: c
- }));
- return processedEventArgs.content;
- }
- };
- const preProcessSetContent = (editor, args) => {
- if (args.no_events) {
- return Result.value(args);
- } else {
- const processedEventArgs = withSerializedContent(args.content, content => fireBeforeSetContent(editor, {
- ...args,
- content
- }));
- if (processedEventArgs.isDefaultPrevented()) {
- fireSetContent(editor, processedEventArgs);
- return Result.error(undefined);
- } else {
- return Result.value(processedEventArgs);
- }
- }
- };
- const postProcessSetContent = (editor, content, args) => {
- if (!args.no_events) {
- fireSetContent(editor, {
- ...args,
- content
- });
- }
- };
- const tableModel = (element, width, rows) => ({
- element,
- width,
- rows
- });
- const tableRow = (element, cells) => ({
- element,
- cells
- });
- const cellPosition = (x, y) => ({
- x,
- y
- });
- const getSpan = (td, key) => {
- const value = parseInt(get$9(td, key), 10);
- return isNaN(value) ? 1 : value;
- };
- const fillout = (table, x, y, tr, td) => {
- const rowspan = getSpan(td, 'rowspan');
- const colspan = getSpan(td, 'colspan');
- const rows = table.rows;
- for (let y2 = y; y2 < y + rowspan; y2++) {
- if (!rows[y2]) {
- rows[y2] = tableRow(deep$1(tr), []);
- }
- for (let x2 = x; x2 < x + colspan; x2++) {
- const cells = rows[y2].cells;
- cells[x2] = y2 === y && x2 === x ? td : shallow$1(td);
- }
- }
- };
- const cellExists = (table, x, y) => {
- const rows = table.rows;
- const cells = rows[y] ? rows[y].cells : [];
- return !!cells[x];
- };
- const skipCellsX = (table, x, y) => {
- while (cellExists(table, x, y)) {
- x++;
- }
- return x;
- };
- const getWidth = rows => {
- return foldl(rows, (acc, row) => {
- return row.cells.length > acc ? row.cells.length : acc;
- }, 0);
- };
- const findElementPos = (table, element) => {
- const rows = table.rows;
- for (let y = 0; y < rows.length; y++) {
- const cells = rows[y].cells;
- for (let x = 0; x < cells.length; x++) {
- if (eq(cells[x], element)) {
- return Optional.some(cellPosition(x, y));
- }
- }
- }
- return Optional.none();
- };
- const extractRows = (table, sx, sy, ex, ey) => {
- const newRows = [];
- const rows = table.rows;
- for (let y = sy; y <= ey; y++) {
- const cells = rows[y].cells;
- const slice = sx < ex ? cells.slice(sx, ex + 1) : cells.slice(ex, sx + 1);
- newRows.push(tableRow(rows[y].element, slice));
- }
- return newRows;
- };
- const subTable = (table, startPos, endPos) => {
- const sx = startPos.x, sy = startPos.y;
- const ex = endPos.x, ey = endPos.y;
- const newRows = sy < ey ? extractRows(table, sx, sy, ex, ey) : extractRows(table, sx, ey, ex, sy);
- return tableModel(table.element, getWidth(newRows), newRows);
- };
- const createDomTable = (table, rows) => {
- const tableElement = shallow$1(table.element);
- const tableBody = SugarElement.fromTag('tbody');
- append(tableBody, rows);
- append$1(tableElement, tableBody);
- return tableElement;
- };
- const modelRowsToDomRows = table => {
- return map$3(table.rows, row => {
- const cells = map$3(row.cells, cell => {
- const td = deep$1(cell);
- remove$b(td, 'colspan');
- remove$b(td, 'rowspan');
- return td;
- });
- const tr = shallow$1(row.element);
- append(tr, cells);
- return tr;
- });
- };
- const fromDom = tableElm => {
- const table = tableModel(shallow$1(tableElm), 0, []);
- each$f(descendants(tableElm, 'tr'), (tr, y) => {
- each$f(descendants(tr, 'td,th'), (td, x) => {
- fillout(table, skipCellsX(table, x, y), y, tr, td);
- });
- });
- return tableModel(table.element, getWidth(table.rows), table.rows);
- };
- const toDom = table => {
- return createDomTable(table, modelRowsToDomRows(table));
- };
- const subsection = (table, startElement, endElement) => {
- return findElementPos(table, startElement).bind(startPos => {
- return findElementPos(table, endElement).map(endPos => {
- return subTable(table, startPos, endPos);
- });
- });
- };
- const findParentListContainer = parents => find$2(parents, elm => name(elm) === 'ul' || name(elm) === 'ol');
- const getFullySelectedListWrappers = (parents, rng) => find$2(parents, elm => name(elm) === 'li' && hasAllContentsSelected(elm, rng)).fold(constant([]), _li => findParentListContainer(parents).map(listCont => {
- const listElm = SugarElement.fromTag(name(listCont));
- const listStyles = filter$5(getAllRaw(listCont), (_style, name) => startsWith(name, 'list-style'));
- setAll(listElm, listStyles);
- return [
- SugarElement.fromTag('li'),
- listElm
- ];
- }).getOr([]));
- const wrap = (innerElm, elms) => {
- const wrapped = foldl(elms, (acc, elm) => {
- append$1(elm, acc);
- return elm;
- }, innerElm);
- return elms.length > 0 ? fromElements([wrapped]) : wrapped;
- };
- const directListWrappers = commonAnchorContainer => {
- if (isListItem(commonAnchorContainer)) {
- return parent(commonAnchorContainer).filter(isList).fold(constant([]), listElm => [
- commonAnchorContainer,
- listElm
- ]);
- } else {
- return isList(commonAnchorContainer) ? [commonAnchorContainer] : [];
- }
- };
- const getWrapElements = (rootNode, rng) => {
- const commonAnchorContainer = SugarElement.fromDom(rng.commonAncestorContainer);
- const parents = parentsAndSelf(commonAnchorContainer, rootNode);
- const wrapElements = filter$6(parents, isWrapElement);
- const listWrappers = getFullySelectedListWrappers(parents, rng);
- const allWrappers = wrapElements.concat(listWrappers.length ? listWrappers : directListWrappers(commonAnchorContainer));
- return map$3(allWrappers, shallow$1);
- };
- const emptyFragment = () => fromElements([]);
- const getFragmentFromRange = (rootNode, rng) => wrap(SugarElement.fromDom(rng.cloneContents()), getWrapElements(rootNode, rng));
- const getParentTable = (rootElm, cell) => ancestor$2(cell, 'table', curry(eq, rootElm));
- const getTableFragment = (rootNode, selectedTableCells) => getParentTable(rootNode, selectedTableCells[0]).bind(tableElm => {
- const firstCell = selectedTableCells[0];
- const lastCell = selectedTableCells[selectedTableCells.length - 1];
- const fullTableModel = fromDom(tableElm);
- return subsection(fullTableModel, firstCell, lastCell).map(sectionedTableModel => fromElements([toDom(sectionedTableModel)]));
- }).getOrThunk(emptyFragment);
- const getSelectionFragment = (rootNode, ranges) => ranges.length > 0 && ranges[0].collapsed ? emptyFragment() : getFragmentFromRange(rootNode, ranges[0]);
- const read$3 = (rootNode, ranges) => {
- const selectedCells = getCellsFromElementOrRanges(ranges, rootNode);
- return selectedCells.length > 0 ? getTableFragment(rootNode, selectedCells) : getSelectionFragment(rootNode, ranges);
- };
- const isCollapsibleWhitespace = (text, index) => index >= 0 && index < text.length && isWhiteSpace(text.charAt(index));
- const getInnerText = bin => {
- return trim$1(bin.innerText);
- };
- const getContextNodeName = parentBlockOpt => parentBlockOpt.map(block => block.nodeName).getOr('div').toLowerCase();
- const getTextContent = editor => Optional.from(editor.selection.getRng()).map(rng => {
- const parentBlockOpt = Optional.from(editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock));
- const body = editor.getBody();
- const contextNodeName = getContextNodeName(parentBlockOpt);
- const bin = editor.dom.add(body, contextNodeName, {
- 'data-mce-bogus': 'all',
- 'style': 'overflow: hidden; opacity: 0;'
- }, rng.cloneContents());
- const text = getInnerText(bin);
- const nonRenderedText = trim$1(bin.textContent);
- editor.dom.remove(bin);
- if (isCollapsibleWhitespace(nonRenderedText, 0) || isCollapsibleWhitespace(nonRenderedText, nonRenderedText.length - 1)) {
- const parentBlock = parentBlockOpt.getOr(body);
- const parentBlockText = getInnerText(parentBlock);
- const textIndex = parentBlockText.indexOf(text);
- if (textIndex === -1) {
- return text;
- } else {
- const hasProceedingSpace = isCollapsibleWhitespace(parentBlockText, textIndex - 1);
- const hasTrailingSpace = isCollapsibleWhitespace(parentBlockText, textIndex + text.length);
- return (hasProceedingSpace ? ' ' : '') + text + (hasTrailingSpace ? ' ' : '');
- }
- } else {
- return text;
- }
- }).getOr('');
- const getSerializedContent = (editor, args) => {
- const rng = editor.selection.getRng(), tmpElm = editor.dom.create('body');
- const sel = editor.selection.getSel();
- const ranges = processRanges(editor, getRanges$1(sel));
- const fragment = args.contextual ? read$3(SugarElement.fromDom(editor.getBody()), ranges).dom : rng.cloneContents();
- if (fragment) {
- tmpElm.appendChild(fragment);
- }
- return editor.selection.serializer.serialize(tmpElm, args);
- };
- const extractSelectedContent = (editor, args) => {
- if (args.format === 'text') {
- return getTextContent(editor);
- } else {
- const content = getSerializedContent(editor, args);
- if (args.format === 'tree') {
- return content;
- } else {
- return editor.selection.isCollapsed() ? '' : content;
- }
- }
- };
- const setupArgs$3 = (args, format) => ({
- ...args,
- format,
- get: true,
- selection: true,
- getInner: true
- });
- const getSelectedContentInternal = (editor, format, args = {}) => {
- const defaultedArgs = setupArgs$3(args, format);
- return preProcessGetContent(editor, defaultedArgs).fold(identity, updatedArgs => {
- const content = extractSelectedContent(editor, updatedArgs);
- return postProcessGetContent(editor, content, updatedArgs);
- });
- };
- const KEEP = 0, INSERT = 1, DELETE = 2;
- const diff = (left, right) => {
- const size = left.length + right.length + 2;
- const vDown = new Array(size);
- const vUp = new Array(size);
- const snake = (start, end, diag) => {
- return {
- start,
- end,
- diag
- };
- };
- const buildScript = (start1, end1, start2, end2, script) => {
- const middle = getMiddleSnake(start1, end1, start2, end2);
- if (middle === null || middle.start === end1 && middle.diag === end1 - end2 || middle.end === start1 && middle.diag === start1 - start2) {
- let i = start1;
- let j = start2;
- while (i < end1 || j < end2) {
- if (i < end1 && j < end2 && left[i] === right[j]) {
- script.push([
- KEEP,
- left[i]
- ]);
- ++i;
- ++j;
- } else {
- if (end1 - start1 > end2 - start2) {
- script.push([
- DELETE,
- left[i]
- ]);
- ++i;
- } else {
- script.push([
- INSERT,
- right[j]
- ]);
- ++j;
- }
- }
- }
- } else {
- buildScript(start1, middle.start, start2, middle.start - middle.diag, script);
- for (let i2 = middle.start; i2 < middle.end; ++i2) {
- script.push([
- KEEP,
- left[i2]
- ]);
- }
- buildScript(middle.end, end1, middle.end - middle.diag, end2, script);
- }
- };
- const buildSnake = (start, diag, end1, end2) => {
- let end = start;
- while (end - diag < end2 && end < end1 && left[end] === right[end - diag]) {
- ++end;
- }
- return snake(start, end, diag);
- };
- const getMiddleSnake = (start1, end1, start2, end2) => {
- const m = end1 - start1;
- const n = end2 - start2;
- if (m === 0 || n === 0) {
- return null;
- }
- const delta = m - n;
- const sum = n + m;
- const offset = (sum % 2 === 0 ? sum : sum + 1) / 2;
- vDown[1 + offset] = start1;
- vUp[1 + offset] = end1 + 1;
- let d, k, i, x, y;
- for (d = 0; d <= offset; ++d) {
- for (k = -d; k <= d; k += 2) {
- i = k + offset;
- if (k === -d || k !== d && vDown[i - 1] < vDown[i + 1]) {
- vDown[i] = vDown[i + 1];
- } else {
- vDown[i] = vDown[i - 1] + 1;
- }
- x = vDown[i];
- y = x - start1 + start2 - k;
- while (x < end1 && y < end2 && left[x] === right[y]) {
- vDown[i] = ++x;
- ++y;
- }
- if (delta % 2 !== 0 && delta - d <= k && k <= delta + d) {
- if (vUp[i - delta] <= vDown[i]) {
- return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2);
- }
- }
- }
- for (k = delta - d; k <= delta + d; k += 2) {
- i = k + offset - delta;
- if (k === delta - d || k !== delta + d && vUp[i + 1] <= vUp[i - 1]) {
- vUp[i] = vUp[i + 1] - 1;
- } else {
- vUp[i] = vUp[i - 1];
- }
- x = vUp[i] - 1;
- y = x - start1 + start2 - k;
- while (x >= start1 && y >= start2 && left[x] === right[y]) {
- vUp[i] = x--;
- y--;
- }
- if (delta % 2 === 0 && -d <= k && k <= d) {
- if (vUp[i] <= vDown[i + delta]) {
- return buildSnake(vUp[i], k + start1 - start2, end1, end2);
- }
- }
- }
- }
- };
- const script = [];
- buildScript(0, left.length, 0, right.length, script);
- return script;
- };
- const getOuterHtml = elm => {
- if (isElement$6(elm)) {
- return elm.outerHTML;
- } else if (isText$9(elm)) {
- return Entities.encodeRaw(elm.data, false);
- } else if (isComment(elm)) {
- return '<!--' + elm.data + '-->';
- }
- return '';
- };
- const createFragment = html => {
- let node;
- const container = document.createElement('div');
- const frag = document.createDocumentFragment();
- if (html) {
- container.innerHTML = html;
- }
- while (node = container.firstChild) {
- frag.appendChild(node);
- }
- return frag;
- };
- const insertAt = (elm, html, index) => {
- const fragment = createFragment(html);
- if (elm.hasChildNodes() && index < elm.childNodes.length) {
- const target = elm.childNodes[index];
- target.parentNode.insertBefore(fragment, target);
- } else {
- elm.appendChild(fragment);
- }
- };
- const removeAt = (elm, index) => {
- if (elm.hasChildNodes() && index < elm.childNodes.length) {
- const target = elm.childNodes[index];
- target.parentNode.removeChild(target);
- }
- };
- const applyDiff = (diff, elm) => {
- let index = 0;
- each$f(diff, action => {
- if (action[0] === KEEP) {
- index++;
- } else if (action[0] === INSERT) {
- insertAt(elm, action[1], index);
- index++;
- } else if (action[0] === DELETE) {
- removeAt(elm, index);
- }
- });
- };
- const read$2 = elm => {
- return filter$6(map$3(from(elm.childNodes), getOuterHtml), item => {
- return item.length > 0;
- });
- };
- const write = (fragments, elm) => {
- const currentFragments = map$3(from(elm.childNodes), getOuterHtml);
- applyDiff(diff(currentFragments, fragments), elm);
- return elm;
- };
- const lazyTempDocument = cached(() => document.implementation.createHTMLDocument('undo'));
- const hasIframes = html => {
- return html.indexOf('</iframe>') !== -1;
- };
- const createFragmentedLevel = fragments => {
- return {
- type: 'fragmented',
- fragments,
- content: '',
- bookmark: null,
- beforeBookmark: null
- };
- };
- const createCompleteLevel = content => {
- return {
- type: 'complete',
- fragments: null,
- content,
- bookmark: null,
- beforeBookmark: null
- };
- };
- const createFromEditor = editor => {
- const fragments = read$2(editor.getBody());
- const trimmedFragments = bind$3(fragments, html => {
- const trimmed = trimInternal(editor.serializer, html);
- return trimmed.length > 0 ? [trimmed] : [];
- });
- const content = trimmedFragments.join('');
- return hasIframes(content) ? createFragmentedLevel(trimmedFragments) : createCompleteLevel(content);
- };
- const applyToEditor = (editor, level, before) => {
- const bookmark = before ? level.beforeBookmark : level.bookmark;
- if (level.type === 'fragmented') {
- write(level.fragments, editor.getBody());
- } else {
- editor.setContent(level.content, {
- format: 'raw',
- no_selection: isNonNullable(bookmark) && isPathBookmark(bookmark) ? !bookmark.isFakeCaret : true
- });
- }
- editor.selection.moveToBookmark(bookmark);
- };
- const getLevelContent = level => {
- return level.type === 'fragmented' ? level.fragments.join('') : level.content;
- };
- const getCleanLevelContent = level => {
- const elm = SugarElement.fromTag('body', lazyTempDocument());
- set(elm, getLevelContent(level));
- each$f(descendants(elm, '*[data-mce-bogus]'), unwrap);
- return get$6(elm);
- };
- const hasEqualContent = (level1, level2) => getLevelContent(level1) === getLevelContent(level2);
- const hasEqualCleanedContent = (level1, level2) => getCleanLevelContent(level1) === getCleanLevelContent(level2);
- const isEq$1 = (level1, level2) => {
- if (!level1 || !level2) {
- return false;
- } else if (hasEqualContent(level1, level2)) {
- return true;
- } else {
- return hasEqualCleanedContent(level1, level2);
- }
- };
- const isUnlocked = locks => locks.get() === 0;
- const setTyping = (undoManager, typing, locks) => {
- if (isUnlocked(locks)) {
- undoManager.typing = typing;
- }
- };
- const endTyping = (undoManager, locks) => {
- if (undoManager.typing) {
- setTyping(undoManager, false, locks);
- undoManager.add();
- }
- };
- const endTypingLevelIgnoreLocks = undoManager => {
- if (undoManager.typing) {
- undoManager.typing = false;
- undoManager.add();
- }
- };
- const beforeChange$1 = (editor, locks, beforeBookmark) => {
- if (isUnlocked(locks)) {
- beforeBookmark.set(getUndoBookmark(editor.selection));
- }
- };
- const addUndoLevel$1 = (editor, undoManager, index, locks, beforeBookmark, level, event) => {
- const currentLevel = createFromEditor(editor);
- level = level || {};
- level = Tools.extend(level, currentLevel);
- if (isUnlocked(locks) === false || editor.removed) {
- return null;
- }
- const lastLevel = undoManager.data[index.get()];
- if (editor.dispatch('BeforeAddUndo', {
- level,
- lastLevel,
- originalEvent: event
- }).isDefaultPrevented()) {
- return null;
- }
- if (lastLevel && isEq$1(lastLevel, level)) {
- return null;
- }
- if (undoManager.data[index.get()]) {
- beforeBookmark.get().each(bm => {
- undoManager.data[index.get()].beforeBookmark = bm;
- });
- }
- const customUndoRedoLevels = getCustomUndoRedoLevels(editor);
- if (customUndoRedoLevels) {
- if (undoManager.data.length > customUndoRedoLevels) {
- for (let i = 0; i < undoManager.data.length - 1; i++) {
- undoManager.data[i] = undoManager.data[i + 1];
- }
- undoManager.data.length--;
- index.set(undoManager.data.length);
- }
- }
- level.bookmark = getUndoBookmark(editor.selection);
- if (index.get() < undoManager.data.length - 1) {
- undoManager.data.length = index.get() + 1;
- }
- undoManager.data.push(level);
- index.set(undoManager.data.length - 1);
- const args = {
- level,
- lastLevel,
- originalEvent: event
- };
- if (index.get() > 0) {
- editor.setDirty(true);
- editor.dispatch('AddUndo', args);
- editor.dispatch('change', args);
- } else {
- editor.dispatch('AddUndo', args);
- }
- return level;
- };
- const clear$1 = (editor, undoManager, index) => {
- undoManager.data = [];
- index.set(0);
- undoManager.typing = false;
- editor.dispatch('ClearUndos');
- };
- const extra$1 = (editor, undoManager, index, callback1, callback2) => {
- if (undoManager.transact(callback1)) {
- const bookmark = undoManager.data[index.get()].bookmark;
- const lastLevel = undoManager.data[index.get() - 1];
- applyToEditor(editor, lastLevel, true);
- if (undoManager.transact(callback2)) {
- undoManager.data[index.get() - 1].beforeBookmark = bookmark;
- }
- }
- };
- const redo$1 = (editor, index, data) => {
- let level;
- if (index.get() < data.length - 1) {
- index.set(index.get() + 1);
- level = data[index.get()];
- applyToEditor(editor, level, false);
- editor.setDirty(true);
- editor.dispatch('Redo', { level });
- }
- return level;
- };
- const undo$1 = (editor, undoManager, locks, index) => {
- let level;
- if (undoManager.typing) {
- undoManager.add();
- undoManager.typing = false;
- setTyping(undoManager, false, locks);
- }
- if (index.get() > 0) {
- index.set(index.get() - 1);
- level = undoManager.data[index.get()];
- applyToEditor(editor, level, true);
- editor.setDirty(true);
- editor.dispatch('Undo', { level });
- }
- return level;
- };
- const reset$1 = undoManager => {
- undoManager.clear();
- undoManager.add();
- };
- const hasUndo$1 = (editor, undoManager, index) => index.get() > 0 || undoManager.typing && undoManager.data[0] && !isEq$1(createFromEditor(editor), undoManager.data[0]);
- const hasRedo$1 = (undoManager, index) => index.get() < undoManager.data.length - 1 && !undoManager.typing;
- const transact$1 = (undoManager, locks, callback) => {
- endTyping(undoManager, locks);
- undoManager.beforeChange();
- undoManager.ignore(callback);
- return undoManager.add();
- };
- const ignore$1 = (locks, callback) => {
- try {
- locks.set(locks.get() + 1);
- callback();
- } finally {
- locks.set(locks.get() - 1);
- }
- };
- const addVisualInternal = (editor, elm) => {
- const dom = editor.dom;
- const scope = isNonNullable(elm) ? elm : editor.getBody();
- if (isUndefined(editor.hasVisual)) {
- editor.hasVisual = isVisualAidsEnabled(editor);
- }
- each$f(dom.select('table,a', scope), matchedElm => {
- switch (matchedElm.nodeName) {
- case 'TABLE':
- const cls = getVisualAidsTableClass(editor);
- const value = dom.getAttrib(matchedElm, 'border');
- if ((!value || value === '0') && editor.hasVisual) {
- dom.addClass(matchedElm, cls);
- } else {
- dom.removeClass(matchedElm, cls);
- }
- break;
- case 'A':
- if (!dom.getAttrib(matchedElm, 'href')) {
- const value = dom.getAttrib(matchedElm, 'name') || matchedElm.id;
- const cls = getVisualAidsAnchorClass(editor);
- if (value && editor.hasVisual) {
- dom.addClass(matchedElm, cls);
- } else {
- dom.removeClass(matchedElm, cls);
- }
- }
- break;
- }
- });
- editor.dispatch('VisualAid', {
- element: elm,
- hasVisual: editor.hasVisual
- });
- };
- const makePlainAdaptor = editor => ({
- init: { bindEvents: noop },
- undoManager: {
- beforeChange: (locks, beforeBookmark) => beforeChange$1(editor, locks, beforeBookmark),
- add: (undoManager, index, locks, beforeBookmark, level, event) => addUndoLevel$1(editor, undoManager, index, locks, beforeBookmark, level, event),
- undo: (undoManager, locks, index) => undo$1(editor, undoManager, locks, index),
- redo: (index, data) => redo$1(editor, index, data),
- clear: (undoManager, index) => clear$1(editor, undoManager, index),
- reset: undoManager => reset$1(undoManager),
- hasUndo: (undoManager, index) => hasUndo$1(editor, undoManager, index),
- hasRedo: (undoManager, index) => hasRedo$1(undoManager, index),
- transact: (undoManager, locks, callback) => transact$1(undoManager, locks, callback),
- ignore: (locks, callback) => ignore$1(locks, callback),
- extra: (undoManager, index, callback1, callback2) => extra$1(editor, undoManager, index, callback1, callback2)
- },
- formatter: {
- match: (name, vars, node, similar) => match$2(editor, name, vars, node, similar),
- matchAll: (names, vars) => matchAll(editor, names, vars),
- matchNode: (node, name, vars, similar) => matchNode(editor, node, name, vars, similar),
- canApply: name => canApply(editor, name),
- closest: names => closest$1(editor, names),
- apply: (name, vars, node) => applyFormat$1(editor, name, vars, node),
- remove: (name, vars, node, similar) => remove$2(editor, name, vars, node, similar),
- toggle: (name, vars, node) => toggle(editor, name, vars, node),
- formatChanged: (registeredFormatListeners, formats, callback, similar, vars) => formatChangedInternal(editor, registeredFormatListeners, formats, callback, similar, vars)
- },
- editor: {
- getContent: args => getContentInternal(editor, args),
- setContent: (content, args) => setContentInternal(editor, content, args),
- insertContent: (value, details) => insertHtmlAtCaret(editor, value, details),
- addVisual: elm => addVisualInternal(editor, elm)
- },
- selection: { getContent: (format, args) => getSelectedContentInternal(editor, format, args) },
- autocompleter: {
- addDecoration: range => create$9(editor, range),
- removeDecoration: () => remove$3(editor, SugarElement.fromDom(editor.getBody()))
- },
- raw: { getModel: () => Optional.none() }
- });
- const makeRtcAdaptor = rtcEditor => {
- const defaultVars = vars => isObject(vars) ? vars : {};
- const {init, undoManager, formatter, editor, selection, autocompleter, raw} = rtcEditor;
- return {
- init: { bindEvents: init.bindEvents },
- undoManager: {
- beforeChange: undoManager.beforeChange,
- add: undoManager.add,
- undo: undoManager.undo,
- redo: undoManager.redo,
- clear: undoManager.clear,
- reset: undoManager.reset,
- hasUndo: undoManager.hasUndo,
- hasRedo: undoManager.hasRedo,
- transact: (_undoManager, _locks, fn) => undoManager.transact(fn),
- ignore: (_locks, callback) => undoManager.ignore(callback),
- extra: (_undoManager, _index, callback1, callback2) => undoManager.extra(callback1, callback2)
- },
- formatter: {
- match: (name, vars, _node, similar) => formatter.match(name, defaultVars(vars), similar),
- matchAll: formatter.matchAll,
- matchNode: formatter.matchNode,
- canApply: name => formatter.canApply(name),
- closest: names => formatter.closest(names),
- apply: (name, vars, _node) => formatter.apply(name, defaultVars(vars)),
- remove: (name, vars, _node, _similar) => formatter.remove(name, defaultVars(vars)),
- toggle: (name, vars, _node) => formatter.toggle(name, defaultVars(vars)),
- formatChanged: (_rfl, formats, callback, similar, vars) => formatter.formatChanged(formats, callback, similar, vars)
- },
- editor: {
- getContent: args => editor.getContent(args),
- setContent: (content, args) => {
- return {
- content: editor.setContent(content, args),
- html: ''
- };
- },
- insertContent: (content, _details) => {
- editor.insertContent(content);
- return '';
- },
- addVisual: editor.addVisual
- },
- selection: { getContent: (_format, args) => selection.getContent(args) },
- autocompleter: {
- addDecoration: autocompleter.addDecoration,
- removeDecoration: autocompleter.removeDecoration
- },
- raw: { getModel: () => Optional.some(raw.getRawModel()) }
- };
- };
- const makeNoopAdaptor = () => {
- const nul = constant(null);
- const empty = constant('');
- return {
- init: { bindEvents: noop },
- undoManager: {
- beforeChange: noop,
- add: nul,
- undo: nul,
- redo: nul,
- clear: noop,
- reset: noop,
- hasUndo: never,
- hasRedo: never,
- transact: nul,
- ignore: noop,
- extra: noop
- },
- formatter: {
- match: never,
- matchAll: constant([]),
- matchNode: constant(undefined),
- canApply: never,
- closest: empty,
- apply: noop,
- remove: noop,
- toggle: noop,
- formatChanged: constant({ unbind: noop })
- },
- editor: {
- getContent: empty,
- setContent: constant({
- content: '',
- html: ''
- }),
- insertContent: constant(''),
- addVisual: noop
- },
- selection: { getContent: empty },
- autocompleter: {
- addDecoration: noop,
- removeDecoration: noop
- },
- raw: { getModel: constant(Optional.none()) }
- };
- };
- const isRtc = editor => has$2(editor.plugins, 'rtc');
- const getRtcSetup = editor => get$a(editor.plugins, 'rtc').bind(rtcPlugin => Optional.from(rtcPlugin.setup));
- const setup$s = editor => {
- const editorCast = editor;
- return getRtcSetup(editor).fold(() => {
- editorCast.rtcInstance = makePlainAdaptor(editor);
- return Optional.none();
- }, setup => {
- editorCast.rtcInstance = makeNoopAdaptor();
- return Optional.some(() => setup().then(rtcEditor => {
- editorCast.rtcInstance = makeRtcAdaptor(rtcEditor);
- return rtcEditor.rtc.isRemote;
- }));
- });
- };
- const getRtcInstanceWithFallback = editor => editor.rtcInstance ? editor.rtcInstance : makePlainAdaptor(editor);
- const getRtcInstanceWithError = editor => {
- const rtcInstance = editor.rtcInstance;
- if (!rtcInstance) {
- throw new Error('Failed to get RTC instance not yet initialized.');
- } else {
- return rtcInstance;
- }
- };
- const beforeChange = (editor, locks, beforeBookmark) => {
- getRtcInstanceWithError(editor).undoManager.beforeChange(locks, beforeBookmark);
- };
- const addUndoLevel = (editor, undoManager, index, locks, beforeBookmark, level, event) => getRtcInstanceWithError(editor).undoManager.add(undoManager, index, locks, beforeBookmark, level, event);
- const undo = (editor, undoManager, locks, index) => getRtcInstanceWithError(editor).undoManager.undo(undoManager, locks, index);
- const redo = (editor, index, data) => getRtcInstanceWithError(editor).undoManager.redo(index, data);
- const clear = (editor, undoManager, index) => {
- getRtcInstanceWithError(editor).undoManager.clear(undoManager, index);
- };
- const reset = (editor, undoManager) => {
- getRtcInstanceWithError(editor).undoManager.reset(undoManager);
- };
- const hasUndo = (editor, undoManager, index) => getRtcInstanceWithError(editor).undoManager.hasUndo(undoManager, index);
- const hasRedo = (editor, undoManager, index) => getRtcInstanceWithError(editor).undoManager.hasRedo(undoManager, index);
- const transact = (editor, undoManager, locks, callback) => getRtcInstanceWithError(editor).undoManager.transact(undoManager, locks, callback);
- const ignore = (editor, locks, callback) => {
- getRtcInstanceWithError(editor).undoManager.ignore(locks, callback);
- };
- const extra = (editor, undoManager, index, callback1, callback2) => {
- getRtcInstanceWithError(editor).undoManager.extra(undoManager, index, callback1, callback2);
- };
- const matchFormat = (editor, name, vars, node, similar) => getRtcInstanceWithError(editor).formatter.match(name, vars, node, similar);
- const matchAllFormats = (editor, names, vars) => getRtcInstanceWithError(editor).formatter.matchAll(names, vars);
- const matchNodeFormat = (editor, node, name, vars, similar) => getRtcInstanceWithError(editor).formatter.matchNode(node, name, vars, similar);
- const canApplyFormat = (editor, name) => getRtcInstanceWithError(editor).formatter.canApply(name);
- const closestFormat = (editor, names) => getRtcInstanceWithError(editor).formatter.closest(names);
- const applyFormat = (editor, name, vars, node) => {
- getRtcInstanceWithError(editor).formatter.apply(name, vars, node);
- };
- const removeFormat = (editor, name, vars, node, similar) => {
- getRtcInstanceWithError(editor).formatter.remove(name, vars, node, similar);
- };
- const toggleFormat = (editor, name, vars, node) => {
- getRtcInstanceWithError(editor).formatter.toggle(name, vars, node);
- };
- const formatChanged = (editor, registeredFormatListeners, formats, callback, similar, vars) => getRtcInstanceWithError(editor).formatter.formatChanged(registeredFormatListeners, formats, callback, similar, vars);
- const getContent$2 = (editor, args) => getRtcInstanceWithFallback(editor).editor.getContent(args);
- const setContent$2 = (editor, content, args) => getRtcInstanceWithFallback(editor).editor.setContent(content, args);
- const insertContent$1 = (editor, value, details) => getRtcInstanceWithFallback(editor).editor.insertContent(value, details);
- const getSelectedContent = (editor, format, args) => getRtcInstanceWithError(editor).selection.getContent(format, args);
- const addVisual$1 = (editor, elm) => getRtcInstanceWithError(editor).editor.addVisual(elm);
- const bindEvents = editor => getRtcInstanceWithError(editor).init.bindEvents();
- const addAutocompleterDecoration = (editor, range) => getRtcInstanceWithError(editor).autocompleter.addDecoration(range);
- const removeAutocompleterDecoration = editor => getRtcInstanceWithError(editor).autocompleter.removeDecoration();
- const getContent$1 = (editor, args = {}) => {
- const format = args.format ? args.format : 'html';
- return getSelectedContent(editor, format, args);
- };
- const removeEmpty = text => {
- if (text.dom.length === 0) {
- remove$6(text);
- return Optional.none();
- } else {
- return Optional.some(text);
- }
- };
- const walkPastBookmark = (node, start) => node.filter(elm => BookmarkManager.isBookmarkNode(elm.dom)).bind(start ? nextSibling : prevSibling);
- const merge$1 = (outer, inner, rng, start) => {
- const outerElm = outer.dom;
- const innerElm = inner.dom;
- const oldLength = start ? outerElm.length : innerElm.length;
- if (start) {
- mergeTextNodes(outerElm, innerElm, false, !start);
- rng.setStart(innerElm, oldLength);
- } else {
- mergeTextNodes(innerElm, outerElm, false, !start);
- rng.setEnd(innerElm, oldLength);
- }
- };
- const normalizeTextIfRequired = (inner, start) => {
- parent(inner).each(root => {
- const text = inner.dom;
- if (start && needsToBeNbspLeft(root, CaretPosition(text, 0))) {
- normalizeWhitespaceAfter(text, 0);
- } else if (!start && needsToBeNbspRight(root, CaretPosition(text, text.length))) {
- normalizeWhitespaceBefore(text, text.length);
- }
- });
- };
- const mergeAndNormalizeText = (outerNode, innerNode, rng, start) => {
- outerNode.bind(outer => {
- const normalizer = start ? normalizeWhitespaceBefore : normalizeWhitespaceAfter;
- normalizer(outer.dom, start ? outer.dom.length : 0);
- return innerNode.filter(isText$a).map(inner => merge$1(outer, inner, rng, start));
- }).orThunk(() => {
- const innerTextNode = walkPastBookmark(innerNode, start).or(innerNode).filter(isText$a);
- return innerTextNode.map(inner => normalizeTextIfRequired(inner, start));
- });
- };
- const rngSetContent = (rng, fragment) => {
- const firstChild = Optional.from(fragment.firstChild).map(SugarElement.fromDom);
- const lastChild = Optional.from(fragment.lastChild).map(SugarElement.fromDom);
- rng.deleteContents();
- rng.insertNode(fragment);
- const prevText = firstChild.bind(prevSibling).filter(isText$a).bind(removeEmpty);
- const nextText = lastChild.bind(nextSibling).filter(isText$a).bind(removeEmpty);
- mergeAndNormalizeText(prevText, firstChild, rng, true);
- mergeAndNormalizeText(nextText, lastChild, rng, false);
- rng.collapse(false);
- };
- const setupArgs$2 = (args, content) => ({
- format: 'html',
- ...args,
- set: true,
- selection: true,
- content
- });
- const cleanContent = (editor, args) => {
- if (args.format !== 'raw') {
- const rng = editor.selection.getRng();
- const contextBlock = editor.dom.getParent(rng.commonAncestorContainer, editor.dom.isBlock);
- const contextArgs = contextBlock ? { context: contextBlock.nodeName.toLowerCase() } : {};
- const node = editor.parser.parse(args.content, {
- forced_root_block: false,
- ...contextArgs,
- ...args
- });
- return HtmlSerializer({ validate: false }, editor.schema).serialize(node);
- } else {
- return args.content;
- }
- };
- const setContent$1 = (editor, content, args = {}) => {
- const defaultedArgs = setupArgs$2(args, content);
- preProcessSetContent(editor, defaultedArgs).each(updatedArgs => {
- const cleanedContent = cleanContent(editor, updatedArgs);
- const rng = editor.selection.getRng();
- rngSetContent(rng, rng.createContextualFragment(cleanedContent));
- editor.selection.setRng(rng);
- scrollRangeIntoView(editor, rng);
- postProcessSetContent(editor, cleanedContent, updatedArgs);
- });
- };
- const deleteFromCallbackMap = (callbackMap, selector, callback) => {
- if (callbackMap && has$2(callbackMap, selector)) {
- const newCallbacks = filter$6(callbackMap[selector], cb => cb !== callback);
- if (newCallbacks.length === 0) {
- delete callbackMap[selector];
- } else {
- callbackMap[selector] = newCallbacks;
- }
- }
- };
- var SelectorChanged = (dom, editor) => {
- let selectorChangedData;
- let currentSelectors;
- const findMatchingNode = (selector, nodes) => find$2(nodes, node => dom.is(node, selector));
- const getParents = elem => dom.getParents(elem, null, dom.getRoot());
- return {
- selectorChangedWithUnbind: (selector, callback) => {
- if (!selectorChangedData) {
- selectorChangedData = {};
- currentSelectors = {};
- editor.on('NodeChange', e => {
- const node = e.element;
- const parents = getParents(node);
- const matchedSelectors = {};
- Tools.each(selectorChangedData, (callbacks, selector) => {
- findMatchingNode(selector, parents).each(node => {
- if (!currentSelectors[selector]) {
- each$f(callbacks, callback => {
- callback(true, {
- node,
- selector,
- parents
- });
- });
- currentSelectors[selector] = callbacks;
- }
- matchedSelectors[selector] = callbacks;
- });
- });
- Tools.each(currentSelectors, (callbacks, selector) => {
- if (!matchedSelectors[selector]) {
- delete currentSelectors[selector];
- Tools.each(callbacks, callback => {
- callback(false, {
- node,
- selector,
- parents
- });
- });
- }
- });
- });
- }
- if (!selectorChangedData[selector]) {
- selectorChangedData[selector] = [];
- }
- selectorChangedData[selector].push(callback);
- findMatchingNode(selector, getParents(editor.selection.getStart())).each(() => {
- currentSelectors[selector] = selectorChangedData[selector];
- });
- return {
- unbind: () => {
- deleteFromCallbackMap(selectorChangedData, selector, callback);
- deleteFromCallbackMap(currentSelectors, selector, callback);
- }
- };
- }
- };
- };
- const isAttachedToDom = node => {
- return !!(node && node.ownerDocument) && contains(SugarElement.fromDom(node.ownerDocument), SugarElement.fromDom(node));
- };
- const isValidRange = rng => {
- if (!rng) {
- return false;
- } else {
- return isAttachedToDom(rng.startContainer) && isAttachedToDom(rng.endContainer);
- }
- };
- const EditorSelection = (dom, win, serializer, editor) => {
- let selectedRange;
- let explicitRange;
- const {selectorChangedWithUnbind} = SelectorChanged(dom, editor);
- const setCursorLocation = (node, offset) => {
- const rng = dom.createRng();
- if (isNonNullable(node) && isNonNullable(offset)) {
- rng.setStart(node, offset);
- rng.setEnd(node, offset);
- setRng(rng);
- collapse(false);
- } else {
- moveEndPoint(dom, rng, editor.getBody(), true);
- setRng(rng);
- }
- };
- const getContent = args => getContent$1(editor, args);
- const setContent = (content, args) => setContent$1(editor, content, args);
- const getStart$1 = real => getStart(editor.getBody(), getRng$1(), real);
- const getEnd = real => getEnd$1(editor.getBody(), getRng$1(), real);
- const getBookmark = (type, normalized) => bookmarkManager.getBookmark(type, normalized);
- const moveToBookmark = bookmark => bookmarkManager.moveToBookmark(bookmark);
- const select$1 = (node, content) => {
- select(dom, node, content).each(setRng);
- return node;
- };
- const isCollapsed = () => {
- const rng = getRng$1(), sel = getSel();
- if (!rng || rng.item) {
- return false;
- }
- if (rng.compareEndPoints) {
- return rng.compareEndPoints('StartToEnd', rng) === 0;
- }
- return !sel || rng.collapsed;
- };
- const collapse = toStart => {
- const rng = getRng$1();
- rng.collapse(!!toStart);
- setRng(rng);
- };
- const getSel = () => win.getSelection ? win.getSelection() : win.document.selection;
- const getRng$1 = () => {
- let selection, rng, elm;
- const tryCompareBoundaryPoints = (how, sourceRange, destinationRange) => {
- try {
- return sourceRange.compareBoundaryPoints(how, destinationRange);
- } catch (ex) {
- return -1;
- }
- };
- const doc = win.document;
- if (editor.bookmark !== undefined && hasFocus(editor) === false) {
- const bookmark = getRng(editor);
- if (bookmark.isSome()) {
- return bookmark.map(r => processRanges(editor, [r])[0]).getOr(doc.createRange());
- }
- }
- try {
- if ((selection = getSel()) && !isRestrictedNode(selection.anchorNode)) {
- if (selection.rangeCount > 0) {
- rng = selection.getRangeAt(0);
- } else {
- rng = selection.createRange ? selection.createRange() : doc.createRange();
- }
- rng = processRanges(editor, [rng])[0];
- }
- } catch (ex) {
- }
- if (!rng) {
- rng = doc.createRange();
- }
- if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
- elm = dom.getRoot();
- rng.setStart(elm, 0);
- rng.setEnd(elm, 0);
- }
- if (selectedRange && explicitRange) {
- if (tryCompareBoundaryPoints(rng.START_TO_START, rng, selectedRange) === 0 && tryCompareBoundaryPoints(rng.END_TO_END, rng, selectedRange) === 0) {
- rng = explicitRange;
- } else {
- selectedRange = null;
- explicitRange = null;
- }
- }
- return rng;
- };
- const setRng = (rng, forward) => {
- let node;
- if (!isValidRange(rng)) {
- return;
- }
- const sel = getSel();
- const evt = editor.dispatch('SetSelectionRange', {
- range: rng,
- forward
- });
- rng = evt.range;
- if (sel) {
- explicitRange = rng;
- try {
- sel.removeAllRanges();
- sel.addRange(rng);
- } catch (ex) {
- }
- if (forward === false && sel.extend) {
- sel.collapse(rng.endContainer, rng.endOffset);
- sel.extend(rng.startContainer, rng.startOffset);
- }
- selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
- }
- if (!rng.collapsed && rng.startContainer === rng.endContainer && sel.setBaseAndExtent) {
- if (rng.endOffset - rng.startOffset < 2) {
- if (rng.startContainer.hasChildNodes()) {
- node = rng.startContainer.childNodes[rng.startOffset];
- if (node && node.tagName === 'IMG') {
- sel.setBaseAndExtent(rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset);
- if (sel.anchorNode !== rng.startContainer || sel.focusNode !== rng.endContainer) {
- sel.setBaseAndExtent(node, 0, node, 1);
- }
- }
- }
- }
- }
- editor.dispatch('AfterSetSelectionRange', {
- range: rng,
- forward
- });
- };
- const setNode = elm => {
- setContent(dom.getOuterHTML(elm));
- return elm;
- };
- const getNode$1 = () => getNode(editor.getBody(), getRng$1());
- const getSelectedBlocks$1 = (startElm, endElm) => getSelectedBlocks(dom, getRng$1(), startElm, endElm);
- const isForward = () => {
- const sel = getSel();
- const anchorNode = sel === null || sel === void 0 ? void 0 : sel.anchorNode;
- const focusNode = sel === null || sel === void 0 ? void 0 : sel.focusNode;
- if (!sel || !anchorNode || !focusNode || isRestrictedNode(anchorNode) || isRestrictedNode(focusNode)) {
- return true;
- }
- const anchorRange = dom.createRng();
- const focusRange = dom.createRng();
- try {
- anchorRange.setStart(anchorNode, sel.anchorOffset);
- anchorRange.collapse(true);
- focusRange.setStart(focusNode, sel.focusOffset);
- focusRange.collapse(true);
- } catch (e) {
- return true;
- }
- return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
- };
- const normalize = () => {
- const rng = getRng$1();
- const sel = getSel();
- if (!hasMultipleRanges(sel) && hasAnyRanges(editor)) {
- const normRng = normalize$2(dom, rng);
- normRng.each(normRng => {
- setRng(normRng, isForward());
- });
- return normRng.getOr(rng);
- }
- return rng;
- };
- const selectorChanged = (selector, callback) => {
- selectorChangedWithUnbind(selector, callback);
- return exports;
- };
- const getScrollContainer = () => {
- let scrollContainer;
- let node = dom.getRoot();
- while (node && node.nodeName !== 'BODY') {
- if (node.scrollHeight > node.clientHeight) {
- scrollContainer = node;
- break;
- }
- node = node.parentNode;
- }
- return scrollContainer;
- };
- const scrollIntoView = (elm, alignToTop) => {
- if (isNonNullable(elm)) {
- scrollElementIntoView(editor, elm, alignToTop);
- } else {
- scrollRangeIntoView(editor, getRng$1(), alignToTop);
- }
- };
- const placeCaretAt = (clientX, clientY) => setRng(fromPoint(clientX, clientY, editor.getDoc()));
- const getBoundingClientRect = () => {
- const rng = getRng$1();
- return rng.collapsed ? CaretPosition.fromRangeStart(rng).getClientRects()[0] : rng.getBoundingClientRect();
- };
- const destroy = () => {
- win = selectedRange = explicitRange = null;
- controlSelection.destroy();
- };
- const exports = {
- bookmarkManager: null,
- controlSelection: null,
- dom,
- win,
- serializer,
- editor,
- collapse,
- setCursorLocation,
- getContent,
- setContent,
- getBookmark,
- moveToBookmark,
- select: select$1,
- isCollapsed,
- isForward,
- setNode,
- getNode: getNode$1,
- getSel,
- setRng,
- getRng: getRng$1,
- getStart: getStart$1,
- getEnd,
- getSelectedBlocks: getSelectedBlocks$1,
- normalize,
- selectorChanged,
- selectorChangedWithUnbind,
- getScrollContainer,
- scrollIntoView,
- placeCaretAt,
- getBoundingClientRect,
- destroy
- };
- const bookmarkManager = BookmarkManager(exports);
- const controlSelection = ControlSelection(exports, editor);
- exports.bookmarkManager = bookmarkManager;
- exports.controlSelection = controlSelection;
- return exports;
- };
- const register$3 = (htmlParser, settings, dom) => {
- htmlParser.addAttributeFilter('data-mce-tabindex', (nodes, name) => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- node.attr('tabindex', node.attr('data-mce-tabindex'));
- node.attr(name, null);
- }
- });
- htmlParser.addAttributeFilter('src,href,style', (nodes, name) => {
- const internalName = 'data-mce-' + name;
- const urlConverter = settings.url_converter;
- const urlConverterScope = settings.url_converter_scope;
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- let value = node.attr(internalName);
- if (value !== undefined) {
- node.attr(name, value.length > 0 ? value : null);
- node.attr(internalName, null);
- } else {
- value = node.attr(name);
- if (name === 'style') {
- value = dom.serializeStyle(dom.parseStyle(value), node.name);
- } else if (urlConverter) {
- value = urlConverter.call(urlConverterScope, value, name, node.name);
- }
- node.attr(name, value.length > 0 ? value : null);
- }
- }
- });
- htmlParser.addAttributeFilter('class', nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- let value = node.attr('class');
- if (value) {
- value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, '');
- node.attr('class', value.length > 0 ? value : null);
- }
- }
- });
- htmlParser.addAttributeFilter('data-mce-type', (nodes, name, args) => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- if (node.attr('data-mce-type') === 'bookmark' && !args.cleanup) {
- const hasChildren = Optional.from(node.firstChild).exists(firstChild => !isZwsp(firstChild.value));
- if (hasChildren) {
- node.unwrap();
- } else {
- node.remove();
- }
- }
- }
- });
- htmlParser.addNodeFilter('noscript', nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i].firstChild;
- if (node) {
- node.value = Entities.decode(node.value);
- }
- }
- });
- htmlParser.addNodeFilter('script,style', (nodes, name) => {
- const trim = value => {
- return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n').replace(/^[\r\n]*|[\r\n]*$/g, '').replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '').replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
- };
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- const value = node.firstChild ? node.firstChild.value : '';
- if (name === 'script') {
- const type = node.attr('type');
- if (type) {
- node.attr('type', type === 'mce-no/type' ? null : type.replace(/^mce\-/, ''));
- }
- if (settings.element_format === 'xhtml' && value.length > 0) {
- node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
- }
- } else {
- if (settings.element_format === 'xhtml' && value.length > 0) {
- node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
- }
- }
- }
- });
- htmlParser.addNodeFilter('#comment', nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- if (settings.preserve_cdata && node.value.indexOf('[CDATA[') === 0) {
- node.name = '#cdata';
- node.type = 4;
- node.value = dom.decode(node.value.replace(/^\[CDATA\[|\]\]$/g, ''));
- } else if (node.value.indexOf('mce:protected ') === 0) {
- node.name = '#text';
- node.type = 3;
- node.raw = true;
- node.value = unescape(node.value).substr(14);
- }
- }
- });
- htmlParser.addNodeFilter('xml:namespace,input', (nodes, name) => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- if (node.type === 7) {
- node.remove();
- } else if (node.type === 1) {
- if (name === 'input' && !node.attr('type')) {
- node.attr('type', 'text');
- }
- }
- }
- });
- htmlParser.addAttributeFilter('data-mce-type', nodes => {
- each$f(nodes, node => {
- if (node.attr('data-mce-type') === 'format-caret') {
- if (node.isEmpty(htmlParser.schema.getNonEmptyElements())) {
- node.remove();
- } else {
- node.unwrap();
- }
- }
- });
- });
- htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style,' + 'data-mce-selected,data-mce-expando,' + 'data-mce-type,data-mce-resize,data-mce-placeholder', (nodes, name) => {
- let i = nodes.length;
- while (i--) {
- nodes[i].attr(name, null);
- }
- });
- };
- const trimTrailingBr = rootNode => {
- const isBr = node => {
- return node && node.name === 'br';
- };
- const brNode1 = rootNode.lastChild;
- if (isBr(brNode1)) {
- const brNode2 = brNode1.prev;
- if (isBr(brNode2)) {
- brNode1.remove();
- brNode2.remove();
- }
- }
- };
- const preProcess$1 = (editor, node, args) => {
- let oldDoc;
- const dom = editor.dom;
- let clonedNode = node.cloneNode(true);
- const impl = document.implementation;
- if (impl.createHTMLDocument) {
- const doc = impl.createHTMLDocument('');
- Tools.each(clonedNode.nodeName === 'BODY' ? clonedNode.childNodes : [clonedNode], node => {
- doc.body.appendChild(doc.importNode(node, true));
- });
- if (clonedNode.nodeName !== 'BODY') {
- clonedNode = doc.body.firstChild;
- } else {
- clonedNode = doc.body;
- }
- oldDoc = dom.doc;
- dom.doc = doc;
- }
- firePreProcess(editor, {
- ...args,
- node: clonedNode
- });
- if (oldDoc) {
- dom.doc = oldDoc;
- }
- return clonedNode;
- };
- const shouldFireEvent = (editor, args) => {
- return editor && editor.hasEventListeners('PreProcess') && !args.no_events;
- };
- const process$1 = (editor, node, args) => {
- return shouldFireEvent(editor, args) ? preProcess$1(editor, node, args) : node;
- };
- const addTempAttr = (htmlParser, tempAttrs, name) => {
- if (Tools.inArray(tempAttrs, name) === -1) {
- htmlParser.addAttributeFilter(name, (nodes, name) => {
- let i = nodes.length;
- while (i--) {
- nodes[i].attr(name, null);
- }
- });
- tempAttrs.push(name);
- }
- };
- const postProcess = (editor, args, content) => {
- if (!args.no_events && editor) {
- const outArgs = firePostProcess(editor, {
- ...args,
- content
- });
- return outArgs.content;
- } else {
- return content;
- }
- };
- const getHtmlFromNode = (dom, node, args) => {
- const html = trim$1(args.getInner ? node.innerHTML : dom.getOuterHTML(node));
- return args.selection || isWsPreserveElement(SugarElement.fromDom(node)) ? html : Tools.trim(html);
- };
- const parseHtml = (htmlParser, html, args) => {
- const parserArgs = args.selection ? {
- forced_root_block: false,
- ...args
- } : args;
- const rootNode = htmlParser.parse(html, parserArgs);
- trimTrailingBr(rootNode);
- return rootNode;
- };
- const serializeNode = (settings, schema, node) => {
- const htmlSerializer = HtmlSerializer(settings, schema);
- return htmlSerializer.serialize(node);
- };
- const toHtml = (editor, settings, schema, rootNode, args) => {
- const content = serializeNode(settings, schema, rootNode);
- return postProcess(editor, args, content);
- };
- const DomSerializerImpl = (settings, editor) => {
- const tempAttrs = ['data-mce-selected'];
- const dom = editor && editor.dom ? editor.dom : DOMUtils.DOM;
- const schema = editor && editor.schema ? editor.schema : Schema(settings);
- settings.entity_encoding = settings.entity_encoding || 'named';
- settings.remove_trailing_brs = 'remove_trailing_brs' in settings ? settings.remove_trailing_brs : true;
- const htmlParser = DomParser(settings, schema);
- register$3(htmlParser, settings, dom);
- const serialize = (node, parserArgs = {}) => {
- const args = {
- format: 'html',
- ...parserArgs
- };
- const targetNode = process$1(editor, node, args);
- const html = getHtmlFromNode(dom, targetNode, args);
- const rootNode = parseHtml(htmlParser, html, args);
- return args.format === 'tree' ? rootNode : toHtml(editor, settings, schema, rootNode, args);
- };
- return {
- schema,
- addNodeFilter: htmlParser.addNodeFilter,
- addAttributeFilter: htmlParser.addAttributeFilter,
- serialize: serialize,
- addRules: schema.addValidElements,
- setRules: schema.setValidElements,
- addTempAttr: curry(addTempAttr, htmlParser, tempAttrs),
- getTempAttrs: constant(tempAttrs),
- getNodeFilters: htmlParser.getNodeFilters,
- getAttributeFilters: htmlParser.getAttributeFilters,
- removeNodeFilter: htmlParser.removeNodeFilter,
- removeAttributeFilter: htmlParser.removeAttributeFilter
- };
- };
- const DomSerializer = (settings, editor) => {
- const domSerializer = DomSerializerImpl(settings, editor);
- return {
- schema: domSerializer.schema,
- addNodeFilter: domSerializer.addNodeFilter,
- addAttributeFilter: domSerializer.addAttributeFilter,
- serialize: domSerializer.serialize,
- addRules: domSerializer.addRules,
- setRules: domSerializer.setRules,
- addTempAttr: domSerializer.addTempAttr,
- getTempAttrs: domSerializer.getTempAttrs,
- getNodeFilters: domSerializer.getNodeFilters,
- getAttributeFilters: domSerializer.getAttributeFilters,
- removeNodeFilter: domSerializer.removeNodeFilter,
- removeAttributeFilter: domSerializer.removeAttributeFilter
- };
- };
- const defaultFormat$1 = 'html';
- const setupArgs$1 = (args, format) => ({
- ...args,
- format,
- get: true,
- getInner: true
- });
- const getContent = (editor, args = {}) => {
- const format = args.format ? args.format : defaultFormat$1;
- const defaultedArgs = setupArgs$1(args, format);
- return preProcessGetContent(editor, defaultedArgs).fold(identity, updatedArgs => {
- const content = getContent$2(editor, updatedArgs);
- return postProcessGetContent(editor, content, updatedArgs);
- });
- };
- const defaultFormat = 'html';
- const setupArgs = (args, content) => ({
- format: defaultFormat,
- ...args,
- set: true,
- content
- });
- const setContent = (editor, content, args = {}) => {
- const defaultedArgs = setupArgs(args, content);
- return preProcessSetContent(editor, defaultedArgs).map(updatedArgs => {
- const result = setContent$2(editor, updatedArgs.content, updatedArgs);
- postProcessSetContent(editor, result.html, updatedArgs);
- return result.content;
- }).getOr(content);
- };
- const removedOptions = ('autoresize_on_init,content_editable_state,padd_empty_with_br,block_elements,' + 'boolean_attributes,editor_deselector,editor_selector,elements,file_browser_callback_types,filepicker_validator_handler,' + 'force_hex_style_colors,force_p_newlines,gecko_spellcheck,images_dataimg_filter,media_scripts,mode,move_caret_before_on_enter_elements,' + 'non_empty_elements,self_closing_elements,short_ended_elements,special,spellchecker_select_languages,spellchecker_whitelist,' + 'tab_focus,tabfocus_elements,table_responsive_width,text_block_elements,text_inline_elements,toolbar_drawer,types,validate,whitespace_elements,' + 'paste_enable_default_filters,paste_filter_drop,paste_word_valid_elements,paste_retain_style_properties,paste_convert_word_fake_lists').split(',');
- const removedPlugins = 'bbcode,colorpicker,contextmenu,fullpage,legacyoutput,spellchecker,textcolor'.split(',');
- const getRemovedOptions = options => {
- const settingNames = filter$6(removedOptions, setting => has$2(options, setting));
- const forcedRootBlock = options.forced_root_block;
- if (forcedRootBlock === false || forcedRootBlock === '') {
- settingNames.push('forced_root_block (false only)');
- }
- return sort(settingNames);
- };
- const getRemovedPlugins = options => {
- const plugins = Tools.makeMap(options.plugins, ' ');
- const hasPlugin = plugin => has$2(plugins, plugin);
- const pluginNames = filter$6(removedPlugins, hasPlugin);
- return sort(pluginNames);
- };
- const logRemovedWarnings = (rawOptions, normalizedOptions) => {
- const removedOptions = getRemovedOptions(rawOptions);
- const removedPlugins = getRemovedPlugins(normalizedOptions);
- const hasRemovedPlugins = removedPlugins.length > 0;
- const hasRemovedOptions = removedOptions.length > 0;
- const isLegacyMobileTheme = normalizedOptions.theme === 'mobile';
- if (hasRemovedPlugins || hasRemovedOptions || isLegacyMobileTheme) {
- const listJoiner = '\n- ';
- const themesMessage = isLegacyMobileTheme ? `\n\nThemes:${ listJoiner }mobile` : '';
- const pluginsMessage = hasRemovedPlugins ? `\n\nPlugins:${ listJoiner }${ removedPlugins.join(listJoiner) }` : '';
- const optionsMessage = hasRemovedOptions ? `\n\nOptions:${ listJoiner }${ removedOptions.join(listJoiner) }` : '';
- console.warn('The following deprecated features are currently enabled and have been removed in TinyMCE 6.0. These features will no longer work and should be removed from the TinyMCE configuration. ' + 'See https://www.tiny.cloud/docs/tinymce/6/migration-from-5x/ for more information.' + themesMessage + pluginsMessage + optionsMessage);
- }
- };
- const logWarnings = (rawOptions, normalizedOptions) => {
- logRemovedWarnings(rawOptions, normalizedOptions);
- };
- const DOM$8 = DOMUtils.DOM;
- const restoreOriginalStyles = editor => {
- DOM$8.setStyle(editor.id, 'display', editor.orgDisplay);
- };
- const safeDestroy = x => Optional.from(x).each(x => x.destroy());
- const clearDomReferences = editor => {
- editor.contentAreaContainer = editor.formElement = editor.container = editor.editorContainer = null;
- editor.bodyElement = editor.contentDocument = editor.contentWindow = null;
- editor.iframeElement = editor.targetElm = null;
- if (editor.selection) {
- editor.selection = editor.selection.win = editor.selection.dom = editor.selection.dom.doc = null;
- }
- };
- const restoreForm = editor => {
- const form = editor.formElement;
- if (form) {
- if (form._mceOldSubmit) {
- form.submit = form._mceOldSubmit;
- form._mceOldSubmit = null;
- }
- DOM$8.unbind(form, 'submit reset', editor.formEventDelegate);
- }
- };
- const remove$1 = editor => {
- if (!editor.removed) {
- const {_selectionOverrides, editorUpload} = editor;
- const body = editor.getBody();
- const element = editor.getElement();
- if (body) {
- editor.save({ is_removing: true });
- }
- editor.removed = true;
- editor.unbindAllNativeEvents();
- if (editor.hasHiddenInput && element) {
- DOM$8.remove(element.nextSibling);
- }
- fireRemove(editor);
- editor.editorManager.remove(editor);
- if (!editor.inline && body) {
- restoreOriginalStyles(editor);
- }
- fireDetach(editor);
- DOM$8.remove(editor.getContainer());
- safeDestroy(_selectionOverrides);
- safeDestroy(editorUpload);
- editor.destroy();
- }
- };
- const destroy = (editor, automatic) => {
- const {selection, dom} = editor;
- if (editor.destroyed) {
- return;
- }
- if (!automatic && !editor.removed) {
- editor.remove();
- return;
- }
- if (!automatic) {
- editor.editorManager.off('beforeunload', editor._beforeUnload);
- if (editor.theme && editor.theme.destroy) {
- editor.theme.destroy();
- }
- safeDestroy(selection);
- safeDestroy(dom);
- }
- restoreForm(editor);
- clearDomReferences(editor);
- editor.destroyed = true;
- };
- const CreateIconManager = () => {
- const lookup = {};
- const add = (id, iconPack) => {
- lookup[id] = iconPack;
- };
- const get = id => {
- if (lookup[id]) {
- return lookup[id];
- }
- return { icons: {} };
- };
- const has = id => has$2(lookup, id);
- return {
- add,
- get,
- has
- };
- };
- const IconManager = CreateIconManager();
- const ModelManager = AddOnManager.ModelManager;
- const getProp = (propName, elm) => {
- const rawElm = elm.dom;
- return rawElm[propName];
- };
- const getComputedSizeProp = (propName, elm) => parseInt(get$7(elm, propName), 10);
- const getClientWidth = curry(getProp, 'clientWidth');
- const getClientHeight = curry(getProp, 'clientHeight');
- const getMarginTop = curry(getComputedSizeProp, 'margin-top');
- const getMarginLeft = curry(getComputedSizeProp, 'margin-left');
- const getBoundingClientRect = elm => elm.dom.getBoundingClientRect();
- const isInsideElementContentArea = (bodyElm, clientX, clientY) => {
- const clientWidth = getClientWidth(bodyElm);
- const clientHeight = getClientHeight(bodyElm);
- return clientX >= 0 && clientY >= 0 && clientX <= clientWidth && clientY <= clientHeight;
- };
- const transpose = (inline, elm, clientX, clientY) => {
- const clientRect = getBoundingClientRect(elm);
- const deltaX = inline ? clientRect.left + elm.dom.clientLeft + getMarginLeft(elm) : 0;
- const deltaY = inline ? clientRect.top + elm.dom.clientTop + getMarginTop(elm) : 0;
- const x = clientX - deltaX;
- const y = clientY - deltaY;
- return {
- x,
- y
- };
- };
- const isXYInContentArea = (editor, clientX, clientY) => {
- const bodyElm = SugarElement.fromDom(editor.getBody());
- const targetElm = editor.inline ? bodyElm : documentElement(bodyElm);
- const transposedPoint = transpose(editor.inline, targetElm, clientX, clientY);
- return isInsideElementContentArea(targetElm, transposedPoint.x, transposedPoint.y);
- };
- const fromDomSafe = node => Optional.from(node).map(SugarElement.fromDom);
- const isEditorAttachedToDom = editor => {
- const rawContainer = editor.inline ? editor.getBody() : editor.getContentAreaContainer();
- return fromDomSafe(rawContainer).map(inBody).getOr(false);
- };
- const NotificationManagerImpl = () => {
- const unimplemented = () => {
- throw new Error('Theme did not provide a NotificationManager implementation.');
- };
- return {
- open: unimplemented,
- close: unimplemented,
- getArgs: unimplemented
- };
- };
- const NotificationManager = editor => {
- const notifications = [];
- const getImplementation = () => {
- const theme = editor.theme;
- return theme && theme.getNotificationManagerImpl ? theme.getNotificationManagerImpl() : NotificationManagerImpl();
- };
- const getTopNotification = () => {
- return Optional.from(notifications[0]);
- };
- const isEqual = (a, b) => {
- return a.type === b.type && a.text === b.text && !a.progressBar && !a.timeout && !b.progressBar && !b.timeout;
- };
- const reposition = () => {
- each$f(notifications, notification => {
- notification.reposition();
- });
- };
- const addNotification = notification => {
- notifications.push(notification);
- };
- const closeNotification = notification => {
- findIndex$2(notifications, otherNotification => {
- return otherNotification === notification;
- }).each(index => {
- notifications.splice(index, 1);
- });
- };
- const open = (spec, fireEvent = true) => {
- if (editor.removed || !isEditorAttachedToDom(editor)) {
- return;
- }
- if (fireEvent) {
- editor.dispatch('BeforeOpenNotification', { notification: spec });
- }
- return find$2(notifications, notification => {
- return isEqual(getImplementation().getArgs(notification), spec);
- }).getOrThunk(() => {
- editor.editorManager.setActive(editor);
- const notification = getImplementation().open(spec, () => {
- closeNotification(notification);
- reposition();
- getTopNotification().fold(() => editor.focus(), top => focus$1(SugarElement.fromDom(top.getEl())));
- });
- addNotification(notification);
- reposition();
- editor.dispatch('OpenNotification', { notification: { ...notification } });
- return notification;
- });
- };
- const close = () => {
- getTopNotification().each(notification => {
- getImplementation().close(notification);
- closeNotification(notification);
- reposition();
- });
- };
- const getNotifications = constant(notifications);
- const registerEvents = editor => {
- editor.on('SkinLoaded', () => {
- const serviceMessage = getServiceMessage(editor);
- if (serviceMessage) {
- open({
- text: serviceMessage,
- type: 'warning',
- timeout: 0
- }, false);
- }
- reposition();
- });
- editor.on('show ResizeEditor ResizeWindow NodeChange', () => {
- requestAnimationFrame(reposition);
- });
- editor.on('remove', () => {
- each$f(notifications.slice(), notification => {
- getImplementation().close(notification);
- });
- });
- };
- registerEvents(editor);
- return {
- open,
- close,
- getNotifications
- };
- };
- const PluginManager = AddOnManager.PluginManager;
- const ThemeManager = AddOnManager.ThemeManager;
- var WindowManagerImpl = () => {
- const unimplemented = () => {
- throw new Error('Theme did not provide a WindowManager implementation.');
- };
- return {
- open: unimplemented,
- openUrl: unimplemented,
- alert: unimplemented,
- confirm: unimplemented,
- close: unimplemented,
- getParams: unimplemented,
- setParams: unimplemented
- };
- };
- const WindowManager = editor => {
- let dialogs = [];
- const getImplementation = () => {
- const theme = editor.theme;
- return theme && theme.getWindowManagerImpl ? theme.getWindowManagerImpl() : WindowManagerImpl();
- };
- const funcBind = (scope, f) => {
- return (...args) => {
- return f ? f.apply(scope, args) : undefined;
- };
- };
- const fireOpenEvent = dialog => {
- editor.dispatch('OpenWindow', { dialog });
- };
- const fireCloseEvent = dialog => {
- editor.dispatch('CloseWindow', { dialog });
- };
- const addDialog = dialog => {
- dialogs.push(dialog);
- fireOpenEvent(dialog);
- };
- const closeDialog = dialog => {
- fireCloseEvent(dialog);
- dialogs = filter$6(dialogs, otherDialog => {
- return otherDialog !== dialog;
- });
- if (dialogs.length === 0) {
- editor.focus();
- }
- };
- const getTopDialog = () => {
- return Optional.from(dialogs[dialogs.length - 1]);
- };
- const storeSelectionAndOpenDialog = openDialog => {
- editor.editorManager.setActive(editor);
- store(editor);
- editor.ui.show();
- const dialog = openDialog();
- addDialog(dialog);
- return dialog;
- };
- const open = (args, params) => {
- return storeSelectionAndOpenDialog(() => getImplementation().open(args, params, closeDialog));
- };
- const openUrl = args => {
- return storeSelectionAndOpenDialog(() => getImplementation().openUrl(args, closeDialog));
- };
- const alert = (message, callback, scope) => {
- const windowManagerImpl = getImplementation();
- windowManagerImpl.alert(message, funcBind(scope ? scope : windowManagerImpl, callback));
- };
- const confirm = (message, callback, scope) => {
- const windowManagerImpl = getImplementation();
- windowManagerImpl.confirm(message, funcBind(scope ? scope : windowManagerImpl, callback));
- };
- const close = () => {
- getTopDialog().each(dialog => {
- getImplementation().close(dialog);
- closeDialog(dialog);
- });
- };
- editor.on('remove', () => {
- each$f(dialogs, dialog => {
- getImplementation().close(dialog);
- });
- });
- return {
- open,
- openUrl,
- alert,
- confirm,
- close
- };
- };
- const displayNotification = (editor, message) => {
- editor.notificationManager.open({
- type: 'error',
- text: message
- });
- };
- const displayError = (editor, message) => {
- if (editor._skinLoaded) {
- displayNotification(editor, message);
- } else {
- editor.on('SkinLoaded', () => {
- displayNotification(editor, message);
- });
- }
- };
- const uploadError = (editor, message) => {
- displayError(editor, I18n.translate([
- 'Failed to upload image: {0}',
- message
- ]));
- };
- const logError = (editor, errorType, msg) => {
- fireError(editor, errorType, { message: msg });
- console.error(msg);
- };
- const createLoadError = (type, url, name) => name ? `Failed to load ${ type }: ${ name } from url ${ url }` : `Failed to load ${ type } url: ${ url }`;
- const pluginLoadError = (editor, url, name) => {
- logError(editor, 'PluginLoadError', createLoadError('plugin', url, name));
- };
- const iconsLoadError = (editor, url, name) => {
- logError(editor, 'IconsLoadError', createLoadError('icons', url, name));
- };
- const languageLoadError = (editor, url, name) => {
- logError(editor, 'LanguageLoadError', createLoadError('language', url, name));
- };
- const themeLoadError = (editor, url, name) => {
- logError(editor, 'ThemeLoadError', createLoadError('theme', url, name));
- };
- const modelLoadError = (editor, url, name) => {
- logError(editor, 'ModelLoadError', createLoadError('model', url, name));
- };
- const pluginInitError = (editor, name, err) => {
- const message = I18n.translate([
- 'Failed to initialize plugin: {0}',
- name
- ]);
- fireError(editor, 'PluginLoadError', { message });
- initError(message, err);
- displayError(editor, message);
- };
- const initError = (message, ...x) => {
- const console = window.console;
- if (console) {
- if (console.error) {
- console.error(message, ...x);
- } else {
- console.log(message, ...x);
- }
- }
- };
- const isContentCssSkinName = url => /^[a-z0-9\-]+$/i.test(url);
- const getContentCssUrls = editor => {
- return transformToUrls(editor, getContentCss(editor));
- };
- const getFontCssUrls = editor => {
- return transformToUrls(editor, getFontCss(editor));
- };
- const transformToUrls = (editor, cssLinks) => {
- const skinUrl = editor.editorManager.baseURL + '/skins/content';
- const suffix = editor.editorManager.suffix;
- const contentCssFile = `content${ suffix }.css`;
- const inline = editor.inline === true;
- return map$3(cssLinks, url => {
- if (isContentCssSkinName(url) && !inline) {
- return `${ skinUrl }/${ url }/${ contentCssFile }`;
- } else {
- return editor.documentBaseURI.toAbsolute(url);
- }
- });
- };
- const appendContentCssFromSettings = editor => {
- editor.contentCSS = editor.contentCSS.concat(getContentCssUrls(editor), getFontCssUrls(editor));
- };
- const filter$1 = always;
- const bind$1 = (element, event, handler) => bind$2(element, event, filter$1, handler);
- const getAllImages = elm => {
- return elm ? from(elm.getElementsByTagName('img')) : [];
- };
- const ImageScanner = (uploadStatus, blobCache) => {
- const cachedPromises = {};
- const findAll = (elm, predicate = always) => {
- const images = filter$6(getAllImages(elm), img => {
- const src = img.src;
- if (img.hasAttribute('data-mce-bogus')) {
- return false;
- }
- if (img.hasAttribute('data-mce-placeholder')) {
- return false;
- }
- if (!src || src === Env.transparentSrc) {
- return false;
- }
- if (startsWith(src, 'blob:')) {
- return !uploadStatus.isUploaded(src) && predicate(img);
- }
- if (startsWith(src, 'data:')) {
- return predicate(img);
- }
- return false;
- });
- const promises = map$3(images, img => {
- const imageSrc = img.src;
- if (has$2(cachedPromises, imageSrc)) {
- return cachedPromises[imageSrc].then(imageInfo => {
- if (isString(imageInfo)) {
- return imageInfo;
- } else {
- return {
- image: img,
- blobInfo: imageInfo.blobInfo
- };
- }
- });
- } else {
- const newPromise = imageToBlobInfo(blobCache, imageSrc).then(blobInfo => {
- delete cachedPromises[imageSrc];
- return {
- image: img,
- blobInfo
- };
- }).catch(error => {
- delete cachedPromises[imageSrc];
- return error;
- });
- cachedPromises[imageSrc] = newPromise;
- return newPromise;
- }
- });
- return Promise.all(promises);
- };
- return { findAll };
- };
- const UploadStatus = () => {
- const PENDING = 1, UPLOADED = 2;
- let blobUriStatuses = {};
- const createStatus = (status, resultUri) => {
- return {
- status,
- resultUri
- };
- };
- const hasBlobUri = blobUri => {
- return blobUri in blobUriStatuses;
- };
- const getResultUri = blobUri => {
- const result = blobUriStatuses[blobUri];
- return result ? result.resultUri : null;
- };
- const isPending = blobUri => {
- return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === PENDING : false;
- };
- const isUploaded = blobUri => {
- return hasBlobUri(blobUri) ? blobUriStatuses[blobUri].status === UPLOADED : false;
- };
- const markPending = blobUri => {
- blobUriStatuses[blobUri] = createStatus(PENDING, null);
- };
- const markUploaded = (blobUri, resultUri) => {
- blobUriStatuses[blobUri] = createStatus(UPLOADED, resultUri);
- };
- const removeFailed = blobUri => {
- delete blobUriStatuses[blobUri];
- };
- const destroy = () => {
- blobUriStatuses = {};
- };
- return {
- hasBlobUri,
- getResultUri,
- isPending,
- isUploaded,
- markPending,
- markUploaded,
- removeFailed,
- destroy
- };
- };
- let count = 0;
- const seed = () => {
- const rnd = () => {
- return Math.round(Math.random() * 4294967295).toString(36);
- };
- const now = new Date().getTime();
- return 's' + now.toString(36) + rnd() + rnd() + rnd();
- };
- const uuid = prefix => {
- return prefix + count++ + seed();
- };
- const BlobCache = () => {
- let cache = [];
- const mimeToExt = mime => {
- const mimes = {
- 'image/jpeg': 'jpg',
- 'image/jpg': 'jpg',
- 'image/gif': 'gif',
- 'image/png': 'png',
- 'image/apng': 'apng',
- 'image/avif': 'avif',
- 'image/svg+xml': 'svg',
- 'image/webp': 'webp',
- 'image/bmp': 'bmp',
- 'image/tiff': 'tiff'
- };
- return mimes[mime.toLowerCase()] || 'dat';
- };
- const create = (o, blob, base64, name, filename) => {
- if (isString(o)) {
- const id = o;
- return toBlobInfo({
- id,
- name,
- filename,
- blob,
- base64
- });
- } else if (isObject(o)) {
- return toBlobInfo(o);
- } else {
- throw new Error('Unknown input type');
- }
- };
- const toBlobInfo = o => {
- if (!o.blob || !o.base64) {
- throw new Error('blob and base64 representations of the image are required for BlobInfo to be created');
- }
- const id = o.id || uuid('blobid');
- const name = o.name || id;
- const blob = o.blob;
- return {
- id: constant(id),
- name: constant(name),
- filename: constant(o.filename || name + '.' + mimeToExt(blob.type)),
- blob: constant(blob),
- base64: constant(o.base64),
- blobUri: constant(o.blobUri || URL.createObjectURL(blob)),
- uri: constant(o.uri)
- };
- };
- const add = blobInfo => {
- if (!get(blobInfo.id())) {
- cache.push(blobInfo);
- }
- };
- const findFirst = predicate => find$2(cache, predicate).getOrUndefined();
- const get = id => findFirst(cachedBlobInfo => cachedBlobInfo.id() === id);
- const getByUri = blobUri => findFirst(blobInfo => blobInfo.blobUri() === blobUri);
- const getByData = (base64, type) => findFirst(blobInfo => blobInfo.base64() === base64 && blobInfo.blob().type === type);
- const removeByUri = blobUri => {
- cache = filter$6(cache, blobInfo => {
- if (blobInfo.blobUri() === blobUri) {
- URL.revokeObjectURL(blobInfo.blobUri());
- return false;
- }
- return true;
- });
- };
- const destroy = () => {
- each$f(cache, cachedBlobInfo => {
- URL.revokeObjectURL(cachedBlobInfo.blobUri());
- });
- cache = [];
- };
- return {
- create,
- add,
- get,
- getByUri,
- getByData,
- findFirst,
- removeByUri,
- destroy
- };
- };
- const Uploader = (uploadStatus, settings) => {
- const pendingPromises = {};
- const pathJoin = (path1, path2) => {
- if (path1) {
- return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
- }
- return path2;
- };
- const defaultHandler = (blobInfo, progress) => new Promise((success, failure) => {
- const xhr = new XMLHttpRequest();
- xhr.open('POST', settings.url);
- xhr.withCredentials = settings.credentials;
- xhr.upload.onprogress = e => {
- progress(e.loaded / e.total * 100);
- };
- xhr.onerror = () => {
- failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
- };
- xhr.onload = () => {
- if (xhr.status < 200 || xhr.status >= 300) {
- failure('HTTP Error: ' + xhr.status);
- return;
- }
- const json = JSON.parse(xhr.responseText);
- if (!json || !isString(json.location)) {
- failure('Invalid JSON: ' + xhr.responseText);
- return;
- }
- success(pathJoin(settings.basePath, json.location));
- };
- const formData = new FormData();
- formData.append('file', blobInfo.blob(), blobInfo.filename());
- xhr.send(formData);
- });
- const noUpload = () => new Promise(resolve => {
- resolve([]);
- });
- const handlerSuccess = (blobInfo, url) => ({
- url,
- blobInfo,
- status: true
- });
- const handlerFailure = (blobInfo, error) => ({
- url: '',
- blobInfo,
- status: false,
- error
- });
- const resolvePending = (blobUri, result) => {
- Tools.each(pendingPromises[blobUri], resolve => {
- resolve(result);
- });
- delete pendingPromises[blobUri];
- };
- const uploadBlobInfo = (blobInfo, handler, openNotification) => {
- uploadStatus.markPending(blobInfo.blobUri());
- return new Promise(resolve => {
- let notification;
- let progress;
- try {
- const closeNotification = () => {
- if (notification) {
- notification.close();
- progress = noop;
- }
- };
- const success = url => {
- closeNotification();
- uploadStatus.markUploaded(blobInfo.blobUri(), url);
- resolvePending(blobInfo.blobUri(), handlerSuccess(blobInfo, url));
- resolve(handlerSuccess(blobInfo, url));
- };
- const failure = error => {
- closeNotification();
- uploadStatus.removeFailed(blobInfo.blobUri());
- resolvePending(blobInfo.blobUri(), handlerFailure(blobInfo, error));
- resolve(handlerFailure(blobInfo, error));
- };
- progress = percent => {
- if (percent < 0 || percent > 100) {
- return;
- }
- Optional.from(notification).orThunk(() => Optional.from(openNotification).map(apply$1)).each(n => {
- notification = n;
- n.progressBar.value(percent);
- });
- };
- handler(blobInfo, progress).then(success, err => {
- failure(isString(err) ? { message: err } : err);
- });
- } catch (ex) {
- resolve(handlerFailure(blobInfo, ex));
- }
- });
- };
- const isDefaultHandler = handler => handler === defaultHandler;
- const pendingUploadBlobInfo = blobInfo => {
- const blobUri = blobInfo.blobUri();
- return new Promise(resolve => {
- pendingPromises[blobUri] = pendingPromises[blobUri] || [];
- pendingPromises[blobUri].push(resolve);
- });
- };
- const uploadBlobs = (blobInfos, openNotification) => {
- blobInfos = Tools.grep(blobInfos, blobInfo => !uploadStatus.isUploaded(blobInfo.blobUri()));
- return Promise.all(Tools.map(blobInfos, blobInfo => uploadStatus.isPending(blobInfo.blobUri()) ? pendingUploadBlobInfo(blobInfo) : uploadBlobInfo(blobInfo, settings.handler, openNotification)));
- };
- const upload = (blobInfos, openNotification) => !settings.url && isDefaultHandler(settings.handler) ? noUpload() : uploadBlobs(blobInfos, openNotification);
- if (isFunction(settings.handler) === false) {
- settings.handler = defaultHandler;
- }
- return { upload };
- };
- const openNotification = editor => () => editor.notificationManager.open({
- text: editor.translate('Image uploading...'),
- type: 'info',
- timeout: -1,
- progressBar: true
- });
- const createUploader = (editor, uploadStatus) => Uploader(uploadStatus, {
- url: getImageUploadUrl(editor),
- basePath: getImageUploadBasePath(editor),
- credentials: getImagesUploadCredentials(editor),
- handler: getImagesUploadHandler(editor)
- });
- const ImageUploader = editor => {
- const uploadStatus = UploadStatus();
- const uploader = createUploader(editor, uploadStatus);
- return { upload: (blobInfos, showNotification = true) => uploader.upload(blobInfos, showNotification ? openNotification(editor) : undefined) };
- };
- const EditorUpload = editor => {
- const blobCache = BlobCache();
- let uploader, imageScanner;
- const uploadStatus = UploadStatus();
- const urlFilters = [];
- const aliveGuard = callback => {
- return result => {
- if (editor.selection) {
- return callback(result);
- }
- return [];
- };
- };
- const cacheInvalidator = url => url + (url.indexOf('?') === -1 ? '?' : '&') + new Date().getTime();
- const replaceString = (content, search, replace) => {
- let index = 0;
- do {
- index = content.indexOf(search, index);
- if (index !== -1) {
- content = content.substring(0, index) + replace + content.substr(index + search.length);
- index += replace.length - search.length + 1;
- }
- } while (index !== -1);
- return content;
- };
- const replaceImageUrl = (content, targetUrl, replacementUrl) => {
- const replacementString = `src="${ replacementUrl }"${ replacementUrl === Env.transparentSrc ? ' data-mce-placeholder="1"' : '' }`;
- content = replaceString(content, `src="${ targetUrl }"`, replacementString);
- content = replaceString(content, 'data-mce-src="' + targetUrl + '"', 'data-mce-src="' + replacementUrl + '"');
- return content;
- };
- const replaceUrlInUndoStack = (targetUrl, replacementUrl) => {
- each$f(editor.undoManager.data, level => {
- if (level.type === 'fragmented') {
- level.fragments = map$3(level.fragments, fragment => replaceImageUrl(fragment, targetUrl, replacementUrl));
- } else {
- level.content = replaceImageUrl(level.content, targetUrl, replacementUrl);
- }
- });
- };
- const replaceImageUriInView = (image, resultUri) => {
- const src = editor.convertURL(resultUri, 'src');
- replaceUrlInUndoStack(image.src, resultUri);
- setAll$1(SugarElement.fromDom(image), {
- 'src': shouldReuseFileName(editor) ? cacheInvalidator(resultUri) : resultUri,
- 'data-mce-src': src
- });
- };
- const uploadImages = () => {
- if (!uploader) {
- uploader = createUploader(editor, uploadStatus);
- }
- return scanForImages().then(aliveGuard(imageInfos => {
- const blobInfos = map$3(imageInfos, imageInfo => imageInfo.blobInfo);
- return uploader.upload(blobInfos, openNotification(editor)).then(aliveGuard(result => {
- const imagesToRemove = [];
- let shouldDispatchChange = false;
- const filteredResult = map$3(result, (uploadInfo, index) => {
- const blobInfo = imageInfos[index].blobInfo;
- const image = imageInfos[index].image;
- let removed = false;
- if (uploadInfo.status && shouldReplaceBlobUris(editor)) {
- if (uploadInfo.url && !contains$1(image.src, uploadInfo.url)) {
- shouldDispatchChange = true;
- }
- blobCache.removeByUri(image.src);
- if (isRtc(editor)) ; else {
- replaceImageUriInView(image, uploadInfo.url);
- }
- } else if (uploadInfo.error) {
- if (uploadInfo.error.remove) {
- replaceUrlInUndoStack(image.getAttribute('src'), Env.transparentSrc);
- imagesToRemove.push(image);
- removed = true;
- }
- uploadError(editor, uploadInfo.error.message);
- }
- return {
- element: image,
- status: uploadInfo.status,
- uploadUri: uploadInfo.url,
- blobInfo,
- removed
- };
- });
- if (imagesToRemove.length > 0 && !isRtc(editor)) {
- editor.undoManager.transact(() => {
- each$f(imagesToRemove, element => {
- editor.dom.remove(element);
- blobCache.removeByUri(element.src);
- });
- });
- } else if (shouldDispatchChange) {
- editor.undoManager.dispatchChange();
- }
- return filteredResult;
- }));
- }));
- };
- const uploadImagesAuto = () => isAutomaticUploadsEnabled(editor) ? uploadImages() : Promise.resolve([]);
- const isValidDataUriImage = imgElm => forall(urlFilters, filter => filter(imgElm));
- const addFilter = filter => {
- urlFilters.push(filter);
- };
- const scanForImages = () => {
- if (!imageScanner) {
- imageScanner = ImageScanner(uploadStatus, blobCache);
- }
- return imageScanner.findAll(editor.getBody(), isValidDataUriImage).then(aliveGuard(result => {
- const filteredResult = filter$6(result, resultItem => {
- if (isString(resultItem)) {
- displayError(editor, resultItem);
- return false;
- } else {
- return true;
- }
- });
- if (isRtc(editor)) ; else {
- each$f(filteredResult, resultItem => {
- replaceUrlInUndoStack(resultItem.image.src, resultItem.blobInfo.blobUri());
- resultItem.image.src = resultItem.blobInfo.blobUri();
- resultItem.image.removeAttribute('data-mce-src');
- });
- }
- return filteredResult;
- }));
- };
- const destroy = () => {
- blobCache.destroy();
- uploadStatus.destroy();
- imageScanner = uploader = null;
- };
- const replaceBlobUris = content => {
- return content.replace(/src="(blob:[^"]+)"/g, (match, blobUri) => {
- const resultUri = uploadStatus.getResultUri(blobUri);
- if (resultUri) {
- return 'src="' + resultUri + '"';
- }
- let blobInfo = blobCache.getByUri(blobUri);
- if (!blobInfo) {
- blobInfo = foldl(editor.editorManager.get(), (result, editor) => {
- return result || editor.editorUpload && editor.editorUpload.blobCache.getByUri(blobUri);
- }, null);
- }
- if (blobInfo) {
- const blob = blobInfo.blob();
- return 'src="data:' + blob.type + ';base64,' + blobInfo.base64() + '"';
- }
- return match;
- });
- };
- editor.on('SetContent', () => {
- if (isAutomaticUploadsEnabled(editor)) {
- uploadImagesAuto();
- } else {
- scanForImages();
- }
- });
- editor.on('RawSaveContent', e => {
- e.content = replaceBlobUris(e.content);
- });
- editor.on('GetContent', e => {
- if (e.source_view || e.format === 'raw' || e.format === 'tree') {
- return;
- }
- e.content = replaceBlobUris(e.content);
- });
- editor.on('PostRender', () => {
- editor.parser.addNodeFilter('img', images => {
- each$f(images, img => {
- const src = img.attr('src');
- if (blobCache.getByUri(src)) {
- return;
- }
- const resultUri = uploadStatus.getResultUri(src);
- if (resultUri) {
- img.attr('src', resultUri);
- }
- });
- });
- });
- return {
- blobCache,
- addFilter,
- uploadImages,
- uploadImagesAuto,
- scanForImages,
- destroy
- };
- };
- const get$1 = editor => {
- const dom = editor.dom;
- const schemaType = editor.schema.type;
- const formats = {
- valigntop: [{
- selector: 'td,th',
- styles: { verticalAlign: 'top' }
- }],
- valignmiddle: [{
- selector: 'td,th',
- styles: { verticalAlign: 'middle' }
- }],
- valignbottom: [{
- selector: 'td,th',
- styles: { verticalAlign: 'bottom' }
- }],
- alignleft: [
- {
- selector: 'figure.image',
- collapsed: false,
- classes: 'align-left',
- ceFalseOverride: true,
- preview: 'font-family font-size'
- },
- {
- selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li,pre',
- styles: { textAlign: 'left' },
- inherit: false,
- preview: false
- },
- {
- selector: 'img,audio,video',
- collapsed: false,
- styles: { float: 'left' },
- preview: 'font-family font-size'
- },
- {
- selector: 'table',
- collapsed: false,
- styles: {
- marginLeft: '0px',
- marginRight: 'auto'
- },
- onformat: table => {
- dom.setStyle(table, 'float', null);
- },
- preview: 'font-family font-size'
- }
- ],
- aligncenter: [
- {
- selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li,pre',
- styles: { textAlign: 'center' },
- inherit: false,
- preview: 'font-family font-size'
- },
- {
- selector: 'figure.image',
- collapsed: false,
- classes: 'align-center',
- ceFalseOverride: true,
- preview: 'font-family font-size'
- },
- {
- selector: 'img,audio,video',
- collapsed: false,
- styles: {
- display: 'block',
- marginLeft: 'auto',
- marginRight: 'auto'
- },
- preview: false
- },
- {
- selector: 'table',
- collapsed: false,
- styles: {
- marginLeft: 'auto',
- marginRight: 'auto'
- },
- preview: 'font-family font-size'
- }
- ],
- alignright: [
- {
- selector: 'figure.image',
- collapsed: false,
- classes: 'align-right',
- ceFalseOverride: true,
- preview: 'font-family font-size'
- },
- {
- selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li,pre',
- styles: { textAlign: 'right' },
- inherit: false,
- preview: 'font-family font-size'
- },
- {
- selector: 'img,audio,video',
- collapsed: false,
- styles: { float: 'right' },
- preview: 'font-family font-size'
- },
- {
- selector: 'table',
- collapsed: false,
- styles: {
- marginRight: '0px',
- marginLeft: 'auto'
- },
- onformat: table => {
- dom.setStyle(table, 'float', null);
- },
- preview: 'font-family font-size'
- }
- ],
- alignjustify: [{
- selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li,pre',
- styles: { textAlign: 'justify' },
- inherit: false,
- preview: 'font-family font-size'
- }],
- bold: [
- {
- inline: 'strong',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- },
- {
- inline: 'span',
- styles: { fontWeight: 'bold' }
- },
- {
- inline: 'b',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- }
- ],
- italic: [
- {
- inline: 'em',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- },
- {
- inline: 'span',
- styles: { fontStyle: 'italic' }
- },
- {
- inline: 'i',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- }
- ],
- underline: [
- {
- inline: 'span',
- styles: { textDecoration: 'underline' },
- exact: true
- },
- {
- inline: 'u',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- }
- ],
- strikethrough: (() => {
- const span = {
- inline: 'span',
- styles: { textDecoration: 'line-through' },
- exact: true
- };
- const strike = {
- inline: 'strike',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- };
- const s = {
- inline: 's',
- remove: 'all',
- preserve_attributes: [
- 'class',
- 'style'
- ]
- };
- return schemaType !== 'html4' ? [
- s,
- span,
- strike
- ] : [
- span,
- s,
- strike
- ];
- })(),
- forecolor: {
- inline: 'span',
- styles: { color: '%value' },
- links: true,
- remove_similar: true,
- clear_child_styles: true
- },
- hilitecolor: {
- inline: 'span',
- styles: { backgroundColor: '%value' },
- links: true,
- remove_similar: true,
- clear_child_styles: true
- },
- fontname: {
- inline: 'span',
- toggle: false,
- styles: { fontFamily: '%value' },
- clear_child_styles: true
- },
- fontsize: {
- inline: 'span',
- toggle: false,
- styles: { fontSize: '%value' },
- clear_child_styles: true
- },
- lineheight: {
- selector: 'h1,h2,h3,h4,h5,h6,p,li,td,th,div',
- styles: { lineHeight: '%value' }
- },
- fontsize_class: {
- inline: 'span',
- attributes: { class: '%value' }
- },
- blockquote: {
- block: 'blockquote',
- wrapper: true,
- remove: 'all'
- },
- subscript: { inline: 'sub' },
- superscript: { inline: 'sup' },
- code: { inline: 'code' },
- link: {
- inline: 'a',
- selector: 'a',
- remove: 'all',
- split: true,
- deep: true,
- onmatch: (node, _fmt, _itemName) => {
- return isElement$6(node) && node.hasAttribute('href');
- },
- onformat: (elm, _fmt, vars) => {
- Tools.each(vars, (value, key) => {
- dom.setAttrib(elm, key, value);
- });
- }
- },
- lang: {
- inline: 'span',
- clear_child_styles: true,
- remove_similar: true,
- attributes: {
- 'lang': '%value',
- 'data-mce-lang': vars => {
- var _a;
- return (_a = vars === null || vars === void 0 ? void 0 : vars.customValue) !== null && _a !== void 0 ? _a : null;
- }
- }
- },
- removeformat: [
- {
- selector: 'b,strong,em,i,font,u,strike,s,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,small',
- remove: 'all',
- split: true,
- expand: false,
- block_expand: true,
- deep: true
- },
- {
- selector: 'span',
- attributes: [
- 'style',
- 'class'
- ],
- remove: 'empty',
- split: true,
- expand: false,
- deep: true
- },
- {
- selector: '*',
- attributes: [
- 'style',
- 'class'
- ],
- split: false,
- expand: false,
- deep: true
- }
- ]
- };
- Tools.each('p h1 h2 h3 h4 h5 h6 div address pre dt dd samp'.split(/\s/), name => {
- formats[name] = {
- block: name,
- remove: 'all'
- };
- });
- return formats;
- };
- const genericBase = {
- remove_similar: true,
- inherit: false
- };
- const cellBase = {
- selector: 'td,th',
- ...genericBase
- };
- const cellFormats = {
- tablecellbackgroundcolor: {
- styles: { backgroundColor: '%value' },
- ...cellBase
- },
- tablecellverticalalign: {
- styles: { 'vertical-align': '%value' },
- ...cellBase
- },
- tablecellbordercolor: {
- styles: { borderColor: '%value' },
- ...cellBase
- },
- tablecellclass: {
- classes: ['%value'],
- ...cellBase
- },
- tableclass: {
- selector: 'table',
- classes: ['%value'],
- ...genericBase
- },
- tablecellborderstyle: {
- styles: { borderStyle: '%value' },
- ...cellBase
- },
- tablecellborderwidth: {
- styles: { borderWidth: '%value' },
- ...cellBase
- }
- };
- const get = constant(cellFormats);
- const FormatRegistry = editor => {
- const formats = {};
- const get$2 = name => isNonNullable(name) ? formats[name] : formats;
- const has = name => has$2(formats, name);
- const register = (name, format) => {
- if (name) {
- if (!isString(name)) {
- each$e(name, (format, name) => {
- register(name, format);
- });
- } else {
- if (!isArray$1(format)) {
- format = [format];
- }
- each$f(format, format => {
- if (isUndefined(format.deep)) {
- format.deep = !isSelectorFormat(format);
- }
- if (isUndefined(format.split)) {
- format.split = !isSelectorFormat(format) || isInlineFormat(format);
- }
- if (isUndefined(format.remove) && isSelectorFormat(format) && !isInlineFormat(format)) {
- format.remove = 'none';
- }
- if (isSelectorFormat(format) && isInlineFormat(format)) {
- format.mixed = true;
- format.block_expand = true;
- }
- if (isString(format.classes)) {
- format.classes = format.classes.split(/\s+/);
- }
- });
- formats[name] = format;
- }
- }
- };
- const unregister = name => {
- if (name && formats[name]) {
- delete formats[name];
- }
- return formats;
- };
- register(get$1(editor));
- register(get());
- register(getFormats(editor));
- return {
- get: get$2,
- has,
- register,
- unregister
- };
- };
- const each$3 = Tools.each;
- const dom = DOMUtils.DOM;
- const parsedSelectorToHtml = (ancestry, editor) => {
- let elm, item, fragment;
- const schema = editor && editor.schema || Schema({});
- const decorate = (elm, item) => {
- if (item.classes.length) {
- dom.addClass(elm, item.classes.join(' '));
- }
- dom.setAttribs(elm, item.attrs);
- };
- const createElement = sItem => {
- item = typeof sItem === 'string' ? {
- name: sItem,
- classes: [],
- attrs: {}
- } : sItem;
- const elm = dom.create(item.name);
- decorate(elm, item);
- return elm;
- };
- const getRequiredParent = (elm, candidate) => {
- const name = typeof elm !== 'string' ? elm.nodeName.toLowerCase() : elm;
- const elmRule = schema.getElementRule(name);
- const parentsRequired = elmRule && elmRule.parentsRequired;
- if (parentsRequired && parentsRequired.length) {
- return candidate && Tools.inArray(parentsRequired, candidate) !== -1 ? candidate : parentsRequired[0];
- } else {
- return false;
- }
- };
- const wrapInHtml = (elm, ancestry, siblings) => {
- let parent, parentCandidate;
- const ancestor = ancestry.length > 0 && ancestry[0];
- const ancestorName = ancestor && ancestor.name;
- const parentRequired = getRequiredParent(elm, ancestorName);
- if (parentRequired) {
- if (ancestorName === parentRequired) {
- parentCandidate = ancestry[0];
- ancestry = ancestry.slice(1);
- } else {
- parentCandidate = parentRequired;
- }
- } else if (ancestor) {
- parentCandidate = ancestry[0];
- ancestry = ancestry.slice(1);
- } else if (!siblings) {
- return elm;
- }
- if (parentCandidate) {
- parent = createElement(parentCandidate);
- parent.appendChild(elm);
- }
- if (siblings) {
- if (!parent) {
- parent = dom.create('div');
- parent.appendChild(elm);
- }
- Tools.each(siblings, sibling => {
- const siblingElm = createElement(sibling);
- parent.insertBefore(siblingElm, elm);
- });
- }
- return wrapInHtml(parent, ancestry, parentCandidate && parentCandidate.siblings);
- };
- if (ancestry && ancestry.length) {
- item = ancestry[0];
- elm = createElement(item);
- fragment = dom.create('div');
- fragment.appendChild(wrapInHtml(elm, ancestry.slice(1), item.siblings));
- return fragment;
- } else {
- return '';
- }
- };
- const parseSelectorItem = item => {
- let tagName;
- const obj = {
- classes: [],
- attrs: {}
- };
- item = obj.selector = Tools.trim(item);
- if (item !== '*') {
- tagName = item.replace(/(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g, ($0, $1, $2, $3, $4) => {
- switch ($1) {
- case '#':
- obj.attrs.id = $2;
- break;
- case '.':
- obj.classes.push($2);
- break;
- case ':':
- if (Tools.inArray('checked disabled enabled read-only required'.split(' '), $2) !== -1) {
- obj.attrs[$2] = $2;
- }
- break;
- }
- if ($3 === '[') {
- const m = $4.match(/([\w\-]+)(?:\=\"([^\"]+))?/);
- if (m) {
- obj.attrs[m[1]] = m[2];
- }
- }
- return '';
- });
- }
- obj.name = tagName || 'div';
- return obj;
- };
- const parseSelector = selector => {
- if (!selector || typeof selector !== 'string') {
- return [];
- }
- selector = selector.split(/\s*,\s*/)[0];
- selector = selector.replace(/\s*(~\+|~|\+|>)\s*/g, '$1');
- return Tools.map(selector.split(/(?:>|\s+(?![^\[\]]+\]))/), item => {
- const siblings = Tools.map(item.split(/(?:~\+|~|\+)/), parseSelectorItem);
- const obj = siblings.pop();
- if (siblings.length) {
- obj.siblings = siblings;
- }
- return obj;
- }).reverse();
- };
- const getCssText = (editor, format) => {
- let name, previewFrag;
- let previewCss = '', parentFontSize;
- let previewStyles = getPreviewStyles(editor);
- if (previewStyles === '') {
- return '';
- }
- const removeVars = val => {
- return val.replace(/%(\w+)/g, '');
- };
- if (typeof format === 'string') {
- format = editor.formatter.get(format);
- if (!format) {
- return;
- }
- format = format[0];
- }
- if ('preview' in format) {
- const previewOpt = get$a(format, 'preview');
- if (is$2(previewOpt, false)) {
- return '';
- } else {
- previewStyles = previewOpt.getOr(previewStyles);
- }
- }
- name = format.block || format.inline || 'span';
- const items = parseSelector(format.selector);
- if (items.length) {
- if (!items[0].name) {
- items[0].name = name;
- }
- name = format.selector;
- previewFrag = parsedSelectorToHtml(items, editor);
- } else {
- previewFrag = parsedSelectorToHtml([name], editor);
- }
- const previewElm = dom.select(name, previewFrag)[0] || previewFrag.firstChild;
- each$3(format.styles, (value, name) => {
- const newValue = removeVars(value);
- if (newValue) {
- dom.setStyle(previewElm, name, newValue);
- }
- });
- each$3(format.attributes, (value, name) => {
- const newValue = removeVars(value);
- if (newValue) {
- dom.setAttrib(previewElm, name, newValue);
- }
- });
- each$3(format.classes, value => {
- const newValue = removeVars(value);
- if (!dom.hasClass(previewElm, newValue)) {
- dom.addClass(previewElm, newValue);
- }
- });
- editor.dispatch('PreviewFormats');
- dom.setStyles(previewFrag, {
- position: 'absolute',
- left: -65535
- });
- editor.getBody().appendChild(previewFrag);
- parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true);
- parentFontSize = /px$/.test(parentFontSize) ? parseInt(parentFontSize, 10) : 0;
- each$3(previewStyles.split(' '), name => {
- let value = dom.getStyle(previewElm, name, true);
- if (name === 'background-color' && /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)) {
- value = dom.getStyle(editor.getBody(), name, true);
- if (rgbaToHexString(value).toLowerCase() === '#ffffff') {
- return;
- }
- }
- if (name === 'color') {
- if (rgbaToHexString(value).toLowerCase() === '#000000') {
- return;
- }
- }
- if (name === 'font-size') {
- if (/em|%$/.test(value)) {
- if (parentFontSize === 0) {
- return;
- }
- const numValue = parseFloat(value) / (/%$/.test(value) ? 100 : 1);
- value = numValue * parentFontSize + 'px';
- }
- }
- if (name === 'border' && value) {
- previewCss += 'padding:0 2px;';
- }
- previewCss += name + ':' + value + ';';
- });
- editor.dispatch('AfterPreviewFormats');
- dom.remove(previewFrag);
- return previewCss;
- };
- const setup$r = editor => {
- editor.addShortcut('meta+b', '', 'Bold');
- editor.addShortcut('meta+i', '', 'Italic');
- editor.addShortcut('meta+u', '', 'Underline');
- for (let i = 1; i <= 6; i++) {
- editor.addShortcut('access+' + i, '', [
- 'FormatBlock',
- false,
- 'h' + i
- ]);
- }
- editor.addShortcut('access+7', '', [
- 'FormatBlock',
- false,
- 'p'
- ]);
- editor.addShortcut('access+8', '', [
- 'FormatBlock',
- false,
- 'div'
- ]);
- editor.addShortcut('access+9', '', [
- 'FormatBlock',
- false,
- 'address'
- ]);
- };
- const Formatter = editor => {
- const formats = FormatRegistry(editor);
- const formatChangeState = Cell(null);
- setup$r(editor);
- setup$u(editor);
- return {
- get: formats.get,
- has: formats.has,
- register: formats.register,
- unregister: formats.unregister,
- apply: (name, vars, node) => {
- applyFormat(editor, name, vars, node);
- },
- remove: (name, vars, node, similar) => {
- removeFormat(editor, name, vars, node, similar);
- },
- toggle: (name, vars, node) => {
- toggleFormat(editor, name, vars, node);
- },
- match: (name, vars, node, similar) => matchFormat(editor, name, vars, node, similar),
- closest: names => closestFormat(editor, names),
- matchAll: (names, vars) => matchAllFormats(editor, names, vars),
- matchNode: (node, name, vars, similar) => matchNodeFormat(editor, node, name, vars, similar),
- canApply: name => canApplyFormat(editor, name),
- formatChanged: (formats, callback, similar, vars) => formatChanged(editor, formatChangeState, formats, callback, similar, vars),
- getCssText: curry(getCssText, editor)
- };
- };
- const shouldIgnoreCommand = cmd => {
- switch (cmd.toLowerCase()) {
- case 'undo':
- case 'redo':
- case 'mcefocus':
- return true;
- default:
- return false;
- }
- };
- const registerEvents = (editor, undoManager, locks) => {
- const isFirstTypedCharacter = Cell(false);
- const addNonTypingUndoLevel = e => {
- setTyping(undoManager, false, locks);
- undoManager.add({}, e);
- };
- editor.on('init', () => {
- undoManager.add();
- });
- editor.on('BeforeExecCommand', e => {
- const cmd = e.command;
- if (!shouldIgnoreCommand(cmd)) {
- endTyping(undoManager, locks);
- undoManager.beforeChange();
- }
- });
- editor.on('ExecCommand', e => {
- const cmd = e.command;
- if (!shouldIgnoreCommand(cmd)) {
- addNonTypingUndoLevel(e);
- }
- });
- editor.on('ObjectResizeStart cut', () => {
- undoManager.beforeChange();
- });
- editor.on('SaveContent ObjectResized blur', addNonTypingUndoLevel);
- editor.on('dragend', addNonTypingUndoLevel);
- editor.on('keyup', e => {
- const keyCode = e.keyCode;
- if (e.isDefaultPrevented()) {
- return;
- }
- if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45 || e.ctrlKey) {
- addNonTypingUndoLevel();
- editor.nodeChanged();
- }
- if (keyCode === 46 || keyCode === 8) {
- editor.nodeChanged();
- }
- if (isFirstTypedCharacter.get() && undoManager.typing && isEq$1(createFromEditor(editor), undoManager.data[0]) === false) {
- if (editor.isDirty() === false) {
- editor.setDirty(true);
- }
- editor.dispatch('TypingUndo');
- isFirstTypedCharacter.set(false);
- editor.nodeChanged();
- }
- });
- editor.on('keydown', e => {
- const keyCode = e.keyCode;
- if (e.isDefaultPrevented()) {
- return;
- }
- if (keyCode >= 33 && keyCode <= 36 || keyCode >= 37 && keyCode <= 40 || keyCode === 45) {
- if (undoManager.typing) {
- addNonTypingUndoLevel(e);
- }
- return;
- }
- const modKey = e.ctrlKey && !e.altKey || e.metaKey;
- if ((keyCode < 16 || keyCode > 20) && keyCode !== 224 && keyCode !== 91 && !undoManager.typing && !modKey) {
- undoManager.beforeChange();
- setTyping(undoManager, true, locks);
- undoManager.add({}, e);
- isFirstTypedCharacter.set(true);
- }
- });
- editor.on('mousedown', e => {
- if (undoManager.typing) {
- addNonTypingUndoLevel(e);
- }
- });
- const isInsertReplacementText = event => event.inputType === 'insertReplacementText';
- const isInsertTextDataNull = event => event.inputType === 'insertText' && event.data === null;
- const isInsertFromPasteOrDrop = event => event.inputType === 'insertFromPaste' || event.inputType === 'insertFromDrop';
- editor.on('input', e => {
- if (e.inputType && (isInsertReplacementText(e) || isInsertTextDataNull(e) || isInsertFromPasteOrDrop(e))) {
- addNonTypingUndoLevel(e);
- }
- });
- editor.on('AddUndo Undo Redo ClearUndos', e => {
- if (!e.isDefaultPrevented()) {
- editor.nodeChanged();
- }
- });
- };
- const addKeyboardShortcuts = editor => {
- editor.addShortcut('meta+z', '', 'Undo');
- editor.addShortcut('meta+y,meta+shift+z', '', 'Redo');
- };
- const UndoManager = editor => {
- const beforeBookmark = value$2();
- const locks = Cell(0);
- const index = Cell(0);
- const undoManager = {
- data: [],
- typing: false,
- beforeChange: () => {
- beforeChange(editor, locks, beforeBookmark);
- },
- add: (level, event) => {
- return addUndoLevel(editor, undoManager, index, locks, beforeBookmark, level, event);
- },
- dispatchChange: () => {
- editor.setDirty(true);
- editor.dispatch('change', {
- level: createFromEditor(editor),
- lastLevel: get$b(undoManager.data, index.get()).getOrUndefined()
- });
- },
- undo: () => {
- return undo(editor, undoManager, locks, index);
- },
- redo: () => {
- return redo(editor, index, undoManager.data);
- },
- clear: () => {
- clear(editor, undoManager, index);
- },
- reset: () => {
- reset(editor, undoManager);
- },
- hasUndo: () => {
- return hasUndo(editor, undoManager, index);
- },
- hasRedo: () => {
- return hasRedo(editor, undoManager, index);
- },
- transact: callback => {
- return transact(editor, undoManager, locks, callback);
- },
- ignore: callback => {
- ignore(editor, locks, callback);
- },
- extra: (callback1, callback2) => {
- extra(editor, undoManager, index, callback1, callback2);
- }
- };
- if (!isRtc(editor)) {
- registerEvents(editor, undoManager, locks);
- }
- addKeyboardShortcuts(editor);
- return undoManager;
- };
- const nonTypingKeycodes = [
- 9,
- 27,
- VK.HOME,
- VK.END,
- 19,
- 20,
- 44,
- 144,
- 145,
- 33,
- 34,
- 45,
- 16,
- 17,
- 18,
- 91,
- 92,
- 93,
- VK.DOWN,
- VK.UP,
- VK.LEFT,
- VK.RIGHT
- ].concat(Env.browser.isFirefox() ? [224] : []);
- const placeholderAttr = 'data-mce-placeholder';
- const isKeyboardEvent = e => e.type === 'keydown' || e.type === 'keyup';
- const isDeleteEvent = e => {
- const keyCode = e.keyCode;
- return keyCode === VK.BACKSPACE || keyCode === VK.DELETE;
- };
- const isNonTypingKeyboardEvent = e => {
- if (isKeyboardEvent(e)) {
- const keyCode = e.keyCode;
- return !isDeleteEvent(e) && (VK.metaKeyPressed(e) || e.altKey || keyCode >= 112 && keyCode <= 123 || contains$2(nonTypingKeycodes, keyCode));
- } else {
- return false;
- }
- };
- const isTypingKeyboardEvent = e => isKeyboardEvent(e) && !(isDeleteEvent(e) || e.type === 'keyup' && e.keyCode === 229);
- const isVisuallyEmpty = (dom, rootElm, forcedRootBlock) => {
- if (isEmpty$2(SugarElement.fromDom(rootElm), false)) {
- const firstElement = rootElm.firstElementChild;
- if (!firstElement) {
- return true;
- } else if (dom.getStyle(rootElm.firstElementChild, 'padding-left') || dom.getStyle(rootElm.firstElementChild, 'padding-right')) {
- return false;
- } else {
- return forcedRootBlock === firstElement.nodeName.toLowerCase();
- }
- } else {
- return false;
- }
- };
- const setup$q = editor => {
- const dom = editor.dom;
- const rootBlock = getForcedRootBlock(editor);
- const placeholder = getPlaceholder(editor);
- const updatePlaceholder = (e, initial) => {
- if (isNonTypingKeyboardEvent(e)) {
- return;
- }
- const body = editor.getBody();
- const showPlaceholder = isTypingKeyboardEvent(e) ? false : isVisuallyEmpty(dom, body, rootBlock);
- const isPlaceholderShown = dom.getAttrib(body, placeholderAttr) !== '';
- if (isPlaceholderShown !== showPlaceholder || initial) {
- dom.setAttrib(body, placeholderAttr, showPlaceholder ? placeholder : null);
- dom.setAttrib(body, 'aria-placeholder', showPlaceholder ? placeholder : null);
- firePlaceholderToggle(editor, showPlaceholder);
- editor.on(showPlaceholder ? 'keydown' : 'keyup', updatePlaceholder);
- editor.off(showPlaceholder ? 'keyup' : 'keydown', updatePlaceholder);
- }
- };
- if (placeholder) {
- editor.on('init', e => {
- updatePlaceholder(e, true);
- editor.on('change SetContent ExecCommand', updatePlaceholder);
- editor.on('paste', e => Delay.setEditorTimeout(editor, () => updatePlaceholder(e)));
- });
- }
- };
- const blockPosition = (block, position) => ({
- block,
- position
- });
- const blockBoundary = (from, to) => ({
- from,
- to
- });
- const getBlockPosition = (rootNode, pos) => {
- const rootElm = SugarElement.fromDom(rootNode);
- const containerElm = SugarElement.fromDom(pos.container());
- return getParentBlock$2(rootElm, containerElm).map(block => blockPosition(block, pos));
- };
- const isDifferentBlocks = blockBoundary => eq(blockBoundary.from.block, blockBoundary.to.block) === false;
- const hasSameParent = blockBoundary => parent(blockBoundary.from.block).bind(parent1 => parent(blockBoundary.to.block).filter(parent2 => eq(parent1, parent2))).isSome();
- const isEditable$2 = blockBoundary => isContentEditableFalse$b(blockBoundary.from.block.dom) === false && isContentEditableFalse$b(blockBoundary.to.block.dom) === false;
- const skipLastBr = (rootNode, forward, blockPosition) => {
- if (isBr$6(blockPosition.position.getNode()) && isEmpty$2(blockPosition.block) === false) {
- return positionIn(false, blockPosition.block.dom).bind(lastPositionInBlock => {
- if (lastPositionInBlock.isEqual(blockPosition.position)) {
- return fromPosition(forward, rootNode, lastPositionInBlock).bind(to => getBlockPosition(rootNode, to));
- } else {
- return Optional.some(blockPosition);
- }
- }).getOr(blockPosition);
- } else {
- return blockPosition;
- }
- };
- const readFromRange = (rootNode, forward, rng) => {
- const fromBlockPos = getBlockPosition(rootNode, CaretPosition.fromRangeStart(rng));
- const toBlockPos = fromBlockPos.bind(blockPos => fromPosition(forward, rootNode, blockPos.position).bind(to => getBlockPosition(rootNode, to).map(blockPos => skipLastBr(rootNode, forward, blockPos))));
- return lift2(fromBlockPos, toBlockPos, blockBoundary).filter(blockBoundary => isDifferentBlocks(blockBoundary) && hasSameParent(blockBoundary) && isEditable$2(blockBoundary));
- };
- const read$1 = (rootNode, forward, rng) => rng.collapsed ? readFromRange(rootNode, forward, rng) : Optional.none();
- const getChildrenUntilBlockBoundary = block => {
- const children$1 = children(block);
- return findIndex$2(children$1, isBlock$2).fold(constant(children$1), index => children$1.slice(0, index));
- };
- const extractChildren = block => {
- const children = getChildrenUntilBlockBoundary(block);
- each$f(children, remove$6);
- return children;
- };
- const removeEmptyRoot = (rootNode, block) => {
- const parents = parentsAndSelf(block, rootNode);
- return find$2(parents.reverse(), element => isEmpty$2(element)).each(remove$6);
- };
- const isEmptyBefore = el => filter$6(prevSiblings(el), el => !isEmpty$2(el)).length === 0;
- const nestedBlockMerge = (rootNode, fromBlock, toBlock, insertionPoint) => {
- if (isEmpty$2(toBlock)) {
- fillWithPaddingBr(toBlock);
- return firstPositionIn(toBlock.dom);
- }
- if (isEmptyBefore(insertionPoint) && isEmpty$2(fromBlock)) {
- before$3(insertionPoint, SugarElement.fromTag('br'));
- }
- const position = prevPosition(toBlock.dom, CaretPosition.before(insertionPoint.dom));
- each$f(extractChildren(fromBlock), child => {
- before$3(insertionPoint, child);
- });
- removeEmptyRoot(rootNode, fromBlock);
- return position;
- };
- const sidelongBlockMerge = (rootNode, fromBlock, toBlock) => {
- if (isEmpty$2(toBlock)) {
- remove$6(toBlock);
- if (isEmpty$2(fromBlock)) {
- fillWithPaddingBr(fromBlock);
- }
- return firstPositionIn(fromBlock.dom);
- }
- const position = lastPositionIn(toBlock.dom);
- each$f(extractChildren(fromBlock), child => {
- append$1(toBlock, child);
- });
- removeEmptyRoot(rootNode, fromBlock);
- return position;
- };
- const findInsertionPoint = (toBlock, block) => {
- const parentsAndSelf$1 = parentsAndSelf(block, toBlock);
- return Optional.from(parentsAndSelf$1[parentsAndSelf$1.length - 1]);
- };
- const getInsertionPoint = (fromBlock, toBlock) => contains(toBlock, fromBlock) ? findInsertionPoint(toBlock, fromBlock) : Optional.none();
- const trimBr = (first, block) => {
- positionIn(first, block.dom).map(position => position.getNode()).map(SugarElement.fromDom).filter(isBr$5).each(remove$6);
- };
- const mergeBlockInto = (rootNode, fromBlock, toBlock) => {
- trimBr(true, fromBlock);
- trimBr(false, toBlock);
- return getInsertionPoint(fromBlock, toBlock).fold(curry(sidelongBlockMerge, rootNode, fromBlock, toBlock), curry(nestedBlockMerge, rootNode, fromBlock, toBlock));
- };
- const mergeBlocks = (rootNode, forward, block1, block2) => forward ? mergeBlockInto(rootNode, block2, block1) : mergeBlockInto(rootNode, block1, block2);
- const backspaceDelete$8 = (editor, forward) => {
- const rootNode = SugarElement.fromDom(editor.getBody());
- const position = read$1(rootNode.dom, forward, editor.selection.getRng()).map(blockBoundary => () => {
- mergeBlocks(rootNode, forward, blockBoundary.from.block, blockBoundary.to.block).each(pos => {
- editor.selection.setRng(pos.toRange());
- });
- });
- return position;
- };
- const deleteRangeMergeBlocks = (rootNode, selection) => {
- const rng = selection.getRng();
- return lift2(getParentBlock$2(rootNode, SugarElement.fromDom(rng.startContainer)), getParentBlock$2(rootNode, SugarElement.fromDom(rng.endContainer)), (block1, block2) => {
- if (eq(block1, block2) === false) {
- return Optional.some(() => {
- rng.deleteContents();
- mergeBlocks(rootNode, true, block1, block2).each(pos => {
- selection.setRng(pos.toRange());
- });
- });
- } else {
- return Optional.none();
- }
- }).getOr(Optional.none());
- };
- const isRawNodeInTable = (root, rawNode) => {
- const node = SugarElement.fromDom(rawNode);
- const isRoot = curry(eq, root);
- return ancestor$3(node, isTableCell$4, isRoot).isSome();
- };
- const isSelectionInTable = (root, rng) => isRawNodeInTable(root, rng.startContainer) || isRawNodeInTable(root, rng.endContainer);
- const isEverythingSelected = (root, rng) => {
- const noPrevious = prevPosition(root.dom, CaretPosition.fromRangeStart(rng)).isNone();
- const noNext = nextPosition(root.dom, CaretPosition.fromRangeEnd(rng)).isNone();
- return !isSelectionInTable(root, rng) && noPrevious && noNext;
- };
- const emptyEditor = editor => {
- return Optional.some(() => {
- editor.setContent('');
- editor.selection.setCursorLocation();
- });
- };
- const deleteRange$1 = editor => {
- const rootNode = SugarElement.fromDom(editor.getBody());
- const rng = editor.selection.getRng();
- return isEverythingSelected(rootNode, rng) ? emptyEditor(editor) : deleteRangeMergeBlocks(rootNode, editor.selection);
- };
- const backspaceDelete$7 = (editor, _forward) => editor.selection.isCollapsed() ? Optional.none() : deleteRange$1(editor);
- const isContentEditableTrue$2 = isContentEditableTrue$5;
- const isContentEditableFalse$5 = isContentEditableFalse$b;
- const showCaret = (direction, editor, node, before, scrollIntoView) => Optional.from(editor._selectionOverrides.showCaret(direction, node, before, scrollIntoView));
- const getNodeRange = node => {
- const rng = node.ownerDocument.createRange();
- rng.selectNode(node);
- return rng;
- };
- const selectNode = (editor, node) => {
- const e = editor.dispatch('BeforeObjectSelected', { target: node });
- if (e.isDefaultPrevented()) {
- return Optional.none();
- }
- return Optional.some(getNodeRange(node));
- };
- const renderCaretAtRange = (editor, range, scrollIntoView) => {
- const normalizedRange = normalizeRange(1, editor.getBody(), range);
- const caretPosition = CaretPosition.fromRangeStart(normalizedRange);
- const caretPositionNode = caretPosition.getNode();
- if (isInlineFakeCaretTarget(caretPositionNode)) {
- return showCaret(1, editor, caretPositionNode, !caretPosition.isAtEnd(), false);
- }
- const caretPositionBeforeNode = caretPosition.getNode(true);
- if (isInlineFakeCaretTarget(caretPositionBeforeNode)) {
- return showCaret(1, editor, caretPositionBeforeNode, false, false);
- }
- const ceRoot = editor.dom.getParent(caretPosition.getNode(), node => isContentEditableFalse$5(node) || isContentEditableTrue$2(node));
- if (isInlineFakeCaretTarget(ceRoot)) {
- return showCaret(1, editor, ceRoot, false, scrollIntoView);
- }
- return Optional.none();
- };
- const renderRangeCaret = (editor, range, scrollIntoView) => range.collapsed ? renderCaretAtRange(editor, range, scrollIntoView).getOr(range) : range;
- const isBeforeBoundary = pos => isBeforeContentEditableFalse(pos) || isBeforeMedia(pos);
- const isAfterBoundary = pos => isAfterContentEditableFalse(pos) || isAfterMedia(pos);
- const trimEmptyTextNode = (dom, node) => {
- if (isText$9(node) && node.data.length === 0) {
- dom.remove(node);
- }
- };
- const deleteContentAndShowCaret = (editor, range, node, direction, forward, peekCaretPosition) => {
- showCaret(direction, editor, peekCaretPosition.getNode(!forward), forward, true).each(caretRange => {
- if (range.collapsed) {
- const deleteRange = range.cloneRange();
- if (forward) {
- deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset);
- } else {
- deleteRange.setStart(caretRange.endContainer, caretRange.endOffset);
- }
- deleteRange.deleteContents();
- } else {
- range.deleteContents();
- }
- editor.selection.setRng(caretRange);
- });
- trimEmptyTextNode(editor.dom, node);
- };
- const deleteBoundaryText = (editor, forward) => {
- const range = editor.selection.getRng();
- if (!isText$9(range.commonAncestorContainer)) {
- return Optional.none();
- }
- const direction = forward ? HDirection.Forwards : HDirection.Backwards;
- const caretWalker = CaretWalker(editor.getBody());
- const getNextPosFn = curry(getVisualCaretPosition, forward ? caretWalker.next : caretWalker.prev);
- const isBeforeFn = forward ? isBeforeBoundary : isAfterBoundary;
- const caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
- const nextCaretPosition = normalizePosition(forward, getNextPosFn(caretPosition));
- if (!nextCaretPosition || !isMoveInsideSameBlock(caretPosition, nextCaretPosition)) {
- return Optional.none();
- } else if (isBeforeFn(nextCaretPosition)) {
- return Optional.some(() => deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, nextCaretPosition));
- }
- const peekCaretPosition = getNextPosFn(nextCaretPosition);
- if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
- if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
- return Optional.some(() => deleteContentAndShowCaret(editor, range, caretPosition.getNode(), direction, forward, peekCaretPosition));
- }
- }
- return Optional.none();
- };
- const backspaceDelete$6 = (editor, forward) => deleteBoundaryText(editor, forward);
- const getEdgeCefPosition = (editor, atStart) => {
- const root = editor.getBody();
- return atStart ? firstPositionIn(root).filter(isBeforeContentEditableFalse) : lastPositionIn(root).filter(isAfterContentEditableFalse);
- };
- const isCefAtEdgeSelected = editor => {
- const rng = editor.selection.getRng();
- return !rng.collapsed && (getEdgeCefPosition(editor, true).exists(pos => pos.isEqual(CaretPosition.fromRangeStart(rng))) || getEdgeCefPosition(editor, false).exists(pos => pos.isEqual(CaretPosition.fromRangeEnd(rng))));
- };
- const isCompoundElement = node => isTableCell$4(SugarElement.fromDom(node)) || isListItem(SugarElement.fromDom(node));
- const DeleteAction = Adt.generate([
- { remove: ['element'] },
- { moveToElement: ['element'] },
- { moveToPosition: ['position'] }
- ]);
- const isAtContentEditableBlockCaret = (forward, from) => {
- const elm = from.getNode(forward === false);
- const caretLocation = forward ? 'after' : 'before';
- return isElement$6(elm) && elm.getAttribute('data-mce-caret') === caretLocation;
- };
- const isDeleteFromCefDifferentBlocks = (root, forward, from, to) => {
- const inSameBlock = elm => isInline$1(SugarElement.fromDom(elm)) && !isInSameBlock(from, to, root);
- return getRelativeCefElm(!forward, from).fold(() => getRelativeCefElm(forward, to).fold(never, inSameBlock), inSameBlock);
- };
- const deleteEmptyBlockOrMoveToCef = (root, forward, from, to) => {
- const toCefElm = to.getNode(forward === false);
- return getParentBlock$2(SugarElement.fromDom(root), SugarElement.fromDom(from.getNode())).map(blockElm => isEmpty$2(blockElm) ? DeleteAction.remove(blockElm.dom) : DeleteAction.moveToElement(toCefElm)).orThunk(() => Optional.some(DeleteAction.moveToElement(toCefElm)));
- };
- const findCefPosition = (root, forward, from) => fromPosition(forward, root, from).bind(to => {
- if (isCompoundElement(to.getNode())) {
- return Optional.none();
- } else if (isDeleteFromCefDifferentBlocks(root, forward, from, to)) {
- return Optional.none();
- } else if (forward && isContentEditableFalse$b(to.getNode())) {
- return deleteEmptyBlockOrMoveToCef(root, forward, from, to);
- } else if (forward === false && isContentEditableFalse$b(to.getNode(true))) {
- return deleteEmptyBlockOrMoveToCef(root, forward, from, to);
- } else if (forward && isAfterContentEditableFalse(from)) {
- return Optional.some(DeleteAction.moveToPosition(to));
- } else if (forward === false && isBeforeContentEditableFalse(from)) {
- return Optional.some(DeleteAction.moveToPosition(to));
- } else {
- return Optional.none();
- }
- });
- const getContentEditableBlockAction = (forward, elm) => {
- if (forward && isContentEditableFalse$b(elm.nextSibling)) {
- return Optional.some(DeleteAction.moveToElement(elm.nextSibling));
- } else if (forward === false && isContentEditableFalse$b(elm.previousSibling)) {
- return Optional.some(DeleteAction.moveToElement(elm.previousSibling));
- } else {
- return Optional.none();
- }
- };
- const skipMoveToActionFromInlineCefToContent = (root, from, deleteAction) => deleteAction.fold(elm => Optional.some(DeleteAction.remove(elm)), elm => Optional.some(DeleteAction.moveToElement(elm)), to => {
- if (isInSameBlock(from, to, root)) {
- return Optional.none();
- } else {
- return Optional.some(DeleteAction.moveToPosition(to));
- }
- });
- const getContentEditableAction = (root, forward, from) => {
- if (isAtContentEditableBlockCaret(forward, from)) {
- return getContentEditableBlockAction(forward, from.getNode(forward === false)).fold(() => findCefPosition(root, forward, from), Optional.some);
- } else {
- return findCefPosition(root, forward, from).bind(deleteAction => skipMoveToActionFromInlineCefToContent(root, from, deleteAction));
- }
- };
- const read = (root, forward, rng) => {
- const normalizedRange = normalizeRange(forward ? 1 : -1, root, rng);
- const from = CaretPosition.fromRangeStart(normalizedRange);
- const rootElement = SugarElement.fromDom(root);
- if (forward === false && isAfterContentEditableFalse(from)) {
- return Optional.some(DeleteAction.remove(from.getNode(true)));
- } else if (forward && isBeforeContentEditableFalse(from)) {
- return Optional.some(DeleteAction.remove(from.getNode()));
- } else if (forward === false && isBeforeContentEditableFalse(from) && isAfterBr(rootElement, from)) {
- return findPreviousBr(rootElement, from).map(br => DeleteAction.remove(br.getNode()));
- } else if (forward && isAfterContentEditableFalse(from) && isBeforeBr$1(rootElement, from)) {
- return findNextBr(rootElement, from).map(br => DeleteAction.remove(br.getNode()));
- } else {
- return getContentEditableAction(root, forward, from);
- }
- };
- const deleteElement$1 = (editor, forward) => element => {
- editor._selectionOverrides.hideFakeCaret();
- deleteElement$2(editor, forward, SugarElement.fromDom(element));
- return true;
- };
- const moveToElement = (editor, forward) => element => {
- const pos = forward ? CaretPosition.before(element) : CaretPosition.after(element);
- editor.selection.setRng(pos.toRange());
- return true;
- };
- const moveToPosition = editor => pos => {
- editor.selection.setRng(pos.toRange());
- return true;
- };
- const getAncestorCe = (editor, node) => Optional.from(getContentEditableRoot$1(editor.getBody(), node));
- const backspaceDeleteCaret = (editor, forward) => {
- const selectedNode = editor.selection.getNode();
- return getAncestorCe(editor, selectedNode).filter(isContentEditableFalse$b).fold(() => read(editor.getBody(), forward, editor.selection.getRng()).map(deleteAction => () => deleteAction.fold(deleteElement$1(editor, forward), moveToElement(editor, forward), moveToPosition(editor))), () => Optional.some(noop));
- };
- const deleteOffscreenSelection = rootElement => {
- each$f(descendants(rootElement, '.mce-offscreen-selection'), remove$6);
- };
- const backspaceDeleteRange = (editor, forward) => {
- const selectedNode = editor.selection.getNode();
- if (isContentEditableFalse$b(selectedNode) && !isTableCell$5(selectedNode)) {
- const hasCefAncestor = getAncestorCe(editor, selectedNode.parentNode).filter(isContentEditableFalse$b);
- return hasCefAncestor.fold(() => Optional.some(() => {
- deleteOffscreenSelection(SugarElement.fromDom(editor.getBody()));
- deleteElement$2(editor, forward, SugarElement.fromDom(editor.selection.getNode()));
- paddEmptyBody(editor);
- }), () => Optional.some(noop));
- }
- if (isCefAtEdgeSelected(editor)) {
- return Optional.some(() => {
- deleteRangeContents(editor, editor.selection.getRng(), SugarElement.fromDom(editor.getBody()));
- });
- }
- return Optional.none();
- };
- const paddEmptyElement = editor => {
- const dom = editor.dom, selection = editor.selection;
- const ceRoot = getContentEditableRoot$1(editor.getBody(), selection.getNode());
- if (isContentEditableTrue$5(ceRoot) && dom.isBlock(ceRoot) && dom.isEmpty(ceRoot)) {
- const br = dom.create('br', { 'data-mce-bogus': '1' });
- dom.setHTML(ceRoot, '');
- ceRoot.appendChild(br);
- selection.setRng(CaretPosition.before(br).toRange());
- }
- return true;
- };
- const backspaceDelete$5 = (editor, forward) => {
- if (editor.selection.isCollapsed()) {
- return backspaceDeleteCaret(editor, forward);
- } else {
- return backspaceDeleteRange(editor, forward);
- }
- };
- const deleteCaret$2 = (editor, forward) => {
- const fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
- return fromPosition(forward, editor.getBody(), fromPos).filter(pos => forward ? isBeforeImageBlock(pos) : isAfterImageBlock(pos)).bind(pos => Optional.from(getChildNodeAtRelativeOffset(forward ? 0 : -1, pos))).map(elm => () => editor.selection.select(elm));
- };
- const backspaceDelete$4 = (editor, forward) => editor.selection.isCollapsed() ? deleteCaret$2(editor, forward) : Optional.none();
- const isText$2 = isText$9;
- const startsWithCaretContainer = node => isText$2(node) && node.data[0] === ZWSP$1;
- const endsWithCaretContainer = node => isText$2(node) && node.data[node.data.length - 1] === ZWSP$1;
- const createZwsp = node => node.ownerDocument.createTextNode(ZWSP$1);
- const insertBefore = node => {
- if (isText$2(node.previousSibling)) {
- if (endsWithCaretContainer(node.previousSibling)) {
- return node.previousSibling;
- } else {
- node.previousSibling.appendData(ZWSP$1);
- return node.previousSibling;
- }
- } else if (isText$2(node)) {
- if (startsWithCaretContainer(node)) {
- return node;
- } else {
- node.insertData(0, ZWSP$1);
- return node;
- }
- } else {
- const newNode = createZwsp(node);
- node.parentNode.insertBefore(newNode, node);
- return newNode;
- }
- };
- const insertAfter = node => {
- if (isText$2(node.nextSibling)) {
- if (startsWithCaretContainer(node.nextSibling)) {
- return node.nextSibling;
- } else {
- node.nextSibling.insertData(0, ZWSP$1);
- return node.nextSibling;
- }
- } else if (isText$2(node)) {
- if (endsWithCaretContainer(node)) {
- return node;
- } else {
- node.appendData(ZWSP$1);
- return node;
- }
- } else {
- const newNode = createZwsp(node);
- if (node.nextSibling) {
- node.parentNode.insertBefore(newNode, node.nextSibling);
- } else {
- node.parentNode.appendChild(newNode);
- }
- return newNode;
- }
- };
- const insertInline = (before, node) => before ? insertBefore(node) : insertAfter(node);
- const insertInlineBefore = curry(insertInline, true);
- const insertInlineAfter = curry(insertInline, false);
- const insertInlinePos = (pos, before) => {
- if (isText$9(pos.container())) {
- return insertInline(before, pos.container());
- } else {
- return insertInline(before, pos.getNode());
- }
- };
- const isPosCaretContainer = (pos, caret) => {
- const caretNode = caret.get();
- return caretNode && pos.container() === caretNode && isCaretContainerInline(caretNode);
- };
- const renderCaret = (caret, location) => location.fold(element => {
- remove$4(caret.get());
- const text = insertInlineBefore(element);
- caret.set(text);
- return Optional.some(CaretPosition(text, text.length - 1));
- }, element => firstPositionIn(element).map(pos => {
- if (!isPosCaretContainer(pos, caret)) {
- remove$4(caret.get());
- const text = insertInlinePos(pos, true);
- caret.set(text);
- return CaretPosition(text, 1);
- } else {
- return CaretPosition(caret.get(), 1);
- }
- }), element => lastPositionIn(element).map(pos => {
- if (!isPosCaretContainer(pos, caret)) {
- remove$4(caret.get());
- const text = insertInlinePos(pos, false);
- caret.set(text);
- return CaretPosition(text, text.length - 1);
- } else {
- return CaretPosition(caret.get(), caret.get().length - 1);
- }
- }), element => {
- remove$4(caret.get());
- const text = insertInlineAfter(element);
- caret.set(text);
- return Optional.some(CaretPosition(text, 1));
- });
- const evaluateUntil = (fns, args) => {
- for (let i = 0; i < fns.length; i++) {
- const result = fns[i].apply(null, args);
- if (result.isSome()) {
- return result;
- }
- }
- return Optional.none();
- };
- const Location = Adt.generate([
- { before: ['element'] },
- { start: ['element'] },
- { end: ['element'] },
- { after: ['element'] }
- ]);
- const rescope$1 = (rootNode, node) => {
- const parentBlock = getParentBlock$3(node, rootNode);
- return parentBlock ? parentBlock : rootNode;
- };
- const before = (isInlineTarget, rootNode, pos) => {
- const nPos = normalizeForwards(pos);
- const scope = rescope$1(rootNode, nPos.container());
- return findRootInline(isInlineTarget, scope, nPos).fold(() => nextPosition(scope, nPos).bind(curry(findRootInline, isInlineTarget, scope)).map(inline => Location.before(inline)), Optional.none);
- };
- const isNotInsideFormatCaretContainer = (rootNode, elm) => getParentCaretContainer(rootNode, elm) === null;
- const findInsideRootInline = (isInlineTarget, rootNode, pos) => findRootInline(isInlineTarget, rootNode, pos).filter(curry(isNotInsideFormatCaretContainer, rootNode));
- const start$1 = (isInlineTarget, rootNode, pos) => {
- const nPos = normalizeBackwards(pos);
- return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(inline => {
- const prevPos = prevPosition(inline, nPos);
- return prevPos.isNone() ? Optional.some(Location.start(inline)) : Optional.none();
- });
- };
- const end = (isInlineTarget, rootNode, pos) => {
- const nPos = normalizeForwards(pos);
- return findInsideRootInline(isInlineTarget, rootNode, nPos).bind(inline => {
- const nextPos = nextPosition(inline, nPos);
- return nextPos.isNone() ? Optional.some(Location.end(inline)) : Optional.none();
- });
- };
- const after = (isInlineTarget, rootNode, pos) => {
- const nPos = normalizeBackwards(pos);
- const scope = rescope$1(rootNode, nPos.container());
- return findRootInline(isInlineTarget, scope, nPos).fold(() => prevPosition(scope, nPos).bind(curry(findRootInline, isInlineTarget, scope)).map(inline => Location.after(inline)), Optional.none);
- };
- const isValidLocation = location => isRtl(getElement(location)) === false;
- const readLocation = (isInlineTarget, rootNode, pos) => {
- const location = evaluateUntil([
- before,
- start$1,
- end,
- after
- ], [
- isInlineTarget,
- rootNode,
- pos
- ]);
- return location.filter(isValidLocation);
- };
- const getElement = location => location.fold(identity, identity, identity, identity);
- const getName = location => location.fold(constant('before'), constant('start'), constant('end'), constant('after'));
- const outside = location => location.fold(Location.before, Location.before, Location.after, Location.after);
- const inside = location => location.fold(Location.start, Location.start, Location.end, Location.end);
- const isEq = (location1, location2) => getName(location1) === getName(location2) && getElement(location1) === getElement(location2);
- const betweenInlines = (forward, isInlineTarget, rootNode, from, to, location) => lift2(findRootInline(isInlineTarget, rootNode, from), findRootInline(isInlineTarget, rootNode, to), (fromInline, toInline) => {
- if (fromInline !== toInline && hasSameParentBlock(rootNode, fromInline, toInline)) {
- return Location.after(forward ? fromInline : toInline);
- } else {
- return location;
- }
- }).getOr(location);
- const skipNoMovement = (fromLocation, toLocation) => fromLocation.fold(always, fromLocation => !isEq(fromLocation, toLocation));
- const findLocationTraverse = (forward, isInlineTarget, rootNode, fromLocation, pos) => {
- const from = normalizePosition(forward, pos);
- const to = fromPosition(forward, rootNode, from).map(curry(normalizePosition, forward));
- const location = to.fold(() => fromLocation.map(outside), to => readLocation(isInlineTarget, rootNode, to).map(curry(betweenInlines, forward, isInlineTarget, rootNode, from, to)).filter(curry(skipNoMovement, fromLocation)));
- return location.filter(isValidLocation);
- };
- const findLocationSimple = (forward, location) => {
- if (forward) {
- return location.fold(compose(Optional.some, Location.start), Optional.none, compose(Optional.some, Location.after), Optional.none);
- } else {
- return location.fold(Optional.none, compose(Optional.some, Location.before), Optional.none, compose(Optional.some, Location.end));
- }
- };
- const findLocation$1 = (forward, isInlineTarget, rootNode, pos) => {
- const from = normalizePosition(forward, pos);
- const fromLocation = readLocation(isInlineTarget, rootNode, from);
- return readLocation(isInlineTarget, rootNode, from).bind(curry(findLocationSimple, forward)).orThunk(() => findLocationTraverse(forward, isInlineTarget, rootNode, fromLocation, pos));
- };
- const hasSelectionModifyApi = editor => {
- return isFunction(editor.selection.getSel().modify);
- };
- const moveRel = (forward, selection, pos) => {
- const delta = forward ? 1 : -1;
- selection.setRng(CaretPosition(pos.container(), pos.offset() + delta).toRange());
- selection.getSel().modify('move', forward ? 'forward' : 'backward', 'word');
- return true;
- };
- const moveByWord = (forward, editor) => {
- const rng = editor.selection.getRng();
- const pos = forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng);
- if (!hasSelectionModifyApi(editor)) {
- return false;
- } else if (forward && isBeforeInline(pos)) {
- return moveRel(true, editor.selection, pos);
- } else if (!forward && isAfterInline(pos)) {
- return moveRel(false, editor.selection, pos);
- } else {
- return false;
- }
- };
- var BreakType;
- (function (BreakType) {
- BreakType[BreakType['Br'] = 0] = 'Br';
- BreakType[BreakType['Block'] = 1] = 'Block';
- BreakType[BreakType['Wrap'] = 2] = 'Wrap';
- BreakType[BreakType['Eol'] = 3] = 'Eol';
- }(BreakType || (BreakType = {})));
- const flip = (direction, positions) => direction === HDirection.Backwards ? reverse(positions) : positions;
- const walk$1 = (direction, caretWalker, pos) => direction === HDirection.Forwards ? caretWalker.next(pos) : caretWalker.prev(pos);
- const getBreakType = (scope, direction, currentPos, nextPos) => {
- if (isBr$6(nextPos.getNode(direction === HDirection.Forwards))) {
- return BreakType.Br;
- } else if (isInSameBlock(currentPos, nextPos) === false) {
- return BreakType.Block;
- } else {
- return BreakType.Wrap;
- }
- };
- const getPositionsUntil = (predicate, direction, scope, start) => {
- const caretWalker = CaretWalker(scope);
- let currentPos = start;
- const positions = [];
- while (currentPos) {
- const nextPos = walk$1(direction, caretWalker, currentPos);
- if (!nextPos) {
- break;
- }
- if (isBr$6(nextPos.getNode(false))) {
- if (direction === HDirection.Forwards) {
- return {
- positions: flip(direction, positions).concat([nextPos]),
- breakType: BreakType.Br,
- breakAt: Optional.some(nextPos)
- };
- } else {
- return {
- positions: flip(direction, positions),
- breakType: BreakType.Br,
- breakAt: Optional.some(nextPos)
- };
- }
- }
- if (!nextPos.isVisible()) {
- currentPos = nextPos;
- continue;
- }
- if (predicate(currentPos, nextPos)) {
- const breakType = getBreakType(scope, direction, currentPos, nextPos);
- return {
- positions: flip(direction, positions),
- breakType,
- breakAt: Optional.some(nextPos)
- };
- }
- positions.push(nextPos);
- currentPos = nextPos;
- }
- return {
- positions: flip(direction, positions),
- breakType: BreakType.Eol,
- breakAt: Optional.none()
- };
- };
- const getAdjacentLinePositions = (direction, getPositionsUntilBreak, scope, start) => getPositionsUntilBreak(scope, start).breakAt.map(pos => {
- const positions = getPositionsUntilBreak(scope, pos).positions;
- return direction === HDirection.Backwards ? positions.concat(pos) : [pos].concat(positions);
- }).getOr([]);
- const findClosestHorizontalPositionFromPoint = (positions, x) => foldl(positions, (acc, newPos) => acc.fold(() => Optional.some(newPos), lastPos => lift2(head(lastPos.getClientRects()), head(newPos.getClientRects()), (lastRect, newRect) => {
- const lastDist = Math.abs(x - lastRect.left);
- const newDist = Math.abs(x - newRect.left);
- return newDist <= lastDist ? newPos : lastPos;
- }).or(acc)), Optional.none());
- const findClosestHorizontalPosition = (positions, pos) => head(pos.getClientRects()).bind(targetRect => findClosestHorizontalPositionFromPoint(positions, targetRect.left));
- const getPositionsUntilPreviousLine = curry(getPositionsUntil, CaretPosition.isAbove, -1);
- const getPositionsUntilNextLine = curry(getPositionsUntil, CaretPosition.isBelow, 1);
- const getPositionsAbove = curry(getAdjacentLinePositions, -1, getPositionsUntilPreviousLine);
- const getPositionsBelow = curry(getAdjacentLinePositions, 1, getPositionsUntilNextLine);
- const isAtFirstLine = (scope, pos) => getPositionsUntilPreviousLine(scope, pos).breakAt.isNone();
- const isAtLastLine = (scope, pos) => getPositionsUntilNextLine(scope, pos).breakAt.isNone();
- const getFirstLinePositions = scope => firstPositionIn(scope).map(pos => [pos].concat(getPositionsUntilNextLine(scope, pos).positions)).getOr([]);
- const getLastLinePositions = scope => lastPositionIn(scope).map(pos => getPositionsUntilPreviousLine(scope, pos).positions.concat(pos)).getOr([]);
- const getClosestPositionAbove = (scope, pos) => findClosestHorizontalPosition(getPositionsAbove(scope, pos), pos);
- const getClosestPositionBelow = (scope, pos) => findClosestHorizontalPosition(getPositionsBelow(scope, pos), pos);
- const isContentEditableFalse$4 = isContentEditableFalse$b;
- const distanceToRectLeft$1 = (clientRect, clientX) => Math.abs(clientRect.left - clientX);
- const distanceToRectRight$1 = (clientRect, clientX) => Math.abs(clientRect.right - clientX);
- const isNodeClientRect = rect => hasNonNullableKey(rect, 'node');
- const findClosestClientRect = (clientRects, clientX) => reduce(clientRects, (oldClientRect, clientRect) => {
- const oldDistance = Math.min(distanceToRectLeft$1(oldClientRect, clientX), distanceToRectRight$1(oldClientRect, clientX));
- const newDistance = Math.min(distanceToRectLeft$1(clientRect, clientX), distanceToRectRight$1(clientRect, clientX));
- if (newDistance === oldDistance && isNodeClientRect(clientRect) && isContentEditableFalse$4(clientRect.node)) {
- return clientRect;
- }
- if (newDistance < oldDistance) {
- return clientRect;
- }
- return oldClientRect;
- });
- const getNodeClientRects = node => {
- const toArrayWithNode = clientRects => {
- return map$3(clientRects, rect => {
- const clientRect = clone$1(rect);
- clientRect.node = node;
- return clientRect;
- });
- };
- if (isElement$6(node)) {
- return toArrayWithNode(node.getClientRects());
- } else if (isText$9(node)) {
- const rng = node.ownerDocument.createRange();
- rng.setStart(node, 0);
- rng.setEnd(node, node.data.length);
- return toArrayWithNode(rng.getClientRects());
- } else {
- return [];
- }
- };
- const getClientRects = nodes => bind$3(nodes, getNodeClientRects);
- var VDirection;
- (function (VDirection) {
- VDirection[VDirection['Up'] = -1] = 'Up';
- VDirection[VDirection['Down'] = 1] = 'Down';
- }(VDirection || (VDirection = {})));
- const findUntil = (direction, root, predicateFn, node) => {
- while (node = findNode(node, direction, isEditableCaretCandidate$1, root)) {
- if (predicateFn(node)) {
- return;
- }
- }
- };
- const walkUntil = (direction, isAboveFn, isBeflowFn, root, predicateFn, caretPosition) => {
- let line = 0;
- const result = [];
- const add = node => {
- let clientRects = getClientRects([node]);
- if (direction === -1) {
- clientRects = clientRects.reverse();
- }
- for (let i = 0; i < clientRects.length; i++) {
- const clientRect = clientRects[i];
- if (isBeflowFn(clientRect, targetClientRect)) {
- continue;
- }
- if (result.length > 0 && isAboveFn(clientRect, last$2(result))) {
- line++;
- }
- clientRect.line = line;
- if (predicateFn(clientRect)) {
- return true;
- }
- result.push(clientRect);
- }
- };
- const targetClientRect = last$2(caretPosition.getClientRects());
- if (!targetClientRect) {
- return result;
- }
- const node = caretPosition.getNode();
- add(node);
- findUntil(direction, root, add, node);
- return result;
- };
- const aboveLineNumber = (lineNumber, clientRect) => clientRect.line > lineNumber;
- const isLineNumber = (lineNumber, clientRect) => clientRect.line === lineNumber;
- const upUntil = curry(walkUntil, VDirection.Up, isAbove$1, isBelow$1);
- const downUntil = curry(walkUntil, VDirection.Down, isBelow$1, isAbove$1);
- const positionsUntil = (direction, root, predicateFn, node) => {
- const caretWalker = CaretWalker(root);
- let walkFn;
- let isBelowFn;
- let isAboveFn;
- let caretPosition;
- const result = [];
- let line = 0;
- const getClientRect = caretPosition => {
- if (direction === 1) {
- return last$2(caretPosition.getClientRects());
- }
- return last$2(caretPosition.getClientRects());
- };
- if (direction === 1) {
- walkFn = caretWalker.next;
- isBelowFn = isBelow$1;
- isAboveFn = isAbove$1;
- caretPosition = CaretPosition.after(node);
- } else {
- walkFn = caretWalker.prev;
- isBelowFn = isAbove$1;
- isAboveFn = isBelow$1;
- caretPosition = CaretPosition.before(node);
- }
- const targetClientRect = getClientRect(caretPosition);
- do {
- if (!caretPosition.isVisible()) {
- continue;
- }
- const rect = getClientRect(caretPosition);
- if (isAboveFn(rect, targetClientRect)) {
- continue;
- }
- if (result.length > 0 && isBelowFn(rect, last$2(result))) {
- line++;
- }
- const clientRect = clone$1(rect);
- clientRect.position = caretPosition;
- clientRect.line = line;
- if (predicateFn(clientRect)) {
- return result;
- }
- result.push(clientRect);
- } while (caretPosition = walkFn(caretPosition));
- return result;
- };
- const isAboveLine = lineNumber => clientRect => aboveLineNumber(lineNumber, clientRect);
- const isLine = lineNumber => clientRect => isLineNumber(lineNumber, clientRect);
- const moveToRange = (editor, rng) => {
- editor.selection.setRng(rng);
- scrollRangeIntoView(editor, editor.selection.getRng());
- };
- const renderRangeCaretOpt = (editor, range, scrollIntoView) => Optional.some(renderRangeCaret(editor, range, scrollIntoView));
- const moveHorizontally = (editor, direction, range, isBefore, isAfter, isElement) => {
- const forwards = direction === HDirection.Forwards;
- const caretWalker = CaretWalker(editor.getBody());
- const getNextPosFn = curry(getVisualCaretPosition, forwards ? caretWalker.next : caretWalker.prev);
- const isBeforeFn = forwards ? isBefore : isAfter;
- if (!range.collapsed) {
- const node = getSelectedNode(range);
- if (isElement(node)) {
- return showCaret(direction, editor, node, direction === HDirection.Backwards, false);
- } else if (isCefAtEdgeSelected(editor)) {
- const newRange = range.cloneRange();
- newRange.collapse(direction === HDirection.Backwards);
- return Optional.from(newRange);
- }
- }
- const caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
- if (isBeforeFn(caretPosition)) {
- return selectNode(editor, caretPosition.getNode(!forwards));
- }
- const nextCaretPosition = normalizePosition(forwards, getNextPosFn(caretPosition));
- const rangeIsInContainerBlock = isRangeInCaretContainerBlock(range);
- if (!nextCaretPosition) {
- return rangeIsInContainerBlock ? Optional.some(range) : Optional.none();
- }
- if (isBeforeFn(nextCaretPosition)) {
- return showCaret(direction, editor, nextCaretPosition.getNode(!forwards), forwards, false);
- }
- const peekCaretPosition = getNextPosFn(nextCaretPosition);
- if (peekCaretPosition && isBeforeFn(peekCaretPosition)) {
- if (isMoveInsideSameBlock(nextCaretPosition, peekCaretPosition)) {
- return showCaret(direction, editor, peekCaretPosition.getNode(!forwards), forwards, false);
- }
- }
- if (rangeIsInContainerBlock) {
- return renderRangeCaretOpt(editor, nextCaretPosition.toRange(), false);
- }
- return Optional.none();
- };
- const moveVertically = (editor, direction, range, isBefore, isAfter, isElement) => {
- const caretPosition = getNormalizedRangeEndPoint(direction, editor.getBody(), range);
- const caretClientRect = last$2(caretPosition.getClientRects());
- const forwards = direction === VDirection.Down;
- const root = editor.getBody();
- if (!caretClientRect) {
- return Optional.none();
- }
- if (isCefAtEdgeSelected(editor)) {
- const caretPosition = forwards ? CaretPosition.fromRangeEnd(range) : CaretPosition.fromRangeStart(range);
- const getClosestFn = !forwards ? getClosestPositionAbove : getClosestPositionBelow;
- return getClosestFn(root, caretPosition).orThunk(() => Optional.from(caretPosition)).map(pos => pos.toRange());
- }
- const walkerFn = forwards ? downUntil : upUntil;
- const linePositions = walkerFn(root, isAboveLine(1), caretPosition);
- const nextLinePositions = filter$6(linePositions, isLine(1));
- const clientX = caretClientRect.left;
- const nextLineRect = findClosestClientRect(nextLinePositions, clientX);
- if (nextLineRect && isElement(nextLineRect.node)) {
- const dist1 = Math.abs(clientX - nextLineRect.left);
- const dist2 = Math.abs(clientX - nextLineRect.right);
- return showCaret(direction, editor, nextLineRect.node, dist1 < dist2, false);
- }
- let currentNode;
- if (isBefore(caretPosition)) {
- currentNode = caretPosition.getNode();
- } else if (isAfter(caretPosition)) {
- currentNode = caretPosition.getNode(true);
- } else {
- currentNode = getSelectedNode(range);
- }
- if (currentNode) {
- const caretPositions = positionsUntil(direction, root, isAboveLine(1), currentNode);
- let closestNextLineRect = findClosestClientRect(filter$6(caretPositions, isLine(1)), clientX);
- if (closestNextLineRect) {
- return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
- }
- closestNextLineRect = last$2(filter$6(caretPositions, isLine(0)));
- if (closestNextLineRect) {
- return renderRangeCaretOpt(editor, closestNextLineRect.position.toRange(), false);
- }
- }
- if (nextLinePositions.length === 0) {
- return getLineEndPoint(editor, forwards).filter(forwards ? isAfter : isBefore).map(pos => renderRangeCaret(editor, pos.toRange(), false));
- }
- return Optional.none();
- };
- const getLineEndPoint = (editor, forward) => {
- const rng = editor.selection.getRng();
- const from = forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng);
- const host = getEditingHost(from.container(), editor.getBody());
- if (forward) {
- const lineInfo = getPositionsUntilNextLine(host, from);
- return last$3(lineInfo.positions);
- } else {
- const lineInfo = getPositionsUntilPreviousLine(host, from);
- return head(lineInfo.positions);
- }
- };
- const moveToLineEndPoint$3 = (editor, forward, isElementPosition) => getLineEndPoint(editor, forward).filter(isElementPosition).exists(pos => {
- editor.selection.setRng(pos.toRange());
- return true;
- });
- const setCaretPosition = (editor, pos) => {
- const rng = editor.dom.createRng();
- rng.setStart(pos.container(), pos.offset());
- rng.setEnd(pos.container(), pos.offset());
- editor.selection.setRng(rng);
- };
- const setSelected = (state, elm) => {
- if (state) {
- elm.setAttribute('data-mce-selected', 'inline-boundary');
- } else {
- elm.removeAttribute('data-mce-selected');
- }
- };
- const renderCaretLocation = (editor, caret, location) => renderCaret(caret, location).map(pos => {
- setCaretPosition(editor, pos);
- return location;
- });
- const getPositionFromRange = (range, root, forward) => {
- const start = CaretPosition.fromRangeStart(range);
- if (range.collapsed) {
- return start;
- } else {
- const end = CaretPosition.fromRangeEnd(range);
- return forward ? prevPosition(root, end).getOr(end) : nextPosition(root, start).getOr(start);
- }
- };
- const findLocation = (editor, caret, forward) => {
- const rootNode = editor.getBody();
- const from = getPositionFromRange(editor.selection.getRng(), rootNode, forward);
- const isInlineTarget$1 = curry(isInlineTarget, editor);
- const location = findLocation$1(forward, isInlineTarget$1, rootNode, from);
- return location.bind(location => renderCaretLocation(editor, caret, location));
- };
- const toggleInlines = (isInlineTarget, dom, elms) => {
- const inlineBoundaries = map$3(descendants(SugarElement.fromDom(dom.getRoot()), '*[data-mce-selected="inline-boundary"]'), e => e.dom);
- const selectedInlines = filter$6(inlineBoundaries, isInlineTarget);
- const targetInlines = filter$6(elms, isInlineTarget);
- each$f(difference(selectedInlines, targetInlines), curry(setSelected, false));
- each$f(difference(targetInlines, selectedInlines), curry(setSelected, true));
- };
- const safeRemoveCaretContainer = (editor, caret) => {
- if (editor.selection.isCollapsed() && editor.composing !== true && caret.get()) {
- const pos = CaretPosition.fromRangeStart(editor.selection.getRng());
- if (CaretPosition.isTextPosition(pos) && isAtZwsp(pos) === false) {
- setCaretPosition(editor, removeAndReposition(caret.get(), pos));
- caret.set(null);
- }
- }
- };
- const renderInsideInlineCaret = (isInlineTarget, editor, caret, elms) => {
- if (editor.selection.isCollapsed()) {
- const inlines = filter$6(elms, isInlineTarget);
- each$f(inlines, _inline => {
- const pos = CaretPosition.fromRangeStart(editor.selection.getRng());
- readLocation(isInlineTarget, editor.getBody(), pos).bind(location => renderCaretLocation(editor, caret, location));
- });
- }
- };
- const move$2 = (editor, caret, forward) => isInlineBoundariesEnabled(editor) ? findLocation(editor, caret, forward).isSome() : false;
- const moveWord = (forward, editor, _caret) => isInlineBoundariesEnabled(editor) ? moveByWord(forward, editor) : false;
- const setupSelectedState = editor => {
- const caret = Cell(null);
- const isInlineTarget$1 = curry(isInlineTarget, editor);
- editor.on('NodeChange', e => {
- if (isInlineBoundariesEnabled(editor)) {
- toggleInlines(isInlineTarget$1, editor.dom, e.parents);
- safeRemoveCaretContainer(editor, caret);
- renderInsideInlineCaret(isInlineTarget$1, editor, caret, e.parents);
- }
- });
- return caret;
- };
- const moveNextWord = curry(moveWord, true);
- const movePrevWord = curry(moveWord, false);
- const moveToLineEndPoint$2 = (editor, forward, caret) => {
- if (isInlineBoundariesEnabled(editor)) {
- const linePoint = getLineEndPoint(editor, forward).getOrThunk(() => {
- const rng = editor.selection.getRng();
- return forward ? CaretPosition.fromRangeEnd(rng) : CaretPosition.fromRangeStart(rng);
- });
- return readLocation(curry(isInlineTarget, editor), editor.getBody(), linePoint).exists(loc => {
- const outsideLoc = outside(loc);
- return renderCaret(caret, outsideLoc).exists(pos => {
- setCaretPosition(editor, pos);
- return true;
- });
- });
- } else {
- return false;
- }
- };
- const rangeFromPositions = (from, to) => {
- const range = document.createRange();
- range.setStart(from.container(), from.offset());
- range.setEnd(to.container(), to.offset());
- return range;
- };
- const hasOnlyTwoOrLessPositionsLeft = elm => lift2(firstPositionIn(elm), lastPositionIn(elm), (firstPos, lastPos) => {
- const normalizedFirstPos = normalizePosition(true, firstPos);
- const normalizedLastPos = normalizePosition(false, lastPos);
- return nextPosition(elm, normalizedFirstPos).forall(pos => pos.isEqual(normalizedLastPos));
- }).getOr(true);
- const setCaretLocation = (editor, caret) => location => renderCaret(caret, location).map(pos => () => setCaretPosition(editor, pos));
- const deleteFromTo = (editor, caret, from, to) => {
- const rootNode = editor.getBody();
- const isInlineTarget$1 = curry(isInlineTarget, editor);
- editor.undoManager.ignore(() => {
- editor.selection.setRng(rangeFromPositions(from, to));
- execDeleteCommand(editor);
- readLocation(isInlineTarget$1, rootNode, CaretPosition.fromRangeStart(editor.selection.getRng())).map(inside).bind(setCaretLocation(editor, caret)).each(call);
- });
- editor.nodeChanged();
- };
- const rescope = (rootNode, node) => {
- const parentBlock = getParentBlock$3(node, rootNode);
- return parentBlock ? parentBlock : rootNode;
- };
- const backspaceDeleteCollapsed = (editor, caret, forward, from) => {
- const rootNode = rescope(editor.getBody(), from.container());
- const isInlineTarget$1 = curry(isInlineTarget, editor);
- const fromLocation = readLocation(isInlineTarget$1, rootNode, from);
- const location = fromLocation.bind(location => {
- if (forward) {
- return location.fold(constant(Optional.some(inside(location))), Optional.none, constant(Optional.some(outside(location))), Optional.none);
- } else {
- return location.fold(Optional.none, constant(Optional.some(outside(location))), Optional.none, constant(Optional.some(inside(location))));
- }
- });
- return location.map(setCaretLocation(editor, caret)).getOrThunk(() => {
- const toPosition = navigate(forward, rootNode, from);
- const toLocation = toPosition.bind(pos => readLocation(isInlineTarget$1, rootNode, pos));
- return lift2(fromLocation, toLocation, () => findRootInline(isInlineTarget$1, rootNode, from).bind(elm => {
- if (hasOnlyTwoOrLessPositionsLeft(elm)) {
- return Optional.some(() => {
- deleteElement$2(editor, forward, SugarElement.fromDom(elm));
- });
- } else {
- return Optional.none();
- }
- })).getOrThunk(() => toLocation.bind(() => toPosition.map(to => {
- return () => {
- if (forward) {
- deleteFromTo(editor, caret, from, to);
- } else {
- deleteFromTo(editor, caret, to, from);
- }
- };
- })));
- });
- };
- const backspaceDelete$3 = (editor, caret, forward) => {
- if (editor.selection.isCollapsed() && isInlineBoundariesEnabled(editor)) {
- const from = CaretPosition.fromRangeStart(editor.selection.getRng());
- return backspaceDeleteCollapsed(editor, caret, forward, from);
- }
- return Optional.none();
- };
- const getParentInlines = (rootElm, startElm) => {
- const parents = parentsAndSelf(startElm, rootElm);
- return findIndex$2(parents, isBlock$2).fold(constant(parents), index => parents.slice(0, index));
- };
- const hasOnlyOneChild = elm => childNodesCount(elm) === 1;
- const deleteLastPosition = (forward, editor, target, parentInlines) => {
- const isFormatElement$1 = curry(isFormatElement, editor);
- const formatNodes = map$3(filter$6(parentInlines, isFormatElement$1), elm => elm.dom);
- if (formatNodes.length === 0) {
- deleteElement$2(editor, forward, target);
- } else {
- const pos = replaceWithCaretFormat(target.dom, formatNodes);
- editor.selection.setRng(pos.toRange());
- }
- };
- const deleteCaret$1 = (editor, forward) => {
- const rootElm = SugarElement.fromDom(editor.getBody());
- const startElm = SugarElement.fromDom(editor.selection.getStart());
- const parentInlines = filter$6(getParentInlines(rootElm, startElm), hasOnlyOneChild);
- return last$3(parentInlines).bind(target => {
- const fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());
- if (willDeleteLastPositionInElement(forward, fromPos, target.dom) && !isEmptyCaretFormatElement(target)) {
- return Optional.some(() => deleteLastPosition(forward, editor, target, parentInlines));
- } else {
- return Optional.none();
- }
- });
- };
- const backspaceDelete$2 = (editor, forward) => editor.selection.isCollapsed() ? deleteCaret$1(editor, forward) : Optional.none();
- const deleteElement = (editor, forward, element) => {
- return Optional.some(() => {
- editor._selectionOverrides.hideFakeCaret();
- deleteElement$2(editor, forward, SugarElement.fromDom(element));
- });
- };
- const deleteCaret = (editor, forward) => {
- const isNearMedia = forward ? isBeforeMedia : isAfterMedia;
- const direction = forward ? HDirection.Forwards : HDirection.Backwards;
- const fromPos = getNormalizedRangeEndPoint(direction, editor.getBody(), editor.selection.getRng());
- if (isNearMedia(fromPos)) {
- return deleteElement(editor, forward, fromPos.getNode(!forward));
- } else {
- return Optional.from(normalizePosition(forward, fromPos)).filter(pos => isNearMedia(pos) && isMoveInsideSameBlock(fromPos, pos)).map(pos => () => deleteElement(editor, forward, pos.getNode(!forward)));
- }
- };
- const deleteRange = (editor, forward) => {
- const selectedNode = editor.selection.getNode();
- return isMedia$2(selectedNode) ? deleteElement(editor, forward, selectedNode) : Optional.none();
- };
- const backspaceDelete$1 = (editor, forward) => editor.selection.isCollapsed() ? deleteCaret(editor, forward) : deleteRange(editor, forward);
- const isEditable$1 = target => closest$4(target, elm => isContentEditableTrue$5(elm.dom) || isContentEditableFalse$b(elm.dom)).exists(elm => isContentEditableTrue$5(elm.dom));
- const parseIndentValue = value => {
- const number = parseInt(value, 10);
- return isNaN(number) ? 0 : number;
- };
- const getIndentStyleName = (useMargin, element) => {
- const indentStyleName = useMargin || isTable$2(element) ? 'margin' : 'padding';
- const suffix = get$7(element, 'direction') === 'rtl' ? '-right' : '-left';
- return indentStyleName + suffix;
- };
- const indentElement = (dom, command, useMargin, value, unit, element) => {
- const indentStyleName = getIndentStyleName(useMargin, SugarElement.fromDom(element));
- if (command === 'outdent') {
- const styleValue = Math.max(0, parseIndentValue(element.style[indentStyleName]) - value);
- dom.setStyle(element, indentStyleName, styleValue ? styleValue + unit : '');
- } else {
- const styleValue = parseIndentValue(element.style[indentStyleName]) + value + unit;
- dom.setStyle(element, indentStyleName, styleValue);
- }
- };
- const validateBlocks = (editor, blocks) => forall(blocks, block => {
- const indentStyleName = getIndentStyleName(shouldIndentUseMargin(editor), block);
- const intentValue = getRaw$1(block, indentStyleName).map(parseIndentValue).getOr(0);
- const contentEditable = editor.dom.getContentEditable(block.dom);
- return contentEditable !== 'false' && intentValue > 0;
- });
- const canOutdent = editor => {
- const blocks = getBlocksToIndent(editor);
- return !editor.mode.isReadOnly() && (blocks.length > 1 || validateBlocks(editor, blocks));
- };
- const isListComponent = el => isList(el) || isListItem(el);
- const parentIsListComponent = el => parent(el).exists(isListComponent);
- const getBlocksToIndent = editor => filter$6(fromDom$1(editor.selection.getSelectedBlocks()), el => !isListComponent(el) && !parentIsListComponent(el) && isEditable$1(el));
- const handle = (editor, command) => {
- const {dom} = editor;
- const indentation = getIndentation(editor);
- const indentUnit = /[a-z%]+$/i.exec(indentation)[0];
- const indentValue = parseInt(indentation, 10);
- const useMargin = shouldIndentUseMargin(editor);
- each$f(getBlocksToIndent(editor), block => {
- indentElement(dom, command, useMargin, indentValue, indentUnit, block.dom);
- });
- };
- const indent = editor => handle(editor, 'indent');
- const outdent = editor => handle(editor, 'outdent');
- const backspaceDelete = editor => {
- if (editor.selection.isCollapsed() && canOutdent(editor)) {
- const dom = editor.dom;
- const rng = editor.selection.getRng();
- const pos = CaretPosition.fromRangeStart(rng);
- const block = dom.getParent(rng.startContainer, dom.isBlock);
- if (block !== null && isAtStartOfBlock(SugarElement.fromDom(block), pos)) {
- return Optional.some(() => outdent(editor));
- }
- }
- return Optional.none();
- };
- const findAction = (editor, caret, forward) => findMap([
- backspaceDelete,
- backspaceDelete$5,
- backspaceDelete$6,
- (editor, forward) => backspaceDelete$3(editor, caret, forward),
- backspaceDelete$8,
- backspaceDelete$9,
- backspaceDelete$4,
- backspaceDelete$1,
- backspaceDelete$7,
- backspaceDelete$2
- ], item => item(editor, forward));
- const deleteCommand = (editor, caret) => {
- const result = findAction(editor, caret, false);
- result.fold(() => {
- execDeleteCommand(editor);
- paddEmptyBody(editor);
- }, call);
- };
- const forwardDeleteCommand = (editor, caret) => {
- const result = findAction(editor, caret, true);
- result.fold(() => execForwardDeleteCommand(editor), call);
- };
- const setup$p = (editor, caret) => {
- editor.addCommand('delete', () => {
- deleteCommand(editor, caret);
- });
- editor.addCommand('forwardDelete', () => {
- forwardDeleteCommand(editor, caret);
- });
- };
- const SIGNIFICANT_MOVE = 5;
- const LONGPRESS_DELAY = 400;
- const getTouch = event => {
- if (event.touches === undefined || event.touches.length !== 1) {
- return Optional.none();
- }
- return Optional.some(event.touches[0]);
- };
- const isFarEnough = (touch, data) => {
- const distX = Math.abs(touch.clientX - data.x);
- const distY = Math.abs(touch.clientY - data.y);
- return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
- };
- const setup$o = editor => {
- const startData = value$2();
- const longpressFired = Cell(false);
- const debounceLongpress = last$1(e => {
- editor.dispatch('longpress', {
- ...e,
- type: 'longpress'
- });
- longpressFired.set(true);
- }, LONGPRESS_DELAY);
- editor.on('touchstart', e => {
- getTouch(e).each(touch => {
- debounceLongpress.cancel();
- const data = {
- x: touch.clientX,
- y: touch.clientY,
- target: e.target
- };
- debounceLongpress.throttle(e);
- longpressFired.set(false);
- startData.set(data);
- });
- }, true);
- editor.on('touchmove', e => {
- debounceLongpress.cancel();
- getTouch(e).each(touch => {
- startData.on(data => {
- if (isFarEnough(touch, data)) {
- startData.clear();
- longpressFired.set(false);
- editor.dispatch('longpresscancel');
- }
- });
- });
- }, true);
- editor.on('touchend touchcancel', e => {
- debounceLongpress.cancel();
- if (e.type === 'touchcancel') {
- return;
- }
- startData.get().filter(data => data.target.isEqualNode(e.target)).each(() => {
- if (longpressFired.get()) {
- e.preventDefault();
- } else {
- editor.dispatch('tap', {
- ...e,
- type: 'tap'
- });
- }
- });
- }, true);
- };
- const isBlockElement = (blockElements, node) => has$2(blockElements, node.nodeName);
- const isValidTarget = (blockElements, node) => {
- if (isText$9(node)) {
- return true;
- } else if (isElement$6(node)) {
- return !isBlockElement(blockElements, node) && !isBookmarkNode$1(node);
- } else {
- return false;
- }
- };
- const hasBlockParent = (blockElements, root, node) => {
- return exists(parents(SugarElement.fromDom(node), SugarElement.fromDom(root)), elm => {
- return isBlockElement(blockElements, elm.dom);
- });
- };
- const shouldRemoveTextNode = (blockElements, node) => {
- if (isText$9(node)) {
- if (node.nodeValue.length === 0) {
- return true;
- } else if (/^\s+$/.test(node.nodeValue) && (!node.nextSibling || isBlockElement(blockElements, node.nextSibling))) {
- return true;
- }
- }
- return false;
- };
- const addRootBlocks = editor => {
- const dom = editor.dom, selection = editor.selection;
- const schema = editor.schema, blockElements = schema.getBlockElements();
- let node = selection.getStart();
- const rootNode = editor.getBody();
- let rootBlockNode, tempNode, wrapped;
- const forcedRootBlock = getForcedRootBlock(editor);
- if (!node || !isElement$6(node)) {
- return;
- }
- const rootNodeName = rootNode.nodeName.toLowerCase();
- if (!schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase()) || hasBlockParent(blockElements, rootNode, node)) {
- return;
- }
- const rng = selection.getRng();
- const startContainer = rng.startContainer;
- const startOffset = rng.startOffset;
- const endContainer = rng.endContainer;
- const endOffset = rng.endOffset;
- const restoreSelection = hasFocus(editor);
- node = rootNode.firstChild;
- while (node) {
- if (isValidTarget(blockElements, node)) {
- if (shouldRemoveTextNode(blockElements, node)) {
- tempNode = node;
- node = node.nextSibling;
- dom.remove(tempNode);
- continue;
- }
- if (!rootBlockNode) {
- rootBlockNode = dom.create(forcedRootBlock, getForcedRootBlockAttrs(editor));
- node.parentNode.insertBefore(rootBlockNode, node);
- wrapped = true;
- }
- tempNode = node;
- node = node.nextSibling;
- rootBlockNode.appendChild(tempNode);
- } else {
- rootBlockNode = null;
- node = node.nextSibling;
- }
- }
- if (wrapped && restoreSelection) {
- rng.setStart(startContainer, startOffset);
- rng.setEnd(endContainer, endOffset);
- selection.setRng(rng);
- editor.nodeChanged();
- }
- };
- const setup$n = editor => {
- editor.on('NodeChange', curry(addRootBlocks, editor));
- };
- const hasClass = checkClassName => node => (' ' + node.attr('class') + ' ').indexOf(checkClassName) !== -1;
- const replaceMatchWithSpan = (editor, content, cls) => {
- return function (match) {
- const args = arguments, index = args[args.length - 2];
- const prevChar = index > 0 ? content.charAt(index - 1) : '';
- if (prevChar === '"') {
- return match;
- }
- if (prevChar === '>') {
- const findStartTagIndex = content.lastIndexOf('<', index);
- if (findStartTagIndex !== -1) {
- const tagHtml = content.substring(findStartTagIndex, index);
- if (tagHtml.indexOf('contenteditable="false"') !== -1) {
- return match;
- }
- }
- }
- return '<span class="' + cls + '" data-mce-content="' + editor.dom.encode(args[0]) + '">' + editor.dom.encode(typeof args[1] === 'string' ? args[1] : args[0]) + '</span>';
- };
- };
- const convertRegExpsToNonEditable = (editor, nonEditableRegExps, e) => {
- let i = nonEditableRegExps.length, content = e.content;
- if (e.format === 'raw') {
- return;
- }
- while (i--) {
- content = content.replace(nonEditableRegExps[i], replaceMatchWithSpan(editor, content, getNonEditableClass(editor)));
- }
- e.content = content;
- };
- const setup$m = editor => {
- const contentEditableAttrName = 'contenteditable';
- const editClass = ' ' + Tools.trim(getEditableClass(editor)) + ' ';
- const nonEditClass = ' ' + Tools.trim(getNonEditableClass(editor)) + ' ';
- const hasEditClass = hasClass(editClass);
- const hasNonEditClass = hasClass(nonEditClass);
- const nonEditableRegExps = getNonEditableRegExps(editor);
- if (nonEditableRegExps.length > 0) {
- editor.on('BeforeSetContent', e => {
- convertRegExpsToNonEditable(editor, nonEditableRegExps, e);
- });
- }
- editor.parser.addAttributeFilter('class', nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- if (hasEditClass(node)) {
- node.attr(contentEditableAttrName, 'true');
- } else if (hasNonEditClass(node)) {
- node.attr(contentEditableAttrName, 'false');
- }
- }
- });
- editor.serializer.addAttributeFilter(contentEditableAttrName, nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- if (!hasEditClass(node) && !hasNonEditClass(node)) {
- continue;
- }
- if (nonEditableRegExps.length > 0 && node.attr('data-mce-content')) {
- node.name = '#text';
- node.type = 3;
- node.raw = true;
- node.value = node.attr('data-mce-content');
- } else {
- node.attr(contentEditableAttrName, null);
- }
- }
- });
- };
- const findBlockCaretContainer = editor => descendant(SugarElement.fromDom(editor.getBody()), '*[data-mce-caret]').map(elm => elm.dom).getOrNull();
- const showBlockCaretContainer = (editor, blockCaretContainer) => {
- if (blockCaretContainer.hasAttribute('data-mce-caret')) {
- showCaretContainerBlock(blockCaretContainer);
- editor.selection.setRng(editor.selection.getRng());
- editor.selection.scrollIntoView(blockCaretContainer);
- }
- };
- const handleBlockContainer = (editor, e) => {
- const blockCaretContainer = findBlockCaretContainer(editor);
- if (!blockCaretContainer) {
- return;
- }
- if (e.type === 'compositionstart') {
- e.preventDefault();
- e.stopPropagation();
- showBlockCaretContainer(editor, blockCaretContainer);
- return;
- }
- if (hasContent(blockCaretContainer)) {
- showBlockCaretContainer(editor, blockCaretContainer);
- editor.undoManager.add();
- }
- };
- const setup$l = editor => {
- editor.on('keyup compositionstart', curry(handleBlockContainer, editor));
- };
- const isContentEditableFalse$3 = isContentEditableFalse$b;
- const moveToCeFalseHorizontally = (direction, editor, range) => moveHorizontally(editor, direction, range, isBeforeContentEditableFalse, isAfterContentEditableFalse, isContentEditableFalse$3);
- const moveToCeFalseVertically = (direction, editor, range) => {
- const isBefore = caretPosition => isBeforeContentEditableFalse(caretPosition) || isBeforeTable(caretPosition);
- const isAfter = caretPosition => isAfterContentEditableFalse(caretPosition) || isAfterTable(caretPosition);
- return moveVertically(editor, direction, range, isBefore, isAfter, isContentEditableFalse$3);
- };
- const createTextBlock = editor => {
- const textBlock = editor.dom.create(getForcedRootBlock(editor));
- textBlock.innerHTML = '<br data-mce-bogus="1">';
- return textBlock;
- };
- const exitPreBlock = (editor, direction, range) => {
- const caretWalker = CaretWalker(editor.getBody());
- const getVisualCaretPosition$1 = curry(getVisualCaretPosition, direction === 1 ? caretWalker.next : caretWalker.prev);
- if (range.collapsed) {
- const pre = editor.dom.getParent(range.startContainer, 'PRE');
- if (!pre) {
- return;
- }
- const caretPos = getVisualCaretPosition$1(CaretPosition.fromRangeStart(range));
- if (!caretPos) {
- const newBlock = SugarElement.fromDom(createTextBlock(editor));
- if (direction === 1) {
- after$4(SugarElement.fromDom(pre), newBlock);
- } else {
- before$3(SugarElement.fromDom(pre), newBlock);
- }
- editor.selection.select(newBlock.dom, true);
- editor.selection.collapse();
- }
- }
- };
- const getHorizontalRange = (editor, forward) => {
- const direction = forward ? HDirection.Forwards : HDirection.Backwards;
- const range = editor.selection.getRng();
- return moveToCeFalseHorizontally(direction, editor, range).orThunk(() => {
- exitPreBlock(editor, direction, range);
- return Optional.none();
- });
- };
- const getVerticalRange = (editor, down) => {
- const direction = down ? 1 : -1;
- const range = editor.selection.getRng();
- return moveToCeFalseVertically(direction, editor, range).orThunk(() => {
- exitPreBlock(editor, direction, range);
- return Optional.none();
- });
- };
- const moveH$2 = (editor, forward) => getHorizontalRange(editor, forward).exists(newRange => {
- moveToRange(editor, newRange);
- return true;
- });
- const moveV$3 = (editor, down) => getVerticalRange(editor, down).exists(newRange => {
- moveToRange(editor, newRange);
- return true;
- });
- const moveToLineEndPoint$1 = (editor, forward) => {
- const isCefPosition = forward ? isAfterContentEditableFalse : isBeforeContentEditableFalse;
- return moveToLineEndPoint$3(editor, forward, isCefPosition);
- };
- const selectToEndPoint = (editor, forward) => getEdgeCefPosition(editor, !forward).map(pos => {
- const rng = pos.toRange();
- const curRng = editor.selection.getRng();
- if (forward) {
- rng.setStart(curRng.startContainer, curRng.startOffset);
- } else {
- rng.setEnd(curRng.endContainer, curRng.endOffset);
- }
- return rng;
- }).exists(rng => {
- moveToRange(editor, rng);
- return true;
- });
- const isTarget = node => contains$2(['figcaption'], name(node));
- const rangeBefore = target => {
- const rng = document.createRange();
- rng.setStartBefore(target.dom);
- rng.setEndBefore(target.dom);
- return rng;
- };
- const insertElement = (root, elm, forward) => {
- if (forward) {
- append$1(root, elm);
- } else {
- prepend(root, elm);
- }
- };
- const insertEmptyLine = (root, forward, blockName, attrs) => {
- const block = SugarElement.fromTag(blockName);
- const br = SugarElement.fromTag('br');
- setAll$1(block, attrs);
- append$1(block, br);
- insertElement(root, block, forward);
- return rangeBefore(br);
- };
- const getClosestTargetBlock = (pos, root) => {
- const isRoot = curry(eq, root);
- return closest$4(SugarElement.fromDom(pos.container()), isBlock$2, isRoot).filter(isTarget);
- };
- const isAtFirstOrLastLine = (root, forward, pos) => forward ? isAtLastLine(root.dom, pos) : isAtFirstLine(root.dom, pos);
- const moveCaretToNewEmptyLine = (editor, forward) => {
- const root = SugarElement.fromDom(editor.getBody());
- const pos = CaretPosition.fromRangeStart(editor.selection.getRng());
- const rootBlock = getForcedRootBlock(editor);
- const rootBlockAttrs = getForcedRootBlockAttrs(editor);
- return getClosestTargetBlock(pos, root).exists(() => {
- if (isAtFirstOrLastLine(root, forward, pos)) {
- const rng = insertEmptyLine(root, forward, rootBlock, rootBlockAttrs);
- editor.selection.setRng(rng);
- return true;
- } else {
- return false;
- }
- });
- };
- const moveV$2 = (editor, forward) => {
- if (editor.selection.isCollapsed()) {
- return moveCaretToNewEmptyLine(editor, forward);
- } else {
- return false;
- }
- };
- const baseKeyPattern = {
- shiftKey: false,
- altKey: false,
- ctrlKey: false,
- metaKey: false,
- keyCode: 0
- };
- const defaultPatterns = patterns => map$3(patterns, pattern => ({
- ...baseKeyPattern,
- action: noop,
- ...pattern
- }));
- const defaultDelayedPatterns = patterns => map$3(patterns, pattern => ({
- ...baseKeyPattern,
- action: () => Optional.none(),
- ...pattern
- }));
- const matchesEvent = (pattern, evt) => evt.keyCode === pattern.keyCode && evt.shiftKey === pattern.shiftKey && evt.altKey === pattern.altKey && evt.ctrlKey === pattern.ctrlKey && evt.metaKey === pattern.metaKey;
- const match$1 = (patterns, evt) => bind$3(defaultPatterns(patterns), pattern => matchesEvent(pattern, evt) ? [pattern] : []);
- const matchDelayed = (patterns, evt) => bind$3(defaultDelayedPatterns(patterns), pattern => matchesEvent(pattern, evt) ? [pattern] : []);
- const action = (f, ...x) => () => f.apply(null, x);
- const execute = (patterns, evt) => find$2(match$1(patterns, evt), pattern => pattern.action());
- const executeWithDelayedAction = (patterns, evt) => findMap(matchDelayed(patterns, evt), pattern => pattern.action());
- const moveH$1 = (editor, forward) => {
- const direction = forward ? HDirection.Forwards : HDirection.Backwards;
- const range = editor.selection.getRng();
- return moveHorizontally(editor, direction, range, isBeforeMedia, isAfterMedia, isMedia$2).exists(newRange => {
- moveToRange(editor, newRange);
- return true;
- });
- };
- const moveV$1 = (editor, down) => {
- const direction = down ? 1 : -1;
- const range = editor.selection.getRng();
- return moveVertically(editor, direction, range, isBeforeMedia, isAfterMedia, isMedia$2).exists(newRange => {
- moveToRange(editor, newRange);
- return true;
- });
- };
- const moveToLineEndPoint = (editor, forward) => {
- const isNearMedia = forward ? isAfterMedia : isBeforeMedia;
- return moveToLineEndPoint$3(editor, forward, isNearMedia);
- };
- const adt = Adt.generate([
- { none: ['current'] },
- { first: ['current'] },
- {
- middle: [
- 'current',
- 'target'
- ]
- },
- { last: ['current'] }
- ]);
- const none = current => adt.none(current);
- const CellLocation = {
- ...adt,
- none
- };
- const firstLayer = (scope, selector) => {
- return filterFirstLayer(scope, selector, always);
- };
- const filterFirstLayer = (scope, selector, predicate) => {
- return bind$3(children(scope), x => {
- if (is$1(x, selector)) {
- return predicate(x) ? [x] : [];
- } else {
- return filterFirstLayer(x, selector, predicate);
- }
- });
- };
- const lookup$1 = (tags, element, isRoot = never) => {
- if (isRoot(element)) {
- return Optional.none();
- }
- if (contains$2(tags, name(element))) {
- return Optional.some(element);
- }
- const isRootOrUpperTable = elm => is$1(elm, 'table') || isRoot(elm);
- return ancestor$2(element, tags.join(','), isRootOrUpperTable);
- };
- const cell = (element, isRoot) => lookup$1([
- 'td',
- 'th'
- ], element, isRoot);
- const cells = ancestor => firstLayer(ancestor, 'th,td');
- const table = (element, isRoot) => closest$3(element, 'table', isRoot);
- const walk = (all, current, index, direction, isEligible = always) => {
- const forwards = direction === 1;
- if (!forwards && index <= 0) {
- return CellLocation.first(all[0]);
- } else if (forwards && index >= all.length - 1) {
- return CellLocation.last(all[all.length - 1]);
- } else {
- const newIndex = index + direction;
- const elem = all[newIndex];
- return isEligible(elem) ? CellLocation.middle(current, elem) : walk(all, current, newIndex, direction, isEligible);
- }
- };
- const detect = (current, isRoot) => {
- return table(current, isRoot).bind(table => {
- const all = cells(table);
- const index = findIndex$2(all, x => eq(current, x));
- return index.map(index => ({
- index,
- all
- }));
- });
- };
- const next = (current, isEligible, isRoot) => {
- const detection = detect(current, isRoot);
- return detection.fold(() => {
- return CellLocation.none(current);
- }, info => {
- return walk(info.all, current, info.index, 1, isEligible);
- });
- };
- const prev = (current, isEligible, isRoot) => {
- const detection = detect(current, isRoot);
- return detection.fold(() => {
- return CellLocation.none();
- }, info => {
- return walk(info.all, current, info.index, -1, isEligible);
- });
- };
- const closest = target => closest$3(target, '[contenteditable]');
- const isEditable = (element, assumeEditable = false) => {
- if (inBody(element)) {
- return element.dom.isContentEditable;
- } else {
- return closest(element).fold(constant(assumeEditable), editable => getRaw(editable) === 'true');
- }
- };
- const getRaw = element => element.dom.contentEditable;
- const deflate = (rect, delta) => ({
- left: rect.left - delta,
- top: rect.top - delta,
- right: rect.right + delta * 2,
- bottom: rect.bottom + delta * 2,
- width: rect.width + delta,
- height: rect.height + delta
- });
- const getCorners = (getYAxisValue, tds) => bind$3(tds, td => {
- const rect = deflate(clone$1(td.getBoundingClientRect()), -1);
- return [
- {
- x: rect.left,
- y: getYAxisValue(rect),
- cell: td
- },
- {
- x: rect.right,
- y: getYAxisValue(rect),
- cell: td
- }
- ];
- });
- const findClosestCorner = (corners, x, y) => foldl(corners, (acc, newCorner) => acc.fold(() => Optional.some(newCorner), oldCorner => {
- const oldDist = Math.sqrt(Math.abs(oldCorner.x - x) + Math.abs(oldCorner.y - y));
- const newDist = Math.sqrt(Math.abs(newCorner.x - x) + Math.abs(newCorner.y - y));
- return Optional.some(newDist < oldDist ? newCorner : oldCorner);
- }), Optional.none());
- const getClosestCell = (getYAxisValue, isTargetCorner, table, x, y) => {
- const cells = descendants(SugarElement.fromDom(table), 'td,th,caption').map(e => e.dom);
- const corners = filter$6(getCorners(getYAxisValue, cells), corner => isTargetCorner(corner, y));
- return findClosestCorner(corners, x, y).map(corner => corner.cell);
- };
- const getBottomValue = rect => rect.bottom;
- const getTopValue = rect => rect.top;
- const isAbove = (corner, y) => corner.y < y;
- const isBelow = (corner, y) => corner.y > y;
- const getClosestCellAbove = curry(getClosestCell, getBottomValue, isAbove);
- const getClosestCellBelow = curry(getClosestCell, getTopValue, isBelow);
- const findClosestPositionInAboveCell = (table, pos) => head(pos.getClientRects()).bind(rect => getClosestCellAbove(table, rect.left, rect.top)).bind(cell => findClosestHorizontalPosition(getLastLinePositions(cell), pos));
- const findClosestPositionInBelowCell = (table, pos) => last$3(pos.getClientRects()).bind(rect => getClosestCellBelow(table, rect.left, rect.top)).bind(cell => findClosestHorizontalPosition(getFirstLinePositions(cell), pos));
- const hasNextBreak = (getPositionsUntil, scope, lineInfo) => lineInfo.breakAt.exists(breakPos => getPositionsUntil(scope, breakPos).breakAt.isSome());
- const startsWithWrapBreak = lineInfo => lineInfo.breakType === BreakType.Wrap && lineInfo.positions.length === 0;
- const startsWithBrBreak = lineInfo => lineInfo.breakType === BreakType.Br && lineInfo.positions.length === 1;
- const isAtTableCellLine = (getPositionsUntil, scope, pos) => {
- const lineInfo = getPositionsUntil(scope, pos);
- if (startsWithWrapBreak(lineInfo) || !isBr$6(pos.getNode()) && startsWithBrBreak(lineInfo)) {
- return !hasNextBreak(getPositionsUntil, scope, lineInfo);
- } else {
- return lineInfo.breakAt.isNone();
- }
- };
- const isAtFirstTableCellLine = curry(isAtTableCellLine, getPositionsUntilPreviousLine);
- const isAtLastTableCellLine = curry(isAtTableCellLine, getPositionsUntilNextLine);
- const isCaretAtStartOrEndOfTable = (forward, rng, table) => {
- const caretPos = CaretPosition.fromRangeStart(rng);
- return positionIn(!forward, table).exists(pos => pos.isEqual(caretPos));
- };
- const navigateHorizontally = (editor, forward, table, _td) => {
- const rng = editor.selection.getRng();
- const direction = forward ? 1 : -1;
- if (isFakeCaretTableBrowser() && isCaretAtStartOrEndOfTable(forward, rng, table)) {
- showCaret(direction, editor, table, !forward, false).each(newRng => {
- moveToRange(editor, newRng);
- });
- return true;
- }
- return false;
- };
- const getClosestAbovePosition = (root, table, start) => findClosestPositionInAboveCell(table, start).orThunk(() => head(start.getClientRects()).bind(rect => findClosestHorizontalPositionFromPoint(getPositionsAbove(root, CaretPosition.before(table)), rect.left))).getOr(CaretPosition.before(table));
- const getClosestBelowPosition = (root, table, start) => findClosestPositionInBelowCell(table, start).orThunk(() => head(start.getClientRects()).bind(rect => findClosestHorizontalPositionFromPoint(getPositionsBelow(root, CaretPosition.after(table)), rect.left))).getOr(CaretPosition.after(table));
- const getTable = (previous, pos) => {
- const node = pos.getNode(previous);
- return isElement$6(node) && node.nodeName === 'TABLE' ? Optional.some(node) : Optional.none();
- };
- const renderBlock = (down, editor, table) => {
- const forcedRootBlock = getForcedRootBlock(editor);
- editor.undoManager.transact(() => {
- const element = SugarElement.fromTag(forcedRootBlock);
- setAll$1(element, getForcedRootBlockAttrs(editor));
- append$1(element, SugarElement.fromTag('br'));
- if (down) {
- after$4(SugarElement.fromDom(table), element);
- } else {
- before$3(SugarElement.fromDom(table), element);
- }
- const rng = editor.dom.createRng();
- rng.setStart(element.dom, 0);
- rng.setEnd(element.dom, 0);
- moveToRange(editor, rng);
- });
- };
- const moveCaret = (editor, down, pos) => {
- const table = down ? getTable(true, pos) : getTable(false, pos);
- const last = down === false;
- table.fold(() => moveToRange(editor, pos.toRange()), table => positionIn(last, editor.getBody()).filter(lastPos => lastPos.isEqual(pos)).fold(() => moveToRange(editor, pos.toRange()), _ => renderBlock(down, editor, table)));
- };
- const navigateVertically = (editor, down, table, td) => {
- const rng = editor.selection.getRng();
- const pos = CaretPosition.fromRangeStart(rng);
- const root = editor.getBody();
- if (!down && isAtFirstTableCellLine(td, pos)) {
- const newPos = getClosestAbovePosition(root, table, pos);
- moveCaret(editor, down, newPos);
- return true;
- } else if (down && isAtLastTableCellLine(td, pos)) {
- const newPos = getClosestBelowPosition(root, table, pos);
- moveCaret(editor, down, newPos);
- return true;
- } else {
- return false;
- }
- };
- const move$1 = (editor, forward, mover) => Optional.from(editor.dom.getParent(editor.selection.getNode(), 'td,th')).bind(td => Optional.from(editor.dom.getParent(td, 'table')).map(table => mover(editor, forward, table, td))).getOr(false);
- const moveH = (editor, forward) => move$1(editor, forward, navigateHorizontally);
- const moveV = (editor, forward) => move$1(editor, forward, navigateVertically);
- const getCellFirstCursorPosition = cell => {
- const selection = SimSelection.exact(cell, 0, cell, 0);
- return toNative(selection);
- };
- const tabGo = (editor, isRoot, cell) => {
- return cell.fold(Optional.none, Optional.none, (_current, next) => {
- return first(next).map(cell => {
- return getCellFirstCursorPosition(cell);
- });
- }, current => {
- editor.execCommand('mceTableInsertRowAfter');
- return tabForward(editor, isRoot, current);
- });
- };
- const tabForward = (editor, isRoot, cell) => tabGo(editor, isRoot, next(cell, isEditable));
- const tabBackward = (editor, isRoot, cell) => tabGo(editor, isRoot, prev(cell, isEditable));
- const handleTab = (editor, forward) => {
- const rootElements = [
- 'table',
- 'li',
- 'dl'
- ];
- const body = SugarElement.fromDom(editor.getBody());
- const isRoot = element => {
- const name$1 = name(element);
- return eq(element, body) || contains$2(rootElements, name$1);
- };
- const rng = editor.selection.getRng();
- const container = SugarElement.fromDom(!forward ? rng.startContainer : rng.endContainer);
- return cell(container, isRoot).map(cell => {
- table(cell, isRoot).each(table => {
- editor.model.table.clearSelectedCells(table.dom);
- });
- editor.selection.collapse(!forward);
- const navigation = !forward ? tabBackward : tabForward;
- const rng = navigation(editor, isRoot, cell);
- rng.each(range => {
- editor.selection.setRng(range);
- });
- return true;
- }).getOr(false);
- };
- const executeKeydownOverride$4 = (editor, caret, evt) => {
- const isMac = Env.os.isMacOS() || Env.os.isiOS();
- execute([
- {
- keyCode: VK.RIGHT,
- action: action(moveH$2, editor, true)
- },
- {
- keyCode: VK.LEFT,
- action: action(moveH$2, editor, false)
- },
- {
- keyCode: VK.UP,
- action: action(moveV$3, editor, false)
- },
- {
- keyCode: VK.DOWN,
- action: action(moveV$3, editor, true)
- },
- ...isMac ? [
- {
- keyCode: VK.UP,
- action: action(selectToEndPoint, editor, false),
- metaKey: true,
- shiftKey: true
- },
- {
- keyCode: VK.DOWN,
- action: action(selectToEndPoint, editor, true),
- metaKey: true,
- shiftKey: true
- }
- ] : [],
- {
- keyCode: VK.RIGHT,
- action: action(moveH, editor, true)
- },
- {
- keyCode: VK.LEFT,
- action: action(moveH, editor, false)
- },
- {
- keyCode: VK.UP,
- action: action(moveV, editor, false)
- },
- {
- keyCode: VK.DOWN,
- action: action(moveV, editor, true)
- },
- {
- keyCode: VK.RIGHT,
- action: action(moveH$1, editor, true)
- },
- {
- keyCode: VK.LEFT,
- action: action(moveH$1, editor, false)
- },
- {
- keyCode: VK.UP,
- action: action(moveV$1, editor, false)
- },
- {
- keyCode: VK.DOWN,
- action: action(moveV$1, editor, true)
- },
- {
- keyCode: VK.RIGHT,
- action: action(move$2, editor, caret, true)
- },
- {
- keyCode: VK.LEFT,
- action: action(move$2, editor, caret, false)
- },
- {
- keyCode: VK.RIGHT,
- ctrlKey: !isMac,
- altKey: isMac,
- action: action(moveNextWord, editor, caret)
- },
- {
- keyCode: VK.LEFT,
- ctrlKey: !isMac,
- altKey: isMac,
- action: action(movePrevWord, editor, caret)
- },
- {
- keyCode: VK.UP,
- action: action(moveV$2, editor, false)
- },
- {
- keyCode: VK.DOWN,
- action: action(moveV$2, editor, true)
- }
- ], evt).each(_ => {
- evt.preventDefault();
- });
- };
- const setup$k = (editor, caret) => {
- editor.on('keydown', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeydownOverride$4(editor, caret, evt);
- }
- });
- };
- const point = (container, offset) => ({
- container,
- offset
- });
- const DOM$7 = DOMUtils.DOM;
- const alwaysNext = startNode => node => startNode === node ? -1 : 0;
- const isBoundary = dom => node => dom.isBlock(node) || contains$2([
- 'BR',
- 'IMG',
- 'HR',
- 'INPUT'
- ], node.nodeName) || dom.getContentEditable(node) === 'false';
- const textBefore = (node, offset, rootNode) => {
- if (isText$9(node) && offset >= 0) {
- return Optional.some(point(node, offset));
- } else {
- const textSeeker = TextSeeker(DOM$7);
- return Optional.from(textSeeker.backwards(node, offset, alwaysNext(node), rootNode)).map(prev => point(prev.container, prev.container.data.length));
- }
- };
- const textAfter = (node, offset, rootNode) => {
- if (isText$9(node) && offset >= node.length) {
- return Optional.some(point(node, offset));
- } else {
- const textSeeker = TextSeeker(DOM$7);
- return Optional.from(textSeeker.forwards(node, offset, alwaysNext(node), rootNode)).map(prev => point(prev.container, 0));
- }
- };
- const scanLeft = (node, offset, rootNode) => {
- if (!isText$9(node)) {
- return Optional.none();
- }
- const text = node.textContent;
- if (offset >= 0 && offset <= text.length) {
- return Optional.some(point(node, offset));
- } else {
- const textSeeker = TextSeeker(DOM$7);
- return Optional.from(textSeeker.backwards(node, offset, alwaysNext(node), rootNode)).bind(prev => {
- const prevText = prev.container.data;
- return scanLeft(prev.container, offset + prevText.length, rootNode);
- });
- }
- };
- const scanRight = (node, offset, rootNode) => {
- if (!isText$9(node)) {
- return Optional.none();
- }
- const text = node.textContent;
- if (offset <= text.length) {
- return Optional.some(point(node, offset));
- } else {
- const textSeeker = TextSeeker(DOM$7);
- return Optional.from(textSeeker.forwards(node, offset, alwaysNext(node), rootNode)).bind(next => scanRight(next.container, offset - text.length, rootNode));
- }
- };
- const repeatLeft = (dom, node, offset, process, rootNode) => {
- const search = TextSeeker(dom, isBoundary(dom));
- return Optional.from(search.backwards(node, offset, process, rootNode));
- };
- const isValidTextRange = rng => rng.collapsed && rng.startContainer.nodeType === 3;
- const getText = rng => rng.toString().replace(/\u00A0/g, ' ').replace(/\uFEFF/g, '');
- const isWhitespace = chr => chr !== '' && ' \xA0\f\n\r\t\x0B'.indexOf(chr) !== -1;
- const stripTriggerChar = (text, triggerCh) => text.substring(triggerCh.length);
- const findChar = (text, index, ch) => {
- let i;
- for (i = index - 1; i >= 0; i--) {
- const char = text.charAt(i);
- if (isWhitespace(char)) {
- return Optional.none();
- }
- if (char === ch) {
- break;
- }
- }
- return Optional.some(i);
- };
- const findStart = (dom, initRange, ch, minChars = 0) => {
- if (!isValidTextRange(initRange)) {
- return Optional.none();
- }
- const findTriggerChIndex = (element, offset, text) => findChar(text, offset, ch).getOr(offset);
- const root = dom.getParent(initRange.startContainer, dom.isBlock) || dom.getRoot();
- return repeatLeft(dom, initRange.startContainer, initRange.startOffset, findTriggerChIndex, root).bind(spot => {
- const range = initRange.cloneRange();
- range.setStart(spot.container, spot.offset);
- range.setEnd(initRange.endContainer, initRange.endOffset);
- if (range.collapsed) {
- return Optional.none();
- }
- const text = getText(range);
- const triggerCharIndex = text.lastIndexOf(ch);
- if (triggerCharIndex !== 0 || stripTriggerChar(text, ch).length < minChars) {
- return Optional.none();
- } else {
- return Optional.some({
- text: stripTriggerChar(text, ch),
- range,
- triggerChar: ch
- });
- }
- });
- };
- const getContext = (dom, initRange, ch, minChars = 0) => detect$1(SugarElement.fromDom(initRange.startContainer)).fold(() => findStart(dom, initRange, ch, minChars), elm => {
- const range = dom.createRng();
- range.selectNode(elm.dom);
- const text = getText(range);
- return Optional.some({
- range,
- text: stripTriggerChar(text, ch),
- triggerChar: ch
- });
- });
- const isText$1 = node => node.nodeType === TEXT;
- const isElement = node => node.nodeType === ELEMENT;
- const toLast = node => {
- if (isText$1(node)) {
- return point(node, node.data.length);
- } else {
- const children = node.childNodes;
- return children.length > 0 ? toLast(children[children.length - 1]) : point(node, children.length);
- }
- };
- const toLeaf = (node, offset) => {
- const children = node.childNodes;
- if (children.length > 0 && offset < children.length) {
- return toLeaf(children[offset], 0);
- } else if (children.length > 0 && isElement(node) && children.length === offset) {
- return toLast(children[children.length - 1]);
- } else {
- return point(node, offset);
- }
- };
- const isPreviousCharContent = (dom, leaf) => {
- const root = dom.getParent(leaf.container, dom.isBlock);
- return repeatLeft(dom, leaf.container, leaf.offset, (_element, offset) => offset === 0 ? -1 : offset, root).filter(spot => {
- const char = spot.container.data.charAt(spot.offset - 1);
- return !isWhitespace(char);
- }).isSome();
- };
- const isStartOfWord = dom => rng => {
- const leaf = toLeaf(rng.startContainer, rng.startOffset);
- return !isPreviousCharContent(dom, leaf);
- };
- const getTriggerContext = (dom, initRange, database) => findMap(database.triggerChars, ch => getContext(dom, initRange, ch));
- const lookup = (editor, getDatabase) => {
- const database = getDatabase();
- const rng = editor.selection.getRng();
- return getTriggerContext(editor.dom, rng, database).bind(context => lookupWithContext(editor, getDatabase, context));
- };
- const lookupWithContext = (editor, getDatabase, context, fetchOptions = {}) => {
- const database = getDatabase();
- const rng = editor.selection.getRng();
- const startText = rng.startContainer.nodeValue;
- const autocompleters = filter$6(database.lookupByChar(context.triggerChar), autocompleter => context.text.length >= autocompleter.minChars && autocompleter.matches.getOrThunk(() => isStartOfWord(editor.dom))(context.range, startText, context.text));
- if (autocompleters.length === 0) {
- return Optional.none();
- }
- const lookupData = Promise.all(map$3(autocompleters, ac => {
- const fetchResult = ac.fetch(context.text, ac.maxResults, fetchOptions);
- return fetchResult.then(results => ({
- matchText: context.text,
- items: results,
- columns: ac.columns,
- onAction: ac.onAction,
- highlightOn: ac.highlightOn
- }));
- }));
- return Optional.some({
- lookupData,
- context
- });
- };
- var SimpleResultType;
- (function (SimpleResultType) {
- SimpleResultType[SimpleResultType['Error'] = 0] = 'Error';
- SimpleResultType[SimpleResultType['Value'] = 1] = 'Value';
- }(SimpleResultType || (SimpleResultType = {})));
- const fold$1 = (res, onError, onValue) => res.stype === SimpleResultType.Error ? onError(res.serror) : onValue(res.svalue);
- const partition = results => {
- const values = [];
- const errors = [];
- each$f(results, obj => {
- fold$1(obj, err => errors.push(err), val => values.push(val));
- });
- return {
- values,
- errors
- };
- };
- const mapError = (res, f) => {
- if (res.stype === SimpleResultType.Error) {
- return {
- stype: SimpleResultType.Error,
- serror: f(res.serror)
- };
- } else {
- return res;
- }
- };
- const map = (res, f) => {
- if (res.stype === SimpleResultType.Value) {
- return {
- stype: SimpleResultType.Value,
- svalue: f(res.svalue)
- };
- } else {
- return res;
- }
- };
- const bind = (res, f) => {
- if (res.stype === SimpleResultType.Value) {
- return f(res.svalue);
- } else {
- return res;
- }
- };
- const bindError = (res, f) => {
- if (res.stype === SimpleResultType.Error) {
- return f(res.serror);
- } else {
- return res;
- }
- };
- const svalue = v => ({
- stype: SimpleResultType.Value,
- svalue: v
- });
- const serror = e => ({
- stype: SimpleResultType.Error,
- serror: e
- });
- const toResult = res => fold$1(res, Result.error, Result.value);
- const fromResult = res => res.fold(serror, svalue);
- const SimpleResult = {
- fromResult,
- toResult,
- svalue,
- partition,
- serror,
- bind,
- bindError,
- map,
- mapError,
- fold: fold$1
- };
- const formatObj = input => {
- return isObject(input) && keys(input).length > 100 ? ' removed due to size' : JSON.stringify(input, null, 2);
- };
- const formatErrors = errors => {
- const es = errors.length > 10 ? errors.slice(0, 10).concat([{
- path: [],
- getErrorInfo: constant('... (only showing first ten failures)')
- }]) : errors;
- return map$3(es, e => {
- return 'Failed path: (' + e.path.join(' > ') + ')\n' + e.getErrorInfo();
- });
- };
- const nu = (path, getErrorInfo) => {
- return SimpleResult.serror([{
- path,
- getErrorInfo
- }]);
- };
- const missingRequired = (path, key, obj) => nu(path, () => 'Could not find valid *required* value for "' + key + '" in ' + formatObj(obj));
- const missingKey = (path, key) => nu(path, () => 'Choice schema did not contain choice key: "' + key + '"');
- const missingBranch = (path, branches, branch) => nu(path, () => 'The chosen schema: "' + branch + '" did not exist in branches: ' + formatObj(branches));
- const custom = (path, err) => nu(path, constant(err));
- const chooseFrom = (path, input, branches, ch) => {
- const fields = get$a(branches, ch);
- return fields.fold(() => missingBranch(path, branches, ch), vp => vp.extract(path.concat(['branch: ' + ch]), input));
- };
- const choose$1 = (key, branches) => {
- const extract = (path, input) => {
- const choice = get$a(input, key);
- return choice.fold(() => missingKey(path, key), chosen => chooseFrom(path, input, branches, chosen));
- };
- const toString = () => 'chooseOn(' + key + '). Possible values: ' + keys(branches);
- return {
- extract,
- toString
- };
- };
- const shallow = (old, nu) => {
- return nu;
- };
- const deep = (old, nu) => {
- const bothObjects = isPlainObject(old) && isPlainObject(nu);
- return bothObjects ? deepMerge(old, nu) : nu;
- };
- const baseMerge = merger => {
- return (...objects) => {
- if (objects.length === 0) {
- throw new Error(`Can't merge zero objects`);
- }
- const ret = {};
- for (let j = 0; j < objects.length; j++) {
- const curObject = objects[j];
- for (const key in curObject) {
- if (has$2(curObject, key)) {
- ret[key] = merger(ret[key], curObject[key]);
- }
- }
- }
- return ret;
- };
- };
- const deepMerge = baseMerge(deep);
- const merge = baseMerge(shallow);
- const required = () => ({
- tag: 'required',
- process: {}
- });
- const defaultedThunk = fallbackThunk => ({
- tag: 'defaultedThunk',
- process: fallbackThunk
- });
- const defaulted$1 = fallback => defaultedThunk(constant(fallback));
- const asOption = () => ({
- tag: 'option',
- process: {}
- });
- const mergeValues = (values, base) => values.length > 0 ? SimpleResult.svalue(deepMerge(base, merge.apply(undefined, values))) : SimpleResult.svalue(base);
- const mergeErrors = errors => compose(SimpleResult.serror, flatten)(errors);
- const consolidateObj = (objects, base) => {
- const partition = SimpleResult.partition(objects);
- return partition.errors.length > 0 ? mergeErrors(partition.errors) : mergeValues(partition.values, base);
- };
- const consolidateArr = objects => {
- const partitions = SimpleResult.partition(objects);
- return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : SimpleResult.svalue(partitions.values);
- };
- const ResultCombine = {
- consolidateObj,
- consolidateArr
- };
- const field$1 = (key, newKey, presence, prop) => ({
- tag: 'field',
- key,
- newKey,
- presence,
- prop
- });
- const customField$1 = (newKey, instantiator) => ({
- tag: 'custom',
- newKey,
- instantiator
- });
- const fold = (value, ifField, ifCustom) => {
- switch (value.tag) {
- case 'field':
- return ifField(value.key, value.newKey, value.presence, value.prop);
- case 'custom':
- return ifCustom(value.newKey, value.instantiator);
- }
- };
- const value = validator => {
- const extract = (path, val) => {
- return SimpleResult.bindError(validator(val), err => custom(path, err));
- };
- const toString = constant('val');
- return {
- extract,
- toString
- };
- };
- const anyValue$1 = value(SimpleResult.svalue);
- const requiredAccess = (path, obj, key, bundle) => get$a(obj, key).fold(() => missingRequired(path, key, obj), bundle);
- const fallbackAccess = (obj, key, fallback, bundle) => {
- const v = get$a(obj, key).getOrThunk(() => fallback(obj));
- return bundle(v);
- };
- const optionAccess = (obj, key, bundle) => bundle(get$a(obj, key));
- const optionDefaultedAccess = (obj, key, fallback, bundle) => {
- const opt = get$a(obj, key).map(val => val === true ? fallback(obj) : val);
- return bundle(opt);
- };
- const extractField = (field, path, obj, key, prop) => {
- const bundle = av => prop.extract(path.concat([key]), av);
- const bundleAsOption = optValue => optValue.fold(() => SimpleResult.svalue(Optional.none()), ov => {
- const result = prop.extract(path.concat([key]), ov);
- return SimpleResult.map(result, Optional.some);
- });
- switch (field.tag) {
- case 'required':
- return requiredAccess(path, obj, key, bundle);
- case 'defaultedThunk':
- return fallbackAccess(obj, key, field.process, bundle);
- case 'option':
- return optionAccess(obj, key, bundleAsOption);
- case 'defaultedOptionThunk':
- return optionDefaultedAccess(obj, key, field.process, bundleAsOption);
- case 'mergeWithThunk': {
- return fallbackAccess(obj, key, constant({}), v => {
- const result = deepMerge(field.process(obj), v);
- return bundle(result);
- });
- }
- }
- };
- const extractFields = (path, obj, fields) => {
- const success = {};
- const errors = [];
- for (const field of fields) {
- fold(field, (key, newKey, presence, prop) => {
- const result = extractField(presence, path, obj, key, prop);
- SimpleResult.fold(result, err => {
- errors.push(...err);
- }, res => {
- success[newKey] = res;
- });
- }, (newKey, instantiator) => {
- success[newKey] = instantiator(obj);
- });
- }
- return errors.length > 0 ? SimpleResult.serror(errors) : SimpleResult.svalue(success);
- };
- const objOf = values => {
- const extract = (path, o) => extractFields(path, o, values);
- const toString = () => {
- const fieldStrings = map$3(values, value => fold(value, (key, _okey, _presence, prop) => key + ' -> ' + prop.toString(), (newKey, _instantiator) => 'state(' + newKey + ')'));
- return 'obj{\n' + fieldStrings.join('\n') + '}';
- };
- return {
- extract,
- toString
- };
- };
- const arrOf = prop => {
- const extract = (path, array) => {
- const results = map$3(array, (a, i) => prop.extract(path.concat(['[' + i + ']']), a));
- return ResultCombine.consolidateArr(results);
- };
- const toString = () => 'array(' + prop.toString() + ')';
- return {
- extract,
- toString
- };
- };
- const valueOf = validator => value(v => validator(v).fold(SimpleResult.serror, SimpleResult.svalue));
- const extractValue = (label, prop, obj) => {
- const res = prop.extract([label], obj);
- return SimpleResult.mapError(res, errs => ({
- input: obj,
- errors: errs
- }));
- };
- const asRaw = (label, prop, obj) => SimpleResult.toResult(extractValue(label, prop, obj));
- const formatError = errInfo => {
- return 'Errors: \n' + formatErrors(errInfo.errors).join('\n') + '\n\nInput object: ' + formatObj(errInfo.input);
- };
- const choose = (key, branches) => choose$1(key, map$2(branches, objOf));
- const anyValue = constant(anyValue$1);
- const typedValue = (validator, expectedType) => value(a => {
- const actualType = typeof a;
- return validator(a) ? SimpleResult.svalue(a) : SimpleResult.serror(`Expected type: ${ expectedType } but got: ${ actualType }`);
- });
- const number = typedValue(isNumber, 'number');
- const string = typedValue(isString, 'string');
- const boolean = typedValue(isBoolean, 'boolean');
- const functionProcessor = typedValue(isFunction, 'function');
- const field = field$1;
- const customField = customField$1;
- const validateEnum = values => valueOf(value => contains$2(values, value) ? Result.value(value) : Result.error(`Unsupported value: "${ value }", choose one of "${ values.join(', ') }".`));
- const requiredOf = (key, schema) => field(key, key, required(), schema);
- const requiredString = key => requiredOf(key, string);
- const requiredFunction = key => requiredOf(key, functionProcessor);
- const requiredArrayOf = (key, schema) => field(key, key, required(), arrOf(schema));
- const optionOf = (key, schema) => field(key, key, asOption(), schema);
- const optionString = key => optionOf(key, string);
- const optionFunction = key => optionOf(key, functionProcessor);
- const defaulted = (key, fallback) => field(key, key, defaulted$1(fallback), anyValue());
- const defaultedOf = (key, fallback, schema) => field(key, key, defaulted$1(fallback), schema);
- const defaultedNumber = (key, fallback) => defaultedOf(key, fallback, number);
- const defaultedString = (key, fallback) => defaultedOf(key, fallback, string);
- const defaultedStringEnum = (key, fallback, values) => defaultedOf(key, fallback, validateEnum(values));
- const defaultedBoolean = (key, fallback) => defaultedOf(key, fallback, boolean);
- const defaultedFunction = (key, fallback) => defaultedOf(key, fallback, functionProcessor);
- const defaultedArrayOf = (key, fallback, schema) => defaultedOf(key, fallback, arrOf(schema));
- const type = requiredString('type');
- const fetch$1 = requiredFunction('fetch');
- const onAction = requiredFunction('onAction');
- const onSetup = defaultedFunction('onSetup', () => noop);
- const optionalText = optionString('text');
- const optionalIcon = optionString('icon');
- const optionalTooltip = optionString('tooltip');
- const optionalLabel = optionString('label');
- const active = defaultedBoolean('active', false);
- const enabled = defaultedBoolean('enabled', true);
- const primary = defaultedBoolean('primary', false);
- const defaultedColumns = num => defaulted('columns', num);
- const defaultedType = type => defaultedString('type', type);
- const autocompleterSchema = objOf([
- type,
- requiredString('ch'),
- defaultedNumber('minChars', 1),
- defaultedColumns(1),
- defaultedNumber('maxResults', 10),
- optionFunction('matches'),
- fetch$1,
- onAction,
- defaultedArrayOf('highlightOn', [], string)
- ]);
- const createAutocompleter = spec => asRaw('Autocompleter', autocompleterSchema, spec);
- const baseToolbarButtonFields = [
- enabled,
- optionalTooltip,
- optionalIcon,
- optionalText,
- onSetup
- ];
- const baseToolbarToggleButtonFields = [active].concat(baseToolbarButtonFields);
- const contextBarFields = [
- defaultedFunction('predicate', never),
- defaultedStringEnum('scope', 'node', [
- 'node',
- 'editor'
- ]),
- defaultedStringEnum('position', 'selection', [
- 'node',
- 'selection',
- 'line'
- ])
- ];
- const contextButtonFields = baseToolbarButtonFields.concat([
- defaultedType('contextformbutton'),
- primary,
- onAction,
- customField('original', identity)
- ]);
- const contextToggleButtonFields = baseToolbarToggleButtonFields.concat([
- defaultedType('contextformbutton'),
- primary,
- onAction,
- customField('original', identity)
- ]);
- const launchButtonFields = baseToolbarButtonFields.concat([defaultedType('contextformbutton')]);
- const launchToggleButtonFields = baseToolbarToggleButtonFields.concat([defaultedType('contextformtogglebutton')]);
- const toggleOrNormal = choose('type', {
- contextformbutton: contextButtonFields,
- contextformtogglebutton: contextToggleButtonFields
- });
- objOf([
- defaultedType('contextform'),
- defaultedFunction('initValue', constant('')),
- optionalLabel,
- requiredArrayOf('commands', toggleOrNormal),
- optionOf('launch', choose('type', {
- contextformbutton: launchButtonFields,
- contextformtogglebutton: launchToggleButtonFields
- }))
- ].concat(contextBarFields));
- const register$2 = editor => {
- const popups = editor.ui.registry.getAll().popups;
- const dataset = map$2(popups, popup => createAutocompleter(popup).fold(err => {
- throw new Error(formatError(err));
- }, identity));
- const triggerChars = stringArray(mapToArray(dataset, v => v.ch));
- const datasetValues = values(dataset);
- const lookupByChar = ch => filter$6(datasetValues, dv => dv.ch === ch);
- return {
- dataset,
- triggerChars,
- lookupByChar
- };
- };
- const setupEditorInput = (editor, api) => {
- const update = last$1(api.load, 50);
- editor.on('keypress compositionend', e => {
- if (e.which === 27) {
- return;
- }
- update.throttle();
- });
- editor.on('keydown', e => {
- const keyCode = e.which;
- if (keyCode === 8) {
- update.throttle();
- } else if (keyCode === 27) {
- api.cancelIfNecessary();
- }
- });
- editor.on('remove', update.cancel);
- };
- const setup$j = editor => {
- const activeAutocompleter = value$2();
- const uiActive = Cell(false);
- const isActive = activeAutocompleter.isSet;
- const cancelIfNecessary = () => {
- if (isActive()) {
- removeAutocompleterDecoration(editor);
- fireAutocompleterEnd(editor);
- uiActive.set(false);
- activeAutocompleter.clear();
- }
- };
- const commenceIfNecessary = context => {
- if (!isActive()) {
- addAutocompleterDecoration(editor, context.range);
- activeAutocompleter.set({
- triggerChar: context.triggerChar,
- matchLength: context.text.length
- });
- }
- };
- const getAutocompleters = cached(() => register$2(editor));
- const doLookup = fetchOptions => activeAutocompleter.get().map(ac => getContext(editor.dom, editor.selection.getRng(), ac.triggerChar).bind(newContext => lookupWithContext(editor, getAutocompleters, newContext, fetchOptions))).getOrThunk(() => lookup(editor, getAutocompleters));
- const load = fetchOptions => {
- doLookup(fetchOptions).fold(cancelIfNecessary, lookupInfo => {
- commenceIfNecessary(lookupInfo.context);
- lookupInfo.lookupData.then(lookupData => {
- activeAutocompleter.get().map(ac => {
- const context = lookupInfo.context;
- if (ac.triggerChar === context.triggerChar) {
- if (context.text.length - ac.matchLength >= 10) {
- cancelIfNecessary();
- } else {
- activeAutocompleter.set({
- ...ac,
- matchLength: context.text.length
- });
- if (uiActive.get()) {
- fireAutocompleterUpdate(editor, { lookupData });
- } else {
- uiActive.set(true);
- fireAutocompleterStart(editor, { lookupData });
- }
- }
- }
- });
- });
- });
- };
- editor.addCommand('mceAutocompleterReload', (_ui, value) => {
- const fetchOptions = isObject(value) ? value.fetchOptions : {};
- load(fetchOptions);
- });
- editor.addCommand('mceAutocompleterClose', cancelIfNecessary);
- setupEditorInput(editor, {
- cancelIfNecessary,
- load
- });
- };
- const createAndFireInputEvent = eventType => (editor, inputType, specifics = {}) => {
- const target = editor.getBody();
- const overrides = {
- bubbles: true,
- composed: true,
- data: null,
- isComposing: false,
- detail: 0,
- view: null,
- target,
- currentTarget: target,
- eventPhase: Event.AT_TARGET,
- originalTarget: target,
- explicitOriginalTarget: target,
- isTrusted: false,
- srcElement: target,
- cancelable: false,
- preventDefault: noop,
- inputType
- };
- const input = clone$3(new InputEvent(eventType));
- return editor.dispatch(eventType, {
- ...input,
- ...overrides,
- ...specifics
- });
- };
- const fireFakeInputEvent = createAndFireInputEvent('input');
- const fireFakeBeforeInputEvent = createAndFireInputEvent('beforeinput');
- const executeKeydownOverride$3 = (editor, caret, evt) => {
- const inputType = evt.keyCode === VK.BACKSPACE ? 'deleteContentBackward' : 'deleteContentForward';
- executeWithDelayedAction([
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete, editor)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$5, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$5, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$6, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$6, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$3, editor, caret, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$3, editor, caret, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$9, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$9, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$4, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$4, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$1, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$1, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$7, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$7, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$8, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$8, editor, true)
- },
- {
- keyCode: VK.BACKSPACE,
- action: action(backspaceDelete$2, editor, false)
- },
- {
- keyCode: VK.DELETE,
- action: action(backspaceDelete$2, editor, true)
- }
- ], evt).each(applyAction => {
- evt.preventDefault();
- const beforeInput = fireFakeBeforeInputEvent(editor, inputType);
- if (!beforeInput.isDefaultPrevented()) {
- applyAction();
- fireFakeInputEvent(editor, inputType);
- }
- });
- };
- const executeKeyupOverride = (editor, evt) => {
- execute([
- {
- keyCode: VK.BACKSPACE,
- action: action(paddEmptyElement, editor)
- },
- {
- keyCode: VK.DELETE,
- action: action(paddEmptyElement, editor)
- }
- ], evt);
- };
- const setup$i = (editor, caret) => {
- editor.on('keydown', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeydownOverride$3(editor, caret, evt);
- }
- });
- editor.on('keyup', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeyupOverride(editor, evt);
- }
- });
- };
- const firstNonWhiteSpaceNodeSibling = node => {
- while (node) {
- if (node.nodeType === 1 || node.nodeType === 3 && node.data && /[\r\n\s]/.test(node.data)) {
- return node;
- }
- node = node.nextSibling;
- }
- };
- const moveToCaretPosition = (editor, root) => {
- let node, lastNode = root;
- const dom = editor.dom;
- const moveCaretBeforeOnEnterElementsMap = editor.schema.getMoveCaretBeforeOnEnterElements();
- if (!root) {
- return;
- }
- if (/^(LI|DT|DD)$/.test(root.nodeName)) {
- const firstChild = firstNonWhiteSpaceNodeSibling(root.firstChild);
- if (firstChild && /^(UL|OL|DL)$/.test(firstChild.nodeName)) {
- root.insertBefore(dom.doc.createTextNode(nbsp), root.firstChild);
- }
- }
- const rng = dom.createRng();
- root.normalize();
- if (root.hasChildNodes()) {
- const walker = new DomTreeWalker(root, root);
- while (node = walker.current()) {
- if (isText$9(node)) {
- rng.setStart(node, 0);
- rng.setEnd(node, 0);
- break;
- }
- if (moveCaretBeforeOnEnterElementsMap[node.nodeName.toLowerCase()]) {
- rng.setStartBefore(node);
- rng.setEndBefore(node);
- break;
- }
- lastNode = node;
- node = walker.next();
- }
- if (!node) {
- rng.setStart(lastNode, 0);
- rng.setEnd(lastNode, 0);
- }
- } else {
- if (isBr$6(root)) {
- if (root.nextSibling && dom.isBlock(root.nextSibling)) {
- rng.setStartBefore(root);
- rng.setEndBefore(root);
- } else {
- rng.setStartAfter(root);
- rng.setEndAfter(root);
- }
- } else {
- rng.setStart(root, 0);
- rng.setEnd(root, 0);
- }
- }
- editor.selection.setRng(rng);
- scrollRangeIntoView(editor, rng);
- };
- const getEditableRoot$1 = (dom, node) => {
- const root = dom.getRoot();
- let parent, editableRoot;
- parent = node;
- while (parent !== root && dom.getContentEditable(parent) !== 'false') {
- if (dom.getContentEditable(parent) === 'true') {
- editableRoot = parent;
- }
- parent = parent.parentNode;
- }
- return parent !== root ? editableRoot : root;
- };
- const getParentBlock$1 = editor => {
- return Optional.from(editor.dom.getParent(editor.selection.getStart(true), editor.dom.isBlock));
- };
- const getParentBlockName = editor => {
- return getParentBlock$1(editor).fold(constant(''), parentBlock => {
- return parentBlock.nodeName.toUpperCase();
- });
- };
- const isListItemParentBlock = editor => {
- return getParentBlock$1(editor).filter(elm => {
- return isListItem(SugarElement.fromDom(elm));
- }).isSome();
- };
- const hasFirstChild = (elm, name) => {
- return elm.firstChild && elm.firstChild.nodeName === name;
- };
- const isFirstChild = elm => {
- var _a;
- return ((_a = elm.parentNode) === null || _a === void 0 ? void 0 : _a.firstChild) === elm;
- };
- const hasParent = (elm, parentName) => {
- return elm && elm.parentNode && elm.parentNode.nodeName === parentName;
- };
- const isListBlock = elm => {
- return elm && /^(OL|UL|LI)$/.test(elm.nodeName);
- };
- const isNestedList = elm => {
- return isListBlock(elm) && isListBlock(elm.parentNode);
- };
- const getContainerBlock = containerBlock => {
- const containerBlockParent = containerBlock.parentNode;
- if (/^(LI|DT|DD)$/.test(containerBlockParent.nodeName)) {
- return containerBlockParent;
- }
- return containerBlock;
- };
- const isFirstOrLastLi = (containerBlock, parentBlock, first) => {
- let node = containerBlock[first ? 'firstChild' : 'lastChild'];
- while (node) {
- if (isElement$6(node)) {
- break;
- }
- node = node[first ? 'nextSibling' : 'previousSibling'];
- }
- return node === parentBlock;
- };
- const insert$3 = (editor, createNewBlock, containerBlock, parentBlock, newBlockName) => {
- const dom = editor.dom;
- const rng = editor.selection.getRng();
- if (containerBlock === editor.getBody()) {
- return;
- }
- if (isNestedList(containerBlock)) {
- newBlockName = 'LI';
- }
- let newBlock = createNewBlock(newBlockName);
- if (isFirstOrLastLi(containerBlock, parentBlock, true) && isFirstOrLastLi(containerBlock, parentBlock, false)) {
- if (hasParent(containerBlock, 'LI')) {
- const containerBlockParent = getContainerBlock(containerBlock);
- dom.insertAfter(newBlock, containerBlockParent);
- if (isFirstChild(containerBlock)) {
- dom.remove(containerBlockParent);
- } else {
- dom.remove(containerBlock);
- }
- } else {
- dom.replace(newBlock, containerBlock);
- }
- } else if (isFirstOrLastLi(containerBlock, parentBlock, true)) {
- if (hasParent(containerBlock, 'LI')) {
- dom.insertAfter(newBlock, getContainerBlock(containerBlock));
- newBlock.appendChild(dom.doc.createTextNode(' '));
- newBlock.appendChild(containerBlock);
- } else {
- containerBlock.parentNode.insertBefore(newBlock, containerBlock);
- }
- dom.remove(parentBlock);
- } else if (isFirstOrLastLi(containerBlock, parentBlock, false)) {
- dom.insertAfter(newBlock, getContainerBlock(containerBlock));
- dom.remove(parentBlock);
- } else {
- containerBlock = getContainerBlock(containerBlock);
- const tmpRng = rng.cloneRange();
- tmpRng.setStartAfter(parentBlock);
- tmpRng.setEndAfter(containerBlock);
- const fragment = tmpRng.extractContents();
- if (newBlockName === 'LI' && hasFirstChild(fragment, 'LI')) {
- newBlock = fragment.firstChild;
- dom.insertAfter(fragment, containerBlock);
- } else {
- dom.insertAfter(fragment, containerBlock);
- dom.insertAfter(newBlock, containerBlock);
- }
- dom.remove(parentBlock);
- }
- moveToCaretPosition(editor, newBlock);
- };
- const trimZwsp = fragment => {
- each$f(descendants$1(SugarElement.fromDom(fragment), isText$a), text => {
- const rawNode = text.dom;
- rawNode.nodeValue = trim$1(rawNode.nodeValue);
- });
- };
- const isEmptyAnchor = (dom, elm) => {
- return elm && elm.nodeName === 'A' && dom.isEmpty(elm);
- };
- const isTableCell = node => {
- return node && /^(TD|TH|CAPTION)$/.test(node.nodeName);
- };
- const emptyBlock = elm => {
- elm.innerHTML = '<br data-mce-bogus="1">';
- };
- const containerAndSiblingName = (container, nodeName) => {
- return container.nodeName === nodeName || container.previousSibling && container.previousSibling.nodeName === nodeName;
- };
- const canSplitBlock = (dom, node) => {
- return node && dom.isBlock(node) && !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) && !/^(fixed|absolute)/i.test(node.style.position) && dom.getContentEditable(node) !== 'true';
- };
- const trimInlineElementsOnLeftSideOfBlock = (dom, nonEmptyElementsMap, block) => {
- let node = block;
- const firstChilds = [];
- let i;
- if (!node) {
- return;
- }
- while (node = node.firstChild) {
- if (dom.isBlock(node)) {
- return;
- }
- if (isElement$6(node) && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
- firstChilds.push(node);
- }
- }
- i = firstChilds.length;
- while (i--) {
- node = firstChilds[i];
- if (!node.hasChildNodes() || node.firstChild === node.lastChild && node.firstChild.nodeValue === '') {
- dom.remove(node);
- } else {
- if (isEmptyAnchor(dom, node)) {
- dom.remove(node);
- }
- }
- }
- };
- const normalizeZwspOffset = (start, container, offset) => {
- if (isText$9(container) === false) {
- return offset;
- } else if (start) {
- return offset === 1 && container.data.charAt(offset - 1) === ZWSP$1 ? 0 : offset;
- } else {
- return offset === container.data.length - 1 && container.data.charAt(offset) === ZWSP$1 ? container.data.length : offset;
- }
- };
- const includeZwspInRange = rng => {
- const newRng = rng.cloneRange();
- newRng.setStart(rng.startContainer, normalizeZwspOffset(true, rng.startContainer, rng.startOffset));
- newRng.setEnd(rng.endContainer, normalizeZwspOffset(false, rng.endContainer, rng.endOffset));
- return newRng;
- };
- const trimLeadingLineBreaks = node => {
- do {
- if (isText$9(node)) {
- node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
- }
- node = node.firstChild;
- } while (node);
- };
- const getEditableRoot = (dom, node) => {
- const root = dom.getRoot();
- let parent, editableRoot;
- parent = node;
- while (parent !== root && dom.getContentEditable(parent) !== 'false') {
- if (dom.getContentEditable(parent) === 'true') {
- editableRoot = parent;
- }
- parent = parent.parentNode;
- }
- return parent !== root ? editableRoot : root;
- };
- const applyAttributes = (editor, node, forcedRootBlockAttrs) => {
- const dom = editor.dom;
- Optional.from(forcedRootBlockAttrs.style).map(dom.parseStyle).each(attrStyles => {
- const currentStyles = getAllRaw(SugarElement.fromDom(node));
- const newStyles = {
- ...currentStyles,
- ...attrStyles
- };
- dom.setStyles(node, newStyles);
- });
- const attrClassesOpt = Optional.from(forcedRootBlockAttrs.class).map(attrClasses => attrClasses.split(/\s+/));
- const currentClassesOpt = Optional.from(node.className).map(currentClasses => filter$6(currentClasses.split(/\s+/), clazz => clazz !== ''));
- lift2(attrClassesOpt, currentClassesOpt, (attrClasses, currentClasses) => {
- const filteredClasses = filter$6(currentClasses, clazz => !contains$2(attrClasses, clazz));
- const newClasses = [
- ...attrClasses,
- ...filteredClasses
- ];
- dom.setAttrib(node, 'class', newClasses.join(' '));
- });
- const appliedAttrs = [
- 'style',
- 'class'
- ];
- const remainingAttrs = filter$5(forcedRootBlockAttrs, (_, attrs) => !contains$2(appliedAttrs, attrs));
- dom.setAttribs(node, remainingAttrs);
- };
- const setForcedBlockAttrs = (editor, node) => {
- const forcedRootBlockName = getForcedRootBlock(editor);
- if (forcedRootBlockName.toLowerCase() === node.tagName.toLowerCase()) {
- const forcedRootBlockAttrs = getForcedRootBlockAttrs(editor);
- applyAttributes(editor, node, forcedRootBlockAttrs);
- }
- };
- const wrapSelfAndSiblingsInDefaultBlock = (editor, newBlockName, rng, container, offset) => {
- let newBlock, parentBlock, startNode, node, next, rootBlockName;
- const dom = editor.dom, editableRoot = getEditableRoot(dom, container);
- parentBlock = dom.getParent(container, dom.isBlock);
- if (!parentBlock || !canSplitBlock(dom, parentBlock)) {
- parentBlock = parentBlock || editableRoot;
- if (parentBlock === editor.getBody() || isTableCell(parentBlock)) {
- rootBlockName = parentBlock.nodeName.toLowerCase();
- } else {
- rootBlockName = parentBlock.parentNode.nodeName.toLowerCase();
- }
- if (!parentBlock.hasChildNodes()) {
- newBlock = dom.create(newBlockName);
- setForcedBlockAttrs(editor, newBlock);
- parentBlock.appendChild(newBlock);
- rng.setStart(newBlock, 0);
- rng.setEnd(newBlock, 0);
- return newBlock;
- }
- node = container;
- while (node.parentNode !== parentBlock) {
- node = node.parentNode;
- }
- while (node && !dom.isBlock(node)) {
- startNode = node;
- node = node.previousSibling;
- }
- if (startNode && editor.schema.isValidChild(rootBlockName, newBlockName.toLowerCase())) {
- newBlock = dom.create(newBlockName);
- setForcedBlockAttrs(editor, newBlock);
- startNode.parentNode.insertBefore(newBlock, startNode);
- node = startNode;
- while (node && !dom.isBlock(node)) {
- next = node.nextSibling;
- newBlock.appendChild(node);
- node = next;
- }
- rng.setStart(container, offset);
- rng.setEnd(container, offset);
- }
- }
- return container;
- };
- const addBrToBlockIfNeeded = (dom, block) => {
- block.normalize();
- const lastChild = block.lastChild;
- if (!lastChild || /^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true))) {
- dom.add(block, 'br');
- }
- };
- const shouldEndContainer = (editor, container) => {
- const optionValue = shouldEndContainerOnEmptyBlock(editor);
- if (isNullable(container)) {
- return false;
- } else if (isString(optionValue)) {
- return contains$2(Tools.explode(optionValue), container.nodeName.toLowerCase());
- } else {
- return optionValue;
- }
- };
- const insert$2 = (editor, evt) => {
- let tmpRng, container, offset, parentBlock;
- let newBlock, fragment, containerBlock, parentBlockName, isAfterLastNodeInContainer;
- const dom = editor.dom;
- const schema = editor.schema, nonEmptyElementsMap = schema.getNonEmptyElements();
- const rng = editor.selection.getRng();
- const newBlockName = getForcedRootBlock(editor);
- const createNewBlock = name => {
- let node = container, block, clonedNode, caretNode;
- const textInlineElements = schema.getTextInlineElements();
- if (name || parentBlockName === 'TABLE' || parentBlockName === 'HR') {
- block = dom.create(name || newBlockName);
- } else {
- block = parentBlock.cloneNode(false);
- }
- caretNode = block;
- if (shouldKeepStyles(editor) === false) {
- dom.setAttrib(block, 'style', null);
- dom.setAttrib(block, 'class', null);
- } else {
- do {
- if (textInlineElements[node.nodeName]) {
- if (isCaretNode(node) || isBookmarkNode$1(node)) {
- continue;
- }
- clonedNode = node.cloneNode(false);
- dom.setAttrib(clonedNode, 'id', '');
- if (block.hasChildNodes()) {
- clonedNode.appendChild(block.firstChild);
- block.appendChild(clonedNode);
- } else {
- caretNode = clonedNode;
- block.appendChild(clonedNode);
- }
- }
- } while ((node = node.parentNode) && node !== editableRoot);
- }
- setForcedBlockAttrs(editor, block);
- emptyBlock(caretNode);
- return block;
- };
- const isCaretAtStartOrEndOfBlock = start => {
- let node, name;
- const normalizedOffset = normalizeZwspOffset(start, container, offset);
- if (isText$9(container) && (start ? normalizedOffset > 0 : normalizedOffset < container.nodeValue.length)) {
- return false;
- }
- if (container.parentNode === parentBlock && isAfterLastNodeInContainer && !start) {
- return true;
- }
- if (start && isElement$6(container) && container === parentBlock.firstChild) {
- return true;
- }
- if (containerAndSiblingName(container, 'TABLE') || containerAndSiblingName(container, 'HR')) {
- return isAfterLastNodeInContainer && !start || !isAfterLastNodeInContainer && start;
- }
- const walker = new DomTreeWalker(container, parentBlock);
- if (isText$9(container)) {
- if (start && normalizedOffset === 0) {
- walker.prev();
- } else if (!start && normalizedOffset === container.nodeValue.length) {
- walker.next();
- }
- }
- while (node = walker.current()) {
- if (isElement$6(node)) {
- if (!node.getAttribute('data-mce-bogus')) {
- name = node.nodeName.toLowerCase();
- if (nonEmptyElementsMap[name] && name !== 'br') {
- return false;
- }
- }
- } else if (isText$9(node) && !isWhitespaceText(node.nodeValue)) {
- return false;
- }
- if (start) {
- walker.prev();
- } else {
- walker.next();
- }
- }
- return true;
- };
- const insertNewBlockAfter = () => {
- if (/^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) && containerBlockName !== 'HGROUP') {
- newBlock = createNewBlock(newBlockName);
- } else {
- newBlock = createNewBlock();
- }
- if (shouldEndContainer(editor, containerBlock) && canSplitBlock(dom, containerBlock) && dom.isEmpty(parentBlock)) {
- newBlock = dom.split(containerBlock, parentBlock);
- } else {
- dom.insertAfter(newBlock, parentBlock);
- }
- moveToCaretPosition(editor, newBlock);
- };
- normalize$2(dom, rng).each(normRng => {
- rng.setStart(normRng.startContainer, normRng.startOffset);
- rng.setEnd(normRng.endContainer, normRng.endOffset);
- });
- container = rng.startContainer;
- offset = rng.startOffset;
- const shiftKey = !!(evt && evt.shiftKey);
- const ctrlKey = !!(evt && evt.ctrlKey);
- if (isElement$6(container) && container.hasChildNodes()) {
- isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
- container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
- if (isAfterLastNodeInContainer && isText$9(container)) {
- offset = container.nodeValue.length;
- } else {
- offset = 0;
- }
- }
- const editableRoot = getEditableRoot(dom, container);
- if (!editableRoot) {
- return;
- }
- if (!shiftKey) {
- container = wrapSelfAndSiblingsInDefaultBlock(editor, newBlockName, rng, container, offset);
- }
- parentBlock = dom.getParent(container, dom.isBlock);
- containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
- parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : '';
- const containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : '';
- if (containerBlockName === 'LI' && !ctrlKey) {
- parentBlock = containerBlock;
- containerBlock = containerBlock.parentNode;
- parentBlockName = containerBlockName;
- }
- if (/^(LI|DT|DD)$/.test(parentBlockName)) {
- if (dom.isEmpty(parentBlock)) {
- insert$3(editor, createNewBlock, containerBlock, parentBlock, newBlockName);
- return;
- }
- }
- if (parentBlock === editor.getBody()) {
- return;
- }
- if (isCaretContainerBlock$1(parentBlock)) {
- newBlock = showCaretContainerBlock(parentBlock);
- if (dom.isEmpty(parentBlock)) {
- emptyBlock(parentBlock);
- }
- setForcedBlockAttrs(editor, newBlock);
- moveToCaretPosition(editor, newBlock);
- } else if (isCaretAtStartOrEndOfBlock()) {
- insertNewBlockAfter();
- } else if (isCaretAtStartOrEndOfBlock(true)) {
- newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
- moveToCaretPosition(editor, containerAndSiblingName(parentBlock, 'HR') ? newBlock : parentBlock);
- } else {
- tmpRng = includeZwspInRange(rng).cloneRange();
- tmpRng.setEndAfter(parentBlock);
- fragment = tmpRng.extractContents();
- trimZwsp(fragment);
- trimLeadingLineBreaks(fragment);
- newBlock = fragment.firstChild;
- dom.insertAfter(fragment, parentBlock);
- trimInlineElementsOnLeftSideOfBlock(dom, nonEmptyElementsMap, newBlock);
- addBrToBlockIfNeeded(dom, parentBlock);
- if (dom.isEmpty(parentBlock)) {
- emptyBlock(parentBlock);
- }
- newBlock.normalize();
- if (dom.isEmpty(newBlock)) {
- dom.remove(newBlock);
- insertNewBlockAfter();
- } else {
- setForcedBlockAttrs(editor, newBlock);
- moveToCaretPosition(editor, newBlock);
- }
- }
- dom.setAttrib(newBlock, 'id', '');
- editor.dispatch('NewBlock', { newBlock });
- };
- const fakeEventName$1 = 'insertParagraph';
- const blockbreak = {
- insert: insert$2,
- fakeEventName: fakeEventName$1
- };
- const hasRightSideContent = (schema, container, parentBlock) => {
- const walker = new DomTreeWalker(container, parentBlock);
- let node;
- const nonEmptyElementsMap = schema.getNonEmptyElements();
- while (node = walker.next()) {
- if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
- return true;
- }
- }
- };
- const moveSelectionToBr = (editor, brElm, extraBr) => {
- const rng = editor.dom.createRng();
- if (!extraBr) {
- rng.setStartAfter(brElm);
- rng.setEndAfter(brElm);
- } else {
- rng.setStartBefore(brElm);
- rng.setEndBefore(brElm);
- }
- editor.selection.setRng(rng);
- scrollRangeIntoView(editor, rng);
- };
- const insertBrAtCaret = (editor, evt) => {
- const selection = editor.selection;
- const dom = editor.dom;
- const rng = selection.getRng();
- let brElm;
- let extraBr;
- normalize$2(dom, rng).each(normRng => {
- rng.setStart(normRng.startContainer, normRng.startOffset);
- rng.setEnd(normRng.endContainer, normRng.endOffset);
- });
- let offset = rng.startOffset;
- let container = rng.startContainer;
- if (container.nodeType === 1 && container.hasChildNodes()) {
- const isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
- container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
- if (isAfterLastNodeInContainer && container.nodeType === 3) {
- offset = container.nodeValue.length;
- } else {
- offset = 0;
- }
- }
- let parentBlock = dom.getParent(container, dom.isBlock);
- const containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
- const containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : '';
- const isControlKey = !!(evt && evt.ctrlKey);
- if (containerBlockName === 'LI' && !isControlKey) {
- parentBlock = containerBlock;
- }
- if (container && container.nodeType === 3 && offset >= container.nodeValue.length) {
- if (!hasRightSideContent(editor.schema, container, parentBlock)) {
- brElm = dom.create('br');
- rng.insertNode(brElm);
- rng.setStartAfter(brElm);
- rng.setEndAfter(brElm);
- extraBr = true;
- }
- }
- brElm = dom.create('br');
- rangeInsertNode(dom, rng, brElm);
- moveSelectionToBr(editor, brElm, extraBr);
- editor.undoManager.add();
- };
- const insertBrBefore = (editor, inline) => {
- const br = SugarElement.fromTag('br');
- before$3(SugarElement.fromDom(inline), br);
- editor.undoManager.add();
- };
- const insertBrAfter = (editor, inline) => {
- if (!hasBrAfter(editor.getBody(), inline)) {
- after$4(SugarElement.fromDom(inline), SugarElement.fromTag('br'));
- }
- const br = SugarElement.fromTag('br');
- after$4(SugarElement.fromDom(inline), br);
- moveSelectionToBr(editor, br.dom, false);
- editor.undoManager.add();
- };
- const isBeforeBr = pos => {
- return isBr$6(pos.getNode());
- };
- const hasBrAfter = (rootNode, startNode) => {
- if (isBeforeBr(CaretPosition.after(startNode))) {
- return true;
- } else {
- return nextPosition(rootNode, CaretPosition.after(startNode)).map(pos => {
- return isBr$6(pos.getNode());
- }).getOr(false);
- }
- };
- const isAnchorLink = elm => {
- return elm && elm.nodeName === 'A' && 'href' in elm;
- };
- const isInsideAnchor = location => {
- return location.fold(never, isAnchorLink, isAnchorLink, never);
- };
- const readInlineAnchorLocation = editor => {
- const isInlineTarget$1 = curry(isInlineTarget, editor);
- const position = CaretPosition.fromRangeStart(editor.selection.getRng());
- return readLocation(isInlineTarget$1, editor.getBody(), position).filter(isInsideAnchor);
- };
- const insertBrOutsideAnchor = (editor, location) => {
- location.fold(noop, curry(insertBrBefore, editor), curry(insertBrAfter, editor), noop);
- };
- const insert$1 = (editor, evt) => {
- const anchorLocation = readInlineAnchorLocation(editor);
- if (anchorLocation.isSome()) {
- anchorLocation.each(curry(insertBrOutsideAnchor, editor));
- } else {
- insertBrAtCaret(editor, evt);
- }
- };
- const fakeEventName = 'insertLineBreak';
- const linebreak = {
- insert: insert$1,
- fakeEventName
- };
- const matchesSelector = (editor, selector) => {
- return getParentBlock$1(editor).filter(parentBlock => {
- return selector.length > 0 && is$1(SugarElement.fromDom(parentBlock), selector);
- }).isSome();
- };
- const shouldInsertBr = editor => {
- return matchesSelector(editor, getBrNewLineSelector(editor));
- };
- const shouldBlockNewLine$1 = editor => {
- return matchesSelector(editor, getNoNewLineSelector(editor));
- };
- const newLineAction = Adt.generate([
- { br: [] },
- { block: [] },
- { none: [] }
- ]);
- const shouldBlockNewLine = (editor, _shiftKey) => {
- return shouldBlockNewLine$1(editor);
- };
- const inListBlock = requiredState => {
- return (editor, _shiftKey) => {
- return isListItemParentBlock(editor) === requiredState;
- };
- };
- const inBlock = (blockName, requiredState) => (editor, _shiftKey) => {
- const state = getParentBlockName(editor) === blockName.toUpperCase();
- return state === requiredState;
- };
- const inPreBlock = requiredState => inBlock('pre', requiredState);
- const inSummaryBlock = () => inBlock('summary', true);
- const shouldPutBrInPre = requiredState => {
- return (editor, _shiftKey) => {
- return shouldPutBrInPre$1(editor) === requiredState;
- };
- };
- const inBrContext = (editor, _shiftKey) => {
- return shouldInsertBr(editor);
- };
- const hasShiftKey = (_editor, shiftKey) => {
- return shiftKey;
- };
- const canInsertIntoEditableRoot = editor => {
- const forcedRootBlock = getForcedRootBlock(editor);
- const rootEditable = getEditableRoot$1(editor.dom, editor.selection.getStart());
- return rootEditable && editor.schema.isValidChild(rootEditable.nodeName, forcedRootBlock);
- };
- const match = (predicates, action) => {
- return (editor, shiftKey) => {
- const isMatch = foldl(predicates, (res, p) => {
- return res && p(editor, shiftKey);
- }, true);
- return isMatch ? Optional.some(action) : Optional.none();
- };
- };
- const getAction = (editor, evt) => {
- return evaluateUntil([
- match([shouldBlockNewLine], newLineAction.none()),
- match([inSummaryBlock()], newLineAction.br()),
- match([
- inPreBlock(true),
- shouldPutBrInPre(false),
- hasShiftKey
- ], newLineAction.br()),
- match([
- inPreBlock(true),
- shouldPutBrInPre(false)
- ], newLineAction.block()),
- match([
- inPreBlock(true),
- shouldPutBrInPre(true),
- hasShiftKey
- ], newLineAction.block()),
- match([
- inPreBlock(true),
- shouldPutBrInPre(true)
- ], newLineAction.br()),
- match([
- inListBlock(true),
- hasShiftKey
- ], newLineAction.br()),
- match([inListBlock(true)], newLineAction.block()),
- match([inBrContext], newLineAction.br()),
- match([hasShiftKey], newLineAction.br()),
- match([canInsertIntoEditableRoot], newLineAction.block())
- ], [
- editor,
- !!(evt && evt.shiftKey)
- ]).getOr(newLineAction.none());
- };
- const insertBreak = (breakType, editor, evt) => {
- if (!editor.selection.isCollapsed()) {
- execDeleteCommand(editor);
- }
- if (isNonNullable(evt)) {
- const event = fireFakeBeforeInputEvent(editor, breakType.fakeEventName);
- if (event.isDefaultPrevented()) {
- return;
- }
- }
- breakType.insert(editor, evt);
- if (isNonNullable(evt)) {
- fireFakeInputEvent(editor, breakType.fakeEventName);
- }
- };
- const insert = (editor, evt) => {
- const br = () => insertBreak(linebreak, editor, evt);
- const block = () => insertBreak(blockbreak, editor, evt);
- const logicalAction = getAction(editor, evt);
- switch (getNewlineBehavior(editor)) {
- case 'linebreak':
- logicalAction.fold(br, br, noop);
- break;
- case 'block':
- logicalAction.fold(block, block, noop);
- break;
- case 'invert':
- logicalAction.fold(block, br, noop);
- break;
- default:
- logicalAction.fold(br, block, noop);
- break;
- }
- };
- const handleEnterKeyEvent = (editor, event) => {
- if (event.isDefaultPrevented()) {
- return;
- }
- event.preventDefault();
- endTypingLevelIgnoreLocks(editor.undoManager);
- editor.undoManager.transact(() => {
- insert(editor, event);
- });
- };
- const setup$h = editor => {
- editor.on('keydown', event => {
- if (event.keyCode === VK.ENTER) {
- handleEnterKeyEvent(editor, event);
- }
- });
- };
- const executeKeydownOverride$2 = (editor, caret, evt) => {
- const isMac = Env.os.isMacOS() || Env.os.isiOS();
- execute([
- {
- keyCode: VK.END,
- action: action(moveToLineEndPoint$1, editor, true)
- },
- {
- keyCode: VK.HOME,
- action: action(moveToLineEndPoint$1, editor, false)
- },
- ...!isMac ? [
- {
- keyCode: VK.HOME,
- action: action(selectToEndPoint, editor, false),
- ctrlKey: true,
- shiftKey: true
- },
- {
- keyCode: VK.END,
- action: action(selectToEndPoint, editor, true),
- ctrlKey: true,
- shiftKey: true
- }
- ] : [],
- {
- keyCode: VK.END,
- action: action(moveToLineEndPoint, editor, true)
- },
- {
- keyCode: VK.HOME,
- action: action(moveToLineEndPoint, editor, false)
- },
- {
- keyCode: VK.END,
- action: action(moveToLineEndPoint$2, editor, true, caret)
- },
- {
- keyCode: VK.HOME,
- action: action(moveToLineEndPoint$2, editor, false, caret)
- }
- ], evt).each(_ => {
- evt.preventDefault();
- });
- };
- const setup$g = (editor, caret) => {
- editor.on('keydown', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeydownOverride$2(editor, caret, evt);
- }
- });
- };
- const setup$f = editor => {
- editor.on('input', e => {
- if (e.isComposing === false) {
- normalizeNbspsInEditor(editor);
- }
- });
- };
- const platform = detect$2();
- const executeKeyupAction = (editor, caret, evt) => {
- execute([
- {
- keyCode: VK.PAGE_UP,
- action: action(moveToLineEndPoint$2, editor, false, caret)
- },
- {
- keyCode: VK.PAGE_DOWN,
- action: action(moveToLineEndPoint$2, editor, true, caret)
- }
- ], evt);
- };
- const stopImmediatePropagation = e => e.stopImmediatePropagation();
- const isPageUpDown = evt => evt.keyCode === VK.PAGE_UP || evt.keyCode === VK.PAGE_DOWN;
- const setNodeChangeBlocker = (blocked, editor, block) => {
- if (block && !blocked.get()) {
- editor.on('NodeChange', stopImmediatePropagation, true);
- } else if (!block && blocked.get()) {
- editor.off('NodeChange', stopImmediatePropagation);
- }
- blocked.set(block);
- };
- const setup$e = (editor, caret) => {
- if (platform.os.isMacOS()) {
- return;
- }
- const blocked = Cell(false);
- editor.on('keydown', evt => {
- if (isPageUpDown(evt)) {
- setNodeChangeBlocker(blocked, editor, true);
- }
- });
- editor.on('keyup', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeyupAction(editor, caret, evt);
- }
- if (isPageUpDown(evt) && blocked.get()) {
- setNodeChangeBlocker(blocked, editor, false);
- editor.nodeChanged();
- }
- });
- };
- const insertTextAtPosition = (text, pos) => {
- const container = pos.container();
- const offset = pos.offset();
- if (isText$9(container)) {
- container.insertData(offset, text);
- return Optional.some(CaretPosition(container, offset + text.length));
- } else {
- return getElementFromPosition(pos).map(elm => {
- const textNode = SugarElement.fromText(text);
- if (pos.isAtEnd()) {
- after$4(elm, textNode);
- } else {
- before$3(elm, textNode);
- }
- return CaretPosition(textNode.dom, text.length);
- });
- }
- };
- const insertNbspAtPosition = curry(insertTextAtPosition, nbsp);
- const insertSpaceAtPosition = curry(insertTextAtPosition, ' ');
- const locationToCaretPosition = root => location => location.fold(element => prevPosition(root.dom, CaretPosition.before(element)), element => firstPositionIn(element), element => lastPositionIn(element), element => nextPosition(root.dom, CaretPosition.after(element)));
- const insertInlineBoundarySpaceOrNbsp = (root, pos) => checkPos => needsToHaveNbsp(root, checkPos) ? insertNbspAtPosition(pos) : insertSpaceAtPosition(pos);
- const setSelection = editor => pos => {
- editor.selection.setRng(pos.toRange());
- editor.nodeChanged();
- return true;
- };
- const insertSpaceOrNbspAtSelection = editor => {
- const pos = CaretPosition.fromRangeStart(editor.selection.getRng());
- const root = SugarElement.fromDom(editor.getBody());
- if (editor.selection.isCollapsed()) {
- const isInlineTarget$1 = curry(isInlineTarget, editor);
- const caretPosition = CaretPosition.fromRangeStart(editor.selection.getRng());
- return readLocation(isInlineTarget$1, editor.getBody(), caretPosition).bind(locationToCaretPosition(root)).map(checkPos => () => insertInlineBoundarySpaceOrNbsp(root, pos)(checkPos).each(setSelection(editor)));
- } else {
- return Optional.none();
- }
- };
- const executeKeydownOverride$1 = (editor, evt) => {
- executeWithDelayedAction([{
- keyCode: VK.SPACEBAR,
- action: action(insertSpaceOrNbspAtSelection, editor)
- }], evt).each(applyAction => {
- evt.preventDefault();
- const event = fireFakeBeforeInputEvent(editor, 'insertText', { data: ' ' });
- if (!event.isDefaultPrevented()) {
- applyAction();
- fireFakeInputEvent(editor, 'insertText', { data: ' ' });
- }
- });
- };
- const setup$d = editor => {
- editor.on('keydown', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeydownOverride$1(editor, evt);
- }
- });
- };
- const tableTabNavigation = editor => {
- if (hasTableTabNavigation(editor)) {
- return [
- {
- keyCode: VK.TAB,
- action: action(handleTab, editor, true)
- },
- {
- keyCode: VK.TAB,
- shiftKey: true,
- action: action(handleTab, editor, false)
- }
- ];
- } else {
- return [];
- }
- };
- const executeKeydownOverride = (editor, evt) => {
- execute([...tableTabNavigation(editor)], evt).each(_ => {
- evt.preventDefault();
- });
- };
- const setup$c = editor => {
- editor.on('keydown', evt => {
- if (evt.isDefaultPrevented() === false) {
- executeKeydownOverride(editor, evt);
- }
- });
- };
- const setup$b = editor => {
- editor.addShortcut('Meta+P', '', 'mcePrint');
- setup$j(editor);
- if (isRtc(editor)) {
- return Cell(null);
- } else {
- const caret = setupSelectedState(editor);
- setup$l(editor);
- setup$k(editor, caret);
- setup$i(editor, caret);
- setup$h(editor);
- setup$d(editor);
- setup$f(editor);
- setup$c(editor);
- setup$g(editor, caret);
- setup$e(editor, caret);
- return caret;
- }
- };
- class NodeChange {
- constructor(editor) {
- this.lastPath = [];
- this.editor = editor;
- let lastRng;
- const self = this;
- if (!('onselectionchange' in editor.getDoc())) {
- editor.on('NodeChange click mouseup keyup focus', e => {
- const nativeRng = editor.selection.getRng();
- const fakeRng = {
- startContainer: nativeRng.startContainer,
- startOffset: nativeRng.startOffset,
- endContainer: nativeRng.endContainer,
- endOffset: nativeRng.endOffset
- };
- if (e.type === 'nodechange' || !isEq$4(fakeRng, lastRng)) {
- editor.dispatch('SelectionChange');
- }
- lastRng = fakeRng;
- });
- }
- editor.on('contextmenu', () => {
- editor.dispatch('SelectionChange');
- });
- editor.on('SelectionChange', () => {
- const startElm = editor.selection.getStart(true);
- if (!startElm) {
- return;
- }
- if (hasAnyRanges(editor) && !self.isSameElementPath(startElm) && editor.dom.isChildOf(startElm, editor.getBody())) {
- editor.nodeChanged({ selectionChange: true });
- }
- });
- editor.on('mouseup', e => {
- if (!e.isDefaultPrevented() && hasAnyRanges(editor)) {
- if (editor.selection.getNode().nodeName === 'IMG') {
- Delay.setEditorTimeout(editor, () => {
- editor.nodeChanged();
- });
- } else {
- editor.nodeChanged();
- }
- }
- });
- }
- nodeChanged(args) {
- const selection = this.editor.selection;
- let node, parents, root;
- if (this.editor.initialized && selection && !shouldDisableNodeChange(this.editor) && !this.editor.mode.isReadOnly()) {
- root = this.editor.getBody();
- node = selection.getStart(true) || root;
- if (node.ownerDocument !== this.editor.getDoc() || !this.editor.dom.isChildOf(node, root)) {
- node = root;
- }
- parents = [];
- this.editor.dom.getParent(node, node => {
- if (node === root) {
- return true;
- }
- parents.push(node);
- });
- args = args || {};
- args.element = node;
- args.parents = parents;
- this.editor.dispatch('NodeChange', args);
- }
- }
- isSameElementPath(startElm) {
- let i;
- const editor = this.editor;
- const currentPath = reverse(editor.dom.getParents(startElm, always, editor.getBody()));
- if (currentPath.length === this.lastPath.length) {
- for (i = currentPath.length; i >= 0; i--) {
- if (currentPath[i] !== this.lastPath[i]) {
- break;
- }
- }
- if (i === -1) {
- this.lastPath = currentPath;
- return true;
- }
- }
- this.lastPath = currentPath;
- return false;
- }
- }
- const internalMimeType = 'x-tinymce/html';
- const internalHtmlMime = constant(internalMimeType);
- const internalMark = '<!-- ' + internalMimeType + ' -->';
- const mark = html => internalMark + html;
- const unmark = html => html.replace(internalMark, '');
- const isMarked = html => html.indexOf(internalMark) !== -1;
- const isPlainText = text => {
- return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text);
- };
- const openContainer = (rootTag, rootAttrs) => {
- let tag = '<' + rootTag;
- const attrs = mapToArray(rootAttrs, (value, key) => key + '="' + Entities.encodeAllRaw(value) + '"');
- if (attrs.length) {
- tag += ' ' + attrs.join(' ');
- }
- return tag + '>';
- };
- const toBlockElements = (text, rootTag, rootAttrs) => {
- const blocks = text.split(/\n\n/);
- const tagOpen = openContainer(rootTag, rootAttrs);
- const tagClose = '</' + rootTag + '>';
- const paragraphs = map$3(blocks, p => {
- return p.split(/\n/).join('<br />');
- });
- const stitch = p => {
- return tagOpen + p + tagClose;
- };
- return paragraphs.length === 1 ? paragraphs[0] : map$3(paragraphs, stitch).join('');
- };
- const pasteBinDefaultContent = '%MCEPASTEBIN%';
- const create$6 = (editor, lastRngCell) => {
- const {dom, selection} = editor;
- const body = editor.getBody();
- lastRngCell.set(selection.getRng());
- const pasteBinElm = dom.add(editor.getBody(), 'div', {
- 'id': 'mcepastebin',
- 'class': 'mce-pastebin',
- 'contentEditable': true,
- 'data-mce-bogus': 'all',
- 'style': 'position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0'
- }, pasteBinDefaultContent);
- if (Env.browser.isFirefox()) {
- dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) === 'rtl' ? 65535 : -65535);
- }
- dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', e => {
- e.stopPropagation();
- });
- pasteBinElm.focus();
- selection.select(pasteBinElm, true);
- };
- const remove = (editor, lastRngCell) => {
- const dom = editor.dom;
- if (getEl(editor)) {
- let pasteBinClone;
- const lastRng = lastRngCell.get();
- while (pasteBinClone = getEl(editor)) {
- dom.remove(pasteBinClone);
- dom.unbind(pasteBinClone);
- }
- if (lastRng) {
- editor.selection.setRng(lastRng);
- }
- }
- lastRngCell.set(null);
- };
- const getEl = editor => editor.dom.get('mcepastebin');
- const isPasteBin = elm => elm && elm.id === 'mcepastebin';
- const getHtml = editor => {
- const dom = editor.dom;
- const copyAndRemove = (toElm, fromElm) => {
- toElm.appendChild(fromElm);
- dom.remove(fromElm, true);
- };
- const [pasteBinElm, ...pasteBinClones] = filter$6(editor.getBody().childNodes, isPasteBin);
- each$f(pasteBinClones, pasteBinClone => {
- copyAndRemove(pasteBinElm, pasteBinClone);
- });
- const dirtyWrappers = dom.select('div[id=mcepastebin]', pasteBinElm);
- for (let i = dirtyWrappers.length - 1; i >= 0; i--) {
- const cleanWrapper = dom.create('div');
- pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
- copyAndRemove(cleanWrapper, dirtyWrappers[i]);
- }
- return pasteBinElm ? pasteBinElm.innerHTML : '';
- };
- const isDefaultPasteBinContent = content => content === pasteBinDefaultContent;
- const PasteBin = editor => {
- const lastRng = Cell(null);
- return {
- create: () => create$6(editor, lastRng),
- remove: () => remove(editor, lastRng),
- getEl: () => getEl(editor),
- getHtml: () => getHtml(editor),
- getLastRng: lastRng.get
- };
- };
- const filter = (content, items) => {
- Tools.each(items, v => {
- if (is$4(v, RegExp)) {
- content = content.replace(v, '');
- } else {
- content = content.replace(v[0], v[1]);
- }
- });
- return content;
- };
- const innerText = html => {
- const schema = Schema();
- const domParser = DomParser({}, schema);
- let text = '';
- const voidElements = schema.getVoidElements();
- const ignoreElements = Tools.makeMap('script noscript style textarea video audio iframe object', ' ');
- const blockElements = schema.getBlockElements();
- const walk = node => {
- const name = node.name, currentNode = node;
- if (name === 'br') {
- text += '\n';
- return;
- }
- if (name === 'wbr') {
- return;
- }
- if (voidElements[name]) {
- text += ' ';
- }
- if (ignoreElements[name]) {
- text += ' ';
- return;
- }
- if (node.type === 3) {
- text += node.value;
- }
- if (!(node.name in schema.getVoidElements())) {
- if (node = node.firstChild) {
- do {
- walk(node);
- } while (node = node.next);
- }
- }
- if (blockElements[name] && currentNode.next) {
- text += '\n';
- if (name === 'p') {
- text += '\n';
- }
- }
- };
- html = filter(html, [/<!\[[^\]]+\]>/g]);
- walk(domParser.parse(html));
- return text;
- };
- const trimHtml = html => {
- const trimSpaces = (all, s1, s2) => {
- if (!s1 && !s2) {
- return ' ';
- }
- return nbsp;
- };
- html = filter(html, [
- /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
- /<!--StartFragment-->|<!--EndFragment-->/g,
- [
- /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
- trimSpaces
- ],
- /<br class="Apple-interchange-newline">/g,
- /<br>$/i
- ]);
- return html;
- };
- const createIdGenerator = prefix => {
- let count = 0;
- return () => {
- return prefix + count++;
- };
- };
- const getImageMimeType = ext => {
- const lowerExt = ext.toLowerCase();
- const mimeOverrides = {
- jpg: 'jpeg',
- jpe: 'jpeg',
- jfi: 'jpeg',
- jif: 'jpeg',
- jfif: 'jpeg',
- pjpeg: 'jpeg',
- pjp: 'jpeg',
- svg: 'svg+xml'
- };
- return Tools.hasOwn(mimeOverrides, lowerExt) ? 'image/' + mimeOverrides[lowerExt] : 'image/' + lowerExt;
- };
- const preProcess = (editor, html) => {
- const parser = DomParser({}, editor.schema);
- parser.addNodeFilter('meta', nodes => {
- Tools.each(nodes, node => {
- node.remove();
- });
- });
- const fragment = parser.parse(html, {
- forced_root_block: false,
- isRootContent: true
- });
- return HtmlSerializer({ validate: true }, editor.schema).serialize(fragment);
- };
- const processResult = (content, cancelled) => ({
- content,
- cancelled
- });
- const postProcessFilter = (editor, html, internal) => {
- const tempBody = editor.dom.create('div', { style: 'display:none' }, html);
- const postProcessArgs = firePastePostProcess(editor, tempBody, internal);
- return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
- };
- const filterContent = (editor, content, internal) => {
- const preProcessArgs = firePastePreProcess(editor, content, internal);
- const filteredContent = preProcess(editor, preProcessArgs.content);
- if (editor.hasEventListeners('PastePostProcess') && !preProcessArgs.isDefaultPrevented()) {
- return postProcessFilter(editor, filteredContent, internal);
- } else {
- return processResult(filteredContent, preProcessArgs.isDefaultPrevented());
- }
- };
- const process = (editor, html, internal) => {
- return filterContent(editor, html, internal);
- };
- const pasteHtml$1 = (editor, html) => {
- editor.insertContent(html, {
- merge: shouldPasteMergeFormats(editor),
- paste: true
- });
- return true;
- };
- const isAbsoluteUrl = url => /^https?:\/\/[\w\-\/+=.,!;:&%@^~(){}?#]+$/i.test(url);
- const isImageUrl = (editor, url) => {
- return isAbsoluteUrl(url) && exists(getAllowedImageFileTypes(editor), type => endsWith(url.toLowerCase(), `.${ type.toLowerCase() }`));
- };
- const createImage = (editor, url, pasteHtmlFn) => {
- editor.undoManager.extra(() => {
- pasteHtmlFn(editor, url);
- }, () => {
- editor.insertContent('<img src="' + url + '">');
- });
- return true;
- };
- const createLink = (editor, url, pasteHtmlFn) => {
- editor.undoManager.extra(() => {
- pasteHtmlFn(editor, url);
- }, () => {
- editor.execCommand('mceInsertLink', false, url);
- });
- return true;
- };
- const linkSelection = (editor, html, pasteHtmlFn) => !editor.selection.isCollapsed() && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
- const insertImage = (editor, html, pasteHtmlFn) => isImageUrl(editor, html) ? createImage(editor, html, pasteHtmlFn) : false;
- const smartInsertContent = (editor, html) => {
- Tools.each([
- linkSelection,
- insertImage,
- pasteHtml$1
- ], action => {
- return action(editor, html, pasteHtml$1) !== true;
- });
- };
- const insertContent = (editor, html, pasteAsText) => {
- if (pasteAsText || !isSmartPasteEnabled(editor)) {
- pasteHtml$1(editor, html);
- } else {
- smartInsertContent(editor, html);
- }
- };
- const uniqueId = createIdGenerator('mceclip');
- const doPaste = (editor, content, internal, pasteAsText) => {
- const args = process(editor, content, internal);
- if (args.cancelled === false) {
- insertContent(editor, args.content, pasteAsText);
- }
- };
- const pasteHtml = (editor, html, internalFlag) => {
- const internal = internalFlag ? internalFlag : isMarked(html);
- doPaste(editor, unmark(html), internal, false);
- };
- const pasteText = (editor, text) => {
- const encodedText = editor.dom.encode(text).replace(/\r\n/g, '\n');
- const normalizedText = normalize$4(encodedText, getPasteTabSpaces(editor));
- const html = toBlockElements(normalizedText, getForcedRootBlock(editor), getForcedRootBlockAttrs(editor));
- doPaste(editor, html, false, true);
- };
- const getDataTransferItems = dataTransfer => {
- const items = {};
- if (dataTransfer && dataTransfer.types) {
- for (let i = 0; i < dataTransfer.types.length; i++) {
- const contentType = dataTransfer.types[i];
- try {
- items[contentType] = dataTransfer.getData(contentType);
- } catch (ex) {
- items[contentType] = '';
- }
- }
- }
- return items;
- };
- const hasContentType = (clipboardContent, mimeType) => mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
- const hasHtmlOrText = content => hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
- const extractFilename = (editor, str) => {
- const m = str.match(/([\s\S]+?)(?:\.[a-z0-9.]+)$/i);
- return isNonNullable(m) ? editor.dom.encode(m[1]) : null;
- };
- const createBlobInfo = (editor, blobCache, file, base64) => {
- const id = uniqueId();
- const useFileName = shouldReuseFileName(editor) && isNonNullable(file.name);
- const name = useFileName ? extractFilename(editor, file.name) : id;
- const filename = useFileName ? file.name : undefined;
- const blobInfo = blobCache.create(id, file, base64, name, filename);
- blobCache.add(blobInfo);
- return blobInfo;
- };
- const pasteImage = (editor, imageItem) => {
- parseDataUri(imageItem.uri).each(({data, type, base64Encoded}) => {
- const base64 = base64Encoded ? data : btoa(data);
- const file = imageItem.file;
- const blobCache = editor.editorUpload.blobCache;
- const existingBlobInfo = blobCache.getByData(base64, type);
- const blobInfo = existingBlobInfo !== null && existingBlobInfo !== void 0 ? existingBlobInfo : createBlobInfo(editor, blobCache, file, base64);
- pasteHtml(editor, `<img src="${ blobInfo.blobUri() }">`, false);
- });
- };
- const isClipboardEvent = event => event.type === 'paste';
- const readFilesAsDataUris = items => Promise.all(map$3(items, file => {
- return blobToDataUri(file).then(uri => ({
- file,
- uri
- }));
- }));
- const isImage = editor => {
- const allowedExtensions = getAllowedImageFileTypes(editor);
- return file => startsWith(file.type, 'image/') && exists(allowedExtensions, extension => {
- return getImageMimeType(extension) === file.type;
- });
- };
- const getImagesFromDataTransfer = (editor, dataTransfer) => {
- const items = dataTransfer.items ? bind$3(from(dataTransfer.items), item => {
- return item.kind === 'file' ? [item.getAsFile()] : [];
- }) : [];
- const files = dataTransfer.files ? from(dataTransfer.files) : [];
- return filter$6(items.length > 0 ? items : files, isImage(editor));
- };
- const pasteImageData = (editor, e, rng) => {
- const dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
- if (shouldPasteDataImages(editor) && dataTransfer) {
- const images = getImagesFromDataTransfer(editor, dataTransfer);
- if (images.length > 0) {
- e.preventDefault();
- readFilesAsDataUris(images).then(fileResults => {
- if (rng) {
- editor.selection.setRng(rng);
- }
- each$f(fileResults, result => {
- pasteImage(editor, result);
- });
- });
- return true;
- }
- }
- return false;
- };
- const isBrokenAndroidClipboardEvent = e => {
- var _a, _b;
- return Env.os.isAndroid() && ((_b = (_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.length) === 0;
- };
- const isKeyboardPasteEvent = e => VK.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
- const insertClipboardContent = (editor, clipboardContent, html, plainTextMode) => {
- let content = trimHtml(html);
- const isInternal = hasContentType(clipboardContent, internalHtmlMime()) || isMarked(html);
- const isPlainTextHtml = !isInternal && isPlainText(content);
- const isAbsoluteUrl$1 = isAbsoluteUrl(content);
- if (isDefaultPasteBinContent(content) || !content.length || isPlainTextHtml && !isAbsoluteUrl$1) {
- plainTextMode = true;
- }
- if (plainTextMode || isAbsoluteUrl$1) {
- if (hasContentType(clipboardContent, 'text/plain') && isPlainTextHtml) {
- content = clipboardContent['text/plain'];
- } else {
- content = innerText(content);
- }
- }
- if (isDefaultPasteBinContent(content)) {
- return;
- }
- if (plainTextMode) {
- pasteText(editor, content);
- } else {
- pasteHtml(editor, content, isInternal);
- }
- };
- const registerEventHandlers = (editor, pasteBin, pasteFormat) => {
- let keyboardPastePlainTextState;
- const getLastRng = () => pasteBin.getLastRng() || editor.selection.getRng();
- editor.on('keydown', e => {
- if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
- keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
- }
- });
- editor.on('paste', e => {
- if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
- return;
- }
- const plainTextMode = pasteFormat.get() === 'text' || keyboardPastePlainTextState;
- keyboardPastePlainTextState = false;
- const clipboardContent = getDataTransferItems(e.clipboardData);
- if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
- return;
- }
- if (hasContentType(clipboardContent, 'text/html')) {
- e.preventDefault();
- insertClipboardContent(editor, clipboardContent, clipboardContent['text/html'], plainTextMode);
- } else {
- pasteBin.create();
- Delay.setEditorTimeout(editor, () => {
- const html = pasteBin.getHtml();
- pasteBin.remove();
- insertClipboardContent(editor, clipboardContent, html, plainTextMode);
- }, 0);
- }
- });
- };
- const registerDataImageFilter = editor => {
- const isWebKitFakeUrl = src => startsWith(src, 'webkit-fake-url');
- const isDataUri = src => startsWith(src, 'data:');
- const isPasteInsert = args => {
- var _a;
- return ((_a = args.data) === null || _a === void 0 ? void 0 : _a.paste) === true;
- };
- editor.parser.addNodeFilter('img', (nodes, name, args) => {
- if (!shouldPasteDataImages(editor) && isPasteInsert(args)) {
- for (const node of nodes) {
- const src = node.attr('src');
- if (isString(src) && !node.attr('data-mce-object') && src !== Env.transparentSrc) {
- if (isWebKitFakeUrl(src)) {
- node.remove();
- } else if (!shouldAllowHtmlDataUrls(editor) && isDataUri(src)) {
- node.remove();
- }
- }
- }
- }
- });
- };
- const registerEventsAndFilters = (editor, pasteBin, pasteFormat) => {
- registerEventHandlers(editor, pasteBin, pasteFormat);
- registerDataImageFilter(editor);
- };
- const togglePlainTextPaste = (editor, pasteFormat) => {
- if (pasteFormat.get() === 'text') {
- pasteFormat.set('html');
- firePastePlainTextToggle(editor, false);
- } else {
- pasteFormat.set('text');
- firePastePlainTextToggle(editor, true);
- }
- editor.focus();
- };
- const register$1 = (editor, pasteFormat) => {
- editor.addCommand('mceTogglePlainTextPaste', () => {
- togglePlainTextPaste(editor, pasteFormat);
- });
- editor.addCommand('mceInsertClipboardContent', (ui, value) => {
- if (value.html) {
- pasteHtml(editor, value.html, value.internal);
- }
- if (value.text) {
- pasteText(editor, value.text);
- }
- });
- };
- const setHtml5Clipboard = (clipboardData, html, text) => {
- try {
- clipboardData.clearData();
- clipboardData.setData('text/html', html);
- clipboardData.setData('text/plain', text);
- clipboardData.setData(internalHtmlMime(), html);
- return true;
- } catch (e) {
- return false;
- }
- };
- const setClipboardData = (evt, data, fallback, done) => {
- if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
- evt.preventDefault();
- done();
- } else {
- fallback(data.html, done);
- }
- };
- const fallback = editor => (html, done) => {
- const {dom, selection} = editor;
- const outer = dom.create('div', {
- 'contenteditable': 'false',
- 'data-mce-bogus': 'all'
- });
- const inner = dom.create('div', { contenteditable: 'true' }, html);
- dom.setStyles(outer, {
- position: 'fixed',
- top: '0',
- left: '-3000px',
- width: '1000px',
- overflow: 'hidden'
- });
- outer.appendChild(inner);
- dom.add(editor.getBody(), outer);
- const range = selection.getRng();
- inner.focus();
- const offscreenRange = dom.createRng();
- offscreenRange.selectNodeContents(inner);
- selection.setRng(offscreenRange);
- Delay.setEditorTimeout(editor, () => {
- selection.setRng(range);
- dom.remove(outer);
- done();
- }, 0);
- };
- const getData = editor => ({
- html: mark(editor.selection.getContent({ contextual: true })),
- text: editor.selection.getContent({ format: 'text' })
- });
- const isTableSelection = editor => !!editor.dom.getParent(editor.selection.getStart(), 'td[data-mce-selected],th[data-mce-selected]', editor.getBody());
- const hasSelectedContent = editor => !editor.selection.isCollapsed() || isTableSelection(editor);
- const cut = editor => evt => {
- if (!evt.isDefaultPrevented() && hasSelectedContent(editor)) {
- setClipboardData(evt, getData(editor), fallback(editor), () => {
- if (Env.browser.isChromium() || Env.browser.isFirefox()) {
- const rng = editor.selection.getRng();
- Delay.setEditorTimeout(editor, () => {
- editor.selection.setRng(rng);
- editor.execCommand('Delete');
- }, 0);
- } else {
- editor.execCommand('Delete');
- }
- });
- }
- };
- const copy = editor => evt => {
- if (!evt.isDefaultPrevented() && hasSelectedContent(editor)) {
- setClipboardData(evt, getData(editor), fallback(editor), noop);
- }
- };
- const register = editor => {
- editor.on('cut', cut(editor));
- editor.on('copy', copy(editor));
- };
- const getCaretRangeFromEvent = (editor, e) => {
- var _a, _b;
- return RangeUtils.getCaretRangeFromPoint((_a = e.clientX) !== null && _a !== void 0 ? _a : 0, (_b = e.clientY) !== null && _b !== void 0 ? _b : 0, editor.getDoc());
- };
- const isPlainTextFileUrl = content => {
- const plainTextContent = content['text/plain'];
- return plainTextContent ? plainTextContent.indexOf('file://') === 0 : false;
- };
- const setFocusedRange = (editor, rng) => {
- editor.focus();
- if (rng) {
- editor.selection.setRng(rng);
- }
- };
- const hasImage = dataTransfer => exists(dataTransfer.files, file => /^image\//.test(file.type));
- const setup$a = (editor, draggingInternallyState) => {
- if (shouldPasteBlockDrop(editor)) {
- editor.on('dragend dragover draggesture dragdrop drop drag', e => {
- e.preventDefault();
- e.stopPropagation();
- });
- }
- if (!shouldPasteDataImages(editor)) {
- editor.on('drop', e => {
- const dataTransfer = e.dataTransfer;
- if (dataTransfer && hasImage(dataTransfer)) {
- e.preventDefault();
- }
- });
- }
- editor.on('drop', e => {
- if (e.isDefaultPrevented() || draggingInternallyState.get()) {
- return;
- }
- const rng = getCaretRangeFromEvent(editor, e);
- if (isNullable(rng)) {
- return;
- }
- const dropContent = getDataTransferItems(e.dataTransfer);
- const internal = hasContentType(dropContent, internalHtmlMime());
- if ((!hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && pasteImageData(editor, e, rng)) {
- return;
- }
- const internalContent = dropContent[internalHtmlMime()];
- const content = internalContent || dropContent['text/html'] || dropContent['text/plain'];
- if (content) {
- e.preventDefault();
- Delay.setEditorTimeout(editor, () => {
- editor.undoManager.transact(() => {
- if (internalContent) {
- editor.execCommand('Delete');
- }
- setFocusedRange(editor, rng);
- const trimmedContent = trimHtml(content);
- if (dropContent['text/html']) {
- pasteHtml(editor, trimmedContent, internal);
- } else {
- pasteText(editor, trimmedContent);
- }
- });
- });
- }
- });
- editor.on('dragstart', _e => {
- draggingInternallyState.set(true);
- });
- editor.on('dragover dragend', e => {
- if (shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
- e.preventDefault();
- setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
- }
- if (e.type === 'dragend') {
- draggingInternallyState.set(false);
- }
- });
- };
- const setup$9 = editor => {
- const processEvent = f => e => {
- f(editor, e);
- };
- const preProcess = getPastePreProcess(editor);
- if (isFunction(preProcess)) {
- editor.on('PastePreProcess', processEvent(preProcess));
- }
- const postProcess = getPastePostProcess(editor);
- if (isFunction(postProcess)) {
- editor.on('PastePostProcess', processEvent(postProcess));
- }
- };
- const addPreProcessFilter = (editor, filterFunc) => {
- editor.on('PastePreProcess', e => {
- e.content = filterFunc(editor, e.content, e.internal);
- });
- };
- const rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi;
- const rgbToHex = value => Tools.trim(value).replace(rgbRegExp, rgbaToHexString).toLowerCase();
- const removeWebKitStyles = (editor, content, internal) => {
- const webKitStylesOption = getPasteWebkitStyles(editor);
- if (internal || webKitStylesOption === 'all' || !shouldPasteRemoveWebKitStyles(editor)) {
- return content;
- }
- const webKitStyles = webKitStylesOption ? webKitStylesOption.split(/[, ]/) : [];
- if (webKitStyles && webKitStylesOption !== 'none') {
- const dom = editor.dom, node = editor.selection.getNode();
- content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, (all, before, value, after) => {
- const inputStyles = dom.parseStyle(dom.decode(value));
- const outputStyles = {};
- for (let i = 0; i < webKitStyles.length; i++) {
- const inputValue = inputStyles[webKitStyles[i]];
- let compareInput = inputValue;
- let currentValue = dom.getStyle(node, webKitStyles[i], true);
- if (/color/.test(webKitStyles[i])) {
- compareInput = rgbToHex(compareInput);
- currentValue = rgbToHex(currentValue);
- }
- if (currentValue !== compareInput) {
- outputStyles[webKitStyles[i]] = inputValue;
- }
- }
- const outputStyle = dom.serializeStyle(outputStyles, 'span');
- if (outputStyle) {
- return before + ' style="' + outputStyle + '"' + after;
- }
- return before + after;
- });
- } else {
- content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, '$1$3');
- }
- content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, (all, before, value, after) => {
- return before + ' style="' + value + '"' + after;
- });
- return content;
- };
- const setup$8 = editor => {
- if (Env.browser.isChromium() || Env.browser.isSafari()) {
- addPreProcessFilter(editor, removeWebKitStyles);
- }
- };
- const setup$7 = editor => {
- const draggingInternallyState = Cell(false);
- const pasteFormat = Cell(isPasteAsTextEnabled(editor) ? 'text' : 'html');
- const pasteBin = PasteBin(editor);
- setup$8(editor);
- register$1(editor, pasteFormat);
- setup$9(editor);
- editor.on('PreInit', () => {
- register(editor);
- setup$a(editor, draggingInternallyState);
- registerEventsAndFilters(editor, pasteBin, pasteFormat);
- });
- };
- const preventSummaryToggle = editor => {
- editor.on('click', e => {
- if (editor.dom.getParent(e.target, 'details')) {
- e.preventDefault();
- }
- });
- };
- const filterDetails = editor => {
- editor.parser.addNodeFilter('details', elms => {
- each$f(elms, details => {
- details.attr('data-mce-open', details.attr('open'));
- details.attr('open', 'open');
- });
- });
- editor.serializer.addNodeFilter('details', elms => {
- each$f(elms, details => {
- const open = details.attr('data-mce-open');
- details.attr('open', isString(open) ? open : null);
- details.attr('data-mce-open', null);
- });
- });
- };
- const setup$6 = editor => {
- preventSummaryToggle(editor);
- filterDetails(editor);
- };
- const isBr = isBr$6;
- const isText = isText$9;
- const isContentEditableFalse$2 = elm => isContentEditableFalse$b(elm.dom);
- const isContentEditableTrue$1 = elm => isContentEditableTrue$5(elm.dom);
- const isRoot = rootNode => elm => eq(SugarElement.fromDom(rootNode), elm);
- const getClosestScope = (node, rootNode) => closest$4(SugarElement.fromDom(node), elm => isContentEditableTrue$1(elm) || isBlock$2(elm), isRoot(rootNode)).getOr(SugarElement.fromDom(rootNode)).dom;
- const getClosestCef = (node, rootNode) => closest$4(SugarElement.fromDom(node), isContentEditableFalse$2, isRoot(rootNode));
- const findEdgeCaretCandidate = (startNode, scope, forward) => {
- const walker = new DomTreeWalker(startNode, scope);
- const next = forward ? walker.next.bind(walker) : walker.prev.bind(walker);
- let result = startNode;
- for (let current = forward ? startNode : next(); current && !isBr(current); current = next()) {
- if (isCaretCandidate$3(current)) {
- result = current;
- }
- }
- return result;
- };
- const findClosestBlockRange = (startRng, rootNode) => {
- const startPos = CaretPosition.fromRangeStart(startRng);
- const clickNode = startPos.getNode();
- const scope = getClosestScope(clickNode, rootNode);
- const startNode = findEdgeCaretCandidate(clickNode, scope, false);
- const endNode = findEdgeCaretCandidate(clickNode, scope, true);
- const rng = document.createRange();
- getClosestCef(startNode, scope).fold(() => {
- if (isText(startNode)) {
- rng.setStart(startNode, 0);
- } else {
- rng.setStartBefore(startNode);
- }
- }, cef => rng.setStartBefore(cef.dom));
- getClosestCef(endNode, scope).fold(() => {
- if (isText(endNode)) {
- rng.setEnd(endNode, endNode.data.length);
- } else {
- rng.setEndAfter(endNode);
- }
- }, cef => rng.setEndAfter(cef.dom));
- return rng;
- };
- const onTripleClickSelect = editor => {
- const rng = findClosestBlockRange(editor.selection.getRng(), editor.getBody());
- editor.selection.setRng(normalize(rng));
- };
- const setup$5 = editor => {
- editor.on('mousedown', e => {
- if (e.detail >= 3) {
- e.preventDefault();
- onTripleClickSelect(editor);
- }
- });
- };
- var FakeCaretPosition;
- (function (FakeCaretPosition) {
- FakeCaretPosition['Before'] = 'before';
- FakeCaretPosition['After'] = 'after';
- }(FakeCaretPosition || (FakeCaretPosition = {})));
- const distanceToRectLeft = (clientRect, clientX) => Math.abs(clientRect.left - clientX);
- const distanceToRectRight = (clientRect, clientX) => Math.abs(clientRect.right - clientX);
- const isInsideY = (clientY, clientRect) => clientY >= clientRect.top && clientY <= clientRect.bottom;
- const collidesY = (r1, r2) => r1.top < r2.bottom && r1.bottom > r2.top;
- const isOverlapping = (r1, r2) => {
- const overlap = overlapY(r1, r2) / Math.min(r1.height, r2.height);
- return collidesY(r1, r2) && overlap > 0.5;
- };
- const splitRectsPerAxis = (rects, y) => {
- const intersectingRects = filter$6(rects, rect => isInsideY(y, rect));
- return boundingClientRectFromRects(intersectingRects).fold(() => [
- [],
- rects
- ], boundingRect => {
- const {
- pass: horizontal,
- fail: vertical
- } = partition$2(rects, rect => isOverlapping(rect, boundingRect));
- return [
- horizontal,
- vertical
- ];
- });
- };
- const clientInfo = (rect, clientX) => {
- return {
- node: rect.node,
- position: distanceToRectLeft(rect, clientX) < distanceToRectRight(rect, clientX) ? FakeCaretPosition.Before : FakeCaretPosition.After
- };
- };
- const horizontalDistance = (rect, x, _y) => x > rect.left && x < rect.right ? 0 : Math.min(Math.abs(rect.left - x), Math.abs(rect.right - x));
- const closestChildCaretCandidateNodeRect = (children, clientX, clientY) => {
- const caretCandidateRect = rect => {
- if (isCaretCandidate$3(rect.node)) {
- return Optional.some(rect);
- } else if (isElement$6(rect.node)) {
- return closestChildCaretCandidateNodeRect(from(rect.node.childNodes), clientX, clientY);
- } else {
- return Optional.none();
- }
- };
- const getClosestTextNode = (rects, distance) => {
- if (rects.length >= 2) {
- const r1 = caretCandidateRect(rects[0]).getOr(rects[0]);
- const r2 = caretCandidateRect(rects[1]).getOr(rects[1]);
- const deltaDistance = Math.abs(distance(r1, clientX, clientY) - distance(r2, clientX, clientY));
- if (deltaDistance < 2) {
- if (isText$9(r1.node)) {
- return Optional.some(r1);
- } else if (isText$9(r2.node)) {
- return Optional.some(r2);
- }
- }
- }
- return Optional.none();
- };
- const findClosestCaretCandidateNodeRect = (rects, distance) => {
- const sortedRects = sort(rects, (r1, r2) => distance(r1, clientX, clientY) - distance(r2, clientX, clientY));
- return getClosestTextNode(sortedRects, distance).orThunk(() => findMap(sortedRects, caretCandidateRect));
- };
- const [horizontalRects, verticalRects] = splitRectsPerAxis(getClientRects(children), clientY);
- const {
- pass: above,
- fail: below
- } = partition$2(verticalRects, rect => rect.top < clientY);
- return findClosestCaretCandidateNodeRect(horizontalRects, horizontalDistance).orThunk(() => findClosestCaretCandidateNodeRect(below, distanceToRectEdgeFromXY)).orThunk(() => findClosestCaretCandidateNodeRect(above, distanceToRectEdgeFromXY));
- };
- const traverseUp = (rootElm, scope, clientX, clientY) => {
- const helper = (scope, prevScope) => {
- return prevScope.fold(() => closestChildCaretCandidateNodeRect(from(scope.dom.childNodes), clientX, clientY), prevScope => {
- const uncheckedChildren = filter$6(from(scope.dom.childNodes), node => node !== prevScope.dom);
- return closestChildCaretCandidateNodeRect(uncheckedChildren, clientX, clientY);
- }).orThunk(() => {
- const parent = eq(scope, rootElm) ? Optional.none() : parentElement(scope);
- return parent.bind(newScope => helper(newScope, Optional.some(scope)));
- });
- };
- return helper(scope, Optional.none());
- };
- const closestCaretCandidateNodeRect = (root, clientX, clientY) => {
- const rootElm = SugarElement.fromDom(root);
- const ownerDoc = documentOrOwner(rootElm);
- const elementAtPoint = SugarElement.fromPoint(ownerDoc, clientX, clientY).filter(elm => contains(rootElm, elm));
- const element = elementAtPoint.getOr(rootElm);
- return traverseUp(rootElm, element, clientX, clientY);
- };
- const closestFakeCaretCandidate = (root, clientX, clientY) => closestCaretCandidateNodeRect(root, clientX, clientY).filter(rect => isFakeCaretTarget(rect.node)).map(rect => clientInfo(rect, clientX));
- const getAbsolutePosition = elm => {
- const clientRect = elm.getBoundingClientRect();
- const doc = elm.ownerDocument;
- const docElem = doc.documentElement;
- const win = doc.defaultView;
- return {
- top: clientRect.top + win.pageYOffset - docElem.clientTop,
- left: clientRect.left + win.pageXOffset - docElem.clientLeft
- };
- };
- const getBodyPosition = editor => editor.inline ? getAbsolutePosition(editor.getBody()) : {
- left: 0,
- top: 0
- };
- const getScrollPosition = editor => {
- const body = editor.getBody();
- return editor.inline ? {
- left: body.scrollLeft,
- top: body.scrollTop
- } : {
- left: 0,
- top: 0
- };
- };
- const getBodyScroll = editor => {
- const body = editor.getBody(), docElm = editor.getDoc().documentElement;
- const inlineScroll = {
- left: body.scrollLeft,
- top: body.scrollTop
- };
- const iframeScroll = {
- left: body.scrollLeft || docElm.scrollLeft,
- top: body.scrollTop || docElm.scrollTop
- };
- return editor.inline ? inlineScroll : iframeScroll;
- };
- const getMousePosition = (editor, event) => {
- if (event.target.ownerDocument !== editor.getDoc()) {
- const iframePosition = getAbsolutePosition(editor.getContentAreaContainer());
- const scrollPosition = getBodyScroll(editor);
- return {
- left: event.pageX - iframePosition.left + scrollPosition.left,
- top: event.pageY - iframePosition.top + scrollPosition.top
- };
- }
- return {
- left: event.pageX,
- top: event.pageY
- };
- };
- const calculatePosition = (bodyPosition, scrollPosition, mousePosition) => ({
- pageX: mousePosition.left - bodyPosition.left + scrollPosition.left,
- pageY: mousePosition.top - bodyPosition.top + scrollPosition.top
- });
- const calc = (editor, event) => calculatePosition(getBodyPosition(editor), getScrollPosition(editor), getMousePosition(editor, event));
- const isContentEditableFalse$1 = isContentEditableFalse$b, isContentEditableTrue = isContentEditableTrue$5;
- const isDraggable = (rootElm, elm) => isContentEditableFalse$1(elm) && elm !== rootElm;
- const isValidDropTarget = (editor, targetElement, dragElement) => {
- if (targetElement === dragElement || editor.dom.isChildOf(targetElement, dragElement)) {
- return false;
- }
- return !isContentEditableFalse$1(targetElement);
- };
- const cloneElement = elm => {
- const cloneElm = elm.cloneNode(true);
- cloneElm.removeAttribute('data-mce-selected');
- return cloneElm;
- };
- const createGhost = (editor, elm, width, height) => {
- const dom = editor.dom;
- const clonedElm = elm.cloneNode(true);
- dom.setStyles(clonedElm, {
- width,
- height
- });
- dom.setAttrib(clonedElm, 'data-mce-selected', null);
- const ghostElm = dom.create('div', {
- 'class': 'mce-drag-container',
- 'data-mce-bogus': 'all',
- 'unselectable': 'on',
- 'contenteditable': 'false'
- });
- dom.setStyles(ghostElm, {
- position: 'absolute',
- opacity: 0.5,
- overflow: 'hidden',
- border: 0,
- padding: 0,
- margin: 0,
- width,
- height
- });
- dom.setStyles(clonedElm, {
- margin: 0,
- boxSizing: 'border-box'
- });
- ghostElm.appendChild(clonedElm);
- return ghostElm;
- };
- const appendGhostToBody = (ghostElm, bodyElm) => {
- if (ghostElm.parentNode !== bodyElm) {
- bodyElm.appendChild(ghostElm);
- }
- };
- const moveGhost = (ghostElm, position, width, height, maxX, maxY) => {
- let overflowX = 0, overflowY = 0;
- ghostElm.style.left = position.pageX + 'px';
- ghostElm.style.top = position.pageY + 'px';
- if (position.pageX + width > maxX) {
- overflowX = position.pageX + width - maxX;
- }
- if (position.pageY + height > maxY) {
- overflowY = position.pageY + height - maxY;
- }
- ghostElm.style.width = width - overflowX + 'px';
- ghostElm.style.height = height - overflowY + 'px';
- };
- const removeElement = elm => {
- if (elm && elm.parentNode) {
- elm.parentNode.removeChild(elm);
- }
- };
- const isLeftMouseButtonPressed = e => e.button === 0;
- const applyRelPos = (state, position) => ({
- pageX: position.pageX - state.relX,
- pageY: position.pageY + 5
- });
- const start = (state, editor) => e => {
- if (isLeftMouseButtonPressed(e)) {
- const ceElm = find$2(editor.dom.getParents(e.target), or(isContentEditableFalse$1, isContentEditableTrue)).getOr(null);
- if (isDraggable(editor.getBody(), ceElm)) {
- const elmPos = editor.dom.getPos(ceElm);
- const bodyElm = editor.getBody();
- const docElm = editor.getDoc().documentElement;
- state.set({
- element: ceElm,
- dragging: false,
- screenX: e.screenX,
- screenY: e.screenY,
- maxX: (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2,
- maxY: (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2,
- relX: e.pageX - elmPos.x,
- relY: e.pageY - elmPos.y,
- width: ceElm.offsetWidth,
- height: ceElm.offsetHeight,
- ghost: createGhost(editor, ceElm, ceElm.offsetWidth, ceElm.offsetHeight)
- });
- }
- }
- };
- const move = (state, editor) => {
- const throttledPlaceCaretAt = first$1((clientX, clientY) => {
- editor._selectionOverrides.hideFakeCaret();
- editor.selection.placeCaretAt(clientX, clientY);
- }, 0);
- editor.on('remove', throttledPlaceCaretAt.cancel);
- return e => state.on(state => {
- const movement = Math.max(Math.abs(e.screenX - state.screenX), Math.abs(e.screenY - state.screenY));
- if (!state.dragging && movement > 10) {
- const args = editor.dispatch('dragstart', { target: state.element });
- if (args.isDefaultPrevented()) {
- return;
- }
- state.dragging = true;
- editor.focus();
- }
- if (state.dragging) {
- const targetPos = applyRelPos(state, calc(editor, e));
- appendGhostToBody(state.ghost, editor.getBody());
- moveGhost(state.ghost, targetPos, state.width, state.height, state.maxX, state.maxY);
- throttledPlaceCaretAt.throttle(e.clientX, e.clientY);
- }
- });
- };
- const getRawTarget = selection => {
- const rng = selection.getSel().getRangeAt(0);
- const startContainer = rng.startContainer;
- return startContainer.nodeType === 3 ? startContainer.parentNode : startContainer;
- };
- const drop = (state, editor) => e => {
- state.on(state => {
- if (state.dragging) {
- if (isValidDropTarget(editor, getRawTarget(editor.selection), state.element)) {
- const targetClone = cloneElement(state.element);
- const args = editor.dispatch('drop', {
- clientX: e.clientX,
- clientY: e.clientY
- });
- if (!args.isDefaultPrevented()) {
- editor.undoManager.transact(() => {
- removeElement(state.element);
- editor.insertContent(editor.dom.getOuterHTML(targetClone));
- editor._selectionOverrides.hideFakeCaret();
- });
- }
- }
- editor.dispatch('dragend');
- }
- });
- removeDragState(state);
- };
- const stop = (state, editor) => () => {
- state.on(state => {
- if (state.dragging) {
- editor.dispatch('dragend');
- }
- });
- removeDragState(state);
- };
- const removeDragState = state => {
- state.on(state => {
- removeElement(state.ghost);
- });
- state.clear();
- };
- const bindFakeDragEvents = editor => {
- const state = value$2();
- const pageDom = DOMUtils.DOM;
- const rootDocument = document;
- const dragStartHandler = start(state, editor);
- const dragHandler = move(state, editor);
- const dropHandler = drop(state, editor);
- const dragEndHandler = stop(state, editor);
- editor.on('mousedown', dragStartHandler);
- editor.on('mousemove', dragHandler);
- editor.on('mouseup', dropHandler);
- pageDom.bind(rootDocument, 'mousemove', dragHandler);
- pageDom.bind(rootDocument, 'mouseup', dragEndHandler);
- editor.on('remove', () => {
- pageDom.unbind(rootDocument, 'mousemove', dragHandler);
- pageDom.unbind(rootDocument, 'mouseup', dragEndHandler);
- });
- editor.on('keydown', e => {
- if (e.keyCode === VK.ESC) {
- dragEndHandler();
- }
- });
- };
- const blockUnsupportedFileDrop = editor => {
- const preventFileDrop = e => {
- if (!e.isDefaultPrevented()) {
- const dataTransfer = e.dataTransfer;
- if (dataTransfer && (contains$2(dataTransfer.types, 'Files') || dataTransfer.files.length > 0)) {
- e.preventDefault();
- if (e.type === 'drop') {
- displayError(editor, 'Dropped file type is not supported');
- }
- }
- }
- };
- const preventFileDropIfUIElement = e => {
- if (isUIElement(editor, e.target)) {
- preventFileDrop(e);
- }
- };
- const setup = () => {
- const pageDom = DOMUtils.DOM;
- const dom = editor.dom;
- const doc = document;
- const editorRoot = editor.inline ? editor.getBody() : editor.getDoc();
- const eventNames = [
- 'drop',
- 'dragover'
- ];
- each$f(eventNames, name => {
- pageDom.bind(doc, name, preventFileDropIfUIElement);
- dom.bind(editorRoot, name, preventFileDrop);
- });
- editor.on('remove', () => {
- each$f(eventNames, name => {
- pageDom.unbind(doc, name, preventFileDropIfUIElement);
- dom.unbind(editorRoot, name, preventFileDrop);
- });
- });
- };
- editor.on('init', () => {
- Delay.setEditorTimeout(editor, setup, 0);
- });
- };
- const init$2 = editor => {
- bindFakeDragEvents(editor);
- if (shouldBlockUnsupportedDrop(editor)) {
- blockUnsupportedFileDrop(editor);
- }
- };
- const setup$4 = editor => {
- const renderFocusCaret = first$1(() => {
- if (!editor.removed && editor.getBody().contains(document.activeElement)) {
- const rng = editor.selection.getRng();
- if (rng.collapsed) {
- const caretRange = renderRangeCaret(editor, rng, false);
- editor.selection.setRng(caretRange);
- }
- }
- }, 0);
- editor.on('focus', () => {
- renderFocusCaret.throttle();
- });
- editor.on('blur', () => {
- renderFocusCaret.cancel();
- });
- };
- const setup$3 = editor => {
- editor.on('init', () => {
- editor.on('focusin', e => {
- const target = e.target;
- if (isMedia$2(target)) {
- const ceRoot = getContentEditableRoot$1(editor.getBody(), target);
- const node = isContentEditableFalse$b(ceRoot) ? ceRoot : target;
- if (editor.selection.getNode() !== node) {
- selectNode(editor, node).each(rng => editor.selection.setRng(rng));
- }
- }
- });
- });
- };
- const isContentEditableFalse = isContentEditableFalse$b;
- const getContentEditableRoot = (editor, node) => getContentEditableRoot$1(editor.getBody(), node);
- const SelectionOverrides = editor => {
- const selection = editor.selection, dom = editor.dom;
- const isBlock = dom.isBlock;
- const rootNode = editor.getBody();
- const fakeCaret = FakeCaret(editor, rootNode, isBlock, () => hasFocus(editor));
- const realSelectionId = 'sel-' + dom.uniqueId();
- const elementSelectionAttr = 'data-mce-selected';
- let selectedElement;
- const isFakeSelectionElement = node => dom.hasClass(node, 'mce-offscreen-selection');
- const isFakeSelectionTargetElement = node => node !== rootNode && (isContentEditableFalse(node) || isMedia$2(node)) && dom.isChildOf(node, rootNode);
- const setRange = range => {
- if (range) {
- selection.setRng(range);
- }
- };
- const showCaret = (direction, node, before, scrollIntoView = true) => {
- const e = editor.dispatch('ShowCaret', {
- target: node,
- direction,
- before
- });
- if (e.isDefaultPrevented()) {
- return null;
- }
- if (scrollIntoView) {
- selection.scrollIntoView(node, direction === -1);
- }
- return fakeCaret.show(before, node);
- };
- const showBlockCaretContainer = blockCaretContainer => {
- if (blockCaretContainer.hasAttribute('data-mce-caret')) {
- showCaretContainerBlock(blockCaretContainer);
- selection.scrollIntoView(blockCaretContainer);
- }
- };
- const registerEvents = () => {
- editor.on('click', e => {
- const contentEditableRoot = getContentEditableRoot(editor, e.target);
- if (contentEditableRoot) {
- if (isContentEditableFalse(contentEditableRoot)) {
- e.preventDefault();
- editor.focus();
- }
- }
- });
- editor.on('blur NewBlock', removeElementSelection);
- editor.on('ResizeWindow FullscreenStateChanged', fakeCaret.reposition);
- editor.on('tap', e => {
- const targetElm = e.target;
- const contentEditableRoot = getContentEditableRoot(editor, targetElm);
- if (isContentEditableFalse(contentEditableRoot)) {
- e.preventDefault();
- selectNode(editor, contentEditableRoot).each(setElementSelection);
- } else if (isFakeSelectionTargetElement(targetElm)) {
- selectNode(editor, targetElm).each(setElementSelection);
- }
- }, true);
- editor.on('mousedown', e => {
- const targetElm = e.target;
- if (targetElm !== rootNode && targetElm.nodeName !== 'HTML' && !dom.isChildOf(targetElm, rootNode)) {
- return;
- }
- if (isXYInContentArea(editor, e.clientX, e.clientY) === false) {
- return;
- }
- removeElementSelection();
- hideFakeCaret();
- const closestContentEditable = getContentEditableRoot(editor, targetElm);
- if (isContentEditableFalse(closestContentEditable)) {
- e.preventDefault();
- selectNode(editor, closestContentEditable).each(setElementSelection);
- } else {
- closestFakeCaretCandidate(rootNode, e.clientX, e.clientY).each(caretInfo => {
- e.preventDefault();
- const range = showCaret(1, caretInfo.node, caretInfo.position === FakeCaretPosition.Before, false);
- setRange(range);
- if (isElement$6(closestContentEditable)) {
- closestContentEditable.focus();
- } else {
- editor.getBody().focus();
- }
- });
- }
- });
- editor.on('keypress', e => {
- if (VK.modifierPressed(e)) {
- return;
- }
- if (isContentEditableFalse(selection.getNode())) {
- e.preventDefault();
- }
- });
- editor.on('GetSelectionRange', e => {
- let rng = e.range;
- if (selectedElement) {
- if (!selectedElement.parentNode) {
- selectedElement = null;
- return;
- }
- rng = rng.cloneRange();
- rng.selectNode(selectedElement);
- e.range = rng;
- }
- });
- editor.on('SetSelectionRange', e => {
- e.range = normalizeVoidElementSelection(e.range);
- const rng = setElementSelection(e.range, e.forward);
- if (rng) {
- e.range = rng;
- }
- });
- const isPasteBin = node => node.id === 'mcepastebin';
- editor.on('AfterSetSelectionRange', e => {
- const rng = e.range;
- const parentNode = rng.startContainer.parentNode;
- if (!isRangeInCaretContainer(rng) && !isPasteBin(parentNode)) {
- hideFakeCaret();
- }
- if (!isFakeSelectionElement(parentNode)) {
- removeElementSelection();
- }
- });
- init$2(editor);
- setup$4(editor);
- setup$3(editor);
- };
- const isWithinCaretContainer = node => isCaretContainer$2(node) || startsWithCaretContainer$1(node) || endsWithCaretContainer$1(node);
- const isRangeInCaretContainer = rng => isWithinCaretContainer(rng.startContainer) || isWithinCaretContainer(rng.endContainer);
- const normalizeVoidElementSelection = rng => {
- const voidElements = editor.schema.getVoidElements();
- const newRng = dom.createRng();
- const startContainer = rng.startContainer;
- const startOffset = rng.startOffset;
- const endContainer = rng.endContainer;
- const endOffset = rng.endOffset;
- if (has$2(voidElements, startContainer.nodeName.toLowerCase())) {
- if (startOffset === 0) {
- newRng.setStartBefore(startContainer);
- } else {
- newRng.setStartAfter(startContainer);
- }
- } else {
- newRng.setStart(startContainer, startOffset);
- }
- if (has$2(voidElements, endContainer.nodeName.toLowerCase())) {
- if (endOffset === 0) {
- newRng.setEndBefore(endContainer);
- } else {
- newRng.setEndAfter(endContainer);
- }
- } else {
- newRng.setEnd(endContainer, endOffset);
- }
- return newRng;
- };
- const setupOffscreenSelection = (node, targetClone) => {
- const body = SugarElement.fromDom(editor.getBody());
- const doc = editor.getDoc();
- const realSelectionContainer = descendant(body, '#' + realSelectionId).getOrThunk(() => {
- const newContainer = SugarElement.fromHtml('<div data-mce-bogus="all" class="mce-offscreen-selection"></div>', doc);
- set$2(newContainer, 'id', realSelectionId);
- append$1(body, newContainer);
- return newContainer;
- });
- const newRange = dom.createRng();
- empty(realSelectionContainer);
- append(realSelectionContainer, [
- SugarElement.fromText(nbsp, doc),
- SugarElement.fromDom(targetClone),
- SugarElement.fromText(nbsp, doc)
- ]);
- newRange.setStart(realSelectionContainer.dom.firstChild, 1);
- newRange.setEnd(realSelectionContainer.dom.lastChild, 0);
- setAll(realSelectionContainer, { top: dom.getPos(node, editor.getBody()).y + 'px' });
- focus$1(realSelectionContainer);
- const sel = selection.getSel();
- sel.removeAllRanges();
- sel.addRange(newRange);
- return newRange;
- };
- const selectElement = elm => {
- const targetClone = elm.cloneNode(true);
- const e = editor.dispatch('ObjectSelected', {
- target: elm,
- targetClone
- });
- if (e.isDefaultPrevented()) {
- return null;
- }
- const range = setupOffscreenSelection(elm, e.targetClone);
- const nodeElm = SugarElement.fromDom(elm);
- each$f(descendants(SugarElement.fromDom(editor.getBody()), `*[${ elementSelectionAttr }]`), elm => {
- if (!eq(nodeElm, elm)) {
- remove$b(elm, elementSelectionAttr);
- }
- });
- if (!dom.getAttrib(elm, elementSelectionAttr)) {
- elm.setAttribute(elementSelectionAttr, '1');
- }
- selectedElement = elm;
- hideFakeCaret();
- return range;
- };
- const setElementSelection = (range, forward) => {
- if (!range) {
- return null;
- }
- if (range.collapsed) {
- if (!isRangeInCaretContainer(range)) {
- const dir = forward ? 1 : -1;
- const caretPosition = getNormalizedRangeEndPoint(dir, rootNode, range);
- const beforeNode = caretPosition.getNode(!forward);
- if (isFakeCaretTarget(beforeNode)) {
- return showCaret(dir, beforeNode, forward ? !caretPosition.isAtEnd() : false, false);
- }
- const afterNode = caretPosition.getNode(forward);
- if (isFakeCaretTarget(afterNode)) {
- return showCaret(dir, afterNode, forward ? false : !caretPosition.isAtEnd(), false);
- }
- }
- return null;
- }
- let startContainer = range.startContainer;
- let startOffset = range.startOffset;
- const endOffset = range.endOffset;
- if (startContainer.nodeType === 3 && startOffset === 0 && isContentEditableFalse(startContainer.parentNode)) {
- startContainer = startContainer.parentNode;
- startOffset = dom.nodeIndex(startContainer);
- startContainer = startContainer.parentNode;
- }
- if (startContainer.nodeType !== 1) {
- return null;
- }
- if (endOffset === startOffset + 1 && startContainer === range.endContainer) {
- const node = startContainer.childNodes[startOffset];
- if (isFakeSelectionTargetElement(node)) {
- return selectElement(node);
- }
- }
- return null;
- };
- const removeElementSelection = () => {
- if (selectedElement) {
- selectedElement.removeAttribute(elementSelectionAttr);
- }
- descendant(SugarElement.fromDom(editor.getBody()), '#' + realSelectionId).each(remove$6);
- selectedElement = null;
- };
- const destroy = () => {
- fakeCaret.destroy();
- selectedElement = null;
- };
- const hideFakeCaret = () => {
- fakeCaret.hide();
- };
- if (!isRtc(editor)) {
- registerEvents();
- }
- return {
- showCaret,
- showBlockCaretContainer,
- hideFakeCaret,
- destroy
- };
- };
- const generatePath = (root, node, offset) => {
- if (isText$9(node) && (offset < 0 || offset > node.data.length)) {
- return [];
- }
- const p = [offset];
- let current = node;
- while (current !== root && current.parentNode) {
- const parent = current.parentNode;
- for (let i = 0; i < parent.childNodes.length; i++) {
- if (parent.childNodes[i] === current) {
- p.push(i);
- break;
- }
- }
- current = parent;
- }
- return current === root ? p.reverse() : [];
- };
- const generatePathRange = (root, startNode, startOffset, endNode, endOffset) => {
- const start = generatePath(root, startNode, startOffset);
- const end = generatePath(root, endNode, endOffset);
- return {
- start,
- end
- };
- };
- const resolvePath = (root, path) => {
- const nodePath = path.slice();
- const offset = nodePath.pop();
- const resolvedNode = foldl(nodePath, (optNode, index) => optNode.bind(node => Optional.from(node.childNodes[index])), Optional.some(root));
- return resolvedNode.bind(node => {
- if (isText$9(node) && (offset < 0 || offset > node.data.length)) {
- return Optional.none();
- } else {
- return Optional.some({
- node,
- offset
- });
- }
- });
- };
- const resolvePathRange = (root, range) => resolvePath(root, range.start).bind(({
- node: startNode,
- offset: startOffset
- }) => resolvePath(root, range.end).map(({
- node: endNode,
- offset: endOffset
- }) => {
- const rng = document.createRange();
- rng.setStart(startNode, startOffset);
- rng.setEnd(endNode, endOffset);
- return rng;
- }));
- const generatePathRangeFromRange = (root, range) => generatePathRange(root, range.startContainer, range.startOffset, range.endContainer, range.endOffset);
- const cleanEmptyNodes = (dom, node, isRoot) => {
- if (node && dom.isEmpty(node) && !isRoot(node)) {
- const parent = node.parentNode;
- dom.remove(node);
- cleanEmptyNodes(dom, parent, isRoot);
- }
- };
- const deleteRng = (dom, rng, isRoot, clean = true) => {
- const startParent = rng.startContainer.parentNode;
- const endParent = rng.endContainer.parentNode;
- rng.deleteContents();
- if (clean && !isRoot(rng.startContainer)) {
- if (isText$9(rng.startContainer) && rng.startContainer.data.length === 0) {
- dom.remove(rng.startContainer);
- }
- if (isText$9(rng.endContainer) && rng.endContainer.data.length === 0) {
- dom.remove(rng.endContainer);
- }
- cleanEmptyNodes(dom, startParent, isRoot);
- if (startParent !== endParent) {
- cleanEmptyNodes(dom, endParent, isRoot);
- }
- }
- };
- const getParentBlock = (editor, rng) => Optional.from(editor.dom.getParent(rng.startContainer, editor.dom.isBlock));
- const stripPattern = (dom, block, pattern) => {
- const firstTextNode = textAfter(block, 0, block);
- firstTextNode.each(spot => {
- const node = spot.container;
- scanRight(node, pattern.start.length, block).each(end => {
- const rng = dom.createRng();
- rng.setStart(node, 0);
- rng.setEnd(end.container, end.offset);
- deleteRng(dom, rng, e => e === block);
- });
- });
- };
- const applyPattern$1 = (editor, match) => {
- const dom = editor.dom;
- const pattern = match.pattern;
- const rng = resolvePathRange(dom.getRoot(), match.range).getOrDie('Unable to resolve path range');
- const isBlockFormatName = (name, formatter) => {
- const formatSet = formatter.get(name);
- return isArray$1(formatSet) && head(formatSet).exists(format => has$2(format, 'block'));
- };
- getParentBlock(editor, rng).each(block => {
- if (pattern.type === 'block-format') {
- if (isBlockFormatName(pattern.format, editor.formatter)) {
- editor.undoManager.transact(() => {
- stripPattern(editor.dom, block, pattern);
- editor.formatter.apply(pattern.format);
- });
- }
- } else if (pattern.type === 'block-command') {
- editor.undoManager.transact(() => {
- stripPattern(editor.dom, block, pattern);
- editor.execCommand(pattern.cmd, false, pattern.value);
- });
- }
- });
- return true;
- };
- const findPattern$1 = (patterns, text) => {
- const nuText = text.replace(nbsp, ' ');
- return find$2(patterns, pattern => text.indexOf(pattern.start) === 0 || nuText.indexOf(pattern.start) === 0);
- };
- const findPatterns$1 = (editor, patterns) => {
- const dom = editor.dom;
- const rng = editor.selection.getRng();
- return getParentBlock(editor, rng).filter(block => {
- const forcedRootBlock = getForcedRootBlock(editor);
- const matchesForcedRootBlock = dom.is(block, forcedRootBlock);
- return block !== null && matchesForcedRootBlock;
- }).bind(block => {
- const blockText = block.textContent;
- const matchedPattern = findPattern$1(patterns, blockText);
- return matchedPattern.map(pattern => {
- if (Tools.trim(blockText).length === pattern.start.length) {
- return [];
- }
- return [{
- pattern,
- range: generatePathRange(dom.getRoot(), block, 0, block, 0)
- }];
- });
- }).getOr([]);
- };
- const applyMatches$1 = (editor, matches) => {
- if (matches.length === 0) {
- return;
- }
- const bookmark = editor.selection.getBookmark();
- each$f(matches, match => applyPattern$1(editor, match));
- editor.selection.moveToBookmark(bookmark);
- };
- const newMarker = (dom, id) => dom.create('span', {
- 'data-mce-type': 'bookmark',
- id
- });
- const rangeFromMarker = (dom, marker) => {
- const rng = dom.createRng();
- rng.setStartAfter(marker.start);
- rng.setEndBefore(marker.end);
- return rng;
- };
- const createMarker = (dom, markerPrefix, pathRange) => {
- const rng = resolvePathRange(dom.getRoot(), pathRange).getOrDie('Unable to resolve path range');
- const startNode = rng.startContainer;
- const endNode = rng.endContainer;
- const textEnd = rng.endOffset === 0 ? endNode : endNode.splitText(rng.endOffset);
- const textStart = rng.startOffset === 0 ? startNode : startNode.splitText(rng.startOffset);
- return {
- prefix: markerPrefix,
- end: textEnd.parentNode.insertBefore(newMarker(dom, markerPrefix + '-end'), textEnd),
- start: textStart.parentNode.insertBefore(newMarker(dom, markerPrefix + '-start'), textStart)
- };
- };
- const removeMarker = (dom, marker, isRoot) => {
- cleanEmptyNodes(dom, dom.get(marker.prefix + '-end'), isRoot);
- cleanEmptyNodes(dom, dom.get(marker.prefix + '-start'), isRoot);
- };
- const isReplacementPattern = pattern => pattern.start.length === 0;
- const matchesPattern = patternContent => (element, offset) => {
- const text = element.data;
- const searchText = text.substring(0, offset);
- const startEndIndex = searchText.lastIndexOf(patternContent.charAt(patternContent.length - 1));
- const startIndex = searchText.lastIndexOf(patternContent);
- if (startIndex !== -1) {
- return startIndex + patternContent.length;
- } else if (startEndIndex !== -1) {
- return startEndIndex + 1;
- } else {
- return -1;
- }
- };
- const findPatternStartFromSpot = (dom, pattern, block, spot) => {
- const startPattern = pattern.start;
- const startSpot = repeatLeft(dom, spot.container, spot.offset, matchesPattern(startPattern), block);
- return startSpot.bind(spot => {
- if (spot.offset >= startPattern.length) {
- const rng = dom.createRng();
- rng.setStart(spot.container, spot.offset - startPattern.length);
- rng.setEnd(spot.container, spot.offset);
- return Optional.some(rng);
- } else {
- const offset = spot.offset - startPattern.length;
- return scanLeft(spot.container, offset, block).map(nextSpot => {
- const rng = dom.createRng();
- rng.setStart(nextSpot.container, nextSpot.offset);
- rng.setEnd(spot.container, spot.offset);
- return rng;
- }).filter(rng => rng.toString() === startPattern).orThunk(() => findPatternStartFromSpot(dom, pattern, block, point(spot.container, 0)));
- }
- });
- };
- const findPatternStart = (dom, pattern, node, offset, block, requireGap = false) => {
- if (pattern.start.length === 0 && !requireGap) {
- const rng = dom.createRng();
- rng.setStart(node, offset);
- rng.setEnd(node, offset);
- return Optional.some(rng);
- }
- return textBefore(node, offset, block).bind(spot => {
- const start = findPatternStartFromSpot(dom, pattern, block, spot);
- return start.bind(startRange => {
- if (requireGap) {
- if (startRange.endContainer === spot.container && startRange.endOffset === spot.offset) {
- return Optional.none();
- } else if (spot.offset === 0 && startRange.endContainer.textContent.length === startRange.endOffset) {
- return Optional.none();
- }
- }
- return Optional.some(startRange);
- });
- });
- };
- const findPattern = (editor, block, details) => {
- const dom = editor.dom;
- const root = dom.getRoot();
- const pattern = details.pattern;
- const endNode = details.position.container;
- const endOffset = details.position.offset;
- return scanLeft(endNode, endOffset - details.pattern.end.length, block).bind(spot => {
- const endPathRng = generatePathRange(root, spot.container, spot.offset, endNode, endOffset);
- if (isReplacementPattern(pattern)) {
- return Optional.some({
- matches: [{
- pattern,
- startRng: endPathRng,
- endRng: endPathRng
- }],
- position: spot
- });
- } else {
- const resultsOpt = findPatternsRec(editor, details.remainingPatterns, spot.container, spot.offset, block);
- const results = resultsOpt.getOr({
- matches: [],
- position: spot
- });
- const pos = results.position;
- const start = findPatternStart(dom, pattern, pos.container, pos.offset, block, resultsOpt.isNone());
- return start.map(startRng => {
- const startPathRng = generatePathRangeFromRange(root, startRng);
- return {
- matches: results.matches.concat([{
- pattern,
- startRng: startPathRng,
- endRng: endPathRng
- }]),
- position: point(startRng.startContainer, startRng.startOffset)
- };
- });
- }
- });
- };
- const findPatternsRec = (editor, patterns, node, offset, block) => {
- const dom = editor.dom;
- return textBefore(node, offset, dom.getRoot()).bind(endSpot => {
- const rng = dom.createRng();
- rng.setStart(block, 0);
- rng.setEnd(node, offset);
- const text = rng.toString();
- for (let i = 0; i < patterns.length; i++) {
- const pattern = patterns[i];
- if (!endsWith(text, pattern.end)) {
- continue;
- }
- const patternsWithoutCurrent = patterns.slice();
- patternsWithoutCurrent.splice(i, 1);
- const result = findPattern(editor, block, {
- pattern,
- remainingPatterns: patternsWithoutCurrent,
- position: endSpot
- });
- if (result.isSome()) {
- return result;
- }
- }
- return Optional.none();
- });
- };
- const applyPattern = (editor, pattern, patternRange) => {
- editor.selection.setRng(patternRange);
- if (pattern.type === 'inline-format') {
- each$f(pattern.format, format => {
- editor.formatter.apply(format);
- });
- } else {
- editor.execCommand(pattern.cmd, false, pattern.value);
- }
- };
- const applyReplacementPattern = (editor, pattern, marker, isRoot) => {
- const markerRange = rangeFromMarker(editor.dom, marker);
- deleteRng(editor.dom, markerRange, isRoot);
- applyPattern(editor, pattern, markerRange);
- };
- const applyPatternWithContent = (editor, pattern, startMarker, endMarker, isRoot) => {
- const dom = editor.dom;
- const markerEndRange = rangeFromMarker(dom, endMarker);
- const markerStartRange = rangeFromMarker(dom, startMarker);
- deleteRng(dom, markerStartRange, isRoot);
- deleteRng(dom, markerEndRange, isRoot);
- const patternMarker = {
- prefix: startMarker.prefix,
- start: startMarker.end,
- end: endMarker.start
- };
- const patternRange = rangeFromMarker(dom, patternMarker);
- applyPattern(editor, pattern, patternRange);
- };
- const addMarkers = (dom, matches) => {
- const markerPrefix = generate$1('mce_textpattern');
- const matchesWithEnds = foldr(matches, (acc, match) => {
- const endMarker = createMarker(dom, markerPrefix + `_end${ acc.length }`, match.endRng);
- return acc.concat([{
- ...match,
- endMarker
- }]);
- }, []);
- return foldr(matchesWithEnds, (acc, match) => {
- const idx = matchesWithEnds.length - acc.length - 1;
- const startMarker = isReplacementPattern(match.pattern) ? match.endMarker : createMarker(dom, markerPrefix + `_start${ idx }`, match.startRng);
- return acc.concat([{
- ...match,
- startMarker
- }]);
- }, []);
- };
- const findPatterns = (editor, patterns, space) => {
- const rng = editor.selection.getRng();
- if (rng.collapsed === false) {
- return [];
- }
- return getParentBlock(editor, rng).bind(block => {
- const offset = Math.max(0, rng.startOffset - (space ? 1 : 0));
- return findPatternsRec(editor, patterns, rng.startContainer, offset, block);
- }).fold(() => [], result => result.matches);
- };
- const applyMatches = (editor, matches) => {
- if (matches.length === 0) {
- return;
- }
- const dom = editor.dom;
- const bookmark = editor.selection.getBookmark();
- const matchesWithMarkers = addMarkers(dom, matches);
- each$f(matchesWithMarkers, match => {
- const block = dom.getParent(match.startMarker.start, dom.isBlock);
- const isRoot = node => node === block;
- if (isReplacementPattern(match.pattern)) {
- applyReplacementPattern(editor, match.pattern, match.endMarker, isRoot);
- } else {
- applyPatternWithContent(editor, match.pattern, match.startMarker, match.endMarker, isRoot);
- }
- removeMarker(dom, match.endMarker, isRoot);
- removeMarker(dom, match.startMarker, isRoot);
- });
- editor.selection.moveToBookmark(bookmark);
- };
- const hasPatterns = patternSet => patternSet.inlinePatterns.length > 0 || patternSet.blockPatterns.length > 0;
- const handleEnter = (editor, patternSet) => {
- if (!editor.selection.isCollapsed() || !hasPatterns(patternSet)) {
- return false;
- }
- const inlineMatches = findPatterns(editor, patternSet.inlinePatterns, false);
- const blockMatches = findPatterns$1(editor, patternSet.blockPatterns);
- if (blockMatches.length > 0 || inlineMatches.length > 0) {
- editor.undoManager.add();
- editor.undoManager.extra(() => {
- editor.execCommand('mceInsertNewLine');
- }, () => {
- editor.insertContent(zeroWidth);
- applyMatches(editor, inlineMatches);
- applyMatches$1(editor, blockMatches);
- const range = editor.selection.getRng();
- const spot = textBefore(range.startContainer, range.startOffset, editor.dom.getRoot());
- editor.execCommand('mceInsertNewLine');
- spot.each(s => {
- const node = s.container;
- if (node.data.charAt(s.offset - 1) === zeroWidth) {
- node.deleteData(s.offset - 1, 1);
- cleanEmptyNodes(editor.dom, node.parentNode, e => e === editor.dom.getRoot());
- }
- });
- });
- return true;
- }
- return false;
- };
- const handleInlineKey = (editor, inlinePatterns) => {
- if (inlinePatterns.length > 0) {
- const inlineMatches = findPatterns(editor, inlinePatterns, true);
- if (inlineMatches.length > 0) {
- editor.undoManager.transact(() => {
- applyMatches(editor, inlineMatches);
- });
- }
- }
- };
- const checkKeyEvent = (codes, event, predicate) => {
- for (let i = 0; i < codes.length; i++) {
- if (predicate(codes[i], event)) {
- return true;
- }
- }
- return false;
- };
- const checkKeyCode = (codes, event) => checkKeyEvent(codes, event, (code, event) => {
- return code === event.keyCode && VK.modifierPressed(event) === false;
- });
- const checkCharCode = (chars, event) => checkKeyEvent(chars, event, (chr, event) => {
- return chr.charCodeAt(0) === event.charCode;
- });
- const setup$2 = editor => {
- const charCodes = [
- ',',
- '.',
- ';',
- ':',
- '!',
- '?'
- ];
- const keyCodes = [32];
- const getPatternSet = () => createPatternSet(getTextPatterns(editor));
- const getInlinePatterns$1 = () => getInlinePatterns(getTextPatterns(editor));
- editor.on('keydown', e => {
- if (e.keyCode === 13 && !VK.modifierPressed(e)) {
- if (handleEnter(editor, getPatternSet())) {
- e.preventDefault();
- }
- }
- }, true);
- editor.on('keyup', e => {
- if (checkKeyCode(keyCodes, e)) {
- handleInlineKey(editor, getInlinePatterns$1());
- }
- });
- editor.on('keypress', e => {
- if (checkCharCode(charCodes, e)) {
- Delay.setEditorTimeout(editor, () => {
- handleInlineKey(editor, getInlinePatterns$1());
- });
- }
- });
- };
- const setup$1 = editor => {
- setup$2(editor);
- };
- const Quirks = editor => {
- const each = Tools.each;
- const BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection, parser = editor.parser;
- const browser = Env.browser;
- const isGecko = browser.isFirefox();
- const isWebKit = browser.isChromium() || browser.isSafari();
- const isiOS = Env.deviceType.isiPhone() || Env.deviceType.isiPad();
- const isMac = Env.os.isMacOS() || Env.os.isiOS();
- const setEditorCommandState = (cmd, state) => {
- try {
- editor.getDoc().execCommand(cmd, false, state);
- } catch (ex) {
- }
- };
- const isDefaultPrevented = e => {
- return e.isDefaultPrevented();
- };
- const emptyEditorWhenDeleting = () => {
- const serializeRng = rng => {
- const body = dom.create('body');
- const contents = rng.cloneContents();
- body.appendChild(contents);
- return selection.serializer.serialize(body, { format: 'html' });
- };
- const allContentsSelected = rng => {
- const selection = serializeRng(rng);
- const allRng = dom.createRng();
- allRng.selectNode(editor.getBody());
- const allSelection = serializeRng(allRng);
- return selection === allSelection;
- };
- editor.on('keydown', e => {
- const keyCode = e.keyCode;
- let isCollapsed, body;
- if (!isDefaultPrevented(e) && (keyCode === DELETE || keyCode === BACKSPACE)) {
- isCollapsed = editor.selection.isCollapsed();
- body = editor.getBody();
- if (isCollapsed && !dom.isEmpty(body)) {
- return;
- }
- if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
- return;
- }
- e.preventDefault();
- editor.setContent('');
- if (body.firstChild && dom.isBlock(body.firstChild)) {
- editor.selection.setCursorLocation(body.firstChild, 0);
- } else {
- editor.selection.setCursorLocation(body, 0);
- }
- editor.nodeChanged();
- }
- });
- };
- const selectAll = () => {
- editor.shortcuts.add('meta+a', null, 'SelectAll');
- };
- const documentElementEditingFocus = () => {
- if (!editor.inline) {
- dom.bind(editor.getDoc(), 'mousedown mouseup', e => {
- let rng;
- if (e.target === editor.getDoc().documentElement) {
- rng = selection.getRng();
- editor.getBody().focus();
- if (e.type === 'mousedown') {
- if (isCaretContainer$2(rng.startContainer)) {
- return;
- }
- selection.placeCaretAt(e.clientX, e.clientY);
- } else {
- selection.setRng(rng);
- }
- }
- });
- }
- };
- const removeHrOnBackspace = () => {
- editor.on('keydown', e => {
- if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
- if (!editor.getBody().getElementsByTagName('hr').length) {
- return;
- }
- if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
- const node = selection.getNode();
- const previousSibling = node.previousSibling;
- if (node.nodeName === 'HR') {
- dom.remove(node);
- e.preventDefault();
- return;
- }
- if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'hr') {
- dom.remove(previousSibling);
- e.preventDefault();
- }
- }
- }
- });
- };
- const focusBody = () => {
- if (!Range.prototype.getClientRects) {
- editor.on('mousedown', e => {
- if (!isDefaultPrevented(e) && e.target.nodeName === 'HTML') {
- const body = editor.getBody();
- body.blur();
- Delay.setEditorTimeout(editor, () => {
- body.focus();
- });
- }
- });
- }
- };
- const selectControlElements = () => {
- const visualAidsAnchorClass = getVisualAidsAnchorClass(editor);
- editor.on('click', e => {
- const target = e.target;
- if (/^(IMG|HR)$/.test(target.nodeName) && dom.getContentEditableParent(target) !== 'false') {
- e.preventDefault();
- editor.selection.select(target);
- editor.nodeChanged();
- }
- if (target.nodeName === 'A' && dom.hasClass(target, visualAidsAnchorClass) && target.childNodes.length === 0) {
- e.preventDefault();
- selection.select(target);
- }
- });
- };
- const removeStylesWhenDeletingAcrossBlockElements = () => {
- const getAttributeApplyFunction = () => {
- const template = dom.getAttribs(selection.getStart().cloneNode(false));
- return () => {
- const target = selection.getStart();
- if (target !== editor.getBody()) {
- dom.setAttrib(target, 'style', null);
- each(template, attr => {
- target.setAttributeNode(attr.cloneNode(true));
- });
- }
- };
- };
- const isSelectionAcrossElements = () => {
- return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) !== dom.getParent(selection.getEnd(), dom.isBlock);
- };
- editor.on('keypress', e => {
- let applyAttributes;
- if (!isDefaultPrevented(e) && (e.keyCode === 8 || e.keyCode === 46) && isSelectionAcrossElements()) {
- applyAttributes = getAttributeApplyFunction();
- editor.getDoc().execCommand('delete', false, null);
- applyAttributes();
- e.preventDefault();
- return false;
- }
- });
- dom.bind(editor.getDoc(), 'cut', e => {
- let applyAttributes;
- if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
- applyAttributes = getAttributeApplyFunction();
- Delay.setEditorTimeout(editor, () => {
- applyAttributes();
- });
- }
- });
- };
- const disableBackspaceIntoATable = () => {
- editor.on('keydown', e => {
- if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
- if (selection.isCollapsed() && selection.getRng().startOffset === 0) {
- const previousSibling = selection.getNode().previousSibling;
- if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === 'table') {
- e.preventDefault();
- return false;
- }
- }
- }
- });
- };
- const removeBlockQuoteOnBackSpace = () => {
- editor.on('keydown', e => {
- let rng, parent;
- if (isDefaultPrevented(e) || e.keyCode !== VK.BACKSPACE) {
- return;
- }
- rng = selection.getRng();
- const container = rng.startContainer;
- const offset = rng.startOffset;
- const root = dom.getRoot();
- parent = container;
- if (!rng.collapsed || offset !== 0) {
- return;
- }
- while (parent && parent.parentNode && parent.parentNode.firstChild === parent && parent.parentNode !== root) {
- parent = parent.parentNode;
- }
- if (parent.tagName === 'BLOCKQUOTE') {
- editor.formatter.toggle('blockquote', null, parent);
- rng = dom.createRng();
- rng.setStart(container, 0);
- rng.setEnd(container, 0);
- selection.setRng(rng);
- }
- });
- };
- const setGeckoEditingOptions = () => {
- const setOpts = () => {
- setEditorCommandState('StyleWithCSS', false);
- setEditorCommandState('enableInlineTableEditing', false);
- if (!getObjectResizing(editor)) {
- setEditorCommandState('enableObjectResizing', false);
- }
- };
- if (!isReadOnly$1(editor)) {
- editor.on('BeforeExecCommand mousedown', setOpts);
- }
- };
- const addBrAfterLastLinks = () => {
- const fixLinks = () => {
- each(dom.select('a'), node => {
- let parentNode = node.parentNode;
- const root = dom.getRoot();
- if (parentNode.lastChild === node) {
- while (parentNode && !dom.isBlock(parentNode)) {
- if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
- return;
- }
- parentNode = parentNode.parentNode;
- }
- dom.add(parentNode, 'br', { 'data-mce-bogus': 1 });
- }
- });
- };
- editor.on('SetContent ExecCommand', e => {
- if (e.type === 'setcontent' || e.command === 'mceInsertLink') {
- fixLinks();
- }
- });
- };
- const setDefaultBlockType = () => {
- editor.on('init', () => {
- setEditorCommandState('DefaultParagraphSeparator', getForcedRootBlock(editor));
- });
- };
- const isAllContentSelected = editor => {
- const body = editor.getBody();
- const rng = editor.selection.getRng();
- return rng.startContainer === rng.endContainer && rng.startContainer === body && rng.startOffset === 0 && rng.endOffset === body.childNodes.length;
- };
- const normalizeSelection = () => {
- editor.on('keyup focusin mouseup', e => {
- if (!VK.modifierPressed(e) && !isAllContentSelected(editor)) {
- selection.normalize();
- }
- }, true);
- };
- const showBrokenImageIcon = () => {
- editor.contentStyles.push('img:-moz-broken {' + '-moz-force-broken-image-icon:1;' + 'min-width:24px;' + 'min-height:24px' + '}');
- };
- const restoreFocusOnKeyDown = () => {
- if (!editor.inline) {
- editor.on('keydown', () => {
- if (document.activeElement === document.body) {
- editor.getWin().focus();
- }
- });
- }
- };
- const bodyHeight = () => {
- if (!editor.inline) {
- editor.contentStyles.push('body {min-height: 150px}');
- editor.on('click', e => {
- let rng;
- if (e.target.nodeName === 'HTML') {
- rng = editor.selection.getRng();
- editor.getBody().focus();
- editor.selection.setRng(rng);
- editor.selection.normalize();
- editor.nodeChanged();
- }
- });
- }
- };
- const blockCmdArrowNavigation = () => {
- if (isMac) {
- editor.on('keydown', e => {
- if (VK.metaKeyPressed(e) && !e.shiftKey && (e.keyCode === 37 || e.keyCode === 39)) {
- e.preventDefault();
- const selection = editor.selection.getSel();
- selection.modify('move', e.keyCode === 37 ? 'backward' : 'forward', 'lineboundary');
- }
- });
- }
- };
- const tapLinksAndImages = () => {
- editor.on('click', e => {
- let elm = e.target;
- do {
- if (elm.tagName === 'A') {
- e.preventDefault();
- return;
- }
- } while (elm = elm.parentNode);
- });
- editor.contentStyles.push('.mce-content-body {-webkit-touch-callout: none}');
- };
- const blockFormSubmitInsideEditor = () => {
- editor.on('init', () => {
- editor.dom.bind(editor.getBody(), 'submit', e => {
- e.preventDefault();
- });
- });
- };
- const removeAppleInterchangeBrs = () => {
- parser.addNodeFilter('br', nodes => {
- let i = nodes.length;
- while (i--) {
- if (nodes[i].attr('class') === 'Apple-interchange-newline') {
- nodes[i].remove();
- }
- }
- });
- };
- const refreshContentEditable = noop;
- const isHidden = () => {
- if (!isGecko || editor.removed) {
- return false;
- }
- const sel = editor.selection.getSel();
- return !sel || !sel.rangeCount || sel.rangeCount === 0;
- };
- const setupRtc = () => {
- if (isWebKit) {
- documentElementEditingFocus();
- selectControlElements();
- blockFormSubmitInsideEditor();
- selectAll();
- if (isiOS) {
- restoreFocusOnKeyDown();
- bodyHeight();
- tapLinksAndImages();
- }
- }
- if (isGecko) {
- focusBody();
- setGeckoEditingOptions();
- showBrokenImageIcon();
- blockCmdArrowNavigation();
- }
- };
- const setup = () => {
- removeBlockQuoteOnBackSpace();
- emptyEditorWhenDeleting();
- if (!Env.windowsPhone) {
- normalizeSelection();
- }
- if (isWebKit) {
- documentElementEditingFocus();
- selectControlElements();
- setDefaultBlockType();
- blockFormSubmitInsideEditor();
- disableBackspaceIntoATable();
- removeAppleInterchangeBrs();
- if (isiOS) {
- restoreFocusOnKeyDown();
- bodyHeight();
- tapLinksAndImages();
- } else {
- selectAll();
- }
- }
- if (isGecko) {
- removeHrOnBackspace();
- focusBody();
- removeStylesWhenDeletingAcrossBlockElements();
- setGeckoEditingOptions();
- addBrAfterLastLinks();
- showBrokenImageIcon();
- blockCmdArrowNavigation();
- disableBackspaceIntoATable();
- }
- };
- if (isRtc(editor)) {
- setupRtc();
- } else {
- setup();
- }
- return {
- refreshContentEditable,
- isHidden
- };
- };
- const DOM$6 = DOMUtils.DOM;
- const appendStyle = (editor, text) => {
- const body = SugarElement.fromDom(editor.getBody());
- const container = getStyleContainer(getRootNode(body));
- const style = SugarElement.fromTag('style');
- set$2(style, 'type', 'text/css');
- append$1(style, SugarElement.fromText(text));
- append$1(container, style);
- editor.on('remove', () => {
- remove$6(style);
- });
- };
- const getRootName = editor => editor.inline ? editor.getElement().nodeName.toLowerCase() : undefined;
- const removeUndefined = obj => filter$5(obj, v => isUndefined(v) === false);
- const mkParserSettings = editor => {
- const getOption = editor.options.get;
- const blobCache = editor.editorUpload.blobCache;
- return removeUndefined({
- allow_conditional_comments: getOption('allow_conditional_comments'),
- allow_html_data_urls: getOption('allow_html_data_urls'),
- allow_svg_data_urls: getOption('allow_svg_data_urls'),
- allow_html_in_named_anchor: getOption('allow_html_in_named_anchor'),
- allow_script_urls: getOption('allow_script_urls'),
- allow_unsafe_link_target: getOption('allow_unsafe_link_target'),
- convert_fonts_to_spans: getOption('convert_fonts_to_spans'),
- fix_list_elements: getOption('fix_list_elements'),
- font_size_legacy_values: getOption('font_size_legacy_values'),
- forced_root_block: getOption('forced_root_block'),
- forced_root_block_attrs: getOption('forced_root_block_attrs'),
- preserve_cdata: getOption('preserve_cdata'),
- remove_trailing_brs: getOption('remove_trailing_brs'),
- inline_styles: getOption('inline_styles'),
- root_name: getRootName(editor),
- validate: true,
- blob_cache: blobCache,
- document: editor.getDoc()
- });
- };
- const mkSchemaSettings = editor => {
- const getOption = editor.options.get;
- return removeUndefined({
- custom_elements: getOption('custom_elements'),
- extended_valid_elements: getOption('extended_valid_elements'),
- invalid_elements: getOption('invalid_elements'),
- invalid_styles: getOption('invalid_styles'),
- schema: getOption('schema'),
- valid_children: getOption('valid_children'),
- valid_classes: getOption('valid_classes'),
- valid_elements: getOption('valid_elements'),
- valid_styles: getOption('valid_styles'),
- verify_html: getOption('verify_html'),
- padd_empty_block_inline_children: getOption('format_empty_lines')
- });
- };
- const mkSerializerSettings = editor => {
- const getOption = editor.options.get;
- return {
- ...mkParserSettings(editor),
- ...mkSchemaSettings(editor),
- ...removeUndefined({
- url_converter: getOption('url_converter'),
- url_converter_scope: getOption('url_converter_scope'),
- element_format: getOption('element_format'),
- entities: getOption('entities'),
- entity_encoding: getOption('entity_encoding'),
- indent: getOption('indent'),
- indent_after: getOption('indent_after'),
- indent_before: getOption('indent_before')
- })
- };
- };
- const createParser = editor => {
- const parser = DomParser(mkParserSettings(editor), editor.schema);
- parser.addAttributeFilter('src,href,style,tabindex', (nodes, name) => {
- let i = nodes.length, node, value;
- const dom = editor.dom;
- const internalName = 'data-mce-' + name;
- while (i--) {
- node = nodes[i];
- value = node.attr(name);
- if (value && !node.attr(internalName)) {
- if (value.indexOf('data:') === 0 || value.indexOf('blob:') === 0) {
- continue;
- }
- if (name === 'style') {
- value = dom.serializeStyle(dom.parseStyle(value), node.name);
- if (!value.length) {
- value = null;
- }
- node.attr(internalName, value);
- node.attr(name, value);
- } else if (name === 'tabindex') {
- node.attr(internalName, value);
- node.attr(name, null);
- } else {
- node.attr(internalName, editor.convertURL(value, name, node.name));
- }
- }
- }
- });
- parser.addNodeFilter('script', nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- const type = node.attr('type') || 'no/type';
- if (type.indexOf('mce-') !== 0) {
- node.attr('type', 'mce-' + type);
- }
- }
- });
- if (editor.options.get('preserve_cdata')) {
- parser.addNodeFilter('#cdata', nodes => {
- let i = nodes.length;
- while (i--) {
- const node = nodes[i];
- node.type = 8;
- node.name = '#comment';
- node.value = '[CDATA[' + editor.dom.encode(node.value) + ']]';
- }
- });
- }
- parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', nodes => {
- let i = nodes.length;
- const nonEmptyElements = editor.schema.getNonEmptyElements();
- while (i--) {
- const node = nodes[i];
- if (node.isEmpty(nonEmptyElements) && node.getAll('br').length === 0) {
- node.append(new AstNode('br', 1));
- }
- }
- });
- return parser;
- };
- const autoFocus = editor => {
- const autoFocus = getAutoFocus(editor);
- if (autoFocus) {
- Delay.setEditorTimeout(editor, () => {
- let focusEditor;
- if (autoFocus === true) {
- focusEditor = editor;
- } else {
- focusEditor = editor.editorManager.get(autoFocus);
- }
- if (!focusEditor.destroyed) {
- focusEditor.focus();
- }
- }, 100);
- }
- };
- const moveSelectionToFirstCaretPosition = editor => {
- const root = editor.dom.getRoot();
- if (!editor.inline && (!hasAnyRanges(editor) || editor.selection.getStart(true) === root)) {
- firstPositionIn(root).each(pos => {
- const node = pos.getNode();
- const caretPos = isTable$3(node) ? firstPositionIn(node).getOr(pos) : pos;
- editor.selection.setRng(caretPos.toRange());
- });
- }
- };
- const initEditor = editor => {
- editor.bindPendingEventDelegates();
- editor.initialized = true;
- fireInit(editor);
- editor.focus(true);
- moveSelectionToFirstCaretPosition(editor);
- editor.nodeChanged({ initial: true });
- const initInstanceCallback = getInitInstanceCallback(editor);
- if (isFunction(initInstanceCallback)) {
- initInstanceCallback.call(editor, editor);
- }
- autoFocus(editor);
- };
- const getStyleSheetLoader$1 = editor => editor.inline ? editor.ui.styleSheetLoader : editor.dom.styleSheetLoader;
- const makeStylesheetLoadingPromises = (editor, css, framedFonts) => {
- const promises = [getStyleSheetLoader$1(editor).loadAll(css)];
- if (editor.inline) {
- return promises;
- } else {
- return promises.concat([editor.ui.styleSheetLoader.loadAll(framedFonts)]);
- }
- };
- const loadContentCss = editor => {
- const styleSheetLoader = getStyleSheetLoader$1(editor);
- const fontCss = getFontCss(editor);
- const css = editor.contentCSS;
- const removeCss = () => {
- styleSheetLoader.unloadAll(css);
- if (!editor.inline) {
- editor.ui.styleSheetLoader.unloadAll(fontCss);
- }
- };
- const loaded = () => {
- if (editor.removed) {
- removeCss();
- } else {
- editor.on('remove', removeCss);
- }
- };
- if (editor.contentStyles.length > 0) {
- let contentCssText = '';
- Tools.each(editor.contentStyles, style => {
- contentCssText += style + '\r\n';
- });
- editor.dom.addStyle(contentCssText);
- }
- const allStylesheets = Promise.all(makeStylesheetLoadingPromises(editor, css, fontCss)).then(loaded).catch(loaded);
- const contentStyle = getContentStyle(editor);
- if (contentStyle) {
- appendStyle(editor, contentStyle);
- }
- return allStylesheets;
- };
- const preInit = editor => {
- const doc = editor.getDoc(), body = editor.getBody();
- firePreInit(editor);
- if (!shouldBrowserSpellcheck(editor)) {
- doc.body.spellcheck = false;
- DOM$6.setAttrib(body, 'spellcheck', 'false');
- }
- editor.quirks = Quirks(editor);
- firePostRender(editor);
- const directionality = getDirectionality(editor);
- if (directionality !== undefined) {
- body.dir = directionality;
- }
- const protect = getProtect(editor);
- if (protect) {
- editor.on('BeforeSetContent', e => {
- Tools.each(protect, pattern => {
- e.content = e.content.replace(pattern, str => {
- return '<!--mce:protected ' + escape(str) + '-->';
- });
- });
- });
- }
- editor.on('SetContent', () => {
- editor.addVisual(editor.getBody());
- });
- editor.on('compositionstart compositionend', e => {
- editor.composing = e.type === 'compositionstart';
- });
- };
- const loadInitialContent = editor => {
- if (!isRtc(editor)) {
- editor.load({
- initial: true,
- format: 'html'
- });
- }
- editor.startContent = editor.getContent({ format: 'raw' });
- };
- const initEditorWithInitialContent = editor => {
- if (editor.removed !== true) {
- loadInitialContent(editor);
- initEditor(editor);
- }
- };
- const contentBodyLoaded = editor => {
- const targetElm = editor.getElement();
- let doc = editor.getDoc();
- if (editor.inline) {
- DOM$6.addClass(targetElm, 'mce-content-body');
- editor.contentDocument = doc = document;
- editor.contentWindow = window;
- editor.bodyElement = targetElm;
- editor.contentAreaContainer = targetElm;
- }
- const body = editor.getBody();
- body.disabled = true;
- editor.readonly = isReadOnly$1(editor);
- if (!editor.readonly) {
- if (editor.inline && DOM$6.getStyle(body, 'position', true) === 'static') {
- body.style.position = 'relative';
- }
- body.contentEditable = 'true';
- }
- body.disabled = false;
- editor.editorUpload = EditorUpload(editor);
- editor.schema = Schema(mkSchemaSettings(editor));
- editor.dom = DOMUtils(doc, {
- keep_values: true,
- url_converter: editor.convertURL,
- url_converter_scope: editor,
- update_styles: true,
- root_element: editor.inline ? editor.getBody() : null,
- collect: () => editor.inline,
- schema: editor.schema,
- contentCssCors: shouldUseContentCssCors(editor),
- referrerPolicy: getReferrerPolicy(editor),
- onSetAttrib: e => {
- editor.dispatch('SetAttrib', e);
- }
- });
- editor.parser = createParser(editor);
- editor.serializer = DomSerializer(mkSerializerSettings(editor), editor);
- editor.selection = EditorSelection(editor.dom, editor.getWin(), editor.serializer, editor);
- editor.annotator = Annotator(editor);
- editor.formatter = Formatter(editor);
- editor.undoManager = UndoManager(editor);
- editor._nodeChangeDispatcher = new NodeChange(editor);
- editor._selectionOverrides = SelectionOverrides(editor);
- setup$o(editor);
- setup$6(editor);
- setup$m(editor);
- if (!isRtc(editor)) {
- setup$5(editor);
- setup$1(editor);
- }
- const caret = setup$b(editor);
- setup$p(editor, caret);
- setup$n(editor);
- setup$q(editor);
- setup$7(editor);
- const setupRtcThunk = setup$s(editor);
- preInit(editor);
- setupRtcThunk.fold(() => {
- loadContentCss(editor).then(() => initEditorWithInitialContent(editor));
- }, setupRtc => {
- editor.setProgressState(true);
- loadContentCss(editor).then(() => {
- setupRtc().then(_rtcMode => {
- editor.setProgressState(false);
- initEditorWithInitialContent(editor);
- bindEvents(editor);
- }, err => {
- editor.notificationManager.open({
- type: 'error',
- text: String(err)
- });
- initEditorWithInitialContent(editor);
- bindEvents(editor);
- });
- });
- });
- };
- const initContentBody = (editor, skipWrite) => {
- if (!editor.inline) {
- editor.getElement().style.visibility = editor.orgVisibility;
- }
- if (!skipWrite && !editor.inline) {
- const iframe = editor.iframeElement;
- const binder = bind$1(SugarElement.fromDom(iframe), 'load', () => {
- binder.unbind();
- editor.contentDocument = iframe.contentDocument;
- contentBodyLoaded(editor);
- });
- iframe.srcdoc = editor.iframeHTML;
- } else {
- contentBodyLoaded(editor);
- }
- };
- const DOM$5 = DOMUtils.DOM;
- const createIframeElement = (id, title, customAttrs, tabindex) => {
- const iframe = SugarElement.fromTag('iframe');
- tabindex.each(t => set$2(iframe, 'tabindex', t));
- setAll$1(iframe, customAttrs);
- setAll$1(iframe, {
- id: id + '_ifr',
- frameBorder: '0',
- allowTransparency: 'true',
- title
- });
- add$2(iframe, 'tox-edit-area__iframe');
- return iframe;
- };
- const getIframeHtml = editor => {
- let iframeHTML = getDocType(editor) + '<html><head>';
- if (getDocumentBaseUrl(editor) !== editor.documentBaseUrl) {
- iframeHTML += '<base href="' + editor.documentBaseURI.getURI() + '" />';
- }
- iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
- const bodyId = getBodyId(editor);
- const bodyClass = getBodyClass(editor);
- const translatedAriaText = editor.translate(getIframeAriaText(editor));
- if (getContentSecurityPolicy(editor)) {
- iframeHTML += '<meta http-equiv="Content-Security-Policy" content="' + getContentSecurityPolicy(editor) + '" />';
- }
- iframeHTML += '</head>' + `<body id="${ bodyId }" class="mce-content-body ${ bodyClass }" data-id="${ editor.id }" aria-label="${ translatedAriaText }">` + '<br>' + '</body></html>';
- return iframeHTML;
- };
- const createIframe = (editor, boxInfo) => {
- const iframeTitle = editor.translate('Rich Text Area');
- const tabindex = getOpt(SugarElement.fromDom(editor.getElement()), 'tabindex').bind(toInt);
- const ifr = createIframeElement(editor.id, iframeTitle, getIframeAttrs(editor), tabindex).dom;
- ifr.onload = () => {
- ifr.onload = null;
- editor.dispatch('load');
- };
- editor.contentAreaContainer = boxInfo.iframeContainer;
- editor.iframeElement = ifr;
- editor.iframeHTML = getIframeHtml(editor);
- DOM$5.add(boxInfo.iframeContainer, ifr);
- };
- const init$1 = (editor, boxInfo) => {
- createIframe(editor, boxInfo);
- if (boxInfo.editorContainer) {
- DOM$5.get(boxInfo.editorContainer).style.display = editor.orgDisplay;
- editor.hidden = DOM$5.isHidden(boxInfo.editorContainer);
- }
- editor.getElement().style.display = 'none';
- DOM$5.setAttrib(editor.id, 'aria-hidden', 'true');
- initContentBody(editor);
- };
- const DOM$4 = DOMUtils.DOM;
- const initPlugin = (editor, initializedPlugins, plugin) => {
- const Plugin = PluginManager.get(plugin);
- const pluginUrl = PluginManager.urls[plugin] || editor.documentBaseUrl.replace(/\/$/, '');
- plugin = Tools.trim(plugin);
- if (Plugin && Tools.inArray(initializedPlugins, plugin) === -1) {
- if (editor.plugins[plugin]) {
- return;
- }
- try {
- const pluginInstance = Plugin(editor, pluginUrl) || {};
- editor.plugins[plugin] = pluginInstance;
- if (isFunction(pluginInstance.init)) {
- pluginInstance.init(editor, pluginUrl);
- initializedPlugins.push(plugin);
- }
- } catch (e) {
- pluginInitError(editor, plugin, e);
- }
- }
- };
- const trimLegacyPrefix = name => {
- return name.replace(/^\-/, '');
- };
- const initPlugins = editor => {
- const initializedPlugins = [];
- each$f(getPlugins(editor), name => {
- initPlugin(editor, initializedPlugins, trimLegacyPrefix(name));
- });
- };
- const initIcons = editor => {
- const iconPackName = Tools.trim(getIconPackName(editor));
- const currentIcons = editor.ui.registry.getAll().icons;
- const loadIcons = {
- ...IconManager.get('default').icons,
- ...IconManager.get(iconPackName).icons
- };
- each$e(loadIcons, (svgData, icon) => {
- if (!has$2(currentIcons, icon)) {
- editor.ui.registry.addIcon(icon, svgData);
- }
- });
- };
- const initTheme = editor => {
- const theme = getTheme(editor);
- if (isString(theme)) {
- const Theme = ThemeManager.get(theme);
- editor.theme = Theme(editor, ThemeManager.urls[theme]) || {};
- if (isFunction(editor.theme.init)) {
- editor.theme.init(editor, ThemeManager.urls[theme] || editor.documentBaseUrl.replace(/\/$/, ''));
- }
- } else {
- editor.theme = {};
- }
- };
- const initModel = editor => {
- const model = getModel(editor);
- const Model = ModelManager.get(model);
- editor.model = Model(editor, ModelManager.urls[model]);
- };
- const renderFromLoadedTheme = editor => {
- return editor.theme.renderUI();
- };
- const renderFromThemeFunc = editor => {
- const elm = editor.getElement();
- const theme = getTheme(editor);
- const info = theme(editor, elm);
- if (info.editorContainer.nodeType) {
- info.editorContainer.id = info.editorContainer.id || editor.id + '_parent';
- }
- if (info.iframeContainer && info.iframeContainer.nodeType) {
- info.iframeContainer.id = info.iframeContainer.id || editor.id + '_iframecontainer';
- }
- info.height = info.iframeHeight ? info.iframeHeight : elm.offsetHeight;
- return info;
- };
- const createThemeFalseResult = element => {
- return {
- editorContainer: element,
- iframeContainer: element,
- api: {}
- };
- };
- const renderThemeFalseIframe = targetElement => {
- const iframeContainer = DOM$4.create('div');
- DOM$4.insertAfter(iframeContainer, targetElement);
- return createThemeFalseResult(iframeContainer);
- };
- const renderThemeFalse = editor => {
- const targetElement = editor.getElement();
- return editor.inline ? createThemeFalseResult(null) : renderThemeFalseIframe(targetElement);
- };
- const renderThemeUi = editor => {
- const elm = editor.getElement();
- editor.orgDisplay = elm.style.display;
- if (isString(getTheme(editor))) {
- return renderFromLoadedTheme(editor);
- } else if (isFunction(getTheme(editor))) {
- return renderFromThemeFunc(editor);
- } else {
- return renderThemeFalse(editor);
- }
- };
- const augmentEditorUiApi = (editor, api) => {
- const uiApiFacade = {
- show: Optional.from(api.show).getOr(noop),
- hide: Optional.from(api.hide).getOr(noop),
- isEnabled: Optional.from(api.isEnabled).getOr(always),
- setEnabled: state => {
- if (!editor.mode.isReadOnly()) {
- Optional.from(api.setEnabled).each(f => f(state));
- }
- }
- };
- editor.ui = {
- ...editor.ui,
- ...uiApiFacade
- };
- };
- const init = editor => {
- editor.dispatch('ScriptsLoaded');
- initIcons(editor);
- initTheme(editor);
- initModel(editor);
- initPlugins(editor);
- const renderInfo = renderThemeUi(editor);
- augmentEditorUiApi(editor, Optional.from(renderInfo.api).getOr({}));
- const boxInfo = {
- editorContainer: renderInfo.editorContainer,
- iframeContainer: renderInfo.iframeContainer
- };
- editor.editorContainer = boxInfo.editorContainer ? boxInfo.editorContainer : null;
- appendContentCssFromSettings(editor);
- if (editor.inline) {
- return initContentBody(editor);
- } else {
- return init$1(editor, boxInfo);
- }
- };
- const DOM$3 = DOMUtils.DOM;
- const hasSkipLoadPrefix = name => name.charAt(0) === '-';
- const loadLanguage = (scriptLoader, editor) => {
- const languageCode = getLanguageCode(editor);
- const languageUrl = getLanguageUrl(editor);
- if (I18n.hasCode(languageCode) === false && languageCode !== 'en') {
- const url = isNotEmpty(languageUrl) ? languageUrl : `${ editor.editorManager.baseURL }/langs/${ languageCode }.js`;
- scriptLoader.add(url).catch(() => {
- languageLoadError(editor, url, languageCode);
- });
- }
- };
- const loadTheme = (editor, suffix) => {
- const theme = getTheme(editor);
- if (isString(theme) && !hasSkipLoadPrefix(theme) && !has$2(ThemeManager.urls, theme)) {
- const themeUrl = getThemeUrl(editor);
- const url = themeUrl ? editor.documentBaseURI.toAbsolute(themeUrl) : `themes/${ theme }/theme${ suffix }.js`;
- ThemeManager.load(theme, url).catch(() => {
- themeLoadError(editor, url, theme);
- });
- }
- };
- const loadModel = (editor, suffix) => {
- const model = getModel(editor);
- if (model !== 'plugin' && !has$2(ModelManager.urls, model)) {
- const modelUrl = getModelUrl(editor);
- const url = isString(modelUrl) ? editor.documentBaseURI.toAbsolute(modelUrl) : `models/${ model }/model${ suffix }.js`;
- ModelManager.load(model, url).catch(() => {
- modelLoadError(editor, url, model);
- });
- }
- };
- const getIconsUrlMetaFromUrl = editor => Optional.from(getIconsUrl(editor)).filter(isNotEmpty).map(url => ({
- url,
- name: Optional.none()
- }));
- const getIconsUrlMetaFromName = (editor, name, suffix) => Optional.from(name).filter(name => isNotEmpty(name) && !IconManager.has(name)).map(name => ({
- url: `${ editor.editorManager.baseURL }/icons/${ name }/icons${ suffix }.js`,
- name: Optional.some(name)
- }));
- const loadIcons = (scriptLoader, editor, suffix) => {
- const defaultIconsUrl = getIconsUrlMetaFromName(editor, 'default', suffix);
- const customIconsUrl = getIconsUrlMetaFromUrl(editor).orThunk(() => getIconsUrlMetaFromName(editor, getIconPackName(editor), ''));
- each$f(cat([
- defaultIconsUrl,
- customIconsUrl
- ]), urlMeta => {
- scriptLoader.add(urlMeta.url).catch(() => {
- iconsLoadError(editor, urlMeta.url, urlMeta.name.getOrUndefined());
- });
- });
- };
- const loadPlugins = (editor, suffix) => {
- const loadPlugin = (name, url) => {
- PluginManager.load(name, url).catch(() => {
- pluginLoadError(editor, url, name);
- });
- };
- each$e(getExternalPlugins$1(editor), (url, name) => {
- loadPlugin(name, url);
- editor.options.set('plugins', getPlugins(editor).concat(name));
- });
- each$f(getPlugins(editor), plugin => {
- plugin = Tools.trim(plugin);
- if (plugin && !PluginManager.urls[plugin] && !hasSkipLoadPrefix(plugin)) {
- loadPlugin(plugin, `plugins/${ plugin }/plugin${ suffix }.js`);
- }
- });
- };
- const isThemeLoaded = editor => {
- const theme = getTheme(editor);
- return !isString(theme) || isNonNullable(ThemeManager.get(theme));
- };
- const isModelLoaded = editor => {
- const model = getModel(editor);
- return isNonNullable(ModelManager.get(model));
- };
- const loadScripts = (editor, suffix) => {
- const scriptLoader = ScriptLoader.ScriptLoader;
- const initEditor = () => {
- if (!editor.removed && isThemeLoaded(editor) && isModelLoaded(editor)) {
- init(editor);
- }
- };
- loadTheme(editor, suffix);
- loadModel(editor, suffix);
- loadLanguage(scriptLoader, editor);
- loadIcons(scriptLoader, editor, suffix);
- loadPlugins(editor, suffix);
- scriptLoader.loadQueue().then(initEditor, initEditor);
- };
- const getStyleSheetLoader = (element, editor) => instance.forElement(element, {
- contentCssCors: hasContentCssCors(editor),
- referrerPolicy: getReferrerPolicy(editor)
- });
- const render = editor => {
- const id = editor.id;
- I18n.setCode(getLanguageCode(editor));
- const readyHandler = () => {
- DOM$3.unbind(window, 'ready', readyHandler);
- editor.render();
- };
- if (!EventUtils.Event.domLoaded) {
- DOM$3.bind(window, 'ready', readyHandler);
- return;
- }
- if (!editor.getElement()) {
- return;
- }
- const element = SugarElement.fromDom(editor.getElement());
- const snapshot = clone$4(element);
- editor.on('remove', () => {
- eachr(element.dom.attributes, attr => remove$b(element, attr.name));
- setAll$1(element, snapshot);
- });
- editor.ui.styleSheetLoader = getStyleSheetLoader(element, editor);
- if (!isInline(editor)) {
- editor.orgVisibility = editor.getElement().style.visibility;
- editor.getElement().style.visibility = 'hidden';
- } else {
- editor.inline = true;
- }
- const form = editor.getElement().form || DOM$3.getParent(id, 'form');
- if (form) {
- editor.formElement = form;
- if (hasHiddenInput(editor) && !isTextareaOrInput(editor.getElement())) {
- DOM$3.insertAfter(DOM$3.create('input', {
- type: 'hidden',
- name: id
- }), id);
- editor.hasHiddenInput = true;
- }
- editor.formEventDelegate = e => {
- editor.dispatch(e.type, e);
- };
- DOM$3.bind(form, 'submit reset', editor.formEventDelegate);
- editor.on('reset', () => {
- editor.resetContent();
- });
- if (shouldPatchSubmit(editor) && !form.submit.nodeType && !form.submit.length && !form._mceOldSubmit) {
- form._mceOldSubmit = form.submit;
- form.submit = () => {
- editor.editorManager.triggerSave();
- editor.setDirty(false);
- return form._mceOldSubmit(form);
- };
- }
- }
- editor.windowManager = WindowManager(editor);
- editor.notificationManager = NotificationManager(editor);
- if (isEncodingXml(editor)) {
- editor.on('GetContent', e => {
- if (e.save) {
- e.content = DOM$3.encode(e.content);
- }
- });
- }
- if (shouldAddFormSubmitTrigger(editor)) {
- editor.on('submit', () => {
- if (editor.initialized) {
- editor.save();
- }
- });
- }
- if (shouldAddUnloadTrigger(editor)) {
- editor._beforeUnload = () => {
- if (editor.initialized && !editor.destroyed && !editor.isHidden()) {
- editor.save({
- format: 'raw',
- no_events: true,
- set_dirty: false
- });
- }
- };
- editor.editorManager.on('BeforeUnload', editor._beforeUnload);
- }
- editor.editorManager.add(editor);
- loadScripts(editor, editor.suffix);
- };
- const sectionResult = (sections, settings) => ({
- sections: constant(sections),
- options: constant(settings)
- });
- const deviceDetection = detect$2().deviceType;
- const isPhone = deviceDetection.isPhone();
- const isTablet = deviceDetection.isTablet();
- const normalizePlugins = plugins => {
- if (isNullable(plugins)) {
- return [];
- } else {
- const pluginNames = isArray$1(plugins) ? plugins : plugins.split(/[ ,]/);
- const trimmedPlugins = map$3(pluginNames, trim$3);
- return filter$6(trimmedPlugins, isNotEmpty);
- }
- };
- const extractSections = (keys, options) => {
- const result = bifilter(options, (value, key) => {
- return contains$2(keys, key);
- });
- return sectionResult(result.t, result.f);
- };
- const getSection = (sectionResult, name, defaults = {}) => {
- const sections = sectionResult.sections();
- const sectionOptions = get$a(sections, name).getOr({});
- return Tools.extend({}, defaults, sectionOptions);
- };
- const hasSection = (sectionResult, name) => {
- return has$2(sectionResult.sections(), name);
- };
- const getSectionConfig = (sectionResult, name) => {
- return hasSection(sectionResult, name) ? sectionResult.sections()[name] : {};
- };
- const getMobileOverrideOptions = (mobileOptions, isPhone) => {
- const defaultMobileOptions = {
- table_grid: false,
- object_resizing: false,
- resize: false,
- toolbar_mode: get$a(mobileOptions, 'toolbar_mode').getOr('scrolling'),
- toolbar_sticky: false
- };
- const defaultPhoneOptions = { menubar: false };
- return {
- ...defaultMobileOptions,
- ...isPhone ? defaultPhoneOptions : {}
- };
- };
- const getExternalPlugins = (overrideOptions, options) => {
- var _a;
- const userDefinedExternalPlugins = (_a = options.external_plugins) !== null && _a !== void 0 ? _a : {};
- if (overrideOptions && overrideOptions.external_plugins) {
- return Tools.extend({}, overrideOptions.external_plugins, userDefinedExternalPlugins);
- } else {
- return userDefinedExternalPlugins;
- }
- };
- const combinePlugins = (forcedPlugins, plugins) => {
- return [].concat(normalizePlugins(forcedPlugins)).concat(normalizePlugins(plugins));
- };
- const getPlatformPlugins = (isMobileDevice, sectionResult, desktopPlugins, mobilePlugins) => {
- if (isMobileDevice && hasSection(sectionResult, 'mobile')) {
- return mobilePlugins;
- } else {
- return desktopPlugins;
- }
- };
- const processPlugins = (isMobileDevice, sectionResult, defaultOverrideOptions, options) => {
- const forcedPlugins = normalizePlugins(defaultOverrideOptions.forced_plugins);
- const desktopPlugins = normalizePlugins(options.plugins);
- const mobileConfig = getSectionConfig(sectionResult, 'mobile');
- const mobilePlugins = mobileConfig.plugins ? normalizePlugins(mobileConfig.plugins) : desktopPlugins;
- const platformPlugins = getPlatformPlugins(isMobileDevice, sectionResult, desktopPlugins, mobilePlugins);
- const combinedPlugins = combinePlugins(forcedPlugins, platformPlugins);
- return Tools.extend(options, {
- forced_plugins: forcedPlugins,
- plugins: combinedPlugins
- });
- };
- const isOnMobile = (isMobileDevice, sectionResult) => {
- return isMobileDevice && hasSection(sectionResult, 'mobile');
- };
- const combineOptions = (isMobileDevice, isPhone, defaultOptions, defaultOverrideOptions, options) => {
- var _a;
- const deviceOverrideOptions = isMobileDevice ? { mobile: getMobileOverrideOptions((_a = options.mobile) !== null && _a !== void 0 ? _a : {}, isPhone) } : {};
- const sectionResult = extractSections(['mobile'], deepMerge(deviceOverrideOptions, options));
- const extendedOptions = Tools.extend(defaultOptions, defaultOverrideOptions, sectionResult.options(), isOnMobile(isMobileDevice, sectionResult) ? getSection(sectionResult, 'mobile') : {}, { external_plugins: getExternalPlugins(defaultOverrideOptions, sectionResult.options()) });
- return processPlugins(isMobileDevice, sectionResult, defaultOverrideOptions, extendedOptions);
- };
- const normalizeOptions = (defaultOverrideOptions, options) => combineOptions(isPhone || isTablet, isPhone, options, defaultOverrideOptions, options);
- const addVisual = (editor, elm) => addVisual$1(editor, elm);
- const registerExecCommands$3 = editor => {
- const toggleFormat = (name, value) => {
- editor.formatter.toggle(name, value);
- editor.nodeChanged();
- };
- const toggleAlign = align => () => {
- each$f('left,center,right,justify'.split(','), name => {
- if (align !== name) {
- editor.formatter.remove('align' + name);
- }
- });
- if (align !== 'none') {
- toggleFormat('align' + align);
- }
- };
- editor.editorCommands.addCommands({
- JustifyLeft: toggleAlign('left'),
- JustifyCenter: toggleAlign('center'),
- JustifyRight: toggleAlign('right'),
- JustifyFull: toggleAlign('justify'),
- JustifyNone: toggleAlign('none')
- });
- };
- const registerQueryStateCommands$1 = editor => {
- const alignStates = name => () => {
- const selection = editor.selection;
- const nodes = selection.isCollapsed() ? [editor.dom.getParent(selection.getNode(), editor.dom.isBlock)] : selection.getSelectedBlocks();
- return exists(nodes, node => isNonNullable(editor.formatter.matchNode(node, name)));
- };
- editor.editorCommands.addCommands({
- JustifyLeft: alignStates('alignleft'),
- JustifyCenter: alignStates('aligncenter'),
- JustifyRight: alignStates('alignright'),
- JustifyFull: alignStates('alignjustify')
- }, 'state');
- };
- const registerCommands$a = editor => {
- registerExecCommands$3(editor);
- registerQueryStateCommands$1(editor);
- };
- const registerCommands$9 = editor => {
- editor.editorCommands.addCommands({
- 'Cut,Copy,Paste': command => {
- const doc = editor.getDoc();
- let failed;
- try {
- doc.execCommand(command);
- } catch (ex) {
- failed = true;
- }
- if (command === 'paste' && !doc.queryCommandEnabled(command)) {
- failed = true;
- }
- if (failed || !doc.queryCommandSupported(command)) {
- let msg = editor.translate(`Your browser doesn't support direct access to the clipboard. ` + 'Please use the Ctrl+X/C/V keyboard shortcuts instead.');
- if (Env.os.isMacOS() || Env.os.isiOS()) {
- msg = msg.replace(/Ctrl\+/g, '\u2318+');
- }
- editor.notificationManager.open({
- text: msg,
- type: 'error'
- });
- }
- }
- });
- };
- const trimOrPadLeftRight = (dom, rng, html) => {
- const root = SugarElement.fromDom(dom.getRoot());
- if (needsToBeNbspLeft(root, CaretPosition.fromRangeStart(rng))) {
- html = html.replace(/^ /, ' ');
- } else {
- html = html.replace(/^ /, ' ');
- }
- if (needsToBeNbspRight(root, CaretPosition.fromRangeEnd(rng))) {
- html = html.replace(/( | )(<br( \/)>)?$/, ' ');
- } else {
- html = html.replace(/ (<br( \/)?>)?$/, ' ');
- }
- return html;
- };
- const processValue$1 = value => {
- if (typeof value !== 'string') {
- const details = Tools.extend({
- paste: value.paste,
- data: { paste: value.paste }
- }, value);
- return {
- content: value.content,
- details
- };
- }
- return {
- content: value,
- details: {}
- };
- };
- const trimOrPad = (editor, value) => {
- const selection = editor.selection;
- const dom = editor.dom;
- if (/^ | $/.test(value)) {
- return trimOrPadLeftRight(dom, selection.getRng(), value);
- } else {
- return value;
- }
- };
- const insertAtCaret = (editor, value) => {
- const {content, details} = processValue$1(value);
- preProcessSetContent(editor, {
- content: trimOrPad(editor, content),
- format: 'html',
- set: false,
- selection: true,
- paste: details.paste
- }).each(args => {
- const insertedContent = insertContent$1(editor, args.content, details);
- postProcessSetContent(editor, insertedContent, args);
- editor.addVisual();
- });
- };
- const registerCommands$8 = editor => {
- editor.editorCommands.addCommands({
- mceCleanup: () => {
- const bm = editor.selection.getBookmark();
- editor.setContent(editor.getContent());
- editor.selection.moveToBookmark(bm);
- },
- insertImage: (_command, _ui, value) => {
- insertAtCaret(editor, editor.dom.createHTML('img', { src: value }));
- },
- insertHorizontalRule: () => {
- editor.execCommand('mceInsertContent', false, '<hr>');
- },
- insertText: (_command, _ui, value) => {
- insertAtCaret(editor, editor.dom.encode(value));
- },
- insertHTML: (_command, _ui, value) => {
- insertAtCaret(editor, value);
- },
- mceInsertContent: (_command, _ui, value) => {
- insertAtCaret(editor, value);
- },
- mceSetContent: (_command, _ui, value) => {
- editor.setContent(value);
- },
- mceReplaceContent: (_command, _ui, value) => {
- editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, editor.selection.getContent({ format: 'text' })));
- },
- mceNewDocument: () => {
- editor.setContent('');
- }
- });
- };
- const legacyPropNames = {
- 'font-size': 'size',
- 'font-family': 'face'
- };
- const getSpecifiedFontProp = (propName, rootElm, elm) => {
- const getProperty = elm => getRaw$1(elm, propName).orThunk(() => {
- if (name(elm) === 'font') {
- return get$a(legacyPropNames, propName).bind(legacyPropName => getOpt(elm, legacyPropName));
- } else {
- return Optional.none();
- }
- });
- const isRoot = elm => eq(SugarElement.fromDom(rootElm), elm);
- return closest$2(SugarElement.fromDom(elm), elm => getProperty(elm), isRoot);
- };
- const normalizeFontFamily = fontFamily => fontFamily.replace(/[\'\"\\]/g, '').replace(/,\s+/g, ',');
- const getComputedFontProp = (propName, elm) => Optional.from(DOMUtils.DOM.getStyle(elm, propName, true));
- const getFontProp = propName => (rootElm, elm) => Optional.from(elm).map(SugarElement.fromDom).filter(isElement$7).bind(element => getSpecifiedFontProp(propName, rootElm, element.dom).or(getComputedFontProp(propName, element.dom))).getOr('');
- const getFontSize = getFontProp('font-size');
- const getFontFamily = compose(normalizeFontFamily, getFontProp('font-family'));
- const findFirstCaretElement = editor => firstPositionIn(editor.getBody()).map(caret => {
- const container = caret.container();
- return isText$9(container) ? container.parentNode : container;
- });
- const getCaretElement = editor => Optional.from(editor.selection.getRng()).bind(rng => {
- const root = editor.getBody();
- const atStartOfNode = rng.startContainer === root && rng.startOffset === 0;
- return atStartOfNode ? Optional.none() : Optional.from(editor.selection.getStart(true));
- });
- const bindRange = (editor, binder) => getCaretElement(editor).orThunk(curry(findFirstCaretElement, editor)).map(SugarElement.fromDom).filter(isElement$7).bind(binder);
- const mapRange = (editor, mapper) => bindRange(editor, compose1(Optional.some, mapper));
- const fromFontSizeNumber = (editor, value) => {
- if (/^[0-9.]+$/.test(value)) {
- const fontSizeNumber = parseInt(value, 10);
- if (fontSizeNumber >= 1 && fontSizeNumber <= 7) {
- const fontSizes = getFontStyleValues(editor);
- const fontClasses = getFontSizeClasses(editor);
- if (fontClasses) {
- return fontClasses[fontSizeNumber - 1] || value;
- } else {
- return fontSizes[fontSizeNumber - 1] || value;
- }
- } else {
- return value;
- }
- } else {
- return value;
- }
- };
- const normalizeFontNames = font => {
- const fonts = font.split(/\s*,\s*/);
- return map$3(fonts, font => {
- if (font.indexOf(' ') !== -1 && !(startsWith(font, '"') || startsWith(font, `'`))) {
- return `'${ font }'`;
- } else {
- return font;
- }
- }).join(',');
- };
- const fontNameAction = (editor, value) => {
- const font = fromFontSizeNumber(editor, value);
- editor.formatter.toggle('fontname', { value: normalizeFontNames(font) });
- editor.nodeChanged();
- };
- const fontNameQuery = editor => mapRange(editor, elm => getFontFamily(editor.getBody(), elm.dom)).getOr('');
- const fontSizeAction = (editor, value) => {
- editor.formatter.toggle('fontsize', { value: fromFontSizeNumber(editor, value) });
- editor.nodeChanged();
- };
- const fontSizeQuery = editor => mapRange(editor, elm => getFontSize(editor.getBody(), elm.dom)).getOr('');
- const lineHeightQuery = editor => mapRange(editor, elm => {
- const root = SugarElement.fromDom(editor.getBody());
- const specifiedStyle = closest$2(elm, elm => getRaw$1(elm, 'line-height'), curry(eq, root));
- const computedStyle = () => {
- const lineHeight = parseFloat(get$7(elm, 'line-height'));
- const fontSize = parseFloat(get$7(elm, 'font-size'));
- return String(lineHeight / fontSize);
- };
- return specifiedStyle.getOrThunk(computedStyle);
- }).getOr('');
- const lineHeightAction = (editor, lineHeight) => {
- editor.formatter.toggle('lineheight', { value: String(lineHeight) });
- editor.nodeChanged();
- };
- const registerExecCommands$2 = editor => {
- const toggleFormat = (name, value) => {
- editor.formatter.toggle(name, value);
- editor.nodeChanged();
- };
- editor.editorCommands.addCommands({
- 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': command => {
- toggleFormat(command);
- },
- 'ForeColor,HiliteColor': (command, _ui, value) => {
- toggleFormat(command, { value });
- },
- 'BackColor': (_command, _ui, value) => {
- toggleFormat('hilitecolor', { value });
- },
- 'FontName': (_command, _ui, value) => {
- fontNameAction(editor, value);
- },
- 'FontSize': (_command, _ui, value) => {
- fontSizeAction(editor, value);
- },
- 'LineHeight': (_command, _ui, value) => {
- lineHeightAction(editor, value);
- },
- 'Lang': (command, _ui, lang) => {
- toggleFormat(command, {
- value: lang.code,
- customValue: lang.customCode
- });
- },
- 'RemoveFormat': command => {
- editor.formatter.remove(command);
- },
- 'mceBlockQuote': () => {
- toggleFormat('blockquote');
- },
- 'FormatBlock': (_command, _ui, value) => {
- toggleFormat(isString(value) ? value : 'p');
- },
- 'mceToggleFormat': (_command, _ui, value) => {
- toggleFormat(value);
- }
- });
- };
- const registerQueryValueCommands = editor => {
- const isFormatMatch = name => editor.formatter.match(name);
- editor.editorCommands.addCommands({
- 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': command => isFormatMatch(command),
- 'mceBlockQuote': () => isFormatMatch('blockquote')
- }, 'state');
- editor.editorCommands.addQueryValueHandler('FontName', () => fontNameQuery(editor));
- editor.editorCommands.addQueryValueHandler('FontSize', () => fontSizeQuery(editor));
- editor.editorCommands.addQueryValueHandler('LineHeight', () => lineHeightQuery(editor));
- };
- const registerCommands$7 = editor => {
- registerExecCommands$2(editor);
- registerQueryValueCommands(editor);
- };
- const registerCommands$6 = editor => {
- editor.editorCommands.addCommands({
- mceAddUndoLevel: () => {
- editor.undoManager.add();
- },
- mceEndUndoLevel: () => {
- editor.undoManager.add();
- },
- Undo: () => {
- editor.undoManager.undo();
- },
- Redo: () => {
- editor.undoManager.redo();
- }
- });
- };
- const registerCommands$5 = editor => {
- editor.editorCommands.addCommands({
- Indent: () => {
- indent(editor);
- },
- Outdent: () => {
- outdent(editor);
- }
- });
- editor.editorCommands.addCommands({ Outdent: () => canOutdent(editor) }, 'state');
- };
- const registerCommands$4 = editor => {
- const applyLinkToSelection = (_command, _ui, value) => {
- const linkDetails = isString(value) ? { href: value } : value;
- const anchor = editor.dom.getParent(editor.selection.getNode(), 'a');
- if (isObject(linkDetails) && isString(linkDetails.href)) {
- linkDetails.href = linkDetails.href.replace(/ /g, '%20');
- if (!anchor || !linkDetails.href) {
- editor.formatter.remove('link');
- }
- if (linkDetails.href) {
- editor.formatter.apply('link', linkDetails, anchor);
- }
- }
- };
- editor.editorCommands.addCommands({
- unlink: () => {
- if (editor.selection.isCollapsed()) {
- const elm = editor.dom.getParent(editor.selection.getStart(), 'a');
- if (elm) {
- editor.dom.remove(elm, true);
- }
- return;
- }
- editor.formatter.remove('link');
- },
- mceInsertLink: applyLinkToSelection,
- createLink: applyLinkToSelection
- });
- };
- const registerExecCommands$1 = editor => {
- editor.editorCommands.addCommands({
- 'InsertUnorderedList,InsertOrderedList': command => {
- editor.getDoc().execCommand(command);
- const listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
- if (listElm) {
- const listParent = listElm.parentNode;
- if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
- const bm = editor.selection.getBookmark();
- editor.dom.split(listParent, listElm);
- editor.selection.moveToBookmark(bm);
- }
- }
- }
- });
- };
- const registerQueryStateCommands = editor => {
- editor.editorCommands.addCommands({
- 'InsertUnorderedList,InsertOrderedList': command => {
- const list = editor.dom.getParent(editor.selection.getNode(), 'ul,ol');
- return list && (command === 'insertunorderedlist' && list.tagName === 'UL' || command === 'insertorderedlist' && list.tagName === 'OL');
- }
- }, 'state');
- };
- const registerCommands$3 = editor => {
- registerExecCommands$1(editor);
- registerQueryStateCommands(editor);
- };
- const registerCommands$2 = editor => {
- editor.editorCommands.addCommands({
- insertParagraph: () => {
- insertBreak(blockbreak, editor);
- },
- mceInsertNewLine: (_command, _ui, value) => {
- insert(editor, value);
- },
- InsertLineBreak: (_command, _ui, _value) => {
- insertBreak(linebreak, editor);
- }
- });
- };
- const registerCommands$1 = editor => {
- editor.editorCommands.addCommands({
- mceSelectNodeDepth: (_command, _ui, value) => {
- let counter = 0;
- editor.dom.getParent(editor.selection.getNode(), node => {
- if (node.nodeType === 1 && counter++ === value) {
- editor.selection.select(node);
- return false;
- }
- }, editor.getBody());
- },
- mceSelectNode: (_command, _ui, value) => {
- editor.selection.select(value);
- },
- selectAll: () => {
- const editingHost = editor.dom.getParent(editor.selection.getStart(), isContentEditableTrue$5);
- if (editingHost) {
- const rng = editor.dom.createRng();
- rng.selectNodeContents(editingHost);
- editor.selection.setRng(rng);
- }
- }
- });
- };
- const registerExecCommands = editor => {
- editor.editorCommands.addCommands({
- mceRemoveNode: (_command, _ui, value) => {
- const node = value !== null && value !== void 0 ? value : editor.selection.getNode();
- if (node !== editor.getBody()) {
- const bm = editor.selection.getBookmark();
- editor.dom.remove(node, true);
- editor.selection.moveToBookmark(bm);
- }
- },
- mcePrint: () => {
- editor.getWin().print();
- },
- mceFocus: (_command, _ui, value) => {
- focus(editor, value);
- },
- mceToggleVisualAid: () => {
- editor.hasVisual = !editor.hasVisual;
- editor.addVisual();
- }
- });
- };
- const registerCommands = editor => {
- registerCommands$a(editor);
- registerCommands$9(editor);
- registerCommands$6(editor);
- registerCommands$1(editor);
- registerCommands$8(editor);
- registerCommands$4(editor);
- registerCommands$5(editor);
- registerCommands$2(editor);
- registerCommands$3(editor);
- registerCommands$7(editor);
- registerExecCommands(editor);
- };
- class EditorCommands {
- constructor(editor) {
- this.commands = {
- state: {},
- exec: {},
- value: {}
- };
- this.editor = editor;
- }
- execCommand(command, ui, value, args) {
- const editor = this.editor;
- const lowerCaseCommand = command.toLowerCase();
- const skipFocus = args === null || args === void 0 ? void 0 : args.skip_focus;
- if (editor.removed) {
- return false;
- }
- if (lowerCaseCommand !== 'mcefocus') {
- if (!/^(mceAddUndoLevel|mceEndUndoLevel)$/i.test(lowerCaseCommand) && !skipFocus) {
- editor.focus();
- } else {
- restore(editor);
- }
- }
- const eventArgs = editor.dispatch('BeforeExecCommand', {
- command,
- ui,
- value
- });
- if (eventArgs.isDefaultPrevented()) {
- return false;
- }
- const func = this.commands.exec[lowerCaseCommand];
- if (isFunction(func)) {
- func(lowerCaseCommand, ui, value);
- editor.dispatch('ExecCommand', {
- command,
- ui,
- value
- });
- return true;
- }
- return false;
- }
- queryCommandState(command) {
- if (this.editor.quirks.isHidden() || this.editor.removed) {
- return false;
- }
- const lowerCaseCommand = command.toLowerCase();
- const func = this.commands.state[lowerCaseCommand];
- if (isFunction(func)) {
- return func(lowerCaseCommand);
- }
- return false;
- }
- queryCommandValue(command) {
- if (this.editor.quirks.isHidden() || this.editor.removed) {
- return '';
- }
- const lowerCaseCommand = command.toLowerCase();
- const func = this.commands.value[lowerCaseCommand];
- if (isFunction(func)) {
- return func(lowerCaseCommand);
- }
- return '';
- }
- addCommands(commandList, type = 'exec') {
- const commands = this.commands;
- each$e(commandList, (callback, command) => {
- each$f(command.toLowerCase().split(','), command => {
- commands[type][command] = callback;
- });
- });
- }
- addCommand(command, callback, scope) {
- const lowerCaseCommand = command.toLowerCase();
- this.commands.exec[lowerCaseCommand] = (_command, ui, value) => callback.call(scope !== null && scope !== void 0 ? scope : this.editor, ui, value);
- }
- queryCommandSupported(command) {
- const lowerCaseCommand = command.toLowerCase();
- if (this.commands.exec[lowerCaseCommand]) {
- return true;
- }
- return false;
- }
- addQueryStateHandler(command, callback, scope) {
- this.commands.state[command.toLowerCase()] = () => callback.call(scope !== null && scope !== void 0 ? scope : this.editor);
- }
- addQueryValueHandler(command, callback, scope) {
- this.commands.value[command.toLowerCase()] = () => callback.call(scope !== null && scope !== void 0 ? scope : this.editor);
- }
- }
- const internalContentEditableAttr = 'data-mce-contenteditable';
- const toggleClass = (elm, cls, state) => {
- if (has(elm, cls) && state === false) {
- remove$8(elm, cls);
- } else if (state) {
- add$2(elm, cls);
- }
- };
- const setEditorCommandState = (editor, cmd, state) => {
- try {
- editor.getDoc().execCommand(cmd, false, String(state));
- } catch (ex) {
- }
- };
- const setContentEditable = (elm, state) => {
- elm.dom.contentEditable = state ? 'true' : 'false';
- };
- const switchOffContentEditableTrue = elm => {
- each$f(descendants(elm, '*[contenteditable="true"]'), elm => {
- set$2(elm, internalContentEditableAttr, 'true');
- setContentEditable(elm, false);
- });
- };
- const switchOnContentEditableTrue = elm => {
- each$f(descendants(elm, `*[${ internalContentEditableAttr }="true"]`), elm => {
- remove$b(elm, internalContentEditableAttr);
- setContentEditable(elm, true);
- });
- };
- const removeFakeSelection = editor => {
- Optional.from(editor.selection.getNode()).each(elm => {
- elm.removeAttribute('data-mce-selected');
- });
- };
- const restoreFakeSelection = editor => {
- editor.selection.setRng(editor.selection.getRng());
- };
- const toggleReadOnly = (editor, state) => {
- const body = SugarElement.fromDom(editor.getBody());
- toggleClass(body, 'mce-content-readonly', state);
- if (state) {
- editor.selection.controlSelection.hideResizeRect();
- editor._selectionOverrides.hideFakeCaret();
- removeFakeSelection(editor);
- editor.readonly = true;
- setContentEditable(body, false);
- switchOffContentEditableTrue(body);
- } else {
- editor.readonly = false;
- setContentEditable(body, true);
- switchOnContentEditableTrue(body);
- setEditorCommandState(editor, 'StyleWithCSS', false);
- setEditorCommandState(editor, 'enableInlineTableEditing', false);
- setEditorCommandState(editor, 'enableObjectResizing', false);
- if (hasEditorOrUiFocus(editor)) {
- editor.focus();
- }
- restoreFakeSelection(editor);
- editor.nodeChanged();
- }
- };
- const isReadOnly = editor => editor.readonly;
- const registerFilters = editor => {
- editor.parser.addAttributeFilter('contenteditable', nodes => {
- if (isReadOnly(editor)) {
- each$f(nodes, node => {
- node.attr(internalContentEditableAttr, node.attr('contenteditable'));
- node.attr('contenteditable', 'false');
- });
- }
- });
- editor.serializer.addAttributeFilter(internalContentEditableAttr, nodes => {
- if (isReadOnly(editor)) {
- each$f(nodes, node => {
- node.attr('contenteditable', node.attr(internalContentEditableAttr));
- });
- }
- });
- editor.serializer.addTempAttr(internalContentEditableAttr);
- };
- const registerReadOnlyContentFilters = editor => {
- if (editor.serializer) {
- registerFilters(editor);
- } else {
- editor.on('PreInit', () => {
- registerFilters(editor);
- });
- }
- };
- const isClickEvent = e => e.type === 'click';
- const allowedEvents = ['copy'];
- const isReadOnlyAllowedEvent = e => contains$2(allowedEvents, e.type);
- const getAnchorHrefOpt = (editor, elm) => {
- const isRoot = elm => eq(elm, SugarElement.fromDom(editor.getBody()));
- return closest$3(elm, 'a', isRoot).bind(a => getOpt(a, 'href'));
- };
- const processReadonlyEvents = (editor, e) => {
- if (isClickEvent(e) && !VK.metaKeyPressed(e)) {
- const elm = SugarElement.fromDom(e.target);
- getAnchorHrefOpt(editor, elm).each(href => {
- e.preventDefault();
- if (/^#/.test(href)) {
- const targetEl = editor.dom.select(`${ href },[name="${ removeLeading(href, '#') }"]`);
- if (targetEl.length) {
- editor.selection.scrollIntoView(targetEl[0], true);
- }
- } else {
- window.open(href, '_blank', 'rel=noopener noreferrer,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes');
- }
- });
- } else if (isReadOnlyAllowedEvent(e)) {
- editor.dispatch(e.type, e);
- }
- };
- const registerReadOnlySelectionBlockers = editor => {
- editor.on('ShowCaret', e => {
- if (isReadOnly(editor)) {
- e.preventDefault();
- }
- });
- editor.on('ObjectSelected', e => {
- if (isReadOnly(editor)) {
- e.preventDefault();
- }
- });
- };
- const nativeEvents = Tools.makeMap('focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange ' + 'mouseout mouseenter mouseleave wheel keydown keypress keyup input beforeinput contextmenu dragstart dragend dragover ' + 'draggesture dragdrop drop drag submit ' + 'compositionstart compositionend compositionupdate touchstart touchmove touchend touchcancel', ' ');
- class EventDispatcher {
- constructor(settings) {
- this.bindings = {};
- this.settings = settings || {};
- this.scope = this.settings.scope || this;
- this.toggleEvent = this.settings.toggleEvent || never;
- }
- static isNative(name) {
- return !!nativeEvents[name.toLowerCase()];
- }
- fire(name, args) {
- return this.dispatch(name, args);
- }
- dispatch(name, args) {
- const lcName = name.toLowerCase();
- const event = normalize$3(lcName, args !== null && args !== void 0 ? args : {}, this.scope);
- if (this.settings.beforeFire) {
- this.settings.beforeFire(event);
- }
- const handlers = this.bindings[lcName];
- if (handlers) {
- for (let i = 0, l = handlers.length; i < l; i++) {
- const callback = handlers[i];
- if (callback.removed) {
- continue;
- }
- if (callback.once) {
- this.off(lcName, callback.func);
- }
- if (event.isImmediatePropagationStopped()) {
- return event;
- }
- if (callback.func.call(this.scope, event) === false) {
- event.preventDefault();
- return event;
- }
- }
- }
- return event;
- }
- on(name, callback, prepend, extra) {
- if (callback === false) {
- callback = never;
- }
- if (callback) {
- const wrappedCallback = {
- func: callback,
- removed: false
- };
- if (extra) {
- Tools.extend(wrappedCallback, extra);
- }
- const names = name.toLowerCase().split(' ');
- let i = names.length;
- while (i--) {
- const currentName = names[i];
- let handlers = this.bindings[currentName];
- if (!handlers) {
- handlers = [];
- this.toggleEvent(currentName, true);
- }
- if (prepend) {
- handlers = [
- wrappedCallback,
- ...handlers
- ];
- } else {
- handlers = [
- ...handlers,
- wrappedCallback
- ];
- }
- this.bindings[currentName] = handlers;
- }
- }
- return this;
- }
- off(name, callback) {
- if (name) {
- const names = name.toLowerCase().split(' ');
- let i = names.length;
- while (i--) {
- const currentName = names[i];
- let handlers = this.bindings[currentName];
- if (!currentName) {
- each$e(this.bindings, (_value, bindingName) => {
- this.toggleEvent(bindingName, false);
- delete this.bindings[bindingName];
- });
- return this;
- }
- if (handlers) {
- if (!callback) {
- handlers.length = 0;
- } else {
- const filteredHandlers = partition$2(handlers, handler => handler.func === callback);
- handlers = filteredHandlers.fail;
- this.bindings[currentName] = handlers;
- each$f(filteredHandlers.pass, handler => {
- handler.removed = true;
- });
- }
- if (!handlers.length) {
- this.toggleEvent(name, false);
- delete this.bindings[currentName];
- }
- }
- }
- } else {
- each$e(this.bindings, (_value, name) => {
- this.toggleEvent(name, false);
- });
- this.bindings = {};
- }
- return this;
- }
- once(name, callback, prepend) {
- return this.on(name, callback, prepend, { once: true });
- }
- has(name) {
- name = name.toLowerCase();
- return !(!this.bindings[name] || this.bindings[name].length === 0);
- }
- }
- const getEventDispatcher = obj => {
- if (!obj._eventDispatcher) {
- obj._eventDispatcher = new EventDispatcher({
- scope: obj,
- toggleEvent: (name, state) => {
- if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) {
- obj.toggleNativeEvent(name, state);
- }
- }
- });
- }
- return obj._eventDispatcher;
- };
- const Observable = {
- fire(name, args, bubble) {
- return this.dispatch(name, args, bubble);
- },
- dispatch(name, args, bubble) {
- const self = this;
- if (self.removed && name !== 'remove' && name !== 'detach') {
- return normalize$3(name.toLowerCase(), args !== null && args !== void 0 ? args : {}, self);
- }
- const dispatcherArgs = getEventDispatcher(self).dispatch(name, args);
- if (bubble !== false && self.parent) {
- let parent = self.parent();
- while (parent && !dispatcherArgs.isPropagationStopped()) {
- parent.dispatch(name, dispatcherArgs, false);
- parent = parent.parent();
- }
- }
- return dispatcherArgs;
- },
- on(name, callback, prepend) {
- return getEventDispatcher(this).on(name, callback, prepend);
- },
- off(name, callback) {
- return getEventDispatcher(this).off(name, callback);
- },
- once(name, callback) {
- return getEventDispatcher(this).once(name, callback);
- },
- hasEventListeners(name) {
- return getEventDispatcher(this).has(name);
- }
- };
- const DOM$2 = DOMUtils.DOM;
- let customEventRootDelegates;
- const getEventTarget = (editor, eventName) => {
- if (eventName === 'selectionchange') {
- return editor.getDoc();
- }
- if (!editor.inline && /^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(eventName)) {
- return editor.getDoc().documentElement;
- }
- const eventRoot = getEventRoot(editor);
- if (eventRoot) {
- if (!editor.eventRoot) {
- editor.eventRoot = DOM$2.select(eventRoot)[0];
- }
- return editor.eventRoot;
- }
- return editor.getBody();
- };
- const isListening = editor => !editor.hidden && !isReadOnly(editor);
- const fireEvent = (editor, eventName, e) => {
- if (isListening(editor)) {
- editor.dispatch(eventName, e);
- } else if (isReadOnly(editor)) {
- processReadonlyEvents(editor, e);
- }
- };
- const bindEventDelegate = (editor, eventName) => {
- let delegate;
- if (!editor.delegates) {
- editor.delegates = {};
- }
- if (editor.delegates[eventName] || editor.removed) {
- return;
- }
- const eventRootElm = getEventTarget(editor, eventName);
- if (getEventRoot(editor)) {
- if (!customEventRootDelegates) {
- customEventRootDelegates = {};
- editor.editorManager.on('removeEditor', () => {
- if (!editor.editorManager.activeEditor) {
- if (customEventRootDelegates) {
- each$e(customEventRootDelegates, (_value, name) => {
- editor.dom.unbind(getEventTarget(editor, name));
- });
- customEventRootDelegates = null;
- }
- }
- });
- }
- if (customEventRootDelegates[eventName]) {
- return;
- }
- delegate = e => {
- const target = e.target;
- const editors = editor.editorManager.get();
- let i = editors.length;
- while (i--) {
- const body = editors[i].getBody();
- if (body === target || DOM$2.isChildOf(target, body)) {
- fireEvent(editors[i], eventName, e);
- }
- }
- };
- customEventRootDelegates[eventName] = delegate;
- DOM$2.bind(eventRootElm, eventName, delegate);
- } else {
- delegate = e => {
- fireEvent(editor, eventName, e);
- };
- DOM$2.bind(eventRootElm, eventName, delegate);
- editor.delegates[eventName] = delegate;
- }
- };
- const EditorObservable = {
- ...Observable,
- bindPendingEventDelegates() {
- const self = this;
- Tools.each(self._pendingNativeEvents, name => {
- bindEventDelegate(self, name);
- });
- },
- toggleNativeEvent(name, state) {
- const self = this;
- if (name === 'focus' || name === 'blur') {
- return;
- }
- if (self.removed) {
- return;
- }
- if (state) {
- if (self.initialized) {
- bindEventDelegate(self, name);
- } else {
- if (!self._pendingNativeEvents) {
- self._pendingNativeEvents = [name];
- } else {
- self._pendingNativeEvents.push(name);
- }
- }
- } else if (self.initialized) {
- self.dom.unbind(getEventTarget(self, name), name, self.delegates[name]);
- delete self.delegates[name];
- }
- },
- unbindAllNativeEvents() {
- const self = this;
- const body = self.getBody();
- const dom = self.dom;
- if (self.delegates) {
- each$e(self.delegates, (value, name) => {
- self.dom.unbind(getEventTarget(self, name), name, value);
- });
- delete self.delegates;
- }
- if (!self.inline && body && dom) {
- body.onload = null;
- dom.unbind(self.getWin());
- dom.unbind(self.getDoc());
- }
- if (dom) {
- dom.unbind(body);
- dom.unbind(self.getContainer());
- }
- }
- };
- const stringListProcessor = value => {
- if (isString(value)) {
- return {
- value: value.split(/[ ,]/),
- valid: true
- };
- } else if (isArrayOf(value, isString)) {
- return {
- value,
- valid: true
- };
- } else {
- return {
- valid: false,
- message: `The value must be a string[] or a comma/space separated string.`
- };
- }
- };
- const getBuiltInProcessor = type => {
- const validator = (() => {
- switch (type) {
- case 'array':
- return isArray$1;
- case 'boolean':
- return isBoolean;
- case 'function':
- return isFunction;
- case 'number':
- return isNumber;
- case 'object':
- return isObject;
- case 'string':
- return isString;
- case 'string[]':
- return stringListProcessor;
- case 'object[]':
- return val => isArrayOf(val, isObject);
- case 'regexp':
- return val => is$4(val, RegExp);
- }
- })();
- return value => processValue(value, validator, `The value must be a ${ type }.`);
- };
- const isBuiltInSpec = spec => isString(spec.processor);
- const getErrorMessage = (message, result) => {
- const additionalText = isEmpty$3(result.message) ? '' : `. ${ result.message }`;
- return message + additionalText;
- };
- const isValidResult = result => result.valid;
- const processValue = (value, processor, message = '') => {
- const result = processor(value);
- if (isBoolean(result)) {
- return result ? {
- value: value,
- valid: true
- } : {
- valid: false,
- message
- };
- } else {
- return result;
- }
- };
- const processDefaultValue = (name, defaultValue, processor) => {
- if (!isUndefined(defaultValue)) {
- const result = processValue(defaultValue, processor);
- if (isValidResult(result)) {
- return result.value;
- } else {
- console.error(getErrorMessage(`Invalid default value passed for the "${ name }" option`, result));
- }
- }
- return undefined;
- };
- const create$5 = (editor, initialOptions) => {
- const registry = {};
- const values = {};
- const setValue = (name, value, processor) => {
- const result = processValue(value, processor);
- if (isValidResult(result)) {
- values[name] = result.value;
- return true;
- } else {
- console.warn(getErrorMessage(`Invalid value passed for the ${ name } option`, result));
- return false;
- }
- };
- const register = (name, spec) => {
- const processor = isBuiltInSpec(spec) ? getBuiltInProcessor(spec.processor) : spec.processor;
- const defaultValue = processDefaultValue(name, spec.default, processor);
- registry[name] = {
- ...spec,
- default: defaultValue,
- processor
- };
- const initValue = get$a(values, name).orThunk(() => get$a(initialOptions, name));
- initValue.each(value => setValue(name, value, processor));
- };
- const isRegistered = name => has$2(registry, name);
- const get = name => get$a(values, name).orThunk(() => get$a(registry, name).map(spec => spec.default)).getOrUndefined();
- const set = (name, value) => {
- if (!isRegistered(name)) {
- console.warn(`"${ name }" is not a registered option. Ensure the option has been registered before setting a value.`);
- return false;
- } else {
- const spec = registry[name];
- if (spec.immutable) {
- console.error(`"${ name }" is an immutable option and cannot be updated`);
- return false;
- } else {
- return setValue(name, value, spec.processor);
- }
- }
- };
- const unset = name => {
- const registered = isRegistered(name);
- if (registered) {
- delete values[name];
- }
- return registered;
- };
- const isSet = name => has$2(values, name);
- return {
- register,
- isRegistered,
- get,
- set,
- unset,
- isSet
- };
- };
- const defaultModes = [
- 'design',
- 'readonly'
- ];
- const switchToMode = (editor, activeMode, availableModes, mode) => {
- const oldMode = availableModes[activeMode.get()];
- const newMode = availableModes[mode];
- try {
- newMode.activate();
- } catch (e) {
- console.error(`problem while activating editor mode ${ mode }:`, e);
- return;
- }
- oldMode.deactivate();
- if (oldMode.editorReadOnly !== newMode.editorReadOnly) {
- toggleReadOnly(editor, newMode.editorReadOnly);
- }
- activeMode.set(mode);
- fireSwitchMode(editor, mode);
- };
- const setMode = (editor, availableModes, activeMode, mode) => {
- if (mode === activeMode.get()) {
- return;
- } else if (!has$2(availableModes, mode)) {
- throw new Error(`Editor mode '${ mode }' is invalid`);
- }
- if (editor.initialized) {
- switchToMode(editor, activeMode, availableModes, mode);
- } else {
- editor.on('init', () => switchToMode(editor, activeMode, availableModes, mode));
- }
- };
- const registerMode = (availableModes, mode, api) => {
- if (contains$2(defaultModes, mode)) {
- throw new Error(`Cannot override default mode ${ mode }`);
- }
- return {
- ...availableModes,
- [mode]: {
- ...api,
- deactivate: () => {
- try {
- api.deactivate();
- } catch (e) {
- console.error(`problem while deactivating editor mode ${ mode }:`, e);
- }
- }
- }
- };
- };
- const create$4 = editor => {
- const activeMode = Cell('design');
- const availableModes = Cell({
- design: {
- activate: noop,
- deactivate: noop,
- editorReadOnly: false
- },
- readonly: {
- activate: noop,
- deactivate: noop,
- editorReadOnly: true
- }
- });
- registerReadOnlyContentFilters(editor);
- registerReadOnlySelectionBlockers(editor);
- return {
- isReadOnly: () => isReadOnly(editor),
- set: mode => setMode(editor, availableModes.get(), activeMode, mode),
- get: () => activeMode.get(),
- register: (mode, api) => {
- availableModes.set(registerMode(availableModes.get(), mode, api));
- }
- };
- };
- const each$2 = Tools.each, explode = Tools.explode;
- const keyCodeLookup = {
- f1: 112,
- f2: 113,
- f3: 114,
- f4: 115,
- f5: 116,
- f6: 117,
- f7: 118,
- f8: 119,
- f9: 120,
- f10: 121,
- f11: 122,
- f12: 123
- };
- const modifierNames = Tools.makeMap('alt,ctrl,shift,meta,access');
- const parseShortcut = pattern => {
- let key;
- const shortcut = {};
- const isMac = Env.os.isMacOS() || Env.os.isiOS();
- each$2(explode(pattern.toLowerCase(), '+'), value => {
- if (value in modifierNames) {
- shortcut[value] = true;
- } else {
- if (/^[0-9]{2,}$/.test(value)) {
- shortcut.keyCode = parseInt(value, 10);
- } else {
- shortcut.charCode = value.charCodeAt(0);
- shortcut.keyCode = keyCodeLookup[value] || value.toUpperCase().charCodeAt(0);
- }
- }
- });
- const id = [shortcut.keyCode];
- for (key in modifierNames) {
- if (shortcut[key]) {
- id.push(key);
- } else {
- shortcut[key] = false;
- }
- }
- shortcut.id = id.join(',');
- if (shortcut.access) {
- shortcut.alt = true;
- if (isMac) {
- shortcut.ctrl = true;
- } else {
- shortcut.shift = true;
- }
- }
- if (shortcut.meta) {
- if (isMac) {
- shortcut.meta = true;
- } else {
- shortcut.ctrl = true;
- shortcut.meta = false;
- }
- }
- return shortcut;
- };
- class Shortcuts {
- constructor(editor) {
- this.shortcuts = {};
- this.pendingPatterns = [];
- this.editor = editor;
- const self = this;
- editor.on('keyup keypress keydown', e => {
- if ((self.hasModifier(e) || self.isFunctionKey(e)) && !e.isDefaultPrevented()) {
- each$2(self.shortcuts, shortcut => {
- if (self.matchShortcut(e, shortcut)) {
- self.pendingPatterns = shortcut.subpatterns.slice(0);
- if (e.type === 'keydown') {
- self.executeShortcutAction(shortcut);
- }
- return true;
- }
- });
- if (self.matchShortcut(e, self.pendingPatterns[0])) {
- if (self.pendingPatterns.length === 1) {
- if (e.type === 'keydown') {
- self.executeShortcutAction(self.pendingPatterns[0]);
- }
- }
- self.pendingPatterns.shift();
- }
- }
- });
- }
- add(pattern, desc, cmdFunc, scope) {
- const self = this;
- const func = self.normalizeCommandFunc(cmdFunc);
- each$2(explode(Tools.trim(pattern)), pattern => {
- const shortcut = self.createShortcut(pattern, desc, func, scope);
- self.shortcuts[shortcut.id] = shortcut;
- });
- return true;
- }
- remove(pattern) {
- const shortcut = this.createShortcut(pattern);
- if (this.shortcuts[shortcut.id]) {
- delete this.shortcuts[shortcut.id];
- return true;
- }
- return false;
- }
- normalizeCommandFunc(cmdFunc) {
- const self = this;
- const cmd = cmdFunc;
- if (typeof cmd === 'string') {
- return () => {
- self.editor.execCommand(cmd, false, null);
- };
- } else if (Tools.isArray(cmd)) {
- return () => {
- self.editor.execCommand(cmd[0], cmd[1], cmd[2]);
- };
- } else {
- return cmd;
- }
- }
- createShortcut(pattern, desc, cmdFunc, scope) {
- const shortcuts = Tools.map(explode(pattern, '>'), parseShortcut);
- shortcuts[shortcuts.length - 1] = Tools.extend(shortcuts[shortcuts.length - 1], {
- func: cmdFunc,
- scope: scope || this.editor
- });
- return Tools.extend(shortcuts[0], {
- desc: this.editor.translate(desc),
- subpatterns: shortcuts.slice(1)
- });
- }
- hasModifier(e) {
- return e.altKey || e.ctrlKey || e.metaKey;
- }
- isFunctionKey(e) {
- return e.type === 'keydown' && e.keyCode >= 112 && e.keyCode <= 123;
- }
- matchShortcut(e, shortcut) {
- if (!shortcut) {
- return false;
- }
- if (shortcut.ctrl !== e.ctrlKey || shortcut.meta !== e.metaKey) {
- return false;
- }
- if (shortcut.alt !== e.altKey || shortcut.shift !== e.shiftKey) {
- return false;
- }
- if (e.keyCode === shortcut.keyCode || e.charCode && e.charCode === shortcut.charCode) {
- e.preventDefault();
- return true;
- }
- return false;
- }
- executeShortcutAction(shortcut) {
- return shortcut.func ? shortcut.func.call(shortcut.scope) : null;
- }
- }
- const create$3 = () => {
- const buttons = {};
- const menuItems = {};
- const popups = {};
- const icons = {};
- const contextMenus = {};
- const contextToolbars = {};
- const sidebars = {};
- const add = (collection, type) => (name, spec) => collection[name.toLowerCase()] = {
- ...spec,
- type
- };
- const addIcon = (name, svgData) => icons[name.toLowerCase()] = svgData;
- return {
- addButton: add(buttons, 'button'),
- addGroupToolbarButton: add(buttons, 'grouptoolbarbutton'),
- addToggleButton: add(buttons, 'togglebutton'),
- addMenuButton: add(buttons, 'menubutton'),
- addSplitButton: add(buttons, 'splitbutton'),
- addMenuItem: add(menuItems, 'menuitem'),
- addNestedMenuItem: add(menuItems, 'nestedmenuitem'),
- addToggleMenuItem: add(menuItems, 'togglemenuitem'),
- addAutocompleter: add(popups, 'autocompleter'),
- addContextMenu: add(contextMenus, 'contextmenu'),
- addContextToolbar: add(contextToolbars, 'contexttoolbar'),
- addContextForm: add(contextToolbars, 'contextform'),
- addSidebar: add(sidebars, 'sidebar'),
- addIcon,
- getAll: () => ({
- buttons,
- menuItems,
- icons,
- popups,
- contextMenus,
- contextToolbars,
- sidebars
- })
- };
- };
- const registry = () => {
- const bridge = create$3();
- return {
- addAutocompleter: bridge.addAutocompleter,
- addButton: bridge.addButton,
- addContextForm: bridge.addContextForm,
- addContextMenu: bridge.addContextMenu,
- addContextToolbar: bridge.addContextToolbar,
- addIcon: bridge.addIcon,
- addMenuButton: bridge.addMenuButton,
- addMenuItem: bridge.addMenuItem,
- addNestedMenuItem: bridge.addNestedMenuItem,
- addSidebar: bridge.addSidebar,
- addSplitButton: bridge.addSplitButton,
- addToggleButton: bridge.addToggleButton,
- addGroupToolbarButton: bridge.addGroupToolbarButton,
- addToggleMenuItem: bridge.addToggleMenuItem,
- getAll: bridge.getAll
- };
- };
- const DOM$1 = DOMUtils.DOM;
- const extend = Tools.extend, each$1 = Tools.each;
- class Editor {
- constructor(id, options, editorManager) {
- this.plugins = {};
- this.contentCSS = [];
- this.contentStyles = [];
- this.loadedCSS = {};
- this.isNotDirty = false;
- this.editorManager = editorManager;
- this.documentBaseUrl = editorManager.documentBaseURL;
- extend(this, EditorObservable);
- const self = this;
- this.id = id;
- this.hidden = false;
- const normalizedOptions = normalizeOptions(editorManager.defaultOptions, options);
- this.options = create$5(self, normalizedOptions);
- register$7(self);
- const getOption = this.options.get;
- if (getOption('deprecation_warnings')) {
- logWarnings(options, normalizedOptions);
- }
- const suffix = getOption('suffix');
- if (suffix) {
- editorManager.suffix = suffix;
- }
- this.suffix = editorManager.suffix;
- const baseUrl = getOption('base_url');
- if (baseUrl) {
- editorManager._setBaseUrl(baseUrl);
- }
- this.baseUri = editorManager.baseURI;
- const referrerPolicy = getReferrerPolicy(self);
- if (referrerPolicy) {
- ScriptLoader.ScriptLoader._setReferrerPolicy(referrerPolicy);
- DOMUtils.DOM.styleSheetLoader._setReferrerPolicy(referrerPolicy);
- }
- AddOnManager.languageLoad = getOption('language_load');
- AddOnManager.baseURL = editorManager.baseURL;
- this.setDirty(false);
- this.documentBaseURI = new URI(getDocumentBaseUrl(self), { base_uri: this.baseUri });
- this.baseURI = this.baseUri;
- this.inline = isInline(self);
- this.shortcuts = new Shortcuts(this);
- this.editorCommands = new EditorCommands(this);
- registerCommands(this);
- const cacheSuffix = getOption('cache_suffix');
- if (cacheSuffix) {
- Env.cacheSuffix = cacheSuffix.replace(/^[\?\&]+/, '');
- }
- this.ui = {
- registry: registry(),
- styleSheetLoader: undefined,
- show: noop,
- hide: noop,
- setEnabled: noop,
- isEnabled: always
- };
- this.mode = create$4(self);
- editorManager.dispatch('SetupEditor', { editor: this });
- const setupCallback = getSetupCallback(self);
- if (isFunction(setupCallback)) {
- setupCallback.call(self, self);
- }
- }
- render() {
- render(this);
- }
- focus(skipFocus) {
- this.execCommand('mceFocus', false, skipFocus);
- }
- hasFocus() {
- return hasFocus(this);
- }
- translate(text) {
- return I18n.translate(text);
- }
- getParam(name, defaultVal, type) {
- const options = this.options;
- if (!options.isRegistered(name)) {
- if (isNonNullable(type)) {
- options.register(name, {
- processor: type,
- default: defaultVal
- });
- } else {
- options.register(name, {
- processor: always,
- default: defaultVal
- });
- }
- }
- return !options.isSet(name) && !isUndefined(defaultVal) ? defaultVal : options.get(name);
- }
- hasPlugin(name, loaded) {
- const hasPlugin = contains$2(getPlugins(this), name);
- if (hasPlugin) {
- return loaded ? PluginManager.get(name) !== undefined : true;
- } else {
- return false;
- }
- }
- nodeChanged(args) {
- this._nodeChangeDispatcher.nodeChanged(args);
- }
- addCommand(name, callback, scope) {
- this.editorCommands.addCommand(name, callback, scope);
- }
- addQueryStateHandler(name, callback, scope) {
- this.editorCommands.addQueryStateHandler(name, callback, scope);
- }
- addQueryValueHandler(name, callback, scope) {
- this.editorCommands.addQueryValueHandler(name, callback, scope);
- }
- addShortcut(pattern, desc, cmdFunc, scope) {
- this.shortcuts.add(pattern, desc, cmdFunc, scope);
- }
- execCommand(cmd, ui, value, args) {
- return this.editorCommands.execCommand(cmd, ui, value, args);
- }
- queryCommandState(cmd) {
- return this.editorCommands.queryCommandState(cmd);
- }
- queryCommandValue(cmd) {
- return this.editorCommands.queryCommandValue(cmd);
- }
- queryCommandSupported(cmd) {
- return this.editorCommands.queryCommandSupported(cmd);
- }
- show() {
- const self = this;
- if (self.hidden) {
- self.hidden = false;
- if (self.inline) {
- self.getBody().contentEditable = 'true';
- } else {
- DOM$1.show(self.getContainer());
- DOM$1.hide(self.id);
- }
- self.load();
- self.dispatch('show');
- }
- }
- hide() {
- const self = this;
- if (!self.hidden) {
- self.save();
- if (self.inline) {
- self.getBody().contentEditable = 'false';
- if (self === self.editorManager.focusedEditor) {
- self.editorManager.focusedEditor = null;
- }
- } else {
- DOM$1.hide(self.getContainer());
- DOM$1.setStyle(self.id, 'display', self.orgDisplay);
- }
- self.hidden = true;
- self.dispatch('hide');
- }
- }
- isHidden() {
- return this.hidden;
- }
- setProgressState(state, time) {
- this.dispatch('ProgressState', {
- state,
- time
- });
- }
- load(args) {
- const self = this;
- let elm = self.getElement(), html;
- if (self.removed) {
- return '';
- }
- if (elm) {
- args = args || {};
- args.load = true;
- const value = isTextareaOrInput(elm) ? elm.value : elm.innerHTML;
- html = self.setContent(value, args);
- args.element = elm;
- if (!args.no_events) {
- self.dispatch('LoadContent', args);
- }
- args.element = elm = null;
- return html;
- }
- }
- save(args) {
- const self = this;
- let elm = self.getElement(), html, form;
- if (!elm || !self.initialized || self.removed) {
- return;
- }
- args = args || {};
- args.save = true;
- args.element = elm;
- html = args.content = self.getContent(args);
- if (!args.no_events) {
- self.dispatch('SaveContent', args);
- }
- if (args.format === 'raw') {
- self.dispatch('RawSaveContent', args);
- }
- html = args.content;
- if (!isTextareaOrInput(elm)) {
- if (args.is_removing || !self.inline) {
- elm.innerHTML = html;
- }
- if (form = DOM$1.getParent(self.id, 'form')) {
- each$1(form.elements, elm => {
- if (elm.name === self.id) {
- elm.value = html;
- return false;
- }
- });
- }
- } else {
- elm.value = html;
- }
- args.element = elm = null;
- if (args.set_dirty !== false) {
- self.setDirty(false);
- }
- return html;
- }
- setContent(content, args) {
- return setContent(this, content, args);
- }
- getContent(args) {
- return getContent(this, args);
- }
- insertContent(content, args) {
- if (args) {
- content = extend({ content }, args);
- }
- this.execCommand('mceInsertContent', false, content);
- }
- resetContent(initialContent) {
- if (initialContent === undefined) {
- setContent(this, this.startContent, { format: 'raw' });
- } else {
- setContent(this, initialContent);
- }
- this.undoManager.reset();
- this.setDirty(false);
- this.nodeChanged();
- }
- isDirty() {
- return !this.isNotDirty;
- }
- setDirty(state) {
- const oldState = !this.isNotDirty;
- this.isNotDirty = !state;
- if (state && state !== oldState) {
- this.dispatch('dirty');
- }
- }
- getContainer() {
- const self = this;
- if (!self.container) {
- self.container = DOM$1.get(self.editorContainer || self.id + '_parent');
- }
- return self.container;
- }
- getContentAreaContainer() {
- return this.contentAreaContainer;
- }
- getElement() {
- if (!this.targetElm) {
- this.targetElm = DOM$1.get(this.id);
- }
- return this.targetElm;
- }
- getWin() {
- const self = this;
- let elm;
- if (!self.contentWindow) {
- elm = self.iframeElement;
- if (elm) {
- self.contentWindow = elm.contentWindow;
- }
- }
- return self.contentWindow;
- }
- getDoc() {
- const self = this;
- let win;
- if (!self.contentDocument) {
- win = self.getWin();
- if (win) {
- self.contentDocument = win.document;
- }
- }
- return self.contentDocument;
- }
- getBody() {
- const doc = this.getDoc();
- return this.bodyElement || (doc ? doc.body : null);
- }
- convertURL(url, name, elm) {
- const self = this, getOption = self.options.get;
- const urlConverterCallback = getUrlConverterCallback(self);
- if (isFunction(urlConverterCallback)) {
- return urlConverterCallback.call(self, url, elm, true, name);
- }
- if (!getOption('convert_urls') || elm && elm.nodeName === 'LINK' || url.indexOf('file:') === 0 || url.length === 0) {
- return url;
- }
- if (getOption('relative_urls')) {
- return self.documentBaseURI.toRelative(url);
- }
- url = self.documentBaseURI.toAbsolute(url, getOption('remove_script_host'));
- return url;
- }
- addVisual(elm) {
- addVisual(this, elm);
- }
- remove() {
- remove$1(this);
- }
- destroy(automatic) {
- destroy(this, automatic);
- }
- uploadImages() {
- return this.editorUpload.uploadImages();
- }
- _scanForImages() {
- return this.editorUpload.scanForImages();
- }
- }
- const DOM = DOMUtils.DOM;
- const each = Tools.each;
- let boundGlobalEvents = false;
- let beforeUnloadDelegate;
- let editors = [];
- const globalEventDelegate = e => {
- const type = e.type;
- each(EditorManager.get(), editor => {
- switch (type) {
- case 'scroll':
- editor.dispatch('ScrollWindow', e);
- break;
- case 'resize':
- editor.dispatch('ResizeWindow', e);
- break;
- }
- });
- };
- const toggleGlobalEvents = state => {
- if (state !== boundGlobalEvents) {
- const DOM = DOMUtils.DOM;
- if (state) {
- DOM.bind(window, 'resize', globalEventDelegate);
- DOM.bind(window, 'scroll', globalEventDelegate);
- } else {
- DOM.unbind(window, 'resize', globalEventDelegate);
- DOM.unbind(window, 'scroll', globalEventDelegate);
- }
- boundGlobalEvents = state;
- }
- };
- const removeEditorFromList = targetEditor => {
- const oldEditors = editors;
- editors = filter$6(editors, editor => {
- return targetEditor !== editor;
- });
- if (EditorManager.activeEditor === targetEditor) {
- EditorManager.activeEditor = editors.length > 0 ? editors[0] : null;
- }
- if (EditorManager.focusedEditor === targetEditor) {
- EditorManager.focusedEditor = null;
- }
- return oldEditors.length !== editors.length;
- };
- const purgeDestroyedEditor = editor => {
- if (editor && editor.initialized && !(editor.getContainer() || editor.getBody()).parentNode) {
- removeEditorFromList(editor);
- editor.unbindAllNativeEvents();
- editor.destroy(true);
- editor.removed = true;
- editor = null;
- }
- return editor;
- };
- const isQuirksMode = document.compatMode !== 'CSS1Compat';
- const EditorManager = {
- ...Observable,
- baseURI: null,
- baseURL: null,
- defaultOptions: {},
- documentBaseURL: null,
- suffix: null,
- majorVersion: '6',
- minorVersion: '1.0',
- releaseDate: '2022-06-29',
- i18n: I18n,
- activeEditor: null,
- focusedEditor: null,
- setup() {
- const self = this;
- let baseURL, documentBaseURL, suffix = '';
- documentBaseURL = URI.getDocumentBaseUrl(document.location);
- if (/^[^:]+:\/\/\/?[^\/]+\//.test(documentBaseURL)) {
- documentBaseURL = documentBaseURL.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
- if (!/[\/\\]$/.test(documentBaseURL)) {
- documentBaseURL += '/';
- }
- }
- const preInit = window.tinymce || window.tinyMCEPreInit;
- if (preInit) {
- baseURL = preInit.base || preInit.baseURL;
- suffix = preInit.suffix;
- } else {
- const scripts = document.getElementsByTagName('script');
- for (let i = 0; i < scripts.length; i++) {
- const src = scripts[i].src || '';
- if (src === '') {
- continue;
- }
- const srcScript = src.substring(src.lastIndexOf('/'));
- if (/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
- if (srcScript.indexOf('.min') !== -1) {
- suffix = '.min';
- }
- baseURL = src.substring(0, src.lastIndexOf('/'));
- break;
- }
- }
- if (!baseURL && document.currentScript) {
- const src = document.currentScript.src;
- if (src.indexOf('.min') !== -1) {
- suffix = '.min';
- }
- baseURL = src.substring(0, src.lastIndexOf('/'));
- }
- }
- self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL);
- self.documentBaseURL = documentBaseURL;
- self.baseURI = new URI(self.baseURL);
- self.suffix = suffix;
- setup$v(self);
- },
- overrideDefaults(defaultOptions) {
- const baseUrl = defaultOptions.base_url;
- if (baseUrl) {
- this._setBaseUrl(baseUrl);
- }
- const suffix = defaultOptions.suffix;
- if (defaultOptions.suffix) {
- this.suffix = suffix;
- }
- this.defaultOptions = defaultOptions;
- const pluginBaseUrls = defaultOptions.plugin_base_urls;
- if (pluginBaseUrls !== undefined) {
- each$e(pluginBaseUrls, (pluginBaseUrl, pluginName) => {
- AddOnManager.PluginManager.urls[pluginName] = pluginBaseUrl;
- });
- }
- },
- init(options) {
- const self = this;
- let result;
- const invalidInlineTargets = Tools.makeMap('area base basefont br col frame hr img input isindex link meta param embed source wbr track ' + 'colgroup option table tbody tfoot thead tr th td script noscript style textarea video audio iframe object menu', ' ');
- const isInvalidInlineTarget = (options, elm) => options.inline && elm.tagName.toLowerCase() in invalidInlineTargets;
- const createId = elm => {
- let id = elm.id;
- if (!id) {
- id = get$a(elm, 'name').filter(name => !DOM.get(name)).getOrThunk(DOM.uniqueId);
- elm.setAttribute('id', id);
- }
- return id;
- };
- const execCallback = name => {
- const callback = options[name];
- if (!callback) {
- return;
- }
- return callback.apply(self, []);
- };
- const findTargets = options => {
- if (Env.browser.isIE() || Env.browser.isEdge()) {
- initError('TinyMCE does not support the browser you are using. For a list of supported' + ' browsers please see: https://www.tiny.cloud/docs/tinymce/6/support/#supportedwebbrowsers');
- return [];
- } else if (isQuirksMode) {
- initError('Failed to initialize the editor as the document is not in standards mode. ' + 'TinyMCE requires standards mode.');
- return [];
- } else if (isString(options.selector)) {
- return DOM.select(options.selector);
- } else if (isNonNullable(options.target)) {
- return [options.target];
- } else {
- return [];
- }
- };
- let provideResults = editors => {
- result = editors;
- };
- const initEditors = () => {
- let initCount = 0;
- const editors = [];
- let targets;
- const createEditor = (id, options, targetElm) => {
- const editor = new Editor(id, options, self);
- editors.push(editor);
- editor.on('init', () => {
- if (++initCount === targets.length) {
- provideResults(editors);
- }
- });
- editor.targetElm = editor.targetElm || targetElm;
- editor.render();
- };
- DOM.unbind(window, 'ready', initEditors);
- execCallback('onpageload');
- targets = unique$1(findTargets(options));
- Tools.each(targets, elm => {
- purgeDestroyedEditor(self.get(elm.id));
- });
- targets = Tools.grep(targets, elm => {
- return !self.get(elm.id);
- });
- if (targets.length === 0) {
- provideResults([]);
- } else {
- each(targets, elm => {
- if (isInvalidInlineTarget(options, elm)) {
- initError('Could not initialize inline editor on invalid inline target element', elm);
- } else {
- createEditor(createId(elm), options, elm);
- }
- });
- }
- };
- DOM.bind(window, 'ready', initEditors);
- return new Promise(resolve => {
- if (result) {
- resolve(result);
- } else {
- provideResults = editors => {
- resolve(editors);
- };
- }
- });
- },
- get(id) {
- if (arguments.length === 0) {
- return editors.slice(0);
- } else if (isString(id)) {
- return find$2(editors, editor => {
- return editor.id === id;
- }).getOr(null);
- } else if (isNumber(id)) {
- return editors[id] ? editors[id] : null;
- } else {
- return null;
- }
- },
- add(editor) {
- const self = this;
- const existingEditor = self.get(editor.id);
- if (existingEditor === editor) {
- return editor;
- }
- if (existingEditor === null) {
- editors.push(editor);
- }
- toggleGlobalEvents(true);
- self.activeEditor = editor;
- self.dispatch('AddEditor', { editor });
- if (!beforeUnloadDelegate) {
- beforeUnloadDelegate = e => {
- const event = self.dispatch('BeforeUnload');
- if (event.returnValue) {
- e.preventDefault();
- e.returnValue = event.returnValue;
- return event.returnValue;
- }
- };
- window.addEventListener('beforeunload', beforeUnloadDelegate);
- }
- return editor;
- },
- createEditor(id, options) {
- return this.add(new Editor(id, options, this));
- },
- remove(selector) {
- const self = this;
- let i, editor;
- if (!selector) {
- for (i = editors.length - 1; i >= 0; i--) {
- self.remove(editors[i]);
- }
- return;
- }
- if (isString(selector)) {
- each(DOM.select(selector), elm => {
- editor = self.get(elm.id);
- if (editor) {
- self.remove(editor);
- }
- });
- return;
- }
- editor = selector;
- if (isNull(self.get(editor.id))) {
- return null;
- }
- if (removeEditorFromList(editor)) {
- self.dispatch('RemoveEditor', { editor });
- }
- if (editors.length === 0) {
- window.removeEventListener('beforeunload', beforeUnloadDelegate);
- }
- editor.remove();
- toggleGlobalEvents(editors.length > 0);
- return editor;
- },
- execCommand(cmd, ui, value) {
- var _a;
- const self = this;
- const editorId = isObject(value) ? (_a = value.id) !== null && _a !== void 0 ? _a : value.index : value;
- switch (cmd) {
- case 'mceAddEditor': {
- if (!self.get(editorId)) {
- const editorOptions = value.options;
- new Editor(editorId, editorOptions, self).render();
- }
- return true;
- }
- case 'mceRemoveEditor': {
- const editor = self.get(editorId);
- if (editor) {
- editor.remove();
- }
- return true;
- }
- case 'mceToggleEditor': {
- const editor = self.get(editorId);
- if (!editor) {
- self.execCommand('mceAddEditor', false, value);
- return true;
- }
- if (editor.isHidden()) {
- editor.show();
- } else {
- editor.hide();
- }
- return true;
- }
- }
- if (self.activeEditor) {
- return self.activeEditor.execCommand(cmd, ui, value);
- }
- return false;
- },
- triggerSave: () => {
- each(editors, editor => {
- editor.save();
- });
- },
- addI18n: (code, items) => {
- I18n.add(code, items);
- },
- translate: text => {
- return I18n.translate(text);
- },
- setActive(editor) {
- const activeEditor = this.activeEditor;
- if (this.activeEditor !== editor) {
- if (activeEditor) {
- activeEditor.dispatch('deactivate', { relatedTarget: editor });
- }
- editor.dispatch('activate', { relatedTarget: activeEditor });
- }
- this.activeEditor = editor;
- },
- _setBaseUrl(baseUrl) {
- this.baseURL = new URI(this.documentBaseURL).toAbsolute(baseUrl.replace(/\/+$/, ''));
- this.baseURI = new URI(this.baseURL);
- }
- };
- EditorManager.setup();
- const setup = () => {
- const dataValue = value$2();
- const FakeClipboardItem = items => ({
- items,
- types: keys(items),
- getType: type => get$a(items, type).getOrUndefined()
- });
- const write = data => {
- dataValue.set(data);
- };
- const read = () => dataValue.get().getOrUndefined();
- const clear = dataValue.clear;
- return {
- FakeClipboardItem,
- write,
- read,
- clear
- };
- };
- const FakeClipboard = setup();
- const min = Math.min, max = Math.max, round = Math.round;
- const relativePosition = (rect, targetRect, rel) => {
- let x = targetRect.x;
- let y = targetRect.y;
- const w = rect.w;
- const h = rect.h;
- const targetW = targetRect.w;
- const targetH = targetRect.h;
- const relChars = (rel || '').split('');
- if (relChars[0] === 'b') {
- y += targetH;
- }
- if (relChars[1] === 'r') {
- x += targetW;
- }
- if (relChars[0] === 'c') {
- y += round(targetH / 2);
- }
- if (relChars[1] === 'c') {
- x += round(targetW / 2);
- }
- if (relChars[3] === 'b') {
- y -= h;
- }
- if (relChars[4] === 'r') {
- x -= w;
- }
- if (relChars[3] === 'c') {
- y -= round(h / 2);
- }
- if (relChars[4] === 'c') {
- x -= round(w / 2);
- }
- return create$2(x, y, w, h);
- };
- const findBestRelativePosition = (rect, targetRect, constrainRect, rels) => {
- let pos, i;
- for (i = 0; i < rels.length; i++) {
- pos = relativePosition(rect, targetRect, rels[i]);
- if (pos.x >= constrainRect.x && pos.x + pos.w <= constrainRect.w + constrainRect.x && pos.y >= constrainRect.y && pos.y + pos.h <= constrainRect.h + constrainRect.y) {
- return rels[i];
- }
- }
- return null;
- };
- const inflate = (rect, w, h) => {
- return create$2(rect.x - w, rect.y - h, rect.w + w * 2, rect.h + h * 2);
- };
- const intersect = (rect, cropRect) => {
- const x1 = max(rect.x, cropRect.x);
- const y1 = max(rect.y, cropRect.y);
- const x2 = min(rect.x + rect.w, cropRect.x + cropRect.w);
- const y2 = min(rect.y + rect.h, cropRect.y + cropRect.h);
- if (x2 - x1 < 0 || y2 - y1 < 0) {
- return null;
- }
- return create$2(x1, y1, x2 - x1, y2 - y1);
- };
- const clamp = (rect, clampRect, fixedSize) => {
- let x1 = rect.x;
- let y1 = rect.y;
- let x2 = rect.x + rect.w;
- let y2 = rect.y + rect.h;
- const cx2 = clampRect.x + clampRect.w;
- const cy2 = clampRect.y + clampRect.h;
- const underflowX1 = max(0, clampRect.x - x1);
- const underflowY1 = max(0, clampRect.y - y1);
- const overflowX2 = max(0, x2 - cx2);
- const overflowY2 = max(0, y2 - cy2);
- x1 += underflowX1;
- y1 += underflowY1;
- if (fixedSize) {
- x2 += underflowX1;
- y2 += underflowY1;
- x1 -= overflowX2;
- y1 -= overflowY2;
- }
- x2 -= overflowX2;
- y2 -= overflowY2;
- return create$2(x1, y1, x2 - x1, y2 - y1);
- };
- const create$2 = (x, y, w, h) => {
- return {
- x,
- y,
- w,
- h
- };
- };
- const fromClientRect = clientRect => {
- return create$2(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
- };
- const Rect = {
- inflate,
- relativePosition,
- findBestRelativePosition,
- intersect,
- clamp,
- create: create$2,
- fromClientRect
- };
- const awaiter = (resolveCb, rejectCb, timeout = 1000) => {
- let done = false;
- let timer = null;
- const complete = completer => (...args) => {
- if (!done) {
- done = true;
- if (timer !== null) {
- clearTimeout(timer);
- timer = null;
- }
- completer.apply(null, args);
- }
- };
- const resolve = complete(resolveCb);
- const reject = complete(rejectCb);
- const start = (...args) => {
- if (!done && timer === null) {
- timer = setTimeout(() => reject.apply(null, args), timeout);
- }
- };
- return {
- start,
- resolve,
- reject
- };
- };
- const create$1 = () => {
- const tasks = {};
- const resultFns = {};
- const load = (id, url) => {
- const loadErrMsg = `Script at URL "${ url }" failed to load`;
- const runErrMsg = `Script at URL "${ url }" did not call \`tinymce.Resource.add('${ id }', data)\` within 1 second`;
- if (tasks[id] !== undefined) {
- return tasks[id];
- } else {
- const task = new Promise((resolve, reject) => {
- const waiter = awaiter(resolve, reject);
- resultFns[id] = waiter.resolve;
- ScriptLoader.ScriptLoader.loadScript(url).then(() => waiter.start(runErrMsg), () => waiter.reject(loadErrMsg));
- });
- tasks[id] = task;
- return task;
- }
- };
- const add = (id, data) => {
- if (resultFns[id] !== undefined) {
- resultFns[id](data);
- delete resultFns[id];
- }
- tasks[id] = Promise.resolve(data);
- };
- const unload = id => {
- delete tasks[id];
- };
- return {
- load,
- add,
- unload
- };
- };
- const Resource = create$1();
- const create = () => (() => {
- let data = {};
- let keys = [];
- const storage = {
- getItem: key => {
- const item = data[key];
- return item ? item : null;
- },
- setItem: (key, value) => {
- keys.push(key);
- data[key] = String(value);
- },
- key: index => {
- return keys[index];
- },
- removeItem: key => {
- keys = keys.filter(k => k === key);
- delete data[key];
- },
- clear: () => {
- keys = [];
- data = {};
- },
- length: 0
- };
- Object.defineProperty(storage, 'length', {
- get: () => keys.length,
- configurable: false,
- enumerable: false
- });
- return storage;
- })();
- let localStorage;
- try {
- const test = '__storage_test__';
- localStorage = window.localStorage;
- localStorage.setItem(test, test);
- localStorage.removeItem(test);
- } catch (e) {
- localStorage = create();
- }
- var LocalStorage = localStorage;
- const publicApi = {
- geom: { Rect },
- util: {
- Delay,
- Tools,
- VK,
- URI,
- EventDispatcher,
- Observable,
- I18n,
- LocalStorage,
- ImageUploader
- },
- dom: {
- EventUtils,
- TreeWalker: DomTreeWalker,
- TextSeeker,
- DOMUtils,
- ScriptLoader,
- RangeUtils,
- Serializer: DomSerializer,
- StyleSheetLoader,
- ControlSelection,
- BookmarkManager,
- Selection: EditorSelection,
- Event: EventUtils.Event
- },
- html: {
- Styles,
- Entities,
- Node: AstNode,
- Schema,
- DomParser,
- Writer,
- Serializer: HtmlSerializer
- },
- Env,
- AddOnManager,
- Annotator,
- Formatter,
- UndoManager,
- EditorCommands,
- WindowManager,
- NotificationManager,
- EditorObservable,
- Shortcuts,
- Editor,
- FocusManager,
- EditorManager,
- DOM: DOMUtils.DOM,
- ScriptLoader: ScriptLoader.ScriptLoader,
- PluginManager,
- ThemeManager,
- ModelManager,
- IconManager,
- Resource,
- FakeClipboard,
- trim: Tools.trim,
- isArray: Tools.isArray,
- is: Tools.is,
- toArray: Tools.toArray,
- makeMap: Tools.makeMap,
- each: Tools.each,
- map: Tools.map,
- grep: Tools.grep,
- inArray: Tools.inArray,
- extend: Tools.extend,
- walk: Tools.walk,
- resolve: Tools.resolve,
- explode: Tools.explode,
- _addCacheSuffix: Tools._addCacheSuffix
- };
- const tinymce = Tools.extend(EditorManager, publicApi);
- const exportToModuleLoaders = tinymce => {
- if (typeof module === 'object') {
- try {
- module.exports = tinymce;
- } catch (_) {
- }
- }
- };
- const exportToWindowGlobal = tinymce => {
- window.tinymce = tinymce;
- window.tinyMCE = tinymce;
- };
- exportToWindowGlobal(tinymce);
- exportToModuleLoaders(tinymce);
- })();
|