選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Draft.js 568 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236
  1. /**
  2. * Draft v0.11.5
  3. *
  4. * Copyright (c) Facebook, Inc. and its affiliates.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. (function webpackUniversalModuleDefinition(root, factory) {
  10. if(typeof exports === 'object' && typeof module === 'object')
  11. module.exports = factory(require("immutable"), require("react"), require("react-dom"));
  12. else if(typeof define === 'function' && define.amd)
  13. define(["immutable", "react", "react-dom"], factory);
  14. else if(typeof exports === 'object')
  15. exports["Draft"] = factory(require("immutable"), require("react"), require("react-dom"));
  16. else
  17. root["Draft"] = factory(root["Immutable"], root["React"], root["ReactDOM"]);
  18. })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_161__) {
  19. return /******/ (function(modules) { // webpackBootstrap
  20. /******/ // The module cache
  21. /******/ var installedModules = {};
  22. /******/
  23. /******/ // The require function
  24. /******/ function __webpack_require__(moduleId) {
  25. /******/
  26. /******/ // Check if module is in cache
  27. /******/ if(installedModules[moduleId]) {
  28. /******/ return installedModules[moduleId].exports;
  29. /******/ }
  30. /******/ // Create a new module (and put it into the cache)
  31. /******/ var module = installedModules[moduleId] = {
  32. /******/ i: moduleId,
  33. /******/ l: false,
  34. /******/ exports: {}
  35. /******/ };
  36. /******/
  37. /******/ // Execute the module function
  38. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  39. /******/
  40. /******/ // Flag the module as loaded
  41. /******/ module.l = true;
  42. /******/
  43. /******/ // Return the exports of the module
  44. /******/ return module.exports;
  45. /******/ }
  46. /******/
  47. /******/
  48. /******/ // expose the modules object (__webpack_modules__)
  49. /******/ __webpack_require__.m = modules;
  50. /******/
  51. /******/ // expose the module cache
  52. /******/ __webpack_require__.c = installedModules;
  53. /******/
  54. /******/ // define getter function for harmony exports
  55. /******/ __webpack_require__.d = function(exports, name, getter) {
  56. /******/ if(!__webpack_require__.o(exports, name)) {
  57. /******/ Object.defineProperty(exports, name, {
  58. /******/ configurable: false,
  59. /******/ enumerable: true,
  60. /******/ get: getter
  61. /******/ });
  62. /******/ }
  63. /******/ };
  64. /******/
  65. /******/ // getDefaultExport function for compatibility with non-harmony modules
  66. /******/ __webpack_require__.n = function(module) {
  67. /******/ var getter = module && module.__esModule ?
  68. /******/ function getDefault() { return module['default']; } :
  69. /******/ function getModuleExports() { return module; };
  70. /******/ __webpack_require__.d(getter, 'a', getter);
  71. /******/ return getter;
  72. /******/ };
  73. /******/
  74. /******/ // Object.prototype.hasOwnProperty.call
  75. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  76. /******/
  77. /******/ // __webpack_public_path__
  78. /******/ __webpack_require__.p = "";
  79. /******/
  80. /******/ // Load entry module and return exports
  81. /******/ return __webpack_require__(__webpack_require__.s = 78);
  82. /******/ })
  83. /************************************************************************/
  84. /******/ ([
  85. /* 0 */
  86. /***/ (function(module, exports) {
  87. module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
  88. /***/ }),
  89. /* 1 */
  90. /***/ (function(module, exports, __webpack_require__) {
  91. "use strict";
  92. /**
  93. * Copyright (c) 2013-present, Facebook, Inc.
  94. *
  95. * This source code is licensed under the MIT license found in the
  96. * LICENSE file in the root directory of this source tree.
  97. *
  98. *
  99. */
  100. var validateFormat = true ? function (format) {} : function (format) {
  101. if (format === undefined) {
  102. throw new Error('invariant(...): Second argument must be a string.');
  103. }
  104. };
  105. /**
  106. * Use invariant() to assert state which your program assumes to be true.
  107. *
  108. * Provide sprintf-style format (only %s is supported) and arguments to provide
  109. * information about what broke and what you were expecting.
  110. *
  111. * The invariant message will be stripped in production, but the invariant will
  112. * remain to ensure logic does not differ in production.
  113. */
  114. function invariant(condition, format) {
  115. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  116. args[_key - 2] = arguments[_key];
  117. }
  118. validateFormat(format);
  119. if (!condition) {
  120. var error;
  121. if (format === undefined) {
  122. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  123. } else {
  124. var argIndex = 0;
  125. error = new Error(format.replace(/%s/g, function () {
  126. return String(args[argIndex++]);
  127. }));
  128. error.name = 'Invariant Violation';
  129. }
  130. error.framesToPop = 1; // Skip invariant's own stack frame.
  131. throw error;
  132. }
  133. }
  134. module.exports = invariant;
  135. /***/ }),
  136. /* 2 */
  137. /***/ (function(module, exports, __webpack_require__) {
  138. "use strict";
  139. /**
  140. * Copyright (c) Facebook, Inc. and its affiliates.
  141. *
  142. * This source code is licensed under the MIT license found in the
  143. * LICENSE file in the root directory of this source tree.
  144. *
  145. * @format
  146. *
  147. * @emails oncall+draft_js
  148. */
  149. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  150. 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; }
  151. var BlockTree = __webpack_require__(90);
  152. var ContentState = __webpack_require__(32);
  153. var EditorBidiService = __webpack_require__(91);
  154. var SelectionState = __webpack_require__(23);
  155. var Immutable = __webpack_require__(0);
  156. var OrderedSet = Immutable.OrderedSet,
  157. Record = Immutable.Record,
  158. Stack = Immutable.Stack; // When configuring an editor, the user can chose to provide or not provide
  159. // basically all keys. `currentContent` varies, so this type doesn't include it.
  160. // (See the types defined below.)
  161. var defaultRecord = {
  162. allowUndo: true,
  163. currentContent: null,
  164. decorator: null,
  165. directionMap: null,
  166. forceSelection: false,
  167. inCompositionMode: false,
  168. inlineStyleOverride: null,
  169. lastChangeType: null,
  170. nativelyRenderedContent: null,
  171. redoStack: Stack(),
  172. selection: null,
  173. treeMap: null,
  174. undoStack: Stack()
  175. };
  176. var EditorStateRecord = Record(defaultRecord);
  177. var EditorState =
  178. /*#__PURE__*/
  179. function () {
  180. EditorState.createEmpty = function createEmpty(decorator) {
  181. return EditorState.createWithContent(ContentState.createFromText(''), decorator);
  182. };
  183. EditorState.createWithContent = function createWithContent(contentState, decorator) {
  184. if (contentState.getBlockMap().count() === 0) {
  185. return EditorState.createEmpty(decorator);
  186. }
  187. var firstKey = contentState.getBlockMap().first().getKey();
  188. return EditorState.create({
  189. currentContent: contentState,
  190. undoStack: Stack(),
  191. redoStack: Stack(),
  192. decorator: decorator || null,
  193. selection: SelectionState.createEmpty(firstKey)
  194. });
  195. };
  196. EditorState.create = function create(config) {
  197. var currentContent = config.currentContent,
  198. decorator = config.decorator;
  199. var recordConfig = _objectSpread({}, config, {
  200. treeMap: generateNewTreeMap(currentContent, decorator),
  201. directionMap: EditorBidiService.getDirectionMap(currentContent)
  202. });
  203. return new EditorState(new EditorStateRecord(recordConfig));
  204. };
  205. EditorState.set = function set(editorState, put) {
  206. var map = editorState.getImmutable().withMutations(function (state) {
  207. var existingDecorator = state.get('decorator');
  208. var decorator = existingDecorator;
  209. if (put.decorator === null) {
  210. decorator = null;
  211. } else if (put.decorator) {
  212. decorator = put.decorator;
  213. }
  214. var newContent = put.currentContent || editorState.getCurrentContent();
  215. if (decorator !== existingDecorator) {
  216. var treeMap = state.get('treeMap');
  217. var newTreeMap;
  218. if (decorator && existingDecorator) {
  219. newTreeMap = regenerateTreeForNewDecorator(newContent, newContent.getBlockMap(), treeMap, decorator, existingDecorator);
  220. } else {
  221. newTreeMap = generateNewTreeMap(newContent, decorator);
  222. }
  223. state.merge({
  224. decorator: decorator,
  225. treeMap: newTreeMap,
  226. nativelyRenderedContent: null
  227. });
  228. return;
  229. }
  230. var existingContent = editorState.getCurrentContent();
  231. if (newContent !== existingContent) {
  232. state.set('treeMap', regenerateTreeForNewBlocks(editorState, newContent.getBlockMap(), newContent.getEntityMap(), decorator));
  233. }
  234. state.merge(put);
  235. });
  236. return new EditorState(map);
  237. };
  238. var _proto = EditorState.prototype;
  239. _proto.toJS = function toJS() {
  240. return this.getImmutable().toJS();
  241. };
  242. _proto.getAllowUndo = function getAllowUndo() {
  243. return this.getImmutable().get('allowUndo');
  244. };
  245. _proto.getCurrentContent = function getCurrentContent() {
  246. return this.getImmutable().get('currentContent');
  247. };
  248. _proto.getUndoStack = function getUndoStack() {
  249. return this.getImmutable().get('undoStack');
  250. };
  251. _proto.getRedoStack = function getRedoStack() {
  252. return this.getImmutable().get('redoStack');
  253. };
  254. _proto.getSelection = function getSelection() {
  255. return this.getImmutable().get('selection');
  256. };
  257. _proto.getDecorator = function getDecorator() {
  258. return this.getImmutable().get('decorator');
  259. };
  260. _proto.isInCompositionMode = function isInCompositionMode() {
  261. return this.getImmutable().get('inCompositionMode');
  262. };
  263. _proto.mustForceSelection = function mustForceSelection() {
  264. return this.getImmutable().get('forceSelection');
  265. };
  266. _proto.getNativelyRenderedContent = function getNativelyRenderedContent() {
  267. return this.getImmutable().get('nativelyRenderedContent');
  268. };
  269. _proto.getLastChangeType = function getLastChangeType() {
  270. return this.getImmutable().get('lastChangeType');
  271. }
  272. /**
  273. * While editing, the user may apply inline style commands with a collapsed
  274. * cursor, intending to type text that adopts the specified style. In this
  275. * case, we track the specified style as an "override" that takes precedence
  276. * over the inline style of the text adjacent to the cursor.
  277. *
  278. * If null, there is no override in place.
  279. */
  280. ;
  281. _proto.getInlineStyleOverride = function getInlineStyleOverride() {
  282. return this.getImmutable().get('inlineStyleOverride');
  283. };
  284. EditorState.setInlineStyleOverride = function setInlineStyleOverride(editorState, inlineStyleOverride) {
  285. return EditorState.set(editorState, {
  286. inlineStyleOverride: inlineStyleOverride
  287. });
  288. }
  289. /**
  290. * Get the appropriate inline style for the editor state. If an
  291. * override is in place, use it. Otherwise, the current style is
  292. * based on the location of the selection state.
  293. */
  294. ;
  295. _proto.getCurrentInlineStyle = function getCurrentInlineStyle() {
  296. var override = this.getInlineStyleOverride();
  297. if (override != null) {
  298. return override;
  299. }
  300. var content = this.getCurrentContent();
  301. var selection = this.getSelection();
  302. if (selection.isCollapsed()) {
  303. return getInlineStyleForCollapsedSelection(content, selection);
  304. }
  305. return getInlineStyleForNonCollapsedSelection(content, selection);
  306. };
  307. _proto.getBlockTree = function getBlockTree(blockKey) {
  308. return this.getImmutable().getIn(['treeMap', blockKey]);
  309. };
  310. _proto.isSelectionAtStartOfContent = function isSelectionAtStartOfContent() {
  311. var firstKey = this.getCurrentContent().getBlockMap().first().getKey();
  312. return this.getSelection().hasEdgeWithin(firstKey, 0, 0);
  313. };
  314. _proto.isSelectionAtEndOfContent = function isSelectionAtEndOfContent() {
  315. var content = this.getCurrentContent();
  316. var blockMap = content.getBlockMap();
  317. var last = blockMap.last();
  318. var end = last.getLength();
  319. return this.getSelection().hasEdgeWithin(last.getKey(), end, end);
  320. };
  321. _proto.getDirectionMap = function getDirectionMap() {
  322. return this.getImmutable().get('directionMap');
  323. }
  324. /**
  325. * Incorporate native DOM selection changes into the EditorState. This
  326. * method can be used when we simply want to accept whatever the DOM
  327. * has given us to represent selection, and we do not need to re-render
  328. * the editor.
  329. *
  330. * To forcibly move the DOM selection, see `EditorState.forceSelection`.
  331. */
  332. ;
  333. EditorState.acceptSelection = function acceptSelection(editorState, selection) {
  334. return updateSelection(editorState, selection, false);
  335. }
  336. /**
  337. * At times, we need to force the DOM selection to be where we
  338. * need it to be. This can occur when the anchor or focus nodes
  339. * are non-text nodes, for instance. In this case, we want to trigger
  340. * a re-render of the editor, which in turn forces selection into
  341. * the correct place in the DOM. The `forceSelection` method
  342. * accomplishes this.
  343. *
  344. * This method should be used in cases where you need to explicitly
  345. * move the DOM selection from one place to another without a change
  346. * in ContentState.
  347. */
  348. ;
  349. EditorState.forceSelection = function forceSelection(editorState, selection) {
  350. if (!selection.getHasFocus()) {
  351. selection = selection.set('hasFocus', true);
  352. }
  353. return updateSelection(editorState, selection, true);
  354. }
  355. /**
  356. * Move selection to the end of the editor without forcing focus.
  357. */
  358. ;
  359. EditorState.moveSelectionToEnd = function moveSelectionToEnd(editorState) {
  360. var content = editorState.getCurrentContent();
  361. var lastBlock = content.getLastBlock();
  362. var lastKey = lastBlock.getKey();
  363. var length = lastBlock.getLength();
  364. return EditorState.acceptSelection(editorState, new SelectionState({
  365. anchorKey: lastKey,
  366. anchorOffset: length,
  367. focusKey: lastKey,
  368. focusOffset: length,
  369. isBackward: false
  370. }));
  371. }
  372. /**
  373. * Force focus to the end of the editor. This is useful in scenarios
  374. * where we want to programmatically focus the input and it makes sense
  375. * to allow the user to continue working seamlessly.
  376. */
  377. ;
  378. EditorState.moveFocusToEnd = function moveFocusToEnd(editorState) {
  379. var afterSelectionMove = EditorState.moveSelectionToEnd(editorState);
  380. return EditorState.forceSelection(afterSelectionMove, afterSelectionMove.getSelection());
  381. }
  382. /**
  383. * Push the current ContentState onto the undo stack if it should be
  384. * considered a boundary state, and set the provided ContentState as the
  385. * new current content.
  386. */
  387. ;
  388. EditorState.push = function push(editorState, contentState, changeType) {
  389. var forceSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  390. if (editorState.getCurrentContent() === contentState) {
  391. return editorState;
  392. }
  393. var directionMap = EditorBidiService.getDirectionMap(contentState, editorState.getDirectionMap());
  394. if (!editorState.getAllowUndo()) {
  395. return EditorState.set(editorState, {
  396. currentContent: contentState,
  397. directionMap: directionMap,
  398. lastChangeType: changeType,
  399. selection: contentState.getSelectionAfter(),
  400. forceSelection: forceSelection,
  401. inlineStyleOverride: null
  402. });
  403. }
  404. var selection = editorState.getSelection();
  405. var currentContent = editorState.getCurrentContent();
  406. var undoStack = editorState.getUndoStack();
  407. var newContent = contentState;
  408. if (selection !== currentContent.getSelectionAfter() || mustBecomeBoundary(editorState, changeType)) {
  409. undoStack = undoStack.push(currentContent);
  410. newContent = newContent.set('selectionBefore', selection);
  411. } else if (changeType === 'insert-characters' || changeType === 'backspace-character' || changeType === 'delete-character') {
  412. // Preserve the previous selection.
  413. newContent = newContent.set('selectionBefore', currentContent.getSelectionBefore());
  414. }
  415. var inlineStyleOverride = editorState.getInlineStyleOverride(); // Don't discard inline style overrides for the following change types:
  416. var overrideChangeTypes = ['adjust-depth', 'change-block-type', 'split-block'];
  417. if (overrideChangeTypes.indexOf(changeType) === -1) {
  418. inlineStyleOverride = null;
  419. }
  420. var editorStateChanges = {
  421. currentContent: newContent,
  422. directionMap: directionMap,
  423. undoStack: undoStack,
  424. redoStack: Stack(),
  425. lastChangeType: changeType,
  426. selection: contentState.getSelectionAfter(),
  427. forceSelection: forceSelection,
  428. inlineStyleOverride: inlineStyleOverride
  429. };
  430. return EditorState.set(editorState, editorStateChanges);
  431. }
  432. /**
  433. * Make the top ContentState in the undo stack the new current content and
  434. * push the current content onto the redo stack.
  435. */
  436. ;
  437. EditorState.undo = function undo(editorState) {
  438. if (!editorState.getAllowUndo()) {
  439. return editorState;
  440. }
  441. var undoStack = editorState.getUndoStack();
  442. var newCurrentContent = undoStack.peek();
  443. if (!newCurrentContent) {
  444. return editorState;
  445. }
  446. var currentContent = editorState.getCurrentContent();
  447. var directionMap = EditorBidiService.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  448. return EditorState.set(editorState, {
  449. currentContent: newCurrentContent,
  450. directionMap: directionMap,
  451. undoStack: undoStack.shift(),
  452. redoStack: editorState.getRedoStack().push(currentContent),
  453. forceSelection: true,
  454. inlineStyleOverride: null,
  455. lastChangeType: 'undo',
  456. nativelyRenderedContent: null,
  457. selection: currentContent.getSelectionBefore()
  458. });
  459. }
  460. /**
  461. * Make the top ContentState in the redo stack the new current content and
  462. * push the current content onto the undo stack.
  463. */
  464. ;
  465. EditorState.redo = function redo(editorState) {
  466. if (!editorState.getAllowUndo()) {
  467. return editorState;
  468. }
  469. var redoStack = editorState.getRedoStack();
  470. var newCurrentContent = redoStack.peek();
  471. if (!newCurrentContent) {
  472. return editorState;
  473. }
  474. var currentContent = editorState.getCurrentContent();
  475. var directionMap = EditorBidiService.getDirectionMap(newCurrentContent, editorState.getDirectionMap());
  476. return EditorState.set(editorState, {
  477. currentContent: newCurrentContent,
  478. directionMap: directionMap,
  479. undoStack: editorState.getUndoStack().push(currentContent),
  480. redoStack: redoStack.shift(),
  481. forceSelection: true,
  482. inlineStyleOverride: null,
  483. lastChangeType: 'redo',
  484. nativelyRenderedContent: null,
  485. selection: newCurrentContent.getSelectionAfter()
  486. });
  487. }
  488. /**
  489. * Not for public consumption.
  490. */
  491. ;
  492. function EditorState(immutable) {
  493. _defineProperty(this, "_immutable", void 0);
  494. this._immutable = immutable;
  495. }
  496. /**
  497. * Not for public consumption.
  498. */
  499. _proto.getImmutable = function getImmutable() {
  500. return this._immutable;
  501. };
  502. return EditorState;
  503. }();
  504. /**
  505. * Set the supplied SelectionState as the new current selection, and set
  506. * the `force` flag to trigger manual selection placement by the view.
  507. */
  508. function updateSelection(editorState, selection, forceSelection) {
  509. return EditorState.set(editorState, {
  510. selection: selection,
  511. forceSelection: forceSelection,
  512. nativelyRenderedContent: null,
  513. inlineStyleOverride: null
  514. });
  515. }
  516. /**
  517. * Regenerate the entire tree map for a given ContentState and decorator.
  518. * Returns an OrderedMap that maps all available ContentBlock objects.
  519. */
  520. function generateNewTreeMap(contentState, decorator) {
  521. return contentState.getBlockMap().map(function (block) {
  522. return BlockTree.generate(contentState, block, decorator);
  523. }).toOrderedMap();
  524. }
  525. /**
  526. * Regenerate tree map objects for all ContentBlocks that have changed
  527. * between the current editorState and newContent. Returns an OrderedMap
  528. * with only changed regenerated tree map objects.
  529. */
  530. function regenerateTreeForNewBlocks(editorState, newBlockMap, newEntityMap, decorator) {
  531. var contentState = editorState.getCurrentContent().set('entityMap', newEntityMap);
  532. var prevBlockMap = contentState.getBlockMap();
  533. var prevTreeMap = editorState.getImmutable().get('treeMap');
  534. return prevTreeMap.merge(newBlockMap.toSeq().filter(function (block, key) {
  535. return block !== prevBlockMap.get(key);
  536. }).map(function (block) {
  537. return BlockTree.generate(contentState, block, decorator);
  538. }));
  539. }
  540. /**
  541. * Generate tree map objects for a new decorator object, preserving any
  542. * decorations that are unchanged from the previous decorator.
  543. *
  544. * Note that in order for this to perform optimally, decoration Lists for
  545. * decorators should be preserved when possible to allow for direct immutable
  546. * List comparison.
  547. */
  548. function regenerateTreeForNewDecorator(content, blockMap, previousTreeMap, decorator, existingDecorator) {
  549. return previousTreeMap.merge(blockMap.toSeq().filter(function (block) {
  550. return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content);
  551. }).map(function (block) {
  552. return BlockTree.generate(content, block, decorator);
  553. }));
  554. }
  555. /**
  556. * Return whether a change should be considered a boundary state, given
  557. * the previous change type. Allows us to discard potential boundary states
  558. * during standard typing or deletion behavior.
  559. */
  560. function mustBecomeBoundary(editorState, changeType) {
  561. var lastChangeType = editorState.getLastChangeType();
  562. return changeType !== lastChangeType || changeType !== 'insert-characters' && changeType !== 'backspace-character' && changeType !== 'delete-character';
  563. }
  564. function getInlineStyleForCollapsedSelection(content, selection) {
  565. var startKey = selection.getStartKey();
  566. var startOffset = selection.getStartOffset();
  567. var startBlock = content.getBlockForKey(startKey); // If the cursor is not at the start of the block, look backward to
  568. // preserve the style of the preceding character.
  569. if (startOffset > 0) {
  570. return startBlock.getInlineStyleAt(startOffset - 1);
  571. } // The caret is at position zero in this block. If the block has any
  572. // text at all, use the style of the first character.
  573. if (startBlock.getLength()) {
  574. return startBlock.getInlineStyleAt(0);
  575. } // Otherwise, look upward in the document to find the closest character.
  576. return lookUpwardForInlineStyle(content, startKey);
  577. }
  578. function getInlineStyleForNonCollapsedSelection(content, selection) {
  579. var startKey = selection.getStartKey();
  580. var startOffset = selection.getStartOffset();
  581. var startBlock = content.getBlockForKey(startKey); // If there is a character just inside the selection, use its style.
  582. if (startOffset < startBlock.getLength()) {
  583. return startBlock.getInlineStyleAt(startOffset);
  584. } // Check if the selection at the end of a non-empty block. Use the last
  585. // style in the block.
  586. if (startOffset > 0) {
  587. return startBlock.getInlineStyleAt(startOffset - 1);
  588. } // Otherwise, look upward in the document to find the closest character.
  589. return lookUpwardForInlineStyle(content, startKey);
  590. }
  591. function lookUpwardForInlineStyle(content, fromKey) {
  592. var lastNonEmpty = content.getBlockMap().reverse().skipUntil(function (_, k) {
  593. return k === fromKey;
  594. }).skip(1).skipUntil(function (block, _) {
  595. return block.getLength();
  596. }).first();
  597. if (lastNonEmpty) {
  598. return lastNonEmpty.getInlineStyleAt(lastNonEmpty.getLength() - 1);
  599. }
  600. return OrderedSet();
  601. }
  602. module.exports = EditorState;
  603. /***/ }),
  604. /* 3 */
  605. /***/ (function(module, exports, __webpack_require__) {
  606. "use strict";
  607. /**
  608. * Copyright (c) Facebook, Inc. and its affiliates.
  609. *
  610. * This source code is licensed under the MIT license found in the
  611. * LICENSE file in the root directory of this source tree.
  612. *
  613. * @format
  614. *
  615. * @emails oncall+draft_js
  616. */
  617. var CharacterMetadata = __webpack_require__(6);
  618. var ContentStateInlineStyle = __webpack_require__(80);
  619. var applyEntityToContentState = __webpack_require__(81);
  620. var getCharacterRemovalRange = __webpack_require__(83);
  621. var getContentStateFragment = __webpack_require__(21);
  622. var Immutable = __webpack_require__(0);
  623. var insertFragmentIntoContentState = __webpack_require__(86);
  624. var insertTextIntoContentState = __webpack_require__(87);
  625. var invariant = __webpack_require__(1);
  626. var modifyBlockForContentState = __webpack_require__(44);
  627. var removeEntitiesAtEdges = __webpack_require__(42);
  628. var removeRangeFromContentState = __webpack_require__(88);
  629. var splitBlockInContentState = __webpack_require__(89);
  630. var OrderedSet = Immutable.OrderedSet;
  631. /**
  632. * `DraftModifier` provides a set of convenience methods that apply
  633. * modifications to a `ContentState` object based on a target `SelectionState`.
  634. *
  635. * Any change to a `ContentState` should be decomposable into a series of
  636. * transaction functions that apply the required changes and return output
  637. * `ContentState` objects.
  638. *
  639. * These functions encapsulate some of the most common transaction sequences.
  640. */
  641. var DraftModifier = {
  642. replaceText: function replaceText(contentState, rangeToReplace, text, inlineStyle, entityKey) {
  643. var withoutEntities = removeEntitiesAtEdges(contentState, rangeToReplace);
  644. var withoutText = removeRangeFromContentState(withoutEntities, rangeToReplace);
  645. var character = CharacterMetadata.create({
  646. style: inlineStyle || OrderedSet(),
  647. entity: entityKey || null
  648. });
  649. return insertTextIntoContentState(withoutText, withoutText.getSelectionAfter(), text, character);
  650. },
  651. insertText: function insertText(contentState, targetRange, text, inlineStyle, entityKey) {
  652. !targetRange.isCollapsed() ? true ? invariant(false, 'Target range must be collapsed for `insertText`.') : invariant(false) : void 0;
  653. return DraftModifier.replaceText(contentState, targetRange, text, inlineStyle, entityKey);
  654. },
  655. moveText: function moveText(contentState, removalRange, targetRange) {
  656. var movedFragment = getContentStateFragment(contentState, removalRange);
  657. var afterRemoval = DraftModifier.removeRange(contentState, removalRange, 'backward');
  658. return DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  659. },
  660. replaceWithFragment: function replaceWithFragment(contentState, targetRange, fragment) {
  661. var mergeBlockData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'REPLACE_WITH_NEW_DATA';
  662. var withoutEntities = removeEntitiesAtEdges(contentState, targetRange);
  663. var withoutText = removeRangeFromContentState(withoutEntities, targetRange);
  664. return insertFragmentIntoContentState(withoutText, withoutText.getSelectionAfter(), fragment, mergeBlockData);
  665. },
  666. removeRange: function removeRange(contentState, rangeToRemove, removalDirection) {
  667. var startKey, endKey, startBlock, endBlock;
  668. if (rangeToRemove.getIsBackward()) {
  669. rangeToRemove = rangeToRemove.merge({
  670. anchorKey: rangeToRemove.getFocusKey(),
  671. anchorOffset: rangeToRemove.getFocusOffset(),
  672. focusKey: rangeToRemove.getAnchorKey(),
  673. focusOffset: rangeToRemove.getAnchorOffset(),
  674. isBackward: false
  675. });
  676. }
  677. startKey = rangeToRemove.getAnchorKey();
  678. endKey = rangeToRemove.getFocusKey();
  679. startBlock = contentState.getBlockForKey(startKey);
  680. endBlock = contentState.getBlockForKey(endKey);
  681. var startOffset = rangeToRemove.getStartOffset();
  682. var endOffset = rangeToRemove.getEndOffset();
  683. var startEntityKey = startBlock.getEntityAt(startOffset);
  684. var endEntityKey = endBlock.getEntityAt(endOffset - 1); // Check whether the selection state overlaps with a single entity.
  685. // If so, try to remove the appropriate substring of the entity text.
  686. if (startKey === endKey) {
  687. if (startEntityKey && startEntityKey === endEntityKey) {
  688. var adjustedRemovalRange = getCharacterRemovalRange(contentState.getEntityMap(), startBlock, endBlock, rangeToRemove, removalDirection);
  689. return removeRangeFromContentState(contentState, adjustedRemovalRange);
  690. }
  691. }
  692. var withoutEntities = removeEntitiesAtEdges(contentState, rangeToRemove);
  693. return removeRangeFromContentState(withoutEntities, rangeToRemove);
  694. },
  695. splitBlock: function splitBlock(contentState, selectionState) {
  696. var withoutEntities = removeEntitiesAtEdges(contentState, selectionState);
  697. var withoutText = removeRangeFromContentState(withoutEntities, selectionState);
  698. return splitBlockInContentState(withoutText, withoutText.getSelectionAfter());
  699. },
  700. applyInlineStyle: function applyInlineStyle(contentState, selectionState, inlineStyle) {
  701. return ContentStateInlineStyle.add(contentState, selectionState, inlineStyle);
  702. },
  703. removeInlineStyle: function removeInlineStyle(contentState, selectionState, inlineStyle) {
  704. return ContentStateInlineStyle.remove(contentState, selectionState, inlineStyle);
  705. },
  706. setBlockType: function setBlockType(contentState, selectionState, blockType) {
  707. return modifyBlockForContentState(contentState, selectionState, function (block) {
  708. return block.merge({
  709. type: blockType,
  710. depth: 0
  711. });
  712. });
  713. },
  714. setBlockData: function setBlockData(contentState, selectionState, blockData) {
  715. return modifyBlockForContentState(contentState, selectionState, function (block) {
  716. return block.merge({
  717. data: blockData
  718. });
  719. });
  720. },
  721. mergeBlockData: function mergeBlockData(contentState, selectionState, blockData) {
  722. return modifyBlockForContentState(contentState, selectionState, function (block) {
  723. return block.merge({
  724. data: block.getData().merge(blockData)
  725. });
  726. });
  727. },
  728. applyEntity: function applyEntity(contentState, selectionState, entityKey) {
  729. var withoutEntities = removeEntitiesAtEdges(contentState, selectionState);
  730. return applyEntityToContentState(withoutEntities, selectionState, entityKey);
  731. }
  732. };
  733. module.exports = DraftModifier;
  734. /***/ }),
  735. /* 4 */
  736. /***/ (function(module, exports, __webpack_require__) {
  737. "use strict";
  738. /**
  739. * Copyright (c) 2013-present, Facebook, Inc.
  740. *
  741. * This source code is licensed under the MIT license found in the
  742. * LICENSE file in the root directory of this source tree.
  743. *
  744. *
  745. */
  746. var nullthrows = function nullthrows(x) {
  747. if (x != null) {
  748. return x;
  749. }
  750. throw new Error("Got unexpected null or undefined");
  751. };
  752. module.exports = nullthrows;
  753. /***/ }),
  754. /* 5 */
  755. /***/ (function(module, exports, __webpack_require__) {
  756. "use strict";
  757. /**
  758. * Copyright (c) 2013-present, Facebook, Inc.
  759. *
  760. * This source code is licensed under the MIT license found in the
  761. * LICENSE file in the root directory of this source tree.
  762. *
  763. */
  764. var UserAgentData = __webpack_require__(98);
  765. var VersionRange = __webpack_require__(101);
  766. var mapObject = __webpack_require__(102);
  767. var memoizeStringOnly = __webpack_require__(103);
  768. /**
  769. * Checks to see whether `name` and `version` satisfy `query`.
  770. *
  771. * @param {string} name Name of the browser, device, engine or platform
  772. * @param {?string} version Version of the browser, engine or platform
  773. * @param {string} query Query of form "Name [range expression]"
  774. * @param {?function} normalizer Optional pre-processor for range expression
  775. * @return {boolean}
  776. */
  777. function compare(name, version, query, normalizer) {
  778. // check for exact match with no version
  779. if (name === query) {
  780. return true;
  781. } // check for non-matching names
  782. if (!query.startsWith(name)) {
  783. return false;
  784. } // full comparison with version
  785. var range = query.slice(name.length);
  786. if (version) {
  787. range = normalizer ? normalizer(range) : range;
  788. return VersionRange.contains(range, version);
  789. }
  790. return false;
  791. }
  792. /**
  793. * Normalizes `version` by stripping any "NT" prefix, but only on the Windows
  794. * platform.
  795. *
  796. * Mimics the stripping performed by the `UserAgentWindowsPlatform` PHP class.
  797. *
  798. * @param {string} version
  799. * @return {string}
  800. */
  801. function normalizePlatformVersion(version) {
  802. if (UserAgentData.platformName === 'Windows') {
  803. return version.replace(/^\s*NT/, '');
  804. }
  805. return version;
  806. }
  807. /**
  808. * Provides client-side access to the authoritative PHP-generated User Agent
  809. * information supplied by the server.
  810. */
  811. var UserAgent = {
  812. /**
  813. * Check if the User Agent browser matches `query`.
  814. *
  815. * `query` should be a string like "Chrome" or "Chrome > 33".
  816. *
  817. * Valid browser names include:
  818. *
  819. * - ACCESS NetFront
  820. * - AOL
  821. * - Amazon Silk
  822. * - Android
  823. * - BlackBerry
  824. * - BlackBerry PlayBook
  825. * - Chrome
  826. * - Chrome for iOS
  827. * - Chrome frame
  828. * - Facebook PHP SDK
  829. * - Facebook for iOS
  830. * - Firefox
  831. * - IE
  832. * - IE Mobile
  833. * - Mobile Safari
  834. * - Motorola Internet Browser
  835. * - Nokia
  836. * - Openwave Mobile Browser
  837. * - Opera
  838. * - Opera Mini
  839. * - Opera Mobile
  840. * - Safari
  841. * - UIWebView
  842. * - Unknown
  843. * - webOS
  844. * - etc...
  845. *
  846. * An authoritative list can be found in the PHP `BrowserDetector` class and
  847. * related classes in the same file (see calls to `new UserAgentBrowser` here:
  848. * https://fburl.com/50728104).
  849. *
  850. * @note Function results are memoized
  851. *
  852. * @param {string} query Query of the form "Name [range expression]"
  853. * @return {boolean}
  854. */
  855. isBrowser: function isBrowser(query) {
  856. return compare(UserAgentData.browserName, UserAgentData.browserFullVersion, query);
  857. },
  858. /**
  859. * Check if the User Agent browser uses a 32 or 64 bit architecture.
  860. *
  861. * @note Function results are memoized
  862. *
  863. * @param {string} query Query of the form "32" or "64".
  864. * @return {boolean}
  865. */
  866. isBrowserArchitecture: function isBrowserArchitecture(query) {
  867. return compare(UserAgentData.browserArchitecture, null, query);
  868. },
  869. /**
  870. * Check if the User Agent device matches `query`.
  871. *
  872. * `query` should be a string like "iPhone" or "iPad".
  873. *
  874. * Valid device names include:
  875. *
  876. * - Kindle
  877. * - Kindle Fire
  878. * - Unknown
  879. * - iPad
  880. * - iPhone
  881. * - iPod
  882. * - etc...
  883. *
  884. * An authoritative list can be found in the PHP `DeviceDetector` class and
  885. * related classes in the same file (see calls to `new UserAgentDevice` here:
  886. * https://fburl.com/50728332).
  887. *
  888. * @note Function results are memoized
  889. *
  890. * @param {string} query Query of the form "Name"
  891. * @return {boolean}
  892. */
  893. isDevice: function isDevice(query) {
  894. return compare(UserAgentData.deviceName, null, query);
  895. },
  896. /**
  897. * Check if the User Agent rendering engine matches `query`.
  898. *
  899. * `query` should be a string like "WebKit" or "WebKit >= 537".
  900. *
  901. * Valid engine names include:
  902. *
  903. * - Gecko
  904. * - Presto
  905. * - Trident
  906. * - WebKit
  907. * - etc...
  908. *
  909. * An authoritative list can be found in the PHP `RenderingEngineDetector`
  910. * class related classes in the same file (see calls to `new
  911. * UserAgentRenderingEngine` here: https://fburl.com/50728617).
  912. *
  913. * @note Function results are memoized
  914. *
  915. * @param {string} query Query of the form "Name [range expression]"
  916. * @return {boolean}
  917. */
  918. isEngine: function isEngine(query) {
  919. return compare(UserAgentData.engineName, UserAgentData.engineVersion, query);
  920. },
  921. /**
  922. * Check if the User Agent platform matches `query`.
  923. *
  924. * `query` should be a string like "Windows" or "iOS 5 - 6".
  925. *
  926. * Valid platform names include:
  927. *
  928. * - Android
  929. * - BlackBerry OS
  930. * - Java ME
  931. * - Linux
  932. * - Mac OS X
  933. * - Mac OS X Calendar
  934. * - Mac OS X Internet Account
  935. * - Symbian
  936. * - SymbianOS
  937. * - Windows
  938. * - Windows Mobile
  939. * - Windows Phone
  940. * - iOS
  941. * - iOS Facebook Integration Account
  942. * - iOS Facebook Social Sharing UI
  943. * - webOS
  944. * - Chrome OS
  945. * - etc...
  946. *
  947. * An authoritative list can be found in the PHP `PlatformDetector` class and
  948. * related classes in the same file (see calls to `new UserAgentPlatform`
  949. * here: https://fburl.com/50729226).
  950. *
  951. * @note Function results are memoized
  952. *
  953. * @param {string} query Query of the form "Name [range expression]"
  954. * @return {boolean}
  955. */
  956. isPlatform: function isPlatform(query) {
  957. return compare(UserAgentData.platformName, UserAgentData.platformFullVersion, query, normalizePlatformVersion);
  958. },
  959. /**
  960. * Check if the User Agent platform is a 32 or 64 bit architecture.
  961. *
  962. * @note Function results are memoized
  963. *
  964. * @param {string} query Query of the form "32" or "64".
  965. * @return {boolean}
  966. */
  967. isPlatformArchitecture: function isPlatformArchitecture(query) {
  968. return compare(UserAgentData.platformArchitecture, null, query);
  969. }
  970. };
  971. module.exports = mapObject(UserAgent, memoizeStringOnly);
  972. /***/ }),
  973. /* 6 */
  974. /***/ (function(module, exports, __webpack_require__) {
  975. "use strict";
  976. /**
  977. * Copyright (c) Facebook, Inc. and its affiliates.
  978. *
  979. * This source code is licensed under the MIT license found in the
  980. * LICENSE file in the root directory of this source tree.
  981. *
  982. * @format
  983. *
  984. * @emails oncall+draft_js
  985. */
  986. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  987. var _require = __webpack_require__(0),
  988. Map = _require.Map,
  989. OrderedSet = _require.OrderedSet,
  990. Record = _require.Record; // Immutable.map is typed such that the value for every key in the map
  991. // must be the same type
  992. var EMPTY_SET = OrderedSet();
  993. var defaultRecord = {
  994. style: EMPTY_SET,
  995. entity: null
  996. };
  997. var CharacterMetadataRecord = Record(defaultRecord);
  998. var CharacterMetadata =
  999. /*#__PURE__*/
  1000. function (_CharacterMetadataRec) {
  1001. _inheritsLoose(CharacterMetadata, _CharacterMetadataRec);
  1002. function CharacterMetadata() {
  1003. return _CharacterMetadataRec.apply(this, arguments) || this;
  1004. }
  1005. var _proto = CharacterMetadata.prototype;
  1006. _proto.getStyle = function getStyle() {
  1007. return this.get('style');
  1008. };
  1009. _proto.getEntity = function getEntity() {
  1010. return this.get('entity');
  1011. };
  1012. _proto.hasStyle = function hasStyle(style) {
  1013. return this.getStyle().includes(style);
  1014. };
  1015. CharacterMetadata.applyStyle = function applyStyle(record, style) {
  1016. var withStyle = record.set('style', record.getStyle().add(style));
  1017. return CharacterMetadata.create(withStyle);
  1018. };
  1019. CharacterMetadata.removeStyle = function removeStyle(record, style) {
  1020. var withoutStyle = record.set('style', record.getStyle().remove(style));
  1021. return CharacterMetadata.create(withoutStyle);
  1022. };
  1023. CharacterMetadata.applyEntity = function applyEntity(record, entityKey) {
  1024. var withEntity = record.getEntity() === entityKey ? record : record.set('entity', entityKey);
  1025. return CharacterMetadata.create(withEntity);
  1026. }
  1027. /**
  1028. * Use this function instead of the `CharacterMetadata` constructor.
  1029. * Since most content generally uses only a very small number of
  1030. * style/entity permutations, we can reuse these objects as often as
  1031. * possible.
  1032. */
  1033. ;
  1034. CharacterMetadata.create = function create(config) {
  1035. if (!config) {
  1036. return EMPTY;
  1037. }
  1038. var defaultConfig = {
  1039. style: EMPTY_SET,
  1040. entity: null
  1041. }; // Fill in unspecified properties, if necessary.
  1042. var configMap = Map(defaultConfig).merge(config);
  1043. var existing = pool.get(configMap);
  1044. if (existing) {
  1045. return existing;
  1046. }
  1047. var newCharacter = new CharacterMetadata(configMap);
  1048. pool = pool.set(configMap, newCharacter);
  1049. return newCharacter;
  1050. };
  1051. return CharacterMetadata;
  1052. }(CharacterMetadataRecord);
  1053. var EMPTY = new CharacterMetadata();
  1054. var pool = Map([[Map(defaultRecord), EMPTY]]);
  1055. CharacterMetadata.EMPTY = EMPTY;
  1056. module.exports = CharacterMetadata;
  1057. /***/ }),
  1058. /* 7 */
  1059. /***/ (function(module, exports, __webpack_require__) {
  1060. "use strict";
  1061. /**
  1062. * Copyright (c) Facebook, Inc. and its affiliates.
  1063. *
  1064. * This source code is licensed under the MIT license found in the
  1065. * LICENSE file in the root directory of this source tree.
  1066. *
  1067. * @format
  1068. *
  1069. * @emails oncall+draft_js
  1070. *
  1071. * This file is a fork of ContentBlock adding support for nesting references by
  1072. * providing links to children, parent, prevSibling, and nextSibling.
  1073. *
  1074. * This is unstable and not part of the public API and should not be used by
  1075. * production systems. This file may be update/removed without notice.
  1076. */
  1077. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  1078. var CharacterMetadata = __webpack_require__(6);
  1079. var findRangesImmutable = __webpack_require__(18);
  1080. var Immutable = __webpack_require__(0);
  1081. var List = Immutable.List,
  1082. Map = Immutable.Map,
  1083. OrderedSet = Immutable.OrderedSet,
  1084. Record = Immutable.Record,
  1085. Repeat = Immutable.Repeat;
  1086. var EMPTY_SET = OrderedSet();
  1087. var defaultRecord = {
  1088. parent: null,
  1089. characterList: List(),
  1090. data: Map(),
  1091. depth: 0,
  1092. key: '',
  1093. text: '',
  1094. type: 'unstyled',
  1095. children: List(),
  1096. prevSibling: null,
  1097. nextSibling: null
  1098. };
  1099. var haveEqualStyle = function haveEqualStyle(charA, charB) {
  1100. return charA.getStyle() === charB.getStyle();
  1101. };
  1102. var haveEqualEntity = function haveEqualEntity(charA, charB) {
  1103. return charA.getEntity() === charB.getEntity();
  1104. };
  1105. var decorateCharacterList = function decorateCharacterList(config) {
  1106. if (!config) {
  1107. return config;
  1108. }
  1109. var characterList = config.characterList,
  1110. text = config.text;
  1111. if (text && !characterList) {
  1112. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  1113. }
  1114. return config;
  1115. };
  1116. var ContentBlockNode =
  1117. /*#__PURE__*/
  1118. function (_ref) {
  1119. _inheritsLoose(ContentBlockNode, _ref);
  1120. function ContentBlockNode() {
  1121. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultRecord;
  1122. /* eslint-disable-next-line constructor-super */
  1123. return _ref.call(this, decorateCharacterList(props)) || this;
  1124. }
  1125. var _proto = ContentBlockNode.prototype;
  1126. _proto.getKey = function getKey() {
  1127. return this.get('key');
  1128. };
  1129. _proto.getType = function getType() {
  1130. return this.get('type');
  1131. };
  1132. _proto.getText = function getText() {
  1133. return this.get('text');
  1134. };
  1135. _proto.getCharacterList = function getCharacterList() {
  1136. return this.get('characterList');
  1137. };
  1138. _proto.getLength = function getLength() {
  1139. return this.getText().length;
  1140. };
  1141. _proto.getDepth = function getDepth() {
  1142. return this.get('depth');
  1143. };
  1144. _proto.getData = function getData() {
  1145. return this.get('data');
  1146. };
  1147. _proto.getInlineStyleAt = function getInlineStyleAt(offset) {
  1148. var character = this.getCharacterList().get(offset);
  1149. return character ? character.getStyle() : EMPTY_SET;
  1150. };
  1151. _proto.getEntityAt = function getEntityAt(offset) {
  1152. var character = this.getCharacterList().get(offset);
  1153. return character ? character.getEntity() : null;
  1154. };
  1155. _proto.getChildKeys = function getChildKeys() {
  1156. return this.get('children');
  1157. };
  1158. _proto.getParentKey = function getParentKey() {
  1159. return this.get('parent');
  1160. };
  1161. _proto.getPrevSiblingKey = function getPrevSiblingKey() {
  1162. return this.get('prevSibling');
  1163. };
  1164. _proto.getNextSiblingKey = function getNextSiblingKey() {
  1165. return this.get('nextSibling');
  1166. };
  1167. _proto.findStyleRanges = function findStyleRanges(filterFn, callback) {
  1168. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  1169. };
  1170. _proto.findEntityRanges = function findEntityRanges(filterFn, callback) {
  1171. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  1172. };
  1173. return ContentBlockNode;
  1174. }(Record(defaultRecord));
  1175. module.exports = ContentBlockNode;
  1176. /***/ }),
  1177. /* 8 */
  1178. /***/ (function(module, exports) {
  1179. module.exports = __WEBPACK_EXTERNAL_MODULE_8__;
  1180. /***/ }),
  1181. /* 9 */
  1182. /***/ (function(module, exports, __webpack_require__) {
  1183. "use strict";
  1184. /**
  1185. * Copyright (c) Facebook, Inc. and its affiliates.
  1186. *
  1187. * This source code is licensed under the MIT license found in the
  1188. * LICENSE file in the root directory of this source tree.
  1189. *
  1190. * @format
  1191. *
  1192. * @emails oncall+draft_js
  1193. */
  1194. var seenKeys = {};
  1195. var MULTIPLIER = Math.pow(2, 24);
  1196. function generateRandomKey() {
  1197. var key;
  1198. while (key === undefined || seenKeys.hasOwnProperty(key) || !isNaN(+key)) {
  1199. key = Math.floor(Math.random() * MULTIPLIER).toString(32);
  1200. }
  1201. seenKeys[key] = true;
  1202. return key;
  1203. }
  1204. module.exports = generateRandomKey;
  1205. /***/ }),
  1206. /* 10 */
  1207. /***/ (function(module, exports, __webpack_require__) {
  1208. "use strict";
  1209. /**
  1210. * Copyright (c) Facebook, Inc. and its affiliates.
  1211. *
  1212. * This source code is licensed under the MIT license found in the
  1213. * LICENSE file in the root directory of this source tree.
  1214. *
  1215. * @format
  1216. *
  1217. * @emails oncall+draft_js
  1218. */
  1219. var KEY_DELIMITER = '-';
  1220. var DraftOffsetKey = {
  1221. encode: function encode(blockKey, decoratorKey, leafKey) {
  1222. return blockKey + KEY_DELIMITER + decoratorKey + KEY_DELIMITER + leafKey;
  1223. },
  1224. decode: function decode(offsetKey) {
  1225. // Extracts the last two parts of offsetKey and captures the rest in blockKeyParts
  1226. var _offsetKey$split$reve = offsetKey.split(KEY_DELIMITER).reverse(),
  1227. leafKey = _offsetKey$split$reve[0],
  1228. decoratorKey = _offsetKey$split$reve[1],
  1229. blockKeyParts = _offsetKey$split$reve.slice(2);
  1230. return {
  1231. // Recomposes the parts of blockKey after reversing them
  1232. blockKey: blockKeyParts.reverse().join(KEY_DELIMITER),
  1233. decoratorKey: parseInt(decoratorKey, 10),
  1234. leafKey: parseInt(leafKey, 10)
  1235. };
  1236. }
  1237. };
  1238. module.exports = DraftOffsetKey;
  1239. /***/ }),
  1240. /* 11 */
  1241. /***/ (function(module, exports, __webpack_require__) {
  1242. "use strict";
  1243. /**
  1244. * Copyright (c) Facebook, Inc. and its affiliates.
  1245. *
  1246. * This source code is licensed under the MIT license found in the
  1247. * LICENSE file in the root directory of this source tree.
  1248. *
  1249. * @format
  1250. *
  1251. */
  1252. module.exports = function (name) {
  1253. if (typeof window !== 'undefined' && window.__DRAFT_GKX) {
  1254. return !!window.__DRAFT_GKX[name];
  1255. }
  1256. return false;
  1257. };
  1258. /***/ }),
  1259. /* 12 */
  1260. /***/ (function(module, exports, __webpack_require__) {
  1261. "use strict";
  1262. /**
  1263. * Copyright (c) Facebook, Inc. and its affiliates.
  1264. *
  1265. * This source code is licensed under the MIT license found in the
  1266. * LICENSE file in the root directory of this source tree.
  1267. *
  1268. * @format
  1269. *
  1270. * @emails oncall+draft_js
  1271. */
  1272. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  1273. var CharacterMetadata = __webpack_require__(6);
  1274. var findRangesImmutable = __webpack_require__(18);
  1275. var Immutable = __webpack_require__(0);
  1276. var List = Immutable.List,
  1277. Map = Immutable.Map,
  1278. OrderedSet = Immutable.OrderedSet,
  1279. Record = Immutable.Record,
  1280. Repeat = Immutable.Repeat;
  1281. var EMPTY_SET = OrderedSet();
  1282. var defaultRecord = {
  1283. key: '',
  1284. type: 'unstyled',
  1285. text: '',
  1286. characterList: List(),
  1287. depth: 0,
  1288. data: Map()
  1289. };
  1290. var ContentBlockRecord = Record(defaultRecord);
  1291. var decorateCharacterList = function decorateCharacterList(config) {
  1292. if (!config) {
  1293. return config;
  1294. }
  1295. var characterList = config.characterList,
  1296. text = config.text;
  1297. if (text && !characterList) {
  1298. config.characterList = List(Repeat(CharacterMetadata.EMPTY, text.length));
  1299. }
  1300. return config;
  1301. };
  1302. var ContentBlock =
  1303. /*#__PURE__*/
  1304. function (_ContentBlockRecord) {
  1305. _inheritsLoose(ContentBlock, _ContentBlockRecord);
  1306. function ContentBlock(config) {
  1307. return _ContentBlockRecord.call(this, decorateCharacterList(config)) || this;
  1308. }
  1309. var _proto = ContentBlock.prototype;
  1310. _proto.getKey = function getKey() {
  1311. return this.get('key');
  1312. };
  1313. _proto.getType = function getType() {
  1314. return this.get('type');
  1315. };
  1316. _proto.getText = function getText() {
  1317. return this.get('text');
  1318. };
  1319. _proto.getCharacterList = function getCharacterList() {
  1320. return this.get('characterList');
  1321. };
  1322. _proto.getLength = function getLength() {
  1323. return this.getText().length;
  1324. };
  1325. _proto.getDepth = function getDepth() {
  1326. return this.get('depth');
  1327. };
  1328. _proto.getData = function getData() {
  1329. return this.get('data');
  1330. };
  1331. _proto.getInlineStyleAt = function getInlineStyleAt(offset) {
  1332. var character = this.getCharacterList().get(offset);
  1333. return character ? character.getStyle() : EMPTY_SET;
  1334. };
  1335. _proto.getEntityAt = function getEntityAt(offset) {
  1336. var character = this.getCharacterList().get(offset);
  1337. return character ? character.getEntity() : null;
  1338. }
  1339. /**
  1340. * Execute a callback for every contiguous range of styles within the block.
  1341. */
  1342. ;
  1343. _proto.findStyleRanges = function findStyleRanges(filterFn, callback) {
  1344. findRangesImmutable(this.getCharacterList(), haveEqualStyle, filterFn, callback);
  1345. }
  1346. /**
  1347. * Execute a callback for every contiguous range of entities within the block.
  1348. */
  1349. ;
  1350. _proto.findEntityRanges = function findEntityRanges(filterFn, callback) {
  1351. findRangesImmutable(this.getCharacterList(), haveEqualEntity, filterFn, callback);
  1352. };
  1353. return ContentBlock;
  1354. }(ContentBlockRecord);
  1355. function haveEqualStyle(charA, charB) {
  1356. return charA.getStyle() === charB.getStyle();
  1357. }
  1358. function haveEqualEntity(charA, charB) {
  1359. return charA.getEntity() === charB.getEntity();
  1360. }
  1361. module.exports = ContentBlock;
  1362. /***/ }),
  1363. /* 13 */
  1364. /***/ (function(module, exports, __webpack_require__) {
  1365. "use strict";
  1366. /**
  1367. * Copyright (c) 2013-present, Facebook, Inc.
  1368. *
  1369. * This source code is licensed under the MIT license found in the
  1370. * LICENSE file in the root directory of this source tree.
  1371. *
  1372. */
  1373. /**
  1374. * This function is used to mark string literals representing CSS class names
  1375. * so that they can be transformed statically. This allows for modularization
  1376. * and minification of CSS class names.
  1377. *
  1378. * In static_upstream, this function is actually implemented, but it should
  1379. * eventually be replaced with something more descriptive, and the transform
  1380. * that is used in the main stack should be ported for use elsewhere.
  1381. *
  1382. * @param string|object className to modularize, or an object of key/values.
  1383. * In the object case, the values are conditions that
  1384. * determine if the className keys should be included.
  1385. * @param [string ...] Variable list of classNames in the string case.
  1386. * @return string Renderable space-separated CSS className.
  1387. */
  1388. function cx(classNames) {
  1389. if (typeof classNames == 'object') {
  1390. return Object.keys(classNames).filter(function (className) {
  1391. return classNames[className];
  1392. }).map(replace).join(' ');
  1393. }
  1394. return Array.prototype.map.call(arguments, replace).join(' ');
  1395. }
  1396. function replace(str) {
  1397. return str.replace(/\//g, '-');
  1398. }
  1399. module.exports = cx;
  1400. /***/ }),
  1401. /* 14 */
  1402. /***/ (function(module, exports, __webpack_require__) {
  1403. "use strict";
  1404. /*
  1405. object-assign
  1406. (c) Sindre Sorhus
  1407. @license MIT
  1408. */
  1409. /* eslint-disable no-unused-vars */
  1410. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  1411. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1412. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  1413. function toObject(val) {
  1414. if (val === null || val === undefined) {
  1415. throw new TypeError('Object.assign cannot be called with null or undefined');
  1416. }
  1417. return Object(val);
  1418. }
  1419. function shouldUseNative() {
  1420. try {
  1421. if (!Object.assign) {
  1422. return false;
  1423. }
  1424. // Detect buggy property enumeration order in older V8 versions.
  1425. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  1426. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  1427. test1[5] = 'de';
  1428. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  1429. return false;
  1430. }
  1431. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1432. var test2 = {};
  1433. for (var i = 0; i < 10; i++) {
  1434. test2['_' + String.fromCharCode(i)] = i;
  1435. }
  1436. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  1437. return test2[n];
  1438. });
  1439. if (order2.join('') !== '0123456789') {
  1440. return false;
  1441. }
  1442. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  1443. var test3 = {};
  1444. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  1445. test3[letter] = letter;
  1446. });
  1447. if (Object.keys(Object.assign({}, test3)).join('') !==
  1448. 'abcdefghijklmnopqrst') {
  1449. return false;
  1450. }
  1451. return true;
  1452. } catch (err) {
  1453. // We don't expect any of the above to throw, but better to be safe.
  1454. return false;
  1455. }
  1456. }
  1457. module.exports = shouldUseNative() ? Object.assign : function (target, source) {
  1458. var from;
  1459. var to = toObject(target);
  1460. var symbols;
  1461. for (var s = 1; s < arguments.length; s++) {
  1462. from = Object(arguments[s]);
  1463. for (var key in from) {
  1464. if (hasOwnProperty.call(from, key)) {
  1465. to[key] = from[key];
  1466. }
  1467. }
  1468. if (getOwnPropertySymbols) {
  1469. symbols = getOwnPropertySymbols(from);
  1470. for (var i = 0; i < symbols.length; i++) {
  1471. if (propIsEnumerable.call(from, symbols[i])) {
  1472. to[symbols[i]] = from[symbols[i]];
  1473. }
  1474. }
  1475. }
  1476. }
  1477. return to;
  1478. };
  1479. /***/ }),
  1480. /* 15 */
  1481. /***/ (function(module, exports, __webpack_require__) {
  1482. "use strict";
  1483. /**
  1484. * Copyright (c) Facebook, Inc. and its affiliates.
  1485. *
  1486. * This source code is licensed under the MIT license found in the
  1487. * LICENSE file in the root directory of this source tree.
  1488. *
  1489. * @format
  1490. *
  1491. * @emails oncall+draft_js
  1492. */
  1493. function isElement(node) {
  1494. if (!node || !node.ownerDocument) {
  1495. return false;
  1496. }
  1497. return node.nodeType === Node.ELEMENT_NODE;
  1498. }
  1499. module.exports = isElement;
  1500. /***/ }),
  1501. /* 16 */
  1502. /***/ (function(module, exports, __webpack_require__) {
  1503. "use strict";
  1504. /**
  1505. * Copyright (c) 2013-present, Facebook, Inc.
  1506. *
  1507. * This source code is licensed under the MIT license found in the
  1508. * LICENSE file in the root directory of this source tree.
  1509. *
  1510. * @typechecks
  1511. */
  1512. /**
  1513. * Unicode-enabled replacesments for basic String functions.
  1514. *
  1515. * All the functions in this module assume that the input string is a valid
  1516. * UTF-16 encoding of a Unicode sequence. If it's not the case, the behavior
  1517. * will be undefined.
  1518. *
  1519. * WARNING: Since this module is typechecks-enforced, you may find new bugs
  1520. * when replacing normal String functions with ones provided here.
  1521. */
  1522. var invariant = __webpack_require__(1); // These two ranges are consecutive so anything in [HIGH_START, LOW_END] is a
  1523. // surrogate code unit.
  1524. var SURROGATE_HIGH_START = 0xD800;
  1525. var SURROGATE_HIGH_END = 0xDBFF;
  1526. var SURROGATE_LOW_START = 0xDC00;
  1527. var SURROGATE_LOW_END = 0xDFFF;
  1528. var SURROGATE_UNITS_REGEX = /[\uD800-\uDFFF]/;
  1529. /**
  1530. * @param {number} codeUnit A Unicode code-unit, in range [0, 0x10FFFF]
  1531. * @return {boolean} Whether code-unit is in a surrogate (hi/low) range
  1532. */
  1533. function isCodeUnitInSurrogateRange(codeUnit) {
  1534. return SURROGATE_HIGH_START <= codeUnit && codeUnit <= SURROGATE_LOW_END;
  1535. }
  1536. /**
  1537. * Returns whether the two characters starting at `index` form a surrogate pair.
  1538. * For example, given the string s = "\uD83D\uDE0A", (s, 0) returns true and
  1539. * (s, 1) returns false.
  1540. *
  1541. * @param {string} str
  1542. * @param {number} index
  1543. * @return {boolean}
  1544. */
  1545. function isSurrogatePair(str, index) {
  1546. !(0 <= index && index < str.length) ? true ? invariant(false, 'isSurrogatePair: Invalid index %s for string length %s.', index, str.length) : invariant(false) : void 0;
  1547. if (index + 1 === str.length) {
  1548. return false;
  1549. }
  1550. var first = str.charCodeAt(index);
  1551. var second = str.charCodeAt(index + 1);
  1552. return SURROGATE_HIGH_START <= first && first <= SURROGATE_HIGH_END && SURROGATE_LOW_START <= second && second <= SURROGATE_LOW_END;
  1553. }
  1554. /**
  1555. * @param {string} str Non-empty string
  1556. * @return {boolean} True if the input includes any surrogate code units
  1557. */
  1558. function hasSurrogateUnit(str) {
  1559. return SURROGATE_UNITS_REGEX.test(str);
  1560. }
  1561. /**
  1562. * Return the length of the original Unicode character at given position in the
  1563. * String by looking into the UTF-16 code unit; that is equal to 1 for any
  1564. * non-surrogate characters in BMP ([U+0000..U+D7FF] and [U+E000, U+FFFF]); and
  1565. * returns 2 for the hi/low surrogates ([U+D800..U+DFFF]), which are in fact
  1566. * representing non-BMP characters ([U+10000..U+10FFFF]).
  1567. *
  1568. * Examples:
  1569. * - '\u0020' => 1
  1570. * - '\u3020' => 1
  1571. * - '\uD835' => 2
  1572. * - '\uD835\uDDEF' => 2
  1573. * - '\uDDEF' => 2
  1574. *
  1575. * @param {string} str Non-empty string
  1576. * @param {number} pos Position in the string to look for one code unit
  1577. * @return {number} Number 1 or 2
  1578. */
  1579. function getUTF16Length(str, pos) {
  1580. return 1 + isCodeUnitInSurrogateRange(str.charCodeAt(pos));
  1581. }
  1582. /**
  1583. * Fully Unicode-enabled replacement for String#length
  1584. *
  1585. * @param {string} str Valid Unicode string
  1586. * @return {number} The number of Unicode characters in the string
  1587. */
  1588. function strlen(str) {
  1589. // Call the native functions if there's no surrogate char
  1590. if (!hasSurrogateUnit(str)) {
  1591. return str.length;
  1592. }
  1593. var len = 0;
  1594. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  1595. len++;
  1596. }
  1597. return len;
  1598. }
  1599. /**
  1600. * Fully Unicode-enabled replacement for String#substr()
  1601. *
  1602. * @param {string} str Valid Unicode string
  1603. * @param {number} start Location in Unicode sequence to begin extracting
  1604. * @param {?number} length The number of Unicode characters to extract
  1605. * (default: to the end of the string)
  1606. * @return {string} Extracted sub-string
  1607. */
  1608. function substr(str, start, length) {
  1609. start = start || 0;
  1610. length = length === undefined ? Infinity : length || 0; // Call the native functions if there's no surrogate char
  1611. if (!hasSurrogateUnit(str)) {
  1612. return str.substr(start, length);
  1613. } // Obvious cases
  1614. var size = str.length;
  1615. if (size <= 0 || start > size || length <= 0) {
  1616. return '';
  1617. } // Find the actual starting position
  1618. var posA = 0;
  1619. if (start > 0) {
  1620. for (; start > 0 && posA < size; start--) {
  1621. posA += getUTF16Length(str, posA);
  1622. }
  1623. if (posA >= size) {
  1624. return '';
  1625. }
  1626. } else if (start < 0) {
  1627. for (posA = size; start < 0 && 0 < posA; start++) {
  1628. posA -= getUTF16Length(str, posA - 1);
  1629. }
  1630. if (posA < 0) {
  1631. posA = 0;
  1632. }
  1633. } // Find the actual ending position
  1634. var posB = size;
  1635. if (length < size) {
  1636. for (posB = posA; length > 0 && posB < size; length--) {
  1637. posB += getUTF16Length(str, posB);
  1638. }
  1639. }
  1640. return str.substring(posA, posB);
  1641. }
  1642. /**
  1643. * Fully Unicode-enabled replacement for String#substring()
  1644. *
  1645. * @param {string} str Valid Unicode string
  1646. * @param {number} start Location in Unicode sequence to begin extracting
  1647. * @param {?number} end Location in Unicode sequence to end extracting
  1648. * (default: end of the string)
  1649. * @return {string} Extracted sub-string
  1650. */
  1651. function substring(str, start, end) {
  1652. start = start || 0;
  1653. end = end === undefined ? Infinity : end || 0;
  1654. if (start < 0) {
  1655. start = 0;
  1656. }
  1657. if (end < 0) {
  1658. end = 0;
  1659. }
  1660. var length = Math.abs(end - start);
  1661. start = start < end ? start : end;
  1662. return substr(str, start, length);
  1663. }
  1664. /**
  1665. * Get a list of Unicode code-points from a String
  1666. *
  1667. * @param {string} str Valid Unicode string
  1668. * @return {array<number>} A list of code-points in [0..0x10FFFF]
  1669. */
  1670. function getCodePoints(str) {
  1671. var codePoints = [];
  1672. for (var pos = 0; pos < str.length; pos += getUTF16Length(str, pos)) {
  1673. codePoints.push(str.codePointAt(pos));
  1674. }
  1675. return codePoints;
  1676. }
  1677. var UnicodeUtils = {
  1678. getCodePoints: getCodePoints,
  1679. getUTF16Length: getUTF16Length,
  1680. hasSurrogateUnit: hasSurrogateUnit,
  1681. isCodeUnitInSurrogateRange: isCodeUnitInSurrogateRange,
  1682. isSurrogatePair: isSurrogatePair,
  1683. strlen: strlen,
  1684. substring: substring,
  1685. substr: substr
  1686. };
  1687. module.exports = UnicodeUtils;
  1688. /***/ }),
  1689. /* 17 */
  1690. /***/ (function(module, exports, __webpack_require__) {
  1691. "use strict";
  1692. /**
  1693. * Copyright (c) Facebook, Inc. and its affiliates.
  1694. *
  1695. * This source code is licensed under the MIT license found in the
  1696. * LICENSE file in the root directory of this source tree.
  1697. *
  1698. * @format
  1699. *
  1700. * @emails oncall+draft_js
  1701. */
  1702. var Immutable = __webpack_require__(0);
  1703. var OrderedMap = Immutable.OrderedMap;
  1704. var BlockMapBuilder = {
  1705. createFromArray: function createFromArray(blocks) {
  1706. return OrderedMap(blocks.map(function (block) {
  1707. return [block.getKey(), block];
  1708. }));
  1709. }
  1710. };
  1711. module.exports = BlockMapBuilder;
  1712. /***/ }),
  1713. /* 18 */
  1714. /***/ (function(module, exports, __webpack_require__) {
  1715. "use strict";
  1716. /**
  1717. * Copyright (c) Facebook, Inc. and its affiliates.
  1718. *
  1719. * This source code is licensed under the MIT license found in the
  1720. * LICENSE file in the root directory of this source tree.
  1721. *
  1722. * @format
  1723. *
  1724. * @emails oncall+draft_js
  1725. */
  1726. /**
  1727. * Search through an array to find contiguous stretches of elements that
  1728. * match a specified filter function.
  1729. *
  1730. * When ranges are found, execute a specified `found` function to supply
  1731. * the values to the caller.
  1732. */
  1733. function findRangesImmutable(haystack, areEqualFn, filterFn, foundFn) {
  1734. if (!haystack.size) {
  1735. return;
  1736. }
  1737. var cursor = 0;
  1738. haystack.reduce(function (value, nextValue, nextIndex) {
  1739. if (!areEqualFn(value, nextValue)) {
  1740. if (filterFn(value)) {
  1741. foundFn(cursor, nextIndex);
  1742. }
  1743. cursor = nextIndex;
  1744. }
  1745. return nextValue;
  1746. });
  1747. filterFn(haystack.last()) && foundFn(cursor, haystack.count());
  1748. }
  1749. module.exports = findRangesImmutable;
  1750. /***/ }),
  1751. /* 19 */
  1752. /***/ (function(module, exports, __webpack_require__) {
  1753. "use strict";
  1754. /**
  1755. * Copyright (c) Facebook, Inc. and its affiliates.
  1756. *
  1757. * This source code is licensed under the MIT license found in the
  1758. * LICENSE file in the root directory of this source tree.
  1759. *
  1760. * @format
  1761. *
  1762. * @emails oncall+draft_js
  1763. */
  1764. function isHTMLElement(node) {
  1765. if (!node || !node.ownerDocument) {
  1766. return false;
  1767. }
  1768. if (!node.ownerDocument.defaultView) {
  1769. return node instanceof HTMLElement;
  1770. }
  1771. if (node instanceof node.ownerDocument.defaultView.HTMLElement) {
  1772. return true;
  1773. }
  1774. return false;
  1775. }
  1776. module.exports = isHTMLElement;
  1777. /***/ }),
  1778. /* 20 */
  1779. /***/ (function(module, exports, __webpack_require__) {
  1780. "use strict";
  1781. /**
  1782. * Copyright (c) Facebook, Inc. and its affiliates.
  1783. *
  1784. * This source code is licensed under the MIT license found in the
  1785. * LICENSE file in the root directory of this source tree.
  1786. *
  1787. * @format
  1788. *
  1789. * @emails oncall+draft_js
  1790. */
  1791. var DraftModifier = __webpack_require__(3);
  1792. var gkx = __webpack_require__(11);
  1793. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  1794. /**
  1795. * For a collapsed selection state, remove text based on the specified strategy.
  1796. * If the selection state is not collapsed, remove the entire selected range.
  1797. */
  1798. function removeTextWithStrategy(editorState, strategy, direction) {
  1799. var selection = editorState.getSelection();
  1800. var content = editorState.getCurrentContent();
  1801. var target = selection;
  1802. var anchorKey = selection.getAnchorKey();
  1803. var focusKey = selection.getFocusKey();
  1804. var anchorBlock = content.getBlockForKey(anchorKey);
  1805. if (experimentalTreeDataSupport) {
  1806. if (direction === 'forward') {
  1807. if (anchorKey !== focusKey) {
  1808. // For now we ignore forward delete across blocks,
  1809. // if there is demand for this we will implement it.
  1810. return content;
  1811. }
  1812. }
  1813. }
  1814. if (selection.isCollapsed()) {
  1815. if (direction === 'forward') {
  1816. if (editorState.isSelectionAtEndOfContent()) {
  1817. return content;
  1818. }
  1819. if (experimentalTreeDataSupport) {
  1820. var isAtEndOfBlock = selection.getAnchorOffset() === content.getBlockForKey(anchorKey).getLength();
  1821. if (isAtEndOfBlock) {
  1822. var anchorBlockSibling = content.getBlockForKey(anchorBlock.nextSibling);
  1823. if (!anchorBlockSibling || anchorBlockSibling.getLength() === 0) {
  1824. // For now we ignore forward delete at the end of a block,
  1825. // if there is demand for this we will implement it.
  1826. return content;
  1827. }
  1828. }
  1829. }
  1830. } else if (editorState.isSelectionAtStartOfContent()) {
  1831. return content;
  1832. }
  1833. target = strategy(editorState);
  1834. if (target === selection) {
  1835. return content;
  1836. }
  1837. }
  1838. return DraftModifier.removeRange(content, target, direction);
  1839. }
  1840. module.exports = removeTextWithStrategy;
  1841. /***/ }),
  1842. /* 21 */
  1843. /***/ (function(module, exports, __webpack_require__) {
  1844. "use strict";
  1845. /**
  1846. * Copyright (c) Facebook, Inc. and its affiliates.
  1847. *
  1848. * This source code is licensed under the MIT license found in the
  1849. * LICENSE file in the root directory of this source tree.
  1850. *
  1851. * @format
  1852. *
  1853. * @emails oncall+draft_js
  1854. */
  1855. var randomizeBlockMapKeys = __webpack_require__(41);
  1856. var removeEntitiesAtEdges = __webpack_require__(42);
  1857. var getContentStateFragment = function getContentStateFragment(contentState, selectionState) {
  1858. var startKey = selectionState.getStartKey();
  1859. var startOffset = selectionState.getStartOffset();
  1860. var endKey = selectionState.getEndKey();
  1861. var endOffset = selectionState.getEndOffset(); // Edge entities should be stripped to ensure that we don't preserve
  1862. // invalid partial entities when the fragment is reused. We do, however,
  1863. // preserve entities that are entirely within the selection range.
  1864. var contentWithoutEdgeEntities = removeEntitiesAtEdges(contentState, selectionState);
  1865. var blockMap = contentWithoutEdgeEntities.getBlockMap();
  1866. var blockKeys = blockMap.keySeq();
  1867. var startIndex = blockKeys.indexOf(startKey);
  1868. var endIndex = blockKeys.indexOf(endKey) + 1;
  1869. return randomizeBlockMapKeys(blockMap.slice(startIndex, endIndex).map(function (block, blockKey) {
  1870. var text = block.getText();
  1871. var chars = block.getCharacterList();
  1872. if (startKey === endKey) {
  1873. return block.merge({
  1874. text: text.slice(startOffset, endOffset),
  1875. characterList: chars.slice(startOffset, endOffset)
  1876. });
  1877. }
  1878. if (blockKey === startKey) {
  1879. return block.merge({
  1880. text: text.slice(startOffset),
  1881. characterList: chars.slice(startOffset)
  1882. });
  1883. }
  1884. if (blockKey === endKey) {
  1885. return block.merge({
  1886. text: text.slice(0, endOffset),
  1887. characterList: chars.slice(0, endOffset)
  1888. });
  1889. }
  1890. return block;
  1891. }));
  1892. };
  1893. module.exports = getContentStateFragment;
  1894. /***/ }),
  1895. /* 22 */
  1896. /***/ (function(module, exports, __webpack_require__) {
  1897. "use strict";
  1898. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  1899. 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; }
  1900. /**
  1901. * Copyright (c) Facebook, Inc. and its affiliates.
  1902. *
  1903. * This source code is licensed under the MIT license found in the
  1904. * LICENSE file in the root directory of this source tree.
  1905. *
  1906. * @format
  1907. *
  1908. * @emails oncall+draft_js
  1909. */
  1910. var DraftEntityInstance = __webpack_require__(46);
  1911. var Immutable = __webpack_require__(0);
  1912. var invariant = __webpack_require__(1);
  1913. var Map = Immutable.Map;
  1914. var instances = Map();
  1915. var instanceKey = 0;
  1916. /**
  1917. * Temporary utility for generating the warnings
  1918. */
  1919. function logWarning(oldMethodCall, newMethodCall) {
  1920. console.warn('WARNING: ' + oldMethodCall + ' will be deprecated soon!\nPlease use "' + newMethodCall + '" instead.');
  1921. }
  1922. /**
  1923. * A "document entity" is an object containing metadata associated with a
  1924. * piece of text in a ContentBlock.
  1925. *
  1926. * For example, a `link` entity might include a `uri` property. When a
  1927. * ContentBlock is rendered in the browser, text that refers to that link
  1928. * entity may be rendered as an anchor, with the `uri` as the href value.
  1929. *
  1930. * In a ContentBlock, every position in the text may correspond to zero
  1931. * or one entities. This correspondence is tracked using a key string,
  1932. * generated via DraftEntity.create() and used to obtain entity metadata
  1933. * via DraftEntity.get().
  1934. */
  1935. var DraftEntity = {
  1936. /**
  1937. * WARNING: This method will be deprecated soon!
  1938. * Please use 'contentState.getLastCreatedEntityKey' instead.
  1939. * ---
  1940. * Get the random key string from whatever entity was last created.
  1941. * We need this to support the new API, as part of transitioning to put Entity
  1942. * storage in contentState.
  1943. */
  1944. getLastCreatedEntityKey: function getLastCreatedEntityKey() {
  1945. logWarning('DraftEntity.getLastCreatedEntityKey', 'contentState.getLastCreatedEntityKey');
  1946. return DraftEntity.__getLastCreatedEntityKey();
  1947. },
  1948. /**
  1949. * WARNING: This method will be deprecated soon!
  1950. * Please use 'contentState.createEntity' instead.
  1951. * ---
  1952. * Create a DraftEntityInstance and store it for later retrieval.
  1953. *
  1954. * A random key string will be generated and returned. This key may
  1955. * be used to track the entity's usage in a ContentBlock, and for
  1956. * retrieving data about the entity at render time.
  1957. */
  1958. create: function create(type, mutability, data) {
  1959. logWarning('DraftEntity.create', 'contentState.createEntity');
  1960. return DraftEntity.__create(type, mutability, data);
  1961. },
  1962. /**
  1963. * WARNING: This method will be deprecated soon!
  1964. * Please use 'contentState.addEntity' instead.
  1965. * ---
  1966. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  1967. * useful when restoring instances from the server.
  1968. */
  1969. add: function add(instance) {
  1970. logWarning('DraftEntity.add', 'contentState.addEntity');
  1971. return DraftEntity.__add(instance);
  1972. },
  1973. /**
  1974. * WARNING: This method will be deprecated soon!
  1975. * Please use 'contentState.getEntity' instead.
  1976. * ---
  1977. * Retrieve the entity corresponding to the supplied key string.
  1978. */
  1979. get: function get(key) {
  1980. logWarning('DraftEntity.get', 'contentState.getEntity');
  1981. return DraftEntity.__get(key);
  1982. },
  1983. /**
  1984. * WARNING: This method will be deprecated soon!
  1985. * Please use 'contentState.mergeEntityData' instead.
  1986. * ---
  1987. * Entity instances are immutable. If you need to update the data for an
  1988. * instance, this method will merge your data updates and return a new
  1989. * instance.
  1990. */
  1991. mergeData: function mergeData(key, toMerge) {
  1992. logWarning('DraftEntity.mergeData', 'contentState.mergeEntityData');
  1993. return DraftEntity.__mergeData(key, toMerge);
  1994. },
  1995. /**
  1996. * WARNING: This method will be deprecated soon!
  1997. * Please use 'contentState.replaceEntityData' instead.
  1998. * ---
  1999. * Completely replace the data for a given instance.
  2000. */
  2001. replaceData: function replaceData(key, newData) {
  2002. logWarning('DraftEntity.replaceData', 'contentState.replaceEntityData');
  2003. return DraftEntity.__replaceData(key, newData);
  2004. },
  2005. // ***********************************WARNING******************************
  2006. // --- the above public API will be deprecated in the next version of Draft!
  2007. // The methods below this line are private - don't call them directly.
  2008. /**
  2009. * Get the random key string from whatever entity was last created.
  2010. * We need this to support the new API, as part of transitioning to put Entity
  2011. * storage in contentState.
  2012. */
  2013. __getLastCreatedEntityKey: function __getLastCreatedEntityKey() {
  2014. return '' + instanceKey;
  2015. },
  2016. /**
  2017. * Create a DraftEntityInstance and store it for later retrieval.
  2018. *
  2019. * A random key string will be generated and returned. This key may
  2020. * be used to track the entity's usage in a ContentBlock, and for
  2021. * retrieving data about the entity at render time.
  2022. */
  2023. __create: function __create(type, mutability, data) {
  2024. return DraftEntity.__add(new DraftEntityInstance({
  2025. type: type,
  2026. mutability: mutability,
  2027. data: data || {}
  2028. }));
  2029. },
  2030. /**
  2031. * Add an existing DraftEntityInstance to the DraftEntity map. This is
  2032. * useful when restoring instances from the server.
  2033. */
  2034. __add: function __add(instance) {
  2035. var key = '' + ++instanceKey;
  2036. instances = instances.set(key, instance);
  2037. return key;
  2038. },
  2039. /**
  2040. * Retrieve the entity corresponding to the supplied key string.
  2041. */
  2042. __get: function __get(key) {
  2043. var instance = instances.get(key);
  2044. !!!instance ? true ? invariant(false, 'Unknown DraftEntity key: %s.', key) : invariant(false) : void 0;
  2045. return instance;
  2046. },
  2047. /**
  2048. * Entity instances are immutable. If you need to update the data for an
  2049. * instance, this method will merge your data updates and return a new
  2050. * instance.
  2051. */
  2052. __mergeData: function __mergeData(key, toMerge) {
  2053. var instance = DraftEntity.__get(key);
  2054. var newData = _objectSpread({}, instance.getData(), toMerge);
  2055. var newInstance = instance.set('data', newData);
  2056. instances = instances.set(key, newInstance);
  2057. return newInstance;
  2058. },
  2059. /**
  2060. * Completely replace the data for a given instance.
  2061. */
  2062. __replaceData: function __replaceData(key, newData) {
  2063. var instance = DraftEntity.__get(key);
  2064. var newInstance = instance.set('data', newData);
  2065. instances = instances.set(key, newInstance);
  2066. return newInstance;
  2067. }
  2068. };
  2069. module.exports = DraftEntity;
  2070. /***/ }),
  2071. /* 23 */
  2072. /***/ (function(module, exports, __webpack_require__) {
  2073. "use strict";
  2074. /**
  2075. * Copyright (c) Facebook, Inc. and its affiliates.
  2076. *
  2077. * This source code is licensed under the MIT license found in the
  2078. * LICENSE file in the root directory of this source tree.
  2079. *
  2080. * @format
  2081. *
  2082. * @emails oncall+draft_js
  2083. */
  2084. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2085. var Immutable = __webpack_require__(0);
  2086. var Record = Immutable.Record;
  2087. var defaultRecord = {
  2088. anchorKey: '',
  2089. anchorOffset: 0,
  2090. focusKey: '',
  2091. focusOffset: 0,
  2092. isBackward: false,
  2093. hasFocus: false
  2094. };
  2095. /* $FlowFixMe This comment suppresses an error found when automatically adding
  2096. * a type annotation with the codemod Komodo/Annotate_exports. To see the error
  2097. * delete this comment and run Flow. */
  2098. var SelectionStateRecord = Record(defaultRecord);
  2099. var SelectionState =
  2100. /*#__PURE__*/
  2101. function (_SelectionStateRecord) {
  2102. _inheritsLoose(SelectionState, _SelectionStateRecord);
  2103. function SelectionState() {
  2104. return _SelectionStateRecord.apply(this, arguments) || this;
  2105. }
  2106. var _proto = SelectionState.prototype;
  2107. _proto.serialize = function serialize() {
  2108. return 'Anchor: ' + this.getAnchorKey() + ':' + this.getAnchorOffset() + ', ' + 'Focus: ' + this.getFocusKey() + ':' + this.getFocusOffset() + ', ' + 'Is Backward: ' + String(this.getIsBackward()) + ', ' + 'Has Focus: ' + String(this.getHasFocus());
  2109. };
  2110. _proto.getAnchorKey = function getAnchorKey() {
  2111. return this.get('anchorKey');
  2112. };
  2113. _proto.getAnchorOffset = function getAnchorOffset() {
  2114. return this.get('anchorOffset');
  2115. };
  2116. _proto.getFocusKey = function getFocusKey() {
  2117. return this.get('focusKey');
  2118. };
  2119. _proto.getFocusOffset = function getFocusOffset() {
  2120. return this.get('focusOffset');
  2121. };
  2122. _proto.getIsBackward = function getIsBackward() {
  2123. return this.get('isBackward');
  2124. };
  2125. _proto.getHasFocus = function getHasFocus() {
  2126. return this.get('hasFocus');
  2127. }
  2128. /**
  2129. * Return whether the specified range overlaps with an edge of the
  2130. * SelectionState.
  2131. */
  2132. ;
  2133. _proto.hasEdgeWithin = function hasEdgeWithin(blockKey, start, end) {
  2134. var anchorKey = this.getAnchorKey();
  2135. var focusKey = this.getFocusKey();
  2136. if (anchorKey === focusKey && anchorKey === blockKey) {
  2137. var selectionStart = this.getStartOffset();
  2138. var selectionEnd = this.getEndOffset();
  2139. return start <= selectionStart && selectionStart <= end || // selectionStart is between start and end, or
  2140. start <= selectionEnd && selectionEnd <= end // selectionEnd is between start and end
  2141. ;
  2142. }
  2143. if (blockKey !== anchorKey && blockKey !== focusKey) {
  2144. return false;
  2145. }
  2146. var offsetToCheck = blockKey === anchorKey ? this.getAnchorOffset() : this.getFocusOffset();
  2147. return start <= offsetToCheck && end >= offsetToCheck;
  2148. };
  2149. _proto.isCollapsed = function isCollapsed() {
  2150. return this.getAnchorKey() === this.getFocusKey() && this.getAnchorOffset() === this.getFocusOffset();
  2151. };
  2152. _proto.getStartKey = function getStartKey() {
  2153. return this.getIsBackward() ? this.getFocusKey() : this.getAnchorKey();
  2154. };
  2155. _proto.getStartOffset = function getStartOffset() {
  2156. return this.getIsBackward() ? this.getFocusOffset() : this.getAnchorOffset();
  2157. };
  2158. _proto.getEndKey = function getEndKey() {
  2159. return this.getIsBackward() ? this.getAnchorKey() : this.getFocusKey();
  2160. };
  2161. _proto.getEndOffset = function getEndOffset() {
  2162. return this.getIsBackward() ? this.getAnchorOffset() : this.getFocusOffset();
  2163. };
  2164. SelectionState.createEmpty = function createEmpty(key) {
  2165. return new SelectionState({
  2166. anchorKey: key,
  2167. anchorOffset: 0,
  2168. focusKey: key,
  2169. focusOffset: 0,
  2170. isBackward: false,
  2171. hasFocus: false
  2172. });
  2173. };
  2174. return SelectionState;
  2175. }(SelectionStateRecord);
  2176. module.exports = SelectionState;
  2177. /***/ }),
  2178. /* 24 */
  2179. /***/ (function(module, exports, __webpack_require__) {
  2180. "use strict";
  2181. /**
  2182. * Copyright (c) 2013-present, Facebook, Inc.
  2183. *
  2184. * This source code is licensed under the MIT license found in the
  2185. * LICENSE file in the root directory of this source tree.
  2186. *
  2187. * @typechecks
  2188. *
  2189. */
  2190. /**
  2191. * Constants to represent text directionality
  2192. *
  2193. * Also defines a *global* direciton, to be used in bidi algorithms as a
  2194. * default fallback direciton, when no better direction is found or provided.
  2195. *
  2196. * NOTE: Use `setGlobalDir()`, or update `initGlobalDir()`, to set the initial
  2197. * global direction value based on the application.
  2198. *
  2199. * Part of the implementation of Unicode Bidirectional Algorithm (UBA)
  2200. * Unicode Standard Annex #9 (UAX9)
  2201. * http://www.unicode.org/reports/tr9/
  2202. */
  2203. var invariant = __webpack_require__(1);
  2204. var NEUTRAL = 'NEUTRAL'; // No strong direction
  2205. var LTR = 'LTR'; // Left-to-Right direction
  2206. var RTL = 'RTL'; // Right-to-Left direction
  2207. var globalDir = null; // == Helpers ==
  2208. /**
  2209. * Check if a directionality value is a Strong one
  2210. */
  2211. function isStrong(dir) {
  2212. return dir === LTR || dir === RTL;
  2213. }
  2214. /**
  2215. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  2216. * property.
  2217. */
  2218. function getHTMLDir(dir) {
  2219. !isStrong(dir) ? true ? invariant(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant(false) : void 0;
  2220. return dir === LTR ? 'ltr' : 'rtl';
  2221. }
  2222. /**
  2223. * Get string value to be used for `dir` HTML attribute or `direction` CSS
  2224. * property, but returns null if `dir` has same value as `otherDir`.
  2225. * `null`.
  2226. */
  2227. function getHTMLDirIfDifferent(dir, otherDir) {
  2228. !isStrong(dir) ? true ? invariant(false, '`dir` must be a strong direction to be converted to HTML Direction') : invariant(false) : void 0;
  2229. !isStrong(otherDir) ? true ? invariant(false, '`otherDir` must be a strong direction to be converted to HTML Direction') : invariant(false) : void 0;
  2230. return dir === otherDir ? null : getHTMLDir(dir);
  2231. } // == Global Direction ==
  2232. /**
  2233. * Set the global direction.
  2234. */
  2235. function setGlobalDir(dir) {
  2236. globalDir = dir;
  2237. }
  2238. /**
  2239. * Initialize the global direction
  2240. */
  2241. function initGlobalDir() {
  2242. setGlobalDir(LTR);
  2243. }
  2244. /**
  2245. * Get the global direction
  2246. */
  2247. function getGlobalDir() {
  2248. if (!globalDir) {
  2249. this.initGlobalDir();
  2250. }
  2251. !globalDir ? true ? invariant(false, 'Global direction not set.') : invariant(false) : void 0;
  2252. return globalDir;
  2253. }
  2254. var UnicodeBidiDirection = {
  2255. // Values
  2256. NEUTRAL: NEUTRAL,
  2257. LTR: LTR,
  2258. RTL: RTL,
  2259. // Helpers
  2260. isStrong: isStrong,
  2261. getHTMLDir: getHTMLDir,
  2262. getHTMLDirIfDifferent: getHTMLDirIfDifferent,
  2263. // Global Direction
  2264. setGlobalDir: setGlobalDir,
  2265. initGlobalDir: initGlobalDir,
  2266. getGlobalDir: getGlobalDir
  2267. };
  2268. module.exports = UnicodeBidiDirection;
  2269. /***/ }),
  2270. /* 25 */
  2271. /***/ (function(module, exports) {
  2272. var g;
  2273. // This works in non-strict mode
  2274. g = (function() {
  2275. return this;
  2276. })();
  2277. try {
  2278. // This works if eval is allowed (see CSP)
  2279. g = g || Function("return this")() || (1,eval)("this");
  2280. } catch(e) {
  2281. // This works if the window reference is available
  2282. if(typeof window === "object")
  2283. g = window;
  2284. }
  2285. // g can still be undefined, but nothing to do about it...
  2286. // We return undefined, instead of nothing here, so it's
  2287. // easier to handle this case. if(!global) { ...}
  2288. module.exports = g;
  2289. /***/ }),
  2290. /* 26 */
  2291. /***/ (function(module, exports, __webpack_require__) {
  2292. "use strict";
  2293. /**
  2294. * Copyright (c) Facebook, Inc. and its affiliates.
  2295. *
  2296. * This source code is licensed under the MIT license found in the
  2297. * LICENSE file in the root directory of this source tree.
  2298. *
  2299. * @format
  2300. *
  2301. * @emails oncall+draft_js
  2302. */
  2303. var getCorrectDocumentFromNode = __webpack_require__(27);
  2304. var getSelectionOffsetKeyForNode = __webpack_require__(49);
  2305. /**
  2306. * Get the key from the node's nearest offset-aware ancestor.
  2307. */
  2308. function findAncestorOffsetKey(node) {
  2309. var searchNode = node;
  2310. while (searchNode && searchNode !== getCorrectDocumentFromNode(node).documentElement) {
  2311. var key = getSelectionOffsetKeyForNode(searchNode);
  2312. if (key != null) {
  2313. return key;
  2314. }
  2315. searchNode = searchNode.parentNode;
  2316. }
  2317. return null;
  2318. }
  2319. module.exports = findAncestorOffsetKey;
  2320. /***/ }),
  2321. /* 27 */
  2322. /***/ (function(module, exports, __webpack_require__) {
  2323. "use strict";
  2324. /**
  2325. * Copyright (c) Facebook, Inc. and its affiliates.
  2326. *
  2327. * This source code is licensed under the MIT license found in the
  2328. * LICENSE file in the root directory of this source tree.
  2329. *
  2330. * @format
  2331. *
  2332. * @emails oncall+draft_js
  2333. */
  2334. function getCorrectDocumentFromNode(node) {
  2335. if (!node || !node.ownerDocument) {
  2336. return document;
  2337. }
  2338. return node.ownerDocument;
  2339. }
  2340. module.exports = getCorrectDocumentFromNode;
  2341. /***/ }),
  2342. /* 28 */
  2343. /***/ (function(module, exports, __webpack_require__) {
  2344. "use strict";
  2345. /**
  2346. * Copyright (c) 2013-present, Facebook, Inc.
  2347. *
  2348. * This source code is licensed under the MIT license found in the
  2349. * LICENSE file in the root directory of this source tree.
  2350. *
  2351. */
  2352. module.exports = {
  2353. BACKSPACE: 8,
  2354. TAB: 9,
  2355. RETURN: 13,
  2356. ALT: 18,
  2357. ESC: 27,
  2358. SPACE: 32,
  2359. PAGE_UP: 33,
  2360. PAGE_DOWN: 34,
  2361. END: 35,
  2362. HOME: 36,
  2363. LEFT: 37,
  2364. UP: 38,
  2365. RIGHT: 39,
  2366. DOWN: 40,
  2367. DELETE: 46,
  2368. COMMA: 188,
  2369. PERIOD: 190,
  2370. A: 65,
  2371. Z: 90,
  2372. ZERO: 48,
  2373. NUMPAD_0: 96,
  2374. NUMPAD_9: 105
  2375. };
  2376. /***/ }),
  2377. /* 29 */
  2378. /***/ (function(module, exports, __webpack_require__) {
  2379. "use strict";
  2380. /**
  2381. * Copyright (c) 2013-present, Facebook, Inc.
  2382. *
  2383. * This source code is licensed under the MIT license found in the
  2384. * LICENSE file in the root directory of this source tree.
  2385. *
  2386. * @typechecks
  2387. */
  2388. var getStyleProperty = __webpack_require__(113);
  2389. /**
  2390. * @param {DOMNode} element [description]
  2391. * @param {string} name Overflow style property name.
  2392. * @return {boolean} True if the supplied ndoe is scrollable.
  2393. */
  2394. function _isNodeScrollable(element, name) {
  2395. var overflow = Style.get(element, name);
  2396. return overflow === 'auto' || overflow === 'scroll';
  2397. }
  2398. /**
  2399. * Utilities for querying and mutating style properties.
  2400. */
  2401. var Style = {
  2402. /**
  2403. * Gets the style property for the supplied node. This will return either the
  2404. * computed style, if available, or the declared style.
  2405. *
  2406. * @param {DOMNode} node
  2407. * @param {string} name Style property name.
  2408. * @return {?string} Style property value.
  2409. */
  2410. get: getStyleProperty,
  2411. /**
  2412. * Determines the nearest ancestor of a node that is scrollable.
  2413. *
  2414. * NOTE: This can be expensive if used repeatedly or on a node nested deeply.
  2415. *
  2416. * @param {?DOMNode} node Node from which to start searching.
  2417. * @return {?DOMWindow|DOMElement} Scroll parent of the supplied node.
  2418. */
  2419. getScrollParent: function getScrollParent(node) {
  2420. if (!node) {
  2421. return null;
  2422. }
  2423. var ownerDocument = node.ownerDocument;
  2424. while (node && node !== ownerDocument.body) {
  2425. if (_isNodeScrollable(node, 'overflow') || _isNodeScrollable(node, 'overflowY') || _isNodeScrollable(node, 'overflowX')) {
  2426. return node;
  2427. }
  2428. node = node.parentNode;
  2429. }
  2430. return ownerDocument.defaultView || ownerDocument.parentWindow;
  2431. }
  2432. };
  2433. module.exports = Style;
  2434. /***/ }),
  2435. /* 30 */
  2436. /***/ (function(module, exports, __webpack_require__) {
  2437. "use strict";
  2438. /**
  2439. * Copyright (c) 2013-present, Facebook, Inc.
  2440. *
  2441. * This source code is licensed under the MIT license found in the
  2442. * LICENSE file in the root directory of this source tree.
  2443. *
  2444. * @typechecks
  2445. */
  2446. var getDocumentScrollElement = __webpack_require__(117);
  2447. var getUnboundedScrollPosition = __webpack_require__(118);
  2448. /**
  2449. * Gets the scroll position of the supplied element or window.
  2450. *
  2451. * The return values are bounded. This means that if the scroll position is
  2452. * negative or exceeds the element boundaries (which is possible using inertial
  2453. * scrolling), you will get zero or the maximum scroll position, respectively.
  2454. *
  2455. * If you need the unbound scroll position, use `getUnboundedScrollPosition`.
  2456. *
  2457. * @param {DOMWindow|DOMElement} scrollable
  2458. * @return {object} Map with `x` and `y` keys.
  2459. */
  2460. function getScrollPosition(scrollable) {
  2461. var documentScrollElement = getDocumentScrollElement(scrollable.ownerDocument || scrollable.document);
  2462. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  2463. scrollable = documentScrollElement;
  2464. }
  2465. var scrollPosition = getUnboundedScrollPosition(scrollable);
  2466. var viewport = scrollable === documentScrollElement ? scrollable.ownerDocument.documentElement : scrollable;
  2467. var xMax = scrollable.scrollWidth - viewport.clientWidth;
  2468. var yMax = scrollable.scrollHeight - viewport.clientHeight;
  2469. scrollPosition.x = Math.max(0, Math.min(scrollPosition.x, xMax));
  2470. scrollPosition.y = Math.max(0, Math.min(scrollPosition.y, yMax));
  2471. return scrollPosition;
  2472. }
  2473. module.exports = getScrollPosition;
  2474. /***/ }),
  2475. /* 31 */
  2476. /***/ (function(module, exports, __webpack_require__) {
  2477. "use strict";
  2478. /**
  2479. * Copyright (c) Facebook, Inc. and its affiliates.
  2480. *
  2481. * This source code is licensed under the MIT license found in the
  2482. * LICENSE file in the root directory of this source tree.
  2483. *
  2484. * @format
  2485. *
  2486. * @emails oncall+draft_js
  2487. */
  2488. /**
  2489. * Utility method for determining whether or not the value returned
  2490. * from a handler indicates that it was handled.
  2491. */
  2492. function isEventHandled(value) {
  2493. return value === 'handled' || value === true;
  2494. }
  2495. module.exports = isEventHandled;
  2496. /***/ }),
  2497. /* 32 */
  2498. /***/ (function(module, exports, __webpack_require__) {
  2499. "use strict";
  2500. /**
  2501. * Copyright (c) Facebook, Inc. and its affiliates.
  2502. *
  2503. * This source code is licensed under the MIT license found in the
  2504. * LICENSE file in the root directory of this source tree.
  2505. *
  2506. * @format
  2507. *
  2508. * @emails oncall+draft_js
  2509. */
  2510. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2511. var BlockMapBuilder = __webpack_require__(17);
  2512. var CharacterMetadata = __webpack_require__(6);
  2513. var ContentBlock = __webpack_require__(12);
  2514. var ContentBlockNode = __webpack_require__(7);
  2515. var DraftEntity = __webpack_require__(22);
  2516. var SelectionState = __webpack_require__(23);
  2517. var generateRandomKey = __webpack_require__(9);
  2518. var gkx = __webpack_require__(11);
  2519. var Immutable = __webpack_require__(0);
  2520. var sanitizeDraftText = __webpack_require__(47);
  2521. var List = Immutable.List,
  2522. Record = Immutable.Record,
  2523. Repeat = Immutable.Repeat;
  2524. var defaultRecord = {
  2525. entityMap: null,
  2526. blockMap: null,
  2527. selectionBefore: null,
  2528. selectionAfter: null
  2529. };
  2530. var ContentStateRecord = Record(defaultRecord);
  2531. var ContentState =
  2532. /*#__PURE__*/
  2533. function (_ContentStateRecord) {
  2534. _inheritsLoose(ContentState, _ContentStateRecord);
  2535. function ContentState() {
  2536. return _ContentStateRecord.apply(this, arguments) || this;
  2537. }
  2538. var _proto = ContentState.prototype;
  2539. _proto.getEntityMap = function getEntityMap() {
  2540. // TODO: update this when we fully remove DraftEntity
  2541. return DraftEntity;
  2542. };
  2543. _proto.getBlockMap = function getBlockMap() {
  2544. return this.get('blockMap');
  2545. };
  2546. _proto.getSelectionBefore = function getSelectionBefore() {
  2547. return this.get('selectionBefore');
  2548. };
  2549. _proto.getSelectionAfter = function getSelectionAfter() {
  2550. return this.get('selectionAfter');
  2551. };
  2552. _proto.getBlockForKey = function getBlockForKey(key) {
  2553. var block = this.getBlockMap().get(key);
  2554. return block;
  2555. };
  2556. _proto.getKeyBefore = function getKeyBefore(key) {
  2557. return this.getBlockMap().reverse().keySeq().skipUntil(function (v) {
  2558. return v === key;
  2559. }).skip(1).first();
  2560. };
  2561. _proto.getKeyAfter = function getKeyAfter(key) {
  2562. return this.getBlockMap().keySeq().skipUntil(function (v) {
  2563. return v === key;
  2564. }).skip(1).first();
  2565. };
  2566. _proto.getBlockAfter = function getBlockAfter(key) {
  2567. return this.getBlockMap().skipUntil(function (_, k) {
  2568. return k === key;
  2569. }).skip(1).first();
  2570. };
  2571. _proto.getBlockBefore = function getBlockBefore(key) {
  2572. return this.getBlockMap().reverse().skipUntil(function (_, k) {
  2573. return k === key;
  2574. }).skip(1).first();
  2575. };
  2576. _proto.getBlocksAsArray = function getBlocksAsArray() {
  2577. return this.getBlockMap().toArray();
  2578. };
  2579. _proto.getFirstBlock = function getFirstBlock() {
  2580. return this.getBlockMap().first();
  2581. };
  2582. _proto.getLastBlock = function getLastBlock() {
  2583. return this.getBlockMap().last();
  2584. };
  2585. _proto.getPlainText = function getPlainText(delimiter) {
  2586. return this.getBlockMap().map(function (block) {
  2587. return block ? block.getText() : '';
  2588. }).join(delimiter || '\n');
  2589. };
  2590. _proto.getLastCreatedEntityKey = function getLastCreatedEntityKey() {
  2591. // TODO: update this when we fully remove DraftEntity
  2592. return DraftEntity.__getLastCreatedEntityKey();
  2593. };
  2594. _proto.hasText = function hasText() {
  2595. var blockMap = this.getBlockMap();
  2596. return blockMap.size > 1 || // make sure that there are no zero width space chars
  2597. escape(blockMap.first().getText()).replace(/%u200B/g, '').length > 0;
  2598. };
  2599. _proto.createEntity = function createEntity(type, mutability, data) {
  2600. // TODO: update this when we fully remove DraftEntity
  2601. DraftEntity.__create(type, mutability, data);
  2602. return this;
  2603. };
  2604. _proto.mergeEntityData = function mergeEntityData(key, toMerge) {
  2605. // TODO: update this when we fully remove DraftEntity
  2606. DraftEntity.__mergeData(key, toMerge);
  2607. return this;
  2608. };
  2609. _proto.replaceEntityData = function replaceEntityData(key, newData) {
  2610. // TODO: update this when we fully remove DraftEntity
  2611. DraftEntity.__replaceData(key, newData);
  2612. return this;
  2613. };
  2614. _proto.addEntity = function addEntity(instance) {
  2615. // TODO: update this when we fully remove DraftEntity
  2616. DraftEntity.__add(instance);
  2617. return this;
  2618. };
  2619. _proto.getEntity = function getEntity(key) {
  2620. // TODO: update this when we fully remove DraftEntity
  2621. return DraftEntity.__get(key);
  2622. };
  2623. ContentState.createFromBlockArray = function createFromBlockArray( // TODO: update flow type when we completely deprecate the old entity API
  2624. blocks, entityMap) {
  2625. // TODO: remove this when we completely deprecate the old entity API
  2626. var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
  2627. var blockMap = BlockMapBuilder.createFromArray(theBlocks);
  2628. var selectionState = blockMap.isEmpty() ? new SelectionState() : SelectionState.createEmpty(blockMap.first().getKey());
  2629. return new ContentState({
  2630. blockMap: blockMap,
  2631. entityMap: entityMap || DraftEntity,
  2632. selectionBefore: selectionState,
  2633. selectionAfter: selectionState
  2634. });
  2635. };
  2636. ContentState.createFromText = function createFromText(text) {
  2637. var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g;
  2638. var strings = text.split(delimiter);
  2639. var blocks = strings.map(function (block) {
  2640. block = sanitizeDraftText(block);
  2641. var ContentBlockNodeRecord = gkx('draft_tree_data_support') ? ContentBlockNode : ContentBlock;
  2642. return new ContentBlockNodeRecord({
  2643. key: generateRandomKey(),
  2644. text: block,
  2645. type: 'unstyled',
  2646. characterList: List(Repeat(CharacterMetadata.EMPTY, block.length))
  2647. });
  2648. });
  2649. return ContentState.createFromBlockArray(blocks);
  2650. };
  2651. return ContentState;
  2652. }(ContentStateRecord);
  2653. module.exports = ContentState;
  2654. /***/ }),
  2655. /* 33 */
  2656. /***/ (function(module, exports, __webpack_require__) {
  2657. "use strict";
  2658. /**
  2659. * Copyright (c) 2013-present, Facebook, Inc.
  2660. *
  2661. * This source code is licensed under the MIT license found in the
  2662. * LICENSE file in the root directory of this source tree.
  2663. *
  2664. * @typechecks
  2665. *
  2666. */
  2667. /**
  2668. * Basic (stateless) API for text direction detection
  2669. *
  2670. * Part of our implementation of Unicode Bidirectional Algorithm (UBA)
  2671. * Unicode Standard Annex #9 (UAX9)
  2672. * http://www.unicode.org/reports/tr9/
  2673. */
  2674. var UnicodeBidiDirection = __webpack_require__(24);
  2675. var invariant = __webpack_require__(1);
  2676. /**
  2677. * RegExp ranges of characters with a *Strong* Bidi_Class value.
  2678. *
  2679. * Data is based on DerivedBidiClass.txt in UCD version 7.0.0.
  2680. *
  2681. * NOTE: For performance reasons, we only support Unicode's
  2682. * Basic Multilingual Plane (BMP) for now.
  2683. */
  2684. var RANGE_BY_BIDI_TYPE = {
  2685. 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",
  2686. 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",
  2687. 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"
  2688. };
  2689. var REGEX_STRONG = new RegExp('[' + RANGE_BY_BIDI_TYPE.L + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  2690. var REGEX_RTL = new RegExp('[' + RANGE_BY_BIDI_TYPE.R + RANGE_BY_BIDI_TYPE.AL + ']');
  2691. /**
  2692. * Returns the first strong character (has Bidi_Class value of L, R, or AL).
  2693. *
  2694. * @param str A text block; e.g. paragraph, table cell, tag
  2695. * @return A character with strong bidi direction, or null if not found
  2696. */
  2697. function firstStrongChar(str) {
  2698. var match = REGEX_STRONG.exec(str);
  2699. return match == null ? null : match[0];
  2700. }
  2701. /**
  2702. * Returns the direction of a block of text, based on the direction of its
  2703. * first strong character (has Bidi_Class value of L, R, or AL).
  2704. *
  2705. * @param str A text block; e.g. paragraph, table cell, tag
  2706. * @return The resolved direction
  2707. */
  2708. function firstStrongCharDir(str) {
  2709. var strongChar = firstStrongChar(str);
  2710. if (strongChar == null) {
  2711. return UnicodeBidiDirection.NEUTRAL;
  2712. }
  2713. return REGEX_RTL.exec(strongChar) ? UnicodeBidiDirection.RTL : UnicodeBidiDirection.LTR;
  2714. }
  2715. /**
  2716. * Returns the direction of a block of text, based on the direction of its
  2717. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  2718. * direction, if no strong character is found.
  2719. *
  2720. * This function is supposed to be used in respect to Higher-Level Protocol
  2721. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  2722. *
  2723. * @param str A text block; e.g. paragraph, table cell, tag
  2724. * @param fallback Fallback direction, used if no strong direction detected
  2725. * for the block (default = NEUTRAL)
  2726. * @return The resolved direction
  2727. */
  2728. function resolveBlockDir(str, fallback) {
  2729. fallback = fallback || UnicodeBidiDirection.NEUTRAL;
  2730. if (!str.length) {
  2731. return fallback;
  2732. }
  2733. var blockDir = firstStrongCharDir(str);
  2734. return blockDir === UnicodeBidiDirection.NEUTRAL ? fallback : blockDir;
  2735. }
  2736. /**
  2737. * Returns the direction of a block of text, based on the direction of its
  2738. * first strong character (has Bidi_Class value of L, R, or AL), or a fallback
  2739. * direction, if no strong character is found.
  2740. *
  2741. * NOTE: This function is similar to resolveBlockDir(), but uses the global
  2742. * direction as the fallback, so it *always* returns a Strong direction,
  2743. * making it useful for integration in places that you need to make the final
  2744. * decision, like setting some CSS class.
  2745. *
  2746. * This function is supposed to be used in respect to Higher-Level Protocol
  2747. * rule HL1. (http://www.unicode.org/reports/tr9/#HL1)
  2748. *
  2749. * @param str A text block; e.g. paragraph, table cell
  2750. * @param strongFallback Fallback direction, used if no strong direction
  2751. * detected for the block (default = global direction)
  2752. * @return The resolved Strong direction
  2753. */
  2754. function getDirection(str, strongFallback) {
  2755. if (!strongFallback) {
  2756. strongFallback = UnicodeBidiDirection.getGlobalDir();
  2757. }
  2758. !UnicodeBidiDirection.isStrong(strongFallback) ? true ? invariant(false, 'Fallback direction must be a strong direction') : invariant(false) : void 0;
  2759. return resolveBlockDir(str, strongFallback);
  2760. }
  2761. /**
  2762. * Returns true if getDirection(arguments...) returns LTR.
  2763. *
  2764. * @param str A text block; e.g. paragraph, table cell
  2765. * @param strongFallback Fallback direction, used if no strong direction
  2766. * detected for the block (default = global direction)
  2767. * @return True if the resolved direction is LTR
  2768. */
  2769. function isDirectionLTR(str, strongFallback) {
  2770. return getDirection(str, strongFallback) === UnicodeBidiDirection.LTR;
  2771. }
  2772. /**
  2773. * Returns true if getDirection(arguments...) returns RTL.
  2774. *
  2775. * @param str A text block; e.g. paragraph, table cell
  2776. * @param strongFallback Fallback direction, used if no strong direction
  2777. * detected for the block (default = global direction)
  2778. * @return True if the resolved direction is RTL
  2779. */
  2780. function isDirectionRTL(str, strongFallback) {
  2781. return getDirection(str, strongFallback) === UnicodeBidiDirection.RTL;
  2782. }
  2783. var UnicodeBidi = {
  2784. firstStrongChar: firstStrongChar,
  2785. firstStrongCharDir: firstStrongCharDir,
  2786. resolveBlockDir: resolveBlockDir,
  2787. getDirection: getDirection,
  2788. isDirectionLTR: isDirectionLTR,
  2789. isDirectionRTL: isDirectionRTL
  2790. };
  2791. module.exports = UnicodeBidi;
  2792. /***/ }),
  2793. /* 34 */
  2794. /***/ (function(module, exports, __webpack_require__) {
  2795. "use strict";
  2796. /**
  2797. * Copyright (c) Facebook, Inc. and its affiliates.
  2798. *
  2799. * This source code is licensed under the MIT license found in the
  2800. * LICENSE file in the root directory of this source tree.
  2801. *
  2802. * @format
  2803. *
  2804. * @emails oncall+draft_js
  2805. */
  2806. var React = __webpack_require__(8);
  2807. var cx = __webpack_require__(13);
  2808. var _require = __webpack_require__(0),
  2809. Map = _require.Map;
  2810. var UL_WRAP = React.createElement("ul", {
  2811. className: cx('public/DraftStyleDefault/ul')
  2812. });
  2813. var OL_WRAP = React.createElement("ol", {
  2814. className: cx('public/DraftStyleDefault/ol')
  2815. });
  2816. var PRE_WRAP = React.createElement("pre", {
  2817. className: cx('public/DraftStyleDefault/pre')
  2818. });
  2819. var DefaultDraftBlockRenderMap = Map({
  2820. 'header-one': {
  2821. element: 'h1'
  2822. },
  2823. 'header-two': {
  2824. element: 'h2'
  2825. },
  2826. 'header-three': {
  2827. element: 'h3'
  2828. },
  2829. 'header-four': {
  2830. element: 'h4'
  2831. },
  2832. 'header-five': {
  2833. element: 'h5'
  2834. },
  2835. 'header-six': {
  2836. element: 'h6'
  2837. },
  2838. section: {
  2839. element: 'section'
  2840. },
  2841. article: {
  2842. element: 'article'
  2843. },
  2844. 'unordered-list-item': {
  2845. element: 'li',
  2846. wrapper: UL_WRAP
  2847. },
  2848. 'ordered-list-item': {
  2849. element: 'li',
  2850. wrapper: OL_WRAP
  2851. },
  2852. blockquote: {
  2853. element: 'blockquote'
  2854. },
  2855. atomic: {
  2856. element: 'figure'
  2857. },
  2858. 'code-block': {
  2859. element: 'pre',
  2860. wrapper: PRE_WRAP
  2861. },
  2862. unstyled: {
  2863. element: 'div',
  2864. aliasedElements: ['p']
  2865. }
  2866. });
  2867. module.exports = DefaultDraftBlockRenderMap;
  2868. /***/ }),
  2869. /* 35 */
  2870. /***/ (function(module, exports, __webpack_require__) {
  2871. "use strict";
  2872. /**
  2873. * Copyright (c) Facebook, Inc. and its affiliates.
  2874. *
  2875. * This source code is licensed under the MIT license found in the
  2876. * LICENSE file in the root directory of this source tree.
  2877. *
  2878. * @format
  2879. *
  2880. * @emails oncall+draft_js
  2881. */
  2882. var _require = __webpack_require__(57),
  2883. notEmptyKey = _require.notEmptyKey;
  2884. /**
  2885. * Return the entity key that should be used when inserting text for the
  2886. * specified target selection, only if the entity is `MUTABLE`. `IMMUTABLE`
  2887. * and `SEGMENTED` entities should not be used for insertion behavior.
  2888. */
  2889. function getEntityKeyForSelection(contentState, targetSelection) {
  2890. var entityKey;
  2891. if (targetSelection.isCollapsed()) {
  2892. var key = targetSelection.getAnchorKey();
  2893. var offset = targetSelection.getAnchorOffset();
  2894. if (offset > 0) {
  2895. entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
  2896. if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
  2897. return null;
  2898. }
  2899. return filterKey(contentState.getEntityMap(), entityKey);
  2900. }
  2901. return null;
  2902. }
  2903. var startKey = targetSelection.getStartKey();
  2904. var startOffset = targetSelection.getStartOffset();
  2905. var startBlock = contentState.getBlockForKey(startKey);
  2906. entityKey = startOffset === startBlock.getLength() ? null : startBlock.getEntityAt(startOffset);
  2907. return filterKey(contentState.getEntityMap(), entityKey);
  2908. }
  2909. /**
  2910. * Determine whether an entity key corresponds to a `MUTABLE` entity. If so,
  2911. * return it. If not, return null.
  2912. */
  2913. function filterKey(entityMap, entityKey) {
  2914. if (notEmptyKey(entityKey)) {
  2915. var entity = entityMap.__get(entityKey);
  2916. return entity.getMutability() === 'MUTABLE' ? entityKey : null;
  2917. }
  2918. return null;
  2919. }
  2920. module.exports = getEntityKeyForSelection;
  2921. /***/ }),
  2922. /* 36 */
  2923. /***/ (function(module, exports, __webpack_require__) {
  2924. "use strict";
  2925. /**
  2926. * Copyright (c) 2013-present, Facebook, Inc.
  2927. *
  2928. * This source code is licensed under the MIT license found in the
  2929. * LICENSE file in the root directory of this source tree.
  2930. *
  2931. *
  2932. */
  2933. var isTextNode = __webpack_require__(111);
  2934. /*eslint-disable no-bitwise */
  2935. /**
  2936. * Checks if a given DOM node contains or is another DOM node.
  2937. */
  2938. function containsNode(outerNode, innerNode) {
  2939. if (!outerNode || !innerNode) {
  2940. return false;
  2941. } else if (outerNode === innerNode) {
  2942. return true;
  2943. } else if (isTextNode(outerNode)) {
  2944. return false;
  2945. } else if (isTextNode(innerNode)) {
  2946. return containsNode(outerNode, innerNode.parentNode);
  2947. } else if ('contains' in outerNode) {
  2948. return outerNode.contains(innerNode);
  2949. } else if (outerNode.compareDocumentPosition) {
  2950. return !!(outerNode.compareDocumentPosition(innerNode) & 16);
  2951. } else {
  2952. return false;
  2953. }
  2954. }
  2955. module.exports = containsNode;
  2956. /***/ }),
  2957. /* 37 */
  2958. /***/ (function(module, exports, __webpack_require__) {
  2959. "use strict";
  2960. /**
  2961. * Copyright (c) 2013-present, Facebook, Inc.
  2962. *
  2963. * This source code is licensed under the MIT license found in the
  2964. * LICENSE file in the root directory of this source tree.
  2965. *
  2966. */
  2967. /**
  2968. * @param {DOMElement} element
  2969. * @param {DOMDocument} doc
  2970. * @return {boolean}
  2971. */
  2972. function _isViewportScrollElement(element, doc) {
  2973. return !!doc && (element === doc.documentElement || element === doc.body);
  2974. }
  2975. /**
  2976. * Scroll Module. This class contains 4 simple static functions
  2977. * to be used to access Element.scrollTop/scrollLeft properties.
  2978. * To solve the inconsistencies between browsers when either
  2979. * document.body or document.documentElement is supplied,
  2980. * below logic will be used to alleviate the issue:
  2981. *
  2982. * 1. If 'element' is either 'document.body' or 'document.documentElement,
  2983. * get whichever element's 'scroll{Top,Left}' is larger.
  2984. * 2. If 'element' is either 'document.body' or 'document.documentElement',
  2985. * set the 'scroll{Top,Left}' on both elements.
  2986. */
  2987. var Scroll = {
  2988. /**
  2989. * @param {DOMElement} element
  2990. * @return {number}
  2991. */
  2992. getTop: function getTop(element) {
  2993. var doc = element.ownerDocument;
  2994. return _isViewportScrollElement(element, doc) ? // In practice, they will either both have the same value,
  2995. // or one will be zero and the other will be the scroll position
  2996. // of the viewport. So we can use `X || Y` instead of `Math.max(X, Y)`
  2997. doc.body.scrollTop || doc.documentElement.scrollTop : element.scrollTop;
  2998. },
  2999. /**
  3000. * @param {DOMElement} element
  3001. * @param {number} newTop
  3002. */
  3003. setTop: function setTop(element, newTop) {
  3004. var doc = element.ownerDocument;
  3005. if (_isViewportScrollElement(element, doc)) {
  3006. doc.body.scrollTop = doc.documentElement.scrollTop = newTop;
  3007. } else {
  3008. element.scrollTop = newTop;
  3009. }
  3010. },
  3011. /**
  3012. * @param {DOMElement} element
  3013. * @return {number}
  3014. */
  3015. getLeft: function getLeft(element) {
  3016. var doc = element.ownerDocument;
  3017. return _isViewportScrollElement(element, doc) ? doc.body.scrollLeft || doc.documentElement.scrollLeft : element.scrollLeft;
  3018. },
  3019. /**
  3020. * @param {DOMElement} element
  3021. * @param {number} newLeft
  3022. */
  3023. setLeft: function setLeft(element, newLeft) {
  3024. var doc = element.ownerDocument;
  3025. if (_isViewportScrollElement(element, doc)) {
  3026. doc.body.scrollLeft = doc.documentElement.scrollLeft = newLeft;
  3027. } else {
  3028. element.scrollLeft = newLeft;
  3029. }
  3030. }
  3031. };
  3032. module.exports = Scroll;
  3033. /***/ }),
  3034. /* 38 */
  3035. /***/ (function(module, exports, __webpack_require__) {
  3036. "use strict";
  3037. /**
  3038. * Copyright (c) Facebook, Inc. and its affiliates.
  3039. *
  3040. * This source code is licensed under the MIT license found in the
  3041. * LICENSE file in the root directory of this source tree.
  3042. *
  3043. * @format
  3044. *
  3045. * @emails oncall+draft_js
  3046. */
  3047. var warning = __webpack_require__(39);
  3048. /**
  3049. * Given a collapsed selection, move the focus `maxDistance` backward within
  3050. * the selected block. If the selection will go beyond the start of the block,
  3051. * move focus to the end of the previous block, but no further.
  3052. *
  3053. * This function is not Unicode-aware, so surrogate pairs will be treated
  3054. * as having length 2.
  3055. */
  3056. function moveSelectionBackward(editorState, maxDistance) {
  3057. var selection = editorState.getSelection(); // Should eventually make this an invariant
  3058. true ? warning(selection.isCollapsed(), 'moveSelectionBackward should only be called with a collapsed SelectionState') : void 0;
  3059. var content = editorState.getCurrentContent();
  3060. var key = selection.getStartKey();
  3061. var offset = selection.getStartOffset();
  3062. var focusKey = key;
  3063. var focusOffset = 0;
  3064. if (maxDistance > offset) {
  3065. var keyBefore = content.getKeyBefore(key);
  3066. if (keyBefore == null) {
  3067. focusKey = key;
  3068. } else {
  3069. focusKey = keyBefore;
  3070. var blockBefore = content.getBlockForKey(keyBefore);
  3071. focusOffset = blockBefore.getText().length;
  3072. }
  3073. } else {
  3074. focusOffset = offset - maxDistance;
  3075. }
  3076. return selection.merge({
  3077. focusKey: focusKey,
  3078. focusOffset: focusOffset,
  3079. isBackward: true
  3080. });
  3081. }
  3082. module.exports = moveSelectionBackward;
  3083. /***/ }),
  3084. /* 39 */
  3085. /***/ (function(module, exports, __webpack_require__) {
  3086. "use strict";
  3087. /**
  3088. * Copyright (c) 2014-present, Facebook, Inc.
  3089. *
  3090. * This source code is licensed under the MIT license found in the
  3091. * LICENSE file in the root directory of this source tree.
  3092. *
  3093. */
  3094. var emptyFunction = __webpack_require__(66);
  3095. /**
  3096. * Similar to invariant but only logs a warning if the condition is not met.
  3097. * This can be used to log issues in development environments in critical
  3098. * paths. Removing the logging code for production environments will keep the
  3099. * same logic and follow the same code paths.
  3100. */
  3101. function printWarning(format) {
  3102. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  3103. args[_key - 1] = arguments[_key];
  3104. }
  3105. var argIndex = 0;
  3106. var message = 'Warning: ' + format.replace(/%s/g, function () {
  3107. return args[argIndex++];
  3108. });
  3109. if (typeof console !== 'undefined') {
  3110. console.error(message);
  3111. }
  3112. try {
  3113. // --- Welcome to debugging React ---
  3114. // This error was thrown as a convenience so that you can use this stack
  3115. // to find the callsite that caused this warning to fire.
  3116. throw new Error(message);
  3117. } catch (x) {}
  3118. }
  3119. var warning = true ? function (condition, format) {
  3120. if (format === undefined) {
  3121. throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
  3122. }
  3123. if (!condition) {
  3124. for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  3125. args[_key2 - 2] = arguments[_key2];
  3126. }
  3127. printWarning.apply(void 0, [format].concat(args));
  3128. }
  3129. } : emptyFunction;
  3130. module.exports = warning;
  3131. /***/ }),
  3132. /* 40 */
  3133. /***/ (function(module, exports, __webpack_require__) {
  3134. "use strict";
  3135. /**
  3136. * Copyright (c) Facebook, Inc. and its affiliates.
  3137. *
  3138. * This source code is licensed under the MIT license found in the
  3139. * LICENSE file in the root directory of this source tree.
  3140. *
  3141. * @format
  3142. *
  3143. * @emails oncall+draft_js
  3144. */
  3145. var UserAgent = __webpack_require__(5);
  3146. var isSoftNewlineEvent = __webpack_require__(140);
  3147. var isOSX = UserAgent.isPlatform('Mac OS X');
  3148. var KeyBindingUtil = {
  3149. /**
  3150. * Check whether the ctrlKey modifier is *not* being used in conjunction with
  3151. * the altKey modifier. If they are combined, the result is an `altGraph`
  3152. * key modifier, which should not be handled by this set of key bindings.
  3153. */
  3154. isCtrlKeyCommand: function isCtrlKeyCommand(e) {
  3155. return !!e.ctrlKey && !e.altKey;
  3156. },
  3157. isOptionKeyCommand: function isOptionKeyCommand(e) {
  3158. return isOSX && e.altKey;
  3159. },
  3160. usesMacOSHeuristics: function usesMacOSHeuristics() {
  3161. return isOSX;
  3162. },
  3163. hasCommandModifier: function hasCommandModifier(e) {
  3164. return isOSX ? !!e.metaKey && !e.altKey : KeyBindingUtil.isCtrlKeyCommand(e);
  3165. },
  3166. isSoftNewlineEvent: isSoftNewlineEvent
  3167. };
  3168. module.exports = KeyBindingUtil;
  3169. /***/ }),
  3170. /* 41 */
  3171. /***/ (function(module, exports, __webpack_require__) {
  3172. "use strict";
  3173. /**
  3174. * Copyright (c) Facebook, Inc. and its affiliates.
  3175. *
  3176. * This source code is licensed under the MIT license found in the
  3177. * LICENSE file in the root directory of this source tree.
  3178. *
  3179. * @format
  3180. *
  3181. * @emails oncall+draft_js
  3182. */
  3183. var ContentBlockNode = __webpack_require__(7);
  3184. var generateRandomKey = __webpack_require__(9);
  3185. var Immutable = __webpack_require__(0);
  3186. var OrderedMap = Immutable.OrderedMap;
  3187. var randomizeContentBlockNodeKeys = function randomizeContentBlockNodeKeys(blockMap) {
  3188. var newKeysRef = {}; // we keep track of root blocks in order to update subsequent sibling links
  3189. var lastRootBlock;
  3190. return OrderedMap(blockMap.withMutations(function (blockMapState) {
  3191. blockMapState.forEach(function (block, index) {
  3192. var oldKey = block.getKey();
  3193. var nextKey = block.getNextSiblingKey();
  3194. var prevKey = block.getPrevSiblingKey();
  3195. var childrenKeys = block.getChildKeys();
  3196. var parentKey = block.getParentKey(); // new key that we will use to build linking
  3197. var key = generateRandomKey(); // we will add it here to re-use it later
  3198. newKeysRef[oldKey] = key;
  3199. if (nextKey) {
  3200. var nextBlock = blockMapState.get(nextKey);
  3201. if (nextBlock) {
  3202. blockMapState.setIn([nextKey, 'prevSibling'], key);
  3203. } else {
  3204. // this can happen when generating random keys for fragments
  3205. blockMapState.setIn([oldKey, 'nextSibling'], null);
  3206. }
  3207. }
  3208. if (prevKey) {
  3209. var prevBlock = blockMapState.get(prevKey);
  3210. if (prevBlock) {
  3211. blockMapState.setIn([prevKey, 'nextSibling'], key);
  3212. } else {
  3213. // this can happen when generating random keys for fragments
  3214. blockMapState.setIn([oldKey, 'prevSibling'], null);
  3215. }
  3216. }
  3217. if (parentKey && blockMapState.get(parentKey)) {
  3218. var parentBlock = blockMapState.get(parentKey);
  3219. var parentChildrenList = parentBlock.getChildKeys();
  3220. blockMapState.setIn([parentKey, 'children'], parentChildrenList.set(parentChildrenList.indexOf(block.getKey()), key));
  3221. } else {
  3222. // blocks will then be treated as root block nodes
  3223. blockMapState.setIn([oldKey, 'parent'], null);
  3224. if (lastRootBlock) {
  3225. blockMapState.setIn([lastRootBlock.getKey(), 'nextSibling'], key);
  3226. blockMapState.setIn([oldKey, 'prevSibling'], newKeysRef[lastRootBlock.getKey()]);
  3227. }
  3228. lastRootBlock = blockMapState.get(oldKey);
  3229. }
  3230. childrenKeys.forEach(function (childKey) {
  3231. var childBlock = blockMapState.get(childKey);
  3232. if (childBlock) {
  3233. blockMapState.setIn([childKey, 'parent'], key);
  3234. } else {
  3235. blockMapState.setIn([oldKey, 'children'], block.getChildKeys().filter(function (child) {
  3236. return child !== childKey;
  3237. }));
  3238. }
  3239. });
  3240. });
  3241. }).toArray().map(function (block) {
  3242. return [newKeysRef[block.getKey()], block.set('key', newKeysRef[block.getKey()])];
  3243. }));
  3244. };
  3245. var randomizeContentBlockKeys = function randomizeContentBlockKeys(blockMap) {
  3246. return OrderedMap(blockMap.toArray().map(function (block) {
  3247. var key = generateRandomKey();
  3248. return [key, block.set('key', key)];
  3249. }));
  3250. };
  3251. var randomizeBlockMapKeys = function randomizeBlockMapKeys(blockMap) {
  3252. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  3253. if (!isTreeBasedBlockMap) {
  3254. return randomizeContentBlockKeys(blockMap);
  3255. }
  3256. return randomizeContentBlockNodeKeys(blockMap);
  3257. };
  3258. module.exports = randomizeBlockMapKeys;
  3259. /***/ }),
  3260. /* 42 */
  3261. /***/ (function(module, exports, __webpack_require__) {
  3262. "use strict";
  3263. /**
  3264. * Copyright (c) Facebook, Inc. and its affiliates.
  3265. *
  3266. * This source code is licensed under the MIT license found in the
  3267. * LICENSE file in the root directory of this source tree.
  3268. *
  3269. * @format
  3270. *
  3271. * @emails oncall+draft_js
  3272. */
  3273. var CharacterMetadata = __webpack_require__(6);
  3274. var findRangesImmutable = __webpack_require__(18);
  3275. var invariant = __webpack_require__(1);
  3276. function removeEntitiesAtEdges(contentState, selectionState) {
  3277. var blockMap = contentState.getBlockMap();
  3278. var entityMap = contentState.getEntityMap();
  3279. var updatedBlocks = {};
  3280. var startKey = selectionState.getStartKey();
  3281. var startOffset = selectionState.getStartOffset();
  3282. var startBlock = blockMap.get(startKey);
  3283. var updatedStart = removeForBlock(entityMap, startBlock, startOffset);
  3284. if (updatedStart !== startBlock) {
  3285. updatedBlocks[startKey] = updatedStart;
  3286. }
  3287. var endKey = selectionState.getEndKey();
  3288. var endOffset = selectionState.getEndOffset();
  3289. var endBlock = blockMap.get(endKey);
  3290. if (startKey === endKey) {
  3291. endBlock = updatedStart;
  3292. }
  3293. var updatedEnd = removeForBlock(entityMap, endBlock, endOffset);
  3294. if (updatedEnd !== endBlock) {
  3295. updatedBlocks[endKey] = updatedEnd;
  3296. }
  3297. if (!Object.keys(updatedBlocks).length) {
  3298. return contentState.set('selectionAfter', selectionState);
  3299. }
  3300. return contentState.merge({
  3301. blockMap: blockMap.merge(updatedBlocks),
  3302. selectionAfter: selectionState
  3303. });
  3304. }
  3305. /**
  3306. * Given a list of characters and an offset that is in the middle of an entity,
  3307. * returns the start and end of the entity that is overlapping the offset.
  3308. * Note: This method requires that the offset be in an entity range.
  3309. */
  3310. function getRemovalRange(characters, entityKey, offset) {
  3311. var removalRange; // Iterates through a list looking for ranges of matching items
  3312. // based on the 'isEqual' callback.
  3313. // Then instead of returning the result, call the 'found' callback
  3314. // with each range.
  3315. // Then filters those ranges based on the 'filter' callback
  3316. //
  3317. // Here we use it to find ranges of characters with the same entity key.
  3318. findRangesImmutable(characters, // the list to iterate through
  3319. function (a, b) {
  3320. return a.getEntity() === b.getEntity();
  3321. }, // 'isEqual' callback
  3322. function (element) {
  3323. return element.getEntity() === entityKey;
  3324. }, // 'filter' callback
  3325. function (start, end) {
  3326. // 'found' callback
  3327. if (start <= offset && end >= offset) {
  3328. // this entity overlaps the offset index
  3329. removalRange = {
  3330. start: start,
  3331. end: end
  3332. };
  3333. }
  3334. });
  3335. !(typeof removalRange === 'object') ? true ? invariant(false, 'Removal range must exist within character list.') : invariant(false) : void 0;
  3336. return removalRange;
  3337. }
  3338. function removeForBlock(entityMap, block, offset) {
  3339. var chars = block.getCharacterList();
  3340. var charBefore = offset > 0 ? chars.get(offset - 1) : undefined;
  3341. var charAfter = offset < chars.count() ? chars.get(offset) : undefined;
  3342. var entityBeforeCursor = charBefore ? charBefore.getEntity() : undefined;
  3343. var entityAfterCursor = charAfter ? charAfter.getEntity() : undefined;
  3344. if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) {
  3345. var entity = entityMap.__get(entityAfterCursor);
  3346. if (entity.getMutability() !== 'MUTABLE') {
  3347. var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset),
  3348. start = _getRemovalRange.start,
  3349. end = _getRemovalRange.end;
  3350. var current;
  3351. while (start < end) {
  3352. current = chars.get(start);
  3353. chars = chars.set(start, CharacterMetadata.applyEntity(current, null));
  3354. start++;
  3355. }
  3356. return block.set('characterList', chars);
  3357. }
  3358. }
  3359. return block;
  3360. }
  3361. module.exports = removeEntitiesAtEdges;
  3362. /***/ }),
  3363. /* 43 */
  3364. /***/ (function(module, exports, __webpack_require__) {
  3365. "use strict";
  3366. /**
  3367. * Copyright (c) Facebook, Inc. and its affiliates.
  3368. *
  3369. * This source code is licensed under the MIT license found in the
  3370. * LICENSE file in the root directory of this source tree.
  3371. *
  3372. * @format
  3373. *
  3374. * @emails oncall+draft_js
  3375. */
  3376. /**
  3377. * Maintain persistence for target list when appending and prepending.
  3378. */
  3379. function insertIntoList(targetListArg, toInsert, offset) {
  3380. var targetList = targetListArg;
  3381. if (offset === targetList.count()) {
  3382. toInsert.forEach(function (c) {
  3383. targetList = targetList.push(c);
  3384. });
  3385. } else if (offset === 0) {
  3386. toInsert.reverse().forEach(function (c) {
  3387. targetList = targetList.unshift(c);
  3388. });
  3389. } else {
  3390. var head = targetList.slice(0, offset);
  3391. var tail = targetList.slice(offset);
  3392. targetList = head.concat(toInsert, tail).toList();
  3393. }
  3394. return targetList;
  3395. }
  3396. module.exports = insertIntoList;
  3397. /***/ }),
  3398. /* 44 */
  3399. /***/ (function(module, exports, __webpack_require__) {
  3400. "use strict";
  3401. /**
  3402. * Copyright (c) Facebook, Inc. and its affiliates.
  3403. *
  3404. * This source code is licensed under the MIT license found in the
  3405. * LICENSE file in the root directory of this source tree.
  3406. *
  3407. * @format
  3408. *
  3409. * @emails oncall+draft_js
  3410. */
  3411. var Immutable = __webpack_require__(0);
  3412. var Map = Immutable.Map;
  3413. function modifyBlockForContentState(contentState, selectionState, operation) {
  3414. var startKey = selectionState.getStartKey();
  3415. var endKey = selectionState.getEndKey();
  3416. var blockMap = contentState.getBlockMap();
  3417. var newBlocks = blockMap.toSeq().skipUntil(function (_, k) {
  3418. return k === startKey;
  3419. }).takeUntil(function (_, k) {
  3420. return k === endKey;
  3421. }).concat(Map([[endKey, blockMap.get(endKey)]])).map(operation);
  3422. return contentState.merge({
  3423. blockMap: blockMap.merge(newBlocks),
  3424. selectionBefore: selectionState,
  3425. selectionAfter: selectionState
  3426. });
  3427. }
  3428. module.exports = modifyBlockForContentState;
  3429. /***/ }),
  3430. /* 45 */
  3431. /***/ (function(module, exports, __webpack_require__) {
  3432. "use strict";
  3433. /**
  3434. * Copyright (c) Facebook, Inc. and its affiliates.
  3435. *
  3436. * This source code is licensed under the MIT license found in the
  3437. * LICENSE file in the root directory of this source tree.
  3438. *
  3439. * @format
  3440. *
  3441. * @emails oncall+draft_js
  3442. *
  3443. * This is unstable and not part of the public API and should not be used by
  3444. * production systems. This file may be update/removed without notice.
  3445. */
  3446. var ContentBlockNode = __webpack_require__(7);
  3447. var getNextDelimiterBlockKey = function getNextDelimiterBlockKey(block, blockMap) {
  3448. var isExperimentalTreeBlock = block instanceof ContentBlockNode;
  3449. if (!isExperimentalTreeBlock) {
  3450. return null;
  3451. }
  3452. var nextSiblingKey = block.getNextSiblingKey();
  3453. if (nextSiblingKey) {
  3454. return nextSiblingKey;
  3455. }
  3456. var parent = block.getParentKey();
  3457. if (!parent) {
  3458. return null;
  3459. }
  3460. var nextNonDescendantBlock = blockMap.get(parent);
  3461. while (nextNonDescendantBlock && !nextNonDescendantBlock.getNextSiblingKey()) {
  3462. var parentKey = nextNonDescendantBlock.getParentKey();
  3463. nextNonDescendantBlock = parentKey ? blockMap.get(parentKey) : null;
  3464. }
  3465. if (!nextNonDescendantBlock) {
  3466. return null;
  3467. }
  3468. return nextNonDescendantBlock.getNextSiblingKey();
  3469. };
  3470. module.exports = getNextDelimiterBlockKey;
  3471. /***/ }),
  3472. /* 46 */
  3473. /***/ (function(module, exports, __webpack_require__) {
  3474. "use strict";
  3475. /**
  3476. * Copyright (c) Facebook, Inc. and its affiliates.
  3477. *
  3478. * This source code is licensed under the MIT license found in the
  3479. * LICENSE file in the root directory of this source tree.
  3480. *
  3481. * @legacyServerCallableInstance
  3482. * @format
  3483. *
  3484. * @emails oncall+draft_js
  3485. */
  3486. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  3487. var Immutable = __webpack_require__(0);
  3488. var Record = Immutable.Record;
  3489. var DraftEntityInstanceRecord = Record({
  3490. type: 'TOKEN',
  3491. mutability: 'IMMUTABLE',
  3492. data: Object
  3493. });
  3494. /**
  3495. * An instance of a document entity, consisting of a `type` and relevant
  3496. * `data`, metadata about the entity.
  3497. *
  3498. * For instance, a "link" entity might provide a URI, and a "mention"
  3499. * entity might provide the mentioned user's ID. These pieces of data
  3500. * may be used when rendering the entity as part of a ContentBlock DOM
  3501. * representation. For a link, the data would be used as an href for
  3502. * the rendered anchor. For a mention, the ID could be used to retrieve
  3503. * a hovercard.
  3504. */
  3505. var DraftEntityInstance =
  3506. /*#__PURE__*/
  3507. function (_DraftEntityInstanceR) {
  3508. _inheritsLoose(DraftEntityInstance, _DraftEntityInstanceR);
  3509. function DraftEntityInstance() {
  3510. return _DraftEntityInstanceR.apply(this, arguments) || this;
  3511. }
  3512. var _proto = DraftEntityInstance.prototype;
  3513. _proto.getType = function getType() {
  3514. return this.get('type');
  3515. };
  3516. _proto.getMutability = function getMutability() {
  3517. return this.get('mutability');
  3518. };
  3519. _proto.getData = function getData() {
  3520. return this.get('data');
  3521. };
  3522. return DraftEntityInstance;
  3523. }(DraftEntityInstanceRecord);
  3524. module.exports = DraftEntityInstance;
  3525. /***/ }),
  3526. /* 47 */
  3527. /***/ (function(module, exports, __webpack_require__) {
  3528. "use strict";
  3529. /**
  3530. * Copyright (c) Facebook, Inc. and its affiliates.
  3531. *
  3532. * This source code is licensed under the MIT license found in the
  3533. * LICENSE file in the root directory of this source tree.
  3534. *
  3535. * @format
  3536. *
  3537. * @emails oncall+draft_js
  3538. */
  3539. var REGEX_BLOCK_DELIMITER = new RegExp('\r', 'g');
  3540. function sanitizeDraftText(input) {
  3541. return input.replace(REGEX_BLOCK_DELIMITER, '');
  3542. }
  3543. module.exports = sanitizeDraftText;
  3544. /***/ }),
  3545. /* 48 */
  3546. /***/ (function(module, exports, __webpack_require__) {
  3547. "use strict";
  3548. /**
  3549. * Copyright (c) Facebook, Inc. and its affiliates.
  3550. *
  3551. * This source code is licensed under the MIT license found in the
  3552. * LICENSE file in the root directory of this source tree.
  3553. *
  3554. * @format
  3555. *
  3556. * @emails oncall+draft_js
  3557. */
  3558. module.exports = {
  3559. BOLD: {
  3560. fontWeight: 'bold'
  3561. },
  3562. CODE: {
  3563. fontFamily: 'monospace',
  3564. wordWrap: 'break-word'
  3565. },
  3566. ITALIC: {
  3567. fontStyle: 'italic'
  3568. },
  3569. STRIKETHROUGH: {
  3570. textDecoration: 'line-through'
  3571. },
  3572. UNDERLINE: {
  3573. textDecoration: 'underline'
  3574. }
  3575. };
  3576. /***/ }),
  3577. /* 49 */
  3578. /***/ (function(module, exports, __webpack_require__) {
  3579. "use strict";
  3580. /**
  3581. * Copyright (c) Facebook, Inc. and its affiliates.
  3582. *
  3583. * This source code is licensed under the MIT license found in the
  3584. * LICENSE file in the root directory of this source tree.
  3585. *
  3586. * @format
  3587. *
  3588. * @emails oncall+draft_js
  3589. */
  3590. /**
  3591. * Get offset key from a node or it's child nodes. Return the first offset key
  3592. * found on the DOM tree of given node.
  3593. */
  3594. var isElement = __webpack_require__(15);
  3595. function getSelectionOffsetKeyForNode(node) {
  3596. if (isElement(node)) {
  3597. var castedNode = node;
  3598. var offsetKey = castedNode.getAttribute('data-offset-key');
  3599. if (offsetKey) {
  3600. return offsetKey;
  3601. }
  3602. for (var ii = 0; ii < castedNode.childNodes.length; ii++) {
  3603. var childOffsetKey = getSelectionOffsetKeyForNode(castedNode.childNodes[ii]);
  3604. if (childOffsetKey) {
  3605. return childOffsetKey;
  3606. }
  3607. }
  3608. }
  3609. return null;
  3610. }
  3611. module.exports = getSelectionOffsetKeyForNode;
  3612. /***/ }),
  3613. /* 50 */
  3614. /***/ (function(module, exports, __webpack_require__) {
  3615. "use strict";
  3616. /**
  3617. * Copyright (c) Facebook, Inc. and its affiliates.
  3618. *
  3619. * This source code is licensed under the MIT license found in the
  3620. * LICENSE file in the root directory of this source tree.
  3621. *
  3622. * @format
  3623. *
  3624. * @emails oncall+draft_js
  3625. */
  3626. function getWindowForNode(node) {
  3627. if (!node || !node.ownerDocument || !node.ownerDocument.defaultView) {
  3628. return window;
  3629. }
  3630. return node.ownerDocument.defaultView;
  3631. }
  3632. module.exports = getWindowForNode;
  3633. /***/ }),
  3634. /* 51 */
  3635. /***/ (function(module, exports, __webpack_require__) {
  3636. "use strict";
  3637. /**
  3638. * Copyright (c) Facebook, Inc. and its affiliates.
  3639. *
  3640. * This source code is licensed under the MIT license found in the
  3641. * LICENSE file in the root directory of this source tree.
  3642. *
  3643. * @format
  3644. *
  3645. * @emails oncall+draft_js
  3646. */
  3647. var DraftJsDebugLogging = __webpack_require__(52);
  3648. var EditorState = __webpack_require__(2);
  3649. var getContentEditableContainer = __webpack_require__(53);
  3650. var getDraftEditorSelection = __webpack_require__(54);
  3651. function editOnSelect(editor) {
  3652. if (editor._blockSelectEvents || editor._latestEditorState !== editor.props.editorState) {
  3653. if (editor._blockSelectEvents) {
  3654. var _editorState = editor.props.editorState;
  3655. var selectionState = _editorState.getSelection();
  3656. DraftJsDebugLogging.logBlockedSelectionEvent({
  3657. // For now I don't think we need any other info
  3658. anonymizedDom: 'N/A',
  3659. extraParams: JSON.stringify({
  3660. stacktrace: new Error().stack
  3661. }),
  3662. selectionState: JSON.stringify(selectionState.toJS())
  3663. });
  3664. }
  3665. return;
  3666. }
  3667. var editorState = editor.props.editorState;
  3668. var documentSelection = getDraftEditorSelection(editorState, getContentEditableContainer(editor));
  3669. var updatedSelectionState = documentSelection.selectionState;
  3670. if (updatedSelectionState !== editorState.getSelection()) {
  3671. if (documentSelection.needsRecovery) {
  3672. editorState = EditorState.forceSelection(editorState, updatedSelectionState);
  3673. } else {
  3674. editorState = EditorState.acceptSelection(editorState, updatedSelectionState);
  3675. }
  3676. editor.update(editorState);
  3677. }
  3678. }
  3679. module.exports = editOnSelect;
  3680. /***/ }),
  3681. /* 52 */
  3682. /***/ (function(module, exports, __webpack_require__) {
  3683. "use strict";
  3684. /**
  3685. * Copyright (c) Facebook, Inc. and its affiliates.
  3686. *
  3687. * This source code is licensed under the MIT license found in the
  3688. * LICENSE file in the root directory of this source tree.
  3689. *
  3690. */
  3691. module.exports = {
  3692. logBlockedSelectionEvent: function logBlockedSelectionEvent() {
  3693. return null;
  3694. },
  3695. logSelectionStateFailure: function logSelectionStateFailure() {
  3696. return null;
  3697. }
  3698. };
  3699. /***/ }),
  3700. /* 53 */
  3701. /***/ (function(module, exports, __webpack_require__) {
  3702. "use strict";
  3703. /**
  3704. * Copyright (c) Facebook, Inc. and its affiliates.
  3705. *
  3706. * This source code is licensed under the MIT license found in the
  3707. * LICENSE file in the root directory of this source tree.
  3708. *
  3709. * @format
  3710. *
  3711. * @emails oncall+draft_js
  3712. */
  3713. var invariant = __webpack_require__(1);
  3714. var isHTMLElement = __webpack_require__(19);
  3715. function getContentEditableContainer(editor) {
  3716. var editorNode = editor.editorContainer;
  3717. !editorNode ? true ? invariant(false, 'Missing editorNode') : invariant(false) : void 0;
  3718. !isHTMLElement(editorNode.firstChild) ? true ? invariant(false, 'editorNode.firstChild is not an HTMLElement') : invariant(false) : void 0;
  3719. var htmlElement = editorNode.firstChild;
  3720. return htmlElement;
  3721. }
  3722. module.exports = getContentEditableContainer;
  3723. /***/ }),
  3724. /* 54 */
  3725. /***/ (function(module, exports, __webpack_require__) {
  3726. "use strict";
  3727. /**
  3728. * Copyright (c) Facebook, Inc. and its affiliates.
  3729. *
  3730. * This source code is licensed under the MIT license found in the
  3731. * LICENSE file in the root directory of this source tree.
  3732. *
  3733. * @format
  3734. *
  3735. * @emails oncall+draft_js
  3736. */
  3737. var getDraftEditorSelectionWithNodes = __webpack_require__(55);
  3738. /**
  3739. * Convert the current selection range to an anchor/focus pair of offset keys
  3740. * and values that can be interpreted by components.
  3741. */
  3742. function getDraftEditorSelection(editorState, root) {
  3743. var selection = root.ownerDocument.defaultView.getSelection(); // No active selection.
  3744. if (selection.rangeCount === 0) {
  3745. return {
  3746. selectionState: editorState.getSelection().set('hasFocus', false),
  3747. needsRecovery: false
  3748. };
  3749. }
  3750. return getDraftEditorSelectionWithNodes(editorState, root, selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
  3751. }
  3752. module.exports = getDraftEditorSelection;
  3753. /***/ }),
  3754. /* 55 */
  3755. /***/ (function(module, exports, __webpack_require__) {
  3756. "use strict";
  3757. /**
  3758. * Copyright (c) Facebook, Inc. and its affiliates.
  3759. *
  3760. * This source code is licensed under the MIT license found in the
  3761. * LICENSE file in the root directory of this source tree.
  3762. *
  3763. * @format
  3764. *
  3765. * @emails oncall+draft_js
  3766. */
  3767. var findAncestorOffsetKey = __webpack_require__(26);
  3768. var getSelectionOffsetKeyForNode = __webpack_require__(49);
  3769. var getUpdatedSelectionState = __webpack_require__(56);
  3770. var invariant = __webpack_require__(1);
  3771. var isElement = __webpack_require__(15);
  3772. var nullthrows = __webpack_require__(4);
  3773. /**
  3774. * Convert the current selection range to an anchor/focus pair of offset keys
  3775. * and values that can be interpreted by components.
  3776. */
  3777. function getDraftEditorSelectionWithNodes(editorState, root, anchorNode, anchorOffset, focusNode, focusOffset) {
  3778. var anchorIsTextNode = anchorNode.nodeType === Node.TEXT_NODE;
  3779. var focusIsTextNode = focusNode.nodeType === Node.TEXT_NODE; // If the selection range lies only on text nodes, the task is simple.
  3780. // Find the nearest offset-aware elements and use the
  3781. // offset values supplied by the selection range.
  3782. if (anchorIsTextNode && focusIsTextNode) {
  3783. return {
  3784. selectionState: getUpdatedSelectionState(editorState, nullthrows(findAncestorOffsetKey(anchorNode)), anchorOffset, nullthrows(findAncestorOffsetKey(focusNode)), focusOffset),
  3785. needsRecovery: false
  3786. };
  3787. }
  3788. var anchorPoint = null;
  3789. var focusPoint = null;
  3790. var needsRecovery = true; // An element is selected. Convert this selection range into leaf offset
  3791. // keys and offset values for consumption at the component level. This
  3792. // is common in Firefox, where select-all and triple click behavior leads
  3793. // to entire elements being selected.
  3794. //
  3795. // Note that we use the `needsRecovery` parameter in the callback here. This
  3796. // is because when certain elements are selected, the behavior for subsequent
  3797. // cursor movement (e.g. via arrow keys) is uncertain and may not match
  3798. // expectations at the component level. For example, if an entire <div> is
  3799. // selected and the user presses the right arrow, Firefox keeps the selection
  3800. // on the <div>. If we allow subsequent keypresses to insert characters
  3801. // natively, they will be inserted into a browser-created text node to the
  3802. // right of that <div>. This is obviously undesirable.
  3803. //
  3804. // With the `needsRecovery` flag, we inform the caller that it is responsible
  3805. // for manually setting the selection state on the rendered document to
  3806. // ensure proper selection state maintenance.
  3807. if (anchorIsTextNode) {
  3808. anchorPoint = {
  3809. key: nullthrows(findAncestorOffsetKey(anchorNode)),
  3810. offset: anchorOffset
  3811. };
  3812. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset);
  3813. } else if (focusIsTextNode) {
  3814. focusPoint = {
  3815. key: nullthrows(findAncestorOffsetKey(focusNode)),
  3816. offset: focusOffset
  3817. };
  3818. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  3819. } else {
  3820. anchorPoint = getPointForNonTextNode(root, anchorNode, anchorOffset);
  3821. focusPoint = getPointForNonTextNode(root, focusNode, focusOffset); // If the selection is collapsed on an empty block, don't force recovery.
  3822. // This way, on arrow key selection changes, the browser can move the
  3823. // cursor from a non-zero offset on one block, through empty blocks,
  3824. // to a matching non-zero offset on other text blocks.
  3825. if (anchorNode === focusNode && anchorOffset === focusOffset) {
  3826. needsRecovery = !!anchorNode.firstChild && anchorNode.firstChild.nodeName !== 'BR';
  3827. }
  3828. }
  3829. return {
  3830. selectionState: getUpdatedSelectionState(editorState, anchorPoint.key, anchorPoint.offset, focusPoint.key, focusPoint.offset),
  3831. needsRecovery: needsRecovery
  3832. };
  3833. }
  3834. /**
  3835. * Identify the first leaf descendant for the given node.
  3836. */
  3837. function getFirstLeaf(node) {
  3838. while (node.firstChild && ( // data-blocks has no offset
  3839. isElement(node.firstChild) && node.firstChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode(node.firstChild))) {
  3840. node = node.firstChild;
  3841. }
  3842. return node;
  3843. }
  3844. /**
  3845. * Identify the last leaf descendant for the given node.
  3846. */
  3847. function getLastLeaf(node) {
  3848. while (node.lastChild && ( // data-blocks has no offset
  3849. isElement(node.lastChild) && node.lastChild.getAttribute('data-blocks') === 'true' || getSelectionOffsetKeyForNode(node.lastChild))) {
  3850. node = node.lastChild;
  3851. }
  3852. return node;
  3853. }
  3854. function getPointForNonTextNode(editorRoot, startNode, childOffset) {
  3855. var node = startNode;
  3856. var offsetKey = findAncestorOffsetKey(node);
  3857. !(offsetKey != null || editorRoot && (editorRoot === node || editorRoot.firstChild === node)) ? true ? invariant(false, 'Unknown node in selection range.') : invariant(false) : void 0; // If the editorRoot is the selection, step downward into the content
  3858. // wrapper.
  3859. if (editorRoot === node) {
  3860. node = node.firstChild;
  3861. !isElement(node) ? true ? invariant(false, 'Invalid DraftEditorContents node.') : invariant(false) : void 0;
  3862. var castedNode = node; // assignment only added for flow :/
  3863. // otherwise it throws in line 200 saying that node can be null or undefined
  3864. node = castedNode;
  3865. !(node.getAttribute('data-contents') === 'true') ? true ? invariant(false, 'Invalid DraftEditorContents structure.') : invariant(false) : void 0;
  3866. if (childOffset > 0) {
  3867. childOffset = node.childNodes.length;
  3868. }
  3869. } // If the child offset is zero and we have an offset key, we're done.
  3870. // If there's no offset key because the entire editor is selected,
  3871. // find the leftmost ("first") leaf in the tree and use that as the offset
  3872. // key.
  3873. if (childOffset === 0) {
  3874. var key = null;
  3875. if (offsetKey != null) {
  3876. key = offsetKey;
  3877. } else {
  3878. var firstLeaf = getFirstLeaf(node);
  3879. key = nullthrows(getSelectionOffsetKeyForNode(firstLeaf));
  3880. }
  3881. return {
  3882. key: key,
  3883. offset: 0
  3884. };
  3885. }
  3886. var nodeBeforeCursor = node.childNodes[childOffset - 1];
  3887. var leafKey = null;
  3888. var textLength = null;
  3889. if (!getSelectionOffsetKeyForNode(nodeBeforeCursor)) {
  3890. // Our target node may be a leaf or a text node, in which case we're
  3891. // already where we want to be and can just use the child's length as
  3892. // our offset.
  3893. leafKey = nullthrows(offsetKey);
  3894. textLength = getTextContentLength(nodeBeforeCursor);
  3895. } else {
  3896. // Otherwise, we'll look at the child to the left of the cursor and find
  3897. // the last leaf node in its subtree.
  3898. var lastLeaf = getLastLeaf(nodeBeforeCursor);
  3899. leafKey = nullthrows(getSelectionOffsetKeyForNode(lastLeaf));
  3900. textLength = getTextContentLength(lastLeaf);
  3901. }
  3902. return {
  3903. key: leafKey,
  3904. offset: textLength
  3905. };
  3906. }
  3907. /**
  3908. * Return the length of a node's textContent, regarding single newline
  3909. * characters as zero-length. This allows us to avoid problems with identifying
  3910. * the correct selection offset for empty blocks in IE, in which we
  3911. * render newlines instead of break tags.
  3912. */
  3913. function getTextContentLength(node) {
  3914. var textContent = node.textContent;
  3915. return textContent === '\n' ? 0 : textContent.length;
  3916. }
  3917. module.exports = getDraftEditorSelectionWithNodes;
  3918. /***/ }),
  3919. /* 56 */
  3920. /***/ (function(module, exports, __webpack_require__) {
  3921. "use strict";
  3922. /**
  3923. * Copyright (c) Facebook, Inc. and its affiliates.
  3924. *
  3925. * This source code is licensed under the MIT license found in the
  3926. * LICENSE file in the root directory of this source tree.
  3927. *
  3928. * @format
  3929. *
  3930. * @emails oncall+draft_js
  3931. */
  3932. var DraftOffsetKey = __webpack_require__(10);
  3933. var nullthrows = __webpack_require__(4);
  3934. function getUpdatedSelectionState(editorState, anchorKey, anchorOffset, focusKey, focusOffset) {
  3935. var selection = nullthrows(editorState.getSelection());
  3936. if (true) {
  3937. if (!anchorKey || !focusKey) {
  3938. /* eslint-disable-next-line */
  3939. console.warn('Invalid selection state.', arguments, editorState.toJS());
  3940. return selection;
  3941. }
  3942. }
  3943. var anchorPath = DraftOffsetKey.decode(anchorKey);
  3944. var anchorBlockKey = anchorPath.blockKey;
  3945. var anchorLeafBlockTree = editorState.getBlockTree(anchorBlockKey);
  3946. var anchorLeaf = anchorLeafBlockTree && anchorLeafBlockTree.getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
  3947. var focusPath = DraftOffsetKey.decode(focusKey);
  3948. var focusBlockKey = focusPath.blockKey;
  3949. var focusLeafBlockTree = editorState.getBlockTree(focusBlockKey);
  3950. var focusLeaf = focusLeafBlockTree && focusLeafBlockTree.getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
  3951. if (!anchorLeaf || !focusLeaf) {
  3952. // If we cannot make sense of the updated selection state, stick to the current one.
  3953. if (true) {
  3954. /* eslint-disable-next-line */
  3955. console.warn('Invalid selection state.', arguments, editorState.toJS());
  3956. }
  3957. return selection;
  3958. }
  3959. var anchorLeafStart = anchorLeaf.get('start');
  3960. var focusLeafStart = focusLeaf.get('start');
  3961. var anchorBlockOffset = anchorLeaf ? anchorLeafStart + anchorOffset : null;
  3962. var focusBlockOffset = focusLeaf ? focusLeafStart + focusOffset : null;
  3963. var areEqual = selection.getAnchorKey() === anchorBlockKey && selection.getAnchorOffset() === anchorBlockOffset && selection.getFocusKey() === focusBlockKey && selection.getFocusOffset() === focusBlockOffset;
  3964. if (areEqual) {
  3965. return selection;
  3966. }
  3967. var isBackward = false;
  3968. if (anchorBlockKey === focusBlockKey) {
  3969. var anchorLeafEnd = anchorLeaf.get('end');
  3970. var focusLeafEnd = focusLeaf.get('end');
  3971. if (focusLeafStart === anchorLeafStart && focusLeafEnd === anchorLeafEnd) {
  3972. isBackward = focusOffset < anchorOffset;
  3973. } else {
  3974. isBackward = focusLeafStart < anchorLeafStart;
  3975. }
  3976. } else {
  3977. var startKey = editorState.getCurrentContent().getBlockMap().keySeq().skipUntil(function (v) {
  3978. return v === anchorBlockKey || v === focusBlockKey;
  3979. }).first();
  3980. isBackward = startKey === focusBlockKey;
  3981. }
  3982. return selection.merge({
  3983. anchorKey: anchorBlockKey,
  3984. anchorOffset: anchorBlockOffset,
  3985. focusKey: focusBlockKey,
  3986. focusOffset: focusBlockOffset,
  3987. isBackward: isBackward
  3988. });
  3989. }
  3990. module.exports = getUpdatedSelectionState;
  3991. /***/ }),
  3992. /* 57 */
  3993. /***/ (function(module, exports, __webpack_require__) {
  3994. "use strict";
  3995. /**
  3996. * Copyright (c) Facebook, Inc. and its affiliates.
  3997. *
  3998. * This source code is licensed under the MIT license found in the
  3999. * LICENSE file in the root directory of this source tree.
  4000. *
  4001. * Provides utilities for handling draftjs keys.
  4002. *
  4003. * @emails oncall+draft_js
  4004. *
  4005. * @format
  4006. */
  4007. function notEmptyKey(key) {
  4008. return key != null && key != '';
  4009. }
  4010. module.exports = {
  4011. notEmptyKey: notEmptyKey
  4012. };
  4013. /***/ }),
  4014. /* 58 */
  4015. /***/ (function(module, exports, __webpack_require__) {
  4016. "use strict";
  4017. /**
  4018. * Copyright (c) Facebook, Inc. and its affiliates.
  4019. *
  4020. * This source code is licensed under the MIT license found in the
  4021. * LICENSE file in the root directory of this source tree.
  4022. *
  4023. * @format
  4024. *
  4025. * @emails oncall+draft_js
  4026. */
  4027. var _assign = __webpack_require__(14);
  4028. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  4029. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  4030. 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; }
  4031. var DraftEditorTextNode = __webpack_require__(109);
  4032. var React = __webpack_require__(8);
  4033. var invariant = __webpack_require__(1);
  4034. var isHTMLBRElement = __webpack_require__(59);
  4035. var setDraftEditorSelection = __webpack_require__(110).setDraftEditorSelection;
  4036. /**
  4037. * All leaf nodes in the editor are spans with single text nodes. Leaf
  4038. * elements are styled based on the merging of an optional custom style map
  4039. * and a default style map.
  4040. *
  4041. * `DraftEditorLeaf` also provides a wrapper for calling into the imperative
  4042. * DOM Selection API. In this way, top-level components can declaratively
  4043. * maintain the selection state.
  4044. */
  4045. var DraftEditorLeaf =
  4046. /*#__PURE__*/
  4047. function (_React$Component) {
  4048. _inheritsLoose(DraftEditorLeaf, _React$Component);
  4049. function DraftEditorLeaf() {
  4050. var _this;
  4051. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4052. args[_key] = arguments[_key];
  4053. }
  4054. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  4055. _defineProperty(_assertThisInitialized(_this), "leaf", void 0);
  4056. return _this;
  4057. }
  4058. var _proto = DraftEditorLeaf.prototype;
  4059. _proto._setSelection = function _setSelection() {
  4060. var selection = this.props.selection; // If selection state is irrelevant to the parent block, no-op.
  4061. if (selection == null || !selection.getHasFocus()) {
  4062. return;
  4063. }
  4064. var _this$props = this.props,
  4065. block = _this$props.block,
  4066. start = _this$props.start,
  4067. text = _this$props.text;
  4068. var blockKey = block.getKey();
  4069. var end = start + text.length;
  4070. if (!selection.hasEdgeWithin(blockKey, start, end)) {
  4071. return;
  4072. } // Determine the appropriate target node for selection. If the child
  4073. // is not a text node, it is a <br /> spacer. In this case, use the
  4074. // <span> itself as the selection target.
  4075. var node = this.leaf;
  4076. !node ? true ? invariant(false, 'Missing node') : invariant(false) : void 0;
  4077. var child = node.firstChild;
  4078. !child ? true ? invariant(false, 'Missing child') : invariant(false) : void 0;
  4079. var targetNode;
  4080. if (child.nodeType === Node.TEXT_NODE) {
  4081. targetNode = child;
  4082. } else if (isHTMLBRElement(child)) {
  4083. targetNode = node;
  4084. } else {
  4085. targetNode = child.firstChild;
  4086. !targetNode ? true ? invariant(false, 'Missing targetNode') : invariant(false) : void 0;
  4087. }
  4088. setDraftEditorSelection(selection, targetNode, blockKey, start, end);
  4089. };
  4090. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  4091. var leafNode = this.leaf;
  4092. !leafNode ? true ? invariant(false, 'Missing leafNode') : invariant(false) : void 0;
  4093. var shouldUpdate = leafNode.textContent !== nextProps.text || nextProps.styleSet !== this.props.styleSet || nextProps.forceSelection;
  4094. return shouldUpdate;
  4095. };
  4096. _proto.componentDidUpdate = function componentDidUpdate() {
  4097. this._setSelection();
  4098. };
  4099. _proto.componentDidMount = function componentDidMount() {
  4100. this._setSelection();
  4101. };
  4102. _proto.render = function render() {
  4103. var _this2 = this;
  4104. var block = this.props.block;
  4105. var text = this.props.text; // If the leaf is at the end of its block and ends in a soft newline, append
  4106. // an extra line feed character. Browsers collapse trailing newline
  4107. // characters, which leaves the cursor in the wrong place after a
  4108. // shift+enter. The extra character repairs this.
  4109. if (text.endsWith('\n') && this.props.isLast) {
  4110. text += '\n';
  4111. }
  4112. var _this$props2 = this.props,
  4113. customStyleMap = _this$props2.customStyleMap,
  4114. customStyleFn = _this$props2.customStyleFn,
  4115. offsetKey = _this$props2.offsetKey,
  4116. styleSet = _this$props2.styleSet;
  4117. var styleObj = styleSet.reduce(function (map, styleName) {
  4118. var mergedStyles = {};
  4119. var style = customStyleMap[styleName];
  4120. if (style !== undefined && map.textDecoration !== style.textDecoration) {
  4121. // .trim() is necessary for IE9/10/11 and Edge
  4122. mergedStyles.textDecoration = [map.textDecoration, style.textDecoration].join(' ').trim();
  4123. }
  4124. return _assign(map, style, mergedStyles);
  4125. }, {});
  4126. if (customStyleFn) {
  4127. var newStyles = customStyleFn(styleSet, block);
  4128. styleObj = _assign(styleObj, newStyles);
  4129. }
  4130. return React.createElement("span", {
  4131. "data-offset-key": offsetKey,
  4132. ref: function ref(_ref) {
  4133. return _this2.leaf = _ref;
  4134. },
  4135. style: styleObj
  4136. }, React.createElement(DraftEditorTextNode, null, text));
  4137. };
  4138. return DraftEditorLeaf;
  4139. }(React.Component);
  4140. module.exports = DraftEditorLeaf;
  4141. /***/ }),
  4142. /* 59 */
  4143. /***/ (function(module, exports, __webpack_require__) {
  4144. "use strict";
  4145. /**
  4146. * Copyright (c) Facebook, Inc. and its affiliates.
  4147. *
  4148. * This source code is licensed under the MIT license found in the
  4149. * LICENSE file in the root directory of this source tree.
  4150. *
  4151. * @format
  4152. *
  4153. * @emails oncall+draft_js
  4154. */
  4155. var isElement = __webpack_require__(15);
  4156. function isHTMLBRElement(node) {
  4157. if (!node || !node.ownerDocument) {
  4158. return false;
  4159. }
  4160. return isElement(node) && node.nodeName === 'BR';
  4161. }
  4162. module.exports = isHTMLBRElement;
  4163. /***/ }),
  4164. /* 60 */
  4165. /***/ (function(module, exports, __webpack_require__) {
  4166. "use strict";
  4167. /**
  4168. * Copyright (c) Facebook, Inc. and its affiliates.
  4169. *
  4170. * This source code is licensed under the MIT license found in the
  4171. * LICENSE file in the root directory of this source tree.
  4172. *
  4173. */
  4174. module.exports = {
  4175. initODS: function initODS() {},
  4176. handleExtensionCausedError: function handleExtensionCausedError() {}
  4177. };
  4178. /***/ }),
  4179. /* 61 */
  4180. /***/ (function(module, exports, __webpack_require__) {
  4181. "use strict";
  4182. /**
  4183. * Copyright (c) 2013-present, Facebook, Inc.
  4184. *
  4185. * This source code is licensed under the MIT license found in the
  4186. * LICENSE file in the root directory of this source tree.
  4187. *
  4188. * @typechecks
  4189. */
  4190. /* eslint-disable fb-www/typeof-undefined */
  4191. /**
  4192. * Same as document.activeElement but wraps in a try-catch block. In IE it is
  4193. * not safe to call document.activeElement if there is nothing focused.
  4194. *
  4195. * The activeElement will be null only if the document or document body is not
  4196. * yet defined.
  4197. *
  4198. * @param {?DOMDocument} doc Defaults to current document.
  4199. * @return {?DOMElement}
  4200. */
  4201. function getActiveElement(doc)
  4202. /*?DOMElement*/
  4203. {
  4204. doc = doc || (typeof document !== 'undefined' ? document : undefined);
  4205. if (typeof doc === 'undefined') {
  4206. return null;
  4207. }
  4208. try {
  4209. return doc.activeElement || doc.body;
  4210. } catch (e) {
  4211. return doc.body;
  4212. }
  4213. }
  4214. module.exports = getActiveElement;
  4215. /***/ }),
  4216. /* 62 */
  4217. /***/ (function(module, exports, __webpack_require__) {
  4218. "use strict";
  4219. /**
  4220. * Copyright (c) 2013-present, Facebook, Inc.
  4221. *
  4222. * This source code is licensed under the MIT license found in the
  4223. * LICENSE file in the root directory of this source tree.
  4224. *
  4225. * @typechecks
  4226. */
  4227. var getElementRect = __webpack_require__(116);
  4228. /**
  4229. * Gets an element's position in pixels relative to the viewport. The returned
  4230. * object represents the position of the element's top left corner.
  4231. *
  4232. * @param {DOMElement} element
  4233. * @return {object}
  4234. */
  4235. function getElementPosition(element) {
  4236. var rect = getElementRect(element);
  4237. return {
  4238. x: rect.left,
  4239. y: rect.top,
  4240. width: rect.right - rect.left,
  4241. height: rect.bottom - rect.top
  4242. };
  4243. }
  4244. module.exports = getElementPosition;
  4245. /***/ }),
  4246. /* 63 */
  4247. /***/ (function(module, exports, __webpack_require__) {
  4248. "use strict";
  4249. /**
  4250. * Copyright (c) 2013-present, Facebook, Inc.
  4251. *
  4252. * This source code is licensed under the MIT license found in the
  4253. * LICENSE file in the root directory of this source tree.
  4254. *
  4255. *
  4256. * @typechecks
  4257. */
  4258. function getViewportWidth() {
  4259. var width;
  4260. if (document.documentElement) {
  4261. width = document.documentElement.clientWidth;
  4262. }
  4263. if (!width && document.body) {
  4264. width = document.body.clientWidth;
  4265. }
  4266. return width || 0;
  4267. }
  4268. function getViewportHeight() {
  4269. var height;
  4270. if (document.documentElement) {
  4271. height = document.documentElement.clientHeight;
  4272. }
  4273. if (!height && document.body) {
  4274. height = document.body.clientHeight;
  4275. }
  4276. return height || 0;
  4277. }
  4278. /**
  4279. * Gets the viewport dimensions including any scrollbars.
  4280. */
  4281. function getViewportDimensions() {
  4282. return {
  4283. width: window.innerWidth || getViewportWidth(),
  4284. height: window.innerHeight || getViewportHeight()
  4285. };
  4286. }
  4287. /**
  4288. * Gets the viewport dimensions excluding any scrollbars.
  4289. */
  4290. getViewportDimensions.withoutScrollbars = function () {
  4291. return {
  4292. width: getViewportWidth(),
  4293. height: getViewportHeight()
  4294. };
  4295. };
  4296. module.exports = getViewportDimensions;
  4297. /***/ }),
  4298. /* 64 */
  4299. /***/ (function(module, exports, __webpack_require__) {
  4300. "use strict";
  4301. /**
  4302. * Copyright (c) Facebook, Inc. and its affiliates.
  4303. *
  4304. * This source code is licensed under the MIT license found in the
  4305. * LICENSE file in the root directory of this source tree.
  4306. *
  4307. * @format
  4308. *
  4309. * @emails oncall+draft_js
  4310. */
  4311. var _assign = __webpack_require__(14);
  4312. function _extends() { _extends = _assign || 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; }; return _extends.apply(this, arguments); }
  4313. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  4314. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  4315. 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; }
  4316. var DraftEditorLeaf = __webpack_require__(58);
  4317. var DraftOffsetKey = __webpack_require__(10);
  4318. var React = __webpack_require__(8);
  4319. var Scroll = __webpack_require__(37);
  4320. var Style = __webpack_require__(29);
  4321. var UnicodeBidi = __webpack_require__(33);
  4322. var UnicodeBidiDirection = __webpack_require__(24);
  4323. var cx = __webpack_require__(13);
  4324. var getElementPosition = __webpack_require__(62);
  4325. var getScrollPosition = __webpack_require__(30);
  4326. var getViewportDimensions = __webpack_require__(63);
  4327. var invariant = __webpack_require__(1);
  4328. var isHTMLElement = __webpack_require__(19);
  4329. var nullthrows = __webpack_require__(4);
  4330. var SCROLL_BUFFER = 10;
  4331. /**
  4332. * Return whether a block overlaps with either edge of the `SelectionState`.
  4333. */
  4334. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  4335. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  4336. };
  4337. /**
  4338. * The default block renderer for a `DraftEditor` component.
  4339. *
  4340. * A `DraftEditorBlock` is able to render a given `ContentBlock` to its
  4341. * appropriate decorator and inline style components.
  4342. */
  4343. var DraftEditorBlock =
  4344. /*#__PURE__*/
  4345. function (_React$Component) {
  4346. _inheritsLoose(DraftEditorBlock, _React$Component);
  4347. function DraftEditorBlock() {
  4348. var _this;
  4349. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4350. args[_key] = arguments[_key];
  4351. }
  4352. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  4353. _defineProperty(_assertThisInitialized(_this), "_node", void 0);
  4354. return _this;
  4355. }
  4356. var _proto = DraftEditorBlock.prototype;
  4357. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  4358. return this.props.block !== nextProps.block || this.props.tree !== nextProps.tree || this.props.direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection;
  4359. }
  4360. /**
  4361. * When a block is mounted and overlaps the selection state, we need to make
  4362. * sure that the cursor is visible to match native behavior. This may not
  4363. * be the case if the user has pressed `RETURN` or pasted some content, since
  4364. * programmatically creating these new blocks and setting the DOM selection
  4365. * will miss out on the browser natively scrolling to that position.
  4366. *
  4367. * To replicate native behavior, if the block overlaps the selection state
  4368. * on mount, force the scroll position. Check the scroll state of the scroll
  4369. * parent, and adjust it to align the entire block to the bottom of the
  4370. * scroll parent.
  4371. */
  4372. ;
  4373. _proto.componentDidMount = function componentDidMount() {
  4374. if (this.props.preventScroll) {
  4375. return;
  4376. }
  4377. var selection = this.props.selection;
  4378. var endKey = selection.getEndKey();
  4379. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  4380. return;
  4381. }
  4382. var blockNode = this._node;
  4383. if (blockNode == null) {
  4384. return;
  4385. }
  4386. var scrollParent = Style.getScrollParent(blockNode);
  4387. var scrollPosition = getScrollPosition(scrollParent);
  4388. var scrollDelta;
  4389. if (scrollParent === window) {
  4390. var nodePosition = getElementPosition(blockNode);
  4391. var nodeBottom = nodePosition.y + nodePosition.height;
  4392. var viewportHeight = getViewportDimensions().height;
  4393. scrollDelta = nodeBottom - viewportHeight;
  4394. if (scrollDelta > 0) {
  4395. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  4396. }
  4397. } else {
  4398. !isHTMLElement(blockNode) ? true ? invariant(false, 'blockNode is not an HTMLElement') : invariant(false) : void 0;
  4399. var blockBottom = blockNode.offsetHeight + blockNode.offsetTop;
  4400. var pOffset = scrollParent.offsetTop + scrollParent.offsetHeight;
  4401. var scrollBottom = pOffset + scrollPosition.y;
  4402. scrollDelta = blockBottom - scrollBottom;
  4403. if (scrollDelta > 0) {
  4404. Scroll.setTop(scrollParent, Scroll.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  4405. }
  4406. }
  4407. };
  4408. _proto._renderChildren = function _renderChildren() {
  4409. var _this2 = this;
  4410. var block = this.props.block;
  4411. var blockKey = block.getKey();
  4412. var text = block.getText();
  4413. var lastLeafSet = this.props.tree.size - 1;
  4414. var hasSelection = isBlockOnSelectionEdge(this.props.selection, blockKey);
  4415. return this.props.tree.map(function (leafSet, ii) {
  4416. var leavesForLeafSet = leafSet.get('leaves'); // T44088704
  4417. if (leavesForLeafSet.size === 0) {
  4418. return null;
  4419. }
  4420. var lastLeaf = leavesForLeafSet.size - 1;
  4421. var leaves = leavesForLeafSet.map(function (leaf, jj) {
  4422. var offsetKey = DraftOffsetKey.encode(blockKey, ii, jj);
  4423. var start = leaf.get('start');
  4424. var end = leaf.get('end');
  4425. return React.createElement(DraftEditorLeaf, {
  4426. key: offsetKey,
  4427. offsetKey: offsetKey,
  4428. block: block,
  4429. start: start,
  4430. selection: hasSelection ? _this2.props.selection : null,
  4431. forceSelection: _this2.props.forceSelection,
  4432. text: text.slice(start, end),
  4433. styleSet: block.getInlineStyleAt(start),
  4434. customStyleMap: _this2.props.customStyleMap,
  4435. customStyleFn: _this2.props.customStyleFn,
  4436. isLast: ii === lastLeafSet && jj === lastLeaf
  4437. });
  4438. }).toArray();
  4439. var decoratorKey = leafSet.get('decoratorKey');
  4440. if (decoratorKey == null) {
  4441. return leaves;
  4442. }
  4443. if (!_this2.props.decorator) {
  4444. return leaves;
  4445. }
  4446. var decorator = nullthrows(_this2.props.decorator);
  4447. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  4448. if (!DecoratorComponent) {
  4449. return leaves;
  4450. }
  4451. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  4452. var decoratorOffsetKey = DraftOffsetKey.encode(blockKey, ii, 0);
  4453. var start = leavesForLeafSet.first().get('start');
  4454. var end = leavesForLeafSet.last().get('end');
  4455. var decoratedText = text.slice(start, end);
  4456. var entityKey = block.getEntityAt(leafSet.get('start')); // Resetting dir to the same value on a child node makes Chrome/Firefox
  4457. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  4458. var dir = UnicodeBidiDirection.getHTMLDirIfDifferent(UnicodeBidi.getDirection(decoratedText), _this2.props.direction);
  4459. var commonProps = {
  4460. contentState: _this2.props.contentState,
  4461. decoratedText: decoratedText,
  4462. dir: dir,
  4463. start: start,
  4464. end: end,
  4465. blockKey: blockKey,
  4466. entityKey: entityKey,
  4467. offsetKey: decoratorOffsetKey
  4468. };
  4469. return React.createElement(DecoratorComponent, _extends({}, decoratorProps, commonProps, {
  4470. key: decoratorOffsetKey
  4471. }), leaves);
  4472. }).toArray();
  4473. };
  4474. _proto.render = function render() {
  4475. var _this3 = this;
  4476. var _this$props = this.props,
  4477. direction = _this$props.direction,
  4478. offsetKey = _this$props.offsetKey;
  4479. var className = cx({
  4480. 'public/DraftStyleDefault/block': true,
  4481. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  4482. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  4483. });
  4484. return React.createElement("div", {
  4485. "data-offset-key": offsetKey,
  4486. className: className,
  4487. ref: function ref(_ref) {
  4488. return _this3._node = _ref;
  4489. }
  4490. }, this._renderChildren());
  4491. };
  4492. return DraftEditorBlock;
  4493. }(React.Component);
  4494. module.exports = DraftEditorBlock;
  4495. /***/ }),
  4496. /* 65 */
  4497. /***/ (function(module, exports, __webpack_require__) {
  4498. "use strict";
  4499. /**
  4500. * Copyright (c) 2013-present, Facebook, Inc.
  4501. *
  4502. * This source code is licensed under the MIT license found in the
  4503. * LICENSE file in the root directory of this source tree.
  4504. *
  4505. * @typechecks
  4506. */
  4507. var PhotosMimeType = __webpack_require__(122);
  4508. var createArrayFromMixed = __webpack_require__(123);
  4509. var emptyFunction = __webpack_require__(66);
  4510. var CR_LF_REGEX = new RegExp("\r\n", 'g');
  4511. var LF_ONLY = "\n";
  4512. var RICH_TEXT_TYPES = {
  4513. 'text/rtf': 1,
  4514. 'text/html': 1
  4515. };
  4516. /**
  4517. * If DataTransferItem is a file then return the Blob of data.
  4518. *
  4519. * @param {object} item
  4520. * @return {?blob}
  4521. */
  4522. function getFileFromDataTransfer(item) {
  4523. if (item.kind == 'file') {
  4524. return item.getAsFile();
  4525. }
  4526. }
  4527. var DataTransfer =
  4528. /*#__PURE__*/
  4529. function () {
  4530. /**
  4531. * @param {object} data
  4532. */
  4533. function DataTransfer(data) {
  4534. this.data = data; // Types could be DOMStringList or array
  4535. this.types = data.types ? createArrayFromMixed(data.types) : [];
  4536. }
  4537. /**
  4538. * Is this likely to be a rich text data transfer?
  4539. *
  4540. * @return {boolean}
  4541. */
  4542. var _proto = DataTransfer.prototype;
  4543. _proto.isRichText = function isRichText() {
  4544. // If HTML is available, treat this data as rich text. This way, we avoid
  4545. // using a pasted image if it is packaged with HTML -- this may occur with
  4546. // pastes from MS Word, for example. However this is only rich text if
  4547. // there's accompanying text.
  4548. if (this.getHTML() && this.getText()) {
  4549. return true;
  4550. } // When an image is copied from a preview window, you end up with two
  4551. // DataTransferItems one of which is a file's metadata as text. Skip those.
  4552. if (this.isImage()) {
  4553. return false;
  4554. }
  4555. return this.types.some(function (type) {
  4556. return RICH_TEXT_TYPES[type];
  4557. });
  4558. };
  4559. /**
  4560. * Get raw text.
  4561. *
  4562. * @return {?string}
  4563. */
  4564. _proto.getText = function getText() {
  4565. var text;
  4566. if (this.data.getData) {
  4567. if (!this.types.length) {
  4568. text = this.data.getData('Text');
  4569. } else if (this.types.indexOf('text/plain') != -1) {
  4570. text = this.data.getData('text/plain');
  4571. }
  4572. }
  4573. return text ? text.replace(CR_LF_REGEX, LF_ONLY) : null;
  4574. };
  4575. /**
  4576. * Get HTML paste data
  4577. *
  4578. * @return {?string}
  4579. */
  4580. _proto.getHTML = function getHTML() {
  4581. if (this.data.getData) {
  4582. if (!this.types.length) {
  4583. return this.data.getData('Text');
  4584. } else if (this.types.indexOf('text/html') != -1) {
  4585. return this.data.getData('text/html');
  4586. }
  4587. }
  4588. };
  4589. /**
  4590. * Is this a link data transfer?
  4591. *
  4592. * @return {boolean}
  4593. */
  4594. _proto.isLink = function isLink() {
  4595. return this.types.some(function (type) {
  4596. return type.indexOf('Url') != -1 || type.indexOf('text/uri-list') != -1 || type.indexOf('text/x-moz-url');
  4597. });
  4598. };
  4599. /**
  4600. * Get a link url.
  4601. *
  4602. * @return {?string}
  4603. */
  4604. _proto.getLink = function getLink() {
  4605. if (this.data.getData) {
  4606. if (this.types.indexOf('text/x-moz-url') != -1) {
  4607. var url = this.data.getData('text/x-moz-url').split('\n');
  4608. return url[0];
  4609. }
  4610. return this.types.indexOf('text/uri-list') != -1 ? this.data.getData('text/uri-list') : this.data.getData('url');
  4611. }
  4612. return null;
  4613. };
  4614. /**
  4615. * Is this an image data transfer?
  4616. *
  4617. * @return {boolean}
  4618. */
  4619. _proto.isImage = function isImage() {
  4620. var isImage = this.types.some(function (type) {
  4621. // Firefox will have a type of application/x-moz-file for images during
  4622. // dragging
  4623. return type.indexOf('application/x-moz-file') != -1;
  4624. });
  4625. if (isImage) {
  4626. return true;
  4627. }
  4628. var items = this.getFiles();
  4629. for (var i = 0; i < items.length; i++) {
  4630. var type = items[i].type;
  4631. if (!PhotosMimeType.isImage(type)) {
  4632. return false;
  4633. }
  4634. }
  4635. return true;
  4636. };
  4637. _proto.getCount = function getCount() {
  4638. if (this.data.hasOwnProperty('items')) {
  4639. return this.data.items.length;
  4640. } else if (this.data.hasOwnProperty('mozItemCount')) {
  4641. return this.data.mozItemCount;
  4642. } else if (this.data.files) {
  4643. return this.data.files.length;
  4644. }
  4645. return null;
  4646. };
  4647. /**
  4648. * Get files.
  4649. *
  4650. * @return {array}
  4651. */
  4652. _proto.getFiles = function getFiles() {
  4653. if (this.data.items) {
  4654. // createArrayFromMixed doesn't properly handle DataTransferItemLists.
  4655. return Array.prototype.slice.call(this.data.items).map(getFileFromDataTransfer).filter(emptyFunction.thatReturnsArgument);
  4656. } else if (this.data.files) {
  4657. return Array.prototype.slice.call(this.data.files);
  4658. } else {
  4659. return [];
  4660. }
  4661. };
  4662. /**
  4663. * Are there any files to fetch?
  4664. *
  4665. * @return {boolean}
  4666. */
  4667. _proto.hasFiles = function hasFiles() {
  4668. return this.getFiles().length > 0;
  4669. };
  4670. return DataTransfer;
  4671. }();
  4672. module.exports = DataTransfer;
  4673. /***/ }),
  4674. /* 66 */
  4675. /***/ (function(module, exports, __webpack_require__) {
  4676. "use strict";
  4677. /**
  4678. * Copyright (c) 2013-present, Facebook, Inc.
  4679. *
  4680. * This source code is licensed under the MIT license found in the
  4681. * LICENSE file in the root directory of this source tree.
  4682. *
  4683. *
  4684. */
  4685. function makeEmptyFunction(arg) {
  4686. return function () {
  4687. return arg;
  4688. };
  4689. }
  4690. /**
  4691. * This function accepts and discards inputs; it has no side effects. This is
  4692. * primarily useful idiomatically for overridable function endpoints which
  4693. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  4694. */
  4695. var emptyFunction = function emptyFunction() {};
  4696. emptyFunction.thatReturns = makeEmptyFunction;
  4697. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  4698. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  4699. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  4700. emptyFunction.thatReturnsThis = function () {
  4701. return this;
  4702. };
  4703. emptyFunction.thatReturnsArgument = function (arg) {
  4704. return arg;
  4705. };
  4706. module.exports = emptyFunction;
  4707. /***/ }),
  4708. /* 67 */
  4709. /***/ (function(module, exports, __webpack_require__) {
  4710. "use strict";
  4711. /* WEBPACK VAR INJECTION */(function(global) {/**
  4712. * Copyright (c) Facebook, Inc. and its affiliates.
  4713. *
  4714. * This source code is licensed under the MIT license found in the
  4715. * LICENSE file in the root directory of this source tree.
  4716. *
  4717. * @format
  4718. *
  4719. * @emails oncall+draft_js
  4720. */
  4721. var invariant = __webpack_require__(1);
  4722. var TEXT_CLIPPING_REGEX = /\.textClipping$/;
  4723. var TEXT_TYPES = {
  4724. 'text/plain': true,
  4725. 'text/html': true,
  4726. 'text/rtf': true
  4727. }; // Somewhat arbitrary upper bound on text size. Let's not lock up the browser.
  4728. var TEXT_SIZE_UPPER_BOUND = 5000;
  4729. /**
  4730. * Extract the text content from a file list.
  4731. */
  4732. function getTextContentFromFiles(files, callback) {
  4733. var readCount = 0;
  4734. var results = [];
  4735. files.forEach(function (
  4736. /*blob*/
  4737. file) {
  4738. readFile(file, function (
  4739. /*string*/
  4740. text) {
  4741. readCount++;
  4742. text && results.push(text.slice(0, TEXT_SIZE_UPPER_BOUND));
  4743. if (readCount == files.length) {
  4744. callback(results.join('\r'));
  4745. }
  4746. });
  4747. });
  4748. }
  4749. /**
  4750. * todo isaac: Do work to turn html/rtf into a content fragment.
  4751. */
  4752. function readFile(file, callback) {
  4753. if (!global.FileReader || file.type && !(file.type in TEXT_TYPES)) {
  4754. callback('');
  4755. return;
  4756. }
  4757. if (file.type === '') {
  4758. var _contents = ''; // Special-case text clippings, which have an empty type but include
  4759. // `.textClipping` in the file name. `readAsText` results in an empty
  4760. // string for text clippings, so we force the file name to serve
  4761. // as the text value for the file.
  4762. if (TEXT_CLIPPING_REGEX.test(file.name)) {
  4763. _contents = file.name.replace(TEXT_CLIPPING_REGEX, '');
  4764. }
  4765. callback(_contents);
  4766. return;
  4767. }
  4768. var reader = new FileReader();
  4769. reader.onload = function () {
  4770. var result = reader.result;
  4771. !(typeof result === 'string') ? true ? invariant(false, 'We should be calling "FileReader.readAsText" which returns a string') : invariant(false) : void 0;
  4772. callback(result);
  4773. };
  4774. reader.onerror = function () {
  4775. callback('');
  4776. };
  4777. reader.readAsText(file);
  4778. }
  4779. module.exports = getTextContentFromFiles;
  4780. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(25)))
  4781. /***/ }),
  4782. /* 68 */
  4783. /***/ (function(module, exports, __webpack_require__) {
  4784. "use strict";
  4785. /**
  4786. * Copyright (c) Facebook, Inc. and its affiliates.
  4787. *
  4788. * This source code is licensed under the MIT license found in the
  4789. * LICENSE file in the root directory of this source tree.
  4790. *
  4791. * @format
  4792. *
  4793. * @emails oncall+draft_js
  4794. */
  4795. var getContentStateFragment = __webpack_require__(21);
  4796. function getFragmentFromSelection(editorState) {
  4797. var selectionState = editorState.getSelection();
  4798. if (selectionState.isCollapsed()) {
  4799. return null;
  4800. }
  4801. return getContentStateFragment(editorState.getCurrentContent(), selectionState);
  4802. }
  4803. module.exports = getFragmentFromSelection;
  4804. /***/ }),
  4805. /* 69 */
  4806. /***/ (function(module, exports, __webpack_require__) {
  4807. "use strict";
  4808. /**
  4809. * Copyright (c) Facebook, Inc. and its affiliates.
  4810. *
  4811. * This source code is licensed under the MIT license found in the
  4812. * LICENSE file in the root directory of this source tree.
  4813. *
  4814. * @format
  4815. *
  4816. * @emails oncall+draft_js
  4817. */
  4818. var EditorState = __webpack_require__(2);
  4819. var UnicodeUtils = __webpack_require__(16);
  4820. var moveSelectionBackward = __webpack_require__(38);
  4821. var removeTextWithStrategy = __webpack_require__(20);
  4822. /**
  4823. * Remove the selected range. If the cursor is collapsed, remove the preceding
  4824. * character. This operation is Unicode-aware, so removing a single character
  4825. * will remove a surrogate pair properly as well.
  4826. */
  4827. function keyCommandPlainBackspace(editorState) {
  4828. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  4829. var selection = strategyState.getSelection();
  4830. var content = strategyState.getCurrentContent();
  4831. var key = selection.getAnchorKey();
  4832. var offset = selection.getAnchorOffset();
  4833. var charBehind = content.getBlockForKey(key).getText()[offset - 1];
  4834. return moveSelectionBackward(strategyState, charBehind ? UnicodeUtils.getUTF16Length(charBehind, 0) : 1);
  4835. }, 'backward');
  4836. if (afterRemoval === editorState.getCurrentContent()) {
  4837. return editorState;
  4838. }
  4839. var selection = editorState.getSelection();
  4840. return EditorState.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'backspace-character' : 'remove-range');
  4841. }
  4842. module.exports = keyCommandPlainBackspace;
  4843. /***/ }),
  4844. /* 70 */
  4845. /***/ (function(module, exports, __webpack_require__) {
  4846. "use strict";
  4847. /**
  4848. * Copyright (c) Facebook, Inc. and its affiliates.
  4849. *
  4850. * This source code is licensed under the MIT license found in the
  4851. * LICENSE file in the root directory of this source tree.
  4852. *
  4853. * @format
  4854. *
  4855. * @emails oncall+draft_js
  4856. */
  4857. var UserAgent = __webpack_require__(5);
  4858. var invariant = __webpack_require__(1);
  4859. var isChrome = UserAgent.isBrowser('Chrome'); // In Chrome, the client rects will include the entire bounds of all nodes that
  4860. // begin (have a start tag) within the selection, even if the selection does
  4861. // not overlap the entire node. To resolve this, we split the range at each
  4862. // start tag and join the client rects together.
  4863. // https://code.google.com/p/chromium/issues/detail?id=324437
  4864. /* eslint-disable consistent-return */
  4865. function getRangeClientRectsChrome(range) {
  4866. var tempRange = range.cloneRange();
  4867. var clientRects = [];
  4868. for (var ancestor = range.endContainer; ancestor != null; ancestor = ancestor.parentNode) {
  4869. // If we've climbed up to the common ancestor, we can now use the
  4870. // original start point and stop climbing the tree.
  4871. var atCommonAncestor = ancestor === range.commonAncestorContainer;
  4872. if (atCommonAncestor) {
  4873. tempRange.setStart(range.startContainer, range.startOffset);
  4874. } else {
  4875. tempRange.setStart(tempRange.endContainer, 0);
  4876. }
  4877. var rects = Array.from(tempRange.getClientRects());
  4878. clientRects.push(rects);
  4879. if (atCommonAncestor) {
  4880. var _ref;
  4881. clientRects.reverse();
  4882. return (_ref = []).concat.apply(_ref, clientRects);
  4883. }
  4884. tempRange.setEndBefore(ancestor);
  4885. }
  4886. true ? true ? invariant(false, 'Found an unexpected detached subtree when getting range client rects.') : invariant(false) : void 0;
  4887. }
  4888. /* eslint-enable consistent-return */
  4889. /**
  4890. * Like range.getClientRects() but normalizes for browser bugs.
  4891. */
  4892. var getRangeClientRects = isChrome ? getRangeClientRectsChrome : function (range) {
  4893. return Array.from(range.getClientRects());
  4894. };
  4895. module.exports = getRangeClientRects;
  4896. /***/ }),
  4897. /* 71 */
  4898. /***/ (function(module, exports, __webpack_require__) {
  4899. "use strict";
  4900. /**
  4901. * Copyright (c) Facebook, Inc. and its affiliates.
  4902. *
  4903. * This source code is licensed under the MIT license found in the
  4904. * LICENSE file in the root directory of this source tree.
  4905. *
  4906. * @format
  4907. *
  4908. * @emails oncall+draft_js
  4909. */
  4910. var TokenizeUtil = __webpack_require__(145);
  4911. var punctuation = TokenizeUtil.getPunctuation(); // The apostrophe and curly single quotes behave in a curious way: when
  4912. // surrounded on both sides by word characters, they behave as word chars; when
  4913. // either neighbor is punctuation or an end of the string, they behave as
  4914. // punctuation.
  4915. var CHAMELEON_CHARS = "['\u2018\u2019]"; // Remove the underscore, which should count as part of the removable word. The
  4916. // "chameleon chars" also count as punctuation in this regex.
  4917. var WHITESPACE_AND_PUNCTUATION = '\\s|(?![_])' + punctuation;
  4918. var DELETE_STRING = '^' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)';
  4919. var DELETE_REGEX = new RegExp(DELETE_STRING);
  4920. var BACKSPACE_STRING = '(?:(?!' + WHITESPACE_AND_PUNCTUATION + ').)' + '(?:' + CHAMELEON_CHARS + '|(?!' + WHITESPACE_AND_PUNCTUATION + ').)*' + '(?:' + WHITESPACE_AND_PUNCTUATION + ')*' + '$';
  4921. var BACKSPACE_REGEX = new RegExp(BACKSPACE_STRING);
  4922. function getRemovableWord(text, isBackward) {
  4923. var matches = isBackward ? BACKSPACE_REGEX.exec(text) : DELETE_REGEX.exec(text);
  4924. return matches ? matches[0] : text;
  4925. }
  4926. var DraftRemovableWord = {
  4927. getBackward: function getBackward(text) {
  4928. return getRemovableWord(text, true);
  4929. },
  4930. getForward: function getForward(text) {
  4931. return getRemovableWord(text, false);
  4932. }
  4933. };
  4934. module.exports = DraftRemovableWord;
  4935. /***/ }),
  4936. /* 72 */
  4937. /***/ (function(module, exports, __webpack_require__) {
  4938. "use strict";
  4939. /**
  4940. * Copyright (c) Facebook, Inc. and its affiliates.
  4941. *
  4942. * This source code is licensed under the MIT license found in the
  4943. * LICENSE file in the root directory of this source tree.
  4944. *
  4945. * @format
  4946. *
  4947. * @emails oncall+draft_js
  4948. */
  4949. var warning = __webpack_require__(39);
  4950. /**
  4951. * Given a collapsed selection, move the focus `maxDistance` forward within
  4952. * the selected block. If the selection will go beyond the end of the block,
  4953. * move focus to the start of the next block, but no further.
  4954. *
  4955. * This function is not Unicode-aware, so surrogate pairs will be treated
  4956. * as having length 2.
  4957. */
  4958. function moveSelectionForward(editorState, maxDistance) {
  4959. var selection = editorState.getSelection(); // Should eventually make this an invariant
  4960. true ? warning(selection.isCollapsed(), 'moveSelectionForward should only be called with a collapsed SelectionState') : void 0;
  4961. var key = selection.getStartKey();
  4962. var offset = selection.getStartOffset();
  4963. var content = editorState.getCurrentContent();
  4964. var focusKey = key;
  4965. var focusOffset;
  4966. var block = content.getBlockForKey(key);
  4967. if (maxDistance > block.getText().length - offset) {
  4968. focusKey = content.getKeyAfter(key);
  4969. focusOffset = 0;
  4970. } else {
  4971. focusOffset = offset + maxDistance;
  4972. }
  4973. return selection.merge({
  4974. focusKey: focusKey,
  4975. focusOffset: focusOffset
  4976. });
  4977. }
  4978. module.exports = moveSelectionForward;
  4979. /***/ }),
  4980. /* 73 */
  4981. /***/ (function(module, exports, __webpack_require__) {
  4982. "use strict";
  4983. /**
  4984. * Copyright (c) Facebook, Inc. and its affiliates.
  4985. *
  4986. * This source code is licensed under the MIT license found in the
  4987. * LICENSE file in the root directory of this source tree.
  4988. *
  4989. * @format
  4990. *
  4991. * @emails oncall+draft_js
  4992. */
  4993. var _knownListItemDepthCl;
  4994. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  4995. 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; }
  4996. var CharacterMetadata = __webpack_require__(6);
  4997. var ContentBlock = __webpack_require__(12);
  4998. var ContentBlockNode = __webpack_require__(7);
  4999. var DefaultDraftBlockRenderMap = __webpack_require__(34);
  5000. var DraftEntity = __webpack_require__(22);
  5001. var URI = __webpack_require__(155);
  5002. var cx = __webpack_require__(13);
  5003. var generateRandomKey = __webpack_require__(9);
  5004. var getSafeBodyFromHTML = __webpack_require__(74);
  5005. var gkx = __webpack_require__(11);
  5006. var _require = __webpack_require__(0),
  5007. List = _require.List,
  5008. Map = _require.Map,
  5009. OrderedSet = _require.OrderedSet;
  5010. var isHTMLAnchorElement = __webpack_require__(156);
  5011. var isHTMLBRElement = __webpack_require__(59);
  5012. var isHTMLElement = __webpack_require__(19);
  5013. var isHTMLImageElement = __webpack_require__(157);
  5014. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  5015. var NBSP = '&nbsp;';
  5016. var SPACE = ' '; // used for replacing characters in HTML
  5017. var REGEX_CR = new RegExp('\r', 'g');
  5018. var REGEX_LF = new RegExp('\n', 'g');
  5019. var REGEX_LEADING_LF = new RegExp('^\n', 'g');
  5020. var REGEX_NBSP = new RegExp(NBSP, 'g');
  5021. var REGEX_CARRIAGE = new RegExp('&#13;?', 'g');
  5022. var REGEX_ZWS = new RegExp('&#8203;?', 'g'); // https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
  5023. var boldValues = ['bold', 'bolder', '500', '600', '700', '800', '900'];
  5024. var notBoldValues = ['light', 'lighter', 'normal', '100', '200', '300', '400'];
  5025. var anchorAttr = ['className', 'href', 'rel', 'target', 'title'];
  5026. var imgAttr = ['alt', 'className', 'height', 'src', 'width'];
  5027. var knownListItemDepthClasses = (_knownListItemDepthCl = {}, _defineProperty(_knownListItemDepthCl, cx('public/DraftStyleDefault/depth0'), 0), _defineProperty(_knownListItemDepthCl, cx('public/DraftStyleDefault/depth1'), 1), _defineProperty(_knownListItemDepthCl, cx('public/DraftStyleDefault/depth2'), 2), _defineProperty(_knownListItemDepthCl, cx('public/DraftStyleDefault/depth3'), 3), _defineProperty(_knownListItemDepthCl, cx('public/DraftStyleDefault/depth4'), 4), _knownListItemDepthCl);
  5028. var HTMLTagToRawInlineStyleMap = Map({
  5029. b: 'BOLD',
  5030. code: 'CODE',
  5031. del: 'STRIKETHROUGH',
  5032. em: 'ITALIC',
  5033. i: 'ITALIC',
  5034. s: 'STRIKETHROUGH',
  5035. strike: 'STRIKETHROUGH',
  5036. strong: 'BOLD',
  5037. u: 'UNDERLINE',
  5038. mark: 'HIGHLIGHT'
  5039. });
  5040. /**
  5041. * Build a mapping from HTML tags to draftjs block types
  5042. * out of a BlockRenderMap.
  5043. *
  5044. * The BlockTypeMap for the default BlockRenderMap looks like this:
  5045. * Map({
  5046. * h1: 'header-one',
  5047. * h2: 'header-two',
  5048. * h3: 'header-three',
  5049. * h4: 'header-four',
  5050. * h5: 'header-five',
  5051. * h6: 'header-six',
  5052. * blockquote: 'blockquote',
  5053. * figure: 'atomic',
  5054. * pre: ['code-block'],
  5055. * div: 'unstyled',
  5056. * p: 'unstyled',
  5057. * li: ['ordered-list-item', 'unordered-list-item'],
  5058. * })
  5059. */
  5060. var buildBlockTypeMap = function buildBlockTypeMap(blockRenderMap) {
  5061. var blockTypeMap = {};
  5062. blockRenderMap.mapKeys(function (blockType, desc) {
  5063. var elements = [desc.element];
  5064. if (desc.aliasedElements !== undefined) {
  5065. elements.push.apply(elements, desc.aliasedElements);
  5066. }
  5067. elements.forEach(function (element) {
  5068. if (blockTypeMap[element] === undefined) {
  5069. blockTypeMap[element] = blockType;
  5070. } else if (typeof blockTypeMap[element] === 'string') {
  5071. blockTypeMap[element] = [blockTypeMap[element], blockType];
  5072. } else {
  5073. blockTypeMap[element].push(blockType);
  5074. }
  5075. });
  5076. });
  5077. return Map(blockTypeMap);
  5078. };
  5079. /**
  5080. * If we're pasting from one DraftEditor to another we can check to see if
  5081. * existing list item depth classes are being used and preserve this style
  5082. */
  5083. var getListItemDepth = function getListItemDepth(node) {
  5084. var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  5085. Object.keys(knownListItemDepthClasses).some(function (depthClass) {
  5086. if (node.classList.contains(depthClass)) {
  5087. depth = knownListItemDepthClasses[depthClass];
  5088. }
  5089. });
  5090. return depth;
  5091. };
  5092. /**
  5093. * Return true if the provided HTML Element can be used to build a
  5094. * Draftjs-compatible link.
  5095. */
  5096. var isValidAnchor = function isValidAnchor(node) {
  5097. if (!isHTMLAnchorElement(node)) {
  5098. return false;
  5099. }
  5100. var anchorNode = node;
  5101. return !!(anchorNode.href && (anchorNode.protocol === 'http:' || anchorNode.protocol === 'https:' || anchorNode.protocol === 'mailto:'));
  5102. };
  5103. /**
  5104. * Return true if the provided HTML Element can be used to build a
  5105. * Draftjs-compatible image.
  5106. */
  5107. var isValidImage = function isValidImage(node) {
  5108. if (!isHTMLImageElement(node)) {
  5109. return false;
  5110. }
  5111. var imageNode = node;
  5112. return !!(imageNode.attributes.getNamedItem('src') && imageNode.attributes.getNamedItem('src').value);
  5113. };
  5114. /**
  5115. * Try to guess the inline style of an HTML element based on its css
  5116. * styles (font-weight, font-style and text-decoration).
  5117. */
  5118. var styleFromNodeAttributes = function styleFromNodeAttributes(node, style) {
  5119. if (!isHTMLElement(node)) {
  5120. return style;
  5121. }
  5122. var htmlElement = node;
  5123. var fontWeight = htmlElement.style.fontWeight;
  5124. var fontStyle = htmlElement.style.fontStyle;
  5125. var textDecoration = htmlElement.style.textDecoration;
  5126. return style.withMutations(function (style) {
  5127. if (boldValues.indexOf(fontWeight) >= 0) {
  5128. style.add('BOLD');
  5129. } else if (notBoldValues.indexOf(fontWeight) >= 0) {
  5130. style.remove('BOLD');
  5131. }
  5132. if (fontStyle === 'italic') {
  5133. style.add('ITALIC');
  5134. } else if (fontStyle === 'normal') {
  5135. style.remove('ITALIC');
  5136. }
  5137. if (textDecoration === 'underline') {
  5138. style.add('UNDERLINE');
  5139. }
  5140. if (textDecoration === 'line-through') {
  5141. style.add('STRIKETHROUGH');
  5142. }
  5143. if (textDecoration === 'none') {
  5144. style.remove('UNDERLINE');
  5145. style.remove('STRIKETHROUGH');
  5146. }
  5147. });
  5148. };
  5149. /**
  5150. * Determine if a nodeName is a list type, 'ul' or 'ol'
  5151. */
  5152. var isListNode = function isListNode(nodeName) {
  5153. return nodeName === 'ul' || nodeName === 'ol';
  5154. };
  5155. /**
  5156. * ContentBlockConfig is a mutable data structure that holds all
  5157. * the information required to build a ContentBlock and an array of
  5158. * all the child nodes (childConfigs).
  5159. * It is being used a temporary data structure by the
  5160. * ContentBlocksBuilder class.
  5161. */
  5162. /**
  5163. * ContentBlocksBuilder builds a list of ContentBlocks and an Entity Map
  5164. * out of one (or several) HTMLElement(s).
  5165. *
  5166. * The algorithm has two passes: first it builds a tree of ContentBlockConfigs
  5167. * by walking through the HTML nodes and their children, then it walks the
  5168. * ContentBlockConfigs tree to compute parents/siblings and create
  5169. * the actual ContentBlocks.
  5170. *
  5171. * Typical usage is:
  5172. * new ContentBlocksBuilder()
  5173. * .addDOMNode(someHTMLNode)
  5174. * .addDOMNode(someOtherHTMLNode)
  5175. * .getContentBlocks();
  5176. *
  5177. */
  5178. var ContentBlocksBuilder =
  5179. /*#__PURE__*/
  5180. function () {
  5181. // Most of the method in the class depend on the state of the content builder
  5182. // (i.e. currentBlockType, currentDepth, currentEntity etc.). Though it may
  5183. // be confusing at first, it made the code simpler than the alternative which
  5184. // is to pass those values around in every call.
  5185. // The following attributes are used to accumulate text and styles
  5186. // as we are walking the HTML node tree.
  5187. // Describes the future ContentState as a tree of content blocks
  5188. // The content blocks generated from the blockConfigs
  5189. // Entity map use to store links and images found in the HTML nodes
  5190. // Map HTML tags to draftjs block types and disambiguation function
  5191. function ContentBlocksBuilder(blockTypeMap, disambiguate) {
  5192. _defineProperty(this, "characterList", List());
  5193. _defineProperty(this, "currentBlockType", 'unstyled');
  5194. _defineProperty(this, "currentDepth", 0);
  5195. _defineProperty(this, "currentEntity", null);
  5196. _defineProperty(this, "currentText", '');
  5197. _defineProperty(this, "wrapper", null);
  5198. _defineProperty(this, "blockConfigs", []);
  5199. _defineProperty(this, "contentBlocks", []);
  5200. _defineProperty(this, "entityMap", DraftEntity);
  5201. _defineProperty(this, "blockTypeMap", void 0);
  5202. _defineProperty(this, "disambiguate", void 0);
  5203. this.clear();
  5204. this.blockTypeMap = blockTypeMap;
  5205. this.disambiguate = disambiguate;
  5206. }
  5207. /**
  5208. * Clear the internal state of the ContentBlocksBuilder
  5209. */
  5210. var _proto = ContentBlocksBuilder.prototype;
  5211. _proto.clear = function clear() {
  5212. this.characterList = List();
  5213. this.blockConfigs = [];
  5214. this.currentBlockType = 'unstyled';
  5215. this.currentDepth = 0;
  5216. this.currentEntity = null;
  5217. this.currentText = '';
  5218. this.entityMap = DraftEntity;
  5219. this.wrapper = null;
  5220. this.contentBlocks = [];
  5221. }
  5222. /**
  5223. * Add an HTMLElement to the ContentBlocksBuilder
  5224. */
  5225. ;
  5226. _proto.addDOMNode = function addDOMNode(node) {
  5227. var _this$blockConfigs;
  5228. this.contentBlocks = [];
  5229. this.currentDepth = 0; // Converts the HTML node to block config
  5230. (_this$blockConfigs = this.blockConfigs).push.apply(_this$blockConfigs, this._toBlockConfigs([node], OrderedSet())); // There might be some left over text in the builder's
  5231. // internal state, if so make a ContentBlock out of it.
  5232. this._trimCurrentText();
  5233. if (this.currentText !== '') {
  5234. this.blockConfigs.push(this._makeBlockConfig());
  5235. } // for chaining
  5236. return this;
  5237. }
  5238. /**
  5239. * Return the ContentBlocks and the EntityMap that corresponds
  5240. * to the previously added HTML nodes.
  5241. */
  5242. ;
  5243. _proto.getContentBlocks = function getContentBlocks() {
  5244. if (this.contentBlocks.length === 0) {
  5245. if (experimentalTreeDataSupport) {
  5246. this._toContentBlocks(this.blockConfigs);
  5247. } else {
  5248. this._toFlatContentBlocks(this.blockConfigs);
  5249. }
  5250. }
  5251. return {
  5252. contentBlocks: this.contentBlocks,
  5253. entityMap: this.entityMap
  5254. };
  5255. } // ***********************************WARNING******************************
  5256. // The methods below this line are private - don't call them directly.
  5257. /**
  5258. * Generate a new ContentBlockConfig out of the current internal state
  5259. * of the builder, then clears the internal state.
  5260. */
  5261. ;
  5262. _proto._makeBlockConfig = function _makeBlockConfig() {
  5263. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  5264. var key = config.key || generateRandomKey();
  5265. var block = _objectSpread({
  5266. key: key,
  5267. type: this.currentBlockType,
  5268. text: this.currentText,
  5269. characterList: this.characterList,
  5270. depth: this.currentDepth,
  5271. parent: null,
  5272. children: List(),
  5273. prevSibling: null,
  5274. nextSibling: null,
  5275. childConfigs: []
  5276. }, config);
  5277. this.characterList = List();
  5278. this.currentBlockType = 'unstyled';
  5279. this.currentText = '';
  5280. return block;
  5281. }
  5282. /**
  5283. * Converts an array of HTML elements to a multi-root tree of content
  5284. * block configs. Some text content may be left in the builders internal
  5285. * state to enable chaining sucessive calls.
  5286. */
  5287. ;
  5288. _proto._toBlockConfigs = function _toBlockConfigs(nodes, style) {
  5289. var blockConfigs = [];
  5290. for (var i = 0; i < nodes.length; i++) {
  5291. var node = nodes[i];
  5292. var nodeName = node.nodeName.toLowerCase();
  5293. if (nodeName === 'body' || isListNode(nodeName)) {
  5294. // body, ol and ul are 'block' type nodes so create a block config
  5295. // with the text accumulated so far (if any)
  5296. this._trimCurrentText();
  5297. if (this.currentText !== '') {
  5298. blockConfigs.push(this._makeBlockConfig());
  5299. } // body, ol and ul nodes are ignored, but their children are inlined in
  5300. // the parent block config.
  5301. var wasCurrentDepth = this.currentDepth;
  5302. var wasWrapper = this.wrapper;
  5303. if (isListNode(nodeName)) {
  5304. this.wrapper = nodeName;
  5305. if (isListNode(wasWrapper)) {
  5306. this.currentDepth++;
  5307. }
  5308. }
  5309. blockConfigs.push.apply(blockConfigs, this._toBlockConfigs(Array.from(node.childNodes), style));
  5310. this.currentDepth = wasCurrentDepth;
  5311. this.wrapper = wasWrapper;
  5312. continue;
  5313. }
  5314. var blockType = this.blockTypeMap.get(nodeName);
  5315. if (blockType !== undefined) {
  5316. // 'block' type node means we need to create a block config
  5317. // with the text accumulated so far (if any)
  5318. this._trimCurrentText();
  5319. if (this.currentText !== '') {
  5320. blockConfigs.push(this._makeBlockConfig());
  5321. }
  5322. var _wasCurrentDepth = this.currentDepth;
  5323. var _wasWrapper = this.wrapper;
  5324. this.wrapper = nodeName === 'pre' ? 'pre' : this.wrapper;
  5325. if (typeof blockType !== 'string') {
  5326. blockType = this.disambiguate(nodeName, this.wrapper) || blockType[0] || 'unstyled';
  5327. }
  5328. if (!experimentalTreeDataSupport && isHTMLElement(node) && (blockType === 'unordered-list-item' || blockType === 'ordered-list-item')) {
  5329. var htmlElement = node;
  5330. this.currentDepth = getListItemDepth(htmlElement, this.currentDepth);
  5331. }
  5332. var key = generateRandomKey();
  5333. var childConfigs = this._toBlockConfigs(Array.from(node.childNodes), style);
  5334. this._trimCurrentText();
  5335. blockConfigs.push(this._makeBlockConfig({
  5336. key: key,
  5337. childConfigs: childConfigs,
  5338. type: blockType
  5339. }));
  5340. this.currentDepth = _wasCurrentDepth;
  5341. this.wrapper = _wasWrapper;
  5342. continue;
  5343. }
  5344. if (nodeName === '#text') {
  5345. this._addTextNode(node, style);
  5346. continue;
  5347. }
  5348. if (nodeName === 'br') {
  5349. this._addBreakNode(node, style);
  5350. continue;
  5351. }
  5352. if (isValidImage(node)) {
  5353. this._addImgNode(node, style);
  5354. continue;
  5355. }
  5356. if (isValidAnchor(node)) {
  5357. this._addAnchorNode(node, blockConfigs, style);
  5358. continue;
  5359. }
  5360. var newStyle = style;
  5361. if (HTMLTagToRawInlineStyleMap.has(nodeName)) {
  5362. newStyle = newStyle.add(HTMLTagToRawInlineStyleMap.get(nodeName));
  5363. }
  5364. newStyle = styleFromNodeAttributes(node, newStyle);
  5365. blockConfigs.push.apply(blockConfigs, this._toBlockConfigs(Array.from(node.childNodes), newStyle));
  5366. }
  5367. return blockConfigs;
  5368. }
  5369. /**
  5370. * Append a string of text to the internal buffer.
  5371. */
  5372. ;
  5373. _proto._appendText = function _appendText(text, style) {
  5374. var _this$characterList;
  5375. this.currentText += text;
  5376. var characterMetadata = CharacterMetadata.create({
  5377. style: style,
  5378. entity: this.currentEntity
  5379. });
  5380. this.characterList = (_this$characterList = this.characterList).push.apply(_this$characterList, Array(text.length).fill(characterMetadata));
  5381. }
  5382. /**
  5383. * Trim the text in the internal buffer.
  5384. */
  5385. ;
  5386. _proto._trimCurrentText = function _trimCurrentText() {
  5387. var l = this.currentText.length;
  5388. var begin = l - this.currentText.trimLeft().length;
  5389. var end = this.currentText.trimRight().length; // We should not trim whitespaces for which an entity is defined.
  5390. var entity = this.characterList.findEntry(function (characterMetadata) {
  5391. return characterMetadata.getEntity() !== null;
  5392. });
  5393. begin = entity !== undefined ? Math.min(begin, entity[0]) : begin;
  5394. entity = this.characterList.reverse().findEntry(function (characterMetadata) {
  5395. return characterMetadata.getEntity() !== null;
  5396. });
  5397. end = entity !== undefined ? Math.max(end, l - entity[0]) : end;
  5398. if (begin > end) {
  5399. this.currentText = '';
  5400. this.characterList = List();
  5401. } else {
  5402. this.currentText = this.currentText.slice(begin, end);
  5403. this.characterList = this.characterList.slice(begin, end);
  5404. }
  5405. }
  5406. /**
  5407. * Add the content of an HTML text node to the internal state
  5408. */
  5409. ;
  5410. _proto._addTextNode = function _addTextNode(node, style) {
  5411. var text = node.textContent;
  5412. var trimmedText = text.trim(); // If we are not in a pre block and the trimmed content is empty,
  5413. // normalize to a single space.
  5414. if (trimmedText === '' && this.wrapper !== 'pre') {
  5415. text = ' ';
  5416. }
  5417. if (this.wrapper !== 'pre') {
  5418. // Trim leading line feed, which is invisible in HTML
  5419. text = text.replace(REGEX_LEADING_LF, ''); // Can't use empty string because MSWord
  5420. text = text.replace(REGEX_LF, SPACE);
  5421. }
  5422. this._appendText(text, style);
  5423. };
  5424. _proto._addBreakNode = function _addBreakNode(node, style) {
  5425. if (!isHTMLBRElement(node)) {
  5426. return;
  5427. }
  5428. this._appendText('\n', style);
  5429. }
  5430. /**
  5431. * Add the content of an HTML img node to the internal state
  5432. */
  5433. ;
  5434. _proto._addImgNode = function _addImgNode(node, style) {
  5435. if (!isHTMLImageElement(node)) {
  5436. return;
  5437. }
  5438. var image = node;
  5439. var entityConfig = {};
  5440. imgAttr.forEach(function (attr) {
  5441. var imageAttribute = image.getAttribute(attr);
  5442. if (imageAttribute) {
  5443. entityConfig[attr] = imageAttribute;
  5444. }
  5445. }); // TODO: T15530363 update this when we remove DraftEntity entirely
  5446. this.currentEntity = this.entityMap.__create('IMAGE', 'IMMUTABLE', entityConfig); // The child text node cannot just have a space or return as content (since
  5447. // we strip those out), unless the image is for presentation only.
  5448. // See https://github.com/facebook/draft-js/issues/231 for some context.
  5449. if (gkx('draftjs_fix_paste_for_img')) {
  5450. if (image.getAttribute('role') !== 'presentation') {
  5451. this._appendText("\uD83D\uDCF7", style);
  5452. }
  5453. } else {
  5454. this._appendText("\uD83D\uDCF7", style);
  5455. }
  5456. this.currentEntity = null;
  5457. }
  5458. /**
  5459. * Add the content of an HTML 'a' node to the internal state. Child nodes
  5460. * (if any) are converted to Block Configs and appended to the provided
  5461. * blockConfig array.
  5462. */
  5463. ;
  5464. _proto._addAnchorNode = function _addAnchorNode(node, blockConfigs, style) {
  5465. // The check has already been made by isValidAnchor but
  5466. // we have to do it again to keep flow happy.
  5467. if (!isHTMLAnchorElement(node)) {
  5468. return;
  5469. }
  5470. var anchor = node;
  5471. var entityConfig = {};
  5472. anchorAttr.forEach(function (attr) {
  5473. var anchorAttribute = anchor.getAttribute(attr);
  5474. if (anchorAttribute) {
  5475. entityConfig[attr] = anchorAttribute;
  5476. }
  5477. });
  5478. entityConfig.url = new URI(anchor.href).toString(); // TODO: T15530363 update this when we remove DraftEntity completely
  5479. this.currentEntity = this.entityMap.__create('LINK', 'MUTABLE', entityConfig || {});
  5480. blockConfigs.push.apply(blockConfigs, this._toBlockConfigs(Array.from(node.childNodes), style));
  5481. this.currentEntity = null;
  5482. }
  5483. /**
  5484. * Walk the BlockConfig tree, compute parent/children/siblings,
  5485. * and generate the corresponding ContentBlockNode
  5486. */
  5487. ;
  5488. _proto._toContentBlocks = function _toContentBlocks(blockConfigs) {
  5489. var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  5490. var l = blockConfigs.length - 1;
  5491. for (var i = 0; i <= l; i++) {
  5492. var config = blockConfigs[i];
  5493. config.parent = parent;
  5494. config.prevSibling = i > 0 ? blockConfigs[i - 1].key : null;
  5495. config.nextSibling = i < l ? blockConfigs[i + 1].key : null;
  5496. config.children = List(config.childConfigs.map(function (child) {
  5497. return child.key;
  5498. }));
  5499. this.contentBlocks.push(new ContentBlockNode(_objectSpread({}, config)));
  5500. this._toContentBlocks(config.childConfigs, config.key);
  5501. }
  5502. }
  5503. /**
  5504. * Remove 'useless' container nodes from the block config hierarchy, by
  5505. * replacing them with their children.
  5506. */
  5507. ;
  5508. _proto._hoistContainersInBlockConfigs = function _hoistContainersInBlockConfigs(blockConfigs) {
  5509. var _this = this;
  5510. var hoisted = List(blockConfigs).flatMap(function (blockConfig) {
  5511. // Don't mess with useful blocks
  5512. if (blockConfig.type !== 'unstyled' || blockConfig.text !== '') {
  5513. return [blockConfig];
  5514. }
  5515. return _this._hoistContainersInBlockConfigs(blockConfig.childConfigs);
  5516. });
  5517. return hoisted;
  5518. } // ***********************************************************************
  5519. // The two methods below are used for backward compatibility when
  5520. // experimentalTreeDataSupport is disabled.
  5521. /**
  5522. * Same as _toContentBlocks but replaces nested blocks by their
  5523. * text content.
  5524. */
  5525. ;
  5526. _proto._toFlatContentBlocks = function _toFlatContentBlocks(blockConfigs) {
  5527. var _this2 = this;
  5528. var cleanConfigs = this._hoistContainersInBlockConfigs(blockConfigs);
  5529. cleanConfigs.forEach(function (config) {
  5530. var _this2$_extractTextFr = _this2._extractTextFromBlockConfigs(config.childConfigs),
  5531. text = _this2$_extractTextFr.text,
  5532. characterList = _this2$_extractTextFr.characterList;
  5533. _this2.contentBlocks.push(new ContentBlock(_objectSpread({}, config, {
  5534. text: config.text + text,
  5535. characterList: config.characterList.concat(characterList)
  5536. })));
  5537. });
  5538. }
  5539. /**
  5540. * Extract the text and the associated inline styles form an
  5541. * array of content block configs.
  5542. */
  5543. ;
  5544. _proto._extractTextFromBlockConfigs = function _extractTextFromBlockConfigs(blockConfigs) {
  5545. var l = blockConfigs.length - 1;
  5546. var text = '';
  5547. var characterList = List();
  5548. for (var i = 0; i <= l; i++) {
  5549. var config = blockConfigs[i];
  5550. text += config.text;
  5551. characterList = characterList.concat(config.characterList);
  5552. if (text !== '' && config.type !== 'unstyled') {
  5553. text += '\n';
  5554. characterList = characterList.push(characterList.last());
  5555. }
  5556. var children = this._extractTextFromBlockConfigs(config.childConfigs);
  5557. text += children.text;
  5558. characterList = characterList.concat(children.characterList);
  5559. }
  5560. return {
  5561. text: text,
  5562. characterList: characterList
  5563. };
  5564. };
  5565. return ContentBlocksBuilder;
  5566. }();
  5567. /**
  5568. * Converts an HTML string to an array of ContentBlocks and an EntityMap
  5569. * suitable to initialize the internal state of a Draftjs component.
  5570. */
  5571. var convertFromHTMLToContentBlocks = function convertFromHTMLToContentBlocks(html) {
  5572. var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML;
  5573. var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap;
  5574. // Be ABSOLUTELY SURE that the dom builder you pass here won't execute
  5575. // arbitrary code in whatever environment you're running this in. For an
  5576. // example of how we try to do this in-browser, see getSafeBodyFromHTML.
  5577. // Remove funky characters from the HTML string
  5578. html = html.trim().replace(REGEX_CR, '').replace(REGEX_NBSP, SPACE).replace(REGEX_CARRIAGE, '').replace(REGEX_ZWS, ''); // Build a DOM tree out of the HTML string
  5579. var safeBody = DOMBuilder(html);
  5580. if (!safeBody) {
  5581. return null;
  5582. } // Build a BlockTypeMap out of the BlockRenderMap
  5583. var blockTypeMap = buildBlockTypeMap(blockRenderMap); // Select the proper block type for the cases where the blockRenderMap
  5584. // uses multiple block types for the same html tag.
  5585. var disambiguate = function disambiguate(tag, wrapper) {
  5586. if (tag === 'li') {
  5587. return wrapper === 'ol' ? 'ordered-list-item' : 'unordered-list-item';
  5588. }
  5589. return null;
  5590. };
  5591. return new ContentBlocksBuilder(blockTypeMap, disambiguate).addDOMNode(safeBody).getContentBlocks();
  5592. };
  5593. module.exports = convertFromHTMLToContentBlocks;
  5594. /***/ }),
  5595. /* 74 */
  5596. /***/ (function(module, exports, __webpack_require__) {
  5597. "use strict";
  5598. /**
  5599. * Copyright (c) Facebook, Inc. and its affiliates.
  5600. *
  5601. * This source code is licensed under the MIT license found in the
  5602. * LICENSE file in the root directory of this source tree.
  5603. *
  5604. * @format
  5605. *
  5606. * @emails oncall+draft_js
  5607. */
  5608. var UserAgent = __webpack_require__(5);
  5609. var invariant = __webpack_require__(1);
  5610. var isOldIE = UserAgent.isBrowser('IE <= 9'); // Provides a dom node that will not execute scripts
  5611. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  5612. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  5613. function getSafeBodyFromHTML(html) {
  5614. var doc;
  5615. var root = null; // Provides a safe context
  5616. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  5617. doc = document.implementation.createHTMLDocument('foo');
  5618. !doc.documentElement ? true ? invariant(false, 'Missing doc.documentElement') : invariant(false) : void 0;
  5619. doc.documentElement.innerHTML = html;
  5620. root = doc.getElementsByTagName('body')[0];
  5621. }
  5622. return root;
  5623. }
  5624. module.exports = getSafeBodyFromHTML;
  5625. /***/ }),
  5626. /* 75 */
  5627. /***/ (function(module, exports, __webpack_require__) {
  5628. "use strict";
  5629. /**
  5630. * Copyright (c) Facebook, Inc. and its affiliates.
  5631. *
  5632. * This source code is licensed under the MIT license found in the
  5633. * LICENSE file in the root directory of this source tree.
  5634. *
  5635. * @format
  5636. *
  5637. * @emails oncall+draft_js
  5638. */
  5639. var DraftModifier = __webpack_require__(3);
  5640. var EditorState = __webpack_require__(2);
  5641. var adjustBlockDepthForContentState = __webpack_require__(158);
  5642. var nullthrows = __webpack_require__(4);
  5643. var RichTextEditorUtil = {
  5644. currentBlockContainsLink: function currentBlockContainsLink(editorState) {
  5645. var selection = editorState.getSelection();
  5646. var contentState = editorState.getCurrentContent();
  5647. var entityMap = contentState.getEntityMap();
  5648. return contentState.getBlockForKey(selection.getAnchorKey()).getCharacterList().slice(selection.getStartOffset(), selection.getEndOffset()).some(function (v) {
  5649. var entity = v.getEntity();
  5650. return !!entity && entityMap.__get(entity).getType() === 'LINK';
  5651. });
  5652. },
  5653. getCurrentBlockType: function getCurrentBlockType(editorState) {
  5654. var selection = editorState.getSelection();
  5655. return editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType();
  5656. },
  5657. getDataObjectForLinkURL: function getDataObjectForLinkURL(uri) {
  5658. return {
  5659. url: uri.toString()
  5660. };
  5661. },
  5662. handleKeyCommand: function handleKeyCommand(editorState, command, eventTimeStamp) {
  5663. switch (command) {
  5664. case 'bold':
  5665. return RichTextEditorUtil.toggleInlineStyle(editorState, 'BOLD');
  5666. case 'italic':
  5667. return RichTextEditorUtil.toggleInlineStyle(editorState, 'ITALIC');
  5668. case 'underline':
  5669. return RichTextEditorUtil.toggleInlineStyle(editorState, 'UNDERLINE');
  5670. case 'code':
  5671. return RichTextEditorUtil.toggleCode(editorState);
  5672. case 'backspace':
  5673. case 'backspace-word':
  5674. case 'backspace-to-start-of-line':
  5675. return RichTextEditorUtil.onBackspace(editorState);
  5676. case 'delete':
  5677. case 'delete-word':
  5678. case 'delete-to-end-of-block':
  5679. return RichTextEditorUtil.onDelete(editorState);
  5680. default:
  5681. // they may have custom editor commands; ignore those
  5682. return null;
  5683. }
  5684. },
  5685. insertSoftNewline: function insertSoftNewline(editorState) {
  5686. var contentState = DraftModifier.insertText(editorState.getCurrentContent(), editorState.getSelection(), '\n', editorState.getCurrentInlineStyle(), null);
  5687. var newEditorState = EditorState.push(editorState, contentState, 'insert-characters');
  5688. return EditorState.forceSelection(newEditorState, contentState.getSelectionAfter());
  5689. },
  5690. /**
  5691. * For collapsed selections at the start of styled blocks, backspace should
  5692. * just remove the existing style.
  5693. */
  5694. onBackspace: function onBackspace(editorState) {
  5695. var selection = editorState.getSelection();
  5696. if (!selection.isCollapsed() || selection.getAnchorOffset() || selection.getFocusOffset()) {
  5697. return null;
  5698. } // First, try to remove a preceding atomic block.
  5699. var content = editorState.getCurrentContent();
  5700. var startKey = selection.getStartKey();
  5701. var blockBefore = content.getBlockBefore(startKey);
  5702. if (blockBefore && blockBefore.getType() === 'atomic') {
  5703. var blockMap = content.getBlockMap()["delete"](blockBefore.getKey());
  5704. var withoutAtomicBlock = content.merge({
  5705. blockMap: blockMap,
  5706. selectionAfter: selection
  5707. });
  5708. if (withoutAtomicBlock !== content) {
  5709. return EditorState.push(editorState, withoutAtomicBlock, 'remove-range');
  5710. }
  5711. } // If that doesn't succeed, try to remove the current block style.
  5712. var withoutBlockStyle = RichTextEditorUtil.tryToRemoveBlockStyle(editorState);
  5713. if (withoutBlockStyle) {
  5714. return EditorState.push(editorState, withoutBlockStyle, 'change-block-type');
  5715. }
  5716. return null;
  5717. },
  5718. onDelete: function onDelete(editorState) {
  5719. var selection = editorState.getSelection();
  5720. if (!selection.isCollapsed()) {
  5721. return null;
  5722. }
  5723. var content = editorState.getCurrentContent();
  5724. var startKey = selection.getStartKey();
  5725. var block = content.getBlockForKey(startKey);
  5726. var length = block.getLength(); // The cursor is somewhere within the text. Behave normally.
  5727. if (selection.getStartOffset() < length) {
  5728. return null;
  5729. }
  5730. var blockAfter = content.getBlockAfter(startKey);
  5731. if (!blockAfter || blockAfter.getType() !== 'atomic') {
  5732. return null;
  5733. }
  5734. var atomicBlockTarget = selection.merge({
  5735. focusKey: blockAfter.getKey(),
  5736. focusOffset: blockAfter.getLength()
  5737. });
  5738. var withoutAtomicBlock = DraftModifier.removeRange(content, atomicBlockTarget, 'forward');
  5739. if (withoutAtomicBlock !== content) {
  5740. return EditorState.push(editorState, withoutAtomicBlock, 'remove-range');
  5741. }
  5742. return null;
  5743. },
  5744. onTab: function onTab(event, editorState, maxDepth) {
  5745. var selection = editorState.getSelection();
  5746. var key = selection.getAnchorKey();
  5747. if (key !== selection.getFocusKey()) {
  5748. return editorState;
  5749. }
  5750. var content = editorState.getCurrentContent();
  5751. var block = content.getBlockForKey(key);
  5752. var type = block.getType();
  5753. if (type !== 'unordered-list-item' && type !== 'ordered-list-item') {
  5754. return editorState;
  5755. }
  5756. event.preventDefault();
  5757. var depth = block.getDepth();
  5758. if (!event.shiftKey && depth === maxDepth) {
  5759. return editorState;
  5760. }
  5761. var withAdjustment = adjustBlockDepthForContentState(content, selection, event.shiftKey ? -1 : 1, maxDepth);
  5762. return EditorState.push(editorState, withAdjustment, 'adjust-depth');
  5763. },
  5764. toggleBlockType: function toggleBlockType(editorState, blockType) {
  5765. var selection = editorState.getSelection();
  5766. var startKey = selection.getStartKey();
  5767. var endKey = selection.getEndKey();
  5768. var content = editorState.getCurrentContent();
  5769. var target = selection; // Triple-click can lead to a selection that includes offset 0 of the
  5770. // following block. The `SelectionState` for this case is accurate, but
  5771. // we should avoid toggling block type for the trailing block because it
  5772. // is a confusing interaction.
  5773. if (startKey !== endKey && selection.getEndOffset() === 0) {
  5774. var blockBefore = nullthrows(content.getBlockBefore(endKey));
  5775. endKey = blockBefore.getKey();
  5776. target = target.merge({
  5777. anchorKey: startKey,
  5778. anchorOffset: selection.getStartOffset(),
  5779. focusKey: endKey,
  5780. focusOffset: blockBefore.getLength(),
  5781. isBackward: false
  5782. });
  5783. }
  5784. var hasAtomicBlock = content.getBlockMap().skipWhile(function (_, k) {
  5785. return k !== startKey;
  5786. }).reverse().skipWhile(function (_, k) {
  5787. return k !== endKey;
  5788. }).some(function (v) {
  5789. return v.getType() === 'atomic';
  5790. });
  5791. if (hasAtomicBlock) {
  5792. return editorState;
  5793. }
  5794. var typeToSet = content.getBlockForKey(startKey).getType() === blockType ? 'unstyled' : blockType;
  5795. return EditorState.push(editorState, DraftModifier.setBlockType(content, target, typeToSet), 'change-block-type');
  5796. },
  5797. toggleCode: function toggleCode(editorState) {
  5798. var selection = editorState.getSelection();
  5799. var anchorKey = selection.getAnchorKey();
  5800. var focusKey = selection.getFocusKey();
  5801. if (selection.isCollapsed() || anchorKey !== focusKey) {
  5802. return RichTextEditorUtil.toggleBlockType(editorState, 'code-block');
  5803. }
  5804. return RichTextEditorUtil.toggleInlineStyle(editorState, 'CODE');
  5805. },
  5806. /**
  5807. * Toggle the specified inline style for the selection. If the
  5808. * user's selection is collapsed, apply or remove the style for the
  5809. * internal state. If it is not collapsed, apply the change directly
  5810. * to the document state.
  5811. */
  5812. toggleInlineStyle: function toggleInlineStyle(editorState, inlineStyle) {
  5813. var selection = editorState.getSelection();
  5814. var currentStyle = editorState.getCurrentInlineStyle(); // If the selection is collapsed, toggle the specified style on or off and
  5815. // set the result as the new inline style override. This will then be
  5816. // used as the inline style for the next character to be inserted.
  5817. if (selection.isCollapsed()) {
  5818. return EditorState.setInlineStyleOverride(editorState, currentStyle.has(inlineStyle) ? currentStyle.remove(inlineStyle) : currentStyle.add(inlineStyle));
  5819. } // If characters are selected, immediately apply or remove the
  5820. // inline style on the document state itself.
  5821. var content = editorState.getCurrentContent();
  5822. var newContent; // If the style is already present for the selection range, remove it.
  5823. // Otherwise, apply it.
  5824. if (currentStyle.has(inlineStyle)) {
  5825. newContent = DraftModifier.removeInlineStyle(content, selection, inlineStyle);
  5826. } else {
  5827. newContent = DraftModifier.applyInlineStyle(content, selection, inlineStyle);
  5828. }
  5829. return EditorState.push(editorState, newContent, 'change-inline-style');
  5830. },
  5831. toggleLink: function toggleLink(editorState, targetSelection, entityKey) {
  5832. var withoutLink = DraftModifier.applyEntity(editorState.getCurrentContent(), targetSelection, entityKey);
  5833. return EditorState.push(editorState, withoutLink, 'apply-entity');
  5834. },
  5835. /**
  5836. * When a collapsed cursor is at the start of a styled block, changes block
  5837. * type to 'unstyled'. Returns null if selection does not meet that criteria.
  5838. */
  5839. tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) {
  5840. var selection = editorState.getSelection();
  5841. var offset = selection.getAnchorOffset();
  5842. if (selection.isCollapsed() && offset === 0) {
  5843. var key = selection.getAnchorKey();
  5844. var content = editorState.getCurrentContent();
  5845. var block = content.getBlockForKey(key);
  5846. var type = block.getType();
  5847. var blockBefore = content.getBlockBefore(key);
  5848. if (type === 'code-block' && blockBefore && blockBefore.getType() === 'code-block' && blockBefore.getLength() !== 0) {
  5849. return null;
  5850. }
  5851. if (type !== 'unstyled') {
  5852. return DraftModifier.setBlockType(content, selection, 'unstyled');
  5853. }
  5854. }
  5855. return null;
  5856. }
  5857. };
  5858. module.exports = RichTextEditorUtil;
  5859. /***/ }),
  5860. /* 76 */
  5861. /***/ (function(module, exports, __webpack_require__) {
  5862. "use strict";
  5863. /**
  5864. * Copyright (c) Facebook, Inc. and its affiliates.
  5865. *
  5866. * This source code is licensed under the MIT license found in the
  5867. * LICENSE file in the root directory of this source tree.
  5868. *
  5869. * @format
  5870. *
  5871. * @emails oncall+draft_js
  5872. */
  5873. var KeyBindingUtil = __webpack_require__(40);
  5874. var Keys = __webpack_require__(28);
  5875. var UserAgent = __webpack_require__(5);
  5876. var isOSX = UserAgent.isPlatform('Mac OS X'); // Firefox on OSX had a bug resulting in navigation instead of cursor movement.
  5877. // This bug was fixed in Firefox 29. Feature detection is virtually impossible
  5878. // so we just check the version number. See #342765.
  5879. var shouldFixFirefoxMovement = isOSX && UserAgent.isBrowser('Firefox < 29');
  5880. var hasCommandModifier = KeyBindingUtil.hasCommandModifier,
  5881. isCtrlKeyCommand = KeyBindingUtil.isCtrlKeyCommand;
  5882. function shouldRemoveWord(e) {
  5883. return isOSX && e.altKey || isCtrlKeyCommand(e);
  5884. }
  5885. /**
  5886. * Get the appropriate undo/redo command for a Z key command.
  5887. */
  5888. function getZCommand(e) {
  5889. if (!hasCommandModifier(e)) {
  5890. return null;
  5891. }
  5892. return e.shiftKey ? 'redo' : 'undo';
  5893. }
  5894. function getDeleteCommand(e) {
  5895. // Allow default "cut" behavior for PCs on Shift + Delete.
  5896. if (!isOSX && e.shiftKey) {
  5897. return null;
  5898. }
  5899. return shouldRemoveWord(e) ? 'delete-word' : 'delete';
  5900. }
  5901. function getBackspaceCommand(e) {
  5902. if (hasCommandModifier(e) && isOSX) {
  5903. return 'backspace-to-start-of-line';
  5904. }
  5905. return shouldRemoveWord(e) ? 'backspace-word' : 'backspace';
  5906. }
  5907. /**
  5908. * Retrieve a bound key command for the given event.
  5909. */
  5910. function getDefaultKeyBinding(e) {
  5911. switch (e.keyCode) {
  5912. case 66:
  5913. // B
  5914. return hasCommandModifier(e) ? 'bold' : null;
  5915. case 68:
  5916. // D
  5917. return isCtrlKeyCommand(e) ? 'delete' : null;
  5918. case 72:
  5919. // H
  5920. return isCtrlKeyCommand(e) ? 'backspace' : null;
  5921. case 73:
  5922. // I
  5923. return hasCommandModifier(e) ? 'italic' : null;
  5924. case 74:
  5925. // J
  5926. return hasCommandModifier(e) ? 'code' : null;
  5927. case 75:
  5928. // K
  5929. return isOSX && isCtrlKeyCommand(e) ? 'secondary-cut' : null;
  5930. case 77:
  5931. // M
  5932. return isCtrlKeyCommand(e) ? 'split-block' : null;
  5933. case 79:
  5934. // O
  5935. return isCtrlKeyCommand(e) ? 'split-block' : null;
  5936. case 84:
  5937. // T
  5938. return isOSX && isCtrlKeyCommand(e) ? 'transpose-characters' : null;
  5939. case 85:
  5940. // U
  5941. return hasCommandModifier(e) ? 'underline' : null;
  5942. case 87:
  5943. // W
  5944. return isOSX && isCtrlKeyCommand(e) ? 'backspace-word' : null;
  5945. case 89:
  5946. // Y
  5947. if (isCtrlKeyCommand(e)) {
  5948. return isOSX ? 'secondary-paste' : 'redo';
  5949. }
  5950. return null;
  5951. case 90:
  5952. // Z
  5953. return getZCommand(e) || null;
  5954. case Keys.RETURN:
  5955. return 'split-block';
  5956. case Keys.DELETE:
  5957. return getDeleteCommand(e);
  5958. case Keys.BACKSPACE:
  5959. return getBackspaceCommand(e);
  5960. // LEFT/RIGHT handlers serve as a workaround for a Firefox bug.
  5961. case Keys.LEFT:
  5962. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-start-of-block' : null;
  5963. case Keys.RIGHT:
  5964. return shouldFixFirefoxMovement && hasCommandModifier(e) ? 'move-selection-to-end-of-block' : null;
  5965. default:
  5966. return null;
  5967. }
  5968. }
  5969. module.exports = getDefaultKeyBinding;
  5970. /***/ }),
  5971. /* 77 */
  5972. /***/ (function(module, exports, __webpack_require__) {
  5973. "use strict";
  5974. /**
  5975. * Copyright (c) Facebook, Inc. and its affiliates.
  5976. *
  5977. * This source code is licensed under the MIT license found in the
  5978. * LICENSE file in the root directory of this source tree.
  5979. *
  5980. * @format
  5981. *
  5982. * @emails oncall+draft_js
  5983. */
  5984. var DraftStringKey = {
  5985. stringify: function stringify(key) {
  5986. return '_' + String(key);
  5987. },
  5988. unstringify: function unstringify(key) {
  5989. return key.slice(1);
  5990. }
  5991. };
  5992. module.exports = DraftStringKey;
  5993. /***/ }),
  5994. /* 78 */
  5995. /***/ (function(module, exports, __webpack_require__) {
  5996. "use strict";
  5997. /**
  5998. * Copyright (c) Facebook, Inc. and its affiliates.
  5999. *
  6000. * This source code is licensed under the MIT license found in the
  6001. * LICENSE file in the root directory of this source tree.
  6002. *
  6003. * @format
  6004. *
  6005. */
  6006. var AtomicBlockUtils = __webpack_require__(79);
  6007. var BlockMapBuilder = __webpack_require__(17);
  6008. var CharacterMetadata = __webpack_require__(6);
  6009. var CompositeDraftDecorator = __webpack_require__(94);
  6010. var ContentBlock = __webpack_require__(12);
  6011. var ContentState = __webpack_require__(32);
  6012. var DefaultDraftBlockRenderMap = __webpack_require__(34);
  6013. var DefaultDraftInlineStyle = __webpack_require__(48);
  6014. var DraftEditor = __webpack_require__(95);
  6015. var DraftEditorBlock = __webpack_require__(64);
  6016. var DraftEntity = __webpack_require__(22);
  6017. var DraftModifier = __webpack_require__(3);
  6018. var DraftEntityInstance = __webpack_require__(46);
  6019. var EditorState = __webpack_require__(2);
  6020. var KeyBindingUtil = __webpack_require__(40);
  6021. var RawDraftContentState = __webpack_require__(163);
  6022. var RichTextEditorUtil = __webpack_require__(75);
  6023. var SelectionState = __webpack_require__(23);
  6024. var convertFromDraftStateToRaw = __webpack_require__(164);
  6025. var convertFromRawToDraftState = __webpack_require__(167);
  6026. var generateRandomKey = __webpack_require__(9);
  6027. var getDefaultKeyBinding = __webpack_require__(76);
  6028. var getVisibleSelectionRect = __webpack_require__(173);
  6029. var convertFromHTML = __webpack_require__(73);
  6030. var DraftPublic = {
  6031. Editor: DraftEditor,
  6032. EditorBlock: DraftEditorBlock,
  6033. EditorState: EditorState,
  6034. CompositeDecorator: CompositeDraftDecorator,
  6035. Entity: DraftEntity,
  6036. EntityInstance: DraftEntityInstance,
  6037. BlockMapBuilder: BlockMapBuilder,
  6038. CharacterMetadata: CharacterMetadata,
  6039. ContentBlock: ContentBlock,
  6040. ContentState: ContentState,
  6041. RawDraftContentState: RawDraftContentState,
  6042. SelectionState: SelectionState,
  6043. AtomicBlockUtils: AtomicBlockUtils,
  6044. KeyBindingUtil: KeyBindingUtil,
  6045. Modifier: DraftModifier,
  6046. RichUtils: RichTextEditorUtil,
  6047. DefaultDraftBlockRenderMap: DefaultDraftBlockRenderMap,
  6048. DefaultDraftInlineStyle: DefaultDraftInlineStyle,
  6049. convertFromHTML: convertFromHTML,
  6050. convertFromRaw: convertFromRawToDraftState,
  6051. convertToRaw: convertFromDraftStateToRaw,
  6052. genKey: generateRandomKey,
  6053. getDefaultKeyBinding: getDefaultKeyBinding,
  6054. getVisibleSelectionRect: getVisibleSelectionRect
  6055. };
  6056. module.exports = DraftPublic;
  6057. /***/ }),
  6058. /* 79 */
  6059. /***/ (function(module, exports, __webpack_require__) {
  6060. "use strict";
  6061. /**
  6062. * Copyright (c) Facebook, Inc. and its affiliates.
  6063. *
  6064. * This source code is licensed under the MIT license found in the
  6065. * LICENSE file in the root directory of this source tree.
  6066. *
  6067. * @format
  6068. *
  6069. * @emails oncall+draft_js
  6070. */
  6071. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  6072. 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; }
  6073. var BlockMapBuilder = __webpack_require__(17);
  6074. var CharacterMetadata = __webpack_require__(6);
  6075. var ContentBlock = __webpack_require__(12);
  6076. var ContentBlockNode = __webpack_require__(7);
  6077. var DraftModifier = __webpack_require__(3);
  6078. var EditorState = __webpack_require__(2);
  6079. var generateRandomKey = __webpack_require__(9);
  6080. var gkx = __webpack_require__(11);
  6081. var Immutable = __webpack_require__(0);
  6082. var moveBlockInContentState = __webpack_require__(93);
  6083. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  6084. var ContentBlockRecord = experimentalTreeDataSupport ? ContentBlockNode : ContentBlock;
  6085. var List = Immutable.List,
  6086. Repeat = Immutable.Repeat;
  6087. var AtomicBlockUtils = {
  6088. insertAtomicBlock: function insertAtomicBlock(editorState, entityKey, character) {
  6089. var contentState = editorState.getCurrentContent();
  6090. var selectionState = editorState.getSelection();
  6091. var afterRemoval = DraftModifier.removeRange(contentState, selectionState, 'backward');
  6092. var targetSelection = afterRemoval.getSelectionAfter();
  6093. var afterSplit = DraftModifier.splitBlock(afterRemoval, targetSelection);
  6094. var insertionTarget = afterSplit.getSelectionAfter();
  6095. var asAtomicBlock = DraftModifier.setBlockType(afterSplit, insertionTarget, 'atomic');
  6096. var charData = CharacterMetadata.create({
  6097. entity: entityKey
  6098. });
  6099. var atomicBlockConfig = {
  6100. key: generateRandomKey(),
  6101. type: 'atomic',
  6102. text: character,
  6103. characterList: List(Repeat(charData, character.length))
  6104. };
  6105. var atomicDividerBlockConfig = {
  6106. key: generateRandomKey(),
  6107. type: 'unstyled'
  6108. };
  6109. if (experimentalTreeDataSupport) {
  6110. atomicBlockConfig = _objectSpread({}, atomicBlockConfig, {
  6111. nextSibling: atomicDividerBlockConfig.key
  6112. });
  6113. atomicDividerBlockConfig = _objectSpread({}, atomicDividerBlockConfig, {
  6114. prevSibling: atomicBlockConfig.key
  6115. });
  6116. }
  6117. var fragmentArray = [new ContentBlockRecord(atomicBlockConfig), new ContentBlockRecord(atomicDividerBlockConfig)];
  6118. var fragment = BlockMapBuilder.createFromArray(fragmentArray);
  6119. var withAtomicBlock = DraftModifier.replaceWithFragment(asAtomicBlock, insertionTarget, fragment);
  6120. var newContent = withAtomicBlock.merge({
  6121. selectionBefore: selectionState,
  6122. selectionAfter: withAtomicBlock.getSelectionAfter().set('hasFocus', true)
  6123. });
  6124. return EditorState.push(editorState, newContent, 'insert-fragment');
  6125. },
  6126. moveAtomicBlock: function moveAtomicBlock(editorState, atomicBlock, targetRange, insertionMode) {
  6127. var contentState = editorState.getCurrentContent();
  6128. var selectionState = editorState.getSelection();
  6129. var withMovedAtomicBlock;
  6130. if (insertionMode === 'before' || insertionMode === 'after') {
  6131. var targetBlock = contentState.getBlockForKey(insertionMode === 'before' ? targetRange.getStartKey() : targetRange.getEndKey());
  6132. withMovedAtomicBlock = moveBlockInContentState(contentState, atomicBlock, targetBlock, insertionMode);
  6133. } else {
  6134. var afterRemoval = DraftModifier.removeRange(contentState, targetRange, 'backward');
  6135. var selectionAfterRemoval = afterRemoval.getSelectionAfter();
  6136. var _targetBlock = afterRemoval.getBlockForKey(selectionAfterRemoval.getFocusKey());
  6137. if (selectionAfterRemoval.getStartOffset() === 0) {
  6138. withMovedAtomicBlock = moveBlockInContentState(afterRemoval, atomicBlock, _targetBlock, 'before');
  6139. } else if (selectionAfterRemoval.getEndOffset() === _targetBlock.getLength()) {
  6140. withMovedAtomicBlock = moveBlockInContentState(afterRemoval, atomicBlock, _targetBlock, 'after');
  6141. } else {
  6142. var afterSplit = DraftModifier.splitBlock(afterRemoval, selectionAfterRemoval);
  6143. var selectionAfterSplit = afterSplit.getSelectionAfter();
  6144. var _targetBlock2 = afterSplit.getBlockForKey(selectionAfterSplit.getFocusKey());
  6145. withMovedAtomicBlock = moveBlockInContentState(afterSplit, atomicBlock, _targetBlock2, 'before');
  6146. }
  6147. }
  6148. var newContent = withMovedAtomicBlock.merge({
  6149. selectionBefore: selectionState,
  6150. selectionAfter: withMovedAtomicBlock.getSelectionAfter().set('hasFocus', true)
  6151. });
  6152. return EditorState.push(editorState, newContent, 'move-block');
  6153. }
  6154. };
  6155. module.exports = AtomicBlockUtils;
  6156. /***/ }),
  6157. /* 80 */
  6158. /***/ (function(module, exports, __webpack_require__) {
  6159. "use strict";
  6160. /**
  6161. * Copyright (c) Facebook, Inc. and its affiliates.
  6162. *
  6163. * This source code is licensed under the MIT license found in the
  6164. * LICENSE file in the root directory of this source tree.
  6165. *
  6166. * @format
  6167. *
  6168. * @emails oncall+draft_js
  6169. */
  6170. var CharacterMetadata = __webpack_require__(6);
  6171. var _require = __webpack_require__(0),
  6172. Map = _require.Map;
  6173. var ContentStateInlineStyle = {
  6174. add: function add(contentState, selectionState, inlineStyle) {
  6175. return modifyInlineStyle(contentState, selectionState, inlineStyle, true);
  6176. },
  6177. remove: function remove(contentState, selectionState, inlineStyle) {
  6178. return modifyInlineStyle(contentState, selectionState, inlineStyle, false);
  6179. }
  6180. };
  6181. function modifyInlineStyle(contentState, selectionState, inlineStyle, addOrRemove) {
  6182. var blockMap = contentState.getBlockMap();
  6183. var startKey = selectionState.getStartKey();
  6184. var startOffset = selectionState.getStartOffset();
  6185. var endKey = selectionState.getEndKey();
  6186. var endOffset = selectionState.getEndOffset();
  6187. var newBlocks = blockMap.skipUntil(function (_, k) {
  6188. return k === startKey;
  6189. }).takeUntil(function (_, k) {
  6190. return k === endKey;
  6191. }).concat(Map([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  6192. var sliceStart;
  6193. var sliceEnd;
  6194. if (startKey === endKey) {
  6195. sliceStart = startOffset;
  6196. sliceEnd = endOffset;
  6197. } else {
  6198. sliceStart = blockKey === startKey ? startOffset : 0;
  6199. sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  6200. }
  6201. var chars = block.getCharacterList();
  6202. var current;
  6203. while (sliceStart < sliceEnd) {
  6204. current = chars.get(sliceStart);
  6205. chars = chars.set(sliceStart, addOrRemove ? CharacterMetadata.applyStyle(current, inlineStyle) : CharacterMetadata.removeStyle(current, inlineStyle));
  6206. sliceStart++;
  6207. }
  6208. return block.set('characterList', chars);
  6209. });
  6210. return contentState.merge({
  6211. blockMap: blockMap.merge(newBlocks),
  6212. selectionBefore: selectionState,
  6213. selectionAfter: selectionState
  6214. });
  6215. }
  6216. module.exports = ContentStateInlineStyle;
  6217. /***/ }),
  6218. /* 81 */
  6219. /***/ (function(module, exports, __webpack_require__) {
  6220. "use strict";
  6221. /**
  6222. * Copyright (c) Facebook, Inc. and its affiliates.
  6223. *
  6224. * This source code is licensed under the MIT license found in the
  6225. * LICENSE file in the root directory of this source tree.
  6226. *
  6227. * @format
  6228. *
  6229. * @emails oncall+draft_js
  6230. */
  6231. var applyEntityToContentBlock = __webpack_require__(82);
  6232. var Immutable = __webpack_require__(0);
  6233. function applyEntityToContentState(contentState, selectionState, entityKey) {
  6234. var blockMap = contentState.getBlockMap();
  6235. var startKey = selectionState.getStartKey();
  6236. var startOffset = selectionState.getStartOffset();
  6237. var endKey = selectionState.getEndKey();
  6238. var endOffset = selectionState.getEndOffset();
  6239. var newBlocks = blockMap.skipUntil(function (_, k) {
  6240. return k === startKey;
  6241. }).takeUntil(function (_, k) {
  6242. return k === endKey;
  6243. }).toOrderedMap().merge(Immutable.OrderedMap([[endKey, blockMap.get(endKey)]])).map(function (block, blockKey) {
  6244. var sliceStart = blockKey === startKey ? startOffset : 0;
  6245. var sliceEnd = blockKey === endKey ? endOffset : block.getLength();
  6246. return applyEntityToContentBlock(block, sliceStart, sliceEnd, entityKey);
  6247. });
  6248. return contentState.merge({
  6249. blockMap: blockMap.merge(newBlocks),
  6250. selectionBefore: selectionState,
  6251. selectionAfter: selectionState
  6252. });
  6253. }
  6254. module.exports = applyEntityToContentState;
  6255. /***/ }),
  6256. /* 82 */
  6257. /***/ (function(module, exports, __webpack_require__) {
  6258. "use strict";
  6259. /**
  6260. * Copyright (c) Facebook, Inc. and its affiliates.
  6261. *
  6262. * This source code is licensed under the MIT license found in the
  6263. * LICENSE file in the root directory of this source tree.
  6264. *
  6265. * @format
  6266. *
  6267. * @emails oncall+draft_js
  6268. */
  6269. var CharacterMetadata = __webpack_require__(6);
  6270. function applyEntityToContentBlock(contentBlock, startArg, end, entityKey) {
  6271. var start = startArg;
  6272. var characterList = contentBlock.getCharacterList();
  6273. while (start < end) {
  6274. characterList = characterList.set(start, CharacterMetadata.applyEntity(characterList.get(start), entityKey));
  6275. start++;
  6276. }
  6277. return contentBlock.set('characterList', characterList);
  6278. }
  6279. module.exports = applyEntityToContentBlock;
  6280. /***/ }),
  6281. /* 83 */
  6282. /***/ (function(module, exports, __webpack_require__) {
  6283. "use strict";
  6284. /**
  6285. * Copyright (c) Facebook, Inc. and its affiliates.
  6286. *
  6287. * This source code is licensed under the MIT license found in the
  6288. * LICENSE file in the root directory of this source tree.
  6289. *
  6290. * @format
  6291. *
  6292. * @emails oncall+draft_js
  6293. */
  6294. var DraftEntitySegments = __webpack_require__(84);
  6295. var getRangesForDraftEntity = __webpack_require__(85);
  6296. var invariant = __webpack_require__(1);
  6297. /**
  6298. * Given a SelectionState and a removal direction, determine the entire range
  6299. * that should be removed from a ContentState. This is based on any entities
  6300. * within the target, with their `mutability` values taken into account.
  6301. *
  6302. * For instance, if we are attempting to remove part of an "immutable" entity
  6303. * range, the entire entity must be removed. The returned `SelectionState`
  6304. * will be adjusted accordingly.
  6305. */
  6306. function getCharacterRemovalRange(entityMap, startBlock, endBlock, selectionState, direction) {
  6307. var start = selectionState.getStartOffset();
  6308. var end = selectionState.getEndOffset();
  6309. var startEntityKey = startBlock.getEntityAt(start);
  6310. var endEntityKey = endBlock.getEntityAt(end - 1);
  6311. if (!startEntityKey && !endEntityKey) {
  6312. return selectionState;
  6313. }
  6314. var newSelectionState = selectionState;
  6315. if (startEntityKey && startEntityKey === endEntityKey) {
  6316. newSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, true, true);
  6317. } else if (startEntityKey && endEntityKey) {
  6318. var startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  6319. var endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  6320. newSelectionState = newSelectionState.merge({
  6321. anchorOffset: startSelectionState.getAnchorOffset(),
  6322. focusOffset: endSelectionState.getFocusOffset(),
  6323. isBackward: false
  6324. });
  6325. } else if (startEntityKey) {
  6326. var _startSelectionState = getEntityRemovalRange(entityMap, startBlock, newSelectionState, direction, startEntityKey, false, true);
  6327. newSelectionState = newSelectionState.merge({
  6328. anchorOffset: _startSelectionState.getStartOffset(),
  6329. isBackward: false
  6330. });
  6331. } else if (endEntityKey) {
  6332. var _endSelectionState = getEntityRemovalRange(entityMap, endBlock, newSelectionState, direction, endEntityKey, false, false);
  6333. newSelectionState = newSelectionState.merge({
  6334. focusOffset: _endSelectionState.getEndOffset(),
  6335. isBackward: false
  6336. });
  6337. }
  6338. return newSelectionState;
  6339. }
  6340. function getEntityRemovalRange(entityMap, block, selectionState, direction, entityKey, isEntireSelectionWithinEntity, isEntityAtStart) {
  6341. var start = selectionState.getStartOffset();
  6342. var end = selectionState.getEndOffset();
  6343. var entity = entityMap.__get(entityKey);
  6344. var mutability = entity.getMutability();
  6345. var sideToConsider = isEntityAtStart ? start : end; // `MUTABLE` entities can just have the specified range of text removed
  6346. // directly. No adjustments are needed.
  6347. if (mutability === 'MUTABLE') {
  6348. return selectionState;
  6349. } // Find the entity range that overlaps with our removal range.
  6350. var entityRanges = getRangesForDraftEntity(block, entityKey).filter(function (range) {
  6351. return sideToConsider <= range.end && sideToConsider >= range.start;
  6352. });
  6353. !(entityRanges.length == 1) ? true ? invariant(false, 'There should only be one entity range within this removal range.') : invariant(false) : void 0;
  6354. var entityRange = entityRanges[0]; // For `IMMUTABLE` entity types, we will remove the entire entity range.
  6355. if (mutability === 'IMMUTABLE') {
  6356. return selectionState.merge({
  6357. anchorOffset: entityRange.start,
  6358. focusOffset: entityRange.end,
  6359. isBackward: false
  6360. });
  6361. } // For `SEGMENTED` entity types, determine the appropriate segment to
  6362. // remove.
  6363. if (!isEntireSelectionWithinEntity) {
  6364. if (isEntityAtStart) {
  6365. end = entityRange.end;
  6366. } else {
  6367. start = entityRange.start;
  6368. }
  6369. }
  6370. var removalRange = DraftEntitySegments.getRemovalRange(start, end, block.getText().slice(entityRange.start, entityRange.end), entityRange.start, direction);
  6371. return selectionState.merge({
  6372. anchorOffset: removalRange.start,
  6373. focusOffset: removalRange.end,
  6374. isBackward: false
  6375. });
  6376. }
  6377. module.exports = getCharacterRemovalRange;
  6378. /***/ }),
  6379. /* 84 */
  6380. /***/ (function(module, exports, __webpack_require__) {
  6381. "use strict";
  6382. /**
  6383. * Copyright (c) Facebook, Inc. and its affiliates.
  6384. *
  6385. * This source code is licensed under the MIT license found in the
  6386. * LICENSE file in the root directory of this source tree.
  6387. *
  6388. * @format
  6389. *
  6390. * @emails oncall+draft_js
  6391. */
  6392. /**
  6393. * Identify the range to delete from a segmented entity.
  6394. *
  6395. * Rules:
  6396. *
  6397. * Example: 'John F. Kennedy'
  6398. *
  6399. * - Deletion from within any non-whitespace (i.e. ['John', 'F.', 'Kennedy'])
  6400. * will return the range of that text.
  6401. *
  6402. * 'John F. Kennedy' -> 'John F.'
  6403. * ^
  6404. *
  6405. * - Forward deletion of whitespace will remove the following section:
  6406. *
  6407. * 'John F. Kennedy' -> 'John Kennedy'
  6408. * ^
  6409. *
  6410. * - Backward deletion of whitespace will remove the previous section:
  6411. *
  6412. * 'John F. Kennedy' -> 'F. Kennedy'
  6413. * ^
  6414. */
  6415. var DraftEntitySegments = {
  6416. getRemovalRange: function getRemovalRange(selectionStart, selectionEnd, text, entityStart, direction) {
  6417. var segments = text.split(' ');
  6418. segments = segments.map(function (
  6419. /*string*/
  6420. segment,
  6421. /*number*/
  6422. ii) {
  6423. if (direction === 'forward') {
  6424. if (ii > 0) {
  6425. return ' ' + segment;
  6426. }
  6427. } else if (ii < segments.length - 1) {
  6428. return segment + ' ';
  6429. }
  6430. return segment;
  6431. });
  6432. var segmentStart = entityStart;
  6433. var segmentEnd;
  6434. var segment;
  6435. var removalStart = null;
  6436. var removalEnd = null;
  6437. for (var jj = 0; jj < segments.length; jj++) {
  6438. segment = segments[jj];
  6439. segmentEnd = segmentStart + segment.length; // Our selection overlaps this segment.
  6440. if (selectionStart < segmentEnd && segmentStart < selectionEnd) {
  6441. if (removalStart !== null) {
  6442. removalEnd = segmentEnd;
  6443. } else {
  6444. removalStart = segmentStart;
  6445. removalEnd = segmentEnd;
  6446. }
  6447. } else if (removalStart !== null) {
  6448. break;
  6449. }
  6450. segmentStart = segmentEnd;
  6451. }
  6452. var entityEnd = entityStart + text.length;
  6453. var atStart = removalStart === entityStart;
  6454. var atEnd = removalEnd === entityEnd;
  6455. if (!atStart && atEnd || atStart && !atEnd) {
  6456. if (direction === 'forward') {
  6457. if (removalEnd !== entityEnd) {
  6458. removalEnd++;
  6459. }
  6460. } else if (removalStart !== entityStart) {
  6461. removalStart--;
  6462. }
  6463. }
  6464. return {
  6465. start: removalStart,
  6466. end: removalEnd
  6467. };
  6468. }
  6469. };
  6470. module.exports = DraftEntitySegments;
  6471. /***/ }),
  6472. /* 85 */
  6473. /***/ (function(module, exports, __webpack_require__) {
  6474. "use strict";
  6475. /**
  6476. * Copyright (c) Facebook, Inc. and its affiliates.
  6477. *
  6478. * This source code is licensed under the MIT license found in the
  6479. * LICENSE file in the root directory of this source tree.
  6480. *
  6481. * @format
  6482. *
  6483. * @emails oncall+draft_js
  6484. */
  6485. var invariant = __webpack_require__(1);
  6486. /**
  6487. * Obtain the start and end positions of the range that has the
  6488. * specified entity applied to it.
  6489. *
  6490. * Entity keys are applied only to contiguous stretches of text, so this
  6491. * method searches for the first instance of the entity key and returns
  6492. * the subsequent range.
  6493. */
  6494. function getRangesForDraftEntity(block, key) {
  6495. var ranges = [];
  6496. block.findEntityRanges(function (c) {
  6497. return c.getEntity() === key;
  6498. }, function (start, end) {
  6499. ranges.push({
  6500. start: start,
  6501. end: end
  6502. });
  6503. });
  6504. !!!ranges.length ? true ? invariant(false, 'Entity key not found in this range.') : invariant(false) : void 0;
  6505. return ranges;
  6506. }
  6507. module.exports = getRangesForDraftEntity;
  6508. /***/ }),
  6509. /* 86 */
  6510. /***/ (function(module, exports, __webpack_require__) {
  6511. "use strict";
  6512. /**
  6513. * Copyright (c) Facebook, Inc. and its affiliates.
  6514. *
  6515. * This source code is licensed under the MIT license found in the
  6516. * LICENSE file in the root directory of this source tree.
  6517. *
  6518. * @format
  6519. *
  6520. * @emails oncall+draft_js
  6521. */
  6522. var BlockMapBuilder = __webpack_require__(17);
  6523. var ContentBlockNode = __webpack_require__(7);
  6524. var Immutable = __webpack_require__(0);
  6525. var insertIntoList = __webpack_require__(43);
  6526. var invariant = __webpack_require__(1);
  6527. var randomizeBlockMapKeys = __webpack_require__(41);
  6528. var List = Immutable.List;
  6529. var updateExistingBlock = function updateExistingBlock(contentState, selectionState, blockMap, fragmentBlock, targetKey, targetOffset) {
  6530. var mergeBlockData = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'REPLACE_WITH_NEW_DATA';
  6531. var targetBlock = blockMap.get(targetKey);
  6532. var text = targetBlock.getText();
  6533. var chars = targetBlock.getCharacterList();
  6534. var finalKey = targetKey;
  6535. var finalOffset = targetOffset + fragmentBlock.getText().length;
  6536. var data = null;
  6537. switch (mergeBlockData) {
  6538. case 'MERGE_OLD_DATA_TO_NEW_DATA':
  6539. data = fragmentBlock.getData().merge(targetBlock.getData());
  6540. break;
  6541. case 'REPLACE_WITH_NEW_DATA':
  6542. data = fragmentBlock.getData();
  6543. break;
  6544. }
  6545. var newBlock = targetBlock.merge({
  6546. text: text.slice(0, targetOffset) + fragmentBlock.getText() + text.slice(targetOffset),
  6547. characterList: insertIntoList(chars, fragmentBlock.getCharacterList(), targetOffset),
  6548. data: data
  6549. });
  6550. return contentState.merge({
  6551. blockMap: blockMap.set(targetKey, newBlock),
  6552. selectionBefore: selectionState,
  6553. selectionAfter: selectionState.merge({
  6554. anchorKey: finalKey,
  6555. anchorOffset: finalOffset,
  6556. focusKey: finalKey,
  6557. focusOffset: finalOffset,
  6558. isBackward: false
  6559. })
  6560. });
  6561. };
  6562. /**
  6563. * Appends text/characterList from the fragment first block to
  6564. * target block.
  6565. */
  6566. var updateHead = function updateHead(block, targetOffset, fragment) {
  6567. var text = block.getText();
  6568. var chars = block.getCharacterList(); // Modify head portion of block.
  6569. var headText = text.slice(0, targetOffset);
  6570. var headCharacters = chars.slice(0, targetOffset);
  6571. var appendToHead = fragment.first();
  6572. return block.merge({
  6573. text: headText + appendToHead.getText(),
  6574. characterList: headCharacters.concat(appendToHead.getCharacterList()),
  6575. type: headText ? block.getType() : appendToHead.getType(),
  6576. data: appendToHead.getData()
  6577. });
  6578. };
  6579. /**
  6580. * Appends offset text/characterList from the target block to the last
  6581. * fragment block.
  6582. */
  6583. var updateTail = function updateTail(block, targetOffset, fragment) {
  6584. // Modify tail portion of block.
  6585. var text = block.getText();
  6586. var chars = block.getCharacterList(); // Modify head portion of block.
  6587. var blockSize = text.length;
  6588. var tailText = text.slice(targetOffset, blockSize);
  6589. var tailCharacters = chars.slice(targetOffset, blockSize);
  6590. var prependToTail = fragment.last();
  6591. return prependToTail.merge({
  6592. text: prependToTail.getText() + tailText,
  6593. characterList: prependToTail.getCharacterList().concat(tailCharacters),
  6594. data: prependToTail.getData()
  6595. });
  6596. };
  6597. var getRootBlocks = function getRootBlocks(block, blockMap) {
  6598. var headKey = block.getKey();
  6599. var rootBlock = block;
  6600. var rootBlocks = []; // sometimes the fragment head block will not be part of the blockMap itself this can happen when
  6601. // the fragment head is used to update the target block, however when this does not happen we need
  6602. // to make sure that we include it on the rootBlocks since the first block of a fragment is always a
  6603. // fragment root block
  6604. if (blockMap.get(headKey)) {
  6605. rootBlocks.push(headKey);
  6606. }
  6607. while (rootBlock && rootBlock.getNextSiblingKey()) {
  6608. var lastSiblingKey = rootBlock.getNextSiblingKey();
  6609. if (!lastSiblingKey) {
  6610. break;
  6611. }
  6612. rootBlocks.push(lastSiblingKey);
  6613. rootBlock = blockMap.get(lastSiblingKey);
  6614. }
  6615. return rootBlocks;
  6616. };
  6617. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockMap, targetBlock, fragmentHeadBlock) {
  6618. return blockMap.withMutations(function (blockMapState) {
  6619. var targetKey = targetBlock.getKey();
  6620. var headKey = fragmentHeadBlock.getKey();
  6621. var targetNextKey = targetBlock.getNextSiblingKey();
  6622. var targetParentKey = targetBlock.getParentKey();
  6623. var fragmentRootBlocks = getRootBlocks(fragmentHeadBlock, blockMap);
  6624. var lastRootFragmentBlockKey = fragmentRootBlocks[fragmentRootBlocks.length - 1];
  6625. if (blockMapState.get(headKey)) {
  6626. // update the fragment head when it is part of the blockMap otherwise
  6627. blockMapState.setIn([targetKey, 'nextSibling'], headKey);
  6628. blockMapState.setIn([headKey, 'prevSibling'], targetKey);
  6629. } else {
  6630. // update the target block that had the fragment head contents merged into it
  6631. blockMapState.setIn([targetKey, 'nextSibling'], fragmentHeadBlock.getNextSiblingKey());
  6632. blockMapState.setIn([fragmentHeadBlock.getNextSiblingKey(), 'prevSibling'], targetKey);
  6633. } // update the last root block fragment
  6634. blockMapState.setIn([lastRootFragmentBlockKey, 'nextSibling'], targetNextKey); // update the original target next block
  6635. if (targetNextKey) {
  6636. blockMapState.setIn([targetNextKey, 'prevSibling'], lastRootFragmentBlockKey);
  6637. } // update fragment parent links
  6638. fragmentRootBlocks.forEach(function (blockKey) {
  6639. return blockMapState.setIn([blockKey, 'parent'], targetParentKey);
  6640. }); // update targetBlock parent child links
  6641. if (targetParentKey) {
  6642. var targetParent = blockMap.get(targetParentKey);
  6643. var originalTargetParentChildKeys = targetParent.getChildKeys();
  6644. var targetBlockIndex = originalTargetParentChildKeys.indexOf(targetKey);
  6645. var insertionIndex = targetBlockIndex + 1;
  6646. var newChildrenKeysArray = originalTargetParentChildKeys.toArray(); // insert fragment children
  6647. newChildrenKeysArray.splice.apply(newChildrenKeysArray, [insertionIndex, 0].concat(fragmentRootBlocks));
  6648. blockMapState.setIn([targetParentKey, 'children'], List(newChildrenKeysArray));
  6649. }
  6650. });
  6651. };
  6652. var insertFragment = function insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset) {
  6653. var isTreeBasedBlockMap = blockMap.first() instanceof ContentBlockNode;
  6654. var newBlockArr = [];
  6655. var fragmentSize = fragment.size;
  6656. var target = blockMap.get(targetKey);
  6657. var head = fragment.first();
  6658. var tail = fragment.last();
  6659. var finalOffset = tail.getLength();
  6660. var finalKey = tail.getKey();
  6661. var shouldNotUpdateFromFragmentBlock = isTreeBasedBlockMap && (!target.getChildKeys().isEmpty() || !head.getChildKeys().isEmpty());
  6662. blockMap.forEach(function (block, blockKey) {
  6663. if (blockKey !== targetKey) {
  6664. newBlockArr.push(block);
  6665. return;
  6666. }
  6667. if (shouldNotUpdateFromFragmentBlock) {
  6668. newBlockArr.push(block);
  6669. } else {
  6670. newBlockArr.push(updateHead(block, targetOffset, fragment));
  6671. } // Insert fragment blocks after the head and before the tail.
  6672. fragment // when we are updating the target block with the head fragment block we skip the first fragment
  6673. // head since its contents have already been merged with the target block otherwise we include
  6674. // the whole fragment
  6675. .slice(shouldNotUpdateFromFragmentBlock ? 0 : 1, fragmentSize - 1).forEach(function (fragmentBlock) {
  6676. return newBlockArr.push(fragmentBlock);
  6677. }); // update tail
  6678. newBlockArr.push(updateTail(block, targetOffset, fragment));
  6679. });
  6680. var updatedBlockMap = BlockMapBuilder.createFromArray(newBlockArr);
  6681. if (isTreeBasedBlockMap) {
  6682. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, blockMap, target, head);
  6683. }
  6684. return contentState.merge({
  6685. blockMap: updatedBlockMap,
  6686. selectionBefore: selectionState,
  6687. selectionAfter: selectionState.merge({
  6688. anchorKey: finalKey,
  6689. anchorOffset: finalOffset,
  6690. focusKey: finalKey,
  6691. focusOffset: finalOffset,
  6692. isBackward: false
  6693. })
  6694. });
  6695. };
  6696. var insertFragmentIntoContentState = function insertFragmentIntoContentState(contentState, selectionState, fragmentBlockMap) {
  6697. var mergeBlockData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'REPLACE_WITH_NEW_DATA';
  6698. !selectionState.isCollapsed() ? true ? invariant(false, '`insertFragment` should only be called with a collapsed selection state.') : invariant(false) : void 0;
  6699. var blockMap = contentState.getBlockMap();
  6700. var fragment = randomizeBlockMapKeys(fragmentBlockMap);
  6701. var targetKey = selectionState.getStartKey();
  6702. var targetOffset = selectionState.getStartOffset();
  6703. var targetBlock = blockMap.get(targetKey);
  6704. if (targetBlock instanceof ContentBlockNode) {
  6705. !targetBlock.getChildKeys().isEmpty() ? true ? invariant(false, '`insertFragment` should not be called when a container node is selected.') : invariant(false) : void 0;
  6706. } // When we insert a fragment with a single block we simply update the target block
  6707. // with the contents of the inserted fragment block
  6708. if (fragment.size === 1) {
  6709. return updateExistingBlock(contentState, selectionState, blockMap, fragment.first(), targetKey, targetOffset, mergeBlockData);
  6710. }
  6711. return insertFragment(contentState, selectionState, blockMap, fragment, targetKey, targetOffset);
  6712. };
  6713. module.exports = insertFragmentIntoContentState;
  6714. /***/ }),
  6715. /* 87 */
  6716. /***/ (function(module, exports, __webpack_require__) {
  6717. "use strict";
  6718. /**
  6719. * Copyright (c) Facebook, Inc. and its affiliates.
  6720. *
  6721. * This source code is licensed under the MIT license found in the
  6722. * LICENSE file in the root directory of this source tree.
  6723. *
  6724. * @format
  6725. *
  6726. * @emails oncall+draft_js
  6727. */
  6728. var Immutable = __webpack_require__(0);
  6729. var insertIntoList = __webpack_require__(43);
  6730. var invariant = __webpack_require__(1);
  6731. var Repeat = Immutable.Repeat;
  6732. function insertTextIntoContentState(contentState, selectionState, text, characterMetadata) {
  6733. !selectionState.isCollapsed() ? true ? invariant(false, '`insertText` should only be called with a collapsed range.') : invariant(false) : void 0;
  6734. var len = null;
  6735. if (text != null) {
  6736. len = text.length;
  6737. }
  6738. if (len == null || len === 0) {
  6739. return contentState;
  6740. }
  6741. var blockMap = contentState.getBlockMap();
  6742. var key = selectionState.getStartKey();
  6743. var offset = selectionState.getStartOffset();
  6744. var block = blockMap.get(key);
  6745. var blockText = block.getText();
  6746. var newBlock = block.merge({
  6747. text: blockText.slice(0, offset) + text + blockText.slice(offset, block.getLength()),
  6748. characterList: insertIntoList(block.getCharacterList(), Repeat(characterMetadata, len).toList(), offset)
  6749. });
  6750. var newOffset = offset + len;
  6751. return contentState.merge({
  6752. blockMap: blockMap.set(key, newBlock),
  6753. selectionAfter: selectionState.merge({
  6754. anchorOffset: newOffset,
  6755. focusOffset: newOffset
  6756. })
  6757. });
  6758. }
  6759. module.exports = insertTextIntoContentState;
  6760. /***/ }),
  6761. /* 88 */
  6762. /***/ (function(module, exports, __webpack_require__) {
  6763. "use strict";
  6764. /**
  6765. * Copyright (c) Facebook, Inc. and its affiliates.
  6766. *
  6767. * This source code is licensed under the MIT license found in the
  6768. * LICENSE file in the root directory of this source tree.
  6769. *
  6770. * @format
  6771. *
  6772. * @emails oncall+draft_js
  6773. */
  6774. var ContentBlockNode = __webpack_require__(7);
  6775. var getNextDelimiterBlockKey = __webpack_require__(45);
  6776. var Immutable = __webpack_require__(0);
  6777. var List = Immutable.List,
  6778. Map = Immutable.Map;
  6779. var transformBlock = function transformBlock(key, blockMap, func) {
  6780. if (!key) {
  6781. return;
  6782. }
  6783. var block = blockMap.get(key);
  6784. if (!block) {
  6785. return;
  6786. }
  6787. blockMap.set(key, func(block));
  6788. };
  6789. /**
  6790. * Ancestors needs to be preserved when there are non selected
  6791. * children to make sure we do not leave any orphans behind
  6792. */
  6793. var getAncestorsKeys = function getAncestorsKeys(blockKey, blockMap) {
  6794. var parents = [];
  6795. if (!blockKey) {
  6796. return parents;
  6797. }
  6798. var blockNode = blockMap.get(blockKey);
  6799. while (blockNode && blockNode.getParentKey()) {
  6800. var parentKey = blockNode.getParentKey();
  6801. if (parentKey) {
  6802. parents.push(parentKey);
  6803. }
  6804. blockNode = parentKey ? blockMap.get(parentKey) : null;
  6805. }
  6806. return parents;
  6807. };
  6808. /**
  6809. * Get all next delimiter keys until we hit a root delimiter and return
  6810. * an array of key references
  6811. */
  6812. var getNextDelimitersBlockKeys = function getNextDelimitersBlockKeys(block, blockMap) {
  6813. var nextDelimiters = [];
  6814. if (!block) {
  6815. return nextDelimiters;
  6816. }
  6817. var nextDelimiter = getNextDelimiterBlockKey(block, blockMap);
  6818. while (nextDelimiter && blockMap.get(nextDelimiter)) {
  6819. var _block = blockMap.get(nextDelimiter);
  6820. nextDelimiters.push(nextDelimiter); // we do not need to keep checking all root node siblings, just the first occurance
  6821. nextDelimiter = _block.getParentKey() ? getNextDelimiterBlockKey(_block, blockMap) : null;
  6822. }
  6823. return nextDelimiters;
  6824. };
  6825. var getNextValidSibling = function getNextValidSibling(block, blockMap, originalBlockMap) {
  6826. if (!block) {
  6827. return null;
  6828. } // note that we need to make sure we refer to the original block since this
  6829. // function is called within a withMutations
  6830. var nextValidSiblingKey = originalBlockMap.get(block.getKey()).getNextSiblingKey();
  6831. while (nextValidSiblingKey && !blockMap.get(nextValidSiblingKey)) {
  6832. nextValidSiblingKey = originalBlockMap.get(nextValidSiblingKey).getNextSiblingKey() || null;
  6833. }
  6834. return nextValidSiblingKey;
  6835. };
  6836. var getPrevValidSibling = function getPrevValidSibling(block, blockMap, originalBlockMap) {
  6837. if (!block) {
  6838. return null;
  6839. } // note that we need to make sure we refer to the original block since this
  6840. // function is called within a withMutations
  6841. var prevValidSiblingKey = originalBlockMap.get(block.getKey()).getPrevSiblingKey();
  6842. while (prevValidSiblingKey && !blockMap.get(prevValidSiblingKey)) {
  6843. prevValidSiblingKey = originalBlockMap.get(prevValidSiblingKey).getPrevSiblingKey() || null;
  6844. }
  6845. return prevValidSiblingKey;
  6846. };
  6847. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, startBlock, endBlock, originalBlockMap) {
  6848. return blockMap.withMutations(function (blocks) {
  6849. // update start block if its retained
  6850. transformBlock(startBlock.getKey(), blocks, function (block) {
  6851. return block.merge({
  6852. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  6853. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  6854. });
  6855. }); // update endblock if its retained
  6856. transformBlock(endBlock.getKey(), blocks, function (block) {
  6857. return block.merge({
  6858. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  6859. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  6860. });
  6861. }); // update start block parent ancestors
  6862. getAncestorsKeys(startBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  6863. return transformBlock(parentKey, blocks, function (block) {
  6864. return block.merge({
  6865. children: block.getChildKeys().filter(function (key) {
  6866. return blocks.get(key);
  6867. }),
  6868. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  6869. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  6870. });
  6871. });
  6872. }); // update start block next - can only happen if startBlock == endBlock
  6873. transformBlock(startBlock.getNextSiblingKey(), blocks, function (block) {
  6874. return block.merge({
  6875. prevSibling: startBlock.getPrevSiblingKey()
  6876. });
  6877. }); // update start block prev
  6878. transformBlock(startBlock.getPrevSiblingKey(), blocks, function (block) {
  6879. return block.merge({
  6880. nextSibling: getNextValidSibling(block, blocks, originalBlockMap)
  6881. });
  6882. }); // update end block next
  6883. transformBlock(endBlock.getNextSiblingKey(), blocks, function (block) {
  6884. return block.merge({
  6885. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  6886. });
  6887. }); // update end block prev
  6888. transformBlock(endBlock.getPrevSiblingKey(), blocks, function (block) {
  6889. return block.merge({
  6890. nextSibling: endBlock.getNextSiblingKey()
  6891. });
  6892. }); // update end block parent ancestors
  6893. getAncestorsKeys(endBlock.getKey(), originalBlockMap).forEach(function (parentKey) {
  6894. transformBlock(parentKey, blocks, function (block) {
  6895. return block.merge({
  6896. children: block.getChildKeys().filter(function (key) {
  6897. return blocks.get(key);
  6898. }),
  6899. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  6900. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  6901. });
  6902. });
  6903. }); // update next delimiters all the way to a root delimiter
  6904. getNextDelimitersBlockKeys(endBlock, originalBlockMap).forEach(function (delimiterKey) {
  6905. return transformBlock(delimiterKey, blocks, function (block) {
  6906. return block.merge({
  6907. nextSibling: getNextValidSibling(block, blocks, originalBlockMap),
  6908. prevSibling: getPrevValidSibling(block, blocks, originalBlockMap)
  6909. });
  6910. });
  6911. }); // if parent (startBlock) was deleted
  6912. if (blockMap.get(startBlock.getKey()) == null && blockMap.get(endBlock.getKey()) != null && endBlock.getParentKey() === startBlock.getKey() && endBlock.getPrevSiblingKey() == null) {
  6913. var prevSiblingKey = startBlock.getPrevSiblingKey(); // endBlock becomes next sibling of parent's prevSibling
  6914. transformBlock(endBlock.getKey(), blocks, function (block) {
  6915. return block.merge({
  6916. prevSibling: prevSiblingKey
  6917. });
  6918. });
  6919. transformBlock(prevSiblingKey, blocks, function (block) {
  6920. return block.merge({
  6921. nextSibling: endBlock.getKey()
  6922. });
  6923. }); // Update parent for previous parent's children, and children for that parent
  6924. var prevSibling = prevSiblingKey ? blockMap.get(prevSiblingKey) : null;
  6925. var newParentKey = prevSibling ? prevSibling.getParentKey() : null;
  6926. startBlock.getChildKeys().forEach(function (childKey) {
  6927. transformBlock(childKey, blocks, function (block) {
  6928. return block.merge({
  6929. parent: newParentKey // set to null if there is no parent
  6930. });
  6931. });
  6932. });
  6933. if (newParentKey != null) {
  6934. var newParent = blockMap.get(newParentKey);
  6935. transformBlock(newParentKey, blocks, function (block) {
  6936. return block.merge({
  6937. children: newParent.getChildKeys().concat(startBlock.getChildKeys())
  6938. });
  6939. });
  6940. } // last child of deleted parent should point to next sibling
  6941. transformBlock(startBlock.getChildKeys().find(function (key) {
  6942. var block = blockMap.get(key);
  6943. return block.getNextSiblingKey() === null;
  6944. }), blocks, function (block) {
  6945. return block.merge({
  6946. nextSibling: startBlock.getNextSiblingKey()
  6947. });
  6948. });
  6949. }
  6950. });
  6951. };
  6952. var removeRangeFromContentState = function removeRangeFromContentState(contentState, selectionState) {
  6953. if (selectionState.isCollapsed()) {
  6954. return contentState;
  6955. }
  6956. var blockMap = contentState.getBlockMap();
  6957. var startKey = selectionState.getStartKey();
  6958. var startOffset = selectionState.getStartOffset();
  6959. var endKey = selectionState.getEndKey();
  6960. var endOffset = selectionState.getEndOffset();
  6961. var startBlock = blockMap.get(startKey);
  6962. var endBlock = blockMap.get(endKey); // we assume that ContentBlockNode and ContentBlocks are not mixed together
  6963. var isExperimentalTreeBlock = startBlock instanceof ContentBlockNode; // used to retain blocks that should not be deleted to avoid orphan children
  6964. var parentAncestors = [];
  6965. if (isExperimentalTreeBlock) {
  6966. var endBlockchildrenKeys = endBlock.getChildKeys();
  6967. var endBlockAncestors = getAncestorsKeys(endKey, blockMap); // endBlock has unselected siblings so we can not remove its ancestors parents
  6968. if (endBlock.getNextSiblingKey()) {
  6969. parentAncestors = parentAncestors.concat(endBlockAncestors);
  6970. } // endBlock has children so can not remove this block or any of its ancestors
  6971. if (!endBlockchildrenKeys.isEmpty()) {
  6972. parentAncestors = parentAncestors.concat(endBlockAncestors.concat([endKey]));
  6973. } // we need to retain all ancestors of the next delimiter block
  6974. parentAncestors = parentAncestors.concat(getAncestorsKeys(getNextDelimiterBlockKey(endBlock, blockMap), blockMap));
  6975. }
  6976. var characterList;
  6977. if (startBlock === endBlock) {
  6978. characterList = removeFromList(startBlock.getCharacterList(), startOffset, endOffset);
  6979. } else {
  6980. characterList = startBlock.getCharacterList().slice(0, startOffset).concat(endBlock.getCharacterList().slice(endOffset));
  6981. }
  6982. var modifiedStart = startBlock.merge({
  6983. text: startBlock.getText().slice(0, startOffset) + endBlock.getText().slice(endOffset),
  6984. characterList: characterList
  6985. }); // If cursor (collapsed) is at the start of the first child, delete parent
  6986. // instead of child
  6987. var shouldDeleteParent = isExperimentalTreeBlock && startOffset === 0 && endOffset === 0 && endBlock.getParentKey() === startKey && endBlock.getPrevSiblingKey() == null;
  6988. var newBlocks = shouldDeleteParent ? Map([[startKey, null]]) : blockMap.toSeq().skipUntil(function (_, k) {
  6989. return k === startKey;
  6990. }).takeUntil(function (_, k) {
  6991. return k === endKey;
  6992. }).filter(function (_, k) {
  6993. return parentAncestors.indexOf(k) === -1;
  6994. }).concat(Map([[endKey, null]])).map(function (_, k) {
  6995. return k === startKey ? modifiedStart : null;
  6996. });
  6997. var updatedBlockMap = blockMap.merge(newBlocks).filter(function (block) {
  6998. return !!block;
  6999. }); // Only update tree block pointers if the range is across blocks
  7000. if (isExperimentalTreeBlock && startBlock !== endBlock) {
  7001. updatedBlockMap = updateBlockMapLinks(updatedBlockMap, startBlock, endBlock, blockMap);
  7002. }
  7003. return contentState.merge({
  7004. blockMap: updatedBlockMap,
  7005. selectionBefore: selectionState,
  7006. selectionAfter: selectionState.merge({
  7007. anchorKey: startKey,
  7008. anchorOffset: startOffset,
  7009. focusKey: startKey,
  7010. focusOffset: startOffset,
  7011. isBackward: false
  7012. })
  7013. });
  7014. };
  7015. /**
  7016. * Maintain persistence for target list when removing characters on the
  7017. * head and tail of the character list.
  7018. */
  7019. var removeFromList = function removeFromList(targetList, startOffset, endOffset) {
  7020. if (startOffset === 0) {
  7021. while (startOffset < endOffset) {
  7022. targetList = targetList.shift();
  7023. startOffset++;
  7024. }
  7025. } else if (endOffset === targetList.count()) {
  7026. while (endOffset > startOffset) {
  7027. targetList = targetList.pop();
  7028. endOffset--;
  7029. }
  7030. } else {
  7031. var head = targetList.slice(0, startOffset);
  7032. var tail = targetList.slice(endOffset);
  7033. targetList = head.concat(tail).toList();
  7034. }
  7035. return targetList;
  7036. };
  7037. module.exports = removeRangeFromContentState;
  7038. /***/ }),
  7039. /* 89 */
  7040. /***/ (function(module, exports, __webpack_require__) {
  7041. "use strict";
  7042. /**
  7043. * Copyright (c) Facebook, Inc. and its affiliates.
  7044. *
  7045. * This source code is licensed under the MIT license found in the
  7046. * LICENSE file in the root directory of this source tree.
  7047. *
  7048. * @format
  7049. *
  7050. * @emails oncall+draft_js
  7051. */
  7052. var ContentBlockNode = __webpack_require__(7);
  7053. var generateRandomKey = __webpack_require__(9);
  7054. var Immutable = __webpack_require__(0);
  7055. var invariant = __webpack_require__(1);
  7056. var modifyBlockForContentState = __webpack_require__(44);
  7057. var List = Immutable.List,
  7058. Map = Immutable.Map;
  7059. var transformBlock = function transformBlock(key, blockMap, func) {
  7060. if (!key) {
  7061. return;
  7062. }
  7063. var block = blockMap.get(key);
  7064. if (!block) {
  7065. return;
  7066. }
  7067. blockMap.set(key, func(block));
  7068. };
  7069. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlock, belowBlock) {
  7070. return blockMap.withMutations(function (blocks) {
  7071. var originalBlockKey = originalBlock.getKey();
  7072. var belowBlockKey = belowBlock.getKey(); // update block parent
  7073. transformBlock(originalBlock.getParentKey(), blocks, function (block) {
  7074. var parentChildrenList = block.getChildKeys();
  7075. var insertionIndex = parentChildrenList.indexOf(originalBlockKey) + 1;
  7076. var newChildrenArray = parentChildrenList.toArray();
  7077. newChildrenArray.splice(insertionIndex, 0, belowBlockKey);
  7078. return block.merge({
  7079. children: List(newChildrenArray)
  7080. });
  7081. }); // update original next block
  7082. transformBlock(originalBlock.getNextSiblingKey(), blocks, function (block) {
  7083. return block.merge({
  7084. prevSibling: belowBlockKey
  7085. });
  7086. }); // update original block
  7087. transformBlock(originalBlockKey, blocks, function (block) {
  7088. return block.merge({
  7089. nextSibling: belowBlockKey
  7090. });
  7091. }); // update below block
  7092. transformBlock(belowBlockKey, blocks, function (block) {
  7093. return block.merge({
  7094. prevSibling: originalBlockKey
  7095. });
  7096. });
  7097. });
  7098. };
  7099. var splitBlockInContentState = function splitBlockInContentState(contentState, selectionState) {
  7100. !selectionState.isCollapsed() ? true ? invariant(false, 'Selection range must be collapsed.') : invariant(false) : void 0;
  7101. var key = selectionState.getAnchorKey();
  7102. var blockMap = contentState.getBlockMap();
  7103. var blockToSplit = blockMap.get(key);
  7104. var text = blockToSplit.getText();
  7105. if (!text) {
  7106. var blockType = blockToSplit.getType();
  7107. if (blockType === 'unordered-list-item' || blockType === 'ordered-list-item') {
  7108. return modifyBlockForContentState(contentState, selectionState, function (block) {
  7109. return block.merge({
  7110. type: 'unstyled',
  7111. depth: 0
  7112. });
  7113. });
  7114. }
  7115. }
  7116. var offset = selectionState.getAnchorOffset();
  7117. var chars = blockToSplit.getCharacterList();
  7118. var keyBelow = generateRandomKey();
  7119. var isExperimentalTreeBlock = blockToSplit instanceof ContentBlockNode;
  7120. var blockAbove = blockToSplit.merge({
  7121. text: text.slice(0, offset),
  7122. characterList: chars.slice(0, offset)
  7123. });
  7124. var blockBelow = blockAbove.merge({
  7125. key: keyBelow,
  7126. text: text.slice(offset),
  7127. characterList: chars.slice(offset),
  7128. data: Map()
  7129. });
  7130. var blocksBefore = blockMap.toSeq().takeUntil(function (v) {
  7131. return v === blockToSplit;
  7132. });
  7133. var blocksAfter = blockMap.toSeq().skipUntil(function (v) {
  7134. return v === blockToSplit;
  7135. }).rest();
  7136. var newBlocks = blocksBefore.concat([[key, blockAbove], [keyBelow, blockBelow]], blocksAfter).toOrderedMap();
  7137. if (isExperimentalTreeBlock) {
  7138. !blockToSplit.getChildKeys().isEmpty() ? true ? invariant(false, 'ContentBlockNode must not have children') : invariant(false) : void 0;
  7139. newBlocks = updateBlockMapLinks(newBlocks, blockAbove, blockBelow);
  7140. }
  7141. return contentState.merge({
  7142. blockMap: newBlocks,
  7143. selectionBefore: selectionState,
  7144. selectionAfter: selectionState.merge({
  7145. anchorKey: keyBelow,
  7146. anchorOffset: 0,
  7147. focusKey: keyBelow,
  7148. focusOffset: 0,
  7149. isBackward: false
  7150. })
  7151. });
  7152. };
  7153. module.exports = splitBlockInContentState;
  7154. /***/ }),
  7155. /* 90 */
  7156. /***/ (function(module, exports, __webpack_require__) {
  7157. "use strict";
  7158. /**
  7159. * Copyright (c) Facebook, Inc. and its affiliates.
  7160. *
  7161. * This source code is licensed under the MIT license found in the
  7162. * LICENSE file in the root directory of this source tree.
  7163. *
  7164. * @format
  7165. *
  7166. * @emails oncall+draft_js
  7167. */
  7168. var findRangesImmutable = __webpack_require__(18);
  7169. var Immutable = __webpack_require__(0);
  7170. var List = Immutable.List,
  7171. Repeat = Immutable.Repeat,
  7172. Record = Immutable.Record;
  7173. var returnTrue = function returnTrue() {
  7174. return true;
  7175. };
  7176. var defaultLeafRange = {
  7177. start: null,
  7178. end: null
  7179. };
  7180. var LeafRange = Record(defaultLeafRange);
  7181. var defaultDecoratorRange = {
  7182. start: null,
  7183. end: null,
  7184. decoratorKey: null,
  7185. leaves: null
  7186. };
  7187. var DecoratorRange = Record(defaultDecoratorRange);
  7188. var BlockTree = {
  7189. /**
  7190. * Generate a block tree for a given ContentBlock/decorator pair.
  7191. */
  7192. generate: function generate(contentState, block, decorator) {
  7193. var textLength = block.getLength();
  7194. if (!textLength) {
  7195. return List.of(new DecoratorRange({
  7196. start: 0,
  7197. end: 0,
  7198. decoratorKey: null,
  7199. leaves: List.of(new LeafRange({
  7200. start: 0,
  7201. end: 0
  7202. }))
  7203. }));
  7204. }
  7205. var leafSets = [];
  7206. var decorations = decorator ? decorator.getDecorations(block, contentState) : List(Repeat(null, textLength));
  7207. var chars = block.getCharacterList();
  7208. findRangesImmutable(decorations, areEqual, returnTrue, function (start, end) {
  7209. leafSets.push(new DecoratorRange({
  7210. start: start,
  7211. end: end,
  7212. decoratorKey: decorations.get(start),
  7213. leaves: generateLeaves(chars.slice(start, end).toList(), start)
  7214. }));
  7215. });
  7216. return List(leafSets);
  7217. }
  7218. };
  7219. /**
  7220. * Generate LeafRange records for a given character list.
  7221. */
  7222. function generateLeaves(characters, offset) {
  7223. var leaves = [];
  7224. var inlineStyles = characters.map(function (c) {
  7225. return c.getStyle();
  7226. }).toList();
  7227. findRangesImmutable(inlineStyles, areEqual, returnTrue, function (start, end) {
  7228. leaves.push(new LeafRange({
  7229. start: start + offset,
  7230. end: end + offset
  7231. }));
  7232. });
  7233. return List(leaves);
  7234. }
  7235. function areEqual(a, b) {
  7236. return a === b;
  7237. }
  7238. module.exports = BlockTree;
  7239. /***/ }),
  7240. /* 91 */
  7241. /***/ (function(module, exports, __webpack_require__) {
  7242. "use strict";
  7243. /**
  7244. * Copyright (c) Facebook, Inc. and its affiliates.
  7245. *
  7246. * This source code is licensed under the MIT license found in the
  7247. * LICENSE file in the root directory of this source tree.
  7248. *
  7249. * @format
  7250. *
  7251. * @emails oncall+draft_js
  7252. */
  7253. var UnicodeBidiService = __webpack_require__(92);
  7254. var Immutable = __webpack_require__(0);
  7255. var nullthrows = __webpack_require__(4);
  7256. var OrderedMap = Immutable.OrderedMap;
  7257. var bidiService;
  7258. var EditorBidiService = {
  7259. getDirectionMap: function getDirectionMap(content, prevBidiMap) {
  7260. if (!bidiService) {
  7261. bidiService = new UnicodeBidiService();
  7262. } else {
  7263. bidiService.reset();
  7264. }
  7265. var blockMap = content.getBlockMap();
  7266. var nextBidi = blockMap.valueSeq().map(function (block) {
  7267. return nullthrows(bidiService).getDirection(block.getText());
  7268. });
  7269. var bidiMap = OrderedMap(blockMap.keySeq().zip(nextBidi));
  7270. if (prevBidiMap != null && Immutable.is(prevBidiMap, bidiMap)) {
  7271. return prevBidiMap;
  7272. }
  7273. return bidiMap;
  7274. }
  7275. };
  7276. module.exports = EditorBidiService;
  7277. /***/ }),
  7278. /* 92 */
  7279. /***/ (function(module, exports, __webpack_require__) {
  7280. "use strict";
  7281. /**
  7282. * Copyright (c) 2013-present, Facebook, Inc.
  7283. *
  7284. * This source code is licensed under the MIT license found in the
  7285. * LICENSE file in the root directory of this source tree.
  7286. *
  7287. * @typechecks
  7288. *
  7289. */
  7290. /**
  7291. * Stateful API for text direction detection
  7292. *
  7293. * This class can be used in applications where you need to detect the
  7294. * direction of a sequence of text blocks, where each direction shall be used
  7295. * as the fallback direction for the next one.
  7296. *
  7297. * NOTE: A default direction, if not provided, is set based on the global
  7298. * direction, as defined by `UnicodeBidiDirection`.
  7299. *
  7300. * == Example ==
  7301. * ```
  7302. * var UnicodeBidiService = require('UnicodeBidiService');
  7303. *
  7304. * var bidiService = new UnicodeBidiService();
  7305. *
  7306. * ...
  7307. *
  7308. * bidiService.reset();
  7309. * for (var para in paragraphs) {
  7310. * var dir = bidiService.getDirection(para);
  7311. * ...
  7312. * }
  7313. * ```
  7314. *
  7315. * Part of our implementation of Unicode Bidirectional Algorithm (UBA)
  7316. * Unicode Standard Annex #9 (UAX9)
  7317. * http://www.unicode.org/reports/tr9/
  7318. */
  7319. 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; }
  7320. var UnicodeBidi = __webpack_require__(33);
  7321. var UnicodeBidiDirection = __webpack_require__(24);
  7322. var invariant = __webpack_require__(1);
  7323. var UnicodeBidiService =
  7324. /*#__PURE__*/
  7325. function () {
  7326. /**
  7327. * Stateful class for paragraph direction detection
  7328. *
  7329. * @param defaultDir Default direction of the service
  7330. */
  7331. function UnicodeBidiService(defaultDir) {
  7332. _defineProperty(this, "_defaultDir", void 0);
  7333. _defineProperty(this, "_lastDir", void 0);
  7334. if (!defaultDir) {
  7335. defaultDir = UnicodeBidiDirection.getGlobalDir();
  7336. } else {
  7337. !UnicodeBidiDirection.isStrong(defaultDir) ? true ? invariant(false, 'Default direction must be a strong direction (LTR or RTL)') : invariant(false) : void 0;
  7338. }
  7339. this._defaultDir = defaultDir;
  7340. this.reset();
  7341. }
  7342. /**
  7343. * Reset the internal state
  7344. *
  7345. * Instead of creating a new instance, you can just reset() your instance
  7346. * everytime you start a new loop.
  7347. */
  7348. var _proto = UnicodeBidiService.prototype;
  7349. _proto.reset = function reset() {
  7350. this._lastDir = this._defaultDir;
  7351. };
  7352. /**
  7353. * Returns the direction of a block of text, and remembers it as the
  7354. * fall-back direction for the next paragraph.
  7355. *
  7356. * @param str A text block, e.g. paragraph, table cell, tag
  7357. * @return The resolved direction
  7358. */
  7359. _proto.getDirection = function getDirection(str) {
  7360. this._lastDir = UnicodeBidi.getDirection(str, this._lastDir);
  7361. return this._lastDir;
  7362. };
  7363. return UnicodeBidiService;
  7364. }();
  7365. module.exports = UnicodeBidiService;
  7366. /***/ }),
  7367. /* 93 */
  7368. /***/ (function(module, exports, __webpack_require__) {
  7369. "use strict";
  7370. /**
  7371. * Copyright (c) Facebook, Inc. and its affiliates.
  7372. *
  7373. * This source code is licensed under the MIT license found in the
  7374. * LICENSE file in the root directory of this source tree.
  7375. *
  7376. * @format
  7377. *
  7378. * @emails oncall+draft_js
  7379. */
  7380. var ContentBlockNode = __webpack_require__(7);
  7381. var getNextDelimiterBlockKey = __webpack_require__(45);
  7382. var Immutable = __webpack_require__(0);
  7383. var invariant = __webpack_require__(1);
  7384. var OrderedMap = Immutable.OrderedMap,
  7385. List = Immutable.List;
  7386. var transformBlock = function transformBlock(key, blockMap, func) {
  7387. if (!key) {
  7388. return;
  7389. }
  7390. var block = blockMap.get(key);
  7391. if (!block) {
  7392. return;
  7393. }
  7394. blockMap.set(key, func(block));
  7395. };
  7396. var updateBlockMapLinks = function updateBlockMapLinks(blockMap, originalBlockToBeMoved, originalTargetBlock, insertionMode, isExperimentalTreeBlock) {
  7397. if (!isExperimentalTreeBlock) {
  7398. return blockMap;
  7399. } // possible values of 'insertionMode' are: 'after', 'before'
  7400. var isInsertedAfterTarget = insertionMode === 'after';
  7401. var originalBlockKey = originalBlockToBeMoved.getKey();
  7402. var originalTargetKey = originalTargetBlock.getKey();
  7403. var originalParentKey = originalBlockToBeMoved.getParentKey();
  7404. var originalNextSiblingKey = originalBlockToBeMoved.getNextSiblingKey();
  7405. var originalPrevSiblingKey = originalBlockToBeMoved.getPrevSiblingKey();
  7406. var newParentKey = originalTargetBlock.getParentKey();
  7407. var newNextSiblingKey = isInsertedAfterTarget ? originalTargetBlock.getNextSiblingKey() : originalTargetKey;
  7408. var newPrevSiblingKey = isInsertedAfterTarget ? originalTargetKey : originalTargetBlock.getPrevSiblingKey();
  7409. return blockMap.withMutations(function (blocks) {
  7410. // update old parent
  7411. transformBlock(originalParentKey, blocks, function (block) {
  7412. var parentChildrenList = block.getChildKeys();
  7413. return block.merge({
  7414. children: parentChildrenList["delete"](parentChildrenList.indexOf(originalBlockKey))
  7415. });
  7416. }); // update old prev
  7417. transformBlock(originalPrevSiblingKey, blocks, function (block) {
  7418. return block.merge({
  7419. nextSibling: originalNextSiblingKey
  7420. });
  7421. }); // update old next
  7422. transformBlock(originalNextSiblingKey, blocks, function (block) {
  7423. return block.merge({
  7424. prevSibling: originalPrevSiblingKey
  7425. });
  7426. }); // update new next
  7427. transformBlock(newNextSiblingKey, blocks, function (block) {
  7428. return block.merge({
  7429. prevSibling: originalBlockKey
  7430. });
  7431. }); // update new prev
  7432. transformBlock(newPrevSiblingKey, blocks, function (block) {
  7433. return block.merge({
  7434. nextSibling: originalBlockKey
  7435. });
  7436. }); // update new parent
  7437. transformBlock(newParentKey, blocks, function (block) {
  7438. var newParentChildrenList = block.getChildKeys();
  7439. var targetBlockIndex = newParentChildrenList.indexOf(originalTargetKey);
  7440. var insertionIndex = isInsertedAfterTarget ? targetBlockIndex + 1 : targetBlockIndex !== 0 ? targetBlockIndex - 1 : 0;
  7441. var newChildrenArray = newParentChildrenList.toArray();
  7442. newChildrenArray.splice(insertionIndex, 0, originalBlockKey);
  7443. return block.merge({
  7444. children: List(newChildrenArray)
  7445. });
  7446. }); // update block
  7447. transformBlock(originalBlockKey, blocks, function (block) {
  7448. return block.merge({
  7449. nextSibling: newNextSiblingKey,
  7450. prevSibling: newPrevSiblingKey,
  7451. parent: newParentKey
  7452. });
  7453. });
  7454. });
  7455. };
  7456. var moveBlockInContentState = function moveBlockInContentState(contentState, blockToBeMoved, targetBlock, insertionMode) {
  7457. !(insertionMode !== 'replace') ? true ? invariant(false, 'Replacing blocks is not supported.') : invariant(false) : void 0;
  7458. var targetKey = targetBlock.getKey();
  7459. var blockKey = blockToBeMoved.getKey();
  7460. !(blockKey !== targetKey) ? true ? invariant(false, 'Block cannot be moved next to itself.') : invariant(false) : void 0;
  7461. var blockMap = contentState.getBlockMap();
  7462. var isExperimentalTreeBlock = blockToBeMoved instanceof ContentBlockNode;
  7463. var blocksToBeMoved = [blockToBeMoved];
  7464. var blockMapWithoutBlocksToBeMoved = blockMap["delete"](blockKey);
  7465. if (isExperimentalTreeBlock) {
  7466. blocksToBeMoved = [];
  7467. blockMapWithoutBlocksToBeMoved = blockMap.withMutations(function (blocks) {
  7468. var nextSiblingKey = blockToBeMoved.getNextSiblingKey();
  7469. var nextDelimiterBlockKey = getNextDelimiterBlockKey(blockToBeMoved, blocks);
  7470. blocks.toSeq().skipUntil(function (block) {
  7471. return block.getKey() === blockKey;
  7472. }).takeWhile(function (block) {
  7473. var key = block.getKey();
  7474. var isBlockToBeMoved = key === blockKey;
  7475. var hasNextSiblingAndIsNotNextSibling = nextSiblingKey && key !== nextSiblingKey;
  7476. var doesNotHaveNextSiblingAndIsNotDelimiter = !nextSiblingKey && block.getParentKey() && (!nextDelimiterBlockKey || key !== nextDelimiterBlockKey);
  7477. return !!(isBlockToBeMoved || hasNextSiblingAndIsNotNextSibling || doesNotHaveNextSiblingAndIsNotDelimiter);
  7478. }).forEach(function (block) {
  7479. blocksToBeMoved.push(block);
  7480. blocks["delete"](block.getKey());
  7481. });
  7482. });
  7483. }
  7484. var blocksBefore = blockMapWithoutBlocksToBeMoved.toSeq().takeUntil(function (v) {
  7485. return v === targetBlock;
  7486. });
  7487. var blocksAfter = blockMapWithoutBlocksToBeMoved.toSeq().skipUntil(function (v) {
  7488. return v === targetBlock;
  7489. }).skip(1);
  7490. var slicedBlocks = blocksToBeMoved.map(function (block) {
  7491. return [block.getKey(), block];
  7492. });
  7493. var newBlocks = OrderedMap();
  7494. if (insertionMode === 'before') {
  7495. var blockBefore = contentState.getBlockBefore(targetKey);
  7496. !(!blockBefore || blockBefore.getKey() !== blockToBeMoved.getKey()) ? true ? invariant(false, 'Block cannot be moved next to itself.') : invariant(false) : void 0;
  7497. newBlocks = blocksBefore.concat([].concat(slicedBlocks, [[targetKey, targetBlock]]), blocksAfter).toOrderedMap();
  7498. } else if (insertionMode === 'after') {
  7499. var blockAfter = contentState.getBlockAfter(targetKey);
  7500. !(!blockAfter || blockAfter.getKey() !== blockKey) ? true ? invariant(false, 'Block cannot be moved next to itself.') : invariant(false) : void 0;
  7501. newBlocks = blocksBefore.concat([[targetKey, targetBlock]].concat(slicedBlocks), blocksAfter).toOrderedMap();
  7502. }
  7503. return contentState.merge({
  7504. blockMap: updateBlockMapLinks(newBlocks, blockToBeMoved, targetBlock, insertionMode, isExperimentalTreeBlock),
  7505. selectionBefore: contentState.getSelectionAfter(),
  7506. selectionAfter: contentState.getSelectionAfter().merge({
  7507. anchorKey: blockKey,
  7508. focusKey: blockKey
  7509. })
  7510. });
  7511. };
  7512. module.exports = moveBlockInContentState;
  7513. /***/ }),
  7514. /* 94 */
  7515. /***/ (function(module, exports, __webpack_require__) {
  7516. "use strict";
  7517. /**
  7518. * Copyright (c) Facebook, Inc. and its affiliates.
  7519. *
  7520. * This source code is licensed under the MIT license found in the
  7521. * LICENSE file in the root directory of this source tree.
  7522. *
  7523. * @format
  7524. *
  7525. * @emails oncall+draft_js
  7526. */
  7527. 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; }
  7528. var Immutable = __webpack_require__(0);
  7529. var List = Immutable.List;
  7530. var DELIMITER = '.';
  7531. /**
  7532. * A CompositeDraftDecorator traverses through a list of DraftDecorator
  7533. * instances to identify sections of a ContentBlock that should be rendered
  7534. * in a "decorated" manner. For example, hashtags, mentions, and links may
  7535. * be intended to stand out visually, be rendered as anchors, etc.
  7536. *
  7537. * The list of decorators supplied to the constructor will be used in the
  7538. * order they are provided. This allows the caller to specify a priority for
  7539. * string matching, in case of match collisions among decorators.
  7540. *
  7541. * For instance, I may have a link with a `#` in its text. Though this section
  7542. * of text may match our hashtag decorator, it should not be treated as a
  7543. * hashtag. I should therefore list my link DraftDecorator
  7544. * before my hashtag DraftDecorator when constructing this composite
  7545. * decorator instance.
  7546. *
  7547. * Thus, when a collision like this is encountered, the earlier match is
  7548. * preserved and the new match is discarded.
  7549. */
  7550. var CompositeDraftDecorator =
  7551. /*#__PURE__*/
  7552. function () {
  7553. function CompositeDraftDecorator(decorators) {
  7554. _defineProperty(this, "_decorators", void 0);
  7555. // Copy the decorator array, since we use this array order to determine
  7556. // precedence of decoration matching. If the array is mutated externally,
  7557. // we don't want to be affected here.
  7558. this._decorators = decorators.slice();
  7559. }
  7560. var _proto = CompositeDraftDecorator.prototype;
  7561. _proto.getDecorations = function getDecorations(block, contentState) {
  7562. var decorations = Array(block.getText().length).fill(null);
  7563. this._decorators.forEach(function (
  7564. /*object*/
  7565. decorator,
  7566. /*number*/
  7567. ii) {
  7568. var counter = 0;
  7569. var strategy = decorator.strategy;
  7570. var callback = function callback(
  7571. /*number*/
  7572. start,
  7573. /*number*/
  7574. end) {
  7575. // Find out if any of our matching range is already occupied
  7576. // by another decorator. If so, discard the match. Otherwise, store
  7577. // the component key for rendering.
  7578. if (canOccupySlice(decorations, start, end)) {
  7579. occupySlice(decorations, start, end, ii + DELIMITER + counter);
  7580. counter++;
  7581. }
  7582. };
  7583. strategy(block, callback, contentState);
  7584. });
  7585. return List(decorations);
  7586. };
  7587. _proto.getComponentForKey = function getComponentForKey(key) {
  7588. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7589. return this._decorators[componentKey].component;
  7590. };
  7591. _proto.getPropsForKey = function getPropsForKey(key) {
  7592. var componentKey = parseInt(key.split(DELIMITER)[0], 10);
  7593. return this._decorators[componentKey].props;
  7594. };
  7595. return CompositeDraftDecorator;
  7596. }();
  7597. /**
  7598. * Determine whether we can occupy the specified slice of the decorations
  7599. * array.
  7600. */
  7601. function canOccupySlice(decorations, start, end) {
  7602. for (var ii = start; ii < end; ii++) {
  7603. if (decorations[ii] != null) {
  7604. return false;
  7605. }
  7606. }
  7607. return true;
  7608. }
  7609. /**
  7610. * Splice the specified component into our decoration array at the desired
  7611. * range.
  7612. */
  7613. function occupySlice(targetArr, start, end, componentKey) {
  7614. for (var ii = start; ii < end; ii++) {
  7615. targetArr[ii] = componentKey;
  7616. }
  7617. }
  7618. module.exports = CompositeDraftDecorator;
  7619. /***/ }),
  7620. /* 95 */
  7621. /***/ (function(module, exports, __webpack_require__) {
  7622. "use strict";
  7623. /* WEBPACK VAR INJECTION */(function(global) {/**
  7624. * Copyright (c) Facebook, Inc. and its affiliates.
  7625. *
  7626. * This source code is licensed under the MIT license found in the
  7627. * LICENSE file in the root directory of this source tree.
  7628. *
  7629. * @format
  7630. *
  7631. * @preventMunge
  7632. * @emails oncall+draft_js
  7633. */
  7634. var _assign = __webpack_require__(14);
  7635. function _extends() { _extends = _assign || 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; }; return _extends.apply(this, arguments); }
  7636. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  7637. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7638. 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; }
  7639. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  7640. var DefaultDraftBlockRenderMap = __webpack_require__(34);
  7641. var DefaultDraftInlineStyle = __webpack_require__(48);
  7642. var DraftEditorCompositionHandler = __webpack_require__(96);
  7643. var DraftEditorContents = __webpack_require__(104);
  7644. var DraftEditorDragHandler = __webpack_require__(121);
  7645. var DraftEditorEditHandler = __webpack_require__(124);
  7646. var flushControlled = __webpack_require__(160);
  7647. var DraftEditorPlaceholder = __webpack_require__(162);
  7648. var DraftEffects = __webpack_require__(60);
  7649. var EditorState = __webpack_require__(2);
  7650. var React = __webpack_require__(8);
  7651. var Scroll = __webpack_require__(37);
  7652. var Style = __webpack_require__(29);
  7653. var UserAgent = __webpack_require__(5);
  7654. var cx = __webpack_require__(13);
  7655. var generateRandomKey = __webpack_require__(9);
  7656. var getDefaultKeyBinding = __webpack_require__(76);
  7657. var getScrollPosition = __webpack_require__(30);
  7658. var gkx = __webpack_require__(11);
  7659. var invariant = __webpack_require__(1);
  7660. var isHTMLElement = __webpack_require__(19);
  7661. var nullthrows = __webpack_require__(4);
  7662. var isIE = UserAgent.isBrowser('IE'); // IE does not support the `input` event on contentEditable, so we can't
  7663. // observe spellcheck behavior.
  7664. var allowSpellCheck = !isIE; // Define a set of handler objects to correspond to each possible `mode`
  7665. // of editor behavior.
  7666. var handlerMap = {
  7667. edit: DraftEditorEditHandler,
  7668. composite: DraftEditorCompositionHandler,
  7669. drag: DraftEditorDragHandler,
  7670. cut: null,
  7671. render: null
  7672. };
  7673. var didInitODS = false;
  7674. var UpdateDraftEditorFlags =
  7675. /*#__PURE__*/
  7676. function (_React$Component) {
  7677. _inheritsLoose(UpdateDraftEditorFlags, _React$Component);
  7678. function UpdateDraftEditorFlags() {
  7679. return _React$Component.apply(this, arguments) || this;
  7680. }
  7681. var _proto = UpdateDraftEditorFlags.prototype;
  7682. _proto.render = function render() {
  7683. return null;
  7684. };
  7685. _proto.componentDidMount = function componentDidMount() {
  7686. this._update();
  7687. };
  7688. _proto.componentDidUpdate = function componentDidUpdate() {
  7689. this._update();
  7690. };
  7691. _proto._update = function _update() {
  7692. var editor = this.props.editor;
  7693. /**
  7694. * Sometimes a render triggers a 'focus' or other event, and that will
  7695. * schedule a second render pass.
  7696. * In order to make sure the second render pass gets the latest editor
  7697. * state, we update it here.
  7698. * Example:
  7699. * render #1
  7700. * +
  7701. * |
  7702. * | cWU -> Nothing ... latestEditorState = STALE_STATE :(
  7703. * |
  7704. * | render -> this.props.editorState = FRESH_STATE
  7705. * | + *and* set latestEditorState = FRESH_STATE
  7706. * |
  7707. * | |
  7708. * | +--> triggers 'focus' event, calling 'handleFocus' with latestEditorState
  7709. * | +
  7710. * | |
  7711. * +>cdU -> latestEditorState = FRESH_STATE | the 'handleFocus' call schedules render #2
  7712. * | with latestEditorState, which is FRESH_STATE
  7713. * |
  7714. * render #2 <--------------------------------------+
  7715. * +
  7716. * |
  7717. * | cwU -> nothing updates
  7718. * |
  7719. * | render -> this.props.editorState = FRESH_STATE which was passed in above
  7720. * |
  7721. * +>cdU fires and resets latestEditorState = FRESH_STATE
  7722. * ---
  7723. * Note that if we don't set latestEditorState in 'render' in the above
  7724. * diagram, then STALE_STATE gets passed to render #2.
  7725. */
  7726. editor._latestEditorState = this.props.editorState;
  7727. /**
  7728. * The reason we set this 'blockSelectEvents' flag is that IE will fire a
  7729. * 'selectionChange' event when we programmatically change the selection,
  7730. * meaning it would trigger a new select event while we are in the middle
  7731. * of updating.
  7732. * We found that the 'selection.addRange' was what triggered the stray
  7733. * selectionchange event in IE.
  7734. * To be clear - we have not been able to reproduce specific bugs related
  7735. * to this stray selection event, but have recorded logs that some
  7736. * conditions do cause it to get bumped into during editOnSelect.
  7737. */
  7738. editor._blockSelectEvents = true;
  7739. };
  7740. return UpdateDraftEditorFlags;
  7741. }(React.Component);
  7742. /**
  7743. * `DraftEditor` is the root editor component. It composes a `contentEditable`
  7744. * div, and provides a wide variety of useful function props for managing the
  7745. * state of the editor. See `DraftEditorProps` for details.
  7746. */
  7747. var DraftEditor =
  7748. /*#__PURE__*/
  7749. function (_React$Component2) {
  7750. _inheritsLoose(DraftEditor, _React$Component2);
  7751. /**
  7752. * Define proxies that can route events to the current handler.
  7753. */
  7754. function DraftEditor(props) {
  7755. var _this;
  7756. _this = _React$Component2.call(this, props) || this;
  7757. _defineProperty(_assertThisInitialized(_this), "_blockSelectEvents", void 0);
  7758. _defineProperty(_assertThisInitialized(_this), "_clipboard", void 0);
  7759. _defineProperty(_assertThisInitialized(_this), "_handler", void 0);
  7760. _defineProperty(_assertThisInitialized(_this), "_dragCount", void 0);
  7761. _defineProperty(_assertThisInitialized(_this), "_internalDrag", void 0);
  7762. _defineProperty(_assertThisInitialized(_this), "_editorKey", void 0);
  7763. _defineProperty(_assertThisInitialized(_this), "_placeholderAccessibilityID", void 0);
  7764. _defineProperty(_assertThisInitialized(_this), "_latestEditorState", void 0);
  7765. _defineProperty(_assertThisInitialized(_this), "_latestCommittedEditorState", void 0);
  7766. _defineProperty(_assertThisInitialized(_this), "_pendingStateFromBeforeInput", void 0);
  7767. _defineProperty(_assertThisInitialized(_this), "_onBeforeInput", void 0);
  7768. _defineProperty(_assertThisInitialized(_this), "_onBlur", void 0);
  7769. _defineProperty(_assertThisInitialized(_this), "_onCharacterData", void 0);
  7770. _defineProperty(_assertThisInitialized(_this), "_onCompositionEnd", void 0);
  7771. _defineProperty(_assertThisInitialized(_this), "_onCompositionStart", void 0);
  7772. _defineProperty(_assertThisInitialized(_this), "_onCopy", void 0);
  7773. _defineProperty(_assertThisInitialized(_this), "_onCut", void 0);
  7774. _defineProperty(_assertThisInitialized(_this), "_onDragEnd", void 0);
  7775. _defineProperty(_assertThisInitialized(_this), "_onDragOver", void 0);
  7776. _defineProperty(_assertThisInitialized(_this), "_onDragStart", void 0);
  7777. _defineProperty(_assertThisInitialized(_this), "_onDrop", void 0);
  7778. _defineProperty(_assertThisInitialized(_this), "_onInput", void 0);
  7779. _defineProperty(_assertThisInitialized(_this), "_onFocus", void 0);
  7780. _defineProperty(_assertThisInitialized(_this), "_onKeyDown", void 0);
  7781. _defineProperty(_assertThisInitialized(_this), "_onKeyPress", void 0);
  7782. _defineProperty(_assertThisInitialized(_this), "_onKeyUp", void 0);
  7783. _defineProperty(_assertThisInitialized(_this), "_onMouseDown", void 0);
  7784. _defineProperty(_assertThisInitialized(_this), "_onMouseUp", void 0);
  7785. _defineProperty(_assertThisInitialized(_this), "_onPaste", void 0);
  7786. _defineProperty(_assertThisInitialized(_this), "_onSelect", void 0);
  7787. _defineProperty(_assertThisInitialized(_this), "editor", void 0);
  7788. _defineProperty(_assertThisInitialized(_this), "editorContainer", void 0);
  7789. _defineProperty(_assertThisInitialized(_this), "focus", void 0);
  7790. _defineProperty(_assertThisInitialized(_this), "blur", void 0);
  7791. _defineProperty(_assertThisInitialized(_this), "setMode", void 0);
  7792. _defineProperty(_assertThisInitialized(_this), "exitCurrentMode", void 0);
  7793. _defineProperty(_assertThisInitialized(_this), "restoreEditorDOM", void 0);
  7794. _defineProperty(_assertThisInitialized(_this), "setClipboard", void 0);
  7795. _defineProperty(_assertThisInitialized(_this), "getClipboard", void 0);
  7796. _defineProperty(_assertThisInitialized(_this), "getEditorKey", void 0);
  7797. _defineProperty(_assertThisInitialized(_this), "update", void 0);
  7798. _defineProperty(_assertThisInitialized(_this), "onDragEnter", void 0);
  7799. _defineProperty(_assertThisInitialized(_this), "onDragLeave", void 0);
  7800. _defineProperty(_assertThisInitialized(_this), "_handleEditorContainerRef", function (node) {
  7801. _this.editorContainer = node; // Instead of having a direct ref on the child, we'll grab it here.
  7802. // This is safe as long as the rendered structure is static (which it is).
  7803. // This lets the child support ref={props.editorRef} without merging refs.
  7804. _this.editor = node !== null ? node.firstChild : null;
  7805. });
  7806. _defineProperty(_assertThisInitialized(_this), "focus", function (scrollPosition) {
  7807. var editorState = _this.props.editorState;
  7808. var alreadyHasFocus = editorState.getSelection().getHasFocus();
  7809. var editorNode = _this.editor;
  7810. if (!editorNode) {
  7811. // once in a while people call 'focus' in a setTimeout, and the node has
  7812. // been deleted, so it can be null in that case.
  7813. return;
  7814. }
  7815. var scrollParent = Style.getScrollParent(editorNode);
  7816. var _ref = scrollPosition || getScrollPosition(scrollParent),
  7817. x = _ref.x,
  7818. y = _ref.y;
  7819. !isHTMLElement(editorNode) ? true ? invariant(false, 'editorNode is not an HTMLElement') : invariant(false) : void 0;
  7820. editorNode.focus(); // Restore scroll position
  7821. if (scrollParent === window) {
  7822. window.scrollTo(x, y);
  7823. } else {
  7824. Scroll.setTop(scrollParent, y);
  7825. } // On Chrome and Safari, calling focus on contenteditable focuses the
  7826. // cursor at the first character. This is something you don't expect when
  7827. // you're clicking on an input element but not directly on a character.
  7828. // Put the cursor back where it was before the blur.
  7829. if (!alreadyHasFocus) {
  7830. _this.update(EditorState.forceSelection(editorState, editorState.getSelection()));
  7831. }
  7832. });
  7833. _defineProperty(_assertThisInitialized(_this), "blur", function () {
  7834. var editorNode = _this.editor;
  7835. if (!editorNode) {
  7836. return;
  7837. }
  7838. !isHTMLElement(editorNode) ? true ? invariant(false, 'editorNode is not an HTMLElement') : invariant(false) : void 0;
  7839. editorNode.blur();
  7840. });
  7841. _defineProperty(_assertThisInitialized(_this), "setMode", function (mode) {
  7842. var _this$props = _this.props,
  7843. onPaste = _this$props.onPaste,
  7844. onCut = _this$props.onCut,
  7845. onCopy = _this$props.onCopy;
  7846. var editHandler = _objectSpread({}, handlerMap.edit);
  7847. if (onPaste) {
  7848. /* $FlowFixMe(>=0.117.0 site=www) This comment suppresses an error found
  7849. * when Flow v0.117 was deployed. To see the error delete this comment
  7850. * and run Flow. */
  7851. editHandler.onPaste = onPaste;
  7852. }
  7853. if (onCut) {
  7854. editHandler.onCut = onCut;
  7855. }
  7856. if (onCopy) {
  7857. editHandler.onCopy = onCopy;
  7858. }
  7859. var handler = _objectSpread({}, handlerMap, {
  7860. edit: editHandler
  7861. });
  7862. _this._handler = handler[mode];
  7863. });
  7864. _defineProperty(_assertThisInitialized(_this), "exitCurrentMode", function () {
  7865. _this.setMode('edit');
  7866. });
  7867. _defineProperty(_assertThisInitialized(_this), "restoreEditorDOM", function (scrollPosition) {
  7868. _this.setState({
  7869. contentsKey: _this.state.contentsKey + 1
  7870. }, function () {
  7871. _this.focus(scrollPosition);
  7872. });
  7873. });
  7874. _defineProperty(_assertThisInitialized(_this), "setClipboard", function (clipboard) {
  7875. _this._clipboard = clipboard;
  7876. });
  7877. _defineProperty(_assertThisInitialized(_this), "getClipboard", function () {
  7878. return _this._clipboard;
  7879. });
  7880. _defineProperty(_assertThisInitialized(_this), "update", function (editorState) {
  7881. _this._latestEditorState = editorState;
  7882. _this.props.onChange(editorState);
  7883. });
  7884. _defineProperty(_assertThisInitialized(_this), "onDragEnter", function () {
  7885. _this._dragCount++;
  7886. });
  7887. _defineProperty(_assertThisInitialized(_this), "onDragLeave", function () {
  7888. _this._dragCount--;
  7889. if (_this._dragCount === 0) {
  7890. _this.exitCurrentMode();
  7891. }
  7892. });
  7893. _this._blockSelectEvents = false;
  7894. _this._clipboard = null;
  7895. _this._handler = null;
  7896. _this._dragCount = 0;
  7897. _this._editorKey = props.editorKey || generateRandomKey();
  7898. _this._placeholderAccessibilityID = 'placeholder-' + _this._editorKey;
  7899. _this._latestEditorState = props.editorState;
  7900. _this._latestCommittedEditorState = props.editorState;
  7901. _this._onBeforeInput = _this._buildHandler('onBeforeInput');
  7902. _this._onBlur = _this._buildHandler('onBlur');
  7903. _this._onCharacterData = _this._buildHandler('onCharacterData');
  7904. _this._onCompositionEnd = _this._buildHandler('onCompositionEnd');
  7905. _this._onCompositionStart = _this._buildHandler('onCompositionStart');
  7906. _this._onCopy = _this._buildHandler('onCopy');
  7907. _this._onCut = _this._buildHandler('onCut');
  7908. _this._onDragEnd = _this._buildHandler('onDragEnd');
  7909. _this._onDragOver = _this._buildHandler('onDragOver');
  7910. _this._onDragStart = _this._buildHandler('onDragStart');
  7911. _this._onDrop = _this._buildHandler('onDrop');
  7912. _this._onInput = _this._buildHandler('onInput');
  7913. _this._onFocus = _this._buildHandler('onFocus');
  7914. _this._onKeyDown = _this._buildHandler('onKeyDown');
  7915. _this._onKeyPress = _this._buildHandler('onKeyPress');
  7916. _this._onKeyUp = _this._buildHandler('onKeyUp');
  7917. _this._onMouseDown = _this._buildHandler('onMouseDown');
  7918. _this._onMouseUp = _this._buildHandler('onMouseUp');
  7919. _this._onPaste = _this._buildHandler('onPaste');
  7920. _this._onSelect = _this._buildHandler('onSelect');
  7921. _this.getEditorKey = function () {
  7922. return _this._editorKey;
  7923. };
  7924. if (true) {
  7925. ['onDownArrow', 'onEscape', 'onLeftArrow', 'onRightArrow', 'onTab', 'onUpArrow'].forEach(function (propName) {
  7926. if (props.hasOwnProperty(propName)) {
  7927. // eslint-disable-next-line no-console
  7928. console.warn("Supplying an `".concat(propName, "` prop to `DraftEditor` has ") + 'been deprecated. If your handler needs access to the keyboard ' + 'event, supply a custom `keyBindingFn` prop that falls back to ' + 'the default one (eg. https://is.gd/wHKQ3W).');
  7929. }
  7930. });
  7931. } // See `restoreEditorDOM()`.
  7932. _this.state = {
  7933. contentsKey: 0
  7934. };
  7935. return _this;
  7936. }
  7937. /**
  7938. * Build a method that will pass the event to the specified handler method.
  7939. * This allows us to look up the correct handler function for the current
  7940. * editor mode, if any has been specified.
  7941. */
  7942. var _proto2 = DraftEditor.prototype;
  7943. _proto2._buildHandler = function _buildHandler(eventName) {
  7944. var _this2 = this;
  7945. // Wrap event handlers in `flushControlled`. In sync mode, this is
  7946. // effectively a no-op. In async mode, this ensures all updates scheduled
  7947. // inside the handler are flushed before React yields to the browser.
  7948. return function (e) {
  7949. if (!_this2.props.readOnly) {
  7950. var method = _this2._handler && _this2._handler[eventName];
  7951. if (method) {
  7952. if (flushControlled) {
  7953. flushControlled(function () {
  7954. return method(_this2, e);
  7955. });
  7956. } else {
  7957. method(_this2, e);
  7958. }
  7959. }
  7960. }
  7961. };
  7962. };
  7963. _proto2._showPlaceholder = function _showPlaceholder() {
  7964. return !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText();
  7965. };
  7966. _proto2._renderPlaceholder = function _renderPlaceholder() {
  7967. if (this._showPlaceholder()) {
  7968. var placeHolderProps = {
  7969. text: nullthrows(this.props.placeholder),
  7970. editorState: this.props.editorState,
  7971. textAlignment: this.props.textAlignment,
  7972. accessibilityID: this._placeholderAccessibilityID
  7973. };
  7974. /* $FlowFixMe(>=0.112.0 site=www,mobile) This comment suppresses an error
  7975. * found when Flow v0.112 was deployed. To see the error delete this
  7976. * comment and run Flow. */
  7977. return React.createElement(DraftEditorPlaceholder, placeHolderProps);
  7978. }
  7979. return null;
  7980. };
  7981. _proto2.render = function render() {
  7982. var _this$props2 = this.props,
  7983. blockRenderMap = _this$props2.blockRenderMap,
  7984. blockRendererFn = _this$props2.blockRendererFn,
  7985. blockStyleFn = _this$props2.blockStyleFn,
  7986. customStyleFn = _this$props2.customStyleFn,
  7987. customStyleMap = _this$props2.customStyleMap,
  7988. editorState = _this$props2.editorState,
  7989. preventScroll = _this$props2.preventScroll,
  7990. readOnly = _this$props2.readOnly,
  7991. textAlignment = _this$props2.textAlignment,
  7992. textDirectionality = _this$props2.textDirectionality;
  7993. var rootClass = cx({
  7994. 'DraftEditor/root': true,
  7995. 'DraftEditor/alignLeft': textAlignment === 'left',
  7996. 'DraftEditor/alignRight': textAlignment === 'right',
  7997. 'DraftEditor/alignCenter': textAlignment === 'center'
  7998. });
  7999. var contentStyle = {
  8000. outline: 'none',
  8001. // fix parent-draggable Safari bug. #1326
  8002. userSelect: 'text',
  8003. WebkitUserSelect: 'text',
  8004. whiteSpace: 'pre-wrap',
  8005. wordWrap: 'break-word'
  8006. }; // The aria-expanded and aria-haspopup properties should only be rendered
  8007. // for a combobox.
  8008. /* $FlowFixMe(>=0.68.0 site=www,mobile) This comment suppresses an error
  8009. * found when Flow v0.68 was deployed. To see the error delete this comment
  8010. * and run Flow. */
  8011. var ariaRole = this.props.role || 'textbox';
  8012. var ariaExpanded = ariaRole === 'combobox' ? !!this.props.ariaExpanded : null;
  8013. var editorContentsProps = {
  8014. blockRenderMap: blockRenderMap,
  8015. blockRendererFn: blockRendererFn,
  8016. blockStyleFn: blockStyleFn,
  8017. customStyleMap: _objectSpread({}, DefaultDraftInlineStyle, customStyleMap),
  8018. customStyleFn: customStyleFn,
  8019. editorKey: this._editorKey,
  8020. editorState: editorState,
  8021. preventScroll: preventScroll,
  8022. textDirectionality: textDirectionality
  8023. };
  8024. return React.createElement("div", {
  8025. className: rootClass
  8026. }, this._renderPlaceholder(), React.createElement("div", {
  8027. className: cx('DraftEditor/editorContainer'),
  8028. ref: this._handleEditorContainerRef
  8029. }, React.createElement("div", {
  8030. "aria-activedescendant": readOnly ? null : this.props.ariaActiveDescendantID,
  8031. "aria-autocomplete": readOnly ? null : this.props.ariaAutoComplete,
  8032. "aria-controls": readOnly ? null : this.props.ariaControls,
  8033. "aria-describedby": this.props.ariaDescribedBy || this._placeholderAccessibilityID,
  8034. "aria-expanded": readOnly ? null : ariaExpanded,
  8035. "aria-label": this.props.ariaLabel,
  8036. "aria-labelledby": this.props.ariaLabelledBy,
  8037. "aria-multiline": this.props.ariaMultiline,
  8038. "aria-owns": readOnly ? null : this.props.ariaOwneeID,
  8039. autoCapitalize: this.props.autoCapitalize,
  8040. autoComplete: this.props.autoComplete,
  8041. autoCorrect: this.props.autoCorrect,
  8042. className: cx({
  8043. // Chrome's built-in translation feature mutates the DOM in ways
  8044. // that Draft doesn't expect (ex: adding <font> tags inside
  8045. // DraftEditorLeaf spans) and causes problems. We add notranslate
  8046. // here which makes its autotranslation skip over this subtree.
  8047. notranslate: !readOnly,
  8048. 'public/DraftEditor/content': true
  8049. }),
  8050. contentEditable: !readOnly,
  8051. "data-testid": this.props.webDriverTestID,
  8052. onBeforeInput: this._onBeforeInput,
  8053. onBlur: this._onBlur,
  8054. onCompositionEnd: this._onCompositionEnd,
  8055. onCompositionStart: this._onCompositionStart,
  8056. onCopy: this._onCopy,
  8057. onCut: this._onCut,
  8058. onDragEnd: this._onDragEnd,
  8059. onDragEnter: this.onDragEnter,
  8060. onDragLeave: this.onDragLeave,
  8061. onDragOver: this._onDragOver,
  8062. onDragStart: this._onDragStart,
  8063. onDrop: this._onDrop,
  8064. onFocus: this._onFocus,
  8065. onInput: this._onInput,
  8066. onKeyDown: this._onKeyDown,
  8067. onKeyPress: this._onKeyPress,
  8068. onKeyUp: this._onKeyUp,
  8069. onMouseUp: this._onMouseUp,
  8070. onPaste: this._onPaste,
  8071. onSelect: this._onSelect,
  8072. ref: this.props.editorRef,
  8073. role: readOnly ? null : ariaRole,
  8074. spellCheck: allowSpellCheck && this.props.spellCheck,
  8075. style: contentStyle,
  8076. suppressContentEditableWarning: true,
  8077. tabIndex: this.props.tabIndex
  8078. }, React.createElement(UpdateDraftEditorFlags, {
  8079. editor: this,
  8080. editorState: editorState
  8081. }), React.createElement(DraftEditorContents, _extends({}, editorContentsProps, {
  8082. key: 'contents' + this.state.contentsKey
  8083. })))));
  8084. };
  8085. _proto2.componentDidMount = function componentDidMount() {
  8086. this._blockSelectEvents = false;
  8087. if (!didInitODS && gkx('draft_ods_enabled')) {
  8088. didInitODS = true;
  8089. DraftEffects.initODS();
  8090. }
  8091. this.setMode('edit');
  8092. /**
  8093. * IE has a hardcoded "feature" that attempts to convert link text into
  8094. * anchors in contentEditable DOM. This breaks the editor's expectations of
  8095. * the DOM, and control is lost. Disable it to make IE behave.
  8096. * See: http://blogs.msdn.com/b/ieinternals/archive/2010/09/15/
  8097. * ie9-beta-minor-change-list.aspx
  8098. */
  8099. if (isIE) {
  8100. // editor can be null after mounting
  8101. // https://stackoverflow.com/questions/44074747/componentdidmount-called-before-ref-callback
  8102. if (!this.editor) {
  8103. global.execCommand('AutoUrlDetect', false, false);
  8104. } else {
  8105. this.editor.ownerDocument.execCommand('AutoUrlDetect', false, false);
  8106. }
  8107. }
  8108. };
  8109. _proto2.componentDidUpdate = function componentDidUpdate() {
  8110. this._blockSelectEvents = false;
  8111. this._latestEditorState = this.props.editorState;
  8112. this._latestCommittedEditorState = this.props.editorState;
  8113. }
  8114. /**
  8115. * Used via `this.focus()`.
  8116. *
  8117. * Force focus back onto the editor node.
  8118. *
  8119. * We attempt to preserve scroll position when focusing. You can also pass
  8120. * a specified scroll position (for cases like `cut` behavior where it should
  8121. * be restored to a known position).
  8122. */
  8123. ;
  8124. return DraftEditor;
  8125. }(React.Component);
  8126. _defineProperty(DraftEditor, "defaultProps", {
  8127. blockRenderMap: DefaultDraftBlockRenderMap,
  8128. blockRendererFn: function blockRendererFn() {
  8129. return null;
  8130. },
  8131. blockStyleFn: function blockStyleFn() {
  8132. return '';
  8133. },
  8134. keyBindingFn: getDefaultKeyBinding,
  8135. readOnly: false,
  8136. spellCheck: false,
  8137. stripPastedStyles: false
  8138. });
  8139. module.exports = DraftEditor;
  8140. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(25)))
  8141. /***/ }),
  8142. /* 96 */
  8143. /***/ (function(module, exports, __webpack_require__) {
  8144. "use strict";
  8145. /**
  8146. * Copyright (c) Facebook, Inc. and its affiliates.
  8147. *
  8148. * This source code is licensed under the MIT license found in the
  8149. * LICENSE file in the root directory of this source tree.
  8150. *
  8151. * @format
  8152. *
  8153. * @emails oncall+draft_js
  8154. */
  8155. var DOMObserver = __webpack_require__(97);
  8156. var DraftModifier = __webpack_require__(3);
  8157. var DraftOffsetKey = __webpack_require__(10);
  8158. var EditorState = __webpack_require__(2);
  8159. var Keys = __webpack_require__(28);
  8160. var editOnSelect = __webpack_require__(51);
  8161. var getContentEditableContainer = __webpack_require__(53);
  8162. var getDraftEditorSelection = __webpack_require__(54);
  8163. var getEntityKeyForSelection = __webpack_require__(35);
  8164. var nullthrows = __webpack_require__(4);
  8165. /**
  8166. * Millisecond delay to allow `compositionstart` to fire again upon
  8167. * `compositionend`.
  8168. *
  8169. * This is used for Korean input to ensure that typing can continue without
  8170. * the editor trying to render too quickly. More specifically, Safari 7.1+
  8171. * triggers `compositionstart` a little slower than Chrome/FF, which
  8172. * leads to composed characters being resolved and re-render occurring
  8173. * sooner than we want.
  8174. */
  8175. var RESOLVE_DELAY = 20;
  8176. /**
  8177. * A handful of variables used to track the current composition and its
  8178. * resolution status. These exist at the module level because it is not
  8179. * possible to have compositions occurring in multiple editors simultaneously,
  8180. * and it simplifies state management with respect to the DraftEditor component.
  8181. */
  8182. var resolved = false;
  8183. var stillComposing = false;
  8184. var domObserver = null;
  8185. function startDOMObserver(editor) {
  8186. if (!domObserver) {
  8187. domObserver = new DOMObserver(getContentEditableContainer(editor));
  8188. domObserver.start();
  8189. }
  8190. }
  8191. var DraftEditorCompositionHandler = {
  8192. /**
  8193. * A `compositionstart` event has fired while we're still in composition
  8194. * mode. Continue the current composition session to prevent a re-render.
  8195. */
  8196. onCompositionStart: function onCompositionStart(editor) {
  8197. stillComposing = true;
  8198. startDOMObserver(editor);
  8199. },
  8200. /**
  8201. * Attempt to end the current composition session.
  8202. *
  8203. * Defer handling because browser will still insert the chars into active
  8204. * element after `compositionend`. If a `compositionstart` event fires
  8205. * before `resolveComposition` executes, our composition session will
  8206. * continue.
  8207. *
  8208. * The `resolved` flag is useful because certain IME interfaces fire the
  8209. * `compositionend` event multiple times, thus queueing up multiple attempts
  8210. * at handling the composition. Since handling the same composition event
  8211. * twice could break the DOM, we only use the first event. Example: Arabic
  8212. * Google Input Tools on Windows 8.1 fires `compositionend` three times.
  8213. */
  8214. onCompositionEnd: function onCompositionEnd(editor) {
  8215. resolved = false;
  8216. stillComposing = false;
  8217. setTimeout(function () {
  8218. if (!resolved) {
  8219. DraftEditorCompositionHandler.resolveComposition(editor);
  8220. }
  8221. }, RESOLVE_DELAY);
  8222. },
  8223. onSelect: editOnSelect,
  8224. /**
  8225. * In Safari, keydown events may fire when committing compositions. If
  8226. * the arrow keys are used to commit, prevent default so that the cursor
  8227. * doesn't move, otherwise it will jump back noticeably on re-render.
  8228. */
  8229. onKeyDown: function onKeyDown(editor, e) {
  8230. if (!stillComposing) {
  8231. // If a keydown event is received after compositionend but before the
  8232. // 20ms timer expires (ex: type option-E then backspace, or type A then
  8233. // backspace in 2-Set Korean), we should immediately resolve the
  8234. // composition and reinterpret the key press in edit mode.
  8235. DraftEditorCompositionHandler.resolveComposition(editor);
  8236. editor._onKeyDown(e);
  8237. return;
  8238. }
  8239. if (e.which === Keys.RIGHT || e.which === Keys.LEFT) {
  8240. e.preventDefault();
  8241. }
  8242. },
  8243. /**
  8244. * Keypress events may fire when committing compositions. In Firefox,
  8245. * pressing RETURN commits the composition and inserts extra newline
  8246. * characters that we do not want. `preventDefault` allows the composition
  8247. * to be committed while preventing the extra characters.
  8248. */
  8249. onKeyPress: function onKeyPress(editor, e) {
  8250. if (e.which === Keys.RETURN) {
  8251. e.preventDefault();
  8252. }
  8253. },
  8254. /**
  8255. * Attempt to insert composed characters into the document.
  8256. *
  8257. * If we are still in a composition session, do nothing. Otherwise, insert
  8258. * the characters into the document and terminate the composition session.
  8259. *
  8260. * If no characters were composed -- for instance, the user
  8261. * deleted all composed characters and committed nothing new --
  8262. * force a re-render. We also re-render when the composition occurs
  8263. * at the beginning of a leaf, to ensure that if the browser has
  8264. * created a new text node for the composition, we will discard it.
  8265. *
  8266. * Resetting innerHTML will move focus to the beginning of the editor,
  8267. * so we update to force it back to the correct place.
  8268. */
  8269. resolveComposition: function resolveComposition(editor) {
  8270. if (stillComposing) {
  8271. return;
  8272. }
  8273. var mutations = nullthrows(domObserver).stopAndFlushMutations();
  8274. domObserver = null;
  8275. resolved = true;
  8276. var editorState = EditorState.set(editor._latestEditorState, {
  8277. inCompositionMode: false
  8278. });
  8279. editor.exitCurrentMode();
  8280. if (!mutations.size) {
  8281. editor.update(editorState);
  8282. return;
  8283. } // TODO, check if Facebook still needs this flag or if it could be removed.
  8284. // Since there can be multiple mutations providing a `composedChars` doesn't
  8285. // apply well on this new model.
  8286. // if (
  8287. // gkx('draft_handlebeforeinput_composed_text') &&
  8288. // editor.props.handleBeforeInput &&
  8289. // isEventHandled(
  8290. // editor.props.handleBeforeInput(
  8291. // composedChars,
  8292. // editorState,
  8293. // event.timeStamp,
  8294. // ),
  8295. // )
  8296. // ) {
  8297. // return;
  8298. // }
  8299. var contentState = editorState.getCurrentContent();
  8300. mutations.forEach(function (composedChars, offsetKey) {
  8301. var _DraftOffsetKey$decod = DraftOffsetKey.decode(offsetKey),
  8302. blockKey = _DraftOffsetKey$decod.blockKey,
  8303. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  8304. leafKey = _DraftOffsetKey$decod.leafKey;
  8305. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  8306. start = _editorState$getBlock.start,
  8307. end = _editorState$getBlock.end;
  8308. var replacementRange = editorState.getSelection().merge({
  8309. anchorKey: blockKey,
  8310. focusKey: blockKey,
  8311. anchorOffset: start,
  8312. focusOffset: end,
  8313. isBackward: false
  8314. });
  8315. var entityKey = getEntityKeyForSelection(contentState, replacementRange);
  8316. var currentStyle = contentState.getBlockForKey(blockKey).getInlineStyleAt(start);
  8317. contentState = DraftModifier.replaceText(contentState, replacementRange, composedChars, currentStyle, entityKey); // We need to update the editorState so the leaf node ranges are properly
  8318. // updated and multiple mutations are correctly applied.
  8319. editorState = EditorState.set(editorState, {
  8320. currentContent: contentState
  8321. });
  8322. }); // When we apply the text changes to the ContentState, the selection always
  8323. // goes to the end of the field, but it should just stay where it is
  8324. // after compositionEnd.
  8325. var documentSelection = getDraftEditorSelection(editorState, getContentEditableContainer(editor));
  8326. var compositionEndSelectionState = documentSelection.selectionState;
  8327. editor.restoreEditorDOM();
  8328. var editorStateWithUpdatedSelection = EditorState.acceptSelection(editorState, compositionEndSelectionState);
  8329. editor.update(EditorState.push(editorStateWithUpdatedSelection, contentState, 'insert-characters'));
  8330. }
  8331. };
  8332. module.exports = DraftEditorCompositionHandler;
  8333. /***/ }),
  8334. /* 97 */
  8335. /***/ (function(module, exports, __webpack_require__) {
  8336. "use strict";
  8337. /**
  8338. * Copyright (c) Facebook, Inc. and its affiliates.
  8339. *
  8340. * This source code is licensed under the MIT license found in the
  8341. * LICENSE file in the root directory of this source tree.
  8342. *
  8343. * @format
  8344. *
  8345. * @emails oncall+draft_js
  8346. */
  8347. 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; }
  8348. var UserAgent = __webpack_require__(5);
  8349. var findAncestorOffsetKey = __webpack_require__(26);
  8350. var getWindowForNode = __webpack_require__(50);
  8351. var Immutable = __webpack_require__(0);
  8352. var invariant = __webpack_require__(1);
  8353. var nullthrows = __webpack_require__(4);
  8354. var Map = Immutable.Map;
  8355. // Heavily based on Prosemirror's DOMObserver https://github.com/ProseMirror/prosemirror-view/blob/master/src/domobserver.js
  8356. var DOM_OBSERVER_OPTIONS = {
  8357. subtree: true,
  8358. characterData: true,
  8359. childList: true,
  8360. characterDataOldValue: false,
  8361. attributes: false
  8362. }; // IE11 has very broken mutation observers, so we also listen to DOMCharacterDataModified
  8363. var USE_CHAR_DATA = UserAgent.isBrowser('IE <= 11');
  8364. var DOMObserver =
  8365. /*#__PURE__*/
  8366. function () {
  8367. function DOMObserver(container) {
  8368. var _this = this;
  8369. _defineProperty(this, "observer", void 0);
  8370. _defineProperty(this, "container", void 0);
  8371. _defineProperty(this, "mutations", void 0);
  8372. _defineProperty(this, "onCharData", void 0);
  8373. this.container = container;
  8374. this.mutations = Map();
  8375. var containerWindow = getWindowForNode(container);
  8376. if (containerWindow.MutationObserver && !USE_CHAR_DATA) {
  8377. this.observer = new containerWindow.MutationObserver(function (mutations) {
  8378. return _this.registerMutations(mutations);
  8379. });
  8380. } else {
  8381. this.onCharData = function (e) {
  8382. !(e.target instanceof Node) ? true ? invariant(false, 'Expected target to be an instance of Node') : invariant(false) : void 0;
  8383. _this.registerMutation({
  8384. type: 'characterData',
  8385. target: e.target
  8386. });
  8387. };
  8388. }
  8389. }
  8390. var _proto = DOMObserver.prototype;
  8391. _proto.start = function start() {
  8392. if (this.observer) {
  8393. this.observer.observe(this.container, DOM_OBSERVER_OPTIONS);
  8394. } else {
  8395. /* $FlowFixMe(>=0.68.0 site=www,mobile) This event type is not defined
  8396. * by Flow's standard library */
  8397. this.container.addEventListener('DOMCharacterDataModified', this.onCharData);
  8398. }
  8399. };
  8400. _proto.stopAndFlushMutations = function stopAndFlushMutations() {
  8401. var observer = this.observer;
  8402. if (observer) {
  8403. this.registerMutations(observer.takeRecords());
  8404. observer.disconnect();
  8405. } else {
  8406. /* $FlowFixMe(>=0.68.0 site=www,mobile) This event type is not defined
  8407. * by Flow's standard library */
  8408. this.container.removeEventListener('DOMCharacterDataModified', this.onCharData);
  8409. }
  8410. var mutations = this.mutations;
  8411. this.mutations = Map();
  8412. return mutations;
  8413. };
  8414. _proto.registerMutations = function registerMutations(mutations) {
  8415. for (var i = 0; i < mutations.length; i++) {
  8416. this.registerMutation(mutations[i]);
  8417. }
  8418. };
  8419. _proto.getMutationTextContent = function getMutationTextContent(mutation) {
  8420. var type = mutation.type,
  8421. target = mutation.target,
  8422. removedNodes = mutation.removedNodes;
  8423. if (type === 'characterData') {
  8424. // When `textContent` is '', there is a race condition that makes
  8425. // getting the offsetKey from the target not possible.
  8426. // These events are also followed by a `childList`, which is the one
  8427. // we are able to retrieve the offsetKey and apply the '' text.
  8428. if (target.textContent !== '') {
  8429. // IE 11 considers the enter keypress that concludes the composition
  8430. // as an input char. This strips that newline character so the draft
  8431. // state does not receive spurious newlines.
  8432. if (USE_CHAR_DATA) {
  8433. return target.textContent.replace('\n', '');
  8434. }
  8435. return target.textContent;
  8436. }
  8437. } else if (type === 'childList') {
  8438. if (removedNodes && removedNodes.length) {
  8439. // `characterData` events won't happen or are ignored when
  8440. // removing the last character of a leaf node, what happens
  8441. // instead is a `childList` event with a `removedNodes` array.
  8442. // For this case the textContent should be '' and
  8443. // `DraftModifier.replaceText` will make sure the content is
  8444. // updated properly.
  8445. return '';
  8446. } else if (target.textContent !== '') {
  8447. // Typing Chinese in an empty block in MS Edge results in a
  8448. // `childList` event with non-empty textContent.
  8449. // See https://github.com/facebook/draft-js/issues/2082
  8450. return target.textContent;
  8451. }
  8452. }
  8453. return null;
  8454. };
  8455. _proto.registerMutation = function registerMutation(mutation) {
  8456. var textContent = this.getMutationTextContent(mutation);
  8457. if (textContent != null) {
  8458. var offsetKey = nullthrows(findAncestorOffsetKey(mutation.target));
  8459. this.mutations = this.mutations.set(offsetKey, textContent);
  8460. }
  8461. };
  8462. return DOMObserver;
  8463. }();
  8464. module.exports = DOMObserver;
  8465. /***/ }),
  8466. /* 98 */
  8467. /***/ (function(module, exports, __webpack_require__) {
  8468. "use strict";
  8469. /**
  8470. * Copyright (c) 2013-present, Facebook, Inc.
  8471. *
  8472. * This source code is licensed under the MIT license found in the
  8473. * LICENSE file in the root directory of this source tree.
  8474. *
  8475. */
  8476. /**
  8477. * Usage note:
  8478. * This module makes a best effort to export the same data we would internally.
  8479. * At Facebook we use a server-generated module that does the parsing and
  8480. * exports the data for the client to use. We can't rely on a server-side
  8481. * implementation in open source so instead we make use of an open source
  8482. * library to do the heavy lifting and then make some adjustments as necessary.
  8483. * It's likely there will be some differences. Some we can smooth over.
  8484. * Others are going to be harder.
  8485. */
  8486. var UAParser = __webpack_require__(99);
  8487. var UNKNOWN = 'Unknown';
  8488. var PLATFORM_MAP = {
  8489. 'Mac OS': 'Mac OS X'
  8490. };
  8491. /**
  8492. * Convert from UAParser platform name to what we expect.
  8493. */
  8494. function convertPlatformName(name) {
  8495. return PLATFORM_MAP[name] || name;
  8496. }
  8497. /**
  8498. * Get the version number in parts. This is very naive. We actually get major
  8499. * version as a part of UAParser already, which is generally good enough, but
  8500. * let's get the minor just in case.
  8501. */
  8502. function getBrowserVersion(version) {
  8503. if (!version) {
  8504. return {
  8505. major: '',
  8506. minor: ''
  8507. };
  8508. }
  8509. var parts = version.split('.');
  8510. return {
  8511. major: parts[0],
  8512. minor: parts[1]
  8513. };
  8514. }
  8515. /**
  8516. * Get the UA data fom UAParser and then convert it to the format we're
  8517. * expecting for our APIS.
  8518. */
  8519. var parser = new UAParser();
  8520. var results = parser.getResult(); // Do some conversion first.
  8521. var browserVersionData = getBrowserVersion(results.browser.version);
  8522. var uaData = {
  8523. browserArchitecture: results.cpu.architecture || UNKNOWN,
  8524. browserFullVersion: results.browser.version || UNKNOWN,
  8525. browserMinorVersion: browserVersionData.minor || UNKNOWN,
  8526. browserName: results.browser.name || UNKNOWN,
  8527. browserVersion: results.browser.major || UNKNOWN,
  8528. deviceName: results.device.model || UNKNOWN,
  8529. engineName: results.engine.name || UNKNOWN,
  8530. engineVersion: results.engine.version || UNKNOWN,
  8531. platformArchitecture: results.cpu.architecture || UNKNOWN,
  8532. platformName: convertPlatformName(results.os.name) || UNKNOWN,
  8533. platformVersion: results.os.version || UNKNOWN,
  8534. platformFullVersion: results.os.version || UNKNOWN
  8535. };
  8536. module.exports = uaData;
  8537. /***/ }),
  8538. /* 99 */
  8539. /***/ (function(module, exports, __webpack_require__) {
  8540. var __WEBPACK_AMD_DEFINE_RESULT__;/*!
  8541. * UAParser.js v0.7.19
  8542. * Lightweight JavaScript-based User-Agent string parser
  8543. * https://github.com/faisalman/ua-parser-js
  8544. *
  8545. * Copyright © 2012-2016 Faisal Salman <fyzlman@gmail.com>
  8546. * Dual licensed under GPLv2 or MIT
  8547. */
  8548. (function (window, undefined) {
  8549. 'use strict';
  8550. //////////////
  8551. // Constants
  8552. /////////////
  8553. var LIBVERSION = '0.7.19',
  8554. EMPTY = '',
  8555. UNKNOWN = '?',
  8556. FUNC_TYPE = 'function',
  8557. UNDEF_TYPE = 'undefined',
  8558. OBJ_TYPE = 'object',
  8559. STR_TYPE = 'string',
  8560. MAJOR = 'major', // deprecated
  8561. MODEL = 'model',
  8562. NAME = 'name',
  8563. TYPE = 'type',
  8564. VENDOR = 'vendor',
  8565. VERSION = 'version',
  8566. ARCHITECTURE= 'architecture',
  8567. CONSOLE = 'console',
  8568. MOBILE = 'mobile',
  8569. TABLET = 'tablet',
  8570. SMARTTV = 'smarttv',
  8571. WEARABLE = 'wearable',
  8572. EMBEDDED = 'embedded';
  8573. ///////////
  8574. // Helper
  8575. //////////
  8576. var util = {
  8577. extend : function (regexes, extensions) {
  8578. var margedRegexes = {};
  8579. for (var i in regexes) {
  8580. if (extensions[i] && extensions[i].length % 2 === 0) {
  8581. margedRegexes[i] = extensions[i].concat(regexes[i]);
  8582. } else {
  8583. margedRegexes[i] = regexes[i];
  8584. }
  8585. }
  8586. return margedRegexes;
  8587. },
  8588. has : function (str1, str2) {
  8589. if (typeof str1 === "string") {
  8590. return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
  8591. } else {
  8592. return false;
  8593. }
  8594. },
  8595. lowerize : function (str) {
  8596. return str.toLowerCase();
  8597. },
  8598. major : function (version) {
  8599. return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g,'').split(".")[0] : undefined;
  8600. },
  8601. trim : function (str) {
  8602. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  8603. }
  8604. };
  8605. ///////////////
  8606. // Map helper
  8607. //////////////
  8608. var mapper = {
  8609. rgx : function (ua, arrays) {
  8610. //var result = {},
  8611. var i = 0, j, k, p, q, matches, match;//, args = arguments;
  8612. /*// construct object barebones
  8613. for (p = 0; p < args[1].length; p++) {
  8614. q = args[1][p];
  8615. result[typeof q === OBJ_TYPE ? q[0] : q] = undefined;
  8616. }*/
  8617. // loop through all regexes maps
  8618. while (i < arrays.length && !matches) {
  8619. var regex = arrays[i], // even sequence (0,2,4,..)
  8620. props = arrays[i + 1]; // odd sequence (1,3,5,..)
  8621. j = k = 0;
  8622. // try matching uastring with regexes
  8623. while (j < regex.length && !matches) {
  8624. matches = regex[j++].exec(ua);
  8625. if (!!matches) {
  8626. for (p = 0; p < props.length; p++) {
  8627. match = matches[++k];
  8628. q = props[p];
  8629. // check if given property is actually array
  8630. if (typeof q === OBJ_TYPE && q.length > 0) {
  8631. if (q.length == 2) {
  8632. if (typeof q[1] == FUNC_TYPE) {
  8633. // assign modified match
  8634. this[q[0]] = q[1].call(this, match);
  8635. } else {
  8636. // assign given value, ignore regex match
  8637. this[q[0]] = q[1];
  8638. }
  8639. } else if (q.length == 3) {
  8640. // check whether function or regex
  8641. if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
  8642. // call function (usually string mapper)
  8643. this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined;
  8644. } else {
  8645. // sanitize match using given regex
  8646. this[q[0]] = match ? match.replace(q[1], q[2]) : undefined;
  8647. }
  8648. } else if (q.length == 4) {
  8649. this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined;
  8650. }
  8651. } else {
  8652. this[q] = match ? match : undefined;
  8653. }
  8654. }
  8655. }
  8656. }
  8657. i += 2;
  8658. }
  8659. // console.log(this);
  8660. //return this;
  8661. },
  8662. str : function (str, map) {
  8663. for (var i in map) {
  8664. // check if array
  8665. if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
  8666. for (var j = 0; j < map[i].length; j++) {
  8667. if (util.has(map[i][j], str)) {
  8668. return (i === UNKNOWN) ? undefined : i;
  8669. }
  8670. }
  8671. } else if (util.has(map[i], str)) {
  8672. return (i === UNKNOWN) ? undefined : i;
  8673. }
  8674. }
  8675. return str;
  8676. }
  8677. };
  8678. ///////////////
  8679. // String map
  8680. //////////////
  8681. var maps = {
  8682. browser : {
  8683. oldsafari : {
  8684. version : {
  8685. '1.0' : '/8',
  8686. '1.2' : '/1',
  8687. '1.3' : '/3',
  8688. '2.0' : '/412',
  8689. '2.0.2' : '/416',
  8690. '2.0.3' : '/417',
  8691. '2.0.4' : '/419',
  8692. '?' : '/'
  8693. }
  8694. }
  8695. },
  8696. device : {
  8697. amazon : {
  8698. model : {
  8699. 'Fire Phone' : ['SD', 'KF']
  8700. }
  8701. },
  8702. sprint : {
  8703. model : {
  8704. 'Evo Shift 4G' : '7373KT'
  8705. },
  8706. vendor : {
  8707. 'HTC' : 'APA',
  8708. 'Sprint' : 'Sprint'
  8709. }
  8710. }
  8711. },
  8712. os : {
  8713. windows : {
  8714. version : {
  8715. 'ME' : '4.90',
  8716. 'NT 3.11' : 'NT3.51',
  8717. 'NT 4.0' : 'NT4.0',
  8718. '2000' : 'NT 5.0',
  8719. 'XP' : ['NT 5.1', 'NT 5.2'],
  8720. 'Vista' : 'NT 6.0',
  8721. '7' : 'NT 6.1',
  8722. '8' : 'NT 6.2',
  8723. '8.1' : 'NT 6.3',
  8724. '10' : ['NT 6.4', 'NT 10.0'],
  8725. 'RT' : 'ARM'
  8726. }
  8727. }
  8728. }
  8729. };
  8730. //////////////
  8731. // Regex map
  8732. /////////////
  8733. var regexes = {
  8734. browser : [[
  8735. // Presto based
  8736. /(opera\smini)\/([\w\.-]+)/i, // Opera Mini
  8737. /(opera\s[mobiletab]+).+version\/([\w\.-]+)/i, // Opera Mobi/Tablet
  8738. /(opera).+version\/([\w\.]+)/i, // Opera > 9.80
  8739. /(opera)[\/\s]+([\w\.]+)/i // Opera < 9.80
  8740. ], [NAME, VERSION], [
  8741. /(opios)[\/\s]+([\w\.]+)/i // Opera mini on iphone >= 8.0
  8742. ], [[NAME, 'Opera Mini'], VERSION], [
  8743. /\s(opr)\/([\w\.]+)/i // Opera Webkit
  8744. ], [[NAME, 'Opera'], VERSION], [
  8745. // Mixed
  8746. /(kindle)\/([\w\.]+)/i, // Kindle
  8747. /(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]*)/i,
  8748. // Lunascape/Maxthon/Netfront/Jasmine/Blazer
  8749. // Trident based
  8750. /(avant\s|iemobile|slim|baidu)(?:browser)?[\/\s]?([\w\.]*)/i,
  8751. // Avant/IEMobile/SlimBrowser/Baidu
  8752. /(?:ms|\()(ie)\s([\w\.]+)/i, // Internet Explorer
  8753. // Webkit/KHTML based
  8754. /(rekonq)\/([\w\.]*)/i, // Rekonq
  8755. /(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark)\/([\w\.-]+)/i
  8756. // Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser
  8757. ], [NAME, VERSION], [
  8758. /(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
  8759. ], [[NAME, 'IE'], VERSION], [
  8760. /(edge|edgios|edga)\/((\d+)?[\w\.]+)/i // Microsoft Edge
  8761. ], [[NAME, 'Edge'], VERSION], [
  8762. /(yabrowser)\/([\w\.]+)/i // Yandex
  8763. ], [[NAME, 'Yandex'], VERSION], [
  8764. /(puffin)\/([\w\.]+)/i // Puffin
  8765. ], [[NAME, 'Puffin'], VERSION], [
  8766. /(focus)\/([\w\.]+)/i // Firefox Focus
  8767. ], [[NAME, 'Firefox Focus'], VERSION], [
  8768. /(opt)\/([\w\.]+)/i // Opera Touch
  8769. ], [[NAME, 'Opera Touch'], VERSION], [
  8770. /((?:[\s\/])uc?\s?browser|(?:juc.+)ucweb)[\/\s]?([\w\.]+)/i // UCBrowser
  8771. ], [[NAME, 'UCBrowser'], VERSION], [
  8772. /(comodo_dragon)\/([\w\.]+)/i // Comodo Dragon
  8773. ], [[NAME, /_/g, ' '], VERSION], [
  8774. /(micromessenger)\/([\w\.]+)/i // WeChat
  8775. ], [[NAME, 'WeChat'], VERSION], [
  8776. /(brave)\/([\w\.]+)/i // Brave browser
  8777. ], [[NAME, 'Brave'], VERSION], [
  8778. /(qqbrowserlite)\/([\w\.]+)/i // QQBrowserLite
  8779. ], [NAME, VERSION], [
  8780. /(QQ)\/([\d\.]+)/i // QQ, aka ShouQ
  8781. ], [NAME, VERSION], [
  8782. /m?(qqbrowser)[\/\s]?([\w\.]+)/i // QQBrowser
  8783. ], [NAME, VERSION], [
  8784. /(BIDUBrowser)[\/\s]?([\w\.]+)/i // Baidu Browser
  8785. ], [NAME, VERSION], [
  8786. /(2345Explorer)[\/\s]?([\w\.]+)/i // 2345 Browser
  8787. ], [NAME, VERSION], [
  8788. /(MetaSr)[\/\s]?([\w\.]+)/i // SouGouBrowser
  8789. ], [NAME], [
  8790. /(LBBROWSER)/i // LieBao Browser
  8791. ], [NAME], [
  8792. /xiaomi\/miuibrowser\/([\w\.]+)/i // MIUI Browser
  8793. ], [VERSION, [NAME, 'MIUI Browser']], [
  8794. /;fbav\/([\w\.]+);/i // Facebook App for iOS & Android
  8795. ], [VERSION, [NAME, 'Facebook']], [
  8796. /safari\s(line)\/([\w\.]+)/i, // Line App for iOS
  8797. /android.+(line)\/([\w\.]+)\/iab/i // Line App for Android
  8798. ], [NAME, VERSION], [
  8799. /headlesschrome(?:\/([\w\.]+)|\s)/i // Chrome Headless
  8800. ], [VERSION, [NAME, 'Chrome Headless']], [
  8801. /\swv\).+(chrome)\/([\w\.]+)/i // Chrome WebView
  8802. ], [[NAME, /(.+)/, '$1 WebView'], VERSION], [
  8803. /((?:oculus|samsung)browser)\/([\w\.]+)/i
  8804. ], [[NAME, /(.+(?:g|us))(.+)/, '$1 $2'], VERSION], [ // Oculus / Samsung Browser
  8805. /android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)*/i // Android Browser
  8806. ], [VERSION, [NAME, 'Android Browser']], [
  8807. /(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i
  8808. // Chrome/OmniWeb/Arora/Tizen/Nokia
  8809. ], [NAME, VERSION], [
  8810. /(dolfin)\/([\w\.]+)/i // Dolphin
  8811. ], [[NAME, 'Dolphin'], VERSION], [
  8812. /((?:android.+)crmo|crios)\/([\w\.]+)/i // Chrome for Android/iOS
  8813. ], [[NAME, 'Chrome'], VERSION], [
  8814. /(coast)\/([\w\.]+)/i // Opera Coast
  8815. ], [[NAME, 'Opera Coast'], VERSION], [
  8816. /fxios\/([\w\.-]+)/i // Firefox for iOS
  8817. ], [VERSION, [NAME, 'Firefox']], [
  8818. /version\/([\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
  8819. ], [VERSION, [NAME, 'Mobile Safari']], [
  8820. /version\/([\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
  8821. ], [VERSION, NAME], [
  8822. /webkit.+?(gsa)\/([\w\.]+).+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Google Search Appliance on iOS
  8823. ], [[NAME, 'GSA'], VERSION], [
  8824. /webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i // Safari < 3.0
  8825. ], [NAME, [VERSION, mapper.str, maps.browser.oldsafari.version]], [
  8826. /(konqueror)\/([\w\.]+)/i, // Konqueror
  8827. /(webkit|khtml)\/([\w\.]+)/i
  8828. ], [NAME, VERSION], [
  8829. // Gecko based
  8830. /(navigator|netscape)\/([\w\.-]+)/i // Netscape
  8831. ], [[NAME, 'Netscape'], VERSION], [
  8832. /(swiftfox)/i, // Swiftfox
  8833. /(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
  8834. // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
  8835. /(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([\w\.-]+)$/i,
  8836. // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
  8837. /(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
  8838. // Other
  8839. /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,
  8840. // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir
  8841. /(links)\s\(([\w\.]+)/i, // Links
  8842. /(gobrowser)\/?([\w\.]*)/i, // GoBrowser
  8843. /(ice\s?browser)\/v?([\w\._]+)/i, // ICE Browser
  8844. /(mosaic)[\/\s]([\w\.]+)/i // Mosaic
  8845. ], [NAME, VERSION]
  8846. /* /////////////////////
  8847. // Media players BEGIN
  8848. ////////////////////////
  8849. , [
  8850. /(apple(?:coremedia|))\/((\d+)[\w\._]+)/i, // Generic Apple CoreMedia
  8851. /(coremedia) v((\d+)[\w\._]+)/i
  8852. ], [NAME, VERSION], [
  8853. /(aqualung|lyssna|bsplayer)\/((\d+)?[\w\.-]+)/i // Aqualung/Lyssna/BSPlayer
  8854. ], [NAME, VERSION], [
  8855. /(ares|ossproxy)\s((\d+)[\w\.-]+)/i // Ares/OSSProxy
  8856. ], [NAME, VERSION], [
  8857. /(audacious|audimusicstream|amarok|bass|core|dalvik|gnomemplayer|music on console|nsplayer|psp-internetradioplayer|videos)\/((\d+)[\w\.-]+)/i,
  8858. // Audacious/AudiMusicStream/Amarok/BASS/OpenCORE/Dalvik/GnomeMplayer/MoC
  8859. // NSPlayer/PSP-InternetRadioPlayer/Videos
  8860. /(clementine|music player daemon)\s((\d+)[\w\.-]+)/i, // Clementine/MPD
  8861. /(lg player|nexplayer)\s((\d+)[\d\.]+)/i,
  8862. /player\/(nexplayer|lg player)\s((\d+)[\w\.-]+)/i // NexPlayer/LG Player
  8863. ], [NAME, VERSION], [
  8864. /(nexplayer)\s((\d+)[\w\.-]+)/i // Nexplayer
  8865. ], [NAME, VERSION], [
  8866. /(flrp)\/((\d+)[\w\.-]+)/i // Flip Player
  8867. ], [[NAME, 'Flip Player'], VERSION], [
  8868. /(fstream|nativehost|queryseekspider|ia-archiver|facebookexternalhit)/i
  8869. // FStream/NativeHost/QuerySeekSpider/IA Archiver/facebookexternalhit
  8870. ], [NAME], [
  8871. /(gstreamer) souphttpsrc (?:\([^\)]+\)){0,1} libsoup\/((\d+)[\w\.-]+)/i
  8872. // Gstreamer
  8873. ], [NAME, VERSION], [
  8874. /(htc streaming player)\s[\w_]+\s\/\s((\d+)[\d\.]+)/i, // HTC Streaming Player
  8875. /(java|python-urllib|python-requests|wget|libcurl)\/((\d+)[\w\.-_]+)/i,
  8876. // Java/urllib/requests/wget/cURL
  8877. /(lavf)((\d+)[\d\.]+)/i // Lavf (FFMPEG)
  8878. ], [NAME, VERSION], [
  8879. /(htc_one_s)\/((\d+)[\d\.]+)/i // HTC One S
  8880. ], [[NAME, /_/g, ' '], VERSION], [
  8881. /(mplayer)(?:\s|\/)(?:(?:sherpya-){0,1}svn)(?:-|\s)(r\d+(?:-\d+[\w\.-]+){0,1})/i
  8882. // MPlayer SVN
  8883. ], [NAME, VERSION], [
  8884. /(mplayer)(?:\s|\/|[unkow-]+)((\d+)[\w\.-]+)/i // MPlayer
  8885. ], [NAME, VERSION], [
  8886. /(mplayer)/i, // MPlayer (no other info)
  8887. /(yourmuze)/i, // YourMuze
  8888. /(media player classic|nero showtime)/i // Media Player Classic/Nero ShowTime
  8889. ], [NAME], [
  8890. /(nero (?:home|scout))\/((\d+)[\w\.-]+)/i // Nero Home/Nero Scout
  8891. ], [NAME, VERSION], [
  8892. /(nokia\d+)\/((\d+)[\w\.-]+)/i // Nokia
  8893. ], [NAME, VERSION], [
  8894. /\s(songbird)\/((\d+)[\w\.-]+)/i // Songbird/Philips-Songbird
  8895. ], [NAME, VERSION], [
  8896. /(winamp)3 version ((\d+)[\w\.-]+)/i, // Winamp
  8897. /(winamp)\s((\d+)[\w\.-]+)/i,
  8898. /(winamp)mpeg\/((\d+)[\w\.-]+)/i
  8899. ], [NAME, VERSION], [
  8900. /(ocms-bot|tapinradio|tunein radio|unknown|winamp|inlight radio)/i // OCMS-bot/tap in radio/tunein/unknown/winamp (no other info)
  8901. // inlight radio
  8902. ], [NAME], [
  8903. /(quicktime|rma|radioapp|radioclientapplication|soundtap|totem|stagefright|streamium)\/((\d+)[\w\.-]+)/i
  8904. // QuickTime/RealMedia/RadioApp/RadioClientApplication/
  8905. // SoundTap/Totem/Stagefright/Streamium
  8906. ], [NAME, VERSION], [
  8907. /(smp)((\d+)[\d\.]+)/i // SMP
  8908. ], [NAME, VERSION], [
  8909. /(vlc) media player - version ((\d+)[\w\.]+)/i, // VLC Videolan
  8910. /(vlc)\/((\d+)[\w\.-]+)/i,
  8911. /(xbmc|gvfs|xine|xmms|irapp)\/((\d+)[\w\.-]+)/i, // XBMC/gvfs/Xine/XMMS/irapp
  8912. /(foobar2000)\/((\d+)[\d\.]+)/i, // Foobar2000
  8913. /(itunes)\/((\d+)[\d\.]+)/i // iTunes
  8914. ], [NAME, VERSION], [
  8915. /(wmplayer)\/((\d+)[\w\.-]+)/i, // Windows Media Player
  8916. /(windows-media-player)\/((\d+)[\w\.-]+)/i
  8917. ], [[NAME, /-/g, ' '], VERSION], [
  8918. /windows\/((\d+)[\w\.-]+) upnp\/[\d\.]+ dlnadoc\/[\d\.]+ (home media server)/i
  8919. // Windows Media Server
  8920. ], [VERSION, [NAME, 'Windows']], [
  8921. /(com\.riseupradioalarm)\/((\d+)[\d\.]*)/i // RiseUP Radio Alarm
  8922. ], [NAME, VERSION], [
  8923. /(rad.io)\s((\d+)[\d\.]+)/i, // Rad.io
  8924. /(radio.(?:de|at|fr))\s((\d+)[\d\.]+)/i
  8925. ], [[NAME, 'rad.io'], VERSION]
  8926. //////////////////////
  8927. // Media players END
  8928. ////////////////////*/
  8929. ],
  8930. cpu : [[
  8931. /(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
  8932. ], [[ARCHITECTURE, 'amd64']], [
  8933. /(ia32(?=;))/i // IA32 (quicktime)
  8934. ], [[ARCHITECTURE, util.lowerize]], [
  8935. /((?:i[346]|x)86)[;\)]/i // IA32
  8936. ], [[ARCHITECTURE, 'ia32']], [
  8937. // PocketPC mistakenly identified as PowerPC
  8938. /windows\s(ce|mobile);\sppc;/i
  8939. ], [[ARCHITECTURE, 'arm']], [
  8940. /((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
  8941. ], [[ARCHITECTURE, /ower/, '', util.lowerize]], [
  8942. /(sun4\w)[;\)]/i // SPARC
  8943. ], [[ARCHITECTURE, 'sparc']], [
  8944. /((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+[;l]))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
  8945. // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
  8946. ], [[ARCHITECTURE, util.lowerize]]
  8947. ],
  8948. device : [[
  8949. /\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook
  8950. ], [MODEL, VENDOR, [TYPE, TABLET]], [
  8951. /applecoremedia\/[\w\.]+ \((ipad)/ // iPad
  8952. ], [MODEL, [VENDOR, 'Apple'], [TYPE, TABLET]], [
  8953. /(apple\s{0,1}tv)/i // Apple TV
  8954. ], [[MODEL, 'Apple TV'], [VENDOR, 'Apple']], [
  8955. /(archos)\s(gamepad2?)/i, // Archos
  8956. /(hp).+(touchpad)/i, // HP TouchPad
  8957. /(hp).+(tablet)/i, // HP Tablet
  8958. /(kindle)\/([\w\.]+)/i, // Kindle
  8959. /\s(nook)[\w\s]+build\/(\w+)/i, // Nook
  8960. /(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
  8961. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8962. /(kf[A-z]+)\sbuild\/.+silk\//i // Kindle Fire HD
  8963. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  8964. /(sd|kf)[0349hijorstuw]+\sbuild\/.+silk\//i // Fire Phone
  8965. ], [[MODEL, mapper.str, maps.device.amazon.model], [VENDOR, 'Amazon'], [TYPE, MOBILE]], [
  8966. /android.+aft([bms])\sbuild/i // Fire TV
  8967. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, SMARTTV]], [
  8968. /\((ip[honed|\s\w*]+);.+(apple)/i // iPod/iPhone
  8969. ], [MODEL, VENDOR, [TYPE, MOBILE]], [
  8970. /\((ip[honed|\s\w*]+);/i // iPod/iPhone
  8971. ], [MODEL, [VENDOR, 'Apple'], [TYPE, MOBILE]], [
  8972. /(blackberry)[\s-]?(\w+)/i, // BlackBerry
  8973. /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[\s_-]?([\w-]*)/i,
  8974. // BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
  8975. /(hp)\s([\w\s]+\w)/i, // HP iPAQ
  8976. /(asus)-?(\w+)/i // Asus
  8977. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  8978. /\(bb10;\s(\w+)/i // BlackBerry 10
  8979. ], [MODEL, [VENDOR, 'BlackBerry'], [TYPE, MOBILE]], [
  8980. // Asus Tablets
  8981. /android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7|padfone)/i
  8982. ], [MODEL, [VENDOR, 'Asus'], [TYPE, TABLET]], [
  8983. /(sony)\s(tablet\s[ps])\sbuild\//i, // Sony
  8984. /(sony)?(?:sgp.+)\sbuild\//i
  8985. ], [[VENDOR, 'Sony'], [MODEL, 'Xperia Tablet'], [TYPE, TABLET]], [
  8986. /android.+\s([c-g]\d{4}|so[-l]\w+)\sbuild\//i
  8987. ], [MODEL, [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  8988. /\s(ouya)\s/i, // Ouya
  8989. /(nintendo)\s([wids3u]+)/i // Nintendo
  8990. ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
  8991. /android.+;\s(shield)\sbuild/i // Nvidia
  8992. ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
  8993. /(playstation\s[34portablevi]+)/i // Playstation
  8994. ], [MODEL, [VENDOR, 'Sony'], [TYPE, CONSOLE]], [
  8995. /(sprint\s(\w+))/i // Sprint Phones
  8996. ], [[VENDOR, mapper.str, maps.device.sprint.vendor], [MODEL, mapper.str, maps.device.sprint.model], [TYPE, MOBILE]], [
  8997. /(lenovo)\s?(S(?:5000|6000)+(?:[-][\w+]))/i // Lenovo tablets
  8998. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  8999. /(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
  9000. /(zte)-(\w*)/i, // ZTE
  9001. /(alcatel|geeksphone|lenovo|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]*)/i
  9002. // Alcatel/GeeksPhone/Lenovo/Nexian/Panasonic/Sony
  9003. ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
  9004. /(nexus\s9)/i // HTC Nexus 9
  9005. ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
  9006. /d\/huawei([\w\s-]+)[;\)]/i,
  9007. /(nexus\s6p)/i // Huawei
  9008. ], [MODEL, [VENDOR, 'Huawei'], [TYPE, MOBILE]], [
  9009. /(microsoft);\s(lumia[\s\w]+)/i // Microsoft Lumia
  9010. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  9011. /[\s\(;](xbox(?:\sone)?)[\s\);]/i // Microsoft Xbox
  9012. ], [MODEL, [VENDOR, 'Microsoft'], [TYPE, CONSOLE]], [
  9013. /(kin\.[onetw]{3})/i // Microsoft Kin
  9014. ], [[MODEL, /\./g, ' '], [VENDOR, 'Microsoft'], [TYPE, MOBILE]], [
  9015. // Motorola
  9016. /\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?:?(\s4g)?)[\w\s]+build\//i,
  9017. /mot[\s-]?(\w*)/i,
  9018. /(XT\d{3,4}) build\//i,
  9019. /(nexus\s6)/i
  9020. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, MOBILE]], [
  9021. /android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i
  9022. ], [MODEL, [VENDOR, 'Motorola'], [TYPE, TABLET]], [
  9023. /hbbtv\/\d+\.\d+\.\d+\s+\([\w\s]*;\s*(\w[^;]*);([^;]*)/i // HbbTV devices
  9024. ], [[VENDOR, util.trim], [MODEL, util.trim], [TYPE, SMARTTV]], [
  9025. /hbbtv.+maple;(\d+)/i
  9026. ], [[MODEL, /^/, 'SmartTV'], [VENDOR, 'Samsung'], [TYPE, SMARTTV]], [
  9027. /\(dtv[\);].+(aquos)/i // Sharp
  9028. ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
  9029. /android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n\d+|sgh-t8[56]9|nexus 10))/i,
  9030. /((SM-T\w+))/i
  9031. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
  9032. /smart-tv.+(samsung)/i
  9033. ], [VENDOR, [TYPE, SMARTTV], MODEL], [
  9034. /((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-\w[\w\d]+))/i,
  9035. /(sam[sung]*)[\s-]*(\w+-?[\w-]*)/i,
  9036. /sec-((sgh\w+))/i
  9037. ], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
  9038. /sie-(\w*)/i // Siemens
  9039. ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
  9040. /(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
  9041. /(nokia)[\s_-]?([\w-]*)/i
  9042. ], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
  9043. /android\s3\.[\s\w;-]{10}(a\d{3})/i // Acer
  9044. ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [
  9045. /android.+([vl]k\-?\d{3})\s+build/i // LG Tablet
  9046. ], [MODEL, [VENDOR, 'LG'], [TYPE, TABLET]], [
  9047. /android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i // LG Tablet
  9048. ], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
  9049. /(lg) netcast\.tv/i // LG SmartTV
  9050. ], [VENDOR, MODEL, [TYPE, SMARTTV]], [
  9051. /(nexus\s[45])/i, // LG
  9052. /lg[e;\s\/-]+(\w*)/i,
  9053. /android.+lg(\-?[\d\w]+)\s+build/i
  9054. ], [MODEL, [VENDOR, 'LG'], [TYPE, MOBILE]], [
  9055. /android.+(ideatab[a-z0-9\-\s]+)/i // Lenovo
  9056. ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [
  9057. /linux;.+((jolla));/i // Jolla
  9058. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  9059. /((pebble))app\/[\d\.]+\s/i // Pebble
  9060. ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
  9061. /android.+;\s(oppo)\s?([\w\s]+)\sbuild/i // OPPO
  9062. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  9063. /crkey/i // Google Chromecast
  9064. ], [[MODEL, 'Chromecast'], [VENDOR, 'Google']], [
  9065. /android.+;\s(glass)\s\d/i // Google Glass
  9066. ], [MODEL, [VENDOR, 'Google'], [TYPE, WEARABLE]], [
  9067. /android.+;\s(pixel c)[\s)]/i // Google Pixel C
  9068. ], [MODEL, [VENDOR, 'Google'], [TYPE, TABLET]], [
  9069. /android.+;\s(pixel( [23])?( xl)?)\s/i // Google Pixel
  9070. ], [MODEL, [VENDOR, 'Google'], [TYPE, MOBILE]], [
  9071. /android.+;\s(\w+)\s+build\/hm\1/i, // Xiaomi Hongmi 'numeric' models
  9072. /android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i, // Xiaomi Hongmi
  9073. /android.+(mi[\s\-_]*(?:one|one[\s_]plus|note lte)?[\s_]*(?:\d?\w?)[\s_]*(?:plus)?)\s+build/i, // Xiaomi Mi
  9074. /android.+(redmi[\s\-_]*(?:note)?(?:[\s_]*[\w\s]+))\s+build/i // Redmi Phones
  9075. ], [[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, MOBILE]], [
  9076. /android.+(mi[\s\-_]*(?:pad)(?:[\s_]*[\w\s]+))\s+build/i // Mi Pad tablets
  9077. ],[[MODEL, /_/g, ' '], [VENDOR, 'Xiaomi'], [TYPE, TABLET]], [
  9078. /android.+;\s(m[1-5]\snote)\sbuild/i // Meizu Tablet
  9079. ], [MODEL, [VENDOR, 'Meizu'], [TYPE, TABLET]], [
  9080. /(mz)-([\w-]{2,})/i // Meizu Phone
  9081. ], [[VENDOR, 'Meizu'], MODEL, [TYPE, MOBILE]], [
  9082. /android.+a000(1)\s+build/i, // OnePlus
  9083. /android.+oneplus\s(a\d{4})\s+build/i
  9084. ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [
  9085. /android.+[;\/]\s*(RCT[\d\w]+)\s+build/i // RCA Tablets
  9086. ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
  9087. /android.+[;\/\s]+(Venue[\d\s]{2,7})\s+build/i // Dell Venue Tablets
  9088. ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
  9089. /android.+[;\/]\s*(Q[T|M][\d\w]+)\s+build/i // Verizon Tablet
  9090. ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
  9091. /android.+[;\/]\s+(Barnes[&\s]+Noble\s+|BN[RT])(V?.*)\s+build/i // Barnes & Noble Tablet
  9092. ], [[VENDOR, 'Barnes & Noble'], MODEL, [TYPE, TABLET]], [
  9093. /android.+[;\/]\s+(TM\d{3}.*\b)\s+build/i // Barnes & Noble Tablet
  9094. ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
  9095. /android.+;\s(k88)\sbuild/i // ZTE K Series Tablet
  9096. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
  9097. /android.+[;\/]\s*(gen\d{3})\s+build.*49h/i // Swiss GEN Mobile
  9098. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
  9099. /android.+[;\/]\s*(zur\d{3})\s+build/i // Swiss ZUR Tablet
  9100. ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
  9101. /android.+[;\/]\s*((Zeki)?TB.*\b)\s+build/i // Zeki Tablets
  9102. ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
  9103. /(android).+[;\/]\s+([YR]\d{2})\s+build/i,
  9104. /android.+[;\/]\s+(Dragon[\-\s]+Touch\s+|DT)(\w{5})\sbuild/i // Dragon Touch Tablet
  9105. ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
  9106. /android.+[;\/]\s*(NS-?\w{0,9})\sbuild/i // Insignia Tablets
  9107. ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
  9108. /android.+[;\/]\s*((NX|Next)-?\w{0,9})\s+build/i // NextBook Tablets
  9109. ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
  9110. /android.+[;\/]\s*(Xtreme\_)?(V(1[045]|2[015]|30|40|60|7[05]|90))\s+build/i
  9111. ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [ // Voice Xtreme Phones
  9112. /android.+[;\/]\s*(LVTEL\-)?(V1[12])\s+build/i // LvTel Phones
  9113. ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
  9114. /android.+;\s(PH-1)\s/i
  9115. ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [ // Essential PH-1
  9116. /android.+[;\/]\s*(V(100MD|700NA|7011|917G).*\b)\s+build/i // Envizen Tablets
  9117. ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
  9118. /android.+[;\/]\s*(Le[\s\-]+Pan)[\s\-]+(\w{1,9})\s+build/i // Le Pan Tablets
  9119. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  9120. /android.+[;\/]\s*(Trio[\s\-]*.*)\s+build/i // MachSpeed Tablets
  9121. ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
  9122. /android.+[;\/]\s*(Trinity)[\-\s]*(T\d{3})\s+build/i // Trinity Tablets
  9123. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  9124. /android.+[;\/]\s*TU_(1491)\s+build/i // Rotor Tablets
  9125. ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
  9126. /android.+(KS(.+))\s+build/i // Amazon Kindle Tablets
  9127. ], [MODEL, [VENDOR, 'Amazon'], [TYPE, TABLET]], [
  9128. /android.+(Gigaset)[\s\-]+(Q\w{1,9})\s+build/i // Gigaset Tablets
  9129. ], [VENDOR, MODEL, [TYPE, TABLET]], [
  9130. /\s(tablet|tab)[;\/]/i, // Unidentifiable Tablet
  9131. /\s(mobile)(?:[;\/]|\ssafari)/i // Unidentifiable Mobile
  9132. ], [[TYPE, util.lowerize], VENDOR, MODEL], [
  9133. /(android[\w\.\s\-]{0,9});.+build/i // Generic Android Device
  9134. ], [MODEL, [VENDOR, 'Generic']]
  9135. /*//////////////////////////
  9136. // TODO: move to string map
  9137. ////////////////////////////
  9138. /(C6603)/i // Sony Xperia Z C6603
  9139. ], [[MODEL, 'Xperia Z C6603'], [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  9140. /(C6903)/i // Sony Xperia Z 1
  9141. ], [[MODEL, 'Xperia Z 1'], [VENDOR, 'Sony'], [TYPE, MOBILE]], [
  9142. /(SM-G900[F|H])/i // Samsung Galaxy S5
  9143. ], [[MODEL, 'Galaxy S5'], [VENDOR, 'Samsung'], [TYPE, MOBILE]], [
  9144. /(SM-G7102)/i // Samsung Galaxy Grand 2
  9145. ], [[MODEL, 'Galaxy Grand 2'], [VENDOR, 'Samsung'], [TYPE, MOBILE]], [
  9146. /(SM-G530H)/i // Samsung Galaxy Grand Prime
  9147. ], [[MODEL, 'Galaxy Grand Prime'], [VENDOR, 'Samsung'], [TYPE, MOBILE]], [
  9148. /(SM-G313HZ)/i // Samsung Galaxy V
  9149. ], [[MODEL, 'Galaxy V'], [VENDOR, 'Samsung'], [TYPE, MOBILE]], [
  9150. /(SM-T805)/i // Samsung Galaxy Tab S 10.5
  9151. ], [[MODEL, 'Galaxy Tab S 10.5'], [VENDOR, 'Samsung'], [TYPE, TABLET]], [
  9152. /(SM-G800F)/i // Samsung Galaxy S5 Mini
  9153. ], [[MODEL, 'Galaxy S5 Mini'], [VENDOR, 'Samsung'], [TYPE, MOBILE]], [
  9154. /(SM-T311)/i // Samsung Galaxy Tab 3 8.0
  9155. ], [[MODEL, 'Galaxy Tab 3 8.0'], [VENDOR, 'Samsung'], [TYPE, TABLET]], [
  9156. /(T3C)/i // Advan Vandroid T3C
  9157. ], [MODEL, [VENDOR, 'Advan'], [TYPE, TABLET]], [
  9158. /(ADVAN T1J\+)/i // Advan Vandroid T1J+
  9159. ], [[MODEL, 'Vandroid T1J+'], [VENDOR, 'Advan'], [TYPE, TABLET]], [
  9160. /(ADVAN S4A)/i // Advan Vandroid S4A
  9161. ], [[MODEL, 'Vandroid S4A'], [VENDOR, 'Advan'], [TYPE, MOBILE]], [
  9162. /(V972M)/i // ZTE V972M
  9163. ], [MODEL, [VENDOR, 'ZTE'], [TYPE, MOBILE]], [
  9164. /(i-mobile)\s(IQ\s[\d\.]+)/i // i-mobile IQ
  9165. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  9166. /(IQ6.3)/i // i-mobile IQ IQ 6.3
  9167. ], [[MODEL, 'IQ 6.3'], [VENDOR, 'i-mobile'], [TYPE, MOBILE]], [
  9168. /(i-mobile)\s(i-style\s[\d\.]+)/i // i-mobile i-STYLE
  9169. ], [VENDOR, MODEL, [TYPE, MOBILE]], [
  9170. /(i-STYLE2.1)/i // i-mobile i-STYLE 2.1
  9171. ], [[MODEL, 'i-STYLE 2.1'], [VENDOR, 'i-mobile'], [TYPE, MOBILE]], [
  9172. /(mobiistar touch LAI 512)/i // mobiistar touch LAI 512
  9173. ], [[MODEL, 'Touch LAI 512'], [VENDOR, 'mobiistar'], [TYPE, MOBILE]], [
  9174. /////////////
  9175. // END TODO
  9176. ///////////*/
  9177. ],
  9178. engine : [[
  9179. /windows.+\sedge\/([\w\.]+)/i // EdgeHTML
  9180. ], [VERSION, [NAME, 'EdgeHTML']], [
  9181. /(presto)\/([\w\.]+)/i, // Presto
  9182. /(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m
  9183. /(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
  9184. /(icab)[\/\s]([23]\.[\d\.]+)/i // iCab
  9185. ], [NAME, VERSION], [
  9186. /rv\:([\w\.]{1,9}).+(gecko)/i // Gecko
  9187. ], [VERSION, NAME]
  9188. ],
  9189. os : [[
  9190. // Windows based
  9191. /microsoft\s(windows)\s(vista|xp)/i // Windows (iTunes)
  9192. ], [NAME, VERSION], [
  9193. /(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
  9194. /(windows\sphone(?:\sos)*)[\s\/]?([\d\.\s\w]*)/i, // Windows Phone
  9195. /(windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
  9196. ], [NAME, [VERSION, mapper.str, maps.os.windows.version]], [
  9197. /(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
  9198. ], [[NAME, 'Windows'], [VERSION, mapper.str, maps.os.windows.version]], [
  9199. // Mobile/Embedded OS
  9200. /\((bb)(10);/i // BlackBerry 10
  9201. ], [[NAME, 'BlackBerry'], VERSION], [
  9202. /(blackberry)\w*\/?([\w\.]*)/i, // Blackberry
  9203. /(tizen)[\/\s]([\w\.]+)/i, // Tizen
  9204. /(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|contiki)[\/\s-]?([\w\.]*)/i,
  9205. // Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki
  9206. /linux;.+(sailfish);/i // Sailfish OS
  9207. ], [NAME, VERSION], [
  9208. /(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]*)/i // Symbian
  9209. ], [[NAME, 'Symbian'], VERSION], [
  9210. /\((series40);/i // Series 40
  9211. ], [NAME], [
  9212. /mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
  9213. ], [[NAME, 'Firefox OS'], VERSION], [
  9214. // Console
  9215. /(nintendo|playstation)\s([wids34portablevu]+)/i, // Nintendo/Playstation
  9216. // GNU/Linux based
  9217. /(mint)[\/\s\(]?(\w*)/i, // Mint
  9218. /(mageia|vectorlinux)[;\s]/i, // Mageia/VectorLinux
  9219. /(joli|[kxln]?ubuntu|debian|suse|opensuse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?(?!chrom)([\w\.-]*)/i,
  9220. // Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
  9221. // Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus
  9222. /(hurd|linux)\s?([\w\.]*)/i, // Hurd/Linux
  9223. /(gnu)\s?([\w\.]*)/i // GNU
  9224. ], [NAME, VERSION], [
  9225. /(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
  9226. ], [[NAME, 'Chromium OS'], VERSION],[
  9227. // Solaris
  9228. /(sunos)\s?([\w\.\d]*)/i // Solaris
  9229. ], [[NAME, 'Solaris'], VERSION], [
  9230. // BSD based
  9231. /\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]*)/i // FreeBSD/NetBSD/OpenBSD/PC-BSD/DragonFly
  9232. ], [NAME, VERSION],[
  9233. /(haiku)\s(\w+)/i // Haiku
  9234. ], [NAME, VERSION],[
  9235. /cfnetwork\/.+darwin/i,
  9236. /ip[honead]{2,4}(?:.*os\s([\w]+)\slike\smac|;\sopera)/i // iOS
  9237. ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
  9238. /(mac\sos\sx)\s?([\w\s\.]*)/i,
  9239. /(macintosh|mac(?=_powerpc)\s)/i // Mac OS
  9240. ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [
  9241. // Other
  9242. /((?:open)?solaris)[\/\s-]?([\w\.]*)/i, // Solaris
  9243. /(aix)\s((\d)(?=\.|\)|\s)[\w\.])*/i, // AIX
  9244. /(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms|fuchsia)/i,
  9245. // Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS/OpenVMS/Fuchsia
  9246. /(unix)\s?([\w\.]*)/i // UNIX
  9247. ], [NAME, VERSION]
  9248. ]
  9249. };
  9250. /////////////////
  9251. // Constructor
  9252. ////////////////
  9253. /*
  9254. var Browser = function (name, version) {
  9255. this[NAME] = name;
  9256. this[VERSION] = version;
  9257. };
  9258. var CPU = function (arch) {
  9259. this[ARCHITECTURE] = arch;
  9260. };
  9261. var Device = function (vendor, model, type) {
  9262. this[VENDOR] = vendor;
  9263. this[MODEL] = model;
  9264. this[TYPE] = type;
  9265. };
  9266. var Engine = Browser;
  9267. var OS = Browser;
  9268. */
  9269. var UAParser = function (uastring, extensions) {
  9270. if (typeof uastring === 'object') {
  9271. extensions = uastring;
  9272. uastring = undefined;
  9273. }
  9274. if (!(this instanceof UAParser)) {
  9275. return new UAParser(uastring, extensions).getResult();
  9276. }
  9277. var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
  9278. var rgxmap = extensions ? util.extend(regexes, extensions) : regexes;
  9279. //var browser = new Browser();
  9280. //var cpu = new CPU();
  9281. //var device = new Device();
  9282. //var engine = new Engine();
  9283. //var os = new OS();
  9284. this.getBrowser = function () {
  9285. var browser = { name: undefined, version: undefined };
  9286. mapper.rgx.call(browser, ua, rgxmap.browser);
  9287. browser.major = util.major(browser.version); // deprecated
  9288. return browser;
  9289. };
  9290. this.getCPU = function () {
  9291. var cpu = { architecture: undefined };
  9292. mapper.rgx.call(cpu, ua, rgxmap.cpu);
  9293. return cpu;
  9294. };
  9295. this.getDevice = function () {
  9296. var device = { vendor: undefined, model: undefined, type: undefined };
  9297. mapper.rgx.call(device, ua, rgxmap.device);
  9298. return device;
  9299. };
  9300. this.getEngine = function () {
  9301. var engine = { name: undefined, version: undefined };
  9302. mapper.rgx.call(engine, ua, rgxmap.engine);
  9303. return engine;
  9304. };
  9305. this.getOS = function () {
  9306. var os = { name: undefined, version: undefined };
  9307. mapper.rgx.call(os, ua, rgxmap.os);
  9308. return os;
  9309. };
  9310. this.getResult = function () {
  9311. return {
  9312. ua : this.getUA(),
  9313. browser : this.getBrowser(),
  9314. engine : this.getEngine(),
  9315. os : this.getOS(),
  9316. device : this.getDevice(),
  9317. cpu : this.getCPU()
  9318. };
  9319. };
  9320. this.getUA = function () {
  9321. return ua;
  9322. };
  9323. this.setUA = function (uastring) {
  9324. ua = uastring;
  9325. //browser = new Browser();
  9326. //cpu = new CPU();
  9327. //device = new Device();
  9328. //engine = new Engine();
  9329. //os = new OS();
  9330. return this;
  9331. };
  9332. return this;
  9333. };
  9334. UAParser.VERSION = LIBVERSION;
  9335. UAParser.BROWSER = {
  9336. NAME : NAME,
  9337. MAJOR : MAJOR, // deprecated
  9338. VERSION : VERSION
  9339. };
  9340. UAParser.CPU = {
  9341. ARCHITECTURE : ARCHITECTURE
  9342. };
  9343. UAParser.DEVICE = {
  9344. MODEL : MODEL,
  9345. VENDOR : VENDOR,
  9346. TYPE : TYPE,
  9347. CONSOLE : CONSOLE,
  9348. MOBILE : MOBILE,
  9349. SMARTTV : SMARTTV,
  9350. TABLET : TABLET,
  9351. WEARABLE: WEARABLE,
  9352. EMBEDDED: EMBEDDED
  9353. };
  9354. UAParser.ENGINE = {
  9355. NAME : NAME,
  9356. VERSION : VERSION
  9357. };
  9358. UAParser.OS = {
  9359. NAME : NAME,
  9360. VERSION : VERSION
  9361. };
  9362. //UAParser.Utils = util;
  9363. ///////////
  9364. // Export
  9365. //////////
  9366. // check js environment
  9367. if (typeof(exports) !== UNDEF_TYPE) {
  9368. // nodejs env
  9369. if (typeof module !== UNDEF_TYPE && module.exports) {
  9370. exports = module.exports = UAParser;
  9371. }
  9372. // TODO: test!!!!!!!!
  9373. /*
  9374. if (require && require.main === module && process) {
  9375. // cli
  9376. var jsonize = function (arr) {
  9377. var res = [];
  9378. for (var i in arr) {
  9379. res.push(new UAParser(arr[i]).getResult());
  9380. }
  9381. process.stdout.write(JSON.stringify(res, null, 2) + '\n');
  9382. };
  9383. if (process.stdin.isTTY) {
  9384. // via args
  9385. jsonize(process.argv.slice(2));
  9386. } else {
  9387. // via pipe
  9388. var str = '';
  9389. process.stdin.on('readable', function() {
  9390. var read = process.stdin.read();
  9391. if (read !== null) {
  9392. str += read;
  9393. }
  9394. });
  9395. process.stdin.on('end', function () {
  9396. jsonize(str.replace(/\n$/, '').split('\n'));
  9397. });
  9398. }
  9399. }
  9400. */
  9401. exports.UAParser = UAParser;
  9402. } else {
  9403. // requirejs env (optional)
  9404. if ("function" === FUNC_TYPE && __webpack_require__(100)) {
  9405. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  9406. return UAParser;
  9407. }).call(exports, __webpack_require__, exports, module),
  9408. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  9409. } else if (window) {
  9410. // browser env
  9411. window.UAParser = UAParser;
  9412. }
  9413. }
  9414. // jQuery/Zepto specific (optional)
  9415. // Note:
  9416. // In AMD env the global scope should be kept clean, but jQuery is an exception.
  9417. // jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
  9418. // and we should catch that.
  9419. var $ = window && (window.jQuery || window.Zepto);
  9420. if (typeof $ !== UNDEF_TYPE && !$.ua) {
  9421. var parser = new UAParser();
  9422. $.ua = parser.getResult();
  9423. $.ua.get = function () {
  9424. return parser.getUA();
  9425. };
  9426. $.ua.set = function (uastring) {
  9427. parser.setUA(uastring);
  9428. var result = parser.getResult();
  9429. for (var prop in result) {
  9430. $.ua[prop] = result[prop];
  9431. }
  9432. };
  9433. }
  9434. })(typeof window === 'object' ? window : this);
  9435. /***/ }),
  9436. /* 100 */
  9437. /***/ (function(module, exports) {
  9438. /* WEBPACK VAR INJECTION */(function(__webpack_amd_options__) {/* globals __webpack_amd_options__ */
  9439. module.exports = __webpack_amd_options__;
  9440. /* WEBPACK VAR INJECTION */}.call(exports, {}))
  9441. /***/ }),
  9442. /* 101 */
  9443. /***/ (function(module, exports, __webpack_require__) {
  9444. "use strict";
  9445. /**
  9446. * Copyright (c) 2013-present, Facebook, Inc.
  9447. *
  9448. * This source code is licensed under the MIT license found in the
  9449. * LICENSE file in the root directory of this source tree.
  9450. *
  9451. */
  9452. var invariant = __webpack_require__(1);
  9453. var componentRegex = /\./;
  9454. var orRegex = /\|\|/;
  9455. var rangeRegex = /\s+\-\s+/;
  9456. var modifierRegex = /^(<=|<|=|>=|~>|~|>|)?\s*(.+)/;
  9457. var numericRegex = /^(\d*)(.*)/;
  9458. /**
  9459. * Splits input `range` on "||" and returns true if any subrange matches
  9460. * `version`.
  9461. *
  9462. * @param {string} range
  9463. * @param {string} version
  9464. * @returns {boolean}
  9465. */
  9466. function checkOrExpression(range, version) {
  9467. var expressions = range.split(orRegex);
  9468. if (expressions.length > 1) {
  9469. return expressions.some(function (range) {
  9470. return VersionRange.contains(range, version);
  9471. });
  9472. } else {
  9473. range = expressions[0].trim();
  9474. return checkRangeExpression(range, version);
  9475. }
  9476. }
  9477. /**
  9478. * Splits input `range` on " - " (the surrounding whitespace is required) and
  9479. * returns true if version falls between the two operands.
  9480. *
  9481. * @param {string} range
  9482. * @param {string} version
  9483. * @returns {boolean}
  9484. */
  9485. function checkRangeExpression(range, version) {
  9486. var expressions = range.split(rangeRegex);
  9487. !(expressions.length > 0 && expressions.length <= 2) ? true ? invariant(false, 'the "-" operator expects exactly 2 operands') : invariant(false) : void 0;
  9488. if (expressions.length === 1) {
  9489. return checkSimpleExpression(expressions[0], version);
  9490. } else {
  9491. var startVersion = expressions[0],
  9492. endVersion = expressions[1];
  9493. !(isSimpleVersion(startVersion) && isSimpleVersion(endVersion)) ? true ? invariant(false, 'operands to the "-" operator must be simple (no modifiers)') : invariant(false) : void 0;
  9494. return checkSimpleExpression('>=' + startVersion, version) && checkSimpleExpression('<=' + endVersion, version);
  9495. }
  9496. }
  9497. /**
  9498. * Checks if `range` matches `version`. `range` should be a "simple" range (ie.
  9499. * not a compound range using the " - " or "||" operators).
  9500. *
  9501. * @param {string} range
  9502. * @param {string} version
  9503. * @returns {boolean}
  9504. */
  9505. function checkSimpleExpression(range, version) {
  9506. range = range.trim();
  9507. if (range === '') {
  9508. return true;
  9509. }
  9510. var versionComponents = version.split(componentRegex);
  9511. var _getModifierAndCompon = getModifierAndComponents(range),
  9512. modifier = _getModifierAndCompon.modifier,
  9513. rangeComponents = _getModifierAndCompon.rangeComponents;
  9514. switch (modifier) {
  9515. case '<':
  9516. return checkLessThan(versionComponents, rangeComponents);
  9517. case '<=':
  9518. return checkLessThanOrEqual(versionComponents, rangeComponents);
  9519. case '>=':
  9520. return checkGreaterThanOrEqual(versionComponents, rangeComponents);
  9521. case '>':
  9522. return checkGreaterThan(versionComponents, rangeComponents);
  9523. case '~':
  9524. case '~>':
  9525. return checkApproximateVersion(versionComponents, rangeComponents);
  9526. default:
  9527. return checkEqual(versionComponents, rangeComponents);
  9528. }
  9529. }
  9530. /**
  9531. * Checks whether `a` is less than `b`.
  9532. *
  9533. * @param {array<string>} a
  9534. * @param {array<string>} b
  9535. * @returns {boolean}
  9536. */
  9537. function checkLessThan(a, b) {
  9538. return compareComponents(a, b) === -1;
  9539. }
  9540. /**
  9541. * Checks whether `a` is less than or equal to `b`.
  9542. *
  9543. * @param {array<string>} a
  9544. * @param {array<string>} b
  9545. * @returns {boolean}
  9546. */
  9547. function checkLessThanOrEqual(a, b) {
  9548. var result = compareComponents(a, b);
  9549. return result === -1 || result === 0;
  9550. }
  9551. /**
  9552. * Checks whether `a` is equal to `b`.
  9553. *
  9554. * @param {array<string>} a
  9555. * @param {array<string>} b
  9556. * @returns {boolean}
  9557. */
  9558. function checkEqual(a, b) {
  9559. return compareComponents(a, b) === 0;
  9560. }
  9561. /**
  9562. * Checks whether `a` is greater than or equal to `b`.
  9563. *
  9564. * @param {array<string>} a
  9565. * @param {array<string>} b
  9566. * @returns {boolean}
  9567. */
  9568. function checkGreaterThanOrEqual(a, b) {
  9569. var result = compareComponents(a, b);
  9570. return result === 1 || result === 0;
  9571. }
  9572. /**
  9573. * Checks whether `a` is greater than `b`.
  9574. *
  9575. * @param {array<string>} a
  9576. * @param {array<string>} b
  9577. * @returns {boolean}
  9578. */
  9579. function checkGreaterThan(a, b) {
  9580. return compareComponents(a, b) === 1;
  9581. }
  9582. /**
  9583. * Checks whether `a` is "reasonably close" to `b` (as described in
  9584. * https://www.npmjs.org/doc/misc/semver.html). For example, if `b` is "1.3.1"
  9585. * then "reasonably close" is defined as ">= 1.3.1 and < 1.4".
  9586. *
  9587. * @param {array<string>} a
  9588. * @param {array<string>} b
  9589. * @returns {boolean}
  9590. */
  9591. function checkApproximateVersion(a, b) {
  9592. var lowerBound = b.slice();
  9593. var upperBound = b.slice();
  9594. if (upperBound.length > 1) {
  9595. upperBound.pop();
  9596. }
  9597. var lastIndex = upperBound.length - 1;
  9598. var numeric = parseInt(upperBound[lastIndex], 10);
  9599. if (isNumber(numeric)) {
  9600. upperBound[lastIndex] = numeric + 1 + '';
  9601. }
  9602. return checkGreaterThanOrEqual(a, lowerBound) && checkLessThan(a, upperBound);
  9603. }
  9604. /**
  9605. * Extracts the optional modifier (<, <=, =, >=, >, ~, ~>) and version
  9606. * components from `range`.
  9607. *
  9608. * For example, given `range` ">= 1.2.3" returns an object with a `modifier` of
  9609. * `">="` and `components` of `[1, 2, 3]`.
  9610. *
  9611. * @param {string} range
  9612. * @returns {object}
  9613. */
  9614. function getModifierAndComponents(range) {
  9615. var rangeComponents = range.split(componentRegex);
  9616. var matches = rangeComponents[0].match(modifierRegex);
  9617. !matches ? true ? invariant(false, 'expected regex to match but it did not') : invariant(false) : void 0;
  9618. return {
  9619. modifier: matches[1],
  9620. rangeComponents: [matches[2]].concat(rangeComponents.slice(1))
  9621. };
  9622. }
  9623. /**
  9624. * Determines if `number` is a number.
  9625. *
  9626. * @param {mixed} number
  9627. * @returns {boolean}
  9628. */
  9629. function isNumber(number) {
  9630. return !isNaN(number) && isFinite(number);
  9631. }
  9632. /**
  9633. * Tests whether `range` is a "simple" version number without any modifiers
  9634. * (">", "~" etc).
  9635. *
  9636. * @param {string} range
  9637. * @returns {boolean}
  9638. */
  9639. function isSimpleVersion(range) {
  9640. return !getModifierAndComponents(range).modifier;
  9641. }
  9642. /**
  9643. * Zero-pads array `array` until it is at least `length` long.
  9644. *
  9645. * @param {array} array
  9646. * @param {number} length
  9647. */
  9648. function zeroPad(array, length) {
  9649. for (var i = array.length; i < length; i++) {
  9650. array[i] = '0';
  9651. }
  9652. }
  9653. /**
  9654. * Normalizes `a` and `b` in preparation for comparison by doing the following:
  9655. *
  9656. * - zero-pads `a` and `b`
  9657. * - marks any "x", "X" or "*" component in `b` as equivalent by zero-ing it out
  9658. * in both `a` and `b`
  9659. * - marks any final "*" component in `b` as a greedy wildcard by zero-ing it
  9660. * and all of its successors in `a`
  9661. *
  9662. * @param {array<string>} a
  9663. * @param {array<string>} b
  9664. * @returns {array<array<string>>}
  9665. */
  9666. function normalizeVersions(a, b) {
  9667. a = a.slice();
  9668. b = b.slice();
  9669. zeroPad(a, b.length); // mark "x" and "*" components as equal
  9670. for (var i = 0; i < b.length; i++) {
  9671. var matches = b[i].match(/^[x*]$/i);
  9672. if (matches) {
  9673. b[i] = a[i] = '0'; // final "*" greedily zeros all remaining components
  9674. if (matches[0] === '*' && i === b.length - 1) {
  9675. for (var j = i; j < a.length; j++) {
  9676. a[j] = '0';
  9677. }
  9678. }
  9679. }
  9680. }
  9681. zeroPad(b, a.length);
  9682. return [a, b];
  9683. }
  9684. /**
  9685. * Returns the numerical -- not the lexicographical -- ordering of `a` and `b`.
  9686. *
  9687. * For example, `10-alpha` is greater than `2-beta`.
  9688. *
  9689. * @param {string} a
  9690. * @param {string} b
  9691. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  9692. * or greater than `b`, respectively
  9693. */
  9694. function compareNumeric(a, b) {
  9695. var aPrefix = a.match(numericRegex)[1];
  9696. var bPrefix = b.match(numericRegex)[1];
  9697. var aNumeric = parseInt(aPrefix, 10);
  9698. var bNumeric = parseInt(bPrefix, 10);
  9699. if (isNumber(aNumeric) && isNumber(bNumeric) && aNumeric !== bNumeric) {
  9700. return compare(aNumeric, bNumeric);
  9701. } else {
  9702. return compare(a, b);
  9703. }
  9704. }
  9705. /**
  9706. * Returns the ordering of `a` and `b`.
  9707. *
  9708. * @param {string|number} a
  9709. * @param {string|number} b
  9710. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  9711. * or greater than `b`, respectively
  9712. */
  9713. function compare(a, b) {
  9714. !(typeof a === typeof b) ? true ? invariant(false, '"a" and "b" must be of the same type') : invariant(false) : void 0;
  9715. if (a > b) {
  9716. return 1;
  9717. } else if (a < b) {
  9718. return -1;
  9719. } else {
  9720. return 0;
  9721. }
  9722. }
  9723. /**
  9724. * Compares arrays of version components.
  9725. *
  9726. * @param {array<string>} a
  9727. * @param {array<string>} b
  9728. * @returns {number} -1, 0 or 1 to indicate whether `a` is less than, equal to,
  9729. * or greater than `b`, respectively
  9730. */
  9731. function compareComponents(a, b) {
  9732. var _normalizeVersions = normalizeVersions(a, b),
  9733. aNormalized = _normalizeVersions[0],
  9734. bNormalized = _normalizeVersions[1];
  9735. for (var i = 0; i < bNormalized.length; i++) {
  9736. var result = compareNumeric(aNormalized[i], bNormalized[i]);
  9737. if (result) {
  9738. return result;
  9739. }
  9740. }
  9741. return 0;
  9742. }
  9743. var VersionRange = {
  9744. /**
  9745. * Checks whether `version` satisfies the `range` specification.
  9746. *
  9747. * We support a subset of the expressions defined in
  9748. * https://www.npmjs.org/doc/misc/semver.html:
  9749. *
  9750. * version Must match version exactly
  9751. * =version Same as just version
  9752. * >version Must be greater than version
  9753. * >=version Must be greater than or equal to version
  9754. * <version Must be less than version
  9755. * <=version Must be less than or equal to version
  9756. * ~version Must be at least version, but less than the next significant
  9757. * revision above version:
  9758. * "~1.2.3" is equivalent to ">= 1.2.3 and < 1.3"
  9759. * ~>version Equivalent to ~version
  9760. * 1.2.x Must match "1.2.x", where "x" is a wildcard that matches
  9761. * anything
  9762. * 1.2.* Similar to "1.2.x", but "*" in the trailing position is a
  9763. * "greedy" wildcard, so will match any number of additional
  9764. * components:
  9765. * "1.2.*" will match "1.2.1", "1.2.1.1", "1.2.1.1.1" etc
  9766. * * Any version
  9767. * "" (Empty string) Same as *
  9768. * v1 - v2 Equivalent to ">= v1 and <= v2"
  9769. * r1 || r2 Passes if either r1 or r2 are satisfied
  9770. *
  9771. * @param {string} range
  9772. * @param {string} version
  9773. * @returns {boolean}
  9774. */
  9775. contains: function contains(range, version) {
  9776. return checkOrExpression(range.trim(), version.trim());
  9777. }
  9778. };
  9779. module.exports = VersionRange;
  9780. /***/ }),
  9781. /* 102 */
  9782. /***/ (function(module, exports, __webpack_require__) {
  9783. "use strict";
  9784. /**
  9785. * Copyright (c) 2013-present, Facebook, Inc.
  9786. *
  9787. * This source code is licensed under the MIT license found in the
  9788. * LICENSE file in the root directory of this source tree.
  9789. *
  9790. */
  9791. var hasOwnProperty = Object.prototype.hasOwnProperty;
  9792. /**
  9793. * Executes the provided `callback` once for each enumerable own property in the
  9794. * object and constructs a new object from the results. The `callback` is
  9795. * invoked with three arguments:
  9796. *
  9797. * - the property value
  9798. * - the property name
  9799. * - the object being traversed
  9800. *
  9801. * Properties that are added after the call to `mapObject` will not be visited
  9802. * by `callback`. If the values of existing properties are changed, the value
  9803. * passed to `callback` will be the value at the time `mapObject` visits them.
  9804. * Properties that are deleted before being visited are not visited.
  9805. *
  9806. * @grep function objectMap()
  9807. * @grep function objMap()
  9808. *
  9809. * @param {?object} object
  9810. * @param {function} callback
  9811. * @param {*} context
  9812. * @return {?object}
  9813. */
  9814. function mapObject(object, callback, context) {
  9815. if (!object) {
  9816. return null;
  9817. }
  9818. var result = {};
  9819. for (var name in object) {
  9820. if (hasOwnProperty.call(object, name)) {
  9821. result[name] = callback.call(context, object[name], name, object);
  9822. }
  9823. }
  9824. return result;
  9825. }
  9826. module.exports = mapObject;
  9827. /***/ }),
  9828. /* 103 */
  9829. /***/ (function(module, exports, __webpack_require__) {
  9830. "use strict";
  9831. /**
  9832. * Copyright (c) 2013-present, Facebook, Inc.
  9833. *
  9834. * This source code is licensed under the MIT license found in the
  9835. * LICENSE file in the root directory of this source tree.
  9836. *
  9837. *
  9838. * @typechecks static-only
  9839. */
  9840. /**
  9841. * Memoizes the return value of a function that accepts one string argument.
  9842. */
  9843. function memoizeStringOnly(callback) {
  9844. var cache = {};
  9845. return function (string) {
  9846. if (!cache.hasOwnProperty(string)) {
  9847. cache[string] = callback.call(this, string);
  9848. }
  9849. return cache[string];
  9850. };
  9851. }
  9852. module.exports = memoizeStringOnly;
  9853. /***/ }),
  9854. /* 104 */
  9855. /***/ (function(module, exports, __webpack_require__) {
  9856. "use strict";
  9857. /**
  9858. * Copyright (c) Facebook, Inc. and its affiliates.
  9859. *
  9860. * This source code is licensed under the MIT license found in the
  9861. * LICENSE file in the root directory of this source tree.
  9862. *
  9863. * @format
  9864. *
  9865. */
  9866. var gkx = __webpack_require__(11);
  9867. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  9868. module.exports = experimentalTreeDataSupport ? __webpack_require__(105) : __webpack_require__(119);
  9869. /***/ }),
  9870. /* 105 */
  9871. /***/ (function(module, exports, __webpack_require__) {
  9872. "use strict";
  9873. /**
  9874. * Copyright (c) Facebook, Inc. and its affiliates.
  9875. *
  9876. * This source code is licensed under the MIT license found in the
  9877. * LICENSE file in the root directory of this source tree.
  9878. *
  9879. * @format
  9880. *
  9881. * @emails oncall+draft_js
  9882. *
  9883. * This file is a fork of DraftEditorContents.react.js for tree nodes
  9884. *
  9885. * This is unstable and not part of the public API and should not be used by
  9886. * production systems. This file may be update/removed without notice.
  9887. */
  9888. var _assign = __webpack_require__(14);
  9889. function _extends() { _extends = _assign || 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; }; return _extends.apply(this, arguments); }
  9890. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  9891. var DraftEditorBlockNode = __webpack_require__(106);
  9892. var DraftOffsetKey = __webpack_require__(10);
  9893. var React = __webpack_require__(8);
  9894. var nullthrows = __webpack_require__(4);
  9895. /**
  9896. * `DraftEditorContents` is the container component for all block components
  9897. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  9898. * re-rendering blocks whenever possible.
  9899. *
  9900. * This component is separate from `DraftEditor` because certain props
  9901. * (for instance, ARIA props) must be allowed to update without affecting
  9902. * the contents of the editor.
  9903. */
  9904. var DraftEditorContentsExperimental =
  9905. /*#__PURE__*/
  9906. function (_React$Component) {
  9907. _inheritsLoose(DraftEditorContentsExperimental, _React$Component);
  9908. function DraftEditorContentsExperimental() {
  9909. return _React$Component.apply(this, arguments) || this;
  9910. }
  9911. var _proto = DraftEditorContentsExperimental.prototype;
  9912. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  9913. var prevEditorState = this.props.editorState;
  9914. var nextEditorState = nextProps.editorState;
  9915. var prevDirectionMap = prevEditorState.getDirectionMap();
  9916. var nextDirectionMap = nextEditorState.getDirectionMap(); // Text direction has changed for one or more blocks. We must re-render.
  9917. if (prevDirectionMap !== nextDirectionMap) {
  9918. return true;
  9919. }
  9920. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  9921. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  9922. if (didHaveFocus !== nowHasFocus) {
  9923. return true;
  9924. }
  9925. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  9926. var wasComposing = prevEditorState.isInCompositionMode();
  9927. var nowComposing = nextEditorState.isInCompositionMode(); // If the state is unchanged or we're currently rendering a natively
  9928. // rendered state, there's nothing new to be done.
  9929. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  9930. return false;
  9931. }
  9932. var prevContent = prevEditorState.getCurrentContent();
  9933. var nextContent = nextEditorState.getCurrentContent();
  9934. var prevDecorator = prevEditorState.getDecorator();
  9935. var nextDecorator = nextEditorState.getDecorator();
  9936. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  9937. };
  9938. _proto.render = function render() {
  9939. var _this$props = this.props,
  9940. blockRenderMap = _this$props.blockRenderMap,
  9941. blockRendererFn = _this$props.blockRendererFn,
  9942. blockStyleFn = _this$props.blockStyleFn,
  9943. customStyleMap = _this$props.customStyleMap,
  9944. customStyleFn = _this$props.customStyleFn,
  9945. editorState = _this$props.editorState,
  9946. editorKey = _this$props.editorKey,
  9947. textDirectionality = _this$props.textDirectionality;
  9948. var content = editorState.getCurrentContent();
  9949. var selection = editorState.getSelection();
  9950. var forceSelection = editorState.mustForceSelection();
  9951. var decorator = editorState.getDecorator();
  9952. var directionMap = nullthrows(editorState.getDirectionMap());
  9953. var blocksAsArray = content.getBlocksAsArray();
  9954. var rootBlock = blocksAsArray[0];
  9955. var processedBlocks = [];
  9956. var nodeBlock = rootBlock;
  9957. while (nodeBlock) {
  9958. var blockKey = nodeBlock.getKey();
  9959. var blockProps = {
  9960. blockRenderMap: blockRenderMap,
  9961. blockRendererFn: blockRendererFn,
  9962. blockStyleFn: blockStyleFn,
  9963. contentState: content,
  9964. customStyleFn: customStyleFn,
  9965. customStyleMap: customStyleMap,
  9966. decorator: decorator,
  9967. editorKey: editorKey,
  9968. editorState: editorState,
  9969. forceSelection: forceSelection,
  9970. selection: selection,
  9971. block: nodeBlock,
  9972. direction: textDirectionality ? textDirectionality : directionMap.get(blockKey),
  9973. tree: editorState.getBlockTree(blockKey)
  9974. };
  9975. var configForType = blockRenderMap.get(nodeBlock.getType()) || blockRenderMap.get('unstyled');
  9976. var wrapperTemplate = configForType.wrapper;
  9977. processedBlocks.push({
  9978. /* $FlowFixMe(>=0.112.0 site=www,mobile) This comment suppresses an
  9979. * error found when Flow v0.112 was deployed. To see the error delete
  9980. * this comment and run Flow. */
  9981. block: React.createElement(DraftEditorBlockNode, _extends({
  9982. key: blockKey
  9983. }, blockProps)),
  9984. wrapperTemplate: wrapperTemplate,
  9985. key: blockKey,
  9986. offsetKey: DraftOffsetKey.encode(blockKey, 0, 0)
  9987. });
  9988. var nextBlockKey = nodeBlock.getNextSiblingKey();
  9989. nodeBlock = nextBlockKey ? content.getBlockForKey(nextBlockKey) : null;
  9990. } // Group contiguous runs of blocks that have the same wrapperTemplate
  9991. var outputBlocks = [];
  9992. for (var ii = 0; ii < processedBlocks.length;) {
  9993. var info = processedBlocks[ii];
  9994. if (info.wrapperTemplate) {
  9995. var blocks = [];
  9996. do {
  9997. blocks.push(processedBlocks[ii].block);
  9998. ii++;
  9999. } while (ii < processedBlocks.length && processedBlocks[ii].wrapperTemplate === info.wrapperTemplate);
  10000. var wrapperElement = React.cloneElement(info.wrapperTemplate, {
  10001. key: info.key + '-wrap',
  10002. 'data-offset-key': info.offsetKey
  10003. }, blocks);
  10004. outputBlocks.push(wrapperElement);
  10005. } else {
  10006. outputBlocks.push(info.block);
  10007. ii++;
  10008. }
  10009. }
  10010. return React.createElement("div", {
  10011. "data-contents": "true"
  10012. }, outputBlocks);
  10013. };
  10014. return DraftEditorContentsExperimental;
  10015. }(React.Component);
  10016. module.exports = DraftEditorContentsExperimental;
  10017. /***/ }),
  10018. /* 106 */
  10019. /***/ (function(module, exports, __webpack_require__) {
  10020. "use strict";
  10021. /**
  10022. * Copyright (c) Facebook, Inc. and its affiliates.
  10023. *
  10024. * This source code is licensed under the MIT license found in the
  10025. * LICENSE file in the root directory of this source tree.
  10026. *
  10027. * @format
  10028. *
  10029. * @emails oncall+draft_js
  10030. *
  10031. * This file is a fork of DraftEditorBlock.react.js and DraftEditorContents.react.js
  10032. *
  10033. * This is unstable and not part of the public API and should not be used by
  10034. * production systems. This file may be update/removed without notice.
  10035. */
  10036. var _assign = __webpack_require__(14);
  10037. function _extends() { _extends = _assign || 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; }; return _extends.apply(this, arguments); }
  10038. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10039. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  10040. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  10041. 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; }
  10042. var DraftEditorNode = __webpack_require__(107);
  10043. var DraftOffsetKey = __webpack_require__(10);
  10044. var React = __webpack_require__(8);
  10045. var Scroll = __webpack_require__(37);
  10046. var Style = __webpack_require__(29);
  10047. var getElementPosition = __webpack_require__(62);
  10048. var getScrollPosition = __webpack_require__(30);
  10049. var getViewportDimensions = __webpack_require__(63);
  10050. var Immutable = __webpack_require__(0);
  10051. var invariant = __webpack_require__(1);
  10052. var isHTMLElement = __webpack_require__(19);
  10053. var SCROLL_BUFFER = 10;
  10054. var List = Immutable.List; // we should harden up the bellow flow types to make them more strict
  10055. /**
  10056. * Return whether a block overlaps with either edge of the `SelectionState`.
  10057. */
  10058. var isBlockOnSelectionEdge = function isBlockOnSelectionEdge(selection, key) {
  10059. return selection.getAnchorKey() === key || selection.getFocusKey() === key;
  10060. };
  10061. /**
  10062. * We will use this helper to identify blocks that need to be wrapped but have siblings that
  10063. * also share the same wrapper element, this way we can do the wrapping once the last sibling
  10064. * is added.
  10065. */
  10066. var shouldNotAddWrapperElement = function shouldNotAddWrapperElement(block, contentState) {
  10067. var nextSiblingKey = block.getNextSiblingKey();
  10068. return nextSiblingKey ? contentState.getBlockForKey(nextSiblingKey).getType() === block.getType() : false;
  10069. };
  10070. var applyWrapperElementToSiblings = function applyWrapperElementToSiblings(wrapperTemplate, Element, nodes) {
  10071. var wrappedSiblings = []; // we check back until we find a sibbling that does not have same wrapper
  10072. var _iteratorNormalCompletion = true;
  10073. var _didIteratorError = false;
  10074. var _iteratorError = undefined;
  10075. try {
  10076. for (var _iterator = nodes.reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  10077. var sibling = _step.value;
  10078. if (sibling.type !== Element) {
  10079. break;
  10080. }
  10081. wrappedSiblings.push(sibling);
  10082. } // we now should remove from acc the wrappedSiblings and add them back under same wrap
  10083. } catch (err) {
  10084. _didIteratorError = true;
  10085. _iteratorError = err;
  10086. } finally {
  10087. try {
  10088. if (!_iteratorNormalCompletion && _iterator["return"] != null) {
  10089. _iterator["return"]();
  10090. }
  10091. } finally {
  10092. if (_didIteratorError) {
  10093. throw _iteratorError;
  10094. }
  10095. }
  10096. }
  10097. nodes.splice(nodes.indexOf(wrappedSiblings[0]), wrappedSiblings.length + 1);
  10098. var childrenIs = wrappedSiblings.reverse();
  10099. var key = childrenIs[0].key;
  10100. nodes.push(React.cloneElement(wrapperTemplate, {
  10101. key: "".concat(key, "-wrap"),
  10102. 'data-offset-key': DraftOffsetKey.encode(key, 0, 0)
  10103. }, childrenIs));
  10104. return nodes;
  10105. };
  10106. var getDraftRenderConfig = function getDraftRenderConfig(block, blockRenderMap) {
  10107. var configForType = blockRenderMap.get(block.getType()) || blockRenderMap.get('unstyled');
  10108. var wrapperTemplate = configForType.wrapper;
  10109. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  10110. return {
  10111. Element: Element,
  10112. wrapperTemplate: wrapperTemplate
  10113. };
  10114. };
  10115. var getCustomRenderConfig = function getCustomRenderConfig(block, blockRendererFn) {
  10116. var customRenderer = blockRendererFn(block);
  10117. if (!customRenderer) {
  10118. return {};
  10119. }
  10120. var CustomComponent = customRenderer.component,
  10121. customProps = customRenderer.props,
  10122. customEditable = customRenderer.editable;
  10123. return {
  10124. CustomComponent: CustomComponent,
  10125. customProps: customProps,
  10126. customEditable: customEditable
  10127. };
  10128. };
  10129. var getElementPropsConfig = function getElementPropsConfig(block, editorKey, offsetKey, blockStyleFn, customConfig, ref) {
  10130. var elementProps = {
  10131. 'data-block': true,
  10132. 'data-editor': editorKey,
  10133. 'data-offset-key': offsetKey,
  10134. key: block.getKey(),
  10135. ref: ref
  10136. };
  10137. var customClass = blockStyleFn(block);
  10138. if (customClass) {
  10139. elementProps.className = customClass;
  10140. }
  10141. if (customConfig.customEditable !== undefined) {
  10142. elementProps = _objectSpread({}, elementProps, {
  10143. contentEditable: customConfig.customEditable,
  10144. suppressContentEditableWarning: true
  10145. });
  10146. }
  10147. return elementProps;
  10148. };
  10149. var DraftEditorBlockNode =
  10150. /*#__PURE__*/
  10151. function (_React$Component) {
  10152. _inheritsLoose(DraftEditorBlockNode, _React$Component);
  10153. function DraftEditorBlockNode() {
  10154. var _this;
  10155. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  10156. args[_key] = arguments[_key];
  10157. }
  10158. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  10159. _defineProperty(_assertThisInitialized(_this), "wrapperRef", React.createRef());
  10160. return _this;
  10161. }
  10162. var _proto = DraftEditorBlockNode.prototype;
  10163. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10164. var _this$props = this.props,
  10165. block = _this$props.block,
  10166. direction = _this$props.direction,
  10167. tree = _this$props.tree;
  10168. var isContainerNode = !block.getChildKeys().isEmpty();
  10169. var blockHasChanged = block !== nextProps.block || tree !== nextProps.tree || direction !== nextProps.direction || isBlockOnSelectionEdge(nextProps.selection, nextProps.block.getKey()) && nextProps.forceSelection; // if we have children at this stage we always re-render container nodes
  10170. // else if its a root node we avoid re-rendering by checking for block updates
  10171. return isContainerNode || blockHasChanged;
  10172. }
  10173. /**
  10174. * When a block is mounted and overlaps the selection state, we need to make
  10175. * sure that the cursor is visible to match native behavior. This may not
  10176. * be the case if the user has pressed `RETURN` or pasted some content, since
  10177. * programatically creating these new blocks and setting the DOM selection
  10178. * will miss out on the browser natively scrolling to that position.
  10179. *
  10180. * To replicate native behavior, if the block overlaps the selection state
  10181. * on mount, force the scroll position. Check the scroll state of the scroll
  10182. * parent, and adjust it to align the entire block to the bottom of the
  10183. * scroll parent.
  10184. */
  10185. ;
  10186. _proto.componentDidMount = function componentDidMount() {
  10187. var selection = this.props.selection;
  10188. var endKey = selection.getEndKey();
  10189. if (!selection.getHasFocus() || endKey !== this.props.block.getKey()) {
  10190. return;
  10191. }
  10192. var blockNode = this.wrapperRef.current;
  10193. if (!blockNode) {
  10194. // This Block Node was rendered without a wrapper element.
  10195. return;
  10196. }
  10197. var scrollParent = Style.getScrollParent(blockNode);
  10198. var scrollPosition = getScrollPosition(scrollParent);
  10199. var scrollDelta;
  10200. if (scrollParent === window) {
  10201. var nodePosition = getElementPosition(blockNode);
  10202. var nodeBottom = nodePosition.y + nodePosition.height;
  10203. var viewportHeight = getViewportDimensions().height;
  10204. scrollDelta = nodeBottom - viewportHeight;
  10205. if (scrollDelta > 0) {
  10206. window.scrollTo(scrollPosition.x, scrollPosition.y + scrollDelta + SCROLL_BUFFER);
  10207. }
  10208. } else {
  10209. !isHTMLElement(blockNode) ? true ? invariant(false, 'blockNode is not an HTMLElement') : invariant(false) : void 0;
  10210. var htmlBlockNode = blockNode;
  10211. var blockBottom = htmlBlockNode.offsetHeight + htmlBlockNode.offsetTop;
  10212. var scrollBottom = scrollParent.offsetHeight + scrollPosition.y;
  10213. scrollDelta = blockBottom - scrollBottom;
  10214. if (scrollDelta > 0) {
  10215. Scroll.setTop(scrollParent, Scroll.getTop(scrollParent) + scrollDelta + SCROLL_BUFFER);
  10216. }
  10217. }
  10218. };
  10219. _proto.render = function render() {
  10220. var _this2 = this;
  10221. var _this$props2 = this.props,
  10222. block = _this$props2.block,
  10223. blockRenderMap = _this$props2.blockRenderMap,
  10224. blockRendererFn = _this$props2.blockRendererFn,
  10225. blockStyleFn = _this$props2.blockStyleFn,
  10226. contentState = _this$props2.contentState,
  10227. decorator = _this$props2.decorator,
  10228. editorKey = _this$props2.editorKey,
  10229. editorState = _this$props2.editorState,
  10230. customStyleFn = _this$props2.customStyleFn,
  10231. customStyleMap = _this$props2.customStyleMap,
  10232. direction = _this$props2.direction,
  10233. forceSelection = _this$props2.forceSelection,
  10234. selection = _this$props2.selection,
  10235. tree = _this$props2.tree;
  10236. var children = null;
  10237. if (block.children.size) {
  10238. children = block.children.reduce(function (acc, key) {
  10239. var offsetKey = DraftOffsetKey.encode(key, 0, 0);
  10240. var child = contentState.getBlockForKey(key);
  10241. var customConfig = getCustomRenderConfig(child, blockRendererFn);
  10242. var Component = customConfig.CustomComponent || DraftEditorBlockNode;
  10243. var _getDraftRenderConfig = getDraftRenderConfig(child, blockRenderMap),
  10244. Element = _getDraftRenderConfig.Element,
  10245. wrapperTemplate = _getDraftRenderConfig.wrapperTemplate;
  10246. var elementProps = getElementPropsConfig(child, editorKey, offsetKey, blockStyleFn, customConfig, null);
  10247. var childProps = _objectSpread({}, _this2.props, {
  10248. tree: editorState.getBlockTree(key),
  10249. blockProps: customConfig.customProps,
  10250. offsetKey: offsetKey,
  10251. block: child
  10252. });
  10253. acc.push(React.createElement(Element, elementProps, React.createElement(Component, childProps)));
  10254. if (!wrapperTemplate || shouldNotAddWrapperElement(child, contentState)) {
  10255. return acc;
  10256. } // if we are here it means we are the last block
  10257. // that has a wrapperTemplate so we should wrap itself
  10258. // and all other previous siblings that share the same wrapper
  10259. applyWrapperElementToSiblings(wrapperTemplate, Element, acc);
  10260. return acc;
  10261. }, []);
  10262. }
  10263. var blockKey = block.getKey();
  10264. var offsetKey = DraftOffsetKey.encode(blockKey, 0, 0);
  10265. var customConfig = getCustomRenderConfig(block, blockRendererFn);
  10266. var Component = customConfig.CustomComponent;
  10267. var blockNode = Component != null ? React.createElement(Component, _extends({}, this.props, {
  10268. tree: editorState.getBlockTree(blockKey),
  10269. blockProps: customConfig.customProps,
  10270. offsetKey: offsetKey,
  10271. block: block
  10272. })) : React.createElement(DraftEditorNode, {
  10273. block: block,
  10274. children: children,
  10275. contentState: contentState,
  10276. customStyleFn: customStyleFn,
  10277. customStyleMap: customStyleMap,
  10278. decorator: decorator,
  10279. direction: direction,
  10280. forceSelection: forceSelection,
  10281. hasSelection: isBlockOnSelectionEdge(selection, blockKey),
  10282. selection: selection,
  10283. tree: tree
  10284. });
  10285. if (block.getParentKey()) {
  10286. return blockNode;
  10287. }
  10288. var _getDraftRenderConfig2 = getDraftRenderConfig(block, blockRenderMap),
  10289. Element = _getDraftRenderConfig2.Element;
  10290. var elementProps = getElementPropsConfig(block, editorKey, offsetKey, blockStyleFn, customConfig, this.wrapperRef); // root block nodes needs to be wrapped
  10291. return React.createElement(Element, elementProps, blockNode);
  10292. };
  10293. return DraftEditorBlockNode;
  10294. }(React.Component);
  10295. module.exports = DraftEditorBlockNode;
  10296. /***/ }),
  10297. /* 107 */
  10298. /***/ (function(module, exports, __webpack_require__) {
  10299. "use strict";
  10300. /**
  10301. * Copyright (c) Facebook, Inc. and its affiliates.
  10302. *
  10303. * This source code is licensed under the MIT license found in the
  10304. * LICENSE file in the root directory of this source tree.
  10305. *
  10306. * @format
  10307. *
  10308. * @emails oncall+draft_js
  10309. *
  10310. * This is unstable and not part of the public API and should not be used by
  10311. * production systems. This file may be update/removed without notice.
  10312. */
  10313. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  10314. var DraftEditorDecoratedLeaves = __webpack_require__(108);
  10315. var DraftEditorLeaf = __webpack_require__(58);
  10316. var DraftOffsetKey = __webpack_require__(10);
  10317. var Immutable = __webpack_require__(0);
  10318. var React = __webpack_require__(8);
  10319. var cx = __webpack_require__(13);
  10320. var List = Immutable.List;
  10321. var DraftEditorNode =
  10322. /*#__PURE__*/
  10323. function (_React$Component) {
  10324. _inheritsLoose(DraftEditorNode, _React$Component);
  10325. function DraftEditorNode() {
  10326. return _React$Component.apply(this, arguments) || this;
  10327. }
  10328. var _proto = DraftEditorNode.prototype;
  10329. _proto.render = function render() {
  10330. var _this$props = this.props,
  10331. block = _this$props.block,
  10332. contentState = _this$props.contentState,
  10333. customStyleFn = _this$props.customStyleFn,
  10334. customStyleMap = _this$props.customStyleMap,
  10335. decorator = _this$props.decorator,
  10336. direction = _this$props.direction,
  10337. forceSelection = _this$props.forceSelection,
  10338. hasSelection = _this$props.hasSelection,
  10339. selection = _this$props.selection,
  10340. tree = _this$props.tree;
  10341. var blockKey = block.getKey();
  10342. var text = block.getText();
  10343. var lastLeafSet = tree.size - 1;
  10344. var children = this.props.children || tree.map(function (leafSet, ii) {
  10345. var decoratorKey = leafSet.get('decoratorKey');
  10346. var leavesForLeafSet = leafSet.get('leaves');
  10347. var lastLeaf = leavesForLeafSet.size - 1;
  10348. var Leaves = leavesForLeafSet.map(function (leaf, jj) {
  10349. var offsetKey = DraftOffsetKey.encode(blockKey, ii, jj);
  10350. var start = leaf.get('start');
  10351. var end = leaf.get('end');
  10352. return React.createElement(DraftEditorLeaf, {
  10353. key: offsetKey,
  10354. offsetKey: offsetKey,
  10355. block: block,
  10356. start: start,
  10357. selection: hasSelection ? selection : null,
  10358. forceSelection: forceSelection,
  10359. text: text.slice(start, end),
  10360. styleSet: block.getInlineStyleAt(start),
  10361. customStyleMap: customStyleMap,
  10362. customStyleFn: customStyleFn,
  10363. isLast: decoratorKey === lastLeafSet && jj === lastLeaf
  10364. });
  10365. }).toArray();
  10366. if (!decoratorKey || !decorator) {
  10367. return Leaves;
  10368. }
  10369. return React.createElement(DraftEditorDecoratedLeaves, {
  10370. block: block,
  10371. children: Leaves,
  10372. contentState: contentState,
  10373. decorator: decorator,
  10374. decoratorKey: decoratorKey,
  10375. direction: direction,
  10376. leafSet: leafSet,
  10377. text: text,
  10378. key: ii
  10379. });
  10380. }).toArray();
  10381. return React.createElement("div", {
  10382. "data-offset-key": DraftOffsetKey.encode(blockKey, 0, 0),
  10383. className: cx({
  10384. 'public/DraftStyleDefault/block': true,
  10385. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  10386. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  10387. })
  10388. }, children);
  10389. };
  10390. return DraftEditorNode;
  10391. }(React.Component);
  10392. module.exports = DraftEditorNode;
  10393. /***/ }),
  10394. /* 108 */
  10395. /***/ (function(module, exports, __webpack_require__) {
  10396. "use strict";
  10397. /**
  10398. * Copyright (c) Facebook, Inc. and its affiliates.
  10399. *
  10400. * This source code is licensed under the MIT license found in the
  10401. * LICENSE file in the root directory of this source tree.
  10402. *
  10403. * @format
  10404. *
  10405. * @emails oncall+draft_js
  10406. *
  10407. * This is unstable and not part of the public API and should not be used by
  10408. * production systems. This file may be update/removed without notice.
  10409. */
  10410. var _assign = __webpack_require__(14);
  10411. function _extends() { _extends = _assign || 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; }; return _extends.apply(this, arguments); }
  10412. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  10413. var DraftOffsetKey = __webpack_require__(10);
  10414. var React = __webpack_require__(8);
  10415. var UnicodeBidi = __webpack_require__(33);
  10416. var UnicodeBidiDirection = __webpack_require__(24);
  10417. var DraftEditorDecoratedLeaves =
  10418. /*#__PURE__*/
  10419. function (_React$Component) {
  10420. _inheritsLoose(DraftEditorDecoratedLeaves, _React$Component);
  10421. function DraftEditorDecoratedLeaves() {
  10422. return _React$Component.apply(this, arguments) || this;
  10423. }
  10424. var _proto = DraftEditorDecoratedLeaves.prototype;
  10425. _proto.render = function render() {
  10426. var _this$props = this.props,
  10427. block = _this$props.block,
  10428. children = _this$props.children,
  10429. contentState = _this$props.contentState,
  10430. decorator = _this$props.decorator,
  10431. decoratorKey = _this$props.decoratorKey,
  10432. direction = _this$props.direction,
  10433. leafSet = _this$props.leafSet,
  10434. text = _this$props.text;
  10435. var blockKey = block.getKey();
  10436. var leavesForLeafSet = leafSet.get('leaves');
  10437. var DecoratorComponent = decorator.getComponentForKey(decoratorKey);
  10438. var decoratorProps = decorator.getPropsForKey(decoratorKey);
  10439. var decoratorOffsetKey = DraftOffsetKey.encode(blockKey, parseInt(decoratorKey, 10), 0);
  10440. var decoratedText = text.slice(leavesForLeafSet.first().get('start'), leavesForLeafSet.last().get('end')); // Resetting dir to the same value on a child node makes Chrome/Firefox
  10441. // confused on cursor movement. See http://jsfiddle.net/d157kLck/3/
  10442. var dir = UnicodeBidiDirection.getHTMLDirIfDifferent(UnicodeBidi.getDirection(decoratedText), direction);
  10443. return React.createElement(DecoratorComponent, _extends({}, decoratorProps, {
  10444. contentState: contentState,
  10445. decoratedText: decoratedText,
  10446. dir: dir,
  10447. key: decoratorOffsetKey,
  10448. entityKey: block.getEntityAt(leafSet.get('start')),
  10449. offsetKey: decoratorOffsetKey
  10450. }), children);
  10451. };
  10452. return DraftEditorDecoratedLeaves;
  10453. }(React.Component);
  10454. module.exports = DraftEditorDecoratedLeaves;
  10455. /***/ }),
  10456. /* 109 */
  10457. /***/ (function(module, exports, __webpack_require__) {
  10458. "use strict";
  10459. /**
  10460. * Copyright (c) Facebook, Inc. and its affiliates.
  10461. *
  10462. * This source code is licensed under the MIT license found in the
  10463. * LICENSE file in the root directory of this source tree.
  10464. *
  10465. * @format
  10466. *
  10467. * @emails oncall+draft_js
  10468. */
  10469. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10470. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  10471. 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; }
  10472. var React = __webpack_require__(8);
  10473. var UserAgent = __webpack_require__(5);
  10474. var invariant = __webpack_require__(1);
  10475. var isElement = __webpack_require__(15); // In IE, spans with <br> tags render as two newlines. By rendering a span
  10476. // with only a newline character, we can be sure to render a single line.
  10477. var useNewlineChar = UserAgent.isBrowser('IE <= 11');
  10478. /**
  10479. * Check whether the node should be considered a newline.
  10480. */
  10481. function isNewline(node) {
  10482. return useNewlineChar ? node.textContent === '\n' : node.tagName === 'BR';
  10483. }
  10484. /**
  10485. * Placeholder elements for empty text content.
  10486. *
  10487. * What is this `data-text` attribute, anyway? It turns out that we need to
  10488. * put an attribute on the lowest-level text node in order to preserve correct
  10489. * spellcheck handling. If the <span> is naked, Chrome and Safari may do
  10490. * bizarre things to do the DOM -- split text nodes, create extra spans, etc.
  10491. * If the <span> has an attribute, this appears not to happen.
  10492. * See http://jsfiddle.net/9khdavod/ for the failure case, and
  10493. * http://jsfiddle.net/7pg143f7/ for the fixed case.
  10494. */
  10495. var NEWLINE_A = function NEWLINE_A(ref) {
  10496. return useNewlineChar ? React.createElement("span", {
  10497. key: "A",
  10498. "data-text": "true",
  10499. ref: ref
  10500. }, '\n') : React.createElement("br", {
  10501. key: "A",
  10502. "data-text": "true",
  10503. ref: ref
  10504. });
  10505. };
  10506. var NEWLINE_B = function NEWLINE_B(ref) {
  10507. return useNewlineChar ? React.createElement("span", {
  10508. key: "B",
  10509. "data-text": "true",
  10510. ref: ref
  10511. }, '\n') : React.createElement("br", {
  10512. key: "B",
  10513. "data-text": "true",
  10514. ref: ref
  10515. });
  10516. };
  10517. /**
  10518. * The lowest-level component in a `DraftEditor`, the text node component
  10519. * replaces the default React text node implementation. This allows us to
  10520. * perform custom handling of newline behavior and avoid re-rendering text
  10521. * nodes with DOM state that already matches the expectations of our immutable
  10522. * editor state.
  10523. */
  10524. var DraftEditorTextNode =
  10525. /*#__PURE__*/
  10526. function (_React$Component) {
  10527. _inheritsLoose(DraftEditorTextNode, _React$Component);
  10528. function DraftEditorTextNode(props) {
  10529. var _this;
  10530. _this = _React$Component.call(this, props) || this; // By flipping this flag, we also keep flipping keys which forces
  10531. // React to remount this node every time it rerenders.
  10532. _defineProperty(_assertThisInitialized(_this), "_forceFlag", void 0);
  10533. _defineProperty(_assertThisInitialized(_this), "_node", void 0);
  10534. _this._forceFlag = false;
  10535. return _this;
  10536. }
  10537. var _proto = DraftEditorTextNode.prototype;
  10538. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  10539. var node = this._node;
  10540. var shouldBeNewline = nextProps.children === '';
  10541. !isElement(node) ? true ? invariant(false, 'node is not an Element') : invariant(false) : void 0;
  10542. var elementNode = node;
  10543. if (shouldBeNewline) {
  10544. return !isNewline(elementNode);
  10545. }
  10546. return elementNode.textContent !== nextProps.children;
  10547. };
  10548. _proto.componentDidMount = function componentDidMount() {
  10549. this._forceFlag = !this._forceFlag;
  10550. };
  10551. _proto.componentDidUpdate = function componentDidUpdate() {
  10552. this._forceFlag = !this._forceFlag;
  10553. };
  10554. _proto.render = function render() {
  10555. var _this2 = this;
  10556. if (this.props.children === '') {
  10557. return this._forceFlag ? NEWLINE_A(function (ref) {
  10558. return _this2._node = ref;
  10559. }) : NEWLINE_B(function (ref) {
  10560. return _this2._node = ref;
  10561. });
  10562. }
  10563. return React.createElement("span", {
  10564. key: this._forceFlag ? 'A' : 'B',
  10565. "data-text": "true",
  10566. ref: function ref(_ref) {
  10567. return _this2._node = _ref;
  10568. }
  10569. }, this.props.children);
  10570. };
  10571. return DraftEditorTextNode;
  10572. }(React.Component);
  10573. module.exports = DraftEditorTextNode;
  10574. /***/ }),
  10575. /* 110 */
  10576. /***/ (function(module, exports, __webpack_require__) {
  10577. "use strict";
  10578. /**
  10579. * Copyright (c) Facebook, Inc. and its affiliates.
  10580. *
  10581. * This source code is licensed under the MIT license found in the
  10582. * LICENSE file in the root directory of this source tree.
  10583. *
  10584. * @format
  10585. *
  10586. * @emails oncall+draft_js
  10587. */
  10588. var DraftEffects = __webpack_require__(60);
  10589. var DraftJsDebugLogging = __webpack_require__(52);
  10590. var UserAgent = __webpack_require__(5);
  10591. var containsNode = __webpack_require__(36);
  10592. var getActiveElement = __webpack_require__(61);
  10593. var getCorrectDocumentFromNode = __webpack_require__(27);
  10594. var invariant = __webpack_require__(1);
  10595. var isElement = __webpack_require__(15);
  10596. var isIE = UserAgent.isBrowser('IE');
  10597. function getAnonymizedDOM(node, getNodeLabels) {
  10598. if (!node) {
  10599. return '[empty]';
  10600. }
  10601. var anonymized = anonymizeTextWithin(node, getNodeLabels);
  10602. if (anonymized.nodeType === Node.TEXT_NODE) {
  10603. return anonymized.textContent;
  10604. }
  10605. !isElement(anonymized) ? true ? invariant(false, 'Node must be an Element if it is not a text node.') : invariant(false) : void 0;
  10606. var castedElement = anonymized;
  10607. return castedElement.outerHTML;
  10608. }
  10609. function anonymizeTextWithin(node, getNodeLabels) {
  10610. var labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];
  10611. if (node.nodeType === Node.TEXT_NODE) {
  10612. var length = node.textContent.length;
  10613. return getCorrectDocumentFromNode(node).createTextNode('[text ' + length + (labels.length ? ' | ' + labels.join(', ') : '') + ']');
  10614. }
  10615. var clone = node.cloneNode();
  10616. if (clone.nodeType === 1 && labels.length) {
  10617. clone.setAttribute('data-labels', labels.join(', '));
  10618. }
  10619. var childNodes = node.childNodes;
  10620. for (var ii = 0; ii < childNodes.length; ii++) {
  10621. clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  10622. }
  10623. return clone;
  10624. }
  10625. function getAnonymizedEditorDOM(node, getNodeLabels) {
  10626. // grabbing the DOM content of the Draft editor
  10627. var currentNode = node; // this should only be used after checking with isElement
  10628. var castedNode = currentNode;
  10629. while (currentNode) {
  10630. if (isElement(currentNode) && castedNode.hasAttribute('contenteditable')) {
  10631. // found the Draft editor container
  10632. return getAnonymizedDOM(currentNode, getNodeLabels);
  10633. } else {
  10634. currentNode = currentNode.parentNode;
  10635. castedNode = currentNode;
  10636. }
  10637. }
  10638. return 'Could not find contentEditable parent of node';
  10639. }
  10640. function getNodeLength(node) {
  10641. return node.nodeValue === null ? node.childNodes.length : node.nodeValue.length;
  10642. }
  10643. /**
  10644. * In modern non-IE browsers, we can support both forward and backward
  10645. * selections.
  10646. *
  10647. * Note: IE10+ supports the Selection object, but it does not support
  10648. * the `extend` method, which means that even in modern IE, it's not possible
  10649. * to programatically create a backward selection. Thus, for all IE
  10650. * versions, we use the old IE API to create our selections.
  10651. */
  10652. function setDraftEditorSelection(selectionState, node, blockKey, nodeStart, nodeEnd) {
  10653. // It's possible that the editor has been removed from the DOM but
  10654. // our selection code doesn't know it yet. Forcing selection in
  10655. // this case may lead to errors, so just bail now.
  10656. var documentObject = getCorrectDocumentFromNode(node);
  10657. if (!containsNode(documentObject.documentElement, node)) {
  10658. return;
  10659. }
  10660. var selection = documentObject.defaultView.getSelection();
  10661. var anchorKey = selectionState.getAnchorKey();
  10662. var anchorOffset = selectionState.getAnchorOffset();
  10663. var focusKey = selectionState.getFocusKey();
  10664. var focusOffset = selectionState.getFocusOffset();
  10665. var isBackward = selectionState.getIsBackward(); // IE doesn't support backward selection. Swap key/offset pairs.
  10666. if (!selection.extend && isBackward) {
  10667. var tempKey = anchorKey;
  10668. var tempOffset = anchorOffset;
  10669. anchorKey = focusKey;
  10670. anchorOffset = focusOffset;
  10671. focusKey = tempKey;
  10672. focusOffset = tempOffset;
  10673. isBackward = false;
  10674. }
  10675. var hasAnchor = anchorKey === blockKey && nodeStart <= anchorOffset && nodeEnd >= anchorOffset;
  10676. var hasFocus = focusKey === blockKey && nodeStart <= focusOffset && nodeEnd >= focusOffset; // If the selection is entirely bound within this node, set the selection
  10677. // and be done.
  10678. if (hasAnchor && hasFocus) {
  10679. selection.removeAllRanges();
  10680. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  10681. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  10682. return;
  10683. }
  10684. if (!isBackward) {
  10685. // If the anchor is within this node, set the range start.
  10686. if (hasAnchor) {
  10687. selection.removeAllRanges();
  10688. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  10689. } // If the focus is within this node, we can assume that we have
  10690. // already set the appropriate start range on the selection, and
  10691. // can simply extend the selection.
  10692. if (hasFocus) {
  10693. addFocusToSelection(selection, node, focusOffset - nodeStart, selectionState);
  10694. }
  10695. } else {
  10696. // If this node has the focus, set the selection range to be a
  10697. // collapsed range beginning here. Later, when we encounter the anchor,
  10698. // we'll use this information to extend the selection.
  10699. if (hasFocus) {
  10700. selection.removeAllRanges();
  10701. addPointToSelection(selection, node, focusOffset - nodeStart, selectionState);
  10702. } // If this node has the anchor, we may assume that the correct
  10703. // focus information is already stored on the selection object.
  10704. // We keep track of it, reset the selection range, and extend it
  10705. // back to the focus point.
  10706. if (hasAnchor) {
  10707. var storedFocusNode = selection.focusNode;
  10708. var storedFocusOffset = selection.focusOffset;
  10709. selection.removeAllRanges();
  10710. addPointToSelection(selection, node, anchorOffset - nodeStart, selectionState);
  10711. addFocusToSelection(selection, storedFocusNode, storedFocusOffset, selectionState);
  10712. }
  10713. }
  10714. }
  10715. /**
  10716. * Extend selection towards focus point.
  10717. */
  10718. function addFocusToSelection(selection, node, offset, selectionState) {
  10719. var activeElement = getActiveElement();
  10720. if (selection.extend && containsNode(activeElement, node)) {
  10721. // If `extend` is called while another element has focus, an error is
  10722. // thrown. We therefore disable `extend` if the active element is somewhere
  10723. // other than the node we are selecting. This should only occur in Firefox,
  10724. // since it is the only browser to support multiple selections.
  10725. // See https://bugzilla.mozilla.org/show_bug.cgi?id=921444.
  10726. // logging to catch bug that is being reported in t16250795
  10727. if (offset > getNodeLength(node)) {
  10728. // the call to 'selection.extend' is about to throw
  10729. DraftJsDebugLogging.logSelectionStateFailure({
  10730. anonymizedDom: getAnonymizedEditorDOM(node),
  10731. extraParams: JSON.stringify({
  10732. offset: offset
  10733. }),
  10734. selectionState: JSON.stringify(selectionState.toJS())
  10735. });
  10736. } // logging to catch bug that is being reported in t18110632
  10737. var nodeWasFocus = node === selection.focusNode;
  10738. try {
  10739. selection.extend(node, offset);
  10740. } catch (e) {
  10741. DraftJsDebugLogging.logSelectionStateFailure({
  10742. anonymizedDom: getAnonymizedEditorDOM(node, function (n) {
  10743. var labels = [];
  10744. if (n === activeElement) {
  10745. labels.push('active element');
  10746. }
  10747. if (n === selection.anchorNode) {
  10748. labels.push('selection anchor node');
  10749. }
  10750. if (n === selection.focusNode) {
  10751. labels.push('selection focus node');
  10752. }
  10753. return labels;
  10754. }),
  10755. extraParams: JSON.stringify({
  10756. activeElementName: activeElement ? activeElement.nodeName : null,
  10757. nodeIsFocus: node === selection.focusNode,
  10758. nodeWasFocus: nodeWasFocus,
  10759. selectionRangeCount: selection.rangeCount,
  10760. selectionAnchorNodeName: selection.anchorNode ? selection.anchorNode.nodeName : null,
  10761. selectionAnchorOffset: selection.anchorOffset,
  10762. selectionFocusNodeName: selection.focusNode ? selection.focusNode.nodeName : null,
  10763. selectionFocusOffset: selection.focusOffset,
  10764. message: e ? '' + e : null,
  10765. offset: offset
  10766. }, null, 2),
  10767. selectionState: JSON.stringify(selectionState.toJS(), null, 2)
  10768. }); // allow the error to be thrown -
  10769. // better than continuing in a broken state
  10770. throw e;
  10771. }
  10772. } else {
  10773. // IE doesn't support extend. This will mean no backward selection.
  10774. // Extract the existing selection range and add focus to it.
  10775. // Additionally, clone the selection range. IE11 throws an
  10776. // InvalidStateError when attempting to access selection properties
  10777. // after the range is detached.
  10778. if (selection.rangeCount > 0) {
  10779. var range = selection.getRangeAt(0);
  10780. range.setEnd(node, offset);
  10781. selection.addRange(range.cloneRange());
  10782. }
  10783. }
  10784. }
  10785. function addPointToSelection(selection, node, offset, selectionState) {
  10786. var range = getCorrectDocumentFromNode(node).createRange(); // logging to catch bug that is being reported in t16250795
  10787. if (offset > getNodeLength(node)) {
  10788. // in this case we know that the call to 'range.setStart' is about to throw
  10789. DraftJsDebugLogging.logSelectionStateFailure({
  10790. anonymizedDom: getAnonymizedEditorDOM(node),
  10791. extraParams: JSON.stringify({
  10792. offset: offset
  10793. }),
  10794. selectionState: JSON.stringify(selectionState.toJS())
  10795. });
  10796. DraftEffects.handleExtensionCausedError();
  10797. }
  10798. range.setStart(node, offset); // IE sometimes throws Unspecified Error when trying to addRange
  10799. if (isIE) {
  10800. try {
  10801. selection.addRange(range);
  10802. } catch (e) {
  10803. if (true) {
  10804. /* eslint-disable-next-line no-console */
  10805. console.warn('Call to selection.addRange() threw exception: ', e);
  10806. }
  10807. }
  10808. } else {
  10809. selection.addRange(range);
  10810. }
  10811. }
  10812. module.exports = {
  10813. setDraftEditorSelection: setDraftEditorSelection,
  10814. addFocusToSelection: addFocusToSelection
  10815. };
  10816. /***/ }),
  10817. /* 111 */
  10818. /***/ (function(module, exports, __webpack_require__) {
  10819. "use strict";
  10820. /**
  10821. * Copyright (c) 2013-present, Facebook, Inc.
  10822. *
  10823. * This source code is licensed under the MIT license found in the
  10824. * LICENSE file in the root directory of this source tree.
  10825. *
  10826. * @typechecks
  10827. */
  10828. var isNode = __webpack_require__(112);
  10829. /**
  10830. * @param {*} object The object to check.
  10831. * @return {boolean} Whether or not the object is a DOM text node.
  10832. */
  10833. function isTextNode(object) {
  10834. return isNode(object) && object.nodeType == 3;
  10835. }
  10836. module.exports = isTextNode;
  10837. /***/ }),
  10838. /* 112 */
  10839. /***/ (function(module, exports, __webpack_require__) {
  10840. "use strict";
  10841. /**
  10842. * Copyright (c) 2013-present, Facebook, Inc.
  10843. *
  10844. * This source code is licensed under the MIT license found in the
  10845. * LICENSE file in the root directory of this source tree.
  10846. *
  10847. * @typechecks
  10848. */
  10849. /**
  10850. * @param {*} object The object to check.
  10851. * @return {boolean} Whether or not the object is a DOM node.
  10852. */
  10853. function isNode(object) {
  10854. var doc = object ? object.ownerDocument || object : document;
  10855. var defaultView = doc.defaultView || window;
  10856. return !!(object && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
  10857. }
  10858. module.exports = isNode;
  10859. /***/ }),
  10860. /* 113 */
  10861. /***/ (function(module, exports, __webpack_require__) {
  10862. "use strict";
  10863. /**
  10864. * Copyright (c) 2013-present, Facebook, Inc.
  10865. *
  10866. * This source code is licensed under the MIT license found in the
  10867. * LICENSE file in the root directory of this source tree.
  10868. *
  10869. * @typechecks
  10870. */
  10871. var camelize = __webpack_require__(114);
  10872. var hyphenate = __webpack_require__(115);
  10873. function asString(value)
  10874. /*?string*/
  10875. {
  10876. return value == null ? value : String(value);
  10877. }
  10878. function getStyleProperty(
  10879. /*DOMNode*/
  10880. node,
  10881. /*string*/
  10882. name)
  10883. /*?string*/
  10884. {
  10885. var computedStyle; // W3C Standard
  10886. if (window.getComputedStyle) {
  10887. // In certain cases such as within an iframe in FF3, this returns null.
  10888. computedStyle = window.getComputedStyle(node, null);
  10889. if (computedStyle) {
  10890. return asString(computedStyle.getPropertyValue(hyphenate(name)));
  10891. }
  10892. } // Safari
  10893. if (document.defaultView && document.defaultView.getComputedStyle) {
  10894. computedStyle = document.defaultView.getComputedStyle(node, null); // A Safari bug causes this to return null for `display: none` elements.
  10895. if (computedStyle) {
  10896. return asString(computedStyle.getPropertyValue(hyphenate(name)));
  10897. }
  10898. if (name === 'display') {
  10899. return 'none';
  10900. }
  10901. } // Internet Explorer
  10902. if (node.currentStyle) {
  10903. if (name === 'float') {
  10904. return asString(node.currentStyle.cssFloat || node.currentStyle.styleFloat);
  10905. }
  10906. return asString(node.currentStyle[camelize(name)]);
  10907. }
  10908. return asString(node.style && node.style[camelize(name)]);
  10909. }
  10910. module.exports = getStyleProperty;
  10911. /***/ }),
  10912. /* 114 */
  10913. /***/ (function(module, exports, __webpack_require__) {
  10914. "use strict";
  10915. /**
  10916. * Copyright (c) 2013-present, Facebook, Inc.
  10917. *
  10918. * This source code is licensed under the MIT license found in the
  10919. * LICENSE file in the root directory of this source tree.
  10920. *
  10921. * @typechecks
  10922. */
  10923. var _hyphenPattern = /-(.)/g;
  10924. /**
  10925. * Camelcases a hyphenated string, for example:
  10926. *
  10927. * > camelize('background-color')
  10928. * < "backgroundColor"
  10929. *
  10930. * @param {string} string
  10931. * @return {string}
  10932. */
  10933. function camelize(string) {
  10934. return string.replace(_hyphenPattern, function (_, character) {
  10935. return character.toUpperCase();
  10936. });
  10937. }
  10938. module.exports = camelize;
  10939. /***/ }),
  10940. /* 115 */
  10941. /***/ (function(module, exports, __webpack_require__) {
  10942. "use strict";
  10943. /**
  10944. * Copyright (c) 2013-present, Facebook, Inc.
  10945. *
  10946. * This source code is licensed under the MIT license found in the
  10947. * LICENSE file in the root directory of this source tree.
  10948. *
  10949. * @typechecks
  10950. */
  10951. var _uppercasePattern = /([A-Z])/g;
  10952. /**
  10953. * Hyphenates a camelcased string, for example:
  10954. *
  10955. * > hyphenate('backgroundColor')
  10956. * < "background-color"
  10957. *
  10958. * For CSS style names, use `hyphenateStyleName` instead which works properly
  10959. * with all vendor prefixes, including `ms`.
  10960. *
  10961. * @param {string} string
  10962. * @return {string}
  10963. */
  10964. function hyphenate(string) {
  10965. return string.replace(_uppercasePattern, '-$1').toLowerCase();
  10966. }
  10967. module.exports = hyphenate;
  10968. /***/ }),
  10969. /* 116 */
  10970. /***/ (function(module, exports, __webpack_require__) {
  10971. "use strict";
  10972. /**
  10973. * Copyright (c) 2013-present, Facebook, Inc.
  10974. *
  10975. * This source code is licensed under the MIT license found in the
  10976. * LICENSE file in the root directory of this source tree.
  10977. *
  10978. * @typechecks
  10979. */
  10980. var containsNode = __webpack_require__(36);
  10981. /**
  10982. * Gets an element's bounding rect in pixels relative to the viewport.
  10983. *
  10984. * @param {DOMElement} elem
  10985. * @return {object}
  10986. */
  10987. function getElementRect(elem) {
  10988. var docElem = elem.ownerDocument.documentElement; // FF 2, Safari 3 and Opera 9.5- do not support getBoundingClientRect().
  10989. // IE9- will throw if the element is not in the document.
  10990. if (!('getBoundingClientRect' in elem) || !containsNode(docElem, elem)) {
  10991. return {
  10992. left: 0,
  10993. right: 0,
  10994. top: 0,
  10995. bottom: 0
  10996. };
  10997. } // Subtracts clientTop/Left because IE8- added a 2px border to the
  10998. // <html> element (see http://fburl.com/1493213). IE 7 in
  10999. // Quicksmode does not report clientLeft/clientTop so there
  11000. // will be an unaccounted offset of 2px when in quirksmode
  11001. var rect = elem.getBoundingClientRect();
  11002. return {
  11003. left: Math.round(rect.left) - docElem.clientLeft,
  11004. right: Math.round(rect.right) - docElem.clientLeft,
  11005. top: Math.round(rect.top) - docElem.clientTop,
  11006. bottom: Math.round(rect.bottom) - docElem.clientTop
  11007. };
  11008. }
  11009. module.exports = getElementRect;
  11010. /***/ }),
  11011. /* 117 */
  11012. /***/ (function(module, exports, __webpack_require__) {
  11013. "use strict";
  11014. /**
  11015. * Copyright (c) 2013-present, Facebook, Inc.
  11016. *
  11017. * This source code is licensed under the MIT license found in the
  11018. * LICENSE file in the root directory of this source tree.
  11019. *
  11020. * @typechecks
  11021. */
  11022. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  11023. /**
  11024. * Gets the element with the document scroll properties such as `scrollLeft` and
  11025. * `scrollHeight`. This may differ across different browsers.
  11026. *
  11027. * NOTE: The return value can be null if the DOM is not yet ready.
  11028. *
  11029. * @param {?DOMDocument} doc Defaults to current document.
  11030. * @return {?DOMElement}
  11031. */
  11032. function getDocumentScrollElement(doc) {
  11033. doc = doc || document;
  11034. if (doc.scrollingElement) {
  11035. return doc.scrollingElement;
  11036. }
  11037. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  11038. }
  11039. module.exports = getDocumentScrollElement;
  11040. /***/ }),
  11041. /* 118 */
  11042. /***/ (function(module, exports, __webpack_require__) {
  11043. "use strict";
  11044. /**
  11045. * Copyright (c) 2013-present, Facebook, Inc.
  11046. *
  11047. * This source code is licensed under the MIT license found in the
  11048. * LICENSE file in the root directory of this source tree.
  11049. *
  11050. * @typechecks
  11051. */
  11052. /**
  11053. * Gets the scroll position of the supplied element or window.
  11054. *
  11055. * The return values are unbounded, unlike `getScrollPosition`. This means they
  11056. * may be negative or exceed the element boundaries (which is possible using
  11057. * inertial scrolling).
  11058. *
  11059. * @param {DOMWindow|DOMElement} scrollable
  11060. * @return {object} Map with `x` and `y` keys.
  11061. */
  11062. function getUnboundedScrollPosition(scrollable) {
  11063. if (scrollable.Window && scrollable instanceof scrollable.Window) {
  11064. return {
  11065. x: scrollable.pageXOffset || scrollable.document.documentElement.scrollLeft,
  11066. y: scrollable.pageYOffset || scrollable.document.documentElement.scrollTop
  11067. };
  11068. }
  11069. return {
  11070. x: scrollable.scrollLeft,
  11071. y: scrollable.scrollTop
  11072. };
  11073. }
  11074. module.exports = getUnboundedScrollPosition;
  11075. /***/ }),
  11076. /* 119 */
  11077. /***/ (function(module, exports, __webpack_require__) {
  11078. "use strict";
  11079. /**
  11080. * Copyright (c) Facebook, Inc. and its affiliates.
  11081. *
  11082. * This source code is licensed under the MIT license found in the
  11083. * LICENSE file in the root directory of this source tree.
  11084. *
  11085. * @format
  11086. *
  11087. * @emails oncall+draft_js
  11088. */
  11089. var _assign = __webpack_require__(14);
  11090. function _extends() { _extends = _assign || 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; }; return _extends.apply(this, arguments); }
  11091. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  11092. 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; }
  11093. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  11094. var DraftEditorBlock = __webpack_require__(64);
  11095. var DraftOffsetKey = __webpack_require__(10);
  11096. var React = __webpack_require__(8);
  11097. var cx = __webpack_require__(13);
  11098. var joinClasses = __webpack_require__(120);
  11099. var nullthrows = __webpack_require__(4);
  11100. /**
  11101. * Provide default styling for list items. This way, lists will be styled with
  11102. * proper counters and indentation even if the caller does not specify
  11103. * their own styling at all. If more than five levels of nesting are needed,
  11104. * the necessary CSS classes can be provided via `blockStyleFn` configuration.
  11105. */
  11106. var getListItemClasses = function getListItemClasses(type, depth, shouldResetCount, direction) {
  11107. return cx({
  11108. 'public/DraftStyleDefault/unorderedListItem': type === 'unordered-list-item',
  11109. 'public/DraftStyleDefault/orderedListItem': type === 'ordered-list-item',
  11110. 'public/DraftStyleDefault/reset': shouldResetCount,
  11111. 'public/DraftStyleDefault/depth0': depth === 0,
  11112. 'public/DraftStyleDefault/depth1': depth === 1,
  11113. 'public/DraftStyleDefault/depth2': depth === 2,
  11114. 'public/DraftStyleDefault/depth3': depth === 3,
  11115. 'public/DraftStyleDefault/depth4': depth >= 4,
  11116. 'public/DraftStyleDefault/listLTR': direction === 'LTR',
  11117. 'public/DraftStyleDefault/listRTL': direction === 'RTL'
  11118. });
  11119. };
  11120. /**
  11121. * `DraftEditorContents` is the container component for all block components
  11122. * rendered for a `DraftEditor`. It is optimized to aggressively avoid
  11123. * re-rendering blocks whenever possible.
  11124. *
  11125. * This component is separate from `DraftEditor` because certain props
  11126. * (for instance, ARIA props) must be allowed to update without affecting
  11127. * the contents of the editor.
  11128. */
  11129. var DraftEditorContents =
  11130. /*#__PURE__*/
  11131. function (_React$Component) {
  11132. _inheritsLoose(DraftEditorContents, _React$Component);
  11133. function DraftEditorContents() {
  11134. return _React$Component.apply(this, arguments) || this;
  11135. }
  11136. var _proto = DraftEditorContents.prototype;
  11137. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  11138. var prevEditorState = this.props.editorState;
  11139. var nextEditorState = nextProps.editorState;
  11140. var prevDirectionMap = prevEditorState.getDirectionMap();
  11141. var nextDirectionMap = nextEditorState.getDirectionMap(); // Text direction has changed for one or more blocks. We must re-render.
  11142. if (prevDirectionMap !== nextDirectionMap) {
  11143. return true;
  11144. }
  11145. var didHaveFocus = prevEditorState.getSelection().getHasFocus();
  11146. var nowHasFocus = nextEditorState.getSelection().getHasFocus();
  11147. if (didHaveFocus !== nowHasFocus) {
  11148. return true;
  11149. }
  11150. var nextNativeContent = nextEditorState.getNativelyRenderedContent();
  11151. var wasComposing = prevEditorState.isInCompositionMode();
  11152. var nowComposing = nextEditorState.isInCompositionMode(); // If the state is unchanged or we're currently rendering a natively
  11153. // rendered state, there's nothing new to be done.
  11154. if (prevEditorState === nextEditorState || nextNativeContent !== null && nextEditorState.getCurrentContent() === nextNativeContent || wasComposing && nowComposing) {
  11155. return false;
  11156. }
  11157. var prevContent = prevEditorState.getCurrentContent();
  11158. var nextContent = nextEditorState.getCurrentContent();
  11159. var prevDecorator = prevEditorState.getDecorator();
  11160. var nextDecorator = nextEditorState.getDecorator();
  11161. return wasComposing !== nowComposing || prevContent !== nextContent || prevDecorator !== nextDecorator || nextEditorState.mustForceSelection();
  11162. };
  11163. _proto.render = function render() {
  11164. var _this$props = this.props,
  11165. blockRenderMap = _this$props.blockRenderMap,
  11166. blockRendererFn = _this$props.blockRendererFn,
  11167. blockStyleFn = _this$props.blockStyleFn,
  11168. customStyleMap = _this$props.customStyleMap,
  11169. customStyleFn = _this$props.customStyleFn,
  11170. editorState = _this$props.editorState,
  11171. editorKey = _this$props.editorKey,
  11172. preventScroll = _this$props.preventScroll,
  11173. textDirectionality = _this$props.textDirectionality;
  11174. var content = editorState.getCurrentContent();
  11175. var selection = editorState.getSelection();
  11176. var forceSelection = editorState.mustForceSelection();
  11177. var decorator = editorState.getDecorator();
  11178. var directionMap = nullthrows(editorState.getDirectionMap());
  11179. var blocksAsArray = content.getBlocksAsArray();
  11180. var processedBlocks = [];
  11181. var currentDepth = null;
  11182. var lastWrapperTemplate = null;
  11183. for (var ii = 0; ii < blocksAsArray.length; ii++) {
  11184. var _block = blocksAsArray[ii];
  11185. var key = _block.getKey();
  11186. var blockType = _block.getType();
  11187. var customRenderer = blockRendererFn(_block);
  11188. var CustomComponent = void 0,
  11189. customProps = void 0,
  11190. customEditable = void 0;
  11191. if (customRenderer) {
  11192. CustomComponent = customRenderer.component;
  11193. customProps = customRenderer.props;
  11194. customEditable = customRenderer.editable;
  11195. }
  11196. var direction = textDirectionality ? textDirectionality : directionMap.get(key);
  11197. var offsetKey = DraftOffsetKey.encode(key, 0, 0);
  11198. var componentProps = {
  11199. contentState: content,
  11200. block: _block,
  11201. blockProps: customProps,
  11202. blockStyleFn: blockStyleFn,
  11203. customStyleMap: customStyleMap,
  11204. customStyleFn: customStyleFn,
  11205. decorator: decorator,
  11206. direction: direction,
  11207. forceSelection: forceSelection,
  11208. offsetKey: offsetKey,
  11209. preventScroll: preventScroll,
  11210. selection: selection,
  11211. tree: editorState.getBlockTree(key)
  11212. };
  11213. var configForType = blockRenderMap.get(blockType) || blockRenderMap.get('unstyled');
  11214. var wrapperTemplate = configForType.wrapper;
  11215. var Element = configForType.element || blockRenderMap.get('unstyled').element;
  11216. var depth = _block.getDepth();
  11217. var _className = '';
  11218. if (blockStyleFn) {
  11219. _className = blockStyleFn(_block);
  11220. } // List items are special snowflakes, since we handle nesting and
  11221. // counters manually.
  11222. if (Element === 'li') {
  11223. var shouldResetCount = lastWrapperTemplate !== wrapperTemplate || currentDepth === null || depth > currentDepth;
  11224. _className = joinClasses(_className, getListItemClasses(blockType, depth, shouldResetCount, direction));
  11225. }
  11226. var Component = CustomComponent || DraftEditorBlock;
  11227. var childProps = {
  11228. className: _className,
  11229. 'data-block': true,
  11230. 'data-editor': editorKey,
  11231. 'data-offset-key': offsetKey,
  11232. key: key
  11233. };
  11234. if (customEditable !== undefined) {
  11235. childProps = _objectSpread({}, childProps, {
  11236. contentEditable: customEditable,
  11237. suppressContentEditableWarning: true
  11238. });
  11239. }
  11240. var child = React.createElement(Element, childProps,
  11241. /* $FlowFixMe(>=0.112.0 site=www,mobile) This comment suppresses an
  11242. * error found when Flow v0.112 was deployed. To see the error delete
  11243. * this comment and run Flow. */
  11244. React.createElement(Component, _extends({}, componentProps, {
  11245. key: key
  11246. })));
  11247. processedBlocks.push({
  11248. block: child,
  11249. wrapperTemplate: wrapperTemplate,
  11250. key: key,
  11251. offsetKey: offsetKey
  11252. });
  11253. if (wrapperTemplate) {
  11254. currentDepth = _block.getDepth();
  11255. } else {
  11256. currentDepth = null;
  11257. }
  11258. lastWrapperTemplate = wrapperTemplate;
  11259. } // Group contiguous runs of blocks that have the same wrapperTemplate
  11260. var outputBlocks = [];
  11261. for (var _ii = 0; _ii < processedBlocks.length;) {
  11262. var info = processedBlocks[_ii];
  11263. if (info.wrapperTemplate) {
  11264. var blocks = [];
  11265. do {
  11266. blocks.push(processedBlocks[_ii].block);
  11267. _ii++;
  11268. } while (_ii < processedBlocks.length && processedBlocks[_ii].wrapperTemplate === info.wrapperTemplate);
  11269. var wrapperElement = React.cloneElement(info.wrapperTemplate, {
  11270. key: info.key + '-wrap',
  11271. 'data-offset-key': info.offsetKey
  11272. }, blocks);
  11273. outputBlocks.push(wrapperElement);
  11274. } else {
  11275. outputBlocks.push(info.block);
  11276. _ii++;
  11277. }
  11278. }
  11279. return React.createElement("div", {
  11280. "data-contents": "true"
  11281. }, outputBlocks);
  11282. };
  11283. return DraftEditorContents;
  11284. }(React.Component);
  11285. module.exports = DraftEditorContents;
  11286. /***/ }),
  11287. /* 120 */
  11288. /***/ (function(module, exports, __webpack_require__) {
  11289. "use strict";
  11290. /**
  11291. * Copyright (c) 2013-present, Facebook, Inc.
  11292. *
  11293. * This source code is licensed under the MIT license found in the
  11294. * LICENSE file in the root directory of this source tree.
  11295. *
  11296. *
  11297. * @typechecks static-only
  11298. */
  11299. /**
  11300. * Combines multiple className strings into one.
  11301. */
  11302. function joinClasses(className) {
  11303. var newClassName = className || '';
  11304. var argLength = arguments.length;
  11305. if (argLength > 1) {
  11306. for (var index = 1; index < argLength; index++) {
  11307. var nextClass = arguments[index];
  11308. if (nextClass) {
  11309. newClassName = (newClassName ? newClassName + ' ' : '') + nextClass;
  11310. }
  11311. }
  11312. }
  11313. return newClassName;
  11314. }
  11315. module.exports = joinClasses;
  11316. /***/ }),
  11317. /* 121 */
  11318. /***/ (function(module, exports, __webpack_require__) {
  11319. "use strict";
  11320. /**
  11321. * Copyright (c) Facebook, Inc. and its affiliates.
  11322. *
  11323. * This source code is licensed under the MIT license found in the
  11324. * LICENSE file in the root directory of this source tree.
  11325. *
  11326. * @format
  11327. *
  11328. * @emails oncall+draft_js
  11329. */
  11330. var DataTransfer = __webpack_require__(65);
  11331. var DraftModifier = __webpack_require__(3);
  11332. var EditorState = __webpack_require__(2);
  11333. var findAncestorOffsetKey = __webpack_require__(26);
  11334. var getCorrectDocumentFromNode = __webpack_require__(27);
  11335. var getTextContentFromFiles = __webpack_require__(67);
  11336. var getUpdatedSelectionState = __webpack_require__(56);
  11337. var getWindowForNode = __webpack_require__(50);
  11338. var isEventHandled = __webpack_require__(31);
  11339. var nullthrows = __webpack_require__(4);
  11340. /**
  11341. * Get a SelectionState for the supplied mouse event.
  11342. */
  11343. function getSelectionForEvent(event, editorState) {
  11344. var node = null;
  11345. var offset = null;
  11346. var eventTargetDocument = getCorrectDocumentFromNode(event.currentTarget);
  11347. /* $FlowFixMe(>=0.68.0 site=www,mobile) This comment suppresses an error
  11348. * found when Flow v0.68 was deployed. To see the error delete this comment
  11349. * and run Flow. */
  11350. if (typeof eventTargetDocument.caretRangeFromPoint === 'function') {
  11351. /* $FlowFixMe(>=0.68.0 site=www,mobile) This comment suppresses an error
  11352. * found when Flow v0.68 was deployed. To see the error delete this comment
  11353. * and run Flow. */
  11354. var dropRange = eventTargetDocument.caretRangeFromPoint(event.x, event.y);
  11355. node = dropRange.startContainer;
  11356. offset = dropRange.startOffset;
  11357. } else if (event.rangeParent) {
  11358. node = event.rangeParent;
  11359. offset = event.rangeOffset;
  11360. } else {
  11361. return null;
  11362. }
  11363. node = nullthrows(node);
  11364. offset = nullthrows(offset);
  11365. var offsetKey = nullthrows(findAncestorOffsetKey(node));
  11366. return getUpdatedSelectionState(editorState, offsetKey, offset, offsetKey, offset);
  11367. }
  11368. var DraftEditorDragHandler = {
  11369. /**
  11370. * Drag originating from input terminated.
  11371. */
  11372. onDragEnd: function onDragEnd(editor) {
  11373. editor.exitCurrentMode();
  11374. endDrag(editor);
  11375. },
  11376. /**
  11377. * Handle data being dropped.
  11378. */
  11379. onDrop: function onDrop(editor, e) {
  11380. var data = new DataTransfer(e.nativeEvent.dataTransfer);
  11381. var editorState = editor._latestEditorState;
  11382. var dropSelection = getSelectionForEvent(e.nativeEvent, editorState);
  11383. e.preventDefault();
  11384. editor._dragCount = 0;
  11385. editor.exitCurrentMode();
  11386. if (dropSelection == null) {
  11387. return;
  11388. }
  11389. var files = data.getFiles();
  11390. if (files.length > 0) {
  11391. if (editor.props.handleDroppedFiles && isEventHandled(editor.props.handleDroppedFiles(dropSelection, files))) {
  11392. return;
  11393. }
  11394. /* $FlowFixMe This comment suppresses an error found DataTransfer was
  11395. * typed. getFiles() returns an array of <Files extends Blob>, not Blob
  11396. */
  11397. getTextContentFromFiles(files, function (fileText) {
  11398. fileText && editor.update(insertTextAtSelection(editorState, dropSelection, fileText));
  11399. });
  11400. return;
  11401. }
  11402. var dragType = editor._internalDrag ? 'internal' : 'external';
  11403. if (editor.props.handleDrop && isEventHandled(editor.props.handleDrop(dropSelection, data, dragType))) {// handled
  11404. } else if (editor._internalDrag) {
  11405. editor.update(moveText(editorState, dropSelection));
  11406. } else {
  11407. editor.update(insertTextAtSelection(editorState, dropSelection, data.getText()));
  11408. }
  11409. endDrag(editor);
  11410. }
  11411. };
  11412. function endDrag(editor) {
  11413. editor._internalDrag = false; // Fix issue #1383
  11414. // Prior to React v16.5.0 onDrop breaks onSelect event:
  11415. // https://github.com/facebook/react/issues/11379.
  11416. // Dispatching a mouseup event on DOM node will make it go back to normal.
  11417. var editorNode = editor.editorContainer;
  11418. if (editorNode) {
  11419. var mouseUpEvent = new MouseEvent('mouseup', {
  11420. view: getWindowForNode(editorNode),
  11421. bubbles: true,
  11422. cancelable: true
  11423. });
  11424. editorNode.dispatchEvent(mouseUpEvent);
  11425. }
  11426. }
  11427. function moveText(editorState, targetSelection) {
  11428. var newContentState = DraftModifier.moveText(editorState.getCurrentContent(), editorState.getSelection(), targetSelection);
  11429. return EditorState.push(editorState, newContentState, 'insert-fragment');
  11430. }
  11431. /**
  11432. * Insert text at a specified selection.
  11433. */
  11434. function insertTextAtSelection(editorState, selection, text) {
  11435. var newContentState = DraftModifier.insertText(editorState.getCurrentContent(), selection, text, editorState.getCurrentInlineStyle());
  11436. return EditorState.push(editorState, newContentState, 'insert-fragment');
  11437. }
  11438. module.exports = DraftEditorDragHandler;
  11439. /***/ }),
  11440. /* 122 */
  11441. /***/ (function(module, exports, __webpack_require__) {
  11442. "use strict";
  11443. /**
  11444. * Copyright (c) 2013-present, Facebook, Inc.
  11445. *
  11446. * This source code is licensed under the MIT license found in the
  11447. * LICENSE file in the root directory of this source tree.
  11448. *
  11449. */
  11450. var PhotosMimeType = {
  11451. isImage: function isImage(mimeString) {
  11452. return getParts(mimeString)[0] === 'image';
  11453. },
  11454. isJpeg: function isJpeg(mimeString) {
  11455. var parts = getParts(mimeString);
  11456. return PhotosMimeType.isImage(mimeString) && ( // see http://fburl.com/10972194
  11457. parts[1] === 'jpeg' || parts[1] === 'pjpeg');
  11458. }
  11459. };
  11460. function getParts(mimeString) {
  11461. return mimeString.split('/');
  11462. }
  11463. module.exports = PhotosMimeType;
  11464. /***/ }),
  11465. /* 123 */
  11466. /***/ (function(module, exports, __webpack_require__) {
  11467. "use strict";
  11468. /**
  11469. * Copyright (c) 2013-present, Facebook, Inc.
  11470. *
  11471. * This source code is licensed under the MIT license found in the
  11472. * LICENSE file in the root directory of this source tree.
  11473. *
  11474. * @typechecks
  11475. */
  11476. var invariant = __webpack_require__(1);
  11477. /**
  11478. * Convert array-like objects to arrays.
  11479. *
  11480. * This API assumes the caller knows the contents of the data type. For less
  11481. * well defined inputs use createArrayFromMixed.
  11482. *
  11483. * @param {object|function|filelist} obj
  11484. * @return {array}
  11485. */
  11486. function toArray(obj) {
  11487. var length = obj.length; // Some browsers builtin objects can report typeof 'function' (e.g. NodeList
  11488. // in old versions of Safari).
  11489. !(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? true ? invariant(false, 'toArray: Array-like object expected') : invariant(false) : void 0;
  11490. !(typeof length === 'number') ? true ? invariant(false, 'toArray: Object needs a length property') : invariant(false) : void 0;
  11491. !(length === 0 || length - 1 in obj) ? true ? invariant(false, 'toArray: Object should have keys for indices') : invariant(false) : void 0;
  11492. !(typeof obj.callee !== 'function') ? true ? invariant(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant(false) : void 0; // Old IE doesn't give collections access to hasOwnProperty. Assume inputs
  11493. // without method will throw during the slice call and skip straight to the
  11494. // fallback.
  11495. if (obj.hasOwnProperty) {
  11496. try {
  11497. return Array.prototype.slice.call(obj);
  11498. } catch (e) {// IE < 9 does not support Array#slice on collections objects
  11499. }
  11500. } // Fall back to copying key by key. This assumes all keys have a value,
  11501. // so will not preserve sparsely populated inputs.
  11502. var ret = Array(length);
  11503. for (var ii = 0; ii < length; ii++) {
  11504. ret[ii] = obj[ii];
  11505. }
  11506. return ret;
  11507. }
  11508. /**
  11509. * Perform a heuristic test to determine if an object is "array-like".
  11510. *
  11511. * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
  11512. * Joshu replied: "Mu."
  11513. *
  11514. * This function determines if its argument has "array nature": it returns
  11515. * true if the argument is an actual array, an `arguments' object, or an
  11516. * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
  11517. *
  11518. * It will return false for other array-like objects like Filelist.
  11519. *
  11520. * @param {*} obj
  11521. * @return {boolean}
  11522. */
  11523. function hasArrayNature(obj) {
  11524. return (// not null/false
  11525. !!obj && ( // arrays are objects, NodeLists are functions in Safari
  11526. typeof obj == 'object' || typeof obj == 'function') && // quacks like an array
  11527. 'length' in obj && // not window
  11528. !('setInterval' in obj) && // no DOM node should be considered an array-like
  11529. // a 'select' element has 'length' and 'item' properties on IE8
  11530. typeof obj.nodeType != 'number' && ( // a real array
  11531. Array.isArray(obj) || // arguments
  11532. 'callee' in obj || // HTMLCollection/NodeList
  11533. 'item' in obj)
  11534. );
  11535. }
  11536. /**
  11537. * Ensure that the argument is an array by wrapping it in an array if it is not.
  11538. * Creates a copy of the argument if it is already an array.
  11539. *
  11540. * This is mostly useful idiomatically:
  11541. *
  11542. * var createArrayFromMixed = require('createArrayFromMixed');
  11543. *
  11544. * function takesOneOrMoreThings(things) {
  11545. * things = createArrayFromMixed(things);
  11546. * ...
  11547. * }
  11548. *
  11549. * This allows you to treat `things' as an array, but accept scalars in the API.
  11550. *
  11551. * If you need to convert an array-like object, like `arguments`, into an array
  11552. * use toArray instead.
  11553. *
  11554. * @param {*} obj
  11555. * @return {array}
  11556. */
  11557. function createArrayFromMixed(obj) {
  11558. if (!hasArrayNature(obj)) {
  11559. return [obj];
  11560. } else if (Array.isArray(obj)) {
  11561. return obj.slice();
  11562. } else {
  11563. return toArray(obj);
  11564. }
  11565. }
  11566. module.exports = createArrayFromMixed;
  11567. /***/ }),
  11568. /* 124 */
  11569. /***/ (function(module, exports, __webpack_require__) {
  11570. "use strict";
  11571. /**
  11572. * Copyright (c) Facebook, Inc. and its affiliates.
  11573. *
  11574. * This source code is licensed under the MIT license found in the
  11575. * LICENSE file in the root directory of this source tree.
  11576. *
  11577. * @format
  11578. *
  11579. * @emails oncall+draft_js
  11580. */
  11581. var UserAgent = __webpack_require__(5);
  11582. var onBeforeInput = __webpack_require__(125);
  11583. var onBlur = __webpack_require__(130);
  11584. var onCompositionStart = __webpack_require__(131);
  11585. var onCopy = __webpack_require__(132);
  11586. var onCut = __webpack_require__(133);
  11587. var onDragOver = __webpack_require__(135);
  11588. var onDragStart = __webpack_require__(136);
  11589. var onFocus = __webpack_require__(137);
  11590. var onInput = __webpack_require__(138);
  11591. var onKeyDown = __webpack_require__(139);
  11592. var onPaste = __webpack_require__(153);
  11593. var onSelect = __webpack_require__(51);
  11594. var isChrome = UserAgent.isBrowser('Chrome');
  11595. var selectionHandler = isChrome ? onSelect : function (e) {};
  11596. var DraftEditorEditHandler = {
  11597. onBeforeInput: onBeforeInput,
  11598. onBlur: onBlur,
  11599. onCompositionStart: onCompositionStart,
  11600. onCopy: onCopy,
  11601. onCut: onCut,
  11602. onDragOver: onDragOver,
  11603. onDragStart: onDragStart,
  11604. onFocus: onFocus,
  11605. onInput: onInput,
  11606. onKeyDown: onKeyDown,
  11607. onPaste: onPaste,
  11608. onSelect: onSelect,
  11609. // In certain cases, contenteditable on chrome does not fire the onSelect
  11610. // event, causing problems with cursor positioning. Therefore, the selection
  11611. // state update handler is added to more events to ensure that the selection
  11612. // state is always synced with the actual cursor positions.
  11613. onMouseUp: selectionHandler,
  11614. onKeyUp: selectionHandler
  11615. };
  11616. module.exports = DraftEditorEditHandler;
  11617. /***/ }),
  11618. /* 125 */
  11619. /***/ (function(module, exports, __webpack_require__) {
  11620. "use strict";
  11621. /**
  11622. * Copyright (c) Facebook, Inc. and its affiliates.
  11623. *
  11624. * This source code is licensed under the MIT license found in the
  11625. * LICENSE file in the root directory of this source tree.
  11626. *
  11627. * @format
  11628. *
  11629. * @emails oncall+draft_js
  11630. */
  11631. var DraftModifier = __webpack_require__(3);
  11632. var EditorState = __webpack_require__(2);
  11633. var UserAgent = __webpack_require__(5);
  11634. var getEntityKeyForSelection = __webpack_require__(35);
  11635. var isEventHandled = __webpack_require__(31);
  11636. var isSelectionAtLeafStart = __webpack_require__(126);
  11637. var nullthrows = __webpack_require__(4);
  11638. var setImmediate = __webpack_require__(127); // When nothing is focused, Firefox regards two characters, `'` and `/`, as
  11639. // commands that should open and focus the "quickfind" search bar. This should
  11640. // *never* happen while a contenteditable is focused, but as of v28, it
  11641. // sometimes does, even when the keypress event target is the contenteditable.
  11642. // This breaks the input. Special case these characters to ensure that when
  11643. // they are typed, we prevent default on the event to make sure not to
  11644. // trigger quickfind.
  11645. var FF_QUICKFIND_CHAR = "'";
  11646. var FF_QUICKFIND_LINK_CHAR = '/';
  11647. var isFirefox = UserAgent.isBrowser('Firefox');
  11648. function mustPreventDefaultForCharacter(character) {
  11649. return isFirefox && (character == FF_QUICKFIND_CHAR || character == FF_QUICKFIND_LINK_CHAR);
  11650. }
  11651. /**
  11652. * Replace the current selection with the specified text string, with the
  11653. * inline style and entity key applied to the newly inserted text.
  11654. */
  11655. function replaceText(editorState, text, inlineStyle, entityKey, forceSelection) {
  11656. var contentState = DraftModifier.replaceText(editorState.getCurrentContent(), editorState.getSelection(), text, inlineStyle, entityKey);
  11657. return EditorState.push(editorState, contentState, 'insert-characters', forceSelection);
  11658. }
  11659. /**
  11660. * When `onBeforeInput` executes, the browser is attempting to insert a
  11661. * character into the editor. Apply this character data to the document,
  11662. * allowing native insertion if possible.
  11663. *
  11664. * Native insertion is encouraged in order to limit re-rendering and to
  11665. * preserve spellcheck highlighting, which disappears or flashes if re-render
  11666. * occurs on the relevant text nodes.
  11667. */
  11668. function editOnBeforeInput(editor, e) {
  11669. if (editor._pendingStateFromBeforeInput !== undefined) {
  11670. editor.update(editor._pendingStateFromBeforeInput);
  11671. editor._pendingStateFromBeforeInput = undefined;
  11672. }
  11673. var editorState = editor._latestEditorState;
  11674. var chars = e.data; // In some cases (ex: IE ideographic space insertion) no character data
  11675. // is provided. There's nothing to do when this happens.
  11676. if (!chars) {
  11677. return;
  11678. } // Allow the top-level component to handle the insertion manually. This is
  11679. // useful when triggering interesting behaviors for a character insertion,
  11680. // Simple examples: replacing a raw text ':)' with a smile emoji or image
  11681. // decorator, or setting a block to be a list item after typing '- ' at the
  11682. // start of the block.
  11683. if (editor.props.handleBeforeInput && isEventHandled(editor.props.handleBeforeInput(chars, editorState, e.timeStamp))) {
  11684. e.preventDefault();
  11685. return;
  11686. } // If selection is collapsed, conditionally allow native behavior. This
  11687. // reduces re-renders and preserves spellcheck highlighting. If the selection
  11688. // is not collapsed, we will re-render.
  11689. var selection = editorState.getSelection();
  11690. var selectionStart = selection.getStartOffset();
  11691. var anchorKey = selection.getAnchorKey();
  11692. if (!selection.isCollapsed()) {
  11693. e.preventDefault();
  11694. editor.update(replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection(editorState.getCurrentContent(), editorState.getSelection()), true));
  11695. return;
  11696. }
  11697. var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection(editorState.getCurrentContent(), editorState.getSelection()), false); // Bunch of different cases follow where we need to prevent native insertion.
  11698. var mustPreventNative = false;
  11699. if (!mustPreventNative) {
  11700. // Browsers tend to insert text in weird places in the DOM when typing at
  11701. // the start of a leaf, so we'll handle it ourselves.
  11702. mustPreventNative = isSelectionAtLeafStart(editor._latestCommittedEditorState);
  11703. }
  11704. if (!mustPreventNative) {
  11705. // Let's say we have a decorator that highlights hashtags. In many cases
  11706. // we need to prevent native behavior and rerender ourselves --
  11707. // particularly, any case *except* where the inserted characters end up
  11708. // anywhere except exactly where you put them.
  11709. //
  11710. // Using [] to denote a decorated leaf, some examples:
  11711. //
  11712. // 1. 'hi #' and append 'f'
  11713. // desired rendering: 'hi [#f]'
  11714. // native rendering would be: 'hi #f' (incorrect)
  11715. //
  11716. // 2. 'x [#foo]' and insert '#' before 'f'
  11717. // desired rendering: 'x #[#foo]'
  11718. // native rendering would be: 'x [##foo]' (incorrect)
  11719. //
  11720. // 3. '[#foobar]' and insert ' ' between 'foo' and 'bar'
  11721. // desired rendering: '[#foo] bar'
  11722. // native rendering would be: '[#foo bar]' (incorrect)
  11723. //
  11724. // 4. '[#foo]' and delete '#' [won't use this beforeinput codepath though]
  11725. // desired rendering: 'foo'
  11726. // native rendering would be: '[foo]' (incorrect)
  11727. //
  11728. // 5. '[#foo]' and append 'b'
  11729. // desired rendering: '[#foob]'
  11730. // native rendering would be: '[#foob]'
  11731. // (native insertion here would be ok for decorators like simple spans,
  11732. // but not more complex decorators. To be safe, we need to prevent it.)
  11733. //
  11734. // It is safe to allow native insertion if and only if the full list of
  11735. // decorator ranges matches what we expect native insertion to give, and
  11736. // the range lengths have not changed. We don't need to compare the content
  11737. // because the only possible mutation to consider here is inserting plain
  11738. // text and decorators can't affect text content.
  11739. var oldBlockTree = editorState.getBlockTree(anchorKey);
  11740. var newBlockTree = newEditorState.getBlockTree(anchorKey);
  11741. mustPreventNative = oldBlockTree.size !== newBlockTree.size || oldBlockTree.zip(newBlockTree).some(function (_ref) {
  11742. var oldLeafSet = _ref[0],
  11743. newLeafSet = _ref[1];
  11744. // selectionStart is guaranteed to be selectionEnd here
  11745. var oldStart = oldLeafSet.get('start');
  11746. var adjustedStart = oldStart + (oldStart >= selectionStart ? chars.length : 0);
  11747. var oldEnd = oldLeafSet.get('end');
  11748. var adjustedEnd = oldEnd + (oldEnd >= selectionStart ? chars.length : 0);
  11749. var newStart = newLeafSet.get('start');
  11750. var newEnd = newLeafSet.get('end');
  11751. var newDecoratorKey = newLeafSet.get('decoratorKey');
  11752. return (// Different decorators
  11753. oldLeafSet.get('decoratorKey') !== newDecoratorKey || // Different number of inline styles
  11754. oldLeafSet.get('leaves').size !== newLeafSet.get('leaves').size || // Different effective decorator position
  11755. adjustedStart !== newStart || adjustedEnd !== newEnd || // Decorator already existed and its length changed
  11756. newDecoratorKey != null && newEnd - newStart !== oldEnd - oldStart
  11757. );
  11758. });
  11759. }
  11760. if (!mustPreventNative) {
  11761. mustPreventNative = mustPreventDefaultForCharacter(chars);
  11762. }
  11763. if (!mustPreventNative) {
  11764. mustPreventNative = nullthrows(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows(editorState.getDirectionMap()).get(anchorKey);
  11765. }
  11766. if (mustPreventNative) {
  11767. e.preventDefault();
  11768. newEditorState = EditorState.set(newEditorState, {
  11769. forceSelection: true
  11770. });
  11771. editor.update(newEditorState);
  11772. return;
  11773. } // We made it all the way! Let the browser do its thing and insert the char.
  11774. newEditorState = EditorState.set(newEditorState, {
  11775. nativelyRenderedContent: newEditorState.getCurrentContent()
  11776. }); // The native event is allowed to occur. To allow user onChange handlers to
  11777. // change the inserted text, we wait until the text is actually inserted
  11778. // before we actually update our state. That way when we rerender, the text
  11779. // we see in the DOM will already have been inserted properly.
  11780. editor._pendingStateFromBeforeInput = newEditorState;
  11781. setImmediate(function () {
  11782. if (editor._pendingStateFromBeforeInput !== undefined) {
  11783. editor.update(editor._pendingStateFromBeforeInput);
  11784. editor._pendingStateFromBeforeInput = undefined;
  11785. }
  11786. });
  11787. }
  11788. module.exports = editOnBeforeInput;
  11789. /***/ }),
  11790. /* 126 */
  11791. /***/ (function(module, exports, __webpack_require__) {
  11792. "use strict";
  11793. /**
  11794. * Copyright (c) Facebook, Inc. and its affiliates.
  11795. *
  11796. * This source code is licensed under the MIT license found in the
  11797. * LICENSE file in the root directory of this source tree.
  11798. *
  11799. * @format
  11800. *
  11801. * @emails oncall+draft_js
  11802. */
  11803. function isSelectionAtLeafStart(editorState) {
  11804. var selection = editorState.getSelection();
  11805. var anchorKey = selection.getAnchorKey();
  11806. var blockTree = editorState.getBlockTree(anchorKey);
  11807. var offset = selection.getStartOffset();
  11808. var isAtStart = false;
  11809. blockTree.some(function (leafSet) {
  11810. if (offset === leafSet.get('start')) {
  11811. isAtStart = true;
  11812. return true;
  11813. }
  11814. if (offset < leafSet.get('end')) {
  11815. return leafSet.get('leaves').some(function (leaf) {
  11816. var leafStart = leaf.get('start');
  11817. if (offset === leafStart) {
  11818. isAtStart = true;
  11819. return true;
  11820. }
  11821. return false;
  11822. });
  11823. }
  11824. return false;
  11825. });
  11826. return isAtStart;
  11827. }
  11828. module.exports = isSelectionAtLeafStart;
  11829. /***/ }),
  11830. /* 127 */
  11831. /***/ (function(module, exports, __webpack_require__) {
  11832. "use strict";
  11833. /* WEBPACK VAR INJECTION */(function(global) {/**
  11834. * Copyright (c) 2013-present, Facebook, Inc.
  11835. *
  11836. * This source code is licensed under the MIT license found in the
  11837. * LICENSE file in the root directory of this source tree.
  11838. *
  11839. */
  11840. // setimmediate adds setImmediate to the global. We want to make sure we export
  11841. // the actual function.
  11842. __webpack_require__(128);
  11843. module.exports = global.setImmediate;
  11844. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(25)))
  11845. /***/ }),
  11846. /* 128 */
  11847. /***/ (function(module, exports, __webpack_require__) {
  11848. /* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
  11849. "use strict";
  11850. if (global.setImmediate) {
  11851. return;
  11852. }
  11853. var nextHandle = 1; // Spec says greater than zero
  11854. var tasksByHandle = {};
  11855. var currentlyRunningATask = false;
  11856. var doc = global.document;
  11857. var registerImmediate;
  11858. function setImmediate(callback) {
  11859. // Callback can either be a function or a string
  11860. if (typeof callback !== "function") {
  11861. callback = new Function("" + callback);
  11862. }
  11863. // Copy function arguments
  11864. var args = new Array(arguments.length - 1);
  11865. for (var i = 0; i < args.length; i++) {
  11866. args[i] = arguments[i + 1];
  11867. }
  11868. // Store and register the task
  11869. var task = { callback: callback, args: args };
  11870. tasksByHandle[nextHandle] = task;
  11871. registerImmediate(nextHandle);
  11872. return nextHandle++;
  11873. }
  11874. function clearImmediate(handle) {
  11875. delete tasksByHandle[handle];
  11876. }
  11877. function run(task) {
  11878. var callback = task.callback;
  11879. var args = task.args;
  11880. switch (args.length) {
  11881. case 0:
  11882. callback();
  11883. break;
  11884. case 1:
  11885. callback(args[0]);
  11886. break;
  11887. case 2:
  11888. callback(args[0], args[1]);
  11889. break;
  11890. case 3:
  11891. callback(args[0], args[1], args[2]);
  11892. break;
  11893. default:
  11894. callback.apply(undefined, args);
  11895. break;
  11896. }
  11897. }
  11898. function runIfPresent(handle) {
  11899. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  11900. // So if we're currently running a task, we'll need to delay this invocation.
  11901. if (currentlyRunningATask) {
  11902. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  11903. // "too much recursion" error.
  11904. setTimeout(runIfPresent, 0, handle);
  11905. } else {
  11906. var task = tasksByHandle[handle];
  11907. if (task) {
  11908. currentlyRunningATask = true;
  11909. try {
  11910. run(task);
  11911. } finally {
  11912. clearImmediate(handle);
  11913. currentlyRunningATask = false;
  11914. }
  11915. }
  11916. }
  11917. }
  11918. function installNextTickImplementation() {
  11919. registerImmediate = function(handle) {
  11920. process.nextTick(function () { runIfPresent(handle); });
  11921. };
  11922. }
  11923. function canUsePostMessage() {
  11924. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  11925. // where `global.postMessage` means something completely different and can't be used for this purpose.
  11926. if (global.postMessage && !global.importScripts) {
  11927. var postMessageIsAsynchronous = true;
  11928. var oldOnMessage = global.onmessage;
  11929. global.onmessage = function() {
  11930. postMessageIsAsynchronous = false;
  11931. };
  11932. global.postMessage("", "*");
  11933. global.onmessage = oldOnMessage;
  11934. return postMessageIsAsynchronous;
  11935. }
  11936. }
  11937. function installPostMessageImplementation() {
  11938. // Installs an event handler on `global` for the `message` event: see
  11939. // * https://developer.mozilla.org/en/DOM/window.postMessage
  11940. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  11941. var messagePrefix = "setImmediate$" + Math.random() + "$";
  11942. var onGlobalMessage = function(event) {
  11943. if (event.source === global &&
  11944. typeof event.data === "string" &&
  11945. event.data.indexOf(messagePrefix) === 0) {
  11946. runIfPresent(+event.data.slice(messagePrefix.length));
  11947. }
  11948. };
  11949. if (global.addEventListener) {
  11950. global.addEventListener("message", onGlobalMessage, false);
  11951. } else {
  11952. global.attachEvent("onmessage", onGlobalMessage);
  11953. }
  11954. registerImmediate = function(handle) {
  11955. global.postMessage(messagePrefix + handle, "*");
  11956. };
  11957. }
  11958. function installMessageChannelImplementation() {
  11959. var channel = new MessageChannel();
  11960. channel.port1.onmessage = function(event) {
  11961. var handle = event.data;
  11962. runIfPresent(handle);
  11963. };
  11964. registerImmediate = function(handle) {
  11965. channel.port2.postMessage(handle);
  11966. };
  11967. }
  11968. function installReadyStateChangeImplementation() {
  11969. var html = doc.documentElement;
  11970. registerImmediate = function(handle) {
  11971. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  11972. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  11973. var script = doc.createElement("script");
  11974. script.onreadystatechange = function () {
  11975. runIfPresent(handle);
  11976. script.onreadystatechange = null;
  11977. html.removeChild(script);
  11978. script = null;
  11979. };
  11980. html.appendChild(script);
  11981. };
  11982. }
  11983. function installSetTimeoutImplementation() {
  11984. registerImmediate = function(handle) {
  11985. setTimeout(runIfPresent, 0, handle);
  11986. };
  11987. }
  11988. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  11989. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  11990. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  11991. // Don't get fooled by e.g. browserify environments.
  11992. if ({}.toString.call(global.process) === "[object process]") {
  11993. // For Node.js before 0.9
  11994. installNextTickImplementation();
  11995. } else if (canUsePostMessage()) {
  11996. // For non-IE10 modern browsers
  11997. installPostMessageImplementation();
  11998. } else if (global.MessageChannel) {
  11999. // For web workers, where supported
  12000. installMessageChannelImplementation();
  12001. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  12002. // For IE 6–8
  12003. installReadyStateChangeImplementation();
  12004. } else {
  12005. // For older browsers
  12006. installSetTimeoutImplementation();
  12007. }
  12008. attachTo.setImmediate = setImmediate;
  12009. attachTo.clearImmediate = clearImmediate;
  12010. }(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
  12011. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(25), __webpack_require__(129)))
  12012. /***/ }),
  12013. /* 129 */
  12014. /***/ (function(module, exports) {
  12015. // shim for using process in browser
  12016. var process = module.exports = {};
  12017. // cached from whatever global is present so that test runners that stub it
  12018. // don't break things. But we need to wrap it in a try catch in case it is
  12019. // wrapped in strict mode code which doesn't define any globals. It's inside a
  12020. // function because try/catches deoptimize in certain engines.
  12021. var cachedSetTimeout;
  12022. var cachedClearTimeout;
  12023. function defaultSetTimout() {
  12024. throw new Error('setTimeout has not been defined');
  12025. }
  12026. function defaultClearTimeout () {
  12027. throw new Error('clearTimeout has not been defined');
  12028. }
  12029. (function () {
  12030. try {
  12031. if (typeof setTimeout === 'function') {
  12032. cachedSetTimeout = setTimeout;
  12033. } else {
  12034. cachedSetTimeout = defaultSetTimout;
  12035. }
  12036. } catch (e) {
  12037. cachedSetTimeout = defaultSetTimout;
  12038. }
  12039. try {
  12040. if (typeof clearTimeout === 'function') {
  12041. cachedClearTimeout = clearTimeout;
  12042. } else {
  12043. cachedClearTimeout = defaultClearTimeout;
  12044. }
  12045. } catch (e) {
  12046. cachedClearTimeout = defaultClearTimeout;
  12047. }
  12048. } ())
  12049. function runTimeout(fun) {
  12050. if (cachedSetTimeout === setTimeout) {
  12051. //normal enviroments in sane situations
  12052. return setTimeout(fun, 0);
  12053. }
  12054. // if setTimeout wasn't available but was latter defined
  12055. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  12056. cachedSetTimeout = setTimeout;
  12057. return setTimeout(fun, 0);
  12058. }
  12059. try {
  12060. // when when somebody has screwed with setTimeout but no I.E. maddness
  12061. return cachedSetTimeout(fun, 0);
  12062. } catch(e){
  12063. try {
  12064. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  12065. return cachedSetTimeout.call(null, fun, 0);
  12066. } catch(e){
  12067. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  12068. return cachedSetTimeout.call(this, fun, 0);
  12069. }
  12070. }
  12071. }
  12072. function runClearTimeout(marker) {
  12073. if (cachedClearTimeout === clearTimeout) {
  12074. //normal enviroments in sane situations
  12075. return clearTimeout(marker);
  12076. }
  12077. // if clearTimeout wasn't available but was latter defined
  12078. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  12079. cachedClearTimeout = clearTimeout;
  12080. return clearTimeout(marker);
  12081. }
  12082. try {
  12083. // when when somebody has screwed with setTimeout but no I.E. maddness
  12084. return cachedClearTimeout(marker);
  12085. } catch (e){
  12086. try {
  12087. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  12088. return cachedClearTimeout.call(null, marker);
  12089. } catch (e){
  12090. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  12091. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  12092. return cachedClearTimeout.call(this, marker);
  12093. }
  12094. }
  12095. }
  12096. var queue = [];
  12097. var draining = false;
  12098. var currentQueue;
  12099. var queueIndex = -1;
  12100. function cleanUpNextTick() {
  12101. if (!draining || !currentQueue) {
  12102. return;
  12103. }
  12104. draining = false;
  12105. if (currentQueue.length) {
  12106. queue = currentQueue.concat(queue);
  12107. } else {
  12108. queueIndex = -1;
  12109. }
  12110. if (queue.length) {
  12111. drainQueue();
  12112. }
  12113. }
  12114. function drainQueue() {
  12115. if (draining) {
  12116. return;
  12117. }
  12118. var timeout = runTimeout(cleanUpNextTick);
  12119. draining = true;
  12120. var len = queue.length;
  12121. while(len) {
  12122. currentQueue = queue;
  12123. queue = [];
  12124. while (++queueIndex < len) {
  12125. if (currentQueue) {
  12126. currentQueue[queueIndex].run();
  12127. }
  12128. }
  12129. queueIndex = -1;
  12130. len = queue.length;
  12131. }
  12132. currentQueue = null;
  12133. draining = false;
  12134. runClearTimeout(timeout);
  12135. }
  12136. process.nextTick = function (fun) {
  12137. var args = new Array(arguments.length - 1);
  12138. if (arguments.length > 1) {
  12139. for (var i = 1; i < arguments.length; i++) {
  12140. args[i - 1] = arguments[i];
  12141. }
  12142. }
  12143. queue.push(new Item(fun, args));
  12144. if (queue.length === 1 && !draining) {
  12145. runTimeout(drainQueue);
  12146. }
  12147. };
  12148. // v8 likes predictible objects
  12149. function Item(fun, array) {
  12150. this.fun = fun;
  12151. this.array = array;
  12152. }
  12153. Item.prototype.run = function () {
  12154. this.fun.apply(null, this.array);
  12155. };
  12156. process.title = 'browser';
  12157. process.browser = true;
  12158. process.env = {};
  12159. process.argv = [];
  12160. process.version = ''; // empty string to avoid regexp issues
  12161. process.versions = {};
  12162. function noop() {}
  12163. process.on = noop;
  12164. process.addListener = noop;
  12165. process.once = noop;
  12166. process.off = noop;
  12167. process.removeListener = noop;
  12168. process.removeAllListeners = noop;
  12169. process.emit = noop;
  12170. process.prependListener = noop;
  12171. process.prependOnceListener = noop;
  12172. process.listeners = function (name) { return [] }
  12173. process.binding = function (name) {
  12174. throw new Error('process.binding is not supported');
  12175. };
  12176. process.cwd = function () { return '/' };
  12177. process.chdir = function (dir) {
  12178. throw new Error('process.chdir is not supported');
  12179. };
  12180. process.umask = function() { return 0; };
  12181. /***/ }),
  12182. /* 130 */
  12183. /***/ (function(module, exports, __webpack_require__) {
  12184. "use strict";
  12185. /**
  12186. * Copyright (c) Facebook, Inc. and its affiliates.
  12187. *
  12188. * This source code is licensed under the MIT license found in the
  12189. * LICENSE file in the root directory of this source tree.
  12190. *
  12191. * @format
  12192. *
  12193. * @emails oncall+draft_js
  12194. */
  12195. var EditorState = __webpack_require__(2);
  12196. var containsNode = __webpack_require__(36);
  12197. var getActiveElement = __webpack_require__(61);
  12198. function editOnBlur(editor, e) {
  12199. // In a contentEditable element, when you select a range and then click
  12200. // another active element, this does trigger a `blur` event but will not
  12201. // remove the DOM selection from the contenteditable.
  12202. // This is consistent across all browsers, but we prefer that the editor
  12203. // behave like a textarea, where a `blur` event clears the DOM selection.
  12204. // We therefore force the issue to be certain, checking whether the active
  12205. // element is `body` to force it when blurring occurs within the window (as
  12206. // opposed to clicking to another tab or window).
  12207. var ownerDocument = e.currentTarget.ownerDocument;
  12208. if ( // This ESLint rule conflicts with `sketchy-null-bool` flow check
  12209. // eslint-disable-next-line no-extra-boolean-cast
  12210. !Boolean(editor.props.preserveSelectionOnBlur) && getActiveElement(ownerDocument) === ownerDocument.body) {
  12211. var _selection = ownerDocument.defaultView.getSelection();
  12212. var editorNode = editor.editor;
  12213. if (_selection.rangeCount === 1 && containsNode(editorNode, _selection.anchorNode) && containsNode(editorNode, _selection.focusNode)) {
  12214. _selection.removeAllRanges();
  12215. }
  12216. }
  12217. var editorState = editor._latestEditorState;
  12218. var currentSelection = editorState.getSelection();
  12219. if (!currentSelection.getHasFocus()) {
  12220. return;
  12221. }
  12222. var selection = currentSelection.set('hasFocus', false);
  12223. editor.props.onBlur && editor.props.onBlur(e);
  12224. editor.update(EditorState.acceptSelection(editorState, selection));
  12225. }
  12226. module.exports = editOnBlur;
  12227. /***/ }),
  12228. /* 131 */
  12229. /***/ (function(module, exports, __webpack_require__) {
  12230. "use strict";
  12231. /**
  12232. * Copyright (c) Facebook, Inc. and its affiliates.
  12233. *
  12234. * This source code is licensed under the MIT license found in the
  12235. * LICENSE file in the root directory of this source tree.
  12236. *
  12237. * @format
  12238. *
  12239. * @emails oncall+draft_js
  12240. */
  12241. var EditorState = __webpack_require__(2);
  12242. /**
  12243. * The user has begun using an IME input system. Switching to `composite` mode
  12244. * allows handling composition input and disables other edit behavior.
  12245. */
  12246. function editOnCompositionStart(editor, e) {
  12247. editor.setMode('composite');
  12248. editor.update(EditorState.set(editor._latestEditorState, {
  12249. inCompositionMode: true
  12250. })); // Allow composition handler to interpret the compositionstart event
  12251. editor._onCompositionStart(e);
  12252. }
  12253. module.exports = editOnCompositionStart;
  12254. /***/ }),
  12255. /* 132 */
  12256. /***/ (function(module, exports, __webpack_require__) {
  12257. "use strict";
  12258. /**
  12259. * Copyright (c) Facebook, Inc. and its affiliates.
  12260. *
  12261. * This source code is licensed under the MIT license found in the
  12262. * LICENSE file in the root directory of this source tree.
  12263. *
  12264. * @format
  12265. *
  12266. * @emails oncall+draft_js
  12267. */
  12268. var getFragmentFromSelection = __webpack_require__(68);
  12269. /**
  12270. * If we have a selection, create a ContentState fragment and store
  12271. * it in our internal clipboard. Subsequent paste events will use this
  12272. * fragment if no external clipboard data is supplied.
  12273. */
  12274. function editOnCopy(editor, e) {
  12275. var editorState = editor._latestEditorState;
  12276. var selection = editorState.getSelection(); // No selection, so there's nothing to copy.
  12277. if (selection.isCollapsed()) {
  12278. e.preventDefault();
  12279. return;
  12280. }
  12281. editor.setClipboard(getFragmentFromSelection(editor._latestEditorState));
  12282. }
  12283. module.exports = editOnCopy;
  12284. /***/ }),
  12285. /* 133 */
  12286. /***/ (function(module, exports, __webpack_require__) {
  12287. "use strict";
  12288. /**
  12289. * Copyright (c) Facebook, Inc. and its affiliates.
  12290. *
  12291. * This source code is licensed under the MIT license found in the
  12292. * LICENSE file in the root directory of this source tree.
  12293. *
  12294. * @format
  12295. *
  12296. * @emails oncall+draft_js
  12297. */
  12298. var DraftModifier = __webpack_require__(3);
  12299. var EditorState = __webpack_require__(2);
  12300. var Style = __webpack_require__(29);
  12301. var getFragmentFromSelection = __webpack_require__(68);
  12302. var getScrollPosition = __webpack_require__(30);
  12303. var isNode = __webpack_require__(134);
  12304. /**
  12305. * On `cut` events, native behavior is allowed to occur so that the system
  12306. * clipboard is set properly. This means that we need to take steps to recover
  12307. * the editor DOM state after the `cut` has occurred in order to maintain
  12308. * control of the component.
  12309. *
  12310. * In addition, we can keep a copy of the removed fragment, including all
  12311. * styles and entities, for use as an internal paste.
  12312. */
  12313. function editOnCut(editor, e) {
  12314. var editorState = editor._latestEditorState;
  12315. var selection = editorState.getSelection();
  12316. var element = e.target;
  12317. var scrollPosition; // No selection, so there's nothing to cut.
  12318. if (selection.isCollapsed()) {
  12319. e.preventDefault();
  12320. return;
  12321. } // Track the current scroll position so that it can be forced back in place
  12322. // after the editor regains control of the DOM.
  12323. if (isNode(element)) {
  12324. var node = element;
  12325. scrollPosition = getScrollPosition(Style.getScrollParent(node));
  12326. }
  12327. var fragment = getFragmentFromSelection(editorState);
  12328. editor.setClipboard(fragment); // Set `cut` mode to disable all event handling temporarily.
  12329. editor.setMode('cut'); // Let native `cut` behavior occur, then recover control.
  12330. setTimeout(function () {
  12331. editor.restoreEditorDOM(scrollPosition);
  12332. editor.exitCurrentMode();
  12333. editor.update(removeFragment(editorState));
  12334. }, 0);
  12335. }
  12336. function removeFragment(editorState) {
  12337. var newContent = DraftModifier.removeRange(editorState.getCurrentContent(), editorState.getSelection(), 'forward');
  12338. return EditorState.push(editorState, newContent, 'remove-range');
  12339. }
  12340. module.exports = editOnCut;
  12341. /***/ }),
  12342. /* 134 */
  12343. /***/ (function(module, exports, __webpack_require__) {
  12344. "use strict";
  12345. /**
  12346. * Copyright (c) Facebook, Inc. and its affiliates.
  12347. *
  12348. * This source code is licensed under the MIT license found in the
  12349. * LICENSE file in the root directory of this source tree.
  12350. *
  12351. * @format
  12352. *
  12353. * @emails oncall+draft_js
  12354. */
  12355. function isInstanceOfNode(target) {
  12356. // we changed the name because of having duplicate module provider (fbjs)
  12357. if (!target || !('ownerDocument' in target)) {
  12358. return false;
  12359. }
  12360. if ('ownerDocument' in target) {
  12361. var node = target;
  12362. if (!node.ownerDocument.defaultView) {
  12363. return node instanceof Node;
  12364. }
  12365. if (node instanceof node.ownerDocument.defaultView.Node) {
  12366. return true;
  12367. }
  12368. }
  12369. return false;
  12370. }
  12371. module.exports = isInstanceOfNode;
  12372. /***/ }),
  12373. /* 135 */
  12374. /***/ (function(module, exports, __webpack_require__) {
  12375. "use strict";
  12376. /**
  12377. * Copyright (c) Facebook, Inc. and its affiliates.
  12378. *
  12379. * This source code is licensed under the MIT license found in the
  12380. * LICENSE file in the root directory of this source tree.
  12381. *
  12382. * @format
  12383. *
  12384. * @emails oncall+draft_js
  12385. */
  12386. /**
  12387. * Drag behavior has begun from outside the editor element.
  12388. */
  12389. function editOnDragOver(editor, e) {
  12390. editor.setMode('drag');
  12391. e.preventDefault();
  12392. }
  12393. module.exports = editOnDragOver;
  12394. /***/ }),
  12395. /* 136 */
  12396. /***/ (function(module, exports, __webpack_require__) {
  12397. "use strict";
  12398. /**
  12399. * Copyright (c) Facebook, Inc. and its affiliates.
  12400. *
  12401. * This source code is licensed under the MIT license found in the
  12402. * LICENSE file in the root directory of this source tree.
  12403. *
  12404. * @format
  12405. *
  12406. * @emails oncall+draft_js
  12407. */
  12408. /**
  12409. * A `dragstart` event has begun within the text editor component.
  12410. */
  12411. function editOnDragStart(editor) {
  12412. editor._internalDrag = true;
  12413. editor.setMode('drag');
  12414. }
  12415. module.exports = editOnDragStart;
  12416. /***/ }),
  12417. /* 137 */
  12418. /***/ (function(module, exports, __webpack_require__) {
  12419. "use strict";
  12420. /**
  12421. * Copyright (c) Facebook, Inc. and its affiliates.
  12422. *
  12423. * This source code is licensed under the MIT license found in the
  12424. * LICENSE file in the root directory of this source tree.
  12425. *
  12426. * @format
  12427. *
  12428. * @emails oncall+draft_js
  12429. */
  12430. var EditorState = __webpack_require__(2);
  12431. var UserAgent = __webpack_require__(5);
  12432. function editOnFocus(editor, e) {
  12433. var editorState = editor._latestEditorState;
  12434. var currentSelection = editorState.getSelection();
  12435. if (currentSelection.getHasFocus()) {
  12436. return;
  12437. }
  12438. var selection = currentSelection.set('hasFocus', true);
  12439. editor.props.onFocus && editor.props.onFocus(e); // When the tab containing this text editor is hidden and the user does a
  12440. // find-in-page in a _different_ tab, Chrome on Mac likes to forget what the
  12441. // selection was right after sending this focus event and (if you let it)
  12442. // moves the cursor back to the beginning of the editor, so we force the
  12443. // selection here instead of simply accepting it in order to preserve the
  12444. // old cursor position. See https://crbug.com/540004.
  12445. // But it looks like this is fixed in Chrome 60.0.3081.0.
  12446. // Other browsers also don't have this bug, so we prefer to acceptSelection
  12447. // when possible, to ensure that unfocusing and refocusing a Draft editor
  12448. // doesn't preserve the selection, matching how textareas work.
  12449. if (UserAgent.isBrowser('Chrome < 60.0.3081.0')) {
  12450. editor.update(EditorState.forceSelection(editorState, selection));
  12451. } else {
  12452. editor.update(EditorState.acceptSelection(editorState, selection));
  12453. }
  12454. }
  12455. module.exports = editOnFocus;
  12456. /***/ }),
  12457. /* 138 */
  12458. /***/ (function(module, exports, __webpack_require__) {
  12459. "use strict";
  12460. /**
  12461. * Copyright (c) Facebook, Inc. and its affiliates.
  12462. *
  12463. * This source code is licensed under the MIT license found in the
  12464. * LICENSE file in the root directory of this source tree.
  12465. *
  12466. * @format
  12467. *
  12468. * @emails oncall+draft_js
  12469. */
  12470. var DraftModifier = __webpack_require__(3);
  12471. var DraftOffsetKey = __webpack_require__(10);
  12472. var EditorState = __webpack_require__(2);
  12473. var UserAgent = __webpack_require__(5);
  12474. var _require = __webpack_require__(57),
  12475. notEmptyKey = _require.notEmptyKey;
  12476. var findAncestorOffsetKey = __webpack_require__(26);
  12477. var keyCommandPlainBackspace = __webpack_require__(69);
  12478. var nullthrows = __webpack_require__(4);
  12479. var isGecko = UserAgent.isEngine('Gecko');
  12480. var DOUBLE_NEWLINE = '\n\n';
  12481. function onInputType(inputType, editorState) {
  12482. switch (inputType) {
  12483. case 'deleteContentBackward':
  12484. return keyCommandPlainBackspace(editorState);
  12485. }
  12486. return editorState;
  12487. }
  12488. /**
  12489. * This function serves two purposes
  12490. *
  12491. * 1. To update the editorState and call onChange method with the new
  12492. * editorState. This editorState is calculated in editOnBeforeInput but the
  12493. * onChange method is not called with the new state until this method does it.
  12494. * It is done to handle a specific case where certain character inputs might
  12495. * be replaced with something else. E.g. snippets ('rc' might be replaced
  12496. * with boilerplate code for react component). More information on the
  12497. * exact problem can be found here -
  12498. * https://github.com/facebook/draft-js/commit/07892ba479bd4dfc6afd1e0ed179aaf51cd138b1
  12499. *
  12500. * 2. intended to handle spellcheck and autocorrect changes,
  12501. * which occur in the DOM natively without any opportunity to observe or
  12502. * interpret the changes before they occur.
  12503. *
  12504. * The `input` event fires in contentEditable elements reliably for non-IE
  12505. * browsers, immediately after changes occur to the editor DOM. Since our other
  12506. * handlers override or otherwise handle cover other varieties of text input,
  12507. * the DOM state should match the model in all controlled input cases. Thus,
  12508. * when an `input` change leads to a DOM/model mismatch, the change should be
  12509. * due to a spellcheck change, and we can incorporate it into our model.
  12510. */
  12511. function editOnInput(editor, e) {
  12512. if (editor._pendingStateFromBeforeInput !== undefined) {
  12513. editor.update(editor._pendingStateFromBeforeInput);
  12514. editor._pendingStateFromBeforeInput = undefined;
  12515. } // at this point editor is not null for sure (after input)
  12516. var castedEditorElement = editor.editor;
  12517. var domSelection = castedEditorElement.ownerDocument.defaultView.getSelection();
  12518. var anchorNode = domSelection.anchorNode,
  12519. isCollapsed = domSelection.isCollapsed;
  12520. var isNotTextOrElementNode = (anchorNode === null || anchorNode === void 0 ? void 0 : anchorNode.nodeType) !== Node.TEXT_NODE && (anchorNode === null || anchorNode === void 0 ? void 0 : anchorNode.nodeType) !== Node.ELEMENT_NODE;
  12521. if (isNotTextOrElementNode) {
  12522. // TODO: (t16149272) figure out context for this change
  12523. return;
  12524. }
  12525. if (anchorNode.nodeType === Node.TEXT_NODE && (anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)) {
  12526. // When typing at the beginning of a visual line, Chrome splits the text
  12527. // nodes into two. Why? No one knows. This commit is suspicious:
  12528. // https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
  12529. // To work around, we'll merge the sibling text nodes back into this one.
  12530. var span = anchorNode.parentNode;
  12531. anchorNode.nodeValue = span.textContent;
  12532. for (var child = span.firstChild; child !== null; child = child.nextSibling) {
  12533. if (child !== anchorNode) {
  12534. span.removeChild(child);
  12535. }
  12536. }
  12537. }
  12538. var domText = anchorNode.textContent;
  12539. var editorState = editor._latestEditorState;
  12540. var offsetKey = nullthrows(findAncestorOffsetKey(anchorNode));
  12541. var _DraftOffsetKey$decod = DraftOffsetKey.decode(offsetKey),
  12542. blockKey = _DraftOffsetKey$decod.blockKey,
  12543. decoratorKey = _DraftOffsetKey$decod.decoratorKey,
  12544. leafKey = _DraftOffsetKey$decod.leafKey;
  12545. var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]),
  12546. start = _editorState$getBlock.start,
  12547. end = _editorState$getBlock.end;
  12548. var content = editorState.getCurrentContent();
  12549. var block = content.getBlockForKey(blockKey);
  12550. var modelText = block.getText().slice(start, end); // Special-case soft newlines here. If the DOM text ends in a soft newline,
  12551. // we will have manually inserted an extra soft newline in DraftEditorLeaf.
  12552. // We want to remove this extra newline for the purpose of our comparison
  12553. // of DOM and model text.
  12554. if (domText.endsWith(DOUBLE_NEWLINE)) {
  12555. domText = domText.slice(0, -1);
  12556. } // No change -- the DOM is up to date. Nothing to do here.
  12557. if (domText === modelText) {
  12558. // This can be buggy for some Android keyboards because they don't fire
  12559. // standard onkeydown/pressed events and only fired editOnInput
  12560. // so domText is already changed by the browser and ends up being equal
  12561. // to modelText unexpectedly.
  12562. // Newest versions of Android support the dom-inputevent-inputtype
  12563. // and we can use the `inputType` to properly apply the state changes.
  12564. /* $FlowFixMe inputType is only defined on a draft of a standard.
  12565. * https://w3c.github.io/input-events/#dom-inputevent-inputtype */
  12566. var inputType = e.nativeEvent.inputType;
  12567. if (inputType) {
  12568. var newEditorState = onInputType(inputType, editorState);
  12569. if (newEditorState !== editorState) {
  12570. editor.restoreEditorDOM();
  12571. editor.update(newEditorState);
  12572. return;
  12573. }
  12574. }
  12575. return;
  12576. }
  12577. var selection = editorState.getSelection(); // We'll replace the entire leaf with the text content of the target.
  12578. var targetRange = selection.merge({
  12579. anchorOffset: start,
  12580. focusOffset: end,
  12581. isBackward: false
  12582. });
  12583. var entityKey = block.getEntityAt(start);
  12584. var entity = notEmptyKey(entityKey) ? content.getEntity(entityKey) : null;
  12585. var entityType = entity != null ? entity.getMutability() : null;
  12586. var preserveEntity = entityType === 'MUTABLE'; // Immutable or segmented entities cannot properly be handled by the
  12587. // default browser undo, so we have to use a different change type to
  12588. // force using our internal undo method instead of falling through to the
  12589. // native browser undo.
  12590. var changeType = preserveEntity ? 'spellcheck-change' : 'apply-entity';
  12591. var newContent = DraftModifier.replaceText(content, targetRange, domText, block.getInlineStyleAt(start), preserveEntity ? block.getEntityAt(start) : null);
  12592. var anchorOffset, focusOffset, startOffset, endOffset;
  12593. if (isGecko) {
  12594. // Firefox selection does not change while the context menu is open, so
  12595. // we preserve the anchor and focus values of the DOM selection.
  12596. anchorOffset = domSelection.anchorOffset;
  12597. focusOffset = domSelection.focusOffset;
  12598. startOffset = start + Math.min(anchorOffset, focusOffset);
  12599. endOffset = startOffset + Math.abs(anchorOffset - focusOffset);
  12600. anchorOffset = startOffset;
  12601. focusOffset = endOffset;
  12602. } else {
  12603. // Browsers other than Firefox may adjust DOM selection while the context
  12604. // menu is open, and Safari autocorrect is prone to providing an inaccurate
  12605. // DOM selection. Don't trust it. Instead, use our existing SelectionState
  12606. // and adjust it based on the number of characters changed during the
  12607. // mutation.
  12608. var charDelta = domText.length - modelText.length;
  12609. startOffset = selection.getStartOffset();
  12610. endOffset = selection.getEndOffset();
  12611. anchorOffset = isCollapsed ? endOffset + charDelta : startOffset;
  12612. focusOffset = endOffset + charDelta;
  12613. } // Segmented entities are completely or partially removed when their
  12614. // text content changes. For this case we do not want any text to be selected
  12615. // after the change, so we are not merging the selection.
  12616. var contentWithAdjustedDOMSelection = newContent.merge({
  12617. selectionBefore: content.getSelectionAfter(),
  12618. selectionAfter: selection.merge({
  12619. anchorOffset: anchorOffset,
  12620. focusOffset: focusOffset
  12621. })
  12622. });
  12623. editor.update(EditorState.push(editorState, contentWithAdjustedDOMSelection, changeType));
  12624. }
  12625. module.exports = editOnInput;
  12626. /***/ }),
  12627. /* 139 */
  12628. /***/ (function(module, exports, __webpack_require__) {
  12629. "use strict";
  12630. /**
  12631. * Copyright (c) Facebook, Inc. and its affiliates.
  12632. *
  12633. * This source code is licensed under the MIT license found in the
  12634. * LICENSE file in the root directory of this source tree.
  12635. *
  12636. * @format
  12637. *
  12638. * @emails oncall+draft_js
  12639. */
  12640. var DraftModifier = __webpack_require__(3);
  12641. var EditorState = __webpack_require__(2);
  12642. var KeyBindingUtil = __webpack_require__(40);
  12643. var Keys = __webpack_require__(28);
  12644. var SecondaryClipboard = __webpack_require__(141);
  12645. var UserAgent = __webpack_require__(5);
  12646. var isEventHandled = __webpack_require__(31);
  12647. var keyCommandBackspaceToStartOfLine = __webpack_require__(142);
  12648. var keyCommandBackspaceWord = __webpack_require__(144);
  12649. var keyCommandDeleteWord = __webpack_require__(146);
  12650. var keyCommandInsertNewline = __webpack_require__(147);
  12651. var keyCommandMoveSelectionToEndOfBlock = __webpack_require__(148);
  12652. var keyCommandMoveSelectionToStartOfBlock = __webpack_require__(149);
  12653. var keyCommandPlainBackspace = __webpack_require__(69);
  12654. var keyCommandPlainDelete = __webpack_require__(150);
  12655. var keyCommandTransposeCharacters = __webpack_require__(151);
  12656. var keyCommandUndo = __webpack_require__(152);
  12657. var isOptionKeyCommand = KeyBindingUtil.isOptionKeyCommand;
  12658. var isChrome = UserAgent.isBrowser('Chrome');
  12659. /**
  12660. * Map a `DraftEditorCommand` command value to a corresponding function.
  12661. */
  12662. function onKeyCommand(command, editorState, e) {
  12663. switch (command) {
  12664. case 'redo':
  12665. return EditorState.redo(editorState);
  12666. case 'delete':
  12667. return keyCommandPlainDelete(editorState);
  12668. case 'delete-word':
  12669. return keyCommandDeleteWord(editorState);
  12670. case 'backspace':
  12671. return keyCommandPlainBackspace(editorState);
  12672. case 'backspace-word':
  12673. return keyCommandBackspaceWord(editorState);
  12674. case 'backspace-to-start-of-line':
  12675. return keyCommandBackspaceToStartOfLine(editorState, e);
  12676. case 'split-block':
  12677. return keyCommandInsertNewline(editorState);
  12678. case 'transpose-characters':
  12679. return keyCommandTransposeCharacters(editorState);
  12680. case 'move-selection-to-start-of-block':
  12681. return keyCommandMoveSelectionToStartOfBlock(editorState);
  12682. case 'move-selection-to-end-of-block':
  12683. return keyCommandMoveSelectionToEndOfBlock(editorState);
  12684. case 'secondary-cut':
  12685. return SecondaryClipboard.cut(editorState);
  12686. case 'secondary-paste':
  12687. return SecondaryClipboard.paste(editorState);
  12688. default:
  12689. return editorState;
  12690. }
  12691. }
  12692. /**
  12693. * Intercept keydown behavior to handle keys and commands manually, if desired.
  12694. *
  12695. * Keydown combinations may be mapped to `DraftCommand` values, which may
  12696. * correspond to command functions that modify the editor or its contents.
  12697. *
  12698. * See `getDefaultKeyBinding` for defaults. Alternatively, the top-level
  12699. * component may provide a custom mapping via the `keyBindingFn` prop.
  12700. */
  12701. function editOnKeyDown(editor, e) {
  12702. var keyCode = e.which;
  12703. var editorState = editor._latestEditorState;
  12704. function callDeprecatedHandler(handlerName) {
  12705. var deprecatedHandler = editor.props[handlerName];
  12706. if (deprecatedHandler) {
  12707. deprecatedHandler(e);
  12708. return true;
  12709. } else {
  12710. return false;
  12711. }
  12712. }
  12713. switch (keyCode) {
  12714. case Keys.RETURN:
  12715. e.preventDefault(); // The top-level component may manually handle newline insertion. If
  12716. // no special handling is performed, fall through to command handling.
  12717. if (editor.props.handleReturn && isEventHandled(editor.props.handleReturn(e, editorState))) {
  12718. return;
  12719. }
  12720. break;
  12721. case Keys.ESC:
  12722. e.preventDefault();
  12723. if (callDeprecatedHandler('onEscape')) {
  12724. return;
  12725. }
  12726. break;
  12727. case Keys.TAB:
  12728. if (callDeprecatedHandler('onTab')) {
  12729. return;
  12730. }
  12731. break;
  12732. case Keys.UP:
  12733. if (callDeprecatedHandler('onUpArrow')) {
  12734. return;
  12735. }
  12736. break;
  12737. case Keys.RIGHT:
  12738. if (callDeprecatedHandler('onRightArrow')) {
  12739. return;
  12740. }
  12741. break;
  12742. case Keys.DOWN:
  12743. if (callDeprecatedHandler('onDownArrow')) {
  12744. return;
  12745. }
  12746. break;
  12747. case Keys.LEFT:
  12748. if (callDeprecatedHandler('onLeftArrow')) {
  12749. return;
  12750. }
  12751. break;
  12752. case Keys.SPACE:
  12753. // Prevent Chrome on OSX behavior where option + space scrolls.
  12754. if (isChrome && isOptionKeyCommand(e)) {
  12755. e.preventDefault();
  12756. }
  12757. }
  12758. var command = editor.props.keyBindingFn(e); // If no command is specified, allow keydown event to continue.
  12759. if (command == null || command === '') {
  12760. if (keyCode === Keys.SPACE && isChrome && isOptionKeyCommand(e)) {
  12761. // The default keydown event has already been prevented in order to stop
  12762. // Chrome from scrolling. Insert a nbsp into the editor as OSX would for
  12763. // other browsers.
  12764. var contentState = DraftModifier.replaceText(editorState.getCurrentContent(), editorState.getSelection(), "\xA0");
  12765. editor.update(EditorState.push(editorState, contentState, 'insert-characters'));
  12766. }
  12767. return;
  12768. }
  12769. if (command === 'undo') {
  12770. // Since undo requires some special updating behavior to keep the editor
  12771. // in sync, handle it separately.
  12772. keyCommandUndo(e, editorState, editor.update);
  12773. return;
  12774. } // At this point, we know that we're handling a command of some kind, so
  12775. // we don't want to insert a character following the keydown.
  12776. e.preventDefault(); // Allow components higher up the tree to handle the command first.
  12777. if (editor.props.handleKeyCommand && isEventHandled(editor.props.handleKeyCommand(command, editorState, e.timeStamp))) {
  12778. return;
  12779. }
  12780. var newState = onKeyCommand(command, editorState, e);
  12781. if (newState !== editorState) {
  12782. editor.update(newState);
  12783. }
  12784. }
  12785. module.exports = editOnKeyDown;
  12786. /***/ }),
  12787. /* 140 */
  12788. /***/ (function(module, exports, __webpack_require__) {
  12789. "use strict";
  12790. /**
  12791. * Copyright (c) Facebook, Inc. and its affiliates.
  12792. *
  12793. * This source code is licensed under the MIT license found in the
  12794. * LICENSE file in the root directory of this source tree.
  12795. *
  12796. * @format
  12797. *
  12798. * @emails oncall+draft_js
  12799. */
  12800. var Keys = __webpack_require__(28);
  12801. function isSoftNewlineEvent(e) {
  12802. return e.which === Keys.RETURN && (e.getModifierState('Shift') || e.getModifierState('Alt') || e.getModifierState('Control'));
  12803. }
  12804. module.exports = isSoftNewlineEvent;
  12805. /***/ }),
  12806. /* 141 */
  12807. /***/ (function(module, exports, __webpack_require__) {
  12808. "use strict";
  12809. /**
  12810. * Copyright (c) Facebook, Inc. and its affiliates.
  12811. *
  12812. * This source code is licensed under the MIT license found in the
  12813. * LICENSE file in the root directory of this source tree.
  12814. *
  12815. * @format
  12816. *
  12817. * @emails oncall+draft_js
  12818. */
  12819. var DraftModifier = __webpack_require__(3);
  12820. var EditorState = __webpack_require__(2);
  12821. var getContentStateFragment = __webpack_require__(21);
  12822. var nullthrows = __webpack_require__(4);
  12823. var clipboard = null;
  12824. /**
  12825. * Some systems offer a "secondary" clipboard to allow quick internal cut
  12826. * and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
  12827. */
  12828. var SecondaryClipboard = {
  12829. cut: function cut(editorState) {
  12830. var content = editorState.getCurrentContent();
  12831. var selection = editorState.getSelection();
  12832. var targetRange = null;
  12833. if (selection.isCollapsed()) {
  12834. var anchorKey = selection.getAnchorKey();
  12835. var blockEnd = content.getBlockForKey(anchorKey).getLength();
  12836. if (blockEnd === selection.getAnchorOffset()) {
  12837. var keyAfter = content.getKeyAfter(anchorKey);
  12838. if (keyAfter == null) {
  12839. return editorState;
  12840. }
  12841. targetRange = selection.set('focusKey', keyAfter).set('focusOffset', 0);
  12842. } else {
  12843. targetRange = selection.set('focusOffset', blockEnd);
  12844. }
  12845. } else {
  12846. targetRange = selection;
  12847. }
  12848. targetRange = nullthrows(targetRange); // TODO: This should actually append to the current state when doing
  12849. // successive ^K commands without any other cursor movement
  12850. clipboard = getContentStateFragment(content, targetRange);
  12851. var afterRemoval = DraftModifier.removeRange(content, targetRange, 'forward');
  12852. if (afterRemoval === content) {
  12853. return editorState;
  12854. }
  12855. return EditorState.push(editorState, afterRemoval, 'remove-range');
  12856. },
  12857. paste: function paste(editorState) {
  12858. if (!clipboard) {
  12859. return editorState;
  12860. }
  12861. var newContent = DraftModifier.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), clipboard);
  12862. return EditorState.push(editorState, newContent, 'insert-fragment');
  12863. }
  12864. };
  12865. module.exports = SecondaryClipboard;
  12866. /***/ }),
  12867. /* 142 */
  12868. /***/ (function(module, exports, __webpack_require__) {
  12869. "use strict";
  12870. /**
  12871. * Copyright (c) Facebook, Inc. and its affiliates.
  12872. *
  12873. * This source code is licensed under the MIT license found in the
  12874. * LICENSE file in the root directory of this source tree.
  12875. *
  12876. * @format
  12877. *
  12878. * @emails oncall+draft_js
  12879. */
  12880. var EditorState = __webpack_require__(2);
  12881. var expandRangeToStartOfLine = __webpack_require__(143);
  12882. var getDraftEditorSelectionWithNodes = __webpack_require__(55);
  12883. var moveSelectionBackward = __webpack_require__(38);
  12884. var removeTextWithStrategy = __webpack_require__(20);
  12885. function keyCommandBackspaceToStartOfLine(editorState, e) {
  12886. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  12887. var selection = strategyState.getSelection();
  12888. if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
  12889. return moveSelectionBackward(strategyState, 1);
  12890. }
  12891. var ownerDocument = e.currentTarget.ownerDocument;
  12892. var domSelection = ownerDocument.defaultView.getSelection();
  12893. var range = domSelection.getRangeAt(0);
  12894. range = expandRangeToStartOfLine(range);
  12895. return getDraftEditorSelectionWithNodes(strategyState, null, range.endContainer, range.endOffset, range.startContainer, range.startOffset).selectionState;
  12896. }, 'backward');
  12897. if (afterRemoval === editorState.getCurrentContent()) {
  12898. return editorState;
  12899. }
  12900. return EditorState.push(editorState, afterRemoval, 'remove-range');
  12901. }
  12902. module.exports = keyCommandBackspaceToStartOfLine;
  12903. /***/ }),
  12904. /* 143 */
  12905. /***/ (function(module, exports, __webpack_require__) {
  12906. "use strict";
  12907. /**
  12908. * Copyright (c) Facebook, Inc. and its affiliates.
  12909. *
  12910. * This source code is licensed under the MIT license found in the
  12911. * LICENSE file in the root directory of this source tree.
  12912. *
  12913. * @format
  12914. *
  12915. * @emails oncall+draft_js
  12916. */
  12917. var UnicodeUtils = __webpack_require__(16);
  12918. var getCorrectDocumentFromNode = __webpack_require__(27);
  12919. var getRangeClientRects = __webpack_require__(70);
  12920. var invariant = __webpack_require__(1);
  12921. /**
  12922. * Return the computed line height, in pixels, for the provided element.
  12923. */
  12924. function getLineHeightPx(element) {
  12925. var computed = getComputedStyle(element);
  12926. var correctDocument = getCorrectDocumentFromNode(element);
  12927. var div = correctDocument.createElement('div');
  12928. div.style.fontFamily = computed.fontFamily;
  12929. div.style.fontSize = computed.fontSize;
  12930. div.style.fontStyle = computed.fontStyle;
  12931. div.style.fontWeight = computed.fontWeight;
  12932. div.style.lineHeight = computed.lineHeight;
  12933. div.style.position = 'absolute';
  12934. div.textContent = 'M';
  12935. var documentBody = correctDocument.body;
  12936. !documentBody ? true ? invariant(false, 'Missing document.body') : invariant(false) : void 0; // forced layout here
  12937. documentBody.appendChild(div);
  12938. var rect = div.getBoundingClientRect();
  12939. documentBody.removeChild(div);
  12940. return rect.height;
  12941. }
  12942. /**
  12943. * Return whether every ClientRect in the provided list lies on the same line.
  12944. *
  12945. * We assume that the rects on the same line all contain the baseline, so the
  12946. * lowest top line needs to be above the highest bottom line (i.e., if you were
  12947. * to project the rects onto the y-axis, their intersection would be nonempty).
  12948. *
  12949. * In addition, we require that no two boxes are lineHeight (or more) apart at
  12950. * either top or bottom, which helps protect against false positives for fonts
  12951. * with extremely large glyph heights (e.g., with a font size of 17px, Zapfino
  12952. * produces rects of height 58px!).
  12953. */
  12954. function areRectsOnOneLine(rects, lineHeight) {
  12955. var minTop = Infinity;
  12956. var minBottom = Infinity;
  12957. var maxTop = -Infinity;
  12958. var maxBottom = -Infinity;
  12959. for (var ii = 0; ii < rects.length; ii++) {
  12960. var rect = rects[ii];
  12961. if (rect.width === 0 || rect.width === 1) {
  12962. // When a range starts or ends a soft wrap, many browsers (Chrome, IE,
  12963. // Safari) include an empty rect on the previous or next line. When the
  12964. // text lies in a container whose position is not integral (e.g., from
  12965. // margin: auto), Safari makes these empty rects have width 1 (instead of
  12966. // 0). Having one-pixel-wide characters seems unlikely (and most browsers
  12967. // report widths in subpixel precision anyway) so it's relatively safe to
  12968. // skip over them.
  12969. continue;
  12970. }
  12971. minTop = Math.min(minTop, rect.top);
  12972. minBottom = Math.min(minBottom, rect.bottom);
  12973. maxTop = Math.max(maxTop, rect.top);
  12974. maxBottom = Math.max(maxBottom, rect.bottom);
  12975. }
  12976. return maxTop <= minBottom && maxTop - minTop < lineHeight && maxBottom - minBottom < lineHeight;
  12977. }
  12978. /**
  12979. * Return the length of a node, as used by Range offsets.
  12980. */
  12981. function getNodeLength(node) {
  12982. // http://www.w3.org/TR/dom/#concept-node-length
  12983. switch (node.nodeType) {
  12984. case Node.DOCUMENT_TYPE_NODE:
  12985. return 0;
  12986. case Node.TEXT_NODE:
  12987. case Node.PROCESSING_INSTRUCTION_NODE:
  12988. case Node.COMMENT_NODE:
  12989. return node.length;
  12990. default:
  12991. return node.childNodes.length;
  12992. }
  12993. }
  12994. /**
  12995. * Given a collapsed range, move the start position backwards as far as
  12996. * possible while the range still spans only a single line.
  12997. */
  12998. function expandRangeToStartOfLine(range) {
  12999. !range.collapsed ? true ? invariant(false, 'expandRangeToStartOfLine: Provided range is not collapsed.') : invariant(false) : void 0;
  13000. range = range.cloneRange();
  13001. var containingElement = range.startContainer;
  13002. if (containingElement.nodeType !== 1) {
  13003. containingElement = containingElement.parentNode;
  13004. }
  13005. var lineHeight = getLineHeightPx(containingElement); // Imagine our text looks like:
  13006. // <div><span>once upon a time, there was a <em>boy
  13007. // who lived</em> </span><q><strong>under^ the
  13008. // stairs</strong> in a small closet.</q></div>
  13009. // where the caret represents the cursor. First, we crawl up the tree until
  13010. // the range spans multiple lines (setting the start point to before
  13011. // "<strong>", then before "<div>"), then at each level we do a search to
  13012. // find the latest point which is still on a previous line. We'll find that
  13013. // the break point is inside the span, then inside the <em>, then in its text
  13014. // node child, the actual break point before "who".
  13015. var bestContainer = range.endContainer;
  13016. var bestOffset = range.endOffset;
  13017. range.setStart(range.startContainer, 0);
  13018. while (areRectsOnOneLine(getRangeClientRects(range), lineHeight)) {
  13019. bestContainer = range.startContainer;
  13020. bestOffset = range.startOffset;
  13021. !bestContainer.parentNode ? true ? invariant(false, 'Found unexpected detached subtree when traversing.') : invariant(false) : void 0;
  13022. range.setStartBefore(bestContainer);
  13023. if (bestContainer.nodeType === 1 && getComputedStyle(bestContainer).display !== 'inline') {
  13024. // The start of the line is never in a different block-level container.
  13025. break;
  13026. }
  13027. } // In the above example, range now spans from "<div>" to "under",
  13028. // bestContainer is <div>, and bestOffset is 1 (index of <q> inside <div>)].
  13029. // Picking out which child to recurse into here is a special case since we
  13030. // don't want to check past <q> -- once we find that the final range starts
  13031. // in <span>, we can look at all of its children (and all of their children)
  13032. // to find the break point.
  13033. // At all times, (bestContainer, bestOffset) is the latest single-line start
  13034. // point that we know of.
  13035. var currentContainer = bestContainer;
  13036. var maxIndexToConsider = bestOffset - 1;
  13037. do {
  13038. var nodeValue = currentContainer.nodeValue;
  13039. var ii = maxIndexToConsider;
  13040. for (; ii >= 0; ii--) {
  13041. if (nodeValue != null && ii > 0 && UnicodeUtils.isSurrogatePair(nodeValue, ii - 1)) {
  13042. // We're in the middle of a surrogate pair -- skip over so we never
  13043. // return a range with an endpoint in the middle of a code point.
  13044. continue;
  13045. }
  13046. range.setStart(currentContainer, ii);
  13047. if (areRectsOnOneLine(getRangeClientRects(range), lineHeight)) {
  13048. bestContainer = currentContainer;
  13049. bestOffset = ii;
  13050. } else {
  13051. break;
  13052. }
  13053. }
  13054. if (ii === -1 || currentContainer.childNodes.length === 0) {
  13055. // If ii === -1, then (bestContainer, bestOffset), which is equal to
  13056. // (currentContainer, 0), was a single-line start point but a start
  13057. // point before currentContainer wasn't, so the line break seems to
  13058. // have occurred immediately after currentContainer's start tag
  13059. //
  13060. // If currentContainer.childNodes.length === 0, we're already at a
  13061. // terminal node (e.g., text node) and should return our current best.
  13062. break;
  13063. }
  13064. currentContainer = currentContainer.childNodes[ii];
  13065. maxIndexToConsider = getNodeLength(currentContainer);
  13066. } while (true);
  13067. range.setStart(bestContainer, bestOffset);
  13068. return range;
  13069. }
  13070. module.exports = expandRangeToStartOfLine;
  13071. /***/ }),
  13072. /* 144 */
  13073. /***/ (function(module, exports, __webpack_require__) {
  13074. "use strict";
  13075. /**
  13076. * Copyright (c) Facebook, Inc. and its affiliates.
  13077. *
  13078. * This source code is licensed under the MIT license found in the
  13079. * LICENSE file in the root directory of this source tree.
  13080. *
  13081. * @format
  13082. *
  13083. * @emails oncall+draft_js
  13084. */
  13085. var DraftRemovableWord = __webpack_require__(71);
  13086. var EditorState = __webpack_require__(2);
  13087. var moveSelectionBackward = __webpack_require__(38);
  13088. var removeTextWithStrategy = __webpack_require__(20);
  13089. /**
  13090. * Delete the word that is left of the cursor, as well as any spaces or
  13091. * punctuation after the word.
  13092. */
  13093. function keyCommandBackspaceWord(editorState) {
  13094. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  13095. var selection = strategyState.getSelection();
  13096. var offset = selection.getStartOffset(); // If there are no words before the cursor, remove the preceding newline.
  13097. if (offset === 0) {
  13098. return moveSelectionBackward(strategyState, 1);
  13099. }
  13100. var key = selection.getStartKey();
  13101. var content = strategyState.getCurrentContent();
  13102. var text = content.getBlockForKey(key).getText().slice(0, offset);
  13103. var toRemove = DraftRemovableWord.getBackward(text);
  13104. return moveSelectionBackward(strategyState, toRemove.length || 1);
  13105. }, 'backward');
  13106. if (afterRemoval === editorState.getCurrentContent()) {
  13107. return editorState;
  13108. }
  13109. return EditorState.push(editorState, afterRemoval, 'remove-range');
  13110. }
  13111. module.exports = keyCommandBackspaceWord;
  13112. /***/ }),
  13113. /* 145 */
  13114. /***/ (function(module, exports, __webpack_require__) {
  13115. "use strict";
  13116. /**
  13117. * Copyright (c) 2013-present, Facebook, Inc.
  13118. *
  13119. * This source code is licensed under the MIT license found in the
  13120. * LICENSE file in the root directory of this source tree.
  13121. *
  13122. * @typechecks
  13123. * @stub
  13124. *
  13125. */
  13126. // \u00a1-\u00b1\u00b4-\u00b8\u00ba\u00bb\u00bf
  13127. // is latin supplement punctuation except fractions and superscript
  13128. // numbers
  13129. // \u2010-\u2027\u2030-\u205e
  13130. // is punctuation from the general punctuation block:
  13131. // weird quotes, commas, bullets, dashes, etc.
  13132. // \u30fb\u3001\u3002\u3008-\u3011\u3014-\u301f
  13133. // is CJK punctuation
  13134. // \uff1a-\uff1f\uff01-\uff0f\uff3b-\uff40\uff5b-\uff65
  13135. // is some full-width/half-width punctuation
  13136. // \u2E2E\u061f\u066a-\u066c\u061b\u060c\u060d\uFD3e\uFD3F
  13137. // is some Arabic punctuation marks
  13138. // \u1801\u0964\u104a\u104b
  13139. // is misc. other language punctuation marks
  13140. 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]";
  13141. module.exports = {
  13142. getPunctuation: function getPunctuation() {
  13143. return PUNCTUATION;
  13144. }
  13145. };
  13146. /***/ }),
  13147. /* 146 */
  13148. /***/ (function(module, exports, __webpack_require__) {
  13149. "use strict";
  13150. /**
  13151. * Copyright (c) Facebook, Inc. and its affiliates.
  13152. *
  13153. * This source code is licensed under the MIT license found in the
  13154. * LICENSE file in the root directory of this source tree.
  13155. *
  13156. * @format
  13157. *
  13158. * @emails oncall+draft_js
  13159. */
  13160. var DraftRemovableWord = __webpack_require__(71);
  13161. var EditorState = __webpack_require__(2);
  13162. var moveSelectionForward = __webpack_require__(72);
  13163. var removeTextWithStrategy = __webpack_require__(20);
  13164. /**
  13165. * Delete the word that is right of the cursor, as well as any spaces or
  13166. * punctuation before the word.
  13167. */
  13168. function keyCommandDeleteWord(editorState) {
  13169. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  13170. var selection = strategyState.getSelection();
  13171. var offset = selection.getStartOffset();
  13172. var key = selection.getStartKey();
  13173. var content = strategyState.getCurrentContent();
  13174. var text = content.getBlockForKey(key).getText().slice(offset);
  13175. var toRemove = DraftRemovableWord.getForward(text); // If there are no words in front of the cursor, remove the newline.
  13176. return moveSelectionForward(strategyState, toRemove.length || 1);
  13177. }, 'forward');
  13178. if (afterRemoval === editorState.getCurrentContent()) {
  13179. return editorState;
  13180. }
  13181. return EditorState.push(editorState, afterRemoval, 'remove-range');
  13182. }
  13183. module.exports = keyCommandDeleteWord;
  13184. /***/ }),
  13185. /* 147 */
  13186. /***/ (function(module, exports, __webpack_require__) {
  13187. "use strict";
  13188. /**
  13189. * Copyright (c) Facebook, Inc. and its affiliates.
  13190. *
  13191. * This source code is licensed under the MIT license found in the
  13192. * LICENSE file in the root directory of this source tree.
  13193. *
  13194. * @format
  13195. *
  13196. * @emails oncall+draft_js
  13197. */
  13198. var DraftModifier = __webpack_require__(3);
  13199. var EditorState = __webpack_require__(2);
  13200. function keyCommandInsertNewline(editorState) {
  13201. var contentState = DraftModifier.splitBlock(editorState.getCurrentContent(), editorState.getSelection());
  13202. return EditorState.push(editorState, contentState, 'split-block');
  13203. }
  13204. module.exports = keyCommandInsertNewline;
  13205. /***/ }),
  13206. /* 148 */
  13207. /***/ (function(module, exports, __webpack_require__) {
  13208. "use strict";
  13209. /**
  13210. * Copyright (c) Facebook, Inc. and its affiliates.
  13211. *
  13212. * This source code is licensed under the MIT license found in the
  13213. * LICENSE file in the root directory of this source tree.
  13214. *
  13215. * @format
  13216. *
  13217. * @emails oncall+draft_js
  13218. */
  13219. var EditorState = __webpack_require__(2);
  13220. /**
  13221. * See comment for `moveSelectionToStartOfBlock`.
  13222. */
  13223. function keyCommandMoveSelectionToEndOfBlock(editorState) {
  13224. var selection = editorState.getSelection();
  13225. var endKey = selection.getEndKey();
  13226. var content = editorState.getCurrentContent();
  13227. var textLength = content.getBlockForKey(endKey).getLength();
  13228. return EditorState.set(editorState, {
  13229. selection: selection.merge({
  13230. anchorKey: endKey,
  13231. anchorOffset: textLength,
  13232. focusKey: endKey,
  13233. focusOffset: textLength,
  13234. isBackward: false
  13235. }),
  13236. forceSelection: true
  13237. });
  13238. }
  13239. module.exports = keyCommandMoveSelectionToEndOfBlock;
  13240. /***/ }),
  13241. /* 149 */
  13242. /***/ (function(module, exports, __webpack_require__) {
  13243. "use strict";
  13244. /**
  13245. * Copyright (c) Facebook, Inc. and its affiliates.
  13246. *
  13247. * This source code is licensed under the MIT license found in the
  13248. * LICENSE file in the root directory of this source tree.
  13249. *
  13250. * @format
  13251. *
  13252. * @emails oncall+draft_js
  13253. */
  13254. var EditorState = __webpack_require__(2);
  13255. /**
  13256. * Collapse selection at the start of the first selected block. This is used
  13257. * for Firefox versions that attempt to navigate forward/backward instead of
  13258. * moving the cursor. Other browsers are able to move the cursor natively.
  13259. */
  13260. function keyCommandMoveSelectionToStartOfBlock(editorState) {
  13261. var selection = editorState.getSelection();
  13262. var startKey = selection.getStartKey();
  13263. return EditorState.set(editorState, {
  13264. selection: selection.merge({
  13265. anchorKey: startKey,
  13266. anchorOffset: 0,
  13267. focusKey: startKey,
  13268. focusOffset: 0,
  13269. isBackward: false
  13270. }),
  13271. forceSelection: true
  13272. });
  13273. }
  13274. module.exports = keyCommandMoveSelectionToStartOfBlock;
  13275. /***/ }),
  13276. /* 150 */
  13277. /***/ (function(module, exports, __webpack_require__) {
  13278. "use strict";
  13279. /**
  13280. * Copyright (c) Facebook, Inc. and its affiliates.
  13281. *
  13282. * This source code is licensed under the MIT license found in the
  13283. * LICENSE file in the root directory of this source tree.
  13284. *
  13285. * @format
  13286. *
  13287. * @emails oncall+draft_js
  13288. */
  13289. var EditorState = __webpack_require__(2);
  13290. var UnicodeUtils = __webpack_require__(16);
  13291. var moveSelectionForward = __webpack_require__(72);
  13292. var removeTextWithStrategy = __webpack_require__(20);
  13293. /**
  13294. * Remove the selected range. If the cursor is collapsed, remove the following
  13295. * character. This operation is Unicode-aware, so removing a single character
  13296. * will remove a surrogate pair properly as well.
  13297. */
  13298. function keyCommandPlainDelete(editorState) {
  13299. var afterRemoval = removeTextWithStrategy(editorState, function (strategyState) {
  13300. var selection = strategyState.getSelection();
  13301. var content = strategyState.getCurrentContent();
  13302. var key = selection.getAnchorKey();
  13303. var offset = selection.getAnchorOffset();
  13304. var charAhead = content.getBlockForKey(key).getText()[offset];
  13305. return moveSelectionForward(strategyState, charAhead ? UnicodeUtils.getUTF16Length(charAhead, 0) : 1);
  13306. }, 'forward');
  13307. if (afterRemoval === editorState.getCurrentContent()) {
  13308. return editorState;
  13309. }
  13310. var selection = editorState.getSelection();
  13311. return EditorState.push(editorState, afterRemoval.set('selectionBefore', selection), selection.isCollapsed() ? 'delete-character' : 'remove-range');
  13312. }
  13313. module.exports = keyCommandPlainDelete;
  13314. /***/ }),
  13315. /* 151 */
  13316. /***/ (function(module, exports, __webpack_require__) {
  13317. "use strict";
  13318. /**
  13319. * Copyright (c) Facebook, Inc. and its affiliates.
  13320. *
  13321. * This source code is licensed under the MIT license found in the
  13322. * LICENSE file in the root directory of this source tree.
  13323. *
  13324. * @format
  13325. *
  13326. * @emails oncall+draft_js
  13327. */
  13328. var DraftModifier = __webpack_require__(3);
  13329. var EditorState = __webpack_require__(2);
  13330. var getContentStateFragment = __webpack_require__(21);
  13331. /**
  13332. * Transpose the characters on either side of a collapsed cursor, or
  13333. * if the cursor is at the end of the block, transpose the last two
  13334. * characters.
  13335. */
  13336. function keyCommandTransposeCharacters(editorState) {
  13337. var selection = editorState.getSelection();
  13338. if (!selection.isCollapsed()) {
  13339. return editorState;
  13340. }
  13341. var offset = selection.getAnchorOffset();
  13342. if (offset === 0) {
  13343. return editorState;
  13344. }
  13345. var blockKey = selection.getAnchorKey();
  13346. var content = editorState.getCurrentContent();
  13347. var block = content.getBlockForKey(blockKey);
  13348. var length = block.getLength(); // Nothing to transpose if there aren't two characters.
  13349. if (length <= 1) {
  13350. return editorState;
  13351. }
  13352. var removalRange;
  13353. var finalSelection;
  13354. if (offset === length) {
  13355. // The cursor is at the end of the block. Swap the last two characters.
  13356. removalRange = selection.set('anchorOffset', offset - 1);
  13357. finalSelection = selection;
  13358. } else {
  13359. removalRange = selection.set('focusOffset', offset + 1);
  13360. finalSelection = removalRange.set('anchorOffset', offset + 1);
  13361. } // Extract the character to move as a fragment. This preserves its
  13362. // styling and entity, if any.
  13363. var movedFragment = getContentStateFragment(content, removalRange);
  13364. var afterRemoval = DraftModifier.removeRange(content, removalRange, 'backward'); // After the removal, the insertion target is one character back.
  13365. var selectionAfter = afterRemoval.getSelectionAfter();
  13366. var targetOffset = selectionAfter.getAnchorOffset() - 1;
  13367. var targetRange = selectionAfter.merge({
  13368. anchorOffset: targetOffset,
  13369. focusOffset: targetOffset
  13370. });
  13371. var afterInsert = DraftModifier.replaceWithFragment(afterRemoval, targetRange, movedFragment);
  13372. var newEditorState = EditorState.push(editorState, afterInsert, 'insert-fragment');
  13373. return EditorState.acceptSelection(newEditorState, finalSelection);
  13374. }
  13375. module.exports = keyCommandTransposeCharacters;
  13376. /***/ }),
  13377. /* 152 */
  13378. /***/ (function(module, exports, __webpack_require__) {
  13379. "use strict";
  13380. /**
  13381. * Copyright (c) Facebook, Inc. and its affiliates.
  13382. *
  13383. * This source code is licensed under the MIT license found in the
  13384. * LICENSE file in the root directory of this source tree.
  13385. *
  13386. * @format
  13387. *
  13388. * @emails oncall+draft_js
  13389. */
  13390. var EditorState = __webpack_require__(2);
  13391. function keyCommandUndo(e, editorState, updateFn) {
  13392. var undoneState = EditorState.undo(editorState); // If the last change to occur was a spellcheck change, allow the undo
  13393. // event to fall through to the browser. This allows the browser to record
  13394. // the unwanted change, which should soon lead it to learn not to suggest
  13395. // the correction again.
  13396. if (editorState.getLastChangeType() === 'spellcheck-change') {
  13397. var nativelyRenderedContent = undoneState.getCurrentContent();
  13398. updateFn(EditorState.set(undoneState, {
  13399. nativelyRenderedContent: nativelyRenderedContent
  13400. }));
  13401. return;
  13402. } // Otheriwse, manage the undo behavior manually.
  13403. e.preventDefault();
  13404. if (!editorState.getNativelyRenderedContent()) {
  13405. updateFn(undoneState);
  13406. return;
  13407. } // Trigger a re-render with the current content state to ensure that the
  13408. // component tree has up-to-date props for comparison.
  13409. updateFn(EditorState.set(editorState, {
  13410. nativelyRenderedContent: null
  13411. })); // Wait to ensure that the re-render has occurred before performing
  13412. // the undo action.
  13413. setTimeout(function () {
  13414. updateFn(undoneState);
  13415. }, 0);
  13416. }
  13417. module.exports = keyCommandUndo;
  13418. /***/ }),
  13419. /* 153 */
  13420. /***/ (function(module, exports, __webpack_require__) {
  13421. "use strict";
  13422. /**
  13423. * Copyright (c) Facebook, Inc. and its affiliates.
  13424. *
  13425. * This source code is licensed under the MIT license found in the
  13426. * LICENSE file in the root directory of this source tree.
  13427. *
  13428. * @format
  13429. *
  13430. * @emails oncall+draft_js
  13431. */
  13432. var BlockMapBuilder = __webpack_require__(17);
  13433. var CharacterMetadata = __webpack_require__(6);
  13434. var DataTransfer = __webpack_require__(65);
  13435. var DraftModifier = __webpack_require__(3);
  13436. var DraftPasteProcessor = __webpack_require__(154);
  13437. var EditorState = __webpack_require__(2);
  13438. var RichTextEditorUtil = __webpack_require__(75);
  13439. var getEntityKeyForSelection = __webpack_require__(35);
  13440. var getTextContentFromFiles = __webpack_require__(67);
  13441. var isEventHandled = __webpack_require__(31);
  13442. var splitTextIntoTextBlocks = __webpack_require__(159);
  13443. /**
  13444. * Paste content.
  13445. */
  13446. function editOnPaste(editor, e) {
  13447. e.preventDefault();
  13448. var data = new DataTransfer(e.clipboardData); // Get files, unless this is likely to be a string the user wants inline.
  13449. if (!data.isRichText()) {
  13450. var files = data.getFiles();
  13451. var defaultFileText = data.getText();
  13452. if (files.length > 0) {
  13453. // Allow customized paste handling for images, etc. Otherwise, fall
  13454. // through to insert text contents into the editor.
  13455. if (editor.props.handlePastedFiles && isEventHandled(editor.props.handlePastedFiles(files))) {
  13456. return;
  13457. }
  13458. /* $FlowFixMe This comment suppresses an error found DataTransfer was
  13459. * typed. getFiles() returns an array of <Files extends Blob>, not Blob
  13460. */
  13461. getTextContentFromFiles(files, function (
  13462. /*string*/
  13463. fileText) {
  13464. fileText = fileText || defaultFileText;
  13465. if (!fileText) {
  13466. return;
  13467. }
  13468. var editorState = editor._latestEditorState;
  13469. var blocks = splitTextIntoTextBlocks(fileText);
  13470. var character = CharacterMetadata.create({
  13471. style: editorState.getCurrentInlineStyle(),
  13472. entity: getEntityKeyForSelection(editorState.getCurrentContent(), editorState.getSelection())
  13473. });
  13474. var currentBlockType = RichTextEditorUtil.getCurrentBlockType(editorState);
  13475. var text = DraftPasteProcessor.processText(blocks, character, currentBlockType);
  13476. var fragment = BlockMapBuilder.createFromArray(text);
  13477. var withInsertedText = DraftModifier.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment);
  13478. editor.update(EditorState.push(editorState, withInsertedText, 'insert-fragment'));
  13479. });
  13480. return;
  13481. }
  13482. }
  13483. var textBlocks = [];
  13484. var text = data.getText();
  13485. var html = data.getHTML();
  13486. var editorState = editor._latestEditorState;
  13487. if (editor.props.handlePastedText && isEventHandled(editor.props.handlePastedText(text, html, editorState))) {
  13488. return;
  13489. }
  13490. if (text) {
  13491. textBlocks = splitTextIntoTextBlocks(text);
  13492. }
  13493. if (!editor.props.stripPastedStyles) {
  13494. // If the text from the paste event is rich content that matches what we
  13495. // already have on the internal clipboard, assume that we should just use
  13496. // the clipboard fragment for the paste. This will allow us to preserve
  13497. // styling and entities, if any are present. Note that newlines are
  13498. // stripped during comparison -- this is because copy/paste within the
  13499. // editor in Firefox and IE will not include empty lines. The resulting
  13500. // paste will preserve the newlines correctly.
  13501. var internalClipboard = editor.getClipboard();
  13502. if (data.isRichText() && internalClipboard) {
  13503. if ( // If the editorKey is present in the pasted HTML, it should be safe to
  13504. // assume this is an internal paste.
  13505. html.indexOf(editor.getEditorKey()) !== -1 || // The copy may have been made within a single block, in which case the
  13506. // editor key won't be part of the paste. In this case, just check
  13507. // whether the pasted text matches the internal clipboard.
  13508. textBlocks.length === 1 && internalClipboard.size === 1 && internalClipboard.first().getText() === text) {
  13509. editor.update(insertFragment(editor._latestEditorState, internalClipboard));
  13510. return;
  13511. }
  13512. } else if (internalClipboard && data.types.includes('com.apple.webarchive') && !data.types.includes('text/html') && areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)) {
  13513. // Safari does not properly store text/html in some cases.
  13514. // Use the internalClipboard if present and equal to what is on
  13515. // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
  13516. editor.update(insertFragment(editor._latestEditorState, internalClipboard));
  13517. return;
  13518. } // If there is html paste data, try to parse that.
  13519. if (html) {
  13520. var htmlFragment = DraftPasteProcessor.processHTML(html, editor.props.blockRenderMap);
  13521. if (htmlFragment) {
  13522. var contentBlocks = htmlFragment.contentBlocks,
  13523. entityMap = htmlFragment.entityMap;
  13524. if (contentBlocks) {
  13525. var htmlMap = BlockMapBuilder.createFromArray(contentBlocks);
  13526. editor.update(insertFragment(editor._latestEditorState, htmlMap, entityMap));
  13527. return;
  13528. }
  13529. }
  13530. } // Otherwise, create a new fragment from our pasted text. Also
  13531. // empty the internal clipboard, since it's no longer valid.
  13532. editor.setClipboard(null);
  13533. }
  13534. if (textBlocks.length) {
  13535. var character = CharacterMetadata.create({
  13536. style: editorState.getCurrentInlineStyle(),
  13537. entity: getEntityKeyForSelection(editorState.getCurrentContent(), editorState.getSelection())
  13538. });
  13539. var currentBlockType = RichTextEditorUtil.getCurrentBlockType(editorState);
  13540. var textFragment = DraftPasteProcessor.processText(textBlocks, character, currentBlockType);
  13541. var textMap = BlockMapBuilder.createFromArray(textFragment);
  13542. editor.update(insertFragment(editor._latestEditorState, textMap));
  13543. }
  13544. }
  13545. function insertFragment(editorState, fragment, entityMap) {
  13546. var newContent = DraftModifier.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment); // TODO: merge the entity map once we stop using DraftEntity
  13547. // like this:
  13548. // const mergedEntityMap = newContent.getEntityMap().merge(entityMap);
  13549. return EditorState.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment');
  13550. }
  13551. function areTextBlocksAndClipboardEqual(textBlocks, blockMap) {
  13552. return textBlocks.length === blockMap.size && blockMap.valueSeq().every(function (block, ii) {
  13553. return block.getText() === textBlocks[ii];
  13554. });
  13555. }
  13556. module.exports = editOnPaste;
  13557. /***/ }),
  13558. /* 154 */
  13559. /***/ (function(module, exports, __webpack_require__) {
  13560. "use strict";
  13561. /**
  13562. * Copyright (c) Facebook, Inc. and its affiliates.
  13563. *
  13564. * This source code is licensed under the MIT license found in the
  13565. * LICENSE file in the root directory of this source tree.
  13566. *
  13567. * @format
  13568. *
  13569. * @emails oncall+draft_js
  13570. */
  13571. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  13572. 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; }
  13573. var ContentBlock = __webpack_require__(12);
  13574. var ContentBlockNode = __webpack_require__(7);
  13575. var convertFromHTMLToContentBlocks = __webpack_require__(73);
  13576. var generateRandomKey = __webpack_require__(9);
  13577. var getSafeBodyFromHTML = __webpack_require__(74);
  13578. var gkx = __webpack_require__(11);
  13579. var Immutable = __webpack_require__(0);
  13580. var sanitizeDraftText = __webpack_require__(47);
  13581. var List = Immutable.List,
  13582. Repeat = Immutable.Repeat;
  13583. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  13584. var ContentBlockRecord = experimentalTreeDataSupport ? ContentBlockNode : ContentBlock;
  13585. var DraftPasteProcessor = {
  13586. processHTML: function processHTML(html, blockRenderMap) {
  13587. return convertFromHTMLToContentBlocks(html, getSafeBodyFromHTML, blockRenderMap);
  13588. },
  13589. processText: function processText(textBlocks, character, type) {
  13590. return textBlocks.reduce(function (acc, textLine, index) {
  13591. textLine = sanitizeDraftText(textLine);
  13592. var key = generateRandomKey();
  13593. var blockNodeConfig = {
  13594. key: key,
  13595. type: type,
  13596. text: textLine,
  13597. characterList: List(Repeat(character, textLine.length))
  13598. }; // next block updates previous block
  13599. if (experimentalTreeDataSupport && index !== 0) {
  13600. var prevSiblingIndex = index - 1; // update previous block
  13601. var previousBlock = acc[prevSiblingIndex] = acc[prevSiblingIndex].merge({
  13602. nextSibling: key
  13603. });
  13604. blockNodeConfig = _objectSpread({}, blockNodeConfig, {
  13605. prevSibling: previousBlock.getKey()
  13606. });
  13607. }
  13608. acc.push(new ContentBlockRecord(blockNodeConfig));
  13609. return acc;
  13610. }, []);
  13611. }
  13612. };
  13613. module.exports = DraftPasteProcessor;
  13614. /***/ }),
  13615. /* 155 */
  13616. /***/ (function(module, exports, __webpack_require__) {
  13617. "use strict";
  13618. /**
  13619. * Copyright (c) 2013-present, Facebook, Inc.
  13620. *
  13621. * This source code is licensed under the MIT license found in the
  13622. * LICENSE file in the root directory of this source tree.
  13623. *
  13624. *
  13625. */
  13626. 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; }
  13627. var URI =
  13628. /*#__PURE__*/
  13629. function () {
  13630. function URI(uri) {
  13631. _defineProperty(this, "_uri", void 0);
  13632. this._uri = uri;
  13633. }
  13634. var _proto = URI.prototype;
  13635. _proto.toString = function toString() {
  13636. return this._uri;
  13637. };
  13638. return URI;
  13639. }();
  13640. module.exports = URI;
  13641. /***/ }),
  13642. /* 156 */
  13643. /***/ (function(module, exports, __webpack_require__) {
  13644. "use strict";
  13645. /**
  13646. * Copyright (c) Facebook, Inc. and its affiliates.
  13647. *
  13648. * This source code is licensed under the MIT license found in the
  13649. * LICENSE file in the root directory of this source tree.
  13650. *
  13651. * @format
  13652. *
  13653. * @emails oncall+draft_js
  13654. */
  13655. var isElement = __webpack_require__(15);
  13656. function isHTMLAnchorElement(node) {
  13657. if (!node || !node.ownerDocument) {
  13658. return false;
  13659. }
  13660. return isElement(node) && node.nodeName === 'A';
  13661. }
  13662. module.exports = isHTMLAnchorElement;
  13663. /***/ }),
  13664. /* 157 */
  13665. /***/ (function(module, exports, __webpack_require__) {
  13666. "use strict";
  13667. /**
  13668. * Copyright (c) Facebook, Inc. and its affiliates.
  13669. *
  13670. * This source code is licensed under the MIT license found in the
  13671. * LICENSE file in the root directory of this source tree.
  13672. *
  13673. * @format
  13674. *
  13675. * @emails oncall+draft_js
  13676. */
  13677. var isElement = __webpack_require__(15);
  13678. function isHTMLImageElement(node) {
  13679. if (!node || !node.ownerDocument) {
  13680. return false;
  13681. }
  13682. return isElement(node) && node.nodeName === 'IMG';
  13683. }
  13684. module.exports = isHTMLImageElement;
  13685. /***/ }),
  13686. /* 158 */
  13687. /***/ (function(module, exports, __webpack_require__) {
  13688. "use strict";
  13689. /**
  13690. * Copyright (c) Facebook, Inc. and its affiliates.
  13691. *
  13692. * This source code is licensed under the MIT license found in the
  13693. * LICENSE file in the root directory of this source tree.
  13694. *
  13695. * @format
  13696. *
  13697. * @emails oncall+draft_js
  13698. */
  13699. function adjustBlockDepthForContentState(contentState, selectionState, adjustment, maxDepth) {
  13700. var startKey = selectionState.getStartKey();
  13701. var endKey = selectionState.getEndKey();
  13702. var blockMap = contentState.getBlockMap();
  13703. var blocks = blockMap.toSeq().skipUntil(function (_, k) {
  13704. return k === startKey;
  13705. }).takeUntil(function (_, k) {
  13706. return k === endKey;
  13707. }).concat([[endKey, blockMap.get(endKey)]]).map(function (block) {
  13708. var depth = block.getDepth() + adjustment;
  13709. depth = Math.max(0, Math.min(depth, maxDepth));
  13710. return block.set('depth', depth);
  13711. });
  13712. blockMap = blockMap.merge(blocks);
  13713. return contentState.merge({
  13714. blockMap: blockMap,
  13715. selectionBefore: selectionState,
  13716. selectionAfter: selectionState
  13717. });
  13718. }
  13719. module.exports = adjustBlockDepthForContentState;
  13720. /***/ }),
  13721. /* 159 */
  13722. /***/ (function(module, exports, __webpack_require__) {
  13723. "use strict";
  13724. /**
  13725. * Copyright (c) Facebook, Inc. and its affiliates.
  13726. *
  13727. * This source code is licensed under the MIT license found in the
  13728. * LICENSE file in the root directory of this source tree.
  13729. *
  13730. * @format
  13731. *
  13732. * @emails oncall+draft_js
  13733. */
  13734. var NEWLINE_REGEX = /\r\n?|\n/g;
  13735. function splitTextIntoTextBlocks(text) {
  13736. return text.split(NEWLINE_REGEX);
  13737. }
  13738. module.exports = splitTextIntoTextBlocks;
  13739. /***/ }),
  13740. /* 160 */
  13741. /***/ (function(module, exports, __webpack_require__) {
  13742. "use strict";
  13743. /**
  13744. * Copyright (c) Facebook, Inc. and its affiliates.
  13745. *
  13746. * This source code is licensed under the MIT license found in the
  13747. * LICENSE file in the root directory of this source tree.
  13748. *
  13749. * @format
  13750. *
  13751. * @emails oncall+draft_js
  13752. */
  13753. var ReactDOMComet = __webpack_require__(161);
  13754. var flushControlled = ReactDOMComet.unstable_flushControlled;
  13755. module.exports = flushControlled;
  13756. /***/ }),
  13757. /* 161 */
  13758. /***/ (function(module, exports) {
  13759. module.exports = __WEBPACK_EXTERNAL_MODULE_161__;
  13760. /***/ }),
  13761. /* 162 */
  13762. /***/ (function(module, exports, __webpack_require__) {
  13763. "use strict";
  13764. /**
  13765. * Copyright (c) Facebook, Inc. and its affiliates.
  13766. *
  13767. * This source code is licensed under the MIT license found in the
  13768. * LICENSE file in the root directory of this source tree.
  13769. *
  13770. * @format
  13771. *
  13772. * @emails oncall+draft_js
  13773. */
  13774. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  13775. var React = __webpack_require__(8);
  13776. var cx = __webpack_require__(13);
  13777. /**
  13778. * This component is responsible for rendering placeholder text for the
  13779. * `DraftEditor` component.
  13780. *
  13781. * Override placeholder style via CSS.
  13782. */
  13783. var DraftEditorPlaceholder =
  13784. /*#__PURE__*/
  13785. function (_React$Component) {
  13786. _inheritsLoose(DraftEditorPlaceholder, _React$Component);
  13787. function DraftEditorPlaceholder() {
  13788. return _React$Component.apply(this, arguments) || this;
  13789. }
  13790. var _proto = DraftEditorPlaceholder.prototype;
  13791. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  13792. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  13793. };
  13794. _proto.render = function render() {
  13795. var hasFocus = this.props.editorState.getSelection().getHasFocus();
  13796. var className = cx({
  13797. 'public/DraftEditorPlaceholder/root': true,
  13798. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  13799. });
  13800. var contentStyle = {
  13801. whiteSpace: 'pre-wrap'
  13802. };
  13803. return React.createElement("div", {
  13804. className: className
  13805. }, React.createElement("div", {
  13806. className: cx('public/DraftEditorPlaceholder/inner'),
  13807. id: this.props.accessibilityID,
  13808. style: contentStyle
  13809. }, this.props.text));
  13810. };
  13811. return DraftEditorPlaceholder;
  13812. }(React.Component);
  13813. module.exports = DraftEditorPlaceholder;
  13814. /***/ }),
  13815. /* 163 */
  13816. /***/ (function(module, exports, __webpack_require__) {
  13817. "use strict";
  13818. /**
  13819. * Copyright (c) Facebook, Inc. and its affiliates.
  13820. *
  13821. * This source code is licensed under the MIT license found in the
  13822. * LICENSE file in the root directory of this source tree.
  13823. *
  13824. * @format
  13825. *
  13826. * @emails oncall+draft_js
  13827. */
  13828. /***/ }),
  13829. /* 164 */
  13830. /***/ (function(module, exports, __webpack_require__) {
  13831. "use strict";
  13832. /**
  13833. * Copyright (c) Facebook, Inc. and its affiliates.
  13834. *
  13835. * This source code is licensed under the MIT license found in the
  13836. * LICENSE file in the root directory of this source tree.
  13837. *
  13838. * @format
  13839. *
  13840. * @emails oncall+draft_js
  13841. */
  13842. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  13843. 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; }
  13844. var ContentBlock = __webpack_require__(12);
  13845. var ContentBlockNode = __webpack_require__(7);
  13846. var DraftStringKey = __webpack_require__(77);
  13847. var encodeEntityRanges = __webpack_require__(165);
  13848. var encodeInlineStyleRanges = __webpack_require__(166);
  13849. var invariant = __webpack_require__(1);
  13850. var createRawBlock = function createRawBlock(block, entityStorageMap) {
  13851. return {
  13852. key: block.getKey(),
  13853. text: block.getText(),
  13854. type: block.getType(),
  13855. depth: block.getDepth(),
  13856. inlineStyleRanges: encodeInlineStyleRanges(block),
  13857. entityRanges: encodeEntityRanges(block, entityStorageMap),
  13858. data: block.getData().toObject()
  13859. };
  13860. };
  13861. var insertRawBlock = function insertRawBlock(block, entityMap, rawBlocks, blockCacheRef) {
  13862. if (block instanceof ContentBlock) {
  13863. rawBlocks.push(createRawBlock(block, entityMap));
  13864. return;
  13865. }
  13866. !(block instanceof ContentBlockNode) ? true ? invariant(false, 'block is not a BlockNode') : invariant(false) : void 0;
  13867. var parentKey = block.getParentKey();
  13868. var rawBlock = blockCacheRef[block.getKey()] = _objectSpread({}, createRawBlock(block, entityMap), {
  13869. children: []
  13870. });
  13871. if (parentKey) {
  13872. blockCacheRef[parentKey].children.push(rawBlock);
  13873. return;
  13874. }
  13875. rawBlocks.push(rawBlock);
  13876. };
  13877. var encodeRawBlocks = function encodeRawBlocks(contentState, rawState) {
  13878. var entityMap = rawState.entityMap;
  13879. var rawBlocks = [];
  13880. var blockCacheRef = {};
  13881. var entityCacheRef = {};
  13882. var entityStorageKey = 0;
  13883. contentState.getBlockMap().forEach(function (block) {
  13884. block.findEntityRanges(function (character) {
  13885. return character.getEntity() !== null;
  13886. }, function (start) {
  13887. var entityKey = block.getEntityAt(start); // Stringify to maintain order of otherwise numeric keys.
  13888. var stringifiedEntityKey = DraftStringKey.stringify(entityKey); // This makes this function resilient to two entities
  13889. // erroneously having the same key
  13890. if (entityCacheRef[stringifiedEntityKey]) {
  13891. return;
  13892. }
  13893. entityCacheRef[stringifiedEntityKey] = entityKey; // we need the `any` casting here since this is a temporary state
  13894. // where we will later on flip the entity map and populate it with
  13895. // real entity, at this stage we just need to map back the entity
  13896. // key used by the BlockNode
  13897. entityMap[stringifiedEntityKey] = "".concat(entityStorageKey);
  13898. entityStorageKey++;
  13899. });
  13900. insertRawBlock(block, entityMap, rawBlocks, blockCacheRef);
  13901. });
  13902. return {
  13903. blocks: rawBlocks,
  13904. entityMap: entityMap
  13905. };
  13906. }; // Flip storage map so that our storage keys map to global
  13907. // DraftEntity keys.
  13908. var encodeRawEntityMap = function encodeRawEntityMap(contentState, rawState) {
  13909. var blocks = rawState.blocks,
  13910. entityMap = rawState.entityMap;
  13911. var rawEntityMap = {};
  13912. Object.keys(entityMap).forEach(function (key, index) {
  13913. var entity = contentState.getEntity(DraftStringKey.unstringify(key));
  13914. rawEntityMap[index] = {
  13915. type: entity.getType(),
  13916. mutability: entity.getMutability(),
  13917. data: entity.getData()
  13918. };
  13919. });
  13920. return {
  13921. blocks: blocks,
  13922. entityMap: rawEntityMap
  13923. };
  13924. };
  13925. var convertFromDraftStateToRaw = function convertFromDraftStateToRaw(contentState) {
  13926. var rawDraftContentState = {
  13927. entityMap: {},
  13928. blocks: []
  13929. }; // add blocks
  13930. rawDraftContentState = encodeRawBlocks(contentState, rawDraftContentState); // add entities
  13931. rawDraftContentState = encodeRawEntityMap(contentState, rawDraftContentState);
  13932. return rawDraftContentState;
  13933. };
  13934. module.exports = convertFromDraftStateToRaw;
  13935. /***/ }),
  13936. /* 165 */
  13937. /***/ (function(module, exports, __webpack_require__) {
  13938. "use strict";
  13939. /**
  13940. * Copyright (c) Facebook, Inc. and its affiliates.
  13941. *
  13942. * This source code is licensed under the MIT license found in the
  13943. * LICENSE file in the root directory of this source tree.
  13944. *
  13945. * @format
  13946. *
  13947. * @emails oncall+draft_js
  13948. */
  13949. var DraftStringKey = __webpack_require__(77);
  13950. var UnicodeUtils = __webpack_require__(16);
  13951. var strlen = UnicodeUtils.strlen;
  13952. /**
  13953. * Convert to UTF-8 character counts for storage.
  13954. */
  13955. function encodeEntityRanges(block, storageMap) {
  13956. var encoded = [];
  13957. block.findEntityRanges(function (character) {
  13958. return !!character.getEntity();
  13959. }, function (
  13960. /*number*/
  13961. start,
  13962. /*number*/
  13963. end) {
  13964. var text = block.getText();
  13965. var key = block.getEntityAt(start);
  13966. encoded.push({
  13967. offset: strlen(text.slice(0, start)),
  13968. length: strlen(text.slice(start, end)),
  13969. // Encode the key as a number for range storage.
  13970. key: Number(storageMap[DraftStringKey.stringify(key)])
  13971. });
  13972. });
  13973. return encoded;
  13974. }
  13975. module.exports = encodeEntityRanges;
  13976. /***/ }),
  13977. /* 166 */
  13978. /***/ (function(module, exports, __webpack_require__) {
  13979. "use strict";
  13980. /**
  13981. * Copyright (c) Facebook, Inc. and its affiliates.
  13982. *
  13983. * This source code is licensed under the MIT license found in the
  13984. * LICENSE file in the root directory of this source tree.
  13985. *
  13986. * @format
  13987. *
  13988. * @emails oncall+draft_js
  13989. */
  13990. var UnicodeUtils = __webpack_require__(16);
  13991. var findRangesImmutable = __webpack_require__(18);
  13992. var areEqual = function areEqual(a, b) {
  13993. return a === b;
  13994. };
  13995. var isTruthy = function isTruthy(a) {
  13996. return !!a;
  13997. };
  13998. var EMPTY_ARRAY = [];
  13999. /**
  14000. * Helper function for getting encoded styles for each inline style. Convert
  14001. * to UTF-8 character counts for storage.
  14002. */
  14003. function getEncodedInlinesForType(block, styleList, styleToEncode) {
  14004. var ranges = []; // Obtain an array with ranges for only the specified style.
  14005. var filteredInlines = styleList.map(function (style) {
  14006. return style.has(styleToEncode);
  14007. }).toList();
  14008. findRangesImmutable(filteredInlines, areEqual, // We only want to keep ranges with nonzero style values.
  14009. isTruthy, function (start, end) {
  14010. var text = block.getText();
  14011. ranges.push({
  14012. offset: UnicodeUtils.strlen(text.slice(0, start)),
  14013. length: UnicodeUtils.strlen(text.slice(start, end)),
  14014. style: styleToEncode
  14015. });
  14016. });
  14017. return ranges;
  14018. }
  14019. /*
  14020. * Retrieve the encoded arrays of inline styles, with each individual style
  14021. * treated separately.
  14022. */
  14023. function encodeInlineStyleRanges(block) {
  14024. var styleList = block.getCharacterList().map(function (c) {
  14025. return c.getStyle();
  14026. }).toList();
  14027. var ranges = styleList.flatten().toSet().map(function (style) {
  14028. return getEncodedInlinesForType(block, styleList, style);
  14029. });
  14030. return Array.prototype.concat.apply(EMPTY_ARRAY, ranges.toJS());
  14031. }
  14032. module.exports = encodeInlineStyleRanges;
  14033. /***/ }),
  14034. /* 167 */
  14035. /***/ (function(module, exports, __webpack_require__) {
  14036. "use strict";
  14037. /**
  14038. * Copyright (c) Facebook, Inc. and its affiliates.
  14039. *
  14040. * This source code is licensed under the MIT license found in the
  14041. * LICENSE file in the root directory of this source tree.
  14042. *
  14043. * @format
  14044. *
  14045. * @emails oncall+draft_js
  14046. */
  14047. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  14048. 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; }
  14049. var ContentBlock = __webpack_require__(12);
  14050. var ContentBlockNode = __webpack_require__(7);
  14051. var ContentState = __webpack_require__(32);
  14052. var DraftEntity = __webpack_require__(22);
  14053. var DraftTreeAdapter = __webpack_require__(168);
  14054. var DraftTreeInvariants = __webpack_require__(169);
  14055. var SelectionState = __webpack_require__(23);
  14056. var createCharacterList = __webpack_require__(170);
  14057. var decodeEntityRanges = __webpack_require__(171);
  14058. var decodeInlineStyleRanges = __webpack_require__(172);
  14059. var generateRandomKey = __webpack_require__(9);
  14060. var gkx = __webpack_require__(11);
  14061. var Immutable = __webpack_require__(0);
  14062. var invariant = __webpack_require__(1);
  14063. var experimentalTreeDataSupport = gkx('draft_tree_data_support');
  14064. var List = Immutable.List,
  14065. Map = Immutable.Map,
  14066. OrderedMap = Immutable.OrderedMap;
  14067. var decodeBlockNodeConfig = function decodeBlockNodeConfig(block, entityMap) {
  14068. var key = block.key,
  14069. type = block.type,
  14070. data = block.data,
  14071. text = block.text,
  14072. depth = block.depth;
  14073. var blockNodeConfig = {
  14074. text: text,
  14075. depth: depth || 0,
  14076. type: type || 'unstyled',
  14077. key: key || generateRandomKey(),
  14078. data: Map(data),
  14079. characterList: decodeCharacterList(block, entityMap)
  14080. };
  14081. return blockNodeConfig;
  14082. };
  14083. var decodeCharacterList = function decodeCharacterList(block, entityMap) {
  14084. var text = block.text,
  14085. rawEntityRanges = block.entityRanges,
  14086. rawInlineStyleRanges = block.inlineStyleRanges;
  14087. var entityRanges = rawEntityRanges || [];
  14088. var inlineStyleRanges = rawInlineStyleRanges || []; // Translate entity range keys to the DraftEntity map.
  14089. return createCharacterList(decodeInlineStyleRanges(text, inlineStyleRanges), decodeEntityRanges(text, entityRanges.filter(function (range) {
  14090. return entityMap.hasOwnProperty(range.key);
  14091. }).map(function (range) {
  14092. return _objectSpread({}, range, {
  14093. key: entityMap[range.key]
  14094. });
  14095. })));
  14096. };
  14097. var addKeyIfMissing = function addKeyIfMissing(block) {
  14098. return _objectSpread({}, block, {
  14099. key: block.key || generateRandomKey()
  14100. });
  14101. };
  14102. /**
  14103. * Node stack is responsible to ensure we traverse the tree only once
  14104. * in depth order, while also providing parent refs to inner nodes to
  14105. * construct their links.
  14106. */
  14107. var updateNodeStack = function updateNodeStack(stack, nodes, parentRef) {
  14108. var nodesWithParentRef = nodes.map(function (block) {
  14109. return _objectSpread({}, block, {
  14110. parentRef: parentRef
  14111. });
  14112. }); // since we pop nodes from the stack we need to insert them in reverse
  14113. return stack.concat(nodesWithParentRef.reverse());
  14114. };
  14115. /**
  14116. * This will build a tree draft content state by creating the node
  14117. * reference links into a single tree walk. Each node has a link
  14118. * reference to "parent", "children", "nextSibling" and "prevSibling"
  14119. * blockMap will be created using depth ordering.
  14120. */
  14121. var decodeContentBlockNodes = function decodeContentBlockNodes(blocks, entityMap) {
  14122. return blocks // ensure children have valid keys to enable sibling links
  14123. .map(addKeyIfMissing).reduce(function (blockMap, block, index) {
  14124. !Array.isArray(block.children) ? true ? invariant(false, 'invalid RawDraftContentBlock can not be converted to ContentBlockNode') : invariant(false) : void 0; // ensure children have valid keys to enable sibling links
  14125. var children = block.children.map(addKeyIfMissing); // root level nodes
  14126. var contentBlockNode = new ContentBlockNode(_objectSpread({}, decodeBlockNodeConfig(block, entityMap), {
  14127. prevSibling: index === 0 ? null : blocks[index - 1].key,
  14128. nextSibling: index === blocks.length - 1 ? null : blocks[index + 1].key,
  14129. children: List(children.map(function (child) {
  14130. return child.key;
  14131. }))
  14132. })); // push root node to blockMap
  14133. blockMap = blockMap.set(contentBlockNode.getKey(), contentBlockNode); // this stack is used to ensure we visit all nodes respecting depth ordering
  14134. var stack = updateNodeStack([], children, contentBlockNode); // start computing children nodes
  14135. while (stack.length > 0) {
  14136. // we pop from the stack and start processing this node
  14137. var node = stack.pop(); // parentRef already points to a converted ContentBlockNode
  14138. var parentRef = node.parentRef;
  14139. var siblings = parentRef.getChildKeys();
  14140. var _index = siblings.indexOf(node.key);
  14141. var isValidBlock = Array.isArray(node.children);
  14142. if (!isValidBlock) {
  14143. !isValidBlock ? true ? invariant(false, 'invalid RawDraftContentBlock can not be converted to ContentBlockNode') : invariant(false) : void 0;
  14144. break;
  14145. } // ensure children have valid keys to enable sibling links
  14146. var _children = node.children.map(addKeyIfMissing);
  14147. var _contentBlockNode = new ContentBlockNode(_objectSpread({}, decodeBlockNodeConfig(node, entityMap), {
  14148. parent: parentRef.getKey(),
  14149. children: List(_children.map(function (child) {
  14150. return child.key;
  14151. })),
  14152. prevSibling: _index === 0 ? null : siblings.get(_index - 1),
  14153. nextSibling: _index === siblings.size - 1 ? null : siblings.get(_index + 1)
  14154. })); // push node to blockMap
  14155. blockMap = blockMap.set(_contentBlockNode.getKey(), _contentBlockNode); // this stack is used to ensure we visit all nodes respecting depth ordering
  14156. stack = updateNodeStack(stack, _children, _contentBlockNode);
  14157. }
  14158. return blockMap;
  14159. }, OrderedMap());
  14160. };
  14161. var decodeContentBlocks = function decodeContentBlocks(blocks, entityMap) {
  14162. return OrderedMap(blocks.map(function (block) {
  14163. var contentBlock = new ContentBlock(decodeBlockNodeConfig(block, entityMap));
  14164. return [contentBlock.getKey(), contentBlock];
  14165. }));
  14166. };
  14167. var decodeRawBlocks = function decodeRawBlocks(rawState, entityMap) {
  14168. var isTreeRawBlock = rawState.blocks.find(function (block) {
  14169. return Array.isArray(block.children) && block.children.length > 0;
  14170. });
  14171. var rawBlocks = experimentalTreeDataSupport && !isTreeRawBlock ? DraftTreeAdapter.fromRawStateToRawTreeState(rawState).blocks : rawState.blocks;
  14172. if (!experimentalTreeDataSupport) {
  14173. return decodeContentBlocks(isTreeRawBlock ? DraftTreeAdapter.fromRawTreeStateToRawState(rawState).blocks : rawBlocks, entityMap);
  14174. }
  14175. var blockMap = decodeContentBlockNodes(rawBlocks, entityMap); // in dev mode, check that the tree invariants are met
  14176. if (true) {
  14177. !DraftTreeInvariants.isValidTree(blockMap) ? true ? invariant(false, 'Should be a valid tree') : invariant(false) : void 0;
  14178. }
  14179. return blockMap;
  14180. };
  14181. var decodeRawEntityMap = function decodeRawEntityMap(rawState) {
  14182. var rawEntityMap = rawState.entityMap;
  14183. var entityMap = {}; // TODO: Update this once we completely remove DraftEntity
  14184. Object.keys(rawEntityMap).forEach(function (rawEntityKey) {
  14185. var _rawEntityMap$rawEnti = rawEntityMap[rawEntityKey],
  14186. type = _rawEntityMap$rawEnti.type,
  14187. mutability = _rawEntityMap$rawEnti.mutability,
  14188. data = _rawEntityMap$rawEnti.data; // get the key reference to created entity
  14189. entityMap[rawEntityKey] = DraftEntity.__create(type, mutability, data || {});
  14190. });
  14191. return entityMap;
  14192. };
  14193. var convertFromRawToDraftState = function convertFromRawToDraftState(rawState) {
  14194. !Array.isArray(rawState.blocks) ? true ? invariant(false, 'invalid RawDraftContentState') : invariant(false) : void 0; // decode entities
  14195. var entityMap = decodeRawEntityMap(rawState); // decode blockMap
  14196. var blockMap = decodeRawBlocks(rawState, entityMap); // create initial selection
  14197. var selectionState = blockMap.isEmpty() ? new SelectionState() : SelectionState.createEmpty(blockMap.first().getKey());
  14198. return new ContentState({
  14199. blockMap: blockMap,
  14200. entityMap: entityMap,
  14201. selectionBefore: selectionState,
  14202. selectionAfter: selectionState
  14203. });
  14204. };
  14205. module.exports = convertFromRawToDraftState;
  14206. /***/ }),
  14207. /* 168 */
  14208. /***/ (function(module, exports, __webpack_require__) {
  14209. "use strict";
  14210. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  14211. 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; }
  14212. /**
  14213. * Copyright (c) Facebook, Inc. and its affiliates.
  14214. *
  14215. * This source code is licensed under the MIT license found in the
  14216. * LICENSE file in the root directory of this source tree.
  14217. *
  14218. * @format
  14219. *
  14220. * @emails oncall+draft_js
  14221. *
  14222. * This is unstable and not part of the public API and should not be used by
  14223. * production systems. This file may be update/removed without notice.
  14224. */
  14225. var generateRandomKey = __webpack_require__(9);
  14226. var invariant = __webpack_require__(1);
  14227. var traverseInDepthOrder = function traverseInDepthOrder(blocks, fn) {
  14228. var stack = [].concat(blocks).reverse();
  14229. while (stack.length) {
  14230. var _block = stack.pop();
  14231. fn(_block);
  14232. var children = _block.children;
  14233. !Array.isArray(children) ? true ? invariant(false, 'Invalid tree raw block') : invariant(false) : void 0;
  14234. stack = stack.concat([].concat(children.reverse()));
  14235. }
  14236. };
  14237. var isListBlock = function isListBlock(block) {
  14238. if (!(block && block.type)) {
  14239. return false;
  14240. }
  14241. var type = block.type;
  14242. return type === 'unordered-list-item' || type === 'ordered-list-item';
  14243. };
  14244. var addDepthToChildren = function addDepthToChildren(block) {
  14245. if (Array.isArray(block.children)) {
  14246. block.children = block.children.map(function (child) {
  14247. return child.type === block.type ? _objectSpread({}, child, {
  14248. depth: (block.depth || 0) + 1
  14249. }) : child;
  14250. });
  14251. }
  14252. };
  14253. /**
  14254. * This adapter is intended to be be used as an adapter to draft tree data
  14255. *
  14256. * draft state <=====> draft tree state
  14257. */
  14258. var DraftTreeAdapter = {
  14259. /**
  14260. * Converts from a tree raw state back to draft raw state
  14261. */
  14262. fromRawTreeStateToRawState: function fromRawTreeStateToRawState(draftTreeState) {
  14263. var blocks = draftTreeState.blocks;
  14264. var transformedBlocks = [];
  14265. !Array.isArray(blocks) ? true ? invariant(false, 'Invalid raw state') : invariant(false) : void 0;
  14266. if (!Array.isArray(blocks) || !blocks.length) {
  14267. return draftTreeState;
  14268. }
  14269. traverseInDepthOrder(blocks, function (block) {
  14270. var newBlock = _objectSpread({}, block);
  14271. if (isListBlock(block)) {
  14272. newBlock.depth = newBlock.depth || 0;
  14273. addDepthToChildren(block); // if it's a non-leaf node, we don't do anything else
  14274. if (block.children != null && block.children.length > 0) {
  14275. return;
  14276. }
  14277. }
  14278. delete newBlock.children;
  14279. transformedBlocks.push(newBlock);
  14280. });
  14281. draftTreeState.blocks = transformedBlocks;
  14282. return _objectSpread({}, draftTreeState, {
  14283. blocks: transformedBlocks
  14284. });
  14285. },
  14286. /**
  14287. * Converts from draft raw state to tree draft state
  14288. */
  14289. fromRawStateToRawTreeState: function fromRawStateToRawTreeState(draftState) {
  14290. var transformedBlocks = [];
  14291. var parentStack = [];
  14292. draftState.blocks.forEach(function (block) {
  14293. var isList = isListBlock(block);
  14294. var depth = block.depth || 0;
  14295. var treeBlock = _objectSpread({}, block, {
  14296. children: []
  14297. });
  14298. if (!isList) {
  14299. transformedBlocks.push(treeBlock);
  14300. return;
  14301. }
  14302. var lastParent = parentStack[0]; // block is non-nested & there are no nested blocks, directly push block
  14303. if (lastParent == null && depth === 0) {
  14304. transformedBlocks.push(treeBlock); // block is first nested block or previous nested block is at a lower level
  14305. } else if (lastParent == null || lastParent.depth < depth - 1) {
  14306. // create new parent block
  14307. var newParent = {
  14308. key: generateRandomKey(),
  14309. text: '',
  14310. depth: depth - 1,
  14311. type: block.type,
  14312. children: [],
  14313. entityRanges: [],
  14314. inlineStyleRanges: []
  14315. };
  14316. parentStack.unshift(newParent);
  14317. if (depth === 1) {
  14318. // add as a root-level block
  14319. transformedBlocks.push(newParent);
  14320. } else if (lastParent != null) {
  14321. // depth > 1 => also add as previous parent's child
  14322. lastParent.children.push(newParent);
  14323. }
  14324. newParent.children.push(treeBlock);
  14325. } else if (lastParent.depth === depth - 1) {
  14326. // add as child of last parent
  14327. lastParent.children.push(treeBlock);
  14328. } else {
  14329. // pop out parents at levels above this one from the parent stack
  14330. while (lastParent != null && lastParent.depth >= depth) {
  14331. parentStack.shift();
  14332. lastParent = parentStack[0];
  14333. }
  14334. if (depth > 0) {
  14335. lastParent.children.push(treeBlock);
  14336. } else {
  14337. transformedBlocks.push(treeBlock);
  14338. }
  14339. }
  14340. });
  14341. return _objectSpread({}, draftState, {
  14342. blocks: transformedBlocks
  14343. });
  14344. }
  14345. };
  14346. module.exports = DraftTreeAdapter;
  14347. /***/ }),
  14348. /* 169 */
  14349. /***/ (function(module, exports, __webpack_require__) {
  14350. "use strict";
  14351. /**
  14352. * Copyright (c) Facebook, Inc. and its affiliates.
  14353. *
  14354. * This source code is licensed under the MIT license found in the
  14355. * LICENSE file in the root directory of this source tree.
  14356. *
  14357. * @format
  14358. *
  14359. * @emails oncall+draft_js
  14360. *
  14361. * This is unstable and not part of the public API and should not be used by
  14362. * production systems. This file may be update/removed without notice.
  14363. */
  14364. var warning = __webpack_require__(39);
  14365. var DraftTreeInvariants = {
  14366. /**
  14367. * Check if the block is valid
  14368. */
  14369. isValidBlock: function isValidBlock(block, blockMap) {
  14370. var key = block.getKey(); // is its parent's child
  14371. var parentKey = block.getParentKey();
  14372. if (parentKey != null) {
  14373. var parent = blockMap.get(parentKey);
  14374. if (!parent.getChildKeys().includes(key)) {
  14375. true ? warning(true, 'Tree is missing parent -> child pointer on %s', key) : void 0;
  14376. return false;
  14377. }
  14378. } // is its children's parent
  14379. var children = block.getChildKeys().map(function (k) {
  14380. return blockMap.get(k);
  14381. });
  14382. if (!children.every(function (c) {
  14383. return c.getParentKey() === key;
  14384. })) {
  14385. true ? warning(true, 'Tree is missing child -> parent pointer on %s', key) : void 0;
  14386. return false;
  14387. } // is its previous sibling's next sibling
  14388. var prevSiblingKey = block.getPrevSiblingKey();
  14389. if (prevSiblingKey != null) {
  14390. var prevSibling = blockMap.get(prevSiblingKey);
  14391. if (prevSibling.getNextSiblingKey() !== key) {
  14392. true ? warning(true, "Tree is missing nextSibling pointer on %s's prevSibling", key) : void 0;
  14393. return false;
  14394. }
  14395. } // is its next sibling's previous sibling
  14396. var nextSiblingKey = block.getNextSiblingKey();
  14397. if (nextSiblingKey != null) {
  14398. var nextSibling = blockMap.get(nextSiblingKey);
  14399. if (nextSibling.getPrevSiblingKey() !== key) {
  14400. true ? warning(true, "Tree is missing prevSibling pointer on %s's nextSibling", key) : void 0;
  14401. return false;
  14402. }
  14403. } // no 2-node cycles
  14404. if (nextSiblingKey !== null && prevSiblingKey !== null) {
  14405. if (prevSiblingKey === nextSiblingKey) {
  14406. true ? warning(true, 'Tree has a two-node cycle at %s', key) : void 0;
  14407. return false;
  14408. }
  14409. } // if it's a leaf node, it has text but no children
  14410. if (block.text != '') {
  14411. if (block.getChildKeys().size > 0) {
  14412. true ? warning(true, 'Leaf node %s has children', key) : void 0;
  14413. return false;
  14414. }
  14415. }
  14416. return true;
  14417. },
  14418. /**
  14419. * Checks that this is a connected tree on all the blocks
  14420. * starting from the first block, traversing nextSibling and child pointers
  14421. * should be a tree (preorder traversal - parent, then children)
  14422. * num of connected node === number of blocks
  14423. */
  14424. isConnectedTree: function isConnectedTree(blockMap) {
  14425. // exactly one node has no previous sibling + no parent
  14426. var eligibleFirstNodes = blockMap.toArray().filter(function (block) {
  14427. return block.getParentKey() == null && block.getPrevSiblingKey() == null;
  14428. });
  14429. if (eligibleFirstNodes.length !== 1) {
  14430. true ? warning(true, 'Tree is not connected. More or less than one first node') : void 0;
  14431. return false;
  14432. }
  14433. var firstNode = eligibleFirstNodes.shift();
  14434. var nodesSeen = 0;
  14435. var currentKey = firstNode.getKey();
  14436. var visitedStack = [];
  14437. while (currentKey != null) {
  14438. var currentNode = blockMap.get(currentKey);
  14439. var childKeys = currentNode.getChildKeys();
  14440. var nextSiblingKey = currentNode.getNextSiblingKey(); // if the node has children, add parent's next sibling to stack and go to children
  14441. if (childKeys.size > 0) {
  14442. if (nextSiblingKey != null) {
  14443. visitedStack.unshift(nextSiblingKey);
  14444. }
  14445. var children = childKeys.map(function (k) {
  14446. return blockMap.get(k);
  14447. });
  14448. var _firstNode = children.find(function (block) {
  14449. return block.getPrevSiblingKey() == null;
  14450. });
  14451. if (_firstNode == null) {
  14452. true ? warning(true, '%s has no first child', currentKey) : void 0;
  14453. return false;
  14454. }
  14455. currentKey = _firstNode.getKey(); // TODO(T32490138): Deal with multi-node cycles here
  14456. } else {
  14457. if (currentNode.getNextSiblingKey() != null) {
  14458. currentKey = currentNode.getNextSiblingKey();
  14459. } else {
  14460. currentKey = visitedStack.shift();
  14461. }
  14462. }
  14463. nodesSeen++;
  14464. }
  14465. if (nodesSeen !== blockMap.size) {
  14466. true ? warning(true, 'Tree is not connected. %s nodes were seen instead of %s', nodesSeen, blockMap.size) : void 0;
  14467. return false;
  14468. }
  14469. return true;
  14470. },
  14471. /**
  14472. * Checks that the block map is a connected tree with valid blocks
  14473. */
  14474. isValidTree: function isValidTree(blockMap) {
  14475. var _this = this;
  14476. var blocks = blockMap.toArray();
  14477. if (!blocks.every(function (block) {
  14478. return _this.isValidBlock(block, blockMap);
  14479. })) {
  14480. return false;
  14481. }
  14482. return this.isConnectedTree(blockMap);
  14483. }
  14484. };
  14485. module.exports = DraftTreeInvariants;
  14486. /***/ }),
  14487. /* 170 */
  14488. /***/ (function(module, exports, __webpack_require__) {
  14489. "use strict";
  14490. /**
  14491. * Copyright (c) Facebook, Inc. and its affiliates.
  14492. *
  14493. * This source code is licensed under the MIT license found in the
  14494. * LICENSE file in the root directory of this source tree.
  14495. *
  14496. * @format
  14497. *
  14498. * @emails oncall+draft_js
  14499. */
  14500. var CharacterMetadata = __webpack_require__(6);
  14501. var Immutable = __webpack_require__(0);
  14502. var List = Immutable.List;
  14503. function createCharacterList(inlineStyles, entities) {
  14504. var characterArray = inlineStyles.map(function (style, ii) {
  14505. var entity = entities[ii];
  14506. return CharacterMetadata.create({
  14507. style: style,
  14508. entity: entity
  14509. });
  14510. });
  14511. return List(characterArray);
  14512. }
  14513. module.exports = createCharacterList;
  14514. /***/ }),
  14515. /* 171 */
  14516. /***/ (function(module, exports, __webpack_require__) {
  14517. "use strict";
  14518. /**
  14519. * Copyright (c) Facebook, Inc. and its affiliates.
  14520. *
  14521. * This source code is licensed under the MIT license found in the
  14522. * LICENSE file in the root directory of this source tree.
  14523. *
  14524. * @format
  14525. *
  14526. * @emails oncall+draft_js
  14527. */
  14528. var UnicodeUtils = __webpack_require__(16);
  14529. var substr = UnicodeUtils.substr;
  14530. /**
  14531. * Convert to native JavaScript string lengths to determine ranges.
  14532. */
  14533. function decodeEntityRanges(text, ranges) {
  14534. var entities = Array(text.length).fill(null);
  14535. if (ranges) {
  14536. ranges.forEach(function (range) {
  14537. // Using Unicode-enabled substrings converted to JavaScript lengths,
  14538. // fill the output array with entity keys.
  14539. var start = substr(text, 0, range.offset).length;
  14540. var end = start + substr(text, range.offset, range.length).length;
  14541. for (var ii = start; ii < end; ii++) {
  14542. entities[ii] = range.key;
  14543. }
  14544. });
  14545. }
  14546. return entities;
  14547. }
  14548. module.exports = decodeEntityRanges;
  14549. /***/ }),
  14550. /* 172 */
  14551. /***/ (function(module, exports, __webpack_require__) {
  14552. "use strict";
  14553. /**
  14554. * Copyright (c) Facebook, Inc. and its affiliates.
  14555. *
  14556. * This source code is licensed under the MIT license found in the
  14557. * LICENSE file in the root directory of this source tree.
  14558. *
  14559. * @format
  14560. *
  14561. * @emails oncall+draft_js
  14562. */
  14563. var UnicodeUtils = __webpack_require__(16);
  14564. var _require = __webpack_require__(0),
  14565. OrderedSet = _require.OrderedSet;
  14566. var substr = UnicodeUtils.substr;
  14567. var EMPTY_SET = OrderedSet();
  14568. /**
  14569. * Convert to native JavaScript string lengths to determine ranges.
  14570. */
  14571. function decodeInlineStyleRanges(text, ranges) {
  14572. var styles = Array(text.length).fill(EMPTY_SET);
  14573. if (ranges) {
  14574. ranges.forEach(function (range) {
  14575. var cursor = substr(text, 0, range.offset).length;
  14576. var end = cursor + substr(text, range.offset, range.length).length;
  14577. while (cursor < end) {
  14578. styles[cursor] = styles[cursor].add(range.style);
  14579. cursor++;
  14580. }
  14581. });
  14582. }
  14583. return styles;
  14584. }
  14585. module.exports = decodeInlineStyleRanges;
  14586. /***/ }),
  14587. /* 173 */
  14588. /***/ (function(module, exports, __webpack_require__) {
  14589. "use strict";
  14590. /**
  14591. * Copyright (c) Facebook, Inc. and its affiliates.
  14592. *
  14593. * This source code is licensed under the MIT license found in the
  14594. * LICENSE file in the root directory of this source tree.
  14595. *
  14596. * @format
  14597. *
  14598. * @emails oncall+draft_js
  14599. */
  14600. var getRangeBoundingClientRect = __webpack_require__(174);
  14601. /**
  14602. * Return the bounding ClientRect for the visible DOM selection, if any.
  14603. * In cases where there are no selected ranges or the bounding rect is
  14604. * temporarily invalid, return null.
  14605. *
  14606. * When using from an iframe, you should pass the iframe window object
  14607. */
  14608. function getVisibleSelectionRect(global) {
  14609. var selection = global.getSelection();
  14610. if (!selection.rangeCount) {
  14611. return null;
  14612. }
  14613. var range = selection.getRangeAt(0);
  14614. var boundingRect = getRangeBoundingClientRect(range);
  14615. var top = boundingRect.top,
  14616. right = boundingRect.right,
  14617. bottom = boundingRect.bottom,
  14618. left = boundingRect.left; // When a re-render leads to a node being removed, the DOM selection will
  14619. // temporarily be placed on an ancestor node, which leads to an invalid
  14620. // bounding rect. Discard this state.
  14621. if (top === 0 && right === 0 && bottom === 0 && left === 0) {
  14622. return null;
  14623. }
  14624. return boundingRect;
  14625. }
  14626. module.exports = getVisibleSelectionRect;
  14627. /***/ }),
  14628. /* 174 */
  14629. /***/ (function(module, exports, __webpack_require__) {
  14630. "use strict";
  14631. /**
  14632. * Copyright (c) Facebook, Inc. and its affiliates.
  14633. *
  14634. * This source code is licensed under the MIT license found in the
  14635. * LICENSE file in the root directory of this source tree.
  14636. *
  14637. * @format
  14638. *
  14639. * @emails oncall+draft_js
  14640. */
  14641. var getRangeClientRects = __webpack_require__(70);
  14642. /**
  14643. * Like range.getBoundingClientRect() but normalizes for browser bugs.
  14644. */
  14645. function getRangeBoundingClientRect(range) {
  14646. // "Return a DOMRect object describing the smallest rectangle that includes
  14647. // the first rectangle in list and all of the remaining rectangles of which
  14648. // the height or width is not zero."
  14649. // http://www.w3.org/TR/cssom-view/#dom-range-getboundingclientrect
  14650. var rects = getRangeClientRects(range);
  14651. var top = 0;
  14652. var right = 0;
  14653. var bottom = 0;
  14654. var left = 0;
  14655. if (rects.length) {
  14656. // If the first rectangle has 0 width, we use the second, this is needed
  14657. // because Chrome renders a 0 width rectangle when the selection contains
  14658. // a line break.
  14659. if (rects.length > 1 && rects[0].width === 0) {
  14660. var _rects$ = rects[1];
  14661. top = _rects$.top;
  14662. right = _rects$.right;
  14663. bottom = _rects$.bottom;
  14664. left = _rects$.left;
  14665. } else {
  14666. var _rects$2 = rects[0];
  14667. top = _rects$2.top;
  14668. right = _rects$2.right;
  14669. bottom = _rects$2.bottom;
  14670. left = _rects$2.left;
  14671. }
  14672. for (var ii = 1; ii < rects.length; ii++) {
  14673. var rect = rects[ii];
  14674. if (rect.height !== 0 && rect.width !== 0) {
  14675. top = Math.min(top, rect.top);
  14676. right = Math.max(right, rect.right);
  14677. bottom = Math.max(bottom, rect.bottom);
  14678. left = Math.min(left, rect.left);
  14679. }
  14680. }
  14681. }
  14682. return {
  14683. top: top,
  14684. right: right,
  14685. bottom: bottom,
  14686. left: left,
  14687. width: right - left,
  14688. height: bottom - top
  14689. };
  14690. }
  14691. module.exports = getRangeBoundingClientRect;
  14692. /***/ })
  14693. /******/ ]);
  14694. });