Nenhuma descrição

Draft-a5afe13a.js 567KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698
  1. 'use strict';
  2. require('react');
  3. var _commonjsHelpers = require('./_commonjsHelpers-72d386ba.js');
  4. require('react-dom');
  5. var _reactDom_commonjsExternal = require('./_react-dom_commonjs-external-55867475.js');
  6. /*
  7. object-assign
  8. (c) Sindre Sorhus
  9. @license MIT
  10. */
  11. /* eslint-disable no-unused-vars */
  12. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  13. var hasOwnProperty = Object.prototype.hasOwnProperty;
  14. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  15. function toObject(val) {
  16. if (val === null || val === undefined) {
  17. throw new TypeError('Object.assign cannot be called with null or undefined');
  18. }
  19. return Object(val);
  20. }
  21. function shouldUseNative() {
  22. try {
  23. if (!Object.assign) {
  24. return false;
  25. }
  26. // Detect buggy property enumeration order in older V8 versions.
  27. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  28. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  29. test1[5] = 'de';
  30. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  31. return false;
  32. }
  33. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  34. var test2 = {};
  35. for (var i = 0; i < 10; i++) {
  36. test2['_' + String.fromCharCode(i)] = i;
  37. }
  38. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  39. return test2[n];
  40. });
  41. if (order2.join('') !== '0123456789') {
  42. return false;
  43. }
  44. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  45. var test3 = {};
  46. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  47. test3[letter] = letter;
  48. });
  49. if (Object.keys(Object.assign({}, test3)).join('') !==
  50. 'abcdefghijklmnopqrst') {
  51. return false;
  52. }
  53. return true;
  54. } catch (err) {
  55. // We don't expect any of the above to throw, but better to be safe.
  56. return false;
  57. }
  58. }
  59. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  60. var from;
  61. var to = toObject(target);
  62. var symbols;
  63. for (var s = 1; s < arguments.length; s++) {
  64. from = Object(arguments[s]);
  65. for (var key in from) {
  66. if (hasOwnProperty.call(from, key)) {
  67. to[key] = from[key];
  68. }
  69. }
  70. if (getOwnPropertySymbols) {
  71. symbols = getOwnPropertySymbols(from);
  72. for (var i = 0; i < symbols.length; i++) {
  73. if (propIsEnumerable.call(from, symbols[i])) {
  74. to[symbols[i]] = from[symbols[i]];
  75. }
  76. }
  77. }
  78. }
  79. return to;
  80. };
  81. var immutable = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  82. /**
  83. * Copyright (c) 2014-2015, Facebook, Inc.
  84. * All rights reserved.
  85. *
  86. * This source code is licensed under the BSD-style license found in the
  87. * LICENSE file in the root directory of this source tree. An additional grant
  88. * of patent rights can be found in the PATENTS file in the same directory.
  89. */
  90. (function (global, factory) {
  91. module.exports = factory() ;
  92. }(_commonjsHelpers.commonjsGlobal, function () {var SLICE$0 = Array.prototype.slice;
  93. function createClass(ctor, superClass) {
  94. if (superClass) {
  95. ctor.prototype = Object.create(superClass.prototype);
  96. }
  97. ctor.prototype.constructor = ctor;
  98. }
  99. function Iterable(value) {
  100. return isIterable(value) ? value : Seq(value);
  101. }
  102. createClass(KeyedIterable, Iterable);
  103. function KeyedIterable(value) {
  104. return isKeyed(value) ? value : KeyedSeq(value);
  105. }
  106. createClass(IndexedIterable, Iterable);
  107. function IndexedIterable(value) {
  108. return isIndexed(value) ? value : IndexedSeq(value);
  109. }
  110. createClass(SetIterable, Iterable);
  111. function SetIterable(value) {
  112. return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
  113. }
  114. function isIterable(maybeIterable) {
  115. return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
  116. }
  117. function isKeyed(maybeKeyed) {
  118. return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
  119. }
  120. function isIndexed(maybeIndexed) {
  121. return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
  122. }
  123. function isAssociative(maybeAssociative) {
  124. return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
  125. }
  126. function isOrdered(maybeOrdered) {
  127. return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
  128. }
  129. Iterable.isIterable = isIterable;
  130. Iterable.isKeyed = isKeyed;
  131. Iterable.isIndexed = isIndexed;
  132. Iterable.isAssociative = isAssociative;
  133. Iterable.isOrdered = isOrdered;
  134. Iterable.Keyed = KeyedIterable;
  135. Iterable.Indexed = IndexedIterable;
  136. Iterable.Set = SetIterable;
  137. var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  138. var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  139. var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  140. var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  141. // Used for setting prototype methods that IE8 chokes on.
  142. var DELETE = 'delete';
  143. // Constants describing the size of trie nodes.
  144. var SHIFT = 5; // Resulted in best performance after ______?
  145. var SIZE = 1 << SHIFT;
  146. var MASK = SIZE - 1;
  147. // A consistent shared value representing "not set" which equals nothing other
  148. // than itself, and nothing that could be provided externally.
  149. var NOT_SET = {};
  150. // Boolean references, Rough equivalent of `bool &`.
  151. var CHANGE_LENGTH = { value: false };
  152. var DID_ALTER = { value: false };
  153. function MakeRef(ref) {
  154. ref.value = false;
  155. return ref;
  156. }
  157. function SetRef(ref) {
  158. ref && (ref.value = true);
  159. }
  160. // A function which returns a value representing an "owner" for transient writes
  161. // to tries. The return value will only ever equal itself, and will not equal
  162. // the return of any subsequent call of this function.
  163. function OwnerID() {}
  164. // http://jsperf.com/copy-array-inline
  165. function arrCopy(arr, offset) {
  166. offset = offset || 0;
  167. var len = Math.max(0, arr.length - offset);
  168. var newArr = new Array(len);
  169. for (var ii = 0; ii < len; ii++) {
  170. newArr[ii] = arr[ii + offset];
  171. }
  172. return newArr;
  173. }
  174. function ensureSize(iter) {
  175. if (iter.size === undefined) {
  176. iter.size = iter.__iterate(returnTrue);
  177. }
  178. return iter.size;
  179. }
  180. function wrapIndex(iter, index) {
  181. // This implements "is array index" which the ECMAString spec defines as:
  182. //
  183. // A String property name P is an array index if and only if
  184. // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
  185. // to 2^32−1.
  186. //
  187. // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
  188. if (typeof index !== 'number') {
  189. var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
  190. if ('' + uint32Index !== index || uint32Index === 4294967295) {
  191. return NaN;
  192. }
  193. index = uint32Index;
  194. }
  195. return index < 0 ? ensureSize(iter) + index : index;
  196. }
  197. function returnTrue() {
  198. return true;
  199. }
  200. function wholeSlice(begin, end, size) {
  201. return (begin === 0 || (size !== undefined && begin <= -size)) &&
  202. (end === undefined || (size !== undefined && end >= size));
  203. }
  204. function resolveBegin(begin, size) {
  205. return resolveIndex(begin, size, 0);
  206. }
  207. function resolveEnd(end, size) {
  208. return resolveIndex(end, size, size);
  209. }
  210. function resolveIndex(index, size, defaultIndex) {
  211. return index === undefined ?
  212. defaultIndex :
  213. index < 0 ?
  214. Math.max(0, size + index) :
  215. size === undefined ?
  216. index :
  217. Math.min(size, index);
  218. }
  219. /* global Symbol */
  220. var ITERATE_KEYS = 0;
  221. var ITERATE_VALUES = 1;
  222. var ITERATE_ENTRIES = 2;
  223. var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  224. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  225. var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
  226. function Iterator(next) {
  227. this.next = next;
  228. }
  229. Iterator.prototype.toString = function() {
  230. return '[Iterator]';
  231. };
  232. Iterator.KEYS = ITERATE_KEYS;
  233. Iterator.VALUES = ITERATE_VALUES;
  234. Iterator.ENTRIES = ITERATE_ENTRIES;
  235. Iterator.prototype.inspect =
  236. Iterator.prototype.toSource = function () { return this.toString(); };
  237. Iterator.prototype[ITERATOR_SYMBOL] = function () {
  238. return this;
  239. };
  240. function iteratorValue(type, k, v, iteratorResult) {
  241. var value = type === 0 ? k : type === 1 ? v : [k, v];
  242. iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
  243. value: value, done: false
  244. });
  245. return iteratorResult;
  246. }
  247. function iteratorDone() {
  248. return { value: undefined, done: true };
  249. }
  250. function hasIterator(maybeIterable) {
  251. return !!getIteratorFn(maybeIterable);
  252. }
  253. function isIterator(maybeIterator) {
  254. return maybeIterator && typeof maybeIterator.next === 'function';
  255. }
  256. function getIterator(iterable) {
  257. var iteratorFn = getIteratorFn(iterable);
  258. return iteratorFn && iteratorFn.call(iterable);
  259. }
  260. function getIteratorFn(iterable) {
  261. var iteratorFn = iterable && (
  262. (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
  263. iterable[FAUX_ITERATOR_SYMBOL]
  264. );
  265. if (typeof iteratorFn === 'function') {
  266. return iteratorFn;
  267. }
  268. }
  269. function isArrayLike(value) {
  270. return value && typeof value.length === 'number';
  271. }
  272. createClass(Seq, Iterable);
  273. function Seq(value) {
  274. return value === null || value === undefined ? emptySequence() :
  275. isIterable(value) ? value.toSeq() : seqFromValue(value);
  276. }
  277. Seq.of = function(/*...values*/) {
  278. return Seq(arguments);
  279. };
  280. Seq.prototype.toSeq = function() {
  281. return this;
  282. };
  283. Seq.prototype.toString = function() {
  284. return this.__toString('Seq {', '}');
  285. };
  286. Seq.prototype.cacheResult = function() {
  287. if (!this._cache && this.__iterateUncached) {
  288. this._cache = this.entrySeq().toArray();
  289. this.size = this._cache.length;
  290. }
  291. return this;
  292. };
  293. // abstract __iterateUncached(fn, reverse)
  294. Seq.prototype.__iterate = function(fn, reverse) {
  295. return seqIterate(this, fn, reverse, true);
  296. };
  297. // abstract __iteratorUncached(type, reverse)
  298. Seq.prototype.__iterator = function(type, reverse) {
  299. return seqIterator(this, type, reverse, true);
  300. };
  301. createClass(KeyedSeq, Seq);
  302. function KeyedSeq(value) {
  303. return value === null || value === undefined ?
  304. emptySequence().toKeyedSeq() :
  305. isIterable(value) ?
  306. (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
  307. keyedSeqFromValue(value);
  308. }
  309. KeyedSeq.prototype.toKeyedSeq = function() {
  310. return this;
  311. };
  312. createClass(IndexedSeq, Seq);
  313. function IndexedSeq(value) {
  314. return value === null || value === undefined ? emptySequence() :
  315. !isIterable(value) ? indexedSeqFromValue(value) :
  316. isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
  317. }
  318. IndexedSeq.of = function(/*...values*/) {
  319. return IndexedSeq(arguments);
  320. };
  321. IndexedSeq.prototype.toIndexedSeq = function() {
  322. return this;
  323. };
  324. IndexedSeq.prototype.toString = function() {
  325. return this.__toString('Seq [', ']');
  326. };
  327. IndexedSeq.prototype.__iterate = function(fn, reverse) {
  328. return seqIterate(this, fn, reverse, false);
  329. };
  330. IndexedSeq.prototype.__iterator = function(type, reverse) {
  331. return seqIterator(this, type, reverse, false);
  332. };
  333. createClass(SetSeq, Seq);
  334. function SetSeq(value) {
  335. return (
  336. value === null || value === undefined ? emptySequence() :
  337. !isIterable(value) ? indexedSeqFromValue(value) :
  338. isKeyed(value) ? value.entrySeq() : value
  339. ).toSetSeq();
  340. }
  341. SetSeq.of = function(/*...values*/) {
  342. return SetSeq(arguments);
  343. };
  344. SetSeq.prototype.toSetSeq = function() {
  345. return this;
  346. };
  347. Seq.isSeq = isSeq;
  348. Seq.Keyed = KeyedSeq;
  349. Seq.Set = SetSeq;
  350. Seq.Indexed = IndexedSeq;
  351. var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
  352. Seq.prototype[IS_SEQ_SENTINEL] = true;
  353. createClass(ArraySeq, IndexedSeq);
  354. function ArraySeq(array) {
  355. this._array = array;
  356. this.size = array.length;
  357. }
  358. ArraySeq.prototype.get = function(index, notSetValue) {
  359. return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
  360. };
  361. ArraySeq.prototype.__iterate = function(fn, reverse) {
  362. var array = this._array;
  363. var maxIndex = array.length - 1;
  364. for (var ii = 0; ii <= maxIndex; ii++) {
  365. if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
  366. return ii + 1;
  367. }
  368. }
  369. return ii;
  370. };
  371. ArraySeq.prototype.__iterator = function(type, reverse) {
  372. var array = this._array;
  373. var maxIndex = array.length - 1;
  374. var ii = 0;
  375. return new Iterator(function()
  376. {return ii > maxIndex ?
  377. iteratorDone() :
  378. iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
  379. );
  380. };
  381. createClass(ObjectSeq, KeyedSeq);
  382. function ObjectSeq(object) {
  383. var keys = Object.keys(object);
  384. this._object = object;
  385. this._keys = keys;
  386. this.size = keys.length;
  387. }
  388. ObjectSeq.prototype.get = function(key, notSetValue) {
  389. if (notSetValue !== undefined && !this.has(key)) {
  390. return notSetValue;
  391. }
  392. return this._object[key];
  393. };
  394. ObjectSeq.prototype.has = function(key) {
  395. return this._object.hasOwnProperty(key);
  396. };
  397. ObjectSeq.prototype.__iterate = function(fn, reverse) {
  398. var object = this._object;
  399. var keys = this._keys;
  400. var maxIndex = keys.length - 1;
  401. for (var ii = 0; ii <= maxIndex; ii++) {
  402. var key = keys[reverse ? maxIndex - ii : ii];
  403. if (fn(object[key], key, this) === false) {
  404. return ii + 1;
  405. }
  406. }
  407. return ii;
  408. };
  409. ObjectSeq.prototype.__iterator = function(type, reverse) {
  410. var object = this._object;
  411. var keys = this._keys;
  412. var maxIndex = keys.length - 1;
  413. var ii = 0;
  414. return new Iterator(function() {
  415. var key = keys[reverse ? maxIndex - ii : ii];
  416. return ii++ > maxIndex ?
  417. iteratorDone() :
  418. iteratorValue(type, key, object[key]);
  419. });
  420. };
  421. ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
  422. createClass(IterableSeq, IndexedSeq);
  423. function IterableSeq(iterable) {
  424. this._iterable = iterable;
  425. this.size = iterable.length || iterable.size;
  426. }
  427. IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
  428. if (reverse) {
  429. return this.cacheResult().__iterate(fn, reverse);
  430. }
  431. var iterable = this._iterable;
  432. var iterator = getIterator(iterable);
  433. var iterations = 0;
  434. if (isIterator(iterator)) {
  435. var step;
  436. while (!(step = iterator.next()).done) {
  437. if (fn(step.value, iterations++, this) === false) {
  438. break;
  439. }
  440. }
  441. }
  442. return iterations;
  443. };
  444. IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
  445. if (reverse) {
  446. return this.cacheResult().__iterator(type, reverse);
  447. }
  448. var iterable = this._iterable;
  449. var iterator = getIterator(iterable);
  450. if (!isIterator(iterator)) {
  451. return new Iterator(iteratorDone);
  452. }
  453. var iterations = 0;
  454. return new Iterator(function() {
  455. var step = iterator.next();
  456. return step.done ? step : iteratorValue(type, iterations++, step.value);
  457. });
  458. };
  459. createClass(IteratorSeq, IndexedSeq);
  460. function IteratorSeq(iterator) {
  461. this._iterator = iterator;
  462. this._iteratorCache = [];
  463. }
  464. IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
  465. if (reverse) {
  466. return this.cacheResult().__iterate(fn, reverse);
  467. }
  468. var iterator = this._iterator;
  469. var cache = this._iteratorCache;
  470. var iterations = 0;
  471. while (iterations < cache.length) {
  472. if (fn(cache[iterations], iterations++, this) === false) {
  473. return iterations;
  474. }
  475. }
  476. var step;
  477. while (!(step = iterator.next()).done) {
  478. var val = step.value;
  479. cache[iterations] = val;
  480. if (fn(val, iterations++, this) === false) {
  481. break;
  482. }
  483. }
  484. return iterations;
  485. };
  486. IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
  487. if (reverse) {
  488. return this.cacheResult().__iterator(type, reverse);
  489. }
  490. var iterator = this._iterator;
  491. var cache = this._iteratorCache;
  492. var iterations = 0;
  493. return new Iterator(function() {
  494. if (iterations >= cache.length) {
  495. var step = iterator.next();
  496. if (step.done) {
  497. return step;
  498. }
  499. cache[iterations] = step.value;
  500. }
  501. return iteratorValue(type, iterations, cache[iterations++]);
  502. });
  503. };
  504. // # pragma Helper functions
  505. function isSeq(maybeSeq) {
  506. return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
  507. }
  508. var EMPTY_SEQ;
  509. function emptySequence() {
  510. return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
  511. }
  512. function keyedSeqFromValue(value) {
  513. var seq =
  514. Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
  515. isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
  516. hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
  517. typeof value === 'object' ? new ObjectSeq(value) :
  518. undefined;
  519. if (!seq) {
  520. throw new TypeError(
  521. 'Expected Array or iterable object of [k, v] entries, '+
  522. 'or keyed object: ' + value
  523. );
  524. }
  525. return seq;
  526. }
  527. function indexedSeqFromValue(value) {
  528. var seq = maybeIndexedSeqFromValue(value);
  529. if (!seq) {
  530. throw new TypeError(
  531. 'Expected Array or iterable object of values: ' + value
  532. );
  533. }
  534. return seq;
  535. }
  536. function seqFromValue(value) {
  537. var seq = maybeIndexedSeqFromValue(value) ||
  538. (typeof value === 'object' && new ObjectSeq(value));
  539. if (!seq) {
  540. throw new TypeError(
  541. 'Expected Array or iterable object of values, or keyed object: ' + value
  542. );
  543. }
  544. return seq;
  545. }
  546. function maybeIndexedSeqFromValue(value) {
  547. return (
  548. isArrayLike(value) ? new ArraySeq(value) :
  549. isIterator(value) ? new IteratorSeq(value) :
  550. hasIterator(value) ? new IterableSeq(value) :
  551. undefined
  552. );
  553. }
  554. function seqIterate(seq, fn, reverse, useKeys) {
  555. var cache = seq._cache;
  556. if (cache) {
  557. var maxIndex = cache.length - 1;
  558. for (var ii = 0; ii <= maxIndex; ii++) {
  559. var entry = cache[reverse ? maxIndex - ii : ii];
  560. if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
  561. return ii + 1;
  562. }
  563. }
  564. return ii;
  565. }
  566. return seq.__iterateUncached(fn, reverse);
  567. }
  568. function seqIterator(seq, type, reverse, useKeys) {
  569. var cache = seq._cache;
  570. if (cache) {
  571. var maxIndex = cache.length - 1;
  572. var ii = 0;
  573. return new Iterator(function() {
  574. var entry = cache[reverse ? maxIndex - ii : ii];
  575. return ii++ > maxIndex ?
  576. iteratorDone() :
  577. iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
  578. });
  579. }
  580. return seq.__iteratorUncached(type, reverse);
  581. }
  582. function fromJS(json, converter) {
  583. return converter ?
  584. fromJSWith(converter, json, '', {'': json}) :
  585. fromJSDefault(json);
  586. }
  587. function fromJSWith(converter, json, key, parentJSON) {
  588. if (Array.isArray(json)) {
  589. return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  590. }
  591. if (isPlainObj(json)) {
  592. return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
  593. }
  594. return json;
  595. }
  596. function fromJSDefault(json) {
  597. if (Array.isArray(json)) {
  598. return IndexedSeq(json).map(fromJSDefault).toList();
  599. }
  600. if (isPlainObj(json)) {
  601. return KeyedSeq(json).map(fromJSDefault).toMap();
  602. }
  603. return json;
  604. }
  605. function isPlainObj(value) {
  606. return value && (value.constructor === Object || value.constructor === undefined);
  607. }
  608. /**
  609. * An extension of the "same-value" algorithm as [described for use by ES6 Map
  610. * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
  611. *
  612. * NaN is considered the same as NaN, however -0 and 0 are considered the same
  613. * value, which is different from the algorithm described by
  614. * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
  615. *
  616. * This is extended further to allow Objects to describe the values they
  617. * represent, by way of `valueOf` or `equals` (and `hashCode`).
  618. *
  619. * Note: because of this extension, the key equality of Immutable.Map and the
  620. * value equality of Immutable.Set will differ from ES6 Map and Set.
  621. *
  622. * ### Defining custom values
  623. *
  624. * The easiest way to describe the value an object represents is by implementing
  625. * `valueOf`. For example, `Date` represents a value by returning a unix
  626. * timestamp for `valueOf`:
  627. *
  628. * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
  629. * var date2 = new Date(1234567890000);
  630. * date1.valueOf(); // 1234567890000
  631. * assert( date1 !== date2 );
  632. * assert( Immutable.is( date1, date2 ) );
  633. *
  634. * Note: overriding `valueOf` may have other implications if you use this object
  635. * where JavaScript expects a primitive, such as implicit string coercion.
  636. *
  637. * For more complex types, especially collections, implementing `valueOf` may
  638. * not be performant. An alternative is to implement `equals` and `hashCode`.
  639. *
  640. * `equals` takes another object, presumably of similar type, and returns true
  641. * if the it is equal. Equality is symmetrical, so the same result should be
  642. * returned if this and the argument are flipped.
  643. *
  644. * assert( a.equals(b) === b.equals(a) );
  645. *
  646. * `hashCode` returns a 32bit integer number representing the object which will
  647. * be used to determine how to store the value object in a Map or Set. You must
  648. * provide both or neither methods, one must not exist without the other.
  649. *
  650. * Also, an important relationship between these methods must be upheld: if two
  651. * values are equal, they *must* return the same hashCode. If the values are not
  652. * equal, they might have the same hashCode; this is called a hash collision,
  653. * and while undesirable for performance reasons, it is acceptable.
  654. *
  655. * if (a.equals(b)) {
  656. * assert( a.hashCode() === b.hashCode() );
  657. * }
  658. *
  659. * All Immutable collections implement `equals` and `hashCode`.
  660. *
  661. */
  662. function is(valueA, valueB) {
  663. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  664. return true;
  665. }
  666. if (!valueA || !valueB) {
  667. return false;
  668. }
  669. if (typeof valueA.valueOf === 'function' &&
  670. typeof valueB.valueOf === 'function') {
  671. valueA = valueA.valueOf();
  672. valueB = valueB.valueOf();
  673. if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
  674. return true;
  675. }
  676. if (!valueA || !valueB) {
  677. return false;
  678. }
  679. }
  680. if (typeof valueA.equals === 'function' &&
  681. typeof valueB.equals === 'function' &&
  682. valueA.equals(valueB)) {
  683. return true;
  684. }
  685. return false;
  686. }
  687. function deepEqual(a, b) {
  688. if (a === b) {
  689. return true;
  690. }
  691. if (
  692. !isIterable(b) ||
  693. a.size !== undefined && b.size !== undefined && a.size !== b.size ||
  694. a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
  695. isKeyed(a) !== isKeyed(b) ||
  696. isIndexed(a) !== isIndexed(b) ||
  697. isOrdered(a) !== isOrdered(b)
  698. ) {
  699. return false;
  700. }
  701. if (a.size === 0 && b.size === 0) {
  702. return true;
  703. }
  704. var notAssociative = !isAssociative(a);
  705. if (isOrdered(a)) {
  706. var entries = a.entries();
  707. return b.every(function(v, k) {
  708. var entry = entries.next().value;
  709. return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
  710. }) && entries.next().done;
  711. }
  712. var flipped = false;
  713. if (a.size === undefined) {
  714. if (b.size === undefined) {
  715. if (typeof a.cacheResult === 'function') {
  716. a.cacheResult();
  717. }
  718. } else {
  719. flipped = true;
  720. var _ = a;
  721. a = b;
  722. b = _;
  723. }
  724. }
  725. var allEqual = true;
  726. var bSize = b.__iterate(function(v, k) {
  727. if (notAssociative ? !a.has(v) :
  728. flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
  729. allEqual = false;
  730. return false;
  731. }
  732. });
  733. return allEqual && a.size === bSize;
  734. }
  735. createClass(Repeat, IndexedSeq);
  736. function Repeat(value, times) {
  737. if (!(this instanceof Repeat)) {
  738. return new Repeat(value, times);
  739. }
  740. this._value = value;
  741. this.size = times === undefined ? Infinity : Math.max(0, times);
  742. if (this.size === 0) {
  743. if (EMPTY_REPEAT) {
  744. return EMPTY_REPEAT;
  745. }
  746. EMPTY_REPEAT = this;
  747. }
  748. }
  749. Repeat.prototype.toString = function() {
  750. if (this.size === 0) {
  751. return 'Repeat []';
  752. }
  753. return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
  754. };
  755. Repeat.prototype.get = function(index, notSetValue) {
  756. return this.has(index) ? this._value : notSetValue;
  757. };
  758. Repeat.prototype.includes = function(searchValue) {
  759. return is(this._value, searchValue);
  760. };
  761. Repeat.prototype.slice = function(begin, end) {
  762. var size = this.size;
  763. return wholeSlice(begin, end, size) ? this :
  764. new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
  765. };
  766. Repeat.prototype.reverse = function() {
  767. return this;
  768. };
  769. Repeat.prototype.indexOf = function(searchValue) {
  770. if (is(this._value, searchValue)) {
  771. return 0;
  772. }
  773. return -1;
  774. };
  775. Repeat.prototype.lastIndexOf = function(searchValue) {
  776. if (is(this._value, searchValue)) {
  777. return this.size;
  778. }
  779. return -1;
  780. };
  781. Repeat.prototype.__iterate = function(fn, reverse) {
  782. for (var ii = 0; ii < this.size; ii++) {
  783. if (fn(this._value, ii, this) === false) {
  784. return ii + 1;
  785. }
  786. }
  787. return ii;
  788. };
  789. Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
  790. var ii = 0;
  791. return new Iterator(function()
  792. {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
  793. );
  794. };
  795. Repeat.prototype.equals = function(other) {
  796. return other instanceof Repeat ?
  797. is(this._value, other._value) :
  798. deepEqual(other);
  799. };
  800. var EMPTY_REPEAT;
  801. function invariant(condition, error) {
  802. if (!condition) throw new Error(error);
  803. }
  804. createClass(Range, IndexedSeq);
  805. function Range(start, end, step) {
  806. if (!(this instanceof Range)) {
  807. return new Range(start, end, step);
  808. }
  809. invariant(step !== 0, 'Cannot step a Range by 0');
  810. start = start || 0;
  811. if (end === undefined) {
  812. end = Infinity;
  813. }
  814. step = step === undefined ? 1 : Math.abs(step);
  815. if (end < start) {
  816. step = -step;
  817. }
  818. this._start = start;
  819. this._end = end;
  820. this._step = step;
  821. this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
  822. if (this.size === 0) {
  823. if (EMPTY_RANGE) {
  824. return EMPTY_RANGE;
  825. }
  826. EMPTY_RANGE = this;
  827. }
  828. }
  829. Range.prototype.toString = function() {
  830. if (this.size === 0) {
  831. return 'Range []';
  832. }
  833. return 'Range [ ' +
  834. this._start + '...' + this._end +
  835. (this._step > 1 ? ' by ' + this._step : '') +
  836. ' ]';
  837. };
  838. Range.prototype.get = function(index, notSetValue) {
  839. return this.has(index) ?
  840. this._start + wrapIndex(this, index) * this._step :
  841. notSetValue;
  842. };
  843. Range.prototype.includes = function(searchValue) {
  844. var possibleIndex = (searchValue - this._start) / this._step;
  845. return possibleIndex >= 0 &&
  846. possibleIndex < this.size &&
  847. possibleIndex === Math.floor(possibleIndex);
  848. };
  849. Range.prototype.slice = function(begin, end) {
  850. if (wholeSlice(begin, end, this.size)) {
  851. return this;
  852. }
  853. begin = resolveBegin(begin, this.size);
  854. end = resolveEnd(end, this.size);
  855. if (end <= begin) {
  856. return new Range(0, 0);
  857. }
  858. return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
  859. };
  860. Range.prototype.indexOf = function(searchValue) {
  861. var offsetValue = searchValue - this._start;
  862. if (offsetValue % this._step === 0) {
  863. var index = offsetValue / this._step;
  864. if (index >= 0 && index < this.size) {
  865. return index
  866. }
  867. }
  868. return -1;
  869. };
  870. Range.prototype.lastIndexOf = function(searchValue) {
  871. return this.indexOf(searchValue);
  872. };
  873. Range.prototype.__iterate = function(fn, reverse) {
  874. var maxIndex = this.size - 1;
  875. var step = this._step;
  876. var value = reverse ? this._start + maxIndex * step : this._start;
  877. for (var ii = 0; ii <= maxIndex; ii++) {
  878. if (fn(value, ii, this) === false) {
  879. return ii + 1;
  880. }
  881. value += reverse ? -step : step;
  882. }
  883. return ii;
  884. };
  885. Range.prototype.__iterator = function(type, reverse) {
  886. var maxIndex = this.size - 1;
  887. var step = this._step;
  888. var value = reverse ? this._start + maxIndex * step : this._start;
  889. var ii = 0;
  890. return new Iterator(function() {
  891. var v = value;
  892. value += reverse ? -step : step;
  893. return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
  894. });
  895. };
  896. Range.prototype.equals = function(other) {
  897. return other instanceof Range ?
  898. this._start === other._start &&
  899. this._end === other._end &&
  900. this._step === other._step :
  901. deepEqual(this, other);
  902. };
  903. var EMPTY_RANGE;
  904. createClass(Collection, Iterable);
  905. function Collection() {
  906. throw TypeError('Abstract');
  907. }
  908. createClass(KeyedCollection, Collection);function KeyedCollection() {}
  909. createClass(IndexedCollection, Collection);function IndexedCollection() {}
  910. createClass(SetCollection, Collection);function SetCollection() {}
  911. Collection.Keyed = KeyedCollection;
  912. Collection.Indexed = IndexedCollection;
  913. Collection.Set = SetCollection;
  914. var imul =
  915. typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
  916. Math.imul :
  917. function imul(a, b) {
  918. a = a | 0; // int
  919. b = b | 0; // int
  920. var c = a & 0xffff;
  921. var d = b & 0xffff;
  922. // Shift by 0 fixes the sign on the high part.
  923. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
  924. };
  925. // v8 has an optimization for storing 31-bit signed numbers.
  926. // Values which have either 00 or 11 as the high order bits qualify.
  927. // This function drops the highest order bit in a signed number, maintaining
  928. // the sign bit.
  929. function smi(i32) {
  930. return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
  931. }
  932. function hash(o) {
  933. if (o === false || o === null || o === undefined) {
  934. return 0;
  935. }
  936. if (typeof o.valueOf === 'function') {
  937. o = o.valueOf();
  938. if (o === false || o === null || o === undefined) {
  939. return 0;
  940. }
  941. }
  942. if (o === true) {
  943. return 1;
  944. }
  945. var type = typeof o;
  946. if (type === 'number') {
  947. var h = o | 0;
  948. if (h !== o) {
  949. h ^= o * 0xFFFFFFFF;
  950. }
  951. while (o > 0xFFFFFFFF) {
  952. o /= 0xFFFFFFFF;
  953. h ^= o;
  954. }
  955. return smi(h);
  956. }
  957. if (type === 'string') {
  958. return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
  959. }
  960. if (typeof o.hashCode === 'function') {
  961. return o.hashCode();
  962. }
  963. if (type === 'object') {
  964. return hashJSObj(o);
  965. }
  966. if (typeof o.toString === 'function') {
  967. return hashString(o.toString());
  968. }
  969. throw new Error('Value type ' + type + ' cannot be hashed.');
  970. }
  971. function cachedHashString(string) {
  972. var hash = stringHashCache[string];
  973. if (hash === undefined) {
  974. hash = hashString(string);
  975. if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
  976. STRING_HASH_CACHE_SIZE = 0;
  977. stringHashCache = {};
  978. }
  979. STRING_HASH_CACHE_SIZE++;
  980. stringHashCache[string] = hash;
  981. }
  982. return hash;
  983. }
  984. // http://jsperf.com/hashing-strings
  985. function hashString(string) {
  986. // This is the hash from JVM
  987. // The hash code for a string is computed as
  988. // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  989. // where s[i] is the ith character of the string and n is the length of
  990. // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  991. // (exclusive) by dropping high bits.
  992. var hash = 0;
  993. for (var ii = 0; ii < string.length; ii++) {
  994. hash = 31 * hash + string.charCodeAt(ii) | 0;
  995. }
  996. return smi(hash);
  997. }
  998. function hashJSObj(obj) {
  999. var hash;
  1000. if (usingWeakMap) {
  1001. hash = weakMap.get(obj);
  1002. if (hash !== undefined) {
  1003. return hash;
  1004. }
  1005. }
  1006. hash = obj[UID_HASH_KEY];
  1007. if (hash !== undefined) {
  1008. return hash;
  1009. }
  1010. if (!canDefineProperty) {
  1011. hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
  1012. if (hash !== undefined) {
  1013. return hash;
  1014. }
  1015. hash = getIENodeHash(obj);
  1016. if (hash !== undefined) {
  1017. return hash;
  1018. }
  1019. }
  1020. hash = ++objHashUID;
  1021. if (objHashUID & 0x40000000) {
  1022. objHashUID = 0;
  1023. }
  1024. if (usingWeakMap) {
  1025. weakMap.set(obj, hash);
  1026. } else if (isExtensible !== undefined && isExtensible(obj) === false) {
  1027. throw new Error('Non-extensible objects are not allowed as keys.');
  1028. } else if (canDefineProperty) {
  1029. Object.defineProperty(obj, UID_HASH_KEY, {
  1030. 'enumerable': false,
  1031. 'configurable': false,
  1032. 'writable': false,
  1033. 'value': hash
  1034. });
  1035. } else if (obj.propertyIsEnumerable !== undefined &&
  1036. obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
  1037. // Since we can't define a non-enumerable property on the object
  1038. // we'll hijack one of the less-used non-enumerable properties to
  1039. // save our hash on it. Since this is a function it will not show up in
  1040. // `JSON.stringify` which is what we want.
  1041. obj.propertyIsEnumerable = function() {
  1042. return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
  1043. };
  1044. obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
  1045. } else if (obj.nodeType !== undefined) {
  1046. // At this point we couldn't get the IE `uniqueID` to use as a hash
  1047. // and we couldn't use a non-enumerable property to exploit the
  1048. // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
  1049. // itself.
  1050. obj[UID_HASH_KEY] = hash;
  1051. } else {
  1052. throw new Error('Unable to set a non-enumerable property on object.');
  1053. }
  1054. return hash;
  1055. }
  1056. // Get references to ES5 object methods.
  1057. var isExtensible = Object.isExtensible;
  1058. // True if Object.defineProperty works as expected. IE8 fails this test.
  1059. var canDefineProperty = (function() {
  1060. try {
  1061. Object.defineProperty({}, '@', {});
  1062. return true;
  1063. } catch (e) {
  1064. return false;
  1065. }
  1066. }());
  1067. // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
  1068. // and avoid memory leaks from the IE cloneNode bug.
  1069. function getIENodeHash(node) {
  1070. if (node && node.nodeType > 0) {
  1071. switch (node.nodeType) {
  1072. case 1: // Element
  1073. return node.uniqueID;
  1074. case 9: // Document
  1075. return node.documentElement && node.documentElement.uniqueID;
  1076. }
  1077. }
  1078. }
  1079. // If possible, use a WeakMap.
  1080. var usingWeakMap = typeof WeakMap === 'function';
  1081. var weakMap;
  1082. if (usingWeakMap) {
  1083. weakMap = new WeakMap();
  1084. }
  1085. var objHashUID = 0;
  1086. var UID_HASH_KEY = '__immutablehash__';
  1087. if (typeof Symbol === 'function') {
  1088. UID_HASH_KEY = Symbol(UID_HASH_KEY);
  1089. }
  1090. var STRING_HASH_CACHE_MIN_STRLEN = 16;
  1091. var STRING_HASH_CACHE_MAX_SIZE = 255;
  1092. var STRING_HASH_CACHE_SIZE = 0;
  1093. var stringHashCache = {};
  1094. function assertNotInfinite(size) {
  1095. invariant(
  1096. size !== Infinity,
  1097. 'Cannot perform this action with an infinite size.'
  1098. );
  1099. }
  1100. createClass(Map, KeyedCollection);
  1101. // @pragma Construction
  1102. function Map(value) {
  1103. return value === null || value === undefined ? emptyMap() :
  1104. isMap(value) && !isOrdered(value) ? value :
  1105. emptyMap().withMutations(function(map ) {
  1106. var iter = KeyedIterable(value);
  1107. assertNotInfinite(iter.size);
  1108. iter.forEach(function(v, k) {return map.set(k, v)});
  1109. });
  1110. }
  1111. Map.prototype.toString = function() {
  1112. return this.__toString('Map {', '}');
  1113. };
  1114. // @pragma Access
  1115. Map.prototype.get = function(k, notSetValue) {
  1116. return this._root ?
  1117. this._root.get(0, undefined, k, notSetValue) :
  1118. notSetValue;
  1119. };
  1120. // @pragma Modification
  1121. Map.prototype.set = function(k, v) {
  1122. return updateMap(this, k, v);
  1123. };
  1124. Map.prototype.setIn = function(keyPath, v) {
  1125. return this.updateIn(keyPath, NOT_SET, function() {return v});
  1126. };
  1127. Map.prototype.remove = function(k) {
  1128. return updateMap(this, k, NOT_SET);
  1129. };
  1130. Map.prototype.deleteIn = function(keyPath) {
  1131. return this.updateIn(keyPath, function() {return NOT_SET});
  1132. };
  1133. Map.prototype.update = function(k, notSetValue, updater) {
  1134. return arguments.length === 1 ?
  1135. k(this) :
  1136. this.updateIn([k], notSetValue, updater);
  1137. };
  1138. Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
  1139. if (!updater) {
  1140. updater = notSetValue;
  1141. notSetValue = undefined;
  1142. }
  1143. var updatedValue = updateInDeepMap(
  1144. this,
  1145. forceIterator(keyPath),
  1146. notSetValue,
  1147. updater
  1148. );
  1149. return updatedValue === NOT_SET ? undefined : updatedValue;
  1150. };
  1151. Map.prototype.clear = function() {
  1152. if (this.size === 0) {
  1153. return this;
  1154. }
  1155. if (this.__ownerID) {
  1156. this.size = 0;
  1157. this._root = null;
  1158. this.__hash = undefined;
  1159. this.__altered = true;
  1160. return this;
  1161. }
  1162. return emptyMap();
  1163. };
  1164. // @pragma Composition
  1165. Map.prototype.merge = function(/*...iters*/) {
  1166. return mergeIntoMapWith(this, undefined, arguments);
  1167. };
  1168. Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1169. return mergeIntoMapWith(this, merger, iters);
  1170. };
  1171. Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1172. return this.updateIn(
  1173. keyPath,
  1174. emptyMap(),
  1175. function(m ) {return typeof m.merge === 'function' ?
  1176. m.merge.apply(m, iters) :
  1177. iters[iters.length - 1]}
  1178. );
  1179. };
  1180. Map.prototype.mergeDeep = function(/*...iters*/) {
  1181. return mergeIntoMapWith(this, deepMerger, arguments);
  1182. };
  1183. Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1184. return mergeIntoMapWith(this, deepMergerWith(merger), iters);
  1185. };
  1186. Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
  1187. return this.updateIn(
  1188. keyPath,
  1189. emptyMap(),
  1190. function(m ) {return typeof m.mergeDeep === 'function' ?
  1191. m.mergeDeep.apply(m, iters) :
  1192. iters[iters.length - 1]}
  1193. );
  1194. };
  1195. Map.prototype.sort = function(comparator) {
  1196. // Late binding
  1197. return OrderedMap(sortFactory(this, comparator));
  1198. };
  1199. Map.prototype.sortBy = function(mapper, comparator) {
  1200. // Late binding
  1201. return OrderedMap(sortFactory(this, comparator, mapper));
  1202. };
  1203. // @pragma Mutability
  1204. Map.prototype.withMutations = function(fn) {
  1205. var mutable = this.asMutable();
  1206. fn(mutable);
  1207. return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
  1208. };
  1209. Map.prototype.asMutable = function() {
  1210. return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
  1211. };
  1212. Map.prototype.asImmutable = function() {
  1213. return this.__ensureOwner();
  1214. };
  1215. Map.prototype.wasAltered = function() {
  1216. return this.__altered;
  1217. };
  1218. Map.prototype.__iterator = function(type, reverse) {
  1219. return new MapIterator(this, type, reverse);
  1220. };
  1221. Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  1222. var iterations = 0;
  1223. this._root && this._root.iterate(function(entry ) {
  1224. iterations++;
  1225. return fn(entry[1], entry[0], this$0);
  1226. }, reverse);
  1227. return iterations;
  1228. };
  1229. Map.prototype.__ensureOwner = function(ownerID) {
  1230. if (ownerID === this.__ownerID) {
  1231. return this;
  1232. }
  1233. if (!ownerID) {
  1234. this.__ownerID = ownerID;
  1235. this.__altered = false;
  1236. return this;
  1237. }
  1238. return makeMap(this.size, this._root, ownerID, this.__hash);
  1239. };
  1240. function isMap(maybeMap) {
  1241. return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
  1242. }
  1243. Map.isMap = isMap;
  1244. var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
  1245. var MapPrototype = Map.prototype;
  1246. MapPrototype[IS_MAP_SENTINEL] = true;
  1247. MapPrototype[DELETE] = MapPrototype.remove;
  1248. MapPrototype.removeIn = MapPrototype.deleteIn;
  1249. // #pragma Trie Nodes
  1250. function ArrayMapNode(ownerID, entries) {
  1251. this.ownerID = ownerID;
  1252. this.entries = entries;
  1253. }
  1254. ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1255. var entries = this.entries;
  1256. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1257. if (is(key, entries[ii][0])) {
  1258. return entries[ii][1];
  1259. }
  1260. }
  1261. return notSetValue;
  1262. };
  1263. ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1264. var removed = value === NOT_SET;
  1265. var entries = this.entries;
  1266. var idx = 0;
  1267. for (var len = entries.length; idx < len; idx++) {
  1268. if (is(key, entries[idx][0])) {
  1269. break;
  1270. }
  1271. }
  1272. var exists = idx < len;
  1273. if (exists ? entries[idx][1] === value : removed) {
  1274. return this;
  1275. }
  1276. SetRef(didAlter);
  1277. (removed || !exists) && SetRef(didChangeSize);
  1278. if (removed && entries.length === 1) {
  1279. return; // undefined
  1280. }
  1281. if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
  1282. return createNodes(ownerID, entries, key, value);
  1283. }
  1284. var isEditable = ownerID && ownerID === this.ownerID;
  1285. var newEntries = isEditable ? entries : arrCopy(entries);
  1286. if (exists) {
  1287. if (removed) {
  1288. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1289. } else {
  1290. newEntries[idx] = [key, value];
  1291. }
  1292. } else {
  1293. newEntries.push([key, value]);
  1294. }
  1295. if (isEditable) {
  1296. this.entries = newEntries;
  1297. return this;
  1298. }
  1299. return new ArrayMapNode(ownerID, newEntries);
  1300. };
  1301. function BitmapIndexedNode(ownerID, bitmap, nodes) {
  1302. this.ownerID = ownerID;
  1303. this.bitmap = bitmap;
  1304. this.nodes = nodes;
  1305. }
  1306. BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1307. if (keyHash === undefined) {
  1308. keyHash = hash(key);
  1309. }
  1310. var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
  1311. var bitmap = this.bitmap;
  1312. return (bitmap & bit) === 0 ? notSetValue :
  1313. this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
  1314. };
  1315. BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1316. if (keyHash === undefined) {
  1317. keyHash = hash(key);
  1318. }
  1319. var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1320. var bit = 1 << keyHashFrag;
  1321. var bitmap = this.bitmap;
  1322. var exists = (bitmap & bit) !== 0;
  1323. if (!exists && value === NOT_SET) {
  1324. return this;
  1325. }
  1326. var idx = popCount(bitmap & (bit - 1));
  1327. var nodes = this.nodes;
  1328. var node = exists ? nodes[idx] : undefined;
  1329. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1330. if (newNode === node) {
  1331. return this;
  1332. }
  1333. if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
  1334. return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
  1335. }
  1336. if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
  1337. return nodes[idx ^ 1];
  1338. }
  1339. if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
  1340. return newNode;
  1341. }
  1342. var isEditable = ownerID && ownerID === this.ownerID;
  1343. var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
  1344. var newNodes = exists ? newNode ?
  1345. setIn(nodes, idx, newNode, isEditable) :
  1346. spliceOut(nodes, idx, isEditable) :
  1347. spliceIn(nodes, idx, newNode, isEditable);
  1348. if (isEditable) {
  1349. this.bitmap = newBitmap;
  1350. this.nodes = newNodes;
  1351. return this;
  1352. }
  1353. return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
  1354. };
  1355. function HashArrayMapNode(ownerID, count, nodes) {
  1356. this.ownerID = ownerID;
  1357. this.count = count;
  1358. this.nodes = nodes;
  1359. }
  1360. HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1361. if (keyHash === undefined) {
  1362. keyHash = hash(key);
  1363. }
  1364. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1365. var node = this.nodes[idx];
  1366. return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
  1367. };
  1368. HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1369. if (keyHash === undefined) {
  1370. keyHash = hash(key);
  1371. }
  1372. var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1373. var removed = value === NOT_SET;
  1374. var nodes = this.nodes;
  1375. var node = nodes[idx];
  1376. if (removed && !node) {
  1377. return this;
  1378. }
  1379. var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
  1380. if (newNode === node) {
  1381. return this;
  1382. }
  1383. var newCount = this.count;
  1384. if (!node) {
  1385. newCount++;
  1386. } else if (!newNode) {
  1387. newCount--;
  1388. if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
  1389. return packNodes(ownerID, nodes, newCount, idx);
  1390. }
  1391. }
  1392. var isEditable = ownerID && ownerID === this.ownerID;
  1393. var newNodes = setIn(nodes, idx, newNode, isEditable);
  1394. if (isEditable) {
  1395. this.count = newCount;
  1396. this.nodes = newNodes;
  1397. return this;
  1398. }
  1399. return new HashArrayMapNode(ownerID, newCount, newNodes);
  1400. };
  1401. function HashCollisionNode(ownerID, keyHash, entries) {
  1402. this.ownerID = ownerID;
  1403. this.keyHash = keyHash;
  1404. this.entries = entries;
  1405. }
  1406. HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1407. var entries = this.entries;
  1408. for (var ii = 0, len = entries.length; ii < len; ii++) {
  1409. if (is(key, entries[ii][0])) {
  1410. return entries[ii][1];
  1411. }
  1412. }
  1413. return notSetValue;
  1414. };
  1415. HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1416. if (keyHash === undefined) {
  1417. keyHash = hash(key);
  1418. }
  1419. var removed = value === NOT_SET;
  1420. if (keyHash !== this.keyHash) {
  1421. if (removed) {
  1422. return this;
  1423. }
  1424. SetRef(didAlter);
  1425. SetRef(didChangeSize);
  1426. return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
  1427. }
  1428. var entries = this.entries;
  1429. var idx = 0;
  1430. for (var len = entries.length; idx < len; idx++) {
  1431. if (is(key, entries[idx][0])) {
  1432. break;
  1433. }
  1434. }
  1435. var exists = idx < len;
  1436. if (exists ? entries[idx][1] === value : removed) {
  1437. return this;
  1438. }
  1439. SetRef(didAlter);
  1440. (removed || !exists) && SetRef(didChangeSize);
  1441. if (removed && len === 2) {
  1442. return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
  1443. }
  1444. var isEditable = ownerID && ownerID === this.ownerID;
  1445. var newEntries = isEditable ? entries : arrCopy(entries);
  1446. if (exists) {
  1447. if (removed) {
  1448. idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
  1449. } else {
  1450. newEntries[idx] = [key, value];
  1451. }
  1452. } else {
  1453. newEntries.push([key, value]);
  1454. }
  1455. if (isEditable) {
  1456. this.entries = newEntries;
  1457. return this;
  1458. }
  1459. return new HashCollisionNode(ownerID, this.keyHash, newEntries);
  1460. };
  1461. function ValueNode(ownerID, keyHash, entry) {
  1462. this.ownerID = ownerID;
  1463. this.keyHash = keyHash;
  1464. this.entry = entry;
  1465. }
  1466. ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
  1467. return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
  1468. };
  1469. ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1470. var removed = value === NOT_SET;
  1471. var keyMatch = is(key, this.entry[0]);
  1472. if (keyMatch ? value === this.entry[1] : removed) {
  1473. return this;
  1474. }
  1475. SetRef(didAlter);
  1476. if (removed) {
  1477. SetRef(didChangeSize);
  1478. return; // undefined
  1479. }
  1480. if (keyMatch) {
  1481. if (ownerID && ownerID === this.ownerID) {
  1482. this.entry[1] = value;
  1483. return this;
  1484. }
  1485. return new ValueNode(ownerID, this.keyHash, [key, value]);
  1486. }
  1487. SetRef(didChangeSize);
  1488. return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
  1489. };
  1490. // #pragma Iterators
  1491. ArrayMapNode.prototype.iterate =
  1492. HashCollisionNode.prototype.iterate = function (fn, reverse) {
  1493. var entries = this.entries;
  1494. for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
  1495. if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
  1496. return false;
  1497. }
  1498. }
  1499. };
  1500. BitmapIndexedNode.prototype.iterate =
  1501. HashArrayMapNode.prototype.iterate = function (fn, reverse) {
  1502. var nodes = this.nodes;
  1503. for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
  1504. var node = nodes[reverse ? maxIndex - ii : ii];
  1505. if (node && node.iterate(fn, reverse) === false) {
  1506. return false;
  1507. }
  1508. }
  1509. };
  1510. ValueNode.prototype.iterate = function (fn, reverse) {
  1511. return fn(this.entry);
  1512. };
  1513. createClass(MapIterator, Iterator);
  1514. function MapIterator(map, type, reverse) {
  1515. this._type = type;
  1516. this._reverse = reverse;
  1517. this._stack = map._root && mapIteratorFrame(map._root);
  1518. }
  1519. MapIterator.prototype.next = function() {
  1520. var type = this._type;
  1521. var stack = this._stack;
  1522. while (stack) {
  1523. var node = stack.node;
  1524. var index = stack.index++;
  1525. var maxIndex;
  1526. if (node.entry) {
  1527. if (index === 0) {
  1528. return mapIteratorValue(type, node.entry);
  1529. }
  1530. } else if (node.entries) {
  1531. maxIndex = node.entries.length - 1;
  1532. if (index <= maxIndex) {
  1533. return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
  1534. }
  1535. } else {
  1536. maxIndex = node.nodes.length - 1;
  1537. if (index <= maxIndex) {
  1538. var subNode = node.nodes[this._reverse ? maxIndex - index : index];
  1539. if (subNode) {
  1540. if (subNode.entry) {
  1541. return mapIteratorValue(type, subNode.entry);
  1542. }
  1543. stack = this._stack = mapIteratorFrame(subNode, stack);
  1544. }
  1545. continue;
  1546. }
  1547. }
  1548. stack = this._stack = this._stack.__prev;
  1549. }
  1550. return iteratorDone();
  1551. };
  1552. function mapIteratorValue(type, entry) {
  1553. return iteratorValue(type, entry[0], entry[1]);
  1554. }
  1555. function mapIteratorFrame(node, prev) {
  1556. return {
  1557. node: node,
  1558. index: 0,
  1559. __prev: prev
  1560. };
  1561. }
  1562. function makeMap(size, root, ownerID, hash) {
  1563. var map = Object.create(MapPrototype);
  1564. map.size = size;
  1565. map._root = root;
  1566. map.__ownerID = ownerID;
  1567. map.__hash = hash;
  1568. map.__altered = false;
  1569. return map;
  1570. }
  1571. var EMPTY_MAP;
  1572. function emptyMap() {
  1573. return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
  1574. }
  1575. function updateMap(map, k, v) {
  1576. var newRoot;
  1577. var newSize;
  1578. if (!map._root) {
  1579. if (v === NOT_SET) {
  1580. return map;
  1581. }
  1582. newSize = 1;
  1583. newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
  1584. } else {
  1585. var didChangeSize = MakeRef(CHANGE_LENGTH);
  1586. var didAlter = MakeRef(DID_ALTER);
  1587. newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
  1588. if (!didAlter.value) {
  1589. return map;
  1590. }
  1591. newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
  1592. }
  1593. if (map.__ownerID) {
  1594. map.size = newSize;
  1595. map._root = newRoot;
  1596. map.__hash = undefined;
  1597. map.__altered = true;
  1598. return map;
  1599. }
  1600. return newRoot ? makeMap(newSize, newRoot) : emptyMap();
  1601. }
  1602. function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
  1603. if (!node) {
  1604. if (value === NOT_SET) {
  1605. return node;
  1606. }
  1607. SetRef(didAlter);
  1608. SetRef(didChangeSize);
  1609. return new ValueNode(ownerID, keyHash, [key, value]);
  1610. }
  1611. return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
  1612. }
  1613. function isLeafNode(node) {
  1614. return node.constructor === ValueNode || node.constructor === HashCollisionNode;
  1615. }
  1616. function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
  1617. if (node.keyHash === keyHash) {
  1618. return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
  1619. }
  1620. var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
  1621. var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
  1622. var newNode;
  1623. var nodes = idx1 === idx2 ?
  1624. [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
  1625. ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
  1626. return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
  1627. }
  1628. function createNodes(ownerID, entries, key, value) {
  1629. if (!ownerID) {
  1630. ownerID = new OwnerID();
  1631. }
  1632. var node = new ValueNode(ownerID, hash(key), [key, value]);
  1633. for (var ii = 0; ii < entries.length; ii++) {
  1634. var entry = entries[ii];
  1635. node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
  1636. }
  1637. return node;
  1638. }
  1639. function packNodes(ownerID, nodes, count, excluding) {
  1640. var bitmap = 0;
  1641. var packedII = 0;
  1642. var packedNodes = new Array(count);
  1643. for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
  1644. var node = nodes[ii];
  1645. if (node !== undefined && ii !== excluding) {
  1646. bitmap |= bit;
  1647. packedNodes[packedII++] = node;
  1648. }
  1649. }
  1650. return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
  1651. }
  1652. function expandNodes(ownerID, nodes, bitmap, including, node) {
  1653. var count = 0;
  1654. var expandedNodes = new Array(SIZE);
  1655. for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
  1656. expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
  1657. }
  1658. expandedNodes[including] = node;
  1659. return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
  1660. }
  1661. function mergeIntoMapWith(map, merger, iterables) {
  1662. var iters = [];
  1663. for (var ii = 0; ii < iterables.length; ii++) {
  1664. var value = iterables[ii];
  1665. var iter = KeyedIterable(value);
  1666. if (!isIterable(value)) {
  1667. iter = iter.map(function(v ) {return fromJS(v)});
  1668. }
  1669. iters.push(iter);
  1670. }
  1671. return mergeIntoCollectionWith(map, merger, iters);
  1672. }
  1673. function deepMerger(existing, value, key) {
  1674. return existing && existing.mergeDeep && isIterable(value) ?
  1675. existing.mergeDeep(value) :
  1676. is(existing, value) ? existing : value;
  1677. }
  1678. function deepMergerWith(merger) {
  1679. return function(existing, value, key) {
  1680. if (existing && existing.mergeDeepWith && isIterable(value)) {
  1681. return existing.mergeDeepWith(merger, value);
  1682. }
  1683. var nextValue = merger(existing, value, key);
  1684. return is(existing, nextValue) ? existing : nextValue;
  1685. };
  1686. }
  1687. function mergeIntoCollectionWith(collection, merger, iters) {
  1688. iters = iters.filter(function(x ) {return x.size !== 0});
  1689. if (iters.length === 0) {
  1690. return collection;
  1691. }
  1692. if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
  1693. return collection.constructor(iters[0]);
  1694. }
  1695. return collection.withMutations(function(collection ) {
  1696. var mergeIntoMap = merger ?
  1697. function(value, key) {
  1698. collection.update(key, NOT_SET, function(existing )
  1699. {return existing === NOT_SET ? value : merger(existing, value, key)}
  1700. );
  1701. } :
  1702. function(value, key) {
  1703. collection.set(key, value);
  1704. };
  1705. for (var ii = 0; ii < iters.length; ii++) {
  1706. iters[ii].forEach(mergeIntoMap);
  1707. }
  1708. });
  1709. }
  1710. function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
  1711. var isNotSet = existing === NOT_SET;
  1712. var step = keyPathIter.next();
  1713. if (step.done) {
  1714. var existingValue = isNotSet ? notSetValue : existing;
  1715. var newValue = updater(existingValue);
  1716. return newValue === existingValue ? existing : newValue;
  1717. }
  1718. invariant(
  1719. isNotSet || (existing && existing.set),
  1720. 'invalid keyPath'
  1721. );
  1722. var key = step.value;
  1723. var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
  1724. var nextUpdated = updateInDeepMap(
  1725. nextExisting,
  1726. keyPathIter,
  1727. notSetValue,
  1728. updater
  1729. );
  1730. return nextUpdated === nextExisting ? existing :
  1731. nextUpdated === NOT_SET ? existing.remove(key) :
  1732. (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
  1733. }
  1734. function popCount(x) {
  1735. x = x - ((x >> 1) & 0x55555555);
  1736. x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
  1737. x = (x + (x >> 4)) & 0x0f0f0f0f;
  1738. x = x + (x >> 8);
  1739. x = x + (x >> 16);
  1740. return x & 0x7f;
  1741. }
  1742. function setIn(array, idx, val, canEdit) {
  1743. var newArray = canEdit ? array : arrCopy(array);
  1744. newArray[idx] = val;
  1745. return newArray;
  1746. }
  1747. function spliceIn(array, idx, val, canEdit) {
  1748. var newLen = array.length + 1;
  1749. if (canEdit && idx + 1 === newLen) {
  1750. array[idx] = val;
  1751. return array;
  1752. }
  1753. var newArray = new Array(newLen);
  1754. var after = 0;
  1755. for (var ii = 0; ii < newLen; ii++) {
  1756. if (ii === idx) {
  1757. newArray[ii] = val;
  1758. after = -1;
  1759. } else {
  1760. newArray[ii] = array[ii + after];
  1761. }
  1762. }
  1763. return newArray;
  1764. }
  1765. function spliceOut(array, idx, canEdit) {
  1766. var newLen = array.length - 1;
  1767. if (canEdit && idx === newLen) {
  1768. array.pop();
  1769. return array;
  1770. }
  1771. var newArray = new Array(newLen);
  1772. var after = 0;
  1773. for (var ii = 0; ii < newLen; ii++) {
  1774. if (ii === idx) {
  1775. after = 1;
  1776. }
  1777. newArray[ii] = array[ii + after];
  1778. }
  1779. return newArray;
  1780. }
  1781. var MAX_ARRAY_MAP_SIZE = SIZE / 4;
  1782. var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
  1783. var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
  1784. createClass(List, IndexedCollection);
  1785. // @pragma Construction
  1786. function List(value) {
  1787. var empty = emptyList();
  1788. if (value === null || value === undefined) {
  1789. return empty;
  1790. }
  1791. if (isList(value)) {
  1792. return value;
  1793. }
  1794. var iter = IndexedIterable(value);
  1795. var size = iter.size;
  1796. if (size === 0) {
  1797. return empty;
  1798. }
  1799. assertNotInfinite(size);
  1800. if (size > 0 && size < SIZE) {
  1801. return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
  1802. }
  1803. return empty.withMutations(function(list ) {
  1804. list.setSize(size);
  1805. iter.forEach(function(v, i) {return list.set(i, v)});
  1806. });
  1807. }
  1808. List.of = function(/*...values*/) {
  1809. return this(arguments);
  1810. };
  1811. List.prototype.toString = function() {
  1812. return this.__toString('List [', ']');
  1813. };
  1814. // @pragma Access
  1815. List.prototype.get = function(index, notSetValue) {
  1816. index = wrapIndex(this, index);
  1817. if (index >= 0 && index < this.size) {
  1818. index += this._origin;
  1819. var node = listNodeFor(this, index);
  1820. return node && node.array[index & MASK];
  1821. }
  1822. return notSetValue;
  1823. };
  1824. // @pragma Modification
  1825. List.prototype.set = function(index, value) {
  1826. return updateList(this, index, value);
  1827. };
  1828. List.prototype.remove = function(index) {
  1829. return !this.has(index) ? this :
  1830. index === 0 ? this.shift() :
  1831. index === this.size - 1 ? this.pop() :
  1832. this.splice(index, 1);
  1833. };
  1834. List.prototype.insert = function(index, value) {
  1835. return this.splice(index, 0, value);
  1836. };
  1837. List.prototype.clear = function() {
  1838. if (this.size === 0) {
  1839. return this;
  1840. }
  1841. if (this.__ownerID) {
  1842. this.size = this._origin = this._capacity = 0;
  1843. this._level = SHIFT;
  1844. this._root = this._tail = null;
  1845. this.__hash = undefined;
  1846. this.__altered = true;
  1847. return this;
  1848. }
  1849. return emptyList();
  1850. };
  1851. List.prototype.push = function(/*...values*/) {
  1852. var values = arguments;
  1853. var oldSize = this.size;
  1854. return this.withMutations(function(list ) {
  1855. setListBounds(list, 0, oldSize + values.length);
  1856. for (var ii = 0; ii < values.length; ii++) {
  1857. list.set(oldSize + ii, values[ii]);
  1858. }
  1859. });
  1860. };
  1861. List.prototype.pop = function() {
  1862. return setListBounds(this, 0, -1);
  1863. };
  1864. List.prototype.unshift = function(/*...values*/) {
  1865. var values = arguments;
  1866. return this.withMutations(function(list ) {
  1867. setListBounds(list, -values.length);
  1868. for (var ii = 0; ii < values.length; ii++) {
  1869. list.set(ii, values[ii]);
  1870. }
  1871. });
  1872. };
  1873. List.prototype.shift = function() {
  1874. return setListBounds(this, 1);
  1875. };
  1876. // @pragma Composition
  1877. List.prototype.merge = function(/*...iters*/) {
  1878. return mergeIntoListWith(this, undefined, arguments);
  1879. };
  1880. List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1881. return mergeIntoListWith(this, merger, iters);
  1882. };
  1883. List.prototype.mergeDeep = function(/*...iters*/) {
  1884. return mergeIntoListWith(this, deepMerger, arguments);
  1885. };
  1886. List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  1887. return mergeIntoListWith(this, deepMergerWith(merger), iters);
  1888. };
  1889. List.prototype.setSize = function(size) {
  1890. return setListBounds(this, 0, size);
  1891. };
  1892. // @pragma Iteration
  1893. List.prototype.slice = function(begin, end) {
  1894. var size = this.size;
  1895. if (wholeSlice(begin, end, size)) {
  1896. return this;
  1897. }
  1898. return setListBounds(
  1899. this,
  1900. resolveBegin(begin, size),
  1901. resolveEnd(end, size)
  1902. );
  1903. };
  1904. List.prototype.__iterator = function(type, reverse) {
  1905. var index = 0;
  1906. var values = iterateList(this, reverse);
  1907. return new Iterator(function() {
  1908. var value = values();
  1909. return value === DONE ?
  1910. iteratorDone() :
  1911. iteratorValue(type, index++, value);
  1912. });
  1913. };
  1914. List.prototype.__iterate = function(fn, reverse) {
  1915. var index = 0;
  1916. var values = iterateList(this, reverse);
  1917. var value;
  1918. while ((value = values()) !== DONE) {
  1919. if (fn(value, index++, this) === false) {
  1920. break;
  1921. }
  1922. }
  1923. return index;
  1924. };
  1925. List.prototype.__ensureOwner = function(ownerID) {
  1926. if (ownerID === this.__ownerID) {
  1927. return this;
  1928. }
  1929. if (!ownerID) {
  1930. this.__ownerID = ownerID;
  1931. return this;
  1932. }
  1933. return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
  1934. };
  1935. function isList(maybeList) {
  1936. return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
  1937. }
  1938. List.isList = isList;
  1939. var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
  1940. var ListPrototype = List.prototype;
  1941. ListPrototype[IS_LIST_SENTINEL] = true;
  1942. ListPrototype[DELETE] = ListPrototype.remove;
  1943. ListPrototype.setIn = MapPrototype.setIn;
  1944. ListPrototype.deleteIn =
  1945. ListPrototype.removeIn = MapPrototype.removeIn;
  1946. ListPrototype.update = MapPrototype.update;
  1947. ListPrototype.updateIn = MapPrototype.updateIn;
  1948. ListPrototype.mergeIn = MapPrototype.mergeIn;
  1949. ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  1950. ListPrototype.withMutations = MapPrototype.withMutations;
  1951. ListPrototype.asMutable = MapPrototype.asMutable;
  1952. ListPrototype.asImmutable = MapPrototype.asImmutable;
  1953. ListPrototype.wasAltered = MapPrototype.wasAltered;
  1954. function VNode(array, ownerID) {
  1955. this.array = array;
  1956. this.ownerID = ownerID;
  1957. }
  1958. // TODO: seems like these methods are very similar
  1959. VNode.prototype.removeBefore = function(ownerID, level, index) {
  1960. if (index === level ? 1 << level : this.array.length === 0) {
  1961. return this;
  1962. }
  1963. var originIndex = (index >>> level) & MASK;
  1964. if (originIndex >= this.array.length) {
  1965. return new VNode([], ownerID);
  1966. }
  1967. var removingFirst = originIndex === 0;
  1968. var newChild;
  1969. if (level > 0) {
  1970. var oldChild = this.array[originIndex];
  1971. newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
  1972. if (newChild === oldChild && removingFirst) {
  1973. return this;
  1974. }
  1975. }
  1976. if (removingFirst && !newChild) {
  1977. return this;
  1978. }
  1979. var editable = editableVNode(this, ownerID);
  1980. if (!removingFirst) {
  1981. for (var ii = 0; ii < originIndex; ii++) {
  1982. editable.array[ii] = undefined;
  1983. }
  1984. }
  1985. if (newChild) {
  1986. editable.array[originIndex] = newChild;
  1987. }
  1988. return editable;
  1989. };
  1990. VNode.prototype.removeAfter = function(ownerID, level, index) {
  1991. if (index === (level ? 1 << level : 0) || this.array.length === 0) {
  1992. return this;
  1993. }
  1994. var sizeIndex = ((index - 1) >>> level) & MASK;
  1995. if (sizeIndex >= this.array.length) {
  1996. return this;
  1997. }
  1998. var newChild;
  1999. if (level > 0) {
  2000. var oldChild = this.array[sizeIndex];
  2001. newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
  2002. if (newChild === oldChild && sizeIndex === this.array.length - 1) {
  2003. return this;
  2004. }
  2005. }
  2006. var editable = editableVNode(this, ownerID);
  2007. editable.array.splice(sizeIndex + 1);
  2008. if (newChild) {
  2009. editable.array[sizeIndex] = newChild;
  2010. }
  2011. return editable;
  2012. };
  2013. var DONE = {};
  2014. function iterateList(list, reverse) {
  2015. var left = list._origin;
  2016. var right = list._capacity;
  2017. var tailPos = getTailOffset(right);
  2018. var tail = list._tail;
  2019. return iterateNodeOrLeaf(list._root, list._level, 0);
  2020. function iterateNodeOrLeaf(node, level, offset) {
  2021. return level === 0 ?
  2022. iterateLeaf(node, offset) :
  2023. iterateNode(node, level, offset);
  2024. }
  2025. function iterateLeaf(node, offset) {
  2026. var array = offset === tailPos ? tail && tail.array : node && node.array;
  2027. var from = offset > left ? 0 : left - offset;
  2028. var to = right - offset;
  2029. if (to > SIZE) {
  2030. to = SIZE;
  2031. }
  2032. return function() {
  2033. if (from === to) {
  2034. return DONE;
  2035. }
  2036. var idx = reverse ? --to : from++;
  2037. return array && array[idx];
  2038. };
  2039. }
  2040. function iterateNode(node, level, offset) {
  2041. var values;
  2042. var array = node && node.array;
  2043. var from = offset > left ? 0 : (left - offset) >> level;
  2044. var to = ((right - offset) >> level) + 1;
  2045. if (to > SIZE) {
  2046. to = SIZE;
  2047. }
  2048. return function() {
  2049. do {
  2050. if (values) {
  2051. var value = values();
  2052. if (value !== DONE) {
  2053. return value;
  2054. }
  2055. values = null;
  2056. }
  2057. if (from === to) {
  2058. return DONE;
  2059. }
  2060. var idx = reverse ? --to : from++;
  2061. values = iterateNodeOrLeaf(
  2062. array && array[idx], level - SHIFT, offset + (idx << level)
  2063. );
  2064. } while (true);
  2065. };
  2066. }
  2067. }
  2068. function makeList(origin, capacity, level, root, tail, ownerID, hash) {
  2069. var list = Object.create(ListPrototype);
  2070. list.size = capacity - origin;
  2071. list._origin = origin;
  2072. list._capacity = capacity;
  2073. list._level = level;
  2074. list._root = root;
  2075. list._tail = tail;
  2076. list.__ownerID = ownerID;
  2077. list.__hash = hash;
  2078. list.__altered = false;
  2079. return list;
  2080. }
  2081. var EMPTY_LIST;
  2082. function emptyList() {
  2083. return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
  2084. }
  2085. function updateList(list, index, value) {
  2086. index = wrapIndex(list, index);
  2087. if (index !== index) {
  2088. return list;
  2089. }
  2090. if (index >= list.size || index < 0) {
  2091. return list.withMutations(function(list ) {
  2092. index < 0 ?
  2093. setListBounds(list, index).set(0, value) :
  2094. setListBounds(list, 0, index + 1).set(index, value);
  2095. });
  2096. }
  2097. index += list._origin;
  2098. var newTail = list._tail;
  2099. var newRoot = list._root;
  2100. var didAlter = MakeRef(DID_ALTER);
  2101. if (index >= getTailOffset(list._capacity)) {
  2102. newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
  2103. } else {
  2104. newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
  2105. }
  2106. if (!didAlter.value) {
  2107. return list;
  2108. }
  2109. if (list.__ownerID) {
  2110. list._root = newRoot;
  2111. list._tail = newTail;
  2112. list.__hash = undefined;
  2113. list.__altered = true;
  2114. return list;
  2115. }
  2116. return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
  2117. }
  2118. function updateVNode(node, ownerID, level, index, value, didAlter) {
  2119. var idx = (index >>> level) & MASK;
  2120. var nodeHas = node && idx < node.array.length;
  2121. if (!nodeHas && value === undefined) {
  2122. return node;
  2123. }
  2124. var newNode;
  2125. if (level > 0) {
  2126. var lowerNode = node && node.array[idx];
  2127. var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
  2128. if (newLowerNode === lowerNode) {
  2129. return node;
  2130. }
  2131. newNode = editableVNode(node, ownerID);
  2132. newNode.array[idx] = newLowerNode;
  2133. return newNode;
  2134. }
  2135. if (nodeHas && node.array[idx] === value) {
  2136. return node;
  2137. }
  2138. SetRef(didAlter);
  2139. newNode = editableVNode(node, ownerID);
  2140. if (value === undefined && idx === newNode.array.length - 1) {
  2141. newNode.array.pop();
  2142. } else {
  2143. newNode.array[idx] = value;
  2144. }
  2145. return newNode;
  2146. }
  2147. function editableVNode(node, ownerID) {
  2148. if (ownerID && node && ownerID === node.ownerID) {
  2149. return node;
  2150. }
  2151. return new VNode(node ? node.array.slice() : [], ownerID);
  2152. }
  2153. function listNodeFor(list, rawIndex) {
  2154. if (rawIndex >= getTailOffset(list._capacity)) {
  2155. return list._tail;
  2156. }
  2157. if (rawIndex < 1 << (list._level + SHIFT)) {
  2158. var node = list._root;
  2159. var level = list._level;
  2160. while (node && level > 0) {
  2161. node = node.array[(rawIndex >>> level) & MASK];
  2162. level -= SHIFT;
  2163. }
  2164. return node;
  2165. }
  2166. }
  2167. function setListBounds(list, begin, end) {
  2168. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2169. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2170. if (begin !== undefined) {
  2171. begin = begin | 0;
  2172. }
  2173. if (end !== undefined) {
  2174. end = end | 0;
  2175. }
  2176. var owner = list.__ownerID || new OwnerID();
  2177. var oldOrigin = list._origin;
  2178. var oldCapacity = list._capacity;
  2179. var newOrigin = oldOrigin + begin;
  2180. var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
  2181. if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
  2182. return list;
  2183. }
  2184. // If it's going to end after it starts, it's empty.
  2185. if (newOrigin >= newCapacity) {
  2186. return list.clear();
  2187. }
  2188. var newLevel = list._level;
  2189. var newRoot = list._root;
  2190. // New origin might need creating a higher root.
  2191. var offsetShift = 0;
  2192. while (newOrigin + offsetShift < 0) {
  2193. newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
  2194. newLevel += SHIFT;
  2195. offsetShift += 1 << newLevel;
  2196. }
  2197. if (offsetShift) {
  2198. newOrigin += offsetShift;
  2199. oldOrigin += offsetShift;
  2200. newCapacity += offsetShift;
  2201. oldCapacity += offsetShift;
  2202. }
  2203. var oldTailOffset = getTailOffset(oldCapacity);
  2204. var newTailOffset = getTailOffset(newCapacity);
  2205. // New size might need creating a higher root.
  2206. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
  2207. newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
  2208. newLevel += SHIFT;
  2209. }
  2210. // Locate or create the new tail.
  2211. var oldTail = list._tail;
  2212. var newTail = newTailOffset < oldTailOffset ?
  2213. listNodeFor(list, newCapacity - 1) :
  2214. newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
  2215. // Merge Tail into tree.
  2216. if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
  2217. newRoot = editableVNode(newRoot, owner);
  2218. var node = newRoot;
  2219. for (var level = newLevel; level > SHIFT; level -= SHIFT) {
  2220. var idx = (oldTailOffset >>> level) & MASK;
  2221. node = node.array[idx] = editableVNode(node.array[idx], owner);
  2222. }
  2223. node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
  2224. }
  2225. // If the size has been reduced, there's a chance the tail needs to be trimmed.
  2226. if (newCapacity < oldCapacity) {
  2227. newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
  2228. }
  2229. // If the new origin is within the tail, then we do not need a root.
  2230. if (newOrigin >= newTailOffset) {
  2231. newOrigin -= newTailOffset;
  2232. newCapacity -= newTailOffset;
  2233. newLevel = SHIFT;
  2234. newRoot = null;
  2235. newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
  2236. // Otherwise, if the root has been trimmed, garbage collect.
  2237. } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
  2238. offsetShift = 0;
  2239. // Identify the new top root node of the subtree of the old root.
  2240. while (newRoot) {
  2241. var beginIndex = (newOrigin >>> newLevel) & MASK;
  2242. if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
  2243. break;
  2244. }
  2245. if (beginIndex) {
  2246. offsetShift += (1 << newLevel) * beginIndex;
  2247. }
  2248. newLevel -= SHIFT;
  2249. newRoot = newRoot.array[beginIndex];
  2250. }
  2251. // Trim the new sides of the new root.
  2252. if (newRoot && newOrigin > oldOrigin) {
  2253. newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
  2254. }
  2255. if (newRoot && newTailOffset < oldTailOffset) {
  2256. newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
  2257. }
  2258. if (offsetShift) {
  2259. newOrigin -= offsetShift;
  2260. newCapacity -= offsetShift;
  2261. }
  2262. }
  2263. if (list.__ownerID) {
  2264. list.size = newCapacity - newOrigin;
  2265. list._origin = newOrigin;
  2266. list._capacity = newCapacity;
  2267. list._level = newLevel;
  2268. list._root = newRoot;
  2269. list._tail = newTail;
  2270. list.__hash = undefined;
  2271. list.__altered = true;
  2272. return list;
  2273. }
  2274. return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
  2275. }
  2276. function mergeIntoListWith(list, merger, iterables) {
  2277. var iters = [];
  2278. var maxSize = 0;
  2279. for (var ii = 0; ii < iterables.length; ii++) {
  2280. var value = iterables[ii];
  2281. var iter = IndexedIterable(value);
  2282. if (iter.size > maxSize) {
  2283. maxSize = iter.size;
  2284. }
  2285. if (!isIterable(value)) {
  2286. iter = iter.map(function(v ) {return fromJS(v)});
  2287. }
  2288. iters.push(iter);
  2289. }
  2290. if (maxSize > list.size) {
  2291. list = list.setSize(maxSize);
  2292. }
  2293. return mergeIntoCollectionWith(list, merger, iters);
  2294. }
  2295. function getTailOffset(size) {
  2296. return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
  2297. }
  2298. createClass(OrderedMap, Map);
  2299. // @pragma Construction
  2300. function OrderedMap(value) {
  2301. return value === null || value === undefined ? emptyOrderedMap() :
  2302. isOrderedMap(value) ? value :
  2303. emptyOrderedMap().withMutations(function(map ) {
  2304. var iter = KeyedIterable(value);
  2305. assertNotInfinite(iter.size);
  2306. iter.forEach(function(v, k) {return map.set(k, v)});
  2307. });
  2308. }
  2309. OrderedMap.of = function(/*...values*/) {
  2310. return this(arguments);
  2311. };
  2312. OrderedMap.prototype.toString = function() {
  2313. return this.__toString('OrderedMap {', '}');
  2314. };
  2315. // @pragma Access
  2316. OrderedMap.prototype.get = function(k, notSetValue) {
  2317. var index = this._map.get(k);
  2318. return index !== undefined ? this._list.get(index)[1] : notSetValue;
  2319. };
  2320. // @pragma Modification
  2321. OrderedMap.prototype.clear = function() {
  2322. if (this.size === 0) {
  2323. return this;
  2324. }
  2325. if (this.__ownerID) {
  2326. this.size = 0;
  2327. this._map.clear();
  2328. this._list.clear();
  2329. return this;
  2330. }
  2331. return emptyOrderedMap();
  2332. };
  2333. OrderedMap.prototype.set = function(k, v) {
  2334. return updateOrderedMap(this, k, v);
  2335. };
  2336. OrderedMap.prototype.remove = function(k) {
  2337. return updateOrderedMap(this, k, NOT_SET);
  2338. };
  2339. OrderedMap.prototype.wasAltered = function() {
  2340. return this._map.wasAltered() || this._list.wasAltered();
  2341. };
  2342. OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2343. return this._list.__iterate(
  2344. function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
  2345. reverse
  2346. );
  2347. };
  2348. OrderedMap.prototype.__iterator = function(type, reverse) {
  2349. return this._list.fromEntrySeq().__iterator(type, reverse);
  2350. };
  2351. OrderedMap.prototype.__ensureOwner = function(ownerID) {
  2352. if (ownerID === this.__ownerID) {
  2353. return this;
  2354. }
  2355. var newMap = this._map.__ensureOwner(ownerID);
  2356. var newList = this._list.__ensureOwner(ownerID);
  2357. if (!ownerID) {
  2358. this.__ownerID = ownerID;
  2359. this._map = newMap;
  2360. this._list = newList;
  2361. return this;
  2362. }
  2363. return makeOrderedMap(newMap, newList, ownerID, this.__hash);
  2364. };
  2365. function isOrderedMap(maybeOrderedMap) {
  2366. return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
  2367. }
  2368. OrderedMap.isOrderedMap = isOrderedMap;
  2369. OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
  2370. OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
  2371. function makeOrderedMap(map, list, ownerID, hash) {
  2372. var omap = Object.create(OrderedMap.prototype);
  2373. omap.size = map ? map.size : 0;
  2374. omap._map = map;
  2375. omap._list = list;
  2376. omap.__ownerID = ownerID;
  2377. omap.__hash = hash;
  2378. return omap;
  2379. }
  2380. var EMPTY_ORDERED_MAP;
  2381. function emptyOrderedMap() {
  2382. return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
  2383. }
  2384. function updateOrderedMap(omap, k, v) {
  2385. var map = omap._map;
  2386. var list = omap._list;
  2387. var i = map.get(k);
  2388. var has = i !== undefined;
  2389. var newMap;
  2390. var newList;
  2391. if (v === NOT_SET) { // removed
  2392. if (!has) {
  2393. return omap;
  2394. }
  2395. if (list.size >= SIZE && list.size >= map.size * 2) {
  2396. newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
  2397. newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
  2398. if (omap.__ownerID) {
  2399. newMap.__ownerID = newList.__ownerID = omap.__ownerID;
  2400. }
  2401. } else {
  2402. newMap = map.remove(k);
  2403. newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
  2404. }
  2405. } else {
  2406. if (has) {
  2407. if (v === list.get(i)[1]) {
  2408. return omap;
  2409. }
  2410. newMap = map;
  2411. newList = list.set(i, [k, v]);
  2412. } else {
  2413. newMap = map.set(k, list.size);
  2414. newList = list.set(list.size, [k, v]);
  2415. }
  2416. }
  2417. if (omap.__ownerID) {
  2418. omap.size = newMap.size;
  2419. omap._map = newMap;
  2420. omap._list = newList;
  2421. omap.__hash = undefined;
  2422. return omap;
  2423. }
  2424. return makeOrderedMap(newMap, newList);
  2425. }
  2426. createClass(ToKeyedSequence, KeyedSeq);
  2427. function ToKeyedSequence(indexed, useKeys) {
  2428. this._iter = indexed;
  2429. this._useKeys = useKeys;
  2430. this.size = indexed.size;
  2431. }
  2432. ToKeyedSequence.prototype.get = function(key, notSetValue) {
  2433. return this._iter.get(key, notSetValue);
  2434. };
  2435. ToKeyedSequence.prototype.has = function(key) {
  2436. return this._iter.has(key);
  2437. };
  2438. ToKeyedSequence.prototype.valueSeq = function() {
  2439. return this._iter.valueSeq();
  2440. };
  2441. ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
  2442. var reversedSequence = reverseFactory(this, true);
  2443. if (!this._useKeys) {
  2444. reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
  2445. }
  2446. return reversedSequence;
  2447. };
  2448. ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
  2449. var mappedSequence = mapFactory(this, mapper, context);
  2450. if (!this._useKeys) {
  2451. mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
  2452. }
  2453. return mappedSequence;
  2454. };
  2455. ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2456. var ii;
  2457. return this._iter.__iterate(
  2458. this._useKeys ?
  2459. function(v, k) {return fn(v, k, this$0)} :
  2460. ((ii = reverse ? resolveSize(this) : 0),
  2461. function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
  2462. reverse
  2463. );
  2464. };
  2465. ToKeyedSequence.prototype.__iterator = function(type, reverse) {
  2466. if (this._useKeys) {
  2467. return this._iter.__iterator(type, reverse);
  2468. }
  2469. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2470. var ii = reverse ? resolveSize(this) : 0;
  2471. return new Iterator(function() {
  2472. var step = iterator.next();
  2473. return step.done ? step :
  2474. iteratorValue(type, reverse ? --ii : ii++, step.value, step);
  2475. });
  2476. };
  2477. ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
  2478. createClass(ToIndexedSequence, IndexedSeq);
  2479. function ToIndexedSequence(iter) {
  2480. this._iter = iter;
  2481. this.size = iter.size;
  2482. }
  2483. ToIndexedSequence.prototype.includes = function(value) {
  2484. return this._iter.includes(value);
  2485. };
  2486. ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2487. var iterations = 0;
  2488. return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
  2489. };
  2490. ToIndexedSequence.prototype.__iterator = function(type, reverse) {
  2491. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2492. var iterations = 0;
  2493. return new Iterator(function() {
  2494. var step = iterator.next();
  2495. return step.done ? step :
  2496. iteratorValue(type, iterations++, step.value, step)
  2497. });
  2498. };
  2499. createClass(ToSetSequence, SetSeq);
  2500. function ToSetSequence(iter) {
  2501. this._iter = iter;
  2502. this.size = iter.size;
  2503. }
  2504. ToSetSequence.prototype.has = function(key) {
  2505. return this._iter.includes(key);
  2506. };
  2507. ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2508. return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
  2509. };
  2510. ToSetSequence.prototype.__iterator = function(type, reverse) {
  2511. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2512. return new Iterator(function() {
  2513. var step = iterator.next();
  2514. return step.done ? step :
  2515. iteratorValue(type, step.value, step.value, step);
  2516. });
  2517. };
  2518. createClass(FromEntriesSequence, KeyedSeq);
  2519. function FromEntriesSequence(entries) {
  2520. this._iter = entries;
  2521. this.size = entries.size;
  2522. }
  2523. FromEntriesSequence.prototype.entrySeq = function() {
  2524. return this._iter.toSeq();
  2525. };
  2526. FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  2527. return this._iter.__iterate(function(entry ) {
  2528. // Check if entry exists first so array access doesn't throw for holes
  2529. // in the parent iteration.
  2530. if (entry) {
  2531. validateEntry(entry);
  2532. var indexedIterable = isIterable(entry);
  2533. return fn(
  2534. indexedIterable ? entry.get(1) : entry[1],
  2535. indexedIterable ? entry.get(0) : entry[0],
  2536. this$0
  2537. );
  2538. }
  2539. }, reverse);
  2540. };
  2541. FromEntriesSequence.prototype.__iterator = function(type, reverse) {
  2542. var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
  2543. return new Iterator(function() {
  2544. while (true) {
  2545. var step = iterator.next();
  2546. if (step.done) {
  2547. return step;
  2548. }
  2549. var entry = step.value;
  2550. // Check if entry exists first so array access doesn't throw for holes
  2551. // in the parent iteration.
  2552. if (entry) {
  2553. validateEntry(entry);
  2554. var indexedIterable = isIterable(entry);
  2555. return iteratorValue(
  2556. type,
  2557. indexedIterable ? entry.get(0) : entry[0],
  2558. indexedIterable ? entry.get(1) : entry[1],
  2559. step
  2560. );
  2561. }
  2562. }
  2563. });
  2564. };
  2565. ToIndexedSequence.prototype.cacheResult =
  2566. ToKeyedSequence.prototype.cacheResult =
  2567. ToSetSequence.prototype.cacheResult =
  2568. FromEntriesSequence.prototype.cacheResult =
  2569. cacheResultThrough;
  2570. function flipFactory(iterable) {
  2571. var flipSequence = makeSequence(iterable);
  2572. flipSequence._iter = iterable;
  2573. flipSequence.size = iterable.size;
  2574. flipSequence.flip = function() {return iterable};
  2575. flipSequence.reverse = function () {
  2576. var reversedSequence = iterable.reverse.apply(this); // super.reverse()
  2577. reversedSequence.flip = function() {return iterable.reverse()};
  2578. return reversedSequence;
  2579. };
  2580. flipSequence.has = function(key ) {return iterable.includes(key)};
  2581. flipSequence.includes = function(key ) {return iterable.has(key)};
  2582. flipSequence.cacheResult = cacheResultThrough;
  2583. flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2584. return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
  2585. };
  2586. flipSequence.__iteratorUncached = function(type, reverse) {
  2587. if (type === ITERATE_ENTRIES) {
  2588. var iterator = iterable.__iterator(type, reverse);
  2589. return new Iterator(function() {
  2590. var step = iterator.next();
  2591. if (!step.done) {
  2592. var k = step.value[0];
  2593. step.value[0] = step.value[1];
  2594. step.value[1] = k;
  2595. }
  2596. return step;
  2597. });
  2598. }
  2599. return iterable.__iterator(
  2600. type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
  2601. reverse
  2602. );
  2603. };
  2604. return flipSequence;
  2605. }
  2606. function mapFactory(iterable, mapper, context) {
  2607. var mappedSequence = makeSequence(iterable);
  2608. mappedSequence.size = iterable.size;
  2609. mappedSequence.has = function(key ) {return iterable.has(key)};
  2610. mappedSequence.get = function(key, notSetValue) {
  2611. var v = iterable.get(key, NOT_SET);
  2612. return v === NOT_SET ?
  2613. notSetValue :
  2614. mapper.call(context, v, key, iterable);
  2615. };
  2616. mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2617. return iterable.__iterate(
  2618. function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
  2619. reverse
  2620. );
  2621. };
  2622. mappedSequence.__iteratorUncached = function (type, reverse) {
  2623. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2624. return new Iterator(function() {
  2625. var step = iterator.next();
  2626. if (step.done) {
  2627. return step;
  2628. }
  2629. var entry = step.value;
  2630. var key = entry[0];
  2631. return iteratorValue(
  2632. type,
  2633. key,
  2634. mapper.call(context, entry[1], key, iterable),
  2635. step
  2636. );
  2637. });
  2638. };
  2639. return mappedSequence;
  2640. }
  2641. function reverseFactory(iterable, useKeys) {
  2642. var reversedSequence = makeSequence(iterable);
  2643. reversedSequence._iter = iterable;
  2644. reversedSequence.size = iterable.size;
  2645. reversedSequence.reverse = function() {return iterable};
  2646. if (iterable.flip) {
  2647. reversedSequence.flip = function () {
  2648. var flipSequence = flipFactory(iterable);
  2649. flipSequence.reverse = function() {return iterable.flip()};
  2650. return flipSequence;
  2651. };
  2652. }
  2653. reversedSequence.get = function(key, notSetValue)
  2654. {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
  2655. reversedSequence.has = function(key )
  2656. {return iterable.has(useKeys ? key : -1 - key)};
  2657. reversedSequence.includes = function(value ) {return iterable.includes(value)};
  2658. reversedSequence.cacheResult = cacheResultThrough;
  2659. reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
  2660. return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
  2661. };
  2662. reversedSequence.__iterator =
  2663. function(type, reverse) {return iterable.__iterator(type, !reverse)};
  2664. return reversedSequence;
  2665. }
  2666. function filterFactory(iterable, predicate, context, useKeys) {
  2667. var filterSequence = makeSequence(iterable);
  2668. if (useKeys) {
  2669. filterSequence.has = function(key ) {
  2670. var v = iterable.get(key, NOT_SET);
  2671. return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
  2672. };
  2673. filterSequence.get = function(key, notSetValue) {
  2674. var v = iterable.get(key, NOT_SET);
  2675. return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
  2676. v : notSetValue;
  2677. };
  2678. }
  2679. filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2680. var iterations = 0;
  2681. iterable.__iterate(function(v, k, c) {
  2682. if (predicate.call(context, v, k, c)) {
  2683. iterations++;
  2684. return fn(v, useKeys ? k : iterations - 1, this$0);
  2685. }
  2686. }, reverse);
  2687. return iterations;
  2688. };
  2689. filterSequence.__iteratorUncached = function (type, reverse) {
  2690. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2691. var iterations = 0;
  2692. return new Iterator(function() {
  2693. while (true) {
  2694. var step = iterator.next();
  2695. if (step.done) {
  2696. return step;
  2697. }
  2698. var entry = step.value;
  2699. var key = entry[0];
  2700. var value = entry[1];
  2701. if (predicate.call(context, value, key, iterable)) {
  2702. return iteratorValue(type, useKeys ? key : iterations++, value, step);
  2703. }
  2704. }
  2705. });
  2706. };
  2707. return filterSequence;
  2708. }
  2709. function countByFactory(iterable, grouper, context) {
  2710. var groups = Map().asMutable();
  2711. iterable.__iterate(function(v, k) {
  2712. groups.update(
  2713. grouper.call(context, v, k, iterable),
  2714. 0,
  2715. function(a ) {return a + 1}
  2716. );
  2717. });
  2718. return groups.asImmutable();
  2719. }
  2720. function groupByFactory(iterable, grouper, context) {
  2721. var isKeyedIter = isKeyed(iterable);
  2722. var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
  2723. iterable.__iterate(function(v, k) {
  2724. groups.update(
  2725. grouper.call(context, v, k, iterable),
  2726. function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
  2727. );
  2728. });
  2729. var coerce = iterableClass(iterable);
  2730. return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
  2731. }
  2732. function sliceFactory(iterable, begin, end, useKeys) {
  2733. var originalSize = iterable.size;
  2734. // Sanitize begin & end using this shorthand for ToInt32(argument)
  2735. // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
  2736. if (begin !== undefined) {
  2737. begin = begin | 0;
  2738. }
  2739. if (end !== undefined) {
  2740. end = end | 0;
  2741. }
  2742. if (wholeSlice(begin, end, originalSize)) {
  2743. return iterable;
  2744. }
  2745. var resolvedBegin = resolveBegin(begin, originalSize);
  2746. var resolvedEnd = resolveEnd(end, originalSize);
  2747. // begin or end will be NaN if they were provided as negative numbers and
  2748. // this iterable's size is unknown. In that case, cache first so there is
  2749. // a known size and these do not resolve to NaN.
  2750. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
  2751. return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
  2752. }
  2753. // Note: resolvedEnd is undefined when the original sequence's length is
  2754. // unknown and this slice did not supply an end and should contain all
  2755. // elements after resolvedBegin.
  2756. // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
  2757. var resolvedSize = resolvedEnd - resolvedBegin;
  2758. var sliceSize;
  2759. if (resolvedSize === resolvedSize) {
  2760. sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
  2761. }
  2762. var sliceSeq = makeSequence(iterable);
  2763. // If iterable.size is undefined, the size of the realized sliceSeq is
  2764. // unknown at this point unless the number of items to slice is 0
  2765. sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
  2766. if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
  2767. sliceSeq.get = function (index, notSetValue) {
  2768. index = wrapIndex(this, index);
  2769. return index >= 0 && index < sliceSize ?
  2770. iterable.get(index + resolvedBegin, notSetValue) :
  2771. notSetValue;
  2772. };
  2773. }
  2774. sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2775. if (sliceSize === 0) {
  2776. return 0;
  2777. }
  2778. if (reverse) {
  2779. return this.cacheResult().__iterate(fn, reverse);
  2780. }
  2781. var skipped = 0;
  2782. var isSkipping = true;
  2783. var iterations = 0;
  2784. iterable.__iterate(function(v, k) {
  2785. if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
  2786. iterations++;
  2787. return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
  2788. iterations !== sliceSize;
  2789. }
  2790. });
  2791. return iterations;
  2792. };
  2793. sliceSeq.__iteratorUncached = function(type, reverse) {
  2794. if (sliceSize !== 0 && reverse) {
  2795. return this.cacheResult().__iterator(type, reverse);
  2796. }
  2797. // Don't bother instantiating parent iterator if taking 0.
  2798. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
  2799. var skipped = 0;
  2800. var iterations = 0;
  2801. return new Iterator(function() {
  2802. while (skipped++ < resolvedBegin) {
  2803. iterator.next();
  2804. }
  2805. if (++iterations > sliceSize) {
  2806. return iteratorDone();
  2807. }
  2808. var step = iterator.next();
  2809. if (useKeys || type === ITERATE_VALUES) {
  2810. return step;
  2811. } else if (type === ITERATE_KEYS) {
  2812. return iteratorValue(type, iterations - 1, undefined, step);
  2813. } else {
  2814. return iteratorValue(type, iterations - 1, step.value[1], step);
  2815. }
  2816. });
  2817. };
  2818. return sliceSeq;
  2819. }
  2820. function takeWhileFactory(iterable, predicate, context) {
  2821. var takeSequence = makeSequence(iterable);
  2822. takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  2823. if (reverse) {
  2824. return this.cacheResult().__iterate(fn, reverse);
  2825. }
  2826. var iterations = 0;
  2827. iterable.__iterate(function(v, k, c)
  2828. {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
  2829. );
  2830. return iterations;
  2831. };
  2832. takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2833. if (reverse) {
  2834. return this.cacheResult().__iterator(type, reverse);
  2835. }
  2836. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2837. var iterating = true;
  2838. return new Iterator(function() {
  2839. if (!iterating) {
  2840. return iteratorDone();
  2841. }
  2842. var step = iterator.next();
  2843. if (step.done) {
  2844. return step;
  2845. }
  2846. var entry = step.value;
  2847. var k = entry[0];
  2848. var v = entry[1];
  2849. if (!predicate.call(context, v, k, this$0)) {
  2850. iterating = false;
  2851. return iteratorDone();
  2852. }
  2853. return type === ITERATE_ENTRIES ? step :
  2854. iteratorValue(type, k, v, step);
  2855. });
  2856. };
  2857. return takeSequence;
  2858. }
  2859. function skipWhileFactory(iterable, predicate, context, useKeys) {
  2860. var skipSequence = makeSequence(iterable);
  2861. skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
  2862. if (reverse) {
  2863. return this.cacheResult().__iterate(fn, reverse);
  2864. }
  2865. var isSkipping = true;
  2866. var iterations = 0;
  2867. iterable.__iterate(function(v, k, c) {
  2868. if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
  2869. iterations++;
  2870. return fn(v, useKeys ? k : iterations - 1, this$0);
  2871. }
  2872. });
  2873. return iterations;
  2874. };
  2875. skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
  2876. if (reverse) {
  2877. return this.cacheResult().__iterator(type, reverse);
  2878. }
  2879. var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
  2880. var skipping = true;
  2881. var iterations = 0;
  2882. return new Iterator(function() {
  2883. var step, k, v;
  2884. do {
  2885. step = iterator.next();
  2886. if (step.done) {
  2887. if (useKeys || type === ITERATE_VALUES) {
  2888. return step;
  2889. } else if (type === ITERATE_KEYS) {
  2890. return iteratorValue(type, iterations++, undefined, step);
  2891. } else {
  2892. return iteratorValue(type, iterations++, step.value[1], step);
  2893. }
  2894. }
  2895. var entry = step.value;
  2896. k = entry[0];
  2897. v = entry[1];
  2898. skipping && (skipping = predicate.call(context, v, k, this$0));
  2899. } while (skipping);
  2900. return type === ITERATE_ENTRIES ? step :
  2901. iteratorValue(type, k, v, step);
  2902. });
  2903. };
  2904. return skipSequence;
  2905. }
  2906. function concatFactory(iterable, values) {
  2907. var isKeyedIterable = isKeyed(iterable);
  2908. var iters = [iterable].concat(values).map(function(v ) {
  2909. if (!isIterable(v)) {
  2910. v = isKeyedIterable ?
  2911. keyedSeqFromValue(v) :
  2912. indexedSeqFromValue(Array.isArray(v) ? v : [v]);
  2913. } else if (isKeyedIterable) {
  2914. v = KeyedIterable(v);
  2915. }
  2916. return v;
  2917. }).filter(function(v ) {return v.size !== 0});
  2918. if (iters.length === 0) {
  2919. return iterable;
  2920. }
  2921. if (iters.length === 1) {
  2922. var singleton = iters[0];
  2923. if (singleton === iterable ||
  2924. isKeyedIterable && isKeyed(singleton) ||
  2925. isIndexed(iterable) && isIndexed(singleton)) {
  2926. return singleton;
  2927. }
  2928. }
  2929. var concatSeq = new ArraySeq(iters);
  2930. if (isKeyedIterable) {
  2931. concatSeq = concatSeq.toKeyedSeq();
  2932. } else if (!isIndexed(iterable)) {
  2933. concatSeq = concatSeq.toSetSeq();
  2934. }
  2935. concatSeq = concatSeq.flatten(true);
  2936. concatSeq.size = iters.reduce(
  2937. function(sum, seq) {
  2938. if (sum !== undefined) {
  2939. var size = seq.size;
  2940. if (size !== undefined) {
  2941. return sum + size;
  2942. }
  2943. }
  2944. },
  2945. 0
  2946. );
  2947. return concatSeq;
  2948. }
  2949. function flattenFactory(iterable, depth, useKeys) {
  2950. var flatSequence = makeSequence(iterable);
  2951. flatSequence.__iterateUncached = function(fn, reverse) {
  2952. var iterations = 0;
  2953. var stopped = false;
  2954. function flatDeep(iter, currentDepth) {var this$0 = this;
  2955. iter.__iterate(function(v, k) {
  2956. if ((!depth || currentDepth < depth) && isIterable(v)) {
  2957. flatDeep(v, currentDepth + 1);
  2958. } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
  2959. stopped = true;
  2960. }
  2961. return !stopped;
  2962. }, reverse);
  2963. }
  2964. flatDeep(iterable, 0);
  2965. return iterations;
  2966. };
  2967. flatSequence.__iteratorUncached = function(type, reverse) {
  2968. var iterator = iterable.__iterator(type, reverse);
  2969. var stack = [];
  2970. var iterations = 0;
  2971. return new Iterator(function() {
  2972. while (iterator) {
  2973. var step = iterator.next();
  2974. if (step.done !== false) {
  2975. iterator = stack.pop();
  2976. continue;
  2977. }
  2978. var v = step.value;
  2979. if (type === ITERATE_ENTRIES) {
  2980. v = v[1];
  2981. }
  2982. if ((!depth || stack.length < depth) && isIterable(v)) {
  2983. stack.push(iterator);
  2984. iterator = v.__iterator(type, reverse);
  2985. } else {
  2986. return useKeys ? step : iteratorValue(type, iterations++, v, step);
  2987. }
  2988. }
  2989. return iteratorDone();
  2990. });
  2991. };
  2992. return flatSequence;
  2993. }
  2994. function flatMapFactory(iterable, mapper, context) {
  2995. var coerce = iterableClass(iterable);
  2996. return iterable.toSeq().map(
  2997. function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
  2998. ).flatten(true);
  2999. }
  3000. function interposeFactory(iterable, separator) {
  3001. var interposedSequence = makeSequence(iterable);
  3002. interposedSequence.size = iterable.size && iterable.size * 2 -1;
  3003. interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
  3004. var iterations = 0;
  3005. iterable.__iterate(function(v, k)
  3006. {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
  3007. fn(v, iterations++, this$0) !== false},
  3008. reverse
  3009. );
  3010. return iterations;
  3011. };
  3012. interposedSequence.__iteratorUncached = function(type, reverse) {
  3013. var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
  3014. var iterations = 0;
  3015. var step;
  3016. return new Iterator(function() {
  3017. if (!step || iterations % 2) {
  3018. step = iterator.next();
  3019. if (step.done) {
  3020. return step;
  3021. }
  3022. }
  3023. return iterations % 2 ?
  3024. iteratorValue(type, iterations++, separator) :
  3025. iteratorValue(type, iterations++, step.value, step);
  3026. });
  3027. };
  3028. return interposedSequence;
  3029. }
  3030. function sortFactory(iterable, comparator, mapper) {
  3031. if (!comparator) {
  3032. comparator = defaultComparator;
  3033. }
  3034. var isKeyedIterable = isKeyed(iterable);
  3035. var index = 0;
  3036. var entries = iterable.toSeq().map(
  3037. function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
  3038. ).toArray();
  3039. entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
  3040. isKeyedIterable ?
  3041. function(v, i) { entries[i].length = 2; } :
  3042. function(v, i) { entries[i] = v[1]; }
  3043. );
  3044. return isKeyedIterable ? KeyedSeq(entries) :
  3045. isIndexed(iterable) ? IndexedSeq(entries) :
  3046. SetSeq(entries);
  3047. }
  3048. function maxFactory(iterable, comparator, mapper) {
  3049. if (!comparator) {
  3050. comparator = defaultComparator;
  3051. }
  3052. if (mapper) {
  3053. var entry = iterable.toSeq()
  3054. .map(function(v, k) {return [v, mapper(v, k, iterable)]})
  3055. .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
  3056. return entry && entry[0];
  3057. } else {
  3058. return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
  3059. }
  3060. }
  3061. function maxCompare(comparator, a, b) {
  3062. var comp = comparator(b, a);
  3063. // b is considered the new max if the comparator declares them equal, but
  3064. // they are not equal and b is in fact a nullish value.
  3065. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
  3066. }
  3067. function zipWithFactory(keyIter, zipper, iters) {
  3068. var zipSequence = makeSequence(keyIter);
  3069. zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
  3070. // Note: this a generic base implementation of __iterate in terms of
  3071. // __iterator which may be more generically useful in the future.
  3072. zipSequence.__iterate = function(fn, reverse) {
  3073. /* generic:
  3074. var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
  3075. var step;
  3076. var iterations = 0;
  3077. while (!(step = iterator.next()).done) {
  3078. iterations++;
  3079. if (fn(step.value[1], step.value[0], this) === false) {
  3080. break;
  3081. }
  3082. }
  3083. return iterations;
  3084. */
  3085. // indexed:
  3086. var iterator = this.__iterator(ITERATE_VALUES, reverse);
  3087. var step;
  3088. var iterations = 0;
  3089. while (!(step = iterator.next()).done) {
  3090. if (fn(step.value, iterations++, this) === false) {
  3091. break;
  3092. }
  3093. }
  3094. return iterations;
  3095. };
  3096. zipSequence.__iteratorUncached = function(type, reverse) {
  3097. var iterators = iters.map(function(i )
  3098. {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
  3099. );
  3100. var iterations = 0;
  3101. var isDone = false;
  3102. return new Iterator(function() {
  3103. var steps;
  3104. if (!isDone) {
  3105. steps = iterators.map(function(i ) {return i.next()});
  3106. isDone = steps.some(function(s ) {return s.done});
  3107. }
  3108. if (isDone) {
  3109. return iteratorDone();
  3110. }
  3111. return iteratorValue(
  3112. type,
  3113. iterations++,
  3114. zipper.apply(null, steps.map(function(s ) {return s.value}))
  3115. );
  3116. });
  3117. };
  3118. return zipSequence
  3119. }
  3120. // #pragma Helper Functions
  3121. function reify(iter, seq) {
  3122. return isSeq(iter) ? seq : iter.constructor(seq);
  3123. }
  3124. function validateEntry(entry) {
  3125. if (entry !== Object(entry)) {
  3126. throw new TypeError('Expected [K, V] tuple: ' + entry);
  3127. }
  3128. }
  3129. function resolveSize(iter) {
  3130. assertNotInfinite(iter.size);
  3131. return ensureSize(iter);
  3132. }
  3133. function iterableClass(iterable) {
  3134. return isKeyed(iterable) ? KeyedIterable :
  3135. isIndexed(iterable) ? IndexedIterable :
  3136. SetIterable;
  3137. }
  3138. function makeSequence(iterable) {
  3139. return Object.create(
  3140. (
  3141. isKeyed(iterable) ? KeyedSeq :
  3142. isIndexed(iterable) ? IndexedSeq :
  3143. SetSeq
  3144. ).prototype
  3145. );
  3146. }
  3147. function cacheResultThrough() {
  3148. if (this._iter.cacheResult) {
  3149. this._iter.cacheResult();
  3150. this.size = this._iter.size;
  3151. return this;
  3152. } else {
  3153. return Seq.prototype.cacheResult.call(this);
  3154. }
  3155. }
  3156. function defaultComparator(a, b) {
  3157. return a > b ? 1 : a < b ? -1 : 0;
  3158. }
  3159. function forceIterator(keyPath) {
  3160. var iter = getIterator(keyPath);
  3161. if (!iter) {
  3162. // Array might not be iterable in this environment, so we need a fallback
  3163. // to our wrapped type.
  3164. if (!isArrayLike(keyPath)) {
  3165. throw new TypeError('Expected iterable or array-like: ' + keyPath);
  3166. }
  3167. iter = getIterator(Iterable(keyPath));
  3168. }
  3169. return iter;
  3170. }
  3171. createClass(Record, KeyedCollection);
  3172. function Record(defaultValues, name) {
  3173. var hasInitialized;
  3174. var RecordType = function Record(values) {
  3175. if (values instanceof RecordType) {
  3176. return values;
  3177. }
  3178. if (!(this instanceof RecordType)) {
  3179. return new RecordType(values);
  3180. }
  3181. if (!hasInitialized) {
  3182. hasInitialized = true;
  3183. var keys = Object.keys(defaultValues);
  3184. setProps(RecordTypePrototype, keys);
  3185. RecordTypePrototype.size = keys.length;
  3186. RecordTypePrototype._name = name;
  3187. RecordTypePrototype._keys = keys;
  3188. RecordTypePrototype._defaultValues = defaultValues;
  3189. }
  3190. this._map = Map(values);
  3191. };
  3192. var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
  3193. RecordTypePrototype.constructor = RecordType;
  3194. return RecordType;
  3195. }
  3196. Record.prototype.toString = function() {
  3197. return this.__toString(recordName(this) + ' {', '}');
  3198. };
  3199. // @pragma Access
  3200. Record.prototype.has = function(k) {
  3201. return this._defaultValues.hasOwnProperty(k);
  3202. };
  3203. Record.prototype.get = function(k, notSetValue) {
  3204. if (!this.has(k)) {
  3205. return notSetValue;
  3206. }
  3207. var defaultVal = this._defaultValues[k];
  3208. return this._map ? this._map.get(k, defaultVal) : defaultVal;
  3209. };
  3210. // @pragma Modification
  3211. Record.prototype.clear = function() {
  3212. if (this.__ownerID) {
  3213. this._map && this._map.clear();
  3214. return this;
  3215. }
  3216. var RecordType = this.constructor;
  3217. return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
  3218. };
  3219. Record.prototype.set = function(k, v) {
  3220. if (!this.has(k)) {
  3221. throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
  3222. }
  3223. var newMap = this._map && this._map.set(k, v);
  3224. if (this.__ownerID || newMap === this._map) {
  3225. return this;
  3226. }
  3227. return makeRecord(this, newMap);
  3228. };
  3229. Record.prototype.remove = function(k) {
  3230. if (!this.has(k)) {
  3231. return this;
  3232. }
  3233. var newMap = this._map && this._map.remove(k);
  3234. if (this.__ownerID || newMap === this._map) {
  3235. return this;
  3236. }
  3237. return makeRecord(this, newMap);
  3238. };
  3239. Record.prototype.wasAltered = function() {
  3240. return this._map.wasAltered();
  3241. };
  3242. Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
  3243. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
  3244. };
  3245. Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3246. return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
  3247. };
  3248. Record.prototype.__ensureOwner = function(ownerID) {
  3249. if (ownerID === this.__ownerID) {
  3250. return this;
  3251. }
  3252. var newMap = this._map && this._map.__ensureOwner(ownerID);
  3253. if (!ownerID) {
  3254. this.__ownerID = ownerID;
  3255. this._map = newMap;
  3256. return this;
  3257. }
  3258. return makeRecord(this, newMap, ownerID);
  3259. };
  3260. var RecordPrototype = Record.prototype;
  3261. RecordPrototype[DELETE] = RecordPrototype.remove;
  3262. RecordPrototype.deleteIn =
  3263. RecordPrototype.removeIn = MapPrototype.removeIn;
  3264. RecordPrototype.merge = MapPrototype.merge;
  3265. RecordPrototype.mergeWith = MapPrototype.mergeWith;
  3266. RecordPrototype.mergeIn = MapPrototype.mergeIn;
  3267. RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
  3268. RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
  3269. RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
  3270. RecordPrototype.setIn = MapPrototype.setIn;
  3271. RecordPrototype.update = MapPrototype.update;
  3272. RecordPrototype.updateIn = MapPrototype.updateIn;
  3273. RecordPrototype.withMutations = MapPrototype.withMutations;
  3274. RecordPrototype.asMutable = MapPrototype.asMutable;
  3275. RecordPrototype.asImmutable = MapPrototype.asImmutable;
  3276. function makeRecord(likeRecord, map, ownerID) {
  3277. var record = Object.create(Object.getPrototypeOf(likeRecord));
  3278. record._map = map;
  3279. record.__ownerID = ownerID;
  3280. return record;
  3281. }
  3282. function recordName(record) {
  3283. return record._name || record.constructor.name || 'Record';
  3284. }
  3285. function setProps(prototype, names) {
  3286. try {
  3287. names.forEach(setProp.bind(undefined, prototype));
  3288. } catch (error) {
  3289. // Object.defineProperty failed. Probably IE8.
  3290. }
  3291. }
  3292. function setProp(prototype, name) {
  3293. Object.defineProperty(prototype, name, {
  3294. get: function() {
  3295. return this.get(name);
  3296. },
  3297. set: function(value) {
  3298. invariant(this.__ownerID, 'Cannot set on an immutable record.');
  3299. this.set(name, value);
  3300. }
  3301. });
  3302. }
  3303. createClass(Set, SetCollection);
  3304. // @pragma Construction
  3305. function Set(value) {
  3306. return value === null || value === undefined ? emptySet() :
  3307. isSet(value) && !isOrdered(value) ? value :
  3308. emptySet().withMutations(function(set ) {
  3309. var iter = SetIterable(value);
  3310. assertNotInfinite(iter.size);
  3311. iter.forEach(function(v ) {return set.add(v)});
  3312. });
  3313. }
  3314. Set.of = function(/*...values*/) {
  3315. return this(arguments);
  3316. };
  3317. Set.fromKeys = function(value) {
  3318. return this(KeyedIterable(value).keySeq());
  3319. };
  3320. Set.prototype.toString = function() {
  3321. return this.__toString('Set {', '}');
  3322. };
  3323. // @pragma Access
  3324. Set.prototype.has = function(value) {
  3325. return this._map.has(value);
  3326. };
  3327. // @pragma Modification
  3328. Set.prototype.add = function(value) {
  3329. return updateSet(this, this._map.set(value, true));
  3330. };
  3331. Set.prototype.remove = function(value) {
  3332. return updateSet(this, this._map.remove(value));
  3333. };
  3334. Set.prototype.clear = function() {
  3335. return updateSet(this, this._map.clear());
  3336. };
  3337. // @pragma Composition
  3338. Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
  3339. iters = iters.filter(function(x ) {return x.size !== 0});
  3340. if (iters.length === 0) {
  3341. return this;
  3342. }
  3343. if (this.size === 0 && !this.__ownerID && iters.length === 1) {
  3344. return this.constructor(iters[0]);
  3345. }
  3346. return this.withMutations(function(set ) {
  3347. for (var ii = 0; ii < iters.length; ii++) {
  3348. SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
  3349. }
  3350. });
  3351. };
  3352. Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
  3353. if (iters.length === 0) {
  3354. return this;
  3355. }
  3356. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3357. var originalSet = this;
  3358. return this.withMutations(function(set ) {
  3359. originalSet.forEach(function(value ) {
  3360. if (!iters.every(function(iter ) {return iter.includes(value)})) {
  3361. set.remove(value);
  3362. }
  3363. });
  3364. });
  3365. };
  3366. Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
  3367. if (iters.length === 0) {
  3368. return this;
  3369. }
  3370. iters = iters.map(function(iter ) {return SetIterable(iter)});
  3371. var originalSet = this;
  3372. return this.withMutations(function(set ) {
  3373. originalSet.forEach(function(value ) {
  3374. if (iters.some(function(iter ) {return iter.includes(value)})) {
  3375. set.remove(value);
  3376. }
  3377. });
  3378. });
  3379. };
  3380. Set.prototype.merge = function() {
  3381. return this.union.apply(this, arguments);
  3382. };
  3383. Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
  3384. return this.union.apply(this, iters);
  3385. };
  3386. Set.prototype.sort = function(comparator) {
  3387. // Late binding
  3388. return OrderedSet(sortFactory(this, comparator));
  3389. };
  3390. Set.prototype.sortBy = function(mapper, comparator) {
  3391. // Late binding
  3392. return OrderedSet(sortFactory(this, comparator, mapper));
  3393. };
  3394. Set.prototype.wasAltered = function() {
  3395. return this._map.wasAltered();
  3396. };
  3397. Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
  3398. return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
  3399. };
  3400. Set.prototype.__iterator = function(type, reverse) {
  3401. return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
  3402. };
  3403. Set.prototype.__ensureOwner = function(ownerID) {
  3404. if (ownerID === this.__ownerID) {
  3405. return this;
  3406. }
  3407. var newMap = this._map.__ensureOwner(ownerID);
  3408. if (!ownerID) {
  3409. this.__ownerID = ownerID;
  3410. this._map = newMap;
  3411. return this;
  3412. }
  3413. return this.__make(newMap, ownerID);
  3414. };
  3415. function isSet(maybeSet) {
  3416. return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
  3417. }
  3418. Set.isSet = isSet;
  3419. var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
  3420. var SetPrototype = Set.prototype;
  3421. SetPrototype[IS_SET_SENTINEL] = true;
  3422. SetPrototype[DELETE] = SetPrototype.remove;
  3423. SetPrototype.mergeDeep = SetPrototype.merge;
  3424. SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
  3425. SetPrototype.withMutations = MapPrototype.withMutations;
  3426. SetPrototype.asMutable = MapPrototype.asMutable;
  3427. SetPrototype.asImmutable = MapPrototype.asImmutable;
  3428. SetPrototype.__empty = emptySet;
  3429. SetPrototype.__make = makeSet;
  3430. function updateSet(set, newMap) {
  3431. if (set.__ownerID) {
  3432. set.size = newMap.size;
  3433. set._map = newMap;
  3434. return set;
  3435. }
  3436. return newMap === set._map ? set :
  3437. newMap.size === 0 ? set.__empty() :
  3438. set.__make(newMap);
  3439. }
  3440. function makeSet(map, ownerID) {
  3441. var set = Object.create(SetPrototype);
  3442. set.size = map ? map.size : 0;
  3443. set._map = map;
  3444. set.__ownerID = ownerID;
  3445. return set;
  3446. }
  3447. var EMPTY_SET;
  3448. function emptySet() {
  3449. return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
  3450. }
  3451. createClass(OrderedSet, Set);
  3452. // @pragma Construction
  3453. function OrderedSet(value) {
  3454. return value === null || value === undefined ? emptyOrderedSet() :
  3455. isOrderedSet(value) ? value :
  3456. emptyOrderedSet().withMutations(function(set ) {
  3457. var iter = SetIterable(value);
  3458. assertNotInfinite(iter.size);
  3459. iter.forEach(function(v ) {return set.add(v)});
  3460. });
  3461. }
  3462. OrderedSet.of = function(/*...values*/) {
  3463. return this(arguments);
  3464. };
  3465. OrderedSet.fromKeys = function(value) {
  3466. return this(KeyedIterable(value).keySeq());
  3467. };
  3468. OrderedSet.prototype.toString = function() {
  3469. return this.__toString('OrderedSet {', '}');
  3470. };
  3471. function isOrderedSet(maybeOrderedSet) {
  3472. return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
  3473. }
  3474. OrderedSet.isOrderedSet = isOrderedSet;
  3475. var OrderedSetPrototype = OrderedSet.prototype;
  3476. OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
  3477. OrderedSetPrototype.__empty = emptyOrderedSet;
  3478. OrderedSetPrototype.__make = makeOrderedSet;
  3479. function makeOrderedSet(map, ownerID) {
  3480. var set = Object.create(OrderedSetPrototype);
  3481. set.size = map ? map.size : 0;
  3482. set._map = map;
  3483. set.__ownerID = ownerID;
  3484. return set;
  3485. }
  3486. var EMPTY_ORDERED_SET;
  3487. function emptyOrderedSet() {
  3488. return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
  3489. }
  3490. createClass(Stack, IndexedCollection);
  3491. // @pragma Construction
  3492. function Stack(value) {
  3493. return value === null || value === undefined ? emptyStack() :
  3494. isStack(value) ? value :
  3495. emptyStack().unshiftAll(value);
  3496. }
  3497. Stack.of = function(/*...values*/) {
  3498. return this(arguments);
  3499. };
  3500. Stack.prototype.toString = function() {
  3501. return this.__toString('Stack [', ']');
  3502. };
  3503. // @pragma Access
  3504. Stack.prototype.get = function(index, notSetValue) {
  3505. var head = this._head;
  3506. index = wrapIndex(this, index);
  3507. while (head && index--) {
  3508. head = head.next;
  3509. }
  3510. return head ? head.value : notSetValue;
  3511. };
  3512. Stack.prototype.peek = function() {
  3513. return this._head && this._head.value;
  3514. };
  3515. // @pragma Modification
  3516. Stack.prototype.push = function(/*...values*/) {
  3517. if (arguments.length === 0) {
  3518. return this;
  3519. }
  3520. var newSize = this.size + arguments.length;
  3521. var head = this._head;
  3522. for (var ii = arguments.length - 1; ii >= 0; ii--) {
  3523. head = {
  3524. value: arguments[ii],
  3525. next: head
  3526. };
  3527. }
  3528. if (this.__ownerID) {
  3529. this.size = newSize;
  3530. this._head = head;
  3531. this.__hash = undefined;
  3532. this.__altered = true;
  3533. return this;
  3534. }
  3535. return makeStack(newSize, head);
  3536. };
  3537. Stack.prototype.pushAll = function(iter) {
  3538. iter = IndexedIterable(iter);
  3539. if (iter.size === 0) {
  3540. return this;
  3541. }
  3542. assertNotInfinite(iter.size);
  3543. var newSize = this.size;
  3544. var head = this._head;
  3545. iter.reverse().forEach(function(value ) {
  3546. newSize++;
  3547. head = {
  3548. value: value,
  3549. next: head
  3550. };
  3551. });
  3552. if (this.__ownerID) {
  3553. this.size = newSize;
  3554. this._head = head;
  3555. this.__hash = undefined;
  3556. this.__altered = true;
  3557. return this;
  3558. }
  3559. return makeStack(newSize, head);
  3560. };
  3561. Stack.prototype.pop = function() {
  3562. return this.slice(1);
  3563. };
  3564. Stack.prototype.unshift = function(/*...values*/) {
  3565. return this.push.apply(this, arguments);
  3566. };
  3567. Stack.prototype.unshiftAll = function(iter) {
  3568. return this.pushAll(iter);
  3569. };
  3570. Stack.prototype.shift = function() {
  3571. return this.pop.apply(this, arguments);
  3572. };
  3573. Stack.prototype.clear = function() {
  3574. if (this.size === 0) {
  3575. return this;
  3576. }
  3577. if (this.__ownerID) {
  3578. this.size = 0;
  3579. this._head = undefined;
  3580. this.__hash = undefined;
  3581. this.__altered = true;
  3582. return this;
  3583. }
  3584. return emptyStack();
  3585. };
  3586. Stack.prototype.slice = function(begin, end) {
  3587. if (wholeSlice(begin, end, this.size)) {
  3588. return this;
  3589. }
  3590. var resolvedBegin = resolveBegin(begin, this.size);
  3591. var resolvedEnd = resolveEnd(end, this.size);
  3592. if (resolvedEnd !== this.size) {
  3593. // super.slice(begin, end);
  3594. return IndexedCollection.prototype.slice.call(this, begin, end);
  3595. }
  3596. var newSize = this.size - resolvedBegin;
  3597. var head = this._head;
  3598. while (resolvedBegin--) {
  3599. head = head.next;
  3600. }
  3601. if (this.__ownerID) {
  3602. this.size = newSize;
  3603. this._head = head;
  3604. this.__hash = undefined;
  3605. this.__altered = true;
  3606. return this;
  3607. }
  3608. return makeStack(newSize, head);
  3609. };
  3610. // @pragma Mutability
  3611. Stack.prototype.__ensureOwner = function(ownerID) {
  3612. if (ownerID === this.__ownerID) {
  3613. return this;
  3614. }
  3615. if (!ownerID) {
  3616. this.__ownerID = ownerID;
  3617. this.__altered = false;
  3618. return this;
  3619. }
  3620. return makeStack(this.size, this._head, ownerID, this.__hash);
  3621. };
  3622. // @pragma Iteration
  3623. Stack.prototype.__iterate = function(fn, reverse) {
  3624. if (reverse) {
  3625. return this.reverse().__iterate(fn);
  3626. }
  3627. var iterations = 0;
  3628. var node = this._head;
  3629. while (node) {
  3630. if (fn(node.value, iterations++, this) === false) {
  3631. break;
  3632. }
  3633. node = node.next;
  3634. }
  3635. return iterations;
  3636. };
  3637. Stack.prototype.__iterator = function(type, reverse) {
  3638. if (reverse) {
  3639. return this.reverse().__iterator(type);
  3640. }
  3641. var iterations = 0;
  3642. var node = this._head;
  3643. return new Iterator(function() {
  3644. if (node) {
  3645. var value = node.value;
  3646. node = node.next;
  3647. return iteratorValue(type, iterations++, value);
  3648. }
  3649. return iteratorDone();
  3650. });
  3651. };
  3652. function isStack(maybeStack) {
  3653. return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
  3654. }
  3655. Stack.isStack = isStack;
  3656. var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
  3657. var StackPrototype = Stack.prototype;
  3658. StackPrototype[IS_STACK_SENTINEL] = true;
  3659. StackPrototype.withMutations = MapPrototype.withMutations;
  3660. StackPrototype.asMutable = MapPrototype.asMutable;
  3661. StackPrototype.asImmutable = MapPrototype.asImmutable;
  3662. StackPrototype.wasAltered = MapPrototype.wasAltered;
  3663. function makeStack(size, head, ownerID, hash) {
  3664. var map = Object.create(StackPrototype);
  3665. map.size = size;
  3666. map._head = head;
  3667. map.__ownerID = ownerID;
  3668. map.__hash = hash;
  3669. map.__altered = false;
  3670. return map;
  3671. }
  3672. var EMPTY_STACK;
  3673. function emptyStack() {
  3674. return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
  3675. }
  3676. /**
  3677. * Contributes additional methods to a constructor
  3678. */
  3679. function mixin(ctor, methods) {
  3680. var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
  3681. Object.keys(methods).forEach(keyCopier);
  3682. Object.getOwnPropertySymbols &&
  3683. Object.getOwnPropertySymbols(methods).forEach(keyCopier);
  3684. return ctor;
  3685. }
  3686. Iterable.Iterator = Iterator;
  3687. mixin(Iterable, {
  3688. // ### Conversion to other types
  3689. toArray: function() {
  3690. assertNotInfinite(this.size);
  3691. var array = new Array(this.size || 0);
  3692. this.valueSeq().__iterate(function(v, i) { array[i] = v; });
  3693. return array;
  3694. },
  3695. toIndexedSeq: function() {
  3696. return new ToIndexedSequence(this);
  3697. },
  3698. toJS: function() {
  3699. return this.toSeq().map(
  3700. function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
  3701. ).__toJS();
  3702. },
  3703. toJSON: function() {
  3704. return this.toSeq().map(
  3705. function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
  3706. ).__toJS();
  3707. },
  3708. toKeyedSeq: function() {
  3709. return new ToKeyedSequence(this, true);
  3710. },
  3711. toMap: function() {
  3712. // Use Late Binding here to solve the circular dependency.
  3713. return Map(this.toKeyedSeq());
  3714. },
  3715. toObject: function() {
  3716. assertNotInfinite(this.size);
  3717. var object = {};
  3718. this.__iterate(function(v, k) { object[k] = v; });
  3719. return object;
  3720. },
  3721. toOrderedMap: function() {
  3722. // Use Late Binding here to solve the circular dependency.
  3723. return OrderedMap(this.toKeyedSeq());
  3724. },
  3725. toOrderedSet: function() {
  3726. // Use Late Binding here to solve the circular dependency.
  3727. return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
  3728. },
  3729. toSet: function() {
  3730. // Use Late Binding here to solve the circular dependency.
  3731. return Set(isKeyed(this) ? this.valueSeq() : this);
  3732. },
  3733. toSetSeq: function() {
  3734. return new ToSetSequence(this);
  3735. },
  3736. toSeq: function() {
  3737. return isIndexed(this) ? this.toIndexedSeq() :
  3738. isKeyed(this) ? this.toKeyedSeq() :
  3739. this.toSetSeq();
  3740. },
  3741. toStack: function() {
  3742. // Use Late Binding here to solve the circular dependency.
  3743. return Stack(isKeyed(this) ? this.valueSeq() : this);
  3744. },
  3745. toList: function() {
  3746. // Use Late Binding here to solve the circular dependency.
  3747. return List(isKeyed(this) ? this.valueSeq() : this);
  3748. },
  3749. // ### Common JavaScript methods and properties
  3750. toString: function() {
  3751. return '[Iterable]';
  3752. },
  3753. __toString: function(head, tail) {
  3754. if (this.size === 0) {
  3755. return head + tail;
  3756. }
  3757. return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
  3758. },
  3759. // ### ES6 Collection methods (ES6 Array and Map)
  3760. concat: function() {var values = SLICE$0.call(arguments, 0);
  3761. return reify(this, concatFactory(this, values));
  3762. },
  3763. includes: function(searchValue) {
  3764. return this.some(function(value ) {return is(value, searchValue)});
  3765. },
  3766. entries: function() {
  3767. return this.__iterator(ITERATE_ENTRIES);
  3768. },
  3769. every: function(predicate, context) {
  3770. assertNotInfinite(this.size);
  3771. var returnValue = true;
  3772. this.__iterate(function(v, k, c) {
  3773. if (!predicate.call(context, v, k, c)) {
  3774. returnValue = false;
  3775. return false;
  3776. }
  3777. });
  3778. return returnValue;
  3779. },
  3780. filter: function(predicate, context) {
  3781. return reify(this, filterFactory(this, predicate, context, true));
  3782. },
  3783. find: function(predicate, context, notSetValue) {
  3784. var entry = this.findEntry(predicate, context);
  3785. return entry ? entry[1] : notSetValue;
  3786. },
  3787. findEntry: function(predicate, context) {
  3788. var found;
  3789. this.__iterate(function(v, k, c) {
  3790. if (predicate.call(context, v, k, c)) {
  3791. found = [k, v];
  3792. return false;
  3793. }
  3794. });
  3795. return found;
  3796. },
  3797. findLastEntry: function(predicate, context) {
  3798. return this.toSeq().reverse().findEntry(predicate, context);
  3799. },
  3800. forEach: function(sideEffect, context) {
  3801. assertNotInfinite(this.size);
  3802. return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
  3803. },
  3804. join: function(separator) {
  3805. assertNotInfinite(this.size);
  3806. separator = separator !== undefined ? '' + separator : ',';
  3807. var joined = '';
  3808. var isFirst = true;
  3809. this.__iterate(function(v ) {
  3810. isFirst ? (isFirst = false) : (joined += separator);
  3811. joined += v !== null && v !== undefined ? v.toString() : '';
  3812. });
  3813. return joined;
  3814. },
  3815. keys: function() {
  3816. return this.__iterator(ITERATE_KEYS);
  3817. },
  3818. map: function(mapper, context) {
  3819. return reify(this, mapFactory(this, mapper, context));
  3820. },
  3821. reduce: function(reducer, initialReduction, context) {
  3822. assertNotInfinite(this.size);
  3823. var reduction;
  3824. var useFirst;
  3825. if (arguments.length < 2) {
  3826. useFirst = true;
  3827. } else {
  3828. reduction = initialReduction;
  3829. }
  3830. this.__iterate(function(v, k, c) {
  3831. if (useFirst) {
  3832. useFirst = false;
  3833. reduction = v;
  3834. } else {
  3835. reduction = reducer.call(context, reduction, v, k, c);
  3836. }
  3837. });
  3838. return reduction;
  3839. },
  3840. reduceRight: function(reducer, initialReduction, context) {
  3841. var reversed = this.toKeyedSeq().reverse();
  3842. return reversed.reduce.apply(reversed, arguments);
  3843. },
  3844. reverse: function() {
  3845. return reify(this, reverseFactory(this, true));
  3846. },
  3847. slice: function(begin, end) {
  3848. return reify(this, sliceFactory(this, begin, end, true));
  3849. },
  3850. some: function(predicate, context) {
  3851. return !this.every(not(predicate), context);
  3852. },
  3853. sort: function(comparator) {
  3854. return reify(this, sortFactory(this, comparator));
  3855. },
  3856. values: function() {
  3857. return this.__iterator(ITERATE_VALUES);
  3858. },
  3859. // ### More sequential methods
  3860. butLast: function() {
  3861. return this.slice(0, -1);
  3862. },
  3863. isEmpty: function() {
  3864. return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
  3865. },
  3866. count: function(predicate, context) {
  3867. return ensureSize(
  3868. predicate ? this.toSeq().filter(predicate, context) : this
  3869. );
  3870. },
  3871. countBy: function(grouper, context) {
  3872. return countByFactory(this, grouper, context);
  3873. },
  3874. equals: function(other) {
  3875. return deepEqual(this, other);
  3876. },
  3877. entrySeq: function() {
  3878. var iterable = this;
  3879. if (iterable._cache) {
  3880. // We cache as an entries array, so we can just return the cache!
  3881. return new ArraySeq(iterable._cache);
  3882. }
  3883. var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
  3884. entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
  3885. return entriesSequence;
  3886. },
  3887. filterNot: function(predicate, context) {
  3888. return this.filter(not(predicate), context);
  3889. },
  3890. findLast: function(predicate, context, notSetValue) {
  3891. return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
  3892. },
  3893. first: function() {
  3894. return this.find(returnTrue);
  3895. },
  3896. flatMap: function(mapper, context) {
  3897. return reify(this, flatMapFactory(this, mapper, context));
  3898. },
  3899. flatten: function(depth) {
  3900. return reify(this, flattenFactory(this, depth, true));
  3901. },
  3902. fromEntrySeq: function() {
  3903. return new FromEntriesSequence(this);
  3904. },
  3905. get: function(searchKey, notSetValue) {
  3906. return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
  3907. },
  3908. getIn: function(searchKeyPath, notSetValue) {
  3909. var nested = this;
  3910. // Note: in an ES6 environment, we would prefer:
  3911. // for (var key of searchKeyPath) {
  3912. var iter = forceIterator(searchKeyPath);
  3913. var step;
  3914. while (!(step = iter.next()).done) {
  3915. var key = step.value;
  3916. nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
  3917. if (nested === NOT_SET) {
  3918. return notSetValue;
  3919. }
  3920. }
  3921. return nested;
  3922. },
  3923. groupBy: function(grouper, context) {
  3924. return groupByFactory(this, grouper, context);
  3925. },
  3926. has: function(searchKey) {
  3927. return this.get(searchKey, NOT_SET) !== NOT_SET;
  3928. },
  3929. hasIn: function(searchKeyPath) {
  3930. return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
  3931. },
  3932. isSubset: function(iter) {
  3933. iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
  3934. return this.every(function(value ) {return iter.includes(value)});
  3935. },
  3936. isSuperset: function(iter) {
  3937. iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
  3938. return iter.isSubset(this);
  3939. },
  3940. keySeq: function() {
  3941. return this.toSeq().map(keyMapper).toIndexedSeq();
  3942. },
  3943. last: function() {
  3944. return this.toSeq().reverse().first();
  3945. },
  3946. max: function(comparator) {
  3947. return maxFactory(this, comparator);
  3948. },
  3949. maxBy: function(mapper, comparator) {
  3950. return maxFactory(this, comparator, mapper);
  3951. },
  3952. min: function(comparator) {
  3953. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
  3954. },
  3955. minBy: function(mapper, comparator) {
  3956. return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
  3957. },
  3958. rest: function() {
  3959. return this.slice(1);
  3960. },
  3961. skip: function(amount) {
  3962. return this.slice(Math.max(0, amount));
  3963. },
  3964. skipLast: function(amount) {
  3965. return reify(this, this.toSeq().reverse().skip(amount).reverse());
  3966. },
  3967. skipWhile: function(predicate, context) {
  3968. return reify(this, skipWhileFactory(this, predicate, context, true));
  3969. },
  3970. skipUntil: function(predicate, context) {
  3971. return this.skipWhile(not(predicate), context);
  3972. },
  3973. sortBy: function(mapper, comparator) {
  3974. return reify(this, sortFactory(this, comparator, mapper));
  3975. },
  3976. take: function(amount) {
  3977. return this.slice(0, Math.max(0, amount));
  3978. },
  3979. takeLast: function(amount) {
  3980. return reify(this, this.toSeq().reverse().take(amount).reverse());
  3981. },
  3982. takeWhile: function(predicate, context) {
  3983. return reify(this, takeWhileFactory(this, predicate, context));
  3984. },
  3985. takeUntil: function(predicate, context) {
  3986. return this.takeWhile(not(predicate), context);
  3987. },
  3988. valueSeq: function() {
  3989. return this.toIndexedSeq();
  3990. },
  3991. // ### Hashable Object
  3992. hashCode: function() {
  3993. return this.__hash || (this.__hash = hashIterable(this));
  3994. }
  3995. // ### Internal
  3996. // abstract __iterate(fn, reverse)
  3997. // abstract __iterator(type, reverse)
  3998. });
  3999. // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
  4000. // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
  4001. // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
  4002. // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
  4003. var IterablePrototype = Iterable.prototype;
  4004. IterablePrototype[IS_ITERABLE_SENTINEL] = true;
  4005. IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
  4006. IterablePrototype.__toJS = IterablePrototype.toArray;
  4007. IterablePrototype.__toStringMapper = quoteString;
  4008. IterablePrototype.inspect =
  4009. IterablePrototype.toSource = function() { return this.toString(); };
  4010. IterablePrototype.chain = IterablePrototype.flatMap;
  4011. IterablePrototype.contains = IterablePrototype.includes;
  4012. // Temporary warning about using length
  4013. (function () {
  4014. try {
  4015. Object.defineProperty(IterablePrototype, 'length', {
  4016. get: function () {
  4017. if (!Iterable.noLengthWarning) {
  4018. var stack;
  4019. try {
  4020. throw new Error();
  4021. } catch (error) {
  4022. stack = error.stack;
  4023. }
  4024. if (stack.indexOf('_wrapObject') === -1) {
  4025. console && console.warn && console.warn(
  4026. 'iterable.length has been deprecated, '+
  4027. 'use iterable.size or iterable.count(). '+
  4028. 'This warning will become a silent error in a future version. ' +
  4029. stack
  4030. );
  4031. return this.size;
  4032. }
  4033. }
  4034. }
  4035. });
  4036. } catch (e) {}
  4037. })();
  4038. mixin(KeyedIterable, {
  4039. // ### More sequential methods
  4040. flip: function() {
  4041. return reify(this, flipFactory(this));
  4042. },
  4043. findKey: function(predicate, context) {
  4044. var entry = this.findEntry(predicate, context);
  4045. return entry && entry[0];
  4046. },
  4047. findLastKey: function(predicate, context) {
  4048. return this.toSeq().reverse().findKey(predicate, context);
  4049. },
  4050. keyOf: function(searchValue) {
  4051. return this.findKey(function(value ) {return is(value, searchValue)});
  4052. },
  4053. lastKeyOf: function(searchValue) {
  4054. return this.findLastKey(function(value ) {return is(value, searchValue)});
  4055. },
  4056. mapEntries: function(mapper, context) {var this$0 = this;
  4057. var iterations = 0;
  4058. return reify(this,
  4059. this.toSeq().map(
  4060. function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
  4061. ).fromEntrySeq()
  4062. );
  4063. },
  4064. mapKeys: function(mapper, context) {var this$0 = this;
  4065. return reify(this,
  4066. this.toSeq().flip().map(
  4067. function(k, v) {return mapper.call(context, k, v, this$0)}
  4068. ).flip()
  4069. );
  4070. }
  4071. });
  4072. var KeyedIterablePrototype = KeyedIterable.prototype;
  4073. KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
  4074. KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
  4075. KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
  4076. KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
  4077. mixin(IndexedIterable, {
  4078. // ### Conversion to other types
  4079. toKeyedSeq: function() {
  4080. return new ToKeyedSequence(this, false);
  4081. },
  4082. // ### ES6 Collection methods (ES6 Array and Map)
  4083. filter: function(predicate, context) {
  4084. return reify(this, filterFactory(this, predicate, context, false));
  4085. },
  4086. findIndex: function(predicate, context) {
  4087. var entry = this.findEntry(predicate, context);
  4088. return entry ? entry[0] : -1;
  4089. },
  4090. indexOf: function(searchValue) {
  4091. var key = this.toKeyedSeq().keyOf(searchValue);
  4092. return key === undefined ? -1 : key;
  4093. },
  4094. lastIndexOf: function(searchValue) {
  4095. var key = this.toKeyedSeq().reverse().keyOf(searchValue);
  4096. return key === undefined ? -1 : key;
  4097. // var index =
  4098. // return this.toSeq().reverse().indexOf(searchValue);
  4099. },
  4100. reverse: function() {
  4101. return reify(this, reverseFactory(this, false));
  4102. },
  4103. slice: function(begin, end) {
  4104. return reify(this, sliceFactory(this, begin, end, false));
  4105. },
  4106. splice: function(index, removeNum /*, ...values*/) {
  4107. var numArgs = arguments.length;
  4108. removeNum = Math.max(removeNum | 0, 0);
  4109. if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
  4110. return this;
  4111. }
  4112. // If index is negative, it should resolve relative to the size of the
  4113. // collection. However size may be expensive to compute if not cached, so
  4114. // only call count() if the number is in fact negative.
  4115. index = resolveBegin(index, index < 0 ? this.count() : this.size);
  4116. var spliced = this.slice(0, index);
  4117. return reify(
  4118. this,
  4119. numArgs === 1 ?
  4120. spliced :
  4121. spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
  4122. );
  4123. },
  4124. // ### More collection methods
  4125. findLastIndex: function(predicate, context) {
  4126. var key = this.toKeyedSeq().findLastKey(predicate, context);
  4127. return key === undefined ? -1 : key;
  4128. },
  4129. first: function() {
  4130. return this.get(0);
  4131. },
  4132. flatten: function(depth) {
  4133. return reify(this, flattenFactory(this, depth, false));
  4134. },
  4135. get: function(index, notSetValue) {
  4136. index = wrapIndex(this, index);
  4137. return (index < 0 || (this.size === Infinity ||
  4138. (this.size !== undefined && index > this.size))) ?
  4139. notSetValue :
  4140. this.find(function(_, key) {return key === index}, undefined, notSetValue);
  4141. },
  4142. has: function(index) {
  4143. index = wrapIndex(this, index);
  4144. return index >= 0 && (this.size !== undefined ?
  4145. this.size === Infinity || index < this.size :
  4146. this.indexOf(index) !== -1
  4147. );
  4148. },
  4149. interpose: function(separator) {
  4150. return reify(this, interposeFactory(this, separator));
  4151. },
  4152. interleave: function(/*...iterables*/) {
  4153. var iterables = [this].concat(arrCopy(arguments));
  4154. var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
  4155. var interleaved = zipped.flatten(true);
  4156. if (zipped.size) {
  4157. interleaved.size = zipped.size * iterables.length;
  4158. }
  4159. return reify(this, interleaved);
  4160. },
  4161. last: function() {
  4162. return this.get(-1);
  4163. },
  4164. skipWhile: function(predicate, context) {
  4165. return reify(this, skipWhileFactory(this, predicate, context, false));
  4166. },
  4167. zip: function(/*, ...iterables */) {
  4168. var iterables = [this].concat(arrCopy(arguments));
  4169. return reify(this, zipWithFactory(this, defaultZipper, iterables));
  4170. },
  4171. zipWith: function(zipper/*, ...iterables */) {
  4172. var iterables = arrCopy(arguments);
  4173. iterables[0] = this;
  4174. return reify(this, zipWithFactory(this, zipper, iterables));
  4175. }
  4176. });
  4177. IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
  4178. IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
  4179. mixin(SetIterable, {
  4180. // ### ES6 Collection methods (ES6 Array and Map)
  4181. get: function(value, notSetValue) {
  4182. return this.has(value) ? value : notSetValue;
  4183. },
  4184. includes: function(value) {
  4185. return this.has(value);
  4186. },
  4187. // ### More sequential methods
  4188. keySeq: function() {
  4189. return this.valueSeq();
  4190. }
  4191. });
  4192. SetIterable.prototype.has = IterablePrototype.includes;
  4193. // Mixin subclasses
  4194. mixin(KeyedSeq, KeyedIterable.prototype);
  4195. mixin(IndexedSeq, IndexedIterable.prototype);
  4196. mixin(SetSeq, SetIterable.prototype);
  4197. mixin(KeyedCollection, KeyedIterable.prototype);
  4198. mixin(IndexedCollection, IndexedIterable.prototype);
  4199. mixin(SetCollection, SetIterable.prototype);
  4200. // #pragma Helper functions
  4201. function keyMapper(v, k) {
  4202. return k;
  4203. }
  4204. function entryMapper(v, k) {
  4205. return [k, v];
  4206. }
  4207. function not(predicate) {
  4208. return function() {
  4209. return !predicate.apply(this, arguments);
  4210. }
  4211. }
  4212. function neg(predicate) {
  4213. return function() {
  4214. return -predicate.apply(this, arguments);
  4215. }
  4216. }
  4217. function quoteString(value) {
  4218. return typeof value === 'string' ? JSON.stringify(value) : value;
  4219. }
  4220. function defaultZipper() {
  4221. return arrCopy(arguments);
  4222. }
  4223. function defaultNegComparator(a, b) {
  4224. return a < b ? 1 : a > b ? -1 : 0;
  4225. }
  4226. function hashIterable(iterable) {
  4227. if (iterable.size === Infinity) {
  4228. return 0;
  4229. }
  4230. var ordered = isOrdered(iterable);
  4231. var keyed = isKeyed(iterable);
  4232. var h = ordered ? 1 : 0;
  4233. var size = iterable.__iterate(
  4234. keyed ?
  4235. ordered ?
  4236. function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
  4237. function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
  4238. ordered ?
  4239. function(v ) { h = 31 * h + hash(v) | 0; } :
  4240. function(v ) { h = h + hash(v) | 0; }
  4241. );
  4242. return murmurHashOfSize(size, h);
  4243. }
  4244. function murmurHashOfSize(size, h) {
  4245. h = imul(h, 0xCC9E2D51);
  4246. h = imul(h << 15 | h >>> -15, 0x1B873593);
  4247. h = imul(h << 13 | h >>> -13, 5);
  4248. h = (h + 0xE6546B64 | 0) ^ size;
  4249. h = imul(h ^ h >>> 16, 0x85EBCA6B);
  4250. h = imul(h ^ h >>> 13, 0xC2B2AE35);
  4251. h = smi(h ^ h >>> 16);
  4252. return h;
  4253. }
  4254. function hashMerge(a, b) {
  4255. return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
  4256. }
  4257. var Immutable = {
  4258. Iterable: Iterable,
  4259. Seq: Seq,
  4260. Collection: Collection,
  4261. Map: Map,
  4262. OrderedMap: OrderedMap,
  4263. List: List,
  4264. Stack: Stack,
  4265. Set: Set,
  4266. OrderedSet: OrderedSet,
  4267. Record: Record,
  4268. Range: Range,
  4269. Repeat: Repeat,
  4270. is: is,
  4271. fromJS: fromJS
  4272. };
  4273. return Immutable;
  4274. }));
  4275. });
  4276. var OrderedMap = immutable.OrderedMap;
  4277. var BlockMapBuilder = {
  4278. createFromArray: function createFromArray(blocks) {
  4279. return OrderedMap(blocks.map(function (block) {
  4280. return [block.getKey(), block];
  4281. }));
  4282. }
  4283. };
  4284. var BlockMapBuilder_1 = BlockMapBuilder;
  4285. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4286. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4287. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4288. var Map = immutable.Map,
  4289. OrderedSet = immutable.OrderedSet,
  4290. Record = immutable.Record;
  4291. // Immutable.map is typed such that the value for every key in the map
  4292. // must be the same type
  4293. var EMPTY_SET = OrderedSet();
  4294. var defaultRecord = {
  4295. style: EMPTY_SET,
  4296. entity: null
  4297. };
  4298. var CharacterMetadataRecord = Record(defaultRecord);
  4299. var CharacterMetadata = function (_CharacterMetadataRec) {
  4300. _inherits(CharacterMetadata, _CharacterMetadataRec);
  4301. function CharacterMetadata() {
  4302. _classCallCheck(this, CharacterMetadata);
  4303. return _possibleConstructorReturn(this, _CharacterMetadataRec.apply(this, arguments));
  4304. }
  4305. CharacterMetadata.prototype.getStyle = function getStyle() {
  4306. return this.get('style');
  4307. };
  4308. CharacterMetadata.prototype.getEntity = function getEntity() {
  4309. return this.get('entity');
  4310. };
  4311. CharacterMetadata.prototype.hasStyle = function hasStyle(style) {
  4312. return this.getStyle().includes(style);
  4313. };
  4314. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  4315. var withStyle = record.set('style', record.getStyle().add(style));
  4316. return CharacterMetadata.create(withStyle);
  4317. };
  4318. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  4319. var withoutStyle = record.set('style', record.getStyle().remove(style));
  4320. return CharacterMetadata.create(withoutStyle);
  4321. };
  4322. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  4323. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  4324. return CharacterMetadata.create(withEntity);
  4325. };
  4326. /**
  4327. * Use this function instead of the `CharacterMetadata` constructor.
  4328. * Since most content generally uses only a very small number of
  4329. * style/entity permutations, we can reuse these objects as often as
  4330. * possible.
  4331. */
  4332. CharacterMetadata.create = function create(config) {
  4333. if (!config) {
  4334. return EMPTY;
  4335. }
  4336. var defaultConfig = {
  4337. style: EMPTY_SET,
  4338. entity: null
  4339. };
  4340. // Fill in unspecified properties, if necessary.
  4341. var configMap = Map(defaultConfig).merge(config);
  4342. var existing = pool.get(configMap);
  4343. if (existing) {
  4344. return existing;
  4345. }
  4346. var newCharacter = new CharacterMetadata(configMap);
  4347. pool = pool.set(configMap, newCharacter);
  4348. return newCharacter;
  4349. };
  4350. return CharacterMetadata;
  4351. }(CharacterMetadataRecord);
  4352. var EMPTY = new CharacterMetadata();
  4353. var pool = Map([[Map(defaultRecord), EMPTY]]);
  4354. CharacterMetadata.EMPTY = EMPTY;
  4355. var CharacterMetadata_1 = CharacterMetadata;
  4356. /**
  4357. * Copyright (c) 2013-present, Facebook, Inc.
  4358. * All rights reserved.
  4359. *
  4360. * This source code is licensed under the BSD-style license found in the
  4361. * LICENSE file in the root directory of this source tree. An additional grant
  4362. * of patent rights can be found in the PATENTS file in the same directory.
  4363. *
  4364. * @providesModule findRangesImmutable
  4365. * @format
  4366. *
  4367. */
  4368. /**
  4369. * Search through an array to find contiguous stretches of elements that
  4370. * match a specified filter function.
  4371. *
  4372. * When ranges are found, execute a specified `found` function to supply
  4373. * the values to the caller.
  4374. */
  4375. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  4376. if (!haystack.size) {
  4377. return;
  4378. }
  4379. var cursor = 0;
  4380. haystack.reduce(function (value, nextValue, nextIndex) {
  4381. if (!areEqualFn(value, nextValue)) {
  4382. if (filterFn(value)) {
  4383. foundFn(cursor, nextIndex);
  4384. }
  4385. cursor = nextIndex;
  4386. }
  4387. return nextValue;
  4388. });
  4389. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  4390. }
  4391. var findRangesImmutable_1 = findRangesImmutable;
  4392. function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4393. function _possibleConstructorReturn$1(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4394. function _inherits$1(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4395. var List = immutable.List,
  4396. Map$1 = immutable.Map,
  4397. OrderedSet$1 = immutable.OrderedSet,
  4398. Record$1 = immutable.Record,
  4399. Repeat = immutable.Repeat;
  4400. var EMPTY_SET$1 = OrderedSet$1();
  4401. var defaultRecord$1 = {
  4402. key: '',
  4403. type: 'unstyled',
  4404. text: '',
  4405. characterList: List(),
  4406. depth: 0,
  4407. data: Map$1()
  4408. };
  4409. var ContentBlockRecord = Record$1(defaultRecord$1);
  4410. var decorateCharacterList = function decorateCharacterList(config) {
  4411. if (!config) {
  4412. return config;
  4413. }
  4414. var characterList = config.characterList,
  4415. text = config.text;
  4416. if (text && !characterList) {
  4417. config.characterList = List(Repeat(CharacterMetadata_1.EMPTY, text.length));
  4418. }
  4419. return config;
  4420. };
  4421. var ContentBlock = function (_ContentBlockRecord) {
  4422. _inherits$1(ContentBlock, _ContentBlockRecord);
  4423. function ContentBlock(config) {
  4424. _classCallCheck$1(this, ContentBlock);
  4425. return _possibleConstructorReturn$1(this, _ContentBlockRecord.call(this, decorateCharacterList(config)));
  4426. }
  4427. ContentBlock.prototype.getKey = function getKey() {
  4428. return this.get('key');
  4429. };
  4430. ContentBlock.prototype.getType = function getType() {
  4431. return this.get('type');
  4432. };
  4433. ContentBlock.prototype.getText = function getText() {
  4434. return this.get('text');
  4435. };
  4436. ContentBlock.prototype.getCharacterList = function getCharacterList() {
  4437. return this.get('characterList');
  4438. };
  4439. ContentBlock.prototype.getLength = function getLength() {
  4440. return this.getText().length;
  4441. };
  4442. ContentBlock.prototype.getDepth = function getDepth() {
  4443. return this.get('depth');
  4444. };
  4445. ContentBlock.prototype.getData = function getData() {
  4446. return this.get('data');
  4447. };
  4448. ContentBlock.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4449. var character = this.getCharacterList().get(offset);
  4450. return character ? character.getStyle() : EMPTY_SET$1;
  4451. };
  4452. ContentBlock.prototype.getEntityAt = function getEntityAt(offset) {
  4453. var character = this.getCharacterList().get(offset);
  4454. return character ? character.getEntity() : null;
  4455. };
  4456. /**
  4457. * Execute a callback for every contiguous range of styles within the block.
  4458. */
  4459. ContentBlock.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4460. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  4461. };
  4462. /**
  4463. * Execute a callback for every contiguous range of entities within the block.
  4464. */
  4465. ContentBlock.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4466. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  4467. };
  4468. return ContentBlock;
  4469. }(ContentBlockRecord);
  4470. function haveEqualStyle(charA, charB) {
  4471. return charA.getStyle() === charB.getStyle();
  4472. }
  4473. function haveEqualEntity(charA, charB) {
  4474. return charA.getEntity() === charB.getEntity();
  4475. }
  4476. var ContentBlock_1 = ContentBlock;
  4477. function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4478. function _possibleConstructorReturn$2(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4479. function _inherits$2(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4480. var List$1 = immutable.List,
  4481. Map$2 = immutable.Map,
  4482. OrderedSet$2 = immutable.OrderedSet,
  4483. Record$2 = immutable.Record,
  4484. Repeat$1 = immutable.Repeat;
  4485. var EMPTY_SET$2 = OrderedSet$2();
  4486. var defaultRecord$2 = {
  4487. parent: null,
  4488. characterList: List$1(),
  4489. data: Map$2(),
  4490. depth: 0,
  4491. key: '',
  4492. text: '',
  4493. type: 'unstyled',
  4494. children: List$1(),
  4495. prevSibling: null,
  4496. nextSibling: null
  4497. };
  4498. var haveEqualStyle$1 = function haveEqualStyle(charA, charB) {
  4499. return charA.getStyle() === charB.getStyle();
  4500. };
  4501. var haveEqualEntity$1 = function haveEqualEntity(charA, charB) {
  4502. return charA.getEntity() === charB.getEntity();
  4503. };
  4504. var decorateCharacterList$1 = function decorateCharacterList(config) {
  4505. if (!config) {
  4506. return config;
  4507. }
  4508. var characterList = config.characterList,
  4509. text = config.text;
  4510. if (text && !characterList) {
  4511. config.characterList = List$1(Repeat$1(CharacterMetadata_1.EMPTY, text.length));
  4512. }
  4513. return config;
  4514. };
  4515. var ContentBlockNode = function (_Record) {
  4516. _inherits$2(ContentBlockNode, _Record);
  4517. function ContentBlockNode() {
  4518. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord$2;
  4519. _classCallCheck$2(this, ContentBlockNode);
  4520. return _possibleConstructorReturn$2(this, _Record.call(this, decorateCharacterList$1(props)));
  4521. }
  4522. ContentBlockNode.prototype.getKey = function getKey() {
  4523. return this.get('key');
  4524. };
  4525. ContentBlockNode.prototype.getType = function getType() {
  4526. return this.get('type');
  4527. };
  4528. ContentBlockNode.prototype.getText = function getText() {
  4529. return this.get('text');
  4530. };
  4531. ContentBlockNode.prototype.getCharacterList = function getCharacterList() {
  4532. return this.get('characterList');
  4533. };
  4534. ContentBlockNode.prototype.getLength = function getLength() {
  4535. return this.getText().length;
  4536. };
  4537. ContentBlockNode.prototype.getDepth = function getDepth() {
  4538. return this.get('depth');
  4539. };
  4540. ContentBlockNode.prototype.getData = function getData() {
  4541. return this.get('data');
  4542. };
  4543. ContentBlockNode.prototype.getInlineStyleAt = function getInlineStyleAt(offset) {
  4544. var character = this.getCharacterList().get(offset);
  4545. return character ? character.getStyle() : EMPTY_SET$2;
  4546. };
  4547. ContentBlockNode.prototype.getEntityAt = function getEntityAt(offset) {
  4548. var character = this.getCharacterList().get(offset);
  4549. return character ? character.getEntity() : null;
  4550. };
  4551. ContentBlockNode.prototype.getChildKeys = function getChildKeys() {
  4552. return this.get('children');
  4553. };
  4554. ContentBlockNode.prototype.getParentKey = function getParentKey() {
  4555. return this.get('parent');
  4556. };
  4557. ContentBlockNode.prototype.getPrevSiblingKey = function getPrevSiblingKey() {
  4558. return this.get('prevSibling');
  4559. };
  4560. ContentBlockNode.prototype.getNextSiblingKey = function getNextSiblingKey() {
  4561. return this.get('nextSibling');
  4562. };
  4563. ContentBlockNode.prototype.findStyleRanges = function findStyleRanges(filterFn, callback) {
  4564. findRangesImmutable_1(this.getCharacterList(), haveEqualStyle$1, filterFn, callback);
  4565. };
  4566. ContentBlockNode.prototype.findEntityRanges = function findEntityRanges(filterFn, callback) {
  4567. findRangesImmutable_1(this.getCharacterList(), haveEqualEntity$1, filterFn, callback);
  4568. };
  4569. return ContentBlockNode;
  4570. }(Record$2(defaultRecord$2));
  4571. var ContentBlockNode_1 = ContentBlockNode;
  4572. /**
  4573. * Copyright 2013-present, Facebook, Inc.
  4574. * All rights reserved.
  4575. *
  4576. * This source code is licensed under the BSD-style license found in the
  4577. * LICENSE file in the root directory of this source tree. An additional grant
  4578. * of patent rights can be found in the PATENTS file in the same directory.
  4579. *
  4580. * @providesModule DraftFeatureFlags-core
  4581. * @format
  4582. *
  4583. */
  4584. var DraftFeatureFlags = {
  4585. draft_killswitch_allow_nontextnodes: false,
  4586. draft_segmented_entities_behavior: false,
  4587. draft_handlebeforeinput_composed_text: false,
  4588. draft_tree_data_support: false
  4589. };
  4590. var DraftFeatureFlagsCore = DraftFeatureFlags;
  4591. var DraftFeatureFlags_1 = DraftFeatureFlagsCore;
  4592. var Map$3 = immutable.Map;
  4593. var ContentStateInlineStyle = {
  4594. add: function add(contentState, selectionState, inlineStyle) {
  4595. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  4596. },
  4597. remove: function remove(contentState, selectionState, inlineStyle) {
  4598. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  4599. }
  4600. };
  4601. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  4602. var blockMap = contentState.getBlockMap();
  4603. var startKey = selectionState.getStartKey();
  4604. var startOffset = selectionState.getStartOffset();
  4605. var endKey = selectionState.getEndKey();
  4606. var endOffset = selectionState.getEndOffset();
  4607. var newBlocks = blockMap.skipUntil(function (_, k) {
  4608. return k === startKey;
  4609. }).takeUntil(function (_, k) {
  4610. return k === endKey;
  4611. }).concat(Map$3([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4612. var sliceStart;
  4613. var sliceEnd;
  4614. if (startKey === endKey) {
  4615. sliceStart = startOffset;
  4616. sliceEnd = endOffset;
  4617. } else {
  4618. sliceStart = blockKey === startKey ? startOffset : 0;
  4619. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4620. }
  4621. var chars = block.getCharacterList();
  4622. var current;
  4623. while (sliceStart < sliceEnd) {
  4624. current = chars.get(sliceStart);
  4625. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata_1.applyStyle(current, inlineStyle) : CharacterMetadata_1.removeStyle(current, inlineStyle));
  4626. sliceStart++;
  4627. }
  4628. return block.set('characterList', chars);
  4629. });
  4630. return contentState.merge({
  4631. blockMap: blockMap.merge(newBlocks),
  4632. selectionBefore: selectionState,
  4633. selectionAfter: selectionState
  4634. });
  4635. }
  4636. var ContentStateInlineStyle_1 = ContentStateInlineStyle;
  4637. function applyEntityToContentBlock(contentBlock, start, end, entityKey) {
  4638. var characterList = contentBlock.getCharacterList();
  4639. while (start < end) {
  4640. characterList = characterList.set(start, CharacterMetadata_1.applyEntity(characterList.get(start), entityKey));
  4641. start++;
  4642. }
  4643. return contentBlock.set('characterList', characterList);
  4644. }
  4645. var applyEntityToContentBlock_1 = applyEntityToContentBlock;
  4646. function applyEntityToContentState(contentState, selectionState, entityKey) {
  4647. var blockMap = contentState.getBlockMap();
  4648. var startKey = selectionState.getStartKey();
  4649. var startOffset = selectionState.getStartOffset();
  4650. var endKey = selectionState.getEndKey();
  4651. var endOffset = selectionState.getEndOffset();
  4652. var newBlocks = blockMap.skipUntil(function (_, k) {
  4653. return k === startKey;
  4654. }).takeUntil(function (_, k) {
  4655. return k === endKey;
  4656. }).toOrderedMap().merge(immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  4657. var sliceStart = blockKey === startKey ? startOffset : 0;
  4658. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  4659. return applyEntityToContentBlock_1(block, sliceStart, sliceEnd, entityKey);
  4660. });
  4661. return contentState.merge({
  4662. blockMap: blockMap.merge(newBlocks),
  4663. selectionBefore: selectionState,
  4664. selectionAfter: selectionState
  4665. });
  4666. }
  4667. var applyEntityToContentState_1 = applyEntityToContentState;
  4668. /**
  4669. * Copyright (c) 2013-present, Facebook, Inc.
  4670. * All rights reserved.
  4671. *
  4672. * This source code is licensed under the BSD-style license found in the
  4673. * LICENSE file in the root directory of this source tree. An additional grant
  4674. * of patent rights can be found in the PATENTS file in the same directory.
  4675. *
  4676. * @providesModule DraftEntitySegments
  4677. * @format
  4678. *
  4679. */
  4680. /**
  4681. * Identify the range to delete from a segmented entity.
  4682. *
  4683. * Rules:
  4684. *
  4685. * Example: 'John F. Kennedy'
  4686. *
  4687. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  4688. * will return the range of that text.
  4689. *
  4690. * 'John F. Kennedy' -> 'John F.'
  4691. * ^
  4692. *
  4693. * - Forward deletion of whitespace will remove the following section:
  4694. *
  4695. * 'John F. Kennedy' -> 'John Kennedy'
  4696. * ^
  4697. *
  4698. * - Backward deletion of whitespace will remove the previous section:
  4699. *
  4700. * 'John F. Kennedy' -> 'F. Kennedy'
  4701. * ^
  4702. */
  4703. var DraftEntitySegments = {
  4704. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  4705. var segments = text.split(' ');
  4706. segments = segments.map(function ( /*string*/segment, /*number*/ii) {
  4707. if (direction === 'forward') {
  4708. if (ii > 0) {
  4709. return ' ' + segment;
  4710. }
  4711. } else if (ii < segments.length - 1) {
  4712. return segment + ' ';
  4713. }
  4714. return segment;
  4715. });
  4716. var segmentStart = entityStart;
  4717. var segmentEnd;
  4718. var segment;
  4719. var removalStart = null;
  4720. var removalEnd = null;
  4721. for (var jj = 0; jj < segments.length; jj++) {
  4722. segment = segments[jj];
  4723. segmentEnd = segmentStart + segment.length;
  4724. // Our selection overlaps this segment.
  4725. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  4726. if (removalStart !== null) {
  4727. removalEnd = segmentEnd;
  4728. } else {
  4729. removalStart = segmentStart;
  4730. removalEnd = segmentEnd;
  4731. }
  4732. } else if (removalStart !== null) {
  4733. break;
  4734. }
  4735. segmentStart = segmentEnd;
  4736. }
  4737. var entityEnd = entityStart + text.length;
  4738. var atStart = removalStart === entityStart;
  4739. var atEnd = removalEnd === entityEnd;
  4740. if (!atStart && atEnd || atStart && !atEnd) {
  4741. if (direction === 'forward') {
  4742. if (removalEnd !== entityEnd) {
  4743. removalEnd++;
  4744. }
  4745. } else if (removalStart !== entityStart) {
  4746. removalStart--;
  4747. }
  4748. }
  4749. return {
  4750. start: removalStart,
  4751. end: removalEnd
  4752. };
  4753. }
  4754. };
  4755. var DraftEntitySegments_1 = DraftEntitySegments;
  4756. /**
  4757. * Copyright (c) 2013-present, Facebook, Inc.
  4758. *
  4759. * This source code is licensed under the MIT license found in the
  4760. * LICENSE file in the root directory of this source tree.
  4761. *
  4762. */
  4763. /**
  4764. * Use invariant() to assert state which your program assumes to be true.
  4765. *
  4766. * Provide sprintf-style format (only %s is supported) and arguments
  4767. * to provide information about what broke and what you were
  4768. * expecting.
  4769. *
  4770. * The invariant message will be stripped in production, but the invariant
  4771. * will remain to ensure logic does not differ in production.
  4772. */
  4773. var validateFormat = function validateFormat(format) {};
  4774. if (process.env.NODE_ENV !== 'production') {
  4775. validateFormat = function validateFormat(format) {
  4776. if (format === undefined) {
  4777. throw new Error('invariant requires an error message argument');
  4778. }
  4779. };
  4780. }
  4781. function invariant(condition, format, a, b, c, d, e, f) {
  4782. validateFormat(format);
  4783. if (!condition) {
  4784. var error;
  4785. if (format === undefined) {
  4786. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  4787. } else {
  4788. var args = [a, b, c, d, e, f];
  4789. var argIndex = 0;
  4790. error = new Error(format.replace(/%s/g, function () {
  4791. return args[argIndex++];
  4792. }));
  4793. error.name = 'Invariant Violation';
  4794. }
  4795. error.framesToPop = 1; // we don't care about invariant's own frame
  4796. throw error;
  4797. }
  4798. }
  4799. var invariant_1 = invariant;
  4800. /**
  4801. * Obtain the start and end positions of the range that has the
  4802. * specified entity applied to it.
  4803. *
  4804. * Entity keys are applied only to contiguous stretches of text, so this
  4805. * method searches for the first instance of the entity key and returns
  4806. * the subsequent range.
  4807. */
  4808. function getRangesForDraftEntity(block, key) {
  4809. var ranges = [];
  4810. block.findEntityRanges(function (c) {
  4811. return c.getEntity() === key;
  4812. }, function (start, end) {
  4813. ranges.push({ start: start, end: end });
  4814. });
  4815. !!!ranges.length ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Entity key not found in this range.') : invariant_1(false) : void 0;
  4816. return ranges;
  4817. }
  4818. var getRangesForDraftEntity_1 = getRangesForDraftEntity;
  4819. /**
  4820. * Given a SelectionState and a removal direction, determine the entire range
  4821. * that should be removed from a ContentState. This is based on any entities
  4822. * within the target, with their `mutability` values taken into account.
  4823. *
  4824. * For instance, if we are attempting to remove part of an "immutable" entity
  4825. * range, the entire entity must be removed. The returned `SelectionState`
  4826. * will be adjusted accordingly.
  4827. */
  4828. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  4829. var start = selectionState.getStartOffset();
  4830. var end = selectionState.getEndOffset();
  4831. var startEntityKey = startBlock.getEntityAt(start);
  4832. var endEntityKey = endBlock.getEntityAt(end - 1);
  4833. if (!startEntityKey && !endEntityKey) {
  4834. return selectionState;
  4835. }
  4836. var newSelectionState = selectionState;
  4837. if (startEntityKey && startEntityKey === endEntityKey) {
  4838. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  4839. } else if (startEntityKey && endEntityKey) {
  4840. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4841. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4842. newSelectionState = newSelectionState.merge({
  4843. anchorOffset: startSelectionState.getAnchorOffset(),
  4844. focusOffset: endSelectionState.getFocusOffset(),
  4845. isBackward: false
  4846. });
  4847. } else if (startEntityKey) {
  4848. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  4849. newSelectionState = newSelectionState.merge({
  4850. anchorOffset: _startSelectionState.getStartOffset(),
  4851. isBackward: false
  4852. });
  4853. } else if (endEntityKey) {
  4854. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  4855. newSelectionState = newSelectionState.merge({
  4856. focusOffset: _endSelectionState.getEndOffset(),
  4857. isBackward: false
  4858. });
  4859. }
  4860. return newSelectionState;
  4861. }
  4862. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  4863. var start = selectionState.getStartOffset();
  4864. var end = selectionState.getEndOffset();
  4865. var entity = entityMap.__get(entityKey);
  4866. var mutability = entity.getMutability();
  4867. var sideToConsider = isEntityAtStart ? start : end;
  4868. // `MUTABLE` entities can just have the specified range of text removed
  4869. // directly. No adjustments are needed.
  4870. if (mutability === 'MUTABLE') {
  4871. return selectionState;
  4872. }
  4873. // Find the entity range that overlaps with our removal range.
  4874. var entityRanges = getRangesForDraftEntity_1(block, entityKey).filter(function (range) {
  4875. return sideToConsider <= range.end && sideToConsider >= range.start;
  4876. });
  4877. !(entityRanges.length == 1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'There should only be one entity range within this removal range.') : invariant_1(false) : void 0;
  4878. var entityRange = entityRanges[0];
  4879. // For `IMMUTABLE` entity types, we will remove the entire entity range.
  4880. if (mutability === 'IMMUTABLE') {
  4881. return selectionState.merge({
  4882. anchorOffset: entityRange.start,
  4883. focusOffset: entityRange.end,
  4884. isBackward: false
  4885. });
  4886. }
  4887. // For `SEGMENTED` entity types, determine the appropriate segment to
  4888. // remove.
  4889. if (!isEntireSelectionWithinEntity) {
  4890. if (isEntityAtStart) {
  4891. end = entityRange.end;
  4892. } else {
  4893. start = entityRange.start;
  4894. }
  4895. }
  4896. var removalRange = DraftEntitySegments_1.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  4897. return selectionState.merge({
  4898. anchorOffset: removalRange.start,
  4899. focusOffset: removalRange.end,
  4900. isBackward: false
  4901. });
  4902. }
  4903. var getCharacterRemovalRange_1 = getCharacterRemovalRange;
  4904. /**
  4905. * Copyright (c) 2013-present, Facebook, Inc.
  4906. * All rights reserved.
  4907. *
  4908. * This source code is licensed under the BSD-style license found in the
  4909. * LICENSE file in the root directory of this source tree. An additional grant
  4910. * of patent rights can be found in the PATENTS file in the same directory.
  4911. *
  4912. * @providesModule generateRandomKey
  4913. * @format
  4914. *
  4915. */
  4916. var seenKeys = {};
  4917. var MULTIPLIER = Math.pow(2, 24);
  4918. function generateRandomKey() {
  4919. var key = void 0;
  4920. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  4921. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  4922. }
  4923. seenKeys[key] = true;
  4924. return key;
  4925. }
  4926. var generateRandomKey_1 = generateRandomKey;
  4927. var OrderedMap$1 = immutable.OrderedMap;
  4928. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  4929. var newKeysRef = {};
  4930. // we keep track of root blocks in order to update subsequent sibling links
  4931. var lastRootBlock = void 0;
  4932. return OrderedMap$1(blockMap.withMutations(function (blockMapState) {
  4933. blockMapState.forEach(function (block, index) {
  4934. var oldKey = block.getKey();
  4935. var nextKey = block.getNextSiblingKey();
  4936. var prevKey = block.getPrevSiblingKey();
  4937. var childrenKeys = block.getChildKeys();
  4938. var parentKey = block.getParentKey();
  4939. // new key that we will use to build linking
  4940. var key = generateRandomKey_1();
  4941. // we will add it here to re-use it later
  4942. newKeysRef[oldKey] = key;
  4943. if (nextKey) {
  4944. var nextBlock = blockMapState.get(nextKey);
  4945. if (nextBlock) {
  4946. blockMapState.setIn([nextKey, 'prevSibling'], key);
  4947. } else {
  4948. // this can happen when generating random keys for fragments
  4949. blockMapState.setIn([oldKey, 'nextSibling'], null);
  4950. }
  4951. }
  4952. if (prevKey) {
  4953. var prevBlock = blockMapState.get(prevKey);
  4954. if (prevBlock) {
  4955. blockMapState.setIn([prevKey, 'nextSibling'], key);
  4956. } else {
  4957. // this can happen when generating random keys for fragments
  4958. blockMapState.setIn([oldKey, 'prevSibling'], null);
  4959. }
  4960. }
  4961. if (parentKey && blockMapState.get(parentKey)) {
  4962. var parentBlock = blockMapState.get(parentKey);
  4963. var parentChildrenList = parentBlock.getChildKeys();
  4964. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  4965. } else {
  4966. // blocks will then be treated as root block nodes
  4967. blockMapState.setIn([oldKey, 'parent'], null);
  4968. if (lastRootBlock) {
  4969. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  4970. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  4971. }
  4972. lastRootBlock = blockMapState.get(oldKey);
  4973. }
  4974. childrenKeys.forEach(function (childKey) {
  4975. var childBlock = blockMapState.get(childKey);
  4976. if (childBlock) {
  4977. blockMapState.setIn([childKey, 'parent'], key);
  4978. } else {
  4979. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  4980. return child !== childKey;
  4981. }));
  4982. }
  4983. });
  4984. });
  4985. }).toArray().map(function (block) {
  4986. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  4987. }));
  4988. };
  4989. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  4990. return OrderedMap$1(blockMap.toArray().map(function (block) {
  4991. var key = generateRandomKey_1();
  4992. return [key, block.set('key', key)];
  4993. }));
  4994. };
  4995. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  4996. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  4997. if (!isTreeBasedBlockMap) {
  4998. return randomizeContentBlockKeys(blockMap);
  4999. }
  5000. return randomizeContentBlockNodeKeys(blockMap);
  5001. };
  5002. var randomizeBlockMapKeys_1 = randomizeBlockMapKeys;
  5003. function removeEntitiesAtEdges(contentState, selectionState) {
  5004. var blockMap = contentState.getBlockMap();
  5005. var entityMap = contentState.getEntityMap();
  5006. var updatedBlocks = {};
  5007. var startKey = selectionState.getStartKey();
  5008. var startOffset = selectionState.getStartOffset();
  5009. var startBlock = blockMap.get(startKey);
  5010. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  5011. if (updatedStart !== startBlock) {
  5012. updatedBlocks[startKey] = updatedStart;
  5013. }
  5014. var endKey = selectionState.getEndKey();
  5015. var endOffset = selectionState.getEndOffset();
  5016. var endBlock = blockMap.get(endKey);
  5017. if (startKey === endKey) {
  5018. endBlock = updatedStart;
  5019. }
  5020. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  5021. if (updatedEnd !== endBlock) {
  5022. updatedBlocks[endKey] = updatedEnd;
  5023. }
  5024. if (!Object.keys(updatedBlocks).length) {
  5025. return contentState.set('selectionAfter', selectionState);
  5026. }
  5027. return contentState.merge({
  5028. blockMap: blockMap.merge(updatedBlocks),
  5029. selectionAfter: selectionState
  5030. });
  5031. }
  5032. function getRemovalRange(characters, key, offset) {
  5033. var removalRange;
  5034. findRangesImmutable_1(characters, function (a, b) {
  5035. return a.getEntity() === b.getEntity();
  5036. }, function (element) {
  5037. return element.getEntity() === key;
  5038. }, function (start, end) {
  5039. if (start <= offset && end >= offset) {
  5040. removalRange = { start: start, end: end };
  5041. }
  5042. });
  5043. !(typeof removalRange === 'object') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Removal range must exist within character list.') : invariant_1(false) : void 0;
  5044. return removalRange;
  5045. }
  5046. function removeForBlock(entityMap, block, offset) {
  5047. var chars = block.getCharacterList();
  5048. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  5049. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  5050. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  5051. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  5052. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  5053. var entity = entityMap.__get(entityAfterCursor);
  5054. if (entity.getMutability() !== 'MUTABLE') {
  5055. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  5056. start = _getRemovalRange.start,
  5057. end = _getRemovalRange.end;
  5058. var current;
  5059. while (start < end) {
  5060. current = chars.get(start);
  5061. chars = chars.set(start, CharacterMetadata_1.applyEntity(current, null));
  5062. start++;
  5063. }
  5064. return block.set('characterList', chars);
  5065. }
  5066. }
  5067. return block;
  5068. }
  5069. var removeEntitiesAtEdges_1 = removeEntitiesAtEdges;
  5070. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  5071. var startKey = selectionState.getStartKey();
  5072. var startOffset = selectionState.getStartOffset();
  5073. var endKey = selectionState.getEndKey();
  5074. var endOffset = selectionState.getEndOffset();
  5075. // Edge entities should be stripped to ensure that we don't preserve
  5076. // invalid partial entities when the fragment is reused. We do, however,
  5077. // preserve entities that are entirely within the selection range.
  5078. var contentWithoutEdgeEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5079. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  5080. var blockKeys = blockMap.keySeq();
  5081. var startIndex = blockKeys.indexOf(startKey);
  5082. var endIndex = blockKeys.indexOf(endKey) + 1;
  5083. return randomizeBlockMapKeys_1(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  5084. var text = block.getText();
  5085. var chars = block.getCharacterList();
  5086. if (startKey === endKey) {
  5087. return block.merge({
  5088. text: text.slice(startOffset, endOffset),
  5089. characterList: chars.slice(startOffset, endOffset)
  5090. });
  5091. }
  5092. if (blockKey === startKey) {
  5093. return block.merge({
  5094. text: text.slice(startOffset),
  5095. characterList: chars.slice(startOffset)
  5096. });
  5097. }
  5098. if (blockKey === endKey) {
  5099. return block.merge({
  5100. text: text.slice(0, endOffset),
  5101. characterList: chars.slice(0, endOffset)
  5102. });
  5103. }
  5104. return block;
  5105. }));
  5106. };
  5107. var getContentStateFragment_1 = getContentStateFragment;
  5108. /**
  5109. * Copyright (c) 2013-present, Facebook, Inc.
  5110. * All rights reserved.
  5111. *
  5112. * This source code is licensed under the BSD-style license found in the
  5113. * LICENSE file in the root directory of this source tree. An additional grant
  5114. * of patent rights can be found in the PATENTS file in the same directory.
  5115. *
  5116. * @providesModule insertIntoList
  5117. * @format
  5118. *
  5119. */
  5120. /**
  5121. * Maintain persistence for target list when appending and prepending.
  5122. */
  5123. function insertIntoList(targetList, toInsert, offset) {
  5124. if (offset === targetList.count()) {
  5125. toInsert.forEach(function (c) {
  5126. targetList = targetList.push(c);
  5127. });
  5128. } else if (offset === 0) {
  5129. toInsert.reverse().forEach(function (c) {
  5130. targetList = targetList.unshift(c);
  5131. });
  5132. } else {
  5133. var head = targetList.slice(0, offset);
  5134. var tail = targetList.slice(offset);
  5135. targetList = head.concat(toInsert, tail).toList();
  5136. }
  5137. return targetList;
  5138. }
  5139. var insertIntoList_1 = insertIntoList;
  5140. var List$2 = immutable.List;
  5141. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  5142. var targetBlock = blockMap.get(targetKey);
  5143. var text = targetBlock.getText();
  5144. var chars = targetBlock.getCharacterList();
  5145. var finalKey = targetKey;
  5146. var finalOffset = targetOffset + fragmentBlock.getText().length;
  5147. var newBlock = targetBlock.merge({
  5148. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  5149. characterList: insertIntoList_1(chars, fragmentBlock.getCharacterList(), targetOffset),
  5150. data: fragmentBlock.getData()
  5151. });
  5152. return contentState.merge({
  5153. blockMap: blockMap.set(targetKey, newBlock),
  5154. selectionBefore: selectionState,
  5155. selectionAfter: selectionState.merge({
  5156. anchorKey: finalKey,
  5157. anchorOffset: finalOffset,
  5158. focusKey: finalKey,
  5159. focusOffset: finalOffset,
  5160. isBackward: false
  5161. })
  5162. });
  5163. };
  5164. /**
  5165. * Appends text/characterList from the fragment first block to
  5166. * target block.
  5167. */
  5168. var updateHead = function updateHead(block, targetOffset, fragment) {
  5169. var text = block.getText();
  5170. var chars = block.getCharacterList();
  5171. // Modify head portion of block.
  5172. var headText = text.slice(0, targetOffset);
  5173. var headCharacters = chars.slice(0, targetOffset);
  5174. var appendToHead = fragment.first();
  5175. return block.merge({
  5176. text: headText + appendToHead.getText(),
  5177. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  5178. type: headText ? block.getType() : appendToHead.getType(),
  5179. data: appendToHead.getData()
  5180. });
  5181. };
  5182. /**
  5183. * Appends offset text/characterList from the target block to the last
  5184. * fragment block.
  5185. */
  5186. var updateTail = function updateTail(block, targetOffset, fragment) {
  5187. // Modify tail portion of block.
  5188. var text = block.getText();
  5189. var chars = block.getCharacterList();
  5190. // Modify head portion of block.
  5191. var blockSize = text.length;
  5192. var tailText = text.slice(targetOffset, blockSize);
  5193. var tailCharacters = chars.slice(targetOffset, blockSize);
  5194. var prependToTail = fragment.last();
  5195. return prependToTail.merge({
  5196. text: prependToTail.getText() + tailText,
  5197. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  5198. data: prependToTail.getData()
  5199. });
  5200. };
  5201. var getRootBlocks = function getRootBlocks(block, blockMap) {
  5202. var headKey = block.getKey();
  5203. var rootBlock = block;
  5204. var rootBlocks = [];
  5205. // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  5206. // the fragment head is used to update the target block, however when this does not happen we need
  5207. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  5208. // fragment root block
  5209. if (blockMap.get(headKey)) {
  5210. rootBlocks.push(headKey);
  5211. }
  5212. while (rootBlock && rootBlock.getNextSiblingKey()) {
  5213. var lastSiblingKey = rootBlock.getNextSiblingKey();
  5214. if (!lastSiblingKey) {
  5215. break;
  5216. }
  5217. rootBlocks.push(lastSiblingKey);
  5218. rootBlock = blockMap.get(lastSiblingKey);
  5219. }
  5220. return rootBlocks;
  5221. };
  5222. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  5223. return blockMap.withMutations(function (blockMapState) {
  5224. var targetKey = targetBlock.getKey();
  5225. var headKey = fragmentHeadBlock.getKey();
  5226. var targetNextKey = targetBlock.getNextSiblingKey();
  5227. var targetParentKey = targetBlock.getParentKey();
  5228. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  5229. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  5230. if (blockMapState.get(headKey)) {
  5231. // update the fragment head when it is part of the blockMap otherwise
  5232. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  5233. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  5234. } else {
  5235. // update the target block that had the fragment head contents merged into it
  5236. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  5237. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  5238. }
  5239. // update the last root block fragment
  5240. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey);
  5241. // update the original target next block
  5242. if (targetNextKey) {
  5243. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  5244. }
  5245. // update fragment parent links
  5246. fragmentRootBlocks.forEach(function (blockKey) {
  5247. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  5248. });
  5249. // update targetBlock parent child links
  5250. if (targetParentKey) {
  5251. var targetParent = blockMap.get(targetParentKey);
  5252. var originalTargetParentChildKeys = targetParent.getChildKeys();
  5253. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  5254. var insertionIndex = targetBlockIndex + 1;
  5255. var newChildrenKeysArray = originalTargetParentChildKeys.toArray();
  5256. // insert fragment children
  5257. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  5258. blockMapState.setIn([targetParentKey, 'children'], List$2(newChildrenKeysArray));
  5259. }
  5260. });
  5261. };
  5262. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  5263. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode_1;
  5264. var newBlockArr = [];
  5265. var fragmentSize = fragment.size;
  5266. var target = blockMap.get(targetKey);
  5267. var head = fragment.first();
  5268. var tail = fragment.last();
  5269. var finalOffset = tail.getLength();
  5270. var finalKey = tail.getKey();
  5271. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  5272. blockMap.forEach(function (block, blockKey) {
  5273. if (blockKey !== targetKey) {
  5274. newBlockArr.push(block);
  5275. return;
  5276. }
  5277. if (shouldNotUpdateFromFragmentBlock) {
  5278. newBlockArr.push(block);
  5279. } else {
  5280. newBlockArr.push(updateHead(block, targetOffset, fragment));
  5281. }
  5282. // Insert fragment blocks after the head and before the tail.
  5283. fragment
  5284. // when we are updating the target block with the head fragment block we skip the first fragment
  5285. // head since its contents have already been merged with the target block otherwise we include
  5286. // the whole fragment
  5287. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  5288. return newBlockArr.push(fragmentBlock);
  5289. });
  5290. // update tail
  5291. newBlockArr.push(updateTail(block, targetOffset, fragment));
  5292. });
  5293. var updatedBlockMap = BlockMapBuilder_1.createFromArray(newBlockArr);
  5294. if (isTreeBasedBlockMap) {
  5295. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  5296. }
  5297. return contentState.merge({
  5298. blockMap: updatedBlockMap,
  5299. selectionBefore: selectionState,
  5300. selectionAfter: selectionState.merge({
  5301. anchorKey: finalKey,
  5302. anchorOffset: finalOffset,
  5303. focusKey: finalKey,
  5304. focusOffset: finalOffset,
  5305. isBackward: false
  5306. })
  5307. });
  5308. };
  5309. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  5310. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertFragment` should only be called with a collapsed selection state.') : invariant_1(false) : void 0;
  5311. var blockMap = contentState.getBlockMap();
  5312. var fragment = randomizeBlockMapKeys_1(fragmentBlockMap);
  5313. var targetKey = selectionState.getStartKey();
  5314. var targetOffset = selectionState.getStartOffset();
  5315. var targetBlock = blockMap.get(targetKey);
  5316. if (targetBlock instanceof ContentBlockNode_1) {
  5317. !targetBlock.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertFragment` should not be called when a container node is selected.') : invariant_1(false) : void 0;
  5318. }
  5319. // When we insert a fragment with a single block we simply update the target block
  5320. // with the contents of the inserted fragment block
  5321. if (fragment.size === 1) {
  5322. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset);
  5323. }
  5324. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  5325. };
  5326. var insertFragmentIntoContentState_1 = insertFragmentIntoContentState;
  5327. var Repeat$2 = immutable.Repeat;
  5328. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  5329. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`insertText` should only be called with a collapsed range.') : invariant_1(false) : void 0;
  5330. var len = text.length;
  5331. if (!len) {
  5332. return contentState;
  5333. }
  5334. var blockMap = contentState.getBlockMap();
  5335. var key = selectionState.getStartKey();
  5336. var offset = selectionState.getStartOffset();
  5337. var block = blockMap.get(key);
  5338. var blockText = block.getText();
  5339. var newBlock = block.merge({
  5340. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  5341. characterList: insertIntoList_1(block.getCharacterList(), Repeat$2(characterMetadata, len).toList(), offset)
  5342. });
  5343. var newOffset = offset + len;
  5344. return contentState.merge({
  5345. blockMap: blockMap.set(key, newBlock),
  5346. selectionAfter: selectionState.merge({
  5347. anchorOffset: newOffset,
  5348. focusOffset: newOffset
  5349. })
  5350. });
  5351. }
  5352. var insertTextIntoContentState_1 = insertTextIntoContentState;
  5353. var Map$4 = immutable.Map;
  5354. function modifyBlockForContentState(contentState, selectionState, operation) {
  5355. var startKey = selectionState.getStartKey();
  5356. var endKey = selectionState.getEndKey();
  5357. var blockMap = contentState.getBlockMap();
  5358. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5359. return k === startKey;
  5360. }).takeUntil(function (_, k) {
  5361. return k === endKey;
  5362. }).concat(Map$4([[endKey, blockMap.get(endKey)]])).map(operation);
  5363. return contentState.merge({
  5364. blockMap: blockMap.merge(newBlocks),
  5365. selectionBefore: selectionState,
  5366. selectionAfter: selectionState
  5367. });
  5368. }
  5369. var modifyBlockForContentState_1 = modifyBlockForContentState;
  5370. /**
  5371. * Copyright (c) 2013-present, Facebook, Inc.
  5372. * All rights reserved.
  5373. *
  5374. * This source code is licensed under the BSD-style license found in the
  5375. * LICENSE file in the root directory of this source tree. An additional grant
  5376. * of patent rights can be found in the PATENTS file in the same directory.
  5377. *
  5378. * @providesModule getNextDelimiterBlockKey
  5379. * @format
  5380. *
  5381. *
  5382. * This is unstable and not part of the public API and should not be used by
  5383. * production systems. This file may be update/removed without notice.
  5384. */
  5385. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  5386. var isExperimentalTreeBlock = block instanceof ContentBlockNode_1;
  5387. if (!isExperimentalTreeBlock) {
  5388. return null;
  5389. }
  5390. var nextSiblingKey = block.getNextSiblingKey();
  5391. if (nextSiblingKey) {
  5392. return nextSiblingKey;
  5393. }
  5394. var parent = block.getParentKey();
  5395. if (!parent) {
  5396. return null;
  5397. }
  5398. var nextNonDescendantBlock = blockMap.get(parent);
  5399. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  5400. var parentKey = nextNonDescendantBlock.getParentKey();
  5401. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  5402. }
  5403. if (!nextNonDescendantBlock) {
  5404. return null;
  5405. }
  5406. return nextNonDescendantBlock.getNextSiblingKey();
  5407. };
  5408. var getNextDelimiterBlockKey_1 = getNextDelimiterBlockKey;
  5409. var List$3 = immutable.List,
  5410. Map$5 = immutable.Map;
  5411. var transformBlock = function transformBlock(key, blockMap, func) {
  5412. if (!key) {
  5413. return;
  5414. }
  5415. var block = blockMap.get(key);
  5416. if (!block) {
  5417. return;
  5418. }
  5419. blockMap.set(key, func(block));
  5420. };
  5421. /**
  5422. * Ancestors needs to be preserved when there are non selected
  5423. * children to make sure we do not leave any orphans behind
  5424. */
  5425. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  5426. var parents = [];
  5427. if (!blockKey) {
  5428. return parents;
  5429. }
  5430. var blockNode = blockMap.get(blockKey);
  5431. while (blockNode && blockNode.getParentKey()) {
  5432. var parentKey = blockNode.getParentKey();
  5433. if (parentKey) {
  5434. parents.push(parentKey);
  5435. }
  5436. blockNode = parentKey ? blockMap.get(parentKey) : null;
  5437. }
  5438. return parents;
  5439. };
  5440. /**
  5441. * Get all next delimiter keys until we hit a root delimiter and return
  5442. * an array of key references
  5443. */
  5444. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  5445. var nextDelimiters = [];
  5446. if (!block) {
  5447. return nextDelimiters;
  5448. }
  5449. var nextDelimiter = getNextDelimiterBlockKey_1(block, blockMap);
  5450. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  5451. var _block = blockMap.get(nextDelimiter);
  5452. nextDelimiters.push(nextDelimiter);
  5453. // we do not need to keep checking all root node siblings, just the first occurance
  5454. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey_1(_block, blockMap) : null;
  5455. }
  5456. return nextDelimiters;
  5457. };
  5458. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  5459. if (!block) {
  5460. return null;
  5461. }
  5462. // note that we need to make sure we refer to the original block since this
  5463. // function is called within a withMutations
  5464. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  5465. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  5466. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  5467. }
  5468. return nextValidSiblingKey;
  5469. };
  5470. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  5471. if (!block) {
  5472. return null;
  5473. }
  5474. // note that we need to make sure we refer to the original block since this
  5475. // function is called within a withMutations
  5476. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  5477. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  5478. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  5479. }
  5480. return prevValidSiblingKey;
  5481. };
  5482. var updateBlockMapLinks$1 = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  5483. return blockMap.withMutations(function (blocks) {
  5484. // update start block if its retained
  5485. transformBlock(startBlock.getKey(), blocks, function (block) {
  5486. return block.merge({
  5487. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap),
  5488. prevSibling: getPrevValidSibling(startBlock, blocks, originalBlockMap)
  5489. });
  5490. });
  5491. // update endblock if its retained
  5492. transformBlock(endBlock.getKey(), blocks, function (block) {
  5493. return block.merge({
  5494. nextSibling: getNextValidSibling(endBlock, blocks, originalBlockMap),
  5495. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5496. });
  5497. });
  5498. // update start block parent ancestors
  5499. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5500. return transformBlock(parentKey, blocks, function (block) {
  5501. return block.merge({
  5502. children: block.getChildKeys().filter(function (key) {
  5503. return blocks.get(key);
  5504. }),
  5505. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5506. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5507. });
  5508. });
  5509. });
  5510. // update start block next - can only happen if startBlock == endBlock
  5511. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  5512. return block.merge({
  5513. prevSibling: startBlock.getPrevSiblingKey()
  5514. });
  5515. });
  5516. // update start block prev
  5517. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  5518. return block.merge({
  5519. nextSibling: getNextValidSibling(startBlock, blocks, originalBlockMap)
  5520. });
  5521. });
  5522. // update end block next
  5523. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  5524. return block.merge({
  5525. prevSibling: getPrevValidSibling(endBlock, blocks, originalBlockMap)
  5526. });
  5527. });
  5528. // update end block prev
  5529. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  5530. return block.merge({
  5531. nextSibling: endBlock.getNextSiblingKey()
  5532. });
  5533. });
  5534. // update end block parent ancestors
  5535. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  5536. transformBlock(parentKey, blocks, function (block) {
  5537. return block.merge({
  5538. children: block.getChildKeys().filter(function (key) {
  5539. return blocks.get(key);
  5540. }),
  5541. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5542. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5543. });
  5544. });
  5545. });
  5546. // update next delimiters all the way to a root delimiter
  5547. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  5548. return transformBlock(delimiterKey, blocks, function (block) {
  5549. return block.merge({
  5550. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  5551. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  5552. });
  5553. });
  5554. });
  5555. });
  5556. };
  5557. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  5558. if (selectionState.isCollapsed()) {
  5559. return contentState;
  5560. }
  5561. var blockMap = contentState.getBlockMap();
  5562. var startKey = selectionState.getStartKey();
  5563. var startOffset = selectionState.getStartOffset();
  5564. var endKey = selectionState.getEndKey();
  5565. var endOffset = selectionState.getEndOffset();
  5566. var startBlock = blockMap.get(startKey);
  5567. var endBlock = blockMap.get(endKey);
  5568. // we assume that ContentBlockNode and ContentBlocks are not mixed together
  5569. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode_1;
  5570. // used to retain blocks that should not be deleted to avoid orphan children
  5571. var parentAncestors = [];
  5572. if (isExperimentalTreeBlock) {
  5573. var endBlockchildrenKeys = endBlock.getChildKeys();
  5574. var endBlockAncestors = getAncestorsKeys(endKey, blockMap);
  5575. // endBlock has unselected sibblings so we can not remove its ancestors parents
  5576. if (endBlock.getNextSiblingKey()) {
  5577. parentAncestors = parentAncestors.concat(endBlockAncestors);
  5578. }
  5579. // endBlock has children so can not remove this block or any of its ancestors
  5580. if (!endBlockchildrenKeys.isEmpty()) {
  5581. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  5582. }
  5583. // we need to retain all ancestors of the next delimiter block
  5584. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey_1(endBlock, blockMap), blockMap));
  5585. }
  5586. var characterList = void 0;
  5587. if (startBlock === endBlock) {
  5588. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  5589. } else {
  5590. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  5591. }
  5592. var modifiedStart = startBlock.merge({
  5593. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  5594. characterList: characterList
  5595. });
  5596. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  5597. return k === startKey;
  5598. }).takeUntil(function (_, k) {
  5599. return k === endKey;
  5600. }).filter(function (_, k) {
  5601. return parentAncestors.indexOf(k) === -1;
  5602. }).concat(Map$5([[endKey, null]])).map(function (_, k) {
  5603. return k === startKey ? modifiedStart : null;
  5604. });
  5605. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  5606. return !!block;
  5607. });
  5608. if (isExperimentalTreeBlock) {
  5609. updatedBlockMap = updateBlockMapLinks$1(updatedBlockMap, startBlock, endBlock, blockMap);
  5610. }
  5611. return contentState.merge({
  5612. blockMap: updatedBlockMap,
  5613. selectionBefore: selectionState,
  5614. selectionAfter: selectionState.merge({
  5615. anchorKey: startKey,
  5616. anchorOffset: startOffset,
  5617. focusKey: startKey,
  5618. focusOffset: startOffset,
  5619. isBackward: false
  5620. })
  5621. });
  5622. };
  5623. /**
  5624. * Maintain persistence for target list when removing characters on the
  5625. * head and tail of the character list.
  5626. */
  5627. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  5628. if (startOffset === 0) {
  5629. while (startOffset < endOffset) {
  5630. targetList = targetList.shift();
  5631. startOffset++;
  5632. }
  5633. } else if (endOffset === targetList.count()) {
  5634. while (endOffset > startOffset) {
  5635. targetList = targetList.pop();
  5636. endOffset--;
  5637. }
  5638. } else {
  5639. var head = targetList.slice(0, startOffset);
  5640. var tail = targetList.slice(endOffset);
  5641. targetList = head.concat(tail).toList();
  5642. }
  5643. return targetList;
  5644. };
  5645. var removeRangeFromContentState_1 = removeRangeFromContentState;
  5646. var List$4 = immutable.List,
  5647. Map$6 = immutable.Map;
  5648. var transformBlock$1 = function transformBlock(key, blockMap, func) {
  5649. if (!key) {
  5650. return;
  5651. }
  5652. var block = blockMap.get(key);
  5653. if (!block) {
  5654. return;
  5655. }
  5656. blockMap.set(key, func(block));
  5657. };
  5658. var updateBlockMapLinks$2 = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  5659. return blockMap.withMutations(function (blocks) {
  5660. var originalBlockKey = originalBlock.getKey();
  5661. var belowBlockKey = belowBlock.getKey();
  5662. // update block parent
  5663. transformBlock$1(originalBlock.getParentKey(), blocks, function (block) {
  5664. var parentChildrenList = block.getChildKeys();
  5665. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  5666. var newChildrenArray = parentChildrenList.toArray();
  5667. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  5668. return block.merge({
  5669. children: List$4(newChildrenArray)
  5670. });
  5671. });
  5672. // update original next block
  5673. transformBlock$1(originalBlock.getNextSiblingKey(), blocks, function (block) {
  5674. return block.merge({
  5675. prevSibling: belowBlockKey
  5676. });
  5677. });
  5678. // update original block
  5679. transformBlock$1(originalBlockKey, blocks, function (block) {
  5680. return block.merge({
  5681. nextSibling: belowBlockKey
  5682. });
  5683. });
  5684. // update below block
  5685. transformBlock$1(belowBlockKey, blocks, function (block) {
  5686. return block.merge({
  5687. prevSibling: originalBlockKey
  5688. });
  5689. });
  5690. });
  5691. };
  5692. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  5693. !selectionState.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Selection range must be collapsed.') : invariant_1(false) : void 0;
  5694. var key = selectionState.getAnchorKey();
  5695. var offset = selectionState.getAnchorOffset();
  5696. var blockMap = contentState.getBlockMap();
  5697. var blockToSplit = blockMap.get(key);
  5698. var text = blockToSplit.getText();
  5699. var chars = blockToSplit.getCharacterList();
  5700. var keyBelow = generateRandomKey_1();
  5701. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode_1;
  5702. var blockAbove = blockToSplit.merge({
  5703. text: text.slice(0, offset),
  5704. characterList: chars.slice(0, offset)
  5705. });
  5706. var blockBelow = blockAbove.merge({
  5707. key: keyBelow,
  5708. text: text.slice(offset),
  5709. characterList: chars.slice(offset),
  5710. data: Map$6()
  5711. });
  5712. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  5713. return v === blockToSplit;
  5714. });
  5715. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  5716. return v === blockToSplit;
  5717. }).rest();
  5718. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  5719. if (isExperimentalTreeBlock) {
  5720. !blockToSplit.getChildKeys().isEmpty() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'ContentBlockNode must not have children') : invariant_1(false) : void 0;
  5721. newBlocks = updateBlockMapLinks$2(newBlocks, blockAbove, blockBelow);
  5722. }
  5723. return contentState.merge({
  5724. blockMap: newBlocks,
  5725. selectionBefore: selectionState,
  5726. selectionAfter: selectionState.merge({
  5727. anchorKey: keyBelow,
  5728. anchorOffset: 0,
  5729. focusKey: keyBelow,
  5730. focusOffset: 0,
  5731. isBackward: false
  5732. })
  5733. });
  5734. };
  5735. var splitBlockInContentState_1 = splitBlockInContentState;
  5736. var OrderedSet$3 = immutable.OrderedSet;
  5737. /**
  5738. * `DraftModifier` provides a set of convenience methods that apply
  5739. * modifications to a `ContentState` object based on a target `SelectionState`.
  5740. *
  5741. * Any change to a `ContentState` should be decomposable into a series of
  5742. * transaction functions that apply the required changes and return output
  5743. * `ContentState` objects.
  5744. *
  5745. * These functions encapsulate some of the most common transaction sequences.
  5746. */
  5747. var DraftModifier = {
  5748. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  5749. var withoutEntities = removeEntitiesAtEdges_1(contentState, rangeToReplace);
  5750. var withoutText = removeRangeFromContentState_1(withoutEntities, rangeToReplace);
  5751. var character = CharacterMetadata_1.create({
  5752. style: inlineStyle || OrderedSet$3(),
  5753. entity: entityKey || null
  5754. });
  5755. return insertTextIntoContentState_1(withoutText, withoutText.getSelectionAfter(), text, character);
  5756. },
  5757. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  5758. !targetRange.isCollapsed() ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Target range must be collapsed for `insertText`.') : invariant_1(false) : void 0;
  5759. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  5760. },
  5761. moveText: function moveText(contentState, removalRange, targetRange) {
  5762. var movedFragment = getContentStateFragment_1(contentState, removalRange);
  5763. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  5764. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  5765. },
  5766. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  5767. var withoutEntities = removeEntitiesAtEdges_1(contentState, targetRange);
  5768. var withoutText = removeRangeFromContentState_1(withoutEntities, targetRange);
  5769. return insertFragmentIntoContentState_1(withoutText, withoutText.getSelectionAfter(), fragment);
  5770. },
  5771. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  5772. var startKey = void 0,
  5773. endKey = void 0,
  5774. startBlock = void 0,
  5775. endBlock = void 0;
  5776. if (rangeToRemove.getIsBackward()) {
  5777. rangeToRemove = rangeToRemove.merge({
  5778. anchorKey: rangeToRemove.getFocusKey(),
  5779. anchorOffset: rangeToRemove.getFocusOffset(),
  5780. focusKey: rangeToRemove.getAnchorKey(),
  5781. focusOffset: rangeToRemove.getAnchorOffset(),
  5782. isBackward: false
  5783. });
  5784. }
  5785. startKey = rangeToRemove.getAnchorKey();
  5786. endKey = rangeToRemove.getFocusKey();
  5787. startBlock = contentState.getBlockForKey(startKey);
  5788. endBlock = contentState.getBlockForKey(endKey);
  5789. var startOffset = rangeToRemove.getStartOffset();
  5790. var endOffset = rangeToRemove.getEndOffset();
  5791. var startEntityKey = startBlock.getEntityAt(startOffset);
  5792. var endEntityKey = endBlock.getEntityAt(endOffset - 1);
  5793. // Check whether the selection state overlaps with a single entity.
  5794. // If so, try to remove the appropriate substring of the entity text.
  5795. if (startKey === endKey) {
  5796. if (startEntityKey && startEntityKey === endEntityKey) {
  5797. var _adjustedRemovalRange = getCharacterRemovalRange_1(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  5798. return removeRangeFromContentState_1(contentState, _adjustedRemovalRange);
  5799. }
  5800. }
  5801. var adjustedRemovalRange = rangeToRemove;
  5802. var withoutEntities = removeEntitiesAtEdges_1(contentState, adjustedRemovalRange);
  5803. return removeRangeFromContentState_1(withoutEntities, adjustedRemovalRange);
  5804. },
  5805. splitBlock: function splitBlock(contentState, selectionState) {
  5806. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5807. var withoutText = removeRangeFromContentState_1(withoutEntities, selectionState);
  5808. return splitBlockInContentState_1(withoutText, withoutText.getSelectionAfter());
  5809. },
  5810. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  5811. return ContentStateInlineStyle_1.add(contentState, selectionState, inlineStyle);
  5812. },
  5813. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  5814. return ContentStateInlineStyle_1.remove(contentState, selectionState, inlineStyle);
  5815. },
  5816. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  5817. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5818. return block.merge({ type: blockType, depth: 0 });
  5819. });
  5820. },
  5821. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  5822. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5823. return block.merge({ data: blockData });
  5824. });
  5825. },
  5826. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  5827. return modifyBlockForContentState_1(contentState, selectionState, function (block) {
  5828. return block.merge({ data: block.getData().merge(blockData) });
  5829. });
  5830. },
  5831. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  5832. var withoutEntities = removeEntitiesAtEdges_1(contentState, selectionState);
  5833. return applyEntityToContentState_1(withoutEntities, selectionState, entityKey);
  5834. }
  5835. };
  5836. var DraftModifier_1 = DraftModifier;
  5837. /**
  5838. * Copyright (c) 2013-present, Facebook, Inc.
  5839. *
  5840. * This source code is licensed under the MIT license found in the
  5841. * LICENSE file in the root directory of this source tree.
  5842. *
  5843. *
  5844. */
  5845. function makeEmptyFunction(arg) {
  5846. return function () {
  5847. return arg;
  5848. };
  5849. }
  5850. /**
  5851. * This function accepts and discards inputs; it has no side effects. This is
  5852. * primarily useful idiomatically for overridable function endpoints which
  5853. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  5854. */
  5855. var emptyFunction = function emptyFunction() {};
  5856. emptyFunction.thatReturns = makeEmptyFunction;
  5857. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  5858. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  5859. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  5860. emptyFunction.thatReturnsThis = function () {
  5861. return this;
  5862. };
  5863. emptyFunction.thatReturnsArgument = function (arg) {
  5864. return arg;
  5865. };
  5866. var emptyFunction_1 = emptyFunction;
  5867. var List$5 = immutable.List,
  5868. Repeat$3 = immutable.Repeat,
  5869. Record$3 = immutable.Record;
  5870. var returnTrue = emptyFunction_1.thatReturnsTrue;
  5871. var FINGERPRINT_DELIMITER = '-';
  5872. var defaultLeafRange = {
  5873. start: null,
  5874. end: null
  5875. };
  5876. var LeafRange = Record$3(defaultLeafRange);
  5877. var defaultDecoratorRange = {
  5878. start: null,
  5879. end: null,
  5880. decoratorKey: null,
  5881. leaves: null
  5882. };
  5883. var DecoratorRange = Record$3(defaultDecoratorRange);
  5884. var BlockTree = {
  5885. /**
  5886. * Generate a block tree for a given ContentBlock/decorator pair.
  5887. */
  5888. generate: function generate(contentState, block, decorator) {
  5889. var textLength = block.getLength();
  5890. if (!textLength) {
  5891. return List$5.of(new DecoratorRange({
  5892. start: 0,
  5893. end: 0,
  5894. decoratorKey: null,
  5895. leaves: List$5.of(new LeafRange({ start: 0, end: 0 }))
  5896. }));
  5897. }
  5898. var leafSets = [];
  5899. var decorations = decorator ? decorator.getDecorations(block, contentState) : List$5(Repeat$3(null, textLength));
  5900. var chars = block.getCharacterList();
  5901. findRangesImmutable_1(decorations, areEqual, returnTrue, function (start, end) {
  5902. leafSets.push(new DecoratorRange({
  5903. start: start,
  5904. end: end,
  5905. decoratorKey: decorations.get(start),
  5906. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  5907. }));
  5908. });
  5909. return List$5(leafSets);
  5910. },
  5911. /**
  5912. * Create a string representation of the given tree map. This allows us
  5913. * to rapidly determine whether a tree has undergone a significant
  5914. * structural change.
  5915. */
  5916. getFingerprint: function getFingerprint(tree) {
  5917. return tree.map(function (leafSet) {
  5918. var decoratorKey = leafSet.get('decoratorKey');
  5919. var fingerprintString = decoratorKey !== null ? decoratorKey + '.' + (leafSet.get('end') - leafSet.get('start')) : '';
  5920. return '' + fingerprintString + '.' + leafSet.get('leaves').size;
  5921. }).join(FINGERPRINT_DELIMITER);
  5922. }
  5923. };
  5924. /**
  5925. * Generate LeafRange records for a given character list.
  5926. */
  5927. function generateLeaves(characters, offset) {
  5928. var leaves = [];
  5929. var inlineStyles = characters.map(function (c) {
  5930. return c.getStyle();
  5931. }).toList();
  5932. findRangesImmutable_1(inlineStyles, areEqual, returnTrue, function (start, end) {
  5933. leaves.push(new LeafRange({
  5934. start: start + offset,
  5935. end: end + offset
  5936. }));
  5937. });
  5938. return List$5(leaves);
  5939. }
  5940. function areEqual(a, b) {
  5941. return a === b;
  5942. }
  5943. var BlockTree_1 = BlockTree;
  5944. function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5945. function _possibleConstructorReturn$3(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5946. function _inherits$3(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5947. var Record$4 = immutable.Record;
  5948. var DraftEntityInstanceRecord = Record$4({
  5949. type: 'TOKEN',
  5950. mutability: 'IMMUTABLE',
  5951. data: Object
  5952. });
  5953. /**
  5954. * An instance of a document entity, consisting of a `type` and relevant
  5955. * `data`, metadata about the entity.
  5956. *
  5957. * For instance, a "link" entity might provide a URI, and a "mention"
  5958. * entity might provide the mentioned user's ID. These pieces of data
  5959. * may be used when rendering the entity as part of a ContentBlock DOM
  5960. * representation. For a link, the data would be used as an href for
  5961. * the rendered anchor. For a mention, the ID could be used to retrieve
  5962. * a hovercard.
  5963. */
  5964. var DraftEntityInstance = function (_DraftEntityInstanceR) {
  5965. _inherits$3(DraftEntityInstance, _DraftEntityInstanceR);
  5966. function DraftEntityInstance() {
  5967. _classCallCheck$3(this, DraftEntityInstance);
  5968. return _possibleConstructorReturn$3(this, _DraftEntityInstanceR.apply(this, arguments));
  5969. }
  5970. DraftEntityInstance.prototype.getType = function getType() {
  5971. return this.get('type');
  5972. };
  5973. DraftEntityInstance.prototype.getMutability = function getMutability() {
  5974. return this.get('mutability');
  5975. };
  5976. DraftEntityInstance.prototype.getData = function getData() {
  5977. return this.get('data');
  5978. };
  5979. return DraftEntityInstance;
  5980. }(DraftEntityInstanceRecord);
  5981. var DraftEntityInstance_1 = DraftEntityInstance;
  5982. var _extends = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  5983. /**
  5984. * Copyright (c) 2013-present, Facebook, Inc.
  5985. * All rights reserved.
  5986. *
  5987. * This source code is licensed under the BSD-style license found in the
  5988. * LICENSE file in the root directory of this source tree. An additional grant
  5989. * of patent rights can be found in the PATENTS file in the same directory.
  5990. *
  5991. * @providesModule DraftEntity
  5992. * @format
  5993. *
  5994. */
  5995. var Map$7 = immutable.Map;
  5996. var instances = Map$7();
  5997. var instanceKey = 0;
  5998. /**
  5999. * Temporary utility for generating the warnings
  6000. */
  6001. function logWarning(oldMethodCall, newMethodCall) {
  6002. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  6003. }
  6004. /**
  6005. * A "document entity" is an object containing metadata associated with a
  6006. * piece of text in a ContentBlock.
  6007. *
  6008. * For example, a `link` entity might include a `uri` property. When a
  6009. * ContentBlock is rendered in the browser, text that refers to that link
  6010. * entity may be rendered as an anchor, with the `uri` as the href value.
  6011. *
  6012. * In a ContentBlock, every position in the text may correspond to zero
  6013. * or one entities. This correspondence is tracked using a key string,
  6014. * generated via DraftEntity.create() and used to obtain entity metadata
  6015. * via DraftEntity.get().
  6016. */
  6017. var DraftEntity = {
  6018. /**
  6019. * WARNING: This method will be deprecated soon!
  6020. * Please use 'contentState.getLastCreatedEntityKey' instead.
  6021. * ---
  6022. * Get the random key string from whatever entity was last created.
  6023. * We need this to support the new API, as part of transitioning to put Entity
  6024. * storage in contentState.
  6025. */
  6026. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  6027. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  6028. return DraftEntity.__getLastCreatedEntityKey();
  6029. },
  6030. /**
  6031. * WARNING: This method will be deprecated soon!
  6032. * Please use 'contentState.createEntity' instead.
  6033. * ---
  6034. * Create a DraftEntityInstance and store it for later retrieval.
  6035. *
  6036. * A random key string will be generated and returned. This key may
  6037. * be used to track the entity's usage in a ContentBlock, and for
  6038. * retrieving data about the entity at render time.
  6039. */
  6040. create: function create(type, mutability, data) {
  6041. logWarning('DraftEntity.create', 'contentState.createEntity');
  6042. return DraftEntity.__create(type, mutability, data);
  6043. },
  6044. /**
  6045. * WARNING: This method will be deprecated soon!
  6046. * Please use 'contentState.addEntity' instead.
  6047. * ---
  6048. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6049. * useful when restoring instances from the server.
  6050. */
  6051. add: function add(instance) {
  6052. logWarning('DraftEntity.add', 'contentState.addEntity');
  6053. return DraftEntity.__add(instance);
  6054. },
  6055. /**
  6056. * WARNING: This method will be deprecated soon!
  6057. * Please use 'contentState.getEntity' instead.
  6058. * ---
  6059. * Retrieve the entity corresponding to the supplied key string.
  6060. */
  6061. get: function get(key) {
  6062. logWarning('DraftEntity.get', 'contentState.getEntity');
  6063. return DraftEntity.__get(key);
  6064. },
  6065. /**
  6066. * WARNING: This method will be deprecated soon!
  6067. * Please use 'contentState.mergeEntityData' instead.
  6068. * ---
  6069. * Entity instances are immutable. If you need to update the data for an
  6070. * instance, this method will merge your data updates and return a new
  6071. * instance.
  6072. */
  6073. mergeData: function mergeData(key, toMerge) {
  6074. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  6075. return DraftEntity.__mergeData(key, toMerge);
  6076. },
  6077. /**
  6078. * WARNING: This method will be deprecated soon!
  6079. * Please use 'contentState.replaceEntityData' instead.
  6080. * ---
  6081. * Completely replace the data for a given instance.
  6082. */
  6083. replaceData: function replaceData(key, newData) {
  6084. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  6085. return DraftEntity.__replaceData(key, newData);
  6086. },
  6087. // ***********************************WARNING******************************
  6088. // --- the above public API will be deprecated in the next version of Draft!
  6089. // The methods below this line are private - don't call them directly.
  6090. /**
  6091. * Get the random key string from whatever entity was last created.
  6092. * We need this to support the new API, as part of transitioning to put Entity
  6093. * storage in contentState.
  6094. */
  6095. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  6096. return '' + instanceKey;
  6097. },
  6098. /**
  6099. * Create a DraftEntityInstance and store it for later retrieval.
  6100. *
  6101. * A random key string will be generated and returned. This key may
  6102. * be used to track the entity's usage in a ContentBlock, and for
  6103. * retrieving data about the entity at render time.
  6104. */
  6105. __create: function __create(type, mutability, data) {
  6106. return DraftEntity.__add(new DraftEntityInstance_1({ type: type, mutability: mutability, data: data || {} }));
  6107. },
  6108. /**
  6109. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  6110. * useful when restoring instances from the server.
  6111. */
  6112. __add: function __add(instance) {
  6113. var key = '' + ++instanceKey;
  6114. instances = instances.set(key, instance);
  6115. return key;
  6116. },
  6117. /**
  6118. * Retrieve the entity corresponding to the supplied key string.
  6119. */
  6120. __get: function __get(key) {
  6121. var instance = instances.get(key);
  6122. !!!instance ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown DraftEntity key: %s.', key) : invariant_1(false) : void 0;
  6123. return instance;
  6124. },
  6125. /**
  6126. * Entity instances are immutable. If you need to update the data for an
  6127. * instance, this method will merge your data updates and return a new
  6128. * instance.
  6129. */
  6130. __mergeData: function __mergeData(key, toMerge) {
  6131. var instance = DraftEntity.__get(key);
  6132. var newData = _extends({}, instance.getData(), toMerge);
  6133. var newInstance = instance.set('data', newData);
  6134. instances = instances.set(key, newInstance);
  6135. return newInstance;
  6136. },
  6137. /**
  6138. * Completely replace the data for a given instance.
  6139. */
  6140. __replaceData: function __replaceData(key, newData) {
  6141. var instance = DraftEntity.__get(key);
  6142. var newInstance = instance.set('data', newData);
  6143. instances = instances.set(key, newInstance);
  6144. return newInstance;
  6145. }
  6146. };
  6147. var DraftEntity_1 = DraftEntity;
  6148. function _classCallCheck$4(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6149. function _possibleConstructorReturn$4(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6150. function _inherits$4(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6151. var Record$5 = immutable.Record;
  6152. var defaultRecord$3 = {
  6153. anchorKey: '',
  6154. anchorOffset: 0,
  6155. focusKey: '',
  6156. focusOffset: 0,
  6157. isBackward: false,
  6158. hasFocus: false
  6159. };
  6160. var SelectionStateRecord = Record$5(defaultRecord$3);
  6161. var SelectionState = function (_SelectionStateRecord) {
  6162. _inherits$4(SelectionState, _SelectionStateRecord);
  6163. function SelectionState() {
  6164. _classCallCheck$4(this, SelectionState);
  6165. return _possibleConstructorReturn$4(this, _SelectionStateRecord.apply(this, arguments));
  6166. }
  6167. SelectionState.prototype.serialize = function serialize() {
  6168. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  6169. };
  6170. SelectionState.prototype.getAnchorKey = function getAnchorKey() {
  6171. return this.get('anchorKey');
  6172. };
  6173. SelectionState.prototype.getAnchorOffset = function getAnchorOffset() {
  6174. return this.get('anchorOffset');
  6175. };
  6176. SelectionState.prototype.getFocusKey = function getFocusKey() {
  6177. return this.get('focusKey');
  6178. };
  6179. SelectionState.prototype.getFocusOffset = function getFocusOffset() {
  6180. return this.get('focusOffset');
  6181. };
  6182. SelectionState.prototype.getIsBackward = function getIsBackward() {
  6183. return this.get('isBackward');
  6184. };
  6185. SelectionState.prototype.getHasFocus = function getHasFocus() {
  6186. return this.get('hasFocus');
  6187. };
  6188. /**
  6189. * Return whether the specified range overlaps with an edge of the
  6190. * SelectionState.
  6191. */
  6192. SelectionState.prototype.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  6193. var anchorKey = this.getAnchorKey();
  6194. var focusKey = this.getFocusKey();
  6195. if (anchorKey === focusKey && anchorKey === blockKey) {
  6196. var selectionStart = this.getStartOffset();
  6197. var selectionEnd = this.getEndOffset();
  6198. return start <= selectionEnd && selectionStart <= end;
  6199. }
  6200. if (blockKey !== anchorKey && blockKey !== focusKey) {
  6201. return false;
  6202. }
  6203. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  6204. return start <= offsetToCheck && end >= offsetToCheck;
  6205. };
  6206. SelectionState.prototype.isCollapsed = function isCollapsed() {
  6207. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  6208. };
  6209. SelectionState.prototype.getStartKey = function getStartKey() {
  6210. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  6211. };
  6212. SelectionState.prototype.getStartOffset = function getStartOffset() {
  6213. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  6214. };
  6215. SelectionState.prototype.getEndKey = function getEndKey() {
  6216. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  6217. };
  6218. SelectionState.prototype.getEndOffset = function getEndOffset() {
  6219. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  6220. };
  6221. SelectionState.createEmpty = function createEmpty(key) {
  6222. return new SelectionState({
  6223. anchorKey: key,
  6224. anchorOffset: 0,
  6225. focusKey: key,
  6226. focusOffset: 0,
  6227. isBackward: false,
  6228. hasFocus: false
  6229. });
  6230. };
  6231. return SelectionState;
  6232. }(SelectionStateRecord);
  6233. var SelectionState_1 = SelectionState;
  6234. /**
  6235. * Copyright (c) 2013-present, Facebook, Inc.
  6236. * All rights reserved.
  6237. *
  6238. * This source code is licensed under the BSD-style license found in the
  6239. * LICENSE file in the root directory of this source tree. An additional grant
  6240. * of patent rights can be found in the PATENTS file in the same directory.
  6241. *
  6242. * @providesModule sanitizeDraftText
  6243. * @format
  6244. *
  6245. */
  6246. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  6247. function sanitizeDraftText(input) {
  6248. return input.replace(REGEX_BLOCK_DELIMITER, '');
  6249. }
  6250. var sanitizeDraftText_1 = sanitizeDraftText;
  6251. function _classCallCheck$5(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6252. function _possibleConstructorReturn$5(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6253. function _inherits$5(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6254. var List$6 = immutable.List,
  6255. Record$6 = immutable.Record,
  6256. Repeat$4 = immutable.Repeat;
  6257. var defaultRecord$4 = {
  6258. entityMap: null,
  6259. blockMap: null,
  6260. selectionBefore: null,
  6261. selectionAfter: null
  6262. };
  6263. var ContentBlockNodeRecord = ContentBlock_1;
  6264. var ContentStateRecord = Record$6(defaultRecord$4);
  6265. var ContentState = function (_ContentStateRecord) {
  6266. _inherits$5(ContentState, _ContentStateRecord);
  6267. function ContentState() {
  6268. _classCallCheck$5(this, ContentState);
  6269. return _possibleConstructorReturn$5(this, _ContentStateRecord.apply(this, arguments));
  6270. }
  6271. ContentState.prototype.getEntityMap = function getEntityMap() {
  6272. // TODO: update this when we fully remove DraftEntity
  6273. return DraftEntity_1;
  6274. };
  6275. ContentState.prototype.getBlockMap = function getBlockMap() {
  6276. return this.get('blockMap');
  6277. };
  6278. ContentState.prototype.getSelectionBefore = function getSelectionBefore() {
  6279. return this.get('selectionBefore');
  6280. };
  6281. ContentState.prototype.getSelectionAfter = function getSelectionAfter() {
  6282. return this.get('selectionAfter');
  6283. };
  6284. ContentState.prototype.getBlockForKey = function getBlockForKey(key) {
  6285. var block = this.getBlockMap().get(key);
  6286. return block;
  6287. };
  6288. ContentState.prototype.getKeyBefore = function getKeyBefore(key) {
  6289. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  6290. return v === key;
  6291. }).skip(1).first();
  6292. };
  6293. ContentState.prototype.getKeyAfter = function getKeyAfter(key) {
  6294. return this.getBlockMap().keySeq().skipUntil(function (v) {
  6295. return v === key;
  6296. }).skip(1).first();
  6297. };
  6298. ContentState.prototype.getBlockAfter = function getBlockAfter(key) {
  6299. return this.getBlockMap().skipUntil(function (_, k) {
  6300. return k === key;
  6301. }).skip(1).first();
  6302. };
  6303. ContentState.prototype.getBlockBefore = function getBlockBefore(key) {
  6304. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  6305. return k === key;
  6306. }).skip(1).first();
  6307. };
  6308. ContentState.prototype.getBlocksAsArray = function getBlocksAsArray() {
  6309. return this.getBlockMap().toArray();
  6310. };
  6311. ContentState.prototype.getFirstBlock = function getFirstBlock() {
  6312. return this.getBlockMap().first();
  6313. };
  6314. ContentState.prototype.getLastBlock = function getLastBlock() {
  6315. return this.getBlockMap().last();
  6316. };
  6317. ContentState.prototype.getPlainText = function getPlainText(delimiter) {
  6318. return this.getBlockMap().map(function (block) {
  6319. return block ? block.getText() : '';
  6320. }).join(delimiter || '\n');
  6321. };
  6322. ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  6323. // TODO: update this when we fully remove DraftEntity
  6324. return DraftEntity_1.__getLastCreatedEntityKey();
  6325. };
  6326. ContentState.prototype.hasText = function hasText() {
  6327. var blockMap = this.getBlockMap();
  6328. return blockMap.size > 1 || blockMap.first().getLength() > 0;
  6329. };
  6330. ContentState.prototype.createEntity = function createEntity(type, mutability, data) {
  6331. // TODO: update this when we fully remove DraftEntity
  6332. DraftEntity_1.__create(type, mutability, data);
  6333. return this;
  6334. };
  6335. ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) {
  6336. // TODO: update this when we fully remove DraftEntity
  6337. DraftEntity_1.__mergeData(key, toMerge);
  6338. return this;
  6339. };
  6340. ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) {
  6341. // TODO: update this when we fully remove DraftEntity
  6342. DraftEntity_1.__replaceData(key, newData);
  6343. return this;
  6344. };
  6345. ContentState.prototype.addEntity = function addEntity(instance) {
  6346. // TODO: update this when we fully remove DraftEntity
  6347. DraftEntity_1.__add(instance);
  6348. return this;
  6349. };
  6350. ContentState.prototype.getEntity = function getEntity(key) {
  6351. // TODO: update this when we fully remove DraftEntity
  6352. return DraftEntity_1.__get(key);
  6353. };
  6354. ContentState.createFromBlockArray = function createFromBlockArray(
  6355. // TODO: update flow type when we completely deprecate the old entity API
  6356. blocks, entityMap) {
  6357. // TODO: remove this when we completely deprecate the old entity API
  6358. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  6359. var blockMap = BlockMapBuilder_1.createFromArray(theBlocks);
  6360. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  6361. return new ContentState({
  6362. blockMap: blockMap,
  6363. entityMap: entityMap || DraftEntity_1,
  6364. selectionBefore: selectionState,
  6365. selectionAfter: selectionState
  6366. });
  6367. };
  6368. ContentState.createFromText = function createFromText(text) {
  6369. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  6370. var strings = text.split(delimiter);
  6371. var blocks = strings.map(function (block) {
  6372. block = sanitizeDraftText_1(block);
  6373. return new ContentBlockNodeRecord({
  6374. key: generateRandomKey_1(),
  6375. text: block,
  6376. type: 'unstyled',
  6377. characterList: List$6(Repeat$4(CharacterMetadata_1.EMPTY, block.length))
  6378. });
  6379. });
  6380. return ContentState.createFromBlockArray(blocks);
  6381. };
  6382. return ContentState;
  6383. }(ContentStateRecord);
  6384. var ContentState_1 = ContentState;
  6385. var NEUTRAL = 'NEUTRAL'; // No strong direction
  6386. var LTR = 'LTR'; // Left-to-Right direction
  6387. var RTL = 'RTL'; // Right-to-Left direction
  6388. var globalDir = null;
  6389. // == Helpers ==
  6390. /**
  6391. * Check if a directionality value is a Strong one
  6392. */
  6393. function isStrong(dir) {
  6394. return dir === LTR || dir === RTL;
  6395. }
  6396. /**
  6397. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6398. * property.
  6399. */
  6400. function getHTMLDir(dir) {
  6401. !isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6402. return dir === LTR ? 'ltr' : 'rtl';
  6403. }
  6404. /**
  6405. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  6406. * property, but returns null if `dir` has same value as `otherDir`.
  6407. * `null`.
  6408. */
  6409. function getHTMLDirIfDifferent(dir, otherDir) {
  6410. !isStrong(dir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6411. !isStrong(otherDir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '`otherDir` must be a strong direction to be converted to HTML Direction') : invariant_1(false) : void 0;
  6412. return dir === otherDir ? null : getHTMLDir(dir);
  6413. }
  6414. // == Global Direction ==
  6415. /**
  6416. * Set the global direction.
  6417. */
  6418. function setGlobalDir(dir) {
  6419. globalDir = dir;
  6420. }
  6421. /**
  6422. * Initialize the global direction
  6423. */
  6424. function initGlobalDir() {
  6425. setGlobalDir(LTR);
  6426. }
  6427. /**
  6428. * Get the global direction
  6429. */
  6430. function getGlobalDir() {
  6431. if (!globalDir) {
  6432. this.initGlobalDir();
  6433. }
  6434. !globalDir ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Global direction not set.') : invariant_1(false) : void 0;
  6435. return globalDir;
  6436. }
  6437. var UnicodeBidiDirection = {
  6438. // Values
  6439. NEUTRAL: NEUTRAL,
  6440. LTR: LTR,
  6441. RTL: RTL,
  6442. // Helpers
  6443. isStrong: isStrong,
  6444. getHTMLDir: getHTMLDir,
  6445. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  6446. // Global Direction
  6447. setGlobalDir: setGlobalDir,
  6448. initGlobalDir: initGlobalDir,
  6449. getGlobalDir: getGlobalDir
  6450. };
  6451. var UnicodeBidiDirection_1 = UnicodeBidiDirection;
  6452. /**
  6453. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  6454. *
  6455. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  6456. *
  6457. * NOTE: For performance reasons, we only support Unicode's
  6458. * Basic Multilingual Plane (BMP) for now.
  6459. */
  6460. var RANGE_BY_BIDI_TYPE = {
  6461. L: 'A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u01BA\u01BB' + '\u01BC-\u01BF\u01C0-\u01C3\u01C4-\u0293\u0294\u0295-\u02AF\u02B0-\u02B8' + '\u02BB-\u02C1\u02D0-\u02D1\u02E0-\u02E4\u02EE\u0370-\u0373\u0376-\u0377' + '\u037A\u037B-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1' + '\u03A3-\u03F5\u03F7-\u0481\u0482\u048A-\u052F\u0531-\u0556\u0559' + '\u055A-\u055F\u0561-\u0587\u0589\u0903\u0904-\u0939\u093B\u093D' + '\u093E-\u0940\u0949-\u094C\u094E-\u094F\u0950\u0958-\u0961\u0964-\u0965' + '\u0966-\u096F\u0970\u0971\u0972-\u0980\u0982-\u0983\u0985-\u098C' + '\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD' + '\u09BE-\u09C0\u09C7-\u09C8\u09CB-\u09CC\u09CE\u09D7\u09DC-\u09DD' + '\u09DF-\u09E1\u09E6-\u09EF\u09F0-\u09F1\u09F4-\u09F9\u09FA\u0A03' + '\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33' + '\u0A35-\u0A36\u0A38-\u0A39\u0A3E-\u0A40\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F' + '\u0A72-\u0A74\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0' + '\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0ABE-\u0AC0\u0AC9\u0ACB-\u0ACC\u0AD0' + '\u0AE0-\u0AE1\u0AE6-\u0AEF\u0AF0\u0B02-\u0B03\u0B05-\u0B0C\u0B0F-\u0B10' + '\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B35-\u0B39\u0B3D\u0B3E\u0B40' + '\u0B47-\u0B48\u0B4B-\u0B4C\u0B57\u0B5C-\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F' + '\u0B70\u0B71\u0B72-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95' + '\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9' + '\u0BBE-\u0BBF\u0BC1-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0BD0\u0BD7' + '\u0BE6-\u0BEF\u0BF0-\u0BF2\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10' + '\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C41-\u0C44\u0C58-\u0C59\u0C60-\u0C61' + '\u0C66-\u0C6F\u0C7F\u0C82-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8' + '\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CBE\u0CBF\u0CC0-\u0CC4\u0CC6' + '\u0CC7-\u0CC8\u0CCA-\u0CCB\u0CD5-\u0CD6\u0CDE\u0CE0-\u0CE1\u0CE6-\u0CEF' + '\u0CF1-\u0CF2\u0D02-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D' + '\u0D3E-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D4E\u0D57\u0D60-\u0D61' + '\u0D66-\u0D6F\u0D70-\u0D75\u0D79\u0D7A-\u0D7F\u0D82-\u0D83\u0D85-\u0D96' + '\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCF-\u0DD1\u0DD8-\u0DDF' + '\u0DE6-\u0DEF\u0DF2-\u0DF3\u0DF4\u0E01-\u0E30\u0E32-\u0E33\u0E40-\u0E45' + '\u0E46\u0E4F\u0E50-\u0E59\u0E5A-\u0E5B\u0E81-\u0E82\u0E84\u0E87-\u0E88' + '\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7' + '\u0EAA-\u0EAB\u0EAD-\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6' + '\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F01-\u0F03\u0F04-\u0F12\u0F13\u0F14' + '\u0F15-\u0F17\u0F1A-\u0F1F\u0F20-\u0F29\u0F2A-\u0F33\u0F34\u0F36\u0F38' + '\u0F3E-\u0F3F\u0F40-\u0F47\u0F49-\u0F6C\u0F7F\u0F85\u0F88-\u0F8C' + '\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE-\u0FCF\u0FD0-\u0FD4\u0FD5-\u0FD8' + '\u0FD9-\u0FDA\u1000-\u102A\u102B-\u102C\u1031\u1038\u103B-\u103C\u103F' + '\u1040-\u1049\u104A-\u104F\u1050-\u1055\u1056-\u1057\u105A-\u105D\u1061' + '\u1062-\u1064\u1065-\u1066\u1067-\u106D\u106E-\u1070\u1075-\u1081' + '\u1083-\u1084\u1087-\u108C\u108E\u108F\u1090-\u1099\u109A-\u109C' + '\u109E-\u109F\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FB\u10FC' + '\u10FD-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288' + '\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5' + '\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1360-\u1368' + '\u1369-\u137C\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166D-\u166E' + '\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EB-\u16ED\u16EE-\u16F0' + '\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1735-\u1736' + '\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17B6\u17BE-\u17C5' + '\u17C7-\u17C8\u17D4-\u17D6\u17D7\u17D8-\u17DA\u17DC\u17E0-\u17E9' + '\u1810-\u1819\u1820-\u1842\u1843\u1844-\u1877\u1880-\u18A8\u18AA' + '\u18B0-\u18F5\u1900-\u191E\u1923-\u1926\u1929-\u192B\u1930-\u1931' + '\u1933-\u1938\u1946-\u194F\u1950-\u196D\u1970-\u1974\u1980-\u19AB' + '\u19B0-\u19C0\u19C1-\u19C7\u19C8-\u19C9\u19D0-\u19D9\u19DA\u1A00-\u1A16' + '\u1A19-\u1A1A\u1A1E-\u1A1F\u1A20-\u1A54\u1A55\u1A57\u1A61\u1A63-\u1A64' + '\u1A6D-\u1A72\u1A80-\u1A89\u1A90-\u1A99\u1AA0-\u1AA6\u1AA7\u1AA8-\u1AAD' + '\u1B04\u1B05-\u1B33\u1B35\u1B3B\u1B3D-\u1B41\u1B43-\u1B44\u1B45-\u1B4B' + '\u1B50-\u1B59\u1B5A-\u1B60\u1B61-\u1B6A\u1B74-\u1B7C\u1B82\u1B83-\u1BA0' + '\u1BA1\u1BA6-\u1BA7\u1BAA\u1BAE-\u1BAF\u1BB0-\u1BB9\u1BBA-\u1BE5\u1BE7' + '\u1BEA-\u1BEC\u1BEE\u1BF2-\u1BF3\u1BFC-\u1BFF\u1C00-\u1C23\u1C24-\u1C2B' + '\u1C34-\u1C35\u1C3B-\u1C3F\u1C40-\u1C49\u1C4D-\u1C4F\u1C50-\u1C59' + '\u1C5A-\u1C77\u1C78-\u1C7D\u1C7E-\u1C7F\u1CC0-\u1CC7\u1CD3\u1CE1' + '\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF2-\u1CF3\u1CF5-\u1CF6\u1D00-\u1D2B' + '\u1D2C-\u1D6A\u1D6B-\u1D77\u1D78\u1D79-\u1D9A\u1D9B-\u1DBF\u1E00-\u1F15' + '\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D' + '\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC' + '\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200E' + '\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D' + '\u2124\u2126\u2128\u212A-\u212D\u212F-\u2134\u2135-\u2138\u2139' + '\u213C-\u213F\u2145-\u2149\u214E\u214F\u2160-\u2182\u2183-\u2184' + '\u2185-\u2188\u2336-\u237A\u2395\u249C-\u24E9\u26AC\u2800-\u28FF' + '\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2C7B\u2C7C-\u2C7D\u2C7E-\u2CE4' + '\u2CEB-\u2CEE\u2CF2-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F' + '\u2D70\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE' + '\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005\u3006\u3007' + '\u3021-\u3029\u302E-\u302F\u3031-\u3035\u3038-\u303A\u303B\u303C' + '\u3041-\u3096\u309D-\u309E\u309F\u30A1-\u30FA\u30FC-\u30FE\u30FF' + '\u3105-\u312D\u3131-\u318E\u3190-\u3191\u3192-\u3195\u3196-\u319F' + '\u31A0-\u31BA\u31F0-\u31FF\u3200-\u321C\u3220-\u3229\u322A-\u3247' + '\u3248-\u324F\u3260-\u327B\u327F\u3280-\u3289\u328A-\u32B0\u32C0-\u32CB' + '\u32D0-\u32FE\u3300-\u3376\u337B-\u33DD\u33E0-\u33FE\u3400-\u4DB5' + '\u4E00-\u9FCC\uA000-\uA014\uA015\uA016-\uA48C\uA4D0-\uA4F7\uA4F8-\uA4FD' + '\uA4FE-\uA4FF\uA500-\uA60B\uA60C\uA610-\uA61F\uA620-\uA629\uA62A-\uA62B' + '\uA640-\uA66D\uA66E\uA680-\uA69B\uA69C-\uA69D\uA6A0-\uA6E5\uA6E6-\uA6EF' + '\uA6F2-\uA6F7\uA722-\uA76F\uA770\uA771-\uA787\uA789-\uA78A\uA78B-\uA78E' + '\uA790-\uA7AD\uA7B0-\uA7B1\uA7F7\uA7F8-\uA7F9\uA7FA\uA7FB-\uA801' + '\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA823-\uA824\uA827\uA830-\uA835' + '\uA836-\uA837\uA840-\uA873\uA880-\uA881\uA882-\uA8B3\uA8B4-\uA8C3' + '\uA8CE-\uA8CF\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8F8-\uA8FA\uA8FB\uA900-\uA909' + '\uA90A-\uA925\uA92E-\uA92F\uA930-\uA946\uA952-\uA953\uA95F\uA960-\uA97C' + '\uA983\uA984-\uA9B2\uA9B4-\uA9B5\uA9BA-\uA9BB\uA9BD-\uA9C0\uA9C1-\uA9CD' + '\uA9CF\uA9D0-\uA9D9\uA9DE-\uA9DF\uA9E0-\uA9E4\uA9E6\uA9E7-\uA9EF' + '\uA9F0-\uA9F9\uA9FA-\uA9FE\uAA00-\uAA28\uAA2F-\uAA30\uAA33-\uAA34' + '\uAA40-\uAA42\uAA44-\uAA4B\uAA4D\uAA50-\uAA59\uAA5C-\uAA5F\uAA60-\uAA6F' + '\uAA70\uAA71-\uAA76\uAA77-\uAA79\uAA7A\uAA7B\uAA7D\uAA7E-\uAAAF\uAAB1' + '\uAAB5-\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADC\uAADD\uAADE-\uAADF' + '\uAAE0-\uAAEA\uAAEB\uAAEE-\uAAEF\uAAF0-\uAAF1\uAAF2\uAAF3-\uAAF4\uAAF5' + '\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E' + '\uAB30-\uAB5A\uAB5B\uAB5C-\uAB5F\uAB64-\uAB65\uABC0-\uABE2\uABE3-\uABE4' + '\uABE6-\uABE7\uABE9-\uABEA\uABEB\uABEC\uABF0-\uABF9\uAC00-\uD7A3' + '\uD7B0-\uD7C6\uD7CB-\uD7FB\uE000-\uF8FF\uF900-\uFA6D\uFA70-\uFAD9' + '\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFF6F\uFF70' + '\uFF71-\uFF9D\uFF9E-\uFF9F\uFFA0-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF' + '\uFFD2-\uFFD7\uFFDA-\uFFDC',
  6462. R: '\u0590\u05BE\u05C0\u05C3\u05C6\u05C8-\u05CF\u05D0-\u05EA\u05EB-\u05EF' + '\u05F0-\u05F2\u05F3-\u05F4\u05F5-\u05FF\u07C0-\u07C9\u07CA-\u07EA' + '\u07F4-\u07F5\u07FA\u07FB-\u07FF\u0800-\u0815\u081A\u0824\u0828' + '\u082E-\u082F\u0830-\u083E\u083F\u0840-\u0858\u085C-\u085D\u085E' + '\u085F-\u089F\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB37\uFB38-\uFB3C' + '\uFB3D\uFB3E\uFB3F\uFB40-\uFB41\uFB42\uFB43-\uFB44\uFB45\uFB46-\uFB4F',
  6463. AL: '\u0608\u060B\u060D\u061B\u061C\u061D\u061E-\u061F\u0620-\u063F\u0640' + '\u0641-\u064A\u066D\u066E-\u066F\u0671-\u06D3\u06D4\u06D5\u06E5-\u06E6' + '\u06EE-\u06EF\u06FA-\u06FC\u06FD-\u06FE\u06FF\u0700-\u070D\u070E\u070F' + '\u0710\u0712-\u072F\u074B-\u074C\u074D-\u07A5\u07B1\u07B2-\u07BF' + '\u08A0-\u08B2\u08B3-\u08E3\uFB50-\uFBB1\uFBB2-\uFBC1\uFBC2-\uFBD2' + '\uFBD3-\uFD3D\uFD40-\uFD4F\uFD50-\uFD8F\uFD90-\uFD91\uFD92-\uFDC7' + '\uFDC8-\uFDCF\uFDF0-\uFDFB\uFDFC\uFDFE-\uFDFF\uFE70-\uFE74\uFE75' + '\uFE76-\uFEFC\uFEFD-\uFEFE'
  6464. };
  6465. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6466. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  6467. /**
  6468. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  6469. *
  6470. * @param str A text block; e.g. paragraph, table cell, tag
  6471. * @return A character with strong bidi direction, or null if not found
  6472. */
  6473. function firstStrongChar(str) {
  6474. var match = REGEX_STRONG.exec(str);
  6475. return match == null ? null : match[0];
  6476. }
  6477. /**
  6478. * Returns the direction of a block of text, based on the direction of its
  6479. * first strong character (has Bidi_Class value of L, R, or AL).
  6480. *
  6481. * @param str A text block; e.g. paragraph, table cell, tag
  6482. * @return The resolved direction
  6483. */
  6484. function firstStrongCharDir(str) {
  6485. var strongChar = firstStrongChar(str);
  6486. if (strongChar == null) {
  6487. return UnicodeBidiDirection_1.NEUTRAL;
  6488. }
  6489. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection_1.RTL : UnicodeBidiDirection_1.LTR;
  6490. }
  6491. /**
  6492. * Returns the direction of a block of text, based on the direction of its
  6493. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6494. * direction, if no strong character is found.
  6495. *
  6496. * This function is supposed to be used in respect to Higher-Level Protocol
  6497. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6498. *
  6499. * @param str A text block; e.g. paragraph, table cell, tag
  6500. * @param fallback Fallback direction, used if no strong direction detected
  6501. * for the block (default = NEUTRAL)
  6502. * @return The resolved direction
  6503. */
  6504. function resolveBlockDir(str, fallback) {
  6505. fallback = fallback || UnicodeBidiDirection_1.NEUTRAL;
  6506. if (!str.length) {
  6507. return fallback;
  6508. }
  6509. var blockDir = firstStrongCharDir(str);
  6510. return blockDir === UnicodeBidiDirection_1.NEUTRAL ? fallback : blockDir;
  6511. }
  6512. /**
  6513. * Returns the direction of a block of text, based on the direction of its
  6514. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  6515. * direction, if no strong character is found.
  6516. *
  6517. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  6518. * direction as the fallback, so it *always* returns a Strong direction,
  6519. * making it useful for integration in places that you need to make the final
  6520. * decision, like setting some CSS class.
  6521. *
  6522. * This function is supposed to be used in respect to Higher-Level Protocol
  6523. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  6524. *
  6525. * @param str A text block; e.g. paragraph, table cell
  6526. * @param strongFallback Fallback direction, used if no strong direction
  6527. * detected for the block (default = global direction)
  6528. * @return The resolved Strong direction
  6529. */
  6530. function getDirection(str, strongFallback) {
  6531. if (!strongFallback) {
  6532. strongFallback = UnicodeBidiDirection_1.getGlobalDir();
  6533. }
  6534. !UnicodeBidiDirection_1.isStrong(strongFallback) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Fallback direction must be a strong direction') : invariant_1(false) : void 0;
  6535. return resolveBlockDir(str, strongFallback);
  6536. }
  6537. /**
  6538. * Returns true if getDirection(arguments...) returns LTR.
  6539. *
  6540. * @param str A text block; e.g. paragraph, table cell
  6541. * @param strongFallback Fallback direction, used if no strong direction
  6542. * detected for the block (default = global direction)
  6543. * @return True if the resolved direction is LTR
  6544. */
  6545. function isDirectionLTR(str, strongFallback) {
  6546. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.LTR;
  6547. }
  6548. /**
  6549. * Returns true if getDirection(arguments...) returns RTL.
  6550. *
  6551. * @param str A text block; e.g. paragraph, table cell
  6552. * @param strongFallback Fallback direction, used if no strong direction
  6553. * detected for the block (default = global direction)
  6554. * @return True if the resolved direction is RTL
  6555. */
  6556. function isDirectionRTL(str, strongFallback) {
  6557. return getDirection(str, strongFallback) === UnicodeBidiDirection_1.RTL;
  6558. }
  6559. var UnicodeBidi = {
  6560. firstStrongChar: firstStrongChar,
  6561. firstStrongCharDir: firstStrongCharDir,
  6562. resolveBlockDir: resolveBlockDir,
  6563. getDirection: getDirection,
  6564. isDirectionLTR: isDirectionLTR,
  6565. isDirectionRTL: isDirectionRTL
  6566. };
  6567. var UnicodeBidi_1 = UnicodeBidi;
  6568. function _classCallCheck$6(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6569. var UnicodeBidiService = function () {
  6570. /**
  6571. * Stateful class for paragraph direction detection
  6572. *
  6573. * @param defaultDir Default direction of the service
  6574. */
  6575. function UnicodeBidiService(defaultDir) {
  6576. _classCallCheck$6(this, UnicodeBidiService);
  6577. if (!defaultDir) {
  6578. defaultDir = UnicodeBidiDirection_1.getGlobalDir();
  6579. } else {
  6580. !UnicodeBidiDirection_1.isStrong(defaultDir) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Default direction must be a strong direction (LTR or RTL)') : invariant_1(false) : void 0;
  6581. }
  6582. this._defaultDir = defaultDir;
  6583. this.reset();
  6584. }
  6585. /**
  6586. * Reset the internal state
  6587. *
  6588. * Instead of creating a new instance, you can just reset() your instance
  6589. * everytime you start a new loop.
  6590. */
  6591. UnicodeBidiService.prototype.reset = function reset() {
  6592. this._lastDir = this._defaultDir;
  6593. };
  6594. /**
  6595. * Returns the direction of a block of text, and remembers it as the
  6596. * fall-back direction for the next paragraph.
  6597. *
  6598. * @param str A text block, e.g. paragraph, table cell, tag
  6599. * @return The resolved direction
  6600. */
  6601. UnicodeBidiService.prototype.getDirection = function getDirection(str) {
  6602. this._lastDir = UnicodeBidi_1.getDirection(str, this._lastDir);
  6603. return this._lastDir;
  6604. };
  6605. return UnicodeBidiService;
  6606. }();
  6607. var UnicodeBidiService_1 = UnicodeBidiService;
  6608. /**
  6609. * Copyright (c) 2013-present, Facebook, Inc.
  6610. *
  6611. * This source code is licensed under the MIT license found in the
  6612. * LICENSE file in the root directory of this source tree.
  6613. *
  6614. *
  6615. */
  6616. var nullthrows = function nullthrows(x) {
  6617. if (x != null) {
  6618. return x;
  6619. }
  6620. throw new Error("Got unexpected null or undefined");
  6621. };
  6622. var nullthrows_1 = nullthrows;
  6623. var OrderedMap$2 = immutable.OrderedMap;
  6624. var bidiService;
  6625. var EditorBidiService = {
  6626. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  6627. if (!bidiService) {
  6628. bidiService = new UnicodeBidiService_1();
  6629. } else {
  6630. bidiService.reset();
  6631. }
  6632. var blockMap = content.getBlockMap();
  6633. var nextBidi = blockMap.valueSeq().map(function (block) {
  6634. return nullthrows_1(bidiService).getDirection(block.getText());
  6635. });
  6636. var bidiMap = OrderedMap$2(blockMap.keySeq().zip(nextBidi));
  6637. if (prevBidiMap != null && immutable.is(prevBidiMap, bidiMap)) {
  6638. return prevBidiMap;
  6639. }
  6640. return bidiMap;
  6641. }
  6642. };
  6643. var EditorBidiService_1 = EditorBidiService;
  6644. var _extends$1 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6645. function _classCallCheck$7(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6646. var OrderedSet$4 = immutable.OrderedSet,
  6647. Record$7 = immutable.Record,
  6648. Stack = immutable.Stack;
  6649. var defaultRecord$5 = {
  6650. allowUndo: true,
  6651. currentContent: null,
  6652. decorator: null,
  6653. directionMap: null,
  6654. forceSelection: false,
  6655. inCompositionMode: false,
  6656. inlineStyleOverride: null,
  6657. lastChangeType: null,
  6658. nativelyRenderedContent: null,
  6659. redoStack: Stack(),
  6660. selection: null,
  6661. treeMap: null,
  6662. undoStack: Stack()
  6663. };
  6664. var EditorStateRecord = Record$7(defaultRecord$5);
  6665. var EditorState = function () {
  6666. EditorState.createEmpty = function createEmpty(decorator) {
  6667. return EditorState.createWithContent(ContentState_1.createFromText(''), decorator);
  6668. };
  6669. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  6670. var firstKey = contentState.getBlockMap().first().getKey();
  6671. return EditorState.create({
  6672. currentContent: contentState,
  6673. undoStack: Stack(),
  6674. redoStack: Stack(),
  6675. decorator: decorator || null,
  6676. selection: SelectionState_1.createEmpty(firstKey)
  6677. });
  6678. };
  6679. EditorState.create = function create(config) {
  6680. var currentContent = config.currentContent,
  6681. decorator = config.decorator;
  6682. var recordConfig = _extends$1({}, config, {
  6683. treeMap: generateNewTreeMap(currentContent, decorator),
  6684. directionMap: EditorBidiService_1.getDirectionMap(currentContent)
  6685. });
  6686. return new EditorState(new EditorStateRecord(recordConfig));
  6687. };
  6688. EditorState.set = function set(editorState, put) {
  6689. var map = editorState.getImmutable().withMutations(function (state) {
  6690. var existingDecorator = state.get('decorator');
  6691. var decorator = existingDecorator;
  6692. if (put.decorator === null) {
  6693. decorator = null;
  6694. } else if (put.decorator) {
  6695. decorator = put.decorator;
  6696. }
  6697. var newContent = put.currentContent || editorState.getCurrentContent();
  6698. if (decorator !== existingDecorator) {
  6699. var treeMap = state.get('treeMap');
  6700. var newTreeMap;
  6701. if (decorator && existingDecorator) {
  6702. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  6703. } else {
  6704. newTreeMap = generateNewTreeMap(newContent, decorator);
  6705. }
  6706. state.merge({
  6707. decorator: decorator,
  6708. treeMap: newTreeMap,
  6709. nativelyRenderedContent: null
  6710. });
  6711. return;
  6712. }
  6713. var existingContent = editorState.getCurrentContent();
  6714. if (newContent !== existingContent) {
  6715. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  6716. }
  6717. state.merge(put);
  6718. });
  6719. return new EditorState(map);
  6720. };
  6721. EditorState.prototype.toJS = function toJS() {
  6722. return this.getImmutable().toJS();
  6723. };
  6724. EditorState.prototype.getAllowUndo = function getAllowUndo() {
  6725. return this.getImmutable().get('allowUndo');
  6726. };
  6727. EditorState.prototype.getCurrentContent = function getCurrentContent() {
  6728. return this.getImmutable().get('currentContent');
  6729. };
  6730. EditorState.prototype.getUndoStack = function getUndoStack() {
  6731. return this.getImmutable().get('undoStack');
  6732. };
  6733. EditorState.prototype.getRedoStack = function getRedoStack() {
  6734. return this.getImmutable().get('redoStack');
  6735. };
  6736. EditorState.prototype.getSelection = function getSelection() {
  6737. return this.getImmutable().get('selection');
  6738. };
  6739. EditorState.prototype.getDecorator = function getDecorator() {
  6740. return this.getImmutable().get('decorator');
  6741. };
  6742. EditorState.prototype.isInCompositionMode = function isInCompositionMode() {
  6743. return this.getImmutable().get('inCompositionMode');
  6744. };
  6745. EditorState.prototype.mustForceSelection = function mustForceSelection() {
  6746. return this.getImmutable().get('forceSelection');
  6747. };
  6748. EditorState.prototype.getNativelyRenderedContent = function getNativelyRenderedContent() {
  6749. return this.getImmutable().get('nativelyRenderedContent');
  6750. };
  6751. EditorState.prototype.getLastChangeType = function getLastChangeType() {
  6752. return this.getImmutable().get('lastChangeType');
  6753. };
  6754. /**
  6755. * While editing, the user may apply inline style commands with a collapsed
  6756. * cursor, intending to type text that adopts the specified style. In this
  6757. * case, we track the specified style as an "override" that takes precedence
  6758. * over the inline style of the text adjacent to the cursor.
  6759. *
  6760. * If null, there is no override in place.
  6761. */
  6762. EditorState.prototype.getInlineStyleOverride = function getInlineStyleOverride() {
  6763. return this.getImmutable().get('inlineStyleOverride');
  6764. };
  6765. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  6766. return EditorState.set(editorState, { inlineStyleOverride: inlineStyleOverride });
  6767. };
  6768. /**
  6769. * Get the appropriate inline style for the editor state. If an
  6770. * override is in place, use it. Otherwise, the current style is
  6771. * based on the location of the selection state.
  6772. */
  6773. EditorState.prototype.getCurrentInlineStyle = function getCurrentInlineStyle() {
  6774. var override = this.getInlineStyleOverride();
  6775. if (override != null) {
  6776. return override;
  6777. }
  6778. var content = this.getCurrentContent();
  6779. var selection = this.getSelection();
  6780. if (selection.isCollapsed()) {
  6781. return getInlineStyleForCollapsedSelection(content, selection);
  6782. }
  6783. return getInlineStyleForNonCollapsedSelection(content, selection);
  6784. };
  6785. EditorState.prototype.getBlockTree = function getBlockTree(blockKey) {
  6786. return this.getImmutable().getIn(['treeMap', blockKey]);
  6787. };
  6788. EditorState.prototype.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  6789. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  6790. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  6791. };
  6792. EditorState.prototype.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  6793. var content = this.getCurrentContent();
  6794. var blockMap = content.getBlockMap();
  6795. var last = blockMap.last();
  6796. var end = last.getLength();
  6797. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  6798. };
  6799. EditorState.prototype.getDirectionMap = function getDirectionMap() {
  6800. return this.getImmutable().get('directionMap');
  6801. };
  6802. /**
  6803. * Incorporate native DOM selection changes into the EditorState. This
  6804. * method can be used when we simply want to accept whatever the DOM
  6805. * has given us to represent selection, and we do not need to re-render
  6806. * the editor.
  6807. *
  6808. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  6809. */
  6810. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  6811. return updateSelection(editorState, selection, false);
  6812. };
  6813. /**
  6814. * At times, we need to force the DOM selection to be where we
  6815. * need it to be. This can occur when the anchor or focus nodes
  6816. * are non-text nodes, for instance. In this case, we want to trigger
  6817. * a re-render of the editor, which in turn forces selection into
  6818. * the correct place in the DOM. The `forceSelection` method
  6819. * accomplishes this.
  6820. *
  6821. * This method should be used in cases where you need to explicitly
  6822. * move the DOM selection from one place to another without a change
  6823. * in ContentState.
  6824. */
  6825. EditorState.forceSelection = function forceSelection(editorState, selection) {
  6826. if (!selection.getHasFocus()) {
  6827. selection = selection.set('hasFocus', true);
  6828. }
  6829. return updateSelection(editorState, selection, true);
  6830. };
  6831. /**
  6832. * Move selection to the end of the editor without forcing focus.
  6833. */
  6834. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  6835. var content = editorState.getCurrentContent();
  6836. var lastBlock = content.getLastBlock();
  6837. var lastKey = lastBlock.getKey();
  6838. var length = lastBlock.getLength();
  6839. return EditorState.acceptSelection(editorState, new SelectionState_1({
  6840. anchorKey: lastKey,
  6841. anchorOffset: length,
  6842. focusKey: lastKey,
  6843. focusOffset: length,
  6844. isBackward: false
  6845. }));
  6846. };
  6847. /**
  6848. * Force focus to the end of the editor. This is useful in scenarios
  6849. * where we want to programmatically focus the input and it makes sense
  6850. * to allow the user to continue working seamlessly.
  6851. */
  6852. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  6853. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  6854. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  6855. };
  6856. /**
  6857. * Push the current ContentState onto the undo stack if it should be
  6858. * considered a boundary state, and set the provided ContentState as the
  6859. * new current content.
  6860. */
  6861. EditorState.push = function push(editorState, contentState, changeType) {
  6862. if (editorState.getCurrentContent() === contentState) {
  6863. return editorState;
  6864. }
  6865. var forceSelection = changeType !== 'insert-characters';
  6866. var directionMap = EditorBidiService_1.getDirectionMap(contentState, editorState.getDirectionMap());
  6867. if (!editorState.getAllowUndo()) {
  6868. return EditorState.set(editorState, {
  6869. currentContent: contentState,
  6870. directionMap: directionMap,
  6871. lastChangeType: changeType,
  6872. selection: contentState.getSelectionAfter(),
  6873. forceSelection: forceSelection,
  6874. inlineStyleOverride: null
  6875. });
  6876. }
  6877. var selection = editorState.getSelection();
  6878. var currentContent = editorState.getCurrentContent();
  6879. var undoStack = editorState.getUndoStack();
  6880. var newContent = contentState;
  6881. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  6882. undoStack = undoStack.push(currentContent);
  6883. newContent = newContent.set('selectionBefore', selection);
  6884. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  6885. // Preserve the previous selection.
  6886. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  6887. }
  6888. var inlineStyleOverride = editorState.getInlineStyleOverride();
  6889. // Don't discard inline style overrides for the following change types:
  6890. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  6891. if (overrideChangeTypes.indexOf(changeType) === -1) {
  6892. inlineStyleOverride = null;
  6893. }
  6894. var editorStateChanges = {
  6895. currentContent: newContent,
  6896. directionMap: directionMap,
  6897. undoStack: undoStack,
  6898. redoStack: Stack(),
  6899. lastChangeType: changeType,
  6900. selection: contentState.getSelectionAfter(),
  6901. forceSelection: forceSelection,
  6902. inlineStyleOverride: inlineStyleOverride
  6903. };
  6904. return EditorState.set(editorState, editorStateChanges);
  6905. };
  6906. /**
  6907. * Make the top ContentState in the undo stack the new current content and
  6908. * push the current content onto the redo stack.
  6909. */
  6910. EditorState.undo = function undo(editorState) {
  6911. if (!editorState.getAllowUndo()) {
  6912. return editorState;
  6913. }
  6914. var undoStack = editorState.getUndoStack();
  6915. var newCurrentContent = undoStack.peek();
  6916. if (!newCurrentContent) {
  6917. return editorState;
  6918. }
  6919. var currentContent = editorState.getCurrentContent();
  6920. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6921. return EditorState.set(editorState, {
  6922. currentContent: newCurrentContent,
  6923. directionMap: directionMap,
  6924. undoStack: undoStack.shift(),
  6925. redoStack: editorState.getRedoStack().push(currentContent),
  6926. forceSelection: true,
  6927. inlineStyleOverride: null,
  6928. lastChangeType: 'undo',
  6929. nativelyRenderedContent: null,
  6930. selection: currentContent.getSelectionBefore()
  6931. });
  6932. };
  6933. /**
  6934. * Make the top ContentState in the redo stack the new current content and
  6935. * push the current content onto the undo stack.
  6936. */
  6937. EditorState.redo = function redo(editorState) {
  6938. if (!editorState.getAllowUndo()) {
  6939. return editorState;
  6940. }
  6941. var redoStack = editorState.getRedoStack();
  6942. var newCurrentContent = redoStack.peek();
  6943. if (!newCurrentContent) {
  6944. return editorState;
  6945. }
  6946. var currentContent = editorState.getCurrentContent();
  6947. var directionMap = EditorBidiService_1.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  6948. return EditorState.set(editorState, {
  6949. currentContent: newCurrentContent,
  6950. directionMap: directionMap,
  6951. undoStack: editorState.getUndoStack().push(currentContent),
  6952. redoStack: redoStack.shift(),
  6953. forceSelection: true,
  6954. inlineStyleOverride: null,
  6955. lastChangeType: 'redo',
  6956. nativelyRenderedContent: null,
  6957. selection: newCurrentContent.getSelectionAfter()
  6958. });
  6959. };
  6960. /**
  6961. * Not for public consumption.
  6962. */
  6963. function EditorState(immutable) {
  6964. _classCallCheck$7(this, EditorState);
  6965. this._immutable = immutable;
  6966. }
  6967. /**
  6968. * Not for public consumption.
  6969. */
  6970. EditorState.prototype.getImmutable = function getImmutable() {
  6971. return this._immutable;
  6972. };
  6973. return EditorState;
  6974. }();
  6975. /**
  6976. * Set the supplied SelectionState as the new current selection, and set
  6977. * the `force` flag to trigger manual selection placement by the view.
  6978. */
  6979. function updateSelection(editorState, selection, forceSelection) {
  6980. return EditorState.set(editorState, {
  6981. selection: selection,
  6982. forceSelection: forceSelection,
  6983. nativelyRenderedContent: null,
  6984. inlineStyleOverride: null
  6985. });
  6986. }
  6987. /**
  6988. * Regenerate the entire tree map for a given ContentState and decorator.
  6989. * Returns an OrderedMap that maps all available ContentBlock objects.
  6990. */
  6991. function generateNewTreeMap(contentState, decorator) {
  6992. return contentState.getBlockMap().map(function (block) {
  6993. return BlockTree_1.generate(contentState, block, decorator);
  6994. }).toOrderedMap();
  6995. }
  6996. /**
  6997. * Regenerate tree map objects for all ContentBlocks that have changed
  6998. * between the current editorState and newContent. Returns an OrderedMap
  6999. * with only changed regenerated tree map objects.
  7000. */
  7001. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  7002. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  7003. var prevBlockMap = contentState.getBlockMap();
  7004. var prevTreeMap = editorState.getImmutable().get('treeMap');
  7005. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  7006. return block !== prevBlockMap.get(key);
  7007. }).map(function (block) {
  7008. return BlockTree_1.generate(contentState, block, decorator);
  7009. }));
  7010. }
  7011. /**
  7012. * Generate tree map objects for a new decorator object, preserving any
  7013. * decorations that are unchanged from the previous decorator.
  7014. *
  7015. * Note that in order for this to perform optimally, decoration Lists for
  7016. * decorators should be preserved when possible to allow for direct immutable
  7017. * List comparison.
  7018. */
  7019. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  7020. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  7021. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  7022. }).map(function (block) {
  7023. return BlockTree_1.generate(content, block, decorator);
  7024. }));
  7025. }
  7026. /**
  7027. * Return whether a change should be considered a boundary state, given
  7028. * the previous change type. Allows us to discard potential boundary states
  7029. * during standard typing or deletion behavior.
  7030. */
  7031. function mustBecomeBoundary(editorState, changeType) {
  7032. var lastChangeType = editorState.getLastChangeType();
  7033. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  7034. }
  7035. function getInlineStyleForCollapsedSelection(content, selection) {
  7036. var startKey = selection.getStartKey();
  7037. var startOffset = selection.getStartOffset();
  7038. var startBlock = content.getBlockForKey(startKey);
  7039. // If the cursor is not at the start of the block, look backward to
  7040. // preserve the style of the preceding character.
  7041. if (startOffset > 0) {
  7042. return startBlock.getInlineStyleAt(startOffset - 1);
  7043. }
  7044. // The caret is at position zero in this block. If the block has any
  7045. // text at all, use the style of the first character.
  7046. if (startBlock.getLength()) {
  7047. return startBlock.getInlineStyleAt(0);
  7048. }
  7049. // Otherwise, look upward in the document to find the closest character.
  7050. return lookUpwardForInlineStyle(content, startKey);
  7051. }
  7052. function getInlineStyleForNonCollapsedSelection(content, selection) {
  7053. var startKey = selection.getStartKey();
  7054. var startOffset = selection.getStartOffset();
  7055. var startBlock = content.getBlockForKey(startKey);
  7056. // If there is a character just inside the selection, use its style.
  7057. if (startOffset < startBlock.getLength()) {
  7058. return startBlock.getInlineStyleAt(startOffset);
  7059. }
  7060. // Check if the selection at the end of a non-empty block. Use the last
  7061. // style in the block.
  7062. if (startOffset > 0) {
  7063. return startBlock.getInlineStyleAt(startOffset - 1);
  7064. }
  7065. // Otherwise, look upward in the document to find the closest character.
  7066. return lookUpwardForInlineStyle(content, startKey);
  7067. }
  7068. function lookUpwardForInlineStyle(content, fromKey) {
  7069. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  7070. return k === fromKey;
  7071. }).skip(1).skipUntil(function (block, _) {
  7072. return block.getLength();
  7073. }).first();
  7074. if (lastNonEmpty) return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  7075. return OrderedSet$4();
  7076. }
  7077. var EditorState_1 = EditorState;
  7078. var OrderedMap$3 = immutable.OrderedMap,
  7079. List$7 = immutable.List;
  7080. var transformBlock$2 = function transformBlock(key, blockMap, func) {
  7081. if (!key) {
  7082. return;
  7083. }
  7084. var block = blockMap.get(key);
  7085. if (!block) {
  7086. return;
  7087. }
  7088. blockMap.set(key, func(block));
  7089. };
  7090. var updateBlockMapLinks$3 = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7091. if (!isExperimentalTreeBlock) {
  7092. return blockMap;
  7093. }
  7094. // possible values of 'insertionMode' are: 'after', 'before'
  7095. var isInsertedAfterTarget = insertionMode === 'after';
  7096. var originalBlockKey = originalBlockToBeMoved.getKey();
  7097. var originalTargetKey = originalTargetBlock.getKey();
  7098. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7099. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7100. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7101. var newParentKey = originalTargetBlock.getParentKey();
  7102. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7103. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7104. return blockMap.withMutations(function (blocks) {
  7105. // update old parent
  7106. transformBlock$2(originalParentKey, blocks, function (block) {
  7107. var parentChildrenList = block.getChildKeys();
  7108. return block.merge({
  7109. children: parentChildrenList['delete'](parentChildrenList.indexOf(originalBlockKey))
  7110. });
  7111. });
  7112. // update old prev
  7113. transformBlock$2(originalPrevSiblingKey, blocks, function (block) {
  7114. return block.merge({
  7115. nextSibling: originalNextSiblingKey
  7116. });
  7117. });
  7118. // update old next
  7119. transformBlock$2(originalNextSiblingKey, blocks, function (block) {
  7120. return block.merge({
  7121. prevSibling: originalPrevSiblingKey
  7122. });
  7123. });
  7124. // update new next
  7125. transformBlock$2(newNextSiblingKey, blocks, function (block) {
  7126. return block.merge({
  7127. prevSibling: originalBlockKey
  7128. });
  7129. });
  7130. // update new prev
  7131. transformBlock$2(newPrevSiblingKey, blocks, function (block) {
  7132. return block.merge({
  7133. nextSibling: originalBlockKey
  7134. });
  7135. });
  7136. // update new parent
  7137. transformBlock$2(newParentKey, blocks, function (block) {
  7138. var newParentChildrenList = block.getChildKeys();
  7139. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7140. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7141. var newChildrenArray = newParentChildrenList.toArray();
  7142. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7143. return block.merge({
  7144. children: List$7(newChildrenArray)
  7145. });
  7146. });
  7147. // update block
  7148. transformBlock$2(originalBlockKey, blocks, function (block) {
  7149. return block.merge({
  7150. nextSibling: newNextSiblingKey,
  7151. prevSibling: newPrevSiblingKey,
  7152. parent: newParentKey
  7153. });
  7154. });
  7155. });
  7156. };
  7157. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7158. !(insertionMode !== 'replace') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Replacing blocks is not supported.') : invariant_1(false) : void 0;
  7159. var targetKey = targetBlock.getKey();
  7160. var blockKey = blockToBeMoved.getKey();
  7161. !(blockKey !== targetKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7162. var blockMap = contentState.getBlockMap();
  7163. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode_1;
  7164. var blocksToBeMoved = [blockToBeMoved];
  7165. var blockMapWithoutBlocksToBeMoved = blockMap['delete'](blockKey);
  7166. if (isExperimentalTreeBlock) {
  7167. blocksToBeMoved = [];
  7168. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7169. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7170. var nextDelimiterBlockKey = getNextDelimiterBlockKey_1(blockToBeMoved, blocks);
  7171. blocks.toSeq().skipUntil(function (block) {
  7172. return block.getKey() === blockKey;
  7173. }).takeWhile(function (block) {
  7174. var key = block.getKey();
  7175. var isBlockToBeMoved = key === blockKey;
  7176. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7177. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7178. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7179. }).forEach(function (block) {
  7180. blocksToBeMoved.push(block);
  7181. blocks['delete'](block.getKey());
  7182. });
  7183. });
  7184. }
  7185. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7186. return v === targetBlock;
  7187. });
  7188. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7189. return v === targetBlock;
  7190. }).skip(1);
  7191. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7192. return [block.getKey(), block];
  7193. });
  7194. var newBlocks = OrderedMap$3();
  7195. if (insertionMode === 'before') {
  7196. var blockBefore = contentState.getBlockBefore(targetKey);
  7197. !(!blockBefore || blockBefore.getKey() !== blockToBeMoved.getKey()) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7198. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7199. } else if (insertionMode === 'after') {
  7200. var blockAfter = contentState.getBlockAfter(targetKey);
  7201. !(!blockAfter || blockAfter.getKey() !== blockKey) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Block cannot be moved next to itself.') : invariant_1(false) : void 0;
  7202. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7203. }
  7204. return contentState.merge({
  7205. blockMap: updateBlockMapLinks$3(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7206. selectionBefore: contentState.getSelectionAfter(),
  7207. selectionAfter: contentState.getSelectionAfter().merge({
  7208. anchorKey: blockKey,
  7209. focusKey: blockKey
  7210. })
  7211. });
  7212. };
  7213. var moveBlockInContentState_1 = moveBlockInContentState;
  7214. var ContentBlockRecord$1 = ContentBlock_1;
  7215. var List$8 = immutable.List,
  7216. Repeat$5 = immutable.Repeat;
  7217. var AtomicBlockUtils = {
  7218. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  7219. var contentState = editorState.getCurrentContent();
  7220. var selectionState = editorState.getSelection();
  7221. var afterRemoval = DraftModifier_1.removeRange(contentState, selectionState, 'backward');
  7222. var targetSelection = afterRemoval.getSelectionAfter();
  7223. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, targetSelection);
  7224. var insertionTarget = afterSplit.getSelectionAfter();
  7225. var asAtomicBlock = DraftModifier_1.setBlockType(afterSplit, insertionTarget, 'atomic');
  7226. var charData = CharacterMetadata_1.create({ entity: entityKey });
  7227. var atomicBlockConfig = {
  7228. key: generateRandomKey_1(),
  7229. type: 'atomic',
  7230. text: character,
  7231. characterList: List$8(Repeat$5(charData, character.length))
  7232. };
  7233. var atomicDividerBlockConfig = {
  7234. key: generateRandomKey_1(),
  7235. type: 'unstyled'
  7236. };
  7237. var fragmentArray = [new ContentBlockRecord$1(atomicBlockConfig), new ContentBlockRecord$1(atomicDividerBlockConfig)];
  7238. var fragment = BlockMapBuilder_1.createFromArray(fragmentArray);
  7239. var withAtomicBlock = DraftModifier_1.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  7240. var newContent = withAtomicBlock.merge({
  7241. selectionBefore: selectionState,
  7242. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7243. });
  7244. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  7245. },
  7246. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  7247. var contentState = editorState.getCurrentContent();
  7248. var selectionState = editorState.getSelection();
  7249. var withMovedAtomicBlock = void 0;
  7250. if (insertionMode === 'before' || insertionMode === 'after') {
  7251. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  7252. withMovedAtomicBlock = moveBlockInContentState_1(contentState, atomicBlock, targetBlock, insertionMode);
  7253. } else {
  7254. var afterRemoval = DraftModifier_1.removeRange(contentState, targetRange, 'backward');
  7255. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  7256. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  7257. if (selectionAfterRemoval.getStartOffset() === 0) {
  7258. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'before');
  7259. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  7260. withMovedAtomicBlock = moveBlockInContentState_1(afterRemoval, atomicBlock, _targetBlock, 'after');
  7261. } else {
  7262. var afterSplit = DraftModifier_1.splitBlock(afterRemoval, selectionAfterRemoval);
  7263. var selectionAfterSplit = afterSplit.getSelectionAfter();
  7264. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  7265. withMovedAtomicBlock = moveBlockInContentState_1(afterSplit, atomicBlock, _targetBlock2, 'before');
  7266. }
  7267. }
  7268. var newContent = withMovedAtomicBlock.merge({
  7269. selectionBefore: selectionState,
  7270. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  7271. });
  7272. return EditorState_1.push(editorState, newContent, 'move-block');
  7273. }
  7274. };
  7275. var AtomicBlockUtils_1 = AtomicBlockUtils;
  7276. function _classCallCheck$8(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7277. var List$9 = immutable.List;
  7278. var DELIMITER = '.';
  7279. /**
  7280. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7281. * instances to identify sections of a ContentBlock that should be rendered
  7282. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7283. * be intended to stand out visually, be rendered as anchors, etc.
  7284. *
  7285. * The list of decorators supplied to the constructor will be used in the
  7286. * order they are provided. This allows the caller to specify a priority for
  7287. * string matching, in case of match collisions among decorators.
  7288. *
  7289. * For instance, I may have a link with a `#` in its text. Though this section
  7290. * of text may match our hashtag decorator, it should not be treated as a
  7291. * hashtag. I should therefore list my link DraftDecorator
  7292. * before my hashtag DraftDecorator when constructing this composite
  7293. * decorator instance.
  7294. *
  7295. * Thus, when a collision like this is encountered, the earlier match is
  7296. * preserved and the new match is discarded.
  7297. */
  7298. var CompositeDraftDecorator = function () {
  7299. function CompositeDraftDecorator(decorators) {
  7300. _classCallCheck$8(this, CompositeDraftDecorator);
  7301. // Copy the decorator array, since we use this array order to determine
  7302. // precedence of decoration matching. If the array is mutated externally,
  7303. // we don't want to be affected here.
  7304. this._decorators = decorators.slice();
  7305. }
  7306. CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) {
  7307. var decorations = Array(block.getText().length).fill(null);
  7308. this._decorators.forEach(function ( /*object*/decorator, /*number*/ii) {
  7309. var counter = 0;
  7310. var strategy = decorator.strategy;
  7311. var callback = function callback( /*number*/start, /*number*/end) {
  7312. // Find out if any of our matching range is already occupied
  7313. // by another decorator. If so, discard the match. Otherwise, store
  7314. // the component key for rendering.
  7315. if (canOccupySlice(decorations, start, end)) {
  7316. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7317. counter++;
  7318. }
  7319. };
  7320. strategy(block, callback, contentState);
  7321. });
  7322. return List$9(decorations);
  7323. };
  7324. CompositeDraftDecorator.prototype.getComponentForKey = function getComponentForKey(key) {
  7325. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7326. return this._decorators[componentKey].component;
  7327. };
  7328. CompositeDraftDecorator.prototype.getPropsForKey = function getPropsForKey(key) {
  7329. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7330. return this._decorators[componentKey].props;
  7331. };
  7332. return CompositeDraftDecorator;
  7333. }();
  7334. /**
  7335. * Determine whether we can occupy the specified slice of the decorations
  7336. * array.
  7337. */
  7338. function canOccupySlice(decorations, start, end) {
  7339. for (var ii = start; ii < end; ii++) {
  7340. if (decorations[ii] != null) {
  7341. return false;
  7342. }
  7343. }
  7344. return true;
  7345. }
  7346. /**
  7347. * Splice the specified component into our decoration array at the desired
  7348. * range.
  7349. */
  7350. function occupySlice(targetArr, start, end, componentKey) {
  7351. for (var ii = start; ii < end; ii++) {
  7352. targetArr[ii] = componentKey;
  7353. }
  7354. }
  7355. var CompositeDraftDecorator_1 = CompositeDraftDecorator;
  7356. /**
  7357. * Copyright (c) 2013-present, Facebook, Inc.
  7358. *
  7359. * This source code is licensed under the MIT license found in the
  7360. * LICENSE file in the root directory of this source tree.
  7361. *
  7362. */
  7363. /**
  7364. * This function is used to mark string literals representing CSS class names
  7365. * so that they can be transformed statically. This allows for modularization
  7366. * and minification of CSS class names.
  7367. *
  7368. * In static_upstream, this function is actually implemented, but it should
  7369. * eventually be replaced with something more descriptive, and the transform
  7370. * that is used in the main stack should be ported for use elsewhere.
  7371. *
  7372. * @param string|object className to modularize, or an object of key/values.
  7373. * In the object case, the values are conditions that
  7374. * determine if the className keys should be included.
  7375. * @param [string ...] Variable list of classNames in the string case.
  7376. * @return string Renderable space-separated CSS className.
  7377. */
  7378. function cx(classNames) {
  7379. if (typeof classNames == 'object') {
  7380. return Object.keys(classNames).filter(function (className) {
  7381. return classNames[className];
  7382. }).map(replace).join(' ');
  7383. }
  7384. return Array.prototype.map.call(arguments, replace).join(' ');
  7385. }
  7386. function replace(str) {
  7387. return str.replace(/\//g, '-');
  7388. }
  7389. var cx_1 = cx;
  7390. var Map$8 = immutable.Map;
  7391. var UL_WRAP = _reactDom_commonjsExternal.React.createElement('ul', { className: cx_1('public/DraftStyleDefault/ul') });
  7392. var OL_WRAP = _reactDom_commonjsExternal.React.createElement('ol', { className: cx_1('public/DraftStyleDefault/ol') });
  7393. var PRE_WRAP = _reactDom_commonjsExternal.React.createElement('pre', { className: cx_1('public/DraftStyleDefault/pre') });
  7394. var DefaultDraftBlockRenderMap = Map$8({
  7395. 'header-one': {
  7396. element: 'h1'
  7397. },
  7398. 'header-two': {
  7399. element: 'h2'
  7400. },
  7401. 'header-three': {
  7402. element: 'h3'
  7403. },
  7404. 'header-four': {
  7405. element: 'h4'
  7406. },
  7407. 'header-five': {
  7408. element: 'h5'
  7409. },
  7410. 'header-six': {
  7411. element: 'h6'
  7412. },
  7413. 'unordered-list-item': {
  7414. element: 'li',
  7415. wrapper: UL_WRAP
  7416. },
  7417. 'ordered-list-item': {
  7418. element: 'li',
  7419. wrapper: OL_WRAP
  7420. },
  7421. blockquote: {
  7422. element: 'blockquote'
  7423. },
  7424. atomic: {
  7425. element: 'figure'
  7426. },
  7427. 'code-block': {
  7428. element: 'pre',
  7429. wrapper: PRE_WRAP
  7430. },
  7431. unstyled: {
  7432. element: 'div',
  7433. aliasedElements: ['p']
  7434. }
  7435. });
  7436. var DefaultDraftBlockRenderMap_1 = DefaultDraftBlockRenderMap;
  7437. /**
  7438. * Copyright (c) 2013-present, Facebook, Inc.
  7439. * All rights reserved.
  7440. *
  7441. * This source code is licensed under the BSD-style license found in the
  7442. * LICENSE file in the root directory of this source tree. An additional grant
  7443. * of patent rights can be found in the PATENTS file in the same directory.
  7444. *
  7445. * @providesModule DefaultDraftInlineStyle
  7446. * @format
  7447. *
  7448. */
  7449. var DefaultDraftInlineStyle = {
  7450. BOLD: {
  7451. fontWeight: 'bold'
  7452. },
  7453. CODE: {
  7454. fontFamily: 'monospace',
  7455. wordWrap: 'break-word'
  7456. },
  7457. ITALIC: {
  7458. fontStyle: 'italic'
  7459. },
  7460. STRIKETHROUGH: {
  7461. textDecoration: 'line-through'
  7462. },
  7463. UNDERLINE: {
  7464. textDecoration: 'underline'
  7465. }
  7466. };
  7467. /**
  7468. * Copyright (c) 2013-present, Facebook, Inc.
  7469. *
  7470. * This source code is licensed under the MIT license found in the
  7471. * LICENSE file in the root directory of this source tree.
  7472. *
  7473. */
  7474. var Keys = {
  7475. BACKSPACE: 8,
  7476. TAB: 9,
  7477. RETURN: 13,
  7478. ALT: 18,
  7479. ESC: 27,
  7480. SPACE: 32,
  7481. PAGE_UP: 33,
  7482. PAGE_DOWN: 34,
  7483. END: 35,
  7484. HOME: 36,
  7485. LEFT: 37,
  7486. UP: 38,
  7487. RIGHT: 39,
  7488. DOWN: 40,
  7489. DELETE: 46,
  7490. COMMA: 188,
  7491. PERIOD: 190,
  7492. A: 65,
  7493. Z: 90,
  7494. ZERO: 48,
  7495. NUMPAD_0: 96,
  7496. NUMPAD_9: 105
  7497. };
  7498. /**
  7499. * Copyright (c) 2013-present, Facebook, Inc.
  7500. * All rights reserved.
  7501. *
  7502. * This source code is licensed under the BSD-style license found in the
  7503. * LICENSE file in the root directory of this source tree. An additional grant
  7504. * of patent rights can be found in the PATENTS file in the same directory.
  7505. *
  7506. * @providesModule getEntityKeyForSelection
  7507. * @format
  7508. *
  7509. */
  7510. /**
  7511. * Return the entity key that should be used when inserting text for the
  7512. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  7513. * and `SEGMENTED` entities should not be used for insertion behavior.
  7514. */
  7515. function getEntityKeyForSelection(contentState, targetSelection) {
  7516. var entityKey;
  7517. if (targetSelection.isCollapsed()) {
  7518. var key = targetSelection.getAnchorKey();
  7519. var offset = targetSelection.getAnchorOffset();
  7520. if (offset > 0) {
  7521. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  7522. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  7523. return null;
  7524. }
  7525. return filterKey(contentState.getEntityMap(), entityKey);
  7526. }
  7527. return null;
  7528. }
  7529. var startKey = targetSelection.getStartKey();
  7530. var startOffset = targetSelection.getStartOffset();
  7531. var startBlock = contentState.getBlockForKey(startKey);
  7532. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  7533. return filterKey(contentState.getEntityMap(), entityKey);
  7534. }
  7535. /**
  7536. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  7537. * return it. If not, return null.
  7538. */
  7539. function filterKey(entityMap, entityKey) {
  7540. if (entityKey) {
  7541. var entity = entityMap.__get(entityKey);
  7542. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  7543. }
  7544. return null;
  7545. }
  7546. var getEntityKeyForSelection_1 = getEntityKeyForSelection;
  7547. /**
  7548. * Copyright (c) 2013-present, Facebook, Inc.
  7549. * All rights reserved.
  7550. *
  7551. * This source code is licensed under the BSD-style license found in the
  7552. * LICENSE file in the root directory of this source tree. An additional grant
  7553. * of patent rights can be found in the PATENTS file in the same directory.
  7554. *
  7555. * @providesModule isEventHandled
  7556. * @format
  7557. *
  7558. */
  7559. /**
  7560. * Utility method for determining whether or not the value returned
  7561. * from a handler indicates that it was handled.
  7562. */
  7563. function isEventHandled(value) {
  7564. return value === 'handled' || value === true;
  7565. }
  7566. var isEventHandled_1 = isEventHandled;
  7567. /**
  7568. * Copyright (c) 2013-present, Facebook, Inc.
  7569. * All rights reserved.
  7570. *
  7571. * This source code is licensed under the BSD-style license found in the
  7572. * LICENSE file in the root directory of this source tree. An additional grant
  7573. * of patent rights can be found in the PATENTS file in the same directory.
  7574. *
  7575. * @providesModule isSelectionAtLeafStart
  7576. * @format
  7577. *
  7578. */
  7579. function isSelectionAtLeafStart(editorState) {
  7580. var selection = editorState.getSelection();
  7581. var anchorKey = selection.getAnchorKey();
  7582. var blockTree = editorState.getBlockTree(anchorKey);
  7583. var offset = selection.getStartOffset();
  7584. var isAtStart = false;
  7585. blockTree.some(function (leafSet) {
  7586. if (offset === leafSet.get('start')) {
  7587. isAtStart = true;
  7588. return true;
  7589. }
  7590. if (offset < leafSet.get('end')) {
  7591. return leafSet.get('leaves').some(function (leaf) {
  7592. var leafStart = leaf.get('start');
  7593. if (offset === leafStart) {
  7594. isAtStart = true;
  7595. return true;
  7596. }
  7597. return false;
  7598. });
  7599. }
  7600. return false;
  7601. });
  7602. return isAtStart;
  7603. }
  7604. var isSelectionAtLeafStart_1 = isSelectionAtLeafStart;
  7605. /**
  7606. * Millisecond delay to allow `compositionstart` to fire again upon
  7607. * `compositionend`.
  7608. *
  7609. * This is used for Korean input to ensure that typing can continue without
  7610. * the editor trying to render too quickly. More specifically, Safari 7.1+
  7611. * triggers `compositionstart` a little slower than Chrome/FF, which
  7612. * leads to composed characters being resolved and re-render occurring
  7613. * sooner than we want.
  7614. */
  7615. var RESOLVE_DELAY = 20;
  7616. /**
  7617. * A handful of variables used to track the current composition and its
  7618. * resolution status. These exist at the module level because it is not
  7619. * possible to have compositions occurring in multiple editors simultaneously,
  7620. * and it simplifies state management with respect to the DraftEditor component.
  7621. */
  7622. var resolved = false;
  7623. var stillComposing = false;
  7624. var textInputData = '';
  7625. var DraftEditorCompositionHandler = {
  7626. onBeforeInput: function onBeforeInput(editor, e) {
  7627. textInputData = (textInputData || '') + e.data;
  7628. },
  7629. /**
  7630. * A `compositionstart` event has fired while we're still in composition
  7631. * mode. Continue the current composition session to prevent a re-render.
  7632. */
  7633. onCompositionStart: function onCompositionStart(editor) {
  7634. stillComposing = true;
  7635. },
  7636. /**
  7637. * Attempt to end the current composition session.
  7638. *
  7639. * Defer handling because browser will still insert the chars into active
  7640. * element after `compositionend`. If a `compositionstart` event fires
  7641. * before `resolveComposition` executes, our composition session will
  7642. * continue.
  7643. *
  7644. * The `resolved` flag is useful because certain IME interfaces fire the
  7645. * `compositionend` event multiple times, thus queueing up multiple attempts
  7646. * at handling the composition. Since handling the same composition event
  7647. * twice could break the DOM, we only use the first event. Example: Arabic
  7648. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  7649. */
  7650. onCompositionEnd: function onCompositionEnd(editor) {
  7651. resolved = false;
  7652. stillComposing = false;
  7653. setTimeout(function () {
  7654. if (!resolved) {
  7655. DraftEditorCompositionHandler.resolveComposition(editor);
  7656. }
  7657. }, RESOLVE_DELAY);
  7658. },
  7659. /**
  7660. * In Safari, keydown events may fire when committing compositions. If
  7661. * the arrow keys are used to commit, prevent default so that the cursor
  7662. * doesn't move, otherwise it will jump back noticeably on re-render.
  7663. */
  7664. onKeyDown: function onKeyDown(editor, e) {
  7665. if (!stillComposing) {
  7666. // If a keydown event is received after compositionend but before the
  7667. // 20ms timer expires (ex: type option-E then backspace, or type A then
  7668. // backspace in 2-Set Korean), we should immediately resolve the
  7669. // composition and reinterpret the key press in edit mode.
  7670. DraftEditorCompositionHandler.resolveComposition(editor);
  7671. editor._onKeyDown(e);
  7672. return;
  7673. }
  7674. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  7675. e.preventDefault();
  7676. }
  7677. },
  7678. /**
  7679. * Keypress events may fire when committing compositions. In Firefox,
  7680. * pressing RETURN commits the composition and inserts extra newline
  7681. * characters that we do not want. `preventDefault` allows the composition
  7682. * to be committed while preventing the extra characters.
  7683. */
  7684. onKeyPress: function onKeyPress(editor, e) {
  7685. if (e.which === Keys.RETURN) {
  7686. e.preventDefault();
  7687. }
  7688. },
  7689. /**
  7690. * Attempt to insert composed characters into the document.
  7691. *
  7692. * If we are still in a composition session, do nothing. Otherwise, insert
  7693. * the characters into the document and terminate the composition session.
  7694. *
  7695. * If no characters were composed -- for instance, the user
  7696. * deleted all composed characters and committed nothing new --
  7697. * force a re-render. We also re-render when the composition occurs
  7698. * at the beginning of a leaf, to ensure that if the browser has
  7699. * created a new text node for the composition, we will discard it.
  7700. *
  7701. * Resetting innerHTML will move focus to the beginning of the editor,
  7702. * so we update to force it back to the correct place.
  7703. */
  7704. resolveComposition: function resolveComposition(editor) {
  7705. if (stillComposing) {
  7706. return;
  7707. }
  7708. resolved = true;
  7709. var composedChars = textInputData;
  7710. textInputData = '';
  7711. var editorState = EditorState_1.set(editor._latestEditorState, {
  7712. inCompositionMode: false
  7713. });
  7714. var currentStyle = editorState.getCurrentInlineStyle();
  7715. var entityKey = getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection());
  7716. var mustReset = !composedChars || isSelectionAtLeafStart_1(editorState) || currentStyle.size > 0 || entityKey !== null;
  7717. if (mustReset) {
  7718. editor.restoreEditorDOM();
  7719. }
  7720. editor.exitCurrentMode();
  7721. if (composedChars) {
  7722. // If characters have been composed, re-rendering with the update
  7723. // is sufficient to reset the editor.
  7724. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), composedChars, currentStyle, entityKey);
  7725. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  7726. return;
  7727. }
  7728. if (mustReset) {
  7729. editor.update(EditorState_1.set(editorState, {
  7730. nativelyRenderedContent: null,
  7731. forceSelection: true
  7732. }));
  7733. }
  7734. }
  7735. };
  7736. var DraftEditorCompositionHandler_1 = DraftEditorCompositionHandler;
  7737. var uaParser = _commonjsHelpers.createCommonjsModule(function (module, exports) {
  7738. /*!
  7739. * UAParser.js v0.7.21
  7740. * Lightweight JavaScript-based User-Agent string parser
  7741. * https://github.com/faisalman/ua-parser-js
  7742. *
  7743. * Copyright © 2012-2019 Faisal Salman <f@faisalman.com>
  7744. * Licensed under MIT License
  7745. */
  7746. (function (window, undefined$1) {
  7747. //////////////
  7748. // Constants
  7749. /////////////
  7750. var LIBVERSION = '0.7.21',
  7751. EMPTY = '',
  7752. UNKNOWN = '?',
  7753. FUNC_TYPE = 'function',
  7754. OBJ_TYPE = 'object',
  7755. STR_TYPE = 'string',
  7756. MAJOR = 'major', // deprecated
  7757. MODEL = 'model',
  7758. NAME = 'name',
  7759. TYPE = 'type',
  7760. VENDOR = 'vendor',
  7761. VERSION = 'version',
  7762. ARCHITECTURE= 'architecture',
  7763. CONSOLE = 'console',
  7764. MOBILE = 'mobile',
  7765. TABLET = 'tablet',
  7766. SMARTTV = 'smarttv',
  7767. WEARABLE = 'wearable',
  7768. EMBEDDED = 'embedded';
  7769. ///////////
  7770. // Helper
  7771. //////////
  7772. var util = {
  7773. extend : function (regexes, extensions) {
  7774. var mergedRegexes = {};
  7775. for (var i in regexes) {
  7776. if (extensions[i] && extensions[i].length % 2 === 0) {
  7777. mergedRegexes[i] = extensions[i].concat(regexes[i]);
  7778. } else {
  7779. mergedRegexes[i] = regexes[i];
  7780. }
  7781. }
  7782. return mergedRegexes;
  7783. },
  7784. has : function (str1, str2) {
  7785. if (typeof str1 === "string") {
  7786. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  7787. } else {
  7788. return false;
  7789. }
  7790. },
  7791. lowerize : function (str) {
  7792. return str.toLowerCase();
  7793. },
  7794. major : function (version) {
  7795. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined$1;
  7796. },
  7797. trim : function (str) {
  7798. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  7799. }
  7800. };
  7801. ///////////////
  7802. // Map helper
  7803. //////////////
  7804. var mapper = {
  7805. rgx : function (ua, arrays) {
  7806. var i = 0, j, k, p, q, matches, match;
  7807. // loop through all regexes maps
  7808. while (i < arrays.length && !matches) {
  7809. var regex = arrays[i], // even sequence (0,2,4,..)
  7810. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  7811. j = k = 0;
  7812. // try matching uastring with regexes
  7813. while (j < regex.length && !matches) {
  7814. matches = regex[j++].exec(ua);
  7815. if (!!matches) {
  7816. for (p = 0; p < props.length; p++) {
  7817. match = matches[++k];
  7818. q = props[p];
  7819. // check if given property is actually array
  7820. if (typeof q === OBJ_TYPE && q.length > 0) {
  7821. if (q.length == 2) {
  7822. if (typeof q[1] == FUNC_TYPE) {
  7823. // assign modified match
  7824. this[q[0]] = q[1].call(this, match);
  7825. } else {
  7826. // assign given value, ignore regex match
  7827. this[q[0]] = q[1];
  7828. }
  7829. } else if (q.length == 3) {
  7830. // check whether function or regex
  7831. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  7832. // call function (usually string mapper)
  7833. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined$1;
  7834. } else {
  7835. // sanitize match using given regex
  7836. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined$1;
  7837. }
  7838. } else if (q.length == 4) {
  7839. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined$1;
  7840. }
  7841. } else {
  7842. this[q] = match ? match : undefined$1;
  7843. }
  7844. }
  7845. }
  7846. }
  7847. i += 2;
  7848. }
  7849. },
  7850. str : function (str, map) {
  7851. for (var i in map) {
  7852. // check if array
  7853. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  7854. for (var j = 0; j < map[i].length; j++) {
  7855. if (util.has(map[i][j], str)) {
  7856. return (i === UNKNOWN) ? undefined$1 : i;
  7857. }
  7858. }
  7859. } else if (util.has(map[i], str)) {
  7860. return (i === UNKNOWN) ? undefined$1 : i;
  7861. }
  7862. }
  7863. return str;
  7864. }
  7865. };
  7866. ///////////////
  7867. // String map
  7868. //////////////
  7869. var maps = {
  7870. browser : {
  7871. oldsafari : {
  7872. version : {
  7873. '1.0' : '/8',
  7874. '1.2' : '/1',
  7875. '1.3' : '/3',
  7876. '2.0' : '/412',
  7877. '2.0.2' : '/416',
  7878. '2.0.3' : '/417',
  7879. '2.0.4' : '/419',
  7880. '?' : '/'
  7881. }
  7882. }
  7883. },
  7884. device : {
  7885. amazon : {
  7886. model : {
  7887. 'Fire Phone' : ['SD', 'KF']
  7888. }
  7889. },
  7890. sprint : {
  7891. model : {
  7892. 'Evo Shift 4G' : '7373KT'
  7893. },
  7894. vendor : {
  7895. 'HTC' : 'APA',
  7896. 'Sprint' : 'Sprint'
  7897. }
  7898. }
  7899. },
  7900. os : {
  7901. windows : {
  7902. version : {
  7903. 'ME' : '4.90',
  7904. 'NT 3.11' : 'NT3.51',
  7905. 'NT 4.0' : 'NT4.0',
  7906. '2000' : 'NT 5.0',
  7907. 'XP' : ['NT 5.1', 'NT 5.2'],
  7908. 'Vista' : 'NT 6.0',
  7909. '7' : 'NT 6.1',
  7910. '8' : 'NT 6.2',
  7911. '8.1' : 'NT 6.3',
  7912. '10' : ['NT 6.4', 'NT 10.0'],
  7913. 'RT' : 'ARM'
  7914. }
  7915. }
  7916. }
  7917. };
  7918. //////////////
  7919. // Regex map
  7920. /////////////
  7921. var regexes = {
  7922. browser : [[
  7923. // Presto based
  7924. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  7925. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  7926. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  7927. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  7928. ], [NAME, VERSION], [
  7929. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  7930. ], [[NAME, 'Opera Mini'], VERSION], [
  7931. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  7932. ], [[NAME, 'Opera'], VERSION], [
  7933. // Mixed
  7934. /(kindle)\/([\w\.]+)/i, // Kindle
  7935. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  7936. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  7937. // Trident based
  7938. /(avant\s|iemobile|slim)(?:browser)?[\/\s]?([\w\.]*)/i,
  7939. // Avant/IEMobile/SlimBrowser
  7940. /(bidubrowser|baidubrowser)[\/\s]?([\w\.]+)/i, // Baidu Browser
  7941. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  7942. // Webkit/KHTML based
  7943. /(rekonq)\/([\w\.]*)/i, // Rekonq
  7944. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon)\/([\w\.-]+)/i
  7945. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
  7946. ], [NAME, VERSION], [
  7947. /(konqueror)\/([\w\.]+)/i // Konqueror
  7948. ], [[NAME, 'Konqueror'], VERSION], [
  7949. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  7950. ], [[NAME, 'IE'], VERSION], [
  7951. /(edge|edgios|edga|edg)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  7952. ], [[NAME, 'Edge'], VERSION], [
  7953. /(yabrowser)\/([\w\.]+)/i // Yandex
  7954. ], [[NAME, 'Yandex'], VERSION], [
  7955. /(Avast)\/([\w\.]+)/i // Avast Secure Browser
  7956. ], [[NAME, 'Avast Secure Browser'], VERSION], [
  7957. /(AVG)\/([\w\.]+)/i // AVG Secure Browser
  7958. ], [[NAME, 'AVG Secure Browser'], VERSION], [
  7959. /(puffin)\/([\w\.]+)/i // Puffin
  7960. ], [[NAME, 'Puffin'], VERSION], [
  7961. /(focus)\/([\w\.]+)/i // Firefox Focus
  7962. ], [[NAME, 'Firefox Focus'], VERSION], [
  7963. /(opt)\/([\w\.]+)/i // Opera Touch
  7964. ], [[NAME, 'Opera Touch'], VERSION], [
  7965. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  7966. ], [[NAME, 'UCBrowser'], VERSION], [
  7967. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  7968. ], [[NAME, /_/g, ' '], VERSION], [
  7969. /(windowswechat qbcore)\/([\w\.]+)/i // WeChat Desktop for Windows Built-in Browser
  7970. ], [[NAME, 'WeChat(Win) Desktop'], VERSION], [
  7971. /(micromessenger)\/([\w\.]+)/i // WeChat
  7972. ], [[NAME, 'WeChat'], VERSION], [
  7973. /(brave)\/([\w\.]+)/i // Brave browser
  7974. ], [[NAME, 'Brave'], VERSION], [
  7975. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  7976. ], [NAME, VERSION], [
  7977. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  7978. ], [NAME, VERSION], [
  7979. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  7980. ], [NAME, VERSION], [
  7981. /(baiduboxapp)[\/\s]?([\w\.]+)/i // Baidu App
  7982. ], [NAME, VERSION], [
  7983. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  7984. ], [NAME, VERSION], [
  7985. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  7986. ], [NAME], [
  7987. /(LBBROWSER)/i // LieBao Browser
  7988. ], [NAME], [
  7989. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  7990. ], [VERSION, [NAME, 'MIUI Browser']], [
  7991. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  7992. ], [VERSION, [NAME, 'Facebook']], [
  7993. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  7994. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  7995. ], [NAME, VERSION], [
  7996. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  7997. ], [VERSION, [NAME, 'Chrome Headless']], [
  7998. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  7999. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  8000. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8001. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8002. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8003. ], [VERSION, [NAME, 'Android Browser']], [
  8004. /(sailfishbrowser)\/([\w\.]+)/i // Sailfish Browser
  8005. ], [[NAME, 'Sailfish Browser'], VERSION], [
  8006. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8007. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8008. ], [NAME, VERSION], [
  8009. /(dolfin)\/([\w\.]+)/i // Dolphin
  8010. ], [[NAME, 'Dolphin'], VERSION], [
  8011. /(qihu|qhbrowser|qihoobrowser|360browser)/i // 360
  8012. ], [[NAME, '360 Browser']], [
  8013. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8014. ], [[NAME, 'Chrome'], VERSION], [
  8015. /(coast)\/([\w\.]+)/i // Opera Coast
  8016. ], [[NAME, 'Opera Coast'], VERSION], [
  8017. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8018. ], [VERSION, [NAME, 'Firefox']], [
  8019. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8020. ], [VERSION, [NAME, 'Mobile Safari']], [
  8021. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8022. ], [VERSION, NAME], [
  8023. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8024. ], [[NAME, 'GSA'], VERSION], [
  8025. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8026. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8027. /(webkit|khtml)\/([\w\.]+)/i
  8028. ], [NAME, VERSION], [
  8029. // Gecko based
  8030. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8031. ], [[NAME, 'Netscape'], VERSION], [
  8032. /(swiftfox)/i, // Swiftfox
  8033. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8034. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8035. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8036. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8037. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8038. // Other
  8039. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8040. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8041. /(links)\s\(([\w\.]+)/i, // Links
  8042. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8043. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8044. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8045. ], [NAME, VERSION]
  8046. ],
  8047. cpu : [[
  8048. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8049. ], [[ARCHITECTURE, 'amd64']], [
  8050. /(ia32(?=;))/i // IA32 (quicktime)
  8051. ], [[ARCHITECTURE, util.lowerize]], [
  8052. /((?:i[346]|x)86)[;\)]/i // IA32
  8053. ], [[ARCHITECTURE, 'ia32']], [
  8054. // PocketPC mistakenly identified as PowerPC
  8055. /windows\s(ce|mobile);\sppc;/i
  8056. ], [[ARCHITECTURE, 'arm']], [
  8057. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8058. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8059. /(sun4\w)[;\)]/i // SPARC
  8060. ], [[ARCHITECTURE, 'sparc']], [
  8061. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8062. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8063. ], [[ARCHITECTURE, util.lowerize]]
  8064. ],
  8065. device : [[
  8066. /\((ipad|playbook);[\w\s\),;-]+(rim|apple)/i // iPad/PlayBook
  8067. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8068. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8069. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8070. /(apple\s{0,1}tv)/i // Apple TV
  8071. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple'], [TYPE, SMARTTV]], [
  8072. /(archos)\s(gamepad2?)/i, // Archos
  8073. /(hp).+(touchpad)/i, // HP TouchPad
  8074. /(hp).+(tablet)/i, // HP Tablet
  8075. /(kindle)\/([\w\.]+)/i, // Kindle
  8076. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8077. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8078. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8079. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8080. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8081. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8082. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8083. /android.+aft([bms])\sbuild/i // Fire TV
  8084. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8085. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8086. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8087. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8088. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8089. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8090. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8091. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8092. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8093. /(asus)-?(\w+)/i // Asus
  8094. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8095. /\(bb10;\s(\w+)/i // BlackBerry 10
  8096. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8097. // Asus Tablets
  8098. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone|p00c)/i
  8099. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8100. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8101. /(sony)?(?:sgp.+)\sbuild\//i
  8102. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8103. /android.+\s([c-g]\d{4}|so[-l]\w+)(?=\sbuild\/|\).+chrome\/(?![1-6]{0,1}\d\.))/i
  8104. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8105. /\s(ouya)\s/i, // Ouya
  8106. /(nintendo)\s([wids3u]+)/i // Nintendo
  8107. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8108. /android.+;\s(shield)\sbuild/i // Nvidia
  8109. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8110. /(playstation\s[34portablevi]+)/i // Playstation
  8111. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8112. /(sprint\s(\w+))/i // Sprint Phones
  8113. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8114. /(htc)[;_\s-]+([\w\s]+(?=\)|\sbuild)|\w+)/i, // HTC
  8115. /(zte)-(\w*)/i, // ZTE
  8116. /(alcatel|geeksphone|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  8117. // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
  8118. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  8119. /(nexus\s9)/i // HTC Nexus 9
  8120. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  8121. /d\/huawei([\w\s-]+)[;\)]/i,
  8122. /(nexus\s6p|vog-l29|ane-lx1|eml-l29)/i // Huawei
  8123. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  8124. /android.+(bah2?-a?[lw]\d{2})/i // Huawei MediaPad
  8125. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, TABLET]], [
  8126. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  8127. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8128. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  8129. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  8130. /(kin\.[onetw]{3})/i // Microsoft Kin
  8131. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  8132. // Motorola
  8133. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  8134. /mot[\s-]?(\w*)/i,
  8135. /(XT\d{3,4}) build\//i,
  8136. /(nexus\s6)/i
  8137. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  8138. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  8139. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  8140. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  8141. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  8142. /hbbtv.+maple;(\d+)/i
  8143. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  8144. /\(dtv[\);].+(aquos)/i // Sharp
  8145. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  8146. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  8147. /((SM-T\w+))/i
  8148. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  8149. /smart-tv.+(samsung)/i
  8150. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  8151. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  8152. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  8153. /sec-((sgh\w+))/i
  8154. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  8155. /sie-(\w*)/i // Siemens
  8156. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  8157. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  8158. /(nokia)[\s_-]?([\w-]*)/i
  8159. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  8160. /android[x\d\.\s;]+\s([ab][1-7]\-?[0178a]\d\d?)/i // Acer
  8161. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  8162. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  8163. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  8164. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  8165. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  8166. /(lg) netcast\.tv/i // LG SmartTV
  8167. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  8168. /(nexus\s[45])/i, // LG
  8169. /lg[e;\s\/-]+(\w*)/i,
  8170. /android.+lg(\-?[\d\w]+)\s+build/i
  8171. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  8172. /(lenovo)\s?(s(?:5000|6000)(?:[\w-]+)|tab(?:[\s\w]+))/i // Lenovo tablets
  8173. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8174. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  8175. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  8176. /(lenovo)[_\s-]?([\w-]+)/i
  8177. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8178. /linux;.+((jolla));/i // Jolla
  8179. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8180. /((pebble))app\/[\d\.]+\s/i // Pebble
  8181. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  8182. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  8183. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8184. /crkey/i // Google Chromecast
  8185. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google'], [TYPE, SMARTTV]], [
  8186. /android.+;\s(glass)\s\d/i // Google Glass
  8187. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  8188. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  8189. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  8190. /android.+;\s(pixel( [23])?( xl)?)[\s)]/i // Google Pixel
  8191. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  8192. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  8193. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  8194. /android.+(mi[\s\-_]*(?:a\d|one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i,
  8195. // Xiaomi Mi
  8196. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  8197. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  8198. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  8199. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  8200. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu
  8201. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [
  8202. /(mz)-([\w-]{2,})/i
  8203. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  8204. /android.+a000(1)\s+build/i, // OnePlus
  8205. /android.+oneplus\s(a\d{4})[\s)]/i
  8206. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  8207. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  8208. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  8209. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  8210. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  8211. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  8212. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  8213. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  8214. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  8215. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  8216. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  8217. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  8218. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  8219. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  8220. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  8221. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  8222. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  8223. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  8224. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  8225. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  8226. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  8227. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  8228. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  8229. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  8230. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  8231. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  8232. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  8233. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  8234. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  8235. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  8236. /android.+;\s(PH-1)\s/i
  8237. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  8238. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  8239. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  8240. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  8241. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8242. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  8243. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  8244. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  8245. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8246. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  8247. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  8248. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  8249. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8250. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  8251. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8252. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  8253. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  8254. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  8255. /[\s\/\(](smart-?tv)[;\)]/i // SmartTV
  8256. ], [[TYPE, SMARTTV]], [
  8257. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  8258. ], [MODEL, [VENDOR, 'Generic']]
  8259. ],
  8260. engine : [[
  8261. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  8262. ], [VERSION, [NAME, 'EdgeHTML']], [
  8263. /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i // Blink
  8264. ], [VERSION, [NAME, 'Blink']], [
  8265. /(presto)\/([\w\.]+)/i, // Presto
  8266. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i,
  8267. // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
  8268. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  8269. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  8270. ], [NAME, VERSION], [
  8271. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  8272. ], [VERSION, NAME]
  8273. ],
  8274. os : [[
  8275. // Windows based
  8276. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  8277. ], [NAME, VERSION], [
  8278. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  8279. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  8280. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  8281. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  8282. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  8283. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  8284. // Mobile/Embedded OS
  8285. /\((bb)(10);/i // BlackBerry 10
  8286. ], [[NAME, 'BlackBerry'], VERSION], [
  8287. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  8288. /(tizen|kaios)[\/\s]([\w\.]+)/i, // Tizen/KaiOS
  8289. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|sailfish|contiki)[\/\s-]?([\w\.]*)/i
  8290. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki/Sailfish OS
  8291. ], [NAME, VERSION], [
  8292. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  8293. ], [[NAME, 'Symbian'], VERSION], [
  8294. /\((series40);/i // Series 40
  8295. ], [NAME], [
  8296. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  8297. ], [[NAME, 'Firefox OS'], VERSION], [
  8298. // Console
  8299. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  8300. // GNU/Linux based
  8301. /(mint)[\/\s\(]?(\w*)/i, // Mint
  8302. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  8303. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  8304. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  8305. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  8306. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  8307. /(gnu)\s?([\w\.]*)/i // GNU
  8308. ], [NAME, VERSION], [
  8309. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  8310. ], [[NAME, 'Chromium OS'], VERSION],[
  8311. // Solaris
  8312. /(sunos)\s?([\w\.\d]*)/i // Solaris
  8313. ], [[NAME, 'Solaris'], VERSION], [
  8314. // BSD based
  8315. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  8316. ], [NAME, VERSION],[
  8317. /(haiku)\s(\w+)/i // Haiku
  8318. ], [NAME, VERSION],[
  8319. /cfnetwork\/.+darwin/i,
  8320. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  8321. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  8322. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  8323. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  8324. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  8325. // Other
  8326. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  8327. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  8328. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  8329. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  8330. /(unix)\s?([\w\.]*)/i // UNIX
  8331. ], [NAME, VERSION]
  8332. ]
  8333. };
  8334. /////////////////
  8335. // Constructor
  8336. ////////////////
  8337. var UAParser = function (uastring, extensions) {
  8338. if (typeof uastring === 'object') {
  8339. extensions = uastring;
  8340. uastring = undefined$1;
  8341. }
  8342. if (!(this instanceof UAParser)) {
  8343. return new UAParser(uastring, extensions).getResult();
  8344. }
  8345. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  8346. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  8347. this.getBrowser = function () {
  8348. var browser = { name: undefined$1, version: undefined$1 };
  8349. mapper.rgx.call(browser, ua, rgxmap.browser);
  8350. browser.major = util.major(browser.version); // deprecated
  8351. return browser;
  8352. };
  8353. this.getCPU = function () {
  8354. var cpu = { architecture: undefined$1 };
  8355. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  8356. return cpu;
  8357. };
  8358. this.getDevice = function () {
  8359. var device = { vendor: undefined$1, model: undefined$1, type: undefined$1 };
  8360. mapper.rgx.call(device, ua, rgxmap.device);
  8361. return device;
  8362. };
  8363. this.getEngine = function () {
  8364. var engine = { name: undefined$1, version: undefined$1 };
  8365. mapper.rgx.call(engine, ua, rgxmap.engine);
  8366. return engine;
  8367. };
  8368. this.getOS = function () {
  8369. var os = { name: undefined$1, version: undefined$1 };
  8370. mapper.rgx.call(os, ua, rgxmap.os);
  8371. return os;
  8372. };
  8373. this.getResult = function () {
  8374. return {
  8375. ua : this.getUA(),
  8376. browser : this.getBrowser(),
  8377. engine : this.getEngine(),
  8378. os : this.getOS(),
  8379. device : this.getDevice(),
  8380. cpu : this.getCPU()
  8381. };
  8382. };
  8383. this.getUA = function () {
  8384. return ua;
  8385. };
  8386. this.setUA = function (uastring) {
  8387. ua = uastring;
  8388. return this;
  8389. };
  8390. return this;
  8391. };
  8392. UAParser.VERSION = LIBVERSION;
  8393. UAParser.BROWSER = {
  8394. NAME : NAME,
  8395. MAJOR : MAJOR, // deprecated
  8396. VERSION : VERSION
  8397. };
  8398. UAParser.CPU = {
  8399. ARCHITECTURE : ARCHITECTURE
  8400. };
  8401. UAParser.DEVICE = {
  8402. MODEL : MODEL,
  8403. VENDOR : VENDOR,
  8404. TYPE : TYPE,
  8405. CONSOLE : CONSOLE,
  8406. MOBILE : MOBILE,
  8407. SMARTTV : SMARTTV,
  8408. TABLET : TABLET,
  8409. WEARABLE: WEARABLE,
  8410. EMBEDDED: EMBEDDED
  8411. };
  8412. UAParser.ENGINE = {
  8413. NAME : NAME,
  8414. VERSION : VERSION
  8415. };
  8416. UAParser.OS = {
  8417. NAME : NAME,
  8418. VERSION : VERSION
  8419. };
  8420. ///////////
  8421. // Export
  8422. //////////
  8423. // check js environment
  8424. {
  8425. // nodejs env
  8426. if ( module.exports) {
  8427. exports = module.exports = UAParser;
  8428. }
  8429. exports.UAParser = UAParser;
  8430. }
  8431. // jQuery/Zepto specific (optional)
  8432. // Note:
  8433. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  8434. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  8435. // and we should catch that.
  8436. var $ = window && (window.jQuery || window.Zepto);
  8437. if ($ && !$.ua) {
  8438. var parser = new UAParser();
  8439. $.ua = parser.getResult();
  8440. $.ua.get = function () {
  8441. return parser.getUA();
  8442. };
  8443. $.ua.set = function (uastring) {
  8444. parser.setUA(uastring);
  8445. var result = parser.getResult();
  8446. for (var prop in result) {
  8447. $.ua[prop] = result[prop];
  8448. }
  8449. };
  8450. }
  8451. })(typeof window === 'object' ? window : _commonjsHelpers.commonjsGlobal);
  8452. });
  8453. var uaParser_1 = uaParser.UAParser;
  8454. var UNKNOWN = 'Unknown';
  8455. var PLATFORM_MAP = {
  8456. 'Mac OS': 'Mac OS X'
  8457. };
  8458. /**
  8459. * Convert from UAParser platform name to what we expect.
  8460. */
  8461. function convertPlatformName(name) {
  8462. return PLATFORM_MAP[name] || name;
  8463. }
  8464. /**
  8465. * Get the version number in parts. This is very naive. We actually get major
  8466. * version as a part of UAParser already, which is generally good enough, but
  8467. * let's get the minor just in case.
  8468. */
  8469. function getBrowserVersion(version) {
  8470. if (!version) {
  8471. return {
  8472. major: '',
  8473. minor: ''
  8474. };
  8475. }
  8476. var parts = version.split('.');
  8477. return {
  8478. major: parts[0],
  8479. minor: parts[1]
  8480. };
  8481. }
  8482. /**
  8483. * Get the UA data fom UAParser and then convert it to the format we're
  8484. * expecting for our APIS.
  8485. */
  8486. var parser = new uaParser();
  8487. var results = parser.getResult();
  8488. // Do some conversion first.
  8489. var browserVersionData = getBrowserVersion(results.browser.version);
  8490. var uaData = {
  8491. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8492. browserFullVersion: results.browser.version || UNKNOWN,
  8493. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8494. browserName: results.browser.name || UNKNOWN,
  8495. browserVersion: results.browser.major || UNKNOWN,
  8496. deviceName: results.device.model || UNKNOWN,
  8497. engineName: results.engine.name || UNKNOWN,
  8498. engineVersion: results.engine.version || UNKNOWN,
  8499. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8500. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8501. platformVersion: results.os.version || UNKNOWN,
  8502. platformFullVersion: results.os.version || UNKNOWN
  8503. };
  8504. var UserAgentData = uaData;
  8505. var componentRegex = /\./;
  8506. var orRegex = /\|\|/;
  8507. var rangeRegex = /\s+\-\s+/;
  8508. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  8509. var numericRegex = /^(\d*)(.*)/;
  8510. /**
  8511. * Splits input `range` on "||" and returns true if any subrange matches
  8512. * `version`.
  8513. *
  8514. * @param {string} range
  8515. * @param {string} version
  8516. * @returns {boolean}
  8517. */
  8518. function checkOrExpression(range, version) {
  8519. var expressions = range.split(orRegex);
  8520. if (expressions.length > 1) {
  8521. return expressions.some(function (range) {
  8522. return VersionRange.contains(range, version);
  8523. });
  8524. } else {
  8525. range = expressions[0].trim();
  8526. return checkRangeExpression(range, version);
  8527. }
  8528. }
  8529. /**
  8530. * Splits input `range` on " - " (the surrounding whitespace is required) and
  8531. * returns true if version falls between the two operands.
  8532. *
  8533. * @param {string} range
  8534. * @param {string} version
  8535. * @returns {boolean}
  8536. */
  8537. function checkRangeExpression(range, version) {
  8538. var expressions = range.split(rangeRegex);
  8539. !(expressions.length > 0 && expressions.length <= 2) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'the "-" operator expects exactly 2 operands') : invariant_1(false) : void 0;
  8540. if (expressions.length === 1) {
  8541. return checkSimpleExpression(expressions[0], version);
  8542. } else {
  8543. var startVersion = expressions[0],
  8544. endVersion = expressions[1];
  8545. !(isSimpleVersion(startVersion) && isSimpleVersion(endVersion)) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'operands to the "-" operator must be simple (no modifiers)') : invariant_1(false) : void 0;
  8546. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  8547. }
  8548. }
  8549. /**
  8550. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  8551. * not a compound range using the " - " or "||" operators).
  8552. *
  8553. * @param {string} range
  8554. * @param {string} version
  8555. * @returns {boolean}
  8556. */
  8557. function checkSimpleExpression(range, version) {
  8558. range = range.trim();
  8559. if (range === '') {
  8560. return true;
  8561. }
  8562. var versionComponents = version.split(componentRegex);
  8563. var _getModifierAndCompon = getModifierAndComponents(range),
  8564. modifier = _getModifierAndCompon.modifier,
  8565. rangeComponents = _getModifierAndCompon.rangeComponents;
  8566. switch (modifier) {
  8567. case '<':
  8568. return checkLessThan(versionComponents, rangeComponents);
  8569. case '<=':
  8570. return checkLessThanOrEqual(versionComponents, rangeComponents);
  8571. case '>=':
  8572. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  8573. case '>':
  8574. return checkGreaterThan(versionComponents, rangeComponents);
  8575. case '~':
  8576. case '~>':
  8577. return checkApproximateVersion(versionComponents, rangeComponents);
  8578. default:
  8579. return checkEqual(versionComponents, rangeComponents);
  8580. }
  8581. }
  8582. /**
  8583. * Checks whether `a` is less than `b`.
  8584. *
  8585. * @param {array<string>} a
  8586. * @param {array<string>} b
  8587. * @returns {boolean}
  8588. */
  8589. function checkLessThan(a, b) {
  8590. return compareComponents(a, b) === -1;
  8591. }
  8592. /**
  8593. * Checks whether `a` is less than or equal to `b`.
  8594. *
  8595. * @param {array<string>} a
  8596. * @param {array<string>} b
  8597. * @returns {boolean}
  8598. */
  8599. function checkLessThanOrEqual(a, b) {
  8600. var result = compareComponents(a, b);
  8601. return result === -1 || result === 0;
  8602. }
  8603. /**
  8604. * Checks whether `a` is equal to `b`.
  8605. *
  8606. * @param {array<string>} a
  8607. * @param {array<string>} b
  8608. * @returns {boolean}
  8609. */
  8610. function checkEqual(a, b) {
  8611. return compareComponents(a, b) === 0;
  8612. }
  8613. /**
  8614. * Checks whether `a` is greater than or equal to `b`.
  8615. *
  8616. * @param {array<string>} a
  8617. * @param {array<string>} b
  8618. * @returns {boolean}
  8619. */
  8620. function checkGreaterThanOrEqual(a, b) {
  8621. var result = compareComponents(a, b);
  8622. return result === 1 || result === 0;
  8623. }
  8624. /**
  8625. * Checks whether `a` is greater than `b`.
  8626. *
  8627. * @param {array<string>} a
  8628. * @param {array<string>} b
  8629. * @returns {boolean}
  8630. */
  8631. function checkGreaterThan(a, b) {
  8632. return compareComponents(a, b) === 1;
  8633. }
  8634. /**
  8635. * Checks whether `a` is "reasonably close" to `b` (as described in
  8636. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  8637. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  8638. *
  8639. * @param {array<string>} a
  8640. * @param {array<string>} b
  8641. * @returns {boolean}
  8642. */
  8643. function checkApproximateVersion(a, b) {
  8644. var lowerBound = b.slice();
  8645. var upperBound = b.slice();
  8646. if (upperBound.length > 1) {
  8647. upperBound.pop();
  8648. }
  8649. var lastIndex = upperBound.length - 1;
  8650. var numeric = parseInt(upperBound[lastIndex], 10);
  8651. if (isNumber(numeric)) {
  8652. upperBound[lastIndex] = numeric + 1 + '';
  8653. }
  8654. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  8655. }
  8656. /**
  8657. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  8658. * components from `range`.
  8659. *
  8660. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  8661. * `">="` and `components` of `[1, 2, 3]`.
  8662. *
  8663. * @param {string} range
  8664. * @returns {object}
  8665. */
  8666. function getModifierAndComponents(range) {
  8667. var rangeComponents = range.split(componentRegex);
  8668. var matches = rangeComponents[0].match(modifierRegex);
  8669. !matches ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expected regex to match but it did not') : invariant_1(false) : void 0;
  8670. return {
  8671. modifier: matches[1],
  8672. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  8673. };
  8674. }
  8675. /**
  8676. * Determines if `number` is a number.
  8677. *
  8678. * @param {mixed} number
  8679. * @returns {boolean}
  8680. */
  8681. function isNumber(number) {
  8682. return !isNaN(number) && isFinite(number);
  8683. }
  8684. /**
  8685. * Tests whether `range` is a "simple" version number without any modifiers
  8686. * (">", "~" etc).
  8687. *
  8688. * @param {string} range
  8689. * @returns {boolean}
  8690. */
  8691. function isSimpleVersion(range) {
  8692. return !getModifierAndComponents(range).modifier;
  8693. }
  8694. /**
  8695. * Zero-pads array `array` until it is at least `length` long.
  8696. *
  8697. * @param {array} array
  8698. * @param {number} length
  8699. */
  8700. function zeroPad(array, length) {
  8701. for (var i = array.length; i < length; i++) {
  8702. array[i] = '0';
  8703. }
  8704. }
  8705. /**
  8706. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  8707. *
  8708. * - zero-pads `a` and `b`
  8709. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  8710. * in both `a` and `b`
  8711. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  8712. * and all of its successors in `a`
  8713. *
  8714. * @param {array<string>} a
  8715. * @param {array<string>} b
  8716. * @returns {array<array<string>>}
  8717. */
  8718. function normalizeVersions(a, b) {
  8719. a = a.slice();
  8720. b = b.slice();
  8721. zeroPad(a, b.length);
  8722. // mark "x" and "*" components as equal
  8723. for (var i = 0; i < b.length; i++) {
  8724. var matches = b[i].match(/^[x*]$/i);
  8725. if (matches) {
  8726. b[i] = a[i] = '0';
  8727. // final "*" greedily zeros all remaining components
  8728. if (matches[0] === '*' && i === b.length - 1) {
  8729. for (var j = i; j < a.length; j++) {
  8730. a[j] = '0';
  8731. }
  8732. }
  8733. }
  8734. }
  8735. zeroPad(b, a.length);
  8736. return [a, b];
  8737. }
  8738. /**
  8739. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  8740. *
  8741. * For example, `10-alpha` is greater than `2-beta`.
  8742. *
  8743. * @param {string} a
  8744. * @param {string} b
  8745. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8746. * or greater than `b`, respectively
  8747. */
  8748. function compareNumeric(a, b) {
  8749. var aPrefix = a.match(numericRegex)[1];
  8750. var bPrefix = b.match(numericRegex)[1];
  8751. var aNumeric = parseInt(aPrefix, 10);
  8752. var bNumeric = parseInt(bPrefix, 10);
  8753. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  8754. return compare(aNumeric, bNumeric);
  8755. } else {
  8756. return compare(a, b);
  8757. }
  8758. }
  8759. /**
  8760. * Returns the ordering of `a` and `b`.
  8761. *
  8762. * @param {string|number} a
  8763. * @param {string|number} b
  8764. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8765. * or greater than `b`, respectively
  8766. */
  8767. function compare(a, b) {
  8768. !(typeof a === typeof b) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, '"a" and "b" must be of the same type') : invariant_1(false) : void 0;
  8769. if (a > b) {
  8770. return 1;
  8771. } else if (a < b) {
  8772. return -1;
  8773. } else {
  8774. return 0;
  8775. }
  8776. }
  8777. /**
  8778. * Compares arrays of version components.
  8779. *
  8780. * @param {array<string>} a
  8781. * @param {array<string>} b
  8782. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  8783. * or greater than `b`, respectively
  8784. */
  8785. function compareComponents(a, b) {
  8786. var _normalizeVersions = normalizeVersions(a, b),
  8787. aNormalized = _normalizeVersions[0],
  8788. bNormalized = _normalizeVersions[1];
  8789. for (var i = 0; i < bNormalized.length; i++) {
  8790. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  8791. if (result) {
  8792. return result;
  8793. }
  8794. }
  8795. return 0;
  8796. }
  8797. var VersionRange = {
  8798. /**
  8799. * Checks whether `version` satisfies the `range` specification.
  8800. *
  8801. * We support a subset of the expressions defined in
  8802. * https://www.npmjs.org/doc/misc/semver.html:
  8803. *
  8804. * version Must match version exactly
  8805. * =version Same as just version
  8806. * >version Must be greater than version
  8807. * >=version Must be greater than or equal to version
  8808. * <version Must be less than version
  8809. * <=version Must be less than or equal to version
  8810. * ~version Must be at least version, but less than the next significant
  8811. * revision above version:
  8812. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  8813. * ~>version Equivalent to ~version
  8814. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  8815. * anything
  8816. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  8817. * "greedy" wildcard, so will match any number of additional
  8818. * components:
  8819. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  8820. * * Any version
  8821. * "" (Empty string) Same as *
  8822. * v1 - v2 Equivalent to ">= v1 and <= v2"
  8823. * r1 || r2 Passes if either r1 or r2 are satisfied
  8824. *
  8825. * @param {string} range
  8826. * @param {string} version
  8827. * @returns {boolean}
  8828. */
  8829. contains: function contains(range, version) {
  8830. return checkOrExpression(range.trim(), version.trim());
  8831. }
  8832. };
  8833. var VersionRange_1 = VersionRange;
  8834. /**
  8835. * Copyright (c) 2013-present, Facebook, Inc.
  8836. *
  8837. * This source code is licensed under the MIT license found in the
  8838. * LICENSE file in the root directory of this source tree.
  8839. *
  8840. */
  8841. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  8842. /**
  8843. * Executes the provided `callback` once for each enumerable own property in the
  8844. * object and constructs a new object from the results. The `callback` is
  8845. * invoked with three arguments:
  8846. *
  8847. * - the property value
  8848. * - the property name
  8849. * - the object being traversed
  8850. *
  8851. * Properties that are added after the call to `mapObject` will not be visited
  8852. * by `callback`. If the values of existing properties are changed, the value
  8853. * passed to `callback` will be the value at the time `mapObject` visits them.
  8854. * Properties that are deleted before being visited are not visited.
  8855. *
  8856. * @grep function objectMap()
  8857. * @grep function objMap()
  8858. *
  8859. * @param {?object} object
  8860. * @param {function} callback
  8861. * @param {*} context
  8862. * @return {?object}
  8863. */
  8864. function mapObject(object, callback, context) {
  8865. if (!object) {
  8866. return null;
  8867. }
  8868. var result = {};
  8869. for (var name in object) {
  8870. if (hasOwnProperty$1.call(object, name)) {
  8871. result[name] = callback.call(context, object[name], name, object);
  8872. }
  8873. }
  8874. return result;
  8875. }
  8876. var mapObject_1 = mapObject;
  8877. /**
  8878. * Copyright (c) 2013-present, Facebook, Inc.
  8879. *
  8880. * This source code is licensed under the MIT license found in the
  8881. * LICENSE file in the root directory of this source tree.
  8882. *
  8883. *
  8884. * @typechecks static-only
  8885. */
  8886. /**
  8887. * Memoizes the return value of a function that accepts one string argument.
  8888. */
  8889. function memoizeStringOnly(callback) {
  8890. var cache = {};
  8891. return function (string) {
  8892. if (!cache.hasOwnProperty(string)) {
  8893. cache[string] = callback.call(this, string);
  8894. }
  8895. return cache[string];
  8896. };
  8897. }
  8898. var memoizeStringOnly_1 = memoizeStringOnly;
  8899. /**
  8900. * Checks to see whether `name` and `version` satisfy `query`.
  8901. *
  8902. * @param {string} name Name of the browser, device, engine or platform
  8903. * @param {?string} version Version of the browser, engine or platform
  8904. * @param {string} query Query of form "Name [range expression]"
  8905. * @param {?function} normalizer Optional pre-processor for range expression
  8906. * @return {boolean}
  8907. */
  8908. function compare$1(name, version, query, normalizer) {
  8909. // check for exact match with no version
  8910. if (name === query) {
  8911. return true;
  8912. }
  8913. // check for non-matching names
  8914. if (!query.startsWith(name)) {
  8915. return false;
  8916. }
  8917. // full comparison with version
  8918. var range = query.slice(name.length);
  8919. if (version) {
  8920. range = normalizer ? normalizer(range) : range;
  8921. return VersionRange_1.contains(range, version);
  8922. }
  8923. return false;
  8924. }
  8925. /**
  8926. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  8927. * platform.
  8928. *
  8929. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  8930. *
  8931. * @param {string} version
  8932. * @return {string}
  8933. */
  8934. function normalizePlatformVersion(version) {
  8935. if (UserAgentData.platformName === 'Windows') {
  8936. return version.replace(/^\s*NT/, '');
  8937. }
  8938. return version;
  8939. }
  8940. /**
  8941. * Provides client-side access to the authoritative PHP-generated User Agent
  8942. * information supplied by the server.
  8943. */
  8944. var UserAgent = {
  8945. /**
  8946. * Check if the User Agent browser matches `query`.
  8947. *
  8948. * `query` should be a string like "Chrome" or "Chrome > 33".
  8949. *
  8950. * Valid browser names include:
  8951. *
  8952. * - ACCESS NetFront
  8953. * - AOL
  8954. * - Amazon Silk
  8955. * - Android
  8956. * - BlackBerry
  8957. * - BlackBerry PlayBook
  8958. * - Chrome
  8959. * - Chrome for iOS
  8960. * - Chrome frame
  8961. * - Facebook PHP SDK
  8962. * - Facebook for iOS
  8963. * - Firefox
  8964. * - IE
  8965. * - IE Mobile
  8966. * - Mobile Safari
  8967. * - Motorola Internet Browser
  8968. * - Nokia
  8969. * - Openwave Mobile Browser
  8970. * - Opera
  8971. * - Opera Mini
  8972. * - Opera Mobile
  8973. * - Safari
  8974. * - UIWebView
  8975. * - Unknown
  8976. * - webOS
  8977. * - etc...
  8978. *
  8979. * An authoritative list can be found in the PHP `BrowserDetector` class and
  8980. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  8981. * https://fburl.com/50728104).
  8982. *
  8983. * @note Function results are memoized
  8984. *
  8985. * @param {string} query Query of the form "Name [range expression]"
  8986. * @return {boolean}
  8987. */
  8988. isBrowser: function isBrowser(query) {
  8989. return compare$1(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  8990. },
  8991. /**
  8992. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  8993. *
  8994. * @note Function results are memoized
  8995. *
  8996. * @param {string} query Query of the form "32" or "64".
  8997. * @return {boolean}
  8998. */
  8999. isBrowserArchitecture: function isBrowserArchitecture(query) {
  9000. return compare$1(UserAgentData.browserArchitecture, null, query);
  9001. },
  9002. /**
  9003. * Check if the User Agent device matches `query`.
  9004. *
  9005. * `query` should be a string like "iPhone" or "iPad".
  9006. *
  9007. * Valid device names include:
  9008. *
  9009. * - Kindle
  9010. * - Kindle Fire
  9011. * - Unknown
  9012. * - iPad
  9013. * - iPhone
  9014. * - iPod
  9015. * - etc...
  9016. *
  9017. * An authoritative list can be found in the PHP `DeviceDetector` class and
  9018. * related classes in the same file (see calls to `new UserAgentDevice` here:
  9019. * https://fburl.com/50728332).
  9020. *
  9021. * @note Function results are memoized
  9022. *
  9023. * @param {string} query Query of the form "Name"
  9024. * @return {boolean}
  9025. */
  9026. isDevice: function isDevice(query) {
  9027. return compare$1(UserAgentData.deviceName, null, query);
  9028. },
  9029. /**
  9030. * Check if the User Agent rendering engine matches `query`.
  9031. *
  9032. * `query` should be a string like "WebKit" or "WebKit >= 537".
  9033. *
  9034. * Valid engine names include:
  9035. *
  9036. * - Gecko
  9037. * - Presto
  9038. * - Trident
  9039. * - WebKit
  9040. * - etc...
  9041. *
  9042. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  9043. * class related classes in the same file (see calls to `new
  9044. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  9045. *
  9046. * @note Function results are memoized
  9047. *
  9048. * @param {string} query Query of the form "Name [range expression]"
  9049. * @return {boolean}
  9050. */
  9051. isEngine: function isEngine(query) {
  9052. return compare$1(UserAgentData.engineName, UserAgentData.engineVersion, query);
  9053. },
  9054. /**
  9055. * Check if the User Agent platform matches `query`.
  9056. *
  9057. * `query` should be a string like "Windows" or "iOS 5 - 6".
  9058. *
  9059. * Valid platform names include:
  9060. *
  9061. * - Android
  9062. * - BlackBerry OS
  9063. * - Java ME
  9064. * - Linux
  9065. * - Mac OS X
  9066. * - Mac OS X Calendar
  9067. * - Mac OS X Internet Account
  9068. * - Symbian
  9069. * - SymbianOS
  9070. * - Windows
  9071. * - Windows Mobile
  9072. * - Windows Phone
  9073. * - iOS
  9074. * - iOS Facebook Integration Account
  9075. * - iOS Facebook Social Sharing UI
  9076. * - webOS
  9077. * - Chrome OS
  9078. * - etc...
  9079. *
  9080. * An authoritative list can be found in the PHP `PlatformDetector` class and
  9081. * related classes in the same file (see calls to `new UserAgentPlatform`
  9082. * here: https://fburl.com/50729226).
  9083. *
  9084. * @note Function results are memoized
  9085. *
  9086. * @param {string} query Query of the form "Name [range expression]"
  9087. * @return {boolean}
  9088. */
  9089. isPlatform: function isPlatform(query) {
  9090. return compare$1(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  9091. },
  9092. /**
  9093. * Check if the User Agent platform is a 32 or 64 bit architecture.
  9094. *
  9095. * @note Function results are memoized
  9096. *
  9097. * @param {string} query Query of the form "32" or "64".
  9098. * @return {boolean}
  9099. */
  9100. isPlatformArchitecture: function isPlatformArchitecture(query) {
  9101. return compare$1(UserAgentData.platformArchitecture, null, query);
  9102. }
  9103. };
  9104. var UserAgent_1 = mapObject_1(UserAgent, memoizeStringOnly_1);
  9105. function _classCallCheck$9(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9106. function _possibleConstructorReturn$6(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9107. function _inherits$6(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9108. // In IE, spans with <br> tags render as two newlines. By rendering a span
  9109. // with only a newline character, we can be sure to render a single line.
  9110. var useNewlineChar = UserAgent_1.isBrowser('IE <= 11');
  9111. /**
  9112. * Check whether the node should be considered a newline.
  9113. */
  9114. function isNewline(node) {
  9115. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  9116. }
  9117. /**
  9118. * Placeholder elements for empty text content.
  9119. *
  9120. * What is this `data-text` attribute, anyway? It turns out that we need to
  9121. * put an attribute on the lowest-level text node in order to preserve correct
  9122. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  9123. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  9124. * If the <span> has an attribute, this appears not to happen.
  9125. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  9126. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  9127. */
  9128. var NEWLINE_A = useNewlineChar ? _reactDom_commonjsExternal.React.createElement(
  9129. 'span',
  9130. { key: 'A', 'data-text': 'true' },
  9131. '\n'
  9132. ) : _reactDom_commonjsExternal.React.createElement('br', { key: 'A', 'data-text': 'true' });
  9133. var NEWLINE_B = useNewlineChar ? _reactDom_commonjsExternal.React.createElement(
  9134. 'span',
  9135. { key: 'B', 'data-text': 'true' },
  9136. '\n'
  9137. ) : _reactDom_commonjsExternal.React.createElement('br', { key: 'B', 'data-text': 'true' });
  9138. /**
  9139. * The lowest-level component in a `DraftEditor`, the text node component
  9140. * replaces the default React text node implementation. This allows us to
  9141. * perform custom handling of newline behavior and avoid re-rendering text
  9142. * nodes with DOM state that already matches the expectations of our immutable
  9143. * editor state.
  9144. */
  9145. var DraftEditorTextNode = function (_React$Component) {
  9146. _inherits$6(DraftEditorTextNode, _React$Component);
  9147. function DraftEditorTextNode(props) {
  9148. _classCallCheck$9(this, DraftEditorTextNode);
  9149. // By flipping this flag, we also keep flipping keys which forces
  9150. // React to remount this node every time it rerenders.
  9151. var _this = _possibleConstructorReturn$6(this, _React$Component.call(this, props));
  9152. _this._forceFlag = false;
  9153. return _this;
  9154. }
  9155. DraftEditorTextNode.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9156. var node = _reactDom_commonjsExternal.require$$3.findDOMNode(this);
  9157. var shouldBeNewline = nextProps.children === '';
  9158. !(node instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'node is not an Element') : invariant_1(false) : void 0;
  9159. if (shouldBeNewline) {
  9160. return !isNewline(node);
  9161. }
  9162. return node.textContent !== nextProps.children;
  9163. };
  9164. DraftEditorTextNode.prototype.componentDidMount = function componentDidMount() {
  9165. this._forceFlag = !this._forceFlag;
  9166. };
  9167. DraftEditorTextNode.prototype.componentDidUpdate = function componentDidUpdate() {
  9168. this._forceFlag = !this._forceFlag;
  9169. };
  9170. DraftEditorTextNode.prototype.render = function render() {
  9171. if (this.props.children === '') {
  9172. return this._forceFlag ? NEWLINE_A : NEWLINE_B;
  9173. }
  9174. return _reactDom_commonjsExternal.React.createElement(
  9175. 'span',
  9176. { key: this._forceFlag ? 'A' : 'B', 'data-text': 'true' },
  9177. this.props.children
  9178. );
  9179. };
  9180. return DraftEditorTextNode;
  9181. }(_reactDom_commonjsExternal.React.Component);
  9182. var DraftEditorTextNode_react = DraftEditorTextNode;
  9183. /**
  9184. * Copyright (c) 2013-present, Facebook, Inc.
  9185. * All rights reserved.
  9186. *
  9187. * This source code is licensed under the BSD-style license found in the
  9188. * LICENSE file in the root directory of this source tree. An additional grant
  9189. * of patent rights can be found in the PATENTS file in the same directory.
  9190. *
  9191. * @providesModule DraftJsDebugLogging
  9192. */
  9193. var DraftJsDebugLogging = {
  9194. logSelectionStateFailure: function logSelectionStateFailure() {
  9195. return null;
  9196. }
  9197. };
  9198. /**
  9199. * Copyright (c) 2013-present, Facebook, Inc.
  9200. *
  9201. * This source code is licensed under the MIT license found in the
  9202. * LICENSE file in the root directory of this source tree.
  9203. *
  9204. * @typechecks
  9205. */
  9206. /**
  9207. * @param {*} object The object to check.
  9208. * @return {boolean} Whether or not the object is a DOM node.
  9209. */
  9210. function isNode(object) {
  9211. var doc = object ? object.ownerDocument || object : document;
  9212. var defaultView = doc.defaultView || window;
  9213. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  9214. }
  9215. var isNode_1 = isNode;
  9216. /**
  9217. * Copyright (c) 2013-present, Facebook, Inc.
  9218. *
  9219. * This source code is licensed under the MIT license found in the
  9220. * LICENSE file in the root directory of this source tree.
  9221. *
  9222. * @typechecks
  9223. */
  9224. /**
  9225. * @param {*} object The object to check.
  9226. * @return {boolean} Whether or not the object is a DOM text node.
  9227. */
  9228. function isTextNode(object) {
  9229. return isNode_1(object) && object.nodeType == 3;
  9230. }
  9231. var isTextNode_1 = isTextNode;
  9232. /**
  9233. * Copyright (c) 2013-present, Facebook, Inc.
  9234. *
  9235. * This source code is licensed under the MIT license found in the
  9236. * LICENSE file in the root directory of this source tree.
  9237. *
  9238. *
  9239. */
  9240. /*eslint-disable no-bitwise */
  9241. /**
  9242. * Checks if a given DOM node contains or is another DOM node.
  9243. */
  9244. function containsNode(outerNode, innerNode) {
  9245. if (!outerNode || !innerNode) {
  9246. return false;
  9247. } else if (outerNode === innerNode) {
  9248. return true;
  9249. } else if (isTextNode_1(outerNode)) {
  9250. return false;
  9251. } else if (isTextNode_1(innerNode)) {
  9252. return containsNode(outerNode, innerNode.parentNode);
  9253. } else if ('contains' in outerNode) {
  9254. return outerNode.contains(innerNode);
  9255. } else if (outerNode.compareDocumentPosition) {
  9256. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  9257. } else {
  9258. return false;
  9259. }
  9260. }
  9261. var containsNode_1 = containsNode;
  9262. /**
  9263. * Copyright (c) 2013-present, Facebook, Inc.
  9264. *
  9265. * This source code is licensed under the MIT license found in the
  9266. * LICENSE file in the root directory of this source tree.
  9267. *
  9268. * @typechecks
  9269. */
  9270. /* eslint-disable fb-www/typeof-undefined */
  9271. /**
  9272. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  9273. * not safe to call document.activeElement if there is nothing focused.
  9274. *
  9275. * The activeElement will be null only if the document or document body is not
  9276. * yet defined.
  9277. *
  9278. * @param {?DOMDocument} doc Defaults to current document.
  9279. * @return {?DOMElement}
  9280. */
  9281. function getActiveElement(doc) /*?DOMElement*/{
  9282. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  9283. if (typeof doc === 'undefined') {
  9284. return null;
  9285. }
  9286. try {
  9287. return doc.activeElement || doc.body;
  9288. } catch (e) {
  9289. return doc.body;
  9290. }
  9291. }
  9292. var getActiveElement_1 = getActiveElement;
  9293. function getAnonymizedDOM(node, getNodeLabels) {
  9294. if (!node) {
  9295. return '[empty]';
  9296. }
  9297. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  9298. if (anonymized.nodeType === Node.TEXT_NODE) {
  9299. return anonymized.textContent;
  9300. }
  9301. !(anonymized instanceof Element) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Node must be an Element if it is not a text node.') : invariant_1(false) : void 0;
  9302. return anonymized.outerHTML;
  9303. }
  9304. function anonymizeTextWithin(node, getNodeLabels) {
  9305. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  9306. if (node.nodeType === Node.TEXT_NODE) {
  9307. var length = node.textContent.length;
  9308. return document.createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  9309. }
  9310. var clone = node.cloneNode();
  9311. if (clone.nodeType === 1 && labels.length) {
  9312. clone.setAttribute('data-labels', labels.join(', '));
  9313. }
  9314. var childNodes = node.childNodes;
  9315. for (var ii = 0; ii < childNodes.length; ii++) {
  9316. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  9317. }
  9318. return clone;
  9319. }
  9320. function getAnonymizedEditorDOM(node, getNodeLabels) {
  9321. // grabbing the DOM content of the Draft editor
  9322. var currentNode = node;
  9323. while (currentNode) {
  9324. if (currentNode instanceof Element && currentNode.hasAttribute('contenteditable')) {
  9325. // found the Draft editor container
  9326. return getAnonymizedDOM(currentNode, getNodeLabels);
  9327. } else {
  9328. currentNode = currentNode.parentNode;
  9329. }
  9330. }
  9331. return 'Could not find contentEditable parent of node';
  9332. }
  9333. function getNodeLength(node) {
  9334. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  9335. }
  9336. /**
  9337. * In modern non-IE browsers, we can support both forward and backward
  9338. * selections.
  9339. *
  9340. * Note: IE10+ supports the Selection object, but it does not support
  9341. * the `extend` method, which means that even in modern IE, it's not possible
  9342. * to programatically create a backward selection. Thus, for all IE
  9343. * versions, we use the old IE API to create our selections.
  9344. */
  9345. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  9346. // It's possible that the editor has been removed from the DOM but
  9347. // our selection code doesn't know it yet. Forcing selection in
  9348. // this case may lead to errors, so just bail now.
  9349. if (!containsNode_1(document.documentElement, node)) {
  9350. return;
  9351. }
  9352. var selection = _commonjsHelpers.commonjsGlobal.getSelection();
  9353. var anchorKey = selectionState.getAnchorKey();
  9354. var anchorOffset = selectionState.getAnchorOffset();
  9355. var focusKey = selectionState.getFocusKey();
  9356. var focusOffset = selectionState.getFocusOffset();
  9357. var isBackward = selectionState.getIsBackward();
  9358. // IE doesn't support backward selection. Swap key/offset pairs.
  9359. if (!selection.extend && isBackward) {
  9360. var tempKey = anchorKey;
  9361. var tempOffset = anchorOffset;
  9362. anchorKey = focusKey;
  9363. anchorOffset = focusOffset;
  9364. focusKey = tempKey;
  9365. focusOffset = tempOffset;
  9366. isBackward = false;
  9367. }
  9368. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  9369. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset;
  9370. // If the selection is entirely bound within this node, set the selection
  9371. // and be done.
  9372. if (hasAnchor && hasFocus) {
  9373. selection.removeAllRanges();
  9374. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9375. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9376. return;
  9377. }
  9378. if (!isBackward) {
  9379. // If the anchor is within this node, set the range start.
  9380. if (hasAnchor) {
  9381. selection.removeAllRanges();
  9382. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9383. }
  9384. // If the focus is within this node, we can assume that we have
  9385. // already set the appropriate start range on the selection, and
  9386. // can simply extend the selection.
  9387. if (hasFocus) {
  9388. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9389. }
  9390. } else {
  9391. // If this node has the focus, set the selection range to be a
  9392. // collapsed range beginning here. Later, when we encounter the anchor,
  9393. // we'll use this information to extend the selection.
  9394. if (hasFocus) {
  9395. selection.removeAllRanges();
  9396. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  9397. }
  9398. // If this node has the anchor, we may assume that the correct
  9399. // focus information is already stored on the selection object.
  9400. // We keep track of it, reset the selection range, and extend it
  9401. // back to the focus point.
  9402. if (hasAnchor) {
  9403. var storedFocusNode = selection.focusNode;
  9404. var storedFocusOffset = selection.focusOffset;
  9405. selection.removeAllRanges();
  9406. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  9407. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  9408. }
  9409. }
  9410. }
  9411. /**
  9412. * Extend selection towards focus point.
  9413. */
  9414. function addFocusToSelection(selection, node, offset, selectionState) {
  9415. var activeElement = getActiveElement_1();
  9416. if (selection.extend && containsNode_1(activeElement, node)) {
  9417. // If `extend` is called while another element has focus, an error is
  9418. // thrown. We therefore disable `extend` if the active element is somewhere
  9419. // other than the node we are selecting. This should only occur in Firefox,
  9420. // since it is the only browser to support multiple selections.
  9421. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  9422. // logging to catch bug that is being reported in t16250795
  9423. if (offset > getNodeLength(node)) {
  9424. // the call to 'selection.extend' is about to throw
  9425. DraftJsDebugLogging.logSelectionStateFailure({
  9426. anonymizedDom: getAnonymizedEditorDOM(node),
  9427. extraParams: JSON.stringify({ offset: offset }),
  9428. selectionState: JSON.stringify(selectionState.toJS())
  9429. });
  9430. }
  9431. // logging to catch bug that is being reported in t18110632
  9432. var nodeWasFocus = node === selection.focusNode;
  9433. try {
  9434. selection.extend(node, offset);
  9435. } catch (e) {
  9436. DraftJsDebugLogging.logSelectionStateFailure({
  9437. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  9438. var labels = [];
  9439. if (n === activeElement) {
  9440. labels.push('active element');
  9441. }
  9442. if (n === selection.anchorNode) {
  9443. labels.push('selection anchor node');
  9444. }
  9445. if (n === selection.focusNode) {
  9446. labels.push('selection focus node');
  9447. }
  9448. return labels;
  9449. }),
  9450. extraParams: JSON.stringify({
  9451. activeElementName: activeElement ? activeElement.nodeName : null,
  9452. nodeIsFocus: node === selection.focusNode,
  9453. nodeWasFocus: nodeWasFocus,
  9454. selectionRangeCount: selection.rangeCount,
  9455. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  9456. selectionAnchorOffset: selection.anchorOffset,
  9457. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  9458. selectionFocusOffset: selection.focusOffset,
  9459. message: e ? '' + e : null,
  9460. offset: offset
  9461. }, null, 2),
  9462. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  9463. });
  9464. // allow the error to be thrown -
  9465. // better than continuing in a broken state
  9466. throw e;
  9467. }
  9468. } else {
  9469. // IE doesn't support extend. This will mean no backward selection.
  9470. // Extract the existing selection range and add focus to it.
  9471. // Additionally, clone the selection range. IE11 throws an
  9472. // InvalidStateError when attempting to access selection properties
  9473. // after the range is detached.
  9474. var range = selection.getRangeAt(0);
  9475. range.setEnd(node, offset);
  9476. selection.addRange(range.cloneRange());
  9477. }
  9478. }
  9479. function addPointToSelection(selection, node, offset, selectionState) {
  9480. var range = document.createRange();
  9481. // logging to catch bug that is being reported in t16250795
  9482. if (offset > getNodeLength(node)) {
  9483. // in this case we know that the call to 'range.setStart' is about to throw
  9484. DraftJsDebugLogging.logSelectionStateFailure({
  9485. anonymizedDom: getAnonymizedEditorDOM(node),
  9486. extraParams: JSON.stringify({ offset: offset }),
  9487. selectionState: JSON.stringify(selectionState.toJS())
  9488. });
  9489. }
  9490. range.setStart(node, offset);
  9491. selection.addRange(range);
  9492. }
  9493. var setDraftEditorSelection_1 = setDraftEditorSelection;
  9494. function _classCallCheck$a(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9495. function _possibleConstructorReturn$7(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  9496. function _inherits$7(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9497. /**
  9498. * All leaf nodes in the editor are spans with single text nodes. Leaf
  9499. * elements are styled based on the merging of an optional custom style map
  9500. * and a default style map.
  9501. *
  9502. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  9503. * DOM Selection API. In this way, top-level components can declaratively
  9504. * maintain the selection state.
  9505. */
  9506. var DraftEditorLeaf = function (_React$Component) {
  9507. _inherits$7(DraftEditorLeaf, _React$Component);
  9508. function DraftEditorLeaf() {
  9509. _classCallCheck$a(this, DraftEditorLeaf);
  9510. return _possibleConstructorReturn$7(this, _React$Component.apply(this, arguments));
  9511. }
  9512. DraftEditorLeaf.prototype._setSelection = function _setSelection() {
  9513. var selection = this.props.selection;
  9514. // If selection state is irrelevant to the parent block, no-op.
  9515. if (selection == null || !selection.getHasFocus()) {
  9516. return;
  9517. }
  9518. var _props = this.props,
  9519. block = _props.block,
  9520. start = _props.start,
  9521. text = _props.text;
  9522. var blockKey = block.getKey();
  9523. var end = start + text.length;
  9524. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  9525. return;
  9526. }
  9527. // Determine the appropriate target node for selection. If the child
  9528. // is not a text node, it is a <br /> spacer. In this case, use the
  9529. // <span> itself as the selection target.
  9530. var node = _reactDom_commonjsExternal.require$$3.findDOMNode(this);
  9531. !node ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing node') : invariant_1(false) : void 0;
  9532. var child = node.firstChild;
  9533. !child ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing child') : invariant_1(false) : void 0;
  9534. var targetNode = void 0;
  9535. if (child.nodeType === Node.TEXT_NODE) {
  9536. targetNode = child;
  9537. } else if (child.tagName === 'BR') {
  9538. targetNode = node;
  9539. } else {
  9540. targetNode = child.firstChild;
  9541. !targetNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing targetNode') : invariant_1(false) : void 0;
  9542. }
  9543. setDraftEditorSelection_1(selection, targetNode, blockKey, start, end);
  9544. };
  9545. /**
  9546. * By making individual leaf instances aware of their context within
  9547. * the text of the editor, we can set our selection range more
  9548. * easily than we could in the non-React world.
  9549. *
  9550. * Note that this depends on our maintaining tight control over the
  9551. * DOM structure of the DraftEditor component. If leaves had multiple
  9552. * text nodes, this would be harder.
  9553. */
  9554. DraftEditorLeaf.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9555. var leafNode = _reactDom_commonjsExternal.require$$3.findDOMNode(this.leaf);
  9556. !leafNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing leafNode') : invariant_1(false) : void 0;
  9557. return leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  9558. };
  9559. DraftEditorLeaf.prototype.componentDidUpdate = function componentDidUpdate() {
  9560. this._setSelection();
  9561. };
  9562. DraftEditorLeaf.prototype.componentDidMount = function componentDidMount() {
  9563. this._setSelection();
  9564. };
  9565. DraftEditorLeaf.prototype.render = function render() {
  9566. var _this2 = this;
  9567. var block = this.props.block;
  9568. var text = this.props.text;
  9569. // If the leaf is at the end of its block and ends in a soft newline, append
  9570. // an extra line feed character. Browsers collapse trailing newline
  9571. // characters, which leaves the cursor in the wrong place after a
  9572. // shift+enter. The extra character repairs this.
  9573. if (text.endsWith('\n') && this.props.isLast) {
  9574. text += '\n';
  9575. }
  9576. var _props2 = this.props,
  9577. customStyleMap = _props2.customStyleMap,
  9578. customStyleFn = _props2.customStyleFn,
  9579. offsetKey = _props2.offsetKey,
  9580. styleSet = _props2.styleSet;
  9581. var styleObj = styleSet.reduce(function (map, styleName) {
  9582. var mergedStyles = {};
  9583. var style = customStyleMap[styleName];
  9584. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  9585. // .trim() is necessary for IE9/10/11 and Edge
  9586. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  9587. }
  9588. return objectAssign(map, style, mergedStyles);
  9589. }, {});
  9590. if (customStyleFn) {
  9591. var newStyles = customStyleFn(styleSet, block);
  9592. styleObj = objectAssign(styleObj, newStyles);
  9593. }
  9594. return _reactDom_commonjsExternal.React.createElement(
  9595. 'span',
  9596. {
  9597. 'data-offset-key': offsetKey,
  9598. ref: function ref(_ref) {
  9599. return _this2.leaf = _ref;
  9600. },
  9601. style: styleObj },
  9602. _reactDom_commonjsExternal.React.createElement(
  9603. DraftEditorTextNode_react,
  9604. null,
  9605. text
  9606. )
  9607. );
  9608. };
  9609. return DraftEditorLeaf;
  9610. }(_reactDom_commonjsExternal.React.Component);
  9611. var DraftEditorLeaf_react = DraftEditorLeaf;
  9612. /**
  9613. * Copyright (c) 2013-present, Facebook, Inc.
  9614. * All rights reserved.
  9615. *
  9616. * This source code is licensed under the BSD-style license found in the
  9617. * LICENSE file in the root directory of this source tree. An additional grant
  9618. * of patent rights can be found in the PATENTS file in the same directory.
  9619. *
  9620. * @providesModule DraftOffsetKey
  9621. * @format
  9622. *
  9623. */
  9624. var KEY_DELIMITER = '-';
  9625. var DraftOffsetKey = {
  9626. encode: function encode(blockKey, decoratorKey, leafKey) {
  9627. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  9628. },
  9629. decode: function decode(offsetKey) {
  9630. var _offsetKey$split = offsetKey.split(KEY_DELIMITER),
  9631. blockKey = _offsetKey$split[0],
  9632. decoratorKey = _offsetKey$split[1],
  9633. leafKey = _offsetKey$split[2];
  9634. return {
  9635. blockKey: blockKey,
  9636. decoratorKey: parseInt(decoratorKey, 10),
  9637. leafKey: parseInt(leafKey, 10)
  9638. };
  9639. }
  9640. };
  9641. var DraftOffsetKey_1 = DraftOffsetKey;
  9642. /**
  9643. * Copyright (c) 2013-present, Facebook, Inc.
  9644. *
  9645. * This source code is licensed under the MIT license found in the
  9646. * LICENSE file in the root directory of this source tree.
  9647. *
  9648. */
  9649. /**
  9650. * @param {DOMElement} element
  9651. * @param {DOMDocument} doc
  9652. * @return {boolean}
  9653. */
  9654. function _isViewportScrollElement(element, doc) {
  9655. return !!doc && (element === doc.documentElement || element === doc.body);
  9656. }
  9657. /**
  9658. * Scroll Module. This class contains 4 simple static functions
  9659. * to be used to access Element.scrollTop/scrollLeft properties.
  9660. * To solve the inconsistencies between browsers when either
  9661. * document.body or document.documentElement is supplied,
  9662. * below logic will be used to alleviate the issue:
  9663. *
  9664. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  9665. * get whichever element's 'scroll{Top,Left}' is larger.
  9666. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  9667. * set the 'scroll{Top,Left}' on both elements.
  9668. */
  9669. var Scroll = {
  9670. /**
  9671. * @param {DOMElement} element
  9672. * @return {number}
  9673. */
  9674. getTop: function getTop(element) {
  9675. var doc = element.ownerDocument;
  9676. return _isViewportScrollElement(element, doc) ?
  9677. // In practice, they will either both have the same value,
  9678. // or one will be zero and the other will be the scroll position
  9679. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  9680. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  9681. },
  9682. /**
  9683. * @param {DOMElement} element
  9684. * @param {number} newTop
  9685. */
  9686. setTop: function setTop(element, newTop) {
  9687. var doc = element.ownerDocument;
  9688. if (_isViewportScrollElement(element, doc)) {
  9689. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  9690. } else {
  9691. element.scrollTop = newTop;
  9692. }
  9693. },
  9694. /**
  9695. * @param {DOMElement} element
  9696. * @return {number}
  9697. */
  9698. getLeft: function getLeft(element) {
  9699. var doc = element.ownerDocument;
  9700. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  9701. },
  9702. /**
  9703. * @param {DOMElement} element
  9704. * @param {number} newLeft
  9705. */
  9706. setLeft: function setLeft(element, newLeft) {
  9707. var doc = element.ownerDocument;
  9708. if (_isViewportScrollElement(element, doc)) {
  9709. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  9710. } else {
  9711. element.scrollLeft = newLeft;
  9712. }
  9713. }
  9714. };
  9715. var Scroll_1 = Scroll;
  9716. /**
  9717. * Copyright (c) 2013-present, Facebook, Inc.
  9718. *
  9719. * This source code is licensed under the MIT license found in the
  9720. * LICENSE file in the root directory of this source tree.
  9721. *
  9722. * @typechecks
  9723. */
  9724. var _hyphenPattern = /-(.)/g;
  9725. /**
  9726. * Camelcases a hyphenated string, for example:
  9727. *
  9728. * > camelize('background-color')
  9729. * < "backgroundColor"
  9730. *
  9731. * @param {string} string
  9732. * @return {string}
  9733. */
  9734. function camelize(string) {
  9735. return string.replace(_hyphenPattern, function (_, character) {
  9736. return character.toUpperCase();
  9737. });
  9738. }
  9739. var camelize_1 = camelize;
  9740. /**
  9741. * Copyright (c) 2013-present, Facebook, Inc.
  9742. *
  9743. * This source code is licensed under the MIT license found in the
  9744. * LICENSE file in the root directory of this source tree.
  9745. *
  9746. * @typechecks
  9747. */
  9748. var _uppercasePattern = /([A-Z])/g;
  9749. /**
  9750. * Hyphenates a camelcased string, for example:
  9751. *
  9752. * > hyphenate('backgroundColor')
  9753. * < "background-color"
  9754. *
  9755. * For CSS style names, use `hyphenateStyleName` instead which works properly
  9756. * with all vendor prefixes, including `ms`.
  9757. *
  9758. * @param {string} string
  9759. * @return {string}
  9760. */
  9761. function hyphenate(string) {
  9762. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  9763. }
  9764. var hyphenate_1 = hyphenate;
  9765. /**
  9766. * Copyright (c) 2013-present, Facebook, Inc.
  9767. *
  9768. * This source code is licensed under the MIT license found in the
  9769. * LICENSE file in the root directory of this source tree.
  9770. *
  9771. * @typechecks
  9772. */
  9773. function asString(value) /*?string*/{
  9774. return value == null ? value : String(value);
  9775. }
  9776. function getStyleProperty( /*DOMNode*/node, /*string*/name) /*?string*/{
  9777. var computedStyle = void 0;
  9778. // W3C Standard
  9779. if (window.getComputedStyle) {
  9780. // In certain cases such as within an iframe in FF3, this returns null.
  9781. computedStyle = window.getComputedStyle(node, null);
  9782. if (computedStyle) {
  9783. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9784. }
  9785. }
  9786. // Safari
  9787. if (document.defaultView && document.defaultView.getComputedStyle) {
  9788. computedStyle = document.defaultView.getComputedStyle(node, null);
  9789. // A Safari bug causes this to return null for `display: none` elements.
  9790. if (computedStyle) {
  9791. return asString(computedStyle.getPropertyValue(hyphenate_1(name)));
  9792. }
  9793. if (name === 'display') {
  9794. return 'none';
  9795. }
  9796. }
  9797. // Internet Explorer
  9798. if (node.currentStyle) {
  9799. if (name === 'float') {
  9800. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  9801. }
  9802. return asString(node.currentStyle[camelize_1(name)]);
  9803. }
  9804. return asString(node.style && node.style[camelize_1(name)]);
  9805. }
  9806. var getStyleProperty_1 = getStyleProperty;
  9807. /**
  9808. * Copyright (c) 2013-present, Facebook, Inc.
  9809. *
  9810. * This source code is licensed under the MIT license found in the
  9811. * LICENSE file in the root directory of this source tree.
  9812. *
  9813. * @typechecks
  9814. */
  9815. /**
  9816. * @param {DOMNode} element [description]
  9817. * @param {string} name Overflow style property name.
  9818. * @return {boolean} True if the supplied ndoe is scrollable.
  9819. */
  9820. function _isNodeScrollable(element, name) {
  9821. var overflow = Style.get(element, name);
  9822. return overflow === 'auto' || overflow === 'scroll';
  9823. }
  9824. /**
  9825. * Utilities for querying and mutating style properties.
  9826. */
  9827. var Style = {
  9828. /**
  9829. * Gets the style property for the supplied node. This will return either the
  9830. * computed style, if available, or the declared style.
  9831. *
  9832. * @param {DOMNode} node
  9833. * @param {string} name Style property name.
  9834. * @return {?string} Style property value.
  9835. */
  9836. get: getStyleProperty_1,
  9837. /**
  9838. * Determines the nearest ancestor of a node that is scrollable.
  9839. *
  9840. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  9841. *
  9842. * @param {?DOMNode} node Node from which to start searching.
  9843. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  9844. */
  9845. getScrollParent: function getScrollParent(node) {
  9846. if (!node) {
  9847. return null;
  9848. }
  9849. var ownerDocument = node.ownerDocument;
  9850. while (node && node !== ownerDocument.body) {
  9851. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  9852. return node;
  9853. }
  9854. node = node.parentNode;
  9855. }
  9856. return ownerDocument.defaultView || ownerDocument.parentWindow;
  9857. }
  9858. };
  9859. var Style_1 = Style;
  9860. /**
  9861. * Copyright (c) 2013-present, Facebook, Inc.
  9862. *
  9863. * This source code is licensed under the MIT license found in the
  9864. * LICENSE file in the root directory of this source tree.
  9865. *
  9866. * @typechecks
  9867. */
  9868. /**
  9869. * Gets an element's bounding rect in pixels relative to the viewport.
  9870. *
  9871. * @param {DOMElement} elem
  9872. * @return {object}
  9873. */
  9874. function getElementRect(elem) {
  9875. var docElem = elem.ownerDocument.documentElement;
  9876. // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  9877. // IE9- will throw if the element is not in the document.
  9878. if (!('getBoundingClientRect' in elem) || !containsNode_1(docElem, elem)) {
  9879. return {
  9880. left: 0,
  9881. right: 0,
  9882. top: 0,
  9883. bottom: 0
  9884. };
  9885. }
  9886. // Subtracts clientTop/Left because IE8- added a 2px border to the
  9887. // <html> element (see http://fburl.com/1493213). IE 7 in
  9888. // Quicksmode does not report clientLeft/clientTop so there
  9889. // will be an unaccounted offset of 2px when in quirksmode
  9890. var rect = elem.getBoundingClientRect();
  9891. return {
  9892. left: Math.round(rect.left) - docElem.clientLeft,
  9893. right: Math.round(rect.right) - docElem.clientLeft,
  9894. top: Math.round(rect.top) - docElem.clientTop,
  9895. bottom: Math.round(rect.bottom) - docElem.clientTop
  9896. };
  9897. }
  9898. var getElementRect_1 = getElementRect;
  9899. /**
  9900. * Copyright (c) 2013-present, Facebook, Inc.
  9901. *
  9902. * This source code is licensed under the MIT license found in the
  9903. * LICENSE file in the root directory of this source tree.
  9904. *
  9905. * @typechecks
  9906. */
  9907. /**
  9908. * Gets an element's position in pixels relative to the viewport. The returned
  9909. * object represents the position of the element's top left corner.
  9910. *
  9911. * @param {DOMElement} element
  9912. * @return {object}
  9913. */
  9914. function getElementPosition(element) {
  9915. var rect = getElementRect_1(element);
  9916. return {
  9917. x: rect.left,
  9918. y: rect.top,
  9919. width: rect.right - rect.left,
  9920. height: rect.bottom - rect.top
  9921. };
  9922. }
  9923. var getElementPosition_1 = getElementPosition;
  9924. /**
  9925. * Copyright (c) 2013-present, Facebook, Inc.
  9926. *
  9927. * This source code is licensed under the MIT license found in the
  9928. * LICENSE file in the root directory of this source tree.
  9929. *
  9930. * @typechecks
  9931. */
  9932. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  9933. /**
  9934. * Gets the element with the document scroll properties such as `scrollLeft` and
  9935. * `scrollHeight`. This may differ across different browsers.
  9936. *
  9937. * NOTE: The return value can be null if the DOM is not yet ready.
  9938. *
  9939. * @param {?DOMDocument} doc Defaults to current document.
  9940. * @return {?DOMElement}
  9941. */
  9942. function getDocumentScrollElement(doc) {
  9943. doc = doc || document;
  9944. if (doc.scrollingElement) {
  9945. return doc.scrollingElement;
  9946. }
  9947. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  9948. }
  9949. var getDocumentScrollElement_1 = getDocumentScrollElement;
  9950. /**
  9951. * Copyright (c) 2013-present, Facebook, Inc.
  9952. *
  9953. * This source code is licensed under the MIT license found in the
  9954. * LICENSE file in the root directory of this source tree.
  9955. *
  9956. * @typechecks
  9957. */
  9958. /**
  9959. * Gets the scroll position of the supplied element or window.
  9960. *
  9961. * The return values are unbounded, unlike `getScrollPosition`. This means they
  9962. * may be negative or exceed the element boundaries (which is possible using
  9963. * inertial scrolling).
  9964. *
  9965. * @param {DOMWindow|DOMElement} scrollable
  9966. * @return {object} Map with `x` and `y` keys.
  9967. */
  9968. function getUnboundedScrollPosition(scrollable) {
  9969. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9970. return {
  9971. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  9972. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  9973. };
  9974. }
  9975. return {
  9976. x: scrollable.scrollLeft,
  9977. y: scrollable.scrollTop
  9978. };
  9979. }
  9980. var getUnboundedScrollPosition_1 = getUnboundedScrollPosition;
  9981. /**
  9982. * Gets the scroll position of the supplied element or window.
  9983. *
  9984. * The return values are bounded. This means that if the scroll position is
  9985. * negative or exceeds the element boundaries (which is possible using inertial
  9986. * scrolling), you will get zero or the maximum scroll position, respectively.
  9987. *
  9988. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  9989. *
  9990. * @param {DOMWindow|DOMElement} scrollable
  9991. * @return {object} Map with `x` and `y` keys.
  9992. */
  9993. function getScrollPosition(scrollable) {
  9994. var documentScrollElement = getDocumentScrollElement_1(scrollable.ownerDocument || scrollable.document);
  9995. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  9996. scrollable = documentScrollElement;
  9997. }
  9998. var scrollPosition = getUnboundedScrollPosition_1(scrollable);
  9999. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  10000. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  10001. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  10002. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  10003. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  10004. return scrollPosition;
  10005. }
  10006. var getScrollPosition_1 = getScrollPosition;
  10007. function getViewportWidth() {
  10008. var width = void 0;
  10009. if (document.documentElement) {
  10010. width = document.documentElement.clientWidth;
  10011. }
  10012. if (!width && document.body) {
  10013. width = document.body.clientWidth;
  10014. }
  10015. return width || 0;
  10016. } /**
  10017. * Copyright (c) 2013-present, Facebook, Inc.
  10018. *
  10019. * This source code is licensed under the MIT license found in the
  10020. * LICENSE file in the root directory of this source tree.
  10021. *
  10022. *
  10023. * @typechecks
  10024. */
  10025. function getViewportHeight() {
  10026. var height = void 0;
  10027. if (document.documentElement) {
  10028. height = document.documentElement.clientHeight;
  10029. }
  10030. if (!height && document.body) {
  10031. height = document.body.clientHeight;
  10032. }
  10033. return height || 0;
  10034. }
  10035. /**
  10036. * Gets the viewport dimensions including any scrollbars.
  10037. */
  10038. function getViewportDimensions() {
  10039. return {
  10040. width: window.innerWidth || getViewportWidth(),
  10041. height: window.innerHeight || getViewportHeight()
  10042. };
  10043. }
  10044. /**
  10045. * Gets the viewport dimensions excluding any scrollbars.
  10046. */
  10047. getViewportDimensions.withoutScrollbars = function () {
  10048. return {
  10049. width: getViewportWidth(),
  10050. height: getViewportHeight()
  10051. };
  10052. };
  10053. var getViewportDimensions_1 = getViewportDimensions;
  10054. var _extends$2 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  10055. function _classCallCheck$b(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10056. function _possibleConstructorReturn$8(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10057. function _inherits$8(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10058. var SCROLL_BUFFER = 10;
  10059. /**
  10060. * Return whether a block overlaps with either edge of the `SelectionState`.
  10061. */
  10062. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10063. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10064. };
  10065. /**
  10066. * The default block renderer for a `DraftEditor` component.
  10067. *
  10068. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  10069. * appropriate decorator and inline style components.
  10070. */
  10071. var DraftEditorBlock = function (_React$Component) {
  10072. _inherits$8(DraftEditorBlock, _React$Component);
  10073. function DraftEditorBlock() {
  10074. _classCallCheck$b(this, DraftEditorBlock);
  10075. return _possibleConstructorReturn$8(this, _React$Component.apply(this, arguments));
  10076. }
  10077. DraftEditorBlock.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10078. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  10079. };
  10080. /**
  10081. * When a block is mounted and overlaps the selection state, we need to make
  10082. * sure that the cursor is visible to match native behavior. This may not
  10083. * be the case if the user has pressed `RETURN` or pasted some content, since
  10084. * programatically creating these new blocks and setting the DOM selection
  10085. * will miss out on the browser natively scrolling to that position.
  10086. *
  10087. * To replicate native behavior, if the block overlaps the selection state
  10088. * on mount, force the scroll position. Check the scroll state of the scroll
  10089. * parent, and adjust it to align the entire block to the bottom of the
  10090. * scroll parent.
  10091. */
  10092. DraftEditorBlock.prototype.componentDidMount = function componentDidMount() {
  10093. var selection = this.props.selection;
  10094. var endKey = selection.getEndKey();
  10095. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10096. return;
  10097. }
  10098. var blockNode = _reactDom_commonjsExternal.require$$3.findDOMNode(this);
  10099. var scrollParent = Style_1.getScrollParent(blockNode);
  10100. var scrollPosition = getScrollPosition_1(scrollParent);
  10101. var scrollDelta = void 0;
  10102. if (scrollParent === window) {
  10103. var nodePosition = getElementPosition_1(blockNode);
  10104. var nodeBottom = nodePosition.y + nodePosition.height;
  10105. var viewportHeight = getViewportDimensions_1().height;
  10106. scrollDelta = nodeBottom - viewportHeight;
  10107. if (scrollDelta > 0) {
  10108. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10109. }
  10110. } else {
  10111. !(blockNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'blockNode is not an HTMLElement') : invariant_1(false) : void 0;
  10112. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  10113. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10114. scrollDelta = blockBottom - scrollBottom;
  10115. if (scrollDelta > 0) {
  10116. Scroll_1.setTop(scrollParent, Scroll_1.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10117. }
  10118. }
  10119. };
  10120. DraftEditorBlock.prototype._renderChildren = function _renderChildren() {
  10121. var _this2 = this;
  10122. var block = this.props.block;
  10123. var blockKey = block.getKey();
  10124. var text = block.getText();
  10125. var lastLeafSet = this.props.tree.size - 1;
  10126. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  10127. return this.props.tree.map(function (leafSet, ii) {
  10128. var leavesForLeafSet = leafSet.get('leaves');
  10129. var lastLeaf = leavesForLeafSet.size - 1;
  10130. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  10131. var offsetKey = DraftOffsetKey_1.encode(blockKey, ii, jj);
  10132. var start = leaf.get('start');
  10133. var end = leaf.get('end');
  10134. return _reactDom_commonjsExternal.React.createElement(DraftEditorLeaf_react, {
  10135. key: offsetKey,
  10136. offsetKey: offsetKey,
  10137. block: block,
  10138. start: start,
  10139. selection: hasSelection ? _this2.props.selection : null,
  10140. forceSelection: _this2.props.forceSelection,
  10141. text: text.slice(start, end),
  10142. styleSet: block.getInlineStyleAt(start),
  10143. customStyleMap: _this2.props.customStyleMap,
  10144. customStyleFn: _this2.props.customStyleFn,
  10145. isLast: ii === lastLeafSet && jj === lastLeaf
  10146. });
  10147. }).toArray();
  10148. var decoratorKey = leafSet.get('decoratorKey');
  10149. if (decoratorKey == null) {
  10150. return leaves;
  10151. }
  10152. if (!_this2.props.decorator) {
  10153. return leaves;
  10154. }
  10155. var decorator = nullthrows_1(_this2.props.decorator);
  10156. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10157. if (!DecoratorComponent) {
  10158. return leaves;
  10159. }
  10160. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10161. var decoratorOffsetKey = DraftOffsetKey_1.encode(blockKey, ii, 0);
  10162. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end'));
  10163. // Resetting dir to the same value on a child node makes Chrome/Firefox
  10164. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10165. var dir = UnicodeBidiDirection_1.getHTMLDirIfDifferent(UnicodeBidi_1.getDirection(decoratedText), _this2.props.direction);
  10166. return _reactDom_commonjsExternal.React.createElement(
  10167. DecoratorComponent,
  10168. _extends$2({}, decoratorProps, {
  10169. contentState: _this2.props.contentState,
  10170. decoratedText: decoratedText,
  10171. dir: dir,
  10172. key: decoratorOffsetKey,
  10173. entityKey: block.getEntityAt(leafSet.get('start')),
  10174. offsetKey: decoratorOffsetKey }),
  10175. leaves
  10176. );
  10177. }).toArray();
  10178. };
  10179. DraftEditorBlock.prototype.render = function render() {
  10180. var _props = this.props,
  10181. direction = _props.direction,
  10182. offsetKey = _props.offsetKey;
  10183. var className = cx_1({
  10184. 'public/DraftStyleDefault/block': true,
  10185. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10186. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10187. });
  10188. return _reactDom_commonjsExternal.React.createElement(
  10189. 'div',
  10190. { 'data-offset-key': offsetKey, className: className },
  10191. this._renderChildren()
  10192. );
  10193. };
  10194. return DraftEditorBlock;
  10195. }(_reactDom_commonjsExternal.React.Component);
  10196. var DraftEditorBlock_react = DraftEditorBlock;
  10197. /**
  10198. * Copyright (c) 2013-present, Facebook, Inc.
  10199. *
  10200. * This source code is licensed under the MIT license found in the
  10201. * LICENSE file in the root directory of this source tree.
  10202. *
  10203. * @typechecks static-only
  10204. */
  10205. /**
  10206. * Combines multiple className strings into one.
  10207. * http://jsperf.com/joinclasses-args-vs-array
  10208. *
  10209. * @param {...?string} className
  10210. * @return {string}
  10211. */
  10212. function joinClasses(className /*, ... */) {
  10213. if (!className) {
  10214. className = '';
  10215. }
  10216. var nextClass = void 0;
  10217. var argLength = arguments.length;
  10218. if (argLength > 1) {
  10219. for (var ii = 1; ii < argLength; ii++) {
  10220. nextClass = arguments[ii];
  10221. if (nextClass) {
  10222. className = (className ? className + ' ' : '') + nextClass;
  10223. }
  10224. }
  10225. }
  10226. return className;
  10227. }
  10228. var joinClasses_1 = joinClasses;
  10229. var _extends$3 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  10230. function _classCallCheck$c(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10231. function _possibleConstructorReturn$9(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10232. function _inherits$9(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10233. /**
  10234. * Provide default styling for list items. This way, lists will be styled with
  10235. * proper counters and indentation even if the caller does not specify
  10236. * their own styling at all. If more than five levels of nesting are needed,
  10237. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  10238. */
  10239. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  10240. return cx_1({
  10241. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  10242. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  10243. 'public/DraftStyleDefault/reset': shouldResetCount,
  10244. 'public/DraftStyleDefault/depth0': depth === 0,
  10245. 'public/DraftStyleDefault/depth1': depth === 1,
  10246. 'public/DraftStyleDefault/depth2': depth === 2,
  10247. 'public/DraftStyleDefault/depth3': depth === 3,
  10248. 'public/DraftStyleDefault/depth4': depth === 4,
  10249. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  10250. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  10251. });
  10252. };
  10253. /**
  10254. * `DraftEditorContents` is the container component for all block components
  10255. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  10256. * re-rendering blocks whenever possible.
  10257. *
  10258. * This component is separate from `DraftEditor` because certain props
  10259. * (for instance, ARIA props) must be allowed to update without affecting
  10260. * the contents of the editor.
  10261. */
  10262. var DraftEditorContents = function (_React$Component) {
  10263. _inherits$9(DraftEditorContents, _React$Component);
  10264. function DraftEditorContents() {
  10265. _classCallCheck$c(this, DraftEditorContents);
  10266. return _possibleConstructorReturn$9(this, _React$Component.apply(this, arguments));
  10267. }
  10268. DraftEditorContents.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10269. var prevEditorState = this.props.editorState;
  10270. var nextEditorState = nextProps.editorState;
  10271. var prevDirectionMap = prevEditorState.getDirectionMap();
  10272. var nextDirectionMap = nextEditorState.getDirectionMap();
  10273. // Text direction has changed for one or more blocks. We must re-render.
  10274. if (prevDirectionMap !== nextDirectionMap) {
  10275. return true;
  10276. }
  10277. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  10278. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  10279. if (didHaveFocus !== nowHasFocus) {
  10280. return true;
  10281. }
  10282. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  10283. var wasComposing = prevEditorState.isInCompositionMode();
  10284. var nowComposing = nextEditorState.isInCompositionMode();
  10285. // If the state is unchanged or we're currently rendering a natively
  10286. // rendered state, there's nothing new to be done.
  10287. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  10288. return false;
  10289. }
  10290. var prevContent = prevEditorState.getCurrentContent();
  10291. var nextContent = nextEditorState.getCurrentContent();
  10292. var prevDecorator = prevEditorState.getDecorator();
  10293. var nextDecorator = nextEditorState.getDecorator();
  10294. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  10295. };
  10296. DraftEditorContents.prototype.render = function render() {
  10297. var _props = this.props,
  10298. blockRenderMap = _props.blockRenderMap,
  10299. blockRendererFn = _props.blockRendererFn,
  10300. blockStyleFn = _props.blockStyleFn,
  10301. customStyleMap = _props.customStyleMap,
  10302. customStyleFn = _props.customStyleFn,
  10303. editorState = _props.editorState,
  10304. editorKey = _props.editorKey,
  10305. textDirectionality = _props.textDirectionality;
  10306. var content = editorState.getCurrentContent();
  10307. var selection = editorState.getSelection();
  10308. var forceSelection = editorState.mustForceSelection();
  10309. var decorator = editorState.getDecorator();
  10310. var directionMap = nullthrows_1(editorState.getDirectionMap());
  10311. var blocksAsArray = content.getBlocksAsArray();
  10312. var processedBlocks = [];
  10313. var currentDepth = null;
  10314. var lastWrapperTemplate = null;
  10315. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  10316. var _block = blocksAsArray[ii];
  10317. var key = _block.getKey();
  10318. var blockType = _block.getType();
  10319. var customRenderer = blockRendererFn(_block);
  10320. var CustomComponent = void 0,
  10321. customProps = void 0,
  10322. customEditable = void 0;
  10323. if (customRenderer) {
  10324. CustomComponent = customRenderer.component;
  10325. customProps = customRenderer.props;
  10326. customEditable = customRenderer.editable;
  10327. }
  10328. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  10329. var offsetKey = DraftOffsetKey_1.encode(key, 0, 0);
  10330. var componentProps = {
  10331. contentState: content,
  10332. block: _block,
  10333. blockProps: customProps,
  10334. blockStyleFn: blockStyleFn,
  10335. customStyleMap: customStyleMap,
  10336. customStyleFn: customStyleFn,
  10337. decorator: decorator,
  10338. direction: direction,
  10339. forceSelection: forceSelection,
  10340. key: key,
  10341. offsetKey: offsetKey,
  10342. selection: selection,
  10343. tree: editorState.getBlockTree(key)
  10344. };
  10345. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  10346. var wrapperTemplate = configForType.wrapper;
  10347. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10348. var depth = _block.getDepth();
  10349. var className = '';
  10350. if (blockStyleFn) {
  10351. className = blockStyleFn(_block);
  10352. }
  10353. // List items are special snowflakes, since we handle nesting and
  10354. // counters manually.
  10355. if (Element === 'li') {
  10356. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  10357. className = joinClasses_1(className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  10358. }
  10359. var Component = CustomComponent || DraftEditorBlock_react;
  10360. var childProps = {
  10361. className: className,
  10362. 'data-block': true,
  10363. 'data-editor': editorKey,
  10364. 'data-offset-key': offsetKey,
  10365. key: key
  10366. };
  10367. if (customEditable !== undefined) {
  10368. childProps = _extends$3({}, childProps, {
  10369. contentEditable: customEditable,
  10370. suppressContentEditableWarning: true
  10371. });
  10372. }
  10373. var child = _reactDom_commonjsExternal.React.createElement(Element, childProps, _reactDom_commonjsExternal.React.createElement(Component, componentProps));
  10374. processedBlocks.push({
  10375. block: child,
  10376. wrapperTemplate: wrapperTemplate,
  10377. key: key,
  10378. offsetKey: offsetKey
  10379. });
  10380. if (wrapperTemplate) {
  10381. currentDepth = _block.getDepth();
  10382. } else {
  10383. currentDepth = null;
  10384. }
  10385. lastWrapperTemplate = wrapperTemplate;
  10386. }
  10387. // Group contiguous runs of blocks that have the same wrapperTemplate
  10388. var outputBlocks = [];
  10389. for (var _ii = 0; _ii < processedBlocks.length;) {
  10390. var info = processedBlocks[_ii];
  10391. if (info.wrapperTemplate) {
  10392. var blocks = [];
  10393. do {
  10394. blocks.push(processedBlocks[_ii].block);
  10395. _ii++;
  10396. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  10397. var wrapperElement = _reactDom_commonjsExternal.React.cloneElement(info.wrapperTemplate, {
  10398. key: info.key + '-wrap',
  10399. 'data-offset-key': info.offsetKey
  10400. }, blocks);
  10401. outputBlocks.push(wrapperElement);
  10402. } else {
  10403. outputBlocks.push(info.block);
  10404. _ii++;
  10405. }
  10406. }
  10407. return _reactDom_commonjsExternal.React.createElement(
  10408. 'div',
  10409. { 'data-contents': 'true' },
  10410. outputBlocks
  10411. );
  10412. };
  10413. return DraftEditorContents;
  10414. }(_reactDom_commonjsExternal.React.Component);
  10415. var DraftEditorContentsCore_react = DraftEditorContents;
  10416. var DraftEditorContents_react = DraftEditorContentsCore_react;
  10417. /**
  10418. * Copyright (c) 2013-present, Facebook, Inc.
  10419. *
  10420. * This source code is licensed under the MIT license found in the
  10421. * LICENSE file in the root directory of this source tree.
  10422. *
  10423. */
  10424. var PhotosMimeType = {
  10425. isImage: function isImage(mimeString) {
  10426. return getParts(mimeString)[0] === 'image';
  10427. },
  10428. isJpeg: function isJpeg(mimeString) {
  10429. var parts = getParts(mimeString);
  10430. return PhotosMimeType.isImage(mimeString) && (
  10431. // see http://fburl.com/10972194
  10432. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  10433. }
  10434. };
  10435. function getParts(mimeString) {
  10436. return mimeString.split('/');
  10437. }
  10438. var PhotosMimeType_1 = PhotosMimeType;
  10439. /**
  10440. * Copyright (c) 2013-present, Facebook, Inc.
  10441. *
  10442. * This source code is licensed under the MIT license found in the
  10443. * LICENSE file in the root directory of this source tree.
  10444. *
  10445. * @typechecks
  10446. */
  10447. /**
  10448. * Convert array-like objects to arrays.
  10449. *
  10450. * This API assumes the caller knows the contents of the data type. For less
  10451. * well defined inputs use createArrayFromMixed.
  10452. *
  10453. * @param {object|function|filelist} obj
  10454. * @return {array}
  10455. */
  10456. function toArray(obj) {
  10457. var length = obj.length;
  10458. // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  10459. // in old versions of Safari).
  10460. !(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Array-like object expected') : invariant_1(false) : void 0;
  10461. !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object needs a length property') : invariant_1(false) : void 0;
  10462. !(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object should have keys for indices') : invariant_1(false) : void 0;
  10463. !(typeof obj.callee !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant_1(false) : void 0;
  10464. // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  10465. // without method will throw during the slice call and skip straight to the
  10466. // fallback.
  10467. if (obj.hasOwnProperty) {
  10468. try {
  10469. return Array.prototype.slice.call(obj);
  10470. } catch (e) {
  10471. // IE < 9 does not support Array#slice on collections objects
  10472. }
  10473. }
  10474. // Fall back to copying key by key. This assumes all keys have a value,
  10475. // so will not preserve sparsely populated inputs.
  10476. var ret = Array(length);
  10477. for (var ii = 0; ii < length; ii++) {
  10478. ret[ii] = obj[ii];
  10479. }
  10480. return ret;
  10481. }
  10482. /**
  10483. * Perform a heuristic test to determine if an object is "array-like".
  10484. *
  10485. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  10486. * Joshu replied: "Mu."
  10487. *
  10488. * This function determines if its argument has "array nature": it returns
  10489. * true if the argument is an actual array, an `arguments' object, or an
  10490. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  10491. *
  10492. * It will return false for other array-like objects like Filelist.
  10493. *
  10494. * @param {*} obj
  10495. * @return {boolean}
  10496. */
  10497. function hasArrayNature(obj) {
  10498. return (
  10499. // not null/false
  10500. !!obj && (
  10501. // arrays are objects, NodeLists are functions in Safari
  10502. typeof obj == 'object' || typeof obj == 'function') &&
  10503. // quacks like an array
  10504. 'length' in obj &&
  10505. // not window
  10506. !('setInterval' in obj) &&
  10507. // no DOM node should be considered an array-like
  10508. // a 'select' element has 'length' and 'item' properties on IE8
  10509. typeof obj.nodeType != 'number' && (
  10510. // a real array
  10511. Array.isArray(obj) ||
  10512. // arguments
  10513. 'callee' in obj ||
  10514. // HTMLCollection/NodeList
  10515. 'item' in obj)
  10516. );
  10517. }
  10518. /**
  10519. * Ensure that the argument is an array by wrapping it in an array if it is not.
  10520. * Creates a copy of the argument if it is already an array.
  10521. *
  10522. * This is mostly useful idiomatically:
  10523. *
  10524. * var createArrayFromMixed = require('createArrayFromMixed');
  10525. *
  10526. * function takesOneOrMoreThings(things) {
  10527. * things = createArrayFromMixed(things);
  10528. * ...
  10529. * }
  10530. *
  10531. * This allows you to treat `things' as an array, but accept scalars in the API.
  10532. *
  10533. * If you need to convert an array-like object, like `arguments`, into an array
  10534. * use toArray instead.
  10535. *
  10536. * @param {*} obj
  10537. * @return {array}
  10538. */
  10539. function createArrayFromMixed(obj) {
  10540. if (!hasArrayNature(obj)) {
  10541. return [obj];
  10542. } else if (Array.isArray(obj)) {
  10543. return obj.slice();
  10544. } else {
  10545. return toArray(obj);
  10546. }
  10547. }
  10548. var createArrayFromMixed_1 = createArrayFromMixed;
  10549. function _classCallCheck$d(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10550. /**
  10551. * Copyright (c) 2013-present, Facebook, Inc.
  10552. *
  10553. * This source code is licensed under the MIT license found in the
  10554. * LICENSE file in the root directory of this source tree.
  10555. *
  10556. * @typechecks
  10557. */
  10558. var CR_LF_REGEX = new RegExp('\r\n', 'g');
  10559. var LF_ONLY = '\n';
  10560. var RICH_TEXT_TYPES = {
  10561. 'text/rtf': 1,
  10562. 'text/html': 1
  10563. };
  10564. /**
  10565. * If DataTransferItem is a file then return the Blob of data.
  10566. *
  10567. * @param {object} item
  10568. * @return {?blob}
  10569. */
  10570. function getFileFromDataTransfer(item) {
  10571. if (item.kind == 'file') {
  10572. return item.getAsFile();
  10573. }
  10574. }
  10575. var DataTransfer = function () {
  10576. /**
  10577. * @param {object} data
  10578. */
  10579. function DataTransfer(data) {
  10580. _classCallCheck$d(this, DataTransfer);
  10581. this.data = data;
  10582. // Types could be DOMStringList or array
  10583. this.types = data.types ? createArrayFromMixed_1(data.types) : [];
  10584. }
  10585. /**
  10586. * Is this likely to be a rich text data transfer?
  10587. *
  10588. * @return {boolean}
  10589. */
  10590. DataTransfer.prototype.isRichText = function isRichText() {
  10591. // If HTML is available, treat this data as rich text. This way, we avoid
  10592. // using a pasted image if it is packaged with HTML -- this may occur with
  10593. // pastes from MS Word, for example. However this is only rich text if
  10594. // there's accompanying text.
  10595. if (this.getHTML() && this.getText()) {
  10596. return true;
  10597. }
  10598. // When an image is copied from a preview window, you end up with two
  10599. // DataTransferItems one of which is a file's metadata as text. Skip those.
  10600. if (this.isImage()) {
  10601. return false;
  10602. }
  10603. return this.types.some(function (type) {
  10604. return RICH_TEXT_TYPES[type];
  10605. });
  10606. };
  10607. /**
  10608. * Get raw text.
  10609. *
  10610. * @return {?string}
  10611. */
  10612. DataTransfer.prototype.getText = function getText() {
  10613. var text;
  10614. if (this.data.getData) {
  10615. if (!this.types.length) {
  10616. text = this.data.getData('Text');
  10617. } else if (this.types.indexOf('text/plain') != -1) {
  10618. text = this.data.getData('text/plain');
  10619. }
  10620. }
  10621. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  10622. };
  10623. /**
  10624. * Get HTML paste data
  10625. *
  10626. * @return {?string}
  10627. */
  10628. DataTransfer.prototype.getHTML = function getHTML() {
  10629. if (this.data.getData) {
  10630. if (!this.types.length) {
  10631. return this.data.getData('Text');
  10632. } else if (this.types.indexOf('text/html') != -1) {
  10633. return this.data.getData('text/html');
  10634. }
  10635. }
  10636. };
  10637. /**
  10638. * Is this a link data transfer?
  10639. *
  10640. * @return {boolean}
  10641. */
  10642. DataTransfer.prototype.isLink = function isLink() {
  10643. return this.types.some(function (type) {
  10644. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  10645. });
  10646. };
  10647. /**
  10648. * Get a link url.
  10649. *
  10650. * @return {?string}
  10651. */
  10652. DataTransfer.prototype.getLink = function getLink() {
  10653. if (this.data.getData) {
  10654. if (this.types.indexOf('text/x-moz-url') != -1) {
  10655. var url = this.data.getData('text/x-moz-url').split('\n');
  10656. return url[0];
  10657. }
  10658. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  10659. }
  10660. return null;
  10661. };
  10662. /**
  10663. * Is this an image data transfer?
  10664. *
  10665. * @return {boolean}
  10666. */
  10667. DataTransfer.prototype.isImage = function isImage() {
  10668. var isImage = this.types.some(function (type) {
  10669. // Firefox will have a type of application/x-moz-file for images during
  10670. // dragging
  10671. return type.indexOf('application/x-moz-file') != -1;
  10672. });
  10673. if (isImage) {
  10674. return true;
  10675. }
  10676. var items = this.getFiles();
  10677. for (var i = 0; i < items.length; i++) {
  10678. var type = items[i].type;
  10679. if (!PhotosMimeType_1.isImage(type)) {
  10680. return false;
  10681. }
  10682. }
  10683. return true;
  10684. };
  10685. DataTransfer.prototype.getCount = function getCount() {
  10686. if (this.data.hasOwnProperty('items')) {
  10687. return this.data.items.length;
  10688. } else if (this.data.hasOwnProperty('mozItemCount')) {
  10689. return this.data.mozItemCount;
  10690. } else if (this.data.files) {
  10691. return this.data.files.length;
  10692. }
  10693. return null;
  10694. };
  10695. /**
  10696. * Get files.
  10697. *
  10698. * @return {array}
  10699. */
  10700. DataTransfer.prototype.getFiles = function getFiles() {
  10701. if (this.data.items) {
  10702. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  10703. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction_1.thatReturnsArgument);
  10704. } else if (this.data.files) {
  10705. return Array.prototype.slice.call(this.data.files);
  10706. } else {
  10707. return [];
  10708. }
  10709. };
  10710. /**
  10711. * Are there any files to fetch?
  10712. *
  10713. * @return {boolean}
  10714. */
  10715. DataTransfer.prototype.hasFiles = function hasFiles() {
  10716. return this.getFiles().length > 0;
  10717. };
  10718. return DataTransfer;
  10719. }();
  10720. var DataTransfer_1 = DataTransfer;
  10721. /**
  10722. * Copyright (c) 2013-present, Facebook, Inc.
  10723. * All rights reserved.
  10724. *
  10725. * This source code is licensed under the BSD-style license found in the
  10726. * LICENSE file in the root directory of this source tree. An additional grant
  10727. * of patent rights can be found in the PATENTS file in the same directory.
  10728. *
  10729. * @providesModule getSelectionOffsetKeyForNode
  10730. * @format
  10731. *
  10732. */
  10733. /**
  10734. * Get offset key from a node or it's child nodes. Return the first offset key
  10735. * found on the DOM tree of given node.
  10736. */
  10737. function getSelectionOffsetKeyForNode(node) {
  10738. if (node instanceof Element) {
  10739. var offsetKey = node.getAttribute('data-offset-key');
  10740. if (offsetKey) {
  10741. return offsetKey;
  10742. }
  10743. for (var ii = 0; ii < node.childNodes.length; ii++) {
  10744. var childOffsetKey = getSelectionOffsetKeyForNode(node.childNodes[ii]);
  10745. if (childOffsetKey) {
  10746. return childOffsetKey;
  10747. }
  10748. }
  10749. }
  10750. return null;
  10751. }
  10752. var getSelectionOffsetKeyForNode_1 = getSelectionOffsetKeyForNode;
  10753. /**
  10754. * Get the key from the node's nearest offset-aware ancestor.
  10755. */
  10756. function findAncestorOffsetKey(node) {
  10757. var searchNode = node;
  10758. while (searchNode && searchNode !== document.documentElement) {
  10759. var key = getSelectionOffsetKeyForNode_1(searchNode);
  10760. if (key != null) {
  10761. return key;
  10762. }
  10763. searchNode = searchNode.parentNode;
  10764. }
  10765. return null;
  10766. }
  10767. var findAncestorOffsetKey_1 = findAncestorOffsetKey;
  10768. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  10769. var TEXT_TYPES = {
  10770. 'text/plain': true,
  10771. 'text/html': true,
  10772. 'text/rtf': true
  10773. };
  10774. // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  10775. var TEXT_SIZE_UPPER_BOUND = 5000;
  10776. /**
  10777. * Extract the text content from a file list.
  10778. */
  10779. function getTextContentFromFiles(files, callback) {
  10780. var readCount = 0;
  10781. var results = [];
  10782. files.forEach(function ( /*blob*/file) {
  10783. readFile(file, function ( /*string*/text) {
  10784. readCount++;
  10785. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  10786. if (readCount == files.length) {
  10787. callback(results.join('\r'));
  10788. }
  10789. });
  10790. });
  10791. }
  10792. /**
  10793. * todo isaac: Do work to turn html/rtf into a content fragment.
  10794. */
  10795. function readFile(file, callback) {
  10796. if (!_commonjsHelpers.commonjsGlobal.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  10797. callback('');
  10798. return;
  10799. }
  10800. if (file.type === '') {
  10801. var contents = '';
  10802. // Special-case text clippings, which have an empty type but include
  10803. // `.textClipping` in the file name. `readAsText` results in an empty
  10804. // string for text clippings, so we force the file name to serve
  10805. // as the text value for the file.
  10806. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  10807. contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  10808. }
  10809. callback(contents);
  10810. return;
  10811. }
  10812. var reader = new FileReader();
  10813. reader.onload = function () {
  10814. var result = reader.result;
  10815. !(typeof result === 'string') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'We should be calling "FileReader.readAsText" which returns a string') : invariant_1(false) : void 0;
  10816. callback(result);
  10817. };
  10818. reader.onerror = function () {
  10819. callback('');
  10820. };
  10821. reader.readAsText(file);
  10822. }
  10823. var getTextContentFromFiles_1 = getTextContentFromFiles;
  10824. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  10825. var selection = nullthrows_1(editorState.getSelection());
  10826. if (process.env.NODE_ENV !== 'production') {
  10827. if (!anchorKey || !focusKey) {
  10828. /*eslint-disable no-console */
  10829. console.warn('Invalid selection state.', arguments, editorState.toJS());
  10830. /*eslint-enable no-console */
  10831. return selection;
  10832. }
  10833. }
  10834. var anchorPath = DraftOffsetKey_1.decode(anchorKey);
  10835. var anchorBlockKey = anchorPath.blockKey;
  10836. var anchorLeaf = editorState.getBlockTree(anchorBlockKey).getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  10837. var focusPath = DraftOffsetKey_1.decode(focusKey);
  10838. var focusBlockKey = focusPath.blockKey;
  10839. var focusLeaf = editorState.getBlockTree(focusBlockKey).getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  10840. var anchorLeafStart = anchorLeaf.get('start');
  10841. var focusLeafStart = focusLeaf.get('start');
  10842. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  10843. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  10844. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  10845. if (areEqual) {
  10846. return selection;
  10847. }
  10848. var isBackward = false;
  10849. if (anchorBlockKey === focusBlockKey) {
  10850. var anchorLeafEnd = anchorLeaf.get('end');
  10851. var focusLeafEnd = focusLeaf.get('end');
  10852. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  10853. isBackward = focusOffset < anchorOffset;
  10854. } else {
  10855. isBackward = focusLeafStart < anchorLeafStart;
  10856. }
  10857. } else {
  10858. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  10859. return v === anchorBlockKey || v === focusBlockKey;
  10860. }).first();
  10861. isBackward = startKey === focusBlockKey;
  10862. }
  10863. return selection.merge({
  10864. anchorKey: anchorBlockKey,
  10865. anchorOffset: anchorBlockOffset,
  10866. focusKey: focusBlockKey,
  10867. focusOffset: focusBlockOffset,
  10868. isBackward: isBackward
  10869. });
  10870. }
  10871. var getUpdatedSelectionState_1 = getUpdatedSelectionState;
  10872. /**
  10873. * Get a SelectionState for the supplied mouse event.
  10874. */
  10875. function getSelectionForEvent(event, editorState) {
  10876. var node = null;
  10877. var offset = null;
  10878. if (typeof document.caretRangeFromPoint === 'function') {
  10879. var dropRange = document.caretRangeFromPoint(event.x, event.y);
  10880. node = dropRange.startContainer;
  10881. offset = dropRange.startOffset;
  10882. } else if (event.rangeParent) {
  10883. node = event.rangeParent;
  10884. offset = event.rangeOffset;
  10885. } else {
  10886. return null;
  10887. }
  10888. node = nullthrows_1(node);
  10889. offset = nullthrows_1(offset);
  10890. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(node));
  10891. return getUpdatedSelectionState_1(editorState, offsetKey, offset, offsetKey, offset);
  10892. }
  10893. var DraftEditorDragHandler = {
  10894. /**
  10895. * Drag originating from input terminated.
  10896. */
  10897. onDragEnd: function onDragEnd(editor) {
  10898. editor.exitCurrentMode();
  10899. },
  10900. /**
  10901. * Handle data being dropped.
  10902. */
  10903. onDrop: function onDrop(editor, e) {
  10904. var data = new DataTransfer_1(e.nativeEvent.dataTransfer);
  10905. var editorState = editor._latestEditorState;
  10906. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  10907. e.preventDefault();
  10908. editor.exitCurrentMode();
  10909. if (dropSelection == null) {
  10910. return;
  10911. }
  10912. var files = data.getFiles();
  10913. if (files.length > 0) {
  10914. if (editor.props.handleDroppedFiles && isEventHandled_1(editor.props.handleDroppedFiles(dropSelection, files))) {
  10915. return;
  10916. }
  10917. getTextContentFromFiles_1(files, function (fileText) {
  10918. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  10919. });
  10920. return;
  10921. }
  10922. var dragType = editor._internalDrag ? 'internal' : 'external';
  10923. if (editor.props.handleDrop && isEventHandled_1(editor.props.handleDrop(dropSelection, data, dragType))) {
  10924. return;
  10925. }
  10926. if (editor._internalDrag) {
  10927. editor.update(moveText(editorState, dropSelection));
  10928. return;
  10929. }
  10930. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  10931. }
  10932. };
  10933. function moveText(editorState, targetSelection) {
  10934. var newContentState = DraftModifier_1.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  10935. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10936. }
  10937. /**
  10938. * Insert text at a specified selection.
  10939. */
  10940. function insertTextAtSelection(editorState, selection, text) {
  10941. var newContentState = DraftModifier_1.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  10942. return EditorState_1.push(editorState, newContentState, 'insert-fragment');
  10943. }
  10944. var DraftEditorDragHandler_1 = DraftEditorDragHandler;
  10945. (function (global, undefined$1) {
  10946. if (global.setImmediate) {
  10947. return;
  10948. }
  10949. var nextHandle = 1; // Spec says greater than zero
  10950. var tasksByHandle = {};
  10951. var currentlyRunningATask = false;
  10952. var doc = global.document;
  10953. var registerImmediate;
  10954. function setImmediate(callback) {
  10955. // Callback can either be a function or a string
  10956. if (typeof callback !== "function") {
  10957. callback = new Function("" + callback);
  10958. }
  10959. // Copy function arguments
  10960. var args = new Array(arguments.length - 1);
  10961. for (var i = 0; i < args.length; i++) {
  10962. args[i] = arguments[i + 1];
  10963. }
  10964. // Store and register the task
  10965. var task = { callback: callback, args: args };
  10966. tasksByHandle[nextHandle] = task;
  10967. registerImmediate(nextHandle);
  10968. return nextHandle++;
  10969. }
  10970. function clearImmediate(handle) {
  10971. delete tasksByHandle[handle];
  10972. }
  10973. function run(task) {
  10974. var callback = task.callback;
  10975. var args = task.args;
  10976. switch (args.length) {
  10977. case 0:
  10978. callback();
  10979. break;
  10980. case 1:
  10981. callback(args[0]);
  10982. break;
  10983. case 2:
  10984. callback(args[0], args[1]);
  10985. break;
  10986. case 3:
  10987. callback(args[0], args[1], args[2]);
  10988. break;
  10989. default:
  10990. callback.apply(undefined$1, args);
  10991. break;
  10992. }
  10993. }
  10994. function runIfPresent(handle) {
  10995. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  10996. // So if we're currently running a task, we'll need to delay this invocation.
  10997. if (currentlyRunningATask) {
  10998. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  10999. // "too much recursion" error.
  11000. setTimeout(runIfPresent, 0, handle);
  11001. } else {
  11002. var task = tasksByHandle[handle];
  11003. if (task) {
  11004. currentlyRunningATask = true;
  11005. try {
  11006. run(task);
  11007. } finally {
  11008. clearImmediate(handle);
  11009. currentlyRunningATask = false;
  11010. }
  11011. }
  11012. }
  11013. }
  11014. function installNextTickImplementation() {
  11015. registerImmediate = function(handle) {
  11016. process.nextTick(function () { runIfPresent(handle); });
  11017. };
  11018. }
  11019. function canUsePostMessage() {
  11020. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11021. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11022. if (global.postMessage && !global.importScripts) {
  11023. var postMessageIsAsynchronous = true;
  11024. var oldOnMessage = global.onmessage;
  11025. global.onmessage = function() {
  11026. postMessageIsAsynchronous = false;
  11027. };
  11028. global.postMessage("", "*");
  11029. global.onmessage = oldOnMessage;
  11030. return postMessageIsAsynchronous;
  11031. }
  11032. }
  11033. function installPostMessageImplementation() {
  11034. // Installs an event handler on `global` for the `message` event: see
  11035. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11036. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11037. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11038. var onGlobalMessage = function(event) {
  11039. if (event.source === global &&
  11040. typeof event.data === "string" &&
  11041. event.data.indexOf(messagePrefix) === 0) {
  11042. runIfPresent(+event.data.slice(messagePrefix.length));
  11043. }
  11044. };
  11045. if (global.addEventListener) {
  11046. global.addEventListener("message", onGlobalMessage, false);
  11047. } else {
  11048. global.attachEvent("onmessage", onGlobalMessage);
  11049. }
  11050. registerImmediate = function(handle) {
  11051. global.postMessage(messagePrefix + handle, "*");
  11052. };
  11053. }
  11054. function installMessageChannelImplementation() {
  11055. var channel = new MessageChannel();
  11056. channel.port1.onmessage = function(event) {
  11057. var handle = event.data;
  11058. runIfPresent(handle);
  11059. };
  11060. registerImmediate = function(handle) {
  11061. channel.port2.postMessage(handle);
  11062. };
  11063. }
  11064. function installReadyStateChangeImplementation() {
  11065. var html = doc.documentElement;
  11066. registerImmediate = function(handle) {
  11067. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11068. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11069. var script = doc.createElement("script");
  11070. script.onreadystatechange = function () {
  11071. runIfPresent(handle);
  11072. script.onreadystatechange = null;
  11073. html.removeChild(script);
  11074. script = null;
  11075. };
  11076. html.appendChild(script);
  11077. };
  11078. }
  11079. function installSetTimeoutImplementation() {
  11080. registerImmediate = function(handle) {
  11081. setTimeout(runIfPresent, 0, handle);
  11082. };
  11083. }
  11084. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11085. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11086. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11087. // Don't get fooled by e.g. browserify environments.
  11088. if ({}.toString.call(global.process) === "[object process]") {
  11089. // For Node.js before 0.9
  11090. installNextTickImplementation();
  11091. } else if (canUsePostMessage()) {
  11092. // For non-IE10 modern browsers
  11093. installPostMessageImplementation();
  11094. } else if (global.MessageChannel) {
  11095. // For web workers, where supported
  11096. installMessageChannelImplementation();
  11097. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  11098. // For IE 6–8
  11099. installReadyStateChangeImplementation();
  11100. } else {
  11101. // For older browsers
  11102. installSetTimeoutImplementation();
  11103. }
  11104. attachTo.setImmediate = setImmediate;
  11105. attachTo.clearImmediate = clearImmediate;
  11106. }(typeof self === "undefined" ? typeof _commonjsHelpers.commonjsGlobal === "undefined" ? _commonjsHelpers.commonjsGlobal : _commonjsHelpers.commonjsGlobal : self));
  11107. // setimmediate adds setImmediate to the global. We want to make sure we export
  11108. // the actual function.
  11109. var setImmediate = _commonjsHelpers.commonjsGlobal.setImmediate;
  11110. // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11111. // commands that should open and focus the "quickfind" search bar. This should
  11112. // *never* happen while a contenteditable is focused, but as of v28, it
  11113. // sometimes does, even when the keypress event target is the contenteditable.
  11114. // This breaks the input. Special case these characters to ensure that when
  11115. // they are typed, we prevent default on the event to make sure not to
  11116. // trigger quickfind.
  11117. var FF_QUICKFIND_CHAR = "'";
  11118. var FF_QUICKFIND_LINK_CHAR = '/';
  11119. var isFirefox = UserAgent_1.isBrowser('Firefox');
  11120. function mustPreventDefaultForCharacter(character) {
  11121. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11122. }
  11123. /**
  11124. * Replace the current selection with the specified text string, with the
  11125. * inline style and entity key applied to the newly inserted text.
  11126. */
  11127. function replaceText(editorState, text, inlineStyle, entityKey) {
  11128. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11129. return EditorState_1.push(editorState, contentState, 'insert-characters');
  11130. }
  11131. /**
  11132. * When `onBeforeInput` executes, the browser is attempting to insert a
  11133. * character into the editor. Apply this character data to the document,
  11134. * allowing native insertion if possible.
  11135. *
  11136. * Native insertion is encouraged in order to limit re-rendering and to
  11137. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11138. * occurs on the relevant text nodes.
  11139. */
  11140. function editOnBeforeInput(editor, e) {
  11141. if (editor._pendingStateFromBeforeInput !== undefined) {
  11142. editor.update(editor._pendingStateFromBeforeInput);
  11143. editor._pendingStateFromBeforeInput = undefined;
  11144. }
  11145. var editorState = editor._latestEditorState;
  11146. var chars = e.data;
  11147. // In some cases (ex: IE ideographic space insertion) no character data
  11148. // is provided. There's nothing to do when this happens.
  11149. if (!chars) {
  11150. return;
  11151. }
  11152. // Allow the top-level component to handle the insertion manually. This is
  11153. // useful when triggering interesting behaviors for a character insertion,
  11154. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11155. // decorator, or setting a block to be a list item after typing '- ' at the
  11156. // start of the block.
  11157. if (editor.props.handleBeforeInput && isEventHandled_1(editor.props.handleBeforeInput(chars, editorState))) {
  11158. e.preventDefault();
  11159. return;
  11160. }
  11161. // If selection is collapsed, conditionally allow native behavior. This
  11162. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11163. // is not collapsed, we will re-render.
  11164. var selection = editorState.getSelection();
  11165. var selectionStart = selection.getStartOffset();
  11166. var selectionEnd = selection.getEndOffset();
  11167. var anchorKey = selection.getAnchorKey();
  11168. if (!selection.isCollapsed()) {
  11169. e.preventDefault();
  11170. // If the currently selected text matches what the user is trying to
  11171. // replace it with, let's just update the `SelectionState`. If not, update
  11172. // the `ContentState` with the new text.
  11173. var currentlySelectedChars = editorState.getCurrentContent().getPlainText().slice(selectionStart, selectionEnd);
  11174. if (chars === currentlySelectedChars) {
  11175. editor.update(EditorState_1.forceSelection(editorState, selection.merge({
  11176. focusOffset: selectionEnd
  11177. })));
  11178. } else {
  11179. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())));
  11180. }
  11181. return;
  11182. }
  11183. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection()));
  11184. // Bunch of different cases follow where we need to prevent native insertion.
  11185. var mustPreventNative = false;
  11186. if (!mustPreventNative) {
  11187. // Browsers tend to insert text in weird places in the DOM when typing at
  11188. // the start of a leaf, so we'll handle it ourselves.
  11189. mustPreventNative = isSelectionAtLeafStart_1(editor._latestCommittedEditorState);
  11190. }
  11191. if (!mustPreventNative) {
  11192. // Chrome will also split up a node into two pieces if it contains a Tab
  11193. // char, for no explicable reason. Seemingly caused by this commit:
  11194. // https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/
  11195. var nativeSelection = _commonjsHelpers.commonjsGlobal.getSelection();
  11196. // Selection is necessarily collapsed at this point due to earlier check.
  11197. if (nativeSelection.anchorNode && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) {
  11198. // See isTabHTMLSpanElement in chromium EditingUtilities.cpp.
  11199. var parentNode = nativeSelection.anchorNode.parentNode;
  11200. mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1;
  11201. }
  11202. }
  11203. if (!mustPreventNative) {
  11204. // Check the old and new "fingerprints" of the current block to determine
  11205. // whether this insertion requires any addition or removal of text nodes,
  11206. // in which case we would prevent the native character insertion.
  11207. var originalFingerprint = BlockTree_1.getFingerprint(editorState.getBlockTree(anchorKey));
  11208. var newFingerprint = BlockTree_1.getFingerprint(newEditorState.getBlockTree(anchorKey));
  11209. mustPreventNative = originalFingerprint !== newFingerprint;
  11210. }
  11211. if (!mustPreventNative) {
  11212. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11213. }
  11214. if (!mustPreventNative) {
  11215. mustPreventNative = nullthrows_1(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows_1(editorState.getDirectionMap()).get(anchorKey);
  11216. }
  11217. if (mustPreventNative) {
  11218. e.preventDefault();
  11219. editor.update(newEditorState);
  11220. return;
  11221. }
  11222. // We made it all the way! Let the browser do its thing and insert the char.
  11223. newEditorState = EditorState_1.set(newEditorState, {
  11224. nativelyRenderedContent: newEditorState.getCurrentContent()
  11225. });
  11226. // The native event is allowed to occur. To allow user onChange handlers to
  11227. // change the inserted text, we wait until the text is actually inserted
  11228. // before we actually update our state. That way when we rerender, the text
  11229. // we see in the DOM will already have been inserted properly.
  11230. editor._pendingStateFromBeforeInput = newEditorState;
  11231. setImmediate(function () {
  11232. if (editor._pendingStateFromBeforeInput !== undefined) {
  11233. editor.update(editor._pendingStateFromBeforeInput);
  11234. editor._pendingStateFromBeforeInput = undefined;
  11235. }
  11236. });
  11237. }
  11238. var editOnBeforeInput_1 = editOnBeforeInput;
  11239. function editOnBlur(editor, e) {
  11240. // In a contentEditable element, when you select a range and then click
  11241. // another active element, this does trigger a `blur` event but will not
  11242. // remove the DOM selection from the contenteditable.
  11243. // This is consistent across all browsers, but we prefer that the editor
  11244. // behave like a textarea, where a `blur` event clears the DOM selection.
  11245. // We therefore force the issue to be certain, checking whether the active
  11246. // element is `body` to force it when blurring occurs within the window (as
  11247. // opposed to clicking to another tab or window).
  11248. if (getActiveElement_1() === document.body) {
  11249. var _selection = _commonjsHelpers.commonjsGlobal.getSelection();
  11250. var editorNode = editor.editor;
  11251. if (_selection.rangeCount === 1 && containsNode_1(editorNode, _selection.anchorNode) && containsNode_1(editorNode, _selection.focusNode)) {
  11252. _selection.removeAllRanges();
  11253. }
  11254. }
  11255. var editorState = editor._latestEditorState;
  11256. var currentSelection = editorState.getSelection();
  11257. if (!currentSelection.getHasFocus()) {
  11258. return;
  11259. }
  11260. var selection = currentSelection.set('hasFocus', false);
  11261. editor.props.onBlur && editor.props.onBlur(e);
  11262. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11263. }
  11264. var editOnBlur_1 = editOnBlur;
  11265. /**
  11266. * The user has begun using an IME input system. Switching to `composite` mode
  11267. * allows handling composition input and disables other edit behavior.
  11268. */
  11269. function editOnCompositionStart(editor, e) {
  11270. editor.setMode('composite');
  11271. editor.update(EditorState_1.set(editor._latestEditorState, { inCompositionMode: true }));
  11272. // Allow composition handler to interpret the compositionstart event
  11273. editor._onCompositionStart(e);
  11274. }
  11275. var editOnCompositionStart_1 = editOnCompositionStart;
  11276. function getFragmentFromSelection(editorState) {
  11277. var selectionState = editorState.getSelection();
  11278. if (selectionState.isCollapsed()) {
  11279. return null;
  11280. }
  11281. return getContentStateFragment_1(editorState.getCurrentContent(), selectionState);
  11282. }
  11283. var getFragmentFromSelection_1 = getFragmentFromSelection;
  11284. /**
  11285. * If we have a selection, create a ContentState fragment and store
  11286. * it in our internal clipboard. Subsequent paste events will use this
  11287. * fragment if no external clipboard data is supplied.
  11288. */
  11289. function editOnCopy(editor, e) {
  11290. var editorState = editor._latestEditorState;
  11291. var selection = editorState.getSelection();
  11292. // No selection, so there's nothing to copy.
  11293. if (selection.isCollapsed()) {
  11294. e.preventDefault();
  11295. return;
  11296. }
  11297. editor.setClipboard(getFragmentFromSelection_1(editor._latestEditorState));
  11298. }
  11299. var editOnCopy_1 = editOnCopy;
  11300. /**
  11301. * On `cut` events, native behavior is allowed to occur so that the system
  11302. * clipboard is set properly. This means that we need to take steps to recover
  11303. * the editor DOM state after the `cut` has occurred in order to maintain
  11304. * control of the component.
  11305. *
  11306. * In addition, we can keep a copy of the removed fragment, including all
  11307. * styles and entities, for use as an internal paste.
  11308. */
  11309. function editOnCut(editor, e) {
  11310. var editorState = editor._latestEditorState;
  11311. var selection = editorState.getSelection();
  11312. var element = e.target;
  11313. var scrollPosition = void 0;
  11314. // No selection, so there's nothing to cut.
  11315. if (selection.isCollapsed()) {
  11316. e.preventDefault();
  11317. return;
  11318. }
  11319. // Track the current scroll position so that it can be forced back in place
  11320. // after the editor regains control of the DOM.
  11321. if (element instanceof Node) {
  11322. scrollPosition = getScrollPosition_1(Style_1.getScrollParent(element));
  11323. }
  11324. var fragment = getFragmentFromSelection_1(editorState);
  11325. editor.setClipboard(fragment);
  11326. // Set `cut` mode to disable all event handling temporarily.
  11327. editor.setMode('cut');
  11328. // Let native `cut` behavior occur, then recover control.
  11329. setTimeout(function () {
  11330. editor.restoreEditorDOM(scrollPosition);
  11331. editor.exitCurrentMode();
  11332. editor.update(removeFragment(editorState));
  11333. }, 0);
  11334. }
  11335. function removeFragment(editorState) {
  11336. var newContent = DraftModifier_1.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  11337. return EditorState_1.push(editorState, newContent, 'remove-range');
  11338. }
  11339. var editOnCut_1 = editOnCut;
  11340. /**
  11341. * Copyright (c) 2013-present, Facebook, Inc.
  11342. * All rights reserved.
  11343. *
  11344. * This source code is licensed under the BSD-style license found in the
  11345. * LICENSE file in the root directory of this source tree. An additional grant
  11346. * of patent rights can be found in the PATENTS file in the same directory.
  11347. *
  11348. * @providesModule editOnDragOver
  11349. * @format
  11350. *
  11351. */
  11352. /**
  11353. * Drag behavior has begun from outside the editor element.
  11354. */
  11355. function editOnDragOver(editor, e) {
  11356. editor._internalDrag = false;
  11357. editor.setMode('drag');
  11358. e.preventDefault();
  11359. }
  11360. var editOnDragOver_1 = editOnDragOver;
  11361. /**
  11362. * Copyright (c) 2013-present, Facebook, Inc.
  11363. * All rights reserved.
  11364. *
  11365. * This source code is licensed under the BSD-style license found in the
  11366. * LICENSE file in the root directory of this source tree. An additional grant
  11367. * of patent rights can be found in the PATENTS file in the same directory.
  11368. *
  11369. * @providesModule editOnDragStart
  11370. * @format
  11371. *
  11372. */
  11373. /**
  11374. * A `dragstart` event has begun within the text editor component.
  11375. */
  11376. function editOnDragStart(editor) {
  11377. editor._internalDrag = true;
  11378. editor.setMode('drag');
  11379. }
  11380. var editOnDragStart_1 = editOnDragStart;
  11381. function editOnFocus(editor, e) {
  11382. var editorState = editor._latestEditorState;
  11383. var currentSelection = editorState.getSelection();
  11384. if (currentSelection.getHasFocus()) {
  11385. return;
  11386. }
  11387. var selection = currentSelection.set('hasFocus', true);
  11388. editor.props.onFocus && editor.props.onFocus(e);
  11389. // When the tab containing this text editor is hidden and the user does a
  11390. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  11391. // selection was right after sending this focus event and (if you let it)
  11392. // moves the cursor back to the beginning of the editor, so we force the
  11393. // selection here instead of simply accepting it in order to preserve the
  11394. // old cursor position. See https://crbug.com/540004.
  11395. // But it looks like this is fixed in Chrome 60.0.3081.0.
  11396. // Other browsers also don't have this bug, so we prefer to acceptSelection
  11397. // when possible, to ensure that unfocusing and refocusing a Draft editor
  11398. // doesn't preserve the selection, matching how textareas work.
  11399. if (UserAgent_1.isBrowser('Chrome < 60.0.3081.0')) {
  11400. editor.update(EditorState_1.forceSelection(editorState, selection));
  11401. } else {
  11402. editor.update(EditorState_1.acceptSelection(editorState, selection));
  11403. }
  11404. }
  11405. var editOnFocus_1 = editOnFocus;
  11406. var isGecko = UserAgent_1.isEngine('Gecko');
  11407. var DOUBLE_NEWLINE = '\n\n';
  11408. /**
  11409. * This function is intended to handle spellcheck and autocorrect changes,
  11410. * which occur in the DOM natively without any opportunity to observe or
  11411. * interpret the changes before they occur.
  11412. *
  11413. * The `input` event fires in contentEditable elements reliably for non-IE
  11414. * browsers, immediately after changes occur to the editor DOM. Since our other
  11415. * handlers override or otherwise handle cover other varieties of text input,
  11416. * the DOM state should match the model in all controlled input cases. Thus,
  11417. * when an `input` change leads to a DOM/model mismatch, the change should be
  11418. * due to a spellcheck change, and we can incorporate it into our model.
  11419. */
  11420. function editOnInput(editor) {
  11421. if (editor._pendingStateFromBeforeInput !== undefined) {
  11422. editor.update(editor._pendingStateFromBeforeInput);
  11423. editor._pendingStateFromBeforeInput = undefined;
  11424. }
  11425. var domSelection = _commonjsHelpers.commonjsGlobal.getSelection();
  11426. var anchorNode = domSelection.anchorNode,
  11427. isCollapsed = domSelection.isCollapsed;
  11428. var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE;
  11429. var isNotTextOrElementNode = anchorNode.nodeType !== Node.TEXT_NODE && anchorNode.nodeType !== Node.ELEMENT_NODE;
  11430. {
  11431. if (isNotTextOrElementNode) {
  11432. // TODO: (t16149272) figure out context for this change
  11433. return;
  11434. }
  11435. }
  11436. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  11437. // When typing at the beginning of a visual line, Chrome splits the text
  11438. // nodes into two. Why? No one knows. This commit is suspicious:
  11439. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  11440. // To work around, we'll merge the sibling text nodes back into this one.
  11441. var span = anchorNode.parentNode;
  11442. anchorNode.nodeValue = span.textContent;
  11443. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  11444. if (child !== anchorNode) {
  11445. span.removeChild(child);
  11446. }
  11447. }
  11448. }
  11449. var domText = anchorNode.textContent;
  11450. var editorState = editor._latestEditorState;
  11451. var offsetKey = nullthrows_1(findAncestorOffsetKey_1(anchorNode));
  11452. var _DraftOffsetKey$decod = DraftOffsetKey_1.decode(offsetKey),
  11453. blockKey = _DraftOffsetKey$decod.blockKey,
  11454. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  11455. leafKey = _DraftOffsetKey$decod.leafKey;
  11456. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  11457. start = _editorState$getBlock.start,
  11458. end = _editorState$getBlock.end;
  11459. var content = editorState.getCurrentContent();
  11460. var block = content.getBlockForKey(blockKey);
  11461. var modelText = block.getText().slice(start, end);
  11462. // Special-case soft newlines here. If the DOM text ends in a soft newline,
  11463. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  11464. // We want to remove this extra newline for the purpose of our comparison
  11465. // of DOM and model text.
  11466. if (domText.endsWith(DOUBLE_NEWLINE)) {
  11467. domText = domText.slice(0, -1);
  11468. }
  11469. // No change -- the DOM is up to date. Nothing to do here.
  11470. if (domText === modelText) {
  11471. // This can be buggy for some Android keyboards because they don't fire
  11472. // standard onkeydown/pressed events and only fired editOnInput
  11473. // so domText is already changed by the browser and ends up being equal
  11474. // to modelText unexpectedly
  11475. return;
  11476. }
  11477. var selection = editorState.getSelection();
  11478. // We'll replace the entire leaf with the text content of the target.
  11479. var targetRange = selection.merge({
  11480. anchorOffset: start,
  11481. focusOffset: end,
  11482. isBackward: false
  11483. });
  11484. var entityKey = block.getEntityAt(start);
  11485. var entity = entityKey && content.getEntity(entityKey);
  11486. var entityType = entity && entity.getMutability();
  11487. var preserveEntity = entityType === 'MUTABLE';
  11488. // Immutable or segmented entities cannot properly be handled by the
  11489. // default browser undo, so we have to use a different change type to
  11490. // force using our internal undo method instead of falling through to the
  11491. // native browser undo.
  11492. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  11493. var newContent = DraftModifier_1.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  11494. var anchorOffset, focusOffset, startOffset, endOffset;
  11495. if (isGecko) {
  11496. // Firefox selection does not change while the context menu is open, so
  11497. // we preserve the anchor and focus values of the DOM selection.
  11498. anchorOffset = domSelection.anchorOffset;
  11499. focusOffset = domSelection.focusOffset;
  11500. startOffset = start + Math.min(anchorOffset, focusOffset);
  11501. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  11502. anchorOffset = startOffset;
  11503. focusOffset = endOffset;
  11504. } else {
  11505. // Browsers other than Firefox may adjust DOM selection while the context
  11506. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  11507. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  11508. // and adjust it based on the number of characters changed during the
  11509. // mutation.
  11510. var charDelta = domText.length - modelText.length;
  11511. startOffset = selection.getStartOffset();
  11512. endOffset = selection.getEndOffset();
  11513. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  11514. focusOffset = endOffset + charDelta;
  11515. }
  11516. // Segmented entities are completely or partially removed when their
  11517. // text content changes. For this case we do not want any text to be selected
  11518. // after the change, so we are not merging the selection.
  11519. var contentWithAdjustedDOMSelection = newContent.merge({
  11520. selectionBefore: content.getSelectionAfter(),
  11521. selectionAfter: selection.merge({ anchorOffset: anchorOffset, focusOffset: focusOffset })
  11522. });
  11523. editor.update(EditorState_1.push(editorState, contentWithAdjustedDOMSelection, changeType));
  11524. }
  11525. var editOnInput_1 = editOnInput;
  11526. var isOSX = UserAgent_1.isPlatform('Mac OS X');
  11527. var KeyBindingUtil = {
  11528. /**
  11529. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  11530. * the altKey modifier. If they are combined, the result is an `altGraph`
  11531. * key modifier, which should not be handled by this set of key bindings.
  11532. */
  11533. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  11534. return !!e.ctrlKey && !e.altKey;
  11535. },
  11536. isOptionKeyCommand: function isOptionKeyCommand(e) {
  11537. return isOSX && e.altKey;
  11538. },
  11539. hasCommandModifier: function hasCommandModifier(e) {
  11540. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  11541. }
  11542. };
  11543. var KeyBindingUtil_1 = KeyBindingUtil;
  11544. var clipboard = null;
  11545. /**
  11546. * Some systems offer a "secondary" clipboard to allow quick internal cut
  11547. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  11548. */
  11549. var SecondaryClipboard = {
  11550. cut: function cut(editorState) {
  11551. var content = editorState.getCurrentContent();
  11552. var selection = editorState.getSelection();
  11553. var targetRange = null;
  11554. if (selection.isCollapsed()) {
  11555. var anchorKey = selection.getAnchorKey();
  11556. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  11557. if (blockEnd === selection.getAnchorOffset()) {
  11558. return editorState;
  11559. }
  11560. targetRange = selection.set('focusOffset', blockEnd);
  11561. } else {
  11562. targetRange = selection;
  11563. }
  11564. targetRange = nullthrows_1(targetRange);
  11565. clipboard = getContentStateFragment_1(content, targetRange);
  11566. var afterRemoval = DraftModifier_1.removeRange(content, targetRange, 'forward');
  11567. if (afterRemoval === content) {
  11568. return editorState;
  11569. }
  11570. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  11571. },
  11572. paste: function paste(editorState) {
  11573. if (!clipboard) {
  11574. return editorState;
  11575. }
  11576. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  11577. return EditorState_1.push(editorState, newContent, 'insert-fragment');
  11578. }
  11579. };
  11580. var SecondaryClipboard_1 = SecondaryClipboard;
  11581. // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  11582. // surrogate code unit.
  11583. var SURROGATE_HIGH_START = 0xD800;
  11584. var SURROGATE_HIGH_END = 0xDBFF;
  11585. var SURROGATE_LOW_START = 0xDC00;
  11586. var SURROGATE_LOW_END = 0xDFFF;
  11587. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  11588. /**
  11589. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  11590. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  11591. */
  11592. function isCodeUnitInSurrogateRange(codeUnit) {
  11593. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  11594. }
  11595. /**
  11596. * Returns whether the two characters starting at `index` form a surrogate pair.
  11597. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  11598. * (s, 1) returns false.
  11599. *
  11600. * @param {string} str
  11601. * @param {number} index
  11602. * @return {boolean}
  11603. */
  11604. function isSurrogatePair(str, index) {
  11605. !(0 <= index && index < str.length) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'isSurrogatePair: Invalid index %s for string length %s.', index, str.length) : invariant_1(false) : void 0;
  11606. if (index + 1 === str.length) {
  11607. return false;
  11608. }
  11609. var first = str.charCodeAt(index);
  11610. var second = str.charCodeAt(index + 1);
  11611. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  11612. }
  11613. /**
  11614. * @param {string} str Non-empty string
  11615. * @return {boolean} True if the input includes any surrogate code units
  11616. */
  11617. function hasSurrogateUnit(str) {
  11618. return SURROGATE_UNITS_REGEX.test(str);
  11619. }
  11620. /**
  11621. * Return the length of the original Unicode character at given position in the
  11622. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  11623. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  11624. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  11625. * representing non-BMP characters ([U+10000..U+10FFFF]).
  11626. *
  11627. * Examples:
  11628. * - '\u0020' => 1
  11629. * - '\u3020' => 1
  11630. * - '\uD835' => 2
  11631. * - '\uD835\uDDEF' => 2
  11632. * - '\uDDEF' => 2
  11633. *
  11634. * @param {string} str Non-empty string
  11635. * @param {number} pos Position in the string to look for one code unit
  11636. * @return {number} Number 1 or 2
  11637. */
  11638. function getUTF16Length(str, pos) {
  11639. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  11640. }
  11641. /**
  11642. * Fully Unicode-enabled replacement for String#length
  11643. *
  11644. * @param {string} str Valid Unicode string
  11645. * @return {number} The number of Unicode characters in the string
  11646. */
  11647. function strlen(str) {
  11648. // Call the native functions if there's no surrogate char
  11649. if (!hasSurrogateUnit(str)) {
  11650. return str.length;
  11651. }
  11652. var len = 0;
  11653. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11654. len++;
  11655. }
  11656. return len;
  11657. }
  11658. /**
  11659. * Fully Unicode-enabled replacement for String#substr()
  11660. *
  11661. * @param {string} str Valid Unicode string
  11662. * @param {number} start Location in Unicode sequence to begin extracting
  11663. * @param {?number} length The number of Unicode characters to extract
  11664. * (default: to the end of the string)
  11665. * @return {string} Extracted sub-string
  11666. */
  11667. function substr(str, start, length) {
  11668. start = start || 0;
  11669. length = length === undefined ? Infinity : length || 0;
  11670. // Call the native functions if there's no surrogate char
  11671. if (!hasSurrogateUnit(str)) {
  11672. return str.substr(start, length);
  11673. }
  11674. // Obvious cases
  11675. var size = str.length;
  11676. if (size <= 0 || start > size || length <= 0) {
  11677. return '';
  11678. }
  11679. // Find the actual starting position
  11680. var posA = 0;
  11681. if (start > 0) {
  11682. for (; start > 0 && posA < size; start--) {
  11683. posA += getUTF16Length(str, posA);
  11684. }
  11685. if (posA >= size) {
  11686. return '';
  11687. }
  11688. } else if (start < 0) {
  11689. for (posA = size; start < 0 && 0 < posA; start++) {
  11690. posA -= getUTF16Length(str, posA - 1);
  11691. }
  11692. if (posA < 0) {
  11693. posA = 0;
  11694. }
  11695. }
  11696. // Find the actual ending position
  11697. var posB = size;
  11698. if (length < size) {
  11699. for (posB = posA; length > 0 && posB < size; length--) {
  11700. posB += getUTF16Length(str, posB);
  11701. }
  11702. }
  11703. return str.substring(posA, posB);
  11704. }
  11705. /**
  11706. * Fully Unicode-enabled replacement for String#substring()
  11707. *
  11708. * @param {string} str Valid Unicode string
  11709. * @param {number} start Location in Unicode sequence to begin extracting
  11710. * @param {?number} end Location in Unicode sequence to end extracting
  11711. * (default: end of the string)
  11712. * @return {string} Extracted sub-string
  11713. */
  11714. function substring(str, start, end) {
  11715. start = start || 0;
  11716. end = end === undefined ? Infinity : end || 0;
  11717. if (start < 0) {
  11718. start = 0;
  11719. }
  11720. if (end < 0) {
  11721. end = 0;
  11722. }
  11723. var length = Math.abs(end - start);
  11724. start = start < end ? start : end;
  11725. return substr(str, start, length);
  11726. }
  11727. /**
  11728. * Get a list of Unicode code-points from a String
  11729. *
  11730. * @param {string} str Valid Unicode string
  11731. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  11732. */
  11733. function getCodePoints(str) {
  11734. var codePoints = [];
  11735. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  11736. codePoints.push(str.codePointAt(pos));
  11737. }
  11738. return codePoints;
  11739. }
  11740. var UnicodeUtils = {
  11741. getCodePoints: getCodePoints,
  11742. getUTF16Length: getUTF16Length,
  11743. hasSurrogateUnit: hasSurrogateUnit,
  11744. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  11745. isSurrogatePair: isSurrogatePair,
  11746. strlen: strlen,
  11747. substring: substring,
  11748. substr: substr
  11749. };
  11750. var UnicodeUtils_1 = UnicodeUtils;
  11751. var isChrome = UserAgent_1.isBrowser('Chrome');
  11752. // In Chrome, the client rects will include the entire bounds of all nodes that
  11753. // begin (have a start tag) within the selection, even if the selection does
  11754. // not overlap the entire node. To resolve this, we split the range at each
  11755. // start tag and join the client rects together.
  11756. // https://code.google.com/p/chromium/issues/detail?id=324437
  11757. /* eslint-disable consistent-return */
  11758. function getRangeClientRectsChrome(range) {
  11759. var tempRange = range.cloneRange();
  11760. var clientRects = [];
  11761. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  11762. // If we've climbed up to the common ancestor, we can now use the
  11763. // original start point and stop climbing the tree.
  11764. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  11765. if (atCommonAncestor) {
  11766. tempRange.setStart(range.startContainer, range.startOffset);
  11767. } else {
  11768. tempRange.setStart(tempRange.endContainer, 0);
  11769. }
  11770. var rects = Array.from(tempRange.getClientRects());
  11771. clientRects.push(rects);
  11772. if (atCommonAncestor) {
  11773. var _ref;
  11774. clientRects.reverse();
  11775. return (_ref = []).concat.apply(_ref, clientRects);
  11776. }
  11777. tempRange.setEndBefore(ancestor);
  11778. }
  11779. process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant_1(false) ;
  11780. }
  11781. /* eslint-enable consistent-return */
  11782. /**
  11783. * Like range.getClientRects() but normalizes for browser bugs.
  11784. */
  11785. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  11786. return Array.from(range.getClientRects());
  11787. };
  11788. var getRangeClientRects_1 = getRangeClientRects;
  11789. /**
  11790. * Copyright (c) 2013-present, Facebook, Inc.
  11791. * All rights reserved.
  11792. *
  11793. * This source code is licensed under the BSD-style license found in the
  11794. * LICENSE file in the root directory of this source tree. An additional grant
  11795. * of patent rights can be found in the PATENTS file in the same directory.
  11796. *
  11797. * @providesModule expandRangeToStartOfLine
  11798. * @format
  11799. *
  11800. */
  11801. /**
  11802. * Return the computed line height, in pixels, for the provided element.
  11803. */
  11804. function getLineHeightPx(element) {
  11805. var computed = getComputedStyle(element);
  11806. var div = document.createElement('div');
  11807. div.style.fontFamily = computed.fontFamily;
  11808. div.style.fontSize = computed.fontSize;
  11809. div.style.fontStyle = computed.fontStyle;
  11810. div.style.fontWeight = computed.fontWeight;
  11811. div.style.lineHeight = computed.lineHeight;
  11812. div.style.position = 'absolute';
  11813. div.textContent = 'M';
  11814. var documentBody = document.body;
  11815. !documentBody ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing document.body') : invariant_1(false) : void 0;
  11816. // forced layout here
  11817. documentBody.appendChild(div);
  11818. var rect = div.getBoundingClientRect();
  11819. documentBody.removeChild(div);
  11820. return rect.height;
  11821. }
  11822. /**
  11823. * Return whether every ClientRect in the provided list lies on the same line.
  11824. *
  11825. * We assume that the rects on the same line all contain the baseline, so the
  11826. * lowest top line needs to be above the highest bottom line (i.e., if you were
  11827. * to project the rects onto the y-axis, their intersection would be nonempty).
  11828. *
  11829. * In addition, we require that no two boxes are lineHeight (or more) apart at
  11830. * either top or bottom, which helps protect against false positives for fonts
  11831. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  11832. * produces rects of height 58px!).
  11833. */
  11834. function areRectsOnOneLine(rects, lineHeight) {
  11835. var minTop = Infinity;
  11836. var minBottom = Infinity;
  11837. var maxTop = -Infinity;
  11838. var maxBottom = -Infinity;
  11839. for (var ii = 0; ii < rects.length; ii++) {
  11840. var rect = rects[ii];
  11841. if (rect.width === 0 || rect.width === 1) {
  11842. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  11843. // Safari) include an empty rect on the previous or next line. When the
  11844. // text lies in a container whose position is not integral (e.g., from
  11845. // margin: auto), Safari makes these empty rects have width 1 (instead of
  11846. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  11847. // report widths in subpixel precision anyway) so it's relatively safe to
  11848. // skip over them.
  11849. continue;
  11850. }
  11851. minTop = Math.min(minTop, rect.top);
  11852. minBottom = Math.min(minBottom, rect.bottom);
  11853. maxTop = Math.max(maxTop, rect.top);
  11854. maxBottom = Math.max(maxBottom, rect.bottom);
  11855. }
  11856. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  11857. }
  11858. /**
  11859. * Return the length of a node, as used by Range offsets.
  11860. */
  11861. function getNodeLength$1(node) {
  11862. // http://www.w3.org/TR/dom/#concept-node-length
  11863. switch (node.nodeType) {
  11864. case Node.DOCUMENT_TYPE_NODE:
  11865. return 0;
  11866. case Node.TEXT_NODE:
  11867. case Node.PROCESSING_INSTRUCTION_NODE:
  11868. case Node.COMMENT_NODE:
  11869. return node.length;
  11870. default:
  11871. return node.childNodes.length;
  11872. }
  11873. }
  11874. /**
  11875. * Given a collapsed range, move the start position backwards as far as
  11876. * possible while the range still spans only a single line.
  11877. */
  11878. function expandRangeToStartOfLine(range) {
  11879. !range.collapsed ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant_1(false) : void 0;
  11880. range = range.cloneRange();
  11881. var containingElement = range.startContainer;
  11882. if (containingElement.nodeType !== 1) {
  11883. containingElement = containingElement.parentNode;
  11884. }
  11885. var lineHeight = getLineHeightPx(containingElement);
  11886. // Imagine our text looks like:
  11887. // <div><span>once upon a time, there was a <em>boy
  11888. // who lived</em> </span><q><strong>under^ the
  11889. // stairs</strong> in a small closet.</q></div>
  11890. // where the caret represents the cursor. First, we crawl up the tree until
  11891. // the range spans multiple lines (setting the start point to before
  11892. // "<strong>", then before "<div>"), then at each level we do a search to
  11893. // find the latest point which is still on a previous line. We'll find that
  11894. // the break point is inside the span, then inside the <em>, then in its text
  11895. // node child, the actual break point before "who".
  11896. var bestContainer = range.endContainer;
  11897. var bestOffset = range.endOffset;
  11898. range.setStart(range.startContainer, 0);
  11899. while (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11900. bestContainer = range.startContainer;
  11901. bestOffset = range.startOffset;
  11902. !bestContainer.parentNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Found unexpected detached subtree when traversing.') : invariant_1(false) : void 0;
  11903. range.setStartBefore(bestContainer);
  11904. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  11905. // The start of the line is never in a different block-level container.
  11906. break;
  11907. }
  11908. }
  11909. // In the above example, range now spans from "<div>" to "under",
  11910. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  11911. // Picking out which child to recurse into here is a special case since we
  11912. // don't want to check past <q> -- once we find that the final range starts
  11913. // in <span>, we can look at all of its children (and all of their children)
  11914. // to find the break point.
  11915. // At all times, (bestContainer, bestOffset) is the latest single-line start
  11916. // point that we know of.
  11917. var currentContainer = bestContainer;
  11918. var maxIndexToConsider = bestOffset - 1;
  11919. do {
  11920. var nodeValue = currentContainer.nodeValue;
  11921. for (var ii = maxIndexToConsider; ii >= 0; ii--) {
  11922. if (nodeValue != null && ii > 0 && UnicodeUtils_1.isSurrogatePair(nodeValue, ii - 1)) {
  11923. // We're in the middle of a surrogate pair -- skip over so we never
  11924. // return a range with an endpoint in the middle of a code point.
  11925. continue;
  11926. }
  11927. range.setStart(currentContainer, ii);
  11928. if (areRectsOnOneLine(getRangeClientRects_1(range), lineHeight)) {
  11929. bestContainer = currentContainer;
  11930. bestOffset = ii;
  11931. } else {
  11932. break;
  11933. }
  11934. }
  11935. if (ii === -1 || currentContainer.childNodes.length === 0) {
  11936. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  11937. // (currentContainer, 0), was a single-line start point but a start
  11938. // point before currentContainer wasn't, so the line break seems to
  11939. // have occurred immediately after currentContainer's start tag
  11940. //
  11941. // If currentContainer.childNodes.length === 0, we're already at a
  11942. // terminal node (e.g., text node) and should return our current best.
  11943. break;
  11944. }
  11945. currentContainer = currentContainer.childNodes[ii];
  11946. maxIndexToConsider = getNodeLength$1(currentContainer);
  11947. } while (true);
  11948. range.setStart(bestContainer, bestOffset);
  11949. return range;
  11950. }
  11951. var expandRangeToStartOfLine_1 = expandRangeToStartOfLine;
  11952. /**
  11953. * Convert the current selection range to an anchor/focus pair of offset keys
  11954. * and values that can be interpreted by components.
  11955. */
  11956. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  11957. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  11958. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE;
  11959. // If the selection range lies only on text nodes, the task is simple.
  11960. // Find the nearest offset-aware elements and use the
  11961. // offset values supplied by the selection range.
  11962. if (anchorIsTextNode && focusIsTextNode) {
  11963. return {
  11964. selectionState: getUpdatedSelectionState_1(editorState, nullthrows_1(findAncestorOffsetKey_1(anchorNode)), anchorOffset, nullthrows_1(findAncestorOffsetKey_1(focusNode)), focusOffset),
  11965. needsRecovery: false
  11966. };
  11967. }
  11968. var anchorPoint = null;
  11969. var focusPoint = null;
  11970. var needsRecovery = true;
  11971. // An element is selected. Convert this selection range into leaf offset
  11972. // keys and offset values for consumption at the component level. This
  11973. // is common in Firefox, where select-all and triple click behavior leads
  11974. // to entire elements being selected.
  11975. //
  11976. // Note that we use the `needsRecovery` parameter in the callback here. This
  11977. // is because when certain elements are selected, the behavior for subsequent
  11978. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  11979. // expectations at the component level. For example, if an entire <div> is
  11980. // selected and the user presses the right arrow, Firefox keeps the selection
  11981. // on the <div>. If we allow subsequent keypresses to insert characters
  11982. // natively, they will be inserted into a browser-created text node to the
  11983. // right of that <div>. This is obviously undesirable.
  11984. //
  11985. // With the `needsRecovery` flag, we inform the caller that it is responsible
  11986. // for manually setting the selection state on the rendered document to
  11987. // ensure proper selection state maintenance.
  11988. if (anchorIsTextNode) {
  11989. anchorPoint = {
  11990. key: nullthrows_1(findAncestorOffsetKey_1(anchorNode)),
  11991. offset: anchorOffset
  11992. };
  11993. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  11994. } else if (focusIsTextNode) {
  11995. focusPoint = {
  11996. key: nullthrows_1(findAncestorOffsetKey_1(focusNode)),
  11997. offset: focusOffset
  11998. };
  11999. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12000. } else {
  12001. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  12002. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  12003. // If the selection is collapsed on an empty block, don't force recovery.
  12004. // This way, on arrow key selection changes, the browser can move the
  12005. // cursor from a non-zero offset on one block, through empty blocks,
  12006. // to a matching non-zero offset on other text blocks.
  12007. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  12008. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  12009. }
  12010. }
  12011. return {
  12012. selectionState: getUpdatedSelectionState_1(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  12013. needsRecovery: needsRecovery
  12014. };
  12015. }
  12016. /**
  12017. * Identify the first leaf descendant for the given node.
  12018. */
  12019. function getFirstLeaf(node) {
  12020. while (node.firstChild && (
  12021. // data-blocks has no offset
  12022. node.firstChild instanceof Element && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.firstChild))) {
  12023. node = node.firstChild;
  12024. }
  12025. return node;
  12026. }
  12027. /**
  12028. * Identify the last leaf descendant for the given node.
  12029. */
  12030. function getLastLeaf(node) {
  12031. while (node.lastChild && (
  12032. // data-blocks has no offset
  12033. node.lastChild instanceof Element && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode_1(node.lastChild))) {
  12034. node = node.lastChild;
  12035. }
  12036. return node;
  12037. }
  12038. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  12039. var node = startNode;
  12040. var offsetKey = findAncestorOffsetKey_1(node);
  12041. !(offsetKey != null || editorRoot && (editorRoot === node || editorRoot.firstChild === node)) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Unknown node in selection range.') : invariant_1(false) : void 0;
  12042. // If the editorRoot is the selection, step downward into the content
  12043. // wrapper.
  12044. if (editorRoot === node) {
  12045. node = node.firstChild;
  12046. !(node instanceof Element && node.getAttribute('data-contents') === 'true') ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid DraftEditorContents structure.') : invariant_1(false) : void 0;
  12047. if (childOffset > 0) {
  12048. childOffset = node.childNodes.length;
  12049. }
  12050. }
  12051. // If the child offset is zero and we have an offset key, we're done.
  12052. // If there's no offset key because the entire editor is selected,
  12053. // find the leftmost ("first") leaf in the tree and use that as the offset
  12054. // key.
  12055. if (childOffset === 0) {
  12056. var key = null;
  12057. if (offsetKey != null) {
  12058. key = offsetKey;
  12059. } else {
  12060. var firstLeaf = getFirstLeaf(node);
  12061. key = nullthrows_1(getSelectionOffsetKeyForNode_1(firstLeaf));
  12062. }
  12063. return { key: key, offset: 0 };
  12064. }
  12065. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  12066. var leafKey = null;
  12067. var textLength = null;
  12068. if (!getSelectionOffsetKeyForNode_1(nodeBeforeCursor)) {
  12069. // Our target node may be a leaf or a text node, in which case we're
  12070. // already where we want to be and can just use the child's length as
  12071. // our offset.
  12072. leafKey = nullthrows_1(offsetKey);
  12073. textLength = getTextContentLength(nodeBeforeCursor);
  12074. } else {
  12075. // Otherwise, we'll look at the child to the left of the cursor and find
  12076. // the last leaf node in its subtree.
  12077. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  12078. leafKey = nullthrows_1(getSelectionOffsetKeyForNode_1(lastLeaf));
  12079. textLength = getTextContentLength(lastLeaf);
  12080. }
  12081. return {
  12082. key: leafKey,
  12083. offset: textLength
  12084. };
  12085. }
  12086. /**
  12087. * Return the length of a node's textContent, regarding single newline
  12088. * characters as zero-length. This allows us to avoid problems with identifying
  12089. * the correct selection offset for empty blocks in IE, in which we
  12090. * render newlines instead of break tags.
  12091. */
  12092. function getTextContentLength(node) {
  12093. var textContent = node.textContent;
  12094. return textContent === '\n' ? 0 : textContent.length;
  12095. }
  12096. var getDraftEditorSelectionWithNodes_1 = getDraftEditorSelectionWithNodes;
  12097. /**
  12098. * Copyright (c) 2013-present, Facebook, Inc.
  12099. * All rights reserved.
  12100. *
  12101. * This source code is licensed under the BSD-style license found in the
  12102. * LICENSE file in the root directory of this source tree. An additional grant
  12103. * of patent rights can be found in the PATENTS file in the same directory.
  12104. *
  12105. * @providesModule moveSelectionBackward
  12106. * @format
  12107. *
  12108. */
  12109. /**
  12110. * Given a collapsed selection, move the focus `maxDistance` backward within
  12111. * the selected block. If the selection will go beyond the start of the block,
  12112. * move focus to the end of the previous block, but no further.
  12113. *
  12114. * This function is not Unicode-aware, so surrogate pairs will be treated
  12115. * as having length 2.
  12116. */
  12117. function moveSelectionBackward(editorState, maxDistance) {
  12118. var selection = editorState.getSelection();
  12119. var content = editorState.getCurrentContent();
  12120. var key = selection.getStartKey();
  12121. var offset = selection.getStartOffset();
  12122. var focusKey = key;
  12123. var focusOffset = 0;
  12124. if (maxDistance > offset) {
  12125. var keyBefore = content.getKeyBefore(key);
  12126. if (keyBefore == null) {
  12127. focusKey = key;
  12128. } else {
  12129. focusKey = keyBefore;
  12130. var blockBefore = content.getBlockForKey(keyBefore);
  12131. focusOffset = blockBefore.getText().length;
  12132. }
  12133. } else {
  12134. focusOffset = offset - maxDistance;
  12135. }
  12136. return selection.merge({
  12137. focusKey: focusKey,
  12138. focusOffset: focusOffset,
  12139. isBackward: true
  12140. });
  12141. }
  12142. var moveSelectionBackward_1 = moveSelectionBackward;
  12143. /**
  12144. * For a collapsed selection state, remove text based on the specified strategy.
  12145. * If the selection state is not collapsed, remove the entire selected range.
  12146. */
  12147. function removeTextWithStrategy(editorState, strategy, direction) {
  12148. var selection = editorState.getSelection();
  12149. var content = editorState.getCurrentContent();
  12150. var target = selection;
  12151. if (selection.isCollapsed()) {
  12152. if (direction === 'forward') {
  12153. if (editorState.isSelectionAtEndOfContent()) {
  12154. return content;
  12155. }
  12156. } else if (editorState.isSelectionAtStartOfContent()) {
  12157. return content;
  12158. }
  12159. target = strategy(editorState);
  12160. if (target === selection) {
  12161. return content;
  12162. }
  12163. }
  12164. return DraftModifier_1.removeRange(content, target, direction);
  12165. }
  12166. var removeTextWithStrategy_1 = removeTextWithStrategy;
  12167. function keyCommandBackspaceToStartOfLine(editorState) {
  12168. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12169. var selection = strategyState.getSelection();
  12170. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12171. return moveSelectionBackward_1(strategyState, 1);
  12172. }
  12173. var domSelection = _commonjsHelpers.commonjsGlobal.getSelection();
  12174. var range = domSelection.getRangeAt(0);
  12175. range = expandRangeToStartOfLine_1(range);
  12176. return getDraftEditorSelectionWithNodes_1(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12177. }, 'backward');
  12178. if (afterRemoval === editorState.getCurrentContent()) {
  12179. return editorState;
  12180. }
  12181. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12182. }
  12183. var keyCommandBackspaceToStartOfLine_1 = keyCommandBackspaceToStartOfLine;
  12184. /**
  12185. * Copyright (c) 2013-present, Facebook, Inc.
  12186. *
  12187. * This source code is licensed under the MIT license found in the
  12188. * LICENSE file in the root directory of this source tree.
  12189. *
  12190. * @typechecks
  12191. * @stub
  12192. *
  12193. */
  12194. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  12195. // is latin supplement punctuation except fractions and superscript
  12196. // numbers
  12197. // \u2010-\u2027\u2030-\u205e
  12198. // is punctuation from the general punctuation block:
  12199. // weird quotes, commas, bullets, dashes, etc.
  12200. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  12201. // is CJK punctuation
  12202. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  12203. // is some full-width/half-width punctuation
  12204. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  12205. // is some Arabic punctuation marks
  12206. // \u1801\u0964\u104a\u104b
  12207. // is misc. other language punctuation marks
  12208. var PUNCTUATION = '[.,+*?$|#{}()\'\\^\\-\\[\\]\\\\\\/!@%"~=<>_:;' + '\u30FB\u3001\u3002\u3008-\u3011\u3014-\u301F\uFF1A-\uFF1F\uFF01-\uFF0F' + '\uFF3B-\uFF40\uFF5B-\uFF65\u2E2E\u061F\u066A-\u066C\u061B\u060C\u060D' + '\uFD3E\uFD3F\u1801\u0964\u104A\u104B\u2010-\u2027\u2030-\u205E' + '\xA1-\xB1\xB4-\xB8\xBA\xBB\xBF]';
  12209. var TokenizeUtil = {
  12210. getPunctuation: function getPunctuation() {
  12211. return PUNCTUATION;
  12212. }
  12213. };
  12214. var punctuation = TokenizeUtil.getPunctuation();
  12215. // The apostrophe and curly single quotes behave in a curious way: when
  12216. // surrounded on both sides by word characters, they behave as word chars; when
  12217. // either neighbor is punctuation or an end of the string, they behave as
  12218. // punctuation.
  12219. var CHAMELEON_CHARS = '[\'\u2018\u2019]';
  12220. // Remove the underscore, which should count as part of the removable word. The
  12221. // "chameleon chars" also count as punctuation in this regex.
  12222. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  12223. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  12224. var DELETE_REGEX = new RegExp(DELETE_STRING);
  12225. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  12226. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  12227. function getRemovableWord(text, isBackward) {
  12228. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  12229. return matches ? matches[0] : text;
  12230. }
  12231. var DraftRemovableWord = {
  12232. getBackward: function getBackward(text) {
  12233. return getRemovableWord(text, true);
  12234. },
  12235. getForward: function getForward(text) {
  12236. return getRemovableWord(text, false);
  12237. }
  12238. };
  12239. var DraftRemovableWord_1 = DraftRemovableWord;
  12240. /**
  12241. * Delete the word that is left of the cursor, as well as any spaces or
  12242. * punctuation after the word.
  12243. */
  12244. function keyCommandBackspaceWord(editorState) {
  12245. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12246. var selection = strategyState.getSelection();
  12247. var offset = selection.getStartOffset();
  12248. // If there are no words before the cursor, remove the preceding newline.
  12249. if (offset === 0) {
  12250. return moveSelectionBackward_1(strategyState, 1);
  12251. }
  12252. var key = selection.getStartKey();
  12253. var content = strategyState.getCurrentContent();
  12254. var text = content.getBlockForKey(key).getText().slice(0, offset);
  12255. var toRemove = DraftRemovableWord_1.getBackward(text);
  12256. return moveSelectionBackward_1(strategyState, toRemove.length || 1);
  12257. }, 'backward');
  12258. if (afterRemoval === editorState.getCurrentContent()) {
  12259. return editorState;
  12260. }
  12261. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12262. }
  12263. var keyCommandBackspaceWord_1 = keyCommandBackspaceWord;
  12264. /**
  12265. * Copyright (c) 2013-present, Facebook, Inc.
  12266. * All rights reserved.
  12267. *
  12268. * This source code is licensed under the BSD-style license found in the
  12269. * LICENSE file in the root directory of this source tree. An additional grant
  12270. * of patent rights can be found in the PATENTS file in the same directory.
  12271. *
  12272. * @providesModule moveSelectionForward
  12273. * @format
  12274. *
  12275. */
  12276. /**
  12277. * Given a collapsed selection, move the focus `maxDistance` forward within
  12278. * the selected block. If the selection will go beyond the end of the block,
  12279. * move focus to the start of the next block, but no further.
  12280. *
  12281. * This function is not Unicode-aware, so surrogate pairs will be treated
  12282. * as having length 2.
  12283. */
  12284. function moveSelectionForward(editorState, maxDistance) {
  12285. var selection = editorState.getSelection();
  12286. var key = selection.getStartKey();
  12287. var offset = selection.getStartOffset();
  12288. var content = editorState.getCurrentContent();
  12289. var focusKey = key;
  12290. var focusOffset;
  12291. var block = content.getBlockForKey(key);
  12292. if (maxDistance > block.getText().length - offset) {
  12293. focusKey = content.getKeyAfter(key);
  12294. focusOffset = 0;
  12295. } else {
  12296. focusOffset = offset + maxDistance;
  12297. }
  12298. return selection.merge({ focusKey: focusKey, focusOffset: focusOffset });
  12299. }
  12300. var moveSelectionForward_1 = moveSelectionForward;
  12301. /**
  12302. * Delete the word that is right of the cursor, as well as any spaces or
  12303. * punctuation before the word.
  12304. */
  12305. function keyCommandDeleteWord(editorState) {
  12306. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12307. var selection = strategyState.getSelection();
  12308. var offset = selection.getStartOffset();
  12309. var key = selection.getStartKey();
  12310. var content = strategyState.getCurrentContent();
  12311. var text = content.getBlockForKey(key).getText().slice(offset);
  12312. var toRemove = DraftRemovableWord_1.getForward(text);
  12313. // If there are no words in front of the cursor, remove the newline.
  12314. return moveSelectionForward_1(strategyState, toRemove.length || 1);
  12315. }, 'forward');
  12316. if (afterRemoval === editorState.getCurrentContent()) {
  12317. return editorState;
  12318. }
  12319. return EditorState_1.push(editorState, afterRemoval, 'remove-range');
  12320. }
  12321. var keyCommandDeleteWord_1 = keyCommandDeleteWord;
  12322. function keyCommandInsertNewline(editorState) {
  12323. var contentState = DraftModifier_1.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  12324. return EditorState_1.push(editorState, contentState, 'split-block');
  12325. }
  12326. var keyCommandInsertNewline_1 = keyCommandInsertNewline;
  12327. /**
  12328. * See comment for `moveSelectionToStartOfBlock`.
  12329. */
  12330. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  12331. var selection = editorState.getSelection();
  12332. var endKey = selection.getEndKey();
  12333. var content = editorState.getCurrentContent();
  12334. var textLength = content.getBlockForKey(endKey).getLength();
  12335. return EditorState_1.set(editorState, {
  12336. selection: selection.merge({
  12337. anchorKey: endKey,
  12338. anchorOffset: textLength,
  12339. focusKey: endKey,
  12340. focusOffset: textLength,
  12341. isBackward: false
  12342. }),
  12343. forceSelection: true
  12344. });
  12345. }
  12346. var keyCommandMoveSelectionToEndOfBlock_1 = keyCommandMoveSelectionToEndOfBlock;
  12347. /**
  12348. * Collapse selection at the start of the first selected block. This is used
  12349. * for Firefox versions that attempt to navigate forward/backward instead of
  12350. * moving the cursor. Other browsers are able to move the cursor natively.
  12351. */
  12352. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  12353. var selection = editorState.getSelection();
  12354. var startKey = selection.getStartKey();
  12355. return EditorState_1.set(editorState, {
  12356. selection: selection.merge({
  12357. anchorKey: startKey,
  12358. anchorOffset: 0,
  12359. focusKey: startKey,
  12360. focusOffset: 0,
  12361. isBackward: false
  12362. }),
  12363. forceSelection: true
  12364. });
  12365. }
  12366. var keyCommandMoveSelectionToStartOfBlock_1 = keyCommandMoveSelectionToStartOfBlock;
  12367. /**
  12368. * Remove the selected range. If the cursor is collapsed, remove the preceding
  12369. * character. This operation is Unicode-aware, so removing a single character
  12370. * will remove a surrogate pair properly as well.
  12371. */
  12372. function keyCommandPlainBackspace(editorState) {
  12373. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12374. var selection = strategyState.getSelection();
  12375. var content = strategyState.getCurrentContent();
  12376. var key = selection.getAnchorKey();
  12377. var offset = selection.getAnchorOffset();
  12378. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  12379. return moveSelectionBackward_1(strategyState, charBehind ? UnicodeUtils_1.getUTF16Length(charBehind, 0) : 1);
  12380. }, 'backward');
  12381. if (afterRemoval === editorState.getCurrentContent()) {
  12382. return editorState;
  12383. }
  12384. var selection = editorState.getSelection();
  12385. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  12386. }
  12387. var keyCommandPlainBackspace_1 = keyCommandPlainBackspace;
  12388. /**
  12389. * Remove the selected range. If the cursor is collapsed, remove the following
  12390. * character. This operation is Unicode-aware, so removing a single character
  12391. * will remove a surrogate pair properly as well.
  12392. */
  12393. function keyCommandPlainDelete(editorState) {
  12394. var afterRemoval = removeTextWithStrategy_1(editorState, function (strategyState) {
  12395. var selection = strategyState.getSelection();
  12396. var content = strategyState.getCurrentContent();
  12397. var key = selection.getAnchorKey();
  12398. var offset = selection.getAnchorOffset();
  12399. var charAhead = content.getBlockForKey(key).getText()[offset];
  12400. return moveSelectionForward_1(strategyState, charAhead ? UnicodeUtils_1.getUTF16Length(charAhead, 0) : 1);
  12401. }, 'forward');
  12402. if (afterRemoval === editorState.getCurrentContent()) {
  12403. return editorState;
  12404. }
  12405. var selection = editorState.getSelection();
  12406. return EditorState_1.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  12407. }
  12408. var keyCommandPlainDelete_1 = keyCommandPlainDelete;
  12409. /**
  12410. * Transpose the characters on either side of a collapsed cursor, or
  12411. * if the cursor is at the end of the block, transpose the last two
  12412. * characters.
  12413. */
  12414. function keyCommandTransposeCharacters(editorState) {
  12415. var selection = editorState.getSelection();
  12416. if (!selection.isCollapsed()) {
  12417. return editorState;
  12418. }
  12419. var offset = selection.getAnchorOffset();
  12420. if (offset === 0) {
  12421. return editorState;
  12422. }
  12423. var blockKey = selection.getAnchorKey();
  12424. var content = editorState.getCurrentContent();
  12425. var block = content.getBlockForKey(blockKey);
  12426. var length = block.getLength();
  12427. // Nothing to transpose if there aren't two characters.
  12428. if (length <= 1) {
  12429. return editorState;
  12430. }
  12431. var removalRange;
  12432. var finalSelection;
  12433. if (offset === length) {
  12434. // The cursor is at the end of the block. Swap the last two characters.
  12435. removalRange = selection.set('anchorOffset', offset - 1);
  12436. finalSelection = selection;
  12437. } else {
  12438. removalRange = selection.set('focusOffset', offset + 1);
  12439. finalSelection = removalRange.set('anchorOffset', offset + 1);
  12440. }
  12441. // Extract the character to move as a fragment. This preserves its
  12442. // styling and entity, if any.
  12443. var movedFragment = getContentStateFragment_1(content, removalRange);
  12444. var afterRemoval = DraftModifier_1.removeRange(content, removalRange, 'backward');
  12445. // After the removal, the insertion target is one character back.
  12446. var selectionAfter = afterRemoval.getSelectionAfter();
  12447. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  12448. var targetRange = selectionAfter.merge({
  12449. anchorOffset: targetOffset,
  12450. focusOffset: targetOffset
  12451. });
  12452. var afterInsert = DraftModifier_1.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  12453. var newEditorState = EditorState_1.push(editorState, afterInsert, 'insert-fragment');
  12454. return EditorState_1.acceptSelection(newEditorState, finalSelection);
  12455. }
  12456. var keyCommandTransposeCharacters_1 = keyCommandTransposeCharacters;
  12457. function keyCommandUndo(e, editorState, updateFn) {
  12458. var undoneState = EditorState_1.undo(editorState);
  12459. // If the last change to occur was a spellcheck change, allow the undo
  12460. // event to fall through to the browser. This allows the browser to record
  12461. // the unwanted change, which should soon lead it to learn not to suggest
  12462. // the correction again.
  12463. if (editorState.getLastChangeType() === 'spellcheck-change') {
  12464. var nativelyRenderedContent = undoneState.getCurrentContent();
  12465. updateFn(EditorState_1.set(undoneState, { nativelyRenderedContent: nativelyRenderedContent }));
  12466. return;
  12467. }
  12468. // Otheriwse, manage the undo behavior manually.
  12469. e.preventDefault();
  12470. if (!editorState.getNativelyRenderedContent()) {
  12471. updateFn(undoneState);
  12472. return;
  12473. }
  12474. // Trigger a re-render with the current content state to ensure that the
  12475. // component tree has up-to-date props for comparison.
  12476. updateFn(EditorState_1.set(editorState, { nativelyRenderedContent: null }));
  12477. // Wait to ensure that the re-render has occurred before performing
  12478. // the undo action.
  12479. setTimeout(function () {
  12480. updateFn(undoneState);
  12481. }, 0);
  12482. }
  12483. var keyCommandUndo_1 = keyCommandUndo;
  12484. var isOptionKeyCommand = KeyBindingUtil_1.isOptionKeyCommand;
  12485. var isChrome$1 = UserAgent_1.isBrowser('Chrome');
  12486. /**
  12487. * Map a `DraftEditorCommand` command value to a corresponding function.
  12488. */
  12489. function onKeyCommand(command, editorState) {
  12490. switch (command) {
  12491. case 'redo':
  12492. return EditorState_1.redo(editorState);
  12493. case 'delete':
  12494. return keyCommandPlainDelete_1(editorState);
  12495. case 'delete-word':
  12496. return keyCommandDeleteWord_1(editorState);
  12497. case 'backspace':
  12498. return keyCommandPlainBackspace_1(editorState);
  12499. case 'backspace-word':
  12500. return keyCommandBackspaceWord_1(editorState);
  12501. case 'backspace-to-start-of-line':
  12502. return keyCommandBackspaceToStartOfLine_1(editorState);
  12503. case 'split-block':
  12504. return keyCommandInsertNewline_1(editorState);
  12505. case 'transpose-characters':
  12506. return keyCommandTransposeCharacters_1(editorState);
  12507. case 'move-selection-to-start-of-block':
  12508. return keyCommandMoveSelectionToStartOfBlock_1(editorState);
  12509. case 'move-selection-to-end-of-block':
  12510. return keyCommandMoveSelectionToEndOfBlock_1(editorState);
  12511. case 'secondary-cut':
  12512. return SecondaryClipboard_1.cut(editorState);
  12513. case 'secondary-paste':
  12514. return SecondaryClipboard_1.paste(editorState);
  12515. default:
  12516. return editorState;
  12517. }
  12518. }
  12519. /**
  12520. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12521. *
  12522. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12523. * correspond to command functions that modify the editor or its contents.
  12524. *
  12525. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12526. * component may provide a custom mapping via the `keyBindingFn` prop.
  12527. */
  12528. function editOnKeyDown(editor, e) {
  12529. var keyCode = e.which;
  12530. var editorState = editor._latestEditorState;
  12531. switch (keyCode) {
  12532. case Keys.RETURN:
  12533. e.preventDefault();
  12534. // The top-level component may manually handle newline insertion. If
  12535. // no special handling is performed, fall through to command handling.
  12536. if (editor.props.handleReturn && isEventHandled_1(editor.props.handleReturn(e, editorState))) {
  12537. return;
  12538. }
  12539. break;
  12540. case Keys.ESC:
  12541. e.preventDefault();
  12542. editor.props.onEscape && editor.props.onEscape(e);
  12543. return;
  12544. case Keys.TAB:
  12545. editor.props.onTab && editor.props.onTab(e);
  12546. return;
  12547. case Keys.UP:
  12548. editor.props.onUpArrow && editor.props.onUpArrow(e);
  12549. return;
  12550. case Keys.RIGHT:
  12551. editor.props.onRightArrow && editor.props.onRightArrow(e);
  12552. return;
  12553. case Keys.DOWN:
  12554. editor.props.onDownArrow && editor.props.onDownArrow(e);
  12555. return;
  12556. case Keys.LEFT:
  12557. editor.props.onLeftArrow && editor.props.onLeftArrow(e);
  12558. return;
  12559. case Keys.SPACE:
  12560. // Handling for OSX where option + space scrolls.
  12561. if (isChrome$1 && isOptionKeyCommand(e)) {
  12562. e.preventDefault();
  12563. // Insert a nbsp into the editor.
  12564. var contentState = DraftModifier_1.replaceText(editorState.getCurrentContent(), editorState.getSelection(), '\xA0');
  12565. editor.update(EditorState_1.push(editorState, contentState, 'insert-characters'));
  12566. return;
  12567. }
  12568. }
  12569. var command = editor.props.keyBindingFn(e);
  12570. // If no command is specified, allow keydown event to continue.
  12571. if (!command) {
  12572. return;
  12573. }
  12574. if (command === 'undo') {
  12575. // Since undo requires some special updating behavior to keep the editor
  12576. // in sync, handle it separately.
  12577. keyCommandUndo_1(e, editorState, editor.update);
  12578. return;
  12579. }
  12580. // At this point, we know that we're handling a command of some kind, so
  12581. // we don't want to insert a character following the keydown.
  12582. e.preventDefault();
  12583. // Allow components higher up the tree to handle the command first.
  12584. if (editor.props.handleKeyCommand && isEventHandled_1(editor.props.handleKeyCommand(command, editorState))) {
  12585. return;
  12586. }
  12587. var newState = onKeyCommand(command, editorState);
  12588. if (newState !== editorState) {
  12589. editor.update(newState);
  12590. }
  12591. }
  12592. var editOnKeyDown_1 = editOnKeyDown;
  12593. /**
  12594. * Copyright (c) 2013-present, Facebook, Inc.
  12595. *
  12596. * This source code is licensed under the MIT license found in the
  12597. * LICENSE file in the root directory of this source tree.
  12598. *
  12599. *
  12600. */
  12601. function _classCallCheck$e(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12602. var URI = function () {
  12603. function URI(uri) {
  12604. _classCallCheck$e(this, URI);
  12605. this._uri = uri;
  12606. }
  12607. URI.prototype.toString = function toString() {
  12608. return this._uri;
  12609. };
  12610. return URI;
  12611. }();
  12612. var URI_1 = URI;
  12613. var isOldIE = UserAgent_1.isBrowser('IE <= 9');
  12614. // Provides a dom node that will not execute scripts
  12615. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  12616. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  12617. function getSafeBodyFromHTML(html) {
  12618. var doc;
  12619. var root = null;
  12620. // Provides a safe context
  12621. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  12622. doc = document.implementation.createHTMLDocument('foo');
  12623. !doc.documentElement ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing doc.documentElement') : invariant_1(false) : void 0;
  12624. doc.documentElement.innerHTML = html;
  12625. root = doc.getElementsByTagName('body')[0];
  12626. }
  12627. return root;
  12628. }
  12629. var getSafeBodyFromHTML_1 = getSafeBodyFromHTML;
  12630. var _extends$4 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  12631. var _knownListItemDepthCl;
  12632. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  12633. var _require = immutable,
  12634. Set = _require.Set;
  12635. var experimentalTreeDataSupport = DraftFeatureFlags_1.draft_tree_data_support;
  12636. var List$a = immutable.List,
  12637. OrderedSet$5 = immutable.OrderedSet;
  12638. var NBSP = '&nbsp;';
  12639. var SPACE = ' ';
  12640. // Arbitrary max indent
  12641. var MAX_DEPTH = 4;
  12642. // used for replacing characters in HTML
  12643. var REGEX_CR = new RegExp('\r', 'g');
  12644. var REGEX_LF = new RegExp('\n', 'g');
  12645. var REGEX_NBSP = new RegExp(NBSP, 'g');
  12646. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  12647. var REGEX_ZWS = new RegExp('&#8203;?', 'g');
  12648. // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  12649. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  12650. var notBoldValues = ['light', 'lighter', '100', '200', '300', '400'];
  12651. // Block tag flow is different because LIs do not have
  12652. // a deterministic style ;_;
  12653. var inlineTags = {
  12654. b: 'BOLD',
  12655. code: 'CODE',
  12656. del: 'STRIKETHROUGH',
  12657. em: 'ITALIC',
  12658. i: 'ITALIC',
  12659. s: 'STRIKETHROUGH',
  12660. strike: 'STRIKETHROUGH',
  12661. strong: 'BOLD',
  12662. u: 'UNDERLINE'
  12663. };
  12664. var knownListItemDepthClasses = (_knownListItemDepthCl = {}, _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth0'), 0), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth1'), 1), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth2'), 2), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth3'), 3), _defineProperty(_knownListItemDepthCl, cx_1('public/DraftStyleDefault/depth4'), 4), _knownListItemDepthCl);
  12665. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  12666. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  12667. var lastBlock = void 0;
  12668. var EMPTY_CHUNK = {
  12669. text: '',
  12670. inlines: [],
  12671. entities: [],
  12672. blocks: []
  12673. };
  12674. var EMPTY_BLOCK = {
  12675. children: List$a(),
  12676. depth: 0,
  12677. key: '',
  12678. type: ''
  12679. };
  12680. var getListBlockType = function getListBlockType(tag, lastList) {
  12681. if (tag === 'li') {
  12682. return lastList === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  12683. }
  12684. return null;
  12685. };
  12686. var getBlockMapSupportedTags = function getBlockMapSupportedTags(blockRenderMap) {
  12687. var unstyledElement = blockRenderMap.get('unstyled').element;
  12688. var tags = Set([]);
  12689. blockRenderMap.forEach(function (draftBlock) {
  12690. if (draftBlock.aliasedElements) {
  12691. draftBlock.aliasedElements.forEach(function (tag) {
  12692. tags = tags.add(tag);
  12693. });
  12694. }
  12695. tags = tags.add(draftBlock.element);
  12696. });
  12697. return tags.filter(function (tag) {
  12698. return tag && tag !== unstyledElement;
  12699. }).toArray().sort();
  12700. };
  12701. // custom element conversions
  12702. var getMultiMatchedType = function getMultiMatchedType(tag, lastList, multiMatchExtractor) {
  12703. for (var ii = 0; ii < multiMatchExtractor.length; ii++) {
  12704. var matchType = multiMatchExtractor[ii](tag, lastList);
  12705. if (matchType) {
  12706. return matchType;
  12707. }
  12708. }
  12709. return null;
  12710. };
  12711. var getBlockTypeForTag = function getBlockTypeForTag(tag, lastList, blockRenderMap) {
  12712. var matchedTypes = blockRenderMap.filter(function (draftBlock) {
  12713. return draftBlock.element === tag || draftBlock.wrapper === tag || draftBlock.aliasedElements && draftBlock.aliasedElements.some(function (alias) {
  12714. return alias === tag;
  12715. });
  12716. }).keySeq().toSet().toArray().sort();
  12717. // if we dont have any matched type, return unstyled
  12718. // if we have one matched type return it
  12719. // if we have multi matched types use the multi-match function to gather type
  12720. switch (matchedTypes.length) {
  12721. case 0:
  12722. return 'unstyled';
  12723. case 1:
  12724. return matchedTypes[0];
  12725. default:
  12726. return getMultiMatchedType(tag, lastList, [getListBlockType]) || 'unstyled';
  12727. }
  12728. };
  12729. var processInlineTag = function processInlineTag(tag, node, currentStyle) {
  12730. var styleToCheck = inlineTags[tag];
  12731. if (styleToCheck) {
  12732. currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
  12733. } else if (node instanceof HTMLElement) {
  12734. var htmlElement = node;
  12735. currentStyle = currentStyle.withMutations(function (style) {
  12736. var fontWeight = htmlElement.style.fontWeight;
  12737. var fontStyle = htmlElement.style.fontStyle;
  12738. var textDecoration = htmlElement.style.textDecoration;
  12739. if (boldValues.indexOf(fontWeight) >= 0) {
  12740. style.add('BOLD');
  12741. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  12742. style.remove('BOLD');
  12743. }
  12744. if (fontStyle === 'italic') {
  12745. style.add('ITALIC');
  12746. } else if (fontStyle === 'normal') {
  12747. style.remove('ITALIC');
  12748. }
  12749. if (textDecoration === 'underline') {
  12750. style.add('UNDERLINE');
  12751. }
  12752. if (textDecoration === 'line-through') {
  12753. style.add('STRIKETHROUGH');
  12754. }
  12755. if (textDecoration === 'none') {
  12756. style.remove('UNDERLINE');
  12757. style.remove('STRIKETHROUGH');
  12758. }
  12759. }).toOrderedSet();
  12760. }
  12761. return currentStyle;
  12762. };
  12763. var joinChunks = function joinChunks(A, B, experimentalHasNestedBlocks) {
  12764. // Sometimes two blocks will touch in the DOM and we need to strip the
  12765. // extra delimiter to preserve niceness.
  12766. var lastInA = A.text.slice(-1);
  12767. var firstInB = B.text.slice(0, 1);
  12768. if (lastInA === '\r' && firstInB === '\r' && !experimentalHasNestedBlocks) {
  12769. A.text = A.text.slice(0, -1);
  12770. A.inlines.pop();
  12771. A.entities.pop();
  12772. A.blocks.pop();
  12773. }
  12774. // Kill whitespace after blocks
  12775. if (lastInA === '\r') {
  12776. if (B.text === SPACE || B.text === '\n') {
  12777. return A;
  12778. } else if (firstInB === SPACE || firstInB === '\n') {
  12779. B.text = B.text.slice(1);
  12780. B.inlines.shift();
  12781. B.entities.shift();
  12782. }
  12783. }
  12784. return {
  12785. text: A.text + B.text,
  12786. inlines: A.inlines.concat(B.inlines),
  12787. entities: A.entities.concat(B.entities),
  12788. blocks: A.blocks.concat(B.blocks)
  12789. };
  12790. };
  12791. /**
  12792. * Check to see if we have anything like <p> <blockquote> <h1>... to create
  12793. * block tags from. If we do, we can use those and ignore <div> tags. If we
  12794. * don't, we can treat <div> tags as meaningful (unstyled) blocks.
  12795. */
  12796. var containsSemanticBlockMarkup = function containsSemanticBlockMarkup(html, blockTags) {
  12797. return blockTags.some(function (tag) {
  12798. return html.indexOf('<' + tag) !== -1;
  12799. });
  12800. };
  12801. var hasValidLinkText = function hasValidLinkText(link) {
  12802. !(link instanceof HTMLAnchorElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Link must be an HTMLAnchorElement.') : invariant_1(false) : void 0;
  12803. var protocol = link.protocol;
  12804. return protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:';
  12805. };
  12806. var getWhitespaceChunk = function getWhitespaceChunk(inEntity) {
  12807. var entities = new Array(1);
  12808. if (inEntity) {
  12809. entities[0] = inEntity;
  12810. }
  12811. return _extends$4({}, EMPTY_CHUNK, {
  12812. text: SPACE,
  12813. inlines: [OrderedSet$5()],
  12814. entities: entities
  12815. });
  12816. };
  12817. var getSoftNewlineChunk = function getSoftNewlineChunk() {
  12818. return _extends$4({}, EMPTY_CHUNK, {
  12819. text: '\n',
  12820. inlines: [OrderedSet$5()],
  12821. entities: new Array(1)
  12822. });
  12823. };
  12824. var getChunkedBlock = function getChunkedBlock() {
  12825. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  12826. return _extends$4({}, EMPTY_BLOCK, props);
  12827. };
  12828. var getBlockDividerChunk = function getBlockDividerChunk(block, depth) {
  12829. var parentKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  12830. return {
  12831. text: '\r',
  12832. inlines: [OrderedSet$5()],
  12833. entities: new Array(1),
  12834. blocks: [getChunkedBlock({
  12835. parent: parentKey,
  12836. key: generateRandomKey_1(),
  12837. type: block,
  12838. depth: Math.max(0, Math.min(MAX_DEPTH, depth))
  12839. })]
  12840. };
  12841. };
  12842. /**
  12843. * If we're pasting from one DraftEditor to another we can check to see if
  12844. * existing list item depth classes are being used and preserve this style
  12845. */
  12846. var getListItemDepth = function getListItemDepth(node) {
  12847. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  12848. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  12849. if (node.classList.contains(depthClass)) {
  12850. depth = knownListItemDepthClasses[depthClass];
  12851. }
  12852. });
  12853. return depth;
  12854. };
  12855. var genFragment = function genFragment(entityMap, node, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, inEntity, parentKey) {
  12856. var lastLastBlock = lastBlock;
  12857. var nodeName = node.nodeName.toLowerCase();
  12858. var newEntityMap = entityMap;
  12859. var nextBlockType = 'unstyled';
  12860. var newBlock = false;
  12861. var inBlockType = inBlock && getBlockTypeForTag(inBlock, lastList, blockRenderMap);
  12862. var chunk = _extends$4({}, EMPTY_CHUNK);
  12863. var newChunk = null;
  12864. var blockKey = void 0;
  12865. // Base Case
  12866. if (nodeName === '#text') {
  12867. var _text = node.textContent;
  12868. var nodeTextContent = _text.trim();
  12869. // We should not create blocks for leading spaces that are
  12870. // existing around ol/ul and their children list items
  12871. if (lastList && nodeTextContent === '' && node.parentElement) {
  12872. var parentNodeName = node.parentElement.nodeName.toLowerCase();
  12873. if (parentNodeName === 'ol' || parentNodeName === 'ul') {
  12874. return { chunk: _extends$4({}, EMPTY_CHUNK), entityMap: entityMap };
  12875. }
  12876. }
  12877. if (nodeTextContent === '' && inBlock !== 'pre') {
  12878. return { chunk: getWhitespaceChunk(inEntity), entityMap: entityMap };
  12879. }
  12880. if (inBlock !== 'pre') {
  12881. // Can't use empty string because MSWord
  12882. _text = _text.replace(REGEX_LF, SPACE);
  12883. }
  12884. // save the last block so we can use it later
  12885. lastBlock = nodeName;
  12886. return {
  12887. chunk: {
  12888. text: _text,
  12889. inlines: Array(_text.length).fill(inlineStyle),
  12890. entities: Array(_text.length).fill(inEntity),
  12891. blocks: []
  12892. },
  12893. entityMap: entityMap
  12894. };
  12895. }
  12896. // save the last block so we can use it later
  12897. lastBlock = nodeName;
  12898. // BR tags
  12899. if (nodeName === 'br') {
  12900. if (lastLastBlock === 'br' && (!inBlock || inBlockType === 'unstyled')) {
  12901. return {
  12902. chunk: getBlockDividerChunk('unstyled', depth, parentKey),
  12903. entityMap: entityMap
  12904. };
  12905. }
  12906. return { chunk: getSoftNewlineChunk(), entityMap: entityMap };
  12907. }
  12908. // IMG tags
  12909. if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) {
  12910. var image = node;
  12911. var entityConfig = {};
  12912. imgAttr.forEach(function (attr) {
  12913. var imageAttribute = image.getAttribute(attr);
  12914. if (imageAttribute) {
  12915. entityConfig[attr] = imageAttribute;
  12916. }
  12917. });
  12918. // Forcing this node to have children because otherwise no entity will be
  12919. // created for this node.
  12920. // The child text node cannot just have a space or return as content -
  12921. // we strip those out.
  12922. // See https://github.com/facebook/draft-js/issues/231 for some context.
  12923. node.textContent = '\uD83D\uDCF7';
  12924. // TODO: update this when we remove DraftEntity entirely
  12925. inEntity = DraftEntity_1.__create('IMAGE', 'MUTABLE', entityConfig || {});
  12926. }
  12927. // Inline tags
  12928. inlineStyle = processInlineTag(nodeName, node, inlineStyle);
  12929. // Handle lists
  12930. if (nodeName === 'ul' || nodeName === 'ol') {
  12931. if (lastList) {
  12932. depth += 1;
  12933. }
  12934. lastList = nodeName;
  12935. }
  12936. if ( nodeName === 'li' && node instanceof HTMLElement) {
  12937. depth = getListItemDepth(node, depth);
  12938. }
  12939. var blockType = getBlockTypeForTag(nodeName, lastList, blockRenderMap);
  12940. var inListBlock = lastList && inBlock === 'li' && nodeName === 'li';
  12941. var inBlockOrHasNestedBlocks = (!inBlock || experimentalTreeDataSupport) && blockTags.indexOf(nodeName) !== -1;
  12942. // Block Tags
  12943. if (inListBlock || inBlockOrHasNestedBlocks) {
  12944. chunk = getBlockDividerChunk(blockType, depth, parentKey);
  12945. blockKey = chunk.blocks[0].key;
  12946. inBlock = nodeName;
  12947. newBlock = !experimentalTreeDataSupport;
  12948. }
  12949. // this is required so that we can handle 'ul' and 'ol'
  12950. if (inListBlock) {
  12951. nextBlockType = lastList === 'ul' ? 'unordered-list-item' : 'ordered-list-item';
  12952. }
  12953. // Recurse through children
  12954. var child = node.firstChild;
  12955. if (child != null) {
  12956. nodeName = child.nodeName.toLowerCase();
  12957. }
  12958. var entityId = null;
  12959. while (child) {
  12960. if (child instanceof HTMLAnchorElement && child.href && hasValidLinkText(child)) {
  12961. (function () {
  12962. var anchor = child;
  12963. var entityConfig = {};
  12964. anchorAttr.forEach(function (attr) {
  12965. var anchorAttribute = anchor.getAttribute(attr);
  12966. if (anchorAttribute) {
  12967. entityConfig[attr] = anchorAttribute;
  12968. }
  12969. });
  12970. entityConfig.url = new URI_1(anchor.href).toString();
  12971. // TODO: update this when we remove DraftEntity completely
  12972. entityId = DraftEntity_1.__create('LINK', 'MUTABLE', entityConfig || {});
  12973. })();
  12974. } else {
  12975. entityId = undefined;
  12976. }
  12977. var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity, null),
  12978. generatedChunk = _genFragment.chunk,
  12979. maybeUpdatedEntityMap = _genFragment.entityMap;
  12980. newChunk = generatedChunk;
  12981. newEntityMap = maybeUpdatedEntityMap;
  12982. chunk = joinChunks(chunk, newChunk, experimentalTreeDataSupport);
  12983. var sibling = child.nextSibling;
  12984. // Put in a newline to break up blocks inside blocks
  12985. if (!parentKey && sibling && blockTags.indexOf(nodeName) >= 0 && inBlock) {
  12986. chunk = joinChunks(chunk, getSoftNewlineChunk());
  12987. }
  12988. if (sibling) {
  12989. nodeName = sibling.nodeName.toLowerCase();
  12990. }
  12991. child = sibling;
  12992. }
  12993. if (newBlock) {
  12994. chunk = joinChunks(chunk, getBlockDividerChunk(nextBlockType, depth, parentKey));
  12995. }
  12996. return { chunk: chunk, entityMap: newEntityMap };
  12997. };
  12998. var getChunkForHTML = function getChunkForHTML(html, DOMBuilder, blockRenderMap, entityMap) {
  12999. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, '');
  13000. var supportedBlockTags = getBlockMapSupportedTags(blockRenderMap);
  13001. var safeBody = DOMBuilder(html);
  13002. if (!safeBody) {
  13003. return null;
  13004. }
  13005. lastBlock = null;
  13006. // Sometimes we aren't dealing with content that contains nice semantic
  13007. // tags. In this case, use divs to separate everything out into paragraphs
  13008. // and hope for the best.
  13009. var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? supportedBlockTags : ['div'];
  13010. // Start with -1 block depth to offset the fact that we are passing in a fake
  13011. // UL block to start with.
  13012. var fragment = genFragment(entityMap, safeBody, OrderedSet$5(), 'ul', null, workingBlocks, -1, blockRenderMap);
  13013. var chunk = fragment.chunk;
  13014. var newEntityMap = fragment.entityMap;
  13015. // join with previous block to prevent weirdness on paste
  13016. if (chunk.text.indexOf('\r') === 0) {
  13017. chunk = {
  13018. text: chunk.text.slice(1),
  13019. inlines: chunk.inlines.slice(1),
  13020. entities: chunk.entities.slice(1),
  13021. blocks: chunk.blocks
  13022. };
  13023. }
  13024. // Kill block delimiter at the end
  13025. if (chunk.text.slice(-1) === '\r') {
  13026. chunk.text = chunk.text.slice(0, -1);
  13027. chunk.inlines = chunk.inlines.slice(0, -1);
  13028. chunk.entities = chunk.entities.slice(0, -1);
  13029. chunk.blocks.pop();
  13030. }
  13031. // If we saw no block tags, put an unstyled one in
  13032. if (chunk.blocks.length === 0) {
  13033. chunk.blocks.push(_extends$4({}, EMPTY_CHUNK, {
  13034. type: 'unstyled',
  13035. depth: 0
  13036. }));
  13037. }
  13038. // Sometimes we start with text that isn't in a block, which is then
  13039. // followed by blocks. Need to fix up the blocks to add in
  13040. // an unstyled block for this content
  13041. if (chunk.text.split('\r').length === chunk.blocks.length + 1) {
  13042. chunk.blocks.unshift({ type: 'unstyled', depth: 0 });
  13043. }
  13044. return { chunk: chunk, entityMap: newEntityMap };
  13045. };
  13046. var convertChunkToContentBlocks = function convertChunkToContentBlocks(chunk) {
  13047. if (!chunk || !chunk.text || !Array.isArray(chunk.blocks)) {
  13048. return null;
  13049. }
  13050. var initialState = {
  13051. cacheRef: {},
  13052. contentBlocks: []
  13053. };
  13054. var start = 0;
  13055. var rawBlocks = chunk.blocks,
  13056. rawInlines = chunk.inlines,
  13057. rawEntities = chunk.entities;
  13058. var BlockNodeRecord = ContentBlock_1;
  13059. return chunk.text.split('\r').reduce(function (acc, textBlock, index) {
  13060. // Make absolutely certain that our text is acceptable.
  13061. textBlock = sanitizeDraftText_1(textBlock);
  13062. var block = rawBlocks[index];
  13063. var end = start + textBlock.length;
  13064. var inlines = rawInlines.slice(start, end);
  13065. var entities = rawEntities.slice(start, end);
  13066. var characterList = List$a(inlines.map(function (style, index) {
  13067. var data = { style: style, entity: null };
  13068. if (entities[index]) {
  13069. data.entity = entities[index];
  13070. }
  13071. return CharacterMetadata_1.create(data);
  13072. }));
  13073. start = end + 1;
  13074. var depth = block.depth,
  13075. type = block.type,
  13076. parent = block.parent;
  13077. var key = block.key || generateRandomKey_1();
  13078. var parentTextNodeKey = null; // will be used to store container text nodes
  13079. // childrens add themselves to their parents since we are iterating in order
  13080. if (parent) {
  13081. var parentIndex = acc.cacheRef[parent];
  13082. var parentRecord = acc.contentBlocks[parentIndex];
  13083. // if parent has text we need to split it into a separate unstyled element
  13084. if (parentRecord.getChildKeys().isEmpty() && parentRecord.getText()) {
  13085. var parentCharacterList = parentRecord.getCharacterList();
  13086. var parentText = parentRecord.getText();
  13087. parentTextNodeKey = generateRandomKey_1();
  13088. var textNode = new ContentBlockNode_1({
  13089. key: parentTextNodeKey,
  13090. text: parentText,
  13091. characterList: parentCharacterList,
  13092. parent: parent,
  13093. nextSibling: key
  13094. });
  13095. acc.contentBlocks.push(textNode);
  13096. parentRecord = parentRecord.withMutations(function (block) {
  13097. block.set('characterList', List$a()).set('text', '').set('children', parentRecord.children.push(textNode.getKey()));
  13098. });
  13099. }
  13100. acc.contentBlocks[parentIndex] = parentRecord.set('children', parentRecord.children.push(key));
  13101. }
  13102. var blockNode = new BlockNodeRecord({
  13103. key: key,
  13104. parent: parent,
  13105. type: type,
  13106. depth: depth,
  13107. text: textBlock,
  13108. characterList: characterList,
  13109. prevSibling: parentTextNodeKey || (index === 0 || rawBlocks[index - 1].parent !== parent ? null : rawBlocks[index - 1].key),
  13110. nextSibling: index === rawBlocks.length - 1 || rawBlocks[index + 1].parent !== parent ? null : rawBlocks[index + 1].key
  13111. });
  13112. // insert node
  13113. acc.contentBlocks.push(blockNode);
  13114. // cache ref for building links
  13115. acc.cacheRef[blockNode.key] = index;
  13116. return acc;
  13117. }, initialState).contentBlocks;
  13118. };
  13119. var convertFromHTMLtoContentBlocks = function convertFromHTMLtoContentBlocks(html) {
  13120. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML_1;
  13121. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap_1;
  13122. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  13123. // arbitrary code in whatever environment you're running this in. For an
  13124. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  13125. // TODO: replace DraftEntity with an OrderedMap here
  13126. var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity_1);
  13127. if (chunkData == null) {
  13128. return null;
  13129. }
  13130. var chunk = chunkData.chunk,
  13131. entityMap = chunkData.entityMap;
  13132. var contentBlocks = convertChunkToContentBlocks(chunk);
  13133. return {
  13134. contentBlocks: contentBlocks,
  13135. entityMap: entityMap
  13136. };
  13137. };
  13138. var convertFromHTMLToContentBlocks = convertFromHTMLtoContentBlocks;
  13139. var List$b = immutable.List,
  13140. Repeat$6 = immutable.Repeat;
  13141. var ContentBlockRecord$2 = ContentBlock_1;
  13142. var DraftPasteProcessor = {
  13143. processHTML: function processHTML(html, blockRenderMap) {
  13144. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML_1, blockRenderMap);
  13145. },
  13146. processText: function processText(textBlocks, character, type) {
  13147. return textBlocks.reduce(function (acc, textLine, index) {
  13148. textLine = sanitizeDraftText_1(textLine);
  13149. var key = generateRandomKey_1();
  13150. var blockNodeConfig = {
  13151. key: key,
  13152. type: type,
  13153. text: textLine,
  13154. characterList: List$b(Repeat$6(character, textLine.length))
  13155. };
  13156. acc.push(new ContentBlockRecord$2(blockNodeConfig));
  13157. return acc;
  13158. }, []);
  13159. }
  13160. };
  13161. var DraftPasteProcessor_1 = DraftPasteProcessor;
  13162. /**
  13163. * Copyright (c) 2013-present, Facebook, Inc.
  13164. * All rights reserved.
  13165. *
  13166. * This source code is licensed under the BSD-style license found in the
  13167. * LICENSE file in the root directory of this source tree. An additional grant
  13168. * of patent rights can be found in the PATENTS file in the same directory.
  13169. *
  13170. * @providesModule adjustBlockDepthForContentState
  13171. * @format
  13172. *
  13173. */
  13174. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13175. var startKey = selectionState.getStartKey();
  13176. var endKey = selectionState.getEndKey();
  13177. var blockMap = contentState.getBlockMap();
  13178. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13179. return k === startKey;
  13180. }).takeUntil(function (_, k) {
  13181. return k === endKey;
  13182. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13183. var depth = block.getDepth() + adjustment;
  13184. depth = Math.max(0, Math.min(depth, maxDepth));
  13185. return block.set('depth', depth);
  13186. });
  13187. blockMap = blockMap.merge(blocks);
  13188. return contentState.merge({
  13189. blockMap: blockMap,
  13190. selectionBefore: selectionState,
  13191. selectionAfter: selectionState
  13192. });
  13193. }
  13194. var adjustBlockDepthForContentState_1 = adjustBlockDepthForContentState;
  13195. var RichTextEditorUtil = {
  13196. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  13197. var selection = editorState.getSelection();
  13198. var contentState = editorState.getCurrentContent();
  13199. var entityMap = contentState.getEntityMap();
  13200. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  13201. var entity = v.getEntity();
  13202. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  13203. });
  13204. },
  13205. getCurrentBlockType: function getCurrentBlockType(editorState) {
  13206. var selection = editorState.getSelection();
  13207. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  13208. },
  13209. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  13210. return { url: uri.toString() };
  13211. },
  13212. handleKeyCommand: function handleKeyCommand(editorState, command) {
  13213. switch (command) {
  13214. case 'bold':
  13215. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  13216. case 'italic':
  13217. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  13218. case 'underline':
  13219. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  13220. case 'code':
  13221. return RichTextEditorUtil.toggleCode(editorState);
  13222. case 'backspace':
  13223. case 'backspace-word':
  13224. case 'backspace-to-start-of-line':
  13225. return RichTextEditorUtil.onBackspace(editorState);
  13226. case 'delete':
  13227. case 'delete-word':
  13228. case 'delete-to-end-of-block':
  13229. return RichTextEditorUtil.onDelete(editorState);
  13230. default:
  13231. // they may have custom editor commands; ignore those
  13232. return null;
  13233. }
  13234. },
  13235. insertSoftNewline: function insertSoftNewline(editorState) {
  13236. var contentState = DraftModifier_1.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  13237. var newEditorState = EditorState_1.push(editorState, contentState, 'insert-characters');
  13238. return EditorState_1.forceSelection(newEditorState, contentState.getSelectionAfter());
  13239. },
  13240. /**
  13241. * For collapsed selections at the start of styled blocks, backspace should
  13242. * just remove the existing style.
  13243. */
  13244. onBackspace: function onBackspace(editorState) {
  13245. var selection = editorState.getSelection();
  13246. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  13247. return null;
  13248. }
  13249. // First, try to remove a preceding atomic block.
  13250. var content = editorState.getCurrentContent();
  13251. var startKey = selection.getStartKey();
  13252. var blockBefore = content.getBlockBefore(startKey);
  13253. if (blockBefore && blockBefore.getType() === 'atomic') {
  13254. var blockMap = content.getBlockMap()['delete'](blockBefore.getKey());
  13255. var withoutAtomicBlock = content.merge({
  13256. blockMap: blockMap,
  13257. selectionAfter: selection
  13258. });
  13259. if (withoutAtomicBlock !== content) {
  13260. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13261. }
  13262. }
  13263. // If that doesn't succeed, try to remove the current block style.
  13264. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  13265. if (withoutBlockStyle) {
  13266. return EditorState_1.push(editorState, withoutBlockStyle, 'change-block-type');
  13267. }
  13268. return null;
  13269. },
  13270. onDelete: function onDelete(editorState) {
  13271. var selection = editorState.getSelection();
  13272. if (!selection.isCollapsed()) {
  13273. return null;
  13274. }
  13275. var content = editorState.getCurrentContent();
  13276. var startKey = selection.getStartKey();
  13277. var block = content.getBlockForKey(startKey);
  13278. var length = block.getLength();
  13279. // The cursor is somewhere within the text. Behave normally.
  13280. if (selection.getStartOffset() < length) {
  13281. return null;
  13282. }
  13283. var blockAfter = content.getBlockAfter(startKey);
  13284. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  13285. return null;
  13286. }
  13287. var atomicBlockTarget = selection.merge({
  13288. focusKey: blockAfter.getKey(),
  13289. focusOffset: blockAfter.getLength()
  13290. });
  13291. var withoutAtomicBlock = DraftModifier_1.removeRange(content, atomicBlockTarget, 'forward');
  13292. if (withoutAtomicBlock !== content) {
  13293. return EditorState_1.push(editorState, withoutAtomicBlock, 'remove-range');
  13294. }
  13295. return null;
  13296. },
  13297. onTab: function onTab(event, editorState, maxDepth) {
  13298. var selection = editorState.getSelection();
  13299. var key = selection.getAnchorKey();
  13300. if (key !== selection.getFocusKey()) {
  13301. return editorState;
  13302. }
  13303. var content = editorState.getCurrentContent();
  13304. var block = content.getBlockForKey(key);
  13305. var type = block.getType();
  13306. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  13307. return editorState;
  13308. }
  13309. event.preventDefault();
  13310. // Only allow indenting one level beyond the block above, and only if
  13311. // the block above is a list item as well.
  13312. var blockAbove = content.getBlockBefore(key);
  13313. if (!blockAbove) {
  13314. return editorState;
  13315. }
  13316. var typeAbove = blockAbove.getType();
  13317. if (typeAbove !== 'unordered-list-item' && typeAbove !== 'ordered-list-item') {
  13318. return editorState;
  13319. }
  13320. var depth = block.getDepth();
  13321. if (!event.shiftKey && depth === maxDepth) {
  13322. return editorState;
  13323. }
  13324. maxDepth = Math.min(blockAbove.getDepth() + 1, maxDepth);
  13325. var withAdjustment = adjustBlockDepthForContentState_1(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  13326. return EditorState_1.push(editorState, withAdjustment, 'adjust-depth');
  13327. },
  13328. toggleBlockType: function toggleBlockType(editorState, blockType) {
  13329. var selection = editorState.getSelection();
  13330. var startKey = selection.getStartKey();
  13331. var endKey = selection.getEndKey();
  13332. var content = editorState.getCurrentContent();
  13333. var target = selection;
  13334. // Triple-click can lead to a selection that includes offset 0 of the
  13335. // following block. The `SelectionState` for this case is accurate, but
  13336. // we should avoid toggling block type for the trailing block because it
  13337. // is a confusing interaction.
  13338. if (startKey !== endKey && selection.getEndOffset() === 0) {
  13339. var blockBefore = nullthrows_1(content.getBlockBefore(endKey));
  13340. endKey = blockBefore.getKey();
  13341. target = target.merge({
  13342. anchorKey: startKey,
  13343. anchorOffset: selection.getStartOffset(),
  13344. focusKey: endKey,
  13345. focusOffset: blockBefore.getLength(),
  13346. isBackward: false
  13347. });
  13348. }
  13349. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  13350. return k !== startKey;
  13351. }).reverse().skipWhile(function (_, k) {
  13352. return k !== endKey;
  13353. }).some(function (v) {
  13354. return v.getType() === 'atomic';
  13355. });
  13356. if (hasAtomicBlock) {
  13357. return editorState;
  13358. }
  13359. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  13360. return EditorState_1.push(editorState, DraftModifier_1.setBlockType(content, target, typeToSet), 'change-block-type');
  13361. },
  13362. toggleCode: function toggleCode(editorState) {
  13363. var selection = editorState.getSelection();
  13364. var anchorKey = selection.getAnchorKey();
  13365. var focusKey = selection.getFocusKey();
  13366. if (selection.isCollapsed() || anchorKey !== focusKey) {
  13367. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  13368. }
  13369. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  13370. },
  13371. /**
  13372. * Toggle the specified inline style for the selection. If the
  13373. * user's selection is collapsed, apply or remove the style for the
  13374. * internal state. If it is not collapsed, apply the change directly
  13375. * to the document state.
  13376. */
  13377. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  13378. var selection = editorState.getSelection();
  13379. var currentStyle = editorState.getCurrentInlineStyle();
  13380. // If the selection is collapsed, toggle the specified style on or off and
  13381. // set the result as the new inline style override. This will then be
  13382. // used as the inline style for the next character to be inserted.
  13383. if (selection.isCollapsed()) {
  13384. return EditorState_1.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  13385. }
  13386. // If characters are selected, immediately apply or remove the
  13387. // inline style on the document state itself.
  13388. var content = editorState.getCurrentContent();
  13389. var newContent;
  13390. // If the style is already present for the selection range, remove it.
  13391. // Otherwise, apply it.
  13392. if (currentStyle.has(inlineStyle)) {
  13393. newContent = DraftModifier_1.removeInlineStyle(content, selection, inlineStyle);
  13394. } else {
  13395. newContent = DraftModifier_1.applyInlineStyle(content, selection, inlineStyle);
  13396. }
  13397. return EditorState_1.push(editorState, newContent, 'change-inline-style');
  13398. },
  13399. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  13400. var withoutLink = DraftModifier_1.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  13401. return EditorState_1.push(editorState, withoutLink, 'apply-entity');
  13402. },
  13403. /**
  13404. * When a collapsed cursor is at the start of the first styled block, or
  13405. * an empty styled block, changes block to 'unstyled'. Returns null if
  13406. * block or selection does not meet that criteria.
  13407. */
  13408. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  13409. var selection = editorState.getSelection();
  13410. var offset = selection.getAnchorOffset();
  13411. if (selection.isCollapsed() && offset === 0) {
  13412. var key = selection.getAnchorKey();
  13413. var content = editorState.getCurrentContent();
  13414. var block = content.getBlockForKey(key);
  13415. var firstBlock = content.getFirstBlock();
  13416. if (block.getLength() > 0 && block !== firstBlock) {
  13417. return null;
  13418. }
  13419. var type = block.getType();
  13420. var blockBefore = content.getBlockBefore(key);
  13421. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  13422. return null;
  13423. }
  13424. if (type !== 'unstyled') {
  13425. return DraftModifier_1.setBlockType(content, selection, 'unstyled');
  13426. }
  13427. }
  13428. return null;
  13429. }
  13430. };
  13431. var RichTextEditorUtil_1 = RichTextEditorUtil;
  13432. /**
  13433. * Copyright (c) 2013-present, Facebook, Inc.
  13434. * All rights reserved.
  13435. *
  13436. * This source code is licensed under the BSD-style license found in the
  13437. * LICENSE file in the root directory of this source tree. An additional grant
  13438. * of patent rights can be found in the PATENTS file in the same directory.
  13439. *
  13440. * @providesModule splitTextIntoTextBlocks
  13441. * @format
  13442. *
  13443. */
  13444. var NEWLINE_REGEX = /\r\n?|\n/g;
  13445. function splitTextIntoTextBlocks(text) {
  13446. return text.split(NEWLINE_REGEX);
  13447. }
  13448. var splitTextIntoTextBlocks_1 = splitTextIntoTextBlocks;
  13449. /**
  13450. * Paste content.
  13451. */
  13452. function editOnPaste(editor, e) {
  13453. e.preventDefault();
  13454. var data = new DataTransfer_1(e.clipboardData);
  13455. // Get files, unless this is likely to be a string the user wants inline.
  13456. if (!data.isRichText()) {
  13457. var files = data.getFiles();
  13458. var defaultFileText = data.getText();
  13459. if (files.length > 0) {
  13460. // Allow customized paste handling for images, etc. Otherwise, fall
  13461. // through to insert text contents into the editor.
  13462. if (editor.props.handlePastedFiles && isEventHandled_1(editor.props.handlePastedFiles(files))) {
  13463. return;
  13464. }
  13465. getTextContentFromFiles_1(files, function ( /*string*/fileText) {
  13466. fileText = fileText || defaultFileText;
  13467. if (!fileText) {
  13468. return;
  13469. }
  13470. var editorState = editor._latestEditorState;
  13471. var blocks = splitTextIntoTextBlocks_1(fileText);
  13472. var character = CharacterMetadata_1.create({
  13473. style: editorState.getCurrentInlineStyle(),
  13474. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13475. });
  13476. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13477. var text = DraftPasteProcessor_1.processText(blocks, character, currentBlockType);
  13478. var fragment = BlockMapBuilder_1.createFromArray(text);
  13479. var withInsertedText = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13480. editor.update(EditorState_1.push(editorState, withInsertedText, 'insert-fragment'));
  13481. });
  13482. return;
  13483. }
  13484. }
  13485. var textBlocks = [];
  13486. var text = data.getText();
  13487. var html = data.getHTML();
  13488. var editorState = editor._latestEditorState;
  13489. if (editor.props.handlePastedText && isEventHandled_1(editor.props.handlePastedText(text, html, editorState))) {
  13490. return;
  13491. }
  13492. if (text) {
  13493. textBlocks = splitTextIntoTextBlocks_1(text);
  13494. }
  13495. if (!editor.props.stripPastedStyles) {
  13496. // If the text from the paste event is rich content that matches what we
  13497. // already have on the internal clipboard, assume that we should just use
  13498. // the clipboard fragment for the paste. This will allow us to preserve
  13499. // styling and entities, if any are present. Note that newlines are
  13500. // stripped during comparison -- this is because copy/paste within the
  13501. // editor in Firefox and IE will not include empty lines. The resulting
  13502. // paste will preserve the newlines correctly.
  13503. var internalClipboard = editor.getClipboard();
  13504. if (data.isRichText() && internalClipboard) {
  13505. if (
  13506. // If the editorKey is present in the pasted HTML, it should be safe to
  13507. // assume this is an internal paste.
  13508. html.indexOf(editor.getEditorKey()) !== -1 ||
  13509. // The copy may have been made within a single block, in which case the
  13510. // editor key won't be part of the paste. In this case, just check
  13511. // whether the pasted text matches the internal clipboard.
  13512. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13513. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13514. return;
  13515. }
  13516. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13517. // Safari does not properly store text/html in some cases.
  13518. // Use the internalClipboard if present and equal to what is on
  13519. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13520. editor.update(insertFragment$1(editor._latestEditorState, internalClipboard));
  13521. return;
  13522. }
  13523. // If there is html paste data, try to parse that.
  13524. if (html) {
  13525. var htmlFragment = DraftPasteProcessor_1.processHTML(html, editor.props.blockRenderMap);
  13526. if (htmlFragment) {
  13527. var contentBlocks = htmlFragment.contentBlocks,
  13528. entityMap = htmlFragment.entityMap;
  13529. if (contentBlocks) {
  13530. var htmlMap = BlockMapBuilder_1.createFromArray(contentBlocks);
  13531. editor.update(insertFragment$1(editor._latestEditorState, htmlMap, entityMap));
  13532. return;
  13533. }
  13534. }
  13535. }
  13536. // Otherwise, create a new fragment from our pasted text. Also
  13537. // empty the internal clipboard, since it's no longer valid.
  13538. editor.setClipboard(null);
  13539. }
  13540. if (textBlocks.length) {
  13541. var character = CharacterMetadata_1.create({
  13542. style: editorState.getCurrentInlineStyle(),
  13543. entity: getEntityKeyForSelection_1(editorState.getCurrentContent(), editorState.getSelection())
  13544. });
  13545. var currentBlockType = RichTextEditorUtil_1.getCurrentBlockType(editorState);
  13546. var textFragment = DraftPasteProcessor_1.processText(textBlocks, character, currentBlockType);
  13547. var textMap = BlockMapBuilder_1.createFromArray(textFragment);
  13548. editor.update(insertFragment$1(editor._latestEditorState, textMap));
  13549. }
  13550. }
  13551. function insertFragment$1(editorState, fragment, entityMap) {
  13552. var newContent = DraftModifier_1.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13553. // TODO: merge the entity map once we stop using DraftEntity
  13554. // like this:
  13555. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13556. return EditorState_1.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13557. }
  13558. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13559. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13560. return block.getText() === textBlocks[ii];
  13561. });
  13562. }
  13563. var editOnPaste_1 = editOnPaste;
  13564. /**
  13565. * Convert the current selection range to an anchor/focus pair of offset keys
  13566. * and values that can be interpreted by components.
  13567. */
  13568. function getDraftEditorSelection(editorState, root) {
  13569. var selection = _commonjsHelpers.commonjsGlobal.getSelection();
  13570. // No active selection.
  13571. if (selection.rangeCount === 0) {
  13572. return {
  13573. selectionState: editorState.getSelection().set('hasFocus', false),
  13574. needsRecovery: false
  13575. };
  13576. }
  13577. return getDraftEditorSelectionWithNodes_1(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  13578. }
  13579. var getDraftEditorSelection_1 = getDraftEditorSelection;
  13580. function editOnSelect(editor) {
  13581. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  13582. return;
  13583. }
  13584. var editorState = editor.props.editorState;
  13585. var editorNode = _reactDom_commonjsExternal.require$$3.findDOMNode(editor.editorContainer);
  13586. !editorNode ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Missing editorNode') : invariant_1(false) : void 0;
  13587. !(editorNode.firstChild instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode.firstChild is not an HTMLElement') : invariant_1(false) : void 0;
  13588. var documentSelection = getDraftEditorSelection_1(editorState, editorNode.firstChild);
  13589. var updatedSelectionState = documentSelection.selectionState;
  13590. if (updatedSelectionState !== editorState.getSelection()) {
  13591. if (documentSelection.needsRecovery) {
  13592. editorState = EditorState_1.forceSelection(editorState, updatedSelectionState);
  13593. } else {
  13594. editorState = EditorState_1.acceptSelection(editorState, updatedSelectionState);
  13595. }
  13596. editor.update(editorState);
  13597. }
  13598. }
  13599. var editOnSelect_1 = editOnSelect;
  13600. var DraftEditorEditHandler = {
  13601. onBeforeInput: editOnBeforeInput_1,
  13602. onBlur: editOnBlur_1,
  13603. onCompositionStart: editOnCompositionStart_1,
  13604. onCopy: editOnCopy_1,
  13605. onCut: editOnCut_1,
  13606. onDragOver: editOnDragOver_1,
  13607. onDragStart: editOnDragStart_1,
  13608. onFocus: editOnFocus_1,
  13609. onInput: editOnInput_1,
  13610. onKeyDown: editOnKeyDown_1,
  13611. onPaste: editOnPaste_1,
  13612. onSelect: editOnSelect_1
  13613. };
  13614. var DraftEditorEditHandler_1 = DraftEditorEditHandler;
  13615. function _classCallCheck$f(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13616. function _possibleConstructorReturn$a(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13617. function _inherits$a(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13618. /**
  13619. * This component is responsible for rendering placeholder text for the
  13620. * `DraftEditor` component.
  13621. *
  13622. * Override placeholder style via CSS.
  13623. */
  13624. var DraftEditorPlaceholder = function (_React$Component) {
  13625. _inherits$a(DraftEditorPlaceholder, _React$Component);
  13626. function DraftEditorPlaceholder() {
  13627. _classCallCheck$f(this, DraftEditorPlaceholder);
  13628. return _possibleConstructorReturn$a(this, _React$Component.apply(this, arguments));
  13629. }
  13630. DraftEditorPlaceholder.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13631. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13632. };
  13633. DraftEditorPlaceholder.prototype.render = function render() {
  13634. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13635. var className = cx_1({
  13636. 'public/DraftEditorPlaceholder/root': true,
  13637. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13638. });
  13639. var contentStyle = {
  13640. whiteSpace: 'pre-wrap'
  13641. };
  13642. return _reactDom_commonjsExternal.React.createElement(
  13643. 'div',
  13644. { className: className },
  13645. _reactDom_commonjsExternal.React.createElement(
  13646. 'div',
  13647. {
  13648. className: cx_1('public/DraftEditorPlaceholder/inner'),
  13649. id: this.props.accessibilityID,
  13650. style: contentStyle },
  13651. this.props.text
  13652. )
  13653. );
  13654. };
  13655. return DraftEditorPlaceholder;
  13656. }(_reactDom_commonjsExternal.React.Component);
  13657. var DraftEditorPlaceholder_react = DraftEditorPlaceholder;
  13658. var isOSX$1 = UserAgent_1.isPlatform('Mac OS X');
  13659. var isWindows = UserAgent_1.isPlatform('Windows');
  13660. // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  13661. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  13662. // so we just check the version number. See #342765.
  13663. var shouldFixFirefoxMovement = isOSX$1 && UserAgent_1.isBrowser('Firefox < 29');
  13664. var hasCommandModifier = KeyBindingUtil_1.hasCommandModifier,
  13665. isCtrlKeyCommand = KeyBindingUtil_1.isCtrlKeyCommand;
  13666. function shouldRemoveWord(e) {
  13667. return isOSX$1 && e.altKey || isCtrlKeyCommand(e);
  13668. }
  13669. /**
  13670. * Get the appropriate undo/redo command for a Z key command.
  13671. */
  13672. function getZCommand(e) {
  13673. if (!hasCommandModifier(e)) {
  13674. return null;
  13675. }
  13676. return e.shiftKey ? 'redo' : 'undo';
  13677. }
  13678. function getDeleteCommand(e) {
  13679. // Allow default "cut" behavior for Windows on Shift + Delete.
  13680. if (isWindows && e.shiftKey) {
  13681. return null;
  13682. }
  13683. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  13684. }
  13685. function getBackspaceCommand(e) {
  13686. if (hasCommandModifier(e) && isOSX$1) {
  13687. return 'backspace-to-start-of-line';
  13688. }
  13689. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  13690. }
  13691. /**
  13692. * Retrieve a bound key command for the given event.
  13693. */
  13694. function getDefaultKeyBinding(e) {
  13695. switch (e.keyCode) {
  13696. case 66:
  13697. // B
  13698. return hasCommandModifier(e) ? 'bold' : null;
  13699. case 68:
  13700. // D
  13701. return isCtrlKeyCommand(e) ? 'delete' : null;
  13702. case 72:
  13703. // H
  13704. return isCtrlKeyCommand(e) ? 'backspace' : null;
  13705. case 73:
  13706. // I
  13707. return hasCommandModifier(e) ? 'italic' : null;
  13708. case 74:
  13709. // J
  13710. return hasCommandModifier(e) ? 'code' : null;
  13711. case 75:
  13712. // K
  13713. return !isWindows && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  13714. case 77:
  13715. // M
  13716. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13717. case 79:
  13718. // O
  13719. return isCtrlKeyCommand(e) ? 'split-block' : null;
  13720. case 84:
  13721. // T
  13722. return isOSX$1 && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  13723. case 85:
  13724. // U
  13725. return hasCommandModifier(e) ? 'underline' : null;
  13726. case 87:
  13727. // W
  13728. return isOSX$1 && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  13729. case 89:
  13730. // Y
  13731. if (isCtrlKeyCommand(e)) {
  13732. return isWindows ? 'redo' : 'secondary-paste';
  13733. }
  13734. return null;
  13735. case 90:
  13736. // Z
  13737. return getZCommand(e) || null;
  13738. case Keys.RETURN:
  13739. return 'split-block';
  13740. case Keys.DELETE:
  13741. return getDeleteCommand(e);
  13742. case Keys.BACKSPACE:
  13743. return getBackspaceCommand(e);
  13744. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  13745. case Keys.LEFT:
  13746. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  13747. case Keys.RIGHT:
  13748. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  13749. default:
  13750. return null;
  13751. }
  13752. }
  13753. var getDefaultKeyBinding_1 = getDefaultKeyBinding;
  13754. var _extends$5 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  13755. function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13756. function _possibleConstructorReturn$b(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13757. function _inherits$b(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13758. var isIE = UserAgent_1.isBrowser('IE');
  13759. // IE does not support the `input` event on contentEditable, so we can't
  13760. // observe spellcheck behavior.
  13761. var allowSpellCheck = !isIE;
  13762. // Define a set of handler objects to correspond to each possible `mode`
  13763. // of editor behavior.
  13764. var handlerMap = {
  13765. edit: DraftEditorEditHandler_1,
  13766. composite: DraftEditorCompositionHandler_1,
  13767. drag: DraftEditorDragHandler_1,
  13768. cut: null,
  13769. render: null
  13770. };
  13771. /**
  13772. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  13773. * div, and provides a wide variety of useful function props for managing the
  13774. * state of the editor. See `DraftEditorProps` for details.
  13775. */
  13776. var DraftEditor = function (_React$Component) {
  13777. _inherits$b(DraftEditor, _React$Component);
  13778. function DraftEditor(props) {
  13779. _classCallCheck$g(this, DraftEditor);
  13780. var _this = _possibleConstructorReturn$b(this, _React$Component.call(this, props));
  13781. _this.focus = function (scrollPosition) {
  13782. var editorState = _this.props.editorState;
  13783. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  13784. var editorNode = _reactDom_commonjsExternal.require$$3.findDOMNode(_this.editor);
  13785. if (!editorNode) {
  13786. // once in a while people call 'focus' in a setTimeout, and the node has
  13787. // been deleted, so it can be null in that case.
  13788. return;
  13789. }
  13790. var scrollParent = Style_1.getScrollParent(editorNode);
  13791. var _ref = scrollPosition || getScrollPosition_1(scrollParent),
  13792. x = _ref.x,
  13793. y = _ref.y;
  13794. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13795. editorNode.focus();
  13796. // Restore scroll position
  13797. if (scrollParent === window) {
  13798. window.scrollTo(x, y);
  13799. } else {
  13800. Scroll_1.setTop(scrollParent, y);
  13801. }
  13802. // On Chrome and Safari, calling focus on contenteditable focuses the
  13803. // cursor at the first character. This is something you don't expect when
  13804. // you're clicking on an input element but not directly on a character.
  13805. // Put the cursor back where it was before the blur.
  13806. if (!alreadyHasFocus) {
  13807. _this.update(EditorState_1.forceSelection(editorState, editorState.getSelection()));
  13808. }
  13809. };
  13810. _this.blur = function () {
  13811. var editorNode = _reactDom_commonjsExternal.require$$3.findDOMNode(_this.editor);
  13812. !(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'editorNode is not an HTMLElement') : invariant_1(false) : void 0;
  13813. editorNode.blur();
  13814. };
  13815. _this.setMode = function (mode) {
  13816. _this._handler = handlerMap[mode];
  13817. };
  13818. _this.exitCurrentMode = function () {
  13819. _this.setMode('edit');
  13820. };
  13821. _this.restoreEditorDOM = function (scrollPosition) {
  13822. _this.setState({ contentsKey: _this.state.contentsKey + 1 }, function () {
  13823. _this.focus(scrollPosition);
  13824. });
  13825. };
  13826. _this.setClipboard = function (clipboard) {
  13827. _this._clipboard = clipboard;
  13828. };
  13829. _this.getClipboard = function () {
  13830. return _this._clipboard;
  13831. };
  13832. _this.update = function (editorState) {
  13833. _this._latestEditorState = editorState;
  13834. _this.props.onChange(editorState);
  13835. };
  13836. _this.onDragEnter = function () {
  13837. _this._dragCount++;
  13838. };
  13839. _this.onDragLeave = function () {
  13840. _this._dragCount--;
  13841. if (_this._dragCount === 0) {
  13842. _this.exitCurrentMode();
  13843. }
  13844. };
  13845. _this._blockSelectEvents = false;
  13846. _this._clipboard = null;
  13847. _this._handler = null;
  13848. _this._dragCount = 0;
  13849. _this._editorKey = props.editorKey || generateRandomKey_1();
  13850. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  13851. _this._latestEditorState = props.editorState;
  13852. _this._latestCommittedEditorState = props.editorState;
  13853. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  13854. _this._onBlur = _this._buildHandler('onBlur');
  13855. _this._onCharacterData = _this._buildHandler('onCharacterData');
  13856. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  13857. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  13858. _this._onCopy = _this._buildHandler('onCopy');
  13859. _this._onCut = _this._buildHandler('onCut');
  13860. _this._onDragEnd = _this._buildHandler('onDragEnd');
  13861. _this._onDragOver = _this._buildHandler('onDragOver');
  13862. _this._onDragStart = _this._buildHandler('onDragStart');
  13863. _this._onDrop = _this._buildHandler('onDrop');
  13864. _this._onInput = _this._buildHandler('onInput');
  13865. _this._onFocus = _this._buildHandler('onFocus');
  13866. _this._onKeyDown = _this._buildHandler('onKeyDown');
  13867. _this._onKeyPress = _this._buildHandler('onKeyPress');
  13868. _this._onKeyUp = _this._buildHandler('onKeyUp');
  13869. _this._onMouseDown = _this._buildHandler('onMouseDown');
  13870. _this._onMouseUp = _this._buildHandler('onMouseUp');
  13871. _this._onPaste = _this._buildHandler('onPaste');
  13872. _this._onSelect = _this._buildHandler('onSelect');
  13873. _this.getEditorKey = function () {
  13874. return _this._editorKey;
  13875. };
  13876. // See `restoreEditorDOM()`.
  13877. _this.state = { contentsKey: 0 };
  13878. return _this;
  13879. }
  13880. /**
  13881. * Build a method that will pass the event to the specified handler method.
  13882. * This allows us to look up the correct handler function for the current
  13883. * editor mode, if any has been specified.
  13884. */
  13885. /**
  13886. * Define proxies that can route events to the current handler.
  13887. */
  13888. DraftEditor.prototype._buildHandler = function _buildHandler(eventName) {
  13889. var _this2 = this;
  13890. return function (e) {
  13891. if (!_this2.props.readOnly) {
  13892. var method = _this2._handler && _this2._handler[eventName];
  13893. method && method(_this2, e);
  13894. }
  13895. };
  13896. };
  13897. DraftEditor.prototype._showPlaceholder = function _showPlaceholder() {
  13898. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  13899. };
  13900. DraftEditor.prototype._renderPlaceholder = function _renderPlaceholder() {
  13901. if (this._showPlaceholder()) {
  13902. var placeHolderProps = {
  13903. text: nullthrows_1(this.props.placeholder),
  13904. editorState: this.props.editorState,
  13905. textAlignment: this.props.textAlignment,
  13906. accessibilityID: this._placeholderAccessibilityID
  13907. };
  13908. return _reactDom_commonjsExternal.React.createElement(DraftEditorPlaceholder_react, placeHolderProps);
  13909. }
  13910. return null;
  13911. };
  13912. DraftEditor.prototype.render = function render() {
  13913. var _this3 = this;
  13914. var _props = this.props,
  13915. blockRenderMap = _props.blockRenderMap,
  13916. blockRendererFn = _props.blockRendererFn,
  13917. blockStyleFn = _props.blockStyleFn,
  13918. customStyleFn = _props.customStyleFn,
  13919. customStyleMap = _props.customStyleMap,
  13920. editorState = _props.editorState,
  13921. readOnly = _props.readOnly,
  13922. textAlignment = _props.textAlignment,
  13923. textDirectionality = _props.textDirectionality;
  13924. var rootClass = cx_1({
  13925. 'DraftEditor/root': true,
  13926. 'DraftEditor/alignLeft': textAlignment === 'left',
  13927. 'DraftEditor/alignRight': textAlignment === 'right',
  13928. 'DraftEditor/alignCenter': textAlignment === 'center'
  13929. });
  13930. var contentStyle = {
  13931. outline: 'none',
  13932. // fix parent-draggable Safari bug. #1326
  13933. userSelect: 'text',
  13934. WebkitUserSelect: 'text',
  13935. whiteSpace: 'pre-wrap',
  13936. wordWrap: 'break-word'
  13937. };
  13938. // The aria-expanded and aria-haspopup properties should only be rendered
  13939. // for a combobox.
  13940. var ariaRole = this.props.role || 'textbox';
  13941. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  13942. var editorContentsProps = {
  13943. blockRenderMap: blockRenderMap,
  13944. blockRendererFn: blockRendererFn,
  13945. blockStyleFn: blockStyleFn,
  13946. customStyleMap: _extends$5({}, DefaultDraftInlineStyle, customStyleMap),
  13947. customStyleFn: customStyleFn,
  13948. editorKey: this._editorKey,
  13949. editorState: editorState,
  13950. key: 'contents' + this.state.contentsKey,
  13951. textDirectionality: textDirectionality
  13952. };
  13953. return _reactDom_commonjsExternal.React.createElement(
  13954. 'div',
  13955. { className: rootClass },
  13956. this._renderPlaceholder(),
  13957. _reactDom_commonjsExternal.React.createElement(
  13958. 'div',
  13959. {
  13960. className: cx_1('DraftEditor/editorContainer'),
  13961. ref: function ref(_ref3) {
  13962. return _this3.editorContainer = _ref3;
  13963. } },
  13964. _reactDom_commonjsExternal.React.createElement(
  13965. 'div',
  13966. {
  13967. 'aria-activedescendant': readOnly ? null : this.props.ariaActiveDescendantID,
  13968. 'aria-autocomplete': readOnly ? null : this.props.ariaAutoComplete,
  13969. 'aria-controls': readOnly ? null : this.props.ariaControls,
  13970. 'aria-describedby': this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  13971. 'aria-expanded': readOnly ? null : ariaExpanded,
  13972. 'aria-label': this.props.ariaLabel,
  13973. 'aria-labelledby': this.props.ariaLabelledBy,
  13974. 'aria-multiline': this.props.ariaMultiline,
  13975. autoCapitalize: this.props.autoCapitalize,
  13976. autoComplete: this.props.autoComplete,
  13977. autoCorrect: this.props.autoCorrect,
  13978. className: cx_1({
  13979. // Chrome's built-in translation feature mutates the DOM in ways
  13980. // that Draft doesn't expect (ex: adding <font> tags inside
  13981. // DraftEditorLeaf spans) and causes problems. We add notranslate
  13982. // here which makes its autotranslation skip over this subtree.
  13983. notranslate: !readOnly,
  13984. 'public/DraftEditor/content': true
  13985. }),
  13986. contentEditable: !readOnly,
  13987. 'data-testid': this.props.webDriverTestID,
  13988. onBeforeInput: this._onBeforeInput,
  13989. onBlur: this._onBlur,
  13990. onCompositionEnd: this._onCompositionEnd,
  13991. onCompositionStart: this._onCompositionStart,
  13992. onCopy: this._onCopy,
  13993. onCut: this._onCut,
  13994. onDragEnd: this._onDragEnd,
  13995. onDragEnter: this.onDragEnter,
  13996. onDragLeave: this.onDragLeave,
  13997. onDragOver: this._onDragOver,
  13998. onDragStart: this._onDragStart,
  13999. onDrop: this._onDrop,
  14000. onFocus: this._onFocus,
  14001. onInput: this._onInput,
  14002. onKeyDown: this._onKeyDown,
  14003. onKeyPress: this._onKeyPress,
  14004. onKeyUp: this._onKeyUp,
  14005. onMouseUp: this._onMouseUp,
  14006. onPaste: this._onPaste,
  14007. onSelect: this._onSelect,
  14008. ref: function ref(_ref2) {
  14009. return _this3.editor = _ref2;
  14010. },
  14011. role: readOnly ? null : ariaRole,
  14012. spellCheck: allowSpellCheck && this.props.spellCheck,
  14013. style: contentStyle,
  14014. suppressContentEditableWarning: true,
  14015. tabIndex: this.props.tabIndex },
  14016. _reactDom_commonjsExternal.React.createElement(DraftEditorContents_react, editorContentsProps)
  14017. )
  14018. )
  14019. );
  14020. };
  14021. DraftEditor.prototype.componentDidMount = function componentDidMount() {
  14022. this.setMode('edit');
  14023. /**
  14024. * IE has a hardcoded "feature" that attempts to convert link text into
  14025. * anchors in contentEditable DOM. This breaks the editor's expectations of
  14026. * the DOM, and control is lost. Disable it to make IE behave.
  14027. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  14028. * ie9-beta-minor-change-list.aspx
  14029. */
  14030. if (isIE) {
  14031. document.execCommand('AutoUrlDetect', false, false);
  14032. }
  14033. };
  14034. /**
  14035. * Prevent selection events from affecting the current editor state. This
  14036. * is mostly intended to defend against IE, which fires off `selectionchange`
  14037. * events regardless of whether the selection is set via the browser or
  14038. * programmatically. We only care about selection events that occur because
  14039. * of browser interaction, not re-renders and forced selections.
  14040. */
  14041. DraftEditor.prototype.componentWillUpdate = function componentWillUpdate(nextProps) {
  14042. this._blockSelectEvents = true;
  14043. this._latestEditorState = nextProps.editorState;
  14044. };
  14045. DraftEditor.prototype.componentDidUpdate = function componentDidUpdate() {
  14046. this._blockSelectEvents = false;
  14047. this._latestCommittedEditorState = this.props.editorState;
  14048. };
  14049. /**
  14050. * Used via `this.focus()`.
  14051. *
  14052. * Force focus back onto the editor node.
  14053. *
  14054. * We attempt to preserve scroll position when focusing. You can also pass
  14055. * a specified scroll position (for cases like `cut` behavior where it should
  14056. * be restored to a known position).
  14057. */
  14058. /**
  14059. * Used via `this.setMode(...)`.
  14060. *
  14061. * Set the behavior mode for the editor component. This switches the current
  14062. * handler module to ensure that DOM events are managed appropriately for
  14063. * the active mode.
  14064. */
  14065. /**
  14066. * Used via `this.restoreEditorDOM()`.
  14067. *
  14068. * Force a complete re-render of the DraftEditorContents based on the current
  14069. * EditorState. This is useful when we know we are going to lose control of
  14070. * the DOM state (cut command, IME) and we want to make sure that
  14071. * reconciliation occurs on a version of the DOM that is synchronized with
  14072. * our EditorState.
  14073. */
  14074. /**
  14075. * Used via `this.setClipboard(...)`.
  14076. *
  14077. * Set the clipboard state for a cut/copy event.
  14078. */
  14079. /**
  14080. * Used via `this.getClipboard()`.
  14081. *
  14082. * Retrieve the clipboard state for a cut/copy event.
  14083. */
  14084. /**
  14085. * Used via `this.update(...)`.
  14086. *
  14087. * Propagate a new `EditorState` object to higher-level components. This is
  14088. * the method by which event handlers inform the `DraftEditor` component of
  14089. * state changes. A component that composes a `DraftEditor` **must** provide
  14090. * an `onChange` prop to receive state updates passed along from this
  14091. * function.
  14092. */
  14093. /**
  14094. * Used in conjunction with `onDragLeave()`, by counting the number of times
  14095. * a dragged element enters and leaves the editor (or any of its children),
  14096. * to determine when the dragged element absolutely leaves the editor.
  14097. */
  14098. /**
  14099. * See `onDragEnter()`.
  14100. */
  14101. return DraftEditor;
  14102. }(_reactDom_commonjsExternal.React.Component);
  14103. DraftEditor.defaultProps = {
  14104. blockRenderMap: DefaultDraftBlockRenderMap_1,
  14105. blockRendererFn: emptyFunction_1.thatReturnsNull,
  14106. blockStyleFn: emptyFunction_1.thatReturns(''),
  14107. keyBindingFn: getDefaultKeyBinding_1,
  14108. readOnly: false,
  14109. spellCheck: false,
  14110. stripPastedStyles: false
  14111. };
  14112. var DraftEditor_react = DraftEditor;
  14113. /**
  14114. * Copyright (c) 2013-present, Facebook, Inc.
  14115. * All rights reserved.
  14116. *
  14117. * This source code is licensed under the BSD-style license found in the
  14118. * LICENSE file in the root directory of this source tree. An additional grant
  14119. * of patent rights can be found in the PATENTS file in the same directory.
  14120. *
  14121. * @providesModule DraftStringKey
  14122. * @format
  14123. *
  14124. */
  14125. var DraftStringKey = {
  14126. stringify: function stringify(key) {
  14127. return '_' + String(key);
  14128. },
  14129. unstringify: function unstringify(key) {
  14130. return key.slice(1);
  14131. }
  14132. };
  14133. var DraftStringKey_1 = DraftStringKey;
  14134. var strlen$1 = UnicodeUtils_1.strlen;
  14135. /**
  14136. * Convert to UTF-8 character counts for storage.
  14137. */
  14138. function encodeEntityRanges(block, storageMap) {
  14139. var encoded = [];
  14140. block.findEntityRanges(function (character) {
  14141. return !!character.getEntity();
  14142. }, function ( /*number*/start, /*number*/end) {
  14143. var text = block.getText();
  14144. var key = block.getEntityAt(start);
  14145. encoded.push({
  14146. offset: strlen$1(text.slice(0, start)),
  14147. length: strlen$1(text.slice(start, end)),
  14148. // Encode the key as a number for range storage.
  14149. key: Number(storageMap[DraftStringKey_1.stringify(key)])
  14150. });
  14151. });
  14152. return encoded;
  14153. }
  14154. var encodeEntityRanges_1 = encodeEntityRanges;
  14155. var areEqual$1 = function areEqual(a, b) {
  14156. return a === b;
  14157. };
  14158. var isTruthy = function isTruthy(a) {
  14159. return !!a;
  14160. };
  14161. var EMPTY_ARRAY = [];
  14162. /**
  14163. * Helper function for getting encoded styles for each inline style. Convert
  14164. * to UTF-8 character counts for storage.
  14165. */
  14166. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14167. var ranges = [];
  14168. // Obtain an array with ranges for only the specified style.
  14169. var filteredInlines = styleList.map(function (style) {
  14170. return style.has(styleToEncode);
  14171. }).toList();
  14172. findRangesImmutable_1(filteredInlines, areEqual$1,
  14173. // We only want to keep ranges with nonzero style values.
  14174. isTruthy, function (start, end) {
  14175. var text = block.getText();
  14176. ranges.push({
  14177. offset: UnicodeUtils_1.strlen(text.slice(0, start)),
  14178. length: UnicodeUtils_1.strlen(text.slice(start, end)),
  14179. style: styleToEncode
  14180. });
  14181. });
  14182. return ranges;
  14183. }
  14184. /*
  14185. * Retrieve the encoded arrays of inline styles, with each individual style
  14186. * treated separately.
  14187. */
  14188. function encodeInlineStyleRanges(block) {
  14189. var styleList = block.getCharacterList().map(function (c) {
  14190. return c.getStyle();
  14191. }).toList();
  14192. var ranges = styleList.flatten().toSet().map(function (style) {
  14193. return getEncodedInlinesForType(block, styleList, style);
  14194. });
  14195. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14196. }
  14197. var encodeInlineStyleRanges_1 = encodeInlineStyleRanges;
  14198. var _extends$6 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14199. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  14200. return {
  14201. key: block.getKey(),
  14202. text: block.getText(),
  14203. type: block.getType(),
  14204. depth: block.getDepth(),
  14205. inlineStyleRanges: encodeInlineStyleRanges_1(block),
  14206. entityRanges: encodeEntityRanges_1(block, entityStorageMap),
  14207. data: block.getData().toObject()
  14208. };
  14209. };
  14210. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  14211. if (block instanceof ContentBlock_1) {
  14212. rawBlocks.push(createRawBlock(block, entityMap));
  14213. return;
  14214. }
  14215. !(block instanceof ContentBlockNode_1) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'block is not a BlockNode') : invariant_1(false) : void 0;
  14216. var parentKey = block.getParentKey();
  14217. var rawBlock = blockCacheRef[block.getKey()] = _extends$6({}, createRawBlock(block, entityMap), {
  14218. children: []
  14219. });
  14220. if (parentKey) {
  14221. blockCacheRef[parentKey].children.push(rawBlock);
  14222. return;
  14223. }
  14224. rawBlocks.push(rawBlock);
  14225. };
  14226. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  14227. var entityMap = rawState.entityMap;
  14228. var rawBlocks = [];
  14229. var blockCacheRef = {};
  14230. var entityCacheRef = {};
  14231. var entityStorageKey = 0;
  14232. contentState.getBlockMap().forEach(function (block) {
  14233. block.findEntityRanges(function (character) {
  14234. return character.getEntity() !== null;
  14235. }, function (start) {
  14236. var entityKey = block.getEntityAt(start);
  14237. // Stringify to maintain order of otherwise numeric keys.
  14238. var stringifiedEntityKey = DraftStringKey_1.stringify(entityKey);
  14239. // This makes this function resilient to two entities
  14240. // erroneously having the same key
  14241. if (entityCacheRef[stringifiedEntityKey]) {
  14242. return;
  14243. }
  14244. entityCacheRef[stringifiedEntityKey] = entityKey;
  14245. // we need the `any` casting here since this is a temporary state
  14246. // where we will later on flip the entity map and populate it with
  14247. // real entity, at this stage we just need to map back the entity
  14248. // key used by the BlockNode
  14249. entityMap[stringifiedEntityKey] = '' + entityStorageKey;
  14250. entityStorageKey++;
  14251. });
  14252. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  14253. });
  14254. return {
  14255. blocks: rawBlocks,
  14256. entityMap: entityMap
  14257. };
  14258. };
  14259. // Flip storage map so that our storage keys map to global
  14260. // DraftEntity keys.
  14261. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  14262. var blocks = rawState.blocks,
  14263. entityMap = rawState.entityMap;
  14264. var rawEntityMap = {};
  14265. Object.keys(entityMap).forEach(function (key, index) {
  14266. var entity = contentState.getEntity(DraftStringKey_1.unstringify(key));
  14267. rawEntityMap[index] = {
  14268. type: entity.getType(),
  14269. mutability: entity.getMutability(),
  14270. data: entity.getData()
  14271. };
  14272. });
  14273. return {
  14274. blocks: blocks,
  14275. entityMap: rawEntityMap
  14276. };
  14277. };
  14278. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  14279. var rawDraftContentState = {
  14280. entityMap: {},
  14281. blocks: []
  14282. };
  14283. // add blocks
  14284. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState);
  14285. // add entities
  14286. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  14287. return rawDraftContentState;
  14288. };
  14289. var convertFromDraftStateToRaw_1 = convertFromDraftStateToRaw;
  14290. var _extends$7 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14291. /**
  14292. * Copyright (c) 2013-present, Facebook, Inc.
  14293. * All rights reserved.
  14294. *
  14295. * This source code is licensed under the BSD-style license found in the
  14296. * LICENSE file in the root directory of this source tree. An additional grant
  14297. * of patent rights can be found in the PATENTS file in the same directory.
  14298. *
  14299. * @providesModule DraftTreeAdapter
  14300. * @format
  14301. *
  14302. *
  14303. * This is unstable and not part of the public API and should not be used by
  14304. * production systems. This file may be update/removed without notice.
  14305. */
  14306. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14307. var stack = [].concat(blocks).reverse();
  14308. while (stack.length) {
  14309. var _block = stack.pop();
  14310. fn(_block);
  14311. var children = _block.children;
  14312. !Array.isArray(children) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid tree raw block') : invariant_1(false) : void 0;
  14313. stack = stack.concat([].concat(children.reverse()));
  14314. }
  14315. };
  14316. var isListBlock = function isListBlock(block) {
  14317. if (!(block && block.type)) {
  14318. return false;
  14319. }
  14320. var type = block.type;
  14321. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14322. };
  14323. var addDepthToChildren = function addDepthToChildren(block) {
  14324. if (Array.isArray(block.children)) {
  14325. block.children = block.children.map(function (child) {
  14326. return child.type === block.type ? _extends$7({}, child, { depth: (block.depth || 0) + 1 }) : child;
  14327. });
  14328. }
  14329. };
  14330. /**
  14331. * This adapter is intended to be be used as an adapter to draft tree data
  14332. *
  14333. * draft state <=====> draft tree state
  14334. */
  14335. var DraftTreeAdapter = {
  14336. /**
  14337. * Converts from a tree raw state back to draft raw state
  14338. */
  14339. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14340. var blocks = draftTreeState.blocks;
  14341. var transformedBlocks = [];
  14342. !Array.isArray(blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid raw state') : invariant_1(false) : void 0;
  14343. if (!Array.isArray(blocks) || !blocks.length) {
  14344. return draftTreeState;
  14345. }
  14346. traverseInDepthOrder(blocks, function (block) {
  14347. var newBlock = _extends$7({}, block);
  14348. if (isListBlock(block)) {
  14349. newBlock.depth = newBlock.depth || 0;
  14350. addDepthToChildren(block);
  14351. }
  14352. delete newBlock.children;
  14353. transformedBlocks.push(newBlock);
  14354. });
  14355. draftTreeState.blocks = transformedBlocks;
  14356. return _extends$7({}, draftTreeState, {
  14357. blocks: transformedBlocks
  14358. });
  14359. },
  14360. /**
  14361. * Converts from draft raw state to tree draft state
  14362. */
  14363. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14364. var lastListDepthCacheRef = {};
  14365. var transformedBlocks = [];
  14366. draftState.blocks.forEach(function (block) {
  14367. var isList = isListBlock(block);
  14368. var depth = block.depth || 0;
  14369. var treeBlock = _extends$7({}, block, {
  14370. children: []
  14371. });
  14372. if (!isList) {
  14373. // reset the cache path
  14374. lastListDepthCacheRef = {};
  14375. transformedBlocks.push(treeBlock);
  14376. return;
  14377. }
  14378. // update our depth cache reference path
  14379. lastListDepthCacheRef[depth] = treeBlock;
  14380. // if we are greater than zero we must have seen a parent already
  14381. if (depth > 0) {
  14382. var parent = lastListDepthCacheRef[depth - 1];
  14383. !parent ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'Invalid depth for RawDraftContentBlock') : invariant_1(false) : void 0;
  14384. // push nested list blocks
  14385. parent.children.push(treeBlock);
  14386. return;
  14387. }
  14388. // push root list blocks
  14389. transformedBlocks.push(treeBlock);
  14390. });
  14391. return _extends$7({}, draftState, {
  14392. blocks: transformedBlocks
  14393. });
  14394. }
  14395. };
  14396. var DraftTreeAdapter_1 = DraftTreeAdapter;
  14397. var List$c = immutable.List;
  14398. function createCharacterList(inlineStyles, entities) {
  14399. var characterArray = inlineStyles.map(function (style, ii) {
  14400. var entity = entities[ii];
  14401. return CharacterMetadata_1.create({ style: style, entity: entity });
  14402. });
  14403. return List$c(characterArray);
  14404. }
  14405. var createCharacterList_1 = createCharacterList;
  14406. var substr$1 = UnicodeUtils_1.substr;
  14407. /**
  14408. * Convert to native JavaScript string lengths to determine ranges.
  14409. */
  14410. function decodeEntityRanges(text, ranges) {
  14411. var entities = Array(text.length).fill(null);
  14412. if (ranges) {
  14413. ranges.forEach(function (range) {
  14414. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14415. // fill the output array with entity keys.
  14416. var start = substr$1(text, 0, range.offset).length;
  14417. var end = start + substr$1(text, range.offset, range.length).length;
  14418. for (var ii = start; ii < end; ii++) {
  14419. entities[ii] = range.key;
  14420. }
  14421. });
  14422. }
  14423. return entities;
  14424. }
  14425. var decodeEntityRanges_1 = decodeEntityRanges;
  14426. var OrderedSet$6 = immutable.OrderedSet;
  14427. var substr$2 = UnicodeUtils_1.substr;
  14428. var EMPTY_SET$3 = OrderedSet$6();
  14429. /**
  14430. * Convert to native JavaScript string lengths to determine ranges.
  14431. */
  14432. function decodeInlineStyleRanges(text, ranges) {
  14433. var styles = Array(text.length).fill(EMPTY_SET$3);
  14434. if (ranges) {
  14435. ranges.forEach(function ( /*object*/range) {
  14436. var cursor = substr$2(text, 0, range.offset).length;
  14437. var end = cursor + substr$2(text, range.offset, range.length).length;
  14438. while (cursor < end) {
  14439. styles[cursor] = styles[cursor].add(range.style);
  14440. cursor++;
  14441. }
  14442. });
  14443. }
  14444. return styles;
  14445. }
  14446. var decodeInlineStyleRanges_1 = decodeInlineStyleRanges;
  14447. var _extends$8 = objectAssign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  14448. var List$d = immutable.List,
  14449. Map$9 = immutable.Map,
  14450. OrderedMap$4 = immutable.OrderedMap;
  14451. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14452. var key = block.key,
  14453. type = block.type,
  14454. data = block.data,
  14455. text = block.text,
  14456. depth = block.depth;
  14457. var blockNodeConfig = {
  14458. text: text,
  14459. depth: depth || 0,
  14460. type: type || 'unstyled',
  14461. key: key || generateRandomKey_1(),
  14462. data: Map$9(data),
  14463. characterList: decodeCharacterList(block, entityMap)
  14464. };
  14465. return blockNodeConfig;
  14466. };
  14467. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14468. var text = block.text,
  14469. rawEntityRanges = block.entityRanges,
  14470. rawInlineStyleRanges = block.inlineStyleRanges;
  14471. var entityRanges = rawEntityRanges || [];
  14472. var inlineStyleRanges = rawInlineStyleRanges || [];
  14473. // Translate entity range keys to the DraftEntity map.
  14474. return createCharacterList_1(decodeInlineStyleRanges_1(text, inlineStyleRanges), decodeEntityRanges_1(text, entityRanges.filter(function (range) {
  14475. return entityMap.hasOwnProperty(range.key);
  14476. }).map(function (range) {
  14477. return _extends$8({}, range, { key: entityMap[range.key] });
  14478. })));
  14479. };
  14480. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14481. return OrderedMap$4(blocks.map(function (block) {
  14482. var contentBlock = new ContentBlock_1(decodeBlockNodeConfig(block, entityMap));
  14483. return [contentBlock.getKey(), contentBlock];
  14484. }));
  14485. };
  14486. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14487. var isTreeRawBlock = Array.isArray(rawState.blocks[0].children);
  14488. var rawBlocks = rawState.blocks;
  14489. {
  14490. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter_1.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14491. }
  14492. };
  14493. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14494. var rawEntityMap = rawState.entityMap;
  14495. var entityMap = {};
  14496. // TODO: Update this once we completely remove DraftEntity
  14497. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14498. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14499. type = _rawEntityMap$rawEnti.type,
  14500. mutability = _rawEntityMap$rawEnti.mutability,
  14501. data = _rawEntityMap$rawEnti.data;
  14502. // get the key reference to created entity
  14503. entityMap[rawEntityKey] = DraftEntity_1.__create(type, mutability, data || {});
  14504. });
  14505. return entityMap;
  14506. };
  14507. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14508. !Array.isArray(rawState.blocks) ? process.env.NODE_ENV !== 'production' ? invariant_1(false, 'invalid RawDraftContentState') : invariant_1(false) : void 0;
  14509. // decode entities
  14510. var entityMap = decodeRawEntityMap(rawState);
  14511. // decode blockMap
  14512. var blockMap = decodeRawBlocks(rawState, entityMap);
  14513. // create initial selection
  14514. var selectionState = blockMap.isEmpty() ? new SelectionState_1() : SelectionState_1.createEmpty(blockMap.first().getKey());
  14515. return new ContentState_1({
  14516. blockMap: blockMap,
  14517. entityMap: entityMap,
  14518. selectionBefore: selectionState,
  14519. selectionAfter: selectionState
  14520. });
  14521. };
  14522. var convertFromRawToDraftState_1 = convertFromRawToDraftState;
  14523. /**
  14524. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14525. */
  14526. function getRangeBoundingClientRect(range) {
  14527. // "Return a DOMRect object describing the smallest rectangle that includes
  14528. // the first rectangle in list and all of the remaining rectangles of which
  14529. // the height or width is not zero."
  14530. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14531. var rects = getRangeClientRects_1(range);
  14532. var top = 0;
  14533. var right = 0;
  14534. var bottom = 0;
  14535. var left = 0;
  14536. if (rects.length) {
  14537. // If the first rectangle has 0 width, we use the second, this is needed
  14538. // because Chrome renders a 0 width rectangle when the selection contains
  14539. // a line break.
  14540. if (rects.length > 1 && rects[0].width === 0) {
  14541. var _rects$ = rects[1];
  14542. top = _rects$.top;
  14543. right = _rects$.right;
  14544. bottom = _rects$.bottom;
  14545. left = _rects$.left;
  14546. } else {
  14547. var _rects$2 = rects[0];
  14548. top = _rects$2.top;
  14549. right = _rects$2.right;
  14550. bottom = _rects$2.bottom;
  14551. left = _rects$2.left;
  14552. }
  14553. for (var ii = 1; ii < rects.length; ii++) {
  14554. var rect = rects[ii];
  14555. if (rect.height !== 0 && rect.width !== 0) {
  14556. top = Math.min(top, rect.top);
  14557. right = Math.max(right, rect.right);
  14558. bottom = Math.max(bottom, rect.bottom);
  14559. left = Math.min(left, rect.left);
  14560. }
  14561. }
  14562. }
  14563. return {
  14564. top: top,
  14565. right: right,
  14566. bottom: bottom,
  14567. left: left,
  14568. width: right - left,
  14569. height: bottom - top
  14570. };
  14571. }
  14572. var getRangeBoundingClientRect_1 = getRangeBoundingClientRect;
  14573. /**
  14574. * Return the bounding ClientRect for the visible DOM selection, if any.
  14575. * In cases where there are no selected ranges or the bounding rect is
  14576. * temporarily invalid, return null.
  14577. */
  14578. function getVisibleSelectionRect(global) {
  14579. var selection = global.getSelection();
  14580. if (!selection.rangeCount) {
  14581. return null;
  14582. }
  14583. var range = selection.getRangeAt(0);
  14584. var boundingRect = getRangeBoundingClientRect_1(range);
  14585. var top = boundingRect.top,
  14586. right = boundingRect.right,
  14587. bottom = boundingRect.bottom,
  14588. left = boundingRect.left;
  14589. // When a re-render leads to a node being removed, the DOM selection will
  14590. // temporarily be placed on an ancestor node, which leads to an invalid
  14591. // bounding rect. Discard this state.
  14592. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14593. return null;
  14594. }
  14595. return boundingRect;
  14596. }
  14597. var getVisibleSelectionRect_1 = getVisibleSelectionRect;
  14598. var DraftPublic = {
  14599. Editor: DraftEditor_react,
  14600. EditorBlock: DraftEditorBlock_react,
  14601. EditorState: EditorState_1,
  14602. CompositeDecorator: CompositeDraftDecorator_1,
  14603. Entity: DraftEntity_1,
  14604. EntityInstance: DraftEntityInstance_1,
  14605. BlockMapBuilder: BlockMapBuilder_1,
  14606. CharacterMetadata: CharacterMetadata_1,
  14607. ContentBlock: ContentBlock_1,
  14608. ContentState: ContentState_1,
  14609. SelectionState: SelectionState_1,
  14610. AtomicBlockUtils: AtomicBlockUtils_1,
  14611. KeyBindingUtil: KeyBindingUtil_1,
  14612. Modifier: DraftModifier_1,
  14613. RichUtils: RichTextEditorUtil_1,
  14614. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap_1,
  14615. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  14616. convertFromHTML: convertFromHTMLToContentBlocks,
  14617. convertFromRaw: convertFromRawToDraftState_1,
  14618. convertToRaw: convertFromDraftStateToRaw_1,
  14619. genKey: generateRandomKey_1,
  14620. getDefaultKeyBinding: getDefaultKeyBinding_1,
  14621. getVisibleSelectionRect: getVisibleSelectionRect_1
  14622. };
  14623. var Draft = DraftPublic;
  14624. var Draft_1 = Draft.Editor;
  14625. var Draft_3 = Draft.EditorState;
  14626. var Draft_4 = Draft.CompositeDecorator;
  14627. var Draft_14 = Draft.Modifier;
  14628. var Draft_15 = Draft.RichUtils;
  14629. var Draft_20 = Draft.convertToRaw;
  14630. exports.Draft = Draft;
  14631. exports.Draft_1 = Draft_1;
  14632. exports.Draft_14 = Draft_14;
  14633. exports.Draft_15 = Draft_15;
  14634. exports.Draft_20 = Draft_20;
  14635. exports.Draft_3 = Draft_3;
  14636. exports.Draft_4 = Draft_4;
  14637. //# sourceMappingURL=Draft-a5afe13a.js.map